⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 266353 in webkit


Ignore:
Timestamp:
Aug 31, 2020, 8:14:57 AM (6 years ago)
Author:
Wenson Hsieh
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.

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r266351 r266353  
     12020-08-31  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Optimize the implementation of TransformationMatrix::rotate(double)
     4        https://bugs.webkit.org/show_bug.cgi?id=215994
     5
     6        Reviewed by Tim Horton.
     7
     8        TransformationMatrix::rotate(angle) currently just calls TransformationMatrix::rotate3d(0, 0, 1, angle), which
     9        has a fast path for the case where we're rotating about the z-axis. However, we can make this *slightly* faster
     10        by omitting the hypotenuse computation, several floating point comparisons, and several assignments in this case
     11        because we already know that we're just rotating about the z-axis.
     12
     13        This is a small (but measurable) improvement on the Multiply subtest of MotionMark, which applies a little over
     14        3 million rotation transformations over the course of 30 seconds.
     15
     16        * platform/graphics/transforms/RotateTransformOperation.h:
     17
     18        Instead of calling `rotate3d`, just have `rotate` directly call `multiply` with the following
     19        `TransformationMatrix`:
     20        ```
     21        [[  cos(z)  sin(z)  0   0 ]
     22         [  -sin(z) cos(z)  0   0 ]
     23         [  0       0       1   0 ]
     24         [  0       0       0   1 ]]
     25        ```
     26        ...where `z` is the angle of rotation, in radians.
     27
     28        * platform/graphics/transforms/TransformationMatrix.cpp:
     29        (WebCore::TransformationMatrix::rotate):
     30        * platform/graphics/transforms/TransformationMatrix.h:
     31        (WebCore::TransformationMatrix::rotate): Deleted.
     32
    1332020-08-31  Aditya Keerthi  <akeerthi@apple.com>
    234
  • trunk/Source/WebCore/platform/graphics/transforms/RotateTransformOperation.h

    r234330 r266353  
    6161    bool apply(TransformationMatrix& transform, const FloatSize& /*borderBoxSize*/) const override
    6262    {
    63         transform.rotate3d(m_x, m_y, m_z, m_angle);
     63        if (type() == TransformOperation::ROTATE)
     64            transform.rotate(m_angle);
     65        else
     66            transform.rotate3d(m_x, m_y, m_z, m_angle);
    6467        return false;
    6568    }
  • trunk/Source/WebCore/platform/graphics/transforms/TransformationMatrix.cpp

    r255559 r266353  
    898898}
    899899
     900TransformationMatrix& TransformationMatrix::rotate(double angle)
     901{
     902    angle = deg2rad(angle);
     903    double sinZ = sin(angle);
     904    double cosZ = cos(angle);
     905    multiply({ cosZ, sinZ, -sinZ, cosZ, 0, 0 });
     906    return *this;
     907}
     908
    900909TransformationMatrix& TransformationMatrix::rotate3d(double rx, double ry, double rz)
    901910{
  • trunk/Source/WebCore/platform/graphics/transforms/TransformationMatrix.h

    r264031 r266353  
    254254
    255255    // Angle is in degrees.
    256     TransformationMatrix& rotate(double d) { return rotate3d(0, 0, d); }
     256    WEBCORE_EXPORT TransformationMatrix& rotate(double);
    257257    TransformationMatrix& rotateFromVector(double x, double y);
    258258    WEBCORE_EXPORT TransformationMatrix& rotate3d(double rx, double ry, double rz);
Note: See TracChangeset for help on using the changeset viewer.