Disallow runtime effect color filters that depend on position

Some of these checks are currently redundant (we don't allow color
filters to have children right now). But the next CL will re-add that
capability, and the unit tests here will ensure we don't re-break things
by allowing child-sampling to violate the color filter invariant.

Change-Id: I54c10d8b1d1e376c13347296765185d42b9f644a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/308285
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/tests/SkRuntimeEffectTest.cpp b/tests/SkRuntimeEffectTest.cpp
index 84e0f9a..0ebe63f 100644
--- a/tests/SkRuntimeEffectTest.cpp
+++ b/tests/SkRuntimeEffectTest.cpp
@@ -7,6 +7,7 @@
 
 #include "include/core/SkBitmap.h"
 #include "include/core/SkCanvas.h"
+#include "include/core/SkColorFilter.h"
 #include "include/core/SkPaint.h"
 #include "include/core/SkSurface.h"
 #include "include/effects/SkRuntimeEffect.h"
@@ -80,6 +81,20 @@
          "expression");
 }
 
+DEF_TEST(SkRuntimeEffectInvalidColorFilters, r) {
+    auto test = [r](const char* sksl) {
+        auto [effect, errorText] = SkRuntimeEffect::Make(SkString(sksl));
+        REPORTER_ASSERT(r, effect);
+        REPORTER_ASSERT(r, effect->makeShader(nullptr, nullptr, 0, nullptr, false));
+        REPORTER_ASSERT(r, !effect->makeColorFilter(nullptr));
+    };
+
+    // Runtime effects that use sample coords or sk_FragCoord are valid shaders,
+    // but not valid color filters
+    test("void main(float2 p, inout half4 color) { color.rg = half2(p); }");
+    test("void main(float2 p, inout half4 color) { color.rg = half2(sk_FragCoord.xy); }");
+}
+
 class TestEffect {
 public:
     TestEffect(skiatest::Reporter* r, sk_sp<SkSurface> surface)