Minor refactoring to make GrAutoMatrix a nested sub-class of GrContext
http://codereview.appspot.com/6356092/
git-svn-id: http://skia.googlecode.com/svn/trunk@4549 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index d718637..8f7378f 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -662,6 +662,44 @@
GrRenderTarget* fPrevTarget;
};
+ /**
+ * Save/restore the view-matrix in the context.
+ */
+ class AutoMatrix : GrNoncopyable {
+ public:
+ AutoMatrix() : fContext(NULL) {}
+ AutoMatrix(GrContext* ctx) : fContext(ctx) {
+ fMatrix = ctx->getMatrix();
+ }
+ AutoMatrix(GrContext* ctx, const GrMatrix& matrix) : fContext(ctx) {
+ fMatrix = ctx->getMatrix();
+ ctx->setMatrix(matrix);
+ }
+ void set(GrContext* ctx) {
+ if (NULL != fContext) {
+ fContext->setMatrix(fMatrix);
+ }
+ fMatrix = ctx->getMatrix();
+ fContext = ctx;
+ }
+ void set(GrContext* ctx, const GrMatrix& matrix) {
+ if (NULL != fContext) {
+ fContext->setMatrix(fMatrix);
+ }
+ fMatrix = ctx->getMatrix();
+ ctx->setMatrix(matrix);
+ fContext = ctx;
+ }
+ ~AutoMatrix() {
+ if (NULL != fContext) {
+ fContext->setMatrix(fMatrix);
+ }
+ }
+
+ private:
+ GrContext* fContext;
+ GrMatrix fMatrix;
+ };
///////////////////////////////////////////////////////////////////////////
// Functions intended for internal use only.
@@ -782,45 +820,6 @@
};
/**
- * Save/restore the view-matrix in the context.
- */
-class GrAutoMatrix : GrNoncopyable {
-public:
- GrAutoMatrix() : fContext(NULL) {}
- GrAutoMatrix(GrContext* ctx) : fContext(ctx) {
- fMatrix = ctx->getMatrix();
- }
- GrAutoMatrix(GrContext* ctx, const GrMatrix& matrix) : fContext(ctx) {
- fMatrix = ctx->getMatrix();
- ctx->setMatrix(matrix);
- }
- void set(GrContext* ctx) {
- if (NULL != fContext) {
- fContext->setMatrix(fMatrix);
- }
- fMatrix = ctx->getMatrix();
- fContext = ctx;
- }
- void set(GrContext* ctx, const GrMatrix& matrix) {
- if (NULL != fContext) {
- fContext->setMatrix(fMatrix);
- }
- fMatrix = ctx->getMatrix();
- ctx->setMatrix(matrix);
- fContext = ctx;
- }
- ~GrAutoMatrix() {
- if (NULL != fContext) {
- fContext->setMatrix(fMatrix);
- }
- }
-
-private:
- GrContext* fContext;
- GrMatrix fMatrix;
-};
-
-/**
* Gets and locks a scratch texture from a descriptor using
* either exact or approximate criteria. Unlocks texture in
* the destructor.