OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkBitmapDevice.h" | 8 #include "SkBitmapDevice.h" |
9 #include "SkBlurImageFilter.h" | 9 #include "SkBlurImageFilter.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 *usedPixRefs->append() = bm.pixelRef(); | 308 *usedPixRefs->append() = bm.pixelRef(); |
309 } | 309 } |
310 | 310 |
311 // Return a picture with the bitmaps drawn at the specified positions. | 311 // Return a picture with the bitmaps drawn at the specified positions. |
312 static SkPicture* record_bitmaps(const SkBitmap bm[], | 312 static SkPicture* record_bitmaps(const SkBitmap bm[], |
313 const SkPoint pos[], | 313 const SkPoint pos[], |
314 SkTDArray<SkPixelRef*> analytic[], | 314 SkTDArray<SkPixelRef*> analytic[], |
315 int count, | 315 int count, |
316 DrawBitmapProc proc) { | 316 DrawBitmapProc proc) { |
317 SkPictureRecorder recorder; | 317 SkPictureRecorder recorder; |
318 SkCanvas* canvas = recorder.beginRecording(1000, 1000, NULL, 0); | 318 SkCanvas* canvas = recorder.beginRecording(1000, 1000); |
319 for (int i = 0; i < count; ++i) { | 319 for (int i = 0; i < count; ++i) { |
320 analytic[i].rewind(); | 320 analytic[i].rewind(); |
321 canvas->save(); | 321 canvas->save(); |
322 SkRect clipRect = SkRect::MakeXYWH(pos[i].fX, pos[i].fY, | 322 SkRect clipRect = SkRect::MakeXYWH(pos[i].fX, pos[i].fY, |
323 SkIntToScalar(bm[i].width()), | 323 SkIntToScalar(bm[i].width()), |
324 SkIntToScalar(bm[i].height())); | 324 SkIntToScalar(bm[i].height())); |
325 canvas->clipRect(clipRect, SkRegion::kIntersect_Op); | 325 canvas->clipRect(clipRect, SkRegion::kIntersect_Op); |
326 proc(canvas, bm[i], bm[count+i], pos[i], &analytic[i]); | 326 proc(canvas, bm[i], bm[count+i], pos[i], &analytic[i]); |
327 canvas->restore(); | 327 canvas->restore(); |
328 } | 328 } |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 } | 664 } |
665 } | 665 } |
666 } | 666 } |
667 | 667 |
668 #ifdef SK_DEBUG | 668 #ifdef SK_DEBUG |
669 // Ensure that deleting SkPicturePlayback does not assert. Asserts only fire in
debug mode, so only | 669 // Ensure that deleting SkPicturePlayback does not assert. Asserts only fire in
debug mode, so only |
670 // run in debug mode. | 670 // run in debug mode. |
671 static void test_deleting_empty_playback() { | 671 static void test_deleting_empty_playback() { |
672 SkPictureRecorder recorder; | 672 SkPictureRecorder recorder; |
673 // Creates an SkPictureRecord | 673 // Creates an SkPictureRecord |
674 recorder.beginRecording(0, 0, NULL, 0); | 674 recorder.beginRecording(0, 0); |
675 // Turns that into an SkPicturePlayback | 675 // Turns that into an SkPicturePlayback |
676 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 676 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
677 // Deletes the old SkPicturePlayback, and creates a new SkPictureRecord | 677 // Deletes the old SkPicturePlayback, and creates a new SkPictureRecord |
678 recorder.beginRecording(0, 0, NULL, 0); | 678 recorder.beginRecording(0, 0); |
679 } | 679 } |
680 | 680 |
681 // Ensure that serializing an empty picture does not assert. Likewise only runs
in debug mode. | 681 // Ensure that serializing an empty picture does not assert. Likewise only runs
in debug mode. |
682 static void test_serializing_empty_picture() { | 682 static void test_serializing_empty_picture() { |
683 SkPictureRecorder recorder; | 683 SkPictureRecorder recorder; |
684 recorder.beginRecording(0, 0, NULL, 0); | 684 recorder.beginRecording(0, 0); |
685 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 685 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
686 SkDynamicMemoryWStream stream; | 686 SkDynamicMemoryWStream stream; |
687 picture->serialize(&stream); | 687 picture->serialize(&stream); |
688 } | 688 } |
689 #endif | 689 #endif |
690 | 690 |
691 static void rand_op(SkCanvas* canvas, SkRandom& rand) { | 691 static void rand_op(SkCanvas* canvas, SkRandom& rand) { |
692 SkPaint paint; | 692 SkPaint paint; |
693 SkRect rect = SkRect::MakeWH(50, 50); | 693 SkRect rect = SkRect::MakeWH(50, 50); |
694 | 694 |
(...skipping 11 matching lines...) Expand all Loading... |
706 // SkDebugf("draw\n"); | 706 // SkDebugf("draw\n"); |
707 canvas->drawPaint(paint); | 707 canvas->drawPaint(paint); |
708 } | 708 } |
709 } | 709 } |
710 | 710 |
711 #if SK_SUPPORT_GPU | 711 #if SK_SUPPORT_GPU |
712 static void test_gpu_veto(skiatest::Reporter* reporter) { | 712 static void test_gpu_veto(skiatest::Reporter* reporter) { |
713 | 713 |
714 SkPictureRecorder recorder; | 714 SkPictureRecorder recorder; |
715 | 715 |
716 SkCanvas* canvas = recorder.beginRecording(100, 100, NULL, 0); | 716 SkCanvas* canvas = recorder.beginRecording(100, 100); |
717 { | 717 { |
718 SkPath path; | 718 SkPath path; |
719 path.moveTo(0, 0); | 719 path.moveTo(0, 0); |
720 path.lineTo(50, 50); | 720 path.lineTo(50, 50); |
721 | 721 |
722 SkScalar intervals[] = { 1.0f, 1.0f }; | 722 SkScalar intervals[] = { 1.0f, 1.0f }; |
723 SkAutoTUnref<SkDashPathEffect> dash(SkDashPathEffect::Create(intervals,
2, 0)); | 723 SkAutoTUnref<SkDashPathEffect> dash(SkDashPathEffect::Create(intervals,
2, 0)); |
724 | 724 |
725 SkPaint paint; | 725 SkPaint paint; |
726 paint.setStyle(SkPaint::kStroke_Style); | 726 paint.setStyle(SkPaint::kStroke_Style); |
727 paint.setPathEffect(dash); | 727 paint.setPathEffect(dash); |
728 | 728 |
729 canvas->drawPath(path, paint); | 729 canvas->drawPath(path, paint); |
730 } | 730 } |
731 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 731 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
732 // path effects currently render an SkPicture undesireable for GPU rendering | 732 // path effects currently render an SkPicture undesireable for GPU rendering |
733 | 733 |
734 const char *reason = NULL; | 734 const char *reason = NULL; |
735 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(NULL, &reaso
n)); | 735 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(NULL, &reaso
n)); |
736 REPORTER_ASSERT(reporter, NULL != reason); | 736 REPORTER_ASSERT(reporter, NULL != reason); |
737 | 737 |
738 canvas = recorder.beginRecording(100, 100, NULL, 0); | 738 canvas = recorder.beginRecording(100, 100); |
739 { | 739 { |
740 SkPath path; | 740 SkPath path; |
741 | 741 |
742 path.moveTo(0, 0); | 742 path.moveTo(0, 0); |
743 path.lineTo(0, 50); | 743 path.lineTo(0, 50); |
744 path.lineTo(25, 25); | 744 path.lineTo(25, 25); |
745 path.lineTo(50, 50); | 745 path.lineTo(50, 50); |
746 path.lineTo(50, 0); | 746 path.lineTo(50, 0); |
747 path.close(); | 747 path.close(); |
748 REPORTER_ASSERT(reporter, !path.isConvex()); | 748 REPORTER_ASSERT(reporter, !path.isConvex()); |
749 | 749 |
750 SkPaint paint; | 750 SkPaint paint; |
751 paint.setAntiAlias(true); | 751 paint.setAntiAlias(true); |
752 for (int i = 0; i < 50; ++i) { | 752 for (int i = 0; i < 50; ++i) { |
753 canvas->drawPath(path, paint); | 753 canvas->drawPath(path, paint); |
754 } | 754 } |
755 } | 755 } |
756 picture.reset(recorder.endRecording()); | 756 picture.reset(recorder.endRecording()); |
757 // A lot of AA concave paths currently render an SkPicture undesireable for
GPU rendering | 757 // A lot of AA concave paths currently render an SkPicture undesireable for
GPU rendering |
758 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(NULL)); | 758 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(NULL)); |
759 | 759 |
760 canvas = recorder.beginRecording(100, 100, NULL, 0); | 760 canvas = recorder.beginRecording(100, 100); |
761 { | 761 { |
762 SkPath path; | 762 SkPath path; |
763 | 763 |
764 path.moveTo(0, 0); | 764 path.moveTo(0, 0); |
765 path.lineTo(0, 50); | 765 path.lineTo(0, 50); |
766 path.lineTo(25, 25); | 766 path.lineTo(25, 25); |
767 path.lineTo(50, 50); | 767 path.lineTo(50, 50); |
768 path.lineTo(50, 0); | 768 path.lineTo(50, 0); |
769 path.close(); | 769 path.close(); |
770 REPORTER_ASSERT(reporter, !path.isConvex()); | 770 REPORTER_ASSERT(reporter, !path.isConvex()); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
804 // Restore | 804 // Restore |
805 // 3) | 805 // 3) |
806 // SaveLayer w/ copyable paint | 806 // SaveLayer w/ copyable paint |
807 // Restore | 807 // Restore |
808 // 4) | 808 // 4) |
809 // SaveLayer w/ non-copyable paint | 809 // SaveLayer w/ non-copyable paint |
810 // Restore | 810 // Restore |
811 { | 811 { |
812 SkPictureRecorder recorder; | 812 SkPictureRecorder recorder; |
813 | 813 |
814 SkCanvas* c = recorder.beginRecording(kWidth, kHeight, NULL, 0); | 814 SkCanvas* c = recorder.beginRecording(kWidth, kHeight); |
815 // 1) | 815 // 1) |
816 c->saveLayer(NULL, NULL); | 816 c->saveLayer(NULL, NULL); |
817 c->restore(); | 817 c->restore(); |
818 | 818 |
819 // 2) | 819 // 2) |
820 c->saveLayer(NULL, NULL); | 820 c->saveLayer(NULL, NULL); |
821 c->translate(kWidth/2, kHeight/2); | 821 c->translate(kWidth/2, kHeight/2); |
822 SkRect r = SkRect::MakeXYWH(0, 0, kWidth/2, kHeight/2); | 822 SkRect r = SkRect::MakeXYWH(0, 0, kWidth/2, kHeight/2); |
823 c->saveLayer(&r, NULL); | 823 c->saveLayer(&r, NULL); |
824 c->restore(); | 824 c->restore(); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
972 REPORTER_ASSERT(reporter, numRestores == canvas.getRestoreCount()); | 972 REPORTER_ASSERT(reporter, numRestores == canvas.getRestoreCount()); |
973 } | 973 } |
974 | 974 |
975 // This class exists so SkPicture can friend it and give it access to | 975 // This class exists so SkPicture can friend it and give it access to |
976 // the 'partialReplay' method. | 976 // the 'partialReplay' method. |
977 class SkPictureRecorderReplayTester { | 977 class SkPictureRecorderReplayTester { |
978 public: | 978 public: |
979 static SkPicture* Copy(SkPictureRecorder* recorder) { | 979 static SkPicture* Copy(SkPictureRecorder* recorder) { |
980 SkPictureRecorder recorder2; | 980 SkPictureRecorder recorder2; |
981 | 981 |
982 SkCanvas* canvas = recorder2.beginRecording(10, 10, NULL, 0); | 982 SkCanvas* canvas = recorder2.beginRecording(10, 10); |
983 | 983 |
984 recorder->partialReplay(canvas); | 984 recorder->partialReplay(canvas); |
985 | 985 |
986 return recorder2.endRecording(); | 986 return recorder2.endRecording(); |
987 } | 987 } |
988 }; | 988 }; |
989 | 989 |
990 // Test out SkPictureRecorder::partialReplay | 990 // Test out SkPictureRecorder::partialReplay |
991 DEF_TEST(PictureRecorder_replay, reporter) { | 991 DEF_TEST(PictureRecorder_replay, reporter) { |
992 // check save/saveLayer state | 992 // check save/saveLayer state |
993 { | 993 { |
994 SkPictureRecorder recorder; | 994 SkPictureRecorder recorder; |
995 | 995 |
996 SkCanvas* canvas = recorder.beginRecording(10, 10, NULL, 0); | 996 SkCanvas* canvas = recorder.beginRecording(10, 10); |
997 | 997 |
998 canvas->saveLayer(NULL, NULL); | 998 canvas->saveLayer(NULL, NULL); |
999 | 999 |
1000 SkAutoTUnref<SkPicture> copy(SkPictureRecorderReplayTester::Copy(&record
er)); | 1000 SkAutoTUnref<SkPicture> copy(SkPictureRecorderReplayTester::Copy(&record
er)); |
1001 | 1001 |
1002 // The extra save and restore comes from the Copy process. | 1002 // The extra save and restore comes from the Copy process. |
1003 check_save_state(reporter, copy, 2, 1, 3); | 1003 check_save_state(reporter, copy, 2, 1, 3); |
1004 | 1004 |
1005 canvas->saveLayer(NULL, NULL); | 1005 canvas->saveLayer(NULL, NULL); |
1006 | 1006 |
1007 SkAutoTUnref<SkPicture> final(recorder.endRecording()); | 1007 SkAutoTUnref<SkPicture> final(recorder.endRecording()); |
1008 | 1008 |
1009 check_save_state(reporter, final, 1, 2, 3); | 1009 check_save_state(reporter, final, 1, 2, 3); |
1010 | 1010 |
1011 // The copy shouldn't pick up any operations added after it was made | 1011 // The copy shouldn't pick up any operations added after it was made |
1012 check_save_state(reporter, copy, 2, 1, 3); | 1012 check_save_state(reporter, copy, 2, 1, 3); |
1013 } | 1013 } |
1014 | 1014 |
1015 // (partially) check leakage of draw ops | 1015 // (partially) check leakage of draw ops |
1016 { | 1016 { |
1017 SkPictureRecorder recorder; | 1017 SkPictureRecorder recorder; |
1018 | 1018 |
1019 SkCanvas* canvas = recorder.beginRecording(10, 10, NULL, 0); | 1019 SkCanvas* canvas = recorder.beginRecording(10, 10); |
1020 | 1020 |
1021 SkRect r = SkRect::MakeWH(5, 5); | 1021 SkRect r = SkRect::MakeWH(5, 5); |
1022 SkPaint p; | 1022 SkPaint p; |
1023 | 1023 |
1024 canvas->drawRect(r, p); | 1024 canvas->drawRect(r, p); |
1025 | 1025 |
1026 SkAutoTUnref<SkPicture> copy(SkPictureRecorderReplayTester::Copy(&record
er)); | 1026 SkAutoTUnref<SkPicture> copy(SkPictureRecorderReplayTester::Copy(&record
er)); |
1027 | 1027 |
1028 REPORTER_ASSERT(reporter, !copy->willPlayBackBitmaps()); | 1028 REPORTER_ASSERT(reporter, !copy->willPlayBackBitmaps()); |
1029 | 1029 |
(...skipping 20 matching lines...) Expand all Loading... |
1050 | 1050 |
1051 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); | 1051 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); |
1052 | 1052 |
1053 SkPaint paint; | 1053 SkPaint paint; |
1054 SkRect rect = SkRect::MakeLTRB(-10000000, -10000000, 10000000, 10000000); | 1054 SkRect rect = SkRect::MakeLTRB(-10000000, -10000000, 10000000, 10000000); |
1055 | 1055 |
1056 SkPictureRecorder recorder; | 1056 SkPictureRecorder recorder; |
1057 | 1057 |
1058 { | 1058 { |
1059 // Create picture with 2 unbalanced saves | 1059 // Create picture with 2 unbalanced saves |
1060 SkCanvas* canvas = recorder.beginRecording(100, 100, NULL, 0); | 1060 SkCanvas* canvas = recorder.beginRecording(100, 100); |
1061 canvas->save(); | 1061 canvas->save(); |
1062 canvas->translate(10, 10); | 1062 canvas->translate(10, 10); |
1063 canvas->drawRect(rect, paint); | 1063 canvas->drawRect(rect, paint); |
1064 canvas->save(); | 1064 canvas->save(); |
1065 canvas->translate(10, 10); | 1065 canvas->translate(10, 10); |
1066 canvas->drawRect(rect, paint); | 1066 canvas->drawRect(rect, paint); |
1067 SkAutoTUnref<SkPicture> extraSavePicture(recorder.endRecording()); | 1067 SkAutoTUnref<SkPicture> extraSavePicture(recorder.endRecording()); |
1068 | 1068 |
1069 testCanvas.drawPicture(extraSavePicture); | 1069 testCanvas.drawPicture(extraSavePicture); |
1070 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); | 1070 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); |
1071 } | 1071 } |
1072 | 1072 |
1073 set_canvas_to_save_count_4(&testCanvas); | 1073 set_canvas_to_save_count_4(&testCanvas); |
1074 | 1074 |
1075 { | 1075 { |
1076 // Create picture with 2 unbalanced restores | 1076 // Create picture with 2 unbalanced restores |
1077 SkCanvas* canvas = recorder.beginRecording(100, 100, NULL, 0); | 1077 SkCanvas* canvas = recorder.beginRecording(100, 100); |
1078 canvas->save(); | 1078 canvas->save(); |
1079 canvas->translate(10, 10); | 1079 canvas->translate(10, 10); |
1080 canvas->drawRect(rect, paint); | 1080 canvas->drawRect(rect, paint); |
1081 canvas->save(); | 1081 canvas->save(); |
1082 canvas->translate(10, 10); | 1082 canvas->translate(10, 10); |
1083 canvas->drawRect(rect, paint); | 1083 canvas->drawRect(rect, paint); |
1084 canvas->restore(); | 1084 canvas->restore(); |
1085 canvas->restore(); | 1085 canvas->restore(); |
1086 canvas->restore(); | 1086 canvas->restore(); |
1087 canvas->restore(); | 1087 canvas->restore(); |
1088 SkAutoTUnref<SkPicture> extraRestorePicture(recorder.endRecording()); | 1088 SkAutoTUnref<SkPicture> extraRestorePicture(recorder.endRecording()); |
1089 | 1089 |
1090 testCanvas.drawPicture(extraRestorePicture); | 1090 testCanvas.drawPicture(extraRestorePicture); |
1091 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); | 1091 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); |
1092 } | 1092 } |
1093 | 1093 |
1094 set_canvas_to_save_count_4(&testCanvas); | 1094 set_canvas_to_save_count_4(&testCanvas); |
1095 | 1095 |
1096 { | 1096 { |
1097 SkCanvas* canvas = recorder.beginRecording(100, 100, NULL, 0); | 1097 SkCanvas* canvas = recorder.beginRecording(100, 100); |
1098 canvas->translate(10, 10); | 1098 canvas->translate(10, 10); |
1099 canvas->drawRect(rect, paint); | 1099 canvas->drawRect(rect, paint); |
1100 SkAutoTUnref<SkPicture> noSavePicture(recorder.endRecording()); | 1100 SkAutoTUnref<SkPicture> noSavePicture(recorder.endRecording()); |
1101 | 1101 |
1102 testCanvas.drawPicture(noSavePicture); | 1102 testCanvas.drawPicture(noSavePicture); |
1103 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); | 1103 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); |
1104 REPORTER_ASSERT(reporter, testCanvas.getTotalMatrix().isIdentity()); | 1104 REPORTER_ASSERT(reporter, testCanvas.getTotalMatrix().isIdentity()); |
1105 } | 1105 } |
1106 } | 1106 } |
1107 | 1107 |
1108 static void test_peephole() { | 1108 static void test_peephole() { |
1109 SkRandom rand; | 1109 SkRandom rand; |
1110 | 1110 |
1111 SkPictureRecorder recorder; | 1111 SkPictureRecorder recorder; |
1112 | 1112 |
1113 for (int j = 0; j < 100; j++) { | 1113 for (int j = 0; j < 100; j++) { |
1114 SkRandom rand2(rand); // remember the seed | 1114 SkRandom rand2(rand); // remember the seed |
1115 | 1115 |
1116 SkCanvas* canvas = recorder.beginRecording(100, 100, NULL, 0); | 1116 SkCanvas* canvas = recorder.beginRecording(100, 100); |
1117 | 1117 |
1118 for (int i = 0; i < 1000; ++i) { | 1118 for (int i = 0; i < 1000; ++i) { |
1119 rand_op(canvas, rand); | 1119 rand_op(canvas, rand); |
1120 } | 1120 } |
1121 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 1121 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
1122 | 1122 |
1123 rand = rand2; | 1123 rand = rand2; |
1124 } | 1124 } |
1125 | 1125 |
1126 { | 1126 { |
1127 SkCanvas* canvas = recorder.beginRecording(100, 100, NULL, 0); | 1127 SkCanvas* canvas = recorder.beginRecording(100, 100); |
1128 SkRect rect = SkRect::MakeWH(50, 50); | 1128 SkRect rect = SkRect::MakeWH(50, 50); |
1129 | 1129 |
1130 for (int i = 0; i < 100; ++i) { | 1130 for (int i = 0; i < 100; ++i) { |
1131 canvas->save(); | 1131 canvas->save(); |
1132 } | 1132 } |
1133 while (canvas->getSaveCount() > 1) { | 1133 while (canvas->getSaveCount() > 1) { |
1134 canvas->clipRect(rect); | 1134 canvas->clipRect(rect); |
1135 canvas->restore(); | 1135 canvas->restore(); |
1136 } | 1136 } |
1137 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 1137 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
1138 } | 1138 } |
1139 } | 1139 } |
1140 | 1140 |
1141 #ifndef SK_DEBUG | 1141 #ifndef SK_DEBUG |
1142 // Only test this is in release mode. We deliberately crash in debug mode, since
a valid caller | 1142 // Only test this is in release mode. We deliberately crash in debug mode, since
a valid caller |
1143 // should never do this. | 1143 // should never do this. |
1144 static void test_bad_bitmap() { | 1144 static void test_bad_bitmap() { |
1145 // This bitmap has a width and height but no pixels. As a result, attempting
to record it will | 1145 // This bitmap has a width and height but no pixels. As a result, attempting
to record it will |
1146 // fail. | 1146 // fail. |
1147 SkBitmap bm; | 1147 SkBitmap bm; |
1148 bm.setInfo(SkImageInfo::MakeN32Premul(100, 100)); | 1148 bm.setInfo(SkImageInfo::MakeN32Premul(100, 100)); |
1149 SkPictureRecorder recorder; | 1149 SkPictureRecorder recorder; |
1150 SkCanvas* recordingCanvas = recorder.beginRecording(100, 100, NULL, 0); | 1150 SkCanvas* recordingCanvas = recorder.beginRecording(100, 100); |
1151 recordingCanvas->drawBitmap(bm, 0, 0); | 1151 recordingCanvas->drawBitmap(bm, 0, 0); |
1152 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 1152 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
1153 | 1153 |
1154 SkCanvas canvas; | 1154 SkCanvas canvas; |
1155 canvas.drawPicture(picture); | 1155 canvas.drawPicture(picture); |
1156 } | 1156 } |
1157 #endif | 1157 #endif |
1158 | 1158 |
1159 static SkData* encode_bitmap_to_data(size_t*, const SkBitmap& bm) { | 1159 static SkData* encode_bitmap_to_data(size_t*, const SkBitmap& bm) { |
1160 return SkImageEncoder::EncodeData(bm, SkImageEncoder::kPNG_Type, 100); | 1160 return SkImageEncoder::EncodeData(bm, SkImageEncoder::kPNG_Type, 100); |
1161 } | 1161 } |
1162 | 1162 |
1163 static SkData* serialized_picture_from_bitmap(const SkBitmap& bitmap) { | 1163 static SkData* serialized_picture_from_bitmap(const SkBitmap& bitmap) { |
1164 SkPictureRecorder recorder; | 1164 SkPictureRecorder recorder; |
1165 SkCanvas* canvas = recorder.beginRecording(bitmap.width(), bitmap.height(),
NULL, 0); | 1165 SkCanvas* canvas = recorder.beginRecording(bitmap.width(), bitmap.height()); |
1166 canvas->drawBitmap(bitmap, 0, 0); | 1166 canvas->drawBitmap(bitmap, 0, 0); |
1167 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 1167 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
1168 | 1168 |
1169 SkDynamicMemoryWStream wStream; | 1169 SkDynamicMemoryWStream wStream; |
1170 picture->serialize(&wStream, &encode_bitmap_to_data); | 1170 picture->serialize(&wStream, &encode_bitmap_to_data); |
1171 return wStream.copyToData(); | 1171 return wStream.copyToData(); |
1172 } | 1172 } |
1173 | 1173 |
1174 struct ErrorContext { | 1174 struct ErrorContext { |
1175 int fErrors; | 1175 int fErrors; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1221 SkClearLastError(); | 1221 SkClearLastError(); |
1222 SkSetErrorCallback(NULL, NULL); | 1222 SkSetErrorCallback(NULL, NULL); |
1223 } | 1223 } |
1224 | 1224 |
1225 static void test_clone_empty(skiatest::Reporter* reporter) { | 1225 static void test_clone_empty(skiatest::Reporter* reporter) { |
1226 // This is a regression test for crbug.com/172062 | 1226 // This is a regression test for crbug.com/172062 |
1227 // Before the fix, we used to crash accessing a null pointer when we | 1227 // Before the fix, we used to crash accessing a null pointer when we |
1228 // had a picture with no paints. This test passes by not crashing. | 1228 // had a picture with no paints. This test passes by not crashing. |
1229 { | 1229 { |
1230 SkPictureRecorder recorder; | 1230 SkPictureRecorder recorder; |
1231 recorder.beginRecording(1, 1, NULL, 0); | 1231 recorder.beginRecording(1, 1); |
1232 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 1232 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
1233 SkAutoTUnref<SkPicture> destPicture(picture->clone()); | 1233 SkAutoTUnref<SkPicture> destPicture(picture->clone()); |
1234 REPORTER_ASSERT(reporter, NULL != destPicture); | 1234 REPORTER_ASSERT(reporter, NULL != destPicture); |
1235 } | 1235 } |
1236 } | 1236 } |
1237 | 1237 |
1238 static void test_draw_empty(skiatest::Reporter* reporter) { | 1238 static void test_draw_empty(skiatest::Reporter* reporter) { |
1239 SkBitmap result; | 1239 SkBitmap result; |
1240 make_bm(&result, 2, 2, SK_ColorBLACK, false); | 1240 make_bm(&result, 2, 2, SK_ColorBLACK, false); |
1241 | 1241 |
1242 SkCanvas canvas(result); | 1242 SkCanvas canvas(result); |
1243 | 1243 |
1244 { | 1244 { |
1245 // stock SkPicture | 1245 // stock SkPicture |
1246 SkPictureRecorder recorder; | 1246 SkPictureRecorder recorder; |
1247 recorder.beginRecording(1, 1, NULL, 0); | 1247 recorder.beginRecording(1, 1); |
1248 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 1248 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
1249 | 1249 |
1250 canvas.drawPicture(picture); | 1250 canvas.drawPicture(picture); |
1251 } | 1251 } |
1252 | 1252 |
1253 { | 1253 { |
1254 // tile grid | 1254 // tile grid |
1255 SkTileGridFactory::TileGridInfo gridInfo; | 1255 SkTileGridFactory::TileGridInfo gridInfo; |
1256 gridInfo.fMargin.setEmpty(); | 1256 gridInfo.fMargin.setEmpty(); |
1257 gridInfo.fOffset.setZero(); | 1257 gridInfo.fOffset.setZero(); |
1258 gridInfo.fTileInterval.set(1, 1); | 1258 gridInfo.fTileInterval.set(1, 1); |
1259 | 1259 |
1260 SkTileGridFactory factory(gridInfo); | 1260 SkTileGridFactory factory(gridInfo); |
1261 SkPictureRecorder recorder; | 1261 SkPictureRecorder recorder; |
1262 recorder.beginRecording(1, 1, &factory, 0); | 1262 recorder.beginRecording(1, 1, &factory); |
1263 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 1263 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
1264 | 1264 |
1265 canvas.drawPicture(picture); | 1265 canvas.drawPicture(picture); |
1266 } | 1266 } |
1267 | 1267 |
1268 { | 1268 { |
1269 // RTree | 1269 // RTree |
1270 SkRTreeFactory factory; | 1270 SkRTreeFactory factory; |
1271 SkPictureRecorder recorder; | 1271 SkPictureRecorder recorder; |
1272 recorder.beginRecording(1, 1, &factory, 0); | 1272 recorder.beginRecording(1, 1, &factory); |
1273 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 1273 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
1274 | 1274 |
1275 canvas.drawPicture(picture); | 1275 canvas.drawPicture(picture); |
1276 } | 1276 } |
1277 | 1277 |
1278 { | 1278 { |
1279 // quad tree | 1279 // quad tree |
1280 SkQuadTreeFactory factory; | 1280 SkQuadTreeFactory factory; |
1281 SkPictureRecorder recorder; | 1281 SkPictureRecorder recorder; |
1282 recorder.beginRecording(1, 1, &factory, 0); | 1282 recorder.beginRecording(1, 1, &factory); |
1283 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 1283 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
1284 | 1284 |
1285 canvas.drawPicture(picture); | 1285 canvas.drawPicture(picture); |
1286 } | 1286 } |
1287 } | 1287 } |
1288 | 1288 |
1289 static void test_clip_bound_opt(skiatest::Reporter* reporter) { | 1289 static void test_clip_bound_opt(skiatest::Reporter* reporter) { |
1290 // Test for crbug.com/229011 | 1290 // Test for crbug.com/229011 |
1291 SkRect rect1 = SkRect::MakeXYWH(SkIntToScalar(4), SkIntToScalar(4), | 1291 SkRect rect1 = SkRect::MakeXYWH(SkIntToScalar(4), SkIntToScalar(4), |
1292 SkIntToScalar(2), SkIntToScalar(2)); | 1292 SkIntToScalar(2), SkIntToScalar(2)); |
1293 SkRect rect2 = SkRect::MakeXYWH(SkIntToScalar(7), SkIntToScalar(7), | 1293 SkRect rect2 = SkRect::MakeXYWH(SkIntToScalar(7), SkIntToScalar(7), |
1294 SkIntToScalar(1), SkIntToScalar(1)); | 1294 SkIntToScalar(1), SkIntToScalar(1)); |
1295 SkRect rect3 = SkRect::MakeXYWH(SkIntToScalar(6), SkIntToScalar(6), | 1295 SkRect rect3 = SkRect::MakeXYWH(SkIntToScalar(6), SkIntToScalar(6), |
1296 SkIntToScalar(1), SkIntToScalar(1)); | 1296 SkIntToScalar(1), SkIntToScalar(1)); |
1297 | 1297 |
1298 SkPath invPath; | 1298 SkPath invPath; |
1299 invPath.addOval(rect1); | 1299 invPath.addOval(rect1); |
1300 invPath.setFillType(SkPath::kInverseEvenOdd_FillType); | 1300 invPath.setFillType(SkPath::kInverseEvenOdd_FillType); |
1301 SkPath path; | 1301 SkPath path; |
1302 path.addOval(rect2); | 1302 path.addOval(rect2); |
1303 SkPath path2; | 1303 SkPath path2; |
1304 path2.addOval(rect3); | 1304 path2.addOval(rect3); |
1305 SkIRect clipBounds; | 1305 SkIRect clipBounds; |
1306 SkPictureRecorder recorder; | 1306 SkPictureRecorder recorder; |
1307 // Minimalist test set for 100% code coverage of | 1307 // Minimalist test set for 100% code coverage of |
1308 // SkPictureRecord::updateClipConservativelyUsingBounds | 1308 // SkPictureRecord::updateClipConservativelyUsingBounds |
1309 { | 1309 { |
1310 SkCanvas* canvas = recorder.beginRecording(10, 10, NULL, | 1310 SkCanvas* canvas = recorder.beginRecording(10, 10); |
1311 SkPicture::kUsePathBoundsForClip_RecordingFlag); | |
1312 canvas->clipPath(invPath, SkRegion::kIntersect_Op); | 1311 canvas->clipPath(invPath, SkRegion::kIntersect_Op); |
1313 bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); | 1312 bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); |
1314 REPORTER_ASSERT(reporter, true == nonEmpty); | 1313 REPORTER_ASSERT(reporter, true == nonEmpty); |
1315 REPORTER_ASSERT(reporter, 0 == clipBounds.fLeft); | 1314 REPORTER_ASSERT(reporter, 0 == clipBounds.fLeft); |
1316 REPORTER_ASSERT(reporter, 0 == clipBounds.fTop); | 1315 REPORTER_ASSERT(reporter, 0 == clipBounds.fTop); |
1317 REPORTER_ASSERT(reporter, 10 == clipBounds.fBottom); | 1316 REPORTER_ASSERT(reporter, 10 == clipBounds.fBottom); |
1318 REPORTER_ASSERT(reporter, 10 == clipBounds.fRight); | 1317 REPORTER_ASSERT(reporter, 10 == clipBounds.fRight); |
1319 } | 1318 } |
1320 { | 1319 { |
1321 SkCanvas* canvas = recorder.beginRecording(10, 10, NULL, | 1320 SkCanvas* canvas = recorder.beginRecording(10, 10); |
1322 SkPicture::kUsePathBoundsForClip_RecordingFlag); | |
1323 canvas->clipPath(path, SkRegion::kIntersect_Op); | 1321 canvas->clipPath(path, SkRegion::kIntersect_Op); |
1324 canvas->clipPath(invPath, SkRegion::kIntersect_Op); | 1322 canvas->clipPath(invPath, SkRegion::kIntersect_Op); |
1325 bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); | 1323 bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); |
1326 REPORTER_ASSERT(reporter, true == nonEmpty); | 1324 REPORTER_ASSERT(reporter, true == nonEmpty); |
1327 REPORTER_ASSERT(reporter, 7 == clipBounds.fLeft); | 1325 REPORTER_ASSERT(reporter, 7 == clipBounds.fLeft); |
1328 REPORTER_ASSERT(reporter, 7 == clipBounds.fTop); | 1326 REPORTER_ASSERT(reporter, 7 == clipBounds.fTop); |
1329 REPORTER_ASSERT(reporter, 8 == clipBounds.fBottom); | 1327 REPORTER_ASSERT(reporter, 8 == clipBounds.fBottom); |
1330 REPORTER_ASSERT(reporter, 8 == clipBounds.fRight); | 1328 REPORTER_ASSERT(reporter, 8 == clipBounds.fRight); |
1331 } | 1329 } |
1332 { | 1330 { |
1333 SkCanvas* canvas = recorder.beginRecording(10, 10, NULL, | 1331 SkCanvas* canvas = recorder.beginRecording(10, 10); |
1334 SkPicture::kUsePathBoundsForClip_RecordingFlag); | |
1335 canvas->clipPath(path, SkRegion::kIntersect_Op); | 1332 canvas->clipPath(path, SkRegion::kIntersect_Op); |
1336 canvas->clipPath(invPath, SkRegion::kUnion_Op); | 1333 canvas->clipPath(invPath, SkRegion::kUnion_Op); |
1337 bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); | 1334 bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); |
1338 REPORTER_ASSERT(reporter, true == nonEmpty); | 1335 REPORTER_ASSERT(reporter, true == nonEmpty); |
1339 REPORTER_ASSERT(reporter, 0 == clipBounds.fLeft); | 1336 REPORTER_ASSERT(reporter, 0 == clipBounds.fLeft); |
1340 REPORTER_ASSERT(reporter, 0 == clipBounds.fTop); | 1337 REPORTER_ASSERT(reporter, 0 == clipBounds.fTop); |
1341 REPORTER_ASSERT(reporter, 10 == clipBounds.fBottom); | 1338 REPORTER_ASSERT(reporter, 10 == clipBounds.fBottom); |
1342 REPORTER_ASSERT(reporter, 10 == clipBounds.fRight); | 1339 REPORTER_ASSERT(reporter, 10 == clipBounds.fRight); |
1343 } | 1340 } |
1344 { | 1341 { |
1345 SkCanvas* canvas = recorder.beginRecording(10, 10, NULL, | 1342 SkCanvas* canvas = recorder.beginRecording(10, 10); |
1346 SkPicture::kUsePathBoundsForClip_RecordingFlag); | |
1347 canvas->clipPath(path, SkRegion::kDifference_Op); | 1343 canvas->clipPath(path, SkRegion::kDifference_Op); |
1348 bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); | 1344 bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); |
1349 REPORTER_ASSERT(reporter, true == nonEmpty); | 1345 REPORTER_ASSERT(reporter, true == nonEmpty); |
1350 REPORTER_ASSERT(reporter, 0 == clipBounds.fLeft); | 1346 REPORTER_ASSERT(reporter, 0 == clipBounds.fLeft); |
1351 REPORTER_ASSERT(reporter, 0 == clipBounds.fTop); | 1347 REPORTER_ASSERT(reporter, 0 == clipBounds.fTop); |
1352 REPORTER_ASSERT(reporter, 10 == clipBounds.fBottom); | 1348 REPORTER_ASSERT(reporter, 10 == clipBounds.fBottom); |
1353 REPORTER_ASSERT(reporter, 10 == clipBounds.fRight); | 1349 REPORTER_ASSERT(reporter, 10 == clipBounds.fRight); |
1354 } | 1350 } |
1355 { | 1351 { |
1356 SkCanvas* canvas = recorder.beginRecording(10, 10, NULL, | 1352 SkCanvas* canvas = recorder.beginRecording(10, 10); |
1357 SkPicture::kUsePathBoundsForClip_RecordingFlag); | |
1358 canvas->clipPath(path, SkRegion::kReverseDifference_Op); | 1353 canvas->clipPath(path, SkRegion::kReverseDifference_Op); |
1359 bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); | 1354 bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); |
1360 // True clip is actually empty in this case, but the best | 1355 // True clip is actually empty in this case, but the best |
1361 // determination we can make using only bounds as input is that the | 1356 // determination we can make using only bounds as input is that the |
1362 // clip is included in the bounds of 'path'. | 1357 // clip is included in the bounds of 'path'. |
1363 REPORTER_ASSERT(reporter, true == nonEmpty); | 1358 REPORTER_ASSERT(reporter, true == nonEmpty); |
1364 REPORTER_ASSERT(reporter, 7 == clipBounds.fLeft); | 1359 REPORTER_ASSERT(reporter, 7 == clipBounds.fLeft); |
1365 REPORTER_ASSERT(reporter, 7 == clipBounds.fTop); | 1360 REPORTER_ASSERT(reporter, 7 == clipBounds.fTop); |
1366 REPORTER_ASSERT(reporter, 8 == clipBounds.fBottom); | 1361 REPORTER_ASSERT(reporter, 8 == clipBounds.fBottom); |
1367 REPORTER_ASSERT(reporter, 8 == clipBounds.fRight); | 1362 REPORTER_ASSERT(reporter, 8 == clipBounds.fRight); |
1368 } | 1363 } |
1369 { | 1364 { |
1370 SkCanvas* canvas = recorder.beginRecording(10, 10, NULL, | 1365 SkCanvas* canvas = recorder.beginRecording(10, 10); |
1371 SkPicture::kUsePathBoundsForClip_RecordingFlag); | |
1372 canvas->clipPath(path, SkRegion::kIntersect_Op); | 1366 canvas->clipPath(path, SkRegion::kIntersect_Op); |
1373 canvas->clipPath(path2, SkRegion::kXOR_Op); | 1367 canvas->clipPath(path2, SkRegion::kXOR_Op); |
1374 bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); | 1368 bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); |
1375 REPORTER_ASSERT(reporter, true == nonEmpty); | 1369 REPORTER_ASSERT(reporter, true == nonEmpty); |
1376 REPORTER_ASSERT(reporter, 6 == clipBounds.fLeft); | 1370 REPORTER_ASSERT(reporter, 6 == clipBounds.fLeft); |
1377 REPORTER_ASSERT(reporter, 6 == clipBounds.fTop); | 1371 REPORTER_ASSERT(reporter, 6 == clipBounds.fTop); |
1378 REPORTER_ASSERT(reporter, 8 == clipBounds.fBottom); | 1372 REPORTER_ASSERT(reporter, 8 == clipBounds.fBottom); |
1379 REPORTER_ASSERT(reporter, 8 == clipBounds.fRight); | 1373 REPORTER_ASSERT(reporter, 8 == clipBounds.fRight); |
1380 } | 1374 } |
1381 } | 1375 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1419 unsigned getClipCount() const { return fClipCount; } | 1413 unsigned getClipCount() const { return fClipCount; } |
1420 | 1414 |
1421 private: | 1415 private: |
1422 unsigned fClipCount; | 1416 unsigned fClipCount; |
1423 | 1417 |
1424 typedef SkCanvas INHERITED; | 1418 typedef SkCanvas INHERITED; |
1425 }; | 1419 }; |
1426 | 1420 |
1427 static void test_clip_expansion(skiatest::Reporter* reporter) { | 1421 static void test_clip_expansion(skiatest::Reporter* reporter) { |
1428 SkPictureRecorder recorder; | 1422 SkPictureRecorder recorder; |
1429 SkCanvas* canvas = recorder.beginRecording(10, 10, NULL, 0); | 1423 SkCanvas* canvas = recorder.beginRecording(10, 10); |
1430 | 1424 |
1431 canvas->clipRect(SkRect::MakeEmpty(), SkRegion::kReplace_Op); | 1425 canvas->clipRect(SkRect::MakeEmpty(), SkRegion::kReplace_Op); |
1432 // The following expanding clip should not be skipped. | 1426 // The following expanding clip should not be skipped. |
1433 canvas->clipRect(SkRect::MakeXYWH(4, 4, 3, 3), SkRegion::kUnion_Op); | 1427 canvas->clipRect(SkRect::MakeXYWH(4, 4, 3, 3), SkRegion::kUnion_Op); |
1434 // Draw something so the optimizer doesn't just fold the world. | 1428 // Draw something so the optimizer doesn't just fold the world. |
1435 SkPaint p; | 1429 SkPaint p; |
1436 p.setColor(SK_ColorBLUE); | 1430 p.setColor(SK_ColorBLUE); |
1437 canvas->drawPaint(p); | 1431 canvas->drawPaint(p); |
1438 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 1432 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
1439 | 1433 |
1440 ClipCountingCanvas testCanvas(10, 10); | 1434 ClipCountingCanvas testCanvas(10, 10); |
1441 picture->draw(&testCanvas); | 1435 picture->draw(&testCanvas); |
1442 | 1436 |
1443 // Both clips should be present on playback. | 1437 // Both clips should be present on playback. |
1444 REPORTER_ASSERT(reporter, testCanvas.getClipCount() == 2); | 1438 REPORTER_ASSERT(reporter, testCanvas.getClipCount() == 2); |
1445 } | 1439 } |
1446 | 1440 |
1447 static void test_hierarchical(skiatest::Reporter* reporter) { | 1441 static void test_hierarchical(skiatest::Reporter* reporter) { |
1448 SkBitmap bm; | 1442 SkBitmap bm; |
1449 make_bm(&bm, 10, 10, SK_ColorRED, true); | 1443 make_bm(&bm, 10, 10, SK_ColorRED, true); |
1450 | 1444 |
1451 SkPictureRecorder recorder; | 1445 SkPictureRecorder recorder; |
1452 | 1446 |
1453 recorder.beginRecording(10, 10, NULL, 0); | 1447 recorder.beginRecording(10, 10); |
1454 SkAutoTUnref<SkPicture> childPlain(recorder.endRecording()); | 1448 SkAutoTUnref<SkPicture> childPlain(recorder.endRecording()); |
1455 REPORTER_ASSERT(reporter, !childPlain->willPlayBackBitmaps()); // 0 | 1449 REPORTER_ASSERT(reporter, !childPlain->willPlayBackBitmaps()); // 0 |
1456 | 1450 |
1457 recorder.beginRecording(10, 10, NULL, 0)->drawBitmap(bm, 0, 0); | 1451 recorder.beginRecording(10, 10)->drawBitmap(bm, 0, 0); |
1458 SkAutoTUnref<SkPicture> childWithBitmap(recorder.endRecording()); | 1452 SkAutoTUnref<SkPicture> childWithBitmap(recorder.endRecording()); |
1459 REPORTER_ASSERT(reporter, childWithBitmap->willPlayBackBitmaps()); // 1 | 1453 REPORTER_ASSERT(reporter, childWithBitmap->willPlayBackBitmaps()); // 1 |
1460 | 1454 |
1461 { | 1455 { |
1462 SkCanvas* canvas = recorder.beginRecording(10, 10, NULL, 0); | 1456 SkCanvas* canvas = recorder.beginRecording(10, 10); |
1463 canvas->drawPicture(childPlain); | 1457 canvas->drawPicture(childPlain); |
1464 SkAutoTUnref<SkPicture> parentPP(recorder.endRecording()); | 1458 SkAutoTUnref<SkPicture> parentPP(recorder.endRecording()); |
1465 REPORTER_ASSERT(reporter, !parentPP->willPlayBackBitmaps()); // 0 | 1459 REPORTER_ASSERT(reporter, !parentPP->willPlayBackBitmaps()); // 0 |
1466 } | 1460 } |
1467 { | 1461 { |
1468 SkCanvas* canvas = recorder.beginRecording(10, 10, NULL, 0); | 1462 SkCanvas* canvas = recorder.beginRecording(10, 10); |
1469 canvas->drawPicture(childWithBitmap); | 1463 canvas->drawPicture(childWithBitmap); |
1470 SkAutoTUnref<SkPicture> parentPWB(recorder.endRecording()); | 1464 SkAutoTUnref<SkPicture> parentPWB(recorder.endRecording()); |
1471 REPORTER_ASSERT(reporter, parentPWB->willPlayBackBitmaps()); // 1 | 1465 REPORTER_ASSERT(reporter, parentPWB->willPlayBackBitmaps()); // 1 |
1472 } | 1466 } |
1473 { | 1467 { |
1474 SkCanvas* canvas = recorder.beginRecording(10, 10, NULL, 0); | 1468 SkCanvas* canvas = recorder.beginRecording(10, 10); |
1475 canvas->drawBitmap(bm, 0, 0); | 1469 canvas->drawBitmap(bm, 0, 0); |
1476 canvas->drawPicture(childPlain); | 1470 canvas->drawPicture(childPlain); |
1477 SkAutoTUnref<SkPicture> parentWBP(recorder.endRecording()); | 1471 SkAutoTUnref<SkPicture> parentWBP(recorder.endRecording()); |
1478 REPORTER_ASSERT(reporter, parentWBP->willPlayBackBitmaps()); // 1 | 1472 REPORTER_ASSERT(reporter, parentWBP->willPlayBackBitmaps()); // 1 |
1479 } | 1473 } |
1480 { | 1474 { |
1481 SkCanvas* canvas = recorder.beginRecording(10, 10, NULL, 0); | 1475 SkCanvas* canvas = recorder.beginRecording(10, 10); |
1482 canvas->drawBitmap(bm, 0, 0); | 1476 canvas->drawBitmap(bm, 0, 0); |
1483 canvas->drawPicture(childWithBitmap); | 1477 canvas->drawPicture(childWithBitmap); |
1484 SkAutoTUnref<SkPicture> parentWBWB(recorder.endRecording()); | 1478 SkAutoTUnref<SkPicture> parentWBWB(recorder.endRecording()); |
1485 REPORTER_ASSERT(reporter, parentWBWB->willPlayBackBitmaps()); // 2 | 1479 REPORTER_ASSERT(reporter, parentWBWB->willPlayBackBitmaps()); // 2 |
1486 } | 1480 } |
1487 } | 1481 } |
1488 | 1482 |
1489 static void test_gen_id(skiatest::Reporter* reporter) { | 1483 static void test_gen_id(skiatest::Reporter* reporter) { |
1490 | 1484 |
1491 SkPicture empty; | 1485 SkPicture empty; |
1492 | 1486 |
1493 // Empty pictures should still have a valid ID | 1487 // Empty pictures should still have a valid ID |
1494 REPORTER_ASSERT(reporter, empty.uniqueID() != SK_InvalidGenID); | 1488 REPORTER_ASSERT(reporter, empty.uniqueID() != SK_InvalidGenID); |
1495 | 1489 |
1496 SkPictureRecorder recorder; | 1490 SkPictureRecorder recorder; |
1497 | 1491 |
1498 SkCanvas* canvas = recorder.beginRecording(1, 1, NULL, 0); | 1492 SkCanvas* canvas = recorder.beginRecording(1, 1); |
1499 canvas->drawARGB(255, 255, 255, 255); | 1493 canvas->drawARGB(255, 255, 255, 255); |
1500 SkAutoTUnref<SkPicture> hasData(recorder.endRecording()); | 1494 SkAutoTUnref<SkPicture> hasData(recorder.endRecording()); |
1501 // picture should have a non-zero id after recording | 1495 // picture should have a non-zero id after recording |
1502 REPORTER_ASSERT(reporter, hasData->uniqueID() != SK_InvalidGenID); | 1496 REPORTER_ASSERT(reporter, hasData->uniqueID() != SK_InvalidGenID); |
1503 | 1497 |
1504 // both pictures should have different ids | 1498 // both pictures should have different ids |
1505 REPORTER_ASSERT(reporter, hasData->uniqueID() != empty.uniqueID()); | 1499 REPORTER_ASSERT(reporter, hasData->uniqueID() != empty.uniqueID()); |
1506 | 1500 |
1507 // test out copy constructor | 1501 // test out copy constructor |
1508 SkPicture copyWithData(*hasData); | 1502 SkPicture copyWithData(*hasData); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1575 | 1569 |
1576 static void test_draw_bitmaps(SkCanvas* canvas) { | 1570 static void test_draw_bitmaps(SkCanvas* canvas) { |
1577 SkBitmap empty; | 1571 SkBitmap empty; |
1578 draw_bitmaps(empty, canvas); | 1572 draw_bitmaps(empty, canvas); |
1579 empty.setInfo(SkImageInfo::MakeN32Premul(10, 10)); | 1573 empty.setInfo(SkImageInfo::MakeN32Premul(10, 10)); |
1580 draw_bitmaps(empty, canvas); | 1574 draw_bitmaps(empty, canvas); |
1581 } | 1575 } |
1582 | 1576 |
1583 DEF_TEST(Picture_EmptyBitmap, r) { | 1577 DEF_TEST(Picture_EmptyBitmap, r) { |
1584 SkPictureRecorder recorder; | 1578 SkPictureRecorder recorder; |
1585 test_draw_bitmaps(recorder.beginRecording(10, 10, NULL, 0)); | 1579 test_draw_bitmaps(recorder.beginRecording(10, 10)); |
1586 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 1580 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
1587 } | 1581 } |
1588 | 1582 |
1589 DEF_TEST(Canvas_EmptyBitmap, r) { | 1583 DEF_TEST(Canvas_EmptyBitmap, r) { |
1590 SkBitmap dst; | 1584 SkBitmap dst; |
1591 dst.allocN32Pixels(10, 10); | 1585 dst.allocN32Pixels(10, 10); |
1592 SkCanvas canvas(dst); | 1586 SkCanvas canvas(dst); |
1593 | 1587 |
1594 test_draw_bitmaps(&canvas); | 1588 test_draw_bitmaps(&canvas); |
1595 } | 1589 } |
OLD | NEW |