diff options
author | Andreas Kling <kling@serenityos.org> | 2021-09-28 22:53:59 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-28 22:53:59 +0200 |
commit | 651f30dfbe2343e32c252324a653f4bdf915ded5 (patch) | |
tree | 430782c3cfee06e30bd961fe05606dc7a62df001 /Userland | |
parent | 82af69376bc16586648320cd5e2de3c94cb3c753 (diff) | |
download | serenity-651f30dfbe2343e32c252324a653f4bdf915ded5.zip |
WebContent: Coalesce paint invalidations to avoid spamming client
Some content cause a lot of paint invalidations (e.g someone drawing to
a <canvas> repeatedly) and we don't need to spam the client about this.
Instead, accumulate a dirty rect, and send it once per event loop step.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Services/WebContent/PageHost.cpp | 10 | ||||
-rw-r--r-- | Userland/Services/WebContent/PageHost.h | 3 |
2 files changed, 11 insertions, 2 deletions
diff --git a/Userland/Services/WebContent/PageHost.cpp b/Userland/Services/WebContent/PageHost.cpp index 4dcbabfdf7..0414a88044 100644 --- a/Userland/Services/WebContent/PageHost.cpp +++ b/Userland/Services/WebContent/PageHost.cpp @@ -21,6 +21,10 @@ PageHost::PageHost(ClientConnection& client) , m_page(make<Web::Page>(*this)) { setup_palette(); + m_invalidation_coalescing_timer = Core::Timer::create_single_shot(0, [this] { + m_client.async_did_invalidate_content_rect(m_invalidation_rect); + m_invalidation_rect = {}; + }); } PageHost::~PageHost() @@ -77,9 +81,11 @@ void PageHost::set_viewport_rect(const Gfx::IntRect& rect) page().top_level_browsing_context().set_viewport_rect(rect); } -void PageHost::page_did_invalidate(const Gfx::IntRect& content_rect) +void PageHost::page_did_invalidate(Gfx::IntRect const& content_rect) { - m_client.async_did_invalidate_content_rect(content_rect); + m_invalidation_rect = m_invalidation_rect.united(content_rect); + if (!m_invalidation_coalescing_timer->is_active()) + m_invalidation_coalescing_timer->start(); } void PageHost::page_did_change_selection() diff --git a/Userland/Services/WebContent/PageHost.h b/Userland/Services/WebContent/PageHost.h index ef4b48208a..1db072ede9 100644 --- a/Userland/Services/WebContent/PageHost.h +++ b/Userland/Services/WebContent/PageHost.h @@ -72,6 +72,9 @@ private: RefPtr<Gfx::PaletteImpl> m_palette_impl; Gfx::IntRect m_screen_rect; bool m_should_show_line_box_borders { false }; + + RefPtr<Core::Timer> m_invalidation_coalescing_timer; + Gfx::IntRect m_invalidation_rect; }; } |