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 GrDrawState_DEFINED | 8 #ifndef GrDrawState_DEFINED |
9 #define GrDrawState_DEFINED | 9 #define GrDrawState_DEFINED |
10 | 10 |
11 #include "GrRODrawState.h" | |
12 | |
11 #include "GrBlend.h" | 13 #include "GrBlend.h" |
12 #include "GrColor.h" | |
13 #include "GrEffectStage.h" | |
14 #include "GrStencil.h" | |
15 #include "effects/GrSimpleTextureEffect.h" | 14 #include "effects/GrSimpleTextureEffect.h" |
16 | 15 |
17 #include "SkMatrix.h" | 16 /** |
18 | 17 * Sub class that is derived from GrRODrawState. The majority of the data the re presents a draw |
bsalomon
2014/08/26 18:25:55
Subclass?
"data the"->"data that"?
Maybe say "Ed
egdaniel
2014/08/26 18:45:23
Done.
| |
19 class GrDrawTargetCaps; | 18 * state is stored in the parent class. GrDrawState contains methods for setting , adding to, etc. |
20 class GrPaint; | 19 * various data members of the draw state. This class will be used in the majori ty of the cases |
21 class GrRenderTarget; | 20 * where a draw state is needed. |
22 class GrTexture; | 21 */ |
23 | 22 class GrDrawState : public GrRODrawState { |
24 class GrDrawState : public SkRefCnt { | |
25 public: | 23 public: |
26 SK_DECLARE_INST_COUNT(GrDrawState) | 24 SK_DECLARE_INST_COUNT(GrDrawState) |
27 | 25 |
28 GrDrawState() { | 26 GrDrawState() { |
29 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) | 27 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
30 this->reset(); | 28 this->reset(); |
31 } | 29 } |
32 | 30 |
33 GrDrawState(const SkMatrix& initialViewMatrix) { | 31 GrDrawState(const SkMatrix& initialViewMatrix) { |
34 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) | 32 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
(...skipping 27 matching lines...) Expand all Loading... | |
62 * GrDrawState encompasses more than GrPaint. Aspects of GrDrawState that ha ve no GrPaint | 60 * GrDrawState encompasses more than GrPaint. Aspects of GrDrawState that ha ve no GrPaint |
63 * equivalents are set to default values with the exception of vertex attrib ute state which | 61 * equivalents are set to default values with the exception of vertex attrib ute state which |
64 * is unmodified by this function and clipping which will be enabled. | 62 * is unmodified by this function and clipping which will be enabled. |
65 */ | 63 */ |
66 void setFromPaint(const GrPaint& , const SkMatrix& viewMatrix, GrRenderTarge t*); | 64 void setFromPaint(const GrPaint& , const SkMatrix& viewMatrix, GrRenderTarge t*); |
67 | 65 |
68 /////////////////////////////////////////////////////////////////////////// | 66 /////////////////////////////////////////////////////////////////////////// |
69 /// @name Vertex Attributes | 67 /// @name Vertex Attributes |
70 //// | 68 //// |
71 | 69 |
72 enum { | |
73 kMaxVertexAttribCnt = kLast_GrVertexAttribBinding + 4, | |
74 }; | |
75 | |
76 /** | 70 /** |
77 * The format of vertices is represented as an array of GrVertexAttribs, wit h each representing | 71 * The format of vertices is represented as an array of GrVertexAttribs, wit h each representing |
78 * the type of the attribute, its offset, and semantic binding (see GrVertex Attrib in | 72 * the type of the attribute, its offset, and semantic binding (see GrVertex Attrib in |
79 * GrTypesPriv.h). | 73 * GrTypesPriv.h). |
80 * | 74 * |
81 * The mapping of attributes with kEffect bindings to GrEffect inputs is spe cified when | 75 * The mapping of attributes with kEffect bindings to GrEffect inputs is spe cified when |
82 * setEffect is called. | 76 * setEffect is called. |
83 */ | 77 */ |
84 | 78 |
85 /** | 79 /** |
86 * Sets vertex attributes for next draw. The object driving the templatizat ion | 80 * Sets vertex attributes for next draw. The object driving the templatizat ion |
87 * should be a global GrVertexAttrib array that is never changed. | 81 * should be a global GrVertexAttrib array that is never changed. |
88 */ | 82 */ |
89 template <const GrVertexAttrib A[]> void setVertexAttribs(int count) { | 83 template <const GrVertexAttrib A[]> void setVertexAttribs(int count) { |
90 this->setVertexAttribs(A, count); | 84 this->setVertexAttribs(A, count); |
91 } | 85 } |
92 | 86 |
93 const GrVertexAttrib* getVertexAttribs() const { return fVAPtr; } | |
94 int getVertexAttribCount() const { return fVACount; } | |
95 | |
96 size_t getVertexSize() const; | |
97 | |
98 /** | 87 /** |
99 * Sets default vertex attributes for next draw. The default is a single at tribute: | 88 * Sets default vertex attributes for next draw. The default is a single at tribute: |
100 * {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribType} | 89 * {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribType} |
101 */ | 90 */ |
102 void setDefaultVertexAttribs(); | 91 void setDefaultVertexAttribs(); |
103 | 92 |
104 /** | 93 /** |
105 * Getters for index into getVertexAttribs() for particular bindings. -1 is returned if the | |
106 * binding does not appear in the current attribs. These bindings should app ear only once in | |
107 * the attrib array. | |
108 */ | |
109 | |
110 int positionAttributeIndex() const { | |
111 return fFixedFunctionVertexAttribIndices[kPosition_GrVertexAttribBinding ]; | |
112 } | |
113 int localCoordAttributeIndex() const { | |
114 return fFixedFunctionVertexAttribIndices[kLocalCoord_GrVertexAttribBindi ng]; | |
115 } | |
116 int colorVertexAttributeIndex() const { | |
117 return fFixedFunctionVertexAttribIndices[kColor_GrVertexAttribBinding]; | |
118 } | |
119 int coverageVertexAttributeIndex() const { | |
120 return fFixedFunctionVertexAttribIndices[kCoverage_GrVertexAttribBinding ]; | |
121 } | |
122 | |
123 bool hasLocalCoordAttribute() const { | |
124 return -1 != fFixedFunctionVertexAttribIndices[kLocalCoord_GrVertexAttri bBinding]; | |
125 } | |
126 bool hasColorVertexAttribute() const { | |
127 return -1 != fFixedFunctionVertexAttribIndices[kColor_GrVertexAttribBind ing]; | |
128 } | |
129 bool hasCoverageVertexAttribute() const { | |
130 return -1 != fFixedFunctionVertexAttribIndices[kCoverage_GrVertexAttribB inding]; | |
131 } | |
132 | |
133 bool validateVertexAttribs() const; | |
134 | |
135 /** | |
136 * Helper to save/restore vertex attribs | 94 * Helper to save/restore vertex attribs |
137 */ | 95 */ |
138 class AutoVertexAttribRestore { | 96 class AutoVertexAttribRestore { |
139 public: | 97 public: |
140 AutoVertexAttribRestore(GrDrawState* drawState); | 98 AutoVertexAttribRestore(GrDrawState* drawState); |
141 | 99 |
142 ~AutoVertexAttribRestore() { fDrawState->setVertexAttribs(fVAPtr, fVACo unt); } | 100 ~AutoVertexAttribRestore() { fDrawState->setVertexAttribs(fVAPtr, fVACo unt); } |
143 | 101 |
144 private: | 102 private: |
145 GrDrawState* fDrawState; | 103 GrDrawState* fDrawState; |
146 const GrVertexAttrib* fVAPtr; | 104 const GrVertexAttrib* fVAPtr; |
147 int fVACount; | 105 int fVACount; |
148 }; | 106 }; |
149 | 107 |
150 /// @} | 108 /// @} |
151 | 109 |
152 /** | 110 /** |
153 * Determines whether src alpha is guaranteed to be one for all src pixels | 111 * Determines whether src alpha is guaranteed to be one for all src pixels |
154 */ | 112 */ |
155 bool srcAlphaWillBeOne() const; | 113 bool srcAlphaWillBeOne() const; |
bsalomon
2014/08/26 18:15:01
Shouldn't this be in RO?
egdaniel
2014/08/26 18:23:46
This is only called in one place, calcBlendOpt. It
bsalomon
2014/08/26 18:26:41
That sgtm
| |
156 | 114 |
157 /** | 115 /** |
158 * Determines whether the output coverage is guaranteed to be one for all pi xels hit by a draw. | |
159 */ | |
160 bool hasSolidCoverage() const; | |
161 | |
162 /** | |
163 * Depending on features available in the underlying 3D API and the color bl end mode requested | 116 * Depending on features available in the underlying 3D API and the color bl end mode requested |
164 * it may or may not be possible to correctly blend with fractional pixel co verage generated by | 117 * it may or may not be possible to correctly blend with fractional pixel co verage generated by |
165 * the fragment shader. | 118 * the fragment shader. |
166 * | 119 * |
167 * This function considers the current draw state and the draw target's capa bilities to | 120 * This function considers the current draw state and the draw target's capa bilities to |
168 * determine whether coverage can be handled correctly. This function assume s that the caller | 121 * determine whether coverage can be handled correctly. This function assume s that the caller |
169 * intends to specify fractional pixel coverage (via setCoverage(), through a coverage vertex | 122 * intends to specify fractional pixel coverage (via setCoverage(), through a coverage vertex |
170 * attribute, or a coverage effect) but may not have specified it yet. | 123 * attribute, or a coverage effect) but may not have specified it yet. |
171 */ | 124 */ |
172 bool couldApplyCoverage(const GrDrawTargetCaps& caps) const; | 125 bool couldApplyCoverage(const GrDrawTargetCaps& caps) const; |
173 | 126 |
174 /// @} | 127 /// @} |
175 | 128 |
176 /////////////////////////////////////////////////////////////////////////// | 129 /////////////////////////////////////////////////////////////////////////// |
177 /// @name Color | 130 /// @name Color |
178 //// | 131 //// |
179 | 132 |
180 /** | 133 /** |
181 * Sets color for next draw to a premultiplied-alpha color. | 134 * Sets color for next draw to a premultiplied-alpha color. |
182 * | 135 * |
183 * @param color the color to set. | 136 * @param color the color to set. |
184 */ | 137 */ |
185 void setColor(GrColor color) { | 138 void setColor(GrColor color) { |
186 fColor = color; | 139 fColor = color; |
187 this->invalidateBlendOptFlags(); | 140 this->invalidateBlendOptFlags(); |
188 } | 141 } |
189 | 142 |
190 GrColor getColor() const { return fColor; } | |
191 | |
192 /** | 143 /** |
193 * Sets the color to be used for the next draw to be | 144 * Sets the color to be used for the next draw to be |
194 * (r,g,b,a) = (alpha, alpha, alpha, alpha). | 145 * (r,g,b,a) = (alpha, alpha, alpha, alpha). |
195 * | 146 * |
196 * @param alpha The alpha value to set as the color. | 147 * @param alpha The alpha value to set as the color. |
197 */ | 148 */ |
198 void setAlpha(uint8_t a) { this->setColor((a << 24) | (a << 16) | (a << 8) | a); } | 149 void setAlpha(uint8_t a) { this->setColor((a << 24) | (a << 16) | (a << 8) | a); } |
199 | 150 |
200 /// @} | 151 /// @} |
201 | 152 |
202 /////////////////////////////////////////////////////////////////////////// | 153 /////////////////////////////////////////////////////////////////////////// |
203 /// @name Coverage | 154 /// @name Coverage |
204 //// | 155 //// |
205 | 156 |
206 /** | 157 /** |
207 * Sets a constant fractional coverage to be applied to the draw. The | 158 * Sets a constant fractional coverage to be applied to the draw. The |
208 * initial value (after construction or reset()) is 0xff. The constant | 159 * initial value (after construction or reset()) is 0xff. The constant |
209 * coverage is ignored when per-vertex coverage is provided. | 160 * coverage is ignored when per-vertex coverage is provided. |
210 */ | 161 */ |
211 void setCoverage(uint8_t coverage) { | 162 void setCoverage(uint8_t coverage) { |
212 fCoverage = coverage; | 163 fCoverage = coverage; |
213 this->invalidateBlendOptFlags(); | 164 this->invalidateBlendOptFlags(); |
214 } | 165 } |
215 | 166 |
216 uint8_t getCoverage() const { return fCoverage; } | |
217 | |
218 GrColor getCoverageColor() const { | |
219 return GrColorPackRGBA(fCoverage, fCoverage, fCoverage, fCoverage); | |
220 } | |
221 | |
222 /// @} | 167 /// @} |
223 | 168 |
224 /////////////////////////////////////////////////////////////////////////// | 169 /////////////////////////////////////////////////////////////////////////// |
225 /// @name Effect Stages | 170 /// @name Effect Stages |
226 /// Each stage hosts a GrEffect. The effect produces an output color or cove rage in the fragment | 171 /// Each stage hosts a GrEffect. The effect produces an output color or cove rage in the fragment |
227 /// shader. Its inputs are the output from the previous stage as well as som e variables | 172 /// shader. Its inputs are the output from the previous stage as well as som e variables |
228 /// available to it in the fragment and vertex shader (e.g. the vertex posit ion, the dst color, | 173 /// available to it in the fragment and vertex shader (e.g. the vertex posit ion, the dst color, |
229 /// the fragment position, local coordinates). | 174 /// the fragment position, local coordinates). |
230 /// | 175 /// |
231 /// The stages are divided into two sets, color-computing and coverage-compu ting. The final | 176 /// The stages are divided into two sets, color-computing and coverage-compu ting. The final |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
295 void set(GrDrawState* ds); | 240 void set(GrDrawState* ds); |
296 | 241 |
297 bool isSet() const { return NULL != fDrawState; } | 242 bool isSet() const { return NULL != fDrawState; } |
298 | 243 |
299 private: | 244 private: |
300 GrDrawState* fDrawState; | 245 GrDrawState* fDrawState; |
301 int fColorEffectCnt; | 246 int fColorEffectCnt; |
302 int fCoverageEffectCnt; | 247 int fCoverageEffectCnt; |
303 }; | 248 }; |
304 | 249 |
305 int numColorStages() const { return fColorStages.count(); } | |
306 int numCoverageStages() const { return fCoverageStages.count(); } | |
307 int numTotalStages() const { return this->numColorStages() + this->numCovera geStages(); } | |
308 | |
309 const GrEffectStage& getColorStage(int stageIdx) const { return fColorStages [stageIdx]; } | |
310 const GrEffectStage& getCoverageStage(int stageIdx) const { return fCoverage Stages[stageIdx]; } | |
311 | |
312 /** | |
313 * Checks whether any of the effects will read the dst pixel color. | |
314 */ | |
315 bool willEffectReadDstColor() const; | |
316 | |
317 /// @} | 250 /// @} |
318 | 251 |
319 /////////////////////////////////////////////////////////////////////////// | 252 /////////////////////////////////////////////////////////////////////////// |
320 /// @name Blending | 253 /// @name Blending |
321 //// | 254 //// |
322 | 255 |
323 /** | 256 /** |
324 * Sets the blending function coefficients. | 257 * Sets the blending function coefficients. |
325 * | 258 * |
326 * The blend function will be: | 259 * The blend function will be: |
(...skipping 13 matching lines...) Expand all Loading... | |
340 #ifdef SK_DEBUG | 273 #ifdef SK_DEBUG |
341 if (GrBlendCoeffRefsDst(dstCoeff)) { | 274 if (GrBlendCoeffRefsDst(dstCoeff)) { |
342 GrPrintf("Unexpected dst blend coeff. Won't work correctly with cove rage stages.\n"); | 275 GrPrintf("Unexpected dst blend coeff. Won't work correctly with cove rage stages.\n"); |
343 } | 276 } |
344 if (GrBlendCoeffRefsSrc(srcCoeff)) { | 277 if (GrBlendCoeffRefsSrc(srcCoeff)) { |
345 GrPrintf("Unexpected src blend coeff. Won't work correctly with cove rage stages.\n"); | 278 GrPrintf("Unexpected src blend coeff. Won't work correctly with cove rage stages.\n"); |
346 } | 279 } |
347 #endif | 280 #endif |
348 } | 281 } |
349 | 282 |
350 GrBlendCoeff getSrcBlendCoeff() const { return fSrcBlend; } | |
351 GrBlendCoeff getDstBlendCoeff() const { return fDstBlend; } | |
352 | |
353 void getDstBlendCoeff(GrBlendCoeff* srcBlendCoeff, | |
354 GrBlendCoeff* dstBlendCoeff) const { | |
355 *srcBlendCoeff = fSrcBlend; | |
356 *dstBlendCoeff = fDstBlend; | |
357 } | |
358 | |
359 /** | 283 /** |
360 * Sets the blending function constant referenced by the following blending | 284 * Sets the blending function constant referenced by the following blending |
361 * coefficients: | 285 * coefficients: |
362 * kConstC_GrBlendCoeff | 286 * kConstC_GrBlendCoeff |
363 * kIConstC_GrBlendCoeff | 287 * kIConstC_GrBlendCoeff |
364 * kConstA_GrBlendCoeff | 288 * kConstA_GrBlendCoeff |
365 * kIConstA_GrBlendCoeff | 289 * kIConstA_GrBlendCoeff |
366 * | 290 * |
367 * @param constant the constant to set | 291 * @param constant the constant to set |
368 */ | 292 */ |
369 void setBlendConstant(GrColor constant) { | 293 void setBlendConstant(GrColor constant) { |
370 fBlendConstant = constant; | 294 fBlendConstant = constant; |
371 this->invalidateBlendOptFlags(); | 295 this->invalidateBlendOptFlags(); |
372 } | 296 } |
373 | 297 |
374 /** | 298 /** |
375 * Retrieves the last value set by setBlendConstant() | |
376 * @return the blending constant value | |
377 */ | |
378 GrColor getBlendConstant() const { return fBlendConstant; } | |
379 | |
380 /** | |
381 * Determines whether multiplying the computed per-pixel color by the pixel' s fractional | |
382 * coverage before the blend will give the correct final destination color. In general it | |
383 * will not as coverage is applied after blending. | |
384 */ | |
385 bool canTweakAlphaForCoverage() const; | |
386 | |
387 /** | |
388 * Optimizations for blending / coverage to that can be applied based on the current state. | |
389 */ | |
390 enum BlendOptFlags { | |
391 /** | |
392 * No optimization | |
393 */ | |
394 kNone_BlendOpt = 0, | |
395 /** | |
396 * Don't draw at all | |
397 */ | |
398 kSkipDraw_BlendOptFlag = 0x1, | |
399 /** | |
400 * The coverage value does not have to be computed separately from alpha , the the output | |
401 * color can be the modulation of the two. | |
402 */ | |
403 kCoverageAsAlpha_BlendOptFlag = 0x2, | |
404 /** | |
405 * Instead of emitting a src color, emit coverage in the alpha channel a nd r,g,b are | |
406 * "don't cares". | |
407 */ | |
408 kEmitCoverage_BlendOptFlag = 0x4, | |
409 /** | |
410 * Emit transparent black instead of the src color, no need to compute c overage. | |
411 */ | |
412 kEmitTransBlack_BlendOptFlag = 0x8, | |
413 /** | |
414 * Flag used to invalidate the cached BlendOptFlags, OptSrcCoeff, and Op tDstCoeff cached by | |
415 * the get BlendOpts function. | |
416 */ | |
417 kInvalid_BlendOptFlag = 1 << 31, | |
418 }; | |
419 GR_DECL_BITFIELD_OPS_FRIENDS(BlendOptFlags); | |
420 | |
421 void invalidateBlendOptFlags() { | |
422 fBlendOptFlags = kInvalid_BlendOptFlag; | |
423 } | |
424 | |
425 /** | |
426 * We don't use suplied vertex color attributes if our blend mode is EmitCov erage or | |
427 * EmitTransBlack | |
428 */ | |
429 bool canIgnoreColorAttribute() const; | |
430 | |
431 /** | |
432 * Determines what optimizations can be applied based on the blend. The coef ficients may have | 299 * Determines what optimizations can be applied based on the blend. The coef ficients may have |
433 * to be tweaked in order for the optimization to work. srcCoeff and dstCoef f are optional | 300 * to be tweaked in order for the optimization to work. srcCoeff and dstCoef f are optional |
434 * params that receive the tweaked coefficients. Normally the function looks at the current | 301 * params that receive the tweaked coefficients. Normally the function looks at the current |
435 * state to see if coverage is enabled. By setting forceCoverage the caller can speculatively | 302 * state to see if coverage is enabled. By setting forceCoverage the caller can speculatively |
436 * determine the blend optimizations that would be used if there was partial pixel coverage. | 303 * determine the blend optimizations that would be used if there was partial pixel coverage. |
437 * | 304 * |
438 * Subclasses of GrDrawTarget that actually draw (as opposed to those that j ust buffer for | 305 * Subclasses of GrDrawTarget that actually draw (as opposed to those that j ust buffer for |
439 * playback) must call this function and respect the flags that replace the output color. | 306 * playback) must call this function and respect the flags that replace the output color. |
440 * | 307 * |
441 * If the cached BlendOptFlags does not have the invalidate bit set, then ge tBlendOpts will | 308 * If the cached BlendOptFlags does not have the invalidate bit set, then ge tBlendOpts will |
442 * simply returned the cached flags and coefficients. Otherwise it will calc ulate the values. | 309 * simply returned the cached flags and coefficients. Otherwise it will calc ulate the values. |
443 */ | 310 */ |
444 BlendOptFlags getBlendOpts(bool forceCoverage = false, | 311 BlendOptFlags getBlendOpts(bool forceCoverage = false, |
445 GrBlendCoeff* srcCoeff = NULL, | 312 GrBlendCoeff* srcCoeff = NULL, |
446 GrBlendCoeff* dstCoeff = NULL) const; | 313 GrBlendCoeff* dstCoeff = NULL) const; |
447 | 314 |
315 void invalidateBlendOptFlags() { | |
bsalomon
2014/08/26 18:15:01
Is this public? Need it be?
egdaniel
2014/08/26 18:23:46
Should be private.
| |
316 fBlendOptFlags = kInvalid_BlendOptFlag; | |
317 } | |
318 | |
319 /** | |
320 * We don't use suplied vertex color attributes if our blend mode is EmitCov erage or | |
321 * EmitTransBlack | |
322 */ | |
323 bool canIgnoreColorAttribute() const; | |
bsalomon
2014/08/26 18:15:01
Should this be in RO? I guess it is going to go aw
egdaniel
2014/08/26 18:23:46
The entire idea of ignoring color attribs is remov
egdaniel
2014/08/26 18:45:23
So I realized the reason I had this here is becaus
bsalomon
2014/08/26 18:51:52
Ok if it disappears (or goes private) at the end o
| |
324 | |
325 | |
448 /// @} | 326 /// @} |
449 | 327 |
450 /////////////////////////////////////////////////////////////////////////// | 328 /////////////////////////////////////////////////////////////////////////// |
451 /// @name View Matrix | 329 /// @name View Matrix |
452 //// | 330 //// |
453 | 331 |
454 /** | 332 /** |
455 * Sets the view matrix to identity and updates any installed effects to com pensate for the | 333 * Sets the view matrix to identity and updates any installed effects to com pensate for the |
456 * coord system change. | 334 * coord system change. |
457 */ | 335 */ |
458 bool setIdentityViewMatrix(); | 336 bool setIdentityViewMatrix(); |
459 | 337 |
460 /** | |
461 * Retrieves the current view matrix | |
462 * @return the current view matrix. | |
463 */ | |
464 const SkMatrix& getViewMatrix() const { return fViewMatrix; } | |
465 | |
466 /** | |
467 * Retrieves the inverse of the current view matrix. | |
468 * | |
469 * If the current view matrix is invertible, return true, and if matrix | |
470 * is non-null, copy the inverse into it. If the current view matrix is | |
471 * non-invertible, return false and ignore the matrix parameter. | |
472 * | |
473 * @param matrix if not null, will receive a copy of the current inverse. | |
474 */ | |
475 bool getViewInverse(SkMatrix* matrix) const { | |
476 // TODO: determine whether we really need to leave matrix unmodified | |
477 // at call sites when inversion fails. | |
478 SkMatrix inverse; | |
479 if (fViewMatrix.invert(&inverse)) { | |
480 if (matrix) { | |
481 *matrix = inverse; | |
482 } | |
483 return true; | |
484 } | |
485 return false; | |
486 } | |
487 | |
488 //////////////////////////////////////////////////////////////////////////// | 338 //////////////////////////////////////////////////////////////////////////// |
489 | 339 |
490 /** | 340 /** |
491 * Preconcats the current view matrix and restores the previous view matrix in the destructor. | 341 * Preconcats the current view matrix and restores the previous view matrix in the destructor. |
492 * Effect matrices are automatically adjusted to compensate and adjusted bac k in the destructor. | 342 * Effect matrices are automatically adjusted to compensate and adjusted bac k in the destructor. |
493 */ | 343 */ |
494 class AutoViewMatrixRestore : public ::SkNoncopyable { | 344 class AutoViewMatrixRestore : public ::SkNoncopyable { |
495 public: | 345 public: |
496 AutoViewMatrixRestore() : fDrawState(NULL) {} | 346 AutoViewMatrixRestore() : fDrawState(NULL) {} |
497 | 347 |
(...skipping 30 matching lines...) Expand all Loading... | |
528 /// @name Render Target | 378 /// @name Render Target |
529 //// | 379 //// |
530 | 380 |
531 /** | 381 /** |
532 * Sets the render-target used at the next drawing call | 382 * Sets the render-target used at the next drawing call |
533 * | 383 * |
534 * @param target The render target to set. | 384 * @param target The render target to set. |
535 */ | 385 */ |
536 void setRenderTarget(GrRenderTarget* target) { fRenderTarget.reset(SkSafeRef (target)); } | 386 void setRenderTarget(GrRenderTarget* target) { fRenderTarget.reset(SkSafeRef (target)); } |
537 | 387 |
538 /** | |
539 * Retrieves the currently set render-target. | |
540 * | |
541 * @return The currently set render target. | |
542 */ | |
543 const GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); } | |
544 GrRenderTarget* getRenderTarget() { return fRenderTarget.get(); } | |
545 | |
546 class AutoRenderTargetRestore : public ::SkNoncopyable { | 388 class AutoRenderTargetRestore : public ::SkNoncopyable { |
547 public: | 389 public: |
548 AutoRenderTargetRestore() : fDrawState(NULL), fSavedTarget(NULL) {} | 390 AutoRenderTargetRestore() : fDrawState(NULL), fSavedTarget(NULL) {} |
549 AutoRenderTargetRestore(GrDrawState* ds, GrRenderTarget* newTarget) { | 391 AutoRenderTargetRestore(GrDrawState* ds, GrRenderTarget* newTarget) { |
550 fDrawState = NULL; | 392 fDrawState = NULL; |
551 fSavedTarget = NULL; | 393 fSavedTarget = NULL; |
552 this->set(ds, newTarget); | 394 this->set(ds, newTarget); |
553 } | 395 } |
554 ~AutoRenderTargetRestore() { this->restore(); } | 396 ~AutoRenderTargetRestore() { this->restore(); } |
555 | 397 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
596 } | 438 } |
597 | 439 |
598 /** | 440 /** |
599 * Shortcut to disable stencil testing and ops. | 441 * Shortcut to disable stencil testing and ops. |
600 */ | 442 */ |
601 void disableStencil() { | 443 void disableStencil() { |
602 fStencilSettings.setDisabled(); | 444 fStencilSettings.setDisabled(); |
603 this->invalidateBlendOptFlags(); | 445 this->invalidateBlendOptFlags(); |
604 } | 446 } |
605 | 447 |
606 const GrStencilSettings& getStencil() const { return fStencilSettings; } | |
607 | |
608 GrStencilSettings* stencil() { return &fStencilSettings; } | 448 GrStencilSettings* stencil() { return &fStencilSettings; } |
609 | 449 |
610 /// @} | 450 /// @} |
611 | 451 |
612 /////////////////////////////////////////////////////////////////////////// | 452 /////////////////////////////////////////////////////////////////////////// |
613 /// @name State Flags | 453 /// @name State Flags |
614 //// | 454 //// |
615 | 455 |
616 /** | |
617 * Flags that affect rendering. Controlled using enable/disableState(). All | |
618 * default to disabled. | |
619 */ | |
620 enum StateBits { | |
621 /** | |
622 * Perform dithering. TODO: Re-evaluate whether we need this bit | |
623 */ | |
624 kDither_StateBit = 0x01, | |
625 /** | |
626 * Perform HW anti-aliasing. This means either HW FSAA, if supported by the render target, | |
627 * or smooth-line rendering if a line primitive is drawn and line smooth ing is supported by | |
628 * the 3D API. | |
629 */ | |
630 kHWAntialias_StateBit = 0x02, | |
631 /** | |
632 * Draws will respect the clip, otherwise the clip is ignored. | |
633 */ | |
634 kClip_StateBit = 0x04, | |
635 /** | |
636 * Disables writing to the color buffer. Useful when performing stencil | |
637 * operations. | |
638 */ | |
639 kNoColorWrites_StateBit = 0x08, | |
640 | |
641 /** | |
642 * Usually coverage is applied after color blending. The color is blende d using the coeffs | |
643 * specified by setBlendFunc(). The blended color is then combined with dst using coeffs | |
644 * of src_coverage, 1-src_coverage. Sometimes we are explicitly drawing a coverage mask. In | |
645 * this case there is no distinction between coverage and color and the caller needs direct | |
646 * control over the blend coeffs. When set, there will be a single blend step controlled by | |
647 * setBlendFunc() which will use coverage*color as the src color. | |
648 */ | |
649 kCoverageDrawing_StateBit = 0x10, | |
650 | |
651 // Users of the class may add additional bits to the vector | |
652 kDummyStateBit, | |
653 kLastPublicStateBit = kDummyStateBit-1, | |
654 }; | |
655 | |
656 void resetStateFlags() { | 456 void resetStateFlags() { |
657 fFlagBits = 0; | 457 fFlagBits = 0; |
658 this->invalidateBlendOptFlags(); | 458 this->invalidateBlendOptFlags(); |
659 } | 459 } |
660 | 460 |
661 /** | 461 /** |
662 * Enable render state settings. | 462 * Enable render state settings. |
663 * | 463 * |
664 * @param stateBits bitfield of StateBits specifying the states to enable | 464 * @param stateBits bitfield of StateBits specifying the states to enable |
665 */ | 465 */ |
(...skipping 19 matching lines...) Expand all Loading... | |
685 * @param enable if true enable stateBits, otherwise disable | 485 * @param enable if true enable stateBits, otherwise disable |
686 */ | 486 */ |
687 void setState(uint32_t stateBits, bool enable) { | 487 void setState(uint32_t stateBits, bool enable) { |
688 if (enable) { | 488 if (enable) { |
689 this->enableState(stateBits); | 489 this->enableState(stateBits); |
690 } else { | 490 } else { |
691 this->disableState(stateBits); | 491 this->disableState(stateBits); |
692 } | 492 } |
693 } | 493 } |
694 | 494 |
695 bool isStateFlagEnabled(uint32_t stateBit) const { return 0 != (stateBit & f FlagBits); } | |
696 | |
697 bool isDitherState() const { return 0 != (fFlagBits & kDither_StateBit); } | |
698 bool isHWAntialiasState() const { return 0 != (fFlagBits & kHWAntialias_Stat eBit); } | |
699 bool isClipState() const { return 0 != (fFlagBits & kClip_StateBit); } | |
700 bool isColorWriteDisabled() const { return 0 != (fFlagBits & kNoColorWrites_ StateBit); } | |
701 bool isCoverageDrawing() const { return 0 != (fFlagBits & kCoverageDrawing_S tateBit); } | |
702 | |
703 /// @} | 495 /// @} |
704 | 496 |
705 /////////////////////////////////////////////////////////////////////////// | 497 /////////////////////////////////////////////////////////////////////////// |
706 /// @name Face Culling | 498 /// @name Face Culling |
707 //// | 499 //// |
708 | 500 |
709 enum DrawFace { | |
710 kInvalid_DrawFace = -1, | |
711 | |
712 kBoth_DrawFace, | |
713 kCCW_DrawFace, | |
714 kCW_DrawFace, | |
715 }; | |
716 | |
717 /** | 501 /** |
718 * Controls whether clockwise, counterclockwise, or both faces are drawn. | 502 * Controls whether clockwise, counterclockwise, or both faces are drawn. |
719 * @param face the face(s) to draw. | 503 * @param face the face(s) to draw. |
720 */ | 504 */ |
721 void setDrawFace(DrawFace face) { | 505 void setDrawFace(DrawFace face) { |
722 SkASSERT(kInvalid_DrawFace != face); | 506 SkASSERT(kInvalid_DrawFace != face); |
723 fDrawFace = face; | 507 fDrawFace = face; |
724 } | 508 } |
725 | 509 |
726 /** | |
727 * Gets whether the target is drawing clockwise, counterclockwise, | |
728 * or both faces. | |
729 * @return the current draw face(s). | |
730 */ | |
731 DrawFace getDrawFace() const { return fDrawFace; } | |
732 | |
733 /// @} | 510 /// @} |
734 | 511 |
735 /////////////////////////////////////////////////////////////////////////// | 512 /////////////////////////////////////////////////////////////////////////// |
736 /// @name Hints | 513 /// @name Hints |
737 /// Hints that when provided can enable optimizations. | 514 /// Hints that when provided can enable optimizations. |
738 //// | 515 //// |
739 | 516 |
740 enum Hints { kVertexColorsAreOpaque_Hint = 0x1, }; | 517 enum Hints { kVertexColorsAreOpaque_Hint = 0x1, }; |
741 | 518 |
742 void setHint(Hints hint, bool value) { fHints = value ? (fHints | hint) : (f Hints & ~hint); } | 519 void setHint(Hints hint, bool value) { fHints = value ? (fHints | hint) : (f Hints & ~hint); } |
(...skipping 23 matching lines...) Expand all Loading... | |
766 | 543 |
767 GrDrawState& operator= (const GrDrawState& that); | 544 GrDrawState& operator= (const GrDrawState& that); |
768 | 545 |
769 private: | 546 private: |
770 void onReset(const SkMatrix* initialViewMatrix); | 547 void onReset(const SkMatrix* initialViewMatrix); |
771 | 548 |
772 BlendOptFlags calcBlendOpts(bool forceCoverage = false, | 549 BlendOptFlags calcBlendOpts(bool forceCoverage = false, |
773 GrBlendCoeff* srcCoeff = NULL, | 550 GrBlendCoeff* srcCoeff = NULL, |
774 GrBlendCoeff* dstCoeff = NULL) const; | 551 GrBlendCoeff* dstCoeff = NULL) const; |
775 | 552 |
776 // These fields are roughly sorted by decreasing likelihood of being differe nt in op== | |
777 SkAutoTUnref<GrRenderTarget> fRenderTarget; | |
778 GrColor fColor; | |
779 SkMatrix fViewMatrix; | |
780 GrBlendCoeff fSrcBlend; | |
781 GrBlendCoeff fDstBlend; | |
782 GrColor fBlendConstant; | |
783 uint32_t fFlagBits; | |
784 const GrVertexAttrib* fVAPtr; | |
785 int fVACount; | |
786 size_t fVertexSize; | |
787 GrStencilSettings fStencilSettings; | |
788 uint8_t fCoverage; | |
789 DrawFace fDrawFace; | |
790 | |
791 typedef SkSTArray<4, GrEffectStage> EffectStageArray; | |
792 EffectStageArray fColorStages; | |
793 EffectStageArray fCoverageStages; | |
794 | |
795 uint32_t fHints; | 553 uint32_t fHints; |
796 | |
797 mutable GrBlendCoeff fOptSrcBlend; | |
798 mutable GrBlendCoeff fOptDstBlend; | |
799 mutable BlendOptFlags fBlendOptFlags; | |
800 | |
801 // This is simply a different representation of info in fVertexAttribs and t hus does | |
802 // not need to be compared in op==. | |
803 int fFixedFunctionVertexAttribIndices[kGrFixedFunctionVertexAttribBindingCnt ]; | |
804 | 554 |
805 // Some of the auto restore objects assume that no effects are removed durin g their lifetime. | 555 // Some of the auto restore objects assume that no effects are removed durin g their lifetime. |
806 // This is used to assert that this condition holds. | 556 // This is used to assert that this condition holds. |
807 SkDEBUGCODE(int fBlockEffectRemovalCnt;) | 557 SkDEBUGCODE(int fBlockEffectRemovalCnt;) |
808 | 558 |
809 /** | 559 /** |
810 * Sets vertex attributes for next draw. | 560 * Sets vertex attributes for next draw. |
811 * | 561 * |
812 * @param attribs the array of vertex attributes to set. | 562 * @param attribs the array of vertex attributes to set. |
813 * @param count the number of attributes being set, limited to kMaxVer texAttribCnt. | 563 * @param count the number of attributes being set, limited to kMaxVer texAttribCnt. |
814 */ | 564 */ |
815 void setVertexAttribs(const GrVertexAttrib attribs[], int count); | 565 void setVertexAttribs(const GrVertexAttrib attribs[], int count); |
816 | 566 |
817 typedef SkRefCnt INHERITED; | 567 typedef GrRODrawState INHERITED; |
818 }; | 568 }; |
819 | 569 |
820 GR_MAKE_BITFIELD_OPS(GrDrawState::BlendOptFlags); | |
821 | |
822 #endif | 570 #endif |
OLD | NEW |