| 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 /** | |
| 294 * 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 | |
| 296 * 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 | |
| 298 * determine the blend optimizations that would be used if there was partial
pixel coverage. | |
| 299 * | |
| 300 * Subclasses of GrDrawTarget that actually draw (as opposed to those that j
ust buffer for | |
| 301 * playback) must call this function and respect the flags that replace the
output color. | |
| 302 * | |
| 303 * If the cached BlendOptFlags does not have the invalidate bit set, then ge
tBlendOpts will | |
| 304 * simply returned the cached flags and coefficients. Otherwise it will calc
ulate the values. | |
| 305 */ | |
| 306 BlendOptFlags getBlendOpts(bool forceCoverage = false, | |
| 307 GrBlendCoeff* srcCoeff = NULL, | |
| 308 GrBlendCoeff* dstCoeff = NULL) const; | |
| 309 | |
| 310 /** | |
| 311 * We don't use suplied vertex color attributes if our blend mode is EmitCov
erage or | |
| 312 * EmitTransBlack | |
| 313 */ | |
| 314 bool canIgnoreColorAttribute() const; | |
| 315 | |
| 316 | |
| 317 /// @} | 304 /// @} |
| 318 | 305 |
| 319 /////////////////////////////////////////////////////////////////////////// | 306 /////////////////////////////////////////////////////////////////////////// |
| 320 /// @name View Matrix | 307 /// @name View Matrix |
| 321 //// | 308 //// |
| 322 | 309 |
| 323 /** | 310 /** |
| 324 * Sets the view matrix to identity and updates any installed effects to com
pensate for the | 311 * Sets the view matrix to identity and updates any installed effects to com
pensate for the |
| 325 * coord system change. | 312 * coord system change. |
| 326 */ | 313 */ |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 | 354 |
| 368 /////////////////////////////////////////////////////////////////////////// | 355 /////////////////////////////////////////////////////////////////////////// |
| 369 /// @name Render Target | 356 /// @name Render Target |
| 370 //// | 357 //// |
| 371 | 358 |
| 372 /** | 359 /** |
| 373 * Sets the render-target used at the next drawing call | 360 * Sets the render-target used at the next drawing call |
| 374 * | 361 * |
| 375 * @param target The render target to set. | 362 * @param target The render target to set. |
| 376 */ | 363 */ |
| 377 void setRenderTarget(GrRenderTarget* target) { fRenderTarget.reset(SkSafeRef
(target)); } | 364 void setRenderTarget(GrRenderTarget* target) { |
| 365 fRenderTarget.reset(SkSafeRef(target)); |
| 366 this->invalidateOptState(); |
| 367 } |
| 378 | 368 |
| 379 class AutoRenderTargetRestore : public ::SkNoncopyable { | 369 class AutoRenderTargetRestore : public ::SkNoncopyable { |
| 380 public: | 370 public: |
| 381 AutoRenderTargetRestore() : fDrawState(NULL), fSavedTarget(NULL) {} | 371 AutoRenderTargetRestore() : fDrawState(NULL), fSavedTarget(NULL) {} |
| 382 AutoRenderTargetRestore(GrDrawState* ds, GrRenderTarget* newTarget) { | 372 AutoRenderTargetRestore(GrDrawState* ds, GrRenderTarget* newTarget) { |
| 383 fDrawState = NULL; | 373 fDrawState = NULL; |
| 384 fSavedTarget = NULL; | 374 fSavedTarget = NULL; |
| 385 this->set(ds, newTarget); | 375 this->set(ds, newTarget); |
| 386 } | 376 } |
| 387 ~AutoRenderTargetRestore() { this->restore(); } | 377 ~AutoRenderTargetRestore() { this->restore(); } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 417 //// | 407 //// |
| 418 | 408 |
| 419 /** | 409 /** |
| 420 * Sets the stencil settings to use for the next draw. | 410 * Sets the stencil settings to use for the next draw. |
| 421 * Changing the clip has the side-effect of possibly zeroing | 411 * Changing the clip has the side-effect of possibly zeroing |
| 422 * out the client settable stencil bits. So multipass algorithms | 412 * out the client settable stencil bits. So multipass algorithms |
| 423 * using stencil should not change the clip between passes. | 413 * using stencil should not change the clip between passes. |
| 424 * @param settings the stencil settings to use. | 414 * @param settings the stencil settings to use. |
| 425 */ | 415 */ |
| 426 void setStencil(const GrStencilSettings& settings) { | 416 void setStencil(const GrStencilSettings& settings) { |
| 427 fStencilSettings = settings; | 417 if (settings != fStencilSettings) { |
| 428 this->invalidateBlendOptFlags(); | 418 fStencilSettings = settings; |
| 419 this->invalidateOptState(); |
| 420 } |
| 429 } | 421 } |
| 430 | 422 |
| 431 /** | 423 /** |
| 432 * Shortcut to disable stencil testing and ops. | 424 * Shortcut to disable stencil testing and ops. |
| 433 */ | 425 */ |
| 434 void disableStencil() { | 426 void disableStencil() { |
| 435 fStencilSettings.setDisabled(); | 427 if (!fStencilSettings.isDisabled()) { |
| 436 this->invalidateBlendOptFlags(); | 428 fStencilSettings.setDisabled(); |
| 429 this->invalidateOptState(); |
| 430 } |
| 437 } | 431 } |
| 438 | 432 |
| 439 GrStencilSettings* stencil() { return &fStencilSettings; } | 433 GrStencilSettings* stencil() { return &fStencilSettings; } |
| 440 | 434 |
| 441 /// @} | 435 /// @} |
| 442 | 436 |
| 443 /////////////////////////////////////////////////////////////////////////// | 437 /////////////////////////////////////////////////////////////////////////// |
| 444 /// @name State Flags | 438 /// @name State Flags |
| 445 //// | 439 //// |
| 446 | 440 |
| 447 void resetStateFlags() { | 441 void resetStateFlags() { |
| 448 fFlagBits = 0; | 442 if (0 != fFlagBits) { |
| 449 this->invalidateBlendOptFlags(); | 443 fFlagBits = 0; |
| 444 this->invalidateOptState(); |
| 445 } |
| 450 } | 446 } |
| 451 | 447 |
| 452 /** | 448 /** |
| 453 * Enable render state settings. | 449 * Enable render state settings. |
| 454 * | 450 * |
| 455 * @param stateBits bitfield of StateBits specifying the states to enable | 451 * @param stateBits bitfield of StateBits specifying the states to enable |
| 456 */ | 452 */ |
| 457 void enableState(uint32_t stateBits) { | 453 void enableState(uint32_t stateBits) { |
| 458 fFlagBits |= stateBits; | 454 if (stateBits & ~fFlagBits) { |
| 459 this->invalidateBlendOptFlags(); | 455 fFlagBits |= stateBits; |
| 456 this->invalidateOptState(); |
| 457 } |
| 460 } | 458 } |
| 461 | 459 |
| 462 /** | 460 /** |
| 463 * Disable render state settings. | 461 * Disable render state settings. |
| 464 * | 462 * |
| 465 * @param stateBits bitfield of StateBits specifying the states to disable | 463 * @param stateBits bitfield of StateBits specifying the states to disable |
| 466 */ | 464 */ |
| 467 void disableState(uint32_t stateBits) { | 465 void disableState(uint32_t stateBits) { |
| 468 fFlagBits &= ~(stateBits); | 466 if (stateBits & fFlagBits) { |
| 469 this->invalidateBlendOptFlags(); | 467 fFlagBits &= ~(stateBits); |
| 468 this->invalidateOptState(); |
| 469 } |
| 470 } | 470 } |
| 471 | 471 |
| 472 /** | 472 /** |
| 473 * Enable or disable stateBits based on a boolean. | 473 * Enable or disable stateBits based on a boolean. |
| 474 * | 474 * |
| 475 * @param stateBits bitfield of StateBits to enable or disable | 475 * @param stateBits bitfield of StateBits to enable or disable |
| 476 * @param enable if true enable stateBits, otherwise disable | 476 * @param enable if true enable stateBits, otherwise disable |
| 477 */ | 477 */ |
| 478 void setState(uint32_t stateBits, bool enable) { | 478 void setState(uint32_t stateBits, bool enable) { |
| 479 if (enable) { | 479 if (enable) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 498 fDrawFace = face; | 498 fDrawFace = face; |
| 499 } | 499 } |
| 500 | 500 |
| 501 /// @} | 501 /// @} |
| 502 | 502 |
| 503 /////////////////////////////////////////////////////////////////////////// | 503 /////////////////////////////////////////////////////////////////////////// |
| 504 /// @name Hints | 504 /// @name Hints |
| 505 /// Hints that when provided can enable optimizations. | 505 /// Hints that when provided can enable optimizations. |
| 506 //// | 506 //// |
| 507 | 507 |
| 508 enum Hints { kVertexColorsAreOpaque_Hint = 0x1, }; | |
| 509 | |
| 510 void setHint(Hints hint, bool value) { fHints = value ? (fHints | hint) : (f
Hints & ~hint); } | 508 void setHint(Hints hint, bool value) { fHints = value ? (fHints | hint) : (f
Hints & ~hint); } |
| 511 | 509 |
| 512 /// @} | 510 /// @} |
| 513 | 511 |
| 514 /////////////////////////////////////////////////////////////////////////// | 512 /////////////////////////////////////////////////////////////////////////// |
| 515 | 513 |
| 516 /** Return type for CombineIfPossible. */ | 514 /** Return type for CombineIfPossible. */ |
| 517 enum CombinedState { | 515 enum CombinedState { |
| 518 /** The GrDrawStates cannot be combined. */ | 516 /** The GrDrawStates cannot be combined. */ |
| 519 kIncompatible_CombinedState, | 517 kIncompatible_CombinedState, |
| 520 /** Either draw state can be used in place of the other. */ | 518 /** Either draw state can be used in place of the other. */ |
| 521 kAOrB_CombinedState, | 519 kAOrB_CombinedState, |
| 522 /** Use the first draw state. */ | 520 /** Use the first draw state. */ |
| 523 kA_CombinedState, | 521 kA_CombinedState, |
| 524 /** Use the second draw state. */ | 522 /** Use the second draw state. */ |
| 525 kB_CombinedState, | 523 kB_CombinedState, |
| 526 }; | 524 }; |
| 527 | 525 |
| 528 /** This function determines whether the GrDrawStates used for two draws can
be combined into | 526 /** 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 | 527 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 | 528 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. */ | 529 so, which of the two inputs should be used. */ |
| 532 static CombinedState CombineIfPossible(const GrDrawState& a, const GrDrawSta
te& b, | 530 static CombinedState CombineIfPossible(const GrDrawState& a, const GrDrawSta
te& b, |
| 533 const GrDrawTargetCaps& caps); | 531 const GrDrawTargetCaps& caps); |
| 534 | 532 |
| 535 GrDrawState& operator= (const GrDrawState& that); | 533 GrDrawState& operator= (const GrDrawState& that); |
| 536 | 534 |
| 535 /** |
| 536 * Returns a snapshot of the current optimized state. If the current drawSta
te has a valid |
| 537 * cached optimiezed state it will simply return a pointer to it otherwise i
t will create a new |
| 538 * GrOptDrawState. In all cases the GrOptDrawState is reffed and ownership i
s given to the |
| 539 * caller. |
| 540 */ |
| 541 GrOptDrawState* createOptState() const; |
| 542 |
| 537 private: | 543 private: |
| 544 void invalidateBlendOptFlags() const { |
| 545 fBlendOptFlags = kInvalid_BlendOptFlag; |
| 546 } |
| 547 |
| 548 void invalidateOptState() const { |
| 549 SkSafeSetNull(fCachedOptState); |
| 550 this->invalidateBlendOptFlags(); |
| 551 } |
| 552 |
| 538 void onReset(const SkMatrix* initialViewMatrix); | 553 void onReset(const SkMatrix* initialViewMatrix); |
| 539 | 554 |
| 540 /** | |
| 541 * Determines whether src alpha is guaranteed to be one for all src pixels | |
| 542 */ | |
| 543 bool srcAlphaWillBeOne() const; | |
| 544 | |
| 545 /** | |
| 546 * Helper function for getBlendOpts. | |
| 547 */ | |
| 548 BlendOptFlags calcBlendOpts(bool forceCoverage = false, | |
| 549 GrBlendCoeff* srcCoeff = NULL, | |
| 550 GrBlendCoeff* dstCoeff = NULL) const; | |
| 551 | |
| 552 void invalidateBlendOptFlags() { | 555 void invalidateBlendOptFlags() { |
| 553 fBlendOptFlags = kInvalid_BlendOptFlag; | 556 fBlendOptFlags = kInvalid_BlendOptFlag; |
| 554 } | 557 } |
| 555 | 558 |
| 556 uint32_t fHints; | |
| 557 | |
| 558 // Some of the auto restore objects assume that no effects are removed durin
g their lifetime. | 559 // Some of the auto restore objects assume that no effects are removed durin
g their lifetime. |
| 559 // This is used to assert that this condition holds. | 560 // This is used to assert that this condition holds. |
| 560 SkDEBUGCODE(int fBlockEffectRemovalCnt;) | 561 SkDEBUGCODE(int fBlockEffectRemovalCnt;) |
| 561 | 562 |
| 562 /** | 563 /** |
| 563 * Sets vertex attributes for next draw. | 564 * Sets vertex attributes for next draw. |
| 564 * | 565 * |
| 565 * @param attribs the array of vertex attributes to set. | 566 * @param attribs the array of vertex attributes to set. |
| 566 * @param count the number of attributes being set, limited to kMaxVer
texAttribCnt. | 567 * @param count the number of attributes being set, limited to kMaxVer
texAttribCnt. |
| 567 */ | 568 */ |
| 568 void setVertexAttribs(const GrVertexAttrib attribs[], int count); | 569 void setVertexAttribs(const GrVertexAttrib attribs[], int count); |
| 569 | 570 |
| 571 mutable GrOptDrawState* fCachedOptState; |
| 572 |
| 570 typedef GrRODrawState INHERITED; | 573 typedef GrRODrawState INHERITED; |
| 571 }; | 574 }; |
| 572 | 575 |
| 573 #endif | 576 #endif |
| OLD | NEW |