Use GrTextureProvider's uniqueKey setting method rather than directly setting it

Clients will not be able to directly set the uniqueKey on GrTextureProxies. This CL sets up the choke point for the switch over to having uniqueKeys be managed by a third party (the textureProvider).

Change-Id: I5061a970faf77ea0c4a320e021ff7c3ef90a0900
Reviewed-on: https://skia-review.googlesource.com/9140
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Robert Phillips 2017-03-02 10:23:52 -05:00 committed by Skia Commit-Bot
parent bfafcba05a
commit f7cf81aefd
8 changed files with 15 additions and 13 deletions

View File

@ -51,6 +51,7 @@ public:
/** Assigns a unique key to the texture. The texture will be findable via this key using
findTextureByUniqueKey(). If an existing texture has this key, it's key will be removed. */
void assignUniqueKeyToTexture(const GrUniqueKey& key, GrTexture* texture) {
SkASSERT(key.isValid());
this->assignUniqueKeyToResource(key, texture);
}

View File

@ -474,9 +474,10 @@ public:
}
};
static GrTexture* set_key_and_return(GrTexture* tex, const GrUniqueKey& key) {
static GrTexture* set_key_and_return(GrTextureProvider* texProvider,
GrTexture* tex, const GrUniqueKey& key) {
if (key.isValid()) {
tex->resourcePriv().setUniqueKey(key);
texProvider->assignUniqueKeyToTexture(key, tex);
}
return tex;
}
@ -543,7 +544,7 @@ GrTexture* SkImageCacherator::lockTexture(GrContext* ctx, const GrUniqueKey& ori
if (GrTexture* tex = generator->generateTexture(ctx, cacheInfo, fOrigin)) {
SK_HISTOGRAM_ENUMERATION("LockTexturePath", kNative_LockTexturePath,
kLockTexturePathCount);
return set_key_and_return(tex, key);
return set_key_and_return(ctx->textureProvider(), tex, key);
}
}
@ -570,7 +571,7 @@ GrTexture* SkImageCacherator::lockTexture(GrContext* ctx, const GrUniqueKey& ori
if (tex) {
SK_HISTOGRAM_ENUMERATION("LockTexturePath", kYUV_LockTexturePath,
kLockTexturePathCount);
return set_key_and_return(tex.release(), key);
return set_key_and_return(ctx->textureProvider(), tex.release(), key);
}
}
@ -587,7 +588,7 @@ GrTexture* SkImageCacherator::lockTexture(GrContext* ctx, const GrUniqueKey& ori
if (tex) {
SK_HISTOGRAM_ENUMERATION("LockTexturePath", kRGBA_LockTexturePath,
kLockTexturePathCount);
return set_key_and_return(tex, key);
return set_key_and_return(ctx->textureProvider(), tex, key);
}
}
SK_HISTOGRAM_ENUMERATION("LockTexturePath", kFailure_LockTexturePath,

View File

@ -43,7 +43,7 @@ GrTexture* GrBitmapTextureMaker::refOriginalTexture(bool willBeMipped,
tex = GrUploadBitmapToTexture(this->context(), fBitmap);
}
if (tex && fOriginalKey.isValid()) {
tex->resourcePriv().setUniqueKey(fOriginalKey);
this->context()->textureProvider()->assignUniqueKeyToTexture(fOriginalKey, tex);
GrInstallBitmapUniqueKeyInvalidator(fOriginalKey, fBitmap.pixelRef());
}
return tex;

View File

@ -446,7 +446,7 @@ sk_sp<GrTextureProxy> GrClipStackClip::createAlphaClipMask(GrContext* context,
return nullptr;
}
tex->resourcePriv().setUniqueKey(key);
context->textureProvider()->assignUniqueKeyToTexture(key, tex);
add_invalidate_on_pop_message(*fStack, reducedClip.elementsGenID(), key);
return result;
@ -522,7 +522,7 @@ sk_sp<GrTextureProxy> GrClipStackClip::createSoftwareClipMask(
return nullptr;
}
tex->resourcePriv().setUniqueKey(key);
context->textureProvider()->assignUniqueKeyToTexture(key, tex);
add_invalidate_on_pop_message(*fStack, reducedClip.elementsGenID(), key);
return result;
}

View File

@ -161,7 +161,7 @@ GrStencilAttachment* GrResourceProvider::attachStencilAttachment(GrRenderTarget*
// Need to try and create a new stencil
stencil = this->gpu()->createStencilAttachmentForRenderTarget(rt, width, height);
if (stencil) {
stencil->resourcePriv().setUniqueKey(sbKey);
this->assignUniqueKeyToResource(sbKey, stencil);
newStencil = true;
}
}

View File

@ -206,7 +206,7 @@ bool GrSoftwarePathRenderer::onDrawPath(const DrawPathArgs& args) {
sk_sp<GrTexture> texture;
if (useCache) {
texture.reset(args.fContext->textureProvider()->findAndRefTextureByUniqueKey(maskKey));
texture.reset(fTexProvider->findAndRefTextureByUniqueKey(maskKey));
}
if (!texture) {
SkBackingFit fit = useCache ? SkBackingFit::kExact : SkBackingFit::kApprox;
@ -219,7 +219,7 @@ bool GrSoftwarePathRenderer::onDrawPath(const DrawPathArgs& args) {
return false;
}
if (useCache) {
texture->resourcePriv().setUniqueKey(maskKey);
fTexProvider->assignUniqueKeyToTexture(maskKey, texture.get());
}
}
if (inverseFilled) {

View File

@ -56,7 +56,7 @@ GrTexture* GrTextureAdjuster::refCopy(const CopyParams& copyParams) {
GrTexture* copy = CopyOnGpu(texture, contentArea, copyParams);
if (copy) {
if (key.isValid()) {
copy->resourcePriv().setUniqueKey(key);
context->textureProvider()->assignUniqueKeyToTexture(key, copy);
this->didCacheCopy(key);
}
}

View File

@ -288,7 +288,7 @@ sk_sp<GrTextureProxy> GrMakeCachedBitmapProxy(GrContext* context, const SkBitmap
if (!tex) {
tex.reset(GrUploadBitmapToTexture(context, bitmap));
if (tex && originalKey.isValid()) {
tex->resourcePriv().setUniqueKey(originalKey);
context->textureProvider()->assignUniqueKeyToTexture(originalKey, tex.get());
GrInstallBitmapUniqueKeyInvalidator(originalKey, bitmap.pixelRef());
}
}