Resurrect SkDebugger

Can't let go <sniffle>.

R=robertphillips@google.com

GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=4793

Change-Id: Ida5936d17af2ef60c3f50e27b4f4987a79165fa5
Reviewed-on: https://skia-review.googlesource.com/4793
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Florin Malita <fmalita@chromium.org>
diff --git a/debugger/QT/SkDebuggerGUI.cpp b/debugger/QT/SkDebuggerGUI.cpp
index 3b84afc..1437faf 100644
--- a/debugger/QT/SkDebuggerGUI.cpp
+++ b/debugger/QT/SkDebuggerGUI.cpp
@@ -283,7 +283,7 @@
 
     sk_sp<SkPixelSerializer> serializer(
             SkImageEncoder::CreatePixelSerializer());
-    copy->serialize(&file, serializer);
+    copy->serialize(&file, serializer.get());
 }
 
 void SkDebuggerGUI::loadFile(QListWidgetItem *item) {
@@ -672,9 +672,9 @@
 void SkDebuggerGUI::loadPicture(const SkString& fileName) {
     fFileName = fileName;
     fLoading = true;
-    std::unique_ptr<SkStream> stream(new SkFILEStream(fileName.c_str()));
+    SkFILEStream stream(fileName.c_str());
 
-    auto picture = SkPicture::MakeFromStream(stream);
+    auto picture = SkPicture::MakeFromStream(&stream);
 
     if (nullptr == picture) {
         QMessageBox::critical(this, "Error loading file", "Couldn't read file, sorry.");
diff --git a/debugger/QT/SkGLWidget.cpp b/debugger/QT/SkGLWidget.cpp
index 5335da4..f95af84 100644
--- a/debugger/QT/SkGLWidget.cpp
+++ b/debugger/QT/SkGLWidget.cpp
@@ -59,7 +59,7 @@
     GrBackendRenderTargetDesc desc = this->getDesc(this->width(), this->height());
     desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
 
-    fGpuSurface = SkSurface::MakeFromBackendRenderTarget(fCurContext, desc, nullptr);
+    fGpuSurface = SkSurface::MakeFromBackendRenderTarget(fCurContext.get(), desc, nullptr);
     fCanvas = fGpuSurface->getCanvas();
 }
 
diff --git a/debugger/SkDebugger.cpp b/debugger/SkDebugger.cpp
index 6639d2c..197a27f 100644
--- a/debugger/SkDebugger.cpp
+++ b/debugger/SkDebugger.cpp
@@ -7,31 +7,24 @@
  */
 
 #include "SkDebugger.h"
+#include "SkMakeUnique.h"
 #include "SkPictureRecorder.h"
 #include "SkString.h"
 
 
 SkDebugger::SkDebugger()
-    : fPicture(nullptr)
-    , fIndex(-1) {
-    // Create this some other dynamic way?
-    fDebugCanvas = new SkDebugCanvas(0, 0);
-}
+    : fDebugCanvas(skstd::make_unique<SkDebugCanvas>(0, 0))
+    , fIndex(-1) { }
 
-SkDebugger::~SkDebugger() {
-    // Need to inherit from SkRef object in order for following to work
-    SkSafeUnref(fDebugCanvas);
-    SkSafeUnref(fPicture);
-}
+SkDebugger::~SkDebugger() {}
 
 void SkDebugger::loadPicture(SkPicture* picture) {
-    SkRefCnt_SafeAssign(fPicture, picture);
-
-    delete fDebugCanvas;
-    fDebugCanvas = new SkDebugCanvas(SkScalarCeilToInt(this->pictureCull().width()), 
-                                     SkScalarCeilToInt(this->pictureCull().height()));
+    fPicture = sk_ref_sp(picture);
+    fDebugCanvas = skstd::make_unique<SkDebugCanvas>(
+        SkScalarCeilToInt(this->pictureCull().width()),
+        SkScalarCeilToInt(this->pictureCull().height()));
     fDebugCanvas->setPicture(picture);
-    picture->playback(fDebugCanvas);
+    picture->playback(fDebugCanvas.get());
     fDebugCanvas->setPicture(nullptr);
     fIndex = fDebugCanvas->getSize() - 1;
 }
diff --git a/debugger/SkDebugger.h b/debugger/SkDebugger.h
index 1fa285a..7e58047 100644
--- a/debugger/SkDebugger.h
+++ b/debugger/SkDebugger.h
@@ -86,7 +86,7 @@
     }
 
     SkRect pictureCull() const   { 
-        return nullptr == fPicture ? SkRect::MakeEmpty() : fPicture->cullRect();
+        return fPicture ? fPicture->cullRect() : SkRect::MakeEmpty();
     }
 
     int index() {
@@ -123,8 +123,8 @@
     void getClipStackText(SkString* clipStack);
 
 private:
-    SkDebugCanvas* fDebugCanvas;
-    SkPicture* fPicture;
+    std::unique_ptr<SkDebugCanvas>  fDebugCanvas;
+    sk_sp<SkPicture>                fPicture;
 
     int fIndex;
 };