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 "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
694 } | 694 } |
695 } | 695 } |
696 | 696 |
697 static void set_canvas_to_save_count_4(SkCanvas* canvas) { | 697 static void set_canvas_to_save_count_4(SkCanvas* canvas) { |
698 canvas->restoreToCount(1); | 698 canvas->restoreToCount(1); |
699 canvas->save(); | 699 canvas->save(); |
700 canvas->save(); | 700 canvas->save(); |
701 canvas->save(); | 701 canvas->save(); |
702 } | 702 } |
703 | 703 |
| 704 // Test out SkPictureRecorder::snapshot |
| 705 static void test_snapshot(skiatest::Reporter* reporter) { |
| 706 SkPictureRecorder recorder; |
| 707 |
| 708 // Calling snapshot when not recording will return NULL |
| 709 REPORTER_ASSERT(reporter, NULL == recorder.snapshot()); |
| 710 |
| 711 SkCanvas* canvas = recorder.beginRecording(10, 10, NULL, 0); |
| 712 |
| 713 SkRect r = SkRect::MakeWH(5, 5); |
| 714 SkPaint p; |
| 715 |
| 716 canvas->drawRect(r, p); |
| 717 |
| 718 SkAutoTUnref<SkPicture> snapshot(recorder.snapshot()); |
| 719 REPORTER_ASSERT(reporter, !snapshot->willPlayBackBitmaps()); |
| 720 |
| 721 SkBitmap bm; |
| 722 make_bm(&bm, 10, 10, SK_ColorRED, true); |
| 723 |
| 724 r.offset(5.0f, 5.0f); |
| 725 canvas->drawBitmapRectToRect(bm, NULL, r); |
| 726 |
| 727 SkAutoTUnref<SkPicture> final(recorder.endRecording()); |
| 728 REPORTER_ASSERT(reporter, final->willPlayBackBitmaps()); |
| 729 |
| 730 REPORTER_ASSERT(reporter, snapshot->uniqueID() != final->uniqueID()); |
| 731 |
| 732 // The snapshot shouldn't pick up any operations added after it was made |
| 733 REPORTER_ASSERT(reporter, !snapshot->willPlayBackBitmaps()); |
| 734 } |
| 735 |
704 static void test_unbalanced_save_restores(skiatest::Reporter* reporter) { | 736 static void test_unbalanced_save_restores(skiatest::Reporter* reporter) { |
705 SkCanvas testCanvas(100, 100); | 737 SkCanvas testCanvas(100, 100); |
706 set_canvas_to_save_count_4(&testCanvas); | 738 set_canvas_to_save_count_4(&testCanvas); |
707 | 739 |
708 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); | 740 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); |
709 | 741 |
710 SkPaint paint; | 742 SkPaint paint; |
711 SkRect rect = SkRect::MakeLTRB(-10000000, -10000000, 10000000, 10000000); | 743 SkRect rect = SkRect::MakeLTRB(-10000000, -10000000, 10000000, 10000000); |
712 | 744 |
713 SkPictureRecorder recorder; | 745 SkPictureRecorder recorder; |
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1188 } | 1220 } |
1189 } | 1221 } |
1190 | 1222 |
1191 DEF_TEST(Picture, reporter) { | 1223 DEF_TEST(Picture, reporter) { |
1192 #ifdef SK_DEBUG | 1224 #ifdef SK_DEBUG |
1193 test_deleting_empty_playback(); | 1225 test_deleting_empty_playback(); |
1194 test_serializing_empty_picture(); | 1226 test_serializing_empty_picture(); |
1195 #else | 1227 #else |
1196 test_bad_bitmap(); | 1228 test_bad_bitmap(); |
1197 #endif | 1229 #endif |
| 1230 test_snapshot(reporter); |
1198 test_unbalanced_save_restores(reporter); | 1231 test_unbalanced_save_restores(reporter); |
1199 test_peephole(); | 1232 test_peephole(); |
1200 test_gatherpixelrefs(reporter); | 1233 test_gatherpixelrefs(reporter); |
1201 test_gatherpixelrefsandrects(reporter); | 1234 test_gatherpixelrefsandrects(reporter); |
1202 test_bitmap_with_encoded_data(reporter); | 1235 test_bitmap_with_encoded_data(reporter); |
1203 test_clone_empty(reporter); | 1236 test_clone_empty(reporter); |
1204 test_draw_empty(reporter); | 1237 test_draw_empty(reporter); |
1205 test_clip_bound_opt(reporter); | 1238 test_clip_bound_opt(reporter); |
1206 test_clip_expansion(reporter); | 1239 test_clip_expansion(reporter); |
1207 test_hierarchical(reporter); | 1240 test_hierarchical(reporter); |
(...skipping 26 matching lines...) Expand all Loading... |
1234 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 1267 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
1235 } | 1268 } |
1236 | 1269 |
1237 DEF_TEST(Canvas_EmptyBitmap, r) { | 1270 DEF_TEST(Canvas_EmptyBitmap, r) { |
1238 SkBitmap dst; | 1271 SkBitmap dst; |
1239 dst.allocN32Pixels(10, 10); | 1272 dst.allocN32Pixels(10, 10); |
1240 SkCanvas canvas(dst); | 1273 SkCanvas canvas(dst); |
1241 | 1274 |
1242 test_draw_bitmaps(&canvas); | 1275 test_draw_bitmaps(&canvas); |
1243 } | 1276 } |
OLD | NEW |