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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 // data, and size is greater than 0. | 62 // data, and size is greater than 0. |
63 size_t readDirectlyFromStream(char* dst, size_t size); | 63 size_t readDirectlyFromStream(char* dst, size_t size); |
64 | 64 |
65 typedef SkStream INHERITED; | 65 typedef SkStream INHERITED; |
66 }; | 66 }; |
67 | 67 |
68 SkStreamRewindable* SkFrontBufferedStream::Create(SkStream* stream, size_t buffe
rSize) { | 68 SkStreamRewindable* SkFrontBufferedStream::Create(SkStream* stream, size_t buffe
rSize) { |
69 if (NULL == stream) { | 69 if (NULL == stream) { |
70 return NULL; | 70 return NULL; |
71 } | 71 } |
72 return SkNEW_ARGS(FrontBufferedStream, (stream, bufferSize)); | 72 return new FrontBufferedStream(stream, bufferSize); |
73 } | 73 } |
74 | 74 |
75 FrontBufferedStream::FrontBufferedStream(SkStream* stream, size_t bufferSize) | 75 FrontBufferedStream::FrontBufferedStream(SkStream* stream, size_t bufferSize) |
76 : fStream(stream) | 76 : fStream(stream) |
77 , fHasLength(stream->hasPosition() && stream->hasLength()) | 77 , fHasLength(stream->hasPosition() && stream->hasLength()) |
78 , fLength(stream->getLength() - stream->getPosition()) | 78 , fLength(stream->getLength() - stream->getPosition()) |
79 , fOffset(0) | 79 , fOffset(0) |
80 , fBufferedSoFar(0) | 80 , fBufferedSoFar(0) |
81 , fBufferSize(bufferSize) | 81 , fBufferSize(bufferSize) |
82 , fBuffer(bufferSize) {} | 82 , fBuffer(bufferSize) {} |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 } | 205 } |
206 | 206 |
207 if (size > 0 && !fStream->isAtEnd()) { | 207 if (size > 0 && !fStream->isAtEnd()) { |
208 SkDEBUGCODE(const size_t bytesReadDirectly =) this->readDirectlyFromStre
am(dst, size); | 208 SkDEBUGCODE(const size_t bytesReadDirectly =) this->readDirectlyFromStre
am(dst, size); |
209 SkDEBUGCODE(size -= bytesReadDirectly;) | 209 SkDEBUGCODE(size -= bytesReadDirectly;) |
210 SkASSERT(size + (fOffset - start) == totalSize); | 210 SkASSERT(size + (fOffset - start) == totalSize); |
211 } | 211 } |
212 | 212 |
213 return fOffset - start; | 213 return fOffset - start; |
214 } | 214 } |
OLD | NEW |