[graphite] Report coverage AA from Renderer and respect it in Device

RenderSteps can now report if they emit an analytic coverage variable.
When we have fragment shader integration, this flag can be checked to
handle the fixed blending that happens between the dst color and the
result of the blend between src and dst that is coverage dependent.

Updates Device to take this into account for ordering, anything that
uses coverage AA can depend on the dst so has to be constrained
appropriately. Sets the flag on the text render steps.

This also cleans up some whitespace alignment and stale comments
in Renderer.h

Change-Id: If8cc0bacc6e11166f4ac36e1eec754b371c417b1
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/560727
Reviewed-by: Greg Daniel <egdaniel@google.com>
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
diff --git a/src/gpu/graphite/Device.cpp b/src/gpu/graphite/Device.cpp
index dae2bf1..ed23090 100644
--- a/src/gpu/graphite/Device.cpp
+++ b/src/gpu/graphite/Device.cpp
@@ -710,7 +710,7 @@
     // order to blend correctly. We always query the most recent draw (even when opaque) because it
     // also lets Device easily track whether or not there are any overlapping draws.
     PaintParams shading{paint};
-    const bool dependsOnDst = paint_depends_on_dst(shading); // TODO: || renderer->usesCoverageAA();
+    const bool dependsOnDst = renderer->emitsCoverage() || paint_depends_on_dst(shading);
     CompressedPaintersOrder prevDraw =
             fColorDepthBoundsManager->getMostRecentDraw(clip.drawBounds());
     if (dependsOnDst) {
diff --git a/src/gpu/graphite/Renderer.h b/src/gpu/graphite/Renderer.h
index c7ce773..7cbb7cd 100644
--- a/src/gpu/graphite/Renderer.h
+++ b/src/gpu/graphite/Renderer.h
@@ -31,6 +31,7 @@
 namespace skgpu { enum class MaskFormat; }
 
 namespace skgpu::graphite {
+
 class DrawWriter;
 class DrawParams;
 class ResourceProvider;
@@ -62,10 +63,6 @@
     // UniformCache handles making an sk_sp if we need to assign a new unique ID to the uniform data
     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.
-    const char* name() const { return fName.c_str(); }
-
     // TODO: This is only temporary. Eventually the RenderStep will define its logic in SkSL and
     // be able to have code operate in both the vertex and fragment shaders. Ideally the RenderStep
     // will provide two functions that fit some ABI for integrating with the common and paint SkSL,
@@ -83,13 +80,30 @@
     // and then including the function bodies returned here.
     virtual const char* vertexSkSL() const = 0;
 
-    bool          requiresMSAA()    const { return fFlags & Flags::kRequiresMSAA;      }
-    bool          performsShading() const { return fFlags & Flags::kPerformsShading;   }
-    bool          hasTextures()     const { return fFlags & Flags::kHasTextures; }
+    // 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.
+    const char* name() const { return fName.c_str(); }
 
-    PrimitiveType primitiveType()   const { return fPrimitiveType;  }
-    size_t        vertexStride()    const { return fVertexStride;   }
-    size_t        instanceStride()  const { return fInstanceStride; }
+    bool requiresMSAA()    const { return fFlags & Flags::kRequiresMSAA;    }
+    bool performsShading() const { return fFlags & Flags::kPerformsShading; }
+    bool hasTextures()     const { return fFlags & Flags::kHasTextures;     }
+    bool emitsCoverage()   const { return fFlags & Flags::kEmitsCoverage;   }
+
+    PrimitiveType primitiveType()  const { return fPrimitiveType;  }
+    size_t        vertexStride()   const { return fVertexStride;   }
+    size_t        instanceStride() const { return fInstanceStride; }
+
+    size_t numUniforms()           const { return fUniforms.size();      }
+    size_t numVertexAttributes()   const { return fVertexAttrs.size();   }
+    size_t numInstanceAttributes() const { return fInstanceAttrs.size(); }
+    size_t numVaryings()           const { return fVaryings.size();      }
+
+    // The uniforms of a RenderStep are bound to the kRenderStep slot, the rest of the pipeline
+    // may still use uniforms bound to other slots.
+    SkSpan<const SkUniform> uniforms()           const { return SkSpan(fUniforms);      }
+    SkSpan<const Attribute> vertexAttributes()   const { return SkSpan(fVertexAttrs);   }
+    SkSpan<const Attribute> instanceAttributes() const { return SkSpan(fInstanceAttrs); }
+    SkSpan<const Varying>   varyings()           const { return SkSpan(fVaryings);      }
 
     const DepthStencilSettings& depthStencilSettings() const { return fDepthStencilSettings; }
 
@@ -99,19 +113,6 @@
                (fDepthStencilSettings.fDepthTestEnabled || fDepthStencilSettings.fDepthWriteEnabled
                         ? DepthStencilFlags::kDepth : DepthStencilFlags::kNone);
     }
-
-    size_t numUniforms()            const { return fUniforms.size();      }
-    size_t numVertexAttributes()    const { return fVertexAttrs.size();   }
-    size_t numInstanceAttributes()  const { return fInstanceAttrs.size(); }
-    size_t numVaryings()            const { return fVaryings.size(); }
-
-    // The uniforms of a RenderStep are bound to the kRenderStep slot, the rest of the pipeline
-    // may still use uniforms bound to other slots.
-    SkSpan<const SkUniform> uniforms()           const { return SkSpan(fUniforms);      }
-    SkSpan<const Attribute> vertexAttributes()   const { return SkSpan(fVertexAttrs);   }
-    SkSpan<const Attribute> instanceAttributes() const { return SkSpan(fInstanceAttrs); }
-    SkSpan<const Varying>   varyings()           const { return SkSpan(fVaryings);      }
-
     // TODO: Actual API to do things
     // 6. Some Renderers benefit from being able to share vertices between RenderSteps. Must find a
     //    way to support that. It may mean that RenderSteps get state per draw.
@@ -119,13 +120,13 @@
     //    - Does DrawList->DrawPass conversion build a separate array of blind data that the
     //      stateless Renderstep can refer to for {draw,step} pairs?
     //    - Does each DrawList::Draw have extra space (e.g. 8 bytes) that steps can cache data in?
-    // 7. Painter's order for the draw sent as uniform or attribute
 protected:
     enum class Flags : unsigned {
-        kNone            = 0b000,
-        kRequiresMSAA    = 0b001,
-        kPerformsShading = 0b010,
-        kHasTextures     = 0b100,
+        kNone            = 0b0000,
+        kRequiresMSAA    = 0b0001,
+        kPerformsShading = 0b0010,
+        kHasTextures     = 0b0100,
+        kEmitsCoverage   = 0b1000,
     };
     SK_DECL_BITMASK_OPS_FRIENDS(Flags);
 
@@ -225,7 +226,7 @@
 
     static const Renderer& TextSDF(bool useLCDText);
 
-    // TODO: Add renderers for primitives (rect, rrect, etc.), special draws (atlas, vertices, text)
+    // TODO: Add renderers for primitives (rect, rrect, etc.), special draws (atlas)
     // and support inverse filled strokes.
 
     // The maximum number of render steps that any Renderer is allowed to have.
@@ -235,9 +236,10 @@
         return {&fSteps.front(), static_cast<size_t>(fStepCount) };
     }
 
-    const char* name()            const { return fName.c_str();    }
-    int         numRenderSteps()  const { return fStepCount;       }
-    bool        requiresMSAA()    const { return fRequiresMSAA;    }
+    const char* name()           const { return fName.c_str();  }
+    int         numRenderSteps() const { return fStepCount;     }
+    bool        requiresMSAA()   const { return fRequiresMSAA;  }
+    bool        emitsCoverage()  const { return fEmitsCoverage; }
 
     SkEnumBitMask<DepthStencilFlags> depthStencilFlags() const { return fDepthStencilFlags; }
 
@@ -265,6 +267,7 @@
         for (int i = 0 ; i < fStepCount; ++i) {
             fSteps[i] = steps[i];
             fRequiresMSAA |= fSteps[i]->requiresMSAA();
+            fEmitsCoverage |= fSteps[i]->emitsCoverage();
             fDepthStencilFlags |= fSteps[i]->depthStencilFlags();
             SkDEBUGCODE(performsShading |= fSteps[i]->performsShading());
         }
@@ -280,6 +283,7 @@
     SkString fName;
     int      fStepCount;
     bool     fRequiresMSAA = false;
+    bool     fEmitsCoverage = false;
 
     SkEnumBitMask<DepthStencilFlags> fDepthStencilFlags = DepthStencilFlags::kNone;
 };
diff --git a/src/gpu/graphite/render/TextDirectRenderStep.cpp b/src/gpu/graphite/render/TextDirectRenderStep.cpp
index cea76fa..6addbb2 100644
--- a/src/gpu/graphite/render/TextDirectRenderStep.cpp
+++ b/src/gpu/graphite/render/TextDirectRenderStep.cpp
@@ -35,7 +35,7 @@
 TextDirectRenderStep::TextDirectRenderStep()
         : RenderStep("TextDirectRenderStep",
                      "",
-                     Flags::kPerformsShading | Flags::kHasTextures,
+                     Flags::kPerformsShading | Flags::kHasTextures | Flags::kEmitsCoverage,
                      /*uniforms=*/{{"atlasSizeInv", SkSLType::kFloat2}},
                      PrimitiveType::kTriangles,
                      kDirectShadingPass,
diff --git a/src/gpu/graphite/render/TextSDFRenderStep.cpp b/src/gpu/graphite/render/TextSDFRenderStep.cpp
index 14dcdb5..eee0f86 100644
--- a/src/gpu/graphite/render/TextSDFRenderStep.cpp
+++ b/src/gpu/graphite/render/TextSDFRenderStep.cpp
@@ -30,7 +30,7 @@
 TextSDFRenderStep::TextSDFRenderStep(bool isA8)
         : RenderStep("TextSDFRenderStep",
                      isA8 ? "A8" : "565",
-                     Flags::kPerformsShading,
+                     Flags::kPerformsShading | Flags::kEmitsCoverage,
                      /*uniforms=*/{{"atlasSizeInv", SkSLType::kFloat2},
                                    {"distanceAdjust", SkSLType::kFloat}},
                      PrimitiveType::kTriangles,