From 90d0ff013bbd8e5295d1517d41cb408e9d9f4d93 Mon Sep 17 00:00:00 2001 From: reed Date: Mon, 24 Nov 2014 12:02:31 -0800 Subject: [PATCH] add some debugging to SkNVRefCnt BUG=skia: Review URL: https://codereview.chromium.org/745383003 --- bench/PicturePlaybackBench.cpp | 8 ++++---- bench/RecordingBench.cpp | 2 +- include/core/SkRefCnt.h | 15 ++++++++++++++- tests/PictureBBHTest.cpp | 4 ++-- tests/PictureTest.cpp | 2 +- tests/RecordingXfermodeTest.cpp | 2 +- tools/filtermain.cpp | 2 +- 7 files changed, 24 insertions(+), 11 deletions(-) diff --git a/bench/PicturePlaybackBench.cpp b/bench/PicturePlaybackBench.cpp index d500029..a1f2dae 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 fe85739..cd029dd 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 1e31d91..d85c20e 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 fa02437..bc712f5 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 77fed2f..ab2fcb7 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 a4b270b..1835673 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 87d68ff..3b9d056 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()) { -- 2.7.4