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

Side by Side Diff: tests/PictureTest.cpp

Issue 1112523006: Sketch splitting SkPicture into an interface and SkBigPicture. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: note Created 5 years, 7 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 | « tests/GpuLayerCacheTest.cpp ('k') | no next file » | 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 "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"
26 #include "SkRRect.h" 27 #include "SkRRect.h"
27 #include "SkRandom.h" 28 #include "SkRandom.h"
28 #include "SkRecord.h" 29 #include "SkRecord.h"
29 #include "SkShader.h" 30 #include "SkShader.h"
30 #include "SkStream.h" 31 #include "SkStream.h"
31 #include "sk_tool_utils.h" 32 #include "sk_tool_utils.h"
32 33
33 #if SK_SUPPORT_GPU 34 #if SK_SUPPORT_GPU
34 #include "SkSurface.h" 35 #include "SkSurface.h"
35 #include "GrContextFactory.h" 36 #include "GrContextFactory.h"
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 c->saveLayer(NULL, &layerPaint); // layer #6 357 c->saveLayer(NULL, &layerPaint); // layer #6
357 c->drawPicture(child, &trans, &picturePaint); // layer #7 inside picture 358 c->drawPicture(child, &trans, &picturePaint); // layer #7 inside picture
358 c->restore(); 359 c->restore();
359 } 360 }
360 361
361 pict.reset(recorder.endRecording()); 362 pict.reset(recorder.endRecording());
362 } 363 }
363 364
364 // Now test out the SaveLayer extraction 365 // Now test out the SaveLayer extraction
365 if (!SkCanvas::Internal_Private_GetIgnoreSaveLayerBounds()) { 366 if (!SkCanvas::Internal_Private_GetIgnoreSaveLayerBounds()) {
366 SkPicture::AccelData::Key key = SkLayerInfo::ComputeKey(); 367 const SkBigPicture* bp = pict->asSkBigPicture();
368 REPORTER_ASSERT(reporter, bp);
367 369
368 const SkPicture::AccelData* data = pict->EXPERIMENTAL_getAccelData(key); 370 const SkBigPicture::AccelData* data = bp->accelData();
369 REPORTER_ASSERT(reporter, data); 371 REPORTER_ASSERT(reporter, data);
370 372
371 const SkLayerInfo *gpuData = static_cast<const SkLayerInfo*>(data); 373 const SkLayerInfo *gpuData = static_cast<const SkLayerInfo*>(data);
372 REPORTER_ASSERT(reporter, 8 == gpuData->numBlocks()); 374 REPORTER_ASSERT(reporter, 8 == gpuData->numBlocks());
373 375
374 const SkLayerInfo::BlockInfo& info0 = gpuData->block(0); 376 const SkLayerInfo::BlockInfo& info0 = gpuData->block(0);
375 // The parent/child layers appear in reverse order 377 // The parent/child layers appear in reverse order
376 const SkLayerInfo::BlockInfo& info1 = gpuData->block(2); 378 const SkLayerInfo::BlockInfo& info1 = gpuData->block(2);
377 const SkLayerInfo::BlockInfo& info2 = gpuData->block(1); 379 const SkLayerInfo::BlockInfo& info2 = gpuData->block(1);
378 380
(...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after
1100 SkCanvas* canvas = recorder.beginRecording(1, 1); 1102 SkCanvas* canvas = recorder.beginRecording(1, 1);
1101 canvas->drawARGB(255, 255, 255, 255); 1103 canvas->drawARGB(255, 255, 255, 255);
1102 SkAutoTUnref<SkPicture> hasData(recorder.endRecording()); 1104 SkAutoTUnref<SkPicture> hasData(recorder.endRecording());
1103 // picture should have a non-zero id after recording 1105 // picture should have a non-zero id after recording
1104 REPORTER_ASSERT(reporter, hasData->uniqueID() != SK_InvalidGenID); 1106 REPORTER_ASSERT(reporter, hasData->uniqueID() != SK_InvalidGenID);
1105 1107
1106 // both pictures should have different ids 1108 // both pictures should have different ids
1107 REPORTER_ASSERT(reporter, hasData->uniqueID() != empty->uniqueID()); 1109 REPORTER_ASSERT(reporter, hasData->uniqueID() != empty->uniqueID());
1108 } 1110 }
1109 1111
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
1134 DEF_TEST(Picture, reporter) { 1112 DEF_TEST(Picture, reporter) {
1135 #ifdef SK_DEBUG 1113 #ifdef SK_DEBUG
1136 test_deleting_empty_picture(); 1114 test_deleting_empty_picture();
1137 test_serializing_empty_picture(); 1115 test_serializing_empty_picture();
1138 #else 1116 #else
1139 test_bad_bitmap(); 1117 test_bad_bitmap();
1140 #endif 1118 #endif
1141 test_unbalanced_save_restores(reporter); 1119 test_unbalanced_save_restores(reporter);
1142 test_peephole(); 1120 test_peephole();
1143 #if SK_SUPPORT_GPU 1121 #if SK_SUPPORT_GPU
1144 test_gpu_veto(reporter); 1122 test_gpu_veto(reporter);
1145 #endif 1123 #endif
1146 test_has_text(reporter); 1124 test_has_text(reporter);
1147 test_analysis(reporter); 1125 test_analysis(reporter);
1148 test_bitmap_with_encoded_data(reporter); 1126 test_bitmap_with_encoded_data(reporter);
1149 test_clip_bound_opt(reporter); 1127 test_clip_bound_opt(reporter);
1150 test_clip_expansion(reporter); 1128 test_clip_expansion(reporter);
1151 test_hierarchical(reporter); 1129 test_hierarchical(reporter);
1152 test_gen_id(reporter); 1130 test_gen_id(reporter);
1153 test_savelayer_extraction(reporter); 1131 test_savelayer_extraction(reporter);
1154 test_bytes_used(reporter);
1155 } 1132 }
1156 1133
1157 static void draw_bitmaps(const SkBitmap bitmap, SkCanvas* canvas) { 1134 static void draw_bitmaps(const SkBitmap bitmap, SkCanvas* canvas) {
1158 const SkPaint paint; 1135 const SkPaint paint;
1159 const SkRect rect = { 5.0f, 5.0f, 8.0f, 8.0f }; 1136 const SkRect rect = { 5.0f, 5.0f, 8.0f, 8.0f };
1160 const SkIRect irect = { 2, 2, 3, 3 }; 1137 const SkIRect irect = { 2, 2, 3, 3 };
1161 1138
1162 // Don't care what these record, as long as they're legal. 1139 // Don't care what these record, as long as they're legal.
1163 canvas->drawBitmap(bitmap, 0.0f, 0.0f, &paint); 1140 canvas->drawBitmap(bitmap, 0.0f, 0.0f, &paint);
1164 canvas->drawBitmapRectToRect(bitmap, &rect, rect, &paint, SkCanvas::kNone_Dr awBitmapRectFlag); 1141 canvas->drawBitmapRectToRect(bitmap, &rect, rect, &paint, SkCanvas::kNone_Dr awBitmapRectFlag);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1260 SkBBoxHierarchy* fBBH; 1237 SkBBoxHierarchy* fBBH;
1261 }; 1238 };
1262 1239
1263 // When the canvas clip covers the full picture, we don't need to call the BBH. 1240 // When the canvas clip covers the full picture, we don't need to call the BBH.
1264 DEF_TEST(Picture_SkipBBH, r) { 1241 DEF_TEST(Picture_SkipBBH, r) {
1265 SkRect bound = SkRect::MakeWH(320, 240); 1242 SkRect bound = SkRect::MakeWH(320, 240);
1266 CountingBBH bbh(bound); 1243 CountingBBH bbh(bound);
1267 SpoonFedBBHFactory factory(&bbh); 1244 SpoonFedBBHFactory factory(&bbh);
1268 1245
1269 SkPictureRecorder recorder; 1246 SkPictureRecorder recorder;
1270 recorder.beginRecording(bound, &factory); 1247 SkCanvas* c = 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());
1271 SkAutoTUnref<const SkPicture> picture(recorder.endRecording()); 1251 SkAutoTUnref<const SkPicture> picture(recorder.endRecording());
1272 1252
1273 SkCanvas big(640, 480), small(300, 200); 1253 SkCanvas big(640, 480), small(300, 200);
1274 1254
1275 picture->playback(&big); 1255 picture->playback(&big);
1276 REPORTER_ASSERT(r, bbh.searchCalls == 0); 1256 REPORTER_ASSERT(r, bbh.searchCalls == 0);
1277 1257
1278 picture->playback(&small); 1258 picture->playback(&small);
1279 REPORTER_ASSERT(r, bbh.searchCalls == 1); 1259 REPORTER_ASSERT(r, bbh.searchCalls == 1);
1280 } 1260 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1316 DEF_TEST(Picture_getRecordingCanvas, r) { 1296 DEF_TEST(Picture_getRecordingCanvas, r) {
1317 SkPictureRecorder rec; 1297 SkPictureRecorder rec;
1318 REPORTER_ASSERT(r, !rec.getRecordingCanvas()); 1298 REPORTER_ASSERT(r, !rec.getRecordingCanvas());
1319 for (int i = 0; i < 3; i++) { 1299 for (int i = 0; i < 3; i++) {
1320 rec.beginRecording(100, 100); 1300 rec.beginRecording(100, 100);
1321 REPORTER_ASSERT(r, rec.getRecordingCanvas()); 1301 REPORTER_ASSERT(r, rec.getRecordingCanvas());
1322 rec.endRecording()->unref(); 1302 rec.endRecording()->unref();
1323 REPORTER_ASSERT(r, !rec.getRecordingCanvas()); 1303 REPORTER_ASSERT(r, !rec.getRecordingCanvas());
1324 } 1304 }
1325 } 1305 }
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 }
OLDNEW
« no previous file with comments | « tests/GpuLayerCacheTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698