diff --git a/gfx/thebes/AndroidSystemFontIterator.cpp b/gfx/thebes/AndroidSystemFontIterator.cpp index 4590df4dbafe..2b13088ec103 100644 --- a/gfx/thebes/AndroidSystemFontIterator.cpp +++ b/gfx/thebes/AndroidSystemFontIterator.cpp @@ -8,7 +8,7 @@ #include "mozilla/Assertions.h" #include "nsDebug.h" -#include +#include namespace mozilla { @@ -36,26 +36,14 @@ AndroidSystemFontIterator::~AndroidSystemFontIterator() { bool AndroidSystemFontIterator::Init() { if (!sSystemFontIterator_open) { - void* handle = dlopen("libandroid.so", RTLD_LAZY | RTLD_LOCAL); - MOZ_ASSERT(handle); - - sSystemFontIterator_open = - (_ASystemFontIterator_open)dlsym(handle, "ASystemFontIterator_open"); - sSystemFontIterator_next = - (_ASystemFontIterator_next)dlsym(handle, "ASystemFontIterator_next"); - sSystemFontIterator_close = - (_ASystemFontIterator_close)dlsym(handle, "ASystemFontIterator_close"); - AndroidFont::sFont_getFontFilePath = - (_AFont_getFontFilePath)dlsym(handle, "AFont_getFontFilePath"); - AndroidFont::sFont_close = (_AFont_close)dlsym(handle, "AFont_close"); - - if (NS_WARN_IF(!sSystemFontIterator_open) || - NS_WARN_IF(!sSystemFontIterator_next) || - NS_WARN_IF(!sSystemFontIterator_close) || - NS_WARN_IF(!AndroidFont::sFont_getFontFilePath) || - NS_WARN_IF(!AndroidFont::sFont_close)) { - sSystemFontIterator_open = nullptr; - return false; + if (__builtin_available(android 29, *)) { + sSystemFontIterator_open = ASystemFontIterator_open; + sSystemFontIterator_next = ASystemFontIterator_next; + sSystemFontIterator_close = ASystemFontIterator_close; + AndroidFont::sFont_getFontFilePath = AFont_getFontFilePath; + AndroidFont::sFont_close = AFont_close; + } else { + return NS_WARN_IF(false); } } @@ -73,7 +61,7 @@ Maybe AndroidSystemFontIterator::Next() { return Nothing(); } - void* font = sSystemFontIterator_next(mIterator); + AFont* font = sSystemFontIterator_next(mIterator); if (!font) { sSystemFontIterator_close(mIterator); mIterator = nullptr; diff --git a/gfx/thebes/AndroidSystemFontIterator.h b/gfx/thebes/AndroidSystemFontIterator.h index f1507585129b..6eb989f89a50 100644 --- a/gfx/thebes/AndroidSystemFontIterator.h +++ b/gfx/thebes/AndroidSystemFontIterator.h @@ -7,19 +7,23 @@ #define AndroidSystemFontIterator_h__ #include "mozilla/Maybe.h" +#include +#include namespace mozilla { -typedef void* (*_ASystemFontIterator_open)(); -typedef void* (*_ASystemFontIterator_next)(void*); -typedef void (*_ASystemFontIterator_close)(void*); - -typedef const char* (*_AFont_getFontFilePath)(const void*); -typedef void (*_AFont_close)(void*); +typedef ASystemFontIterator* _Nullable (*_ASystemFontIterator_open)(); +typedef AFont* _Nullable (*_ASystemFontIterator_next)( + ASystemFontIterator* _Nonnull iterator); +typedef void (*_ASystemFontIterator_close)( + ASystemFontIterator* _Nullable iterator); +typedef const char* _Nonnull (*_AFont_getFontFilePath)( + const AFont* _Nonnull font); +typedef void (*_AFont_close)(AFont* _Nullable font); class AndroidFont final { public: - explicit AndroidFont(void* aFont) : mFont(aFont) {}; + explicit AndroidFont(AFont* _Nullable aFont) : mFont(aFont) {}; AndroidFont() = delete; AndroidFont(AndroidFont&) = delete; @@ -31,13 +35,13 @@ class AndroidFont final { ~AndroidFont(); - const char* GetFontFilePath(); + const char* _Nullable GetFontFilePath(); private: - void* mFont; + AFont* _Nullable mFont; - static _AFont_getFontFilePath sFont_getFontFilePath; - static _AFont_close sFont_close; + static _AFont_getFontFilePath _Nullable sFont_getFontFilePath; + static _AFont_close _Nullable sFont_close; friend class AndroidSystemFontIterator; }; @@ -53,11 +57,11 @@ class AndroidSystemFontIterator final { Maybe Next(); private: - void* mIterator = nullptr; + ASystemFontIterator* _Nullable mIterator = nullptr; - static _ASystemFontIterator_open sSystemFontIterator_open; - static _ASystemFontIterator_next sSystemFontIterator_next; - static _ASystemFontIterator_close sSystemFontIterator_close; + static _ASystemFontIterator_open _Nullable sSystemFontIterator_open; + static _ASystemFontIterator_next _Nullable sSystemFontIterator_next; + static _ASystemFontIterator_close _Nullable sSystemFontIterator_close; }; } // namespace mozilla