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

Commit 18682dc6 authored by Jorge Betancourt's avatar Jorge Betancourt
Browse files

fix incorrect casting for child color filters

Flag: com.android.graphics.hwui.flags.runtime_color_filters_blenders

Test: atest
CtsUiRenderingTestCases:RuntimeShaderTests
CtsUiRenderingTestCases:RuntimeColorFilterTests
CtsUiRenderingTestCases:RuntimeXfermodeTests

Bug: b/358126864 b/379193391

Change-Id: Ic0a92c18075e1fd9f07080c2b9a7a795e541cdee
parent 7bc0eb3b
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -280,7 +280,8 @@ public class RuntimeColorFilter extends ColorFilter {
        if (colorFilter == null) {
            throw new NullPointerException("The colorFilter parameter must not be null");
        }
        nativeUpdateChild(getNativeInstance(), filterName, colorFilter.getNativeInstance());
        nativeUpdateInputColorFilter(getNativeInstance(), filterName,
                colorFilter.getNativeInstance());
    }

    /**
@@ -318,5 +319,6 @@ public class RuntimeColorFilter extends ColorFilter {
            long colorFilter, String uniformName, int value1, int value2, int value3,
            int value4, int count);
    private static native void nativeUpdateChild(long colorFilter, String childName, long child);

    private static native void nativeUpdateInputColorFilter(long colorFilter, String childName,
            long inputFilter);
}
+10 −1
Original line number Diff line number Diff line
@@ -264,6 +264,9 @@ public class RuntimeShader extends Shader {
     * enable better heap tracking & tooling support
     */
    private ArrayMap<String, Shader> mShaderUniforms = new ArrayMap<>();
    private ArrayMap<String, ColorFilter> mColorFilterUniforms = new ArrayMap<>();
    private ArrayMap<String, RuntimeXfermode> mXfermodeUniforms = new ArrayMap<>();


    /**
     * Creates a new RuntimeShader.
@@ -544,8 +547,10 @@ public class RuntimeShader extends Shader {
        if (colorFilter == null) {
            throw new NullPointerException("The colorFilter parameter must not be null");
        }
        nativeUpdateChild(mNativeInstanceRuntimeShaderBuilder, filterName,
        mColorFilterUniforms.put(filterName, colorFilter);
        nativeUpdateColorFilter(mNativeInstanceRuntimeShaderBuilder, filterName,
                colorFilter.getNativeInstance());
        discardNativeInstance();
    }

    /**
@@ -563,8 +568,10 @@ public class RuntimeShader extends Shader {
        if (xfermode == null) {
            throw new NullPointerException("The xfermode parameter must not be null");
        }
        mXfermodeUniforms.put(xfermodeName, xfermode);
        nativeUpdateChild(mNativeInstanceRuntimeShaderBuilder, xfermodeName,
                xfermode.createNativeInstance());
        discardNativeInstance();
    }


@@ -594,6 +601,8 @@ public class RuntimeShader extends Shader {
            int value4, int count);
    private static native void nativeUpdateShader(
            long shaderBuilder, String shaderName, long shader);
    private static native void nativeUpdateColorFilter(
            long shaderBuilder, String colorFilterName, long colorFilter);
    private static native void nativeUpdateChild(
            long shaderBuilder, String childName, long child);
}
+3 −1
Original line number Diff line number Diff line
@@ -285,7 +285,8 @@ public class RuntimeXfermode extends Xfermode {
        if (colorFilter == null) {
            throw new NullPointerException("The colorFilter parameter must not be null");
        }
        nativeUpdateChild(mBuilderNativeInstance, filterName, colorFilter.getNativeInstance());
        nativeUpdateColorFilter(mBuilderNativeInstance, filterName,
                colorFilter.getNativeInstance());
    }

    /**
@@ -325,5 +326,6 @@ public class RuntimeXfermode extends Xfermode {
            long builder, String uniformName, int value1, int value2, int value3,
            int value4, int count);
    private static native void nativeUpdateChild(long builder, String childName, long child);
    private static native void nativeUpdateColorFilter(long builder, String childName, long filter);

}
+17 −1
Original line number Diff line number Diff line
@@ -163,6 +163,20 @@ public:
            filter->updateChild(env, name.c_str(), child);
        }
    }

    static void RuntimeColorFilter_updateInputColorFilter(JNIEnv* env, jobject,
                                                          jlong colorFilterPtr, jstring childName,
                                                          jlong childFilterPtr) {
        auto* filter = reinterpret_cast<RuntimeColorFilter*>(colorFilterPtr);
        ScopedUtfChars name(env, childName);
        auto* child = reinterpret_cast<ColorFilter*>(childFilterPtr);
        if (filter && child) {
            auto childInput = child->getInstance();
            if (childInput) {
                filter->updateChild(env, name.c_str(), childInput.release());
            }
        }
    }
};

static const JNINativeMethod colorfilter_methods[] = {
@@ -193,7 +207,9 @@ static const JNINativeMethod runtime_color_filter_methods[] = {
        {"nativeUpdateUniforms", "(JLjava/lang/String;IIIII)V",
         (void*)ColorFilterGlue::RuntimeColorFilter_updateUniformsInts},
        {"nativeUpdateChild", "(JLjava/lang/String;J)V",
         (void*)ColorFilterGlue::RuntimeColorFilter_updateChild}};
         (void*)ColorFilterGlue::RuntimeColorFilter_updateChild},
        {"nativeUpdateInputColorFilter", "(JLjava/lang/String;J)V",
         (void*)ColorFilterGlue::RuntimeColorFilter_updateInputColorFilter}};

int register_android_graphics_ColorFilter(JNIEnv* env) {
    android::RegisterMethodsOrDie(env, "android/graphics/ColorFilter", colorfilter_methods,
+16 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@
 * limitations under the License.
 */

#include "ColorFilter.h"
#include "GraphicsJNI.h"
#include "RuntimeEffectUtils.h"
#include "SkBlender.h"
@@ -93,6 +94,19 @@ static void RuntimeXfermode_updateChild(JNIEnv* env, jobject, jlong builderPtr,
    }
}

static void RuntimeXfermode_updateColorFilter(JNIEnv* env, jobject, jlong builderPtr,
                                              jstring childName, jlong colorFilterPtr) {
    auto* builder = reinterpret_cast<SkRuntimeEffectBuilder*>(builderPtr);
    ScopedUtfChars name(env, childName);
    auto* child = reinterpret_cast<ColorFilter*>(colorFilterPtr);
    if (child) {
        auto childInput = child->getInstance();
        if (childInput) {
            UpdateChild(env, builder, name.c_str(), childInput.release());
        }
    }
}

static const JNINativeMethod gRuntimeXfermodeMethods[] = {
        {"nativeGetFinalizer", "()J", (void*)RuntimeXfermode_getNativeFinalizer},
        {"nativeCreateBlenderBuilder", "(Ljava/lang/String;)J",
@@ -107,6 +121,8 @@ static const JNINativeMethod gRuntimeXfermodeMethods[] = {
        {"nativeUpdateUniforms", "(JLjava/lang/String;IIIII)V",
         (void*)RuntimeXfermode_updateIntUniforms},
        {"nativeUpdateChild", "(JLjava/lang/String;J)V", (void*)RuntimeXfermode_updateChild},
        {"nativeUpdateColorFilter", "(JLjava/lang/String;J)V",
         (void*)RuntimeXfermode_updateColorFilter},
};

int register_android_graphics_RuntimeXfermode(JNIEnv* env) {
Loading