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 |
11 #include "GrAARectRenderer.h" | 11 #include "GrAARectRenderer.h" |
12 #include "GrBatch.h" | 12 #include "GrBatch.h" |
13 #include "GrBatchFontCache.h" | |
14 #include "GrBatchTarget.h" | 13 #include "GrBatchTarget.h" |
15 #include "GrBitmapTextContext.h" | |
16 #include "GrBufferAllocPool.h" | 14 #include "GrBufferAllocPool.h" |
17 #include "GrDefaultGeoProcFactory.h" | 15 #include "GrDefaultGeoProcFactory.h" |
18 #include "GrFontCache.h" | 16 #include "GrFontCache.h" |
19 #include "GrGpuResource.h" | 17 #include "GrGpuResource.h" |
20 #include "GrGpuResourcePriv.h" | 18 #include "GrGpuResourcePriv.h" |
21 #include "GrDistanceFieldTextContext.h" | 19 #include "GrDistanceFieldTextContext.h" |
22 #include "GrDrawTargetCaps.h" | 20 #include "GrDrawTargetCaps.h" |
23 #include "GrGpu.h" | 21 #include "GrGpu.h" |
24 #include "GrIndexBuffer.h" | 22 #include "GrIndexBuffer.h" |
25 #include "GrInOrderDrawBuffer.h" | 23 #include "GrInOrderDrawBuffer.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 context->unref(); | 87 context->unref(); |
90 return NULL; | 88 return NULL; |
91 } | 89 } |
92 } | 90 } |
93 | 91 |
94 GrContext::GrContext(const Options& opts) : fOptions(opts) { | 92 GrContext::GrContext(const Options& opts) : fOptions(opts) { |
95 fGpu = NULL; | 93 fGpu = NULL; |
96 fPathRendererChain = NULL; | 94 fPathRendererChain = NULL; |
97 fSoftwarePathRenderer = NULL; | 95 fSoftwarePathRenderer = NULL; |
98 fResourceCache = NULL; | 96 fResourceCache = NULL; |
99 fBatchFontCache = NULL; | |
100 fFontCache = NULL; | 97 fFontCache = NULL; |
101 fDrawBuffer = NULL; | 98 fDrawBuffer = NULL; |
102 fDrawBufferVBAllocPool = NULL; | 99 fDrawBufferVBAllocPool = NULL; |
103 fDrawBufferIBAllocPool = NULL; | 100 fDrawBufferIBAllocPool = NULL; |
104 fFlushToReduceCacheSize = false; | 101 fFlushToReduceCacheSize = false; |
105 fAARectRenderer = NULL; | 102 fAARectRenderer = NULL; |
106 fOvalRenderer = NULL; | 103 fOvalRenderer = NULL; |
107 fMaxTextureSizeOverride = 1 << 20; | 104 fMaxTextureSizeOverride = 1 << 20; |
108 } | 105 } |
109 | 106 |
(...skipping 15 matching lines...) Expand all Loading... |
125 fFontCache = SkNEW_ARGS(GrFontCache, (fGpu)); | 122 fFontCache = SkNEW_ARGS(GrFontCache, (fGpu)); |
126 | 123 |
127 fLayerCache.reset(SkNEW_ARGS(GrLayerCache, (this))); | 124 fLayerCache.reset(SkNEW_ARGS(GrLayerCache, (this))); |
128 | 125 |
129 fAARectRenderer = SkNEW_ARGS(GrAARectRenderer, (fGpu)); | 126 fAARectRenderer = SkNEW_ARGS(GrAARectRenderer, (fGpu)); |
130 fOvalRenderer = SkNEW_ARGS(GrOvalRenderer, (fGpu)); | 127 fOvalRenderer = SkNEW_ARGS(GrOvalRenderer, (fGpu)); |
131 | 128 |
132 fDidTestPMConversions = false; | 129 fDidTestPMConversions = false; |
133 | 130 |
134 this->setupDrawBuffer(); | 131 this->setupDrawBuffer(); |
135 | |
136 // GrBatchFontCache will eventually replace GrFontCache | |
137 fBatchFontCache = SkNEW(GrBatchFontCache); | |
138 fBatchFontCache->init(this); | |
139 } | 132 } |
140 | 133 |
141 GrContext::~GrContext() { | 134 GrContext::~GrContext() { |
142 if (NULL == fGpu) { | 135 if (NULL == fGpu) { |
143 return; | 136 return; |
144 } | 137 } |
145 | 138 |
146 this->flush(); | 139 this->flush(); |
147 | 140 |
148 for (int i = 0; i < fCleanUpData.count(); ++i) { | 141 for (int i = 0; i < fCleanUpData.count(); ++i) { |
149 (*fCleanUpData[i].fFunc)(this, fCleanUpData[i].fInfo); | 142 (*fCleanUpData[i].fFunc)(this, fCleanUpData[i].fInfo); |
150 } | 143 } |
151 | 144 |
152 SkDELETE(fResourceCache); | 145 SkDELETE(fResourceCache); |
153 SkDELETE(fBatchFontCache); | |
154 SkDELETE(fFontCache); | 146 SkDELETE(fFontCache); |
155 SkDELETE(fDrawBuffer); | 147 SkDELETE(fDrawBuffer); |
156 SkDELETE(fDrawBufferVBAllocPool); | 148 SkDELETE(fDrawBufferVBAllocPool); |
157 SkDELETE(fDrawBufferIBAllocPool); | 149 SkDELETE(fDrawBufferIBAllocPool); |
158 | 150 |
159 fAARectRenderer->unref(); | 151 fAARectRenderer->unref(); |
160 fOvalRenderer->unref(); | 152 fOvalRenderer->unref(); |
161 | 153 |
162 fGpu->unref(); | 154 fGpu->unref(); |
163 SkSafeUnref(fPathRendererChain); | 155 SkSafeUnref(fPathRendererChain); |
(...skipping 17 matching lines...) Expand all Loading... |
181 | 173 |
182 delete fDrawBufferVBAllocPool; | 174 delete fDrawBufferVBAllocPool; |
183 fDrawBufferVBAllocPool = NULL; | 175 fDrawBufferVBAllocPool = NULL; |
184 | 176 |
185 delete fDrawBufferIBAllocPool; | 177 delete fDrawBufferIBAllocPool; |
186 fDrawBufferIBAllocPool = NULL; | 178 fDrawBufferIBAllocPool = NULL; |
187 | 179 |
188 fAARectRenderer->reset(); | 180 fAARectRenderer->reset(); |
189 fOvalRenderer->reset(); | 181 fOvalRenderer->reset(); |
190 | 182 |
191 fBatchFontCache->freeAll(); | |
192 fFontCache->freeAll(); | 183 fFontCache->freeAll(); |
193 fLayerCache->freeAll(); | 184 fLayerCache->freeAll(); |
194 } | 185 } |
195 | 186 |
196 void GrContext::resetContext(uint32_t state) { | 187 void GrContext::resetContext(uint32_t state) { |
197 fGpu->markContextDirty(state); | 188 fGpu->markContextDirty(state); |
198 } | 189 } |
199 | 190 |
200 void GrContext::freeGpuResources() { | 191 void GrContext::freeGpuResources() { |
201 this->flush(); | 192 this->flush(); |
202 | 193 |
203 if (fDrawBuffer) { | 194 if (fDrawBuffer) { |
204 fDrawBuffer->purgeResources(); | 195 fDrawBuffer->purgeResources(); |
205 } | 196 } |
206 | 197 |
207 fAARectRenderer->reset(); | 198 fAARectRenderer->reset(); |
208 fOvalRenderer->reset(); | 199 fOvalRenderer->reset(); |
209 | 200 |
210 fBatchFontCache->freeAll(); | |
211 fFontCache->freeAll(); | 201 fFontCache->freeAll(); |
212 fLayerCache->freeAll(); | 202 fLayerCache->freeAll(); |
213 // a path renderer may be holding onto resources | 203 // a path renderer may be holding onto resources |
214 SkSafeSetNull(fPathRendererChain); | 204 SkSafeSetNull(fPathRendererChain); |
215 SkSafeSetNull(fSoftwarePathRenderer); | 205 SkSafeSetNull(fSoftwarePathRenderer); |
216 } | 206 } |
217 | 207 |
218 void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes)
const { | 208 void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes)
const { |
219 if (resourceCount) { | 209 if (resourceCount) { |
220 *resourceCount = fResourceCache->getBudgetedResourceCount(); | 210 *resourceCount = fResourceCache->getBudgetedResourceCount(); |
221 } | 211 } |
222 if (resourceBytes) { | 212 if (resourceBytes) { |
223 *resourceBytes = fResourceCache->getBudgetedResourceBytes(); | 213 *resourceBytes = fResourceCache->getBudgetedResourceBytes(); |
224 } | 214 } |
225 } | 215 } |
226 | 216 |
227 GrTextContext* GrContext::createTextContext(GrRenderTarget* renderTarget, | 217 GrTextContext* GrContext::createTextContext(GrRenderTarget* renderTarget, |
228 SkGpuDevice* gpuDevice, | 218 SkGpuDevice* gpuDevice, |
229 const SkDeviceProperties& | 219 const SkDeviceProperties& |
230 leakyProperties, | 220 leakyProperties, |
231 bool enableDistanceFieldFonts) { | 221 bool enableDistanceFieldFonts) { |
232 if (fGpu->caps()->pathRenderingSupport() && renderTarget->isMultisampled())
{ | 222 if (fGpu->caps()->pathRenderingSupport() && renderTarget->isMultisampled())
{ |
233 GrStencilBuffer* sb = renderTarget->renderTargetPriv().attachStencilBuff
er(); | 223 GrStencilBuffer* sb = renderTarget->renderTargetPriv().attachStencilBuff
er(); |
234 if (sb) { | 224 if (sb) { |
235 return GrStencilAndCoverTextContext::Create(this, gpuDevice, leakyPr
operties); | 225 return GrStencilAndCoverTextContext::Create(this, gpuDevice, leakyPr
operties); |
236 } | 226 } |
237 } | 227 } |
238 | 228 |
239 #ifdef USE_BITMAP_TEXTBLOBS | |
240 return GrBitmapTextContextB::Create(this, gpuDevice, leakyProperties); | |
241 #else | |
242 return GrDistanceFieldTextContext::Create(this, gpuDevice, leakyProperties, | 229 return GrDistanceFieldTextContext::Create(this, gpuDevice, leakyProperties, |
243 enableDistanceFieldFonts); | 230 enableDistanceFieldFonts); |
244 #endif | |
245 } | 231 } |
246 | 232 |
247 //////////////////////////////////////////////////////////////////////////////// | 233 //////////////////////////////////////////////////////////////////////////////// |
248 enum ScratchTextureFlags { | 234 enum ScratchTextureFlags { |
249 kExact_ScratchTextureFlag = 0x1, | 235 kExact_ScratchTextureFlag = 0x1, |
250 kNoPendingIO_ScratchTextureFlag = 0x2, | 236 kNoPendingIO_ScratchTextureFlag = 0x2, |
251 kNoCreate_ScratchTextureFlag = 0x4, | 237 kNoCreate_ScratchTextureFlag = 0x4, |
252 }; | 238 }; |
253 | 239 |
254 bool GrContext::isConfigTexturable(GrPixelConfig config) const { | 240 bool GrContext::isConfigTexturable(GrPixelConfig config) const { |
(...skipping 1758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2013 } | 1999 } |
2014 } | 2000 } |
2015 | 2001 |
2016 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { | 2002 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { |
2017 fGpu->removeGpuTraceMarker(marker); | 2003 fGpu->removeGpuTraceMarker(marker); |
2018 if (fDrawBuffer) { | 2004 if (fDrawBuffer) { |
2019 fDrawBuffer->removeGpuTraceMarker(marker); | 2005 fDrawBuffer->removeGpuTraceMarker(marker); |
2020 } | 2006 } |
2021 } | 2007 } |
2022 | 2008 |
OLD | NEW |