OLD | NEW |
---|---|
(Empty) | |
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 #include "SkStream.h" | |
9 #include "SkTypes.h" | |
10 | |
11 class SkBufferedStream : public SkStreamRewindable { | |
reed1
2013/09/17 20:23:02
We might consider just adding the static Create to
scroggo
2013/09/17 20:41:19
I was leaving it in utils since I think only Andro
| |
12 public: | |
13 /** | |
14 * Creates a new stream that wraps and buffers SkStream. | |
15 * @param stream SkStream to buffer. If NULL, NULL is returned. After | |
16 * this call, unref stream and do not refer to it. | |
17 * SkBufferedStream is expected to be its only owner. | |
18 * @param bufferSize Exact size of the buffer to be used. | |
19 * @return An SkStream that can buffer up to bufferSize. | |
20 */ | |
21 static SkBufferedStream* Create(SkStream* stream, size_t bufferSize); | |
22 | |
23 virtual size_t read(void* buffer, size_t size) SK_OVERRIDE; | |
24 | |
25 virtual bool isAtEnd() const SK_OVERRIDE; | |
26 | |
27 virtual bool rewind() SK_OVERRIDE; | |
28 | |
29 virtual bool hasPosition() const SK_OVERRIDE { return true; } | |
30 | |
31 virtual size_t getPosition() const SK_OVERRIDE { return fOffset; } | |
32 | |
33 virtual bool hasLength() const SK_OVERRIDE; | |
34 | |
35 virtual size_t getLength() const SK_OVERRIDE; | |
36 | |
37 virtual SkStreamRewindable* duplicate() const SK_OVERRIDE { return NULL; } | |
38 | |
39 private: | |
40 SkAutoTUnref<SkStream> fStream; | |
41 size_t fOffset; | |
42 size_t fBufferedSoFar; | |
43 const size_t fBufferSize; | |
44 SkAutoTMalloc<char> fBuffer; | |
45 | |
46 // Unimplemented. | |
47 SkBufferedStream(); | |
48 | |
49 // Private. Use Create. | |
50 SkBufferedStream(SkStream*, size_t bufferSize); | |
51 | |
52 char* getBufferAtOffset() { | |
53 return fBuffer.get() + fOffset; | |
54 } | |
55 | |
56 typedef SkStream INHERITED; | |
57 }; | |
OLD | NEW |