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