From 23855bd41242f04b16b081a426db5f535963e560 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Thu, 29 May 2025 13:30:45 -0400 Subject: [PATCH] LibWebView: Do not make the client bitmap shareable for screenshots Not sure what the issue is here, but it seems to cause very incorrect screenshots on macOS. In any case, it's wasted computation. --- Libraries/LibWebView/ViewImplementation.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Libraries/LibWebView/ViewImplementation.cpp b/Libraries/LibWebView/ViewImplementation.cpp index 3f746d9366e..6636535c32d 100644 --- a/Libraries/LibWebView/ViewImplementation.cpp +++ b/Libraries/LibWebView/ViewImplementation.cpp @@ -673,15 +673,15 @@ void ViewImplementation::do_not_track_changed() client().async_set_enable_do_not_track(page_id(), do_not_track == DoNotTrack::Yes); } -static ErrorOr save_screenshot(Gfx::ShareableBitmap const& bitmap) +static ErrorOr save_screenshot(Gfx::Bitmap const* bitmap) { - if (!bitmap.is_valid()) + if (!bitmap) return Error::from_string_literal("Failed to take a screenshot"); auto file = Core::DateTime::now().to_byte_string("screenshot-%Y-%m-%d-%H-%M-%S.png"sv); auto path = TRY(Application::the().path_for_downloaded_file(file)); - auto encoded = TRY(Gfx::PNGWriter::encode(*bitmap.bitmap())); + auto encoded = TRY(Gfx::PNGWriter::encode(*bitmap)); auto dump_file = TRY(Core::File::open(path.string(), Core::File::OpenMode::Write)); TRY(dump_file->write_until_depleted(encoded)); @@ -700,12 +700,10 @@ NonnullRefPtr> ViewImplementation::take_screenshot(Sc return promise; } - Gfx::ShareableBitmap bitmap; - switch (type) { case ScreenshotType::Visible: if (auto* visible_bitmap = m_client_state.has_usable_bitmap ? m_client_state.front_bitmap.bitmap.ptr() : m_backup_bitmap.ptr()) { - if (auto result = save_screenshot(visible_bitmap->to_shareable_bitmap()); result.is_error()) + if (auto result = save_screenshot(visible_bitmap); result.is_error()) promise->reject(result.release_error()); else promise->resolve(result.release_value()); @@ -742,7 +740,7 @@ void ViewImplementation::did_receive_screenshot(Badge, Gfx::Sh { VERIFY(m_pending_screenshot); - if (auto result = save_screenshot(screenshot); result.is_error()) + if (auto result = save_screenshot(screenshot.bitmap()); result.is_error()) m_pending_screenshot->reject(result.release_error()); else m_pending_screenshot->resolve(result.release_value());