From 6187e7d8bec3119e9dda06da859fb069e7db481d Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 10 Apr 2024 17:03:11 +0800 Subject: [PATCH] 1 --- src/core/ohos/SDL_ohos.cpp | 34 ++++---- src/core/ohos/SDL_ohosthreadsafe.cpp | 118 +++++++++++++-------------- src/core/ohos/SDL_ohosthreadsafe.h | 2 +- 3 files changed, 77 insertions(+), 77 deletions(-) diff --git a/src/core/ohos/SDL_ohos.cpp b/src/core/ohos/SDL_ohos.cpp index 4c3fb1534..4203da4ab 100644 --- a/src/core/ohos/SDL_ohos.cpp +++ b/src/core/ohos/SDL_ohos.cpp @@ -114,7 +114,7 @@ void OHOS_NAPI_SetWindowResize(int x, int y, int w, int h) cJSON_AddNumberToObject(root, "y", y); cJSON_AddNumberToObject(root, "w", w); cJSON_AddNumberToObject(root, "h", h); - napi_status status = napi_call_threadsafe_function(napiCallback->tsfn, root, napi_tsfn_nonblocking); + napi_status status = napi_call_threadsafe_function(g_napiCallback->tsfn, root, napi_tsfn_nonblocking); if (status != napi_ok) { cJSON_free(root); } @@ -133,7 +133,7 @@ OHOS_NAPI_ShowTextInput(int x, int y, int w, int h) cJSON_AddNumberToObject(root, "y", y); cJSON_AddNumberToObject(root, "w", w); cJSON_AddNumberToObject(root, "h", h); - napi_status status = napi_call_threadsafe_function(napiCallback->tsfn, root, napi_tsfn_nonblocking); + napi_status status = napi_call_threadsafe_function(g_napiCallback->tsfn, root, napi_tsfn_nonblocking); if (status != napi_ok) { cJSON_free(root); } @@ -155,7 +155,7 @@ OHOS_NAPI_RequestPermission(const char *permission) } cJSON_AddNumberToObject(root, OHOS_TS_CALLBACK_TYPE, NAPI_CALLBACK_REQUEST_PERMISSION); cJSON_AddStringToObject(root, "permission", permission); - napi_status status = napi_call_threadsafe_function(napiCallback->tsfn, root, napi_tsfn_nonblocking); + napi_status status = napi_call_threadsafe_function(g_napiCallback->tsfn, root, napi_tsfn_nonblocking); if (status != napi_ok) { cJSON_free(root); } @@ -176,7 +176,7 @@ OHOS_NAPI_HideTextInput(int flag) } cJSON_AddNumberToObject(root, OHOS_TS_CALLBACK_TYPE, NAPI_CALLBACK_HIDE_TEXTINPUT); cJSON_AddNumberToObject(root, "flag", flag); - napi_status status = napi_call_threadsafe_function(napiCallback->tsfn, root, napi_tsfn_nonblocking); + napi_status status = napi_call_threadsafe_function(g_napiCallback->tsfn, root, napi_tsfn_nonblocking); if (status != napi_ok) { cJSON_free(root); } @@ -192,7 +192,7 @@ OHOS_NAPI_ShouldMinimizeOnFocusLoss(int flag) } cJSON_AddNumberToObject(root, OHOS_TS_CALLBACK_TYPE, NAPI_CALLBACK_SHOULD_MINIMIZEON_FOCUSLOSS); cJSON_AddNumberToObject(root, "flag", flag); - napi_status status = napi_call_threadsafe_function(napiCallback->tsfn, root, napi_tsfn_nonblocking); + napi_status status = napi_call_threadsafe_function(g_napiCallback->tsfn, root, napi_tsfn_nonblocking); if (status != napi_ok) { cJSON_free(root); } @@ -208,7 +208,7 @@ OHOS_NAPI_SetTitle(const char *title) } cJSON_AddNumberToObject(root, OHOS_TS_CALLBACK_TYPE, NAPI_CALLBACK_SET_TITLE); cJSON_AddStringToObject(root, "title", title); - napi_status status = napi_call_threadsafe_function(napiCallback->tsfn, root, napi_tsfn_nonblocking); + napi_status status = napi_call_threadsafe_function(g_napiCallback->tsfn, root, napi_tsfn_nonblocking); if (status != napi_ok) { cJSON_free(root); } @@ -224,7 +224,7 @@ OHOS_NAPI_SetWindowStyle(SDL_bool fullscreen) } cJSON_AddNumberToObject(root, OHOS_TS_CALLBACK_TYPE, NAPI_CALLBACK_SET_WINDOWSTYLE); cJSON_AddBoolToObject(root, "fullscreen", fullscreen); - napi_status status = napi_call_threadsafe_function(napiCallback->tsfn, root, napi_tsfn_nonblocking); + napi_status status = napi_call_threadsafe_function(g_napiCallback->tsfn, root, napi_tsfn_nonblocking); if (status != napi_ok) { cJSON_free(root); } @@ -240,7 +240,7 @@ OHOS_NAPI_ShowTextInputKeyboard(SDL_bool isshow) } cJSON_AddNumberToObject(root, OHOS_TS_CALLBACK_TYPE, NAPI_CALLBACK_SHOW_TEXTINPUTKEYBOARD); cJSON_AddBoolToObject(root, "isshow", isshow); - napi_status status = napi_call_threadsafe_function(napiCallback->tsfn, root, napi_tsfn_nonblocking); + napi_status status = napi_call_threadsafe_function(g_napiCallback->tsfn, root, napi_tsfn_nonblocking); if (status != napi_ok) { cJSON_free(root); } @@ -259,7 +259,7 @@ OHOS_NAPI_SetOrientation(int w, int h, int resizable, const char *hint) cJSON_AddNumberToObject(root, "h", h); cJSON_AddNumberToObject(root, "resizable", resizable); cJSON_AddStringToObject(root, "hint", hint); - napi_status status = napi_call_threadsafe_function(napiCallback->tsfn, root, napi_tsfn_nonblocking); + napi_status status = napi_call_threadsafe_function(g_napiCallback->tsfn, root, napi_tsfn_nonblocking); if (status != napi_ok) { cJSON_free(root); } @@ -284,7 +284,7 @@ OHOS_CreateCustomCursor(SDL_Surface *xcomponent, int hotX, int hotY) SDL_memcpy(buff, xcomponent->pixels, bufferSize); long long xcomponentpixel = (long long)buff; cJSON_AddNumberToObject(root, "xcomponentpixel", (double)xcomponentpixel); - napi_status status = napi_call_threadsafe_function(napiCallback->tsfn, root, napi_tsfn_nonblocking); + napi_status status = napi_call_threadsafe_function(g_napiCallback->tsfn, root, napi_tsfn_nonblocking); if (status != napi_ok) { cJSON_free(root); } @@ -303,7 +303,7 @@ OHOS_SetCustomCursor(int cursorID) return SDL_FALSE; } cJSON_AddNumberToObject(root, "cursorID", cursorID); - napi_status status = napi_call_threadsafe_function(napiCallback->tsfn, root, napi_tsfn_nonblocking); + napi_status status = napi_call_threadsafe_function(g_napiCallback->tsfn, root, napi_tsfn_nonblocking); if (status != napi_ok) { cJSON_free(root); } @@ -323,7 +323,7 @@ OHOS_SetSystemCursor(int cursorID) } cJSON_AddNumberToObject(root, OHOS_TS_CALLBACK_TYPE, NAPI_CALLBACK_SET_SYSTEMCURSOR); cJSON_AddNumberToObject(root, "cursorID", cursorID); - napi_status status = napi_call_threadsafe_function(napiCallback->tsfn, root, napi_tsfn_nonblocking); + napi_status status = napi_call_threadsafe_function(g_napiCallback->tsfn, root, napi_tsfn_nonblocking); if (status != napi_ok) { cJSON_free(root); } @@ -592,21 +592,21 @@ OHOS_NAPI_NativeSetup(void) static napi_value OHOS_NAPI_Init(napi_env env, napi_callback_info info) { - if (napiCallback == nullptr) { - napiCallback = std::make_unique(); + if (g_napiCallback == nullptr) { + g_napiCallback = std::make_unique(); } OHOS_NAPI_NativeSetup(); - napiCallback->env = env; + g_napiCallback->env = env; size_t argc = 1; napi_value args[1] = {nullptr}; napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - napi_create_reference(env, args[0], 1, &napiCallback->callbackRef); + napi_create_reference(env, args[0], 1, &g_napiCallback->callbackRef); napi_value resourceName = nullptr; napi_create_string_utf8(env, "SDLThreadSafe", NAPI_AUTO_LENGTH, &resourceName); napi_create_threadsafe_function(env, args[0], nullptr, resourceName, 0, 1, nullptr, nullptr, nullptr, OHOS_TS_Call, - &napiCallback->tsfn); + &g_napiCallback->tsfn); return nullptr; } diff --git a/src/core/ohos/SDL_ohosthreadsafe.cpp b/src/core/ohos/SDL_ohosthreadsafe.cpp index 61e7132f6..b5e43c8c4 100644 --- a/src/core/ohos/SDL_ohosthreadsafe.cpp +++ b/src/core/ohos/SDL_ohosthreadsafe.cpp @@ -36,7 +36,7 @@ extern "C" { #define OHOS_THREADSAFE_ARG4 4 #define OHOS_THREADSAFE_ARG5 5 -std::unique_ptr napiCallback = nullptr; +std::unique_ptr g_napiCallback = nullptr; static SDL_Thread *g_sdlMainThread; @@ -91,16 +91,16 @@ static void OHOS_TS_SetWindowResize(const cJSON *root) napi_value args[OHOS_THREADSAFE_ARG1] = {nullptr}; napi_value argv[OHOS_THREADSAFE_ARG4] = {nullptr}; - napi_create_int32(napiCallback->env, x, &argv[OHOS_THREADSAFE_ARG0]); - napi_create_int32(napiCallback->env, y, &argv[OHOS_THREADSAFE_ARG1]); - napi_create_int32(napiCallback->env, w, &argv[OHOS_THREADSAFE_ARG2]); - napi_create_int32(napiCallback->env, h, &argv[OHOS_THREADSAFE_ARG3]); + napi_create_int32(g_napiCallback->env, x, &argv[OHOS_THREADSAFE_ARG0]); + napi_create_int32(g_napiCallback->env, y, &argv[OHOS_THREADSAFE_ARG1]); + napi_create_int32(g_napiCallback->env, w, &argv[OHOS_THREADSAFE_ARG2]); + napi_create_int32(g_napiCallback->env, h, &argv[OHOS_THREADSAFE_ARG3]); napi_value callback = nullptr; - napi_get_reference_value(napiCallback->env, napiCallback->callbackRef, &callback); + napi_get_reference_value(g_napiCallback->env, g_napiCallback->callbackRef, &callback); napi_value jsMethod; - napi_get_named_property(napiCallback->env, callback, "nAPISetWindowResize", &jsMethod); - napi_call_function(napiCallback->env, nullptr, jsMethod, OHOS_THREADSAFE_ARG4, argv, nullptr); + napi_get_named_property(g_napiCallback->env, callback, "nAPISetWindowResize", &jsMethod); + napi_call_function(g_napiCallback->env, nullptr, jsMethod, OHOS_THREADSAFE_ARG4, argv, nullptr); } static void OHOS_TS_ShowTextInput(const cJSON *root) @@ -125,16 +125,16 @@ static void OHOS_TS_ShowTextInput(const cJSON *root) napi_value args[OHOS_THREADSAFE_ARG1] = {nullptr}; napi_value argv[OHOS_THREADSAFE_ARG4] = {nullptr}; - napi_create_int32(napiCallback->env, x, &argv[OHOS_THREADSAFE_ARG0]); - napi_create_int32(napiCallback->env, y, &argv[OHOS_THREADSAFE_ARG1]); - napi_create_int32(napiCallback->env, w, &argv[OHOS_THREADSAFE_ARG2]); - napi_create_int32(napiCallback->env, h, &argv[OHOS_THREADSAFE_ARG3]); + napi_create_int32(g_napiCallback->env, x, &argv[OHOS_THREADSAFE_ARG0]); + napi_create_int32(g_napiCallback->env, y, &argv[OHOS_THREADSAFE_ARG1]); + napi_create_int32(g_napiCallback->env, w, &argv[OHOS_THREADSAFE_ARG2]); + napi_create_int32(g_napiCallback->env, h, &argv[OHOS_THREADSAFE_ARG3]); napi_value callback = nullptr; - napi_get_reference_value(napiCallback->env, napiCallback->callbackRef, &callback); + napi_get_reference_value(g_napiCallback->env, g_napiCallback->callbackRef, &callback); napi_value jsMethod; - napi_get_named_property(napiCallback->env, callback, "showTextInput", &jsMethod); - napi_call_function(napiCallback->env, nullptr, jsMethod, OHOS_THREADSAFE_ARG4, argv, nullptr); + napi_get_named_property(g_napiCallback->env, callback, "showTextInput", &jsMethod); + napi_call_function(g_napiCallback->env, nullptr, jsMethod, OHOS_THREADSAFE_ARG4, argv, nullptr); return; } @@ -144,13 +144,13 @@ static void OHOS_TS_RequestPermission(const cJSON *root) const char *permission = data->valuestring; napi_value argv[OHOS_THREADSAFE_ARG1] = {nullptr}; - napi_create_string_utf8(napiCallback->env, permission, NAPI_AUTO_LENGTH, &argv[OHOS_THREADSAFE_ARG0]); + napi_create_string_utf8(g_napiCallback->env, permission, NAPI_AUTO_LENGTH, &argv[OHOS_THREADSAFE_ARG0]); napi_value callback = nullptr; - napi_get_reference_value(napiCallback->env, napiCallback->callbackRef, &callback); + napi_get_reference_value(g_napiCallback->env, g_napiCallback->callbackRef, &callback); napi_value jsMethod; - napi_get_named_property(napiCallback->env, callback, "requestPermission", &jsMethod); - napi_call_function(napiCallback->env, nullptr, jsMethod, OHOS_THREADSAFE_ARG1, argv, nullptr); + napi_get_named_property(g_napiCallback->env, callback, "requestPermission", &jsMethod); + napi_call_function(g_napiCallback->env, nullptr, jsMethod, OHOS_THREADSAFE_ARG1, argv, nullptr); return; } @@ -161,13 +161,13 @@ static void OHOS_TS_HideTextInput(const cJSON *root) int flag = data->valueint; size_t argc = OHOS_THREADSAFE_ARG1; napi_value argv[OHOS_THREADSAFE_ARG1] = {nullptr}; - napi_create_int32(napiCallback->env, flag, &argv[OHOS_THREADSAFE_ARG0]); + napi_create_int32(g_napiCallback->env, flag, &argv[OHOS_THREADSAFE_ARG0]); napi_value callback = nullptr; - napi_get_reference_value(napiCallback->env, napiCallback->callbackRef, &callback); + napi_get_reference_value(g_napiCallback->env, g_napiCallback->callbackRef, &callback); napi_value jsMethod; - napi_get_named_property(napiCallback->env, callback, "hideTextInput", &jsMethod); - napi_call_function(napiCallback->env, nullptr, jsMethod, OHOS_THREADSAFE_ARG1, argv, nullptr); + napi_get_named_property(g_napiCallback->env, callback, "hideTextInput", &jsMethod); + napi_call_function(g_napiCallback->env, nullptr, jsMethod, OHOS_THREADSAFE_ARG1, argv, nullptr); } static void OHOS_TS_ShouldMinimizeOnFocusLoss(const cJSON *root) @@ -176,13 +176,13 @@ static void OHOS_TS_ShouldMinimizeOnFocusLoss(const cJSON *root) int flag = data->valueint; size_t argc = OHOS_THREADSAFE_ARG1; napi_value argv[OHOS_THREADSAFE_ARG1] = {nullptr}; - napi_create_int32(napiCallback->env, flag, &argv[OHOS_THREADSAFE_ARG0]); + napi_create_int32(g_napiCallback->env, flag, &argv[OHOS_THREADSAFE_ARG0]); napi_value callback = nullptr; - napi_get_reference_value(napiCallback->env, napiCallback->callbackRef, &callback); + napi_get_reference_value(g_napiCallback->env, g_napiCallback->callbackRef, &callback); napi_value jsMethod; - napi_get_named_property(napiCallback->env, callback, "shouldMinimizeOnFocusLoss", &jsMethod); - napi_call_function(napiCallback->env, nullptr, jsMethod, OHOS_THREADSAFE_ARG1, argv, nullptr); + napi_get_named_property(g_napiCallback->env, callback, "shouldMinimizeOnFocusLoss", &jsMethod); + napi_call_function(g_napiCallback->env, nullptr, jsMethod, OHOS_THREADSAFE_ARG1, argv, nullptr); } static void OHOS_TS_SetTitle(const cJSON *root) @@ -192,13 +192,13 @@ static void OHOS_TS_SetTitle(const cJSON *root) size_t argc = OHOS_THREADSAFE_ARG1; napi_value args[OHOS_THREADSAFE_ARG1] = {nullptr}; napi_value argv[OHOS_THREADSAFE_ARG1] = {nullptr}; - napi_create_string_utf8(napiCallback->env, title, NAPI_AUTO_LENGTH, &argv[OHOS_THREADSAFE_ARG0]); + napi_create_string_utf8(g_napiCallback->env, title, NAPI_AUTO_LENGTH, &argv[OHOS_THREADSAFE_ARG0]); napi_value callback = nullptr; - napi_get_reference_value(napiCallback->env, napiCallback->callbackRef, &callback); + napi_get_reference_value(g_napiCallback->env, g_napiCallback->callbackRef, &callback); napi_value jsMethod; - napi_get_named_property(napiCallback->env, callback, "setTitle", &jsMethod); - napi_call_function(napiCallback->env, nullptr, jsMethod, OHOS_THREADSAFE_ARG1, argv, nullptr); + napi_get_named_property(g_napiCallback->env, callback, "setTitle", &jsMethod); + napi_call_function(g_napiCallback->env, nullptr, jsMethod, OHOS_THREADSAFE_ARG1, argv, nullptr); } static void OHOS_TS_SetWindowStyle(const cJSON *root) @@ -209,13 +209,13 @@ static void OHOS_TS_SetWindowStyle(const cJSON *root) napi_value args[OHOS_THREADSAFE_ARG1] = {nullptr}; napi_value argv[OHOS_THREADSAFE_ARG1] = {nullptr}; - napi_get_boolean(napiCallback->env, fullscreen, &argv[OHOS_THREADSAFE_ARG0]); + napi_get_boolean(g_napiCallback->env, fullscreen, &argv[OHOS_THREADSAFE_ARG0]); napi_value callback = nullptr; - napi_get_reference_value(napiCallback->env, napiCallback->callbackRef, &callback); + napi_get_reference_value(g_napiCallback->env, g_napiCallback->callbackRef, &callback); napi_value jsMethod; - napi_get_named_property(napiCallback->env, callback, "setWindowStyle", &jsMethod); - napi_call_function(napiCallback->env, nullptr, jsMethod, OHOS_THREADSAFE_ARG1, argv, nullptr); + napi_get_named_property(g_napiCallback->env, callback, "setWindowStyle", &jsMethod); + napi_call_function(g_napiCallback->env, nullptr, jsMethod, OHOS_THREADSAFE_ARG1, argv, nullptr); } static void OHOS_TS_ShowTextInputKeyboard(const cJSON *root) @@ -227,13 +227,13 @@ static void OHOS_TS_ShowTextInputKeyboard(const cJSON *root) napi_value args[OHOS_THREADSAFE_ARG1] = {nullptr}; napi_value argv[OHOS_THREADSAFE_ARG1] = {nullptr}; - napi_get_boolean(napiCallback->env, isshow, &argv[OHOS_THREADSAFE_ARG0]); + napi_get_boolean(g_napiCallback->env, isshow, &argv[OHOS_THREADSAFE_ARG0]); napi_value callback = nullptr; - napi_get_reference_value(napiCallback->env, napiCallback->callbackRef, &callback); + napi_get_reference_value(g_napiCallback->env, g_napiCallback->callbackRef, &callback); napi_value jsMethod; - napi_get_named_property(napiCallback->env, callback, "showTextInput2", &jsMethod); - napi_call_function(napiCallback->env, nullptr, jsMethod, OHOS_THREADSAFE_ARG1, argv, nullptr); + napi_get_named_property(g_napiCallback->env, callback, "showTextInput2", &jsMethod); + napi_call_function(g_napiCallback->env, nullptr, jsMethod, OHOS_THREADSAFE_ARG1, argv, nullptr); } static void OHOS_TS_SetOrientation(const cJSON *root) @@ -256,16 +256,16 @@ static void OHOS_TS_SetOrientation(const cJSON *root) size_t argc = OHOS_THREADSAFE_ARG4; napi_value args[OHOS_THREADSAFE_ARG4] = {nullptr}; napi_value argv[OHOS_THREADSAFE_ARG4] = {nullptr}; - napi_create_int32(napiCallback->env, w, &argv[OHOS_THREADSAFE_ARG0]); - napi_create_int32(napiCallback->env, h, &argv[OHOS_THREADSAFE_ARG1]); - napi_create_int32(napiCallback->env, resizable, &argv[OHOS_THREADSAFE_ARG2]); - napi_create_string_utf8(napiCallback->env, hint, NAPI_AUTO_LENGTH, &argv[OHOS_THREADSAFE_ARG3]); + napi_create_int32(g_napiCallback->env, w, &argv[OHOS_THREADSAFE_ARG0]); + napi_create_int32(g_napiCallback->env, h, &argv[OHOS_THREADSAFE_ARG1]); + napi_create_int32(g_napiCallback->env, resizable, &argv[OHOS_THREADSAFE_ARG2]); + napi_create_string_utf8(g_napiCallback->env, hint, NAPI_AUTO_LENGTH, &argv[OHOS_THREADSAFE_ARG3]); napi_value callback = nullptr; - napi_get_reference_value(napiCallback->env, napiCallback->callbackRef, &callback); + napi_get_reference_value(g_napiCallback->env, g_napiCallback->callbackRef, &callback); napi_value jsMethod; - napi_get_named_property(napiCallback->env, callback, "setOrientation", &jsMethod); - napi_call_function(napiCallback->env, nullptr, jsMethod, OHOS_THREADSAFE_ARG4, argv, nullptr); + napi_get_named_property(g_napiCallback->env, callback, "setOrientation", &jsMethod); + napi_call_function(g_napiCallback->env, nullptr, jsMethod, OHOS_THREADSAFE_ARG4, argv, nullptr); } static void OHOS_TS_CreateCustomCursor(const cJSON *root) @@ -302,19 +302,19 @@ static void OHOS_TS_CreateCustomCursor(const cJSON *root) createOps.pixelFormat = bytesPerPixel; createOps.alphaType = 0; size_t bufferSize = createOps.width * createOps.height * bytesPerPixel; - int32_t res = OH_PixelMap_CreatePixelMap(napiCallback->env, createOps, (uint8_t *)xcomponentpixelbuffer, + int32_t res = OH_PixelMap_CreatePixelMap(g_napiCallback->env, createOps, (uint8_t *)xcomponentpixelbuffer, bufferSize, &argv[OHOS_THREADSAFE_ARG0]); if (res != IMAGE_RESULT_SUCCESS || argv[OHOS_THREADSAFE_ARG0] == nullptr) { SDL_Log("OH_PixelMap_CreatePixelMap is failed"); } - napi_create_int32(napiCallback->env, hotX, &argv[OHOS_THREADSAFE_ARG1]); // coordinate x - napi_create_int32(napiCallback->env, hotY, &argv[OHOS_THREADSAFE_ARG2]); // coordinate y + napi_create_int32(g_napiCallback->env, hotX, &argv[OHOS_THREADSAFE_ARG1]); // coordinate x + napi_create_int32(g_napiCallback->env, hotY, &argv[OHOS_THREADSAFE_ARG2]); // coordinate y napi_value callback = nullptr; - napi_get_reference_value(napiCallback->env, napiCallback->callbackRef, &callback); + napi_get_reference_value(g_napiCallback->env, g_napiCallback->callbackRef, &callback); napi_value jsMethod; - napi_get_named_property(napiCallback->env, callback, "setCustomCursorandCreate", &jsMethod); - napi_call_function(napiCallback->env, nullptr, jsMethod, OHOS_THREADSAFE_ARG3, argv, nullptr); + napi_get_named_property(g_napiCallback->env, callback, "setCustomCursorandCreate", &jsMethod); + napi_call_function(g_napiCallback->env, nullptr, jsMethod, OHOS_THREADSAFE_ARG3, argv, nullptr); SDL_free(xcomponentpixelbuffer); return; } @@ -331,12 +331,12 @@ static void OHOS_SetSystemCursor(const cJSON *root) cJSON *data = cJSON_GetObjectItem(root, "cursorID"); int cursorID = data->valueint; napi_value argv[OHOS_THREADSAFE_ARG1] = {nullptr}; - napi_create_int32(napiCallback->env, cursorID, &argv[OHOS_THREADSAFE_ARG0]); + napi_create_int32(g_napiCallback->env, cursorID, &argv[OHOS_THREADSAFE_ARG0]); napi_value callback = nullptr; - napi_get_reference_value(napiCallback->env, napiCallback->callbackRef, &callback); + napi_get_reference_value(g_napiCallback->env, g_napiCallback->callbackRef, &callback); napi_value jsMethod; - napi_get_named_property(napiCallback->env, callback, "setPointer", &jsMethod); - napi_call_function(napiCallback->env, nullptr, jsMethod, OHOS_THREADSAFE_ARG1, argv, nullptr); + napi_get_named_property(g_napiCallback->env, callback, "setPointer", &jsMethod); + napi_call_function(g_napiCallback->env, nullptr, jsMethod, OHOS_THREADSAFE_ARG1, argv, nullptr); return; } @@ -414,7 +414,7 @@ SDL_bool OHOS_IsThreadRun(void) void OHOS_ThreadExit(void) { SDL_free(g_sdlMainThread); - napi_release_threadsafe_function(napiCallback->tsfn, napi_tsfn_release); - napiCallback->tsfn = nullptr; - napiCallback = NULL; + napi_release_threadsafe_function(g_napiCallback->tsfn, napi_tsfn_release); + g_napiCallback->tsfn = nullptr; + g_napiCallback = NULL; } \ No newline at end of file diff --git a/src/core/ohos/SDL_ohosthreadsafe.h b/src/core/ohos/SDL_ohosthreadsafe.h index 4c3faf56d..304d321e1 100644 --- a/src/core/ohos/SDL_ohosthreadsafe.h +++ b/src/core/ohos/SDL_ohosthreadsafe.h @@ -55,7 +55,7 @@ typedef struct { char *libraryFile; } OhosSDLEntryInfo; -extern std::unique_ptr napiCallback; +extern std::unique_ptr g_napiCallback; #ifdef __cplusplus /* *INDENT-OFF* */ -- Gitee