Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3008d3c2 authored by Seigo Nonaka's avatar Seigo Nonaka
Browse files

Use fontation SkTypeface backend

By default, the FreeType implementation is still used.
Following command changes text library from FreeType to Fontation.

```adb shell setprop debug.hwui.text.backend 2```

Bug: 405267306
Test: atest CtsWidgetTestCases CtsTextTestCases CtsGraphicsTestCases
Flag: com.android.text.flags.use_fontation_by_default
Change-Id: I955c0147de3226cec233b5b441f06f222776b64c
parent e875b051
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -215,3 +215,10 @@ flag {
  bug: "355296926"
  is_exported: true
}

flag {
  name: "use_fontation_by_default"
  namespace: "text"
  description: "Use Fontation(Skrifa) as a default text reader."
  bug: "405267306"
}
+9 −0
Original line number Diff line number Diff line
@@ -43,6 +43,15 @@ inline bool typeface_redesign_readonly() {
#endif  // __ANDROID__
}

inline bool use_fontation_by_default() {
#ifdef __ANDROID__
    static bool flag = com_android_text_flags_use_fontation_by_default();
    return flag;
#else
    return true;
#endif  // __ANDROID__
}

}  // namespace text_feature

namespace view_accessibility_flags {
+10 −0
Original line number Diff line number Diff line
@@ -238,6 +238,16 @@ enum DebugLevel {

#define PROPERTY_EARLY_PRELOAD_GL_CONTEXT "debug.hwui.early_preload_gl_context"

/**
 * Property for font reading library.
 */
#define PROPERTY_SKTYPEFACE_BACKEND "debug.hwui.text.backend"

enum class SkTypefaceBackend {
    kAuto = 0,
    kFreeType = 1,
    kFontation = 2,
};
///////////////////////////////////////////////////////////////////////////////
// Misc
///////////////////////////////////////////////////////////////////////////////
+1 −3
Original line number Diff line number Diff line
@@ -160,9 +160,7 @@ void Typeface::setRobotoTypefaceForTest() {
    LOG_ALWAYS_FATAL_IF(fstat(fd, &st) == -1, "Failed to stat file %s", kRobotoFont);
    void* data = mmap(nullptr, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
    std::unique_ptr<SkStreamAsset> fontData(new SkMemoryStream(data, st.st_size));
    sk_sp<SkFontMgr> fm = android::FreeTypeFontMgr();
    LOG_ALWAYS_FATAL_IF(fm == nullptr, "Could not load FreeType SkFontMgr");
    sk_sp<SkTypeface> typeface = fm->makeFromStream(std::move(fontData));
    sk_sp<SkTypeface> typeface = android::makeSkTypeface(std::move(fontData), SkFontArguments());
    LOG_ALWAYS_FATAL_IF(typeface == nullptr, "Failed to make typeface from %s", kRobotoFont);

    std::shared_ptr<minikin::MinikinFont> font = std::make_shared<MinikinFontSkia>(
+1 −2
Original line number Diff line number Diff line
@@ -126,8 +126,7 @@ static bool addSkTypeface(NativeFamilyBuilder* builder, sk_sp<SkData>&& data, in
    args.setCollectionIndex(ttcIndex);
    args.setVariationDesignPosition({skVariation.data(), static_cast<int>(skVariation.size())});

    sk_sp<SkFontMgr> fm = android::FreeTypeFontMgr();
    sk_sp<SkTypeface> face(fm->makeFromStream(std::move(fontData), args));
    sk_sp<SkTypeface> face = makeSkTypeface(std::move(fontData), args);
    if (face == NULL) {
        ALOGE("addFont failed to create font, invalid request");
        builder->axes.clear();
Loading