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 { | |
| 
 
bungeman-skia
2013/09/17 22:19:11
So I'm a bit iffy about the name, simply because t
 
scroggo
2013/09/18 15:15:44
Good point. How about SkFrontBufferedStream?
 
 | |
| 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 // Current offset into the stream. Always >= 0. | |
| 42 size_t fOffset; | |
| 43 // Amount that has been buffered by calls to read. Will always be less than | |
| 44 // fBufferSize. | |
| 45 size_t fBufferedSoFar; | |
| 46 // Total size of the buffer. | |
| 47 const size_t fBufferSize; | |
| 48 SkAutoTMalloc<char> fBuffer; | |
| 49 | |
| 50 // Unimplemented. | |
| 51 SkBufferedStream(); | |
| 52 | |
| 53 // Private. Use Create. | |
| 54 SkBufferedStream(SkStream*, size_t bufferSize); | |
| 55 | |
| 56 char* getBufferAtOffset() { | |
| 57 return fBuffer.get() + fOffset; | |
| 58 } | |
| 59 | |
| 60 typedef SkStream INHERITED; | |
| 61 }; | |
| OLD | NEW |