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

Side by Side Diff: tests/MatrixClipCollapseTest.cpp

Issue 164823003: Improve saveLayer handling in SkMatrixClipStateMgr (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Fix another compiler issue 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/core/SkPictureRecord.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 /* 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"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 kRect_DrawOpType, 122 kRect_DrawOpType,
123 kRRect_DrawOpType, 123 kRRect_DrawOpType,
124 #if 0 124 #if 0
125 kSprite_DrawOpType, 125 kSprite_DrawOpType,
126 kText_DrawOpType, 126 kText_DrawOpType,
127 kTextOnPath_DrawOpType, 127 kTextOnPath_DrawOpType,
128 kTextTopBottom_DrawOpType, 128 kTextTopBottom_DrawOpType,
129 kDrawVertices_DrawOpType, 129 kDrawVertices_DrawOpType,
130 #endif 130 #endif
131 131
132 kLast_DrawOpType = kRect_DrawOpType 132 kLastNonSaveLayer_DrawOpType = kRect_DrawOpType,
133
134 // saveLayer's have to handled apart from the other draw operations
135 // since they also alter the save/restore structure.
136 kSaveLayer_DrawOpType,
133 }; 137 };
134 138
135 static const int kDrawOpTypeCount = kLast_DrawOpType + 1; 139 static const int kNonSaveLayerDrawOpTypeCount = kLastNonSaveLayer_DrawOpType + 1 ;
136 140
137 typedef void (*PFEmitMC)(SkCanvas* canvas, MatType mat, ClipType clip, 141 typedef void (*PFEmitMC)(SkCanvas* canvas, MatType mat, ClipType clip,
138 DrawOpType draw, SkTDArray<DrawType>* expected, 142 DrawOpType draw, SkTDArray<DrawType>* expected,
139 int accumulatedClips); 143 int accumulatedClips);
140 typedef void (*PFEmitBody)(SkCanvas* canvas, PFEmitMC emitMC, MatType mat, 144 typedef void (*PFEmitBody)(SkCanvas* canvas, PFEmitMC emitMC, MatType mat,
141 ClipType clip, DrawOpType draw, 145 ClipType clip, DrawOpType draw,
142 SkTDArray<DrawType>* expected, int accumulatedClips); 146 SkTDArray<DrawType>* expected, int accumulatedClips);
143 typedef void (*PFEmitStruct)(SkCanvas* canvas, PFEmitMC emitMC, MatType mat, 147 typedef void (*PFEmitStruct)(SkCanvas* canvas, PFEmitMC emitMC, MatType mat,
144 ClipType clip, PFEmitBody emitBody, DrawOpType draw , 148 ClipType clip, PFEmitBody emitBody, DrawOpType draw ,
145 SkTDArray<DrawType>* expected); 149 SkTDArray<DrawType>* expected);
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 318
315 ////////////////////////////////////////////////////////////////////////////// 319 //////////////////////////////////////////////////////////////////////////////
316 320
317 // Emit: 321 // Emit:
318 // clip 322 // clip
319 // matrix 323 // matrix
320 // Simple case - the clip isn't effect by the matrix 324 // Simple case - the clip isn't effect by the matrix
321 static void emit_clip_and_mat(SkCanvas* canvas, MatType mat, ClipType clip, 325 static void emit_clip_and_mat(SkCanvas* canvas, MatType mat, ClipType clip,
322 DrawOpType draw, SkTDArray<DrawType>* expected, 326 DrawOpType draw, SkTDArray<DrawType>* expected,
323 int accumulatedClips) { 327 int accumulatedClips) {
328 emit_clip(canvas, clip);
329 emit_mat(canvas, mat);
330
324 if (kNone_DrawOpType == draw) { 331 if (kNone_DrawOpType == draw) {
325 return; 332 return;
326 } 333 }
327 334
328 emit_clip(canvas, clip);
329 emit_mat(canvas, mat);
330
331 for (int i = 0; i < accumulatedClips; ++i) { 335 for (int i = 0; i < accumulatedClips; ++i) {
332 add_clip(clip, mat, expected); 336 add_clip(clip, mat, expected);
333 } 337 }
334 add_mat(mat, expected); 338 add_mat(mat, expected);
335 } 339 }
336 340
337 // Emit: 341 // Emit:
338 // matrix 342 // matrix
339 // clip 343 // clip
340 // Emitting the matrix first is more challenging since the matrix has to be 344 // Emitting the matrix first is more challenging since the matrix has to be
341 // pushed across (i.e., applied to) the clip. 345 // pushed across (i.e., applied to) the clip.
342 static void emit_mat_and_clip(SkCanvas* canvas, MatType mat, ClipType clip, 346 static void emit_mat_and_clip(SkCanvas* canvas, MatType mat, ClipType clip,
343 DrawOpType draw, SkTDArray<DrawType>* expected, 347 DrawOpType draw, SkTDArray<DrawType>* expected,
344 int accumulatedClips) { 348 int accumulatedClips) {
349 emit_mat(canvas, mat);
350 emit_clip(canvas, clip);
351
345 if (kNone_DrawOpType == draw) { 352 if (kNone_DrawOpType == draw) {
346 return; 353 return;
347 } 354 }
348 355
349 emit_mat(canvas, mat);
350 emit_clip(canvas, clip);
351
352 // the matrix & clip order will be reversed once collapsed! 356 // the matrix & clip order will be reversed once collapsed!
353 for (int i = 0; i < accumulatedClips; ++i) { 357 for (int i = 0; i < accumulatedClips; ++i) {
354 add_clip(clip, mat, expected); 358 add_clip(clip, mat, expected);
355 } 359 }
356 add_mat(mat, expected); 360 add_mat(mat, expected);
357 } 361 }
358 362
359 // Emit: 363 // Emit:
360 // matrix 364 // matrix
361 // clip 365 // clip
362 // matrix 366 // matrix
363 // clip 367 // clip
364 // This tests that the matrices and clips coalesce when collapsed 368 // This tests that the matrices and clips coalesce when collapsed
365 static void emit_double_mat_and_clip(SkCanvas* canvas, MatType mat, ClipType cli p, 369 static void emit_double_mat_and_clip(SkCanvas* canvas, MatType mat, ClipType cli p,
366 DrawOpType draw, SkTDArray<DrawType>* expec ted, 370 DrawOpType draw, SkTDArray<DrawType>* expec ted,
367 int accumulatedClips) { 371 int accumulatedClips) {
368 if (kNone_DrawOpType == draw) {
369 return;
370 }
371
372 emit_mat(canvas, mat); 372 emit_mat(canvas, mat);
373 emit_clip(canvas, clip); 373 emit_clip(canvas, clip);
374 emit_mat(canvas, mat); 374 emit_mat(canvas, mat);
375 emit_clip(canvas, clip); 375 emit_clip(canvas, clip);
376 376
377 if (kNone_DrawOpType == draw) {
378 return;
379 }
380
377 for (int i = 0; i < accumulatedClips; ++i) { 381 for (int i = 0; i < accumulatedClips; ++i) {
378 add_clip(clip, mat, expected); 382 add_clip(clip, mat, expected);
379 add_clip(clip, mat, expected); 383 add_clip(clip, mat, expected);
380 } 384 }
381 add_mat(mat, expected); 385 add_mat(mat, expected);
382 } 386 }
383 387
384 // Emit: 388 // Emit:
385 // matrix 389 // matrix
386 // clip 390 // clip
387 // clip 391 // clip
388 // This tests accumulation of clips in same transform state. It also tests pushi ng 392 // This tests accumulation of clips in same transform state. It also tests pushi ng
389 // of the matrix across both the clips. 393 // of the matrix across both the clips.
390 static void emit_mat_clip_clip(SkCanvas* canvas, MatType mat, ClipType clip, 394 static void emit_mat_clip_clip(SkCanvas* canvas, MatType mat, ClipType clip,
391 DrawOpType draw, SkTDArray<DrawType>* expected, 395 DrawOpType draw, SkTDArray<DrawType>* expected,
392 int accumulatedClips) { 396 int accumulatedClips) {
397 emit_mat(canvas, mat);
398 emit_clip(canvas, clip);
399 emit_clip(canvas, clip);
400
393 if (kNone_DrawOpType == draw) { 401 if (kNone_DrawOpType == draw) {
394 return; 402 return;
395 } 403 }
396 404
397 emit_mat(canvas, mat);
398 emit_clip(canvas, clip);
399 emit_clip(canvas, clip);
400
401 for (int i = 0; i < accumulatedClips; ++i) { 405 for (int i = 0; i < accumulatedClips; ++i) {
402 add_clip(clip, mat, expected); 406 add_clip(clip, mat, expected);
403 add_clip(clip, mat, expected); 407 add_clip(clip, mat, expected);
404 } 408 }
405 add_mat(mat, expected); 409 add_mat(mat, expected);
406 } 410 }
407 411
408 ////////////////////////////////////////////////////////////////////////////// 412 //////////////////////////////////////////////////////////////////////////////
409 413
410 // Emit: 414 // Emit:
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 // SaveLayer 462 // SaveLayer
459 // matrix & clip calls 463 // matrix & clip calls
460 // draw op 464 // draw op
461 // Restore 465 // Restore
462 static void emit_body2(SkCanvas* canvas, PFEmitMC emitMC, MatType mat, 466 static void emit_body2(SkCanvas* canvas, PFEmitMC emitMC, MatType mat,
463 ClipType clip, DrawOpType draw, 467 ClipType clip, DrawOpType draw,
464 SkTDArray<DrawType>* expected, int accumulatedClips) { 468 SkTDArray<DrawType>* expected, int accumulatedClips) {
465 bool needsSaveRestore = kNone_DrawOpType != draw && 469 bool needsSaveRestore = kNone_DrawOpType != draw &&
466 (kNone_MatType != mat || kNone_ClipType != clip); 470 (kNone_MatType != mat || kNone_ClipType != clip);
467 471
468 if (needsSaveRestore) { 472 if (kNone_MatType != mat || kNone_ClipType != clip) {
469 *expected->append() = SAVE_LAYER; 473 *expected->append() = SAVE;
470 } 474 }
471 (*emitMC)(canvas, mat, clip, draw, NULL, 0); // these get fused into later o ps 475 (*emitMC)(canvas, mat, clip, kSaveLayer_DrawOpType, expected, accumulatedCli ps+1);
476 *expected->append() = SAVE_LAYER;
472 // TODO: widen testing to exercise saveLayer's parameters 477 // TODO: widen testing to exercise saveLayer's parameters
473 canvas->saveLayer(NULL, NULL); 478 canvas->saveLayer(NULL, NULL);
474 if (needsSaveRestore) { 479 if (needsSaveRestore) {
475 *expected->append() = SAVE; 480 *expected->append() = SAVE;
476 } 481 }
477 (*emitMC)(canvas, mat, clip, draw, expected, accumulatedClips+2); 482 (*emitMC)(canvas, mat, clip, draw, expected, 1);
478 emit_draw(canvas, draw, expected); 483 emit_draw(canvas, draw, expected);
479 if (needsSaveRestore) { 484 if (needsSaveRestore) {
480 *expected->append() = RESTORE; 485 *expected->append() = RESTORE;
481 } 486 }
482 canvas->restore(); 487 canvas->restore();
483 if (needsSaveRestore) { 488 *expected->append() = RESTORE;
489 if (kNone_MatType != mat || kNone_ClipType != clip) {
484 *expected->append() = RESTORE; 490 *expected->append() = RESTORE;
485 } 491 }
486 } 492 }
487 493
488 // Emit: 494 // Emit:
489 // matrix & clip calls 495 // matrix & clip calls
490 // SaveLayer 496 // SaveLayer
491 // matrix & clip calls 497 // matrix & clip calls
492 // SaveLayer 498 // SaveLayer
493 // matrix & clip calls 499 // matrix & clip calls
494 // draw op 500 // draw op
495 // Restore 501 // Restore
496 // matrix & clip calls (will be ignored) 502 // matrix & clip calls (will be ignored)
497 // Restore 503 // Restore
498 static void emit_body3(SkCanvas* canvas, PFEmitMC emitMC, MatType mat, 504 static void emit_body3(SkCanvas* canvas, PFEmitMC emitMC, MatType mat,
499 ClipType clip, DrawOpType draw, 505 ClipType clip, DrawOpType draw,
500 SkTDArray<DrawType>* expected, int accumulatedClips) { 506 SkTDArray<DrawType>* expected, int accumulatedClips) {
501 bool needsSaveRestore = kNone_DrawOpType != draw && 507 bool needsSaveRestore = kNone_DrawOpType != draw &&
502 (kNone_MatType != mat || kNone_ClipType != clip); 508 (kNone_MatType != mat || kNone_ClipType != clip);
503 509
504 // This saveLayer will always be forced b.c. we currently can't tell 510 if (kNone_MatType != mat || kNone_ClipType != clip) {
505 // ahead of time if it will be empty (see comment in SkMatrixClipStateMgr::s ave) 511 *expected->append() = SAVE;
512 }
513 (*emitMC)(canvas, mat, clip, kSaveLayer_DrawOpType, expected, accumulatedCli ps+1);
506 *expected->append() = SAVE_LAYER; 514 *expected->append() = SAVE_LAYER;
507
508 (*emitMC)(canvas, mat, clip, draw, NULL, 0); // these get fused into later o ps
509 // TODO: widen testing to exercise saveLayer's parameters 515 // TODO: widen testing to exercise saveLayer's parameters
510 canvas->saveLayer(NULL, NULL); 516 canvas->saveLayer(NULL, NULL);
511 (*emitMC)(canvas, mat, clip, draw, NULL, 0); // these get fused into lat er ops 517 (*emitMC)(canvas, mat, clip, kSaveLayer_DrawOpType, expected, 1);
512 if (needsSaveRestore) { 518 if (kNone_MatType != mat || kNone_ClipType != clip) {
513 *expected->append() = SAVE_LAYER; 519 *expected->append() = SAVE;
514 } 520 }
521 *expected->append() = SAVE_LAYER;
515 // TODO: widen testing to exercise saveLayer's parameters 522 // TODO: widen testing to exercise saveLayer's parameters
516 canvas->saveLayer(NULL, NULL); 523 canvas->saveLayer(NULL, NULL);
517 if (needsSaveRestore) { 524 if (needsSaveRestore) {
518 *expected->append() = SAVE; 525 *expected->append() = SAVE;
519 } 526 }
520 (*emitMC)(canvas, mat, clip, draw, expected, accumulatedClips+3); 527 (*emitMC)(canvas, mat, clip, draw, expected, 1);
521 emit_draw(canvas, draw, expected); 528 emit_draw(canvas, draw, expected);
522 if (needsSaveRestore) { 529 if (needsSaveRestore) {
523 *expected->append() = RESTORE; 530 *expected->append() = RESTORE;
524 } 531 }
525 canvas->restore(); 532 canvas->restore(); // for saveLayer
526 if (needsSaveRestore) { 533 *expected->append() = RESTORE; // for saveLayer
534 if (kNone_MatType != mat || kNone_ClipType != clip) {
527 *expected->append() = RESTORE; 535 *expected->append() = RESTORE;
528 } 536 }
529 canvas->restore(); 537 canvas->restore();
530
531 // required to match forced SAVE_LAYER 538 // required to match forced SAVE_LAYER
532 *expected->append() = RESTORE; 539 *expected->append() = RESTORE;
540 if (kNone_MatType != mat || kNone_ClipType != clip) {
541 *expected->append() = RESTORE;
542 }
533 } 543 }
534 544
535 ////////////////////////////////////////////////////////////////////////////// 545 //////////////////////////////////////////////////////////////////////////////
536 546
537 // Emit: 547 // Emit:
538 // Save 548 // Save
539 // some body 549 // some body
540 // Restore 550 // Restore
541 // Note: the outer save/restore are provided by beginRecording/endRecording 551 // Note: the outer save/restore are provided by beginRecording/endRecording
542 static void emit_struct0(SkCanvas* canvas, 552 static void emit_struct0(SkCanvas* canvas,
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 PFEmitStruct gStructure[] = { emit_struct0, emit_struct1, emit_struct2, emit _struct3 }; 663 PFEmitStruct gStructure[] = { emit_struct0, emit_struct1, emit_struct2, emit _struct3 };
654 PFEmitBody gBody[] = { emit_body0, emit_body1, emit_body2, emit_body3 }; 664 PFEmitBody gBody[] = { emit_body0, emit_body1, emit_body2, emit_body3 };
655 PFEmitMC gMCs[] = { emit_clip_and_mat, emit_mat_and_clip, 665 PFEmitMC gMCs[] = { emit_clip_and_mat, emit_mat_and_clip,
656 emit_double_mat_and_clip, emit_mat_clip_clip }; 666 emit_double_mat_and_clip, emit_mat_clip_clip };
657 667
658 for (size_t i = 0; i < SK_ARRAY_COUNT(gStructure); ++i) { 668 for (size_t i = 0; i < SK_ARRAY_COUNT(gStructure); ++i) {
659 for (size_t j = 0; j < SK_ARRAY_COUNT(gBody); ++j) { 669 for (size_t j = 0; j < SK_ARRAY_COUNT(gBody); ++j) {
660 for (size_t k = 0; k < SK_ARRAY_COUNT(gMCs); ++k) { 670 for (size_t k = 0; k < SK_ARRAY_COUNT(gMCs); ++k) {
661 for (int l = 0; l < kMatTypeCount; ++l) { 671 for (int l = 0; l < kMatTypeCount; ++l) {
662 for (int m = 0; m < kClipTypeCount; ++m) { 672 for (int m = 0; m < kClipTypeCount; ++m) {
663 for (int n = 0; n < kDrawOpTypeCount; ++n) { 673 for (int n = 0; n < kNonSaveLayerDrawOpTypeCount; ++n) {
664 #ifdef TEST_COLLAPSE_MATRIX_CLIP_STATE 674 #ifdef TEST_COLLAPSE_MATRIX_CLIP_STATE
665 static int testID = -1; 675 static int testID = -1;
666 ++testID; 676 ++testID;
667 if (testID < -1) { 677 if (testID < -1) {
668 continue; 678 continue;
669 } 679 }
680 SkDebugf("test: %d\n", testID);
670 #endif 681 #endif
671 682
672 SkTDArray<DrawType> expected, actual; 683 SkTDArray<DrawType> expected, actual;
673 684
674 SkPicture picture; 685 SkPicture picture;
675 686
676 // Note: beginRecording/endRecording add a save/rest ore pair 687 // Note: beginRecording/endRecording add a save/rest ore pair
677 SkCanvas* canvas = picture.beginRecording(100, 100); 688 SkCanvas* canvas = picture.beginRecording(100, 100);
678 (*gStructure[i])(canvas, 689 (*gStructure[i])(canvas,
679 gMCs[k], 690 gMCs[k],
(...skipping 30 matching lines...) Expand all
710 } 721 }
711 } 722 }
712 } 723 }
713 } 724 }
714 725
715 DEF_TEST(MatrixClipCollapse, reporter) { 726 DEF_TEST(MatrixClipCollapse, reporter) {
716 test_collapse(reporter); 727 test_collapse(reporter);
717 } 728 }
718 729
719 #endif 730 #endif
OLDNEW
« no previous file with comments | « src/core/SkPictureRecord.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698