| 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/BoxReflection.h" | 9 #include "platform/graphics/BoxReflection.h" |
| 10 #include "platform/graphics/filters/SkiaImageFilterBuilder.h" | 10 #include "platform/graphics/filters/SkiaImageFilterBuilder.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 const FloatRect& rect, | 68 const FloatRect& rect, |
| 69 const PropertyTreeState& localState, | 69 const PropertyTreeState& localState, |
| 70 const PropertyTreeState& ancestorState, | 70 const PropertyTreeState& ancestorState, |
| 71 bool& success) { | 71 bool& success) { |
| 72 return geometryMapper | 72 return geometryMapper |
| 73 ->localToAncestorVisualRectInternal(rect, localState, ancestorState, | 73 ->localToAncestorVisualRectInternal(rect, localState, ancestorState, |
| 74 success) | 74 success) |
| 75 .rect(); | 75 .rect(); |
| 76 } | 76 } |
| 77 | 77 |
| 78 FloatRect localToAncestorRectInternal( | 78 void localToAncestorRectInternal( |
| 79 const FloatRect& rect, | |
| 80 const TransformPaintPropertyNode* localTransformNode, | 79 const TransformPaintPropertyNode* localTransformNode, |
| 81 const TransformPaintPropertyNode* ancestorTransformNode, | 80 const TransformPaintPropertyNode* ancestorTransformNode, |
| 81 FloatRect& rect, |
| 82 bool& success) { | 82 bool& success) { |
| 83 return geometryMapper->localToAncestorRectInternal( | 83 geometryMapper->localToAncestorRectInternal( |
| 84 rect, localTransformNode, ancestorTransformNode, success); | 84 localTransformNode, ancestorTransformNode, rect, success); |
| 85 } | 85 } |
| 86 | 86 |
| 87 private: | 87 private: |
| 88 void SetUp() override { geometryMapper = GeometryMapper::create(); } | 88 void SetUp() override { geometryMapper = GeometryMapper::create(); } |
| 89 | 89 |
| 90 void TearDown() override { geometryMapper.reset(); } | 90 void TearDown() override { geometryMapper.reset(); } |
| 91 }; | 91 }; |
| 92 | 92 |
| 93 const static float kTestEpsilon = 1e-6; | 93 const static float kTestEpsilon = 1e-6; |
| 94 | 94 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 EXPECT_EQ(hasRadius, clipRect.hasRadius()); \ | 128 EXPECT_EQ(hasRadius, clipRect.hasRadius()); \ |
| 129 EXPECT_RECT_EQ(expectedVisualRect, clipRect.rect()); \ | 129 EXPECT_RECT_EQ(expectedVisualRect, clipRect.rect()); \ |
| 130 clipRect = geometryMapper->localToAncestorClipRect( \ | 130 clipRect = geometryMapper->localToAncestorClipRect( \ |
| 131 localPropertyTreeState, ancestorPropertyTreeState); \ | 131 localPropertyTreeState, ancestorPropertyTreeState); \ |
| 132 EXPECT_EQ(hasRadius, clipRect.hasRadius()); \ | 132 EXPECT_EQ(hasRadius, clipRect.hasRadius()); \ |
| 133 EXPECT_CLIP_RECT_EQ(expectedClipInAncestorSpace, clipRect); \ | 133 EXPECT_CLIP_RECT_EQ(expectedClipInAncestorSpace, clipRect); \ |
| 134 clipRect = geometryMapper->sourceToDestinationVisualRect( \ | 134 clipRect = geometryMapper->sourceToDestinationVisualRect( \ |
| 135 inputRect, localPropertyTreeState, ancestorPropertyTreeState); \ | 135 inputRect, localPropertyTreeState, ancestorPropertyTreeState); \ |
| 136 EXPECT_EQ(hasRadius, clipRect.hasRadius()); \ | 136 EXPECT_EQ(hasRadius, clipRect.hasRadius()); \ |
| 137 EXPECT_RECT_EQ(expectedVisualRect, clipRect.rect()); \ | 137 EXPECT_RECT_EQ(expectedVisualRect, clipRect.rect()); \ |
| 138 EXPECT_RECT_EQ(expectedTransformedRect, \ | 138 FloatRect testMappedRect = inputRect; \ |
| 139 geometryMapper->localToAncestorRect( \ | 139 geometryMapper->localToAncestorRect(localPropertyTreeState.transform(), \ |
| 140 inputRect, localPropertyTreeState.transform(), \ | 140 ancestorPropertyTreeState.transform(), \ |
| 141 ancestorPropertyTreeState.transform())); \ | 141 testMappedRect); \ |
| 142 EXPECT_RECT_EQ(expectedTransformedRect, \ | 142 EXPECT_RECT_EQ(expectedTransformedRect, testMappedRect); \ |
| 143 geometryMapper->sourceToDestinationRect( \ | 143 testMappedRect = inputRect; \ |
| 144 inputRect, localPropertyTreeState.transform(), \ | 144 geometryMapper->sourceToDestinationRect( \ |
| 145 ancestorPropertyTreeState.transform())); \ | 145 localPropertyTreeState.transform(), \ |
| 146 ancestorPropertyTreeState.transform(), testMappedRect); \ |
| 147 EXPECT_RECT_EQ(expectedTransformedRect, testMappedRect); \ |
| 146 if (ancestorPropertyTreeState.transform() != \ | 148 if (ancestorPropertyTreeState.transform() != \ |
| 147 localPropertyTreeState.transform()) { \ | 149 localPropertyTreeState.transform()) { \ |
| 148 const TransformationMatrix* transformForTesting = \ | 150 const TransformationMatrix* transformForTesting = \ |
| 149 getTransform(localPropertyTreeState.transform(), \ | 151 getTransform(localPropertyTreeState.transform(), \ |
| 150 ancestorPropertyTreeState.transform()); \ | 152 ancestorPropertyTreeState.transform()); \ |
| 151 CHECK(transformForTesting); \ | 153 CHECK(transformForTesting); \ |
| 152 EXPECT_EQ(expectedTransformToAncestor, *transformForTesting); \ | 154 EXPECT_EQ(expectedTransformToAncestor, *transformForTesting); \ |
| 153 } \ | 155 } \ |
| 154 if (ancestorPropertyTreeState.clip() != localPropertyTreeState.clip()) { \ | 156 if (ancestorPropertyTreeState.clip() != localPropertyTreeState.clip()) { \ |
| 155 const FloatClipRect* outputClipForTesting = \ | 157 const FloatClipRect* outputClipForTesting = \ |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 PropertyTreeState localState = rootPropertyTreeState(); | 196 PropertyTreeState localState = rootPropertyTreeState(); |
| 195 localState.setTransform(transform.get()); | 197 localState.setTransform(transform.get()); |
| 196 | 198 |
| 197 FloatRect input(0, 0, 100, 100); | 199 FloatRect input(0, 0, 100, 100); |
| 198 FloatRect output = transformMatrix.mapRect(input); | 200 FloatRect output = transformMatrix.mapRect(input); |
| 199 | 201 |
| 200 bool hasRadius = false; | 202 bool hasRadius = false; |
| 201 CHECK_MAPPINGS(input, output, output, transform->matrix(), FloatClipRect(), | 203 CHECK_MAPPINGS(input, output, output, transform->matrix(), FloatClipRect(), |
| 202 localState, rootPropertyTreeState(), hasRadius); | 204 localState, rootPropertyTreeState(), hasRadius); |
| 203 | 205 |
| 204 EXPECT_RECT_EQ(input, geometryMapper->ancestorToLocalRect( | 206 geometryMapper->ancestorToLocalRect(rootPropertyTreeState().transform(), |
| 205 output, rootPropertyTreeState().transform(), | 207 localState.transform(), output); |
| 206 localState.transform())); | 208 EXPECT_RECT_EQ(input, output); |
| 207 } | 209 } |
| 208 | 210 |
| 209 TEST_F(GeometryMapperTest, RotationAndScaleTransform) { | 211 TEST_F(GeometryMapperTest, RotationAndScaleTransform) { |
| 210 TransformationMatrix transformMatrix; | 212 TransformationMatrix transformMatrix; |
| 211 transformMatrix.rotate(45); | 213 transformMatrix.rotate(45); |
| 212 transformMatrix.scale(2); | 214 transformMatrix.scale(2); |
| 213 RefPtr<TransformPaintPropertyNode> transform = | 215 RefPtr<TransformPaintPropertyNode> transform = |
| 214 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), | 216 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), |
| 215 transformMatrix, | 217 transformMatrix, |
| 216 FloatPoint3D(0, 0, 0)); | 218 FloatPoint3D(0, 0, 0)); |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 transform2State.setTransform(transform2.get()); | 630 transform2State.setTransform(transform2.get()); |
| 629 | 631 |
| 630 bool success; | 632 bool success; |
| 631 FloatRect input(0, 0, 100, 100); | 633 FloatRect input(0, 0, 100, 100); |
| 632 FloatRect result = localToAncestorVisualRectInternal( | 634 FloatRect result = localToAncestorVisualRectInternal( |
| 633 input, transform1State, transform2State, success); | 635 input, transform1State, transform2State, success); |
| 634 // Fails, because the transform2state is not an ancestor of transform1State. | 636 // Fails, because the transform2state is not an ancestor of transform1State. |
| 635 EXPECT_FALSE(success); | 637 EXPECT_FALSE(success); |
| 636 EXPECT_RECT_EQ(input, result); | 638 EXPECT_RECT_EQ(input, result); |
| 637 | 639 |
| 638 result = localToAncestorRectInternal(input, transform1.get(), | 640 result = input; |
| 639 transform2.get(), success); | 641 localToAncestorRectInternal(transform1.get(), transform2.get(), result, |
| 642 success); |
| 640 // Fails, because the transform2state is not an ancestor of transform1State. | 643 // Fails, because the transform2state is not an ancestor of transform1State. |
| 641 EXPECT_FALSE(success); | 644 EXPECT_FALSE(success); |
| 642 EXPECT_RECT_EQ(input, result); | 645 EXPECT_RECT_EQ(input, result); |
| 643 | 646 |
| 644 result = localToAncestorVisualRectInternal(input, transform2State, | 647 result = localToAncestorVisualRectInternal(input, transform2State, |
| 645 transform1State, success); | 648 transform1State, success); |
| 646 // Fails, because the transform1state is not an ancestor of transform2State. | 649 // Fails, because the transform1state is not an ancestor of transform2State. |
| 647 EXPECT_FALSE(success); | 650 EXPECT_FALSE(success); |
| 648 EXPECT_RECT_EQ(input, result); | 651 EXPECT_RECT_EQ(input, result); |
| 649 | 652 |
| 650 result = localToAncestorRectInternal(input, transform2.get(), | 653 result = input; |
| 651 transform1.get(), success); | 654 localToAncestorRectInternal(transform2.get(), transform1.get(), result, |
| 655 success); |
| 652 // Fails, because the transform1state is not an ancestor of transform2State. | 656 // Fails, because the transform1state is not an ancestor of transform2State. |
| 653 EXPECT_FALSE(success); | 657 EXPECT_FALSE(success); |
| 654 EXPECT_RECT_EQ(input, result); | 658 EXPECT_RECT_EQ(input, result); |
| 655 | 659 |
| 656 FloatRect expected = | 660 FloatRect expected = |
| 657 rotateTransform2.inverse().mapRect(rotateTransform1.mapRect(input)); | 661 rotateTransform2.inverse().mapRect(rotateTransform1.mapRect(input)); |
| 658 result = geometryMapper | 662 result = geometryMapper |
| 659 ->sourceToDestinationVisualRect(input, transform1State, | 663 ->sourceToDestinationVisualRect(input, transform1State, |
| 660 transform2State) | 664 transform2State) |
| 661 .rect(); | 665 .rect(); |
| 662 EXPECT_RECT_EQ(expected, result); | 666 EXPECT_RECT_EQ(expected, result); |
| 663 | 667 |
| 664 result = geometryMapper->sourceToDestinationRect(input, transform1.get(), | 668 result = input; |
| 665 transform2.get()); | 669 geometryMapper->sourceToDestinationRect(transform1.get(), transform2.get(), |
| 670 result); |
| 666 EXPECT_RECT_EQ(expected, result); | 671 EXPECT_RECT_EQ(expected, result); |
| 667 } | 672 } |
| 668 | 673 |
| 669 TEST_F(GeometryMapperTest, SiblingTransformsWithClip) { | 674 TEST_F(GeometryMapperTest, SiblingTransformsWithClip) { |
| 670 // These transforms are siblings. Thus mapping from one to the other requires | 675 // These transforms are siblings. Thus mapping from one to the other requires |
| 671 // going through the root. | 676 // going through the root. |
| 672 TransformationMatrix rotateTransform1; | 677 TransformationMatrix rotateTransform1; |
| 673 rotateTransform1.rotate(45); | 678 rotateTransform1.rotate(45); |
| 674 RefPtr<TransformPaintPropertyNode> transform1 = | 679 RefPtr<TransformPaintPropertyNode> transform1 = |
| 675 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), | 680 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), |
| (...skipping 24 matching lines...) Expand all Loading... |
| 700 | 705 |
| 701 // sourceToDestinationVisualRect ignores clip from the common ancestor to | 706 // sourceToDestinationVisualRect ignores clip from the common ancestor to |
| 702 // destination. | 707 // destination. |
| 703 FloatRect result = sourceToDestinationVisualRectInternal( | 708 FloatRect result = sourceToDestinationVisualRectInternal( |
| 704 input, transform1State, transform2AndClipState, success); | 709 input, transform1State, transform2AndClipState, success); |
| 705 // Fails, because the clip of the destination state is not an ancestor of the | 710 // Fails, because the clip of the destination state is not an ancestor of the |
| 706 // clip of the source state. | 711 // clip of the source state. |
| 707 EXPECT_FALSE(success); | 712 EXPECT_FALSE(success); |
| 708 | 713 |
| 709 // sourceToDestinationRect applies transforms only. | 714 // sourceToDestinationRect applies transforms only. |
| 710 result = geometryMapper->sourceToDestinationRect(input, transform1.get(), | 715 result = input; |
| 711 transform2.get()); | 716 geometryMapper->sourceToDestinationRect(transform1.get(), transform2.get(), |
| 717 result); |
| 712 EXPECT_RECT_EQ(expected, result); | 718 EXPECT_RECT_EQ(expected, result); |
| 713 | 719 |
| 714 // Test map from transform2AndClipState to transform1State. | 720 // Test map from transform2AndClipState to transform1State. |
| 715 FloatRect expectedUnclipped = | 721 FloatRect expectedUnclipped = |
| 716 rotateTransform1.inverse().mapRect(rotateTransform2.mapRect(input)); | 722 rotateTransform1.inverse().mapRect(rotateTransform2.mapRect(input)); |
| 717 FloatRect expectedClipped = rotateTransform1.inverse().mapRect( | 723 FloatRect expectedClipped = rotateTransform1.inverse().mapRect( |
| 718 rotateTransform2.mapRect(FloatRect(10, 10, 70, 70))); | 724 rotateTransform2.mapRect(FloatRect(10, 10, 70, 70))); |
| 719 | 725 |
| 720 // sourceToDestinationVisualRect ignores clip from the common ancestor to | 726 // sourceToDestinationVisualRect ignores clip from the common ancestor to |
| 721 // destination. | 727 // destination. |
| 722 result = geometryMapper | 728 result = geometryMapper |
| 723 ->sourceToDestinationVisualRect(input, transform2AndClipState, | 729 ->sourceToDestinationVisualRect(input, transform2AndClipState, |
| 724 transform1State) | 730 transform1State) |
| 725 .rect(); | 731 .rect(); |
| 726 EXPECT_RECT_EQ(expectedClipped, result); | 732 EXPECT_RECT_EQ(expectedClipped, result); |
| 727 | 733 |
| 728 // sourceToDestinationRect applies transforms only. | 734 // sourceToDestinationRect applies transforms only. |
| 729 result = geometryMapper->sourceToDestinationRect(input, transform2.get(), | 735 result = input; |
| 730 transform1.get()); | 736 geometryMapper->sourceToDestinationRect(transform2.get(), transform1.get(), |
| 737 result); |
| 731 EXPECT_RECT_EQ(expectedUnclipped, result); | 738 EXPECT_RECT_EQ(expectedUnclipped, result); |
| 732 } | 739 } |
| 733 | 740 |
| 734 TEST_F(GeometryMapperTest, LowestCommonAncestor) { | 741 TEST_F(GeometryMapperTest, LowestCommonAncestor) { |
| 735 TransformationMatrix matrix; | 742 TransformationMatrix matrix; |
| 736 RefPtr<TransformPaintPropertyNode> child1 = | 743 RefPtr<TransformPaintPropertyNode> child1 = |
| 737 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), | 744 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), |
| 738 matrix, FloatPoint3D()); | 745 matrix, FloatPoint3D()); |
| 739 RefPtr<TransformPaintPropertyNode> child2 = | 746 RefPtr<TransformPaintPropertyNode> child2 = |
| 740 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), | 747 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 FloatRect input(100, 100, 50, 50); | 842 FloatRect input(100, 100, 50, 50); |
| 836 // Reflection is at (50, 100, 50, 50). | 843 // Reflection is at (50, 100, 50, 50). |
| 837 FloatRect output(50, 100, 100, 50); | 844 FloatRect output(50, 100, 100, 50); |
| 838 | 845 |
| 839 bool hasRadius = false; | 846 bool hasRadius = false; |
| 840 CHECK_MAPPINGS(input, output, input, TransformationMatrix(), FloatClipRect(), | 847 CHECK_MAPPINGS(input, output, input, TransformationMatrix(), FloatClipRect(), |
| 841 localState, rootPropertyTreeState(), hasRadius); | 848 localState, rootPropertyTreeState(), hasRadius); |
| 842 } | 849 } |
| 843 | 850 |
| 844 } // namespace blink | 851 } // namespace blink |
| OLD | NEW |