diff options
author | Mike Reed <reed@google.com> | 2017-07-23 15:30:02 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-07-25 15:35:23 +0000 |
commit | ede7bac43fbc69b9fdf1c178890ba6353f5bb140 (patch) | |
tree | dccdba46e7abf125e2f90e6dc08eca00ad9cb09b /src/codec/SkBmpCodec.cpp | |
parent | fa3ed03720b5083afd3620c9239863f05f2eedbd (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 'src/codec/SkBmpCodec.cpp')
-rw-r--r-- | src/codec/SkBmpCodec.cpp | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/src/codec/SkBmpCodec.cpp b/src/codec/SkBmpCodec.cpp index 70397f656f..18f8768e0d 100644 --- a/src/codec/SkBmpCodec.cpp +++ b/src/codec/SkBmpCodec.cpp @@ -67,16 +67,17 @@ bool SkBmpCodec::IsBmp(const void* buffer, size_t bytesRead) { * 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 @@ SkCodec::Result SkBmpCodec::ReadHeader(SkStream* stream, bool inIco, // 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 @@ SkCodec::Result SkBmpCodec::ReadHeader(SkStream* stream, bool inIco, 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 @@ SkCodec::Result SkBmpCodec::ReadHeader(SkStream* stream, bool inIco, // 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 @@ SkCodec::Result SkBmpCodec::ReadHeader(SkStream* stream, bool inIco, * 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))) |