diff options
author | mtklein <mtklein@chromium.org> | 2014-11-24 13:09:39 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-11-24 13:09:39 -0800 |
commit | bbb61d7268b26d240afde2c924cb7d1370aa4071 (patch) | |
tree | 013f00dc4cabedbdc33b0fd201bf4338d3d24eee | |
parent | 7ba39cb9a6c97f07eb392a1cf99ce65c1f23ded0 (diff) |
make SkRefCnt::getRefCnt() debug-only, remove it from SkNVRefCnt.
Only (unused) API removed.
TBR=reed@google.com
BUG=skia:3160
Review URL: https://codereview.chromium.org/752263002
-rw-r--r-- | include/core/SkRefCnt.h | 3 | ||||
-rw-r--r-- | tests/MetaDataTest.cpp | 10 | ||||
-rw-r--r-- | tests/RefCntTest.cpp | 4 | ||||
-rw-r--r-- | tests/RefDictTest.cpp | 30 | ||||
-rw-r--r-- | tests/SurfaceTest.cpp | 6 | ||||
-rw-r--r-- | tests/UtilsTest.cpp | 50 |
6 files changed, 52 insertions, 51 deletions
diff --git a/include/core/SkRefCnt.h b/include/core/SkRefCnt.h index d85c20ecaf..7ccfbf9d70 100644 --- a/include/core/SkRefCnt.h +++ b/include/core/SkRefCnt.h @@ -42,8 +42,10 @@ public: #endif } +#ifdef SK_DEBUG /** Return the reference count. Use only for debugging. */ int32_t getRefCnt() const { return fRefCnt; } +#endif /** May return true if the caller is the only owner. * Ensures that all previous owner's actions are complete. @@ -269,7 +271,6 @@ public: } } 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 diff --git a/tests/MetaDataTest.cpp b/tests/MetaDataTest.cpp index eb7eae9e0f..8ed1e493ec 100644 --- a/tests/MetaDataTest.cpp +++ b/tests/MetaDataTest.cpp @@ -10,7 +10,7 @@ static void test_ptrs(skiatest::Reporter* reporter) { SkRefCnt ref; - REPORTER_ASSERT(reporter, 1 == ref.getRefCnt()); + REPORTER_ASSERT(reporter, ref.unique()); { SkMetaData md0, md1; @@ -19,19 +19,19 @@ static void test_ptrs(skiatest::Reporter* reporter) { md0.setRefCnt(name, &ref); REPORTER_ASSERT(reporter, md0.findRefCnt(name)); REPORTER_ASSERT(reporter, md0.hasRefCnt(name, &ref)); - REPORTER_ASSERT(reporter, 2 == ref.getRefCnt()); + REPORTER_ASSERT(reporter, !ref.unique()); md1 = md0; REPORTER_ASSERT(reporter, md1.findRefCnt(name)); REPORTER_ASSERT(reporter, md1.hasRefCnt(name, &ref)); - REPORTER_ASSERT(reporter, 3 == ref.getRefCnt()); + REPORTER_ASSERT(reporter, !ref.unique()); REPORTER_ASSERT(reporter, md0.removeRefCnt(name)); REPORTER_ASSERT(reporter, !md0.findRefCnt(name)); REPORTER_ASSERT(reporter, !md0.hasRefCnt(name, &ref)); - REPORTER_ASSERT(reporter, 2 == ref.getRefCnt()); + REPORTER_ASSERT(reporter, !ref.unique()); } - REPORTER_ASSERT(reporter, 1 == ref.getRefCnt()); + REPORTER_ASSERT(reporter, ref.unique()); } DEF_TEST(MetaData, reporter) { diff --git a/tests/RefCntTest.cpp b/tests/RefCntTest.cpp index cf6ca3e0f2..cf4acc6233 100644 --- a/tests/RefCntTest.cpp +++ b/tests/RefCntTest.cpp @@ -49,7 +49,7 @@ static void test_refCnt(skiatest::Reporter* reporter) { thing1.join(); thing2.join(); - REPORTER_ASSERT(reporter, ref->getRefCnt() == 1); + REPORTER_ASSERT(reporter, ref->unique()); ref->unref(); } @@ -93,7 +93,7 @@ static void test_weakRefCnt(skiatest::Reporter* reporter) { thing3.join(); thing4.join(); - REPORTER_ASSERT(reporter, ref->getRefCnt() == 1); + REPORTER_ASSERT(reporter, ref->unique()); REPORTER_ASSERT(reporter, ref->getWeakCnt() == 1); ref->unref(); } diff --git a/tests/RefDictTest.cpp b/tests/RefDictTest.cpp index 1e18a6815d..23e4b114a5 100644 --- a/tests/RefDictTest.cpp +++ b/tests/RefDictTest.cpp @@ -25,50 +25,50 @@ DEF_TEST(RefDict, reporter) { dict.set("foo", &data0); REPORTER_ASSERT(reporter, &data0 == dict.find("foo")); - REPORTER_ASSERT(reporter, 2 == data0.getRefCnt()); + REPORTER_ASSERT(reporter, !data0.unique()); dict.set("foo", &data0); REPORTER_ASSERT(reporter, &data0 == dict.find("foo")); - REPORTER_ASSERT(reporter, 2 == data0.getRefCnt()); + REPORTER_ASSERT(reporter, !data0.unique()); dict.set("foo", &data1); REPORTER_ASSERT(reporter, &data1 == dict.find("foo")); - REPORTER_ASSERT(reporter, 1 == data0.getRefCnt()); - REPORTER_ASSERT(reporter, 2 == data1.getRefCnt()); + REPORTER_ASSERT(reporter, data0.unique()); + REPORTER_ASSERT(reporter, !data1.unique()); dict.set("foo", NULL); REPORTER_ASSERT(reporter, NULL == dict.find("foo")); - REPORTER_ASSERT(reporter, 1 == data0.getRefCnt()); - REPORTER_ASSERT(reporter, 1 == data1.getRefCnt()); + REPORTER_ASSERT(reporter, data0.unique()); + REPORTER_ASSERT(reporter, data1.unique()); dict.set("foo", &data0); dict.set("bar", &data1); REPORTER_ASSERT(reporter, &data0 == dict.find("foo")); REPORTER_ASSERT(reporter, &data1 == dict.find("bar")); - REPORTER_ASSERT(reporter, 2 == data0.getRefCnt()); - REPORTER_ASSERT(reporter, 2 == data1.getRefCnt()); + REPORTER_ASSERT(reporter, !data0.unique()); + REPORTER_ASSERT(reporter, !data1.unique()); dict.set("foo", &data1); REPORTER_ASSERT(reporter, &data1 == dict.find("foo")); REPORTER_ASSERT(reporter, &data1 == dict.find("bar")); - REPORTER_ASSERT(reporter, 1 == data0.getRefCnt()); - REPORTER_ASSERT(reporter, 3 == data1.getRefCnt()); + REPORTER_ASSERT(reporter, data0.unique()); + REPORTER_ASSERT(reporter, !data1.unique()); dict.removeAll(); REPORTER_ASSERT(reporter, NULL == dict.find("foo")); REPORTER_ASSERT(reporter, NULL == dict.find("bar")); - REPORTER_ASSERT(reporter, 1 == data0.getRefCnt()); - REPORTER_ASSERT(reporter, 1 == data1.getRefCnt()); + REPORTER_ASSERT(reporter, data0.unique()); + REPORTER_ASSERT(reporter, data1.unique()); { SkRefDict d; REPORTER_ASSERT(reporter, NULL == d.find("foo")); - REPORTER_ASSERT(reporter, 1 == data0.getRefCnt()); + REPORTER_ASSERT(reporter, data0.unique()); d.set("foo", &data0); REPORTER_ASSERT(reporter, &data0 == d.find("foo")); - REPORTER_ASSERT(reporter, 2 == data0.getRefCnt()); + REPORTER_ASSERT(reporter, !data0.unique()); // let d go out of scope still with a ref on data0 } // be sure d's destructor lowered data0's owner count back to 1 - REPORTER_ASSERT(reporter, 1 == data0.getRefCnt()); + REPORTER_ASSERT(reporter, data0.unique()); } diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp index 1913fcb146..6422669055 100644 --- a/tests/SurfaceTest.cpp +++ b/tests/SurfaceTest.cpp @@ -77,11 +77,11 @@ static void test_image(skiatest::Reporter* reporter) { size_t size = info.getSafeSize(rowBytes); SkData* data = SkData::NewUninitialized(size); - REPORTER_ASSERT(reporter, 1 == data->getRefCnt()); + REPORTER_ASSERT(reporter, data->unique()); SkImage* image = SkImage::NewRasterData(info, data, rowBytes); - REPORTER_ASSERT(reporter, 2 == data->getRefCnt()); + REPORTER_ASSERT(reporter, !data->unique()); image->unref(); - REPORTER_ASSERT(reporter, 1 == data->getRefCnt()); + REPORTER_ASSERT(reporter, data->unique()); data->unref(); } diff --git a/tests/UtilsTest.cpp b/tests/UtilsTest.cpp index 2c84c958ec..81e6492f3c 100644 --- a/tests/UtilsTest.cpp +++ b/tests/UtilsTest.cpp @@ -27,30 +27,30 @@ private: static void test_autounref(skiatest::Reporter* reporter) { RefClass obj(0); - REPORTER_ASSERT(reporter, 1 == obj.getRefCnt()); + REPORTER_ASSERT(reporter, obj.unique()); SkAutoTUnref<RefClass> tmp(&obj); REPORTER_ASSERT(reporter, &obj == tmp.get()); - REPORTER_ASSERT(reporter, 1 == obj.getRefCnt()); + REPORTER_ASSERT(reporter, obj.unique()); REPORTER_ASSERT(reporter, &obj == tmp.detach()); - REPORTER_ASSERT(reporter, 1 == obj.getRefCnt()); + REPORTER_ASSERT(reporter, obj.unique()); REPORTER_ASSERT(reporter, NULL == tmp.detach()); REPORTER_ASSERT(reporter, NULL == tmp.get()); obj.ref(); - REPORTER_ASSERT(reporter, 2 == obj.getRefCnt()); + REPORTER_ASSERT(reporter, !obj.unique()); { SkAutoTUnref<RefClass> tmp2(&obj); } - REPORTER_ASSERT(reporter, 1 == obj.getRefCnt()); + REPORTER_ASSERT(reporter, obj.unique()); } static void test_autostarray(skiatest::Reporter* reporter) { RefClass obj0(0); RefClass obj1(1); - REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt()); - REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt()); + REPORTER_ASSERT(reporter, obj0.unique()); + REPORTER_ASSERT(reporter, obj1.unique()); { SkAutoSTArray<2, SkAutoTUnref<RefClass> > tmp; @@ -61,14 +61,14 @@ static void test_autostarray(skiatest::Reporter* reporter) { REPORTER_ASSERT(reporter, 4 == tmp.count()); tmp[0].reset(SkRef(&obj0)); tmp[1].reset(SkRef(&obj1)); - REPORTER_ASSERT(reporter, 2 == obj0.getRefCnt()); - REPORTER_ASSERT(reporter, 2 == obj1.getRefCnt()); + REPORTER_ASSERT(reporter, !obj0.unique()); + REPORTER_ASSERT(reporter, !obj1.unique()); // test out reset with data in the array (and a new allocation) tmp.reset(0); REPORTER_ASSERT(reporter, 0 == tmp.count()); - REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt()); - REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt()); + REPORTER_ASSERT(reporter, obj0.unique()); + REPORTER_ASSERT(reporter, obj1.unique()); tmp.reset(2); // this should use the preexisting allocation REPORTER_ASSERT(reporter, 2 == tmp.count()); @@ -77,8 +77,8 @@ static void test_autostarray(skiatest::Reporter* reporter) { } // test out destructor with data in the array (and using existing allocation) - REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt()); - REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt()); + REPORTER_ASSERT(reporter, obj0.unique()); + REPORTER_ASSERT(reporter, obj1.unique()); { // test out allocating ctor (this should allocate new memory) @@ -87,32 +87,32 @@ static void test_autostarray(skiatest::Reporter* reporter) { tmp[0].reset(SkRef(&obj0)); tmp[1].reset(SkRef(&obj1)); - REPORTER_ASSERT(reporter, 2 == obj0.getRefCnt()); - REPORTER_ASSERT(reporter, 2 == obj1.getRefCnt()); + REPORTER_ASSERT(reporter, !obj0.unique()); + REPORTER_ASSERT(reporter, !obj1.unique()); // Test out resut with data in the array and malloced storage tmp.reset(0); - REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt()); - REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt()); + REPORTER_ASSERT(reporter, obj0.unique()); + REPORTER_ASSERT(reporter, obj1.unique()); tmp.reset(2); // this should use the preexisting storage tmp[0].reset(SkRef(&obj0)); tmp[1].reset(SkRef(&obj1)); - REPORTER_ASSERT(reporter, 2 == obj0.getRefCnt()); - REPORTER_ASSERT(reporter, 2 == obj1.getRefCnt()); + REPORTER_ASSERT(reporter, !obj0.unique()); + REPORTER_ASSERT(reporter, !obj1.unique()); tmp.reset(4); // this should force a new malloc - REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt()); - REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt()); + REPORTER_ASSERT(reporter, obj0.unique()); + REPORTER_ASSERT(reporter, obj1.unique()); tmp[0].reset(SkRef(&obj0)); tmp[1].reset(SkRef(&obj1)); - REPORTER_ASSERT(reporter, 2 == obj0.getRefCnt()); - REPORTER_ASSERT(reporter, 2 == obj1.getRefCnt()); + REPORTER_ASSERT(reporter, !obj0.unique()); + REPORTER_ASSERT(reporter, !obj1.unique()); } - REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt()); - REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt()); + REPORTER_ASSERT(reporter, obj0.unique()); + REPORTER_ASSERT(reporter, obj1.unique()); } ///////////////////////////////////////////////////////////////////////////// |