| 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 1085 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1096 { | 1096 { |
| 1097 SkCanvas* canvas = recorder.beginRecording(100, 100, NULL, 0); | 1097 SkCanvas* canvas = recorder.beginRecording(100, 100, NULL, 0); |
| 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 | |
| 1107 #if defined(SK_SUPPORT_LEGACY_PICTURE_CAN_RECORD) && \ | |
| 1108 defined(SK_SUPPORT_LEGACY_DERIVED_PICTURE_CLASSES) | |
| 1109 set_canvas_to_save_count_4(&testCanvas); | |
| 1110 | |
| 1111 // Due to "fake" endRecording, the old SkPicture recording interface | |
| 1112 // allowed unbalanced saves/restores to leak out. This sub-test checks | |
| 1113 // that the situation has been remedied. | |
| 1114 { | |
| 1115 SkPicture p; | |
| 1116 | |
| 1117 SkCanvas* canvas = p.beginRecording(100, 100); | |
| 1118 for (int i = 0; i < 4; ++i) { | |
| 1119 canvas->save(); | |
| 1120 } | |
| 1121 SkRect r = SkRect::MakeWH(50, 50); | |
| 1122 SkPaint paint; | |
| 1123 canvas->drawRect(r, paint); | |
| 1124 | |
| 1125 // Check that copying a mid-recording picture does not result in unbalan
ced saves/restores | |
| 1126 SkPicture p2(p); | |
| 1127 | |
| 1128 testCanvas.drawPicture(p2); | |
| 1129 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); | |
| 1130 set_canvas_to_save_count_4(&testCanvas); | |
| 1131 | |
| 1132 // Check that cloning a mid-recording picture does not result in unbalan
ced saves/restores | |
| 1133 SkAutoTUnref<SkPicture> p3(p.clone()); | |
| 1134 testCanvas.drawPicture(*p3); | |
| 1135 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); | |
| 1136 set_canvas_to_save_count_4(&testCanvas); | |
| 1137 | |
| 1138 // Check that serializing a mid-recording picture doesn't result in unba
lanced | |
| 1139 // saves/restores | |
| 1140 SkDynamicMemoryWStream wStream; | |
| 1141 p.serialize(&wStream); | |
| 1142 SkAutoDataUnref data(wStream.copyToData()); | |
| 1143 SkMemoryStream stream(data); | |
| 1144 SkAutoTUnref<SkPicture> p4(SkPicture::CreateFromStream(&stream, NULL)); | |
| 1145 testCanvas.drawPicture(*p4); | |
| 1146 REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount()); | |
| 1147 } | |
| 1148 #endif | |
| 1149 } | 1106 } |
| 1150 | 1107 |
| 1151 static void test_peephole() { | 1108 static void test_peephole() { |
| 1152 SkRandom rand; | 1109 SkRandom rand; |
| 1153 | 1110 |
| 1154 SkPictureRecorder recorder; | 1111 SkPictureRecorder recorder; |
| 1155 | 1112 |
| 1156 for (int j = 0; j < 100; j++) { | 1113 for (int j = 0; j < 100; j++) { |
| 1157 SkRandom rand2(rand); // remember the seed | 1114 SkRandom rand2(rand); // remember the seed |
| 1158 | 1115 |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1629 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 1586 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
| 1630 } | 1587 } |
| 1631 | 1588 |
| 1632 DEF_TEST(Canvas_EmptyBitmap, r) { | 1589 DEF_TEST(Canvas_EmptyBitmap, r) { |
| 1633 SkBitmap dst; | 1590 SkBitmap dst; |
| 1634 dst.allocN32Pixels(10, 10); | 1591 dst.allocN32Pixels(10, 10); |
| 1635 SkCanvas canvas(dst); | 1592 SkCanvas canvas(dst); |
| 1636 | 1593 |
| 1637 test_draw_bitmaps(&canvas); | 1594 test_draw_bitmaps(&canvas); |
| 1638 } | 1595 } |
| OLD | NEW |