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
This commit is contained in:
mtklein 2014-11-24 13:09:39 -08:00 committed by Commit bot
parent 7ba39cb9a6
commit bbb61d7268
6 changed files with 52 additions and 51 deletions

View File

@ -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

View File

@ -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) {

View File

@ -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();
}

View File

@ -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());
}

View File

@ -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();
}

View File

@ -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());
}
/////////////////////////////////////////////////////////////////////////////