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 "GrBlend.h" | |
12 #include "GrOptDrawState.h" | |
11 #include "GrRODrawState.h" | 13 #include "GrRODrawState.h" |
12 | |
13 #include "GrBlend.h" | |
14 #include "effects/GrSimpleTextureEffect.h" | 14 #include "effects/GrSimpleTextureEffect.h" |
15 | 15 |
16 /** | 16 /** |
17 * Sub class that is derived from GrRODrawState. The majority of the data the re presents a draw | 17 * Sub class that is derived from GrRODrawState. The majority of the data the re presents a draw |
18 * state is stored in the parent class. GrDrawState contains methods for setting , adding to, etc. | 18 * state is stored in the parent class. GrDrawState contains methods for setting , adding to, etc. |
19 * various data members of the draw state. This class will be used in the majori ty of the cases | 19 * various data members of the draw state. This class will be used in the majori ty of the cases |
20 * where a draw state is needed. | 20 * where a draw state is needed. |
21 */ | 21 */ |
22 class GrDrawState : public GrRODrawState { | 22 class GrDrawState : public GrRODrawState { |
23 public: | 23 public: |
24 SK_DECLARE_INST_COUNT(GrDrawState) | 24 SK_DECLARE_INST_COUNT(GrDrawState) |
25 | 25 |
26 GrDrawState() { | 26 GrDrawState() : fCachedOptState(NULL) { |
27 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) | 27 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
28 this->reset(); | 28 this->reset(); |
29 } | 29 } |
30 | 30 |
31 GrDrawState(const SkMatrix& initialViewMatrix) { | 31 GrDrawState(const SkMatrix& initialViewMatrix) :fCachedOptState(NULL) { |
bsalomon
2014/08/26 18:41:43
space after :
| |
32 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) | 32 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
33 this->reset(initialViewMatrix); | 33 this->reset(initialViewMatrix); |
34 } | 34 } |
35 | 35 |
36 /** | 36 /** |
37 * Copies another draw state. | 37 * Copies another draw state. |
38 **/ | 38 **/ |
39 GrDrawState(const GrDrawState& state) : INHERITED() { | 39 GrDrawState(const GrDrawState& state) : INHERITED(), fCachedOptState(NULL) { |
40 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) | 40 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
41 *this = state; | 41 *this = state; |
42 } | 42 } |
43 | 43 |
44 /** | 44 /** |
45 * Copies another draw state with a preconcat to the view matrix. | 45 * Copies another draw state with a preconcat to the view matrix. |
46 **/ | 46 **/ |
47 GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatrix); | 47 GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatrix); |
48 | 48 |
49 virtual ~GrDrawState() { SkASSERT(0 == fBlockEffectRemovalCnt); } | 49 virtual ~GrDrawState() { |
50 SkSafeUnref(fCachedOptState); | |
51 SkASSERT(0 == fBlockEffectRemovalCnt); | |
52 } | |
50 | 53 |
51 /** | 54 /** |
52 * Resets to the default state. GrEffects will be removed from all stages. | 55 * Resets to the default state. GrEffects will be removed from all stages. |
53 */ | 56 */ |
54 void reset() { this->onReset(NULL); } | 57 void reset() { this->onReset(NULL); } |
55 | 58 |
56 void reset(const SkMatrix& initialViewMatrix) { this->onReset(&initialViewMa trix); } | 59 void reset(const SkMatrix& initialViewMatrix) { this->onReset(&initialViewMa trix); } |
57 | 60 |
58 /** | 61 /** |
59 * Initializes the GrDrawState based on a GrPaint, view matrix and render ta rget. Note that | 62 * Initializes the GrDrawState based on a GrPaint, view matrix and render ta rget. Note that |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
129 /////////////////////////////////////////////////////////////////////////// | 132 /////////////////////////////////////////////////////////////////////////// |
130 /// @name Color | 133 /// @name Color |
131 //// | 134 //// |
132 | 135 |
133 /** | 136 /** |
134 * Sets color for next draw to a premultiplied-alpha color. | 137 * Sets color for next draw to a premultiplied-alpha color. |
135 * | 138 * |
136 * @param color the color to set. | 139 * @param color the color to set. |
137 */ | 140 */ |
138 void setColor(GrColor color) { | 141 void setColor(GrColor color) { |
139 fColor = color; | 142 if (color != fColor) { |
140 this->invalidateBlendOptFlags(); | 143 fColor = color; |
144 this->invalidateOptState(); | |
145 } | |
141 } | 146 } |
142 | 147 |
143 /** | 148 /** |
144 * Sets the color to be used for the next draw to be | 149 * Sets the color to be used for the next draw to be |
145 * (r,g,b,a) = (alpha, alpha, alpha, alpha). | 150 * (r,g,b,a) = (alpha, alpha, alpha, alpha). |
146 * | 151 * |
147 * @param alpha The alpha value to set as the color. | 152 * @param alpha The alpha value to set as the color. |
148 */ | 153 */ |
149 void setAlpha(uint8_t a) { this->setColor((a << 24) | (a << 16) | (a << 8) | a); } | 154 void setAlpha(uint8_t a) { this->setColor((a << 24) | (a << 16) | (a << 8) | a); } |
150 | 155 |
151 /// @} | 156 /// @} |
152 | 157 |
153 /////////////////////////////////////////////////////////////////////////// | 158 /////////////////////////////////////////////////////////////////////////// |
154 /// @name Coverage | 159 /// @name Coverage |
155 //// | 160 //// |
156 | 161 |
157 /** | 162 /** |
158 * Sets a constant fractional coverage to be applied to the draw. The | 163 * Sets a constant fractional coverage to be applied to the draw. The |
159 * initial value (after construction or reset()) is 0xff. The constant | 164 * initial value (after construction or reset()) is 0xff. The constant |
160 * coverage is ignored when per-vertex coverage is provided. | 165 * coverage is ignored when per-vertex coverage is provided. |
161 */ | 166 */ |
162 void setCoverage(uint8_t coverage) { | 167 void setCoverage(uint8_t coverage) { |
163 fCoverage = coverage; | 168 if (coverage != fCoverage) { |
164 this->invalidateBlendOptFlags(); | 169 fCoverage = coverage; |
170 this->invalidateOptState(); | |
171 } | |
165 } | 172 } |
166 | 173 |
167 /// @} | 174 /// @} |
168 | 175 |
169 /////////////////////////////////////////////////////////////////////////// | 176 /////////////////////////////////////////////////////////////////////////// |
170 /// @name Effect Stages | 177 /// @name Effect Stages |
171 /// Each stage hosts a GrEffect. The effect produces an output color or cove rage in the fragment | 178 /// Each stage hosts a GrEffect. The effect produces an output color or cove rage in the fragment |
172 /// shader. Its inputs are the output from the previous stage as well as som e variables | 179 /// shader. Its inputs are the output from the previous stage as well as som e variables |
173 /// available to it in the fragment and vertex shader (e.g. the vertex posit ion, the dst color, | 180 /// available to it in the fragment and vertex shader (e.g. the vertex posit ion, the dst color, |
174 /// the fragment position, local coordinates). | 181 /// the fragment position, local coordinates). |
175 /// | 182 /// |
176 /// The stages are divided into two sets, color-computing and coverage-compu ting. The final | 183 /// The stages are divided into two sets, color-computing and coverage-compu ting. The final |
177 /// color stage produces the final pixel color. The coverage-computing stage s function exactly | 184 /// color stage produces the final pixel color. The coverage-computing stage s function exactly |
178 /// as the color-computing but the output of the final coverage stage is tre ated as a fractional | 185 /// as the color-computing but the output of the final coverage stage is tre ated as a fractional |
179 /// pixel coverage rather than as input to the src/dst color blend step. | 186 /// pixel coverage rather than as input to the src/dst color blend step. |
180 /// | 187 /// |
181 /// The input color to the first color-stage is either the constant color or interpolated | 188 /// The input color to the first color-stage is either the constant color or interpolated |
182 /// per-vertex colors. The input to the first coverage stage is either a con stant coverage | 189 /// per-vertex colors. The input to the first coverage stage is either a con stant coverage |
183 /// (usually full-coverage) or interpolated per-vertex coverage. | 190 /// (usually full-coverage) or interpolated per-vertex coverage. |
184 /// | 191 /// |
185 /// See the documentation of kCoverageDrawing_StateBit for information about disabling the | 192 /// See the documentation of kCoverageDrawing_StateBit for information about disabling the |
186 /// the color / coverage distinction. | 193 /// the color / coverage distinction. |
187 //// | 194 //// |
188 | 195 |
189 const GrEffect* addColorEffect(const GrEffect* effect, int attr0 = -1, int a ttr1 = -1) { | 196 const GrEffect* addColorEffect(const GrEffect* effect, int attr0 = -1, int a ttr1 = -1) { |
190 SkASSERT(NULL != effect); | 197 SkASSERT(NULL != effect); |
191 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrEffectStage, (effect, attr0, att r1)); | 198 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrEffectStage, (effect, attr0, att r1)); |
192 this->invalidateBlendOptFlags(); | 199 this->invalidateOptState(); |
193 return effect; | 200 return effect; |
194 } | 201 } |
195 | 202 |
196 const GrEffect* addCoverageEffect(const GrEffect* effect, int attr0 = -1, in t attr1 = -1) { | 203 const GrEffect* addCoverageEffect(const GrEffect* effect, int attr0 = -1, in t attr1 = -1) { |
197 SkASSERT(NULL != effect); | 204 SkASSERT(NULL != effect); |
198 SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrEffectStage, (effect, attr0, attr1)); | 205 SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrEffectStage, (effect, attr0, attr1)); |
199 this->invalidateBlendOptFlags(); | 206 this->invalidateOptState(); |
200 return effect; | 207 return effect; |
201 } | 208 } |
202 | 209 |
203 /** | 210 /** |
204 * Creates a GrSimpleTextureEffect that uses local coords as texture coordin ates. | 211 * Creates a GrSimpleTextureEffect that uses local coords as texture coordin ates. |
205 */ | 212 */ |
206 void addColorTextureEffect(GrTexture* texture, const SkMatrix& matrix) { | 213 void addColorTextureEffect(GrTexture* texture, const SkMatrix& matrix) { |
207 this->addColorEffect(GrSimpleTextureEffect::Create(texture, matrix))->un ref(); | 214 this->addColorEffect(GrSimpleTextureEffect::Create(texture, matrix))->un ref(); |
208 } | 215 } |
209 | 216 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
260 * D' = sat(S*srcCoef + D*dstCoef) | 267 * D' = sat(S*srcCoef + D*dstCoef) |
261 * | 268 * |
262 * where D is the existing destination color, S is the incoming source | 269 * where D is the existing destination color, S is the incoming source |
263 * color, and D' is the new destination color that will be written. sat() | 270 * color, and D' is the new destination color that will be written. sat() |
264 * is the saturation function. | 271 * is the saturation function. |
265 * | 272 * |
266 * @param srcCoef coefficient applied to the src color. | 273 * @param srcCoef coefficient applied to the src color. |
267 * @param dstCoef coefficient applied to the dst color. | 274 * @param dstCoef coefficient applied to the dst color. |
268 */ | 275 */ |
269 void setBlendFunc(GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff) { | 276 void setBlendFunc(GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff) { |
270 fSrcBlend = srcCoeff; | 277 if (srcCoeff != fSrcBlend || dstCoeff != fDstBlend) { |
271 fDstBlend = dstCoeff; | 278 fSrcBlend = srcCoeff; |
272 this->invalidateBlendOptFlags(); | 279 fDstBlend = dstCoeff; |
280 this->invalidateOptState(); | |
281 } | |
273 #ifdef SK_DEBUG | 282 #ifdef SK_DEBUG |
274 if (GrBlendCoeffRefsDst(dstCoeff)) { | 283 if (GrBlendCoeffRefsDst(dstCoeff)) { |
275 GrPrintf("Unexpected dst blend coeff. Won't work correctly with cove rage stages.\n"); | 284 GrPrintf("Unexpected dst blend coeff. Won't work correctly with cove rage stages.\n"); |
276 } | 285 } |
277 if (GrBlendCoeffRefsSrc(srcCoeff)) { | 286 if (GrBlendCoeffRefsSrc(srcCoeff)) { |
278 GrPrintf("Unexpected src blend coeff. Won't work correctly with cove rage stages.\n"); | 287 GrPrintf("Unexpected src blend coeff. Won't work correctly with cove rage stages.\n"); |
279 } | 288 } |
280 #endif | 289 #endif |
281 } | 290 } |
282 | 291 |
283 /** | 292 /** |
284 * Sets the blending function constant referenced by the following blending | 293 * Sets the blending function constant referenced by the following blending |
285 * coefficients: | 294 * coefficients: |
286 * kConstC_GrBlendCoeff | 295 * kConstC_GrBlendCoeff |
287 * kIConstC_GrBlendCoeff | 296 * kIConstC_GrBlendCoeff |
288 * kConstA_GrBlendCoeff | 297 * kConstA_GrBlendCoeff |
289 * kIConstA_GrBlendCoeff | 298 * kIConstA_GrBlendCoeff |
290 * | 299 * |
291 * @param constant the constant to set | 300 * @param constant the constant to set |
292 */ | 301 */ |
293 void setBlendConstant(GrColor constant) { | 302 void setBlendConstant(GrColor constant) { |
294 fBlendConstant = constant; | 303 if (constant != fBlendConstant) { |
295 this->invalidateBlendOptFlags(); | 304 fBlendConstant = constant; |
305 this->invalidateOptState(); | |
306 } | |
296 } | 307 } |
297 | 308 |
298 /** | 309 /** |
299 * Determines what optimizations can be applied based on the blend. The coef ficients may have | 310 * Determines what optimizations can be applied based on the blend. The coef ficients may have |
300 * to be tweaked in order for the optimization to work. srcCoeff and dstCoef f are optional | 311 * to be tweaked in order for the optimization to work. srcCoeff and dstCoef f are optional |
301 * params that receive the tweaked coefficients. Normally the function looks at the current | 312 * params that receive the tweaked coefficients. Normally the function looks at the current |
302 * state to see if coverage is enabled. By setting forceCoverage the caller can speculatively | 313 * state to see if coverage is enabled. By setting forceCoverage the caller can speculatively |
303 * determine the blend optimizations that would be used if there was partial pixel coverage. | 314 * determine the blend optimizations that would be used if there was partial pixel coverage. |
304 * | 315 * |
305 * Subclasses of GrDrawTarget that actually draw (as opposed to those that j ust buffer for | 316 * Subclasses of GrDrawTarget that actually draw (as opposed to those that j ust buffer for |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
376 | 387 |
377 /////////////////////////////////////////////////////////////////////////// | 388 /////////////////////////////////////////////////////////////////////////// |
378 /// @name Render Target | 389 /// @name Render Target |
379 //// | 390 //// |
380 | 391 |
381 /** | 392 /** |
382 * Sets the render-target used at the next drawing call | 393 * Sets the render-target used at the next drawing call |
383 * | 394 * |
384 * @param target The render target to set. | 395 * @param target The render target to set. |
385 */ | 396 */ |
386 void setRenderTarget(GrRenderTarget* target) { fRenderTarget.reset(SkSafeRef (target)); } | 397 void setRenderTarget(GrRenderTarget* target) { |
398 fRenderTarget.reset(SkSafeRef(target)); | |
399 this->invalidateOptState(); | |
400 } | |
387 | 401 |
388 class AutoRenderTargetRestore : public ::SkNoncopyable { | 402 class AutoRenderTargetRestore : public ::SkNoncopyable { |
389 public: | 403 public: |
390 AutoRenderTargetRestore() : fDrawState(NULL), fSavedTarget(NULL) {} | 404 AutoRenderTargetRestore() : fDrawState(NULL), fSavedTarget(NULL) {} |
391 AutoRenderTargetRestore(GrDrawState* ds, GrRenderTarget* newTarget) { | 405 AutoRenderTargetRestore(GrDrawState* ds, GrRenderTarget* newTarget) { |
392 fDrawState = NULL; | 406 fDrawState = NULL; |
393 fSavedTarget = NULL; | 407 fSavedTarget = NULL; |
394 this->set(ds, newTarget); | 408 this->set(ds, newTarget); |
395 } | 409 } |
396 ~AutoRenderTargetRestore() { this->restore(); } | 410 ~AutoRenderTargetRestore() { this->restore(); } |
(...skipping 29 matching lines...) Expand all Loading... | |
426 //// | 440 //// |
427 | 441 |
428 /** | 442 /** |
429 * Sets the stencil settings to use for the next draw. | 443 * Sets the stencil settings to use for the next draw. |
430 * Changing the clip has the side-effect of possibly zeroing | 444 * Changing the clip has the side-effect of possibly zeroing |
431 * out the client settable stencil bits. So multipass algorithms | 445 * out the client settable stencil bits. So multipass algorithms |
432 * using stencil should not change the clip between passes. | 446 * using stencil should not change the clip between passes. |
433 * @param settings the stencil settings to use. | 447 * @param settings the stencil settings to use. |
434 */ | 448 */ |
435 void setStencil(const GrStencilSettings& settings) { | 449 void setStencil(const GrStencilSettings& settings) { |
436 fStencilSettings = settings; | 450 if (settings != fStencilSettings) { |
437 this->invalidateBlendOptFlags(); | 451 fStencilSettings = settings; |
452 this->invalidateOptState(); | |
453 } | |
438 } | 454 } |
439 | 455 |
440 /** | 456 /** |
441 * Shortcut to disable stencil testing and ops. | 457 * Shortcut to disable stencil testing and ops. |
442 */ | 458 */ |
443 void disableStencil() { | 459 void disableStencil() { |
444 fStencilSettings.setDisabled(); | 460 if (!fStencilSettings.isDisabled()) { |
445 this->invalidateBlendOptFlags(); | 461 fStencilSettings.setDisabled(); |
462 this->invalidateOptState(); | |
463 } | |
446 } | 464 } |
447 | 465 |
448 GrStencilSettings* stencil() { return &fStencilSettings; } | 466 GrStencilSettings* stencil() { return &fStencilSettings; } |
449 | 467 |
450 /// @} | 468 /// @} |
451 | 469 |
452 /////////////////////////////////////////////////////////////////////////// | 470 /////////////////////////////////////////////////////////////////////////// |
453 /// @name State Flags | 471 /// @name State Flags |
454 //// | 472 //// |
455 | 473 |
456 void resetStateFlags() { | 474 void resetStateFlags() { |
457 fFlagBits = 0; | 475 if (0 != fFlagBits) { |
458 this->invalidateBlendOptFlags(); | 476 fFlagBits = 0; |
477 this->invalidateOptState(); | |
478 } | |
459 } | 479 } |
460 | 480 |
461 /** | 481 /** |
462 * Enable render state settings. | 482 * Enable render state settings. |
463 * | 483 * |
464 * @param stateBits bitfield of StateBits specifying the states to enable | 484 * @param stateBits bitfield of StateBits specifying the states to enable |
465 */ | 485 */ |
466 void enableState(uint32_t stateBits) { | 486 void enableState(uint32_t stateBits) { |
467 fFlagBits |= stateBits; | 487 if (stateBits & ~fFlagBits) { |
468 this->invalidateBlendOptFlags(); | 488 fFlagBits |= stateBits; |
489 this->invalidateOptState(); | |
490 } | |
469 } | 491 } |
470 | 492 |
471 /** | 493 /** |
472 * Disable render state settings. | 494 * Disable render state settings. |
473 * | 495 * |
474 * @param stateBits bitfield of StateBits specifying the states to disable | 496 * @param stateBits bitfield of StateBits specifying the states to disable |
475 */ | 497 */ |
476 void disableState(uint32_t stateBits) { | 498 void disableState(uint32_t stateBits) { |
477 fFlagBits &= ~(stateBits); | 499 if (stateBits & fFlagBits) { |
478 this->invalidateBlendOptFlags(); | 500 fFlagBits &= ~(stateBits); |
501 this->invalidateOptState(); | |
502 } | |
479 } | 503 } |
480 | 504 |
481 /** | 505 /** |
482 * Enable or disable stateBits based on a boolean. | 506 * Enable or disable stateBits based on a boolean. |
483 * | 507 * |
484 * @param stateBits bitfield of StateBits to enable or disable | 508 * @param stateBits bitfield of StateBits to enable or disable |
485 * @param enable if true enable stateBits, otherwise disable | 509 * @param enable if true enable stateBits, otherwise disable |
486 */ | 510 */ |
487 void setState(uint32_t stateBits, bool enable) { | 511 void setState(uint32_t stateBits, bool enable) { |
488 if (enable) { | 512 if (enable) { |
(...skipping 22 matching lines...) Expand all Loading... | |
511 | 535 |
512 /////////////////////////////////////////////////////////////////////////// | 536 /////////////////////////////////////////////////////////////////////////// |
513 /// @name Hints | 537 /// @name Hints |
514 /// Hints that when provided can enable optimizations. | 538 /// Hints that when provided can enable optimizations. |
515 //// | 539 //// |
516 | 540 |
517 enum Hints { kVertexColorsAreOpaque_Hint = 0x1, }; | 541 enum Hints { kVertexColorsAreOpaque_Hint = 0x1, }; |
518 | 542 |
519 void setHint(Hints hint, bool value) { fHints = value ? (fHints | hint) : (f Hints & ~hint); } | 543 void setHint(Hints hint, bool value) { fHints = value ? (fHints | hint) : (f Hints & ~hint); } |
520 | 544 |
545 bool vertexColorsAreOpaque() const { return kVertexColorsAreOpaque_Hint & fH ints; } | |
546 | |
521 /// @} | 547 /// @} |
522 | 548 |
523 /////////////////////////////////////////////////////////////////////////// | 549 /////////////////////////////////////////////////////////////////////////// |
524 | 550 |
525 /** Return type for CombineIfPossible. */ | 551 /** Return type for CombineIfPossible. */ |
526 enum CombinedState { | 552 enum CombinedState { |
527 /** The GrDrawStates cannot be combined. */ | 553 /** The GrDrawStates cannot be combined. */ |
528 kIncompatible_CombinedState, | 554 kIncompatible_CombinedState, |
529 /** Either draw state can be used in place of the other. */ | 555 /** Either draw state can be used in place of the other. */ |
530 kAOrB_CombinedState, | 556 kAOrB_CombinedState, |
531 /** Use the first draw state. */ | 557 /** Use the first draw state. */ |
532 kA_CombinedState, | 558 kA_CombinedState, |
533 /** Use the second draw state. */ | 559 /** Use the second draw state. */ |
534 kB_CombinedState, | 560 kB_CombinedState, |
535 }; | 561 }; |
536 | 562 |
537 /** This function determines whether the GrDrawStates used for two draws can be combined into | 563 /** This function determines whether the GrDrawStates used for two draws can be combined into |
538 a single GrDrawState. This is used to avoid storing redundant GrDrawStat es and to determine | 564 a single GrDrawState. This is used to avoid storing redundant GrDrawStat es and to determine |
539 if draws can be batched. The return value indicates whether combining is possible and, if | 565 if draws can be batched. The return value indicates whether combining is possible and, if |
540 so, which of the two inputs should be used. */ | 566 so, which of the two inputs should be used. */ |
541 static CombinedState CombineIfPossible(const GrDrawState& a, const GrDrawSta te& b, | 567 static CombinedState CombineIfPossible(const GrDrawState& a, const GrDrawSta te& b, |
542 const GrDrawTargetCaps& caps); | 568 const GrDrawTargetCaps& caps); |
543 | 569 |
544 GrDrawState& operator= (const GrDrawState& that); | 570 GrDrawState& operator= (const GrDrawState& that); |
545 | 571 |
572 /** | |
573 * Returns a snapshot of the current optimized state. If the current drawSta te has a valid | |
574 * cached optimiezed state it will simply return a pointer to it otherwise i t will create a new | |
575 * GrOptDrawState. In all cases the GrOptDrawState is reffed and ownership i s given to the | |
576 * caller. | |
577 */ | |
578 GrOptDrawState* createOptState() const; | |
579 | |
546 private: | 580 private: |
581 void invalidateBlendOptFlags() const { | |
582 fBlendOptFlags = kInvalid_BlendOptFlag; | |
583 } | |
584 | |
585 void invalidateOptState() const { | |
586 SkSafeSetNull(fCachedOptState); | |
587 this->invalidateBlendOptFlags(); | |
588 } | |
589 | |
547 void onReset(const SkMatrix* initialViewMatrix); | 590 void onReset(const SkMatrix* initialViewMatrix); |
548 | 591 |
549 BlendOptFlags calcBlendOpts(bool forceCoverage = false, | 592 BlendOptFlags calcBlendOpts(bool forceCoverage = false, |
550 GrBlendCoeff* srcCoeff = NULL, | 593 GrBlendCoeff* srcCoeff = NULL, |
551 GrBlendCoeff* dstCoeff = NULL) const; | 594 GrBlendCoeff* dstCoeff = NULL) const; |
552 | 595 |
553 uint32_t fHints; | 596 uint32_t fHints; |
554 | 597 |
555 // Some of the auto restore objects assume that no effects are removed durin g their lifetime. | 598 // Some of the auto restore objects assume that no effects are removed durin g their lifetime. |
556 // This is used to assert that this condition holds. | 599 // This is used to assert that this condition holds. |
557 SkDEBUGCODE(int fBlockEffectRemovalCnt;) | 600 SkDEBUGCODE(int fBlockEffectRemovalCnt;) |
558 | 601 |
559 /** | 602 /** |
560 * Sets vertex attributes for next draw. | 603 * Sets vertex attributes for next draw. |
561 * | 604 * |
562 * @param attribs the array of vertex attributes to set. | 605 * @param attribs the array of vertex attributes to set. |
563 * @param count the number of attributes being set, limited to kMaxVer texAttribCnt. | 606 * @param count the number of attributes being set, limited to kMaxVer texAttribCnt. |
564 */ | 607 */ |
565 void setVertexAttribs(const GrVertexAttrib attribs[], int count); | 608 void setVertexAttribs(const GrVertexAttrib attribs[], int count); |
566 | 609 |
610 mutable GrOptDrawState* fCachedOptState; | |
611 | |
567 typedef GrRODrawState INHERITED; | 612 typedef GrRODrawState INHERITED; |
568 }; | 613 }; |
569 | 614 |
570 #endif | 615 #endif |
OLD | NEW |