Index: src/utils/SkFrontBufferedStream.cpp |
diff --git a/src/utils/SkFrontBufferedStream.cpp b/src/utils/SkFrontBufferedStream.cpp |
index f23b1f99c4c6da1c98f8b947647ce977421546e8..bc68f8dbcc6c1ddfcc4e2559909edaa6f9d7ccd5 100644 |
--- a/src/utils/SkFrontBufferedStream.cpp |
+++ b/src/utils/SkFrontBufferedStream.cpp |
@@ -16,6 +16,8 @@ public: |
size_t read(void* buffer, size_t size) override; |
+ bool peek(void* buffer, size_t size) const override; |
+ |
bool isAtEnd() const override; |
bool rewind() override; |
@@ -155,6 +157,23 @@ size_t FrontBufferedStream::readDirectlyFromStream(char* dst, size_t size) { |
return bytesReadDirectly; |
} |
+bool FrontBufferedStream::peek(void* dst, size_t size) const { |
+ // Keep track of the offset so we can return to it. |
+ const size_t start = fOffset; |
+ if (start + size > fBufferSize) { |
+ // This stream is not able to buffer enough. |
+ return false; |
+ } |
+ FrontBufferedStream* nonConstThis = const_cast<FrontBufferedStream*>(this); |
+#ifdef SK_DEBUG |
+ const size_t bytesRead = |
+#endif |
+ nonConstThis->read(dst, size); |
+ SkASSERT(bytesRead == size); |
+ nonConstThis->fOffset = start; |
+ return bytesRead; |
scroggo
2015/04/02 19:49:43
Oops, this should be true. Good thing I tested in
|
+} |
+ |
size_t FrontBufferedStream::read(void* voidDst, size_t size) { |
// Cast voidDst to a char* for easy addition. |
char* dst = reinterpret_cast<char*>(voidDst); |