diff options
author | 2013-05-29 21:27:53 +0000 | |
---|---|---|
committer | 2013-05-29 21:27:53 +0000 | |
commit | 137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3 (patch) | |
tree | 11258502b9eb36bb0d073e50c6aa0dc040be11ec /src/gpu/GrDrawState.cpp | |
parent | 9a6eb0e1e8a8de7371cd9604f34619b8f87de66f (diff) |
Replace GrDrawState::AutoDeviceCoordDraw with GrDrawState::AutoViewMatrixRestore::setIdentity(). s
R=robertphillips@google.com
Review URL: https://codereview.chromium.org/15780002
git-svn-id: http://skia.googlecode.com/svn/trunk@9331 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/gpu/GrDrawState.cpp')
-rw-r--r-- | src/gpu/GrDrawState.cpp | 75 |
1 files changed, 36 insertions, 39 deletions
diff --git a/src/gpu/GrDrawState.cpp b/src/gpu/GrDrawState.cpp index 2cc50f7dc4..f114cccf89 100644 --- a/src/gpu/GrDrawState.cpp +++ b/src/gpu/GrDrawState.cpp @@ -8,6 +8,25 @@ #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)) { + if (!inverted) { + if (!fCommon.fViewMatrix.invert(&invVM)) { + // sad trombone sound + return false; + } + 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 +414,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; } |