blob: 4c597ce49a7ad10ce3aa45f8ff65b54b625d8db5 [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();
reed8e474782014-10-06 11:00:51 -070055void sk_path_move_to(sk_path_t*, float x, float y);
56void sk_path_line_to(sk_path_t*, float x, float y);
57void sk_path_quad_to(sk_path_t*, float x0, float y0, float x1, float y1);
reed938dfba2014-10-06 06:08:16 -070058void sk_path_get_bounds(const sk_path_t*, sk_rect_t*);
59
reed8e474782014-10-06 11:00:51 -070060typedef struct sk_paint_t sk_paint_t;
reed938dfba2014-10-06 06:08:16 -070061
62sk_paint_t* sk_paint_new();
reed8e474782014-10-06 11:00:51 -070063void sk_paint_delete(sk_paint_t*);
reed938dfba2014-10-06 06:08:16 -070064bool sk_paint_is_antialias(sk_paint_t*);
65void sk_paint_set_antialias(sk_paint_t*, bool);
66sk_color_t sk_paint_get_color(const sk_paint_t*);
67void sk_paint_set_color(sk_paint_t*, sk_color_t);
68
reed8e474782014-10-06 11:00:51 -070069typedef struct sk_canvas_t sk_canvas_t;
70typedef struct sk_image_t sk_image_t;
reed938dfba2014-10-06 06:08:16 -070071
72void sk_canvas_save(sk_canvas_t*);
73void sk_canvas_save_layer(sk_canvas_t*, const sk_rect_t*, const sk_paint_t*);
74void sk_canvas_restore(sk_canvas_t*);
75
reed8e474782014-10-06 11:00:51 -070076void sk_canvas_translate(sk_canvas_t*, float dx, float dy);
77void sk_canvas_scale(sk_canvas_t*, float sx, float sy);
reed938dfba2014-10-06 06:08:16 -070078
79void sk_canvas_draw_paint(sk_canvas_t*, const sk_paint_t*);
80void sk_canvas_draw_rect(sk_canvas_t*, const sk_rect_t*, const sk_paint_t*);
81void sk_canvas_draw_oval(sk_canvas_t*, const sk_rect_t*, const sk_paint_t*);
82void sk_canvas_draw_path(sk_canvas_t*, const sk_path_t*, const sk_paint_t*);
83void sk_canvas_draw_image(sk_canvas_t*, const sk_image_t*, float x, float y, const sk_paint_t*);
84
reed8e474782014-10-06 11:00:51 -070085sk_image_t* sk_image_new_raster_copy(const sk_imageinfo_t*, const void* pixels, size_t rowBytes);
86void sk_image_ref(const sk_image_t*);
87void sk_image_unref(const sk_image_t*);
reed938dfba2014-10-06 06:08:16 -070088int sk_image_get_width(const sk_image_t*);
89int sk_image_get_height(const sk_image_t*);
90uint32_t sk_image_get_unique_id(const sk_image_t*);
91
reed8e474782014-10-06 11:00:51 -070092typedef struct sk_surface_t sk_surface_t;
reed938dfba2014-10-06 06:08:16 -070093
reed8e474782014-10-06 11:00:51 -070094sk_surface_t* sk_surface_new_raster(const sk_imageinfo_t*);
95sk_surface_t* sk_surface_new_raster_direct(const sk_imageinfo_t*, void* pixels, size_t rowBytes);
reed938dfba2014-10-06 06:08:16 -070096void sk_surface_delete(sk_surface_t*);
reed938dfba2014-10-06 06:08:16 -070097sk_canvas_t* sk_surface_get_canvas(sk_surface_t*);
98sk_image_t* sk_surface_new_image_snapshot(sk_surface_t*);
99
reed8e474782014-10-06 11:00:51 -0700100#ifdef __cplusplus
101 class SkCanvas;
102 void sk_test_capi(SkCanvas*);
103}
104#endif
105
106#endif