aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2017-07-23 15:30:02 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-07-25 15:35:23 +0000
commitede7bac43fbc69b9fdf1c178890ba6353f5bb140 (patch)
treedccdba46e7abf125e2f90e6dc08eca00ad9cb09b /tests
parentfa3ed03720b5083afd3620c9239863f05f2eedbd (diff)
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>
Diffstat (limited to 'tests')
-rw-r--r--tests/BadIcoTest.cpp2
-rw-r--r--tests/CodecAnimTest.cpp10
-rw-r--r--tests/CodecExactReadTest.cpp4
-rw-r--r--tests/CodecPartialTest.cpp31
-rw-r--r--tests/CodecPriv.h2
-rw-r--r--tests/CodecTest.cpp94
-rw-r--r--tests/ColorSpaceTest.cpp2
-rw-r--r--tests/ExifTest.cpp5
-rw-r--r--tests/FrontBufferedStreamTest.cpp2
-rw-r--r--tests/GifTest.cpp8
-rw-r--r--tests/StreamBufferTest.cpp33
-rw-r--r--tests/YUVTest.cpp2
12 files changed, 92 insertions, 103 deletions
diff --git a/tests/BadIcoTest.cpp b/tests/BadIcoTest.cpp
index 670c2ac311..21343a2a5c 100644
--- a/tests/BadIcoTest.cpp
+++ b/tests/BadIcoTest.cpp
@@ -32,7 +32,7 @@ DEF_TEST(BadImage, reporter) {
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 84dc9faa6b..612a0facd0 100644
--- a/tests/CodecAnimTest.cpp
+++ b/tests/CodecAnimTest.cpp
@@ -37,9 +37,7 @@ DEF_TEST(Codec_trunc, r) {
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 @@ DEF_TEST(Codec_565, r) {
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 @@ DEF_TEST(Codec_frames, r) {
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 @@ DEF_TEST(Codec_frames, r) {
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 9b6acc8bc9..d00c0bcf97 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 @@ DEF_TEST(Codec_end, r) {
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 4a56f46e21..e40ff8b714 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 SkImageInfo standardize_info(SkCodec* codec) {
}
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 @@ static void test_partial(skiatest::Reporter* r, const char* name, size_t minByte
// 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 @@ DEF_TEST(Codec_requiredFrame, r) {
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 @@ DEF_TEST(Codec_requiredFrame, r) {
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 @@ DEF_TEST(Codec_partialAnim, r) {
// 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 @@ DEF_TEST(Codec_partialAnim, r) {
// 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 @@ static void test_interleaved(skiatest::Reporter* r, const char* name) {
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 @@ static unsigned char gNoGlobalColorMap[] = {
// 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 @@ DEF_TEST(Codec_GifPreMap, r) {
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 @@ DEF_TEST(Codec_GifPreMap, r) {
// 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 @@ DEF_TEST(Codec_emptyIDAT, r) {
// 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 @@ DEF_TEST(Codec_incomplete, r) {
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 d80bb69672..8362599e95 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 12e3f2c13e..698af46de7 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 @@ static void check(skiatest::Reporter* r,
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 @@ static void check(skiatest::Reporter* r,
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 @@ static void check(skiatest::Reporter* r,
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 @@ DEF_TEST(Codec_raw, r) {
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_leaks, r) {
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 @@ static void test_dimensions(skiatest::Reporter* r, const char path[]) {
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 @@ static void test_invalid(skiatest::Reporter* r, const char path[]) {
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 @@ DEF_TEST(Codec_pngChunkReader, r) {
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 @@ DEF_TEST(Codec_raw_notseekable, r) {
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 @@ DEF_TEST(Codec_webp_peek, r) {
}
// 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 @@ DEF_TEST(Codec_wbmp_restrictive, r) {
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 @@ DEF_TEST(Codec_wbmp_max_size, r) {
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 @@ DEF_TEST(Codec_wbmp_max_size, r) {
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 @@ DEF_TEST(Codec_jpeg_rewind, r) {
}
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 @@ DEF_TEST(Codec_jpeg_rewind, r) {
}
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 @@ static void check_round_trip(skiatest::Reporter* r, SkCodec* origCodec, const Sk
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 @@ static void check_round_trip(skiatest::Reporter* r, SkCodec* origCodec, const Sk
}
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 @@ DEF_TEST(Codec_PngRoundTrip, r) {
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 @@ DEF_TEST(Codec_PngRoundTrip, r) {
}
}
- 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 @@ static void test_conversion_possible(skiatest::Reporter* r, const char* path,
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 @@ DEF_TEST(Codec_skipFullParse, r) {
// 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 @@ DEF_TEST(Codec_fallBack, r) {
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 @@ DEF_TEST(Codec_reusePng, r) {
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 @@ DEF_TEST(Codec_rowsDecoded, r) {
}
// 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 @@ static void test_invalid_images(skiatest::Reporter* r, const char* path,
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 @@ static void test_invalid_header(skiatest::Reporter* r, const char* path) {
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 @@ DEF_TEST(Codec_InvalidAnimated, r) {
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 @@ static void test_encode_icc(skiatest::Reporter* r, SkEncodedImageFormat format,
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 @@ static void test_encode_icc(skiatest::Reporter* r, SkEncodedImageFormat format,
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 9b2e1b3dc6..efbfe8a29c 100644
--- a/tests/ColorSpaceTest.cpp
+++ b/tests/ColorSpaceTest.cpp
@@ -53,7 +53,7 @@ static void test_path(skiatest::Reporter* r, const char* path,
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 f9e357d5e6..181f0f9f04 100644
--- a/tests/ExifTest.cpp
+++ b/tests/ExifTest.cpp
@@ -16,13 +16,12 @@ DEF_TEST(ExifOrientation, r) {
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 69ff488358..aa2dc89a11 100644
--- a/tests/FrontBufferedStreamTest.cpp
+++ b/tests/FrontBufferedStreamTest.cpp
@@ -285,5 +285,5 @@ DEF_TEST(ShortFrontBufferedStream, reporter) {
// 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 5749df1be5..daa5cf56d0 100644
--- a/tests/GifTest.cpp
+++ b/tests/GifTest.cpp
@@ -195,7 +195,7 @@ DEF_TEST(Gif, reporter) {
// 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 @@ DEF_TEST(Gif_Sampled, r) {
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 @@ DEF_TEST(Codec_GifTruncated, r) {
// 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 @@ DEF_TEST(Codec_GifTruncated2, r) {
// 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 96bca35c92..35bebad274 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 @@ static void test_get_data_at_position(skiatest::Reporter* r, SkStreamBuffer* buf
}
// 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 @@ static void test_buffer_from_beginning(skiatest::Reporter* r, SkStream* stream,
}
// 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 @@ DEF_TEST(StreamBuffer, r) {
}
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 @@ DEF_TEST(StreamBuffer, r) {
}
// 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 @@ DEF_TEST(StreamBuffer, r) {
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 @@ DEF_TEST(StreamBuffer, r) {
// 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 @@ DEF_TEST(StreamBuffer, r) {
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 0c31c0929a..825e2d1628 100644
--- a/tests/YUVTest.cpp
+++ b/tests/YUVTest.cpp
@@ -20,7 +20,7 @@ static void codec_yuv(skiatest::Reporter* reporter,
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;