SaveLayerRec::fClipMask -> raw pointer

Use raw pointers for optional clip mask plumbing, to match the backdrop
API.

Change-Id: I7eb0ee5896faf34cc05789ba0703f35a4ab6a4f2
Reviewed-on: https://skia-review.googlesource.com/14901
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Florin Malita <fmalita@chromium.org>
diff --git a/gm/savelayer.cpp b/gm/savelayer.cpp
index 245785e..dd7ff7b 100644
--- a/gm/savelayer.cpp
+++ b/gm/savelayer.cpp
@@ -210,8 +210,8 @@
         rec.fPaint = &layerPaint;
 
         for (const auto& maskMaker : kMaskMakers) {
-            maskMaker(kSize);
-            rec.fClipMask = maskMaker(kSize);
+            sk_sp<SkImage> mask = maskMaker(kSize);
+            rec.fClipMask = mask.get();
 
             canvas->save();
             for (const auto cfg : kConfigs) {
diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h
index 197fad8..06e2620 100644
--- a/include/core/SkCanvas.h
+++ b/include/core/SkCanvas.h
@@ -336,8 +336,10 @@
             , fBackdrop(backdrop)
             , fSaveLayerFlags(saveLayerFlags)
         {}
+
+        // EXPERIMENTAL: not ready for general use.
         SaveLayerRec(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop,
-                     sk_sp<SkImage> clipMask, const SkMatrix* clipMatrix,
+                     const SkImage* clipMask, const SkMatrix* clipMatrix,
                      SaveLayerFlags saveLayerFlags)
             : fBounds(bounds)
             , fPaint(paint)
@@ -350,7 +352,7 @@
         const SkRect*           fBounds = nullptr;      // optional
         const SkPaint*          fPaint = nullptr;       // optional
         const SkImageFilter*    fBackdrop = nullptr;    // optional
-        sk_sp<SkImage>          fClipMask;              // optional
+        const SkImage*          fClipMask = nullptr;    // optional
         const SkMatrix*         fClipMatrix = nullptr;  // optional -- only used with fClipMask
         SaveLayerFlags          fSaveLayerFlags = 0;
     };
diff --git a/include/private/SkRecords.h b/include/private/SkRecords.h
index f1886f3..4d7b217 100644
--- a/include/private/SkRecords.h
+++ b/include/private/SkRecords.h
@@ -180,7 +180,7 @@
        Optional<SkRect> bounds;
        Optional<SkPaint> paint;
        sk_sp<const SkImageFilter> backdrop;
-       sk_sp<SkImage> clipMask;
+       sk_sp<const SkImage> clipMask;
        Optional<SkMatrix> clipMatrix;
        SkCanvas::SaveLayerFlags saveLayerFlags);
 
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index c7e1d6e..c09e6cb 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -257,12 +257,12 @@
     SkMatrix                       fClipMatrix;
 
     DeviceCM(sk_sp<SkBaseDevice> device, const SkPaint* paint, const SkMatrix& stashed,
-             sk_sp<SkImage> clipImage, const SkMatrix* clipMatrix)
+             const SkImage* clipImage, const SkMatrix* clipMatrix)
         : fNext(nullptr)
         , fDevice(std::move(device))
         , fPaint(paint ? skstd::make_unique<SkPaint>(*paint) : nullptr)
         , fStashedMatrix(stashed)
-        , fClipImage(std::move(clipImage))
+        , fClipImage(sk_ref_sp(const_cast<SkImage*>(clipImage)))
         , fClipMatrix(clipMatrix ? *clipMatrix : SkMatrix::I())
     {}
 
diff --git a/src/core/SkColorSpaceXformCanvas.cpp b/src/core/SkColorSpaceXformCanvas.cpp
index b4dd5bb..2d62458 100644
--- a/src/core/SkColorSpaceXformCanvas.cpp
+++ b/src/core/SkColorSpaceXformCanvas.cpp
@@ -229,12 +229,12 @@
 
     SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec& rec) override {
         sk_sp<SkImageFilter> backdrop = rec.fBackdrop ? fXformer->apply(rec.fBackdrop) : nullptr;
-        sk_sp<SkImage> clipMask = rec.fClipMask ? fXformer->apply(rec.fClipMask.get()) : nullptr;
+        sk_sp<SkImage> clipMask = rec.fClipMask ? fXformer->apply(rec.fClipMask) : nullptr;
         fTarget->saveLayer({
             rec.fBounds,
             MaybePaint(rec.fPaint, fXformer.get()),
             backdrop.get(),
-            std::move(clipMask),
+            clipMask.get(),
             rec.fClipMatrix,
             rec.fSaveLayerFlags,
         });
diff --git a/src/core/SkLiteDL.cpp b/src/core/SkLiteDL.cpp
index f840607..71cbf68 100644
--- a/src/core/SkLiteDL.cpp
+++ b/src/core/SkLiteDL.cpp
@@ -91,23 +91,23 @@
     struct SaveLayer final : Op {
         static const auto kType = Type::SaveLayer;
         SaveLayer(const SkRect* bounds, const SkPaint* paint,
-                  const SkImageFilter* backdrop, sk_sp<SkImage> clipMask,
+                  const SkImageFilter* backdrop, const SkImage* clipMask,
                   const SkMatrix* clipMatrix, SkCanvas::SaveLayerFlags flags) {
             if (bounds) { this->bounds = *bounds; }
             if (paint)  { this->paint  = *paint;  }
             this->backdrop = sk_ref_sp(backdrop);
-            this->clipMask = std::move(clipMask);
+            this->clipMask = sk_ref_sp(clipMask);
             this->clipMatrix = clipMatrix ? *clipMatrix : SkMatrix::I();
             this->flags = flags;
         }
         SkRect                     bounds = kUnset;
         SkPaint                    paint;
         sk_sp<const SkImageFilter> backdrop;
-        sk_sp<SkImage>             clipMask;
+        sk_sp<const SkImage>       clipMask;
         SkMatrix                   clipMatrix;
         SkCanvas::SaveLayerFlags   flags;
         void draw(SkCanvas* c, const SkMatrix&) const {
-            c->saveLayer({ maybe_unset(bounds), &paint, backdrop.get(), clipMask,
+            c->saveLayer({ maybe_unset(bounds), &paint, backdrop.get(), clipMask.get(),
                            clipMatrix.isIdentity() ? nullptr : &clipMatrix, flags });
         }
     };
@@ -550,9 +550,9 @@
 void SkLiteDL::   save() { this->push   <Save>(0); }
 void SkLiteDL::restore() { this->push<Restore>(0); }
 void SkLiteDL::saveLayer(const SkRect* bounds, const SkPaint* paint,
-                         const SkImageFilter* backdrop, sk_sp<SkImage> clipMask,
+                         const SkImageFilter* backdrop, const SkImage* clipMask,
                          const SkMatrix* clipMatrix, SkCanvas::SaveLayerFlags flags) {
-    this->push<SaveLayer>(0, bounds, paint, backdrop, std::move(clipMask), clipMatrix, flags);
+    this->push<SaveLayer>(0, bounds, paint, backdrop, clipMask, clipMatrix, flags);
 }
 
 void SkLiteDL::   concat(const SkMatrix& matrix)   { this->push   <Concat>(0, matrix); }
diff --git a/src/core/SkLiteDL.h b/src/core/SkLiteDL.h
index 5219cd0..f8e7910 100644
--- a/src/core/SkLiteDL.h
+++ b/src/core/SkLiteDL.h
@@ -29,7 +29,7 @@
 #endif
 
     void save();
-    void saveLayer(const SkRect*, const SkPaint*, const SkImageFilter*, sk_sp<SkImage>,
+    void saveLayer(const SkRect*, const SkPaint*, const SkImageFilter*, const SkImage*,
                    const SkMatrix*, SkCanvas::SaveLayerFlags);
     void restore();
 
diff --git a/src/core/SkPicturePlayback.cpp b/src/core/SkPicturePlayback.cpp
index 84228d0..3af7909 100644
--- a/src/core/SkPicturePlayback.cpp
+++ b/src/core/SkPicturePlayback.cpp
@@ -744,7 +744,7 @@
                 rec.fSaveLayerFlags = reader->readInt();
             }
             if (flatFlags & SAVELAYERREC_HAS_CLIPMASK) {
-                rec.fClipMask = sk_ref_sp(const_cast<SkImage*>(fPictureData->getImage(reader)));
+                rec.fClipMask = fPictureData->getImage(reader);
             }
             if (flatFlags & SAVELAYERREC_HAS_CLIPMATRIX) {
                 reader->readMatrix(&clipMatrix);
diff --git a/src/core/SkPictureRecord.cpp b/src/core/SkPictureRecord.cpp
index ea4273f..608c6b3 100644
--- a/src/core/SkPictureRecord.cpp
+++ b/src/core/SkPictureRecord.cpp
@@ -125,7 +125,7 @@
         this->addInt(rec.fSaveLayerFlags);
     }
     if (flatFlags & SAVELAYERREC_HAS_CLIPMASK) {
-        this->addImage(rec.fClipMask.get());
+        this->addImage(rec.fClipMask);
     }
     if (flatFlags & SAVELAYERREC_HAS_CLIPMATRIX) {
         this->addMatrix(*rec.fClipMatrix);
diff --git a/src/core/SkRecordDraw.cpp b/src/core/SkRecordDraw.cpp
index 02c8c69..9e8d6fc 100644
--- a/src/core/SkRecordDraw.cpp
+++ b/src/core/SkRecordDraw.cpp
@@ -77,7 +77,7 @@
 DRAW(SaveLayer, saveLayer(SkCanvas::SaveLayerRec(r.bounds,
                                                  r.paint,
                                                  r.backdrop.get(),
-                                                 r.clipMask,
+                                                 r.clipMask.get(),
                                                  r.clipMatrix,
                                                  r.saveLayerFlags)));
 DRAW(SetMatrix, setMatrix(SkMatrix::Concat(fInitialCTM, r.matrix)));
diff --git a/src/core/SkRecorder.cpp b/src/core/SkRecorder.cpp
index c9d88fc..3fdc17d 100644
--- a/src/core/SkRecorder.cpp
+++ b/src/core/SkRecorder.cpp
@@ -366,7 +366,7 @@
     APPEND(SaveLayer, this->copy(rec.fBounds)
                     , this->copy(rec.fPaint)
                     , sk_ref_sp(rec.fBackdrop)
-                    , rec.fClipMask
+                    , sk_ref_sp(rec.fClipMask)
                     , this->copy(rec.fClipMatrix)
                     , rec.fSaveLayerFlags);
     return SkCanvas::kNoLayer_SaveLayerStrategy;
diff --git a/src/pipe/SkPipeCanvas.cpp b/src/pipe/SkPipeCanvas.cpp
index 91e74ee..7b665d9 100644
--- a/src/pipe/SkPipeCanvas.cpp
+++ b/src/pipe/SkPipeCanvas.cpp
@@ -258,7 +258,7 @@
         writer.writeFlattenable(rec.fBackdrop);
     }
     if (rec.fClipMask) {
-        writer.writeImage(rec.fClipMask.get());
+        writer.writeImage(rec.fClipMask);
     }
     if (rec.fClipMatrix) {
         writer.writeMatrix(*rec.fClipMatrix);
diff --git a/src/pipe/SkPipeReader.cpp b/src/pipe/SkPipeReader.cpp
index 73ef970..07b360c 100644
--- a/src/pipe/SkPipeReader.cpp
+++ b/src/pipe/SkPipeReader.cpp
@@ -259,7 +259,7 @@
         flags |= (1 << 31);//SkCanvas::kDontClipToLayer_PrivateSaveLayerFlag;
     }
 
-    canvas->saveLayer(SkCanvas::SaveLayerRec(bounds, paint, backdrop.get(), std::move(clipMask),
+    canvas->saveLayer(SkCanvas::SaveLayerRec(bounds, paint, backdrop.get(), clipMask.get(),
                       (extra & kHasClipMatrix_SaveLayerMask) ? &clipMatrix : nullptr, flags));
 }
 
diff --git a/tests/RecordOptsTest.cpp b/tests/RecordOptsTest.cpp
index d34959a..cb80987 100644
--- a/tests/RecordOptsTest.cpp
+++ b/tests/RecordOptsTest.cpp
@@ -198,7 +198,8 @@
     // saveLayer w/ clip mask should also NOT go away
     {
         sk_sp<SkSurface> surface(SkSurface::MakeRasterN32Premul(10, 10));
-        recorder.saveLayer({ nullptr, nullptr, nullptr, surface->makeImageSnapshot(), nullptr, 0});
+        recorder.saveLayer({ nullptr, nullptr, nullptr, surface->makeImageSnapshot().get(),
+                             nullptr, 0});
             recorder.drawRect(draw, opaqueDrawPaint);
         recorder.restore();
         assert_savelayer_draw_restore(r, &record, 21, false);