fix(Windows): use global lock (#6425)

This commit is contained in:
Liam
2024-07-08 05:38:47 +02:00
committed by GitHub
parent f8c26ea150
commit af041657aa
6 changed files with 65 additions and 28 deletions
+1
View File
@@ -1699,6 +1699,7 @@ menu "LVGL configuration"
config LV_USE_WINDOWS config LV_USE_WINDOWS
bool "Use LVGL Windows backend" bool "Use LVGL Windows backend"
depends on LV_OS_WINDOWS
default n default n
config LV_USE_OPENGLES config LV_USE_OPENGLES
+4
View File
@@ -79,6 +79,8 @@ Usage
return -1; return -1;
} }
lv_lock();
lv_indev_t* pointer_device = lv_windows_acquire_pointer_indev(display); lv_indev_t* pointer_device = lv_windows_acquire_pointer_indev(display);
if (!pointer_device) if (!pointer_device)
{ {
@@ -99,6 +101,8 @@ Usage
lv_demo_widgets(); lv_demo_widgets();
lv_unlock();
while (1) while (1)
{ {
uint32_t time_till_next = lv_timer_handler(); uint32_t time_till_next = lv_timer_handler();
+45 -11
View File
@@ -36,6 +36,13 @@ static void lv_windows_delay_callback(uint32_t ms);
static void lv_windows_check_display_existence_timer_callback( static void lv_windows_check_display_existence_timer_callback(
lv_timer_t * timer); lv_timer_t * timer);
static bool lv_windows_window_message_callback_nolock(
HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam,
LRESULT * plResult);
static LRESULT CALLBACK lv_windows_window_message_callback( static LRESULT CALLBACK lv_windows_window_message_callback(
HWND hWnd, HWND hWnd,
UINT uMsg, UINT uMsg,
@@ -452,11 +459,12 @@ static BOOL lv_windows_enable_child_window_dpi_message(
return function(WindowHandle, TRUE); return function(WindowHandle, TRUE);
} }
static LRESULT CALLBACK lv_windows_window_message_callback( static bool lv_windows_window_message_callback_nolock(
HWND hWnd, HWND hWnd,
UINT uMsg, UINT uMsg,
WPARAM wParam, WPARAM wParam,
LPARAM lParam) LPARAM lParam,
LRESULT * plResult)
{ {
switch(uMsg) { switch(uMsg) {
case WM_CREATE: { case WM_CREATE: {
@@ -646,15 +654,15 @@ static LRESULT CALLBACK lv_windows_window_message_callback(
lv_windows_window_context_t * context = (lv_windows_window_context_t *)( lv_windows_window_context_t * context = (lv_windows_window_context_t *)(
lv_windows_get_window_context(hWnd)); lv_windows_get_window_context(hWnd));
if(context) { if(context) {
LRESULT lResult = 0;
if(context->pointer.indev && if(context->pointer.indev &&
lv_windows_pointer_device_window_message_handler( lv_windows_pointer_device_window_message_handler(
hWnd, hWnd,
uMsg, uMsg,
wParam, wParam,
lParam, lParam,
&lResult)) { plResult)) {
return lResult; // Handled
return true;
} }
else if(context->keypad.indev && else if(context->keypad.indev &&
lv_windows_keypad_device_window_message_handler( lv_windows_keypad_device_window_message_handler(
@@ -662,8 +670,9 @@ static LRESULT CALLBACK lv_windows_window_message_callback(
uMsg, uMsg,
wParam, wParam,
lParam, lParam,
&lResult)) { plResult)) {
return lResult; // Handled
return true;
} }
else if(context->encoder.indev && else if(context->encoder.indev &&
lv_windows_encoder_device_window_message_handler( lv_windows_encoder_device_window_message_handler(
@@ -671,16 +680,41 @@ static LRESULT CALLBACK lv_windows_window_message_callback(
uMsg, uMsg,
wParam, wParam,
lParam, lParam,
&lResult)) { plResult)) {
return lResult; // Handled
return true;
} }
} }
return DefWindowProcW(hWnd, uMsg, wParam, lParam); // Not Handled
return false;
} }
} }
return 0; // Handled
*plResult = 0;
return true;
}
static LRESULT CALLBACK lv_windows_window_message_callback(
HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
lv_lock();
LRESULT lResult = 0;
bool Handled = lv_windows_window_message_callback_nolock(
hWnd,
uMsg,
wParam,
lParam,
&lResult);
lv_unlock();
return Handled ? lResult : DefWindowProcW(hWnd, uMsg, wParam, lParam);
} }
#endif // LV_USE_WINDOWS #endif // LV_USE_WINDOWS
+13 -2
View File
@@ -1,4 +1,4 @@
/** /**
* @file lv_windows_context.h * @file lv_windows_context.h
* *
*/ */
@@ -19,8 +19,20 @@ extern "C" {
#if LV_USE_WINDOWS #if LV_USE_WINDOWS
#if LV_USE_OS != LV_OS_WINDOWS
#error [lv_windows] LV_OS_WINDOWS is required. Enable it in lv_conf.h (LV_USE_OS LV_OS_WINDOWS)
#endif
#include <windows.h> #include <windows.h>
#ifndef CREATE_WAITABLE_TIMER_MANUAL_RESET
#define CREATE_WAITABLE_TIMER_MANUAL_RESET 0x00000001
#endif
#ifndef CREATE_WAITABLE_TIMER_HIGH_RESOLUTION
#define CREATE_WAITABLE_TIMER_HIGH_RESOLUTION 0x00000002
#endif
/********************* /*********************
* DEFINES * DEFINES
*********************/ *********************/
@@ -41,7 +53,6 @@ typedef struct _lv_windows_keypad_queue_item_t {
} lv_windows_keypad_queue_item_t; } lv_windows_keypad_queue_item_t;
typedef struct _lv_windows_keypad_context_t { typedef struct _lv_windows_keypad_context_t {
CRITICAL_SECTION mutex;
lv_ll_t queue; lv_ll_t queue;
uint16_t utf16_high_surrogate; uint16_t utf16_high_surrogate;
uint16_t utf16_low_surrogate; uint16_t utf16_low_surrogate;
+1 -15
View File
@@ -1,4 +1,4 @@
/** /**
* @file lv_windows_input.c * @file lv_windows_input.c
* *
*/ */
@@ -128,7 +128,6 @@ lv_indev_t * lv_windows_acquire_keypad_indev(lv_display_t * display)
} }
if(!context->keypad.indev) { if(!context->keypad.indev) {
InitializeCriticalSection(&context->keypad.mutex);
_lv_ll_init( _lv_ll_init(
&context->keypad.queue, &context->keypad.queue,
sizeof(lv_windows_keypad_queue_item_t)); sizeof(lv_windows_keypad_queue_item_t));
@@ -421,8 +420,6 @@ static void lv_windows_keypad_driver_read_callback(
return; return;
} }
EnterCriticalSection(&context->keypad.mutex);
lv_windows_keypad_queue_item_t * current = (lv_windows_keypad_queue_item_t *)( lv_windows_keypad_queue_item_t * current = (lv_windows_keypad_queue_item_t *)(
_lv_ll_get_head(&context->keypad.queue)); _lv_ll_get_head(&context->keypad.queue));
if(current) { if(current) {
@@ -434,8 +431,6 @@ static void lv_windows_keypad_driver_read_callback(
data->continue_reading = true; data->continue_reading = true;
} }
LeaveCriticalSection(&context->keypad.mutex);
} }
static void lv_windows_release_keypad_device_event_callback(lv_event_t * e) static void lv_windows_release_keypad_device_event_callback(lv_event_t * e)
@@ -456,7 +451,6 @@ static void lv_windows_release_keypad_device_event_callback(lv_event_t * e)
return; return;
} }
DeleteCriticalSection(&context->keypad.mutex);
_lv_ll_clear(&context->keypad.queue); _lv_ll_clear(&context->keypad.queue);
context->keypad.utf16_high_surrogate = 0; context->keypad.utf16_high_surrogate = 0;
context->keypad.utf16_low_surrogate = 0; context->keypad.utf16_low_surrogate = 0;
@@ -571,8 +565,6 @@ bool lv_windows_keypad_device_window_message_handler(
lv_windows_window_context_t * context = (lv_windows_window_context_t *)( lv_windows_window_context_t * context = (lv_windows_window_context_t *)(
lv_windows_get_window_context(hWnd)); lv_windows_get_window_context(hWnd));
if(context) { if(context) {
EnterCriticalSection(&context->keypad.mutex);
bool skip_translation = false; bool skip_translation = false;
uint32_t translated_key = 0; uint32_t translated_key = 0;
@@ -627,8 +619,6 @@ bool lv_windows_keypad_device_window_message_handler(
? LV_INDEV_STATE_RELEASED ? LV_INDEV_STATE_RELEASED
: LV_INDEV_STATE_PRESSED)); : LV_INDEV_STATE_PRESSED));
} }
LeaveCriticalSection(&context->keypad.mutex);
} }
break; break;
@@ -637,8 +627,6 @@ bool lv_windows_keypad_device_window_message_handler(
lv_windows_window_context_t * context = (lv_windows_window_context_t *)( lv_windows_window_context_t * context = (lv_windows_window_context_t *)(
lv_windows_get_window_context(hWnd)); lv_windows_get_window_context(hWnd));
if(context) { if(context) {
EnterCriticalSection(&context->keypad.mutex);
uint16_t raw_code_point = (uint16_t)(wParam); uint16_t raw_code_point = (uint16_t)(wParam);
if(raw_code_point >= 0x20 && raw_code_point != 0x7F) { if(raw_code_point >= 0x20 && raw_code_point != 0x7F) {
@@ -677,8 +665,6 @@ bool lv_windows_keypad_device_window_message_handler(
lvgl_code_point, lvgl_code_point,
LV_INDEV_STATE_RELEASED); LV_INDEV_STATE_RELEASED);
} }
LeaveCriticalSection(&context->keypad.mutex);
} }
break; break;
+1
View File
@@ -387,6 +387,7 @@ endif()
if(WIN32) if(WIN32)
add_definitions(-DLV_USE_LINUX_FBDEV=0) add_definitions(-DLV_USE_LINUX_FBDEV=0)
add_definitions(-DLV_USE_WINDOWS=1) add_definitions(-DLV_USE_WINDOWS=1)
add_definitions(-DLV_USE_OS=LV_OS_WINDOWS)
endif() endif()
# disable test targets for build only tests # disable test targets for build only tests