From 219f18f30df465beeee8114febe52fa50454a804 Mon Sep 17 00:00:00 2001 From: halcanary Date: Tue, 1 Sep 2015 10:01:38 -0700 Subject: C API: Add SK_API, also documentation of an example. SK_API = __declspec(dllexport) / __attribute__((visibility("default"))) Also, add documentation in experimental/c-api-example/c.md Review URL: https://codereview.chromium.org/1307183006 --- include/c/sk_canvas.h | 47 +++++++++++++++++++++++++---------------------- include/c/sk_data.h | 16 ++++++++-------- include/c/sk_image.h | 16 ++++++++-------- include/c/sk_paint.h | 38 +++++++++++++++++++------------------- include/c/sk_path.h | 29 ++++++++++++++++------------- include/c/sk_surface.h | 13 +++++++------ include/c/sk_types.h | 6 +++++- 7 files changed, 88 insertions(+), 77 deletions(-) (limited to 'include/c') diff --git a/include/c/sk_canvas.h b/include/c/sk_canvas.h index 9eb21f3a61..f65d3aa5c9 100644 --- a/include/c/sk_canvas.h +++ b/include/c/sk_canvas.h @@ -15,28 +15,31 @@ SK_C_PLUS_PLUS_BEGIN_GUARD -void sk_canvas_save(sk_canvas_t*); -void sk_canvas_save_layer(sk_canvas_t*, const sk_rect_t*, const sk_paint_t*); -void sk_canvas_restore(sk_canvas_t*); - -void sk_canvas_translate(sk_canvas_t*, float dx, float dy); -void sk_canvas_scale(sk_canvas_t*, float sx, float sy); -void sk_canvas_rotate_degrees(sk_canvas_t*, float degrees); -void sk_canvas_rotate_radians(sk_canvas_t*, float radians); -void sk_canvas_skew(sk_canvas_t*, float sx, float sy); -void sk_canvas_concat(sk_canvas_t*, const sk_matrix_t*); - -void sk_canvas_clip_rect(sk_canvas_t*, const sk_rect_t*); -void sk_canvas_clip_path(sk_canvas_t*, const sk_path_t*); - -void sk_canvas_draw_paint(sk_canvas_t*, const sk_paint_t*); -void sk_canvas_draw_rect(sk_canvas_t*, const sk_rect_t*, const sk_paint_t*); -void sk_canvas_draw_oval(sk_canvas_t*, const sk_rect_t*, const sk_paint_t*); -void sk_canvas_draw_path(sk_canvas_t*, const sk_path_t*, const sk_paint_t*); -void sk_canvas_draw_image(sk_canvas_t*, const sk_image_t*, float x, float y, const sk_paint_t*); -void sk_canvas_draw_image_rect(sk_canvas_t*, const sk_image_t*, const sk_rect_t* src, - const sk_rect_t* dst, const sk_paint_t*); -void sk_canvas_draw_picture(sk_canvas_t*, const sk_picture_t*, const sk_matrix_t*, const sk_paint_t*); +SK_API void sk_canvas_save(sk_canvas_t*); +SK_API void sk_canvas_save_layer(sk_canvas_t*, const sk_rect_t*, const sk_paint_t*); +SK_API void sk_canvas_restore(sk_canvas_t*); + +SK_API void sk_canvas_translate(sk_canvas_t*, float dx, float dy); +SK_API void sk_canvas_scale(sk_canvas_t*, float sx, float sy); +SK_API void sk_canvas_rotate_degrees(sk_canvas_t*, float degrees); +SK_API void sk_canvas_rotate_radians(sk_canvas_t*, float radians); +SK_API void sk_canvas_skew(sk_canvas_t*, float sx, float sy); +SK_API void sk_canvas_concat(sk_canvas_t*, const sk_matrix_t*); + +SK_API void sk_canvas_clip_rect(sk_canvas_t*, const sk_rect_t*); +SK_API void sk_canvas_clip_path(sk_canvas_t*, const sk_path_t*); + +SK_API void sk_canvas_draw_paint(sk_canvas_t*, const sk_paint_t*); +SK_API void sk_canvas_draw_rect(sk_canvas_t*, const sk_rect_t*, const sk_paint_t*); +SK_API void sk_canvas_draw_oval(sk_canvas_t*, const sk_rect_t*, const sk_paint_t*); +SK_API void sk_canvas_draw_path(sk_canvas_t*, const sk_path_t*, const sk_paint_t*); +SK_API void sk_canvas_draw_image(sk_canvas_t*, const sk_image_t*, + float x, float y, const sk_paint_t*); +SK_API void sk_canvas_draw_image_rect(sk_canvas_t*, const sk_image_t*, + const sk_rect_t* src, + const sk_rect_t* dst, const sk_paint_t*); +SK_API void sk_canvas_draw_picture(sk_canvas_t*, const sk_picture_t*, + const sk_matrix_t*, const sk_paint_t*); SK_C_PLUS_PLUS_END_GUARD diff --git a/include/c/sk_data.h b/include/c/sk_data.h index 90863ee889..95b7f5eb0b 100644 --- a/include/c/sk_data.h +++ b/include/c/sk_data.h @@ -15,16 +15,16 @@ SK_C_PLUS_PLUS_BEGIN_GUARD -sk_data_t* sk_data_new_empty(); -sk_data_t* sk_data_new_with_copy(const void* src, size_t length); -sk_data_t* sk_data_new_from_malloc(const void* memory, size_t length); -sk_data_t* sk_data_new_subset(const sk_data_t* src, size_t offset, size_t length); +SK_API sk_data_t* sk_data_new_empty(); +SK_API sk_data_t* sk_data_new_with_copy(const void* src, size_t length); +SK_API sk_data_t* sk_data_new_from_malloc(const void* memory, size_t length); +SK_API sk_data_t* sk_data_new_subset(const sk_data_t* src, size_t offset, size_t length); -void sk_data_ref(const sk_data_t*); -void sk_data_unref(const sk_data_t*); +SK_API void sk_data_ref(const sk_data_t*); +SK_API void sk_data_unref(const sk_data_t*); -size_t sk_data_get_size(const sk_data_t*); -const void* sk_data_get_data(const sk_data_t*); +SK_API size_t sk_data_get_size(const sk_data_t*); +SK_API const void* sk_data_get_data(const sk_data_t*); SK_C_PLUS_PLUS_END_GUARD diff --git a/include/c/sk_image.h b/include/c/sk_image.h index c9973ac125..e6f49b74ee 100644 --- a/include/c/sk_image.h +++ b/include/c/sk_image.h @@ -19,7 +19,7 @@ SK_C_PLUS_PLUS_BEGIN_GUARD * Return a new image that has made a copy of the provided pixels, or NULL on failure. * Balance with a call to sk_image_unref(). */ -sk_image_t* sk_image_new_raster_copy(const sk_imageinfo_t*, const void* pixels, size_t rowBytes); +SK_API sk_image_t* sk_image_new_raster_copy(const sk_imageinfo_t*, const void* pixels, size_t rowBytes); /** * If the specified data can be interpreted as a compressed image (e.g. PNG or JPEG) then this @@ -28,15 +28,15 @@ sk_image_t* sk_image_new_raster_copy(const sk_imageinfo_t*, const void* pixels, * On success, the encoded data may be processed immediately, or it may be ref()'d for later * use. */ -sk_image_t* sk_image_new_from_encoded(const sk_data_t* encoded, const sk_irect_t* subset); +SK_API sk_image_t* sk_image_new_from_encoded(const sk_data_t* encoded, const sk_irect_t* subset); -sk_data_t* sk_image_encode(const sk_image_t*); +SK_API sk_data_t* sk_image_encode(const sk_image_t*); -void sk_image_ref(const sk_image_t*); -void sk_image_unref(const sk_image_t*); -int sk_image_get_width(const sk_image_t*); -int sk_image_get_height(const sk_image_t*); -uint32_t sk_image_get_unique_id(const sk_image_t*); +SK_API void sk_image_ref(const sk_image_t*); +SK_API void sk_image_unref(const sk_image_t*); +SK_API int sk_image_get_width(const sk_image_t*); +SK_API int sk_image_get_height(const sk_image_t*); +SK_API uint32_t sk_image_get_unique_id(const sk_image_t*); SK_C_PLUS_PLUS_END_GUARD diff --git a/include/c/sk_paint.h b/include/c/sk_paint.h index 382438051b..6699fb4f6f 100644 --- a/include/c/sk_paint.h +++ b/include/c/sk_paint.h @@ -15,25 +15,25 @@ SK_C_PLUS_PLUS_BEGIN_GUARD -sk_paint_t* sk_paint_new(); -void sk_paint_delete(sk_paint_t*); +SK_API sk_paint_t* sk_paint_new(); +SK_API void sk_paint_delete(sk_paint_t*); -bool sk_paint_is_antialias(const sk_paint_t*); -void sk_paint_set_antialias(sk_paint_t*, bool); +SK_API bool sk_paint_is_antialias(const sk_paint_t*); +SK_API void sk_paint_set_antialias(sk_paint_t*, bool); -sk_color_t sk_paint_get_color(const sk_paint_t*); -void sk_paint_set_color(sk_paint_t*, sk_color_t); +SK_API sk_color_t sk_paint_get_color(const sk_paint_t*); +SK_API void sk_paint_set_color(sk_paint_t*, sk_color_t); /* stroke settings */ -bool sk_paint_is_stroke(const sk_paint_t*); -void sk_paint_set_stroke(sk_paint_t*, bool); +SK_API bool sk_paint_is_stroke(const sk_paint_t*); +SK_API void sk_paint_set_stroke(sk_paint_t*, bool); -float sk_paint_get_stroke_width(const sk_paint_t*); -void sk_paint_set_stroke_width(sk_paint_t*, float width); +SK_API float sk_paint_get_stroke_width(const sk_paint_t*); +SK_API void sk_paint_set_stroke_width(sk_paint_t*, float width); -float sk_paint_get_stroke_miter(const sk_paint_t*); -void sk_paint_set_stroke_miter(sk_paint_t*, float miter); +SK_API float sk_paint_get_stroke_miter(const sk_paint_t*); +SK_API void sk_paint_set_stroke_miter(sk_paint_t*, float miter); typedef enum { BUTT_SK_STROKE_CAP, @@ -41,8 +41,8 @@ typedef enum { SQUARE_SK_STROKE_CAP } sk_stroke_cap_t; -sk_stroke_cap_t sk_paint_get_stroke_cap(const sk_paint_t*); -void sk_paint_set_stroke_cap(sk_paint_t*, sk_stroke_cap_t); +SK_API sk_stroke_cap_t sk_paint_get_stroke_cap(const sk_paint_t*); +SK_API void sk_paint_set_stroke_cap(sk_paint_t*, sk_stroke_cap_t); typedef enum { MITER_SK_STROKE_JOIN, @@ -50,25 +50,25 @@ typedef enum { BEVEL_SK_STROKE_JOIN } sk_stroke_join_t; -sk_stroke_join_t sk_paint_get_stroke_join(const sk_paint_t*); -void sk_paint_set_stroke_join(sk_paint_t*, sk_stroke_join_t); +SK_API sk_stroke_join_t sk_paint_get_stroke_join(const sk_paint_t*); +SK_API void sk_paint_set_stroke_join(sk_paint_t*, sk_stroke_join_t); /** * Set the paint's shader to the specified parameter. This will automatically call unref() on * any previous value, and call ref() on the new value. */ -void sk_paint_set_shader(sk_paint_t*, sk_shader_t*); +SK_API void sk_paint_set_shader(sk_paint_t*, sk_shader_t*); /** * Set the paint's maskfilter to the specified parameter. This will automatically call unref() on * any previous value, and call ref() on the new value. */ -void sk_paint_set_maskfilter(sk_paint_t*, sk_maskfilter_t*); +SK_API void sk_paint_set_maskfilter(sk_paint_t*, sk_maskfilter_t*); /** * Set the paint's xfermode to the specified parameter. */ -void sk_paint_set_xfermode_mode(sk_paint_t*, sk_xfermode_mode_t); +SK_API void sk_paint_set_xfermode_mode(sk_paint_t*, sk_xfermode_mode_t); SK_C_PLUS_PLUS_END_GUARD diff --git a/include/c/sk_path.h b/include/c/sk_path.h index 801e1480f9..d13a11219f 100644 --- a/include/c/sk_path.h +++ b/include/c/sk_path.h @@ -20,25 +20,28 @@ typedef enum { CCW_SK_PATH_DIRECTION, } sk_path_direction_t; -sk_path_t* sk_path_new(); -void sk_path_delete(sk_path_t*); - -void sk_path_move_to(sk_path_t*, float x, float y); -void sk_path_line_to(sk_path_t*, float x, float y); -void sk_path_quad_to(sk_path_t*, float x0, float y0, float x1, float y1); -void sk_path_conic_to(sk_path_t*, float x0, float y0, float x1, float y1, float w); -void sk_path_cubic_to(sk_path_t*, float x0, float y0, float x1, float y1, float x2, float y2); -void sk_path_close(sk_path_t*); - -void sk_path_add_rect(sk_path_t*, const sk_rect_t*, sk_path_direction_t); -void sk_path_add_oval(sk_path_t*, const sk_rect_t*, sk_path_direction_t); +SK_API sk_path_t* sk_path_new(); +SK_API void sk_path_delete(sk_path_t*); + +SK_API void sk_path_move_to(sk_path_t*, float x, float y); +SK_API void sk_path_line_to(sk_path_t*, float x, float y); +SK_API void sk_path_quad_to(sk_path_t*, float x0, float y0, float x1, float y1); +SK_API void sk_path_conic_to(sk_path_t*, float x0, float y0, float x1, float y1, float w); +SK_API void sk_path_cubic_to(sk_path_t*, + float x0, float y0, + float x1, float y1, + float x2, float y2); +SK_API void sk_path_close(sk_path_t*); + +SK_API void sk_path_add_rect(sk_path_t*, const sk_rect_t*, sk_path_direction_t); +SK_API void sk_path_add_oval(sk_path_t*, const sk_rect_t*, sk_path_direction_t); /** * If the path is empty, return false and set the rect parameter to [0, 0, 0, 0]. * else return true and set the rect parameter to the bounds of the control-points * of the path. */ -bool sk_path_get_bounds(const sk_path_t*, sk_rect_t*); +SK_API bool sk_path_get_bounds(const sk_path_t*, sk_rect_t*); SK_C_PLUS_PLUS_END_GUARD diff --git a/include/c/sk_surface.h b/include/c/sk_surface.h index 397dc833c2..f3c17d075d 100644 --- a/include/c/sk_surface.h +++ b/include/c/sk_surface.h @@ -15,21 +15,22 @@ SK_C_PLUS_PLUS_BEGIN_GUARD -sk_surface_t* sk_surface_new_raster(const sk_imageinfo_t*, const sk_surfaceprops_t*); -sk_surface_t* sk_surface_new_raster_direct(const sk_imageinfo_t*, void* pixels, size_t rowBytes, - const sk_surfaceprops_t* props); -void sk_surface_unref(sk_surface_t*); +SK_API sk_surface_t* sk_surface_new_raster(const sk_imageinfo_t*, const sk_surfaceprops_t*); +SK_API sk_surface_t* sk_surface_new_raster_direct(const sk_imageinfo_t*, + void* pixels, size_t rowBytes, + const sk_surfaceprops_t* props); +SK_API void sk_surface_unref(sk_surface_t*); /** * Return the canvas associated with this surface. Note: the canvas is owned by the surface, * so the returned object is only valid while the owning surface is valid. */ -sk_canvas_t* sk_surface_get_canvas(sk_surface_t*); +SK_API sk_canvas_t* sk_surface_get_canvas(sk_surface_t*); /** * Call sk_image_unref() when the returned image is no longer used. */ -sk_image_t* sk_surface_new_image_snapshot(sk_surface_t*); +SK_API sk_image_t* sk_surface_new_image_snapshot(sk_surface_t*); SK_C_PLUS_PLUS_END_GUARD diff --git a/include/c/sk_types.h b/include/c/sk_types.h index 87cc0555bd..f6d73df94d 100644 --- a/include/c/sk_types.h +++ b/include/c/sk_types.h @@ -23,6 +23,10 @@ #define SK_C_PLUS_PLUS_END_GUARD #endif +#ifndef SK_API +#define SK_API +#endif + /////////////////////////////////////////////////////////////////////////////////////// SK_C_PLUS_PLUS_BEGIN_GUARD @@ -61,7 +65,7 @@ typedef enum { BGR_V_SK_PIXELGEOMETRY, } sk_pixelgeometry_t; -sk_colortype_t sk_colortype_get_default_8888(); +SK_API sk_colortype_t sk_colortype_get_default_8888(); typedef struct { int32_t width; -- cgit v1.2.3