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

Side by Side Diff: tests/MatrixClipCollapseTest.cpp

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