Bug 237590 - Extract transform-origin handling out of RenderStyle::applyTransform()
Summary: Extract transform-origin handling out of RenderStyle::applyTransform()
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nikolas Zimmermann
URL:
Keywords: InRadar
Depends on:
Blocks: 90738 237711
  Show dependency treegraph
 
Reported: 2022-03-08 01:50 PST by Nikolas Zimmermann
Modified: 2022-03-16 03:20 PDT (History)
11 users (show)

See Also:


Attachments
Patch, v1 (7.90 KB, patch)
2022-03-08 01:53 PST, Nikolas Zimmermann
no flags Details | Formatted Diff | Diff
Patch, v2 (10.07 KB, patch)
2022-03-09 02:31 PST, Nikolas Zimmermann
no flags Details | Formatted Diff | Diff
Patch, v3 (10.07 KB, patch)
2022-03-09 03:08 PST, Nikolas Zimmermann
no flags Details | Formatted Diff | Diff
Patch, v4 (9.08 KB, patch)
2022-03-10 05:52 PST, Nikolas Zimmermann
simon.fraser: review+
ews-feeder: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Nikolas Zimmermann 2022-03-08 01:50:30 PST
RenderStyle::applyTransform() implements the algorithm given in CSS Transforms Module Level 2 (https://www.w3.org/TR/css-transforms-2/#ctm)
that yields the "current transformation matrix". It is used e.g. in RenderLayer::updateTransform() to compute the layer transformation matrix, that's used for rendering.
    
Make it possible to re-use all steps of the algorithm for SVG, by allowing to override the CSS transform by an external matrix that's used instead (SVG 2D transform).
Comment 1 Nikolas Zimmermann 2022-03-08 01:53:53 PST
Created attachment 454086 [details]
Patch, v1
Comment 2 Rob Buis 2022-03-08 07:25:11 PST
Comment on attachment 454086 [details]
Patch, v1

View in context: https://bugs.webkit.org/attachment.cgi?id=454086&action=review

> Source/WebCore/platform/graphics/transforms/TransformationMatrix.cpp:1536
> +TransformationMatrix& TransformationMatrix::multiplyAffineTransform(const AffineTransform& mat)

We probably should not abbreviate here, so either 'matrix' or 'affineTransform'.
Comment 3 Simon Fraser (smfr) 2022-03-08 09:26:58 PST
Comment on attachment 454086 [details]
Patch, v1

View in context: https://bugs.webkit.org/attachment.cgi?id=454086&action=review

> Source/WebCore/rendering/style/RenderStyle.cpp:1474
> +    if (transformOperations.size()) {
> +        for (auto& operation : transformOperations.operations())
> +            operation->apply(transform, boundingBox.size());
> +    } else if (externalAffineTransformationSource) {
> +        // SVG may provide additional non-CSS transformation operations.
> +        transform.multiplyAffineTransform(externalAffineTransformationSource());
> +    }

It's weird that this is either-or. From the function signature I would expect that the result of externalAffineTransformationSource would get multiplied with the style's transforms. Especially since this function DOES use the individual transform properties.
Comment 4 Simon Fraser (smfr) 2022-03-08 09:33:27 PST
Comment on attachment 454086 [details]
Patch, v1

View in context: https://bugs.webkit.org/attachment.cgi?id=454086&action=review

>> Source/WebCore/rendering/style/RenderStyle.cpp:1474
>> +    }
> 
> It's weird that this is either-or. From the function signature I would expect that the result of externalAffineTransformationSource would get multiplied with the style's transforms. Especially since this function DOES use the individual transform properties.

One option would be to add another function that knows how to apply/unapply transform origin, and call it from this function, and to add a third function for the custom SVG case.
Comment 5 Nikolas Zimmermann 2022-03-09 01:46:59 PST
(In reply to Simon Fraser (smfr) from comment #3)
> Comment on attachment 454086 [details]
> Patch, v1
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=454086&action=review
> 
> > Source/WebCore/rendering/style/RenderStyle.cpp:1474
> > +    if (transformOperations.size()) {
> > +        for (auto& operation : transformOperations.operations())
> > +            operation->apply(transform, boundingBox.size());
> > +    } else if (externalAffineTransformationSource) {
> > +        // SVG may provide additional non-CSS transformation operations.
> > +        transform.multiplyAffineTransform(externalAffineTransformationSource());
> > +    }
> 
> It's weird that this is either-or. From the function signature I would
> expect that the result of externalAffineTransformationSource would get
> multiplied with the style's transforms. Especially since this function DOES
> use the individual transform properties.

Good catch, the intention was to only look at 'externalAffineTransformSource' if neither the transform property nor the individual transform properties are given, but the "if (transformOperatations.size())" case only catches the transform attribute, not the rest.
Comment 6 Nikolas Zimmermann 2022-03-09 01:47:44 PST
(In reply to Simon Fraser (smfr) from comment #4)
> > It's weird that this is either-or. From the function signature I would expect that the result of externalAffineTransformationSource would get multiplied with the style's transforms. Especially since this function DOES use the individual transform properties.
> 
> One option would be to add another function that knows how to apply/unapply
> transform origin, and call it from this function, and to add a third
> function for the custom SVG case.

+1 that sounds much nicer.
Comment 7 Nikolas Zimmermann 2022-03-09 02:31:01 PST
Created attachment 454212 [details]
Patch, v2
Comment 8 Nikolas Zimmermann 2022-03-09 03:08:44 PST
Created attachment 454217 [details]
Patch, v3
Comment 9 Nikolas Zimmermann 2022-03-10 01:31:33 PST
(In reply to Rob Buis from comment #2)
> Comment on attachment 454086 [details]
> Patch, v1
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=454086&action=review
> 
> > Source/WebCore/platform/graphics/transforms/TransformationMatrix.cpp:1536
> > +TransformationMatrix& TransformationMatrix::multiplyAffineTransform(const AffineTransform& mat)
> 
> We probably should not abbreviate here, so either 'matrix' or
> 'affineTransform'.

Missed that comment, I can apply s/mat/matrix/ before landing.
Comment 10 Nikolas Zimmermann 2022-03-10 05:52:51 PST
Created attachment 454348 [details]
Patch, v4
Comment 11 Nikolas Zimmermann 2022-03-10 05:53:08 PST
(In reply to Nikolas Zimmermann from comment #9)
> (In reply to Rob Buis from comment #2)
> > Comment on attachment 454086 [details]
> > Patch, v1
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=454086&action=review
> > 
> > > Source/WebCore/platform/graphics/transforms/TransformationMatrix.cpp:1536
> > > +TransformationMatrix& TransformationMatrix::multiplyAffineTransform(const AffineTransform& mat)
> > 
> > We probably should not abbreviate here, so either 'matrix' or
> > 'affineTransform'.
> 
> Missed that comment, I can apply s/mat/matrix/ before landing.
Even easier, the changes are not needed here anymore, leaving this out for another LBSE patch.
Comment 12 Nikolas Zimmermann 2022-03-10 15:48:15 PST
Simon, can you have another look?
This slightly deviates from your proposal -- it might be helpful to look at this patch and also at https://bugs.webkit.org/show_bug.cgi?id=237711, which is the patch that enables SVG/CSS transform support for LBSE (RenderLayerModelObject::applySVGTransform() makes use of the new methods introduced here: applyTransformOrigin/unapplyTransformOrigin/affectedByTransformOrigin/etc.)

The patch on ticket 237711 depends on all of these tickets: 237553 (done), 237554 (r?), 237590 (this one), 237701 (depends on 2357554).

Once these are in, I can proceed to the patches that enable transform-box support for composited elements -- which is trivial after the cleanups are all in.
Comment 13 Radar WebKit Bug Importer 2022-03-14 08:54:29 PDT
<rdar://problem/90248514>
Comment 14 Simon Fraser (smfr) 2022-03-14 11:21:18 PDT
Comment on attachment 454348 [details]
Patch, v4

View in context: https://bugs.webkit.org/attachment.cgi?id=454348&action=review

> Source/WebCore/rendering/style/RenderStyle.cpp:1508
> +    // 8. Translate by the negated computed X, Y and Z values of transform-origin. (see unapplyTransformOrigin)

Weird to have this dangling comment here.
Comment 15 Nikolas Zimmermann 2022-03-16 03:18:17 PDT
(In reply to Simon Fraser (smfr) from comment #14)
> Comment on attachment 454348 [details]
> Patch, v4
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=454348&action=review
> 
> > Source/WebCore/rendering/style/RenderStyle.cpp:1508
> > +    // 8. Translate by the negated computed X, Y and Z values of transform-origin. (see unapplyTransformOrigin)
> 
> Weird to have this dangling comment here.

I've added (see unapplyTransformOrigin) -- modified to:
+    // 8. Translate by the negated computed X, Y and Z values of transform-origin.
+    // (implemented in unapplyTransformOrigin)

before landing. I hope that's better :-)
Comment 16 Nikolas Zimmermann 2022-03-16 03:20:04 PDT
Committed r291338 (248477@trunk): <https://commits.webkit.org/248477@trunk>