| 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 } |
| 34 |
| 35 PassRefPtr<TransformPaintPropertyNode> leastCommonAncestor(PassRefPtr<Transf
ormPaintPropertyNode> a, PassRefPtr<TransformPaintPropertyNode> b) |
| 36 { |
| 37 return geometryMapper->leastCommonAncestor(a, b); |
| 33 } | 38 } |
| 34 | 39 |
| 35 private: | 40 private: |
| 36 void SetUp() override | 41 void SetUp() override |
| 37 { | 42 { |
| 38 rootTransformNode = TransformPaintPropertyNode::create(TransformationMat
rix(), FloatPoint3D(), nullptr); | 43 rootTransformNode = TransformPaintPropertyNode::create(TransformationMat
rix(), FloatPoint3D(), nullptr); |
| 39 rootClipNode = ClipPaintPropertyNode::create(rootTransformNode, FloatRou
ndedRect(LayoutRect::infiniteIntRect()), nullptr); | 44 rootClipNode = ClipPaintPropertyNode::create(rootTransformNode, FloatRou
ndedRect(LayoutRect::infiniteIntRect()), nullptr); |
| 40 rootEffectNode = EffectPaintPropertyNode::create(1.0, nullptr); | 45 rootEffectNode = EffectPaintPropertyNode::create(1.0, nullptr); |
| 41 geometryMapper = wrapUnique(new GeometryMapper()); | 46 geometryMapper = wrapUnique(new GeometryMapper()); |
| 42 } | 47 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 53 do { \ | 58 do { \ |
| 54 const FloatRect& actualRect = actual; \ | 59 const FloatRect& actualRect = actual; \ |
| 55 EXPECT_TRUE(GeometryTest::ApproximatelyEqual(expected.x(), actualRect.x(), k
TestEpsilon)) << "actual: " << actualRect.x() << ", expected: " << expected.x();
\ | 60 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();
\ | 61 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(); \ | 62 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(); \ | 63 EXPECT_TRUE(GeometryTest::ApproximatelyEqual(expected.height(), actualRect.h
eight(), kTestEpsilon)) << "actual: " << actualRect.height() << ", expected: " <
< expected.height(); \ |
| 59 } while (false) | 64 } while (false) |
| 60 | 65 |
| 61 #define CHECK_MAPPINGS(inputRect, expectedVisualRect, expectedTransformedRect, e
xpectedTransformToAncestor, expectedClipInAncestorSpace, localPropertyTreeState,
ancestorPropertyTreeState) \ | 66 #define CHECK_MAPPINGS(inputRect, expectedVisualRect, expectedTransformedRect, e
xpectedTransformToAncestor, expectedClipInAncestorSpace, localPropertyTreeState,
ancestorPropertyTreeState) \ |
| 62 do { \ | 67 do { \ |
| 68 bool success = false; \ |
| 63 EXPECT_RECT_EQ(expectedVisualRect, \ | 69 EXPECT_RECT_EQ(expectedVisualRect, \ |
| 64 geometryMapper->LocalToVisualRectInAncestorSpace(inputRect, localPropert
yTreeState, ancestorPropertyTreeState)); \ | 70 geometryMapper->localToVisualRectInAncestorSpace(inputRect, localPropert
yTreeState, ancestorPropertyTreeState, &success)); \ |
| 71 EXPECT_TRUE(success); \ |
| 65 EXPECT_RECT_EQ(expectedTransformedRect, \ | 72 EXPECT_RECT_EQ(expectedTransformedRect, \ |
| 66 geometryMapper->LocalToAncestorRect(inputRect, localPropertyTreeState, a
ncestorPropertyTreeState)); \ | 73 geometryMapper->localToAncestorRect(inputRect, localPropertyTreeState, a
ncestorPropertyTreeState, &success)); \ |
| 67 EXPECT_EQ(expectedTransformToAncestor, GetPrecomputedDataForAncestor(ancesto
rPropertyTreeState).toAncestorTransforms.get(localPropertyTreeState.transform));
\ | 74 EXPECT_TRUE(success); \ |
| 68 EXPECT_EQ(expectedClipInAncestorSpace, GetPrecomputedDataForAncestor(ancesto
rPropertyTreeState).toAncestorClipRects.get(localPropertyTreeState.clip)); \ | 75 EXPECT_EQ(expectedTransformToAncestor, getPrecomputedDataForAncestor(ancesto
rPropertyTreeState).toAncestorTransforms.get(localPropertyTreeState.transform.ge
t())); \ |
| 76 EXPECT_EQ(expectedClipInAncestorSpace, getPrecomputedDataForAncestor(ancesto
rPropertyTreeState).toAncestorClipRects.get(localPropertyTreeState.clip.get()));
\ |
| 69 } while (false) | 77 } while (false) |
| 70 | 78 |
| 71 TEST_F(GeometryMapperTest, Root) | 79 TEST_F(GeometryMapperTest, Root) |
| 72 { | 80 { |
| 73 FloatRect input(0, 0, 100, 100); | 81 FloatRect input(0, 0, 100, 100); |
| 74 | 82 |
| 75 CHECK_MAPPINGS(input, input, input, rootTransformNode->matrix(), rootClipNod
e->clipRect().rect(), rootPropertyTreeState(), rootPropertyTreeState()); | 83 CHECK_MAPPINGS(input, input, input, rootTransformNode->matrix(), rootClipNod
e->clipRect().rect(), rootPropertyTreeState(), rootPropertyTreeState()); |
| 76 } | 84 } |
| 77 | 85 |
| 78 TEST_F(GeometryMapperTest, IdentityTransform) | 86 TEST_F(GeometryMapperTest, IdentityTransform) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 94 PropertyTreeState localState = rootPropertyTreeState(); | 102 PropertyTreeState localState = rootPropertyTreeState(); |
| 95 localState.transform = transform.get(); | 103 localState.transform = transform.get(); |
| 96 | 104 |
| 97 FloatRect input(0, 0, 100, 100); | 105 FloatRect input(0, 0, 100, 100); |
| 98 FloatRect output = transformMatrix.mapRect(input); | 106 FloatRect output = transformMatrix.mapRect(input); |
| 99 | 107 |
| 100 CHECK_MAPPINGS(input, output, output, transform->matrix(), rootClipNode->cli
pRect().rect(), localState, rootPropertyTreeState()); | 108 CHECK_MAPPINGS(input, output, output, transform->matrix(), rootClipNode->cli
pRect().rect(), localState, rootPropertyTreeState()); |
| 101 | 109 |
| 102 bool success = false; | 110 bool success = false; |
| 103 EXPECT_RECT_EQ(input, | 111 EXPECT_RECT_EQ(input, |
| 104 geometryMapper->AncestorToLocalRect(output, localState, rootPropertyTree
State(), &success)); | 112 geometryMapper->ancestorToLocalRect(output, localState, rootPropertyTree
State(), &success)); |
| 105 EXPECT_TRUE(success); | 113 EXPECT_TRUE(success); |
| 106 } | 114 } |
| 107 | 115 |
| 108 TEST_F(GeometryMapperTest, RotationAndScaleTransform) | 116 TEST_F(GeometryMapperTest, RotationAndScaleTransform) |
| 109 { | 117 { |
| 110 TransformationMatrix transformMatrix; | 118 TransformationMatrix transformMatrix; |
| 111 transformMatrix.rotate(45); | 119 transformMatrix.rotate(45); |
| 112 transformMatrix.scale(2); | 120 transformMatrix.scale(2); |
| 113 RefPtr<TransformPaintPropertyNode> transform = TransformPaintPropertyNode::c
reate(transformMatrix, FloatPoint3D(0, 0, 0), rootPropertyTreeState().transform)
; | 121 RefPtr<TransformPaintPropertyNode> transform = TransformPaintPropertyNode::c
reate(transformMatrix, FloatPoint3D(0, 0, 0), rootPropertyTreeState().transform)
; |
| 114 PropertyTreeState localState = rootPropertyTreeState(); | 122 PropertyTreeState localState = rootPropertyTreeState(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 PropertyTreeState localState = rootPropertyTreeState(); | 157 PropertyTreeState localState = rootPropertyTreeState(); |
| 150 localState.transform = transform2.get(); | 158 localState.transform = transform2.get(); |
| 151 | 159 |
| 152 FloatRect input(0, 0, 100, 100); | 160 FloatRect input(0, 0, 100, 100); |
| 153 TransformationMatrix final = rotateTransform * scaleTransform; | 161 TransformationMatrix final = rotateTransform * scaleTransform; |
| 154 FloatRect output = final.mapRect(input); | 162 FloatRect output = final.mapRect(input); |
| 155 | 163 |
| 156 CHECK_MAPPINGS(input, output, output, final, rootClipNode->clipRect().rect()
, localState, rootPropertyTreeState()); | 164 CHECK_MAPPINGS(input, output, output, final, rootClipNode->clipRect().rect()
, localState, rootPropertyTreeState()); |
| 157 | 165 |
| 158 // Check the cached matrix for the intermediate transform. | 166 // Check the cached matrix for the intermediate transform. |
| 159 EXPECT_EQ(rotateTransform, GetPrecomputedDataForAncestor(rootPropertyTreeSta
te()).toAncestorTransforms.get(transform1.get())); | 167 EXPECT_EQ(rotateTransform, getPrecomputedDataForAncestor(rootPropertyTreeSta
te()).toAncestorTransforms.get(transform1.get())); |
| 160 } | 168 } |
| 161 | 169 |
| 162 TEST_F(GeometryMapperTest, NestedTransformsIntermediateDestination) | 170 TEST_F(GeometryMapperTest, NestedTransformsIntermediateDestination) |
| 163 { | 171 { |
| 164 TransformationMatrix rotateTransform; | 172 TransformationMatrix rotateTransform; |
| 165 rotateTransform.rotate(45); | 173 rotateTransform.rotate(45); |
| 166 RefPtr<TransformPaintPropertyNode> transform1 = TransformPaintPropertyNode::
create(rotateTransform, FloatPoint3D(), rootPropertyTreeState().transform); | 174 RefPtr<TransformPaintPropertyNode> transform1 = TransformPaintPropertyNode::
create(rotateTransform, FloatPoint3D(), rootPropertyTreeState().transform); |
| 167 | 175 |
| 168 TransformationMatrix scaleTransform; | 176 TransformationMatrix scaleTransform; |
| 169 scaleTransform.scale(2); | 177 scaleTransform.scale(2); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 CHECK_MAPPINGS( | 310 CHECK_MAPPINGS( |
| 303 input, // Input | 311 input, // Input |
| 304 output, // Visual rect | 312 output, // Visual rect |
| 305 rotateTransform.mapRect(input), // Transformed rect (not clipped) | 313 rotateTransform.mapRect(input), // Transformed rect (not clipped) |
| 306 rotateTransform, // Transform matrix to ancestor space | 314 rotateTransform, // Transform matrix to ancestor space |
| 307 mappedClip, // Clip rect in ancestor space | 315 mappedClip, // Clip rect in ancestor space |
| 308 localState, rootPropertyTreeState()); | 316 localState, rootPropertyTreeState()); |
| 309 } | 317 } |
| 310 } | 318 } |
| 311 | 319 |
| 320 TEST_F(GeometryMapperTest, SiblingTransforms) |
| 321 { |
| 322 // These transforms are siblings. Thus mapping from one to the other require
s going through the root. |
| 323 TransformationMatrix rotateTransform1; |
| 324 rotateTransform1.rotate(45); |
| 325 RefPtr<TransformPaintPropertyNode> transform1 = TransformPaintPropertyNode::
create(rotateTransform1, FloatPoint3D(), rootPropertyTreeState().transform); |
| 326 |
| 327 TransformationMatrix rotateTransform2; |
| 328 rotateTransform2.rotate(-45); |
| 329 RefPtr<TransformPaintPropertyNode> transform2 = TransformPaintPropertyNode::
create(rotateTransform2, FloatPoint3D(), rootPropertyTreeState().transform); |
| 330 |
| 331 PropertyTreeState transform1State = rootPropertyTreeState(); |
| 332 transform1State.transform = transform1; |
| 333 PropertyTreeState transform2State = rootPropertyTreeState(); |
| 334 transform2State.transform = transform2; |
| 335 |
| 336 bool success; |
| 337 FloatRect input(0, 0, 100, 100); |
| 338 FloatRect result = geometryMapper->localToVisualRectInAncestorSpace(input, t
ransform1State, transform2State, &success); |
| 339 // Fails, because the transform2state is not an ancestor of transform1State. |
| 340 EXPECT_FALSE(success); |
| 341 EXPECT_RECT_EQ(input, result); |
| 342 |
| 343 result = geometryMapper->localToVisualRectInAncestorSpace(input, transform2S
tate, transform1State, &success); |
| 344 // Fails, because the transform1state is not an ancestor of transform2State. |
| 345 EXPECT_FALSE(success); |
| 346 EXPECT_RECT_EQ(input, result); |
| 347 |
| 348 FloatRect expected = rotateTransform2.inverse().mapRect(rotateTransform1.map
Rect(input)); |
| 349 result = geometryMapper->mapToVisualRectInDestinationSpace(input, transform1
State, transform2State, &success); |
| 350 EXPECT_TRUE(success); |
| 351 EXPECT_RECT_EQ(expected, result); |
| 352 } |
| 353 |
| 354 TEST_F(GeometryMapperTest, LeastCommonAncestor) |
| 355 { |
| 356 TransformationMatrix matrix; |
| 357 RefPtr<TransformPaintPropertyNode> child1 = TransformPaintPropertyNode::crea
te(matrix, FloatPoint3D(), rootPropertyTreeState().transform); |
| 358 RefPtr<TransformPaintPropertyNode> child2 = TransformPaintPropertyNode::crea
te(matrix, FloatPoint3D(), rootPropertyTreeState().transform); |
| 359 |
| 360 RefPtr<TransformPaintPropertyNode> childOfChild1 = TransformPaintPropertyNod
e::create(matrix, FloatPoint3D(), child1); |
| 361 RefPtr<TransformPaintPropertyNode> childOfChild2 = TransformPaintPropertyNod
e::create(matrix, FloatPoint3D(), child2); |
| 362 |
| 363 EXPECT_EQ(rootPropertyTreeState().transform, leastCommonAncestor(childOfChil
d1, childOfChild2)); |
| 364 EXPECT_EQ(rootPropertyTreeState().transform, leastCommonAncestor(childOfChil
d1, child2)); |
| 365 EXPECT_EQ(rootPropertyTreeState().transform, leastCommonAncestor(childOfChil
d1, rootPropertyTreeState().transform)); |
| 366 EXPECT_EQ(child1, leastCommonAncestor(childOfChild1, child1)); |
| 367 |
| 368 EXPECT_EQ(rootPropertyTreeState().transform, leastCommonAncestor(childOfChil
d2, childOfChild1)); |
| 369 EXPECT_EQ(rootPropertyTreeState().transform, leastCommonAncestor(childOfChil
d2, child1)); |
| 370 EXPECT_EQ(rootPropertyTreeState().transform, leastCommonAncestor(childOfChil
d2, rootPropertyTreeState().transform)); |
| 371 EXPECT_EQ(child2, leastCommonAncestor(childOfChild2, child2)); |
| 372 |
| 373 EXPECT_EQ(rootPropertyTreeState().transform, leastCommonAncestor(child1, chi
ld2)); |
| 374 } |
| 375 |
| 312 } // namespace blink | 376 } // namespace blink |
| OLD | NEW |