Chromium Code Reviews| 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 { | |
| 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 ~SkBufferedStream(); | |
| 24 | |
| 25 virtual size_t read(void* buffer, size_t size) SK_OVERRIDE; | |
| 26 | |
| 27 virtual bool isAtEnd() const SK_OVERRIDE; | |
| 28 | |
| 29 virtual bool rewind() SK_OVERRIDE; | |
| 30 | |
| 31 virtual bool hasPosition() const SK_OVERRIDE { return true; } | |
| 32 | |
| 33 virtual size_t getPosition() const SK_OVERRIDE { return fOffset; } | |
| 34 | |
| 35 virtual bool hasLength() const SK_OVERRIDE; | |
| 36 | |
| 37 virtual size_t getLength() const SK_OVERRIDE; | |
| 38 | |
| 39 virtual SkStreamRewindable* duplicate() const SK_OVERRIDE { return NULL; } | |
| 40 | |
| 41 private: | |
| 42 SkStream* fStream; | |
|
mtklein
2013/09/17 19:18:32
SkAutoTUnref?
scroggo
2013/09/17 20:12:52
Done.
| |
| 43 size_t fOffset; | |
| 44 size_t fBufferedSoFar; | |
| 45 const size_t fBufferSize; | |
| 46 SkAutoMalloc fBuffer; | |
|
mtklein
2013/09/17 19:18:32
Maybe use an SkAutoTMalloc<char> or <uint8_t> here
scroggo
2013/09/17 20:12:52
Done.
| |
| 47 | |
| 48 // Unimplemented. | |
| 49 SkBufferedStream(); | |
| 50 | |
| 51 // Private. Use Create. | |
| 52 SkBufferedStream(SkStream*, size_t bufferSize); | |
| 53 | |
| 54 void* getBufferAtOffset() { | |
| 55 return reinterpret_cast<void*>(reinterpret_cast<char*>(fBuffer.get()) + fOffset); | |
| 56 } | |
| 57 | |
| 58 typedef SkStream INHERITED; | |
| 59 }; | |
| OLD | NEW |