OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2015 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #ifndef SkRWBuffer_DEFINED | |
9 #define SkRWBuffer_DEFINED | |
10 | |
11 #include "SkRefCnt.h" | |
12 | |
13 struct SkBufferBlock; | |
14 struct SkBufferHead; | |
15 class SkData; | |
16 class SkRWBuffer; | |
17 class SkStreamAsset; | |
18 | |
19 /** | |
20 * Contains a read-only, thread-sharable block of memory. To access the memory, the caller must | |
21 * instantiate a local iterator, as the memory is stored in 1 or more contiguou s blocks. | |
22 */ | |
23 class SkRBuffer : public SkRefCnt { | |
24 public: | |
25 /** | |
26 * Return the logical length of the data owned/shared by this buffer. It ma y be stored in | |
27 * multiple contiguous blocks, accessible via the iterator. | |
28 */ | |
29 size_t size() const { return fUsed; } | |
30 | |
31 class Iter { | |
32 public: | |
33 Iter(const SkRBuffer*); | |
34 | |
35 void reset(const SkRBuffer*); | |
36 | |
37 /** | |
38 * Return the current continuous block of memory, or NULL if the iterat or is exhausted | |
39 */ | |
40 const void* data() const; | |
41 | |
42 /** | |
43 * Returns the number of bytes in the current continguous block of memo ry, or 0 if the | |
44 * iterator is exhausted. | |
45 */ | |
46 size_t size() const; | |
47 | |
48 /** | |
49 * Advance to the next contiguous block of memory, returning true if th ere is another | |
50 * block, or false if the iterator is exhausted. | |
51 */ | |
52 bool next(); | |
53 | |
54 private: | |
55 const SkBufferBlock* fBlock; | |
56 size_t fRemaining; | |
57 }; | |
58 | |
59 private: | |
60 SkRBuffer(const SkBufferHead* head, size_t used); | |
61 virtual ~SkRBuffer(); | |
62 | |
63 const SkBufferHead* fHead; | |
64 const size_t fUsed; | |
65 | |
66 friend class SkRWBuffer; | |
67 }; | |
68 | |
69 /** | |
70 * Accumulates bytes of memory that are "appended" to it, growing internal stor age as needed. | |
71 * The growth is done such that at any time, a RBuffer or StreamAsset can be sn apped off, which | |
72 * can see the previously stored bytes, but which will be unaware of any future writes. | |
73 */ | |
74 class SkRWBuffer { | |
75 public: | |
76 SkRWBuffer(size_t initialCapacity = 0); | |
77 ~SkRWBuffer(); | |
78 | |
79 size_t size() const { return fTotalUsed; } | |
80 void append(const void* buffer, size_t length); | |
81 | |
82 SkData* newDataSnapshot() const; | |
bungeman-skia
2015/04/27 14:52:42
I would be very, very careful about adding this, a
reed2
2015/04/28 02:25:00
will remove for now
| |
83 SkRBuffer* newRBufferSnapshot() const; | |
84 SkStreamAsset* newStreamSnapshot() const; | |
85 | |
86 #ifdef SK_DEBUG | |
87 void validate() const; | |
88 #else | |
89 void validate() const {} | |
90 #endif | |
91 | |
92 private: | |
93 SkBufferHead* fHead; | |
94 SkBufferBlock* fTail; | |
95 size_t fTotalUsed; | |
96 }; | |
97 | |
98 #endif | |
OLD | NEW |