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/tests/SkRuntimeEffectTest.cpp b/tests/SkRuntimeEffectTest.cpp
index 312c476..297254e 100644
--- a/tests/SkRuntimeEffectTest.cpp
+++ b/tests/SkRuntimeEffectTest.cpp
@@ -459,7 +459,7 @@
 
     // Sampling a null child should return the paint color
     effect.build("uniform shader child;"
-                 "half4 main(float2 p) { return sample(child, p); }");
+                 "half4 main(float2 p) { return shade(child, p); }");
     effect.child("child") = nullptr;
     effect.test(0xFF00FFFF,
                 [](SkCanvas*, SkPaint* paint) { paint->setColor4f({1.0f, 1.0f, 0.0f, 1.0f}); });
@@ -468,13 +468,13 @@
 
     // Sampling a simple child at our coordinates
     effect.build("uniform shader child;"
-                 "half4 main(float2 p) { return sample(child, p); }");
+                 "half4 main(float2 p) { return shade(child, p); }");
     effect.child("child") = rgbwShader;
     effect.test({0xFF0000FF, 0xFF00FF00, 0xFFFF0000, 0xFFFFFFFF});
 
     // Sampling with explicit coordinates (reflecting about the diagonal)
     effect.build("uniform shader child;"
-                 "half4 main(float2 p) { return sample(child, p.yx); }");
+                 "half4 main(float2 p) { return shade(child, p.yx); }");
     effect.child("child") = rgbwShader;
     effect.test({0xFF0000FF, 0xFFFF0000, 0xFF00FF00, 0xFFFFFFFF});
 
@@ -560,13 +560,13 @@
 
     // Sampling a null shader/color filter should return the paint color.
     effect.build("uniform shader child;"
-                 "half4 main(half4 s, half4 d) { return sample(child, s.rg); }");
+                 "half4 main(half4 s, half4 d) { return shade(child, s.rg); }");
     effect.child("child") = nullptr;
     effect.test(0xFF00FFFF,
                 [](SkCanvas*, SkPaint* paint) { paint->setColor4f({1.0f, 1.0f, 0.0f, 1.0f}); });
 
     effect.build("uniform colorFilter child;"
-                 "half4 main(half4 s, half4 d) { return sample(child, s); }");
+                 "half4 main(half4 s, half4 d) { return filter(child, s); }");
     effect.child("child") = nullptr;
     effect.test(0xFF00FFFF,
                 [](SkCanvas*, SkPaint* paint) { paint->setColor4f({1.0f, 1.0f, 0.0f, 1.0f}); });
@@ -574,7 +574,7 @@
     // Sampling a null blender should do a src-over blend. Draw 50% black over RGBW to verify this.
     surface->getCanvas()->drawPaint(rgbwPaint);
     effect.build("uniform blender child;"
-                 "half4 main(half4 s, half4 d) { return sample(child, s, d); }");
+                 "half4 main(half4 s, half4 d) { return blend(child, s, d); }");
     effect.child("child") = nullptr;
     effect.test({0xFF000080, 0xFF008000, 0xFF800000, 0xFF808080},
                 [](SkCanvas*, SkPaint* paint) { paint->setColor4f({0.0f, 0.0f, 0.0f, 0.497f}); });
@@ -582,7 +582,7 @@
     // Sampling a shader at various coordinates
     effect.build("uniform shader child;"
                  "uniform half2 pos;"
-                 "half4 main(half4 s, half4 d) { return sample(child, pos); }");
+                 "half4 main(half4 s, half4 d) { return shade(child, pos); }");
     effect.child("child") = make_RGBW_shader();
     effect.uniform("pos") = float2{0, 0};
     effect.test(0xFF0000FF);
@@ -598,14 +598,14 @@
 
     // Sampling a color filter
     effect.build("uniform colorFilter child;"
-                 "half4 main(half4 s, half4 d) { return sample(child, half4(1)); }");
+                 "half4 main(half4 s, half4 d) { return filter(child, half4(1)); }");
     effect.child("child") = SkColorFilters::Blend(0xFF012345, SkBlendMode::kSrc);
     effect.test(0xFF452301);
 
     // Sampling a built-in blender
     surface->getCanvas()->drawPaint(rgbwPaint);
     effect.build("uniform blender child;"
-                 "half4 main(half4 s, half4 d) { return sample(child, s, d); }");
+                 "half4 main(half4 s, half4 d) { return blend(child, s, d); }");
     effect.child("child") = SkBlender::Mode(SkBlendMode::kPlus);
     effect.test({0xFF4523FF, 0xFF45FF01, 0xFFFF2301, 0xFFFFFFFF},
                 [](SkCanvas*, SkPaint* paint) { paint->setColor(0xFF012345); });
@@ -613,7 +613,7 @@
     // Sampling a runtime-effect blender
     surface->getCanvas()->drawPaint(rgbwPaint);
     effect.build("uniform blender child;"
-                 "half4 main(half4 s, half4 d) { return sample(child, s, d); }");
+                 "half4 main(half4 s, half4 d) { return blend(child, s, d); }");
     effect.child("child") = SkBlenders::Arithmetic(0, 1, 1, 0, /*enforcePremul=*/false);
     effect.test({0xFF4523FF, 0xFF45FF01, 0xFFFF2301, 0xFFFFFFFF},
                 [](SkCanvas*, SkPaint* paint) { paint->setColor(0xFF012345); });
@@ -736,7 +736,7 @@
         "uniform shader paint;"
         "struct S { half4 rgba; };"
         "void process(inout S s) { s.rgba.rgb *= 0.5; }"
-        "half4 main(float2 p) { S s; s.rgba = sample(paint, p); process(s); return s.rgba; }"
+        "half4 main(float2 p) { S s; s.rgba = shade(paint, p); process(s); return s.rgba; }"
     ));
     REPORTER_ASSERT(r, childEffect, "%s\n", err.c_str());
     sk_sp<SkShader> nullChild = nullptr;
@@ -755,7 +755,7 @@
             "uniform shader child;"
             "struct S { float2 coord; };"
             "void process(inout S s) { s.coord = s.coord.yx; }"
-            "half4 main(float2 p) { S s; s.coord = p; process(s); return sample(child, s.coord); "
+            "half4 main(float2 p) { S s; s.coord = p; process(s); return shade(child, s.coord); "
             "}");
     effect.child("child") = child;
     effect.test(0xFF00407F, [](SkCanvas*, SkPaint* paint) {
@@ -815,31 +815,31 @@
 
     // Direct use of passed-in coords. Here, the only use of sample coords is for a sample call
     // converted to passthrough, so referenceSampleCoords is *false*, despite appearing in main.
-    test("half4 main(float2 xy) { return sample(child, xy); }", false, false);
+    test("half4 main(float2 xy) { return shade(child, xy); }", false, false);
     // Sample with passed-in coords, read (but don't write) sample coords elsewhere
-    test("half4 main(float2 xy) { return sample(child, xy) + sin(xy.x); }", false, true);
+    test("half4 main(float2 xy) { return shade(child, xy) + sin(xy.x); }", false, true);
 
     // Cases where our optimization is not valid, and does not happen:
 
     // Sampling with values completely unrelated to passed-in coords
-    test("half4 main(float2 xy) { return sample(child, float2(0, 0)); }", true, false);
+    test("half4 main(float2 xy) { return shade(child, float2(0, 0)); }", true, false);
     // Use of expression involving passed in coords
-    test("half4 main(float2 xy) { return sample(child, xy * 0.5); }", true, true);
+    test("half4 main(float2 xy) { return shade(child, xy * 0.5); }", true, true);
     // Use of coords after modification
-    test("half4 main(float2 xy) { xy *= 2; return sample(child, xy); }", true, true);
+    test("half4 main(float2 xy) { xy *= 2; return shade(child, xy); }", true, true);
     // Use of coords after modification via out-param call
     test("void adjust(inout float2 xy) { xy *= 2; }"
-         "half4 main(float2 xy) { adjust(xy); return sample(child, xy); }", true, true);
+         "half4 main(float2 xy) { adjust(xy); return shade(child, xy); }", true, true);
 
     // There should (must) not be any false-positive cases. There are false-negatives.
     // In all of these cases, our optimization would be valid, but does not happen:
 
     // Direct use of passed-in coords, modified after use
-    test("half4 main(float2 xy) { half4 c = sample(child, xy); xy *= 2; return c; }", true, true);
+    test("half4 main(float2 xy) { half4 c = shade(child, xy); xy *= 2; return c; }", true, true);
     // Passed-in coords copied to a temp variable
-    test("half4 main(float2 xy) { float2 p = xy; return sample(child, p); }", true, true);
+    test("half4 main(float2 xy) { float2 p = xy; return shade(child, p); }", true, true);
     // Use of coords passed to helper function
-    test("half4 helper(float2 xy) { return sample(child, xy); }"
+    test("half4 helper(float2 xy) { return shade(child, xy); }"
          "half4 main(float2 xy) { return helper(xy); }", true, true);
 }