| 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 |
| 11 bool GrDrawState::setIdentityViewMatrix() { | 11 bool GrDrawState::setIdentityViewMatrix() { |
| 12 SkMatrix invVM; | 12 if (fColorStages.count() || fCoverageStages.count()) { |
| 13 bool inverted = false; | 13 SkMatrix invVM; |
| 14 for (int s = 0; s < GrDrawState::kNumStages; ++s) { | 14 if (!fCommon.fViewMatrix.invert(&invVM)) { |
| 15 if (this->isStageEnabled(s)) { | 15 // sad trombone sound |
| 16 if (!inverted) { | 16 return false; |
| 17 if (!fCommon.fViewMatrix.invert(&invVM)) { | 17 } |
| 18 // sad trombone sound | 18 for (int s = 0; s < fColorStages.count(); ++s) { |
| 19 return false; | 19 fColorStages[s].localCoordChange(invVM); |
| 20 } | 20 } |
| 21 inverted = true; | 21 for (int s = 0; s < fCoverageStages.count(); ++s) { |
| 22 } | 22 fCoverageStages[s].localCoordChange(invVM); |
| 23 fStages[s].localCoordChange(invVM); | |
| 24 } | 23 } |
| 25 } | 24 } |
| 26 fCommon.fViewMatrix.reset(); | 25 fCommon.fViewMatrix.reset(); |
| 27 return true; | 26 return true; |
| 28 } | 27 } |
| 29 | 28 |
| 30 void GrDrawState::setFromPaint(const GrPaint& paint, const SkMatrix& vm, GrRende
rTarget* rt) { | 29 void GrDrawState::setFromPaint(const GrPaint& paint, const SkMatrix& vm, GrRende
rTarget* rt) { |
| 30 GrAssert(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); |
| 31 |
| 32 fColorStages.reset(); |
| 33 fCoverageStages.reset(); |
| 34 |
| 31 for (int i = 0; i < GrPaint::kMaxColorStages; ++i) { | 35 for (int i = 0; i < GrPaint::kMaxColorStages; ++i) { |
| 32 int s = i + GrPaint::kFirstColorStage; | |
| 33 if (paint.isColorStageEnabled(i)) { | 36 if (paint.isColorStageEnabled(i)) { |
| 34 fStages[s] = paint.getColorStage(i); | 37 fColorStages.push_back(paint.getColorStage(i)); |
| 35 } else { | |
| 36 fStages[s].setEffect(NULL); | |
| 37 } | 38 } |
| 38 } | 39 } |
| 39 | 40 |
| 40 this->setFirstCoverageStage(GrPaint::kFirstCoverageStage); | |
| 41 | |
| 42 for (int i = 0; i < GrPaint::kMaxCoverageStages; ++i) { | 41 for (int i = 0; i < GrPaint::kMaxCoverageStages; ++i) { |
| 43 int s = i + GrPaint::kFirstCoverageStage; | |
| 44 if (paint.isCoverageStageEnabled(i)) { | 42 if (paint.isCoverageStageEnabled(i)) { |
| 45 fStages[s] = paint.getCoverageStage(i); | 43 fCoverageStages.push_back(paint.getCoverageStage(i)); |
| 46 } else { | |
| 47 fStages[s].setEffect(NULL); | |
| 48 } | 44 } |
| 49 } | 45 } |
| 50 | 46 |
| 51 // disable all stages not accessible via the paint | |
| 52 for (int s = GrPaint::kTotalStages; s < GrDrawState::kNumStages; ++s) { | |
| 53 this->disableStage(s); | |
| 54 } | |
| 55 | |
| 56 this->setRenderTarget(rt); | 47 this->setRenderTarget(rt); |
| 57 | 48 |
| 58 fCommon.fViewMatrix = vm; | 49 fCommon.fViewMatrix = vm; |
| 59 | 50 |
| 60 // These have no equivalent in GrPaint, set them to defaults | 51 // These have no equivalent in GrPaint, set them to defaults |
| 61 fCommon.fBlendConstant = 0x0; | 52 fCommon.fBlendConstant = 0x0; |
| 62 fCommon.fCoverage = 0xffffffff; | 53 fCommon.fCoverage = 0xffffffff; |
| 63 fCommon.fDrawFace = kBoth_DrawFace; | 54 fCommon.fDrawFace = kBoth_DrawFace; |
| 64 fCommon.fStencilSettings.setDisabled(); | 55 fCommon.fStencilSettings.setDisabled(); |
| 65 this->resetStateFlags(); | 56 this->resetStateFlags(); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 } | 146 } |
| 156 | 147 |
| 157 //////////////////////////////////////////////////////////////////////////////// | 148 //////////////////////////////////////////////////////////////////////////////// |
| 158 | 149 |
| 159 bool GrDrawState::validateVertexAttribs() const { | 150 bool GrDrawState::validateVertexAttribs() const { |
| 160 // check consistency of effects and attributes | 151 // check consistency of effects and attributes |
| 161 GrSLType slTypes[kMaxVertexAttribCnt]; | 152 GrSLType slTypes[kMaxVertexAttribCnt]; |
| 162 for (int i = 0; i < kMaxVertexAttribCnt; ++i) { | 153 for (int i = 0; i < kMaxVertexAttribCnt; ++i) { |
| 163 slTypes[i] = static_cast<GrSLType>(-1); | 154 slTypes[i] = static_cast<GrSLType>(-1); |
| 164 } | 155 } |
| 165 for (int s = 0; s < kNumStages; ++s) { | 156 int totalStages = fColorStages.count() + fCoverageStages.count(); |
| 166 if (this->isStageEnabled(s)) { | 157 for (int s = 0; s < totalStages; ++s) { |
| 167 const GrEffectStage& stage = fStages[s]; | 158 int covIdx = s - fColorStages.count(); |
| 168 const GrEffectRef* effect = stage.getEffect(); | 159 const GrEffectStage& stage = covIdx < 0 ? fColorStages[s] : fCoverageSta
ges[covIdx]; |
| 169 // make sure that any attribute indices have the correct binding typ
e, that the attrib | 160 const GrEffectRef* effect = stage.getEffect(); |
| 170 // type and effect's shader lang type are compatible, and that attri
butes shared by | 161 GrAssert(NULL != effect); |
| 171 // multiple effects use the same shader lang type. | 162 // make sure that any attribute indices have the correct binding type, t
hat the attrib |
| 172 const int* attributeIndices = stage.getVertexAttribIndices(); | 163 // type and effect's shader lang type are compatible, and that attribute
s shared by |
| 173 int numAttributes = stage.getVertexAttribIndexCount(); | 164 // multiple effects use the same shader lang type. |
| 174 for (int i = 0; i < numAttributes; ++i) { | 165 const int* attributeIndices = stage.getVertexAttribIndices(); |
| 175 int attribIndex = attributeIndices[i]; | 166 int numAttributes = stage.getVertexAttribIndexCount(); |
| 176 if (attribIndex >= fCommon.fVACount || | 167 for (int i = 0; i < numAttributes; ++i) { |
| 177 kEffect_GrVertexAttribBinding != fCommon.fVAPtr[attribIndex]
.fBinding) { | 168 int attribIndex = attributeIndices[i]; |
| 178 return false; | 169 if (attribIndex >= fCommon.fVACount || |
| 179 } | 170 kEffect_GrVertexAttribBinding != fCommon.fVAPtr[attribIndex].fBi
nding) { |
| 171 return false; |
| 172 } |
| 180 | 173 |
| 181 GrSLType effectSLType = (*effect)->vertexAttribType(i); | 174 GrSLType effectSLType = (*effect)->vertexAttribType(i); |
| 182 GrVertexAttribType attribType = fCommon.fVAPtr[attribIndex].fTyp
e; | 175 GrVertexAttribType attribType = fCommon.fVAPtr[attribIndex].fType; |
| 183 int slVecCount = GrSLTypeVectorCount(effectSLType); | 176 int slVecCount = GrSLTypeVectorCount(effectSLType); |
| 184 int attribVecCount = GrVertexAttribTypeVectorCount(attribType); | 177 int attribVecCount = GrVertexAttribTypeVectorCount(attribType); |
| 185 if (slVecCount != attribVecCount || | 178 if (slVecCount != attribVecCount || |
| 186 (static_cast<GrSLType>(-1) != slTypes[attribIndex] && | 179 (static_cast<GrSLType>(-1) != slTypes[attribIndex] && |
| 187 slTypes[attribIndex] != effectSLType)) { | 180 slTypes[attribIndex] != effectSLType)) { |
| 188 return false; | 181 return false; |
| 189 } | |
| 190 slTypes[attribIndex] = effectSLType; | |
| 191 } | 182 } |
| 183 slTypes[attribIndex] = effectSLType; |
| 192 } | 184 } |
| 193 } | 185 } |
| 194 | 186 |
| 195 return true; | 187 return true; |
| 196 } | 188 } |
| 197 | 189 |
| 198 bool GrDrawState::willEffectReadDstColor() const { | 190 bool GrDrawState::willEffectReadDstColor() const { |
| 199 int startStage = this->isColorWriteDisabled() ? this->getFirstCoverageStage(
) : 0; | 191 if (!this->isColorWriteDisabled()) { |
| 200 for (int s = startStage; s < kNumStages; ++s) { | 192 for (int s = 0; s < fColorStages.count(); ++s) { |
| 201 if (this->isStageEnabled(s) && (*this->getStage(s).getEffect())->willRea
dDstColor()) { | 193 if ((*fColorStages[s].getEffect())->willReadDstColor()) { |
| 194 return true; |
| 195 } |
| 196 } |
| 197 } |
| 198 for (int s = 0; s < fCoverageStages.count(); ++s) { |
| 199 if ((*fCoverageStages[s].getEffect())->willReadDstColor()) { |
| 202 return true; | 200 return true; |
| 203 } | 201 } |
| 204 } | 202 } |
| 205 return false; | 203 return false; |
| 206 } | 204 } |
| 207 | 205 |
| 208 //////////////////////////////////////////////////////////////////////////////// | 206 //////////////////////////////////////////////////////////////////////////////// |
| 209 | 207 |
| 210 bool GrDrawState::srcAlphaWillBeOne() const { | 208 bool GrDrawState::srcAlphaWillBeOne() const { |
| 211 uint32_t validComponentFlags; | 209 uint32_t validComponentFlags; |
| 212 GrColor color; | 210 GrColor color; |
| 213 // Check if per-vertex or constant color may have partial alpha | 211 // Check if per-vertex or constant color may have partial alpha |
| 214 if (this->hasColorVertexAttribute()) { | 212 if (this->hasColorVertexAttribute()) { |
| 215 validComponentFlags = 0; | 213 validComponentFlags = 0; |
| 216 color = 0; // not strictly necessary but we get false alarms from tools
about uninit. | 214 color = 0; // not strictly necessary but we get false alarms from tools
about uninit. |
| 217 } else { | 215 } else { |
| 218 validComponentFlags = kRGBA_GrColorComponentFlags; | 216 validComponentFlags = kRGBA_GrColorComponentFlags; |
| 219 color = this->getColor(); | 217 color = this->getColor(); |
| 220 } | 218 } |
| 221 | 219 |
| 222 // Run through the color stages | 220 // Run through the color stages |
| 223 int stageCnt = getFirstCoverageStage(); | 221 for (int s = 0; s < fColorStages.count(); ++s) { |
| 224 for (int s = 0; s < stageCnt; ++s) { | 222 const GrEffectRef* effect = fColorStages[s].getEffect(); |
| 225 const GrEffectRef* effect = this->getStage(s).getEffect(); | 223 (*effect)->getConstantColorComponents(&color, &validComponentFlags); |
| 226 if (NULL != effect) { | |
| 227 (*effect)->getConstantColorComponents(&color, &validComponentFlags); | |
| 228 } | |
| 229 } | 224 } |
| 230 | 225 |
| 231 // Check if the color filter could introduce an alpha. | 226 // Check if the color filter could introduce an alpha. |
| 232 // We could skip the above work when this is true, but it is rare and the ri
ght fix is to make | 227 // We could skip the above work when this is true, but it is rare and the ri
ght fix is to make |
| 233 // the color filter a GrEffect and implement getConstantColorComponents() fo
r it. | 228 // the color filter a GrEffect and implement getConstantColorComponents() fo
r it. |
| 234 if (SkXfermode::kDst_Mode != this->getColorFilterMode()) { | 229 if (SkXfermode::kDst_Mode != this->getColorFilterMode()) { |
| 235 validComponentFlags = 0; | 230 validComponentFlags = 0; |
| 236 } | 231 } |
| 237 | 232 |
| 238 // Check whether coverage is treated as color. If so we run through the cove
rage computation. | 233 // Check whether coverage is treated as color. If so we run through the cove
rage computation. |
| 239 if (this->isCoverageDrawing()) { | 234 if (this->isCoverageDrawing()) { |
| 240 GrColor coverageColor = this->getCoverage(); | 235 GrColor coverageColor = this->getCoverage(); |
| 241 GrColor oldColor = color; | 236 GrColor oldColor = color; |
| 242 color = 0; | 237 color = 0; |
| 243 for (int c = 0; c < 4; ++c) { | 238 for (int c = 0; c < 4; ++c) { |
| 244 if (validComponentFlags & (1 << c)) { | 239 if (validComponentFlags & (1 << c)) { |
| 245 U8CPU a = (oldColor >> (c * 8)) & 0xff; | 240 U8CPU a = (oldColor >> (c * 8)) & 0xff; |
| 246 U8CPU b = (coverageColor >> (c * 8)) & 0xff; | 241 U8CPU b = (coverageColor >> (c * 8)) & 0xff; |
| 247 color |= (SkMulDiv255Round(a, b) << (c * 8)); | 242 color |= (SkMulDiv255Round(a, b) << (c * 8)); |
| 248 } | 243 } |
| 249 } | 244 } |
| 250 for (int s = this->getFirstCoverageStage(); s < GrDrawState::kNumStages;
++s) { | 245 for (int s = 0; s < fCoverageStages.count(); ++s) { |
| 251 const GrEffectRef* effect = this->getStage(s).getEffect(); | 246 const GrEffectRef* effect = fCoverageStages[s].getEffect(); |
| 252 if (NULL != effect) { | 247 (*effect)->getConstantColorComponents(&color, &validComponentFlags); |
| 253 (*effect)->getConstantColorComponents(&color, &validComponentFla
gs); | |
| 254 } | |
| 255 } | 248 } |
| 256 } | 249 } |
| 257 return (kA_GrColorComponentFlag & validComponentFlags) && 0xff == GrColorUnp
ackA(color); | 250 return (kA_GrColorComponentFlag & validComponentFlags) && 0xff == GrColorUnp
ackA(color); |
| 258 } | 251 } |
| 259 | 252 |
| 260 bool GrDrawState::hasSolidCoverage() const { | 253 bool GrDrawState::hasSolidCoverage() const { |
| 261 // If we're drawing coverage directly then coverage is effectively treated a
s color. | 254 // If we're drawing coverage directly then coverage is effectively treated a
s color. |
| 262 if (this->isCoverageDrawing()) { | 255 if (this->isCoverageDrawing()) { |
| 263 return true; | 256 return true; |
| 264 } | 257 } |
| 265 | 258 |
| 266 GrColor coverage; | 259 GrColor coverage; |
| 267 uint32_t validComponentFlags; | 260 uint32_t validComponentFlags; |
| 268 // Initialize to an unknown starting coverage if per-vertex coverage is spec
ified. | 261 // Initialize to an unknown starting coverage if per-vertex coverage is spec
ified. |
| 269 if (this->hasCoverageVertexAttribute()) { | 262 if (this->hasCoverageVertexAttribute()) { |
| 270 validComponentFlags = 0; | 263 validComponentFlags = 0; |
| 271 } else { | 264 } else { |
| 272 coverage = fCommon.fCoverage; | 265 coverage = fCommon.fCoverage; |
| 273 validComponentFlags = kRGBA_GrColorComponentFlags; | 266 validComponentFlags = kRGBA_GrColorComponentFlags; |
| 274 } | 267 } |
| 275 | 268 |
| 276 // Run through the coverage stages and see if the coverage will be all ones
at the end. | 269 // Run through the coverage stages and see if the coverage will be all ones
at the end. |
| 277 for (int s = this->getFirstCoverageStage(); s < GrDrawState::kNumStages; ++s
) { | 270 for (int s = 0; s < fCoverageStages.count(); ++s) { |
| 278 const GrEffectRef* effect = this->getStage(s).getEffect(); | 271 const GrEffectRef* effect = fCoverageStages[s].getEffect(); |
| 279 if (NULL != effect) { | 272 (*effect)->getConstantColorComponents(&coverage, &validComponentFlags); |
| 280 (*effect)->getConstantColorComponents(&coverage, &validComponentFlag
s); | |
| 281 } | |
| 282 } | 273 } |
| 283 return (kRGBA_GrColorComponentFlags == validComponentFlags) && (0xffffffff
== coverage); | 274 return (kRGBA_GrColorComponentFlags == validComponentFlags) && (0xffffffff =
= coverage); |
| 284 } | 275 } |
| 285 | 276 |
| 286 //////////////////////////////////////////////////////////////////////////////// | 277 //////////////////////////////////////////////////////////////////////////////// |
| 287 | 278 |
| 288 // Some blend modes allow folding a fractional coverage value into the color's a
lpha channel, while | 279 // Some blend modes allow folding a fractional coverage value into the color's a
lpha channel, while |
| 289 // others will blend incorrectly. | 280 // others will blend incorrectly. |
| 290 bool GrDrawState::canTweakAlphaForCoverage() const { | 281 bool GrDrawState::canTweakAlphaForCoverage() const { |
| 291 /* | 282 /* |
| 292 The fractional coverage is f. | 283 The fractional coverage is f. |
| 293 The src and dst coeffs are Cs and Cd. | 284 The src and dst coeffs are Cs and Cd. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 return kDisableBlend_BlendOptFlag | | 333 return kDisableBlend_BlendOptFlag | |
| 343 kEmitTransBlack_BlendOptFlag; | 334 kEmitTransBlack_BlendOptFlag; |
| 344 } else { | 335 } else { |
| 345 return kSkipDraw_BlendOptFlag; | 336 return kSkipDraw_BlendOptFlag; |
| 346 } | 337 } |
| 347 } | 338 } |
| 348 | 339 |
| 349 // check for coverage due to constant coverage, per-vertex coverage, or cove
rage stage | 340 // check for coverage due to constant coverage, per-vertex coverage, or cove
rage stage |
| 350 bool hasCoverage = forceCoverage || | 341 bool hasCoverage = forceCoverage || |
| 351 0xffffffff != this->getCoverage() || | 342 0xffffffff != this->getCoverage() || |
| 352 this->hasCoverageVertexAttribute(); | 343 this->hasCoverageVertexAttribute() || |
| 353 for (int s = this->getFirstCoverageStage(); !hasCoverage && s < GrDrawState:
:kNumStages; ++s) { | 344 fCoverageStages.count() > 0; |
| 354 if (this->isStageEnabled(s)) { | |
| 355 hasCoverage = true; | |
| 356 } | |
| 357 } | |
| 358 | 345 |
| 359 // if we don't have coverage we can check whether the dst | 346 // if we don't have coverage we can check whether the dst |
| 360 // has to read at all. If not, we'll disable blending. | 347 // has to read at all. If not, we'll disable blending. |
| 361 if (!hasCoverage) { | 348 if (!hasCoverage) { |
| 362 if (dstCoeffIsZero) { | 349 if (dstCoeffIsZero) { |
| 363 if (kOne_GrBlendCoeff == *srcCoeff) { | 350 if (kOne_GrBlendCoeff == *srcCoeff) { |
| 364 // if there is no coverage and coeffs are (1,0) then we | 351 // if there is no coverage and coeffs are (1,0) then we |
| 365 // won't need to read the dst at all, it gets replaced by src | 352 // won't need to read the dst at all, it gets replaced by src |
| 366 return kDisableBlend_BlendOptFlag; | 353 return kDisableBlend_BlendOptFlag; |
| 367 } else if (kZero_GrBlendCoeff == *srcCoeff) { | 354 } else if (kZero_GrBlendCoeff == *srcCoeff) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 // need blending. | 397 // need blending. |
| 411 return kDisableBlend_BlendOptFlag; | 398 return kDisableBlend_BlendOptFlag; |
| 412 } | 399 } |
| 413 return kNone_BlendOpt; | 400 return kNone_BlendOpt; |
| 414 } | 401 } |
| 415 | 402 |
| 416 //////////////////////////////////////////////////////////////////////////////// | 403 //////////////////////////////////////////////////////////////////////////////// |
| 417 | 404 |
| 418 void GrDrawState::AutoViewMatrixRestore::restore() { | 405 void GrDrawState::AutoViewMatrixRestore::restore() { |
| 419 if (NULL != fDrawState) { | 406 if (NULL != fDrawState) { |
| 407 GR_DEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;) |
| 420 fDrawState->fCommon.fViewMatrix = fViewMatrix; | 408 fDrawState->fCommon.fViewMatrix = fViewMatrix; |
| 421 for (int s = 0; s < GrDrawState::kNumStages; ++s) { | 409 GrAssert(fDrawState->numColorStages() >= fNumColorStages); |
| 422 if (fRestoreMask & (1 << s)) { | 410 int numCoverageStages = fSavedCoordChanges.count() - fNumColorStages; |
| 423 fDrawState->fStages[s].restoreCoordChange(fSavedCoordChanges[s])
; | 411 GrAssert(fDrawState->numCoverageStages() >= numCoverageStages); |
| 424 } | 412 |
| 413 int i = 0; |
| 414 for (int s = 0; s < fNumColorStages; ++s, ++i) { |
| 415 fDrawState->fColorStages[s].restoreCoordChange(fSavedCoordChanges[i]
); |
| 416 } |
| 417 for (int s = 0; s < numCoverageStages; ++s, ++i) { |
| 418 fDrawState->fCoverageStages[s].restoreCoordChange(fSavedCoordChanges
[i]); |
| 425 } | 419 } |
| 426 fDrawState = NULL; | 420 fDrawState = NULL; |
| 427 } | 421 } |
| 428 } | 422 } |
| 429 | 423 |
| 430 void GrDrawState::AutoViewMatrixRestore::set(GrDrawState* drawState, | 424 void GrDrawState::AutoViewMatrixRestore::set(GrDrawState* drawState, |
| 431 const SkMatrix& preconcatMatrix) { | 425 const SkMatrix& preconcatMatrix) { |
| 432 this->restore(); | 426 this->restore(); |
| 433 | 427 |
| 428 GrAssert(NULL == fDrawState); |
| 434 if (NULL == drawState || preconcatMatrix.isIdentity()) { | 429 if (NULL == drawState || preconcatMatrix.isIdentity()) { |
| 435 return; | 430 return; |
| 436 } | 431 } |
| 437 fDrawState = drawState; | 432 fDrawState = drawState; |
| 438 | 433 |
| 439 fRestoreMask = 0; | |
| 440 fViewMatrix = drawState->getViewMatrix(); | 434 fViewMatrix = drawState->getViewMatrix(); |
| 441 drawState->fCommon.fViewMatrix.preConcat(preconcatMatrix); | 435 drawState->fCommon.fViewMatrix.preConcat(preconcatMatrix); |
| 442 for (int s = 0; s < GrDrawState::kNumStages; ++s) { | 436 |
| 443 if (drawState->isStageEnabled(s)) { | 437 this->doEffectCoordChanges(preconcatMatrix); |
| 444 fRestoreMask |= (1 << s); | 438 GR_DEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;) |
| 445 drawState->fStages[s].saveCoordChange(&fSavedCoordChanges[s]); | |
| 446 drawState->fStages[s].localCoordChange(preconcatMatrix); | |
| 447 } | |
| 448 } | |
| 449 } | 439 } |
| 450 | 440 |
| 451 bool GrDrawState::AutoViewMatrixRestore::setIdentity(GrDrawState* drawState) { | 441 bool GrDrawState::AutoViewMatrixRestore::setIdentity(GrDrawState* drawState) { |
| 452 this->restore(); | 442 this->restore(); |
| 453 | 443 |
| 454 if (NULL == drawState) { | 444 if (NULL == drawState) { |
| 455 return false; | 445 return false; |
| 456 } | 446 } |
| 457 | 447 |
| 458 if (drawState->getViewMatrix().isIdentity()) { | 448 if (drawState->getViewMatrix().isIdentity()) { |
| 459 return true; | 449 return true; |
| 460 } | 450 } |
| 461 | 451 |
| 462 fViewMatrix = drawState->getViewMatrix(); | 452 fViewMatrix = drawState->getViewMatrix(); |
| 463 fRestoreMask = 0; | 453 if (0 == drawState->numTotalStages()) { |
| 464 for (int s = 0; s < GrDrawState::kNumStages; ++s) { | 454 drawState->fCommon.fViewMatrix.reset(); |
| 465 if (drawState->isStageEnabled(s)) { | 455 fDrawState = drawState; |
| 466 fRestoreMask |= (1 << s); | 456 fNumColorStages = 0; |
| 467 drawState->fStages[s].saveCoordChange(&fSavedCoordChanges[s]); | 457 fSavedCoordChanges.reset(0); |
| 458 GR_DEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;) |
| 459 return true; |
| 460 } else { |
| 461 SkMatrix inv; |
| 462 if (!fViewMatrix.invert(&inv)) { |
| 463 return false; |
| 468 } | 464 } |
| 465 drawState->fCommon.fViewMatrix.reset(); |
| 466 fDrawState = drawState; |
| 467 this->doEffectCoordChanges(inv); |
| 468 GR_DEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;) |
| 469 return true; |
| 469 } | 470 } |
| 470 if (!drawState->setIdentityViewMatrix()) { | 471 } |
| 471 return false; | 472 |
| 473 void GrDrawState::AutoViewMatrixRestore::doEffectCoordChanges(const SkMatrix& co
ordChangeMatrix) { |
| 474 fSavedCoordChanges.reset(fDrawState->numTotalStages()); |
| 475 int i = 0; |
| 476 |
| 477 fNumColorStages = fDrawState->numColorStages(); |
| 478 for (int s = 0; s < fNumColorStages; ++s, ++i) { |
| 479 fDrawState->fColorStages[s].saveCoordChange(&fSavedCoordChanges[i]); |
| 480 fDrawState->fColorStages[s].localCoordChange(coordChangeMatrix); |
| 472 } | 481 } |
| 473 fDrawState = drawState; | 482 |
| 474 return true; | 483 int numCoverageStages = fDrawState->numCoverageStages(); |
| 484 for (int s = 0; s < numCoverageStages; ++s, ++i) { |
| 485 fDrawState->fCoverageStages[s].saveCoordChange(&fSavedCoordChanges[i]); |
| 486 fDrawState->fCoverageStages[s].localCoordChange(coordChangeMatrix); |
| 487 } |
| 475 } | 488 } |
| OLD | NEW |