OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkFrontBufferedStream.h" | 8 #include "SkFrontBufferedStream.h" |
9 #include "SkStream.h" | 9 #include "SkStream.h" |
10 #include "SkTemplates.h" | 10 #include "SkTemplates.h" |
(...skipping 13 matching lines...) Loading... |
24 | 24 |
25 size_t getPosition() const SK_OVERRIDE { return fOffset; } | 25 size_t getPosition() const SK_OVERRIDE { return fOffset; } |
26 | 26 |
27 bool hasLength() const SK_OVERRIDE { return fHasLength; } | 27 bool hasLength() const SK_OVERRIDE { return fHasLength; } |
28 | 28 |
29 size_t getLength() const SK_OVERRIDE { return fLength; } | 29 size_t getLength() const SK_OVERRIDE { return fLength; } |
30 | 30 |
31 SkStreamRewindable* duplicate() const SK_OVERRIDE { return NULL; } | 31 SkStreamRewindable* duplicate() const SK_OVERRIDE { return NULL; } |
32 | 32 |
33 private: | 33 private: |
34 SkAutoTUnref<SkStream> fStream; | 34 SkAutoTDelete<SkStream> fStream; |
35 const bool fHasLength; | 35 const bool fHasLength; |
36 const size_t fLength; | 36 const size_t fLength; |
37 // Current offset into the stream. Always >= 0. | 37 // Current offset into the stream. Always >= 0. |
38 size_t fOffset; | 38 size_t fOffset; |
39 // Amount that has been buffered by calls to read. Will always be less than | 39 // Amount that has been buffered by calls to read. Will always be less than |
40 // fBufferSize. | 40 // fBufferSize. |
41 size_t fBufferedSoFar; | 41 size_t fBufferedSoFar; |
42 // Total size of the buffer. | 42 // Total size of the buffer. |
43 const size_t fBufferSize; | 43 const size_t fBufferSize; |
44 // FIXME: SkAutoTMalloc throws on failure. Instead, Create should return a | 44 // FIXME: SkAutoTMalloc throws on failure. Instead, Create should return a |
(...skipping 19 matching lines...) Loading... |
64 }; | 64 }; |
65 | 65 |
66 SkStreamRewindable* SkFrontBufferedStream::Create(SkStream* stream, size_t buffe
rSize) { | 66 SkStreamRewindable* SkFrontBufferedStream::Create(SkStream* stream, size_t buffe
rSize) { |
67 if (NULL == stream) { | 67 if (NULL == stream) { |
68 return NULL; | 68 return NULL; |
69 } | 69 } |
70 return SkNEW_ARGS(FrontBufferedStream, (stream, bufferSize)); | 70 return SkNEW_ARGS(FrontBufferedStream, (stream, bufferSize)); |
71 } | 71 } |
72 | 72 |
73 FrontBufferedStream::FrontBufferedStream(SkStream* stream, size_t bufferSize) | 73 FrontBufferedStream::FrontBufferedStream(SkStream* stream, size_t bufferSize) |
74 : fStream(SkRef(stream)) | 74 : fStream(stream) |
75 , fHasLength(stream->hasPosition() && stream->hasLength()) | 75 , fHasLength(stream->hasPosition() && stream->hasLength()) |
76 , fLength(stream->getLength() - stream->getPosition()) | 76 , fLength(stream->getLength() - stream->getPosition()) |
77 , fOffset(0) | 77 , fOffset(0) |
78 , fBufferedSoFar(0) | 78 , fBufferedSoFar(0) |
79 , fBufferSize(bufferSize) | 79 , fBufferSize(bufferSize) |
80 , fBuffer(bufferSize) {} | 80 , fBuffer(bufferSize) {} |
81 | 81 |
82 bool FrontBufferedStream::isAtEnd() const { | 82 bool FrontBufferedStream::isAtEnd() const { |
83 if (fOffset < fBufferedSoFar) { | 83 if (fOffset < fBufferedSoFar) { |
84 // Even if the underlying stream is at the end, this stream has been | 84 // Even if the underlying stream is at the end, this stream has been |
(...skipping 104 matching lines...) Loading... |
189 } | 189 } |
190 | 190 |
191 if (size > 0 && !fStream->isAtEnd()) { | 191 if (size > 0 && !fStream->isAtEnd()) { |
192 SkDEBUGCODE(const size_t bytesReadDirectly =) this->readDirectlyFromStre
am(dst, size); | 192 SkDEBUGCODE(const size_t bytesReadDirectly =) this->readDirectlyFromStre
am(dst, size); |
193 SkDEBUGCODE(size -= bytesReadDirectly;) | 193 SkDEBUGCODE(size -= bytesReadDirectly;) |
194 SkASSERT(size + (fOffset - start) == totalSize); | 194 SkASSERT(size + (fOffset - start) == totalSize); |
195 } | 195 } |
196 | 196 |
197 return fOffset - start; | 197 return fOffset - start; |
198 } | 198 } |
OLD | NEW |