diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkStream.cpp | 14 | ||||
-rw-r--r-- | src/utils/SkFrontBufferedStream.cpp | 16 |
2 files changed, 30 insertions, 0 deletions
diff --git a/src/core/SkStream.cpp b/src/core/SkStream.cpp index 426f5569e8..ad67a0ba7d 100644 --- a/src/core/SkStream.cpp +++ b/src/core/SkStream.cpp @@ -367,6 +367,20 @@ size_t SkMemoryStream::read(void* buffer, size_t size) { return size; } +bool SkMemoryStream::peek(void* buffer, size_t size) const { + SkASSERT(buffer != NULL); + const size_t position = fOffset; + if (size > fData->size() - position) { + // The stream is not large enough to satisfy this request. + return false; + } + SkMemoryStream* nonConstThis = const_cast<SkMemoryStream*>(this); + SkDEBUGCODE(const size_t bytesRead =) nonConstThis->read(buffer, size); + SkASSERT(bytesRead == size); + nonConstThis->fOffset = position; + return true; +} + bool SkMemoryStream::isAtEnd() const { return fOffset == fData->size(); } diff --git a/src/utils/SkFrontBufferedStream.cpp b/src/utils/SkFrontBufferedStream.cpp index f23b1f99c4..beead37a95 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,20 @@ 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); + SkDEBUGCODE(const size_t bytesRead =) nonConstThis->read(dst, size); + SkASSERT(bytesRead == size); + nonConstThis->fOffset = start; + return true; +} + size_t FrontBufferedStream::read(void* voidDst, size_t size) { // Cast voidDst to a char* for easy addition. char* dst = reinterpret_cast<char*>(voidDst); |