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" |
11 | 11 |
12 class FrontBufferedStream : public SkStreamRewindable { | 12 class FrontBufferedStream : public SkStreamRewindable { |
13 public: | 13 public: |
14 // Called by Create. | 14 // Called by Create. |
15 FrontBufferedStream(SkStream*, size_t bufferSize); | 15 FrontBufferedStream(SkStream*, size_t bufferSize); |
16 | 16 |
17 virtual size_t read(void* buffer, size_t size) SK_OVERRIDE; | 17 size_t read(void* buffer, size_t size) SK_OVERRIDE; |
18 | 18 |
19 virtual bool isAtEnd() const SK_OVERRIDE; | 19 bool isAtEnd() const SK_OVERRIDE; |
20 | 20 |
21 virtual bool rewind() SK_OVERRIDE; | 21 bool rewind() SK_OVERRIDE; |
22 | 22 |
23 virtual bool hasPosition() const SK_OVERRIDE { return true; } | 23 bool hasPosition() const SK_OVERRIDE { return true; } |
24 | 24 |
25 virtual size_t getPosition() const SK_OVERRIDE { return fOffset; } | 25 size_t getPosition() const SK_OVERRIDE { return fOffset; } |
26 | 26 |
27 virtual bool hasLength() const SK_OVERRIDE { return fHasLength; } | 27 bool hasLength() const SK_OVERRIDE { return fHasLength; } |
28 | 28 |
29 virtual size_t getLength() const SK_OVERRIDE { return fLength; } | 29 size_t getLength() const SK_OVERRIDE { return fLength; } |
30 | 30 |
31 virtual 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 SkAutoTUnref<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; |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 |