1 /**************************************************************************** 2 * 3 * Copyright 2012 - 2020 Vivante Corporation, Santa Clara, California. 4 * All Rights Reserved. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining 7 * a copy of this software and associated documentation files (the 8 * 'Software'), to deal in the Software without restriction, including 9 * without limitation the rights to use, copy, modify, merge, publish, 10 * distribute, sub license, and/or sell copies of the Software, and to 11 * permit persons to whom the Software is furnished to do so, subject 12 * to the following conditions: 13 * 14 * The above copyright notice and this permission notice (including the 15 * next paragraph) shall be included in all copies or substantial 16 * portions of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21 * IN NO EVENT SHALL VIVANTE AND/OR ITS SUPPLIERS BE LIABLE FOR ANY 22 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 * 26 *****************************************************************************/ 27 28 #ifndef VELM_H_ 29 #define VELM_H_ 30 31 #ifdef __cplusplus 32 extern "C" { 33 #endif 34 /* 35 */ 36 #define VERSION 0x00000001 37 #define SLOT_COUNT 256/*16*/ 38 #define OBJECT_SLOT(id) \ 39 elm_tls->gContext.object_slots[id % SLOT_COUNT] 40 41 /* 42 VGLite releated configurations. 43 */ 44 #define TS_WIDTH 64 45 #define TS_HEIGHT 64 46 #define RTOS 1 47 #define APP_BUFFER_COUNT 2 48 #if (RTOS && DDRLESS) || BAREMETAL 49 #define OBJCOUNT_GRAD 16 50 #define OBJCOUNT_EVO 128 51 #define OBJCOUNT_EBO 64 52 #define OBJCOUNT_GROUP 16 53 #endif 54 55 #if RTOS 56 57 #include "rtthread.h" 58 59 #define elm_alloc(num_objects, object_size) rt_malloc(num_objects * object_size) 60 #define elm_free rt_free 61 #else 62 #define elm_alloc calloc 63 #define elm_free free 64 #endif 65 66 typedef enum { 67 ELEMENT_LINEARGRADIENT = 0, /*! linear gradient element */ 68 ELEMENT_PATH = 1, /*! path element */ 69 ELEMENT_GROUP = 2, /*! group element */ 70 ELEMENT_TEXT = 3, /*! text element */ 71 ELEMENT_TSPAN = 4, /*! tspan element */ 72 ELEMENT_FONT = 5, /*! font element */ 73 ELEMENT_TTF_FONT = 6, /*! ttf-type font */ 74 ELEMENT_VECTOR_FONT = 7, /*! vector fonts */ 75 ELEMENT_TEXT_FONT = 8, /*! text fonts */ 76 } ELM_ELEMENT_TYPE; 77 78 #define COUNT_OF(array) (sizeof(array) / sizeof(array[0])) 79 /* 80 System definitions. 81 */ 82 #define DEBUG_ASSERT(a, message) \ 83 if (!a) \ 84 printf("%s: ASSERT failed @ %s, %d.\n", message, __FILE__, __LINE__) 85 86 /*! 87 @typedef el_Object 88 common object type definition shared by all EVO object to identify its handle, 89 object type, and ELM version info. 90 for reference purpose, handle = 0 is reserved. 91 */ 92 typedef struct { 93 ElmHandle handle; 94 ELM_OBJECT_TYPE type; 95 unsigned int reference; // Reference count by other objects. 96 #if (RTOS && DDRLESS) || BAREMETAL 97 int index; /* The index of the object in pool. */ 98 #endif 99 } el_Object; 100 101 /*! 102 @typedef el_Transform 103 The transformation attribute for an EVO/EBO/Group object. 104 */ 105 typedef struct { 106 float rotate; 107 float translate[2]; 108 float scale[2]; 109 BOOL dirty; 110 BOOL identity; 111 vg_lite_matrix_t matrix; 112 } el_Transform; 113 114 /*! 115 @typedef el_GradData 116 Linear gradient definition. 117 !grad the native vg_lite gradient data; 118 !gransform the grad's transformation. matrix is synced to grad's. 119 */ 120 typedef struct { 121 vg_lite_linear_gradient_t grad; 122 el_Transform transform; 123 } el_GradData; 124 125 /*! 126 @typedef el_RadgradData 127 Radial gradient definition. 128 !rad_grad the native vg_lite_radial_gradient data; 129 !gransform the grad's transformation. matrix is synced to grad's. 130 */ 131 typedef struct { 132 vg_lite_radial_gradient_t rad_grad; 133 el_Transform transform; 134 } el_RadgradData; 135 136 /*! 137 @typedef el_Obj_Grad 138 The linear gradient object definition. 139 */ 140 typedef struct { 141 el_Object object; 142 el_GradData data; 143 } el_Obj_Grad; 144 145 /*! 146 @typedef el_Obj_Radgrad 147 The radial gradient object definition. 148 */ 149 typedef struct { 150 el_Object object; 151 el_RadgradData data; 152 } el_Obj_Radgrad; 153 154 /*! 155 @typedef el_Obj_Pattern 156 The pattern paint object definition. 157 pattern: it should be an pointer to an el_Obj_EVO; 158 mode: the pattern fill mode. 159 color: the color value if pattern mode is COLOR 160 */ 161 typedef struct { 162 void *pattern; 163 ELM_PATTERN_MODE mode; 164 uint32_t color; 165 } el_Obj_Pattern; 166 167 /*! 168 @typedef el_Paint 169 The paint object definition. 170 color: for solid fill; 171 grad: for linear gradient fill; 172 pattern: for image fill. 173 */ 174 typedef struct { 175 ELM_PAINT_TYPE type; 176 uint32_t color; 177 el_Obj_Grad * grad; 178 el_Obj_Radgrad * radgrad; 179 el_Obj_Pattern pattern; 180 } el_Paint; 181 182 /*! 183 @typedef el_Attribute 184 The rendering attribute definition. 185 */ 186 typedef struct { 187 ELM_QUALITY quality; 188 ELM_BLEND blend; 189 ELM_EVO_FILL fill_rule; 190 el_Paint paint; 191 el_Transform transform; 192 } el_Attribute; 193 194 /*! 195 @typedef el_EVOData 196 The data definition for EVO (vector object). 197 */ 198 typedef struct { 199 vg_lite_path_t path; 200 } el_EVOData; 201 202 /*! 203 @typedef el_Obj_EVO 204 EVO (Elementry Vector Object) type definition. 205 */ 206 typedef struct { 207 el_Object object; 208 el_Attribute attribute; 209 el_Attribute defaultAttrib; 210 el_EVOData data; 211 uint32_t has_pattern; 212 uint32_t is_pattern; 213 uint32_t is_image; 214 char eboname[20]; 215 uint32_t img_width; 216 uint32_t img_height; 217 } el_Obj_EVO; 218 219 /*! 220 @typedef el_EBOData 221 The data definition for EBO (bitmap object). 222 */ 223 typedef struct { 224 vg_lite_buffer_t buffer; 225 } el_EBOData; 226 227 /*! 228 @typedef el_Obj_EBO 229 EBO (Elementry Buffer Object) type definition. 230 */ 231 typedef struct { 232 el_Object object; 233 el_Attribute attribute; 234 el_Attribute defaultAttrib; 235 el_EBOData data; 236 uint32_t clut_count; 237 uint32_t clut[256]; 238 } el_Obj_EBO; 239 240 /*! 241 @typedef el_GroupData 242 The group object data definition. 243 */ 244 typedef struct { 245 unsigned int count; 246 el_Obj_EVO * objects; 247 } el_GroupData; 248 249 /*! 250 @typedef el_Obj_Group 251 Group object type definition. 252 */ 253 typedef struct { 254 el_Object object; 255 el_Transform transform; 256 el_Transform defaultTrans; 257 el_GroupData group; 258 } el_Obj_Group; 259 260 /*! 261 @typedef el_Obj_Buffer 262 The render buffer object definition. 263 */ 264 typedef struct { 265 el_Object object; 266 vg_lite_buffer_t buffer; 267 } el_Obj_Buffer; 268 269 /*! 270 @typedef el_ObjList 271 List to organize objects. 272 */ 273 typedef struct _object_list{ 274 el_Object *object; 275 struct _object_list *next; 276 } el_ObjList; 277 278 /*! 279 @typedef ElmRenderBuffer 280 The ElmRenderBuffer definition. 281 */ 282 typedef struct elm_render_buffer { 283 ElmBuffer handle; 284 vg_lite_buffer_t *buffer; 285 } ElmRenderBuffer; 286 287 /*! 288 @typedef el_Context 289 The context object for global data management. 290 !version UXDK version 291 !currentHandle The current handle for new object 292 !objectCount Count of all objects 293 !object_slots List array to manage objects 294 */ 295 typedef struct { 296 uint32_t version; 297 int reference; 298 ElmHandle currentHandle; 299 unsigned int objectCount; 300 el_ObjList *object_slots[SLOT_COUNT]; 301 ElmRenderBuffer elmFB[APP_BUFFER_COUNT]; 302 /* VGLite related states. */ 303 uint32_t tessellation_width; 304 uint32_t tessellation_height; 305 306 /* The current vector index (within a group). */ 307 int32_t vector_id; 308 309 #if (RTOS && DDRLESS) || BAREMETAL 310 /* Static object pools. */ 311 el_Obj_Grad objpool_grad[OBJCOUNT_GRAD]; 312 el_Obj_EVO objpool_evo[OBJCOUNT_EVO]; 313 el_Obj_EBO objpool_ebo[OBJCOUNT_EBO]; 314 el_Obj_Group objpool_group[OBJCOUNT_GROUP]; 315 316 /* The allocation map table. 317 * Each bit in the element maps to the usage of the object. 318 * 0 means free, 1 means allocated. 319 * The mapping order is 01234567...31 (hi -> low) in big endian systems. 320 * */ 321 int32_t objmap_grad[(OBJCOUNT_GRAD + 31) / 32]; 322 int32_t objmap_evo[(OBJCOUNT_EVO + 31) / 32]; 323 int32_t objmap_ebo[(OBJCOUNT_EBO + 31) / 32]; 324 int32_t objmap_group[(OBJCOUNT_GROUP + 31) / 32]; 325 326 int objcounter_grad; 327 int objcounter_evo; 328 int objcounter_ebo; 329 int objcounter_group; 330 #endif 331 } el_Context; 332 333 /*! 334 @typedef elm_tls_t 335 The elm_tls_t definition. 336 */ 337 typedef struct vglite_elm_tls { 338 el_Context gContext; 339 } elm_tls_t; 340 341 /* 342 API function prototypes. 343 */ 344 int add_object (el_Object *object); 345 int remove_object (el_Object *object); 346 el_Object *get_object (ElmHandle handle); 347 348 #ifdef __cplusplus 349 } 350 #endif 351 #endif /* VELM_H_ */ 352