diff options
Diffstat (limited to 'src/core/SkImageCacherator.cpp')
-rw-r--r-- | src/core/SkImageCacherator.cpp | 80 |
1 files changed, 32 insertions, 48 deletions
diff --git a/src/core/SkImageCacherator.cpp b/src/core/SkImageCacherator.cpp index 64b2e62a33..f0bc9973a6 100644 --- a/src/core/SkImageCacherator.cpp +++ b/src/core/SkImageCacherator.cpp @@ -485,22 +485,12 @@ public: } }; -static GrTexture* set_key_and_return(GrResourceProvider* resourceProvider, - GrTexture* tex, const GrUniqueKey& key) { - if (key.isValid()) { - resourceProvider->assignUniqueKeyToTexture(key, tex); - } - return tex; -} - -#if 0 static void set_key_on_proxy(GrResourceProvider* resourceProvider, GrTextureProxy* proxy, const GrUniqueKey& key) { if (key.isValid()) { resourceProvider->assignUniqueKeyToProxy(key, proxy); } } -#endif sk_sp<SkColorSpace> SkImageCacherator::getColorSpace(GrContext* ctx, SkColorSpace* dstColorSpace) { // TODO: This isn't always correct. Picture generator currently produces textures in N32, @@ -520,9 +510,12 @@ sk_sp<SkColorSpace> SkImageCacherator::getColorSpace(GrContext* ctx, SkColorSpac * 4. Ask the generator to return YUV planes, which the GPU can convert * 5. Ask the generator to return RGB(A) data, which the GPU can convert */ -GrTexture* SkImageCacherator::lockTexture(GrContext* ctx, const GrUniqueKey& origKey, - const SkImage* client, SkImage::CachingHint chint, - bool willBeMipped, SkColorSpace* dstColorSpace) { +sk_sp<GrTextureProxy> SkImageCacherator::lockTextureProxy(GrContext* ctx, + const GrUniqueKey& origKey, + const SkImage* client, + SkImage::CachingHint chint, + bool willBeMipped, + SkColorSpace* dstColorSpace) { // Values representing the various texture lock paths we can take. Used for logging the path // taken to a histogram. enum LockTexturePath { @@ -546,10 +539,10 @@ GrTexture* SkImageCacherator::lockTexture(GrContext* ctx, const GrUniqueKey& ori // 1. Check the cache for a pre-existing one if (key.isValid()) { - if (GrTexture* tex = ctx->resourceProvider()->findAndRefTextureByUniqueKey(key)) { + if (sk_sp<GrTextureProxy> proxy = ctx->resourceProvider()->findProxyByUniqueKey(key)) { SK_HISTOGRAM_ENUMERATION("LockTexturePath", kPreExisting_LockTexturePath, kLockTexturePathCount); - return tex; + return proxy; } } @@ -564,10 +557,8 @@ GrTexture* SkImageCacherator::lockTexture(GrContext* ctx, const GrUniqueKey& ori if (sk_sp<GrTextureProxy> proxy = generator->generateTexture(ctx, cacheInfo, fOrigin)) { SK_HISTOGRAM_ENUMERATION("LockTexturePath", kNative_LockTexturePath, kLockTexturePathCount); - GrTexture* tex2 = proxy->instantiate(ctx->resourceProvider()); - if (tex2) { - return set_key_and_return(ctx->resourceProvider(), SkRef(tex2), key); - } + set_key_on_proxy(ctx->resourceProvider(), proxy.get(), key); + return proxy; } } @@ -593,27 +584,26 @@ GrTexture* SkImageCacherator::lockTexture(GrContext* ctx, const GrUniqueKey& ori if (sk_sp<GrTextureProxy> proxy = provider.refAsTextureProxy(ctx, desc, true)) { SK_HISTOGRAM_ENUMERATION("LockTexturePath", kYUV_LockTexturePath, kLockTexturePathCount); - GrTexture* tex2 = proxy->instantiate(ctx->resourceProvider()); - if (tex2) { - return set_key_and_return(ctx->resourceProvider(), SkRef(tex2), key); - } + set_key_on_proxy(ctx->resourceProvider(), proxy.get(), key); + return proxy; } } // 5. Ask the generator to return RGB(A) data, which the GPU can convert SkBitmap bitmap; if (this->tryLockAsBitmap(&bitmap, client, chint, format, cacheInfo)) { - GrTexture* tex = nullptr; + sk_sp<GrTextureProxy> proxy; if (willBeMipped) { - tex = GrGenerateMipMapsAndUploadToTexture(ctx, bitmap, dstColorSpace); + proxy = GrGenerateMipMapsAndUploadToTextureProxy(ctx, bitmap, dstColorSpace); } - if (!tex) { - tex = GrUploadBitmapToTexture(ctx, bitmap); + if (!proxy) { + proxy = GrUploadBitmapToTextureProxy(ctx->resourceProvider(), bitmap); } - if (tex) { + if (proxy) { SK_HISTOGRAM_ENUMERATION("LockTexturePath", kRGBA_LockTexturePath, kLockTexturePathCount); - return set_key_and_return(ctx->resourceProvider(), tex, key); + set_key_on_proxy(ctx->resourceProvider(), proxy.get(), key); + return proxy; } } SK_HISTOGRAM_ENUMERATION("LockTexturePath", kFailure_LockTexturePath, @@ -623,29 +613,23 @@ GrTexture* SkImageCacherator::lockTexture(GrContext* ctx, const GrUniqueKey& ori /////////////////////////////////////////////////////////////////////////////////////////////////// -GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, const GrSamplerParams& params, - SkColorSpace* dstColorSpace, - sk_sp<SkColorSpace>* texColorSpace, - const SkImage* client, - SkScalar scaleAdjust[2], - SkImage::CachingHint chint) { +sk_sp<GrTextureProxy> SkImageCacherator::lockAsTextureProxy(GrContext* ctx, + const GrSamplerParams& params, + SkColorSpace* dstColorSpace, + sk_sp<SkColorSpace>* texColorSpace, + const SkImage* client, + SkScalar scaleAdjust[2], + SkImage::CachingHint chint) { if (!ctx) { return nullptr; } - return GrImageTextureMaker(ctx, this, client, chint).refTextureForParams(params, dstColorSpace, - texColorSpace, - scaleAdjust); -} - -#else - -GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, const GrSamplerParams&, - SkColorSpace* dstColorSpace, - sk_sp<SkColorSpace>* texColorSpace, - const SkImage* client, - SkScalar scaleAdjust[2], SkImage::CachingHint) { - return nullptr; + sk_sp<GrTexture> tex(GrImageTextureMaker(ctx, this, client, chint).refTextureForParams( + params, + dstColorSpace, + texColorSpace, + scaleAdjust)); + return GrSurfaceProxy::MakeWrapped(std::move(tex)); } #endif |