aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2014-11-24 12:02:31 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2014-11-24 12:02:31 -0800
commit90d0ff013bbd8e5295d1517d41cb408e9d9f4d93 (patch)
tree48f4d640384d870a41372957098a75d4ae98cf7e
parent989131755712dbf9ab05f15537c76c82094de067 (diff)
add some debugging to SkNVRefCnt
-rw-r--r--bench/PicturePlaybackBench.cpp8
-rw-r--r--bench/RecordingBench.cpp2
-rw-r--r--include/core/SkRefCnt.h15
-rw-r--r--tests/PictureBBHTest.cpp4
-rw-r--r--tests/PictureTest.cpp2
-rw-r--r--tests/RecordingXfermodeTest.cpp2
-rw-r--r--tools/filtermain.cpp2
7 files changed, 24 insertions, 11 deletions
diff --git a/bench/PicturePlaybackBench.cpp b/bench/PicturePlaybackBench.cpp
index d5000294e3..a1f2daeca5 100644
--- a/bench/PicturePlaybackBench.cpp
+++ b/bench/PicturePlaybackBench.cpp
@@ -210,10 +210,10 @@ public:
}
private:
- BBH fBBH;
- Mode fMode;
- SkString fName;
- SkAutoTDelete<SkPicture> fPic;
+ BBH fBBH;
+ Mode fMode;
+ SkString fName;
+ SkAutoTUnref<SkPicture> fPic;
};
DEF_BENCH( return new TiledPlaybackBench(kNone, kRandom); )
diff --git a/bench/RecordingBench.cpp b/bench/RecordingBench.cpp
index fe85739323..cd029ddf14 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 1e31d918cc..d85c20ecaf 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 fa02437432..bc712f575e 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<SkPicture> srcPic(src.endRecording());
+ SkAutoTUnref<SkPicture> 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<SkPicture> dstPic(dst.endRecording());
+ SkAutoTUnref<SkPicture> 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 77fed2ffe3..ab2fcb7239 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<const SkPicture> pic(rec.endRecording());
+ SkAutoTUnref<const SkPicture> 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 a4b270bf09..18356732fd 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<SkPicture> picture(recorder.endRecording());
+ SkAutoTUnref<SkPicture> picture(recorder.endRecording());
SkCanvas replayCanvas(fBitmap);
replayCanvas.clear(0xffffffff);
diff --git a/tools/filtermain.cpp b/tools/filtermain.cpp
index 87d68ff3a2..3b9d05682c 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<SkPicture> inPicture;
+ SkAutoTUnref<SkPicture> inPicture;
SkFILEStream inStream(inFile.c_str());
if (inStream.isValid()) {