Plumb GrBackendFormat into the GrPrimitiveProcessor::TextureSampler

This is not a substantive CL. It is just setting up for removing the
usage of the GrGpu in the creation of the GrProgramDesc.

Change-Id: Ic24204de256862e5e780626bde3a44f4d735c6e9
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/249121
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/src/gpu/GrPrimitiveProcessor.cpp b/src/gpu/GrPrimitiveProcessor.cpp
index fea8e2d..5ca399a 100644
--- a/src/gpu/GrPrimitiveProcessor.cpp
+++ b/src/gpu/GrPrimitiveProcessor.cpp
@@ -53,21 +53,21 @@
     return requestedFilter;
 }
 
-GrPrimitiveProcessor::TextureSampler::TextureSampler(GrTextureType textureType,
-                                                     const GrSamplerState& samplerState,
+GrPrimitiveProcessor::TextureSampler::TextureSampler(const GrSamplerState& samplerState,
+                                                     const GrBackendFormat& backendFormat,
                                                      const GrSwizzle& swizzle,
                                                      uint32_t extraSamplerKey) {
-    this->reset(textureType, samplerState, swizzle, extraSamplerKey);
+    this->reset(samplerState, backendFormat, swizzle, extraSamplerKey);
 }
 
-void GrPrimitiveProcessor::TextureSampler::reset(GrTextureType textureType,
-                                                 const GrSamplerState& samplerState,
+void GrPrimitiveProcessor::TextureSampler::reset(const GrSamplerState& samplerState,
+                                                 const GrBackendFormat& backendFormat,
                                                  const GrSwizzle& swizzle,
                                                  uint32_t extraSamplerKey) {
     fSamplerState = samplerState;
-    fSamplerState.setFilterMode(clamp_filter(textureType, samplerState.filter()));
+    fSamplerState.setFilterMode(clamp_filter(backendFormat.textureType(), samplerState.filter()));
+    fBackendFormat = backendFormat;
     fSwizzle = swizzle;
-    fTextureType = textureType;
     fExtraSamplerKey = extraSamplerKey;
     fIsInitialized = true;
 }
diff --git a/src/gpu/GrPrimitiveProcessor.h b/src/gpu/GrPrimitiveProcessor.h
index 41f37a3..e0baf65 100644
--- a/src/gpu/GrPrimitiveProcessor.h
+++ b/src/gpu/GrPrimitiveProcessor.h
@@ -255,16 +255,17 @@
 public:
     TextureSampler() = default;
 
-    TextureSampler(GrTextureType, const GrSamplerState&, const GrSwizzle&,
+    TextureSampler(const GrSamplerState&, const GrBackendFormat&, const GrSwizzle&,
                    uint32_t extraSamplerKey = 0);
 
     TextureSampler(const TextureSampler&) = delete;
     TextureSampler& operator=(const TextureSampler&) = delete;
 
-    void reset(GrTextureType, const GrSamplerState&, const GrSwizzle&,
+    void reset(const GrSamplerState&, const GrBackendFormat&, const GrSwizzle&,
                uint32_t extraSamplerKey = 0);
 
-    GrTextureType textureType() const { return fTextureType; }
+    const GrBackendFormat& backendFormat() const { return fBackendFormat; }
+    GrTextureType textureType() const { return fBackendFormat.textureType(); }
 
     const GrSamplerState& samplerState() const { return fSamplerState; }
     const GrSwizzle& swizzle() const { return fSwizzle; }
@@ -274,11 +275,11 @@
     bool isInitialized() const { return fIsInitialized; }
 
 private:
-    GrSamplerState fSamplerState;
-    GrSwizzle fSwizzle;
-    GrTextureType fTextureType = GrTextureType::k2D;
-    uint32_t fExtraSamplerKey = 0;
-    bool fIsInitialized = false;
+    GrSamplerState  fSamplerState;
+    GrBackendFormat fBackendFormat;
+    GrSwizzle       fSwizzle;
+    uint32_t        fExtraSamplerKey = 0;
+    bool            fIsInitialized = false;
 };
 
 const GrPrimitiveProcessor::TextureSampler& GrPrimitiveProcessor::IthTextureSampler(int i) {
diff --git a/src/gpu/GrProgramDesc.cpp b/src/gpu/GrProgramDesc.cpp
index 9d42d69..a4a7548 100644
--- a/src/gpu/GrProgramDesc.cpp
+++ b/src/gpu/GrProgramDesc.cpp
@@ -56,8 +56,8 @@
     return SkToU32(samplerTypeKey | swizzleKey << kSamplerOrImageTypeKeyBits);
 }
 
-static void add_sampler_keys(GrProcessorKeyBuilder* b, const GrFragmentProcessor& fp,
-                             GrGpu* gpu, const GrShaderCaps& caps) {
+static void add_fp_sampler_keys(GrProcessorKeyBuilder* b, const GrFragmentProcessor& fp,
+                                GrGpu* gpu, const GrShaderCaps& caps) {
     int numTextureSamplers = fp.numTextureSamplers();
     if (!numTextureSamplers) {
         return;
@@ -81,8 +81,8 @@
     }
 }
 
-static void add_sampler_keys(GrProcessorKeyBuilder* b, const GrPrimitiveProcessor& pp,
-                             const GrShaderCaps& caps) {
+static void add_pp_sampler_keys(GrProcessorKeyBuilder* b, const GrPrimitiveProcessor& pp,
+                                const GrShaderCaps& caps) {
     int numTextureSamplers = pp.numTextureSamplers();
     if (!numTextureSamplers) {
         return;
@@ -113,11 +113,11 @@
  * transforms, etc, for the space allotted in the meta-key.  NOTE, both FPs and GPs share this
  * function because it is hairy, though FPs do not have attribs, and GPs do not have transforms
  */
-static bool gen_meta_key(const GrFragmentProcessor& fp,
-                         GrGpu* gpu,
-                         const GrShaderCaps& shaderCaps,
-                         uint32_t transformKey,
-                         GrProcessorKeyBuilder* b) {
+static bool gen_fp_meta_key(const GrFragmentProcessor& fp,
+                            GrGpu* gpu,
+                            const GrShaderCaps& shaderCaps,
+                            uint32_t transformKey,
+                            GrProcessorKeyBuilder* b) {
     size_t processorKeySize = b->size();
     uint32_t classID = fp.classID();
 
@@ -127,7 +127,7 @@
         return false;
     }
 
-    add_sampler_keys(b, fp, gpu, shaderCaps);
+    add_fp_sampler_keys(b, fp, gpu, shaderCaps);
 
     uint32_t* key = b->add32n(2);
     key[0] = (classID << 16) | SkToU32(processorKeySize);
@@ -135,10 +135,10 @@
     return true;
 }
 
-static bool gen_meta_key(const GrPrimitiveProcessor& pp,
-                         const GrShaderCaps& shaderCaps,
-                         uint32_t transformKey,
-                         GrProcessorKeyBuilder* b) {
+static bool gen_pp_meta_key(const GrPrimitiveProcessor& pp,
+                            const GrShaderCaps& shaderCaps,
+                            uint32_t transformKey,
+                            GrProcessorKeyBuilder* b) {
     size_t processorKeySize = b->size();
     uint32_t classID = pp.classID();
 
@@ -148,7 +148,7 @@
         return false;
     }
 
-    add_sampler_keys(b, pp, shaderCaps);
+    add_pp_sampler_keys(b, pp, shaderCaps);
 
     uint32_t* key = b->add32n(2);
     key[0] = (classID << 16) | SkToU32(processorKeySize);
@@ -156,9 +156,9 @@
     return true;
 }
 
-static bool gen_meta_key(const GrXferProcessor& xp,
-                         const GrShaderCaps& shaderCaps,
-                         GrProcessorKeyBuilder* b) {
+static bool gen_xp_meta_key(const GrXferProcessor& xp,
+                            const GrShaderCaps& shaderCaps,
+                            GrProcessorKeyBuilder* b) {
     size_t processorKeySize = b->size();
     uint32_t classID = xp.classID();
 
@@ -185,8 +185,9 @@
 
     fp.getGLSLProcessorKey(shaderCaps, b);
 
-    return gen_meta_key(fp, gpu, shaderCaps, primProc.getTransformKey(fp.coordTransforms(),
-                                                                      fp.numCoordTransforms()), b);
+    return gen_fp_meta_key(fp, gpu, shaderCaps, primProc.getTransformKey(fp.coordTransforms(),
+                                                                         fp.numCoordTransforms()),
+                                                                         b);
 }
 
 bool GrProgramDesc::Build(GrProgramDesc* desc, const GrRenderTarget* renderTarget,
@@ -208,7 +209,7 @@
 
     programInfo.primProc().getGLSLProcessorKey(shaderCaps, &b);
     programInfo.primProc().getAttributeKey(&b);
-    if (!gen_meta_key(programInfo.primProc(), shaderCaps, 0, &b)) {
+    if (!gen_pp_meta_key(programInfo.primProc(), shaderCaps, 0, &b)) {
         desc->key().reset();
         return false;
     }
@@ -229,7 +230,7 @@
         originIfDstTexture = &origin;
     }
     xp.getGLSLProcessorKey(shaderCaps, &b, originIfDstTexture);
-    if (!gen_meta_key(xp, shaderCaps, &b)) {
+    if (!gen_xp_meta_key(xp, shaderCaps, &b)) {
         desc->key().reset();
         return false;
     }
diff --git a/src/gpu/ccpr/GrCCClipProcessor.cpp b/src/gpu/ccpr/GrCCClipProcessor.cpp
index 75535dd..a4656fa 100644
--- a/src/gpu/ccpr/GrCCClipProcessor.cpp
+++ b/src/gpu/ccpr/GrCCClipProcessor.cpp
@@ -20,7 +20,7 @@
         , fClipPath(clipPath)
         , fIsCoverageCount(IsCoverageCount::kYes == isCoverageCount)
         , fMustCheckBounds(MustCheckBounds::kYes == mustCheckBounds)
-        , fAtlasAccess(sk_ref_sp(fClipPath->atlasLazyProxy()), GrSamplerState::ClampNearest()) {
+        , fAtlasAccess(sk_ref_sp(fClipPath->atlasLazyProxy())) {
     SkASSERT(fAtlasAccess.proxy());
     this->setTextureSamplerCnt(1);
 }
diff --git a/src/gpu/ccpr/GrCCPathProcessor.cpp b/src/gpu/ccpr/GrCCPathProcessor.cpp
index 9fba60d..07065f5 100644
--- a/src/gpu/ccpr/GrCCPathProcessor.cpp
+++ b/src/gpu/ccpr/GrCCPathProcessor.cpp
@@ -84,8 +84,7 @@
                                      const SkMatrix& viewMatrixIfUsingLocalCoords)
         : INHERITED(kGrCCPathProcessor_ClassID)
         , fCoverageMode(coverageMode)
-        , fAtlasAccess(atlasTexture->texturePriv().textureType(), GrSamplerState::ClampNearest(),
-                       swizzle)
+        , fAtlasAccess(GrSamplerState::ClampNearest(), atlasTexture->backendFormat(), swizzle)
         , fAtlasSize(SkISize::Make(atlasTexture->width(), atlasTexture->height()))
         , fAtlasOrigin(atlasOrigin) {
     // TODO: Can we just assert that atlas has GrCCAtlas::kTextureOrigin and remove fAtlasOrigin?
diff --git a/src/gpu/effects/GrBitmapTextGeoProc.cpp b/src/gpu/effects/GrBitmapTextGeoProc.cpp
index 4a8c25d..5bbe8fb 100644
--- a/src/gpu/effects/GrBitmapTextGeoProc.cpp
+++ b/src/gpu/effects/GrBitmapTextGeoProc.cpp
@@ -154,7 +154,8 @@
     for (int i = 0; i < numActiveProxies; ++i) {
         SkASSERT(proxies[i]);
         SkASSERT(proxies[i]->isize() == fAtlasSize);
-        fTextureSamplers[i].reset(proxies[i]->textureType(), params, proxies[i]->textureSwizzle());
+        fTextureSamplers[i].reset(params, proxies[i]->backendFormat(),
+                                  proxies[i]->textureSwizzle());
     }
     this->setTextureSamplerCnt(numActiveProxies);
 }
@@ -173,7 +174,7 @@
         SkASSERT(proxies[i]->isize() == fAtlasSize);
 
         if (!fTextureSamplers[i].isInitialized()) {
-            fTextureSamplers[i].reset(proxies[i]->textureType(), params,
+            fTextureSamplers[i].reset(params, proxies[i]->backendFormat(),
                                       proxies[i]->textureSwizzle());
         }
     }
diff --git a/src/gpu/effects/GrDistanceFieldGeoProc.cpp b/src/gpu/effects/GrDistanceFieldGeoProc.cpp
index 08c36dc..321aef5 100644
--- a/src/gpu/effects/GrDistanceFieldGeoProc.cpp
+++ b/src/gpu/effects/GrDistanceFieldGeoProc.cpp
@@ -241,7 +241,8 @@
     for (int i = 0; i < numProxies; ++i) {
         SkASSERT(proxies[i]);
         SkASSERT(proxies[i]->isize() == fAtlasSize);
-        fTextureSamplers[i].reset(proxies[i]->textureType(), params, proxies[i]->textureSwizzle());
+        fTextureSamplers[i].reset(params, proxies[i]->backendFormat(),
+                                  proxies[i]->textureSwizzle());
     }
     this->setTextureSamplerCnt(numProxies);
 }
@@ -259,7 +260,7 @@
         SkASSERT(proxies[i]);
         SkASSERT(proxies[i]->isize() == fAtlasSize);
         if (!fTextureSamplers[i].isInitialized()) {
-            fTextureSamplers[i].reset(proxies[i]->textureType(), params,
+            fTextureSamplers[i].reset(params, proxies[i]->backendFormat(),
                                       proxies[i]->textureSwizzle());
         }
     }
@@ -536,7 +537,8 @@
     for (int i = 0; i < numProxies; ++i) {
         SkASSERT(proxies[i]);
         SkASSERT(proxies[i]->isize() == fAtlasSize);
-        fTextureSamplers[i].reset(proxies[i]->textureType(), params, proxies[i]->textureSwizzle());
+        fTextureSamplers[i].reset(params, proxies[i]->backendFormat(),
+                                  proxies[i]->textureSwizzle());
     }
     this->setTextureSamplerCnt(numProxies);
 }
@@ -555,7 +557,7 @@
         SkASSERT(proxies[i]->isize() == fAtlasSize);
 
         if (!fTextureSamplers[i].isInitialized()) {
-            fTextureSamplers[i].reset(proxies[i]->textureType(), params,
+            fTextureSamplers[i].reset(params, proxies[i]->backendFormat(),
                                       proxies[i]->textureSwizzle());
         }
     }
@@ -859,7 +861,8 @@
     for (int i = 0; i < numProxies; ++i) {
         SkASSERT(proxies[i]);
         SkASSERT(proxies[i]->isize() == fAtlasSize);
-        fTextureSamplers[i].reset(proxies[i]->textureType(), params, proxies[i]->textureSwizzle());
+        fTextureSamplers[i].reset(params, proxies[i]->backendFormat(),
+                                  proxies[i]->textureSwizzle());
     }
     this->setTextureSamplerCnt(numProxies);
 }
@@ -878,7 +881,7 @@
         SkASSERT(proxies[i]->isize() == fAtlasSize);
 
         if (!fTextureSamplers[i].isInitialized()) {
-            fTextureSamplers[i].reset(proxies[i]->textureType(), params,
+            fTextureSamplers[i].reset(params, proxies[i]->backendFormat(),
                                       proxies[i]->textureSwizzle());
         }
     }
diff --git a/src/gpu/gl/GrGLGpuProgramCache.cpp b/src/gpu/gl/GrGLGpuProgramCache.cpp
index 0109741..592605e 100644
--- a/src/gpu/gl/GrGLGpuProgramCache.cpp
+++ b/src/gpu/gl/GrGLGpuProgramCache.cpp
@@ -52,6 +52,7 @@
     // TODO: can this be unified between GL, Vk and Mtl?
     // Get GrGLProgramDesc
     GrProgramDesc desc;
+
     if (!GrProgramDesc::Build(&desc, renderTarget, programInfo, primitiveType, gpu)) {
         GrCapsDebugf(gpu->caps(), "Failed to gl program descriptor!\n");
         return nullptr;
diff --git a/src/gpu/ops/GrLatticeOp.cpp b/src/gpu/ops/GrLatticeOp.cpp
index adcfe8c..d63c7d6 100644
--- a/src/gpu/ops/GrLatticeOp.cpp
+++ b/src/gpu/ops/GrLatticeOp.cpp
@@ -96,12 +96,11 @@
               GrSamplerState::Filter filter, bool wideColor)
             : INHERITED(kLatticeGP_ClassID), fColorSpaceXform(std::move(csxf)) {
 
-        GrSamplerState samplerState = GrSamplerState(GrSamplerState::WrapMode::kClamp,
-                                                     filter);
+        GrSamplerState samplerState = GrSamplerState(GrSamplerState::WrapMode::kClamp, filter);
         uint32_t extraSamplerKey = gpu->getExtraSamplerKeyForProgram(samplerState,
                                                                      proxy->backendFormat());
 
-        fSampler.reset(proxy->textureType(), samplerState, proxy->textureSwizzle(),
+        fSampler.reset(samplerState, proxy->backendFormat(), proxy->textureSwizzle(),
                        extraSamplerKey);
         this->setTextureSamplerCnt(1);
         fInPosition = {"position", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
diff --git a/src/gpu/ops/GrQuadPerEdgeAA.cpp b/src/gpu/ops/GrQuadPerEdgeAA.cpp
index 27bd00e..929824c 100644
--- a/src/gpu/ops/GrQuadPerEdgeAA.cpp
+++ b/src/gpu/ops/GrQuadPerEdgeAA.cpp
@@ -732,13 +732,13 @@
     }
 
     static sk_sp<GrGeometryProcessor> Make(const VertexSpec& vertexSpec, const GrShaderCaps& caps,
-                                           GrTextureType textureType,
+                                           const GrBackendFormat& backendFormat,
                                            const GrSamplerState& samplerState,
                                            const GrSwizzle& swizzle, uint32_t extraSamplerKey,
                                            sk_sp<GrColorSpaceXform> textureColorSpaceXform,
                                            Saturate saturate) {
         return sk_sp<QuadPerEdgeAAGeometryProcessor>(new QuadPerEdgeAAGeometryProcessor(
-                vertexSpec, caps, textureType, samplerState, swizzle, extraSamplerKey,
+                vertexSpec, caps, backendFormat, samplerState, swizzle, extraSamplerKey,
                 std::move(textureColorSpaceXform), saturate));
     }
 
@@ -939,7 +939,7 @@
 
     QuadPerEdgeAAGeometryProcessor(const VertexSpec& spec,
                                    const GrShaderCaps& caps,
-                                   GrTextureType textureType,
+                                   const GrBackendFormat& backendFormat,
                                    const GrSamplerState& samplerState,
                                    const GrSwizzle& swizzle,
                                    uint32_t extraSamplerKey,
@@ -948,7 +948,7 @@
             : INHERITED(kQuadPerEdgeAAGeometryProcessor_ClassID)
             , fSaturate(saturate)
             , fTextureColorSpaceXform(std::move(textureColorSpaceXform))
-            , fSampler(textureType, samplerState, swizzle, extraSamplerKey) {
+            , fSampler(samplerState, backendFormat, swizzle, extraSamplerKey) {
         SkASSERT(spec.hasLocalCoords());
         this->initializeAttrs(spec);
         this->setTextureSamplerCnt(1);
@@ -1029,12 +1029,12 @@
 }
 
 sk_sp<GrGeometryProcessor> MakeTexturedProcessor(const VertexSpec& spec, const GrShaderCaps& caps,
-                                                 GrTextureType textureType,
+                                                 const GrBackendFormat& backendFormat,
                                                  const GrSamplerState& samplerState,
                                                  const GrSwizzle& swizzle, uint32_t extraSamplerKey,
                                                  sk_sp<GrColorSpaceXform> textureColorSpaceXform,
                                                  Saturate saturate) {
-    return QuadPerEdgeAAGeometryProcessor::Make(spec, caps, textureType, samplerState, swizzle,
+    return QuadPerEdgeAAGeometryProcessor::Make(spec, caps, backendFormat, samplerState, swizzle,
                                                 extraSamplerKey, std::move(textureColorSpaceXform),
                                                 saturate);
 }
diff --git a/src/gpu/ops/GrQuadPerEdgeAA.h b/src/gpu/ops/GrQuadPerEdgeAA.h
index 06bb315..eec30b3 100644
--- a/src/gpu/ops/GrQuadPerEdgeAA.h
+++ b/src/gpu/ops/GrQuadPerEdgeAA.h
@@ -89,7 +89,7 @@
     sk_sp<GrGeometryProcessor> MakeProcessor(const VertexSpec& spec);
 
     sk_sp<GrGeometryProcessor> MakeTexturedProcessor(
-            const VertexSpec& spec, const GrShaderCaps& caps, GrTextureType textureType,
+            const VertexSpec& spec, const GrShaderCaps& caps, const GrBackendFormat&,
             const GrSamplerState& samplerState, const GrSwizzle& swizzle, uint32_t extraSamplerKey,
             sk_sp<GrColorSpaceXform> textureColorSpaceXform, Saturate saturate);
 
diff --git a/src/gpu/ops/GrTextureOp.cpp b/src/gpu/ops/GrTextureOp.cpp
index bd4673e..9da40bd 100644
--- a/src/gpu/ops/GrTextureOp.cpp
+++ b/src/gpu/ops/GrTextureOp.cpp
@@ -572,7 +572,7 @@
         sk_sp<GrGeometryProcessor> gp;
 
         {
-            auto textureType = fProxies[0].fProxy->textureType();
+            const GrBackendFormat& backendFormat = fProxies[0].fProxy->backendFormat();
             const GrSwizzle& swizzle = fProxies[0].fProxy->textureSwizzle();
 
             GrSamplerState samplerState = GrSamplerState(GrSamplerState::WrapMode::kClamp,
@@ -581,11 +581,11 @@
             auto saturate = static_cast<GrTextureOp::Saturate>(fSaturate);
 
             GrGpu* gpu = target->resourceProvider()->priv().gpu();
-            uint32_t extraSamplerKey = gpu->getExtraSamplerKeyForProgram(
-                    samplerState, fProxies[0].fProxy->backendFormat());
+            uint32_t extraSamplerKey = gpu->getExtraSamplerKeyForProgram(samplerState,
+                                                                         backendFormat);
 
             gp = GrQuadPerEdgeAA::MakeTexturedProcessor(
-                vertexSpec, *target->caps().shaderCaps(), textureType, samplerState, swizzle,
+                vertexSpec, *target->caps().shaderCaps(), backendFormat, samplerState, swizzle,
                 extraSamplerKey, std::move(fTextureColorSpaceXform), saturate);
 
             SkASSERT(vertexSize == gp->vertexStride());