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/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;