Convert internal SkSL to use .eval()
Also update RELEASE_NOTES to describe new syntax.
Change-Id: I2666551b98f80b61ae3a48c92a9e306cdc7242b0
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/444735
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
diff --git a/src/core/SkBlurMF.cpp b/src/core/SkBlurMF.cpp
index 5bdbc38..f516697 100644
--- a/src/core/SkBlurMF.cpp
+++ b/src/core/SkBlurMF.cpp
@@ -850,7 +850,7 @@
// to rearrange to avoid passing large values to length() that would overflow.
half2 vec = half2((sk_FragCoord.xy - circleData.xy) * circleData.w);
half dist = length(vec) + (0.5 - circleData.z) * circleData.w;
- return inColor * shade(blurProfile, half2(dist, 0.5)).a;
+ return inColor * blurProfile.eval(half2(dist, 0.5)).a;
}
)");
@@ -994,8 +994,8 @@
// computations align the left edge of the integral texture with the inset rect's
// edge extending outward 6 * sigma from the inset rect.
half2 xy = max(half2(rect.LT - pos), half2(pos - rect.RB));
- xCoverage = shade(integral, half2(xy.x, 0.5)).a;
- yCoverage = shade(integral, half2(xy.y, 0.5)).a;
+ xCoverage = integral.eval(half2(xy.x, 0.5)).a;
+ yCoverage = integral.eval(half2(xy.y, 0.5)).a;
} else {
// We just consider just the x direction here. In practice we compute x and y
// separately and multiply them together.
@@ -1013,10 +1013,10 @@
// Also, our rect uniform was pre-inset by 3 sigma from the actual rect being
// blurred, also factored in.
half4 rect = half4(half2(rect.LT - pos), half2(pos - rect.RB));
- xCoverage = 1 - shade(integral, half2(rect.L, 0.5)).a
- - shade(integral, half2(rect.R, 0.5)).a;
- yCoverage = 1 - shade(integral, half2(rect.T, 0.5)).a
- - shade(integral, half2(rect.B, 0.5)).a;
+ xCoverage = 1 - integral.eval(half2(rect.L, 0.5)).a
+ - integral.eval(half2(rect.R, 0.5)).a;
+ yCoverage = 1 - integral.eval(half2(rect.T, 0.5)).a
+ - integral.eval(half2(rect.B, 0.5)).a;
}
return inColor * xCoverage * yCoverage;
}
@@ -1426,7 +1426,7 @@
half2 proxyDims = half2(2.0 * edgeSize);
half2 texCoord = translatedFragPosHalf / proxyDims;
- return inColor * shade(ninePatchFP, texCoord).a;
+ return inColor * ninePatchFP.eval(texCoord).a;
}
)");
diff --git a/src/core/SkColorFilter.cpp b/src/core/SkColorFilter.cpp
index 3c6ac99..eb1c9c6 100644
--- a/src/core/SkColorFilter.cpp
+++ b/src/core/SkColorFilter.cpp
@@ -477,7 +477,7 @@
"uniform colorFilter cf1;"
"uniform half weight;"
"half4 main(half4 color) {"
- "return mix(filter(cf0, color), filter(cf1, color), weight);"
+ "return mix(cf0.eval(color), cf1.eval(color), weight);"
"}"
);
SkASSERT(effect);
diff --git a/src/core/SkRuntimeEffectPriv.h b/src/core/SkRuntimeEffectPriv.h
index 80337a3..cec8cae 100644
--- a/src/core/SkRuntimeEffectPriv.h
+++ b/src/core/SkRuntimeEffectPriv.h
@@ -119,10 +119,10 @@
private:
struct SampleCall {
enum class Kind {
- kInputColor, // eg filter(child, inputColor)
- kImmediate, // eg filter(child, half4(1))
- kPrevious, // eg filter(child1, filter(child2, ...))
- kUniform, // eg uniform half4 color; ... filter(child, color)
+ kInputColor, // eg child.eval(inputColor)
+ kImmediate, // eg child.eval(half4(1))
+ kPrevious, // eg child1.eval(child2.eval(...))
+ kUniform, // eg uniform half4 color; ... child.eval(color)
};
int fChild;
diff --git a/src/effects/imagefilters/SkAlphaThresholdImageFilter.cpp b/src/effects/imagefilters/SkAlphaThresholdImageFilter.cpp
index 5c82b02..a7c7aa4 100644
--- a/src/effects/imagefilters/SkAlphaThresholdImageFilter.cpp
+++ b/src/effects/imagefilters/SkAlphaThresholdImageFilter.cpp
@@ -145,7 +145,7 @@
uniform half outerThreshold;
half4 main(float2 xy, half4 color) {
- half4 mask_color = shade(maskFP, xy);
+ half4 mask_color = maskFP.eval(xy);
if (mask_color.a < 0.5) {
if (color.a > outerThreshold) {
half scale = outerThreshold / color.a;
diff --git a/src/effects/imagefilters/SkArithmeticImageFilter.cpp b/src/effects/imagefilters/SkArithmeticImageFilter.cpp
index 9572d7e..3dcebc4 100644
--- a/src/effects/imagefilters/SkArithmeticImageFilter.cpp
+++ b/src/effects/imagefilters/SkArithmeticImageFilter.cpp
@@ -315,8 +315,8 @@
uniform half4 k;
uniform half pmClamp;
half4 main(float2 xy) {
- half4 src = shade(srcFP, xy);
- half4 dst = shade(dstFP, xy);
+ half4 src = srcFP.eval(xy);
+ half4 dst = dstFP.eval(xy);
half4 color = saturate(k.x * src * dst +
k.y * src +
k.z * dst +
diff --git a/src/effects/imagefilters/SkMagnifierImageFilter.cpp b/src/effects/imagefilters/SkMagnifierImageFilter.cpp
index 58dfbd6..136c012 100644
--- a/src/effects/imagefilters/SkMagnifierImageFilter.cpp
+++ b/src/effects/imagefilters/SkMagnifierImageFilter.cpp
@@ -126,7 +126,7 @@
weight = min(min(delta_squared.x, delta_squared.y), 1.0);
}
- return shade(src, mix(coord, zoom_coord, weight));
+ return src.eval(mix(coord, zoom_coord, weight));
}
)");
diff --git a/src/gpu/GrFragmentProcessor.cpp b/src/gpu/GrFragmentProcessor.cpp
index b7c8b4d..0d5f537 100644
--- a/src/gpu/GrFragmentProcessor.cpp
+++ b/src/gpu/GrFragmentProcessor.cpp
@@ -405,7 +405,7 @@
uniform colorFilter fp; // Declared as colorFilter so we can pass a color
uniform half4 color;
half4 main(half4 inColor) {
- return filter(fp, color);
+ return fp.eval(color);
}
)");
SkASSERT(SkRuntimeEffectPriv::SupportsConstantOutputForConstantInput(effect));
@@ -423,7 +423,7 @@
static auto effect = SkMakeRuntimeEffect(SkRuntimeEffect::MakeForBlender, R"(
uniform colorFilter fp; // Declared as colorFilter so we can pass a color
half4 main(half4 src, half4 dst) {
- return filter(fp, dst);
+ return fp.eval(dst);
}
)");
return GrSkSLFP::Make(effect, "UseDestColorAsInput", /*inputFP=*/nullptr,
@@ -440,7 +440,7 @@
static auto effect = SkMakeRuntimeEffect(SkRuntimeEffect::MakeForColorFilter, R"(
uniform colorFilter fp; // Declared as colorFilter so we can pass a color
half4 main(half4 inColor) {
- return inColor.a * filter(fp, unpremul(inColor).rgb1);
+ return inColor.a * fp.eval(unpremul(inColor).rgb1);
}
)");
return GrSkSLFP::Make(effect,
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index 1adb44e..9422c7e 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -394,7 +394,7 @@
uniform half range;
uniform shader table;
half4 main(float2 xy, half4 color) {
- half value = shade(table, sk_FragCoord.xy).a - 0.5; // undo the bias in the table
+ half value = table.eval(sk_FragCoord.xy).a - 0.5; // undo the bias in the table
// For each color channel, add the random offset to the channel value and then clamp
// between 0 and alpha to keep the color premultiplied.
return half4(clamp(color.rgb + value * range, 0.0, color.a), color.a);
diff --git a/src/gpu/gradients/GrGradientShader.cpp b/src/gpu/gradients/GrGradientShader.cpp
index 2d5b2cb..b3e2fc1 100644
--- a/src/gpu/gradients/GrGradientShader.cpp
+++ b/src/gpu/gradients/GrGradientShader.cpp
@@ -425,7 +425,7 @@
uniform int layoutPreservesOpacity; // specialized
half4 main(float2 coord) {
- half4 t = shade(gradLayout, coord);
+ half4 t = gradLayout.eval(coord);
half4 outColor;
// If t.x is below 0, use the left border color without invoking the child processor.
@@ -442,7 +442,7 @@
} else {
// Always sample from (x, 0), discarding y, since the layout FP can use y as a
// side-channel.
- outColor = shade(colorizer, t.x0);
+ outColor = colorizer.eval(t.x0);
}
if (bool(makePremul)) {
outColor.rgb *= outColor.a;
@@ -487,7 +487,7 @@
uniform int useFloorAbsWorkaround; // specialized
half4 main(float2 coord) {
- half4 t = shade(gradLayout, coord);
+ half4 t = gradLayout.eval(coord);
if (!bool(layoutPreservesOpacity) && t.y < 0) {
// layout has rejected this fragment (rely on sksl to remove this branch if the
@@ -511,7 +511,7 @@
// Always sample from (x, 0), discarding y, since the layout FP can use y as a
// side-channel.
- half4 outColor = shade(colorizer, t.x0);
+ half4 outColor = colorizer.eval(t.x0);
if (bool(makePremul)) {
outColor.rgb *= outColor.a;
}
diff --git a/src/sksl/SkSLAnalysis.h b/src/sksl/SkSLAnalysis.h
index ee19213..1772355 100644
--- a/src/sksl/SkSLAnalysis.h
+++ b/src/sksl/SkSLAnalysis.h
@@ -37,7 +37,7 @@
struct Analysis {
/**
* Determines how `program` samples `child`. By default, assumes that the sample coords
- * (SK_MAIN_COORDS_BUILTIN) might be modified, so `shade(fp, sampleCoords)` is treated as
+ * (SK_MAIN_COORDS_BUILTIN) might be modified, so `child.eval(sampleCoords)` is treated as
* Explicit. If writesToSampleCoords is false, treats that as PassThrough, instead.
* If elidedSampleCoordCount is provided, the pointed to value will be incremented by the
* number of sample calls where the above rewrite was performed.
diff --git a/src/sksl/SkSLMain.cpp b/src/sksl/SkSLMain.cpp
index f66b939..17102fa 100644
--- a/src/sksl/SkSLMain.cpp
+++ b/src/sksl/SkSLMain.cpp
@@ -409,15 +409,15 @@
}
String sampleShader(int index, String coords) override {
- return "shade(child_" + SkSL::to_string(index) + ", " + coords + ")";
+ return "child_" + SkSL::to_string(index) + ".eval(" + coords + ")";
}
String sampleColorFilter(int index, String color) override {
- return "filter(child_" + SkSL::to_string(index) + ", " + color + ")";
+ return "child_" + SkSL::to_string(index) + ".eval(" + color + ")";
}
String sampleBlender(int index, String src, String dst) override {
- return "blend(child_" + SkSL::to_string(index) + ", " + src + ", " +
+ return "child_" + SkSL::to_string(index) + ".eval(" + src + ", " +
dst + ")";
}
diff --git a/src/sksl/ir/SkSLChildCall.cpp b/src/sksl/ir/SkSLChildCall.cpp
index 90ab36e..e2da51c 100644
--- a/src/sksl/ir/SkSLChildCall.cpp
+++ b/src/sksl/ir/SkSLChildCall.cpp
@@ -29,17 +29,12 @@
}
String ChildCall::description() const {
- String result;
- switch (this->child().type().typeKind()) {
- case Type::TypeKind::kBlender: result += "blend("; break;
- case Type::TypeKind::kColorFilter: result += "filter("; break;
- case Type::TypeKind::kShader: result += "shade("; break;
- default: SkUNREACHABLE;
- }
- result += this->child().name();
+ String result = String(this->child().name()) + ".eval(";
+ String separator;
for (const std::unique_ptr<Expression>& arg : this->arguments()) {
- result += ", ";
+ result += separator;
result += arg->description();
+ separator = ", ";
}
result += ")";
return result;