From cab3df2511b64afc08b24fdb668ba5e8b73f3c55 Mon Sep 17 00:00:00 2001 From: litie <2372581223@qq.com> Date: Tue, 9 Apr 2024 19:02:32 +0800 Subject: [PATCH] codecheck --- src/video/ohos/SDL_ohosevents.c | 54 ++++++++---------- src/video/ohos/SDL_ohosevents.h | 13 ++--- src/video/ohos/SDL_ohosgl.c | 34 +++++------ src/video/ohos/SDL_ohosgl.h | 17 +++--- src/video/ohos/SDL_ohoskeyboard.c | 26 +++------ src/video/ohos/SDL_ohoskeyboard.h | 14 ++--- src/video/ohos/SDL_ohosvideo.c | 93 +++++++++++++++---------------- src/video/ohos/SDL_ohosvideo.h | 19 +++---- src/video/ohos/SDL_ohoswindow.c | 82 +++++++++++++-------------- src/video/ohos/SDL_ohoswindow.h | 36 ++++++------ 10 files changed, 183 insertions(+), 205 deletions(-) diff --git a/src/video/ohos/SDL_ohosevents.c b/src/video/ohos/SDL_ohosevents.c index 93bc7a0dd..da416975d 100644 --- a/src/video/ohos/SDL_ohosevents.c +++ b/src/video/ohos/SDL_ohosevents.c @@ -15,12 +15,12 @@ #include "../../SDL_internal.h" +#ifdef SDL_VIDEO_DRIVER_OHOS #if SDL_VIDEO_DRIVER_OHOS +#endif #include "SDL_ohosevents.h" #include "SDL_events.h" -//#include "SDL_ohoskeyboard.h" -//#include "SDL_ohoswindow.h" #include "../SDL_sysvideo.h" #include "../../events/SDL_events_c.h" @@ -44,14 +44,14 @@ static void openslES_PauseDevices(void) {} #endif /* Number of 'type' events in the event queue */ -static int -SDL_NumberOfEvents(Uint32 type) + +static int SDL_NumberOfEvents(Uint32 type) { return SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, type, type); } -static void -OHOS_EGL_context_restore(SDL_Window *window) + +static void OHOS_EGL_context_restore(SDL_Window *window) { if (window) { SDL_Event event; @@ -67,8 +67,8 @@ OHOS_EGL_context_restore(SDL_Window *window) } } -static void -OHOS_EGL_context_backup(SDL_Window *window) + +static void OHOS_EGL_context_backup(SDL_Window *window) { if (window) { /* Keep a copy of the EGL Context so we can try to restore it when we resume */ @@ -80,18 +80,16 @@ OHOS_EGL_context_backup(SDL_Window *window) } } -void -OHOS_PumpEvents_Blocking(_THIS) -{ - SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; +void OHOS_PumpEvents_Blocking(SDL_VideoDevice *thisDevice) +{ + SDL_VideoData *videodata = (SDL_VideoData *)thisDevice->driverdata; if (videodata->isPaused) { SDL_bool isContextExternal = SDL_IsVideoContextExternal(); - /* Make sure this is the last thing we do before pausing */ if (!isContextExternal) { SDL_LockMutex(OHOS_PageMutex); - OHOS_EGL_context_backup(OHOS_Window); + OHOS_EGL_context_backup(g_ohosWindow); SDL_UnlockMutex(OHOS_PageMutex); } @@ -105,7 +103,7 @@ OHOS_PumpEvents_Blocking(_THIS) /* OHOS_ResumeSem was signaled */ SDL_SendAppEvent(SDL_APP_WILLENTERFOREGROUND); SDL_SendAppEvent(SDL_APP_DIDENTERFOREGROUND); - SDL_SendWindowEvent(OHOS_Window, SDL_WINDOWEVENT_RESTORED, 0, 0); + SDL_SendWindowEvent(g_ohosWindow, SDL_WINDOWEVENT_RESTORED, 0, 0); OHOSAUDIO_ResumeDevices(); openslES_ResumeDevices(); @@ -113,21 +111,19 @@ OHOS_PumpEvents_Blocking(_THIS) /* Restore the GL Context from here, as this operation is thread dependent */ if (!isContextExternal && !SDL_HasEvent(SDL_QUIT)) { SDL_LockMutex(OHOS_PageMutex); - OHOS_EGL_context_restore(OHOS_Window); + OHOS_EGL_context_restore(g_ohosWindow); SDL_UnlockMutex(OHOS_PageMutex); } /* Make sure SW Keyboard is restored when an app becomes foreground */ if (SDL_IsTextInputActive()) { - OHOS_StartTextInput(_this); /* Only showTextInput */ + OHOS_StartTextInput(thisDevice); /* Only showTextInput */ } } } else { - if (videodata->isPausing || SDL_SemTryWait(OHOS_PauseSem) == 0) { - /* OHOS_PauseSem was signaled */ if (videodata->isPausing == 0) { - SDL_SendWindowEvent(OHOS_Window, SDL_WINDOWEVENT_MINIMIZED, 0, 0); + SDL_SendWindowEvent(g_ohosWindow, SDL_WINDOWEVENT_MINIMIZED, 0, 0); SDL_SendAppEvent(SDL_APP_WILLENTERBACKGROUND); SDL_SendAppEvent(SDL_APP_DIDENTERBACKGROUND); } @@ -145,10 +141,10 @@ OHOS_PumpEvents_Blocking(_THIS) } } -void -OHOS_PumpEvents_NonBlocking(_THIS) + +void OHOS_PumpEvents_NonBlocking(SDL_VideoDevice *thisDevice) { - SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *videodata = (SDL_VideoData *)thisDevice->driverdata; static int backup_context = 0; if (videodata->isPaused) { @@ -158,7 +154,7 @@ OHOS_PumpEvents_NonBlocking(_THIS) if (!isContextExternal) { SDL_LockMutex(OHOS_PageMutex); - OHOS_EGL_context_backup(OHOS_Window); + OHOS_EGL_context_backup(g_ohosWindow); SDL_UnlockMutex(OHOS_PageMutex); } @@ -167,8 +163,6 @@ OHOS_PumpEvents_NonBlocking(_THIS) backup_context = 0; } - - if (SDL_SemTryWait(OHOS_ResumeSem) == 0) { videodata->isPaused = 0; @@ -176,7 +170,7 @@ OHOS_PumpEvents_NonBlocking(_THIS) /* OHOS_ResumeSem was signaled */ SDL_SendAppEvent(SDL_APP_WILLENTERFOREGROUND); SDL_SendAppEvent(SDL_APP_DIDENTERFOREGROUND); - SDL_SendWindowEvent(OHOS_Window, SDL_WINDOWEVENT_RESTORED, 0, 0); + SDL_SendWindowEvent(g_ohosWindow, SDL_WINDOWEVENT_RESTORED, 0, 0); OHOSAUDIO_ResumeDevices(); openslES_ResumeDevices(); @@ -184,13 +178,13 @@ OHOS_PumpEvents_NonBlocking(_THIS) /* Restore the GL Context from here, as this operation is thread dependent */ if (!isContextExternal && !SDL_HasEvent(SDL_QUIT)) { SDL_LockMutex(OHOS_PageMutex); - OHOS_EGL_context_restore(OHOS_Window); + OHOS_EGL_context_restore(g_ohosWindow); SDL_UnlockMutex(OHOS_PageMutex); } /* Make sure SW Keyboard is restored when an app becomes foreground */ if (SDL_IsTextInputActive()) { - OHOS_StartTextInput(_this); /* Only showTextInput */ + OHOS_StartTextInput(thisDevice); /* Only showTextInput */ } } } else { @@ -198,7 +192,7 @@ OHOS_PumpEvents_NonBlocking(_THIS) /* OHOS_PauseSem was signaled */ if (videodata->isPausing == 0) { - SDL_SendWindowEvent(OHOS_Window, SDL_WINDOWEVENT_MINIMIZED, 0, 0); + SDL_SendWindowEvent(g_ohosWindow, SDL_WINDOWEVENT_MINIMIZED, 0, 0); SDL_SendAppEvent(SDL_APP_WILLENTERBACKGROUND); SDL_SendAppEvent(SDL_APP_DIDENTERBACKGROUND); } diff --git a/src/video/ohos/SDL_ohosevents.h b/src/video/ohos/SDL_ohosevents.h index 84c9ac569..b0bedd9dc 100644 --- a/src/video/ohos/SDL_ohosevents.h +++ b/src/video/ohos/SDL_ohosevents.h @@ -13,16 +13,15 @@ * limitations under the License. */ -#include "../../SDL_internal.h" - -#ifndef SDL_ohosevents_h_ -#define SDL_ohosevents_h_ +#ifndef SDL_OHOSEVENTS_H +#define SDL_OHOSEVENTS_H #include "SDL_ohosvideo.h" +#include "../../SDL_internal.h" -extern void OHOS_PumpEvents_Blocking(_THIS); -extern void OHOS_PumpEvents_NonBlocking(_THIS); +extern void OHOS_PumpEvents_Blocking(SDL_VideoDevice *thisDevice); +extern void OHOS_PumpEvents_NonBlocking(SDL_VideoDevice *thisDevice); -#endif /* SDL_ohosevents_h_ */ +#endif /* SDL_OHOSEVENTS_H */ /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/ohos/SDL_ohosgl.c b/src/video/ohos/SDL_ohosgl.c index 2b116dd18..eccf100b3 100644 --- a/src/video/ohos/SDL_ohosgl.c +++ b/src/video/ohos/SDL_ohosgl.c @@ -15,7 +15,9 @@ #include "../../SDL_internal.h" +#ifdef SDL_VIDEO_DRIVER_OHOS #if SDL_VIDEO_DRIVER_OHOS +#endif /* OHOS SDL video driver implementation */ @@ -29,51 +31,45 @@ #include -int -OHOS_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) +int OHOS_GLES_MakeCurrent(SDL_VideoDevice *thisDevice, SDL_Window * window, SDL_GLContext context) { if (window && context) { - return SDL_EGL_MakeCurrent(_this, ((SDL_WindowData *) window->driverdata)->egl_surface, context); + return SDL_EGL_MakeCurrent(thisDevice, ((SDL_WindowData *) window->driverdata)->egl_xcomponent, context); } else { - return SDL_EGL_MakeCurrent(_this, NULL, NULL); + return SDL_EGL_MakeCurrent(thisDevice, NULL, NULL); } } -SDL_GLContext -OHOS_GLES_CreateContext(_THIS, SDL_Window * window) + +SDL_GLContext OHOS_GLES_CreateContext(SDL_VideoDevice *thisDevice, SDL_Window * window) { SDL_GLContext ret; - OHOS_PageMutex_Lock_Running(); - - ret = SDL_EGL_CreateContext(_this, ((SDL_WindowData *) window->driverdata)->egl_surface); - + ret = SDL_EGL_CreateContext(thisDevice, ((SDL_WindowData *) window->driverdata)->egl_xcomponent); SDL_UnlockMutex(OHOS_PageMutex); - return ret; } -int -OHOS_GLES_SwapWindow(_THIS, SDL_Window * window) + +int OHOS_GLES_SwapWindow(SDL_VideoDevice *thisDevice, SDL_Window * window) { int retval; - SDL_LockMutex(OHOS_PageMutex); /* The following two calls existed in the original Java code * If you happen to have a device that's affected by their removal, * please report to Bugzilla. -- Gabriel */ - retval = SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *) window->driverdata)->egl_surface); - + retval = SDL_EGL_SwapBuffers(thisDevice, ((SDL_WindowData *) window->driverdata)->egl_xcomponent); SDL_UnlockMutex(OHOS_PageMutex); return retval; } -int -OHOS_GLES_LoadLibrary(_THIS, const char *path) { - return SDL_EGL_LoadLibrary(_this, path, (NativeDisplayType) 0, 0); + +int OHOS_GLES_LoadLibrary(SDL_VideoDevice *thisDevice, const char *path) +{ + return SDL_EGL_LoadLibrary(thisDevice, path, (NativeDisplayType) 0, 0); } #endif /* SDL_VIDEO_DRIVER_OHOS */ diff --git a/src/video/ohos/SDL_ohosgl.h b/src/video/ohos/SDL_ohosgl.h index 7d7843d25..b95b241be 100644 --- a/src/video/ohos/SDL_ohosgl.h +++ b/src/video/ohos/SDL_ohosgl.h @@ -13,16 +13,17 @@ * limitations under the License. */ -#include "../../SDL_internal.h" +#ifndef SDL_OHOSGL_H +#define SDL_OHOSGL_H -#ifndef SDL_ohosgl_h_ -#define SDL_ohosgl_h_ +#include "SDL_ohosvideo.h" +#include "../../SDL_internal.h" -SDL_GLContext OHOS_GLES_CreateContext(_THIS, SDL_Window * window); -int OHOS_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context); -int OHOS_GLES_SwapWindow(_THIS, SDL_Window * window); -int OHOS_GLES_LoadLibrary(_THIS, const char *path); +SDL_GLContext OHOS_GLES_CreateContext(SDL_VideoDevice *thisDevice, SDL_Window* window); +int OHOS_GLES_MakeCurrent(SDL_VideoDevice *thisDevice, SDL_Window* window, SDL_GLContext context); +int OHOS_GLES_SwapWindow(SDL_VideoDevice *thisDevice, SDL_Window* window); +int OHOS_GLES_LoadLibrary(SDL_VideoDevice *thisDevice, const char *path); -#endif /* SDL_ohosgl_h_ */ +#endif /* SDL_OHOSGL_H */ /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/ohos/SDL_ohoskeyboard.c b/src/video/ohos/SDL_ohoskeyboard.c index bf2b0a25c..8c5e66f7f 100644 --- a/src/video/ohos/SDL_ohoskeyboard.c +++ b/src/video/ohos/SDL_ohoskeyboard.c @@ -475,8 +475,7 @@ OHOS_InitKeyboard(void) } -static SDL_Scancode -TranslateKeycode(int keycode) +static SDL_Scancode TranslateKeycode(int keycode) { int i; @@ -504,8 +503,7 @@ TranslateKeycode(int keycode) if (keycode != KEYCODE_NUMPAD_0) { return SDL_SCANCODE_KP_1 + (keycode - KEYCODE_NUMPAD_1); - } - else + } else { return SDL_SCANCODE_KP_0; } @@ -517,15 +515,12 @@ TranslateKeycode(int keycode) for (i = 0; i < SDL_arraysize(KeyCodeToSDLScancode); ++i) { - if (keycode == KeyCodeToSDLScancode[i].keycode) - { + if (keycode == KeyCodeToSDLScancode[i].keycode) { return KeyCodeToSDLScancode[i].scancode; } } - SDL_Log("OHOS TranslateKeycode, unknown keycode=%d\n", keycode); return SDL_SCANCODE_UNKNOWN; - } int @@ -534,8 +529,7 @@ OHOS_OnKeyDown(int keycode) return SDL_SendKeyboardKey(SDL_PRESSED, TranslateKeycode(keycode)); } -int -OHOS_OnKeyUp(int keycode) +int OHOS_OnKeyUp(int keycode) { return SDL_SendKeyboardKey(SDL_RELEASED, TranslateKeycode(keycode)); } @@ -546,28 +540,26 @@ OHOS_HasScreenKeyboardSupport(SDL_VideoDevice *_this) return SDL_TRUE; } -SDL_bool -OHOS_IsScreenKeyboardShown(SDL_VideoDevice *_this, SDL_Window * window) +SDL_bool OHOS_IsScreenKeyboardShown(SDL_VideoDevice *_this, SDL_Window* window) { return true; } void -OHOS_StartTextInput(SDL_VideoDevice *_this) +OHOS_StartTextInput(SDL_VideoDevice *thisDevice) { OHOS_NAPI_ShowTextInputKeyboard(SDL_TRUE); } void -OHOS_StopTextInput(SDL_VideoDevice *_this) +OHOS_StopTextInput(SDL_VideoDevice *thisDevice) { OHOS_NAPI_HideTextInput(1); } -void -OHOS_SetTextInputRect(SDL_VideoDevice *_this, SDL_Rect *rect) +void OHOS_SetTextInputRect(SDL_VideoDevice *thisDevice, SDL_Rect *rect) { - SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *videodata = (SDL_VideoData *)thisDevice->driverdata; if (!rect) { SDL_InvalidParamError("rect"); diff --git a/src/video/ohos/SDL_ohoskeyboard.h b/src/video/ohos/SDL_ohoskeyboard.h index 96145d7d6..b0839b1ec 100644 --- a/src/video/ohos/SDL_ohoskeyboard.h +++ b/src/video/ohos/SDL_ohoskeyboard.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef SDL_OHOSKEYBOARD_H_ -#define SDL_OHOSKEYBOARD_H_ +#ifndef SDL_OHOSKEYBOARD_H +#define SDL_OHOSKEYBOARD_H #include "SDL_ohosvideo.h" @@ -23,12 +23,12 @@ extern int OHOS_OnKeyDown(int keycode); extern int OHOS_OnKeyUp(int keycode); extern SDL_bool OHOS_HasScreenKeyboardSupport(SDL_VideoDevice *_this); -extern SDL_bool OHOS_IsScreenKeyboardShown(SDL_VideoDevice *_this, SDL_Window * window); +extern SDL_bool OHOS_IsScreenKeyboardShown(SDL_VideoDevice *_this, SDL_Window* window); -extern void OHOS_StartTextInput(SDL_VideoDevice *_this); -extern void OHOS_StopTextInput(SDL_VideoDevice *_this); -extern void OHOS_SetTextInputRect(SDL_VideoDevice *_this, SDL_Rect *rect); +extern void OHOS_StartTextInput(SDL_VideoDevice *thisDevice); +extern void OHOS_StopTextInput(SDL_VideoDevice *thisDevice); +extern void OHOS_SetTextInputRect(SDL_VideoDevice *thisDevice, SDL_Rect *rect); -#endif /* SDL_ohoskeyboard_h_ */ +#endif /* SDL_OHOSKEYBOARD_H */ /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/ohos/SDL_ohosvideo.c b/src/video/ohos/SDL_ohosvideo.c index 934c6217f..7c8e85a67 100644 --- a/src/video/ohos/SDL_ohosvideo.c +++ b/src/video/ohos/SDL_ohosvideo.c @@ -52,18 +52,17 @@ int OHOS_GetDisplayDPI(SDL_VideoDevice *_this, SDL_VideoDisplay *display, float /* These are filled in with real values in OHOS_SetScreenResolution on init (before SDL_main()) */ -int OHOS_SurfaceWidth = 0; -int OHOS_SurfaceHeight = 0; -int OHOS_DeviceWidth = 0; -int OHOS_DeviceHeight = 0; +int g_ohosSurfaceWidth = 0; +int g_ohosSurfaceHeight = 0; +int g_ohosDeviceWidth = 0; +int g_ohosDeviceHeight = 0; static Uint32 OHOS_ScreenFormat = SDL_PIXELFORMAT_UNKNOWN; static int OHOS_ScreenRate = 0; SDL_sem *OHOS_PauseSem = NULL; SDL_sem *OHOS_ResumeSem = NULL; SDL_mutex *OHOS_PageMutex = NULL; -static int -OHOS_Available(void) +static int OHOS_Available(void) { return 1; } @@ -71,39 +70,18 @@ OHOS_Available(void) static void OHOS_SuspendScreenSaver(SDL_VideoDevice *_this) { - } -static void -OHOS_DeleteDevice(SDL_VideoDevice *device) +static void OHOS_DeleteDevice(SDL_VideoDevice *device) { SDL_free(device->driverdata); SDL_free(device); } -static SDL_VideoDevice * -OHOS_CreateDevice(int devindex) +static void OHOS_SetDevice(SDL_VideoDevice *device) { - SDL_VideoDevice *device; - SDL_VideoData *data; SDL_bool block_on_pause; - - /* Initialize all variables that we clean on shutdown */ - device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice)); - if (!device) { - SDL_OutOfMemory(); - return NULL; - } - - data = (SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData)); - if (!data) { - SDL_OutOfMemory(); - SDL_free(device); - return NULL; - } - - device->driverdata = data; - + /* Set the function pointers */ device->VideoInit = OHOS_VideoInit; device->VideoQuit = OHOS_VideoQuit; @@ -144,7 +122,30 @@ OHOS_CreateDevice(int devindex) /* Screensaver */ device->SuspendScreenSaver = OHOS_SuspendScreenSaver; +} + +static SDL_VideoDevice * +OHOS_CreateDevice(int devindex) +{ + SDL_VideoDevice *device; + SDL_VideoData *data; + /* Initialize all variables that we clean on shutdown */ + device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice)); + if (!device) { + SDL_OutOfMemory(); + return NULL; + } + + data = (SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData)); + if (!data) { + SDL_OutOfMemory(); + SDL_free(device); + return NULL; + } + + device->driverdata = data; + OHOS_SetDevice(device); return device; } @@ -166,8 +167,8 @@ OHOS_VideoInit(SDL_VideoDevice *_this) videodata->isPausing = SDL_FALSE; mode.format = OHOS_ScreenFormat; - mode.w = OHOS_DeviceWidth; - mode.h = OHOS_DeviceHeight; + mode.w = g_ohosDeviceWidth; + mode.h = g_ohosDeviceHeight; mode.refresh_rate = OHOS_ScreenRate; mode.driverdata = NULL; @@ -188,15 +189,13 @@ OHOS_VideoInit(SDL_VideoDevice *_this) return 0; } -void -OHOS_VideoQuit(SDL_VideoDevice *_this) +void OHOS_VideoQuit(SDL_VideoDevice *_this) { OHOS_QuitMouse(); OHOS_QuitTouch(); } -int -OHOS_GetDisplayDPI(SDL_VideoDevice *_this, SDL_VideoDisplay *display, float *ddpi, float *hdpi, float *vdpi) +int OHOS_GetDisplayDPI(SDL_VideoDevice *_this, SDL_VideoDisplay *display, float *ddpi, float *hdpi, float *vdpi) { return 0; } @@ -205,14 +204,14 @@ void OHOS_SetScreenResolution(int deviceWidth, int deviceHeight, Uint32 format, { OHOS_ScreenFormat = format; OHOS_ScreenRate = (int)rate; - OHOS_DeviceWidth = deviceWidth; - OHOS_DeviceHeight = deviceHeight; + g_ohosDeviceWidth = deviceWidth; + g_ohosDeviceHeight = deviceHeight; } void OHOS_SetScreenSize(int surfaceWidth, int surfaceHeight) { - OHOS_SurfaceWidth = surfaceWidth; - OHOS_SurfaceHeight = surfaceHeight; + g_ohosSurfaceWidth = surfaceWidth; + g_ohosSurfaceHeight = surfaceHeight; } @@ -221,16 +220,14 @@ void OHOS_SendResize(SDL_Window *window) /* Update the resolution of the desktop mode, so that the window can be properly resized. The screen resolution change can for - example happen when the Activity enters or exits immersive mode, which can happen after VideoInit(). */ SDL_VideoDevice *device = SDL_GetVideoDevice(); - if (device && device->num_displays > 0) - { + if (device && device->num_displays > 0) { SDL_VideoDisplay *display = &device->displays[0]; display->desktop_mode.format = OHOS_ScreenFormat; - display->desktop_mode.w = OHOS_DeviceWidth; - display->desktop_mode.h = OHOS_DeviceHeight; + display->desktop_mode.w = g_ohosDeviceWidth; + display->desktop_mode.h = g_ohosDeviceHeight; display->desktop_mode.refresh_rate = OHOS_ScreenRate; } @@ -239,12 +236,12 @@ void OHOS_SendResize(SDL_Window *window) * will fall back to the old mode */ SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); display->display_modes[0].format = OHOS_ScreenFormat; - display->display_modes[0].w = OHOS_DeviceWidth; - display->display_modes[0].h = OHOS_DeviceHeight; + display->display_modes[0].w = g_ohosDeviceWidth; + display->display_modes[0].h = g_ohosDeviceHeight; display->display_modes[0].refresh_rate = OHOS_ScreenRate; display->current_mode = display->display_modes[0]; - SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, OHOS_SurfaceWidth, OHOS_SurfaceHeight); + SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, g_ohosSurfaceWidth, g_ohosSurfaceHeight); } } diff --git a/src/video/ohos/SDL_ohosvideo.h b/src/video/ohos/SDL_ohosvideo.h index 72d19ec1a..1b92ecd34 100644 --- a/src/video/ohos/SDL_ohosvideo.h +++ b/src/video/ohos/SDL_ohosvideo.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef SDL_OHOSVIDEO_H_ -#define SDL_OHOSVIDEO_H_ +#ifndef SDL_OHOSVIDEO_H +#define SDL_OHOSVIDEO_H #include #include "../../core/ohos/SDL_ohos.h" @@ -32,22 +32,21 @@ extern void OHOS_SetScreenSize(int surfaceWidth, int surfaceHeight); /* Private display data */ -typedef struct SDL_VideoData -{ +typedef struct SDL_VideoData { SDL_Rect textRect; int isPaused; int isPausing; } SDL_VideoData; -extern int OHOS_SurfaceWidth; -extern int OHOS_SurfaceHeight; -extern int OHOS_DeviceWidth; -extern int OHOS_DeviceHeight; +extern int g_ohosSurfaceWidth; +extern int g_ohosSurfaceHeight; +extern int g_ohosDeviceWidth; +extern int g_ohosDeviceHeight; extern SDL_sem *OHOS_PauseSem, *OHOS_ResumeSem; extern SDL_mutex *OHOS_PageMutex; -extern SDL_Window *OHOS_Window; +extern SDL_Window *g_ohosWindow; -#endif /* SDL_ohosvideo_h_ */ +#endif /* SDL_OHOSVIDEO_H */ /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/ohos/SDL_ohoswindow.c b/src/video/ohos/SDL_ohoswindow.c index d17d2afa8..4e799e3c5 100644 --- a/src/video/ohos/SDL_ohoswindow.c +++ b/src/video/ohos/SDL_ohoswindow.c @@ -34,21 +34,21 @@ #include "SDL_hints.h" /* Currently only one window */ -SDL_Window *OHOS_Window = NULL; +SDL_Window *g_ohosWindow = NULL; SDL_atomic_t bWindowCreateFlag; int -OHOS_CreateWindow(SDL_VideoDevice *_this, SDL_Window * window) +OHOS_CreateWindow(SDL_VideoDevice *thisDevice, SDL_Window * window) { SDL_WindowData *data; int retval = 0; unsigned int delaytime = 0; - - while (SDL_AtomicGet(&bWindowCreateFlag) == SDL_FALSE) { + + while (SDL_AtomicGet(&bWindowCreateFlag) == SDL_FALSE) { SDL_Delay(OHOS_GETWINDOW_DELAY_TIME); - } + } - if (OHOS_Window) { + if (g_ohosWindow) { retval = SDL_SetError("OHOS only supports one window"); goto endfunction; } @@ -60,8 +60,8 @@ OHOS_CreateWindow(SDL_VideoDevice *_this, SDL_Window * window) /* Adjust the window data to match the screen */ window->x = window->windowed.x; window->y = window->windowed.y; - window->w = OHOS_SurfaceWidth; - window->h = OHOS_SurfaceHeight; + window->w = g_ohosSurfaceWidth; + window->h = g_ohosSurfaceHeight; window->flags &= ~SDL_WINDOW_HIDDEN; window->flags |= SDL_WINDOW_SHOWN; /* only one window on OHOS */ @@ -83,9 +83,9 @@ OHOS_CreateWindow(SDL_VideoDevice *_this, SDL_Window * window) /* Do not create EGLSurface for Vulkan window since it will then make the window incompatible with vkCreateOHOSSurfaceKHR */ if ((window->flags & SDL_WINDOW_OPENGL) != 0) { - data->egl_surface = (EGLSurface)SDL_EGL_CreateSurface(_this, (NativeWindowType)data->native_window); + data->egl_xcomponent = (EGLSurface)SDL_EGL_CreateSurface(thisDevice, (NativeWindowType)data->native_window); - if (data->egl_surface == EGL_NO_SURFACE) { + if (data->egl_xcomponent == EGL_NO_SURFACE) { SDL_free(data->native_window); SDL_free(data); retval = -1; @@ -94,8 +94,8 @@ OHOS_CreateWindow(SDL_VideoDevice *_this, SDL_Window * window) } window->driverdata = data; - OHOS_Window = window; - SDL_SendWindowEvent(OHOS_Window, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0); + g_ohosWindow = window; + SDL_SendWindowEvent(g_ohosWindow, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0); endfunction : SDL_UnlockMutex(OHOS_PageMutex); @@ -104,19 +104,18 @@ endfunction : } void -OHOS_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window) +OHOS_SetWindowTitle(SDL_VideoDevice *thisDevice, SDL_Window *window) { OHOS_NAPI_SetTitle(window->title); } void -OHOS_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen) +OHOS_SetWindowFullscreen(SDL_VideoDevice *thisDevice, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen) { SDL_WindowData *data; - SDL_LockMutex(OHOS_PageMutex); - if (window == OHOS_Window) { + if (window == g_ohosWindow) { /* If the window is being destroyed don't change visible state */ if (!window->is_destroying) { @@ -139,22 +138,21 @@ endfunction: } void -OHOS_MinimizeWindow(SDL_VideoDevice *_this, SDL_Window *window) +OHOS_MinimizeWindow(SDL_VideoDevice *thisDevice, SDL_Window *window) { } -void -OHOS_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window) +void OHOS_DestroyWindow(SDL_VideoDevice *thisDevice, SDL_Window *window) { SDL_LockMutex(OHOS_PageMutex); - if (window == OHOS_Window) { - OHOS_Window = NULL; + if (window == g_ohosWindow) { + g_ohosWindow = NULL; if (window->driverdata) { SDL_WindowData *data = (SDL_WindowData *) window->driverdata; - if (data->egl_surface != EGL_NO_SURFACE) { - SDL_EGL_DestroySurface(_this, data->egl_surface); + if (data->egl_xcomponent != EGL_NO_SURFACE) { + SDL_EGL_DestroySurface(thisDevice, data->egl_xcomponent); } if (data->native_window) { } @@ -166,8 +164,7 @@ OHOS_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window) SDL_UnlockMutex(OHOS_PageMutex); } -SDL_bool -OHOS_GetWindowWMInfo(SDL_VideoDevice *_this, SDL_Window *window, SDL_SysWMinfo *info) +SDL_bool OHOS_GetWindowWMInfo(SDL_VideoDevice *thisDevice, SDL_Window *window, SDL_SysWMinfo *info) { SDL_WindowData *data = (SDL_WindowData *) window->driverdata; @@ -175,7 +172,7 @@ OHOS_GetWindowWMInfo(SDL_VideoDevice *_this, SDL_Window *window, SDL_SysWMinfo * info->version.minor == SDL_MINOR_VERSION) { info->subsystem = SDL_SYSWM_OHOS; info->info.ohos.window = data->native_window; - info->info.ohos.surface = data->egl_surface; + info->info.ohos.surface = data->egl_xcomponent; return SDL_TRUE; } else { SDL_SetError("Application not compiled with SDL %d.%d", @@ -184,39 +181,41 @@ OHOS_GetWindowWMInfo(SDL_VideoDevice *_this, SDL_Window *window, SDL_SysWMinfo * } } -void OHOS_SetWindowResizable(SDL_VideoDevice *_this, SDL_Window *window, SDL_bool resizable) { +void OHOS_SetWindowResizable(SDL_VideoDevice *thisDevice, SDL_Window *window, SDL_bool resizable) +{ if (resizable) { OHOS_NAPI_SetWindowResize(window->windowed.x, window->windowed.y, window->windowed.w, window->windowed.h); } } -void OHOS_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window) { +void OHOS_SetWindowSize(SDL_VideoDevice *thisDevice, SDL_Window *window) +{ if ((window->flags & SDL_WINDOW_RESIZABLE) != 0) { window->flags &= ~SDL_WINDOW_RESIZABLE; } SDL_SetWindowResizable(window, SDL_TRUE); while (SDL_TRUE) { - if ((window->w == OHOS_SurfaceWidth) && (window->h == OHOS_SurfaceHeight)) { + if ((window->w == g_ohosSurfaceWidth) && (window->h == g_ohosSurfaceHeight)) { break; } SDL_Delay(OHOS_GETWINDOW_DELAY_TIME); } } -int -OHOS_CreateWindowFrom(SDL_VideoDevice *_this, SDL_Window *window, const void *data) { +int OHOS_CreateWindowFrom(SDL_VideoDevice *thisDevice, SDL_Window *window, const void *data) +{ SDL_Window *w = (SDL_Window *)data; - window->title = OHOS_GetWindowTitle(_this, w); + window->title = OHOS_GetWindowTitle(thisDevice, w); - if (SetupWindowData(_this, window, w) < 0) { + if (SetupWindowData(thisDevice, window, w) < 0) { return -1; } return 0; } -char -*OHOS_GetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window) { +char *OHOS_GetWindowTitle(SDL_VideoDevice *thisDevice, SDL_Window *window) +{ char *title = NULL; title = window->title; if (title) { @@ -227,7 +226,8 @@ char } int -SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, SDL_Window *w) { +SetupWindowData(SDL_VideoDevice *thisDevice, SDL_Window *window, SDL_Window *w) +{ SDL_WindowData *data; unsigned int delaytime = 0; @@ -239,7 +239,7 @@ SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, SDL_Window *w) { window->w = w->w; window->h = w->h; - OHOS_DestroyWindow(_this, w); + OHOS_DestroyWindow(thisDevice, w); data = (SDL_WindowData *)SDL_calloc(1, sizeof(*data)); if (!data) { return SDL_OutOfMemory(); @@ -255,23 +255,23 @@ SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, SDL_Window *w) { } if ((window->flags & SDL_WINDOW_OPENGL) != 0) { - data->egl_surface = (EGLSurface)SDL_EGL_CreateSurface(_this, (NativeWindowType)data->native_window); + data->egl_xcomponent = (EGLSurface)SDL_EGL_CreateSurface(thisDevice, (NativeWindowType)data->native_window); - if (data->egl_surface == EGL_NO_SURFACE) { + if (data->egl_xcomponent == EGL_NO_SURFACE) { SDL_free(data->native_window); SDL_free(data); goto endfunction; } } window->driverdata = data; - SDL_SendWindowEvent(OHOS_Window, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0); + SDL_SendWindowEvent(g_ohosWindow, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0); endfunction: SDL_UnlockMutex(OHOS_PageMutex); /* All done! */ return 0; -} +} #endif /* SDL_VIDEO_DRIVER_OHOS */ /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/ohos/SDL_ohoswindow.h b/src/video/ohos/SDL_ohoswindow.h index 5dd73195d..7338cff5e 100644 --- a/src/video/ohos/SDL_ohoswindow.h +++ b/src/video/ohos/SDL_ohoswindow.h @@ -13,36 +13,36 @@ * limitations under the License. */ -#ifndef SDL_OHOSWINDOW_H_ -#define SDL_OHOSWINDOW_H_ +#ifndef SDL_OHOSWINDOW_H +#define SDL_OHOSWINDOW_H #include "../../core/ohos/SDL_ohos.h" #include "../SDL_egl_c.h" #include "../../core/ohos/SDL_ohos_xcomponent.h" -extern int OHOS_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window); -extern void OHOS_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window); -extern void OHOS_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen); -extern void OHOS_MinimizeWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern int OHOS_CreateWindow(SDL_VideoDevice *thisDevice, SDL_Window *window); +extern void OHOS_SetWindowTitle(SDL_VideoDevice *thisDevice, SDL_Window *window); +extern void OHOS_SetWindowFullscreen(SDL_VideoDevice *thisDevice, SDL_Window *window, SDL_VideoDisplay *display, + SDL_bool fullscreen); +extern void OHOS_MinimizeWindow(SDL_VideoDevice *thisDevice, SDL_Window *window); -extern void OHOS_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window); -extern SDL_bool OHOS_GetWindowWMInfo(SDL_VideoDevice *_this, SDL_Window *window, struct SDL_SysWMinfo *info); -extern void OHOS_SetWindowResizable(SDL_VideoDevice *_this, SDL_Window *window, SDL_bool resizable); -extern void OHOS_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window); -extern int OHOS_CreateWindowFrom(SDL_VideoDevice *_this, SDL_Window *window, const void *data); -extern char *OHOS_GetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window); -extern int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, SDL_Window *w); -extern SDL_Window *OHOS_Window; +extern void OHOS_DestroyWindow(SDL_VideoDevice *thisDevice, SDL_Window *window); +extern SDL_bool OHOS_GetWindowWMInfo(SDL_VideoDevice *thisDevice, SDL_Window *window, struct SDL_SysWMinfo *info); +extern void OHOS_SetWindowResizable(SDL_VideoDevice *thisDevice, SDL_Window *window, SDL_bool resizable); +extern void OHOS_SetWindowSize(SDL_VideoDevice *thisDevice, SDL_Window *window); +extern int OHOS_CreateWindowFrom(SDL_VideoDevice *thisDevice, SDL_Window *window, const void *data); +extern char *OHOS_GetWindowTitle(SDL_VideoDevice *thisDevice, SDL_Window *window); +extern int SetupWindowData(SDL_VideoDevice *thisDevice, SDL_Window *window, SDL_Window *w); +extern SDL_Window *g_ohosWindow; extern SDL_atomic_t bWindowCreateFlag; -typedef struct -{ - EGLSurface egl_surface; +typedef struct { + EGLSurface egl_xcomponent; EGLContext egl_context; /* We use this to preserve the context when losing focus */ SDL_bool backup_done; OHNativeWindow *native_window; } SDL_WindowData; -#endif /* SDL_ohoswindow_h_ */ +#endif /* SDL_OHOSWINDOW_H */ /* vi: set ts=4 sw=4 expandtab: */ -- Gitee