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
This commit is contained in:
robertphillips@google.com 2013-07-18 17:11:45 +00:00
parent c968315136
commit 1622a6d950

View File

@ -390,6 +390,9 @@ GrTexture* GrContext::createTexture(const GrTextureParams* params,
} }
if (NULL != texture) { 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); fTextureCache->addResource(resourceKey, texture);
} }
@ -449,6 +452,9 @@ GrTexture* GrContext::lockAndRefScratchTexture(const GrTextureDesc& inDesc, Scra
GrTexture* texture = fGpu->createTexture(desc, NULL, 0); GrTexture* texture = fGpu->createTexture(desc, NULL, 0);
if (NULL != texture) { if (NULL != texture) {
GrResourceKey key = GrTexture::ComputeScratchKey(texture->desc()); 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 // Make the resource exclusive so future 'find' calls don't return it
fTextureCache->addResource(key, texture, GrResourceCache::kHide_OwnershipFlag); fTextureCache->addResource(key, texture, GrResourceCache::kHide_OwnershipFlag);
resource = texture; resource = texture;
@ -489,9 +495,9 @@ void GrContext::unlockScratchTexture(GrTexture* texture) {
// the same texture). // the same texture).
if (texture->getCacheEntry()->key().isScratch()) { if (texture->getCacheEntry()->key().isScratch()) {
fTextureCache->makeNonExclusive(texture->getCacheEntry()); fTextureCache->makeNonExclusive(texture->getCacheEntry());
this->purgeCache();
} }
this->purgeCache();
} }
void GrContext::purgeCache() { void GrContext::purgeCache() {