Title: [292575] trunk/Source/WebCore
Revision
292575
Author
[email protected]
Date
2022-04-07 15:56:25 -0700 (Thu, 07 Apr 2022)

Log Message

Unify reference box / CTM computation in RenderLayer
https://bugs.webkit.org/show_bug.cgi?id=237701

Reviewed by Rob Buis.

Extract the code in RenderLayer that computes the reference box, obtains the CTM,
applies pixel snapping, etc. into a shared updateTransformFromStyle() helper function.
Use that helper to de-duplicate code between updateTransform() / currentTransform()
(and RenderLayerBacking::updateTransform() in follow-up patches).

currentTransform() needs to compute the CTM, based on a non-default RenderStyle (!= renderer().style()),
namely the aninmatedStyle(), if an accelerated transform animation is running. Therefore extend
RenderLayerModelObject::applyTransform() to take an additional RenderStyle parameter,
that is used to access the CSS transform operations, instead of always querying renderer().style().
RenderLayer::updateTransform() continues to pass 'renderer().style()' to updateTransformFromStyle(),
whereas RenderLayer::currentTransform() passes the elements animatedStyle().

Covered by existing tests, no change in behaviour.

* rendering/RenderBox.cpp:
(WebCore::RenderBox::applyTransform const):
* rendering/RenderBox.h:
* rendering/RenderBoxModelObject.cpp:
(WebCore::RenderBoxModelObject::applyTransform const):
* rendering/RenderBoxModelObject.h:
* rendering/RenderLayer.cpp:
(WebCore::RenderLayer::updateTransformFromStyle const):
(WebCore::RenderLayer::updateTransform):
(WebCore::RenderLayer::currentTransform const):
* rendering/RenderLayer.h:
* rendering/RenderLayerBacking.cpp:
(WebCore::RenderLayerBacking::updateTransform):
* rendering/RenderLayerModelObject.h:
* rendering/svg/RenderSVGModelObject.cpp:
(WebCore::RenderSVGModelObject::applyTransform const): Deleted.
* rendering/svg/RenderSVGModelObject.h:
* rendering/svg/RenderSVGRoot.cpp:
(WebCore::RenderSVGRoot::applyTransform const): Deleted.
* rendering/svg/RenderSVGRoot.h:
* rendering/svg/RenderSVGShape.cpp:
(WebCore::RenderSVGShape::applyTransform const):
* rendering/svg/RenderSVGShape.h:
* rendering/svg/RenderSVGTransformableContainer.cpp:
(WebCore::RenderSVGTransformableContainer::applyTransform const):
* rendering/svg/RenderSVGTransformableContainer.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (292574 => 292575)


--- trunk/Source/WebCore/ChangeLog	2022-04-07 22:50:19 UTC (rev 292574)
+++ trunk/Source/WebCore/ChangeLog	2022-04-07 22:56:25 UTC (rev 292575)
@@ -1,3 +1,51 @@
+2022-04-07  Nikolas Zimmermann  <[email protected]>
+
+        Unify reference box / CTM computation in RenderLayer
+        https://bugs.webkit.org/show_bug.cgi?id=237701
+
+        Reviewed by Rob Buis.
+
+        Extract the code in RenderLayer that computes the reference box, obtains the CTM,
+        applies pixel snapping, etc. into a shared updateTransformFromStyle() helper function.
+        Use that helper to de-duplicate code between updateTransform() / currentTransform()
+        (and RenderLayerBacking::updateTransform() in follow-up patches).
+
+        currentTransform() needs to compute the CTM, based on a non-default RenderStyle (!= renderer().style()),
+        namely the aninmatedStyle(), if an accelerated transform animation is running. Therefore extend
+        RenderLayerModelObject::applyTransform() to take an additional RenderStyle parameter,
+        that is used to access the CSS transform operations, instead of always querying renderer().style().
+        RenderLayer::updateTransform() continues to pass 'renderer().style()' to updateTransformFromStyle(),
+        whereas RenderLayer::currentTransform() passes the elements animatedStyle().
+
+        Covered by existing tests, no change in behaviour.
+
+        * rendering/RenderBox.cpp:
+        (WebCore::RenderBox::applyTransform const):
+        * rendering/RenderBox.h:
+        * rendering/RenderBoxModelObject.cpp:
+        (WebCore::RenderBoxModelObject::applyTransform const):
+        * rendering/RenderBoxModelObject.h:
+        * rendering/RenderLayer.cpp:
+        (WebCore::RenderLayer::updateTransformFromStyle const):
+        (WebCore::RenderLayer::updateTransform):
+        (WebCore::RenderLayer::currentTransform const):
+        * rendering/RenderLayer.h:
+        * rendering/RenderLayerBacking.cpp:
+        (WebCore::RenderLayerBacking::updateTransform):
+        * rendering/RenderLayerModelObject.h:
+        * rendering/svg/RenderSVGModelObject.cpp:
+        (WebCore::RenderSVGModelObject::applyTransform const): Deleted.
+        * rendering/svg/RenderSVGModelObject.h:
+        * rendering/svg/RenderSVGRoot.cpp:
+        (WebCore::RenderSVGRoot::applyTransform const): Deleted.
+        * rendering/svg/RenderSVGRoot.h:
+        * rendering/svg/RenderSVGShape.cpp:
+        (WebCore::RenderSVGShape::applyTransform const):
+        * rendering/svg/RenderSVGShape.h:
+        * rendering/svg/RenderSVGTransformableContainer.cpp:
+        (WebCore::RenderSVGTransformableContainer::applyTransform const):
+        * rendering/svg/RenderSVGTransformableContainer.h:
+
 2022-04-07  Jean-Yves Avenard  <[email protected]>
 
         Full screen video progress bar flickers after dragging it.

Modified: trunk/Source/WebCore/rendering/RenderBox.cpp (292574 => 292575)


--- trunk/Source/WebCore/rendering/RenderBox.cpp	2022-04-07 22:50:19 UTC (rev 292574)
+++ trunk/Source/WebCore/rendering/RenderBox.cpp	2022-04-07 22:56:25 UTC (rev 292575)
@@ -674,9 +674,9 @@
         layer()->updateTransform();
 }
 
-void RenderBox::applyTransform(TransformationMatrix& t, const FloatRect& boundingBox, OptionSet<RenderStyle::TransformOperationOption> options) const
+void RenderBox::applyTransform(TransformationMatrix& t, const RenderStyle& style, const FloatRect& boundingBox, OptionSet<RenderStyle::TransformOperationOption> options) const
 {
-    style().applyTransform(t, boundingBox, options);
+    style.applyTransform(t, boundingBox, options);
 }
 
 LayoutUnit RenderBox::constrainLogicalWidthInFragmentByMinMax(LayoutUnit logicalWidth, LayoutUnit availableWidth, RenderBlock& cb, RenderFragmentContainer* fragment, AllowIntrinsic allowIntrinsic) const

Modified: trunk/Source/WebCore/rendering/RenderBox.h (292574 => 292575)


--- trunk/Source/WebCore/rendering/RenderBox.h	2022-04-07 22:50:19 UTC (rev 292574)
+++ trunk/Source/WebCore/rendering/RenderBox.h	2022-04-07 22:56:25 UTC (rev 292575)
@@ -219,7 +219,7 @@
     void addOverflowFromChild(const RenderBox* child, const LayoutSize& delta);
 
     void updateLayerTransform();
-    void applyTransform(TransformationMatrix&, const FloatRect& boundingBox, OptionSet<RenderStyle::TransformOperationOption> = RenderStyle::allTransformOperations) const override;
+    void applyTransform(TransformationMatrix&, const RenderStyle&, const FloatRect& boundingBox, OptionSet<RenderStyle::TransformOperationOption> = RenderStyle::allTransformOperations) const override;
 
     LayoutSize contentSize() const { return { contentWidth(), contentHeight() }; }
     LayoutUnit contentWidth() const { return std::max(0_lu, paddingBoxWidth() - paddingLeft() - paddingRight()); }

Modified: trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp (292574 => 292575)


--- trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp	2022-04-07 22:50:19 UTC (rev 292574)
+++ trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp	2022-04-07 22:56:25 UTC (rev 292575)
@@ -2706,7 +2706,7 @@
     }
 }
 
-void RenderBoxModelObject::applyTransform(TransformationMatrix&, const FloatRect&, OptionSet<RenderStyle::TransformOperationOption>) const
+void RenderBoxModelObject::applyTransform(TransformationMatrix&, const RenderStyle&, const FloatRect&, OptionSet<RenderStyle::TransformOperationOption>) const
 {
     // applyTransform() is only used through RenderLayer*, which only invokes this for RenderBox derived renderers, thus not for
     // RenderInline/RenderLineBreak - the other two renderers that inherit from RenderBoxModelObject.

Modified: trunk/Source/WebCore/rendering/RenderBoxModelObject.h (292574 => 292575)


--- trunk/Source/WebCore/rendering/RenderBoxModelObject.h	2022-04-07 22:50:19 UTC (rev 292574)
+++ trunk/Source/WebCore/rendering/RenderBoxModelObject.h	2022-04-07 22:56:25 UTC (rev 292575)
@@ -254,7 +254,7 @@
     virtual bool hasOverridingContainingBlockContentWidth() const { return false; }
     virtual bool hasOverridingContainingBlockContentHeight() const { return false; }
 
-    void applyTransform(TransformationMatrix&, const FloatRect& boundingBox, OptionSet<RenderStyle::TransformOperationOption> = RenderStyle::allTransformOperations) const override;
+    void applyTransform(TransformationMatrix&, const RenderStyle&, const FloatRect& boundingBox, OptionSet<RenderStyle::TransformOperationOption> = RenderStyle::allTransformOperations) const override;
 
 protected:
     RenderBoxModelObject(Element&, RenderStyle&&, BaseTypeFlags);

Modified: trunk/Source/WebCore/rendering/RenderLayer.cpp (292574 => 292575)


--- trunk/Source/WebCore/rendering/RenderLayer.cpp	2022-04-07 22:50:19 UTC (rev 292574)
+++ trunk/Source/WebCore/rendering/RenderLayer.cpp	2022-04-07 22:56:25 UTC (rev 292575)
@@ -1310,6 +1310,13 @@
     return referenceBoxRect;
 }
 
+void RenderLayer::updateTransformFromStyle(TransformationMatrix& transform, const RenderStyle& style, OptionSet<RenderStyle::TransformOperationOption> options) const
+{
+    auto referenceBoxRect = snapRectToDevicePixelsIfNeeded(renderer().transformReferenceBoxRect(style), renderer());
+    renderer().applyTransform(transform, style, referenceBoxRect, options);
+    makeMatrixRenderable(transform, canRender3DTransforms());
+}
+
 void RenderLayer::updateTransform()
 {
     bool hasTransform = renderer().hasTransform();
@@ -1335,9 +1342,7 @@
             boxPathOperation.setPathForReferenceRect(FloatRoundedRect { pathReferenceBoxRect });
         }
 
-        auto referenceBoxRect = snapRectToDevicePixelsIfNeeded(renderer().transformReferenceBoxRect(renderer().style()), renderer());
-        renderer().applyTransform(*m_transform, referenceBoxRect);
-        makeMatrixRenderable(*m_transform, canRender3DTransforms());
+        updateTransformFromStyle(*m_transform, renderer().style(), RenderStyle::allTransformOperations);
     }
 
     if (had3DTransform != has3DTransform()) {
@@ -1365,11 +1370,9 @@
     auto styleable = Styleable::fromRenderer(renderBox);
     if ((styleable && styleable->isRunningAcceleratedTransformAnimation()) || !options.contains(RenderStyle::TransformOperationOption::TransformOrigin)) {
         std::unique_ptr<RenderStyle> animatedStyle = renderBox.animatedStyle();
-        auto referenceBoxRect = snapRectToDevicePixelsIfNeeded(renderer().transformReferenceBoxRect(*animatedStyle), renderer());
 
         TransformationMatrix transform;
-        animatedStyle->applyTransform(transform, referenceBoxRect, options);
-        makeMatrixRenderable(transform, canRender3DTransforms());
+        updateTransformFromStyle(transform, *animatedStyle, options);
         return transform;
     }
 

Modified: trunk/Source/WebCore/rendering/RenderLayer.h (292574 => 292575)


--- trunk/Source/WebCore/rendering/RenderLayer.h	2022-04-07 22:50:19 UTC (rev 292574)
+++ trunk/Source/WebCore/rendering/RenderLayer.h	2022-04-07 22:56:25 UTC (rev 292575)
@@ -730,9 +730,11 @@
     bool hasTransform() const { return renderer().hasTransform(); }
     // Note that this transform has the transform-origin baked in.
     TransformationMatrix* transform() const { return m_transform.get(); }
+    // updateTransformFromStyle computes a transform according to the passed options (e.g. transform-origin baked in or excluded) and the given style.
+    void updateTransformFromStyle(TransformationMatrix&, const RenderStyle&, OptionSet<RenderStyle::TransformOperationOption>) const;
     // currentTransform computes a transform which takes accelerated animations into account. The
-    // resulting transform has transform-origin baked in. If the layer does not have a transform,
-    // returns the identity matrix.
+    // resulting transform has transform-origin baked in, unless non-default options are given. If
+    // the layer does not have a transform, the identity matrix is returned.
     TransformationMatrix currentTransform(OptionSet<RenderStyle::TransformOperationOption> = RenderStyle::allTransformOperations) const;
     TransformationMatrix renderableTransform(OptionSet<PaintBehavior>) const;
     

Modified: trunk/Source/WebCore/rendering/RenderLayerBacking.cpp (292574 => 292575)


--- trunk/Source/WebCore/rendering/RenderLayerBacking.cpp	2022-04-07 22:50:19 UTC (rev 292574)
+++ trunk/Source/WebCore/rendering/RenderLayerBacking.cpp	2022-04-07 22:56:25 UTC (rev 292575)
@@ -643,7 +643,8 @@
     // baked into it, and we don't want that.
     TransformationMatrix t;
     if (m_owningLayer.hasTransform()) {
-        renderer().applyTransform(t, snapRectToDevicePixels(m_owningLayer.rendererBorderBoxRect(), deviceScaleFactor()), RenderStyle::individualTransformOperations);
+        // FIXME: This uses the wrong, transform-box unaware, geometry.
+        renderer().applyTransform(t, renderer().style(), snapRectToDevicePixels(m_owningLayer.rendererBorderBoxRect(), deviceScaleFactor()), RenderStyle::individualTransformOperations);
         makeMatrixRenderable(t, compositor().canRender3DTransforms());
     }
     

Modified: trunk/Source/WebCore/rendering/RenderLayerModelObject.h (292574 => 292575)


--- trunk/Source/WebCore/rendering/RenderLayerModelObject.h	2022-04-07 22:50:19 UTC (rev 292574)
+++ trunk/Source/WebCore/rendering/RenderLayerModelObject.h	2022-04-07 22:56:25 UTC (rev 292575)
@@ -77,7 +77,7 @@
     void mapLocalToSVGContainer(const RenderLayerModelObject* ancestorContainer, TransformState&, OptionSet<MapCoordinatesMode>, bool* wasFixed) const;
 #endif
 
-    virtual void applyTransform(TransformationMatrix&, const FloatRect& boundingBox, OptionSet<RenderStyle::TransformOperationOption> = RenderStyle::allTransformOperations) const = 0;
+    virtual void applyTransform(TransformationMatrix&, const RenderStyle&, const FloatRect& boundingBox, OptionSet<RenderStyle::TransformOperationOption> = RenderStyle::allTransformOperations) const = 0;
 
 protected:
     RenderLayerModelObject(Element&, RenderStyle&&, BaseTypeFlags);

Modified: trunk/Source/WebCore/rendering/svg/RenderSVGModelObject.cpp (292574 => 292575)


--- trunk/Source/WebCore/rendering/svg/RenderSVGModelObject.cpp	2022-04-07 22:50:19 UTC (rev 292574)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGModelObject.cpp	2022-04-07 22:56:25 UTC (rev 292575)
@@ -276,15 +276,6 @@
     return rect.contains(ctm.mapRect(renderer->repaintRectInLocalCoordinates()));
 }
 
-void RenderSVGModelObject::applyTransform(TransformationMatrix& transform, const FloatRect& boundingBox, OptionSet<RenderStyle::TransformOperationOption> options) const
-{
-    UNUSED_PARAM(transform);
-    UNUSED_PARAM(boundingBox);
-    UNUSED_PARAM(options);
-    // FIXME: [LBSE] Upstream SVGRenderSupport changes
-    // SVGRenderSupport::applyTransform(*this, transform, style, boundingBox, std::nullopt, std::nullopt, options);
-}
-
 } // namespace WebCore
 
 #endif // ENABLE(LAYER_BASED_SVG_ENGINE)

Modified: trunk/Source/WebCore/rendering/svg/RenderSVGModelObject.h (292574 => 292575)


--- trunk/Source/WebCore/rendering/svg/RenderSVGModelObject.h	2022-04-07 22:50:19 UTC (rev 292574)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGModelObject.h	2022-04-07 22:56:25 UTC (rev 292575)
@@ -58,8 +58,6 @@
 
     inline SVGElement& element() const;
 
-    void applyTransform(TransformationMatrix&, const FloatRect& boundingBox, OptionSet<RenderStyle::TransformOperationOption> = RenderStyle::allTransformOperations) const override;
-
     // Mimic the RenderBox accessors - by sharing the same terminology the painting / hit testing / layout logic is
     // similar to read compared to non-SVG renderers such as RenderBox & friends.
     LayoutRect borderBoxRectEquivalent() const { return { LayoutPoint(), m_layoutRect.size() }; }

Modified: trunk/Source/WebCore/rendering/svg/RenderSVGRoot.cpp (292574 => 292575)


--- trunk/Source/WebCore/rendering/svg/RenderSVGRoot.cpp	2022-04-07 22:50:19 UTC (rev 292574)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGRoot.cpp	2022-04-07 22:56:25 UTC (rev 292575)
@@ -606,14 +606,6 @@
     return clipRect;
 }
 
-void RenderSVGRoot::applyTransform(TransformationMatrix& transform, const FloatRect& boundingBox, OptionSet<RenderStyle::TransformOperationOption> options) const
-{
-    RenderReplaced::applyTransform(transform, boundingBox, options);
-
-    // FIXME: [LBSE] Upstream SVGRenderSupport changes
-    // SVGRenderSupport::applyTransform(*this, transform, style, boundingBox, std::nullopt, std::nullopt, options);
-}
-
 void RenderSVGRoot::absoluteRects(Vector<IntRect>& rects, const LayoutPoint& accumulatedOffset) const
 {
     auto localRect = LayoutRect(valueOrDefault(m_supplementalLocalToParentTransform.inverse()).mapRect(borderBoxRect()));

Modified: trunk/Source/WebCore/rendering/svg/RenderSVGRoot.h (292574 => 292575)


--- trunk/Source/WebCore/rendering/svg/RenderSVGRoot.h	2022-04-07 22:50:19 UTC (rev 292574)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGRoot.h	2022-04-07 22:56:25 UTC (rev 292575)
@@ -66,8 +66,6 @@
 
     bool shouldApplyViewportClip() const;
 
-    void applyTransform(TransformationMatrix&, const FloatRect& boundingBox, OptionSet<RenderStyle::TransformOperationOption> = RenderStyle::allTransformOperations) const final;
-
     FloatRect objectBoundingBox() const final { return m_objectBoundingBox; }
     FloatRect strokeBoundingBox() const final { return m_strokeBoundingBox; }
     FloatRect repaintRectInLocalCoordinates() const final { return SVGBoundingBoxComputation::computeRepaintBoundingBox(*this); }

Modified: trunk/Source/WebCore/rendering/svg/RenderSVGShape.cpp (292574 => 292575)


--- trunk/Source/WebCore/rendering/svg/RenderSVGShape.cpp	2022-04-07 22:50:19 UTC (rev 292574)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGShape.cpp	2022-04-07 22:56:25 UTC (rev 292575)
@@ -534,6 +534,12 @@
     RenderSVGModelObject::styleWillChange(diff, newStyle);
 }
 
+void RenderSVGShape::applyTransform(TransformationMatrix& transform, const RenderStyle& style, const FloatRect& boundingBox, OptionSet<RenderStyle::TransformOperationOption> options) const
+{
+    // FIXME: [LBSE] Upstream CSS/SVG transform support
+    style.applyTransform(transform, boundingBox, options);
 }
 
+}
+
 #endif // ENABLE(LAYER_BASED_SVG_ENGINE)

Modified: trunk/Source/WebCore/rendering/svg/RenderSVGShape.h (292574 => 292575)


--- trunk/Source/WebCore/rendering/svg/RenderSVGShape.h	2022-04-07 22:50:19 UTC (rev 292574)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGShape.h	2022-04-07 22:56:25 UTC (rev 292575)
@@ -82,6 +82,8 @@
 
     FloatRect computeMarkerBoundingBox(const SVGBoundingBoxComputation::DecorationOptions&) const;
 
+    void applyTransform(TransformationMatrix&, const RenderStyle&, const FloatRect& boundingBox, OptionSet<RenderStyle::TransformOperationOption> = RenderStyle::allTransformOperations) const override;
+
 protected:
     void element() const = delete;
 

Modified: trunk/Source/WebCore/rendering/svg/RenderSVGTransformableContainer.cpp (292574 => 292575)


--- trunk/Source/WebCore/rendering/svg/RenderSVGTransformableContainer.cpp	2022-04-07 22:50:19 UTC (rev 292574)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGTransformableContainer.cpp	2022-04-07 22:56:25 UTC (rev 292575)
@@ -102,10 +102,10 @@
     //    setHasSVGTransform();
 }
 
-void RenderSVGTransformableContainer::applyTransform(TransformationMatrix& transform, const FloatRect& boundingBox, OptionSet<RenderStyle::TransformOperationOption> options) const
+void RenderSVGTransformableContainer::applyTransform(TransformationMatrix& transform, const RenderStyle& style, const FloatRect& boundingBox, OptionSet<RenderStyle::TransformOperationOption> options) const
 {
     // FIXME: [LBSE] Upstream CSS/SVG transform support
-    RenderSVGContainer::applyTransform(transform, boundingBox, options);
+    style.applyTransform(transform, boundingBox, options);
 }
 
 void RenderSVGTransformableContainer::styleWillChange(StyleDifference diff, const RenderStyle& newStyle)

Modified: trunk/Source/WebCore/rendering/svg/RenderSVGTransformableContainer.h (292574 => 292575)


--- trunk/Source/WebCore/rendering/svg/RenderSVGTransformableContainer.h	2022-04-07 22:50:19 UTC (rev 292574)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGTransformableContainer.h	2022-04-07 22:56:25 UTC (rev 292575)
@@ -45,7 +45,7 @@
     void layoutChildren() final;
     void calculateViewport() final;
     FloatPoint additionalContainerTranslation() const;
-    void applyTransform(TransformationMatrix&, const FloatRect& boundingBox, OptionSet<RenderStyle::TransformOperationOption> = RenderStyle::allTransformOperations) const final;
+    void applyTransform(TransformationMatrix&, const RenderStyle&, const FloatRect& boundingBox, OptionSet<RenderStyle::TransformOperationOption> = RenderStyle::allTransformOperations) const final;
     void styleWillChange(StyleDifference, const RenderStyle& newStyle) final;
     void updateFromStyle() final;
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to