| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/graphics/paint/GeometryMapper.h" | 5 #include "platform/graphics/paint/GeometryMapper.h" |
| 6 | 6 |
| 7 #include "platform/geometry/GeometryTestHelpers.h" | 7 #include "platform/geometry/GeometryTestHelpers.h" |
| 8 #include "platform/geometry/LayoutRect.h" | 8 #include "platform/geometry/LayoutRect.h" |
| 9 #include "platform/graphics/paint/ClipPaintPropertyNode.h" | 9 #include "platform/graphics/paint/ClipPaintPropertyNode.h" |
| 10 #include "platform/graphics/paint/EffectPaintPropertyNode.h" | 10 #include "platform/graphics/paint/EffectPaintPropertyNode.h" |
| 11 #include "platform/graphics/paint/TransformPaintPropertyNode.h" | 11 #include "platform/graphics/paint/TransformPaintPropertyNode.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 namespace blink { | 14 namespace blink { |
| 15 | 15 |
| 16 class GeometryMapperTest : public ::testing::Test { | 16 class GeometryMapperTest : public ::testing::Test { |
| 17 public: | 17 public: |
| 18 RefPtr<TransformPaintPropertyNode> rootTransformNode; | 18 RefPtr<TransformPaintPropertyNode> rootTransformNode; |
| 19 RefPtr<ClipPaintPropertyNode> rootClipNode; | 19 RefPtr<ClipPaintPropertyNode> rootClipNode; |
| 20 RefPtr<EffectPaintPropertyNode> rootEffectNode; | 20 RefPtr<EffectPaintPropertyNode> rootEffectNode; |
| 21 | 21 |
| 22 std::unique_ptr<GeometryMapper> geometryMapper; | 22 std::unique_ptr<GeometryMapper> geometryMapper; |
| 23 | 23 |
| 24 PropertyTreeState rootPropertyTreeState() | 24 PropertyTreeState rootPropertyTreeState() |
| 25 { | 25 { |
| 26 PropertyTreeState state(rootTransformNode.get(), rootClipNode.get(), roo
tEffectNode.get()); | 26 PropertyTreeState state(rootTransformNode.get(), rootClipNode.get(), roo
tEffectNode.get()); |
| 27 return state; | 27 return state; |
| 28 } | 28 } |
| 29 | 29 |
| 30 PrecomputedDataForAncestor& GetPrecomputedDataForAncestor(const PropertyTree
State& propertyTreeState) | 30 PrecomputedDataForAncestor& getPrecomputedDataForAncestor(const PropertyTree
State& propertyTreeState) |
| 31 { | 31 { |
| 32 return geometryMapper->GetPrecomputedDataForAncestor(propertyTreeState); | 32 return geometryMapper->getPrecomputedDataForAncestor(propertyTreeState); |
| 33 } | 33 } |
| 34 | 34 |
| 35 private: | 35 private: |
| 36 void SetUp() override | 36 void SetUp() override |
| 37 { | 37 { |
| 38 rootTransformNode = TransformPaintPropertyNode::create(TransformationMat
rix(), FloatPoint3D(), nullptr); | 38 rootTransformNode = TransformPaintPropertyNode::create(TransformationMat
rix(), FloatPoint3D(), nullptr); |
| 39 rootClipNode = ClipPaintPropertyNode::create(rootTransformNode, FloatRou
ndedRect(LayoutRect::infiniteIntRect()), nullptr); | 39 rootClipNode = ClipPaintPropertyNode::create(rootTransformNode, FloatRou
ndedRect(LayoutRect::infiniteIntRect()), nullptr); |
| 40 rootEffectNode = EffectPaintPropertyNode::create(1.0, nullptr); | 40 rootEffectNode = EffectPaintPropertyNode::create(1.0, nullptr); |
| 41 geometryMapper = wrapUnique(new GeometryMapper()); | 41 geometryMapper = wrapUnique(new GeometryMapper()); |
| 42 } | 42 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 53 do { \ | 53 do { \ |
| 54 const FloatRect& actualRect = actual; \ | 54 const FloatRect& actualRect = actual; \ |
| 55 EXPECT_TRUE(GeometryTest::ApproximatelyEqual(expected.x(), actualRect.x(), k
TestEpsilon)) << "actual: " << actualRect.x() << ", expected: " << expected.x();
\ | 55 EXPECT_TRUE(GeometryTest::ApproximatelyEqual(expected.x(), actualRect.x(), k
TestEpsilon)) << "actual: " << actualRect.x() << ", expected: " << expected.x();
\ |
| 56 EXPECT_TRUE(GeometryTest::ApproximatelyEqual(expected.y(), actualRect.y(), k
TestEpsilon)) << "actual: " << actualRect.y() << ", expected: " << expected.y();
\ | 56 EXPECT_TRUE(GeometryTest::ApproximatelyEqual(expected.y(), actualRect.y(), k
TestEpsilon)) << "actual: " << actualRect.y() << ", expected: " << expected.y();
\ |
| 57 EXPECT_TRUE(GeometryTest::ApproximatelyEqual(expected.width(), actualRect.wi
dth(), kTestEpsilon)) << "actual: " << actualRect.width() << ", expected: " << e
xpected.width(); \ | 57 EXPECT_TRUE(GeometryTest::ApproximatelyEqual(expected.width(), actualRect.wi
dth(), kTestEpsilon)) << "actual: " << actualRect.width() << ", expected: " << e
xpected.width(); \ |
| 58 EXPECT_TRUE(GeometryTest::ApproximatelyEqual(expected.height(), actualRect.h
eight(), kTestEpsilon)) << "actual: " << actualRect.height() << ", expected: " <
< expected.height(); \ | 58 EXPECT_TRUE(GeometryTest::ApproximatelyEqual(expected.height(), actualRect.h
eight(), kTestEpsilon)) << "actual: " << actualRect.height() << ", expected: " <
< expected.height(); \ |
| 59 } while (false) | 59 } while (false) |
| 60 | 60 |
| 61 #define CHECK_MAPPINGS(inputRect, expectedVisualRect, expectedTransformedRect, e
xpectedTransformToAncestor, expectedClipInAncestorSpace, localPropertyTreeState,
ancestorPropertyTreeState) \ | 61 #define CHECK_MAPPINGS(inputRect, expectedVisualRect, expectedTransformedRect, e
xpectedTransformToAncestor, expectedClipInAncestorSpace, localPropertyTreeState,
ancestorPropertyTreeState) \ |
| 62 do { \ | 62 do { \ |
| 63 bool success = false; \ |
| 63 EXPECT_RECT_EQ(expectedVisualRect, \ | 64 EXPECT_RECT_EQ(expectedVisualRect, \ |
| 64 geometryMapper->LocalToVisualRectInAncestorSpace(inputRect, localPropert
yTreeState, ancestorPropertyTreeState)); \ | 65 geometryMapper->localToVisualRectInAncestorSpace(inputRect, localPropert
yTreeState, ancestorPropertyTreeState, success)); \ |
| 66 EXPECT_TRUE(success); \ |
| 65 EXPECT_RECT_EQ(expectedTransformedRect, \ | 67 EXPECT_RECT_EQ(expectedTransformedRect, \ |
| 66 geometryMapper->LocalToAncestorRect(inputRect, localPropertyTreeState, a
ncestorPropertyTreeState)); \ | 68 geometryMapper->localToAncestorRect(inputRect, localPropertyTreeState, a
ncestorPropertyTreeState, success)); \ |
| 67 EXPECT_EQ(expectedTransformToAncestor, GetPrecomputedDataForAncestor(ancesto
rPropertyTreeState).toAncestorTransforms.get(localPropertyTreeState.transform));
\ | 69 EXPECT_TRUE(success); \ |
| 68 EXPECT_EQ(expectedClipInAncestorSpace, GetPrecomputedDataForAncestor(ancesto
rPropertyTreeState).toAncestorClipRects.get(localPropertyTreeState.clip)); \ | 70 EXPECT_EQ(expectedTransformToAncestor, getPrecomputedDataForAncestor(ancesto
rPropertyTreeState).toAncestorTransforms.get(localPropertyTreeState.transform.ge
t())); \ |
| 71 EXPECT_EQ(expectedClipInAncestorSpace, getPrecomputedDataForAncestor(ancesto
rPropertyTreeState).toAncestorClipRects.get(localPropertyTreeState.clip.get()));
\ |
| 69 } while (false) | 72 } while (false) |
| 70 | 73 |
| 71 TEST_F(GeometryMapperTest, Root) | 74 TEST_F(GeometryMapperTest, Root) |
| 72 { | 75 { |
| 73 FloatRect input(0, 0, 100, 100); | 76 FloatRect input(0, 0, 100, 100); |
| 74 | 77 |
| 75 CHECK_MAPPINGS(input, input, input, rootTransformNode->matrix(), rootClipNod
e->clipRect().rect(), rootPropertyTreeState(), rootPropertyTreeState()); | 78 CHECK_MAPPINGS(input, input, input, rootTransformNode->matrix(), rootClipNod
e->clipRect().rect(), rootPropertyTreeState(), rootPropertyTreeState()); |
| 76 } | 79 } |
| 77 | 80 |
| 78 TEST_F(GeometryMapperTest, IdentityTransform) | 81 TEST_F(GeometryMapperTest, IdentityTransform) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 94 PropertyTreeState localState = rootPropertyTreeState(); | 97 PropertyTreeState localState = rootPropertyTreeState(); |
| 95 localState.transform = transform.get(); | 98 localState.transform = transform.get(); |
| 96 | 99 |
| 97 FloatRect input(0, 0, 100, 100); | 100 FloatRect input(0, 0, 100, 100); |
| 98 FloatRect output = transformMatrix.mapRect(input); | 101 FloatRect output = transformMatrix.mapRect(input); |
| 99 | 102 |
| 100 CHECK_MAPPINGS(input, output, output, transform->matrix(), rootClipNode->cli
pRect().rect(), localState, rootPropertyTreeState()); | 103 CHECK_MAPPINGS(input, output, output, transform->matrix(), rootClipNode->cli
pRect().rect(), localState, rootPropertyTreeState()); |
| 101 | 104 |
| 102 bool success = false; | 105 bool success = false; |
| 103 EXPECT_RECT_EQ(input, | 106 EXPECT_RECT_EQ(input, |
| 104 geometryMapper->AncestorToLocalRect(output, localState, rootPropertyTree
State(), &success)); | 107 geometryMapper->ancestorToLocalRect(output, localState, rootPropertyTree
State(), success)); |
| 105 EXPECT_TRUE(success); | 108 EXPECT_TRUE(success); |
| 106 } | 109 } |
| 107 | 110 |
| 108 TEST_F(GeometryMapperTest, RotationAndScaleTransform) | 111 TEST_F(GeometryMapperTest, RotationAndScaleTransform) |
| 109 { | 112 { |
| 110 TransformationMatrix transformMatrix; | 113 TransformationMatrix transformMatrix; |
| 111 transformMatrix.rotate(45); | 114 transformMatrix.rotate(45); |
| 112 transformMatrix.scale(2); | 115 transformMatrix.scale(2); |
| 113 RefPtr<TransformPaintPropertyNode> transform = TransformPaintPropertyNode::c
reate(transformMatrix, FloatPoint3D(0, 0, 0), rootPropertyTreeState().transform)
; | 116 RefPtr<TransformPaintPropertyNode> transform = TransformPaintPropertyNode::c
reate(transformMatrix, FloatPoint3D(0, 0, 0), rootPropertyTreeState().transform)
; |
| 114 PropertyTreeState localState = rootPropertyTreeState(); | 117 PropertyTreeState localState = rootPropertyTreeState(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 PropertyTreeState localState = rootPropertyTreeState(); | 152 PropertyTreeState localState = rootPropertyTreeState(); |
| 150 localState.transform = transform2.get(); | 153 localState.transform = transform2.get(); |
| 151 | 154 |
| 152 FloatRect input(0, 0, 100, 100); | 155 FloatRect input(0, 0, 100, 100); |
| 153 TransformationMatrix final = rotateTransform * scaleTransform; | 156 TransformationMatrix final = rotateTransform * scaleTransform; |
| 154 FloatRect output = final.mapRect(input); | 157 FloatRect output = final.mapRect(input); |
| 155 | 158 |
| 156 CHECK_MAPPINGS(input, output, output, final, rootClipNode->clipRect().rect()
, localState, rootPropertyTreeState()); | 159 CHECK_MAPPINGS(input, output, output, final, rootClipNode->clipRect().rect()
, localState, rootPropertyTreeState()); |
| 157 | 160 |
| 158 // Check the cached matrix for the intermediate transform. | 161 // Check the cached matrix for the intermediate transform. |
| 159 EXPECT_EQ(rotateTransform, GetPrecomputedDataForAncestor(rootPropertyTreeSta
te()).toAncestorTransforms.get(transform1.get())); | 162 EXPECT_EQ(rotateTransform, getPrecomputedDataForAncestor(rootPropertyTreeSta
te()).toAncestorTransforms.get(transform1.get())); |
| 160 } | 163 } |
| 161 | 164 |
| 162 TEST_F(GeometryMapperTest, NestedTransformsIntermediateDestination) | 165 TEST_F(GeometryMapperTest, NestedTransformsIntermediateDestination) |
| 163 { | 166 { |
| 164 TransformationMatrix rotateTransform; | 167 TransformationMatrix rotateTransform; |
| 165 rotateTransform.rotate(45); | 168 rotateTransform.rotate(45); |
| 166 RefPtr<TransformPaintPropertyNode> transform1 = TransformPaintPropertyNode::
create(rotateTransform, FloatPoint3D(), rootPropertyTreeState().transform); | 169 RefPtr<TransformPaintPropertyNode> transform1 = TransformPaintPropertyNode::
create(rotateTransform, FloatPoint3D(), rootPropertyTreeState().transform); |
| 167 | 170 |
| 168 TransformationMatrix scaleTransform; | 171 TransformationMatrix scaleTransform; |
| 169 scaleTransform.scale(2); | 172 scaleTransform.scale(2); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 CHECK_MAPPINGS( | 305 CHECK_MAPPINGS( |
| 303 input, // Input | 306 input, // Input |
| 304 output, // Visual rect | 307 output, // Visual rect |
| 305 rotateTransform.mapRect(input), // Transformed rect (not clipped) | 308 rotateTransform.mapRect(input), // Transformed rect (not clipped) |
| 306 rotateTransform, // Transform matrix to ancestor space | 309 rotateTransform, // Transform matrix to ancestor space |
| 307 mappedClip, // Clip rect in ancestor space | 310 mappedClip, // Clip rect in ancestor space |
| 308 localState, rootPropertyTreeState()); | 311 localState, rootPropertyTreeState()); |
| 309 } | 312 } |
| 310 } | 313 } |
| 311 | 314 |
| 315 TEST_F(GeometryMapperTest, SiblingTransforms) |
| 316 { |
| 317 // These transforms are siblings. Thus mapping from one to the other require
s going through the root. |
| 318 TransformationMatrix rotateTransform1; |
| 319 rotateTransform1.rotate(45); |
| 320 RefPtr<TransformPaintPropertyNode> transform1 = TransformPaintPropertyNode::
create(rotateTransform1, FloatPoint3D(), rootPropertyTreeState().transform); |
| 321 |
| 322 TransformationMatrix rotateTransform2; |
| 323 rotateTransform2.rotate(-45); |
| 324 RefPtr<TransformPaintPropertyNode> transform2 = TransformPaintPropertyNode::
create(rotateTransform2, FloatPoint3D(), rootPropertyTreeState().transform); |
| 325 |
| 326 PropertyTreeState transform1State = rootPropertyTreeState(); |
| 327 transform1State.transform = transform1; |
| 328 PropertyTreeState transform2State = rootPropertyTreeState(); |
| 329 transform2State.transform = transform2; |
| 330 |
| 331 bool success; |
| 332 FloatRect input(0, 0, 100, 100); |
| 333 FloatRect result = geometryMapper->localToVisualRectInAncestorSpace(input, t
ransform1State, transform2State, success); |
| 334 // Fails, because the transform2state is not an ancestor of transform1State. |
| 335 EXPECT_FALSE(success); |
| 336 EXPECT_RECT_EQ(input, result); |
| 337 |
| 338 result = geometryMapper->localToVisualRectInAncestorSpace(input, transform2S
tate, transform1State, success); |
| 339 // Fails, because the transform1state is not an ancestor of transform2State. |
| 340 EXPECT_FALSE(success); |
| 341 EXPECT_RECT_EQ(input, result); |
| 342 |
| 343 FloatRect expected = rotateTransform2.inverse().mapRect(rotateTransform1.map
Rect(input)); |
| 344 result = geometryMapper->mapToVisualRectInDestinationSpace(input, transform1
State, transform2State, success); |
| 345 EXPECT_TRUE(success); |
| 346 EXPECT_RECT_EQ(expected, result); |
| 347 } |
| 348 |
| 312 } // namespace blink | 349 } // namespace blink |
| OLD | NEW |