OLD | NEW |
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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 static void make_bitmap_immutable(SkBitmap* bm) { | 222 static void make_bitmap_immutable(SkBitmap* bm) { |
223 bm->allocN32Pixels(10, 10); | 223 bm->allocN32Pixels(10, 10); |
224 bm->setImmutable(); | 224 bm->setImmutable(); |
225 } | 225 } |
226 | 226 |
227 DEF_TEST(image_newfrombitmap, reporter) { | 227 DEF_TEST(image_newfrombitmap, reporter) { |
228 const struct { | 228 const struct { |
229 void (*fMakeProc)(SkBitmap*); | 229 void (*fMakeProc)(SkBitmap*); |
230 bool fExpectPeekSuccess; | 230 bool fExpectPeekSuccess; |
231 bool fExpectSharedID; | 231 bool fExpectSharedID; |
| 232 bool fExpectLazy; |
232 } rec[] = { | 233 } rec[] = { |
233 { make_bitmap_lazy, false, true }, | 234 { make_bitmap_lazy, false, true, true }, |
234 { make_bitmap_mutable, true, false }, | 235 { make_bitmap_mutable, true, false, false }, |
235 { make_bitmap_immutable, true, true }, | 236 { make_bitmap_immutable, true, true, false }, |
236 }; | 237 }; |
237 | 238 |
238 for (size_t i = 0; i < SK_ARRAY_COUNT(rec); ++i) { | 239 for (size_t i = 0; i < SK_ARRAY_COUNT(rec); ++i) { |
239 SkBitmap bm; | 240 SkBitmap bm; |
240 rec[i].fMakeProc(&bm); | 241 rec[i].fMakeProc(&bm); |
241 | 242 |
242 SkAutoTUnref<SkImage> image(SkImage::NewFromBitmap(bm)); | 243 SkAutoTUnref<SkImage> image(SkImage::NewFromBitmap(bm)); |
243 SkPixmap pmap; | 244 SkPixmap pmap; |
244 | 245 |
245 const bool sharedID = (image->uniqueID() == bm.getGenerationID()); | 246 const bool sharedID = (image->uniqueID() == bm.getGenerationID()); |
246 REPORTER_ASSERT(reporter, sharedID == rec[i].fExpectSharedID); | 247 REPORTER_ASSERT(reporter, sharedID == rec[i].fExpectSharedID); |
247 | 248 |
248 const bool peekSuccess = image->peekPixels(&pmap); | 249 const bool peekSuccess = image->peekPixels(&pmap); |
249 REPORTER_ASSERT(reporter, peekSuccess == rec[i].fExpectPeekSuccess); | 250 REPORTER_ASSERT(reporter, peekSuccess == rec[i].fExpectPeekSuccess); |
| 251 |
| 252 const bool lazy = image->isLazyGenerated(); |
| 253 REPORTER_ASSERT(reporter, lazy == rec[i].fExpectLazy); |
250 } | 254 } |
251 } | 255 } |
252 | 256 |
253 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 257 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
254 #if SK_SUPPORT_GPU | 258 #if SK_SUPPORT_GPU |
255 | 259 |
256 static SkImage* make_gpu_image(GrContext* ctx, const SkImageInfo& info, SkColor
color) { | 260 static SkImage* make_gpu_image(GrContext* ctx, const SkImageInfo& info, SkColor
color) { |
257 const SkSurface::Budgeted budgeted = SkSurface::kNo_Budgeted; | 261 const SkSurface::Budgeted budgeted = SkSurface::kNo_Budgeted; |
258 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(ctx, budgeted, in
fo, 0)); | 262 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(ctx, budgeted, in
fo, 0)); |
259 surface->getCanvas()->drawColor(color); | 263 surface->getCanvas()->drawColor(color); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 } | 308 } |
305 } | 309 } |
306 | 310 |
307 image.reset(nullptr); | 311 image.reset(nullptr); |
308 { | 312 { |
309 SkBitmap cachedBitmap; | 313 SkBitmap cachedBitmap; |
310 REPORTER_ASSERT(reporter, !SkBitmapCache::Find(uniqueID, &cachedBitmap))
; | 314 REPORTER_ASSERT(reporter, !SkBitmapCache::Find(uniqueID, &cachedBitmap))
; |
311 } | 315 } |
312 } | 316 } |
313 #endif | 317 #endif |
OLD | NEW |