Move some auto restore helpers from GrDrawTarget to GrDrawState.
R=robertphillips@google.com
git-svn-id: http://skia.googlecode.com/svn/trunk@5846 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/GrDrawState.h b/src/gpu/GrDrawState.h
index ca3b2c1..ea8f418 100644
--- a/src/gpu/GrDrawState.h
+++ b/src/gpu/GrDrawState.h
@@ -135,6 +135,24 @@
GrColor getColorFilterColor() const { return fColorFilterColor; }
SkXfermode::Mode getColorFilterMode() const { return fColorFilterMode; }
+ /**
+ * Constructor sets the color to be 'color' which is undone by the destructor.
+ */
+ class AutoColorRestore : public ::GrNoncopyable {
+ public:
+ AutoColorRestore(GrDrawState* drawState, GrColor color) {
+ fDrawState = drawState;
+ fOldColor = fDrawState->getColor();
+ fDrawState->setColor(color);
+ }
+ ~AutoColorRestore() {
+ fDrawState->setColor(fOldColor);
+ }
+ private:
+ GrDrawState* fDrawState;
+ GrColor fOldColor;
+ };
+
/// @}
///////////////////////////////////////////////////////////////////////////
@@ -446,6 +464,11 @@
return false;
}
+ ////////////////////////////////////////////////////////////////////////////
+
+ /**
+ * TODO: Automatically handle stage matrices.
+ */
class AutoViewMatrixRestore : public ::GrNoncopyable {
public:
AutoViewMatrixRestore() : fDrawState(NULL) {}
@@ -485,6 +508,31 @@
GrMatrix fSavedMatrix;
};
+ ////////////////////////////////////////////////////////////////////////////
+
+ /**
+ * This sets the view matrix to identity and adjusts stage matrices to
+ * compensate. The destructor undoes the changes, restoring the view matrix
+ * that was set before the constructor.
+ */
+ class AutoDeviceCoordDraw : ::GrNoncopyable {
+ public:
+ /**
+ * If a stage's texture matrix is applied to explicit per-vertex coords,
+ * rather than to positions, then we don't want to modify its matrix.
+ * The explicitCoordStageMask is used to specify such stages.
+ */
+ AutoDeviceCoordDraw(GrDrawState* drawState,
+ uint32_t explicitCoordStageMask = 0);
+ bool succeeded() const { return NULL != fDrawState; }
+ ~AutoDeviceCoordDraw();
+ private:
+ GrDrawState* fDrawState;
+ GrMatrix fViewMatrix;
+ GrMatrix fSamplerMatrices[GrDrawState::kNumStages];
+ int fRestoreMask;
+ };
+
/// @}
///////////////////////////////////////////////////////////////////////////