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 GrRODrawState_DEFINED | 8 #ifndef GrRODrawState_DEFINED |
9 #define GrRODrawState_DEFINED | 9 #define GrRODrawState_DEFINED |
10 | 10 |
11 #include "GrStencil.h" | 11 #include "GrStencil.h" |
12 #include "GrEffectStage.h" | 12 #include "GrEffectStage.h" |
13 #include "SkMatrix.h" | 13 #include "SkMatrix.h" |
14 | 14 |
15 class GrDrawState; | |
15 class GrDrawTargetCaps; | 16 class GrDrawTargetCaps; |
16 class GrPaint; | 17 class GrPaint; |
17 class GrRenderTarget; | 18 class GrRenderTarget; |
18 class GrTexture; | 19 class GrTexture; |
19 | 20 |
20 /** | 21 /** |
21 * Read-only base class for GrDrawState. This class contains all the necessary d ata to represent a | 22 * Read-only base class for GrDrawState. This class contains all the necessary d ata to represent a |
22 * canonical DrawState. All methods in the class are const, thus once created th e data in the class | 23 * canonical DrawState. All methods in the class are const, thus once created th e data in the class |
23 * cannot be changed. | 24 * cannot be changed. |
24 */ | 25 */ |
25 class GrRODrawState : public SkRefCnt { | 26 class GrRODrawState : public SkRefCnt { |
26 public: | 27 public: |
27 SK_DECLARE_INST_COUNT(GrRODrawState) | 28 SK_DECLARE_INST_COUNT(GrRODrawState) |
28 | 29 |
30 GrRODrawState() {} | |
31 | |
32 GrRODrawState& operator= (const GrRODrawState& that); | |
33 | |
29 /////////////////////////////////////////////////////////////////////////// | 34 /////////////////////////////////////////////////////////////////////////// |
30 /// @name Vertex Attributes | 35 /// @name Vertex Attributes |
31 //// | 36 //// |
32 | 37 |
33 enum { | 38 enum { |
34 kMaxVertexAttribCnt = kLast_GrVertexAttribBinding + 4, | 39 kMaxVertexAttribCnt = kLast_GrVertexAttribBinding + 4, |
35 }; | 40 }; |
36 | 41 |
37 const GrVertexAttrib* getVertexAttribs() const { return fVAPtr; } | 42 const GrVertexAttrib* getVertexAttribs() const { return fVAPtr; } |
38 int getVertexAttribCount() const { return fVACount; } | 43 int getVertexAttribCount() const { return fVACount; } |
39 | 44 |
40 size_t getVertexSize() const { return fVertexSize; } | 45 size_t getVertexSize() const { return fVertexSize; } |
bsalomon
2014/08/28 13:49:27
Have you rebased? I thought this was now stride...
egdaniel
2014/08/28 14:39:38
Woops thought I had rebased
| |
41 | 46 |
42 /** | 47 /** |
43 * Getters for index into getVertexAttribs() for particular bindings. -1 is returned if the | 48 * Getters for index into getVertexAttribs() for particular bindings. -1 is returned if the |
44 * binding does not appear in the current attribs. These bindings should app ear only once in | 49 * binding does not appear in the current attribs. These bindings should app ear only once in |
45 * the attrib array. | 50 * the attrib array. |
46 */ | 51 */ |
47 | 52 |
48 int positionAttributeIndex() const { | 53 int positionAttributeIndex() const { |
49 return fFixedFunctionVertexAttribIndices[kPosition_GrVertexAttribBinding ]; | 54 return fFixedFunctionVertexAttribIndices[kPosition_GrVertexAttribBinding ]; |
50 } | 55 } |
(...skipping 10 matching lines...) Expand all Loading... | |
61 bool hasLocalCoordAttribute() const { | 66 bool hasLocalCoordAttribute() const { |
62 return -1 != fFixedFunctionVertexAttribIndices[kLocalCoord_GrVertexAttri bBinding]; | 67 return -1 != fFixedFunctionVertexAttribIndices[kLocalCoord_GrVertexAttri bBinding]; |
63 } | 68 } |
64 bool hasColorVertexAttribute() const { | 69 bool hasColorVertexAttribute() const { |
65 return -1 != fFixedFunctionVertexAttribIndices[kColor_GrVertexAttribBind ing]; | 70 return -1 != fFixedFunctionVertexAttribIndices[kColor_GrVertexAttribBind ing]; |
66 } | 71 } |
67 bool hasCoverageVertexAttribute() const { | 72 bool hasCoverageVertexAttribute() const { |
68 return -1 != fFixedFunctionVertexAttribIndices[kCoverage_GrVertexAttribB inding]; | 73 return -1 != fFixedFunctionVertexAttribIndices[kCoverage_GrVertexAttribB inding]; |
69 } | 74 } |
70 | 75 |
76 const int* getFixedFunctionVertexAttribIndices() const { | |
bsalomon
2014/08/28 13:49:27
Does this need to be public? Comment about what it
egdaniel
2014/08/28 14:39:38
moved to protected
| |
77 return fFixedFunctionVertexAttribIndices; | |
78 } | |
79 | |
71 bool validateVertexAttribs() const; | 80 bool validateVertexAttribs() const; |
72 | 81 |
73 /// @} | 82 /// @} |
74 | 83 |
75 /** | 84 /** |
76 * Determines whether the output coverage is guaranteed to be one for all pi xels hit by a draw. | 85 * Determines whether the output coverage is guaranteed to be one for all pi xels hit by a draw. |
77 */ | 86 */ |
78 bool hasSolidCoverage() const; | 87 bool hasSolidCoverage() const; |
79 | 88 |
80 /// @} | 89 /// @} |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 *dstBlendCoeff = fDstBlend; | 155 *dstBlendCoeff = fDstBlend; |
147 } | 156 } |
148 | 157 |
149 /** | 158 /** |
150 * Retrieves the last value set by setBlendConstant() | 159 * Retrieves the last value set by setBlendConstant() |
151 * @return the blending constant value | 160 * @return the blending constant value |
152 */ | 161 */ |
153 GrColor getBlendConstant() const { return fBlendConstant; } | 162 GrColor getBlendConstant() const { return fBlendConstant; } |
154 | 163 |
155 /** | 164 /** |
165 * We don't use supplied vertex color attributes if our blend mode is EmitCo verage or | |
166 * EmitTransBlack | |
167 */ | |
168 bool canIgnoreColorAttribute() const; | |
169 | |
170 /** | |
156 * Determines whether multiplying the computed per-pixel color by the pixel' s fractional | 171 * Determines whether multiplying the computed per-pixel color by the pixel' s fractional |
157 * coverage before the blend will give the correct final destination color. In general it | 172 * coverage before the blend will give the correct final destination color. In general it |
158 * will not as coverage is applied after blending. | 173 * will not as coverage is applied after blending. |
159 */ | 174 */ |
160 bool canTweakAlphaForCoverage() const; | 175 bool canTweakAlphaForCoverage() const; |
161 | 176 |
162 /** | 177 /** |
163 * Optimizations for blending / coverage to that can be applied based on the current state. | 178 * Optimizations for blending / coverage to that can be applied based on the current state. |
164 */ | 179 */ |
165 enum BlendOptFlags { | 180 enum BlendOptFlags { |
(...skipping 20 matching lines...) Expand all Loading... | |
186 */ | 201 */ |
187 kEmitTransBlack_BlendOptFlag = 0x8, | 202 kEmitTransBlack_BlendOptFlag = 0x8, |
188 /** | 203 /** |
189 * Flag used to invalidate the cached BlendOptFlags, OptSrcCoeff, and Op tDstCoeff cached by | 204 * Flag used to invalidate the cached BlendOptFlags, OptSrcCoeff, and Op tDstCoeff cached by |
190 * the get BlendOpts function. | 205 * the get BlendOpts function. |
191 */ | 206 */ |
192 kInvalid_BlendOptFlag = 1 << 31, | 207 kInvalid_BlendOptFlag = 1 << 31, |
193 }; | 208 }; |
194 GR_DECL_BITFIELD_OPS_FRIENDS(BlendOptFlags); | 209 GR_DECL_BITFIELD_OPS_FRIENDS(BlendOptFlags); |
195 | 210 |
211 /** | |
212 * Determines what optimizations can be applied based on the blend. The coef ficients may have | |
213 * to be tweaked in order for the optimization to work. srcCoeff and dstCoef f are optional | |
214 * params that receive the tweaked coefficients. Normally the function looks at the current | |
215 * state to see if coverage is enabled. By setting forceCoverage the caller can speculatively | |
216 * determine the blend optimizations that would be used if there was partial pixel coverage. | |
217 * | |
218 * Subclasses of GrDrawTarget that actually draw (as opposed to those that j ust buffer for | |
219 * playback) must call this function and respect the flags that replace the output color. | |
220 * | |
221 * If the cached BlendOptFlags does not have the invalidate bit set, then ge tBlendOpts will | |
222 * simply returned the cached flags and coefficients. Otherwise it will calc ulate the values. | |
223 */ | |
224 BlendOptFlags getBlendOpts(bool forceCoverage = false, | |
bsalomon
2014/08/28 13:49:27
What was it that is keeping this public now? I kno
egdaniel
2014/08/28 14:39:38
Needed to stay public in this CL since the opt sta
| |
225 GrBlendCoeff* srcCoeff = NULL, | |
226 GrBlendCoeff* dstCoeff = NULL) const; | |
196 /// @} | 227 /// @} |
197 | 228 |
198 /////////////////////////////////////////////////////////////////////////// | 229 /////////////////////////////////////////////////////////////////////////// |
199 /// @name View Matrix | 230 /// @name View Matrix |
200 //// | 231 //// |
201 | 232 |
202 /** | 233 /** |
203 * Retrieves the current view matrix | 234 * Retrieves the current view matrix |
204 * @return the current view matrix. | 235 * @return the current view matrix. |
205 */ | 236 */ |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
288 * control over the blend coeffs. When set, there will be a single blend step controlled by | 319 * control over the blend coeffs. When set, there will be a single blend step controlled by |
289 * setBlendFunc() which will use coverage*color as the src color. | 320 * setBlendFunc() which will use coverage*color as the src color. |
290 */ | 321 */ |
291 kCoverageDrawing_StateBit = 0x10, | 322 kCoverageDrawing_StateBit = 0x10, |
292 | 323 |
293 // Users of the class may add additional bits to the vector | 324 // Users of the class may add additional bits to the vector |
294 kDummyStateBit, | 325 kDummyStateBit, |
295 kLastPublicStateBit = kDummyStateBit-1, | 326 kLastPublicStateBit = kDummyStateBit-1, |
296 }; | 327 }; |
297 | 328 |
329 uint32_t getFlagBits() const { return fFlagBits; } | |
330 | |
298 bool isStateFlagEnabled(uint32_t stateBit) const { return 0 != (stateBit & f FlagBits); } | 331 bool isStateFlagEnabled(uint32_t stateBit) const { return 0 != (stateBit & f FlagBits); } |
299 | 332 |
300 bool isDitherState() const { return 0 != (fFlagBits & kDither_StateBit); } | 333 bool isDitherState() const { return 0 != (fFlagBits & kDither_StateBit); } |
301 bool isHWAntialiasState() const { return 0 != (fFlagBits & kHWAntialias_Stat eBit); } | 334 bool isHWAntialiasState() const { return 0 != (fFlagBits & kHWAntialias_Stat eBit); } |
302 bool isClipState() const { return 0 != (fFlagBits & kClip_StateBit); } | 335 bool isClipState() const { return 0 != (fFlagBits & kClip_StateBit); } |
303 bool isColorWriteDisabled() const { return 0 != (fFlagBits & kNoColorWrites_ StateBit); } | 336 bool isColorWriteDisabled() const { return 0 != (fFlagBits & kNoColorWrites_ StateBit); } |
304 bool isCoverageDrawing() const { return 0 != (fFlagBits & kCoverageDrawing_S tateBit); } | 337 bool isCoverageDrawing() const { return 0 != (fFlagBits & kCoverageDrawing_S tateBit); } |
305 | 338 |
306 /// @} | 339 /// @} |
307 | 340 |
(...skipping 12 matching lines...) Expand all Loading... | |
320 /** | 353 /** |
321 * Gets whether the target is drawing clockwise, counterclockwise, | 354 * Gets whether the target is drawing clockwise, counterclockwise, |
322 * or both faces. | 355 * or both faces. |
323 * @return the current draw face(s). | 356 * @return the current draw face(s). |
324 */ | 357 */ |
325 DrawFace getDrawFace() const { return fDrawFace; } | 358 DrawFace getDrawFace() const { return fDrawFace; } |
326 | 359 |
327 /// @} | 360 /// @} |
328 | 361 |
329 /////////////////////////////////////////////////////////////////////////// | 362 /////////////////////////////////////////////////////////////////////////// |
363 /// @name Hints | |
364 /// Hints that when provided can enable optimizations. | |
365 //// | |
366 | |
367 enum Hints { kVertexColorsAreOpaque_Hint = 0x1, }; | |
368 | |
369 bool vertexColorsAreOpaque() const { return kVertexColorsAreOpaque_Hint & fH ints; } | |
370 | |
371 /// @} | |
372 | |
373 /////////////////////////////////////////////////////////////////////////// | |
330 | 374 |
331 /** Return type for CombineIfPossible. */ | 375 /** Return type for CombineIfPossible. */ |
332 enum CombinedState { | 376 enum CombinedState { |
333 /** The GrDrawStates cannot be combined. */ | 377 /** The GrDrawStates cannot be combined. */ |
334 kIncompatible_CombinedState, | 378 kIncompatible_CombinedState, |
335 /** Either draw state can be used in place of the other. */ | 379 /** Either draw state can be used in place of the other. */ |
336 kAOrB_CombinedState, | 380 kAOrB_CombinedState, |
337 /** Use the first draw state. */ | 381 /** Use the first draw state. */ |
338 kA_CombinedState, | 382 kA_CombinedState, |
339 /** Use the second draw state. */ | 383 /** Use the second draw state. */ |
340 kB_CombinedState, | 384 kB_CombinedState, |
341 }; | 385 }; |
342 | 386 |
343 GrRODrawState& operator= (const GrRODrawState& that); | 387 protected: |
388 explicit GrRODrawState(const GrRODrawState& drawState) : INHERITED() { | |
389 fRenderTarget.reset(SkSafeRef(drawState.fRenderTarget.get())); | |
390 } | |
344 | 391 |
345 protected: | |
346 bool isEqual(const GrRODrawState& that) const; | 392 bool isEqual(const GrRODrawState& that) const; |
347 | 393 |
348 // These fields are roughly sorted by decreasing likelihood of being differe nt in op== | 394 // These fields are roughly sorted by decreasing likelihood of being differe nt in op== |
349 SkAutoTUnref<GrRenderTarget> fRenderTarget; | 395 SkAutoTUnref<GrRenderTarget> fRenderTarget; |
350 GrColor fColor; | 396 GrColor fColor; |
351 SkMatrix fViewMatrix; | 397 SkMatrix fViewMatrix; |
352 GrColor fBlendConstant; | 398 GrColor fBlendConstant; |
353 uint32_t fFlagBits; | 399 uint32_t fFlagBits; |
354 const GrVertexAttrib* fVAPtr; | 400 const GrVertexAttrib* fVAPtr; |
355 int fVACount; | 401 int fVACount; |
356 size_t fVertexSize; | 402 size_t fVertexSize; |
357 GrStencilSettings fStencilSettings; | 403 GrStencilSettings fStencilSettings; |
358 uint8_t fCoverage; | 404 uint8_t fCoverage; |
359 DrawFace fDrawFace; | 405 DrawFace fDrawFace; |
360 GrBlendCoeff fSrcBlend; | 406 GrBlendCoeff fSrcBlend; |
361 GrBlendCoeff fDstBlend; | 407 GrBlendCoeff fDstBlend; |
362 | 408 |
363 typedef SkSTArray<4, GrEffectStage> EffectStageArray; | 409 typedef SkSTArray<4, GrEffectStage> EffectStageArray; |
364 EffectStageArray fColorStages; | 410 EffectStageArray fColorStages; |
365 EffectStageArray fCoverageStages; | 411 EffectStageArray fCoverageStages; |
366 | 412 |
413 uint32_t fHints; | |
414 | |
367 mutable GrBlendCoeff fOptSrcBlend; | 415 mutable GrBlendCoeff fOptSrcBlend; |
368 mutable GrBlendCoeff fOptDstBlend; | 416 mutable GrBlendCoeff fOptDstBlend; |
369 mutable BlendOptFlags fBlendOptFlags; | 417 mutable BlendOptFlags fBlendOptFlags; |
370 | 418 |
371 // This is simply a different representation of info in fVertexAttribs and t hus does | 419 // This is simply a different representation of info in fVertexAttribs and t hus does |
372 // not need to be compared in op==. | 420 // not need to be compared in op==. |
373 int fFixedFunctionVertexAttribIndices[kGrFixedFunctionVertexAttribBindingCnt ]; | 421 int fFixedFunctionVertexAttribIndices[kGrFixedFunctionVertexAttribBindingCnt ]; |
374 | 422 |
375 private: | 423 private: |
424 /** | |
425 * Determines whether src alpha is guaranteed to be one for all src pixels | |
426 */ | |
427 bool srcAlphaWillBeOne() const; | |
428 | |
429 /** | |
430 * Helper function for getBlendOpts. | |
431 */ | |
432 BlendOptFlags calcBlendOpts(bool forceCoverage = false, | |
433 GrBlendCoeff* srcCoeff = NULL, | |
434 GrBlendCoeff* dstCoeff = NULL) const; | |
435 | |
376 typedef SkRefCnt INHERITED; | 436 typedef SkRefCnt INHERITED; |
377 }; | 437 }; |
378 | 438 |
379 GR_MAKE_BITFIELD_OPS(GrRODrawState::BlendOptFlags); | 439 GR_MAKE_BITFIELD_OPS(GrRODrawState::BlendOptFlags); |
380 | 440 |
381 #endif | 441 #endif |
OLD | NEW |