Always attach stencil buffers with exact sample count matches

After this CL we will always attach a stencil buffer for rendering
that matches the stencil sample count of the proxy. We will even
downgrade a stencil attachment to one with less samples if necessary.
(In the past we would only guarantee that the attached stencil buffer
had a sample count >= to that of the proxy.)

Change-Id: I358e13ffdf286695257b1b5b672a84d16c417b80
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/253547
Commit-Queue: Chris Dalton <csmartdalton@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/GrResourceProvider.cpp b/src/gpu/GrResourceProvider.cpp
index 4139d0f..5434c5d 100644
--- a/src/gpu/GrResourceProvider.cpp
+++ b/src/gpu/GrResourceProvider.cpp
@@ -481,10 +481,10 @@
     return buffer;
 }
 
-bool GrResourceProvider::attachStencilAttachment(GrRenderTarget* rt, int minStencilSampleCount) {
+bool GrResourceProvider::attachStencilAttachment(GrRenderTarget* rt, int numStencilSamples) {
     SkASSERT(rt);
     GrStencilAttachment* stencil = rt->renderTargetPriv().getStencilAttachment();
-    if (stencil && stencil->numSamples() >= minStencilSampleCount) {
+    if (stencil && stencil->numSamples() == numStencilSamples) {
         return true;
     }
 
@@ -500,12 +500,12 @@
         }
 #endif
         GrStencilAttachment::ComputeSharedStencilAttachmentKey(
-                width, height, minStencilSampleCount, &sbKey);
+                width, height, numStencilSamples, &sbKey);
         auto stencil = this->findByUniqueKey<GrStencilAttachment>(sbKey);
         if (!stencil) {
             // Need to try and create a new stencil
             stencil.reset(this->gpu()->createStencilAttachmentForRenderTarget(
-                    rt, width, height, minStencilSampleCount));
+                    rt, width, height, numStencilSamples));
             if (!stencil) {
                 return false;
             }
@@ -515,7 +515,7 @@
     }
 
     if (GrStencilAttachment* stencil = rt->renderTargetPriv().getStencilAttachment()) {
-        return stencil->numSamples() >= minStencilSampleCount;
+        return stencil->numSamples() == numStencilSamples;
     }
     return false;
 }