LibGfx+LibWebView+UI: Store Gfx::Bitmap in RefPtr to const

This commit is contained in:
Andrew Kaster 2025-04-15 15:50:18 -06:00 committed by Andrew Kaster
parent be2dd91289
commit 91b549f797
Notes: github-actions[bot] 2025-04-16 16:44:09 +00:00
8 changed files with 15 additions and 15 deletions

View file

@ -95,7 +95,7 @@ void WebViewBridge::enqueue_input_event(Web::KeyEvent event)
Optional<WebViewBridge::Paintable> WebViewBridge::paintable()
{
Gfx::Bitmap* bitmap = nullptr;
Gfx::Bitmap const* bitmap = nullptr;
Gfx::IntSize bitmap_size;
if (m_client_state.has_usable_bitmap) {

View file

@ -42,7 +42,7 @@ public:
void enqueue_input_event(Web::KeyEvent);
struct Paintable {
Gfx::Bitmap& bitmap;
Gfx::Bitmap const& bitmap;
Gfx::IntSize bitmap_size;
};
Optional<Paintable> paintable();

View file

@ -164,11 +164,11 @@ void HeadlessWebView::clear_content_filters()
client().async_set_content_filters(m_client_state.page_index, {});
}
NonnullRefPtr<Core::Promise<RefPtr<Gfx::Bitmap>>> HeadlessWebView::take_screenshot()
NonnullRefPtr<Core::Promise<RefPtr<Gfx::Bitmap const>>> HeadlessWebView::take_screenshot()
{
VERIFY(!m_pending_screenshot);
m_pending_screenshot = Core::Promise<RefPtr<Gfx::Bitmap>>::construct();
m_pending_screenshot = Core::Promise<RefPtr<Gfx::Bitmap const>>::construct();
client().async_take_document_screenshot(0);
return *m_pending_screenshot;

View file

@ -25,7 +25,7 @@ public:
void clear_content_filters();
NonnullRefPtr<Core::Promise<RefPtr<Gfx::Bitmap>>> take_screenshot();
NonnullRefPtr<Core::Promise<RefPtr<Gfx::Bitmap const>>> take_screenshot();
TestPromise& test_promise() { return *m_test_promise; }
void on_test_complete(TestCompletion);
@ -45,7 +45,7 @@ private:
Core::AnonymousBuffer m_theme;
Web::DevicePixelSize m_viewport_size;
RefPtr<Core::Promise<RefPtr<Gfx::Bitmap>>> m_pending_screenshot;
RefPtr<Core::Promise<RefPtr<Gfx::Bitmap const>>> m_pending_screenshot;
NonnullRefPtr<TestPromise> m_test_promise;

View file

@ -328,7 +328,7 @@ static void run_ref_test(HeadlessWebView& view, Test& test, URL::URL const& url,
if (Application::the().dump_failed_ref_tests) {
warnln("\033[33;1mRef test {} failed; dumping screenshots\033[0m", test.relative_path);
auto dump_screenshot = [&](Gfx::Bitmap& bitmap, StringView path) -> ErrorOr<void> {
auto dump_screenshot = [&](Gfx::Bitmap const& bitmap, StringView path) -> ErrorOr<void> {
auto screenshot_file = TRY(Core::File::open(path, Core::File::OpenMode::Write));
auto encoded_data = TRY(Gfx::PNGWriter::encode(bitmap));
TRY(screenshot_file->write_until_depleted(encoded_data));
@ -375,13 +375,13 @@ static void run_ref_test(HeadlessWebView& view, Test& test, URL::URL const& url,
} else {
test.ref_test_expectation_type = RefTestExpectationType::Match;
}
view.take_screenshot()->when_resolved([&view, &test, on_test_complete = move(on_test_complete)](RefPtr<Gfx::Bitmap> screenshot) {
view.take_screenshot()->when_resolved([&view, &test, on_test_complete = move(on_test_complete)](RefPtr<Gfx::Bitmap const> screenshot) {
test.expectation_screenshot = move(screenshot);
view.reset_zoom();
on_test_complete();
});
} else {
view.take_screenshot()->when_resolved([&view, &test](RefPtr<Gfx::Bitmap> screenshot) {
view.take_screenshot()->when_resolved([&view, &test](RefPtr<Gfx::Bitmap const> screenshot) {
test.actual_screenshot = move(screenshot);
view.reset_zoom();
view.debug_request("load-reference-page");

View file

@ -77,8 +77,8 @@ struct Test {
Optional<RefTestExpectationType> ref_test_expectation_type {};
RefPtr<Gfx::Bitmap> actual_screenshot {};
RefPtr<Gfx::Bitmap> expectation_screenshot {};
RefPtr<Gfx::Bitmap const> actual_screenshot {};
RefPtr<Gfx::Bitmap const> expectation_screenshot {};
};
struct TestCompletion {