diff --git a/src/core/ohos/SDL_ohos.c b/src/core/ohos/SDL_ohos.c index 32481d0f21..a9a71d10c8 100644 --- a/src/core/ohos/SDL_ohos.c +++ b/src/core/ohos/SDL_ohos.c @@ -1,3 +1,4 @@ +#include "SDL3/SDL_video.h" #include "SDL_internal.h" #include #include @@ -62,6 +63,16 @@ void OHOS_windowDataFill(SDL_Window* w) SDL_VideoDevice *_this = SDL_GetVideoDevice(); + if (_this->windows == NULL) + { + _this->windows = w; + } + else + { + _this->windows->next = w; + w->prev = _this->windows; + } + #ifdef SDL_VIDEO_OPENGL_EGL if (w->flags & SDL_WINDOW_OPENGL) { SDL_LockMutex(g_ohosPageMutex); @@ -73,6 +84,51 @@ void OHOS_windowDataFill(SDL_Window* w) } #endif } +void OHOS_removeWindow(SDL_Window* w) +{ + SDL_VideoDevice *_this = SDL_GetVideoDevice(); + if (_this->windows == w) + { + _this->windows = _this->windows->next; + } + else + { + SDL_Window* curWin = _this->windows; + while (curWin != NULL) + { + if (curWin == w) + { + if (curWin->next == NULL) + { + curWin->prev->next = NULL; + } + else + { + curWin->prev->next = curWin->next; + curWin->next->prev = curWin->prev; + } + break; + } + curWin = curWin->next; + } + } + +#ifdef SDL_VIDEO_OPENGL_EGL + if (w->flags & SDL_WINDOW_OPENGL) { + SDL_LockMutex(g_ohosPageMutex); + if (w->internal->egl_context) + { + SDL_EGL_DestroyContext(_this, w->internal->egl_context); + } + if (w->internal->egl_surface != EGL_NO_SURFACE) + { + SDL_EGL_DestroySurface(_this, w->internal->egl_surface); + } + SDL_UnlockMutex(g_ohosPageMutex); + } + SDL_free(w->internal); +#endif +} static napi_value minus(napi_env env, napi_callback_info info) { diff --git a/src/core/ohos/SDL_ohos.h b/src/core/ohos/SDL_ohos.h index 967f248491..99d584d1a0 100644 --- a/src/core/ohos/SDL_ohos.h +++ b/src/core/ohos/SDL_ohos.h @@ -9,6 +9,7 @@ extern SDL_Mutex *g_ohosPageMutex; void OHOS_windowDataFill(SDL_Window* w); +void OHOS_removeWindow(SDL_Window* w); typedef struct SDL_VideoData { SDL_Rect textRect; diff --git a/src/video/ohos/SDL_ohoswindow.c b/src/video/ohos/SDL_ohoswindow.c index 8d0958fb08..b74c725558 100644 --- a/src/video/ohos/SDL_ohoswindow.c +++ b/src/video/ohos/SDL_ohoswindow.c @@ -14,21 +14,7 @@ bool OHOS_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Propertie void OHOS_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window) { - #ifdef SDL_VIDEO_OPENGL_EGL - if (window->flags & SDL_WINDOW_OPENGL) { - SDL_LockMutex(g_ohosPageMutex); - if (window->internal->egl_context) - { - SDL_EGL_DestroyContext(_this, window->internal->egl_context); - } - if (window->internal->egl_surface != EGL_NO_SURFACE) - { - SDL_EGL_DestroySurface(_this, window->internal->egl_surface); - } - SDL_UnlockMutex(g_ohosPageMutex); - } - SDL_free(window->internal); - #endif + OHOS_removeWindow(window); } #endif