| 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 | 85 |
| 86 /// @} | 86 /// @} |
| 87 | 87 |
| 88 /** | 88 /** |
| 89 * Depending on features available in the underlying 3D API and the color bl
end mode requested | 89 * Depending on features available in the underlying 3D API and the color bl
end mode requested |
| 90 * it may or may not be possible to correctly blend with fractional pixel co
verage generated by | 90 * it may or may not be possible to correctly blend with fractional pixel co
verage generated by |
| 91 * the fragment shader. | 91 * the fragment shader. |
| 92 * | 92 * |
| 93 * This function considers the current draw state and the draw target's capa
bilities to | 93 * This function considers the current draw state and the draw target's capa
bilities to |
| 94 * determine whether coverage can be handled correctly. This function assume
s that the caller | 94 * determine whether coverage can be handled correctly. This function assume
s that the caller |
| 95 * intends to specify fractional pixel coverage (via setCoverage(), through
a coverage vertex | 95 * intends to specify fractional pixel coverage via a primitive processor bu
t may not have |
| 96 * attribute, or a coverage effect) but may not have specified it yet. | 96 * specified it yet. |
| 97 */ | 97 */ |
| 98 bool couldApplyCoverage(const GrDrawTargetCaps& caps) const; | 98 bool canUseFracCoveragePrimProc(GrColor color, const GrDrawTargetCaps& caps)
const; |
| 99 | 99 |
| 100 /** | 100 /** |
| 101 * Determines whether the output coverage is guaranteed to be one for all pi
xels hit by a draw. | 101 * Determines whether the output coverage is guaranteed to be one for all pi
xels hit by a draw. |
| 102 */ | 102 */ |
| 103 bool hasSolidCoverage() const; | 103 bool hasSolidCoverage(GrColor coverage) const; |
| 104 | 104 |
| 105 /** | 105 /** |
| 106 * This function returns true if the render target destination pixel values
will be read for | 106 * This function returns true if the render target destination pixel values
will be read for |
| 107 * blending during draw. | 107 * blending during draw. |
| 108 */ | 108 */ |
| 109 bool willBlendWithDst() const; | 109 bool willBlendWithDst(GrColor color, GrColor coverage) const; |
| 110 | 110 |
| 111 /// @} | 111 /// @} |
| 112 | 112 |
| 113 /////////////////////////////////////////////////////////////////////////// | |
| 114 /// @name Color | |
| 115 //// | |
| 116 | |
| 117 GrColor getColor() const { return fColor; } | |
| 118 | |
| 119 /** | |
| 120 * Sets color for next draw to a premultiplied-alpha color. | |
| 121 * | |
| 122 * @param color the color to set. | |
| 123 */ | |
| 124 void setColor(GrColor color) { | |
| 125 if (color != fColor) { | |
| 126 fColor = color; | |
| 127 fColorProcInfoValid = false; | |
| 128 } | |
| 129 } | |
| 130 | |
| 131 /** | |
| 132 * Sets the color to be used for the next draw to be | |
| 133 * (r,g,b,a) = (alpha, alpha, alpha, alpha). | |
| 134 * | |
| 135 * @param alpha The alpha value to set as the color. | |
| 136 */ | |
| 137 void setAlpha(uint8_t a) { this->setColor((a << 24) | (a << 16) | (a << 8) |
a); } | |
| 138 | |
| 139 /// @} | |
| 140 | |
| 141 /////////////////////////////////////////////////////////////////////////// | |
| 142 /// @name Coverage | |
| 143 //// | |
| 144 | |
| 145 uint8_t getCoverage() const { return fCoverage; } | |
| 146 | |
| 147 GrColor getCoverageColor() const { | |
| 148 return GrColorPackRGBA(fCoverage, fCoverage, fCoverage, fCoverage); | |
| 149 } | |
| 150 | |
| 151 /** | |
| 152 * Sets a constant fractional coverage to be applied to the draw. The | |
| 153 * initial value (after construction or reset()) is 0xff. The constant | |
| 154 * coverage is ignored when per-vertex coverage is provided. | |
| 155 */ | |
| 156 void setCoverage(uint8_t coverage) { | |
| 157 if (coverage != fCoverage) { | |
| 158 fCoverage = coverage; | |
| 159 fCoverageProcInfoValid = false; | |
| 160 } | |
| 161 } | |
| 162 | |
| 163 /// @} | |
| 164 | |
| 165 /** | 113 /** |
| 166 * The geometry processor is the sole element of the skia pipeline which can
use the vertex, | 114 * The geometry processor is the sole element of the skia pipeline which can
use the vertex, |
| 167 * geometry, and tesselation shaders. The GP may also compute a coverage in
its fragment shader | 115 * geometry, and tesselation shaders. The GP may also compute a coverage in
its fragment shader |
| 168 * but is never put in the color processing pipeline. | 116 * but is never put in the color processing pipeline. |
| 169 */ | 117 */ |
| 170 | 118 |
| 171 const GrGeometryProcessor* setGeometryProcessor(const GrGeometryProcessor* g
eometryProcessor) { | 119 const GrGeometryProcessor* setGeometryProcessor(const GrGeometryProcessor* g
eometryProcessor) { |
| 172 SkASSERT(geometryProcessor); | 120 SkASSERT(geometryProcessor); |
| 173 SkASSERT(!this->hasGeometryProcessor()); | 121 SkASSERT(!this->hasGeometryProcessor()); |
| 174 fGeometryProcessor.reset(SkRef(geometryProcessor)); | 122 fGeometryProcessor.reset(SkRef(geometryProcessor)); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 bool hasGeometryProcessor() const { return SkToBool(fGeometryProcessor.get()
); } | 154 bool hasGeometryProcessor() const { return SkToBool(fGeometryProcessor.get()
); } |
| 207 const GrGeometryProcessor* getGeometryProcessor() const { return fGeometryPr
ocessor.get(); } | 155 const GrGeometryProcessor* getGeometryProcessor() const { return fGeometryPr
ocessor.get(); } |
| 208 | 156 |
| 209 const GrXPFactory* getXPFactory() const { return fXPFactory.get(); } | 157 const GrXPFactory* getXPFactory() const { return fXPFactory.get(); } |
| 210 | 158 |
| 211 const GrFragmentStage& getColorStage(int idx) const { return fColorStages[id
x]; } | 159 const GrFragmentStage& getColorStage(int idx) const { return fColorStages[id
x]; } |
| 212 const GrFragmentStage& getCoverageStage(int idx) const { return fCoverageSta
ges[idx]; } | 160 const GrFragmentStage& getCoverageStage(int idx) const { return fCoverageSta
ges[idx]; } |
| 213 | 161 |
| 214 /** | 162 /** |
| 215 * Checks whether any of the effects will read the dst pixel color. | 163 * Checks whether any of the effects will read the dst pixel color. |
| 164 * TODO remove when we have an XP |
| 216 */ | 165 */ |
| 217 bool willEffectReadDstColor() const; | 166 bool willEffectReadDstColor(GrColor color, GrColor coverage) const; |
| 218 | 167 |
| 219 /** | 168 /** |
| 220 * The xfer processor factory. | 169 * The xfer processor factory. |
| 221 */ | 170 */ |
| 222 const GrXPFactory* setXPFactory(const GrXPFactory* xpFactory) { | 171 const GrXPFactory* setXPFactory(const GrXPFactory* xpFactory) { |
| 223 fXPFactory.reset(SkRef(xpFactory)); | 172 fXPFactory.reset(SkRef(xpFactory)); |
| 224 return xpFactory; | 173 return xpFactory; |
| 225 } | 174 } |
| 226 | 175 |
| 227 void setPorterDuffXPFactory(SkXfermode::Mode mode) { | 176 void setPorterDuffXPFactory(SkXfermode::Mode mode) { |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 | 550 |
| 602 /// @} | 551 /// @} |
| 603 | 552 |
| 604 /////////////////////////////////////////////////////////////////////////// | 553 /////////////////////////////////////////////////////////////////////////// |
| 605 | 554 |
| 606 GrDrawState& operator= (const GrDrawState& that); | 555 GrDrawState& operator= (const GrDrawState& that); |
| 607 | 556 |
| 608 private: | 557 private: |
| 609 bool isEqual(const GrDrawState& that) const; | 558 bool isEqual(const GrDrawState& that) const; |
| 610 | 559 |
| 611 const GrProcOptInfo& colorProcInfo() const { | 560 const GrProcOptInfo& colorProcInfo(GrColor color) const { |
| 612 this->calcColorInvariantOutput(); | 561 this->calcColorInvariantOutput(color); |
| 613 return fColorProcInfo; | 562 return fColorProcInfo; |
| 614 } | 563 } |
| 615 | 564 |
| 616 const GrProcOptInfo& coverageProcInfo() const { | 565 const GrProcOptInfo& coverageProcInfo(GrColor coverage) const { |
| 617 this->calcCoverageInvariantOutput(); | 566 this->calcCoverageInvariantOutput(coverage); |
| 618 return fCoverageProcInfo; | 567 return fCoverageProcInfo; |
| 619 } | 568 } |
| 620 | 569 |
| 621 /** | 570 /** |
| 622 * Determines whether src alpha is guaranteed to be one for all src pixels | 571 * Determines whether src alpha is guaranteed to be one for all src pixels |
| 623 */ | 572 */ |
| 624 bool srcAlphaWillBeOne() const; | 573 bool srcAlphaWillBeOne(GrColor color, GrColor coverage) const; |
| 625 | 574 |
| 626 /** | 575 /** |
| 627 * If fColorProcInfoValid is false, function calculates the invariant output
for the color | 576 * If fColorProcInfoValid is false, function calculates the invariant output
for the color |
| 628 * stages and results are stored in fColorProcInfo. | 577 * stages and results are stored in fColorProcInfo. |
| 629 */ | 578 */ |
| 630 void calcColorInvariantOutput() const; | 579 void calcColorInvariantOutput(GrColor) const; |
| 631 | 580 |
| 632 /** | 581 /** |
| 633 * If fCoverageProcInfoValid is false, function calculates the invariant out
put for the coverage | 582 * If fCoverageProcInfoValid is false, function calculates the invariant out
put for the coverage |
| 634 * stages and results are stored in fCoverageProcInfo. | 583 * stages and results are stored in fCoverageProcInfo. |
| 635 */ | 584 */ |
| 636 void calcCoverageInvariantOutput() const; | 585 void calcCoverageInvariantOutput(GrColor) const; |
| 637 | 586 |
| 638 void onReset(const SkMatrix* initialViewMatrix); | 587 void onReset(const SkMatrix* initialViewMatrix); |
| 639 | 588 |
| 640 // Some of the auto restore objects assume that no effects are removed durin
g their lifetime. | 589 // Some of the auto restore objects assume that no effects are removed durin
g their lifetime. |
| 641 // This is used to assert that this condition holds. | 590 // This is used to assert that this condition holds. |
| 642 SkDEBUGCODE(int fBlockEffectRemovalCnt;) | 591 SkDEBUGCODE(int fBlockEffectRemovalCnt;) |
| 643 | 592 |
| 644 typedef SkSTArray<4, GrFragmentStage> FragmentStageArray; | 593 typedef SkSTArray<4, GrFragmentStage> FragmentStageArray; |
| 645 | 594 |
| 646 SkAutoTUnref<GrRenderTarget> fRenderTarget; | 595 SkAutoTUnref<GrRenderTarget> fRenderTarget; |
| 647 GrColor fColor; | |
| 648 SkMatrix fViewMatrix; | 596 SkMatrix fViewMatrix; |
| 649 uint32_t fFlagBits; | 597 uint32_t fFlagBits; |
| 650 GrStencilSettings fStencilSettings; | 598 GrStencilSettings fStencilSettings; |
| 651 uint8_t fCoverage; | |
| 652 DrawFace fDrawFace; | 599 DrawFace fDrawFace; |
| 653 SkAutoTUnref<const GrGeometryProcessor> fGeometryProcessor; | 600 SkAutoTUnref<const GrGeometryProcessor> fGeometryProcessor; |
| 654 SkAutoTUnref<const GrXPFactory> fXPFactory; | 601 SkAutoTUnref<const GrXPFactory> fXPFactory; |
| 655 FragmentStageArray fColorStages; | 602 FragmentStageArray fColorStages; |
| 656 FragmentStageArray fCoverageStages; | 603 FragmentStageArray fCoverageStages; |
| 657 uint32_t fHints; | 604 uint32_t fHints; |
| 658 | 605 |
| 659 mutable GrProcOptInfo fColorProcInfo; | 606 mutable GrProcOptInfo fColorProcInfo; |
| 660 mutable GrProcOptInfo fCoverageProcInfo; | 607 mutable GrProcOptInfo fCoverageProcInfo; |
| 661 mutable bool fColorProcInfoValid; | 608 mutable bool fColorProcInfoValid; |
| 662 mutable bool fCoverageProcInfoValid; | 609 mutable bool fCoverageProcInfoValid; |
| 610 mutable GrColor fColorCache; |
| 611 mutable GrColor fCoverageCache; |
| 663 | 612 |
| 664 friend class GrOptDrawState; | 613 friend class GrOptDrawState; |
| 665 }; | 614 }; |
| 666 | 615 |
| 667 #endif | 616 #endif |
| OLD | NEW |