diff options
author | 2017-04-24 16:44:03 -0400 | |
---|---|---|
committer | 2017-04-24 21:11:44 +0000 | |
commit | a28e2b07b7a11fc14be7178a32ce6bf726d8b0bd (patch) | |
tree | 3a190a1ea705078f9a2358631590a3f455ba4933 /src/core/SkImageCacherator.cpp | |
parent | 42a2a20b9114c904ce73d66d0105b81f19d93914 (diff) |
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 <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Diffstat (limited to 'src/core/SkImageCacherator.cpp')
-rw-r--r-- | src/core/SkImageCacherator.cpp | 80 |
1 files changed, 6 insertions, 74 deletions
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<GrTextureProxy> 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<GrSurfaceContext> 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<GrTextureProxy> 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<GrTextureProxy> proxy; if (willBeMipped) { proxy = GrGenerateMipMapsAndUploadToTextureProxy(ctx, bitmap, dstColorSpace); |