Speculative render target ref/unref fixes

https://codereview.appspot.com/6592051/



git-svn-id: http://skia.googlecode.com/svn/trunk@5754 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index 3c38fad..16eab66 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -640,21 +640,24 @@
     ///////////////////////////////////////////////////////////////////////////
     // Helpers
 
-    class AutoRenderTarget : ::GrNoncopyable {
+    class AutoRenderTarget : public ::GrNoncopyable {
     public:
         AutoRenderTarget(GrContext* context, GrRenderTarget* target) {
             fPrevTarget = context->getRenderTarget();
+            GrSafeRef(fPrevTarget);
             context->setRenderTarget(target);
             fContext = context;
         }
         AutoRenderTarget(GrContext* context) {
             fPrevTarget = context->getRenderTarget();
+            GrSafeRef(fPrevTarget);
             fContext = context;
         }
         ~AutoRenderTarget() {
-            if (fContext) {
+            if (NULL != fContext) {
                 fContext->setRenderTarget(fPrevTarget);
             }
+            GrSafeUnref(fPrevTarget);
         }
     private:
         GrContext*      fContext;
@@ -728,12 +731,13 @@
             kWideOpen_InitialClip,
         };
 
-        AutoClip(GrContext* context, InitialClip initialState) {
+        AutoClip(GrContext* context, InitialClip initialState) 
+        : fContext(context) {
             GrAssert(kWideOpen_InitialClip == initialState);
-            fOldClip = context->getClip();
             fNewClipData.fClipStack = &fNewClipStack;
+
+            fOldClip = context->getClip();
             context->setClip(&fNewClipData);
-            fContext = context;
         }
 
         AutoClip(GrContext* context, const GrRect& newClipRect)