diff options
author | 2012-10-08 17:15:55 +0000 | |
---|---|---|
committer | 2012-10-08 17:15:55 +0000 | |
commit | 2fdcdeb86788206c23410109b3e2b7976747fd11 (patch) | |
tree | fd780e51a91a279ddfa9147cf54a573d15208c00 /src/gpu/GrDrawState.cpp | |
parent | 0f11e1ab5b6e53f6176dde2dbb25a8e3ae34858f (diff) |
Make GrDrawState::AutoRestoreViewMatrix handle sampler matrices.
R=robertphillips@google.com
Review URL: https://codereview.appspot.com/6618065
git-svn-id: http://skia.googlecode.com/svn/trunk@5853 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/gpu/GrDrawState.cpp')
-rw-r--r-- | src/gpu/GrDrawState.cpp | 71 |
1 files changed, 57 insertions, 14 deletions
diff --git a/src/gpu/GrDrawState.cpp b/src/gpu/GrDrawState.cpp index b9b708e4bf..b0bbd06a16 100644 --- a/src/gpu/GrDrawState.cpp +++ b/src/gpu/GrDrawState.cpp @@ -49,11 +49,64 @@ void GrDrawState::setFromPaint(const GrPaint& paint) { //////////////////////////////////////////////////////////////////////////////// -GrDrawState::AutoDeviceCoordDraw::AutoDeviceCoordDraw(GrDrawState* drawState, - uint32_t explicitCoordStageMask) { +void GrDrawState::AutoViewMatrixRestore::restore() { + if (NULL != fDrawState) { + fDrawState->setViewMatrix(fViewMatrix); + for (int s = 0; s < GrDrawState::kNumStages; ++s) { + if (fRestoreMask & (1 << s)) { + *fDrawState->sampler(s)->matrix() = fSamplerMatrices[s]; + } + } + } + fDrawState = NULL; +} + +void GrDrawState::AutoViewMatrixRestore::set(GrDrawState* drawState, + const GrMatrix& preconcatMatrix, + uint32_t explicitCoordStageMask) { + this->restore(); + + fDrawState = drawState; + if (NULL == drawState) { + return; + } + + fRestoreMask = 0; + fViewMatrix = drawState->getViewMatrix(); + drawState->preConcatViewMatrix(preconcatMatrix); + for (int s = 0; s < GrDrawState::kNumStages; ++s) { + if (!(explicitCoordStageMask & (1 << s)) && drawState->isStageEnabled(s)) { + fRestoreMask |= (1 << s); + drawState->sampler(s)->preConcatMatrix(preconcatMatrix); + } + } +} + +//////////////////////////////////////////////////////////////////////////////// + +void GrDrawState::AutoDeviceCoordDraw::restore() { + if (NULL != fDrawState) { + fDrawState->setViewMatrix(fViewMatrix); + for (int s = 0; s < GrDrawState::kNumStages; ++s) { + if (fRestoreMask & (1 << s)) { + *fDrawState->sampler(s)->matrix() = fSamplerMatrices[s]; + } + } + } + fDrawState = NULL; +} + +bool GrDrawState::AutoDeviceCoordDraw::set(GrDrawState* drawState, + uint32_t explicitCoordStageMask) { GrAssert(NULL != drawState); + this->restore(); + fDrawState = drawState; + if (NULL == fDrawState) { + return false; + } + fViewMatrix = drawState->getViewMatrix(); fRestoreMask = 0; GrMatrix invVM; @@ -64,7 +117,7 @@ GrDrawState::AutoDeviceCoordDraw::AutoDeviceCoordDraw(GrDrawState* drawState, if (!inverted && !fViewMatrix.invert(&invVM)) { // sad trombone sound fDrawState = NULL; - return; + return false; } else { inverted = true; } @@ -75,15 +128,5 @@ GrDrawState::AutoDeviceCoordDraw::AutoDeviceCoordDraw(GrDrawState* drawState, } } drawState->viewMatrix()->reset(); -} - -GrDrawState::AutoDeviceCoordDraw::~AutoDeviceCoordDraw() { - if (NULL != fDrawState) { - fDrawState->setViewMatrix(fViewMatrix); - for (int s = 0; s < GrDrawState::kNumStages; ++s) { - if (fRestoreMask & (1 << s)) { - *fDrawState->sampler(s)->matrix() = fSamplerMatrices[s]; - } - } - } + return true; } |