From a28e2b07b7a11fc14be7178a32ce6bf726d8b0bd Mon Sep 17 00:00:00 2001 From: Brian Osman Date: Mon, 24 Apr 2017 16:44:03 -0400 Subject: Simplify SkImageCacherator slightly - lockAsBitmap supported reading back textures to a bitmap, but this was only used by one GM. Removed all of that code, and merged the two bitmap functions together. - To make the GM cleaner, don't use SkImageCacherator directly - construct actual images. Bug: skia: Change-Id: Iad17184a02a72f89ccc851fa158764d6c871befa Reviewed-on: https://skia-review.googlesource.com/14192 Reviewed-by: Brian Salomon Commit-Queue: Brian Osman --- src/core/SkImageCacherator.cpp | 80 ++++-------------------------------------- 1 file changed, 6 insertions(+), 74 deletions(-) (limited to 'src/core/SkImageCacherator.cpp') diff --git a/src/core/SkImageCacherator.cpp b/src/core/SkImageCacherator.cpp index c755f5d4d2..808fdd4554 100644 --- a/src/core/SkImageCacherator.cpp +++ b/src/core/SkImageCacherator.cpp @@ -199,9 +199,9 @@ static bool generate_pixels(SkImageGenerator* gen, const SkPixmap& pmap, int ori return true; } -bool SkImageCacherator::tryLockAsBitmap(SkBitmap* bitmap, const SkImage* client, - SkImage::CachingHint chint, CachedFormat format, - const SkImageInfo& info) { +bool SkImageCacherator::lockAsBitmap(SkBitmap* bitmap, const SkImage* client, + SkImage::CachingHint chint, CachedFormat format, + const SkImageInfo& info) { if (this->lockAsBitmapOnlyIfAlreadyCached(bitmap, format)) { return true; } @@ -243,77 +243,9 @@ bool SkImageCacherator::tryLockAsBitmap(SkBitmap* bitmap, const SkImage* client, *bitmap = tmpBitmap; bitmap->pixelRef()->setImmutableWithID(uniqueID); } - return true; -} - -bool SkImageCacherator::lockAsBitmap(GrContext* context, SkBitmap* bitmap, const SkImage* client, - SkColorSpace* dstColorSpace, - SkImage::CachingHint chint) { - CachedFormat format = this->chooseCacheFormat(dstColorSpace); - SkImageInfo cacheInfo = this->buildCacheInfo(format); - const uint32_t uniqueID = this->getUniqueID(format); - - if (this->tryLockAsBitmap(bitmap, client, chint, format, cacheInfo)) { - return check_output_bitmap(*bitmap, uniqueID); - } - -#if SK_SUPPORT_GPU - if (!context) { - bitmap->reset(); - return false; - } - // Try to get a texture and read it back to raster (and then cache that with our ID) - sk_sp proxy; - - { - ScopedGenerator generator(fSharedGenerator); - proxy = generator->generateTexture(context, cacheInfo, fOrigin); - } - if (!proxy) { - bitmap->reset(); - return false; - } - - const auto desc = SkBitmapCacheDesc::Make(uniqueID, fInfo.width(), fInfo.height()); - SkBitmapCache::RecPtr rec; - SkPixmap pmap; - if (SkImage::kAllow_CachingHint == chint) { - rec = SkBitmapCache::Alloc(desc, cacheInfo, &pmap); - if (!rec) { - bitmap->reset(); - return false; - } - } else { - if (!bitmap->tryAllocPixels(cacheInfo)) { - bitmap->reset(); - return false; - } - } - - sk_sp sContext(context->contextPriv().makeWrappedSurfaceContext( - proxy, - fInfo.refColorSpace())); // src colorSpace - if (!sContext) { - bitmap->reset(); - return false; - } - - if (!sContext->readPixels(pmap.info(), pmap.writable_addr(), pmap.rowBytes(), 0, 0)) { - bitmap->reset(); - return false; - } - - if (rec) { - SkBitmapCache::Add(std::move(rec), bitmap); - if (client) { - as_IB(client)->notifyAddedToCache(); - } - } - return check_output_bitmap(*bitmap, uniqueID); -#else - return false; -#endif + check_output_bitmap(*bitmap, uniqueID); + return true; } ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -628,7 +560,7 @@ sk_sp SkImageCacherator::lockTextureProxy(GrContext* ctx, // 5. Ask the generator to return RGB(A) data, which the GPU can convert SkBitmap bitmap; - if (this->tryLockAsBitmap(&bitmap, client, chint, format, cacheInfo)) { + if (this->lockAsBitmap(&bitmap, client, chint, format, cacheInfo)) { sk_sp proxy; if (willBeMipped) { proxy = GrGenerateMipMapsAndUploadToTextureProxy(ctx, bitmap, dstColorSpace); -- cgit v1.2.3