| 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 | INTERSECT_SK_CLIPTYPE, |
| 57 | DIFFERENCE_SK_CLIPTYPE, |
| 58 | } sk_cliptype_t; |
| 59 | |
| 60 | typedef enum { |
| 61 | UNKNOWN_SK_PIXELGEOMETRY, |
| 62 | RGB_H_SK_PIXELGEOMETRY, |
| 63 | BGR_H_SK_PIXELGEOMETRY, |
| 64 | RGB_V_SK_PIXELGEOMETRY, |
| 65 | BGR_V_SK_PIXELGEOMETRY, |
| 66 | } sk_pixelgeometry_t; |
| 67 | |
| 68 | typedef struct { |
| 69 | sk_pixelgeometry_t pixelGeometry; |
| 70 | } sk_surfaceprops_t; |
| 71 | |
| 72 | typedef struct { |
| 73 | float x; |
| 74 | float y; |
| 75 | } sk_point_t; |
| 76 | |
| 77 | typedef struct { |
| 78 | int32_t left; |
| 79 | int32_t top; |
| 80 | int32_t right; |
| 81 | int32_t bottom; |
| 82 | } sk_irect_t; |
| 83 | |
| 84 | typedef struct { |
| 85 | float left; |
| 86 | float top; |
| 87 | float right; |
| 88 | float bottom; |
| 89 | } sk_rect_t; |
| 90 | |
| 91 | /** |
| 92 | The sk_matrix_t struct holds a 3x3 perspective matrix for |
| 93 | transforming coordinates: |
| 94 | |
| 95 | (X,Y) = T[M]((x,y)) |
| 96 | X = (M[0] * x + M[1] * y + M[2]) / (M[6] * x + M[7] * y + M[8]); |
| 97 | Y = (M[3] * x + M[4] * y + M[5]) / (M[6] * x + M[7] * y + M[8]); |
| 98 | |
| 99 | Therefore, the identity matrix is |
| 100 | |
| 101 | sk_matrix_t identity = {{1, 0, 0, |
| 102 | 0, 1, 0, |
| 103 | 0, 0, 1}}; |
| 104 | |
| 105 | A matrix that scales by sx and sy is: |
| 106 | |
| 107 | sk_matrix_t scale = {{sx, 0, 0, |
| 108 | 0, sy, 0, |
| 109 | 0, 0, 1}}; |
| 110 | |
| 111 | A matrix that translates by tx and ty is: |
| 112 | |
| 113 | sk_matrix_t translate = {{1, 0, tx, |
| 114 | 0, 1, ty, |
| 115 | 0, 0, 1}}; |
| 116 | |
| 117 | A matrix that rotates around the origin by A radians: |
| 118 | |
| 119 | sk_matrix_t rotate = {{cos(A), -sin(A), 0, |
| 120 | sin(A), cos(A), 0, |
| 121 | 0, 0, 1}}; |
| 122 | |
| 123 | Two matrixes can be concatinated by: |
| 124 | |
| 125 | void concat_matrices(sk_matrix_t* dst, |
| 126 | const sk_matrix_t* matrixU, |
| 127 | const sk_matrix_t* matrixV) { |
| 128 | const float* u = matrixU->mat; |
| 129 | const float* v = matrixV->mat; |
| 130 | sk_matrix_t result = {{ |
| 131 | u[0] * v[0] + u[1] * v[3] + u[2] * v[6], |
| 132 | u[0] * v[1] + u[1] * v[4] + u[2] * v[7], |
| 133 | u[0] * v[2] + u[1] * v[5] + u[2] * v[8], |
| 134 | u[3] * v[0] + u[4] * v[3] + u[5] * v[6], |
| 135 | u[3] * v[1] + u[4] * v[4] + u[5] * v[7], |
| 136 | u[3] * v[2] + u[4] * v[5] + u[5] * v[8], |
| 137 | u[6] * v[0] + u[7] * v[3] + u[8] * v[6], |
| 138 | u[6] * v[1] + u[7] * v[4] + u[8] * v[7], |
| 139 | u[6] * v[2] + u[7] * v[5] + u[8] * v[8] |
| 140 | }}; |
| 141 | *dst = result; |
| 142 | } |
| 143 | */ |
| 144 | typedef struct { |
| 145 | float mat[9]; |
| 146 | } sk_matrix_t; |
| 147 | |
| 148 | /** |
| 149 | A sk_canvas_t encapsulates all of the state about drawing into a |
| 150 | destination This includes a reference to the destination itself, |
| 151 | and a stack of matrix/clip values. |
| 152 | */ |
| 153 | typedef struct sk_canvas_t sk_canvas_t; |
| 154 | /** |
| 155 | A sk_data_ holds an immutable data buffer. |
| 156 | */ |
| 157 | typedef struct sk_data_t sk_data_t; |
| 158 | /** |
| 159 | A sk_image_t is an abstraction for drawing a rectagle of pixels. |
| 160 | The content of the image is always immutable, though the actual |
| 161 | storage may change, if for example that image can be re-created via |
| 162 | encoded data or other means. |
| 163 | */ |
| 164 | typedef struct sk_image_t sk_image_t; |
| 165 | |
| 166 | /** |
| 167 | * Describes the color components. See ICC Profiles. |
| 168 | */ |
| 169 | typedef struct sk_colorspace_t sk_colorspace_t; |
| 170 | |
| 171 | /** |
| 172 | * Describes an image buffer : width, height, pixel type, colorspace, etc. |
| 173 | */ |
| 174 | typedef struct sk_imageinfo_t sk_imageinfo_t; |
| 175 | |
| 176 | /** |
| 177 | A sk_maskfilter_t is an object that perform transformations on an |
| 178 | alpha-channel mask before drawing it; it may be installed into a |
| 179 | sk_paint_t. Each time a primitive is drawn, it is first |
| 180 | scan-converted into a alpha mask, which os handed to the |
| 181 | maskfilter, which may create a new mask is to render into the |
| 182 | destination. |
| 183 | */ |
| 184 | typedef struct sk_maskfilter_t sk_maskfilter_t; |
| 185 | /** |
| 186 | A sk_paint_t holds the style and color information about how to |
| 187 | draw geometries, text and bitmaps. |
| 188 | */ |
| 189 | typedef struct sk_paint_t sk_paint_t; |
| 190 | /** |
| 191 | A sk_path_t encapsulates compound (multiple contour) geometric |
| 192 | paths consisting of straight line segments, quadratic curves, and |
| 193 | cubic curves. |
| 194 | */ |
| 195 | typedef struct sk_path_t sk_path_t; |
| 196 | /** |
| 197 | A sk_picture_t holds recorded canvas drawing commands to be played |
| 198 | back at a later time. |
| 199 | */ |
| 200 | typedef struct sk_picture_t sk_picture_t; |
| 201 | /** |
| 202 | A sk_picture_recorder_t holds a sk_canvas_t that records commands |
| 203 | to create a sk_picture_t. |
| 204 | */ |
| 205 | typedef struct sk_picture_recorder_t sk_picture_recorder_t; |
| 206 | /** |
| 207 | A sk_shader_t specifies the source color(s) for what is being drawn. If a |
| 208 | paint has no shader, then the paint's color is used. If the paint |
| 209 | has a shader, then the shader's color(s) are use instead, but they |
| 210 | are modulated by the paint's alpha. |
| 211 | */ |
| 212 | typedef struct sk_shader_t sk_shader_t; |
| 213 | /** |
| 214 | A sk_surface_t holds the destination for drawing to a canvas. For |
| 215 | raster drawing, the destination is an array of pixels in memory. |
| 216 | For GPU drawing, the destination is a texture or a framebuffer. |
| 217 | */ |
| 218 | typedef struct sk_surface_t sk_surface_t; |
| 219 | |
| 220 | typedef enum { |
| 221 | CLEAR_SK_XFERMODE_MODE, |
| 222 | SRC_SK_XFERMODE_MODE, |
| 223 | DST_SK_XFERMODE_MODE, |
| 224 | SRCOVER_SK_XFERMODE_MODE, |
| 225 | DSTOVER_SK_XFERMODE_MODE, |
| 226 | SRCIN_SK_XFERMODE_MODE, |
| 227 | DSTIN_SK_XFERMODE_MODE, |
| 228 | SRCOUT_SK_XFERMODE_MODE, |
| 229 | DSTOUT_SK_XFERMODE_MODE, |
| 230 | SRCATOP_SK_XFERMODE_MODE, |
| 231 | DSTATOP_SK_XFERMODE_MODE, |
| 232 | XOR_SK_XFERMODE_MODE, |
| 233 | PLUS_SK_XFERMODE_MODE, |
| 234 | MODULATE_SK_XFERMODE_MODE, |
| 235 | SCREEN_SK_XFERMODE_MODE, |
| 236 | OVERLAY_SK_XFERMODE_MODE, |
| 237 | DARKEN_SK_XFERMODE_MODE, |
| 238 | LIGHTEN_SK_XFERMODE_MODE, |
| 239 | COLORDODGE_SK_XFERMODE_MODE, |
| 240 | COLORBURN_SK_XFERMODE_MODE, |
| 241 | HARDLIGHT_SK_XFERMODE_MODE, |
| 242 | SOFTLIGHT_SK_XFERMODE_MODE, |
| 243 | DIFFERENCE_SK_XFERMODE_MODE, |
| 244 | EXCLUSION_SK_XFERMODE_MODE, |
| 245 | MULTIPLY_SK_XFERMODE_MODE, |
| 246 | HUE_SK_XFERMODE_MODE, |
| 247 | SATURATION_SK_XFERMODE_MODE, |
| 248 | COLOR_SK_XFERMODE_MODE, |
| 249 | LUMINOSITY_SK_XFERMODE_MODE, |
| 250 | } sk_xfermode_mode_t; |
| 251 | |
| 252 | ////////////////////////////////////////////////////////////////////////////////////////// |
| 253 | |
| 254 | SK_C_PLUS_PLUS_END_GUARD |
| 255 | |
| 256 | #endif |
| 257 | |