OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 #ifndef SkRWBuffer_DEFINED | 8 #ifndef SkRWBuffer_DEFINED |
9 #define SkRWBuffer_DEFINED | 9 #define SkRWBuffer_DEFINED |
10 | 10 |
11 #include "SkRefCnt.h" | 11 #include "SkRefCnt.h" |
12 | 12 |
13 struct SkBufferBlock; | 13 struct SkBufferBlock; |
14 struct SkBufferHead; | 14 struct SkBufferHead; |
15 class SkRWBuffer; | 15 class SkRWBuffer; |
16 class SkStreamAsset; | 16 class SkStreamAsset; |
17 | 17 |
18 /** | 18 /** |
19 * Contains a read-only, thread-sharable block of memory. To access the memory,
the caller must | 19 * Contains a read-only, thread-sharable block of memory. To access the memory,
the caller must |
20 * instantiate a local iterator, as the memory is stored in 1 or more contiguou
s blocks. | 20 * instantiate a local iterator, as the memory is stored in 1 or more contiguou
s blocks. |
21 */ | 21 */ |
22 class SK_API SkROBuffer : public SkRefCnt { | 22 class SK_API SkROBuffer : public SkRefCnt { |
23 public: | 23 public: |
24 /** | 24 /** |
25 * Return the logical length of the data owned/shared by this buffer. It ma
y be stored in | 25 * Return the logical length of the data owned/shared by this buffer. It ma
y be stored in |
26 * multiple contiguous blocks, accessible via the iterator. | 26 * multiple contiguous blocks, accessible via the iterator. |
27 */ | 27 */ |
28 size_t size() const { return fUsed; } | 28 size_t size() const { return fAvailable; } |
29 | 29 |
30 class SK_API Iter { | 30 class SK_API Iter { |
31 public: | 31 public: |
32 Iter(const SkROBuffer*); | 32 Iter(const SkROBuffer*); |
33 | 33 |
34 void reset(const SkROBuffer*); | 34 void reset(const SkROBuffer*); |
35 | 35 |
36 /** | 36 /** |
37 * Return the current continuous block of memory, or nullptr if the ite
rator is exhausted | 37 * Return the current continuous block of memory, or nullptr if the ite
rator is exhausted |
38 */ | 38 */ |
(...skipping 10 matching lines...) Expand all Loading... |
49 * block, or false if the iterator is exhausted. | 49 * block, or false if the iterator is exhausted. |
50 */ | 50 */ |
51 bool next(); | 51 bool next(); |
52 | 52 |
53 private: | 53 private: |
54 const SkBufferBlock* fBlock; | 54 const SkBufferBlock* fBlock; |
55 size_t fRemaining; | 55 size_t fRemaining; |
56 }; | 56 }; |
57 | 57 |
58 private: | 58 private: |
59 SkROBuffer(const SkBufferHead* head, size_t used); | 59 SkROBuffer(const SkBufferHead* head, size_t available); |
60 virtual ~SkROBuffer(); | 60 virtual ~SkROBuffer(); |
61 | 61 |
62 const SkBufferHead* fHead; | 62 const SkBufferHead* fHead; |
63 const size_t fUsed; | 63 const size_t fAvailable; |
64 | 64 |
65 friend class SkRWBuffer; | 65 friend class SkRWBuffer; |
66 }; | 66 }; |
67 | 67 |
68 /** | 68 /** |
69 * Accumulates bytes of memory that are "appended" to it, growing internal stor
age as needed. | 69 * Accumulates bytes of memory that are "appended" to it, growing internal stor
age as needed. |
70 * The growth is done such that at any time, a RBuffer or StreamAsset can be sn
apped off, which | 70 * The growth is done such that at any time, a RBuffer or StreamAsset can be sn
apped off, which |
71 * can see the previously stored bytes, but which will be unaware of any future
writes. | 71 * can see the previously stored bytes, but which will be unaware of any future
writes. |
72 */ | 72 */ |
73 class SK_API SkRWBuffer { | 73 class SK_API SkRWBuffer { |
74 public: | 74 public: |
75 SkRWBuffer(size_t initialCapacity = 0); | 75 SkRWBuffer(size_t initialCapacity = 0); |
76 ~SkRWBuffer(); | 76 ~SkRWBuffer(); |
77 | 77 |
78 size_t size() const { return fTotalUsed; } | 78 size_t size() const { return fTotalUsed; } |
79 void append(const void* buffer, size_t length); | 79 void append(const void* buffer, size_t length); |
80 void* append(size_t length); | |
81 | 80 |
82 SkROBuffer* newRBufferSnapshot() const; | 81 SkROBuffer* newRBufferSnapshot() const; |
83 SkStreamAsset* newStreamSnapshot() const; | 82 SkStreamAsset* newStreamSnapshot() const; |
84 | 83 |
85 #ifdef SK_DEBUG | 84 #ifdef SK_DEBUG |
86 void validate() const; | 85 void validate() const; |
87 #else | 86 #else |
88 void validate() const {} | 87 void validate() const {} |
89 #endif | 88 #endif |
90 | 89 |
91 private: | 90 private: |
92 SkBufferHead* fHead; | 91 SkBufferHead* fHead; |
93 SkBufferBlock* fTail; | 92 SkBufferBlock* fTail; |
94 size_t fTotalUsed; | 93 size_t fTotalUsed; |
95 }; | 94 }; |
96 | 95 |
97 #endif | 96 #endif |
OLD | NEW |