| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "GrContext.h" | 8 #include "GrContext.h" |
| 9 #include "GrContextPriv.h" | 9 #include "GrContextPriv.h" |
| 10 #include "GrContextOptions.h" | 10 #include "GrContextOptions.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 } while (id == SK_InvalidGenID); | 59 } while (id == SK_InvalidGenID); |
| 60 return id; | 60 return id; |
| 61 } | 61 } |
| 62 | 62 |
| 63 GrContext::GrContext() : fUniqueID(next_id()) { | 63 GrContext::GrContext() : fUniqueID(next_id()) { |
| 64 fGpu = nullptr; | 64 fGpu = nullptr; |
| 65 fCaps = nullptr; | 65 fCaps = nullptr; |
| 66 fResourceCache = nullptr; | 66 fResourceCache = nullptr; |
| 67 fResourceProvider = nullptr; | 67 fResourceProvider = nullptr; |
| 68 fBatchFontCache = nullptr; | 68 fBatchFontCache = nullptr; |
| 69 fFlushToReduceCacheSize = false; | |
| 70 } | 69 } |
| 71 | 70 |
| 72 bool GrContext::init(GrBackend backend, GrBackendContext backendContext, | 71 bool GrContext::init(GrBackend backend, GrBackendContext backendContext, |
| 73 const GrContextOptions& options) { | 72 const GrContextOptions& options) { |
| 74 ASSERT_SINGLE_OWNER | 73 ASSERT_SINGLE_OWNER |
| 75 SkASSERT(!fGpu); | 74 SkASSERT(!fGpu); |
| 76 | 75 |
| 77 fGpu = GrGpu::Create(backend, backendContext, options, this); | 76 fGpu = GrGpu::Create(backend, backendContext, options, this); |
| 78 if (!fGpu) { | 77 if (!fGpu) { |
| 79 return false; | 78 return false; |
| 80 } | 79 } |
| 81 this->initCommon(options); | 80 this->initCommon(options); |
| 82 return true; | 81 return true; |
| 83 } | 82 } |
| 84 | 83 |
| 85 void GrContext::initCommon(const GrContextOptions& options) { | 84 void GrContext::initCommon(const GrContextOptions& options) { |
| 86 ASSERT_SINGLE_OWNER | 85 ASSERT_SINGLE_OWNER |
| 87 | 86 |
| 88 fCaps = SkRef(fGpu->caps()); | 87 fCaps = SkRef(fGpu->caps()); |
| 89 fResourceCache = new GrResourceCache(fCaps); | 88 fResourceCache = new GrResourceCache(fCaps); |
| 90 fResourceCache->setOverBudgetCallback(OverBudgetCB, this); | |
| 91 fResourceProvider = new GrResourceProvider(fGpu, fResourceCache, &fSingleOwn
er); | 89 fResourceProvider = new GrResourceProvider(fGpu, fResourceCache, &fSingleOwn
er); |
| 92 | 90 |
| 93 fDidTestPMConversions = false; | 91 fDidTestPMConversions = false; |
| 94 | 92 |
| 95 GrDrawTarget::Options dtOptions; | 93 GrDrawTarget::Options dtOptions; |
| 96 dtOptions.fClipBatchToBounds = options.fClipBatchToBounds; | 94 dtOptions.fClipBatchToBounds = options.fClipBatchToBounds; |
| 97 dtOptions.fDrawBatchBounds = options.fDrawBatchBounds; | 95 dtOptions.fDrawBatchBounds = options.fDrawBatchBounds; |
| 98 dtOptions.fMaxBatchLookback = options.fMaxBatchLookback; | 96 dtOptions.fMaxBatchLookback = options.fMaxBatchLookback; |
| 99 dtOptions.fMaxBatchLookahead = options.fMaxBatchLookahead; | 97 dtOptions.fMaxBatchLookahead = options.fMaxBatchLookahead; |
| 100 fDrawingManager.reset(new GrDrawingManager(this, dtOptions, &fSingleOwner)); | 98 fDrawingManager.reset(new GrDrawingManager(this, dtOptions, options.fImmedia
teMode, |
| 99 &fSingleOwner)); |
| 101 | 100 |
| 102 // GrBatchFontCache will eventually replace GrFontCache | 101 // GrBatchFontCache will eventually replace GrFontCache |
| 103 fBatchFontCache = new GrBatchFontCache(this); | 102 fBatchFontCache = new GrBatchFontCache(this); |
| 104 | 103 |
| 105 fTextBlobCache.reset(new GrTextBlobCache(TextBlobCacheOverBudgetCB, this)); | 104 fTextBlobCache.reset(new GrTextBlobCache(TextBlobCacheOverBudgetCB, this)); |
| 106 } | 105 } |
| 107 | 106 |
| 108 GrContext::~GrContext() { | 107 GrContext::~GrContext() { |
| 109 ASSERT_SINGLE_OWNER | 108 ASSERT_SINGLE_OWNER |
| 110 | 109 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 if (resourceCount) { | 195 if (resourceCount) { |
| 197 *resourceCount = fResourceCache->getBudgetedResourceCount(); | 196 *resourceCount = fResourceCache->getBudgetedResourceCount(); |
| 198 } | 197 } |
| 199 if (resourceBytes) { | 198 if (resourceBytes) { |
| 200 *resourceBytes = fResourceCache->getBudgetedResourceBytes(); | 199 *resourceBytes = fResourceCache->getBudgetedResourceBytes(); |
| 201 } | 200 } |
| 202 } | 201 } |
| 203 | 202 |
| 204 //////////////////////////////////////////////////////////////////////////////// | 203 //////////////////////////////////////////////////////////////////////////////// |
| 205 | 204 |
| 206 void GrContext::OverBudgetCB(void* data) { | |
| 207 SkASSERT(data); | |
| 208 | |
| 209 GrContext* context = reinterpret_cast<GrContext*>(data); | |
| 210 | |
| 211 // Flush the GrBufferedDrawTarget to possibly free up some textures | |
| 212 context->fFlushToReduceCacheSize = true; | |
| 213 } | |
| 214 | |
| 215 void GrContext::TextBlobCacheOverBudgetCB(void* data) { | 205 void GrContext::TextBlobCacheOverBudgetCB(void* data) { |
| 216 SkASSERT(data); | 206 SkASSERT(data); |
| 217 | 207 // TextBlobs are drawn at the SkGpuDevice level, therefore they cannot rely
on GrDrawContext |
| 218 // Unlike the GrResourceCache, TextBlobs are drawn at the SkGpuDevice level,
therefore they | 208 // to perform a necessary flush. The solution is to move drawText calls to
below the GrContext |
| 219 // cannot use fFlushTorReduceCacheSize because it uses AutoCheckFlush. The
solution is to move | 209 // level, but this is not trivial because they call drawPath on SkGpuDevice. |
| 220 // drawText calls to below the GrContext level, but this is not trivial beca
use they call | |
| 221 // drawPath on SkGpuDevice | |
| 222 GrContext* context = reinterpret_cast<GrContext*>(data); | 210 GrContext* context = reinterpret_cast<GrContext*>(data); |
| 223 context->flush(); | 211 context->flush(); |
| 224 } | 212 } |
| 225 | 213 |
| 226 //////////////////////////////////////////////////////////////////////////////// | 214 //////////////////////////////////////////////////////////////////////////////// |
| 227 | 215 |
| 228 void GrContext::flush(int flagsBitfield) { | 216 void GrContext::flush() { |
| 229 ASSERT_SINGLE_OWNER | 217 ASSERT_SINGLE_OWNER |
| 230 RETURN_IF_ABANDONED | 218 RETURN_IF_ABANDONED |
| 231 bool flushed = false; | 219 fDrawingManager->flush(); |
| 232 if (kDiscard_FlushBit & flagsBitfield) { | |
| 233 fDrawingManager->reset(); | |
| 234 } else { | |
| 235 flushed = fDrawingManager->flush(); | |
| 236 } | |
| 237 if (flushed) { | |
| 238 fResourceCache->notifyFlushOccurred(); | |
| 239 } | |
| 240 fFlushToReduceCacheSize = false; | |
| 241 } | 220 } |
| 242 | 221 |
| 243 bool sw_convert_to_premul(GrPixelConfig srcConfig, int width, int height, size_t
inRowBytes, | 222 bool sw_convert_to_premul(GrPixelConfig srcConfig, int width, int height, size_t
inRowBytes, |
| 244 const void* inPixels, size_t outRowBytes, void* outPix
els) { | 223 const void* inPixels, size_t outRowBytes, void* outPix
els) { |
| 245 SkSrcPixelInfo srcPI; | 224 SkSrcPixelInfo srcPI; |
| 246 if (!GrPixelConfigToColorType(srcConfig, &srcPI.fColorType)) { | 225 if (!GrPixelConfigToColorType(srcConfig, &srcPI.fColorType)) { |
| 247 return false; | 226 return false; |
| 248 } | 227 } |
| 249 srcPI.fAlphaType = kUnpremul_SkAlphaType; | 228 srcPI.fAlphaType = kUnpremul_SkAlphaType; |
| 250 srcPI.fPixels = inPixels; | 229 srcPI.fPixels = inPixels; |
| (...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 857 ASSERT_SINGLE_OWNER | 836 ASSERT_SINGLE_OWNER |
| 858 fResourceCache->setLimits(maxTextures, maxTextureBytes); | 837 fResourceCache->setLimits(maxTextures, maxTextureBytes); |
| 859 } | 838 } |
| 860 | 839 |
| 861 ////////////////////////////////////////////////////////////////////////////// | 840 ////////////////////////////////////////////////////////////////////////////// |
| 862 | 841 |
| 863 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { | 842 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { |
| 864 ASSERT_SINGLE_OWNER | 843 ASSERT_SINGLE_OWNER |
| 865 fResourceCache->dumpMemoryStatistics(traceMemoryDump); | 844 fResourceCache->dumpMemoryStatistics(traceMemoryDump); |
| 866 } | 845 } |
| OLD | NEW |