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

Side by Side Diff: tests/ImageTest.cpp

Issue 1340803002: discardable pixelrefs are gone, update tests accordingly (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 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
« no previous file with comments | « tests/ImageDecodingTest.cpp ('k') | tests/JpegTest.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 "SkCanvas.h" 8 #include "SkCanvas.h"
9 #include "SkData.h" 9 #include "SkData.h"
10 #include "SkDevice.h" 10 #include "SkDevice.h"
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 238
239 SkAutoTUnref<SkImage> image2(surface->newImageSnapshot()); 239 SkAutoTUnref<SkImage> image2(surface->newImageSnapshot());
240 REPORTER_ASSERT(reporter, image2->readPixels(dstInfo, pixels, dstRowBytes, 0 , 0)); 240 REPORTER_ASSERT(reporter, image2->readPixels(dstInfo, pixels, dstRowBytes, 0 , 0));
241 REPORTER_ASSERT(reporter, pixels[0] == green); 241 REPORTER_ASSERT(reporter, pixels[0] == green);
242 REPORTER_ASSERT(reporter, pixels[1] == green); 242 REPORTER_ASSERT(reporter, pixels[1] == green);
243 REPORTER_ASSERT(reporter, pixels[2] == green); 243 REPORTER_ASSERT(reporter, pixels[2] == green);
244 REPORTER_ASSERT(reporter, pixels[3] == red); 244 REPORTER_ASSERT(reporter, pixels[3] == red);
245 } 245 }
246 246
247 //////////////////////////////////////////////////////////////////////////////// ///////////////// 247 //////////////////////////////////////////////////////////////////////////////// /////////////////
248 #include "SkImageGenerator.h"
249 #include "SkData.h"
250
251 const uint8_t tiny_png[] = {
252 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d,
253 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x64,
254 0x08, 0x06, 0x00, 0x00, 0x00, 0x70, 0xe2, 0x95, 0x54, 0x00, 0x00, 0x00,
255 0x01, 0x73, 0x52, 0x47, 0x42, 0x00, 0xae, 0xce, 0x1c, 0xe9, 0x00, 0x00,
256 0x01, 0x6b, 0x49, 0x44, 0x41, 0x54, 0x78, 0x01, 0xed, 0xd3, 0x41, 0x11,
257 0x00, 0x20, 0x0c, 0xc4, 0x40, 0xc0, 0xbf, 0xe7, 0xc2, 0xa0, 0x22, 0x8f,
258 0xad, 0x82, 0x4c, 0xd2, 0xdb, 0xf3, 0x6e, 0xb9, 0x8c, 0x81, 0x93, 0x21,
259 0x01, 0xf2, 0x0d, 0x08, 0x12, 0x7b, 0x04, 0x41, 0x04, 0x89, 0x19, 0x88,
260 0xe1, 0x58, 0x88, 0x20, 0x31, 0x03, 0x31, 0x1c, 0x0b, 0x11, 0x24, 0x66,
261 0x20, 0x86, 0x63, 0x21, 0x82, 0xc4, 0x0c, 0xc4, 0x70, 0x2c, 0x44, 0x90,
262 0x98, 0x81, 0x18, 0x8e, 0x85, 0x08, 0x12, 0x33, 0x10, 0xc3, 0xb1, 0x10,
263 0x41, 0x62, 0x06, 0x62, 0x38, 0x16, 0x22, 0x48, 0xcc, 0x40, 0x0c, 0xc7,
264 0x42, 0x04, 0x89, 0x19, 0x88, 0xe1, 0x58, 0x88, 0x20, 0x31, 0x03, 0x31,
265 0x1c, 0x0b, 0x11, 0x24, 0x66, 0x20, 0x86, 0x63, 0x21, 0x82, 0xc4, 0x0c,
266 0xc4, 0x70, 0x2c, 0x44, 0x90, 0x98, 0x81, 0x18, 0x8e, 0x85, 0x08, 0x12,
267 0x33, 0x10, 0xc3, 0xb1, 0x10, 0x41, 0x62, 0x06, 0x62, 0x38, 0x16, 0x22,
268 0x48, 0xcc, 0x40, 0x0c, 0xc7, 0x42, 0x04, 0x89, 0x19, 0x88, 0xe1, 0x58,
269 0x88, 0x20, 0x31, 0x03, 0x31, 0x1c, 0x0b, 0x11, 0x24, 0x66, 0x20, 0x86,
270 0x63, 0x21, 0x82, 0xc4, 0x0c, 0xc4, 0x70, 0x2c, 0x44, 0x90, 0x98, 0x81,
271 0x18, 0x8e, 0x85, 0x08, 0x12, 0x33, 0x10, 0xc3, 0xb1, 0x10, 0x41, 0x62,
272 0x06, 0x62, 0x38, 0x16, 0x22, 0x48, 0xcc, 0x40, 0x0c, 0xc7, 0x42, 0x04,
273 0x89, 0x19, 0x88, 0xe1, 0x58, 0x88, 0x20, 0x31, 0x03, 0x31, 0x1c, 0x0b,
274 0x11, 0x24, 0x66, 0x20, 0x86, 0x63, 0x21, 0x82, 0xc4, 0x0c, 0xc4, 0x70,
275 0x2c, 0x44, 0x90, 0x98, 0x81, 0x18, 0x8e, 0x85, 0x08, 0x12, 0x33, 0x10,
276 0xc3, 0xb1, 0x10, 0x41, 0x62, 0x06, 0x62, 0x38, 0x16, 0x22, 0x48, 0xcc,
277 0x40, 0x0c, 0xc7, 0x42, 0x04, 0x89, 0x19, 0x88, 0xe1, 0x58, 0x88, 0x20,
278 0x31, 0x03, 0x31, 0x1c, 0x0b, 0x11, 0x24, 0x66, 0x20, 0x86, 0x63, 0x21,
279 0x82, 0xc4, 0x0c, 0xc4, 0x70, 0x2c, 0x44, 0x90, 0x98, 0x81, 0x18, 0x8e,
280 0x85, 0x08, 0x12, 0x33, 0x10, 0xc3, 0xb1, 0x10, 0x41, 0x62, 0x06, 0x62,
281 0x38, 0x16, 0x22, 0x48, 0xcc, 0x40, 0x0c, 0xc7, 0x42, 0x04, 0x89, 0x19,
282 0x88, 0xe1, 0x58, 0x88, 0x20, 0x31, 0x03, 0x31, 0x1c, 0x0b, 0x11, 0x24,
283 0x66, 0x20, 0x86, 0x63, 0x21, 0x82, 0xc4, 0x0c, 0xc4, 0x70, 0x2c, 0x44,
284 0x90, 0x98, 0x81, 0x18, 0x8e, 0x85, 0x08, 0x12, 0x33, 0x10, 0xc3, 0xb1,
285 0x10, 0x41, 0x62, 0x06, 0x62, 0x38, 0x16, 0x22, 0x48, 0xcc, 0x40, 0x0c,
286 0xc7, 0x42, 0x62, 0x41, 0x2e, 0x08, 0x60, 0x04, 0xc4, 0x4c, 0x5d, 0x6e,
287 0xf2, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60,
288 0x82
289 };
290
291 static void make_bitmap_lazy(SkBitmap* bm) {
292 SkAutoTUnref<SkData> data(SkData::NewWithoutCopy(tiny_png, sizeof(tiny_png)) );
293 SkInstallDiscardablePixelRef(data, bm);
294 }
295 248
296 static void make_bitmap_mutable(SkBitmap* bm) { 249 static void make_bitmap_mutable(SkBitmap* bm) {
297 bm->allocN32Pixels(10, 10); 250 bm->allocN32Pixels(10, 10);
298 } 251 }
299 252
300 static void make_bitmap_immutable(SkBitmap* bm) { 253 static void make_bitmap_immutable(SkBitmap* bm) {
301 bm->allocN32Pixels(10, 10); 254 bm->allocN32Pixels(10, 10);
302 bm->setImmutable(); 255 bm->setImmutable();
303 } 256 }
304 257
305 DEF_TEST(image_newfrombitmap, reporter) { 258 DEF_TEST(image_newfrombitmap, reporter) {
306 const struct { 259 const struct {
307 void (*fMakeProc)(SkBitmap*); 260 void (*fMakeProc)(SkBitmap*);
308 bool fExpectPeekSuccess; 261 bool fExpectPeekSuccess;
309 bool fExpectSharedID; 262 bool fExpectSharedID;
310 bool fExpectLazy; 263 bool fExpectLazy;
311 } rec[] = { 264 } rec[] = {
312 { make_bitmap_lazy, false, true, true },
313 { make_bitmap_mutable, true, false, false }, 265 { make_bitmap_mutable, true, false, false },
314 { make_bitmap_immutable, true, true, false }, 266 { make_bitmap_immutable, true, true, false },
315 }; 267 };
316 268
317 for (size_t i = 0; i < SK_ARRAY_COUNT(rec); ++i) { 269 for (size_t i = 0; i < SK_ARRAY_COUNT(rec); ++i) {
318 SkBitmap bm; 270 SkBitmap bm;
319 rec[i].fMakeProc(&bm); 271 rec[i].fMakeProc(&bm);
320 272
321 SkAutoTUnref<SkImage> image(SkImage::NewFromBitmap(bm)); 273 SkAutoTUnref<SkImage> image(SkImage::NewFromBitmap(bm));
322 SkPixmap pmap; 274 SkPixmap pmap;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 } 338 }
387 } 339 }
388 340
389 image.reset(nullptr); 341 image.reset(nullptr);
390 { 342 {
391 SkBitmap cachedBitmap; 343 SkBitmap cachedBitmap;
392 REPORTER_ASSERT(reporter, !SkBitmapCache::Find(uniqueID, &cachedBitmap)) ; 344 REPORTER_ASSERT(reporter, !SkBitmapCache::Find(uniqueID, &cachedBitmap)) ;
393 } 345 }
394 } 346 }
395 #endif 347 #endif
OLDNEW
« no previous file with comments | « tests/ImageDecodingTest.cpp ('k') | tests/JpegTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698