| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 #include "GrRODrawState.h" | 8 #include "GrRODrawState.h" |
| 9 #include "GrDrawTargetCaps.h" | 9 #include "GrDrawTargetCaps.h" |
| 10 | 10 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 this->fDrawFace != that.fDrawFace) { | 31 this->fDrawFace != that.fDrawFace) { |
| 32 return false; | 32 return false; |
| 33 } | 33 } |
| 34 | 34 |
| 35 bool usingVertexCoverage = this->hasCoverageVertexAttribute(); | 35 bool usingVertexCoverage = this->hasCoverageVertexAttribute(); |
| 36 if (!usingVertexCoverage && this->fCoverage != that.fCoverage) { | 36 if (!usingVertexCoverage && this->fCoverage != that.fCoverage) { |
| 37 return false; | 37 return false; |
| 38 } | 38 } |
| 39 | 39 |
| 40 bool explicitLocalCoords = this->hasLocalCoordAttribute(); | 40 bool explicitLocalCoords = this->hasLocalCoordAttribute(); |
| 41 if (this->hasGeometryProcessor()) { |
| 42 if (!that.hasGeometryProcessor()) { |
| 43 return kIncompatible_CombinedState; |
| 44 } else if (!GrEffectStage::AreCompatible(*this->getGeometryProcessor(), |
| 45 *that.getGeometryProcessor(), |
| 46 explicitLocalCoords)) { |
| 47 return kIncompatible_CombinedState; |
| 48 } |
| 49 } else if (that.hasGeometryProcessor()) { |
| 50 return kIncompatible_CombinedState; |
| 51 } |
| 52 |
| 41 for (int i = 0; i < this->numColorStages(); i++) { | 53 for (int i = 0; i < this->numColorStages(); i++) { |
| 42 if (!GrEffectStage::AreCompatible(this->getColorStage(i), that.getColorS
tage(i), | 54 if (!GrEffectStage::AreCompatible(this->getColorStage(i), that.getColorS
tage(i), |
| 43 explicitLocalCoords)) { | 55 explicitLocalCoords)) { |
| 44 return false; | 56 return false; |
| 45 } | 57 } |
| 46 } | 58 } |
| 47 for (int i = 0; i < this->numCoverageStages(); i++) { | 59 for (int i = 0; i < this->numCoverageStages(); i++) { |
| 48 if (!GrEffectStage::AreCompatible(this->getCoverageStage(i), that.getCov
erageStage(i), | 60 if (!GrEffectStage::AreCompatible(this->getCoverageStage(i), that.getCov
erageStage(i), |
| 49 explicitLocalCoords)) { | 61 explicitLocalCoords)) { |
| 50 return false; | 62 return false; |
| 51 } | 63 } |
| 52 } | 64 } |
| 53 | 65 |
| 54 SkASSERT(0 == memcmp(this->fFixedFunctionVertexAttribIndices, | 66 SkASSERT(0 == memcmp(this->fFixedFunctionVertexAttribIndices, |
| 55 that.fFixedFunctionVertexAttribIndices, | 67 that.fFixedFunctionVertexAttribIndices, |
| 56 sizeof(this->fFixedFunctionVertexAttribIndices))); | 68 sizeof(this->fFixedFunctionVertexAttribIndices))); |
| 57 | 69 |
| 58 return true; | 70 return true; |
| 59 } | 71 } |
| 60 | 72 |
| 61 //////////////////////////////////////////////////////////////////////////////// | 73 //////////////////////////////////////////////////////////////////////////////// |
| 62 | 74 |
| 63 bool GrRODrawState::validateVertexAttribs() const { | 75 bool GrRODrawState::validateVertexAttribs() const { |
| 64 // check consistency of effects and attributes | 76 // check consistency of effects and attributes |
| 65 GrSLType slTypes[kMaxVertexAttribCnt]; | 77 GrSLType slTypes[kMaxVertexAttribCnt]; |
| 66 for (int i = 0; i < kMaxVertexAttribCnt; ++i) { | 78 for (int i = 0; i < kMaxVertexAttribCnt; ++i) { |
| 67 slTypes[i] = static_cast<GrSLType>(-1); | 79 slTypes[i] = static_cast<GrSLType>(-1); |
| 68 } | 80 } |
| 69 int totalStages = this->numTotalStages(); | 81 |
| 70 for (int s = 0; s < totalStages; ++s) { | 82 if (this->hasGeometryProcessor()) { |
| 71 int covIdx = s - this->numColorStages(); | 83 const GrEffectStage& stage = *this->getGeometryProcessor(); |
| 72 const GrEffectStage& stage = covIdx < 0 ? this->getColorStage(s) : | |
| 73 this->getCoverageStage(covIdx)
; | |
| 74 const GrEffect* effect = stage.getEffect(); | 84 const GrEffect* effect = stage.getEffect(); |
| 75 SkASSERT(NULL != effect); | 85 SkASSERT(NULL != effect); |
| 76 // make sure that any attribute indices have the correct binding type, t
hat the attrib | 86 // make sure that any attribute indices have the correct binding type, t
hat the attrib |
| 77 // type and effect's shader lang type are compatible, and that attribute
s shared by | 87 // type and effect's shader lang type are compatible, and that attribute
s shared by |
| 78 // multiple effects use the same shader lang type. | 88 // multiple effects use the same shader lang type. |
| 79 const int* attributeIndices = stage.getVertexAttribIndices(); | 89 const int* attributeIndices = stage.getVertexAttribIndices(); |
| 80 int numAttributes = stage.getVertexAttribIndexCount(); | 90 int numAttributes = stage.getVertexAttribIndexCount(); |
| 81 for (int i = 0; i < numAttributes; ++i) { | 91 for (int i = 0; i < numAttributes; ++i) { |
| 82 int attribIndex = attributeIndices[i]; | 92 int attribIndex = attributeIndices[i]; |
| 83 if (attribIndex >= fVACount || | 93 if (attribIndex >= fVACount || |
| (...skipping 27 matching lines...) Expand all Loading... |
| 111 uint32_t validComponentFlags; | 121 uint32_t validComponentFlags; |
| 112 // Initialize to an unknown starting coverage if per-vertex coverage is spec
ified. | 122 // Initialize to an unknown starting coverage if per-vertex coverage is spec
ified. |
| 113 if (this->hasCoverageVertexAttribute()) { | 123 if (this->hasCoverageVertexAttribute()) { |
| 114 validComponentFlags = 0; | 124 validComponentFlags = 0; |
| 115 } else { | 125 } else { |
| 116 coverage = fCoverage; | 126 coverage = fCoverage; |
| 117 validComponentFlags = kRGBA_GrColorComponentFlags; | 127 validComponentFlags = kRGBA_GrColorComponentFlags; |
| 118 } | 128 } |
| 119 | 129 |
| 120 // Run through the coverage stages and see if the coverage will be all ones
at the end. | 130 // Run through the coverage stages and see if the coverage will be all ones
at the end. |
| 131 if (this->hasGeometryProcessor()) { |
| 132 const GrEffect* effect = fGeometryProcessor->getEffect(); |
| 133 effect->getConstantColorComponents(&coverage, &validComponentFlags); |
| 134 } |
| 121 for (int s = 0; s < this->numCoverageStages(); ++s) { | 135 for (int s = 0; s < this->numCoverageStages(); ++s) { |
| 122 const GrEffect* effect = this->getCoverageStage(s).getEffect(); | 136 const GrEffect* effect = this->getCoverageStage(s).getEffect(); |
| 123 effect->getConstantColorComponents(&coverage, &validComponentFlags); | 137 effect->getConstantColorComponents(&coverage, &validComponentFlags); |
| 124 } | 138 } |
| 125 return (kRGBA_GrColorComponentFlags == validComponentFlags) && (0xffffffff =
= coverage); | 139 return (kRGBA_GrColorComponentFlags == validComponentFlags) && (0xffffffff =
= coverage); |
| 126 } | 140 } |
| 127 | 141 |
| 128 //////////////////////////////////////////////////////////////////////////////// | 142 //////////////////////////////////////////////////////////////////////////////// |
| 129 | 143 |
| 130 bool GrRODrawState::willEffectReadDstColor() const { | 144 bool GrRODrawState::willEffectReadDstColor() const { |
| 131 if (!this->isColorWriteDisabled()) { | 145 if (!this->isColorWriteDisabled()) { |
| 132 for (int s = 0; s < this->numColorStages(); ++s) { | 146 for (int s = 0; s < this->numColorStages(); ++s) { |
| 133 if (this->getColorStage(s).getEffect()->willReadDstColor()) { | 147 if (this->getColorStage(s).getEffect()->willReadDstColor()) { |
| 134 return true; | 148 return true; |
| 135 } | 149 } |
| 136 } | 150 } |
| 137 } | 151 } |
| 138 for (int s = 0; s < this->numCoverageStages(); ++s) { | 152 for (int s = 0; s < this->numCoverageStages(); ++s) { |
| 139 if (this->getCoverageStage(s).getEffect()->willReadDstColor()) { | 153 if (this->getCoverageStage(s).getEffect()->willReadDstColor()) { |
| 140 return true; | 154 return true; |
| 141 } | 155 } |
| 142 } | 156 } |
| 157 if (this->hasGeometryProcessor()) { |
| 158 if (fGeometryProcessor->getEffect()->willReadDstColor()) { |
| 159 return true; |
| 160 } |
| 161 } |
| 143 return false; | 162 return false; |
| 144 } | 163 } |
| 145 | 164 |
| 146 //////////////////////////////////////////////////////////////////////////////// | 165 //////////////////////////////////////////////////////////////////////////////// |
| 147 | 166 |
| 148 // Some blend modes allow folding a fractional coverage value into the color's a
lpha channel, while | 167 // Some blend modes allow folding a fractional coverage value into the color's a
lpha channel, while |
| 149 // others will blend incorrectly. | 168 // others will blend incorrectly. |
| 150 bool GrRODrawState::canTweakAlphaForCoverage() const { | 169 bool GrRODrawState::canTweakAlphaForCoverage() const { |
| 151 /* | 170 /* |
| 152 The fractional coverage is f. | 171 The fractional coverage is f. |
| 153 The src and dst coeffs are Cs and Cd. | 172 The src and dst coeffs are Cs and Cd. |
| 154 The dst and src colors are S and D. | 173 The dst and src colors are S and D. |
| 155 We want the blend to compute: f*Cs*S + (f*Cd + (1-f))D. By tweaking the sou
rce color's alpha | 174 We want the blend to compute: f*Cs*S + (f*Cd + (1-f))D. By tweaking the sou
rce color's alpha |
| 156 we're replacing S with S'=fS. It's obvious that that first term will always
be ok. The second | 175 we're replacing S with S'=fS. It's obvious that that first term will always
be ok. The second |
| 157 term can be rearranged as [1-(1-Cd)f]D. By substituting in the various poss
ibilities for Cd we | 176 term can be rearranged as [1-(1-Cd)f]D. By substituting in the various poss
ibilities for Cd we |
| 158 find that only 1, ISA, and ISC produce the correct destination when applied
to S' and D. | 177 find that only 1, ISA, and ISC produce the correct destination when applied
to S' and D. |
| 159 Also, if we're directly rendering coverage (isCoverageDrawing) then coverag
e is treated as | 178 Also, if we're directly rendering coverage (isCoverageDrawing) then coverag
e is treated as |
| 160 color by definition. | 179 color by definition. |
| 161 */ | 180 */ |
| 162 return kOne_GrBlendCoeff == fDstBlend || | 181 return kOne_GrBlendCoeff == fDstBlend || |
| 163 kISA_GrBlendCoeff == fDstBlend || | 182 kISA_GrBlendCoeff == fDstBlend || |
| 164 kISC_GrBlendCoeff == fDstBlend || | 183 kISC_GrBlendCoeff == fDstBlend || |
| 165 this->isCoverageDrawing(); | 184 this->isCoverageDrawing(); |
| 166 } | 185 } |
| 167 | 186 |
| OLD | NEW |