From 1622a6d950a4a1deb13048210bdb78d952375f05 Mon Sep 17 00:00:00 2001 From: "robertphillips@google.com" Date: Thu, 18 Jul 2013 17:11:45 +0000 Subject: [PATCH] Add purgeAsNeeded calls before addResource calls https://codereview.chromium.org/19591003/ git-svn-id: http://skia.googlecode.com/svn/trunk@10145 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/gpu/GrContext.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index ee8d9f7048..72cb2b365b 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -390,6 +390,9 @@ GrTexture* GrContext::createTexture(const GrTextureParams* params, } if (NULL != texture) { + // Adding a resource could put us overbudget. Try to free up the + // necessary space before adding it. + fTextureCache->purgeAsNeeded(1, texture->sizeInBytes()); fTextureCache->addResource(resourceKey, texture); } @@ -449,6 +452,9 @@ GrTexture* GrContext::lockAndRefScratchTexture(const GrTextureDesc& inDesc, Scra GrTexture* texture = fGpu->createTexture(desc, NULL, 0); if (NULL != texture) { GrResourceKey key = GrTexture::ComputeScratchKey(texture->desc()); + // Adding a resource could put us overbudget. Try to free up the + // necessary space before adding it. + fTextureCache->purgeAsNeeded(1, texture->sizeInBytes()); // Make the resource exclusive so future 'find' calls don't return it fTextureCache->addResource(key, texture, GrResourceCache::kHide_OwnershipFlag); resource = texture; @@ -489,9 +495,9 @@ void GrContext::unlockScratchTexture(GrTexture* texture) { // the same texture). if (texture->getCacheEntry()->key().isScratch()) { fTextureCache->makeNonExclusive(texture->getCacheEntry()); + this->purgeCache(); } - this->purgeCache(); } void GrContext::purgeCache() {