blob: e170049a4bdef0e9a22e093eefb72b1e3f2de9ce [file] [log] [blame]
reed8e474782014-10-06 11:00:51 -07001/*
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 */
reed938dfba2014-10-06 06:08:16 -07007
reed8e474782014-10-06 11:00:51 -07008#ifndef sk_types_DEFINED
9#define sk_types_DEFINED
10
11#include <stdint.h>
12#include <stddef.h>
13
14#ifdef __cplusplus
15extern "C" {
16#endif
reed938dfba2014-10-06 06:08:16 -070017
18typedef uint32_t sk_color_t;
19
reed8e474782014-10-06 11:00:51 -070020#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)
reed938dfba2014-10-06 06:08:16 -070025
26typedef 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
reed8e474782014-10-06 11:00:51 -070033typedef enum {
34 PREMUL_SK_ALPHATYPE,
35 UNPREMUL_SK_ALPHATYPE,
36} sk_alphatype_t;
37
38typedef struct {
reed938dfba2014-10-06 06:08:16 -070039 int32_t width;
40 int32_t height;
41 sk_colortype_t colorType;
reed8e474782014-10-06 11:00:51 -070042 sk_alphatype_t alphaType;
43} sk_imageinfo_t;
reed938dfba2014-10-06 06:08:16 -070044
reed8e474782014-10-06 11:00:51 -070045typedef struct {
reed938dfba2014-10-06 06:08:16 -070046 float left;
47 float top;
48 float right;
49 float bottom;
reed8e474782014-10-06 11:00:51 -070050} sk_rect_t;
reed938dfba2014-10-06 06:08:16 -070051
reed8e474782014-10-06 11:00:51 -070052typedef struct sk_path_t sk_path_t;
reed938dfba2014-10-06 06:08:16 -070053
54sk_path_t* sk_path_new();
robertphillipsa624e872014-10-08 06:04:35 -070055void sk_path_delete(sk_path_t*);
reed8e474782014-10-06 11:00:51 -070056void sk_path_move_to(sk_path_t*, float x, float y);
57void sk_path_line_to(sk_path_t*, float x, float y);
58void sk_path_quad_to(sk_path_t*, float x0, float y0, float x1, float y1);
robertphillipsa624e872014-10-08 06:04:35 -070059void sk_path_close(sk_path_t*);
reed938dfba2014-10-06 06:08:16 -070060
reed8e474782014-10-06 11:00:51 -070061typedef struct sk_paint_t sk_paint_t;
reed938dfba2014-10-06 06:08:16 -070062
63sk_paint_t* sk_paint_new();
reed8e474782014-10-06 11:00:51 -070064void sk_paint_delete(sk_paint_t*);
robertphillipsa624e872014-10-08 06:04:35 -070065bool sk_paint_is_antialias(const sk_paint_t*);
reed938dfba2014-10-06 06:08:16 -070066void sk_paint_set_antialias(sk_paint_t*, bool);
67sk_color_t sk_paint_get_color(const sk_paint_t*);
68void sk_paint_set_color(sk_paint_t*, sk_color_t);
69
reed8e474782014-10-06 11:00:51 -070070typedef struct sk_canvas_t sk_canvas_t;
71typedef struct sk_image_t sk_image_t;
reed938dfba2014-10-06 06:08:16 -070072
73void sk_canvas_save(sk_canvas_t*);
74void sk_canvas_save_layer(sk_canvas_t*, const sk_rect_t*, const sk_paint_t*);
75void sk_canvas_restore(sk_canvas_t*);
76
reed8e474782014-10-06 11:00:51 -070077void sk_canvas_translate(sk_canvas_t*, float dx, float dy);
78void sk_canvas_scale(sk_canvas_t*, float sx, float sy);
reed938dfba2014-10-06 06:08:16 -070079
80void sk_canvas_draw_paint(sk_canvas_t*, const sk_paint_t*);
81void sk_canvas_draw_rect(sk_canvas_t*, const sk_rect_t*, const sk_paint_t*);
82void sk_canvas_draw_oval(sk_canvas_t*, const sk_rect_t*, const sk_paint_t*);
83void sk_canvas_draw_path(sk_canvas_t*, const sk_path_t*, const sk_paint_t*);
84void sk_canvas_draw_image(sk_canvas_t*, const sk_image_t*, float x, float y, const sk_paint_t*);
85
reed8e474782014-10-06 11:00:51 -070086sk_image_t* sk_image_new_raster_copy(const sk_imageinfo_t*, const void* pixels, size_t rowBytes);
87void sk_image_ref(const sk_image_t*);
88void sk_image_unref(const sk_image_t*);
reed938dfba2014-10-06 06:08:16 -070089int sk_image_get_width(const sk_image_t*);
90int sk_image_get_height(const sk_image_t*);
91uint32_t sk_image_get_unique_id(const sk_image_t*);
92
reed8e474782014-10-06 11:00:51 -070093typedef struct sk_surface_t sk_surface_t;
reed938dfba2014-10-06 06:08:16 -070094
reed8e474782014-10-06 11:00:51 -070095sk_surface_t* sk_surface_new_raster(const sk_imageinfo_t*);
96sk_surface_t* sk_surface_new_raster_direct(const sk_imageinfo_t*, void* pixels, size_t rowBytes);
reed938dfba2014-10-06 06:08:16 -070097void sk_surface_delete(sk_surface_t*);
reed938dfba2014-10-06 06:08:16 -070098sk_canvas_t* sk_surface_get_canvas(sk_surface_t*);
99sk_image_t* sk_surface_new_image_snapshot(sk_surface_t*);
100
reed8e474782014-10-06 11:00:51 -0700101#ifdef __cplusplus
102 class SkCanvas;
103 void sk_test_capi(SkCanvas*);
104}
105#endif
106
107#endif