Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Side by Side Diff: src/gpu/GrContext.cpp

Issue 19591003: Add purgeAsNeeded calls before addResource calls (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: added extraCount & extraSize to account for future memory requirements Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/gpu/GrResourceCache.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "GrContext.h" 10 #include "GrContext.h"
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 GrTexture* texture; 383 GrTexture* texture;
384 if (GrTexture::NeedsResizing(resourceKey)) { 384 if (GrTexture::NeedsResizing(resourceKey)) {
385 texture = this->createResizedTexture(desc, cacheID, 385 texture = this->createResizedTexture(desc, cacheID,
386 srcData, rowBytes, 386 srcData, rowBytes,
387 GrTexture::NeedsFiltering(resourceK ey)); 387 GrTexture::NeedsFiltering(resourceK ey));
388 } else { 388 } else {
389 texture= fGpu->createTexture(desc, srcData, rowBytes); 389 texture= fGpu->createTexture(desc, srcData, rowBytes);
390 } 390 }
391 391
392 if (NULL != texture) { 392 if (NULL != texture) {
393 // Adding a resource could put us overbudget. Try to free up the
394 // necessary space before adding it.
395 fTextureCache->purgeAsNeeded(1, texture->sizeInBytes());
393 fTextureCache->addResource(resourceKey, texture); 396 fTextureCache->addResource(resourceKey, texture);
394 } 397 }
395 398
396 return texture; 399 return texture;
397 } 400 }
398 401
399 GrTexture* GrContext::lockAndRefScratchTexture(const GrTextureDesc& inDesc, Scra tchTexMatch match) { 402 GrTexture* GrContext::lockAndRefScratchTexture(const GrTextureDesc& inDesc, Scra tchTexMatch match) {
400 GrTextureDesc desc = inDesc; 403 GrTextureDesc desc = inDesc;
401 404
402 GrAssert((desc.fFlags & kRenderTarget_GrTextureFlagBit) || 405 GrAssert((desc.fFlags & kRenderTarget_GrTextureFlagBit) ||
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 445
443 } while (true); 446 } while (true);
444 447
445 if (NULL == resource) { 448 if (NULL == resource) {
446 desc.fFlags = inDesc.fFlags; 449 desc.fFlags = inDesc.fFlags;
447 desc.fWidth = origWidth; 450 desc.fWidth = origWidth;
448 desc.fHeight = origHeight; 451 desc.fHeight = origHeight;
449 GrTexture* texture = fGpu->createTexture(desc, NULL, 0); 452 GrTexture* texture = fGpu->createTexture(desc, NULL, 0);
450 if (NULL != texture) { 453 if (NULL != texture) {
451 GrResourceKey key = GrTexture::ComputeScratchKey(texture->desc()); 454 GrResourceKey key = GrTexture::ComputeScratchKey(texture->desc());
455 // Adding a resource could put us overbudget. Try to free up the
456 // necessary space before adding it.
457 fTextureCache->purgeAsNeeded(1, texture->sizeInBytes());
452 // Make the resource exclusive so future 'find' calls don't return i t 458 // Make the resource exclusive so future 'find' calls don't return i t
453 fTextureCache->addResource(key, texture, GrResourceCache::kHide_Owne rshipFlag); 459 fTextureCache->addResource(key, texture, GrResourceCache::kHide_Owne rshipFlag);
454 resource = texture; 460 resource = texture;
455 } 461 }
456 } 462 }
457 463
458 return static_cast<GrTexture*>(resource); 464 return static_cast<GrTexture*>(resource);
459 } 465 }
460 466
461 void GrContext::addExistingTextureToCache(GrTexture* texture) { 467 void GrContext::addExistingTextureToCache(GrTexture* texture) {
(...skipping 20 matching lines...) Expand all
482 488
483 void GrContext::unlockScratchTexture(GrTexture* texture) { 489 void GrContext::unlockScratchTexture(GrTexture* texture) {
484 ASSERT_OWNED_RESOURCE(texture); 490 ASSERT_OWNED_RESOURCE(texture);
485 GrAssert(NULL != texture->getCacheEntry()); 491 GrAssert(NULL != texture->getCacheEntry());
486 492
487 // If this is a scratch texture we detached it from the cache 493 // If this is a scratch texture we detached it from the cache
488 // while it was locked (to avoid two callers simultaneously getting 494 // while it was locked (to avoid two callers simultaneously getting
489 // the same texture). 495 // the same texture).
490 if (texture->getCacheEntry()->key().isScratch()) { 496 if (texture->getCacheEntry()->key().isScratch()) {
491 fTextureCache->makeNonExclusive(texture->getCacheEntry()); 497 fTextureCache->makeNonExclusive(texture->getCacheEntry());
498 this->purgeCache();
492 } 499 }
493 500
494 this->purgeCache();
495 } 501 }
496 502
497 void GrContext::purgeCache() { 503 void GrContext::purgeCache() {
498 if (NULL != fTextureCache) { 504 if (NULL != fTextureCache) {
499 fTextureCache->purgeAsNeeded(); 505 fTextureCache->purgeAsNeeded();
500 } 506 }
501 } 507 }
502 508
503 bool GrContext::OverbudgetCB(void* data) { 509 bool GrContext::OverbudgetCB(void* data) {
504 GrAssert(NULL != data); 510 GrAssert(NULL != data);
(...skipping 1175 matching lines...) Expand 10 before | Expand all | Expand 10 after
1680 return NULL; 1686 return NULL;
1681 } 1687 }
1682 } 1688 }
1683 1689
1684 /////////////////////////////////////////////////////////////////////////////// 1690 ///////////////////////////////////////////////////////////////////////////////
1685 #if GR_CACHE_STATS 1691 #if GR_CACHE_STATS
1686 void GrContext::printCacheStats() const { 1692 void GrContext::printCacheStats() const {
1687 fTextureCache->printStats(); 1693 fTextureCache->printStats();
1688 } 1694 }
1689 #endif 1695 #endif
OLDNEW
« no previous file with comments | « no previous file | src/gpu/GrResourceCache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698