1 /*
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
8 #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"
14 #include "include/core/SkPathBuilder.h"
15 #include "include/core/SkPictureRecorder.h"
16 #include "include/core/SkSurface.h"
17
18 #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"
23 #include "include/c/sk_picture.h"
24 #include "include/c/sk_surface.h"
25 #include "src/c/sk_types_priv.h"
26
27 const struct {
28 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
from_c_pixelgeometry(sk_pixelgeometry_t cGeom,SkPixelGeometry * skGeom)39 static 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
from_c_matrix(const sk_matrix_t * cmatrix,SkMatrix * matrix)51 static 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
57 const struct {
58 sk_path_direction_t fC;
59 SkPathDirection fSk;
60 } gPathDirMap[] = {
61 { CW_SK_PATH_DIRECTION, SkPathDirection::kCW },
62 { CCW_SK_PATH_DIRECTION, SkPathDirection::kCCW },
63 };
64
from_c_path_direction(sk_path_direction_t cdir,SkPathDirection * dir)65 static bool from_c_path_direction(sk_path_direction_t cdir, SkPathDirection* dir) {
66 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
AsData(const sk_data_t * cdata)77 static SkData* AsData(const sk_data_t* cdata) {
78 return reinterpret_cast<SkData*>(const_cast<sk_data_t*>(cdata));
79 }
80
ToData(SkData * data)81 static sk_data_t* ToData(SkData* data) {
82 return reinterpret_cast<sk_data_t*>(data);
83 }
84
ToRect(const SkRect & rect)85 static sk_rect_t ToRect(const SkRect& rect) {
86 return reinterpret_cast<const sk_rect_t&>(rect);
87 }
88
AsRect(const sk_rect_t & crect)89 static const SkRect& AsRect(const sk_rect_t& crect) {
90 return reinterpret_cast<const SkRect&>(crect);
91 }
92
AsPath(const sk_path_t & cpath)93 static const SkPath& AsPath(const sk_path_t& cpath) {
94 return reinterpret_cast<const SkPath&>(cpath);
95 }
96
as_pathbuilder(sk_pathbuilder_t * cbuilder)97 static SkPathBuilder* as_pathbuilder(sk_pathbuilder_t* cbuilder) {
98 return reinterpret_cast<SkPathBuilder*>(cbuilder);
99 }
100
as_path(sk_path_t * cpath)101 static SkPath* as_path(sk_path_t* cpath) {
102 return reinterpret_cast<SkPath*>(cpath);
103 }
104
AsImage(const sk_image_t * cimage)105 static const SkImage* AsImage(const sk_image_t* cimage) {
106 return reinterpret_cast<const SkImage*>(cimage);
107 }
108
ToImage(SkImage * cimage)109 static sk_image_t* ToImage(SkImage* cimage) {
110 return reinterpret_cast<sk_image_t*>(cimage);
111 }
112
ToCanvas(SkCanvas * canvas)113 static sk_canvas_t* ToCanvas(SkCanvas* canvas) {
114 return reinterpret_cast<sk_canvas_t*>(canvas);
115 }
116
AsCanvas(sk_canvas_t * ccanvas)117 static SkCanvas* AsCanvas(sk_canvas_t* ccanvas) {
118 return reinterpret_cast<SkCanvas*>(ccanvas);
119 }
120
AsPictureRecorder(sk_picture_recorder_t * crec)121 static SkPictureRecorder* AsPictureRecorder(sk_picture_recorder_t* crec) {
122 return reinterpret_cast<SkPictureRecorder*>(crec);
123 }
124
ToPictureRecorder(SkPictureRecorder * rec)125 static sk_picture_recorder_t* ToPictureRecorder(SkPictureRecorder* rec) {
126 return reinterpret_cast<sk_picture_recorder_t*>(rec);
127 }
128
AsPicture(const sk_picture_t * cpic)129 static const SkPicture* AsPicture(const sk_picture_t* cpic) {
130 return reinterpret_cast<const SkPicture*>(cpic);
131 }
132
AsPicture(sk_picture_t * cpic)133 static SkPicture* AsPicture(sk_picture_t* cpic) {
134 return reinterpret_cast<SkPicture*>(cpic);
135 }
136
ToPicture(SkPicture * pic)137 static sk_picture_t* ToPicture(SkPicture* pic) {
138 return reinterpret_cast<sk_picture_t*>(pic);
139 }
140
141 ///////////////////////////////////////////////////////////////////////////////////////////
142
sk_image_new_raster_copy(const sk_imageinfo_t * cinfo,const void * pixels,size_t rowBytes)143 sk_image_t* sk_image_new_raster_copy(const sk_imageinfo_t* cinfo, const void* pixels,
144 size_t rowBytes) {
145 const SkImageInfo* info = reinterpret_cast<const SkImageInfo*>(cinfo);
146 return (sk_image_t*)SkImage::MakeRasterCopy(SkPixmap(*info, pixels, rowBytes)).release();
147 }
148
sk_image_new_from_encoded(const sk_data_t * cdata)149 sk_image_t* sk_image_new_from_encoded(const sk_data_t* cdata) {
150 return ToImage(SkImage::MakeFromEncoded(sk_ref_sp(AsData(cdata))).release());
151 }
152
sk_image_encode(const sk_image_t * cimage)153 sk_data_t* sk_image_encode(const sk_image_t* cimage) {
154 return ToData(AsImage(cimage)->encodeToData().release());
155 }
156
sk_image_ref(const sk_image_t * cimage)157 void sk_image_ref(const sk_image_t* cimage) {
158 AsImage(cimage)->ref();
159 }
160
sk_image_unref(const sk_image_t * cimage)161 void sk_image_unref(const sk_image_t* cimage) {
162 AsImage(cimage)->unref();
163 }
164
sk_image_get_width(const sk_image_t * cimage)165 int sk_image_get_width(const sk_image_t* cimage) {
166 return AsImage(cimage)->width();
167 }
168
sk_image_get_height(const sk_image_t * cimage)169 int sk_image_get_height(const sk_image_t* cimage) {
170 return AsImage(cimage)->height();
171 }
172
sk_image_get_unique_id(const sk_image_t * cimage)173 uint32_t sk_image_get_unique_id(const sk_image_t* cimage) {
174 return AsImage(cimage)->uniqueID();
175 }
176
177 ///////////////////////////////////////////////////////////////////////////////////////////
178
sk_pathbuilder_new()179 sk_pathbuilder_t* sk_pathbuilder_new() { return (sk_pathbuilder_t*)new SkPathBuilder; }
180
sk_pathbuilder_delete(sk_pathbuilder_t * cbuilder)181 void sk_pathbuilder_delete(sk_pathbuilder_t* cbuilder) { delete as_pathbuilder(cbuilder); }
182
sk_pathbuilder_move_to(sk_pathbuilder_t * cbuilder,float x,float y)183 void sk_pathbuilder_move_to(sk_pathbuilder_t* cbuilder, float x, float y) {
184 as_pathbuilder(cbuilder)->moveTo(x, y);
185 }
186
sk_pathbuilder_line_to(sk_pathbuilder_t * cbuilder,float x,float y)187 void sk_pathbuilder_line_to(sk_pathbuilder_t* cbuilder, float x, float y) {
188 as_pathbuilder(cbuilder)->lineTo(x, y);
189 }
190
sk_pathbuilder_quad_to(sk_pathbuilder_t * cbuilder,float x0,float y0,float x1,float y1)191 void 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
sk_pathbuilder_conic_to(sk_pathbuilder_t * cbuilder,float x0,float y0,float x1,float y1,float w)196 void 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
sk_pathbuilder_cubic_to(sk_pathbuilder_t * cbuilder,float x0,float y0,float x1,float y1,float x2,float y2)201 void 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
sk_pathbuilder_close(sk_pathbuilder_t * cbuilder)206 void sk_pathbuilder_close(sk_pathbuilder_t* cbuilder) {
207 as_pathbuilder(cbuilder)->close();
208 }
209
sk_pathbuilder_add_rect(sk_pathbuilder_t * cbuilder,const sk_rect_t * crect,sk_path_direction_t cdir)210 void 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
sk_pathbuilder_add_oval(sk_pathbuilder_t * cbuilder,const sk_rect_t * crect,sk_path_direction_t cdir)218 void 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
sk_pathbuilder_detach_path(sk_pathbuilder_t * cbuilder)226 sk_path_t* sk_pathbuilder_detach_path(sk_pathbuilder_t* cbuilder) {
227 return (sk_path_t*)(new SkPath(as_pathbuilder(cbuilder)->detach()));
228 }
229
sk_pathbuilder_snapshot_path(sk_pathbuilder_t * cbuilder)230 sk_path_t* sk_pathbuilder_snapshot_path(sk_pathbuilder_t* cbuilder) {
231 return (sk_path_t*)(new SkPath(as_pathbuilder(cbuilder)->snapshot()));
232 }
233
234 //////////////////////////////////////////////////////////////////////////////////////////////////
235
sk_path_delete(sk_path_t * cpath)236 void sk_path_delete(sk_path_t* cpath) { delete as_path(cpath); }
237
sk_path_get_bounds(const sk_path_t * cpath,sk_rect_t * crect)238 bool sk_path_get_bounds(const sk_path_t* cpath, sk_rect_t* crect) {
239 const SkPath& path = AsPath(*cpath);
240
241 if (path.isEmpty()) {
242 if (crect) {
243 *crect = ToRect(SkRect::MakeEmpty());
244 }
245 return false;
246 }
247
248 if (crect) {
249 *crect = ToRect(path.getBounds());
250 }
251 return true;
252 }
253
254 ///////////////////////////////////////////////////////////////////////////////////////////
255
sk_canvas_save(sk_canvas_t * ccanvas)256 void sk_canvas_save(sk_canvas_t* ccanvas) {
257 AsCanvas(ccanvas)->save();
258 }
259
sk_canvas_save_layer(sk_canvas_t * ccanvas,const sk_rect_t * crect,const sk_paint_t * cpaint)260 void 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
sk_canvas_restore(sk_canvas_t * ccanvas)264 void sk_canvas_restore(sk_canvas_t* ccanvas) {
265 AsCanvas(ccanvas)->restore();
266 }
267
sk_canvas_translate(sk_canvas_t * ccanvas,float dx,float dy)268 void sk_canvas_translate(sk_canvas_t* ccanvas, float dx, float dy) {
269 AsCanvas(ccanvas)->translate(dx, dy);
270 }
271
sk_canvas_scale(sk_canvas_t * ccanvas,float sx,float sy)272 void sk_canvas_scale(sk_canvas_t* ccanvas, float sx, float sy) {
273 AsCanvas(ccanvas)->scale(sx, sy);
274 }
275
sk_canvas_rotate_degrees(sk_canvas_t * ccanvas,float degrees)276 void sk_canvas_rotate_degrees(sk_canvas_t* ccanvas, float degrees) {
277 AsCanvas(ccanvas)->rotate(degrees);
278 }
279
sk_canvas_rotate_radians(sk_canvas_t * ccanvas,float radians)280 void sk_canvas_rotate_radians(sk_canvas_t* ccanvas, float radians) {
281 AsCanvas(ccanvas)->rotate(SkRadiansToDegrees(radians));
282 }
283
sk_canvas_skew(sk_canvas_t * ccanvas,float sx,float sy)284 void sk_canvas_skew(sk_canvas_t* ccanvas, float sx, float sy) {
285 AsCanvas(ccanvas)->skew(sx, sy);
286 }
287
sk_canvas_concat(sk_canvas_t * ccanvas,const sk_matrix_t * cmatrix)288 void sk_canvas_concat(sk_canvas_t* ccanvas, const sk_matrix_t* cmatrix) {
289 SkASSERT(cmatrix);
290 SkMatrix matrix;
291 from_c_matrix(cmatrix, &matrix);
292 AsCanvas(ccanvas)->concat(matrix);
293 }
294
sk_canvas_clip_rect(sk_canvas_t * ccanvas,const sk_rect_t * crect)295 void sk_canvas_clip_rect(sk_canvas_t* ccanvas, const sk_rect_t* crect) {
296 AsCanvas(ccanvas)->clipRect(AsRect(*crect));
297 }
298
sk_canvas_clip_path(sk_canvas_t * ccanvas,const sk_path_t * cpath)299 void sk_canvas_clip_path(sk_canvas_t* ccanvas, const sk_path_t* cpath) {
300 AsCanvas(ccanvas)->clipPath(AsPath(*cpath));
301 }
302
sk_canvas_draw_paint(sk_canvas_t * ccanvas,const sk_paint_t * cpaint)303 void sk_canvas_draw_paint(sk_canvas_t* ccanvas, const sk_paint_t* cpaint) {
304 AsCanvas(ccanvas)->drawPaint(AsPaint(*cpaint));
305 }
306
sk_canvas_draw_rect(sk_canvas_t * ccanvas,const sk_rect_t * crect,const sk_paint_t * cpaint)307 void 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
sk_canvas_draw_circle(sk_canvas_t * ccanvas,float cx,float cy,float rad,const sk_paint_t * cpaint)311 void 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
sk_canvas_draw_oval(sk_canvas_t * ccanvas,const sk_rect_t * crect,const sk_paint_t * cpaint)316 void 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
sk_canvas_draw_path(sk_canvas_t * ccanvas,const sk_path_t * cpath,const sk_paint_t * cpaint)320 void 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
to_sampling(const sk_sampling_options_t * s)324 static 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
sk_canvas_draw_image(sk_canvas_t * ccanvas,const sk_image_t * cimage,float x,float y,const sk_sampling_options_t * csamp,const sk_paint_t * cpaint)335 void sk_canvas_draw_image(sk_canvas_t* ccanvas, const sk_image_t* cimage, float x, float y,
336 const sk_sampling_options_t* csamp, const sk_paint_t* cpaint) {
337 AsCanvas(ccanvas)->drawImage(AsImage(cimage), x, y, to_sampling(csamp), AsPaint(cpaint));
338 }
339
sk_canvas_draw_image_rect(sk_canvas_t * ccanvas,const sk_image_t * cimage,const sk_rect_t * csrcR,const sk_rect_t * cdstR,const sk_sampling_options_t * csamp,const sk_paint_t * cpaint)340 void 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,
342 const sk_sampling_options_t* csamp, const sk_paint_t* cpaint) {
343 SkCanvas* canvas = AsCanvas(ccanvas);
344 const SkImage* image = AsImage(cimage);
345 const SkRect& dst = AsRect(*cdstR);
346 const SkSamplingOptions sampling = to_sampling(csamp);
347 const SkPaint* paint = AsPaint(cpaint);
348
349 if (csrcR) {
350 canvas->drawImageRect(image, AsRect(*csrcR), dst, sampling, paint,
351 SkCanvas::kStrict_SrcRectConstraint);
352 } else {
353 canvas->drawImageRect(image, dst, sampling, paint);
354 }
355 }
356
sk_canvas_draw_picture(sk_canvas_t * ccanvas,const sk_picture_t * cpicture,const sk_matrix_t * cmatrix,const sk_paint_t * cpaint)357 void sk_canvas_draw_picture(sk_canvas_t* ccanvas, const sk_picture_t* cpicture,
358 const sk_matrix_t* cmatrix, const sk_paint_t* cpaint) {
359 const SkMatrix* matrixPtr = nullptr;
360 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
368 ///////////////////////////////////////////////////////////////////////////////////////////
369
sk_surface_new_raster(const sk_imageinfo_t * cinfo,const sk_surfaceprops_t * props)370 sk_surface_t* sk_surface_new_raster(const sk_imageinfo_t* cinfo,
371 const sk_surfaceprops_t* props) {
372 const SkImageInfo* info = reinterpret_cast<const SkImageInfo*>(cinfo);
373 SkPixelGeometry geo = kUnknown_SkPixelGeometry;
374 if (props && !from_c_pixelgeometry(props->pixelGeometry, &geo)) {
375 return nullptr;
376 }
377
378 SkSurfaceProps surfProps(0, geo);
379 return (sk_surface_t*)SkSurface::MakeRaster(*info, &surfProps).release();
380 }
381
sk_surface_new_raster_direct(const sk_imageinfo_t * cinfo,void * pixels,size_t rowBytes,const sk_surfaceprops_t * props)382 sk_surface_t* sk_surface_new_raster_direct(const sk_imageinfo_t* cinfo, void* pixels,
383 size_t rowBytes,
384 const sk_surfaceprops_t* props) {
385 const SkImageInfo* info = reinterpret_cast<const SkImageInfo*>(cinfo);
386 SkPixelGeometry geo = kUnknown_SkPixelGeometry;
387 if (props && !from_c_pixelgeometry(props->pixelGeometry, &geo)) {
388 return nullptr;
389 }
390
391 SkSurfaceProps surfProps(0, geo);
392 return (sk_surface_t*)SkSurface::MakeRasterDirect(*info, pixels, rowBytes, &surfProps).release();
393 }
394
sk_surface_unref(sk_surface_t * csurf)395 void sk_surface_unref(sk_surface_t* csurf) {
396 SkSafeUnref((SkSurface*)csurf);
397 }
398
sk_surface_get_canvas(sk_surface_t * csurf)399 sk_canvas_t* sk_surface_get_canvas(sk_surface_t* csurf) {
400 SkSurface* surf = (SkSurface*)csurf;
401 return (sk_canvas_t*)surf->getCanvas();
402 }
403
sk_surface_new_image_snapshot(sk_surface_t * csurf)404 sk_image_t* sk_surface_new_image_snapshot(sk_surface_t* csurf) {
405 SkSurface* surf = (SkSurface*)csurf;
406 return (sk_image_t*)surf->makeImageSnapshot().release();
407 }
408
409 ///////////////////////////////////////////////////////////////////////////////////////////
410
sk_picture_recorder_new()411 sk_picture_recorder_t* sk_picture_recorder_new() {
412 return ToPictureRecorder(new SkPictureRecorder);
413 }
414
sk_picture_recorder_delete(sk_picture_recorder_t * crec)415 void sk_picture_recorder_delete(sk_picture_recorder_t* crec) {
416 delete AsPictureRecorder(crec);
417 }
418
sk_picture_recorder_begin_recording(sk_picture_recorder_t * crec,const sk_rect_t * cbounds)419 sk_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
sk_picture_recorder_end_recording(sk_picture_recorder_t * crec)424 sk_picture_t* sk_picture_recorder_end_recording(sk_picture_recorder_t* crec) {
425 return ToPicture(AsPictureRecorder(crec)->finishRecordingAsPicture().release());
426 }
427
sk_picture_ref(sk_picture_t * cpic)428 void sk_picture_ref(sk_picture_t* cpic) {
429 SkSafeRef(AsPicture(cpic));
430 }
431
sk_picture_unref(sk_picture_t * cpic)432 void sk_picture_unref(sk_picture_t* cpic) {
433 SkSafeUnref(AsPicture(cpic));
434 }
435
sk_picture_get_unique_id(sk_picture_t * cpic)436 uint32_t sk_picture_get_unique_id(sk_picture_t* cpic) {
437 return AsPicture(cpic)->uniqueID();
438 }
439
sk_picture_get_bounds(sk_picture_t * cpic)440 sk_rect_t sk_picture_get_bounds(sk_picture_t* cpic) {
441 return ToRect(AsPicture(cpic)->cullRect());
442 }
443
444 ///////////////////////////////////////////////////////////////////////////////////////////
445
sk_data_new_with_copy(const void * src,size_t length)446 sk_data_t* sk_data_new_with_copy(const void* src, size_t length) {
447 return ToData(SkData::MakeWithCopy(src, length).release());
448 }
449
sk_data_new_from_malloc(const void * memory,size_t length)450 sk_data_t* sk_data_new_from_malloc(const void* memory, size_t length) {
451 return ToData(SkData::MakeFromMalloc(memory, length).release());
452 }
453
sk_data_new_subset(const sk_data_t * csrc,size_t offset,size_t length)454 sk_data_t* sk_data_new_subset(const sk_data_t* csrc, size_t offset, size_t length) {
455 return ToData(SkData::MakeSubset(AsData(csrc), offset, length).release());
456 }
457
sk_data_ref(const sk_data_t * cdata)458 void sk_data_ref(const sk_data_t* cdata) {
459 SkSafeRef(AsData(cdata));
460 }
461
sk_data_unref(const sk_data_t * cdata)462 void sk_data_unref(const sk_data_t* cdata) {
463 SkSafeUnref(AsData(cdata));
464 }
465
sk_data_get_size(const sk_data_t * cdata)466 size_t sk_data_get_size(const sk_data_t* cdata) {
467 return AsData(cdata)->size();
468 }
469
sk_data_get_data(const sk_data_t * cdata)470 const void* sk_data_get_data(const sk_data_t* cdata) {
471 return AsData(cdata)->data();
472 }
473
474 ///////////////////////////////////////////////////////////////////////////////////////////
475