Chromium Code Reviews| Index: src/gpu/GrDrawState.cpp |
| diff --git a/src/gpu/GrDrawState.cpp b/src/gpu/GrDrawState.cpp |
| index 2cc50f7dc463c7a3c5511d3d278433275b414e55..bd0bc48e450750579fa010c7d47d7c50dd6852d4 100644 |
| --- a/src/gpu/GrDrawState.cpp |
| +++ b/src/gpu/GrDrawState.cpp |
| @@ -8,6 +8,24 @@ |
| #include "GrDrawState.h" |
| #include "GrPaint.h" |
| +bool GrDrawState::setIdentityViewMatrix() { |
| + SkMatrix invVM; |
| + bool inverted = false; |
| + for (int s = 0; s < GrDrawState::kNumStages; ++s) { |
| + if (this->isStageEnabled(s)) { |
|
robertphillips
2013/05/29 21:16:20
if (!inverted) {
if (!fCommon....) {
return
bsalomon
2013/06/03 14:31:40
Done.
|
| + if (!inverted && !fCommon.fViewMatrix.invert(&invVM)) { |
| + // sad trombone sound |
| + return false; |
| + } else { |
| + inverted = true; |
| + } |
| + fStages[s].localCoordChange(invVM); |
| + } |
| + } |
| + fCommon.fViewMatrix.reset(); |
| + return true; |
| +} |
| + |
| void GrDrawState::setFromPaint(const GrPaint& paint, const SkMatrix& vm, GrRenderTarget* rt) { |
| for (int i = 0; i < GrPaint::kMaxColorStages; ++i) { |
| int s = i + GrPaint::kFirstColorStage; |
| @@ -395,81 +413,59 @@ GrDrawState::BlendOptFlags GrDrawState::getBlendOpts(bool forceCoverage, |
| void GrDrawState::AutoViewMatrixRestore::restore() { |
| if (NULL != fDrawState) { |
| - fDrawState->setViewMatrix(fViewMatrix); |
| + fDrawState->fCommon.fViewMatrix = fViewMatrix; |
| for (int s = 0; s < GrDrawState::kNumStages; ++s) { |
| if (fRestoreMask & (1 << s)) { |
| fDrawState->fStages[s].restoreCoordChange(fSavedCoordChanges[s]); |
| } |
| } |
| + fDrawState = NULL; |
| } |
| - fDrawState = NULL; |
| } |
| void GrDrawState::AutoViewMatrixRestore::set(GrDrawState* drawState, |
| const SkMatrix& preconcatMatrix) { |
| this->restore(); |
| - fDrawState = drawState; |
| - if (NULL == drawState) { |
| + if (NULL == drawState || preconcatMatrix.isIdentity()) { |
| return; |
| } |
| + fDrawState = drawState; |
| fRestoreMask = 0; |
| fViewMatrix = drawState->getViewMatrix(); |
| - drawState->preConcatViewMatrix(preconcatMatrix); |
| + drawState->fCommon.fViewMatrix.preConcat(preconcatMatrix); |
| for (int s = 0; s < GrDrawState::kNumStages; ++s) { |
| if (drawState->isStageEnabled(s)) { |
| fRestoreMask |= (1 << s); |
| - fDrawState->fStages[s].saveCoordChange(&fSavedCoordChanges[s]); |
| + drawState->fStages[s].saveCoordChange(&fSavedCoordChanges[s]); |
| drawState->fStages[s].localCoordChange(preconcatMatrix); |
| } |
| } |
| } |
| -//////////////////////////////////////////////////////////////////////////////// |
| - |
| -void GrDrawState::AutoDeviceCoordDraw::restore() { |
| - if (NULL != fDrawState) { |
| - fDrawState->setViewMatrix(fViewMatrix); |
| - for (int s = 0; s < GrDrawState::kNumStages; ++s) { |
| - if (fRestoreMask & (1 << s)) { |
| - fDrawState->fStages[s].restoreCoordChange(fSavedCoordChanges[s]); |
| - } |
| - } |
| - } |
| - fDrawState = NULL; |
| -} |
| - |
| -bool GrDrawState::AutoDeviceCoordDraw::set(GrDrawState* drawState) { |
| - GrAssert(NULL != drawState); |
| - |
| +bool GrDrawState::AutoViewMatrixRestore::setIdentity(GrDrawState* drawState) { |
| this->restore(); |
| - fDrawState = drawState; |
| - if (NULL == fDrawState) { |
| + if (NULL == drawState) { |
| return false; |
| } |
| + if (drawState->getViewMatrix().isIdentity()) { |
| + return true; |
| + } |
| + |
| fViewMatrix = drawState->getViewMatrix(); |
| fRestoreMask = 0; |
| - SkMatrix invVM; |
| - bool inverted = false; |
| - |
| for (int s = 0; s < GrDrawState::kNumStages; ++s) { |
| if (drawState->isStageEnabled(s)) { |
| - if (!inverted && !fViewMatrix.invert(&invVM)) { |
| - // sad trombone sound |
| - fDrawState = NULL; |
| - return false; |
| - } else { |
| - inverted = true; |
| - } |
| fRestoreMask |= (1 << s); |
| - GrEffectStage* stage = drawState->fStages + s; |
| - stage->saveCoordChange(&fSavedCoordChanges[s]); |
| - stage->localCoordChange(invVM); |
| + drawState->fStages[s].saveCoordChange(&fSavedCoordChanges[s]); |
| } |
| } |
| - drawState->viewMatrix()->reset(); |
| + if (!drawState->setIdentityViewMatrix()) { |
| + return false; |
| + } |
| + fDrawState = drawState; |
| return true; |
| } |