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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 * significant complexity to the multi-ref architecture for deferred drawing
. Once GrDrawState | 194 * significant complexity to the multi-ref architecture for deferred drawing
. Once GrDrawState |
232 * and GrOptDrawState are fully separated then GrDrawState will never be in
the deferred | 195 * and GrOptDrawState are fully separated then GrDrawState will never be in
the deferred |
233 * execution state and GrOptDrawState always will be (and will be immutable
and therefore | 196 * execution state and GrOptDrawState always will be (and will be immutable
and therefore |
234 * unable to have an ARE). At this point we can restore sanity and have the
ARE save and restore | 197 * unable to have an ARE). At this point we can restore sanity and have the
ARE save and restore |
235 * the GP. | 198 * the GP. |
236 */ | 199 */ |
237 class AutoRestoreEffects : public ::SkNoncopyable { | 200 class AutoRestoreEffects : public ::SkNoncopyable { |
238 public: | 201 public: |
239 AutoRestoreEffects() | 202 AutoRestoreEffects() |
240 : fDrawState(NULL) | 203 : fDrawState(NULL) |
241 , fOriginalGPID(SK_InvalidUniqueID) | |
242 , fColorEffectCnt(0) | 204 , fColorEffectCnt(0) |
243 , fCoverageEffectCnt(0) {} | 205 , fCoverageEffectCnt(0) {} |
244 | 206 |
245 AutoRestoreEffects(GrDrawState* ds) | 207 AutoRestoreEffects(GrDrawState* ds) |
246 : fDrawState(NULL) | 208 : fDrawState(NULL) |
247 , fOriginalGPID(SK_InvalidUniqueID) | |
248 , fColorEffectCnt(0) | 209 , fColorEffectCnt(0) |
249 , fCoverageEffectCnt(0) { | 210 , fCoverageEffectCnt(0) { |
250 this->set(ds); | 211 this->set(ds); |
251 } | 212 } |
252 | 213 |
253 ~AutoRestoreEffects() { this->set(NULL); } | 214 ~AutoRestoreEffects() { this->set(NULL); } |
254 | 215 |
255 void set(GrDrawState* ds); | 216 void set(GrDrawState* ds); |
256 | 217 |
257 bool isSet() const { return SkToBool(fDrawState); } | 218 bool isSet() const { return SkToBool(fDrawState); } |
258 | 219 |
259 private: | 220 private: |
260 GrDrawState* fDrawState; | 221 GrDrawState* fDrawState; |
261 uint32_t fOriginalGPID; | |
262 int fColorEffectCnt; | 222 int fColorEffectCnt; |
263 int fCoverageEffectCnt; | 223 int fCoverageEffectCnt; |
264 }; | 224 }; |
265 | 225 |
266 /** | 226 /** |
267 * AutoRestoreStencil | 227 * AutoRestoreStencil |
268 * | 228 * |
269 * This simple struct saves and restores the stencil settings | 229 * This simple struct saves and restores the stencil settings |
270 */ | 230 */ |
271 class AutoRestoreStencil : public ::SkNoncopyable { | 231 class AutoRestoreStencil : public ::SkNoncopyable { |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 * @param face the face(s) to draw. | 488 * @param face the face(s) to draw. |
529 */ | 489 */ |
530 void setDrawFace(DrawFace face) { | 490 void setDrawFace(DrawFace face) { |
531 SkASSERT(kInvalid_DrawFace != face); | 491 SkASSERT(kInvalid_DrawFace != face); |
532 fDrawFace = face; | 492 fDrawFace = face; |
533 } | 493 } |
534 | 494 |
535 /// @} | 495 /// @} |
536 | 496 |
537 /////////////////////////////////////////////////////////////////////////// | 497 /////////////////////////////////////////////////////////////////////////// |
538 /// @name Hints | |
539 /// Hints that when provided can enable optimizations. | |
540 //// | |
541 | |
542 enum Hints { | |
543 kVertexColorsAreOpaque_Hint = 0x1, | |
544 kLast_Hint = kVertexColorsAreOpaque_Hint | |
545 }; | |
546 | |
547 void setHint(Hints hint, bool value) { fHints = value ? (fHints | hint) : (f
Hints & ~hint); } | |
548 | |
549 bool vertexColorsAreOpaque() const { return kVertexColorsAreOpaque_Hint & fH
ints; } | |
550 | |
551 /// @} | |
552 | |
553 /////////////////////////////////////////////////////////////////////////// | |
554 | 498 |
555 GrDrawState& operator= (const GrDrawState& that); | 499 GrDrawState& operator= (const GrDrawState& that); |
556 | 500 |
557 private: | 501 private: |
558 bool isEqual(const GrDrawState& that) const; | 502 bool isEqual(const GrDrawState& that, bool explicitLocalCoords) const; |
559 | 503 |
560 const GrProcOptInfo& colorProcInfo(GrColor color) const { | 504 const GrProcOptInfo& colorProcInfo(const GrPrimitiveProcessor* pp) const { |
561 this->calcColorInvariantOutput(color); | 505 this->calcColorInvariantOutput(pp); |
562 return fColorProcInfo; | 506 return fColorProcInfo; |
563 } | 507 } |
564 | 508 |
565 const GrProcOptInfo& coverageProcInfo(GrColor coverage) const { | 509 const GrProcOptInfo& coverageProcInfo(const GrPrimitiveProcessor* pp) const
{ |
566 this->calcCoverageInvariantOutput(coverage); | 510 this->calcCoverageInvariantOutput(pp); |
567 return fCoverageProcInfo; | 511 return fCoverageProcInfo; |
568 } | 512 } |
569 | 513 |
570 /** | 514 /** |
571 * Determines whether src alpha is guaranteed to be one for all src pixels | 515 * If fColorProcInfoValid is false, function calculates the invariant output
for the color |
| 516 * stages and results are stored in fColorProcInfo. |
572 */ | 517 */ |
573 bool srcAlphaWillBeOne(GrColor color, GrColor coverage) const; | 518 void calcColorInvariantOutput(const GrPrimitiveProcessor*) const; |
| 519 |
| 520 /** |
| 521 * If fCoverageProcInfoValid is false, function calculates the invariant out
put for the coverage |
| 522 * stages and results are stored in fCoverageProcInfo. |
| 523 */ |
| 524 void calcCoverageInvariantOutput(const GrPrimitiveProcessor*) const; |
574 | 525 |
575 /** | 526 /** |
576 * If fColorProcInfoValid is false, function calculates the invariant output
for the color | 527 * If fColorProcInfoValid is false, function calculates the invariant output
for the color |
577 * stages and results are stored in fColorProcInfo. | 528 * stages and results are stored in fColorProcInfo. |
578 */ | 529 */ |
579 void calcColorInvariantOutput(GrColor) const; | 530 void calcColorInvariantOutput(GrColor) const; |
580 | 531 |
581 /** | 532 /** |
582 * If fCoverageProcInfoValid is false, function calculates the invariant out
put for the coverage | 533 * If fCoverageProcInfoValid is false, function calculates the invariant out
put for the coverage |
583 * stages and results are stored in fCoverageProcInfo. | 534 * stages and results are stored in fCoverageProcInfo. |
584 */ | 535 */ |
585 void calcCoverageInvariantOutput(GrColor) const; | 536 void calcCoverageInvariantOutput(GrColor) const; |
586 | 537 |
587 void onReset(const SkMatrix* initialViewMatrix); | 538 void onReset(const SkMatrix* initialViewMatrix); |
588 | 539 |
589 // Some of the auto restore objects assume that no effects are removed durin
g their lifetime. | 540 // 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. | 541 // This is used to assert that this condition holds. |
591 SkDEBUGCODE(int fBlockEffectRemovalCnt;) | 542 SkDEBUGCODE(int fBlockEffectRemovalCnt;) |
592 | 543 |
593 typedef SkSTArray<4, GrFragmentStage> FragmentStageArray; | 544 typedef SkSTArray<4, GrFragmentStage> FragmentStageArray; |
594 | 545 |
595 SkAutoTUnref<GrRenderTarget> fRenderTarget; | 546 SkAutoTUnref<GrRenderTarget> fRenderTarget; |
596 SkMatrix fViewMatrix; | 547 SkMatrix fViewMatrix; |
597 uint32_t fFlagBits; | 548 uint32_t fFlagBits; |
598 GrStencilSettings fStencilSettings; | 549 GrStencilSettings fStencilSettings; |
599 DrawFace fDrawFace; | 550 DrawFace fDrawFace; |
600 SkAutoTUnref<const GrGeometryProcessor> fGeometryProcessor; | |
601 SkAutoTUnref<const GrXPFactory> fXPFactory; | 551 SkAutoTUnref<const GrXPFactory> fXPFactory; |
602 FragmentStageArray fColorStages; | 552 FragmentStageArray fColorStages; |
603 FragmentStageArray fCoverageStages; | 553 FragmentStageArray fCoverageStages; |
604 uint32_t fHints; | |
605 | 554 |
606 mutable GrProcOptInfo fColorProcInfo; | 555 mutable GrProcOptInfo fColorProcInfo; |
607 mutable GrProcOptInfo fCoverageProcInfo; | 556 mutable GrProcOptInfo fCoverageProcInfo; |
608 mutable bool fColorProcInfoValid; | 557 mutable bool fColorProcInfoValid; |
609 mutable bool fCoverageProcInfoValid; | 558 mutable bool fCoverageProcInfoValid; |
610 mutable GrColor fColorCache; | 559 mutable GrColor fColorCache; |
611 mutable GrColor fCoverageCache; | 560 mutable GrColor fCoverageCache; |
| 561 mutable const GrPrimitiveProcessor* fColorPrimProc; |
| 562 mutable const GrPrimitiveProcessor* fCoveragePrimProc; |
612 | 563 |
613 friend class GrOptDrawState; | 564 friend class GrOptDrawState; |
614 }; | 565 }; |
615 | 566 |
616 #endif | 567 #endif |
OLD | NEW |