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