diff options
author | 2017-07-26 11:35:53 -0400 | |
---|---|---|
committer | 2017-07-26 15:59:49 +0000 | |
commit | 847068ce833f2409ae2f5e39d14616899b24e1a5 (patch) | |
tree | c4a94a3568ced9c3f8cdaf3a18a54a6031fa0a59 /include/core/SkStream.h | |
parent | 50fa3ff1381028e8a155522a4598678911bce53d (diff) |
add Make factory to SkMemoryStream (simplify call-sites)
Bug: skia:6888
Change-Id: Ia4e432673ed089a91229697c8dde0489f220000d
Reviewed-on: https://skia-review.googlesource.com/26884
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
Diffstat (limited to 'include/core/SkStream.h')
-rw-r--r-- | include/core/SkStream.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/include/core/SkStream.h b/include/core/SkStream.h index 01fd82a530..1862117bb6 100644 --- a/include/core/SkStream.h +++ b/include/core/SkStream.h @@ -263,6 +263,11 @@ public: ~SkFILEStream() override; + static std::unique_ptr<SkFILEStream> Make(const char path[]) { + SkFILEStream* stream = new SkFILEStream(path); + return stream->isValid() ? std::unique_ptr<SkFILEStream>(stream) : nullptr; + } + /** Returns true if the current path could be opened. */ bool isValid() const { return fFILE != nullptr; } @@ -308,6 +313,15 @@ public: /** Creates the stream to read from the specified data */ SkMemoryStream(sk_sp<SkData>); + /** Returns a stream with a copy of the input data. */ + static std::unique_ptr<SkMemoryStream> MakeCopy(const void* data, size_t length); + + /** Returns a stream with a bare pointer reference to the input data. */ + static std::unique_ptr<SkMemoryStream> MakeDirect(const void* data, size_t length); + + /** Returns a stream with a shared reference to the input data. */ + static std::unique_ptr<SkMemoryStream> Make(sk_sp<SkData> data); + /** Resets the stream to the specified data and length, just like the constructor. if copyData is true, the stream makes a private copy of the data |