diff options
-rw-r--r-- | bench/GrResourceCacheBench.cpp | 3 | ||||
-rw-r--r-- | gyp/gpu.gypi | 1 | ||||
-rw-r--r-- | include/gpu/GrGpuResource.h | 9 | ||||
-rwxr-xr-x | src/gpu/GrContext.cpp | 16 | ||||
-rw-r--r-- | src/gpu/GrGpu.cpp | 3 | ||||
-rw-r--r-- | src/gpu/GrGpuResource.cpp | 3 | ||||
-rw-r--r-- | src/gpu/GrGpuResourceCacheAccess.h | 68 | ||||
-rw-r--r-- | src/gpu/GrGpuResourcePriv.h | 88 | ||||
-rw-r--r-- | src/gpu/GrResourceCache.cpp | 45 | ||||
-rw-r--r-- | src/gpu/GrResourceCache.h | 4 | ||||
-rw-r--r-- | src/gpu/GrTest.cpp | 3 | ||||
-rw-r--r-- | src/gpu/gl/GrGLGpu.cpp | 4 | ||||
-rw-r--r-- | src/image/SkImage_Gpu.h | 6 | ||||
-rw-r--r-- | src/image/SkSurface_Gpu.cpp | 6 | ||||
-rw-r--r-- | tests/ResourceCacheTest.cpp | 60 | ||||
-rw-r--r-- | tests/SurfaceTest.cpp | 6 |
16 files changed, 189 insertions, 136 deletions
diff --git a/bench/GrResourceCacheBench.cpp b/bench/GrResourceCacheBench.cpp index 39007c30b2..61ab4d0a73 100644 --- a/bench/GrResourceCacheBench.cpp +++ b/bench/GrResourceCacheBench.cpp @@ -11,6 +11,7 @@ #if SK_SUPPORT_GPU #include "GrGpuResource.h" +#include "GrGpuResourcePriv.h" #include "GrContext.h" #include "GrGpu.h" #include "GrResourceCache.h" @@ -45,7 +46,7 @@ static void populate_cache(GrGpu* gpu, int resourceCount) { GrContentKey key; BenchResource::ComputeKey(i, &key); GrGpuResource* resource = SkNEW_ARGS(BenchResource, (gpu)); - resource->cacheAccess().setContentKey(key); + resource->resourcePriv().setContentKey(key); resource->unref(); } } diff --git a/gyp/gpu.gypi b/gyp/gpu.gypi index f06477fa8e..ad3d357a15 100644 --- a/gyp/gpu.gypi +++ b/gyp/gpu.gypi @@ -92,6 +92,7 @@ '<(skia_src_path)/gpu/GrGpu.cpp', '<(skia_src_path)/gpu/GrGpu.h', '<(skia_src_path)/gpu/GrGpuResourceCacheAccess.h', + '<(skia_src_path)/gpu/GrGpuResourcePriv.h', '<(skia_src_path)/gpu/GrGpuResource.cpp', '<(skia_src_path)/gpu/GrGpuFactory.cpp', '<(skia_src_path)/gpu/GrIndexBuffer.h', diff --git a/include/gpu/GrGpuResource.h b/include/gpu/GrGpuResource.h index 8e983d89c5..baffd9ec83 100644 --- a/include/gpu/GrGpuResource.h +++ b/include/gpu/GrGpuResource.h @@ -207,13 +207,20 @@ public: const SkData* getCustomData() const { return fData.get(); } /** - * Internal-only helper class used for cache manipulations of the reosurce. + * Internal-only helper class used for manipulations of the resource by the cache. */ class CacheAccess; inline CacheAccess cacheAccess(); inline const CacheAccess cacheAccess() const; /** + * Internal-only helper class used for manipulations of the resource by internal code. + */ + class ResourcePriv; + inline ResourcePriv resourcePriv(); + inline const ResourcePriv resourcePriv() const; + + /** * Removes references to objects in the underlying 3D API without freeing them. * Called by CacheAccess. * In general this method should not be called outside of skia. It was diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index 6c6ec50356..26b30a434a 100755 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -13,7 +13,7 @@ #include "GrDefaultGeoProcFactory.h" #include "GrFontCache.h" #include "GrGpuResource.h" -#include "GrGpuResourceCacheAccess.h" +#include "GrGpuResourcePriv.h" #include "GrDistanceFieldTextContext.h" #include "GrDrawTargetCaps.h" #include "GrGpu.h" @@ -249,7 +249,7 @@ GrTexture* GrContext::createTexture(const GrSurfaceDesc& desc, bool budgeted, co if (!srcData || texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig, srcData, rowBytes)) { if (!budgeted) { - texture->cacheAccess().makeUnbudgeted(); + texture->resourcePriv().makeUnbudgeted(); } return texture; } @@ -335,15 +335,7 @@ GrTexture* GrContext::internalRefScratchTexture(const GrSurfaceDesc& inDesc, uin } if (!(kNoCreate_ScratchTextureFlag & flags)) { - GrTexture* texture = fGpu->createTexture(*desc, true, NULL, 0); - #ifdef SK_DEBUG - if (fGpu->caps()->reuseScratchTextures() || (desc->fFlags & kRenderTarget_GrSurfaceFlag)) { - GrScratchKey key; - GrTexturePriv::ComputeScratchKey(*desc, &key); - SkASSERT(NULL == texture || texture->cacheAccess().getScratchKey() == key); - } - #endif - return texture; + return fGpu->createTexture(*desc, true, NULL, 0); } return NULL; @@ -1585,7 +1577,7 @@ bool GrContext::addResourceToCache(const GrContentKey& key, GrGpuResource* resou if (!resource || resource->wasDestroyed()) { return false; } - return resource->cacheAccess().setContentKey(key); + return resource->resourcePriv().setContentKey(key); } bool GrContext::isResourceInCache(const GrContentKey& key) const { diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp index d23d4524a9..eef965e5b6 100644 --- a/src/gpu/GrGpu.cpp +++ b/src/gpu/GrGpu.cpp @@ -12,6 +12,7 @@ #include "GrBufferAllocPool.h" #include "GrContext.h" #include "GrDrawTargetCaps.h" +#include "GrGpuResourcePriv.h" #include "GrIndexBuffer.h" #include "GrResourceCache.h" #include "GrStencilBuffer.h" @@ -72,7 +73,7 @@ GrTexture* GrGpu::createTexture(const GrSurfaceDesc& desc, bool budgeted, } } if (!this->caps()->reuseScratchTextures() && !isRT) { - tex->cacheAccess().removeScratchKey(); + tex->resourcePriv().removeScratchKey(); } if (tex) { fStats.incTextureCreates(); diff --git a/src/gpu/GrGpuResource.cpp b/src/gpu/GrGpuResource.cpp index 7f65af25d4..dbf5d8c2bb 100644 --- a/src/gpu/GrGpuResource.cpp +++ b/src/gpu/GrGpuResource.cpp @@ -9,6 +9,7 @@ #include "GrGpuResource.h" #include "GrResourceCache.h" #include "GrGpu.h" +#include "GrGpuResourcePriv.h" static inline GrResourceCache* get_resource_cache(GrGpu* gpu) { SkASSERT(gpu); @@ -94,7 +95,7 @@ bool GrGpuResource::setContentKey(const GrContentKey& key) { SkASSERT(key.isValid()); // Wrapped and uncached resources can never have a content key. - if (!this->cacheAccess().isBudgeted()) { + if (!this->resourcePriv().isBudgeted()) { return false; } diff --git a/src/gpu/GrGpuResourceCacheAccess.h b/src/gpu/GrGpuResourceCacheAccess.h index 6c99d08e46..922e3b36b5 100644 --- a/src/gpu/GrGpuResourceCacheAccess.h +++ b/src/gpu/GrGpuResourceCacheAccess.h @@ -10,74 +10,31 @@ #define GrGpuResourceCacheAccess_DEFINED #include "GrGpuResource.h" +#include "GrGpuResourcePriv.h" + +namespace skiatest { + class Reporter; +} /** - * This class allows code internal to Skia privileged access to manage the cache keys of a - * GrGpuResource object. + * This class allows GrResourceCache increased privileged access to GrGpuResource objects. */ class GrGpuResource::CacheAccess { -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. - */ - bool setContentKey(const GrContentKey& contentKey) { - return fResource->setContentKey(contentKey); - } - - void removeContentKey() { return fResource->removeContentKey(); } - +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. */ bool isScratch() const { return !fResource->getContentKey().isValid() && fResource->fScratchKey.isValid() && - this->isBudgeted(); + fResource->resourcePriv().isBudgeted(); } - /** - * 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(). - */ - const GrScratchKey& getScratchKey() const { return fResource->fScratchKey; } - - /** - * If the resource has a scratch key, the key will be removed. Since scratch keys are installed - * at resource creation time, this means the resource will never again be used as scratch. - */ - void removeScratchKey() const { fResource->removeScratchKey(); } - /** * Is the resource object wrapping an externally allocated GPU resource? */ bool isWrapped() const { return GrGpuResource::kWrapped_LifeCycle == fResource->fLifeCycle; } - - /** - * Does the resource count against the resource budget? - */ - bool isBudgeted() const { - bool ret = GrGpuResource::kCached_LifeCycle == fResource->fLifeCycle; - SkASSERT(ret || !fResource->getContentKey().isValid()); - return ret; - } - - /** - * If the resource is uncached make it cached. Has no effect on resources that are wrapped or - * already cached. - */ - void makeBudgeted() { fResource->makeBudgeted(); } - - /** - * 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. - */ - void makeUnbudgeted() { fResource->makeUnbudgeted(); } - + /** * Called by the cache to delete the resource under normal circumstances. */ @@ -98,9 +55,8 @@ public: } } -private: - CacheAccess(GrGpuResource* resource) : fResource(resource) { } - CacheAccess(const CacheAccess& that) : fResource(that.fResource) { } + CacheAccess(GrGpuResource* resource) : fResource(resource) {} + CacheAccess(const CacheAccess& that) : fResource(that.fResource) {} CacheAccess& operator=(const CacheAccess&); // unimpl // No taking addresses of this type. @@ -110,6 +66,8 @@ private: GrGpuResource* fResource; friend class GrGpuResource; // to construct/copy this type. + friend class GrResourceCache; // to use this type + friend void test_unbudgeted_to_scratch(skiatest::Reporter* reporter); // for unit testing }; inline GrGpuResource::CacheAccess GrGpuResource::cacheAccess() { return CacheAccess(this); } diff --git a/src/gpu/GrGpuResourcePriv.h b/src/gpu/GrGpuResourcePriv.h new file mode 100644 index 0000000000..520e217e98 --- /dev/null +++ b/src/gpu/GrGpuResourcePriv.h @@ -0,0 +1,88 @@ + +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef GrGpuResourcePriv_DEFINED +#define GrGpuResourcePriv_DEFINED + +#include "GrGpuResource.h" + +/** + * This class allows code internal to Skia privileged access to manage the cache keys and budget + * status of a GrGpuResource object. + */ +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. + */ + bool setContentKey(const GrContentKey& contentKey) { + return fResource->setContentKey(contentKey); + } + + /** Removes the content key from a resource */ + void removeContentKey() { return fResource->removeContentKey(); } + + /** + * If the resource is uncached make it cached. Has no effect on resources that are wrapped or + * already cached. + */ + void makeBudgeted() { fResource->makeBudgeted(); } + + /** + * 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. + */ + void makeUnbudgeted() { fResource->makeUnbudgeted(); } + + /** + * Does the resource count against the resource budget? + */ + bool isBudgeted() const { + bool ret = GrGpuResource::kCached_LifeCycle == fResource->fLifeCycle; + SkASSERT(ret || !fResource->getContentKey().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(). + */ + const GrScratchKey& getScratchKey() const { return fResource->fScratchKey; } + + /** + * If the resource has a scratch key, the key will be removed. Since scratch keys are installed + * at resource creation time, this means the resource will never again be used as scratch. + */ + void removeScratchKey() const { fResource->removeScratchKey(); } + +protected: + ResourcePriv(GrGpuResource* resource) : fResource(resource) { } + ResourcePriv(const ResourcePriv& that) : fResource(that.fResource) {} + ResourcePriv& operator=(const CacheAccess&); // unimpl + + // No taking addresses of this type. + const ResourcePriv* operator&() const; + ResourcePriv* operator&(); + + GrGpuResource* fResource; + + friend class GrGpuResource; // to construct/copy this type. +}; + +inline GrGpuResource::ResourcePriv GrGpuResource::resourcePriv() { return ResourcePriv(this); } + +inline const GrGpuResource::ResourcePriv GrGpuResource::resourcePriv() const { + return ResourcePriv(const_cast<GrGpuResource*>(this)); +} + +#endif diff --git a/src/gpu/GrResourceCache.cpp b/src/gpu/GrResourceCache.cpp index 2b842a8f08..5cb1dd2a94 100644 --- a/src/gpu/GrResourceCache.cpp +++ b/src/gpu/GrResourceCache.cpp @@ -8,8 +8,7 @@ #include "GrResourceCache.h" -#include "GrGpuResource.h" - +#include "GrGpuResourceCacheAccess.h" #include "SkChecksum.h" #include "SkGr.h" #include "SkMessageBus.h" @@ -101,7 +100,7 @@ void GrResourceCache::insertResource(GrGpuResource* resource) { fHighWaterCount = SkTMax(fCount, fHighWaterCount); fHighWaterBytes = SkTMax(fBytes, fHighWaterBytes); #endif - if (resource->cacheAccess().isBudgeted()) { + if (resource->resourcePriv().isBudgeted()) { ++fBudgetedCount; fBudgetedBytes += size; #if GR_CACHE_STATS @@ -109,9 +108,9 @@ void GrResourceCache::insertResource(GrGpuResource* resource) { fBudgetedHighWaterBytes = SkTMax(fBudgetedBytes, fBudgetedHighWaterBytes); #endif } - if (resource->cacheAccess().getScratchKey().isValid()) { + if (resource->resourcePriv().getScratchKey().isValid()) { SkASSERT(!resource->cacheAccess().isWrapped()); - fScratchMap.insert(resource->cacheAccess().getScratchKey(), resource); + fScratchMap.insert(resource->resourcePriv().getScratchKey(), resource); } this->purgeAsNeeded(); @@ -123,14 +122,14 @@ void GrResourceCache::removeResource(GrGpuResource* resource) { size_t size = resource->gpuMemorySize(); --fCount; fBytes -= size; - if (resource->cacheAccess().isBudgeted()) { + if (resource->resourcePriv().isBudgeted()) { --fBudgetedCount; fBudgetedBytes -= size; } fResources.remove(resource); - if (resource->cacheAccess().getScratchKey().isValid()) { - fScratchMap.remove(resource->cacheAccess().getScratchKey(), resource); + if (resource->resourcePriv().getScratchKey().isValid()) { + fScratchMap.remove(resource->resourcePriv().getScratchKey(), resource); } if (resource->getContentKey().isValid()) { fContentHash.remove(resource->getContentKey()); @@ -217,8 +216,8 @@ GrGpuResource* GrResourceCache::findAndRefScratchResource(const GrScratchKey& sc } void GrResourceCache::willRemoveScratchKey(const GrGpuResource* resource) { - SkASSERT(resource->cacheAccess().getScratchKey().isValid()); - fScratchMap.remove(resource->cacheAccess().getScratchKey(), resource); + SkASSERT(resource->resourcePriv().getScratchKey().isValid()); + fScratchMap.remove(resource->resourcePriv().getScratchKey(), resource); } void GrResourceCache::willRemoveContentKey(const GrGpuResource* resource) { @@ -268,14 +267,14 @@ void GrResourceCache::notifyPurgeable(GrGpuResource* resource) { if (resource->cacheAccess().isWrapped()) { release = true; - } else if (!resource->cacheAccess().isBudgeted()) { + } else if (!resource->resourcePriv().isBudgeted()) { // Check whether this resource could still be used as a scratch resource. - if (resource->cacheAccess().getScratchKey().isValid()) { + if (resource->resourcePriv().getScratchKey().isValid()) { // We won't purge an existing resource to make room for this one. bool underBudget = fBudgetedCount < fMaxCount && fBudgetedBytes + resource->gpuMemorySize() <= fMaxBytes; if (underBudget) { - resource->cacheAccess().makeBudgeted(); + resource->resourcePriv().makeBudgeted(); } else { release = true; } @@ -287,7 +286,7 @@ void GrResourceCache::notifyPurgeable(GrGpuResource* resource) { bool overBudget = fBudgetedCount > fMaxCount || fBudgetedBytes > fMaxBytes; // Also purge if the resource has neither a valid scratch key nor a content key. - bool noKey = !resource->cacheAccess().getScratchKey().isValid() && + bool noKey = !resource->resourcePriv().getScratchKey().isValid() && !resource->getContentKey().isValid(); if (overBudget || noKey) { release = true; @@ -314,7 +313,7 @@ void GrResourceCache::didChangeGpuMemorySize(const GrGpuResource* resource, size #if GR_CACHE_STATS fHighWaterBytes = SkTMax(fBytes, fHighWaterBytes); #endif - if (resource->cacheAccess().isBudgeted()) { + if (resource->resourcePriv().isBudgeted()) { fBudgetedBytes += delta; #if GR_CACHE_STATS fBudgetedHighWaterBytes = SkTMax(fBudgetedBytes, fBudgetedHighWaterBytes); @@ -332,7 +331,7 @@ void GrResourceCache::didChangeBudgetStatus(GrGpuResource* resource) { size_t size = resource->gpuMemorySize(); - if (resource->cacheAccess().isBudgeted()) { + if (resource->resourcePriv().isBudgeted()) { ++fBudgetedCount; fBudgetedBytes += size; #if GR_CACHE_STATS @@ -418,7 +417,7 @@ void GrResourceCache::processInvalidContentKeys( for (int i = 0; i < msgs.count(); ++i) { GrGpuResource* resource = this->findAndRefContentResource(msgs[i].key()); if (resource) { - resource->cacheAccess().removeContentKey(); + resource->resourcePriv().removeContentKey(); resource->unref(); // will call notifyPurgeable, if it is indeed now purgeable. } } @@ -455,13 +454,13 @@ void GrResourceCache::validate() const { if (resource->cacheAccess().isScratch()) { SkASSERT(!resource->getContentKey().isValid()); ++scratch; - SkASSERT(fScratchMap.countForKey(resource->cacheAccess().getScratchKey())); + SkASSERT(fScratchMap.countForKey(resource->resourcePriv().getScratchKey())); SkASSERT(!resource->cacheAccess().isWrapped()); - } else if (resource->cacheAccess().getScratchKey().isValid()) { - SkASSERT(!resource->cacheAccess().isBudgeted() || + } else if (resource->resourcePriv().getScratchKey().isValid()) { + SkASSERT(!resource->resourcePriv().isBudgeted() || resource->getContentKey().isValid()); ++couldBeScratch; - SkASSERT(fScratchMap.countForKey(resource->cacheAccess().getScratchKey())); + SkASSERT(fScratchMap.countForKey(resource->resourcePriv().getScratchKey())); SkASSERT(!resource->cacheAccess().isWrapped()); } const GrContentKey& contentKey = resource->getContentKey(); @@ -469,10 +468,10 @@ void GrResourceCache::validate() const { ++content; SkASSERT(fContentHash.find(contentKey) == resource); SkASSERT(!resource->cacheAccess().isWrapped()); - SkASSERT(resource->cacheAccess().isBudgeted()); + SkASSERT(resource->resourcePriv().isBudgeted()); } - if (resource->cacheAccess().isBudgeted()) { + if (resource->resourcePriv().isBudgeted()) { ++budgetedCount; budgetedBytes += resource->gpuMemorySize(); } diff --git a/src/gpu/GrResourceCache.h b/src/gpu/GrResourceCache.h index 522641ba37..3e4ededc9e 100644 --- a/src/gpu/GrResourceCache.h +++ b/src/gpu/GrResourceCache.h @@ -10,7 +10,7 @@ #define GrResourceCache_DEFINED #include "GrGpuResource.h" -#include "GrGpuResourceCacheAccess.h" +#include "GrGpuResourcePriv.h" #include "GrResourceKey.h" #include "SkMessageBus.h" #include "SkRefCnt.h" @@ -198,7 +198,7 @@ private: struct ScratchMapTraits { static const GrScratchKey& GetKey(const GrGpuResource& r) { - return r.cacheAccess().getScratchKey(); + return r.resourcePriv().getScratchKey(); } static uint32_t Hash(const GrScratchKey& key) { return key.hash(); } diff --git a/src/gpu/GrTest.cpp b/src/gpu/GrTest.cpp index 14259e6b38..72fde041b1 100644 --- a/src/gpu/GrTest.cpp +++ b/src/gpu/GrTest.cpp @@ -8,6 +8,7 @@ #include "GrTest.h" +#include "GrGpuResourceCacheAccess.h" #include "GrInOrderDrawBuffer.h" #include "GrResourceCache.h" #include "SkString.h" @@ -96,7 +97,7 @@ void GrResourceCache::dumpStats(SkString* out) const { if (resource->cacheAccess().isWrapped()) { ++wrapped; } - if (!resource->cacheAccess().isBudgeted()) { + if (!resource->resourcePriv().isBudgeted()) { unbudgetedSize += resource->gpuMemorySize(); } } diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp index 21d2f6327b..5813d5d0f6 100644 --- a/src/gpu/gl/GrGLGpu.cpp +++ b/src/gpu/gl/GrGLGpu.cpp @@ -9,7 +9,7 @@ #include "GrGLGpu.h" #include "GrGLStencilBuffer.h" #include "GrGLTextureRenderTarget.h" -#include "GrGpuResourceCacheAccess.h" +#include "GrGpuResourcePriv.h" #include "GrPipeline.h" #include "GrSurfacePriv.h" #include "GrTemplates.h" @@ -1186,7 +1186,7 @@ bool GrGLGpu::createStencilBufferForRenderTarget(GrRenderTarget* rt, bool budget } // Remove the scratch key from this resource so we don't grab it from the cache ever // again. - sb->cacheAccess().removeScratchKey(); + sb->resourcePriv().removeScratchKey(); // Set this to 0 since we handed the valid ID off to the failed stencil buffer resource. sbDesc.fRenderbufferID = 0; } diff --git a/src/image/SkImage_Gpu.h b/src/image/SkImage_Gpu.h index f20625a29e..f4ca064d51 100644 --- a/src/image/SkImage_Gpu.h +++ b/src/image/SkImage_Gpu.h @@ -9,7 +9,7 @@ #define SkImage_Gpu_DEFINED #include "GrTexture.h" -#include "GrGpuResourceCacheAccess.h" +#include "GrGpuResourcePriv.h" #include "SkBitmap.h" #include "SkImage_Base.h" #include "SkImagePriv.h" @@ -38,9 +38,9 @@ public: void applyBudgetDecision() const { if (fBudgeted) { - fBitmap.getTexture()->cacheAccess().makeBudgeted(); + fBitmap.getTexture()->resourcePriv().makeBudgeted(); } else { - fBitmap.getTexture()->cacheAccess().makeUnbudgeted(); + fBitmap.getTexture()->resourcePriv().makeUnbudgeted(); } } diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp index 34aec2b7bb..a1c31f3137 100644 --- a/src/image/SkSurface_Gpu.cpp +++ b/src/image/SkSurface_Gpu.cpp @@ -7,7 +7,7 @@ #include "SkSurface_Gpu.h" -#include "GrGpuResourceCacheAccess.h" +#include "GrGpuResourcePriv.h" #include "SkCanvas.h" #include "SkGpuDevice.h" #include "SkImage_Base.h" @@ -70,8 +70,8 @@ void SkSurface_Gpu::onCopyOnWrite(ContentChangeMode mode) { SkASSERT(image); if (rt->asTexture() == SkTextureImageGetTexture(image)) { GrRenderTarget* oldRT = this->fDevice->accessRenderTarget(); - SkSurface::Budgeted budgeted = oldRT->cacheAccess().isBudgeted() ? kYes_Budgeted : - kNo_Budgeted; + SkSurface::Budgeted budgeted = oldRT->resourcePriv().isBudgeted() ? kYes_Budgeted : + kNo_Budgeted; SkAutoTUnref<SkGpuDevice> newDevice( SkGpuDevice::Create(oldRT->getContext(), budgeted, fDevice->imageInfo(), oldRT->numSamples(), &this->props(), 0)); diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp index 856bd723a7..620a2fead5 100644 --- a/tests/ResourceCacheTest.cpp +++ b/tests/ResourceCacheTest.cpp @@ -10,6 +10,8 @@ #include "GrContext.h" #include "GrContextFactory.h" #include "GrGpu.h" +#include "GrGpuResourceCacheAccess.h" +#include "GrGpuResourcePriv.h" #include "GrResourceCache.h" #include "SkCanvas.h" #include "SkGr.h" @@ -243,7 +245,7 @@ static void test_budgeting(skiatest::Reporter* reporter) { scratch->setSize(10); TestResource* content = SkNEW_ARGS(TestResource, (context->getGpu())); content->setSize(11); - REPORTER_ASSERT(reporter, content->cacheAccess().setContentKey(contentKey)); + REPORTER_ASSERT(reporter, content->resourcePriv().setContentKey(contentKey)); TestResource* wrapped = SkNEW_ARGS(TestResource, (context->getGpu(), GrGpuResource::kWrapped_LifeCycle)); wrapped->setSize(12); @@ -254,7 +256,7 @@ static void test_budgeting(skiatest::Reporter* reporter) { // 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->cacheAccess().setContentKey(contentKey2)); + REPORTER_ASSERT(reporter, !wrapped->resourcePriv().setContentKey(contentKey2)); REPORTER_ASSERT(reporter, NULL == cache->findAndRefContentResource(contentKey2)); // Make sure sizes are as we expect @@ -338,7 +340,7 @@ static void test_unbudgeted(skiatest::Reporter* reporter) { content = SkNEW_ARGS(TestResource, (context->getGpu())); content->setSize(11); - REPORTER_ASSERT(reporter, content->cacheAccess().setContentKey(contentKey)); + REPORTER_ASSERT(reporter, content->resourcePriv().setContentKey(contentKey)); content->unref(); REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); REPORTER_ASSERT(reporter, 21 == cache->getResourceBytes()); @@ -379,7 +381,9 @@ static void test_unbudgeted(skiatest::Reporter* reporter) { REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes()); } -static void test_unbudgeted_to_scratch(skiatest::Reporter* reporter) { +// This method can't be static because it needs to friended in GrGpuResource::CacheAccess. +void test_unbudgeted_to_scratch(skiatest::Reporter* reporter); +/*static*/ void test_unbudgeted_to_scratch(skiatest::Reporter* reporter) { Mock mock(10, 300); GrContext* context = mock.context(); GrResourceCache* cache = mock.cache(); @@ -392,9 +396,9 @@ static void test_unbudgeted_to_scratch(skiatest::Reporter* reporter) { size_t size = resource->gpuMemorySize(); for (int i = 0; i < 2; ++i) { // Since this resource is unbudgeted, it should not be reachable as scratch. - REPORTER_ASSERT(reporter, resource->cacheAccess().getScratchKey() == key); + REPORTER_ASSERT(reporter, resource->resourcePriv().getScratchKey() == key); REPORTER_ASSERT(reporter, !resource->cacheAccess().isScratch()); - REPORTER_ASSERT(reporter, !resource->cacheAccess().isBudgeted()); + REPORTER_ASSERT(reporter, !resource->resourcePriv().isBudgeted()); REPORTER_ASSERT(reporter, NULL == cache->findAndRefScratchResource(key)); REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); REPORTER_ASSERT(reporter, size == cache->getResourceBytes()); @@ -409,24 +413,24 @@ static void test_unbudgeted_to_scratch(skiatest::Reporter* reporter) { REPORTER_ASSERT(reporter, size == cache->getBudgetedResourceBytes()); resource = static_cast<TestResource*>(cache->findAndRefScratchResource(key)); REPORTER_ASSERT(reporter, resource); - REPORTER_ASSERT(reporter, resource->cacheAccess().getScratchKey() == key); + REPORTER_ASSERT(reporter, resource->resourcePriv().getScratchKey() == key); REPORTER_ASSERT(reporter, resource->cacheAccess().isScratch()); - REPORTER_ASSERT(reporter, resource->cacheAccess().isBudgeted()); + REPORTER_ASSERT(reporter, resource->resourcePriv().isBudgeted()); if (0 == i) { // If made unbudgeted, it should return to original state: ref'ed and unbudgeted. Try // the above tests again. - resource->cacheAccess().makeUnbudgeted(); + resource->resourcePriv().makeUnbudgeted(); } else { // After the second time around, try removing the scratch key - resource->cacheAccess().removeScratchKey(); + resource->resourcePriv().removeScratchKey(); REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); REPORTER_ASSERT(reporter, size == cache->getResourceBytes()); REPORTER_ASSERT(reporter, 1 == cache->getBudgetedResourceCount()); REPORTER_ASSERT(reporter, size == cache->getBudgetedResourceBytes()); - REPORTER_ASSERT(reporter, !resource->cacheAccess().getScratchKey().isValid()); + REPORTER_ASSERT(reporter, !resource->resourcePriv().getScratchKey().isValid()); REPORTER_ASSERT(reporter, !resource->cacheAccess().isScratch()); - REPORTER_ASSERT(reporter, resource->cacheAccess().isBudgeted()); + REPORTER_ASSERT(reporter, resource->resourcePriv().isBudgeted()); // now when it is unrefed it should die since it has no key. resource->unref(); @@ -512,7 +516,7 @@ static void test_remove_scratch_key(skiatest::Reporter* reporter) { // Find the first resource and remove its scratch key GrGpuResource* find; find = cache->findAndRefScratchResource(scratchKey); - find->cacheAccess().removeScratchKey(); + find->resourcePriv().removeScratchKey(); // It's still alive, but not cached by scratch key anymore REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); SkDEBUGCODE(REPORTER_ASSERT(reporter, 1 == cache->countScratchEntriesForKey(scratchKey));) @@ -526,13 +530,13 @@ static void test_remove_scratch_key(skiatest::Reporter* reporter) { // Repeat for the second resource. find = cache->findAndRefScratchResource(scratchKey); - find->cacheAccess().removeScratchKey(); + find->resourcePriv().removeScratchKey(); REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); SkDEBUGCODE(REPORTER_ASSERT(reporter, 0 == cache->countScratchEntriesForKey(scratchKey));) REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); // Should be able to call this multiple times with no problem. - find->cacheAccess().removeScratchKey(); + find->resourcePriv().removeScratchKey(); REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); SkDEBUGCODE(REPORTER_ASSERT(reporter, 0 == cache->countScratchEntriesForKey(scratchKey));) REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); @@ -617,8 +621,8 @@ static void test_duplicate_content_key(skiatest::Reporter* reporter) { b->setSize(12); // Can't set the same content key on two resources. - REPORTER_ASSERT(reporter, a->cacheAccess().setContentKey(key)); - REPORTER_ASSERT(reporter, !b->cacheAccess().setContentKey(key)); + REPORTER_ASSERT(reporter, a->resourcePriv().setContentKey(key)); + REPORTER_ASSERT(reporter, !b->resourcePriv().setContentKey(key)); // Still have two resources because b is still reffed. REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); @@ -664,9 +668,9 @@ static void test_purge_invalidated(skiatest::Reporter* reporter) { TestResource* b = SkNEW_ARGS(TestResource, (context->getGpu())); TestResource* c = TestResource::CreateScratch(context->getGpu(), TestResource::kA_SimulatedProperty); - a->cacheAccess().setContentKey(key1); - b->cacheAccess().setContentKey(key2); - c->cacheAccess().setContentKey(key3); + a->resourcePriv().setContentKey(key1); + b->resourcePriv().setContentKey(key2); + c->resourcePriv().setContentKey(key3); a->unref(); // hold b until *after* the message is sent. c->unref(); @@ -729,8 +733,8 @@ static void test_cache_chained_purge(skiatest::Reporter* reporter) { TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu())); TestResource* b = SkNEW_ARGS(TestResource, (context->getGpu())); - a->cacheAccess().setContentKey(key1); - b->cacheAccess().setContentKey(key2); + a->resourcePriv().setContentKey(key1); + b->resourcePriv().setContentKey(key2); // Make a cycle a->setUnrefWhenDestroyed(b); @@ -766,11 +770,11 @@ static void test_resource_size_changed(skiatest::Reporter* reporter) { GrResourceCache* cache = mock.cache(); TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu())); - a->cacheAccess().setContentKey(key1); + a->resourcePriv().setContentKey(key1); a->unref(); TestResource* b = SkNEW_ARGS(TestResource, (context->getGpu())); - b->cacheAccess().setContentKey(key2); + b->resourcePriv().setContentKey(key2); b->unref(); REPORTER_ASSERT(reporter, 200 == cache->getResourceBytes()); @@ -794,12 +798,12 @@ static void test_resource_size_changed(skiatest::Reporter* reporter) { TestResource* a = SkNEW_ARGS(TestResource, (context->getGpu())); a->setSize(100); - a->cacheAccess().setContentKey(key1); + a->resourcePriv().setContentKey(key1); a->unref(); TestResource* b = SkNEW_ARGS(TestResource, (context->getGpu())); b->setSize(100); - b->cacheAccess().setContentKey(key2); + b->resourcePriv().setContentKey(key2); b->unref(); REPORTER_ASSERT(reporter, 200 == cache->getResourceBytes()); @@ -834,12 +838,12 @@ static void test_large_resource_count(skiatest::Reporter* reporter) { TestResource* resource; resource = SkNEW_ARGS(TestResource, (context->getGpu())); - resource->cacheAccess().setContentKey(key1); + resource->resourcePriv().setContentKey(key1); resource->setSize(1); resource->unref(); resource = SkNEW_ARGS(TestResource, (context->getGpu())); - resource->cacheAccess().setContentKey(key2); + resource->resourcePriv().setContentKey(key2); resource->setSize(1); resource->unref(); } diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp index 8cd50ddd33..9ce9d5fbe8 100644 --- a/tests/SurfaceTest.cpp +++ b/tests/SurfaceTest.cpp @@ -456,18 +456,18 @@ static void TestGetTexture(skiatest::Reporter* reporter, REPORTER_ASSERT(reporter, image->getTexture() == texture); } -#include "GrGpuResourceCacheAccess.h" +#include "GrGpuResourcePriv.h" #include "SkGpuDevice.h" #include "SkImage_Gpu.h" #include "SkSurface_Gpu.h" SkSurface::Budgeted is_budgeted(SkSurface* surf) { - return ((SkSurface_Gpu*)surf)->getDevice()->accessRenderTarget()->cacheAccess().isBudgeted() ? + return ((SkSurface_Gpu*)surf)->getDevice()->accessRenderTarget()->resourcePriv().isBudgeted() ? SkSurface::kYes_Budgeted : SkSurface::kNo_Budgeted; } SkSurface::Budgeted is_budgeted(SkImage* image) { - return ((SkImage_Gpu*)image)->getTexture()->cacheAccess().isBudgeted() ? + return ((SkImage_Gpu*)image)->getTexture()->resourcePriv().isBudgeted() ? SkSurface::kYes_Budgeted : SkSurface::kNo_Budgeted; } |