Title: [267581] branches/safari-610-branch/Source/WebCore
Revision
267581
Author
alanc...@apple.com
Date
2020-09-25 11:20:53 -0700 (Fri, 25 Sep 2020)

Log Message

Cherry-pick r266353. rdar://problem/69382920

    Optimize the implementation of TransformationMatrix::rotate(double)
    https://bugs.webkit.org/show_bug.cgi?id=215994

    Reviewed by Tim Horton.

    TransformationMatrix::rotate(angle) currently just calls TransformationMatrix::rotate3d(0, 0, 1, angle), which
    has a fast path for the case where we're rotating about the z-axis. However, we can make this *slightly* faster
    by omitting the hypotenuse computation, several floating point comparisons, and several assignments in this case
    because we already know that we're just rotating about the z-axis.

    This is a small (but measurable) improvement on the Multiply subtest of MotionMark, which applies a little over
    3 million rotation transformations over the course of 30 seconds.

    * platform/graphics/transforms/RotateTransformOperation.h:

    Instead of calling `rotate3d`, just have `rotate` directly call `multiply` with the following
    `TransformationMatrix`:
    ```
    [[  cos(z)  sin(z)  0   0 ]
     [  -sin(z) cos(z)  0   0 ]
     [  0       0       1   0 ]
     [  0       0       0   1 ]]
    ```
    ...where `z` is the angle of rotation, in radians.

    * platform/graphics/transforms/TransformationMatrix.cpp:
    (WebCore::TransformationMatrix::rotate):
    * platform/graphics/transforms/TransformationMatrix.h:
    (WebCore::TransformationMatrix::rotate): Deleted.

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@266353 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Diff

Modified: branches/safari-610-branch/Source/WebCore/ChangeLog (267580 => 267581)


--- branches/safari-610-branch/Source/WebCore/ChangeLog	2020-09-25 18:20:50 UTC (rev 267580)
+++ branches/safari-610-branch/Source/WebCore/ChangeLog	2020-09-25 18:20:53 UTC (rev 267581)
@@ -1,5 +1,74 @@
 2020-09-22  Alan Coon  <alanc...@apple.com>
 
+        Cherry-pick r266353. rdar://problem/69382920
+
+    Optimize the implementation of TransformationMatrix::rotate(double)
+    https://bugs.webkit.org/show_bug.cgi?id=215994
+    
+    Reviewed by Tim Horton.
+    
+    TransformationMatrix::rotate(angle) currently just calls TransformationMatrix::rotate3d(0, 0, 1, angle), which
+    has a fast path for the case where we're rotating about the z-axis. However, we can make this *slightly* faster
+    by omitting the hypotenuse computation, several floating point comparisons, and several assignments in this case
+    because we already know that we're just rotating about the z-axis.
+    
+    This is a small (but measurable) improvement on the Multiply subtest of MotionMark, which applies a little over
+    3 million rotation transformations over the course of 30 seconds.
+    
+    * platform/graphics/transforms/RotateTransformOperation.h:
+    
+    Instead of calling `rotate3d`, just have `rotate` directly call `multiply` with the following
+    `TransformationMatrix`:
+    ```
+    [[  cos(z)  sin(z)  0   0 ]
+     [  -sin(z) cos(z)  0   0 ]
+     [  0       0       1   0 ]
+     [  0       0       0   1 ]]
+    ```
+    ...where `z` is the angle of rotation, in radians.
+    
+    * platform/graphics/transforms/TransformationMatrix.cpp:
+    (WebCore::TransformationMatrix::rotate):
+    * platform/graphics/transforms/TransformationMatrix.h:
+    (WebCore::TransformationMatrix::rotate): Deleted.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@266353 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2020-08-31  Wenson Hsieh  <wenson_hs...@apple.com>
+
+            Optimize the implementation of TransformationMatrix::rotate(double)
+            https://bugs.webkit.org/show_bug.cgi?id=215994
+
+            Reviewed by Tim Horton.
+
+            TransformationMatrix::rotate(angle) currently just calls TransformationMatrix::rotate3d(0, 0, 1, angle), which
+            has a fast path for the case where we're rotating about the z-axis. However, we can make this *slightly* faster
+            by omitting the hypotenuse computation, several floating point comparisons, and several assignments in this case
+            because we already know that we're just rotating about the z-axis.
+
+            This is a small (but measurable) improvement on the Multiply subtest of MotionMark, which applies a little over
+            3 million rotation transformations over the course of 30 seconds.
+
+            * platform/graphics/transforms/RotateTransformOperation.h:
+
+            Instead of calling `rotate3d`, just have `rotate` directly call `multiply` with the following
+            `TransformationMatrix`:
+            ```
+            [[  cos(z)  sin(z)  0   0 ]
+             [  -sin(z) cos(z)  0   0 ]
+             [  0       0       1   0 ]
+             [  0       0       0   1 ]]
+            ```
+            ...where `z` is the angle of rotation, in radians.
+
+            * platform/graphics/transforms/TransformationMatrix.cpp:
+            (WebCore::TransformationMatrix::rotate):
+            * platform/graphics/transforms/TransformationMatrix.h:
+            (WebCore::TransformationMatrix::rotate): Deleted.
+
+2020-09-22  Alan Coon  <alanc...@apple.com>
+
         Cherry-pick r266198. rdar://problem/69382901
 
     Avoid unnecessarily copying a Vector in WebCore::transformsForValue

Modified: branches/safari-610-branch/Source/WebCore/platform/graphics/transforms/RotateTransformOperation.h (267580 => 267581)


--- branches/safari-610-branch/Source/WebCore/platform/graphics/transforms/RotateTransformOperation.h	2020-09-25 18:20:50 UTC (rev 267580)
+++ branches/safari-610-branch/Source/WebCore/platform/graphics/transforms/RotateTransformOperation.h	2020-09-25 18:20:53 UTC (rev 267581)
@@ -60,7 +60,10 @@
 
     bool apply(TransformationMatrix& transform, const FloatSize& /*borderBoxSize*/) const override
     {
-        transform.rotate3d(m_x, m_y, m_z, m_angle);
+        if (type() == TransformOperation::ROTATE)
+            transform.rotate(m_angle);
+        else
+            transform.rotate3d(m_x, m_y, m_z, m_angle);
         return false;
     }
 

Modified: branches/safari-610-branch/Source/WebCore/platform/graphics/transforms/TransformationMatrix.cpp (267580 => 267581)


--- branches/safari-610-branch/Source/WebCore/platform/graphics/transforms/TransformationMatrix.cpp	2020-09-25 18:20:50 UTC (rev 267580)
+++ branches/safari-610-branch/Source/WebCore/platform/graphics/transforms/TransformationMatrix.cpp	2020-09-25 18:20:53 UTC (rev 267581)
@@ -947,6 +947,15 @@
     return *this;
 }
 
+TransformationMatrix& TransformationMatrix::rotate(double angle)
+{
+    angle = deg2rad(angle);
+    double sinZ = sin(angle);
+    double cosZ = cos(angle);
+    multiply({ cosZ, sinZ, -sinZ, cosZ, 0, 0 });
+    return *this;
+}
+
 TransformationMatrix& TransformationMatrix::rotate3d(double rx, double ry, double rz)
 {
     // Angles are in degrees. Switch to radians.

Modified: branches/safari-610-branch/Source/WebCore/platform/graphics/transforms/TransformationMatrix.h (267580 => 267581)


--- branches/safari-610-branch/Source/WebCore/platform/graphics/transforms/TransformationMatrix.h	2020-09-25 18:20:50 UTC (rev 267580)
+++ branches/safari-610-branch/Source/WebCore/platform/graphics/transforms/TransformationMatrix.h	2020-09-25 18:20:53 UTC (rev 267581)
@@ -253,7 +253,7 @@
     TransformationMatrix& scale3d(double sx, double sy, double sz);
 
     // Angle is in degrees.
-    TransformationMatrix& rotate(double d) { return rotate3d(0, 0, d); }
+    WEBCORE_EXPORT TransformationMatrix& rotate(double);
     TransformationMatrix& rotateFromVector(double x, double y);
     WEBCORE_EXPORT TransformationMatrix& rotate3d(double rx, double ry, double rz);
     
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to