summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-09-17 14:30:49 +0200
committerAndreas Kling <kling@serenityos.org>2021-09-17 14:39:42 +0200
commit17a5c96b7c863b513441e85555363f9ae26a09bd (patch)
tree3ef1e2fe9439cab4c352a69669bcf3f78bf8d5c1
parentc8c3828b59fe09dd1380285506f17271bac0cb82 (diff)
downloadserenity-17a5c96b7c863b513441e85555363f9ae26a09bd.zip
LibWeb: Make a SharedBitmap struct for OOPWV bitmaps
Instead of having separate members for "bitmap ID" and "bitmap", let's wrap them in a struct.
-rw-r--r--Userland/Libraries/LibWeb/OutOfProcessWebView.cpp39
-rw-r--r--Userland/Libraries/LibWeb/OutOfProcessWebView.h11
2 files changed, 26 insertions, 24 deletions
diff --git a/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp b/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp
index e6585341b9..0ad119df66 100644
--- a/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp
+++ b/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp
@@ -103,7 +103,7 @@ void OutOfProcessWebView::paint_event(GUI::PaintEvent& event)
GUI::Painter painter(*this);
painter.add_clip_rect(event.rect());
- if (auto* bitmap = m_client_state.has_usable_bitmap ? m_client_state.front_bitmap.ptr() : m_backup_bitmap.ptr()) {
+ if (auto* bitmap = m_client_state.has_usable_bitmap ? m_client_state.front_bitmap.bitmap.ptr() : m_backup_bitmap.ptr()) {
painter.add_clip_rect(frame_inner_rect());
painter.translate(frame_thickness(), frame_thickness());
painter.blit({ 0, 0 }, *bitmap, bitmap->rect());
@@ -125,36 +125,36 @@ void OutOfProcessWebView::handle_resize()
if (m_client_state.has_usable_bitmap) {
// NOTE: We keep the outgoing front bitmap as a backup so we have something to paint until we get a new one.
- m_backup_bitmap = m_client_state.front_bitmap;
+ m_backup_bitmap = m_client_state.front_bitmap.bitmap;
}
- if (m_client_state.front_bitmap) {
- m_client_state.front_bitmap = nullptr;
- client().async_remove_backing_store(m_client_state.front_bitmap_id);
+ if (m_client_state.front_bitmap.bitmap) {
+ m_client_state.front_bitmap.bitmap = nullptr;
+ client().async_remove_backing_store(m_client_state.front_bitmap.id);
}
- if (m_client_state.back_bitmap) {
- m_client_state.back_bitmap = nullptr;
- client().async_remove_backing_store(m_client_state.back_bitmap_id);
+ if (m_client_state.back_bitmap.bitmap) {
+ m_client_state.back_bitmap.bitmap = nullptr;
+ client().async_remove_backing_store(m_client_state.back_bitmap.id);
}
- m_client_state.front_bitmap_id = -1;
- m_client_state.back_bitmap_id = -1;
+ m_client_state.front_bitmap.id = -1;
+ m_client_state.back_bitmap.id = -1;
m_client_state.has_usable_bitmap = false;
if (available_size().is_empty())
return;
if (auto new_bitmap = Gfx::Bitmap::try_create_shareable(Gfx::BitmapFormat::BGRx8888, available_size())) {
- m_client_state.front_bitmap = move(new_bitmap);
- m_client_state.front_bitmap_id = m_client_state.next_bitmap_id++;
- client().async_add_backing_store(m_client_state.front_bitmap_id, m_client_state.front_bitmap->to_shareable_bitmap());
+ m_client_state.front_bitmap.bitmap = move(new_bitmap);
+ m_client_state.front_bitmap.id = m_client_state.next_bitmap_id++;
+ client().async_add_backing_store(m_client_state.front_bitmap.id, m_client_state.front_bitmap.bitmap->to_shareable_bitmap());
}
if (auto new_bitmap = Gfx::Bitmap::try_create_shareable(Gfx::BitmapFormat::BGRx8888, available_size())) {
- m_client_state.back_bitmap = move(new_bitmap);
- m_client_state.back_bitmap_id = m_client_state.next_bitmap_id++;
- client().async_add_backing_store(m_client_state.back_bitmap_id, m_client_state.back_bitmap->to_shareable_bitmap());
+ m_client_state.back_bitmap.bitmap = move(new_bitmap);
+ m_client_state.back_bitmap.id = m_client_state.next_bitmap_id++;
+ client().async_add_backing_store(m_client_state.back_bitmap.id, m_client_state.back_bitmap.bitmap->to_shareable_bitmap());
}
request_repaint();
@@ -199,10 +199,9 @@ void OutOfProcessWebView::screen_rects_change_event(GUI::ScreenRectsChangeEvent&
void OutOfProcessWebView::notify_server_did_paint(Badge<WebContentClient>, i32 bitmap_id)
{
- if (m_client_state.back_bitmap_id == bitmap_id) {
+ if (m_client_state.back_bitmap.id == bitmap_id) {
m_client_state.has_usable_bitmap = true;
swap(m_client_state.back_bitmap, m_client_state.front_bitmap);
- swap(m_client_state.back_bitmap_id, m_client_state.front_bitmap_id);
// We don't need the backup bitmap anymore, so drop it.
m_backup_bitmap = nullptr;
update();
@@ -395,9 +394,9 @@ void OutOfProcessWebView::request_repaint()
{
// If this widget was instantiated but not yet added to a window,
// it won't have a back bitmap yet, so we can just skip repaint requests.
- if (!m_client_state.back_bitmap)
+ if (!m_client_state.back_bitmap.bitmap)
return;
- client().async_paint(m_client_state.back_bitmap->rect().translated(horizontal_scrollbar().value(), vertical_scrollbar().value()), m_client_state.back_bitmap_id);
+ client().async_paint(m_client_state.back_bitmap.bitmap->rect().translated(horizontal_scrollbar().value(), vertical_scrollbar().value()), m_client_state.back_bitmap.id);
}
WebContentClient& OutOfProcessWebView::client()
diff --git a/Userland/Libraries/LibWeb/OutOfProcessWebView.h b/Userland/Libraries/LibWeb/OutOfProcessWebView.h
index bbb87b55d8..49a74c3f9c 100644
--- a/Userland/Libraries/LibWeb/OutOfProcessWebView.h
+++ b/Userland/Libraries/LibWeb/OutOfProcessWebView.h
@@ -110,12 +110,15 @@ private:
AK::URL m_url;
+ struct SharedBitmap {
+ i32 id { -1 };
+ RefPtr<Gfx::Bitmap> bitmap;
+ };
+
struct ClientState {
RefPtr<WebContentClient> client;
- RefPtr<Gfx::Bitmap> front_bitmap;
- RefPtr<Gfx::Bitmap> back_bitmap;
- i32 front_bitmap_id { -1 };
- i32 back_bitmap_id { -1 };
+ SharedBitmap front_bitmap;
+ SharedBitmap back_bitmap;
i32 next_bitmap_id { 0 };
bool has_usable_bitmap { false };
} m_client_state;