Truly independent web browser
LibWeb: Invalidate only the SVG image whose document asks for a frame
sideshowbarkerd4ca14bdebfd
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cppindex cf1e9b0520a..ce16cdc85ee 100644--- a/Libraries/LibWeb/DOM/Document.cpp+++ b/Libraries/LibWeb/DOM/Document.cpp@@ -3083,7 +3083,7 @@ void Document::throttled_animation_visibility_changed()}flush_throttled_animation_style_update();set_rendering_pending(*this, RenderingPendingReason::NeedsRenderingUpdate, 1);- page().client().request_frame();+ page().client().request_frame_for(*this);}void Document::set_needs_animated_style_update(Animations::KeyframeEffect& effect)@@ -3099,7 +3099,7 @@ void Document::set_needs_animated_style_update(Animations::KeyframeEffect& effecreturn;set_rendering_pending(*this, RenderingPendingReason::NeedsRenderingUpdate, 1);- page().client().request_frame();+ page().client().request_frame_for(*this);}void Document::finish_animated_style_update()@@ -5352,7 +5352,7 @@ void Document::update_readiness(HTML::DocumentReadyState readiness_value)if (readiness_value != HTML::DocumentReadyState::Loading) {set_rendering_pending(*this, RenderingPendingReason::NeedsRenderingUpdate, 1);- page().client().request_frame();+ page().client().request_frame_for(*this);}// 3. If document is associated with an HTML parser, then:@@ -5823,7 +5823,7 @@ void Document::update_the_visibility_state(HTML::VisibilityState visibility_statif (m_visibility_state == HTML::VisibilityState::Visible) {flush_throttled_animation_style_update();set_rendering_pending(*this, RenderingPendingReason::NeedsRenderingUpdate, 1);- page().client().request_frame();+ page().client().request_frame_for(*this);}}@@ -6223,7 +6223,7 @@ void Document::increment_number_of_pending_style_sheet_requests(Badge<DocumentLo++m_number_of_pending_style_sheet_requests;set_rendering_pending(*this, RenderingPendingReason::StyleSheetLoads, m_number_of_pending_style_sheet_requests + m_pending_css_import_rules.size());set_rendering_pending(*this, RenderingPendingReason::NeedsRenderingUpdate, 1);- page().client().request_frame();+ page().client().request_frame_for(*this);}void Document::decrement_number_of_pending_style_sheet_requests(Badge<DocumentLoadEventDelayer>)@@ -6232,7 +6232,7 @@ void Document::decrement_number_of_pending_style_sheet_requests(Badge<DocumentLo--m_number_of_pending_style_sheet_requests;set_rendering_pending(*this, RenderingPendingReason::StyleSheetLoads, m_number_of_pending_style_sheet_requests + m_pending_css_import_rules.size());set_rendering_pending(*this, RenderingPendingReason::NeedsRenderingUpdate, 1);- page().client().request_frame();+ page().client().request_frame_for(*this);}// AD-HOC: A navigation can drop the document it created before activating it. Its parser and fetch go on queueing@@ -9235,7 +9235,7 @@ void Document::service_compositor_animation_wakeup(double timestamp)}++m_style_invalidation_counters.animation_frame_pump_requests;set_rendering_pending(*this, RenderingPendingReason::NeedsRenderingUpdate, 1);- page().client().request_frame();+ page().client().request_frame_for(*this);}}@@ -9988,7 +9988,7 @@ void Document::update_compositor_animations(Layout::BegunRead const& read)m_compositor_animation_observation_timer = Core::Timer::create_single_shot(AK::Duration::from_milliseconds(100), GC::weak_callback(*this, [](auto& document) {++document.m_style_invalidation_counters.animation_frame_pump_requests;set_rendering_pending(document, RenderingPendingReason::NeedsRenderingUpdate, 1);- document.page().client().request_frame();+ document.page().client().request_frame_for(document);document.m_compositor_animation_observation_timer->start();}));}@@ -10160,7 +10160,7 @@ void Document::update_animations_and_send_events(double timestamp)}++m_style_invalidation_counters.animation_frame_pump_requests;set_rendering_pending(*this, RenderingPendingReason::NeedsRenderingUpdate, 1);- page().client().request_frame();+ page().client().request_frame_for(*this);break;}}@@ -11362,7 +11362,7 @@ void Document::remove_render_blocking_element(GC::Ref<Element> element)}set_rendering_pending(*this, RenderingPendingReason::NeedsRenderingUpdate, 1);- page().client().request_frame();+ page().client().request_frame_for(*this);}// https://fullscreen.spec.whatwg.org/#run-the-fullscreen-steps@@ -11402,7 +11402,7 @@ void Document::append_pending_fullscreen_change(PendingFullscreenEvent::Type typ{m_pending_fullscreen_events.append(PendingFullscreenEvent { type, element, request_type });set_rendering_pending(*this, RenderingPendingReason::NeedsRenderingUpdate, 1);- page().client().request_frame();+ page().client().request_frame_for(*this);}// https://fullscreen.spec.whatwg.org/#fullscreen-an-element@@ -11932,7 +11932,7 @@ void Document::request_frame_for_pending_repaint()// loading between renders must still invalidate the image's cached rendering and notify its clients.if (page().client().is_svg_page_client()) {set_rendering_pending(*this, RenderingPendingReason::NeedsRenderingUpdate, 1);- page().client().request_frame();+ page().client().request_frame_for(*this);}return;}@@ -11942,7 +11942,7 @@ void Document::request_frame_for_pending_repaint()// A local root's frames come from its page, whether it is the traversable or another process hosts its parent.if (navigable->is_local_root()) {set_rendering_pending(*this, RenderingPendingReason::NeedsRenderingUpdate, 1);- page().client().request_frame();+ page().client().request_frame_for(*this);return;}@@ -12219,7 +12219,7 @@ void Document::set_caret_hit_test_debug_rect(Optional<CSSPixelRect> rect)m_caret_hit_test_debug_rect = rect;set_needs_repaint(InvalidateDisplayList::PaintCommands);set_rendering_pending(*this, RenderingPendingReason::NeedsRenderingUpdate, 1);- page().client().request_frame();+ page().client().request_frame_for(*this);}Optional<Painting::HitTestQuery> Document::prepare_hit_test_query(Layout::BegunRead const& read, Optional<i64> visual_animation_sample_time_nanoseconds)@@ -12632,7 +12632,7 @@ void Document::set_rendering_suppression_for_view_transitions(bool value)if (!value) {set_rendering_pending(*this, RenderingPendingReason::NeedsRenderingUpdate, 1);- page().client().request_frame();+ page().client().request_frame_for(*this);}}@@ -13100,7 +13100,7 @@ void Document::remove_pending_css_import_rule(Badge<CSS::StyleSheetImport>, Nonnset_rendering_pending(*this, RenderingPendingReason::StyleSheetLoads, m_number_of_pending_style_sheet_requests + m_pending_css_import_rules.size());if (m_pending_css_import_rules.is_empty()) {set_rendering_pending(*this, RenderingPendingReason::NeedsRenderingUpdate, 1);- page().client().request_frame();+ page().client().request_frame_for(*this);}}diff --git a/Libraries/LibWeb/Page/Page.h b/Libraries/LibWeb/Page/Page.hindex 775e8f5da0f..4f171decbe4 100644--- a/Libraries/LibWeb/Page/Page.h+++ b/Libraries/LibWeb/Page/Page.h@@ -787,6 +787,8 @@ public:}virtual HTML::CrossProcessId allocate_navigable_id() { return allocate_cross_process_id(); }virtual void request_frame() = 0;+ // A frame request on behalf of one document, for a client whose page shows many documents.+ virtual void request_frame_for(DOM::Document const&) { request_frame(); }virtual double rendering_frame_interval_in_milliseconds() const { return 1000.0 / 60.0; }virtual void rendering_opportunity([[maybe_unused]] i64 frame_time_nanoseconds, [[maybe_unused]] double frame_interval_milliseconds) { }virtual void will_begin_rendering_update() { }diff --git a/Libraries/LibWeb/SVG/SVGDecodedImageData.cpp b/Libraries/LibWeb/SVG/SVGDecodedImageData.cppindex af0b4530f39..f26b8ae39f3 100644--- a/Libraries/LibWeb/SVG/SVGDecodedImageData.cpp+++ b/Libraries/LibWeb/SVG/SVGDecodedImageData.cpp@@ -495,6 +495,22 @@ void SVGDecodedImageData::SVGPageClient::request_frame()svg_image_data.did_request_frame();}+void SVGDecodedImageData::SVGPageClient::request_frame_for(DOM::Document const& document)+{+ if (m_frame_request_suppression_count > 0)+ return;++ // Only the image of the document asking for the frame changes. A document that's still being decoded has no image+ // yet, and so nothing to invalidate. Invalidating every image instead would make loading n images take O(n^3)+ // time, since each invalidation prunes the cached resources of every image.+ for (auto& svg_image_data : m_svg_image_data) {+ if (&svg_image_data.svg_document() == &document) {+ svg_image_data.did_request_frame();+ return;+ }+ }+}+NonnullRefPtr<Media::AudioOutputFactory> SVGDecodedImageData::SVGPageClient::create_audio_output_factory(){return m_host_page->client().create_audio_output_factory();diff --git a/Libraries/LibWeb/SVG/SVGDecodedImageData.h b/Libraries/LibWeb/SVG/SVGDecodedImageData.hindex 9d51c4f5b04..65590684232 100644--- a/Libraries/LibWeb/SVG/SVGDecodedImageData.h+++ b/Libraries/LibWeb/SVG/SVGDecodedImageData.h@@ -149,6 +149,7 @@ public:virtual Queue<QueuedInputEvent>& input_event_queue() override { VERIFY_NOT_REACHED(); }virtual void report_finished_handling_input_event([[maybe_unused]] Web::PageId page_id, [[maybe_unused]] u64 event_id, [[maybe_unused]] EventResult event_was_handled) override { }virtual void request_frame() override;+ virtual void request_frame_for(DOM::Document const&) override;virtual bool is_headless() const override { return m_host_page->client().is_headless(); }virtual NonnullRefPtr<Media::AudioOutputFactory> create_audio_output_factory() override;