diff options
author | 2024-11-14 19:52:27 +0000 | |
---|---|---|
committer | 2024-11-15 04:09:37 +0000 | |
commit | 9a3d35e96bc8964e30cdd493fbe471226087b15a (patch) | |
tree | 0bce4ba7baf0875a581f45751d47969e17fc658d | |
parent | d0e4ee2fc64240bfeb8c4f1024ae3fe0e18fd976 (diff) |
add child setters to RuntimeEffects
Flag: com.android.graphics.hwui.flags.runtime_color_filters_blenders
Test: atest CtsUiRenderingTestCases:RuntimeShaderTests
Bug: b/358126864
API-Coverage-Bug: 379193391
Change-Id: I0e89e3880af12813935acd6ced817abff3f61084
-rw-r--r-- | core/api/current.txt | 4 | ||||
-rw-r--r-- | graphics/java/android/graphics/RuntimeColorFilter.java | 17 | ||||
-rw-r--r-- | graphics/java/android/graphics/RuntimeShader.java | 44 | ||||
-rw-r--r-- | graphics/java/android/graphics/RuntimeXfermode.java | 17 | ||||
-rw-r--r-- | libs/hwui/jni/RuntimeEffectUtils.cpp | 2 | ||||
-rw-r--r-- | libs/hwui/jni/Shader.cpp | 69 |
6 files changed, 94 insertions, 59 deletions
diff --git a/core/api/current.txt b/core/api/current.txt index 2056056a1e62..72dee1af4ece 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -17471,6 +17471,7 @@ package android.graphics { method public void setFloatUniform(@NonNull String, @NonNull float[]); method public void setInputColorFilter(@NonNull String, @NonNull android.graphics.ColorFilter); method public void setInputShader(@NonNull String, @NonNull android.graphics.Shader); + method public void setInputXfermode(@NonNull String, @NonNull android.graphics.RuntimeXfermode); method public void setIntUniform(@NonNull String, int); method public void setIntUniform(@NonNull String, int, int); method public void setIntUniform(@NonNull String, int, int, int); @@ -17489,7 +17490,9 @@ package android.graphics { method public void setFloatUniform(@NonNull String, float, float, float, float); method public void setFloatUniform(@NonNull String, @NonNull float[]); method public void setInputBuffer(@NonNull String, @NonNull android.graphics.BitmapShader); + method @FlaggedApi("com.android.graphics.hwui.flags.runtime_color_filters_blenders") public void setInputColorFilter(@NonNull String, @NonNull android.graphics.ColorFilter); method public void setInputShader(@NonNull String, @NonNull android.graphics.Shader); + method @FlaggedApi("com.android.graphics.hwui.flags.runtime_color_filters_blenders") public void setInputXfermode(@NonNull String, @NonNull android.graphics.RuntimeXfermode); method public void setIntUniform(@NonNull String, int); method public void setIntUniform(@NonNull String, int, int); method public void setIntUniform(@NonNull String, int, int, int); @@ -17509,6 +17512,7 @@ package android.graphics { method public void setFloatUniform(@NonNull String, @NonNull float[]); method public void setInputColorFilter(@NonNull String, @NonNull android.graphics.ColorFilter); method public void setInputShader(@NonNull String, @NonNull android.graphics.Shader); + method public void setInputXfermode(@NonNull String, @NonNull android.graphics.RuntimeXfermode); method public void setIntUniform(@NonNull String, int); method public void setIntUniform(@NonNull String, int, int); method public void setIntUniform(@NonNull String, int, int, int); diff --git a/graphics/java/android/graphics/RuntimeColorFilter.java b/graphics/java/android/graphics/RuntimeColorFilter.java index 52724ceaf301..d112f7153fca 100644 --- a/graphics/java/android/graphics/RuntimeColorFilter.java +++ b/graphics/java/android/graphics/RuntimeColorFilter.java @@ -283,6 +283,23 @@ public class RuntimeColorFilter extends ColorFilter { nativeUpdateChild(getNativeInstance(), filterName, colorFilter.getNativeInstance()); } + /** + * Assigns the uniform xfermode to the provided xfermode parameter. If the shader program does + * not have a uniform xfermode with that name then an IllegalArgumentException is thrown. + * + * @param xfermodeName name matching the uniform declared in the AGSL program + * @param xfermode filter passed into the AGSL program for sampling + */ + public void setInputXfermode(@NonNull String xfermodeName, @NonNull RuntimeXfermode xfermode) { + if (xfermodeName == null) { + throw new NullPointerException("The xfermodeName parameter must not be null"); + } + if (xfermode == null) { + throw new NullPointerException("The xfermode parameter must not be null"); + } + nativeUpdateChild(getNativeInstance(), xfermodeName, xfermode.createNativeInstance()); + } + /** @hide */ @Override protected long createNativeInstance() { diff --git a/graphics/java/android/graphics/RuntimeShader.java b/graphics/java/android/graphics/RuntimeShader.java index 78d257f86613..6316c1fb8b47 100644 --- a/graphics/java/android/graphics/RuntimeShader.java +++ b/graphics/java/android/graphics/RuntimeShader.java @@ -18,10 +18,13 @@ package android.graphics; import android.annotation.ColorInt; import android.annotation.ColorLong; +import android.annotation.FlaggedApi; import android.annotation.NonNull; import android.util.ArrayMap; import android.view.Window; +import com.android.graphics.hwui.flags.Flags; + import libcore.util.NativeAllocationRegistry; /** @@ -525,6 +528,45 @@ public class RuntimeShader extends Shader { discardNativeInstance(); } + /** + * Assigns the uniform color filter to the provided color filter parameter. If the shader + * program does not have a uniform color filter with that name then an IllegalArgumentException + * is thrown. + * + * @param filterName name matching the uniform declared in the AGSL program + * @param colorFilter filter passed into the AGSL program for sampling + */ + @FlaggedApi(Flags.FLAG_RUNTIME_COLOR_FILTERS_BLENDERS) + public void setInputColorFilter(@NonNull String filterName, @NonNull ColorFilter colorFilter) { + if (filterName == null) { + throw new NullPointerException("The filterName parameter must not be null"); + } + if (colorFilter == null) { + throw new NullPointerException("The colorFilter parameter must not be null"); + } + nativeUpdateChild(mNativeInstanceRuntimeShaderBuilder, filterName, + colorFilter.getNativeInstance()); + } + + /** + * Assigns the uniform xfermode to the provided xfermode parameter. If the shader program does + * not have a uniform xfermode with that name then an IllegalArgumentException is thrown. + * + * @param xfermodeName name matching the uniform declared in the AGSL program + * @param xfermode filter passed into the AGSL program for sampling + */ + @FlaggedApi(Flags.FLAG_RUNTIME_COLOR_FILTERS_BLENDERS) + public void setInputXfermode(@NonNull String xfermodeName, @NonNull RuntimeXfermode xfermode) { + if (xfermodeName == null) { + throw new NullPointerException("The xfermodeName parameter must not be null"); + } + if (xfermode == null) { + throw new NullPointerException("The xfermode parameter must not be null"); + } + nativeUpdateChild(mNativeInstanceRuntimeShaderBuilder, xfermodeName, + xfermode.createNativeInstance()); + } + /** @hide */ @Override @@ -552,5 +594,7 @@ public class RuntimeShader extends Shader { int value4, int count); private static native void nativeUpdateShader( long shaderBuilder, String shaderName, long shader); + private static native void nativeUpdateChild( + long shaderBuilder, String childName, long child); } diff --git a/graphics/java/android/graphics/RuntimeXfermode.java b/graphics/java/android/graphics/RuntimeXfermode.java index f5a656862bf9..51d97a4b7487 100644 --- a/graphics/java/android/graphics/RuntimeXfermode.java +++ b/graphics/java/android/graphics/RuntimeXfermode.java @@ -288,6 +288,23 @@ public class RuntimeXfermode extends Xfermode { nativeUpdateChild(mBuilderNativeInstance, filterName, colorFilter.getNativeInstance()); } + /** + * Assigns the uniform xfermode to the provided xfermode parameter. If the shader program does + * not have a uniform xfermode with that name then an IllegalArgumentException is thrown. + * + * @param xfermodeName name matching the uniform declared in the AGSL program + * @param xfermode xfermode function passed into the AGSL program for sampling + */ + public void setInputXfermode(@NonNull String xfermodeName, @NonNull RuntimeXfermode xfermode) { + if (xfermodeName == null) { + throw new NullPointerException("The xfermodeName parameter must not be null"); + } + if (xfermode == null) { + throw new NullPointerException("The xfermode parameter must not be null"); + } + nativeUpdateChild(mBuilderNativeInstance, xfermodeName, xfermode.createNativeInstance()); + } + /** @hide */ public long createNativeInstance() { return nativeCreateNativeInstance(mBuilderNativeInstance); diff --git a/libs/hwui/jni/RuntimeEffectUtils.cpp b/libs/hwui/jni/RuntimeEffectUtils.cpp index 46db8633c66e..ad0e540b5b40 100644 --- a/libs/hwui/jni/RuntimeEffectUtils.cpp +++ b/libs/hwui/jni/RuntimeEffectUtils.cpp @@ -90,7 +90,7 @@ void UpdateChild(JNIEnv* env, SkRuntimeEffectBuilder* builder, const char* child SkFlattenable* childEffect) { SkRuntimeShaderBuilder::BuilderChild builderChild = builder->child(childName); if (builderChild.fChild == nullptr) { - ThrowIAEFmt(env, "unable to find shader named %s", childName); + ThrowIAEFmt(env, "unable to find child named %s", childName); return; } diff --git a/libs/hwui/jni/Shader.cpp b/libs/hwui/jni/Shader.cpp index 2a057e7a4cdc..018c2b1374d0 100644 --- a/libs/hwui/jni/Shader.cpp +++ b/libs/hwui/jni/Shader.cpp @@ -2,6 +2,7 @@ #include "Gainmap.h" #include "GraphicsJNI.h" +#include "RuntimeEffectUtils.h" #include "SkBitmap.h" #include "SkBlendMode.h" #include "SkColor.h" @@ -280,50 +281,6 @@ static inline int ThrowIAEFmt(JNIEnv* env, const char* fmt, ...) { return ret; } -static bool isIntUniformType(const SkRuntimeEffect::Uniform::Type& type) { - switch (type) { - case SkRuntimeEffect::Uniform::Type::kFloat: - case SkRuntimeEffect::Uniform::Type::kFloat2: - case SkRuntimeEffect::Uniform::Type::kFloat3: - case SkRuntimeEffect::Uniform::Type::kFloat4: - case SkRuntimeEffect::Uniform::Type::kFloat2x2: - case SkRuntimeEffect::Uniform::Type::kFloat3x3: - case SkRuntimeEffect::Uniform::Type::kFloat4x4: - return false; - case SkRuntimeEffect::Uniform::Type::kInt: - case SkRuntimeEffect::Uniform::Type::kInt2: - case SkRuntimeEffect::Uniform::Type::kInt3: - case SkRuntimeEffect::Uniform::Type::kInt4: - return true; - } -} - -static void UpdateFloatUniforms(JNIEnv* env, SkRuntimeShaderBuilder* builder, - const char* uniformName, const float values[], int count, - bool isColor) { - SkRuntimeShaderBuilder::BuilderUniform uniform = builder->uniform(uniformName); - if (uniform.fVar == nullptr) { - ThrowIAEFmt(env, "unable to find uniform named %s", uniformName); - } else if (isColor != ((uniform.fVar->flags & SkRuntimeEffect::Uniform::kColor_Flag) != 0)) { - if (isColor) { - jniThrowExceptionFmt( - env, "java/lang/IllegalArgumentException", - "attempting to set a color uniform using the non-color specific APIs: %s %x", - uniformName, uniform.fVar->flags); - } else { - ThrowIAEFmt(env, - "attempting to set a non-color uniform using the setColorUniform APIs: %s", - uniformName); - } - } else if (isIntUniformType(uniform.fVar->type)) { - ThrowIAEFmt(env, "attempting to set a int uniform using the setUniform APIs: %s", - uniformName); - } else if (!uniform.set<float>(values, count)) { - ThrowIAEFmt(env, "mismatch in byte size for uniform [expected: %zu actual: %zu]", - uniform.fVar->sizeInBytes(), sizeof(float) * count); - } -} - static void RuntimeShader_updateFloatUniforms(JNIEnv* env, jobject, jlong shaderBuilder, jstring jUniformName, jfloat value1, jfloat value2, jfloat value3, jfloat value4, jint count) { @@ -342,20 +299,6 @@ static void RuntimeShader_updateFloatArrayUniforms(JNIEnv* env, jobject, jlong s UpdateFloatUniforms(env, builder, name.c_str(), autoValues.ptr(), autoValues.length(), isColor); } -static void UpdateIntUniforms(JNIEnv* env, SkRuntimeShaderBuilder* builder, const char* uniformName, - const int values[], int count) { - SkRuntimeShaderBuilder::BuilderUniform uniform = builder->uniform(uniformName); - if (uniform.fVar == nullptr) { - ThrowIAEFmt(env, "unable to find uniform named %s", uniformName); - } else if (!isIntUniformType(uniform.fVar->type)) { - ThrowIAEFmt(env, "attempting to set a non-int uniform using the setIntUniform APIs: %s", - uniformName); - } else if (!uniform.set<int>(values, count)) { - ThrowIAEFmt(env, "mismatch in byte size for uniform [expected: %zu actual: %zu]", - uniform.fVar->sizeInBytes(), sizeof(float) * count); - } -} - static void RuntimeShader_updateIntUniforms(JNIEnv* env, jobject, jlong shaderBuilder, jstring jUniformName, jint value1, jint value2, jint value3, jint value4, jint count) { @@ -388,6 +331,15 @@ static void RuntimeShader_updateShader(JNIEnv* env, jobject, jlong shaderBuilder builder->child(name.c_str()) = sk_ref_sp(shader); } +static void RuntimeShader_updateChild(JNIEnv* env, jobject, jlong shaderBuilder, + jstring jUniformName, jlong childHandle) { + SkRuntimeShaderBuilder* builder = reinterpret_cast<SkRuntimeShaderBuilder*>(shaderBuilder); + ScopedUtfChars name(env, jUniformName); + auto* childEffect = reinterpret_cast<SkFlattenable*>(childHandle); + + UpdateChild(env, builder, name.c_str(), childEffect); +} + /////////////////////////////////////////////////////////////////////////////////////////////// static const JNINativeMethod gShaderMethods[] = { @@ -428,6 +380,7 @@ static const JNINativeMethod gRuntimeShaderMethods[] = { {"nativeUpdateUniforms", "(JLjava/lang/String;IIIII)V", (void*)RuntimeShader_updateIntUniforms}, {"nativeUpdateShader", "(JLjava/lang/String;J)V", (void*)RuntimeShader_updateShader}, + {"nativeUpdateChild", "(JLjava/lang/String;J)V", (void*)RuntimeShader_updateChild}, }; int register_android_graphics_Shader(JNIEnv* env) |