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

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

Issue 24222004: Don't reuse scratch textures patch (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: check nothing changes Created 7 years, 1 month 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 | « include/gpu/GrResource.h ('k') | src/gpu/GrResource.cpp » ('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 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 504
505 if (NULL == texture) { 505 if (NULL == texture) {
506 return; 506 return;
507 } 507 }
508 508
509 // This texture should already have a cache entry since it was once 509 // This texture should already have a cache entry since it was once
510 // attached 510 // attached
511 SkASSERT(NULL != texture->getCacheEntry()); 511 SkASSERT(NULL != texture->getCacheEntry());
512 512
513 // Conceptually, the cache entry is going to assume responsibility 513 // Conceptually, the cache entry is going to assume responsibility
514 // for the creation ref. 514 // for the creation ref. Assert refcnt == 1.
515 SkASSERT(texture->unique()); 515 SkASSERT(texture->unique());
516 516
517 // Since this texture came from an AutoScratchTexture it should
518 // still be in the exclusive pile
519 fTextureCache->makeNonExclusive(texture->getCacheEntry());
520
521 if (fGpu->caps()->reuseScratchTextures()) { 517 if (fGpu->caps()->reuseScratchTextures()) {
518 // Since this texture came from an AutoScratchTexture it should
519 // still be in the exclusive pile. Recycle it.
520 fTextureCache->makeNonExclusive(texture->getCacheEntry());
522 this->purgeCache(); 521 this->purgeCache();
523 } else { 522 } else if (texture->getDeferredRefCount() <= 0) {
524 // When we aren't reusing textures we know this scratch texture 523 // When we aren't reusing textures we know this scratch texture
525 // will never be reused and would be just wasting time in the cache 524 // will never be reused and would be just wasting time in the cache
525 fTextureCache->makeNonExclusive(texture->getCacheEntry());
526 fTextureCache->deleteResource(texture->getCacheEntry()); 526 fTextureCache->deleteResource(texture->getCacheEntry());
527 } else {
528 // In this case (fDeferredRefCount > 0) but the cache is the only
529 // one holding a real ref. Mark the object so when the deferred
530 // ref count goes to 0 the texture will be deleted (remember
531 // in this code path scratch textures aren't getting reused).
532 texture->setNeedsDeferredUnref();
527 } 533 }
528 } 534 }
529 535
530 536
531 void GrContext::unlockScratchTexture(GrTexture* texture) { 537 void GrContext::unlockScratchTexture(GrTexture* texture) {
532 ASSERT_OWNED_RESOURCE(texture); 538 ASSERT_OWNED_RESOURCE(texture);
533 SkASSERT(NULL != texture->getCacheEntry()); 539 SkASSERT(NULL != texture->getCacheEntry());
534 540
535 // If this is a scratch texture we detached it from the cache 541 // If this is a scratch texture we detached it from the cache
536 // while it was locked (to avoid two callers simultaneously getting 542 // while it was locked (to avoid two callers simultaneously getting
537 // the same texture). 543 // the same texture).
538 if (texture->getCacheEntry()->key().isScratch()) { 544 if (texture->getCacheEntry()->key().isScratch()) {
539 fTextureCache->makeNonExclusive(texture->getCacheEntry()); 545 if (fGpu->caps()->reuseScratchTextures()) {
540 this->purgeCache(); 546 fTextureCache->makeNonExclusive(texture->getCacheEntry());
547 this->purgeCache();
548 } else if (texture->unique() && texture->getDeferredRefCount() <= 0) {
549 // Only the cache now knows about this texture. Since we're never
550 // reusing scratch textures (in this code path) it would just be
551 // wasting time sitting in the cache.
552 fTextureCache->makeNonExclusive(texture->getCacheEntry());
553 fTextureCache->deleteResource(texture->getCacheEntry());
554 } else {
555 // In this case (fRefCnt > 1 || defRefCnt > 0) but we don't really
556 // want to readd it to the cache (since it will never be reused).
557 // Instead, give up the cache's ref and leave the decision up to
558 // addExistingTextureToCache once its ref count reaches 0. For
559 // this to work we need to leave it in the exclusive list.
560 texture->setFlag((GrTextureFlags) GrTexture::kReturnToCache_FlagBit) ;
561 // Give up the cache's ref to the texture
562 texture->unref();
563 }
541 } 564 }
542 } 565 }
543 566
544 void GrContext::purgeCache() { 567 void GrContext::purgeCache() {
545 if (NULL != fTextureCache) { 568 if (NULL != fTextureCache) {
546 fTextureCache->purgeAsNeeded(); 569 fTextureCache->purgeAsNeeded();
547 } 570 }
548 } 571 }
549 572
550 bool GrContext::OverbudgetCB(void* data) { 573 bool GrContext::OverbudgetCB(void* data) {
(...skipping 1235 matching lines...) Expand 10 before | Expand all | Expand 10 after
1786 return NULL; 1809 return NULL;
1787 } 1810 }
1788 } 1811 }
1789 1812
1790 /////////////////////////////////////////////////////////////////////////////// 1813 ///////////////////////////////////////////////////////////////////////////////
1791 #if GR_CACHE_STATS 1814 #if GR_CACHE_STATS
1792 void GrContext::printCacheStats() const { 1815 void GrContext::printCacheStats() const {
1793 fTextureCache->printStats(); 1816 fTextureCache->printStats();
1794 } 1817 }
1795 #endif 1818 #endif
OLDNEW
« no previous file with comments | « include/gpu/GrResource.h ('k') | src/gpu/GrResource.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698