OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrPathRenderer_DEFINED | 8 #ifndef GrPathRenderer_DEFINED |
9 #define GrPathRenderer_DEFINED | 9 #define GrPathRenderer_DEFINED |
10 | 10 |
11 #include "GrDrawTarget.h" | 11 #include "GrDrawTarget.h" |
12 #include "GrStencil.h" | 12 #include "GrStencil.h" |
13 #include "GrStrokeInfo.h" | 13 #include "GrStyle.h" |
14 | 14 |
15 #include "SkDrawProcs.h" | 15 #include "SkDrawProcs.h" |
16 #include "SkTArray.h" | 16 #include "SkTArray.h" |
17 | 17 |
18 class SkPath; | 18 class SkPath; |
19 | |
20 struct GrPoint; | 19 struct GrPoint; |
21 | 20 |
22 /** | 21 /** |
23 * Base class for drawing paths into a GrDrawTarget. | 22 * Base class for drawing paths into a GrDrawTarget. |
24 * | 23 * |
25 * Derived classes can use stages GrPaint::kTotalStages through GrPipelineBuild
er::kNumStages-1. | 24 * Derived classes can use stages GrPaint::kTotalStages through GrPipelineBuild
er::kNumStages-1. |
26 * The stages before GrPaint::kTotalStages are reserved for setting up the draw
(i.e., textures and | 25 * The stages before GrPaint::kTotalStages are reserved for setting up the draw
(i.e., textures and |
27 * filter masks). | 26 * filter masks). |
28 */ | 27 */ |
29 class SK_API GrPathRenderer : public SkRefCnt { | 28 class SK_API GrPathRenderer : public SkRefCnt { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 SkASSERT(!path.isInverseFillType()); | 64 SkASSERT(!path.isInverseFillType()); |
66 return this->onGetStencilSupport(path); | 65 return this->onGetStencilSupport(path); |
67 } | 66 } |
68 | 67 |
69 /** Args to canDrawPath() | 68 /** Args to canDrawPath() |
70 * | 69 * |
71 * fShaderCaps The shader caps | 70 * fShaderCaps The shader caps |
72 * fPipelineBuilder The pipelineBuilder | 71 * fPipelineBuilder The pipelineBuilder |
73 * fViewMatrix The viewMatrix | 72 * fViewMatrix The viewMatrix |
74 * fPath The path to draw | 73 * fPath The path to draw |
75 * fStroke The stroke information (width, join, cap) | 74 * fStyle The styling info (path effect, stroking info) |
76 * fAntiAlias True if anti-aliasing is required. | 75 * fAntiAlias True if anti-aliasing is required. |
77 */ | 76 */ |
78 struct CanDrawPathArgs { | 77 struct CanDrawPathArgs { |
79 const GrShaderCaps* fShaderCaps; | 78 const GrShaderCaps* fShaderCaps; |
80 const SkMatrix* fViewMatrix; | 79 const SkMatrix* fViewMatrix; |
81 const SkPath* fPath; | 80 const SkPath* fPath; |
82 const GrStrokeInfo* fStroke; | 81 const GrStyle* fStyle; |
83 bool fAntiAlias; | 82 bool fAntiAlias; |
84 | 83 |
85 // These next two are only used by GrStencilAndCoverPathRenderer | 84 // These next two are only used by GrStencilAndCoverPathRenderer |
86 bool fIsStencilDisabled; | 85 bool fIsStencilDisabled; |
87 bool fIsStencilBufferMSAA; | 86 bool fIsStencilBufferMSAA; |
88 | 87 |
89 void validate() const { | 88 void validate() const { |
90 SkASSERT(fShaderCaps); | 89 SkASSERT(fShaderCaps); |
91 SkASSERT(fViewMatrix); | 90 SkASSERT(fViewMatrix); |
92 SkASSERT(fPath); | 91 SkASSERT(fPath); |
93 SkASSERT(fStroke); | 92 SkASSERT(fStyle); |
94 SkASSERT(!fPath->isEmpty()); | 93 SkASSERT(!fPath->isEmpty()); |
95 } | 94 } |
96 }; | 95 }; |
97 | 96 |
98 /** | 97 /** |
99 * Returns true if this path renderer is able to render the path. Returning
false allows the | 98 * Returns true if this path renderer is able to render the path. Returning
false allows the |
100 * caller to fallback to another path renderer This function is called when
searching for a path | 99 * caller to fallback to another path renderer This function is called when
searching for a path |
101 * renderer capable of rendering a path. | 100 * renderer capable of rendering a path. |
102 * | 101 * |
103 * @return true if the path can be drawn by this object, false otherwise. | 102 * @return true if the path can be drawn by this object, false otherwise. |
104 */ | 103 */ |
105 bool canDrawPath(const CanDrawPathArgs& args) const { | 104 bool canDrawPath(const CanDrawPathArgs& args) const { |
106 SkDEBUGCODE(args.validate();) | 105 SkDEBUGCODE(args.validate();) |
107 return this->onCanDrawPath(args); | 106 return this->onCanDrawPath(args); |
108 } | 107 } |
109 | 108 |
110 /** | 109 /** |
111 * Args to drawPath() | 110 * Args to drawPath() |
112 * | 111 * |
113 * fTarget The target that the path will be rendered to | 112 * fTarget The target that the path will be rendered to |
114 * fResourceProvider The resource provider for creating gpu resources t
o render the path | 113 * fResourceProvider The resource provider for creating gpu resources t
o render the path |
115 * fPipelineBuilder The pipelineBuilder | 114 * fPipelineBuilder The pipelineBuilder |
116 * fColor Color to render with | 115 * fColor Color to render with |
117 * fViewMatrix The viewMatrix | 116 * fViewMatrix The viewMatrix |
118 * fPath the path to draw. | 117 * fPath the path to draw. |
119 * fStroke the stroke information (width, join, cap) | 118 * fStyle the style information (path effect, stroke info) |
120 * fAntiAlias true if anti-aliasing is required. | 119 * fAntiAlias true if anti-aliasing is required. |
121 * fGammaCorrect true if gamma-correct rendering is to be used. | 120 * fGammaCorrect true if gamma-correct rendering is to be used. |
122 */ | 121 */ |
123 struct DrawPathArgs { | 122 struct DrawPathArgs { |
124 GrDrawTarget* fTarget; | 123 GrDrawTarget* fTarget; |
125 GrResourceProvider* fResourceProvider; | 124 GrResourceProvider* fResourceProvider; |
126 GrPipelineBuilder* fPipelineBuilder; | 125 GrPipelineBuilder* fPipelineBuilder; |
127 GrColor fColor; | 126 GrColor fColor; |
128 const SkMatrix* fViewMatrix; | 127 const SkMatrix* fViewMatrix; |
129 const SkPath* fPath; | 128 const SkPath* fPath; |
130 const GrStrokeInfo* fStroke; | 129 const GrStyle* fStyle; |
131 bool fAntiAlias; | 130 bool fAntiAlias; |
132 bool fGammaCorrect; | 131 bool fGammaCorrect; |
133 | 132 |
134 void validate() const { | 133 void validate() const { |
135 SkASSERT(fTarget); | 134 SkASSERT(fTarget); |
136 SkASSERT(fResourceProvider); | 135 SkASSERT(fResourceProvider); |
137 SkASSERT(fPipelineBuilder); | 136 SkASSERT(fPipelineBuilder); |
138 SkASSERT(fViewMatrix); | 137 SkASSERT(fViewMatrix); |
139 SkASSERT(fPath); | 138 SkASSERT(fPath); |
140 SkASSERT(fStroke); | 139 SkASSERT(fStyle); |
141 SkASSERT(!fPath->isEmpty()); | 140 SkASSERT(!fPath->isEmpty()); |
142 } | 141 } |
143 }; | 142 }; |
144 | 143 |
145 /** | 144 /** |
146 * Draws the path into the draw target. If getStencilSupport() would return
kNoRestriction then | 145 * Draws the path into the draw target. If getStencilSupport() would return
kNoRestriction then |
147 * the subclass must respect the stencil settings of the GrPipelineBuilder. | 146 * the subclass must respect the stencil settings of the GrPipelineBuilder. |
148 */ | 147 */ |
149 bool drawPath(const DrawPathArgs& args) { | 148 bool drawPath(const DrawPathArgs& args) { |
150 SkDEBUGCODE(args.validate();) | 149 SkDEBUGCODE(args.validate();) |
151 #ifdef SK_DEBUG | 150 #ifdef SK_DEBUG |
152 CanDrawPathArgs canArgs; | 151 CanDrawPathArgs canArgs; |
153 canArgs.fShaderCaps = args.fTarget->caps()->shaderCaps(); | 152 canArgs.fShaderCaps = args.fTarget->caps()->shaderCaps(); |
154 canArgs.fViewMatrix = args.fViewMatrix; | 153 canArgs.fViewMatrix = args.fViewMatrix; |
155 canArgs.fPath = args.fPath; | 154 canArgs.fPath = args.fPath; |
156 canArgs.fStroke = args.fStroke; | 155 canArgs.fStyle = args.fStyle; |
157 canArgs.fAntiAlias = args.fAntiAlias; | 156 canArgs.fAntiAlias = args.fAntiAlias; |
158 | 157 |
159 canArgs.fIsStencilDisabled = args.fPipelineBuilder->getStencil().isDisab
led(); | 158 canArgs.fIsStencilDisabled = args.fPipelineBuilder->getStencil().isDisab
led(); |
160 canArgs.fIsStencilBufferMSAA = | 159 canArgs.fIsStencilBufferMSAA = |
161 args.fPipelineBuilder->getRenderTarget()->isStencilBuf
ferMultisampled(); | 160 args.fPipelineBuilder->getRenderTarget()->isStencilBuf
ferMultisampled(); |
162 SkASSERT(this->canDrawPath(canArgs)); | 161 SkASSERT(this->canDrawPath(canArgs)); |
163 if (!args.fPipelineBuilder->getStencil().isDisabled()) { | 162 if (!args.fPipelineBuilder->getStencil().isDisabled()) { |
164 SkASSERT(kNoRestriction_StencilSupport == this->getStencilSupport(*a
rgs.fPath)); | 163 SkASSERT(kNoRestriction_StencilSupport == this->getStencilSupport(*a
rgs.fPath)); |
165 SkASSERT(!args.fStroke->isDashed()); | 164 SkASSERT(args.fStyle->isSimpleFill()); |
166 SkASSERT(args.fStroke->isFillStyle()); | |
167 } | 165 } |
168 #endif | 166 #endif |
169 return this->onDrawPath(args); | 167 return this->onDrawPath(args); |
170 } | 168 } |
171 | 169 |
172 /* Args to stencilPath(). | 170 /* Args to stencilPath(). |
173 * | 171 * |
174 * fTarget The target that the path will be rendered to. | 172 * fTarget The target that the path will be rendered to. |
175 * fResourceProvider The resource provider for creating gpu resources t
o render the path | 173 * fResourceProvider The resource provider for creating gpu resources t
o render the path |
176 * fPipelineBuilder The pipeline builder. | 174 * fPipelineBuilder The pipeline builder. |
(...skipping 13 matching lines...) Expand all Loading... |
190 SkASSERT(fPipelineBuilder); | 188 SkASSERT(fPipelineBuilder); |
191 SkASSERT(fViewMatrix); | 189 SkASSERT(fViewMatrix); |
192 SkASSERT(fPath); | 190 SkASSERT(fPath); |
193 SkASSERT(!fPath->isEmpty()); | 191 SkASSERT(!fPath->isEmpty()); |
194 } | 192 } |
195 }; | 193 }; |
196 | 194 |
197 /** | 195 /** |
198 * Draws the path to the stencil buffer. Assume the writable stencil bits ar
e already | 196 * Draws the path to the stencil buffer. Assume the writable stencil bits ar
e already |
199 * initialized to zero. The pixels inside the path will have non-zero stenci
l values afterwards. | 197 * initialized to zero. The pixels inside the path will have non-zero stenci
l values afterwards. |
200 * | |
201 */ | 198 */ |
202 void stencilPath(const StencilPathArgs& args) { | 199 void stencilPath(const StencilPathArgs& args) { |
203 SkDEBUGCODE(args.validate();) | 200 SkDEBUGCODE(args.validate();) |
204 SkASSERT(kNoSupport_StencilSupport != this->getStencilSupport(*args.fPat
h)); | 201 SkASSERT(kNoSupport_StencilSupport != this->getStencilSupport(*args.fPat
h)); |
205 | |
206 this->onStencilPath(args); | 202 this->onStencilPath(args); |
207 } | 203 } |
208 | 204 |
209 // Helper for determining if we can treat a thin stroke as a hairline w/ cov
erage. | 205 // Helper for determining if we can treat a thin stroke as a hairline w/ cov
erage. |
210 // If we can, we draw lots faster (raster device does this same test). | 206 // If we can, we draw lots faster (raster device does this same test). |
211 static bool IsStrokeHairlineOrEquivalent(const GrStrokeInfo& stroke, const S
kMatrix& matrix, | 207 static bool IsStrokeHairlineOrEquivalent(const GrStyle& style, const SkMatri
x& matrix, |
212 SkScalar* outCoverage) { | 208 SkScalar* outCoverage) { |
213 if (stroke.isDashed()) { | 209 if (style.pathEffect()) { |
214 return false; | 210 return false; |
215 } | 211 } |
| 212 const SkStrokeRec& stroke = style.strokeRec(); |
216 if (stroke.isHairlineStyle()) { | 213 if (stroke.isHairlineStyle()) { |
217 if (outCoverage) { | 214 if (outCoverage) { |
218 *outCoverage = SK_Scalar1; | 215 *outCoverage = SK_Scalar1; |
219 } | 216 } |
220 return true; | 217 return true; |
221 } | 218 } |
222 return stroke.getStyle() == SkStrokeRec::kStroke_Style && | 219 return stroke.getStyle() == SkStrokeRec::kStroke_Style && |
223 SkDrawTreatAAStrokeAsHairline(stroke.getWidth(), matrix, outCoverage
); | 220 SkDrawTreatAAStrokeAsHairline(stroke.getWidth(), matrix, outCoverage
); |
224 } | 221 } |
225 | 222 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 0xffff); | 269 0xffff); |
273 args.fPipelineBuilder->setStencil(kIncrementStencil); | 270 args.fPipelineBuilder->setStencil(kIncrementStencil); |
274 args.fPipelineBuilder->setDisableColorXPFactory(); | 271 args.fPipelineBuilder->setDisableColorXPFactory(); |
275 DrawPathArgs drawArgs; | 272 DrawPathArgs drawArgs; |
276 drawArgs.fTarget = args.fTarget; | 273 drawArgs.fTarget = args.fTarget; |
277 drawArgs.fResourceProvider = args.fResourceProvider; | 274 drawArgs.fResourceProvider = args.fResourceProvider; |
278 drawArgs.fPipelineBuilder = args.fPipelineBuilder; | 275 drawArgs.fPipelineBuilder = args.fPipelineBuilder; |
279 drawArgs.fColor = 0xFFFFFFFF; | 276 drawArgs.fColor = 0xFFFFFFFF; |
280 drawArgs.fViewMatrix = args.fViewMatrix; | 277 drawArgs.fViewMatrix = args.fViewMatrix; |
281 drawArgs.fPath = args.fPath; | 278 drawArgs.fPath = args.fPath; |
282 drawArgs.fStroke = &GrStrokeInfo::FillInfo(); | 279 drawArgs.fStyle = &GrStyle::SimpleFill(); |
283 drawArgs.fAntiAlias = false; | 280 drawArgs.fAntiAlias = false; |
284 drawArgs.fGammaCorrect = false; | 281 drawArgs.fGammaCorrect = false; |
285 this->drawPath(drawArgs); | 282 this->drawPath(drawArgs); |
286 } | 283 } |
287 | 284 |
288 | |
289 typedef SkRefCnt INHERITED; | 285 typedef SkRefCnt INHERITED; |
290 }; | 286 }; |
291 | 287 |
292 #endif | 288 #endif |
OLD | NEW |