diff options
Diffstat (limited to 'src/gpu')
-rw-r--r-- | src/gpu/GrContext.cpp | 15 | ||||
-rw-r--r-- | src/gpu/GrResourceCache.cpp | 27 | ||||
-rw-r--r-- | src/gpu/GrResourceCache.h | 28 | ||||
-rw-r--r-- | src/gpu/SkGpuDevice.cpp | 3 |
4 files changed, 24 insertions, 49 deletions
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index 5a0f68982b..d2b312f7ca 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -46,8 +46,7 @@ #define GR_DEBUG_PARTIAL_COVERAGE_CHECK 0 #endif -static const size_t MAX_TEXTURE_CACHE_COUNT = 256; -static const size_t MAX_TEXTURE_CACHE_BYTES = 16 * 1024 * 1024; +static const size_t kDefaultTextureCacheBudget = 16 * 1024 * 1024; static const size_t DRAW_BUFFER_VBPOOL_BUFFER_SIZE = 1 << 15; static const int DRAW_BUFFER_VBPOOL_PREALLOC_BUFFERS = 4; @@ -541,13 +540,12 @@ GrTexture* GrContext::createUncachedTexture(const GrTextureDesc& descIn, return fGpu->createTexture(descCopy, srcData, rowBytes); } -void GrContext::getTextureCacheLimits(int* maxTextures, - size_t* maxTextureBytes) const { - fTextureCache->getLimits(maxTextures, maxTextureBytes); +size_t GrContext::getTextureCacheBudget() const { + return fTextureCache->getBudget(); } -void GrContext::setTextureCacheLimits(int maxTextures, size_t maxTextureBytes) { - fTextureCache->setLimits(maxTextures, maxTextureBytes); +void GrContext::setTextureCacheBudget(size_t maxTextureBytes) { + fTextureCache->setBudget(maxTextureBytes); } int GrContext::getMaxTextureSize() const { @@ -1731,8 +1729,7 @@ GrContext::GrContext(GrGpu* gpu) { fPathRendererChain = NULL; fSoftwarePathRenderer = NULL; - fTextureCache = new GrResourceCache(MAX_TEXTURE_CACHE_COUNT, - MAX_TEXTURE_CACHE_BYTES); + fTextureCache = new GrResourceCache(kDefaultTextureCacheBudget); fFontCache = new GrFontCache(fGpu); fLastDrawCategory = kUnbuffered_DrawCategory; diff --git a/src/gpu/GrResourceCache.cpp b/src/gpu/GrResourceCache.cpp index 848a9227e5..6a6c16697a 100644 --- a/src/gpu/GrResourceCache.cpp +++ b/src/gpu/GrResourceCache.cpp @@ -34,9 +34,8 @@ void GrResourceEntry::validate() const { /////////////////////////////////////////////////////////////////////////////// -GrResourceCache::GrResourceCache(int maxCount, size_t maxBytes) : - fMaxCount(maxCount), - fMaxBytes(maxBytes) { +GrResourceCache::GrResourceCache(size_t maxBytes) { + fMaxBytes = maxBytes; fEntryCount = 0; fUnlockedEntryCount = 0; fEntryBytes = 0; @@ -53,19 +52,9 @@ GrResourceCache::~GrResourceCache() { this->removeAll(); } -void GrResourceCache::getLimits(int* maxResources, size_t* maxResourceBytes) const{ - if (maxResources) { - *maxResources = fMaxCount; - } - if (maxResourceBytes) { - *maxResourceBytes = fMaxBytes; - } -} - -void GrResourceCache::setLimits(int maxResources, size_t maxResourceBytes) { - bool smaller = (maxResources < fMaxCount) || (maxResourceBytes < fMaxBytes); +void GrResourceCache::setBudget(size_t maxResourceBytes) { + bool smaller = maxResourceBytes < fMaxBytes; - fMaxCount = maxResources; fMaxBytes = maxResourceBytes; if (smaller) { @@ -223,6 +212,7 @@ void GrResourceCache::reattachAndUnlock(GrResourceEntry* entry) { fClientDetachedCount -= 1; fEntryCount -= 1; size_t size = entry->resource()->sizeInBytes(); + GrAssert(size > 0); fClientDetachedBytes -= size; fEntryBytes -= size; } @@ -261,7 +251,7 @@ void GrResourceCache::purgeAsNeeded() { GrResourceEntry* entry = fTail; while (entry && fUnlockedEntryCount) { GrAutoResourceCacheValidate atcv(this); - if (fEntryCount <= fMaxCount && fEntryBytes <= fMaxBytes) { + if (fEntryBytes <= fMaxBytes) { withinBudget = true; break; } @@ -297,9 +287,7 @@ void GrResourceCache::removeAll() { // entry out. Instead change the budget and purge. int savedMaxBytes = fMaxBytes; - int savedMaxCount = fMaxCount; - fMaxBytes = (size_t) -1; - fMaxCount = 0; + fMaxBytes = 0; this->purgeAsNeeded(); #if GR_DEBUG @@ -316,7 +304,6 @@ void GrResourceCache::removeAll() { #endif fMaxBytes = savedMaxBytes; - fMaxCount = savedMaxCount; } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/gpu/GrResourceCache.h b/src/gpu/GrResourceCache.h index b83e8ec348..ca7ca10a46 100644 --- a/src/gpu/GrResourceCache.h +++ b/src/gpu/GrResourceCache.h @@ -194,29 +194,22 @@ private: */ class GrResourceCache { public: - GrResourceCache(int maxCount, size_t maxBytes); + GrResourceCache(size_t maxResourceBytes); ~GrResourceCache(); /** - * Return the current resource cache limits. - * - * @param maxResource If non-null, returns maximum number of resources - * that can be held in the cache. - * @param maxBytes If non-null, returns maximum number of bytes of - * gpu memory that can be held in the cache. + * Returns the cache budget in bytes. */ - void getLimits(int* maxResources, size_t* maxBytes) const; + size_t getBudget() const { return fMaxBytes; } /** - * Specify the resource cache limits. If the current cache exceeds either - * of these, it will be purged (LRU) to keep the cache within these limits. + * Specify the resource cache budget in bytes of GPU memory. If the current + * cache exceeds the budget it will be purged to be within the budget. * - * @param maxResources The maximum number of resources that can be held in - * the cache. - * @param maxBytes The maximum number of bytes of resource memory that - * can be held in the cache. + * @param maxResourceBytes The maximum number of bytes of GPU memory that + * can be held in the cache. */ - void setLimits(int maxResource, size_t maxResourceBytes); + void setBudget(size_t maxResourceBytes); /** * Returns the number of bytes consumed by cached resources. @@ -241,8 +234,8 @@ public: * Create a new entry, based on the specified key and resource, and return * its "locked" entry. * - * Ownership of the resource is transferred to the Entry, which will unref() - * it when we are purged or deleted. + * Ownership of the resource is transferred to the Entry, which will + * unref() it when we are purged or deleted. */ GrResourceEntry* createAndLock(const GrResourceKey&, GrResource*); @@ -294,7 +287,6 @@ private: GrResourceEntry* fTail; // our budget, used in purgeAsNeeded() - int fMaxCount; size_t fMaxBytes; // our current stats, related to our budget diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index 77a08eccb9..628adc4c96 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -1152,8 +1152,7 @@ bool SkGpuDevice::shouldTileBitmap(const SkBitmap& bitmap, // assumption here is that sw bitmap size is a good proxy for its size as // a texture size_t bmpSize = bitmap.getSize(); - size_t cacheSize; - fContext->getTextureCacheLimits(NULL, &cacheSize); + size_t cacheSize = fContext->getTextureCacheBudget(); if (bmpSize < cacheSize / 2) { return false; } |