Remove GrProgramDesc's need for the GrGpu

Although not strictly necessary, being able to compute the program key w/o needing access to the Gpu will give us more flexibility.

Bug: skia:9455
Change-Id: I0cd76d79a3008b69be18636be370e7aaa531bc65
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/247686
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
diff --git a/src/gpu/GrProgramDesc.cpp b/src/gpu/GrProgramDesc.cpp
index 8d995a3..d0b4f23 100644
--- a/src/gpu/GrProgramDesc.cpp
+++ b/src/gpu/GrProgramDesc.cpp
@@ -45,62 +45,48 @@
 }
 
 static uint32_t sampler_key(GrTextureType textureType, const GrSwizzle& swizzle,
-                            const GrShaderCaps& caps) {
+                            const GrCaps& caps) {
     int samplerTypeKey = texture_type_key(textureType);
 
     GR_STATIC_ASSERT(2 == sizeof(swizzle.asKey()));
     uint16_t swizzleKey = 0;
-    if (caps.textureSwizzleAppliedInShader()) {
+    if (caps.shaderCaps()->textureSwizzleAppliedInShader()) {
         swizzleKey = swizzle.asKey();
     }
     return SkToU32(samplerTypeKey | swizzleKey << kSamplerOrImageTypeKeyBits);
 }
 
 static void add_fp_sampler_keys(GrProcessorKeyBuilder* b, const GrFragmentProcessor& fp,
-                                GrGpu* gpu, const GrShaderCaps& caps) {
+                                const GrCaps& caps) {
     int numTextureSamplers = fp.numTextureSamplers();
     if (!numTextureSamplers) {
         return;
     }
     for (int i = 0; i < numTextureSamplers; ++i) {
         const GrFragmentProcessor::TextureSampler& sampler = fp.textureSampler(i);
-        const GrTexture* tex = sampler.peekTexture();
-        uint32_t samplerKey = sampler_key(
-                tex->texturePriv().textureType(), sampler.swizzle(), caps);
-        uint32_t extraSamplerKey = gpu->getExtraSamplerKeyForProgram(
-                sampler.samplerState(), sampler.proxy()->backendFormat());
-        if (extraSamplerKey) {
-            // We first mark the normal sampler key with last bit to flag that it has an extra
-            // sampler key. We then add both keys.
-            SkASSERT((samplerKey & (1 << 31)) == 0);
-            b->add32(samplerKey | (1 << 31));
-            b->add32(extraSamplerKey);
-        } else {
-            b->add32(samplerKey);
-        }
+        const GrBackendFormat& backendFormat = sampler.proxy()->backendFormat();
+
+        uint32_t samplerKey = sampler_key(backendFormat.textureType(), sampler.swizzle(), caps);
+        b->add32(samplerKey);
+
+        caps.addExtraSamplerKey(b, sampler.samplerState(), backendFormat);
     }
 }
 
 static void add_pp_sampler_keys(GrProcessorKeyBuilder* b, const GrPrimitiveProcessor& pp,
-                                const GrShaderCaps& caps) {
+                                const GrCaps& caps) {
     int numTextureSamplers = pp.numTextureSamplers();
     if (!numTextureSamplers) {
         return;
     }
     for (int i = 0; i < numTextureSamplers; ++i) {
         const GrPrimitiveProcessor::TextureSampler& sampler = pp.textureSampler(i);
-        uint32_t samplerKey = sampler_key(
-                sampler.textureType(), sampler.swizzle(), caps);
-        uint32_t extraSamplerKey = sampler.extraSamplerKey();
-        if (extraSamplerKey) {
-            // We first mark the normal sampler key with last bit to flag that it has an extra
-            // sampler key. We then add both keys.
-            SkASSERT((samplerKey & (1 << 31)) == 0);
-            b->add32(samplerKey | (1 << 31));
-            b->add32(extraSamplerKey);
-        } else {
-            b->add32(samplerKey);
-        }
+        const GrBackendFormat& backendFormat = sampler.backendFormat();
+
+        uint32_t samplerKey = sampler_key(backendFormat.textureType(), sampler.swizzle(), caps);
+        b->add32(samplerKey);
+
+        caps.addExtraSamplerKey(b, sampler.samplerState(), backendFormat);
     }
 }
 
@@ -114,8 +100,7 @@
  * function because it is hairy, though FPs do not have attribs, and GPs do not have transforms
  */
 static bool gen_fp_meta_key(const GrFragmentProcessor& fp,
-                            GrGpu* gpu,
-                            const GrShaderCaps& shaderCaps,
+                            const GrCaps& caps,
                             uint32_t transformKey,
                             GrProcessorKeyBuilder* b) {
     size_t processorKeySize = b->size();
@@ -127,7 +112,7 @@
         return false;
     }
 
-    add_fp_sampler_keys(b, fp, gpu, shaderCaps);
+    add_fp_sampler_keys(b, fp, caps);
 
     uint32_t* key = b->add32n(2);
     key[0] = (classID << 16) | SkToU32(processorKeySize);
@@ -136,7 +121,7 @@
 }
 
 static bool gen_pp_meta_key(const GrPrimitiveProcessor& pp,
-                            const GrShaderCaps& shaderCaps,
+                            const GrCaps& caps,
                             uint32_t transformKey,
                             GrProcessorKeyBuilder* b) {
     size_t processorKeySize = b->size();
@@ -148,7 +133,7 @@
         return false;
     }
 
-    add_pp_sampler_keys(b, pp, shaderCaps);
+    add_pp_sampler_keys(b, pp, caps);
 
     uint32_t* key = b->add32n(2);
     key[0] = (classID << 16) | SkToU32(processorKeySize);
@@ -156,9 +141,7 @@
     return true;
 }
 
-static bool gen_xp_meta_key(const GrXferProcessor& xp,
-                            const GrShaderCaps& shaderCaps,
-                            GrProcessorKeyBuilder* b) {
+static bool gen_xp_meta_key(const GrXferProcessor& xp, GrProcessorKeyBuilder* b) {
     size_t processorKeySize = b->size();
     uint32_t classID = xp.classID();
 
@@ -174,31 +157,28 @@
 
 static bool gen_frag_proc_and_meta_keys(const GrPrimitiveProcessor& primProc,
                                         const GrFragmentProcessor& fp,
-                                        GrGpu* gpu,
-                                        const GrShaderCaps& shaderCaps,
+                                        const GrCaps& caps,
                                         GrProcessorKeyBuilder* b) {
     for (int i = 0; i < fp.numChildProcessors(); ++i) {
-        if (!gen_frag_proc_and_meta_keys(primProc, fp.childProcessor(i), gpu, shaderCaps, b)) {
+        if (!gen_frag_proc_and_meta_keys(primProc, fp.childProcessor(i), caps, b)) {
             return false;
         }
     }
 
-    fp.getGLSLProcessorKey(shaderCaps, b);
+    fp.getGLSLProcessorKey(*caps.shaderCaps(), b);
 
-    return gen_fp_meta_key(fp, gpu, shaderCaps, primProc.getTransformKey(fp.coordTransforms(),
-                                                                         fp.numCoordTransforms()),
-                                                                         b);
+    return gen_fp_meta_key(fp, caps, primProc.getTransformKey(fp.coordTransforms(),
+                                                              fp.numCoordTransforms()), b);
 }
 
 bool GrProgramDesc::Build(GrProgramDesc* desc, const GrRenderTarget* renderTarget,
-                          const GrProgramInfo& programInfo, GrGpu* gpu) {
+                          const GrProgramInfo& programInfo, const GrCaps& caps) {
+
     // The descriptor is used as a cache key. Thus when a field of the
     // descriptor will not affect program generation (because of the attribute
     // bindings in use or other descriptor field settings) it should be set
     // to a canonical value to avoid duplicate programs with different keys.
 
-    const GrShaderCaps& shaderCaps = *gpu->caps()->shaderCaps();
-
     GR_STATIC_ASSERT(0 == kProcessorKeysOffset % sizeof(uint32_t));
     // Make room for everything up to the effect keys.
     desc->key().reset();
@@ -206,16 +186,16 @@
 
     GrProcessorKeyBuilder b(&desc->key());
 
-    programInfo.primProc().getGLSLProcessorKey(shaderCaps, &b);
+    programInfo.primProc().getGLSLProcessorKey(*caps.shaderCaps(), &b);
     programInfo.primProc().getAttributeKey(&b);
-    if (!gen_pp_meta_key(programInfo.primProc(), shaderCaps, 0, &b)) {
+    if (!gen_pp_meta_key(programInfo.primProc(), caps, 0, &b)) {
         desc->key().reset();
         return false;
     }
 
     for (int i = 0; i < programInfo.pipeline().numFragmentProcessors(); ++i) {
         const GrFragmentProcessor& fp = programInfo.pipeline().getFragmentProcessor(i);
-        if (!gen_frag_proc_and_meta_keys(programInfo.primProc(), fp, gpu, shaderCaps, &b)) {
+        if (!gen_frag_proc_and_meta_keys(programInfo.primProc(), fp, caps, &b)) {
             desc->key().reset();
             return false;
         }
@@ -228,8 +208,8 @@
         origin = programInfo.pipeline().dstProxyView().origin();
         originIfDstTexture = &origin;
     }
-    xp.getGLSLProcessorKey(shaderCaps, &b, originIfDstTexture);
-    if (!gen_xp_meta_key(xp, shaderCaps, &b)) {
+    xp.getGLSLProcessorKey(*caps.shaderCaps(), &b, originIfDstTexture);
+    if (!gen_xp_meta_key(xp, &b)) {
         desc->key().reset();
         return false;
     }