OLD | NEW |
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
55 #ifdef COLLAPSE_MATRIX_CLIP_STATE | 55 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 56 |
| 57 // Enable/disable debugging helper code |
| 58 //#define TEST_COLLAPSE_MATRIX_CLIP_STATE 1 |
56 | 59 |
57 // Extract the command ops from the input SkPicture | 60 // Extract the command ops from the input SkPicture |
58 static void gets_ops(SkPicture& input, SkTDArray<DrawType>* ops) { | 61 static void gets_ops(SkPicture& input, SkTDArray<DrawType>* ops) { |
59 SkDebugCanvas debugCanvas(input.width(), input.height()); | 62 SkDebugCanvas debugCanvas(input.width(), input.height()); |
60 debugCanvas.setBounds(input.width(), input.height()); | 63 debugCanvas.setBounds(input.width(), input.height()); |
61 input.draw(&debugCanvas); | 64 input.draw(&debugCanvas); |
62 | 65 |
63 ops->setCount(debugCanvas.getSize()); | 66 ops->setCount(debugCanvas.getSize()); |
64 for (int i = 0; i < debugCanvas.getSize(); ++i) { | 67 for (int i = 0; i < debugCanvas.getSize(); ++i) { |
65 (*ops)[i] = debugCanvas.getDrawCommandAt(i)->getType(); | 68 (*ops)[i] = debugCanvas.getDrawCommandAt(i)->getType(); |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 (*emitMC)(canvas, mat, clip, draw, NULL, 1); // these will get fused int
o later ops | 619 (*emitMC)(canvas, mat, clip, draw, NULL, 1); // these will get fused int
o later ops |
617 canvas->save(); | 620 canvas->save(); |
618 (*emitBody)(canvas, emitMC, mat, clip, draw, expected, 2); | 621 (*emitBody)(canvas, emitMC, mat, clip, draw, expected, 2); |
619 canvas->restore(); | 622 canvas->restore(); |
620 canvas->restore(); | 623 canvas->restore(); |
621 (*emitMC)(canvas, mat, clip, draw, NULL, 0); // these will get removed | 624 (*emitMC)(canvas, mat, clip, draw, NULL, 0); // these will get removed |
622 } | 625 } |
623 | 626 |
624 ////////////////////////////////////////////////////////////////////////////// | 627 ////////////////////////////////////////////////////////////////////////////// |
625 | 628 |
626 #ifdef COLLAPSE_MATRIX_CLIP_STATE | 629 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
627 static void print(const SkTDArray<DrawType>& expected, const SkTDArray<DrawType>
& actual) { | 630 static void print(const SkTDArray<DrawType>& expected, const SkTDArray<DrawType>
& actual) { |
628 SkDebugf("\n\nexpected %d --- actual %d\n", expected.count(), actual.count()
); | 631 SkDebugf("\n\nexpected %d --- actual %d\n", expected.count(), actual.count()
); |
629 int max = SkMax32(expected.count(), actual.count()); | 632 int max = SkMax32(expected.count(), actual.count()); |
630 | 633 |
631 for (int i = 0; i < max; ++i) { | 634 for (int i = 0; i < max; ++i) { |
632 if (i < expected.count()) { | 635 if (i < expected.count()) { |
633 SkDebugf("%16s, ", SkDrawCommand::GetCommandString(expected[i])); | 636 SkDebugf("%16s, ", SkDrawCommand::GetCommandString(expected[i])); |
634 } else { | 637 } else { |
635 SkDebugf("%16s, ", " "); | 638 SkDebugf("%16s, ", " "); |
636 } | 639 } |
(...skipping 14 matching lines...) Expand all Loading... |
651 PFEmitBody gBody[] = { emit_body0, emit_body1, emit_body2, emit_body3 }; | 654 PFEmitBody gBody[] = { emit_body0, emit_body1, emit_body2, emit_body3 }; |
652 PFEmitMC gMCs[] = { emit_clip_and_mat, emit_mat_and_clip, | 655 PFEmitMC gMCs[] = { emit_clip_and_mat, emit_mat_and_clip, |
653 emit_double_mat_and_clip, emit_mat_clip_clip }; | 656 emit_double_mat_and_clip, emit_mat_clip_clip }; |
654 | 657 |
655 for (size_t i = 0; i < SK_ARRAY_COUNT(gStructure); ++i) { | 658 for (size_t i = 0; i < SK_ARRAY_COUNT(gStructure); ++i) { |
656 for (size_t j = 0; j < SK_ARRAY_COUNT(gBody); ++j) { | 659 for (size_t j = 0; j < SK_ARRAY_COUNT(gBody); ++j) { |
657 for (size_t k = 0; k < SK_ARRAY_COUNT(gMCs); ++k) { | 660 for (size_t k = 0; k < SK_ARRAY_COUNT(gMCs); ++k) { |
658 for (int l = 0; l < kMatTypeCount; ++l) { | 661 for (int l = 0; l < kMatTypeCount; ++l) { |
659 for (int m = 0; m < kClipTypeCount; ++m) { | 662 for (int m = 0; m < kClipTypeCount; ++m) { |
660 for (int n = 0; n < kDrawOpTypeCount; ++n) { | 663 for (int n = 0; n < kDrawOpTypeCount; ++n) { |
661 #ifdef COLLAPSE_MATRIX_CLIP_STATE | 664 #ifdef TEST_COLLAPSE_MATRIX_CLIP_STATE |
662 static int testID = -1; | 665 static int testID = -1; |
663 ++testID; | 666 ++testID; |
664 if (testID < -1) { | 667 if (testID < -1) { |
665 continue; | 668 continue; |
666 } | 669 } |
667 #endif | 670 #endif |
668 | 671 |
669 SkTDArray<DrawType> expected, actual; | 672 SkTDArray<DrawType> expected, actual; |
670 | 673 |
671 SkPicture picture; | 674 SkPicture picture; |
672 | 675 |
673 // Note: beginRecording/endRecording add a save/rest
ore pair | 676 // Note: beginRecording/endRecording add a save/rest
ore pair |
674 SkCanvas* canvas = picture.beginRecording(100, 100); | 677 SkCanvas* canvas = picture.beginRecording(100, 100); |
675 (*gStructure[i])(canvas, | 678 (*gStructure[i])(canvas, |
676 gMCs[k], | 679 gMCs[k], |
677 (MatType) l, | 680 (MatType) l, |
678 (ClipType) m, | 681 (ClipType) m, |
679 gBody[j], | 682 gBody[j], |
680 (DrawOpType) n, | 683 (DrawOpType) n, |
681 &expected); | 684 &expected); |
682 picture.endRecording(); | 685 picture.endRecording(); |
683 | 686 |
684 gets_ops(picture, &actual); | 687 gets_ops(picture, &actual); |
685 | 688 |
686 REPORTER_ASSERT(reporter, expected.count() == actual
.count()); | 689 REPORTER_ASSERT(reporter, expected.count() == actual
.count()); |
687 | 690 |
688 if (expected.count() != actual.count()) { | 691 if (expected.count() != actual.count()) { |
689 #ifdef COLLAPSE_MATRIX_CLIP_STATE | 692 #ifdef TEST_COLLAPSE_MATRIX_CLIP_STATE |
690 print(expected, actual); | 693 print(expected, actual); |
691 #endif | 694 #endif |
692 continue; | 695 continue; |
693 } | 696 } |
694 | 697 |
695 for (int i = 0; i < expected.count(); ++i) { | 698 for (int i = 0; i < expected.count(); ++i) { |
696 REPORTER_ASSERT(reporter, expected[i] == actual[
i]); | 699 REPORTER_ASSERT(reporter, expected[i] == actual[
i]); |
697 #ifdef COLLAPSE_MATRIX_CLIP_STATE | 700 #ifdef TEST_COLLAPSE_MATRIX_CLIP_STATE |
698 if (expected[i] != actual[i]) { | 701 if (expected[i] != actual[i]) { |
699 print(expected, actual); | 702 print(expected, actual); |
700 } | 703 } |
701 #endif | 704 #endif |
702 break; | 705 break; |
703 } | 706 } |
704 } | 707 } |
705 } | 708 } |
706 } | 709 } |
707 } | 710 } |
708 } | 711 } |
709 } | 712 } |
710 } | 713 } |
711 | 714 |
712 DEF_TEST(MatrixClipCollapse, reporter) { | 715 DEF_TEST(MatrixClipCollapse, reporter) { |
713 test_collapse(reporter); | 716 test_collapse(reporter); |
714 } | 717 } |
715 | 718 |
716 #endif | 719 #endif |
OLD | NEW |