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

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

Issue 2678263002: Plumb border radius through when computing clip visual rects. (Closed)
Patch Set: none Created 3 years, 10 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/paint/ClipPaintPropertyNode.h" 9 #include "platform/graphics/paint/ClipPaintPropertyNode.h"
10 #include "platform/graphics/paint/EffectPaintPropertyNode.h" 10 #include "platform/graphics/paint/EffectPaintPropertyNode.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 const TransformPaintPropertyNode* a, 43 const TransformPaintPropertyNode* a,
44 const TransformPaintPropertyNode* b) { 44 const TransformPaintPropertyNode* b) {
45 return GeometryMapper::lowestCommonAncestor(a, b); 45 return GeometryMapper::lowestCommonAncestor(a, b);
46 } 46 }
47 47
48 FloatRect sourceToDestinationVisualRectInternal( 48 FloatRect sourceToDestinationVisualRectInternal(
49 const FloatRect& rect, 49 const FloatRect& rect,
50 const PropertyTreeState& sourceState, 50 const PropertyTreeState& sourceState,
51 const PropertyTreeState& destinationState, 51 const PropertyTreeState& destinationState,
52 bool& success) { 52 bool& success) {
53 return geometryMapper->localToAncestorVisualRectInternal( 53 return geometryMapper
54 rect, sourceState, destinationState, success); 54 ->localToAncestorVisualRectInternal(rect, sourceState, destinationState,
55 success)
56 .rect();
55 } 57 }
56 58
57 FloatRect localToAncestorVisualRectInternal( 59 FloatRect localToAncestorVisualRectInternal(
58 const FloatRect& rect, 60 const FloatRect& rect,
59 const PropertyTreeState& localState, 61 const PropertyTreeState& localState,
60 const PropertyTreeState& ancestorState, 62 const PropertyTreeState& ancestorState,
61 bool& success) { 63 bool& success) {
62 return geometryMapper->localToAncestorVisualRectInternal( 64 return geometryMapper
63 rect, localState, ancestorState, success); 65 ->localToAncestorVisualRectInternal(rect, localState, ancestorState,
66 success)
67 .rect();
64 } 68 }
65 69
66 FloatRect localToAncestorRectInternal( 70 FloatRect localToAncestorRectInternal(
67 const FloatRect& rect, 71 const FloatRect& rect,
68 const TransformPaintPropertyNode* localTransformNode, 72 const TransformPaintPropertyNode* localTransformNode,
69 const TransformPaintPropertyNode* ancestorTransformNode, 73 const TransformPaintPropertyNode* ancestorTransformNode,
70 bool& success) { 74 bool& success) {
71 return geometryMapper->localToAncestorRectInternal( 75 return geometryMapper->localToAncestorRectInternal(
72 rect, localTransformNode, ancestorTransformNode, success); 76 rect, localTransformNode, ancestorTransformNode, success);
73 } 77 }
(...skipping 23 matching lines...) Expand all
97 << ", expected: " << expected.width(); \ 101 << ", expected: " << expected.width(); \
98 EXPECT_TRUE(GeometryTest::ApproximatelyEqual( \ 102 EXPECT_TRUE(GeometryTest::ApproximatelyEqual( \
99 expected.height(), actualRect.height(), kTestEpsilon)) \ 103 expected.height(), actualRect.height(), kTestEpsilon)) \
100 << "actual: " << actualRect.height() \ 104 << "actual: " << actualRect.height() \
101 << ", expected: " << expected.height(); \ 105 << ", expected: " << expected.height(); \
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) \ 111 ancestorPropertyTreeState, hasRadius) \
108 do { \ 112 do { \
109 EXPECT_RECT_EQ( \ 113 FloatClipRect clipRect = geometryMapper->localToAncestorVisualRect( \
110 expectedVisualRect, \ 114 inputRect, localPropertyTreeState, ancestorPropertyTreeState); \
111 geometryMapper->localToAncestorVisualRect( \ 115 EXPECT_EQ(hasRadius, clipRect.hasRadius()); \
112 inputRect, localPropertyTreeState, ancestorPropertyTreeState)); \ 116 EXPECT_RECT_EQ(expectedVisualRect, clipRect.rect()); \
113 FloatRect mappedClip = geometryMapper->localToAncestorClipRect( \ 117 clipRect = geometryMapper->localToAncestorClipRect( \
114 localPropertyTreeState, ancestorPropertyTreeState); \ 118 localPropertyTreeState, ancestorPropertyTreeState); \
115 EXPECT_RECT_EQ(expectedClipInAncestorSpace, mappedClip); \ 119 EXPECT_EQ(hasRadius, clipRect.hasRadius()); \
116 EXPECT_RECT_EQ( \ 120 EXPECT_RECT_EQ(expectedClipInAncestorSpace, clipRect.rect()); \
117 expectedVisualRect, \ 121 clipRect = geometryMapper->sourceToDestinationVisualRect( \
118 geometryMapper->sourceToDestinationVisualRect( \ 122 inputRect, localPropertyTreeState, ancestorPropertyTreeState); \
119 inputRect, localPropertyTreeState, ancestorPropertyTreeState)); \ 123 EXPECT_EQ(hasRadius, clipRect.hasRadius()); \
124 EXPECT_RECT_EQ(expectedVisualRect, clipRect.rect()); \
120 EXPECT_RECT_EQ(expectedTransformedRect, \ 125 EXPECT_RECT_EQ(expectedTransformedRect, \
121 geometryMapper->localToAncestorRect( \ 126 geometryMapper->localToAncestorRect( \
122 inputRect, localPropertyTreeState.transform(), \ 127 inputRect, localPropertyTreeState.transform(), \
123 ancestorPropertyTreeState.transform())); \ 128 ancestorPropertyTreeState.transform())); \
124 EXPECT_RECT_EQ(expectedTransformedRect, \ 129 EXPECT_RECT_EQ(expectedTransformedRect, \
125 geometryMapper->sourceToDestinationRect( \ 130 geometryMapper->sourceToDestinationRect( \
126 inputRect, localPropertyTreeState.transform(), \ 131 inputRect, localPropertyTreeState.transform(), \
127 ancestorPropertyTreeState.transform())); \ 132 ancestorPropertyTreeState.transform())); \
128 if (ancestorPropertyTreeState.transform() != \ 133 if (ancestorPropertyTreeState.transform() != \
129 localPropertyTreeState.transform()) { \ 134 localPropertyTreeState.transform()) { \
130 EXPECT_EQ(expectedTransformToAncestor, \ 135 EXPECT_EQ(expectedTransformToAncestor, \
131 getTransformCache(ancestorPropertyTreeState) \ 136 getTransformCache(ancestorPropertyTreeState) \
132 .get(localPropertyTreeState.transform())); \ 137 .get(localPropertyTreeState.transform())); \
133 } \ 138 } \
134 if (ancestorPropertyTreeState.clip() != localPropertyTreeState.clip()) { \ 139 if (ancestorPropertyTreeState.clip() != localPropertyTreeState.clip()) { \
135 EXPECT_EQ(expectedClipInAncestorSpace, \ 140 EXPECT_EQ(expectedClipInAncestorSpace, \
136 getClipCache(ancestorPropertyTreeState) \ 141 getClipCache(ancestorPropertyTreeState) \
137 .get(localPropertyTreeState.clip())); \ 142 .get(localPropertyTreeState.clip()) \
143 .rect()); \
138 } \ 144 } \
139 } while (false) 145 } while (false)
140 146
141 TEST_F(GeometryMapperTest, Root) { 147 TEST_F(GeometryMapperTest, Root) {
142 FloatRect input(0, 0, 100, 100); 148 FloatRect input(0, 0, 100, 100);
143 149
150 bool hasRadius = false;
144 CHECK_MAPPINGS(input, input, input, 151 CHECK_MAPPINGS(input, input, input,
145 TransformPaintPropertyNode::root()->matrix(), 152 TransformPaintPropertyNode::root()->matrix(),
146 ClipPaintPropertyNode::root()->clipRect().rect(), 153 ClipPaintPropertyNode::root()->clipRect().rect(),
147 rootPropertyTreeState(), rootPropertyTreeState()); 154 rootPropertyTreeState(), rootPropertyTreeState(), hasRadius);
148 } 155 }
149 156
150 TEST_F(GeometryMapperTest, IdentityTransform) { 157 TEST_F(GeometryMapperTest, IdentityTransform) {
151 RefPtr<TransformPaintPropertyNode> transform = 158 RefPtr<TransformPaintPropertyNode> transform =
152 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), 159 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(),
153 TransformationMatrix(), 160 TransformationMatrix(),
154 FloatPoint3D()); 161 FloatPoint3D());
155 PropertyTreeState localState = rootPropertyTreeState(); 162 PropertyTreeState localState = rootPropertyTreeState();
156 localState.setTransform(transform.get()); 163 localState.setTransform(transform.get());
157 164
158 FloatRect input(0, 0, 100, 100); 165 FloatRect input(0, 0, 100, 100);
159 166
167 bool hasRadius = false;
160 CHECK_MAPPINGS(input, input, input, transform->matrix(), 168 CHECK_MAPPINGS(input, input, input, transform->matrix(),
161 ClipPaintPropertyNode::root()->clipRect().rect(), localState, 169 ClipPaintPropertyNode::root()->clipRect().rect(), localState,
162 rootPropertyTreeState()); 170 rootPropertyTreeState(), hasRadius);
163 } 171 }
164 172
165 TEST_F(GeometryMapperTest, TranslationTransform) { 173 TEST_F(GeometryMapperTest, TranslationTransform) {
166 TransformationMatrix transformMatrix; 174 TransformationMatrix transformMatrix;
167 transformMatrix.translate(20, 10); 175 transformMatrix.translate(20, 10);
168 RefPtr<TransformPaintPropertyNode> transform = 176 RefPtr<TransformPaintPropertyNode> transform =
169 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), 177 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(),
170 transformMatrix, FloatPoint3D()); 178 transformMatrix, FloatPoint3D());
171 PropertyTreeState localState = rootPropertyTreeState(); 179 PropertyTreeState localState = rootPropertyTreeState();
172 localState.setTransform(transform.get()); 180 localState.setTransform(transform.get());
173 181
174 FloatRect input(0, 0, 100, 100); 182 FloatRect input(0, 0, 100, 100);
175 FloatRect output = transformMatrix.mapRect(input); 183 FloatRect output = transformMatrix.mapRect(input);
176 184
185 bool hasRadius = false;
177 CHECK_MAPPINGS(input, output, output, transform->matrix(), 186 CHECK_MAPPINGS(input, output, output, transform->matrix(),
178 ClipPaintPropertyNode::root()->clipRect().rect(), localState, 187 ClipPaintPropertyNode::root()->clipRect().rect(), localState,
179 rootPropertyTreeState()); 188 rootPropertyTreeState(), hasRadius);
180 189
181 EXPECT_RECT_EQ(input, geometryMapper->ancestorToLocalRect( 190 EXPECT_RECT_EQ(input, geometryMapper->ancestorToLocalRect(
182 output, rootPropertyTreeState().transform(), 191 output, rootPropertyTreeState().transform(),
183 localState.transform())); 192 localState.transform()));
184 } 193 }
185 194
186 TEST_F(GeometryMapperTest, RotationAndScaleTransform) { 195 TEST_F(GeometryMapperTest, RotationAndScaleTransform) {
187 TransformationMatrix transformMatrix; 196 TransformationMatrix transformMatrix;
188 transformMatrix.rotate(45); 197 transformMatrix.rotate(45);
189 transformMatrix.scale(2); 198 transformMatrix.scale(2);
190 RefPtr<TransformPaintPropertyNode> transform = 199 RefPtr<TransformPaintPropertyNode> transform =
191 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), 200 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(),
192 transformMatrix, 201 transformMatrix,
193 FloatPoint3D(0, 0, 0)); 202 FloatPoint3D(0, 0, 0));
194 PropertyTreeState localState = rootPropertyTreeState(); 203 PropertyTreeState localState = rootPropertyTreeState();
195 localState.setTransform(transform.get()); 204 localState.setTransform(transform.get());
196 205
197 FloatRect input(0, 0, 100, 100); 206 FloatRect input(0, 0, 100, 100);
198 FloatRect output = transformMatrix.mapRect(input); 207 FloatRect output = transformMatrix.mapRect(input);
199 208
209 bool hasRadius = false;
200 CHECK_MAPPINGS(input, output, output, transformMatrix, 210 CHECK_MAPPINGS(input, output, output, transformMatrix,
201 ClipPaintPropertyNode::root()->clipRect().rect(), localState, 211 ClipPaintPropertyNode::root()->clipRect().rect(), localState,
202 rootPropertyTreeState()); 212 rootPropertyTreeState(), hasRadius);
203 } 213 }
204 214
205 TEST_F(GeometryMapperTest, RotationAndScaleTransformWithTransformOrigin) { 215 TEST_F(GeometryMapperTest, RotationAndScaleTransformWithTransformOrigin) {
206 TransformationMatrix transformMatrix; 216 TransformationMatrix transformMatrix;
207 transformMatrix.rotate(45); 217 transformMatrix.rotate(45);
208 transformMatrix.scale(2); 218 transformMatrix.scale(2);
209 RefPtr<TransformPaintPropertyNode> transform = 219 RefPtr<TransformPaintPropertyNode> transform =
210 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), 220 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(),
211 transformMatrix, 221 transformMatrix,
212 FloatPoint3D(50, 50, 0)); 222 FloatPoint3D(50, 50, 0));
213 PropertyTreeState localState = rootPropertyTreeState(); 223 PropertyTreeState localState = rootPropertyTreeState();
214 localState.setTransform(transform.get()); 224 localState.setTransform(transform.get());
215 225
216 FloatRect input(0, 0, 100, 100); 226 FloatRect input(0, 0, 100, 100);
217 transformMatrix.applyTransformOrigin(50, 50, 0); 227 transformMatrix.applyTransformOrigin(50, 50, 0);
218 FloatRect output = transformMatrix.mapRect(input); 228 FloatRect output = transformMatrix.mapRect(input);
219 229
230 bool hasRadius = false;
220 CHECK_MAPPINGS(input, output, output, transformMatrix, 231 CHECK_MAPPINGS(input, output, output, transformMatrix,
221 ClipPaintPropertyNode::root()->clipRect().rect(), localState, 232 ClipPaintPropertyNode::root()->clipRect().rect(), localState,
222 rootPropertyTreeState()); 233 rootPropertyTreeState(), hasRadius);
223 } 234 }
224 235
225 TEST_F(GeometryMapperTest, NestedTransforms) { 236 TEST_F(GeometryMapperTest, NestedTransforms) {
226 TransformationMatrix rotateTransform; 237 TransformationMatrix rotateTransform;
227 rotateTransform.rotate(45); 238 rotateTransform.rotate(45);
228 RefPtr<TransformPaintPropertyNode> transform1 = 239 RefPtr<TransformPaintPropertyNode> transform1 =
229 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), 240 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(),
230 rotateTransform, FloatPoint3D()); 241 rotateTransform, FloatPoint3D());
231 242
232 TransformationMatrix scaleTransform; 243 TransformationMatrix scaleTransform;
233 scaleTransform.scale(2); 244 scaleTransform.scale(2);
234 RefPtr<TransformPaintPropertyNode> transform2 = 245 RefPtr<TransformPaintPropertyNode> transform2 =
235 TransformPaintPropertyNode::create(transform1, scaleTransform, 246 TransformPaintPropertyNode::create(transform1, scaleTransform,
236 FloatPoint3D()); 247 FloatPoint3D());
237 248
238 PropertyTreeState localState = rootPropertyTreeState(); 249 PropertyTreeState localState = rootPropertyTreeState();
239 localState.setTransform(transform2.get()); 250 localState.setTransform(transform2.get());
240 251
241 FloatRect input(0, 0, 100, 100); 252 FloatRect input(0, 0, 100, 100);
242 TransformationMatrix final = rotateTransform * scaleTransform; 253 TransformationMatrix final = rotateTransform * scaleTransform;
243 FloatRect output = final.mapRect(input); 254 FloatRect output = final.mapRect(input);
244 255
256 bool hasRadius = false;
245 CHECK_MAPPINGS(input, output, output, final, 257 CHECK_MAPPINGS(input, output, output, final,
246 ClipPaintPropertyNode::root()->clipRect().rect(), localState, 258 ClipPaintPropertyNode::root()->clipRect().rect(), localState,
247 rootPropertyTreeState()); 259 rootPropertyTreeState(), hasRadius);
248 260
249 // Check the cached matrix for the intermediate transform. 261 // Check the cached matrix for the intermediate transform.
250 EXPECT_EQ(rotateTransform, 262 EXPECT_EQ(rotateTransform,
251 getTransformCache(rootPropertyTreeState()).get(transform1.get())); 263 getTransformCache(rootPropertyTreeState()).get(transform1.get()));
252 } 264 }
253 265
254 TEST_F(GeometryMapperTest, NestedTransformsScaleAndTranslation) { 266 TEST_F(GeometryMapperTest, NestedTransformsScaleAndTranslation) {
255 TransformationMatrix scaleTransform; 267 TransformationMatrix scaleTransform;
256 scaleTransform.scale(2); 268 scaleTransform.scale(2);
257 RefPtr<TransformPaintPropertyNode> transform1 = 269 RefPtr<TransformPaintPropertyNode> transform1 =
258 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), 270 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(),
259 scaleTransform, FloatPoint3D()); 271 scaleTransform, FloatPoint3D());
260 272
261 TransformationMatrix translateTransform; 273 TransformationMatrix translateTransform;
262 translateTransform.translate(100, 0); 274 translateTransform.translate(100, 0);
263 RefPtr<TransformPaintPropertyNode> transform2 = 275 RefPtr<TransformPaintPropertyNode> transform2 =
264 TransformPaintPropertyNode::create(transform1, translateTransform, 276 TransformPaintPropertyNode::create(transform1, translateTransform,
265 FloatPoint3D()); 277 FloatPoint3D());
266 278
267 PropertyTreeState localState = rootPropertyTreeState(); 279 PropertyTreeState localState = rootPropertyTreeState();
268 localState.setTransform(transform2.get()); 280 localState.setTransform(transform2.get());
269 281
270 FloatRect input(0, 0, 100, 100); 282 FloatRect input(0, 0, 100, 100);
271 // Note: unlike NestedTransforms, the order of these transforms matters. This 283 // Note: unlike NestedTransforms, the order of these transforms matters. This
272 // tests correct order of matrix multiplication. 284 // tests correct order of matrix multiplication.
273 TransformationMatrix final = scaleTransform * translateTransform; 285 TransformationMatrix final = scaleTransform * translateTransform;
274 FloatRect output = final.mapRect(input); 286 FloatRect output = final.mapRect(input);
275 287
288 bool hasRadius = false;
276 CHECK_MAPPINGS(input, output, output, final, 289 CHECK_MAPPINGS(input, output, output, final,
277 ClipPaintPropertyNode::root()->clipRect().rect(), localState, 290 ClipPaintPropertyNode::root()->clipRect().rect(), localState,
278 rootPropertyTreeState()); 291 rootPropertyTreeState(), hasRadius);
279 292
280 // Check the cached matrix for the intermediate transform. 293 // Check the cached matrix for the intermediate transform.
281 EXPECT_EQ(scaleTransform, getTransformCache(rootPropertyTreeState()) 294 EXPECT_EQ(scaleTransform, getTransformCache(rootPropertyTreeState())
282 295
283 .get(transform1.get())); 296 .get(transform1.get()));
284 } 297 }
285 298
286 TEST_F(GeometryMapperTest, NestedTransformsIntermediateDestination) { 299 TEST_F(GeometryMapperTest, NestedTransformsIntermediateDestination) {
287 TransformationMatrix rotateTransform; 300 TransformationMatrix rotateTransform;
288 rotateTransform.rotate(45); 301 rotateTransform.rotate(45);
289 RefPtr<TransformPaintPropertyNode> transform1 = 302 RefPtr<TransformPaintPropertyNode> transform1 =
290 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), 303 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(),
291 rotateTransform, FloatPoint3D()); 304 rotateTransform, FloatPoint3D());
292 305
293 TransformationMatrix scaleTransform; 306 TransformationMatrix scaleTransform;
294 scaleTransform.scale(2); 307 scaleTransform.scale(2);
295 RefPtr<TransformPaintPropertyNode> transform2 = 308 RefPtr<TransformPaintPropertyNode> transform2 =
296 TransformPaintPropertyNode::create(transform1, scaleTransform, 309 TransformPaintPropertyNode::create(transform1, scaleTransform,
297 FloatPoint3D()); 310 FloatPoint3D());
298 311
299 PropertyTreeState localState = rootPropertyTreeState(); 312 PropertyTreeState localState = rootPropertyTreeState();
300 localState.setTransform(transform2.get()); 313 localState.setTransform(transform2.get());
301 314
302 PropertyTreeState intermediateState = rootPropertyTreeState(); 315 PropertyTreeState intermediateState = rootPropertyTreeState();
303 intermediateState.setTransform(transform1.get()); 316 intermediateState.setTransform(transform1.get());
304 317
305 FloatRect input(0, 0, 100, 100); 318 FloatRect input(0, 0, 100, 100);
306 FloatRect output = scaleTransform.mapRect(input); 319 FloatRect output = scaleTransform.mapRect(input);
307 320
321 bool hasRadius = false;
308 CHECK_MAPPINGS(input, output, output, scaleTransform, 322 CHECK_MAPPINGS(input, output, output, scaleTransform,
309 ClipPaintPropertyNode::root()->clipRect().rect(), localState, 323 ClipPaintPropertyNode::root()->clipRect().rect(), localState,
310 intermediateState); 324 intermediateState, hasRadius);
311 } 325 }
312 326
313 TEST_F(GeometryMapperTest, SimpleClip) { 327 TEST_F(GeometryMapperTest, SimpleClip) {
314 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create( 328 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create(
315 ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(), 329 ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(),
316 FloatRoundedRect(10, 10, 50, 50)); 330 FloatRoundedRect(10, 10, 50, 50));
317 331
318 PropertyTreeState localState = rootPropertyTreeState(); 332 PropertyTreeState localState = rootPropertyTreeState();
319 localState.setClip(clip.get()); 333 localState.setClip(clip.get());
320 334
321 FloatRect input(0, 0, 100, 100); 335 FloatRect input(0, 0, 100, 100);
322 FloatRect output(10, 10, 50, 50); 336 FloatRect output(10, 10, 50, 50);
323 337
338 bool hasRadius = false;
324 CHECK_MAPPINGS(input, // Input 339 CHECK_MAPPINGS(input, // Input
325 output, // Visual rect 340 output, // Visual rect
326 input, // Transformed rect (not clipped). 341 input, // Transformed rect (not clipped).
327 TransformPaintPropertyNode::root() 342 TransformPaintPropertyNode::root()
328 ->matrix(), // Transform matrix to ancestor space 343 ->matrix(), // Transform matrix to ancestor space
329 clip->clipRect().rect(), // Clip rect in ancestor space 344 clip->clipRect().rect(), // Clip rect in ancestor space
330 localState, 345 localState,
331 rootPropertyTreeState()); 346 rootPropertyTreeState(), hasRadius);
347 }
348
349 TEST_F(GeometryMapperTest, RoundedClip) {
350 FloatRoundedRect rect(FloatRect(10, 10, 50, 50),
351 FloatRoundedRect::Radii(FloatSize(1, 1), FloatSize(),
352 FloatSize(), FloatSize()));
353 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create(
354 ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(), rect);
355
356 PropertyTreeState localState = rootPropertyTreeState();
357 localState.setClip(clip.get());
358
359 FloatRect input(0, 0, 100, 100);
360 FloatRect output(10, 10, 50, 50);
361
362 bool hasRadius = true;
363 CHECK_MAPPINGS(input, // Input
364 output, // Visual rect
365 input, // Transformed rect (not clipped).
366 TransformPaintPropertyNode::root()
367 ->matrix(), // Transform matrix to ancestor space
368 clip->clipRect().rect(), // Clip rect in ancestor space
369 localState,
370 rootPropertyTreeState(), hasRadius);
332 } 371 }
333 372
334 TEST_F(GeometryMapperTest, TwoClips) { 373 TEST_F(GeometryMapperTest, TwoClips) {
374 FloatRoundedRect clipRect1(
375 FloatRect(10, 10, 30, 40),
376 FloatRoundedRect::Radii(FloatSize(1, 1), FloatSize(), FloatSize(),
377 FloatSize()));
378
335 RefPtr<ClipPaintPropertyNode> clip1 = ClipPaintPropertyNode::create( 379 RefPtr<ClipPaintPropertyNode> clip1 = ClipPaintPropertyNode::create(
336 ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(), 380 ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(),
337 FloatRoundedRect(10, 10, 30, 40)); 381 clipRect1);
338 382
339 RefPtr<ClipPaintPropertyNode> clip2 = 383 RefPtr<ClipPaintPropertyNode> clip2 =
340 ClipPaintPropertyNode::create(clip1, TransformPaintPropertyNode::root(), 384 ClipPaintPropertyNode::create(clip1, TransformPaintPropertyNode::root(),
341 FloatRoundedRect(10, 10, 50, 50)); 385 FloatRoundedRect(10, 10, 50, 50));
342 386
343 PropertyTreeState localState = rootPropertyTreeState(); 387 PropertyTreeState localState = rootPropertyTreeState();
344 PropertyTreeState ancestorState = rootPropertyTreeState(); 388 PropertyTreeState ancestorState = rootPropertyTreeState();
345 localState.setClip(clip2.get()); 389 localState.setClip(clip2.get());
346 390
347 FloatRect input(0, 0, 100, 100); 391 FloatRect input(0, 0, 100, 100);
348 FloatRect output1(10, 10, 30, 40); 392 FloatRect output1(10, 10, 30, 40);
349 393
394 bool hasRadius = true;
350 CHECK_MAPPINGS(input, // Input 395 CHECK_MAPPINGS(input, // Input
351 output1, // Visual rect 396 output1, // Visual rect
352 input, // Transformed rect (not clipped). 397 input, // Transformed rect (not clipped).
353 TransformPaintPropertyNode::root() 398 TransformPaintPropertyNode::root()
354 ->matrix(), // Transform matrix to ancestor space 399 ->matrix(), // Transform matrix to ancestor space
355 clip1->clipRect().rect(), // Clip rect in ancestor space 400 clip1->clipRect().rect(), // Clip rect in ancestor space
356 localState, 401 localState,
357 ancestorState); 402 ancestorState, hasRadius);
358 403
359 ancestorState.setClip(clip1.get()); 404 ancestorState.setClip(clip1.get());
360 FloatRect output2(10, 10, 50, 50); 405 FloatRect output2(10, 10, 50, 50);
361 406
407 hasRadius = false;
362 CHECK_MAPPINGS(input, // Input 408 CHECK_MAPPINGS(input, // Input
363 output2, // Visual rect 409 output2, // Visual rect
364 input, // Transformed rect (not clipped). 410 input, // Transformed rect (not clipped).
365 TransformPaintPropertyNode::root() 411 TransformPaintPropertyNode::root()
366 ->matrix(), // Transform matrix to ancestor space 412 ->matrix(), // Transform matrix to ancestor space
367 clip2->clipRect().rect(), // Clip rect in ancestor space 413 clip2->clipRect().rect(), // Clip rect in ancestor space
368 localState, 414 localState,
369 ancestorState); 415 ancestorState, hasRadius);
370 } 416 }
371 417
372 TEST_F(GeometryMapperTest, ClipBeforeTransform) { 418 TEST_F(GeometryMapperTest, ClipBeforeTransform) {
373 TransformationMatrix rotateTransform; 419 TransformationMatrix rotateTransform;
374 rotateTransform.rotate(45); 420 rotateTransform.rotate(45);
375 RefPtr<TransformPaintPropertyNode> transform = 421 RefPtr<TransformPaintPropertyNode> transform =
376 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), 422 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(),
377 rotateTransform, FloatPoint3D()); 423 rotateTransform, FloatPoint3D());
378 424
379 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create( 425 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create(
380 ClipPaintPropertyNode::root(), transform.get(), 426 ClipPaintPropertyNode::root(), transform.get(),
381 FloatRoundedRect(10, 10, 50, 50)); 427 FloatRoundedRect(10, 10, 50, 50));
382 428
383 PropertyTreeState localState = rootPropertyTreeState(); 429 PropertyTreeState localState = rootPropertyTreeState();
384 localState.setClip(clip.get()); 430 localState.setClip(clip.get());
385 localState.setTransform(transform.get()); 431 localState.setTransform(transform.get());
386 432
387 FloatRect input(0, 0, 100, 100); 433 FloatRect input(0, 0, 100, 100);
388 FloatRect output(input); 434 FloatRect output(input);
389 output.intersect(clip->clipRect().rect()); 435 output.intersect(clip->clipRect().rect());
390 output = rotateTransform.mapRect(output); 436 output = rotateTransform.mapRect(output);
391 437
438 bool hasRadius = false;
392 CHECK_MAPPINGS( 439 CHECK_MAPPINGS(
393 input, // Input 440 input, // Input
394 output, // Visual rect 441 output, // Visual rect
395 rotateTransform.mapRect(input), // Transformed rect (not clipped). 442 rotateTransform.mapRect(input), // Transformed rect (not clipped).
396 rotateTransform, // Transform matrix to ancestor space 443 rotateTransform, // Transform matrix to ancestor space
397 rotateTransform.mapRect( 444 rotateTransform.mapRect(
398 clip->clipRect().rect()), // Clip rect in ancestor space 445 clip->clipRect().rect()), // Clip rect in ancestor space
399 localState, 446 localState,
400 rootPropertyTreeState()); 447 rootPropertyTreeState(), hasRadius);
401 } 448 }
402 449
403 TEST_F(GeometryMapperTest, ClipAfterTransform) { 450 TEST_F(GeometryMapperTest, ClipAfterTransform) {
404 TransformationMatrix rotateTransform; 451 TransformationMatrix rotateTransform;
405 rotateTransform.rotate(45); 452 rotateTransform.rotate(45);
406 RefPtr<TransformPaintPropertyNode> transform = 453 RefPtr<TransformPaintPropertyNode> transform =
407 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), 454 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(),
408 rotateTransform, FloatPoint3D()); 455 rotateTransform, FloatPoint3D());
409 456
410 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create( 457 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create(
411 ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(), 458 ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(),
412 FloatRoundedRect(10, 10, 200, 200)); 459 FloatRoundedRect(10, 10, 200, 200));
413 460
414 PropertyTreeState localState = rootPropertyTreeState(); 461 PropertyTreeState localState = rootPropertyTreeState();
415 localState.setClip(clip.get()); 462 localState.setClip(clip.get());
416 localState.setTransform(transform.get()); 463 localState.setTransform(transform.get());
417 464
418 FloatRect input(0, 0, 100, 100); 465 FloatRect input(0, 0, 100, 100);
419 FloatRect output(input); 466 FloatRect output(input);
420 output = rotateTransform.mapRect(output); 467 output = rotateTransform.mapRect(output);
421 output.intersect(clip->clipRect().rect()); 468 output.intersect(clip->clipRect().rect());
422 469
470 bool hasRadius = false;
423 CHECK_MAPPINGS( 471 CHECK_MAPPINGS(
424 input, // Input 472 input, // Input
425 output, // Visual rect 473 output, // Visual rect
426 rotateTransform.mapRect(input), // Transformed rect (not clipped) 474 rotateTransform.mapRect(input), // Transformed rect (not clipped)
427 rotateTransform, // Transform matrix to ancestor space 475 rotateTransform, // Transform matrix to ancestor space
428 clip->clipRect().rect(), // Clip rect in ancestor space 476 clip->clipRect().rect(), // Clip rect in ancestor space
429 localState, rootPropertyTreeState()); 477 localState, rootPropertyTreeState(), hasRadius);
430 } 478 }
431 479
432 TEST_F(GeometryMapperTest, TwoClipsWithTransformBetween) { 480 TEST_F(GeometryMapperTest, TwoClipsWithTransformBetween) {
433 RefPtr<ClipPaintPropertyNode> clip1 = ClipPaintPropertyNode::create( 481 RefPtr<ClipPaintPropertyNode> clip1 = ClipPaintPropertyNode::create(
434 ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(), 482 ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(),
435 FloatRoundedRect(10, 10, 200, 200)); 483 FloatRoundedRect(10, 10, 200, 200));
436 484
437 TransformationMatrix rotateTransform; 485 TransformationMatrix rotateTransform;
438 rotateTransform.rotate(45); 486 rotateTransform.rotate(45);
439 RefPtr<TransformPaintPropertyNode> transform = 487 RefPtr<TransformPaintPropertyNode> transform =
440 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), 488 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(),
441 rotateTransform, FloatPoint3D()); 489 rotateTransform, FloatPoint3D());
442 490
443 RefPtr<ClipPaintPropertyNode> clip2 = ClipPaintPropertyNode::create( 491 RefPtr<ClipPaintPropertyNode> clip2 = ClipPaintPropertyNode::create(
444 clip1, transform.get(), FloatRoundedRect(10, 10, 200, 200)); 492 clip1, transform.get(), FloatRoundedRect(10, 10, 200, 200));
445 493
446 FloatRect input(0, 0, 100, 100); 494 FloatRect input(0, 0, 100, 100);
447 495
496 bool hasRadius = false;
448 { 497 {
449 PropertyTreeState localState = rootPropertyTreeState(); 498 PropertyTreeState localState = rootPropertyTreeState();
450 localState.setClip(clip1.get()); 499 localState.setClip(clip1.get());
451 localState.setTransform(transform.get()); 500 localState.setTransform(transform.get());
452 501
453 FloatRect output(input); 502 FloatRect output(input);
454 output = rotateTransform.mapRect(output); 503 output = rotateTransform.mapRect(output);
455 output.intersect(clip1->clipRect().rect()); 504 output.intersect(clip1->clipRect().rect());
456 505
457 CHECK_MAPPINGS( 506 CHECK_MAPPINGS(
458 input, // Input 507 input, // Input
459 output, // Visual rect 508 output, // Visual rect
460 rotateTransform.mapRect(input), // Transformed rect (not clipped) 509 rotateTransform.mapRect(input), // Transformed rect (not clipped)
461 rotateTransform, // Transform matrix to ancestor space 510 rotateTransform, // Transform matrix to ancestor space
462 clip1->clipRect().rect(), // Clip rect in ancestor space 511 clip1->clipRect().rect(), // Clip rect in ancestor space
463 localState, rootPropertyTreeState()); 512 localState, rootPropertyTreeState(), hasRadius);
464 } 513 }
465 514
466 { 515 {
467 PropertyTreeState localState = rootPropertyTreeState(); 516 PropertyTreeState localState = rootPropertyTreeState();
468 localState.setClip(clip2.get()); 517 localState.setClip(clip2.get());
469 localState.setTransform(transform.get()); 518 localState.setTransform(transform.get());
470 519
471 FloatRect mappedClip = rotateTransform.mapRect(clip2->clipRect().rect()); 520 FloatRect mappedClip = rotateTransform.mapRect(clip2->clipRect().rect());
472 mappedClip.intersect(clip1->clipRect().rect()); 521 mappedClip.intersect(clip1->clipRect().rect());
473 522
474 // All clips are performed in the space of the ancestor. In cases such as 523 // All clips are performed in the space of the ancestor. In cases such as
475 // this, this means the clip is a bit lossy. 524 // this, this means the clip is a bit lossy.
476 FloatRect output(input); 525 FloatRect output(input);
477 // Map to transformed rect in ancestor space. 526 // Map to transformed rect in ancestor space.
478 output = rotateTransform.mapRect(output); 527 output = rotateTransform.mapRect(output);
479 // Intersect with all clips between local and ancestor, independently mapped 528 // Intersect with all clips between local and ancestor, independently mapped
480 // to ancestor space. 529 // to ancestor space.
481 output.intersect(mappedClip); 530 output.intersect(mappedClip);
482 531
483 CHECK_MAPPINGS( 532 CHECK_MAPPINGS(
484 input, // Input 533 input, // Input
485 output, // Visual rect 534 output, // Visual rect
486 rotateTransform.mapRect(input), // Transformed rect (not clipped) 535 rotateTransform.mapRect(input), // Transformed rect (not clipped)
487 rotateTransform, // Transform matrix to ancestor space 536 rotateTransform, // Transform matrix to ancestor space
488 mappedClip, // Clip rect in ancestor space 537 mappedClip, // Clip rect in ancestor space
489 localState, rootPropertyTreeState()); 538 localState, rootPropertyTreeState(), hasRadius);
490 } 539 }
491 } 540 }
492 541
493 TEST_F(GeometryMapperTest, SiblingTransforms) { 542 TEST_F(GeometryMapperTest, SiblingTransforms) {
494 // These transforms are siblings. Thus mapping from one to the other requires 543 // These transforms are siblings. Thus mapping from one to the other requires
495 // going through the root. 544 // going through the root.
496 TransformationMatrix rotateTransform1; 545 TransformationMatrix rotateTransform1;
497 rotateTransform1.rotate(45); 546 rotateTransform1.rotate(45);
498 RefPtr<TransformPaintPropertyNode> transform1 = 547 RefPtr<TransformPaintPropertyNode> transform1 =
499 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), 548 TransformPaintPropertyNode::create(rootPropertyTreeState().transform(),
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 EXPECT_RECT_EQ(input, result); 580 EXPECT_RECT_EQ(input, result);
532 581
533 result = localToAncestorRectInternal(input, transform2.get(), 582 result = localToAncestorRectInternal(input, transform2.get(),
534 transform1.get(), success); 583 transform1.get(), success);
535 // Fails, because the transform1state is not an ancestor of transform2State. 584 // Fails, because the transform1state is not an ancestor of transform2State.
536 EXPECT_FALSE(success); 585 EXPECT_FALSE(success);
537 EXPECT_RECT_EQ(input, result); 586 EXPECT_RECT_EQ(input, result);
538 587
539 FloatRect expected = 588 FloatRect expected =
540 rotateTransform2.inverse().mapRect(rotateTransform1.mapRect(input)); 589 rotateTransform2.inverse().mapRect(rotateTransform1.mapRect(input));
541 result = geometryMapper->sourceToDestinationVisualRect(input, transform1State, 590 result = geometryMapper
542 transform2State); 591 ->sourceToDestinationVisualRect(input, transform1State,
592 transform2State)
593 .rect();
543 EXPECT_RECT_EQ(expected, result); 594 EXPECT_RECT_EQ(expected, result);
544 595
545 result = geometryMapper->sourceToDestinationRect(input, transform1.get(), 596 result = geometryMapper->sourceToDestinationRect(input, transform1.get(),
546 transform2.get()); 597 transform2.get());
547 EXPECT_RECT_EQ(expected, result); 598 EXPECT_RECT_EQ(expected, result);
548 } 599 }
549 600
550 TEST_F(GeometryMapperTest, SiblingTransformsWithClip) { 601 TEST_F(GeometryMapperTest, SiblingTransformsWithClip) {
551 // These transforms are siblings. Thus mapping from one to the other requires 602 // These transforms are siblings. Thus mapping from one to the other requires
552 // going through the root. 603 // going through the root.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 EXPECT_RECT_EQ(expected, result); 644 EXPECT_RECT_EQ(expected, result);
594 645
595 // Test map from transform2AndClipState to transform1State. 646 // Test map from transform2AndClipState to transform1State.
596 FloatRect expectedUnclipped = 647 FloatRect expectedUnclipped =
597 rotateTransform1.inverse().mapRect(rotateTransform2.mapRect(input)); 648 rotateTransform1.inverse().mapRect(rotateTransform2.mapRect(input));
598 FloatRect expectedClipped = rotateTransform1.inverse().mapRect( 649 FloatRect expectedClipped = rotateTransform1.inverse().mapRect(
599 rotateTransform2.mapRect(FloatRect(10, 10, 70, 70))); 650 rotateTransform2.mapRect(FloatRect(10, 10, 70, 70)));
600 651
601 // sourceToDestinationVisualRect ignores clip from the common ancestor to 652 // sourceToDestinationVisualRect ignores clip from the common ancestor to
602 // destination. 653 // destination.
603 result = geometryMapper->sourceToDestinationVisualRect( 654 result = geometryMapper
604 input, transform2AndClipState, transform1State); 655 ->sourceToDestinationVisualRect(input, transform2AndClipState,
656 transform1State)
657 .rect();
605 EXPECT_RECT_EQ(expectedClipped, result); 658 EXPECT_RECT_EQ(expectedClipped, result);
606 659
607 // sourceToDestinationRect applies transforms only. 660 // sourceToDestinationRect applies transforms only.
608 result = geometryMapper->sourceToDestinationRect(input, transform2.get(), 661 result = geometryMapper->sourceToDestinationRect(input, transform2.get(),
609 transform1.get()); 662 transform1.get());
610 EXPECT_RECT_EQ(expectedUnclipped, result); 663 EXPECT_RECT_EQ(expectedUnclipped, result);
611 } 664 }
612 665
613 TEST_F(GeometryMapperTest, LowestCommonAncestor) { 666 TEST_F(GeometryMapperTest, LowestCommonAncestor) {
614 TransformationMatrix matrix; 667 TransformationMatrix matrix;
(...skipping 25 matching lines...) Expand all
640 EXPECT_EQ(rootPropertyTreeState().transform(), 693 EXPECT_EQ(rootPropertyTreeState().transform(),
641 lowestCommonAncestor(childOfChild2.get(), 694 lowestCommonAncestor(childOfChild2.get(),
642 rootPropertyTreeState().transform())); 695 rootPropertyTreeState().transform()));
643 EXPECT_EQ(child2, lowestCommonAncestor(childOfChild2.get(), child2.get())); 696 EXPECT_EQ(child2, lowestCommonAncestor(childOfChild2.get(), child2.get()));
644 697
645 EXPECT_EQ(rootPropertyTreeState().transform(), 698 EXPECT_EQ(rootPropertyTreeState().transform(),
646 lowestCommonAncestor(child1.get(), child2.get())); 699 lowestCommonAncestor(child1.get(), child2.get()));
647 } 700 }
648 701
649 } // namespace blink 702 } // 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