Convert internal sample() calls to shade/filter/blend
Bug: skia:12302
Change-Id: I8cf958acf9214d0de903a4097647afd74f2a659e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/441541
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/src/gpu/GrFragmentProcessor.cpp b/src/gpu/GrFragmentProcessor.cpp
index 9b20bee..b7c8b4d 100644
--- a/src/gpu/GrFragmentProcessor.cpp
+++ b/src/gpu/GrFragmentProcessor.cpp
@@ -402,10 +402,10 @@
return nullptr;
}
static auto effect = SkMakeRuntimeEffect(SkRuntimeEffect::MakeForColorFilter, R"(
- uniform colorFilter fp; // Declared as colorFilter so we can use sample(..., color)
+ uniform colorFilter fp; // Declared as colorFilter so we can pass a color
uniform half4 color;
half4 main(half4 inColor) {
- return sample(fp, color);
+ return filter(fp, color);
}
)");
SkASSERT(SkRuntimeEffectPriv::SupportsConstantOutputForConstantInput(effect));
@@ -421,9 +421,9 @@
std::unique_ptr<GrFragmentProcessor> GrFragmentProcessor::UseDestColorAsInput(
std::unique_ptr<GrFragmentProcessor> fp) {
static auto effect = SkMakeRuntimeEffect(SkRuntimeEffect::MakeForBlender, R"(
- uniform colorFilter fp; // Declared as colorFilter so we can use sample(..., color)
+ uniform colorFilter fp; // Declared as colorFilter so we can pass a color
half4 main(half4 src, half4 dst) {
- return sample(fp, dst);
+ return filter(fp, dst);
}
)");
return GrSkSLFP::Make(effect, "UseDestColorAsInput", /*inputFP=*/nullptr,
@@ -438,9 +438,9 @@
return nullptr;
}
static auto effect = SkMakeRuntimeEffect(SkRuntimeEffect::MakeForColorFilter, R"(
- uniform colorFilter fp; // Declared as colorFilter so we can use sample(..., color)
+ uniform colorFilter fp; // Declared as colorFilter so we can pass a color
half4 main(half4 inColor) {
- return inColor.a * sample(fp, unpremul(inColor).rgb1);
+ return inColor.a * filter(fp, unpremul(inColor).rgb1);
}
)");
return GrSkSLFP::Make(effect,
diff --git a/src/gpu/GrFragmentProcessor.h b/src/gpu/GrFragmentProcessor.h
index 6118f38..89dbb83 100644
--- a/src/gpu/GrFragmentProcessor.h
+++ b/src/gpu/GrFragmentProcessor.h
@@ -611,10 +611,9 @@
* to the child's helper function). It is legal to pass nullptr as inputColor, since all
* fragment processors are required to work without an input color.
*
- * When skslCoords is empty, invokeChild corresponds to a call to "sample(child, color)"
- * in SkSL. When skslCoords is not empty, invokeChild corresponds to a call to
- * "sample(child, color, float2)", where skslCoords is an SkSL expression that evaluates to a
- * float2 and is passed in as the 3rd argument.
+ * When skslCoords is empty, the child is invoked at the sample coordinates from parentArgs.
+ * When skslCoords is not empty, is must be an SkSL expression that evaluates to a float2.
+ * That expression is passed to the child's processor function as the "_coords" argument.
*/
SkString invokeChild(int childIndex,
const char* inputColor,
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index e464adf..1adb44e 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 = sample(table, sk_FragCoord.xy).a - 0.5; // undo the bias in the table
+ half value = shade(table, 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 c506c73..2d5b2cb 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 = sample(gradLayout, coord);
+ half4 t = shade(gradLayout, 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 = sample(colorizer, t.x0);
+ outColor = shade(colorizer, t.x0);
}
if (bool(makePremul)) {
outColor.rgb *= outColor.a;
@@ -487,7 +487,7 @@
uniform int useFloorAbsWorkaround; // specialized
half4 main(float2 coord) {
- half4 t = sample(gradLayout, coord);
+ half4 t = shade(gradLayout, 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 = sample(colorizer, t.x0);
+ half4 outColor = shade(colorizer, t.x0);
if (bool(makePremul)) {
outColor.rgb *= outColor.a;
}