SkSL: Disallow fragmentProcessor variables in several places

We only want SkSL to contain fp variables at global scope, and to sample
directly from references to those global variables. Anything else will
confuse our sample-usage analysis, and often leads to asserts in the CPP
or pipeline-stage generators.

Bug: skia:10514
Change-Id: Ie1ef10821c1b2a946a92d050fea45d95569bc934
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/304599
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 5271a20..84e0f9a 100644
--- a/tests/SkRuntimeEffectTest.cpp
+++ b/tests/SkRuntimeEffectTest.cpp
@@ -61,6 +61,23 @@
 
     // Shouldn't be possible to create an SkRuntimeEffect without "main"
     test("//", "", "main");
+
+    // Various places that shaders (fragmentProcessors) should not be allowed
+    test("",
+         "shader child;",
+         "must be global");
+    test("in shader child; half4 helper(shader fp) { return sample(fp); }",
+         "color = helper(child);",
+         "parameter");
+    test("in shader child; shader get_child() { return child; }",
+         "color = sample(get_child());",
+         "return");
+    test("in shader child;",
+         "color = sample(shader(child));",
+         "construct");
+    test("in shader child1; in shader child2;",
+         "color = sample(p.x > 10 ? child1 : child2);",
+         "expression");
 }
 
 class TestEffect {