• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
8 #ifndef FrontBufferedStream_DEFINED
9 #define FrontBufferedStream_DEFINED
10 
11 #include "include/core/SkStream.h"
12 
13 namespace android {
14 namespace skia {
15 /**
16  *  Specialized stream that buffers the first X bytes of a stream,
17  *  where X is passed in by the user. Note that unlike some buffered
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.
23  */
24 class SK_API FrontBufferedStream {
25 public:
26     /**
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),
30      *      FrontBufferedStream is expected to be the only owner of
31      *      stream, so it should no be longer used directly.
32      *      FrontBufferedStream will delete stream upon deletion.
33      *  @param minBufferSize Minimum size of buffer required.
34      *  @return An SkStream that can buffer at least minBufferSize, or
35      *      NULL on failure. The caller is required to delete when finished with
36      *      this object.
37      */
38     static std::unique_ptr<SkStreamRewindable> Make(std::unique_ptr<SkStream> stream,
39                                                     size_t minBufferSize);
40 };
41 } // namespace skia
42 } // namespace android
43 #endif  // FrontBufferedStream_DEFINED
44