blob: 3532fc5259fc4525fecf6164f573b37ed0af9386 [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
Hal Canary03a7f5f2017-02-10 09:06:38 -05008#ifndef SkFrontBufferedStream_DEFINED
9#define SkFrontBufferedStream_DEFINED
10
scroggo@google.com09a53832013-11-12 20:53:05 +000011#include "SkTypes.h"
12
13class SkStream;
14class SkStreamRewindable;
scroggo@google.com83fd2c72013-09-26 21:35:39 +000015
16/**
scroggo@google.com09a53832013-11-12 20:53:05 +000017 * Specialized stream that buffers the first X bytes of a stream,
scroggo@google.com83fd2c72013-09-26 21:35:39 +000018 * where X is passed in by the user. Note that unlike some buffered
scroggo@google.com09a53832013-11-12 20:53:05 +000019 * stream APIs, once more bytes than can fit in the buffer are read,
20 * no more buffering is done. This stream is designed for a use case
21 * where the caller knows that rewind will only be called from within
22 * X bytes (inclusive), and the wrapped stream is not necessarily
23 * able to rewind at all.
scroggo@google.com83fd2c72013-09-26 21:35:39 +000024 */
scroggo@google.com09a53832013-11-12 20:53:05 +000025class SkFrontBufferedStream {
scroggo@google.com83fd2c72013-09-26 21:35:39 +000026public:
27 /**
scroggo@google.com09a53832013-11-12 20:53:05 +000028 * Creates a new stream that wraps and buffers an SkStream.
29 * @param stream SkStream to buffer. If stream is NULL, NULL is
30 * returned. When this call succeeds (i.e. returns non NULL),
31 * SkFrontBufferedStream is expected to be the only owner of
scroggoa1193e42015-01-21 12:09:53 -080032 * stream, so it should no be longer used directly.
33 * SkFrontBufferedStream will delete stream upon deletion.
scroggo@google.com09a53832013-11-12 20:53:05 +000034 * @param minBufferSize Minimum size of buffer required.
35 * @return An SkStream that can buffer at least minBufferSize, or
scroggoa1193e42015-01-21 12:09:53 -080036 * NULL on failure. The caller is required to delete when finished with
37 * this object.
scroggo@google.com83fd2c72013-09-26 21:35:39 +000038 */
scroggo@google.com09a53832013-11-12 20:53:05 +000039 static SkStreamRewindable* Create(SkStream* stream, size_t minBufferSize);
scroggo@google.com83fd2c72013-09-26 21:35:39 +000040};
Hal Canary03a7f5f2017-02-10 09:06:38 -050041#endif // SkFrontBufferedStream_DEFINED