Harmony port: review changes

This commit is contained in:
Jack253-png 2025-06-01 07:22:00 +08:00
parent 4a0d0685ee
commit 590509b34d
No known key found for this signature in database
GPG key ID: 51EA61206B02D886
6 changed files with 57 additions and 58 deletions

View file

@ -15,11 +15,11 @@
#include "SDL3/SDL_mutex.h"
#include "../../video/ohos/SDL_ohoskeyboard.h"
OHNativeWindow *g_ohosNativeWindow;
static OHNativeWindow *g_ohosNativeWindow;
SDL_Mutex *g_ohosPageMutex = NULL;
static OH_NativeXComponent_Callback callback;
static OH_NativeXComponent_MouseEvent_Callback mouseCallback;
SDL_WindowData windowData;
static int x, y, wid, hei;
static struct
{
napi_env env;
@ -51,6 +51,29 @@ typedef struct
napiCallbackArg arg8;
} napiCallbackData;
void OHOS_windowDataFill(SDL_Window* w)
{
w->internal = SDL_calloc(1, sizeof(SDL_WindowData));
w->x = x;
w->y = y;
w->w = wid;
w->h = hei;
w->internal->native_window = g_ohosNativeWindow;
SDL_VideoDevice *_this = SDL_GetVideoDevice();
#ifdef SDL_VIDEO_OPENGL_EGL
if (w->flags & SDL_WINDOW_OPENGL) {
SDL_LockMutex(g_ohosPageMutex);
if (w->internal->egl_surface == EGL_NO_SURFACE)
{
w->internal->egl_surface = SDL_EGL_CreateSurface(_this, w, (NativeWindowType)g_ohosNativeWindow);
}
SDL_UnlockMutex(g_ohosPageMutex);
}
#endif
}
static napi_value minus(napi_env env, napi_callback_info info)
{
size_t argc = 2;
@ -112,11 +135,10 @@ static void OnSurfaceCreatedCB(OH_NativeXComponent *component, void *window)
OH_NativeXComponent_GetXComponentOffset(component, window, &offsetX, &offsetY);
SDL_LockMutex(g_ohosPageMutex);
windowData.native_window = g_ohosNativeWindow;
windowData.width = width;
windowData.height = height;
windowData.x = offsetX;
windowData.y = offsetY;
wid = width;
hei = height;
x = (int)offsetX;
y = (int)offsetY;
SDL_UnlockMutex(g_ohosPageMutex);
}
static void OnSurfaceChangedCB(OH_NativeXComponent *component, void *window)
@ -131,27 +153,14 @@ static void OnSurfaceChangedCB(OH_NativeXComponent *component, void *window)
OH_NativeXComponent_GetXComponentOffset(component, window, &offsetX, &offsetY);
SDL_LockMutex(g_ohosPageMutex);
windowData.native_window = g_ohosNativeWindow;
windowData.width = width;
windowData.height = height;
windowData.x = offsetX;
windowData.y = offsetY;
wid = width;
hei = height;
x = (int)offsetX;
y = (int)offsetY;
SDL_UnlockMutex(g_ohosPageMutex);
}
static void OnSurfaceDestroyedCB(OH_NativeXComponent *component, void *window)
{
SDL_VideoDevice* _this = SDL_GetVideoDevice();
#ifdef SDL_VIDEO_OPENGL_EGL
if (windowData.egl_context)
{
SDL_EGL_DestroyContext(_this, windowData.egl_context);
}
if (windowData.egl_xcomponent)
{
SDL_EGL_DestroySurface(_this, windowData.egl_xcomponent);
}
#endif
}
static void onKeyEvent(OH_NativeXComponent *component, void *window)
{

View file

@ -2,12 +2,13 @@
#define SDL_OHOS_H
#include "SDL3/SDL_mutex.h"
#include "SDL3/SDL_video.h"
#include "video/SDL_sysvideo.h"
#include <native_window/external_window.h>
extern SDL_Mutex *g_ohosPageMutex;
extern OHNativeWindow *g_ohosNativeWindow;
extern SDL_WindowData windowData;
void OHOS_windowDataFill(SDL_Window* w);
typedef struct SDL_VideoData {
SDL_Rect textRect;

View file

@ -7,7 +7,7 @@ bool OHOS_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLCon
{
if (window && context)
{
return SDL_EGL_MakeCurrent(_this, window->internal->egl_xcomponent, context);
return SDL_EGL_MakeCurrent(_this, window->internal->egl_surface, context);
}
else
{
@ -21,7 +21,7 @@ SDL_GLContext OHOS_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window
SDL_LockMutex(g_ohosPageMutex);
result = SDL_EGL_CreateContext(_this, window->internal->egl_xcomponent);
result = SDL_EGL_CreateContext(_this, window->internal->egl_surface);
SDL_UnlockMutex(g_ohosPageMutex);
@ -34,7 +34,7 @@ bool OHOS_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window)
SDL_LockMutex(g_ohosPageMutex);
result = SDL_EGL_SwapBuffers(_this, window->internal->egl_xcomponent);
result = SDL_EGL_SwapBuffers(_this, window->internal->egl_surface);
SDL_UnlockMutex(g_ohosPageMutex);

View file

@ -5,15 +5,13 @@
#include "../../core/ohos/SDL_ohos.h"
struct SDL_WindowData {
#ifdef SDL_VIDEO_OPENGL_EGL
EGLSurface egl_xcomponent;
EGLSurface egl_surface;
EGLContext egl_context;
#endif
bool backup_done;
OHNativeWindow *native_window;
uint64_t width;
uint64_t height;
double x;
double y;
};
#endif

View file

@ -8,6 +8,7 @@
#include "../SDL_sysvideo.h"
#include "../../core/ohos/SDL_ohos.h"
#include "vulkan/vulkan_ohos.h"
#include "SDL_ohosvideo.h"
#include <native_window/external_window.h>
static int loadedCount = 0;
@ -111,7 +112,7 @@ bool OHOS_Vulkan_CreateSurface(SDL_VideoDevice *_this,
createInfo.sType = VK_STRUCTURE_TYPE_SURFACE_CREATE_INFO_OHOS;
createInfo.pNext = NULL;
createInfo.flags = 0;
createInfo.window = g_ohosNativeWindow;
createInfo.window = window->internal->native_window;
result = vkCreateSurfaceOHOS(instance, &createInfo, NULL, surface);
if (result != VK_SUCCESS) {
SDL_SetError("vkCreateSurfaceOHOS failed: %d", result);

View file

@ -1,4 +1,5 @@
#include "SDL_ohoswindow.h"
#include "SDL_internal.h"
#include <EGL/eglplatform.h>
#ifdef SDL_VIDEO_DRIVER_OHOS
@ -6,19 +7,7 @@
#include "SDL_ohosvideo.h"
bool OHOS_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props)
{
window->internal = &windowData;
#ifdef SDL_VIDEO_OPENGL_EGL
if (window->flags & SDL_WINDOW_OPENGL) {
SDL_LockMutex(g_ohosPageMutex);
if (window->internal->egl_xcomponent == EGL_NO_SURFACE)
{
window->internal->egl_xcomponent = SDL_EGL_CreateSurface(_this, window, (NativeWindowType)window->internal->native_window);
}
SDL_UnlockMutex(g_ohosPageMutex);
}
#endif
window->x = (int)window->internal->x;
window->y = (int)window->internal->y;
OHOS_windowDataFill(window);
return true;
}
@ -26,19 +15,20 @@ 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->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);
}
if (window->internal->egl_xcomponent != EGL_NO_SURFACE)
{
SDL_EGL_DestroySurface(_this, window->internal->egl_xcomponent);
}
SDL_UnlockMutex(g_ohosPageMutex);
}
#endif
SDL_free(window->internal);
#endif
}
#endif