Truly independent web browser
LibWeb: Run opacity animations inside an SVG on the compositor
Andreas Klingd2ceae288af2
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cppindex 989dab0b52a..5ac45af5ade 100644--- a/Libraries/LibWeb/DOM/Document.cpp+++ b/Libraries/LibWeb/DOM/Document.cpp@@ -8540,7 +8540,10 @@ static Painting::CompositorAnimationEffectState::BuildOutcome build_compositor_areturn {};if (target->element().namespace_uri() == Namespace::SVG) {auto const* layout_node = target->unsafe_layout_node(read);- if (!targets_transform || !layout_node || !svg_transform_may_run_on_the_compositor(target->element(), *layout_node))+ // NB: The compositor has no animations for the documents of SVG images.+ if (!layout_node || (!targets_transform && !targets_opacity) || target->document().is_decoded_svg())+ return {};+ if (targets_transform && !svg_transform_may_run_on_the_compositor(target->element(), *layout_node))return {};}auto monotonic_time_at_anchor_ms = [&]() -> Optional<double> {diff --git a/Tests/LibWeb/Text/expected/css/compositor-svg-internal-transform.txt b/Tests/LibWeb/Text/expected/css/compositor-svg-internal-transform.txtindex 8ce25ed4498..07cb2ff089e 100644--- a/Tests/LibWeb/Text/expected/css/compositor-svg-internal-transform.txt+++ b/Tests/LibWeb/Text/expected/css/compositor-svg-internal-transform.txt@@ -10,10 +10,10 @@ runs on the compositor:a use element: falsea use element with a position: falsea nested svg: false- a fading rect: false- a fading group: false- a fading use element: false- a fading rect in a group with a filter element: false+ a fading rect: true+ a fading group: true+ a fading use element: true+ a fading rect in a group with a filter element: trueruns on the compositor, though it must not:a rect in a group with a filter element: falsea rect in a group with a clip path in its bounding box: falsediff --git a/Tests/LibWeb/Text/expected/css/offscreen-svg-opacity-animation.txt b/Tests/LibWeb/Text/expected/css/offscreen-svg-opacity-animation.txtindex 0949e11aebb..66c2ada2ca2 100644--- a/Tests/LibWeb/Text/expected/css/offscreen-svg-opacity-animation.txt+++ b/Tests/LibWeb/Text/expected/css/offscreen-svg-opacity-animation.txt@@ -1,9 +1,9 @@offscreen SVG opacity builds no overlays: true-an outer clip stops the frame pump around transformed and filtered SVG: true+an outer clip stops updates around transformed and filtered SVG: trueSVG style observes the current opacity: truescrolling into view samples SVG opacity: true-visible SVG opacity resumes the frame pump: true-scrolling out of view stops the frame pump again: true+visible SVG opacity resumes updating: true+scrolling out of view stops updating again: truea transform outside the clip keeps SVG opacity updating: truea filter outside the clip keeps SVG opacity updating: truepotentially referenced SVG keeps updating: truediff --git a/Tests/LibWeb/Text/input/css/offscreen-svg-opacity-animation.html b/Tests/LibWeb/Text/input/css/offscreen-svg-opacity-animation.htmlindex 590666fd0b7..44fdce3eb5d 100644--- a/Tests/LibWeb/Text/input/css/offscreen-svg-opacity-animation.html+++ b/Tests/LibWeb/Text/input/css/offscreen-svg-opacity-animation.html@@ -21,6 +21,10 @@await settle();return internals.getStyleInvalidationCounters();}+ // Visible SVG opacity updates beside the main thread if it can, or through frames of the main thread if not.+ function updates(counters) {+ return counters.animationFramePumpRequests > 0 || counters.compositorVisualAnimations > 0;+ }const timeline = internals.createInternalAnimationTimeline();timeline.setTime(0);timeline.setTimeForObservation(0);@@ -33,7 +37,7 @@await settle();let counters = await countersOverFrames();println(`offscreen SVG opacity builds no overlays: ${counters.animatedStyleOverlayBuilds === 0}`);- println(`an outer clip stops the frame pump around transformed and filtered SVG: ${counters.animationFramePumpRequests === 0}`);+ println(`an outer clip stops updates around transformed and filtered SVG: ${!updates(counters)}`);timeline.setTimeForObservation(400);println(`SVG style observes the current opacity: ${getComputedStyle(target).opacity === "0.4"}`);@@ -43,21 +47,21 @@await settle();println(`scrolling into view samples SVG opacity: ${getComputedStyle(target).opacity === "0.6"}`);counters = await countersOverFrames();- println(`visible SVG opacity resumes the frame pump: ${counters.animationFramePumpRequests > 0}`);+ println(`visible SVG opacity resumes updating: ${updates(counters)}`);scrollTo(0, 0);await settle();counters = await countersOverFrames();- println(`scrolling out of view stops the frame pump again: ${counters.animationFramePumpRequests === 0}`);+ println(`scrolling out of view stops updating again: ${!updates(counters)}`);clip.style.transform = "translateX(0px)";await settle();counters = await countersOverFrames();- println(`a transform outside the clip keeps SVG opacity updating: ${counters.animationFramePumpRequests > 0}`);+ println(`a transform outside the clip keeps SVG opacity updating: ${updates(counters)}`);clip.style.transform = "";clip.style.filter = "blur(100px)";await settle();counters = await countersOverFrames();- println(`a filter outside the clip keeps SVG opacity updating: ${counters.animationFramePumpRequests > 0}`);+ println(`a filter outside the clip keeps SVG opacity updating: ${updates(counters)}`);clip.style.filter = "";target.id = "referenced";@@ -68,7 +72,7 @@document.body.append(visibleSVG);await settle();counters = await countersOverFrames();- println(`potentially referenced SVG keeps updating: ${counters.animationFramePumpRequests > 0}`);+ println(`potentially referenced SVG keeps updating: ${updates(counters)}`);visibleSVG.remove();target.removeAttribute("id");@@ -77,13 +81,13 @@pattern.append(target);await settle();counters = await countersOverFrames();- println(`SVG paint resources are not throttled by their DOM position: ${counters.animationFramePumpRequests > 0}`);+ println(`SVG paint resources are not throttled by their DOM position: ${updates(counters)}`);pattern.replaceWith(target);animation.effect.setKeyframes([{ opacity: 0, r: "20px" }, { opacity: 1, r: "40px" }]);await settle();counters = await countersOverFrames();- println(`mixed SVG geometry and opacity animation keeps updating: ${counters.animationFramePumpRequests > 0}`);+ println(`mixed SVG geometry and opacity animation keeps updating: ${updates(counters)}`);animation.cancel();done();});