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" |
12 #include "GrBatch.h" | 13 #include "GrBatch.h" |
13 #include "GrBatchFontCache.h" | 14 #include "GrBatchFontCache.h" |
14 #include "GrBatchTarget.h" | 15 #include "GrBatchTarget.h" |
15 #include "GrBatchTest.h" | 16 #include "GrBatchTest.h" |
16 #include "GrCaps.h" | 17 #include "GrCaps.h" |
17 #include "GrContextOptions.h" | 18 #include "GrContextOptions.h" |
18 #include "GrDefaultGeoProcFactory.h" | 19 #include "GrDefaultGeoProcFactory.h" |
19 #include "GrDrawContext.h" | 20 #include "GrDrawContext.h" |
20 #include "GrGpuResource.h" | 21 #include "GrGpuResource.h" |
21 #include "GrGpuResourcePriv.h" | 22 #include "GrGpuResourcePriv.h" |
22 #include "GrGpu.h" | 23 #include "GrGpu.h" |
23 #include "GrImmediateDrawTarget.h" | 24 #include "GrImmediateDrawTarget.h" |
24 #include "GrIndexBuffer.h" | 25 #include "GrIndexBuffer.h" |
25 #include "GrInOrderDrawBuffer.h" | 26 #include "GrInOrderDrawBuffer.h" |
26 #include "GrLayerCache.h" | 27 #include "GrLayerCache.h" |
27 #include "GrOvalRenderer.h" | 28 #include "GrOvalRenderer.h" |
28 #include "GrPathRenderer.h" | 29 #include "GrPathRenderer.h" |
29 #include "GrPathUtils.h" | 30 #include "GrPathUtils.h" |
30 #include "GrRenderTargetPriv.h" | 31 #include "GrRenderTargetPriv.h" |
31 #include "GrResourceCache.h" | 32 #include "GrResourceCache.h" |
32 #include "GrResourceProvider.h" | 33 #include "GrResourceProvider.h" |
33 #include "GrSoftwarePathRenderer.h" | 34 #include "GrSoftwarePathRenderer.h" |
| 35 #include "GrStencilAndCoverTextContext.h" |
34 #include "GrStrokeInfo.h" | 36 #include "GrStrokeInfo.h" |
35 #include "GrSurfacePriv.h" | 37 #include "GrSurfacePriv.h" |
36 #include "GrTextBlobCache.h" | 38 #include "GrTextBlobCache.h" |
37 #include "GrTexturePriv.h" | 39 #include "GrTexturePriv.h" |
38 #include "GrTraceMarker.h" | 40 #include "GrTraceMarker.h" |
39 #include "GrTracing.h" | 41 #include "GrTracing.h" |
40 #include "GrVertices.h" | 42 #include "GrVertices.h" |
41 #include "SkDashPathPriv.h" | 43 #include "SkDashPathPriv.h" |
42 #include "SkConfig8888.h" | 44 #include "SkConfig8888.h" |
43 #include "SkGr.h" | 45 #include "SkGr.h" |
44 #include "SkRRect.h" | 46 #include "SkRRect.h" |
45 #include "SkStrokeRec.h" | 47 #include "SkStrokeRec.h" |
46 #include "SkTLazy.h" | 48 #include "SkTLazy.h" |
47 #include "SkTLS.h" | 49 #include "SkTLS.h" |
48 #include "SkTraceEvent.h" | 50 #include "SkTraceEvent.h" |
49 | 51 |
50 #include "effects/GrConfigConversionEffect.h" | 52 #include "effects/GrConfigConversionEffect.h" |
51 #include "effects/GrDashingEffect.h" | 53 #include "effects/GrDashingEffect.h" |
52 #include "effects/GrSingleTextureEffect.h" | 54 #include "effects/GrSingleTextureEffect.h" |
53 | 55 |
54 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this) | 56 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this) |
55 #define RETURN_IF_ABANDONED if (fDrawingMgr.abandoned()) { return; } | 57 #define RETURN_IF_ABANDONED if (fDrawingMgr.abandoned()) { return; } |
56 #define RETURN_FALSE_IF_ABANDONED if (fDrawingMgr.abandoned()) { return false; } | 58 #define RETURN_FALSE_IF_ABANDONED if (fDrawingMgr.abandoned()) { return false; } |
57 #define RETURN_NULL_IF_ABANDONED if (fDrawingMgr.abandoned()) { return NULL; } | 59 #define RETURN_NULL_IF_ABANDONED if (fDrawingMgr.abandoned()) { return NULL; } |
58 | 60 |
59 | 61 |
60 //////////////////////////////////////////////////////////////////////////////// | 62 //////////////////////////////////////////////////////////////////////////////// |
61 | 63 |
62 void GrContext::DrawingMgr::init(GrContext* context) { | 64 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)); |
70 } | 72 } |
71 | 73 |
72 GrContext::DrawingMgr::~DrawingMgr() { | 74 GrContext::DrawingMgr::~DrawingMgr() { |
73 SkSafeUnref(fDrawTarget); | 75 SkSafeUnref(fDrawTarget); |
74 for (int i = 0; i < kNumPixelGeometries; ++i) { | 76 SkSafeUnref(fDrawContext); |
75 SkSafeUnref(fDrawContext[i][0]); | |
76 SkSafeUnref(fDrawContext[i][1]); | |
77 } | |
78 } | 77 } |
79 | 78 |
80 void GrContext::DrawingMgr::abandon() { | 79 void GrContext::DrawingMgr::abandon() { |
81 SkSafeSetNull(fDrawTarget); | 80 SkSafeSetNull(fDrawTarget); |
82 for (int i = 0; i < kNumPixelGeometries; ++i) { | 81 SkSafeSetNull(fDrawContext->fDrawTarget); |
83 for (int j = 0; j < kNumDFTOptions; ++j) { | 82 SkSafeSetNull(fDrawContext); |
84 if (fDrawContext[i][j]) { | |
85 SkSafeSetNull(fDrawContext[i][j]->fDrawTarget); | |
86 SkSafeSetNull(fDrawContext[i][j]); | |
87 } | |
88 } | |
89 } | |
90 } | 83 } |
91 | 84 |
92 void GrContext::DrawingMgr::purgeResources() { | 85 void GrContext::DrawingMgr::purgeResources() { |
93 if (fDrawTarget) { | 86 if (fDrawTarget) { |
94 fDrawTarget->purgeResources(); | 87 fDrawTarget->purgeResources(); |
95 } | 88 } |
96 } | 89 } |
97 | 90 |
98 void GrContext::DrawingMgr::reset() { | 91 void GrContext::DrawingMgr::reset() { |
99 if (fDrawTarget) { | 92 if (fDrawTarget) { |
100 fDrawTarget->reset(); | 93 fDrawTarget->reset(); |
101 } | 94 } |
102 } | 95 } |
103 | 96 |
104 void GrContext::DrawingMgr::flush() { | 97 void GrContext::DrawingMgr::flush() { |
105 if (fDrawTarget) { | 98 if (fDrawTarget) { |
106 fDrawTarget->flush(); | 99 fDrawTarget->flush(); |
107 } | 100 } |
108 } | 101 } |
109 | 102 |
110 GrDrawContext* GrContext::DrawingMgr::drawContext(const SkDeviceProperties* devP
rops, bool useDFT) { | 103 GrDrawContext* GrContext::DrawingMgr::drawContext() { |
111 if (this->abandoned()) { | 104 if (this->abandoned()) { |
112 return NULL; | 105 return NULL; |
113 } | 106 } |
114 | 107 return fDrawContext; |
115 const SkDeviceProperties defProps; | |
116 if (!devProps) { | |
117 devProps = &defProps; | |
118 } | |
119 | |
120 SkASSERT(devProps->pixelGeometry() < kNumPixelGeometries); | |
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]; | |
133 } | 108 } |
134 | 109 |
135 //////////////////////////////////////////////////////////////////////////////// | 110 //////////////////////////////////////////////////////////////////////////////// |
136 | 111 |
137 | 112 |
138 GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext)
{ | 113 GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext)
{ |
139 GrContextOptions defaultOptions; | 114 GrContextOptions defaultOptions; |
140 return Create(backend, backendContext, defaultOptions); | 115 return Create(backend, backendContext, defaultOptions); |
141 } | 116 } |
142 | 117 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 | 239 |
265 void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes)
const { | 240 void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes)
const { |
266 if (resourceCount) { | 241 if (resourceCount) { |
267 *resourceCount = fResourceCache->getBudgetedResourceCount(); | 242 *resourceCount = fResourceCache->getBudgetedResourceCount(); |
268 } | 243 } |
269 if (resourceBytes) { | 244 if (resourceBytes) { |
270 *resourceBytes = fResourceCache->getBudgetedResourceBytes(); | 245 *resourceBytes = fResourceCache->getBudgetedResourceBytes(); |
271 } | 246 } |
272 } | 247 } |
273 | 248 |
| 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 |
274 //////////////////////////////////////////////////////////////////////////////// | 264 //////////////////////////////////////////////////////////////////////////////// |
275 | 265 |
276 void GrContext::OverBudgetCB(void* data) { | 266 void GrContext::OverBudgetCB(void* data) { |
277 SkASSERT(data); | 267 SkASSERT(data); |
278 | 268 |
279 GrContext* context = reinterpret_cast<GrContext*>(data); | 269 GrContext* context = reinterpret_cast<GrContext*>(data); |
280 | 270 |
281 // Flush the InOrderDrawBuffer to possibly free up some textures | 271 // Flush the InOrderDrawBuffer to possibly free up some textures |
282 context->fFlushToReduceCacheSize = true; | 272 context->fFlushToReduceCacheSize = true; |
283 } | 273 } |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
755 ////////////////////////////////////////////////////////////////////////////// | 745 ////////////////////////////////////////////////////////////////////////////// |
756 | 746 |
757 void GrContext::addGpuTraceMarker(const GrGpuTraceMarker* marker) { | 747 void GrContext::addGpuTraceMarker(const GrGpuTraceMarker* marker) { |
758 fGpu->addGpuTraceMarker(marker); | 748 fGpu->addGpuTraceMarker(marker); |
759 } | 749 } |
760 | 750 |
761 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { | 751 void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { |
762 fGpu->removeGpuTraceMarker(marker); | 752 fGpu->removeGpuTraceMarker(marker); |
763 } | 753 } |
764 | 754 |
OLD | NEW |