| 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 | 11 |
| 12 #include "GrBlend.h" | 12 #include "GrBlend.h" |
| 13 #include "GrDrawTargetCaps.h" | 13 #include "GrDrawTargetCaps.h" |
| 14 #include "GrGeometryProcessor.h" | 14 #include "GrGeometryProcessor.h" |
| 15 #include "GrGpuResourceRef.h" | 15 #include "GrGpuResourceRef.h" |
| 16 #include "GrFragmentStage.h" | 16 #include "GrFragmentStage.h" |
| 17 #include "GrProcOptInfo.h" | 17 #include "GrProcOptInfo.h" |
| 18 #include "GrRenderTarget.h" | 18 #include "GrRenderTarget.h" |
| 19 #include "GrStencil.h" | 19 #include "GrStencil.h" |
| 20 #include "GrXferProcessor.h" |
| 20 #include "SkMatrix.h" | 21 #include "SkMatrix.h" |
| 22 #include "effects/GrPorterDuffXferProcessor.h" |
| 21 #include "effects/GrSimpleTextureEffect.h" | 23 #include "effects/GrSimpleTextureEffect.h" |
| 22 | 24 |
| 23 class GrDrawTargetCaps; | 25 class GrDrawTargetCaps; |
| 24 class GrPaint; | 26 class GrPaint; |
| 25 class GrTexture; | 27 class GrTexture; |
| 26 | 28 |
| 27 class GrDrawState { | 29 class GrDrawState { |
| 28 public: | 30 public: |
| 29 GrDrawState() { | 31 GrDrawState() { |
| 30 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) | 32 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 const GrXPFactory* getXPFactory() const { return fXPFactory.get(); } | 209 const GrXPFactory* getXPFactory() const { return fXPFactory.get(); } |
| 208 | 210 |
| 209 const GrFragmentStage& getColorStage(int idx) const { return fColorStages[id
x]; } | 211 const GrFragmentStage& getColorStage(int idx) const { return fColorStages[id
x]; } |
| 210 const GrFragmentStage& getCoverageStage(int idx) const { return fCoverageSta
ges[idx]; } | 212 const GrFragmentStage& getCoverageStage(int idx) const { return fCoverageSta
ges[idx]; } |
| 211 | 213 |
| 212 /** | 214 /** |
| 213 * Checks whether any of the effects will read the dst pixel color. | 215 * Checks whether any of the effects will read the dst pixel color. |
| 214 */ | 216 */ |
| 215 bool willEffectReadDstColor() const; | 217 bool willEffectReadDstColor() const; |
| 216 | 218 |
| 219 /** |
| 220 * The xfer processor factory. |
| 221 */ |
| 222 const GrXPFactory* setXPFactory(const GrXPFactory* xpFactory) { |
| 223 fXPFactory.reset(SkRef(xpFactory)); |
| 224 return xpFactory; |
| 225 } |
| 226 |
| 227 void setPorterDuffXPFactory(SkXfermode::Mode mode) { |
| 228 fXPFactory.reset(GrPorterDuffXPFactory::Create(mode)); |
| 229 } |
| 230 |
| 231 void setPorterDuffXPFactory(GrBlendCoeff src, GrBlendCoeff dst) { |
| 232 fXPFactory.reset(GrPorterDuffXPFactory::Create(src, dst)); |
| 233 } |
| 234 |
| 217 const GrFragmentProcessor* addColorProcessor(const GrFragmentProcessor* effe
ct) { | 235 const GrFragmentProcessor* addColorProcessor(const GrFragmentProcessor* effe
ct) { |
| 218 SkASSERT(effect); | 236 SkASSERT(effect); |
| 219 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrFragmentStage, (effect)); | 237 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrFragmentStage, (effect)); |
| 220 fColorProcInfoValid = false; | 238 fColorProcInfoValid = false; |
| 221 return effect; | 239 return effect; |
| 222 } | 240 } |
| 223 | 241 |
| 224 const GrFragmentProcessor* addCoverageProcessor(const GrFragmentProcessor* e
ffect) { | 242 const GrFragmentProcessor* addCoverageProcessor(const GrFragmentProcessor* e
ffect) { |
| 225 SkASSERT(effect); | 243 SkASSERT(effect); |
| 226 SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrFragmentStage, (effect)); | 244 SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrFragmentStage, (effect)); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 GrDrawState* fDrawState; | 343 GrDrawState* fDrawState; |
| 326 GrStencilSettings fStencilSettings; | 344 GrStencilSettings fStencilSettings; |
| 327 }; | 345 }; |
| 328 | 346 |
| 329 /// @} | 347 /// @} |
| 330 | 348 |
| 331 /////////////////////////////////////////////////////////////////////////// | 349 /////////////////////////////////////////////////////////////////////////// |
| 332 /// @name Blending | 350 /// @name Blending |
| 333 //// | 351 //// |
| 334 | 352 |
| 335 GrBlendCoeff getSrcBlendCoeff() const { return fSrcBlend; } | |
| 336 GrBlendCoeff getDstBlendCoeff() const { return fDstBlend; } | |
| 337 | |
| 338 /** | |
| 339 * Retrieves the last value set by setBlendConstant() | |
| 340 * @return the blending constant value | |
| 341 */ | |
| 342 GrColor getBlendConstant() const { return fBlendConstant; } | |
| 343 | |
| 344 /** | 353 /** |
| 345 * Determines whether multiplying the computed per-pixel color by the pixel'
s fractional | 354 * Determines whether multiplying the computed per-pixel color by the pixel'
s fractional |
| 346 * coverage before the blend will give the correct final destination color.
In general it | 355 * coverage before the blend will give the correct final destination color.
In general it |
| 347 * will not as coverage is applied after blending. | 356 * will not as coverage is applied after blending. |
| 348 */ | 357 */ |
| 349 bool canTweakAlphaForCoverage() const; | 358 bool canTweakAlphaForCoverage() const; |
| 350 | 359 |
| 351 /** | |
| 352 * Sets the blending function coefficients. | |
| 353 * | |
| 354 * The blend function will be: | |
| 355 * D' = sat(S*srcCoef + D*dstCoef) | |
| 356 * | |
| 357 * where D is the existing destination color, S is the incoming source | |
| 358 * color, and D' is the new destination color that will be written. sat() | |
| 359 * is the saturation function. | |
| 360 * | |
| 361 * @param srcCoef coefficient applied to the src color. | |
| 362 * @param dstCoef coefficient applied to the dst color. | |
| 363 */ | |
| 364 void setBlendFunc(GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff) { | |
| 365 fSrcBlend = srcCoeff; | |
| 366 fDstBlend = dstCoeff; | |
| 367 #ifdef SK_DEBUG | |
| 368 if (GrBlendCoeffRefsDst(dstCoeff)) { | |
| 369 SkDebugf("Unexpected dst blend coeff. Won't work correctly with cove
rage stages.\n"); | |
| 370 } | |
| 371 if (GrBlendCoeffRefsSrc(srcCoeff)) { | |
| 372 SkDebugf("Unexpected src blend coeff. Won't work correctly with cove
rage stages.\n"); | |
| 373 } | |
| 374 #endif | |
| 375 } | |
| 376 | |
| 377 /** | |
| 378 * Sets the blending function constant referenced by the following blending | |
| 379 * coefficients: | |
| 380 * kConstC_GrBlendCoeff | |
| 381 * kIConstC_GrBlendCoeff | |
| 382 * kConstA_GrBlendCoeff | |
| 383 * kIConstA_GrBlendCoeff | |
| 384 * | |
| 385 * @param constant the constant to set | |
| 386 */ | |
| 387 void setBlendConstant(GrColor constant) { fBlendConstant = constant; } | |
| 388 | |
| 389 /// @} | 360 /// @} |
| 390 | 361 |
| 391 /////////////////////////////////////////////////////////////////////////// | 362 /////////////////////////////////////////////////////////////////////////// |
| 392 /// @name View Matrix | 363 /// @name View Matrix |
| 393 //// | 364 //// |
| 394 | 365 |
| 395 /** | 366 /** |
| 396 * Retrieves the current view matrix | 367 * Retrieves the current view matrix |
| 397 * @return the current view matrix. | 368 * @return the current view matrix. |
| 398 */ | 369 */ |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 | 601 |
| 631 /// @} | 602 /// @} |
| 632 | 603 |
| 633 /////////////////////////////////////////////////////////////////////////// | 604 /////////////////////////////////////////////////////////////////////////// |
| 634 | 605 |
| 635 GrDrawState& operator= (const GrDrawState& that); | 606 GrDrawState& operator= (const GrDrawState& that); |
| 636 | 607 |
| 637 private: | 608 private: |
| 638 bool isEqual(const GrDrawState& that) const; | 609 bool isEqual(const GrDrawState& that) const; |
| 639 | 610 |
| 640 /** | |
| 641 * Optimizations for blending / coverage to that can be applied based on the
current state. | |
| 642 */ | |
| 643 enum BlendOpt { | |
| 644 /** | |
| 645 * No optimization | |
| 646 */ | |
| 647 kNone_BlendOpt, | |
| 648 /** | |
| 649 * Don't draw at all | |
| 650 */ | |
| 651 kSkipDraw_BlendOpt, | |
| 652 /** | |
| 653 * The coverage value does not have to be computed separately from alpha
, the the output | |
| 654 * color can be the modulation of the two. | |
| 655 */ | |
| 656 kCoverageAsAlpha_BlendOpt, | |
| 657 /** | |
| 658 * Instead of emitting a src color, emit coverage in the alpha channel a
nd r,g,b are | |
| 659 * "don't cares". | |
| 660 */ | |
| 661 kEmitCoverage_BlendOpt, | |
| 662 /** | |
| 663 * Emit transparent black instead of the src color, no need to compute c
overage. | |
| 664 */ | |
| 665 kEmitTransBlack_BlendOpt | |
| 666 }; | |
| 667 | |
| 668 /** | |
| 669 * Determines what optimizations can be applied based on the blend. The coef
ficients may have | |
| 670 * to be tweaked in order for the optimization to work. srcCoeff and dstCoef
f are optional | |
| 671 * params that receive the tweaked coefficients. Normally the function looks
at the current | |
| 672 * state to see if coverage is enabled. By setting forceCoverage the caller
can speculatively | |
| 673 * determine the blend optimizations that would be used if there was partial
pixel coverage. | |
| 674 * | |
| 675 * This is used internally and when constructing a GrOptDrawState. | |
| 676 */ | |
| 677 BlendOpt getBlendOpt(bool forceCoverage = false, | |
| 678 GrBlendCoeff* srcCoeff = NULL, | |
| 679 GrBlendCoeff* dstCoeff = NULL) const; | |
| 680 | |
| 681 const GrProcOptInfo& colorProcInfo() const { | 611 const GrProcOptInfo& colorProcInfo() const { |
| 682 this->calcColorInvariantOutput(); | 612 this->calcColorInvariantOutput(); |
| 683 return fColorProcInfo; | 613 return fColorProcInfo; |
| 684 } | 614 } |
| 685 | 615 |
| 686 const GrProcOptInfo& coverageProcInfo() const { | 616 const GrProcOptInfo& coverageProcInfo() const { |
| 687 this->calcCoverageInvariantOutput(); | 617 this->calcCoverageInvariantOutput(); |
| 688 return fCoverageProcInfo; | 618 return fCoverageProcInfo; |
| 689 } | 619 } |
| 690 | 620 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 709 | 639 |
| 710 // Some of the auto restore objects assume that no effects are removed durin
g their lifetime. | 640 // Some of the auto restore objects assume that no effects are removed durin
g their lifetime. |
| 711 // This is used to assert that this condition holds. | 641 // This is used to assert that this condition holds. |
| 712 SkDEBUGCODE(int fBlockEffectRemovalCnt;) | 642 SkDEBUGCODE(int fBlockEffectRemovalCnt;) |
| 713 | 643 |
| 714 typedef SkSTArray<4, GrFragmentStage> FragmentStageArray; | 644 typedef SkSTArray<4, GrFragmentStage> FragmentStageArray; |
| 715 | 645 |
| 716 SkAutoTUnref<GrRenderTarget> fRenderTarget; | 646 SkAutoTUnref<GrRenderTarget> fRenderTarget; |
| 717 GrColor fColor; | 647 GrColor fColor; |
| 718 SkMatrix fViewMatrix; | 648 SkMatrix fViewMatrix; |
| 719 GrColor fBlendConstant; | |
| 720 uint32_t fFlagBits; | 649 uint32_t fFlagBits; |
| 721 GrStencilSettings fStencilSettings; | 650 GrStencilSettings fStencilSettings; |
| 722 uint8_t fCoverage; | 651 uint8_t fCoverage; |
| 723 DrawFace fDrawFace; | 652 DrawFace fDrawFace; |
| 724 GrBlendCoeff fSrcBlend; | |
| 725 GrBlendCoeff fDstBlend; | |
| 726 SkAutoTUnref<const GrGeometryProcessor> fGeometryProcessor; | 653 SkAutoTUnref<const GrGeometryProcessor> fGeometryProcessor; |
| 727 SkAutoTUnref<const GrXPFactory> fXPFactory; | 654 SkAutoTUnref<const GrXPFactory> fXPFactory; |
| 728 FragmentStageArray fColorStages; | 655 FragmentStageArray fColorStages; |
| 729 FragmentStageArray fCoverageStages; | 656 FragmentStageArray fCoverageStages; |
| 730 uint32_t fHints; | 657 uint32_t fHints; |
| 731 | 658 |
| 732 mutable GrProcOptInfo fColorProcInfo; | 659 mutable GrProcOptInfo fColorProcInfo; |
| 733 mutable GrProcOptInfo fCoverageProcInfo; | 660 mutable GrProcOptInfo fCoverageProcInfo; |
| 734 mutable bool fColorProcInfoValid; | 661 mutable bool fColorProcInfoValid; |
| 735 mutable bool fCoverageProcInfoValid; | 662 mutable bool fCoverageProcInfoValid; |
| 736 | 663 |
| 737 friend class GrOptDrawState; | 664 friend class GrOptDrawState; |
| 738 }; | 665 }; |
| 739 | 666 |
| 740 #endif | 667 #endif |
| OLD | NEW |