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

Side by Side Diff: tests/PictureTest.cpp

Issue 513983002: Try out scalar picture sizes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Clean up Created 6 years, 3 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
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 879 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 // Restore 890 // Restore
891 // 3) 891 // 3)
892 // SaveLayer w/ copyable paint 892 // SaveLayer w/ copyable paint
893 // Restore 893 // Restore
894 // 4) 894 // 4)
895 // SaveLayer w/ non-copyable paint 895 // SaveLayer w/ non-copyable paint
896 // Restore 896 // Restore
897 { 897 {
898 SkPictureRecorder recorder; 898 SkPictureRecorder recorder;
899 899
900 SkCanvas* c = recorder.DEPRECATED_beginRecording(kWidth, kHeight); 900 SkCanvas* c = recorder.DEPRECATED_beginRecording(SkIntToScalar(kWidt h),
901 SkIntToScalar(kHeig ht));
901 // 1) 902 // 1)
902 c->saveLayer(NULL, NULL); 903 c->saveLayer(NULL, NULL);
903 c->restore(); 904 c->restore();
904 905
905 // 2) 906 // 2)
906 c->saveLayer(NULL, NULL); 907 c->saveLayer(NULL, NULL);
907 c->translate(kWidth/2, kHeight/2); 908 c->translate(kWidth/2, kHeight/2);
908 SkRect r = SkRect::MakeXYWH(0, 0, kWidth/2, kHeight/2); 909 SkRect r = SkRect::MakeXYWH(0, 0, kWidth/2, kHeight/2);
909 c->saveLayer(&r, NULL); 910 c->saveLayer(&r, NULL);
910 c->restore(); 911 c->restore();
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
1111 unsigned int fSaveCount; 1112 unsigned int fSaveCount;
1112 unsigned int fSaveLayerCount; 1113 unsigned int fSaveLayerCount;
1113 unsigned int fRestoreCount; 1114 unsigned int fRestoreCount;
1114 1115
1115 typedef SkCanvas INHERITED; 1116 typedef SkCanvas INHERITED;
1116 }; 1117 };
1117 1118
1118 void check_save_state(skiatest::Reporter* reporter, SkPicture* picture, 1119 void check_save_state(skiatest::Reporter* reporter, SkPicture* picture,
1119 unsigned int numSaves, unsigned int numSaveLayers, 1120 unsigned int numSaves, unsigned int numSaveLayers,
1120 unsigned int numRestores) { 1121 unsigned int numRestores) {
1121 SaveCountingCanvas canvas(picture->width(), picture->height()); 1122 SaveCountingCanvas canvas(SkScalarCeilToInt(picture->cullRect().width()),
1123 SkScalarCeilToInt(picture->cullRect().height()));
1122 1124
1123 picture->draw(&canvas); 1125 picture->draw(&canvas);
1124 1126
1125 REPORTER_ASSERT(reporter, numSaves == canvas.getSaveCount()); 1127 REPORTER_ASSERT(reporter, numSaves == canvas.getSaveCount());
1126 REPORTER_ASSERT(reporter, numSaveLayers == canvas.getSaveLayerCount()); 1128 REPORTER_ASSERT(reporter, numSaveLayers == canvas.getSaveLayerCount());
1127 REPORTER_ASSERT(reporter, numRestores == canvas.getRestoreCount()); 1129 REPORTER_ASSERT(reporter, numRestores == canvas.getRestoreCount());
1128 } 1130 }
1129 1131
1130 // This class exists so SkPicture can friend it and give it access to 1132 // This class exists so SkPicture can friend it and give it access to
1131 // the 'partialReplay' method. 1133 // the 'partialReplay' method.
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
1367 canvas.drawPicture(picture); 1369 canvas.drawPicture(picture);
1368 } 1370 }
1369 #endif 1371 #endif
1370 1372
1371 static SkData* encode_bitmap_to_data(size_t*, const SkBitmap& bm) { 1373 static SkData* encode_bitmap_to_data(size_t*, const SkBitmap& bm) {
1372 return SkImageEncoder::EncodeData(bm, SkImageEncoder::kPNG_Type, 100); 1374 return SkImageEncoder::EncodeData(bm, SkImageEncoder::kPNG_Type, 100);
1373 } 1375 }
1374 1376
1375 static SkData* serialized_picture_from_bitmap(const SkBitmap& bitmap) { 1377 static SkData* serialized_picture_from_bitmap(const SkBitmap& bitmap) {
1376 SkPictureRecorder recorder; 1378 SkPictureRecorder recorder;
1377 SkCanvas* canvas = recorder.beginRecording(bitmap.width(), bitmap.height()); 1379 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(bitmap.width()),
1380 SkIntToScalar(bitmap.height()));
1378 canvas->drawBitmap(bitmap, 0, 0); 1381 canvas->drawBitmap(bitmap, 0, 0);
1379 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); 1382 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
1380 1383
1381 SkDynamicMemoryWStream wStream; 1384 SkDynamicMemoryWStream wStream;
1382 picture->serialize(&wStream, &encode_bitmap_to_data); 1385 picture->serialize(&wStream, &encode_bitmap_to_data);
1383 return wStream.copyToData(); 1386 return wStream.copyToData();
1384 } 1387 }
1385 1388
1386 struct ErrorContext { 1389 struct ErrorContext {
1387 int fErrors; 1390 int fErrors;
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
1841 SkAutoTUnref<const SkPicture> picture(recorder.endRecording()); 1844 SkAutoTUnref<const SkPicture> picture(recorder.endRecording());
1842 1845
1843 SkCanvas big(640, 480), small(300, 200); 1846 SkCanvas big(640, 480), small(300, 200);
1844 1847
1845 picture->draw(&big); 1848 picture->draw(&big);
1846 REPORTER_ASSERT(r, bbh.searchCalls == 0); 1849 REPORTER_ASSERT(r, bbh.searchCalls == 0);
1847 1850
1848 picture->draw(&small); 1851 picture->draw(&small);
1849 REPORTER_ASSERT(r, bbh.searchCalls == 1); 1852 REPORTER_ASSERT(r, bbh.searchCalls == 1);
1850 } 1853 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698