Expose sk_FragCoord for runtime effects

This is needed for the inline dither effect to use device coordinates
instead of local coords for dithering.

The builtin is not "in float4" because that trips up the runtime effect
assertions about what types of in variables are allowed.

Change-Id: I580fc461fdc9cbd812592b2571f51868a7a3ea4b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/292262
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
diff --git a/src/sksl/sksl_pipeline.inc b/src/sksl/sksl_pipeline.inc
index 99e4e30..2f31951 100644
--- a/src/sksl/sksl_pipeline.inc
+++ b/src/sksl/sksl_pipeline.inc
@@ -1,4 +1,5 @@
 STRINGIFY(
+    layout(builtin=15) float4 sk_FragCoord;
     half4 sample(fragmentProcessor fp, float2 coords);
     half4 sample(fragmentProcessor fp, float3x3 transform);
 )
diff --git a/tests/SkRuntimeEffectTest.cpp b/tests/SkRuntimeEffectTest.cpp
index 66dacd3..082a98a 100644
--- a/tests/SkRuntimeEffectTest.cpp
+++ b/tests/SkRuntimeEffectTest.cpp
@@ -150,6 +150,14 @@
     TestEffect inlineColor(r, "in half c;", "color = half4(c, c, c, 1);");
     inlineColor["c"] = 0.498f;
     inlineColor.test(r, surface, 0xFF7F7F7F);
+
+    // Test sk_FragCoord, which we output to color. Since the surface is 2x2, we should see
+    // (0,0), (1,0), (0,1), (1,1), multiply by 0.498 to make sure we're not saturating unexpectedly.
+    // TODO: Remove this when sk_FragCoord is supported by interpreter.
+    if (context) {
+        TestEffect fragCoord(r, "", "color = half4(0.498 * (half2(sk_FragCoord.xy) - 0.5), 0, 1);");
+        fragCoord.test(r, surface, 0xFF000000, 0xFF00007F, 0xFF007F00, 0xFF007F7F);
+    }
 }
 
 DEF_TEST(SkRuntimeEffectSimple, r) {