OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "GrDrawState.h" | 8 #include "GrDrawState.h" |
9 #include "GrPaint.h" | 9 #include "GrPaint.h" |
10 | 10 |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 bool GrDrawState::validateVertexAttribs() const { | 144 bool GrDrawState::validateVertexAttribs() const { |
145 // check consistency of effects and attributes | 145 // check consistency of effects and attributes |
146 GrSLType slTypes[kMaxVertexAttribCnt]; | 146 GrSLType slTypes[kMaxVertexAttribCnt]; |
147 for (int i = 0; i < kMaxVertexAttribCnt; ++i) { | 147 for (int i = 0; i < kMaxVertexAttribCnt; ++i) { |
148 slTypes[i] = static_cast<GrSLType>(-1); | 148 slTypes[i] = static_cast<GrSLType>(-1); |
149 } | 149 } |
150 int totalStages = fColorStages.count() + fCoverageStages.count(); | 150 int totalStages = fColorStages.count() + fCoverageStages.count(); |
151 for (int s = 0; s < totalStages; ++s) { | 151 for (int s = 0; s < totalStages; ++s) { |
152 int covIdx = s - fColorStages.count(); | 152 int covIdx = s - fColorStages.count(); |
153 const GrEffectStage& stage = covIdx < 0 ? fColorStages[s] : fCoverageSta
ges[covIdx]; | 153 const GrEffectStage& stage = covIdx < 0 ? fColorStages[s] : fCoverageSta
ges[covIdx]; |
154 const GrEffectRef* effect = stage.getEffect(); | 154 const GrEffect* effect = stage.getEffect(); |
155 SkASSERT(NULL != effect); | 155 SkASSERT(NULL != effect); |
156 // make sure that any attribute indices have the correct binding type, t
hat the attrib | 156 // make sure that any attribute indices have the correct binding type, t
hat the attrib |
157 // type and effect's shader lang type are compatible, and that attribute
s shared by | 157 // type and effect's shader lang type are compatible, and that attribute
s shared by |
158 // multiple effects use the same shader lang type. | 158 // multiple effects use the same shader lang type. |
159 const int* attributeIndices = stage.getVertexAttribIndices(); | 159 const int* attributeIndices = stage.getVertexAttribIndices(); |
160 int numAttributes = stage.getVertexAttribIndexCount(); | 160 int numAttributes = stage.getVertexAttribIndexCount(); |
161 for (int i = 0; i < numAttributes; ++i) { | 161 for (int i = 0; i < numAttributes; ++i) { |
162 int attribIndex = attributeIndices[i]; | 162 int attribIndex = attributeIndices[i]; |
163 if (attribIndex >= fVACount || | 163 if (attribIndex >= fVACount || |
164 kEffect_GrVertexAttribBinding != fVAPtr[attribIndex].fBinding) { | 164 kEffect_GrVertexAttribBinding != fVAPtr[attribIndex].fBinding) { |
165 return false; | 165 return false; |
166 } | 166 } |
167 | 167 |
168 GrSLType effectSLType = (*effect)->vertexAttribType(i); | 168 GrSLType effectSLType = effect->vertexAttribType(i); |
169 GrVertexAttribType attribType = fVAPtr[attribIndex].fType; | 169 GrVertexAttribType attribType = fVAPtr[attribIndex].fType; |
170 int slVecCount = GrSLTypeVectorCount(effectSLType); | 170 int slVecCount = GrSLTypeVectorCount(effectSLType); |
171 int attribVecCount = GrVertexAttribTypeVectorCount(attribType); | 171 int attribVecCount = GrVertexAttribTypeVectorCount(attribType); |
172 if (slVecCount != attribVecCount || | 172 if (slVecCount != attribVecCount || |
173 (static_cast<GrSLType>(-1) != slTypes[attribIndex] && | 173 (static_cast<GrSLType>(-1) != slTypes[attribIndex] && |
174 slTypes[attribIndex] != effectSLType)) { | 174 slTypes[attribIndex] != effectSLType)) { |
175 return false; | 175 return false; |
176 } | 176 } |
177 slTypes[attribIndex] = effectSLType; | 177 slTypes[attribIndex] = effectSLType; |
178 } | 178 } |
179 } | 179 } |
180 | 180 |
181 return true; | 181 return true; |
182 } | 182 } |
183 | 183 |
184 bool GrDrawState::willEffectReadDstColor() const { | 184 bool GrDrawState::willEffectReadDstColor() const { |
185 if (!this->isColorWriteDisabled()) { | 185 if (!this->isColorWriteDisabled()) { |
186 for (int s = 0; s < fColorStages.count(); ++s) { | 186 for (int s = 0; s < fColorStages.count(); ++s) { |
187 if ((*fColorStages[s].getEffect())->willReadDstColor()) { | 187 if (fColorStages[s].getEffect()->willReadDstColor()) { |
188 return true; | 188 return true; |
189 } | 189 } |
190 } | 190 } |
191 } | 191 } |
192 for (int s = 0; s < fCoverageStages.count(); ++s) { | 192 for (int s = 0; s < fCoverageStages.count(); ++s) { |
193 if ((*fCoverageStages[s].getEffect())->willReadDstColor()) { | 193 if (fCoverageStages[s].getEffect()->willReadDstColor()) { |
194 return true; | 194 return true; |
195 } | 195 } |
196 } | 196 } |
197 return false; | 197 return false; |
198 } | 198 } |
199 | 199 |
200 //////////////////////////////////////////////////////////////////////////////// | 200 //////////////////////////////////////////////////////////////////////////////// |
201 | 201 |
202 bool GrDrawState::srcAlphaWillBeOne() const { | 202 bool GrDrawState::srcAlphaWillBeOne() const { |
203 uint32_t validComponentFlags; | 203 uint32_t validComponentFlags; |
204 GrColor color; | 204 GrColor color; |
205 // Check if per-vertex or constant color may have partial alpha | 205 // Check if per-vertex or constant color may have partial alpha |
206 if (this->hasColorVertexAttribute()) { | 206 if (this->hasColorVertexAttribute()) { |
207 validComponentFlags = 0; | 207 validComponentFlags = 0; |
208 color = 0; // not strictly necessary but we get false alarms from tools
about uninit. | 208 color = 0; // not strictly necessary but we get false alarms from tools
about uninit. |
209 } else { | 209 } else { |
210 validComponentFlags = kRGBA_GrColorComponentFlags; | 210 validComponentFlags = kRGBA_GrColorComponentFlags; |
211 color = this->getColor(); | 211 color = this->getColor(); |
212 } | 212 } |
213 | 213 |
214 // Run through the color stages | 214 // Run through the color stages |
215 for (int s = 0; s < fColorStages.count(); ++s) { | 215 for (int s = 0; s < fColorStages.count(); ++s) { |
216 const GrEffectRef* effect = fColorStages[s].getEffect(); | 216 const GrEffect* effect = fColorStages[s].getEffect(); |
217 (*effect)->getConstantColorComponents(&color, &validComponentFlags); | 217 effect->getConstantColorComponents(&color, &validComponentFlags); |
218 } | 218 } |
219 | 219 |
220 // Check whether coverage is treated as color. If so we run through the cove
rage computation. | 220 // Check whether coverage is treated as color. If so we run through the cove
rage computation. |
221 if (this->isCoverageDrawing()) { | 221 if (this->isCoverageDrawing()) { |
222 GrColor coverageColor = this->getCoverageColor(); | 222 GrColor coverageColor = this->getCoverageColor(); |
223 GrColor oldColor = color; | 223 GrColor oldColor = color; |
224 color = 0; | 224 color = 0; |
225 for (int c = 0; c < 4; ++c) { | 225 for (int c = 0; c < 4; ++c) { |
226 if (validComponentFlags & (1 << c)) { | 226 if (validComponentFlags & (1 << c)) { |
227 U8CPU a = (oldColor >> (c * 8)) & 0xff; | 227 U8CPU a = (oldColor >> (c * 8)) & 0xff; |
228 U8CPU b = (coverageColor >> (c * 8)) & 0xff; | 228 U8CPU b = (coverageColor >> (c * 8)) & 0xff; |
229 color |= (SkMulDiv255Round(a, b) << (c * 8)); | 229 color |= (SkMulDiv255Round(a, b) << (c * 8)); |
230 } | 230 } |
231 } | 231 } |
232 for (int s = 0; s < fCoverageStages.count(); ++s) { | 232 for (int s = 0; s < fCoverageStages.count(); ++s) { |
233 const GrEffectRef* effect = fCoverageStages[s].getEffect(); | 233 const GrEffect* effect = fCoverageStages[s].getEffect(); |
234 (*effect)->getConstantColorComponents(&color, &validComponentFlags); | 234 effect->getConstantColorComponents(&color, &validComponentFlags); |
235 } | 235 } |
236 } | 236 } |
237 return (kA_GrColorComponentFlag & validComponentFlags) && 0xff == GrColorUnp
ackA(color); | 237 return (kA_GrColorComponentFlag & validComponentFlags) && 0xff == GrColorUnp
ackA(color); |
238 } | 238 } |
239 | 239 |
240 bool GrDrawState::hasSolidCoverage() const { | 240 bool GrDrawState::hasSolidCoverage() const { |
241 // If we're drawing coverage directly then coverage is effectively treated a
s color. | 241 // If we're drawing coverage directly then coverage is effectively treated a
s color. |
242 if (this->isCoverageDrawing()) { | 242 if (this->isCoverageDrawing()) { |
243 return true; | 243 return true; |
244 } | 244 } |
245 | 245 |
246 GrColor coverage; | 246 GrColor coverage; |
247 uint32_t validComponentFlags; | 247 uint32_t validComponentFlags; |
248 // Initialize to an unknown starting coverage if per-vertex coverage is spec
ified. | 248 // Initialize to an unknown starting coverage if per-vertex coverage is spec
ified. |
249 if (this->hasCoverageVertexAttribute()) { | 249 if (this->hasCoverageVertexAttribute()) { |
250 validComponentFlags = 0; | 250 validComponentFlags = 0; |
251 } else { | 251 } else { |
252 coverage = fCoverage; | 252 coverage = fCoverage; |
253 validComponentFlags = kRGBA_GrColorComponentFlags; | 253 validComponentFlags = kRGBA_GrColorComponentFlags; |
254 } | 254 } |
255 | 255 |
256 // Run through the coverage stages and see if the coverage will be all ones
at the end. | 256 // Run through the coverage stages and see if the coverage will be all ones
at the end. |
257 for (int s = 0; s < fCoverageStages.count(); ++s) { | 257 for (int s = 0; s < fCoverageStages.count(); ++s) { |
258 const GrEffectRef* effect = fCoverageStages[s].getEffect(); | 258 const GrEffect* effect = fCoverageStages[s].getEffect(); |
259 (*effect)->getConstantColorComponents(&coverage, &validComponentFlags); | 259 effect->getConstantColorComponents(&coverage, &validComponentFlags); |
260 } | 260 } |
261 return (kRGBA_GrColorComponentFlags == validComponentFlags) && (0xffffffff =
= coverage); | 261 return (kRGBA_GrColorComponentFlags == validComponentFlags) && (0xffffffff =
= coverage); |
262 } | 262 } |
263 | 263 |
264 //////////////////////////////////////////////////////////////////////////////// | 264 //////////////////////////////////////////////////////////////////////////////// |
265 | 265 |
266 // Some blend modes allow folding a fractional coverage value into the color's a
lpha channel, while | 266 // Some blend modes allow folding a fractional coverage value into the color's a
lpha channel, while |
267 // others will blend incorrectly. | 267 // others will blend incorrectly. |
268 bool GrDrawState::canTweakAlphaForCoverage() const { | 268 bool GrDrawState::canTweakAlphaForCoverage() const { |
269 /* | 269 /* |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 fDrawState->fColorStages[s].saveCoordChange(&fSavedCoordChanges[i]); | 466 fDrawState->fColorStages[s].saveCoordChange(&fSavedCoordChanges[i]); |
467 fDrawState->fColorStages[s].localCoordChange(coordChangeMatrix); | 467 fDrawState->fColorStages[s].localCoordChange(coordChangeMatrix); |
468 } | 468 } |
469 | 469 |
470 int numCoverageStages = fDrawState->numCoverageStages(); | 470 int numCoverageStages = fDrawState->numCoverageStages(); |
471 for (int s = 0; s < numCoverageStages; ++s, ++i) { | 471 for (int s = 0; s < numCoverageStages; ++s, ++i) { |
472 fDrawState->fCoverageStages[s].saveCoordChange(&fSavedCoordChanges[i]); | 472 fDrawState->fCoverageStages[s].saveCoordChange(&fSavedCoordChanges[i]); |
473 fDrawState->fCoverageStages[s].localCoordChange(coordChangeMatrix); | 473 fDrawState->fCoverageStages[s].localCoordChange(coordChangeMatrix); |
474 } | 474 } |
475 } | 475 } |
OLD | NEW |