Make GrRenderTargetContext::addDrawOp use sk_sp

Change-Id: Iff7f63635cdbc5cc51e5968a565f2fde2be3acb0
Reviewed-on: https://skia-review.googlesource.com/5932
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp
index a40473f..1a1f6a5 100644
--- a/src/gpu/GrRenderTargetContext.cpp
+++ b/src/gpu/GrRenderTargetContext.cpp
@@ -744,7 +744,7 @@
         sk_sp<GrDrawOp> op(GrAAFillRectBatch::CreateWithLocalRect(paint.getColor(), viewMatrix,
                                                                   croppedRect, croppedLocalRect));
         GrPipelineBuilder pipelineBuilder(paint, aaType);
-        this->addDrawOp(pipelineBuilder, clip, op.get());
+        this->addDrawOp(pipelineBuilder, clip, std::move(op));
         return;
     }
 
@@ -1584,11 +1584,11 @@
 }
 
 void GrRenderTargetContext::addDrawOp(const GrPipelineBuilder& pipelineBuilder, const GrClip& clip,
-                                      GrDrawOp* op) {
+                                      sk_sp<GrDrawOp> op) {
     ASSERT_SINGLE_OWNER
     RETURN_IF_ABANDONED
     SkDEBUGCODE(this->validate();)
     GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrRenderTargetContext::addDrawOp");
 
-    this->getOpList()->addDrawOp(pipelineBuilder, this, clip, sk_ref_sp(op));
+    this->getOpList()->addDrawOp(pipelineBuilder, this, clip, std::move(op));
 }
diff --git a/src/gpu/GrSWMaskHelper.cpp b/src/gpu/GrSWMaskHelper.cpp
index 7351ecd..6bbb3bd 100644
--- a/src/gpu/GrSWMaskHelper.cpp
+++ b/src/gpu/GrSWMaskHelper.cpp
@@ -192,7 +192,7 @@
                                                      maskMatrix,
                                                      GrSamplerParams::kNone_FilterMode));
 
-    sk_sp<GrDrawOp> batch(GrRectBatchFactory::CreateNonAAFill(paint.getColor(), SkMatrix::I(),
-                                                              dstRect, nullptr, &invert));
-    renderTargetContext->addDrawOp(pipelineBuilder, clip, batch.get());
+    sk_sp<GrDrawOp> op(GrRectBatchFactory::CreateNonAAFill(paint.getColor(), SkMatrix::I(), dstRect,
+                                                           nullptr, &invert));
+    renderTargetContext->addDrawOp(pipelineBuilder, clip, std::move(op));
 }
diff --git a/src/gpu/GrSoftwarePathRenderer.cpp b/src/gpu/GrSoftwarePathRenderer.cpp
index 73080a6..cb3f679 100644
--- a/src/gpu/GrSoftwarePathRenderer.cpp
+++ b/src/gpu/GrSoftwarePathRenderer.cpp
@@ -68,13 +68,12 @@
                                            const SkMatrix& viewMatrix,
                                            const SkRect& rect,
                                            const SkMatrix& localMatrix) {
-    sk_sp<GrDrawOp> batch(GrRectBatchFactory::CreateNonAAFill(paint.getColor(),
-                                                              viewMatrix, rect,
-                                                              nullptr, &localMatrix));
+    sk_sp<GrDrawOp> op(GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewMatrix, rect,
+                                                           nullptr, &localMatrix));
 
     GrPipelineBuilder pipelineBuilder(paint, GrAAType::kNone);
     pipelineBuilder.setUserStencil(&userStencilSettings);
-    renderTargetContext->addDrawOp(pipelineBuilder, clip, batch.get());
+    renderTargetContext->addDrawOp(pipelineBuilder, clip, std::move(op));
 }
 
 void GrSoftwarePathRenderer::DrawAroundInvPath(GrRenderTargetContext* renderTargetContext,
diff --git a/src/gpu/batches/GrAAConvexPathRenderer.cpp b/src/gpu/batches/GrAAConvexPathRenderer.cpp
index cc31f49..69b99fd 100644
--- a/src/gpu/batches/GrAAConvexPathRenderer.cpp
+++ b/src/gpu/batches/GrAAConvexPathRenderer.cpp
@@ -1000,12 +1000,12 @@
     SkPath path;
     args.fShape->asPath(&path);
 
-    sk_sp<GrDrawOp> batch(new AAConvexPathBatch(args.fPaint->getColor(), *args.fViewMatrix, path));
+    sk_sp<GrDrawOp> op(new AAConvexPathBatch(args.fPaint->getColor(), *args.fViewMatrix, path));
 
     GrPipelineBuilder pipelineBuilder(*args.fPaint, args.fAAType);
     pipelineBuilder.setUserStencil(args.fUserStencilSettings);
 
-    args.fRenderTargetContext->addDrawOp(pipelineBuilder, *args.fClip, batch.get());
+    args.fRenderTargetContext->addDrawOp(pipelineBuilder, *args.fClip, std::move(op));
 
     return true;
 
diff --git a/src/gpu/batches/GrAADistanceFieldPathRenderer.cpp b/src/gpu/batches/GrAADistanceFieldPathRenderer.cpp
index 71b9000..738d1c8 100644
--- a/src/gpu/batches/GrAADistanceFieldPathRenderer.cpp
+++ b/src/gpu/batches/GrAADistanceFieldPathRenderer.cpp
@@ -530,14 +530,13 @@
         }
     }
 
-    sk_sp<GrDrawOp> batch(new AADistanceFieldPathBatch(args.fPaint->getColor(),
-                                                       *args.fShape, *args.fViewMatrix,
-                                                       fAtlas.get(), &fShapeCache, &fShapeList,
-                                                       args.fGammaCorrect));
+    sk_sp<GrDrawOp> op(new AADistanceFieldPathBatch(args.fPaint->getColor(), *args.fShape,
+                                                    *args.fViewMatrix, fAtlas.get(), &fShapeCache,
+                                                    &fShapeList, args.fGammaCorrect));
     GrPipelineBuilder pipelineBuilder(*args.fPaint, args.fAAType);
     pipelineBuilder.setUserStencil(args.fUserStencilSettings);
 
-    args.fRenderTargetContext->addDrawOp(pipelineBuilder, *args.fClip, batch.get());
+    args.fRenderTargetContext->addDrawOp(pipelineBuilder, *args.fClip, std::move(op));
 
     return true;
 }
diff --git a/src/gpu/batches/GrAAHairLinePathRenderer.cpp b/src/gpu/batches/GrAAHairLinePathRenderer.cpp
index 732d694..29231cd 100644
--- a/src/gpu/batches/GrAAHairLinePathRenderer.cpp
+++ b/src/gpu/batches/GrAAHairLinePathRenderer.cpp
@@ -977,13 +977,12 @@
 
     SkPath path;
     args.fShape->asPath(&path);
-    sk_sp<GrDrawOp> batch(create_hairline_batch(args.fPaint->getColor(),
-                                                *args.fViewMatrix, path,
-                                                args.fShape->style(), devClipBounds));
+    sk_sp<GrDrawOp> op(create_hairline_batch(args.fPaint->getColor(), *args.fViewMatrix, path,
+                                             args.fShape->style(), devClipBounds));
 
     GrPipelineBuilder pipelineBuilder(*args.fPaint, args.fAAType);
     pipelineBuilder.setUserStencil(args.fUserStencilSettings);
-    args.fRenderTargetContext->addDrawOp(pipelineBuilder, *args.fClip, batch.get());
+    args.fRenderTargetContext->addDrawOp(pipelineBuilder, *args.fClip, std::move(op));
 
     return true;
 }
diff --git a/src/gpu/batches/GrAALinearizingConvexPathRenderer.cpp b/src/gpu/batches/GrAALinearizingConvexPathRenderer.cpp
index cbf526c..dc1cd8a 100644
--- a/src/gpu/batches/GrAALinearizingConvexPathRenderer.cpp
+++ b/src/gpu/batches/GrAALinearizingConvexPathRenderer.cpp
@@ -355,16 +355,14 @@
     SkPaint::Join join = fill ? SkPaint::Join::kMiter_Join : stroke.getJoin();
     SkScalar miterLimit = stroke.getMiter();
 
-    sk_sp<GrDrawOp> batch(new AAFlatteningConvexPathBatch(args.fPaint->getColor(),
-                                                          *args.fViewMatrix,
-                                                          path, strokeWidth,
-                                                          stroke.getStyle(),
-                                                          join, miterLimit));
+    sk_sp<GrDrawOp> op(new AAFlatteningConvexPathBatch(args.fPaint->getColor(), *args.fViewMatrix,
+                                                       path, strokeWidth, stroke.getStyle(), join,
+                                                       miterLimit));
 
     GrPipelineBuilder pipelineBuilder(*args.fPaint, args.fAAType);
     pipelineBuilder.setUserStencil(args.fUserStencilSettings);
 
-    args.fRenderTargetContext->addDrawOp(pipelineBuilder, *args.fClip, batch.get());
+    args.fRenderTargetContext->addDrawOp(pipelineBuilder, *args.fClip, std::move(op));
 
     return true;
 }
diff --git a/src/gpu/batches/GrDashLinePathRenderer.cpp b/src/gpu/batches/GrDashLinePathRenderer.cpp
index 9304885..1bda9d5 100644
--- a/src/gpu/batches/GrDashLinePathRenderer.cpp
+++ b/src/gpu/batches/GrDashLinePathRenderer.cpp
@@ -45,18 +45,15 @@
     }
     SkPoint pts[2];
     SkAssertResult(args.fShape->asLine(pts, nullptr));
-    sk_sp<GrDrawOp> batch(GrDashingEffect::CreateDashLineBatch(args.fPaint->getColor(),
-                                                               *args.fViewMatrix,
-                                                               pts,
-                                                               aaMode,
-                                                               args.fShape->style()));
-    if (!batch) {
+    sk_sp<GrDrawOp> op(GrDashingEffect::CreateDashLineBatch(
+            args.fPaint->getColor(), *args.fViewMatrix, pts, aaMode, args.fShape->style()));
+    if (!op) {
         return false;
     }
 
     GrPipelineBuilder pipelineBuilder(*args.fPaint, args.fAAType);
     pipelineBuilder.setUserStencil(args.fUserStencilSettings);
 
-    args.fRenderTargetContext->addDrawOp(pipelineBuilder, *args.fClip, batch.get());
+    args.fRenderTargetContext->addDrawOp(pipelineBuilder, *args.fClip, std::move(op));
     return true;
 }
diff --git a/src/gpu/batches/GrDefaultPathRenderer.cpp b/src/gpu/batches/GrDefaultPathRenderer.cpp
index 0b688c5..d4f3481 100644
--- a/src/gpu/batches/GrDefaultPathRenderer.cpp
+++ b/src/gpu/batches/GrDefaultPathRenderer.cpp
@@ -564,26 +564,25 @@
             }
             const SkMatrix& viewM = (reverse && viewMatrix.hasPerspective()) ? SkMatrix::I() :
                                                                                viewMatrix;
-            sk_sp<GrDrawOp> batch(
-                    GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewM, bounds, nullptr,
-                                                        &localMatrix));
+            sk_sp<GrDrawOp> op(GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewM, bounds,
+                                                                   nullptr, &localMatrix));
 
             SkASSERT(GrDrawFace::kBoth == drawFace[p]);
             GrPipelineBuilder pipelineBuilder(paint, aaType);
             pipelineBuilder.setDrawFace(drawFace[p]);
             pipelineBuilder.setUserStencil(passes[p]);
-            renderTargetContext->addDrawOp(pipelineBuilder, clip, batch.get());
+            renderTargetContext->addDrawOp(pipelineBuilder, clip, std::move(op));
         } else {
-            sk_sp<GrDrawOp> batch(new DefaultPathBatch(paint.getColor(), path, srcSpaceTol,
-                                                       newCoverage, viewMatrix, isHairline,
-                                                       devBounds));
+            sk_sp<GrDrawOp> op(new DefaultPathBatch(paint.getColor(), path, srcSpaceTol,
+                                                    newCoverage, viewMatrix, isHairline,
+                                                    devBounds));
             GrPipelineBuilder pipelineBuilder(paint, aaType);
             pipelineBuilder.setDrawFace(drawFace[p]);
             pipelineBuilder.setUserStencil(passes[p]);
             if (passCount > 1) {
                 pipelineBuilder.setDisableColorXPFactory();
             }
-            renderTargetContext->addDrawOp(pipelineBuilder, clip, batch.get());
+            renderTargetContext->addDrawOp(pipelineBuilder, clip, std::move(op));
         }
     }
     return true;
diff --git a/src/gpu/batches/GrMSAAPathRenderer.cpp b/src/gpu/batches/GrMSAAPathRenderer.cpp
index 930f7f9..84017d6 100644
--- a/src/gpu/batches/GrMSAAPathRenderer.cpp
+++ b/src/gpu/batches/GrMSAAPathRenderer.cpp
@@ -659,18 +659,17 @@
             }
             const SkMatrix& viewM = (reverse && viewMatrix.hasPerspective()) ? SkMatrix::I() :
                                                                                viewMatrix;
-            sk_sp<GrDrawOp> batch(
-                    GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewM, bounds, nullptr,
-                                                        &localMatrix));
+            sk_sp<GrDrawOp> op(GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewM, bounds,
+                                                                   nullptr, &localMatrix));
 
             GrPipelineBuilder pipelineBuilder(paint, aaType);
             pipelineBuilder.setUserStencil(passes[p]);
 
-            renderTargetContext->addDrawOp(pipelineBuilder, clip, batch.get());
+            renderTargetContext->addDrawOp(pipelineBuilder, clip, std::move(op));
         } else {
-            sk_sp<MSAAPathBatch> batch(new MSAAPathBatch(paint.getColor(), path,
-                                                         viewMatrix, devBounds));
-            if (!batch->isValid()) {
+            sk_sp<MSAAPathBatch> op(
+                    new MSAAPathBatch(paint.getColor(), path, viewMatrix, devBounds));
+            if (!op->isValid()) {
                 return false;
             }
 
@@ -679,7 +678,7 @@
             if (passCount > 1) {
                 pipelineBuilder.setDisableColorXPFactory();
             }
-            renderTargetContext->addDrawOp(pipelineBuilder, clip, batch.get());
+            renderTargetContext->addDrawOp(pipelineBuilder, clip, std::move(op));
         }
     }
     return true;
diff --git a/src/gpu/batches/GrPLSPathRenderer.cpp b/src/gpu/batches/GrPLSPathRenderer.cpp
index 269fde1..ae6485f 100644
--- a/src/gpu/batches/GrPLSPathRenderer.cpp
+++ b/src/gpu/batches/GrPLSPathRenderer.cpp
@@ -935,11 +935,11 @@
     SkPath path;
     args.fShape->asPath(&path);
 
-    sk_sp<GrDrawOp> batch(new PLSPathBatch(args.fPaint->getColor(), path, *args.fViewMatrix));
+    sk_sp<GrDrawOp> op(new PLSPathBatch(args.fPaint->getColor(), path, *args.fViewMatrix));
     GrPipelineBuilder pipelineBuilder(*args.fPaint, args.fAAType);
     pipelineBuilder.setUserStencil(args.fUserStencilSettings);
 
-    args.fRenderTargetContext->addDrawOp(pipelineBuilder, *args.fClip, batch.get());
+    args.fRenderTargetContext->addDrawOp(pipelineBuilder, *args.fClip, std::move(op));
     SkDEBUGCODE(inPLSDraw = false;)
     return true;
 
diff --git a/src/gpu/batches/GrStencilAndCoverPathRenderer.cpp b/src/gpu/batches/GrStencilAndCoverPathRenderer.cpp
index ac9ed90..a4318b7 100644
--- a/src/gpu/batches/GrStencilAndCoverPathRenderer.cpp
+++ b/src/gpu/batches/GrStencilAndCoverPathRenderer.cpp
@@ -113,9 +113,8 @@
         }
         const SkMatrix& viewM = viewMatrix.hasPerspective() ? SkMatrix::I() : viewMatrix;
 
-        sk_sp<GrDrawOp> coverBatch(
-                GrRectBatchFactory::CreateNonAAFill(args.fPaint->getColor(), viewM, bounds,
-                                                    nullptr, &invert));
+        sk_sp<GrDrawOp> coverOp(GrRectBatchFactory::CreateNonAAFill(args.fPaint->getColor(), viewM,
+                                                                    bounds, nullptr, &invert));
 
         // fake inverse with a stencil and cover
         args.fRenderTargetContext->priv().stencilPath(*args.fClip, args.fAAType, viewMatrix,
@@ -143,7 +142,7 @@
             GrPipelineBuilder pipelineBuilder(*args.fPaint, coverAAType);
             pipelineBuilder.setUserStencil(&kInvertedCoverPass);
 
-            args.fRenderTargetContext->addDrawOp(pipelineBuilder, *args.fClip, coverBatch.get());
+            args.fRenderTargetContext->addDrawOp(pipelineBuilder, *args.fClip, std::move(coverOp));
         }
     } else {
         static constexpr GrUserStencilSettings kCoverPass(
@@ -156,12 +155,12 @@
                 0xffff>()
         );
 
-        sk_sp<GrDrawOp> batch(GrDrawPathBatch::Create(viewMatrix, args.fPaint->getColor(),
-                                                      path.get()));
+        sk_sp<GrDrawOp> op(
+                GrDrawPathBatch::Create(viewMatrix, args.fPaint->getColor(), path.get()));
 
         GrPipelineBuilder pipelineBuilder(*args.fPaint, args.fAAType);
         pipelineBuilder.setUserStencil(&kCoverPass);
-        args.fRenderTargetContext->addDrawOp(pipelineBuilder, *args.fClip, batch.get());
+        args.fRenderTargetContext->addDrawOp(pipelineBuilder, *args.fClip, std::move(op));
     }
 
     return true;
diff --git a/src/gpu/batches/GrTessellatingPathRenderer.cpp b/src/gpu/batches/GrTessellatingPathRenderer.cpp
index 4b3ef00..f2616e4 100644
--- a/src/gpu/batches/GrTessellatingPathRenderer.cpp
+++ b/src/gpu/batches/GrTessellatingPathRenderer.cpp
@@ -360,14 +360,14 @@
     args.fClip->getConservativeBounds(args.fRenderTargetContext->width(),
                                       args.fRenderTargetContext->height(),
                                       &clipBoundsI);
-    sk_sp<GrDrawOp> batch(TessellatingPathBatch::Create(args.fPaint->getColor(),
-                                                        *args.fShape,
-                                                        *args.fViewMatrix,
-                                                        clipBoundsI,
-                                                        GrAAType::kCoverage == args.fAAType));
+    sk_sp<GrDrawOp> op(TessellatingPathBatch::Create(args.fPaint->getColor(),
+                                                     *args.fShape,
+                                                     *args.fViewMatrix,
+                                                     clipBoundsI,
+                                                     GrAAType::kCoverage == args.fAAType));
     GrPipelineBuilder pipelineBuilder(*args.fPaint, args.fAAType);
     pipelineBuilder.setUserStencil(args.fUserStencilSettings);
-    args.fRenderTargetContext->addDrawOp(pipelineBuilder, *args.fClip, batch.get());
+    args.fRenderTargetContext->addDrawOp(pipelineBuilder, *args.fClip, std::move(op));
     return true;
 }
 
diff --git a/src/gpu/text/GrAtlasTextBlob.cpp b/src/gpu/text/GrAtlasTextBlob.cpp
index 1fb4f2c..c5fa86f 100644
--- a/src/gpu/text/GrAtlasTextBlob.cpp
+++ b/src/gpu/text/GrAtlasTextBlob.cpp
@@ -317,15 +317,12 @@
 
         GrColor color = grPaint.getColor();
 
-        sk_sp<GrDrawOp> batch(this->createBatch(info, glyphCount, run,
-                                                subRun, viewMatrix, x, y, color,
-                                                skPaint, props,
-                                                distanceAdjustTable,
-                                                rtc->isGammaCorrect(),
-                                                cache));
+        sk_sp<GrDrawOp> op(this->createBatch(info, glyphCount, run, subRun, viewMatrix, x, y, color,
+                                             skPaint, props, distanceAdjustTable,
+                                             rtc->isGammaCorrect(), cache));
         GrPipelineBuilder pipelineBuilder(grPaint, GrAAType::kNone);
 
-        rtc->addDrawOp(pipelineBuilder, clip, batch.get());
+        rtc->addDrawOp(pipelineBuilder, clip, std::move(op));
     }
 }
 
diff --git a/src/gpu/text/GrStencilAndCoverTextContext.cpp b/src/gpu/text/GrStencilAndCoverTextContext.cpp
index b573b83..50ca192 100644
--- a/src/gpu/text/GrStencilAndCoverTextContext.cpp
+++ b/src/gpu/text/GrStencilAndCoverTextContext.cpp
@@ -633,11 +633,10 @@
         const SkRect bounds = SkRect::MakeIWH(renderTargetContext->width(),
                                               renderTargetContext->height());
 
-        sk_sp<GrDrawOp> batch(
-            GrDrawPathRangeBatch::Create(viewMatrix, fTextRatio, fTextInverseRatio * x,
-                                         fTextInverseRatio * y, grPaint.getColor(),
-                                         GrPathRendering::kWinding_FillType, glyphs.get(),
-                                         fInstanceData.get(), bounds));
+        sk_sp<GrDrawOp> op(GrDrawPathRangeBatch::Create(
+                viewMatrix, fTextRatio, fTextInverseRatio * x, fTextInverseRatio * y,
+                grPaint.getColor(), GrPathRendering::kWinding_FillType, glyphs.get(),
+                fInstanceData.get(), bounds));
 
         // The run's "font" overrides the anti-aliasing of the passed in SkPaint!
         GrAAType aaType = GrAAType::kNone;
@@ -651,7 +650,7 @@
         GrPipelineBuilder pipelineBuilder(grPaint, aaType);
         pipelineBuilder.setUserStencil(&kCoverPass);
 
-        renderTargetContext->addDrawOp(pipelineBuilder, clip, batch.get());
+        renderTargetContext->addDrawOp(pipelineBuilder, clip, std::move(op));
     }
 
     if (fFallbackTextBlob) {