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 #include "elm_precom.h"
29 #include "elm_os.h"
30 #include "vg_lite_os.h"
31 #if (VG_RENDER_TEXT==1)
32 #include "elm_text.h"
33 #endif /* VG_RENDER_TEXT */
34
35 /* Prototypes */
36 static int _initialize_elm(uint32_t width, uint32_t height);
37
38 /* Initialize vg_lite related. */
_initialize_vglite(int32_t width,int32_t height)39 static int _initialize_vglite(int32_t width, int32_t height)
40 {
41 vg_lite_error_t error = VG_LITE_SUCCESS;
42
43 error = vg_lite_init(width, height);
44
45 return (error == VG_LITE_SUCCESS);
46 }
47
48 /* Initialize elm global objects. */
_initialize_elm(uint32_t width,uint32_t height)49 static int _initialize_elm(uint32_t width, uint32_t height)
50 {
51 vg_lite_error_t error;
52 elm_tls_t* elm_tls;
53 elm_tls = (elm_tls_t *)elm_os_get_tls();
54 if (elm_tls == NULL) {
55 elm_tls = (elm_tls_t *)vg_lite_os_malloc(sizeof(elm_tls_t));
56 error = elm_os_set_tls((void *) elm_tls);
57 if(error != VG_LITE_SUCCESS)
58 return error;
59 }
60
61 int i;
62
63 elm_tls->gContext.version = VERSION;
64 elm_tls->gContext.currentHandle = (ELM_NULL_HANDLE + 1); /* Reserve handle 0 for error */
65 elm_tls->gContext.objectCount = 0;
66 elm_tls->gContext.tessellation_width = width;
67 elm_tls->gContext.tessellation_height = height;
68 elm_tls->gContext.vector_id = -1;
69
70 for (i = 0; i < SLOT_COUNT; i++) {
71 elm_tls->gContext.object_slots[i] = NULL;
72 }
73
74 #if (RTOS && DDRLESS) || BAREMETAL
75 for (i = 0; i < sizeof(elm_tls->gContext.objmap_ebo) / 4; i++) {
76 elm_tls->gContext.objmap_ebo[i] = 0;
77 }
78 for (i = 0; i < sizeof(elm_tls->gContext.objmap_evo) / 4; i++) {
79 elm_tls->gContext.objmap_evo[i] = 0;
80 }
81 for (i = 0; i < sizeof(elm_tls->gContext.objmap_group) / 4; i++) {
82 elm_tls->gContext.objmap_group[i] = 0;
83 }
84 for (i = 0; i < sizeof(elm_tls->gContext.objmap_grad) / 4; i++) {
85 elm_tls->gContext.objmap_grad[i] = 0;
86 }
87
88 elm_tls->gContext.objcounter_grad = 0;
89 elm_tls->gContext.objcounter_evo = 0;
90 elm_tls->gContext.objcounter_ebo = 0;
91 elm_tls->gContext.objcounter_group = 0;
92 #endif
93 return 1;
94 }
95
96 /* Terminate vg_lite related. */
_terminate_vglite(void)97 static void _terminate_vglite(void)
98 {
99 vg_lite_close();
100 }
101
102 /* Terminate elm global objects. */
_terminate_elm(void)103 static void _terminate_elm(void)
104 {
105 #if (VG_RENDER_TEXT==1)
106 _release_default_text_parameters();
107 #endif
108 elm_os_reset_tls();
109 }
110
111 /*!
112 @abstract Initialize Elementary context.
113
114 @discussion
115 It should be called as the first function of Elemenatary libary, which initializes the library. Currently
116 Elementary library doesn't support context concept, neigher multi-threading. Elementary library defines
117 origin of coordinate system is at top-left.
118
119 @param none
120
121 @return none
122 */
ElmInitialize(uint32_t width,uint32_t height)123 BOOL ElmInitialize(uint32_t width, uint32_t height)
124 {
125 BOOL result = TRUE;
126
127 do {
128 result = _initialize_vglite((int32_t)width, (int32_t)height);
129
130 if (!result)
131 break;
132
133 result = _initialize_elm(width, height);
134
135 if (!result)
136 break;
137 }
138 while (0);
139
140 #if (VG_RENDER_TEXT==1)
141 initialize_elm_text();
142 #endif /* VG_RENDER_TEXT */
143 return result;
144 }
145
146 /*!
147 @abstract Terminate Elementary context.
148
149 @discussion
150 This should be called when an app exits. It frees all the resource.
151
152 @param none
153
154 @return none
155 */
ElmTerminate(void)156 void ElmTerminate(void)
157 {
158 _terminate_elm();
159 _terminate_vglite();
160 }
161