diff --git a/core/api/current.txt b/core/api/current.txt index 1f6dcd0b57a78..28b7f9b79d490 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -15795,6 +15795,7 @@ package android.graphics { method @NonNull public static android.graphics.RenderEffect createColorFilterEffect(@NonNull android.graphics.ColorFilter); method @NonNull public static android.graphics.RenderEffect createOffsetEffect(float, float); method @NonNull public static android.graphics.RenderEffect createOffsetEffect(float, float, @NonNull android.graphics.RenderEffect); + method @NonNull public static android.graphics.RenderEffect createShaderEffect(@NonNull android.graphics.Shader); } public final class RenderNode { diff --git a/graphics/java/android/graphics/RenderEffect.java b/graphics/java/android/graphics/RenderEffect.java index 496e4707dbffb..ad4c3fe86175d 100644 --- a/graphics/java/android/graphics/RenderEffect.java +++ b/graphics/java/android/graphics/RenderEffect.java @@ -190,7 +190,7 @@ public final class RenderEffect { } /** - * Create a filter that applies the color filter to the provided RenderEffect + * Create a {@link RenderEffect} that applies the color filter to the provided RenderEffect * * @param colorFilter ColorFilter applied to the content in the input RenderEffect * @param renderEffect Source to be transformed by the specified {@link ColorFilter} @@ -209,7 +209,7 @@ public final class RenderEffect { } /** - * Create a filter that applies the color filter to the contents of the + * Create a {@link RenderEffect} that applies the color filter to the contents of the * {@link android.graphics.RenderNode} that this RenderEffect is installed on * @param colorFilter ColorFilter applied to the content in the input RenderEffect */ @@ -224,7 +224,7 @@ public final class RenderEffect { } /** - * {@link RenderEffect} that is a composition of 2 other {@link RenderEffect} instances + * Create a {@link RenderEffect} that is a composition of 2 other {@link RenderEffect} instances * combined by the specified {@link BlendMode} * * @param dst The Dst pixels used in blending @@ -248,8 +248,8 @@ public final class RenderEffect { } /** - * Create a filter that composes 'inner' with 'outer', such that the results of 'inner' are - * treated as the source bitmap passed to 'outer', i.e. + * Create a {@link RenderEffect} that composes 'inner' with 'outer', such that the results of + * 'inner' are treated as the source bitmap passed to 'outer', i.e. * *
      * {@code
@@ -278,6 +278,18 @@ public final class RenderEffect {
             );
     }
 
+    /**
+     * Create a {@link RenderEffect} that renders the contents of the input {@link Shader}.
+     * This is useful to create an input for other {@link RenderEffect} types such as
+     * {@link RenderEffect#createBlurEffect(float, float, RenderEffect, TileMode)}
+     * {@link RenderEffect#createBlurEffect(float, float, RenderEffect, TileMode)} or
+     * {@link RenderEffect#createColorFilterEffect(ColorFilter, RenderEffect)}.
+     */
+    @NonNull
+    public static RenderEffect createShaderEffect(@NonNull Shader shader) {
+        return new RenderEffect(nativeCreateShaderEffect(shader.getNativeInstance()));
+    }
+
     private final long mNativeRenderEffect;
 
     /* only constructed from static factory methods */
@@ -305,5 +317,6 @@ public final class RenderEffect {
     private static native long nativeCreateColorFilterEffect(long colorFilter, long nativeInput);
     private static native long nativeCreateBlendModeEffect(long dst, long src, int blendmode);
     private static native long nativeCreateChainEffect(long outer, long inner);
+    private static native long nativeCreateShaderEffect(long shader);
     private static native long nativeGetFinalizer();
 }
diff --git a/libs/hwui/jni/RenderEffect.cpp b/libs/hwui/jni/RenderEffect.cpp
index 97c40d695f978..fa1752cc47d6e 100644
--- a/libs/hwui/jni/RenderEffect.cpp
+++ b/libs/hwui/jni/RenderEffect.cpp
@@ -115,6 +115,18 @@ static jlong createChainEffect(
     return reinterpret_cast(composeFilter.release());
 }
 
+static jlong createShaderEffect(
+    JNIEnv* env,
+    jobject,
+    jlong shaderHandle
+) {
+    auto* shader = reinterpret_cast(shaderHandle);
+    sk_sp shaderFilter = SkImageFilters::Shader(
+          sk_ref_sp(shader), nullptr
+    );
+    return reinterpret_cast(shaderFilter.release());
+}
+
 static void RenderEffect_safeUnref(SkImageFilter* filter) {
     SkSafeUnref(filter);
 }
@@ -130,7 +142,8 @@ static const JNINativeMethod gRenderEffectMethods[] = {
     {"nativeCreateBitmapEffect", "(JFFFFFFFF)J", (void*)createBitmapEffect},
     {"nativeCreateColorFilterEffect", "(JJ)J", (void*)createColorFilterEffect},
     {"nativeCreateBlendModeEffect", "(JJI)J", (void*)createBlendModeEffect},
-    {"nativeCreateChainEffect", "(JJ)J", (void*)createChainEffect}
+    {"nativeCreateChainEffect", "(JJ)J", (void*)createChainEffect},
+    {"nativeCreateShaderEffect", "(J)J", (void*)createShaderEffect}
 };
 
 int register_android_graphics_RenderEffect(JNIEnv* env) {
diff --git a/tests/HwAccelerationTest/AndroidManifest.xml b/tests/HwAccelerationTest/AndroidManifest.xml
index 1a940c75cfa4e..c6c67feeed72d 100644
--- a/tests/HwAccelerationTest/AndroidManifest.xml
+++ b/tests/HwAccelerationTest/AndroidManifest.xml
@@ -753,6 +753,15 @@
             
         
 
+        
+            
+                
+                
+            
+        
+