Separate user and raw stencil settings

Adds a new GrUserStencilSettings class that describes in abstract terms
how a draw will use the stencil (e.g. kAlwaysIfInClip, kSetClipBit,
etc.). GrPipelineBuilder now only defines the GrUserStencilSettings.
When the GrPipeline is finalized, the user stencil settings are then
translated into concrete GrStencilSettings.

At this point, GrClipMaskManager only needs to tell the GrAppliedClip
whether or not there is a stencil clip. It does not need to modify
stencil settings and GrPipelineBuilder does not need
AutoRestoreStencil.

This is one step of the stencil overhaul. In the future it will also
allow us to clean up the special case handling for nvpr and the
stateful fClipMode member of GrClipMaskManager.

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1962243002

Committed: https://skia.googlesource.com/skia/+/12dbb3947e1aaf205b4fcf13b40e54e50650eb37

Review-Url: https://codereview.chromium.org/1962243002
diff --git a/src/gpu/batches/GrStencilAndCoverPathRenderer.cpp b/src/gpu/batches/GrStencilAndCoverPathRenderer.cpp
index ddba1c8..1309ded 100644
--- a/src/gpu/batches/GrStencilAndCoverPathRenderer.cpp
+++ b/src/gpu/batches/GrStencilAndCoverPathRenderer.cpp
@@ -36,7 +36,7 @@
     if (args.fStyle->hasNonDashPathEffect() || args.fStyle->strokeRec().isHairlineStyle()) {
         return false;
     }
-    if (!args.fIsStencilDisabled) {
+    if (args.fHasUserStencilSettings) {
         return false;
     }
     if (args.fAntiAlias) {
@@ -80,7 +80,7 @@
     GrPipelineBuilder* pipelineBuilder = args.fPipelineBuilder;
     const SkMatrix& viewMatrix = *args.fViewMatrix;
 
-    SkASSERT(pipelineBuilder->getStencil().isDisabled());
+    SkASSERT(!pipelineBuilder->hasUserStencilSettings());
 
     if (args.fAntiAlias) {
         SkASSERT(pipelineBuilder->getRenderTarget()->isStencilBufferMultisampled());
@@ -90,18 +90,21 @@
     SkAutoTUnref<GrPath> p(get_gr_path(fResourceProvider, path, *args.fStyle));
 
     if (path.isInverseFillType()) {
-        static constexpr GrStencilSettings kInvertedStencilPass(
-            kKeep_StencilOp,
-            kZero_StencilOp,
-            // We know our rect will hit pixels outside the clip and the user bits will be 0
-            // outside the clip. So we can't just fill where the user bits are 0. We also need to
-            // check that the clip bit is set.
-            kEqualIfInClip_StencilFunc,
-            0xffff,
-            0x0000,
-            0xffff);
+        static constexpr GrUserStencilSettings kInvertedCoverPass(
+            GrUserStencilSettings::StaticInit<
+                0x0000,
+                // We know our rect will hit pixels outside the clip and the user bits will be 0
+                // outside the clip. So we can't just fill where the user bits are 0. We also need
+                // to check that the clip bit is set.
+                GrUserStencilTest::kEqualIfInClip,
+                0xffff,
+                GrUserStencilOp::kKeep,
+                GrUserStencilOp::kZero,
+                0xffff>()
+        );
 
-        pipelineBuilder->setStencil(kInvertedStencilPass);
+
+        pipelineBuilder->setUserStencil(&kInvertedCoverPass);
 
         // fake inverse with a stencil and cover
         args.fTarget->stencilPath(*pipelineBuilder, viewMatrix, p, p->getFillType());
@@ -133,20 +136,22 @@
                                                     &invert));
         args.fTarget->drawBatch(*pipelineBuilder, batch);
     } else {
-        static constexpr GrStencilSettings kStencilPass(
-            kZero_StencilOp,
-            kKeep_StencilOp,
-            kNotEqual_StencilFunc,
-            0xffff,
-            0x0000,
-            0xffff);
+        static constexpr GrUserStencilSettings kCoverPass(
+            GrUserStencilSettings::StaticInit<
+                0x0000,
+                GrUserStencilTest::kNotEqual,
+                0xffff,
+                GrUserStencilOp::kZero,
+                GrUserStencilOp::kKeep,
+                0xffff>()
+        );
 
-        pipelineBuilder->setStencil(kStencilPass);
+        pipelineBuilder->setUserStencil(&kCoverPass);
         SkAutoTUnref<GrDrawPathBatchBase> batch(
                 GrDrawPathBatch::Create(viewMatrix, args.fColor, p->getFillType(), p));
         args.fTarget->drawPathBatch(*pipelineBuilder, batch);
     }
 
-    pipelineBuilder->stencil()->setDisabled();
+    pipelineBuilder->disableUserStencil();
     return true;
 }