fix refcount bug - as picture gets referenced by canvas when canvas is a
authorreed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Wed, 12 Jan 2011 17:14:04 +0000 (17:14 +0000)
committerreed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Wed, 12 Jan 2011 17:14:04 +0000 (17:14 +0000)
picture-recording canvas, so it can't live on the stack. Probably a bug:
nested pictures should probably ref some internal impl, so that callers can be
free to use the stack when they want to.

git-svn-id: http://skia.googlecode.com/svn/trunk@687 2bbb7eff-a529-9590-31e7-b0007b416f81

gm/shapes.cpp

index b3d4863..324ce7e 100644 (file)
@@ -53,40 +53,40 @@ public:
         fGroup.appendShape(make_shape1(), m)->unref();
         m.postTranslate(0, SkIntToScalar(120));
         fGroup.appendShape(make_shape2(), m)->unref();
-        
+
         for (size_t i = 0; i < SK_ARRAY_COUNT(fMatrixRefs); i++) {
             SkSafeRef(fMatrixRefs[i] = fGroup.getShapeMatrixRef(i));
         }
     }
-    
+
     virtual ~ShapesGM() {
         for (size_t i = 0; i < SK_ARRAY_COUNT(fMatrixRefs); i++) {
             SkSafeUnref(fMatrixRefs[i]);
         }
     }
-    
+
 protected:
     virtual SkString onShortName() {
         return SkString("shapes");
     }
-    
+
        virtual SkISize onISize() {
         return make_isize(380, 480);
     }
-    
+
     void drawBG(SkCanvas* canvas) {
         canvas->drawColor(0xFFDDDDDD);
     }
-    
+
     virtual void onDraw(SkCanvas* canvas) {
         this->drawBG(canvas);
-        
+
         SkMatrix saveM = *fMatrixRefs[3];
         SkScalar c = SkIntToScalar(50);
         fMatrixRefs[3]->preRotate(SkIntToScalar(30), c, c);
-        
+
         SkMatrix matrix;
-     
+
         SkGroupShape* gs = new SkGroupShape;
         SkAutoUnref aur(gs);
         gs->appendShape(&fGroup);
@@ -96,24 +96,25 @@ protected:
         matrix.setTranslate(SkIntToScalar(240), 0);
         matrix.preScale(SK_Scalar1*2, SK_Scalar1*2);
         gs->appendShape(&fGroup, matrix);
-        
-#if 0        
+
+#if 0
         canvas->drawShape(gs);
 #else
-        SkPicture pict;
-        SkCanvas* cv = pict.beginRecording(1000, 1000);
+        SkPicture* pict = new SkPicture;
+        SkCanvas* cv = pict->beginRecording(1000, 1000);
         cv->scale(SK_ScalarHalf, SK_ScalarHalf);
         cv->drawShape(gs);
         cv->translate(SkIntToScalar(680), SkIntToScalar(480));
         cv->scale(-SK_Scalar1, SK_Scalar1);
         cv->drawShape(gs);
-        pict.endRecording();
-        canvas->drawPicture(pict);
+        pict->endRecording();
+        canvas->drawPicture(*pict);
+        pict->unref();
 #endif
 
         *fMatrixRefs[3] = saveM;
 }
-    
+
 private:
     typedef GM INHERITED;
 };