| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrRODrawState_DEFINED | 8 #ifndef GrRODrawState_DEFINED |
| 9 #define GrRODrawState_DEFINED | 9 #define GrRODrawState_DEFINED |
| 10 | 10 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 *dstBlendCoeff = fDstBlend; | 160 *dstBlendCoeff = fDstBlend; |
| 161 } | 161 } |
| 162 | 162 |
| 163 /** | 163 /** |
| 164 * Retrieves the last value set by setBlendConstant() | 164 * Retrieves the last value set by setBlendConstant() |
| 165 * @return the blending constant value | 165 * @return the blending constant value |
| 166 */ | 166 */ |
| 167 GrColor getBlendConstant() const { return fBlendConstant; } | 167 GrColor getBlendConstant() const { return fBlendConstant; } |
| 168 | 168 |
| 169 /** | 169 /** |
| 170 * We don't use supplied vertex color attributes if our blend mode is EmitCo
verage or | |
| 171 * EmitTransBlack | |
| 172 */ | |
| 173 bool canIgnoreColorAttribute() const; | |
| 174 | |
| 175 /** | |
| 176 * Determines whether multiplying the computed per-pixel color by the pixel'
s fractional | 170 * Determines whether multiplying the computed per-pixel color by the pixel'
s fractional |
| 177 * coverage before the blend will give the correct final destination color.
In general it | 171 * coverage before the blend will give the correct final destination color.
In general it |
| 178 * will not as coverage is applied after blending. | 172 * will not as coverage is applied after blending. |
| 179 */ | 173 */ |
| 180 bool canTweakAlphaForCoverage() const; | 174 bool canTweakAlphaForCoverage() const; |
| 181 | 175 |
| 182 /** | |
| 183 * Optimizations for blending / coverage to that can be applied based on the
current state. | |
| 184 */ | |
| 185 enum BlendOptFlags { | |
| 186 /** | |
| 187 * No optimization | |
| 188 */ | |
| 189 kNone_BlendOpt = 0, | |
| 190 /** | |
| 191 * Don't draw at all | |
| 192 */ | |
| 193 kSkipDraw_BlendOptFlag = 0x1, | |
| 194 /** | |
| 195 * The coverage value does not have to be computed separately from alpha
, the output | |
| 196 * color can be the modulation of the two. | |
| 197 */ | |
| 198 kCoverageAsAlpha_BlendOptFlag = 0x2, | |
| 199 /** | |
| 200 * Instead of emitting a src color, emit coverage in the alpha channel a
nd r,g,b are | |
| 201 * "don't cares". | |
| 202 */ | |
| 203 kEmitCoverage_BlendOptFlag = 0x4, | |
| 204 /** | |
| 205 * Emit transparent black instead of the src color, no need to compute c
overage. | |
| 206 */ | |
| 207 kEmitTransBlack_BlendOptFlag = 0x8, | |
| 208 /** | |
| 209 * Flag used to invalidate the cached BlendOptFlags, OptSrcCoeff, and Op
tDstCoeff cached by | |
| 210 * the get BlendOpts function. | |
| 211 */ | |
| 212 kInvalid_BlendOptFlag = 1 << 31, | |
| 213 }; | |
| 214 GR_DECL_BITFIELD_OPS_FRIENDS(BlendOptFlags); | |
| 215 | |
| 216 /** | |
| 217 * Determines what optimizations can be applied based on the blend. The coef
ficients may have | |
| 218 * to be tweaked in order for the optimization to work. srcCoeff and dstCoef
f are optional | |
| 219 * params that receive the tweaked coefficients. Normally the function looks
at the current | |
| 220 * state to see if coverage is enabled. By setting forceCoverage the caller
can speculatively | |
| 221 * determine the blend optimizations that would be used if there was partial
pixel coverage. | |
| 222 * | |
| 223 * Subclasses of GrDrawTarget that actually draw (as opposed to those that j
ust buffer for | |
| 224 * playback) must call this function and respect the flags that replace the
output color. | |
| 225 * | |
| 226 * If the cached BlendOptFlags does not have the invalidate bit set, then ge
tBlendOpts will | |
| 227 * simply returned the cached flags and coefficients. Otherwise it will calc
ulate the values. | |
| 228 */ | |
| 229 BlendOptFlags getBlendOpts(bool forceCoverage = false, | |
| 230 GrBlendCoeff* srcCoeff = NULL, | |
| 231 GrBlendCoeff* dstCoeff = NULL) const; | |
| 232 /// @} | 176 /// @} |
| 233 | 177 |
| 234 /////////////////////////////////////////////////////////////////////////// | 178 /////////////////////////////////////////////////////////////////////////// |
| 235 /// @name View Matrix | 179 /// @name View Matrix |
| 236 //// | 180 //// |
| 237 | 181 |
| 238 /** | 182 /** |
| 239 * Retrieves the current view matrix | 183 * Retrieves the current view matrix |
| 240 * @return the current view matrix. | 184 * @return the current view matrix. |
| 241 */ | 185 */ |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 * an optimized draw state. | 344 * an optimized draw state. |
| 401 */ | 345 */ |
| 402 void convertToPendingExec(); | 346 void convertToPendingExec(); |
| 403 | 347 |
| 404 friend class GrDrawTarget; | 348 friend class GrDrawTarget; |
| 405 | 349 |
| 406 explicit GrRODrawState(const GrRODrawState& drawState); | 350 explicit GrRODrawState(const GrRODrawState& drawState); |
| 407 | 351 |
| 408 bool isEqual(const GrRODrawState& that) const; | 352 bool isEqual(const GrRODrawState& that) const; |
| 409 | 353 |
| 354 /** |
| 355 * Optimizations for blending / coverage to that can be applied based on the
current state. |
| 356 */ |
| 357 enum BlendOptFlags { |
| 358 /** |
| 359 * No optimization |
| 360 */ |
| 361 kNone_BlendOpt = 0, |
| 362 /** |
| 363 * Don't draw at all |
| 364 */ |
| 365 kSkipDraw_BlendOptFlag = 0x1, |
| 366 /** |
| 367 * The coverage value does not have to be computed separately from alpha
, the the output |
| 368 * color can be the modulation of the two. |
| 369 */ |
| 370 kCoverageAsAlpha_BlendOptFlag = 0x2, |
| 371 /** |
| 372 * Instead of emitting a src color, emit coverage in the alpha channel a
nd r,g,b are |
| 373 * "don't cares". |
| 374 */ |
| 375 kEmitCoverage_BlendOptFlag = 0x4, |
| 376 /** |
| 377 * Emit transparent black instead of the src color, no need to compute c
overage. |
| 378 */ |
| 379 kEmitTransBlack_BlendOptFlag = 0x8, |
| 380 }; |
| 381 GR_DECL_BITFIELD_OPS_FRIENDS(BlendOptFlags); |
| 382 |
| 383 /** |
| 384 * Determines what optimizations can be applied based on the blend. The coef
ficients may have |
| 385 * to be tweaked in order for the optimization to work. srcCoeff and dstCoef
f are optional |
| 386 * params that receive the tweaked coefficients. Normally the function looks
at the current |
| 387 * state to see if coverage is enabled. By setting forceCoverage the caller
can speculatively |
| 388 * determine the blend optimizations that would be used if there was partial
pixel coverage. |
| 389 * |
| 390 * Subclasses of GrDrawTarget that actually draw (as opposed to those that j
ust buffer for |
| 391 * playback) must call this function and respect the flags that replace the
output color. |
| 392 * |
| 393 * If the cached BlendOptFlags does not have the invalidate bit set, then ge
tBlendOpts will |
| 394 * simply returned the cached flags and coefficients. Otherwise it will calc
ulate the values. |
| 395 */ |
| 396 BlendOptFlags getBlendOpts(bool forceCoverage = false, |
| 397 GrBlendCoeff* srcCoeff = NULL, |
| 398 GrBlendCoeff* dstCoeff = NULL) const; |
| 399 |
| 410 // These fields are roughly sorted by decreasing likelihood of being differe
nt in op== | 400 // These fields are roughly sorted by decreasing likelihood of being differe
nt in op== |
| 411 GrProgramResource fRenderTarget; | 401 GrProgramResource fRenderTarget; |
| 412 GrColor fColor; | 402 GrColor fColor; |
| 413 SkMatrix fViewMatrix; | 403 SkMatrix fViewMatrix; |
| 414 GrColor fBlendConstant; | 404 GrColor fBlendConstant; |
| 415 uint32_t fFlagBits; | 405 uint32_t fFlagBits; |
| 416 const GrVertexAttrib* fVAPtr; | 406 const GrVertexAttrib* fVAPtr; |
| 417 int fVACount; | 407 int fVACount; |
| 418 size_t fVAStride; | 408 size_t fVAStride; |
| 419 GrStencilSettings fStencilSettings; | 409 GrStencilSettings fStencilSettings; |
| 420 uint8_t fCoverage; | 410 uint8_t fCoverage; |
| 421 DrawFace fDrawFace; | 411 DrawFace fDrawFace; |
| 422 GrBlendCoeff fSrcBlend; | 412 GrBlendCoeff fSrcBlend; |
| 423 GrBlendCoeff fDstBlend; | 413 GrBlendCoeff fDstBlend; |
| 424 | 414 |
| 425 typedef SkSTArray<4, GrEffectStage> EffectStageArray; | 415 typedef SkSTArray<4, GrEffectStage> EffectStageArray; |
| 426 SkAutoTDelete<GrEffectStage> fGeometryProcessor; | 416 SkAutoTDelete<GrEffectStage> fGeometryProcessor; |
| 427 EffectStageArray fColorStages; | 417 EffectStageArray fColorStages; |
| 428 EffectStageArray fCoverageStages; | 418 EffectStageArray fCoverageStages; |
| 429 | 419 |
| 430 uint32_t fHints; | 420 uint32_t fHints; |
| 431 | 421 |
| 432 mutable GrBlendCoeff fOptSrcBlend; | |
| 433 mutable GrBlendCoeff fOptDstBlend; | |
| 434 mutable BlendOptFlags fBlendOptFlags; | |
| 435 | |
| 436 // This is simply a different representation of info in fVertexAttribs and t
hus does | 422 // This is simply a different representation of info in fVertexAttribs and t
hus does |
| 437 // not need to be compared in op==. | 423 // not need to be compared in op==. |
| 438 int fFixedFunctionVertexAttribIndices[kGrFixedFunctionVertexAttribBindingCnt
]; | 424 int fFixedFunctionVertexAttribIndices[kGrFixedFunctionVertexAttribBindingCnt
]; |
| 439 | 425 |
| 440 private: | 426 private: |
| 441 /** | 427 /** |
| 442 * Determines whether src alpha is guaranteed to be one for all src pixels | 428 * Determines whether src alpha is guaranteed to be one for all src pixels |
| 443 */ | 429 */ |
| 444 bool srcAlphaWillBeOne() const; | 430 bool srcAlphaWillBeOne() const; |
| 445 | 431 |
| 446 /** | |
| 447 * Helper function for getBlendOpts. | |
| 448 */ | |
| 449 BlendOptFlags calcBlendOpts(bool forceCoverage = false, | |
| 450 GrBlendCoeff* srcCoeff = NULL, | |
| 451 GrBlendCoeff* dstCoeff = NULL) const; | |
| 452 | |
| 453 typedef SkRefCnt INHERITED; | 432 typedef SkRefCnt INHERITED; |
| 454 }; | 433 }; |
| 455 | 434 |
| 456 GR_MAKE_BITFIELD_OPS(GrRODrawState::BlendOptFlags); | 435 GR_MAKE_BITFIELD_OPS(GrRODrawState::BlendOptFlags); |
| 457 | 436 |
| 458 #endif | 437 #endif |
| OLD | NEW |