| 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 18 matching lines...) Expand all Loading... |
| 29 * bytes, they may return fewer than N bytes on a given call, in which case | 29 * bytes, they may return fewer than N bytes on a given call, in which case |
| 30 * the caller can "try again" to get more bytes, eventually (modulo an error) | 30 * the caller can "try again" to get more bytes, eventually (modulo an error) |
| 31 * receiving their total N bytes. | 31 * receiving their total N bytes. |
| 32 * | 32 * |
| 33 * Skia streams behave differently. They are effectively synchronous, and will | 33 * Skia streams behave differently. They are effectively synchronous, and will |
| 34 * always return all N bytes of the request if possible. If they return fewer | 34 * always return all N bytes of the request if possible. If they return fewer |
| 35 * (the read() call returns the number of bytes read) then that means there is | 35 * (the read() call returns the number of bytes read) then that means there is |
| 36 * no more data (at EOF or hit an error). The caller should *not* call again | 36 * no more data (at EOF or hit an error). The caller should *not* call again |
| 37 * in hopes of fulfilling more of the request. | 37 * in hopes of fulfilling more of the request. |
| 38 */ | 38 */ |
| 39 class SK_API SkStream : public SkRefCnt { //TODO: remove SkRefCnt | 39 class SK_API SkStream : public SkNoncopyable { |
| 40 public: | 40 public: |
| 41 virtual ~SkStream() {} |
| 42 |
| 43 /** |
| 44 * @deprecated |
| 45 * SkStream is no longer ref counted, but we leave this here for staging. |
| 46 */ |
| 47 void unref() { |
| 48 SkDebugf("SkStream is no longer ref counted!"); |
| 49 } |
| 50 |
| 41 /** | 51 /** |
| 42 * Attempts to open the specified file, and return a stream to it (using | 52 * Attempts to open the specified file, and return a stream to it (using |
| 43 * mmap if available). On success, the caller must call unref() on the | 53 * mmap if available). On success, the caller is responsible for deleting. |
| 44 * returned object. On failure, returns NULL. | 54 * On failure, returns NULL. |
| 45 */ | 55 */ |
| 46 static SkStreamAsset* NewFromFile(const char path[]); | 56 static SkStreamAsset* NewFromFile(const char path[]); |
| 47 | 57 |
| 48 SK_DECLARE_INST_COUNT(SkStream) | |
| 49 | |
| 50 /** Reads or skips size number of bytes. | 58 /** Reads or skips size number of bytes. |
| 51 * If buffer == NULL, skip size bytes, return how many were skipped. | 59 * If buffer == NULL, skip size bytes, return how many were skipped. |
| 52 * If buffer != NULL, copy size bytes into buffer, return how many were cop
ied. | 60 * If buffer != NULL, copy size bytes into buffer, return how many were cop
ied. |
| 53 * @param buffer when NULL skip size bytes, otherwise copy size bytes into
buffer | 61 * @param buffer when NULL skip size bytes, otherwise copy size bytes into
buffer |
| 54 * @param size the number of bytes to skip or copy | 62 * @param size the number of bytes to skip or copy |
| 55 * @return the number of bytes actually read. | 63 * @return the number of bytes actually read. |
| 56 */ | 64 */ |
| 57 virtual size_t read(void* buffer, size_t size) = 0; | 65 virtual size_t read(void* buffer, size_t size) = 0; |
| 58 | 66 |
| 59 /** Skip size number of bytes. | 67 /** Skip size number of bytes. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 //SkStreamAsset | 126 //SkStreamAsset |
| 119 /** Returns true if this stream can report it's total length. */ | 127 /** Returns true if this stream can report it's total length. */ |
| 120 virtual bool hasLength() const { return false; } | 128 virtual bool hasLength() const { return false; } |
| 121 /** Returns the total length of the stream. If this cannot be done, returns
0. */ | 129 /** Returns the total length of the stream. If this cannot be done, returns
0. */ |
| 122 virtual size_t getLength() const { return 0; } | 130 virtual size_t getLength() const { return 0; } |
| 123 | 131 |
| 124 //SkStreamMemory | 132 //SkStreamMemory |
| 125 /** Returns the starting address for the data. If this cannot be done, retur
ns NULL. */ | 133 /** Returns the starting address for the data. If this cannot be done, retur
ns NULL. */ |
| 126 //TODO: replace with virtual const SkData* getData() | 134 //TODO: replace with virtual const SkData* getData() |
| 127 virtual const void* getMemoryBase() { return NULL; } | 135 virtual const void* getMemoryBase() { return NULL; } |
| 128 | |
| 129 private: | |
| 130 typedef SkRefCnt INHERITED; | |
| 131 }; | 136 }; |
| 132 | 137 |
| 133 /** SkStreamRewindable is a SkStream for which rewind and duplicate are required
. */ | 138 /** SkStreamRewindable is a SkStream for which rewind and duplicate are required
. */ |
| 134 class SK_API SkStreamRewindable : public SkStream { | 139 class SK_API SkStreamRewindable : public SkStream { |
| 135 public: | 140 public: |
| 136 bool rewind() SK_OVERRIDE = 0; | 141 bool rewind() SK_OVERRIDE = 0; |
| 137 SkStreamRewindable* duplicate() const SK_OVERRIDE = 0; | 142 SkStreamRewindable* duplicate() const SK_OVERRIDE = 0; |
| 138 }; | 143 }; |
| 139 | 144 |
| 140 /** SkStreamSeekable is a SkStreamRewindable for which position, seek, move, and
fork are required. */ | 145 /** SkStreamSeekable is a SkStreamRewindable for which position, seek, move, and
fork are required. */ |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 | 445 |
| 441 private: | 446 private: |
| 442 size_t fBytesWritten; | 447 size_t fBytesWritten; |
| 443 typedef SkWStream INHERITED; | 448 typedef SkWStream INHERITED; |
| 444 }; | 449 }; |
| 445 | 450 |
| 446 // for now | 451 // for now |
| 447 typedef SkFILEStream SkURLStream; | 452 typedef SkFILEStream SkURLStream; |
| 448 | 453 |
| 449 #endif | 454 #endif |
| OLD | NEW |