aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Robert Phillips <robertphillips@google.com>2017-09-20 20:50:37 +0000
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-09-20 20:50:50 +0000
commit76d640d14ea78e1f827a2f545e7f0729cdc2896f (patch)
tree807a1db51245b15ca045f822f3e36c1f4c9e2eb0
parent0ca21466da7441baf471966be8c628d408752a72 (diff)
Revert "Add native caching of uniquely keyed GrTextureProxies"
This reverts commit d4f100dad90ed5beb1b614464d8c4fcb22c0a993. Reason for revert: ASAN Original change's description: > Add native caching of uniquely keyed GrTextureProxies > > Change-Id: I303fe025b7856b8d681a2d35b416c015bd468e1d > Reviewed-on: https://skia-review.googlesource.com/48300 > Commit-Queue: Robert Phillips <robertphillips@google.com> > Reviewed-by: Brian Salomon <bsalomon@google.com> TBR=bsalomon@google.com,robertphillips@google.com,brianosman@google.com Change-Id: I7bbf549d4855ce6d985867c3880eef80080bd3d1 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://skia-review.googlesource.com/49442 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
-rw-r--r--gm/image_pict.cpp4
-rw-r--r--gn/gpu.gni1
-rw-r--r--gn/tests.gni1
-rw-r--r--include/private/GrSurfaceProxy.h2
-rw-r--r--include/private/GrTextureProxy.h35
-rw-r--r--src/gpu/GrBitmapTextureMaker.cpp1
-rw-r--r--src/gpu/GrClipStackClip.cpp2
-rw-r--r--src/gpu/GrRenderTargetProxy.cpp2
-rw-r--r--src/gpu/GrResourceCache.cpp64
-rw-r--r--src/gpu/GrResourceCache.h55
-rw-r--r--src/gpu/GrResourceProvider.cpp17
-rw-r--r--src/gpu/GrResourceProvider.h20
-rw-r--r--src/gpu/GrSurfaceProxy.cpp10
-rw-r--r--src/gpu/GrTextureProxy.cpp44
-rw-r--r--src/gpu/GrTextureProxyCacheAccess.h46
-rw-r--r--src/gpu/GrTextureRenderTargetProxy.cpp9
-rw-r--r--src/gpu/SkGr.cpp1
-rw-r--r--tests/TextureProxyTest.cpp238
18 files changed, 37 insertions, 515 deletions
diff --git a/gm/image_pict.cpp b/gm/image_pict.cpp
index 25c3b1c085..73fedec3a0 100644
--- a/gm/image_pict.cpp
+++ b/gm/image_pict.cpp
@@ -152,7 +152,7 @@ public:
: SkImageGenerator(info)
, fCtx(SkRef(ctx)) {
- sk_sp<SkSurface> surface(SkSurface::MakeRenderTarget(ctx, SkBudgeted::kYes, info, 0,
+ sk_sp<SkSurface> surface(SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info, 0,
kTopLeft_GrSurfaceOrigin, nullptr));
if (surface) {
surface->getCanvas()->clear(0);
@@ -188,7 +188,7 @@ protected:
sk_sp<GrSurfaceContext> dstContext(fCtx->contextPriv().makeDeferredSurfaceContext(
desc,
SkBackingFit::kExact,
- SkBudgeted::kYes));
+ SkBudgeted::kNo));
if (!dstContext) {
return nullptr;
}
diff --git a/gn/gpu.gni b/gn/gpu.gni
index fbc976b70d..1a5687e9e8 100644
--- a/gn/gpu.gni
+++ b/gn/gpu.gni
@@ -185,7 +185,6 @@ skia_gpu_sources = [
"$_src/gpu/GrTessellator.h",
"$_src/gpu/GrTextureOpList.cpp",
"$_src/gpu/GrTextureOpList.h",
- "$_src/gpu/GrTextureProxyCacheAccess.h",
"$_src/gpu/GrTracing.h",
"$_src/gpu/GrTestUtils.cpp",
"$_src/gpu/GrTestUtils.h",
diff --git a/gn/tests.gni b/gn/tests.gni
index 9cea3ea355..c2f3759cd2 100644
--- a/gn/tests.gni
+++ b/gn/tests.gni
@@ -248,7 +248,6 @@ tests_sources = [
"$_tests/TestUtils.cpp",
"$_tests/TextBlobCacheTest.cpp",
"$_tests/TextBlobTest.cpp",
- "$_tests/TextureProxyTest.cpp",
"$_tests/Time.cpp",
"$_tests/TLSTest.cpp",
"$_tests/TopoSortTest.cpp",
diff --git a/include/private/GrSurfaceProxy.h b/include/private/GrSurfaceProxy.h
index fcb839c1fe..12ba91ba91 100644
--- a/include/private/GrSurfaceProxy.h
+++ b/include/private/GrSurfaceProxy.h
@@ -378,7 +378,7 @@ protected:
bool instantiateImpl(GrResourceProvider* resourceProvider, int sampleCnt, bool needsStencil,
GrSurfaceFlags flags, bool isMipMapped,
- SkDestinationSurfaceColorMode mipColorMode, const GrUniqueKey*);
+ SkDestinationSurfaceColorMode mipColorMode);
// For wrapped resources, 'fConfig', 'fWidth', 'fHeight', and 'fOrigin; will always be filled in
// from the wrapped resource.
diff --git a/include/private/GrTextureProxy.h b/include/private/GrTextureProxy.h
index 3634ce4d0a..9db2bb2e50 100644
--- a/include/private/GrTextureProxy.h
+++ b/include/private/GrTextureProxy.h
@@ -12,7 +12,6 @@
#include "GrSurfaceProxy.h"
class GrCaps;
-class GrResourceCache;
class GrResourceProvider;
class GrTextureOpList;
@@ -39,31 +38,6 @@ public:
bool isMipMapped() const { return fIsMipMapped; }
- /**
- * Return the texture proxy's unique key. It will be invalid if the proxy doesn't have one.
- */
- const GrUniqueKey& getUniqueKey() const {
-#ifdef SK_DEBUG
- if (fTarget && fUniqueKey.isValid()) {
- SkASSERT(fTarget->getUniqueKey().isValid());
- // It is possible for a non-keyed proxy to have a uniquely keyed resource assigned to
- // it. This just means that a future user of the resource will be filling it with unique
- // data. However, if the proxy has a unique key its attached resource should also
- // have that key.
- SkASSERT(fUniqueKey == fTarget->getUniqueKey());
- }
-#endif
-
- return fUniqueKey;
- }
-
- /**
- * Internal-only helper class used for manipulations of the resource by the cache.
- */
- class CacheAccess;
- inline CacheAccess cacheAccess();
- inline const CacheAccess cacheAccess() const;
-
protected:
friend class GrSurfaceProxy; // for ctors
@@ -73,8 +47,6 @@ protected:
// Wrapped version
GrTextureProxy(sk_sp<GrSurface>, GrSurfaceOrigin);
- ~GrTextureProxy() override;
-
SkDestinationSurfaceColorMode mipColorMode() const { return fMipColorMode; }
sk_sp<GrSurface> createSurface(GrResourceProvider*) const override;
@@ -83,15 +55,8 @@ private:
bool fIsMipMapped;
SkDestinationSurfaceColorMode fMipColorMode;
- GrUniqueKey fUniqueKey;
- GrResourceCache* fCache; // only set when fUniqueKey is valid
-
size_t onUninstantiatedGpuMemorySize() const override;
- // Methods made available via GrTextureProxy::CacheAccess
- void setUniqueKey(GrResourceCache*, const GrUniqueKey&);
- void clearUniqueKey();
-
// For wrapped proxies the GrTexture pointer is stored in GrIORefProxy.
// For deferred proxies that pointer will be filled in when we need to instantiate
// the deferred resource
diff --git a/src/gpu/GrBitmapTextureMaker.cpp b/src/gpu/GrBitmapTextureMaker.cpp
index 2bf3afe4e1..85e791ef90 100644
--- a/src/gpu/GrBitmapTextureMaker.cpp
+++ b/src/gpu/GrBitmapTextureMaker.cpp
@@ -53,6 +53,7 @@ sk_sp<GrTextureProxy> GrBitmapTextureMaker::refOriginalTextureProxy(bool willBeM
if (proxy && fOriginalKey.isValid()) {
SkASSERT(proxy->origin() == kTopLeft_GrSurfaceOrigin);
this->context()->resourceProvider()->assignUniqueKeyToProxy(fOriginalKey, proxy.get());
+ // MDB TODO (caching): this has to play nice with the GrSurfaceProxy's caching
GrInstallBitmapUniqueKeyInvalidator(fOriginalKey, fBitmap.pixelRef());
}
return proxy;
diff --git a/src/gpu/GrClipStackClip.cpp b/src/gpu/GrClipStackClip.cpp
index 69d81a08a2..165b442d90 100644
--- a/src/gpu/GrClipStackClip.cpp
+++ b/src/gpu/GrClipStackClip.cpp
@@ -420,6 +420,7 @@ sk_sp<GrTextureProxy> GrClipStackClip::createAlphaClipMask(GrContext* context,
SkASSERT(result->origin() == kBottomLeft_GrSurfaceOrigin);
resourceProvider->assignUniqueKeyToProxy(key, result.get());
+ // MDB TODO (caching): this has to play nice with the GrSurfaceProxy's caching
add_invalidate_on_pop_message(*fStack, reducedClip.elementsGenID(), key);
return result;
@@ -558,6 +559,7 @@ sk_sp<GrTextureProxy> GrClipStackClip::createSoftwareClipMask(
SkASSERT(proxy->origin() == kTopLeft_GrSurfaceOrigin);
context->resourceProvider()->assignUniqueKeyToProxy(key, proxy.get());
+ // MDB TODO (caching): this has to play nice with the GrSurfaceProxy's caching
add_invalidate_on_pop_message(*fStack, reducedClip.elementsGenID(), key);
return proxy;
}
diff --git a/src/gpu/GrRenderTargetProxy.cpp b/src/gpu/GrRenderTargetProxy.cpp
index 111ecf6625..fff3d0bcea 100644
--- a/src/gpu/GrRenderTargetProxy.cpp
+++ b/src/gpu/GrRenderTargetProxy.cpp
@@ -53,7 +53,7 @@ bool GrRenderTargetProxy::instantiate(GrResourceProvider* resourceProvider) {
if (!this->instantiateImpl(resourceProvider, fSampleCnt, fNeedsStencil, kFlags,
/* isMipped = */ false,
- SkDestinationSurfaceColorMode::kLegacy, nullptr)) {
+ SkDestinationSurfaceColorMode::kLegacy)) {
return false;
}
SkASSERT(fTarget->asRenderTarget());
diff --git a/src/gpu/GrResourceCache.cpp b/src/gpu/GrResourceCache.cpp
index c207b44a38..f6170c01b6 100644
--- a/src/gpu/GrResourceCache.cpp
+++ b/src/gpu/GrResourceCache.cpp
@@ -10,8 +10,6 @@
#include "GrCaps.h"
#include "GrGpuResourceCacheAccess.h"
-#include "GrTexture.h"
-#include "GrTextureProxyCacheAccess.h"
#include "GrTracing.h"
#include "SkGr.h"
#include "SkMessageBus.h"
@@ -580,8 +578,6 @@ void GrResourceCache::purgeUnlockedResources(size_t bytesToPurge, bool preferScr
void GrResourceCache::processInvalidUniqueKeys(
const SkTArray<GrUniqueKeyInvalidatedMessage>& msgs) {
for (int i = 0; i < msgs.count(); ++i) {
- this->processInvalidProxyUniqueKey(msgs[i].key());
-
GrGpuResource* resource = this->findAndRefUniqueResource(msgs[i].key());
if (resource) {
resource->resourcePriv().removeUniqueKey();
@@ -851,63 +847,3 @@ bool GrResourceCache::isInCache(const GrGpuResource* resource) const {
}
#endif
-
-void GrResourceCache::assignUniqueKeyToProxy(const GrUniqueKey& key, GrTextureProxy* proxy) {
- SkASSERT(key.isValid());
- SkASSERT(proxy);
-
- // If there is already a GrResource with this key then the caller has violated the normal
- // usage pattern of uniquely keyed resources (e.g., they have created one w/o first seeing
- // if it already existed in the cache).
- SkASSERT(!this->findAndRefUniqueResource(key));
-
- // Uncached resources can never have a unique key, unless they're wrapped resources. Wrapped
- // resources are a special case: the unique keys give us a weak ref so that we can reuse the
- // same resource (rather than re-wrapping). When a wrapped resource is no longer referenced,
- // it will always be released - it is never converted to a scratch resource.
- if (SkBudgeted::kNo == proxy->isBudgeted() &&
- (!proxy->priv().isInstantiated() ||
- !proxy->priv().peekSurface()->resourcePriv().refsWrappedObjects())) {
- return;
- }
-
- SkASSERT(!fUniquelyKeyedProxies.find(key)); // multiple proxies can't get the same key
-
- proxy->cacheAccess().setUniqueKey(this, key);
- SkASSERT(proxy->getUniqueKey() == key);
- fUniquelyKeyedProxies.add(proxy);
-}
-
-sk_sp<GrTextureProxy> GrResourceCache::findProxyByUniqueKey(const GrUniqueKey& key,
- GrSurfaceOrigin origin) {
-
- sk_sp<GrTextureProxy> result = sk_ref_sp(fUniquelyKeyedProxies.find(key));
- if (result) {
- SkASSERT(result->origin() == origin);
- return result;
- }
-
- GrGpuResource* resource = findAndRefUniqueResource(key);
- if (!resource) {
- return nullptr;
- }
-
- sk_sp<GrTexture> texture(static_cast<GrSurface*>(resource)->asTexture());
- SkASSERT(texture);
-
- result = GrSurfaceProxy::MakeWrapped(std::move(texture), origin);
- SkASSERT(result->getUniqueKey() == key);
- fUniquelyKeyedProxies.add(result.get());
- return result;
-}
-
-void GrResourceCache::processInvalidProxyUniqueKey(const GrUniqueKey& key) {
- // Note: this method is called for the whole variety of GrGpuResources so often 'key'
- // will not be in 'fUniquelyKeyedProxies'.
- GrTextureProxy* proxy = fUniquelyKeyedProxies.find(key);
- if (proxy) {
- fUniquelyKeyedProxies.remove(key);
- proxy->cacheAccess().clearUniqueKey();
- }
-}
-
diff --git a/src/gpu/GrResourceCache.h b/src/gpu/GrResourceCache.h
index 96323be73c..5cdc5636ea 100644
--- a/src/gpu/GrResourceCache.h
+++ b/src/gpu/GrResourceCache.h
@@ -13,7 +13,6 @@
#include "GrGpuResourcePriv.h"
#include "GrResourceCache.h"
#include "GrResourceKey.h"
-#include "GrTextureProxy.h"
#include "SkMessageBus.h"
#include "SkRefCnt.h"
#include "SkTArray.h"
@@ -157,48 +156,6 @@ public:
return resource;
}
- ///////////////////////////////////////////////////////////////////////////
- // TextureProxies & GrUniqueKeys
- //
- // The two GrResourceCache methods assignUniqueKeyToProxy and findProxyByUniqueKey drive
- // the behavior of uniqueKeys on proxies.
- //
- // assignUniqueKeyToProxy does the following:
- // if the proxy is wrapped, it sets the texture & proxy keys & adds the proxy to the hash
- // if the proxy is deferred, it just set the unique key on the proxy & adds it to the hash
- //
- // Note that when a deferred proxy with a unique key is instantiated, its unique key will be
- // pushed to the backing resource.
- //
- // Futher note, a proxy can only receive a unique key once. It can be removed if Ganesh
- // determines that the key will never be used again but, in that case, the proxy should
- // never receive another key.
- //
- // findProxyByUniqueKey does the following:
- // first looks in the UniqueKeyProxy hash table to see if there is already a proxy w/ the key
- // failing that it looks in the ResourceCache to see there is a texture with that key
- // if so, it will wrap the texture in a proxy, add the proxy to the hash and return it
- // failing that it will return null
-
- /*
- * Associate the provided proxy with the provided unique key.
- */
- void assignUniqueKeyToProxy(const GrUniqueKey&, GrTextureProxy*);
-
- /**
- * Find a texture proxy that is associated with the provided unique key.
- */
- sk_sp<GrTextureProxy> findProxyByUniqueKey(const GrUniqueKey&, GrSurfaceOrigin);
-
- /**
- * Either the proxy attached to the unique key is being deleted (in which case we
- * don't want it cluttering up the hash table) or the client has indicated that
- * it will never refer to the unique key again. In either case, remove the key
- * from the hash table.
- * Note: this does not, by itself, alter unique key attached to the underlying GrTexture.
- */
- void processInvalidProxyUniqueKey(const GrUniqueKey&);
-
/**
* Query whether a unique key exists in the cache.
*/
@@ -292,8 +249,6 @@ public:
// Enumerates all cached resources and dumps their details to traceMemoryDump.
void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const;
- int numUniqueKeyProxies_TestOnly() const;
-
private:
///////////////////////////////////////////////////////////////////////////
/// @name Methods accessible via ResourceAccess
@@ -348,13 +303,6 @@ private:
};
typedef SkTDynamicHash<GrGpuResource, GrUniqueKey, UniqueHashTraits> UniqueHash;
- struct UniquelyKeyedProxyHashTraits {
- static const GrUniqueKey& GetKey(const GrTextureProxy& p) { return p.getUniqueKey(); }
-
- static uint32_t Hash(const GrUniqueKey& key) { return key.hash(); }
- };
- typedef SkTDynamicHash<GrTextureProxy, GrUniqueKey, UniquelyKeyedProxyHashTraits> UniquelyKeyedProxyHash;
-
static bool CompareTimestamp(GrGpuResource* const& a, GrGpuResource* const& b) {
return a->cacheAccess().timestamp() < b->cacheAccess().timestamp();
}
@@ -379,9 +327,6 @@ private:
ScratchMap fScratchMap;
// This holds all resources that have unique keys.
UniqueHash fUniqueHash;
- // This holds the texture proxies that have unique keys. The resourceCache does not get a ref
- // on these proxies but they must send a message to the resourceCache when they are deleted.
- UniquelyKeyedProxyHash fUniquelyKeyedProxies;
// our budget, used in purgeAsNeeded()
int fMaxCount;
diff --git a/src/gpu/GrResourceProvider.cpp b/src/gpu/GrResourceProvider.cpp
index 0182baa977..8dce5497d8 100644
--- a/src/gpu/GrResourceProvider.cpp
+++ b/src/gpu/GrResourceProvider.cpp
@@ -292,6 +292,7 @@ void GrResourceProvider::assignUniqueKeyToTexture(const GrUniqueKey& key, GrText
this->assignUniqueKeyToResource(key, texture);
}
+// MDB TODO (caching): this side-steps the issue of texture proxies with unique IDs
void GrResourceProvider::assignUniqueKeyToProxy(const GrUniqueKey& key, GrTextureProxy* proxy) {
ASSERT_SINGLE_OWNER
SkASSERT(key.isValid());
@@ -299,13 +300,25 @@ void GrResourceProvider::assignUniqueKeyToProxy(const GrUniqueKey& key, GrTextur
return;
}
- fCache->assignUniqueKeyToProxy(key, proxy);
+ if (!proxy->instantiate(this)) {
+ return;
+ }
+ GrTexture* texture = proxy->priv().peekTexture();
+
+ this->assignUniqueKeyToResource(key, texture);
}
+// MDB TODO (caching): this side-steps the issue of texture proxies with unique IDs
sk_sp<GrTextureProxy> GrResourceProvider::findProxyByUniqueKey(const GrUniqueKey& key,
GrSurfaceOrigin origin) {
ASSERT_SINGLE_OWNER
- return this->isAbandoned() ? nullptr : fCache->findProxyByUniqueKey(key, origin);
+
+ sk_sp<GrTexture> texture(this->findAndRefTextureByUniqueKey(key));
+ if (!texture) {
+ return nullptr;
+ }
+
+ return GrSurfaceProxy::MakeWrapped(std::move(texture), origin);
}
const GrBuffer* GrResourceProvider::createPatternedIndexBuffer(const uint16_t* pattern,
diff --git a/src/gpu/GrResourceProvider.h b/src/gpu/GrResourceProvider.h
index 7be8ec1793..1ab1ec42fc 100644
--- a/src/gpu/GrResourceProvider.h
+++ b/src/gpu/GrResourceProvider.h
@@ -45,20 +45,18 @@ public:
return static_cast<T*>(this->findAndRefResourceByUniqueKey(key));
}
- /*
- * Assigns a unique key to a proxy. The proxy will be findable via this key using
- * findProxyByUniqueKey(). It is an error if an existing proxy already has a key.
- */
- void assignUniqueKeyToProxy(const GrUniqueKey&, GrTextureProxy*);
-
- /*
- * Finds a proxy by unique key.
- */
- sk_sp<GrTextureProxy> findProxyByUniqueKey(const GrUniqueKey&, GrSurfaceOrigin);
-
///////////////////////////////////////////////////////////////////////////
// Textures
+ /** 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 assignUniqueKeyToProxy(const GrUniqueKey& key, GrTextureProxy*);
+
+ /** Finds a texture by unique key. If the texture is found it is ref'ed and returned. */
+ // MDB TODO (caching): If this were actually caching proxies (rather than shallowly
+ // wrapping GrSurface caching) we would not need the origin parameter.
+ sk_sp<GrTextureProxy> findProxyByUniqueKey(const GrUniqueKey& key, GrSurfaceOrigin);
+
/**
* Finds a texture that approximately matches the descriptor. Will be at least as large in width
* and height as desc specifies. If desc specifies that the texture should be a render target
diff --git a/src/gpu/GrSurfaceProxy.cpp b/src/gpu/GrSurfaceProxy.cpp
index 433c230881..5918830bf8 100644
--- a/src/gpu/GrSurfaceProxy.cpp
+++ b/src/gpu/GrSurfaceProxy.cpp
@@ -109,12 +109,8 @@ void GrSurfaceProxy::assign(sk_sp<GrSurface> surface) {
bool GrSurfaceProxy::instantiateImpl(GrResourceProvider* resourceProvider, int sampleCnt,
bool needsStencil, GrSurfaceFlags flags, bool isMipMapped,
- SkDestinationSurfaceColorMode mipColorMode,
- const GrUniqueKey* uniqueKey) {
+ SkDestinationSurfaceColorMode mipColorMode) {
if (fTarget) {
- if (uniqueKey) {
- SkASSERT(fTarget->getUniqueKey() == *uniqueKey);
- }
return attach_stencil_if_needed(resourceProvider, fTarget, needsStencil);
}
@@ -124,10 +120,6 @@ bool GrSurfaceProxy::instantiateImpl(GrResourceProvider* resourceProvider, int s
return false;
}
- if (uniqueKey) {
- resourceProvider->assignUniqueKeyToResource(*uniqueKey, surface.get());
- }
-
this->assign(std::move(surface));
return true;
}
diff --git a/src/gpu/GrTextureProxy.cpp b/src/gpu/GrTextureProxy.cpp
index 8a68e03bac..3cb87b3faf 100644
--- a/src/gpu/GrTextureProxy.cpp
+++ b/src/gpu/GrTextureProxy.cpp
@@ -7,43 +7,25 @@
#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)
- , fCache(nullptr) {
+ , fMipColorMode(SkDestinationSurfaceColorMode::kLegacy) {
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())
- , fCache(nullptr) {
- if (fTarget->getUniqueKey().isValid()) {
- fUniqueKey = fTarget->getUniqueKey();
- fCache = fTarget->asTexture()->getContext()->getResourceCache();
- }
-}
-
-GrTextureProxy::~GrTextureProxy() {
- if (fUniqueKey.isValid()) {
- fCache->processInvalidProxyUniqueKey(fUniqueKey);
- } else {
- SkASSERT(!fCache);
- }
+ , fMipColorMode(fTarget->asTexture()->texturePriv().mipColorMode()) {
}
bool GrTextureProxy::instantiate(GrResourceProvider* resourceProvider) {
if (!this->instantiateImpl(resourceProvider, 0, /* needsStencil = */ false,
- kNone_GrSurfaceFlags, fIsMipMapped, fMipColorMode,
- fUniqueKey.isValid() ? &fUniqueKey : nullptr)) {
+ kNone_GrSurfaceFlags, fIsMipMapped, fMipColorMode)) {
return false;
}
@@ -98,23 +80,3 @@ 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;
-}
-
diff --git a/src/gpu/GrTextureProxyCacheAccess.h b/src/gpu/GrTextureProxyCacheAccess.h
deleted file mode 100644
index 79cf845987..0000000000
--- a/src/gpu/GrTextureProxyCacheAccess.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef GrTextureProxyCacheAccess_DEFINED
-#define GrTextureProxyCacheAccess_DEFINED
-
-#include "GrTextureProxy.h"
-
-/**
- * This class allows GrResourceCache increased privileged access to GrTextureProxy objects.
- */
-class GrTextureProxy::CacheAccess {
-private:
- void setUniqueKey(GrResourceCache* cache, const GrUniqueKey& key) {
- fTextureProxy->setUniqueKey(cache, key);
- }
-
- void clearUniqueKey() {
- fTextureProxy->clearUniqueKey();
- }
-
- explicit CacheAccess(GrTextureProxy* textureProxy) : fTextureProxy(textureProxy) {}
- CacheAccess(const CacheAccess&) {} // unimpl
- CacheAccess& operator=(const CacheAccess&); // unimpl
-
- // No taking addresses of this type.
- const CacheAccess* operator&() const;
- CacheAccess* operator&();
-
- GrTextureProxy* fTextureProxy;
-
- friend class GrTextureProxy; // to construct/copy this type.
- friend class GrResourceCache; // to use this type
-};
-
-inline GrTextureProxy::CacheAccess GrTextureProxy::cacheAccess() { return CacheAccess(this); }
-
-inline const GrTextureProxy::CacheAccess GrTextureProxy::cacheAccess() const {
- return CacheAccess(const_cast<GrTextureProxy*>(this));
-}
-
-#endif
diff --git a/src/gpu/GrTextureRenderTargetProxy.cpp b/src/gpu/GrTextureRenderTargetProxy.cpp
index 7515c3df08..4a4d79c531 100644
--- a/src/gpu/GrTextureRenderTargetProxy.cpp
+++ b/src/gpu/GrTextureRenderTargetProxy.cpp
@@ -48,17 +48,10 @@ size_t GrTextureRenderTargetProxy::onUninstantiatedGpuMemorySize() const {
bool GrTextureRenderTargetProxy::instantiate(GrResourceProvider* resourceProvider) {
static constexpr GrSurfaceFlags kFlags = kRenderTarget_GrSurfaceFlag;
- const GrUniqueKey& key = this->getUniqueKey();
-
if (!this->instantiateImpl(resourceProvider, this->numStencilSamples(), this->needsStencil(),
- kFlags, this->isMipMapped(), this->mipColorMode(),
- key.isValid() ? &key : nullptr)) {
+ kFlags, this->isMipMapped(), this->mipColorMode())) {
return false;
}
- if (key.isValid()) {
- SkASSERT(key == this->getUniqueKey());
- }
-
SkASSERT(fTarget->asRenderTarget());
SkASSERT(fTarget->asTexture());
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index b9f75e0821..4943804553 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -266,6 +266,7 @@ sk_sp<GrTextureProxy> GrMakeCachedBitmapProxy(GrResourceProvider* resourceProvid
if (proxy && originalKey.isValid()) {
SkASSERT(proxy->origin() == kTopLeft_GrSurfaceOrigin);
resourceProvider->assignUniqueKeyToProxy(originalKey, proxy.get());
+ // MDB TODO (caching): this has to play nice with the GrSurfaceProxy's caching
GrInstallBitmapUniqueKeyInvalidator(originalKey, bitmap.pixelRef());
}
}
diff --git a/tests/TextureProxyTest.cpp b/tests/TextureProxyTest.cpp
deleted file mode 100644
index 58c29fcb85..0000000000
--- a/tests/TextureProxyTest.cpp
+++ /dev/null
@@ -1,238 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-// This is a GPU-backend specific test.
-
-#include "Test.h"
-
-#if SK_SUPPORT_GPU
-
-#include "GrBackendSurface.h"
-#include "GrContextPriv.h"
-#include "GrResourceCache.h"
-#include "GrResourceProvider.h"
-#include "GrTest.h"
-#include "GrTexture.h"
-#include "GrTextureProxy.h"
-
-#include "SkGr.h"
-#include "SkImage.h"
-
-int GrResourceCache::numUniqueKeyProxies_TestOnly() const {
- return fUniquelyKeyedProxies.count();
-}
-
-static GrSurfaceDesc make_desc(GrSurfaceFlags flags) {
- GrSurfaceDesc desc;
- desc.fFlags = flags;
- desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
- desc.fWidth = 64;
- desc.fHeight = 64;
- desc.fConfig = kRGBA_8888_GrPixelConfig;
- desc.fSampleCnt = 0;
-
- return desc;
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// Basic test
-
-static sk_sp<GrTextureProxy> deferred_tex(GrResourceProvider* provider, SkBackingFit fit) {
- GrSurfaceDesc desc = make_desc(kNone_GrSurfaceFlags);
-
- // Only budgeted & wrapped external proxies get to carry uniqueKeys
- return GrSurfaceProxy::MakeDeferred(provider, desc, fit, SkBudgeted::kYes);
-}
-
-static sk_sp<GrTextureProxy> deferred_texRT(GrResourceProvider* provider, SkBackingFit fit) {
- GrSurfaceDesc desc = make_desc(kRenderTarget_GrSurfaceFlag);
-
- // Only budgeted & wrapped external proxies get to carry uniqueKeys
- return GrSurfaceProxy::MakeDeferred(provider, desc, fit, SkBudgeted::kYes);
-}
-
-static sk_sp<GrTextureProxy> wrapped(GrResourceProvider* provider, SkBackingFit fit) {
- GrSurfaceDesc desc = make_desc(kNone_GrSurfaceFlags);
-
- sk_sp<GrTexture> tex;
- if (SkBackingFit::kApprox == fit) {
- tex = sk_sp<GrTexture>(provider->createApproxTexture(desc, 0));
- } else {
- // Only budgeted & wrapped external proxies get to carry uniqueKeys
- tex = provider->createTexture(desc, SkBudgeted::kYes);
- }
-
- return GrSurfaceProxy::MakeWrapped(std::move(tex), kBottomLeft_GrSurfaceOrigin);
-}
-
-static sk_sp<GrTextureProxy> create_wrapped_backend(GrContext* context, SkBackingFit fit,
- sk_sp<GrTexture>* backingSurface) {
- GrResourceProvider* provider = context->resourceProvider();
-
- GrSurfaceDesc desc = make_desc(kNone_GrSurfaceFlags);
-
- *backingSurface = provider->createTexture(desc, SkBudgeted::kNo);
- if (!(*backingSurface)) {
- return nullptr;
- }
-
- GrBackendTexture backendTex =
- GrTest::CreateBackendTexture(context->contextPriv().getBackend(),
- 64, 64,
- kRGBA_8888_GrPixelConfig,
- (*backingSurface)->getTextureHandle());
-
- return GrSurfaceProxy::MakeWrappedBackend(context, backendTex, kBottomLeft_GrSurfaceOrigin);
-}
-
-
-// This tests the basic capabilities of the uniquely keyed texture proxies. Does assigning
-// and looking them up work, etc.
-static void basic_test(GrContext* context,
- skiatest::Reporter* reporter,
- sk_sp<GrTextureProxy> proxy, bool proxyIsCached) {
- static int id = 1;
-
- GrResourceProvider* provider = context->resourceProvider();
- GrResourceCache* cache = context->getResourceCache();
-
- int startCacheCount = cache->getResourceCount();
-
- REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid());
-
- GrUniqueKey key;
- GrMakeKeyFromImageID(&key, id, SkIRect::MakeWH(64, 64));
- ++id;
-
- // Assigning the uniqueKey adds the proxy to the hash but doesn't force instantiation
- REPORTER_ASSERT(reporter, !cache->numUniqueKeyProxies_TestOnly());
- provider->assignUniqueKeyToProxy(key, proxy.get());
- REPORTER_ASSERT(reporter, 1 == cache->numUniqueKeyProxies_TestOnly());
- REPORTER_ASSERT(reporter, startCacheCount == cache->getResourceCount());
-
- // setUniqueKey had better stick
- REPORTER_ASSERT(reporter, key == proxy->getUniqueKey());
-
- // We just added it, surely we can find it
- REPORTER_ASSERT(reporter, provider->findProxyByUniqueKey(key, kBottomLeft_GrSurfaceOrigin));
- REPORTER_ASSERT(reporter, 1 == cache->numUniqueKeyProxies_TestOnly());
-
- // Once instantiated, the backing resource should have the same key
- SkAssertResult(proxy->instantiate(provider));
- const GrUniqueKey& texKey = proxy->priv().peekSurface()->getUniqueKey();
- REPORTER_ASSERT(reporter, texKey.isValid());
- REPORTER_ASSERT(reporter, key == texKey);
- if (proxyIsCached) {
- REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
- }
-
- // deleting the proxy should delete it from the hash but not the cache
- proxy = nullptr;
- REPORTER_ASSERT(reporter, 0 == cache->numUniqueKeyProxies_TestOnly());
- REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
-
- // If the proxy was cached refinding it should bring it back to life
- proxy = provider->findProxyByUniqueKey(key, kBottomLeft_GrSurfaceOrigin);
- if (proxyIsCached) {
- REPORTER_ASSERT(reporter, proxy);
- REPORTER_ASSERT(reporter, 1 == cache->numUniqueKeyProxies_TestOnly());
- } else {
- REPORTER_ASSERT(reporter, !proxy);
- REPORTER_ASSERT(reporter, 0 == cache->numUniqueKeyProxies_TestOnly());
- }
- REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
-
- // Mega-purging it should remove it from both the hash and the cache
- proxy = nullptr;
- cache->purgeAllUnlocked();
- if (proxyIsCached) {
- REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
- } else {
- REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
- }
-
- // We can bring neither the texture nor proxy back from perma-death
- proxy = provider->findProxyByUniqueKey(key, kBottomLeft_GrSurfaceOrigin);
- REPORTER_ASSERT(reporter, !proxy);
- if (proxyIsCached) {
- REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
- } else {
- REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
- }
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// Invalidation test
-
-// Test if invalidating unique ids operates as expected for texture proxies.
-static void invalidation_test(GrContext* context, skiatest::Reporter* reporter) {
-
- GrResourceCache* cache = context->getResourceCache();
- REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
-
- sk_sp<SkImage> rasterImg;
-
- {
- SkImageInfo ii = SkImageInfo::Make(64, 64, kRGBA_8888_SkColorType, kOpaque_SkAlphaType);
-
- SkBitmap bm;
- bm.allocPixels(ii);
-
- rasterImg = SkImage::MakeFromBitmap(bm);
- REPORTER_ASSERT(reporter, 0 == cache->numUniqueKeyProxies_TestOnly());
- REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
- }
-
- sk_sp<SkImage> textureImg = rasterImg->makeTextureImage(context, nullptr);
- REPORTER_ASSERT(reporter, 1 == cache->numUniqueKeyProxies_TestOnly());
- REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
-
- rasterImg = nullptr; // this invalidates the uniqueKey
-
- // this forces the cache to respond to the inval msg
- int maxNum;
- size_t maxBytes;
- context->getResourceCacheLimits(&maxNum, &maxBytes);
- context->setResourceCacheLimits(maxNum-1, maxBytes);
-
- REPORTER_ASSERT(reporter, 0 == cache->numUniqueKeyProxies_TestOnly());
- REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
-
- textureImg = nullptr;
- context->purgeAllUnlockedResources();
-
- REPORTER_ASSERT(reporter, 0 == cache->numUniqueKeyProxies_TestOnly());
- REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
-}
-
-DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TextureProxyTest, reporter, ctxInfo) {
- GrContext* context = ctxInfo.grContext();
- GrResourceProvider* provider = context->resourceProvider();
- GrResourceCache* cache = context->getResourceCache();
-
- REPORTER_ASSERT(reporter, !cache->numUniqueKeyProxies_TestOnly());
- REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
-
- for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) {
- for (auto create : { deferred_tex, deferred_texRT, wrapped }) {
- REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
- basic_test(context, reporter, create(provider, fit), true);
- }
-
- REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
- sk_sp<GrTexture> backingTex;
- sk_sp<GrTextureProxy> proxy = create_wrapped_backend(context, fit, &backingTex);
- basic_test(context, reporter, std::move(proxy), false);
-
- backingTex = nullptr;
- cache->purgeAllUnlocked();
- }
-
- invalidation_test(context, reporter);
-}
-
-#endif