diff options
author | bsalomon <bsalomon@google.com> | 2015-02-19 07:24:21 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-02-19 07:24:21 -0800 |
commit | 8718aafec239c93485e45bbe8fed19d9a8def079 (patch) | |
tree | 209402fb1f20c023f822b4af7dd4212e44956821 | |
parent | 2e4414e60b1f98e1736aa1925cbe181ed37d11e8 (diff) |
Rename GrContentKey to GrUniqueKey
Review URL: https://codereview.chromium.org/940463006
-rw-r--r-- | bench/GrResourceCacheBench.cpp | 14 | ||||
-rw-r--r-- | include/gpu/GrContext.h | 12 | ||||
-rw-r--r-- | include/gpu/GrGpuResource.h | 14 | ||||
-rw-r--r-- | include/gpu/GrResourceKey.h | 79 | ||||
-rw-r--r-- | src/effects/SkBlurMaskFilter.cpp | 12 | ||||
-rw-r--r-- | src/effects/SkColorCubeFilter.cpp | 6 | ||||
-rwxr-xr-x | src/gpu/GrContext.cpp | 12 | ||||
-rw-r--r-- | src/gpu/GrGpuResource.cpp | 22 | ||||
-rw-r--r-- | src/gpu/GrGpuResourceCacheAccess.h | 4 | ||||
-rw-r--r-- | src/gpu/GrGpuResourcePriv.h | 24 | ||||
-rw-r--r-- | src/gpu/GrPath.cpp | 6 | ||||
-rw-r--r-- | src/gpu/GrPath.h | 2 | ||||
-rw-r--r-- | src/gpu/GrResourceCache.cpp | 56 | ||||
-rw-r--r-- | src/gpu/GrResourceCache.h | 68 | ||||
-rw-r--r-- | src/gpu/GrStencilAndCoverPathRenderer.cpp | 2 | ||||
-rw-r--r-- | src/gpu/GrStencilAndCoverTextContext.cpp | 6 | ||||
-rw-r--r-- | src/gpu/SkGr.cpp | 50 | ||||
-rw-r--r-- | src/gpu/effects/GrTextureStripAtlas.cpp | 6 | ||||
-rw-r--r-- | tests/GLProgramsTest.cpp | 6 | ||||
-rw-r--r-- | tests/ResourceCacheTest.cpp | 169 |
20 files changed, 302 insertions, 268 deletions
diff --git a/bench/GrResourceCacheBench.cpp b/bench/GrResourceCacheBench.cpp index 61ab4d0a73..def736c8b8 100644 --- a/bench/GrResourceCacheBench.cpp +++ b/bench/GrResourceCacheBench.cpp @@ -29,9 +29,9 @@ public: this->registerWithCache(); } - static void ComputeKey(int i, GrContentKey* key) { - static GrContentKey::Domain kDomain = GrContentKey::GenerateDomain(); - GrContentKey::Builder builder(key, kDomain, 1); + static void ComputeKey(int i, GrUniqueKey* key) { + static GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); + GrUniqueKey::Builder builder(key, kDomain, 1); builder[0] = i; } @@ -43,10 +43,10 @@ private: static void populate_cache(GrGpu* gpu, int resourceCount) { for (int i = 0; i < resourceCount; ++i) { - GrContentKey key; + GrUniqueKey key; BenchResource::ComputeKey(i, &key); GrGpuResource* resource = SkNEW_ARGS(BenchResource, (gpu)); - resource->resourcePriv().setContentKey(key); + resource->resourcePriv().setUniqueKey(key); resource->unref(); } } @@ -126,9 +126,9 @@ protected: SkASSERT(CACHE_SIZE_COUNT == cache->getResourceCount()); for (int i = 0; i < loops; ++i) { for (int k = 0; k < CACHE_SIZE_COUNT; ++k) { - GrContentKey key; + GrUniqueKey key; BenchResource::ComputeKey(k, &key); - SkAutoTUnref<GrGpuResource> resource(cache->findAndRefContentResource(key)); + SkAutoTUnref<GrGpuResource> resource(cache->findAndRefUniqueResource(key)); SkASSERT(resource); } } diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h index 95fe92c0ae..712eeb8334 100644 --- a/include/gpu/GrContext.h +++ b/include/gpu/GrContext.h @@ -169,21 +169,21 @@ public: */ void purgeAllUnlockedResources(); - /** Sets a content key on the resource. The resource must not already have a content key and - * the key must not already be in use for this to succeed. + /** Sets a unique key on the resource. The resource must not already have a unique key and the + * key must not already be in use for this to succeed. */ - bool addResourceToCache(const GrContentKey&, GrGpuResource*); + bool addResourceToCache(const GrUniqueKey&, GrGpuResource*); /** * Finds a resource in the cache, based on the specified key. This is intended for use in * conjunction with addResourceToCache(). The return value will be NULL if not found. The * caller must balance with a call to unref(). */ - GrGpuResource* findAndRefCachedResource(const GrContentKey&); + GrGpuResource* findAndRefCachedResource(const GrUniqueKey&); /** Helper for casting resource to a texture. Caller must be sure that the resource cached with the key is either NULL or a texture and not another resource type. */ - GrTexture* findAndRefCachedTexture(const GrContentKey& key) { + GrTexture* findAndRefCachedTexture(const GrUniqueKey& key) { GrGpuResource* resource = this->findAndRefCachedResource(key); if (resource) { GrTexture* texture = static_cast<GrSurface*>(resource)->asTexture(); @@ -198,7 +198,7 @@ public: * will not be locked or returned. This call does not affect the priority of * the resource for deletion. */ - bool isResourceInCache(const GrContentKey& key) const; + bool isResourceInCache(const GrUniqueKey& key) const; /** * Creates a new text rendering context that is optimal for the diff --git a/include/gpu/GrGpuResource.h b/include/gpu/GrGpuResource.h index aefae27dd5..80b50e308e 100644 --- a/include/gpu/GrGpuResource.h +++ b/include/gpu/GrGpuResource.h @@ -127,7 +127,7 @@ public: enum LifeCycle { /** * The resource is cached and owned by Skia. Resources with this status may be kept alive - * by the cache as either scratch or content resources even when there are no refs to them. + * by the cache as either scratch or unique resources even when there are no refs to them. * The cache may release them whenever there are no refs. */ kCached_LifeCycle, @@ -187,9 +187,9 @@ public: */ uint32_t getUniqueID() const { return fUniqueID; } - /** Returns the current content key for the resource. It will be invalid if the resource has not - been cached by its contents. */ - const GrContentKey& getContentKey() const { return fContentKey; } + /** Returns the current unique key for the resource. It will be invalid if the resource has no + associated unique key. */ + const GrUniqueKey& getUniqueKey() const { return fUniqueKey; } /** * Attach a custom data object to this resource. The data will remain attached @@ -269,8 +269,8 @@ private: virtual size_t onGpuMemorySize() const = 0; // See comments in CacheAccess and ResourcePriv. - bool setContentKey(const GrContentKey& contentKey); - void removeContentKey(); + bool setUniqueKey(const GrUniqueKey&); + void removeUniqueKey(); void notifyIsPurgeable() const; void removeScratchKey(); void makeBudgeted(); @@ -291,7 +291,7 @@ private: static const size_t kInvalidGpuMemorySize = ~static_cast<size_t>(0); GrScratchKey fScratchKey; - GrContentKey fContentKey; + GrUniqueKey fUniqueKey; // This is not ref'ed but abandon() or release() will be called before the GrGpu object // is destroyed. Those calls set will this to NULL. diff --git a/include/gpu/GrResourceKey.h b/include/gpu/GrResourceKey.h index 1eb7d1fd07..ce3e76e2ab 100644 --- a/include/gpu/GrResourceKey.h +++ b/include/gpu/GrResourceKey.h @@ -14,6 +14,10 @@ uint32_t GrResourceKeyHash(const uint32_t* data, size_t size); +/** + * Base class for all GrGpuResource cache keys. There are two types of cache keys. Refer to the + * comments for each key type below. + */ class GrResourceKey { public: uint32_t hash() const { @@ -135,9 +139,25 @@ private: }; /** - * A key used for scratch resources. The key consists of a resource type (subclass) identifier, a - * hash, a data length, and type-specific data. A Builder object is used to initialize the - * key contents. The contents must be initialized before the key can be used. + * A key used for scratch resources. There are three important rules about scratch keys: + * * Multiple resources can share the same scratch key. Therefore resources assigned the same + * scratch key should be interchangeable with respect to the code that uses them. + * * A resource can have at most one scratch key and it is set at resource creation by the + * resource itself. + * * When a scratch resource is ref'ed it will not be returned from the + * cache for a subsequent cache request until all refs are released. This facilitates using + * a scratch key for multiple render-to-texture scenarios. An example is a separable blur: + * + * GrTexture* texture[2]; + * texture[0] = get_scratch_texture(scratchKey); + * texture[1] = get_scratch_texture(scratchKey); // texture[0] is already owned so we will get a + * // different one for texture[1] + * draw_mask(texture[0], path); // draws path mask to texture[0] + * blur_x(texture[0], texture[1]); // blurs texture[0] in y and stores result in texture[1] + * blur_y(texture[1], texture[0]); // blurs texture[1] in y and stores result in texture[0] + * texture[1]->unref(); // texture 1 can now be recycled for the next request with scratchKey + * consume_blur(texture[0]); + * texture[0]->unref(); // texture 0 can now be recycled for the next request with scratchKey */ class GrScratchKey : public GrResourceKey { private: @@ -180,46 +200,55 @@ public: }; /** - * A key used to cache resources based on their content. The key consists of a domain type (use - * case for the cache), a hash, a data length, and domain-specific data. A Builder object is used to - * initialize the key contents. The contents must be initialized before the key can be used. + * A key that allows for exclusive use of a resource for a use case (AKA "domain"). There are three + * rules governing the use of unique keys: + * * Only one resource can have a given unique key at a time. Hence, "unique". + * * A resource can have at most one unique key at a time. + * * Unlike scratch keys, multiple requests for a unique key will return the same + * resource even if the resource already has refs. + * This key type allows a code path to create cached resources for which it is the exclusive user. + * The code path creates a domain which it sets on its keys. This guarantees that there are no + * cross-domain collisions. + * + * Unique keys preempt scratch keys. While a resource has a unique key it is inaccessible via its + * scratch key. It can become scratch again if the unique key is removed. */ -class GrContentKey : public GrResourceKey { +class GrUniqueKey : public GrResourceKey { private: typedef GrResourceKey INHERITED; public: typedef uint32_t Domain; - /** Generate a unique Domain of content keys. */ + /** Generate a Domain for unique keys. */ static Domain GenerateDomain(); - /** Creates an invalid content key. It must be initialized using a Builder object before use. */ - GrContentKey() {} + /** Creates an invalid unique key. It must be initialized using a Builder object before use. */ + GrUniqueKey() {} - GrContentKey(const GrContentKey& that) { *this = that; } + GrUniqueKey(const GrUniqueKey& that) { *this = that; } /** reset() returns the key to the invalid state. */ using INHERITED::reset; using INHERITED::isValid; - GrContentKey& operator=(const GrContentKey& that) { + GrUniqueKey& operator=(const GrUniqueKey& that) { this->INHERITED::operator=(that); return *this; } - bool operator==(const GrContentKey& that) const { + bool operator==(const GrUniqueKey& that) const { return this->INHERITED::operator==(that); } - bool operator!=(const GrContentKey& that) const { return !(*this == that); } + bool operator!=(const GrUniqueKey& that) const { return !(*this == that); } class Builder : public INHERITED::Builder { public: - Builder(GrContentKey* key, Domain domain, int data32Count) + Builder(GrUniqueKey* key, Domain domain, int data32Count) : INHERITED::Builder(key, domain, data32Count) {} /** Used to build a key that wraps another key and adds additional data. */ - Builder(GrContentKey* key, const GrContentKey& innerKey, Domain domain, + Builder(GrUniqueKey* key, const GrUniqueKey& innerKey, Domain domain, int extraData32Cnt) : INHERITED::Builder(key, domain, Data32CntForInnerKey(innerKey) + extraData32Cnt) { SkASSERT(&innerKey != key); @@ -231,7 +260,7 @@ public: } private: - static int Data32CntForInnerKey(const GrContentKey& innerKey) { + static int Data32CntForInnerKey(const GrUniqueKey& innerKey) { // key data + domain return SkToInt((innerKey.dataSize() >> 2) + 1); } @@ -239,16 +268,20 @@ public: }; // The cache listens for these messages to purge junk resources proactively. -class GrContentKeyInvalidatedMessage { +class GrUniqueKeyInvalidatedMessage { public: - explicit GrContentKeyInvalidatedMessage(const GrContentKey& key) : fKey(key) {} - GrContentKeyInvalidatedMessage(const GrContentKeyInvalidatedMessage& that) : fKey(that.fKey) {} - GrContentKeyInvalidatedMessage& operator=(const GrContentKeyInvalidatedMessage& that) { + explicit GrUniqueKeyInvalidatedMessage(const GrUniqueKey& key) : fKey(key) {} + + GrUniqueKeyInvalidatedMessage(const GrUniqueKeyInvalidatedMessage& that) : fKey(that.fKey) {} + + GrUniqueKeyInvalidatedMessage& operator=(const GrUniqueKeyInvalidatedMessage& that) { fKey = that.fKey; return *this; } - const GrContentKey& key() const { return fKey; } + + const GrUniqueKey& key() const { return fKey; } + private: - GrContentKey fKey; + GrUniqueKey fKey; }; #endif diff --git a/src/effects/SkBlurMaskFilter.cpp b/src/effects/SkBlurMaskFilter.cpp index c2c663fafc..c16cc2d54c 100644 --- a/src/effects/SkBlurMaskFilter.cpp +++ b/src/effects/SkBlurMaskFilter.cpp @@ -756,9 +756,9 @@ bool GrRectBlurEffect::CreateBlurProfileTexture(GrContext *context, float sigma, texDesc.fHeight = 1; texDesc.fConfig = kAlpha_8_GrPixelConfig; - static const GrContentKey::Domain kDomain = GrContentKey::GenerateDomain(); - GrContentKey key; - GrContentKey::Builder builder(&key, kDomain, 1); + static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); + GrUniqueKey key; + GrUniqueKey::Builder builder(&key, kDomain, 1); builder[0] = profileSize; builder.finish(); @@ -917,9 +917,9 @@ GrFragmentProcessor* GrRRectBlurEffect::Create(GrContext* context, float sigma, return NULL; } - static const GrContentKey::Domain kDomain = GrContentKey::GenerateDomain(); - GrContentKey key; - GrContentKey::Builder builder(&key, kDomain, 2); + static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); + GrUniqueKey key; + GrUniqueKey::Builder builder(&key, kDomain, 2); builder[0] = blurRadius; builder[1] = cornerRadius; builder.finish(); diff --git a/src/effects/SkColorCubeFilter.cpp b/src/effects/SkColorCubeFilter.cpp index 31876aa1ec..552d000c96 100644 --- a/src/effects/SkColorCubeFilter.cpp +++ b/src/effects/SkColorCubeFilter.cpp @@ -338,9 +338,9 @@ void GrColorCubeEffect::GLProcessor::GenKey(const GrProcessor& proc, } GrFragmentProcessor* SkColorCubeFilter::asFragmentProcessor(GrContext* context) const { - static const GrContentKey::Domain kDomain = GrContentKey::GenerateDomain(); - GrContentKey key; - GrContentKey::Builder builder(&key, kDomain, 2); + static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); + GrUniqueKey key; + GrUniqueKey::Builder builder(&key, kDomain, 2); builder[0] = fUniqueID; builder[1] = fCache.cubeDimension(); builder.finish(); diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index 5e46bb49e8..ef80b5b290 100755 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -1582,20 +1582,20 @@ void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes) fResourceCache->setLimits(maxTextures, maxTextureBytes); } -bool GrContext::addResourceToCache(const GrContentKey& key, GrGpuResource* resource) { +bool GrContext::addResourceToCache(const GrUniqueKey& key, GrGpuResource* resource) { ASSERT_OWNED_RESOURCE(resource); if (!resource || resource->wasDestroyed()) { return false; } - return resource->resourcePriv().setContentKey(key); + return resource->resourcePriv().setUniqueKey(key); } -bool GrContext::isResourceInCache(const GrContentKey& key) const { - return fResourceCache->hasContentKey(key); +bool GrContext::isResourceInCache(const GrUniqueKey& key) const { + return fResourceCache->hasUniqueKey(key); } -GrGpuResource* GrContext::findAndRefCachedResource(const GrContentKey& key) { - return fResourceCache->findAndRefContentResource(key); +GrGpuResource* GrContext::findAndRefCachedResource(const GrUniqueKey& key) { + return fResourceCache->findAndRefUniqueResource(key); } ////////////////////////////////////////////////////////////////////////////// diff --git a/src/gpu/GrGpuResource.cpp b/src/gpu/GrGpuResource.cpp index d86ec7cafd..0c2c9a1849 100644 --- a/src/gpu/GrGpuResource.cpp +++ b/src/gpu/GrGpuResource.cpp @@ -84,30 +84,30 @@ void GrGpuResource::didChangeGpuMemorySize() const { get_resource_cache(fGpu)->resourceAccess().didChangeGpuMemorySize(this, oldSize); } -void GrGpuResource::removeContentKey() { - SkASSERT(fContentKey.isValid()); - get_resource_cache(fGpu)->resourceAccess().willRemoveContentKey(this); - fContentKey.reset(); +void GrGpuResource::removeUniqueKey() { + SkASSERT(fUniqueKey.isValid()); + get_resource_cache(fGpu)->resourceAccess().willRemoveUniqueKey(this); + fUniqueKey.reset(); } -bool GrGpuResource::setContentKey(const GrContentKey& key) { +bool GrGpuResource::setUniqueKey(const GrUniqueKey& key) { // Currently this can only be called once and can't be called when the resource is scratch. SkASSERT(this->internalHasRef()); SkASSERT(key.isValid()); - // Wrapped and uncached resources can never have a content key. + // Wrapped and uncached resources can never have a unique key. if (!this->resourcePriv().isBudgeted()) { return false; } - if (fContentKey.isValid() || this->wasDestroyed()) { + if (fUniqueKey.isValid() || this->wasDestroyed()) { return false; } - fContentKey = key; + fUniqueKey = key; - if (!get_resource_cache(fGpu)->resourceAccess().didSetContentKey(this)) { - fContentKey.reset(); + if (!get_resource_cache(fGpu)->resourceAccess().didSetUniqueKey(this)) { + fUniqueKey.reset(); return false; } return true; @@ -148,7 +148,7 @@ void GrGpuResource::makeBudgeted() { } void GrGpuResource::makeUnbudgeted() { - if (GrGpuResource::kCached_LifeCycle == fLifeCycle && !fContentKey.isValid()) { + if (GrGpuResource::kCached_LifeCycle == fLifeCycle && !fUniqueKey.isValid()) { fLifeCycle = kUncached_LifeCycle; get_resource_cache(fGpu)->resourceAccess().didChangeBudgetStatus(this); } diff --git a/src/gpu/GrGpuResourceCacheAccess.h b/src/gpu/GrGpuResourceCacheAccess.h index 52294cef90..df0ca34bca 100644 --- a/src/gpu/GrGpuResourceCacheAccess.h +++ b/src/gpu/GrGpuResourceCacheAccess.h @@ -23,10 +23,10 @@ class GrGpuResource::CacheAccess { private: /** * Is the resource currently cached as scratch? This means it is cached, has a valid scratch - * key, and does not have a content key. + * key, and does not have a unique key. */ bool isScratch() const { - return !fResource->getContentKey().isValid() && fResource->fScratchKey.isValid() && + return !fResource->getUniqueKey().isValid() && fResource->fScratchKey.isValid() && fResource->resourcePriv().isBudgeted(); } diff --git a/src/gpu/GrGpuResourcePriv.h b/src/gpu/GrGpuResourcePriv.h index 520e217e98..92c53daf0e 100644 --- a/src/gpu/GrGpuResourcePriv.h +++ b/src/gpu/GrGpuResourcePriv.h @@ -18,18 +18,18 @@ class GrGpuResource::ResourcePriv { public: /** - * Sets a content key for the resource. If the resource was previously cached as scratch it will - * be converted to a content resource. Currently this may only be called once per resource. It - * fails if there is already a resource with the same content key. TODO: make this supplant the - * resource that currently is using the content key, allow resources' content keys to change, - * and allow removal of a content key to convert a resource back to scratch. + * Sets a unique key for the resource. If the resource was previously cached as scratch it will + * be converted to a uniquely-keyed resource. Currently this may only be called once per + * resource. It fails if there is already a resource with the same unique key. TODO: make this + * supplant the resource that currently is using the unique key, allow resources' unique keys + * to change, and allow removal of a unique key to convert a resource back to scratch. */ - bool setContentKey(const GrContentKey& contentKey) { - return fResource->setContentKey(contentKey); + bool setUniqueKey(const GrUniqueKey& key) { + return fResource->setUniqueKey(key); } - /** Removes the content key from a resource */ - void removeContentKey() { return fResource->removeContentKey(); } + /** Removes the unique key from a resource */ + void removeUniqueKey() { return fResource->removeUniqueKey(); } /** * If the resource is uncached make it cached. Has no effect on resources that are wrapped or @@ -39,7 +39,7 @@ public: /** * If the resource is cached make it uncached. Has no effect on resources that are wrapped or - * already uncached. Furthermore, resources with content keys cannot be made unbudgeted. + * already uncached. Furthermore, resources with unique keys cannot be made unbudgeted. */ void makeUnbudgeted() { fResource->makeUnbudgeted(); } @@ -48,14 +48,14 @@ public: */ bool isBudgeted() const { bool ret = GrGpuResource::kCached_LifeCycle == fResource->fLifeCycle; - SkASSERT(ret || !fResource->getContentKey().isValid()); + SkASSERT(ret || !fResource->getUniqueKey().isValid()); return ret; } /** * If this resource can be used as a scratch resource this returns a valid scratch key. * Otherwise it returns a key for which isNullScratch is true. The resource may currently be - * used as a content resource rather than scratch. Check isScratch(). + * used as a uniquely keyed resource rather than scratch. Check isScratch(). */ const GrScratchKey& getScratchKey() const { return fResource->fScratchKey; } diff --git a/src/gpu/GrPath.cpp b/src/gpu/GrPath.cpp index a069b0ad1e..3a66865c6e 100644 --- a/src/gpu/GrPath.cpp +++ b/src/gpu/GrPath.cpp @@ -13,9 +13,9 @@ template<int NumBits> static uint64_t get_top_n_float_bits(float f) { return floatBits >> (32 - NumBits); } -void GrPath::ComputeKey(const SkPath& path, const SkStrokeRec& stroke, GrContentKey* key) { - static const GrContentKey::Domain kDomain = GrContentKey::GenerateDomain(); - GrContentKey::Builder builder(key, kDomain, 3); +void GrPath::ComputeKey(const SkPath& path, const SkStrokeRec& stroke, GrUniqueKey* key) { + static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); + GrUniqueKey::Builder builder(key, kDomain, 3); *reinterpret_cast<uint64_t*>(&builder[0]) = ComputeStrokeKey(stroke); builder[2] = path.getGenerationID(); } diff --git a/src/gpu/GrPath.h b/src/gpu/GrPath.h index 56e26b3374..27bbdc0439 100644 --- a/src/gpu/GrPath.h +++ b/src/gpu/GrPath.h @@ -27,7 +27,7 @@ public: fBounds(skPath.getBounds()) { } - static void ComputeKey(const SkPath& path, const SkStrokeRec& stroke, GrContentKey* key); + static void ComputeKey(const SkPath& path, const SkStrokeRec& stroke, GrUniqueKey* key); static uint64_t ComputeStrokeKey(const SkStrokeRec&); bool isEqualTo(const SkPath& path, const SkStrokeRec& stroke) { diff --git a/src/gpu/GrResourceCache.cpp b/src/gpu/GrResourceCache.cpp index 04b7ec5777..8658744d9a 100644 --- a/src/gpu/GrResourceCache.cpp +++ b/src/gpu/GrResourceCache.cpp @@ -13,7 +13,7 @@ #include "SkGr.h" #include "SkMessageBus.h" -DECLARE_SKMESSAGEBUS_MESSAGE(GrContentKeyInvalidatedMessage); +DECLARE_SKMESSAGEBUS_MESSAGE(GrUniqueKeyInvalidatedMessage); ////////////////////////////////////////////////////////////////////////////// @@ -28,12 +28,12 @@ GrScratchKey::ResourceType GrScratchKey::GenerateResourceType() { return static_cast<ResourceType>(type); } -GrContentKey::Domain GrContentKey::GenerateDomain() { +GrUniqueKey::Domain GrUniqueKey::GenerateDomain() { static int32_t gDomain = INHERITED::kInvalidDomain + 1; int32_t domain = sk_atomic_inc(&gDomain); if (domain > SK_MaxU16) { - SkFAIL("Too many Content Key Domains"); + SkFAIL("Too many GrUniqueKey Domains"); } return static_cast<Domain>(domain); @@ -138,8 +138,8 @@ void GrResourceCache::removeResource(GrGpuResource* resource) { if (resource->resourcePriv().getScratchKey().isValid()) { fScratchMap.remove(resource->resourcePriv().getScratchKey(), resource); } - if (resource->getContentKey().isValid()) { - fContentHash.remove(resource->getContentKey()); + if (resource->getUniqueKey().isValid()) { + fUniqueHash.remove(resource->getUniqueKey()); } this->validate(); } @@ -160,7 +160,7 @@ void GrResourceCache::abandonAll() { } SkASSERT(!fScratchMap.count()); - SkASSERT(!fContentHash.count()); + SkASSERT(!fUniqueHash.count()); SkASSERT(!fCount); SkASSERT(!this->getResourceCount()); SkASSERT(!fBytes); @@ -184,7 +184,7 @@ void GrResourceCache::releaseAll() { } SkASSERT(!fScratchMap.count()); - SkASSERT(!fContentHash.count()); + SkASSERT(!fUniqueHash.count()); SkASSERT(!fCount); SkASSERT(!this->getResourceCount()); SkASSERT(!fBytes); @@ -237,24 +237,24 @@ void GrResourceCache::willRemoveScratchKey(const GrGpuResource* resource) { fScratchMap.remove(resource->resourcePriv().getScratchKey(), resource); } -void GrResourceCache::willRemoveContentKey(const GrGpuResource* resource) { +void GrResourceCache::willRemoveUniqueKey(const GrGpuResource* resource) { // Someone has a ref to this resource in order to invalidate it. When the ref count reaches // zero we will get a notifyPurgable() and figure out what to do with it. - SkASSERT(resource->getContentKey().isValid()); - fContentHash.remove(resource->getContentKey()); + SkASSERT(resource->getUniqueKey().isValid()); + fUniqueHash.remove(resource->getUniqueKey()); } -bool GrResourceCache::didSetContentKey(GrGpuResource* resource) { +bool GrResourceCache::didSetUniqueKey(GrGpuResource* resource) { SkASSERT(resource); SkASSERT(this->isInCache(resource)); - SkASSERT(resource->getContentKey().isValid()); + SkASSERT(resource->getUniqueKey().isValid()); - GrGpuResource* res = fContentHash.find(resource->getContentKey()); + GrGpuResource* res = fUniqueHash.find(resource->getUniqueKey()); if (NULL != res) { return false; } - fContentHash.add(resource); + fUniqueHash.add(resource); this->validate(); return true; } @@ -293,9 +293,9 @@ void GrResourceCache::notifyPurgeable(GrGpuResource* resource) { } } else { // Purge the resource immediately if we're over budget - // Also purge if the resource has neither a valid scratch key nor a content key. + // Also purge if the resource has neither a valid scratch key nor a unique key. bool noKey = !resource->resourcePriv().getScratchKey().isValid() && - !resource->getContentKey().isValid(); + !resource->getUniqueKey().isValid(); if (!this->overBudget() && !noKey) { return; } @@ -388,12 +388,12 @@ void GrResourceCache::purgeAllUnlocked() { this->validate(); } -void GrResourceCache::processInvalidContentKeys( - const SkTArray<GrContentKeyInvalidatedMessage>& msgs) { +void GrResourceCache::processInvalidUniqueKeys( + const SkTArray<GrUniqueKeyInvalidatedMessage>& msgs) { for (int i = 0; i < msgs.count(); ++i) { - GrGpuResource* resource = this->findAndRefContentResource(msgs[i].key()); + GrGpuResource* resource = this->findAndRefUniqueResource(msgs[i].key()); if (resource) { - resource->resourcePriv().removeContentKey(); + resource->resourcePriv().removeUniqueKey(); resource->unref(); // will call notifyPurgeable, if it is indeed now purgeable. } } @@ -435,12 +435,12 @@ void GrResourceCache::validate() const { int fCouldBeScratch; int fContent; const ScratchMap* fScratchMap; - const ContentHash* fContentHash; + const UniqueHash* fUniqueHash; Stats(const GrResourceCache* cache) { memset(this, 0, sizeof(*this)); fScratchMap = &cache->fScratchMap; - fContentHash = &cache->fContentHash; + fUniqueHash = &cache->fUniqueHash; } void update(GrGpuResource* resource) { @@ -451,21 +451,21 @@ void GrResourceCache::validate() const { } if (resource->cacheAccess().isScratch()) { - SkASSERT(!resource->getContentKey().isValid()); + SkASSERT(!resource->getUniqueKey().isValid()); ++fScratch; SkASSERT(fScratchMap->countForKey(resource->resourcePriv().getScratchKey())); SkASSERT(!resource->cacheAccess().isWrapped()); } else if (resource->resourcePriv().getScratchKey().isValid()) { SkASSERT(!resource->resourcePriv().isBudgeted() || - resource->getContentKey().isValid()); + resource->getUniqueKey().isValid()); ++fCouldBeScratch; SkASSERT(fScratchMap->countForKey(resource->resourcePriv().getScratchKey())); SkASSERT(!resource->cacheAccess().isWrapped()); } - const GrContentKey& contentKey = resource->getContentKey(); - if (contentKey.isValid()) { + const GrUniqueKey& uniqueKey = resource->getUniqueKey(); + if (uniqueKey.isValid()) { ++fContent; - SkASSERT(fContentHash->find(contentKey) == resource); + SkASSERT(fUniqueHash->find(uniqueKey) == resource); SkASSERT(!resource->cacheAccess().isWrapped()); SkASSERT(resource->resourcePriv().isBudgeted()); } @@ -506,7 +506,7 @@ void GrResourceCache::validate() const { SkASSERT(fBudgetedBytes <= fBudgetedHighWaterBytes); SkASSERT(fBudgetedCount <= fBudgetedHighWaterCount); #endif - SkASSERT(stats.fContent == fContentHash.count()); + SkASSERT(stats.fContent == fUniqueHash.count()); SkASSERT(stats.fScratch + stats.fCouldBeScratch == fScratchMap.count()); // This assertion is not currently valid because we can be in recursive notifyIsPurgeable() diff --git a/src/gpu/GrResourceCache.h b/src/gpu/GrResourceCache.h index 0f19b98ece..a908140aaf 100644 --- a/src/gpu/GrResourceCache.h +++ b/src/gpu/GrResourceCache.h @@ -29,14 +29,15 @@ class SkString; * 1) A scratch key. This is for resources whose allocations are cached but not their contents. * Multiple resources can share the same scratch key. This is so a caller can have two * resource instances with the same properties (e.g. multipass rendering that ping-pongs - * between two temporary surfaces. The scratch key is set at resource creation time and + * between two temporary surfaces). The scratch key is set at resource creation time and * should never change. Resources need not have a scratch key. - * 2) A content key. This key represents the contents of the resource rather than just its - * allocation properties. They may not collide. The content key can be set after resource + * 2) A unique key. This key's meaning is specific to the domain that created the key. Only one + * resource may have a given unique key. The unique key can be set after resource creation * creation. Currently it may only be set once and cannot be cleared. This restriction will * be removed. + * A unique key always takes precedence over a scratch key when a resource has both types of keys. * If a resource has neither key type then it will be deleted as soon as the last reference to it - * is dropped. If a key has both keys the content key takes precedence. + * is dropped. */ class GrResourceCache { public: @@ -116,10 +117,10 @@ public: #endif /** - * Find a resource that matches a content key. + * Find a resource that matches a unique key. */ - GrGpuResource* findAndRefContentResource(const GrContentKey& contentKey) { - GrGpuResource* resource = fContentHash.find(contentKey); + GrGpuResource* findAndRefUniqueResource(const GrUniqueKey& key) { + GrGpuResource* resource = fUniqueHash.find(key); if (resource) { this->refAndMakeResourceMRU(resource); } @@ -127,19 +128,19 @@ public: } /** - * Query whether a content key exists in the cache. + * Query whether a unique key exists in the cache. */ - bool hasContentKey(const GrContentKey& contentKey) const { - return SkToBool(fContentHash.find(contentKey)); + bool hasUniqueKey(const GrUniqueKey& key) const { + return SkToBool(fUniqueHash.find(key)); } - /** Purges resources to become under budget and processes resources with invalidated content + /** Purges resources to become under budget and processes resources with invalidated unique keys. */ void purgeAsNeeded() { - SkTArray<GrContentKeyInvalidatedMessage> invalidKeyMsgs; - fInvalidContentKeyInbox.poll(&invalidKeyMsgs); + SkTArray<GrUniqueKeyInvalidatedMessage> invalidKeyMsgs; + fInvalidUniqueKeyInbox.poll(&invalidKeyMsgs); if (invalidKeyMsgs.count()) { - this->processInvalidContentKeys(invalidKeyMsgs); + this->processInvalidUniqueKeys(invalidKeyMsgs); } if (fBudgetedCount <= fMaxCount && fBudgetedBytes <= fMaxBytes) { return; @@ -178,15 +179,15 @@ private: void removeResource(GrGpuResource*); void notifyPurgeable(GrGpuResource*); void didChangeGpuMemorySize(const GrGpuResource*, size_t oldSize); - bool didSetContentKey(GrGpuResource*); + bool didSetUniqueKey(GrGpuResource*); void willRemoveScratchKey(const GrGpuResource*); - void willRemoveContentKey(const GrGpuResource*); + void willRemoveUniqueKey(const GrGpuResource*); void didChangeBudgetStatus(GrGpuResource*); void refAndMakeResourceMRU(GrGpuResource*); /// @} void internalPurgeAsNeeded(); - void processInvalidContentKeys(const SkTArray<GrContentKeyInvalidatedMessage>&); + void processInvalidUniqueKeys(const SkTArray<GrUniqueKeyInvalidatedMessage>&); void addToNonpurgeableArray(GrGpuResource*); void removeFromNonpurgeableArray(GrGpuResource*); bool overBudget() const { return fBudgetedBytes > fMaxBytes || fBudgetedCount > fMaxCount; } @@ -211,14 +212,12 @@ private: }; typedef SkTMultiMap<GrGpuResource, GrScratchKey, ScratchMapTraits> ScratchMap; - struct ContentHashTraits { - static const GrContentKey& GetKey(const GrGpuResource& r) { - return r.getContentKey(); - } + struct UniqueHashTraits { + static const GrUniqueKey& GetKey(const GrGpuResource& r) { return r.getUniqueKey(); } - static uint32_t Hash(const GrContentKey& key) { return key.hash(); } + static uint32_t Hash(const GrUniqueKey& key) { return key.hash(); } }; - typedef SkTDynamicHash<GrGpuResource, GrContentKey, ContentHashTraits> ContentHash; + typedef SkTDynamicHash<GrGpuResource, GrUniqueKey, UniqueHashTraits> UniqueHash; static bool CompareTimestamp(GrGpuResource* const& a, GrGpuResource* const& b) { return a->cacheAccess().timestamp() < b->cacheAccess().timestamp(); @@ -228,7 +227,7 @@ private: return res->cacheAccess().accessCacheIndex(); } - typedef SkMessageBus<GrContentKeyInvalidatedMessage>::Inbox InvalidContentKeyInbox; + typedef SkMessageBus<GrUniqueKeyInvalidatedMessage>::Inbox InvalidUniqueKeyInbox; typedef SkTDPQueue<GrGpuResource*, CompareTimestamp, AccessResourceIndex> PurgeableQueue; typedef SkTDArray<GrGpuResource*> ResourceArray; @@ -241,8 +240,8 @@ private: // This map holds all resources that can be used as scratch resources. ScratchMap fScratchMap; - // This holds all resources that have content keys. - ContentHash fContentHash; + // This holds all resources that have unique keys. + UniqueHash fUniqueHash; // our budget, used in purgeAsNeeded() int fMaxCount; @@ -266,7 +265,7 @@ private: PFOverBudgetCB fOverBudgetCB; void* fOverBudgetData; - InvalidContentKeyInbox fInvalidContentKeyInbox; + InvalidUniqueKeyInbox fInvalidUniqueKeyInbox; }; class GrResourceCache::ResourceAccess { @@ -298,20 +297,19 @@ private: } /** - * Called by GrGpuResources when their content keys change. + * Called by GrGpuResources when their unique keys change. * * This currently returns a bool and fails when an existing resource has a key that collides - * with the new content key. In the future it will null out the content key for the existing - * resource. The failure is a temporary measure taken because duties are split between two - * cache objects currently. + * with the new key. In the future it will null out the unique key for the existing resource. + * The failure is a temporary measure which will be fixed soon. */ - bool didSetContentKey(GrGpuResource* resource) { return fCache->didSetContentKey(resource); } + bool didSetUniqueKey(GrGpuResource* resource) { return fCache->didSetUniqueKey(resource); } /** - * Called by a GrGpuResource when it removes its content key. + * Called by a GrGpuResource when it removes its unique key. */ - void willRemoveContentKey(GrGpuResource* resource) { - return fCache->willRemoveContentKey(resource); + void willRemoveUniqueKey(GrGpuResource* resource) { + return fCache->willRemoveUniqueKey(resource); } /** diff --git a/src/gpu/GrStencilAndCoverPathRenderer.cpp b/src/gpu/GrStencilAndCoverPathRenderer.cpp index 1b6a2f7c7e..0cef788355 100644 --- a/src/gpu/GrStencilAndCoverPathRenderer.cpp +++ b/src/gpu/GrStencilAndCoverPathRenderer.cpp @@ -72,7 +72,7 @@ GrStencilAndCoverPathRenderer::onGetStencilSupport(const GrDrawTarget*, static GrPath* get_gr_path(GrGpu* gpu, const SkPath& skPath, const SkStrokeRec& stroke) { GrContext* ctx = gpu->getContext(); - GrContentKey key; + GrUniqueKey key; GrPath::ComputeKey(skPath, stroke, &key); SkAutoTUnref<GrPath> path(static_cast<GrPath*>(ctx->findAndRefCachedResource(key))); if (NULL == path || !path->isEqualTo(skPath, stroke)) { diff --git a/src/gpu/GrStencilAndCoverTextContext.cpp b/src/gpu/GrStencilAndCoverTextContext.cpp index 3061ec6b10..9c3ba6af8a 100644 --- a/src/gpu/GrStencilAndCoverTextContext.cpp +++ b/src/gpu/GrStencilAndCoverTextContext.cpp @@ -207,9 +207,9 @@ static GrPathRange* get_gr_glyphs(GrContext* ctx, const SkTypeface* typeface, const SkDescriptor* desc, const SkStrokeRec& stroke) { - static const GrContentKey::Domain kDomain = GrContentKey::GenerateDomain(); - GrContentKey key; - GrContentKey::Builder builder(&key, kDomain, 4); + static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); + GrUniqueKey key; + GrUniqueKey::Builder builder(&key, kDomain, 4); struct GlyphKey { uint32_t fChecksum; uint32_t fTypeface; diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index 5f162cad9a..e353d41b06 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -106,11 +106,11 @@ static Stretch get_stretch_type(const GrContext* ctx, int width, int height, return kNo_Stretch; } -static bool make_stretched_key(const GrContentKey& origKey, Stretch stretch, - GrContentKey* stretchedKey) { +static bool make_stretched_key(const GrUniqueKey& origKey, Stretch stretch, + GrUniqueKey* stretchedKey) { if (origKey.isValid() && kNo_Stretch != stretch) { - static const GrContentKey::Domain kDomain = GrContentKey::GenerateDomain(); - GrContentKey::Builder builder(stretchedKey, origKey, kDomain, 1); + static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); + GrUniqueKey::Builder builder(stretchedKey, origKey, kDomain, 1); builder[0] = stretch; builder.finish(); return true; @@ -119,7 +119,7 @@ static bool make_stretched_key(const GrContentKey& origKey, Stretch stretch, return false; } -static void make_unstretched_key(const SkBitmap& bitmap, GrContentKey* key) { +static void make_unstretched_key(const SkBitmap& bitmap, GrUniqueKey* key) { // Our id includes the offset, width, and height so that bitmaps created by extractSubset() // are unique. uint32_t genID = bitmap.getGenerationID(); @@ -127,8 +127,8 @@ static void make_unstretched_key(const SkBitmap& bitmap, GrContentKey* key) { uint32_t width = SkToU16(bitmap.width()); uint32_t height = SkToU16(bitmap.height()); - static const GrContentKey::Domain kDomain = GrContentKey::GenerateDomain(); - GrContentKey::Builder builder(key, kDomain, 4); + static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); + GrUniqueKey::Builder builder(key, kDomain, 4); builder[0] = genID; builder[1] = origin.fX; builder[2] = origin.fY; @@ -137,8 +137,8 @@ static void make_unstretched_key(const SkBitmap& bitmap, GrContentKey* key) { static void make_bitmap_keys(const SkBitmap& bitmap, Stretch stretch, - GrContentKey* key, - GrContentKey* stretchedKey) { + GrUniqueKey* key, + GrUniqueKey* stretchedKey) { make_unstretched_key(bitmap, key); if (kNo_Stretch != stretch) { make_stretched_key(*key, stretch, stretchedKey); @@ -158,12 +158,12 @@ namespace { // When the SkPixelRef genID changes, invalidate a corresponding GrResource described by key. class BitmapInvalidator : public SkPixelRef::GenIDChangeListener { public: - explicit BitmapInvalidator(const GrContentKey& key) : fMsg(key) {} + explicit BitmapInvalidator(const GrUniqueKey& key) : fMsg(key) {} private: - GrContentKeyInvalidatedMessage fMsg; + GrUniqueKeyInvalidatedMessage fMsg; void onChange() SK_OVERRIDE { - SkMessageBus<GrContentKeyInvalidatedMessage>::Post(fMsg); + SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post(fMsg); } }; @@ -171,7 +171,7 @@ private: static GrTexture* create_texture_for_bmp(GrContext* ctx, - const GrContentKey& optionalKey, + const GrUniqueKey& optionalKey, GrSurfaceDesc desc, SkPixelRef* pixelRefForInvalidationNotification, const void* pixels, @@ -190,7 +190,7 @@ static GrTexture* create_texture_for_bmp(GrContext* ctx, // controls whether the scaling is done using nearest or bilerp filtering. GrTexture* stretch_texture_to_next_pot(GrTexture* inputTexture, Stretch stretch, SkPixelRef* pixelRef, - const GrContentKey& optionalKey) { + const GrUniqueKey& optionalKey) { SkASSERT(kNo_Stretch != stretch); GrContext* context = inputTexture->getContext(); @@ -253,7 +253,7 @@ GrTexture* stretch_texture_to_next_pot(GrTexture* inputTexture, Stretch stretch, } #ifndef SK_IGNORE_ETC1_SUPPORT -static GrTexture *load_etc1_texture(GrContext* ctx, const GrContentKey& optionalKey, +static GrTexture *load_etc1_texture(GrContext* ctx, const GrUniqueKey& optionalKey, const SkBitmap &bm, GrSurfaceDesc desc) { SkAutoTUnref<SkData> data(bm.pixelRef()->refEncodedData()); @@ -302,7 +302,7 @@ static GrTexture *load_etc1_texture(GrContext* ctx, const GrContentKey& optional } #endif // SK_IGNORE_ETC1_SUPPORT -static GrTexture* load_yuv_texture(GrContext* ctx, const GrContentKey& optionalKey, +static GrTexture* load_yuv_texture(GrContext* ctx, const GrUniqueKey& optionalKey, const SkBitmap& bm, const GrSurfaceDesc& desc) { // Subsets are not supported, the whole pixelRef is loaded when using YUV decoding SkPixelRef* pixelRef = bm.pixelRef(); @@ -404,7 +404,7 @@ static GrTexture* load_yuv_texture(GrContext* ctx, const GrContentKey& optionalK static GrTexture* create_unstretched_bitmap_texture(GrContext* ctx, const SkBitmap& origBitmap, - const GrContentKey& optionalKey) { + const GrUniqueKey& optionalKey) { SkBitmap tmpBitmap; const SkBitmap* bitmap = &origBitmap; @@ -465,8 +465,8 @@ static GrTexture* create_unstretched_bitmap_texture(GrContext* ctx, static GrTexture* create_bitmap_texture(GrContext* ctx, const SkBitmap& bmp, Stretch stretch, - const GrContentKey& unstretchedKey, - const GrContentKey& stretchedKey) { + const GrUniqueKey& unstretchedKey, + const GrUniqueKey& stretchedKey) { if (kNo_Stretch != stretch) { SkAutoTUnref<GrTexture> unstretched; // Check if we have the unstretched version in the cache, if not create it. @@ -503,11 +503,11 @@ bool GrIsBitmapInCache(const GrContext* ctx, if (bitmap.isVolatile()) { return false; } - const GrContentKey& key = texture->getContentKey(); + const GrUniqueKey& key = texture->getUniqueKey(); if (!key.isValid()) { return false; } - GrContentKey stretchedKey; + GrUniqueKey stretchedKey; make_stretched_key(key, stretch, &stretchedKey); return ctx->isResourceInCache(stretchedKey); } @@ -517,7 +517,7 @@ bool GrIsBitmapInCache(const GrContext* ctx, return false; } - GrContentKey key, stretchedKey; + GrUniqueKey key, stretchedKey; make_bitmap_keys(bitmap, stretch, &key, &stretchedKey); return ctx->isResourceInCache((kNo_Stretch == stretch) ? key : stretchedKey); } @@ -533,10 +533,10 @@ GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, if (kNo_Stretch == stretch) { return SkRef(result); } - GrContentKey stretchedKey; + GrUniqueKey stretchedKey; // Don't create a key for the resized version if the bmp is volatile. if (!bitmap.isVolatile()) { - const GrContentKey& key = result->getContentKey(); + const GrUniqueKey& key = result->getUniqueKey(); if (key.isValid()) { make_stretched_key(key, stretch, &stretchedKey); GrTexture* stretched = ctx->findAndRefCachedTexture(stretchedKey); @@ -548,7 +548,7 @@ GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, return stretch_texture_to_next_pot(result, stretch, bitmap.pixelRef(), stretchedKey); } - GrContentKey key, resizedKey; + GrUniqueKey key, resizedKey; if (!bitmap.isVolatile()) { // If the bitmap isn't changing try to find a cached copy first. diff --git a/src/gpu/effects/GrTextureStripAtlas.cpp b/src/gpu/effects/GrTextureStripAtlas.cpp index dfee607c0c..73764199c5 100644 --- a/src/gpu/effects/GrTextureStripAtlas.cpp +++ b/src/gpu/effects/GrTextureStripAtlas.cpp @@ -195,9 +195,9 @@ void GrTextureStripAtlas::lockTexture() { texDesc.fHeight = fDesc.fHeight; texDesc.fConfig = fDesc.fConfig; - static const GrContentKey::Domain kDomain = GrContentKey::GenerateDomain(); - GrContentKey key; - GrContentKey::Builder builder(&key, kDomain, 1); + static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); + GrUniqueKey key; + GrUniqueKey::Builder builder(&key, kDomain, 1); builder[0] = static_cast<uint32_t>(fCacheKey); builder.finish(); diff --git a/tests/GLProgramsTest.cpp b/tests/GLProgramsTest.cpp index 34da404714..7736653a91 100644 --- a/tests/GLProgramsTest.cpp +++ b/tests/GLProgramsTest.cpp @@ -108,9 +108,9 @@ static GrRenderTarget* random_render_target(GrContext* context, SkRandom* random texDesc.fConfig = kRGBA_8888_GrPixelConfig; texDesc.fOrigin = random->nextBool() == true ? kTopLeft_GrSurfaceOrigin : kBottomLeft_GrSurfaceOrigin; - GrContentKey key; - static const GrContentKey::Domain kDomain = GrContentKey::GenerateDomain(); - GrContentKey::Builder builder(&key, kDomain, 1); + GrUniqueKey key; + static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); + GrUniqueKey::Builder builder(&key, kDomain, 1); builder[0] = texDesc.fOrigin; builder.finish(); diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp index 620a2fead5..574d713055 100644 --- a/tests/ResourceCacheTest.cpp +++ b/tests/ResourceCacheTest.cpp @@ -199,7 +199,7 @@ static void test_no_key(skiatest::Reporter* reporter) { cache->purgeAllUnlocked(); REPORTER_ASSERT(reporter, 4 == TestResource::NumAlive()); - // Since the resources have neither content nor scratch keys, delete immediately upon unref. + // Since the resources have neither unique nor scratch keys, delete immediately upon unref. a->unref(); REPORTER_ASSERT(reporter, 3 == TestResource::NumAlive()); @@ -225,9 +225,9 @@ static void test_no_key(skiatest::Reporter* reporter) { } // Each integer passed as a template param creates a new domain. -template <int> static void make_content_key(GrContentKey* key, int data) { - static GrContentKey::Domain d = GrContentKey::GenerateDomain(); - GrContentKey::Builder builder(key, d, 1); +template <int> static void make_unique_key(GrUniqueKey* key, int data) { + static GrUniqueKey::Domain d = GrUniqueKey::GenerateDomain(); + GrUniqueKey::Builder builder(key, d, 1); builder[0] = data; } @@ -236,16 +236,16 @@ static void test_budgeting(skiatest::Reporter* reporter) { GrContext* context = mock.context(); GrResourceCache* cache = mock.cache(); - GrContentKey contentKey; - make_content_key<0>(&contentKey, 0); + GrUniqueKey uniqueKey; + make_unique_key<0>(&uniqueKey, 0); - // Create a scratch, a content, and a wrapped resource + // Create a scratch, a unique, and a wrapped resource TestResource* scratch = TestResource::CreateScratch(context->getGpu(), TestResource::kB_SimulatedProperty); scratch->setSize(10); - TestResource* content = SkNEW_ARGS(TestResource, (context->getGpu())); - content->setSize(11); - REPORTER_ASSERT(reporter, content->resourcePriv().setContentKey(contentKey)); + TestResource* unique = SkNEW_ARGS(TestResource, (context->getGpu())); + unique->setSize(11); + REPORTER_ASSERT(reporter, unique->resourcePriv().setUniqueKey(uniqueKey)); TestResource* wrapped = SkNEW_ARGS(TestResource, (context->getGpu(), GrGpuResource::kWrapped_LifeCycle)); wrapped->setSize(12); @@ -253,41 +253,41 @@ static void test_budgeting(skiatest::Reporter* reporter) { (context->getGpu(), GrGpuResource::kUncached_LifeCycle)); unbudgeted->setSize(13); - // Make sure we can't add a content key to the wrapped resource - GrContentKey contentKey2; - make_content_key<0>(&contentKey2, 1); - REPORTER_ASSERT(reporter, !wrapped->resourcePriv().setContentKey(contentKey2)); - REPORTER_ASSERT(reporter, NULL == cache->findAndRefContentResource(contentKey2)); + // Make sure we can't add a unique key to the wrapped resource + GrUniqueKey uniqueKey2; + make_unique_key<0>(&uniqueKey2, 1); + REPORTER_ASSERT(reporter, !wrapped->resourcePriv().setUniqueKey(uniqueKey2)); + REPORTER_ASSERT(reporter, NULL == cache->findAndRefUniqueResource(uniqueKey2)); // Make sure sizes are as we expect REPORTER_ASSERT(reporter, 4 == cache->getResourceCount()); - REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->gpuMemorySize() + + REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize() + wrapped->gpuMemorySize() + unbudgeted->gpuMemorySize() == cache->getResourceBytes()); REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); - REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->gpuMemorySize() == + REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize() == cache->getBudgetedResourceBytes()); // Our refs mean that the resources are non purgeable. cache->purgeAllUnlocked(); REPORTER_ASSERT(reporter, 4 == cache->getResourceCount()); - REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->gpuMemorySize() + + REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize() + wrapped->gpuMemorySize() + unbudgeted->gpuMemorySize() == cache->getResourceBytes()); REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); - REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->gpuMemorySize() == + REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize() == cache->getBudgetedResourceBytes()); // Unreffing the wrapped resource should free it right away. wrapped->unref(); REPORTER_ASSERT(reporter, 3 == cache->getResourceCount()); - REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + content->gpuMemorySize() + + REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize() + unbudgeted->gpuMemorySize() == cache->getResourceBytes()); // Now try freeing the budgeted resources first wrapped = SkNEW_ARGS(TestResource, (context->getGpu(), GrGpuResource::kWrapped_LifeCycle)); scratch->setSize(12); - content->unref(); + unique->unref(); cache->purgeAllUnlocked(); REPORTER_ASSERT(reporter, 3 == cache->getResourceCount()); REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + wrapped->gpuMemorySize() + @@ -321,11 +321,11 @@ static void test_unbudgeted(skiatest::Reporter* reporter) { GrContext* context = mock.context(); GrResourceCache* cache = mock.cache(); - GrContentKey contentKey; - make_content_key<0>(&contentKey, 0); + GrUniqueKey uniqueKey; + make_unique_key<0>(&uniqueKey, 0); TestResource* scratch; - TestResource* content; + TestResource* unique; TestResource* wrapped; TestResource* unbudgeted; @@ -338,10 +338,10 @@ static void test_unbudgeted(skiatest::Reporter* reporter) { REPORTER_ASSERT(reporter, 1 == cache->getBudgetedResourceCount()); REPORTER_ASSERT(reporter, 10 == cache->getBudgetedResourceBytes()); - content = SkNEW_ARGS(TestResource, (context->getGpu())); - content->setSize(11); - REPORTER_ASSERT(reporter, content->resourcePriv().setContentKey(contentKey)); - content->unref(); + unique = SkNEW_ARGS(TestResource, (context->getGpu())); + unique->setSize(11); + REPORTER_ASSERT(reporter, unique->resourcePriv().setUniqueKey(uniqueKey)); + unique->unref(); REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); REPORTER_ASSERT(reporter, 21 == cache->getResourceBytes()); REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); @@ -606,23 +606,23 @@ static void test_scratch_key_consistency(skiatest::Reporter* reporter) { find->unref(); } -static void test_duplicate_content_key(skiatest::Reporter* reporter) { +static void test_duplicate_unique_key(skiatest::Reporter* reporter) { Mock mock(5, 30000); GrContext* context = mock.context(); GrResourceCache* cache = mock.cache(); - GrContentKey key; - make_content_key<0>(&key, 0); + GrUniqueKey key; + make_unique_key<0>(&key, 0); - // Create two resources that we will attempt to register with the same content key. + // Create two resources that we will attempt to register with the same unique key. TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu())); TestResource* b = SkNEW_ARGS(TestResource, (context->getGpu())); a->setSize(11); b->setSize(12); - // Can't set the same content key on two resources. - REPORTER_ASSERT(reporter, a->resourcePriv().setContentKey(key)); - REPORTER_ASSERT(reporter, !b->resourcePriv().setContentKey(key)); + // Can't set the same unique key on two resources. + REPORTER_ASSERT(reporter, a->resourcePriv().setUniqueKey(key)); + REPORTER_ASSERT(reporter, !b->resourcePriv().setUniqueKey(key)); // Still have two resources because b is still reffed. REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); @@ -658,47 +658,47 @@ static void test_purge_invalidated(skiatest::Reporter* reporter) { GrContext* context = mock.context(); GrResourceCache* cache = mock.cache(); - GrContentKey key1, key2, key3; - make_content_key<0>(&key1, 1); - make_content_key<0>(&key2, 2); - make_content_key<0>(&key3, 3); + GrUniqueKey key1, key2, key3; + make_unique_key<0>(&key1, 1); + make_unique_key<0>(&key2, 2); + make_unique_key<0>(&key3, 3); // Add three resources to the cache. Only c is usable as scratch. TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu())); TestResource* b = SkNEW_ARGS(TestResource, (context->getGpu())); TestResource* c = TestResource::CreateScratch(context->getGpu(), TestResource::kA_SimulatedProperty); - a->resourcePriv().setContentKey(key1); - b->resourcePriv().setContentKey(key2); - c->resourcePriv().setContentKey(key3); + a->resourcePriv().setUniqueKey(key1); + b->resourcePriv().setUniqueKey(key2); + c->resourcePriv().setUniqueKey(key3); a->unref(); // hold b until *after* the message is sent. c->unref(); - REPORTER_ASSERT(reporter, cache->hasContentKey(key1)); - REPORTER_ASSERT(reporter, cache->hasContentKey(key2)); - REPORTER_ASSERT(reporter, cache->hasContentKey(key3)); + REPORTER_ASSERT(reporter, cache->hasUniqueKey(key1)); + REPORTER_ASSERT(reporter, cache->hasUniqueKey(key2)); + REPORTER_ASSERT(reporter, cache->hasUniqueKey(key3)); REPORTER_ASSERT(reporter, 3 == TestResource::NumAlive()); - typedef GrContentKeyInvalidatedMessage Msg; - typedef SkMessageBus<GrContentKeyInvalidatedMessage> Bus; + typedef GrUniqueKeyInvalidatedMessage Msg; + typedef SkMessageBus<GrUniqueKeyInvalidatedMessage> Bus; // Invalidate two of the three, they should be purged and no longer accessible via their keys. Bus::Post(Msg(key1)); Bus::Post(Msg(key2)); cache->purgeAsNeeded(); // a should be deleted now, but we still have a ref on b. - REPORTER_ASSERT(reporter, !cache->hasContentKey(key1)); - REPORTER_ASSERT(reporter, !cache->hasContentKey(key2)); + REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key1)); + REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key2)); REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); - REPORTER_ASSERT(reporter, cache->hasContentKey(key3)); + REPORTER_ASSERT(reporter, cache->hasUniqueKey(key3)); // Invalidate the third. Bus::Post(Msg(key3)); cache->purgeAsNeeded(); // we still have a ref on b, c should be recycled as scratch. REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); - REPORTER_ASSERT(reporter, !cache->hasContentKey(key3)); + REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key3)); // make b purgeable. It should be immediately deleted since it has no key. b->unref(); @@ -726,15 +726,15 @@ static void test_cache_chained_purge(skiatest::Reporter* reporter) { GrContext* context = mock.context(); GrResourceCache* cache = mock.cache(); - GrContentKey key1, key2; - make_content_key<0>(&key1, 1); - make_content_key<0>(&key2, 2); + GrUniqueKey key1, key2; + make_unique_key<0>(&key1, 1); + make_unique_key<0>(&key2, 2); TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu())); TestResource* b = SkNEW_ARGS(TestResource, (context->getGpu())); - a->resourcePriv().setContentKey(key1); - b->resourcePriv().setContentKey(key2); + a->resourcePriv().setUniqueKey(key1); + b->resourcePriv().setUniqueKey(key2); // Make a cycle a->setUnrefWhenDestroyed(b); @@ -759,9 +759,9 @@ static void test_cache_chained_purge(skiatest::Reporter* reporter) { } static void test_resource_size_changed(skiatest::Reporter* reporter) { - GrContentKey key1, key2; - make_content_key<0>(&key1, 1); - make_content_key<0>(&key2, 2); + GrUniqueKey key1, key2; + make_unique_key<0>(&key1, 1); + make_unique_key<0>(&key2, 2); // Test changing resources sizes (both increase & decrease). { @@ -770,19 +770,21 @@ static void test_resource_size_changed(skiatest::Reporter* reporter) { GrResourceCache* cache = mock.cache(); TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu())); - a->resourcePriv().setContentKey(key1); + a->resourcePriv().setUniqueKey(key1); a->unref(); TestResource* b = SkNEW_ARGS(TestResource, (context->getGpu())); - b->resourcePriv().setContentKey(key2); + b->resourcePriv().setUniqueKey(key2); b->unref(); REPORTER_ASSERT(reporter, 200 == cache->getResourceBytes()); REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); { - SkAutoTUnref<TestResource> find2(static_cast<TestResource*>(cache->findAndRefContentResource(key2))); + SkAutoTUnref<TestResource> find2( + static_cast<TestResource*>(cache->findAndRefUniqueResource(key2))); find2->setSize(200); - SkAutoTUnref<TestResource> find1(static_cast<TestResource*>(cache->findAndRefContentResource(key1))); + SkAutoTUnref<TestResource> find1( + static_cast<TestResource*>(cache->findAndRefUniqueResource(key1))); find1->setSize(50); } @@ -798,22 +800,23 @@ static void test_resource_size_changed(skiatest::Reporter* reporter) { TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu())); a->setSize(100); - a->resourcePriv().setContentKey(key1); + a->resourcePriv().setUniqueKey(key1); a->unref(); TestResource* b = SkNEW_ARGS(TestResource, (context->getGpu())); b->setSize(100); - b->resourcePriv().setContentKey(key2); + b->resourcePriv().setUniqueKey(key2); b->unref(); REPORTER_ASSERT(reporter, 200 == cache->getResourceBytes()); REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); { - SkAutoTUnref<TestResource> find2(static_cast<TestResource*>(cache->findAndRefContentResource(key2))); + SkAutoTUnref<TestResource> find2(static_cast<TestResource*>( + cache->findAndRefUniqueResource(key2))); find2->setSize(201); } - REPORTER_ASSERT(reporter, !cache->hasContentKey(key1)); + REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key1)); REPORTER_ASSERT(reporter, 201 == cache->getResourceBytes()); REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); @@ -831,19 +834,19 @@ static void test_large_resource_count(skiatest::Reporter* reporter) { GrResourceCache* cache = mock.cache(); for (int i = 0; i < kResourceCnt; ++i) { - GrContentKey key1, key2; - make_content_key<1>(&key1, i); - make_content_key<2>(&key2, i); + GrUniqueKey key1, key2; + make_unique_key<1>(&key1, i); + make_unique_key<2>(&key2, i); TestResource* resource; resource = SkNEW_ARGS(TestResource, (context->getGpu())); - resource->resourcePriv().setContentKey(key1); + resource->resourcePriv().setUniqueKey(key1); resource->setSize(1); resource->unref(); resource = SkNEW_ARGS(TestResource, (context->getGpu())); - resource->resourcePriv().setContentKey(key2); + resource->resourcePriv().setUniqueKey(key2); resource->setSize(1); resource->unref(); } @@ -854,12 +857,12 @@ static void test_large_resource_count(skiatest::Reporter* reporter) { REPORTER_ASSERT(reporter, cache->getResourceBytes() == 2 * kResourceCnt); REPORTER_ASSERT(reporter, cache->getResourceCount() == 2 * kResourceCnt); for (int i = 0; i < kResourceCnt; ++i) { - GrContentKey key1, key2; - make_content_key<1>(&key1, i); - make_content_key<2>(&key2, i); + GrUniqueKey key1, key2; + make_unique_key<1>(&key1, i); + make_unique_key<2>(&key2, i); - REPORTER_ASSERT(reporter, cache->hasContentKey(key1)); - REPORTER_ASSERT(reporter, cache->hasContentKey(key2)); + REPORTER_ASSERT(reporter, cache->hasUniqueKey(key1)); + REPORTER_ASSERT(reporter, cache->hasUniqueKey(key2)); } cache->purgeAllUnlocked(); @@ -870,12 +873,12 @@ static void test_large_resource_count(skiatest::Reporter* reporter) { REPORTER_ASSERT(reporter, cache->getResourceCount() == 0); for (int i = 0; i < kResourceCnt; ++i) { - GrContentKey key1, key2; - make_content_key<1>(&key1, i); - make_content_key<2>(&key2, i); + GrUniqueKey key1, key2; + make_unique_key<1>(&key1, i); + make_unique_key<2>(&key2, i); - REPORTER_ASSERT(reporter, !cache->hasContentKey(key1)); - REPORTER_ASSERT(reporter, !cache->hasContentKey(key2)); + REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key1)); + REPORTER_ASSERT(reporter, !cache->hasUniqueKey(key2)); } } @@ -907,7 +910,7 @@ DEF_GPUTEST(ResourceCache, reporter, factory) { test_budgeting(reporter); test_unbudgeted(reporter); test_unbudgeted_to_scratch(reporter); - test_duplicate_content_key(reporter); + test_duplicate_unique_key(reporter); test_duplicate_scratch_key(reporter); test_remove_scratch_key(reporter); test_scratch_key_consistency(reporter); |