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
This commit is contained in:
Brian Osman
2021-04-20 19:46:39 +00:00
parent 7e551439cd
commit 7556777511
6 changed files with 7 additions and 6 deletions

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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"

View File

@@ -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) {

View File

@@ -440,7 +440,7 @@ public class StretchShaderActivity extends Activity {
}
}
private static final String SKSL = "in shader uContentTexture;\n"
private static final String SKSL = "uniform shader uContentTexture;\n"
+ "uniform float uMaxStretchIntensity; // multiplier to apply to scale effect\n"
+ "uniform float uStretchAffectedDist; // Maximum percentage to stretch beyond bounds"
+ " of target\n"