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

Side by Side Diff: src/utils/SkFrontBufferedStream.cpp

Issue 849103004: Make SkStream *not* ref counted. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase, just in case. Created 5 years, 11 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 unified diff | Download patch
« no previous file with comments | « src/sfnt/SkOTUtils.h ('k') | src/utils/SkPDFRasterizer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 13 matching lines...) Expand all
24 24
25 size_t getPosition() const SK_OVERRIDE { return fOffset; } 25 size_t getPosition() const SK_OVERRIDE { return fOffset; }
26 26
27 bool hasLength() const SK_OVERRIDE { return fHasLength; } 27 bool hasLength() const SK_OVERRIDE { return fHasLength; }
28 28
29 size_t getLength() const SK_OVERRIDE { return fLength; } 29 size_t getLength() const SK_OVERRIDE { return fLength; }
30 30
31 SkStreamRewindable* duplicate() const SK_OVERRIDE { return NULL; } 31 SkStreamRewindable* duplicate() const SK_OVERRIDE { return NULL; }
32 32
33 private: 33 private:
34 SkAutoTUnref<SkStream> fStream; 34 SkAutoTDelete<SkStream> fStream;
35 const bool fHasLength; 35 const bool fHasLength;
36 const size_t fLength; 36 const size_t fLength;
37 // Current offset into the stream. Always >= 0. 37 // Current offset into the stream. Always >= 0.
38 size_t fOffset; 38 size_t fOffset;
39 // Amount that has been buffered by calls to read. Will always be less than 39 // Amount that has been buffered by calls to read. Will always be less than
40 // fBufferSize. 40 // fBufferSize.
41 size_t fBufferedSoFar; 41 size_t fBufferedSoFar;
42 // Total size of the buffer. 42 // Total size of the buffer.
43 const size_t fBufferSize; 43 const size_t fBufferSize;
44 // FIXME: SkAutoTMalloc throws on failure. Instead, Create should return a 44 // FIXME: SkAutoTMalloc throws on failure. Instead, Create should return a
(...skipping 19 matching lines...) Expand all
64 }; 64 };
65 65
66 SkStreamRewindable* SkFrontBufferedStream::Create(SkStream* stream, size_t buffe rSize) { 66 SkStreamRewindable* SkFrontBufferedStream::Create(SkStream* stream, size_t buffe rSize) {
67 if (NULL == stream) { 67 if (NULL == stream) {
68 return NULL; 68 return NULL;
69 } 69 }
70 return SkNEW_ARGS(FrontBufferedStream, (stream, bufferSize)); 70 return SkNEW_ARGS(FrontBufferedStream, (stream, bufferSize));
71 } 71 }
72 72
73 FrontBufferedStream::FrontBufferedStream(SkStream* stream, size_t bufferSize) 73 FrontBufferedStream::FrontBufferedStream(SkStream* stream, size_t bufferSize)
74 : fStream(SkRef(stream)) 74 : fStream(stream)
75 , fHasLength(stream->hasPosition() && stream->hasLength()) 75 , fHasLength(stream->hasPosition() && stream->hasLength())
76 , fLength(stream->getLength() - stream->getPosition()) 76 , fLength(stream->getLength() - stream->getPosition())
77 , fOffset(0) 77 , fOffset(0)
78 , fBufferedSoFar(0) 78 , fBufferedSoFar(0)
79 , fBufferSize(bufferSize) 79 , fBufferSize(bufferSize)
80 , fBuffer(bufferSize) {} 80 , fBuffer(bufferSize) {}
81 81
82 bool FrontBufferedStream::isAtEnd() const { 82 bool FrontBufferedStream::isAtEnd() const {
83 if (fOffset < fBufferedSoFar) { 83 if (fOffset < fBufferedSoFar) {
84 // Even if the underlying stream is at the end, this stream has been 84 // Even if the underlying stream is at the end, this stream has been
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 } 189 }
190 190
191 if (size > 0 && !fStream->isAtEnd()) { 191 if (size > 0 && !fStream->isAtEnd()) {
192 SkDEBUGCODE(const size_t bytesReadDirectly =) this->readDirectlyFromStre am(dst, size); 192 SkDEBUGCODE(const size_t bytesReadDirectly =) this->readDirectlyFromStre am(dst, size);
193 SkDEBUGCODE(size -= bytesReadDirectly;) 193 SkDEBUGCODE(size -= bytesReadDirectly;)
194 SkASSERT(size + (fOffset - start) == totalSize); 194 SkASSERT(size + (fOffset - start) == totalSize);
195 } 195 }
196 196
197 return fOffset - start; 197 return fOffset - start;
198 } 198 }
OLDNEW
« no previous file with comments | « src/sfnt/SkOTUtils.h ('k') | src/utils/SkPDFRasterizer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698