Convert some SkRuntimeEffect::Make to use stage-specific factories
The old factory is deprecated. The new ones do stricter checking on the
signature of main and calls to sample, and include checks at effect
creation-time that the SkSL is valid for the requested stage.
Bug: skia:11813
Change-Id: Ibd15a6f90e74bdc9c2352d3dc61b6682f626f413
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/397477
Reviewed-by: Florin Malita <fmalita@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/bench/ColorFilterBench.cpp b/bench/ColorFilterBench.cpp
index 0dd6cb4..59701a9 100644
--- a/bench/ColorFilterBench.cpp
+++ b/bench/ColorFilterBench.cpp
@@ -203,12 +203,12 @@
#if SK_SUPPORT_GPU
DEF_BENCH( return new ColorFilterBench("src_runtime", []() {
static sk_sp<SkRuntimeEffect> gEffect =
- SkRuntimeEffect::Make(SkString(RuntimeNone_GPU_SRC)).effect;
+ SkRuntimeEffect::MakeForColorFilter(SkString(RuntimeNone_GPU_SRC)).effect;
return gEffect->makeColorFilter(SkData::MakeEmpty());
});)
DEF_BENCH( return new ColorFilterBench("matrix_runtime", []() {
static sk_sp<SkRuntimeEffect> gEffect =
- SkRuntimeEffect::Make(SkString(RuntimeColorMatrix_GPU_SRC)).effect;
+ SkRuntimeEffect::MakeForColorFilter(SkString(RuntimeColorMatrix_GPU_SRC)).effect;
return gEffect->makeColorFilter(SkData::MakeWithCopy(gColorMatrix, sizeof(gColorMatrix)));
});)
#endif
diff --git a/gm/lumafilter.cpp b/gm/lumafilter.cpp
index 1b3166b..779dd89 100644
--- a/gm/lumafilter.cpp
+++ b/gm/lumafilter.cpp
@@ -185,7 +185,7 @@
canvas->translate(128,0);
// Splatting the Y channel of XYZ on the right should result in (near) greyscale.
- auto [effect, err] = SkRuntimeEffect::Make(SkString{
+ auto [effect, err] = SkRuntimeEffect::MakeForColorFilter(SkString{
"half4 main(half4 inColor) { return inColor.yyya; }"});
SkASSERT(effect && err.isEmpty());
diff --git a/gm/runtimecolorfilter.cpp b/gm/runtimecolorfilter.cpp
index d544c02..d55319d 100644
--- a/gm/runtimecolorfilter.cpp
+++ b/gm/runtimecolorfilter.cpp
@@ -32,12 +32,6 @@
}
)";
-const char* gLumaSrcWithCoords = R"(
- half4 main(float2 p, half4 color) {
- return dot(color.rgb, half3(0.3, 0.6, 0.1)).000r;
- }
-)";
-
// Build up the same effect with increasingly complex control flow syntax.
// All of these are semantically equivalent and can be reduced in principle to one basic block.
@@ -92,7 +86,7 @@
sk_sp<SkImage> img = GetResourceAsImage("images/mandrill_256.png");
auto draw_filter = [&](const char* src) {
- auto [effect, err] = SkRuntimeEffect::Make(SkString(src));
+ auto [effect, err] = SkRuntimeEffect::MakeForColorFilter(SkString(src));
if (!effect) {
SkDebugf("%s\n%s\n", src, err.c_str());
}
@@ -103,10 +97,10 @@
canvas->translate(256, 0);
};
- for (const char* src : { gNoop, gLumaSrc, gLumaSrcWithCoords}) {
+ for (const char* src : { gNoop, gLumaSrc }) {
draw_filter(src);
}
- canvas->translate(-256*3, 256);
+ canvas->translate(-256*2, 256);
for (const char* src : { gTernary, gIfs, gEarlyReturn}) {
draw_filter(src);
}
diff --git a/gm/runtimeeffectimage.cpp b/gm/runtimeeffectimage.cpp
index b9cb610..c24f77a 100644
--- a/gm/runtimeeffectimage.cpp
+++ b/gm/runtimeeffectimage.cpp
@@ -42,7 +42,7 @@
return result;
}
)");
- auto [effect, error] = SkRuntimeEffect::Make(sksl);
+ auto [effect, error] = SkRuntimeEffect::MakeForShader(sksl);
if (!effect) {
SkDebugf("RuntimeShader error: %s\n", error.c_str());
}
diff --git a/gm/runtimefunctions.cpp b/gm/runtimefunctions.cpp
index d472602..8158864 100644
--- a/gm/runtimefunctions.cpp
+++ b/gm/runtimefunctions.cpp
@@ -40,7 +40,7 @@
void onDraw(SkCanvas* canvas) override {
sk_sp<SkRuntimeEffect> gEffect =
- SkRuntimeEffect::Make(SkString(RUNTIME_FUNCTIONS_SRC)).effect;
+ SkRuntimeEffect::MakeForShader(SkString(RUNTIME_FUNCTIONS_SRC)).effect;
SkASSERT(gEffect);
SkMatrix localM;
diff --git a/gm/runtimeintrinsics.cpp b/gm/runtimeintrinsics.cpp
index a6729c9..5a51c61 100644
--- a/gm/runtimeintrinsics.cpp
+++ b/gm/runtimeintrinsics.cpp
@@ -114,7 +114,7 @@
draw_label(canvas, label ? label : fn);
- auto [effect, error] = SkRuntimeEffect::Make(make_unary_sksl_1d(fn));
+ auto [effect, error] = SkRuntimeEffect::MakeForShader(make_unary_sksl_1d(fn));
if (!effect) {
SkDebugf("Error: %s\n", error.c_str());
return;
@@ -339,7 +339,7 @@
draw_label(canvas, label);
- auto [effect, error] = SkRuntimeEffect::Make(make_matrix_comp_mult_sksl(N));
+ auto [effect, error] = SkRuntimeEffect::MakeForShader(make_matrix_comp_mult_sksl(N));
if (!effect) {
SkDebugf("Error: %s\n", error.c_str());
return;
@@ -376,7 +376,7 @@
draw_label(canvas, label);
- auto [effect, error] = SkRuntimeEffect::Make(make_matrix_inverse_sksl(N));
+ auto [effect, error] = SkRuntimeEffect::MakeForShader(make_matrix_inverse_sksl(N));
if (!effect) {
SkDebugf("Error: %s\n", error.c_str());
return;
@@ -465,7 +465,7 @@
draw_label(canvas, label);
const char* type = std::is_integral<T>::value ? "int" : "float";
- auto [effect, error] = SkRuntimeEffect::Make(make_bvec_sksl(type, fn));
+ auto [effect, error] = SkRuntimeEffect::MakeForShader(make_bvec_sksl(type, fn));
if (!effect) {
SkDebugf("Error: %s\n", error.c_str());
return;
diff --git a/gm/runtimeshader.cpp b/gm/runtimeshader.cpp
index 578f28a..663c349 100644
--- a/gm/runtimeshader.cpp
+++ b/gm/runtimeshader.cpp
@@ -30,7 +30,7 @@
: fName(name), fSize(size), fFlags(flags), fSkSL(sksl) {}
void onOnceBeforeDraw() override {
- auto [effect, error] = SkRuntimeEffect::Make(fSkSL);
+ auto [effect, error] = SkRuntimeEffect::MakeForShader(fSkSL);
if (!effect) {
SkDebugf("RuntimeShader error: %s\n", error.c_str());
}
@@ -300,12 +300,10 @@
class DefaultColorRT : public RuntimeShaderGM {
public:
- // This test also *explicitly* doesn't include coords in main's parameter list, to test that
- // runtime shaders work without them being declared (when they're not used).
DefaultColorRT() : RuntimeShaderGM("default_color_rt", {512, 256}, R"(
uniform shader input;
- half4 main() {
- return sample(input);
+ half4 main(float2 xy) {
+ return sample(input, xy);
}
)") {}
@@ -513,7 +511,7 @@
surf->getCanvas()->drawLine(0, 0, 100, 100, p);
auto shader = surf->makeImageSnapshot()->makeShader(SkSamplingOptions(SkFilterMode::kLinear));
- SkRuntimeShaderBuilder builder(SkRuntimeEffect::Make(SkString(scale)).effect);
+ SkRuntimeShaderBuilder builder(SkRuntimeEffect::MakeForShader(SkString(scale)).effect);
builder.child("child") = shader;
p.setShader(builder.makeShader(nullptr, false));
diff --git a/modules/skottie/src/effects/BlackAndWhiteEffect.cpp b/modules/skottie/src/effects/BlackAndWhiteEffect.cpp
index 4a5cedf..17163b6 100644
--- a/modules/skottie/src/effects/BlackAndWhiteEffect.cpp
+++ b/modules/skottie/src/effects/BlackAndWhiteEffect.cpp
@@ -61,7 +61,7 @@
)";
static const SkRuntimeEffect* effect =
- SkRuntimeEffect::Make(SkString(BLACK_AND_WHITE_EFFECT)).effect.release();
+ SkRuntimeEffect::MakeForColorFilter(SkString(BLACK_AND_WHITE_EFFECT)).effect.release();
SkASSERT(effect);
return sk_ref_sp(effect);
diff --git a/modules/skottie/src/effects/BrightnessContrastEffect.cpp b/modules/skottie/src/effects/BrightnessContrastEffect.cpp
index 64a8d51..5747849 100644
--- a/modules/skottie/src/effects/BrightnessContrastEffect.cpp
+++ b/modules/skottie/src/effects/BrightnessContrastEffect.cpp
@@ -134,8 +134,8 @@
const AnimationBuilder& abuilder,
sk_sp<sksg::RenderNode> layer)
: INHERITED(sksg::ExternalColorFilter::Make(std::move(layer)))
- , fBrightnessEffect(SkRuntimeEffect::Make(SkString(BRIGHTNESS_EFFECT)).effect)
- , fContrastEffect(SkRuntimeEffect::Make(SkString(CONTRAST_EFFECT)).effect) {
+ , fBrightnessEffect(SkRuntimeEffect::MakeForColorFilter(SkString(BRIGHTNESS_EFFECT)).effect)
+ , fContrastEffect(SkRuntimeEffect::MakeForColorFilter(SkString(CONTRAST_EFFECT)).effect) {
SkASSERT(fBrightnessEffect);
SkASSERT(fContrastEffect);
diff --git a/modules/skottie/src/effects/DisplacementMapEffect.cpp b/modules/skottie/src/effects/DisplacementMapEffect.cpp
index 8559224..613e24d 100644
--- a/modules/skottie/src/effects/DisplacementMapEffect.cpp
+++ b/modules/skottie/src/effects/DisplacementMapEffect.cpp
@@ -45,7 +45,7 @@
uniform half4 selector_offset;
half4 main(float2 xy) {
- half4 d = sample(displ);
+ half4 d = sample(displ, xy);
d = selector_matrix*unpremul(d) + selector_offset;
@@ -55,9 +55,9 @@
static sk_sp<SkRuntimeEffect> displacement_effect_singleton() {
static const SkRuntimeEffect* effect =
- SkRuntimeEffect::Make(SkString(gDisplacementSkSL)).effect.release();
+ SkRuntimeEffect::MakeForShader(SkString(gDisplacementSkSL)).effect.release();
if (0 && !effect) {
- auto err = SkRuntimeEffect::Make(SkString(gDisplacementSkSL)).errorText;
+ auto err = SkRuntimeEffect::MakeForShader(SkString(gDisplacementSkSL)).errorText;
printf("!!! %s\n", err.c_str());
}
SkASSERT(effect);
diff --git a/modules/skottie/src/effects/FractalNoiseEffect.cpp b/modules/skottie/src/effects/FractalNoiseEffect.cpp
index f7f7eaf..71b43cc 100644
--- a/modules/skottie/src/effects/FractalNoiseEffect.cpp
+++ b/modules/skottie/src/effects/FractalNoiseEffect.cpp
@@ -190,8 +190,8 @@
};
sk_sp<SkRuntimeEffect> make_noise_effect(unsigned loops, const char* filter, const char* fractal) {
- auto result =
- SkRuntimeEffect::Make(SkStringPrintf(gNoiseEffectSkSL, filter, fractal, loops), {});
+ auto result = SkRuntimeEffect::MakeForShader(
+ SkStringPrintf(gNoiseEffectSkSL, filter, fractal, loops), {});
if (0 && !result.effect) {
printf("!!! %s\n", result.errorText.c_str());
diff --git a/modules/skottie/src/effects/SphereEffect.cpp b/modules/skottie/src/effects/SphereEffect.cpp
index ea4a1bd..75a90f2 100644
--- a/modules/skottie/src/effects/SphereEffect.cpp
+++ b/modules/skottie/src/effects/SphereEffect.cpp
@@ -126,10 +126,12 @@
static sk_sp<SkRuntimeEffect> sphere_fancylight_effect() {
static const SkRuntimeEffect* effect =
- SkRuntimeEffect::Make(SkStringPrintf(gSphereSkSL, gFancyLightSkSL), {}).effect.release();
+ SkRuntimeEffect::MakeForShader(SkStringPrintf(gSphereSkSL, gFancyLightSkSL), {})
+ .effect.release();
if (0 && !effect) {
- printf("!!! %s\n", SkRuntimeEffect::Make(SkStringPrintf(gSphereSkSL, gFancyLightSkSL),
- {}).errorText.c_str());
+ printf("!!! %s\n",
+ SkRuntimeEffect::MakeForShader(SkStringPrintf(gSphereSkSL, gFancyLightSkSL), {})
+ .errorText.c_str());
}
SkASSERT(effect);
@@ -138,7 +140,8 @@
static sk_sp<SkRuntimeEffect> sphere_basiclight_effect() {
static const SkRuntimeEffect* effect =
- SkRuntimeEffect::Make(SkStringPrintf(gSphereSkSL, gBasicLightSkSL), {}).effect.release();
+ SkRuntimeEffect::MakeForShader(SkStringPrintf(gSphereSkSL, gBasicLightSkSL), {})
+ .effect.release();
SkASSERT(effect);
return sk_ref_sp(effect);
diff --git a/modules/skottie/src/effects/ThresholdEffect.cpp b/modules/skottie/src/effects/ThresholdEffect.cpp
index 3405160..b41ee77 100644
--- a/modules/skottie/src/effects/ThresholdEffect.cpp
+++ b/modules/skottie/src/effects/ThresholdEffect.cpp
@@ -33,7 +33,7 @@
static sk_sp<SkRuntimeEffect> threshold_effect() {
static const SkRuntimeEffect* effect =
- SkRuntimeEffect::Make(SkString(gThresholdSkSL), {}).effect.release();
+ SkRuntimeEffect::MakeForColorFilter(SkString(gThresholdSkSL), {}).effect.release();
SkASSERT(effect);
return sk_ref_sp(effect);
diff --git a/samplecode/Sample3D.cpp b/samplecode/Sample3D.cpp
index 062bfbf..17e3166 100644
--- a/samplecode/Sample3D.cpp
+++ b/samplecode/Sample3D.cpp
@@ -402,7 +402,7 @@
return sample(color_map, p) * scale.xxx1;
}
)";
- auto [effect, error] = SkRuntimeEffect::Make(SkString(code));
+ auto [effect, error] = SkRuntimeEffect::MakeForShader(SkString(code));
if (!effect) {
SkDebugf("runtime error %s\n", error.c_str());
}