Re-land sksl fragment processor support

This reverts commit ed50200682e0de72c3abecaa4d5324ebcd1ed9f9.

Bug: skia:
Change-Id: I9caa7454b391450620d6989dc472abb3cf7a2cab
Reviewed-on: https://skia-review.googlesource.com/20965
Reviewed-by: Ben Wagner <benjaminwagner@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
diff --git a/BUILD.gn b/BUILD.gn
index bb5122a..6ead044 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -139,6 +139,7 @@
     "src/utils/win",
     "src/xml",
     "third_party/gif",
+    "$target_gen_dir",
   ]
 
   defines = [ "SK_GAMMA_APPLY_TO_A8" ]
@@ -345,6 +346,9 @@
 
 optional("effects") {
   enabled = skia_enable_effects
+  deps = [
+    ":compile_processors",
+  ]
   sources =
       skia_effects_sources + [ "src/ports/SkGlobalInitialization_default.cpp" ]
   sources_when_disabled = [ "src/ports/SkGlobalInitialization_none.cpp" ]
@@ -410,12 +414,68 @@
   ]
 }
 
+if (skia_enable_gpu && skia_gpu_processor_sources != []) {
+  executable("skslc") {
+    defines = [ "SKSL_STANDALONE" ]
+    sources = [
+      "src/sksl/SkSLMain.cpp",
+    ]
+    sources += skia_sksl_sources
+    include_dirs = [
+      "src/gpu",
+      "src/sksl",
+    ]
+    deps = [
+      "//third_party/spirv-tools",
+    ]
+  }
+
+  skia_gpu_processor_outputs = []
+  foreach(src, skia_gpu_processor_sources) {
+    name = get_path_info(src, "name")
+    skia_gpu_processor_outputs += [
+      "$target_gen_dir/effects/$name.h",
+      "$target_gen_dir/effects/$name.cpp",
+    ]
+  }
+
+  action("compile_processors") {
+    script = "gn/compile_processors.py"
+    deps = [
+      ":skslc(//gn/toolchain:$host_toolchain)",
+    ]
+    sources = skia_gpu_processor_sources
+    outputs = skia_gpu_processor_outputs
+    skslc_path = "$root_out_dir/"
+    if (host_toolchain != default_toolchain_name) {
+      skslc_path += "$host_toolchain/"
+    }
+    skslc_path += "skslc"
+    if (host_os == "win") {
+      skslc_path = ".exe"
+    }
+    args = [
+      rebase_path(skslc_path),
+      rebase_path("$target_gen_dir/effects"),
+    ]
+    args += rebase_path(skia_gpu_processor_sources)
+  }
+} else {
+  skia_gpu_processor_outputs = []
+  group("compile_processors") {
+  }
+}
+
 optional("gpu") {
   enabled = skia_enable_gpu
+  deps = [
+    ":compile_processors",
+  ]
   public_defines = []
 
   sources = skia_gpu_sources + skia_sksl_sources +
-            [ "src/gpu/gl/GrGLDefaultInterface_native.cpp" ]
+            [ "src/gpu/gl/GrGLDefaultInterface_native.cpp" ] +
+            skia_gpu_processor_outputs
 
   # These paths need to be absolute to match the ones produced by shared_sources.gni.
   sources -= get_path_info([
@@ -454,9 +514,7 @@
     }
   }
   if (skia_enable_spirv_validation) {
-    deps = [
-      "//third_party/spirv-tools",
-    ]
+    deps += [ "//third_party/spirv-tools" ]
     public_defines += [ "SK_ENABLE_SPIRV_VALIDATION" ]
   }
 }
@@ -1525,15 +1583,4 @@
       ]
     }
   }
-
-  if (skia_enable_gpu) {
-    test_app("skslc") {
-      defines = [ "SKSL_STANDALONE" ]
-      sources = [
-        "src/sksl/SkSLMain.cpp",
-      ]
-      sources += skia_sksl_sources
-      include_dirs = [ "src/sksl" ]
-    }
-  }
 }