use unique_ptr for codec factories

Will need guards for android (at least)

Bug: skia:
Change-Id: I2bb8e656997984489ef1f2e41cd3d301c4e7b947
Reviewed-on: https://skia-review.googlesource.com/26040
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Mike Reed <reed@google.com>
diff --git a/bench/AndroidCodecBench.cpp b/bench/AndroidCodecBench.cpp
index e0680bd..d9abac6 100644
--- a/bench/AndroidCodecBench.cpp
+++ b/bench/AndroidCodecBench.cpp
@@ -29,7 +29,7 @@
 }
 
 void AndroidCodecBench::onDelayedSetup() {
-    std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::NewFromData(fData));
+    std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::MakeFromData(fData));
     SkISize scaledSize = codec->getSampledDimensions(fSampleSize);
 
     fInfo = codec->getInfo().makeWH(scaledSize.width(), scaledSize.height())
@@ -46,7 +46,7 @@
     SkAndroidCodec::AndroidOptions options;
     options.fSampleSize = fSampleSize;
     for (int i = 0; i < n; i++) {
-        codec.reset(SkAndroidCodec::NewFromData(fData));
+        codec = SkAndroidCodec::MakeFromData(fData);
 #ifdef SK_DEBUG
         const SkCodec::Result result =
 #endif
diff --git a/bench/CodecBench.cpp b/bench/CodecBench.cpp
index f72294e..2944374 100644
--- a/bench/CodecBench.cpp
+++ b/bench/CodecBench.cpp
@@ -24,11 +24,8 @@
     // Parse filename and the color type to give the benchmark a useful name
     fName.printf("Codec_%s_%s%s", baseName.c_str(), color_type_to_str(colorType),
             alpha_type_to_str(alphaType));
-#ifdef SK_DEBUG
     // Ensure that we can create an SkCodec from this data.
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(fData));
-    SkASSERT(codec);
-#endif
+    SkASSERT(SkCodec::MakeFromData(fData));
 }
 
 const char* CodecBench::onGetName() {
@@ -40,7 +37,7 @@
 }
 
 void CodecBench::onDelayedSetup() {
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(fData));
+    std::unique_ptr<SkCodec> codec = SkCodec::MakeFromData(fData);
 
     fInfo = codec->getInfo().makeColorType(fColorType)
                             .makeAlphaType(fAlphaType)
@@ -56,7 +53,7 @@
         options.fZeroInitialized = SkCodec::kYes_ZeroInitialized;
     }
     for (int i = 0; i < n; i++) {
-        codec.reset(SkCodec::NewFromData(fData));
+        codec = SkCodec::MakeFromData(fData);
 #ifdef SK_DEBUG
         const SkCodec::Result result =
 #endif
diff --git a/bench/ColorCodecBench.cpp b/bench/ColorCodecBench.cpp
index 867b8a1..680c1d9 100644
--- a/bench/ColorCodecBench.cpp
+++ b/bench/ColorCodecBench.cpp
@@ -34,13 +34,10 @@
 }
 
 void ColorCodecBench::decodeAndXform() {
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(fEncoded));
-    SkASSERT(codec);
-
 #ifdef SK_DEBUG
     SkCodec::Result result =
 #endif
-    codec->getPixels(fDstInfo, fDst.get(), fDstInfo.minRowBytes());
+    SkCodec::MakeFromData(fEncoded)->getPixels(fDstInfo, fDst.get(), fDstInfo.minRowBytes());
     SkASSERT(SkCodec::kSuccess == result);
 }
 
@@ -61,7 +58,7 @@
 }
 
 void ColorCodecBench::onDelayedSetup() {
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(fEncoded));
+    std::unique_ptr<SkCodec> codec = SkCodec::MakeFromData(fEncoded);
     fSrcInfo = codec->getInfo().makeColorType(kRGBA_8888_SkColorType);
     fDstInfo = fSrcInfo;
 
diff --git a/bench/nanobench.cpp b/bench/nanobench.cpp
index 95e1211..196cb22 100644
--- a/bench/nanobench.cpp
+++ b/bench/nanobench.cpp
@@ -815,7 +815,7 @@
                 continue;
             }
             sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str()));
-            std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(encoded));
+            std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(encoded));
             if (!codec) {
                 // Nothing to time.
                 SkDebugf("Cannot find codec for %s\n", path.c_str());
@@ -894,7 +894,7 @@
                 continue;
             }
             sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str()));
-            std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::NewFromData(encoded));
+            std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::MakeFromData(encoded));
             if (!codec) {
                 // Nothing to time.
                 SkDebugf("Cannot find codec for %s\n", path.c_str());
diff --git a/dm/DM.cpp b/dm/DM.cpp
index 1b88889..698a79c 100644
--- a/dm/DM.cpp
+++ b/dm/DM.cpp
@@ -531,7 +531,7 @@
         info("Couldn't read %s.", path.c_str());
         return;
     }
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(encoded));
+    std::unique_ptr<SkCodec> codec = SkCodec::MakeFromData(encoded);
     if (nullptr == codec.get()) {
         info("Couldn't create codec for %s.", path.c_str());
         return;
diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp
index 6876254..0e295a0 100644
--- a/dm/DMSrcSink.cpp
+++ b/dm/DMSrcSink.cpp
@@ -419,7 +419,7 @@
         return SkStringPrintf("Couldn't read %s.", fPath.c_str());
     }
 
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(encoded));
+    std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(encoded));
     if (nullptr == codec.get()) {
         return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str());
     }
@@ -757,7 +757,7 @@
 
 SkISize CodecSrc::size() const {
     sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(encoded));
+    std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(encoded));
     if (nullptr == codec) {
         return {0, 0};
     }
@@ -818,8 +818,8 @@
     if (!encoded) {
         return SkStringPrintf("Couldn't read %s.", fPath.c_str());
     }
-    std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::NewFromData(encoded));
-    if (nullptr == codec.get()) {
+    std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::MakeFromData(encoded));
+    if (nullptr == codec) {
         return SkStringPrintf("Couldn't create android codec for %s.", fPath.c_str());
     }
 
@@ -869,7 +869,7 @@
 
 SkISize AndroidCodecSrc::size() const {
     sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
-    std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::NewFromData(encoded));
+    std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::MakeFromData(encoded));
     if (nullptr == codec) {
         return {0, 0};
     }
@@ -990,7 +990,7 @@
 
 SkISize ImageGenSrc::size() const {
     sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(encoded));
+    std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(encoded));
     if (nullptr == codec) {
         return {0, 0};
     }
@@ -1052,8 +1052,8 @@
         return SkStringPrintf("Couldn't read %s.", fPath.c_str());
     }
 
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(encoded));
-    if (nullptr == codec.get()) {
+    std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(encoded));
+    if (nullptr == codec) {
         return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str());
     }
 
@@ -1123,7 +1123,7 @@
 
 SkISize ColorCodecSrc::size() const {
     sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(encoded));
+    std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(encoded));
     if (nullptr == codec) {
         return {0, 0};
     }
diff --git a/fuzz/fuzz.cpp b/fuzz/fuzz.cpp
index e030979..f8897e6 100644
--- a/fuzz/fuzz.cpp
+++ b/fuzz/fuzz.cpp
@@ -195,7 +195,7 @@
 
     // This is mostly copied from DMSrcSink's CodecSrc::draw method.
     SkDebugf("Decoding\n");
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(bytes));
+    std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(bytes));
     if (nullptr == codec.get()) {
         SkDebugf("[terminated] Couldn't create codec.\n");
         return;
diff --git a/gm/animatedGif.cpp b/gm/animatedGif.cpp
index fc5217f..5686193 100644
--- a/gm/animatedGif.cpp
+++ b/gm/animatedGif.cpp
@@ -123,7 +123,7 @@
             return false;
         }
 
-        fCodec.reset(SkCodec::NewFromStream(stream.release()));
+        fCodec = SkCodec::MakeFromStream(std::move(stream));
         if (!fCodec) {
             SkDebugf("Could create codec from %s", FLAGS_animatedGif[0]);
             return false;
diff --git a/gm/bitmapimage.cpp b/gm/bitmapimage.cpp
index 9832041..ccd3487 100644
--- a/gm/bitmapimage.cpp
+++ b/gm/bitmapimage.cpp
@@ -36,7 +36,7 @@
         }
 
         // Create matching bitmap.
-        std::unique_ptr<SkCodec> codec(SkCodec::NewFromStream(GetResourceAsStream(path).release()));
+        std::unique_ptr<SkCodec> codec(SkCodec::MakeFromStream(GetResourceAsStream(path)));
         SkBitmap bitmap;
         bitmap.allocPixels(codec->getInfo());
         codec->getPixels(codec->getInfo(), bitmap.getPixels(), bitmap.rowBytes());
diff --git a/gm/encode-srgb.cpp b/gm/encode-srgb.cpp
index bffe196..be3cd62 100644
--- a/gm/encode-srgb.cpp
+++ b/gm/encode-srgb.cpp
@@ -56,7 +56,7 @@
     }
 
     sk_sp<SkData> data = GetResourceAsData(resource);
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(data));
+    std::unique_ptr<SkCodec> codec = SkCodec::MakeFromData(data);
     SkImageInfo dstInfo = codec->getInfo().makeColorType(colorType)
                                           .makeAlphaType(alphaType)
                                           .makeColorSpace(fix_for_colortype(colorSpace, colorType));
diff --git a/gm/makecolorspace.cpp b/gm/makecolorspace.cpp
index b3b937e..0ea3d40 100644
--- a/gm/makecolorspace.cpp
+++ b/gm/makecolorspace.cpp
@@ -15,7 +15,7 @@
 sk_sp<SkImage> make_raster_image(const char* path, SkTransferFunctionBehavior behavior) {
     SkString resourcePath = GetResourcePath(path);
     sk_sp<SkData> resourceData = SkData::MakeFromFileName(resourcePath.c_str());
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(resourceData));
+    std::unique_ptr<SkCodec> codec = SkCodec::MakeFromData(resourceData);
 
     SkBitmap bitmap;
     bitmap.allocPixels(codec->getInfo());
diff --git a/gm/readpixels.cpp b/gm/readpixels.cpp
index 69d22bb..bd2fe9b 100644
--- a/gm/readpixels.cpp
+++ b/gm/readpixels.cpp
@@ -52,7 +52,7 @@
 
 static sk_sp<SkImage> make_raster_image(SkColorType colorType) {
     std::unique_ptr<SkStream> stream(GetResourceAsStream("google_chrome.ico"));
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromStream(stream.release()));
+    std::unique_ptr<SkCodec> codec = SkCodec::MakeFromStream(std::move(stream));
 
     SkBitmap bitmap;
     SkImageInfo info = codec->getInfo().makeWH(kWidth, kHeight)
diff --git a/include/codec/SkAndroidCodec.h b/include/codec/SkAndroidCodec.h
index b4dd385..e785411 100644
--- a/include/codec/SkAndroidCodec.h
+++ b/include/codec/SkAndroidCodec.h
@@ -29,7 +29,8 @@
      *  If NULL is returned, the stream is deleted immediately. Otherwise, the
      *  SkCodec takes ownership of it, and will delete it when done with it.
      */
-    static SkAndroidCodec* NewFromStream(SkStream*, SkPngChunkReader* = NULL);
+    static std::unique_ptr<SkAndroidCodec> MakeFromStream(std::unique_ptr<SkStream>,
+                                                          SkPngChunkReader* = nullptr);
 
     /**
      *  If this data represents an encoded image that we know how to decode,
@@ -38,10 +39,19 @@
      *  The SkPngChunkReader handles unknown chunks in PNGs.
      *  See SkCodec.h for more details.
      */
-    static SkAndroidCodec* NewFromData(sk_sp<SkData>, SkPngChunkReader* = NULL);
+    static std::unique_ptr<SkAndroidCodec> MakeFromData(sk_sp<SkData>, SkPngChunkReader* = nullptr);
+
+#ifdef SK_SUPPORT_LEGACY_CODEC_NEW
+    static SkAndroidCodec* NewFromStream(SkStream* stream, SkPngChunkReader* reader) {
+        return MakeFromStream(std::unique_ptr<SkStream>(stream), reader).release();
+    }
+    static SkAndroidCodec* NewFromData(sk_sp<SkData> data, SkPngChunkReader* reader) {
+        return MakeFromData(std::move(data), reader).release();
+    }
     static SkAndroidCodec* NewFromData(SkData* data, SkPngChunkReader* reader) {
         return NewFromData(sk_ref_sp(data), reader);
     }
+#endif
 
     virtual ~SkAndroidCodec() {}
 
diff --git a/include/codec/SkCodec.h b/include/codec/SkCodec.h
index bb780f0..1d6d904 100644
--- a/include/codec/SkCodec.h
+++ b/include/codec/SkCodec.h
@@ -139,8 +139,8 @@
      *  If NULL is returned, the stream is deleted immediately. Otherwise, the
      *  SkCodec takes ownership of it, and will delete it when done with it.
      */
-    static SkCodec* NewFromStream(SkStream*, Result* = nullptr,
-                                  SkPngChunkReader* = nullptr);
+    static std::unique_ptr<SkCodec> MakeFromStream(std::unique_ptr<SkStream>, Result* = nullptr,
+                                                   SkPngChunkReader* = nullptr);
 
     /**
      *  If this data represents an encoded image that we know how to decode,
@@ -158,10 +158,15 @@
      *      If the PNG does not contain unknown chunks, the SkPngChunkReader
      *      will not be used or modified.
      */
-    static SkCodec* NewFromData(sk_sp<SkData>, SkPngChunkReader* = NULL);
+    static std::unique_ptr<SkCodec> MakeFromData(sk_sp<SkData>, SkPngChunkReader* = nullptr);
+
+#ifdef SK_SUPPORT_LEGACY_CODEC_NEW
+    static SkCodec* NewFromStream(SkStream* str, Result* res, SkPngChunkReader* chunk);
+    static SkCodec* NewFromData(sk_sp<SkData>, SkPngChunkReader* = nullptr);
     static SkCodec* NewFromData(SkData* data, SkPngChunkReader* reader) {
         return NewFromData(sk_ref_sp(data), reader);
     }
+#endif
 
     virtual ~SkCodec();
 
@@ -674,25 +679,21 @@
 protected:
     using XformFormat = SkColorSpaceXform::ColorFormat;
 
-    /**
-     *  Takes ownership of SkStream*
-     */
     SkCodec(int width,
             int height,
             const SkEncodedInfo&,
             XformFormat srcFormat,
-            SkStream*,
+            std::unique_ptr<SkStream>,
             sk_sp<SkColorSpace>,
             Origin = kTopLeft_Origin);
 
     /**
-     *  Takes ownership of SkStream*
      *  Allows the subclass to set the recommended SkImageInfo
      */
     SkCodec(const SkEncodedInfo&,
             const SkImageInfo&,
             XformFormat srcFormat,
-            SkStream*,
+            std::unique_ptr<SkStream>,
             Origin = kTopLeft_Origin);
 
     virtual SkISize onGetScaledDimensions(float /*desiredScale*/) const {
diff --git a/samplecode/DecodeFile.h b/samplecode/DecodeFile.h
index 1ae98a4..eeb1cce 100644
--- a/samplecode/DecodeFile.h
+++ b/samplecode/DecodeFile.h
@@ -17,7 +17,7 @@
                                SkColorType colorType = kN32_SkColorType,
                                bool requireUnpremul = false) {
     sk_sp<SkData> data(SkData::MakeFromFileName(filename));
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(data));
+    std::unique_ptr<SkCodec> codec = SkCodec::MakeFromData(data);
     if (!codec) {
         return false;
     }
diff --git a/src/android/SkBitmapRegionDecoder.cpp b/src/android/SkBitmapRegionDecoder.cpp
index 8298fb5..a6e3ac6 100644
--- a/src/android/SkBitmapRegionDecoder.cpp
+++ b/src/android/SkBitmapRegionDecoder.cpp
@@ -22,11 +22,10 @@
     std::unique_ptr<SkStreamRewindable> streamDeleter(stream);
     switch (strategy) {
         case kAndroidCodec_Strategy: {
-            std::unique_ptr<SkAndroidCodec> codec(
-                    SkAndroidCodec::NewFromStream(streamDeleter.release()));
+            auto codec = SkAndroidCodec::MakeFromStream(std::move(streamDeleter));
             if (nullptr == codec) {
                 SkCodecPrintf("Error: Failed to create codec.\n");
-                return NULL;
+                return nullptr;
             }
 
             switch ((SkEncodedImageFormat)codec->getEncodedFormat()) {
diff --git a/src/codec/SkAndroidCodec.cpp b/src/codec/SkAndroidCodec.cpp
index 0245ea2..3a23e06 100644
--- a/src/codec/SkAndroidCodec.cpp
+++ b/src/codec/SkAndroidCodec.cpp
@@ -8,6 +8,7 @@
 #include "SkAndroidCodec.h"
 #include "SkCodec.h"
 #include "SkCodecPriv.h"
+#include "SkMakeUnique.h"
 #include "SkRawAdapterCodec.h"
 #include "SkSampledCodec.h"
 #include "SkWebpAdapterCodec.h"
@@ -65,8 +66,8 @@
     , fCodec(codec)
 {}
 
-SkAndroidCodec* SkAndroidCodec::NewFromStream(SkStream* stream, SkPngChunkReader* chunkReader) {
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromStream(stream, nullptr, chunkReader));
+std::unique_ptr<SkAndroidCodec> SkAndroidCodec::MakeFromStream(std::unique_ptr<SkStream> stream, SkPngChunkReader* chunkReader) {
+    auto codec = SkCodec::MakeFromStream(std::move(stream), nullptr, chunkReader);
     if (nullptr == codec) {
         return nullptr;
     }
@@ -82,26 +83,27 @@
         case SkEncodedImageFormat::kGIF:
         case SkEncodedImageFormat::kBMP:
         case SkEncodedImageFormat::kWBMP:
-            return new SkSampledCodec(codec.release());
+            return skstd::make_unique<SkSampledCodec>(codec.release());
 #ifdef SK_HAS_WEBP_LIBRARY
         case SkEncodedImageFormat::kWEBP:
-            return new SkWebpAdapterCodec((SkWebpCodec*) codec.release());
+            return skstd::make_unique<SkWebpAdapterCodec>((SkWebpCodec*) codec.release());
 #endif
 #ifdef SK_CODEC_DECODES_RAW
         case SkEncodedImageFormat::kDNG:
-            return new SkRawAdapterCodec((SkRawCodec*)codec.release());
+            return skstd::make_unique<SkRawAdapterCodec>((SkRawCodec*)codec.release());
 #endif
         default:
             return nullptr;
     }
 }
 
-SkAndroidCodec* SkAndroidCodec::NewFromData(sk_sp<SkData> data, SkPngChunkReader* chunkReader) {
+std::unique_ptr<SkAndroidCodec> SkAndroidCodec::MakeFromData(sk_sp<SkData> data,
+                                                             SkPngChunkReader* chunkReader) {
     if (!data) {
         return nullptr;
     }
 
-    return NewFromStream(new SkMemoryStream(data), chunkReader);
+    return MakeFromStream(skstd::make_unique<SkMemoryStream>(std::move(data)), chunkReader);
 }
 
 SkColorType SkAndroidCodec::computeOutputColorType(SkColorType requestedColorType) {
diff --git a/src/codec/SkBmpBaseCodec.cpp b/src/codec/SkBmpBaseCodec.cpp
index 0e74435..1071ff3 100644
--- a/src/codec/SkBmpBaseCodec.cpp
+++ b/src/codec/SkBmpBaseCodec.cpp
@@ -9,8 +9,9 @@
 
 SkBmpBaseCodec::~SkBmpBaseCodec() {}
 
-SkBmpBaseCodec::SkBmpBaseCodec(int width, int height, const SkEncodedInfo& info, SkStream* stream,
+SkBmpBaseCodec::SkBmpBaseCodec(int width, int height, const SkEncodedInfo& info,
+                               std::unique_ptr<SkStream> stream,
                                uint16_t bitsPerPixel, SkCodec::SkScanlineOrder rowOrder)
-    : INHERITED(width, height, info, stream, bitsPerPixel, rowOrder)
+    : INHERITED(width, height, info, std::move(stream), bitsPerPixel, rowOrder)
     , fSrcBuffer(sk_malloc_flags(this->srcRowBytes(), 0))
 {}
diff --git a/src/codec/SkBmpBaseCodec.h b/src/codec/SkBmpBaseCodec.h
index 0b9f919..24277fc 100644
--- a/src/codec/SkBmpBaseCodec.h
+++ b/src/codec/SkBmpBaseCodec.h
@@ -25,7 +25,7 @@
     bool didCreateSrcBuffer() const { return fSrcBuffer != nullptr; }
 
 protected:
-    SkBmpBaseCodec(int width, int height, const SkEncodedInfo& info, SkStream* stream,
+    SkBmpBaseCodec(int width, int height, const SkEncodedInfo& info, std::unique_ptr<SkStream>,
                    uint16_t bitsPerPixel, SkCodec::SkScanlineOrder rowOrder);
 
     uint8_t* srcBuffer() { return reinterpret_cast<uint8_t*>(fSrcBuffer.get()); }
diff --git a/src/codec/SkBmpCodec.cpp b/src/codec/SkBmpCodec.cpp
index 70397f6..18f8768 100644
--- a/src/codec/SkBmpCodec.cpp
+++ b/src/codec/SkBmpCodec.cpp
@@ -67,16 +67,17 @@
  * Creates a bmp decoder
  * Reads enough of the stream to determine the image format
  */
-SkCodec* SkBmpCodec::NewFromStream(SkStream* stream, Result* result) {
-    return SkBmpCodec::NewFromStream(stream, result, false);
+std::unique_ptr<SkCodec> SkBmpCodec::MakeFromStream(std::unique_ptr<SkStream> stream,
+                                                    Result* result) {
+    return SkBmpCodec::MakeFromStream(std::move(stream), result, false);
 }
 
 /*
  * Creates a bmp decoder for a bmp embedded in ico
  * Reads enough of the stream to determine the image format
  */
-SkCodec* SkBmpCodec::NewFromIco(SkStream* stream, Result* result) {
-    return SkBmpCodec::NewFromStream(stream, result, true);
+std::unique_ptr<SkCodec> SkBmpCodec::MakeFromIco(std::unique_ptr<SkStream> stream, Result* result) {
+    return SkBmpCodec::MakeFromStream(std::move(stream), result, true);
 }
 
 // Header size constants
@@ -476,9 +477,11 @@
 
                 // Set the image info and create a codec.
                 const SkEncodedInfo info = SkEncodedInfo::Make(color, alpha, bitsPerComponent);
-                codecOut->reset(new SkBmpStandardCodec(width, height, info, stream, bitsPerPixel,
-                                                       numColors, bytesPerColor, offset - bytesRead,
-                                                       rowOrder, isOpaque, inIco));
+                codecOut->reset(new SkBmpStandardCodec(width, height, info,
+                                                       std::unique_ptr<SkStream>(stream),
+                                                       bitsPerPixel, numColors, bytesPerColor,
+                                                       offset - bytesRead, rowOrder, isOpaque,
+                                                       inIco));
                 return static_cast<SkBmpStandardCodec*>(codecOut->get())->didCreateSrcBuffer()
                         ? kSuccess : kInvalidInput;
             }
@@ -532,7 +535,8 @@
                     alpha = SkEncodedInfo::kOpaque_Alpha;
                 }
                 const SkEncodedInfo info = SkEncodedInfo::Make(color, alpha, 8);
-                codecOut->reset(new SkBmpMaskCodec(width, height, info, stream, bitsPerPixel,
+                codecOut->reset(new SkBmpMaskCodec(width, height, info,
+                                                   std::unique_ptr<SkStream>(stream), bitsPerPixel,
                                                    masks.release(), rowOrder));
                 return static_cast<SkBmpMaskCodec*>(codecOut->get())->didCreateSrcBuffer()
                         ? kSuccess : kInvalidInput;
@@ -563,7 +567,8 @@
                 // For that reason, we always indicate that we are kBGRA.
                 const SkEncodedInfo info = SkEncodedInfo::Make(SkEncodedInfo::kBGRA_Color,
                         SkEncodedInfo::kBinary_Alpha, 8);
-                codecOut->reset(new SkBmpRLECodec(width, height, info, stream, bitsPerPixel,
+                codecOut->reset(new SkBmpRLECodec(width, height, info,
+                                                  std::unique_ptr<SkStream>(stream), bitsPerPixel,
                                                   numColors, bytesPerColor, offset - bytesRead,
                                                   rowOrder));
             }
@@ -579,21 +584,22 @@
  * Creates a bmp decoder
  * Reads enough of the stream to determine the image format
  */
-SkCodec* SkBmpCodec::NewFromStream(SkStream* stream, Result* result, bool inIco) {
-    std::unique_ptr<SkStream> streamDeleter(stream);
+std::unique_ptr<SkCodec> SkBmpCodec::MakeFromStream(std::unique_ptr<SkStream> stream,
+                                                    Result* result, bool inIco) {
     std::unique_ptr<SkCodec> codec;
-    *result = ReadHeader(stream, inIco, &codec);
+    *result = ReadHeader(stream.get(), inIco, &codec);
     if (codec) {
-        // codec has taken ownership of stream, so we do not need to
-        // delete it.
-        streamDeleter.release();
+        // codec has taken ownership of stream, so we do not need to delete it.
+        stream.release();
     }
-    return kSuccess == *result ? codec.release() : nullptr;
+    return kSuccess == *result ? std::move(codec) : nullptr;
 }
 
-SkBmpCodec::SkBmpCodec(int width, int height, const SkEncodedInfo& info, SkStream* stream,
+SkBmpCodec::SkBmpCodec(int width, int height, const SkEncodedInfo& info,
+                       std::unique_ptr<SkStream> stream,
         uint16_t bitsPerPixel, SkCodec::SkScanlineOrder rowOrder)
-    : INHERITED(width, height, info, kXformSrcColorFormat, stream, SkColorSpace::MakeSRGB())
+    : INHERITED(width, height, info, kXformSrcColorFormat, std::move(stream),
+                SkColorSpace::MakeSRGB())
     , fBitsPerPixel(bitsPerPixel)
     , fRowOrder(rowOrder)
     , fSrcRowBytes(SkAlign4(compute_row_bytes(width, fBitsPerPixel)))
diff --git a/src/codec/SkBmpCodec.h b/src/codec/SkBmpCodec.h
index d5f5a32..651f1be 100644
--- a/src/codec/SkBmpCodec.h
+++ b/src/codec/SkBmpCodec.h
@@ -28,17 +28,17 @@
      * Creates a bmp decoder
      * Reads enough of the stream to determine the image format
      */
-    static SkCodec* NewFromStream(SkStream*, Result*);
+    static std::unique_ptr<SkCodec> MakeFromStream(std::unique_ptr<SkStream>, Result*);
 
     /*
      * Creates a bmp decoder for a bmp embedded in ico
      * Reads enough of the stream to determine the image format
      */
-    static SkCodec* NewFromIco(SkStream*, Result*);
+    static std::unique_ptr<SkCodec> MakeFromIco(std::unique_ptr<SkStream>, Result*);
 
 protected:
 
-    SkBmpCodec(int width, int height, const SkEncodedInfo& info, SkStream* stream,
+    SkBmpCodec(int width, int height, const SkEncodedInfo& info, std::unique_ptr<SkStream>,
             uint16_t bitsPerPixel, SkCodec::SkScanlineOrder rowOrder);
 
     SkEncodedImageFormat onGetEncodedFormat() const override { return SkEncodedImageFormat::kBMP; }
@@ -46,7 +46,6 @@
     /*
      * Read enough of the stream to initialize the SkBmpCodec.
      * On kSuccess, if codecOut is not nullptr, it will be set to a new SkBmpCodec.
-     * If an SkCodec is created, it will take ownership of the SkStream.
      */
     static Result ReadHeader(SkStream*, bool inIco, std::unique_ptr<SkCodec>* codecOut);
 
@@ -112,7 +111,7 @@
      * Creates a bmp decoder
      * Reads enough of the stream to determine the image format
      */
-    static SkCodec* NewFromStream(SkStream*, Result*, bool inIco);
+    static std::unique_ptr<SkCodec> MakeFromStream(std::unique_ptr<SkStream>, Result*, bool inIco);
 
     /*
      * Decodes the next dstInfo.height() lines.
diff --git a/src/codec/SkBmpMaskCodec.cpp b/src/codec/SkBmpMaskCodec.cpp
index 51060e5..aec56ee 100644
--- a/src/codec/SkBmpMaskCodec.cpp
+++ b/src/codec/SkBmpMaskCodec.cpp
@@ -12,10 +12,11 @@
 /*
  * Creates an instance of the decoder
  */
-SkBmpMaskCodec::SkBmpMaskCodec(int width, int height, const SkEncodedInfo& info, SkStream* stream,
+SkBmpMaskCodec::SkBmpMaskCodec(int width, int height, const SkEncodedInfo& info,
+                               std::unique_ptr<SkStream> stream,
                                uint16_t bitsPerPixel, SkMasks* masks,
                                SkCodec::SkScanlineOrder rowOrder)
-    : INHERITED(width, height, info, stream, bitsPerPixel, rowOrder)
+    : INHERITED(width, height, info, std::move(stream), bitsPerPixel, rowOrder)
     , fMasks(masks)
     , fMaskSwizzler(nullptr)
 {}
diff --git a/src/codec/SkBmpMaskCodec.h b/src/codec/SkBmpMaskCodec.h
index 8d8d64c..4b0dbde 100644
--- a/src/codec/SkBmpMaskCodec.h
+++ b/src/codec/SkBmpMaskCodec.h
@@ -22,7 +22,7 @@
     /*
      * Creates an instance of the decoder
      *
-     * Called only by SkBmpCodec::NewFromStream
+     * Called only by SkBmpCodec::MakeFromStream
      * There should be no other callers despite this being public
      *
      * @param info contains properties of the encoded data
@@ -31,7 +31,7 @@
      * @param masks color masks for certain bmp formats
      * @param rowOrder indicates whether rows are ordered top-down or bottom-up
      */
-    SkBmpMaskCodec(int width, int height, const SkEncodedInfo& info, SkStream* stream,
+    SkBmpMaskCodec(int width, int height, const SkEncodedInfo& info, std::unique_ptr<SkStream>,
             uint16_t bitsPerPixel, SkMasks* masks,
             SkCodec::SkScanlineOrder rowOrder);
 
diff --git a/src/codec/SkBmpRLECodec.cpp b/src/codec/SkBmpRLECodec.cpp
index 0fcd290..23a2c98 100644
--- a/src/codec/SkBmpRLECodec.cpp
+++ b/src/codec/SkBmpRLECodec.cpp
@@ -14,11 +14,12 @@
  * Creates an instance of the decoder
  * Called only by NewFromStream
  */
-SkBmpRLECodec::SkBmpRLECodec(int width, int height, const SkEncodedInfo& info, SkStream* stream,
+SkBmpRLECodec::SkBmpRLECodec(int width, int height, const SkEncodedInfo& info,
+                             std::unique_ptr<SkStream> stream,
                              uint16_t bitsPerPixel, uint32_t numColors,
                              uint32_t bytesPerColor, uint32_t offset,
                              SkCodec::SkScanlineOrder rowOrder)
-    : INHERITED(width, height, info, stream, bitsPerPixel, rowOrder)
+    : INHERITED(width, height, info, std::move(stream), bitsPerPixel, rowOrder)
     , fColorTable(nullptr)
     , fNumColors(numColors)
     , fBytesPerColor(bytesPerColor)
diff --git a/src/codec/SkBmpRLECodec.h b/src/codec/SkBmpRLECodec.h
index d6c17c3..70e97a7 100644
--- a/src/codec/SkBmpRLECodec.h
+++ b/src/codec/SkBmpRLECodec.h
@@ -22,7 +22,7 @@
     /*
      * Creates an instance of the decoder
      *
-     * Called only by SkBmpCodec::NewFromStream
+     * Called only by SkBmpCodec::MakeFromStream
      * There should be no other callers despite this being public
      *
      * @param info contains properties of the encoded data
@@ -35,7 +35,7 @@
      *               headers
      * @param rowOrder indicates whether rows are ordered top-down or bottom-up
      */
-    SkBmpRLECodec(int width, int height, const SkEncodedInfo& info, SkStream* stream,
+    SkBmpRLECodec(int width, int height, const SkEncodedInfo& info, std::unique_ptr<SkStream>,
             uint16_t bitsPerPixel, uint32_t numColors, uint32_t bytesPerColor,
             uint32_t offset, SkCodec::SkScanlineOrder rowOrder);
 
diff --git a/src/codec/SkBmpStandardCodec.cpp b/src/codec/SkBmpStandardCodec.cpp
index 46a5715..53aa91c 100644
--- a/src/codec/SkBmpStandardCodec.cpp
+++ b/src/codec/SkBmpStandardCodec.cpp
@@ -15,11 +15,11 @@
  * Called only by NewFromStream
  */
 SkBmpStandardCodec::SkBmpStandardCodec(int width, int height, const SkEncodedInfo& info,
-                                       SkStream* stream, uint16_t bitsPerPixel, uint32_t numColors,
-                                       uint32_t bytesPerColor, uint32_t offset,
+                                       std::unique_ptr<SkStream> stream, uint16_t bitsPerPixel,
+                                       uint32_t numColors, uint32_t bytesPerColor, uint32_t offset,
                                        SkCodec::SkScanlineOrder rowOrder,
                                        bool isOpaque, bool inIco)
-    : INHERITED(width, height, info, stream, bitsPerPixel, rowOrder)
+    : INHERITED(width, height, info, std::move(stream), bitsPerPixel, rowOrder)
     , fColorTable(nullptr)
     , fNumColors(numColors)
     , fBytesPerColor(bytesPerColor)
diff --git a/src/codec/SkBmpStandardCodec.h b/src/codec/SkBmpStandardCodec.h
index f9ce5c6..60587fb 100644
--- a/src/codec/SkBmpStandardCodec.h
+++ b/src/codec/SkBmpStandardCodec.h
@@ -23,7 +23,7 @@
     /*
      * Creates an instance of the decoder
      *
-     * Called only by SkBmpCodec::NewFromStream
+     * Called only by SkBmpCodec::MakeFromStream
      * There should be no other callers despite this being public
      *
      * @param info contains properties of the encoded data
@@ -39,10 +39,10 @@
      *                 the icp mask, if there is one)
      * @param inIco    indicates if the bmp is embedded in an ico file
      */
-    SkBmpStandardCodec(int width, int height, const SkEncodedInfo& info, SkStream* stream,
-            uint16_t bitsPerPixel, uint32_t numColors, uint32_t bytesPerColor,
-            uint32_t offset, SkCodec::SkScanlineOrder rowOrder, bool isOpaque,
-            bool inIco);
+    SkBmpStandardCodec(int width, int height, const SkEncodedInfo& info,
+                       std::unique_ptr<SkStream> stream, uint16_t bitsPerPixel, uint32_t numColors,
+                       uint32_t bytesPerColor, uint32_t offset, SkCodec::SkScanlineOrder rowOrder,
+                       bool isOpaque, bool inIco);
 
 protected:
 
diff --git a/src/codec/SkCodec.cpp b/src/codec/SkCodec.cpp
index 872fe2b..4fb0ea9 100644
--- a/src/codec/SkCodec.cpp
+++ b/src/codec/SkCodec.cpp
@@ -26,30 +26,30 @@
 
 struct DecoderProc {
     bool (*IsFormat)(const void*, size_t);
-    SkCodec* (*NewFromStream)(SkStream*, SkCodec::Result*);
+    std::unique_ptr<SkCodec> (*MakeFromStream)(std::unique_ptr<SkStream>, SkCodec::Result*);
 };
 
 static const DecoderProc gDecoderProcs[] = {
 #ifdef SK_HAS_JPEG_LIBRARY
-    { SkJpegCodec::IsJpeg, SkJpegCodec::NewFromStream },
+    { SkJpegCodec::IsJpeg, SkJpegCodec::MakeFromStream },
 #endif
 #ifdef SK_HAS_WEBP_LIBRARY
-    { SkWebpCodec::IsWebp, SkWebpCodec::NewFromStream },
+    { SkWebpCodec::IsWebp, SkWebpCodec::MakeFromStream },
 #endif
-    { SkGifCodec::IsGif, SkGifCodec::NewFromStream },
+    { SkGifCodec::IsGif, SkGifCodec::MakeFromStream },
 #ifdef SK_HAS_PNG_LIBRARY
-    { SkIcoCodec::IsIco, SkIcoCodec::NewFromStream },
+    { SkIcoCodec::IsIco, SkIcoCodec::MakeFromStream },
 #endif
-    { SkBmpCodec::IsBmp, SkBmpCodec::NewFromStream },
-    { SkWbmpCodec::IsWbmp, SkWbmpCodec::NewFromStream }
+    { SkBmpCodec::IsBmp, SkBmpCodec::MakeFromStream },
+    { SkWbmpCodec::IsWbmp, SkWbmpCodec::MakeFromStream }
 };
 
 size_t SkCodec::MinBufferedBytesNeeded() {
     return WEBP_VP8_HEADER_SIZE;
 }
 
-SkCodec* SkCodec::NewFromStream(SkStream* stream,
-        Result* outResult, SkPngChunkReader* chunkReader) {
+std::unique_ptr<SkCodec> SkCodec::MakeFromStream(std::unique_ptr<SkStream> stream,
+                                                 Result* outResult, SkPngChunkReader* chunkReader) {
     Result resultStorage;
     if (!outResult) {
         outResult = &resultStorage;
@@ -60,8 +60,6 @@
         return nullptr;
     }
 
-    std::unique_ptr<SkStream> streamDeleter(stream);
-
     // 14 is enough to read all of the supported types.
     const size_t bytesToRead = 14;
     SkASSERT(bytesToRead <= MinBufferedBytesNeeded());
@@ -96,19 +94,19 @@
     // But this code follows the same pattern as the loop.
 #ifdef SK_HAS_PNG_LIBRARY
     if (SkPngCodec::IsPng(buffer, bytesRead)) {
-        return SkPngCodec::NewFromStream(streamDeleter.release(), outResult, chunkReader);
+        return SkPngCodec::MakeFromStream(std::move(stream), outResult, chunkReader);
     } else
 #endif
     {
         for (DecoderProc proc : gDecoderProcs) {
             if (proc.IsFormat(buffer, bytesRead)) {
-                return proc.NewFromStream(streamDeleter.release(), outResult);
+                return proc.MakeFromStream(std::move(stream), outResult);
             }
         }
 
 #ifdef SK_CODEC_DECODES_RAW
         // Try to treat the input as RAW if all the other checks failed.
-        return SkRawCodec::NewFromStream(streamDeleter.release(), outResult);
+        return SkRawCodec::MakeFromStream(std::move(stream), outResult);
 #endif
     }
 
@@ -121,20 +119,21 @@
     return nullptr;
 }
 
-SkCodec* SkCodec::NewFromData(sk_sp<SkData> data, SkPngChunkReader* reader) {
+std::unique_ptr<SkCodec> SkCodec::MakeFromData(sk_sp<SkData> data, SkPngChunkReader* reader) {
     if (!data) {
         return nullptr;
     }
-    return NewFromStream(new SkMemoryStream(data), nullptr, reader);
+    return MakeFromStream(std::unique_ptr<SkStream>(new SkMemoryStream(std::move(data))),
+                                                    nullptr, reader);
 }
 
 SkCodec::SkCodec(int width, int height, const SkEncodedInfo& info,
-        XformFormat srcFormat, SkStream* stream,
+        XformFormat srcFormat, std::unique_ptr<SkStream> stream,
         sk_sp<SkColorSpace> colorSpace, Origin origin)
     : fEncodedInfo(info)
     , fSrcInfo(info.makeImageInfo(width, height, std::move(colorSpace)))
     , fSrcXformFormat(srcFormat)
-    , fStream(stream)
+    , fStream(std::move(stream))
     , fNeedsRewind(false)
     , fOrigin(origin)
     , fDstInfo()
@@ -143,11 +142,11 @@
 {}
 
 SkCodec::SkCodec(const SkEncodedInfo& info, const SkImageInfo& imageInfo,
-        XformFormat srcFormat, SkStream* stream, Origin origin)
+        XformFormat srcFormat, std::unique_ptr<SkStream> stream, Origin origin)
     : fEncodedInfo(info)
     , fSrcInfo(imageInfo)
     , fSrcXformFormat(srcFormat)
-    , fStream(stream)
+    , fStream(std::move(stream))
     , fNeedsRewind(false)
     , fOrigin(origin)
     , fDstInfo()
@@ -619,3 +618,12 @@
     }
     return result;
 }
+
+#ifdef SK_SUPPORT_LEGACY_CODEC_NEW
+SkCodec* SkCodec::NewFromStream(SkStream* str, Result* res, SkPngChunkReader* chunk) {
+    return MakeFromStream(std::unique_ptr<SkStream*>(str), res, chunk).release();
+}
+SkCodec* SkCodec::NewFromData(sk_sp<SkData> data, SkPngChunkReader* chunk) {
+    return MakeFromData(std::move(data), chunk).release();
+}
+#endif
diff --git a/src/codec/SkCodecImageGenerator.cpp b/src/codec/SkCodecImageGenerator.cpp
index 7be6277..e6ca212 100644
--- a/src/codec/SkCodecImageGenerator.cpp
+++ b/src/codec/SkCodecImageGenerator.cpp
@@ -9,12 +9,12 @@
 #include "SkMakeUnique.h"
 
 std::unique_ptr<SkImageGenerator> SkCodecImageGenerator::MakeFromEncodedCodec(sk_sp<SkData> data) {
-    SkCodec* codec = SkCodec::NewFromData(data);
+    auto codec = SkCodec::MakeFromData(data);
     if (nullptr == codec) {
         return nullptr;
     }
 
-    return std::unique_ptr<SkImageGenerator>(new SkCodecImageGenerator(codec, data));
+    return std::unique_ptr<SkImageGenerator>(new SkCodecImageGenerator(std::move(codec), data));
 }
 
 static SkImageInfo adjust_info(const SkImageInfo& info) {
@@ -25,9 +25,9 @@
     return newInfo;
 }
 
-SkCodecImageGenerator::SkCodecImageGenerator(SkCodec* codec, sk_sp<SkData> data)
+SkCodecImageGenerator::SkCodecImageGenerator(std::unique_ptr<SkCodec> codec, sk_sp<SkData> data)
     : INHERITED(adjust_info(codec->getInfo()))
-    , fCodec(codec)
+    , fCodec(std::move(codec))
     , fData(std::move(data))
 {}
 
diff --git a/src/codec/SkCodecImageGenerator.h b/src/codec/SkCodecImageGenerator.h
index 4d0c078..1b2cbc2 100644
--- a/src/codec/SkCodecImageGenerator.h
+++ b/src/codec/SkCodecImageGenerator.h
@@ -34,7 +34,7 @@
     /*
      * Takes ownership of codec
      */
-    SkCodecImageGenerator(SkCodec* codec, sk_sp<SkData>);
+    SkCodecImageGenerator(std::unique_ptr<SkCodec>, sk_sp<SkData>);
 
     std::unique_ptr<SkCodec> fCodec;
     sk_sp<SkData> fData;
diff --git a/src/codec/SkGifCodec.cpp b/src/codec/SkGifCodec.cpp
index 412b8ff..d54cbd5 100644
--- a/src/codec/SkGifCodec.cpp
+++ b/src/codec/SkGifCodec.cpp
@@ -35,6 +35,7 @@
 #include "SkColorPriv.h"
 #include "SkColorTable.h"
 #include "SkGifCodec.h"
+#include "SkMakeUnique.h"
 #include "SkRasterPipeline.h"
 #include "SkStream.h"
 #include "SkSwizzler.h"
@@ -68,8 +69,9 @@
     return result;
 }
 
-SkCodec* SkGifCodec::NewFromStream(SkStream* stream, Result* result) {
-    std::unique_ptr<SkGifImageReader> reader(new SkGifImageReader(stream));
+std::unique_ptr<SkCodec> SkGifCodec::MakeFromStream(std::unique_ptr<SkStream> stream,
+                                                    Result* result) {
+    std::unique_ptr<SkGifImageReader> reader(new SkGifImageReader(std::move(stream)));
     *result = reader->parse(SkGifImageReader::SkGIFSizeQuery);
     if (*result != kSuccess) {
         return nullptr;
@@ -102,7 +104,7 @@
     const auto imageInfo = SkImageInfo::Make(reader->screenWidth(), reader->screenHeight(),
                                              kN32_SkColorType, alphaType,
                                              SkColorSpace::MakeSRGB());
-    return new SkGifCodec(encodedInfo, imageInfo, reader.release());
+    return std::unique_ptr<SkCodec>(new SkGifCodec(encodedInfo, imageInfo, reader.release()));
 }
 
 bool SkGifCodec::onRewind() {
diff --git a/src/codec/SkGifCodec.h b/src/codec/SkGifCodec.h
index 6ecd419..89c84bd 100644
--- a/src/codec/SkGifCodec.h
+++ b/src/codec/SkGifCodec.h
@@ -29,7 +29,7 @@
      * Assumes IsGif was called and returned true
      * Reads enough of the stream to determine the image format
      */
-    static SkCodec* NewFromStream(SkStream*, Result*);
+    static std::unique_ptr<SkCodec> MakeFromStream(std::unique_ptr<SkStream>, Result*);
 
     // Callback for SkGifImageReader when a row is available.
     bool haveDecodedRow(int frameIndex, const unsigned char* rowBegin,
diff --git a/src/codec/SkIcoCodec.cpp b/src/codec/SkIcoCodec.cpp
index 2e61bfe..fce14a2 100644
--- a/src/codec/SkIcoCodec.cpp
+++ b/src/codec/SkIcoCodec.cpp
@@ -26,18 +26,15 @@
             !memcmp(buffer, curSig, sizeof(curSig)));
 }
 
-SkCodec* SkIcoCodec::NewFromStream(SkStream* stream, Result* result) {
-    // Ensure that we do not leak the input stream
-    std::unique_ptr<SkStream> inputStream(stream);
-
+std::unique_ptr<SkCodec> SkIcoCodec::MakeFromStream(std::unique_ptr<SkStream> stream,
+                                                    Result* result) {
     // Header size constants
     static const uint32_t kIcoDirectoryBytes = 6;
     static const uint32_t kIcoDirEntryBytes = 16;
 
     // Read the directory header
     std::unique_ptr<uint8_t[]> dirBuffer(new uint8_t[kIcoDirectoryBytes]);
-    if (inputStream.get()->read(dirBuffer.get(), kIcoDirectoryBytes) !=
-            kIcoDirectoryBytes) {
+    if (stream->read(dirBuffer.get(), kIcoDirectoryBytes) != kIcoDirectoryBytes) {
         SkCodecPrintf("Error: unable to read ico directory header.\n");
         *result = kIncompleteInput;
         return nullptr;
@@ -71,8 +68,7 @@
     // Iterate over directory entries
     for (uint32_t i = 0; i < numImages; i++) {
         uint8_t entryBuffer[kIcoDirEntryBytes];
-        if (inputStream->read(entryBuffer, kIcoDirEntryBytes) !=
-                kIcoDirEntryBytes) {
+        if (stream->read(entryBuffer, kIcoDirEntryBytes) != kIcoDirEntryBytes) {
             SkCodecPrintf("Error: Dir entries truncated in ico.\n");
             *result = kIncompleteInput;
             return nullptr;
@@ -128,7 +124,7 @@
 
         // If we cannot skip, assume we have reached the end of the stream and
         // stop trying to make codecs
-        if (inputStream.get()->skip(offset - bytesRead) != offset - bytesRead) {
+        if (stream->skip(offset - bytesRead) != offset - bytesRead) {
             SkCodecPrintf("Warning: could not skip to ico offset.\n");
             break;
         }
@@ -141,7 +137,7 @@
             break;
         }
 
-        if (inputStream->read(buffer.get(), size) != size) {
+        if (stream->read(buffer.get(), size) != size) {
             SkCodecPrintf("Warning: could not create embedded stream.\n");
             *result = kIncompleteInput;
             break;
@@ -152,17 +148,17 @@
         bytesRead += size;
 
         // Check if the embedded codec is bmp or png and create the codec
-        SkCodec* codec = nullptr;
+        std::unique_ptr<SkCodec> codec;
         Result dummyResult;
         if (SkPngCodec::IsPng((const char*) data->bytes(), data->size())) {
-            codec = SkPngCodec::NewFromStream(embeddedStream.release(), &dummyResult);
+            codec = SkPngCodec::MakeFromStream(std::move(embeddedStream), &dummyResult);
         } else {
-            codec = SkBmpCodec::NewFromIco(embeddedStream.release(), &dummyResult);
+            codec = SkBmpCodec::MakeFromIco(std::move(embeddedStream), &dummyResult);
         }
 
         // Save a valid codec
         if (nullptr != codec) {
-            codecs->push_back().reset(codec);
+            codecs->push_back().reset(codec.release());
         }
     }
 
@@ -192,7 +188,8 @@
     *result = kSuccess;
     // The original stream is no longer needed, because the embedded codecs own their
     // own streams.
-    return new SkIcoCodec(width, height, info, codecs.release(), sk_ref_sp(colorSpace));
+    return std::unique_ptr<SkCodec>(new SkIcoCodec(width, height, info, codecs.release(),
+                                                   sk_ref_sp(colorSpace)));
 }
 
 /*
diff --git a/src/codec/SkIcoCodec.h b/src/codec/SkIcoCodec.h
index 0c27934..aa19c9b 100644
--- a/src/codec/SkIcoCodec.h
+++ b/src/codec/SkIcoCodec.h
@@ -25,7 +25,7 @@
      * Creates an Ico decoder
      * Reads enough of the stream to determine the image format
      */
-    static SkCodec* NewFromStream(SkStream*, Result*);
+    static std::unique_ptr<SkCodec> MakeFromStream(std::unique_ptr<SkStream>, Result*);
 
 protected:
 
diff --git a/src/codec/SkJpegCodec.cpp b/src/codec/SkJpegCodec.cpp
index f3dbdf1..8f88138 100644
--- a/src/codec/SkJpegCodec.cpp
+++ b/src/codec/SkJpegCodec.cpp
@@ -252,8 +252,9 @@
 
         const int width = decoderMgr->dinfo()->image_width;
         const int height = decoderMgr->dinfo()->image_height;
-        SkJpegCodec* codec = new SkJpegCodec(width, height, info, stream, decoderMgr.release(),
-                                             std::move(colorSpace), orientation);
+        SkJpegCodec* codec = new SkJpegCodec(width, height, info, std::unique_ptr<SkStream>(stream),
+                                             decoderMgr.release(), std::move(colorSpace),
+                                             orientation);
         *codecOut = codec;
     } else {
         SkASSERT(nullptr != decoderMgrOut);
@@ -262,27 +263,29 @@
     return kSuccess;
 }
 
-SkCodec* SkJpegCodec::NewFromStream(SkStream* stream, Result* result) {
-    return SkJpegCodec::NewFromStream(stream, result, SkColorSpace::MakeSRGB());
+std::unique_ptr<SkCodec> SkJpegCodec::MakeFromStream(std::unique_ptr<SkStream> stream,
+                                                     Result* result) {
+    return SkJpegCodec::MakeFromStream(std::move(stream), result, SkColorSpace::MakeSRGB());
 }
 
-SkCodec* SkJpegCodec::NewFromStream(SkStream* stream, Result* result,
+std::unique_ptr<SkCodec> SkJpegCodec::MakeFromStream(std::unique_ptr<SkStream> stream,
+                                                     Result* result,
                                     sk_sp<SkColorSpace> defaultColorSpace) {
-    std::unique_ptr<SkStream> streamDeleter(stream);
     SkCodec* codec = nullptr;
-    *result = ReadHeader(stream, &codec, nullptr, std::move(defaultColorSpace));
+    *result = ReadHeader(stream.get(), &codec, nullptr, std::move(defaultColorSpace));
     if (kSuccess == *result) {
         // Codec has taken ownership of the stream, we do not need to delete it
         SkASSERT(codec);
-        streamDeleter.release();
-        return codec;
+        stream.release();
+        return std::unique_ptr<SkCodec>(codec);
     }
     return nullptr;
 }
 
-SkJpegCodec::SkJpegCodec(int width, int height, const SkEncodedInfo& info, SkStream* stream,
-        JpegDecoderMgr* decoderMgr, sk_sp<SkColorSpace> colorSpace, Origin origin)
-    : INHERITED(width, height, info, SkColorSpaceXform::kRGBA_8888_ColorFormat, stream,
+SkJpegCodec::SkJpegCodec(int width, int height, const SkEncodedInfo& info,
+                         std::unique_ptr<SkStream> stream, JpegDecoderMgr* decoderMgr,
+                         sk_sp<SkColorSpace> colorSpace, Origin origin)
+    : INHERITED(width, height, info, SkColorSpaceXform::kRGBA_8888_ColorFormat, std::move(stream),
                 std::move(colorSpace), origin)
     , fDecoderMgr(decoderMgr)
     , fReadyState(decoderMgr->dinfo()->global_state)
diff --git a/src/codec/SkJpegCodec.h b/src/codec/SkJpegCodec.h
index 96228f3..1409182 100644
--- a/src/codec/SkJpegCodec.h
+++ b/src/codec/SkJpegCodec.h
@@ -31,7 +31,7 @@
      * Assumes IsJpeg was called and returned true
      * Takes ownership of the stream
      */
-    static SkCodec* NewFromStream(SkStream*, Result*);
+    static std::unique_ptr<SkCodec> MakeFromStream(std::unique_ptr<SkStream>, Result*);
 
 protected:
 
@@ -63,7 +63,8 @@
     /*
      * Allows SkRawCodec to communicate the color space from the exif data.
      */
-    static SkCodec* NewFromStream(SkStream*, Result*, sk_sp<SkColorSpace> defaultColorSpace);
+    static std::unique_ptr<SkCodec> MakeFromStream(std::unique_ptr<SkStream>, Result*,
+                                                   sk_sp<SkColorSpace> defaultColorSpace);
 
     /*
      * Read enough of the stream to initialize the SkJpegCodec.
@@ -99,7 +100,7 @@
      * @param decoderMgr holds decompress struct, src manager, and error manager
      *                   takes ownership
      */
-    SkJpegCodec(int width, int height, const SkEncodedInfo& info, SkStream* stream,
+    SkJpegCodec(int width, int height, const SkEncodedInfo& info, std::unique_ptr<SkStream> stream,
             JpegDecoderMgr* decoderMgr, sk_sp<SkColorSpace> colorSpace, Origin origin);
 
     /*
diff --git a/src/codec/SkPngCodec.cpp b/src/codec/SkPngCodec.cpp
index 560b5bf..13e45ab 100644
--- a/src/codec/SkPngCodec.cpp
+++ b/src/codec/SkPngCodec.cpp
@@ -480,9 +480,10 @@
 
 class SkPngNormalDecoder : public SkPngCodec {
 public:
-    SkPngNormalDecoder(const SkEncodedInfo& info, const SkImageInfo& imageInfo, SkStream* stream,
-            SkPngChunkReader* reader, png_structp png_ptr, png_infop info_ptr, int bitDepth)
-        : INHERITED(info, imageInfo, stream, reader, png_ptr, info_ptr, bitDepth)
+    SkPngNormalDecoder(const SkEncodedInfo& info, const SkImageInfo& imageInfo,
+                       std::unique_ptr<SkStream> stream, SkPngChunkReader* reader,
+                       png_structp png_ptr, png_infop info_ptr, int bitDepth)
+        : INHERITED(info, imageInfo, std::move(stream), reader, png_ptr, info_ptr, bitDepth)
         , fRowsWrittenToOutput(0)
         , fDst(nullptr)
         , fRowBytes(0)
@@ -598,9 +599,9 @@
 class SkPngInterlacedDecoder : public SkPngCodec {
 public:
     SkPngInterlacedDecoder(const SkEncodedInfo& info, const SkImageInfo& imageInfo,
-            SkStream* stream, SkPngChunkReader* reader, png_structp png_ptr, png_infop info_ptr,
-            int bitDepth, int numberPasses)
-        : INHERITED(info, imageInfo, stream, reader, png_ptr, info_ptr, bitDepth)
+            std::unique_ptr<SkStream> stream, SkPngChunkReader* reader, png_structp png_ptr,
+            png_infop info_ptr, int bitDepth, int numberPasses)
+        : INHERITED(info, imageInfo, std::move(stream), reader, png_ptr, info_ptr, bitDepth)
         , fNumberPasses(numberPasses)
         , fFirstRow(0)
         , fLastRow(0)
@@ -922,11 +923,12 @@
         }
 
         if (1 == numberPasses) {
-            *fOutCodec = new SkPngNormalDecoder(encodedInfo, imageInfo, fStream,
-                    fChunkReader, fPng_ptr, fInfo_ptr, bitDepth);
+            *fOutCodec = new SkPngNormalDecoder(encodedInfo, imageInfo,
+                   std::unique_ptr<SkStream>(fStream), fChunkReader, fPng_ptr, fInfo_ptr, bitDepth);
         } else {
-            *fOutCodec = new SkPngInterlacedDecoder(encodedInfo, imageInfo, fStream,
-                    fChunkReader, fPng_ptr, fInfo_ptr, bitDepth, numberPasses);
+            *fOutCodec = new SkPngInterlacedDecoder(encodedInfo, imageInfo,
+                    std::unique_ptr<SkStream>(fStream), fChunkReader, fPng_ptr, fInfo_ptr, bitDepth,
+                    numberPasses);
         }
         static_cast<SkPngCodec*>(*fOutCodec)->setIdatLength(idatLength);
     }
@@ -937,9 +939,9 @@
 }
 
 SkPngCodec::SkPngCodec(const SkEncodedInfo& encodedInfo, const SkImageInfo& imageInfo,
-                       SkStream* stream, SkPngChunkReader* chunkReader, void* png_ptr,
-                       void* info_ptr, int bitDepth)
-    : INHERITED(encodedInfo, imageInfo, png_select_xform_format(encodedInfo), stream)
+                       std::unique_ptr<SkStream> stream, SkPngChunkReader* chunkReader,
+                       void* png_ptr, void* info_ptr, int bitDepth)
+    : INHERITED(encodedInfo, imageInfo, png_select_xform_format(encodedInfo), std::move(stream))
     , fPngChunkReader(SkSafeRef(chunkReader))
     , fPng_ptr(png_ptr)
     , fInfo_ptr(info_ptr)
@@ -1145,15 +1147,14 @@
     return INHERITED::onGetFillValue(dstInfo);
 }
 
-SkCodec* SkPngCodec::NewFromStream(SkStream* stream, Result* result, SkPngChunkReader* chunkReader) {
-    std::unique_ptr<SkStream> streamDeleter(stream);
-
+std::unique_ptr<SkCodec> SkPngCodec::MakeFromStream(std::unique_ptr<SkStream> stream,
+                                                    Result* result, SkPngChunkReader* chunkReader) {
     SkCodec* outCodec = nullptr;
-    *result = read_header(stream, chunkReader, &outCodec, nullptr, nullptr);
+    *result = read_header(stream.get(), chunkReader, &outCodec, nullptr, nullptr);
     if (kSuccess == *result) {
         // Codec has taken ownership of the stream.
         SkASSERT(outCodec);
-        streamDeleter.release();
+        stream.release();
     }
-    return outCodec;
+    return std::unique_ptr<SkCodec>(outCodec);
 }
diff --git a/src/codec/SkPngCodec.h b/src/codec/SkPngCodec.h
index b5f9347..8496705 100644
--- a/src/codec/SkPngCodec.h
+++ b/src/codec/SkPngCodec.h
@@ -23,8 +23,8 @@
     static bool IsPng(const char*, size_t);
 
     // Assume IsPng was called and returned true.
-    static SkCodec* NewFromStream(SkStream*, Result*,
-                                  SkPngChunkReader* = nullptr);
+    static std::unique_ptr<SkCodec> MakeFromStream(std::unique_ptr<SkStream>, Result*,
+                                                   SkPngChunkReader* = nullptr);
 
     // FIXME (scroggo): Temporarily needed by AutoCleanPng.
     void setIdatLength(size_t len) { fIdatLength = len; }
@@ -45,8 +45,8 @@
         void* fPtr;
     };
 
-    SkPngCodec(const SkEncodedInfo&, const SkImageInfo&, SkStream*, SkPngChunkReader*,
-            void* png_ptr, void* info_ptr, int bitDepth);
+    SkPngCodec(const SkEncodedInfo&, const SkImageInfo&, std::unique_ptr<SkStream>,
+               SkPngChunkReader*, void* png_ptr, void* info_ptr, int bitDepth);
 
     Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, int*)
             override;
diff --git a/src/codec/SkRawCodec.cpp b/src/codec/SkRawCodec.cpp
index d23eec0..dbcbd28 100644
--- a/src/codec/SkRawCodec.cpp
+++ b/src/codec/SkRawCodec.cpp
@@ -10,6 +10,7 @@
 #include "SkColorPriv.h"
 #include "SkData.h"
 #include "SkJpegCodec.h"
+#include "SkMakeUnique.h"
 #include "SkMutex.h"
 #include "SkRawCodec.h"
 #include "SkRefCnt.h"
@@ -196,7 +197,7 @@
      * Note: for performance reason, this function is destructive to the SkRawStream. One should
      *       abandon current object after the function call.
      */
-   virtual SkMemoryStream* transferBuffer(size_t offset, size_t size) = 0;
+   virtual std::unique_ptr<SkMemoryStream> transferBuffer(size_t offset, size_t size) = 0;
 };
 
 class SkRawLimitedDynamicMemoryWStream : public SkDynamicMemoryWStream {
@@ -225,13 +226,12 @@
 // Note: the maximum buffer size is 100MB (limited by SkRawLimitedDynamicMemoryWStream).
 class SkRawBufferedStream : public SkRawStream {
 public:
-    // Will take the ownership of the stream.
-    explicit SkRawBufferedStream(SkStream* stream)
-        : fStream(stream)
+    explicit SkRawBufferedStream(std::unique_ptr<SkStream> stream)
+        : fStream(std::move(stream))
         , fWholeStreamRead(false)
     {
         // Only use SkRawBufferedStream when the stream is not an asset stream.
-        SkASSERT(!is_asset_stream(*stream));
+        SkASSERT(!is_asset_stream(*fStream));
     }
 
     ~SkRawBufferedStream() override {}
@@ -256,7 +256,7 @@
         return this->bufferMoreData(sum) && fStreamBuffer.read(data, offset, length);
     }
 
-    SkMemoryStream* transferBuffer(size_t offset, size_t size) override {
+    std::unique_ptr<SkMemoryStream> transferBuffer(size_t offset, size_t size) override {
         sk_sp<SkData> data(SkData::MakeUninitialized(size));
         if (offset > fStreamBuffer.bytesWritten()) {
             // If the offset is not buffered, read from fStream directly and skip the buffering.
@@ -288,7 +288,7 @@
                 }
             }
         }
-        return new SkMemoryStream(data);
+        return skstd::make_unique<SkMemoryStream>(data);
     }
 
 private:
@@ -333,12 +333,11 @@
 
 class SkRawAssetStream : public SkRawStream {
 public:
-    // Will take the ownership of the stream.
-    explicit SkRawAssetStream(SkStream* stream)
-        : fStream(stream)
+    explicit SkRawAssetStream(std::unique_ptr<SkStream> stream)
+        : fStream(std::move(stream))
     {
         // Only use SkRawAssetStream when the stream is an asset stream.
-        SkASSERT(is_asset_stream(*stream));
+        SkASSERT(is_asset_stream(*fStream));
     }
 
     ~SkRawAssetStream() override {}
@@ -361,7 +360,7 @@
         return fStream->seek(offset) && (fStream->read(data, length) == length);
     }
 
-    SkMemoryStream* transferBuffer(size_t offset, size_t size) override {
+    std::unique_ptr<SkMemoryStream> transferBuffer(size_t offset, size_t size) override {
         if (fStream->getLength() < offset) {
             return nullptr;
         }
@@ -382,7 +381,7 @@
             sk_sp<SkData> data(SkData::MakeWithCopy(
                 static_cast<const uint8_t*>(fStream->getMemoryBase()) + offset, bytesToRead));
             fStream.reset();
-            return new SkMemoryStream(data);
+            return skstd::make_unique<SkMemoryStream>(data);
         } else {
             sk_sp<SkData> data(SkData::MakeUninitialized(bytesToRead));
             if (!fStream->seek(offset)) {
@@ -392,7 +391,7 @@
             if (bytesRead < bytesToRead) {
                 data = SkData::MakeSubset(data.get(), 0, bytesRead);
             }
-            return new SkMemoryStream(data);
+            return skstd::make_unique<SkMemoryStream>(data);
         }
     }
 private:
@@ -630,12 +629,13 @@
  * SkJpegCodec. If PIEX returns kFail, then the file is invalid, return nullptr. In other cases,
  * fallback to create SkRawCodec for DNG images.
  */
-SkCodec* SkRawCodec::NewFromStream(SkStream* stream, Result* result) {
+std::unique_ptr<SkCodec> SkRawCodec::MakeFromStream(std::unique_ptr<SkStream> stream,
+                                                    Result* result) {
     std::unique_ptr<SkRawStream> rawStream;
     if (is_asset_stream(*stream)) {
-        rawStream.reset(new SkRawAssetStream(stream));
+        rawStream.reset(new SkRawAssetStream(std::move(stream)));
     } else {
-        rawStream.reset(new SkRawBufferedStream(stream));
+        rawStream.reset(new SkRawBufferedStream(std::move(stream)));
     }
 
     // Does not take the ownership of rawStream.
@@ -666,13 +666,14 @@
             // transferBuffer() is destructive to the rawStream. Abandon the rawStream after this
             // function call.
             // FIXME: one may avoid the copy of memoryStream and use the buffered rawStream.
-            SkMemoryStream* memoryStream =
-                rawStream->transferBuffer(imageData.preview.offset, imageData.preview.length);
+            auto memoryStream = rawStream->transferBuffer(imageData.preview.offset,
+                                                          imageData.preview.length);
             if (!memoryStream) {
                 *result = kInvalidInput;
                 return nullptr;
             }
-            return SkJpegCodec::NewFromStream(memoryStream, result, std::move(colorSpace));
+            return SkJpegCodec::MakeFromStream(std::move(memoryStream), result,
+                                               std::move(colorSpace));
         }
     }
 
@@ -689,7 +690,7 @@
     }
 
     *result = kSuccess;
-    return new SkRawCodec(dngImage.release());
+    return std::unique_ptr<SkCodec>(new SkRawCodec(dngImage.release()));
 }
 
 SkCodec::Result SkRawCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst,
diff --git a/src/codec/SkRawCodec.h b/src/codec/SkRawCodec.h
index 5ed7211..c258ac1 100644
--- a/src/codec/SkRawCodec.h
+++ b/src/codec/SkRawCodec.h
@@ -28,7 +28,7 @@
      * Creates a RAW decoder
      * Takes ownership of the stream
      */
-    static SkCodec* NewFromStream(SkStream*, Result*);
+    static std::unique_ptr<SkCodec> MakeFromStream(std::unique_ptr<SkStream>, Result*);
 
     ~SkRawCodec() override;
 
diff --git a/src/codec/SkStreamBuffer.cpp b/src/codec/SkStreamBuffer.cpp
index 754065d..00253fa 100644
--- a/src/codec/SkStreamBuffer.cpp
+++ b/src/codec/SkStreamBuffer.cpp
@@ -7,11 +7,11 @@
 
 #include "SkStreamBuffer.h"
 
-SkStreamBuffer::SkStreamBuffer(SkStream* stream)
-    : fStream(stream)
+SkStreamBuffer::SkStreamBuffer(std::unique_ptr<SkStream> stream)
+    : fStream(std::move(stream))
     , fPosition(0)
     , fBytesBuffered(0)
-    , fHasLengthAndPosition(stream->hasLength() && stream->hasPosition())
+    , fHasLengthAndPosition(fStream->hasLength() && fStream->hasPosition())
     , fTrulyBuffered(0)
 {}
 
diff --git a/src/codec/SkStreamBuffer.h b/src/codec/SkStreamBuffer.h
index 2b60775..7543e32 100644
--- a/src/codec/SkStreamBuffer.h
+++ b/src/codec/SkStreamBuffer.h
@@ -24,9 +24,7 @@
  */
 class SkStreamBuffer : SkNoncopyable {
 public:
-    // Takes ownership of the SkStream.
-    SkStreamBuffer(SkStream*);
-
+    SkStreamBuffer(std::unique_ptr<SkStream>);
     ~SkStreamBuffer();
 
     /**
diff --git a/src/codec/SkWbmpCodec.cpp b/src/codec/SkWbmpCodec.cpp
index eea5e4b..934d7d5 100644
--- a/src/codec/SkWbmpCodec.cpp
+++ b/src/codec/SkWbmpCodec.cpp
@@ -95,10 +95,11 @@
     return this->stream()->read(row, fSrcRowBytes) == fSrcRowBytes;
 }
 
-SkWbmpCodec::SkWbmpCodec(int width, int height, const SkEncodedInfo& info, SkStream* stream)
+SkWbmpCodec::SkWbmpCodec(int width, int height, const SkEncodedInfo& info,
+                         std::unique_ptr<SkStream> stream)
     // Wbmp does not need a colorXform, so choose an arbitrary srcFormat.
     : INHERITED(width, height, info, SkColorSpaceXform::ColorFormat(),
-                stream, SkColorSpace::MakeSRGB())
+                std::move(stream), SkColorSpace::MakeSRGB())
     , fSrcRowBytes(get_src_row_bytes(this->getInfo().width()))
     , fSwizzler(nullptr)
 {}
@@ -145,10 +146,10 @@
     return read_header(&stream, nullptr);
 }
 
-SkCodec* SkWbmpCodec::NewFromStream(SkStream* stream, Result* result) {
-    std::unique_ptr<SkStream> streamDeleter(stream);
+std::unique_ptr<SkCodec> SkWbmpCodec::MakeFromStream(std::unique_ptr<SkStream> stream,
+                                                     Result* result) {
     SkISize size;
-    if (!read_header(stream, &size)) {
+    if (!read_header(stream.get(), &size)) {
         // This already succeeded in IsWbmp, so this stream was corrupted in/
         // after rewind.
         *result = kCouldNotRewind;
@@ -157,7 +158,8 @@
     *result = kSuccess;
     SkEncodedInfo info = SkEncodedInfo::Make(SkEncodedInfo::kGray_Color,
             SkEncodedInfo::kOpaque_Alpha, 1);
-    return new SkWbmpCodec(size.width(), size.height(), info, streamDeleter.release());
+    return std::unique_ptr<SkCodec>(new SkWbmpCodec(size.width(), size.height(), info,
+                                                    std::move(stream)));
 }
 
 int SkWbmpCodec::onGetScanlines(void* dst, int count, size_t dstRowBytes) {
diff --git a/src/codec/SkWbmpCodec.h b/src/codec/SkWbmpCodec.h
index f81b428..0328771 100644
--- a/src/codec/SkWbmpCodec.h
+++ b/src/codec/SkWbmpCodec.h
@@ -21,7 +21,7 @@
      * Creates a wbmp codec
      * Takes ownership of the stream
      */
-    static SkCodec* NewFromStream(SkStream*, Result*);
+    static std::unique_ptr<SkCodec> MakeFromStream(std::unique_ptr<SkStream>, Result*);
 
 protected:
     SkEncodedImageFormat onGetEncodedFormat() const override;
@@ -44,7 +44,7 @@
      */
     bool readRow(uint8_t* row);
 
-    SkWbmpCodec(int width, int height, const SkEncodedInfo&, SkStream*);
+    SkWbmpCodec(int width, int height, const SkEncodedInfo&, std::unique_ptr<SkStream>);
 
     const size_t                fSrcRowBytes;
 
diff --git a/src/codec/SkWebpCodec.cpp b/src/codec/SkWebpCodec.cpp
index 02e6ff2..94fa175 100644
--- a/src/codec/SkWebpCodec.cpp
+++ b/src/codec/SkWebpCodec.cpp
@@ -11,6 +11,7 @@
 #include "SkCodecAnimationPriv.h"
 #include "SkCodecPriv.h"
 #include "SkColorSpaceXform.h"
+#include "SkMakeUnique.h"
 #include "SkRasterPipeline.h"
 #include "SkSampler.h"
 #include "SkStreamPriv.h"
@@ -44,19 +45,18 @@
 
 // Parse headers of RIFF container, and check for valid Webp (VP8) content.
 // Returns an SkWebpCodec on success
-SkCodec* SkWebpCodec::NewFromStream(SkStream* stream, Result* result) {
-    std::unique_ptr<SkStream> streamDeleter(stream);
-
+std::unique_ptr<SkCodec> SkWebpCodec::MakeFromStream(std::unique_ptr<SkStream> stream,
+                                                     Result* result) {
     // Webp demux needs a contiguous data buffer.
     sk_sp<SkData> data = nullptr;
     if (stream->getMemoryBase()) {
         // It is safe to make without copy because we'll hold onto the stream.
         data = SkData::MakeWithoutCopy(stream->getMemoryBase(), stream->getLength());
     } else {
-        data = SkCopyStreamToData(stream);
+        data = SkCopyStreamToData(stream.get());
 
         // If we are forced to copy the stream to a data, we can go ahead and delete the stream.
-        streamDeleter.reset(nullptr);
+        stream.reset(nullptr);
     }
 
     // It's a little strange that the |demux| will outlive |webpData|, though it needs the
@@ -162,9 +162,8 @@
 
     *result = kSuccess;
     SkEncodedInfo info = SkEncodedInfo::Make(color, alpha, 8);
-    return new SkWebpCodec(width, height, info, std::move(colorSpace),
-                           streamDeleter.release(), demux.release(),
-                           std::move(data));
+    return std::unique_ptr<SkCodec>(new SkWebpCodec(width, height, info, std::move(colorSpace),
+                                           std::move(stream), demux.release(), std::move(data)));
 }
 
 SkISize SkWebpCodec::onGetScaledDimensions(float desiredScale) const {
@@ -628,9 +627,9 @@
 }
 
 SkWebpCodec::SkWebpCodec(int width, int height, const SkEncodedInfo& info,
-                         sk_sp<SkColorSpace> colorSpace, SkStream* stream, WebPDemuxer* demux,
-                         sk_sp<SkData> data)
-    : INHERITED(width, height, info, SkColorSpaceXform::kBGRA_8888_ColorFormat, stream,
+                         sk_sp<SkColorSpace> colorSpace, std::unique_ptr<SkStream> stream,
+                         WebPDemuxer* demux, sk_sp<SkData> data)
+    : INHERITED(width, height, info, SkColorSpaceXform::kBGRA_8888_ColorFormat, std::move(stream),
                 std::move(colorSpace))
     , fDemux(demux)
     , fData(std::move(data))
diff --git a/src/codec/SkWebpCodec.h b/src/codec/SkWebpCodec.h
index e06d097..60bff61 100644
--- a/src/codec/SkWebpCodec.h
+++ b/src/codec/SkWebpCodec.h
@@ -28,7 +28,7 @@
 class SkWebpCodec final : public SkCodec {
 public:
     // Assumes IsWebp was called and returned true.
-    static SkCodec* NewFromStream(SkStream*, Result*);
+    static std::unique_ptr<SkCodec> MakeFromStream(std::unique_ptr<SkStream>, Result*);
     static bool IsWebp(const void*, size_t);
 protected:
     Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, int*) override;
@@ -49,8 +49,8 @@
     }
 
 private:
-    SkWebpCodec(int width, int height, const SkEncodedInfo&, sk_sp<SkColorSpace>, SkStream*,
-                WebPDemuxer*, sk_sp<SkData>);
+    SkWebpCodec(int width, int height, const SkEncodedInfo&, sk_sp<SkColorSpace>,
+                std::unique_ptr<SkStream>, WebPDemuxer*, sk_sp<SkData>);
 
     SkAutoTCallVProc<WebPDemuxer, WebPDemuxDelete> fDemux;
 
diff --git a/tests/BadIcoTest.cpp b/tests/BadIcoTest.cpp
index 670c2ac..21343a2 100644
--- a/tests/BadIcoTest.cpp
+++ b/tests/BadIcoTest.cpp
@@ -32,7 +32,7 @@
     for (size_t i = 0; i < SK_ARRAY_COUNT(badImages); ++i) {
         SkString resourcePath = SkOSPath::Join(badImagesFolder, badImages[i]);
         std::unique_ptr<SkStream> stream(GetResourceAsStream(resourcePath.c_str()));
-        std::unique_ptr<SkCodec> codec(SkCodec::NewFromStream(stream.release()));
+        std::unique_ptr<SkCodec> codec(SkCodec::MakeFromStream(std::move(stream)));
 
         // These images are corrupt.  It's not important whether we succeed/fail in codec
         // creation or decoding.  We just want to make sure that we don't crash.
diff --git a/tests/CodecAnimTest.cpp b/tests/CodecAnimTest.cpp
index 84dc9fa..612a0fa 100644
--- a/tests/CodecAnimTest.cpp
+++ b/tests/CodecAnimTest.cpp
@@ -37,9 +37,7 @@
     if (!data) {
         return;
     }
-    data = SkData::MakeSubset(data.get(), 0, 23);
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(data));
-    codec->getFrameInfo();
+    SkCodec::MakeFromData(SkData::MakeSubset(data.get(), 0, 23))->getFrameInfo();
 }
 
 // 565 does not support alpha, but there is no reason for it not to support an
@@ -50,7 +48,7 @@
     if (!data) {
         return;
     }
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(std::move(data)));
+    std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(std::move(data)));
     auto info = codec->getInfo().makeColorType(kRGB_565_SkColorType);
     SkBitmap bm;
     bm.allocPixels(info);
@@ -175,7 +173,7 @@
             continue;
         }
 
-        std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(data));
+        std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(data));
         if (!codec) {
             ERRORF(r, "Failed to create an SkCodec from '%s'", rec.fName);
             continue;
@@ -227,7 +225,7 @@
 
         for (auto mode : { TestMode::kVector, TestMode::kIndividual }) {
             // Re-create the codec to reset state and test parsing.
-            codec.reset(SkCodec::NewFromData(data));
+            codec = SkCodec::MakeFromData(data);
 
             int frameCount;
             std::vector<SkCodec::FrameInfo> frameInfos;
diff --git a/tests/CodecExactReadTest.cpp b/tests/CodecExactReadTest.cpp
index 9b6acc8..d00c0bc 100644
--- a/tests/CodecExactReadTest.cpp
+++ b/tests/CodecExactReadTest.cpp
@@ -11,6 +11,7 @@
 #include "SkBitmap.h"
 #include "SkCodec.h"
 #include "SkData.h"
+#include "SkMakeUnique.h"
 #include "SkStream.h"
 
 namespace {
@@ -67,7 +68,8 @@
 
         SkMemoryStream stream(std::move(multiData));
         for (int i = 0; i < kNumImages; ++i) {
-            std::unique_ptr<SkCodec> codec(SkCodec::NewFromStream(new UnowningStream(&stream)));
+            std::unique_ptr<SkCodec> codec(SkCodec::MakeFromStream(
+                                                   skstd::make_unique<UnowningStream>(&stream)));
             if (!codec) {
                 ERRORF(r, "Failed to create a codec from %s, iteration %i", path, i);
                 continue;
diff --git a/tests/CodecPartialTest.cpp b/tests/CodecPartialTest.cpp
index 4a56f46..e40ff8b 100644
--- a/tests/CodecPartialTest.cpp
+++ b/tests/CodecPartialTest.cpp
@@ -9,6 +9,7 @@
 #include "SkCodec.h"
 #include "SkData.h"
 #include "SkImageInfo.h"
+#include "SkMakeUnique.h"
 #include "SkRWBuffer.h"
 #include "SkString.h"
 
@@ -24,7 +25,7 @@
 }
 
 static bool create_truth(sk_sp<SkData> data, SkBitmap* dst) {
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(std::move(data)));
+    std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(std::move(data)));
     if (!codec) {
         return false;
     }
@@ -64,7 +65,7 @@
 
     // Note that we cheat and hold on to a pointer to stream, though it is owned by
     // partialCodec.
-    std::unique_ptr<SkCodec> partialCodec(SkCodec::NewFromStream(stream));
+    std::unique_ptr<SkCodec> partialCodec(SkCodec::MakeFromStream(std::unique_ptr<SkStream>(stream)));
     if (!partialCodec) {
         // Technically, this could be a small file where half the file is not
         // enough.
@@ -146,7 +147,7 @@
         return;
     }
 
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(file));
+    std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(file));
     if (!codec) {
         ERRORF(r, "Failed to create codec from %s", path);
         return;
@@ -166,7 +167,7 @@
             return;
         }
         stream = new HaltingStream(file, i);
-        partialCodec.reset(SkCodec::NewFromStream(stream));
+        partialCodec = SkCodec::MakeFromStream(std::unique_ptr<SkStream>(stream));
     }
 
     std::vector<SkCodec::FrameInfo> partialInfo;
@@ -193,8 +194,7 @@
 
     // This stream will be owned by fullCodec, but we hang on to the pointer
     // to determine frame offsets.
-    SkStream* stream = new SkMemoryStream(file);
-    std::unique_ptr<SkCodec> fullCodec(SkCodec::NewFromStream(stream));
+    std::unique_ptr<SkCodec> fullCodec(SkCodec::MakeFromStream(skstd::make_unique<SkMemoryStream>(file)));
     const auto info = standardize_info(fullCodec.get());
 
     // frameByteCounts stores the number of bytes to decode a particular frame.
@@ -233,7 +233,8 @@
 
     // Now decode frames partially, then completely, and compare to the original.
     HaltingStream* haltingStream = new HaltingStream(file, frameByteCounts[0]);
-    std::unique_ptr<SkCodec> partialCodec(SkCodec::NewFromStream(haltingStream));
+    std::unique_ptr<SkCodec> partialCodec(SkCodec::MakeFromStream(
+                                                      std::unique_ptr<SkStream>(haltingStream)));
     if (!partialCodec) {
         ERRORF(r, "Failed to create a partial codec from %s with %i bytes out of %i",
                path, frameByteCounts[0], file->size());
@@ -287,8 +288,8 @@
         return;
     }
     const size_t halfSize = file->size() / 2;
-    std::unique_ptr<SkCodec> partialCodec(SkCodec::NewFromStream(
-            new HaltingStream(std::move(file), halfSize)));
+    std::unique_ptr<SkCodec> partialCodec(SkCodec::MakeFromStream(
+                                  skstd::make_unique<HaltingStream>(std::move(file), halfSize)));
     if (!partialCodec) {
         ERRORF(r, "Failed to create codec for %s", name);
         return;
@@ -351,7 +352,7 @@
 // Test that a gif file truncated before its local color map behaves as expected.
 DEF_TEST(Codec_GifPreMap, r) {
     sk_sp<SkData> data = SkData::MakeWithoutCopy(gNoGlobalColorMap, sizeof(gNoGlobalColorMap));
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(data));
+    std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(data));
     if (!codec) {
         ERRORF(r, "failed to create codec");
         return;
@@ -365,7 +366,7 @@
     REPORTER_ASSERT(r, result == SkCodec::kSuccess);
 
     // Truncate to 23 bytes, just before the color map. This should fail to decode.
-    codec.reset(SkCodec::NewFromData(SkData::MakeWithoutCopy(gNoGlobalColorMap, 23)));
+    codec = SkCodec::MakeFromData(SkData::MakeWithoutCopy(gNoGlobalColorMap, 23));
     REPORTER_ASSERT(r, codec);
     if (codec) {
         SkBitmap bm;
@@ -378,7 +379,7 @@
     // cannot start an incremental decode until we have more data. If we did,
     // we would be using the wrong color table.
     HaltingStream* stream = new HaltingStream(data, 23);
-    codec.reset(SkCodec::NewFromStream(stream));
+    codec = SkCodec::MakeFromStream(std::unique_ptr<SkStream>(stream));
     REPORTER_ASSERT(r, codec);
     if (codec) {
         SkBitmap bm;
@@ -406,7 +407,7 @@
     // Truncate to the beginning of the IDAT, immediately after the IDAT tag.
     file = SkData::MakeSubset(file.get(), 0, 80);
 
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(std::move(file)));
+    std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(std::move(file)));
     if (!codec) {
         ERRORF(r, "Failed to create a codec for %s", name);
         return;
@@ -436,8 +437,8 @@
 
         for (size_t len = 14; len <= file->size(); len += 5) {
             SkCodec::Result result;
-            auto* stream = new SkMemoryStream(file->data(), len);
-            std::unique_ptr<SkCodec> codec(SkCodec::NewFromStream(stream, &result));
+            std::unique_ptr<SkCodec> codec(SkCodec::MakeFromStream(
+                                   skstd::make_unique<SkMemoryStream>(file->data(), len), &result));
             if (codec) {
                 if (result != SkCodec::kSuccess) {
                     ERRORF(r, "Created an SkCodec for %s with %lu bytes, but "
diff --git a/tests/CodecPriv.h b/tests/CodecPriv.h
index d80bb69..8362599 100644
--- a/tests/CodecPriv.h
+++ b/tests/CodecPriv.h
@@ -12,7 +12,7 @@
 #include "SkData.h"
 
 inline bool decode_memory(const void* mem, size_t size, SkBitmap* bm) {
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(SkData::MakeWithoutCopy(mem, size)));
+    std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(SkData::MakeWithoutCopy(mem, size)));
     if (!codec) {
         return false;
     }
diff --git a/tests/CodecTest.cpp b/tests/CodecTest.cpp
index 12e3f2c..698af46 100644
--- a/tests/CodecTest.cpp
+++ b/tests/CodecTest.cpp
@@ -18,6 +18,7 @@
 #include "SkFrontBufferedStream.h"
 #include "SkImageEncoder.h"
 #include "SkImageEncoderPriv.h"
+#include "SkMakeUnique.h"
 #include "SkMD5.h"
 #include "SkOSPath.h"
 #include "SkJpegEncoder.h"
@@ -273,10 +274,9 @@
     bool isIncomplete = supportsIncomplete;
     if (isIncomplete) {
         size_t size = stream->getLength();
-        sk_sp<SkData> data((SkData::MakeFromStream(stream.get(), 2 * size / 3)));
-        codec.reset(SkCodec::NewFromData(data));
+        codec = SkCodec::MakeFromData(SkData::MakeFromStream(stream.get(), 2 * size / 3));
     } else {
-        codec.reset(SkCodec::NewFromStream(stream.release()));
+        codec = SkCodec::MakeFromStream(std::move(stream));
     }
     if (!codec) {
         ERRORF(r, "Unable to decode '%s'", path);
@@ -414,9 +414,9 @@
         if (isIncomplete) {
             size_t size = stream->getLength();
             sk_sp<SkData> data((SkData::MakeFromStream(stream.get(), 2 * size / 3)));
-            androidCodec.reset(SkAndroidCodec::NewFromData(data));
+            androidCodec = SkAndroidCodec::MakeFromData(data);
         } else {
-            androidCodec.reset(SkAndroidCodec::NewFromStream(stream.release()));
+            androidCodec = SkAndroidCodec::MakeFromStream(std::move(stream));
         }
         if (!androidCodec) {
             ERRORF(r, "Unable to decode '%s'", path);
@@ -445,7 +445,7 @@
         SkStream* bufferedStream = SkFrontBufferedStream::Create(
                 new SkMemoryStream(std::move(fullData)), SkCodec::MinBufferedBytesNeeded());
         REPORTER_ASSERT(r, bufferedStream);
-        codec.reset(SkCodec::NewFromStream(bufferedStream));
+        codec = SkCodec::MakeFromStream(std::unique_ptr<SkStream>(bufferedStream));
         REPORTER_ASSERT(r, codec);
         if (codec) {
             test_info(r, codec.get(), info, SkCodec::kSuccess, &codecDigest);
@@ -530,12 +530,10 @@
 
 static void test_invalid_stream(skiatest::Reporter* r, const void* stream, size_t len) {
     // Neither of these calls should return a codec. Bots should catch us if we leaked anything.
-    SkCodec* codec = SkCodec::NewFromStream(new SkMemoryStream(stream, len, false));
-    REPORTER_ASSERT(r, !codec);
-
-    SkAndroidCodec* androidCodec =
-            SkAndroidCodec::NewFromStream(new SkMemoryStream(stream, len, false));
-    REPORTER_ASSERT(r, !androidCodec);
+    REPORTER_ASSERT(r, !SkCodec::MakeFromStream(
+                                        skstd::make_unique<SkMemoryStream>(stream, len, false)));
+    REPORTER_ASSERT(r, !SkAndroidCodec::MakeFromStream(
+                                        skstd::make_unique<SkMemoryStream>(stream, len, false)));
 }
 
 // Ensure that SkCodec::NewFromStream handles freeing the passed in SkStream,
@@ -564,11 +562,8 @@
 DEF_TEST(Codec_null, r) {
     // Attempting to create an SkCodec or an SkAndroidCodec with null should not
     // crash.
-    SkCodec* codec = SkCodec::NewFromStream(nullptr);
-    REPORTER_ASSERT(r, !codec);
-
-    SkAndroidCodec* androidCodec = SkAndroidCodec::NewFromStream(nullptr);
-    REPORTER_ASSERT(r, !androidCodec);
+    REPORTER_ASSERT(r, !SkCodec::MakeFromStream(nullptr));
+    REPORTER_ASSERT(r, !SkAndroidCodec::MakeFromStream(nullptr));
 }
 
 static void test_dimensions(skiatest::Reporter* r, const char path[]) {
@@ -577,7 +572,7 @@
     if (!stream) {
         return;
     }
-    std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::NewFromStream(stream.release()));
+    std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::MakeFromStream(std::move(stream)));
     if (!codec) {
         ERRORF(r, "Unable to create codec '%s'", path);
         return;
@@ -641,8 +636,7 @@
     if (!stream) {
         return;
     }
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromStream(stream.release()));
-    REPORTER_ASSERT(r, nullptr == codec);
+    REPORTER_ASSERT(r, !SkCodec::MakeFromStream(std::move(stream)));
 }
 
 DEF_TEST(Codec_Empty, r) {
@@ -789,7 +783,7 @@
     ChunkReader chunkReader(r);
 
     // Now read the file with SkCodec.
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(wStream.detachAsData(), &chunkReader));
+    std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(wStream.detachAsData(), &chunkReader));
     REPORTER_ASSERT(r, codec);
     if (!codec) {
         return;
@@ -864,7 +858,8 @@
         return;
     }
 
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromStream(new NotAssetMemStream(std::move(data))));
+    std::unique_ptr<SkCodec> codec(SkCodec::MakeFromStream(
+                                           skstd::make_unique<NotAssetMemStream>(std::move(data))));
     REPORTER_ASSERT(r, codec);
 
     test_info(r, codec.get(), codec->getInfo(), SkCodec::kSuccess, nullptr);
@@ -883,14 +878,14 @@
     }
 
     // The limit is less than webp needs to peek or read.
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromStream(
-                                 new LimitedPeekingMemStream(data, 25)));
+    std::unique_ptr<SkCodec> codec(SkCodec::MakeFromStream(
+                                           skstd::make_unique<LimitedPeekingMemStream>(data, 25)));
     REPORTER_ASSERT(r, codec);
 
     test_info(r, codec.get(), codec->getInfo(), SkCodec::kSuccess, nullptr);
 
     // Similarly, a stream which does not peek should still succeed.
-    codec.reset(SkCodec::NewFromStream(new LimitedPeekingMemStream(data, 0)));
+    codec = SkCodec::MakeFromStream(skstd::make_unique<LimitedPeekingMemStream>(data, 0));
     REPORTER_ASSERT(r, codec);
 
     test_info(r, codec.get(), codec->getInfo(), SkCodec::kSuccess, nullptr);
@@ -913,7 +908,7 @@
     writeableData[1] = static_cast<uint8_t>(~0x9F);
 
     // SkCodec should support this.
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(data));
+    std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(data));
     REPORTER_ASSERT(r, codec);
     if (!codec) {
         return;
@@ -931,7 +926,7 @@
                                           0x83, 0xFF, 0x7F,     // W: 65535
                                           0x83, 0xFF, 0x7F };   // H: 65535
     std::unique_ptr<SkStream> stream(new SkMemoryStream(maxSizeWbmp, sizeof(maxSizeWbmp), false));
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromStream(stream.release()));
+    std::unique_ptr<SkCodec> codec(SkCodec::MakeFromStream(std::move(stream)));
 
     REPORTER_ASSERT(r, codec);
     if (!codec) return;
@@ -945,7 +940,7 @@
                                          0x84, 0x80, 0x00,     // W: 65536
                                          0x84, 0x80, 0x00 };   // H: 65536
     stream.reset(new SkMemoryStream(tooBigWbmp, sizeof(tooBigWbmp), false));
-    codec.reset(SkCodec::NewFromStream(stream.release()));
+    codec = SkCodec::MakeFromStream(std::move(stream));
 
     REPORTER_ASSERT(r, !codec);
 }
@@ -958,7 +953,7 @@
     }
 
     data = SkData::MakeSubset(data.get(), 0, data->size() / 2);
-    std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::NewFromData(data));
+    std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::MakeFromData(data));
     if (!codec) {
         ERRORF(r, "Unable to create codec '%s'.", path);
         return;
@@ -1001,7 +996,7 @@
 }
 
 static void check_color_xform(skiatest::Reporter* r, const char* path) {
-    std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::NewFromStream(GetResourceAsStream(path).release()));
+    std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::MakeFromStream(GetResourceAsStream(path)));
 
     SkAndroidCodec::AndroidOptions opts;
     opts.fSampleSize = 3;
@@ -1062,7 +1057,7 @@
     sk_sp<SkData> data =
             sk_sp<SkData>(sk_tool_utils::EncodeImageToData(bm1, SkEncodedImageFormat::kPNG, 100));
 
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(data));
+    std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(data));
     REPORTER_ASSERT(r, color_type_match(info.colorType(), codec->getInfo().colorType()));
     REPORTER_ASSERT(r, alpha_type_match(info.alphaType(), codec->getInfo().alphaType()));
 
@@ -1078,9 +1073,7 @@
 }
 
 DEF_TEST(Codec_PngRoundTrip, r) {
-    const char* path = "mandrill_512_q075.jpg";
-    std::unique_ptr<SkStream> stream(GetResourceAsStream(path));
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromStream(stream.release()));
+    auto codec = SkCodec::MakeFromStream(GetResourceAsStream("mandrill_512_q075.jpg"));
 
     SkColorType colorTypesOpaque[] = {
             kRGB_565_SkColorType, kRGBA_8888_SkColorType, kBGRA_8888_SkColorType
@@ -1090,14 +1083,10 @@
         check_round_trip(r, codec.get(), newInfo);
     }
 
-    path = "grayscale.jpg";
-    stream = GetResourceAsStream(path);
-    codec.reset(SkCodec::NewFromStream(stream.release()));
+    codec = SkCodec::MakeFromStream(GetResourceAsStream("grayscale.jpg"));
     check_round_trip(r, codec.get(), codec->getInfo());
 
-    path = "yellow_rose.png";
-    stream = GetResourceAsStream(path);
-    codec.reset(SkCodec::NewFromStream(stream.release()));
+    codec = SkCodec::MakeFromStream(GetResourceAsStream("yellow_rose.png"));
 
     SkColorType colorTypesWithAlpha[] = {
             kRGBA_8888_SkColorType, kBGRA_8888_SkColorType
@@ -1115,9 +1104,7 @@
         }
     }
 
-    path = "index8.png";
-    stream = GetResourceAsStream(path);
-    codec.reset(SkCodec::NewFromStream(stream.release()));
+    codec = SkCodec::MakeFromStream(GetResourceAsStream("index8.png"));
 
     for (SkAlphaType alphaType : alphaTypes) {
         SkImageInfo newInfo = codec->getInfo().makeAlphaType(alphaType)
@@ -1134,7 +1121,7 @@
         return;
     }
 
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromStream(stream.release()));
+    std::unique_ptr<SkCodec> codec(SkCodec::MakeFromStream(std::move(stream)));
     if (!codec) {
         ERRORF(r, "failed to create a codec for %s", path);
         return;
@@ -1211,7 +1198,7 @@
     // Note that we cheat and hold on to the stream pointer, but SkCodec will
     // take ownership. We will not refer to the stream after the SkCodec
     // deletes it.
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromStream(streamObj.release()));
+    std::unique_ptr<SkCodec> codec(SkCodec::MakeFromStream(std::move(streamObj)));
     if (!codec) {
         ERRORF(r, "Failed to create codec for %s", path);
         return;
@@ -1296,7 +1283,7 @@
             return;
         }
 
-        std::unique_ptr<SkCodec> codec(SkCodec::NewFromStream(stream.release()));
+        std::unique_ptr<SkCodec> codec(SkCodec::MakeFromStream(std::move(stream)));
         if (!codec) {
             ERRORF(r, "Failed to create codec for %s,", file);
             continue;
@@ -1328,7 +1315,7 @@
         return;
     }
 
-    std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::NewFromStream(stream.release()));
+    std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::MakeFromStream(std::move(stream)));
     if (!codec) {
         ERRORF(r, "Failed to create codec\n");
         return;
@@ -1358,8 +1345,7 @@
     }
 
     // This is enough to read the header etc, but no rows.
-    auto data = SkData::MakeFromStream(stream.get(), 99);
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(data));
+    std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(SkData::MakeFromStream(stream.get(), 99)));
     if (!codec) {
         ERRORF(r, "Failed to create codec\n");
         return;
@@ -1386,7 +1372,7 @@
         return;
     }
 
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromStream(stream.release()));
+    std::unique_ptr<SkCodec> codec(SkCodec::MakeFromStream(std::move(stream)));
     REPORTER_ASSERT(r, codec);
 
     test_info(r, codec.get(), codec->getInfo().makeColorType(kN32_SkColorType), expectedResult,
@@ -1408,7 +1394,7 @@
         return;
     }
 
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromStream(stream.release()));
+    std::unique_ptr<SkCodec> codec(SkCodec::MakeFromStream(std::move(stream)));
     REPORTER_ASSERT(r, !codec);
 }
 
@@ -1429,7 +1415,7 @@
         return;
     }
 
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromStream(stream.release()));
+    std::unique_ptr<SkCodec> codec(SkCodec::MakeFromStream(std::move(stream)));
     REPORTER_ASSERT(r, codec);
     if (!codec) {
         return;
@@ -1491,7 +1477,7 @@
     SkDynamicMemoryWStream srgbBuf;
     encode_format(&srgbBuf, pixmap, unpremulBehavior, format);
     sk_sp<SkData> srgbData = srgbBuf.detachAsData();
-    std::unique_ptr<SkCodec> srgbCodec(SkCodec::NewFromData(srgbData));
+    std::unique_ptr<SkCodec> srgbCodec(SkCodec::MakeFromData(srgbData));
     REPORTER_ASSERT(r, srgbCodec->getInfo().colorSpace() == SkColorSpace::MakeSRGB().get());
 
     // Test with P3 color space.
@@ -1501,7 +1487,7 @@
     pixmap.setColorSpace(p3);
     encode_format(&p3Buf, pixmap, unpremulBehavior, format);
     sk_sp<SkData> p3Data = p3Buf.detachAsData();
-    std::unique_ptr<SkCodec> p3Codec(SkCodec::NewFromData(p3Data));
+    std::unique_ptr<SkCodec> p3Codec(SkCodec::MakeFromData(p3Data));
     REPORTER_ASSERT(r, p3Codec->getInfo().colorSpace()->gammaCloseToSRGB());
     SkMatrix44 mat0(SkMatrix44::kUninitialized_Constructor);
     SkMatrix44 mat1(SkMatrix44::kUninitialized_Constructor);
diff --git a/tests/ColorSpaceTest.cpp b/tests/ColorSpaceTest.cpp
index 9b2e1b3..efbfe8a 100644
--- a/tests/ColorSpaceTest.cpp
+++ b/tests/ColorSpaceTest.cpp
@@ -53,7 +53,7 @@
         return;
     }
 
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromStream(stream.release()));
+    std::unique_ptr<SkCodec> codec(SkCodec::MakeFromStream(std::move(stream)));
     REPORTER_ASSERT(r, nullptr != codec);
     if (!codec) {
         return;
diff --git a/tests/ExifTest.cpp b/tests/ExifTest.cpp
index f9e357d..181f0f9 100644
--- a/tests/ExifTest.cpp
+++ b/tests/ExifTest.cpp
@@ -16,13 +16,12 @@
         return;
     }
 
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromStream(stream.release()));
+    std::unique_ptr<SkCodec> codec(SkCodec::MakeFromStream(std::move(stream)));
     REPORTER_ASSERT(r, nullptr != codec);
     SkCodec::Origin origin = codec->getOrigin();
     REPORTER_ASSERT(r, SkCodec::kTopRight_Origin == origin);
 
-    stream = GetResourceAsStream("mandrill_512_q075.jpg");
-    codec.reset(SkCodec::NewFromStream(stream.release()));
+    codec = SkCodec::MakeFromStream(GetResourceAsStream("mandrill_512_q075.jpg"));
     REPORTER_ASSERT(r, nullptr != codec);
     origin = codec->getOrigin();
     REPORTER_ASSERT(r, SkCodec::kTopLeft_Origin == origin);
diff --git a/tests/FrontBufferedStreamTest.cpp b/tests/FrontBufferedStreamTest.cpp
index 69ff488..aa2dc89 100644
--- a/tests/FrontBufferedStreamTest.cpp
+++ b/tests/FrontBufferedStreamTest.cpp
@@ -285,5 +285,5 @@
 
     // This will fail to create a codec.  However, what we really want to test is that we
     // won't read past the end of the stream.
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromStream(stream.release()));
+    std::unique_ptr<SkCodec> codec(SkCodec::MakeFromStream(std::move(stream)));
 }
diff --git a/tests/GifTest.cpp b/tests/GifTest.cpp
index 5749df1..daa5cf5 100644
--- a/tests/GifTest.cpp
+++ b/tests/GifTest.cpp
@@ -195,7 +195,7 @@
     // Likewise, incremental decoding should succeed here.
     {
         sk_sp<SkData> data = SkData::MakeWithoutCopy(gGIFDataNoColormap, 31);
-        std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(data));
+        std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(data));
         REPORTER_ASSERT(reporter, codec);
         if (codec) {
             auto info = codec->getInfo().makeColorType(kN32_SkColorType);
@@ -232,7 +232,7 @@
         return;
     }
 
-    std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::NewFromStream(stream.release()));
+    std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::MakeFromStream(std::move(stream)));
     REPORTER_ASSERT(r, codec);
     if (!codec) {
         return;
@@ -258,7 +258,7 @@
 
     // This is right before the header for the first image.
     data = SkData::MakeSubset(data.get(), 0, 446);
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(data));
+    std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(data));
     REPORTER_ASSERT(r, !codec);
 }
 
@@ -270,7 +270,7 @@
 
     // This is after the header, but before the color table.
     data = SkData::MakeSubset(data.get(), 0, 23);
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(data));
+    std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(data));
     if (!codec) {
         ERRORF(r, "Failed to create codec with partial data");
         return;
diff --git a/tests/StreamBufferTest.cpp b/tests/StreamBufferTest.cpp
index 96bca35..35bebad 100644
--- a/tests/StreamBufferTest.cpp
+++ b/tests/StreamBufferTest.cpp
@@ -6,6 +6,7 @@
  */
 
 #include "SkData.h"
+#include "SkMakeUnique.h"
 #include "SkOSPath.h"
 #include "SkStream.h"
 #include "SkStreamBuffer.h"
@@ -25,8 +26,9 @@
 }
 
 // Test buffering from the beginning, by different amounts.
-static void test_buffer_from_beginning(skiatest::Reporter* r, SkStream* stream, size_t length) {
-    SkStreamBuffer buffer(stream);
+static void test_buffer_from_beginning(skiatest::Reporter* r, std::unique_ptr<SkStream> stream,
+                                       size_t length) {
+    SkStreamBuffer buffer(std::move(stream));
 
     // Buffer an arbitrary amount:
     size_t buffered = length / 2;
@@ -42,9 +44,9 @@
 }
 
 // Test flushing the stream as we read.
-static void test_flushing(skiatest::Reporter* r, SkStream* stream, size_t length,
+static void test_flushing(skiatest::Reporter* r, std::unique_ptr<SkStream> stream, size_t length,
                           bool getDataAtPosition) {
-    SkStreamBuffer buffer(stream);
+    SkStreamBuffer buffer(std::move(stream));
     const size_t step = 5;
     for (size_t position = 0; position + step <= length; position += step) {
         REPORTER_ASSERT(r, buffer.buffer(step));
@@ -80,12 +82,12 @@
     }
 
     struct {
-        std::function<SkStream*()> createStream;
-        bool                       skipIfNoTmpDir;
+        std::function<std::unique_ptr<SkStream>()>  createStream;
+        bool                                        skipIfNoTmpDir;
     } factories[] = {
-        { [&data]() { return new SkMemoryStream(data); },       false },
-        { [&data]() { return new NotAssetMemStream(data); },    false },
-        { [&path]() { return new SkFILEStream(path.c_str()); }, true  },
+        { [&data]() { return skstd::make_unique<SkMemoryStream>(data); },       false },
+        { [&data]() { return skstd::make_unique<NotAssetMemStream>(data); },    false },
+        { [&path]() { return skstd::make_unique<SkFILEStream>(path.c_str()); }, true  },
     };
 
     for (auto f : factories) {
@@ -98,8 +100,9 @@
     }
 
     // Stream that will receive more data. Will be owned by the SkStreamBuffer.
-    HaltingStream* stream = new HaltingStream(data, 6);
-    SkStreamBuffer buffer(stream);
+    auto halting = skstd::make_unique<HaltingStream>(data, 6);
+    HaltingStream* peekHalting = halting.get();
+    SkStreamBuffer buffer(std::move(halting));
 
     // Can only buffer less than what's available (6).
     REPORTER_ASSERT(r, !buffer.buffer(7));
@@ -107,7 +110,7 @@
     REPORTER_ASSERT(r, !memcmp(buffer.get(), gText, 5));
 
     // Add some more data. We can buffer and read all of it.
-    stream->addNewData(8);
+    peekHalting->addNewData(8);
     REPORTER_ASSERT(r, buffer.buffer(14));
     REPORTER_ASSERT(r, !memcmp(buffer.get(), gText, 14));
 
@@ -116,9 +119,9 @@
 
     // Add some data, and try to read more. Can only read what is
     // available.
-    stream->addNewData(9);
+    peekHalting->addNewData(9);
     REPORTER_ASSERT(r, !buffer.buffer(13));
-    stream->addNewData(4);
+    peekHalting->addNewData(4);
     REPORTER_ASSERT(r, buffer.buffer(13));
 
     // Do not call get on this data. We'll come back to this data after adding
@@ -126,7 +129,7 @@
     buffer.flush();
     const size_t remaining = size - 27;
     REPORTER_ASSERT(r, remaining > 0);
-    stream->addNewData(remaining);
+    peekHalting->addNewData(remaining);
     REPORTER_ASSERT(r, buffer.buffer(remaining));
     REPORTER_ASSERT(r, !memcmp(buffer.get(), gText + 27, remaining));
 
diff --git a/tests/YUVTest.cpp b/tests/YUVTest.cpp
index 0c31c09..825e2d1 100644
--- a/tests/YUVTest.cpp
+++ b/tests/YUVTest.cpp
@@ -20,7 +20,7 @@
     if (!stream) {
         return;
     }
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromStream(stream.release()));
+    std::unique_ptr<SkCodec> codec(SkCodec::MakeFromStream(std::move(stream)));
     REPORTER_ASSERT(reporter, codec);
     if (!codec) {
         return;
diff --git a/third_party/gif/SkGifImageReader.h b/third_party/gif/SkGifImageReader.h
index 0ba767e..d87b68f 100644
--- a/third_party/gif/SkGifImageReader.h
+++ b/third_party/gif/SkGifImageReader.h
@@ -280,13 +280,13 @@
 class SkGifImageReader final : public SkFrameHolder {
 public:
     // This takes ownership of stream.
-    SkGifImageReader(SkStream* stream)
+    SkGifImageReader(std::unique_ptr<SkStream> stream)
         : m_client(nullptr)
         , m_state(SkGIFType)
         , m_bytesToConsume(6) // Number of bytes for GIF type, either "GIF87a" or "GIF89a".
         , m_version(0)
         , m_loopCount(cLoopCountNotSeen)
-        , m_streamBuffer(stream)
+        , m_streamBuffer(std::move(stream))
         , m_parseCompleted(false)
         , m_firstFrameHasAlpha(false)
     {
diff --git a/tools/colorspaceinfo.cpp b/tools/colorspaceinfo.cpp
index ec11019..c35e735 100644
--- a/tools/colorspaceinfo.cpp
+++ b/tools/colorspaceinfo.cpp
@@ -463,7 +463,7 @@
     if (FLAGS_icc) {
         colorSpace = SkColorSpace::MakeICC(data->bytes(), data->size());
     } else {
-        codec.reset(SkCodec::NewFromData(data));
+        codec = SkCodec::MakeFromData(data);
         colorSpace = sk_ref_sp(codec->getInfo().colorSpace());
         SkDebugf("SkCodec would naturally decode as colorType=%s\n",
                  sk_tool_utils::colortype_name(codec->getInfo().colorType()));
diff --git a/tools/get_images_from_skps.cpp b/tools/get_images_from_skps.cpp
index 0debe36..0a2164cf 100644
--- a/tools/get_images_from_skps.cpp
+++ b/tools/get_images_from_skps.cpp
@@ -61,7 +61,7 @@
         gSeen.add(digest);
 
         sk_sp<SkData> data(SkData::MakeWithoutCopy(ptr, len));
-        std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(data));
+        std::unique_ptr<SkCodec> codec = SkCodec::MakeFromData(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/skdiff/skdiff_utils.cpp b/tools/skdiff/skdiff_utils.cpp
index 7a1b7e8..fddd99c 100644
--- a/tools/skdiff/skdiff_utils.cpp
+++ b/tools/skdiff/skdiff_utils.cpp
@@ -35,7 +35,7 @@
 }
 
 bool get_bitmap(sk_sp<SkData> fileBits, DiffResource& resource, bool sizeOnly) {
-    std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(fileBits));
+    auto codec = SkCodec::MakeFromData(fileBits);
     if (!codec) {
         SkDebugf("ERROR: could not create codec for <%s>\n", resource.fFullPath.c_str());
         resource.fStatus = DiffResource::kCouldNotDecode_Status;