Modified: trunk/Source/WebCore/ChangeLog (291337 => 291338)
--- trunk/Source/WebCore/ChangeLog 2022-03-16 10:16:11 UTC (rev 291337)
+++ trunk/Source/WebCore/ChangeLog 2022-03-16 10:19:42 UTC (rev 291338)
@@ -1,3 +1,44 @@
+2022-03-16 Nikolas Zimmermann <[email protected]>
+
+ Extract transform-origin handling out of RenderStyle::applyTransform()
+ https://bugs.webkit.org/show_bug.cgi?id=237590
+
+ Reviewed by Simon Fraser.
+
+ 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.
+
+ LBSE wants to re-use the same algorithm, interchanging the individual
+ CSS transform properties / the CSS transform property with an external
+ AffineTransform, representing the SVG 2D transform.
+
+ Therefore split RenderStyle::applyTransform() into three main methods:
+ applyTransformOrigin / applyCSSTransform / unapplyTransformOrigin.
+
+ LBSE can call applyTransformOrigin(), multiply the TransformationMatrix
+ with the given SVG 2D AffineTransform and call unapplyTransformOrigin():
+
+ auto originTranslate = style.applyTransformOrigin(transform, boundingBox);
+ transform.multiplyAffineTransform(svgTransform.value());
+ style.unapplyTransformOrigin(transform, originTranslate);
+
+ The LBSE transform changes will follow in a separated patch, this only contains
+ the general changes. The non-SVG code paths remain unchained, since the applyTransform()
+ is kept as-is, just refactored to make use of the new (un)applyTransformOrigin() methods.
+
+ Covered by existing tests, no change in behaviour.
+
+ * rendering/style/RenderStyle.cpp:
+ (WebCore::RenderStyle::affectedByTransformOrigin const):
+ (WebCore::RenderStyle::applyTransformOrigin const):
+ (WebCore::RenderStyle::unapplyTransformOrigin const):
+ (WebCore::RenderStyle::applyTransform const):
+ (WebCore::RenderStyle::applyCSSTransform const):
+ * rendering/style/RenderStyle.h:
+
2022-03-16 Enrique Ocaña González <[email protected]>
[GStreamer] Avoid auto-selection of hole punching player
Modified: trunk/Source/WebCore/rendering/style/RenderStyle.cpp (291337 => 291338)
--- trunk/Source/WebCore/rendering/style/RenderStyle.cpp 2022-03-16 10:16:11 UTC (rev 291337)
+++ trunk/Source/WebCore/rendering/style/RenderStyle.cpp 2022-03-16 10:19:42 UTC (rev 291338)
@@ -1421,27 +1421,65 @@
SET_VAR(m_rareNonInheritedData, hasAttrContent, true);
}
-void RenderStyle::applyTransform(TransformationMatrix& transform, const FloatRect& boundingBox, OptionSet<RenderStyle::TransformOperationOption> options) const
+bool RenderStyle::affectedByTransformOrigin() const
{
- // https://www.w3.org/TR/css-transforms-2/#ctm
- // The transformation matrix is computed from the transform, transform-origin, translate, rotate, scale, and offset properties as follows:
- // 1. Start with the identity matrix.
+ if (m_rareNonInheritedData->rotate && !m_rareNonInheritedData->rotate->isIdentity())
+ return true;
+ if (m_rareNonInheritedData->scale && !m_rareNonInheritedData->scale->isIdentity())
+ return true;
+
auto& transformOperations = m_rareNonInheritedData->transform->operations;
- bool applyTransformOrigin = options.contains(RenderStyle::TransformOperationOption::TransformOrigin)
- && ((m_rareNonInheritedData->rotate && !m_rareNonInheritedData->rotate->isIdentity())
- || (m_rareNonInheritedData->scale && !m_rareNonInheritedData->scale->isIdentity())
- || transformOperations.affectedByTransformOrigin()
- || offsetPath());
+ if (transformOperations.affectedByTransformOrigin())
+ return true;
+ if (offsetPath())
+ return true;
+
+ return false;
+}
+
+FloatPoint3D RenderStyle::applyTransformOrigin(TransformationMatrix& transform, const FloatRect& boundingBox) const
+{
+ // https://www.w3.org/TR/css-transforms-2/#ctm
// 2. Translate by the computed X, Y, and Z values of transform-origin.
FloatPoint3D originTranslate;
- if (applyTransformOrigin) {
- originTranslate.setXY(boundingBox.location() + floatPointForLengthPoint(transformOriginXY(), boundingBox.size()));
- originTranslate.setZ(transformOriginZ());
+ originTranslate.setXY(boundingBox.location() + floatPointForLengthPoint(transformOriginXY(), boundingBox.size()));
+ originTranslate.setZ(transformOriginZ());
+ if (!originTranslate.isZero())
transform.translate3d(originTranslate.x(), originTranslate.y(), originTranslate.z());
+ return originTranslate;
+}
+
+void RenderStyle::unapplyTransformOrigin(TransformationMatrix& transform, const FloatPoint3D& originTranslate) const
+{
+ // https://www.w3.org/TR/css-transforms-2/#ctm
+ // 8. Translate by the negated computed X, Y and Z values of transform-origin.
+ if (!originTranslate.isZero())
+ transform.translate3d(-originTranslate.x(), -originTranslate.y(), -originTranslate.z());
+}
+
+void RenderStyle::applyTransform(TransformationMatrix& transform, const FloatRect& boundingBox, OptionSet<RenderStyle::TransformOperationOption> options) const
+{
+ if (!options.contains(RenderStyle::TransformOperationOption::TransformOrigin) || !affectedByTransformOrigin()) {
+ applyCSSTransform(transform, boundingBox, options);
+ return;
}
+ auto originTranslate = applyTransformOrigin(transform, boundingBox);
+ applyCSSTransform(transform, boundingBox, options);
+ unapplyTransformOrigin(transform, originTranslate);
+}
+
+void RenderStyle::applyCSSTransform(TransformationMatrix& transform, const FloatRect& boundingBox, OptionSet<RenderStyle::TransformOperationOption> options) const
+{
+ // https://www.w3.org/TR/css-transforms-2/#ctm
+ // The transformation matrix is computed from the transform, transform-origin, translate, rotate, scale, and offset properties as follows:
+ // 1. Start with the identity matrix.
+
+ // 2. Translate by the computed X, Y, and Z values of transform-origin.
+ // (implemented in applyTransformOrigin)
+
// 3. Translate by the computed X, Y, and Z values of translate.
if (options.contains(RenderStyle::TransformOperationOption::Translate)) {
if (TransformOperation* translate = m_rareNonInheritedData->translate.get())
@@ -1465,12 +1503,12 @@
applyMotionPathTransform(transform, boundingBox);
// 7. Multiply by each of the transform functions in transform from left to right.
+ auto& transformOperations = m_rareNonInheritedData->transform->operations;
for (auto& operation : transformOperations.operations())
operation->apply(transform, boundingBox.size());
// 8. Translate by the negated computed X, Y and Z values of transform-origin.
- if (applyTransformOrigin)
- transform.translate3d(-originTranslate.x(), -originTranslate.y(), -originTranslate.z());
+ // (implemented in unapplyTransformOrigin)
}
static std::optional<Path> getPathFromPathOperation(const FloatRect& box, const PathOperation& operation)
Modified: trunk/Source/WebCore/rendering/style/RenderStyle.h (291337 => 291338)
--- trunk/Source/WebCore/rendering/style/RenderStyle.h 2022-03-16 10:16:11 UTC (rev 291337)
+++ trunk/Source/WebCore/rendering/style/RenderStyle.h 2022-03-16 10:19:42 UTC (rev 291338)
@@ -699,7 +699,13 @@
static constexpr OptionSet<TransformOperationOption> allTransformOperations = { TransformOperationOption::TransformOrigin, TransformOperationOption::Translate, TransformOperationOption::Rotate, TransformOperationOption::Scale , TransformOperationOption::Offset };
static constexpr OptionSet<TransformOperationOption> individualTransformOperations = { TransformOperationOption::Translate, TransformOperationOption::Rotate, TransformOperationOption::Scale, TransformOperationOption::Offset };
+
+ bool affectedByTransformOrigin() const;
+ FloatPoint3D applyTransformOrigin(TransformationMatrix&, const FloatRect& boundingBox) const;
+ void unapplyTransformOrigin(TransformationMatrix&, const FloatPoint3D& originTranslate) const;
+ // applyTransform calls applyTransformOrigin(), then applyCSSTransform(), followed by unapplyTransformOrigin().
void applyTransform(TransformationMatrix&, const FloatRect& boundingBox, OptionSet<TransformOperationOption> = allTransformOperations) const;
+ void applyCSSTransform(TransformationMatrix&, const FloatRect& boundingBox, OptionSet<TransformOperationOption> = allTransformOperations) const;
void applyMotionPathTransform(TransformationMatrix&, const FloatRect& boundingBox) const;
void setPageScaleTransform(float);