Chromium Code Reviews| 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 | |
| 235 | |
|
bsalomon
2014/12/08 15:38:51
extra \n
egdaniel
2014/12/08 16:24:01
Done.
| |
| 217 const GrFragmentProcessor* addColorProcessor(const GrFragmentProcessor* effe ct) { | 236 const GrFragmentProcessor* addColorProcessor(const GrFragmentProcessor* effe ct) { |
| 218 SkASSERT(effect); | 237 SkASSERT(effect); |
| 219 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrFragmentStage, (effect)); | 238 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrFragmentStage, (effect)); |
| 220 fColorProcInfoValid = false; | 239 fColorProcInfoValid = false; |
| 221 return effect; | 240 return effect; |
| 222 } | 241 } |
| 223 | 242 |
| 224 const GrFragmentProcessor* addCoverageProcessor(const GrFragmentProcessor* e ffect) { | 243 const GrFragmentProcessor* addCoverageProcessor(const GrFragmentProcessor* e ffect) { |
| 225 SkASSERT(effect); | 244 SkASSERT(effect); |
| 226 SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrFragmentStage, (effect)); | 245 SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrFragmentStage, (effect)); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 325 GrDrawState* fDrawState; | 344 GrDrawState* fDrawState; |
| 326 GrStencilSettings fStencilSettings; | 345 GrStencilSettings fStencilSettings; |
| 327 }; | 346 }; |
| 328 | 347 |
| 329 /// @} | 348 /// @} |
| 330 | 349 |
| 331 /////////////////////////////////////////////////////////////////////////// | 350 /////////////////////////////////////////////////////////////////////////// |
| 332 /// @name Blending | 351 /// @name Blending |
| 333 //// | 352 //// |
| 334 | 353 |
| 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 /** | 354 /** |
| 345 * Determines whether multiplying the computed per-pixel color by the pixel' s fractional | 355 * 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 | 356 * coverage before the blend will give the correct final destination color. In general it |
| 347 * will not as coverage is applied after blending. | 357 * will not as coverage is applied after blending. |
| 348 */ | 358 */ |
| 349 bool canTweakAlphaForCoverage() const; | 359 bool canTweakAlphaForCoverage() const; |
| 350 | 360 |
| 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 /// @} | 361 /// @} |
| 390 | 362 |
| 391 /////////////////////////////////////////////////////////////////////////// | 363 /////////////////////////////////////////////////////////////////////////// |
| 392 /// @name View Matrix | 364 /// @name View Matrix |
| 393 //// | 365 //// |
| 394 | 366 |
| 395 /** | 367 /** |
| 396 * Retrieves the current view matrix | 368 * Retrieves the current view matrix |
| 397 * @return the current view matrix. | 369 * @return the current view matrix. |
| 398 */ | 370 */ |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 630 | 602 |
| 631 /// @} | 603 /// @} |
| 632 | 604 |
| 633 /////////////////////////////////////////////////////////////////////////// | 605 /////////////////////////////////////////////////////////////////////////// |
| 634 | 606 |
| 635 GrDrawState& operator= (const GrDrawState& that); | 607 GrDrawState& operator= (const GrDrawState& that); |
| 636 | 608 |
| 637 private: | 609 private: |
| 638 bool isEqual(const GrDrawState& that) const; | 610 bool isEqual(const GrDrawState& that) const; |
| 639 | 611 |
| 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 { | 612 const GrProcOptInfo& colorProcInfo() const { |
| 682 this->calcColorInvariantOutput(); | 613 this->calcColorInvariantOutput(); |
| 683 return fColorProcInfo; | 614 return fColorProcInfo; |
| 684 } | 615 } |
| 685 | 616 |
| 686 const GrProcOptInfo& coverageProcInfo() const { | 617 const GrProcOptInfo& coverageProcInfo() const { |
| 687 this->calcCoverageInvariantOutput(); | 618 this->calcCoverageInvariantOutput(); |
| 688 return fCoverageProcInfo; | 619 return fCoverageProcInfo; |
| 689 } | 620 } |
| 690 | 621 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 709 | 640 |
| 710 // Some of the auto restore objects assume that no effects are removed durin g their lifetime. | 641 // 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. | 642 // This is used to assert that this condition holds. |
| 712 SkDEBUGCODE(int fBlockEffectRemovalCnt;) | 643 SkDEBUGCODE(int fBlockEffectRemovalCnt;) |
| 713 | 644 |
| 714 typedef SkSTArray<4, GrFragmentStage> FragmentStageArray; | 645 typedef SkSTArray<4, GrFragmentStage> FragmentStageArray; |
| 715 | 646 |
| 716 SkAutoTUnref<GrRenderTarget> fRenderTarget; | 647 SkAutoTUnref<GrRenderTarget> fRenderTarget; |
| 717 GrColor fColor; | 648 GrColor fColor; |
| 718 SkMatrix fViewMatrix; | 649 SkMatrix fViewMatrix; |
| 719 GrColor fBlendConstant; | |
| 720 uint32_t fFlagBits; | 650 uint32_t fFlagBits; |
| 721 GrStencilSettings fStencilSettings; | 651 GrStencilSettings fStencilSettings; |
| 722 uint8_t fCoverage; | 652 uint8_t fCoverage; |
| 723 DrawFace fDrawFace; | 653 DrawFace fDrawFace; |
| 724 GrBlendCoeff fSrcBlend; | |
| 725 GrBlendCoeff fDstBlend; | |
| 726 SkAutoTUnref<const GrGeometryProcessor> fGeometryProcessor; | 654 SkAutoTUnref<const GrGeometryProcessor> fGeometryProcessor; |
| 727 SkAutoTUnref<const GrXPFactory> fXPFactory; | 655 SkAutoTUnref<const GrXPFactory> fXPFactory; |
| 728 FragmentStageArray fColorStages; | 656 FragmentStageArray fColorStages; |
| 729 FragmentStageArray fCoverageStages; | 657 FragmentStageArray fCoverageStages; |
| 730 uint32_t fHints; | 658 uint32_t fHints; |
| 731 | 659 |
| 732 mutable GrProcOptInfo fColorProcInfo; | 660 mutable GrProcOptInfo fColorProcInfo; |
| 733 mutable GrProcOptInfo fCoverageProcInfo; | 661 mutable GrProcOptInfo fCoverageProcInfo; |
| 734 mutable bool fColorProcInfoValid; | 662 mutable bool fColorProcInfoValid; |
| 735 mutable bool fCoverageProcInfoValid; | 663 mutable bool fCoverageProcInfoValid; |
| 736 | 664 |
| 737 friend class GrOptDrawState; | 665 friend class GrOptDrawState; |
| 738 }; | 666 }; |
| 739 | 667 |
| 740 #endif | 668 #endif |
| OLD | NEW |