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

Side by Side Diff: tests/ImageTest.cpp

Issue 1817383002: switch surface to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 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/ImageNewShaderTest.cpp ('k') | tests/IndexedPngOverflowTest.cpp » ('j') | 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 2015 Google Inc. 2 * Copyright 2015 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 <functional> 8 #include <functional>
9 #include <initializer_list> 9 #include <initializer_list>
10 #include "DMGpuSupport.h" 10 #include "DMGpuSupport.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 } 55 }
56 } 56 }
57 static void draw_image_test_pattern(SkCanvas* canvas) { 57 static void draw_image_test_pattern(SkCanvas* canvas) {
58 canvas->clear(SK_ColorWHITE); 58 canvas->clear(SK_ColorWHITE);
59 SkPaint paint; 59 SkPaint paint;
60 paint.setColor(SK_ColorBLACK); 60 paint.setColor(SK_ColorBLACK);
61 canvas->drawRect(SkRect::MakeXYWH(5, 5, 10, 10), paint); 61 canvas->drawRect(SkRect::MakeXYWH(5, 5, 10, 10), paint);
62 } 62 }
63 static sk_sp<SkImage> create_image() { 63 static sk_sp<SkImage> create_image() {
64 const SkImageInfo info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType); 64 const SkImageInfo info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType);
65 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); 65 auto surface(SkSurface::MakeRaster(info));
66 draw_image_test_pattern(surface->getCanvas()); 66 draw_image_test_pattern(surface->getCanvas());
67 return surface->makeImageSnapshot(); 67 return surface->makeImageSnapshot();
68 } 68 }
69 static sk_sp<SkImage> create_image_565() { 69 static sk_sp<SkImage> create_image_565() {
70 const SkImageInfo info = SkImageInfo::Make(20, 20, kRGB_565_SkColorType, kOp aque_SkAlphaType); 70 const SkImageInfo info = SkImageInfo::Make(20, 20, kRGB_565_SkColorType, kOp aque_SkAlphaType);
71 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); 71 auto surface(SkSurface::MakeRaster(info));
72 draw_image_test_pattern(surface->getCanvas()); 72 draw_image_test_pattern(surface->getCanvas());
73 return surface->makeImageSnapshot(); 73 return surface->makeImageSnapshot();
74 } 74 }
75 static sk_sp<SkImage> create_image_ct() { 75 static sk_sp<SkImage> create_image_ct() {
76 SkPMColor colors[] = { 76 SkPMColor colors[] = {
77 SkPreMultiplyARGB(0xFF, 0xFF, 0xFF, 0x00), 77 SkPreMultiplyARGB(0xFF, 0xFF, 0xFF, 0x00),
78 SkPreMultiplyARGB(0x80, 0x00, 0xA0, 0xFF), 78 SkPreMultiplyARGB(0x80, 0x00, 0xA0, 0xFF),
79 SkPreMultiplyARGB(0xFF, 0xBB, 0x00, 0xBB) 79 SkPreMultiplyARGB(0xFF, 0xBB, 0x00, 0xBB)
80 }; 80 };
81 SkAutoTUnref<SkColorTable> colorTable(new SkColorTable(colors, SK_ARRAY_COUN T(colors))); 81 SkAutoTUnref<SkColorTable> colorTable(new SkColorTable(colors, SK_ARRAY_COUN T(colors)));
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 SkAutoTUnref<SkData> data(create_image_data(&info)); 139 SkAutoTUnref<SkData> data(create_image_data(&info));
140 SkBitmap bitmap; 140 SkBitmap bitmap;
141 bitmap.installPixels(info, data->writable_data(), info.minRowBytes()); 141 bitmap.installPixels(info, data->writable_data(), info.minRowBytes());
142 sk_sp<SkData> src( 142 sk_sp<SkData> src(
143 SkImageEncoder::EncodeData(bitmap, SkImageEncoder::kPNG_Type, 100)); 143 SkImageEncoder::EncodeData(bitmap, SkImageEncoder::kPNG_Type, 100));
144 return SkImage::MakeFromEncoded(src); 144 return SkImage::MakeFromEncoded(src);
145 } 145 }
146 #if SK_SUPPORT_GPU 146 #if SK_SUPPORT_GPU
147 static sk_sp<SkImage> create_gpu_image(GrContext* context) { 147 static sk_sp<SkImage> create_gpu_image(GrContext* context) {
148 const SkImageInfo info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType); 148 const SkImageInfo info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType);
149 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context, SkBudget ed::kNo, 149 auto surface(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info));
150 info));
151 draw_image_test_pattern(surface->getCanvas()); 150 draw_image_test_pattern(surface->getCanvas());
152 return surface->makeImageSnapshot(); 151 return surface->makeImageSnapshot();
153 } 152 }
154 #endif 153 #endif
155 154
156 static void test_encode(skiatest::Reporter* reporter, SkImage* image) { 155 static void test_encode(skiatest::Reporter* reporter, SkImage* image) {
157 const SkIRect ir = SkIRect::MakeXYWH(5, 5, 10, 10); 156 const SkIRect ir = SkIRect::MakeXYWH(5, 5, 10, 10);
158 sk_sp<SkData> origEncoded(image->encode()); 157 sk_sp<SkData> origEncoded(image->encode());
159 REPORTER_ASSERT(reporter, origEncoded); 158 REPORTER_ASSERT(reporter, origEncoded);
160 REPORTER_ASSERT(reporter, origEncoded->size() > 0); 159 REPORTER_ASSERT(reporter, origEncoded->size() > 0);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 SkAutoTUnref<SkData> reference(SkData::NewWithCString(kSerializedData)); 216 SkAutoTUnref<SkData> reference(SkData::NewWithCString(kSerializedData));
218 217
219 REPORTER_ASSERT(reporter, serializer.didEncode()); 218 REPORTER_ASSERT(reporter, serializer.didEncode());
220 REPORTER_ASSERT(reporter, encoded); 219 REPORTER_ASSERT(reporter, encoded);
221 REPORTER_ASSERT(reporter, encoded->size() > 0); 220 REPORTER_ASSERT(reporter, encoded->size() > 0);
222 REPORTER_ASSERT(reporter, encoded->equals(reference)); 221 REPORTER_ASSERT(reporter, encoded->equals(reference));
223 } 222 }
224 223
225 // Test that image encoding failures do not break picture serialization/deserial ization. 224 // Test that image encoding failures do not break picture serialization/deserial ization.
226 DEF_TEST(Image_Serialize_Encoding_Failure, reporter) { 225 DEF_TEST(Image_Serialize_Encoding_Failure, reporter) {
227 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(100, 100)); 226 auto surface(SkSurface::MakeRasterN32Premul(100, 100));
228 surface->getCanvas()->clear(SK_ColorGREEN); 227 surface->getCanvas()->clear(SK_ColorGREEN);
229 sk_sp<SkImage> image(surface->makeImageSnapshot()); 228 sk_sp<SkImage> image(surface->makeImageSnapshot());
230 REPORTER_ASSERT(reporter, image); 229 REPORTER_ASSERT(reporter, image);
231 230
232 SkPictureRecorder recorder; 231 SkPictureRecorder recorder;
233 SkCanvas* canvas = recorder.beginRecording(100, 100); 232 SkCanvas* canvas = recorder.beginRecording(100, 100);
234 canvas->drawImage(image, 0, 0); 233 canvas->drawImage(image, 0, 0);
235 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); 234 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
236 REPORTER_ASSERT(reporter, picture); 235 REPORTER_ASSERT(reporter, picture);
237 REPORTER_ASSERT(reporter, picture->approximateOpCount() > 0); 236 REPORTER_ASSERT(reporter, picture->approximateOpCount() > 0);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 REPORTER_ASSERT(reporter, 0 == pixels[3]); 279 REPORTER_ASSERT(reporter, 0 == pixels[3]);
281 } 280 }
282 281
283 // Test that a draw that only partially covers the drawing surface isn't 282 // Test that a draw that only partially covers the drawing surface isn't
284 // interpreted as covering the entire drawing surface (i.e., exercise one of the 283 // interpreted as covering the entire drawing surface (i.e., exercise one of the
285 // conditions of SkCanvas::wouldOverwriteEntireSurface()). 284 // conditions of SkCanvas::wouldOverwriteEntireSurface()).
286 DEF_TEST(Image_RetainSnapshot, reporter) { 285 DEF_TEST(Image_RetainSnapshot, reporter) {
287 const SkPMColor red = SkPackARGB32(0xFF, 0xFF, 0, 0); 286 const SkPMColor red = SkPackARGB32(0xFF, 0xFF, 0, 0);
288 const SkPMColor green = SkPackARGB32(0xFF, 0, 0xFF, 0); 287 const SkPMColor green = SkPackARGB32(0xFF, 0, 0xFF, 0);
289 SkImageInfo info = SkImageInfo::MakeN32Premul(2, 2); 288 SkImageInfo info = SkImageInfo::MakeN32Premul(2, 2);
290 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); 289 auto surface(SkSurface::MakeRaster(info));
291 surface->getCanvas()->clear(0xFF00FF00); 290 surface->getCanvas()->clear(0xFF00FF00);
292 291
293 SkPMColor pixels[4]; 292 SkPMColor pixels[4];
294 memset(pixels, 0xFF, sizeof(pixels)); // init with values we don't expect 293 memset(pixels, 0xFF, sizeof(pixels)); // init with values we don't expect
295 const SkImageInfo dstInfo = SkImageInfo::MakeN32Premul(2, 2); 294 const SkImageInfo dstInfo = SkImageInfo::MakeN32Premul(2, 2);
296 const size_t dstRowBytes = 2 * sizeof(SkPMColor); 295 const size_t dstRowBytes = 2 * sizeof(SkPMColor);
297 296
298 sk_sp<SkImage> image1(surface->makeImageSnapshot()); 297 sk_sp<SkImage> image1(surface->makeImageSnapshot());
299 REPORTER_ASSERT(reporter, image1->readPixels(dstInfo, pixels, dstRowBytes, 0 , 0)); 298 REPORTER_ASSERT(reporter, image1->readPixels(dstInfo, pixels, dstRowBytes, 0 , 0));
300 for (size_t i = 0; i < SK_ARRAY_COUNT(pixels); ++i) { 299 for (size_t i = 0; i < SK_ARRAY_COUNT(pixels); ++i) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 * 365 *
367 * A cleaner test would know if each drawImage call triggered a read-back from the gpu, 366 * A cleaner test would know if each drawImage call triggered a read-back from the gpu,
368 * but we don't have that facility (at the moment) so we use a little internal knowledge 367 * but we don't have that facility (at the moment) so we use a little internal knowledge
369 * of *how* the raster version is cached, and look for that. 368 * of *how* the raster version is cached, and look for that.
370 */ 369 */
371 DEF_GPUTEST_FOR_NATIVE_CONTEXT(SkImage_Gpu2Cpu, reporter, context) { 370 DEF_GPUTEST_FOR_NATIVE_CONTEXT(SkImage_Gpu2Cpu, reporter, context) {
372 SkImageInfo info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType); 371 SkImageInfo info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType);
373 sk_sp<SkImage> image(create_gpu_image(context)); 372 sk_sp<SkImage> image(create_gpu_image(context));
374 const uint32_t uniqueID = image->uniqueID(); 373 const uint32_t uniqueID = image->uniqueID();
375 374
376 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); 375 auto surface(SkSurface::MakeRaster(info));
377 376
378 // now we can test drawing a gpu-backed image into a cpu-backed surface 377 // now we can test drawing a gpu-backed image into a cpu-backed surface
379 378
380 { 379 {
381 SkBitmap cachedBitmap; 380 SkBitmap cachedBitmap;
382 REPORTER_ASSERT(reporter, !SkBitmapCache::Find(uniqueID, &cachedBitmap)) ; 381 REPORTER_ASSERT(reporter, !SkBitmapCache::Find(uniqueID, &cachedBitmap)) ;
383 } 382 }
384 383
385 surface->getCanvas()->drawImage(image, 0, 0); 384 surface->getCanvas()->drawImage(image, 0, 0);
386 { 385 {
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 otherContextInfo.fGrContext, buffer, budgeted)); 883 otherContextInfo.fGrContext, buffer, budgeted));
885 REPORTER_ASSERT(reporter, !newImage2); 884 REPORTER_ASSERT(reporter, !newImage2);
886 glContext->makeCurrent(); 885 glContext->makeCurrent();
887 } 886 }
888 } 887 }
889 sk_free(buffer); 888 sk_free(buffer);
890 } 889 }
891 } 890 }
892 } 891 }
893 #endif 892 #endif
OLDNEW
« no previous file with comments | « tests/ImageNewShaderTest.cpp ('k') | tests/IndexedPngOverflowTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698