| 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" |
| 11 | 11 |
| 12 #include "effects/GrConfigConversionEffect.h" | 12 #include "effects/GrConfigConversionEffect.h" |
| 13 #include "effects/GrDashingEffect.h" | 13 #include "effects/GrDashingEffect.h" |
| 14 #include "effects/GrSingleTextureEffect.h" | 14 #include "effects/GrSingleTextureEffect.h" |
| 15 | 15 |
| 16 #include "GrAARectRenderer.h" | 16 #include "GrAARectRenderer.h" |
| 17 #include "GrBufferAllocPool.h" | 17 #include "GrBufferAllocPool.h" |
| 18 #include "GrGpu.h" | 18 #include "GrGpu.h" |
| 19 #include "GrDistanceFieldTextContext.h" | 19 #include "GrDistanceFieldTextContext.h" |
| 20 #include "GrDrawTargetCaps.h" | 20 #include "GrDrawTargetCaps.h" |
| 21 #include "GrIndexBuffer.h" | 21 #include "GrIndexBuffer.h" |
| 22 #include "GrInOrderDrawBuffer.h" | 22 #include "GrInOrderDrawBuffer.h" |
| 23 #include "GrLayerCache.h" | 23 #include "GrLayerCache.h" |
| 24 #include "GrOvalRenderer.h" | 24 #include "GrOvalRenderer.h" |
| 25 #include "GrPathRenderer.h" | 25 #include "GrPathRenderer.h" |
| 26 #include "GrPathUtils.h" | 26 #include "GrPathUtils.h" |
| 27 #include "GrResourceCache.h" | 27 #include "GrResourceCache.h" |
| 28 #include "GrResourceCache2.h" |
| 28 #include "GrSoftwarePathRenderer.h" | 29 #include "GrSoftwarePathRenderer.h" |
| 29 #include "GrStencilBuffer.h" | 30 #include "GrStencilBuffer.h" |
| 30 #include "GrStencilAndCoverTextContext.h" | 31 #include "GrStencilAndCoverTextContext.h" |
| 31 #include "GrStrokeInfo.h" | 32 #include "GrStrokeInfo.h" |
| 32 #include "GrTextStrike.h" | 33 #include "GrTextStrike.h" |
| 33 #include "GrTraceMarker.h" | 34 #include "GrTraceMarker.h" |
| 34 #include "GrTracing.h" | 35 #include "GrTracing.h" |
| 35 #include "SkDashPathPriv.h" | 36 #include "SkDashPathPriv.h" |
| 36 #include "SkGr.h" | 37 #include "SkGr.h" |
| 37 #include "SkRTConf.h" | 38 #include "SkRTConf.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 } | 102 } |
| 102 } | 103 } |
| 103 | 104 |
| 104 GrContext::GrContext(const Options& opts) : fOptions(opts) { | 105 GrContext::GrContext(const Options& opts) : fOptions(opts) { |
| 105 fDrawState = NULL; | 106 fDrawState = NULL; |
| 106 fGpu = NULL; | 107 fGpu = NULL; |
| 107 fClip = NULL; | 108 fClip = NULL; |
| 108 fPathRendererChain = NULL; | 109 fPathRendererChain = NULL; |
| 109 fSoftwarePathRenderer = NULL; | 110 fSoftwarePathRenderer = NULL; |
| 110 fResourceCache = NULL; | 111 fResourceCache = NULL; |
| 112 fResourceCache2 = NULL; |
| 111 fFontCache = NULL; | 113 fFontCache = NULL; |
| 112 fDrawBuffer = NULL; | 114 fDrawBuffer = NULL; |
| 113 fDrawBufferVBAllocPool = NULL; | 115 fDrawBufferVBAllocPool = NULL; |
| 114 fDrawBufferIBAllocPool = NULL; | 116 fDrawBufferIBAllocPool = NULL; |
| 115 fFlushToReduceCacheSize = false; | 117 fFlushToReduceCacheSize = false; |
| 116 fAARectRenderer = NULL; | 118 fAARectRenderer = NULL; |
| 117 fOvalRenderer = NULL; | 119 fOvalRenderer = NULL; |
| 118 fViewMatrix.reset(); | 120 fViewMatrix.reset(); |
| 119 fMaxTextureSizeOverride = 1 << 20; | 121 fMaxTextureSizeOverride = 1 << 20; |
| 120 } | 122 } |
| 121 | 123 |
| 122 bool GrContext::init(GrBackend backend, GrBackendContext backendContext) { | 124 bool GrContext::init(GrBackend backend, GrBackendContext backendContext) { |
| 123 SkASSERT(NULL == fGpu); | 125 SkASSERT(NULL == fGpu); |
| 124 | 126 |
| 125 fGpu = GrGpu::Create(backend, backendContext, this); | 127 fGpu = GrGpu::Create(backend, backendContext, this); |
| 126 if (NULL == fGpu) { | 128 if (NULL == fGpu) { |
| 127 return false; | 129 return false; |
| 128 } | 130 } |
| 129 | 131 |
| 130 fDrawState = SkNEW(GrDrawState); | 132 fDrawState = SkNEW(GrDrawState); |
| 131 fGpu->setDrawState(fDrawState); | 133 fGpu->setDrawState(fDrawState); |
| 132 | 134 |
| 133 fResourceCache = SkNEW_ARGS(GrResourceCache, (MAX_RESOURCE_CACHE_COUNT, | 135 fResourceCache = SkNEW_ARGS(GrResourceCache, (MAX_RESOURCE_CACHE_COUNT, |
| 134 MAX_RESOURCE_CACHE_BYTES)); | 136 MAX_RESOURCE_CACHE_BYTES)); |
| 135 fResourceCache->setOverbudgetCallback(OverbudgetCB, this); | 137 fResourceCache->setOverbudgetCallback(OverbudgetCB, this); |
| 138 fResourceCache2 = SkNEW(GrResourceCache2); |
| 136 | 139 |
| 137 fFontCache = SkNEW_ARGS(GrFontCache, (fGpu)); | 140 fFontCache = SkNEW_ARGS(GrFontCache, (fGpu)); |
| 138 | 141 |
| 139 fLayerCache.reset(SkNEW_ARGS(GrLayerCache, (this))); | 142 fLayerCache.reset(SkNEW_ARGS(GrLayerCache, (this))); |
| 140 | 143 |
| 141 fLastDrawWasBuffered = kNo_BufferedDraw; | 144 fLastDrawWasBuffered = kNo_BufferedDraw; |
| 142 | 145 |
| 143 fAARectRenderer = SkNEW(GrAARectRenderer); | 146 fAARectRenderer = SkNEW(GrAARectRenderer); |
| 144 fOvalRenderer = SkNEW(GrOvalRenderer); | 147 fOvalRenderer = SkNEW(GrOvalRenderer); |
| 145 | 148 |
| 146 fDidTestPMConversions = false; | 149 fDidTestPMConversions = false; |
| 147 | 150 |
| 148 this->setupDrawBuffer(); | 151 this->setupDrawBuffer(); |
| 149 | 152 |
| 150 return true; | 153 return true; |
| 151 } | 154 } |
| 152 | 155 |
| 153 GrContext::~GrContext() { | 156 GrContext::~GrContext() { |
| 154 if (NULL == fGpu) { | 157 if (NULL == fGpu) { |
| 155 return; | 158 return; |
| 156 } | 159 } |
| 157 | 160 |
| 158 this->flush(); | 161 this->flush(); |
| 159 | 162 |
| 160 for (int i = 0; i < fCleanUpData.count(); ++i) { | 163 for (int i = 0; i < fCleanUpData.count(); ++i) { |
| 161 (*fCleanUpData[i].fFunc)(this, fCleanUpData[i].fInfo); | 164 (*fCleanUpData[i].fFunc)(this, fCleanUpData[i].fInfo); |
| 162 } | 165 } |
| 163 | 166 |
| 164 // Since the gpu can hold scratch textures, give it a chance to let go | 167 delete fResourceCache2; |
| 165 // of them before freeing the texture cache | 168 fResourceCache2 = NULL; |
| 166 fGpu->purgeResources(); | |
| 167 | |
| 168 delete fResourceCache; | 169 delete fResourceCache; |
| 169 fResourceCache = NULL; | 170 fResourceCache = NULL; |
| 170 delete fFontCache; | 171 delete fFontCache; |
| 171 delete fDrawBuffer; | 172 delete fDrawBuffer; |
| 172 delete fDrawBufferVBAllocPool; | 173 delete fDrawBufferVBAllocPool; |
| 173 delete fDrawBufferIBAllocPool; | 174 delete fDrawBufferIBAllocPool; |
| 174 | 175 |
| 175 fAARectRenderer->unref(); | 176 fAARectRenderer->unref(); |
| 176 fOvalRenderer->unref(); | 177 fOvalRenderer->unref(); |
| 177 | 178 |
| 178 fGpu->unref(); | 179 fGpu->unref(); |
| 179 SkSafeUnref(fPathRendererChain); | 180 SkSafeUnref(fPathRendererChain); |
| 180 SkSafeUnref(fSoftwarePathRenderer); | 181 SkSafeUnref(fSoftwarePathRenderer); |
| 181 fDrawState->unref(); | 182 fDrawState->unref(); |
| 182 } | 183 } |
| 183 | 184 |
| 184 void GrContext::abandonContext() { | 185 void GrContext::abandonContext() { |
| 185 // abandon first to so destructors | 186 // abandon first to so destructors |
| 186 // don't try to free the resources in the API. | 187 // don't try to free the resources in the API. |
| 187 fGpu->abandonResources(); | 188 fResourceCache2->abandonAll(); |
| 189 |
| 190 fGpu->contextAbandonded(); |
| 188 | 191 |
| 189 // a path renderer may be holding onto resources that | 192 // a path renderer may be holding onto resources that |
| 190 // are now unusable | 193 // are now unusable |
| 191 SkSafeSetNull(fPathRendererChain); | 194 SkSafeSetNull(fPathRendererChain); |
| 192 SkSafeSetNull(fSoftwarePathRenderer); | 195 SkSafeSetNull(fSoftwarePathRenderer); |
| 193 | 196 |
| 194 delete fDrawBuffer; | 197 delete fDrawBuffer; |
| 195 fDrawBuffer = NULL; | 198 fDrawBuffer = NULL; |
| 196 | 199 |
| 197 delete fDrawBufferVBAllocPool; | 200 delete fDrawBufferVBAllocPool; |
| 198 fDrawBufferVBAllocPool = NULL; | 201 fDrawBufferVBAllocPool = NULL; |
| 199 | 202 |
| 200 delete fDrawBufferIBAllocPool; | 203 delete fDrawBufferIBAllocPool; |
| 201 fDrawBufferIBAllocPool = NULL; | 204 fDrawBufferIBAllocPool = NULL; |
| 202 | 205 |
| 203 fAARectRenderer->reset(); | 206 fAARectRenderer->reset(); |
| 204 fOvalRenderer->reset(); | 207 fOvalRenderer->reset(); |
| 205 | 208 |
| 206 fResourceCache->purgeAllUnlocked(); | 209 fResourceCache->purgeAllUnlocked(); |
| 207 | 210 |
| 208 fFontCache->freeAll(); | 211 fFontCache->freeAll(); |
| 209 fLayerCache->freeAll(); | 212 fLayerCache->freeAll(); |
| 210 fGpu->markContextDirty(); | |
| 211 } | 213 } |
| 212 | 214 |
| 213 void GrContext::resetContext(uint32_t state) { | 215 void GrContext::resetContext(uint32_t state) { |
| 214 fGpu->markContextDirty(state); | 216 fGpu->markContextDirty(state); |
| 215 } | 217 } |
| 216 | 218 |
| 217 void GrContext::freeGpuResources() { | 219 void GrContext::freeGpuResources() { |
| 218 this->flush(); | 220 this->flush(); |
| 219 | 221 |
| 220 fGpu->purgeResources(); | 222 fGpu->purgeResources(); |
| 223 if (NULL != fDrawBuffer) { |
| 224 fDrawBuffer->purgeResources(); |
| 225 } |
| 221 | 226 |
| 222 fAARectRenderer->reset(); | 227 fAARectRenderer->reset(); |
| 223 fOvalRenderer->reset(); | 228 fOvalRenderer->reset(); |
| 224 | 229 |
| 225 fResourceCache->purgeAllUnlocked(); | 230 fResourceCache->purgeAllUnlocked(); |
| 226 fFontCache->freeAll(); | 231 fFontCache->freeAll(); |
| 227 fLayerCache->freeAll(); | 232 fLayerCache->freeAll(); |
| 228 // a path renderer may be holding onto resources | 233 // a path renderer may be holding onto resources |
| 229 SkSafeSetNull(fPathRendererChain); | 234 SkSafeSetNull(fPathRendererChain); |
| 230 SkSafeSetNull(fSoftwarePathRenderer); | 235 SkSafeSetNull(fSoftwarePathRenderer); |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 this->purgeCache(); | 538 this->purgeCache(); |
| 534 } else { | 539 } else { |
| 535 // When we aren't reusing textures we know this scratch texture | 540 // When we aren't reusing textures we know this scratch texture |
| 536 // will never be reused and would be just wasting time in the cache | 541 // will never be reused and would be just wasting time in the cache |
| 537 fResourceCache->makeNonExclusive(texture->getCacheEntry()); | 542 fResourceCache->makeNonExclusive(texture->getCacheEntry()); |
| 538 fResourceCache->deleteResource(texture->getCacheEntry()); | 543 fResourceCache->deleteResource(texture->getCacheEntry()); |
| 539 } | 544 } |
| 540 } | 545 } |
| 541 | 546 |
| 542 void GrContext::unlockScratchTexture(GrTexture* texture) { | 547 void GrContext::unlockScratchTexture(GrTexture* texture) { |
| 548 if (texture->wasDestroyed()) { |
| 549 if (texture->getCacheEntry()->key().isScratch()) { |
| 550 // This texture was detached from the cache but the cache still had
a ref to it but |
| 551 // not a pointer to it. |
| 552 texture->unref(); |
| 553 } |
| 554 return; |
| 555 } |
| 556 |
| 543 ASSERT_OWNED_RESOURCE(texture); | 557 ASSERT_OWNED_RESOURCE(texture); |
| 544 SkASSERT(NULL != texture->getCacheEntry()); | 558 SkASSERT(NULL != texture->getCacheEntry()); |
| 545 | 559 |
| 546 // If this is a scratch texture we detached it from the cache | 560 // If this is a scratch texture we detached it from the cache |
| 547 // while it was locked (to avoid two callers simultaneously getting | 561 // while it was locked (to avoid two callers simultaneously getting |
| 548 // the same texture). | 562 // the same texture). |
| 549 if (texture->getCacheEntry()->key().isScratch()) { | 563 if (texture->getCacheEntry()->key().isScratch()) { |
| 550 if (fGpu->caps()->reuseScratchTextures() || NULL != texture->asRenderTar
get()) { | 564 if (fGpu->caps()->reuseScratchTextures() || NULL != texture->asRenderTar
get()) { |
| 551 fResourceCache->makeNonExclusive(texture->getCacheEntry()); | 565 fResourceCache->makeNonExclusive(texture->getCacheEntry()); |
| 552 this->purgeCache(); | 566 this->purgeCache(); |
| (...skipping 1378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1931 fDrawBuffer->removeGpuTraceMarker(marker); | 1945 fDrawBuffer->removeGpuTraceMarker(marker); |
| 1932 } | 1946 } |
| 1933 } | 1947 } |
| 1934 | 1948 |
| 1935 /////////////////////////////////////////////////////////////////////////////// | 1949 /////////////////////////////////////////////////////////////////////////////// |
| 1936 #if GR_CACHE_STATS | 1950 #if GR_CACHE_STATS |
| 1937 void GrContext::printCacheStats() const { | 1951 void GrContext::printCacheStats() const { |
| 1938 fResourceCache->printStats(); | 1952 fResourceCache->printStats(); |
| 1939 } | 1953 } |
| 1940 #endif | 1954 #endif |
| OLD | NEW |