bool SkImageCacherator::lockAsBitmap(SkBitmap* bitmap, const SkImage* client, SkImage::CachingHint chint) { if (this->tryLockAsBitmap(bitmap, client, chint)) { return check_output_bitmap(*bitmap, fUniqueID); } #if SK_SUPPORT_GPU // Try to get a texture and read it back to raster (and then cache that with our ID) SkAutoTUnref<GrTexture> tex; { ScopedGenerator generator(this); SkIRect subset = SkIRect::MakeXYWH(fOrigin.x(), fOrigin.y(), fInfo.width(), fInfo.height()); tex.reset(generator->generateTexture(nullptr, &subset)); } if (!tex) { bitmap->reset(); return false; } if (!bitmap->tryAllocPixels(fInfo)) { bitmap->reset(); return false; } const uint32_t pixelOpsFlags = 0; if (!tex->readPixels(0, 0, bitmap->width(), bitmap->height(), SkImageInfo2GrPixelConfig(fInfo), bitmap->getPixels(), bitmap->rowBytes(), pixelOpsFlags)) { bitmap->reset(); return false; } bitmap->pixelRef()->setImmutableWithID(fUniqueID); if (SkImage::kAllow_CachingHint == chint) { SkBitmapCache::Add(fUniqueID, *bitmap); if (client) { as_IB(client)->notifyAddedToCache(); } } return check_output_bitmap(*bitmap, fUniqueID); #else return false; #endif }
bool SkImageCacherator::tryLockAsBitmap(SkBitmap* bitmap) { if (SkBitmapCache::Find(fUniqueID, bitmap)) { return check_output_bitmap(*bitmap, fUniqueID); } if (!this->generateBitmap(bitmap)) { return false; } bitmap->pixelRef()->setImmutableWithID(fUniqueID); SkBitmapCache::Add(fUniqueID, *bitmap); return true; }
bool SkImageCacherator::tryLockAsBitmap(SkBitmap* bitmap) { const uint32_t uniqueID = fGenerator->uniqueID(); if (SkBitmapCache::Find(uniqueID, bitmap)) { return check_output_bitmap(*bitmap, uniqueID); } if (!generate_bitmap(fGenerator, bitmap)) { return false; } bitmap->pixelRef()->setImmutableWithID(uniqueID); SkBitmapCache::Add(uniqueID, *bitmap); return true; }
bool SkImageCacherator::lockAsBitmap(SkBitmap* bitmap) { const uint32_t uniqueID = fGenerator->uniqueID(); if (this->tryLockAsBitmap(bitmap)) { return check_output_bitmap(*bitmap, uniqueID); } #if SK_SUPPORT_GPU // Try to get a texture and read it back to raster (and then cache that with our ID) SkAutoTUnref<GrTexture> tex(fGenerator->generateTexture(nullptr, kUntiled_SkImageUsageType)); if (!tex) { bitmap->reset(); return false; } const SkImageInfo& info = this->info(); if (!bitmap->tryAllocPixels(info)) { bitmap->reset(); return false; } const uint32_t pixelOpsFlags = 0; if (!tex->readPixels(0, 0, bitmap->width(), bitmap->height(), SkImageInfo2GrPixelConfig(info), bitmap->getPixels(), bitmap->rowBytes(), pixelOpsFlags)) { bitmap->reset(); return false; } bitmap->pixelRef()->setImmutableWithID(uniqueID); SkBitmapCache::Add(uniqueID, *bitmap); return check_output_bitmap(*bitmap, uniqueID); #else return false; #endif }
bool SkImageCacherator::tryLockAsBitmap(SkBitmap* bitmap, const SkImage* client) { if (SkBitmapCache::Find(fUniqueID, bitmap)) { return check_output_bitmap(*bitmap, fUniqueID); } if (!this->generateBitmap(bitmap)) { return false; } bitmap->pixelRef()->setImmutableWithID(fUniqueID); SkBitmapCache::Add(fUniqueID, *bitmap); if (client) { as_IB(client)->notifyAddedToCache(); } return true; }
bool SkImage_Lazy::lockAsBitmap(SkBitmap* bitmap, SkImage::CachingHint chint, CachedFormat format, const SkImageInfo& info, SkTransferFunctionBehavior behavior) const { if (this->lockAsBitmapOnlyIfAlreadyCached(bitmap, format)) { return true; } uint32_t uniqueID = this->getUniqueID(format); SkBitmap tmpBitmap; SkBitmapCache::RecPtr cacheRec; SkPixmap pmap; if (SkImage::kAllow_CachingHint == chint) { auto desc = SkBitmapCacheDesc::Make(uniqueID, info.width(), info.height()); cacheRec = SkBitmapCache::Alloc(desc, info, &pmap); if (!cacheRec) { return false; } } else { if (!tmpBitmap.tryAllocPixels(info)) { return false; } if (!tmpBitmap.peekPixels(&pmap)) { return false; } } ScopedGenerator generator(fSharedGenerator); if (!generate_pixels(generator, pmap, fOrigin.x(), fOrigin.y(), behavior)) { return false; } if (cacheRec) { SkBitmapCache::Add(std::move(cacheRec), bitmap); SkASSERT(bitmap->getPixels()); // we're locked SkASSERT(bitmap->isImmutable()); SkASSERT(bitmap->getGenerationID() == uniqueID); this->notifyAddedToCache(); } else { *bitmap = tmpBitmap; bitmap->pixelRef()->setImmutableWithID(uniqueID); } check_output_bitmap(*bitmap, uniqueID); return true; }
bool SkImageCacherator::lockAsBitmapOnlyIfAlreadyCached(SkBitmap* bitmap) { return SkBitmapCache::Find(fUniqueID, bitmap) && check_output_bitmap(*bitmap, fUniqueID); }
bool SkImage_Lazy::lockAsBitmapOnlyIfAlreadyCached(SkBitmap* bitmap, CachedFormat format) const { uint32_t uniqueID = this->getUniqueID(format); return SkBitmapCache::Find(SkBitmapCacheDesc::Make(uniqueID, fInfo.width(), fInfo.height()), bitmap) && check_output_bitmap(*bitmap, uniqueID); }