Harmony port: review changes

This commit is contained in:
Jack253-png 2025-06-01 07:36:26 +08:00
parent 590509b34d
commit c99ae6e155
No known key found for this signature in database
GPG key ID: 51EA61206B02D886
3 changed files with 58 additions and 15 deletions

View file

@ -1,3 +1,4 @@
#include "SDL3/SDL_video.h"
#include "SDL_internal.h"
#include <EGL/egl.h>
#include <EGL/eglplatform.h>
@ -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)
{

View file

@ -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;

View file

@ -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