Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Unified Diff: src/utils/SkFrontBufferedStream.cpp

Issue 157103002: Allow buffered stream to work with an offset. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: No need for return from test_read Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/FrontBufferedStreamTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/utils/SkFrontBufferedStream.cpp
diff --git a/src/utils/SkFrontBufferedStream.cpp b/src/utils/SkFrontBufferedStream.cpp
index d44389b7c81ad4c8bdfd625b4f0c29d2625a6742..8cb3931082c75d268e793212a73f688a1dbe227f 100644
--- a/src/utils/SkFrontBufferedStream.cpp
+++ b/src/utils/SkFrontBufferedStream.cpp
@@ -24,14 +24,16 @@ public:
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 @@ SkStreamRewindable* SkFrontBufferedStream::Create(SkStream* stream, size_t buffe
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 @@ bool FrontBufferedStream::rewind() {
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
« no previous file with comments | « no previous file | tests/FrontBufferedStreamTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698