1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-09 09:34:57 +09:00

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

@ -333,7 +333,7 @@ static ARGB32 sub_argb32(ARGB32 a, ARGB32 b)
.value(); .value();
} }
static ErrorOr<NonnullRefPtr<Bitmap>> maybe_write_color_indexing_transform(LittleEndianOutputBitStream& bit_stream, NonnullRefPtr<Bitmap> bitmap, IsOpaque& is_fully_opaque) static ErrorOr<NonnullRefPtr<Bitmap const>> maybe_write_color_indexing_transform(LittleEndianOutputBitStream& bit_stream, NonnullRefPtr<Bitmap const> bitmap, IsOpaque& is_fully_opaque)
{ {
// https://developers.google.com/speed/webp/docs/webp_lossless_bitstream_specification#44_color_indexing_transform // https://developers.google.com/speed/webp/docs/webp_lossless_bitstream_specification#44_color_indexing_transform
unsigned color_table_size = 0; unsigned color_table_size = 0;
@ -427,7 +427,7 @@ static ErrorOr<NonnullRefPtr<Bitmap>> maybe_write_color_indexing_transform(Littl
return new_bitmap; return new_bitmap;
} }
static ErrorOr<void> write_VP8L_image_data(Stream& stream, NonnullRefPtr<Bitmap> bitmap, VP8LEncoderOptions const& options, IsOpaque& is_fully_opaque) static ErrorOr<void> write_VP8L_image_data(Stream& stream, NonnullRefPtr<Bitmap const> bitmap, VP8LEncoderOptions const& options, IsOpaque& is_fully_opaque)
{ {
LittleEndianOutputBitStream bit_stream { MaybeOwned<Stream>(stream) }; LittleEndianOutputBitStream bit_stream { MaybeOwned<Stream>(stream) };

View file

@ -267,7 +267,7 @@ protected:
struct SharedBitmap { struct SharedBitmap {
i32 id { -1 }; i32 id { -1 };
Web::DevicePixelSize last_painted_size; Web::DevicePixelSize last_painted_size;
RefPtr<Gfx::Bitmap> bitmap; RefPtr<Gfx::Bitmap const> bitmap;
}; };
struct ClientState { struct ClientState {
@ -289,7 +289,7 @@ protected:
RefPtr<Core::Timer> m_backing_store_shrink_timer; RefPtr<Core::Timer> m_backing_store_shrink_timer;
RefPtr<Gfx::Bitmap> m_backup_bitmap; RefPtr<Gfx::Bitmap const> m_backup_bitmap;
Web::DevicePixelSize m_backup_bitmap_size; Web::DevicePixelSize m_backup_bitmap_size;
size_t m_crash_count = 0; size_t m_crash_count = 0;

View file

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

View file

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

View file

@ -164,11 +164,11 @@ void HeadlessWebView::clear_content_filters()
client().async_set_content_filters(m_client_state.page_index, {}); 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); 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); client().async_take_document_screenshot(0);
return *m_pending_screenshot; return *m_pending_screenshot;

View file

@ -25,7 +25,7 @@ public:
void clear_content_filters(); 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; } TestPromise& test_promise() { return *m_test_promise; }
void on_test_complete(TestCompletion); void on_test_complete(TestCompletion);
@ -45,7 +45,7 @@ private:
Core::AnonymousBuffer m_theme; Core::AnonymousBuffer m_theme;
Web::DevicePixelSize m_viewport_size; 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; 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) { if (Application::the().dump_failed_ref_tests) {
warnln("\033[33;1mRef test {} failed; dumping screenshots\033[0m", test.relative_path); 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 screenshot_file = TRY(Core::File::open(path, Core::File::OpenMode::Write));
auto encoded_data = TRY(Gfx::PNGWriter::encode(bitmap)); auto encoded_data = TRY(Gfx::PNGWriter::encode(bitmap));
TRY(screenshot_file->write_until_depleted(encoded_data)); 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 { } else {
test.ref_test_expectation_type = RefTestExpectationType::Match; 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); test.expectation_screenshot = move(screenshot);
view.reset_zoom(); view.reset_zoom();
on_test_complete(); on_test_complete();
}); });
} else { } 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); test.actual_screenshot = move(screenshot);
view.reset_zoom(); view.reset_zoom();
view.debug_request("load-reference-page"); view.debug_request("load-reference-page");

View file

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