Chromium Code Reviews| 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 { | |
|
bsalomon
2014/09/15 14:04:34
w00t
| |
| 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 * Flag used to invalidate the cached BlendOptFlags, OptSrcCoeff, and Op tDstCoeff cached by | |
| 382 * the get BlendOpts function. | |
| 383 */ | |
| 384 kInvalid_BlendOptFlag = 1 << 31, | |
| 385 }; | |
| 386 GR_DECL_BITFIELD_OPS_FRIENDS(BlendOptFlags); | |
| 387 | |
| 388 /** | |
| 389 * Determines what optimizations can be applied based on the blend. The coef ficients may have | |
| 390 * to be tweaked in order for the optimization to work. srcCoeff and dstCoef f are optional | |
| 391 * params that receive the tweaked coefficients. Normally the function looks at the current | |
| 392 * state to see if coverage is enabled. By setting forceCoverage the caller can speculatively | |
| 393 * determine the blend optimizations that would be used if there was partial pixel coverage. | |
| 394 * | |
| 395 * Subclasses of GrDrawTarget that actually draw (as opposed to those that j ust buffer for | |
| 396 * playback) must call this function and respect the flags that replace the output color. | |
| 397 * | |
| 398 * If the cached BlendOptFlags does not have the invalidate bit set, then ge tBlendOpts will | |
| 399 * simply returned the cached flags and coefficients. Otherwise it will calc ulate the values. | |
| 400 */ | |
| 401 BlendOptFlags getBlendOpts(bool forceCoverage = false, | |
| 402 GrBlendCoeff* srcCoeff = NULL, | |
| 403 GrBlendCoeff* dstCoeff = NULL) const; | |
| 404 | |
| 410 // These fields are roughly sorted by decreasing likelihood of being differe nt in op== | 405 // These fields are roughly sorted by decreasing likelihood of being differe nt in op== |
| 411 GrProgramResource fRenderTarget; | 406 GrProgramResource fRenderTarget; |
| 412 GrColor fColor; | 407 GrColor fColor; |
| 413 SkMatrix fViewMatrix; | 408 SkMatrix fViewMatrix; |
| 414 GrColor fBlendConstant; | 409 GrColor fBlendConstant; |
| 415 uint32_t fFlagBits; | 410 uint32_t fFlagBits; |
| 416 const GrVertexAttrib* fVAPtr; | 411 const GrVertexAttrib* fVAPtr; |
| 417 int fVACount; | 412 int fVACount; |
| 418 size_t fVAStride; | 413 size_t fVAStride; |
| 419 GrStencilSettings fStencilSettings; | 414 GrStencilSettings fStencilSettings; |
| 420 uint8_t fCoverage; | 415 uint8_t fCoverage; |
| 421 DrawFace fDrawFace; | 416 DrawFace fDrawFace; |
| 422 GrBlendCoeff fSrcBlend; | 417 GrBlendCoeff fSrcBlend; |
| 423 GrBlendCoeff fDstBlend; | 418 GrBlendCoeff fDstBlend; |
| 424 | 419 |
| 425 typedef SkSTArray<4, GrEffectStage> EffectStageArray; | 420 typedef SkSTArray<4, GrEffectStage> EffectStageArray; |
| 426 SkAutoTDelete<GrEffectStage> fGeometryProcessor; | 421 SkAutoTDelete<GrEffectStage> fGeometryProcessor; |
| 427 EffectStageArray fColorStages; | 422 EffectStageArray fColorStages; |
| 428 EffectStageArray fCoverageStages; | 423 EffectStageArray fCoverageStages; |
| 429 | 424 |
| 430 uint32_t fHints; | 425 uint32_t fHints; |
| 431 | 426 |
| 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 | 427 // This is simply a different representation of info in fVertexAttribs and t hus does |
| 437 // not need to be compared in op==. | 428 // not need to be compared in op==. |
| 438 int fFixedFunctionVertexAttribIndices[kGrFixedFunctionVertexAttribBindingCnt ]; | 429 int fFixedFunctionVertexAttribIndices[kGrFixedFunctionVertexAttribBindingCnt ]; |
| 439 | 430 |
| 440 private: | 431 private: |
| 441 /** | 432 /** |
| 442 * Determines whether src alpha is guaranteed to be one for all src pixels | 433 * Determines whether src alpha is guaranteed to be one for all src pixels |
| 443 */ | 434 */ |
| 444 bool srcAlphaWillBeOne() const; | 435 bool srcAlphaWillBeOne() const; |
| 445 | 436 |
| 446 /** | 437 /** |
| 447 * Helper function for getBlendOpts. | 438 * Helper function for getBlendOpts. |
| 448 */ | 439 */ |
| 449 BlendOptFlags calcBlendOpts(bool forceCoverage = false, | 440 BlendOptFlags calcBlendOpts(bool forceCoverage = false, |
| 450 GrBlendCoeff* srcCoeff = NULL, | 441 GrBlendCoeff* srcCoeff = NULL, |
| 451 GrBlendCoeff* dstCoeff = NULL) const; | 442 GrBlendCoeff* dstCoeff = NULL) const; |
| 452 | 443 |
| 453 typedef SkRefCnt INHERITED; | 444 typedef SkRefCnt INHERITED; |
| 454 }; | 445 }; |
| 455 | 446 |
| 456 GR_MAKE_BITFIELD_OPS(GrRODrawState::BlendOptFlags); | 447 GR_MAKE_BITFIELD_OPS(GrRODrawState::BlendOptFlags); |
| 457 | 448 |
| 458 #endif | 449 #endif |
| OLD | NEW |