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

Side by Side Diff: tests/PictureTest.cpp

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