Move creation of GrProgramDesc to GrCaps-derived classes

We need a means of creating GrProgramDescs pre-flush w/o needing to know the specific backend in play.

Bug: skia:9455
Change-Id: Iac14ff8eda262ee6d2ad666c5d2e27e7a375c210
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/256698
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/src/gpu/GrProgramDesc.h b/src/gpu/GrProgramDesc.h
index 775db62..c0cfaa8 100644
--- a/src/gpu/GrProgramDesc.h
+++ b/src/gpu/GrProgramDesc.h
@@ -11,11 +11,10 @@
 #include "include/private/GrTypesPriv.h"
 #include "include/private/SkTArray.h"
 #include "include/private/SkTo.h"
-#include "src/core/SkOpts.h"
-#include "src/gpu/GrColor.h"
-#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
 
+class GrCaps;
 class GrProgramInfo;
+class GrRenderTarget;
 class GrShaderCaps;
 
 /** This class is used to generate a generic program cache key. The Dawn, Metal and Vulkan
@@ -23,29 +22,7 @@
  */
 class GrProgramDesc {
 public:
-    // Creates an uninitialized key that must be populated by Build
-    GrProgramDesc() {}
-
-    /**
-     * Builds a program descriptor.
-     *
-     * @param desc          The built descriptor
-     * @param renderTarget  The target of the draw
-     * @param programInfo   Program information need to build the key
-     * @param caps          the caps
-     **/
-    static bool Build(GrProgramDesc*, const GrRenderTarget*, const GrProgramInfo&, const GrCaps&);
-
-    // This is strictly an OpenGL call since the other backends have additional data in their
-    // keys
-    static bool BuildFromData(GrProgramDesc* desc, const void* keyData, size_t keyLength) {
-        if (!SkTFitsIn<int>(keyLength)) {
-            return false;
-        }
-        desc->fKey.reset(SkToInt(keyLength));
-        memcpy(desc->fKey.begin(), keyData, keyLength);
-        return true;
-    }
+    bool isValid() const { return !fKey.empty(); }
 
     // Returns this as a uint32_t array to be used as a key in the program cache.
     const uint32_t* asKey() const {
@@ -89,6 +66,38 @@
     uint32_t initialKeyLength() const { return this->header().fInitialKeyLength; }
 
 protected:
+    friend class GrDawnCaps;
+    friend class GrGLCaps;
+    friend class GrMockCaps;
+    friend class GrMtlCaps;
+    friend class GrVkCaps;
+
+    friend class GrGLGpu; // for ProgramCache to access BuildFromData
+
+    // Creates an uninitialized key that must be populated by Build
+    GrProgramDesc() {}
+
+    /**
+     * Builds a program descriptor.
+     *
+     * @param desc          The built descriptor
+     * @param renderTarget  The target of the draw
+     * @param programInfo   Program information need to build the key
+     * @param caps          the caps
+     **/
+    static bool Build(GrProgramDesc*, const GrRenderTarget*, const GrProgramInfo&, const GrCaps&);
+
+    // This is strictly an OpenGL call since the other backends have additional data in their
+    // keys
+    static bool BuildFromData(GrProgramDesc* desc, const void* keyData, size_t keyLength) {
+        if (!SkTFitsIn<int>(keyLength)) {
+            return false;
+        }
+        desc->fKey.reset(SkToInt(keyLength));
+        memcpy(desc->fKey.begin(), keyData, keyLength);
+        return true;
+    }
+
     // TODO: this should be removed and converted to just data added to the key
     struct KeyHeader {
         // Set to uniquely identify any swizzling of the shader's output color(s).