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

Side by Side Diff: tests/PictureTest.cpp

Issue 316143003: Remove SkPicture::kUsePathBoundsForClip_RecordingFlag (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add suppression for fixed GM Created 6 years, 6 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') | tools/PictureRenderer.h » ('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 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
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
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
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
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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
971 REPORTER_ASSERT(reporter, numRestores == canvas.getRestoreCount()); 971 REPORTER_ASSERT(reporter, numRestores == canvas.getRestoreCount());
972 } 972 }
973 973
974 // This class exists so SkPicture can friend it and give it access to 974 // This class exists so SkPicture can friend it and give it access to
975 // the 'partialReplay' method. 975 // the 'partialReplay' method.
976 class SkPictureRecorderReplayTester { 976 class SkPictureRecorderReplayTester {
977 public: 977 public:
978 static SkPicture* Copy(SkPictureRecorder* recorder) { 978 static SkPicture* Copy(SkPictureRecorder* recorder) {
979 SkPictureRecorder recorder2; 979 SkPictureRecorder recorder2;
980 980
981 SkCanvas* canvas = recorder2.beginRecording(10, 10, NULL, 0); 981 SkCanvas* canvas = recorder2.beginRecording(10, 10);
982 982
983 recorder->partialReplay(canvas); 983 recorder->partialReplay(canvas);
984 984
985 return recorder2.endRecording(); 985 return recorder2.endRecording();
986 } 986 }
987 }; 987 };
988 988
989 // Test out SkPictureRecorder::partialReplay 989 // Test out SkPictureRecorder::partialReplay
990 DEF_TEST(PictureRecorder_replay, reporter) { 990 DEF_TEST(PictureRecorder_replay, reporter) {
991 // check save/saveLayer state 991 // check save/saveLayer state
992 { 992 {
993 SkPictureRecorder recorder; 993 SkPictureRecorder recorder;
994 994
995 SkCanvas* canvas = recorder.beginRecording(10, 10, NULL, 0); 995 SkCanvas* canvas = recorder.beginRecording(10, 10);
996 996
997 canvas->saveLayer(NULL, NULL); 997 canvas->saveLayer(NULL, NULL);
998 998
999 SkAutoTUnref<SkPicture> copy(SkPictureRecorderReplayTester::Copy(&record er)); 999 SkAutoTUnref<SkPicture> copy(SkPictureRecorderReplayTester::Copy(&record er));
1000 1000
1001 // The extra save and restore comes from the Copy process. 1001 // The extra save and restore comes from the Copy process.
1002 check_save_state(reporter, copy, 2, 1, 3); 1002 check_save_state(reporter, copy, 2, 1, 3);
1003 1003
1004 canvas->saveLayer(NULL, NULL); 1004 canvas->saveLayer(NULL, NULL);
1005 1005
1006 SkAutoTUnref<SkPicture> final(recorder.endRecording()); 1006 SkAutoTUnref<SkPicture> final(recorder.endRecording());
1007 1007
1008 check_save_state(reporter, final, 1, 2, 3); 1008 check_save_state(reporter, final, 1, 2, 3);
1009 1009
1010 // The copy shouldn't pick up any operations added after it was made 1010 // The copy shouldn't pick up any operations added after it was made
1011 check_save_state(reporter, copy, 2, 1, 3); 1011 check_save_state(reporter, copy, 2, 1, 3);
1012 } 1012 }
1013 1013
1014 // (partially) check leakage of draw ops 1014 // (partially) check leakage of draw ops
1015 { 1015 {
1016 SkPictureRecorder recorder; 1016 SkPictureRecorder recorder;
1017 1017
1018 SkCanvas* canvas = recorder.beginRecording(10, 10, NULL, 0); 1018 SkCanvas* canvas = recorder.beginRecording(10, 10);
1019 1019
1020 SkRect r = SkRect::MakeWH(5, 5); 1020 SkRect r = SkRect::MakeWH(5, 5);
1021 SkPaint p; 1021 SkPaint p;
1022 1022
1023 canvas->drawRect(r, p); 1023 canvas->drawRect(r, p);
1024 1024
1025 SkAutoTUnref<SkPicture> copy(SkPictureRecorderReplayTester::Copy(&record er)); 1025 SkAutoTUnref<SkPicture> copy(SkPictureRecorderReplayTester::Copy(&record er));
1026 1026
1027 REPORTER_ASSERT(reporter, !copy->willPlayBackBitmaps()); 1027 REPORTER_ASSERT(reporter, !copy->willPlayBackBitmaps());
1028 1028
(...skipping 19 matching lines...) Expand all
1048 1048
1049 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); 1049 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount());
1050 1050
1051 SkPaint paint; 1051 SkPaint paint;
1052 SkRect rect = SkRect::MakeLTRB(-10000000, -10000000, 10000000, 10000000); 1052 SkRect rect = SkRect::MakeLTRB(-10000000, -10000000, 10000000, 10000000);
1053 1053
1054 SkPictureRecorder recorder; 1054 SkPictureRecorder recorder;
1055 1055
1056 { 1056 {
1057 // Create picture with 2 unbalanced saves 1057 // Create picture with 2 unbalanced saves
1058 SkCanvas* canvas = recorder.beginRecording(100, 100, NULL, 0); 1058 SkCanvas* canvas = recorder.beginRecording(100, 100);
1059 canvas->save(); 1059 canvas->save();
1060 canvas->translate(10, 10); 1060 canvas->translate(10, 10);
1061 canvas->drawRect(rect, paint); 1061 canvas->drawRect(rect, paint);
1062 canvas->save(); 1062 canvas->save();
1063 canvas->translate(10, 10); 1063 canvas->translate(10, 10);
1064 canvas->drawRect(rect, paint); 1064 canvas->drawRect(rect, paint);
1065 SkAutoTUnref<SkPicture> extraSavePicture(recorder.endRecording()); 1065 SkAutoTUnref<SkPicture> extraSavePicture(recorder.endRecording());
1066 1066
1067 testCanvas.drawPicture(extraSavePicture); 1067 testCanvas.drawPicture(extraSavePicture);
1068 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); 1068 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount());
1069 } 1069 }
1070 1070
1071 set_canvas_to_save_count_4(&testCanvas); 1071 set_canvas_to_save_count_4(&testCanvas);
1072 1072
1073 { 1073 {
1074 // Create picture with 2 unbalanced restores 1074 // Create picture with 2 unbalanced restores
1075 SkCanvas* canvas = recorder.beginRecording(100, 100, NULL, 0); 1075 SkCanvas* canvas = recorder.beginRecording(100, 100);
1076 canvas->save(); 1076 canvas->save();
1077 canvas->translate(10, 10); 1077 canvas->translate(10, 10);
1078 canvas->drawRect(rect, paint); 1078 canvas->drawRect(rect, paint);
1079 canvas->save(); 1079 canvas->save();
1080 canvas->translate(10, 10); 1080 canvas->translate(10, 10);
1081 canvas->drawRect(rect, paint); 1081 canvas->drawRect(rect, paint);
1082 canvas->restore(); 1082 canvas->restore();
1083 canvas->restore(); 1083 canvas->restore();
1084 canvas->restore(); 1084 canvas->restore();
1085 canvas->restore(); 1085 canvas->restore();
1086 SkAutoTUnref<SkPicture> extraRestorePicture(recorder.endRecording()); 1086 SkAutoTUnref<SkPicture> extraRestorePicture(recorder.endRecording());
1087 1087
1088 testCanvas.drawPicture(extraRestorePicture); 1088 testCanvas.drawPicture(extraRestorePicture);
1089 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); 1089 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount());
1090 } 1090 }
1091 1091
1092 set_canvas_to_save_count_4(&testCanvas); 1092 set_canvas_to_save_count_4(&testCanvas);
1093 1093
1094 { 1094 {
1095 SkCanvas* canvas = recorder.beginRecording(100, 100, NULL, 0); 1095 SkCanvas* canvas = recorder.beginRecording(100, 100);
1096 canvas->translate(10, 10); 1096 canvas->translate(10, 10);
1097 canvas->drawRect(rect, paint); 1097 canvas->drawRect(rect, paint);
1098 SkAutoTUnref<SkPicture> noSavePicture(recorder.endRecording()); 1098 SkAutoTUnref<SkPicture> noSavePicture(recorder.endRecording());
1099 1099
1100 testCanvas.drawPicture(noSavePicture); 1100 testCanvas.drawPicture(noSavePicture);
1101 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); 1101 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount());
1102 REPORTER_ASSERT(reporter, testCanvas.getTotalMatrix().isIdentity()); 1102 REPORTER_ASSERT(reporter, testCanvas.getTotalMatrix().isIdentity());
1103 } 1103 }
1104 } 1104 }
1105 1105
1106 static void test_peephole() { 1106 static void test_peephole() {
1107 SkRandom rand; 1107 SkRandom rand;
1108 1108
1109 SkPictureRecorder recorder; 1109 SkPictureRecorder recorder;
1110 1110
1111 for (int j = 0; j < 100; j++) { 1111 for (int j = 0; j < 100; j++) {
1112 SkRandom rand2(rand); // remember the seed 1112 SkRandom rand2(rand); // remember the seed
1113 1113
1114 SkCanvas* canvas = recorder.beginRecording(100, 100, NULL, 0); 1114 SkCanvas* canvas = recorder.beginRecording(100, 100);
1115 1115
1116 for (int i = 0; i < 1000; ++i) { 1116 for (int i = 0; i < 1000; ++i) {
1117 rand_op(canvas, rand); 1117 rand_op(canvas, rand);
1118 } 1118 }
1119 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); 1119 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
1120 1120
1121 rand = rand2; 1121 rand = rand2;
1122 } 1122 }
1123 1123
1124 { 1124 {
1125 SkCanvas* canvas = recorder.beginRecording(100, 100, NULL, 0); 1125 SkCanvas* canvas = recorder.beginRecording(100, 100);
1126 SkRect rect = SkRect::MakeWH(50, 50); 1126 SkRect rect = SkRect::MakeWH(50, 50);
1127 1127
1128 for (int i = 0; i < 100; ++i) { 1128 for (int i = 0; i < 100; ++i) {
1129 canvas->save(); 1129 canvas->save();
1130 } 1130 }
1131 while (canvas->getSaveCount() > 1) { 1131 while (canvas->getSaveCount() > 1) {
1132 canvas->clipRect(rect); 1132 canvas->clipRect(rect);
1133 canvas->restore(); 1133 canvas->restore();
1134 } 1134 }
1135 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); 1135 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
1136 } 1136 }
1137 } 1137 }
1138 1138
1139 #ifndef SK_DEBUG 1139 #ifndef SK_DEBUG
1140 // Only test this is in release mode. We deliberately crash in debug mode, since a valid caller 1140 // Only test this is in release mode. We deliberately crash in debug mode, since a valid caller
1141 // should never do this. 1141 // should never do this.
1142 static void test_bad_bitmap() { 1142 static void test_bad_bitmap() {
1143 // This bitmap has a width and height but no pixels. As a result, attempting to record it will 1143 // This bitmap has a width and height but no pixels. As a result, attempting to record it will
1144 // fail. 1144 // fail.
1145 SkBitmap bm; 1145 SkBitmap bm;
1146 bm.setInfo(SkImageInfo::MakeN32Premul(100, 100)); 1146 bm.setInfo(SkImageInfo::MakeN32Premul(100, 100));
1147 SkPictureRecorder recorder; 1147 SkPictureRecorder recorder;
1148 SkCanvas* recordingCanvas = recorder.beginRecording(100, 100, NULL, 0); 1148 SkCanvas* recordingCanvas = recorder.beginRecording(100, 100);
1149 recordingCanvas->drawBitmap(bm, 0, 0); 1149 recordingCanvas->drawBitmap(bm, 0, 0);
1150 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); 1150 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
1151 1151
1152 SkCanvas canvas; 1152 SkCanvas canvas;
1153 canvas.drawPicture(picture); 1153 canvas.drawPicture(picture);
1154 } 1154 }
1155 #endif 1155 #endif
1156 1156
1157 static SkData* encode_bitmap_to_data(size_t*, const SkBitmap& bm) { 1157 static SkData* encode_bitmap_to_data(size_t*, const SkBitmap& bm) {
1158 return SkImageEncoder::EncodeData(bm, SkImageEncoder::kPNG_Type, 100); 1158 return SkImageEncoder::EncodeData(bm, SkImageEncoder::kPNG_Type, 100);
1159 } 1159 }
1160 1160
1161 static SkData* serialized_picture_from_bitmap(const SkBitmap& bitmap) { 1161 static SkData* serialized_picture_from_bitmap(const SkBitmap& bitmap) {
1162 SkPictureRecorder recorder; 1162 SkPictureRecorder recorder;
1163 SkCanvas* canvas = recorder.beginRecording(bitmap.width(), bitmap.height(), NULL, 0); 1163 SkCanvas* canvas = recorder.beginRecording(bitmap.width(), bitmap.height());
1164 canvas->drawBitmap(bitmap, 0, 0); 1164 canvas->drawBitmap(bitmap, 0, 0);
1165 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); 1165 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
1166 1166
1167 SkDynamicMemoryWStream wStream; 1167 SkDynamicMemoryWStream wStream;
1168 picture->serialize(&wStream, &encode_bitmap_to_data); 1168 picture->serialize(&wStream, &encode_bitmap_to_data);
1169 return wStream.copyToData(); 1169 return wStream.copyToData();
1170 } 1170 }
1171 1171
1172 struct ErrorContext { 1172 struct ErrorContext {
1173 int fErrors; 1173 int fErrors;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1219 SkClearLastError(); 1219 SkClearLastError();
1220 SkSetErrorCallback(NULL, NULL); 1220 SkSetErrorCallback(NULL, NULL);
1221 } 1221 }
1222 1222
1223 static void test_clone_empty(skiatest::Reporter* reporter) { 1223 static void test_clone_empty(skiatest::Reporter* reporter) {
1224 // This is a regression test for crbug.com/172062 1224 // This is a regression test for crbug.com/172062
1225 // Before the fix, we used to crash accessing a null pointer when we 1225 // Before the fix, we used to crash accessing a null pointer when we
1226 // had a picture with no paints. This test passes by not crashing. 1226 // had a picture with no paints. This test passes by not crashing.
1227 { 1227 {
1228 SkPictureRecorder recorder; 1228 SkPictureRecorder recorder;
1229 recorder.beginRecording(1, 1, NULL, 0); 1229 recorder.beginRecording(1, 1);
1230 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); 1230 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
1231 SkAutoTUnref<SkPicture> destPicture(picture->clone()); 1231 SkAutoTUnref<SkPicture> destPicture(picture->clone());
1232 REPORTER_ASSERT(reporter, NULL != destPicture); 1232 REPORTER_ASSERT(reporter, NULL != destPicture);
1233 } 1233 }
1234 } 1234 }
1235 1235
1236 static void test_draw_empty(skiatest::Reporter* reporter) { 1236 static void test_draw_empty(skiatest::Reporter* reporter) {
1237 SkBitmap result; 1237 SkBitmap result;
1238 make_bm(&result, 2, 2, SK_ColorBLACK, false); 1238 make_bm(&result, 2, 2, SK_ColorBLACK, false);
1239 1239
1240 SkCanvas canvas(result); 1240 SkCanvas canvas(result);
1241 1241
1242 { 1242 {
1243 // stock SkPicture 1243 // stock SkPicture
1244 SkPictureRecorder recorder; 1244 SkPictureRecorder recorder;
1245 recorder.beginRecording(1, 1, NULL, 0); 1245 recorder.beginRecording(1, 1);
1246 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); 1246 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
1247 1247
1248 canvas.drawPicture(picture); 1248 canvas.drawPicture(picture);
1249 } 1249 }
1250 1250
1251 { 1251 {
1252 // tile grid 1252 // tile grid
1253 SkTileGridFactory::TileGridInfo gridInfo; 1253 SkTileGridFactory::TileGridInfo gridInfo;
1254 gridInfo.fMargin.setEmpty(); 1254 gridInfo.fMargin.setEmpty();
1255 gridInfo.fOffset.setZero(); 1255 gridInfo.fOffset.setZero();
1256 gridInfo.fTileInterval.set(1, 1); 1256 gridInfo.fTileInterval.set(1, 1);
1257 1257
1258 SkTileGridFactory factory(gridInfo); 1258 SkTileGridFactory factory(gridInfo);
1259 SkPictureRecorder recorder; 1259 SkPictureRecorder recorder;
1260 recorder.beginRecording(1, 1, &factory, 0); 1260 recorder.beginRecording(1, 1, &factory);
1261 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); 1261 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
1262 1262
1263 canvas.drawPicture(picture); 1263 canvas.drawPicture(picture);
1264 } 1264 }
1265 1265
1266 { 1266 {
1267 // RTree 1267 // RTree
1268 SkRTreeFactory factory; 1268 SkRTreeFactory factory;
1269 SkPictureRecorder recorder; 1269 SkPictureRecorder recorder;
1270 recorder.beginRecording(1, 1, &factory, 0); 1270 recorder.beginRecording(1, 1, &factory);
1271 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); 1271 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
1272 1272
1273 canvas.drawPicture(picture); 1273 canvas.drawPicture(picture);
1274 } 1274 }
1275 1275
1276 { 1276 {
1277 // quad tree 1277 // quad tree
1278 SkQuadTreeFactory factory; 1278 SkQuadTreeFactory factory;
1279 SkPictureRecorder recorder; 1279 SkPictureRecorder recorder;
1280 recorder.beginRecording(1, 1, &factory, 0); 1280 recorder.beginRecording(1, 1, &factory);
1281 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); 1281 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
1282 1282
1283 canvas.drawPicture(picture); 1283 canvas.drawPicture(picture);
1284 } 1284 }
1285 } 1285 }
1286 1286
1287 static void test_clip_bound_opt(skiatest::Reporter* reporter) { 1287 static void test_clip_bound_opt(skiatest::Reporter* reporter) {
1288 // Test for crbug.com/229011 1288 // Test for crbug.com/229011
1289 SkRect rect1 = SkRect::MakeXYWH(SkIntToScalar(4), SkIntToScalar(4), 1289 SkRect rect1 = SkRect::MakeXYWH(SkIntToScalar(4), SkIntToScalar(4),
1290 SkIntToScalar(2), SkIntToScalar(2)); 1290 SkIntToScalar(2), SkIntToScalar(2));
1291 SkRect rect2 = SkRect::MakeXYWH(SkIntToScalar(7), SkIntToScalar(7), 1291 SkRect rect2 = SkRect::MakeXYWH(SkIntToScalar(7), SkIntToScalar(7),
1292 SkIntToScalar(1), SkIntToScalar(1)); 1292 SkIntToScalar(1), SkIntToScalar(1));
1293 SkRect rect3 = SkRect::MakeXYWH(SkIntToScalar(6), SkIntToScalar(6), 1293 SkRect rect3 = SkRect::MakeXYWH(SkIntToScalar(6), SkIntToScalar(6),
1294 SkIntToScalar(1), SkIntToScalar(1)); 1294 SkIntToScalar(1), SkIntToScalar(1));
1295 1295
1296 SkPath invPath; 1296 SkPath invPath;
1297 invPath.addOval(rect1); 1297 invPath.addOval(rect1);
1298 invPath.setFillType(SkPath::kInverseEvenOdd_FillType); 1298 invPath.setFillType(SkPath::kInverseEvenOdd_FillType);
1299 SkPath path; 1299 SkPath path;
1300 path.addOval(rect2); 1300 path.addOval(rect2);
1301 SkPath path2; 1301 SkPath path2;
1302 path2.addOval(rect3); 1302 path2.addOval(rect3);
1303 SkIRect clipBounds; 1303 SkIRect clipBounds;
1304 SkPictureRecorder recorder; 1304 SkPictureRecorder recorder;
1305 // Minimalist test set for 100% code coverage of 1305 // Minimalist test set for 100% code coverage of
1306 // SkPictureRecord::updateClipConservativelyUsingBounds 1306 // SkPictureRecord::updateClipConservativelyUsingBounds
1307 { 1307 {
1308 SkCanvas* canvas = recorder.beginRecording(10, 10, NULL, 1308 SkCanvas* canvas = recorder.beginRecording(10, 10);
1309 SkPicture::kUsePathBoundsForClip_RecordingFlag);
1310 canvas->clipPath(invPath, SkRegion::kIntersect_Op); 1309 canvas->clipPath(invPath, SkRegion::kIntersect_Op);
1311 bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); 1310 bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds);
1312 REPORTER_ASSERT(reporter, true == nonEmpty); 1311 REPORTER_ASSERT(reporter, true == nonEmpty);
1313 REPORTER_ASSERT(reporter, 0 == clipBounds.fLeft); 1312 REPORTER_ASSERT(reporter, 0 == clipBounds.fLeft);
1314 REPORTER_ASSERT(reporter, 0 == clipBounds.fTop); 1313 REPORTER_ASSERT(reporter, 0 == clipBounds.fTop);
1315 REPORTER_ASSERT(reporter, 10 == clipBounds.fBottom); 1314 REPORTER_ASSERT(reporter, 10 == clipBounds.fBottom);
1316 REPORTER_ASSERT(reporter, 10 == clipBounds.fRight); 1315 REPORTER_ASSERT(reporter, 10 == clipBounds.fRight);
1317 } 1316 }
1318 { 1317 {
1319 SkCanvas* canvas = recorder.beginRecording(10, 10, NULL, 1318 SkCanvas* canvas = recorder.beginRecording(10, 10);
1320 SkPicture::kUsePathBoundsForClip_RecordingFlag);
1321 canvas->clipPath(path, SkRegion::kIntersect_Op); 1319 canvas->clipPath(path, SkRegion::kIntersect_Op);
1322 canvas->clipPath(invPath, SkRegion::kIntersect_Op); 1320 canvas->clipPath(invPath, SkRegion::kIntersect_Op);
1323 bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); 1321 bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds);
1324 REPORTER_ASSERT(reporter, true == nonEmpty); 1322 REPORTER_ASSERT(reporter, true == nonEmpty);
1325 REPORTER_ASSERT(reporter, 7 == clipBounds.fLeft); 1323 REPORTER_ASSERT(reporter, 7 == clipBounds.fLeft);
1326 REPORTER_ASSERT(reporter, 7 == clipBounds.fTop); 1324 REPORTER_ASSERT(reporter, 7 == clipBounds.fTop);
1327 REPORTER_ASSERT(reporter, 8 == clipBounds.fBottom); 1325 REPORTER_ASSERT(reporter, 8 == clipBounds.fBottom);
1328 REPORTER_ASSERT(reporter, 8 == clipBounds.fRight); 1326 REPORTER_ASSERT(reporter, 8 == clipBounds.fRight);
1329 } 1327 }
1330 { 1328 {
1331 SkCanvas* canvas = recorder.beginRecording(10, 10, NULL, 1329 SkCanvas* canvas = recorder.beginRecording(10, 10);
1332 SkPicture::kUsePathBoundsForClip_RecordingFlag);
1333 canvas->clipPath(path, SkRegion::kIntersect_Op); 1330 canvas->clipPath(path, SkRegion::kIntersect_Op);
1334 canvas->clipPath(invPath, SkRegion::kUnion_Op); 1331 canvas->clipPath(invPath, SkRegion::kUnion_Op);
1335 bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); 1332 bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds);
1336 REPORTER_ASSERT(reporter, true == nonEmpty); 1333 REPORTER_ASSERT(reporter, true == nonEmpty);
1337 REPORTER_ASSERT(reporter, 0 == clipBounds.fLeft); 1334 REPORTER_ASSERT(reporter, 0 == clipBounds.fLeft);
1338 REPORTER_ASSERT(reporter, 0 == clipBounds.fTop); 1335 REPORTER_ASSERT(reporter, 0 == clipBounds.fTop);
1339 REPORTER_ASSERT(reporter, 10 == clipBounds.fBottom); 1336 REPORTER_ASSERT(reporter, 10 == clipBounds.fBottom);
1340 REPORTER_ASSERT(reporter, 10 == clipBounds.fRight); 1337 REPORTER_ASSERT(reporter, 10 == clipBounds.fRight);
1341 } 1338 }
1342 { 1339 {
1343 SkCanvas* canvas = recorder.beginRecording(10, 10, NULL, 1340 SkCanvas* canvas = recorder.beginRecording(10, 10);
1344 SkPicture::kUsePathBoundsForClip_RecordingFlag);
1345 canvas->clipPath(path, SkRegion::kDifference_Op); 1341 canvas->clipPath(path, SkRegion::kDifference_Op);
1346 bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); 1342 bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds);
1347 REPORTER_ASSERT(reporter, true == nonEmpty); 1343 REPORTER_ASSERT(reporter, true == nonEmpty);
1348 REPORTER_ASSERT(reporter, 0 == clipBounds.fLeft); 1344 REPORTER_ASSERT(reporter, 0 == clipBounds.fLeft);
1349 REPORTER_ASSERT(reporter, 0 == clipBounds.fTop); 1345 REPORTER_ASSERT(reporter, 0 == clipBounds.fTop);
1350 REPORTER_ASSERT(reporter, 10 == clipBounds.fBottom); 1346 REPORTER_ASSERT(reporter, 10 == clipBounds.fBottom);
1351 REPORTER_ASSERT(reporter, 10 == clipBounds.fRight); 1347 REPORTER_ASSERT(reporter, 10 == clipBounds.fRight);
1352 } 1348 }
1353 { 1349 {
1354 SkCanvas* canvas = recorder.beginRecording(10, 10, NULL, 1350 SkCanvas* canvas = recorder.beginRecording(10, 10);
1355 SkPicture::kUsePathBoundsForClip_RecordingFlag);
1356 canvas->clipPath(path, SkRegion::kReverseDifference_Op); 1351 canvas->clipPath(path, SkRegion::kReverseDifference_Op);
1357 bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); 1352 bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds);
1358 // True clip is actually empty in this case, but the best 1353 // True clip is actually empty in this case, but the best
1359 // determination we can make using only bounds as input is that the 1354 // determination we can make using only bounds as input is that the
1360 // clip is included in the bounds of 'path'. 1355 // clip is included in the bounds of 'path'.
1361 REPORTER_ASSERT(reporter, true == nonEmpty); 1356 REPORTER_ASSERT(reporter, true == nonEmpty);
1362 REPORTER_ASSERT(reporter, 7 == clipBounds.fLeft); 1357 REPORTER_ASSERT(reporter, 7 == clipBounds.fLeft);
1363 REPORTER_ASSERT(reporter, 7 == clipBounds.fTop); 1358 REPORTER_ASSERT(reporter, 7 == clipBounds.fTop);
1364 REPORTER_ASSERT(reporter, 8 == clipBounds.fBottom); 1359 REPORTER_ASSERT(reporter, 8 == clipBounds.fBottom);
1365 REPORTER_ASSERT(reporter, 8 == clipBounds.fRight); 1360 REPORTER_ASSERT(reporter, 8 == clipBounds.fRight);
1366 } 1361 }
1367 { 1362 {
1368 SkCanvas* canvas = recorder.beginRecording(10, 10, NULL, 1363 SkCanvas* canvas = recorder.beginRecording(10, 10);
1369 SkPicture::kUsePathBoundsForClip_RecordingFlag);
1370 canvas->clipPath(path, SkRegion::kIntersect_Op); 1364 canvas->clipPath(path, SkRegion::kIntersect_Op);
1371 canvas->clipPath(path2, SkRegion::kXOR_Op); 1365 canvas->clipPath(path2, SkRegion::kXOR_Op);
1372 bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); 1366 bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds);
1373 REPORTER_ASSERT(reporter, true == nonEmpty); 1367 REPORTER_ASSERT(reporter, true == nonEmpty);
1374 REPORTER_ASSERT(reporter, 6 == clipBounds.fLeft); 1368 REPORTER_ASSERT(reporter, 6 == clipBounds.fLeft);
1375 REPORTER_ASSERT(reporter, 6 == clipBounds.fTop); 1369 REPORTER_ASSERT(reporter, 6 == clipBounds.fTop);
1376 REPORTER_ASSERT(reporter, 8 == clipBounds.fBottom); 1370 REPORTER_ASSERT(reporter, 8 == clipBounds.fBottom);
1377 REPORTER_ASSERT(reporter, 8 == clipBounds.fRight); 1371 REPORTER_ASSERT(reporter, 8 == clipBounds.fRight);
1378 } 1372 }
1379 } 1373 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1417 unsigned getClipCount() const { return fClipCount; } 1411 unsigned getClipCount() const { return fClipCount; }
1418 1412
1419 private: 1413 private:
1420 unsigned fClipCount; 1414 unsigned fClipCount;
1421 1415
1422 typedef SkCanvas INHERITED; 1416 typedef SkCanvas INHERITED;
1423 }; 1417 };
1424 1418
1425 static void test_clip_expansion(skiatest::Reporter* reporter) { 1419 static void test_clip_expansion(skiatest::Reporter* reporter) {
1426 SkPictureRecorder recorder; 1420 SkPictureRecorder recorder;
1427 SkCanvas* canvas = recorder.beginRecording(10, 10, NULL, 0); 1421 SkCanvas* canvas = recorder.beginRecording(10, 10);
1428 1422
1429 canvas->clipRect(SkRect::MakeEmpty(), SkRegion::kReplace_Op); 1423 canvas->clipRect(SkRect::MakeEmpty(), SkRegion::kReplace_Op);
1430 // The following expanding clip should not be skipped. 1424 // The following expanding clip should not be skipped.
1431 canvas->clipRect(SkRect::MakeXYWH(4, 4, 3, 3), SkRegion::kUnion_Op); 1425 canvas->clipRect(SkRect::MakeXYWH(4, 4, 3, 3), SkRegion::kUnion_Op);
1432 // Draw something so the optimizer doesn't just fold the world. 1426 // Draw something so the optimizer doesn't just fold the world.
1433 SkPaint p; 1427 SkPaint p;
1434 p.setColor(SK_ColorBLUE); 1428 p.setColor(SK_ColorBLUE);
1435 canvas->drawPaint(p); 1429 canvas->drawPaint(p);
1436 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); 1430 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
1437 1431
1438 ClipCountingCanvas testCanvas(10, 10); 1432 ClipCountingCanvas testCanvas(10, 10);
1439 picture->draw(&testCanvas); 1433 picture->draw(&testCanvas);
1440 1434
1441 // Both clips should be present on playback. 1435 // Both clips should be present on playback.
1442 REPORTER_ASSERT(reporter, testCanvas.getClipCount() == 2); 1436 REPORTER_ASSERT(reporter, testCanvas.getClipCount() == 2);
1443 } 1437 }
1444 1438
1445 static void test_hierarchical(skiatest::Reporter* reporter) { 1439 static void test_hierarchical(skiatest::Reporter* reporter) {
1446 SkBitmap bm; 1440 SkBitmap bm;
1447 make_bm(&bm, 10, 10, SK_ColorRED, true); 1441 make_bm(&bm, 10, 10, SK_ColorRED, true);
1448 1442
1449 SkPictureRecorder recorder; 1443 SkPictureRecorder recorder;
1450 1444
1451 recorder.beginRecording(10, 10, NULL, 0); 1445 recorder.beginRecording(10, 10);
1452 SkAutoTUnref<SkPicture> childPlain(recorder.endRecording()); 1446 SkAutoTUnref<SkPicture> childPlain(recorder.endRecording());
1453 REPORTER_ASSERT(reporter, !childPlain->willPlayBackBitmaps()); // 0 1447 REPORTER_ASSERT(reporter, !childPlain->willPlayBackBitmaps()); // 0
1454 1448
1455 recorder.beginRecording(10, 10, NULL, 0)->drawBitmap(bm, 0, 0); 1449 recorder.beginRecording(10, 10)->drawBitmap(bm, 0, 0);
1456 SkAutoTUnref<SkPicture> childWithBitmap(recorder.endRecording()); 1450 SkAutoTUnref<SkPicture> childWithBitmap(recorder.endRecording());
1457 REPORTER_ASSERT(reporter, childWithBitmap->willPlayBackBitmaps()); // 1 1451 REPORTER_ASSERT(reporter, childWithBitmap->willPlayBackBitmaps()); // 1
1458 1452
1459 { 1453 {
1460 SkCanvas* canvas = recorder.beginRecording(10, 10, NULL, 0); 1454 SkCanvas* canvas = recorder.beginRecording(10, 10);
1461 canvas->drawPicture(childPlain); 1455 canvas->drawPicture(childPlain);
1462 SkAutoTUnref<SkPicture> parentPP(recorder.endRecording()); 1456 SkAutoTUnref<SkPicture> parentPP(recorder.endRecording());
1463 REPORTER_ASSERT(reporter, !parentPP->willPlayBackBitmaps()); // 0 1457 REPORTER_ASSERT(reporter, !parentPP->willPlayBackBitmaps()); // 0
1464 } 1458 }
1465 { 1459 {
1466 SkCanvas* canvas = recorder.beginRecording(10, 10, NULL, 0); 1460 SkCanvas* canvas = recorder.beginRecording(10, 10);
1467 canvas->drawPicture(childWithBitmap); 1461 canvas->drawPicture(childWithBitmap);
1468 SkAutoTUnref<SkPicture> parentPWB(recorder.endRecording()); 1462 SkAutoTUnref<SkPicture> parentPWB(recorder.endRecording());
1469 REPORTER_ASSERT(reporter, parentPWB->willPlayBackBitmaps()); // 1 1463 REPORTER_ASSERT(reporter, parentPWB->willPlayBackBitmaps()); // 1
1470 } 1464 }
1471 { 1465 {
1472 SkCanvas* canvas = recorder.beginRecording(10, 10, NULL, 0); 1466 SkCanvas* canvas = recorder.beginRecording(10, 10);
1473 canvas->drawBitmap(bm, 0, 0); 1467 canvas->drawBitmap(bm, 0, 0);
1474 canvas->drawPicture(childPlain); 1468 canvas->drawPicture(childPlain);
1475 SkAutoTUnref<SkPicture> parentWBP(recorder.endRecording()); 1469 SkAutoTUnref<SkPicture> parentWBP(recorder.endRecording());
1476 REPORTER_ASSERT(reporter, parentWBP->willPlayBackBitmaps()); // 1 1470 REPORTER_ASSERT(reporter, parentWBP->willPlayBackBitmaps()); // 1
1477 } 1471 }
1478 { 1472 {
1479 SkCanvas* canvas = recorder.beginRecording(10, 10, NULL, 0); 1473 SkCanvas* canvas = recorder.beginRecording(10, 10);
1480 canvas->drawBitmap(bm, 0, 0); 1474 canvas->drawBitmap(bm, 0, 0);
1481 canvas->drawPicture(childWithBitmap); 1475 canvas->drawPicture(childWithBitmap);
1482 SkAutoTUnref<SkPicture> parentWBWB(recorder.endRecording()); 1476 SkAutoTUnref<SkPicture> parentWBWB(recorder.endRecording());
1483 REPORTER_ASSERT(reporter, parentWBWB->willPlayBackBitmaps()); // 2 1477 REPORTER_ASSERT(reporter, parentWBWB->willPlayBackBitmaps()); // 2
1484 } 1478 }
1485 } 1479 }
1486 1480
1487 static void test_gen_id(skiatest::Reporter* reporter) { 1481 static void test_gen_id(skiatest::Reporter* reporter) {
1488 1482
1489 SkPicture empty; 1483 SkPicture empty;
1490 1484
1491 // Empty pictures should still have a valid ID 1485 // Empty pictures should still have a valid ID
1492 REPORTER_ASSERT(reporter, empty.uniqueID() != SK_InvalidGenID); 1486 REPORTER_ASSERT(reporter, empty.uniqueID() != SK_InvalidGenID);
1493 1487
1494 SkPictureRecorder recorder; 1488 SkPictureRecorder recorder;
1495 1489
1496 SkCanvas* canvas = recorder.beginRecording(1, 1, NULL, 0); 1490 SkCanvas* canvas = recorder.beginRecording(1, 1);
1497 canvas->drawARGB(255, 255, 255, 255); 1491 canvas->drawARGB(255, 255, 255, 255);
1498 SkAutoTUnref<SkPicture> hasData(recorder.endRecording()); 1492 SkAutoTUnref<SkPicture> hasData(recorder.endRecording());
1499 // picture should have a non-zero id after recording 1493 // picture should have a non-zero id after recording
1500 REPORTER_ASSERT(reporter, hasData->uniqueID() != SK_InvalidGenID); 1494 REPORTER_ASSERT(reporter, hasData->uniqueID() != SK_InvalidGenID);
1501 1495
1502 // both pictures should have different ids 1496 // both pictures should have different ids
1503 REPORTER_ASSERT(reporter, hasData->uniqueID() != empty.uniqueID()); 1497 REPORTER_ASSERT(reporter, hasData->uniqueID() != empty.uniqueID());
1504 1498
1505 // test out copy constructor 1499 // test out copy constructor
1506 SkPicture copyWithData(*hasData); 1500 SkPicture copyWithData(*hasData);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1573 1567
1574 static void test_draw_bitmaps(SkCanvas* canvas) { 1568 static void test_draw_bitmaps(SkCanvas* canvas) {
1575 SkBitmap empty; 1569 SkBitmap empty;
1576 draw_bitmaps(empty, canvas); 1570 draw_bitmaps(empty, canvas);
1577 empty.setInfo(SkImageInfo::MakeN32Premul(10, 10)); 1571 empty.setInfo(SkImageInfo::MakeN32Premul(10, 10));
1578 draw_bitmaps(empty, canvas); 1572 draw_bitmaps(empty, canvas);
1579 } 1573 }
1580 1574
1581 DEF_TEST(Picture_EmptyBitmap, r) { 1575 DEF_TEST(Picture_EmptyBitmap, r) {
1582 SkPictureRecorder recorder; 1576 SkPictureRecorder recorder;
1583 test_draw_bitmaps(recorder.beginRecording(10, 10, NULL, 0)); 1577 test_draw_bitmaps(recorder.beginRecording(10, 10));
1584 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); 1578 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
1585 } 1579 }
1586 1580
1587 DEF_TEST(Canvas_EmptyBitmap, r) { 1581 DEF_TEST(Canvas_EmptyBitmap, r) {
1588 SkBitmap dst; 1582 SkBitmap dst;
1589 dst.allocN32Pixels(10, 10); 1583 dst.allocN32Pixels(10, 10);
1590 SkCanvas canvas(dst); 1584 SkCanvas canvas(dst);
1591 1585
1592 test_draw_bitmaps(&canvas); 1586 test_draw_bitmaps(&canvas);
1593 } 1587 }
OLDNEW
« no previous file with comments | « src/core/SkPictureRecord.cpp ('k') | tools/PictureRenderer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698