From cd0d25ca11702cab823025f3c16a36df6bc82548 Mon Sep 17 00:00:00 2001 From: Jack253-png Date: Sat, 31 May 2025 16:16:45 +0800 Subject: [PATCH] Harmony port: video library --- src/core/ohos/SDL_ohos.c | 46 +++++++++++++++++++++++++++------ src/core/ohos/SDL_ohos.h | 9 ++++++- src/video/ohos/SDL_ohosvideo.c | 3 +++ src/video/ohos/SDL_ohoswindow.c | 4 +++ 4 files changed, 53 insertions(+), 9 deletions(-) create mode 100644 src/video/ohos/SDL_ohoswindow.c diff --git a/src/core/ohos/SDL_ohos.c b/src/core/ohos/SDL_ohos.c index 2fca870f5f..1f128c1e1c 100644 --- a/src/core/ohos/SDL_ohos.c +++ b/src/core/ohos/SDL_ohos.c @@ -1,4 +1,6 @@ #include "SDL_internal.h" +#include +#include #ifdef SDL_PLATFORM_OHOS @@ -6,12 +8,14 @@ #include "SDL_ohos.h" #include #include "../../video/ohos/SDL_ohosvideo.h" +#include "SDL3/SDL_mutex.h" OHNativeWindow *nativeWindow; SDL_Mutex *g_ohosPageMutex = NULL; static OH_NativeXComponent_Callback callback; static OH_NativeXComponent_MouseEvent_Callback mouseCallback; -SDL_WindowData data; +SDL_WindowData windowData; +SDL_VideoData videoData; static napi_value minus(napi_env env, napi_callback_info info) { @@ -51,14 +55,40 @@ static void OnSurfaceCreatedCB(OH_NativeXComponent *component, void *window) SDL_Log("Native Window: %p", nativeWindow); - data.native_window = nativeWindow; - data.width = width; - data.height = height; - data.x = offsetX; - data.y = offsetY; + SDL_LockMutex(g_ohosPageMutex); + windowData.native_window = nativeWindow; + windowData.width = width; + windowData.height = height; + windowData.x = offsetX; + windowData.y = offsetY; + SDL_UnlockMutex(g_ohosPageMutex); +} +static void OnSurfaceChangedCB(OH_NativeXComponent *component, void *window) +{ + nativeWindow = (OHNativeWindow *)window; + + uint64_t width; + uint64_t height; + double offsetX; + double offsetY; + OH_NativeXComponent_GetXComponentSize(component, window, &width, &height); + OH_NativeXComponent_GetXComponentOffset(component, window, &offsetX, &offsetY); + + SDL_Log("Native Window: %p", nativeWindow); + + SDL_LockMutex(g_ohosPageMutex); + windowData.native_window = nativeWindow; + windowData.width = width; + windowData.height = height; + windowData.x = offsetX; + windowData.y = offsetY; + + SDL_UnlockMutex(g_ohosPageMutex); +} +static void OnSurfaceDestroyedCB(OH_NativeXComponent *component, void *window) +{ + // SDL_VideoDevice* _this = SDL_GetVideoDevice(); } -static void OnSurfaceChangedCB(OH_NativeXComponent *component, void *window) {} -static void OnSurfaceDestroyedCB(OH_NativeXComponent *component, void *window) {} static void onKeyEvent(OH_NativeXComponent *component, void *window) {} static void onNativeTouch(OH_NativeXComponent *component, void *window) {} static void onNativeMouse(OH_NativeXComponent *component, void *window) {} diff --git a/src/core/ohos/SDL_ohos.h b/src/core/ohos/SDL_ohos.h index 8440f07386..0df3a0bee0 100644 --- a/src/core/ohos/SDL_ohos.h +++ b/src/core/ohos/SDL_ohos.h @@ -7,6 +7,13 @@ extern SDL_Mutex *g_ohosPageMutex; extern OHNativeWindow *nativeWindow; -extern SDL_WindowData data; +extern SDL_WindowData windowData; +extern SDL_VideoData videoData; + +typedef struct SDL_VideoData { + SDL_Rect textRect; + int isPaused; + int isPausing; +} SDL_VideoData; #endif diff --git a/src/video/ohos/SDL_ohosvideo.c b/src/video/ohos/SDL_ohosvideo.c index d4df17c2a2..5372751666 100644 --- a/src/video/ohos/SDL_ohosvideo.c +++ b/src/video/ohos/SDL_ohosvideo.c @@ -3,6 +3,7 @@ #ifdef SDL_VIDEO_DRIVER_OHOS #include "SDL_ohosvulkan.h" +#include "../../core/ohos/SDL_ohos.h" bool OHOS_VideoInit(SDL_VideoDevice *_this) { @@ -20,6 +21,8 @@ static SDL_VideoDevice *OHOS_CreateDevice(void) return NULL; } + device->internal = &videoData; + device->VideoInit = OHOS_VideoInit; device->VideoQuit = OHOS_VideoQuit; #ifdef SDL_VIDEO_VULKAN diff --git a/src/video/ohos/SDL_ohoswindow.c b/src/video/ohos/SDL_ohoswindow.c new file mode 100644 index 0000000000..10d54fba2f --- /dev/null +++ b/src/video/ohos/SDL_ohoswindow.c @@ -0,0 +1,4 @@ +#ifdef SDL_VIDEO_DRIVER_OHOS + + +#endif