summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
author Seigo Nonaka <nona@google.com> 2024-11-23 11:30:48 +0900
committer Seigo Nonaka <nona@google.com> 2024-11-25 14:38:36 +0900
commitfe1c8dfd6aaadd63cdaeacaf83e9f6f425854441 (patch)
tree81a8e51b7264c6a18059dddf7cca5398abd73fd6 /libs
parent09e4858b01e7818c5e5462c8a9ac5b3e4300390e (diff)
Don't create variation instance if the Typeface is variation instance
Bug: 379218341 Test: Manually done Flag: com.android.text.flags.typeface_redesign Change-Id: I71ac97fb5ca8fd06372cd3e7120f25c4f1fc6327
Diffstat (limited to 'libs')
-rw-r--r--libs/hwui/hwui/Typeface.cpp5
-rw-r--r--libs/hwui/hwui/Typeface.h3
-rw-r--r--libs/hwui/jni/text/TextShaper.cpp14
3 files changed, 19 insertions, 3 deletions
diff --git a/libs/hwui/hwui/Typeface.cpp b/libs/hwui/hwui/Typeface.cpp
index 2d812d675fdc..4dfe05377a48 100644
--- a/libs/hwui/hwui/Typeface.cpp
+++ b/libs/hwui/hwui/Typeface.cpp
@@ -76,6 +76,7 @@ Typeface* Typeface::createRelative(Typeface* src, Typeface::Style style) {
result->fBaseWeight = resolvedFace->fBaseWeight;
result->fAPIStyle = style;
result->fStyle = computeRelativeStyle(result->fBaseWeight, style);
+ result->fIsVariationInstance = resolvedFace->fIsVariationInstance;
}
return result;
}
@@ -88,6 +89,7 @@ Typeface* Typeface::createAbsolute(Typeface* base, int weight, bool italic) {
result->fBaseWeight = resolvedFace->fBaseWeight;
result->fAPIStyle = computeAPIStyle(weight, italic);
result->fStyle = computeMinikinStyle(weight, italic);
+ result->fIsVariationInstance = resolvedFace->fIsVariationInstance;
}
return result;
}
@@ -109,6 +111,7 @@ Typeface* Typeface::createFromTypefaceWithVariation(Typeface* src,
result->fBaseWeight = resolvedFace->fBaseWeight;
result->fAPIStyle = resolvedFace->fAPIStyle;
result->fStyle = resolvedFace->fStyle;
+ result->fIsVariationInstance = true;
}
return result;
}
@@ -121,6 +124,7 @@ Typeface* Typeface::createWithDifferentBaseWeight(Typeface* src, int weight) {
result->fBaseWeight = weight;
result->fAPIStyle = resolvedFace->fAPIStyle;
result->fStyle = computeRelativeStyle(weight, result->fAPIStyle);
+ result->fIsVariationInstance = resolvedFace->fIsVariationInstance;
}
return result;
}
@@ -170,6 +174,7 @@ Typeface* Typeface::createFromFamilies(std::vector<std::shared_ptr<minikin::Font
result->fBaseWeight = weight;
result->fAPIStyle = computeAPIStyle(weight, italic);
result->fStyle = computeMinikinStyle(weight, italic);
+ result->fIsVariationInstance = false;
return result;
}
diff --git a/libs/hwui/hwui/Typeface.h b/libs/hwui/hwui/Typeface.h
index 2c96c1ad80fe..97d1bf4ef011 100644
--- a/libs/hwui/hwui/Typeface.h
+++ b/libs/hwui/hwui/Typeface.h
@@ -44,6 +44,9 @@ public:
// base weight in CSS-style units, 1..1000
int fBaseWeight;
+ // True if the Typeface is already created for variation settings.
+ bool fIsVariationInstance;
+
static const Typeface* resolveDefault(const Typeface* src);
// The following three functions create new Typeface from an existing Typeface with a different
diff --git a/libs/hwui/jni/text/TextShaper.cpp b/libs/hwui/jni/text/TextShaper.cpp
index 5f693462af91..c73598960551 100644
--- a/libs/hwui/jni/text/TextShaper.cpp
+++ b/libs/hwui/jni/text/TextShaper.cpp
@@ -68,7 +68,7 @@ static void releaseLayout(jlong ptr) {
static jlong shapeTextRun(const uint16_t* text, int textSize, int start, int count,
int contextStart, int contextCount, minikin::Bidi bidiFlags,
const Paint& paint, const Typeface* typeface) {
-
+ const Typeface* resolvedFace = Typeface::resolveDefault(typeface);
minikin::MinikinPaint minikinPaint = MinikinUtils::prepareMinikinPaint(&paint, typeface);
minikin::Layout layout = MinikinUtils::doLayout(&paint, bidiFlags, typeface,
@@ -103,8 +103,16 @@ static jlong shapeTextRun(const uint16_t* text, int textSize, int start, int cou
fontId = it->second; // We've seen it.
} else {
fontId = fonts.size(); // This is new to us. Create new one.
- std::shared_ptr<minikin::Font> font = std::make_shared<minikin::Font>(
- fakedFont.font, fakedFont.fakery.variationSettings());
+ std::shared_ptr<minikin::Font> font;
+ if (resolvedFace->fIsVariationInstance) {
+ // The optimization for target SDK 35 or before because the variation instance
+ // is already created and no runtime variation resolution happens on such
+ // environment.
+ font = fakedFont.font;
+ } else {
+ font = std::make_shared<minikin::Font>(fakedFont.font,
+ fakedFont.fakery.variationSettings());
+ }
fonts.push_back(reinterpret_cast<jlong>(new FontWrapper(std::move(font))));
fakedToFontIds.insert(std::make_pair(fakedFont, fontId));
}