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

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

Issue 2329463004: ABANDONED CL: Changes needed to make things compile after running rewrite_to_chrome_style tool. (Closed)
Patch Set: More fixes - things build fine at this point. 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
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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 #define EXPECT_CLIP_RECT_EQ(expected, actual) \ 101 #define EXPECT_CLIP_RECT_EQ(expected, actual) \
102 do { \ 102 do { \
103 EXPECT_EQ(expected.isInfinite(), actual.isInfinite()); \ 103 EXPECT_EQ(expected.isInfinite(), actual.isInfinite()); \
104 if (!expected.isInfinite()) \ 104 if (!expected.isInfinite()) \
105 EXPECT_RECT_EQ(expected.rect(), actual.rect()); \ 105 EXPECT_RECT_EQ(expected.rect(), actual.rect()); \
106 } while (false) 106 } while (false)
107 107
108 #define CHECK_MAPPINGS(inputRect, expectedVisualRect, expectedTransformedRect, \ 108 #define CHECK_MAPPINGS(inputRect, expectedVisualRect, expectedTransformedRect, \
109 expectedTransformToAncestor, \ 109 expectedTransformToAncestor, \
110 expectedClipInAncestorSpace, localPropertyTreeState, \ 110 expectedClipInAncestorSpace, localPropertyTreeState, \
111 ancestorPropertyTreeState, hasRadius) \ 111 ancestorPropertyTreeState) \
112 do { \ 112 do { \
113 FloatClipRect floatRect(inputRect); \ 113 FloatClipRect floatRect(inputRect); \
114 GeometryMapper::localToAncestorVisualRect( \ 114 GeometryMapper::localToAncestorVisualRect( \
115 localPropertyTreeState, ancestorPropertyTreeState, floatRect); \ 115 localPropertyTreeState, ancestorPropertyTreeState, floatRect); \
116 EXPECT_RECT_EQ(expectedVisualRect, floatRect.rect()); \ 116 EXPECT_RECT_EQ(expectedVisualRect, floatRect.rect()); \
117 EXPECT_EQ(hasRadius, floatRect.hasRadius()); \ 117 EXPECT_EQ(hasRadius, floatRect.hasRadius()); \
118 FloatClipRect floatClipRect; \ 118 FloatClipRect floatClipRect; \
119 floatClipRect = GeometryMapper::localToAncestorClipRect( \ 119 floatClipRect = GeometryMapper::localToAncestorClipRect( \
120 localPropertyTreeState, ancestorPropertyTreeState); \ 120 localPropertyTreeState, ancestorPropertyTreeState); \
121 EXPECT_EQ(hasRadius, floatClipRect.hasRadius()); \ 121 EXPECT_EQ(hasRadius, floatClipRect.HasRadius()); \
122 EXPECT_CLIP_RECT_EQ(expectedClipInAncestorSpace, floatClipRect); \ 122 EXPECT_CLIP_RECT_EQ(expectedClipInAncestorSpace, floatClipRect); \
123 floatRect.setRect(inputRect); \ 123 floatRect.setRect(inputRect); \
124 GeometryMapper::sourceToDestinationVisualRect( \ 124 GeometryMapper::sourceToDestinationVisualRect( \
125 localPropertyTreeState, ancestorPropertyTreeState, floatRect); \ 125 localPropertyTreeState, ancestorPropertyTreeState, floatRect); \
126 EXPECT_RECT_EQ(expectedVisualRect, floatRect.rect()); \ 126 EXPECT_RECT_EQ(expectedVisualRect, floatRect.rect()); \
127 EXPECT_EQ(hasRadius, floatRect.hasRadius()); \ 127 EXPECT_EQ(hasRadius, floatRect.hasRadius()); \
128 FloatRect testMappedRect = inputRect; \ 128 FloatRect testMappedRect = inputRect; \
129 GeometryMapper::localToAncestorRect(localPropertyTreeState.transform(), \ 129 GeometryMapper::localToAncestorRect(localPropertyTreeState.transform(), \
130 ancestorPropertyTreeState.transform(), \ 130 ancestorPropertyTreeState.transform(), \
131 testMappedRect); \ 131 testMappedRect); \
(...skipping 10 matching lines...) Expand all
142 ancestorPropertyTreeState.transform()); \ 142 ancestorPropertyTreeState.transform()); \
143 CHECK(transformForTesting); \ 143 CHECK(transformForTesting); \
144 EXPECT_EQ(expectedTransformToAncestor, *transformForTesting); \ 144 EXPECT_EQ(expectedTransformToAncestor, *transformForTesting); \
145 } \ 145 } \
146 if (ancestorPropertyTreeState.clip() != localPropertyTreeState.clip()) { \ 146 if (ancestorPropertyTreeState.clip() != localPropertyTreeState.clip()) { \
147 const FloatClipRect* outputClipForTesting = \ 147 const FloatClipRect* outputClipForTesting = \
148 getClip(localPropertyTreeState.clip(), ancestorPropertyTreeState); \ 148 getClip(localPropertyTreeState.clip(), ancestorPropertyTreeState); \
149 DCHECK(outputClipForTesting); \ 149 DCHECK(outputClipForTesting); \
150 EXPECT_EQ(expectedClipInAncestorSpace, *outputClipForTesting) \ 150 EXPECT_EQ(expectedClipInAncestorSpace, *outputClipForTesting) \
151 << "expected: " << expectedClipInAncestorSpace.rect().toString() \ 151 << "expected: " << expectedClipInAncestorSpace.rect().toString() \
152 << " (hasRadius: " << expectedClipInAncestorSpace.hasRadius() \ 152 << " (hasRadius: " << expectedClipInAncestorSpace.HasRadius() \
153 << ") " \ 153 << ") " \
154 << "actual: " << outputClipForTesting->rect().toString() \ 154 << "actual: " << outputClipForTesting->rect().toString() \
155 << " (hasRadius: " << outputClipForTesting->hasRadius() << ")"; \ 155 << " (hasRadius: " << outputClipForTesting->HasRadius() << ")"; \
156 } \ 156 } \
157 } while (false) 157 } while (false)
158 158
159 TEST_F(GeometryMapperTest, Root) { 159 TEST_F(GeometryMapperTest, Root) {
160 FloatRect input(0, 0, 100, 100); 160 FloatRect input(0, 0, 100, 100);
161 161
162 bool hasRadius = false; 162 bool hasRadius = false;
163 CHECK_MAPPINGS(input, input, input, 163 CHECK_MAPPINGS(input, input, input,
164 TransformPaintPropertyNode::root()->matrix(), FloatClipRect(), 164 TransformPaintPropertyNode::root()->matrix(), FloatClipRect(),
165 PropertyTreeState::root(), PropertyTreeState::root(), 165 PropertyTreeState::root(), PropertyTreeState::root(), hasRadius );
166 hasRadius);
167 } 166 }
168 167
169 TEST_F(GeometryMapperTest, IdentityTransform) { 168 TEST_F(GeometryMapperTest, IdentityTransform) {
170 RefPtr<TransformPaintPropertyNode> transform = 169 RefPtr<TransformPaintPropertyNode> transform =
171 TransformPaintPropertyNode::create(TransformPaintPropertyNode::root(), 170 TransformPaintPropertyNode::create(TransformPaintPropertyNode::root(),
172 TransformationMatrix(), 171 TransformationMatrix(),
173 FloatPoint3D()); 172 FloatPoint3D());
174 PropertyTreeState localState = PropertyTreeState::root(); 173 PropertyTreeState localState = PropertyTreeState::root();
175 localState.setTransform(transform.get()); 174 localState.setTransform(transform.get());
176 175
177 FloatRect input(0, 0, 100, 100); 176 FloatRect input(0, 0, 100, 100);
178 177
179 bool hasRadius = false; 178 bool hasRadius = false;
180 CHECK_MAPPINGS(input, input, input, transform->matrix(), FloatClipRect(), 179 CHECK_MAPPINGS(input, input, input, transform->matrix(), FloatClipRect(),
181 localState, PropertyTreeState::root(), hasRadius); 180 localState, PropertyTreeState::root());
182 } 181 }
183 182
184 TEST_F(GeometryMapperTest, TranslationTransform) { 183 TEST_F(GeometryMapperTest, TranslationTransform) {
185 TransformationMatrix transformMatrix; 184 TransformationMatrix transformMatrix;
186 transformMatrix.translate(20, 10); 185 transformMatrix.translate(20, 10);
187 RefPtr<TransformPaintPropertyNode> transform = 186 RefPtr<TransformPaintPropertyNode> transform =
188 TransformPaintPropertyNode::create(TransformPaintPropertyNode::root(), 187 TransformPaintPropertyNode::create(TransformPaintPropertyNode::root(),
189 transformMatrix, FloatPoint3D()); 188 transformMatrix, FloatPoint3D());
190 PropertyTreeState localState = PropertyTreeState::root(); 189 PropertyTreeState localState = PropertyTreeState::root();
191 localState.setTransform(transform.get()); 190 localState.setTransform(transform.get());
192 191
193 FloatRect input(0, 0, 100, 100); 192 FloatRect input(0, 0, 100, 100);
194 FloatRect output = transformMatrix.mapRect(input); 193 FloatRect output = transformMatrix.mapRect(input);
195 194
196 bool hasRadius = false; 195 bool hasRadius = false;
197 CHECK_MAPPINGS(input, output, output, transform->matrix(), FloatClipRect(), 196 CHECK_MAPPINGS(input, output, output, transform->matrix(), FloatClipRect(),
198 localState, PropertyTreeState::root(), hasRadius); 197 localState, PropertyTreeState::root());
199 198
200 GeometryMapper::ancestorToLocalRect(TransformPaintPropertyNode::root(), 199 GeometryMapper::ancestorToLocalRect(TransformPaintPropertyNode::root(),
201 localState.transform(), output); 200 localState.transform(), output);
202 EXPECT_RECT_EQ(input, output); 201 EXPECT_RECT_EQ(input, output);
203 } 202 }
204 203
205 TEST_F(GeometryMapperTest, RotationAndScaleTransform) { 204 TEST_F(GeometryMapperTest, RotationAndScaleTransform) {
206 TransformationMatrix transformMatrix; 205 TransformationMatrix transformMatrix;
207 transformMatrix.rotate(45); 206 transformMatrix.rotate(45);
208 transformMatrix.scale(2); 207 transformMatrix.scale(2);
209 RefPtr<TransformPaintPropertyNode> transform = 208 RefPtr<TransformPaintPropertyNode> transform =
210 TransformPaintPropertyNode::create(TransformPaintPropertyNode::root(), 209 TransformPaintPropertyNode::create(TransformPaintPropertyNode::root(),
211 transformMatrix, 210 transformMatrix,
212 FloatPoint3D(0, 0, 0)); 211 FloatPoint3D(0, 0, 0));
213 PropertyTreeState localState = PropertyTreeState::root(); 212 PropertyTreeState localState = PropertyTreeState::root();
214 localState.setTransform(transform.get()); 213 localState.setTransform(transform.get());
215 214
216 FloatRect input(0, 0, 100, 100); 215 FloatRect input(0, 0, 100, 100);
217 FloatRect output = transformMatrix.mapRect(input); 216 FloatRect output = transformMatrix.mapRect(input);
218 217
219 bool hasRadius = false; 218 bool hasRadius = false;
220 CHECK_MAPPINGS(input, output, output, transformMatrix, FloatClipRect(), 219 CHECK_MAPPINGS(input, output, output, transformMatrix, FloatClipRect(),
221 localState, PropertyTreeState::root(), hasRadius); 220 localState, PropertyTreeState::root());
222 } 221 }
223 222
224 TEST_F(GeometryMapperTest, RotationAndScaleTransformWithTransformOrigin) { 223 TEST_F(GeometryMapperTest, RotationAndScaleTransformWithTransformOrigin) {
225 TransformationMatrix transformMatrix; 224 TransformationMatrix transformMatrix;
226 transformMatrix.rotate(45); 225 transformMatrix.rotate(45);
227 transformMatrix.scale(2); 226 transformMatrix.scale(2);
228 RefPtr<TransformPaintPropertyNode> transform = 227 RefPtr<TransformPaintPropertyNode> transform =
229 TransformPaintPropertyNode::create(TransformPaintPropertyNode::root(), 228 TransformPaintPropertyNode::create(TransformPaintPropertyNode::root(),
230 transformMatrix, 229 transformMatrix,
231 FloatPoint3D(50, 50, 0)); 230 FloatPoint3D(50, 50, 0));
232 PropertyTreeState localState = PropertyTreeState::root(); 231 PropertyTreeState localState = PropertyTreeState::root();
233 localState.setTransform(transform.get()); 232 localState.setTransform(transform.get());
234 233
235 FloatRect input(0, 0, 100, 100); 234 FloatRect input(0, 0, 100, 100);
236 transformMatrix.applyTransformOrigin(50, 50, 0); 235 transformMatrix.applyTransformOrigin(50, 50, 0);
237 FloatRect output = transformMatrix.mapRect(input); 236 FloatRect output = transformMatrix.mapRect(input);
238 237
239 bool hasRadius = false; 238 bool hasRadius = false;
240 CHECK_MAPPINGS(input, output, output, transformMatrix, FloatClipRect(), 239 CHECK_MAPPINGS(input, output, output, transformMatrix, FloatClipRect(),
241 localState, PropertyTreeState::root(), hasRadius); 240 localState, PropertyTreeState::root());
242 } 241 }
243 242
244 TEST_F(GeometryMapperTest, NestedTransforms) { 243 TEST_F(GeometryMapperTest, NestedTransforms) {
245 TransformationMatrix rotateTransform; 244 TransformationMatrix rotateTransform;
246 rotateTransform.rotate(45); 245 rotateTransform.rotate(45);
247 RefPtr<TransformPaintPropertyNode> transform1 = 246 RefPtr<TransformPaintPropertyNode> transform1 =
248 TransformPaintPropertyNode::create(TransformPaintPropertyNode::root(), 247 TransformPaintPropertyNode::create(TransformPaintPropertyNode::root(),
249 rotateTransform, FloatPoint3D()); 248 rotateTransform, FloatPoint3D());
250 249
251 TransformationMatrix scaleTransform; 250 TransformationMatrix scaleTransform;
252 scaleTransform.scale(2); 251 scaleTransform.scale(2);
253 RefPtr<TransformPaintPropertyNode> transform2 = 252 RefPtr<TransformPaintPropertyNode> transform2 =
254 TransformPaintPropertyNode::create(transform1, scaleTransform, 253 TransformPaintPropertyNode::create(transform1, scaleTransform,
255 FloatPoint3D()); 254 FloatPoint3D());
256 255
257 PropertyTreeState localState = PropertyTreeState::root(); 256 PropertyTreeState localState = PropertyTreeState::root();
258 localState.setTransform(transform2.get()); 257 localState.setTransform(transform2.get());
259 258
260 FloatRect input(0, 0, 100, 100); 259 FloatRect input(0, 0, 100, 100);
261 TransformationMatrix final = rotateTransform * scaleTransform; 260 TransformationMatrix final = rotateTransform * scaleTransform;
262 FloatRect output = final.mapRect(input); 261 FloatRect output = final.mapRect(input);
263 262
264 bool hasRadius = false; 263 bool hasRadius = false;
265 CHECK_MAPPINGS(input, output, output, final, FloatClipRect(), localState, 264 CHECK_MAPPINGS(input, output, output, final, FloatClipRect(), localState,
266 PropertyTreeState::root(), hasRadius); 265 PropertyTreeState::root());
267 266
268 // Check the cached matrix for the intermediate transform. 267 // Check the cached matrix for the intermediate transform.
269 EXPECT_EQ(rotateTransform, *getTransform(transform1.get(), 268 EXPECT_EQ(rotateTransform, *getTransform(transform1.get(),
270 TransformPaintPropertyNode::root())); 269 TransformPaintPropertyNode::root()));
271 } 270 }
272 271
273 TEST_F(GeometryMapperTest, NestedTransformsFlattening) { 272 TEST_F(GeometryMapperTest, NestedTransformsFlattening) {
274 TransformationMatrix rotateTransform; 273 TransformationMatrix rotateTransform;
275 rotateTransform.rotate3d(45, 0, 0); 274 rotateTransform.rotate3d(45, 0, 0);
276 RefPtr<TransformPaintPropertyNode> transform1 = 275 RefPtr<TransformPaintPropertyNode> transform1 =
277 TransformPaintPropertyNode::create(TransformPaintPropertyNode::root(), 276 TransformPaintPropertyNode::create(TransformPaintPropertyNode::root(),
278 rotateTransform, FloatPoint3D()); 277 rotateTransform, FloatPoint3D());
279 278
280 TransformationMatrix inverseRotateTransform; 279 TransformationMatrix inverseRotateTransform;
281 inverseRotateTransform.rotate3d(-45, 0, 0); 280 inverseRotateTransform.rotate3d(-45, 0, 0);
282 RefPtr<TransformPaintPropertyNode> transform2 = 281 RefPtr<TransformPaintPropertyNode> transform2 =
283 TransformPaintPropertyNode::create(transform1, inverseRotateTransform, 282 TransformPaintPropertyNode::create(transform1, inverseRotateTransform,
284 FloatPoint3D(), 283 FloatPoint3D(),
285 true); // Flattens 284 true); // Flattens
286 285
287 PropertyTreeState localState = PropertyTreeState::root(); 286 PropertyTreeState localState = PropertyTreeState::root();
288 localState.setTransform(transform2.get()); 287 localState.setTransform(transform2.get());
289 288
290 FloatRect input(0, 0, 100, 100); 289 FloatRect input(0, 0, 100, 100);
291 rotateTransform.flattenTo2d(); 290 rotateTransform.flattenTo2d();
292 TransformationMatrix final = rotateTransform * inverseRotateTransform; 291 TransformationMatrix final = rotateTransform * inverseRotateTransform;
293 FloatRect output = final.mapRect(input); 292 FloatRect output = final.mapRect(input);
294 bool hasRadius = false; 293 bool hasRadius = false;
295 CHECK_MAPPINGS(input, output, output, final, FloatClipRect(), localState, 294 CHECK_MAPPINGS(input, output, output, final, FloatClipRect(), localState,
296 PropertyTreeState::root(), hasRadius); 295 PropertyTreeState::root());
297 } 296 }
298 297
299 TEST_F(GeometryMapperTest, NestedTransformsScaleAndTranslation) { 298 TEST_F(GeometryMapperTest, NestedTransformsScaleAndTranslation) {
300 TransformationMatrix scaleTransform; 299 TransformationMatrix scaleTransform;
301 scaleTransform.scale(2); 300 scaleTransform.scale(2);
302 RefPtr<TransformPaintPropertyNode> transform1 = 301 RefPtr<TransformPaintPropertyNode> transform1 =
303 TransformPaintPropertyNode::create(TransformPaintPropertyNode::root(), 302 TransformPaintPropertyNode::create(TransformPaintPropertyNode::root(),
304 scaleTransform, FloatPoint3D()); 303 scaleTransform, FloatPoint3D());
305 304
306 TransformationMatrix translateTransform; 305 TransformationMatrix translateTransform;
307 translateTransform.translate(100, 0); 306 translateTransform.translate(100, 0);
308 RefPtr<TransformPaintPropertyNode> transform2 = 307 RefPtr<TransformPaintPropertyNode> transform2 =
309 TransformPaintPropertyNode::create(transform1, translateTransform, 308 TransformPaintPropertyNode::create(transform1, translateTransform,
310 FloatPoint3D()); 309 FloatPoint3D());
311 310
312 PropertyTreeState localState = PropertyTreeState::root(); 311 PropertyTreeState localState = PropertyTreeState::root();
313 localState.setTransform(transform2.get()); 312 localState.setTransform(transform2.get());
314 313
315 FloatRect input(0, 0, 100, 100); 314 FloatRect input(0, 0, 100, 100);
316 // Note: unlike NestedTransforms, the order of these transforms matters. This 315 // Note: unlike NestedTransforms, the order of these transforms matters. This
317 // tests correct order of matrix multiplication. 316 // tests correct order of matrix multiplication.
318 TransformationMatrix final = scaleTransform * translateTransform; 317 TransformationMatrix final = scaleTransform * translateTransform;
319 FloatRect output = final.mapRect(input); 318 FloatRect output = final.mapRect(input);
320 319
321 bool hasRadius = false; 320 bool hasRadius = false;
322 CHECK_MAPPINGS(input, output, output, final, FloatClipRect(), localState, 321 CHECK_MAPPINGS(input, output, output, final, FloatClipRect(), localState,
323 PropertyTreeState::root(), hasRadius); 322 PropertyTreeState::root());
324 323
325 // Check the cached matrix for the intermediate transform. 324 // Check the cached matrix for the intermediate transform.
326 EXPECT_EQ(scaleTransform, *getTransform(transform1.get(), 325 EXPECT_EQ(scaleTransform, *getTransform(transform1.get(),
327 TransformPaintPropertyNode::root())); 326 TransformPaintPropertyNode::root()));
328 } 327 }
329 328
330 TEST_F(GeometryMapperTest, NestedTransformsIntermediateDestination) { 329 TEST_F(GeometryMapperTest, NestedTransformsIntermediateDestination) {
331 TransformationMatrix rotateTransform; 330 TransformationMatrix rotateTransform;
332 rotateTransform.rotate(45); 331 rotateTransform.rotate(45);
333 RefPtr<TransformPaintPropertyNode> transform1 = 332 RefPtr<TransformPaintPropertyNode> transform1 =
(...skipping 10 matching lines...) Expand all
344 localState.setTransform(transform2.get()); 343 localState.setTransform(transform2.get());
345 344
346 PropertyTreeState intermediateState = PropertyTreeState::root(); 345 PropertyTreeState intermediateState = PropertyTreeState::root();
347 intermediateState.setTransform(transform1.get()); 346 intermediateState.setTransform(transform1.get());
348 347
349 FloatRect input(0, 0, 100, 100); 348 FloatRect input(0, 0, 100, 100);
350 FloatRect output = scaleTransform.mapRect(input); 349 FloatRect output = scaleTransform.mapRect(input);
351 350
352 bool hasRadius = false; 351 bool hasRadius = false;
353 CHECK_MAPPINGS(input, output, output, scaleTransform, FloatClipRect(), 352 CHECK_MAPPINGS(input, output, output, scaleTransform, FloatClipRect(),
354 localState, intermediateState, hasRadius); 353 localState, intermediateState);
355 } 354 }
356 355
357 TEST_F(GeometryMapperTest, SimpleClip) { 356 TEST_F(GeometryMapperTest, SimpleClip) {
358 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create( 357 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create(
359 ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(), 358 ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(),
360 FloatRoundedRect(10, 10, 50, 50)); 359 FloatRoundedRect(10, 10, 50, 50));
361 360
362 PropertyTreeState localState = PropertyTreeState::root(); 361 PropertyTreeState localState = PropertyTreeState::root();
363 localState.setClip(clip.get()); 362 localState.setClip(clip.get());
364 363
365 FloatRect input(0, 0, 100, 100); 364 FloatRect input(0, 0, 100, 100);
366 FloatRect output(10, 10, 50, 50); 365 FloatRect output(10, 10, 50, 50);
367 366
368 bool hasRadius = false; 367 bool hasRadius = false;
369 CHECK_MAPPINGS(input, // Input 368 CHECK_MAPPINGS(input, // Input
370 output, // Visual rect 369 output, // Visual rect
371 input, // Transformed rect (not clipped). 370 input, // Transformed rect (not clipped).
372 TransformPaintPropertyNode::root() 371 TransformPaintPropertyNode::root()
373 ->matrix(), // Transform matrix to ancestor space 372 ->matrix(), // Transform matrix to ancestor space
374 FloatClipRect(clip->clipRect().rect()), // Clip rect in 373 FloatClipRect(clip->clipRect().rect()), // Clip rect in
375 // ancestor space 374 // ancestor space
376 localState, PropertyTreeState::root(), hasRadius); 375 localState, PropertyTreeState::root());
377 } 376 }
378 377
379 TEST_F(GeometryMapperTest, RoundedClip) { 378 TEST_F(GeometryMapperTest, RoundedClip) {
380 FloatRoundedRect rect(FloatRect(10, 10, 50, 50), 379 FloatRoundedRect rect(FloatRect(10, 10, 50, 50),
381 FloatRoundedRect::Radii(FloatSize(1, 1), FloatSize(), 380 FloatRoundedRect::Radii(FloatSize(1, 1), FloatSize(),
382 FloatSize(), FloatSize())); 381 FloatSize(), FloatSize()));
383 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create( 382 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create(
384 ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(), rect); 383 ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(), rect);
385 384
386 PropertyTreeState localState = PropertyTreeState::root(); 385 PropertyTreeState localState = PropertyTreeState::root();
387 localState.setClip(clip.get()); 386 localState.setClip(clip.get());
388 387
389 FloatRect input(0, 0, 100, 100); 388 FloatRect input(0, 0, 100, 100);
390 FloatRect output(10, 10, 50, 50); 389 FloatRect output(10, 10, 50, 50);
391 390
392 FloatClipRect expectedClip(clip->clipRect().rect()); 391 FloatClipRect expectedClip(clip->clipRect().rect());
393 expectedClip.setHasRadius(); 392 expectedClip.setHasRadius();
394 393
395 bool hasRadius = true; 394 bool hasRadius = true;
396 CHECK_MAPPINGS(input, // Input 395 CHECK_MAPPINGS(input, // Input
397 output, // Visual rect 396 output, // Visual rect
398 input, // Transformed rect (not clipped). 397 input, // Transformed rect (not clipped).
399 TransformPaintPropertyNode::root() 398 TransformPaintPropertyNode::root()
400 ->matrix(), // Transform matrix to ancestor space 399 ->matrix(), // Transform matrix to ancestor space
401 expectedClip, // Clip rect in ancestor space 400 expectedClip, // Clip rect in ancestor space
402 localState, PropertyTreeState::root(), hasRadius); 401 localState, PropertyTreeState::root());
403 } 402 }
404 403
405 TEST_F(GeometryMapperTest, TwoClips) { 404 TEST_F(GeometryMapperTest, TwoClips) {
406 FloatRoundedRect clipRect1( 405 FloatRoundedRect clipRect1(
407 FloatRect(10, 10, 30, 40), 406 FloatRect(10, 10, 30, 40),
408 FloatRoundedRect::Radii(FloatSize(1, 1), FloatSize(), FloatSize(), 407 FloatRoundedRect::Radii(FloatSize(1, 1), FloatSize(), FloatSize(),
409 FloatSize())); 408 FloatSize()));
410 409
411 RefPtr<ClipPaintPropertyNode> clip1 = ClipPaintPropertyNode::create( 410 RefPtr<ClipPaintPropertyNode> clip1 = ClipPaintPropertyNode::create(
412 ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(), 411 ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(),
(...skipping 14 matching lines...) Expand all
427 clipRect.setHasRadius(); 426 clipRect.setHasRadius();
428 427
429 bool hasRadius = true; 428 bool hasRadius = true;
430 CHECK_MAPPINGS(input, // Input 429 CHECK_MAPPINGS(input, // Input
431 output1, // Visual rect 430 output1, // Visual rect
432 input, // Transformed rect (not clipped). 431 input, // Transformed rect (not clipped).
433 TransformPaintPropertyNode::root() 432 TransformPaintPropertyNode::root()
434 ->matrix(), // Transform matrix to ancestor space 433 ->matrix(), // Transform matrix to ancestor space
435 clipRect, // Clip rect in ancestor space 434 clipRect, // Clip rect in ancestor space
436 localState, 435 localState,
437 ancestorState, hasRadius); 436 ancestorState);
438 437
439 ancestorState.setClip(clip1.get()); 438 ancestorState.setClip(clip1.get());
440 FloatRect output2(10, 10, 50, 50); 439 FloatRect output2(10, 10, 50, 50);
441 440
442 FloatClipRect clipRect2; 441 FloatClipRect clipRect2;
443 clipRect2.setRect(clip2->clipRect().rect()); 442 clipRect2.setRect(clip2->clipRect().rect());
444 443
445 hasRadius = false; 444 hasRadius = false;
446 CHECK_MAPPINGS(input, // Input 445 CHECK_MAPPINGS(input, // Input
447 output2, // Visual rect 446 output2, // Visual rect
448 input, // Transformed rect (not clipped). 447 input, // Transformed rect (not clipped).
449 TransformPaintPropertyNode::root() 448 TransformPaintPropertyNode::root()
450 ->matrix(), // Transform matrix to ancestor space 449 ->matrix(), // Transform matrix to ancestor space
451 clipRect2, // Clip rect in ancestor space 450 clipRect2, // Clip rect in ancestor space
452 localState, ancestorState, hasRadius); 451 localState, ancestorState);
453 } 452 }
454 453
455 TEST_F(GeometryMapperTest, TwoClipsTransformAbove) { 454 TEST_F(GeometryMapperTest, TwoClipsTransformAbove) {
456 RefPtr<TransformPaintPropertyNode> transform = 455 RefPtr<TransformPaintPropertyNode> transform =
457 TransformPaintPropertyNode::create(TransformPaintPropertyNode::root(), 456 TransformPaintPropertyNode::create(TransformPaintPropertyNode::root(),
458 TransformationMatrix(), 457 TransformationMatrix(),
459 FloatPoint3D()); 458 FloatPoint3D());
460 459
461 FloatRoundedRect clipRect1( 460 FloatRoundedRect clipRect1(
462 FloatRect(10, 10, 50, 50), 461 FloatRect(10, 10, 50, 50),
(...skipping 17 matching lines...) Expand all
480 expectedClip.setHasRadius(); 479 expectedClip.setHasRadius();
481 480
482 bool hasRadius = true; 481 bool hasRadius = true;
483 CHECK_MAPPINGS(input, // Input 482 CHECK_MAPPINGS(input, // Input
484 output1, // Visual rect 483 output1, // Visual rect
485 input, // Transformed rect (not clipped). 484 input, // Transformed rect (not clipped).
486 TransformPaintPropertyNode::root() 485 TransformPaintPropertyNode::root()
487 ->matrix(), // Transform matrix to ancestor space 486 ->matrix(), // Transform matrix to ancestor space
488 expectedClip, // Clip rect in ancestor space 487 expectedClip, // Clip rect in ancestor space
489 localState, 488 localState,
490 ancestorState, hasRadius); 489 ancestorState);
491 490
492 expectedClip.setRect(clip1->clipRect().rect()); 491 expectedClip.setRect(clip1->clipRect().rect());
493 localState.setClip(clip1.get()); 492 localState.setClip(clip1.get());
494 FloatRect output2(10, 10, 50, 50); 493 FloatRect output2(10, 10, 50, 50);
495 CHECK_MAPPINGS(input, // Input 494 CHECK_MAPPINGS(input, // Input
496 output2, // Visual rect 495 output2, // Visual rect
497 input, // Transformed rect (not clipped). 496 input, // Transformed rect (not clipped).
498 TransformPaintPropertyNode::root() 497 TransformPaintPropertyNode::root()
499 ->matrix(), // Transform matrix to ancestor space 498 ->matrix(), // Transform matrix to ancestor space
500 expectedClip, // Clip rect in ancestor space 499 expectedClip, // Clip rect in ancestor space
501 localState, 500 localState,
502 ancestorState, hasRadius); 501 ancestorState);
503 } 502 }
504 503
505 TEST_F(GeometryMapperTest, ClipBeforeTransform) { 504 TEST_F(GeometryMapperTest, ClipBeforeTransform) {
506 TransformationMatrix rotateTransform; 505 TransformationMatrix rotateTransform;
507 rotateTransform.rotate(45); 506 rotateTransform.rotate(45);
508 RefPtr<TransformPaintPropertyNode> transform = 507 RefPtr<TransformPaintPropertyNode> transform =
509 TransformPaintPropertyNode::create(TransformPaintPropertyNode::root(), 508 TransformPaintPropertyNode::create(TransformPaintPropertyNode::root(),
510 rotateTransform, FloatPoint3D()); 509 rotateTransform, FloatPoint3D());
511 510
512 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create( 511 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create(
(...skipping 10 matching lines...) Expand all
523 output = rotateTransform.mapRect(output); 522 output = rotateTransform.mapRect(output);
524 523
525 bool hasRadius = false; 524 bool hasRadius = false;
526 CHECK_MAPPINGS( 525 CHECK_MAPPINGS(
527 input, // Input 526 input, // Input
528 output, // Visual rect 527 output, // Visual rect
529 rotateTransform.mapRect(input), // Transformed rect (not clipped). 528 rotateTransform.mapRect(input), // Transformed rect (not clipped).
530 rotateTransform, // Transform matrix to ancestor space 529 rotateTransform, // Transform matrix to ancestor space
531 FloatClipRect(rotateTransform.mapRect( 530 FloatClipRect(rotateTransform.mapRect(
532 clip->clipRect().rect())), // Clip rect in ancestor space 531 clip->clipRect().rect())), // Clip rect in ancestor space
533 localState, PropertyTreeState::root(), hasRadius); 532 localState, PropertyTreeState::root());
534 } 533 }
535 534
536 TEST_F(GeometryMapperTest, ClipAfterTransform) { 535 TEST_F(GeometryMapperTest, ClipAfterTransform) {
537 TransformationMatrix rotateTransform; 536 TransformationMatrix rotateTransform;
538 rotateTransform.rotate(45); 537 rotateTransform.rotate(45);
539 RefPtr<TransformPaintPropertyNode> transform = 538 RefPtr<TransformPaintPropertyNode> transform =
540 TransformPaintPropertyNode::create(TransformPaintPropertyNode::root(), 539 TransformPaintPropertyNode::create(TransformPaintPropertyNode::root(),
541 rotateTransform, FloatPoint3D()); 540 rotateTransform, FloatPoint3D());
542 541
543 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create( 542 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create(
544 ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(), 543 ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(),
545 FloatRoundedRect(10, 10, 200, 200)); 544 FloatRoundedRect(10, 10, 200, 200));
546 545
547 PropertyTreeState localState = PropertyTreeState::root(); 546 PropertyTreeState localState = PropertyTreeState::root();
548 localState.setClip(clip.get()); 547 localState.setClip(clip.get());
549 localState.setTransform(transform.get()); 548 localState.setTransform(transform.get());
550 549
551 FloatRect input(0, 0, 100, 100); 550 FloatRect input(0, 0, 100, 100);
552 FloatRect output(input); 551 FloatRect output(input);
553 output = rotateTransform.mapRect(output); 552 output = rotateTransform.mapRect(output);
554 output.intersect(clip->clipRect().rect()); 553 output.intersect(clip->clipRect().rect());
555 554
556 bool hasRadius = false; 555 bool hasRadius = false;
557 CHECK_MAPPINGS( 556 CHECK_MAPPINGS(
558 input, // Input 557 input, // Input
559 output, // Visual rect 558 output, // Visual rect
560 rotateTransform.mapRect(input), // Transformed rect (not clipped) 559 rotateTransform.mapRect(input), // Transformed rect (not clipped)
561 rotateTransform, // Transform matrix to ancestor space 560 rotateTransform, // Transform matrix to ancestor space
562 FloatClipRect(clip->clipRect().rect()), // Clip rect in ancestor space 561 FloatClipRect(clip->clipRect().rect()), // Clip rect in ancestor space
563 localState, PropertyTreeState::root(), hasRadius); 562 localState, PropertyTreeState::root());
564 } 563 }
565 564
566 TEST_F(GeometryMapperTest, TwoClipsWithTransformBetween) { 565 TEST_F(GeometryMapperTest, TwoClipsWithTransformBetween) {
567 RefPtr<ClipPaintPropertyNode> clip1 = ClipPaintPropertyNode::create( 566 RefPtr<ClipPaintPropertyNode> clip1 = ClipPaintPropertyNode::create(
568 ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(), 567 ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(),
569 FloatRoundedRect(10, 10, 200, 200)); 568 FloatRoundedRect(10, 10, 200, 200));
570 569
571 TransformationMatrix rotateTransform; 570 TransformationMatrix rotateTransform;
572 rotateTransform.rotate(45); 571 rotateTransform.rotate(45);
573 RefPtr<TransformPaintPropertyNode> transform = 572 RefPtr<TransformPaintPropertyNode> transform =
(...skipping 14 matching lines...) Expand all
588 FloatRect output(input); 587 FloatRect output(input);
589 output = rotateTransform.mapRect(output); 588 output = rotateTransform.mapRect(output);
590 output.intersect(clip1->clipRect().rect()); 589 output.intersect(clip1->clipRect().rect());
591 590
592 CHECK_MAPPINGS( 591 CHECK_MAPPINGS(
593 input, // Input 592 input, // Input
594 output, // Visual rect 593 output, // Visual rect
595 rotateTransform.mapRect(input), // Transformed rect (not clipped) 594 rotateTransform.mapRect(input), // Transformed rect (not clipped)
596 rotateTransform, // Transform matrix to ancestor space 595 rotateTransform, // Transform matrix to ancestor space
597 FloatClipRect(clip1->clipRect().rect()), // Clip rect in ancestor space 596 FloatClipRect(clip1->clipRect().rect()), // Clip rect in ancestor space
598 localState, PropertyTreeState::root(), hasRadius); 597 localState, PropertyTreeState::root());
599 } 598 }
600 599
601 { 600 {
602 PropertyTreeState localState = PropertyTreeState::root(); 601 PropertyTreeState localState = PropertyTreeState::root();
603 localState.setClip(clip2.get()); 602 localState.setClip(clip2.get());
604 localState.setTransform(transform.get()); 603 localState.setTransform(transform.get());
605 604
606 FloatRect mappedClip = rotateTransform.mapRect(clip2->clipRect().rect()); 605 FloatRect mappedClip = rotateTransform.mapRect(clip2->clipRect().rect());
607 mappedClip.intersect(clip1->clipRect().rect()); 606 mappedClip.intersect(clip1->clipRect().rect());
608 607
609 // All clips are performed in the space of the ancestor. In cases such as 608 // All clips are performed in the space of the ancestor. In cases such as
610 // this, this means the clip is a bit lossy. 609 // this, this means the clip is a bit lossy.
611 FloatRect output(input); 610 FloatRect output(input);
612 // Map to transformed rect in ancestor space. 611 // Map to transformed rect in ancestor space.
613 output = rotateTransform.mapRect(output); 612 output = rotateTransform.mapRect(output);
614 // Intersect with all clips between local and ancestor, independently mapped 613 // Intersect with all clips between local and ancestor, independently mapped
615 // to ancestor space. 614 // to ancestor space.
616 output.intersect(mappedClip); 615 output.intersect(mappedClip);
617 616
618 CHECK_MAPPINGS( 617 CHECK_MAPPINGS(
619 input, // Input 618 input, // Input
620 output, // Visual rect 619 output, // Visual rect
621 rotateTransform.mapRect(input), // Transformed rect (not clipped) 620 rotateTransform.mapRect(input), // Transformed rect (not clipped)
622 rotateTransform, // Transform matrix to ancestor space 621 rotateTransform, // Transform matrix to ancestor space
623 FloatClipRect(mappedClip), // Clip rect in ancestor space 622 FloatClipRect(mappedClip), // Clip rect in ancestor space
624 localState, PropertyTreeState::root(), hasRadius); 623 localState, PropertyTreeState::root());
625 } 624 }
626 } 625 }
627 626
628 TEST_F(GeometryMapperTest, SiblingTransforms) { 627 TEST_F(GeometryMapperTest, SiblingTransforms) {
629 // These transforms are siblings. Thus mapping from one to the other requires 628 // These transforms are siblings. Thus mapping from one to the other requires
630 // going through the root. 629 // going through the root.
631 TransformationMatrix rotateTransform1; 630 TransformationMatrix rotateTransform1;
632 rotateTransform1.rotate(45); 631 rotateTransform1.rotate(45);
633 RefPtr<TransformPaintPropertyNode> transform1 = 632 RefPtr<TransformPaintPropertyNode> transform1 =
634 TransformPaintPropertyNode::create(TransformPaintPropertyNode::root(), 633 TransformPaintPropertyNode::create(TransformPaintPropertyNode::root(),
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 EXPECT_EQ(FloatRect(-50, -50, 150, 150), output); 836 EXPECT_EQ(FloatRect(-50, -50, 150, 150), output);
838 // 5. transformAboveEffect 837 // 5. transformAboveEffect
839 output = transformAboveEffect->matrix().mapRect(output); 838 output = transformAboveEffect->matrix().mapRect(output);
840 EXPECT_EQ(FloatRect(-150, -150, 450, 450), output); 839 EXPECT_EQ(FloatRect(-150, -150, 450, 450), output);
841 840
842 bool hasRadius = false; 841 bool hasRadius = false;
843 TransformationMatrix combinedTransform = 842 TransformationMatrix combinedTransform =
844 transformAboveEffect->matrix() * transformBelowEffect->matrix(); 843 transformAboveEffect->matrix() * transformBelowEffect->matrix();
845 CHECK_MAPPINGS(input, output, FloatRect(0, 0, 300, 300), combinedTransform, 844 CHECK_MAPPINGS(input, output, FloatRect(0, 0, 300, 300), combinedTransform,
846 FloatClipRect(FloatRect(30, 30, 270, 270)), localState, 845 FloatClipRect(FloatRect(30, 30, 270, 270)), localState,
847 PropertyTreeState::root(), hasRadius); 846 PropertyTreeState::root());
848 } 847 }
849 848
850 TEST_F(GeometryMapperTest, ReflectionWithPaintOffset) { 849 TEST_F(GeometryMapperTest, ReflectionWithPaintOffset) {
851 CompositorFilterOperations filters; 850 CompositorFilterOperations filters;
852 filters.appendReferenceFilter(SkiaImageFilterBuilder::buildBoxReflectFilter( 851 filters.appendReferenceFilter(SkiaImageFilterBuilder::buildBoxReflectFilter(
853 BoxReflection(BoxReflection::HorizontalReflection, 0), nullptr)); 852 BoxReflection(BoxReflection::HorizontalReflection, 0), nullptr));
854 RefPtr<EffectPaintPropertyNode> effect = EffectPaintPropertyNode::create( 853 RefPtr<EffectPaintPropertyNode> effect = EffectPaintPropertyNode::create(
855 EffectPaintPropertyNode::root(), TransformPaintPropertyNode::root(), 854 EffectPaintPropertyNode::root(), TransformPaintPropertyNode::root(),
856 ClipPaintPropertyNode::root(), ColorFilterNone, filters, 1.0, 855 ClipPaintPropertyNode::root(), ColorFilterNone, filters, 1.0,
857 SkBlendMode::kSrcOver, CompositingReasonNone, CompositorElementId(), 856 SkBlendMode::kSrcOver, CompositingReasonNone, CompositorElementId(),
858 FloatPoint(100, 100)); 857 FloatPoint(100, 100));
859 858
860 PropertyTreeState localState = PropertyTreeState::root(); 859 PropertyTreeState localState = PropertyTreeState::root();
861 localState.setEffect(effect); 860 localState.setEffect(effect);
862 861
863 FloatRect input(100, 100, 50, 50); 862 FloatRect input(100, 100, 50, 50);
864 // Reflection is at (50, 100, 50, 50). 863 // Reflection is at (50, 100, 50, 50).
865 FloatRect output(50, 100, 100, 50); 864 FloatRect output(50, 100, 100, 50);
866 865
867 bool hasRadius = false; 866 bool hasRadius = false;
868 CHECK_MAPPINGS(input, output, input, TransformationMatrix(), FloatClipRect(), 867 CHECK_MAPPINGS(input, output, input, TransformationMatrix(), FloatClipRect(),
869 localState, PropertyTreeState::root(), hasRadius); 868 localState, PropertyTreeState::root());
870 } 869 }
871 870
872 } // namespace blink 871 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698