Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(723)

Side by Side Diff: third_party/WebKit/Source/platform/graphics/paint/GeometryMapperTest.cpp

Issue 2802443002: Compute rounded-ness of visual rects (Closed)
Patch Set: none Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/paint/GeometryMapper.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 const TransformPaintPropertyNode* a, 42 const TransformPaintPropertyNode* a,
43 const TransformPaintPropertyNode* b) { 43 const TransformPaintPropertyNode* b) {
44 return GeometryMapper::lowestCommonAncestor(a, b); 44 return GeometryMapper::lowestCommonAncestor(a, b);
45 } 45 }
46 46
47 void sourceToDestinationVisualRectInternal( 47 void sourceToDestinationVisualRectInternal(
48 const PropertyTreeState& sourceState, 48 const PropertyTreeState& sourceState,
49 const PropertyTreeState& destinationState, 49 const PropertyTreeState& destinationState,
50 FloatRect& mappingRect, 50 FloatRect& mappingRect,
51 bool& success) { 51 bool& success) {
52 FloatClipRect floatClipRect(mappingRect);
52 GeometryMapper::localToAncestorVisualRectInternal( 53 GeometryMapper::localToAncestorVisualRectInternal(
53 sourceState, destinationState, mappingRect, success); 54 sourceState, destinationState, floatClipRect, success);
55 mappingRect = floatClipRect.rect();
54 } 56 }
55 57
56 void localToAncestorVisualRectInternal(const PropertyTreeState& localState, 58 void localToAncestorVisualRectInternal(const PropertyTreeState& localState,
57 const PropertyTreeState& ancestorState, 59 const PropertyTreeState& ancestorState,
58 FloatRect& mappingRect, 60 FloatRect& mappingRect,
59 bool& success) { 61 bool& success) {
62 FloatClipRect floatClipRect(mappingRect);
60 GeometryMapper::localToAncestorVisualRectInternal(localState, ancestorState, 63 GeometryMapper::localToAncestorVisualRectInternal(localState, ancestorState,
61 mappingRect, success); 64 floatClipRect, success);
65 mappingRect = floatClipRect.rect();
62 } 66 }
63 67
64 void localToAncestorRectInternal( 68 void localToAncestorRectInternal(
65 const TransformPaintPropertyNode* localTransformNode, 69 const TransformPaintPropertyNode* localTransformNode,
66 const TransformPaintPropertyNode* ancestorTransformNode, 70 const TransformPaintPropertyNode* ancestorTransformNode,
67 FloatRect& rect, 71 FloatRect& rect,
68 bool& success) { 72 bool& success) {
69 GeometryMapper::localToAncestorRectInternal( 73 GeometryMapper::localToAncestorRectInternal(
70 localTransformNode, ancestorTransformNode, rect, success); 74 localTransformNode, ancestorTransformNode, rect, success);
71 } 75 }
(...skipping 27 matching lines...) Expand all
99 EXPECT_EQ(expected.isInfinite(), actual.isInfinite()); \ 103 EXPECT_EQ(expected.isInfinite(), actual.isInfinite()); \
100 if (!expected.isInfinite()) \ 104 if (!expected.isInfinite()) \
101 EXPECT_RECT_EQ(expected.rect(), actual.rect()); \ 105 EXPECT_RECT_EQ(expected.rect(), actual.rect()); \
102 } while (false) 106 } while (false)
103 107
104 #define CHECK_MAPPINGS(inputRect, expectedVisualRect, expectedTransformedRect, \ 108 #define CHECK_MAPPINGS(inputRect, expectedVisualRect, expectedTransformedRect, \
105 expectedTransformToAncestor, \ 109 expectedTransformToAncestor, \
106 expectedClipInAncestorSpace, localPropertyTreeState, \ 110 expectedClipInAncestorSpace, localPropertyTreeState, \
107 ancestorPropertyTreeState, hasRadius) \ 111 ancestorPropertyTreeState, hasRadius) \
108 do { \ 112 do { \
109 FloatRect floatRect = inputRect; \ 113 FloatClipRect floatRect(inputRect); \
110 GeometryMapper::localToAncestorVisualRect( \ 114 GeometryMapper::localToAncestorVisualRect( \
111 localPropertyTreeState, ancestorPropertyTreeState, floatRect); \ 115 localPropertyTreeState, ancestorPropertyTreeState, floatRect); \
112 EXPECT_RECT_EQ(expectedVisualRect, floatRect); \ 116 EXPECT_RECT_EQ(expectedVisualRect, floatRect.rect()); \
117 EXPECT_EQ(hasRadius, floatRect.hasRadius()); \
113 FloatClipRect floatClipRect; \ 118 FloatClipRect floatClipRect; \
114 floatClipRect = GeometryMapper::localToAncestorClipRect( \ 119 floatClipRect = GeometryMapper::localToAncestorClipRect( \
115 localPropertyTreeState, ancestorPropertyTreeState); \ 120 localPropertyTreeState, ancestorPropertyTreeState); \
116 EXPECT_EQ(hasRadius, floatClipRect.hasRadius()); \ 121 EXPECT_EQ(hasRadius, floatClipRect.hasRadius()); \
117 EXPECT_CLIP_RECT_EQ(expectedClipInAncestorSpace, floatClipRect); \ 122 EXPECT_CLIP_RECT_EQ(expectedClipInAncestorSpace, floatClipRect); \
118 floatRect = inputRect; \ 123 floatRect.setRect(inputRect); \
119 GeometryMapper::sourceToDestinationVisualRect( \ 124 GeometryMapper::sourceToDestinationVisualRect( \
120 localPropertyTreeState, ancestorPropertyTreeState, floatRect); \ 125 localPropertyTreeState, ancestorPropertyTreeState, floatRect); \
121 EXPECT_RECT_EQ(expectedVisualRect, floatRect); \ 126 EXPECT_RECT_EQ(expectedVisualRect, floatRect.rect()); \
127 EXPECT_EQ(hasRadius, floatRect.hasRadius()); \
122 FloatRect testMappedRect = inputRect; \ 128 FloatRect testMappedRect = inputRect; \
123 GeometryMapper::localToAncestorRect(localPropertyTreeState.transform(), \ 129 GeometryMapper::localToAncestorRect(localPropertyTreeState.transform(), \
124 ancestorPropertyTreeState.transform(), \ 130 ancestorPropertyTreeState.transform(), \
125 testMappedRect); \ 131 testMappedRect); \
126 EXPECT_RECT_EQ(expectedTransformedRect, testMappedRect); \ 132 EXPECT_RECT_EQ(expectedTransformedRect, testMappedRect); \
127 testMappedRect = inputRect; \ 133 testMappedRect = inputRect; \
128 GeometryMapper::sourceToDestinationRect( \ 134 GeometryMapper::sourceToDestinationRect( \
129 localPropertyTreeState.transform(), \ 135 localPropertyTreeState.transform(), \
130 ancestorPropertyTreeState.transform(), testMappedRect); \ 136 ancestorPropertyTreeState.transform(), testMappedRect); \
131 EXPECT_RECT_EQ(expectedTransformedRect, testMappedRect); \ 137 EXPECT_RECT_EQ(expectedTransformedRect, testMappedRect); \
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 result = input; 671 result = input;
666 localToAncestorRectInternal(transform2.get(), transform1.get(), result, 672 localToAncestorRectInternal(transform2.get(), transform1.get(), result,
667 success); 673 success);
668 // Fails, because the transform1state is not an ancestor of transform2State. 674 // Fails, because the transform1state is not an ancestor of transform2State.
669 EXPECT_FALSE(success); 675 EXPECT_FALSE(success);
670 EXPECT_RECT_EQ(input, result); 676 EXPECT_RECT_EQ(input, result);
671 677
672 FloatRect expected = 678 FloatRect expected =
673 rotateTransform2.inverse().mapRect(rotateTransform1.mapRect(input)); 679 rotateTransform2.inverse().mapRect(rotateTransform1.mapRect(input));
674 result = input; 680 result = input;
681 FloatClipRect floatClipRect(result);
675 GeometryMapper::sourceToDestinationVisualRect(transform1State, 682 GeometryMapper::sourceToDestinationVisualRect(transform1State,
676 transform2State, result); 683 transform2State, floatClipRect);
684 result = floatClipRect.rect();
677 EXPECT_RECT_EQ(expected, result); 685 EXPECT_RECT_EQ(expected, result);
678 686
679 result = input; 687 result = input;
680 GeometryMapper::sourceToDestinationRect(transform1.get(), transform2.get(), 688 GeometryMapper::sourceToDestinationRect(transform1.get(), transform2.get(),
681 result); 689 result);
682 EXPECT_RECT_EQ(expected, result); 690 EXPECT_RECT_EQ(expected, result);
683 } 691 }
684 692
685 TEST_F(GeometryMapperTest, SiblingTransformsWithClip) { 693 TEST_F(GeometryMapperTest, SiblingTransformsWithClip) {
686 // These transforms are siblings. Thus mapping from one to the other requires 694 // These transforms are siblings. Thus mapping from one to the other requires
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 739
732 // Test map from transform2AndClipState to transform1State. 740 // Test map from transform2AndClipState to transform1State.
733 FloatRect expectedUnclipped = 741 FloatRect expectedUnclipped =
734 rotateTransform1.inverse().mapRect(rotateTransform2.mapRect(input)); 742 rotateTransform1.inverse().mapRect(rotateTransform2.mapRect(input));
735 FloatRect expectedClipped = rotateTransform1.inverse().mapRect( 743 FloatRect expectedClipped = rotateTransform1.inverse().mapRect(
736 rotateTransform2.mapRect(FloatRect(10, 10, 70, 70))); 744 rotateTransform2.mapRect(FloatRect(10, 10, 70, 70)));
737 745
738 // sourceToDestinationVisualRect ignores clip from the common ancestor to 746 // sourceToDestinationVisualRect ignores clip from the common ancestor to
739 // destination. 747 // destination.
740 result = input; 748 result = input;
749 FloatClipRect floatClipRect(result);
741 GeometryMapper::sourceToDestinationVisualRect(transform2AndClipState, 750 GeometryMapper::sourceToDestinationVisualRect(transform2AndClipState,
742 transform1State, result); 751 transform1State, floatClipRect);
752 result = floatClipRect.rect();
743 EXPECT_RECT_EQ(expectedClipped, result); 753 EXPECT_RECT_EQ(expectedClipped, result);
744 754
745 // sourceToDestinationRect applies transforms only. 755 // sourceToDestinationRect applies transforms only.
746 result = input; 756 result = input;
747 GeometryMapper::sourceToDestinationRect(transform2.get(), transform1.get(), 757 GeometryMapper::sourceToDestinationRect(transform2.get(), transform1.get(),
748 result); 758 result);
749 EXPECT_RECT_EQ(expectedUnclipped, result); 759 EXPECT_RECT_EQ(expectedUnclipped, result);
750 } 760 }
751 761
752 TEST_F(GeometryMapperTest, LowestCommonAncestor) { 762 TEST_F(GeometryMapperTest, LowestCommonAncestor) {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 FloatRect input(100, 100, 50, 50); 863 FloatRect input(100, 100, 50, 50);
854 // Reflection is at (50, 100, 50, 50). 864 // Reflection is at (50, 100, 50, 50).
855 FloatRect output(50, 100, 100, 50); 865 FloatRect output(50, 100, 100, 50);
856 866
857 bool hasRadius = false; 867 bool hasRadius = false;
858 CHECK_MAPPINGS(input, output, input, TransformationMatrix(), FloatClipRect(), 868 CHECK_MAPPINGS(input, output, input, TransformationMatrix(), FloatClipRect(),
859 localState, PropertyTreeState::root(), hasRadius); 869 localState, PropertyTreeState::root(), hasRadius);
860 } 870 }
861 871
862 } // namespace blink 872 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/paint/GeometryMapper.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698