Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7c60f921 authored by Derek Sollenberger's avatar Derek Sollenberger Committed by Android (Google) Code Review
Browse files

Merge "Add RuntimeShader API to RenderEffect"

parents 765e7acb 56c07983
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -16525,6 +16525,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 createRuntimeShaderEffect(@NonNull android.graphics.RuntimeShader, @NonNull String);
    method @NonNull public static android.graphics.RenderEffect createShaderEffect(@NonNull android.graphics.Shader);
  }
+18 −0
Original line number Diff line number Diff line
@@ -290,6 +290,22 @@ public final class RenderEffect {
        return new RenderEffect(nativeCreateShaderEffect(shader.getNativeInstance()));
    }

    /**
     * Create a {@link RenderEffect} that executes the provided {@link RuntimeShader} and passes
     * the contents of the {@link android.graphics.RenderNode} that this RenderEffect is installed
     * on as an input to the shader.
     * @param shader the runtime shader that will bind the inputShaderName to the RenderEffect input
     * @param uniformShaderName the uniform name defined in the RuntimeShader's program to which
     *                         the contents of the RenderNode will be bound
     */
    @NonNull
    public static RenderEffect createRuntimeShaderEffect(
            @NonNull RuntimeShader shader, @NonNull String uniformShaderName) {
        return new RenderEffect(
                nativeCreateRuntimeShaderEffect(shader.getNativeShaderBuilder(),
                        uniformShaderName));
    }

    private final long mNativeRenderEffect;

    /* only constructed from static factory methods */
@@ -318,5 +334,7 @@ public final class RenderEffect {
    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 nativeCreateRuntimeShaderEffect(
            long shaderBuilder, String inputShaderName);
    private static native long nativeGetFinalizer();
}
+36 −9
Original line number Diff line number Diff line
@@ -127,6 +127,32 @@ static jlong createShaderEffect(
    return reinterpret_cast<jlong>(shaderFilter.release());
}

static inline int ThrowIAEFmt(JNIEnv* env, const char* fmt, ...) {
    va_list args;
    va_start(args, fmt);
    int ret = jniThrowExceptionFmt(env, "java/lang/IllegalArgumentException", fmt, args);
    va_end(args);
    return ret;
}

static jlong createRuntimeShaderEffect(JNIEnv* env, jobject, jlong shaderBuilderHandle,
                                       jstring inputShaderName) {
    SkRuntimeShaderBuilder* builder =
            reinterpret_cast<SkRuntimeShaderBuilder*>(shaderBuilderHandle);
    ScopedUtfChars name(env, inputShaderName);

    if (builder->child(name.c_str()).fChild == nullptr) {
        ThrowIAEFmt(env,
                    "unable to find a uniform with the name '%s' of the correct "
                    "type defined by the provided RuntimeShader",
                    name.c_str());
        return 0;
    }

    sk_sp<SkImageFilter> filter = SkImageFilters::RuntimeShader(*builder, name.c_str(), nullptr);
    return reinterpret_cast<jlong>(filter.release());
}

static void RenderEffect_safeUnref(SkImageFilter* filter) {
    SkSafeUnref(filter);
}
@@ -143,8 +169,9 @@ static const JNINativeMethod gRenderEffectMethods[] = {
        {"nativeCreateColorFilterEffect", "(JJ)J", (void*)createColorFilterEffect},
        {"nativeCreateBlendModeEffect", "(JJI)J", (void*)createBlendModeEffect},
        {"nativeCreateChainEffect", "(JJ)J", (void*)createChainEffect},
    {"nativeCreateShaderEffect", "(J)J", (void*)createShaderEffect}
};
        {"nativeCreateShaderEffect", "(J)J", (void*)createShaderEffect},
        {"nativeCreateRuntimeShaderEffect", "(JLjava/lang/String;)J",
         (void*)createRuntimeShaderEffect}};

int register_android_graphics_RenderEffect(JNIEnv* env) {
    android::RegisterMethodsOrDie(env, "android/graphics/RenderEffect",
+4 −0
Original line number Diff line number Diff line
@@ -32,6 +32,10 @@ android_test {
        "**/*.java",
        "**/*.kt",
    ],
    static_libs: [
        "androidx.cardview_cardview",
    ],

    platform_apis: true,
    certificate: "platform",
}
+9 −0
Original line number Diff line number Diff line
@@ -789,6 +789,15 @@
            </intent-filter>
        </activity>

        <activity android:name="RenderEffectViewActivity"
                  android:label="RenderEffect/View"
                  android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="com.android.test.hwui.TEST"/>
            </intent-filter>
        </activity>

        <activity android:name="StretchShaderActivity"
                  android:label="RenderEffect/Stretch"
                  android:exported="true">
Loading