diff options
author | Robert Phillips <robertphillips@google.com> | 2017-09-21 08:26:08 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-09-21 13:52:10 +0000 |
commit | ae7d3f3992708354a3284bb49066737e36a76f40 (patch) | |
tree | 5f629138138923176da38afe3cb5899fc54a66a5 /src/gpu/GrTextureProxy.cpp | |
parent | 48497462c18533794979cb8020a982f4681fd635 (diff) |
Add native caching of uniquely keyed GrTextureProxies (take 2)
TBR=bsalomon@google.com
Change-Id: I590dcdc85fb60706c7eb06277694791dc04c9141
Reviewed-on: https://skia-review.googlesource.com/49543
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'src/gpu/GrTextureProxy.cpp')
-rw-r--r-- | src/gpu/GrTextureProxy.cpp | 47 |
1 files changed, 44 insertions, 3 deletions
diff --git a/src/gpu/GrTextureProxy.cpp b/src/gpu/GrTextureProxy.cpp index 3cb87b3faf..208ef78790 100644 --- a/src/gpu/GrTextureProxy.cpp +++ b/src/gpu/GrTextureProxy.cpp @@ -7,25 +7,46 @@ #include "GrTextureProxy.h" +#include "GrContext.h" +#include "GrResourceCache.h" + #include "GrTexturePriv.h" GrTextureProxy::GrTextureProxy(const GrSurfaceDesc& srcDesc, SkBackingFit fit, SkBudgeted budgeted, const void* srcData, size_t /*rowBytes*/, uint32_t flags) : INHERITED(srcDesc, fit, budgeted, flags) , fIsMipMapped(srcDesc.fIsMipMapped) - , fMipColorMode(SkDestinationSurfaceColorMode::kLegacy) { + , fMipColorMode(SkDestinationSurfaceColorMode::kLegacy) + , fCache(nullptr) { SkASSERT(!srcData); // currently handled in Make() } GrTextureProxy::GrTextureProxy(sk_sp<GrSurface> surf, GrSurfaceOrigin origin) : INHERITED(std::move(surf), origin, SkBackingFit::kExact) , fIsMipMapped(fTarget->asTexture()->texturePriv().hasMipMaps()) - , fMipColorMode(fTarget->asTexture()->texturePriv().mipColorMode()) { + , fMipColorMode(fTarget->asTexture()->texturePriv().mipColorMode()) + , fCache(nullptr) { + if (fTarget->getUniqueKey().isValid()) { + fUniqueKey = fTarget->getUniqueKey(); + fCache = fTarget->asTexture()->getContext()->getResourceCache(); + } +} + +GrTextureProxy::~GrTextureProxy() { + // Due to the order of cleanup the GrSurface this proxy may have wrapped may have gone away + // at this point. Zero out the pointer so the cache invalidation code doesn't try to use it. + fTarget = nullptr; + if (fUniqueKey.isValid()) { + fCache->processInvalidProxyUniqueKey(fUniqueKey); + } else { + SkASSERT(!fCache); + } } bool GrTextureProxy::instantiate(GrResourceProvider* resourceProvider) { if (!this->instantiateImpl(resourceProvider, 0, /* needsStencil = */ false, - kNone_GrSurfaceFlags, fIsMipMapped, fMipColorMode)) { + kNone_GrSurfaceFlags, fIsMipMapped, fMipColorMode, + fUniqueKey.isValid() ? &fUniqueKey : nullptr)) { return false; } @@ -80,3 +101,23 @@ size_t GrTextureProxy::onUninstantiatedGpuMemorySize() const { return GrSurface::ComputeSize(fConfig, fWidth, fHeight, 1, kHasMipMaps, SkBackingFit::kApprox == fFit); } + +void GrTextureProxy::setUniqueKey(GrResourceCache* cache, const GrUniqueKey& key) { + SkASSERT(key.isValid()); + SkASSERT(!fUniqueKey.isValid()); // proxies can only ever get one uniqueKey + + if (fTarget) { + SkASSERT(!fTarget->getUniqueKey().isValid()); + fTarget->resourcePriv().setUniqueKey(key); + SkASSERT(fTarget->getUniqueKey() == key); + } + + fUniqueKey = key; + fCache = cache; +} + +void GrTextureProxy::clearUniqueKey() { + fUniqueKey.reset(); + fCache = nullptr; +} + |