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 | */ |
reed | 938dfba | 2014-10-06 06:08:16 -0700 | [diff] [blame] | 7 | |
reed | 8e47478 | 2014-10-06 11:00:51 -0700 | [diff] [blame] | 8 | #ifndef sk_types_DEFINED |
| 9 | #define sk_types_DEFINED |
| 10 | |
| 11 | #include <stdint.h> |
| 12 | #include <stddef.h> |
| 13 | |
| 14 | #ifdef __cplusplus |
| 15 | extern "C" { |
| 16 | #endif |
reed | 938dfba | 2014-10-06 06:08:16 -0700 | [diff] [blame] | 17 | |
| 18 | typedef uint32_t sk_color_t; |
| 19 | |
reed | 8e47478 | 2014-10-06 11:00:51 -0700 | [diff] [blame] | 20 | #define sk_color_set_argb(a, r, g, b) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b)) |
| 21 | #define sk_color_get_a(c) (((c) >> 24) & 0xFF) |
| 22 | #define sk_color_get_r(c) (((c) >> 16) & 0xFF) |
| 23 | #define sk_color_get_g(c) (((c) >> 8) & 0xFF) |
| 24 | #define sk_color_get_b(c) (((c) >> 0) & 0xFF) |
reed | 938dfba | 2014-10-06 06:08:16 -0700 | [diff] [blame] | 25 | |
| 26 | typedef enum { |
| 27 | UNKNOWN_SK_COLORTYPE, |
| 28 | RGBA_8888_SK_COLORTYPE, |
| 29 | BGRA_8888_SK_COLORTYPE, |
| 30 | ALPHA_8_SK_COLORTYPE, |
| 31 | } sk_colortype_t; |
| 32 | |
reed | 8e47478 | 2014-10-06 11:00:51 -0700 | [diff] [blame] | 33 | typedef enum { |
| 34 | PREMUL_SK_ALPHATYPE, |
| 35 | UNPREMUL_SK_ALPHATYPE, |
| 36 | } sk_alphatype_t; |
| 37 | |
| 38 | typedef struct { |
reed | 938dfba | 2014-10-06 06:08:16 -0700 | [diff] [blame] | 39 | int32_t width; |
| 40 | int32_t height; |
| 41 | sk_colortype_t colorType; |
reed | 8e47478 | 2014-10-06 11:00:51 -0700 | [diff] [blame] | 42 | sk_alphatype_t alphaType; |
| 43 | } sk_imageinfo_t; |
reed | 938dfba | 2014-10-06 06:08:16 -0700 | [diff] [blame] | 44 | |
reed | 8e47478 | 2014-10-06 11:00:51 -0700 | [diff] [blame] | 45 | typedef struct { |
reed | 938dfba | 2014-10-06 06:08:16 -0700 | [diff] [blame] | 46 | float left; |
| 47 | float top; |
| 48 | float right; |
| 49 | float bottom; |
reed | 8e47478 | 2014-10-06 11:00:51 -0700 | [diff] [blame] | 50 | } sk_rect_t; |
reed | 938dfba | 2014-10-06 06:08:16 -0700 | [diff] [blame] | 51 | |
reed | 8e47478 | 2014-10-06 11:00:51 -0700 | [diff] [blame] | 52 | typedef struct sk_path_t sk_path_t; |
reed | 938dfba | 2014-10-06 06:08:16 -0700 | [diff] [blame] | 53 | |
| 54 | sk_path_t* sk_path_new(); |
robertphillips | a624e87 | 2014-10-08 06:04:35 -0700 | [diff] [blame] | 55 | void sk_path_delete(sk_path_t*); |
reed | 8e47478 | 2014-10-06 11:00:51 -0700 | [diff] [blame] | 56 | void sk_path_move_to(sk_path_t*, float x, float y); |
| 57 | void sk_path_line_to(sk_path_t*, float x, float y); |
| 58 | void sk_path_quad_to(sk_path_t*, float x0, float y0, float x1, float y1); |
robertphillips | a624e87 | 2014-10-08 06:04:35 -0700 | [diff] [blame] | 59 | void sk_path_close(sk_path_t*); |
reed | 938dfba | 2014-10-06 06:08:16 -0700 | [diff] [blame] | 60 | |
reed | 8e47478 | 2014-10-06 11:00:51 -0700 | [diff] [blame] | 61 | typedef struct sk_paint_t sk_paint_t; |
reed | 938dfba | 2014-10-06 06:08:16 -0700 | [diff] [blame] | 62 | |
| 63 | sk_paint_t* sk_paint_new(); |
reed | 8e47478 | 2014-10-06 11:00:51 -0700 | [diff] [blame] | 64 | void sk_paint_delete(sk_paint_t*); |
robertphillips | a624e87 | 2014-10-08 06:04:35 -0700 | [diff] [blame] | 65 | bool sk_paint_is_antialias(const sk_paint_t*); |
reed | 938dfba | 2014-10-06 06:08:16 -0700 | [diff] [blame] | 66 | void sk_paint_set_antialias(sk_paint_t*, bool); |
| 67 | sk_color_t sk_paint_get_color(const sk_paint_t*); |
| 68 | void sk_paint_set_color(sk_paint_t*, sk_color_t); |
| 69 | |
reed | 8e47478 | 2014-10-06 11:00:51 -0700 | [diff] [blame] | 70 | typedef struct sk_canvas_t sk_canvas_t; |
| 71 | typedef struct sk_image_t sk_image_t; |
reed | 938dfba | 2014-10-06 06:08:16 -0700 | [diff] [blame] | 72 | |
| 73 | void sk_canvas_save(sk_canvas_t*); |
| 74 | void sk_canvas_save_layer(sk_canvas_t*, const sk_rect_t*, const sk_paint_t*); |
| 75 | void sk_canvas_restore(sk_canvas_t*); |
| 76 | |
reed | 8e47478 | 2014-10-06 11:00:51 -0700 | [diff] [blame] | 77 | void sk_canvas_translate(sk_canvas_t*, float dx, float dy); |
| 78 | void sk_canvas_scale(sk_canvas_t*, float sx, float sy); |
reed | 938dfba | 2014-10-06 06:08:16 -0700 | [diff] [blame] | 79 | |
| 80 | void sk_canvas_draw_paint(sk_canvas_t*, const sk_paint_t*); |
| 81 | void sk_canvas_draw_rect(sk_canvas_t*, const sk_rect_t*, const sk_paint_t*); |
| 82 | void sk_canvas_draw_oval(sk_canvas_t*, const sk_rect_t*, const sk_paint_t*); |
| 83 | void sk_canvas_draw_path(sk_canvas_t*, const sk_path_t*, const sk_paint_t*); |
| 84 | void sk_canvas_draw_image(sk_canvas_t*, const sk_image_t*, float x, float y, const sk_paint_t*); |
| 85 | |
reed | 8e47478 | 2014-10-06 11:00:51 -0700 | [diff] [blame] | 86 | sk_image_t* sk_image_new_raster_copy(const sk_imageinfo_t*, const void* pixels, size_t rowBytes); |
| 87 | void sk_image_ref(const sk_image_t*); |
| 88 | void sk_image_unref(const sk_image_t*); |
reed | 938dfba | 2014-10-06 06:08:16 -0700 | [diff] [blame] | 89 | int sk_image_get_width(const sk_image_t*); |
| 90 | int sk_image_get_height(const sk_image_t*); |
| 91 | uint32_t sk_image_get_unique_id(const sk_image_t*); |
| 92 | |
reed | 8e47478 | 2014-10-06 11:00:51 -0700 | [diff] [blame] | 93 | typedef struct sk_surface_t sk_surface_t; |
reed | 938dfba | 2014-10-06 06:08:16 -0700 | [diff] [blame] | 94 | |
reed | 8e47478 | 2014-10-06 11:00:51 -0700 | [diff] [blame] | 95 | sk_surface_t* sk_surface_new_raster(const sk_imageinfo_t*); |
| 96 | sk_surface_t* sk_surface_new_raster_direct(const sk_imageinfo_t*, void* pixels, size_t rowBytes); |
reed | 938dfba | 2014-10-06 06:08:16 -0700 | [diff] [blame] | 97 | void sk_surface_delete(sk_surface_t*); |
reed | 938dfba | 2014-10-06 06:08:16 -0700 | [diff] [blame] | 98 | sk_canvas_t* sk_surface_get_canvas(sk_surface_t*); |
| 99 | sk_image_t* sk_surface_new_image_snapshot(sk_surface_t*); |
| 100 | |
reed | 8e47478 | 2014-10-06 11:00:51 -0700 | [diff] [blame] | 101 | #ifdef __cplusplus |
| 102 | class SkCanvas; |
| 103 | void sk_test_capi(SkCanvas*); |
| 104 | } |
| 105 | #endif |
| 106 | |
| 107 | #endif |