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" |
21 #include "effects/GrSimpleTextureEffect.h" | 22 #include "effects/GrSimpleTextureEffect.h" |
22 | 23 |
23 class GrDrawTargetCaps; | 24 class GrDrawTargetCaps; |
24 class GrPaint; | 25 class GrPaint; |
25 class GrTexture; | 26 class GrTexture; |
26 | 27 |
27 class GrDrawState { | 28 class GrDrawState { |
28 public: | 29 public: |
29 GrDrawState() { | 30 GrDrawState() { |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 const GrXPFactory* getXPFactory() const { return fXPFactory.get(); } | 208 const GrXPFactory* getXPFactory() const { return fXPFactory.get(); } |
208 | 209 |
209 const GrFragmentStage& getColorStage(int idx) const { return fColorStages[id
x]; } | 210 const GrFragmentStage& getColorStage(int idx) const { return fColorStages[id
x]; } |
210 const GrFragmentStage& getCoverageStage(int idx) const { return fCoverageSta
ges[idx]; } | 211 const GrFragmentStage& getCoverageStage(int idx) const { return fCoverageSta
ges[idx]; } |
211 | 212 |
212 /** | 213 /** |
213 * Checks whether any of the effects will read the dst pixel color. | 214 * Checks whether any of the effects will read the dst pixel color. |
214 */ | 215 */ |
215 bool willEffectReadDstColor() const; | 216 bool willEffectReadDstColor() const; |
216 | 217 |
| 218 /** |
| 219 * The xfer processor factory. |
| 220 */ |
| 221 const GrXPFactory* setXPFactory(const GrXPFactory* xpFactory) { |
| 222 fXPFactory.reset(SkRef(xpFactory)); |
| 223 return xpFactory; |
| 224 } |
| 225 |
217 const GrFragmentProcessor* addColorProcessor(const GrFragmentProcessor* effe
ct) { | 226 const GrFragmentProcessor* addColorProcessor(const GrFragmentProcessor* effe
ct) { |
218 SkASSERT(effect); | 227 SkASSERT(effect); |
219 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrFragmentStage, (effect)); | 228 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrFragmentStage, (effect)); |
220 fColorProcInfoValid = false; | 229 fColorProcInfoValid = false; |
221 return effect; | 230 return effect; |
222 } | 231 } |
223 | 232 |
224 const GrFragmentProcessor* addCoverageProcessor(const GrFragmentProcessor* e
ffect) { | 233 const GrFragmentProcessor* addCoverageProcessor(const GrFragmentProcessor* e
ffect) { |
225 SkASSERT(effect); | 234 SkASSERT(effect); |
226 SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrFragmentStage, (effect)); | 235 SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrFragmentStage, (effect)); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 GrDrawState* fDrawState; | 334 GrDrawState* fDrawState; |
326 GrStencilSettings fStencilSettings; | 335 GrStencilSettings fStencilSettings; |
327 }; | 336 }; |
328 | 337 |
329 /// @} | 338 /// @} |
330 | 339 |
331 /////////////////////////////////////////////////////////////////////////// | 340 /////////////////////////////////////////////////////////////////////////// |
332 /// @name Blending | 341 /// @name Blending |
333 //// | 342 //// |
334 | 343 |
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 /** | 344 /** |
345 * Determines whether multiplying the computed per-pixel color by the pixel'
s fractional | 345 * 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 | 346 * coverage before the blend will give the correct final destination color.
In general it |
347 * will not as coverage is applied after blending. | 347 * will not as coverage is applied after blending. |
348 */ | 348 */ |
349 bool canTweakAlphaForCoverage() const; | 349 bool canTweakAlphaForCoverage() const; |
350 | 350 |
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 /// @} | 351 /// @} |
390 | 352 |
391 /////////////////////////////////////////////////////////////////////////// | 353 /////////////////////////////////////////////////////////////////////////// |
392 /// @name View Matrix | 354 /// @name View Matrix |
393 //// | 355 //// |
394 | 356 |
395 /** | 357 /** |
396 * Retrieves the current view matrix | 358 * Retrieves the current view matrix |
397 * @return the current view matrix. | 359 * @return the current view matrix. |
398 */ | 360 */ |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 | 592 |
631 /// @} | 593 /// @} |
632 | 594 |
633 /////////////////////////////////////////////////////////////////////////// | 595 /////////////////////////////////////////////////////////////////////////// |
634 | 596 |
635 GrDrawState& operator= (const GrDrawState& that); | 597 GrDrawState& operator= (const GrDrawState& that); |
636 | 598 |
637 private: | 599 private: |
638 bool isEqual(const GrDrawState& that) const; | 600 bool isEqual(const GrDrawState& that) const; |
639 | 601 |
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 { | 602 const GrProcOptInfo& colorProcInfo() const { |
682 this->calcColorInvariantOutput(); | 603 this->calcColorInvariantOutput(); |
683 return fColorProcInfo; | 604 return fColorProcInfo; |
684 } | 605 } |
685 | 606 |
686 const GrProcOptInfo& coverageProcInfo() const { | 607 const GrProcOptInfo& coverageProcInfo() const { |
687 this->calcCoverageInvariantOutput(); | 608 this->calcCoverageInvariantOutput(); |
688 return fCoverageProcInfo; | 609 return fCoverageProcInfo; |
689 } | 610 } |
690 | 611 |
(...skipping 18 matching lines...) Expand all Loading... |
709 | 630 |
710 // Some of the auto restore objects assume that no effects are removed durin
g their lifetime. | 631 // 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. | 632 // This is used to assert that this condition holds. |
712 SkDEBUGCODE(int fBlockEffectRemovalCnt;) | 633 SkDEBUGCODE(int fBlockEffectRemovalCnt;) |
713 | 634 |
714 typedef SkSTArray<4, GrFragmentStage> FragmentStageArray; | 635 typedef SkSTArray<4, GrFragmentStage> FragmentStageArray; |
715 | 636 |
716 SkAutoTUnref<GrRenderTarget> fRenderTarget; | 637 SkAutoTUnref<GrRenderTarget> fRenderTarget; |
717 GrColor fColor; | 638 GrColor fColor; |
718 SkMatrix fViewMatrix; | 639 SkMatrix fViewMatrix; |
719 GrColor fBlendConstant; | |
720 uint32_t fFlagBits; | 640 uint32_t fFlagBits; |
721 GrStencilSettings fStencilSettings; | 641 GrStencilSettings fStencilSettings; |
722 uint8_t fCoverage; | 642 uint8_t fCoverage; |
723 DrawFace fDrawFace; | 643 DrawFace fDrawFace; |
724 GrBlendCoeff fSrcBlend; | |
725 GrBlendCoeff fDstBlend; | |
726 SkAutoTUnref<const GrGeometryProcessor> fGeometryProcessor; | 644 SkAutoTUnref<const GrGeometryProcessor> fGeometryProcessor; |
727 SkAutoTUnref<const GrXPFactory> fXPFactory; | 645 SkAutoTUnref<const GrXPFactory> fXPFactory; |
728 FragmentStageArray fColorStages; | 646 FragmentStageArray fColorStages; |
729 FragmentStageArray fCoverageStages; | 647 FragmentStageArray fCoverageStages; |
730 uint32_t fHints; | 648 uint32_t fHints; |
731 | 649 |
732 mutable GrProcOptInfo fColorProcInfo; | 650 mutable GrProcOptInfo fColorProcInfo; |
733 mutable GrProcOptInfo fCoverageProcInfo; | 651 mutable GrProcOptInfo fCoverageProcInfo; |
734 mutable bool fColorProcInfoValid; | 652 mutable bool fColorProcInfoValid; |
735 mutable bool fCoverageProcInfoValid; | 653 mutable bool fCoverageProcInfoValid; |
736 | 654 |
737 friend class GrOptDrawState; | 655 friend class GrOptDrawState; |
738 }; | 656 }; |
739 | 657 |
740 #endif | 658 #endif |
OLD | NEW |