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

Side by Side Diff: include/core/SkStream.h

Issue 1044953002: Add a method to read a stream without advancing it. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 8 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 | « no previous file | src/utils/SkFrontBufferedStream.cpp » ('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 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
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 #ifndef SkStream_DEFINED 8 #ifndef SkStream_DEFINED
9 #define SkStream_DEFINED 9 #define SkStream_DEFINED
10 10
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 */ 56 */
57 virtual size_t read(void* buffer, size_t size) = 0; 57 virtual size_t read(void* buffer, size_t size) = 0;
58 58
59 /** Skip size number of bytes. 59 /** Skip size number of bytes.
60 * @return the actual number bytes that could be skipped. 60 * @return the actual number bytes that could be skipped.
61 */ 61 */
62 size_t skip(size_t size) { 62 size_t skip(size_t size) {
63 return this->read(NULL, size); 63 return this->read(NULL, size);
64 } 64 }
65 65
66 /**
67 * Attempt to peek at size bytes.
68 * If this stream supports peeking, copy up to size bytes into buffer. If
69 * less than size is returned, the stream is at the end or the stream has
70 * reached its limit for how many bytes it can peek. Zero is returned on
71 * error.
72 * After this call, the stream will have the same state it did beforehand,
73 * unless there was an error.
74 * If peeking is unsupported, return 0.
75 * @param buffer Must not be NULL. Destination to copy bytes.
76 * @param size Number of bytes to copy.
77 * @return the number of bytes actually read.
78 */
79 virtual size_t peek(void* buffer, size_t size) { return 0; }
bungeman-skia 2015/03/30 19:09:00 Since SkStreamSeekable must support this (slightly
scroggo 2015/03/30 19:31:49 FWIW, an SkStreamSeekable supports it incidentally
djsollen 2015/03/30 19:56:53 I think it is important to disambiguate between th
80
66 /** Returns true when all the bytes in the stream have been read. 81 /** Returns true when all the bytes in the stream have been read.
67 * This may return true early (when there are no more bytes to be read) 82 * This may return true early (when there are no more bytes to be read)
68 * or late (after the first unsuccessful read). 83 * or late (after the first unsuccessful read).
69 */ 84 */
70 virtual bool isAtEnd() const = 0; 85 virtual bool isAtEnd() const = 0;
71 86
72 int8_t readS8(); 87 int8_t readS8();
73 int16_t readS16(); 88 int16_t readS16();
74 int32_t readS32(); 89 int32_t readS32();
75 90
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 /** SkStreamSeekable is a SkStreamRewindable for which position, seek, move, and fork are required. */ 152 /** SkStreamSeekable is a SkStreamRewindable for which position, seek, move, and fork are required. */
138 class SK_API SkStreamSeekable : public SkStreamRewindable { 153 class SK_API SkStreamSeekable : public SkStreamRewindable {
139 public: 154 public:
140 SkStreamSeekable* duplicate() const override = 0; 155 SkStreamSeekable* duplicate() const override = 0;
141 156
142 bool hasPosition() const override { return true; } 157 bool hasPosition() const override { return true; }
143 size_t getPosition() const override = 0; 158 size_t getPosition() const override = 0;
144 bool seek(size_t position) override = 0; 159 bool seek(size_t position) override = 0;
145 bool move(long offset) override = 0; 160 bool move(long offset) override = 0;
146 SkStreamSeekable* fork() const override = 0; 161 SkStreamSeekable* fork() const override = 0;
162 // Default implementation reads and then resets the position.
163 size_t peek(void* buffer, size_t size) override {
164 SkASSERT(buffer != NULL);
165 const size_t position = this->getPosition();
166 const size_t bytesRead = this->read(buffer, size);
167 if (!this->seek(position)) {
168 return 0;
169 }
170 return bytesRead;
171 }
147 }; 172 };
148 173
149 /** SkStreamAsset is a SkStreamSeekable for which getLength is required. */ 174 /** SkStreamAsset is a SkStreamSeekable for which getLength is required. */
150 class SK_API SkStreamAsset : public SkStreamSeekable { 175 class SK_API SkStreamAsset : public SkStreamSeekable {
151 public: 176 public:
152 SkStreamAsset* duplicate() const override = 0; 177 SkStreamAsset* duplicate() const override = 0;
153 SkStreamAsset* fork() const override = 0; 178 SkStreamAsset* fork() const override = 0;
154 179
155 bool hasLength() const override { return true; } 180 bool hasLength() const override { return true; }
156 size_t getLength() const override = 0; 181 size_t getLength() const override = 0;
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 462
438 private: 463 private:
439 size_t fBytesWritten; 464 size_t fBytesWritten;
440 typedef SkWStream INHERITED; 465 typedef SkWStream INHERITED;
441 }; 466 };
442 467
443 // for now 468 // for now
444 typedef SkFILEStream SkURLStream; 469 typedef SkFILEStream SkURLStream;
445 470
446 #endif 471 #endif
OLDNEW
« no previous file with comments | « no previous file | src/utils/SkFrontBufferedStream.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698