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

Commit 75567775 authored by Brian Osman's avatar Brian Osman
Browse files

Update frameworks/base to use newer SkRuntimeEffect::MakeForShader

This enforces stricter rules on the SkSL at effect creation time, and
ensures it's valid as an SkShader (vs. an SkColorFilter). Also updated
some SkSL that was already (or would become) illegal:

- Child shaders must be declared 'uniform', not 'in'
- sampling a child requires coordinates

Bug: skia:11813
Change-Id: I743b985b5012723186a43e58e9e3ccf29d809d2b
parent 7e551439
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -115,7 +115,7 @@ final class RippleShader extends RuntimeShader {
            + "    float fade = min(fadeIn, 1. - fadeOutRipple);\n"
            + "    vec4 circle = in_color * (softCircle(p, center, in_maxRadius "
            + "      * scaleIn, 0.2) * fade);\n"
            + "    float mask = in_hasMask == 1. ? sample(in_shader).a > 0. ? 1. : 0. : 1.;\n"
            + "    float mask = in_hasMask == 1. ? sample(in_shader, p).a > 0. ? 1. : 0. : 1.;\n"
            + "    return mix(circle, in_sparkleColor, sparkle) * mask;\n"
            + "}";
    private static final String SHADER = SHADER_UNIFORMS + SHADER_LIB + SHADER_MAIN;
+1 −1
Original line number Diff line number Diff line
@@ -237,7 +237,7 @@ sk_sp<SkShader> StretchEffect::getShader(const sk_sp<SkImage>& snapshotImage) co
}

sk_sp<SkRuntimeEffect> StretchEffect::getStretchEffect() {
    const static SkRuntimeEffect::Result instance = SkRuntimeEffect::Make(stretchShader);
    const static SkRuntimeEffect::Result instance = SkRuntimeEffect::MakeForShader(stretchShader);
    return instance.effect;
}

+2 −1
Original line number Diff line number Diff line
@@ -239,7 +239,8 @@ static jlong ComposeShader_create(JNIEnv* env, jobject o, jlong matrixPtr,

static jlong RuntimeShader_createShaderBuilder(JNIEnv* env, jobject, jstring sksl) {
    ScopedUtfChars strSksl(env, sksl);
    auto result = SkRuntimeEffect::Make(SkString(strSksl.c_str()), SkRuntimeEffect::Options{});
    auto result = SkRuntimeEffect::MakeForShader(SkString(strSksl.c_str()),
                                                 SkRuntimeEffect::Options{});
    if (result.effect.get() == nullptr) {
        doThrowIAE(env, result.errorText.c_str());
        return 0;
+1 −1
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ public class ColorFiltersMutateActivity extends Activity {
        private float mShaderParam1 = 0.0f;

        static final String sSkSL =
                "in shader bitmapShader;\n"
                "uniform shader bitmapShader;\n"
                + "uniform float param1;\n"
                + "half4 main(float2 xy) {\n"
                + "  return half4(sample(bitmapShader, xy).rgb, param1);\n"
+1 −1
Original line number Diff line number Diff line
@@ -89,7 +89,7 @@ public class RippleActivity extends Activity {
                + "    d = rand(float2(x, y)) > density ? d : d * .2;\n"
                + "    d = d * rand(float2(fraction, x * y));\n"
                + "    float alpha = 1. - pow(fraction, 3.);\n"
                + "    return float4(sample(in_paintColor).rgb, d * alpha);\n"
                + "    return float4(sample(in_paintColor, p).rgb, d * alpha);\n"
                + "}";

        RippleView(Context c) {
Loading