Skip to content

Commit c99ae6e

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

File tree

3 files changed

+58
-15
lines changed

3 files changed

+58
-15
lines changed

src/core/ohos/SDL_ohos.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "SDL3/SDL_video.h"
12
#include "SDL_internal.h"
23
#include <EGL/egl.h>
34
#include <EGL/eglplatform.h>
@@ -62,6 +63,16 @@ void OHOS_windowDataFill(SDL_Window* w)
6263

6364
SDL_VideoDevice *_this = SDL_GetVideoDevice();
6465

66+
if (_this->windows == NULL)
67+
{
68+
_this->windows = w;
69+
}
70+
else
71+
{
72+
_this->windows->next = w;
73+
w->prev = _this->windows;
74+
}
75+
6576
#ifdef SDL_VIDEO_OPENGL_EGL
6677
if (w->flags & SDL_WINDOW_OPENGL) {
6778
SDL_LockMutex(g_ohosPageMutex);
@@ -73,6 +84,51 @@ void OHOS_windowDataFill(SDL_Window* w)
7384
}
7485
#endif
7586
}
87+
void OHOS_removeWindow(SDL_Window* w)
88+
{
89+
SDL_VideoDevice *_this = SDL_GetVideoDevice();
90+
if (_this->windows == w)
91+
{
92+
_this->windows = _this->windows->next;
93+
}
94+
else
95+
{
96+
SDL_Window* curWin = _this->windows;
97+
while (curWin != NULL)
98+
{
99+
if (curWin == w)
100+
{
101+
if (curWin->next == NULL)
102+
{
103+
curWin->prev->next = NULL;
104+
}
105+
else
106+
{
107+
curWin->prev->next = curWin->next;
108+
curWin->next->prev = curWin->prev;
109+
}
110+
break;
111+
}
112+
curWin = curWin->next;
113+
}
114+
}
115+
116+
#ifdef SDL_VIDEO_OPENGL_EGL
117+
if (w->flags & SDL_WINDOW_OPENGL) {
118+
SDL_LockMutex(g_ohosPageMutex);
119+
if (w->internal->egl_context)
120+
{
121+
SDL_EGL_DestroyContext(_this, w->internal->egl_context);
122+
}
123+
if (w->internal->egl_surface != EGL_NO_SURFACE)
124+
{
125+
SDL_EGL_DestroySurface(_this, w->internal->egl_surface);
126+
}
127+
SDL_UnlockMutex(g_ohosPageMutex);
128+
}
129+
SDL_free(w->internal);
130+
#endif
131+
}
76132

77133
static napi_value minus(napi_env env, napi_callback_info info)
78134
{

src/core/ohos/SDL_ohos.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
extern SDL_Mutex *g_ohosPageMutex;
1010

1111
void OHOS_windowDataFill(SDL_Window* w);
12+
void OHOS_removeWindow(SDL_Window* w);
1213

1314
typedef struct SDL_VideoData {
1415
SDL_Rect textRect;

src/video/ohos/SDL_ohoswindow.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,7 @@ bool OHOS_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Propertie
1414

1515
void OHOS_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window)
1616
{
17-
#ifdef SDL_VIDEO_OPENGL_EGL
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);
29-
}
30-
SDL_free(window->internal);
31-
#endif
17+
OHOS_removeWindow(window);
3218
}
3319

3420
#endif

0 commit comments

Comments
 (0)