blob: ca23a7d7eea2f1152330f05e757b5ff668888e6a [file] [log] [blame]
reed8e474782014-10-06 11:00:51 -07001/*
2 * Copyright 2014 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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/core/SkCanvas.h"
9#include "include/core/SkData.h"
10#include "include/core/SkImage.h"
11#include "include/core/SkMaskFilter.h"
12#include "include/core/SkMatrix.h"
13#include "include/core/SkPaint.h"
Mike Reede9d783c2020-08-17 14:14:13 -040014#include "include/core/SkPathBuilder.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050015#include "include/core/SkPictureRecorder.h"
16#include "include/core/SkSurface.h"
reed938dfba2014-10-06 06:08:16 -070017
Mike Kleinc0bd9f92019-04-23 12:05:21 -050018#include "include/c/sk_canvas.h"
19#include "include/c/sk_data.h"
20#include "include/c/sk_image.h"
21#include "include/c/sk_paint.h"
22#include "include/c/sk_path.h"
Stan Iliev82310312019-06-05 16:55:54 -040023#include "include/c/sk_picture.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040024#include "include/c/sk_surface.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050025#include "src/c/sk_types_priv.h"
halcanary219f18f2015-09-01 10:01:38 -070026
reede3323962014-10-24 11:16:19 -070027const struct {
robertphillips702edbd2015-06-23 06:26:08 -070028 sk_pixelgeometry_t fC;
29 SkPixelGeometry fSK;
30} gPixelGeometryMap[] = {
31 { UNKNOWN_SK_PIXELGEOMETRY, kUnknown_SkPixelGeometry },
32 { RGB_H_SK_PIXELGEOMETRY, kRGB_H_SkPixelGeometry },
33 { BGR_H_SK_PIXELGEOMETRY, kBGR_H_SkPixelGeometry },
34 { RGB_V_SK_PIXELGEOMETRY, kRGB_V_SkPixelGeometry },
35 { BGR_V_SK_PIXELGEOMETRY, kBGR_V_SkPixelGeometry },
36};
37
38
39static bool from_c_pixelgeometry(sk_pixelgeometry_t cGeom, SkPixelGeometry* skGeom) {
40 for (size_t i = 0; i < SK_ARRAY_COUNT(gPixelGeometryMap); ++i) {
41 if (gPixelGeometryMap[i].fC == cGeom) {
42 if (skGeom) {
43 *skGeom = gPixelGeometryMap[i].fSK;
44 }
45 return true;
46 }
47 }
48 return false;
49}
50
abarth9503ac72014-12-02 15:47:33 -080051static void from_c_matrix(const sk_matrix_t* cmatrix, SkMatrix* matrix) {
52 matrix->setAll(cmatrix->mat[0], cmatrix->mat[1], cmatrix->mat[2],
53 cmatrix->mat[3], cmatrix->mat[4], cmatrix->mat[5],
54 cmatrix->mat[6], cmatrix->mat[7], cmatrix->mat[8]);
55}
56
reed73c25012014-11-17 06:15:42 -080057const struct {
58 sk_path_direction_t fC;
Mike Reed30bc5272019-11-22 18:34:02 +000059 SkPathDirection fSk;
reed73c25012014-11-17 06:15:42 -080060} gPathDirMap[] = {
Mike Reed30bc5272019-11-22 18:34:02 +000061 { CW_SK_PATH_DIRECTION, SkPathDirection::kCW },
62 { CCW_SK_PATH_DIRECTION, SkPathDirection::kCCW },
reed73c25012014-11-17 06:15:42 -080063};
64
Mike Reed30bc5272019-11-22 18:34:02 +000065static bool from_c_path_direction(sk_path_direction_t cdir, SkPathDirection* dir) {
reed73c25012014-11-17 06:15:42 -080066 for (size_t i = 0; i < SK_ARRAY_COUNT(gPathDirMap); ++i) {
67 if (gPathDirMap[i].fC == cdir) {
68 if (dir) {
69 *dir = gPathDirMap[i].fSk;
70 }
71 return true;
72 }
73 }
74 return false;
75}
76
reedb2a5d7e2014-12-25 14:16:21 -080077static SkData* AsData(const sk_data_t* cdata) {
78 return reinterpret_cast<SkData*>(const_cast<sk_data_t*>(cdata));
79}
80
81static sk_data_t* ToData(SkData* data) {
82 return reinterpret_cast<sk_data_t*>(data);
83}
84
reede3719892014-12-22 17:46:00 -080085static sk_rect_t ToRect(const SkRect& rect) {
86 return reinterpret_cast<const sk_rect_t&>(rect);
87}
88
reed8e474782014-10-06 11:00:51 -070089static const SkRect& AsRect(const sk_rect_t& crect) {
90 return reinterpret_cast<const SkRect&>(crect);
91}
92
93static const SkPath& AsPath(const sk_path_t& cpath) {
94 return reinterpret_cast<const SkPath&>(cpath);
95}
96
Mike Reede9d783c2020-08-17 14:14:13 -040097static SkPathBuilder* as_pathbuilder(sk_pathbuilder_t* cbuilder) {
98 return reinterpret_cast<SkPathBuilder*>(cbuilder);
99}
100
robertphillipsa624e872014-10-08 06:04:35 -0700101static SkPath* as_path(sk_path_t* cpath) {
102 return reinterpret_cast<SkPath*>(cpath);
103}
104
reed8e474782014-10-06 11:00:51 -0700105static const SkImage* AsImage(const sk_image_t* cimage) {
106 return reinterpret_cast<const SkImage*>(cimage);
107}
reed938dfba2014-10-06 06:08:16 -0700108
reedb2a5d7e2014-12-25 14:16:21 -0800109static sk_image_t* ToImage(SkImage* cimage) {
110 return reinterpret_cast<sk_image_t*>(cimage);
111}
112
reede3719892014-12-22 17:46:00 -0800113static sk_canvas_t* ToCanvas(SkCanvas* canvas) {
114 return reinterpret_cast<sk_canvas_t*>(canvas);
115}
116
reed8e474782014-10-06 11:00:51 -0700117static SkCanvas* AsCanvas(sk_canvas_t* ccanvas) {
118 return reinterpret_cast<SkCanvas*>(ccanvas);
119}
120
reede3719892014-12-22 17:46:00 -0800121static SkPictureRecorder* AsPictureRecorder(sk_picture_recorder_t* crec) {
122 return reinterpret_cast<SkPictureRecorder*>(crec);
123}
124
125static sk_picture_recorder_t* ToPictureRecorder(SkPictureRecorder* rec) {
126 return reinterpret_cast<sk_picture_recorder_t*>(rec);
127}
128
129static const SkPicture* AsPicture(const sk_picture_t* cpic) {
130 return reinterpret_cast<const SkPicture*>(cpic);
131}
132
133static SkPicture* AsPicture(sk_picture_t* cpic) {
134 return reinterpret_cast<SkPicture*>(cpic);
135}
136
137static sk_picture_t* ToPicture(SkPicture* pic) {
138 return reinterpret_cast<sk_picture_t*>(pic);
139}
140
reed8e474782014-10-06 11:00:51 -0700141///////////////////////////////////////////////////////////////////////////////////////////
142
143sk_image_t* sk_image_new_raster_copy(const sk_imageinfo_t* cinfo, const void* pixels,
144 size_t rowBytes) {
Mike Reed66c505f2018-09-28 11:27:57 -0400145 const SkImageInfo* info = reinterpret_cast<const SkImageInfo*>(cinfo);
146 return (sk_image_t*)SkImage::MakeRasterCopy(SkPixmap(*info, pixels, rowBytes)).release();
reed8e474782014-10-06 11:00:51 -0700147}
148
Mike Reed564d49e2020-07-28 12:52:31 -0400149sk_image_t* sk_image_new_from_encoded(const sk_data_t* cdata) {
150 return ToImage(SkImage::MakeFromEncoded(sk_ref_sp(AsData(cdata))).release());
reedb2a5d7e2014-12-25 14:16:21 -0800151}
152
153sk_data_t* sk_image_encode(const sk_image_t* cimage) {
Mike Reed6409f842017-07-11 16:03:13 -0400154 return ToData(AsImage(cimage)->encodeToData().release());
reedb2a5d7e2014-12-25 14:16:21 -0800155}
156
reed8e474782014-10-06 11:00:51 -0700157void sk_image_ref(const sk_image_t* cimage) {
158 AsImage(cimage)->ref();
159}
160
161void sk_image_unref(const sk_image_t* cimage) {
162 AsImage(cimage)->unref();
163}
164
165int sk_image_get_width(const sk_image_t* cimage) {
166 return AsImage(cimage)->width();
167}
168
169int sk_image_get_height(const sk_image_t* cimage) {
170 return AsImage(cimage)->height();
171}
172
173uint32_t sk_image_get_unique_id(const sk_image_t* cimage) {
174 return AsImage(cimage)->uniqueID();
175}
176
177///////////////////////////////////////////////////////////////////////////////////////////
178
Mike Reede9d783c2020-08-17 14:14:13 -0400179sk_pathbuilder_t* sk_pathbuilder_new() { return (sk_pathbuilder_t*)new SkPathBuilder; }
180
181void sk_pathbuilder_delete(sk_pathbuilder_t* cbuilder) { delete as_pathbuilder(cbuilder); }
182
183void sk_pathbuilder_move_to(sk_pathbuilder_t* cbuilder, float x, float y) {
184 as_pathbuilder(cbuilder)->moveTo(x, y);
185}
186
187void sk_pathbuilder_line_to(sk_pathbuilder_t* cbuilder, float x, float y) {
188 as_pathbuilder(cbuilder)->lineTo(x, y);
189}
190
191void sk_pathbuilder_quad_to(sk_pathbuilder_t* cbuilder,
192 float x0, float y0, float x1, float y1) {
193 as_pathbuilder(cbuilder)->quadTo(x0, y0, x1, y1);
194}
195
196void sk_pathbuilder_conic_to(sk_pathbuilder_t* cbuilder,
197 float x0, float y0, float x1, float y1, float w) {
198 as_pathbuilder(cbuilder)->conicTo(x0, y0, x1, y1, w);
199}
200
201void sk_pathbuilder_cubic_to(sk_pathbuilder_t* cbuilder,
202 float x0, float y0, float x1, float y1, float x2, float y2) {
203 as_pathbuilder(cbuilder)->cubicTo(x0, y0, x1, y1, x2, y2);
204}
205
206void sk_pathbuilder_close(sk_pathbuilder_t* cbuilder) {
207 as_pathbuilder(cbuilder)->close();
208}
209
210void sk_pathbuilder_add_rect(sk_pathbuilder_t* cbuilder, const sk_rect_t* crect, sk_path_direction_t cdir) {
211 SkPathDirection dir;
212 if (!from_c_path_direction(cdir, &dir)) {
213 return;
214 }
215 as_pathbuilder(cbuilder)->addRect(AsRect(*crect), dir);
216}
217
218void sk_pathbuilder_add_oval(sk_pathbuilder_t* cbuilder, const sk_rect_t* crect, sk_path_direction_t cdir) {
219 SkPathDirection dir;
220 if (!from_c_path_direction(cdir, &dir)) {
221 return;
222 }
223 as_pathbuilder(cbuilder)->addOval(AsRect(*crect), dir);
224}
225
226sk_path_t* sk_pathbuilder_detach_path(sk_pathbuilder_t* cbuilder) {
227 return (sk_path_t*)(new SkPath(as_pathbuilder(cbuilder)->detach()));
228}
229
230sk_path_t* sk_pathbuilder_snapshot_path(sk_pathbuilder_t* cbuilder) {
231 return (sk_path_t*)(new SkPath(as_pathbuilder(cbuilder)->snapshot()));
232}
233
234//////////////////////////////////////////////////////////////////////////////////////////////////
robertphillipsa624e872014-10-08 06:04:35 -0700235
halcanary385fe4d2015-08-26 13:07:48 -0700236void sk_path_delete(sk_path_t* cpath) { delete as_path(cpath); }
robertphillipsa624e872014-10-08 06:04:35 -0700237
reed73c25012014-11-17 06:15:42 -0800238bool sk_path_get_bounds(const sk_path_t* cpath, sk_rect_t* crect) {
239 const SkPath& path = AsPath(*cpath);
reed73c25012014-11-17 06:15:42 -0800240
241 if (path.isEmpty()) {
reede3719892014-12-22 17:46:00 -0800242 if (crect) {
243 *crect = ToRect(SkRect::MakeEmpty());
reed73c25012014-11-17 06:15:42 -0800244 }
245 return false;
246 }
reede3719892014-12-22 17:46:00 -0800247
248 if (crect) {
249 *crect = ToRect(path.getBounds());
250 }
reed73c25012014-11-17 06:15:42 -0800251 return true;
252}
253
robertphillipsa624e872014-10-08 06:04:35 -0700254///////////////////////////////////////////////////////////////////////////////////////////
255
reed938dfba2014-10-06 06:08:16 -0700256void sk_canvas_save(sk_canvas_t* ccanvas) {
257 AsCanvas(ccanvas)->save();
258}
259
260void sk_canvas_save_layer(sk_canvas_t* ccanvas, const sk_rect_t* crect, const sk_paint_t* cpaint) {
261 AsCanvas(ccanvas)->drawRect(AsRect(*crect), AsPaint(*cpaint));
262}
263
264void sk_canvas_restore(sk_canvas_t* ccanvas) {
265 AsCanvas(ccanvas)->restore();
266}
267
268void sk_canvas_translate(sk_canvas_t* ccanvas, float dx, float dy) {
269 AsCanvas(ccanvas)->translate(dx, dy);
270}
271
272void sk_canvas_scale(sk_canvas_t* ccanvas, float sx, float sy) {
reed8e474782014-10-06 11:00:51 -0700273 AsCanvas(ccanvas)->scale(sx, sy);
reed938dfba2014-10-06 06:08:16 -0700274}
275
Mike Kleinfa2d4682020-10-28 16:25:37 -0500276void sk_canvas_rotate_degrees(sk_canvas_t* ccanvas, float degrees) {
abarth2fc6ea62014-12-01 14:04:03 -0800277 AsCanvas(ccanvas)->rotate(degrees);
278}
279
280void sk_canvas_rotate_radians(sk_canvas_t* ccanvas, float radians) {
281 AsCanvas(ccanvas)->rotate(SkRadiansToDegrees(radians));
282}
283
284void sk_canvas_skew(sk_canvas_t* ccanvas, float sx, float sy) {
285 AsCanvas(ccanvas)->skew(sx, sy);
286}
287
reede3719892014-12-22 17:46:00 -0800288void sk_canvas_concat(sk_canvas_t* ccanvas, const sk_matrix_t* cmatrix) {
abarth9503ac72014-12-02 15:47:33 -0800289 SkASSERT(cmatrix);
290 SkMatrix matrix;
291 from_c_matrix(cmatrix, &matrix);
292 AsCanvas(ccanvas)->concat(matrix);
293}
294
reede3719892014-12-22 17:46:00 -0800295void sk_canvas_clip_rect(sk_canvas_t* ccanvas, const sk_rect_t* crect) {
296 AsCanvas(ccanvas)->clipRect(AsRect(*crect));
297}
298
299void sk_canvas_clip_path(sk_canvas_t* ccanvas, const sk_path_t* cpath) {
300 AsCanvas(ccanvas)->clipPath(AsPath(*cpath));
301}
302
reed938dfba2014-10-06 06:08:16 -0700303void sk_canvas_draw_paint(sk_canvas_t* ccanvas, const sk_paint_t* cpaint) {
304 AsCanvas(ccanvas)->drawPaint(AsPaint(*cpaint));
305}
306
307void sk_canvas_draw_rect(sk_canvas_t* ccanvas, const sk_rect_t* crect, const sk_paint_t* cpaint) {
308 AsCanvas(ccanvas)->drawRect(AsRect(*crect), AsPaint(*cpaint));
309}
310
reed4a7940b2016-02-09 13:25:51 -0800311void sk_canvas_draw_circle(sk_canvas_t* ccanvas, float cx, float cy, float rad,
312 const sk_paint_t* cpaint) {
313 AsCanvas(ccanvas)->drawCircle(cx, cy, rad, AsPaint(*cpaint));
314}
315
reed938dfba2014-10-06 06:08:16 -0700316void sk_canvas_draw_oval(sk_canvas_t* ccanvas, const sk_rect_t* crect, const sk_paint_t* cpaint) {
317 AsCanvas(ccanvas)->drawOval(AsRect(*crect), AsPaint(*cpaint));
318}
319
320void sk_canvas_draw_path(sk_canvas_t* ccanvas, const sk_path_t* cpath, const sk_paint_t* cpaint) {
321 AsCanvas(ccanvas)->drawPath(AsPath(*cpath), AsPaint(*cpaint));
322}
323
Mike Reed18aeb572021-01-19 17:58:25 -0500324static SkSamplingOptions to_sampling(const sk_sampling_options_t* s) {
325 if (s) {
326 if (s->useCubic) {
327 return SkSamplingOptions({s->cubic.B, s->cubic.C});
328 } else {
329 return SkSamplingOptions(SkFilterMode(s->filter), SkMipmapMode(s->mipmap));
330 }
331 }
332 return SkSamplingOptions();
333}
334
reed938dfba2014-10-06 06:08:16 -0700335void sk_canvas_draw_image(sk_canvas_t* ccanvas, const sk_image_t* cimage, float x, float y,
Mike Reed18aeb572021-01-19 17:58:25 -0500336 const sk_sampling_options_t* csamp, const sk_paint_t* cpaint) {
337 AsCanvas(ccanvas)->drawImage(AsImage(cimage), x, y, to_sampling(csamp), AsPaint(cpaint));
reed938dfba2014-10-06 06:08:16 -0700338}
339
reede3719892014-12-22 17:46:00 -0800340void sk_canvas_draw_image_rect(sk_canvas_t* ccanvas, const sk_image_t* cimage,
341 const sk_rect_t* csrcR, const sk_rect_t* cdstR,
Mike Reed18aeb572021-01-19 17:58:25 -0500342 const sk_sampling_options_t* csamp, const sk_paint_t* cpaint) {
reede47829b2015-08-06 10:02:53 -0700343 SkCanvas* canvas = AsCanvas(ccanvas);
344 const SkImage* image = AsImage(cimage);
345 const SkRect& dst = AsRect(*cdstR);
Mike Reed18aeb572021-01-19 17:58:25 -0500346 const SkSamplingOptions sampling = to_sampling(csamp);
reede47829b2015-08-06 10:02:53 -0700347 const SkPaint* paint = AsPaint(cpaint);
348
349 if (csrcR) {
Mike Reed18aeb572021-01-19 17:58:25 -0500350 canvas->drawImageRect(image, AsRect(*csrcR), dst, sampling, paint,
351 SkCanvas::kStrict_SrcRectConstraint);
reede47829b2015-08-06 10:02:53 -0700352 } else {
Mike Reed34c56a52021-01-22 15:26:41 -0500353 canvas->drawImageRect(image, dst, sampling, paint);
reede47829b2015-08-06 10:02:53 -0700354 }
reede3719892014-12-22 17:46:00 -0800355}
356
357void sk_canvas_draw_picture(sk_canvas_t* ccanvas, const sk_picture_t* cpicture,
358 const sk_matrix_t* cmatrix, const sk_paint_t* cpaint) {
John Stilesfe0de302020-08-14 10:52:06 -0400359 const SkMatrix* matrixPtr = nullptr;
reede3719892014-12-22 17:46:00 -0800360 SkMatrix matrix;
361 if (cmatrix) {
362 from_c_matrix(cmatrix, &matrix);
363 matrixPtr = &matrix;
364 }
365 AsCanvas(ccanvas)->drawPicture(AsPicture(cpicture), matrixPtr, AsPaint(cpaint));
366}
367
reed938dfba2014-10-06 06:08:16 -0700368///////////////////////////////////////////////////////////////////////////////////////////
369
robertphillips702edbd2015-06-23 06:26:08 -0700370sk_surface_t* sk_surface_new_raster(const sk_imageinfo_t* cinfo,
371 const sk_surfaceprops_t* props) {
Mike Reed66c505f2018-09-28 11:27:57 -0400372 const SkImageInfo* info = reinterpret_cast<const SkImageInfo*>(cinfo);
robertphillips702edbd2015-06-23 06:26:08 -0700373 SkPixelGeometry geo = kUnknown_SkPixelGeometry;
374 if (props && !from_c_pixelgeometry(props->pixelGeometry, &geo)) {
John Stilesfe0de302020-08-14 10:52:06 -0400375 return nullptr;
robertphillips702edbd2015-06-23 06:26:08 -0700376 }
377
378 SkSurfaceProps surfProps(0, geo);
Mike Reed66c505f2018-09-28 11:27:57 -0400379 return (sk_surface_t*)SkSurface::MakeRaster(*info, &surfProps).release();
reed938dfba2014-10-06 06:08:16 -0700380}
381
reed8e474782014-10-06 11:00:51 -0700382sk_surface_t* sk_surface_new_raster_direct(const sk_imageinfo_t* cinfo, void* pixels,
robertphillips702edbd2015-06-23 06:26:08 -0700383 size_t rowBytes,
384 const sk_surfaceprops_t* props) {
Mike Reed66c505f2018-09-28 11:27:57 -0400385 const SkImageInfo* info = reinterpret_cast<const SkImageInfo*>(cinfo);
robertphillips702edbd2015-06-23 06:26:08 -0700386 SkPixelGeometry geo = kUnknown_SkPixelGeometry;
387 if (props && !from_c_pixelgeometry(props->pixelGeometry, &geo)) {
John Stilesfe0de302020-08-14 10:52:06 -0400388 return nullptr;
robertphillips702edbd2015-06-23 06:26:08 -0700389 }
390
391 SkSurfaceProps surfProps(0, geo);
Mike Reed66c505f2018-09-28 11:27:57 -0400392 return (sk_surface_t*)SkSurface::MakeRasterDirect(*info, pixels, rowBytes, &surfProps).release();
reed938dfba2014-10-06 06:08:16 -0700393}
394
reedafa278e2014-11-24 19:11:48 -0800395void sk_surface_unref(sk_surface_t* csurf) {
396 SkSafeUnref((SkSurface*)csurf);
reed938dfba2014-10-06 06:08:16 -0700397}
398
399sk_canvas_t* sk_surface_get_canvas(sk_surface_t* csurf) {
400 SkSurface* surf = (SkSurface*)csurf;
reed8e474782014-10-06 11:00:51 -0700401 return (sk_canvas_t*)surf->getCanvas();
reed938dfba2014-10-06 06:08:16 -0700402}
403
404sk_image_t* sk_surface_new_image_snapshot(sk_surface_t* csurf) {
405 SkSurface* surf = (SkSurface*)csurf;
reed9ce9d672016-03-17 10:51:11 -0700406 return (sk_image_t*)surf->makeImageSnapshot().release();
reed938dfba2014-10-06 06:08:16 -0700407}
408
reedafa278e2014-11-24 19:11:48 -0800409///////////////////////////////////////////////////////////////////////////////////////////
reed938dfba2014-10-06 06:08:16 -0700410
reede3719892014-12-22 17:46:00 -0800411sk_picture_recorder_t* sk_picture_recorder_new() {
412 return ToPictureRecorder(new SkPictureRecorder);
413}
414
415void sk_picture_recorder_delete(sk_picture_recorder_t* crec) {
416 delete AsPictureRecorder(crec);
417}
418
419sk_canvas_t* sk_picture_recorder_begin_recording(sk_picture_recorder_t* crec,
420 const sk_rect_t* cbounds) {
421 return ToCanvas(AsPictureRecorder(crec)->beginRecording(AsRect(*cbounds)));
422}
423
424sk_picture_t* sk_picture_recorder_end_recording(sk_picture_recorder_t* crec) {
reedca2622b2016-03-18 07:25:55 -0700425 return ToPicture(AsPictureRecorder(crec)->finishRecordingAsPicture().release());
reede3719892014-12-22 17:46:00 -0800426}
427
428void sk_picture_ref(sk_picture_t* cpic) {
429 SkSafeRef(AsPicture(cpic));
430}
431
432void sk_picture_unref(sk_picture_t* cpic) {
433 SkSafeUnref(AsPicture(cpic));
434}
435
436uint32_t sk_picture_get_unique_id(sk_picture_t* cpic) {
437 return AsPicture(cpic)->uniqueID();
438}
439
440sk_rect_t sk_picture_get_bounds(sk_picture_t* cpic) {
441 return ToRect(AsPicture(cpic)->cullRect());
442}
443
444///////////////////////////////////////////////////////////////////////////////////////////
445
reedb2a5d7e2014-12-25 14:16:21 -0800446sk_data_t* sk_data_new_with_copy(const void* src, size_t length) {
reedfde05112016-03-11 13:02:28 -0800447 return ToData(SkData::MakeWithCopy(src, length).release());
reedb2a5d7e2014-12-25 14:16:21 -0800448}
449
450sk_data_t* sk_data_new_from_malloc(const void* memory, size_t length) {
reedfde05112016-03-11 13:02:28 -0800451 return ToData(SkData::MakeFromMalloc(memory, length).release());
reedb2a5d7e2014-12-25 14:16:21 -0800452}
453
454sk_data_t* sk_data_new_subset(const sk_data_t* csrc, size_t offset, size_t length) {
reedfde05112016-03-11 13:02:28 -0800455 return ToData(SkData::MakeSubset(AsData(csrc), offset, length).release());
reedb2a5d7e2014-12-25 14:16:21 -0800456}
457
458void sk_data_ref(const sk_data_t* cdata) {
459 SkSafeRef(AsData(cdata));
460}
461
462void sk_data_unref(const sk_data_t* cdata) {
463 SkSafeUnref(AsData(cdata));
464}
465
466size_t sk_data_get_size(const sk_data_t* cdata) {
467 return AsData(cdata)->size();
468}
469
470const void* sk_data_get_data(const sk_data_t* cdata) {
471 return AsData(cdata)->data();
472}
473
474///////////////////////////////////////////////////////////////////////////////////////////