| 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 |
| 71 /// @} | 86 /// @} |
| 72 | 87 |
| 73 /** | 88 /** |
| 74 * 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 |
| 75 * 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 |
| 76 * the fragment shader. | 91 * the fragment shader. |
| 77 * | 92 * |
| 78 * 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 |
| 79 * 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 |
| 80 * intends to specify fractional pixel coverage via a primitive processor bu
t may not have | 95 * intends to specify fractional pixel coverage via a primitive processor bu
t may not have |
| 81 * specified it yet. | 96 * specified it yet. |
| 82 */ | 97 */ |
| 83 bool canUseFracCoveragePrimProc(GrColor color, const GrDrawTargetCaps& caps)
const; | 98 bool canUseFracCoveragePrimProc(GrColor color, const GrDrawTargetCaps& caps)
const; |
| 84 | 99 |
| 85 /** | 100 /** |
| 86 * 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. |
| 87 */ | 102 */ |
| 88 bool hasSolidCoverage(const GrPrimitiveProcessor*) const; | 103 bool hasSolidCoverage(GrColor coverage) const; |
| 89 | 104 |
| 90 /** | 105 /** |
| 91 * 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 |
| 92 * blending during draw. | 107 * blending during draw. |
| 93 */ | 108 */ |
| 94 bool willBlendWithDst(const GrPrimitiveProcessor*) const; | 109 bool willBlendWithDst(GrColor color, GrColor coverage) 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 } |
| 95 | 126 |
| 96 /////////////////////////////////////////////////////////////////////////// | 127 /////////////////////////////////////////////////////////////////////////// |
| 97 /// @name Effect Stages | 128 /// @name Effect Stages |
| 98 /// Each stage hosts a GrProcessor. The effect produces an output color or c
overage in the | 129 /// Each stage hosts a GrProcessor. The effect produces an output color or c
overage in the |
| 99 /// fragment shader. Its inputs are the output from the previous stage as we
ll as some variables | 130 /// fragment shader. Its inputs are the output from the previous stage as we
ll as some variables |
| 100 /// available to it in the fragment and vertex shader (e.g. the vertex posit
ion, the dst color, | 131 /// available to it in the fragment and vertex shader (e.g. the vertex posit
ion, the dst color, |
| 101 /// the fragment position, local coordinates). | 132 /// the fragment position, local coordinates). |
| 102 /// | 133 /// |
| 103 /// The stages are divided into two sets, color-computing and coverage-compu
ting. The final | 134 /// The stages are divided into two sets, color-computing and coverage-compu
ting. The final |
| 104 /// color stage produces the final pixel color. The coverage-computing stage
s function exactly | 135 /// color stage produces the final pixel color. The coverage-computing stage
s function exactly |
| 105 /// as the color-computing but the output of the final coverage stage is tre
ated as a fractional | 136 /// as the color-computing but the output of the final coverage stage is tre
ated as a fractional |
| 106 /// pixel coverage rather than as input to the src/dst color blend step. | 137 /// pixel coverage rather than as input to the src/dst color blend step. |
| 107 /// | 138 /// |
| 108 /// The input color to the first color-stage is either the constant color or
interpolated | 139 /// The input color to the first color-stage is either the constant color or
interpolated |
| 109 /// per-vertex colors. The input to the first coverage stage is either a con
stant coverage | 140 /// per-vertex colors. The input to the first coverage stage is either a con
stant coverage |
| 110 /// (usually full-coverage) or interpolated per-vertex coverage. | 141 /// (usually full-coverage) or interpolated per-vertex coverage. |
| 111 /// | 142 /// |
| 112 /// See the documentation of kCoverageDrawing_StateBit for information about
disabling the | 143 /// See the documentation of kCoverageDrawing_StateBit for information about
disabling the |
| 113 /// the color / coverage distinction. | 144 /// the color / coverage distinction. |
| 114 //// | 145 //// |
| 115 | 146 |
| 116 int numColorStages() const { return fColorStages.count(); } | 147 int numColorStages() const { return fColorStages.count(); } |
| 117 int numCoverageStages() const { return fCoverageStages.count(); } | 148 int numCoverageStages() const { return fCoverageStages.count(); } |
| 118 int numFragmentStages() const { return this->numColorStages() + this->numCov
erageStages(); } | 149 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(); } |
| 119 | 156 |
| 120 const GrXPFactory* getXPFactory() const { return fXPFactory.get(); } | 157 const GrXPFactory* getXPFactory() const { return fXPFactory.get(); } |
| 121 | 158 |
| 122 const GrFragmentStage& getColorStage(int idx) const { return fColorStages[id
x]; } | 159 const GrFragmentStage& getColorStage(int idx) const { return fColorStages[id
x]; } |
| 123 const GrFragmentStage& getCoverageStage(int idx) const { return fCoverageSta
ges[idx]; } | 160 const GrFragmentStage& getCoverageStage(int idx) const { return fCoverageSta
ges[idx]; } |
| 124 | 161 |
| 125 /** | 162 /** |
| 126 * 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. |
| 127 * TODO remove when we have an XP | 164 * TODO remove when we have an XP |
| 128 */ | 165 */ |
| 129 bool willEffectReadDstColor(const GrPrimitiveProcessor*) const; | 166 bool willEffectReadDstColor(GrColor color, GrColor coverage) const; |
| 130 | 167 |
| 131 /** | 168 /** |
| 132 * The xfer processor factory. | 169 * The xfer processor factory. |
| 133 */ | 170 */ |
| 134 const GrXPFactory* setXPFactory(const GrXPFactory* xpFactory) { | 171 const GrXPFactory* setXPFactory(const GrXPFactory* xpFactory) { |
| 135 fXPFactory.reset(SkRef(xpFactory)); | 172 fXPFactory.reset(SkRef(xpFactory)); |
| 136 return xpFactory; | 173 return xpFactory; |
| 137 } | 174 } |
| 138 | 175 |
| 139 void setPorterDuffXPFactory(SkXfermode::Mode mode) { | 176 void setPorterDuffXPFactory(SkXfermode::Mode mode) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 * significant complexity to the multi-ref architecture for deferred drawing
. Once GrDrawState | 231 * significant complexity to the multi-ref architecture for deferred drawing
. Once GrDrawState |
| 195 * and GrOptDrawState are fully separated then GrDrawState will never be in
the deferred | 232 * and GrOptDrawState are fully separated then GrDrawState will never be in
the deferred |
| 196 * execution state and GrOptDrawState always will be (and will be immutable
and therefore | 233 * execution state and GrOptDrawState always will be (and will be immutable
and therefore |
| 197 * unable to have an ARE). At this point we can restore sanity and have the
ARE save and restore | 234 * unable to have an ARE). At this point we can restore sanity and have the
ARE save and restore |
| 198 * the GP. | 235 * the GP. |
| 199 */ | 236 */ |
| 200 class AutoRestoreEffects : public ::SkNoncopyable { | 237 class AutoRestoreEffects : public ::SkNoncopyable { |
| 201 public: | 238 public: |
| 202 AutoRestoreEffects() | 239 AutoRestoreEffects() |
| 203 : fDrawState(NULL) | 240 : fDrawState(NULL) |
| 241 , fOriginalGPID(SK_InvalidUniqueID) |
| 204 , fColorEffectCnt(0) | 242 , fColorEffectCnt(0) |
| 205 , fCoverageEffectCnt(0) {} | 243 , fCoverageEffectCnt(0) {} |
| 206 | 244 |
| 207 AutoRestoreEffects(GrDrawState* ds) | 245 AutoRestoreEffects(GrDrawState* ds) |
| 208 : fDrawState(NULL) | 246 : fDrawState(NULL) |
| 247 , fOriginalGPID(SK_InvalidUniqueID) |
| 209 , fColorEffectCnt(0) | 248 , fColorEffectCnt(0) |
| 210 , fCoverageEffectCnt(0) { | 249 , fCoverageEffectCnt(0) { |
| 211 this->set(ds); | 250 this->set(ds); |
| 212 } | 251 } |
| 213 | 252 |
| 214 ~AutoRestoreEffects() { this->set(NULL); } | 253 ~AutoRestoreEffects() { this->set(NULL); } |
| 215 | 254 |
| 216 void set(GrDrawState* ds); | 255 void set(GrDrawState* ds); |
| 217 | 256 |
| 218 bool isSet() const { return SkToBool(fDrawState); } | 257 bool isSet() const { return SkToBool(fDrawState); } |
| 219 | 258 |
| 220 private: | 259 private: |
| 221 GrDrawState* fDrawState; | 260 GrDrawState* fDrawState; |
| 261 uint32_t fOriginalGPID; |
| 222 int fColorEffectCnt; | 262 int fColorEffectCnt; |
| 223 int fCoverageEffectCnt; | 263 int fCoverageEffectCnt; |
| 224 }; | 264 }; |
| 225 | 265 |
| 226 /** | 266 /** |
| 227 * AutoRestoreStencil | 267 * AutoRestoreStencil |
| 228 * | 268 * |
| 229 * This simple struct saves and restores the stencil settings | 269 * This simple struct saves and restores the stencil settings |
| 230 */ | 270 */ |
| 231 class AutoRestoreStencil : public ::SkNoncopyable { | 271 class AutoRestoreStencil : public ::SkNoncopyable { |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 | 548 |
| 509 bool vertexColorsAreOpaque() const { return kVertexColorsAreOpaque_Hint & fH
ints; } | 549 bool vertexColorsAreOpaque() const { return kVertexColorsAreOpaque_Hint & fH
ints; } |
| 510 | 550 |
| 511 /// @} | 551 /// @} |
| 512 | 552 |
| 513 /////////////////////////////////////////////////////////////////////////// | 553 /////////////////////////////////////////////////////////////////////////// |
| 514 | 554 |
| 515 GrDrawState& operator= (const GrDrawState& that); | 555 GrDrawState& operator= (const GrDrawState& that); |
| 516 | 556 |
| 517 private: | 557 private: |
| 518 bool isEqual(const GrDrawState& that, bool explicitLocalCoords) const; | 558 bool isEqual(const GrDrawState& that) const; |
| 519 | 559 |
| 520 const GrProcOptInfo& colorProcInfo(const GrPrimitiveProcessor* pp) const { | 560 const GrProcOptInfo& colorProcInfo(GrColor color) const { |
| 521 this->calcColorInvariantOutput(pp); | 561 this->calcColorInvariantOutput(color); |
| 522 return fColorProcInfo; | 562 return fColorProcInfo; |
| 523 } | 563 } |
| 524 | 564 |
| 525 const GrProcOptInfo& coverageProcInfo(const GrPrimitiveProcessor* pp) const
{ | 565 const GrProcOptInfo& coverageProcInfo(GrColor coverage) const { |
| 526 this->calcCoverageInvariantOutput(pp); | 566 this->calcCoverageInvariantOutput(coverage); |
| 527 return fCoverageProcInfo; | 567 return fCoverageProcInfo; |
| 528 } | 568 } |
| 529 | 569 |
| 530 /** | 570 /** |
| 531 * If fColorProcInfoValid is false, function calculates the invariant output
for the color | 571 * Determines whether src alpha is guaranteed to be one for all src pixels |
| 532 * stages and results are stored in fColorProcInfo. | |
| 533 */ | 572 */ |
| 534 void calcColorInvariantOutput(const GrPrimitiveProcessor*) const; | 573 bool srcAlphaWillBeOne(GrColor color, GrColor coverage) const; |
| 535 | |
| 536 /** | |
| 537 * If fCoverageProcInfoValid is false, function calculates the invariant out
put for the coverage | |
| 538 * stages and results are stored in fCoverageProcInfo. | |
| 539 */ | |
| 540 void calcCoverageInvariantOutput(const GrPrimitiveProcessor*) const; | |
| 541 | 574 |
| 542 /** | 575 /** |
| 543 * 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 |
| 544 * stages and results are stored in fColorProcInfo. | 577 * stages and results are stored in fColorProcInfo. |
| 545 */ | 578 */ |
| 546 void calcColorInvariantOutput(GrColor) const; | 579 void calcColorInvariantOutput(GrColor) const; |
| 547 | 580 |
| 548 /** | 581 /** |
| 549 * 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 |
| 550 * stages and results are stored in fCoverageProcInfo. | 583 * stages and results are stored in fCoverageProcInfo. |
| 551 */ | 584 */ |
| 552 void calcCoverageInvariantOutput(GrColor) const; | 585 void calcCoverageInvariantOutput(GrColor) const; |
| 553 | 586 |
| 554 void onReset(const SkMatrix* initialViewMatrix); | 587 void onReset(const SkMatrix* initialViewMatrix); |
| 555 | 588 |
| 556 // 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. |
| 557 // This is used to assert that this condition holds. | 590 // This is used to assert that this condition holds. |
| 558 SkDEBUGCODE(int fBlockEffectRemovalCnt;) | 591 SkDEBUGCODE(int fBlockEffectRemovalCnt;) |
| 559 | 592 |
| 560 typedef SkSTArray<4, GrFragmentStage> FragmentStageArray; | 593 typedef SkSTArray<4, GrFragmentStage> FragmentStageArray; |
| 561 | 594 |
| 562 SkAutoTUnref<GrRenderTarget> fRenderTarget; | 595 SkAutoTUnref<GrRenderTarget> fRenderTarget; |
| 563 SkMatrix fViewMatrix; | 596 SkMatrix fViewMatrix; |
| 564 uint32_t fFlagBits; | 597 uint32_t fFlagBits; |
| 565 GrStencilSettings fStencilSettings; | 598 GrStencilSettings fStencilSettings; |
| 566 DrawFace fDrawFace; | 599 DrawFace fDrawFace; |
| 600 SkAutoTUnref<const GrGeometryProcessor> fGeometryProcessor; |
| 567 SkAutoTUnref<const GrXPFactory> fXPFactory; | 601 SkAutoTUnref<const GrXPFactory> fXPFactory; |
| 568 FragmentStageArray fColorStages; | 602 FragmentStageArray fColorStages; |
| 569 FragmentStageArray fCoverageStages; | 603 FragmentStageArray fCoverageStages; |
| 570 uint32_t fHints; | 604 uint32_t fHints; |
| 571 | 605 |
| 572 mutable GrProcOptInfo fColorProcInfo; | 606 mutable GrProcOptInfo fColorProcInfo; |
| 573 mutable GrProcOptInfo fCoverageProcInfo; | 607 mutable GrProcOptInfo fCoverageProcInfo; |
| 574 mutable bool fColorProcInfoValid; | 608 mutable bool fColorProcInfoValid; |
| 575 mutable bool fCoverageProcInfoValid; | 609 mutable bool fCoverageProcInfoValid; |
| 576 mutable GrColor fColorCache; | 610 mutable GrColor fColorCache; |
| 577 mutable GrColor fCoverageCache; | 611 mutable GrColor fCoverageCache; |
| 578 mutable const GrPrimitiveProcessor* fColorPrimProc; | |
| 579 mutable const GrPrimitiveProcessor* fCoveragePrimProc; | |
| 580 | 612 |
| 581 friend class GrOptDrawState; | 613 friend class GrOptDrawState; |
| 582 }; | 614 }; |
| 583 | 615 |
| 584 #endif | 616 #endif |
| OLD | NEW |