From ed4fcb2cfce31508481bf6dd061b7637e11e62b4 Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Wed, 16 Dec 2020 03:24:10 +0300 Subject: [PATCH] kmsdrm_legacy build fixes: - add missing '_LEGACY' to symbol names - perform missing 2.0.14 portage - fix 'for' loop initial declarations are only allowed in C99 mode errors --- .../kmsdrm_legacy/SDL_kmsdrm_legacy_dyn.c | 28 +++++++------- .../kmsdrm_legacy/SDL_kmsdrm_legacy_dyn.h | 4 +- .../kmsdrm_legacy/SDL_kmsdrm_legacy_mouse.c | 6 +-- .../kmsdrm_legacy/SDL_kmsdrm_legacy_video.c | 37 +++++++++++-------- .../kmsdrm_legacy/SDL_kmsdrm_legacy_video.h | 2 +- 5 files changed, 42 insertions(+), 35 deletions(-) diff --git a/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_dyn.c b/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_dyn.c index 26bdc2b13..019c8e188 100644 --- a/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_dyn.c +++ b/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_dyn.c @@ -79,9 +79,9 @@ KMSDRM_LEGACY_GetSym(const char *fnname, int *pHasModule) #endif /* SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC */ /* Define all the function pointers and wrappers... */ -#define SDL_KMSDRM_LEGACY_MODULE(modname) int SDL_KMSDRM_HAVE_##modname = 0; -#define SDL_KMSDRM_LEGACY_SYM(rc,fn,params) SDL_DYNKMSDRMFN_##fn KMSDRM_##fn = NULL; -#define SDL_KMSDRM_LEGACY_SYM_CONST(type,name) SDL_DYNKMSDRMCONST_##name KMSDRM_##name = NULL; +#define SDL_KMSDRM_LEGACY_MODULE(modname) int SDL_KMSDRM_LEGACY_HAVE_##modname = 0; +#define SDL_KMSDRM_LEGACY_SYM(rc,fn,params) SDL_DYNKMSDRM_LEGACYFN_##fn KMSDRM_LEGACY_##fn = NULL; +#define SDL_KMSDRM_LEGACY_SYM_CONST(type,name) SDL_DYNKMSDRM_LEGACYCONST_##name KMSDRM_LEGACY_##name = NULL; #include "SDL_kmsdrm_legacy_sym.h" static int kmsdrm_load_refcount = 0; @@ -97,9 +97,9 @@ SDL_KMSDRM_LEGACY_UnloadSymbols(void) #endif /* set all the function pointers to NULL. */ -#define SDL_KMSDRM_LEGACY_MODULE(modname) SDL_KMSDRM_HAVE_##modname = 0; -#define SDL_KMSDRM_LEGACY_SYM(rc,fn,params) KMSDRM_##fn = NULL; -#define SDL_KMSDRM_LEGACY_SYM_CONST(type,name) KMSDRM_##name = NULL; +#define SDL_KMSDRM_LEGACY_MODULE(modname) SDL_KMSDRM_LEGACY_HAVE_##modname = 0; +#define SDL_KMSDRM_LEGACY_SYM(rc,fn,params) KMSDRM_LEGACY_##fn = NULL; +#define SDL_KMSDRM_LEGACY_SYM_CONST(type,name) KMSDRM_LEGACY_##name = NULL; #include "SDL_kmsdrm_legacy_sym.h" @@ -132,15 +132,15 @@ SDL_KMSDRM_LEGACY_LoadSymbols(void) } } -#define SDL_KMSDRM_LEGACY_MODULE(modname) SDL_KMSDRM_HAVE_##modname = 1; /* default yes */ +#define SDL_KMSDRM_LEGACY_MODULE(modname) SDL_KMSDRM_LEGACY_HAVE_##modname = 1; /* default yes */ #include "SDL_kmsdrm_legacy_sym.h" -#define SDL_KMSDRM_LEGACY_MODULE(modname) thismod = &SDL_KMSDRM_HAVE_##modname; -#define SDL_KMSDRM_LEGACY_SYM(rc,fn,params) KMSDRM_##fn = (SDL_DYNKMSDRMFN_##fn) KMSDRM_GetSym(#fn,thismod); -#define SDL_KMSDRM_LEGACY_SYM_CONST(type,name) KMSDRM_##name = *(SDL_DYNKMSDRMCONST_##name*) KMSDRM_GetSym(#name,thismod); +#define SDL_KMSDRM_LEGACY_MODULE(modname) thismod = &SDL_KMSDRM_LEGACY_HAVE_##modname; +#define SDL_KMSDRM_LEGACY_SYM(rc,fn,params) KMSDRM_LEGACY_##fn = (SDL_DYNKMSDRM_LEGACYFN_##fn) KMSDRM_LEGACY_GetSym(#fn,thismod); +#define SDL_KMSDRM_LEGACY_SYM_CONST(type,name) KMSDRM_LEGACY_##name = *(SDL_DYNKMSDRM_LEGACYCONST_##name*) KMSDRM_LEGACY_GetSym(#name,thismod); #include "SDL_kmsdrm_legacy_sym.h" - if ((SDL_KMSDRM_LEGACY_HAVE_LIBDRM) && (SDL_KMSDRM_HAVE_GBM)) { + if ((SDL_KMSDRM_LEGACY_HAVE_LIBDRM) && (SDL_KMSDRM_LEGACY_HAVE_GBM)) { /* all required symbols loaded. */ SDL_ClearError(); } else { @@ -151,9 +151,9 @@ SDL_KMSDRM_LEGACY_LoadSymbols(void) #else /* no dynamic KMSDRM_LEGACY */ -#define SDL_KMSDRM_LEGACY_MODULE(modname) SDL_KMSDRM_HAVE_##modname = 1; /* default yes */ -#define SDL_KMSDRM_LEGACY_SYM(rc,fn,params) KMSDRM_##fn = fn; -#define SDL_KMSDRM_LEGACY_SYM_CONST(type,name) KMSDRM_##name = name; +#define SDL_KMSDRM_LEGACY_MODULE(modname) SDL_KMSDRM_LEGACY_HAVE_##modname = 1; /* default yes */ +#define SDL_KMSDRM_LEGACY_SYM(rc,fn,params) KMSDRM_LEGACY_##fn = fn; +#define SDL_KMSDRM_LEGACY_SYM_CONST(type,name) KMSDRM_LEGACY_##name = name; #include "SDL_kmsdrm_legacy_sym.h" #endif diff --git a/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_dyn.h b/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_dyn.h index 6ff8a317b..3cb67b08e 100644 --- a/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_dyn.h +++ b/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_dyn.h @@ -38,10 +38,10 @@ void SDL_KMSDRM_LEGACY_UnloadSymbols(void); /* Declare all the function pointers and wrappers... */ #define SDL_KMSDRM_LEGACY_SYM(rc,fn,params) \ typedef rc (*SDL_DYNKMSDRM_LEGACYFN_##fn) params; \ - extern SDL_DYNKMSDRM_LEGACYFN_##fn KMSDRM_##fn; + extern SDL_DYNKMSDRM_LEGACYFN_##fn KMSDRM_LEGACY_##fn; #define SDL_KMSDRM_LEGACY_SYM_CONST(type, name) \ typedef type SDL_DYNKMSDRM_LEGACYCONST_##name; \ - extern SDL_DYNKMSDRM_LEGACYCONST_##name KMSDRM_##name; + extern SDL_DYNKMSDRM_LEGACYCONST_##name KMSDRM_LEGACY_##name; #include "SDL_kmsdrm_legacy_sym.h" #ifdef __cplusplus diff --git a/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_mouse.c b/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_mouse.c index 0357b83de..c980ebba6 100644 --- a/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_mouse.c +++ b/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_mouse.c @@ -394,7 +394,7 @@ KMSDRM_LEGACY_FreeCursor(SDL_Cursor * cursor) if (curdata) { if (curdata->bo) { if (curdata->crtc_id != 0) { - drm_fd = KMSDRM_LEGACY_gbm_device_get_fd(KMSDRM_gbm_bo_get_device(curdata->bo)); + drm_fd = KMSDRM_LEGACY_gbm_device_get_fd(KMSDRM_LEGACY_gbm_bo_get_device(curdata->bo)); /* Hide the cursor if previously shown on a CRTC */ KMSDRM_LEGACY_drmModeSetCursor(drm_fd, curdata->crtc_id, 0, 0, 0); curdata->crtc_id = 0; @@ -433,7 +433,7 @@ KMSDRM_LEGACY_WarpMouseGlobal(int x, int y) if (curdata->crtc_id != 0) { int ret, drm_fd; - drm_fd = KMSDRM_LEGACY_gbm_device_get_fd(KMSDRM_gbm_bo_get_device(curdata->bo)); + drm_fd = KMSDRM_LEGACY_gbm_device_get_fd(KMSDRM_LEGACY_gbm_bo_get_device(curdata->bo)); ret = KMSDRM_LEGACY_drmModeMoveCursor(drm_fd, curdata->crtc_id, x, y); if (ret) { @@ -488,7 +488,7 @@ KMSDRM_LEGACY_MoveCursor(SDL_Cursor * cursor) That's why we move the cursor graphic ONLY. */ if (mouse && mouse->cur_cursor && mouse->cur_cursor->driverdata) { curdata = (KMSDRM_LEGACY_CursorData *) mouse->cur_cursor->driverdata; - drm_fd = KMSDRM_LEGACY_gbm_device_get_fd(KMSDRM_gbm_bo_get_device(curdata->bo)); + drm_fd = KMSDRM_LEGACY_gbm_device_get_fd(KMSDRM_LEGACY_gbm_bo_get_device(curdata->bo)); ret = KMSDRM_LEGACY_drmModeMoveCursor(drm_fd, curdata->crtc_id, mouse->x, mouse->y); if (ret) { diff --git a/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_video.c b/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_video.c index 666415dcd..36b1899bd 100644 --- a/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_video.c +++ b/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_video.c @@ -160,6 +160,10 @@ KMSDRM_LEGACY_CreateDevice(int devindex) SDL_VideoDevice *device; SDL_VideoData *viddata; + if (!KMSDRM_LEGACY_Available()) { + return NULL; + } + if (!devindex || (devindex > 99)) { devindex = get_driindex(); } @@ -236,7 +240,6 @@ cleanup: VideoBootStrap KMSDRM_LEGACY_bootstrap = { "KMSDRM_LEGACY", "KMS/DRM Video Driver", - KMSDRM_LEGACY_Available, KMSDRM_LEGACY_CreateDevice }; @@ -244,7 +247,7 @@ VideoBootStrap KMSDRM_LEGACY_bootstrap = { static void KMSDRM_LEGACY_FBDestroyCallback(struct gbm_bo *bo, void *data) { - KMSDRM_LEGACY_FBInfo *fb_info = (KMSDRM_FBInfo *)data; + KMSDRM_LEGACY_FBInfo *fb_info = (KMSDRM_LEGACY_FBInfo *)data; if (fb_info && fb_info->drm_fd >= 0 && fb_info->fb_id != 0) { KMSDRM_LEGACY_drmModeRmFB(fb_info->drm_fd, fb_info->fb_id); @@ -263,7 +266,7 @@ KMSDRM_LEGACY_FBFromBO(_THIS, struct gbm_bo *bo) Uint32 stride, handle; /* Check for an existing framebuffer */ - KMSDRM_LEGACY_FBInfo *fb_info = (KMSDRM_FBInfo *)KMSDRM_gbm_bo_get_user_data(bo); + KMSDRM_LEGACY_FBInfo *fb_info = (KMSDRM_LEGACY_FBInfo *)KMSDRM_LEGACY_gbm_bo_get_user_data(bo); if (fb_info) { return fb_info; @@ -271,7 +274,7 @@ KMSDRM_LEGACY_FBFromBO(_THIS, struct gbm_bo *bo) /* Create a structure that contains enough info to remove the framebuffer when the backing buffer is destroyed */ - fb_info = (KMSDRM_LEGACY_FBInfo *)SDL_calloc(1, sizeof(KMSDRM_FBInfo)); + fb_info = (KMSDRM_LEGACY_FBInfo *)SDL_calloc(1, sizeof(KMSDRM_LEGACY_FBInfo)); if (!fb_info) { SDL_OutOfMemory(); @@ -296,7 +299,7 @@ KMSDRM_LEGACY_FBFromBO(_THIS, struct gbm_bo *bo) fb_info->fb_id, w, h, stride, (void *)bo); /* Associate our DRM framebuffer with this buffer object */ - KMSDRM_LEGACY_gbm_bo_set_user_data(bo, fb_info, KMSDRM_FBDestroyCallback); + KMSDRM_LEGACY_gbm_bo_set_user_data(bo, fb_info, KMSDRM_LEGACY_FBDestroyCallback); return fb_info; } @@ -430,7 +433,7 @@ KMSDRM_LEGACY_CreateSurfaces(_THIS, SDL_Window * window) int KMSDRM_LEGACY_VideoInit(_THIS) { - int ret = 0; + int i, j, ret = 0; SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata); SDL_DisplayData *dispdata = NULL; drmModeRes *resources = NULL; @@ -472,7 +475,7 @@ KMSDRM_LEGACY_VideoInit(_THIS) goto cleanup; } - for (int i = 0; i < resources->count_connectors; i++) { + for (i = 0; i < resources->count_connectors; i++) { drmModeConnector *conn = KMSDRM_LEGACY_drmModeGetConnector(viddata->drm_fd, resources->connectors[i]); if (!conn) { @@ -495,7 +498,7 @@ KMSDRM_LEGACY_VideoInit(_THIS) } /* Try to find the connector's current encoder */ - for (int i = 0; i < resources->count_encoders; i++) { + for (i = 0; i < resources->count_encoders; i++) { encoder = KMSDRM_LEGACY_drmModeGetEncoder(viddata->drm_fd, resources->encoders[i]); if (!encoder) { @@ -513,7 +516,7 @@ KMSDRM_LEGACY_VideoInit(_THIS) if (!encoder) { /* No encoder was connected, find the first supported one */ - for (int i = 0, j; i < resources->count_encoders; i++) { + for (i = 0; i < resources->count_encoders; i++) { encoder = KMSDRM_LEGACY_drmModeGetEncoder(viddata->drm_fd, resources->encoders[i]); if (!encoder) { @@ -547,7 +550,7 @@ KMSDRM_LEGACY_VideoInit(_THIS) if (!dispdata->saved_crtc) { /* No CRTC was connected, find the first CRTC that can be connected */ - for (int i = 0; i < resources->count_crtcs; i++) { + for (i = 0; i < resources->count_crtcs; i++) { if (encoder->possible_crtcs & (1 << i)) { encoder->crtc_id = resources->crtcs[i]; dispdata->saved_crtc = KMSDRM_LEGACY_drmModeGetCrtc(viddata->drm_fd, encoder->crtc_id); @@ -594,7 +597,7 @@ KMSDRM_LEGACY_VideoInit(_THIS) #endif display.current_mode = display.desktop_mode; display.driverdata = dispdata; - SDL_AddVideoDisplay(&display); + SDL_AddVideoDisplay(&display, SDL_FALSE); #ifdef SDL_INPUT_LINUXEV SDL_EVDEV_Init(); @@ -691,8 +694,9 @@ KMSDRM_LEGACY_GetDisplayModes(_THIS, SDL_VideoDisplay * display) SDL_DisplayData *dispdata = display->driverdata; drmModeConnector *conn = dispdata->conn; SDL_DisplayMode mode; + int i; - for (int i = 0; i < conn->count_modes; i++) { + for (i = 0; i < conn->count_modes; i++) { SDL_DisplayModeData *modedata = SDL_calloc(1, sizeof(SDL_DisplayModeData)); if (modedata) { @@ -718,6 +722,7 @@ KMSDRM_LEGACY_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode SDL_DisplayData *dispdata = (SDL_DisplayData *)display->driverdata; SDL_DisplayModeData *modedata = (SDL_DisplayModeData *)mode->driverdata; drmModeConnector *conn = dispdata->conn; + int i; if (!modedata) { return SDL_SetError("Mode doesn't have an associated index"); @@ -725,7 +730,7 @@ KMSDRM_LEGACY_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode dispdata->mode = conn->modes[modedata->mode_index]; - for (int i = 0; i < viddata->num_windows; i++) { + for (i = 0; i < viddata->num_windows; i++) { SDL_Window *window = viddata->windows[i]; SDL_WindowData *windata = (SDL_WindowData *)window->driverdata; @@ -826,6 +831,8 @@ KMSDRM_LEGACY_DestroyWindow(_THIS, SDL_Window * window) { SDL_WindowData *windata = (SDL_WindowData *) window->driverdata; SDL_VideoData *viddata; + int i, j; + if (!windata) { return; } @@ -833,11 +840,11 @@ KMSDRM_LEGACY_DestroyWindow(_THIS, SDL_Window * window) /* Remove from the internal window list */ viddata = windata->viddata; - for (int i = 0; i < viddata->num_windows; i++) { + for (i = 0; i < viddata->num_windows; i++) { if (viddata->windows[i] == window) { viddata->num_windows--; - for (int j = i; j < viddata->num_windows; j++) { + for (j = i; j < viddata->num_windows; j++) { viddata->windows[j] = viddata->windows[j + 1]; } diff --git a/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_video.h b/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_video.h index bb19fe5eb..28e1bc4fe 100644 --- a/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_video.h +++ b/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_video.h @@ -85,7 +85,7 @@ typedef struct KMSDRM_LEGACY_FBInfo /* Helper functions */ int KMSDRM_LEGACY_CreateSurfaces(_THIS, SDL_Window * window); -KMSDRM_LEGACY_FBInfo *KMSDRM_FBFromBO(_THIS, struct gbm_bo *bo); +KMSDRM_LEGACY_FBInfo *KMSDRM_LEGACY_FBFromBO(_THIS, struct gbm_bo *bo); SDL_bool KMSDRM_LEGACY_WaitPageFlip(_THIS, SDL_WindowData *windata, int timeout); /****************************************************************************/