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 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 /** | 86 /** |
| 87 * Depending on features available in the underlying 3D API and the color bl end mode requested | 87 * Depending on features available in the underlying 3D API and the color bl end mode requested |
| 88 * it may or may not be possible to correctly blend with fractional pixel co verage generated by | 88 * it may or may not be possible to correctly blend with fractional pixel co verage generated by |
| 89 * the fragment shader. | 89 * the fragment shader. |
| 90 * | 90 * |
| 91 * This function considers the current draw state and the draw target's capa bilities to | 91 * This function considers the current draw state and the draw target's capa bilities to |
| 92 * determine whether coverage can be handled correctly. This function assume s that the caller | 92 * determine whether coverage can be handled correctly. This function assume s that the caller |
| 93 * intends to specify fractional pixel coverage (via setCoverage(), through a coverage vertex | 93 * intends to specify fractional pixel coverage (via setCoverage(), through a coverage vertex |
| 94 * attribute, or a coverage effect) but may not have specified it yet. | 94 * attribute, or a coverage effect) but may not have specified it yet. |
| 95 */ | 95 */ |
| 96 bool couldApplyCoverage(const GrDrawTargetCaps& caps) const; | 96 bool couldApplyCoverage(GrColor color, GrColor coverage, const GrDrawTargetC aps& caps) const; |
|
bsalomon
2014/12/08 19:42:13
Do we really need the coverage field here? If some
joshualitt
2014/12/08 20:19:20
So, this function is called in context before we h
bsalomon
2014/12/08 20:28:15
Right that's why I think we should rephrase the qu
| |
| 97 | 97 |
| 98 /** | 98 /** |
| 99 * Determines whether the output coverage is guaranteed to be one for all pi xels hit by a draw. | 99 * Determines whether the output coverage is guaranteed to be one for all pi xels hit by a draw. |
| 100 */ | 100 */ |
| 101 bool hasSolidCoverage() const; | 101 bool hasSolidCoverage(GrColor coverage) const; |
|
bsalomon
2014/12/08 19:42:13
I assume this goes away when the GP outputs an inv
joshualitt
2014/12/08 20:19:20
I think so yes
| |
| 102 | 102 |
| 103 /** | 103 /** |
| 104 * This function returns true if the render target destination pixel values will be read for | 104 * This function returns true if the render target destination pixel values will be read for |
| 105 * blending during draw. | 105 * blending during draw. |
| 106 */ | 106 */ |
| 107 bool willBlendWithDst() const; | 107 bool willBlendWithDst(GrColor color, GrColor coverage) const; |
| 108 | 108 |
| 109 /// @} | 109 /// @} |
| 110 | 110 |
| 111 /////////////////////////////////////////////////////////////////////////// | |
| 112 /// @name Color | |
| 113 //// | |
| 114 | |
| 115 GrColor getColor() const { return fColor; } | |
| 116 | |
| 117 /** | |
| 118 * Sets color for next draw to a premultiplied-alpha color. | |
| 119 * | |
| 120 * @param color the color to set. | |
| 121 */ | |
| 122 void setColor(GrColor color) { | |
| 123 if (color != fColor) { | |
| 124 fColor = color; | |
| 125 fColorProcInfoValid = false; | |
| 126 } | |
| 127 } | |
| 128 | |
| 129 /** | |
| 130 * Sets the color to be used for the next draw to be | |
| 131 * (r,g,b,a) = (alpha, alpha, alpha, alpha). | |
| 132 * | |
| 133 * @param alpha The alpha value to set as the color. | |
| 134 */ | |
| 135 void setAlpha(uint8_t a) { this->setColor((a << 24) | (a << 16) | (a << 8) | a); } | |
| 136 | |
| 137 /// @} | |
| 138 | |
| 139 /////////////////////////////////////////////////////////////////////////// | |
| 140 /// @name Coverage | |
| 141 //// | |
| 142 | |
| 143 uint8_t getCoverage() const { return fCoverage; } | |
| 144 | |
| 145 GrColor getCoverageColor() const { | |
| 146 return GrColorPackRGBA(fCoverage, fCoverage, fCoverage, fCoverage); | |
| 147 } | |
| 148 | |
| 149 /** | |
| 150 * Sets a constant fractional coverage to be applied to the draw. The | |
| 151 * initial value (after construction or reset()) is 0xff. The constant | |
| 152 * coverage is ignored when per-vertex coverage is provided. | |
| 153 */ | |
| 154 void setCoverage(uint8_t coverage) { | |
| 155 if (coverage != fCoverage) { | |
| 156 fCoverage = coverage; | |
| 157 fCoverageProcInfoValid = false; | |
| 158 } | |
| 159 } | |
| 160 | |
| 161 /// @} | |
| 162 | |
| 163 /** | 111 /** |
| 164 * The geometry processor is the sole element of the skia pipeline which can use the vertex, | 112 * The geometry processor is the sole element of the skia pipeline which can use the vertex, |
| 165 * geometry, and tesselation shaders. The GP may also compute a coverage in its fragment shader | 113 * geometry, and tesselation shaders. The GP may also compute a coverage in its fragment shader |
| 166 * but is never put in the color processing pipeline. | 114 * but is never put in the color processing pipeline. |
| 167 */ | 115 */ |
| 168 | 116 |
| 169 const GrGeometryProcessor* setGeometryProcessor(const GrGeometryProcessor* g eometryProcessor) { | 117 const GrGeometryProcessor* setGeometryProcessor(const GrGeometryProcessor* g eometryProcessor) { |
| 170 SkASSERT(geometryProcessor); | 118 SkASSERT(geometryProcessor); |
| 171 SkASSERT(!this->hasGeometryProcessor()); | 119 SkASSERT(!this->hasGeometryProcessor()); |
| 172 fGeometryProcessor.reset(SkRef(geometryProcessor)); | 120 fGeometryProcessor.reset(SkRef(geometryProcessor)); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 const GrGeometryProcessor* getGeometryProcessor() const { return fGeometryPr ocessor.get(); } | 153 const GrGeometryProcessor* getGeometryProcessor() const { return fGeometryPr ocessor.get(); } |
| 206 | 154 |
| 207 const GrXPFactory* getXPFactory() const { return fXPFactory.get(); } | 155 const GrXPFactory* getXPFactory() const { return fXPFactory.get(); } |
| 208 | 156 |
| 209 const GrFragmentStage& getColorStage(int idx) const { return fColorStages[id x]; } | 157 const GrFragmentStage& getColorStage(int idx) const { return fColorStages[id x]; } |
| 210 const GrFragmentStage& getCoverageStage(int idx) const { return fCoverageSta ges[idx]; } | 158 const GrFragmentStage& getCoverageStage(int idx) const { return fCoverageSta ges[idx]; } |
| 211 | 159 |
| 212 /** | 160 /** |
| 213 * Checks whether any of the effects will read the dst pixel color. | 161 * Checks whether any of the effects will read the dst pixel color. |
| 214 */ | 162 */ |
| 215 bool willEffectReadDstColor() const; | 163 bool willEffectReadDstColor(GrColor color, GrColor coverage) const; |
|
bsalomon
2014/12/08 19:42:13
Add a TODO to remove this function once only XP ca
joshualitt
2014/12/08 20:19:20
Acknowledged.
| |
| 216 | 164 |
| 217 const GrFragmentProcessor* addColorProcessor(const GrFragmentProcessor* effe ct) { | 165 const GrFragmentProcessor* addColorProcessor(const GrFragmentProcessor* effe ct) { |
| 218 SkASSERT(effect); | 166 SkASSERT(effect); |
| 219 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrFragmentStage, (effect)); | 167 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrFragmentStage, (effect)); |
| 220 fColorProcInfoValid = false; | 168 fColorProcInfoValid = false; |
| 221 return effect; | 169 return effect; |
| 222 } | 170 } |
| 223 | 171 |
| 224 const GrFragmentProcessor* addCoverageProcessor(const GrFragmentProcessor* e ffect) { | 172 const GrFragmentProcessor* addCoverageProcessor(const GrFragmentProcessor* e ffect) { |
| 225 SkASSERT(effect); | 173 SkASSERT(effect); |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 667 | 615 |
| 668 /** | 616 /** |
| 669 * Determines what optimizations can be applied based on the blend. The coef ficients may have | 617 * 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 | 618 * 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 | 619 * 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 | 620 * 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. | 621 * determine the blend optimizations that would be used if there was partial pixel coverage. |
| 674 * | 622 * |
| 675 * This is used internally and when constructing a GrOptDrawState. | 623 * This is used internally and when constructing a GrOptDrawState. |
| 676 */ | 624 */ |
| 677 BlendOpt getBlendOpt(bool forceCoverage = false, | 625 BlendOpt getBlendOpt(GrColor color, |
| 626 GrColor coverage, | |
| 627 bool forceCoverage = false, | |
| 678 GrBlendCoeff* srcCoeff = NULL, | 628 GrBlendCoeff* srcCoeff = NULL, |
| 679 GrBlendCoeff* dstCoeff = NULL) const; | 629 GrBlendCoeff* dstCoeff = NULL) const; |
| 680 | 630 |
| 681 const GrProcOptInfo& colorProcInfo() const { | 631 const GrProcOptInfo& colorProcInfo(GrColor color) const { |
| 682 this->calcColorInvariantOutput(); | 632 this->calcColorInvariantOutput(color); |
| 683 return fColorProcInfo; | 633 return fColorProcInfo; |
| 684 } | 634 } |
| 685 | 635 |
| 686 const GrProcOptInfo& coverageProcInfo() const { | 636 const GrProcOptInfo& coverageProcInfo(GrColor coverage) const { |
| 687 this->calcCoverageInvariantOutput(); | 637 this->calcCoverageInvariantOutput(coverage); |
| 688 return fCoverageProcInfo; | 638 return fCoverageProcInfo; |
| 689 } | 639 } |
| 690 | 640 |
| 691 /** | 641 /** |
| 692 * Determines whether src alpha is guaranteed to be one for all src pixels | 642 * Determines whether src alpha is guaranteed to be one for all src pixels |
| 693 */ | 643 */ |
| 694 bool srcAlphaWillBeOne() const; | 644 bool srcAlphaWillBeOne(GrColor color, GrColor coverage) const; |
| 695 | 645 |
| 696 /** | 646 /** |
| 697 * If fColorProcInfoValid is false, function calculates the invariant output for the color | 647 * If fColorProcInfoValid is false, function calculates the invariant output for the color |
| 698 * stages and results are stored in fColorProcInfo. | 648 * stages and results are stored in fColorProcInfo. |
| 699 */ | 649 */ |
| 700 void calcColorInvariantOutput() const; | 650 void calcColorInvariantOutput(GrColor) const; |
| 701 | 651 |
| 702 /** | 652 /** |
| 703 * If fCoverageProcInfoValid is false, function calculates the invariant out put for the coverage | 653 * If fCoverageProcInfoValid is false, function calculates the invariant out put for the coverage |
| 704 * stages and results are stored in fCoverageProcInfo. | 654 * stages and results are stored in fCoverageProcInfo. |
| 705 */ | 655 */ |
| 706 void calcCoverageInvariantOutput() const; | 656 void calcCoverageInvariantOutput(GrColor) const; |
| 707 | 657 |
| 708 void onReset(const SkMatrix* initialViewMatrix); | 658 void onReset(const SkMatrix* initialViewMatrix); |
| 709 | 659 |
| 710 // Some of the auto restore objects assume that no effects are removed durin g their lifetime. | 660 // 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. | 661 // This is used to assert that this condition holds. |
| 712 SkDEBUGCODE(int fBlockEffectRemovalCnt;) | 662 SkDEBUGCODE(int fBlockEffectRemovalCnt;) |
| 713 | 663 |
| 714 typedef SkSTArray<4, GrFragmentStage> FragmentStageArray; | 664 typedef SkSTArray<4, GrFragmentStage> FragmentStageArray; |
| 715 | 665 |
| 716 SkAutoTUnref<GrRenderTarget> fRenderTarget; | 666 SkAutoTUnref<GrRenderTarget> fRenderTarget; |
| 717 GrColor fColor; | |
| 718 SkMatrix fViewMatrix; | 667 SkMatrix fViewMatrix; |
| 719 GrColor fBlendConstant; | 668 GrColor fBlendConstant; |
| 720 uint32_t fFlagBits; | 669 uint32_t fFlagBits; |
| 721 GrStencilSettings fStencilSettings; | 670 GrStencilSettings fStencilSettings; |
| 722 uint8_t fCoverage; | |
| 723 DrawFace fDrawFace; | 671 DrawFace fDrawFace; |
| 724 GrBlendCoeff fSrcBlend; | 672 GrBlendCoeff fSrcBlend; |
| 725 GrBlendCoeff fDstBlend; | 673 GrBlendCoeff fDstBlend; |
| 726 SkAutoTUnref<const GrGeometryProcessor> fGeometryProcessor; | 674 SkAutoTUnref<const GrGeometryProcessor> fGeometryProcessor; |
| 727 SkAutoTUnref<const GrXPFactory> fXPFactory; | 675 SkAutoTUnref<const GrXPFactory> fXPFactory; |
| 728 FragmentStageArray fColorStages; | 676 FragmentStageArray fColorStages; |
| 729 FragmentStageArray fCoverageStages; | 677 FragmentStageArray fCoverageStages; |
| 730 uint32_t fHints; | 678 uint32_t fHints; |
| 731 | 679 |
| 732 mutable GrProcOptInfo fColorProcInfo; | 680 mutable GrProcOptInfo fColorProcInfo; |
| 733 mutable GrProcOptInfo fCoverageProcInfo; | 681 mutable GrProcOptInfo fCoverageProcInfo; |
| 734 mutable bool fColorProcInfoValid; | 682 mutable bool fColorProcInfoValid; |
| 735 mutable bool fCoverageProcInfoValid; | 683 mutable bool fCoverageProcInfoValid; |
| 684 mutable GrColor fColorCache; | |
| 685 mutable GrColor fCoverageCache; | |
| 736 | 686 |
| 737 friend class GrOptDrawState; | 687 friend class GrOptDrawState; |
| 738 }; | 688 }; |
| 739 | 689 |
| 740 #endif | 690 #endif |
| OLD | NEW |