1 /* TSI 2023.xmo */ 2 /******************************************************************************* 3 * Copyright (c) 2023 Think Silicon Single Member PC 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a copy 6 * of this header file and/or associated documentation files to use, copy, 7 * modify, merge, publish, distribute, sublicense, and/or sell copies of the 8 * Materials, and to permit persons to whom the Materials are furnished to do 9 * so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Materials. 13 * 14 * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS 15 * NEMAGFX API. THE UNMODIFIED, NORMATIVE VERSIONS OF THINK-SILICON NEMAGFX 16 * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT: 17 * https://think-silicon.com/products/software/nemagfx-api 18 * 19 * The software is provided 'as is', without warranty of any kind, express or 20 * implied, including but not limited to the warranties of merchantability, 21 * fitness for a particular purpose and noninfringement. In no event shall 22 * Think Silicon Single Member PC be liable for any claim, damages or other 23 * liability, whether in an action of contract, tort or otherwise, arising 24 * from, out of or in connection with the software or the use or other dealings 25 * in the software. 26 ******************************************************************************/ 27 28 /** 29 * @file 30 * @brief Core NemaVG API drawing and initialization functions. 31 * 32 */ 33 34 #ifndef __NEMA_VG_H__ 35 #define __NEMA_VG_H__ 36 37 #include "nema_core.h" 38 #include "nema_sys_defs.h" 39 #include "nema_vg_path.h" 40 #include "nema_vg_paint.h" 41 #include "nema_vg_context.h" 42 43 #ifdef __cplusplus 44 extern "C" { 45 #endif 46 47 // ------------------------------------------------------------------------------- 48 // SETUP 49 // ------------------------------------------------------------------------------- 50 51 /** \brief Initializes NemaVG library and allocates the stencil buffer to the default memory pool (NEMA_MEM_POOL_FB) 52 * Call either this or nema_vg_init_stencil_pool to allocate the stencil buffer to a different memory pool 53 * or nema_vg_init_stencil_prealloc to provide the stencil buffer 54 * \param width Framebuffer width 55 * \param height Framebuffer height 56 */ 57 void nema_vg_init(int width, int height); 58 59 /** \brief Initializes NemaVG library and allocate the stencil buffer in a specific memory pool. 60 * Call either this or nema_vg_init to allocate the stencil buffer to the default memory pool (NEMA_MEM_POOL_FB) 61 * or nema_vg_init_stencil_prealloc to provide the stencil buffer 62 * \param width Stencil buffer width - Must be the first multiple of 4 of the framebuffer width 63 * \param height Stencil buffer height - Must be the first multiple of 4 of the framebuffer height 64 * \param pool Memory pool for allocating the stencil buffer (memory pools are platform specific and defined in nema_sys_defs.h file) 65 */ 66 void nema_vg_init_stencil_pool(int width, int height, int pool); 67 68 /** \brief Initializes NemaVG library without allocating the stencil buffer which is provided by the user. 69 * Call either this or nema_vg_init to allocate the stencil buffer to the default memory pool (NEMA_MEM_POOL_FB) 70 * or nema_vg_init_stencil_pool to allocate the stencil buffer to a different memory pool 71 * \param width Stencil buffer width - Must be the first multiple of 4 of the framebuffer width 72 * \param height Stencil buffer height - Must be the first multiple of 4 of the framebuffer height 73 * \param stencil_bo stencil buffer 74 */ 75 void nema_vg_init_stencil_prealloc(int width, int height, nema_buffer_t stencil_bo); 76 77 78 /** \brief Reinitialize NemaVG library after a gpu powerofff 79 * 80 */ 81 void nema_vg_reinit(void); 82 83 /** \brief Deinitialize NemaVG library. Free memory from implicitly allocated objects (stencil buffer 84 * if created inside the library, lut buffer and tsvgs' path, paint and gradient buffers) 85 * 86 * 87 */ 88 void nema_vg_deinit(void); 89 90 /** \brief Initialize NemaVG library for a new thread. 91 * Must be called for every new thread that is used. 92 * 93 * 94 */ 95 void nema_vg_thread_init(void); 96 97 98 // ------------------------------------------------------------------------------- 99 // PATH DRAW 100 // ------------------------------------------------------------------------------- 101 102 /** \brief Draw a path using a specified paint object 103 * 104 * \param path Pointer (handle) to the path that will be drawn 105 * \param paint Pointer (handle) to the paint object that wil be used for drawing 106 107 * \return Error code. See NEMA_VG_ERR_* defines in "nema_vg_context.h" header file for the error codes. 108 * 109 */ 110 uint32_t nema_vg_draw_path(NEMA_VG_PATH_HANDLE path, NEMA_VG_PAINT_HANDLE paint); 111 112 /** \brief Draw a line shape 113 * 114 * \param x1 Upper left x coordinate 115 * \param y1 Upper left y coordinate 116 * \param x2 The width 117 * \param y2 The height 118 * \param m 3x3 affine transformation matrix 119 * \param paint The paint to draw 120 121 * \return Error code. See NEMA_VG_ERR_* defines in "nema_vg_context.h" header file for the error codes. 122 * 123 */ 124 uint32_t nema_vg_draw_line(float x1, float y1, float x2, float y2, 125 nema_matrix3x3_t m, 126 NEMA_VG_PAINT_HANDLE paint); 127 128 /** \brief Draw a rectangle shape 129 * 130 * \param x Upper left x coordinate 131 * \param y Upper left y coordinate 132 * \param width The width 133 * \param height The height 134 * \param m 3x3 affine transformation matrix 135 * \param paint The paint to draw 136 137 * \return Error code 138 * 139 */ 140 uint32_t nema_vg_draw_rect(float x, float y, float width, float height, 141 nema_matrix3x3_t m, 142 NEMA_VG_PAINT_HANDLE paint); 143 144 /** \brief Draw a rounded rectangle shape 145 * 146 * \param x Upper left x coordinate 147 * \param y Upper left y coordinate 148 * \param width The width 149 * \param height The height 150 * \param rx Horizontal cornel radius 151 * \param ry Vertical cornel radius 152 * \param m 3x3 affine transformation matrix 153 * \param paint The paint to draw 154 155 * \return Error code. See NEMA_VG_ERR_* defines in "nema_vg_context.h" header file for the error codes. 156 * 157 */ 158 uint32_t nema_vg_draw_rounded_rect(float x, float y, float width, float height, 159 float rx, float ry, 160 nema_matrix3x3_t m, 161 NEMA_VG_PAINT_HANDLE paint); 162 163 /** \brief Draw a ellipse shape 164 * 165 * \param cx The x position of the ellipse 166 * \param cy The y position of the ellipse 167 * \param rx Radius on the x axis 168 * \param ry Radius on the y axis 169 * \param m 3x3 affine transformation matrix 170 * \param paint The paint to draw 171 172 * \return Error code. See NEMA_VG_ERR_* defines in "nema_vg_context.h" header file for the error codes. 173 * 174 */ 175 uint32_t nema_vg_draw_ellipse(float cx, float cy, float rx, float ry, 176 nema_matrix3x3_t m, 177 NEMA_VG_PAINT_HANDLE paint); 178 179 /** \brief Draw a circle shape 180 * 181 * \param cx The x center of the circle 182 * \param cy The y center of the circle 183 * \param r Radius of the circle 184 * \param m 3x3 affine transformation matrix 185 * \param paint The paint to draw 186 187 * \return Error code. See NEMA_VG_ERR_* defines in "nema_vg_context.h" header file for the error codes. 188 * 189 */ 190 uint32_t nema_vg_draw_circle(float cx, float cy, float r, 191 nema_matrix3x3_t m, 192 NEMA_VG_PAINT_HANDLE paint); 193 194 195 /** \brief Draw a filled ring with rounded caps shape. In case of a conical gradient paint type, 196 * the conical gradient center should be at the center of the ring(cx, cy). In other case, where the two centers do not match, 197 * the ring should be drawn with NEMA_VG_QUALITY_MAXIMUM. The ring width can be set with the paint's stroke_width. 198 * 199 * \param cx The center x coordinate of the ring 200 * \param cy The center y coordinate of the ring 201 * \param ring_radius The radius of the ring 202 * \param angle_start The angle in degrees of the ring 203 * \param angle_end The angle in degrees that ends this ring 204 * \param paint The paint to draw 205 206 * \return Error code. See NEMA_VG_ERR_* defines in "nema_vg_context.h" header file for the error codes. 207 * 208 */ 209 uint32_t nema_vg_draw_ring(float cx, float cy, float ring_radius, float angle_start, float angle_end, 210 NEMA_VG_PAINT_HANDLE paint); 211 212 /** \private 213 * \brief Draw a filled ring with flat ending or rounded ending caps. In case of a conical gradient paint type, 214 * the conical gradient center should be at the center of the ring(cx, cy). In other case, where the two centers do not match, 215 * the ring should be drawn with NEMA_VG_QUALITY_MAXIMUM. The ring width can be set with the paint's stroke_width. 216 * 217 * \param cx The center x coordinate of the ring 218 * \param cy The center y coordinate of the ring 219 * \param ring_radius The radius of the ring 220 * \param angle_start The angle in degrees of the ring 221 * \param angle_end The angle in degrees that ends this ring 222 * \param paint The paint to draw 223 * \param has_caps 1 For caps 0 for flat ending 224 225 * \return Error code. See NEMA_VG_ERR_* defines in "nema_vg_context.h" header file for the error codes. 226 * 227 */ 228 uint32_t nema_vg_draw_ring_generic(float cx, float cy, float ring_radius, float angle_start, float angle_end, 229 NEMA_VG_PAINT_HANDLE paint, uint8_t has_caps); 230 231 232 /** \brief Returns the minimum and maximum values for the coordinates that 233 * can be handled by the underlying hardware 234 * 235 * \param min_coord Minimum coordinate (x or y) value (pointer) 236 * \param max_coord Maximum coordinate (x or y) value (pointer) 237 * 238 */ 239 void nema_vg_get_coord_limits(float *min_coord, float *max_coord); 240 241 242 /** \brief Disables tsvg features from rendering. Should be set before 243 * nema_vg_draw_tsvg() 244 * 245 * \param feature feature to be disabled 246 * 247 */ 248 void nema_vg_tsvg_disable_feature(uint32_t feature); 249 250 #ifdef __cplusplus 251 } 252 #endif 253 254 #endif //__NEMA_VG_H__ 255