2013-09-26 21:35:39 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2020-04-24 17:00:48 +00:00
|
|
|
#ifndef FrontBufferedStream_DEFINED
|
|
|
|
#define FrontBufferedStream_DEFINED
|
2017-02-10 14:06:38 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkStream.h"
|
2013-09-26 21:35:39 +00:00
|
|
|
|
2020-04-24 17:00:48 +00:00
|
|
|
namespace android {
|
|
|
|
namespace skia {
|
2013-09-26 21:35:39 +00:00
|
|
|
/**
|
2013-11-12 20:53:05 +00:00
|
|
|
* Specialized stream that buffers the first X bytes of a stream,
|
2013-09-26 21:35:39 +00:00
|
|
|
* where X is passed in by the user. Note that unlike some buffered
|
2013-11-12 20:53:05 +00:00
|
|
|
* stream APIs, once more bytes than can fit in the buffer are read,
|
|
|
|
* no more buffering is done. This stream is designed for a use case
|
|
|
|
* where the caller knows that rewind will only be called from within
|
|
|
|
* X bytes (inclusive), and the wrapped stream is not necessarily
|
|
|
|
* able to rewind at all.
|
2013-09-26 21:35:39 +00:00
|
|
|
*/
|
2020-04-24 17:00:48 +00:00
|
|
|
class SK_API FrontBufferedStream {
|
2013-09-26 21:35:39 +00:00
|
|
|
public:
|
|
|
|
/**
|
2013-11-12 20:53:05 +00:00
|
|
|
* Creates a new stream that wraps and buffers an SkStream.
|
|
|
|
* @param stream SkStream to buffer. If stream is NULL, NULL is
|
|
|
|
* returned. When this call succeeds (i.e. returns non NULL),
|
2020-04-24 17:00:48 +00:00
|
|
|
* FrontBufferedStream is expected to be the only owner of
|
2015-01-21 20:09:53 +00:00
|
|
|
* stream, so it should no be longer used directly.
|
2020-04-24 17:00:48 +00:00
|
|
|
* FrontBufferedStream will delete stream upon deletion.
|
2013-11-12 20:53:05 +00:00
|
|
|
* @param minBufferSize Minimum size of buffer required.
|
|
|
|
* @return An SkStream that can buffer at least minBufferSize, or
|
2015-01-21 20:09:53 +00:00
|
|
|
* NULL on failure. The caller is required to delete when finished with
|
|
|
|
* this object.
|
2013-09-26 21:35:39 +00:00
|
|
|
*/
|
2017-09-16 01:39:47 +00:00
|
|
|
static std::unique_ptr<SkStreamRewindable> Make(std::unique_ptr<SkStream> stream,
|
|
|
|
size_t minBufferSize);
|
2013-09-26 21:35:39 +00:00
|
|
|
};
|
2020-04-24 17:00:48 +00:00
|
|
|
} // namespace skia
|
|
|
|
} // namespace android
|
|
|
|
#endif // FrontBufferedStream_DEFINED
|