diff options
author | Andreas Kling <kling@serenityos.org> | 2020-07-05 16:31:50 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-07-05 16:33:33 +0200 |
commit | 554b58d85fb4d1442e95ada5bea524956d28c8dd (patch) | |
tree | be67a0206add9d5fb2fb44d057c0d23843d93e6f /Demos | |
parent | 668fe61b1de666ba583fa43a317d47d269e0bb70 (diff) | |
download | serenity-554b58d85fb4d1442e95ada5bea524956d28c8dd.zip |
WebContent: Add double buffering to the WebContentView
This removes the remaining flicker in the WebContentView widget and
makes it feel pretty good to use it. :^)
The increase in memory use is something we'll have to address in the
future with more sophisticated solutions like tiling, etc.
Diffstat (limited to 'Demos')
-rw-r--r-- | Demos/WebView/WebContentView.cpp | 21 | ||||
-rw-r--r-- | Demos/WebView/WebContentView.h | 3 |
2 files changed, 15 insertions, 9 deletions
diff --git a/Demos/WebView/WebContentView.cpp b/Demos/WebView/WebContentView.cpp index 97e5ddf0e8..490ecfad18 100644 --- a/Demos/WebView/WebContentView.cpp +++ b/Demos/WebView/WebContentView.cpp @@ -55,18 +55,21 @@ void WebContentView::paint_event(GUI::PaintEvent& event) painter.add_clip_rect(event.rect()); painter.translate(frame_thickness(), frame_thickness()); - ASSERT(m_bitmap); - painter.blit({ 0, 0 }, *m_bitmap, m_bitmap->rect()); + ASSERT(m_front_bitmap); + painter.blit({ 0, 0 }, *m_front_bitmap, m_front_bitmap->rect()); } void WebContentView::resize_event(GUI::ResizeEvent& event) { GUI::ScrollableWidget::resize_event(event); - auto bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::RGB32, available_size()); - m_bitmap = bitmap->to_bitmap_backed_by_shared_buffer(); - m_bitmap->shared_buffer()->share_with(client().server_pid()); - client().post_message(Messages::WebContentServer::SetViewportRect(Gfx::IntRect({ horizontal_scrollbar().value(), vertical_scrollbar().value() }, m_bitmap->size()))); + m_front_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::RGB32, available_size())->to_bitmap_backed_by_shared_buffer(); + m_front_bitmap->shared_buffer()->share_with(client().server_pid()); + + m_back_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::RGB32, available_size())->to_bitmap_backed_by_shared_buffer(); + m_back_bitmap->shared_buffer()->share_with(client().server_pid()); + + client().post_message(Messages::WebContentServer::SetViewportRect(Gfx::IntRect({ horizontal_scrollbar().value(), vertical_scrollbar().value() }, available_size()))); request_repaint(); } @@ -87,8 +90,10 @@ void WebContentView::mousemove_event(GUI::MouseEvent& event) void WebContentView::notify_server_did_paint(Badge<WebContentClient>, i32 shbuf_id) { - if (m_bitmap->shbuf_id() == shbuf_id) + if (m_back_bitmap->shbuf_id() == shbuf_id) { + swap(m_back_bitmap, m_front_bitmap); update(); + } } void WebContentView::notify_server_did_invalidate_content_rect(Badge<WebContentClient>, [[maybe_unused]] const Gfx::IntRect& content_rect) @@ -128,7 +133,7 @@ void WebContentView::did_scroll() void WebContentView::request_repaint() { - client().post_message(Messages::WebContentServer::Paint(m_bitmap->rect().translated(horizontal_scrollbar().value(), vertical_scrollbar().value()), m_bitmap->shbuf_id())); + client().post_message(Messages::WebContentServer::Paint(m_back_bitmap->rect().translated(horizontal_scrollbar().value(), vertical_scrollbar().value()), m_back_bitmap->shbuf_id())); } WebContentClient& WebContentView::client() diff --git a/Demos/WebView/WebContentView.h b/Demos/WebView/WebContentView.h index 4805bf6654..4d448dd956 100644 --- a/Demos/WebView/WebContentView.h +++ b/Demos/WebView/WebContentView.h @@ -66,5 +66,6 @@ private: WebContentClient& client(); RefPtr<WebContentClient> m_client; - RefPtr<Gfx::Bitmap> m_bitmap; + RefPtr<Gfx::Bitmap> m_front_bitmap; + RefPtr<Gfx::Bitmap> m_back_bitmap; }; |