blob: ed678b3a2289cbf8f3a4959d7134b856b79c4ede [file] [log] [blame]
scroggo@google.com83fd2c72013-09-26 21:35:39 +00001/*
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 III63cfb362020-04-24 13:00:48 -04008#ifndef FrontBufferedStream_DEFINED
9#define FrontBufferedStream_DEFINED
Hal Canary03a7f5f2017-02-10 09:06:38 -050010
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkStream.h"
scroggo@google.com83fd2c72013-09-26 21:35:39 +000012
Leon Scroggins III63cfb362020-04-24 13:00:48 -040013namespace android {
14namespace skia {
scroggo@google.com83fd2c72013-09-26 21:35:39 +000015/**
scroggo@google.com09a53832013-11-12 20:53:05 +000016 * Specialized stream that buffers the first X bytes of a stream,
scroggo@google.com83fd2c72013-09-26 21:35:39 +000017 * where X is passed in by the user. Note that unlike some buffered
scroggo@google.com09a53832013-11-12 20:53:05 +000018 * 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.com83fd2c72013-09-26 21:35:39 +000023 */
Leon Scroggins III63cfb362020-04-24 13:00:48 -040024class SK_API FrontBufferedStream {
scroggo@google.com83fd2c72013-09-26 21:35:39 +000025public:
26 /**
scroggo@google.com09a53832013-11-12 20:53:05 +000027 * 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 III63cfb362020-04-24 13:00:48 -040030 * FrontBufferedStream is expected to be the only owner of
scroggoa1193e42015-01-21 12:09:53 -080031 * stream, so it should no be longer used directly.
Leon Scroggins III63cfb362020-04-24 13:00:48 -040032 * FrontBufferedStream will delete stream upon deletion.
scroggo@google.com09a53832013-11-12 20:53:05 +000033 * @param minBufferSize Minimum size of buffer required.
34 * @return An SkStream that can buffer at least minBufferSize, or
scroggoa1193e42015-01-21 12:09:53 -080035 * NULL on failure. The caller is required to delete when finished with
36 * this object.
scroggo@google.com83fd2c72013-09-26 21:35:39 +000037 */
Mike Reed98c5d922017-09-15 21:39:47 -040038 static std::unique_ptr<SkStreamRewindable> Make(std::unique_ptr<SkStream> stream,
39 size_t minBufferSize);
scroggo@google.com83fd2c72013-09-26 21:35:39 +000040};
Leon Scroggins III63cfb362020-04-24 13:00:48 -040041} // namespace skia
42} // namespace android
43#endif // FrontBufferedStream_DEFINED