Title: [266353] trunk/Source/WebCore
Revision
266353
Author
wenson_hs...@apple.com
Date
2020-08-31 08:14:57 -0700 (Mon, 31 Aug 2020)

Log Message

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.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (266352 => 266353)


--- trunk/Source/WebCore/ChangeLog	2020-08-31 15:12:49 UTC (rev 266352)
+++ trunk/Source/WebCore/ChangeLog	2020-08-31 15:14:57 UTC (rev 266353)
@@ -1,3 +1,35 @@
+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-08-31  Aditya Keerthi  <akeer...@apple.com>
 
         [macOS] Date inputs should contain editable components

Modified: trunk/Source/WebCore/platform/graphics/transforms/RotateTransformOperation.h (266352 => 266353)


--- trunk/Source/WebCore/platform/graphics/transforms/RotateTransformOperation.h	2020-08-31 15:12:49 UTC (rev 266352)
+++ trunk/Source/WebCore/platform/graphics/transforms/RotateTransformOperation.h	2020-08-31 15:14:57 UTC (rev 266353)
@@ -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: trunk/Source/WebCore/platform/graphics/transforms/TransformationMatrix.cpp (266352 => 266353)


--- trunk/Source/WebCore/platform/graphics/transforms/TransformationMatrix.cpp	2020-08-31 15:12:49 UTC (rev 266352)
+++ trunk/Source/WebCore/platform/graphics/transforms/TransformationMatrix.cpp	2020-08-31 15:14:57 UTC (rev 266353)
@@ -897,6 +897,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: trunk/Source/WebCore/platform/graphics/transforms/TransformationMatrix.h (266352 => 266353)


--- trunk/Source/WebCore/platform/graphics/transforms/TransformationMatrix.h	2020-08-31 15:12:49 UTC (rev 266352)
+++ trunk/Source/WebCore/platform/graphics/transforms/TransformationMatrix.h	2020-08-31 15:14:57 UTC (rev 266353)
@@ -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