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 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 fUsed; } |
29 | 29 |
30 class Iter { | 30 class Iter { |
31 public: | 31 public: |
32 Iter(const SkROBuffer*); | 32 Iter(const SkROBuffer*); |
(...skipping 30 matching lines...) Expand all Loading... |
63 const size_t fUsed; | 63 const size_t fUsed; |
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 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); | 80 void* append(size_t length); |
81 | 81 |
82 SkROBuffer* newRBufferSnapshot() const; | 82 SkROBuffer* newRBufferSnapshot() const; |
83 SkStreamAsset* newStreamSnapshot() const; | 83 SkStreamAsset* newStreamSnapshot() const; |
84 | 84 |
85 #ifdef SK_DEBUG | 85 #ifdef SK_DEBUG |
86 void validate() const; | 86 void validate() const; |
87 #else | 87 #else |
88 void validate() const {} | 88 void validate() const {} |
89 #endif | 89 #endif |
90 | 90 |
91 private: | 91 private: |
92 SkBufferHead* fHead; | 92 SkBufferHead* fHead; |
93 SkBufferBlock* fTail; | 93 SkBufferBlock* fTail; |
94 size_t fTotalUsed; | 94 size_t fTotalUsed; |
95 }; | 95 }; |
96 | 96 |
97 #endif | 97 #endif |
OLD | NEW |