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 "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 | |
71 fDrawContext = SkNEW_ARGS(GrDrawContext, (context, fDrawTarget)); | |
72 } | 70 } |
73 | 71 |
74 GrContext::DrawingMgr::~DrawingMgr() { | 72 GrContext::DrawingMgr::~DrawingMgr() { |
75 SkSafeUnref(fDrawTarget); | 73 SkSafeUnref(fDrawTarget); |
76 SkSafeUnref(fDrawContext); | 74 for (int i = 0; i < kNumContextFlavors; ++i) { |
75 SkSafeUnref(fDrawContext[i][0]); | |
76 SkSafeUnref(fDrawContext[i][1]); | |
77 } | |
77 } | 78 } |
78 | 79 |
79 void GrContext::DrawingMgr::abandon() { | 80 void GrContext::DrawingMgr::abandon() { |
80 SkSafeSetNull(fDrawTarget); | 81 SkSafeSetNull(fDrawTarget); |
81 SkSafeSetNull(fDrawContext->fDrawTarget); | 82 for (int i = 0; i < kNumContextFlavors; ++i) { |
82 SkSafeSetNull(fDrawContext); | 83 for (int j = 0; j < 2; ++j) { |
joshualitt
2015/06/09 17:10:02
magic numbers :(
robertphillips
2015/06/09 17:26:40
Done.
| |
84 if (fDrawContext[i][j]) { | |
85 SkSafeSetNull(fDrawContext[i][j]->fDrawTarget); | |
86 SkSafeSetNull(fDrawContext[i][j]); | |
87 } | |
88 } | |
89 } | |
83 } | 90 } |
84 | 91 |
85 void GrContext::DrawingMgr::purgeResources() { | 92 void GrContext::DrawingMgr::purgeResources() { |
86 if (fDrawTarget) { | 93 if (fDrawTarget) { |
87 fDrawTarget->purgeResources(); | 94 fDrawTarget->purgeResources(); |
88 } | 95 } |
89 } | 96 } |
90 | 97 |
91 void GrContext::DrawingMgr::reset() { | 98 void GrContext::DrawingMgr::reset() { |
92 if (fDrawTarget) { | 99 if (fDrawTarget) { |
93 fDrawTarget->reset(); | 100 fDrawTarget->reset(); |
94 } | 101 } |
95 } | 102 } |
96 | 103 |
97 void GrContext::DrawingMgr::flush() { | 104 void GrContext::DrawingMgr::flush() { |
98 if (fDrawTarget) { | 105 if (fDrawTarget) { |
99 fDrawTarget->flush(); | 106 fDrawTarget->flush(); |
100 } | 107 } |
101 } | 108 } |
102 | 109 |
103 GrDrawContext* GrContext::DrawingMgr::drawContext() { | 110 GrDrawContext* GrContext::DrawingMgr::drawContext(const SkDeviceProperties* devP rops, bool useDFT) { |
104 if (this->abandoned()) { | 111 if (this->abandoned()) { |
105 return NULL; | 112 return NULL; |
106 } | 113 } |
107 return fDrawContext; | 114 |
115 const SkDeviceProperties defProps; | |
116 if (!devProps) { | |
117 devProps = &defProps; | |
118 } | |
119 | |
120 SkASSERT(devProps->pixelGeometry() < kNumContextFlavors); | |
121 if (!fDrawContext[devProps->pixelGeometry()][useDFT]) { | |
122 fDrawContext[devProps->pixelGeometry()][useDFT] = | |
123 SkNEW_ARGS(GrDrawContext, (fContext, fDrawTarget, *devProps, use DFT)); | |
124 } | |
125 | |
126 SkASSERT(fDrawContext[devProps->pixelGeometry()][useDFT]->fDevProps->pixelGe ometry() == | |
127 devProps->pixelGeometry()); | |
128 SkASSERT(fDrawContext[devProps->pixelGeometry()][useDFT]->fDevProps->gamma() == | |
129 devProps->gamma()); | |
130 SkASSERT(fDrawContext[devProps->pixelGeometry()][useDFT]->fUseDFT == useDFT) ; | |
131 | |
132 return fDrawContext[devProps->pixelGeometry()][useDFT]; | |
108 } | 133 } |
109 | 134 |
110 //////////////////////////////////////////////////////////////////////////////// | 135 //////////////////////////////////////////////////////////////////////////////// |
111 | 136 |
112 | 137 |
113 GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext) { | 138 GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext) { |
114 GrContextOptions defaultOptions; | 139 GrContextOptions defaultOptions; |
115 return Create(backend, backendContext, defaultOptions); | 140 return Create(backend, backendContext, defaultOptions); |
116 } | 141 } |
117 | 142 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
239 | 264 |
240 void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const { | 265 void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const { |
241 if (resourceCount) { | 266 if (resourceCount) { |
242 *resourceCount = fResourceCache->getBudgetedResourceCount(); | 267 *resourceCount = fResourceCache->getBudgetedResourceCount(); |
243 } | 268 } |
244 if (resourceBytes) { | 269 if (resourceBytes) { |
245 *resourceBytes = fResourceCache->getBudgetedResourceBytes(); | 270 *resourceBytes = fResourceCache->getBudgetedResourceBytes(); |
246 } | 271 } |
247 } | 272 } |
248 | 273 |
249 GrTextContext* GrContext::createTextContext(GrRenderTarget* renderTarget, | |
250 const SkDeviceProperties& | |
251 leakyProperties, | |
252 bool enableDistanceFieldFonts) { | |
253 if (fGpu->caps()->shaderCaps()->pathRenderingSupport() && renderTarget->isMu ltisampled()) { | |
254 GrStencilAttachment* sb = renderTarget->renderTargetPriv().attachStencil Attachment(); | |
255 if (sb) { | |
256 return GrStencilAndCoverTextContext::Create(this, leakyProperties); | |
257 } | |
258 } | |
259 | |
260 return GrAtlasTextContext::Create(this, leakyProperties, enableDistanceField Fonts); | |
261 } | |
262 | |
263 //////////////////////////////////////////////////////////////////////////////// | 274 //////////////////////////////////////////////////////////////////////////////// |
264 | 275 |
265 void GrContext::OverBudgetCB(void* data) { | 276 void GrContext::OverBudgetCB(void* data) { |
266 SkASSERT(data); | 277 SkASSERT(data); |
267 | 278 |
268 GrContext* context = reinterpret_cast<GrContext*>(data); | 279 GrContext* context = reinterpret_cast<GrContext*>(data); |
269 | 280 |
270 // Flush the InOrderDrawBuffer to possibly free up some textures | 281 // Flush the InOrderDrawBuffer to possibly free up some textures |
271 context->fFlushToReduceCacheSize = true; | 282 context->fFlushToReduceCacheSize = true; |
272 } | 283 } |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
744 ////////////////////////////////////////////////////////////////////////////// | 755 ////////////////////////////////////////////////////////////////////////////// |
745 | 756 |
746 void GrContext::addGpuTraceMarker(const GrGpuTraceMarker* marker) { | 757 void GrContext::addGpuTraceMarker(const GrGpuTraceMarker* marker) { |
747 fGpu->addGpuTraceMarker(marker); | 758 fGpu->addGpuTraceMarker(marker); |
748 } | 759 } |
749 | 760 |
750 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { | 761 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { |
751 fGpu->removeGpuTraceMarker(marker); | 762 fGpu->removeGpuTraceMarker(marker); |
752 } | 763 } |
753 | 764 |
OLD | NEW |