reed | 8e47478 | 2014-10-06 11:00:51 -0700 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 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/SkPath.h" |
| 15 | #include "include/core/SkPictureRecorder.h" |
| 16 | #include "include/core/SkSurface.h" |
reed | 938dfba | 2014-10-06 06:08:16 -0700 | [diff] [blame] | 17 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 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_surface.h" |
Stan Iliev | 8231031 | 2019-06-05 16:55:54 -0400 | [diff] [blame^] | 24 | #include "include/c/sk_picture.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 25 | #include "src/c/sk_types_priv.h" |
halcanary | 219f18f | 2015-09-01 10:01:38 -0700 | [diff] [blame] | 26 | |
reed | e332396 | 2014-10-24 11:16:19 -0700 | [diff] [blame] | 27 | const struct { |
robertphillips | 702edbd | 2015-06-23 06:26:08 -0700 | [diff] [blame] | 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 | |
| 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 | |
abarth | 9503ac7 | 2014-12-02 15:47:33 -0800 | [diff] [blame] | 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 | |
reed | 73c2501 | 2014-11-17 06:15:42 -0800 | [diff] [blame] | 57 | const struct { |
| 58 | sk_path_direction_t fC; |
| 59 | SkPath::Direction fSk; |
| 60 | } gPathDirMap[] = { |
| 61 | { CW_SK_PATH_DIRECTION, SkPath::kCW_Direction }, |
| 62 | { CCW_SK_PATH_DIRECTION, SkPath::kCCW_Direction }, |
| 63 | }; |
| 64 | |
| 65 | static bool from_c_path_direction(sk_path_direction_t cdir, SkPath::Direction* 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 | |
reed | b2a5d7e | 2014-12-25 14:16:21 -0800 | [diff] [blame] | 77 | static SkData* AsData(const sk_data_t* cdata) { |
| 78 | return reinterpret_cast<SkData*>(const_cast<sk_data_t*>(cdata)); |
| 79 | } |
| 80 | |
| 81 | static sk_data_t* ToData(SkData* data) { |
| 82 | return reinterpret_cast<sk_data_t*>(data); |
| 83 | } |
| 84 | |
reed | e371989 | 2014-12-22 17:46:00 -0800 | [diff] [blame] | 85 | static sk_rect_t ToRect(const SkRect& rect) { |
| 86 | return reinterpret_cast<const sk_rect_t&>(rect); |
| 87 | } |
| 88 | |
reed | 8e47478 | 2014-10-06 11:00:51 -0700 | [diff] [blame] | 89 | static const SkRect& AsRect(const sk_rect_t& crect) { |
| 90 | return reinterpret_cast<const SkRect&>(crect); |
| 91 | } |
| 92 | |
| 93 | static const SkPath& AsPath(const sk_path_t& cpath) { |
| 94 | return reinterpret_cast<const SkPath&>(cpath); |
| 95 | } |
| 96 | |
robertphillips | a624e87 | 2014-10-08 06:04:35 -0700 | [diff] [blame] | 97 | static SkPath* as_path(sk_path_t* cpath) { |
| 98 | return reinterpret_cast<SkPath*>(cpath); |
| 99 | } |
| 100 | |
reed | 8e47478 | 2014-10-06 11:00:51 -0700 | [diff] [blame] | 101 | static const SkImage* AsImage(const sk_image_t* cimage) { |
| 102 | return reinterpret_cast<const SkImage*>(cimage); |
| 103 | } |
reed | 938dfba | 2014-10-06 06:08:16 -0700 | [diff] [blame] | 104 | |
reed | b2a5d7e | 2014-12-25 14:16:21 -0800 | [diff] [blame] | 105 | static sk_image_t* ToImage(SkImage* cimage) { |
| 106 | return reinterpret_cast<sk_image_t*>(cimage); |
| 107 | } |
| 108 | |
reed | e371989 | 2014-12-22 17:46:00 -0800 | [diff] [blame] | 109 | static sk_canvas_t* ToCanvas(SkCanvas* canvas) { |
| 110 | return reinterpret_cast<sk_canvas_t*>(canvas); |
| 111 | } |
| 112 | |
reed | 8e47478 | 2014-10-06 11:00:51 -0700 | [diff] [blame] | 113 | static SkCanvas* AsCanvas(sk_canvas_t* ccanvas) { |
| 114 | return reinterpret_cast<SkCanvas*>(ccanvas); |
| 115 | } |
| 116 | |
reed | e371989 | 2014-12-22 17:46:00 -0800 | [diff] [blame] | 117 | static SkPictureRecorder* AsPictureRecorder(sk_picture_recorder_t* crec) { |
| 118 | return reinterpret_cast<SkPictureRecorder*>(crec); |
| 119 | } |
| 120 | |
| 121 | static sk_picture_recorder_t* ToPictureRecorder(SkPictureRecorder* rec) { |
| 122 | return reinterpret_cast<sk_picture_recorder_t*>(rec); |
| 123 | } |
| 124 | |
| 125 | static const SkPicture* AsPicture(const sk_picture_t* cpic) { |
| 126 | return reinterpret_cast<const SkPicture*>(cpic); |
| 127 | } |
| 128 | |
| 129 | static SkPicture* AsPicture(sk_picture_t* cpic) { |
| 130 | return reinterpret_cast<SkPicture*>(cpic); |
| 131 | } |
| 132 | |
| 133 | static sk_picture_t* ToPicture(SkPicture* pic) { |
| 134 | return reinterpret_cast<sk_picture_t*>(pic); |
| 135 | } |
| 136 | |
reed | 8e47478 | 2014-10-06 11:00:51 -0700 | [diff] [blame] | 137 | /////////////////////////////////////////////////////////////////////////////////////////// |
| 138 | |
| 139 | sk_image_t* sk_image_new_raster_copy(const sk_imageinfo_t* cinfo, const void* pixels, |
| 140 | size_t rowBytes) { |
Mike Reed | 66c505f | 2018-09-28 11:27:57 -0400 | [diff] [blame] | 141 | const SkImageInfo* info = reinterpret_cast<const SkImageInfo*>(cinfo); |
| 142 | return (sk_image_t*)SkImage::MakeRasterCopy(SkPixmap(*info, pixels, rowBytes)).release(); |
reed | 8e47478 | 2014-10-06 11:00:51 -0700 | [diff] [blame] | 143 | } |
| 144 | |
reed | 871872f | 2015-06-22 12:48:26 -0700 | [diff] [blame] | 145 | sk_image_t* sk_image_new_from_encoded(const sk_data_t* cdata, const sk_irect_t* subset) { |
reed | 7fb4f8b | 2016-03-11 04:33:52 -0800 | [diff] [blame] | 146 | return ToImage(SkImage::MakeFromEncoded(sk_ref_sp(AsData(cdata)), |
| 147 | reinterpret_cast<const SkIRect*>(subset)).release()); |
reed | b2a5d7e | 2014-12-25 14:16:21 -0800 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | sk_data_t* sk_image_encode(const sk_image_t* cimage) { |
Mike Reed | 6409f84 | 2017-07-11 16:03:13 -0400 | [diff] [blame] | 151 | return ToData(AsImage(cimage)->encodeToData().release()); |
reed | b2a5d7e | 2014-12-25 14:16:21 -0800 | [diff] [blame] | 152 | } |
| 153 | |
reed | 8e47478 | 2014-10-06 11:00:51 -0700 | [diff] [blame] | 154 | void sk_image_ref(const sk_image_t* cimage) { |
| 155 | AsImage(cimage)->ref(); |
| 156 | } |
| 157 | |
| 158 | void sk_image_unref(const sk_image_t* cimage) { |
| 159 | AsImage(cimage)->unref(); |
| 160 | } |
| 161 | |
| 162 | int sk_image_get_width(const sk_image_t* cimage) { |
| 163 | return AsImage(cimage)->width(); |
| 164 | } |
| 165 | |
| 166 | int sk_image_get_height(const sk_image_t* cimage) { |
| 167 | return AsImage(cimage)->height(); |
| 168 | } |
| 169 | |
| 170 | uint32_t sk_image_get_unique_id(const sk_image_t* cimage) { |
| 171 | return AsImage(cimage)->uniqueID(); |
| 172 | } |
| 173 | |
| 174 | /////////////////////////////////////////////////////////////////////////////////////////// |
| 175 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 176 | sk_path_t* sk_path_new() { return (sk_path_t*)new SkPath; } |
robertphillips | a624e87 | 2014-10-08 06:04:35 -0700 | [diff] [blame] | 177 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 178 | void sk_path_delete(sk_path_t* cpath) { delete as_path(cpath); } |
robertphillips | a624e87 | 2014-10-08 06:04:35 -0700 | [diff] [blame] | 179 | |
| 180 | void sk_path_move_to(sk_path_t* cpath, float x, float y) { |
| 181 | as_path(cpath)->moveTo(x, y); |
| 182 | } |
| 183 | |
| 184 | void sk_path_line_to(sk_path_t* cpath, float x, float y) { |
| 185 | as_path(cpath)->lineTo(x, y); |
| 186 | } |
| 187 | |
| 188 | void sk_path_quad_to(sk_path_t* cpath, float x0, float y0, float x1, float y1) { |
| 189 | as_path(cpath)->quadTo(x0, y0, x1, y1); |
| 190 | } |
| 191 | |
reed | 73c2501 | 2014-11-17 06:15:42 -0800 | [diff] [blame] | 192 | void sk_path_conic_to(sk_path_t* cpath, float x0, float y0, float x1, float y1, float w) { |
| 193 | as_path(cpath)->conicTo(x0, y0, x1, y1, w); |
| 194 | } |
| 195 | |
| 196 | void sk_path_cubic_to(sk_path_t* cpath, float x0, float y0, float x1, float y1, float x2, float y2) { |
| 197 | as_path(cpath)->cubicTo(x0, y0, x1, y1, x2, y2); |
| 198 | } |
| 199 | |
robertphillips | a624e87 | 2014-10-08 06:04:35 -0700 | [diff] [blame] | 200 | void sk_path_close(sk_path_t* cpath) { |
| 201 | as_path(cpath)->close(); |
| 202 | } |
| 203 | |
reed | 73c2501 | 2014-11-17 06:15:42 -0800 | [diff] [blame] | 204 | void sk_path_add_rect(sk_path_t* cpath, const sk_rect_t* crect, sk_path_direction_t cdir) { |
| 205 | SkPath::Direction dir; |
| 206 | if (!from_c_path_direction(cdir, &dir)) { |
| 207 | return; |
| 208 | } |
| 209 | as_path(cpath)->addRect(AsRect(*crect), dir); |
| 210 | } |
| 211 | |
| 212 | void sk_path_add_oval(sk_path_t* cpath, const sk_rect_t* crect, sk_path_direction_t cdir) { |
| 213 | SkPath::Direction dir; |
| 214 | if (!from_c_path_direction(cdir, &dir)) { |
| 215 | return; |
| 216 | } |
| 217 | as_path(cpath)->addOval(AsRect(*crect), dir); |
| 218 | } |
| 219 | |
| 220 | bool sk_path_get_bounds(const sk_path_t* cpath, sk_rect_t* crect) { |
| 221 | const SkPath& path = AsPath(*cpath); |
reed | 73c2501 | 2014-11-17 06:15:42 -0800 | [diff] [blame] | 222 | |
| 223 | if (path.isEmpty()) { |
reed | e371989 | 2014-12-22 17:46:00 -0800 | [diff] [blame] | 224 | if (crect) { |
| 225 | *crect = ToRect(SkRect::MakeEmpty()); |
reed | 73c2501 | 2014-11-17 06:15:42 -0800 | [diff] [blame] | 226 | } |
| 227 | return false; |
| 228 | } |
reed | e371989 | 2014-12-22 17:46:00 -0800 | [diff] [blame] | 229 | |
| 230 | if (crect) { |
| 231 | *crect = ToRect(path.getBounds()); |
| 232 | } |
reed | 73c2501 | 2014-11-17 06:15:42 -0800 | [diff] [blame] | 233 | return true; |
| 234 | } |
| 235 | |
robertphillips | a624e87 | 2014-10-08 06:04:35 -0700 | [diff] [blame] | 236 | /////////////////////////////////////////////////////////////////////////////////////////// |
| 237 | |
reed | 938dfba | 2014-10-06 06:08:16 -0700 | [diff] [blame] | 238 | void sk_canvas_save(sk_canvas_t* ccanvas) { |
| 239 | AsCanvas(ccanvas)->save(); |
| 240 | } |
| 241 | |
| 242 | void sk_canvas_save_layer(sk_canvas_t* ccanvas, const sk_rect_t* crect, const sk_paint_t* cpaint) { |
| 243 | AsCanvas(ccanvas)->drawRect(AsRect(*crect), AsPaint(*cpaint)); |
| 244 | } |
| 245 | |
| 246 | void sk_canvas_restore(sk_canvas_t* ccanvas) { |
| 247 | AsCanvas(ccanvas)->restore(); |
| 248 | } |
| 249 | |
| 250 | void sk_canvas_translate(sk_canvas_t* ccanvas, float dx, float dy) { |
| 251 | AsCanvas(ccanvas)->translate(dx, dy); |
| 252 | } |
| 253 | |
| 254 | void sk_canvas_scale(sk_canvas_t* ccanvas, float sx, float sy) { |
reed | 8e47478 | 2014-10-06 11:00:51 -0700 | [diff] [blame] | 255 | AsCanvas(ccanvas)->scale(sx, sy); |
reed | 938dfba | 2014-10-06 06:08:16 -0700 | [diff] [blame] | 256 | } |
| 257 | |
abarth | 2fc6ea6 | 2014-12-01 14:04:03 -0800 | [diff] [blame] | 258 | void sk_canvas_rotate_degress(sk_canvas_t* ccanvas, float degrees) { |
| 259 | AsCanvas(ccanvas)->rotate(degrees); |
| 260 | } |
| 261 | |
| 262 | void sk_canvas_rotate_radians(sk_canvas_t* ccanvas, float radians) { |
| 263 | AsCanvas(ccanvas)->rotate(SkRadiansToDegrees(radians)); |
| 264 | } |
| 265 | |
| 266 | void sk_canvas_skew(sk_canvas_t* ccanvas, float sx, float sy) { |
| 267 | AsCanvas(ccanvas)->skew(sx, sy); |
| 268 | } |
| 269 | |
reed | e371989 | 2014-12-22 17:46:00 -0800 | [diff] [blame] | 270 | void sk_canvas_concat(sk_canvas_t* ccanvas, const sk_matrix_t* cmatrix) { |
abarth | 9503ac7 | 2014-12-02 15:47:33 -0800 | [diff] [blame] | 271 | SkASSERT(cmatrix); |
| 272 | SkMatrix matrix; |
| 273 | from_c_matrix(cmatrix, &matrix); |
| 274 | AsCanvas(ccanvas)->concat(matrix); |
| 275 | } |
| 276 | |
reed | e371989 | 2014-12-22 17:46:00 -0800 | [diff] [blame] | 277 | void sk_canvas_clip_rect(sk_canvas_t* ccanvas, const sk_rect_t* crect) { |
| 278 | AsCanvas(ccanvas)->clipRect(AsRect(*crect)); |
| 279 | } |
| 280 | |
| 281 | void sk_canvas_clip_path(sk_canvas_t* ccanvas, const sk_path_t* cpath) { |
| 282 | AsCanvas(ccanvas)->clipPath(AsPath(*cpath)); |
| 283 | } |
| 284 | |
reed | 938dfba | 2014-10-06 06:08:16 -0700 | [diff] [blame] | 285 | void sk_canvas_draw_paint(sk_canvas_t* ccanvas, const sk_paint_t* cpaint) { |
| 286 | AsCanvas(ccanvas)->drawPaint(AsPaint(*cpaint)); |
| 287 | } |
| 288 | |
| 289 | void sk_canvas_draw_rect(sk_canvas_t* ccanvas, const sk_rect_t* crect, const sk_paint_t* cpaint) { |
| 290 | AsCanvas(ccanvas)->drawRect(AsRect(*crect), AsPaint(*cpaint)); |
| 291 | } |
| 292 | |
reed | 4a7940b | 2016-02-09 13:25:51 -0800 | [diff] [blame] | 293 | void sk_canvas_draw_circle(sk_canvas_t* ccanvas, float cx, float cy, float rad, |
| 294 | const sk_paint_t* cpaint) { |
| 295 | AsCanvas(ccanvas)->drawCircle(cx, cy, rad, AsPaint(*cpaint)); |
| 296 | } |
| 297 | |
reed | 938dfba | 2014-10-06 06:08:16 -0700 | [diff] [blame] | 298 | void sk_canvas_draw_oval(sk_canvas_t* ccanvas, const sk_rect_t* crect, const sk_paint_t* cpaint) { |
| 299 | AsCanvas(ccanvas)->drawOval(AsRect(*crect), AsPaint(*cpaint)); |
| 300 | } |
| 301 | |
| 302 | void sk_canvas_draw_path(sk_canvas_t* ccanvas, const sk_path_t* cpath, const sk_paint_t* cpaint) { |
| 303 | AsCanvas(ccanvas)->drawPath(AsPath(*cpath), AsPaint(*cpaint)); |
| 304 | } |
| 305 | |
| 306 | void sk_canvas_draw_image(sk_canvas_t* ccanvas, const sk_image_t* cimage, float x, float y, |
| 307 | const sk_paint_t* cpaint) { |
| 308 | AsCanvas(ccanvas)->drawImage(AsImage(cimage), x, y, AsPaint(cpaint)); |
| 309 | } |
| 310 | |
reed | e371989 | 2014-12-22 17:46:00 -0800 | [diff] [blame] | 311 | void sk_canvas_draw_image_rect(sk_canvas_t* ccanvas, const sk_image_t* cimage, |
| 312 | const sk_rect_t* csrcR, const sk_rect_t* cdstR, |
| 313 | const sk_paint_t* cpaint) { |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 314 | SkCanvas* canvas = AsCanvas(ccanvas); |
| 315 | const SkImage* image = AsImage(cimage); |
| 316 | const SkRect& dst = AsRect(*cdstR); |
| 317 | const SkPaint* paint = AsPaint(cpaint); |
| 318 | |
| 319 | if (csrcR) { |
| 320 | canvas->drawImageRect(image, AsRect(*csrcR), dst, paint); |
| 321 | } else { |
| 322 | canvas->drawImageRect(image, dst, paint); |
| 323 | } |
reed | e371989 | 2014-12-22 17:46:00 -0800 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | void sk_canvas_draw_picture(sk_canvas_t* ccanvas, const sk_picture_t* cpicture, |
| 327 | const sk_matrix_t* cmatrix, const sk_paint_t* cpaint) { |
| 328 | const SkMatrix* matrixPtr = NULL; |
| 329 | SkMatrix matrix; |
| 330 | if (cmatrix) { |
| 331 | from_c_matrix(cmatrix, &matrix); |
| 332 | matrixPtr = &matrix; |
| 333 | } |
| 334 | AsCanvas(ccanvas)->drawPicture(AsPicture(cpicture), matrixPtr, AsPaint(cpaint)); |
| 335 | } |
| 336 | |
reed | 938dfba | 2014-10-06 06:08:16 -0700 | [diff] [blame] | 337 | /////////////////////////////////////////////////////////////////////////////////////////// |
| 338 | |
robertphillips | 702edbd | 2015-06-23 06:26:08 -0700 | [diff] [blame] | 339 | sk_surface_t* sk_surface_new_raster(const sk_imageinfo_t* cinfo, |
| 340 | const sk_surfaceprops_t* props) { |
Mike Reed | 66c505f | 2018-09-28 11:27:57 -0400 | [diff] [blame] | 341 | const SkImageInfo* info = reinterpret_cast<const SkImageInfo*>(cinfo); |
robertphillips | 702edbd | 2015-06-23 06:26:08 -0700 | [diff] [blame] | 342 | SkPixelGeometry geo = kUnknown_SkPixelGeometry; |
| 343 | if (props && !from_c_pixelgeometry(props->pixelGeometry, &geo)) { |
| 344 | return NULL; |
| 345 | } |
| 346 | |
| 347 | SkSurfaceProps surfProps(0, geo); |
Mike Reed | 66c505f | 2018-09-28 11:27:57 -0400 | [diff] [blame] | 348 | return (sk_surface_t*)SkSurface::MakeRaster(*info, &surfProps).release(); |
reed | 938dfba | 2014-10-06 06:08:16 -0700 | [diff] [blame] | 349 | } |
| 350 | |
reed | 8e47478 | 2014-10-06 11:00:51 -0700 | [diff] [blame] | 351 | sk_surface_t* sk_surface_new_raster_direct(const sk_imageinfo_t* cinfo, void* pixels, |
robertphillips | 702edbd | 2015-06-23 06:26:08 -0700 | [diff] [blame] | 352 | size_t rowBytes, |
| 353 | const sk_surfaceprops_t* props) { |
Mike Reed | 66c505f | 2018-09-28 11:27:57 -0400 | [diff] [blame] | 354 | const SkImageInfo* info = reinterpret_cast<const SkImageInfo*>(cinfo); |
robertphillips | 702edbd | 2015-06-23 06:26:08 -0700 | [diff] [blame] | 355 | SkPixelGeometry geo = kUnknown_SkPixelGeometry; |
| 356 | if (props && !from_c_pixelgeometry(props->pixelGeometry, &geo)) { |
| 357 | return NULL; |
| 358 | } |
| 359 | |
| 360 | SkSurfaceProps surfProps(0, geo); |
Mike Reed | 66c505f | 2018-09-28 11:27:57 -0400 | [diff] [blame] | 361 | return (sk_surface_t*)SkSurface::MakeRasterDirect(*info, pixels, rowBytes, &surfProps).release(); |
reed | 938dfba | 2014-10-06 06:08:16 -0700 | [diff] [blame] | 362 | } |
| 363 | |
reed | afa278e | 2014-11-24 19:11:48 -0800 | [diff] [blame] | 364 | void sk_surface_unref(sk_surface_t* csurf) { |
| 365 | SkSafeUnref((SkSurface*)csurf); |
reed | 938dfba | 2014-10-06 06:08:16 -0700 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | sk_canvas_t* sk_surface_get_canvas(sk_surface_t* csurf) { |
| 369 | SkSurface* surf = (SkSurface*)csurf; |
reed | 8e47478 | 2014-10-06 11:00:51 -0700 | [diff] [blame] | 370 | return (sk_canvas_t*)surf->getCanvas(); |
reed | 938dfba | 2014-10-06 06:08:16 -0700 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | sk_image_t* sk_surface_new_image_snapshot(sk_surface_t* csurf) { |
| 374 | SkSurface* surf = (SkSurface*)csurf; |
reed | 9ce9d67 | 2016-03-17 10:51:11 -0700 | [diff] [blame] | 375 | return (sk_image_t*)surf->makeImageSnapshot().release(); |
reed | 938dfba | 2014-10-06 06:08:16 -0700 | [diff] [blame] | 376 | } |
| 377 | |
reed | afa278e | 2014-11-24 19:11:48 -0800 | [diff] [blame] | 378 | /////////////////////////////////////////////////////////////////////////////////////////// |
reed | 938dfba | 2014-10-06 06:08:16 -0700 | [diff] [blame] | 379 | |
reed | e371989 | 2014-12-22 17:46:00 -0800 | [diff] [blame] | 380 | sk_picture_recorder_t* sk_picture_recorder_new() { |
| 381 | return ToPictureRecorder(new SkPictureRecorder); |
| 382 | } |
| 383 | |
| 384 | void sk_picture_recorder_delete(sk_picture_recorder_t* crec) { |
| 385 | delete AsPictureRecorder(crec); |
| 386 | } |
| 387 | |
| 388 | sk_canvas_t* sk_picture_recorder_begin_recording(sk_picture_recorder_t* crec, |
| 389 | const sk_rect_t* cbounds) { |
| 390 | return ToCanvas(AsPictureRecorder(crec)->beginRecording(AsRect(*cbounds))); |
| 391 | } |
| 392 | |
| 393 | sk_picture_t* sk_picture_recorder_end_recording(sk_picture_recorder_t* crec) { |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 394 | return ToPicture(AsPictureRecorder(crec)->finishRecordingAsPicture().release()); |
reed | e371989 | 2014-12-22 17:46:00 -0800 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | void sk_picture_ref(sk_picture_t* cpic) { |
| 398 | SkSafeRef(AsPicture(cpic)); |
| 399 | } |
| 400 | |
| 401 | void sk_picture_unref(sk_picture_t* cpic) { |
| 402 | SkSafeUnref(AsPicture(cpic)); |
| 403 | } |
| 404 | |
| 405 | uint32_t sk_picture_get_unique_id(sk_picture_t* cpic) { |
| 406 | return AsPicture(cpic)->uniqueID(); |
| 407 | } |
| 408 | |
| 409 | sk_rect_t sk_picture_get_bounds(sk_picture_t* cpic) { |
| 410 | return ToRect(AsPicture(cpic)->cullRect()); |
| 411 | } |
| 412 | |
| 413 | /////////////////////////////////////////////////////////////////////////////////////////// |
| 414 | |
reed | b2a5d7e | 2014-12-25 14:16:21 -0800 | [diff] [blame] | 415 | sk_data_t* sk_data_new_with_copy(const void* src, size_t length) { |
reed | fde0511 | 2016-03-11 13:02:28 -0800 | [diff] [blame] | 416 | return ToData(SkData::MakeWithCopy(src, length).release()); |
reed | b2a5d7e | 2014-12-25 14:16:21 -0800 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | sk_data_t* sk_data_new_from_malloc(const void* memory, size_t length) { |
reed | fde0511 | 2016-03-11 13:02:28 -0800 | [diff] [blame] | 420 | return ToData(SkData::MakeFromMalloc(memory, length).release()); |
reed | b2a5d7e | 2014-12-25 14:16:21 -0800 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | sk_data_t* sk_data_new_subset(const sk_data_t* csrc, size_t offset, size_t length) { |
reed | fde0511 | 2016-03-11 13:02:28 -0800 | [diff] [blame] | 424 | return ToData(SkData::MakeSubset(AsData(csrc), offset, length).release()); |
reed | b2a5d7e | 2014-12-25 14:16:21 -0800 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | void sk_data_ref(const sk_data_t* cdata) { |
| 428 | SkSafeRef(AsData(cdata)); |
| 429 | } |
| 430 | |
| 431 | void sk_data_unref(const sk_data_t* cdata) { |
| 432 | SkSafeUnref(AsData(cdata)); |
| 433 | } |
| 434 | |
| 435 | size_t sk_data_get_size(const sk_data_t* cdata) { |
| 436 | return AsData(cdata)->size(); |
| 437 | } |
| 438 | |
| 439 | const void* sk_data_get_data(const sk_data_t* cdata) { |
| 440 | return AsData(cdata)->data(); |
| 441 | } |
| 442 | |
| 443 | /////////////////////////////////////////////////////////////////////////////////////////// |