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 "SkBBoxHierarchy.h" | 8 #include "SkBBoxHierarchy.h" |
9 #include "SkBlurImageFilter.h" | 9 #include "SkBlurImageFilter.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
11 #include "SkColorMatrixFilter.h" | 11 #include "SkColorMatrixFilter.h" |
12 #include "SkColorPriv.h" | 12 #include "SkColorPriv.h" |
13 #include "SkDashPathEffect.h" | 13 #include "SkDashPathEffect.h" |
14 #include "SkData.h" | 14 #include "SkData.h" |
15 #include "SkImageGenerator.h" | 15 #include "SkImageGenerator.h" |
16 #include "SkError.h" | 16 #include "SkError.h" |
17 #include "SkImageEncoder.h" | 17 #include "SkImageEncoder.h" |
18 #include "SkImageGenerator.h" | 18 #include "SkImageGenerator.h" |
19 #include "SkLayerInfo.h" | 19 #include "SkLayerInfo.h" |
20 #include "SkPaint.h" | 20 #include "SkPaint.h" |
21 #include "SkPicture.h" | 21 #include "SkPicture.h" |
22 #include "SkPictureRecorder.h" | 22 #include "SkPictureRecorder.h" |
23 #include "SkPictureUtils.h" | 23 #include "SkPictureUtils.h" |
24 #include "SkPixelRef.h" | 24 #include "SkPixelRef.h" |
25 #include "SkPixelSerializer.h" | 25 #include "SkPixelSerializer.h" |
26 #include "SkMiniRecorder.h" | |
27 #include "SkRRect.h" | 26 #include "SkRRect.h" |
28 #include "SkRandom.h" | 27 #include "SkRandom.h" |
29 #include "SkRecord.h" | 28 #include "SkRecord.h" |
30 #include "SkShader.h" | 29 #include "SkShader.h" |
31 #include "SkStream.h" | 30 #include "SkStream.h" |
32 #include "sk_tool_utils.h" | 31 #include "sk_tool_utils.h" |
33 | 32 |
34 #if SK_SUPPORT_GPU | 33 #if SK_SUPPORT_GPU |
35 #include "SkSurface.h" | 34 #include "SkSurface.h" |
36 #include "GrContextFactory.h" | 35 #include "GrContextFactory.h" |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 c->saveLayer(NULL, &layerPaint); // layer #6 | 356 c->saveLayer(NULL, &layerPaint); // layer #6 |
358 c->drawPicture(child, &trans, &picturePaint); // layer #7 inside
picture | 357 c->drawPicture(child, &trans, &picturePaint); // layer #7 inside
picture |
359 c->restore(); | 358 c->restore(); |
360 } | 359 } |
361 | 360 |
362 pict.reset(recorder.endRecording()); | 361 pict.reset(recorder.endRecording()); |
363 } | 362 } |
364 | 363 |
365 // Now test out the SaveLayer extraction | 364 // Now test out the SaveLayer extraction |
366 if (!SkCanvas::Internal_Private_GetIgnoreSaveLayerBounds()) { | 365 if (!SkCanvas::Internal_Private_GetIgnoreSaveLayerBounds()) { |
367 const SkBigPicture* bp = pict->asSkBigPicture(); | 366 SkPicture::AccelData::Key key = SkLayerInfo::ComputeKey(); |
368 REPORTER_ASSERT(reporter, bp); | |
369 | 367 |
370 const SkBigPicture::AccelData* data = bp->accelData(); | 368 const SkPicture::AccelData* data = pict->EXPERIMENTAL_getAccelData(key); |
371 REPORTER_ASSERT(reporter, data); | 369 REPORTER_ASSERT(reporter, data); |
372 | 370 |
373 const SkLayerInfo *gpuData = static_cast<const SkLayerInfo*>(data); | 371 const SkLayerInfo *gpuData = static_cast<const SkLayerInfo*>(data); |
374 REPORTER_ASSERT(reporter, 8 == gpuData->numBlocks()); | 372 REPORTER_ASSERT(reporter, 8 == gpuData->numBlocks()); |
375 | 373 |
376 const SkLayerInfo::BlockInfo& info0 = gpuData->block(0); | 374 const SkLayerInfo::BlockInfo& info0 = gpuData->block(0); |
377 // The parent/child layers appear in reverse order | 375 // The parent/child layers appear in reverse order |
378 const SkLayerInfo::BlockInfo& info1 = gpuData->block(2); | 376 const SkLayerInfo::BlockInfo& info1 = gpuData->block(2); |
379 const SkLayerInfo::BlockInfo& info2 = gpuData->block(1); | 377 const SkLayerInfo::BlockInfo& info2 = gpuData->block(1); |
380 | 378 |
(...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1102 SkCanvas* canvas = recorder.beginRecording(1, 1); | 1100 SkCanvas* canvas = recorder.beginRecording(1, 1); |
1103 canvas->drawARGB(255, 255, 255, 255); | 1101 canvas->drawARGB(255, 255, 255, 255); |
1104 SkAutoTUnref<SkPicture> hasData(recorder.endRecording()); | 1102 SkAutoTUnref<SkPicture> hasData(recorder.endRecording()); |
1105 // picture should have a non-zero id after recording | 1103 // picture should have a non-zero id after recording |
1106 REPORTER_ASSERT(reporter, hasData->uniqueID() != SK_InvalidGenID); | 1104 REPORTER_ASSERT(reporter, hasData->uniqueID() != SK_InvalidGenID); |
1107 | 1105 |
1108 // both pictures should have different ids | 1106 // both pictures should have different ids |
1109 REPORTER_ASSERT(reporter, hasData->uniqueID() != empty->uniqueID()); | 1107 REPORTER_ASSERT(reporter, hasData->uniqueID() != empty->uniqueID()); |
1110 } | 1108 } |
1111 | 1109 |
| 1110 static void test_bytes_used(skiatest::Reporter* reporter) { |
| 1111 SkPictureRecorder recorder; |
| 1112 |
| 1113 recorder.beginRecording(0, 0); |
| 1114 SkAutoTUnref<SkPicture> empty(recorder.endRecording()); |
| 1115 |
| 1116 // Sanity check to make sure we aren't under-measuring. |
| 1117 REPORTER_ASSERT(reporter, SkPictureUtils::ApproximateBytesUsed(empty.get())
>= |
| 1118 sizeof(SkPicture) + sizeof(SkRecord)); |
| 1119 |
| 1120 // Protect against any unintentional bloat. |
| 1121 size_t approxUsed = SkPictureUtils::ApproximateBytesUsed(empty.get()); |
| 1122 REPORTER_ASSERT(reporter, approxUsed <= 432); |
| 1123 |
| 1124 // Sanity check of nested SkPictures. |
| 1125 SkPictureRecorder r2; |
| 1126 r2.beginRecording(0, 0); |
| 1127 r2.getRecordingCanvas()->drawPicture(empty.get()); |
| 1128 SkAutoTUnref<SkPicture> nested(r2.endRecording()); |
| 1129 |
| 1130 REPORTER_ASSERT(reporter, SkPictureUtils::ApproximateBytesUsed(nested.get())
>= |
| 1131 SkPictureUtils::ApproximateBytesUsed(empty.get()))
; |
| 1132 } |
| 1133 |
1112 DEF_TEST(Picture, reporter) { | 1134 DEF_TEST(Picture, reporter) { |
1113 #ifdef SK_DEBUG | 1135 #ifdef SK_DEBUG |
1114 test_deleting_empty_picture(); | 1136 test_deleting_empty_picture(); |
1115 test_serializing_empty_picture(); | 1137 test_serializing_empty_picture(); |
1116 #else | 1138 #else |
1117 test_bad_bitmap(); | 1139 test_bad_bitmap(); |
1118 #endif | 1140 #endif |
1119 test_unbalanced_save_restores(reporter); | 1141 test_unbalanced_save_restores(reporter); |
1120 test_peephole(); | 1142 test_peephole(); |
1121 #if SK_SUPPORT_GPU | 1143 #if SK_SUPPORT_GPU |
1122 test_gpu_veto(reporter); | 1144 test_gpu_veto(reporter); |
1123 #endif | 1145 #endif |
1124 test_has_text(reporter); | 1146 test_has_text(reporter); |
1125 test_analysis(reporter); | 1147 test_analysis(reporter); |
1126 test_bitmap_with_encoded_data(reporter); | 1148 test_bitmap_with_encoded_data(reporter); |
1127 test_clip_bound_opt(reporter); | 1149 test_clip_bound_opt(reporter); |
1128 test_clip_expansion(reporter); | 1150 test_clip_expansion(reporter); |
1129 test_hierarchical(reporter); | 1151 test_hierarchical(reporter); |
1130 test_gen_id(reporter); | 1152 test_gen_id(reporter); |
1131 test_savelayer_extraction(reporter); | 1153 test_savelayer_extraction(reporter); |
| 1154 test_bytes_used(reporter); |
1132 } | 1155 } |
1133 | 1156 |
1134 static void draw_bitmaps(const SkBitmap bitmap, SkCanvas* canvas) { | 1157 static void draw_bitmaps(const SkBitmap bitmap, SkCanvas* canvas) { |
1135 const SkPaint paint; | 1158 const SkPaint paint; |
1136 const SkRect rect = { 5.0f, 5.0f, 8.0f, 8.0f }; | 1159 const SkRect rect = { 5.0f, 5.0f, 8.0f, 8.0f }; |
1137 const SkIRect irect = { 2, 2, 3, 3 }; | 1160 const SkIRect irect = { 2, 2, 3, 3 }; |
1138 | 1161 |
1139 // Don't care what these record, as long as they're legal. | 1162 // Don't care what these record, as long as they're legal. |
1140 canvas->drawBitmap(bitmap, 0.0f, 0.0f, &paint); | 1163 canvas->drawBitmap(bitmap, 0.0f, 0.0f, &paint); |
1141 canvas->drawBitmapRectToRect(bitmap, &rect, rect, &paint, SkCanvas::kNone_Dr
awBitmapRectFlag); | 1164 canvas->drawBitmapRectToRect(bitmap, &rect, rect, &paint, SkCanvas::kNone_Dr
awBitmapRectFlag); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1237 SkBBoxHierarchy* fBBH; | 1260 SkBBoxHierarchy* fBBH; |
1238 }; | 1261 }; |
1239 | 1262 |
1240 // When the canvas clip covers the full picture, we don't need to call the BBH. | 1263 // When the canvas clip covers the full picture, we don't need to call the BBH. |
1241 DEF_TEST(Picture_SkipBBH, r) { | 1264 DEF_TEST(Picture_SkipBBH, r) { |
1242 SkRect bound = SkRect::MakeWH(320, 240); | 1265 SkRect bound = SkRect::MakeWH(320, 240); |
1243 CountingBBH bbh(bound); | 1266 CountingBBH bbh(bound); |
1244 SpoonFedBBHFactory factory(&bbh); | 1267 SpoonFedBBHFactory factory(&bbh); |
1245 | 1268 |
1246 SkPictureRecorder recorder; | 1269 SkPictureRecorder recorder; |
1247 SkCanvas* c = recorder.beginRecording(bound, &factory); | 1270 recorder.beginRecording(bound, &factory); |
1248 // Record a few ops so we don't hit a small- or empty- picture optimization. | |
1249 c->drawRect(bound, SkPaint()); | |
1250 c->drawRect(bound, SkPaint()); | |
1251 SkAutoTUnref<const SkPicture> picture(recorder.endRecording()); | 1271 SkAutoTUnref<const SkPicture> picture(recorder.endRecording()); |
1252 | 1272 |
1253 SkCanvas big(640, 480), small(300, 200); | 1273 SkCanvas big(640, 480), small(300, 200); |
1254 | 1274 |
1255 picture->playback(&big); | 1275 picture->playback(&big); |
1256 REPORTER_ASSERT(r, bbh.searchCalls == 0); | 1276 REPORTER_ASSERT(r, bbh.searchCalls == 0); |
1257 | 1277 |
1258 picture->playback(&small); | 1278 picture->playback(&small); |
1259 REPORTER_ASSERT(r, bbh.searchCalls == 1); | 1279 REPORTER_ASSERT(r, bbh.searchCalls == 1); |
1260 } | 1280 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1296 DEF_TEST(Picture_getRecordingCanvas, r) { | 1316 DEF_TEST(Picture_getRecordingCanvas, r) { |
1297 SkPictureRecorder rec; | 1317 SkPictureRecorder rec; |
1298 REPORTER_ASSERT(r, !rec.getRecordingCanvas()); | 1318 REPORTER_ASSERT(r, !rec.getRecordingCanvas()); |
1299 for (int i = 0; i < 3; i++) { | 1319 for (int i = 0; i < 3; i++) { |
1300 rec.beginRecording(100, 100); | 1320 rec.beginRecording(100, 100); |
1301 REPORTER_ASSERT(r, rec.getRecordingCanvas()); | 1321 REPORTER_ASSERT(r, rec.getRecordingCanvas()); |
1302 rec.endRecording()->unref(); | 1322 rec.endRecording()->unref(); |
1303 REPORTER_ASSERT(r, !rec.getRecordingCanvas()); | 1323 REPORTER_ASSERT(r, !rec.getRecordingCanvas()); |
1304 } | 1324 } |
1305 } | 1325 } |
1306 | |
1307 DEF_TEST(MiniRecorderLeftHanging, r) { | |
1308 // Any shader or other ref-counted effect will do just fine here. | |
1309 SkPaint paint; | |
1310 paint.setShader(SkShader::CreateColorShader(SK_ColorRED))->unref(); | |
1311 | |
1312 SkMiniRecorder rec; | |
1313 REPORTER_ASSERT(r, rec.drawRect(SkRect::MakeWH(20,30), paint)); | |
1314 // Don't call rec.detachPicture(). Test succeeds by not asserting or leakin
g the shader. | |
1315 } | |
OLD | NEW |