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

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

Issue 849103004: Make SkStream *not* ref counted. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Treat SkFontMgr::createFromStream as taking ownership of the stream (is this correct?) 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
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
11 #include "SkInstCnt.h"
11 #include "SkRefCnt.h" 12 #include "SkRefCnt.h"
12 #include "SkScalar.h" 13 #include "SkScalar.h"
13 14
14 class SkData; 15 class SkData;
15 16
16 class SkStream; 17 class SkStream;
17 class SkStreamRewindable; 18 class SkStreamRewindable;
18 class SkStreamSeekable; 19 class SkStreamSeekable;
19 class SkStreamAsset; 20 class SkStreamAsset;
20 class SkStreamMemory; 21 class SkStreamMemory;
21 22
22 /** 23 /**
23 * SkStream -- abstraction for a source of bytes. Subclasses can be backed by 24 * SkStream -- abstraction for a source of bytes. Subclasses can be backed by
24 * memory, or a file, or something else. 25 * memory, or a file, or something else.
25 * 26 *
26 * NOTE: 27 * NOTE:
27 * 28 *
28 * Classic "streams" APIs are sort of async, in that on a request for N 29 * Classic "streams" APIs are sort of async, in that on a request for N
29 * bytes, they may return fewer than N bytes on a given call, in which case 30 * 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) 31 * the caller can "try again" to get more bytes, eventually (modulo an error)
31 * receiving their total N bytes. 32 * receiving their total N bytes.
32 * 33 *
33 * Skia streams behave differently. They are effectively synchronous, and will 34 * 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 35 * 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 36 * (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 37 * no more data (at EOF or hit an error). The caller should *not* call again
37 * in hopes of fulfilling more of the request. 38 * in hopes of fulfilling more of the request.
38 */ 39 */
39 class SK_API SkStream : public SkRefCnt { //TODO: remove SkRefCnt 40 class SK_API SkStream : public SkNoncopyable {
40 public: 41 public:
42 virtual ~SkStream() {}
41 /** 43 /**
42 * Attempts to open the specified file, and return a stream to it (using 44 * 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 45 * mmap if available). On success, the caller is responsible for deleting.
44 * returned object. On failure, returns NULL. 46 * On failure, returns NULL.
45 */ 47 */
46 static SkStreamAsset* NewFromFile(const char path[]); 48 static SkStreamAsset* NewFromFile(const char path[]);
47 49
48 SK_DECLARE_INST_COUNT(SkStream) 50 SK_DECLARE_INST_COUNT(SkStream)
bungeman-skia 2015/01/15 22:44:55 The entire point of this is to instance count ref
scroggo 2015/01/16 19:13:37 Oh, right, of course.
49 51
50 /** Reads or skips size number of bytes. 52 /** Reads or skips size number of bytes.
51 * If buffer == NULL, skip size bytes, return how many were skipped. 53 * 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. 54 * 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 55 * @param buffer when NULL skip size bytes, otherwise copy size bytes into buffer
54 * @param size the number of bytes to skip or copy 56 * @param size the number of bytes to skip or copy
55 * @return the number of bytes actually read. 57 * @return the number of bytes actually read.
56 */ 58 */
57 virtual size_t read(void* buffer, size_t size) = 0; 59 virtual size_t read(void* buffer, size_t size) = 0;
58 60
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 //SkStreamAsset 120 //SkStreamAsset
119 /** Returns true if this stream can report it's total length. */ 121 /** Returns true if this stream can report it's total length. */
120 virtual bool hasLength() const { return false; } 122 virtual bool hasLength() const { return false; }
121 /** Returns the total length of the stream. If this cannot be done, returns 0. */ 123 /** Returns the total length of the stream. If this cannot be done, returns 0. */
122 virtual size_t getLength() const { return 0; } 124 virtual size_t getLength() const { return 0; }
123 125
124 //SkStreamMemory 126 //SkStreamMemory
125 /** Returns the starting address for the data. If this cannot be done, retur ns NULL. */ 127 /** Returns the starting address for the data. If this cannot be done, retur ns NULL. */
126 //TODO: replace with virtual const SkData* getData() 128 //TODO: replace with virtual const SkData* getData()
127 virtual const void* getMemoryBase() { return NULL; } 129 virtual const void* getMemoryBase() { return NULL; }
128
129 private:
130 typedef SkRefCnt INHERITED;
131 }; 130 };
132 131
133 /** SkStreamRewindable is a SkStream for which rewind and duplicate are required . */ 132 /** SkStreamRewindable is a SkStream for which rewind and duplicate are required . */
134 class SK_API SkStreamRewindable : public SkStream { 133 class SK_API SkStreamRewindable : public SkStream {
135 public: 134 public:
136 bool rewind() SK_OVERRIDE = 0; 135 bool rewind() SK_OVERRIDE = 0;
137 SkStreamRewindable* duplicate() const SK_OVERRIDE = 0; 136 SkStreamRewindable* duplicate() const SK_OVERRIDE = 0;
138 }; 137 };
139 138
140 /** SkStreamSeekable is a SkStreamRewindable for which position, seek, move, and fork are required. */ 139 /** 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
440 439
441 private: 440 private:
442 size_t fBytesWritten; 441 size_t fBytesWritten;
443 typedef SkWStream INHERITED; 442 typedef SkWStream INHERITED;
444 }; 443 };
445 444
446 // for now 445 // for now
447 typedef SkFILEStream SkURLStream; 446 typedef SkFILEStream SkURLStream;
448 447
449 #endif 448 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698