| OLD | NEW |
| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 * @param buffer when NULL skip size bytes, otherwise copy size bytes into
buffer | 53 * @param buffer when NULL skip size bytes, otherwise copy size bytes into
buffer |
| 54 * @param size the number of bytes to skip or copy | 54 * @param size the number of bytes to skip or copy |
| 55 * @return the number of bytes actually read. | 55 * @return the number of bytes actually read. |
| 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 //TODO: remove this old logic after updating existing implementations | |
| 65 return 0 == size ? 0 : this->read(NULL, size); | |
| 66 } | 64 } |
| 67 | 65 |
| 68 /** Returns true when all the bytes in the stream have been read. | 66 /** Returns true when all the bytes in the stream have been read. |
| 69 * This may return true early (when there are no more bytes to be read) | 67 * This may return true early (when there are no more bytes to be read) |
| 70 * or late (after the first unsuccessful read). | 68 * or late (after the first unsuccessful read). |
| 71 * | |
| 72 * In Progress: do not use until all implementations are updated. | |
| 73 * TODO: after this is implemented everywhere, make pure virtual. | |
| 74 */ | 69 */ |
| 75 virtual bool isAtEnd() const { | 70 virtual bool isAtEnd() const = 0; |
| 76 SkASSERT(false); | |
| 77 return true; | |
| 78 } | |
| 79 | 71 |
| 80 int8_t readS8(); | 72 int8_t readS8(); |
| 81 int16_t readS16(); | 73 int16_t readS16(); |
| 82 int32_t readS32(); | 74 int32_t readS32(); |
| 83 | 75 |
| 84 uint8_t readU8() { return (uint8_t)this->readS8(); } | 76 uint8_t readU8() { return (uint8_t)this->readS8(); } |
| 85 uint16_t readU16() { return (uint16_t)this->readS16(); } | 77 uint16_t readU16() { return (uint16_t)this->readS16(); } |
| 86 uint32_t readU32() { return (uint32_t)this->readS32(); } | 78 uint32_t readU32() { return (uint32_t)this->readS32(); } |
| 87 | 79 |
| 88 bool readBool() { return this->readU8() != 0; } | 80 bool readBool() { return this->readU8() != 0; } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 | 118 |
| 127 /** Duplicates this stream. If this cannot be done, returns NULL. | 119 /** Duplicates this stream. If this cannot be done, returns NULL. |
| 128 * The returned stream will be positioned the same as this stream. | 120 * The returned stream will be positioned the same as this stream. |
| 129 */ | 121 */ |
| 130 virtual SkStreamSeekable* fork() const { return NULL; } | 122 virtual SkStreamSeekable* fork() const { return NULL; } |
| 131 | 123 |
| 132 //SkStreamAsset | 124 //SkStreamAsset |
| 133 /** Returns true if this stream can report it's total length. */ | 125 /** Returns true if this stream can report it's total length. */ |
| 134 virtual bool hasLength() const { return false; } | 126 virtual bool hasLength() const { return false; } |
| 135 /** Returns the total length of the stream. If this cannot be done, returns
0. */ | 127 /** Returns the total length of the stream. If this cannot be done, returns
0. */ |
| 136 virtual size_t getLength() const { | 128 virtual size_t getLength() const { return 0; } |
| 137 //return 0; | |
| 138 //TODO: remove the following after everyone is updated. | |
| 139 return ((SkStream*)this)->read(NULL, 0); | |
| 140 } | |
| 141 | 129 |
| 142 //SkStreamMemory | 130 //SkStreamMemory |
| 143 /** Returns the starting address for the data. If this cannot be done, retur
ns NULL. */ | 131 /** Returns the starting address for the data. If this cannot be done, retur
ns NULL. */ |
| 144 //TODO: replace with virtual const SkData* getData() | 132 //TODO: replace with virtual const SkData* getData() |
| 145 virtual const void* getMemoryBase() { return NULL; } | 133 virtual const void* getMemoryBase() { return NULL; } |
| 146 | 134 |
| 147 private: | 135 private: |
| 148 typedef SkRefCnt INHERITED; | 136 typedef SkRefCnt INHERITED; |
| 149 }; | 137 }; |
| 150 | 138 |
| 151 /** SkStreamRewindable is a SkStream for which rewind and duplicate are required
. */ | 139 /** SkStreamRewindable is a SkStream for which rewind and duplicate are required
. */ |
| 152 class SK_API SkStreamRewindable : public SkStream { | 140 class SK_API SkStreamRewindable : public SkStream { |
| 153 public: | 141 public: |
| 154 //TODO: remove the following after everyone is updated (ensures new behavior
on new classes). | |
| 155 virtual bool isAtEnd() const SK_OVERRIDE = 0; | |
| 156 //TODO: remove the following after everyone is updated (ensures new behavior
on new classes). | |
| 157 virtual size_t getLength() const SK_OVERRIDE { return 0; } | |
| 158 | |
| 159 virtual bool rewind() SK_OVERRIDE = 0; | 142 virtual bool rewind() SK_OVERRIDE = 0; |
| 160 virtual SkStreamRewindable* duplicate() const SK_OVERRIDE = 0; | 143 virtual SkStreamRewindable* duplicate() const SK_OVERRIDE = 0; |
| 161 }; | 144 }; |
| 162 | 145 |
| 163 /** SkStreamSeekable is a SkStreamRewindable for which position, seek, move, and
fork are required. */ | 146 /** SkStreamSeekable is a SkStreamRewindable for which position, seek, move, and
fork are required. */ |
| 164 class SK_API SkStreamSeekable : public SkStreamRewindable { | 147 class SK_API SkStreamSeekable : public SkStreamRewindable { |
| 165 public: | 148 public: |
| 166 virtual SkStreamSeekable* duplicate() const SK_OVERRIDE = 0; | 149 virtual SkStreamSeekable* duplicate() const SK_OVERRIDE = 0; |
| 167 | 150 |
| 168 virtual bool hasPosition() const SK_OVERRIDE { return true; } | 151 virtual bool hasPosition() const SK_OVERRIDE { return true; } |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 virtual void newline() SK_OVERRIDE; | 444 virtual void newline() SK_OVERRIDE; |
| 462 | 445 |
| 463 private: | 446 private: |
| 464 typedef SkWStream INHERITED; | 447 typedef SkWStream INHERITED; |
| 465 }; | 448 }; |
| 466 | 449 |
| 467 // for now | 450 // for now |
| 468 typedef SkFILEStream SkURLStream; | 451 typedef SkFILEStream SkURLStream; |
| 469 | 452 |
| 470 #endif | 453 #endif |
| OLD | NEW |