OLD | NEW |
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 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 // attached | 507 // attached |
508 SkASSERT(NULL != texture->getCacheEntry()); | 508 SkASSERT(NULL != texture->getCacheEntry()); |
509 | 509 |
510 // Conceptually, the cache entry is going to assume responsibility | 510 // Conceptually, the cache entry is going to assume responsibility |
511 // for the creation ref. Assert refcnt == 1. | 511 // for the creation ref. Assert refcnt == 1. |
512 SkASSERT(texture->unique()); | 512 SkASSERT(texture->unique()); |
513 | 513 |
514 if (fGpu->caps()->reuseScratchTextures() || NULL != texture->asRenderTarget(
)) { | 514 if (fGpu->caps()->reuseScratchTextures() || NULL != texture->asRenderTarget(
)) { |
515 // Since this texture came from an AutoScratchTexture it should | 515 // Since this texture came from an AutoScratchTexture it should |
516 // still be in the exclusive pile. Recycle it. | 516 // still be in the exclusive pile. Recycle it. |
517 fTextureCache->makeNonExclusive(texture->getCacheEntry()); | 517 fTextureCache->makeNonExclusive(texture); |
518 this->purgeCache(); | 518 this->purgeCache(); |
519 } else if (texture->getDeferredRefCount() <= 0) { | 519 } else if (texture->getDeferredRefCount() <= 0) { |
520 // When we aren't reusing textures we know this scratch texture | 520 // When we aren't reusing textures we know this scratch texture |
521 // will never be reused and would be just wasting time in the cache | 521 // will never be reused and would be just wasting time in the cache |
522 fTextureCache->makeNonExclusive(texture->getCacheEntry()); | 522 fTextureCache->makeNonExclusive(texture); |
523 fTextureCache->deleteResource(texture->getCacheEntry()); | 523 fTextureCache->deleteResource(texture); |
524 } else { | 524 } else { |
525 // In this case (fDeferredRefCount > 0) but the cache is the only | 525 // In this case (fDeferredRefCount > 0) but the cache is the only |
526 // one holding a real ref. Mark the object so when the deferred | 526 // one holding a real ref. Mark the object so when the deferred |
527 // ref count goes to 0 the texture will be deleted (remember | 527 // ref count goes to 0 the texture will be deleted (remember |
528 // in this code path scratch textures aren't getting reused). | 528 // in this code path scratch textures aren't getting reused). |
529 texture->setNeedsDeferredUnref(); | 529 texture->setNeedsDeferredUnref(); |
530 } | 530 } |
531 } | 531 } |
532 | 532 |
533 | 533 |
534 void GrContext::unlockScratchTexture(GrTexture* texture) { | 534 void GrContext::unlockScratchTexture(GrTexture* texture) { |
535 ASSERT_OWNED_RESOURCE(texture); | 535 ASSERT_OWNED_RESOURCE(texture); |
536 SkASSERT(NULL != texture->getCacheEntry()); | 536 SkASSERT(NULL != texture->getCacheEntry()); |
537 | 537 |
538 // If this is a scratch texture we detached it from the cache | 538 // If this is a scratch texture we detached it from the cache |
539 // while it was locked (to avoid two callers simultaneously getting | 539 // while it was locked (to avoid two callers simultaneously getting |
540 // the same texture). | 540 // the same texture). |
541 if (texture->getCacheEntry()->key().isScratch()) { | 541 if (texture->getCacheEntry()->key().isScratch()) { |
542 if (fGpu->caps()->reuseScratchTextures() || NULL != texture->asRenderTar
get()) { | 542 if (fGpu->caps()->reuseScratchTextures() || NULL != texture->asRenderTar
get()) { |
543 fTextureCache->makeNonExclusive(texture->getCacheEntry()); | 543 fTextureCache->makeNonExclusive(texture); |
544 this->purgeCache(); | 544 this->purgeCache(); |
545 } else if (texture->unique() && texture->getDeferredRefCount() <= 0) { | 545 } else if (texture->unique() && texture->getDeferredRefCount() <= 0) { |
546 // Only the cache now knows about this texture. Since we're never | 546 // Only the cache now knows about this texture. Since we're never |
547 // reusing scratch textures (in this code path) it would just be | 547 // reusing scratch textures (in this code path) it would just be |
548 // wasting time sitting in the cache. | 548 // wasting time sitting in the cache. |
549 fTextureCache->makeNonExclusive(texture->getCacheEntry()); | 549 fTextureCache->makeNonExclusive(texture); |
550 fTextureCache->deleteResource(texture->getCacheEntry()); | 550 fTextureCache->deleteResource(texture); |
551 } else { | 551 } else { |
552 // In this case (fRefCnt > 1 || defRefCnt > 0) but we don't really | 552 // In this case (fRefCnt > 1 || defRefCnt > 0) but we don't really |
553 // want to readd it to the cache (since it will never be reused). | 553 // want to readd it to the cache (since it will never be reused). |
554 // Instead, give up the cache's ref and leave the decision up to | 554 // Instead, give up the cache's ref and leave the decision up to |
555 // addExistingTextureToCache once its ref count reaches 0. For | 555 // addExistingTextureToCache once its ref count reaches 0. For |
556 // this to work we need to leave it in the exclusive list. | 556 // this to work we need to leave it in the exclusive list. |
557 texture->setFlag((GrTextureFlags) GrTexture::kReturnToCache_FlagBit)
; | 557 texture->setFlag((GrTextureFlags) GrTexture::kReturnToCache_FlagBit)
; |
558 // Give up the cache's ref to the texture | 558 // Give up the cache's ref to the texture |
559 texture->unref(); | 559 texture->unref(); |
560 } | 560 } |
(...skipping 1249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1810 } | 1810 } |
1811 return path; | 1811 return path; |
1812 } | 1812 } |
1813 | 1813 |
1814 /////////////////////////////////////////////////////////////////////////////// | 1814 /////////////////////////////////////////////////////////////////////////////// |
1815 #if GR_CACHE_STATS | 1815 #if GR_CACHE_STATS |
1816 void GrContext::printCacheStats() const { | 1816 void GrContext::printCacheStats() const { |
1817 fTextureCache->printStats(); | 1817 fTextureCache->printStats(); |
1818 } | 1818 } |
1819 #endif | 1819 #endif |
OLD | NEW |