Bug 929350 - Allow the context for gfxContextMatrixAutoSaveRestore to be set lazily. r=mattwoodrow
authorJonathan Watt <jwatt@jwatt.org>
Tue, 22 Oct 2013 10:37:45 +0200
changeset 151600 041018f175349cceac71204a20c56b614666f57c
parent 151599 07dec571ca957e8842914f26bfafd6f8353fcf88
child 151601 a03c584f9874be67cf1d238518aa64f6411ef087
push id35240
push userjwatt@jwatt.org
push dateTue, 22 Oct 2013 08:38:34 +0000
treeherdermozilla-inbound@041018f17534 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs929350
milestone27.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 929350 - Allow the context for gfxContextMatrixAutoSaveRestore to be set lazily. r=mattwoodrow
gfx/thebes/gfxContext.h
--- a/gfx/thebes/gfxContext.h
+++ b/gfx/thebes/gfxContext.h
@@ -895,28 +895,50 @@ private:
 /**
  * Sentry helper class for functions with multiple return points that need to
  * back up the current matrix of a context and have it automatically restored
  * before they return.
  */
 class gfxContextMatrixAutoSaveRestore
 {
 public:
+    gfxContextMatrixAutoSaveRestore() :
+        mContext(nullptr)
+    {
+    }
+
     gfxContextMatrixAutoSaveRestore(gfxContext *aContext) :
         mContext(aContext), mMatrix(aContext->CurrentMatrix())
     {
     }
 
     ~gfxContextMatrixAutoSaveRestore()
     {
-        mContext->SetMatrix(mMatrix);
+        if (mContext) {
+            mContext->SetMatrix(mMatrix);
+        }
+    }
+
+    void SetContext(gfxContext *aContext)
+    {
+        NS_ASSERTION(!mContext, "Not going to restore the matrix on some context!");
+        mContext = aContext;
+        mMatrix = aContext->CurrentMatrix();
+    }
+
+    void Restore()
+    {
+        if (mContext) {
+            mContext->SetMatrix(mMatrix);
+        }
     }
 
     const gfxMatrix& Matrix()
     {
+        MOZ_ASSERT(mContext, "mMatrix doesn't contain a useful matrix");
         return mMatrix;
     }
 
 private:
     gfxContext *mContext;
     gfxMatrix   mMatrix;
 };