mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-30 05:09:01 +00:00
LibWeb: Add basic implementation of has_a_rendering_opportunity()
Return true only if we are ready to repaint. This fixes the issue where requestAnimationFrame() was invoked more than once between repaints.
This commit is contained in:
parent
e800605ad3
commit
e3e6af39bc
Notes:
sideshowbarker
2024-07-16 23:54:15 +09:00
Author: https://github.com/kalenikaliaksandr
Commit: e3e6af39bc
Pull-request: https://github.com/SerenityOS/serenity/pull/23629
6 changed files with 14 additions and 2 deletions
|
@ -2073,8 +2073,11 @@ bool Navigable::has_a_rendering_opportunity() const
|
||||||
// or whether the document's visibility state is "visible".
|
// or whether the document's visibility state is "visible".
|
||||||
// Rendering opportunities typically occur at regular intervals.
|
// Rendering opportunities typically occur at regular intervals.
|
||||||
|
|
||||||
// FIXME: We should at the very least say `false` here if we're an inactive browser tab.
|
// FIXME: Return `false` here if we're an inactive browser tab.
|
||||||
return true;
|
auto browsing_context = const_cast<Navigable*>(this)->active_browsing_context();
|
||||||
|
if (!browsing_context)
|
||||||
|
return false;
|
||||||
|
return browsing_context->page().client().is_ready_to_paint();
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#inform-the-navigation-api-about-aborting-navigation
|
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#inform-the-navigation-api-about-aborting-navigation
|
||||||
|
|
|
@ -307,6 +307,7 @@ public:
|
||||||
virtual void inspector_did_execute_console_script([[maybe_unused]] String const& script) { }
|
virtual void inspector_did_execute_console_script([[maybe_unused]] String const& script) { }
|
||||||
|
|
||||||
virtual void schedule_repaint() = 0;
|
virtual void schedule_repaint() = 0;
|
||||||
|
virtual bool is_ready_to_paint() const = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual ~PageClient() = default;
|
virtual ~PageClient() = default;
|
||||||
|
|
|
@ -49,6 +49,7 @@ public:
|
||||||
virtual void request_file(FileRequest) override { }
|
virtual void request_file(FileRequest) override { }
|
||||||
virtual void paint(DevicePixelRect const&, Gfx::Bitmap&, Web::PaintOptions = {}) override { }
|
virtual void paint(DevicePixelRect const&, Gfx::Bitmap&, Web::PaintOptions = {}) override { }
|
||||||
virtual void schedule_repaint() override { }
|
virtual void schedule_repaint() override { }
|
||||||
|
virtual bool is_ready_to_paint() const override { return true; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit SVGPageClient(Page& host_page)
|
explicit SVGPageClient(Page& host_page)
|
||||||
|
|
|
@ -96,6 +96,11 @@ void PageClient::schedule_repaint()
|
||||||
m_repaint_timer->start();
|
m_repaint_timer->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PageClient::is_ready_to_paint() const
|
||||||
|
{
|
||||||
|
return m_paint_state == PaintState::Ready;
|
||||||
|
}
|
||||||
|
|
||||||
void PageClient::ready_to_paint()
|
void PageClient::ready_to_paint()
|
||||||
{
|
{
|
||||||
auto old_paint_state = exchange(m_paint_state, PaintState::Ready);
|
auto old_paint_state = exchange(m_paint_state, PaintState::Ready);
|
||||||
|
|
|
@ -30,6 +30,7 @@ public:
|
||||||
static void set_use_gpu_painter();
|
static void set_use_gpu_painter();
|
||||||
|
|
||||||
virtual void schedule_repaint() override;
|
virtual void schedule_repaint() override;
|
||||||
|
virtual bool is_ready_to_paint() const override;
|
||||||
|
|
||||||
virtual Web::Page& page() override { return *m_page; }
|
virtual Web::Page& page() override { return *m_page; }
|
||||||
virtual Web::Page const& page() const override { return *m_page; }
|
virtual Web::Page const& page() const override { return *m_page; }
|
||||||
|
|
|
@ -31,6 +31,7 @@ public:
|
||||||
virtual void paint(Web::DevicePixelRect const&, Gfx::Bitmap&, Web::PaintOptions = {}) override;
|
virtual void paint(Web::DevicePixelRect const&, Gfx::Bitmap&, Web::PaintOptions = {}) override;
|
||||||
virtual void request_file(Web::FileRequest) override;
|
virtual void request_file(Web::FileRequest) override;
|
||||||
virtual void schedule_repaint() override {};
|
virtual void schedule_repaint() override {};
|
||||||
|
virtual bool is_ready_to_paint() const override { return true; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit PageHost(ConnectionFromClient&);
|
explicit PageHost(ConnectionFromClient&);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue