Truly independent web browser
LibWeb: Run transform animations of <use> elements on the compositor
Andreas Klingbdbbcabcc39d
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cppindex a08fcaf1be7..ac1a3d5741a 100644--- a/Libraries/LibWeb/DOM/Document.cpp+++ b/Libraries/LibWeb/DOM/Document.cpp@@ -8505,10 +8505,6 @@ static bool svg_transform_may_run_on_the_compositor(Element const& target, Layouif (layout_node.kind() == Layout::RustFFI::NodeKind::SVGSVGBox && !target.parent_element())return false;- // NB: The compositor replaces the matrix that the x and y of a <use> element are part of.- if (is<SVG::SVGUseElement>(target))- return false;-// NB: A box's own bounding box leaves out its own transform, but those of the boxes around it include it.for (auto const* ancestor = layout_node.parent(); ancestor && ancestor->is_svg_box(); ancestor = ancestor->parent()) {if (svg_box_uses_its_bounding_box(*ancestor))diff --git a/Libraries/LibWeb/Rust/src/painting/ffi.rs b/Libraries/LibWeb/Rust/src/painting/ffi.rsindex 0ce911fdec8..494765793f1 100644--- a/Libraries/LibWeb/Rust/src/painting/ffi.rs+++ b/Libraries/LibWeb/Rust/src/painting/ffi.rs@@ -1270,9 +1270,17 @@ pub unsafe extern "C" fn compositor_animation_effect_build() -> crate::painting::host::FfiCompositorAnimationBuildOutcome {use crate::painting::visual_animation_builder::{Host, Request};// SAFETY: Guaranteed by the caller.- let request = unsafe { Request::new(&*request) };+ let mut request = unsafe { Request::new(&*request) };let host = Host::new(host);let layout_node = request.layout_node();+ if request.target_kind() == crate::painting::host::FfiVisualAnimationTargetKind::Transform {+ let additional_element_transform = read_arena(document_host, node_read(), layout_node, |arena, layout_node| {+ crate::painting::paintable_geometry::committed_svg_additional_element_transform(arena, layout_node)+ });+ if let Some(transform) = additional_element_transform {+ request.set_additional_translation(transform.e, transform.f);+ }+ }state.build(&request, &host, |kind| {read_arena(document_host,diff --git a/Libraries/LibWeb/Rust/src/painting/visual_animation_builder.rs b/Libraries/LibWeb/Rust/src/painting/visual_animation_builder.rsindex f51d512ed02..ab66d8bdcfa 100644--- a/Libraries/LibWeb/Rust/src/painting/visual_animation_builder.rs+++ b/Libraries/LibWeb/Rust/src/painting/visual_animation_builder.rs@@ -130,6 +130,8 @@ impl<'a> Host<'a> {pub struct Request<'a> {ffi: &'a FfiCompositorAnimationRequest,keyframes: &'a [FfiCompositorAnimationKeyframe],+ /// The translation in CSS pixels that the x and y of a <use> element apply after its transform.+ additional_translation: (f32, f32),}impl<'a> Request<'a> {@@ -141,14 +143,23 @@ impl<'a> Request<'a> {ffi,// SAFETY: The caller guarantees the keyframe range is live.keyframes: unsafe { ak::slice_from_raw_parts(ffi.keyframes, ffi.keyframe_count) },+ additional_translation: (0.0, 0.0),}}+ pub fn set_additional_translation(&mut self, x: f32, y: f32) {+ self.additional_translation = (x, y);+ }+/// A request whose keyframe range is `keyframes`, for a unit test.#[cfg(test)]fn with_keyframes(ffi: &'a FfiCompositorAnimationRequest, keyframes: &'a [FfiCompositorAnimationKeyframe]) -> Self {assert!(std::ptr::eq(ffi.keyframes, keyframes.as_ptr()) && ffi.keyframe_count == keyframes.len());- Self { ffi, keyframes }+ Self {+ ffi,+ keyframes,+ additional_translation: (0.0, 0.0),+ }}pub fn target_kind(&self) -> FfiVisualAnimationTargetKind {@@ -203,6 +214,8 @@ impl<'a> Request<'a> {reference_box_width: self.ffi.reference_box_width,reference_box_height: self.ffi.reference_box_height,device_pixels_per_css_pixel: self.ffi.device_pixels_per_css_pixel,+ additional_translation_x: self.additional_translation.0,+ additional_translation_y: self.additional_translation.1,}}}@@ -595,6 +608,8 @@ struct KeyframeValueCacheKey {reference_box_width: f32,reference_box_height: f32,device_pixels_per_css_pixel: f32,+ additional_translation_x: f32,+ additional_translation_y: f32,}/// The values of one target kind lowered from an effect's keyframes, kept while the keyframes and@@ -689,6 +704,16 @@ fn lower_transform_keyframe(identity_shape,)?);}+ // The compositor interpolates transform lists function by function, so a function that is the same at the end of+ // every list applies after whatever the others have interpolated to.+ let (x, y) = request.additional_translation;+ if x != 0.0 || y != 0.0 {+ let scale = request.device_pixels_per_css_pixel();+ operations.push(VisualAnimationTransformOperation::new(+ FfiVisualAnimationTransformOperationKind::Translate,+ &[x * scale, y * scale],+ )?);+ }Some(Some(VisualAnimationValue::Transform(operations)))}diff --git a/Tests/LibWeb/Text/expected/css/compositor-svg-internal-transform.txt b/Tests/LibWeb/Text/expected/css/compositor-svg-internal-transform.txtindex a90dce4987a..ff9d647471c 100644--- a/Tests/LibWeb/Text/expected/css/compositor-svg-internal-transform.txt+++ b/Tests/LibWeb/Text/expected/css/compositor-svg-internal-transform.txt@@ -7,8 +7,8 @@ runs on the compositor:a rect in a group with a filter function: truea rect in a group with a clip path in user space: truea rect in a group with a mask in user space: true- a use element: false- a use element with a position: false+ a use element: true+ a use element with a position: truea nested svg: truea fading rect: truea fading group: true