1 |
|
|
/*************************************************************************** |
2 |
|
|
* Copyright (c) 2024 Microsoft Corporation |
3 |
|
|
* Copyright (c) 2026-present Eclipse ThreadX contributors |
4 |
|
|
* |
5 |
|
|
* This program and the accompanying materials are made available under the |
6 |
|
|
* terms of the MIT License which is available at |
7 |
|
|
* https://opensource.org/licenses/MIT. |
8 |
|
|
* |
9 |
|
|
* SPDX-License-Identifier: MIT |
10 |
|
|
**************************************************************************/ |
11 |
|
|
|
12 |
|
|
|
13 |
|
|
/**************************************************************************/ |
14 |
|
|
/**************************************************************************/ |
15 |
|
|
/** */ |
16 |
|
|
/** GUIX Component */ |
17 |
|
|
/** */ |
18 |
|
|
/** System Management (System) */ |
19 |
|
|
/** */ |
20 |
|
|
/**************************************************************************/ |
21 |
|
|
|
22 |
|
|
#define GX_SOURCE_CODE |
23 |
|
|
|
24 |
|
|
|
25 |
|
|
/* Locate GUIX system data in this file. */ |
26 |
|
|
|
27 |
|
|
#define GX_SYSTEM_INIT |
28 |
|
|
|
29 |
|
|
|
30 |
|
|
/* Include necessary system files. */ |
31 |
|
|
|
32 |
|
|
#include "gx_api.h" |
33 |
|
|
#include "gx_system.h" |
34 |
|
|
#include "gx_utility.h" |
35 |
|
|
#include "gx_animation.h" |
36 |
|
|
|
37 |
|
|
/**************************************************************************/ |
38 |
|
|
/* */ |
39 |
|
|
/* FUNCTION RELEASE */ |
40 |
|
|
/* */ |
41 |
|
|
/* _gx_system_initialize PORTABLE C */ |
42 |
|
|
/* 6.1.3 */ |
43 |
|
|
/* AUTHOR */ |
44 |
|
|
/* */ |
45 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
46 |
|
|
/* */ |
47 |
|
|
/* DESCRIPTION */ |
48 |
|
|
/* */ |
49 |
|
|
/* This service initializes GUIX. */ |
50 |
|
|
/* */ |
51 |
|
|
/* INPUT */ |
52 |
|
|
/* */ |
53 |
|
|
/* None */ |
54 |
|
|
/* */ |
55 |
|
|
/* OUTPUT */ |
56 |
|
|
/* */ |
57 |
|
|
/* status Completion status */ |
58 |
|
|
/* */ |
59 |
|
|
/* CALLS */ |
60 |
|
|
/* */ |
61 |
|
|
/* memset Clear various data structures */ |
62 |
|
|
/* _gx_system_error_process Process system errors */ |
63 |
|
|
/* _gx_utility_ltoa Int to ASCII conversion */ |
64 |
|
|
/* _gx_utility_string_length_check Test string length */ |
65 |
|
|
/* tx_timer_create Create ThreadX Timer */ |
66 |
|
|
/* tx_mutex_create Create system protection mutex*/ |
67 |
|
|
/* tx_queue_create Create system event queue */ |
68 |
|
|
/* tx_queue_delete Delete system event queue */ |
69 |
|
|
/* */ |
70 |
|
|
/* CALLED BY */ |
71 |
|
|
/* */ |
72 |
|
|
/* Application Code */ |
73 |
|
|
/* */ |
74 |
|
|
/**************************************************************************/ |
75 |
|
729 |
UINT _gx_system_initialize(VOID) |
76 |
|
|
{ |
77 |
|
|
#ifndef TX_DISABLE_ERROR_CHECKING |
78 |
|
|
UINT status; |
79 |
|
|
#endif |
80 |
|
|
UINT index; |
81 |
|
|
UINT length; |
82 |
|
|
|
83 |
|
|
/* Set linked list pointers to NULL. */ |
84 |
|
|
|
85 |
|
729 |
_gx_system_display_created_list = GX_NULL; |
86 |
|
729 |
_gx_system_canvas_created_list = GX_NULL; |
87 |
|
729 |
_gx_system_root_window_created_list = GX_NULL; |
88 |
|
729 |
_gx_system_focus_owner = GX_NULL; |
89 |
|
|
|
90 |
|
|
/* Clear all the created counters. */ |
91 |
|
729 |
_gx_system_display_created_count = 0; |
92 |
|
729 |
_gx_system_canvas_created_count = 0; |
93 |
|
|
|
94 |
|
|
/* initialize the draw context stack */ |
95 |
|
729 |
_gx_system_draw_context_stack_end = _gx_system_draw_context_stack; |
96 |
|
729 |
_gx_system_draw_context_stack_end += GX_MAX_CONTEXT_NESTING; |
97 |
|
729 |
_gx_system_current_draw_context = GX_NULL; |
98 |
|
|
|
99 |
|
|
/* initialize gradient list */ |
100 |
|
729 |
_gx_system_gradient_list = GX_NULL; |
101 |
|
|
|
102 |
|
|
/* initialize the input capture stack */ |
103 |
|
729 |
memset(_gx_system_input_capture_stack, 0, sizeof(GX_WIDGET *) * GX_MAX_INPUT_CAPTURE_NESTING); |
104 |
|
729 |
_gx_system_capture_count = 0; |
105 |
|
729 |
_gx_system_input_owner = GX_NULL; |
106 |
|
|
|
107 |
|
|
/* initialize rich text context stack. */ |
108 |
|
729 |
_gx_system_rich_text_context_stack.gx_rich_text_context_stack_top = 0; |
109 |
|
729 |
_gx_system_rich_text_context_stack_save.gx_rich_text_context_stack_top = 0; |
110 |
|
|
|
111 |
|
|
/* initialize the lock count to 0 */ |
112 |
|
729 |
_gx_system_lock_nesting = 0; |
113 |
|
|
|
114 |
|
|
/* no thread has GUIX locked */ |
115 |
|
|
|
116 |
|
729 |
_gx_system_lock_thread = GX_NULL; |
117 |
|
|
|
118 |
|
|
/* initialize default vertical scrollbar appearance */ |
119 |
|
729 |
memset(&_gx_system_vertical_scrollbar_appearance, 0, sizeof(GX_SCROLLBAR_APPEARANCE)); |
120 |
|
|
|
121 |
|
729 |
_gx_system_vertical_scrollbar_style = GX_SCROLLBAR_VERTICAL | GX_SCROLLBAR_RELATIVE_THUMB | GX_SCROLLBAR_END_BUTTONS; |
122 |
|
|
|
123 |
|
729 |
_gx_system_vertical_scrollbar_appearance.gx_scroll_width = 20; |
124 |
|
729 |
_gx_system_vertical_scrollbar_appearance.gx_scroll_thumb_width = 18; |
125 |
|
729 |
_gx_system_vertical_scrollbar_appearance.gx_scroll_thumb_color = GX_COLOR_ID_SCROLL_BUTTON; |
126 |
|
729 |
_gx_system_vertical_scrollbar_appearance.gx_scroll_thumb_border_color = GX_COLOR_ID_SCROLL_BUTTON; |
127 |
|
729 |
_gx_system_vertical_scrollbar_appearance.gx_scroll_button_color = GX_COLOR_ID_SCROLL_BUTTON; |
128 |
|
729 |
_gx_system_vertical_scrollbar_appearance.gx_scroll_thumb_travel_min = 20; |
129 |
|
729 |
_gx_system_vertical_scrollbar_appearance.gx_scroll_thumb_travel_max = 20; |
130 |
|
729 |
_gx_system_vertical_scrollbar_appearance.gx_scroll_thumb_border_style = GX_STYLE_BORDER_THIN; |
131 |
|
|
|
132 |
|
|
/* initialize default horizontal scrollbar appearance */ |
133 |
|
729 |
_gx_system_horizontal_scrollbar_appearance = _gx_system_vertical_scrollbar_appearance; |
134 |
|
729 |
_gx_system_horizontal_scrollbar_style = GX_SCROLLBAR_HORIZONTAL | GX_SCROLLBAR_RELATIVE_THUMB | GX_SCROLLBAR_END_BUTTONS; |
135 |
|
|
|
136 |
|
|
#if defined(GX_DYNAMIC_BIDI_TEXT_SUPPORT) |
137 |
|
|
_gx_system_bidi_text_enabled = GX_FALSE; |
138 |
|
|
#endif |
139 |
|
|
|
140 |
|
|
#if defined(GX_THAI_GLYPH_SHAPING_SUPPORT) |
141 |
|
|
_gx_system_text_render_style = 0; |
142 |
|
|
#endif |
143 |
|
|
|
144 |
|
|
/* initialize theme table information */ |
145 |
|
729 |
_gx_system_theme_table = GX_NULL; |
146 |
|
729 |
_gx_system_theme_table_size = 0; |
147 |
|
729 |
_gx_system_active_theme = 0; |
148 |
|
|
|
149 |
|
|
/* Initialize the version string */ |
150 |
|
729 |
memset(_gx_system_version_string, 0, GX_VERSION_STRING_LENGTH); |
151 |
|
|
|
152 |
|
|
/* We are allocating 16 bytes for the version string. MAJOR_VERSION and MINOR_VERSION do not exceed 3 bytes each |
153 |
|
|
(version 999.999). Therefore the code below will not exceed the 16 byte buffer. (8 + 3 + '.' + 3 + NULL). */ |
154 |
|
729 |
length = sizeof("Version ") - 1; |
155 |
|
|
|
156 |
|
|
/* Copy "Version " to version string. */ |
157 |
|
729 |
memcpy(_gx_system_version_string, "Version ", length); /* Use case of memcpy is verified. */ |
158 |
|
|
|
159 |
|
729 |
index = length; |
160 |
|
|
|
161 |
|
|
/* Convert major version value to version string. */ |
162 |
|
729 |
_gx_utility_ltoa(__GUIX_MAJOR_VERSION, _gx_system_version_string + index, GX_VERSION_STRING_LENGTH - index); |
163 |
|
|
|
164 |
|
|
/* Calculate major version string length. */ |
165 |
|
729 |
_gx_utility_string_length_check(_gx_system_version_string + index, &length, GX_VERSION_STRING_LENGTH - index); |
166 |
|
|
|
167 |
|
729 |
index += length; |
168 |
|
729 |
_gx_system_version_string[index++] = '.'; |
169 |
|
|
|
170 |
|
|
/* Convert minor version value to version string. */ |
171 |
|
729 |
_gx_utility_ltoa(__GUIX_MINOR_VERSION, _gx_system_version_string + index, GX_VERSION_STRING_LENGTH - index); |
172 |
|
|
|
173 |
|
|
/* Initialize the system timers */ |
174 |
|
|
|
175 |
|
729 |
memset(_gx_system_timer_memory, 0, sizeof(GX_TIMER) * GX_MAX_ACTIVE_TIMERS); |
176 |
|
729 |
_gx_system_free_timer_list = _gx_system_timer_memory; |
177 |
|
729 |
_gx_system_active_timer_list = GX_NULL; |
178 |
|
|
|
179 |
|
|
/* link all the timers in the timer free list */ |
180 |
✓✓ |
23328 |
for (index = 0; index < GX_MAX_ACTIVE_TIMERS - 1; index++) |
181 |
|
|
{ |
182 |
|
22599 |
_gx_system_timer_memory[index].gx_timer_next = &_gx_system_timer_memory[index + 1]; |
183 |
|
|
} |
184 |
|
|
|
185 |
|
|
/* initialize pen tracking variables */ |
186 |
|
729 |
_gx_system_last_clock = 0; |
187 |
|
729 |
_gx_system_clock_delta = 0; |
188 |
|
729 |
_gx_system_last_pen_point.gx_point_x = 0; |
189 |
|
729 |
_gx_system_last_pen_point.gx_point_y = 0; |
190 |
|
729 |
_gx_system_pen_speed_x = 0; |
191 |
|
729 |
_gx_system_pen_speed_y = 0; |
192 |
|
|
|
193 |
|
|
/* initialize touch configuration information */ |
194 |
|
729 |
_gx_system_pen_configuration.gx_pen_configuration_min_drag_dist = 80; |
195 |
|
729 |
_gx_system_pen_configuration.gx_pen_configuration_max_pen_speed_ticks = 10; |
196 |
|
|
|
197 |
|
|
/* Initialize free animation pool */ |
198 |
|
|
#if (GX_ANIMATION_POOL_SIZE > 0) |
199 |
|
|
/* link all of the animation blocks into free list */ |
200 |
✓✓ |
4374 |
for (index = 0; index < GX_ANIMATION_POOL_SIZE - 1; index++) |
201 |
|
|
{ |
202 |
|
3645 |
_gx_animation_create(&_gx_system_animation_pool[index]); |
203 |
|
3645 |
_gx_system_animation_pool[index].gx_animation_next = &_gx_system_animation_pool[index + 1]; |
204 |
|
|
} |
205 |
|
729 |
_gx_system_animation_free_list = _gx_system_animation_pool; |
206 |
|
|
#endif |
207 |
|
|
|
208 |
|
|
/* initialize the active animation list */ |
209 |
|
729 |
_gx_system_animation_list = GX_NULL; |
210 |
|
|
|
211 |
|
|
/* initialize memory allocators */ |
212 |
|
729 |
_gx_system_memory_allocator = GX_NULL; |
213 |
|
729 |
_gx_system_memory_free = GX_NULL; |
214 |
|
|
|
215 |
|
|
/* Initialize the viewport storage */ |
216 |
|
|
|
217 |
|
729 |
_gx_system_free_views = _gx_system_view_memory; |
218 |
|
|
|
219 |
✓✓ |
23328 |
for (index = 0; index < GX_MAX_VIEWS - 1; index++) |
220 |
|
|
{ |
221 |
|
22599 |
_gx_system_free_views -> gx_view_next = (_gx_system_free_views + 1); |
222 |
|
22599 |
_gx_system_free_views = _gx_system_free_views -> gx_view_next; |
223 |
|
|
} |
224 |
|
729 |
_gx_system_free_views -> gx_view_next = GX_NULL; |
225 |
|
729 |
_gx_system_free_views = _gx_system_view_memory; |
226 |
|
|
|
227 |
|
|
/* Initialize the system error information. */ |
228 |
|
729 |
_gx_system_last_error = GX_SUCCESS; |
229 |
|
729 |
_gx_system_error_count = 0; |
230 |
|
|
|
231 |
|
729 |
_gx_system_clipboard = GX_NULL; |
232 |
|
729 |
_gx_system_clipboard_size = 0; |
233 |
|
|
|
234 |
|
|
/* Initiate system screen stack controler. */ |
235 |
|
729 |
memset(&_gx_system_screen_stack, 0, sizeof(GX_SCREEN_STACK_CONTROL)); |
236 |
|
|
|
237 |
|
|
/* Create the required ThreadX objects. */ |
238 |
|
|
|
239 |
|
|
#ifdef GX_THREADX_BINDING |
240 |
|
|
/* First initialize all ThreadX objects to 0. */ |
241 |
|
729 |
memset(&_gx_system_event_queue, 0, sizeof(_gx_system_event_queue)); |
242 |
|
729 |
memset(&_gx_system_protect, 0, sizeof(_gx_system_protect)); |
243 |
|
|
|
244 |
|
|
/* Check the validity of the GX_EVENT_SIZE constant. */ |
245 |
|
|
if (GX_EVENT_SIZE < sizeof(GX_EVENT)) |
246 |
|
|
{ |
247 |
|
|
|
248 |
|
|
/* The constant GX_EVENT_SIZE is not large enough to hold a GX_EVENT type, which is a system |
249 |
|
|
error. GX_EVENT_SIZE must be redefined and the GUIX library must be rebuilt. */ |
250 |
|
|
|
251 |
|
|
/* Call system error handler. */ |
252 |
|
|
_gx_system_error_process(GX_SYSTEM_EVENT_SIZE_MISMATCH); |
253 |
|
|
|
254 |
|
|
/* Return error! */ |
255 |
|
|
return(GX_SYSTEM_ERROR); |
256 |
|
|
} |
257 |
|
|
|
258 |
|
|
#ifndef GX_DISABLE_THREADX_TIMER_SOURCE |
259 |
|
729 |
memset(&_gx_system_timer, 0, sizeof(_gx_system_timer)); |
260 |
|
|
|
261 |
|
|
/* create the ThreadX timer that drives all GUIX timers */ |
262 |
|
729 |
tx_timer_create(&_gx_system_timer, "guix timer", _gx_system_timer_expiration, 0, |
263 |
|
|
GX_SYSTEM_TIMER_TICKS, GX_SYSTEM_TIMER_TICKS, TX_NO_ACTIVATE); |
264 |
|
|
#endif |
265 |
|
|
|
266 |
|
|
#ifdef TX_DISABLE_ERROR_CHECKING |
267 |
|
729 |
tx_queue_create(&_gx_system_event_queue, "GUIX System Event Queue", (GX_EVENT_SIZE / sizeof(ULONG)), |
268 |
|
|
_gx_system_event_queue_memory, sizeof(_gx_system_event_queue_memory)); |
269 |
|
|
#else |
270 |
|
|
/* Create the system event queue. */ |
271 |
|
|
status = tx_queue_create(&_gx_system_event_queue, "GUIX System Event Queue", (GX_EVENT_SIZE / sizeof(ULONG)), |
272 |
|
|
_gx_system_event_queue_memory, sizeof(_gx_system_event_queue_memory)); |
273 |
|
|
|
274 |
|
|
/* Determine if the event queue creation was successful. */ |
275 |
|
|
if (status != TX_SUCCESS) |
276 |
|
|
{ |
277 |
|
|
|
278 |
|
|
/* Queue create failed - call system error handler. */ |
279 |
|
|
_gx_system_error_process(GX_SYSTEM_QUEUE_CREATE_FAILED); |
280 |
|
|
|
281 |
|
|
/* Return error! */ |
282 |
|
|
return(GX_SYSTEM_ERROR); |
283 |
|
|
} |
284 |
|
|
#endif |
285 |
|
|
|
286 |
|
|
#ifdef TX_DISABLE_ERROR_CHECKING |
287 |
|
729 |
tx_mutex_create(&_gx_system_protect, "GUIX System Protection", TX_NO_INHERIT); |
288 |
|
|
#else |
289 |
|
|
/* Create the system protection mutex. */ |
290 |
|
|
status = tx_mutex_create(&_gx_system_protect, "GUIX System Protection", TX_NO_INHERIT); |
291 |
|
|
|
292 |
|
|
/* Determine if the mutex creation was successful. */ |
293 |
|
|
if (status != TX_SUCCESS) |
294 |
|
|
{ |
295 |
|
|
|
296 |
|
|
/* Mutex create failed - call system error handler. */ |
297 |
|
|
_gx_system_error_process(GX_SYSTEM_MUTEX_CREATE_FAILED); |
298 |
|
|
|
299 |
|
|
/* Delete the event queue. */ |
300 |
|
|
tx_queue_delete(&_gx_system_event_queue); |
301 |
|
|
|
302 |
|
|
/* Return error! */ |
303 |
|
|
return(GX_SYSTEM_ERROR); |
304 |
|
|
} |
305 |
|
|
#endif |
306 |
|
|
|
307 |
|
|
/* initialize GUIX thread here. It is started later by gx_system_start() */ |
308 |
|
729 |
memset(&_gx_system_thread, 0, sizeof(_gx_system_thread)); |
309 |
|
|
|
310 |
|
|
#ifdef TX_DISABLE_ERROR_CHECKING |
311 |
|
729 |
tx_thread_create(&_gx_system_thread, "GUIX System Thread", |
312 |
|
|
_gx_system_thread_entry, 0, |
313 |
|
|
_gx_system_thread_stack, sizeof(_gx_system_thread_stack), |
314 |
|
|
GX_SYSTEM_THREAD_PRIORITY, GX_SYSTEM_THREAD_PRIORITY, |
315 |
|
|
GX_SYSTEM_THREAD_TIMESLICE, TX_DONT_START); |
316 |
|
|
#else |
317 |
|
|
status = tx_thread_create(&_gx_system_thread, "GUIX System Thread", |
318 |
|
|
_gx_system_thread_entry, 0, |
319 |
|
|
_gx_system_thread_stack, sizeof(_gx_system_thread_stack), |
320 |
|
|
GX_SYSTEM_THREAD_PRIORITY, GX_SYSTEM_THREAD_PRIORITY, |
321 |
|
|
GX_SYSTEM_THREAD_TIMESLICE, TX_DONT_START); |
322 |
|
|
|
323 |
|
|
if (status != TX_SUCCESS) |
324 |
|
|
{ |
325 |
|
|
/* delete other resources */ |
326 |
|
|
tx_queue_delete(&_gx_system_event_queue); |
327 |
|
|
|
328 |
|
|
/* Delete the mutex. */ |
329 |
|
|
tx_mutex_delete(&_gx_system_protect); |
330 |
|
|
|
331 |
|
|
/* thread create failed - call system error handler. */ |
332 |
|
|
_gx_system_error_process(GX_SYSTEM_THREAD_CREATE_FAILED); |
333 |
|
|
return(GX_SYSTEM_ERROR); |
334 |
|
|
} |
335 |
|
|
#endif |
336 |
|
|
#else |
337 |
|
|
GX_RTOS_BINDING_INITIALIZE; |
338 |
|
|
#endif |
339 |
|
|
|
340 |
|
|
/* Return successful completion. */ |
341 |
|
729 |
return(GX_SUCCESS); |
342 |
|
|
} |
343 |
|
|
|