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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 SkAutoTUnref<SkImage> image(SkImage::NewFromBitmap(bm)); | 242 SkAutoTUnref<SkImage> image(SkImage::NewFromBitmap(bm)); |
243 SkPixmap pmap; | 243 SkPixmap pmap; |
244 | 244 |
245 const bool sharedID = (image->uniqueID() == bm.getGenerationID()); | 245 const bool sharedID = (image->uniqueID() == bm.getGenerationID()); |
246 REPORTER_ASSERT(reporter, sharedID == rec[i].fExpectSharedID); | 246 REPORTER_ASSERT(reporter, sharedID == rec[i].fExpectSharedID); |
247 | 247 |
248 const bool peekSuccess = image->peekPixels(&pmap); | 248 const bool peekSuccess = image->peekPixels(&pmap); |
249 REPORTER_ASSERT(reporter, peekSuccess == rec[i].fExpectPeekSuccess); | 249 REPORTER_ASSERT(reporter, peekSuccess == rec[i].fExpectPeekSuccess); |
250 } | 250 } |
251 } | 251 } |
| 252 |
| 253 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 254 #if SK_SUPPORT_GPU |
| 255 |
| 256 static SkImage* make_gpu_image(GrContext* ctx, const SkImageInfo& info, SkColor
color) { |
| 257 const SkSurface::Budgeted budgeted = SkSurface::kNo_Budgeted; |
| 258 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(ctx, budgeted, in
fo, 0)); |
| 259 surface->getCanvas()->drawColor(color); |
| 260 return surface->newImageSnapshot(); |
| 261 } |
| 262 |
| 263 #include "SkBitmapCache.h" |
| 264 |
| 265 /* |
| 266 * This tests the caching (and preemptive purge) of the raster equivalent of a
gpu-image. |
| 267 * We cache it for performance when drawing into a raster surface. |
| 268 * |
| 269 * A cleaner test would know if each drawImage call triggered a read-back from
the gpu, |
| 270 * but we don't have that facility (at the moment) so we use a little internal
knowledge |
| 271 * of *how* the raster version is cached, and look for that. |
| 272 */ |
| 273 DEF_GPUTEST(SkImage_Gpu2Cpu, reporter, factory) { |
| 274 GrContext* ctx = factory->get(GrContextFactory::kNative_GLContextType); |
| 275 if (!ctx) { |
| 276 REPORTER_ASSERT(reporter, false); |
| 277 return; |
| 278 } |
| 279 |
| 280 const SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10); |
| 281 SkAutoTUnref<SkImage> image(make_gpu_image(ctx, info, SK_ColorRED)); |
| 282 const uint32_t uniqueID = image->uniqueID(); |
| 283 |
| 284 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); |
| 285 |
| 286 // now we can test drawing a gpu-backed image into a cpu-backed surface |
| 287 |
| 288 { |
| 289 SkBitmap cachedBitmap; |
| 290 REPORTER_ASSERT(reporter, !SkBitmapCache::Find(uniqueID, &cachedBitmap))
; |
| 291 } |
| 292 |
| 293 surface->getCanvas()->drawImage(image, 0, 0); |
| 294 { |
| 295 SkBitmap cachedBitmap; |
| 296 if (SkBitmapCache::Find(uniqueID, &cachedBitmap)) { |
| 297 REPORTER_ASSERT(reporter, cachedBitmap.getGenerationID() == uniqueID
); |
| 298 REPORTER_ASSERT(reporter, cachedBitmap.isImmutable()); |
| 299 REPORTER_ASSERT(reporter, cachedBitmap.getPixels()); |
| 300 } else { |
| 301 // unexpected, but not really a bug, since the cache is global and t
his test may be |
| 302 // run w/ other threads competing for its budget. |
| 303 SkDebugf("SkImage_Gpu2Cpu : cachedBitmap was already purged\n"); |
| 304 } |
| 305 } |
| 306 |
| 307 image.reset(nullptr); |
| 308 { |
| 309 SkBitmap cachedBitmap; |
| 310 REPORTER_ASSERT(reporter, !SkBitmapCache::Find(uniqueID, &cachedBitmap))
; |
| 311 } |
| 312 } |
| 313 #endif |
OLD | NEW |