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 957 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
968 { | 968 { |
969 SkCanvas* canvas = recorder.beginRecording(100, 100, NULL, 0); | 969 SkCanvas* canvas = recorder.beginRecording(100, 100, NULL, 0); |
970 canvas->translate(10, 10); | 970 canvas->translate(10, 10); |
971 canvas->drawRect(rect, paint); | 971 canvas->drawRect(rect, paint); |
972 SkAutoTUnref<SkPicture> noSavePicture(recorder.endRecording()); | 972 SkAutoTUnref<SkPicture> noSavePicture(recorder.endRecording()); |
973 | 973 |
974 testCanvas.drawPicture(*noSavePicture); | 974 testCanvas.drawPicture(*noSavePicture); |
975 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); | 975 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); |
976 REPORTER_ASSERT(reporter, testCanvas.getTotalMatrix().isIdentity()); | 976 REPORTER_ASSERT(reporter, testCanvas.getTotalMatrix().isIdentity()); |
977 } | 977 } |
| 978 |
| 979 #if defined(SK_SUPPORT_LEGACY_PICTURE_CAN_RECORD) && \ |
| 980 defined(SK_SUPPORT_LEGACY_DERIVED_PICTURE_CLASSES) |
| 981 set_canvas_to_save_count_4(&testCanvas); |
| 982 |
| 983 // Due to "fake" endRecording, the old SkPicture recording interface |
| 984 // allowed unbalanced saves/restores to leak out. This sub-test checks |
| 985 // that the situation has been remedied. |
| 986 { |
| 987 SkPicture p; |
| 988 |
| 989 SkCanvas* canvas = p.beginRecording(100, 100); |
| 990 for (int i = 0; i < 4; ++i) { |
| 991 canvas->save(); |
| 992 } |
| 993 SkRect r = SkRect::MakeWH(50, 50); |
| 994 SkPaint paint; |
| 995 canvas->drawRect(r, paint); |
| 996 |
| 997 // Copying a mid-recording picture could result in unbalanced saves/rest
ores |
| 998 SkPicture p2(p); |
| 999 |
| 1000 testCanvas.drawPicture(p2); |
| 1001 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); |
| 1002 set_canvas_to_save_count_4(&testCanvas); |
| 1003 |
| 1004 // Cloning a mid-recording picture could result in unbalanced saves/rest
ores |
| 1005 SkAutoTUnref<SkPicture> p3(p.clone()); |
| 1006 testCanvas.drawPicture(*p3); |
| 1007 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); |
| 1008 set_canvas_to_save_count_4(&testCanvas); |
| 1009 |
| 1010 // Serializing a mid-recording picture could result in unbalanced saves/
restores |
| 1011 SkDynamicMemoryWStream wStream; |
| 1012 p.serialize(&wStream); |
| 1013 SkAutoDataUnref data(wStream.copyToData()); |
| 1014 SkMemoryStream stream(data); |
| 1015 SkAutoTUnref<SkPicture> p4(SkPicture::CreateFromStream(&stream, NULL)); |
| 1016 testCanvas.drawPicture(*p4); |
| 1017 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); |
| 1018 } |
| 1019 #endif |
978 } | 1020 } |
979 | 1021 |
980 static void test_peephole() { | 1022 static void test_peephole() { |
981 SkRandom rand; | 1023 SkRandom rand; |
982 | 1024 |
983 SkPictureRecorder recorder; | 1025 SkPictureRecorder recorder; |
984 | 1026 |
985 for (int j = 0; j < 100; j++) { | 1027 for (int j = 0; j < 100; j++) { |
986 SkRandom rand2(rand); // remember the seed | 1028 SkRandom rand2(rand); // remember the seed |
987 | 1029 |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1458 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 1500 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
1459 } | 1501 } |
1460 | 1502 |
1461 DEF_TEST(Canvas_EmptyBitmap, r) { | 1503 DEF_TEST(Canvas_EmptyBitmap, r) { |
1462 SkBitmap dst; | 1504 SkBitmap dst; |
1463 dst.allocN32Pixels(10, 10); | 1505 dst.allocN32Pixels(10, 10); |
1464 SkCanvas canvas(dst); | 1506 SkCanvas canvas(dst); |
1465 | 1507 |
1466 test_draw_bitmaps(&canvas); | 1508 test_draw_bitmaps(&canvas); |
1467 } | 1509 } |
OLD | NEW |