| 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 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 | 229 |
| 230 bool GrDrawState::srcAlphaWillBeOne(GrAttribBindings bindings) const { | 230 bool GrDrawState::srcAlphaWillBeOne(GrAttribBindings bindings) const { |
| 231 | 231 |
| 232 uint32_t validComponentFlags; | 232 uint32_t validComponentFlags; |
| 233 GrColor color; | 233 GrColor color; |
| 234 // Check if per-vertex or constant color may have partial alpha | 234 // Check if per-vertex or constant color may have partial alpha |
| 235 if (bindings & kColor_AttribBindingsBit) { | 235 if (bindings & kColor_AttribBindingsBit) { |
| 236 validComponentFlags = 0; | 236 validComponentFlags = 0; |
| 237 color = 0; // not strictly necessary but we get false alarms from tools
about uninit. | 237 color = 0; // not strictly necessary but we get false alarms from tools
about uninit. |
| 238 } else { | 238 } else { |
| 239 validComponentFlags = GrEffect::kAll_ValidComponentFlags; | 239 validComponentFlags = kRGBA_GrColorComponentFlags; |
| 240 color = this->getColor(); | 240 color = this->getColor(); |
| 241 } | 241 } |
| 242 | 242 |
| 243 // Run through the color stages | 243 // Run through the color stages |
| 244 int stageCnt = getFirstCoverageStage(); | 244 int stageCnt = getFirstCoverageStage(); |
| 245 for (int s = 0; s < stageCnt; ++s) { | 245 for (int s = 0; s < stageCnt; ++s) { |
| 246 const GrEffectRef* effect = this->getStage(s).getEffect(); | 246 const GrEffectRef* effect = this->getStage(s).getEffect(); |
| 247 if (NULL != effect) { | 247 if (NULL != effect) { |
| 248 (*effect)->getConstantColorComponents(&color, &validComponentFlags); | 248 (*effect)->getConstantColorComponents(&color, &validComponentFlags); |
| 249 } | 249 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 268 color |= (SkMulDiv255Round(a, b) << (c * 8)); | 268 color |= (SkMulDiv255Round(a, b) << (c * 8)); |
| 269 } | 269 } |
| 270 } | 270 } |
| 271 for (int s = this->getFirstCoverageStage(); s < GrDrawState::kNumStages;
++s) { | 271 for (int s = this->getFirstCoverageStage(); s < GrDrawState::kNumStages;
++s) { |
| 272 const GrEffectRef* effect = this->getStage(s).getEffect(); | 272 const GrEffectRef* effect = this->getStage(s).getEffect(); |
| 273 if (NULL != effect) { | 273 if (NULL != effect) { |
| 274 (*effect)->getConstantColorComponents(&color, &validComponentFla
gs); | 274 (*effect)->getConstantColorComponents(&color, &validComponentFla
gs); |
| 275 } | 275 } |
| 276 } | 276 } |
| 277 } | 277 } |
| 278 return (GrEffect::kA_ValidComponentFlag & validComponentFlags) && 0xff == Gr
ColorUnpackA(color); | 278 return (kA_GrColorComponentFlag & validComponentFlags) && 0xff == GrColorUnp
ackA(color); |
| 279 } | 279 } |
| 280 | 280 |
| 281 bool GrDrawState::hasSolidCoverage(GrAttribBindings bindings) const { | 281 bool GrDrawState::hasSolidCoverage(GrAttribBindings bindings) const { |
| 282 // If we're drawing coverage directly then coverage is effectively treated a
s color. | 282 // If we're drawing coverage directly then coverage is effectively treated a
s color. |
| 283 if (this->isCoverageDrawing()) { | 283 if (this->isCoverageDrawing()) { |
| 284 return true; | 284 return true; |
| 285 } | 285 } |
| 286 | 286 |
| 287 GrColor coverage; | 287 GrColor coverage; |
| 288 uint32_t validComponentFlags; | 288 uint32_t validComponentFlags; |
| 289 // Initialize to an unknown starting coverage if per-vertex coverage is spec
ified. | 289 // Initialize to an unknown starting coverage if per-vertex coverage is spec
ified. |
| 290 if (bindings & kCoverage_AttribBindingsBit) { | 290 if (bindings & kCoverage_AttribBindingsBit) { |
| 291 validComponentFlags = 0; | 291 validComponentFlags = 0; |
| 292 } else { | 292 } else { |
| 293 coverage = fCommon.fCoverage; | 293 coverage = fCommon.fCoverage; |
| 294 validComponentFlags = GrEffect::kAll_ValidComponentFlags; | 294 validComponentFlags = kRGBA_GrColorComponentFlags; |
| 295 } | 295 } |
| 296 | 296 |
| 297 // Run through the coverage stages and see if the coverage will be all ones
at the end. | 297 // Run through the coverage stages and see if the coverage will be all ones
at the end. |
| 298 for (int s = this->getFirstCoverageStage(); s < GrDrawState::kNumStages; ++s
) { | 298 for (int s = this->getFirstCoverageStage(); s < GrDrawState::kNumStages; ++s
) { |
| 299 const GrEffectRef* effect = this->getStage(s).getEffect(); | 299 const GrEffectRef* effect = this->getStage(s).getEffect(); |
| 300 if (NULL != effect) { | 300 if (NULL != effect) { |
| 301 (*effect)->getConstantColorComponents(&coverage, &validComponentFlag
s); | 301 (*effect)->getConstantColorComponents(&coverage, &validComponentFlag
s); |
| 302 } | 302 } |
| 303 } | 303 } |
| 304 return (GrEffect::kAll_ValidComponentFlags == validComponentFlags) && (0xff
ffffff == coverage); | 304 return (kRGBA_GrColorComponentFlags == validComponentFlags) && (0xffffffff
== coverage); |
| 305 } | 305 } |
| 306 | 306 |
| 307 //////////////////////////////////////////////////////////////////////////////// | 307 //////////////////////////////////////////////////////////////////////////////// |
| 308 | 308 |
| 309 // Some blend modes allow folding a fractional coverage value into the color's a
lpha channel, while | 309 // Some blend modes allow folding a fractional coverage value into the color's a
lpha channel, while |
| 310 // others will blend incorrectly. | 310 // others will blend incorrectly. |
| 311 bool GrDrawState::canTweakAlphaForCoverage() const { | 311 bool GrDrawState::canTweakAlphaForCoverage() const { |
| 312 /* | 312 /* |
| 313 The fractional coverage is f. | 313 The fractional coverage is f. |
| 314 The src and dst coeffs are Cs and Cd. | 314 The src and dst coeffs are Cs and Cd. |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 } | 505 } |
| 506 fRestoreMask |= (1 << s); | 506 fRestoreMask |= (1 << s); |
| 507 GrEffectStage* stage = drawState->fStages + s; | 507 GrEffectStage* stage = drawState->fStages + s; |
| 508 stage->saveCoordChange(&fSavedCoordChanges[s]); | 508 stage->saveCoordChange(&fSavedCoordChanges[s]); |
| 509 stage->localCoordChange(invVM); | 509 stage->localCoordChange(invVM); |
| 510 } | 510 } |
| 511 } | 511 } |
| 512 drawState->viewMatrix()->reset(); | 512 drawState->viewMatrix()->reset(); |
| 513 return true; | 513 return true; |
| 514 } | 514 } |
| OLD | NEW |