Merge from google/chrome/m55
[platform/upstream/libSkiaSharp.git] / src / c / sk_stream.cpp
1 /*
2  * Copyright 2016 Xamarin 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 #include "SkStream.h"
9
10 #include "sk_stream.h"
11
12 #include "sk_types_priv.h"
13
14 void sk_stream_asset_destroy(sk_stream_asset_t* cstream)
15 {
16     delete AsStreamAsset(cstream);
17 }
18
19 void sk_filestream_destroy(sk_stream_filestream_t* cstream)
20 {
21     delete AsFileStream(cstream);
22 }
23
24 void sk_memorystream_destroy(sk_stream_memorystream_t* cstream)
25 {
26     delete AsMemoryStream(cstream);
27 }
28
29 sk_stream_filestream_t* sk_filestream_new (const char* path)
30 {
31     return ToFileStream(new SkFILEStream(path));
32 }
33
34 sk_stream_memorystream_t* sk_memorystream_new ()
35 {
36     return ToMemoryStream(new SkMemoryStream());
37 }
38 sk_stream_memorystream_t* sk_memorystream_new_with_length (size_t length)
39 {
40     return ToMemoryStream(new SkMemoryStream(length));
41 }
42 sk_stream_memorystream_t* sk_memorystream_new_with_data (const void* data, size_t length, bool copyData)
43 {
44     return ToMemoryStream(new SkMemoryStream(data, length, copyData));
45 }
46 sk_stream_memorystream_t* sk_memorystream_new_with_skdata (sk_data_t* data)
47 {
48     return ToMemoryStream(new SkMemoryStream(AsData(data)));
49 }
50 void sk_memorystream_set_memory (sk_stream_memorystream_t* cmemorystream, const void* data, size_t length, bool copyData)
51 {
52     AsMemoryStream(cmemorystream)->setMemory(data, length, copyData);
53 }
54
55 size_t sk_stream_read (sk_stream_t* cstream, void* buffer, size_t size)
56 {
57     return AsStream(cstream)->read(buffer, size);
58 }
59
60 size_t sk_stream_skip (sk_stream_t* cstream, size_t size)
61 {
62     return AsStream(cstream)->skip(size);
63 }
64
65 bool sk_stream_is_at_end (sk_stream_t* cstream)
66 {
67     return AsStream(cstream)->isAtEnd();
68 }
69 int8_t sk_stream_read_s8 (sk_stream_t* cstream)
70 {
71     return AsStream(cstream)->readS8();
72 }
73 int16_t sk_stream_read_s16 (sk_stream_t* cstream)
74 {
75     return AsStream(cstream)->readS16();
76 }
77 int32_t sk_stream_read_s32 (sk_stream_t* cstream)
78 {
79     return AsStream(cstream)->readS32();
80 }
81 uint8_t sk_stream_read_u8 (sk_stream_t* cstream)
82 {
83     return AsStream(cstream)->readU8();
84 }
85 uint16_t sk_stream_read_u16 (sk_stream_t* cstream)
86 {
87     return AsStream(cstream)->readU16();
88 }
89 uint32_t sk_stream_read_u32 (sk_stream_t* cstream)
90 {
91     return AsStream(cstream)->readU32();
92 }
93 bool sk_stream_read_bool (sk_stream_t* cstream)
94 {
95     return AsStream(cstream)->readBool();
96 }
97
98 bool sk_stream_rewind (sk_stream_t* cstream)
99 {
100     return AsStream(cstream)->rewind();
101 }
102
103 bool sk_stream_has_position (sk_stream_t* cstream)
104 {
105     return AsStream(cstream)->hasPosition();
106 }
107
108 size_t sk_stream_get_position (sk_stream_t* cstream)
109 {
110     return AsStream(cstream)->getPosition();
111 }
112
113 bool sk_stream_seek (sk_stream_t* cstream, size_t position)
114 {
115     return AsStream(cstream)->seek(position);
116 }
117
118 bool sk_stream_move (sk_stream_t* cstream, long offset)
119 {
120     return AsStream(cstream)->move(offset);
121 }
122
123 bool sk_stream_has_length (sk_stream_t* cstream)
124 {
125     return AsStream(cstream)->hasLength();
126 }
127
128 size_t sk_stream_get_length (sk_stream_t* cstream)
129 {
130     return AsStream(cstream)->getLength();
131 }
132
133 void sk_filewstream_destroy(sk_wstream_filestream_t* cstream)
134 {
135     delete AsFileWStream(cstream);
136 }
137
138 void sk_dynamicmemorywstream_destroy(sk_wstream_dynamicmemorystream_t* cstream)
139 {
140     delete AsDynamicMemoryWStream(cstream);
141 }
142
143 sk_wstream_filestream_t* sk_filewstream_new(const char* path)
144 {
145     return ToFileWStream(new SkFILEWStream(path));
146 }
147
148 sk_wstream_dynamicmemorystream_t* sk_dynamicmemorywstream_new()
149 {
150     return ToDynamicMemoryWStream(new SkDynamicMemoryWStream());
151 }
152
153 sk_data_t* sk_dynamicmemorywstream_copy_to_data(sk_wstream_dynamicmemorystream_t* cstream)
154 {
155     return ToData(AsDynamicMemoryWStream(cstream)->copyToData());
156 }
157
158 sk_stream_asset_t* sk_dynamicmemorywstream_detach_as_stream(sk_wstream_dynamicmemorystream_t* cstream)
159 {
160     return ToStreamAsset(AsDynamicMemoryWStream(cstream)->detachAsStream());
161 }
162
163 bool sk_wstream_write(sk_wstream_t* cstream, const void* buffer, size_t size)
164 {
165     return AsWStream(cstream)->write(buffer, size);
166 }
167
168 void sk_wstream_newline(sk_wstream_t* cstream)
169 {
170     return AsWStream(cstream)->newline();
171 }
172
173 void sk_wstream_flush(sk_wstream_t* cstream)
174 {
175     return AsWStream(cstream)->flush();
176 }
177
178 size_t sk_wstream_bytes_written(sk_wstream_t* cstream)
179 {
180     return AsWStream(cstream)->bytesWritten();
181 }
182
183 bool sk_wstream_write_8(sk_wstream_t* cstream, uint8_t value)
184 {
185     return AsWStream(cstream)->write8(value);
186 }
187
188 bool sk_wstream_write_16(sk_wstream_t* cstream, uint16_t value)
189 {
190     return AsWStream(cstream)->write16(value);
191 }
192
193 bool sk_wstream_write_32(sk_wstream_t* cstream, uint32_t value)
194 {
195     return AsWStream(cstream)->write32(value);
196 }
197
198 bool sk_wstream_write_text(sk_wstream_t* cstream, const char* value)
199 {
200     return AsWStream(cstream)->writeText(value);
201 }
202
203 bool sk_wstream_write_dec_as_text(sk_wstream_t* cstream, int32_t value)
204 {
205     return AsWStream(cstream)->writeDecAsText(value);
206 }
207
208 bool sk_wstream_write_bigdec_as_text(sk_wstream_t* cstream, int64_t value, int minDigits)
209 {
210     return AsWStream(cstream)->writeBigDecAsText(value, minDigits);
211 }
212
213 bool sk_wstream_write_hex_as_text(sk_wstream_t* cstream, uint32_t value, int minDigits)
214 {
215     return AsWStream(cstream)->writeHexAsText(value, minDigits);
216 }
217
218 bool sk_wstream_write_scalar_as_text(sk_wstream_t* cstream, float value)
219 {
220     return AsWStream(cstream)->writeScalarAsText(value);
221 }
222
223 bool sk_wstream_write_bool(sk_wstream_t* cstream, bool value)
224 {
225     return AsWStream(cstream)->writeBool(value);
226 }
227
228 bool sk_wstream_write_scalar(sk_wstream_t* cstream, float value)
229 {
230     return AsWStream(cstream)->writeScalar(value);
231 }
232
233 bool sk_wstream_write_packed_uint(sk_wstream_t* cstream, size_t value)
234 {
235     return AsWStream(cstream)->writePackedUInt(value);
236 }
237
238 bool sk_wstream_write_stream(sk_wstream_t* cstream, sk_stream_t* input, size_t length)
239 {
240     return AsWStream(cstream)->writeStream(AsStream(input), length);
241 }
242
243 int sk_wstream_get_size_of_packed_uint(size_t value)
244 {
245     return SkWStream::SizeOfPackedUInt(value);
246 }