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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 } | 80 } |
81 this->initCommon(options); | 81 this->initCommon(options); |
82 return true; | 82 return true; |
83 } | 83 } |
84 | 84 |
85 void GrContext::initCommon(const GrContextOptions& options) { | 85 void GrContext::initCommon(const GrContextOptions& options) { |
86 ASSERT_SINGLE_OWNER | 86 ASSERT_SINGLE_OWNER |
87 | 87 |
88 fCaps = SkRef(fGpu->caps()); | 88 fCaps = SkRef(fGpu->caps()); |
89 fResourceCache = new GrResourceCache(fCaps); | 89 fResourceCache = new GrResourceCache(fCaps); |
90 fResourceCache->setOverBudgetCallback(OverBudgetCB, this); | |
91 fResourceProvider = new GrResourceProvider(fGpu, fResourceCache, &fSingleOwn
er); | 90 fResourceProvider = new GrResourceProvider(fGpu, fResourceCache, &fSingleOwn
er); |
92 | 91 |
93 fDidTestPMConversions = false; | 92 fDidTestPMConversions = false; |
94 | 93 |
95 GrDrawTarget::Options dtOptions; | 94 GrDrawTarget::Options dtOptions; |
96 dtOptions.fClipBatchToBounds = options.fClipBatchToBounds; | 95 dtOptions.fClipBatchToBounds = options.fClipBatchToBounds; |
97 dtOptions.fDrawBatchBounds = options.fDrawBatchBounds; | 96 dtOptions.fDrawBatchBounds = options.fDrawBatchBounds; |
98 dtOptions.fMaxBatchLookback = options.fMaxBatchLookback; | 97 dtOptions.fMaxBatchLookback = options.fMaxBatchLookback; |
99 dtOptions.fMaxBatchLookahead = options.fMaxBatchLookahead; | 98 dtOptions.fMaxBatchLookahead = options.fMaxBatchLookahead; |
100 fDrawingManager.reset(new GrDrawingManager(this, dtOptions, &fSingleOwner)); | 99 fDrawingManager.reset(new GrDrawingManager(this, dtOptions, &fSingleOwner)); |
(...skipping 95 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 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
797 ASSERT_SINGLE_OWNER | 776 ASSERT_SINGLE_OWNER |
798 fResourceCache->setLimits(maxTextures, maxTextureBytes); | 777 fResourceCache->setLimits(maxTextures, maxTextureBytes); |
799 } | 778 } |
800 | 779 |
801 ////////////////////////////////////////////////////////////////////////////// | 780 ////////////////////////////////////////////////////////////////////////////// |
802 | 781 |
803 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { | 782 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { |
804 ASSERT_SINGLE_OWNER | 783 ASSERT_SINGLE_OWNER |
805 fResourceCache->dumpMemoryStatistics(traceMemoryDump); | 784 fResourceCache->dumpMemoryStatistics(traceMemoryDump); |
806 } | 785 } |
OLD | NEW |