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

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

Issue 1175553002: Make GrTextContext be owned by the GrDrawContext (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix nvpr config Created 5 years, 6 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/GrAtlasTextContext.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 "GrAARectRenderer.h" 11 #include "GrAARectRenderer.h"
12 #include "GrAtlasTextContext.h"
13 #include "GrBatch.h" 12 #include "GrBatch.h"
14 #include "GrBatchFontCache.h" 13 #include "GrBatchFontCache.h"
15 #include "GrBatchTarget.h" 14 #include "GrBatchTarget.h"
16 #include "GrBatchTest.h" 15 #include "GrBatchTest.h"
17 #include "GrCaps.h" 16 #include "GrCaps.h"
18 #include "GrContextOptions.h" 17 #include "GrContextOptions.h"
19 #include "GrDefaultGeoProcFactory.h" 18 #include "GrDefaultGeoProcFactory.h"
20 #include "GrDrawContext.h" 19 #include "GrDrawContext.h"
21 #include "GrGpuResource.h" 20 #include "GrGpuResource.h"
22 #include "GrGpuResourcePriv.h" 21 #include "GrGpuResourcePriv.h"
23 #include "GrGpu.h" 22 #include "GrGpu.h"
24 #include "GrImmediateDrawTarget.h" 23 #include "GrImmediateDrawTarget.h"
25 #include "GrIndexBuffer.h" 24 #include "GrIndexBuffer.h"
26 #include "GrInOrderDrawBuffer.h" 25 #include "GrInOrderDrawBuffer.h"
27 #include "GrLayerCache.h" 26 #include "GrLayerCache.h"
28 #include "GrOvalRenderer.h" 27 #include "GrOvalRenderer.h"
29 #include "GrPathRenderer.h" 28 #include "GrPathRenderer.h"
30 #include "GrPathUtils.h" 29 #include "GrPathUtils.h"
31 #include "GrRenderTargetPriv.h" 30 #include "GrRenderTargetPriv.h"
32 #include "GrResourceCache.h" 31 #include "GrResourceCache.h"
33 #include "GrResourceProvider.h" 32 #include "GrResourceProvider.h"
34 #include "GrSoftwarePathRenderer.h" 33 #include "GrSoftwarePathRenderer.h"
35 #include "GrStencilAndCoverTextContext.h"
36 #include "GrStrokeInfo.h" 34 #include "GrStrokeInfo.h"
37 #include "GrSurfacePriv.h" 35 #include "GrSurfacePriv.h"
38 #include "GrTextBlobCache.h" 36 #include "GrTextBlobCache.h"
39 #include "GrTexturePriv.h" 37 #include "GrTexturePriv.h"
40 #include "GrTraceMarker.h" 38 #include "GrTraceMarker.h"
41 #include "GrTracing.h" 39 #include "GrTracing.h"
42 #include "GrVertices.h" 40 #include "GrVertices.h"
43 #include "SkDashPathPriv.h" 41 #include "SkDashPathPriv.h"
44 #include "SkConfig8888.h" 42 #include "SkConfig8888.h"
45 #include "SkGr.h" 43 #include "SkGr.h"
46 #include "SkRRect.h" 44 #include "SkRRect.h"
47 #include "SkStrokeRec.h" 45 #include "SkStrokeRec.h"
48 #include "SkTLazy.h" 46 #include "SkTLazy.h"
49 #include "SkTLS.h" 47 #include "SkTLS.h"
50 #include "SkTraceEvent.h" 48 #include "SkTraceEvent.h"
51 49
52 #include "effects/GrConfigConversionEffect.h" 50 #include "effects/GrConfigConversionEffect.h"
53 #include "effects/GrDashingEffect.h" 51 #include "effects/GrDashingEffect.h"
54 #include "effects/GrSingleTextureEffect.h" 52 #include "effects/GrSingleTextureEffect.h"
55 53
56 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this) 54 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this)
57 #define RETURN_IF_ABANDONED if (fDrawingMgr.abandoned()) { return; } 55 #define RETURN_IF_ABANDONED if (fDrawingMgr.abandoned()) { return; }
58 #define RETURN_FALSE_IF_ABANDONED if (fDrawingMgr.abandoned()) { return false; } 56 #define RETURN_FALSE_IF_ABANDONED if (fDrawingMgr.abandoned()) { return false; }
59 #define RETURN_NULL_IF_ABANDONED if (fDrawingMgr.abandoned()) { return NULL; } 57 #define RETURN_NULL_IF_ABANDONED if (fDrawingMgr.abandoned()) { return NULL; }
60 58
61 59
62 //////////////////////////////////////////////////////////////////////////////// 60 ////////////////////////////////////////////////////////////////////////////////
63 61
64 void GrContext::DrawingMgr::init(GrContext* context) { 62 void GrContext::DrawingMgr::init(GrContext* context) {
63 fContext = context;
64
65 #ifdef IMMEDIATE_MODE 65 #ifdef IMMEDIATE_MODE
66 fDrawTarget = SkNEW_ARGS(GrImmediateDrawTarget, (context)); 66 fDrawTarget = SkNEW_ARGS(GrImmediateDrawTarget, (context));
67 #else 67 #else
68 fDrawTarget = SkNEW_ARGS(GrInOrderDrawBuffer, (context)); 68 fDrawTarget = SkNEW_ARGS(GrInOrderDrawBuffer, (context));
69 #endif 69 #endif
70 }
70 71
71 fDrawContext = SkNEW_ARGS(GrDrawContext, (context, fDrawTarget)); 72 void GrContext::DrawingMgr::cleanup() {
73 SkSafeSetNull(fDrawTarget);
74 for (int i = 0; i < kNumPixelGeometries; ++i) {
75 SkSafeSetNull(fDrawContext[i][0]);
76 SkSafeSetNull(fDrawContext[i][1]);
77 }
72 } 78 }
73 79
74 GrContext::DrawingMgr::~DrawingMgr() { 80 GrContext::DrawingMgr::~DrawingMgr() {
75 SkSafeUnref(fDrawTarget); 81 this->cleanup();
76 SkSafeUnref(fDrawContext);
77 } 82 }
78 83
79 void GrContext::DrawingMgr::abandon() { 84 void GrContext::DrawingMgr::abandon() {
80 SkSafeSetNull(fDrawTarget); 85 SkSafeSetNull(fDrawTarget);
81 SkSafeSetNull(fDrawContext->fDrawTarget); 86 for (int i = 0; i < kNumPixelGeometries; ++i) {
82 SkSafeSetNull(fDrawContext); 87 for (int j = 0; j < kNumDFTOptions; ++j) {
88 if (fDrawContext[i][j]) {
89 SkSafeSetNull(fDrawContext[i][j]->fDrawTarget);
90 SkSafeSetNull(fDrawContext[i][j]);
91 }
92 }
93 }
83 } 94 }
84 95
85 void GrContext::DrawingMgr::purgeResources() { 96 void GrContext::DrawingMgr::purgeResources() {
86 if (fDrawTarget) { 97 if (fDrawTarget) {
87 fDrawTarget->purgeResources(); 98 fDrawTarget->purgeResources();
88 } 99 }
89 } 100 }
90 101
91 void GrContext::DrawingMgr::reset() { 102 void GrContext::DrawingMgr::reset() {
92 if (fDrawTarget) { 103 if (fDrawTarget) {
93 fDrawTarget->reset(); 104 fDrawTarget->reset();
94 } 105 }
95 } 106 }
96 107
97 void GrContext::DrawingMgr::flush() { 108 void GrContext::DrawingMgr::flush() {
98 if (fDrawTarget) { 109 if (fDrawTarget) {
99 fDrawTarget->flush(); 110 fDrawTarget->flush();
100 } 111 }
101 } 112 }
102 113
103 GrDrawContext* GrContext::DrawingMgr::drawContext() { 114 GrDrawContext* GrContext::DrawingMgr::drawContext(const SkDeviceProperties* devP rops, bool useDFT) {
104 if (this->abandoned()) { 115 if (this->abandoned()) {
105 return NULL; 116 return NULL;
106 } 117 }
107 return fDrawContext; 118
119 const SkDeviceProperties defProps;
120 if (!devProps) {
121 devProps = &defProps;
122 }
123
124 SkASSERT(devProps->pixelGeometry() < kNumPixelGeometries);
125 if (!fDrawContext[devProps->pixelGeometry()][useDFT]) {
126 fDrawContext[devProps->pixelGeometry()][useDFT] =
127 SkNEW_ARGS(GrDrawContext, (fContext, fDrawTarget, *devProps, use DFT));
128 }
129
130 SkASSERT(fDrawContext[devProps->pixelGeometry()][useDFT]->fDevProps->pixelGe ometry() ==
131 devProps->pixelGeometry());
132 SkASSERT(fDrawContext[devProps->pixelGeometry()][useDFT]->fDevProps->gamma() ==
133 devProps->gamma());
134 SkASSERT(fDrawContext[devProps->pixelGeometry()][useDFT]->fUseDFT == useDFT) ;
135
136 return fDrawContext[devProps->pixelGeometry()][useDFT];
108 } 137 }
109 138
110 //////////////////////////////////////////////////////////////////////////////// 139 ////////////////////////////////////////////////////////////////////////////////
111 140
112 141
113 GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext) { 142 GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext) {
114 GrContextOptions defaultOptions; 143 GrContextOptions defaultOptions;
115 return Create(backend, backendContext, defaultOptions); 144 return Create(backend, backendContext, defaultOptions);
116 } 145 }
117 146
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 } 207 }
179 208
180 GrContext::~GrContext() { 209 GrContext::~GrContext() {
181 if (!fGpu) { 210 if (!fGpu) {
182 SkASSERT(!fCaps); 211 SkASSERT(!fCaps);
183 return; 212 return;
184 } 213 }
185 214
186 this->flush(); 215 this->flush();
187 216
217 fDrawingMgr.cleanup();
218
188 for (int i = 0; i < fCleanUpData.count(); ++i) { 219 for (int i = 0; i < fCleanUpData.count(); ++i) {
189 (*fCleanUpData[i].fFunc)(this, fCleanUpData[i].fInfo); 220 (*fCleanUpData[i].fFunc)(this, fCleanUpData[i].fInfo);
190 } 221 }
191 222
192 SkDELETE(fResourceProvider); 223 SkDELETE(fResourceProvider);
193 SkDELETE(fResourceCache); 224 SkDELETE(fResourceCache);
194 SkDELETE(fBatchFontCache); 225 SkDELETE(fBatchFontCache);
195 226
196 fGpu->unref(); 227 fGpu->unref();
197 fCaps->unref(); 228 fCaps->unref();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 270
240 void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const { 271 void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const {
241 if (resourceCount) { 272 if (resourceCount) {
242 *resourceCount = fResourceCache->getBudgetedResourceCount(); 273 *resourceCount = fResourceCache->getBudgetedResourceCount();
243 } 274 }
244 if (resourceBytes) { 275 if (resourceBytes) {
245 *resourceBytes = fResourceCache->getBudgetedResourceBytes(); 276 *resourceBytes = fResourceCache->getBudgetedResourceBytes();
246 } 277 }
247 } 278 }
248 279
249 GrTextContext* GrContext::createTextContext(GrRenderTarget* renderTarget,
250 const SkDeviceProperties&
251 leakyProperties,
252 bool enableDistanceFieldFonts) {
253 if (fGpu->caps()->shaderCaps()->pathRenderingSupport() &&
254 renderTarget->isStencilBufferMultisampled()) {
255 GrStencilAttachment* sb = renderTarget->renderTargetPriv().attachStencil Attachment();
256 if (sb) {
257 return GrStencilAndCoverTextContext::Create(this, leakyProperties);
258 }
259 }
260
261 return GrAtlasTextContext::Create(this, leakyProperties, enableDistanceField Fonts);
262 }
263
264 //////////////////////////////////////////////////////////////////////////////// 280 ////////////////////////////////////////////////////////////////////////////////
265 281
266 void GrContext::OverBudgetCB(void* data) { 282 void GrContext::OverBudgetCB(void* data) {
267 SkASSERT(data); 283 SkASSERT(data);
268 284
269 GrContext* context = reinterpret_cast<GrContext*>(data); 285 GrContext* context = reinterpret_cast<GrContext*>(data);
270 286
271 // Flush the InOrderDrawBuffer to possibly free up some textures 287 // Flush the InOrderDrawBuffer to possibly free up some textures
272 context->fFlushToReduceCacheSize = true; 288 context->fFlushToReduceCacheSize = true;
273 } 289 }
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 ////////////////////////////////////////////////////////////////////////////// 761 //////////////////////////////////////////////////////////////////////////////
746 762
747 void GrContext::addGpuTraceMarker(const GrGpuTraceMarker* marker) { 763 void GrContext::addGpuTraceMarker(const GrGpuTraceMarker* marker) {
748 fGpu->addGpuTraceMarker(marker); 764 fGpu->addGpuTraceMarker(marker);
749 } 765 }
750 766
751 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { 767 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) {
752 fGpu->removeGpuTraceMarker(marker); 768 fGpu->removeGpuTraceMarker(marker);
753 } 769 }
754 770
OLDNEW
« no previous file with comments | « src/gpu/GrAtlasTextContext.cpp ('k') | src/gpu/GrDrawContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698