Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(428)

Side by Side Diff: src/gpu/GrContext.cpp

Issue 1104343003: remove old text contexts and fontcache (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: tweak Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/GrBitmapTextContext.cpp ('k') | src/gpu/GrDistanceFieldTextContext.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "GrAtlasTextContext.h" 12 #include "GrAtlasTextContext.h"
13 #include "GrBatch.h" 13 #include "GrBatch.h"
14 #include "GrBatchFontCache.h" 14 #include "GrBatchFontCache.h"
15 #include "GrBatchTarget.h" 15 #include "GrBatchTarget.h"
16 #include "GrBufferAllocPool.h" 16 #include "GrBufferAllocPool.h"
17 #include "GrDefaultGeoProcFactory.h" 17 #include "GrDefaultGeoProcFactory.h"
18 #include "GrFontCache.h"
19 #include "GrGpuResource.h" 18 #include "GrGpuResource.h"
20 #include "GrGpuResourcePriv.h" 19 #include "GrGpuResourcePriv.h"
21 #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"
26 #include "GrLayerCache.h" 24 #include "GrLayerCache.h"
27 #include "GrOvalRenderer.h" 25 #include "GrOvalRenderer.h"
28 #include "GrPathRenderer.h" 26 #include "GrPathRenderer.h"
29 #include "GrPathUtils.h" 27 #include "GrPathUtils.h"
30 #include "GrRenderTargetPriv.h" 28 #include "GrRenderTargetPriv.h"
31 #include "GrResourceCache.h" 29 #include "GrResourceCache.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 return NULL; 89 return NULL;
92 } 90 }
93 } 91 }
94 92
95 GrContext::GrContext(const Options& opts) : fOptions(opts) { 93 GrContext::GrContext(const Options& opts) : fOptions(opts) {
96 fGpu = NULL; 94 fGpu = NULL;
97 fPathRendererChain = NULL; 95 fPathRendererChain = NULL;
98 fSoftwarePathRenderer = NULL; 96 fSoftwarePathRenderer = NULL;
99 fResourceCache = NULL; 97 fResourceCache = NULL;
100 fBatchFontCache = NULL; 98 fBatchFontCache = NULL;
101 fFontCache = NULL;
102 fDrawBuffer = NULL; 99 fDrawBuffer = NULL;
103 fDrawBufferVBAllocPool = NULL; 100 fDrawBufferVBAllocPool = NULL;
104 fDrawBufferIBAllocPool = NULL; 101 fDrawBufferIBAllocPool = NULL;
105 fFlushToReduceCacheSize = false; 102 fFlushToReduceCacheSize = false;
106 fAARectRenderer = NULL; 103 fAARectRenderer = NULL;
107 fOvalRenderer = NULL; 104 fOvalRenderer = NULL;
108 fMaxTextureSizeOverride = 1 << 20; 105 fMaxTextureSizeOverride = 1 << 20;
109 } 106 }
110 107
111 bool GrContext::init(GrBackend backend, GrBackendContext backendContext) { 108 bool GrContext::init(GrBackend backend, GrBackendContext backendContext) {
112 SkASSERT(NULL == fGpu); 109 SkASSERT(NULL == fGpu);
113 110
114 fGpu = GrGpu::Create(backend, backendContext, this); 111 fGpu = GrGpu::Create(backend, backendContext, this);
115 if (NULL == fGpu) { 112 if (NULL == fGpu) {
116 return false; 113 return false;
117 } 114 }
118 this->initCommon(); 115 this->initCommon();
119 return true; 116 return true;
120 } 117 }
121 118
122 void GrContext::initCommon() { 119 void GrContext::initCommon() {
123 fResourceCache = SkNEW(GrResourceCache); 120 fResourceCache = SkNEW(GrResourceCache);
124 fResourceCache->setOverBudgetCallback(OverBudgetCB, this); 121 fResourceCache->setOverBudgetCallback(OverBudgetCB, this);
125 122
126 fFontCache = SkNEW_ARGS(GrFontCache, (fGpu));
127
128 fLayerCache.reset(SkNEW_ARGS(GrLayerCache, (this))); 123 fLayerCache.reset(SkNEW_ARGS(GrLayerCache, (this)));
129 124
130 fAARectRenderer = SkNEW_ARGS(GrAARectRenderer, (fGpu)); 125 fAARectRenderer = SkNEW_ARGS(GrAARectRenderer, (fGpu));
131 fOvalRenderer = SkNEW_ARGS(GrOvalRenderer, (fGpu)); 126 fOvalRenderer = SkNEW_ARGS(GrOvalRenderer, (fGpu));
132 127
133 fDidTestPMConversions = false; 128 fDidTestPMConversions = false;
134 129
135 this->setupDrawBuffer(); 130 this->setupDrawBuffer();
136 131
137 // GrBatchFontCache will eventually replace GrFontCache 132 // GrBatchFontCache will eventually replace GrFontCache
138 fBatchFontCache = SkNEW_ARGS(GrBatchFontCache, (this)); 133 fBatchFontCache = SkNEW_ARGS(GrBatchFontCache, (this));
139 134
140 fTextBlobCache.reset(SkNEW_ARGS(GrTextBlobCache, (TextBlobCacheOverBudgetCB, this))); 135 fTextBlobCache.reset(SkNEW_ARGS(GrTextBlobCache, (TextBlobCacheOverBudgetCB, this)));
141 } 136 }
142 137
143 GrContext::~GrContext() { 138 GrContext::~GrContext() {
144 if (NULL == fGpu) { 139 if (NULL == fGpu) {
145 return; 140 return;
146 } 141 }
147 142
148 this->flush(); 143 this->flush();
149 144
150 for (int i = 0; i < fCleanUpData.count(); ++i) { 145 for (int i = 0; i < fCleanUpData.count(); ++i) {
151 (*fCleanUpData[i].fFunc)(this, fCleanUpData[i].fInfo); 146 (*fCleanUpData[i].fFunc)(this, fCleanUpData[i].fInfo);
152 } 147 }
153 148
154 SkDELETE(fResourceCache); 149 SkDELETE(fResourceCache);
155 SkDELETE(fBatchFontCache); 150 SkDELETE(fBatchFontCache);
156 SkDELETE(fFontCache);
157 SkDELETE(fDrawBuffer); 151 SkDELETE(fDrawBuffer);
158 SkDELETE(fDrawBufferVBAllocPool); 152 SkDELETE(fDrawBufferVBAllocPool);
159 SkDELETE(fDrawBufferIBAllocPool); 153 SkDELETE(fDrawBufferIBAllocPool);
160 154
161 fAARectRenderer->unref(); 155 fAARectRenderer->unref();
162 fOvalRenderer->unref(); 156 fOvalRenderer->unref();
163 157
164 fGpu->unref(); 158 fGpu->unref();
165 SkSafeUnref(fPathRendererChain); 159 SkSafeUnref(fPathRendererChain);
166 SkSafeUnref(fSoftwarePathRenderer); 160 SkSafeUnref(fSoftwarePathRenderer);
(...skipping 17 matching lines...) Expand all
184 delete fDrawBufferVBAllocPool; 178 delete fDrawBufferVBAllocPool;
185 fDrawBufferVBAllocPool = NULL; 179 fDrawBufferVBAllocPool = NULL;
186 180
187 delete fDrawBufferIBAllocPool; 181 delete fDrawBufferIBAllocPool;
188 fDrawBufferIBAllocPool = NULL; 182 fDrawBufferIBAllocPool = NULL;
189 183
190 fAARectRenderer->reset(); 184 fAARectRenderer->reset();
191 fOvalRenderer->reset(); 185 fOvalRenderer->reset();
192 186
193 fBatchFontCache->freeAll(); 187 fBatchFontCache->freeAll();
194 fFontCache->freeAll();
195 fLayerCache->freeAll(); 188 fLayerCache->freeAll();
196 fTextBlobCache->freeAll(); 189 fTextBlobCache->freeAll();
197 } 190 }
198 191
199 void GrContext::resetContext(uint32_t state) { 192 void GrContext::resetContext(uint32_t state) {
200 fGpu->markContextDirty(state); 193 fGpu->markContextDirty(state);
201 } 194 }
202 195
203 void GrContext::freeGpuResources() { 196 void GrContext::freeGpuResources() {
204 this->flush(); 197 this->flush();
205 198
206 if (fDrawBuffer) { 199 if (fDrawBuffer) {
207 fDrawBuffer->purgeResources(); 200 fDrawBuffer->purgeResources();
208 } 201 }
209 202
210 fAARectRenderer->reset(); 203 fAARectRenderer->reset();
211 fOvalRenderer->reset(); 204 fOvalRenderer->reset();
212 205
213 fBatchFontCache->freeAll(); 206 fBatchFontCache->freeAll();
214 fFontCache->freeAll();
215 fLayerCache->freeAll(); 207 fLayerCache->freeAll();
216 // a path renderer may be holding onto resources 208 // a path renderer may be holding onto resources
217 SkSafeSetNull(fPathRendererChain); 209 SkSafeSetNull(fPathRendererChain);
218 SkSafeSetNull(fSoftwarePathRenderer); 210 SkSafeSetNull(fSoftwarePathRenderer);
219 211
220 fResourceCache->purgeAllUnlocked(); 212 fResourceCache->purgeAllUnlocked();
221 } 213 }
222 214
223 void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const { 215 void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const {
224 if (resourceCount) { 216 if (resourceCount) {
225 *resourceCount = fResourceCache->getBudgetedResourceCount(); 217 *resourceCount = fResourceCache->getBudgetedResourceCount();
226 } 218 }
227 if (resourceBytes) { 219 if (resourceBytes) {
228 *resourceBytes = fResourceCache->getBudgetedResourceBytes(); 220 *resourceBytes = fResourceCache->getBudgetedResourceBytes();
229 } 221 }
230 } 222 }
231 223
232 GrTextContext* GrContext::createTextContext(GrRenderTarget* renderTarget, 224 GrTextContext* GrContext::createTextContext(GrRenderTarget* renderTarget,
233 SkGpuDevice* gpuDevice, 225 SkGpuDevice* gpuDevice,
234 const SkDeviceProperties& 226 const SkDeviceProperties&
235 leakyProperties, 227 leakyProperties,
236 bool enableDistanceFieldFonts) { 228 bool enableDistanceFieldFonts) {
237 if (fGpu->caps()->pathRenderingSupport() && renderTarget->isMultisampled()) { 229 if (fGpu->caps()->pathRenderingSupport() && renderTarget->isMultisampled()) {
238 GrStencilAttachment* sb = renderTarget->renderTargetPriv().attachStencil Attachment(); 230 GrStencilAttachment* sb = renderTarget->renderTargetPriv().attachStencil Attachment();
239 if (sb) { 231 if (sb) {
240 return GrStencilAndCoverTextContext::Create(this, gpuDevice, leakyPr operties); 232 return GrStencilAndCoverTextContext::Create(this, gpuDevice, leakyPr operties);
241 } 233 }
242 } 234 }
243 235
244 #ifdef USE_BITMAP_TEXTBLOBS
245 return GrAtlasTextContext::Create(this, gpuDevice, leakyProperties, enableDi stanceFieldFonts); 236 return GrAtlasTextContext::Create(this, gpuDevice, leakyProperties, enableDi stanceFieldFonts);
246 #else
247 return GrDistanceFieldTextContext::Create(this, gpuDevice, leakyProperties,
248 enableDistanceFieldFonts);
249 #endif
250 } 237 }
251 238
252 //////////////////////////////////////////////////////////////////////////////// 239 ////////////////////////////////////////////////////////////////////////////////
253 enum ScratchTextureFlags { 240 enum ScratchTextureFlags {
254 kExact_ScratchTextureFlag = 0x1, 241 kExact_ScratchTextureFlag = 0x1,
255 kNoPendingIO_ScratchTextureFlag = 0x2, 242 kNoPendingIO_ScratchTextureFlag = 0x2,
256 kNoCreate_ScratchTextureFlag = 0x4, 243 kNoCreate_ScratchTextureFlag = 0x4,
257 }; 244 };
258 245
259 bool GrContext::isConfigTexturable(GrPixelConfig config) const { 246 bool GrContext::isConfigTexturable(GrPixelConfig config) const {
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 GR_CREATE_TRACE_MARKER("GrContext::drawPaintWithPerspective", target); 446 GR_CREATE_TRACE_MARKER("GrContext::drawPaintWithPerspective", target);
460 target->drawRect(&pipelineBuilder, 447 target->drawRect(&pipelineBuilder,
461 paint->getColor(), 448 paint->getColor(),
462 SkMatrix::I(), 449 SkMatrix::I(),
463 r, 450 r,
464 NULL, 451 NULL,
465 &localMatrix); 452 &localMatrix);
466 } 453 }
467 } 454 }
468 455
469 #ifdef SK_DEVELOPER
470 void GrContext::dumpFontCache() const {
471 fFontCache->dump();
472 }
473 #endif
474
475 //////////////////////////////////////////////////////////////////////////////// 456 ////////////////////////////////////////////////////////////////////////////////
476 457
477 static inline bool is_irect(const SkRect& r) { 458 static inline bool is_irect(const SkRect& r) {
478 return SkScalarIsInt(r.fLeft) && SkScalarIsInt(r.fTop) && 459 return SkScalarIsInt(r.fLeft) && SkScalarIsInt(r.fTop) &&
479 SkScalarIsInt(r.fRight) && SkScalarIsInt(r.fBottom); 460 SkScalarIsInt(r.fRight) && SkScalarIsInt(r.fBottom);
480 } 461 }
481 462
482 static bool apply_aa_to_rect(GrDrawTarget* target, 463 static bool apply_aa_to_rect(GrDrawTarget* target,
483 GrPipelineBuilder* pipelineBuilder, 464 GrPipelineBuilder* pipelineBuilder,
484 SkRect* devBoundRect, 465 SkRect* devBoundRect,
(...skipping 1545 matching lines...) Expand 10 before | Expand all | Expand 10 after
2030 } 2011 }
2031 } 2012 }
2032 2013
2033 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { 2014 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) {
2034 fGpu->removeGpuTraceMarker(marker); 2015 fGpu->removeGpuTraceMarker(marker);
2035 if (fDrawBuffer) { 2016 if (fDrawBuffer) {
2036 fDrawBuffer->removeGpuTraceMarker(marker); 2017 fDrawBuffer->removeGpuTraceMarker(marker);
2037 } 2018 }
2038 } 2019 }
2039 2020
OLDNEW
« no previous file with comments | « src/gpu/GrBitmapTextContext.cpp ('k') | src/gpu/GrDistanceFieldTextContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698