diff options
author | Daniel Norman <danielnorman@google.com> | 2021-06-18 15:33:36 -0700 |
---|---|---|
committer | Scott Lobdell <slobdell@google.com> | 2021-06-21 23:21:54 +0000 |
commit | b6d6690a3594cd78966e26508247d4ab1b66776f (patch) | |
tree | 43afd0520ff98b8729b5c8f73ef2ee1c7e77041a /graphics | |
parent | 71c831703ae59baf47e0afe611fecd714c481cdf (diff) | |
parent | 233ce9ef453bc7b47f7ac5d0eb1d5fda0ce845ab (diff) |
Merge SP1A.210616.001
Change-Id: I9acdc955f698dbebb8fad19cfd5cb71fcdd27b45
Diffstat (limited to 'graphics')
4 files changed, 36 insertions, 63 deletions
diff --git a/graphics/java/android/graphics/Typeface.java b/graphics/java/android/graphics/Typeface.java index b88751a610dd..61f7facf0916 100644 --- a/graphics/java/android/graphics/Typeface.java +++ b/graphics/java/android/graphics/Typeface.java @@ -1387,6 +1387,7 @@ public class Typeface { static { // Preload Roboto-Regular.ttf in Zygote for improving app launch performance. preloadFontFile("/system/fonts/Roboto-Regular.ttf"); + preloadFontFile("/system/fonts/RobotoStatic-Regular.ttf"); String locale = SystemProperties.get("persist.sys.locale", "en-US"); String script = ULocale.addLikelySubtags(ULocale.forLanguageTag(locale)).getScript(); diff --git a/graphics/java/android/graphics/drawable/RippleDrawable.java b/graphics/java/android/graphics/drawable/RippleDrawable.java index 73e65c2ec050..fe80b5845bf5 100644 --- a/graphics/java/android/graphics/drawable/RippleDrawable.java +++ b/graphics/java/android/graphics/drawable/RippleDrawable.java @@ -182,6 +182,7 @@ public class RippleDrawable extends LayerDrawable { private Canvas mMaskCanvas; private Matrix mMaskMatrix; private PorterDuffColorFilter mMaskColorFilter; + private PorterDuffColorFilter mFocusColorFilter; private boolean mHasValidMask; private int mComputedRadius = -1; @@ -330,18 +331,18 @@ public class RippleDrawable extends LayerDrawable { private void setRippleActive(boolean active) { if (mRippleActive != active) { mRippleActive = active; - } - if (mState.mRippleStyle == STYLE_SOLID) { - if (active) { - tryRippleEnter(); - } else { - tryRippleExit(); - } - } else { - if (active) { - startPatternedAnimation(); + if (mState.mRippleStyle == STYLE_SOLID) { + if (active) { + tryRippleEnter(); + } else { + tryRippleExit(); + } } else { - exitPatternedAnimation(); + if (active) { + startPatternedAnimation(); + } else { + exitPatternedAnimation(); + } } } } @@ -938,7 +939,7 @@ public class RippleDrawable extends LayerDrawable { final int alpha = Math.min((int) (origAlpha * newOpacity + 0.5f), 255); if (alpha > 0) { ColorFilter origFilter = p.getColorFilter(); - p.setColorFilter(mMaskColorFilter); + p.setColorFilter(mFocusColorFilter); p.setAlpha(alpha); c.drawCircle(cx, cy, getComputedRadius(), p); p.setAlpha(origAlpha); @@ -1091,6 +1092,7 @@ public class RippleDrawable extends LayerDrawable { if (mMaskColorFilter == null) { mMaskColorFilter = new PorterDuffColorFilter(0, PorterDuff.Mode.SRC_IN); + mFocusColorFilter = new PorterDuffColorFilter(0, PorterDuff.Mode.SRC_IN); } // Draw the appropriate mask anchored to (0,0). @@ -1219,6 +1221,8 @@ public class RippleDrawable extends LayerDrawable { int maskColor = mState.mRippleStyle == STYLE_PATTERNED ? color : color | 0xFF000000; if (mMaskColorFilter.getColor() != maskColor) { mMaskColorFilter = new PorterDuffColorFilter(maskColor, mMaskColorFilter.getMode()); + mFocusColorFilter = new PorterDuffColorFilter(color | 0xFF000000, + mFocusColorFilter.getMode()); } p.setColor(color & 0xFF000000); p.setColorFilter(mMaskColorFilter); diff --git a/graphics/java/android/graphics/fonts/Font.java b/graphics/java/android/graphics/fonts/Font.java index 69cd8bdb3e70..cd7936d50dff 100644 --- a/graphics/java/android/graphics/fonts/Font.java +++ b/graphics/java/android/graphics/fonts/Font.java @@ -46,7 +46,10 @@ import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.channels.FileChannel; import java.util.Arrays; +import java.util.Collections; +import java.util.IdentityHashMap; import java.util.Objects; +import java.util.Set; /** * A font class can be used for creating FontFamily. @@ -859,6 +862,18 @@ public final class Font { + "}"; } + /** @hide */ + public static Set<Font> getAvailableFonts() { + // The font uniqueness is already calculated in the native code. So use IdentityHashMap + // for avoiding hash/equals calculation. + IdentityHashMap<Font, Font> map = new IdentityHashMap<>(); + for (long nativePtr : nGetAvailableFontSet()) { + Font font = new Font(nativePtr); + map.put(font, font); + } + return Collections.unmodifiableSet(map.keySet()); + } + @CriticalNative private static native long nGetMinikinFontPtr(long font); @@ -900,4 +915,7 @@ public final class Font { @CriticalNative private static native long nGetAxisInfo(long fontPtr, int i); + + @FastNative + private static native long[] nGetAvailableFontSet(); } diff --git a/graphics/java/android/graphics/fonts/SystemFonts.java b/graphics/java/android/graphics/fonts/SystemFonts.java index 8d69d447f4e0..6278c0e23f27 100644 --- a/graphics/java/android/graphics/fonts/SystemFonts.java +++ b/graphics/java/android/graphics/fonts/SystemFonts.java @@ -22,7 +22,6 @@ import android.graphics.FontListParser; import android.graphics.Typeface; import android.text.FontConfig; import android.util.ArrayMap; -import android.util.ArraySet; import android.util.Log; import com.android.internal.annotations.GuardedBy; @@ -39,7 +38,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.Set; /** @@ -61,36 +59,6 @@ public final class SystemFonts { private static @GuardedBy("sLock") Set<Font> sAvailableFonts; /** - * Helper wrapper class for skipping buffer equality check of Font#equals. - * - * Due to historical reasons, the Font#equals checks the byte-by-byte buffer equality which - * requires heavy IO work in getAvailableFonts. Since the fonts came from system are all regular - * file backed font instance and stored in the unique place, just comparing file path should be - * good enough for this case. - */ - private static final class SystemFontHashWrapper { - private final Font mFont; - SystemFontHashWrapper(Font font) { - mFont = font; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - // All system fonts are regular-file backed font instance, so no need to - // compare buffers. - return mFont.paramEquals(((SystemFontHashWrapper) o).mFont); - } - - @Override - public int hashCode() { - return Objects.hash(mFont); - } - } - - /** * Returns all available font files in the system. * * @return a set of system fonts @@ -98,25 +66,7 @@ public final class SystemFonts { public static @NonNull Set<Font> getAvailableFonts() { synchronized (LOCK) { if (sAvailableFonts == null) { - Set<SystemFontHashWrapper> set = new ArraySet<>(); - for (Typeface tf : Typeface.getSystemFontMap().values()) { - List<FontFamily> families = tf.getFallback(); - for (int i = 0; i < families.size(); ++i) { - FontFamily family = families.get(i); - for (int j = 0; j < family.getSize(); ++j) { - set.add(new SystemFontHashWrapper(family.getFont(j))); - } - } - } - - // Unwrapping font instance for Set<Font> interface. The ArraySet#add won't call - // Font#equals function if none of two objects has the same hash, so following - // unwrapping won't cause bad performance due to byte-by-byte equality check. - ArraySet<Font> result = new ArraySet(set.size()); - for (SystemFontHashWrapper wrapper : set) { - result.add(wrapper.mFont); - } - sAvailableFonts = Collections.unmodifiableSet(result); + sAvailableFonts = Font.getAvailableFonts(); } return sAvailableFonts; } |