diff --git a/bench/PicturePlaybackBench.cpp b/bench/PicturePlaybackBench.cpp index d5000294e..a1f2daeca 100644 --- a/bench/PicturePlaybackBench.cpp +++ b/bench/PicturePlaybackBench.cpp @@ -210,10 +210,10 @@ public: } private: - BBH fBBH; - Mode fMode; - SkString fName; - SkAutoTDelete fPic; + BBH fBBH; + Mode fMode; + SkString fName; + SkAutoTUnref fPic; }; DEF_BENCH( return new TiledPlaybackBench(kNone, kRandom); ) diff --git a/bench/RecordingBench.cpp b/bench/RecordingBench.cpp index fe8573932..cd029ddf1 100644 --- a/bench/RecordingBench.cpp +++ b/bench/RecordingBench.cpp @@ -37,6 +37,6 @@ void RecordingBench::onDraw(const int loops, SkCanvas*) { SkPictureRecorder recorder; fSrc->playback(recorder.beginRecording(w, h, fUseBBH ? &factory : NULL, SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag)); - SkDELETE(recorder.endRecording()); + SkSafeUnref(recorder.endRecording()); } } diff --git a/include/core/SkRefCnt.h b/include/core/SkRefCnt.h index 1e31d918c..d85c20eca 100644 --- a/include/core/SkRefCnt.h +++ b/include/core/SkRefCnt.h @@ -261,10 +261,23 @@ public: bool unique() const { return 1 == sk_acquire_load(&fRefCnt); } void ref() const { sk_atomic_inc(&fRefCnt); } - void unref() const { if (1 == sk_atomic_dec(&fRefCnt)) { SkDELETE((const Derived*)this); } } + void unref() const { + int32_t prevValue = sk_atomic_dec(&fRefCnt); + SkASSERT(prevValue >= 1); + if (1 == prevValue) { + SkDELETE((const Derived*)this); + } + } void deref() const { this->unref(); } // Chrome prefers to call deref(). int32_t getRefCnt() const { return fRefCnt; } // Used by Chrome unit tests. +protected: +#ifdef SK_DEBUG + ~SkNVRefCnt() { + SkASSERTF(0 == fRefCnt, "NVRefCnt was %d", fRefCnt); + } +#endif + private: mutable int32_t fRefCnt; }; diff --git a/tests/PictureBBHTest.cpp b/tests/PictureBBHTest.cpp index fa0243743..bc712f575 100644 --- a/tests/PictureBBHTest.cpp +++ b/tests/PictureBBHTest.cpp @@ -109,13 +109,13 @@ static void test_clear(skiatest::Reporter* r, SkBBHFactory* factory) { // A picture that's just clear(). src.beginRecording(1,1, factory) ->clear(SK_ColorGREEN); - SkAutoTDelete srcPic(src.endRecording()); + SkAutoTUnref srcPic(src.endRecording()); // A target canvas with an empty clip. SkCanvas* c = dst.beginRecording(1,1, NULL); c->clipRect(SkRect::MakeEmpty()); srcPic->playback(c); - SkAutoTDelete dstPic(dst.endRecording()); + SkAutoTUnref dstPic(dst.endRecording()); // Should be Clip - Save - Clear - Restore. // Buggy implementations might return 1 (just Clip) or 3 (Clip - Save - Restore). diff --git a/tests/PictureTest.cpp b/tests/PictureTest.cpp index 77fed2ffe..ab2fcb723 100644 --- a/tests/PictureTest.cpp +++ b/tests/PictureTest.cpp @@ -1909,7 +1909,7 @@ DEF_TEST(Picture_BitmapLeak, r) { SkCanvas* canvas = rec.beginRecording(1920, 1200); canvas->drawBitmap(mut, 0, 0); canvas->drawBitmap(immut, 800, 600); - SkAutoTDelete pic(rec.endRecording()); + SkAutoTUnref pic(rec.endRecording()); // The picture shares the immutable pixels but copies the mutable ones. REPORTER_ASSERT(r, mut.pixelRef()->unique()); diff --git a/tests/RecordingXfermodeTest.cpp b/tests/RecordingXfermodeTest.cpp index a4b270bf0..18356732f 100644 --- a/tests/RecordingXfermodeTest.cpp +++ b/tests/RecordingXfermodeTest.cpp @@ -115,7 +115,7 @@ class PictureStrategy : public RecordingStrategy { SkIntToScalar(fHeight), &factory); drawer.draw(canvas, canvasRect, mode); - SkAutoTDelete picture(recorder.endRecording()); + SkAutoTUnref picture(recorder.endRecording()); SkCanvas replayCanvas(fBitmap); replayCanvas.clear(0xffffffff); diff --git a/tools/filtermain.cpp b/tools/filtermain.cpp index 87d68ff3a..3b9d05682 100644 --- a/tools/filtermain.cpp +++ b/tools/filtermain.cpp @@ -661,7 +661,7 @@ struct OptTableEntry { static int filter_picture(const SkString& inFile, const SkString& outFile) { - SkAutoTDelete inPicture; + SkAutoTUnref inPicture; SkFILEStream inStream(inFile.c_str()); if (inStream.isValid()) {