Loading graphics/java/android/graphics/fonts/Font.java +4 −22 Original line number Original line Diff line number Diff line Loading @@ -27,7 +27,6 @@ import android.graphics.RectF; import android.os.LocaleList; import android.os.LocaleList; import android.os.ParcelFileDescriptor; import android.os.ParcelFileDescriptor; import android.text.TextUtils; import android.text.TextUtils; import android.util.LongSparseLongArray; import android.util.TypedValue; import android.util.TypedValue; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.GuardedBy; Loading Loading @@ -67,11 +66,6 @@ public final class Font { NativeAllocationRegistry.createMalloced(Font.class.getClassLoader(), NativeAllocationRegistry.createMalloced(Font.class.getClassLoader(), nGetReleaseNativeFont()); nGetReleaseNativeFont()); private static final Object SOURCE_ID_LOCK = new Object(); @GuardedBy("SOURCE_ID_LOCK") private static final LongSparseLongArray FONT_SOURCE_ID_MAP = new LongSparseLongArray(300); // System font has 200 fonts, so 300 should be enough. /** /** * A builder class for creating new Font. * A builder class for creating new Font. */ */ Loading Loading @@ -523,8 +517,6 @@ public final class Font { private @Nullable FontVariationAxis[] mAxes = null; private @Nullable FontVariationAxis[] mAxes = null; @GuardedBy("mLock") @GuardedBy("mLock") private @NonNull LocaleList mLocaleList = null; private @NonNull LocaleList mLocaleList = null; @GuardedBy("mLock") private int mSourceIdentifier = -1; /** /** * Use Builder instead * Use Builder instead Loading Loading @@ -758,20 +750,7 @@ public final class Font { * @return an unique identifier for the font source data. * @return an unique identifier for the font source data. */ */ public int getSourceIdentifier() { public int getSourceIdentifier() { synchronized (mLock) { return nGetSourceId(mNativePtr); if (mSourceIdentifier == -1) { long bufferAddress = nGetBufferAddress(mNativePtr); synchronized (SOURCE_ID_LOCK) { long id = FONT_SOURCE_ID_MAP.get(bufferAddress, -1); if (id == -1) { id = FONT_SOURCE_ID_MAP.size(); FONT_SOURCE_ID_MAP.append(bufferAddress, id); } mSourceIdentifier = (int) id; } } return mSourceIdentifier; } } } /** /** Loading Loading @@ -889,6 +868,9 @@ public final class Font { @CriticalNative @CriticalNative private static native long nGetBufferAddress(long font); private static native long nGetBufferAddress(long font); @CriticalNative private static native int nGetSourceId(long font); @CriticalNative @CriticalNative private static native long nGetReleaseNativeFont(); private static native long nGetReleaseNativeFont(); Loading libs/hwui/hwui/MinikinSkia.cpp +5 −4 Original line number Original line Diff line number Diff line Loading @@ -30,10 +30,11 @@ namespace android { namespace android { MinikinFontSkia::MinikinFontSkia(sk_sp<SkTypeface> typeface, const void* fontData, size_t fontSize, MinikinFontSkia::MinikinFontSkia(sk_sp<SkTypeface> typeface, int sourceId, const void* fontData, std::string_view filePath, int ttcIndex, size_t fontSize, std::string_view filePath, int ttcIndex, const std::vector<minikin::FontVariation>& axes) const std::vector<minikin::FontVariation>& axes) : mTypeface(std::move(typeface)) : mTypeface(std::move(typeface)) , mSourceId(sourceId) , mFontData(fontData) , mFontData(fontData) , mFontSize(fontSize) , mFontSize(fontSize) , mTtcIndex(ttcIndex) , mTtcIndex(ttcIndex) Loading Loading @@ -141,8 +142,8 @@ std::shared_ptr<minikin::MinikinFont> MinikinFontSkia::createFontWithVariation( sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault()); sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault()); sk_sp<SkTypeface> face(fm->makeFromStream(std::move(stream), args)); sk_sp<SkTypeface> face(fm->makeFromStream(std::move(stream), args)); return std::make_shared<MinikinFontSkia>(std::move(face), mFontData, mFontSize, mFilePath, return std::make_shared<MinikinFontSkia>(std::move(face), mSourceId, mFontData, mFontSize, ttcIndex, variations); mFilePath, ttcIndex, variations); } } // hinting<<16 | edging<<8 | bools:5bits // hinting<<16 | edging<<8 | bools:5bits Loading libs/hwui/hwui/MinikinSkia.h +3 −1 Original line number Original line Diff line number Diff line Loading @@ -30,7 +30,7 @@ namespace android { class ANDROID_API MinikinFontSkia : public minikin::MinikinFont { class ANDROID_API MinikinFontSkia : public minikin::MinikinFont { public: public: MinikinFontSkia(sk_sp<SkTypeface> typeface, const void* fontData, size_t fontSize, MinikinFontSkia(sk_sp<SkTypeface> typeface, int sourceId, const void* fontData, size_t fontSize, std::string_view filePath, int ttcIndex, std::string_view filePath, int ttcIndex, const std::vector<minikin::FontVariation>& axes); const std::vector<minikin::FontVariation>& axes); Loading Loading @@ -62,6 +62,7 @@ public: const std::vector<minikin::FontVariation>& GetAxes() const; const std::vector<minikin::FontVariation>& GetAxes() const; std::shared_ptr<minikin::MinikinFont> createFontWithVariation( std::shared_ptr<minikin::MinikinFont> createFontWithVariation( const std::vector<minikin::FontVariation>&) const; const std::vector<minikin::FontVariation>&) const; int GetSourceId() const override { return mSourceId; } static uint32_t packFontFlags(const SkFont&); static uint32_t packFontFlags(const SkFont&); static void unpackFontFlags(SkFont*, uint32_t fontFlags); static void unpackFontFlags(SkFont*, uint32_t fontFlags); Loading @@ -73,6 +74,7 @@ public: private: private: sk_sp<SkTypeface> mTypeface; sk_sp<SkTypeface> mTypeface; int mSourceId; // A raw pointer to the font data - it should be owned by some other object with // A raw pointer to the font data - it should be owned by some other object with // lifetime at least as long as this object. // lifetime at least as long as this object. const void* mFontData; const void* mFontData; Loading libs/hwui/hwui/Typeface.cpp +3 −3 Original line number Original line Diff line number Diff line Loading @@ -185,9 +185,9 @@ void Typeface::setRobotoTypefaceForTest() { sk_sp<SkTypeface> typeface = SkTypeface::MakeFromStream(std::move(fontData)); sk_sp<SkTypeface> typeface = SkTypeface::MakeFromStream(std::move(fontData)); LOG_ALWAYS_FATAL_IF(typeface == nullptr, "Failed to make typeface from %s", kRobotoFont); LOG_ALWAYS_FATAL_IF(typeface == nullptr, "Failed to make typeface from %s", kRobotoFont); std::shared_ptr<minikin::MinikinFont> font = std::make_shared<MinikinFontSkia>( std::shared_ptr<minikin::MinikinFont> font = std::move(typeface), data, st.st_size, kRobotoFont, 0, std::make_shared<MinikinFontSkia>(std::move(typeface), 0, data, st.st_size, kRobotoFont, std::vector<minikin::FontVariation>()); 0, std::vector<minikin::FontVariation>()); std::vector<std::shared_ptr<minikin::Font>> fonts; std::vector<std::shared_ptr<minikin::Font>> fonts; fonts.push_back(minikin::Font::Builder(font).build()); fonts.push_back(minikin::Font::Builder(font).build()); Loading libs/hwui/jni/FontFamily.cpp +13 −6 Original line number Original line Diff line number Diff line Loading @@ -17,15 +17,16 @@ #undef LOG_TAG #undef LOG_TAG #define LOG_TAG "Minikin" #define LOG_TAG "Minikin" #include <nativehelper/ScopedPrimitiveArray.h> #include <nativehelper/ScopedUtfChars.h> #include "FontUtils.h" #include "GraphicsJNI.h" #include "SkData.h" #include "SkData.h" #include "SkFontMgr.h" #include "SkFontMgr.h" #include "SkRefCnt.h" #include "SkRefCnt.h" #include "SkTypeface.h" #include "SkTypeface.h" #include "GraphicsJNI.h" #include <nativehelper/ScopedPrimitiveArray.h> #include <nativehelper/ScopedUtfChars.h> #include "Utils.h" #include "Utils.h" #include "FontUtils.h" #include "fonts/Font.h" #include <hwui/MinikinSkia.h> #include <hwui/MinikinSkia.h> #include <hwui/Typeface.h> #include <hwui/Typeface.h> Loading @@ -35,6 +36,12 @@ #include <memory> #include <memory> /////////////////////////////////////////////////////////////////////////////////////////////////// // // The following JNI methods are kept only for compatibility reasons due to hidden API accesses. // /////////////////////////////////////////////////////////////////////////////////////////////////// namespace android { namespace android { struct NativeFamilyBuilder { struct NativeFamilyBuilder { Loading Loading @@ -125,8 +132,8 @@ static bool addSkTypeface(NativeFamilyBuilder* builder, sk_sp<SkData>&& data, in return false; return false; } } std::shared_ptr<minikin::MinikinFont> minikinFont = std::shared_ptr<minikin::MinikinFont> minikinFont = std::make_shared<MinikinFontSkia>(std::move(face), fontPtr, fontSize, "", ttcIndex, std::make_shared<MinikinFontSkia>(std::move(face), fonts::getNewSourceId(), fontPtr, builder->axes); fontSize, "", ttcIndex, builder->axes); minikin::Font::Builder fontBuilder(minikinFont); minikin::Font::Builder fontBuilder(minikinFont); if (weight != RESOLVE_BY_FONT_TABLE) { if (weight != RESOLVE_BY_FONT_TABLE) { Loading Loading
graphics/java/android/graphics/fonts/Font.java +4 −22 Original line number Original line Diff line number Diff line Loading @@ -27,7 +27,6 @@ import android.graphics.RectF; import android.os.LocaleList; import android.os.LocaleList; import android.os.ParcelFileDescriptor; import android.os.ParcelFileDescriptor; import android.text.TextUtils; import android.text.TextUtils; import android.util.LongSparseLongArray; import android.util.TypedValue; import android.util.TypedValue; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.GuardedBy; Loading Loading @@ -67,11 +66,6 @@ public final class Font { NativeAllocationRegistry.createMalloced(Font.class.getClassLoader(), NativeAllocationRegistry.createMalloced(Font.class.getClassLoader(), nGetReleaseNativeFont()); nGetReleaseNativeFont()); private static final Object SOURCE_ID_LOCK = new Object(); @GuardedBy("SOURCE_ID_LOCK") private static final LongSparseLongArray FONT_SOURCE_ID_MAP = new LongSparseLongArray(300); // System font has 200 fonts, so 300 should be enough. /** /** * A builder class for creating new Font. * A builder class for creating new Font. */ */ Loading Loading @@ -523,8 +517,6 @@ public final class Font { private @Nullable FontVariationAxis[] mAxes = null; private @Nullable FontVariationAxis[] mAxes = null; @GuardedBy("mLock") @GuardedBy("mLock") private @NonNull LocaleList mLocaleList = null; private @NonNull LocaleList mLocaleList = null; @GuardedBy("mLock") private int mSourceIdentifier = -1; /** /** * Use Builder instead * Use Builder instead Loading Loading @@ -758,20 +750,7 @@ public final class Font { * @return an unique identifier for the font source data. * @return an unique identifier for the font source data. */ */ public int getSourceIdentifier() { public int getSourceIdentifier() { synchronized (mLock) { return nGetSourceId(mNativePtr); if (mSourceIdentifier == -1) { long bufferAddress = nGetBufferAddress(mNativePtr); synchronized (SOURCE_ID_LOCK) { long id = FONT_SOURCE_ID_MAP.get(bufferAddress, -1); if (id == -1) { id = FONT_SOURCE_ID_MAP.size(); FONT_SOURCE_ID_MAP.append(bufferAddress, id); } mSourceIdentifier = (int) id; } } return mSourceIdentifier; } } } /** /** Loading Loading @@ -889,6 +868,9 @@ public final class Font { @CriticalNative @CriticalNative private static native long nGetBufferAddress(long font); private static native long nGetBufferAddress(long font); @CriticalNative private static native int nGetSourceId(long font); @CriticalNative @CriticalNative private static native long nGetReleaseNativeFont(); private static native long nGetReleaseNativeFont(); Loading
libs/hwui/hwui/MinikinSkia.cpp +5 −4 Original line number Original line Diff line number Diff line Loading @@ -30,10 +30,11 @@ namespace android { namespace android { MinikinFontSkia::MinikinFontSkia(sk_sp<SkTypeface> typeface, const void* fontData, size_t fontSize, MinikinFontSkia::MinikinFontSkia(sk_sp<SkTypeface> typeface, int sourceId, const void* fontData, std::string_view filePath, int ttcIndex, size_t fontSize, std::string_view filePath, int ttcIndex, const std::vector<minikin::FontVariation>& axes) const std::vector<minikin::FontVariation>& axes) : mTypeface(std::move(typeface)) : mTypeface(std::move(typeface)) , mSourceId(sourceId) , mFontData(fontData) , mFontData(fontData) , mFontSize(fontSize) , mFontSize(fontSize) , mTtcIndex(ttcIndex) , mTtcIndex(ttcIndex) Loading Loading @@ -141,8 +142,8 @@ std::shared_ptr<minikin::MinikinFont> MinikinFontSkia::createFontWithVariation( sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault()); sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault()); sk_sp<SkTypeface> face(fm->makeFromStream(std::move(stream), args)); sk_sp<SkTypeface> face(fm->makeFromStream(std::move(stream), args)); return std::make_shared<MinikinFontSkia>(std::move(face), mFontData, mFontSize, mFilePath, return std::make_shared<MinikinFontSkia>(std::move(face), mSourceId, mFontData, mFontSize, ttcIndex, variations); mFilePath, ttcIndex, variations); } } // hinting<<16 | edging<<8 | bools:5bits // hinting<<16 | edging<<8 | bools:5bits Loading
libs/hwui/hwui/MinikinSkia.h +3 −1 Original line number Original line Diff line number Diff line Loading @@ -30,7 +30,7 @@ namespace android { class ANDROID_API MinikinFontSkia : public minikin::MinikinFont { class ANDROID_API MinikinFontSkia : public minikin::MinikinFont { public: public: MinikinFontSkia(sk_sp<SkTypeface> typeface, const void* fontData, size_t fontSize, MinikinFontSkia(sk_sp<SkTypeface> typeface, int sourceId, const void* fontData, size_t fontSize, std::string_view filePath, int ttcIndex, std::string_view filePath, int ttcIndex, const std::vector<minikin::FontVariation>& axes); const std::vector<minikin::FontVariation>& axes); Loading Loading @@ -62,6 +62,7 @@ public: const std::vector<minikin::FontVariation>& GetAxes() const; const std::vector<minikin::FontVariation>& GetAxes() const; std::shared_ptr<minikin::MinikinFont> createFontWithVariation( std::shared_ptr<minikin::MinikinFont> createFontWithVariation( const std::vector<minikin::FontVariation>&) const; const std::vector<minikin::FontVariation>&) const; int GetSourceId() const override { return mSourceId; } static uint32_t packFontFlags(const SkFont&); static uint32_t packFontFlags(const SkFont&); static void unpackFontFlags(SkFont*, uint32_t fontFlags); static void unpackFontFlags(SkFont*, uint32_t fontFlags); Loading @@ -73,6 +74,7 @@ public: private: private: sk_sp<SkTypeface> mTypeface; sk_sp<SkTypeface> mTypeface; int mSourceId; // A raw pointer to the font data - it should be owned by some other object with // A raw pointer to the font data - it should be owned by some other object with // lifetime at least as long as this object. // lifetime at least as long as this object. const void* mFontData; const void* mFontData; Loading
libs/hwui/hwui/Typeface.cpp +3 −3 Original line number Original line Diff line number Diff line Loading @@ -185,9 +185,9 @@ void Typeface::setRobotoTypefaceForTest() { sk_sp<SkTypeface> typeface = SkTypeface::MakeFromStream(std::move(fontData)); sk_sp<SkTypeface> typeface = SkTypeface::MakeFromStream(std::move(fontData)); LOG_ALWAYS_FATAL_IF(typeface == nullptr, "Failed to make typeface from %s", kRobotoFont); LOG_ALWAYS_FATAL_IF(typeface == nullptr, "Failed to make typeface from %s", kRobotoFont); std::shared_ptr<minikin::MinikinFont> font = std::make_shared<MinikinFontSkia>( std::shared_ptr<minikin::MinikinFont> font = std::move(typeface), data, st.st_size, kRobotoFont, 0, std::make_shared<MinikinFontSkia>(std::move(typeface), 0, data, st.st_size, kRobotoFont, std::vector<minikin::FontVariation>()); 0, std::vector<minikin::FontVariation>()); std::vector<std::shared_ptr<minikin::Font>> fonts; std::vector<std::shared_ptr<minikin::Font>> fonts; fonts.push_back(minikin::Font::Builder(font).build()); fonts.push_back(minikin::Font::Builder(font).build()); Loading
libs/hwui/jni/FontFamily.cpp +13 −6 Original line number Original line Diff line number Diff line Loading @@ -17,15 +17,16 @@ #undef LOG_TAG #undef LOG_TAG #define LOG_TAG "Minikin" #define LOG_TAG "Minikin" #include <nativehelper/ScopedPrimitiveArray.h> #include <nativehelper/ScopedUtfChars.h> #include "FontUtils.h" #include "GraphicsJNI.h" #include "SkData.h" #include "SkData.h" #include "SkFontMgr.h" #include "SkFontMgr.h" #include "SkRefCnt.h" #include "SkRefCnt.h" #include "SkTypeface.h" #include "SkTypeface.h" #include "GraphicsJNI.h" #include <nativehelper/ScopedPrimitiveArray.h> #include <nativehelper/ScopedUtfChars.h> #include "Utils.h" #include "Utils.h" #include "FontUtils.h" #include "fonts/Font.h" #include <hwui/MinikinSkia.h> #include <hwui/MinikinSkia.h> #include <hwui/Typeface.h> #include <hwui/Typeface.h> Loading @@ -35,6 +36,12 @@ #include <memory> #include <memory> /////////////////////////////////////////////////////////////////////////////////////////////////// // // The following JNI methods are kept only for compatibility reasons due to hidden API accesses. // /////////////////////////////////////////////////////////////////////////////////////////////////// namespace android { namespace android { struct NativeFamilyBuilder { struct NativeFamilyBuilder { Loading Loading @@ -125,8 +132,8 @@ static bool addSkTypeface(NativeFamilyBuilder* builder, sk_sp<SkData>&& data, in return false; return false; } } std::shared_ptr<minikin::MinikinFont> minikinFont = std::shared_ptr<minikin::MinikinFont> minikinFont = std::make_shared<MinikinFontSkia>(std::move(face), fontPtr, fontSize, "", ttcIndex, std::make_shared<MinikinFontSkia>(std::move(face), fonts::getNewSourceId(), fontPtr, builder->axes); fontSize, "", ttcIndex, builder->axes); minikin::Font::Builder fontBuilder(minikinFont); minikin::Font::Builder fontBuilder(minikinFont); if (weight != RESOLVE_BY_FONT_TABLE) { if (weight != RESOLVE_BY_FONT_TABLE) { Loading