diff --git a/src/video/ohos/SDL_ohosgl.c b/src/video/ohos/SDL_ohosgl.c new file mode 100644 index 0000000000..bc4398e5a2 --- /dev/null +++ b/src/video/ohos/SDL_ohosgl.c @@ -0,0 +1,49 @@ +#include "SDL_internal.h" +#ifdef SDL_VIDEO_DRIVER_OHOS +#include "SDL_ohosvideo.h" +#include "../../core/ohos/SDL_ohos.h" + +bool OHOS_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context) +{ + if (window && context) + { + return SDL_EGL_MakeCurrent(_this, window->internal->egl_xcomponent, context); + } + else + { + return SDL_EGL_MakeCurrent(_this, NULL, NULL); + } +} + +SDL_GLContext OHOS_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window) +{ + SDL_GLContext result; + + SDL_LockMutex(g_ohosPageMutex); + + result = SDL_EGL_CreateContext(_this, window->internal->egl_xcomponent); + + SDL_UnlockMutex(g_ohosPageMutex); + + return result; +} + +bool OHOS_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) +{ + bool result; + + SDL_LockMutex(g_ohosPageMutex); + + result = SDL_EGL_SwapBuffers(_this, window->internal->egl_xcomponent); + + SDL_UnlockMutex(g_ohosPageMutex); + + return result; +} + +bool OHOS_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path) +{ + return SDL_EGL_LoadLibrary(_this, path, (NativeDisplayType)0, 0); +} + +#endif diff --git a/src/video/ohos/SDL_ohosgl.h b/src/video/ohos/SDL_ohosgl.h new file mode 100644 index 0000000000..b168dbeb3d --- /dev/null +++ b/src/video/ohos/SDL_ohosgl.h @@ -0,0 +1,9 @@ +#ifdef SDL_VIDEO_DRIVER_OHOS +#include "SDL_ohosvideo.h" + +bool OHOS_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); +SDL_GLContext OHOS_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window); +bool OHOS_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); +bool OHOS_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path); + +#endif diff --git a/src/video/ohos/SDL_ohosvideo.c b/src/video/ohos/SDL_ohosvideo.c index a823916d7a..222247c9f8 100644 --- a/src/video/ohos/SDL_ohosvideo.c +++ b/src/video/ohos/SDL_ohosvideo.c @@ -3,6 +3,7 @@ #ifdef SDL_VIDEO_DRIVER_OHOS #include "SDL_ohosvulkan.h" +#include "SDL_ohosgl.h" #include "SDL_ohoswindow.h" #include "../../core/ohos/SDL_ohos.h" @@ -13,6 +14,10 @@ bool OHOS_VideoInit(SDL_VideoDevice *_this) void OHOS_VideoQuit(SDL_VideoDevice *_this) { } +void OHOS_DeviceFree(SDL_VideoDevice *device) +{ + SDL_free(device); +} static SDL_VideoDevice *OHOS_CreateDevice(void) { SDL_VideoDevice *device; @@ -23,6 +28,7 @@ static SDL_VideoDevice *OHOS_CreateDevice(void) } device->internal = &videoData; + device->free = OHOS_DeviceFree; device->VideoInit = OHOS_VideoInit; device->VideoQuit = OHOS_VideoQuit; @@ -36,6 +42,18 @@ static SDL_VideoDevice *OHOS_CreateDevice(void) device->CreateSDLWindow = OHOS_CreateWindow; device->DestroyWindow = OHOS_DestroyWindow; +#ifdef SDL_VIDEO_OPENGL_EGL + device->GL_LoadLibrary = OHOS_GLES_LoadLibrary; + device->GL_MakeCurrent = OHOS_GLES_MakeCurrent; + device->GL_CreateContext = OHOS_GLES_CreateContext; + device->GL_SwapWindow = OHOS_GLES_SwapWindow; + device->GL_GetProcAddress = SDL_EGL_GetProcAddressInternal; + device->GL_UnloadLibrary = SDL_EGL_UnloadLibrary; + device->GL_SetSwapInterval = SDL_EGL_SetSwapInterval; + device->GL_GetSwapInterval = SDL_EGL_GetSwapInterval; + device->GL_DestroyContext = SDL_EGL_DestroyContext; +#endif + return device; } VideoBootStrap OHOS_bootstrap = {