sk_types.h 7.4 KB

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