Allow buffered stream to work with an offset.
If the stream being buffered is buffered from somewhere other than
the start, the SkFrontBufferedStream needs to take that into account
when reporting its length.
R=djsollen@google.com, bungeman@google.com, reed@google.com
Author: scroggo@google.com
Review URL: https://codereview.chromium.org/157103002
git-svn-id: http://skia.googlecode.com/svn/trunk@13388 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/utils/SkFrontBufferedStream.cpp b/src/utils/SkFrontBufferedStream.cpp
index d44389b..8cb3931 100644
--- a/src/utils/SkFrontBufferedStream.cpp
+++ b/src/utils/SkFrontBufferedStream.cpp
@@ -24,14 +24,16 @@
virtual size_t getPosition() const SK_OVERRIDE { return fOffset; }
- virtual bool hasLength() const SK_OVERRIDE;
+ virtual bool hasLength() const SK_OVERRIDE { return fHasLength; }
- virtual size_t getLength() const SK_OVERRIDE;
+ virtual size_t getLength() const SK_OVERRIDE { return fLength; }
virtual SkStreamRewindable* duplicate() const SK_OVERRIDE { return NULL; }
private:
SkAutoTUnref<SkStream> fStream;
+ const bool fHasLength;
+ const size_t fLength;
// Current offset into the stream. Always >= 0.
size_t fOffset;
// Amount that has been buffered by calls to read. Will always be less than
@@ -70,6 +72,8 @@
FrontBufferedStream::FrontBufferedStream(SkStream* stream, size_t bufferSize)
: fStream(SkRef(stream))
+ , fHasLength(stream->hasPosition() && stream->hasLength())
+ , fLength(stream->getLength() - stream->getPosition())
, fOffset(0)
, fBufferedSoFar(0)
, fBufferSize(bufferSize)
@@ -94,14 +98,6 @@
return false;
}
-bool FrontBufferedStream::hasLength() const {
- return fStream->hasLength();
-}
-
-size_t FrontBufferedStream::getLength() const {
- return fStream->getLength();
-}
-
size_t FrontBufferedStream::readFromBuffer(char* dst, size_t size) {
SkASSERT(fOffset < fBufferedSoFar);
// Some data has already been copied to fBuffer. Read up to the