diff options
-rw-r--r-- | include/core/SkRefCnt.h | 32 | ||||
-rw-r--r-- | src/ports/SkFontConfigInterface_android.cpp | 10 | ||||
-rw-r--r-- | tests/UtilsTest.cpp | 24 |
3 files changed, 17 insertions, 49 deletions
diff --git a/include/core/SkRefCnt.h b/include/core/SkRefCnt.h index 9e3a92eb9a..f92154bc2f 100644 --- a/include/core/SkRefCnt.h +++ b/include/core/SkRefCnt.h @@ -248,36 +248,4 @@ public: }; #define SkAutoUnref(...) SK_REQUIRE_LOCAL_VAR(SkAutoUnref) -/** Wrapper class for SkRefCnt pointers. This manages ref/unref of a pointer to - a SkRefCnt (or subclass) object. - */ -template <typename T> class SkRefPtr { -public: - SkRefPtr() : fObj(NULL) {} - SkRefPtr(T* obj) : fObj(obj) { SkSafeRef(fObj); } - SkRefPtr(const SkRefPtr& o) : fObj(o.fObj) { SkSafeRef(fObj); } - ~SkRefPtr() { SkSafeUnref(fObj); } - - SkRefPtr& operator=(const SkRefPtr& rp) { - SkRefCnt_SafeAssign(fObj, rp.fObj); - return *this; - } - SkRefPtr& operator=(T* obj) { - SkRefCnt_SafeAssign(fObj, obj); - return *this; - } - - T* get() const { return fObj; } - T& operator*() const { return *fObj; } - T* operator->() const { return fObj; } - - typedef T* SkRefPtr::*unspecified_bool_type; - operator unspecified_bool_type() const { - return fObj ? &SkRefPtr::fObj : NULL; - } - -private: - T* fObj; -}; - #endif diff --git a/src/ports/SkFontConfigInterface_android.cpp b/src/ports/SkFontConfigInterface_android.cpp index 236f62b808..c4f1753eb7 100644 --- a/src/ports/SkFontConfigInterface_android.cpp +++ b/src/ports/SkFontConfigInterface_android.cpp @@ -53,7 +53,7 @@ typedef int32_t FamilyRecID; // used to record our notion of the pre-existing fonts struct FontRec { - SkRefPtr<SkTypeface> fTypeface; + SkAutoTUnref<SkTypeface> fTypeface; SkString fFileName; SkTypeface::Style fStyle; bool fIsValid; @@ -115,8 +115,8 @@ private: FallbackFontList* getCurrentLocaleFallbackFontList(); FallbackFontList* findFallbackFontList(const SkLanguage& lang, bool isOriginal = true); - SkTArray<FontRec> fFonts; - SkTArray<FamilyRec> fFontFamilies; + SkTArray<FontRec, true> fFonts; + SkTArray<FamilyRec, true> fFontFamilies; SkTDict<FamilyRecID> fFamilyNameDict; FamilyRecID fDefaultFamilyRecID; @@ -163,7 +163,7 @@ SkFontConfigInterface* SkFontConfigInterface::GetSingletonDirectInterface(SkBase /////////////////////////////////////////////////////////////////////////////// -static bool has_font(const SkTArray<FontRec>& array, const SkString& filename) { +static bool has_font(const SkTArray<FontRec, true>& array, const SkString& filename) { for (int i = 0; i < array.count(); i++) { if (array[i].fFileName == filename) { return true; @@ -503,7 +503,7 @@ SkTypeface* SkFontConfigInterfaceAndroid::getTypefaceForFontRec(FontRecID fontRe } // store the result for subsequent lookups - fontRec.fTypeface = face; + fontRec.fTypeface.reset(face); } SkASSERT(face); return face; diff --git a/tests/UtilsTest.cpp b/tests/UtilsTest.cpp index 438a5cce47..2c84c958ec 100644 --- a/tests/UtilsTest.cpp +++ b/tests/UtilsTest.cpp @@ -53,14 +53,14 @@ static void test_autostarray(skiatest::Reporter* reporter) { REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt()); { - SkAutoSTArray<2, SkRefPtr<RefClass> > tmp; + SkAutoSTArray<2, SkAutoTUnref<RefClass> > tmp; REPORTER_ASSERT(reporter, 0 == tmp.count()); tmp.reset(0); // test out reset(0) when already at 0 tmp.reset(4); // this should force a new allocation REPORTER_ASSERT(reporter, 4 == tmp.count()); - tmp[0] = &obj0; - tmp[1] = &obj1; + tmp[0].reset(SkRef(&obj0)); + tmp[1].reset(SkRef(&obj1)); REPORTER_ASSERT(reporter, 2 == obj0.getRefCnt()); REPORTER_ASSERT(reporter, 2 == obj1.getRefCnt()); @@ -72,8 +72,8 @@ static void test_autostarray(skiatest::Reporter* reporter) { tmp.reset(2); // this should use the preexisting allocation REPORTER_ASSERT(reporter, 2 == tmp.count()); - tmp[0] = &obj0; - tmp[1] = &obj1; + tmp[0].reset(SkRef(&obj0)); + tmp[1].reset(SkRef(&obj1)); } // test out destructor with data in the array (and using existing allocation) @@ -82,11 +82,11 @@ static void test_autostarray(skiatest::Reporter* reporter) { { // test out allocating ctor (this should allocate new memory) - SkAutoSTArray<2, SkRefPtr<RefClass> > tmp(4); + SkAutoSTArray<2, SkAutoTUnref<RefClass> > tmp(4); REPORTER_ASSERT(reporter, 4 == tmp.count()); - tmp[0] = &obj0; - tmp[1] = &obj1; + tmp[0].reset(SkRef(&obj0)); + tmp[1].reset(SkRef(&obj1)); REPORTER_ASSERT(reporter, 2 == obj0.getRefCnt()); REPORTER_ASSERT(reporter, 2 == obj1.getRefCnt()); @@ -96,8 +96,8 @@ static void test_autostarray(skiatest::Reporter* reporter) { REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt()); tmp.reset(2); // this should use the preexisting storage - tmp[0] = &obj0; - tmp[1] = &obj1; + tmp[0].reset(SkRef(&obj0)); + tmp[1].reset(SkRef(&obj1)); REPORTER_ASSERT(reporter, 2 == obj0.getRefCnt()); REPORTER_ASSERT(reporter, 2 == obj1.getRefCnt()); @@ -105,8 +105,8 @@ static void test_autostarray(skiatest::Reporter* reporter) { REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt()); REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt()); - tmp[0] = &obj0; - tmp[1] = &obj1; + tmp[0].reset(SkRef(&obj0)); + tmp[1].reset(SkRef(&obj1)); REPORTER_ASSERT(reporter, 2 == obj0.getRefCnt()); REPORTER_ASSERT(reporter, 2 == obj1.getRefCnt()); } |