summaryrefslogtreecommitdiff
path: root/graphics/java
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/java')
-rw-r--r--graphics/java/android/graphics/Typeface.java36
-rw-r--r--graphics/java/android/graphics/drawable/RippleDrawable.java15
-rw-r--r--graphics/java/android/graphics/drawable/RippleShader.java57
-rw-r--r--graphics/java/android/graphics/fonts/FontFileUtil.java17
4 files changed, 55 insertions, 70 deletions
diff --git a/graphics/java/android/graphics/Typeface.java b/graphics/java/android/graphics/Typeface.java
index c80788269c24..2a6bbf36ef76 100644
--- a/graphics/java/android/graphics/Typeface.java
+++ b/graphics/java/android/graphics/Typeface.java
@@ -25,6 +25,7 @@ import android.annotation.IntDef;
import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.annotation.TestApi;
import android.annotation.UiThread;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.res.AssetManager;
@@ -169,6 +170,21 @@ public class Typeface {
Collections.emptyMap();
/**
+ * Returns the shared memory that used for creating Typefaces.
+ *
+ * @return A SharedMemory used for creating Typeface. Maybe null if the lazy initialization is
+ * disabled or inside SystemServer or Zygote.
+ * @hide
+ */
+ @TestApi
+ public static @Nullable SharedMemory getSystemFontMapSharedMemory() {
+ if (ENABLE_LAZY_TYPEFACE_INITIALIZATION) {
+ Objects.requireNonNull(sSystemFontMapSharedMemory);
+ }
+ return sSystemFontMapSharedMemory;
+ }
+
+ /**
* @hide
*/
@UnsupportedAppUsage
@@ -1196,8 +1212,13 @@ public class Typeface {
}
}
- /** @hide */
- public static SharedMemory serializeFontMap(Map<String, Typeface> fontMap)
+ /**
+ * Create a serialized system font mappings.
+ *
+ * @hide
+ */
+ @TestApi
+ public static @NonNull SharedMemory serializeFontMap(@NonNull Map<String, Typeface> fontMap)
throws IOException, ErrnoException {
long[] nativePtrs = new long[fontMap.size()];
// The name table will not be large, so let's create a byte array in memory.
@@ -1229,9 +1250,14 @@ public class Typeface {
}
// buffer's byte order should be BIG_ENDIAN.
- /** @hide */
- @VisibleForTesting
- public static Map<String, Typeface> deserializeFontMap(ByteBuffer buffer) throws IOException {
+ /**
+ * Deserialize the font mapping from the serialized byte buffer.
+ *
+ * @hide
+ */
+ @TestApi
+ public static @NonNull Map<String, Typeface> deserializeFontMap(@NonNull ByteBuffer buffer)
+ throws IOException {
Map<String, Typeface> fontMap = new ArrayMap<>();
int typefacesBytesCount = buffer.getInt();
long[] nativePtrs = nativeReadTypefaces(buffer.slice());
diff --git a/graphics/java/android/graphics/drawable/RippleDrawable.java b/graphics/java/android/graphics/drawable/RippleDrawable.java
index 7fd3cdc39cc7..d6bbee90d73b 100644
--- a/graphics/java/android/graphics/drawable/RippleDrawable.java
+++ b/graphics/java/android/graphics/drawable/RippleDrawable.java
@@ -110,17 +110,6 @@ import java.util.Arrays;
* </pre>
*
* @attr ref android.R.styleable#RippleDrawable_color
- *
- * To change the ripple style, assign the value of "solid" or "patterned" to the android:rippleStyle
- * attribute.
- *
- * <pre>
- * <code>&lt;!-- A red ripple masked against an opaque rectangle. --/>
- * &lt;ripple android:rippleStyle="patterned">
- * &lt;/ripple></code>
- * </pre>
- *
- * @attr ref android.R.styleable#RippleDrawable_rippleStyle
*/
public class RippleDrawable extends LayerDrawable {
/**
@@ -132,12 +121,14 @@ public class RippleDrawable extends LayerDrawable {
/**
* Ripple style where a solid circle is drawn. This is also the default style
* @see #setRippleStyle(int)
+ * @hide
*/
public static final int STYLE_SOLID = 0;
/**
* Ripple style where a circle shape with a patterned,
* noisy interior expands from the hotspot to the bounds".
* @see #setRippleStyle(int)
+ * @hide
*/
public static final int STYLE_PATTERNED = 1;
@@ -1248,6 +1239,7 @@ public class RippleDrawable extends LayerDrawable {
* @see #STYLE_PATTERNED
*
* @param style The style of the ripple
+ * @hide
*/
public void setRippleStyle(@RippleStyle int style) throws IllegalArgumentException {
if (style == STYLE_SOLID || style == STYLE_PATTERNED) {
@@ -1260,6 +1252,7 @@ public class RippleDrawable extends LayerDrawable {
/**
* Get the current ripple style
* @return Ripple style
+ * @hide
*/
public @RippleStyle int getRippleStyle() {
return mState.mRippleStyle;
diff --git a/graphics/java/android/graphics/drawable/RippleShader.java b/graphics/java/android/graphics/drawable/RippleShader.java
index 25492779e6e9..657a32c1ac46 100644
--- a/graphics/java/android/graphics/drawable/RippleShader.java
+++ b/graphics/java/android/graphics/drawable/RippleShader.java
@@ -61,53 +61,6 @@ final class RippleShader extends RuntimeShader {
+ " return 1. - smoothstep(1. - blurHalf, 1. + blurHalf, d / radius);\n"
+ "}\n"
+ "\n"
- + "float softRing(vec2 uv, vec2 xy, float radius, float blur) {\n"
- + " float thickness = 0.4;\n"
- + " float circle_outer = softCircle(uv, xy, radius + thickness * 0.5, blur);\n"
- + " float circle_inner = softCircle(uv, xy, radius - thickness * 0.5, blur);\n"
- + " return circle_outer - circle_inner;\n"
- + "}\n"
- + "\n"
- + "struct Viewport {\n"
- + " float aspect;\n"
- + " vec2 uv;\n"
- + " vec2 resolution_pixels;\n"
- + "};\n"
- + "\n"
- + "Viewport getViewport(vec2 frag_coord, vec2 resolution_pixels) {\n"
- + " Viewport v;\n"
- + " v.aspect = resolution_pixels.y / resolution_pixels.x;\n"
- + " v.uv = frag_coord / resolution_pixels;\n"
- + " v.uv.y = (1.0 - v.uv.y) * v.aspect;\n"
- + " v.resolution_pixels = resolution_pixels;\n"
- + " return v;\n"
- + "}\n"
- + "\n"
- + "vec2 getTouch(vec2 touch_position_pixels, Viewport viewport) {\n"
- + " vec2 touch = touch_position_pixels / viewport.resolution_pixels;\n"
- + " touch.y *= viewport.aspect;\n"
- + " return touch;\n"
- + "}\n"
- + "\n"
- + "struct Wave {\n"
- + " float ring;\n"
- + " float circle;\n"
- + "};\n"
- + "\n"
- + "Wave getWave(Viewport viewport, vec2 touch, float progress) {\n"
- + " float fade = pow((clamp(progress, 0.8, 1.0)), 8.);\n"
- + " Wave w;\n"
- + " w.ring = max(softRing(viewport.uv, touch, progress, 0.45) - fade, 0.);\n"
- + " w.circle = softCircle(viewport.uv, touch, 2.0 * progress, 0.2) - progress;\n"
- + " return w;\n"
- + "}\n"
- + "\n"
- + "vec4 getRipple(vec4 color, float loudness, float sparkle, Wave wave) {\n"
- + " float alpha = wave.ring * sparkle * loudness\n"
- + " + wave.circle * color.a;\n"
- + " return vec4(color.rgb, saturate(alpha));\n"
- + "}\n"
- + "\n"
+ "float getRingMask(vec2 frag, vec2 center, float r, float progress) {\n"
+ " float dist = distance(frag, center);\n"
+ " float expansion = r * .6;\n"
@@ -126,19 +79,15 @@ final class RippleShader extends RuntimeShader {
+ " float fadeIn = subProgress(0., 0.175, in_progress);\n"
+ " float fadeOutNoise = subProgress(0.375, 1., in_progress);\n"
+ " float fadeOutRipple = subProgress(0.375, 0.75, in_progress);\n"
- + " Viewport vp = getViewport(p, in_resolution);\n"
- + " vec2 touch = getTouch(in_origin, vp);\n"
- + " Wave w = getWave(vp, touch, in_progress * 0.25);\n"
+ " float ring = getRingMask(p, in_origin, in_maxRadius, fadeIn);\n"
+ " float alpha = min(fadeIn, 1. - fadeOutNoise);\n"
+ " float sparkle = sparkles(p, in_progress * 0.25 + in_secondsOffset)\n"
+ " * ring * alpha;\n"
- + " vec4 r = getRipple(in_color, 1., sparkle, w);\n"
+ " float fade = min(fadeIn, 1.-fadeOutRipple);\n"
- + " vec4 circle = vec4(in_color.rgb, softCircle(p, in_origin, in_maxRadius "
- + " * fadeIn, 0.2) * fade * in_color.a);\n"
+ + " vec4 circle = in_color * (softCircle(p, in_origin, in_maxRadius "
+ + " * fadeIn, 0.2) * fade);\n"
+ " float mask = in_hasMask == 1. ? sample(in_shader).a > 0. ? 1. : 0. : 1.;\n"
- + " return mix(circle, vec4(1.), sparkle * mask);\n"
+ + " return mix(circle, vec4(sparkle), sparkle) * mask;\n"
+ "}";
private static final String SHADER = SHADER_UNIFORMS + SHADER_LIB + SHADER_MAIN;
diff --git a/graphics/java/android/graphics/fonts/FontFileUtil.java b/graphics/java/android/graphics/fonts/FontFileUtil.java
index af49619fb840..917eef2ffede 100644
--- a/graphics/java/android/graphics/fonts/FontFileUtil.java
+++ b/graphics/java/android/graphics/fonts/FontFileUtil.java
@@ -183,6 +183,23 @@ public class FontFileUtil {
return nIsPostScriptType1Font(buffer, index);
}
+ /**
+ * Analyze the file content and returns 1 if the font file is an OpenType collection file, 0 if
+ * the font file is a OpenType font file, -1 otherwise.
+ */
+ public static int isCollectionFont(@NonNull ByteBuffer buffer) {
+ ByteBuffer copied = buffer.slice();
+ copied.order(ByteOrder.BIG_ENDIAN);
+ int magicNumber = copied.getInt(0);
+ if (magicNumber == TTC_TAG) {
+ return 1;
+ } else if (magicNumber == SFNT_VERSION_1 || magicNumber == SFNT_VERSION_OTTO) {
+ return 0;
+ } else {
+ return -1;
+ }
+ }
+
@FastNative
private static native long nGetFontRevision(@NonNull ByteBuffer buffer,
@IntRange(from = 0) int index);