Changeset 169320 in webkit


Ignore:
Timestamp:
May 25, 2014 11:09:16 AM (10 years ago)
Author:
ddkilzer@apple.com
Message:

Add type-checked casts for TransformOperations
<http://webkit.org/b/133217>

Reviewed by Simon Fraser.

Source/WebCore:

  • platform/graphics/GraphicsLayer.cpp:

(WebCore::GraphicsLayer::validateTransformOperations):

  • platform/graphics/ca/GraphicsLayerCA.cpp:

(WebCore::getTransformFunctionValue):

  • Switch to type-checked casts.
  • platform/graphics/transforms/IdentityTransformOperation.h:
  • platform/graphics/transforms/Matrix3DTransformOperation.h:
  • platform/graphics/transforms/MatrixTransformOperation.h:
  • platform/graphics/transforms/PerspectiveTransformOperation.h:
  • platform/graphics/transforms/RotateTransformOperation.h:
  • platform/graphics/transforms/ScaleTransformOperation.h:
  • platform/graphics/transforms/SkewTransformOperation.h:
  • platform/graphics/transforms/TranslateTransformOperation.h:
  • Add 'final' to class declaration.
  • Add 'override' to overridden methods.
  • Add type-checked cast via TRANSFORMOPERATION_TYPE_CASTS macro.
  • Move implementation of operator==(const TransformOperation&) from header to source file so it is able to use a type-checked cast, and switch back to using a reference instead of a pointer.
  • Add or update ASSERT in private constructor to check for correct OperationType in classes that represent multiple types.
  • platform/graphics/transforms/Matrix3DTransformOperation.cpp:

(WebCore::Matrix3DTransformOperation::operator==): Added.

  • platform/graphics/transforms/MatrixTransformOperation.cpp:

(WebCore::Matrix3DTransformOperation::operator==): Added.
(WebCore::MatrixTransformOperation::blend):

  • Switch to type-checked casts and use a reference.
  • platform/graphics/transforms/PerspectiveTransformOperation.cpp:

(WebCore::Matrix3DTransformOperation::operator==): Added.
(WebCore::PerspectiveTransformOperation::blend):

  • platform/graphics/transforms/RotateTransformOperation.cpp:

(WebCore::Matrix3DTransformOperation::operator==): Added.
(WebCore::RotateTransformOperation::blend):

  • platform/graphics/transforms/ScaleTransformOperation.cpp:

(WebCore::Matrix3DTransformOperation::operator==): Added.
(WebCore::ScaleTransformOperation::blend):

  • platform/graphics/transforms/SkewTransformOperation.cpp:

(WebCore::Matrix3DTransformOperation::operator==): Added.
(WebCore::SkewTransformOperation::blend):

  • platform/graphics/transforms/TranslateTransformOperation.cpp:

(WebCore::Matrix3DTransformOperation::operator==): Added.
(WebCore::TranslateTransformOperation::blend):

  • Switch to type-checked casts.
  • platform/graphics/transforms/TransformOperation.h:

(WebCore::TransformOperation::isRotateTransformOperationType):
(WebCore::TransformOperation::isScaleTransformOperationType):
(WebCore::TransformOperation::isSkewTransformOperationType):
(WebCore::TransformOperation::isTranslateTransformOperationType):

  • Add type-checking methods used in constructors and type-checked casts.
  • Define TRANSFORMOPERATION_TYPE_CASTS macro used by subclasses.

Source/WebKit2:

  • Shared/CoordinatedGraphics/CoordinatedGraphicsArgumentCoders.cpp:

(IPC::ArgumentCoder<TransformOperations>::encode):

  • Switch to type-checked casts.
Location:
trunk/Source
Files:
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r169318 r169320  
     12014-05-25  David Kilzer  <ddkilzer@apple.com>
     2
     3        Add type-checked casts for TransformOperations
     4        <http://webkit.org/b/133217>
     5
     6        Reviewed by Simon Fraser.
     7
     8        * platform/graphics/GraphicsLayer.cpp:
     9        (WebCore::GraphicsLayer::validateTransformOperations):
     10        * platform/graphics/ca/GraphicsLayerCA.cpp:
     11        (WebCore::getTransformFunctionValue):
     12        - Switch to type-checked casts.
     13
     14        * platform/graphics/transforms/IdentityTransformOperation.h:
     15        * platform/graphics/transforms/Matrix3DTransformOperation.h:
     16        * platform/graphics/transforms/MatrixTransformOperation.h:
     17        * platform/graphics/transforms/PerspectiveTransformOperation.h:
     18        * platform/graphics/transforms/RotateTransformOperation.h:
     19        * platform/graphics/transforms/ScaleTransformOperation.h:
     20        * platform/graphics/transforms/SkewTransformOperation.h:
     21        * platform/graphics/transforms/TranslateTransformOperation.h:
     22        - Add 'final' to class declaration.
     23        - Add 'override' to overridden methods.
     24        - Add type-checked cast via TRANSFORMOPERATION_TYPE_CASTS macro.
     25        - Move implementation of operator==(const TransformOperation&)
     26          from header to source file so it is able to use a type-checked
     27          cast, and switch back to using a reference instead of a
     28          pointer.
     29        - Add or update ASSERT in private constructor to check for
     30          correct OperationType in classes that represent multiple
     31          types.
     32
     33        * platform/graphics/transforms/Matrix3DTransformOperation.cpp:
     34        (WebCore::Matrix3DTransformOperation::operator==): Added.
     35
     36        * platform/graphics/transforms/MatrixTransformOperation.cpp:
     37        (WebCore::Matrix3DTransformOperation::operator==): Added.
     38        (WebCore::MatrixTransformOperation::blend):
     39        - Switch to type-checked casts and use a reference.
     40
     41        * platform/graphics/transforms/PerspectiveTransformOperation.cpp:
     42        (WebCore::Matrix3DTransformOperation::operator==): Added.
     43        (WebCore::PerspectiveTransformOperation::blend):
     44        * platform/graphics/transforms/RotateTransformOperation.cpp:
     45        (WebCore::Matrix3DTransformOperation::operator==): Added.
     46        (WebCore::RotateTransformOperation::blend):
     47        * platform/graphics/transforms/ScaleTransformOperation.cpp:
     48        (WebCore::Matrix3DTransformOperation::operator==): Added.
     49        (WebCore::ScaleTransformOperation::blend):
     50        * platform/graphics/transforms/SkewTransformOperation.cpp:
     51        (WebCore::Matrix3DTransformOperation::operator==): Added.
     52        (WebCore::SkewTransformOperation::blend):
     53        * platform/graphics/transforms/TranslateTransformOperation.cpp:
     54        (WebCore::Matrix3DTransformOperation::operator==): Added.
     55        (WebCore::TranslateTransformOperation::blend):
     56        - Switch to type-checked casts.
     57
     58        * platform/graphics/transforms/TransformOperation.h:
     59        (WebCore::TransformOperation::isRotateTransformOperationType):
     60        (WebCore::TransformOperation::isScaleTransformOperationType):
     61        (WebCore::TransformOperation::isSkewTransformOperationType):
     62        (WebCore::TransformOperation::isTranslateTransformOperationType):
     63        - Add type-checking methods used in constructors and type-checked
     64          casts.
     65        - Define TRANSFORMOPERATION_TYPE_CASTS macro used by subclasses.
     66
    1672014-05-25  David Kilzer  <ddkilzer@apple.com>
    268
  • trunk/Source/WebCore/platform/graphics/GraphicsLayer.cpp

    r168423 r169320  
    517517            type == TransformOperation::ROTATE_Z ||
    518518            type == TransformOperation::ROTATE_3D) {
    519             lastRotAngle = static_cast<RotateTransformOperation*>(firstVal.operations().at(j).get())->angle();
     519            lastRotAngle = toRotateTransformOperation(firstVal.operations().at(j).get())->angle();
    520520           
    521521            if (maxRotAngle < 0)
     
    524524            for (size_t i = firstIndex + 1; i < valueList.size(); ++i) {
    525525                const TransformOperations& val = operationsAt(valueList, i);
    526                 double rotAngle = val.operations().isEmpty() ? 0 : (static_cast<RotateTransformOperation*>(val.operations().at(j).get())->angle());
     526                double rotAngle = val.operations().isEmpty() ? 0 : (toRotateTransformOperation(val.operations().at(j).get())->angle());
    527527                double diffAngle = fabs(rotAngle - lastRotAngle);
    528528                if (diffAngle > maxRotAngle)
  • trunk/Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp

    r169229 r169320  
    130130    case TransformOperation::ROTATE_X:
    131131    case TransformOperation::ROTATE_Y:
    132         value = transformOp ? narrowPrecisionToFloat(deg2rad(static_cast<const RotateTransformOperation*>(transformOp)->angle())) : 0;
     132        value = transformOp ? narrowPrecisionToFloat(deg2rad(toRotateTransformOperation(transformOp)->angle())) : 0;
    133133        break;
    134134    case TransformOperation::SCALE_X:
    135         value = transformOp ? narrowPrecisionToFloat(static_cast<const ScaleTransformOperation*>(transformOp)->x()) : 1;
     135        value = transformOp ? narrowPrecisionToFloat(toScaleTransformOperation(transformOp)->x()) : 1;
    136136        break;
    137137    case TransformOperation::SCALE_Y:
    138         value = transformOp ? narrowPrecisionToFloat(static_cast<const ScaleTransformOperation*>(transformOp)->y()) : 1;
     138        value = transformOp ? narrowPrecisionToFloat(toScaleTransformOperation(transformOp)->y()) : 1;
    139139        break;
    140140    case TransformOperation::SCALE_Z:
    141         value = transformOp ? narrowPrecisionToFloat(static_cast<const ScaleTransformOperation*>(transformOp)->z()) : 1;
     141        value = transformOp ? narrowPrecisionToFloat(toScaleTransformOperation(transformOp)->z()) : 1;
    142142        break;
    143143    case TransformOperation::TRANSLATE_X:
    144         value = transformOp ? narrowPrecisionToFloat(static_cast<const TranslateTransformOperation*>(transformOp)->x(size)) : 0;
     144        value = transformOp ? narrowPrecisionToFloat(toTranslateTransformOperation(transformOp)->x(size)) : 0;
    145145        break;
    146146    case TransformOperation::TRANSLATE_Y:
    147         value = transformOp ? narrowPrecisionToFloat(static_cast<const TranslateTransformOperation*>(transformOp)->y(size)) : 0;
     147        value = transformOp ? narrowPrecisionToFloat(toTranslateTransformOperation(transformOp)->y(size)) : 0;
    148148        break;
    149149    case TransformOperation::TRANSLATE_Z:
    150         value = transformOp ? narrowPrecisionToFloat(static_cast<const TranslateTransformOperation*>(transformOp)->z(size)) : 0;
     150        value = transformOp ? narrowPrecisionToFloat(toTranslateTransformOperation(transformOp)->z(size)) : 0;
    151151        break;
    152152    default:
     
    159159    switch (transformType) {
    160160    case TransformOperation::SCALE:
    161     case TransformOperation::SCALE_3D:
    162         value.setX(transformOp ? narrowPrecisionToFloat(static_cast<const ScaleTransformOperation*>(transformOp)->x()) : 1);
    163         value.setY(transformOp ? narrowPrecisionToFloat(static_cast<const ScaleTransformOperation*>(transformOp)->y()) : 1);
    164         value.setZ(transformOp ? narrowPrecisionToFloat(static_cast<const ScaleTransformOperation*>(transformOp)->z()) : 1);
     161    case TransformOperation::SCALE_3D: {
     162        const ScaleTransformOperation* scaleTransformOp = toScaleTransformOperation(transformOp);
     163        value.setX(scaleTransformOp ? narrowPrecisionToFloat(scaleTransformOp->x()) : 1);
     164        value.setY(scaleTransformOp ? narrowPrecisionToFloat(scaleTransformOp->y()) : 1);
     165        value.setZ(scaleTransformOp ? narrowPrecisionToFloat(scaleTransformOp->z()) : 1);
    165166        break;
     167    }
    166168    case TransformOperation::TRANSLATE:
    167     case TransformOperation::TRANSLATE_3D:
    168         value.setX(transformOp ? narrowPrecisionToFloat(static_cast<const TranslateTransformOperation*>(transformOp)->x(size)) : 0);
    169         value.setY(transformOp ? narrowPrecisionToFloat(static_cast<const TranslateTransformOperation*>(transformOp)->y(size)) : 0);
    170         value.setZ(transformOp ? narrowPrecisionToFloat(static_cast<const TranslateTransformOperation*>(transformOp)->z(size)) : 0);
     169    case TransformOperation::TRANSLATE_3D: {
     170        const TranslateTransformOperation* translateTransformOp = toTranslateTransformOperation(transformOp);
     171        value.setX(translateTransformOp ? narrowPrecisionToFloat(translateTransformOp->x(size)) : 0);
     172        value.setY(translateTransformOp ? narrowPrecisionToFloat(translateTransformOp->y(size)) : 0);
     173        value.setZ(translateTransformOp ? narrowPrecisionToFloat(translateTransformOp->z(size)) : 0);
    171174        break;
     175    }
    172176    default:
    173177        break;
  • trunk/Source/WebCore/platform/graphics/transforms/IdentityTransformOperation.h

    r157823 r169320  
    3030namespace WebCore {
    3131
    32 class IdentityTransformOperation : public TransformOperation {
     32class IdentityTransformOperation final : public TransformOperation {
    3333public:
    3434    static PassRefPtr<IdentityTransformOperation> create()
     
    3838       
    3939private:
    40     virtual bool isIdentity() const { return true; }
    41     virtual OperationType type() const { return IDENTITY; }
    42     virtual bool isSameType(const TransformOperation& o) const { return o.type() == IDENTITY; }
     40    virtual bool isIdentity() const override { return true; }
     41    virtual OperationType type() const override { return IDENTITY; }
     42    virtual bool isSameType(const TransformOperation& o) const override { return o.type() == IDENTITY; }
    4343
    44     virtual bool operator==(const TransformOperation& o) const
     44    virtual bool operator==(const TransformOperation& o) const override
    4545    {
    4646        return isSameType(o);
    4747    }
    4848
    49     virtual bool apply(TransformationMatrix&, const FloatSize&) const
     49    virtual bool apply(TransformationMatrix&, const FloatSize&) const override
    5050    {
    5151        return false;
    5252    }
    5353
    54     virtual PassRefPtr<TransformOperation> blend(const TransformOperation*, double, bool = false)
     54    virtual PassRefPtr<TransformOperation> blend(const TransformOperation*, double, bool = false) override
    5555    {
    5656        return this;
     
    6363};
    6464
     65TRANSFORMOPERATION_TYPE_CASTS(IdentityTransformOperation, type() == TransformOperation::IDENTITY);
     66
    6567} // namespace WebCore
    6668
  • trunk/Source/WebCore/platform/graphics/transforms/Matrix3DTransformOperation.cpp

    r165676 r169320  
    3131namespace WebCore {
    3232
     33bool Matrix3DTransformOperation::operator==(const TransformOperation& o) const
     34{
     35    if (!isSameType(o))
     36        return false;
     37    const Matrix3DTransformOperation& m = toMatrix3DTransformOperation(o);
     38    return m_matrix == m.m_matrix;
     39}
     40
    3341PassRefPtr<TransformOperation> Matrix3DTransformOperation::blend(const TransformOperation* from, double progress, bool blendToIdentity)
    3442{
  • trunk/Source/WebCore/platform/graphics/transforms/Matrix3DTransformOperation.h

    r165676 r169320  
    3131namespace WebCore {
    3232
    33 class Matrix3DTransformOperation : public TransformOperation {
     33class Matrix3DTransformOperation final : public TransformOperation {
    3434public:
    3535    static PassRefPtr<Matrix3DTransformOperation> create(const TransformationMatrix& matrix)
     
    4141
    4242private:   
    43     virtual bool isIdentity() const { return m_matrix.isIdentity(); }
     43    virtual bool isIdentity() const override { return m_matrix.isIdentity(); }
    4444
    45     virtual OperationType type() const { return MATRIX_3D; }
    46     virtual bool isSameType(const TransformOperation& o) const { return o.type() == MATRIX_3D; }
     45    virtual OperationType type() const override { return MATRIX_3D; }
     46    virtual bool isSameType(const TransformOperation& o) const override { return o.type() == MATRIX_3D; }
    4747
    48     virtual bool operator==(const TransformOperation& o) const
    49     {
    50         if (!isSameType(o))
    51             return false;
    52         const Matrix3DTransformOperation* m = static_cast<const Matrix3DTransformOperation*>(&o);
    53         return m_matrix == m->m_matrix;
    54     }
     48    virtual bool operator==(const TransformOperation&) const override;
    5549
    56     virtual bool apply(TransformationMatrix& transform, const FloatSize&) const
     50    virtual bool apply(TransformationMatrix& transform, const FloatSize&) const override
    5751    {
    5852        transform.multiply(TransformationMatrix(m_matrix));
     
    6054    }
    6155
    62     virtual PassRefPtr<TransformOperation> blend(const TransformOperation* from, double progress, bool blendToIdentity = false);
     56    virtual PassRefPtr<TransformOperation> blend(const TransformOperation* from, double progress, bool blendToIdentity = false) override;
    6357   
    6458    Matrix3DTransformOperation(const TransformationMatrix& mat)
     
    7064};
    7165
     66TRANSFORMOPERATION_TYPE_CASTS(Matrix3DTransformOperation, type() == TransformOperation::MATRIX_3D);
     67
    7268} // namespace WebCore
    7369
  • trunk/Source/WebCore/platform/graphics/transforms/MatrixTransformOperation.cpp

    r159027 r169320  
    2727namespace WebCore {
    2828
     29bool MatrixTransformOperation::operator==(const TransformOperation& o) const
     30{
     31    if (!isSameType(o))
     32        return false;
     33    const MatrixTransformOperation& m = toMatrixTransformOperation(o);
     34    return m_a == m.m_a && m_b == m.m_b && m_c == m.m_c && m_d == m.m_d && m_e == m.m_e && m_f == m.m_f;
     35}
     36
    2937PassRefPtr<TransformOperation> MatrixTransformOperation::blend(const TransformOperation* from, double progress, bool blendToIdentity)
    3038{
     
    3745    TransformationMatrix toT(m_a, m_b, m_c, m_d, m_e, m_f);
    3846    if (from) {
    39         const MatrixTransformOperation* m = static_cast<const MatrixTransformOperation*>(from);
    40         fromT.setMatrix(m->m_a, m->m_b, m->m_c, m->m_d, m->m_e, m->m_f);
     47        const MatrixTransformOperation& m = toMatrixTransformOperation(*from);
     48        fromT.setMatrix(m.m_a, m.m_b, m.m_c, m.m_d, m.m_e, m.m_f);
    4149    }
    4250   
  • trunk/Source/WebCore/platform/graphics/transforms/MatrixTransformOperation.h

    r157823 r169320  
    3131namespace WebCore {
    3232
    33 class MatrixTransformOperation : public TransformOperation {
     33class MatrixTransformOperation final : public TransformOperation {
    3434public:
    3535    static PassRefPtr<MatrixTransformOperation> create(double a, double b, double c, double d, double e, double f)
     
    4646
    4747private:
    48     virtual bool isIdentity() const { return m_a == 1 && m_b == 0 && m_c == 0 && m_d == 1 && m_e == 0 && m_f == 0; }
     48    virtual bool isIdentity() const override { return m_a == 1 && m_b == 0 && m_c == 0 && m_d == 1 && m_e == 0 && m_f == 0; }
    4949
    50     virtual OperationType type() const { return MATRIX; }
    51     virtual bool isSameType(const TransformOperation& o) const { return o.type() == MATRIX; }
     50    virtual OperationType type() const override { return MATRIX; }
     51    virtual bool isSameType(const TransformOperation& o) const override { return o.type() == MATRIX; }
    5252
    53     virtual bool operator==(const TransformOperation& o) const
    54     {
    55         if (!isSameType(o))
    56             return false;
     53    virtual bool operator==(const TransformOperation&) const override;
    5754
    58         const MatrixTransformOperation* m = static_cast<const MatrixTransformOperation*>(&o);
    59         return m_a == m->m_a && m_b == m->m_b && m_c == m->m_c && m_d == m->m_d && m_e == m->m_e && m_f == m->m_f;
    60     }
    61 
    62     virtual bool apply(TransformationMatrix& transform, const FloatSize&) const
     55    virtual bool apply(TransformationMatrix& transform, const FloatSize&) const override
    6356    {
    6457        TransformationMatrix matrix(m_a, m_b, m_c, m_d, m_e, m_f);
     
    6760    }
    6861
    69     virtual PassRefPtr<TransformOperation> blend(const TransformOperation* from, double progress, bool blendToIdentity = false);
     62    virtual PassRefPtr<TransformOperation> blend(const TransformOperation* from, double progress, bool blendToIdentity = false) override;
    7063   
    7164    MatrixTransformOperation(double a, double b, double c, double d, double e, double f)
     
    9790};
    9891
     92TRANSFORMOPERATION_TYPE_CASTS(MatrixTransformOperation, type() == TransformOperation::MATRIX);
     93
    9994} // namespace WebCore
    10095
  • trunk/Source/WebCore/platform/graphics/transforms/PerspectiveTransformOperation.cpp

    r165676 r169320  
    3232namespace WebCore {
    3333
     34bool PerspectiveTransformOperation::operator==(const TransformOperation& o) const
     35{
     36    if (!isSameType(o))
     37        return false;
     38    const PerspectiveTransformOperation& p = toPerspectiveTransformOperation(o);
     39    return m_p == p.m_p;
     40}
     41
    3442PassRefPtr<TransformOperation> PerspectiveTransformOperation::blend(const TransformOperation* from, double progress, bool blendToIdentity)
    3543{
     
    4351    }
    4452   
    45     const PerspectiveTransformOperation* fromOp = static_cast<const PerspectiveTransformOperation*>(from);
     53    const PerspectiveTransformOperation* fromOp = toPerspectiveTransformOperation(from);
    4654    Length fromP = fromOp ? fromOp->m_p : Length(m_p.type());
    4755    Length toP = m_p;
  • trunk/Source/WebCore/platform/graphics/transforms/PerspectiveTransformOperation.h

    r165676 r169320  
    3333namespace WebCore {
    3434
    35 class PerspectiveTransformOperation : public TransformOperation {
     35class PerspectiveTransformOperation final : public TransformOperation {
    3636public:
    3737    static PassRefPtr<PerspectiveTransformOperation> create(const Length& p)
     
    4343   
    4444private:
    45     virtual bool isIdentity() const { return !floatValueForLength(m_p, 1); }
    46     virtual OperationType type() const { return PERSPECTIVE; }
    47     virtual bool isSameType(const TransformOperation& o) const { return o.type() == PERSPECTIVE; }
     45    virtual bool isIdentity() const override { return !floatValueForLength(m_p, 1); }
     46    virtual OperationType type() const override { return PERSPECTIVE; }
     47    virtual bool isSameType(const TransformOperation& o) const override { return o.type() == PERSPECTIVE; }
    4848
    49     virtual bool operator==(const TransformOperation& o) const
    50     {
    51         if (!isSameType(o))
    52             return false;
    53         const PerspectiveTransformOperation* p = static_cast<const PerspectiveTransformOperation*>(&o);
    54         return m_p == p->m_p;
    55     }
     49    virtual bool operator==(const TransformOperation&) const override;
    5650
    57     virtual bool apply(TransformationMatrix& transform, const FloatSize&) const
     51    virtual bool apply(TransformationMatrix& transform, const FloatSize&) const override
    5852    {
    5953        transform.applyPerspective(floatValueForLength(m_p, 1));
     
    6155    }
    6256
    63     virtual PassRefPtr<TransformOperation> blend(const TransformOperation* from, double progress, bool blendToIdentity = false);
     57    virtual PassRefPtr<TransformOperation> blend(const TransformOperation* from, double progress, bool blendToIdentity = false) override;
    6458
    6559    PerspectiveTransformOperation(const Length& p)
     
    7266};
    7367
     68TRANSFORMOPERATION_TYPE_CASTS(PerspectiveTransformOperation, type() == TransformOperation::PERSPECTIVE);
     69
    7470} // namespace WebCore
    7571
  • trunk/Source/WebCore/platform/graphics/transforms/RotateTransformOperation.cpp

    r159027 r169320  
    2929namespace WebCore {
    3030
     31bool RotateTransformOperation::operator==(const TransformOperation& o) const
     32{
     33    if (!isSameType(o))
     34        return false;
     35    const RotateTransformOperation& r = toRotateTransformOperation(o);
     36    return m_x == r.m_x && m_y == r.m_y && m_z == r.m_z && m_angle == r.m_angle;
     37}
     38
    3139PassRefPtr<TransformOperation> RotateTransformOperation::blend(const TransformOperation* from, double progress, bool blendToIdentity)
    3240{
     
    3745        return RotateTransformOperation::create(m_x, m_y, m_z, m_angle - m_angle * progress, m_type);
    3846   
    39     const RotateTransformOperation* fromOp = static_cast<const RotateTransformOperation*>(from);
     47    const RotateTransformOperation* fromOp = toRotateTransformOperation(from);
    4048   
    4149    // Optimize for single axis rotation
  • trunk/Source/WebCore/platform/graphics/transforms/RotateTransformOperation.h

    r157823 r169320  
    3030namespace WebCore {
    3131
    32 class RotateTransformOperation : public TransformOperation {
     32class RotateTransformOperation final : public TransformOperation {
    3333public:
    3434    static PassRefPtr<RotateTransformOperation> create(double angle, OperationType type)
     
    4848
    4949private:
    50     virtual bool isIdentity() const { return m_angle == 0; }
     50    virtual bool isIdentity() const override { return m_angle == 0; }
    5151
    52     virtual OperationType type() const { return m_type; }
    53     virtual bool isSameType(const TransformOperation& o) const { return o.type() == m_type; }
     52    virtual OperationType type() const override { return m_type; }
     53    virtual bool isSameType(const TransformOperation& o) const override { return o.type() == m_type; }
    5454
    55     virtual bool operator==(const TransformOperation& o) const
    56     {
    57         if (!isSameType(o))
    58             return false;
    59         const RotateTransformOperation* r = static_cast<const RotateTransformOperation*>(&o);
    60         return m_x == r->m_x && m_y == r->m_y && m_z == r->m_z && m_angle == r->m_angle;
    61     }
     55    virtual bool operator==(const TransformOperation&) const override;
    6256
    63     virtual bool apply(TransformationMatrix& transform, const FloatSize& /*borderBoxSize*/) const
     57    virtual bool apply(TransformationMatrix& transform, const FloatSize& /*borderBoxSize*/) const override
    6458    {
    6559        transform.rotate3d(m_x, m_y, m_z, m_angle);
     
    6761    }
    6862
    69     virtual PassRefPtr<TransformOperation> blend(const TransformOperation* from, double progress, bool blendToIdentity = false);
     63    virtual PassRefPtr<TransformOperation> blend(const TransformOperation* from, double progress, bool blendToIdentity = false) override;
    7064
    7165    RotateTransformOperation(double x, double y, double z, double angle, OperationType type)
     
    7670        , m_type(type)
    7771    {
    78         ASSERT(type == ROTATE_X || type == ROTATE_Y || type == ROTATE_Z || type == ROTATE_3D);
     72        ASSERT(isRotateTransformOperationType());
    7973    }
    8074
     
    8680};
    8781
     82TRANSFORMOPERATION_TYPE_CASTS(RotateTransformOperation, isRotateTransformOperationType());
     83
    8884} // namespace WebCore
    8985
  • trunk/Source/WebCore/platform/graphics/transforms/ScaleTransformOperation.cpp

    r102740 r169320  
    2727namespace WebCore {
    2828
     29bool ScaleTransformOperation::operator==(const TransformOperation& o) const
     30{
     31    if (!isSameType(o))
     32        return false;
     33    const ScaleTransformOperation& s = toScaleTransformOperation(o);
     34    return m_x == s.m_x && m_y == s.m_y && m_z == s.m_z;
     35}
     36
    2937PassRefPtr<TransformOperation> ScaleTransformOperation::blend(const TransformOperation* from, double progress, bool blendToIdentity)
    3038{
     
    3745                                               WebCore::blend(m_z, 1.0, progress), m_type);
    3846   
    39     const ScaleTransformOperation* fromOp = static_cast<const ScaleTransformOperation*>(from);
     47    const ScaleTransformOperation* fromOp = toScaleTransformOperation(from);
    4048    double fromX = fromOp ? fromOp->m_x : 1.0;
    4149    double fromY = fromOp ? fromOp->m_y : 1.0;
  • trunk/Source/WebCore/platform/graphics/transforms/ScaleTransformOperation.h

    r157823 r169320  
    3030namespace WebCore {
    3131
    32 class ScaleTransformOperation : public TransformOperation {
     32class ScaleTransformOperation final : public TransformOperation {
    3333public:
    3434    static PassRefPtr<ScaleTransformOperation> create(double sx, double sy, OperationType type)
     
    4747
    4848private:
    49     virtual bool isIdentity() const { return m_x == 1 &&  m_y == 1 &&  m_z == 1; }
     49    virtual bool isIdentity() const override { return m_x == 1 &&  m_y == 1 &&  m_z == 1; }
    5050
    51     virtual OperationType type() const { return m_type; }
    52     virtual bool isSameType(const TransformOperation& o) const { return o.type() == m_type; }
     51    virtual OperationType type() const override { return m_type; }
     52    virtual bool isSameType(const TransformOperation& o) const override { return o.type() == m_type; }
    5353
    54     virtual bool operator==(const TransformOperation& o) const
    55     {
    56         if (!isSameType(o))
    57             return false;
    58         const ScaleTransformOperation* s = static_cast<const ScaleTransformOperation*>(&o);
    59         return m_x == s->m_x && m_y == s->m_y && m_z == s->m_z;
    60     }
     54    virtual bool operator==(const TransformOperation&) const override;
    6155
    62     virtual bool apply(TransformationMatrix& transform, const FloatSize&) const
     56    virtual bool apply(TransformationMatrix& transform, const FloatSize&) const override
    6357    {
    6458        transform.scale3d(m_x, m_y, m_z);
     
    6660    }
    6761
    68     virtual PassRefPtr<TransformOperation> blend(const TransformOperation* from, double progress, bool blendToIdentity = false);
     62    virtual PassRefPtr<TransformOperation> blend(const TransformOperation* from, double progress, bool blendToIdentity = false) override;
    6963
    7064    ScaleTransformOperation(double sx, double sy, double sz, OperationType type)
     
    7468        , m_type(type)
    7569    {
    76         ASSERT(type == SCALE_X || type == SCALE_Y || type == SCALE_Z || type == SCALE || type == SCALE_3D);
     70        ASSERT(isScaleTransformOperationType());
    7771    }
    7872       
     
    8377};
    8478
     79TRANSFORMOPERATION_TYPE_CASTS(ScaleTransformOperation, isScaleTransformOperationType());
     80
    8581} // namespace WebCore
    8682
  • trunk/Source/WebCore/platform/graphics/transforms/SkewTransformOperation.cpp

    r102740 r169320  
    2727namespace WebCore {
    2828
     29bool SkewTransformOperation::operator==(const TransformOperation& o) const
     30{
     31    if (!isSameType(o))
     32        return false;
     33    const SkewTransformOperation& s = toSkewTransformOperation(o);
     34    return m_angleX == s.m_angleX && m_angleY == s.m_angleY;
     35}
     36
    2937PassRefPtr<TransformOperation> SkewTransformOperation::blend(const TransformOperation* from, double progress, bool blendToIdentity)
    3038{
     
    3543        return SkewTransformOperation::create(WebCore::blend(m_angleX, 0.0, progress), WebCore::blend(m_angleY, 0.0, progress), m_type);
    3644   
    37     const SkewTransformOperation* fromOp = static_cast<const SkewTransformOperation*>(from);
     45    const SkewTransformOperation* fromOp = toSkewTransformOperation(from);
    3846    double fromAngleX = fromOp ? fromOp->m_angleX : 0;
    3947    double fromAngleY = fromOp ? fromOp->m_angleY : 0;
  • trunk/Source/WebCore/platform/graphics/transforms/SkewTransformOperation.h

    r157823 r169320  
    3030namespace WebCore {
    3131
    32 class SkewTransformOperation : public TransformOperation {
     32class SkewTransformOperation final : public TransformOperation {
    3333public:
    3434    static PassRefPtr<SkewTransformOperation> create(double angleX, double angleY, OperationType type)
     
    4141
    4242private:
    43     virtual bool isIdentity() const { return m_angleX == 0 && m_angleY == 0; }
    44     virtual OperationType type() const { return m_type; }
    45     virtual bool isSameType(const TransformOperation& o) const { return o.type() == m_type; }
     43    virtual bool isIdentity() const override { return m_angleX == 0 && m_angleY == 0; }
     44    virtual OperationType type() const override { return m_type; }
     45    virtual bool isSameType(const TransformOperation& o) const override { return o.type() == m_type; }
    4646
    47     virtual bool operator==(const TransformOperation& o) const
    48     {
    49         if (!isSameType(o))
    50             return false;
    51         const SkewTransformOperation* s = static_cast<const SkewTransformOperation*>(&o);
    52         return m_angleX == s->m_angleX && m_angleY == s->m_angleY;
    53     }
     47    virtual bool operator==(const TransformOperation&) const override;
    5448
    55     virtual bool apply(TransformationMatrix& transform, const FloatSize&) const
     49    virtual bool apply(TransformationMatrix& transform, const FloatSize&) const override
    5650    {
    5751        transform.skew(m_angleX, m_angleY);
     
    5953    }
    6054
    61     virtual PassRefPtr<TransformOperation> blend(const TransformOperation* from, double progress, bool blendToIdentity = false);
     55    virtual PassRefPtr<TransformOperation> blend(const TransformOperation* from, double progress, bool blendToIdentity = false) override;
    6256   
    6357    SkewTransformOperation(double angleX, double angleY, OperationType type)
     
    6660        , m_type(type)
    6761    {
     62        ASSERT(isSkewTransformOperationType());
    6863    }
    6964   
     
    7368};
    7469
     70TRANSFORMOPERATION_TYPE_CASTS(SkewTransformOperation, isSkewTransformOperationType());
     71
    7572} // namespace WebCore
    7673
  • trunk/Source/WebCore/platform/graphics/transforms/TransformOperation.h

    r157823 r169320  
    8080               opType == PERSPECTIVE;
    8181    }
     82
     83    bool isRotateTransformOperationType() const
     84    {
     85        return type() == ROTATE_X || type() == ROTATE_Y || type() == ROTATE_Z || type() == ROTATE || type() == ROTATE_3D;
     86    }
     87
     88    bool isScaleTransformOperationType() const
     89    {
     90        return type() == SCALE_X || type() == SCALE_Y || type() == SCALE_Z || type() == SCALE || type() == SCALE_3D;
     91    }
     92
     93    bool isSkewTransformOperationType() const
     94    {
     95        return type() == SKEW_X || type() == SKEW_Y || type() == SKEW;
     96    }
     97
     98    bool isTranslateTransformOperationType() const
     99    {
     100        return type() == TRANSLATE_X || type() == TRANSLATE_Y || type() == TRANSLATE_Z || type() == TRANSLATE || type() == TRANSLATE_3D;
     101    }
    82102};
     103
     104#define TRANSFORMOPERATION_TYPE_CASTS(ToValueTypeName, predicate) \
     105    TYPE_CASTS_BASE(ToValueTypeName, WebCore::TransformOperation, value, value->predicate, value.predicate)
    83106
    84107} // namespace WebCore
  • trunk/Source/WebCore/platform/graphics/transforms/TranslateTransformOperation.cpp

    r152825 r169320  
    2626namespace WebCore {
    2727
     28bool TranslateTransformOperation::operator==(const TransformOperation& o) const
     29{
     30    if (!isSameType(o))
     31        return false;
     32    const TranslateTransformOperation& t = toTranslateTransformOperation(o);
     33    return m_x == t.m_x && m_y == t.m_y && m_z == t.m_z;
     34}
     35
    2836PassRefPtr<TransformOperation> TranslateTransformOperation::blend(const TransformOperation* from, double progress, bool blendToIdentity)
    2937{
     
    3543        return TranslateTransformOperation::create(zeroLength.blend(m_x, progress), zeroLength.blend(m_y, progress), zeroLength.blend(m_z, progress), m_type);
    3644
    37     const TranslateTransformOperation* fromOp = static_cast<const TranslateTransformOperation*>(from);
     45    const TranslateTransformOperation* fromOp = toTranslateTransformOperation(from);
    3846    Length fromX = fromOp ? fromOp->m_x : zeroLength;
    3947    Length fromY = fromOp ? fromOp->m_y : zeroLength;
  • trunk/Source/WebCore/platform/graphics/transforms/TranslateTransformOperation.h

    r166920 r169320  
    3232namespace WebCore {
    3333
    34 class TranslateTransformOperation : public TransformOperation {
     34class TranslateTransformOperation final : public TransformOperation {
    3535public:
    3636    static PassRefPtr<TranslateTransformOperation> create(const Length& tx, const Length& ty, OperationType type)
     
    5353
    5454private:
    55     virtual bool isIdentity() const { return !floatValueForLength(m_x, 1) && !floatValueForLength(m_y, 1) && !floatValueForLength(m_z, 1); }
     55    virtual bool isIdentity() const override { return !floatValueForLength(m_x, 1) && !floatValueForLength(m_y, 1) && !floatValueForLength(m_z, 1); }
    5656
    57     virtual OperationType type() const { return m_type; }
    58     virtual bool isSameType(const TransformOperation& o) const { return o.type() == m_type; }
     57    virtual OperationType type() const override { return m_type; }
     58    virtual bool isSameType(const TransformOperation& o) const override { return o.type() == m_type; }
    5959
    60     virtual bool operator==(const TransformOperation& o) const
    61     {
    62         if (!isSameType(o))
    63             return false;
    64         const TranslateTransformOperation* t = static_cast<const TranslateTransformOperation*>(&o);
    65         return m_x == t->m_x && m_y == t->m_y && m_z == t->m_z;
    66     }
     60    virtual bool operator==(const TransformOperation&) const override;
    6761
    68     virtual bool apply(TransformationMatrix& transform, const FloatSize& borderBoxSize) const
     62    virtual bool apply(TransformationMatrix& transform, const FloatSize& borderBoxSize) const override
    6963    {
    7064        transform.translate3d(x(borderBoxSize), y(borderBoxSize), z(borderBoxSize));
     
    7266    }
    7367
    74     virtual PassRefPtr<TransformOperation> blend(const TransformOperation* from, double progress, bool blendToIdentity = false);
     68    virtual PassRefPtr<TransformOperation> blend(const TransformOperation* from, double progress, bool blendToIdentity = false) override;
    7569
    7670    TranslateTransformOperation(const Length& tx, const Length& ty, const Length& tz, OperationType type)
     
    8074        , m_type(type)
    8175    {
    82         ASSERT(type == TRANSLATE_X || type == TRANSLATE_Y || type == TRANSLATE_Z || type == TRANSLATE || type == TRANSLATE_3D);
     76        ASSERT(isTranslateTransformOperationType());
    8377    }
    8478
     
    8983};
    9084
     85TRANSFORMOPERATION_TYPE_CASTS(TranslateTransformOperation, isTranslateTransformOperationType());
     86
    9187} // namespace WebCore
    9288
  • trunk/Source/WebKit2/ChangeLog

    r169319 r169320  
     12014-05-25  David Kilzer  <ddkilzer@apple.com>
     2
     3        Add type-checked casts for TransformOperations
     4        <http://webkit.org/b/133217>
     5
     6        Reviewed by Simon Fraser.
     7
     8        * Shared/CoordinatedGraphics/CoordinatedGraphicsArgumentCoders.cpp:
     9        (IPC::ArgumentCoder<TransformOperations>::encode):
     10        - Switch to type-checked casts.
     11
    1122014-05-25  David Kilzer  <ddkilzer@apple.com>
    213
  • trunk/Source/WebKit2/Shared/CoordinatedGraphics/CoordinatedGraphicsArgumentCoders.cpp

    r169319 r169320  
    187187        case TransformOperation::SCALE_Z:
    188188        case TransformOperation::SCALE_3D:
    189             encoder << static_cast<const ScaleTransformOperation*>(operation)->x();
    190             encoder << static_cast<const ScaleTransformOperation*>(operation)->y();
    191             encoder << static_cast<const ScaleTransformOperation*>(operation)->z();
     189            encoder << toScaleTransformOperation(operation)->x();
     190            encoder << toScaleTransformOperation(operation)->y();
     191            encoder << toScaleTransformOperation(operation)->z();
    192192            break;
    193193        case TransformOperation::TRANSLATE_X:
     
    196196        case TransformOperation::TRANSLATE_Z:
    197197        case TransformOperation::TRANSLATE_3D:
    198             ArgumentCoder<Length>::encode(encoder, static_cast<const TranslateTransformOperation*>(operation)->x());
    199             ArgumentCoder<Length>::encode(encoder, static_cast<const TranslateTransformOperation*>(operation)->y());
    200             ArgumentCoder<Length>::encode(encoder, static_cast<const TranslateTransformOperation*>(operation)->z());
     198            ArgumentCoder<Length>::encode(encoder, toTranslateTransformOperation(operation)->x());
     199            ArgumentCoder<Length>::encode(encoder, toTranslateTransformOperation(operation)->y());
     200            ArgumentCoder<Length>::encode(encoder, toTranslateTransformOperation(operation)->z());
    201201            break;
    202202        case TransformOperation::ROTATE:
     
    204204        case TransformOperation::ROTATE_Y:
    205205        case TransformOperation::ROTATE_3D:
    206             encoder << static_cast<const RotateTransformOperation*>(operation)->x();
    207             encoder << static_cast<const RotateTransformOperation*>(operation)->y();
    208             encoder << static_cast<const RotateTransformOperation*>(operation)->z();
    209             encoder << static_cast<const RotateTransformOperation*>(operation)->angle();
     206            encoder << toRotateTransformOperation(operation)->x();
     207            encoder << toRotateTransformOperation(operation)->y();
     208            encoder << toRotateTransformOperation(operation)->z();
     209            encoder << toRotateTransformOperation(operation)->angle();
    210210            break;
    211211        case TransformOperation::SKEW_X:
    212212        case TransformOperation::SKEW_Y:
    213213        case TransformOperation::SKEW:
    214             encoder << static_cast<const SkewTransformOperation*>(operation)->angleX();
    215             encoder << static_cast<const SkewTransformOperation*>(operation)->angleY();
     214            encoder << toSkewTransformOperation(operation)->angleX();
     215            encoder << toSkewTransformOperation(operation)->angleY();
    216216            break;
    217217        case TransformOperation::MATRIX:
    218             ArgumentCoder<TransformationMatrix>::encode(encoder, static_cast<const MatrixTransformOperation*>(operation)->matrix());
     218            ArgumentCoder<TransformationMatrix>::encode(encoder, toMatrixTransformOperation(operation)->matrix());
    219219            break;
    220220        case TransformOperation::MATRIX_3D:
    221             ArgumentCoder<TransformationMatrix>::encode(encoder, static_cast<const Matrix3DTransformOperation*>(operation)->matrix());
     221            ArgumentCoder<TransformationMatrix>::encode(encoder, toMatrix3DTransformOperation(operation)->matrix());
    222222            break;
    223223        case TransformOperation::PERSPECTIVE:
    224             ArgumentCoder<Length>::encode(encoder, static_cast<const PerspectiveTransformOperation*>(operation)->perspective());
     224            ArgumentCoder<Length>::encode(encoder, toPerspectiveTransformOperation(operation)->perspective());
    225225            break;
    226226        case TransformOperation::IDENTITY:
Note: See TracChangeset for help on using the changeset viewer.