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 /include/codec | |
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 'include/codec')
-rw-r--r-- | include/codec/SkAndroidCodec.h | 14 | ||||
-rw-r--r-- | include/codec/SkCodec.h | 19 |
2 files changed, 22 insertions, 11 deletions
diff --git a/include/codec/SkAndroidCodec.h b/include/codec/SkAndroidCodec.h index b4dd3854e6..e785411ea9 100644 --- a/include/codec/SkAndroidCodec.h +++ b/include/codec/SkAndroidCodec.h @@ -29,7 +29,8 @@ public: * 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 @@ public: * 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 bb780f0906..1d6d904e28 100644 --- a/include/codec/SkCodec.h +++ b/include/codec/SkCodec.h @@ -139,8 +139,8 @@ public: * 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 @@ public: * 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 @@ public: 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 { |