| 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 510 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 521 | 521 | 
| 522     // Conceptually, the cache entry is going to assume responsibility | 522     // Conceptually, the cache entry is going to assume responsibility | 
| 523     // for the creation ref. Assert refcnt == 1. | 523     // for the creation ref. Assert refcnt == 1. | 
| 524     SkASSERT(texture->unique()); | 524     SkASSERT(texture->unique()); | 
| 525 | 525 | 
| 526     if (fGpu->caps()->reuseScratchTextures() || NULL != texture->asRenderTarget(
      )) { | 526     if (fGpu->caps()->reuseScratchTextures() || NULL != texture->asRenderTarget(
      )) { | 
| 527         // Since this texture came from an AutoScratchTexture it should | 527         // Since this texture came from an AutoScratchTexture it should | 
| 528         // still be in the exclusive pile. Recycle it. | 528         // still be in the exclusive pile. Recycle it. | 
| 529         fResourceCache->makeNonExclusive(texture->getCacheEntry()); | 529         fResourceCache->makeNonExclusive(texture->getCacheEntry()); | 
| 530         this->purgeCache(); | 530         this->purgeCache(); | 
| 531     } else if (texture->getDeferredRefCount() <= 0) { | 531     } else { | 
| 532         // When we aren't reusing textures we know this scratch texture | 532         // When we aren't reusing textures we know this scratch texture | 
| 533         // will never be reused and would be just wasting time in the cache | 533         // will never be reused and would be just wasting time in the cache | 
| 534         fResourceCache->makeNonExclusive(texture->getCacheEntry()); | 534         fResourceCache->makeNonExclusive(texture->getCacheEntry()); | 
| 535         fResourceCache->deleteResource(texture->getCacheEntry()); | 535         fResourceCache->deleteResource(texture->getCacheEntry()); | 
| 536     } else { |  | 
| 537         // In this case (fDeferredRefCount > 0) but the cache is the only |  | 
| 538         // one holding a real ref. Mark the object so when the deferred |  | 
| 539         // ref count goes to 0 the texture will be deleted (remember |  | 
| 540         // in this code path scratch textures aren't getting reused). |  | 
| 541         texture->setNeedsDeferredUnref(); |  | 
| 542     } | 536     } | 
| 543 } | 537 } | 
| 544 | 538 | 
| 545 |  | 
| 546 void GrContext::unlockScratchTexture(GrTexture* texture) { | 539 void GrContext::unlockScratchTexture(GrTexture* texture) { | 
| 547     ASSERT_OWNED_RESOURCE(texture); | 540     ASSERT_OWNED_RESOURCE(texture); | 
| 548     SkASSERT(NULL != texture->getCacheEntry()); | 541     SkASSERT(NULL != texture->getCacheEntry()); | 
| 549 | 542 | 
| 550     // If this is a scratch texture we detached it from the cache | 543     // If this is a scratch texture we detached it from the cache | 
| 551     // while it was locked (to avoid two callers simultaneously getting | 544     // while it was locked (to avoid two callers simultaneously getting | 
| 552     // the same texture). | 545     // the same texture). | 
| 553     if (texture->getCacheEntry()->key().isScratch()) { | 546     if (texture->getCacheEntry()->key().isScratch()) { | 
| 554         if (fGpu->caps()->reuseScratchTextures() || NULL != texture->asRenderTar
      get()) { | 547         if (fGpu->caps()->reuseScratchTextures() || NULL != texture->asRenderTar
      get()) { | 
| 555             fResourceCache->makeNonExclusive(texture->getCacheEntry()); | 548             fResourceCache->makeNonExclusive(texture->getCacheEntry()); | 
| 556             this->purgeCache(); | 549             this->purgeCache(); | 
| 557         } else if (texture->unique() && texture->getDeferredRefCount() <= 0) { | 550         } else if (texture->unique()) { | 
| 558             // Only the cache now knows about this texture. Since we're never | 551             // Only the cache now knows about this texture. Since we're never | 
| 559             // reusing scratch textures (in this code path) it would just be | 552             // reusing scratch textures (in this code path) it would just be | 
| 560             // wasting time sitting in the cache. | 553             // wasting time sitting in the cache. | 
| 561             fResourceCache->makeNonExclusive(texture->getCacheEntry()); | 554             fResourceCache->makeNonExclusive(texture->getCacheEntry()); | 
| 562             fResourceCache->deleteResource(texture->getCacheEntry()); | 555             fResourceCache->deleteResource(texture->getCacheEntry()); | 
| 563         } else { | 556         } else { | 
| 564             // In this case (fRefCnt > 1 || defRefCnt > 0) but we don't really | 557             // In this case (there is still a non-cache ref) but we don't really | 
| 565             // want to readd it to the cache (since it will never be reused). | 558             // want to readd it to the cache (since it will never be reused). | 
| 566             // Instead, give up the cache's ref and leave the decision up to | 559             // Instead, give up the cache's ref and leave the decision up to | 
| 567             // addExistingTextureToCache once its ref count reaches 0. For | 560             // addExistingTextureToCache once its ref count reaches 0. For | 
| 568             // this to work we need to leave it in the exclusive list. | 561             // this to work we need to leave it in the exclusive list. | 
| 569             texture->impl()->setFlag((GrTextureFlags) GrTextureImpl::kReturnToCa
      che_FlagBit); | 562             texture->impl()->setFlag((GrTextureFlags) GrTextureImpl::kReturnToCa
      che_FlagBit); | 
| 570             // Give up the cache's ref to the texture | 563             // Give up the cache's ref to the texture | 
| 571             texture->unref(); | 564             texture->unref(); | 
| 572         } | 565         } | 
| 573     } | 566     } | 
| 574 } | 567 } | 
| (...skipping 1359 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1934         fDrawBuffer->removeGpuTraceMarker(marker); | 1927         fDrawBuffer->removeGpuTraceMarker(marker); | 
| 1935     } | 1928     } | 
| 1936 } | 1929 } | 
| 1937 | 1930 | 
| 1938 /////////////////////////////////////////////////////////////////////////////// | 1931 /////////////////////////////////////////////////////////////////////////////// | 
| 1939 #if GR_CACHE_STATS | 1932 #if GR_CACHE_STATS | 
| 1940 void GrContext::printCacheStats() const { | 1933 void GrContext::printCacheStats() const { | 
| 1941     fResourceCache->printStats(); | 1934     fResourceCache->printStats(); | 
| 1942 } | 1935 } | 
| 1943 #endif | 1936 #endif | 
| OLD | NEW | 
|---|