#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.
}
}
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
static void test_ptrs(skiatest::Reporter* reporter) {
SkRefCnt ref;
- REPORTER_ASSERT(reporter, 1 == ref.getRefCnt());
+ REPORTER_ASSERT(reporter, ref.unique());
{
SkMetaData md0, md1;
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) {
thing1.join();
thing2.join();
- REPORTER_ASSERT(reporter, ref->getRefCnt() == 1);
+ REPORTER_ASSERT(reporter, ref->unique());
ref->unref();
}
thing3.join();
thing4.join();
- REPORTER_ASSERT(reporter, ref->getRefCnt() == 1);
+ REPORTER_ASSERT(reporter, ref->unique());
REPORTER_ASSERT(reporter, ref->getWeakCnt() == 1);
ref->unref();
}
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());
}
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();
}
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;
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());
}
// 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)
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());
}
/////////////////////////////////////////////////////////////////////////////