Remove SkAutoTDelete.

Replace with std::unique_ptr.

Change-Id: I5806cfbb30515fcb20e5e66ce13fb5f3b8728176
Reviewed-on: https://skia-review.googlesource.com/4381
Commit-Queue: Ben Wagner <bungeman@google.com>
Reviewed-by: Mike Klein <mtklein@chromium.org>
diff --git a/tools/Resources.cpp b/tools/Resources.cpp
index 9c12a67..dcca202 100644
--- a/tools/Resources.cpp
+++ b/tools/Resources.cpp
@@ -28,7 +28,7 @@
 bool GetResourceAsBitmap(const char* resource, SkBitmap* dst) {
     SkString resourcePath = GetResourcePath(resource);
     sk_sp<SkData> resourceData(SkData::MakeFromFileName(resourcePath.c_str()));
-    SkAutoTDelete<SkImageGenerator> gen(SkImageGenerator::NewFromEncoded(resourceData.get()));
+    std::unique_ptr<SkImageGenerator> gen(SkImageGenerator::NewFromEncoded(resourceData.get()));
     return gen && gen->tryGenerateBitmap(dst);
 }
 
@@ -40,7 +40,7 @@
 
 SkStreamAsset* GetResourceAsStream(const char* resource) {
     SkString resourcePath = GetResourcePath(resource);
-    SkAutoTDelete<SkFILEStream> stream(new SkFILEStream(resourcePath.c_str()));
+    std::unique_ptr<SkFILEStream> stream(new SkFILEStream(resourcePath.c_str()));
     if (!stream->isValid()) {
         SkDebugf("Resource %s not found.\n", resource);
         return nullptr;
@@ -49,7 +49,7 @@
 }
 
 sk_sp<SkTypeface> MakeResourceAsTypeface(const char* resource) {
-    SkAutoTDelete<SkStreamAsset> stream(GetResourceAsStream(resource));
+    std::unique_ptr<SkStreamAsset> stream(GetResourceAsStream(resource));
     if (!stream) {
         return nullptr;
     }
diff --git a/tools/debugger/SkDrawCommand.cpp b/tools/debugger/SkDrawCommand.cpp
index 4c34b87..3ee5cdb 100644
--- a/tools/debugger/SkDrawCommand.cpp
+++ b/tools/debugger/SkDrawCommand.cpp
@@ -847,9 +847,9 @@
     sk_sp<SkData> encoded(SkData::MakeWithoutCopy(data, size));
     sk_sp<SkImage> image(SkImage::MakeFromEncoded(std::move(encoded), nullptr));
 
-    SkAutoTDelete<SkBitmap> bitmap(new SkBitmap());
+    std::unique_ptr<SkBitmap> bitmap(new SkBitmap());
     if (nullptr != image) {
-        if (!image->asLegacyBitmap(bitmap, SkImage::kRW_LegacyBitmapMode)) {
+        if (!image->asLegacyBitmap(bitmap.get(), SkImage::kRW_LegacyBitmapMode)) {
             SkDebugf("image decode failed\n");
             return nullptr;
         }
@@ -2791,18 +2791,18 @@
     , fYPos(y)
     , fPaint(paint) {
 
-    SkAutoTDelete<SkString> runsStr(new SkString);
+    std::unique_ptr<SkString> runsStr(new SkString);
     fInfo.push(SkObjectParser::ScalarToString(x, "XPOS: "));
     fInfo.push(SkObjectParser::ScalarToString(y, "YPOS: "));
     fInfo.push(SkObjectParser::RectToString(fBlob->bounds(), "Bounds: "));
-    fInfo.push(runsStr);
+    fInfo.push(runsStr.get());
     fInfo.push(SkObjectParser::PaintToString(paint));
 
     unsigned runs = 0;
     SkPaint runPaint(paint);
     SkTextBlobRunIterator iter(fBlob.get());
     while (!iter.done()) {
-        SkAutoTDelete<SkString> tmpStr(new SkString);
+        std::unique_ptr<SkString> tmpStr(new SkString);
         tmpStr->printf("==== Run [%d] ====", runs++);
         fInfo.push(tmpStr.release());
 
diff --git a/tools/flags/SkCommonFlagsConfig.h b/tools/flags/SkCommonFlagsConfig.h
index 9abf4cb..2b80397 100644
--- a/tools/flags/SkCommonFlagsConfig.h
+++ b/tools/flags/SkCommonFlagsConfig.h
@@ -75,7 +75,7 @@
 };
 #endif
 
-typedef SkTArray<SkAutoTDelete<SkCommandLineConfig>, true> SkCommandLineConfigArray;
+typedef SkTArray<std::unique_ptr<SkCommandLineConfig>, true> SkCommandLineConfigArray;
 void ParseConfigs(const SkCommandLineFlags::StringArray& configList,
                   SkCommandLineConfigArray* outResult);
 
diff --git a/tools/get_images_from_skps.cpp b/tools/get_images_from_skps.cpp
index e38a245..b8a8930 100644
--- a/tools/get_images_from_skps.cpp
+++ b/tools/get_images_from_skps.cpp
@@ -54,7 +54,7 @@
         gSeen.add(digest);
 
         sk_sp<SkData> data(SkData::MakeWithoutCopy(ptr, len));
-        SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(data));
+        std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(data));
         if (!codec) {
             // FIXME: This code is currently unreachable because we create an empty generator when
             //        we fail to create a codec.
diff --git a/tools/gpu/GrContextFactory.cpp b/tools/gpu/GrContextFactory.cpp
index 4f18994..79489f4 100644
--- a/tools/gpu/GrContextFactory.cpp
+++ b/tools/gpu/GrContextFactory.cpp
@@ -101,7 +101,7 @@
             return ContextInfo(context.fBackend, context.fTestContext, context.fGrContext);
         }
     }
-    SkAutoTDelete<TestContext> testCtx;
+    std::unique_ptr<TestContext> testCtx;
     sk_sp<GrContext> grCtx;
     GrBackendContext backendContext = 0;
     sk_sp<const GrGLInterface> glInterface;
diff --git a/tools/gpu/GrContextFactory.h b/tools/gpu/GrContextFactory.h
index d6baffc..54b6611 100644
--- a/tools/gpu/GrContextFactory.h
+++ b/tools/gpu/GrContextFactory.h
@@ -162,7 +162,7 @@
         bool            fAbandoned;
     };
     SkTArray<Context, true>         fContexts;
-    SkAutoTDelete<GLTestContext>    fSentinelGLContext;
+    std::unique_ptr<GLTestContext>  fSentinelGLContext;
     const GrContextOptions          fGlobalOptions;
 };
 }  // namespace sk_gpu_test
diff --git a/tools/gpu/TestContext.h b/tools/gpu/TestContext.h
index 8722a33..ecb61e3 100644
--- a/tools/gpu/TestContext.h
+++ b/tools/gpu/TestContext.h
@@ -28,10 +28,10 @@
     virtual bool isValid() const = 0;
 
     bool fenceSyncSupport() const { return fFenceSync != nullptr; }
-    FenceSync* fenceSync() { SkASSERT(fFenceSync); return fFenceSync; }
+    FenceSync* fenceSync() { SkASSERT(fFenceSync); return fFenceSync.get(); }
 
     bool gpuTimingSupport() const { return fGpuTimer != nullptr; }
-    GpuTimer* gpuTimer() const { SkASSERT(fGpuTimer); return fGpuTimer; }
+    GpuTimer* gpuTimer() const { SkASSERT(fGpuTimer); return fGpuTimer.get(); }
 
     bool getMaxGpuFrameLag(int *maxFrameLag) const {
         if (!fFenceSync) {
@@ -81,8 +81,8 @@
     virtual void finish() = 0;
 
 protected:
-    SkAutoTDelete<FenceSync>   fFenceSync;
-    SkAutoTDelete<GpuTimer>    fGpuTimer;
+    std::unique_ptr<FenceSync> fFenceSync;
+    std::unique_ptr<GpuTimer>  fGpuTimer;
 
     TestContext();
 
diff --git a/tools/gpu/gl/GLTestContext.cpp b/tools/gpu/gl/GLTestContext.cpp
index 20a9908..e6d0e40 100644
--- a/tools/gpu/gl/GLTestContext.cpp
+++ b/tools/gpu/gl/GLTestContext.cpp
@@ -14,7 +14,7 @@
 
 class GLFenceSync : public sk_gpu_test::FenceSync {
 public:
-    static GLFenceSync* CreateIfSupported(const sk_gpu_test::GLTestContext*);
+    static std::unique_ptr<GLFenceSync> MakeIfSupported(const sk_gpu_test::GLTestContext*);
 
     sk_gpu_test::PlatformFence SK_WARN_UNUSED_RESULT insertFence() const override;
     bool waitFence(sk_gpu_test::PlatformFence fence) const override;
@@ -43,8 +43,8 @@
     typedef FenceSync INHERITED;
 };
 
-GLFenceSync* GLFenceSync::CreateIfSupported(const sk_gpu_test::GLTestContext* ctx) {
-    SkAutoTDelete<GLFenceSync> ret;
+std::unique_ptr<GLFenceSync> GLFenceSync::MakeIfSupported(const sk_gpu_test::GLTestContext* ctx) {
+    std::unique_ptr<GLFenceSync> ret;
     if (kGL_GrGLStandard == ctx->gl()->fStandard) {
         if (GrGLGetVersion(ctx->gl()) < GR_GL_VER(3,2) && !ctx->gl()->hasExtension("GL_ARB_sync")) {
             return nullptr;
@@ -56,7 +56,10 @@
         }
         ret.reset(new GLFenceSync(ctx, "APPLE"));
     }
-    return ret->validate() ? ret.release() : nullptr;
+    if (!ret->validate()) {
+        ret = nullptr;
+    }
+    return ret;
 }
 
 GLFenceSync::GLFenceSync(const sk_gpu_test::GLTestContext* ctx, const char* ext) {
@@ -82,7 +85,7 @@
 
 class GLGpuTimer : public sk_gpu_test::GpuTimer {
 public:
-    static GLGpuTimer* CreateIfSupported(const sk_gpu_test::GLTestContext*);
+    static std::unique_ptr<GLGpuTimer> MakeIfSupported(const sk_gpu_test::GLTestContext*);
 
     QueryStatus checkQueryStatus(sk_gpu_test::PlatformTimerQuery) override;
     std::chrono::nanoseconds getTimeElapsed(sk_gpu_test::PlatformTimerQuery) override;
@@ -121,8 +124,8 @@
     typedef sk_gpu_test::GpuTimer INHERITED;
 };
 
-GLGpuTimer* GLGpuTimer::CreateIfSupported(const sk_gpu_test::GLTestContext* ctx) {
-    SkAutoTDelete<GLGpuTimer> ret;
+std::unique_ptr<GLGpuTimer> GLGpuTimer::MakeIfSupported(const sk_gpu_test::GLTestContext* ctx) {
+    std::unique_ptr<GLGpuTimer> ret;
     const GrGLInterface* gl = ctx->gl();
     if (gl->fExtensions.has("GL_EXT_disjoint_timer_query")) {
         ret.reset(new GLGpuTimer(true, ctx, "EXT"));
@@ -132,7 +135,10 @@
     } else if (gl->fExtensions.has("GL_EXT_timer_query")) {
         ret.reset(new GLGpuTimer(false, ctx, "EXT"));
     }
-    return ret && ret->validate() ? ret.release() : nullptr;
+    if (ret && !ret->validate()) {
+        ret = nullptr;
+    }
+    return ret;
 }
 
 GLGpuTimer::GLGpuTimer(bool disjointSupport, const sk_gpu_test::GLTestContext* ctx, const char* ext)
@@ -219,11 +225,11 @@
     SkASSERT(nullptr == fGL.get());
 }
 
-void GLTestContext::init(const GrGLInterface* gl, FenceSync* fenceSync) {
+void GLTestContext::init(const GrGLInterface* gl, std::unique_ptr<FenceSync> fenceSync) {
     SkASSERT(!fGL.get());
     fGL.reset(gl);
-    fFenceSync = fenceSync ? fenceSync : GLFenceSync::CreateIfSupported(this);
-    fGpuTimer = GLGpuTimer::CreateIfSupported(this);
+    fFenceSync = fenceSync ? std::move(fenceSync) : GLFenceSync::MakeIfSupported(this);
+    fGpuTimer = GLGpuTimer::MakeIfSupported(this);
 }
 
 void GLTestContext::teardown() {
diff --git a/tools/gpu/gl/GLTestContext.h b/tools/gpu/gl/GLTestContext.h
index 0cd9762..a2b0455 100644
--- a/tools/gpu/gl/GLTestContext.h
+++ b/tools/gpu/gl/GLTestContext.h
@@ -57,7 +57,7 @@
      * Creates a new GL context of the same type and makes the returned context current
      * (if not null).
      */
-    virtual GLTestContext *createNew() const { return nullptr; }
+    virtual std::unique_ptr<GLTestContext> makeNew() const { return nullptr; }
 
     template<typename Ret, typename... Args>
     void getGLProcAddress(Ret(GR_GL_FUNCTION_TYPE** out)(Args...),
@@ -81,7 +81,7 @@
     /*
      * Methods that sublcasses must call from their constructors and destructors.
      */
-    void init(const GrGLInterface *, FenceSync* = nullptr);
+    void init(const GrGLInterface *, std::unique_ptr<FenceSync> = nullptr);
 
     void teardown() override;
 
diff --git a/tools/gpu/gl/angle/GLTestContext_angle.cpp b/tools/gpu/gl/angle/GLTestContext_angle.cpp
index 449e14c..aa55bf3 100644
--- a/tools/gpu/gl/angle/GLTestContext_angle.cpp
+++ b/tools/gpu/gl/angle/GLTestContext_angle.cpp
@@ -82,7 +82,7 @@
     GrEGLImage texture2DToEGLImage(GrGLuint texID) const override;
     void destroyEGLImage(GrEGLImage) const override;
     GrGLuint eglImageToExternalTexture(GrEGLImage) const override;
-    sk_gpu_test::GLTestContext* createNew() const override;
+    std::unique_ptr<sk_gpu_test::GLTestContext> makeNew() const override;
 
 private:
     void destroyGLContext();
@@ -216,8 +216,9 @@
     return texID;
 }
 
-sk_gpu_test::GLTestContext* ANGLEGLContext::createNew() const {
-    sk_gpu_test::GLTestContext* ctx = sk_gpu_test::CreateANGLETestContext(fType, fVersion);
+std::unique_ptr<sk_gpu_test::GLTestContext> ANGLEGLContext::makeNew() const {
+    std::unique_ptr<sk_gpu_test::GLTestContext> ctx =
+        sk_gpu_test::MakeANGLETestContext(fType, fVersion);
     if (ctx) {
         ctx->makeCurrent();
     }
@@ -286,12 +287,10 @@
     return GrGLAssembleGLESInterface(&gLibs, angle_get_gl_proc);
 }
 
-GLTestContext* CreateANGLETestContext(ANGLEBackend type,
-                                      ANGLEContextVersion version) {
-    ANGLEGLContext* ctx = new ANGLEGLContext(type, version);
+std::unique_ptr<GLTestContext> MakeANGLETestContext(ANGLEBackend type, ANGLEContextVersion version){
+    std::unique_ptr<ANGLEGLContext> ctx(new ANGLEGLContext(type, version));
     if (!ctx->isValid()) {
-        delete ctx;
-        return NULL;
+        return nullptr;
     }
     return ctx;
 }
diff --git a/tools/gpu/gl/angle/GLTestContext_angle.h b/tools/gpu/gl/angle/GLTestContext_angle.h
index 0da747f..9314710 100644
--- a/tools/gpu/gl/angle/GLTestContext_angle.h
+++ b/tools/gpu/gl/angle/GLTestContext_angle.h
@@ -30,7 +30,7 @@
 };
 
 /** Creates a GLTestContext backed by ANGLE. */
-GLTestContext* CreateANGLETestContext(ANGLEBackend, ANGLEContextVersion);
+std::unique_ptr<GLTestContext> MakeANGLETestContext(ANGLEBackend, ANGLEContextVersion);
 
 }  // namespace sk_gpu_test
 #endif
diff --git a/tools/gpu/gl/egl/CreatePlatformGLTestContext_egl.cpp b/tools/gpu/gl/egl/CreatePlatformGLTestContext_egl.cpp
index 06bd70f..b2517f0 100644
--- a/tools/gpu/gl/egl/CreatePlatformGLTestContext_egl.cpp
+++ b/tools/gpu/gl/egl/CreatePlatformGLTestContext_egl.cpp
@@ -22,7 +22,7 @@
 // TODO: Share this class with ANGLE if/when it gets support for EGL_KHR_fence_sync.
 class EGLFenceSync : public sk_gpu_test::FenceSync {
 public:
-    static EGLFenceSync* CreateIfSupported(EGLDisplay);
+    static std::unique_ptr<EGLFenceSync> MakeIfSupported(EGLDisplay);
 
     sk_gpu_test::PlatformFence SK_WARN_UNUSED_RESULT insertFence() const override;
     bool waitFence(sk_gpu_test::PlatformFence fence) const override;
@@ -44,7 +44,7 @@
     GrEGLImage texture2DToEGLImage(GrGLuint texID) const override;
     void destroyEGLImage(GrEGLImage) const override;
     GrGLuint eglImageToExternalTexture(GrEGLImage) const override;
-    sk_gpu_test::GLTestContext* createNew() const override;
+    std::unique_ptr<sk_gpu_test::GLTestContext> makeNew() const override;
 
 private:
     void destroyGLContext();
@@ -180,7 +180,7 @@
             continue;
         }
 
-        this->init(gl.release(), EGLFenceSync::CreateIfSupported(fDisplay));
+        this->init(gl.release(), EGLFenceSync::MakeIfSupported(fDisplay));
         break;
     }
 }
@@ -255,8 +255,8 @@
     return texID;
 }
 
-sk_gpu_test::GLTestContext* EGLGLTestContext::createNew() const {
-    sk_gpu_test::GLTestContext* ctx = new EGLGLTestContext(this->gl()->fStandard);
+std::unique_ptr<sk_gpu_test::GLTestContext> EGLGLTestContext::makeNew() const {
+    std::unique_ptr<sk_gpu_test::GLTestContext> ctx(new EGLGLTestContext(this->gl()->fStandard));
     if (ctx) {
         ctx->makeCurrent();
     }
@@ -294,11 +294,11 @@
     return false;
 }
 
-EGLFenceSync* EGLFenceSync::CreateIfSupported(EGLDisplay display) {
+std::unique_ptr<EGLFenceSync> EGLFenceSync::MakeIfSupported(EGLDisplay display) {
     if (!display || !supports_egl_extension(display, "EGL_KHR_fence_sync")) {
         return nullptr;
     }
-    return new EGLFenceSync(display);
+    return std::unique_ptr<EGLFenceSync>(new EGLFenceSync(display));
 }
 
 sk_gpu_test::PlatformFence EGLFenceSync::insertFence() const {
diff --git a/tools/gpu/vk/VkTestContext.cpp b/tools/gpu/vk/VkTestContext.cpp
index 92bef7c..502dea8 100644
--- a/tools/gpu/vk/VkTestContext.cpp
+++ b/tools/gpu/vk/VkTestContext.cpp
@@ -134,8 +134,8 @@
 private:
     VkTestContextImpl(sk_sp<const GrVkBackendContext> backendContext)
             : VkTestContext(std::move(backendContext)) {
-        fFenceSync = new VkFenceSync(sk_ref_sp(fVk->fInterface.get()), fVk->fDevice, fVk->fQueue,
-                                     fVk->fGraphicsQueueIndex);
+        fFenceSync.reset(new VkFenceSync(fVk->fInterface, fVk->fDevice, fVk->fQueue,
+                                         fVk->fGraphicsQueueIndex));
     }
 
     void onPlatformMakeCurrent() const override {}
diff --git a/tools/skdiff/skdiff_utils.cpp b/tools/skdiff/skdiff_utils.cpp
index 609d75d..f788ec8 100644
--- a/tools/skdiff/skdiff_utils.cpp
+++ b/tools/skdiff/skdiff_utils.cpp
@@ -34,7 +34,7 @@
 }
 
 bool get_bitmap(sk_sp<SkData> fileBits, DiffResource& resource, bool sizeOnly) {
-    SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(fileBits));
+    std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(fileBits));
     if (!codec) {
         SkDebugf("ERROR: could not create codec for <%s>\n", resource.fFullPath.c_str());
         resource.fStatus = DiffResource::kCouldNotDecode_Status;
diff --git a/tools/skiaserve/Request.cpp b/tools/skiaserve/Request.cpp
index 9da9f0f..134fdf0 100644
--- a/tools/skiaserve/Request.cpp
+++ b/tools/skiaserve/Request.cpp
@@ -55,7 +55,7 @@
 
 sk_sp<SkData> Request::writeCanvasToPng(SkCanvas* canvas) {
     // capture pixels
-    SkAutoTDelete<SkBitmap> bmp(this->getBitmapFromCanvas(canvas));
+    std::unique_ptr<SkBitmap> bmp(this->getBitmapFromCanvas(canvas));
     SkASSERT(bmp);
 
     // Convert to format suitable for PNG output
@@ -302,7 +302,7 @@
 SkColor Request::getPixel(int x, int y) {
     SkCanvas* canvas = this->getCanvas();
     canvas->flush();
-    SkAutoTDelete<SkBitmap> bitmap(this->getBitmapFromCanvas(canvas));
+    std::unique_ptr<SkBitmap> bitmap(this->getBitmapFromCanvas(canvas));
     SkASSERT(bitmap);
 
     // Convert to format suitable for inspection
diff --git a/tools/viewer/ImageSlide.cpp b/tools/viewer/ImageSlide.cpp
index e70f618..0ffd4ea 100644
--- a/tools/viewer/ImageSlide.cpp
+++ b/tools/viewer/ImageSlide.cpp
@@ -37,7 +37,7 @@
 
 void ImageSlide::load(SkScalar, SkScalar) {
     sk_sp<SkData> encoded = SkData::MakeFromFileName(fPath.c_str());
-    SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
+    std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(encoded));
     if (!codec) {
         return;
     }
diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp
index 739882d..d92b801 100644
--- a/tools/viewer/Viewer.cpp
+++ b/tools/viewer/Viewer.cpp
@@ -252,7 +252,7 @@
 
     const skiagm::GMRegistry* gms(skiagm::GMRegistry::Head());
     while (gms) {
-        SkAutoTDelete<skiagm::GM> gm(gms->factory()(nullptr));
+        std::unique_ptr<skiagm::GM> gm(gms->factory()(nullptr));
 
         if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, gm->getName())) {
             sk_sp<Slide> slide(new GMSlide(gm.release()));
diff --git a/tools/visualize_color_gamut.cpp b/tools/visualize_color_gamut.cpp
index 9e9ed96..ee4c2a5 100644
--- a/tools/visualize_color_gamut.cpp
+++ b/tools/visualize_color_gamut.cpp
@@ -124,7 +124,7 @@
         SkDebugf("Cannot find input image.\n");
         return -1;
     }
-    SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(data));
+    std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(data));
     if (!codec) {
         SkDebugf("Invalid input image.\n");
         return -1;