Commit 2d12cf6a authored by Abhijeet Kandalkar's avatar Abhijeet Kandalkar Committed by Commit Bot

Remove DEFINE_TRANSFORM_TYPE_CASTS from third_party/blink

In this CL, DEFINE_TRANSFORM_TYPE_CASTS is removed and new downcast
helpers are used for below classes,
- Matrix3DTransformOperation
- MatrixTransformOperation
- PerspectiveTransformOperation
- RotateTransformOperation
- RotateAroundOriginTransformOperation
- ScaleTransformOperation
- SkewTransformOperation
- TranslateTransformOperation

Bug: 891908
Change-Id: Ie5f51f1133cb7fbef2c67ca2be493ba6d0d25eb2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2046943Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Abhijeet Kandalkar <abhijeet@igalia.com>
Cr-Commit-Position: refs/heads/master@{#740181}
parent da8fde1c
......@@ -33,7 +33,7 @@ const CSSValue* ComputedTransformComponent(const TransformOperation& operation,
case TransformOperation::kScaleZ:
case TransformOperation::kScale:
case TransformOperation::kScale3D: {
const auto& scale = ToScaleTransformOperation(operation);
const auto& scale = To<ScaleTransformOperation>(operation);
CSSFunctionValue* result = MakeGarbageCollected<CSSFunctionValue>(
operation.Is3DOperation() ? CSSValueID::kScale3d
: CSSValueID::kScale);
......@@ -52,7 +52,7 @@ const CSSValue* ComputedTransformComponent(const TransformOperation& operation,
case TransformOperation::kTranslateZ:
case TransformOperation::kTranslate:
case TransformOperation::kTranslate3D: {
const auto& translate = ToTranslateTransformOperation(operation);
const auto& translate = To<TranslateTransformOperation>(operation);
CSSFunctionValue* result = MakeGarbageCollected<CSSFunctionValue>(
operation.Is3DOperation() ? CSSValueID::kTranslate3d
: CSSValueID::kTranslate);
......@@ -67,7 +67,7 @@ const CSSValue* ComputedTransformComponent(const TransformOperation& operation,
case TransformOperation::kRotateX:
case TransformOperation::kRotateY:
case TransformOperation::kRotate3D: {
const auto& rotate = ToRotateTransformOperation(operation);
const auto& rotate = To<RotateTransformOperation>(operation);
CSSFunctionValue* result =
MakeGarbageCollected<CSSFunctionValue>(CSSValueID::kRotate3d);
result->Append(*CSSNumericLiteralValue::Create(
......@@ -81,7 +81,7 @@ const CSSValue* ComputedTransformComponent(const TransformOperation& operation,
return result;
}
case TransformOperation::kRotate: {
const auto& rotate = ToRotateTransformOperation(operation);
const auto& rotate = To<RotateTransformOperation>(operation);
auto* result =
MakeGarbageCollected<CSSFunctionValue>(CSSValueID::kRotate);
result->Append(*CSSNumericLiteralValue::Create(
......@@ -89,21 +89,21 @@ const CSSValue* ComputedTransformComponent(const TransformOperation& operation,
return result;
}
case TransformOperation::kSkewX: {
const auto& skew = ToSkewTransformOperation(operation);
const auto& skew = To<SkewTransformOperation>(operation);
auto* result = MakeGarbageCollected<CSSFunctionValue>(CSSValueID::kSkewX);
result->Append(*CSSNumericLiteralValue::Create(
skew.AngleX(), CSSPrimitiveValue::UnitType::kDegrees));
return result;
}
case TransformOperation::kSkewY: {
const auto& skew = ToSkewTransformOperation(operation);
const auto& skew = To<SkewTransformOperation>(operation);
auto* result = MakeGarbageCollected<CSSFunctionValue>(CSSValueID::kSkewY);
result->Append(*CSSNumericLiteralValue::Create(
skew.AngleY(), CSSPrimitiveValue::UnitType::kDegrees));
return result;
}
case TransformOperation::kSkew: {
const auto& skew = ToSkewTransformOperation(operation);
const auto& skew = To<SkewTransformOperation>(operation);
auto* result = MakeGarbageCollected<CSSFunctionValue>(CSSValueID::kSkew);
result->Append(*CSSNumericLiteralValue::Create(
skew.AngleX(), CSSPrimitiveValue::UnitType::kDegrees));
......@@ -112,7 +112,7 @@ const CSSValue* ComputedTransformComponent(const TransformOperation& operation,
return result;
}
case TransformOperation::kPerspective: {
const auto& perspective = ToPerspectiveTransformOperation(operation);
const auto& perspective = To<PerspectiveTransformOperation>(operation);
auto* result =
MakeGarbageCollected<CSSFunctionValue>(CSSValueID::kPerspective);
result->Append(*CSSNumericLiteralValue::Create(
......@@ -121,7 +121,7 @@ const CSSValue* ComputedTransformComponent(const TransformOperation& operation,
return result;
}
case TransformOperation::kMatrix: {
const auto& matrix = ToMatrixTransformOperation(operation).Matrix();
const auto& matrix = To<MatrixTransformOperation>(operation).Matrix();
auto* result =
MakeGarbageCollected<CSSFunctionValue>(CSSValueID::kMatrix);
double values[6] = {matrix.A(), matrix.B(), matrix.C(),
......@@ -133,7 +133,7 @@ const CSSValue* ComputedTransformComponent(const TransformOperation& operation,
return result;
}
case TransformOperation::kMatrix3D: {
const auto& matrix = ToMatrix3DTransformOperation(operation).Matrix();
const auto& matrix = To<Matrix3DTransformOperation>(operation).Matrix();
CSSFunctionValue* result =
MakeGarbageCollected<CSSFunctionValue>(CSSValueID::kMatrix3d);
double values[16] = {
......
......@@ -35,7 +35,7 @@ namespace blink {
scoped_refptr<TransformOperation> Matrix3DTransformOperation::Accumulate(
const TransformOperation& other_op) {
DCHECK(other_op.IsSameType(*this));
const auto& other = ToMatrix3DTransformOperation(other_op);
const auto& other = To<Matrix3DTransformOperation>(other_op);
// If either matrix is non-invertible, fail and fallback to replace.
if (!matrix_.IsInvertible() || !other.matrix_.IsInvertible())
......
......@@ -27,6 +27,7 @@
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_TRANSFORMS_MATRIX_3D_TRANSFORM_OPERATION_H_
#include "third_party/blink/renderer/platform/transforms/transform_operation.h"
#include "third_party/blink/renderer/platform/wtf/casting.h"
namespace blink {
......@@ -81,7 +82,13 @@ class PLATFORM_EXPORT Matrix3DTransformOperation final
TransformationMatrix matrix_;
};
DEFINE_TRANSFORM_TYPE_CASTS(Matrix3DTransformOperation);
template <>
struct DowncastTraits<Matrix3DTransformOperation> {
static bool AllowFrom(const TransformOperation& transform) {
return Matrix3DTransformOperation::IsMatchingOperationType(
transform.GetType());
}
};
} // namespace blink
......
......@@ -28,7 +28,7 @@ namespace blink {
scoped_refptr<TransformOperation> MatrixTransformOperation::Accumulate(
const TransformOperation& other_op) {
DCHECK(other_op.IsSameType(*this));
const MatrixTransformOperation& other = ToMatrixTransformOperation(other_op);
const auto& other = To<MatrixTransformOperation>(other_op);
TransformationMatrix from_t(other.a_, other.b_, other.c_, other.d_, other.e_,
other.f_);
......
......@@ -27,6 +27,7 @@
#include "third_party/blink/renderer/platform/transforms/transform_operation.h"
#include "third_party/blink/renderer/platform/transforms/transformation_matrix.h"
#include "third_party/blink/renderer/platform/wtf/casting.h"
namespace blink {
......@@ -109,7 +110,13 @@ class PLATFORM_EXPORT MatrixTransformOperation final
double f_;
};
DEFINE_TRANSFORM_TYPE_CASTS(MatrixTransformOperation);
template <>
struct DowncastTraits<MatrixTransformOperation> {
static bool AllowFrom(const TransformOperation& transform) {
return MatrixTransformOperation::IsMatchingOperationType(
transform.GetType());
}
};
} // namespace blink
......
......@@ -33,7 +33,7 @@ namespace blink {
scoped_refptr<TransformOperation> PerspectiveTransformOperation::Accumulate(
const TransformOperation& other) {
DCHECK(other.IsSameType(*this));
double other_p = ToPerspectiveTransformOperation(other).p_;
double other_p = To<PerspectiveTransformOperation>(other).p_;
if (p_ == 0 && other_p == 0)
return nullptr;
......
......@@ -27,6 +27,7 @@
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_TRANSFORMS_PERSPECTIVE_TRANSFORM_OPERATION_H_
#include "third_party/blink/renderer/platform/transforms/transform_operation.h"
#include "third_party/blink/renderer/platform/wtf/casting.h"
namespace blink {
......@@ -78,7 +79,13 @@ class PLATFORM_EXPORT PerspectiveTransformOperation final
double p_;
};
DEFINE_TRANSFORM_TYPE_CASTS(PerspectiveTransformOperation);
template <>
struct DowncastTraits<PerspectiveTransformOperation> {
static bool AllowFrom(const TransformOperation& transform) {
return PerspectiveTransformOperation::IsMatchingOperationType(
transform.GetType());
}
};
} // namespace blink
......
......@@ -43,7 +43,7 @@ bool RotateTransformOperation::operator==(
const TransformOperation& other) const {
if (!IsSameType(other))
return false;
const Rotation& other_rotation = ToRotateTransformOperation(other).rotation_;
const auto& other_rotation = To<RotateTransformOperation>(other).rotation_;
return rotation_.axis == other_rotation.axis &&
rotation_.angle == other_rotation.angle;
}
......@@ -62,7 +62,7 @@ scoped_refptr<TransformOperation> RotateTransformOperation::Accumulate(
const TransformOperation& other) {
DCHECK(IsMatchingOperationType(other.GetType()));
Rotation new_rotation =
Rotation::Add(rotation_, ToRotateTransformOperation(other).rotation_);
Rotation::Add(rotation_, To<RotateTransformOperation>(other).rotation_);
return RotateTransformOperation::Create(new_rotation,
GetTypeForRotation(new_rotation));
}
......@@ -91,8 +91,7 @@ scoped_refptr<TransformOperation> RotateTransformOperation::Blend(
DCHECK(from->PrimitiveType() == OperationType::kRotate3D);
OperationType type =
from->IsSameType(*this) ? type_ : OperationType::kRotate3D;
const RotateTransformOperation& from_rotate =
ToRotateTransformOperation(*from);
const auto& from_rotate = To<RotateTransformOperation>(*from);
return RotateTransformOperation::Create(
Rotation::Slerp(from_rotate.rotation_, rotation_, progress), type);
}
......@@ -123,8 +122,7 @@ bool RotateAroundOriginTransformOperation::operator==(
const TransformOperation& other) const {
if (!IsSameType(other))
return false;
const RotateAroundOriginTransformOperation& other_rotate =
ToRotateAroundOriginTransformOperation(other);
const auto& other_rotate = To<RotateAroundOriginTransformOperation>(other);
const Rotation& other_rotation = other_rotate.rotation_;
return rotation_.axis == other_rotation.axis &&
rotation_.angle == other_rotation.angle &&
......@@ -146,8 +144,7 @@ scoped_refptr<TransformOperation> RotateAroundOriginTransformOperation::Blend(
return RotateAroundOriginTransformOperation::Create(Angle() * progress,
origin_x_, origin_y_);
}
const RotateAroundOriginTransformOperation& from_rotate =
ToRotateAroundOriginTransformOperation(*from);
const auto& from_rotate = To<RotateAroundOriginTransformOperation>(*from);
return RotateAroundOriginTransformOperation::Create(
blink::Blend(from_rotate.Angle(), Angle(), progress),
blink::Blend(from_rotate.origin_x_, origin_x_, progress),
......
......@@ -28,6 +28,7 @@
#include "third_party/blink/renderer/platform/geometry/float_point_3d.h"
#include "third_party/blink/renderer/platform/transforms/rotation.h"
#include "third_party/blink/renderer/platform/transforms/transform_operation.h"
#include "third_party/blink/renderer/platform/wtf/casting.h"
namespace blink {
......@@ -107,7 +108,13 @@ class PLATFORM_EXPORT RotateTransformOperation : public TransformOperation {
const OperationType type_;
};
DEFINE_TRANSFORM_TYPE_CASTS(RotateTransformOperation);
template <>
struct DowncastTraits<RotateTransformOperation> {
static bool AllowFrom(const TransformOperation& transform) {
return RotateTransformOperation::IsMatchingOperationType(
transform.GetType());
}
};
class PLATFORM_EXPORT RotateAroundOriginTransformOperation final
: public RotateTransformOperation {
......@@ -141,7 +148,13 @@ class PLATFORM_EXPORT RotateAroundOriginTransformOperation final
double origin_y_;
};
DEFINE_TRANSFORM_TYPE_CASTS(RotateAroundOriginTransformOperation);
template <>
struct DowncastTraits<RotateAroundOriginTransformOperation> {
static bool AllowFrom(const TransformOperation& transform) {
return RotateAroundOriginTransformOperation::IsMatchingOperationType(
transform.GetType());
}
};
} // namespace blink
......
......@@ -49,7 +49,7 @@ TransformOperation::OperationType GetTypeForScale(double x,
scoped_refptr<TransformOperation> ScaleTransformOperation::Accumulate(
const TransformOperation& other) {
DCHECK(other.CanBlendWith(*this));
const auto& other_op = ToScaleTransformOperation(other);
const auto& other_op = To<ScaleTransformOperation>(other);
// Scale parameters are one in the identity transform function so use
// accumulation for one-based values.
double new_x = x_ + other_op.x_ - 1;
......
......@@ -26,6 +26,7 @@
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_TRANSFORMS_SCALE_TRANSFORM_OPERATION_H_
#include "third_party/blink/renderer/platform/transforms/transform_operation.h"
#include "third_party/blink/renderer/platform/wtf/casting.h"
namespace blink {
......@@ -99,7 +100,13 @@ class PLATFORM_EXPORT ScaleTransformOperation final
OperationType type_;
};
DEFINE_TRANSFORM_TYPE_CASTS(ScaleTransformOperation);
template <>
struct DowncastTraits<ScaleTransformOperation> {
static bool AllowFrom(const TransformOperation& transform) {
return ScaleTransformOperation::IsMatchingOperationType(
transform.GetType());
}
};
} // namespace blink
......
......@@ -28,7 +28,7 @@ namespace blink {
scoped_refptr<TransformOperation> SkewTransformOperation::Accumulate(
const TransformOperation& other) {
DCHECK(other.CanBlendWith(*this));
const SkewTransformOperation& skew_other = ToSkewTransformOperation(other);
const auto& skew_other = To<SkewTransformOperation>(other);
return SkewTransformOperation::Create(angle_x_ + skew_other.angle_x_,
angle_y_ + skew_other.angle_y_, type_);
}
......
......@@ -27,6 +27,7 @@
#include "base/memory/scoped_refptr.h"
#include "third_party/blink/renderer/platform/transforms/transform_operation.h"
#include "third_party/blink/renderer/platform/wtf/casting.h"
namespace blink {
......@@ -78,7 +79,12 @@ class PLATFORM_EXPORT SkewTransformOperation final : public TransformOperation {
OperationType type_;
};
DEFINE_TRANSFORM_TYPE_CASTS(SkewTransformOperation);
template <>
struct DowncastTraits<SkewTransformOperation> {
static bool AllowFrom(const TransformOperation& transform) {
return SkewTransformOperation::IsMatchingOperationType(transform.GetType());
}
};
} // namespace blink
......
......@@ -114,11 +114,6 @@ class PLATFORM_EXPORT TransformOperation
DISALLOW_COPY_AND_ASSIGN(TransformOperation);
};
#define DEFINE_TRANSFORM_TYPE_CASTS(thisType) \
DEFINE_TYPE_CASTS(thisType, TransformOperation, transform, \
thisType::IsMatchingOperationType(transform->GetType()), \
thisType::IsMatchingOperationType(transform.GetType()))
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_TRANSFORMS_TRANSFORM_OPERATION_H_
......@@ -62,7 +62,7 @@ scoped_refptr<TransformOperation> TranslateTransformOperation::Accumulate(
const TransformOperation& other) {
DCHECK(other.CanBlendWith(*this));
const auto& other_op = ToTranslateTransformOperation(other);
const auto& other_op = To<TranslateTransformOperation>(other);
Length new_x = AddLengths(x_, other_op.x_);
Length new_y = AddLengths(y_, other_op.y_);
double new_z = z_ + other_op.z_;
......@@ -85,7 +85,7 @@ scoped_refptr<TransformOperation> TranslateTransformOperation::Blend(
blink::Blend(z_, 0., progress), type_);
}
const auto* from_op = ToTranslateTransformOperation(from);
const auto* from_op = To<TranslateTransformOperation>(from);
const Length& from_x = from_op ? from_op->x_ : zero_length;
const Length& from_y = from_op ? from_op->y_ : zero_length;
double from_z = from_op ? from_op->z_ : 0;
......
......@@ -28,6 +28,7 @@
#include "third_party/blink/renderer/platform/geometry/length.h"
#include "third_party/blink/renderer/platform/geometry/length_functions.h"
#include "third_party/blink/renderer/platform/transforms/transform_operation.h"
#include "third_party/blink/renderer/platform/wtf/casting.h"
namespace blink {
......@@ -119,7 +120,13 @@ class PLATFORM_EXPORT TranslateTransformOperation final
OperationType type_;
};
DEFINE_TRANSFORM_TYPE_CASTS(TranslateTransformOperation);
template <>
struct DowncastTraits<TranslateTransformOperation> {
static bool AllowFrom(const TransformOperation& transform) {
return TranslateTransformOperation::IsMatchingOperationType(
transform.GetType());
}
};
} // namespace blink
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment