Skip to content

Commit 20b80c0

Browse files
committed
Harmony port: window creation
1 parent e862b9a commit 20b80c0

File tree

4 files changed

+62
-1
lines changed

4 files changed

+62
-1
lines changed

src/core/ohos/SDL_ohos.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,17 @@ static void OnSurfaceChangedCB(OH_NativeXComponent *component, void *window)
8787
}
8888
static void OnSurfaceDestroyedCB(OH_NativeXComponent *component, void *window)
8989
{
90-
// SDL_VideoDevice* _this = SDL_GetVideoDevice();
90+
SDL_VideoDevice* _this = SDL_GetVideoDevice();
91+
#ifdef SDL_VIDEO_OPENGL_EGL
92+
if (windowData.egl_context)
93+
{
94+
SDL_EGL_DestroyContext(_this, windowData.egl_context);
95+
}
96+
if (windowData.egl_xcomponent)
97+
{
98+
SDL_EGL_DestroySurface(_this, windowData.egl_xcomponent);
99+
}
100+
#endif
91101
}
92102
static void onKeyEvent(OH_NativeXComponent *component, void *window) {}
93103
static void onNativeTouch(OH_NativeXComponent *component, void *window) {}

src/video/ohos/SDL_ohosvideo.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#ifdef SDL_VIDEO_DRIVER_OHOS
55
#include "SDL_ohosvulkan.h"
6+
#include "SDL_ohoswindow.h"
67
#include "../../core/ohos/SDL_ohos.h"
78

89
bool OHOS_VideoInit(SDL_VideoDevice *_this)
@@ -32,6 +33,8 @@ static SDL_VideoDevice *OHOS_CreateDevice(void)
3233
device->Vulkan_CreateSurface = OHOS_Vulkan_CreateSurface;
3334
device->Vulkan_DestroySurface = OHOS_Vulkan_DestroySurface;
3435
#endif
36+
device->CreateSDLWindow = OHOS_CreateWindow;
37+
device->DestroyWindow = OHOS_DestroyWindow;
3538

3639
return device;
3740
}

src/video/ohos/SDL_ohoswindow.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,44 @@
1+
#include "SDL_ohoswindow.h"
2+
#include <EGL/eglplatform.h>
3+
14
#ifdef SDL_VIDEO_DRIVER_OHOS
5+
#include "../../core/ohos/SDL_ohos.h"
6+
#include "SDL_ohosvideo.h"
7+
bool OHOS_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props)
8+
{
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;
222

23+
return true;
24+
}
25+
26+
void OHOS_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window)
27+
{
28+
#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);
34+
}
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
42+
}
343

444
#endif

src/video/ohos/SDL_ohoswindow.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include "SDL_internal.h"
2+
3+
#ifdef SDL_VIDEO_DRIVER_OHOS
4+
#include "../SDL_sysvideo.h"
5+
bool OHOS_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props);
6+
void OHOS_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window);
7+
8+
#endif

0 commit comments

Comments
 (0)