OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 GrOptDrawState_DEFINED | 8 #ifndef GrOptDrawState_DEFINED |
9 #define GrOptDrawState_DEFINED | 9 #define GrOptDrawState_DEFINED |
10 | 10 |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 /////////////////////////////////////////////////////////////////////////// | 169 /////////////////////////////////////////////////////////////////////////// |
170 /// @name ScissorState | 170 /// @name ScissorState |
171 //// | 171 //// |
172 | 172 |
173 const ScissorState& getScissorState() const { return fScissorState; } | 173 const ScissorState& getScissorState() const { return fScissorState; } |
174 | 174 |
175 /// @} | 175 /// @} |
176 | 176 |
177 | 177 |
178 /////////////////////////////////////////////////////////////////////////// | 178 /////////////////////////////////////////////////////////////////////////// |
179 /// @name State Flags | 179 /// @name Boolean Queries |
180 //// | 180 //// |
181 | 181 |
182 bool isDitherState() const { return 0 != (fFlagBits & kDither_StateBit); } | 182 bool isDitherState() const { return SkToBool(fFlags & kDither_Flag); } |
183 bool isHWAntialiasState() const { return 0 != (fFlagBits & kHWAntialias_Stat
eBit); } | 183 bool isHWAntialiasState() const { return SkToBool(fFlags & kHWAA_Flag); } |
184 bool isColorWriteDisabled() const { return 0 != (fFlagBits & kNoColorWrites_
StateBit); } | 184 bool isColorWriteDisabled() const { return SkToBool(fFlags & kDisableColorWr
ite_Flag); } |
185 bool isCoverageDrawing() const { return 0 != (fFlagBits & kCoverageDrawing_S
tateBit); } | |
186 | 185 |
187 /// @} | 186 /// @} |
188 | 187 |
189 /////////////////////////////////////////////////////////////////////////// | |
190 /// @name Face Culling | |
191 //// | |
192 | |
193 enum DrawFace { | |
194 kInvalid_DrawFace = -1, | |
195 | |
196 kBoth_DrawFace, | |
197 kCCW_DrawFace, | |
198 kCW_DrawFace, | |
199 }; | |
200 | |
201 /** | 188 /** |
202 * Gets whether the target is drawing clockwise, counterclockwise, | 189 * Gets whether the target is drawing clockwise, counterclockwise, |
203 * or both faces. | 190 * or both faces. |
204 * @return the current draw face(s). | 191 * @return the current draw face(s). |
205 */ | 192 */ |
206 DrawFace getDrawFace() const { return fDrawFace; } | 193 GrDrawState::DrawFace getDrawFace() const { return fDrawFace; } |
207 | 194 |
208 /// @} | 195 /// @} |
209 | 196 |
210 /////////////////////////////////////////////////////////////////////////// | 197 /////////////////////////////////////////////////////////////////////////// |
211 | 198 |
212 | 199 |
213 const GrProgramDesc& programDesc() const { return fDesc; } | 200 const GrProgramDesc& programDesc() const { return fDesc; } |
214 | 201 |
215 private: | 202 private: |
216 // This is lifted from GrDrawState. This should be revised and made specific
to this class/ | |
217 enum StateBits { | |
218 /** | |
219 * Perform dithering. TODO: Re-evaluate whether we need this bit | |
220 */ | |
221 kDither_StateBit = 0x01, | |
222 /** | |
223 * Perform HW anti-aliasing. This means either HW FSAA, if supported by
the render target, | |
224 * or smooth-line rendering if a line primitive is drawn and line smooth
ing is supported by | |
225 * the 3D API. | |
226 */ | |
227 kHWAntialias_StateBit = 0x02, | |
228 /** | |
229 * Draws will respect the clip, otherwise the clip is ignored. | |
230 */ | |
231 kClip_StateBit = 0x04, | |
232 /** | |
233 * Disables writing to the color buffer. Useful when performing stencil | |
234 * operations. | |
235 */ | |
236 kNoColorWrites_StateBit = 0x08, | |
237 | |
238 /** | |
239 * Usually coverage is applied after color blending. The color is blende
d using the coeffs | |
240 * specified by setBlendFunc(). The blended color is then combined with
dst using coeffs | |
241 * of src_coverage, 1-src_coverage. Sometimes we are explicitly drawing
a coverage mask. In | |
242 * this case there is no distinction between coverage and color and the
caller needs direct | |
243 * control over the blend coeffs. When set, there will be a single blend
step controlled by | |
244 * setBlendFunc() which will use coverage*color as the src color. | |
245 */ | |
246 kCoverageDrawing_StateBit = 0x10 | |
247 }; | |
248 | |
249 /** | |
250 * Optimizations for blending / coverage to that can be applied based on the
current state. | |
251 */ | |
252 enum BlendOptFlags { | |
253 /** | |
254 * No optimization | |
255 */ | |
256 kNone_BlendOpt = 0, | |
257 /** | |
258 * Don't draw at all | |
259 */ | |
260 kSkipDraw_BlendOptFlag = 0x1, | |
261 /** | |
262 * The coverage value does not have to be computed separately from alpha
, the the output | |
263 * color can be the modulation of the two. | |
264 */ | |
265 kCoverageAsAlpha_BlendOptFlag = 0x2, | |
266 /** | |
267 * Instead of emitting a src color, emit coverage in the alpha channel a
nd r,g,b are | |
268 * "don't cares". | |
269 */ | |
270 kEmitCoverage_BlendOptFlag = 0x4, | |
271 /** | |
272 * Emit transparent black instead of the src color, no need to compute c
overage. | |
273 */ | |
274 kEmitTransBlack_BlendOptFlag = 0x8, | |
275 }; | |
276 GR_DECL_BITFIELD_OPS_FRIENDS(BlendOptFlags); | |
277 | |
278 /** | 203 /** |
279 * Constructs and optimized drawState out of a GrRODrawState. | 204 * Constructs and optimized drawState out of a GrRODrawState. |
280 */ | 205 */ |
281 GrOptDrawState(const GrDrawState& drawState, BlendOptFlags blendOptFlags, | 206 GrOptDrawState(const GrDrawState& drawState, GrDrawState::BlendOpt, |
282 GrBlendCoeff optSrcCoeff, GrBlendCoeff optDstCoeff, | 207 GrBlendCoeff optSrcCoeff, GrBlendCoeff optDstCoeff, |
283 GrGpu*, const ScissorState&, const GrDeviceCoordTexture* dstC
opy, | 208 GrGpu*, const ScissorState&, const GrDeviceCoordTexture* dstC
opy, |
284 GrGpu::DrawType); | 209 GrGpu::DrawType); |
285 | 210 |
286 /** | 211 /** |
287 * Loops through all the color stage effects to check if the stage will igno
re color input or | 212 * Loops through all the color stage effects to check if the stage will igno
re color input or |
288 * always output a constant color. In the ignore color input case we can ign
ore all previous | 213 * always output a constant color. In the ignore color input case we can ign
ore all previous |
289 * stages. In the constant color case, we can ignore all previous stages and | 214 * stages. In the constant color case, we can ignore all previous stages and |
290 * the current one and set the state color to the constant color. | 215 * the current one and set the state color to the constant color. |
291 */ | 216 */ |
292 void computeEffectiveColorStages(const GrDrawState& ds, GrProgramDesc::DescI
nfo*, | 217 void computeEffectiveColorStages(const GrDrawState& ds, GrProgramDesc::DescI
nfo*, |
293 int* firstColorStageIdx, uint8_t* fixFuncti
onVAToRemove); | 218 int* firstColorStageIdx, uint8_t* fixFuncti
onVAToRemove); |
294 | 219 |
295 /** | 220 /** |
296 * Loops through all the coverage stage effects to check if the stage will i
gnore color input. | 221 * Loops through all the coverage stage effects to check if the stage will i
gnore color input. |
297 * If a coverage stage will ignore input, then we can ignore all coverage st
ages before it. We | 222 * If a coverage stage will ignore input, then we can ignore all coverage st
ages before it. We |
298 * loop to determine the first effective coverage stage. | 223 * loop to determine the first effective coverage stage. |
299 */ | 224 */ |
300 void computeEffectiveCoverageStages(const GrDrawState& ds, GrProgramDesc::De
scInfo* descInfo, | 225 void computeEffectiveCoverageStages(const GrDrawState& ds, GrProgramDesc::De
scInfo* descInfo, |
301 int* firstCoverageStageIdx); | 226 int* firstCoverageStageIdx); |
302 | 227 |
303 /** | 228 /** |
304 * This function takes in a flag and removes the corresponding fixed functio
n vertex attributes. | 229 * This function takes in a flag and removes the corresponding fixed functio
n vertex attributes. |
305 * The flags are in the same order as GrVertexAttribBinding array. If bit i
of removeVAFlags is | 230 * The flags are in the same order as GrVertexAttribBinding array. If bit i
of removeVAFlags is |
306 * set, then vertex attributes with binding (GrVertexAttribute)i will be rem
oved. | 231 * set, then vertex attributes with binding (GrVertexAttribute)i will be rem
oved. |
307 */ | 232 */ |
308 void removeFixedFunctionVertexAttribs(uint8_t removeVAFlags, GrProgramDesc::
DescInfo*); | 233 void removeFixedFunctionVertexAttribs(uint8_t removeVAFlags, GrProgramDesc::
DescInfo*); |
309 | 234 |
310 /** | 235 /** |
311 * Alter the OptDrawState (adjusting stages, vertex attribs, flags, etc.) ba
sed on the | 236 * Alter the program desc and inputs (attribs and processors) based on the b
lend optimization. |
312 * BlendOptFlags. | |
313 */ | 237 */ |
314 void adjustFromBlendOpts(const GrDrawState& ds, GrProgramDesc::DescInfo*, | 238 void adjustProgramForBlendOpt(const GrDrawState& ds, GrDrawState::BlendOpt, |
315 int* firstColorStageIdx, int* firstCoverageStageIdx
, | 239 GrProgramDesc::DescInfo*, |
316 uint8_t* fixedFunctionVAToRemove); | 240 int* firstColorStageIdx, int* firstCoverageSta
geIdx, |
| 241 uint8_t* fixedFunctionVAToRemove); |
317 | 242 |
318 /** | 243 /** |
319 * Loop over the effect stages to determine various info like what data they
will read and what | 244 * Loop over the effect stages to determine various info like what data they
will read and what |
320 * shaders they require. | 245 * shaders they require. |
321 */ | 246 */ |
322 void getStageStats(const GrDrawState& ds, int firstColorStageIdx, int firstC
overageStageIdx, | 247 void getStageStats(const GrDrawState& ds, int firstColorStageIdx, int firstC
overageStageIdx, |
323 GrProgramDesc::DescInfo*); | 248 GrProgramDesc::DescInfo*); |
324 | 249 |
325 /** | 250 /** |
326 * Calculates the primary and secondary output types of the shader. For cert
ain output types | 251 * Calculates the primary and secondary output types of the shader. For cert
ain output types |
327 * the function may adjust the blend coefficients. After this function is ca
lled the src and dst | 252 * the function may adjust the blend coefficients. After this function is ca
lled the src and dst |
328 * blend coeffs will represent those used by backend API. | 253 * blend coeffs will represent those used by backend API. |
329 */ | 254 */ |
330 void setOutputStateInfo(const GrDrawState& ds, const GrDrawTargetCaps&, | 255 void setOutputStateInfo(const GrDrawState& ds, GrDrawState::BlendOpt, const
GrDrawTargetCaps&, |
331 GrProgramDesc::DescInfo*); | 256 GrProgramDesc::DescInfo*); |
332 | 257 |
| 258 enum Flags { |
| 259 kDither_Flag = 0x1, |
| 260 kHWAA_Flag = 0x2, |
| 261 kDisableColorWrite_Flag = 0x4, |
| 262 }; |
| 263 |
333 typedef GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> RenderTarget; | 264 typedef GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> RenderTarget; |
334 typedef SkSTArray<8, GrPendingFragmentStage> FragmentStageArray; | 265 typedef SkSTArray<8, GrPendingFragmentStage> FragmentStageArray; |
335 typedef GrPendingProgramElement<const GrGeometryProcessor> ProgramGeometryPr
ocessor; | 266 typedef GrPendingProgramElement<const GrGeometryProcessor> ProgramGeometryPr
ocessor; |
336 RenderTarget fRenderTarget; | 267 RenderTarget fRenderTarget; |
337 ScissorState fScissorState; | 268 ScissorState fScissorState; |
338 GrColor fColor; | 269 GrColor fColor; |
339 SkMatrix fViewMatrix; | 270 SkMatrix fViewMatrix; |
340 GrColor fBlendConstant; | 271 GrColor fBlendConstant; |
341 uint32_t fFlagBits; | |
342 const GrVertexAttrib* fVAPtr; | 272 const GrVertexAttrib* fVAPtr; |
343 int fVACount; | 273 int fVACount; |
344 size_t fVAStride; | 274 size_t fVAStride; |
345 GrStencilSettings fStencilSettings; | 275 GrStencilSettings fStencilSettings; |
346 uint8_t fCoverage; | 276 uint8_t fCoverage; |
347 DrawFace fDrawFace; | 277 GrDrawState::DrawFace fDrawFace; |
348 GrBlendCoeff fSrcBlend; | 278 GrBlendCoeff fSrcBlend; |
349 GrBlendCoeff fDstBlend; | 279 GrBlendCoeff fDstBlend; |
350 | 280 uint32_t fFlags; |
351 ProgramGeometryProcessor fGeometryProcessor; | 281 ProgramGeometryProcessor fGeometryProcessor; |
352 FragmentStageArray fFragmentStages; | 282 FragmentStageArray fFragmentStages; |
353 | 283 |
354 // This function is equivalent to the offset into fFragmentStages where cove
rage stages begin. | 284 // This function is equivalent to the offset into fFragmentStages where cove
rage stages begin. |
355 int fNumColorStages; | 285 int fNumColorStages; |
356 | 286 |
357 SkAutoSTArray<4, GrVertexAttrib> fOptVA; | 287 SkAutoSTArray<4, GrVertexAttrib> fOptVA; |
358 | 288 |
359 BlendOptFlags fBlendOptFlags; | |
360 | |
361 GrProgramDesc fDesc; | 289 GrProgramDesc fDesc; |
362 | 290 |
363 typedef SkRefCnt INHERITED; | 291 typedef SkRefCnt INHERITED; |
364 }; | 292 }; |
365 | 293 |
366 GR_MAKE_BITFIELD_OPS(GrOptDrawState::BlendOptFlags); | |
367 | |
368 #endif | 294 #endif |
369 | |
OLD | NEW |