scroggo@google.com | 83fd2c7 | 2013-09-26 21:35:39 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
Leon Scroggins III | 63cfb36 | 2020-04-24 13:00:48 -0400 | [diff] [blame] | 8 | #ifndef FrontBufferedStream_DEFINED |
| 9 | #define FrontBufferedStream_DEFINED |
Hal Canary | 03a7f5f | 2017-02-10 09:06:38 -0500 | [diff] [blame] | 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/core/SkStream.h" |
scroggo@google.com | 83fd2c7 | 2013-09-26 21:35:39 +0000 | [diff] [blame] | 12 | |
Leon Scroggins III | 63cfb36 | 2020-04-24 13:00:48 -0400 | [diff] [blame] | 13 | namespace android { |
| 14 | namespace skia { |
scroggo@google.com | 83fd2c7 | 2013-09-26 21:35:39 +0000 | [diff] [blame] | 15 | /** |
scroggo@google.com | 09a5383 | 2013-11-12 20:53:05 +0000 | [diff] [blame] | 16 | * Specialized stream that buffers the first X bytes of a stream, |
scroggo@google.com | 83fd2c7 | 2013-09-26 21:35:39 +0000 | [diff] [blame] | 17 | * where X is passed in by the user. Note that unlike some buffered |
scroggo@google.com | 09a5383 | 2013-11-12 20:53:05 +0000 | [diff] [blame] | 18 | * stream APIs, once more bytes than can fit in the buffer are read, |
| 19 | * no more buffering is done. This stream is designed for a use case |
| 20 | * where the caller knows that rewind will only be called from within |
| 21 | * X bytes (inclusive), and the wrapped stream is not necessarily |
| 22 | * able to rewind at all. |
scroggo@google.com | 83fd2c7 | 2013-09-26 21:35:39 +0000 | [diff] [blame] | 23 | */ |
Leon Scroggins III | 63cfb36 | 2020-04-24 13:00:48 -0400 | [diff] [blame] | 24 | class SK_API FrontBufferedStream { |
scroggo@google.com | 83fd2c7 | 2013-09-26 21:35:39 +0000 | [diff] [blame] | 25 | public: |
| 26 | /** |
scroggo@google.com | 09a5383 | 2013-11-12 20:53:05 +0000 | [diff] [blame] | 27 | * Creates a new stream that wraps and buffers an SkStream. |
| 28 | * @param stream SkStream to buffer. If stream is NULL, NULL is |
| 29 | * returned. When this call succeeds (i.e. returns non NULL), |
Leon Scroggins III | 63cfb36 | 2020-04-24 13:00:48 -0400 | [diff] [blame] | 30 | * FrontBufferedStream is expected to be the only owner of |
scroggo | a1193e4 | 2015-01-21 12:09:53 -0800 | [diff] [blame] | 31 | * stream, so it should no be longer used directly. |
Leon Scroggins III | 63cfb36 | 2020-04-24 13:00:48 -0400 | [diff] [blame] | 32 | * FrontBufferedStream will delete stream upon deletion. |
scroggo@google.com | 09a5383 | 2013-11-12 20:53:05 +0000 | [diff] [blame] | 33 | * @param minBufferSize Minimum size of buffer required. |
| 34 | * @return An SkStream that can buffer at least minBufferSize, or |
scroggo | a1193e4 | 2015-01-21 12:09:53 -0800 | [diff] [blame] | 35 | * NULL on failure. The caller is required to delete when finished with |
| 36 | * this object. |
scroggo@google.com | 83fd2c7 | 2013-09-26 21:35:39 +0000 | [diff] [blame] | 37 | */ |
Mike Reed | 98c5d92 | 2017-09-15 21:39:47 -0400 | [diff] [blame] | 38 | static std::unique_ptr<SkStreamRewindable> Make(std::unique_ptr<SkStream> stream, |
| 39 | size_t minBufferSize); |
scroggo@google.com | 83fd2c7 | 2013-09-26 21:35:39 +0000 | [diff] [blame] | 40 | }; |
Leon Scroggins III | 63cfb36 | 2020-04-24 13:00:48 -0400 | [diff] [blame] | 41 | } // namespace skia |
| 42 | } // namespace android |
| 43 | #endif // FrontBufferedStream_DEFINED |