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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 void reset(const SkMatrix& initialViewMatrix) { this->onReset(&initialViewMa
trix); } | 61 void reset(const SkMatrix& initialViewMatrix) { this->onReset(&initialViewMa
trix); } |
62 | 62 |
63 /** | 63 /** |
64 * Initializes the GrDrawState based on a GrPaint, view matrix and render ta
rget. Note that | 64 * Initializes the GrDrawState based on a GrPaint, view matrix and render ta
rget. Note that |
65 * GrDrawState encompasses more than GrPaint. Aspects of GrDrawState that ha
ve no GrPaint | 65 * GrDrawState encompasses more than GrPaint. Aspects of GrDrawState that ha
ve no GrPaint |
66 * equivalents are set to default values with the exception of vertex attrib
ute state which | 66 * equivalents are set to default values with the exception of vertex attrib
ute state which |
67 * is unmodified by this function and clipping which will be enabled. | 67 * is unmodified by this function and clipping which will be enabled. |
68 */ | 68 */ |
69 void setFromPaint(const GrPaint& , const SkMatrix& viewMatrix, GrRenderTarge
t*); | 69 void setFromPaint(const GrPaint& , const SkMatrix& viewMatrix, GrRenderTarge
t*); |
70 | 70 |
71 /////////////////////////////////////////////////////////////////////////// | |
72 /// @name Vertex Attributes | |
73 //// | |
74 | |
75 // TODO when we move this info off of GrGeometryProcessor, delete these | |
76 bool hasLocalCoordAttribute() const { | |
77 return this->hasGeometryProcessor() && this->getGeometryProcessor()->has
LocalCoords(); | |
78 } | |
79 bool hasColorVertexAttribute() const { | |
80 return this->hasGeometryProcessor() && this->getGeometryProcessor()->has
VertexColor(); | |
81 } | |
82 bool hasCoverageVertexAttribute() const { | |
83 return this->hasGeometryProcessor() && this->getGeometryProcessor()->has
VertexCoverage(); | |
84 } | |
85 | |
86 /// @} | 71 /// @} |
87 | 72 |
88 /** | 73 /** |
89 * Depending on features available in the underlying 3D API and the color bl
end mode requested | 74 * 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 | 75 * it may or may not be possible to correctly blend with fractional pixel co
verage generated by |
91 * the fragment shader. | 76 * the fragment shader. |
92 * | 77 * |
93 * This function considers the current draw state and the draw target's capa
bilities to | 78 * 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 | 79 * determine whether coverage can be handled correctly. This function assume
s that the caller |
95 * intends to specify fractional pixel coverage via a primitive processor bu
t may not have | 80 * intends to specify fractional pixel coverage via a primitive processor bu
t may not have |
96 * specified it yet. | 81 * specified it yet. |
97 */ | 82 */ |
98 bool canUseFracCoveragePrimProc(GrColor color, const GrDrawTargetCaps& caps)
const; | 83 bool canUseFracCoveragePrimProc(GrColor color, const GrDrawTargetCaps& caps)
const; |
99 | 84 |
100 /** | 85 /** |
101 * Determines whether the output coverage is guaranteed to be one for all pi
xels hit by a draw. | 86 * Determines whether the output coverage is guaranteed to be one for all pi
xels hit by a draw. |
102 */ | 87 */ |
103 bool hasSolidCoverage(GrColor coverage) const; | 88 bool hasSolidCoverage(const GrPrimitiveProcessor*) const; |
104 | 89 |
105 /** | 90 /** |
106 * This function returns true if the render target destination pixel values
will be read for | 91 * This function returns true if the render target destination pixel values
will be read for |
107 * blending during draw. | 92 * blending during draw. |
108 */ | 93 */ |
109 bool willBlendWithDst(GrColor color, GrColor coverage) const; | 94 bool willBlendWithDst(const GrPrimitiveProcessor*) const; |
110 | |
111 /// @} | |
112 | |
113 /** | |
114 * The geometry processor is the sole element of the skia pipeline which can
use the vertex, | |
115 * geometry, and tesselation shaders. The GP may also compute a coverage in
its fragment shader | |
116 * but is never put in the color processing pipeline. | |
117 */ | |
118 | |
119 const GrGeometryProcessor* setGeometryProcessor(const GrGeometryProcessor* g
eometryProcessor) { | |
120 SkASSERT(geometryProcessor); | |
121 SkASSERT(!this->hasGeometryProcessor()); | |
122 fGeometryProcessor.reset(SkRef(geometryProcessor)); | |
123 fCoverageProcInfoValid = false; | |
124 return geometryProcessor; | |
125 } | |
126 | 95 |
127 /////////////////////////////////////////////////////////////////////////// | 96 /////////////////////////////////////////////////////////////////////////// |
128 /// @name Effect Stages | 97 /// @name Effect Stages |
129 /// Each stage hosts a GrProcessor. The effect produces an output color or c
overage in the | 98 /// Each stage hosts a GrProcessor. The effect produces an output color or c
overage in the |
130 /// fragment shader. Its inputs are the output from the previous stage as we
ll as some variables | 99 /// fragment shader. Its inputs are the output from the previous stage as we
ll as some variables |
131 /// available to it in the fragment and vertex shader (e.g. the vertex posit
ion, the dst color, | 100 /// available to it in the fragment and vertex shader (e.g. the vertex posit
ion, the dst color, |
132 /// the fragment position, local coordinates). | 101 /// the fragment position, local coordinates). |
133 /// | 102 /// |
134 /// The stages are divided into two sets, color-computing and coverage-compu
ting. The final | 103 /// The stages are divided into two sets, color-computing and coverage-compu
ting. The final |
135 /// color stage produces the final pixel color. The coverage-computing stage
s function exactly | 104 /// color stage produces the final pixel color. The coverage-computing stage
s function exactly |
136 /// as the color-computing but the output of the final coverage stage is tre
ated as a fractional | 105 /// as the color-computing but the output of the final coverage stage is tre
ated as a fractional |
137 /// pixel coverage rather than as input to the src/dst color blend step. | 106 /// pixel coverage rather than as input to the src/dst color blend step. |
138 /// | 107 /// |
139 /// The input color to the first color-stage is either the constant color or
interpolated | 108 /// The input color to the first color-stage is either the constant color or
interpolated |
140 /// per-vertex colors. The input to the first coverage stage is either a con
stant coverage | 109 /// per-vertex colors. The input to the first coverage stage is either a con
stant coverage |
141 /// (usually full-coverage) or interpolated per-vertex coverage. | 110 /// (usually full-coverage) or interpolated per-vertex coverage. |
142 /// | 111 /// |
143 /// See the documentation of kCoverageDrawing_StateBit for information about
disabling the | 112 /// See the documentation of kCoverageDrawing_StateBit for information about
disabling the |
144 /// the color / coverage distinction. | 113 /// the color / coverage distinction. |
145 //// | 114 //// |
146 | 115 |
147 int numColorStages() const { return fColorStages.count(); } | 116 int numColorStages() const { return fColorStages.count(); } |
148 int numCoverageStages() const { return fCoverageStages.count(); } | 117 int numCoverageStages() const { return fCoverageStages.count(); } |
149 int numFragmentStages() const { return this->numColorStages() + this->numCov
erageStages(); } | 118 int numFragmentStages() const { return this->numColorStages() + this->numCov
erageStages(); } |
150 int numTotalStages() const { | |
151 return this->numFragmentStages() + (this->hasGeometryProcessor() ? 1 :
0); | |
152 } | |
153 | |
154 bool hasGeometryProcessor() const { return SkToBool(fGeometryProcessor.get()
); } | |
155 const GrGeometryProcessor* getGeometryProcessor() const { return fGeometryPr
ocessor.get(); } | |
156 | 119 |
157 const GrXPFactory* getXPFactory() const { return fXPFactory.get(); } | 120 const GrXPFactory* getXPFactory() const { return fXPFactory.get(); } |
158 | 121 |
159 const GrFragmentStage& getColorStage(int idx) const { return fColorStages[id
x]; } | 122 const GrFragmentStage& getColorStage(int idx) const { return fColorStages[id
x]; } |
160 const GrFragmentStage& getCoverageStage(int idx) const { return fCoverageSta
ges[idx]; } | 123 const GrFragmentStage& getCoverageStage(int idx) const { return fCoverageSta
ges[idx]; } |
161 | 124 |
162 /** | 125 /** |
163 * Checks whether any of the effects will read the dst pixel color. | 126 * Checks whether any of the effects will read the dst pixel color. |
164 * TODO remove when we have an XP | 127 * TODO remove when we have an XP |
165 */ | 128 */ |
166 bool willEffectReadDstColor(GrColor color, GrColor coverage) const; | 129 bool willEffectReadDstColor(const GrPrimitiveProcessor*) const; |
167 | 130 |
168 /** | 131 /** |
169 * The xfer processor factory. | 132 * The xfer processor factory. |
170 */ | 133 */ |
171 const GrXPFactory* setXPFactory(const GrXPFactory* xpFactory) { | 134 const GrXPFactory* setXPFactory(const GrXPFactory* xpFactory) { |
172 fXPFactory.reset(SkRef(xpFactory)); | 135 fXPFactory.reset(SkRef(xpFactory)); |
173 return xpFactory; | 136 return xpFactory; |
174 } | 137 } |
175 | 138 |
176 void setPorterDuffXPFactory(SkXfermode::Mode mode) { | 139 void setPorterDuffXPFactory(SkXfermode::Mode mode) { |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 | 511 |
549 bool vertexColorsAreOpaque() const { return kVertexColorsAreOpaque_Hint & fH
ints; } | 512 bool vertexColorsAreOpaque() const { return kVertexColorsAreOpaque_Hint & fH
ints; } |
550 | 513 |
551 /// @} | 514 /// @} |
552 | 515 |
553 /////////////////////////////////////////////////////////////////////////// | 516 /////////////////////////////////////////////////////////////////////////// |
554 | 517 |
555 GrDrawState& operator= (const GrDrawState& that); | 518 GrDrawState& operator= (const GrDrawState& that); |
556 | 519 |
557 private: | 520 private: |
558 bool isEqual(const GrDrawState& that) const; | 521 bool isEqual(const GrDrawState& that, bool explicitLocalCoords) const; |
559 | 522 |
560 const GrProcOptInfo& colorProcInfo(GrColor color) const { | 523 const GrProcOptInfo& colorProcInfo(const GrPrimitiveProcessor* pp) const { |
561 this->calcColorInvariantOutput(color); | 524 this->calcColorInvariantOutput(pp); |
562 return fColorProcInfo; | 525 return fColorProcInfo; |
563 } | 526 } |
564 | 527 |
565 const GrProcOptInfo& coverageProcInfo(GrColor coverage) const { | 528 const GrProcOptInfo& coverageProcInfo(const GrPrimitiveProcessor* pp) const
{ |
566 this->calcCoverageInvariantOutput(coverage); | 529 this->calcCoverageInvariantOutput(pp); |
567 return fCoverageProcInfo; | 530 return fCoverageProcInfo; |
568 } | 531 } |
569 | 532 |
570 /** | 533 /** |
571 * Determines whether src alpha is guaranteed to be one for all src pixels | 534 * If fColorProcInfoValid is false, function calculates the invariant output
for the color |
| 535 * stages and results are stored in fColorProcInfo. |
572 */ | 536 */ |
573 bool srcAlphaWillBeOne(GrColor color, GrColor coverage) const; | 537 void calcColorInvariantOutput(const GrPrimitiveProcessor*) const; |
| 538 |
| 539 /** |
| 540 * If fCoverageProcInfoValid is false, function calculates the invariant out
put for the coverage |
| 541 * stages and results are stored in fCoverageProcInfo. |
| 542 */ |
| 543 void calcCoverageInvariantOutput(const GrPrimitiveProcessor*) const; |
574 | 544 |
575 /** | 545 /** |
576 * If fColorProcInfoValid is false, function calculates the invariant output
for the color | 546 * If fColorProcInfoValid is false, function calculates the invariant output
for the color |
577 * stages and results are stored in fColorProcInfo. | 547 * stages and results are stored in fColorProcInfo. |
578 */ | 548 */ |
579 void calcColorInvariantOutput(GrColor) const; | 549 void calcColorInvariantOutput(GrColor) const; |
580 | 550 |
581 /** | 551 /** |
582 * If fCoverageProcInfoValid is false, function calculates the invariant out
put for the coverage | 552 * If fCoverageProcInfoValid is false, function calculates the invariant out
put for the coverage |
583 * stages and results are stored in fCoverageProcInfo. | 553 * stages and results are stored in fCoverageProcInfo. |
584 */ | 554 */ |
585 void calcCoverageInvariantOutput(GrColor) const; | 555 void calcCoverageInvariantOutput(GrColor) const; |
586 | 556 |
587 void onReset(const SkMatrix* initialViewMatrix); | 557 void onReset(const SkMatrix* initialViewMatrix); |
588 | 558 |
589 // Some of the auto restore objects assume that no effects are removed durin
g their lifetime. | 559 // Some of the auto restore objects assume that no effects are removed durin
g their lifetime. |
590 // This is used to assert that this condition holds. | 560 // This is used to assert that this condition holds. |
591 SkDEBUGCODE(int fBlockEffectRemovalCnt;) | 561 SkDEBUGCODE(int fBlockEffectRemovalCnt;) |
592 | 562 |
593 typedef SkSTArray<4, GrFragmentStage> FragmentStageArray; | 563 typedef SkSTArray<4, GrFragmentStage> FragmentStageArray; |
594 | 564 |
595 SkAutoTUnref<GrRenderTarget> fRenderTarget; | 565 SkAutoTUnref<GrRenderTarget> fRenderTarget; |
596 SkMatrix fViewMatrix; | 566 SkMatrix fViewMatrix; |
597 uint32_t fFlagBits; | 567 uint32_t fFlagBits; |
598 GrStencilSettings fStencilSettings; | 568 GrStencilSettings fStencilSettings; |
599 DrawFace fDrawFace; | 569 DrawFace fDrawFace; |
600 SkAutoTUnref<const GrGeometryProcessor> fGeometryProcessor; | |
601 SkAutoTUnref<const GrXPFactory> fXPFactory; | 570 SkAutoTUnref<const GrXPFactory> fXPFactory; |
602 FragmentStageArray fColorStages; | 571 FragmentStageArray fColorStages; |
603 FragmentStageArray fCoverageStages; | 572 FragmentStageArray fCoverageStages; |
604 uint32_t fHints; | 573 uint32_t fHints; |
605 | 574 |
606 mutable GrProcOptInfo fColorProcInfo; | 575 mutable GrProcOptInfo fColorProcInfo; |
607 mutable GrProcOptInfo fCoverageProcInfo; | 576 mutable GrProcOptInfo fCoverageProcInfo; |
608 mutable bool fColorProcInfoValid; | 577 mutable bool fColorProcInfoValid; |
609 mutable bool fCoverageProcInfoValid; | 578 mutable bool fCoverageProcInfoValid; |
610 mutable GrColor fColorCache; | 579 mutable GrColor fColorCache; |
611 mutable GrColor fCoverageCache; | 580 mutable GrColor fCoverageCache; |
| 581 mutable const GrPrimitiveProcessor* fColorPrimProc; |
| 582 mutable const GrPrimitiveProcessor* fCoveragePrimProc; |
612 | 583 |
613 friend class GrOptDrawState; | 584 friend class GrOptDrawState; |
614 }; | 585 }; |
615 | 586 |
616 #endif | 587 #endif |
OLD | NEW |