Skip to content

Commit cd0d25c

Browse files
committed
Harmony port: video library
1 parent 1e75f1f commit cd0d25c

File tree

4 files changed

+53
-9
lines changed

4 files changed

+53
-9
lines changed

src/core/ohos/SDL_ohos.c

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
#include "SDL_internal.h"
2+
#include <EGL/egl.h>
3+
#include <EGL/eglplatform.h>
24

35
#ifdef SDL_PLATFORM_OHOS
46

57
#include "napi/native_api.h"
68
#include "SDL_ohos.h"
79
#include <ace/xcomponent/native_interface_xcomponent.h>
810
#include "../../video/ohos/SDL_ohosvideo.h"
11+
#include "SDL3/SDL_mutex.h"
912

1013
OHNativeWindow *nativeWindow;
1114
SDL_Mutex *g_ohosPageMutex = NULL;
1215
static OH_NativeXComponent_Callback callback;
1316
static OH_NativeXComponent_MouseEvent_Callback mouseCallback;
14-
SDL_WindowData data;
17+
SDL_WindowData windowData;
18+
SDL_VideoData videoData;
1519

1620
static napi_value minus(napi_env env, napi_callback_info info)
1721
{
@@ -51,14 +55,40 @@ static void OnSurfaceCreatedCB(OH_NativeXComponent *component, void *window)
5155

5256
SDL_Log("Native Window: %p", nativeWindow);
5357

54-
data.native_window = nativeWindow;
55-
data.width = width;
56-
data.height = height;
57-
data.x = offsetX;
58-
data.y = offsetY;
58+
SDL_LockMutex(g_ohosPageMutex);
59+
windowData.native_window = nativeWindow;
60+
windowData.width = width;
61+
windowData.height = height;
62+
windowData.x = offsetX;
63+
windowData.y = offsetY;
64+
SDL_UnlockMutex(g_ohosPageMutex);
65+
}
66+
static void OnSurfaceChangedCB(OH_NativeXComponent *component, void *window)
67+
{
68+
nativeWindow = (OHNativeWindow *)window;
69+
70+
uint64_t width;
71+
uint64_t height;
72+
double offsetX;
73+
double offsetY;
74+
OH_NativeXComponent_GetXComponentSize(component, window, &width, &height);
75+
OH_NativeXComponent_GetXComponentOffset(component, window, &offsetX, &offsetY);
76+
77+
SDL_Log("Native Window: %p", nativeWindow);
78+
79+
SDL_LockMutex(g_ohosPageMutex);
80+
windowData.native_window = nativeWindow;
81+
windowData.width = width;
82+
windowData.height = height;
83+
windowData.x = offsetX;
84+
windowData.y = offsetY;
85+
86+
SDL_UnlockMutex(g_ohosPageMutex);
87+
}
88+
static void OnSurfaceDestroyedCB(OH_NativeXComponent *component, void *window)
89+
{
90+
// SDL_VideoDevice* _this = SDL_GetVideoDevice();
5991
}
60-
static void OnSurfaceChangedCB(OH_NativeXComponent *component, void *window) {}
61-
static void OnSurfaceDestroyedCB(OH_NativeXComponent *component, void *window) {}
6292
static void onKeyEvent(OH_NativeXComponent *component, void *window) {}
6393
static void onNativeTouch(OH_NativeXComponent *component, void *window) {}
6494
static void onNativeMouse(OH_NativeXComponent *component, void *window) {}

src/core/ohos/SDL_ohos.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77

88
extern SDL_Mutex *g_ohosPageMutex;
99
extern OHNativeWindow *nativeWindow;
10-
extern SDL_WindowData data;
10+
extern SDL_WindowData windowData;
11+
extern SDL_VideoData videoData;
12+
13+
typedef struct SDL_VideoData {
14+
SDL_Rect textRect;
15+
int isPaused;
16+
int isPausing;
17+
} SDL_VideoData;
1118

1219
#endif

src/video/ohos/SDL_ohosvideo.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#ifdef SDL_VIDEO_DRIVER_OHOS
55
#include "SDL_ohosvulkan.h"
6+
#include "../../core/ohos/SDL_ohos.h"
67

78
bool OHOS_VideoInit(SDL_VideoDevice *_this)
89
{
@@ -20,6 +21,8 @@ static SDL_VideoDevice *OHOS_CreateDevice(void)
2021
return NULL;
2122
}
2223

24+
device->internal = &videoData;
25+
2326
device->VideoInit = OHOS_VideoInit;
2427
device->VideoQuit = OHOS_VideoQuit;
2528
#ifdef SDL_VIDEO_VULKAN

src/video/ohos/SDL_ohoswindow.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#ifdef SDL_VIDEO_DRIVER_OHOS
2+
3+
4+
#endif

0 commit comments

Comments
 (0)