Skip to content

Commit 9e61fcb

Browse files
committed
Harmony port: egl/gles lib
1 parent 8b6c78c commit 9e61fcb

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

src/video/ohos/SDL_ohosgl.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include "SDL_internal.h"
2+
#ifdef SDL_VIDEO_DRIVER_OHOS
3+
#include "SDL_ohosvideo.h"
4+
#include "../../core/ohos/SDL_ohos.h"
5+
6+
bool OHOS_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context)
7+
{
8+
if (window && context)
9+
{
10+
return SDL_EGL_MakeCurrent(_this, window->internal->egl_xcomponent, context);
11+
}
12+
else
13+
{
14+
return SDL_EGL_MakeCurrent(_this, NULL, NULL);
15+
}
16+
}
17+
18+
SDL_GLContext OHOS_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window)
19+
{
20+
SDL_GLContext result;
21+
22+
SDL_LockMutex(g_ohosPageMutex);
23+
24+
result = SDL_EGL_CreateContext(_this, window->internal->egl_xcomponent);
25+
26+
SDL_UnlockMutex(g_ohosPageMutex);
27+
28+
return result;
29+
}
30+
31+
bool OHOS_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window)
32+
{
33+
bool result;
34+
35+
SDL_LockMutex(g_ohosPageMutex);
36+
37+
result = SDL_EGL_SwapBuffers(_this, window->internal->egl_xcomponent);
38+
39+
SDL_UnlockMutex(g_ohosPageMutex);
40+
41+
return result;
42+
}
43+
44+
bool OHOS_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path)
45+
{
46+
return SDL_EGL_LoadLibrary(_this, path, (NativeDisplayType)0, 0);
47+
}
48+
49+
#endif

src/video/ohos/SDL_ohosgl.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifdef SDL_VIDEO_DRIVER_OHOS
2+
#include "SDL_ohosvideo.h"
3+
4+
bool OHOS_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context);
5+
SDL_GLContext OHOS_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window);
6+
bool OHOS_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window);
7+
bool OHOS_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path);
8+
9+
#endif

src/video/ohos/SDL_ohosvideo.c

Lines changed: 18 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_ohosgl.h"
67
#include "SDL_ohoswindow.h"
78
#include "../../core/ohos/SDL_ohos.h"
89

@@ -13,6 +14,10 @@ bool OHOS_VideoInit(SDL_VideoDevice *_this)
1314
void OHOS_VideoQuit(SDL_VideoDevice *_this)
1415
{
1516
}
17+
void OHOS_DeviceFree(SDL_VideoDevice *device)
18+
{
19+
SDL_free(device);
20+
}
1621
static SDL_VideoDevice *OHOS_CreateDevice(void)
1722
{
1823
SDL_VideoDevice *device;
@@ -23,6 +28,7 @@ static SDL_VideoDevice *OHOS_CreateDevice(void)
2328
}
2429

2530
device->internal = &videoData;
31+
device->free = OHOS_DeviceFree;
2632

2733
device->VideoInit = OHOS_VideoInit;
2834
device->VideoQuit = OHOS_VideoQuit;
@@ -36,6 +42,18 @@ static SDL_VideoDevice *OHOS_CreateDevice(void)
3642
device->CreateSDLWindow = OHOS_CreateWindow;
3743
device->DestroyWindow = OHOS_DestroyWindow;
3844

45+
#ifdef SDL_VIDEO_OPENGL_EGL
46+
device->GL_LoadLibrary = OHOS_GLES_LoadLibrary;
47+
device->GL_MakeCurrent = OHOS_GLES_MakeCurrent;
48+
device->GL_CreateContext = OHOS_GLES_CreateContext;
49+
device->GL_SwapWindow = OHOS_GLES_SwapWindow;
50+
device->GL_GetProcAddress = SDL_EGL_GetProcAddressInternal;
51+
device->GL_UnloadLibrary = SDL_EGL_UnloadLibrary;
52+
device->GL_SetSwapInterval = SDL_EGL_SetSwapInterval;
53+
device->GL_GetSwapInterval = SDL_EGL_GetSwapInterval;
54+
device->GL_DestroyContext = SDL_EGL_DestroyContext;
55+
#endif
56+
3957
return device;
4058
}
4159
VideoBootStrap OHOS_bootstrap = {

0 commit comments

Comments
 (0)