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

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

Issue 1413673002: Remove DrawingMgr shims from GrContext (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix names in comments Created 5 years, 2 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/effects/SkMorphologyImageFilter.cpp ('k') | src/gpu/GrDrawContext.cpp » ('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 "GrBatchFontCache.h" 11 #include "GrBatchFontCache.h"
12 #include "GrBatchFlushState.h" 12 #include "GrBatchFlushState.h"
13 #include "GrBatchTest.h" 13 #include "GrBatchTest.h"
14 #include "GrCaps.h" 14 #include "GrCaps.h"
15 #include "GrContextOptions.h" 15 #include "GrContextOptions.h"
16 #include "GrDefaultGeoProcFactory.h" 16 #include "GrDefaultGeoProcFactory.h"
17 #include "GrDrawingManager.h"
17 #include "GrDrawContext.h" 18 #include "GrDrawContext.h"
18 #include "GrDrawTarget.h" 19 #include "GrDrawTarget.h"
19 #include "GrGpuResource.h" 20 #include "GrGpuResource.h"
20 #include "GrGpuResourcePriv.h" 21 #include "GrGpuResourcePriv.h"
21 #include "GrGpu.h" 22 #include "GrGpu.h"
22 #include "GrIndexBuffer.h" 23 #include "GrIndexBuffer.h"
23 #include "GrLayerCache.h" 24 #include "GrLayerCache.h"
24 #include "GrOvalRenderer.h" 25 #include "GrOvalRenderer.h"
25 #include "GrPathRenderer.h" 26 #include "GrPathRenderer.h"
26 #include "GrPathUtils.h" 27 #include "GrPathUtils.h"
(...skipping 19 matching lines...) Expand all
46 #include "SkTraceEvent.h" 47 #include "SkTraceEvent.h"
47 48
48 49
49 #include "batches/GrBatch.h" 50 #include "batches/GrBatch.h"
50 51
51 #include "effects/GrConfigConversionEffect.h" 52 #include "effects/GrConfigConversionEffect.h"
52 #include "effects/GrDashingEffect.h" 53 #include "effects/GrDashingEffect.h"
53 #include "effects/GrSingleTextureEffect.h" 54 #include "effects/GrSingleTextureEffect.h"
54 55
55 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this) 56 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this)
56 #define RETURN_IF_ABANDONED if (fDrawingMgr.abandoned()) { return; } 57 #define RETURN_IF_ABANDONED if (fDrawingManager->abandoned()) { return; }
57 #define RETURN_FALSE_IF_ABANDONED if (fDrawingMgr.abandoned()) { return false; } 58 #define RETURN_FALSE_IF_ABANDONED if (fDrawingManager->abandoned()) { return fal se; }
58 #define RETURN_NULL_IF_ABANDONED if (fDrawingMgr.abandoned()) { return nullptr; } 59 #define RETURN_NULL_IF_ABANDONED if (fDrawingManager->abandoned()) { return null ptr; }
59 60
60 61
61 //////////////////////////////////////////////////////////////////////////////// 62 ////////////////////////////////////////////////////////////////////////////////
62 63
63 void GrContext::DrawingMgr::init(GrContext* context) { 64 void GrDrawingManager::cleanup() {
64 fContext = context;
65 }
66
67 void GrContext::DrawingMgr::cleanup() {
68 for (int i = 0; i < fDrawTargets.count(); ++i) { 65 for (int i = 0; i < fDrawTargets.count(); ++i) {
69 fDrawTargets[i]->unref(); 66 fDrawTargets[i]->unref();
70 } 67 }
71 68
72 fDrawTargets.reset(); 69 fDrawTargets.reset();
73 70
74 delete fNVPRTextContext; 71 delete fNVPRTextContext;
75 fNVPRTextContext = nullptr; 72 fNVPRTextContext = nullptr;
76 73
77 for (int i = 0; i < kNumPixelGeometries; ++i) { 74 for (int i = 0; i < kNumPixelGeometries; ++i) {
78 delete fTextContexts[i][0]; 75 delete fTextContexts[i][0];
79 fTextContexts[i][0] = nullptr; 76 fTextContexts[i][0] = nullptr;
80 delete fTextContexts[i][1]; 77 delete fTextContexts[i][1];
81 fTextContexts[i][1] = nullptr; 78 fTextContexts[i][1] = nullptr;
82 } 79 }
83 } 80 }
84 81
85 GrContext::DrawingMgr::~DrawingMgr() { 82 GrDrawingManager::~GrDrawingManager() {
86 this->cleanup(); 83 this->cleanup();
87 } 84 }
88 85
89 void GrContext::DrawingMgr::abandon() { 86 void GrDrawingManager::abandon() {
90 fAbandoned = true; 87 fAbandoned = true;
91 this->cleanup(); 88 this->cleanup();
92 } 89 }
93 90
94 void GrContext::DrawingMgr::reset() { 91 void GrDrawingManager::reset() {
95 for (int i = 0; i < fDrawTargets.count(); ++i) { 92 for (int i = 0; i < fDrawTargets.count(); ++i) {
96 fDrawTargets[i]->reset(); 93 fDrawTargets[i]->reset();
97 } 94 }
98 } 95 }
99 96
100 void GrContext::DrawingMgr::flush() { 97 void GrDrawingManager::flush() {
101 for (int i = 0; i < fDrawTargets.count(); ++i) { 98 for (int i = 0; i < fDrawTargets.count(); ++i) {
102 fDrawTargets[i]->flush(); 99 fDrawTargets[i]->flush();
103 } 100 }
104 } 101 }
105 102
106 GrTextContext* GrContext::DrawingMgr::textContext(const SkSurfaceProps& props, 103 GrTextContext* GrDrawingManager::textContext(const SkSurfaceProps& props,
107 GrRenderTarget* rt) { 104 GrRenderTarget* rt) {
108 if (this->abandoned()) { 105 if (this->abandoned()) {
109 return nullptr; 106 return nullptr;
110 } 107 }
111 108
112 SkASSERT(props.pixelGeometry() < kNumPixelGeometries); 109 SkASSERT(props.pixelGeometry() < kNumPixelGeometries);
113 bool useDIF = props.isUseDeviceIndependentFonts(); 110 bool useDIF = props.isUseDeviceIndependentFonts();
114 111
115 if (useDIF && fContext->caps()->shaderCaps()->pathRenderingSupport() && 112 if (useDIF && fContext->caps()->shaderCaps()->pathRenderingSupport() &&
116 rt->isStencilBufferMultisampled()) { 113 rt->isStencilBufferMultisampled()) {
117 GrStencilAttachment* sb = fContext->resourceProvider()->attachStencilAtt achment(rt); 114 GrStencilAttachment* sb = fContext->resourceProvider()->attachStencilAtt achment(rt);
118 if (sb) { 115 if (sb) {
119 if (!fNVPRTextContext) { 116 if (!fNVPRTextContext) {
120 fNVPRTextContext = GrStencilAndCoverTextContext::Create(fContext , props); 117 fNVPRTextContext = GrStencilAndCoverTextContext::Create(fContext , props);
121 } 118 }
122 119
123 return fNVPRTextContext; 120 return fNVPRTextContext;
124 } 121 }
125 } 122 }
126 123
127 if (!fTextContexts[props.pixelGeometry()][useDIF]) { 124 if (!fTextContexts[props.pixelGeometry()][useDIF]) {
128 fTextContexts[props.pixelGeometry()][useDIF] = GrAtlasTextContext::Creat e(fContext, props); 125 fTextContexts[props.pixelGeometry()][useDIF] = GrAtlasTextContext::Creat e(fContext, props);
129 } 126 }
130 127
131 return fTextContexts[props.pixelGeometry()][useDIF]; 128 return fTextContexts[props.pixelGeometry()][useDIF];
132 } 129 }
133 130
134 GrDrawTarget* GrContext::DrawingMgr::newDrawTarget(GrRenderTarget* rt) { 131 GrDrawTarget* GrDrawingManager::newDrawTarget(GrRenderTarget* rt) {
135 SkASSERT(fContext); 132 SkASSERT(fContext);
136 133
137 // When MDB is disabled we always just return the single drawTarget 134 // When MDB is disabled we always just return the single drawTarget
138 #ifndef ENABLE_MDB 135 #ifndef ENABLE_MDB
139 if (fDrawTargets.count()) { 136 if (fDrawTargets.count()) {
140 SkASSERT(fDrawTargets.count() == 1); 137 SkASSERT(fDrawTargets.count() == 1);
141 // DrawingMgr gets the creation ref - this ref is for the caller 138 // DrawingManager gets the creation ref - this ref is for the caller
142 return SkRef(fDrawTargets[0]); 139 return SkRef(fDrawTargets[0]);
143 } 140 }
144 #endif 141 #endif
145 142
146 GrDrawTarget* dt = new GrDrawTarget(fContext->getGpu(), fContext->resourcePr ovider()); 143 GrDrawTarget* dt = new GrDrawTarget(fContext->getGpu(), fContext->resourcePr ovider());
147 144
148 *fDrawTargets.append() = dt; 145 *fDrawTargets.append() = dt;
149 146
150 // DrawingMgr gets the creation ref - this ref is for the caller 147 // DrawingManager gets the creation ref - this ref is for the caller
151 return SkRef(dt); 148 return SkRef(dt);
152 } 149 }
153 150
154 GrDrawContext* GrContext::DrawingMgr::drawContext(GrRenderTarget* rt, 151 GrDrawContext* GrDrawingManager::drawContext(GrRenderTarget* rt,
155 const SkSurfaceProps* surfaceP rops) { 152 const SkSurfaceProps* surfaceProps) {
156 if (this->abandoned()) { 153 if (this->abandoned()) {
157 return nullptr; 154 return nullptr;
158 } 155 }
159 156
160 return new GrDrawContext(fContext, rt, surfaceProps); 157 return new GrDrawContext(this, rt, surfaceProps);
161 } 158 }
162 159
163 //////////////////////////////////////////////////////////////////////////////// 160 ////////////////////////////////////////////////////////////////////////////////
164 161
165 162
166 GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext) { 163 GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext) {
167 GrContextOptions defaultOptions; 164 GrContextOptions defaultOptions;
168 return Create(backend, backendContext, defaultOptions); 165 return Create(backend, backendContext, defaultOptions);
169 } 166 }
170 167
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 void GrContext::initCommon() { 212 void GrContext::initCommon() {
216 fCaps = SkRef(fGpu->caps()); 213 fCaps = SkRef(fGpu->caps());
217 fResourceCache = new GrResourceCache(fCaps); 214 fResourceCache = new GrResourceCache(fCaps);
218 fResourceCache->setOverBudgetCallback(OverBudgetCB, this); 215 fResourceCache->setOverBudgetCallback(OverBudgetCB, this);
219 fResourceProvider = new GrResourceProvider(fGpu, fResourceCache); 216 fResourceProvider = new GrResourceProvider(fGpu, fResourceCache);
220 217
221 fLayerCache.reset(new GrLayerCache(this)); 218 fLayerCache.reset(new GrLayerCache(this));
222 219
223 fDidTestPMConversions = false; 220 fDidTestPMConversions = false;
224 221
225 fDrawingMgr.init(this); 222 fDrawingManager.reset(new GrDrawingManager(this));
226 223
227 // GrBatchFontCache will eventually replace GrFontCache 224 // GrBatchFontCache will eventually replace GrFontCache
228 fBatchFontCache = new GrBatchFontCache(this); 225 fBatchFontCache = new GrBatchFontCache(this);
229 226
230 fTextBlobCache.reset(new GrTextBlobCache(TextBlobCacheOverBudgetCB, this)); 227 fTextBlobCache.reset(new GrTextBlobCache(TextBlobCacheOverBudgetCB, this));
231 } 228 }
232 229
233 GrContext::~GrContext() { 230 GrContext::~GrContext() {
234 if (!fGpu) { 231 if (!fGpu) {
235 SkASSERT(!fCaps); 232 SkASSERT(!fCaps);
236 return; 233 return;
237 } 234 }
238 235
239 this->flush(); 236 this->flush();
240 237
241 fDrawingMgr.cleanup(); 238 fDrawingManager->cleanup();
242 239
243 for (int i = 0; i < fCleanUpData.count(); ++i) { 240 for (int i = 0; i < fCleanUpData.count(); ++i) {
244 (*fCleanUpData[i].fFunc)(this, fCleanUpData[i].fInfo); 241 (*fCleanUpData[i].fFunc)(this, fCleanUpData[i].fInfo);
245 } 242 }
246 243
247 delete fResourceProvider; 244 delete fResourceProvider;
248 delete fResourceCache; 245 delete fResourceCache;
249 delete fBatchFontCache; 246 delete fBatchFontCache;
250 247
251 fGpu->unref(); 248 fGpu->unref();
252 fCaps->unref(); 249 fCaps->unref();
253 SkSafeUnref(fPathRendererChain); 250 SkSafeUnref(fPathRendererChain);
254 SkSafeUnref(fSoftwarePathRenderer); 251 SkSafeUnref(fSoftwarePathRenderer);
255 } 252 }
256 253
257 void GrContext::abandonContext() { 254 void GrContext::abandonContext() {
258 fResourceProvider->abandon(); 255 fResourceProvider->abandon();
259 // abandon first to so destructors 256 // abandon first to so destructors
260 // don't try to free the resources in the API. 257 // don't try to free the resources in the API.
261 fResourceCache->abandonAll(); 258 fResourceCache->abandonAll();
262 259
263 fGpu->contextAbandoned(); 260 fGpu->contextAbandoned();
264 261
265 // a path renderer may be holding onto resources that 262 // a path renderer may be holding onto resources that
266 // are now unusable 263 // are now unusable
267 SkSafeSetNull(fPathRendererChain); 264 SkSafeSetNull(fPathRendererChain);
268 SkSafeSetNull(fSoftwarePathRenderer); 265 SkSafeSetNull(fSoftwarePathRenderer);
269 266
270 fDrawingMgr.abandon(); 267 fDrawingManager->abandon();
271 268
272 fBatchFontCache->freeAll(); 269 fBatchFontCache->freeAll();
273 fLayerCache->freeAll(); 270 fLayerCache->freeAll();
274 fTextBlobCache->freeAll(); 271 fTextBlobCache->freeAll();
275 } 272 }
276 273
277 void GrContext::resetContext(uint32_t state) { 274 void GrContext::resetContext(uint32_t state) {
278 fGpu->markContextDirty(state); 275 fGpu->markContextDirty(state);
279 } 276 }
280 277
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 GrContext* context = reinterpret_cast<GrContext*>(data); 317 GrContext* context = reinterpret_cast<GrContext*>(data);
321 context->flush(); 318 context->flush();
322 } 319 }
323 320
324 //////////////////////////////////////////////////////////////////////////////// 321 ////////////////////////////////////////////////////////////////////////////////
325 322
326 void GrContext::flush(int flagsBitfield) { 323 void GrContext::flush(int flagsBitfield) {
327 RETURN_IF_ABANDONED 324 RETURN_IF_ABANDONED
328 325
329 if (kDiscard_FlushBit & flagsBitfield) { 326 if (kDiscard_FlushBit & flagsBitfield) {
330 fDrawingMgr.reset(); 327 fDrawingManager->reset();
331 } else { 328 } else {
332 fDrawingMgr.flush(); 329 fDrawingManager->flush();
333 } 330 }
334 fResourceCache->notifyFlushOccurred(); 331 fResourceCache->notifyFlushOccurred();
335 fFlushToReduceCacheSize = false; 332 fFlushToReduceCacheSize = false;
336 } 333 }
337 334
338 bool sw_convert_to_premul(GrPixelConfig srcConfig, int width, int height, size_t inRowBytes, 335 bool sw_convert_to_premul(GrPixelConfig srcConfig, int width, int height, size_t inRowBytes,
339 const void* inPixels, size_t outRowBytes, void* outPix els) { 336 const void* inPixels, size_t outRowBytes, void* outPix els) {
340 SkSrcPixelInfo srcPI; 337 SkSrcPixelInfo srcPI;
341 if (!GrPixelConfig2ColorAndProfileType(srcConfig, &srcPI.fColorType, nullptr )) { 338 if (!GrPixelConfig2ColorAndProfileType(srcConfig, &srcPI.fColorType, nullptr )) {
342 return false; 339 return false;
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 if (dpi >= 250.0f) { 707 if (dpi >= 250.0f) {
711 chosenSampleCount = 4; 708 chosenSampleCount = 4;
712 } else { 709 } else {
713 chosenSampleCount = 16; 710 chosenSampleCount = 16;
714 } 711 }
715 } 712 }
716 return chosenSampleCount <= fGpu->caps()->maxSampleCount() ? 713 return chosenSampleCount <= fGpu->caps()->maxSampleCount() ?
717 chosenSampleCount : 0; 714 chosenSampleCount : 0;
718 } 715 }
719 716
717
718 GrDrawContext* GrContext::drawContext(GrRenderTarget* rt, const SkSurfaceProps* surfaceProps) {
719 return fDrawingManager->drawContext(rt, surfaceProps);
720 }
721
722 bool GrContext::abandoned() const {
723 return fDrawingManager->abandoned();
724 }
725
720 namespace { 726 namespace {
721 void test_pm_conversions(GrContext* ctx, int* pmToUPMValue, int* upmToPMValue) { 727 void test_pm_conversions(GrContext* ctx, int* pmToUPMValue, int* upmToPMValue) {
722 GrConfigConversionEffect::PMConversion pmToUPM; 728 GrConfigConversionEffect::PMConversion pmToUPM;
723 GrConfigConversionEffect::PMConversion upmToPM; 729 GrConfigConversionEffect::PMConversion upmToPM;
724 GrConfigConversionEffect::TestForPreservingPMConversions(ctx, &pmToUPM, &upm ToPM); 730 GrConfigConversionEffect::TestForPreservingPMConversions(ctx, &pmToUPM, &upm ToPM);
725 *pmToUPMValue = pmToUPM; 731 *pmToUPMValue = pmToUPM;
726 *upmToPMValue = upmToPM; 732 *upmToPMValue = upmToPM;
727 } 733 }
728 } 734 }
729 735
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 791
786 void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes) { 792 void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes) {
787 fResourceCache->setLimits(maxTextures, maxTextureBytes); 793 fResourceCache->setLimits(maxTextures, maxTextureBytes);
788 } 794 }
789 795
790 ////////////////////////////////////////////////////////////////////////////// 796 //////////////////////////////////////////////////////////////////////////////
791 797
792 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { 798 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const {
793 fResourceCache->dumpMemoryStatistics(traceMemoryDump); 799 fResourceCache->dumpMemoryStatistics(traceMemoryDump);
794 } 800 }
OLDNEW
« no previous file with comments | « src/effects/SkMorphologyImageFilter.cpp ('k') | src/gpu/GrDrawContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698