Chromium Code Reviews| 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 { |
|
bsalomon
2014/07/21 20:14:46
I think this is safe because incDeferredRefCount()
| |
| 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 | 539 |
| 546 void GrContext::unlockScratchTexture(GrTexture* texture) { | 540 void GrContext::unlockScratchTexture(GrTexture* texture) { |
| 547 ASSERT_OWNED_RESOURCE(texture); | 541 ASSERT_OWNED_RESOURCE(texture); |
| 548 SkASSERT(NULL != texture->getCacheEntry()); | 542 SkASSERT(NULL != texture->getCacheEntry()); |
| 549 | 543 |
| 550 // If this is a scratch texture we detached it from the cache | 544 // If this is a scratch texture we detached it from the cache |
| 551 // while it was locked (to avoid two callers simultaneously getting | 545 // while it was locked (to avoid two callers simultaneously getting |
| 552 // the same texture). | 546 // the same texture). |
| 553 if (texture->getCacheEntry()->key().isScratch()) { | 547 if (texture->getCacheEntry()->key().isScratch()) { |
| 554 if (fGpu->caps()->reuseScratchTextures() || NULL != texture->asRenderTar get()) { | 548 if (fGpu->caps()->reuseScratchTextures() || NULL != texture->asRenderTar get()) { |
| 555 fResourceCache->makeNonExclusive(texture->getCacheEntry()); | 549 fResourceCache->makeNonExclusive(texture->getCacheEntry()); |
| 556 this->purgeCache(); | 550 this->purgeCache(); |
| 557 } else if (texture->unique() && texture->getDeferredRefCount() <= 0) { | |
|
bsalomon
2014/07/21 20:14:46
I'm not sure I did the right thing here. Maybe I s
robertphillips
2014/07/21 20:53:05
I think we want to remove the check of deferred re
| |
| 558 // Only the cache now knows about this texture. Since we're never | |
| 559 // reusing scratch textures (in this code path) it would just be | |
| 560 // wasting time sitting in the cache. | |
| 561 fResourceCache->makeNonExclusive(texture->getCacheEntry()); | |
| 562 fResourceCache->deleteResource(texture->getCacheEntry()); | |
| 563 } else { | 551 } else { |
| 564 // 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 |
| 565 // 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). |
| 566 // 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 |
| 567 // addExistingTextureToCache once its ref count reaches 0. For | 555 // addExistingTextureToCache once its ref count reaches 0. For |
| 568 // 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. |
| 569 texture->impl()->setFlag((GrTextureFlags) GrTextureImpl::kReturnToCa che_FlagBit); | 557 texture->impl()->setFlag((GrTextureFlags) GrTextureImpl::kReturnToCa che_FlagBit); |
| 570 // Give up the cache's ref to the texture | 558 // Give up the cache's ref to the texture |
| 571 texture->unref(); | 559 texture->unref(); |
| 572 } | 560 } |
| (...skipping 1361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1934 fDrawBuffer->removeGpuTraceMarker(marker); | 1922 fDrawBuffer->removeGpuTraceMarker(marker); |
| 1935 } | 1923 } |
| 1936 } | 1924 } |
| 1937 | 1925 |
| 1938 /////////////////////////////////////////////////////////////////////////////// | 1926 /////////////////////////////////////////////////////////////////////////////// |
| 1939 #if GR_CACHE_STATS | 1927 #if GR_CACHE_STATS |
| 1940 void GrContext::printCacheStats() const { | 1928 void GrContext::printCacheStats() const { |
| 1941 fResourceCache->printStats(); | 1929 fResourceCache->printStats(); |
| 1942 } | 1930 } |
| 1943 #endif | 1931 #endif |
| OLD | NEW |