[graphite] Combine writeTextures and writeUniforms

RenderStep::writeUniforms and RenderStep::writeTextures act on the
same data structure in the same locations in code so it makes sense
to combine them into one method.

Bug: skia:13118
Change-Id: I48b2f5cc95247aa5d58c0780ead65378bb812ff5
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/560396
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Jim Van Verth <jvanverth@google.com>
diff --git a/src/gpu/graphite/ContextUtils.cpp b/src/gpu/graphite/ContextUtils.cpp
index 89981e5..59a0200 100644
--- a/src/gpu/graphite/ContextUtils.cpp
+++ b/src/gpu/graphite/ContextUtils.cpp
@@ -62,13 +62,12 @@
                       const DrawParams& params) {
     SkDEBUGCODE(gatherer->checkReset());
 
-    step->writeUniforms(params, gatherer);
+    step->writeUniformsAndTextures(params, gatherer);
 
     UniformDataCache::Index uIndex = geometryUniformDataCache->insert(gatherer->peekUniformData());
 
     TextureDataCache::Index textureIndex;
     if (step->hasTextures()) {
-        step->writeTextures(params, gatherer);
         textureIndex = textureDataCache->insert(gatherer->textureDataBlock());
     }
 
diff --git a/src/gpu/graphite/Renderer.h b/src/gpu/graphite/Renderer.h
index 89334f3..c7ce773 100644
--- a/src/gpu/graphite/Renderer.h
+++ b/src/gpu/graphite/Renderer.h
@@ -50,20 +50,17 @@
     // this RenderStep.
     virtual void writeVertices(DrawWriter*, const DrawParams&) const = 0;
 
-    // Write out the uniform values (aligned for the layout). These values will be de-duplicated
-    // across all draws using the RenderStep before uploading to the GPU, but it can be assumed the
-    // uniforms will be bound before the draws recorded in 'writeVertices' are executed.
+    // Write out the uniform values (aligned for the layout), textures, and samplers. The uniform
+    // values will be de-duplicated across all draws using the RenderStep before uploading to the
+    // GPU, but it can be assumed the uniforms will be bound before the draws recorded in
+    // 'writeVertices' are executed.
     // TODO: We definitely want this to return CPU memory since it's better for the caller to handle
     // the de-duplication and GPU upload/binding (DrawPass tracks all this). However, a RenderStep's
     // uniforms aren't going to change, and the Layout won't change during a process, so it would be
     // nice if we could remember the offsets for the layout/gpu and reuse them across draws.
     // Similarly, it would be nice if this could write into reusable storage and then DrawPass or
     // UniformCache handles making an sk_sp if we need to assign a new unique ID to the uniform data
-    virtual void writeUniforms(const DrawParams&, SkPipelineDataGatherer*) const = 0;
-
-    // Write out the textures and samplers that depend on the RenderStep.
-    // E.g., atlas textures and samplers for text rendering.
-    virtual void writeTextures(const DrawParams&, SkPipelineDataGatherer*) const {}
+    virtual void writeUniformsAndTextures(const DrawParams&, SkPipelineDataGatherer*) const = 0;
 
     // Returns a name formatted as "Subclass[variant]", where "Subclass" matches the C++ class name
     // and variant is a unique term describing instance's specific configuration.
diff --git a/src/gpu/graphite/render/CoverBoundsRenderStep.cpp b/src/gpu/graphite/render/CoverBoundsRenderStep.cpp
index 65b4b92..02777c3 100644
--- a/src/gpu/graphite/render/CoverBoundsRenderStep.cpp
+++ b/src/gpu/graphite/render/CoverBoundsRenderStep.cpp
@@ -56,7 +56,8 @@
                     << devPoints[2].x << devPoints[2].y << depth << devPoints[2].w;// BR
 }
 
-void CoverBoundsRenderStep::writeUniforms(const DrawParams&, SkPipelineDataGatherer*) const {
+void CoverBoundsRenderStep::writeUniformsAndTextures(const DrawParams&,
+                                                     SkPipelineDataGatherer*) const {
     // Control points are pre-transformed to device space on the CPU, so no uniforms needed.
 }
 
diff --git a/src/gpu/graphite/render/CoverBoundsRenderStep.h b/src/gpu/graphite/render/CoverBoundsRenderStep.h
index 3eab244..2e11918 100644
--- a/src/gpu/graphite/render/CoverBoundsRenderStep.h
+++ b/src/gpu/graphite/render/CoverBoundsRenderStep.h
@@ -20,7 +20,7 @@
 
     const char* vertexSkSL() const override;
     void writeVertices(DrawWriter*, const DrawParams&) const override;
-    void writeUniforms(const DrawParams&, SkPipelineDataGatherer*) const override;
+    void writeUniformsAndTextures(const DrawParams&, SkPipelineDataGatherer*) const override;
 
 private:
     const bool fInverseFill;
diff --git a/src/gpu/graphite/render/MiddleOutFanRenderStep.cpp b/src/gpu/graphite/render/MiddleOutFanRenderStep.cpp
index 31d1cf3..a3673d4 100644
--- a/src/gpu/graphite/render/MiddleOutFanRenderStep.cpp
+++ b/src/gpu/graphite/render/MiddleOutFanRenderStep.cpp
@@ -59,7 +59,8 @@
     }
 }
 
-void MiddleOutFanRenderStep::writeUniforms(const DrawParams&, SkPipelineDataGatherer*) const {
+void MiddleOutFanRenderStep::writeUniformsAndTextures(const DrawParams&,
+                                                      SkPipelineDataGatherer*) const {
     // Control points are pre-transformed to device space on the CPU, so no uniforms needed.
 }
 
diff --git a/src/gpu/graphite/render/MiddleOutFanRenderStep.h b/src/gpu/graphite/render/MiddleOutFanRenderStep.h
index d0c06aa..da0fcef 100644
--- a/src/gpu/graphite/render/MiddleOutFanRenderStep.h
+++ b/src/gpu/graphite/render/MiddleOutFanRenderStep.h
@@ -23,7 +23,7 @@
 
     const char* vertexSkSL() const override;
     void writeVertices(DrawWriter*, const DrawParams&) const override;
-    void writeUniforms(const DrawParams&, SkPipelineDataGatherer*) const override;
+    void writeUniformsAndTextures(const DrawParams&, SkPipelineDataGatherer*) const override;
 };
 
 }  // namespace skgpu::graphite
diff --git a/src/gpu/graphite/render/TessellateCurvesRenderStep.cpp b/src/gpu/graphite/render/TessellateCurvesRenderStep.cpp
index 5a88bc0..e48f523 100644
--- a/src/gpu/graphite/render/TessellateCurvesRenderStep.cpp
+++ b/src/gpu/graphite/render/TessellateCurvesRenderStep.cpp
@@ -123,7 +123,8 @@
     }
 }
 
-void TessellateCurvesRenderStep::writeUniforms(const DrawParams&, SkPipelineDataGatherer*) const {
+void TessellateCurvesRenderStep::writeUniformsAndTextures(const DrawParams&,
+                                                          SkPipelineDataGatherer*) const {
     // Control points are pre-transformed to device space on the CPU, so no uniforms needed.
 }
 
diff --git a/src/gpu/graphite/render/TessellateCurvesRenderStep.h b/src/gpu/graphite/render/TessellateCurvesRenderStep.h
index 2397e77..cf8637e 100644
--- a/src/gpu/graphite/render/TessellateCurvesRenderStep.h
+++ b/src/gpu/graphite/render/TessellateCurvesRenderStep.h
@@ -23,7 +23,7 @@
 
     const char* vertexSkSL() const override;
     void writeVertices(DrawWriter*, const DrawParams&) const override;
-    void writeUniforms(const DrawParams&, SkPipelineDataGatherer*) const override;
+    void writeUniformsAndTextures(const DrawParams&, SkPipelineDataGatherer*) const override;
 };
 
 }  // namespace skgpu::graphite
diff --git a/src/gpu/graphite/render/TessellateStrokesRenderStep.cpp b/src/gpu/graphite/render/TessellateStrokesRenderStep.cpp
index d7f1b7a..165d7f9 100644
--- a/src/gpu/graphite/render/TessellateStrokesRenderStep.cpp
+++ b/src/gpu/graphite/render/TessellateStrokesRenderStep.cpp
@@ -211,8 +211,8 @@
     }
 }
 
-void TessellateStrokesRenderStep::writeUniforms(const DrawParams& params,
-                                                SkPipelineDataGatherer* gatherer) const {
+void TessellateStrokesRenderStep::writeUniformsAndTextures(const DrawParams& params,
+                                                           SkPipelineDataGatherer* gatherer) const {
     SkASSERT(params.transform().type() < Transform::Type::kProjection); // TODO: Implement perspective
 
     SkDEBUGCODE(UniformExpectationsValidator uev(gatherer, this->uniforms());)
diff --git a/src/gpu/graphite/render/TessellateStrokesRenderStep.h b/src/gpu/graphite/render/TessellateStrokesRenderStep.h
index f687359..09e33eb 100644
--- a/src/gpu/graphite/render/TessellateStrokesRenderStep.h
+++ b/src/gpu/graphite/render/TessellateStrokesRenderStep.h
@@ -23,7 +23,7 @@
 
     const char* vertexSkSL() const override;
     void writeVertices(DrawWriter*, const DrawParams&) const override;
-    void writeUniforms(const DrawParams&, SkPipelineDataGatherer*) const override;
+    void writeUniformsAndTextures(const DrawParams&, SkPipelineDataGatherer*) const override;
 };
 
 }  // namespace skgpu::graphite
diff --git a/src/gpu/graphite/render/TessellateWedgesRenderStep.cpp b/src/gpu/graphite/render/TessellateWedgesRenderStep.cpp
index b35461c..72e52b3 100644
--- a/src/gpu/graphite/render/TessellateWedgesRenderStep.cpp
+++ b/src/gpu/graphite/render/TessellateWedgesRenderStep.cpp
@@ -154,7 +154,8 @@
     }
 }
 
-void TessellateWedgesRenderStep::writeUniforms(const DrawParams&, SkPipelineDataGatherer*) const {
+void TessellateWedgesRenderStep::writeUniformsAndTextures(const DrawParams&,
+                                                          SkPipelineDataGatherer*) const {
     // Control points are pre-transformed to device space on the CPU, so no uniforms needed.
 }
 
diff --git a/src/gpu/graphite/render/TessellateWedgesRenderStep.h b/src/gpu/graphite/render/TessellateWedgesRenderStep.h
index 0af1fb8..b313973 100644
--- a/src/gpu/graphite/render/TessellateWedgesRenderStep.h
+++ b/src/gpu/graphite/render/TessellateWedgesRenderStep.h
@@ -21,7 +21,7 @@
 
     const char* vertexSkSL() const override;
     void writeVertices(DrawWriter*, const DrawParams&) const override;
-    void writeUniforms(const DrawParams&, SkPipelineDataGatherer*) const override;
+    void writeUniformsAndTextures(const DrawParams&, SkPipelineDataGatherer*) const override;
 
 };
 
diff --git a/src/gpu/graphite/render/TextDirectRenderStep.cpp b/src/gpu/graphite/render/TextDirectRenderStep.cpp
index 5a3f4ec..cea76fa 100644
--- a/src/gpu/graphite/render/TextDirectRenderStep.cpp
+++ b/src/gpu/graphite/render/TextDirectRenderStep.cpp
@@ -71,8 +71,8 @@
                                         params.transform());
 }
 
-void TextDirectRenderStep::writeUniforms(const DrawParams& params,
-                                         SkPipelineDataGatherer* gatherer) const {
+void TextDirectRenderStep::writeUniformsAndTextures(const DrawParams& params,
+                                                    SkPipelineDataGatherer* gatherer) const {
     SkDEBUGCODE(UniformExpectationsValidator uev(gatherer, this->uniforms());)
 
     const SubRunData& subRunData = params.geometry().subRunData();
@@ -83,21 +83,12 @@
                                                         &numProxies);
     SkASSERT(proxies && numProxies > 0);
 
+    // write uniforms
     skvx::float2 atlasDimensionsInverse = {1.f/proxies[0]->dimensions().width(),
                                            1.f/proxies[0]->dimensions().height()};
     gatherer->write(atlasDimensionsInverse);
-}
 
-void TextDirectRenderStep::writeTextures(const DrawParams& params,
-                                         SkPipelineDataGatherer* gatherer) const {
-    const SubRunData& subRunData = params.geometry().subRunData();
-
-    unsigned int numProxies;
-    Recorder* recorder = subRunData.recorder();
-    const sk_sp<TextureProxy>* proxies =
-            recorder->priv().atlasManager()->getProxies(subRunData.subRun()->maskFormat(),
-                                                        &numProxies);
-    SkASSERT(proxies && numProxies > 0);
+    // write textures and samplers
     const SkSamplingOptions samplingOptions(SkFilterMode::kNearest);
     const SkTileMode tileModes[2] = { SkTileMode::kClamp, SkTileMode::kClamp };
     for (unsigned int i = 0; i < numProxies; ++i) {
diff --git a/src/gpu/graphite/render/TextDirectRenderStep.h b/src/gpu/graphite/render/TextDirectRenderStep.h
index dab5b66..599ae30 100644
--- a/src/gpu/graphite/render/TextDirectRenderStep.h
+++ b/src/gpu/graphite/render/TextDirectRenderStep.h
@@ -20,8 +20,7 @@
 
     const char* vertexSkSL() const override;
     void writeVertices(DrawWriter*, const DrawParams&) const override;
-    void writeUniforms(const DrawParams&, SkPipelineDataGatherer*) const override;
-    void writeTextures(const DrawParams&, SkPipelineDataGatherer*) const override;
+    void writeUniformsAndTextures(const DrawParams&, SkPipelineDataGatherer*) const override;
 };
 
 }  // namespace skgpu::graphite
diff --git a/src/gpu/graphite/render/TextSDFRenderStep.cpp b/src/gpu/graphite/render/TextSDFRenderStep.cpp
index 3b4fb6a..14dcdb5 100644
--- a/src/gpu/graphite/render/TextSDFRenderStep.cpp
+++ b/src/gpu/graphite/render/TextSDFRenderStep.cpp
@@ -68,8 +68,8 @@
                                         params.order().depthAsFloat(), params.transform());
 }
 
-void TextSDFRenderStep::writeUniforms(const DrawParams& params,
-                                      SkPipelineDataGatherer* gatherer) const {
+void TextSDFRenderStep::writeUniformsAndTextures(const DrawParams& params,
+                                                 SkPipelineDataGatherer* gatherer) const {
     SkDEBUGCODE(UniformExpectationsValidator uev(gatherer, this->uniforms());)
 
     // TODO: get this from the actual texture size via the SubRunData
diff --git a/src/gpu/graphite/render/TextSDFRenderStep.h b/src/gpu/graphite/render/TextSDFRenderStep.h
index 557b145..f44fb0d 100644
--- a/src/gpu/graphite/render/TextSDFRenderStep.h
+++ b/src/gpu/graphite/render/TextSDFRenderStep.h
@@ -22,7 +22,7 @@
 
     const char* vertexSkSL() const override;
     void writeVertices(DrawWriter*, const DrawParams&) const override;
-    void writeUniforms(const DrawParams&, SkPipelineDataGatherer*) const override;
+    void writeUniformsAndTextures(const DrawParams&, SkPipelineDataGatherer*) const override;
 };
 
 }  // namespace skgpu::graphite