| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 | 49 |
| 50 #ifdef SK_DEBUG | 50 #ifdef SK_DEBUG |
| 51 // change this to a 1 to see notifications when partial coverage fails | 51 // change this to a 1 to see notifications when partial coverage fails |
| 52 #define GR_DEBUG_PARTIAL_COVERAGE_CHECK 0 | 52 #define GR_DEBUG_PARTIAL_COVERAGE_CHECK 0 |
| 53 #else | 53 #else |
| 54 #define GR_DEBUG_PARTIAL_COVERAGE_CHECK 0 | 54 #define GR_DEBUG_PARTIAL_COVERAGE_CHECK 0 |
| 55 #endif | 55 #endif |
| 56 | 56 |
| 57 static const size_t MAX_TEXTURE_CACHE_COUNT = 2048; | 57 static const size_t MAX_TEXTURE_CACHE_COUNT = 2048; |
| 58 static const size_t MAX_TEXTURE_CACHE_BYTES = GR_DEFAULT_TEXTURE_CACHE_MB_LIMIT
* 1024 * 1024; | 58 static const size_t MAX_TEXTURE_CACHE_BYTES = GR_DEFAULT_TEXTURE_CACHE_MB_LIMIT
* 1024 * 1024; |
| 59 static const size_t MAX_PATH_CACHE_COUNT = 2048; |
| 60 static const size_t MAX_PATH_CACHE_BYTES = 1 * 1024 * 1024; |
| 59 | 61 |
| 60 static const size_t DRAW_BUFFER_VBPOOL_BUFFER_SIZE = 1 << 15; | 62 static const size_t DRAW_BUFFER_VBPOOL_BUFFER_SIZE = 1 << 15; |
| 61 static const int DRAW_BUFFER_VBPOOL_PREALLOC_BUFFERS = 4; | 63 static const int DRAW_BUFFER_VBPOOL_PREALLOC_BUFFERS = 4; |
| 62 | 64 |
| 63 static const size_t DRAW_BUFFER_IBPOOL_BUFFER_SIZE = 1 << 11; | 65 static const size_t DRAW_BUFFER_IBPOOL_BUFFER_SIZE = 1 << 11; |
| 64 static const int DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS = 4; | 66 static const int DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS = 4; |
| 65 | 67 |
| 66 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this) | 68 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this) |
| 67 | 69 |
| 68 // Glorified typedef to avoid including GrDrawState.h in GrContext.h | 70 // Glorified typedef to avoid including GrDrawState.h in GrContext.h |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 } | 106 } |
| 105 | 107 |
| 106 GrContext::GrContext() { | 108 GrContext::GrContext() { |
| 107 ++THREAD_INSTANCE_COUNT; | 109 ++THREAD_INSTANCE_COUNT; |
| 108 fDrawState = NULL; | 110 fDrawState = NULL; |
| 109 fGpu = NULL; | 111 fGpu = NULL; |
| 110 fClip = NULL; | 112 fClip = NULL; |
| 111 fPathRendererChain = NULL; | 113 fPathRendererChain = NULL; |
| 112 fSoftwarePathRenderer = NULL; | 114 fSoftwarePathRenderer = NULL; |
| 113 fTextureCache = NULL; | 115 fTextureCache = NULL; |
| 116 fPathCache = NULL; |
| 114 fFontCache = NULL; | 117 fFontCache = NULL; |
| 115 fDrawBuffer = NULL; | 118 fDrawBuffer = NULL; |
| 116 fDrawBufferVBAllocPool = NULL; | 119 fDrawBufferVBAllocPool = NULL; |
| 117 fDrawBufferIBAllocPool = NULL; | 120 fDrawBufferIBAllocPool = NULL; |
| 118 fFlushToReduceCacheSize = false; | 121 fFlushToReduceCacheSize = false; |
| 119 fAARectRenderer = NULL; | 122 fAARectRenderer = NULL; |
| 120 fOvalRenderer = NULL; | 123 fOvalRenderer = NULL; |
| 121 fViewMatrix.reset(); | 124 fViewMatrix.reset(); |
| 122 fMaxTextureSizeOverride = 1 << 20; | 125 fMaxTextureSizeOverride = 1 << 20; |
| 123 } | 126 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 } | 169 } |
| 167 | 170 |
| 168 this->flush(); | 171 this->flush(); |
| 169 | 172 |
| 170 // Since the gpu can hold scratch textures, give it a chance to let go | 173 // Since the gpu can hold scratch textures, give it a chance to let go |
| 171 // of them before freeing the texture cache | 174 // of them before freeing the texture cache |
| 172 fGpu->purgeResources(); | 175 fGpu->purgeResources(); |
| 173 | 176 |
| 174 delete fTextureCache; | 177 delete fTextureCache; |
| 175 fTextureCache = NULL; | 178 fTextureCache = NULL; |
| 179 delete fPathCache; |
| 180 fPathCache = NULL; |
| 176 delete fFontCache; | 181 delete fFontCache; |
| 177 delete fDrawBuffer; | 182 delete fDrawBuffer; |
| 178 delete fDrawBufferVBAllocPool; | 183 delete fDrawBufferVBAllocPool; |
| 179 delete fDrawBufferIBAllocPool; | 184 delete fDrawBufferIBAllocPool; |
| 180 | 185 |
| 181 fAARectRenderer->unref(); | 186 fAARectRenderer->unref(); |
| 182 fOvalRenderer->unref(); | 187 fOvalRenderer->unref(); |
| 183 | 188 |
| 184 fGpu->unref(); | 189 fGpu->unref(); |
| 185 SkSafeUnref(fPathRendererChain); | 190 SkSafeUnref(fPathRendererChain); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 210 delete fDrawBufferVBAllocPool; | 215 delete fDrawBufferVBAllocPool; |
| 211 fDrawBufferVBAllocPool = NULL; | 216 fDrawBufferVBAllocPool = NULL; |
| 212 | 217 |
| 213 delete fDrawBufferIBAllocPool; | 218 delete fDrawBufferIBAllocPool; |
| 214 fDrawBufferIBAllocPool = NULL; | 219 fDrawBufferIBAllocPool = NULL; |
| 215 | 220 |
| 216 fAARectRenderer->reset(); | 221 fAARectRenderer->reset(); |
| 217 fOvalRenderer->reset(); | 222 fOvalRenderer->reset(); |
| 218 | 223 |
| 219 fTextureCache->purgeAllUnlocked(); | 224 fTextureCache->purgeAllUnlocked(); |
| 225 if (fPathCache) { |
| 226 fPathCache->purgeAllUnlocked(); |
| 227 } |
| 228 |
| 220 fFontCache->freeAll(); | 229 fFontCache->freeAll(); |
| 221 fGpu->markContextDirty(); | 230 fGpu->markContextDirty(); |
| 222 } | 231 } |
| 223 | 232 |
| 224 void GrContext::resetContext(uint32_t state) { | 233 void GrContext::resetContext(uint32_t state) { |
| 225 fGpu->markContextDirty(state); | 234 fGpu->markContextDirty(state); |
| 226 } | 235 } |
| 227 | 236 |
| 228 void GrContext::freeGpuResources() { | 237 void GrContext::freeGpuResources() { |
| 229 this->flush(); | 238 this->flush(); |
| 230 | 239 |
| 231 fGpu->purgeResources(); | 240 fGpu->purgeResources(); |
| 232 | 241 |
| 233 fAARectRenderer->reset(); | 242 fAARectRenderer->reset(); |
| 234 fOvalRenderer->reset(); | 243 fOvalRenderer->reset(); |
| 235 | 244 |
| 236 fTextureCache->purgeAllUnlocked(); | 245 fTextureCache->purgeAllUnlocked(); |
| 246 if (fPathCache) { |
| 247 fPathCache->purgeAllUnlocked(); |
| 248 } |
| 237 fFontCache->freeAll(); | 249 fFontCache->freeAll(); |
| 238 // a path renderer may be holding onto resources | 250 // a path renderer may be holding onto resources |
| 239 SkSafeSetNull(fPathRendererChain); | 251 SkSafeSetNull(fPathRendererChain); |
| 240 SkSafeSetNull(fSoftwarePathRenderer); | 252 SkSafeSetNull(fSoftwarePathRenderer); |
| 241 } | 253 } |
| 242 | 254 |
| 243 size_t GrContext::getGpuTextureCacheBytes() const { | 255 size_t GrContext::getGpuTextureCacheBytes() const { |
| 244 return fTextureCache->getCachedResourceBytes(); | 256 return fTextureCache->getCachedResourceBytes(); |
| 245 } | 257 } |
| 246 | 258 |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 } | 587 } |
| 576 | 588 |
| 577 int GrContext::getMaxRenderTargetSize() const { | 589 int GrContext::getMaxRenderTargetSize() const { |
| 578 return fGpu->caps()->maxRenderTargetSize(); | 590 return fGpu->caps()->maxRenderTargetSize(); |
| 579 } | 591 } |
| 580 | 592 |
| 581 int GrContext::getMaxSampleCount() const { | 593 int GrContext::getMaxSampleCount() const { |
| 582 return fGpu->caps()->maxSampleCount(); | 594 return fGpu->caps()->maxSampleCount(); |
| 583 } | 595 } |
| 584 | 596 |
| 597 GrPath* GrContext::createPath(const SkPath& inPath, const SkStrokeRec& stroke) { |
| 598 if (!fGpu->caps()->pathRenderingSupport()) { |
| 599 return NULL; |
| 600 } |
| 601 |
| 602 if (!fPathCache) { |
| 603 fPathCache = SkNEW_ARGS(GrResourceCache, |
| 604 (MAX_PATH_CACHE_COUNT, |
| 605 MAX_PATH_CACHE_BYTES)); |
| 606 fPathCache->setOverbudgetCallback(OverbudgetCB, this); |
| 607 } |
| 608 |
| 609 GrResourceKey resourceKey = GrPath::ComputeKey(inPath, stroke); |
| 610 GrPath* path = static_cast<GrPath*>(fPathCache->find(resourceKey)); |
| 611 if (NULL != path && path->isEqualTo(inPath, stroke)) { |
| 612 path->ref(); |
| 613 } else { |
| 614 path = fGpu->createPath(inPath, stroke); |
| 615 fPathCache->purgeAsNeeded(1, path->sizeInBytes()); |
| 616 fPathCache->addResource(resourceKey, path); |
| 617 } |
| 618 return path; |
| 619 } |
| 620 |
| 585 /////////////////////////////////////////////////////////////////////////////// | 621 /////////////////////////////////////////////////////////////////////////////// |
| 586 | 622 |
| 587 GrTexture* GrContext::wrapBackendTexture(const GrBackendTextureDesc& desc) { | 623 GrTexture* GrContext::wrapBackendTexture(const GrBackendTextureDesc& desc) { |
| 588 return fGpu->wrapBackendTexture(desc); | 624 return fGpu->wrapBackendTexture(desc); |
| 589 } | 625 } |
| 590 | 626 |
| 591 GrRenderTarget* GrContext::wrapBackendRenderTarget(const GrBackendRenderTargetDe
sc& desc) { | 627 GrRenderTarget* GrContext::wrapBackendRenderTarget(const GrBackendRenderTargetDe
sc& desc) { |
| 592 return fGpu->wrapBackendRenderTarget(desc); | 628 return fGpu->wrapBackendRenderTarget(desc); |
| 593 } | 629 } |
| 594 | 630 |
| (...skipping 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1769 return GrConfigConversionEffect::Create(texture, swapRAndB, upmToPM, mat
rix); | 1805 return GrConfigConversionEffect::Create(texture, swapRAndB, upmToPM, mat
rix); |
| 1770 } else { | 1806 } else { |
| 1771 return NULL; | 1807 return NULL; |
| 1772 } | 1808 } |
| 1773 } | 1809 } |
| 1774 | 1810 |
| 1775 /////////////////////////////////////////////////////////////////////////////// | 1811 /////////////////////////////////////////////////////////////////////////////// |
| 1776 #if GR_CACHE_STATS | 1812 #if GR_CACHE_STATS |
| 1777 void GrContext::printCacheStats() const { | 1813 void GrContext::printCacheStats() const { |
| 1778 fTextureCache->printStats(); | 1814 fTextureCache->printStats(); |
| 1815 if (fPathCache) { |
| 1816 fPathCache->printStats(); |
| 1817 } |
| 1779 } | 1818 } |
| 1780 #endif | 1819 #endif |
| OLD | NEW |