| 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 | 10 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 static int32_t next_id() { | 131 static int32_t next_id() { |
| 132 int32_t id; | 132 int32_t id; |
| 133 do { | 133 do { |
| 134 id = sk_atomic_inc(&gNextID); | 134 id = sk_atomic_inc(&gNextID); |
| 135 } while (id == SK_InvalidGenID); | 135 } while (id == SK_InvalidGenID); |
| 136 return id; | 136 return id; |
| 137 } | 137 } |
| 138 | 138 |
| 139 GrContext::GrContext() : fUniqueID(next_id()) { | 139 GrContext::GrContext() : fUniqueID(next_id()) { |
| 140 fGpu = NULL; | 140 fGpu = NULL; |
| 141 fCaps = NULL; | |
| 142 fResourceCache = NULL; | 141 fResourceCache = NULL; |
| 143 fResourceProvider = NULL; | 142 fResourceProvider = NULL; |
| 144 fPathRendererChain = NULL; | 143 fPathRendererChain = NULL; |
| 145 fSoftwarePathRenderer = NULL; | 144 fSoftwarePathRenderer = NULL; |
| 146 fBatchFontCache = NULL; | 145 fBatchFontCache = NULL; |
| 147 fFlushToReduceCacheSize = false; | 146 fFlushToReduceCacheSize = false; |
| 148 } | 147 } |
| 149 | 148 |
| 150 bool GrContext::init(GrBackend backend, GrBackendContext backendContext, | 149 bool GrContext::init(GrBackend backend, GrBackendContext backendContext, |
| 151 const GrContextOptions& options) { | 150 const GrContextOptions& options) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 167 fLayerCache.reset(SkNEW_ARGS(GrLayerCache, (this))); | 166 fLayerCache.reset(SkNEW_ARGS(GrLayerCache, (this))); |
| 168 | 167 |
| 169 fDidTestPMConversions = false; | 168 fDidTestPMConversions = false; |
| 170 | 169 |
| 171 fDrawingMgr.init(this); | 170 fDrawingMgr.init(this); |
| 172 | 171 |
| 173 // GrBatchFontCache will eventually replace GrFontCache | 172 // GrBatchFontCache will eventually replace GrFontCache |
| 174 fBatchFontCache = SkNEW_ARGS(GrBatchFontCache, (this)); | 173 fBatchFontCache = SkNEW_ARGS(GrBatchFontCache, (this)); |
| 175 | 174 |
| 176 fTextBlobCache.reset(SkNEW_ARGS(GrTextBlobCache, (TextBlobCacheOverBudgetCB,
this))); | 175 fTextBlobCache.reset(SkNEW_ARGS(GrTextBlobCache, (TextBlobCacheOverBudgetCB,
this))); |
| 177 | |
| 178 fCaps = SkRef(fGpu->caps()); | |
| 179 } | 176 } |
| 180 | 177 |
| 181 GrContext::~GrContext() { | 178 GrContext::~GrContext() { |
| 182 if (!fGpu) { | 179 if (!fGpu) { |
| 183 SkASSERT(!fCaps); | |
| 184 return; | 180 return; |
| 185 } | 181 } |
| 186 | 182 |
| 187 this->flush(); | 183 this->flush(); |
| 188 | 184 |
| 189 for (int i = 0; i < fCleanUpData.count(); ++i) { | 185 for (int i = 0; i < fCleanUpData.count(); ++i) { |
| 190 (*fCleanUpData[i].fFunc)(this, fCleanUpData[i].fInfo); | 186 (*fCleanUpData[i].fFunc)(this, fCleanUpData[i].fInfo); |
| 191 } | 187 } |
| 192 | 188 |
| 193 SkDELETE(fResourceProvider); | 189 SkDELETE(fResourceProvider); |
| 194 SkDELETE(fResourceCache); | 190 SkDELETE(fResourceCache); |
| 195 SkDELETE(fBatchFontCache); | 191 SkDELETE(fBatchFontCache); |
| 196 | 192 |
| 197 fGpu->unref(); | 193 fGpu->unref(); |
| 198 fCaps->unref(); | |
| 199 SkSafeUnref(fPathRendererChain); | 194 SkSafeUnref(fPathRendererChain); |
| 200 SkSafeUnref(fSoftwarePathRenderer); | 195 SkSafeUnref(fSoftwarePathRenderer); |
| 201 } | 196 } |
| 202 | 197 |
| 203 void GrContext::abandonContext() { | 198 void GrContext::abandonContext() { |
| 204 fResourceProvider->abandon(); | 199 fResourceProvider->abandon(); |
| 205 // abandon first to so destructors | 200 // abandon first to so destructors |
| 206 // don't try to free the resources in the API. | 201 // don't try to free the resources in the API. |
| 207 fResourceCache->abandonAll(); | 202 fResourceCache->abandonAll(); |
| 208 | 203 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 if (sb) { | 251 if (sb) { |
| 257 return GrStencilAndCoverTextContext::Create(this, leakyProperties); | 252 return GrStencilAndCoverTextContext::Create(this, leakyProperties); |
| 258 } | 253 } |
| 259 } | 254 } |
| 260 | 255 |
| 261 return GrAtlasTextContext::Create(this, leakyProperties, enableDistanceField
Fonts); | 256 return GrAtlasTextContext::Create(this, leakyProperties, enableDistanceField
Fonts); |
| 262 } | 257 } |
| 263 | 258 |
| 264 //////////////////////////////////////////////////////////////////////////////// | 259 //////////////////////////////////////////////////////////////////////////////// |
| 265 | 260 |
| 261 bool GrContext::shaderDerivativeSupport() const { |
| 262 return fGpu->caps()->shaderCaps()->shaderDerivativeSupport(); |
| 263 } |
| 264 |
| 265 bool GrContext::isConfigTexturable(GrPixelConfig config) const { |
| 266 return fGpu->caps()->isConfigTexturable(config); |
| 267 } |
| 268 |
| 269 bool GrContext::npotTextureTileSupport() const { |
| 270 return fGpu->caps()->npotTextureTileSupport(); |
| 271 } |
| 272 |
| 266 void GrContext::OverBudgetCB(void* data) { | 273 void GrContext::OverBudgetCB(void* data) { |
| 267 SkASSERT(data); | 274 SkASSERT(data); |
| 268 | 275 |
| 269 GrContext* context = reinterpret_cast<GrContext*>(data); | 276 GrContext* context = reinterpret_cast<GrContext*>(data); |
| 270 | 277 |
| 271 // Flush the InOrderDrawBuffer to possibly free up some textures | 278 // Flush the InOrderDrawBuffer to possibly free up some textures |
| 272 context->fFlushToReduceCacheSize = true; | 279 context->fFlushToReduceCacheSize = true; |
| 273 } | 280 } |
| 274 | 281 |
| 275 void GrContext::TextBlobCacheOverBudgetCB(void* data) { | 282 void GrContext::TextBlobCacheOverBudgetCB(void* data) { |
| 276 SkASSERT(data); | 283 SkASSERT(data); |
| 277 | 284 |
| 278 // Unlike the GrResourceCache, TextBlobs are drawn at the SkGpuDevice level,
therefore they | 285 // Unlike the GrResourceCache, TextBlobs are drawn at the SkGpuDevice level,
therefore they |
| 279 // cannot use fFlushTorReduceCacheSize because it uses AutoCheckFlush. The
solution is to move | 286 // cannot use fFlushTorReduceCacheSize because it uses AutoCheckFlush. The
solution is to move |
| 280 // drawText calls to below the GrContext level, but this is not trivial beca
use they call | 287 // drawText calls to below the GrContext level, but this is not trivial beca
use they call |
| 281 // drawPath on SkGpuDevice | 288 // drawPath on SkGpuDevice |
| 282 GrContext* context = reinterpret_cast<GrContext*>(data); | 289 GrContext* context = reinterpret_cast<GrContext*>(data); |
| 283 context->flush(); | 290 context->flush(); |
| 284 } | 291 } |
| 285 | 292 |
| 293 int GrContext::getMaxTextureSize() const { |
| 294 return fGpu->caps()->maxTextureSize(); |
| 295 } |
| 296 |
| 297 int GrContext::getMaxRenderTargetSize() const { |
| 298 return fGpu->caps()->maxRenderTargetSize(); |
| 299 } |
| 300 |
| 301 int GrContext::getMaxSampleCount() const { |
| 302 return fGpu->caps()->maxSampleCount(); |
| 303 } |
| 304 |
| 286 //////////////////////////////////////////////////////////////////////////////// | 305 //////////////////////////////////////////////////////////////////////////////// |
| 287 | 306 |
| 288 void GrContext::flush(int flagsBitfield) { | 307 void GrContext::flush(int flagsBitfield) { |
| 289 RETURN_IF_ABANDONED | 308 RETURN_IF_ABANDONED |
| 290 | 309 |
| 291 if (kDiscard_FlushBit & flagsBitfield) { | 310 if (kDiscard_FlushBit & flagsBitfield) { |
| 292 fDrawingMgr.reset(); | 311 fDrawingMgr.reset(); |
| 293 } else { | 312 } else { |
| 294 fDrawingMgr.flush(); | 313 fDrawingMgr.flush(); |
| 295 } | 314 } |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 if (!fSoftwarePathRenderer) { | 680 if (!fSoftwarePathRenderer) { |
| 662 fSoftwarePathRenderer = SkNEW_ARGS(GrSoftwarePathRenderer, (this)); | 681 fSoftwarePathRenderer = SkNEW_ARGS(GrSoftwarePathRenderer, (this)); |
| 663 } | 682 } |
| 664 pr = fSoftwarePathRenderer; | 683 pr = fSoftwarePathRenderer; |
| 665 } | 684 } |
| 666 | 685 |
| 667 return pr; | 686 return pr; |
| 668 } | 687 } |
| 669 | 688 |
| 670 //////////////////////////////////////////////////////////////////////////////// | 689 //////////////////////////////////////////////////////////////////////////////// |
| 690 bool GrContext::isConfigRenderable(GrPixelConfig config, bool withMSAA) const { |
| 691 return fGpu->caps()->isConfigRenderable(config, withMSAA); |
| 692 } |
| 693 |
| 671 int GrContext::getRecommendedSampleCount(GrPixelConfig config, | 694 int GrContext::getRecommendedSampleCount(GrPixelConfig config, |
| 672 SkScalar dpi) const { | 695 SkScalar dpi) const { |
| 673 if (!this->caps()->isConfigRenderable(config, true)) { | 696 if (!this->isConfigRenderable(config, true)) { |
| 674 return 0; | 697 return 0; |
| 675 } | 698 } |
| 676 int chosenSampleCount = 0; | 699 int chosenSampleCount = 0; |
| 677 if (fGpu->caps()->shaderCaps()->pathRenderingSupport()) { | 700 if (fGpu->caps()->shaderCaps()->pathRenderingSupport()) { |
| 678 if (dpi >= 250.0f) { | 701 if (dpi >= 250.0f) { |
| 679 chosenSampleCount = 4; | 702 chosenSampleCount = 4; |
| 680 } else { | 703 } else { |
| 681 chosenSampleCount = 16; | 704 chosenSampleCount = 16; |
| 682 } | 705 } |
| 683 } | 706 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 ////////////////////////////////////////////////////////////////////////////// | 768 ////////////////////////////////////////////////////////////////////////////// |
| 746 | 769 |
| 747 void GrContext::addGpuTraceMarker(const GrGpuTraceMarker* marker) { | 770 void GrContext::addGpuTraceMarker(const GrGpuTraceMarker* marker) { |
| 748 fGpu->addGpuTraceMarker(marker); | 771 fGpu->addGpuTraceMarker(marker); |
| 749 } | 772 } |
| 750 | 773 |
| 751 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { | 774 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { |
| 752 fGpu->removeGpuTraceMarker(marker); | 775 fGpu->removeGpuTraceMarker(marker); |
| 753 } | 776 } |
| 754 | 777 |
| OLD | NEW |