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:
Aliaksandr Kalenik 2024-03-18 20:11:06 +01:00 committed by Andreas Kling
parent e800605ad3
commit e3e6af39bc
Notes: sideshowbarker 2024-07-16 23:54:15 +09:00
6 changed files with 14 additions and 2 deletions

View File

@ -2073,8 +2073,11 @@ bool Navigable::has_a_rendering_opportunity() const
// or whether the document's visibility state is "visible".
// Rendering opportunities typically occur at regular intervals.
// FIXME: We should at the very least say `false` here if we're an inactive browser tab.
return true;
// FIXME: Return `false` here if we're an inactive browser tab.
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

View File

@ -307,6 +307,7 @@ public:
virtual void inspector_did_execute_console_script([[maybe_unused]] String const& script) { }
virtual void schedule_repaint() = 0;
virtual bool is_ready_to_paint() const = 0;
protected:
virtual ~PageClient() = default;

View File

@ -49,6 +49,7 @@ public:
virtual void request_file(FileRequest) override { }
virtual void paint(DevicePixelRect const&, Gfx::Bitmap&, Web::PaintOptions = {}) override { }
virtual void schedule_repaint() override { }
virtual bool is_ready_to_paint() const override { return true; }
private:
explicit SVGPageClient(Page& host_page)

View File

@ -96,6 +96,11 @@ void PageClient::schedule_repaint()
m_repaint_timer->start();
}
bool PageClient::is_ready_to_paint() const
{
return m_paint_state == PaintState::Ready;
}
void PageClient::ready_to_paint()
{
auto old_paint_state = exchange(m_paint_state, PaintState::Ready);

View File

@ -30,6 +30,7 @@ public:
static void set_use_gpu_painter();
virtual void schedule_repaint() override;
virtual bool is_ready_to_paint() const override;
virtual Web::Page& page() override { return *m_page; }
virtual Web::Page const& page() const override { return *m_page; }

View File

@ -31,6 +31,7 @@ public:
virtual void paint(Web::DevicePixelRect const&, Gfx::Bitmap&, Web::PaintOptions = {}) override;
virtual void request_file(Web::FileRequest) override;
virtual void schedule_repaint() override {};
virtual bool is_ready_to_paint() const override { return true; }
private:
explicit PageHost(ConnectionFromClient&);