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/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) {