| 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 #include "GrContext.h" | 9 #include "GrContext.h" |
| 10 #include "GrContextOptions.h" | 10 #include "GrContextOptions.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 id = sk_atomic_inc(&gNextID); | 53 id = sk_atomic_inc(&gNextID); |
| 54 } while (id == SK_InvalidGenID); | 54 } while (id == SK_InvalidGenID); |
| 55 return id; | 55 return id; |
| 56 } | 56 } |
| 57 | 57 |
| 58 GrContext::GrContext() : fUniqueID(next_id()) { | 58 GrContext::GrContext() : fUniqueID(next_id()) { |
| 59 fGpu = nullptr; | 59 fGpu = nullptr; |
| 60 fCaps = nullptr; | 60 fCaps = nullptr; |
| 61 fResourceCache = nullptr; | 61 fResourceCache = nullptr; |
| 62 fResourceProvider = nullptr; | 62 fResourceProvider = nullptr; |
| 63 fPathRendererChain = nullptr; | |
| 64 fSoftwarePathRenderer = nullptr; | |
| 65 fBatchFontCache = nullptr; | 63 fBatchFontCache = nullptr; |
| 66 fFlushToReduceCacheSize = false; | 64 fFlushToReduceCacheSize = false; |
| 67 } | 65 } |
| 68 | 66 |
| 69 bool GrContext::init(GrBackend backend, GrBackendContext backendContext, | 67 bool GrContext::init(GrBackend backend, GrBackendContext backendContext, |
| 70 const GrContextOptions& options) { | 68 const GrContextOptions& options) { |
| 71 SkASSERT(!fGpu); | 69 SkASSERT(!fGpu); |
| 72 | 70 |
| 73 fGpu = GrGpu::Create(backend, backendContext, options, this); | 71 fGpu = GrGpu::Create(backend, backendContext, options, this); |
| 74 if (!fGpu) { | 72 if (!fGpu) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 for (int i = 0; i < fCleanUpData.count(); ++i) { | 109 for (int i = 0; i < fCleanUpData.count(); ++i) { |
| 112 (*fCleanUpData[i].fFunc)(this, fCleanUpData[i].fInfo); | 110 (*fCleanUpData[i].fFunc)(this, fCleanUpData[i].fInfo); |
| 113 } | 111 } |
| 114 | 112 |
| 115 delete fResourceProvider; | 113 delete fResourceProvider; |
| 116 delete fResourceCache; | 114 delete fResourceCache; |
| 117 delete fBatchFontCache; | 115 delete fBatchFontCache; |
| 118 | 116 |
| 119 fGpu->unref(); | 117 fGpu->unref(); |
| 120 fCaps->unref(); | 118 fCaps->unref(); |
| 121 SkSafeUnref(fPathRendererChain); | |
| 122 SkSafeUnref(fSoftwarePathRenderer); | |
| 123 } | 119 } |
| 124 | 120 |
| 125 void GrContext::abandonContext() { | 121 void GrContext::abandonContext() { |
| 126 fResourceProvider->abandon(); | 122 fResourceProvider->abandon(); |
| 127 // abandon first to so destructors | 123 // abandon first to so destructors |
| 128 // don't try to free the resources in the API. | 124 // don't try to free the resources in the API. |
| 129 fResourceCache->abandonAll(); | 125 fResourceCache->abandonAll(); |
| 130 | 126 |
| 131 fGpu->contextAbandoned(); | 127 fGpu->contextAbandoned(); |
| 132 | 128 |
| 133 // a path renderer may be holding onto resources that | |
| 134 // are now unusable | |
| 135 SkSafeSetNull(fPathRendererChain); | |
| 136 SkSafeSetNull(fSoftwarePathRenderer); | |
| 137 | |
| 138 fDrawingManager->abandon(); | 129 fDrawingManager->abandon(); |
| 139 | 130 |
| 140 fBatchFontCache->freeAll(); | 131 fBatchFontCache->freeAll(); |
| 141 fLayerCache->freeAll(); | 132 fLayerCache->freeAll(); |
| 142 fTextBlobCache->freeAll(); | 133 fTextBlobCache->freeAll(); |
| 143 } | 134 } |
| 144 | 135 |
| 145 void GrContext::resetContext(uint32_t state) { | 136 void GrContext::resetContext(uint32_t state) { |
| 146 fGpu->markContextDirty(state); | 137 fGpu->markContextDirty(state); |
| 147 } | 138 } |
| 148 | 139 |
| 149 void GrContext::freeGpuResources() { | 140 void GrContext::freeGpuResources() { |
| 150 this->flush(); | 141 this->flush(); |
| 151 | 142 |
| 152 fBatchFontCache->freeAll(); | 143 fBatchFontCache->freeAll(); |
| 153 fLayerCache->freeAll(); | 144 fLayerCache->freeAll(); |
| 154 // a path renderer may be holding onto resources | 145 |
| 155 SkSafeSetNull(fPathRendererChain); | 146 fDrawingManager->freeGpuResources(); |
| 156 SkSafeSetNull(fSoftwarePathRenderer); | |
| 157 | 147 |
| 158 fResourceCache->purgeAllUnlocked(); | 148 fResourceCache->purgeAllUnlocked(); |
| 159 } | 149 } |
| 160 | 150 |
| 161 void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes)
const { | 151 void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes)
const { |
| 162 if (resourceCount) { | 152 if (resourceCount) { |
| 163 *resourceCount = fResourceCache->getBudgetedResourceCount(); | 153 *resourceCount = fResourceCache->getBudgetedResourceCount(); |
| 164 } | 154 } |
| 165 if (resourceBytes) { | 155 if (resourceBytes) { |
| 166 *resourceBytes = fResourceCache->getBudgetedResourceBytes(); | 156 *resourceBytes = fResourceCache->getBudgetedResourceBytes(); |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 } | 518 } |
| 529 } | 519 } |
| 530 | 520 |
| 531 void GrContext::flushSurfaceWrites(GrSurface* surface) { | 521 void GrContext::flushSurfaceWrites(GrSurface* surface) { |
| 532 RETURN_IF_ABANDONED | 522 RETURN_IF_ABANDONED |
| 533 if (surface->surfacePriv().hasPendingWrite()) { | 523 if (surface->surfacePriv().hasPendingWrite()) { |
| 534 this->flush(); | 524 this->flush(); |
| 535 } | 525 } |
| 536 } | 526 } |
| 537 | 527 |
| 538 /* | |
| 539 * This method finds a path renderer that can draw the specified path on | |
| 540 * the provided target. | |
| 541 * Due to its expense, the software path renderer has split out so it can | |
| 542 * can be individually allowed/disallowed via the "allowSW" boolean. | |
| 543 */ | |
| 544 GrPathRenderer* GrContext::getPathRenderer(const GrPipelineBuilder& pipelineBuil
der, | |
| 545 const SkMatrix& viewMatrix, | |
| 546 const SkPath& path, | |
| 547 const GrStrokeInfo& stroke, | |
| 548 bool allowSW, | |
| 549 GrPathRendererChain::DrawType drawTyp
e, | |
| 550 GrPathRendererChain::StencilSupport*
stencilSupport) { | |
| 551 | |
| 552 if (!fPathRendererChain) { | |
| 553 fPathRendererChain = new GrPathRendererChain(this); | |
| 554 } | |
| 555 | |
| 556 GrPathRenderer* pr = fPathRendererChain->getPathRenderer(this->caps()->shade
rCaps(), | |
| 557 pipelineBuilder, | |
| 558 viewMatrix, | |
| 559 path, | |
| 560 stroke, | |
| 561 drawType, | |
| 562 stencilSupport); | |
| 563 | |
| 564 if (!pr && allowSW) { | |
| 565 if (!fSoftwarePathRenderer) { | |
| 566 fSoftwarePathRenderer = new GrSoftwarePathRenderer(this); | |
| 567 } | |
| 568 pr = fSoftwarePathRenderer; | |
| 569 } | |
| 570 | |
| 571 return pr; | |
| 572 } | |
| 573 | |
| 574 //////////////////////////////////////////////////////////////////////////////// | 528 //////////////////////////////////////////////////////////////////////////////// |
| 575 int GrContext::getRecommendedSampleCount(GrPixelConfig config, | 529 int GrContext::getRecommendedSampleCount(GrPixelConfig config, |
| 576 SkScalar dpi) const { | 530 SkScalar dpi) const { |
| 577 if (!this->caps()->isConfigRenderable(config, true)) { | 531 if (!this->caps()->isConfigRenderable(config, true)) { |
| 578 return 0; | 532 return 0; |
| 579 } | 533 } |
| 580 int chosenSampleCount = 0; | 534 int chosenSampleCount = 0; |
| 581 if (fGpu->caps()->shaderCaps()->pathRenderingSupport()) { | 535 if (fGpu->caps()->shaderCaps()->pathRenderingSupport()) { |
| 582 if (dpi >= 250.0f) { | 536 if (dpi >= 250.0f) { |
| 583 chosenSampleCount = 4; | 537 chosenSampleCount = 4; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 | 620 |
| 667 void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes)
{ | 621 void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes)
{ |
| 668 fResourceCache->setLimits(maxTextures, maxTextureBytes); | 622 fResourceCache->setLimits(maxTextures, maxTextureBytes); |
| 669 } | 623 } |
| 670 | 624 |
| 671 ////////////////////////////////////////////////////////////////////////////// | 625 ////////////////////////////////////////////////////////////////////////////// |
| 672 | 626 |
| 673 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { | 627 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { |
| 674 fResourceCache->dumpMemoryStatistics(traceMemoryDump); | 628 fResourceCache->dumpMemoryStatistics(traceMemoryDump); |
| 675 } | 629 } |
| OLD | NEW |