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

Side by Side Diff: tests/MatrixClipCollapseTest.cpp

Issue 153583007: Revert "Serialization of SkPictureImageFilter" (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « src/image/SkImage.cpp ('k') | tests/SurfaceTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "Test.h" 8 #include "Test.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkDebugCanvas.h" 10 #include "SkDebugCanvas.h"
11 #include "SkPicture.h" 11 #include "SkPicture.h"
12 #include "SkPictureFlat.h" 12 #include "SkPictureFlat.h"
13 #include "SkPictureRecord.h" 13 #include "SkPictureRecord.h"
14 14
15 // This test exercises the Matrix/Clip State collapsing system. It generates 15 // This test exercises the Matrix/Clip State collapsing system. It generates
16 // example skps and the compares the actual stored operations to the expected 16 // example skps and the compares the actual stored operations to the expected
17 // operations. The test works by emitting canvas operations at three levels: 17 // operations. The test works by emitting canvas operations at three levels:
18 // overall structure, bodies that draw something and model/clip state changes. 18 // overall structure, bodies that draw something and model/clip state changes.
19 // 19 //
20 // Structure methods only directly emit save and restores but call the 20 // Structure methods only directly emit save and restores but call the
21 // ModelClip and Body helper methods to fill in the structure. Since they only 21 // ModelClip and Body helper methods to fill in the structure. Since they only
22 // emit saves and restores the operations emitted by the structure methods will 22 // emit saves and restores the operations emitted by the structure methods will
23 // be completely removed by the matrix/clip collapse. Note: every save in 23 // be completely removed by the matrix/clip collapse. Note: every save in
24 // a structure method is followed by a call to a ModelClip helper. 24 // a structure method is followed by a call to a ModelClip helper.
25 // 25 //
26 // Body methods only directly emit draw ops and saveLayer/restore pairs but call 26 // Body methods only directly emit draw ops and saveLayer/restore pairs but call
27 // the ModelClip helper methods. Since the body methods emit the ops that cannot 27 // the ModelClip helper methods. Since the body methods emit the ops that cannot
28 // be collapsed (i.e., draw ops, saveLayer/restore) they also generate the 28 // be collapsed (i.e., draw ops, saveLayer/restore) they also generate the
29 // expected result information. Note: every saveLayer in a body method is 29 // expected result information. Note: every saveLayer in a body method is
30 // followed by a call to a ModelClip helper. 30 // followed by a call to a ModelClip helper.
31 // 31 //
32 // The ModelClip methods output matrix and clip ops in various orders and 32 // The ModelClip methods output matrix and clip ops in various orders and
33 // combinations. They contribute to the expected result by outputting the 33 // combinations. They contribute to the expected result by outputting the
34 // expected matrix & clip ops. Note that, currently, the entire clip stack 34 // expected matrix & clip ops. Note that, currently, the entire clip stack
35 // is output for each MC state so the clip operations accumulate down the 35 // is output for each MC state so the clip operations accumulate down the
36 // save/restore stack. 36 // save/restore stack.
37 37
38 // TODOs: 38 // TODOs:
39 // check on clip offsets 39 // check on clip offsets
40 // - not sure if this is possible. The desire is to verify that the clip 40 // - not sure if this is possible. The desire is to verify that the clip
41 // operations' offsets point to the correct follow-on operations. This 41 // operations' offsets point to the correct follow-on operations. This
42 // could be difficult since there is no good way to communicate the 42 // could be difficult since there is no good way to communicate the
43 // offset stored in the SkPicture to the debugger's clip objects 43 // offset stored in the SkPicture to the debugger's clip objects
44 // add comparison of rendered before & after images? 44 // add comparison of rendered before & after images?
45 // - not sure if this would be useful since it somewhat duplicates the 45 // - not sure if this would be useful since it somewhat duplicates the
46 // correctness test of running render_pictures in record mode and 46 // correctness test of running render_pictures in record mode and
47 // rendering before and after images. Additionally the matrix/clip collap se 47 // rendering before and after images. Additionally the matrix/clip collap se
48 // is sure to cause some small differences so an automated test might 48 // is sure to cause some small differences so an automated test might
49 // yield too many false positives. 49 // yield too many false positives.
50 // run the matrix/clip collapse system on the 10K skp set 50 // run the matrix/clip collapse system on the 10K skp set
51 // - this should give us warm fuzzies that the matrix clip collapse 51 // - this should give us warm fuzzies that the matrix clip collapse
52 // system is ready for prime time 52 // system is ready for prime time
53 // bench the recording times with/without matrix/clip collapsing 53 // bench the recording times with/without matrix/clip collapsing
54 54
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 kTextOnPath_DrawOpType, 124 kTextOnPath_DrawOpType,
125 kTextTopBottom_DrawOpType, 125 kTextTopBottom_DrawOpType,
126 kDrawVertices_DrawOpType, 126 kDrawVertices_DrawOpType,
127 #endif 127 #endif
128 128
129 kLast_DrawOpType = kRect_DrawOpType 129 kLast_DrawOpType = kRect_DrawOpType
130 }; 130 };
131 131
132 static const int kDrawOpTypeCount = kLast_DrawOpType + 1; 132 static const int kDrawOpTypeCount = kLast_DrawOpType + 1;
133 133
134 typedef void (*PFEmitMC)(SkCanvas* canvas, MatType mat, ClipType clip, 134 typedef void (*PFEmitMC)(SkCanvas* canvas, MatType mat, ClipType clip,
135 DrawOpType draw, SkTDArray<DrawType>* expected, 135 DrawOpType draw, SkTDArray<DrawType>* expected,
136 int accumulatedClips); 136 int accumulatedClips);
137 typedef void (*PFEmitBody)(SkCanvas* canvas, PFEmitMC emitMC, MatType mat, 137 typedef void (*PFEmitBody)(SkCanvas* canvas, PFEmitMC emitMC, MatType mat,
138 ClipType clip, DrawOpType draw, 138 ClipType clip, DrawOpType draw,
139 SkTDArray<DrawType>* expected, int accumulatedClips); 139 SkTDArray<DrawType>* expected, int accumulatedClips);
140 typedef void (*PFEmitStruct)(SkCanvas* canvas, PFEmitMC emitMC, MatType mat, 140 typedef void (*PFEmitStruct)(SkCanvas* canvas, PFEmitMC emitMC, MatType mat,
141 ClipType clip, PFEmitBody emitBody, DrawOpType draw , 141 ClipType clip, PFEmitBody emitBody, DrawOpType draw ,
142 SkTDArray<DrawType>* expected); 142 SkTDArray<DrawType>* expected);
143 143
144 ////////////////////////////////////////////////////////////////////////////// 144 //////////////////////////////////////////////////////////////////////////////
145 145
146 // TODO: expand the testing to include the different ops & AA types! 146 // TODO: expand the testing to include the different ops & AA types!
147 static void emit_clip(SkCanvas* canvas, ClipType clip) { 147 static void emit_clip(SkCanvas* canvas, ClipType clip) {
148 switch (clip) { 148 switch (clip) {
149 case kNone_ClipType: 149 case kNone_ClipType:
150 break; 150 break;
151 case kRect_ClipType: { 151 case kRect_ClipType: {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 } 254 }
255 255
256 switch (mat) { 256 switch (mat) {
257 case kNone_MatType: 257 case kNone_MatType:
258 break; 258 break;
259 case kTranslate_MatType: // fall thru 259 case kTranslate_MatType: // fall thru
260 case kScale_MatType: // fall thru 260 case kScale_MatType: // fall thru
261 case kSkew_MatType: // fall thru 261 case kSkew_MatType: // fall thru
262 case kRotate_MatType: // fall thru 262 case kRotate_MatType: // fall thru
263 case kConcat_MatType: // fall thru 263 case kConcat_MatType: // fall thru
264 case kSetMatrix_MatType: 264 case kSetMatrix_MatType:
265 // TODO: this system currently converts a setMatrix to concat. If we wan ted to 265 // TODO: this system currently converts a setMatrix to concat. If we wan ted to
266 // really preserve the setMatrix semantics we should keep it a setMatrix . I'm 266 // really preserve the setMatrix semantics we should keep it a setMatrix . I'm
267 // not sure if this is a good idea though since this would keep things l ike pinch 267 // not sure if this is a good idea though since this would keep things l ike pinch
268 // zoom from working. 268 // zoom from working.
269 *expected->append() = CONCAT; 269 *expected->append() = CONCAT;
270 break; 270 break;
271 default: 271 default:
272 SkASSERT(0); 272 SkASSERT(0);
273 } 273 }
274 } 274 }
275 275
276 static void emit_draw(SkCanvas* canvas, DrawOpType draw, SkTDArray<DrawType>* ex pected) { 276 static void emit_draw(SkCanvas* canvas, DrawOpType draw, SkTDArray<DrawType>* ex pected) {
277 switch (draw) { 277 switch (draw) {
278 case kNone_DrawOpType: 278 case kNone_DrawOpType:
279 break; 279 break;
280 case kClear_DrawOpType: 280 case kClear_DrawOpType:
281 canvas->clear(SK_ColorRED); 281 canvas->clear(SK_ColorRED);
282 *expected->append() = DRAW_CLEAR; 282 *expected->append() = DRAW_CLEAR;
283 break; 283 break;
284 case kOval_DrawOpType: { 284 case kOval_DrawOpType: {
(...skipping 23 matching lines...) Expand all
308 SkASSERT(0); 308 SkASSERT(0);
309 } 309 }
310 } 310 }
311 311
312 ////////////////////////////////////////////////////////////////////////////// 312 //////////////////////////////////////////////////////////////////////////////
313 313
314 // Emit: 314 // Emit:
315 // clip 315 // clip
316 // matrix 316 // matrix
317 // Simple case - the clip isn't effect by the matrix 317 // Simple case - the clip isn't effect by the matrix
318 static void emit_clip_and_mat(SkCanvas* canvas, MatType mat, ClipType clip, 318 static void emit_clip_and_mat(SkCanvas* canvas, MatType mat, ClipType clip,
319 DrawOpType draw, SkTDArray<DrawType>* expected, 319 DrawOpType draw, SkTDArray<DrawType>* expected,
320 int accumulatedClips) { 320 int accumulatedClips) {
321 if (kNone_DrawOpType == draw) { 321 if (kNone_DrawOpType == draw) {
322 return; 322 return;
323 } 323 }
324 324
325 emit_clip(canvas, clip); 325 emit_clip(canvas, clip);
326 emit_mat(canvas, mat); 326 emit_mat(canvas, mat);
327 327
328 for (int i = 0; i < accumulatedClips; ++i) { 328 for (int i = 0; i < accumulatedClips; ++i) {
329 add_clip(clip, mat, expected); 329 add_clip(clip, mat, expected);
330 } 330 }
331 add_mat(mat, expected); 331 add_mat(mat, expected);
332 } 332 }
333 333
334 // Emit: 334 // Emit:
335 // matrix 335 // matrix
336 // clip 336 // clip
337 // Emitting the matrix first is more challenging since the matrix has to be 337 // Emitting the matrix first is more challenging since the matrix has to be
338 // pushed across (i.e., applied to) the clip. 338 // pushed across (i.e., applied to) the clip.
339 static void emit_mat_and_clip(SkCanvas* canvas, MatType mat, ClipType clip, 339 static void emit_mat_and_clip(SkCanvas* canvas, MatType mat, ClipType clip,
340 DrawOpType draw, SkTDArray<DrawType>* expected, 340 DrawOpType draw, SkTDArray<DrawType>* expected,
341 int accumulatedClips) { 341 int accumulatedClips) {
342 if (kNone_DrawOpType == draw) { 342 if (kNone_DrawOpType == draw) {
343 return; 343 return;
344 } 344 }
345 345
346 emit_mat(canvas, mat); 346 emit_mat(canvas, mat);
347 emit_clip(canvas, clip); 347 emit_clip(canvas, clip);
348 348
349 // the matrix & clip order will be reversed once collapsed! 349 // the matrix & clip order will be reversed once collapsed!
350 for (int i = 0; i < accumulatedClips; ++i) { 350 for (int i = 0; i < accumulatedClips; ++i) {
351 add_clip(clip, mat, expected); 351 add_clip(clip, mat, expected);
352 } 352 }
353 add_mat(mat, expected); 353 add_mat(mat, expected);
354 } 354 }
355 355
356 // Emit: 356 // Emit:
357 // matrix 357 // matrix
358 // clip 358 // clip
359 // matrix 359 // matrix
360 // clip 360 // clip
361 // This tests that the matrices and clips coalesce when collapsed 361 // This tests that the matrices and clips coalesce when collapsed
362 static void emit_double_mat_and_clip(SkCanvas* canvas, MatType mat, ClipType cli p, 362 static void emit_double_mat_and_clip(SkCanvas* canvas, MatType mat, ClipType cli p,
363 DrawOpType draw, SkTDArray<DrawType>* expec ted, 363 DrawOpType draw, SkTDArray<DrawType>* expec ted,
364 int accumulatedClips) { 364 int accumulatedClips) {
365 if (kNone_DrawOpType == draw) { 365 if (kNone_DrawOpType == draw) {
366 return; 366 return;
367 } 367 }
368 368
369 emit_mat(canvas, mat); 369 emit_mat(canvas, mat);
370 emit_clip(canvas, clip); 370 emit_clip(canvas, clip);
371 emit_mat(canvas, mat); 371 emit_mat(canvas, mat);
372 emit_clip(canvas, clip); 372 emit_clip(canvas, clip);
373 373
374 for (int i = 0; i < accumulatedClips; ++i) { 374 for (int i = 0; i < accumulatedClips; ++i) {
375 add_clip(clip, mat, expected); 375 add_clip(clip, mat, expected);
376 add_clip(clip, mat, expected); 376 add_clip(clip, mat, expected);
377 } 377 }
378 add_mat(mat, expected); 378 add_mat(mat, expected);
379 } 379 }
380 380
381 // Emit: 381 // Emit:
382 // matrix 382 // matrix
383 // clip 383 // clip
384 // clip 384 // clip
385 // This tests accumulation of clips in same transform state. It also tests pushi ng 385 // This tests accumulation of clips in same transform state. It also tests pushi ng
386 // of the matrix across both the clips. 386 // of the matrix across both the clips.
387 static void emit_mat_clip_clip(SkCanvas* canvas, MatType mat, ClipType clip, 387 static void emit_mat_clip_clip(SkCanvas* canvas, MatType mat, ClipType clip,
388 DrawOpType draw, SkTDArray<DrawType>* expected, 388 DrawOpType draw, SkTDArray<DrawType>* expected,
389 int accumulatedClips) { 389 int accumulatedClips) {
390 if (kNone_DrawOpType == draw) { 390 if (kNone_DrawOpType == draw) {
391 return; 391 return;
392 } 392 }
393 393
394 emit_mat(canvas, mat); 394 emit_mat(canvas, mat);
395 emit_clip(canvas, clip); 395 emit_clip(canvas, clip);
396 emit_clip(canvas, clip); 396 emit_clip(canvas, clip);
397 397
398 for (int i = 0; i < accumulatedClips; ++i) { 398 for (int i = 0; i < accumulatedClips; ++i) {
399 add_clip(clip, mat, expected); 399 add_clip(clip, mat, expected);
400 add_clip(clip, mat, expected); 400 add_clip(clip, mat, expected);
401 } 401 }
402 add_mat(mat, expected); 402 add_mat(mat, expected);
403 } 403 }
404 404
405 ////////////////////////////////////////////////////////////////////////////// 405 //////////////////////////////////////////////////////////////////////////////
406 406
407 // Emit: 407 // Emit:
408 // matrix & clip calls 408 // matrix & clip calls
409 // draw op 409 // draw op
410 static void emit_body0(SkCanvas* canvas, PFEmitMC emitMC, MatType mat, 410 static void emit_body0(SkCanvas* canvas, PFEmitMC emitMC, MatType mat,
411 ClipType clip, DrawOpType draw, 411 ClipType clip, DrawOpType draw,
412 SkTDArray<DrawType>* expected, int accumulatedClips) { 412 SkTDArray<DrawType>* expected, int accumulatedClips) {
413 bool needsSaveRestore = kNone_DrawOpType != draw && 413 bool needsSaveRestore = kNone_DrawOpType != draw &&
414 (kNone_MatType != mat || kNone_ClipType != clip); 414 (kNone_MatType != mat || kNone_ClipType != clip);
415 415
416 if (needsSaveRestore) { 416 if (needsSaveRestore) {
417 *expected->append() = SAVE; 417 *expected->append() = SAVE;
418 } 418 }
419 (*emitMC)(canvas, mat, clip, draw, expected, accumulatedClips+1); 419 (*emitMC)(canvas, mat, clip, draw, expected, accumulatedClips+1);
420 emit_draw(canvas, draw, expected); 420 emit_draw(canvas, draw, expected);
421 if (needsSaveRestore) { 421 if (needsSaveRestore) {
422 *expected->append() = RESTORE; 422 *expected->append() = RESTORE;
423 } 423 }
424 } 424 }
425 425
426 // Emit: 426 // Emit:
427 // matrix & clip calls 427 // matrix & clip calls
428 // draw op 428 // draw op
429 // matrix & clip calls 429 // matrix & clip calls
430 // draw op 430 // draw op
431 static void emit_body1(SkCanvas* canvas, PFEmitMC emitMC, MatType mat, 431 static void emit_body1(SkCanvas* canvas, PFEmitMC emitMC, MatType mat,
432 ClipType clip, DrawOpType draw, 432 ClipType clip, DrawOpType draw,
433 SkTDArray<DrawType>* expected, int accumulatedClips) { 433 SkTDArray<DrawType>* expected, int accumulatedClips) {
434 bool needsSaveRestore = kNone_DrawOpType != draw && 434 bool needsSaveRestore = kNone_DrawOpType != draw &&
435 (kNone_MatType != mat || kNone_ClipType != clip); 435 (kNone_MatType != mat || kNone_ClipType != clip);
436 436
437 if (needsSaveRestore) { 437 if (needsSaveRestore) {
438 *expected->append() = SAVE; 438 *expected->append() = SAVE;
439 } 439 }
440 (*emitMC)(canvas, mat, clip, draw, expected, accumulatedClips+1); 440 (*emitMC)(canvas, mat, clip, draw, expected, accumulatedClips+1);
441 emit_draw(canvas, draw, expected); 441 emit_draw(canvas, draw, expected);
442 if (needsSaveRestore) { 442 if (needsSaveRestore) {
443 *expected->append() = RESTORE; 443 *expected->append() = RESTORE;
444 *expected->append() = SAVE; 444 *expected->append() = SAVE;
445 } 445 }
446 (*emitMC)(canvas, mat, clip, draw, expected, accumulatedClips+2); 446 (*emitMC)(canvas, mat, clip, draw, expected, accumulatedClips+2);
447 emit_draw(canvas, draw, expected); 447 emit_draw(canvas, draw, expected);
448 if (needsSaveRestore) { 448 if (needsSaveRestore) {
449 *expected->append() = RESTORE; 449 *expected->append() = RESTORE;
450 } 450 }
451 } 451 }
452 452
453 // Emit: 453 // Emit:
454 // matrix & clip calls 454 // matrix & clip calls
455 // SaveLayer 455 // SaveLayer
456 // matrix & clip calls 456 // matrix & clip calls
457 // draw op 457 // draw op
458 // Restore 458 // Restore
459 static void emit_body2(SkCanvas* canvas, PFEmitMC emitMC, MatType mat, 459 static void emit_body2(SkCanvas* canvas, PFEmitMC emitMC, MatType mat,
460 ClipType clip, DrawOpType draw, 460 ClipType clip, DrawOpType draw,
461 SkTDArray<DrawType>* expected, int accumulatedClips) { 461 SkTDArray<DrawType>* expected, int accumulatedClips) {
462 bool needsSaveRestore = kNone_DrawOpType != draw && 462 bool needsSaveRestore = kNone_DrawOpType != draw &&
463 (kNone_MatType != mat || kNone_ClipType != clip); 463 (kNone_MatType != mat || kNone_ClipType != clip);
464 464
465 if (needsSaveRestore) { 465 if (needsSaveRestore) {
466 *expected->append() = SAVE_LAYER; 466 *expected->append() = SAVE_LAYER;
467 } 467 }
468 (*emitMC)(canvas, mat, clip, draw, NULL, 0); // these get fused into later o ps 468 (*emitMC)(canvas, mat, clip, draw, NULL, 0); // these get fused into later o ps
469 // TODO: widen testing to exercise saveLayer's parameters 469 // TODO: widen testing to exercise saveLayer's parameters
470 canvas->saveLayer(NULL, NULL); 470 canvas->saveLayer(NULL, NULL);
471 if (needsSaveRestore) { 471 if (needsSaveRestore) {
472 *expected->append() = SAVE; 472 *expected->append() = SAVE;
(...skipping 12 matching lines...) Expand all
485 // Emit: 485 // Emit:
486 // matrix & clip calls 486 // matrix & clip calls
487 // SaveLayer 487 // SaveLayer
488 // matrix & clip calls 488 // matrix & clip calls
489 // SaveLayer 489 // SaveLayer
490 // matrix & clip calls 490 // matrix & clip calls
491 // draw op 491 // draw op
492 // Restore 492 // Restore
493 // matrix & clip calls (will be ignored) 493 // matrix & clip calls (will be ignored)
494 // Restore 494 // Restore
495 static void emit_body3(SkCanvas* canvas, PFEmitMC emitMC, MatType mat, 495 static void emit_body3(SkCanvas* canvas, PFEmitMC emitMC, MatType mat,
496 ClipType clip, DrawOpType draw, 496 ClipType clip, DrawOpType draw,
497 SkTDArray<DrawType>* expected, int accumulatedClips) { 497 SkTDArray<DrawType>* expected, int accumulatedClips) {
498 bool needsSaveRestore = kNone_DrawOpType != draw && 498 bool needsSaveRestore = kNone_DrawOpType != draw &&
499 (kNone_MatType != mat || kNone_ClipType != clip); 499 (kNone_MatType != mat || kNone_ClipType != clip);
500 500
501 // This saveLayer will always be forced b.c. we currently can't tell 501 // This saveLayer will always be forced b.c. we currently can't tell
502 // ahead of time if it will be empty (see comment in SkMatrixClipStateMgr::s ave) 502 // ahead of time if it will be empty (see comment in SkMatrixClipStateMgr::s ave)
503 *expected->append() = SAVE_LAYER; 503 *expected->append() = SAVE_LAYER;
504 504
505 (*emitMC)(canvas, mat, clip, draw, NULL, 0); // these get fused into later o ps 505 (*emitMC)(canvas, mat, clip, draw, NULL, 0); // these get fused into later o ps
506 // TODO: widen testing to exercise saveLayer's parameters 506 // TODO: widen testing to exercise saveLayer's parameters
507 canvas->saveLayer(NULL, NULL); 507 canvas->saveLayer(NULL, NULL);
508 (*emitMC)(canvas, mat, clip, draw, NULL, 0); // these get fused into lat er ops 508 (*emitMC)(canvas, mat, clip, draw, NULL, 0); // these get fused into lat er ops
509 if (needsSaveRestore) { 509 if (needsSaveRestore) {
510 *expected->append() = SAVE_LAYER; 510 *expected->append() = SAVE_LAYER;
511 } 511 }
(...skipping 17 matching lines...) Expand all
529 *expected->append() = RESTORE; 529 *expected->append() = RESTORE;
530 } 530 }
531 531
532 ////////////////////////////////////////////////////////////////////////////// 532 //////////////////////////////////////////////////////////////////////////////
533 533
534 // Emit: 534 // Emit:
535 // Save 535 // Save
536 // some body 536 // some body
537 // Restore 537 // Restore
538 // Note: the outer save/restore are provided by beginRecording/endRecording 538 // Note: the outer save/restore are provided by beginRecording/endRecording
539 static void emit_struct0(SkCanvas* canvas, 539 static void emit_struct0(SkCanvas* canvas,
540 PFEmitMC emitMC, MatType mat, ClipType clip, 540 PFEmitMC emitMC, MatType mat, ClipType clip,
541 PFEmitBody emitBody, DrawOpType draw, 541 PFEmitBody emitBody, DrawOpType draw,
542 SkTDArray<DrawType>* expected) { 542 SkTDArray<DrawType>* expected) {
543 (*emitBody)(canvas, emitMC, mat, clip, draw, expected, 0); 543 (*emitBody)(canvas, emitMC, mat, clip, draw, expected, 0);
544 } 544 }
545 545
546 // Emit: 546 // Emit:
547 // Save 547 // Save
548 // matrix & clip calls 548 // matrix & clip calls
549 // Save 549 // Save
550 // some body 550 // some body
551 // Restore 551 // Restore
552 // matrix & clip calls (will be ignored) 552 // matrix & clip calls (will be ignored)
553 // Restore 553 // Restore
554 // Note: the outer save/restore are provided by beginRecording/endRecording 554 // Note: the outer save/restore are provided by beginRecording/endRecording
555 static void emit_struct1(SkCanvas* canvas, 555 static void emit_struct1(SkCanvas* canvas,
556 PFEmitMC emitMC, MatType mat, ClipType clip, 556 PFEmitMC emitMC, MatType mat, ClipType clip,
557 PFEmitBody emitBody, DrawOpType draw, 557 PFEmitBody emitBody, DrawOpType draw,
558 SkTDArray<DrawType>* expected) { 558 SkTDArray<DrawType>* expected) {
559 (*emitMC)(canvas, mat, clip, draw, NULL, 0); // these get fused into later o ps 559 (*emitMC)(canvas, mat, clip, draw, NULL, 0); // these get fused into later o ps
560 canvas->save(); 560 canvas->save();
561 (*emitBody)(canvas, emitMC, mat, clip, draw, expected, 1); 561 (*emitBody)(canvas, emitMC, mat, clip, draw, expected, 1);
562 canvas->restore(); 562 canvas->restore();
563 (*emitMC)(canvas, mat, clip, draw, NULL, 0); // these will get removed 563 (*emitMC)(canvas, mat, clip, draw, NULL, 0); // these will get removed
564 } 564 }
565 565
566 // Emit: 566 // Emit:
567 // Save 567 // Save
568 // matrix & clip calls 568 // matrix & clip calls
569 // Save 569 // Save
570 // some body 570 // some body
571 // Restore 571 // Restore
572 // Save 572 // Save
573 // some body 573 // some body
574 // Restore 574 // Restore
575 // matrix & clip calls (will be ignored) 575 // matrix & clip calls (will be ignored)
576 // Restore 576 // Restore
577 // Note: the outer save/restore are provided by beginRecording/endRecording 577 // Note: the outer save/restore are provided by beginRecording/endRecording
578 static void emit_struct2(SkCanvas* canvas, 578 static void emit_struct2(SkCanvas* canvas,
579 PFEmitMC emitMC, MatType mat, ClipType clip, 579 PFEmitMC emitMC, MatType mat, ClipType clip,
580 PFEmitBody emitBody, DrawOpType draw, 580 PFEmitBody emitBody, DrawOpType draw,
581 SkTDArray<DrawType>* expected) { 581 SkTDArray<DrawType>* expected) {
582 (*emitMC)(canvas, mat, clip, draw, NULL, 1); // these will get fused into la ter ops 582 (*emitMC)(canvas, mat, clip, draw, NULL, 1); // these will get fused into la ter ops
583 canvas->save(); 583 canvas->save();
584 (*emitBody)(canvas, emitMC, mat, clip, draw, expected, 1); 584 (*emitBody)(canvas, emitMC, mat, clip, draw, expected, 1);
585 canvas->restore(); 585 canvas->restore();
586 canvas->save(); 586 canvas->save();
587 (*emitBody)(canvas, emitMC, mat, clip, draw, expected, 1); 587 (*emitBody)(canvas, emitMC, mat, clip, draw, expected, 1);
588 canvas->restore(); 588 canvas->restore();
589 (*emitMC)(canvas, mat, clip, draw, NULL, 1); // these will get removed 589 (*emitMC)(canvas, mat, clip, draw, NULL, 1); // these will get removed
590 } 590 }
591 591
592 // Emit: 592 // Emit:
593 // Save 593 // Save
594 // matrix & clip calls 594 // matrix & clip calls
595 // Save 595 // Save
596 // some body 596 // some body
597 // Restore 597 // Restore
598 // Save 598 // Save
599 // matrix & clip calls 599 // matrix & clip calls
600 // Save 600 // Save
601 // some body 601 // some body
602 // Restore 602 // Restore
603 // Restore 603 // Restore
604 // matrix & clip calls (will be ignored) 604 // matrix & clip calls (will be ignored)
605 // Restore 605 // Restore
606 // Note: the outer save/restore are provided by beginRecording/endRecording 606 // Note: the outer save/restore are provided by beginRecording/endRecording
607 static void emit_struct3(SkCanvas* canvas, 607 static void emit_struct3(SkCanvas* canvas,
608 PFEmitMC emitMC, MatType mat, ClipType clip, 608 PFEmitMC emitMC, MatType mat, ClipType clip,
609 PFEmitBody emitBody, DrawOpType draw, 609 PFEmitBody emitBody, DrawOpType draw,
610 SkTDArray<DrawType>* expected) { 610 SkTDArray<DrawType>* expected) {
611 (*emitMC)(canvas, mat, clip, draw, NULL, 0); // these will get fused into la ter ops 611 (*emitMC)(canvas, mat, clip, draw, NULL, 0); // these will get fused into la ter ops
612 canvas->save(); 612 canvas->save();
613 (*emitBody)(canvas, emitMC, mat, clip, draw, expected, 1); 613 (*emitBody)(canvas, emitMC, mat, clip, draw, expected, 1);
614 canvas->restore(); 614 canvas->restore();
615 canvas->save(); 615 canvas->save();
616 (*emitMC)(canvas, mat, clip, draw, NULL, 1); // these will get fused int o later ops 616 (*emitMC)(canvas, mat, clip, draw, NULL, 1); // these will get fused int o later ops
617 canvas->save(); 617 canvas->save();
(...skipping 24 matching lines...) Expand all
642 } 642 }
643 } 643 }
644 SkDebugf("\n\n"); 644 SkDebugf("\n\n");
645 SkASSERT(0); 645 SkASSERT(0);
646 } 646 }
647 #endif 647 #endif
648 648
649 static void test_collapse(skiatest::Reporter* reporter) { 649 static void test_collapse(skiatest::Reporter* reporter) {
650 PFEmitStruct gStructure[] = { emit_struct0, emit_struct1, emit_struct2, emit _struct3 }; 650 PFEmitStruct gStructure[] = { emit_struct0, emit_struct1, emit_struct2, emit _struct3 };
651 PFEmitBody gBody[] = { emit_body0, emit_body1, emit_body2, emit_body3 }; 651 PFEmitBody gBody[] = { emit_body0, emit_body1, emit_body2, emit_body3 };
652 PFEmitMC gMCs[] = { emit_clip_and_mat, emit_mat_and_clip, 652 PFEmitMC gMCs[] = { emit_clip_and_mat, emit_mat_and_clip,
653 emit_double_mat_and_clip, emit_mat_clip_clip }; 653 emit_double_mat_and_clip, emit_mat_clip_clip };
654 654
655 for (size_t i = 0; i < SK_ARRAY_COUNT(gStructure); ++i) { 655 for (size_t i = 0; i < SK_ARRAY_COUNT(gStructure); ++i) {
656 for (size_t j = 0; j < SK_ARRAY_COUNT(gBody); ++j) { 656 for (size_t j = 0; j < SK_ARRAY_COUNT(gBody); ++j) {
657 for (size_t k = 0; k < SK_ARRAY_COUNT(gMCs); ++k) { 657 for (size_t k = 0; k < SK_ARRAY_COUNT(gMCs); ++k) {
658 for (int l = 0; l < kMatTypeCount; ++l) { 658 for (int l = 0; l < kMatTypeCount; ++l) {
659 for (int m = 0; m < kClipTypeCount; ++m) { 659 for (int m = 0; m < kClipTypeCount; ++m) {
660 for (int n = 0; n < kDrawOpTypeCount; ++n) { 660 for (int n = 0; n < kDrawOpTypeCount; ++n) {
661 #ifdef COLLAPSE_MATRIX_CLIP_STATE 661 #ifdef COLLAPSE_MATRIX_CLIP_STATE
662 static int testID = -1; 662 static int testID = -1;
663 ++testID; 663 ++testID;
664 if (testID < -1) { 664 if (testID < -1) {
665 continue; 665 continue;
666 } 666 }
667 #endif 667 #endif
668 668
669 SkTDArray<DrawType> expected, actual; 669 SkTDArray<DrawType> expected, actual;
670 670
671 SkPicture picture; 671 SkPicture picture;
672 672
673 // Note: beginRecording/endRecording add a save/rest ore pair 673 // Note: beginRecording/endRecording add a save/rest ore pair
674 SkCanvas* canvas = picture.beginRecording(100, 100); 674 SkCanvas* canvas = picture.beginRecording(100, 100);
675 (*gStructure[i])(canvas, 675 (*gStructure[i])(canvas,
676 gMCs[k], 676 gMCs[k],
677 (MatType) l, 677 (MatType) l,
678 (ClipType) m, 678 (ClipType) m,
679 gBody[j], 679 gBody[j],
680 (DrawOpType) n, 680 (DrawOpType) n,
681 &expected); 681 &expected);
682 picture.endRecording(); 682 picture.endRecording();
683 683
684 gets_ops(picture, &actual); 684 gets_ops(picture, &actual);
685 685
686 REPORTER_ASSERT(reporter, expected.count() == actual .count()); 686 REPORTER_ASSERT(reporter, expected.count() == actual .count());
687 687
688 if (expected.count() != actual.count()) { 688 if (expected.count() != actual.count()) {
689 #ifdef COLLAPSE_MATRIX_CLIP_STATE 689 #ifdef COLLAPSE_MATRIX_CLIP_STATE
690 print(expected, actual); 690 print(expected, actual);
(...skipping 16 matching lines...) Expand all
707 } 707 }
708 } 708 }
709 } 709 }
710 } 710 }
711 711
712 DEF_TEST(MatrixClipCollapse, reporter) { 712 DEF_TEST(MatrixClipCollapse, reporter) {
713 test_collapse(reporter); 713 test_collapse(reporter);
714 } 714 }
715 715
716 #endif 716 #endif
OLDNEW
« no previous file with comments | « src/image/SkImage.cpp ('k') | tests/SurfaceTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698