summaryrefslogtreecommitdiff
path: root/graphics/java/android
diff options
context:
space:
mode:
author Liana Kazanova (xWF) <lkazanova@google.com> 2024-08-08 18:56:01 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2024-08-08 18:56:01 +0000
commit367529e5dee9828929ffb9325c59f602218931ee (patch)
tree3a60324c76a817f65001ee1aa48197ac0144bc63 /graphics/java/android
parent4cefdc6df295534f7f94b26371dbacdba75db32f (diff)
Revert "Cache the variation instance of Typeface"
Revert submission 28490963-font_var_typeface_cache Reason for revert: DroidMonitor. Potential culprit for b/358347869 - verifying through ABTD before revert submission. This is part of the standard investigation process, and does not mean your CL will be reverted. Reverted changes: /q/submissionid:28490963-font_var_typeface_cache Change-Id: Ia3e291421dc8fe424245a3ed64c8b88bc1f8dc84
Diffstat (limited to 'graphics/java/android')
-rw-r--r--graphics/java/android/graphics/Typeface.java88
1 files changed, 2 insertions, 86 deletions
diff --git a/graphics/java/android/graphics/Typeface.java b/graphics/java/android/graphics/Typeface.java
index 889a778556b7..fd788167a0d8 100644
--- a/graphics/java/android/graphics/Typeface.java
+++ b/graphics/java/android/graphics/Typeface.java
@@ -56,7 +56,6 @@ import android.util.SparseArray;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.Preconditions;
-import com.android.text.flags.Flags;
import dalvik.annotation.optimization.CriticalNative;
import dalvik.annotation.optimization.FastNative;
@@ -75,7 +74,6 @@ import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
-import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -145,23 +143,6 @@ public class Typeface {
private static final LruCache<String, Typeface> sDynamicTypefaceCache = new LruCache<>(16);
private static final Object sDynamicCacheLock = new Object();
- private static final LruCache<Long, LruCache<String, Typeface>> sVariableCache =
- new LruCache<>(16);
- private static final Object sVariableCacheLock = new Object();
-
- /** @hide */
- @VisibleForTesting
- public static void clearTypefaceCachesForTestingPurpose() {
- synchronized (sWeightCacheLock) {
- sWeightTypefaceCache.clear();
- }
- synchronized (sDynamicCacheLock) {
- sDynamicTypefaceCache.evictAll();
- }
- synchronized (sVariableCacheLock) {
- sVariableCache.evictAll();
- }
- }
@GuardedBy("SYSTEM_FONT_MAP_LOCK")
static Typeface sDefaultTypeface;
@@ -214,8 +195,6 @@ public class Typeface {
@UnsupportedAppUsage
public final long native_instance;
- private final Typeface mDerivedFrom;
-
private final String mSystemFontFamilyName;
private final Runnable mCleaner;
@@ -295,18 +274,6 @@ public class Typeface {
}
/**
- * Returns the Typeface used for creating this Typeface.
- *
- * Maybe null if this is not derived from other Typeface.
- * TODO(b/357707916): Make this public API.
- * @hide
- */
- @VisibleForTesting
- public final @Nullable Typeface getDerivedFrom() {
- return mDerivedFrom;
- }
-
- /**
* Returns the system font family name if the typeface was created from a system font family,
* otherwise returns null.
*/
@@ -1054,51 +1021,9 @@ public class Typeface {
return typeface;
}
- private static String axesToVarKey(@NonNull List<FontVariationAxis> axes) {
- // The given list can be mutated because it is allocated in Paint#setFontVariationSettings.
- // Currently, Paint#setFontVariationSettings is the only code path reaches this method.
- axes.sort(Comparator.comparingInt(FontVariationAxis::getOpenTypeTagValue));
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < axes.size(); ++i) {
- final FontVariationAxis fva = axes.get(i);
- sb.append(fva.getTag());
- sb.append(fva.getStyleValue());
- }
- return sb.toString();
- }
-
- /**
- * TODO(b/357707916): Make this public API.
- * @hide
- */
+ /** @hide */
public static Typeface createFromTypefaceWithVariation(@Nullable Typeface family,
@NonNull List<FontVariationAxis> axes) {
- if (Flags.typefaceCacheForVarSettings()) {
- final Typeface target = (family == null) ? Typeface.DEFAULT : family;
- final Typeface base = (target.mDerivedFrom == null) ? target : target.mDerivedFrom;
-
- final String key = axesToVarKey(axes);
-
- synchronized (sVariableCacheLock) {
- LruCache<String, Typeface> innerCache = sVariableCache.get(base.native_instance);
- if (innerCache == null) {
- // Cache up to 16 var instance per root Typeface
- innerCache = new LruCache<>(16);
- sVariableCache.put(base.native_instance, innerCache);
- } else {
- Typeface cached = innerCache.get(key);
- if (cached != null) {
- return cached;
- }
- }
- Typeface typeface = new Typeface(
- nativeCreateFromTypefaceWithVariation(base.native_instance, axes),
- base.getSystemFontFamilyName(), base);
- innerCache.put(key, typeface);
- return typeface;
- }
- }
-
final Typeface base = family == null ? Typeface.DEFAULT : family;
Typeface typeface = new Typeface(
nativeCreateFromTypefaceWithVariation(base.native_instance, axes),
@@ -1259,19 +1184,11 @@ public class Typeface {
// don't allow clients to call this directly
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
private Typeface(long ni) {
- this(ni, null, null);
+ this(ni, null);
}
-
// don't allow clients to call this directly
- // This is kept for robolectric.
private Typeface(long ni, @Nullable String systemFontFamilyName) {
- this(ni, systemFontFamilyName, null);
- }
-
- // don't allow clients to call this directly
- private Typeface(long ni, @Nullable String systemFontFamilyName,
- @Nullable Typeface derivedFrom) {
if (ni == 0) {
throw new RuntimeException("native typeface cannot be made");
}
@@ -1281,7 +1198,6 @@ public class Typeface {
mStyle = nativeGetStyle(ni);
mWeight = nativeGetWeight(ni);
mSystemFontFamilyName = systemFontFamilyName;
- mDerivedFrom = derivedFrom;
}
/**