• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
8 // EXPERIMENTAL EXPERIMENTAL EXPERIMENTAL EXPERIMENTAL
9 // DO NOT USE -- FOR INTERNAL TESTING ONLY
10 
11 #ifndef sk_types_DEFINED
12 #define sk_types_DEFINED
13 
14 #include <stdint.h>
15 #include <stddef.h>
16 
17 #ifdef __cplusplus
18     #define SK_C_PLUS_PLUS_BEGIN_GUARD    extern "C" {
19     #define SK_C_PLUS_PLUS_END_GUARD      }
20 #else
21     #include <stdbool.h>
22     #define SK_C_PLUS_PLUS_BEGIN_GUARD
23     #define SK_C_PLUS_PLUS_END_GUARD
24 #endif
25 
26 #if !defined(SK_API)
27     #if defined(SKIA_DLL)
28         #if defined(_MSC_VER)
29             #if SKIA_IMPLEMENTATION
30                 #define SK_API __declspec(dllexport)
31             #else
32                 #define SK_API __declspec(dllimport)
33             #endif
34         #else
35             #define SK_API __attribute__((visibility("default")))
36         #endif
37     #else
38         #define SK_API
39     #endif
40 #endif
41 
42 ///////////////////////////////////////////////////////////////////////////////////////
43 
44 SK_C_PLUS_PLUS_BEGIN_GUARD
45 
46 typedef uint32_t sk_color_t;
47 
48 /* This macro assumes all arguments are >=0 and <=255. */
49 #define sk_color_set_argb(a, r, g, b)   (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
50 #define sk_color_get_a(c)               (((c) >> 24) & 0xFF)
51 #define sk_color_get_r(c)               (((c) >> 16) & 0xFF)
52 #define sk_color_get_g(c)               (((c) >>  8) & 0xFF)
53 #define sk_color_get_b(c)               (((c) >>  0) & 0xFF)
54 
55 typedef enum {
56     UNKNOWN_SK_COLORTYPE,
57     RGBA_8888_SK_COLORTYPE,
58     BGRA_8888_SK_COLORTYPE,
59     ALPHA_8_SK_COLORTYPE,
60 } sk_colortype_t;
61 
62 typedef enum {
63     OPAQUE_SK_ALPHATYPE,
64     PREMUL_SK_ALPHATYPE,
65     UNPREMUL_SK_ALPHATYPE,
66 } sk_alphatype_t;
67 
68 typedef enum {
69     INTERSECT_SK_CLIPTYPE,
70     DIFFERENCE_SK_CLIPTYPE,
71 } sk_cliptype_t;
72 
73 typedef enum {
74     UNKNOWN_SK_PIXELGEOMETRY,
75     RGB_H_SK_PIXELGEOMETRY,
76     BGR_H_SK_PIXELGEOMETRY,
77     RGB_V_SK_PIXELGEOMETRY,
78     BGR_V_SK_PIXELGEOMETRY,
79 } sk_pixelgeometry_t;
80 
81 /**
82     Return the default sk_colortype_t; this is operating-system dependent.
83 */
84 SK_API sk_colortype_t sk_colortype_get_default_8888(void);
85 
86 typedef struct {
87     int32_t         width;
88     int32_t         height;
89     sk_colortype_t  colorType;
90     sk_alphatype_t  alphaType;
91 } sk_imageinfo_t;
92 
93 typedef struct {
94     sk_pixelgeometry_t pixelGeometry;
95 } sk_surfaceprops_t;
96 
97 typedef struct {
98     float   x;
99     float   y;
100 } sk_point_t;
101 
102 typedef struct {
103     int32_t left;
104     int32_t top;
105     int32_t right;
106     int32_t bottom;
107 } sk_irect_t;
108 
109 typedef struct {
110     float   left;
111     float   top;
112     float   right;
113     float   bottom;
114 } sk_rect_t;
115 
116 /**
117     The sk_matrix_t struct holds a 3x3 perspective matrix for
118     transforming coordinates:
119 
120         (X,Y) = T[M]((x,y))
121         X = (M[0] * x + M[1] * y + M[2]) / (M[6] * x + M[7] * y + M[8]);
122         Y = (M[3] * x + M[4] * y + M[5]) / (M[6] * x + M[7] * y + M[8]);
123 
124     Therefore, the identity matrix is
125 
126         sk_matrix_t identity = {{1, 0, 0,
127                                  0, 1, 0,
128                                  0, 0, 1}};
129 
130     A matrix that scales by sx and sy is:
131 
132         sk_matrix_t scale = {{sx, 0,  0,
133                               0,  sy, 0,
134                               0,  0,  1}};
135 
136     A matrix that translates by tx and ty is:
137 
138         sk_matrix_t translate = {{1, 0, tx,
139                                   0, 1, ty,
140                                   0, 0, 1}};
141 
142     A matrix that rotates around the origin by A radians:
143 
144         sk_matrix_t rotate = {{cos(A), -sin(A), 0,
145                                sin(A),  cos(A), 0,
146                                0,       0,      1}};
147 
148     Two matrixes can be concatinated by:
149 
150          void concat_matrices(sk_matrix_t* dst,
151                              const sk_matrix_t* matrixU,
152                              const sk_matrix_t* matrixV) {
153             const float* u = matrixU->mat;
154             const float* v = matrixV->mat;
155             sk_matrix_t result = {{
156                     u[0] * v[0] + u[1] * v[3] + u[2] * v[6],
157                     u[0] * v[1] + u[1] * v[4] + u[2] * v[7],
158                     u[0] * v[2] + u[1] * v[5] + u[2] * v[8],
159                     u[3] * v[0] + u[4] * v[3] + u[5] * v[6],
160                     u[3] * v[1] + u[4] * v[4] + u[5] * v[7],
161                     u[3] * v[2] + u[4] * v[5] + u[5] * v[8],
162                     u[6] * v[0] + u[7] * v[3] + u[8] * v[6],
163                     u[6] * v[1] + u[7] * v[4] + u[8] * v[7],
164                     u[6] * v[2] + u[7] * v[5] + u[8] * v[8]
165             }};
166             *dst = result;
167         }
168 */
169 typedef struct {
170     float   mat[9];
171 } sk_matrix_t;
172 
173 /**
174     A sk_canvas_t encapsulates all of the state about drawing into a
175     destination This includes a reference to the destination itself,
176     and a stack of matrix/clip values.
177 */
178 typedef struct sk_canvas_t sk_canvas_t;
179 /**
180     A sk_data_ holds an immutable data buffer.
181 */
182 typedef struct sk_data_t sk_data_t;
183 /**
184     A sk_image_t is an abstraction for drawing a rectagle of pixels.
185     The content of the image is always immutable, though the actual
186     storage may change, if for example that image can be re-created via
187     encoded data or other means.
188 */
189 typedef struct sk_image_t sk_image_t;
190 /**
191     A sk_maskfilter_t is an object that perform transformations on an
192     alpha-channel mask before drawing it; it may be installed into a
193     sk_paint_t.  Each time a primitive is drawn, it is first
194     scan-converted into a alpha mask, which os handed to the
195     maskfilter, which may create a new mask is to render into the
196     destination.
197  */
198 typedef struct sk_maskfilter_t sk_maskfilter_t;
199 /**
200     A sk_paint_t holds the style and color information about how to
201     draw geometries, text and bitmaps.
202 */
203 typedef struct sk_paint_t sk_paint_t;
204 /**
205     A sk_path_t encapsulates compound (multiple contour) geometric
206     paths consisting of straight line segments, quadratic curves, and
207     cubic curves.
208 */
209 typedef struct sk_path_t sk_path_t;
210 /**
211     A sk_picture_t holds recorded canvas drawing commands to be played
212     back at a later time.
213 */
214 typedef struct sk_picture_t sk_picture_t;
215 /**
216     A sk_picture_recorder_t holds a sk_canvas_t that records commands
217     to create a sk_picture_t.
218 */
219 typedef struct sk_picture_recorder_t sk_picture_recorder_t;
220 /**
221     A sk_shader_t specifies the source color(s) for what is being drawn. If a
222     paint has no shader, then the paint's color is used. If the paint
223     has a shader, then the shader's color(s) are use instead, but they
224     are modulated by the paint's alpha.
225 */
226 typedef struct sk_shader_t sk_shader_t;
227 /**
228     A sk_surface_t holds the destination for drawing to a canvas. For
229     raster drawing, the destination is an array of pixels in memory.
230     For GPU drawing, the destination is a texture or a framebuffer.
231 */
232 typedef struct sk_surface_t sk_surface_t;
233 
234 typedef enum {
235     CLEAR_SK_XFERMODE_MODE,
236     SRC_SK_XFERMODE_MODE,
237     DST_SK_XFERMODE_MODE,
238     SRCOVER_SK_XFERMODE_MODE,
239     DSTOVER_SK_XFERMODE_MODE,
240     SRCIN_SK_XFERMODE_MODE,
241     DSTIN_SK_XFERMODE_MODE,
242     SRCOUT_SK_XFERMODE_MODE,
243     DSTOUT_SK_XFERMODE_MODE,
244     SRCATOP_SK_XFERMODE_MODE,
245     DSTATOP_SK_XFERMODE_MODE,
246     XOR_SK_XFERMODE_MODE,
247     PLUS_SK_XFERMODE_MODE,
248     MODULATE_SK_XFERMODE_MODE,
249     SCREEN_SK_XFERMODE_MODE,
250     OVERLAY_SK_XFERMODE_MODE,
251     DARKEN_SK_XFERMODE_MODE,
252     LIGHTEN_SK_XFERMODE_MODE,
253     COLORDODGE_SK_XFERMODE_MODE,
254     COLORBURN_SK_XFERMODE_MODE,
255     HARDLIGHT_SK_XFERMODE_MODE,
256     SOFTLIGHT_SK_XFERMODE_MODE,
257     DIFFERENCE_SK_XFERMODE_MODE,
258     EXCLUSION_SK_XFERMODE_MODE,
259     MULTIPLY_SK_XFERMODE_MODE,
260     HUE_SK_XFERMODE_MODE,
261     SATURATION_SK_XFERMODE_MODE,
262     COLOR_SK_XFERMODE_MODE,
263     LUMINOSITY_SK_XFERMODE_MODE,
264 } sk_xfermode_mode_t;
265 
266 //////////////////////////////////////////////////////////////////////////////////////////
267 
268 SK_C_PLUS_PLUS_END_GUARD
269 
270 #endif
271