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