Skip to content

Commit 590509b

Browse files
committed
Harmony port: review changes
1 parent 4a0d068 commit 590509b

File tree

6 files changed

+57
-58
lines changed

6 files changed

+57
-58
lines changed

src/core/ohos/SDL_ohos.c

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
#include "SDL3/SDL_mutex.h"
1616
#include "../../video/ohos/SDL_ohoskeyboard.h"
1717

18-
OHNativeWindow *g_ohosNativeWindow;
18+
static OHNativeWindow *g_ohosNativeWindow;
1919
SDL_Mutex *g_ohosPageMutex = NULL;
2020
static OH_NativeXComponent_Callback callback;
2121
static OH_NativeXComponent_MouseEvent_Callback mouseCallback;
22-
SDL_WindowData windowData;
22+
static int x, y, wid, hei;
2323
static struct
2424
{
2525
napi_env env;
@@ -51,6 +51,29 @@ typedef struct
5151
napiCallbackArg arg8;
5252
} napiCallbackData;
5353

54+
void OHOS_windowDataFill(SDL_Window* w)
55+
{
56+
w->internal = SDL_calloc(1, sizeof(SDL_WindowData));
57+
w->x = x;
58+
w->y = y;
59+
w->w = wid;
60+
w->h = hei;
61+
w->internal->native_window = g_ohosNativeWindow;
62+
63+
SDL_VideoDevice *_this = SDL_GetVideoDevice();
64+
65+
#ifdef SDL_VIDEO_OPENGL_EGL
66+
if (w->flags & SDL_WINDOW_OPENGL) {
67+
SDL_LockMutex(g_ohosPageMutex);
68+
if (w->internal->egl_surface == EGL_NO_SURFACE)
69+
{
70+
w->internal->egl_surface = SDL_EGL_CreateSurface(_this, w, (NativeWindowType)g_ohosNativeWindow);
71+
}
72+
SDL_UnlockMutex(g_ohosPageMutex);
73+
}
74+
#endif
75+
}
76+
5477
static napi_value minus(napi_env env, napi_callback_info info)
5578
{
5679
size_t argc = 2;
@@ -112,11 +135,10 @@ static void OnSurfaceCreatedCB(OH_NativeXComponent *component, void *window)
112135
OH_NativeXComponent_GetXComponentOffset(component, window, &offsetX, &offsetY);
113136

114137
SDL_LockMutex(g_ohosPageMutex);
115-
windowData.native_window = g_ohosNativeWindow;
116-
windowData.width = width;
117-
windowData.height = height;
118-
windowData.x = offsetX;
119-
windowData.y = offsetY;
138+
wid = width;
139+
hei = height;
140+
x = (int)offsetX;
141+
y = (int)offsetY;
120142
SDL_UnlockMutex(g_ohosPageMutex);
121143
}
122144
static void OnSurfaceChangedCB(OH_NativeXComponent *component, void *window)
@@ -131,27 +153,14 @@ static void OnSurfaceChangedCB(OH_NativeXComponent *component, void *window)
131153
OH_NativeXComponent_GetXComponentOffset(component, window, &offsetX, &offsetY);
132154

133155
SDL_LockMutex(g_ohosPageMutex);
134-
windowData.native_window = g_ohosNativeWindow;
135-
windowData.width = width;
136-
windowData.height = height;
137-
windowData.x = offsetX;
138-
windowData.y = offsetY;
139-
156+
wid = width;
157+
hei = height;
158+
x = (int)offsetX;
159+
y = (int)offsetY;
140160
SDL_UnlockMutex(g_ohosPageMutex);
141161
}
142162
static void OnSurfaceDestroyedCB(OH_NativeXComponent *component, void *window)
143163
{
144-
SDL_VideoDevice* _this = SDL_GetVideoDevice();
145-
#ifdef SDL_VIDEO_OPENGL_EGL
146-
if (windowData.egl_context)
147-
{
148-
SDL_EGL_DestroyContext(_this, windowData.egl_context);
149-
}
150-
if (windowData.egl_xcomponent)
151-
{
152-
SDL_EGL_DestroySurface(_this, windowData.egl_xcomponent);
153-
}
154-
#endif
155164
}
156165
static void onKeyEvent(OH_NativeXComponent *component, void *window)
157166
{

src/core/ohos/SDL_ohos.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
#define SDL_OHOS_H
33

44
#include "SDL3/SDL_mutex.h"
5+
#include "SDL3/SDL_video.h"
56
#include "video/SDL_sysvideo.h"
67
#include <native_window/external_window.h>
78

89
extern SDL_Mutex *g_ohosPageMutex;
9-
extern OHNativeWindow *g_ohosNativeWindow;
10-
extern SDL_WindowData windowData;
10+
11+
void OHOS_windowDataFill(SDL_Window* w);
1112

1213
typedef struct SDL_VideoData {
1314
SDL_Rect textRect;

src/video/ohos/SDL_ohosgl.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ bool OHOS_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLCon
77
{
88
if (window && context)
99
{
10-
return SDL_EGL_MakeCurrent(_this, window->internal->egl_xcomponent, context);
10+
return SDL_EGL_MakeCurrent(_this, window->internal->egl_surface, context);
1111
}
1212
else
1313
{
@@ -21,7 +21,7 @@ SDL_GLContext OHOS_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window
2121

2222
SDL_LockMutex(g_ohosPageMutex);
2323

24-
result = SDL_EGL_CreateContext(_this, window->internal->egl_xcomponent);
24+
result = SDL_EGL_CreateContext(_this, window->internal->egl_surface);
2525

2626
SDL_UnlockMutex(g_ohosPageMutex);
2727

@@ -34,7 +34,7 @@ bool OHOS_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window)
3434

3535
SDL_LockMutex(g_ohosPageMutex);
3636

37-
result = SDL_EGL_SwapBuffers(_this, window->internal->egl_xcomponent);
37+
result = SDL_EGL_SwapBuffers(_this, window->internal->egl_surface);
3838

3939
SDL_UnlockMutex(g_ohosPageMutex);
4040

src/video/ohos/SDL_ohosvideo.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@
55
#include "../../core/ohos/SDL_ohos.h"
66
struct SDL_WindowData {
77
#ifdef SDL_VIDEO_OPENGL_EGL
8-
EGLSurface egl_xcomponent;
8+
EGLSurface egl_surface;
99
EGLContext egl_context;
1010
#endif
1111
bool backup_done;
1212
OHNativeWindow *native_window;
1313
uint64_t width;
1414
uint64_t height;
15-
double x;
16-
double y;
1715
};
1816

1917
#endif

src/video/ohos/SDL_ohosvulkan.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "../SDL_sysvideo.h"
99
#include "../../core/ohos/SDL_ohos.h"
1010
#include "vulkan/vulkan_ohos.h"
11+
#include "SDL_ohosvideo.h"
1112
#include <native_window/external_window.h>
1213

1314
static int loadedCount = 0;
@@ -111,7 +112,7 @@ bool OHOS_Vulkan_CreateSurface(SDL_VideoDevice *_this,
111112
createInfo.sType = VK_STRUCTURE_TYPE_SURFACE_CREATE_INFO_OHOS;
112113
createInfo.pNext = NULL;
113114
createInfo.flags = 0;
114-
createInfo.window = g_ohosNativeWindow;
115+
createInfo.window = window->internal->native_window;
115116
result = vkCreateSurfaceOHOS(instance, &createInfo, NULL, surface);
116117
if (result != VK_SUCCESS) {
117118
SDL_SetError("vkCreateSurfaceOHOS failed: %d", result);

src/video/ohos/SDL_ohoswindow.c

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,34 @@
11
#include "SDL_ohoswindow.h"
2+
#include "SDL_internal.h"
23
#include <EGL/eglplatform.h>
34

45
#ifdef SDL_VIDEO_DRIVER_OHOS
56
#include "../../core/ohos/SDL_ohos.h"
67
#include "SDL_ohosvideo.h"
78
bool OHOS_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props)
89
{
9-
window->internal = &windowData;
10-
#ifdef SDL_VIDEO_OPENGL_EGL
11-
if (window->flags & SDL_WINDOW_OPENGL) {
12-
SDL_LockMutex(g_ohosPageMutex);
13-
if (window->internal->egl_xcomponent == EGL_NO_SURFACE)
14-
{
15-
window->internal->egl_xcomponent = SDL_EGL_CreateSurface(_this, window, (NativeWindowType)window->internal->native_window);
16-
}
17-
SDL_UnlockMutex(g_ohosPageMutex);
18-
}
19-
#endif
20-
window->x = (int)window->internal->x;
21-
window->y = (int)window->internal->y;
10+
OHOS_windowDataFill(window);
2211

2312
return true;
2413
}
2514

2615
void OHOS_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window)
2716
{
2817
#ifdef SDL_VIDEO_OPENGL_EGL
29-
if (window->flags & SDL_WINDOW_OPENGL) {
30-
SDL_LockMutex(g_ohosPageMutex);
31-
if (window->internal->egl_context)
32-
{
33-
SDL_EGL_DestroyContext(_this, window->internal->egl_context);
18+
if (window->flags & SDL_WINDOW_OPENGL) {
19+
SDL_LockMutex(g_ohosPageMutex);
20+
if (window->internal->egl_context)
21+
{
22+
SDL_EGL_DestroyContext(_this, window->internal->egl_context);
23+
}
24+
if (window->internal->egl_surface != EGL_NO_SURFACE)
25+
{
26+
SDL_EGL_DestroySurface(_this, window->internal->egl_surface);
27+
}
28+
SDL_UnlockMutex(g_ohosPageMutex);
3429
}
35-
if (window->internal->egl_xcomponent != EGL_NO_SURFACE)
36-
{
37-
SDL_EGL_DestroySurface(_this, window->internal->egl_xcomponent);
38-
}
39-
SDL_UnlockMutex(g_ohosPageMutex);
40-
}
41-
#endif
30+
SDL_free(window->internal);
31+
#endif
4232
}
4333

4434
#endif

0 commit comments

Comments
 (0)