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 | 9 |
10 #include "GrDrawTargetCaps.h" | 10 #include "GrDrawTargetCaps.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 | 41 |
42 bool usingVertexCoverage = this->hasCoverageVertexAttribute(); | 42 bool usingVertexCoverage = this->hasCoverageVertexAttribute(); |
43 if (!usingVertexCoverage && this->fCoverage != that.fCoverage) { | 43 if (!usingVertexCoverage && this->fCoverage != that.fCoverage) { |
44 return false; | 44 return false; |
45 } | 45 } |
46 | 46 |
47 bool explicitLocalCoords = this->hasLocalCoordAttribute(); | 47 bool explicitLocalCoords = this->hasLocalCoordAttribute(); |
48 if (this->hasGeometryProcessor()) { | 48 if (this->hasGeometryProcessor()) { |
49 if (!that.hasGeometryProcessor()) { | 49 if (!that.hasGeometryProcessor()) { |
50 return false; | 50 return false; |
51 } else if (!GrEffectStage::AreCompatible(*this->getGeometryProcessor(), | 51 } else if (!GrProcessorStage::AreCompatible(*this->getGeometryProcessor(
), |
52 *that.getGeometryProcessor(), | 52 *that.getGeometryProcessor()
, |
53 explicitLocalCoords)) { | 53 explicitLocalCoords)) { |
54 return false; | 54 return false; |
55 } | 55 } |
56 } else if (that.hasGeometryProcessor()) { | 56 } else if (that.hasGeometryProcessor()) { |
57 return false; | 57 return false; |
58 } | 58 } |
59 | 59 |
60 for (int i = 0; i < this->numColorStages(); i++) { | 60 for (int i = 0; i < this->numColorStages(); i++) { |
61 if (!GrEffectStage::AreCompatible(this->getColorStage(i), that.getColorS
tage(i), | 61 if (!GrProcessorStage::AreCompatible(this->getColorStage(i), that.getCol
orStage(i), |
62 explicitLocalCoords)) { | 62 explicitLocalCoords)) { |
63 return false; | 63 return false; |
64 } | 64 } |
65 } | 65 } |
66 for (int i = 0; i < this->numCoverageStages(); i++) { | 66 for (int i = 0; i < this->numCoverageStages(); i++) { |
67 if (!GrEffectStage::AreCompatible(this->getCoverageStage(i), that.getCov
erageStage(i), | 67 if (!GrProcessorStage::AreCompatible(this->getCoverageStage(i), that.get
CoverageStage(i), |
68 explicitLocalCoords)) { | 68 explicitLocalCoords)) { |
69 return false; | 69 return false; |
70 } | 70 } |
71 } | 71 } |
72 | 72 |
73 SkASSERT(0 == memcmp(this->fFixedFunctionVertexAttribIndices, | 73 SkASSERT(0 == memcmp(this->fFixedFunctionVertexAttribIndices, |
74 that.fFixedFunctionVertexAttribIndices, | 74 that.fFixedFunctionVertexAttribIndices, |
75 sizeof(this->fFixedFunctionVertexAttribIndices))); | 75 sizeof(this->fFixedFunctionVertexAttribIndices))); |
76 | 76 |
77 return true; | 77 return true; |
78 } | 78 } |
79 | 79 |
80 //////////////////////////////////////////////////////////////////////////////// | 80 //////////////////////////////////////////////////////////////////////////////// |
81 | 81 |
82 bool GrRODrawState::validateVertexAttribs() const { | 82 bool GrRODrawState::validateVertexAttribs() const { |
83 // check consistency of effects and attributes | 83 // check consistency of effects and attributes |
84 GrSLType slTypes[kMaxVertexAttribCnt]; | 84 GrSLType slTypes[kMaxVertexAttribCnt]; |
85 for (int i = 0; i < kMaxVertexAttribCnt; ++i) { | 85 for (int i = 0; i < kMaxVertexAttribCnt; ++i) { |
86 slTypes[i] = static_cast<GrSLType>(-1); | 86 slTypes[i] = static_cast<GrSLType>(-1); |
87 } | 87 } |
88 | 88 |
89 if (this->hasGeometryProcessor()) { | 89 if (this->hasGeometryProcessor()) { |
90 const GrEffectStage& stage = *this->getGeometryProcessor(); | 90 const GrGeometryStage& stage = *this->getGeometryProcessor(); |
91 const GrEffect* effect = stage.getEffect(); | 91 const GrGeometryProcessor* gp = stage.getGeometryProcessor(); |
92 SkASSERT(effect); | 92 SkASSERT(gp); |
93 // make sure that any attribute indices have the correct binding type, t
hat the attrib | 93 // make sure that any attribute indices have the correct binding type, t
hat the attrib |
94 // type and effect's shader lang type are compatible, and that attribute
s shared by | 94 // type and effect's shader lang type are compatible, and that attribute
s shared by |
95 // multiple effects use the same shader lang type. | 95 // multiple effects use the same shader lang type. |
96 const GrEffect::VertexAttribArray& s = effect->getVertexAttribs(); | 96 const GrGeometryProcessor::VertexAttribArray& s = gp->getVertexAttribs()
; |
97 | 97 |
98 int effectIndex = 0; | 98 int effectIndex = 0; |
99 for (int index = 0; index < fVACount; index++) { | 99 for (int index = 0; index < fVACount; index++) { |
100 if (kEffect_GrVertexAttribBinding != fVAPtr[index].fBinding) { | 100 if (kGeometryProcessor_GrVertexAttribBinding != fVAPtr[index].fBindi
ng) { |
101 // we only care about effect bindings | 101 // we only care about effect bindings |
102 continue; | 102 continue; |
103 } | 103 } |
104 SkASSERT(effectIndex < s.count()); | 104 SkASSERT(effectIndex < s.count()); |
105 GrSLType effectSLType = s[effectIndex].getType(); | 105 GrSLType effectSLType = s[effectIndex].getType(); |
106 GrVertexAttribType attribType = fVAPtr[index].fType; | 106 GrVertexAttribType attribType = fVAPtr[index].fType; |
107 int slVecCount = GrSLTypeVectorCount(effectSLType); | 107 int slVecCount = GrSLTypeVectorCount(effectSLType); |
108 int attribVecCount = GrVertexAttribTypeVectorCount(attribType); | 108 int attribVecCount = GrVertexAttribTypeVectorCount(attribType); |
109 if (slVecCount != attribVecCount || | 109 if (slVecCount != attribVecCount || |
110 (static_cast<GrSLType>(-1) != slTypes[index] && slTypes[index] !
= effectSLType)) { | 110 (static_cast<GrSLType>(-1) != slTypes[index] && slTypes[index] !
= effectSLType)) { |
(...skipping 20 matching lines...) Expand all Loading... |
131 // Initialize to an unknown starting coverage if per-vertex coverage is spec
ified. | 131 // Initialize to an unknown starting coverage if per-vertex coverage is spec
ified. |
132 if (this->hasCoverageVertexAttribute()) { | 132 if (this->hasCoverageVertexAttribute()) { |
133 validComponentFlags = 0; | 133 validComponentFlags = 0; |
134 } else { | 134 } else { |
135 coverage = fCoverage; | 135 coverage = fCoverage; |
136 validComponentFlags = kRGBA_GrColorComponentFlags; | 136 validComponentFlags = kRGBA_GrColorComponentFlags; |
137 } | 137 } |
138 | 138 |
139 // Run through the coverage stages and see if the coverage will be all ones
at the end. | 139 // Run through the coverage stages and see if the coverage will be all ones
at the end. |
140 if (this->hasGeometryProcessor()) { | 140 if (this->hasGeometryProcessor()) { |
141 const GrEffect* effect = fGeometryProcessor->getEffect(); | 141 const GrGeometryProcessor* gp = fGeometryProcessor->getGeometryProcessor
(); |
142 effect->getConstantColorComponents(&coverage, &validComponentFlags); | 142 gp->getConstantColorComponents(&coverage, &validComponentFlags); |
143 } | 143 } |
144 for (int s = 0; s < this->numCoverageStages(); ++s) { | 144 for (int s = 0; s < this->numCoverageStages(); ++s) { |
145 const GrEffect* effect = this->getCoverageStage(s).getEffect(); | 145 const GrProcessor* processor = this->getCoverageStage(s).getProcessor(); |
146 effect->getConstantColorComponents(&coverage, &validComponentFlags); | 146 processor->getConstantColorComponents(&coverage, &validComponentFlags); |
147 } | 147 } |
148 return (kRGBA_GrColorComponentFlags == validComponentFlags) && (0xffffffff =
= coverage); | 148 return (kRGBA_GrColorComponentFlags == validComponentFlags) && (0xffffffff =
= coverage); |
149 } | 149 } |
150 | 150 |
151 //////////////////////////////////////////////////////////////////////////////// | 151 //////////////////////////////////////////////////////////////////////////////// |
152 | 152 |
153 bool GrRODrawState::willEffectReadDstColor() const { | 153 bool GrRODrawState::willEffectReadDstColor() const { |
154 if (!this->isColorWriteDisabled()) { | 154 if (!this->isColorWriteDisabled()) { |
155 for (int s = 0; s < this->numColorStages(); ++s) { | 155 for (int s = 0; s < this->numColorStages(); ++s) { |
156 if (this->getColorStage(s).getEffect()->willReadDstColor()) { | 156 if (this->getColorStage(s).getFragmentProcessor()->willReadDstColor(
)) { |
157 return true; | 157 return true; |
158 } | 158 } |
159 } | 159 } |
160 } | 160 } |
161 for (int s = 0; s < this->numCoverageStages(); ++s) { | 161 for (int s = 0; s < this->numCoverageStages(); ++s) { |
162 if (this->getCoverageStage(s).getEffect()->willReadDstColor()) { | 162 if (this->getCoverageStage(s).getFragmentProcessor()->willReadDstColor()
) { |
163 return true; | 163 return true; |
164 } | 164 } |
165 } | 165 } |
166 if (this->hasGeometryProcessor()) { | |
167 if (fGeometryProcessor->getEffect()->willReadDstColor()) { | |
168 return true; | |
169 } | |
170 } | |
171 return false; | 166 return false; |
172 } | 167 } |
173 | 168 |
174 //////////////////////////////////////////////////////////////////////////////// | 169 //////////////////////////////////////////////////////////////////////////////// |
175 | 170 |
176 GrRODrawState::BlendOptFlags GrRODrawState::getBlendOpts(bool forceCoverage, | 171 GrRODrawState::BlendOptFlags GrRODrawState::getBlendOpts(bool forceCoverage, |
177 GrBlendCoeff* srcCoeff, | 172 GrBlendCoeff* srcCoeff, |
178 GrBlendCoeff* dstCoeff)
const { | 173 GrBlendCoeff* dstCoeff)
const { |
179 GrBlendCoeff bogusSrcCoeff, bogusDstCoeff; | 174 GrBlendCoeff bogusSrcCoeff, bogusDstCoeff; |
180 if (NULL == srcCoeff) { | 175 if (NULL == srcCoeff) { |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 validComponentFlags = 0; | 307 validComponentFlags = 0; |
313 color = 0; // not strictly necessary but we get false alarms from to
ols about uninit. | 308 color = 0; // not strictly necessary but we get false alarms from to
ols about uninit. |
314 } | 309 } |
315 } else { | 310 } else { |
316 validComponentFlags = kRGBA_GrColorComponentFlags; | 311 validComponentFlags = kRGBA_GrColorComponentFlags; |
317 color = this->getColor(); | 312 color = this->getColor(); |
318 } | 313 } |
319 | 314 |
320 // Run through the color stages | 315 // Run through the color stages |
321 for (int s = 0; s < this->numColorStages(); ++s) { | 316 for (int s = 0; s < this->numColorStages(); ++s) { |
322 const GrEffect* effect = this->getColorStage(s).getEffect(); | 317 const GrProcessor* processor = this->getColorStage(s).getProcessor(); |
323 effect->getConstantColorComponents(&color, &validComponentFlags); | 318 processor->getConstantColorComponents(&color, &validComponentFlags); |
324 } | 319 } |
325 | 320 |
326 // Check whether coverage is treated as color. If so we run through the cove
rage computation. | 321 // Check whether coverage is treated as color. If so we run through the cove
rage computation. |
327 if (this->isCoverageDrawing()) { | 322 if (this->isCoverageDrawing()) { |
328 // The shader generated for coverage drawing runs the full coverage comp
utation and then | 323 // The shader generated for coverage drawing runs the full coverage comp
utation and then |
329 // makes the shader output be the multiplication of color and coverage.
We mirror that here. | 324 // makes the shader output be the multiplication of color and coverage.
We mirror that here. |
330 GrColor coverage; | 325 GrColor coverage; |
331 uint32_t coverageComponentFlags; | 326 uint32_t coverageComponentFlags; |
332 if (this->hasCoverageVertexAttribute()) { | 327 if (this->hasCoverageVertexAttribute()) { |
333 coverageComponentFlags = 0; | 328 coverageComponentFlags = 0; |
334 coverage = 0; // suppresses any warnings. | 329 coverage = 0; // suppresses any warnings. |
335 } else { | 330 } else { |
336 coverageComponentFlags = kRGBA_GrColorComponentFlags; | 331 coverageComponentFlags = kRGBA_GrColorComponentFlags; |
337 coverage = this->getCoverageColor(); | 332 coverage = this->getCoverageColor(); |
338 } | 333 } |
339 | 334 |
340 // Run through the coverage stages | 335 // Run through the coverage stages |
341 for (int s = 0; s < this->numCoverageStages(); ++s) { | 336 for (int s = 0; s < this->numCoverageStages(); ++s) { |
342 const GrEffect* effect = this->getCoverageStage(s).getEffect(); | 337 const GrProcessor* processor = this->getCoverageStage(s).getProcesso
r(); |
343 effect->getConstantColorComponents(&coverage, &coverageComponentFlag
s); | 338 processor->getConstantColorComponents(&coverage, &coverageComponentF
lags); |
344 } | 339 } |
345 | 340 |
346 // Since the shader will multiply coverage and color, the only way the f
inal A==1 is if | 341 // Since the shader will multiply coverage and color, the only way the f
inal A==1 is if |
347 // coverage and color both have A==1. | 342 // coverage and color both have A==1. |
348 return (kA_GrColorComponentFlag & validComponentFlags & coverageComponen
tFlags) && | 343 return (kA_GrColorComponentFlag & validComponentFlags & coverageComponen
tFlags) && |
349 0xFF == GrColorUnpackA(color) && 0xFF == GrColorUnpackA(coverage
); | 344 0xFF == GrColorUnpackA(color) && 0xFF == GrColorUnpackA(coverage
); |
350 | 345 |
351 } | 346 } |
352 | 347 |
353 return (kA_GrColorComponentFlag & validComponentFlags) && 0xFF == GrColorUnp
ackA(color); | 348 return (kA_GrColorComponentFlag & validComponentFlags) && 0xFF == GrColorUnp
ackA(color); |
354 } | 349 } |
355 | 350 |
OLD | NEW |