aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkImageCacherator.cpp
diff options
context:
space:
mode:
authorGravatar Robert Phillips <robertphillips@google.com>2017-03-03 11:10:18 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-03-03 17:40:52 +0000
commit4447b64a88ea141161fca772c2fec28b6141bbc3 (patch)
treefce75d30623892dfe7271acdd671623240302e10 /src/core/SkImageCacherator.cpp
parent3c6d5b0daa8c9ff1137bb2ef9b00a712bb3a47c2 (diff)
Switch SkImageGenerator over to generating GrTextureProxies
It does not seem irrational for generateTexture to always receive a valid GrContext. lockAsBitmap can do as it pleases. This is split out of: https://skia-review.googlesource.com/c/8823/ (Remove GrFragmentProcessor-derived class' GrTexture-based ctors) Change-Id: I8aebc813a8a3a7d694b7369c2c9810e2164fe16e Reviewed-on: https://skia-review.googlesource.com/9191 Commit-Queue: Robert Phillips <robertphillips@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src/core/SkImageCacherator.cpp')
-rw-r--r--src/core/SkImageCacherator.cpp32
1 files changed, 23 insertions, 9 deletions
diff --git a/src/core/SkImageCacherator.cpp b/src/core/SkImageCacherator.cpp
index 17cac1b4ee..c33a008baa 100644
--- a/src/core/SkImageCacherator.cpp
+++ b/src/core/SkImageCacherator.cpp
@@ -208,7 +208,7 @@ bool SkImageCacherator::tryLockAsBitmap(SkBitmap* bitmap, const SkImage* client,
return true;
}
-bool SkImageCacherator::lockAsBitmap(SkBitmap* bitmap, const SkImage* client,
+bool SkImageCacherator::lockAsBitmap(GrContext* context, SkBitmap* bitmap, const SkImage* client,
SkColorSpace* dstColorSpace,
SkImage::CachingHint chint) {
CachedFormat format = this->chooseCacheFormat(dstColorSpace);
@@ -223,14 +223,19 @@ bool SkImageCacherator::lockAsBitmap(SkBitmap* bitmap, const SkImage* client,
}
#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<GrTexture> tex;
+ sk_sp<GrTextureProxy> proxy;
{
ScopedGenerator generator(fSharedGenerator);
- tex.reset(generator->generateTexture(nullptr, cacheInfo, fOrigin));
+ proxy = generator->generateTexture(context, cacheInfo, fOrigin);
}
- if (!tex) {
+ if (!proxy) {
bitmap->reset();
return false;
}
@@ -240,9 +245,15 @@ bool SkImageCacherator::lockAsBitmap(SkBitmap* bitmap, const SkImage* client,
return false;
}
- if (!tex->readPixels(fInfo.colorSpace(), 0, 0, bitmap->width(), bitmap->height(),
- SkImageInfo2GrPixelConfig(cacheInfo, *tex->getContext()->caps()),
- cacheInfo.colorSpace(), bitmap->getPixels(), bitmap->rowBytes())) {
+ sk_sp<GrSurfaceContext> sContext(context->contextPriv().makeWrappedSurfaceContext(
+ proxy,
+ fInfo.refColorSpace())); // src colorSpace
+ if (!sContext) {
+ bitmap->reset();
+ return false;
+ }
+
+ if (!sContext->readPixels(bitmap->info(), bitmap->getPixels(), bitmap->rowBytes(), 0, 0)) {
bitmap->reset();
return false;
}
@@ -542,10 +553,13 @@ GrTexture* SkImageCacherator::lockTexture(GrContext* ctx, const GrUniqueKey& ori
// 2. Ask the generator to natively create one
{
ScopedGenerator generator(fSharedGenerator);
- if (GrTexture* tex = generator->generateTexture(ctx, cacheInfo, fOrigin)) {
+ if (sk_sp<GrTextureProxy> proxy = generator->generateTexture(ctx, cacheInfo, fOrigin)) {
SK_HISTOGRAM_ENUMERATION("LockTexturePath", kNative_LockTexturePath,
kLockTexturePathCount);
- return set_key_and_return(ctx->textureProvider(), tex, key);
+ GrTexture* tex2 = proxy->instantiate(ctx->textureProvider());
+ if (tex2) {
+ return set_key_and_return(ctx->textureProvider(), SkSafeRef(tex2), key);
+ }
}
}