summaryrefslogtreecommitdiffstats
path: root/include/minikin
diff options
context:
space:
mode:
authorSeigo Nonaka <nona@google.com>2016-04-11 17:53:34 +0900
committerRaph Levien <raph@google.com>2016-04-11 13:33:35 -0700
commit6c60831cfce24b0749f50f37231e0a56d8fd4b85 (patch)
tree6f389a2979b0585148168a6e6ea1ad91ee655272 /include/minikin
parent29abb82198868908ece4600284fa8b7d3ed73f3b (diff)
downloadandroid_frameworks_minikin-6c60831cfce24b0749f50f37231e0a56d8fd4b85.tar.gz
android_frameworks_minikin-6c60831cfce24b0749f50f37231e0a56d8fd4b85.tar.bz2
android_frameworks_minikin-6c60831cfce24b0749f50f37231e0a56d8fd4b85.zip
Fix minikin_unittests
This CL fixes following test cases in minikin_tests - FontFamilyTest.hasVariationSelectorTest - HbFontCacheTest.getHbFontLockedTest - HbFontCacheTest.purgeCacheTest For the fix of FontFamilyTest.hasVariationSelectorTest, removing virtual from GetUniqueId() in MinikinFont. After [1], MinikinFont's destructor started calling purgeHbCache() which calls virtual method, MinikinFont::GetUniqueId(). Fortunately, the SkTypeface::uniqueID() returns just internal value, so we can store it at the construction time and use it instead of calling SkTypeface::uniqueID() every time. This patch also changes purgeHbFont to purgeHbFontLocked, as all uses of it were already under global mutex. This change avoids deadlock on explicit unref, as when invoked by a Java finalizer from the Java object that holds a reference to the font. Some of the tests needed to change to using the ref counting protocol rather than explicitly destructing font objects, as well. [1] 9afcc6e2bd4d89e4e1deb6e18c3c4daca4e114fd Bug: 28105730 Bug: 28105688 Change-Id: Ie5983c4869147dacabdca81af1605066cd680b3f
Diffstat (limited to 'include/minikin')
-rw-r--r--include/minikin/MinikinFont.h8
-rw-r--r--include/minikin/MinikinFontFreeType.h3
-rw-r--r--include/minikin/MinikinRefCounted.h17
3 files changed, 23 insertions, 5 deletions
diff --git a/include/minikin/MinikinFont.h b/include/minikin/MinikinFont.h
index 0298235..4951514 100644
--- a/include/minikin/MinikinFont.h
+++ b/include/minikin/MinikinFont.h
@@ -99,6 +99,8 @@ typedef void (*MinikinDestroyFunc) (void* data);
class MinikinFont : public MinikinRefCounted {
public:
+ MinikinFont(int32_t uniqueId) : mUniqueId(uniqueId) {}
+
virtual ~MinikinFont();
virtual float GetHorizontalAdvance(uint32_t glyph_id,
@@ -125,12 +127,14 @@ public:
return 0;
}
- virtual int32_t GetUniqueId() const = 0;
-
static uint32_t MakeTag(char c1, char c2, char c3, char c4) {
return ((uint32_t)c1 << 24) | ((uint32_t)c2 << 16) |
((uint32_t)c3 << 8) | (uint32_t)c4;
}
+
+ int32_t GetUniqueId() const { return mUniqueId; }
+private:
+ const int32_t mUniqueId;
};
} // namespace android
diff --git a/include/minikin/MinikinFontFreeType.h b/include/minikin/MinikinFontFreeType.h
index 535c249..baa08df 100644
--- a/include/minikin/MinikinFontFreeType.h
+++ b/include/minikin/MinikinFontFreeType.h
@@ -52,8 +52,6 @@ public:
// TODO: provide access to raw data, as an optimization.
- int32_t GetUniqueId() const;
-
// Not a virtual method, as the protocol to access rendered
// glyph bitmaps is probably different depending on the
// backend.
@@ -64,7 +62,6 @@ public:
private:
FT_Face mTypeface;
- int32_t mUniqueId;
static int32_t sIdCounter;
};
diff --git a/include/minikin/MinikinRefCounted.h b/include/minikin/MinikinRefCounted.h
index 74d27fe..603aff0 100644
--- a/include/minikin/MinikinRefCounted.h
+++ b/include/minikin/MinikinRefCounted.h
@@ -37,6 +37,23 @@ private:
int mRefcount_;
};
+// An RAII container for reference counted objects.
+// Note: this is only suitable for clients which are _not_ holding the global lock.
+template <typename T>
+class MinikinAutoUnref {
+public:
+ MinikinAutoUnref(T* obj) : mObj(obj) {
+ }
+ ~MinikinAutoUnref() {
+ mObj->Unref();
+ }
+ T& operator*() const { return *mObj; }
+ T* operator->() const { return mObj; }
+ T* get() const { return mObj; }
+private:
+ T* mObj;
+};
+
}
#endif // MINIKIN_REF_COUNTED_H \ No newline at end of file