From 8746788feaa815b555e0bd32453f98b0d263981e Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 8 Jan 2021 11:08:23 -0800 Subject: [PATCH] KMSDRM_LEGACY is no longer legacy --- .../kmsdrm_legacy/SDL_kmsdrm_legacy_dyn.c | 167 --- .../kmsdrm_legacy/SDL_kmsdrm_legacy_dyn.h | 53 - .../kmsdrm_legacy/SDL_kmsdrm_legacy_events.c | 42 - .../kmsdrm_legacy/SDL_kmsdrm_legacy_events.h | 31 - .../kmsdrm_legacy/SDL_kmsdrm_legacy_mouse.c | 474 ------ .../kmsdrm_legacy/SDL_kmsdrm_legacy_mouse.h | 54 - .../SDL_kmsdrm_legacy_opengles.c | 166 --- .../SDL_kmsdrm_legacy_opengles.h | 48 - .../kmsdrm_legacy/SDL_kmsdrm_legacy_sym.h | 118 -- .../kmsdrm_legacy/SDL_kmsdrm_legacy_video.c | 1280 ----------------- .../kmsdrm_legacy/SDL_kmsdrm_legacy_video.h | 162 --- .../kmsdrm_legacy/SDL_kmsdrm_legacy_vulkan.c | 422 ------ .../kmsdrm_legacy/SDL_kmsdrm_legacy_vulkan.h | 53 - 13 files changed, 3070 deletions(-) delete mode 100644 src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_dyn.c delete mode 100644 src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_dyn.h delete mode 100644 src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_events.c delete mode 100644 src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_events.h delete mode 100644 src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_mouse.c delete mode 100644 src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_mouse.h delete mode 100644 src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_opengles.c delete mode 100644 src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_opengles.h delete mode 100644 src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_sym.h delete mode 100644 src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_video.c delete mode 100644 src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_video.h delete mode 100644 src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_vulkan.c delete mode 100644 src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_vulkan.h diff --git a/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_dyn.c b/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_dyn.c deleted file mode 100644 index d94f0f905..000000000 --- a/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_dyn.c +++ /dev/null @@ -1,167 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2021 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -#include "../../SDL_internal.h" - -#if SDL_VIDEO_DRIVER_KMSDRM - -#define DEBUG_DYNAMIC_KMSDRM_LEGACY 0 - -#include "SDL_kmsdrm_legacy_dyn.h" - -#ifdef SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC - -#include "SDL_name.h" -#include "SDL_loadso.h" - -typedef struct -{ - void *lib; - const char *libname; -} kmsdrmdynlib; - -#ifndef SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC -#define SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC NULL -#endif -#ifndef SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC_GBM -#define SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC_GBM NULL -#endif - -static kmsdrmdynlib kmsdrmlibs[] = { - {NULL, SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC_GBM}, - {NULL, SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC} -}; - -static void * -KMSDRM_LEGACY_GetSym(const char *fnname, int *pHasModule) -{ - int i; - void *fn = NULL; - for (i = 0; i < SDL_TABLESIZE(kmsdrmlibs); i++) { - if (kmsdrmlibs[i].lib != NULL) { - fn = SDL_LoadFunction(kmsdrmlibs[i].lib, fnname); - if (fn != NULL) - break; - } - } - -#if DEBUG_DYNAMIC_KMSDRM_LEGACY - if (fn != NULL) - SDL_Log("KMSDRM_LEGACY: Found '%s' in %s (%p)\n", fnname, kmsdrmlibs[i].libname, fn); - else - SDL_Log("KMSDRM_LEGACY: Symbol '%s' NOT FOUND!\n", fnname); -#endif - - if (fn == NULL) - *pHasModule = 0; /* kill this module. */ - - return fn; -} - -#endif /* SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC */ - -/* Define all the function pointers and wrappers... */ -#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; - -void -SDL_KMSDRM_LEGACY_UnloadSymbols(void) -{ - /* Don't actually unload if more than one module is using the libs... */ - if (kmsdrm_load_refcount > 0) { - if (--kmsdrm_load_refcount == 0) { -#ifdef SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC - int i; -#endif - - /* set all the function pointers to 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" - - -#ifdef SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC - for (i = 0; i < SDL_TABLESIZE(kmsdrmlibs); i++) { - if (kmsdrmlibs[i].lib != NULL) { - SDL_UnloadObject(kmsdrmlibs[i].lib); - kmsdrmlibs[i].lib = NULL; - } - } -#endif - } - } -} - -/* returns non-zero if all needed symbols were loaded. */ -int -SDL_KMSDRM_LEGACY_LoadSymbols(void) -{ - int rc = 1; /* always succeed if not using Dynamic KMSDRM_LEGACY stuff. */ - - /* deal with multiple modules needing these symbols... */ - if (kmsdrm_load_refcount++ == 0) { -#ifdef SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC - int i; - int *thismod = NULL; - for (i = 0; i < SDL_TABLESIZE(kmsdrmlibs); i++) { - if (kmsdrmlibs[i].libname != NULL) { - kmsdrmlibs[i].lib = SDL_LoadObject(kmsdrmlibs[i].libname); - } - } - -#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_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_LEGACY_HAVE_GBM)) { - /* all required symbols loaded. */ - SDL_ClearError(); - } else { - /* in case something got loaded... */ - SDL_KMSDRM_LEGACY_UnloadSymbols(); - rc = 0; - } - -#else /* no dynamic KMSDRM_LEGACY */ - -#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 - } - - return rc; -} - -#endif /* SDL_VIDEO_DRIVER_KMSDRM */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_dyn.h b/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_dyn.h deleted file mode 100644 index f88049612..000000000 --- a/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_dyn.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2021 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -#ifndef SDL_kmsdrmdyn_h_ -#define SDL_kmsdrmdyn_h_ - -#include "../../SDL_internal.h" - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -int SDL_KMSDRM_LEGACY_LoadSymbols(void); -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_LEGACY_##fn; -#define SDL_KMSDRM_LEGACY_SYM_CONST(type, name) \ - typedef type SDL_DYNKMSDRM_LEGACYCONST_##name; \ - extern SDL_DYNKMSDRM_LEGACYCONST_##name KMSDRM_LEGACY_##name; -#include "SDL_kmsdrm_legacy_sym.h" - -#ifdef __cplusplus -} -#endif - -#endif /* SDL_kmsdrmdyn_h_ */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_events.c b/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_events.c deleted file mode 100644 index bcd9c69d6..000000000 --- a/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_events.c +++ /dev/null @@ -1,42 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2021 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -#include "../../SDL_internal.h" - -#if SDL_VIDEO_DRIVER_KMSDRM - -#include "SDL_kmsdrm_legacy_video.h" -#include "SDL_kmsdrm_legacy_events.h" - -#ifdef SDL_INPUT_LINUXEV -#include "../../core/linux/SDL_evdev.h" -#endif - -void KMSDRM_LEGACY_PumpEvents(_THIS) -{ -#ifdef SDL_INPUT_LINUXEV - SDL_EVDEV_Poll(); -#endif - -} - -#endif /* SDL_VIDEO_DRIVER_KMSDRM */ - diff --git a/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_events.h b/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_events.h deleted file mode 100644 index 084175bb2..000000000 --- a/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_events.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2021 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -#include "../../SDL_internal.h" - -#ifndef SDL_kmsdrmevents_h_ -#define SDL_kmsdrmevents_h_ - -extern void KMSDRM_LEGACY_PumpEvents(_THIS); -extern void KMSDRM_LEGACY_EventInit(_THIS); -extern void KMSDRM_LEGACY_EventQuit(_THIS); - -#endif /* SDL_kmsdrmevents_h_ */ diff --git a/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_mouse.c b/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_mouse.c deleted file mode 100644 index e84c9ad9a..000000000 --- a/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_mouse.c +++ /dev/null @@ -1,474 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2021 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -#include "../../SDL_internal.h" - -#if SDL_VIDEO_DRIVER_KMSDRM - -#include "SDL_kmsdrm_legacy_video.h" -#include "SDL_kmsdrm_legacy_mouse.h" -#include "SDL_kmsdrm_legacy_dyn.h" - -#include "../../events/SDL_mouse_c.h" -#include "../../events/default_cursor.h" - -static SDL_Cursor *KMSDRM_LEGACY_CreateDefaultCursor(void); -static SDL_Cursor *KMSDRM_LEGACY_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y); -static int KMSDRM_LEGACY_ShowCursor(SDL_Cursor * cursor); -static void KMSDRM_LEGACY_MoveCursor(SDL_Cursor * cursor); -static void KMSDRM_LEGACY_FreeCursor(SDL_Cursor * cursor); -static void KMSDRM_LEGACY_WarpMouse(SDL_Window * window, int x, int y); -static int KMSDRM_LEGACY_WarpMouseGlobal(int x, int y); - -/**************************************************************************************/ -/* BEFORE CODING ANYTHING MOUSE/CURSOR RELATED, REMEMBER THIS. */ -/* How does SDL manage cursors internally? First, mouse =! cursor. The mouse can have */ -/* many cursors in mouse->cursors. */ -/* -SDL tells us to create a cursor with KMSDRM_CreateCursor(). It can create many */ -/* cursosr with this, not only one. */ -/* -SDL stores those cursors in a cursors array, in mouse->cursors. */ -/* -Whenever it wants (or the programmer wants) takes a cursor from that array */ -/* and shows it on screen with KMSDRM_ShowCursor(). */ -/* KMSDRM_ShowCursor() simply shows or hides the cursor it receives: it does NOT */ -/* mind if it's mouse->cur_cursor, etc. */ -/* -If KMSDRM_ShowCursor() returns succesfully, that cursor becomes mouse->cur_cursor */ -/* and mouse->cursor_shown is 1. */ -/**************************************************************************************/ - -static SDL_Cursor * -KMSDRM_LEGACY_CreateDefaultCursor(void) -{ - return SDL_CreateCursor(default_cdata, default_cmask, DEFAULT_CWIDTH, DEFAULT_CHEIGHT, DEFAULT_CHOTX, DEFAULT_CHOTY); -} - -/* Converts a pixel from straight-alpha [AA, RR, GG, BB], which the SDL cursor surface has, - to premultiplied-alpha [AA. AA*RR, AA*GG, AA*BB]. - These multiplications have to be done with floats instead of uint32_t's, - and the resulting values have to be converted to be relative to the 0-255 interval, - where 255 is 1.00 and anything between 0 and 255 is 0.xx. */ -void legacy_alpha_premultiply_ARGB8888 (uint32_t *pixel) { - - uint32_t A, R, G, B; - - /* Component bytes extraction. */ - A = (*pixel >> (3 << 3)) & 0xFF; - R = (*pixel >> (2 << 3)) & 0xFF; - G = (*pixel >> (1 << 3)) & 0xFF; - B = (*pixel >> (0 << 3)) & 0xFF; - - /* Alpha pre-multiplication of each component. */ - R = (float)A * ((float)R /255); - G = (float)A * ((float)G /255); - B = (float)A * ((float)B /255); - - /* ARGB8888 pixel recomposition. */ - (*pixel) = (((uint32_t)A << 24) | ((uint32_t)R << 16) | ((uint32_t)G << 8)) | ((uint32_t)B << 0); -} - -/* This simply gets the cursor soft-buffer ready. - We don't copy it to a GBO BO until ShowCursor() because the cusor GBM BO (living - in dispata) is destroyed and recreated when we recreate windows, etc. */ -static SDL_Cursor * -KMSDRM_LEGACY_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y) -{ - KMSDRM_LEGACY_CursorData *curdata; - SDL_Cursor *cursor, *ret; - - curdata = NULL; - ret = NULL; - - /* All code below assumes ARGB8888 format for the cursor surface, - like other backends do. Also, the GBM BO pixels have to be - alpha-premultiplied, but the SDL surface we receive has - straight-alpha pixels, so we always have to convert. */ - SDL_assert(surface->format->format == SDL_PIXELFORMAT_ARGB8888); - SDL_assert(surface->pitch == surface->w * 4); - - cursor = (SDL_Cursor *) SDL_calloc(1, sizeof(*cursor)); - if (!cursor) { - SDL_OutOfMemory(); - goto cleanup; - } - curdata = (KMSDRM_LEGACY_CursorData *) SDL_calloc(1, sizeof(*curdata)); - if (!curdata) { - SDL_OutOfMemory(); - goto cleanup; - } - - /* hox_x and hot_y are the coordinates of the "tip of the cursor" from it's base. */ - curdata->hot_x = hot_x; - curdata->hot_y = hot_y; - curdata->w = surface->w; - curdata->h = surface->h; - curdata->buffer = NULL; - - /* Configure the cursor buffer info. - This buffer has the original size of the cursor surface we are given. */ - curdata->buffer_pitch = surface->pitch; - curdata->buffer_size = surface->pitch * surface->h; - curdata->buffer = (uint32_t*)SDL_malloc(curdata->buffer_size); - - if (!curdata->buffer) { - SDL_OutOfMemory(); - goto cleanup; - } - - if (SDL_MUSTLOCK(surface)) { - if (SDL_LockSurface(surface) < 0) { - /* Could not lock surface */ - goto cleanup; - } - } - - /* Copy the surface pixels to the cursor buffer, for future use in ShowCursor() */ - SDL_memcpy(curdata->buffer, surface->pixels, curdata->buffer_size); - - if (SDL_MUSTLOCK(surface)) { - SDL_UnlockSurface(surface); - } - - cursor->driverdata = curdata; - - ret = cursor; - -cleanup: - if (ret == NULL) { - if (curdata) { - if (curdata->buffer) { - SDL_free(curdata->buffer); - } - SDL_free(curdata); - } - if (cursor) { - SDL_free(cursor); - } - } - - return ret; -} - -/* When we create a window, we have to test if we have to show the cursor, - and explicily do so if necessary. - This is because when we destroy a window, we take the cursor away from the - cursor plane, and destroy the cusror GBM BO. So we have to re-show it, - so to say. */ -void -KMSDRM_LEGACY_InitCursor() -{ - SDL_Mouse *mouse = NULL; - mouse = SDL_GetMouse(); - - if (!mouse) { - return; - } - if (!(mouse->cur_cursor)) { - return; - } - - if (!(mouse->cursor_shown)) { - return; - } - - KMSDRM_LEGACY_ShowCursor(mouse->cur_cursor); -} - -/* Show the specified cursor, or hide if cursor is NULL or has no focus. */ -static int -KMSDRM_LEGACY_ShowCursor(SDL_Cursor * cursor) -{ - SDL_VideoDevice *video_device = SDL_GetVideoDevice(); - SDL_VideoData *viddata = ((SDL_VideoData *)video_device->driverdata); - SDL_DisplayData *dispdata = (SDL_DisplayData *)SDL_GetDisplayDriverData(0); - SDL_Mouse *mouse; - KMSDRM_LEGACY_CursorData *curdata; - - uint32_t bo_handle; - - size_t bo_stride; - size_t bufsize; - uint32_t *ready_buffer = NULL; - uint32_t pixel; - - int i,j; - int ret; - - mouse = SDL_GetMouse(); - if (!mouse) { - return SDL_SetError("No mouse."); - } - - /*********************************************************/ - /* Hide cursor if it's NULL or it has no focus(=winwow). */ - /*********************************************************/ - if (!cursor || !mouse->focus) { - /* Hide the drm cursor with no more considerations because - SDL_VideoQuit() takes us here after disabling the mouse - so there is no mouse->cur_cursor by now. */ - ret = KMSDRM_LEGACY_drmModeSetCursor(viddata->drm_fd, - dispdata->crtc->crtc_id, 0, 0, 0); - if (ret) { - ret = SDL_SetError("Could not hide current cursor with drmModeSetCursor()."); - } - return ret; - } - - /************************************************/ - /* If cursor != NULL, DO show cursor on display */ - /************************************************/ - curdata = (KMSDRM_LEGACY_CursorData *) cursor->driverdata; - - if (!curdata || !dispdata->cursor_bo) { - return SDL_SetError("Cursor not initialized properly."); - } - - /* Prepare a buffer we can dump to our GBM BO (different - size, alpha premultiplication...) */ - bo_stride = KMSDRM_LEGACY_gbm_bo_get_stride(dispdata->cursor_bo); - bufsize = bo_stride * curdata->h; - - ready_buffer = (uint32_t*)SDL_malloc(bufsize); - if (!ready_buffer) { - ret = SDL_OutOfMemory(); - goto cleanup; - } - - /* Clean the whole buffer we are preparing. */ - SDL_memset(ready_buffer, 0x00, bo_stride * curdata->h); - - /* Copy from the cursor buffer to a buffer that we can dump to the GBM BO, - pre-multiplying by alpha each pixel as we go. */ - for (i = 0; i < curdata->h; i++) { - for (j = 0; j < curdata->w; j++) { - pixel = ((uint32_t*)curdata->buffer)[i * curdata->w + j]; - legacy_alpha_premultiply_ARGB8888 (&pixel); - SDL_memcpy(ready_buffer + (i * dispdata->cursor_w) + j, &pixel, 4); - } - } - - /* Dump the cursor buffer to our GBM BO. */ - if (KMSDRM_LEGACY_gbm_bo_write(dispdata->cursor_bo, ready_buffer, bufsize)) { - ret = SDL_SetError("Could not write to GBM cursor BO"); - goto cleanup; - } - - /* Put the GBM BO buffer on screen using the DRM interface. */ - bo_handle = KMSDRM_LEGACY_gbm_bo_get_handle(dispdata->cursor_bo).u32; - if (curdata->hot_x == 0 && curdata->hot_y == 0) { - ret = KMSDRM_LEGACY_drmModeSetCursor(viddata->drm_fd, dispdata->crtc->crtc_id, - bo_handle, dispdata->cursor_w, dispdata->cursor_h); - } else { - ret = KMSDRM_LEGACY_drmModeSetCursor2(viddata->drm_fd, dispdata->crtc->crtc_id, - bo_handle, dispdata->cursor_w, dispdata->cursor_h, curdata->hot_x, curdata->hot_y); - } - - if (ret) { - ret = SDL_SetError("Failed to set DRM cursor."); - goto cleanup; - } - -cleanup: - - if (ready_buffer) { - SDL_free(ready_buffer); - } - return ret; -} - -/* This is only for freeing the SDL_cursor.*/ -static void -KMSDRM_LEGACY_FreeCursor(SDL_Cursor * cursor) -{ - KMSDRM_LEGACY_CursorData *curdata; - - /* Even if the cursor is not ours, free it. */ - if (cursor) { - curdata = (KMSDRM_LEGACY_CursorData *) cursor->driverdata; - /* Free cursor buffer */ - if (curdata->buffer) { - SDL_free(curdata->buffer); - curdata->buffer = NULL; - } - /* Free cursor itself */ - if (cursor->driverdata) { - SDL_free(cursor->driverdata); - } - SDL_free(cursor); - } -} - -/* Warp the mouse to (x,y) */ -static void -KMSDRM_LEGACY_WarpMouse(SDL_Window * window, int x, int y) -{ - /* Only one global/fullscreen window is supported */ - KMSDRM_LEGACY_WarpMouseGlobal(x, y); -} - -/* Warp the mouse to (x,y) */ -static int -KMSDRM_LEGACY_WarpMouseGlobal(int x, int y) -{ - SDL_Mouse *mouse = SDL_GetMouse(); - SDL_DisplayData *dispdata = (SDL_DisplayData *)SDL_GetDisplayDriverData(0); - - if (mouse && mouse->cur_cursor && mouse->cur_cursor->driverdata) { - /* Update internal mouse position. */ - SDL_SendMouseMotion(mouse->focus, mouse->mouseID, 0, x, y); - - /* And now update the cursor graphic position on screen. */ - if (dispdata->cursor_bo) { - int ret, drm_fd; - drm_fd = KMSDRM_LEGACY_gbm_device_get_fd( - KMSDRM_LEGACY_gbm_bo_get_device(dispdata->cursor_bo)); - ret = KMSDRM_LEGACY_drmModeMoveCursor(drm_fd, dispdata->crtc->crtc_id, x, y); - - if (ret) { - SDL_SetError("drmModeMoveCursor() failed."); - } - - return ret; - - } else { - return SDL_SetError("Cursor not initialized properly."); - } - } else { - return SDL_SetError("No mouse or current cursor."); - } - - return 0; -} - -/* UNDO WHAT WE DID IN KMSDRM_InitMouse(). */ -void -KMSDRM_LEGACY_DeinitMouse(_THIS) -{ - SDL_VideoDevice *video_device = SDL_GetVideoDevice(); - SDL_DisplayData *dispdata = (SDL_DisplayData *)SDL_GetDisplayDriverData(0); - - /* Destroy the curso GBM BO. */ - if (video_device && dispdata->cursor_bo) { - KMSDRM_LEGACY_gbm_bo_destroy(dispdata->cursor_bo); - dispdata->cursor_bo = NULL; - } -} - -/* Create cursor BO. */ -void -KMSDRM_LEGACY_InitMouse(_THIS) -{ - SDL_VideoDevice *dev = SDL_GetVideoDevice(); - SDL_VideoData *viddata = ((SDL_VideoData *)dev->driverdata); - SDL_DisplayData *dispdata = (SDL_DisplayData *)SDL_GetDisplayDriverData(0); - SDL_Mouse *mouse = SDL_GetMouse(); - - mouse->CreateCursor = KMSDRM_LEGACY_CreateCursor; - mouse->ShowCursor = KMSDRM_LEGACY_ShowCursor; - mouse->MoveCursor = KMSDRM_LEGACY_MoveCursor; - mouse->FreeCursor = KMSDRM_LEGACY_FreeCursor; - mouse->WarpMouse = KMSDRM_LEGACY_WarpMouse; - mouse->WarpMouseGlobal = KMSDRM_LEGACY_WarpMouseGlobal; - - /************************************************/ - /* Create the cursor GBM BO, if we haven't yet. */ - /************************************************/ - if (!dispdata->cursor_bo) { - - if (!KMSDRM_LEGACY_gbm_device_is_format_supported(viddata->gbm_dev, - GBM_FORMAT_ARGB8888, - GBM_BO_USE_CURSOR | GBM_BO_USE_WRITE)) - { - SDL_SetError("Unsupported pixel format for cursor"); - return; - } - - if (KMSDRM_LEGACY_drmGetCap(viddata->drm_fd, - DRM_CAP_CURSOR_WIDTH, &dispdata->cursor_w) || - KMSDRM_LEGACY_drmGetCap(viddata->drm_fd, DRM_CAP_CURSOR_HEIGHT, - &dispdata->cursor_h)) - { - SDL_SetError("Could not get the recommended GBM cursor size"); - goto cleanup; - } - - if (dispdata->cursor_w == 0 || dispdata->cursor_h == 0) { - SDL_SetError("Could not get an usable GBM cursor size"); - goto cleanup; - } - - dispdata->cursor_bo = KMSDRM_LEGACY_gbm_bo_create(viddata->gbm_dev, - dispdata->cursor_w, dispdata->cursor_h, - GBM_FORMAT_ARGB8888, GBM_BO_USE_CURSOR | GBM_BO_USE_WRITE | GBM_BO_USE_LINEAR); - - if (!dispdata->cursor_bo) { - SDL_SetError("Could not create GBM cursor BO"); - goto cleanup; - } - } - - /* SDL expects to set the default cursor on screen when we init the mouse, - but since we have moved the KMSDRM_InitMouse() call to KMSDRM_CreateWindow(), - we end up calling KMSDRM_InitMouse() every time we create a window, so we - have to prevent this from being done every time a new window is created. - If we don't, new default cursors would stack up on mouse->cursors and SDL - would have to hide and delete them at quit, not to mention the memory leak... */ - if(dispdata->set_default_cursor_pending) { - SDL_SetDefaultCursor(KMSDRM_LEGACY_CreateDefaultCursor()); - dispdata->set_default_cursor_pending = SDL_FALSE; - } - - return; - -cleanup: - if (dispdata->cursor_bo) { - KMSDRM_LEGACY_gbm_bo_destroy(dispdata->cursor_bo); - dispdata->cursor_bo = NULL; - } -} - -void -KMSDRM_LEGACY_QuitMouse(_THIS) -{ - /* TODO: ? */ -} - -/* This is called when a mouse motion event occurs */ -static void -KMSDRM_LEGACY_MoveCursor(SDL_Cursor * cursor) -{ - SDL_Mouse *mouse = SDL_GetMouse(); - SDL_DisplayData *dispdata = (SDL_DisplayData *)SDL_GetDisplayDriverData(0); - int drm_fd, ret; - - /* We must NOT call SDL_SendMouseMotion() here or we will enter recursivity! - That's why we move the cursor graphic ONLY. */ - if (mouse && mouse->cur_cursor && mouse->cur_cursor->driverdata) { - drm_fd = KMSDRM_LEGACY_gbm_device_get_fd(KMSDRM_LEGACY_gbm_bo_get_device(dispdata->cursor_bo)); - ret = KMSDRM_LEGACY_drmModeMoveCursor(drm_fd, dispdata->crtc->crtc_id, mouse->x, mouse->y); - - if (ret) { - SDL_SetError("drmModeMoveCursor() failed."); - } - } -} - -#endif /* SDL_VIDEO_DRIVER_KMSDRM */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_mouse.h b/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_mouse.h deleted file mode 100644 index e2bc96871..000000000 --- a/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_mouse.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2021 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -#include "../../SDL_internal.h" - -#ifndef SDL_KMSDRM_LEGACY_mouse_h_ -#define SDL_KMSDRM_LEGACY_mouse_h_ - -#include - -#define MAX_CURSOR_W 512 -#define MAX_CURSOR_H 512 - -typedef struct _KMSDRM_LEGACY_CursorData -{ - int hot_x, hot_y; - int w, h; - - /* The buffer where we store the mouse bitmap ready to be used. - We get it ready and filled in CreateCursor(), and copy it - to a GBM BO in ShowCursor().*/ - uint32_t *buffer; - size_t buffer_size; - size_t buffer_pitch; - -} KMSDRM_LEGACY_CursorData; - -extern void KMSDRM_LEGACY_InitMouse(_THIS); -extern void KMSDRM_LEGACY_DeinitMouse(_THIS); -extern void KMSDRM_LEGACY_QuitMouse(_THIS); - -extern void KMSDRM_LEGACY_InitCursor(); - -#endif /* SDL_KMSDRM_LEGACY_mouse_h_ */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_opengles.c b/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_opengles.c deleted file mode 100644 index c4acd755e..000000000 --- a/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_opengles.c +++ /dev/null @@ -1,166 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2021 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -#include "../../SDL_internal.h" - -#if SDL_VIDEO_DRIVER_KMSDRM - -#include "SDL_log.h" - -#include "SDL_kmsdrm_legacy_video.h" -#include "SDL_kmsdrm_legacy_opengles.h" -#include "SDL_kmsdrm_legacy_dyn.h" - -#ifndef EGL_PLATFORM_GBM_MESA -#define EGL_PLATFORM_GBM_MESA 0x31D7 -#endif - -/* EGL implementation of SDL OpenGL support */ - -void -KMSDRM_LEGACY_GLES_DefaultProfileConfig(_THIS, int *mask, int *major, int *minor) -{ - /* if SDL was _also_ built with the Raspberry Pi driver (so we're - definitely a Pi device), default to GLES2. */ -#if SDL_VIDEO_DRIVER_RPI - *mask = SDL_GL_CONTEXT_PROFILE_ES; - *major = 2; - *minor = 0; -#endif -} - -int -KMSDRM_LEGACY_GLES_LoadLibrary(_THIS, const char *path) { - /* Just pretend you do this here, but don't do it until KMSDRM_CreateWindow(), - where we do the same library load we would normally do here. - because this gets called by SDL_CreateWindow() before KMSDR_CreateWindow(), - so gbm dev isn't yet created when this is called, AND we can't alter the - call order in SDL_CreateWindow(). */ -#if 0 - NativeDisplayType display = (NativeDisplayType)((SDL_VideoData *)_this->driverdata)->gbm_dev; - return SDL_EGL_LoadLibrary(_this, path, display, EGL_PLATFORM_GBM_MESA); -#endif - return 0; -} - -void -KMSDRM_LEGACY_GLES_UnloadLibrary(_THIS) { - /* As with KMSDRM_GLES_LoadLibrary(), we define our own "dummy" unloading function - so we manually unload the library whenever we want. */ -} - -SDL_EGL_CreateContext_impl(KMSDRM_LEGACY) - -int KMSDRM_LEGACY_GLES_SetSwapInterval(_THIS, int interval) { - if (!_this->egl_data) { - return SDL_SetError("EGL not initialized"); - } - - if (interval == 0 || interval == 1) { - _this->egl_data->egl_swapinterval = interval; - } else { - return SDL_SetError("Only swap intervals of 0 or 1 are supported"); - } - - return 0; -} - -int -KMSDRM_LEGACY_GLES_SwapWindow(_THIS, SDL_Window * window) { - SDL_WindowData *windata = ((SDL_WindowData *) window->driverdata); - SDL_DisplayData *dispdata = (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata; - SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata); - KMSDRM_LEGACY_FBInfo *fb_info; - int ret, timeout; - - /* Recreate the GBM / EGL surfaces if the display mode has changed */ - if (windata->egl_surface_dirty) { - KMSDRM_LEGACY_CreateSurfaces(_this, window); - } - - /* Wait for confirmation that the next front buffer has been flipped, at which - point the previous front buffer can be released */ - timeout = 0; - if (_this->egl_data->egl_swapinterval == 1) { - timeout = -1; - } - if (!KMSDRM_LEGACY_WaitPageFlip(_this, windata, timeout)) { - return 0; - } - - /* Release the previous front buffer */ - if (windata->bo) { - KMSDRM_LEGACY_gbm_surface_release_buffer(windata->gs, windata->bo); - windata->bo = NULL; - } - - windata->bo = windata->next_bo; - - /* Mark a buffer to becume the next front buffer. - This won't happen until pagelip completes. */ - if (!(_this->egl_data->eglSwapBuffers(_this->egl_data->egl_display, - windata->egl_surface))) { - SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "eglSwapBuffers failed."); - return 0; - } - - /* Lock the next front buffer so it can't be allocated as a back buffer */ - windata->next_bo = KMSDRM_LEGACY_gbm_surface_lock_front_buffer(windata->gs); - if (!windata->next_bo) { - SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not lock GBM surface front buffer"); - return 0; - } - - /* Get the fb_info for the next front buffer. */ - fb_info = KMSDRM_LEGACY_FBFromBO(_this, windata->next_bo); - if (!fb_info) { - return 0; - } - - /* Issue pageflip on the next front buffer. - The pageflip will be done during the next vblank. */ - ret = KMSDRM_LEGACY_drmModePageFlip(viddata->drm_fd, dispdata->crtc->crtc_id, - fb_info->fb_id, DRM_MODE_PAGE_FLIP_EVENT, &windata->waiting_for_flip); - - if (_this->egl_data->egl_swapinterval == 1) { - if (ret == 0) { - windata->waiting_for_flip = SDL_TRUE; - } else { - SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not queue pageflip: %d", ret); - } - } - - /* If we are in double-buffer mode, wait immediately for vsync - (as if we only had two buffers), - Run your SDL2 program with "SDL_KMSDRM_LEGACY_DOUBLE_BUFFER=1 " - to enable this. */ - if (_this->egl_data->egl_swapinterval == 1 && windata->double_buffer) { - KMSDRM_LEGACY_WaitPageFlip(_this, windata, -1); - } - - return 0; -} - -SDL_EGL_MakeCurrent_impl(KMSDRM_LEGACY) - -#endif /* SDL_VIDEO_DRIVER_KMSDRM */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_opengles.h b/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_opengles.h deleted file mode 100644 index e1314b7e1..000000000 --- a/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_opengles.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2021 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "../../SDL_internal.h" - -#ifndef SDL_kmsdrmopengles_h_ -#define SDL_kmsdrmopengles_h_ - -#if SDL_VIDEO_DRIVER_KMSDRM - -#include "../SDL_sysvideo.h" -#include "../SDL_egl_c.h" - -/* OpenGLES functions */ -#define KMSDRM_LEGACY_GLES_GetAttribute SDL_EGL_GetAttribute -#define KMSDRM_LEGACY_GLES_GetProcAddress SDL_EGL_GetProcAddress -#define KMSDRM_LEGACY_GLES_DeleteContext SDL_EGL_DeleteContext -#define KMSDRM_LEGACY_GLES_GetSwapInterval SDL_EGL_GetSwapInterval - -extern void KMSDRM_LEGACY_GLES_DefaultProfileConfig(_THIS, int *mask, int *major, int *minor); -extern int KMSDRM_LEGACY_GLES_SetSwapInterval(_THIS, int interval); -extern int KMSDRM_LEGACY_GLES_LoadLibrary(_THIS, const char *path); -extern SDL_GLContext KMSDRM_LEGACY_GLES_CreateContext(_THIS, SDL_Window * window); -extern int KMSDRM_LEGACY_GLES_SwapWindow(_THIS, SDL_Window * window); -extern int KMSDRM_LEGACY_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context); - -#endif /* SDL_VIDEO_DRIVER_KMSDRM */ - -#endif /* SDL_kmsdrmopengles_h_ */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_sym.h b/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_sym.h deleted file mode 100644 index 487dc1969..000000000 --- a/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_sym.h +++ /dev/null @@ -1,118 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2021 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -/* *INDENT-OFF* */ - -#ifndef SDL_KMSDRM_LEGACY_MODULE -#define SDL_KMSDRM_LEGACY_MODULE(modname) -#endif - -#ifndef SDL_KMSDRM_LEGACY_SYM -#define SDL_KMSDRM_LEGACY_SYM(rc,fn,params) -#endif - -#ifndef SDL_KMSDRM_LEGACY_SYM_CONST -#define SDL_KMSDRM_LEGACY_SYM_CONST(type, name) -#endif - - -SDL_KMSDRM_LEGACY_MODULE(LIBDRM) -SDL_KMSDRM_LEGACY_SYM(void,drmModeFreeResources,(drmModeResPtr ptr)) -SDL_KMSDRM_LEGACY_SYM(void,drmModeFreeFB,(drmModeFBPtr ptr)) -SDL_KMSDRM_LEGACY_SYM(void,drmModeFreeCrtc,(drmModeCrtcPtr ptr)) -SDL_KMSDRM_LEGACY_SYM(void,drmModeFreeConnector,(drmModeConnectorPtr ptr)) -SDL_KMSDRM_LEGACY_SYM(void,drmModeFreeEncoder,(drmModeEncoderPtr ptr)) -SDL_KMSDRM_LEGACY_SYM(int,drmGetCap,(int fd, uint64_t capability, uint64_t *value)) -SDL_KMSDRM_LEGACY_SYM(drmModeResPtr,drmModeGetResources,(int fd)) -SDL_KMSDRM_LEGACY_SYM(int,drmModeAddFB,(int fd, uint32_t width, uint32_t height, uint8_t depth, - uint8_t bpp, uint32_t pitch, uint32_t bo_handle, - uint32_t *buf_id)) -SDL_KMSDRM_LEGACY_SYM(int,drmModeRmFB,(int fd, uint32_t bufferId)) -SDL_KMSDRM_LEGACY_SYM(drmModeFBPtr,drmModeGetFB,(int fd, uint32_t buf)) -SDL_KMSDRM_LEGACY_SYM(drmModeCrtcPtr,drmModeGetCrtc,(int fd, uint32_t crtcId)) -SDL_KMSDRM_LEGACY_SYM(int,drmModeSetCrtc,(int fd, uint32_t crtcId, uint32_t bufferId, - uint32_t x, uint32_t y, uint32_t *connectors, int count, - drmModeModeInfoPtr mode)) -SDL_KMSDRM_LEGACY_SYM(int,drmModeSetCursor,(int fd, uint32_t crtcId, uint32_t bo_handle, - uint32_t width, uint32_t height)) -SDL_KMSDRM_LEGACY_SYM(int,drmModeSetCursor2,(int fd, uint32_t crtcId, uint32_t bo_handle, - uint32_t width, uint32_t height, - int32_t hot_x, int32_t hot_y)) -SDL_KMSDRM_LEGACY_SYM(int,drmModeMoveCursor,(int fd, uint32_t crtcId, int x, int y)) -SDL_KMSDRM_LEGACY_SYM(drmModeEncoderPtr,drmModeGetEncoder,(int fd, uint32_t encoder_id)) -SDL_KMSDRM_LEGACY_SYM(drmModeConnectorPtr,drmModeGetConnector,(int fd, uint32_t connector_id)) -SDL_KMSDRM_LEGACY_SYM(int,drmHandleEvent,(int fd,drmEventContextPtr evctx)) -SDL_KMSDRM_LEGACY_SYM(int,drmModePageFlip,(int fd, uint32_t crtc_id, uint32_t fb_id, - uint32_t flags, void *user_data)) - -/* Planes stuff. */ -SDL_KMSDRM_LEGACY_SYM(int,drmSetClientCap,(int fd, uint64_t capability, uint64_t value)) -SDL_KMSDRM_LEGACY_SYM(drmModePlaneResPtr,drmModeGetPlaneResources,(int fd)) -SDL_KMSDRM_LEGACY_SYM(drmModePlanePtr,drmModeGetPlane,(int fd, uint32_t plane_id)) -SDL_KMSDRM_LEGACY_SYM(drmModeObjectPropertiesPtr,drmModeObjectGetProperties,(int fd,uint32_t object_id,uint32_t object_type)) -SDL_KMSDRM_LEGACY_SYM(drmModePropertyPtr,drmModeGetProperty,(int fd, uint32_t propertyId)) - -SDL_KMSDRM_LEGACY_SYM(void,drmModeFreeProperty,(drmModePropertyPtr ptr)) -SDL_KMSDRM_LEGACY_SYM(void,drmModeFreeObjectProperties,(drmModeObjectPropertiesPtr ptr)) -SDL_KMSDRM_LEGACY_SYM(void,drmModeFreePlane,(drmModePlanePtr ptr)) -SDL_KMSDRM_LEGACY_SYM(void,drmModeFreePlaneResources,(drmModePlaneResPtr ptr)) -SDL_KMSDRM_LEGACY_SYM(int,drmModeSetPlane,(int fd, uint32_t plane_id, uint32_t crtc_id, - uint32_t fb_id, uint32_t flags, - int32_t crtc_x, int32_t crtc_y, - uint32_t crtc_w, uint32_t crtc_h, - uint32_t src_x, uint32_t src_y, - uint32_t src_w, uint32_t src_h)) -/* Planes stuff ends. */ - -SDL_KMSDRM_LEGACY_MODULE(GBM) -SDL_KMSDRM_LEGACY_SYM(int,gbm_device_get_fd,(struct gbm_device *gbm)) -SDL_KMSDRM_LEGACY_SYM(int,gbm_device_is_format_supported,(struct gbm_device *gbm, - uint32_t format, uint32_t usage)) -SDL_KMSDRM_LEGACY_SYM(void,gbm_device_destroy,(struct gbm_device *gbm)) -SDL_KMSDRM_LEGACY_SYM(struct gbm_device *,gbm_create_device,(int fd)) -SDL_KMSDRM_LEGACY_SYM(unsigned int,gbm_bo_get_width,(struct gbm_bo *bo)) -SDL_KMSDRM_LEGACY_SYM(unsigned int,gbm_bo_get_height,(struct gbm_bo *bo)) -SDL_KMSDRM_LEGACY_SYM(uint32_t,gbm_bo_get_stride,(struct gbm_bo *bo)) -SDL_KMSDRM_LEGACY_SYM(union gbm_bo_handle,gbm_bo_get_handle,(struct gbm_bo *bo)) -SDL_KMSDRM_LEGACY_SYM(int,gbm_bo_write,(struct gbm_bo *bo, const void *buf, size_t count)) -SDL_KMSDRM_LEGACY_SYM(struct gbm_device *,gbm_bo_get_device,(struct gbm_bo *bo)) -SDL_KMSDRM_LEGACY_SYM(void,gbm_bo_set_user_data,(struct gbm_bo *bo, void *data, - void (*destroy_user_data)(struct gbm_bo *, void *))) -SDL_KMSDRM_LEGACY_SYM(void *,gbm_bo_get_user_data,(struct gbm_bo *bo)) -SDL_KMSDRM_LEGACY_SYM(void,gbm_bo_destroy,(struct gbm_bo *bo)) -SDL_KMSDRM_LEGACY_SYM(struct gbm_bo *,gbm_bo_create,(struct gbm_device *gbm, - uint32_t width, uint32_t height, - uint32_t format, uint32_t usage)) -SDL_KMSDRM_LEGACY_SYM(struct gbm_surface *,gbm_surface_create,(struct gbm_device *gbm, - uint32_t width, uint32_t height, - uint32_t format, uint32_t flags)) -SDL_KMSDRM_LEGACY_SYM(void,gbm_surface_destroy,(struct gbm_surface *surf)) -SDL_KMSDRM_LEGACY_SYM(struct gbm_bo *,gbm_surface_lock_front_buffer,(struct gbm_surface *surf)) -SDL_KMSDRM_LEGACY_SYM(void,gbm_surface_release_buffer,(struct gbm_surface *surf, struct gbm_bo *bo)) - - -#undef SDL_KMSDRM_LEGACY_MODULE -#undef SDL_KMSDRM_LEGACY_SYM -#undef SDL_KMSDRM_LEGACY_SYM_CONST - -/* *INDENT-ON* */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_video.c b/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_video.c deleted file mode 100644 index 17be847ad..000000000 --- a/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_video.c +++ /dev/null @@ -1,1280 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2021 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -#include "../../SDL_internal.h" - -#if SDL_VIDEO_DRIVER_KMSDRM - -/* SDL internals */ -#include "../SDL_sysvideo.h" -#include "SDL_syswm.h" -#include "SDL_log.h" -#include "SDL_hints.h" -#include "../../events/SDL_events_c.h" -#include "../../events/SDL_mouse_c.h" -#include "../../events/SDL_keyboard_c.h" - -#ifdef SDL_INPUT_LINUXEV -#include "../../core/linux/SDL_evdev.h" -#endif - -/* KMS/DRM declarations */ -#include "SDL_kmsdrm_legacy_video.h" -#include "SDL_kmsdrm_legacy_events.h" -#include "SDL_kmsdrm_legacy_opengles.h" -#include "SDL_kmsdrm_legacy_mouse.h" -#include "SDL_kmsdrm_legacy_dyn.h" -#include "SDL_kmsdrm_legacy_vulkan.h" -#include -#include -#include -#include - -#ifdef __OpenBSD__ -#define KMSDRM_LEGACY_DRI_PATH "/dev/" -#define KMSDRM_LEGACY_DRI_DEVFMT "%sdrm%d" -#define KMSDRM_LEGACY_DRI_DEVNAME "drm" -#define KMSDRM_LEGACY_DRI_DEVNAMESIZE 3 -#define KMSDRM_LEGACY_DRI_CARDPATHFMT "/dev/drm%d" -#else -#define KMSDRM_LEGACY_DRI_PATH "/dev/dri/" -#define KMSDRM_LEGACY_DRI_DEVFMT "%scard%d" -#define KMSDRM_LEGACY_DRI_DEVNAME "card" -#define KMSDRM_LEGACY_DRI_DEVNAMESIZE 4 -#define KMSDRM_LEGACY_DRI_CARDPATHFMT "/dev/dri/card%d" -#endif - -static int -check_modestting(int devindex) -{ - SDL_bool available = SDL_FALSE; - char device[512]; - int drm_fd; - - SDL_snprintf(device, sizeof (device), KMSDRM_LEGACY_DRI_DEVFMT, KMSDRM_LEGACY_DRI_PATH, devindex); - - drm_fd = open(device, O_RDWR | O_CLOEXEC); - if (drm_fd >= 0) { - if (SDL_KMSDRM_LEGACY_LoadSymbols()) { - drmModeRes *resources = KMSDRM_LEGACY_drmModeGetResources(drm_fd); - if (resources) { - SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, - KMSDRM_LEGACY_DRI_DEVFMT - " connector, encoder and CRTC counts are: %d %d %d", - KMSDRM_LEGACY_DRI_PATH, devindex, - resources->count_connectors, resources->count_encoders, - resources->count_crtcs); - - if (resources->count_connectors > 0 - && resources->count_encoders > 0 - && resources->count_crtcs > 0) - { - available = SDL_TRUE; - } - KMSDRM_LEGACY_drmModeFreeResources(resources); - } - SDL_KMSDRM_LEGACY_UnloadSymbols(); - } - close(drm_fd); - } - - return available; -} - -static int get_dricount(void) -{ - int devcount = 0; - struct dirent *res; - struct stat sb; - DIR *folder; - - if (!(stat(KMSDRM_LEGACY_DRI_PATH, &sb) == 0 - && S_ISDIR(sb.st_mode))) { - printf("The path %s cannot be opened or is not available\n", - KMSDRM_LEGACY_DRI_PATH); - return 0; - } - - if (access(KMSDRM_LEGACY_DRI_PATH, F_OK) == -1) { - printf("The path %s cannot be opened\n", - KMSDRM_LEGACY_DRI_PATH); - return 0; - } - - folder = opendir(KMSDRM_LEGACY_DRI_PATH); - if (folder) { - while ((res = readdir(folder))) { - int len = SDL_strlen(res->d_name); - if (len > KMSDRM_LEGACY_DRI_DEVNAMESIZE && SDL_strncmp(res->d_name, - KMSDRM_LEGACY_DRI_DEVNAME, KMSDRM_LEGACY_DRI_DEVNAMESIZE) == 0) { - devcount++; - } - } - closedir(folder); - } - - return devcount; -} - -static int -get_driindex(void) -{ - const int devcount = get_dricount(); - int i; - - for (i = 0; i < devcount; i++) { - if (check_modestting(i)) { - return i; - } - } - - return -ENOENT; -} - -static int -KMSDRM_LEGACY_Available(void) -{ - int ret = -ENOENT; - - ret = get_driindex(); - if (ret >= 0) - return 1; - - return ret; -} - -static void -KMSDRM_LEGACY_DeleteDevice(SDL_VideoDevice * device) -{ - if (device->driverdata) { - SDL_free(device->driverdata); - device->driverdata = NULL; - } - - SDL_free(device); - - SDL_KMSDRM_LEGACY_UnloadSymbols(); -} - -static SDL_VideoDevice * -KMSDRM_LEGACY_CreateDevice(int devindex) -{ - SDL_VideoDevice *device; - SDL_VideoData *viddata; - - if (!KMSDRM_LEGACY_Available()) { - return NULL; - } - - if (!devindex || (devindex > 99)) { - devindex = get_driindex(); - } - - if (devindex < 0) { - SDL_SetError("devindex (%d) must be between 0 and 99.\n", devindex); - return NULL; - } - - if (!SDL_KMSDRM_LEGACY_LoadSymbols()) { - return NULL; - } - - device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice)); - if (!device) { - SDL_OutOfMemory(); - return NULL; - } - - viddata = (SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData)); - if (!viddata) { - SDL_OutOfMemory(); - goto cleanup; - } - viddata->devindex = devindex; - viddata->drm_fd = -1; - - device->driverdata = viddata; - - /* Setup all functions which we can handle */ - device->VideoInit = KMSDRM_LEGACY_VideoInit; - device->VideoQuit = KMSDRM_LEGACY_VideoQuit; - device->GetDisplayModes = KMSDRM_LEGACY_GetDisplayModes; - device->SetDisplayMode = KMSDRM_LEGACY_SetDisplayMode; - device->CreateSDLWindow = KMSDRM_LEGACY_CreateWindow; - device->CreateSDLWindowFrom = KMSDRM_LEGACY_CreateWindowFrom; - device->SetWindowTitle = KMSDRM_LEGACY_SetWindowTitle; - device->SetWindowIcon = KMSDRM_LEGACY_SetWindowIcon; - device->SetWindowPosition = KMSDRM_LEGACY_SetWindowPosition; - device->SetWindowSize = KMSDRM_LEGACY_SetWindowSize; - device->SetWindowFullscreen = KMSDRM_LEGACY_SetWindowFullscreen; - device->ShowWindow = KMSDRM_LEGACY_ShowWindow; - device->HideWindow = KMSDRM_LEGACY_HideWindow; - device->RaiseWindow = KMSDRM_LEGACY_RaiseWindow; - device->MaximizeWindow = KMSDRM_LEGACY_MaximizeWindow; - device->MinimizeWindow = KMSDRM_LEGACY_MinimizeWindow; - device->RestoreWindow = KMSDRM_LEGACY_RestoreWindow; - device->SetWindowGrab = KMSDRM_LEGACY_SetWindowGrab; - device->DestroyWindow = KMSDRM_LEGACY_DestroyWindow; - device->GetWindowWMInfo = KMSDRM_LEGACY_GetWindowWMInfo; - - device->GL_LoadLibrary = KMSDRM_LEGACY_GLES_LoadLibrary; - device->GL_GetProcAddress = KMSDRM_LEGACY_GLES_GetProcAddress; - device->GL_UnloadLibrary = KMSDRM_LEGACY_GLES_UnloadLibrary; - device->GL_CreateContext = KMSDRM_LEGACY_GLES_CreateContext; - device->GL_MakeCurrent = KMSDRM_LEGACY_GLES_MakeCurrent; - device->GL_SetSwapInterval = KMSDRM_LEGACY_GLES_SetSwapInterval; - device->GL_GetSwapInterval = KMSDRM_LEGACY_GLES_GetSwapInterval; - device->GL_SwapWindow = KMSDRM_LEGACY_GLES_SwapWindow; - device->GL_DeleteContext = KMSDRM_LEGACY_GLES_DeleteContext; - -#if SDL_VIDEO_VULKAN - device->Vulkan_LoadLibrary = KMSDRM_LEGACY_Vulkan_LoadLibrary; - device->Vulkan_UnloadLibrary = KMSDRM_LEGACY_Vulkan_UnloadLibrary; - device->Vulkan_GetInstanceExtensions = KMSDRM_LEGACY_Vulkan_GetInstanceExtensions; - device->Vulkan_CreateSurface = KMSDRM_LEGACY_Vulkan_CreateSurface; - device->Vulkan_GetDrawableSize = KMSDRM_LEGACY_Vulkan_GetDrawableSize; -#endif - - device->PumpEvents = KMSDRM_LEGACY_PumpEvents; - device->free = KMSDRM_LEGACY_DeleteDevice; - - return device; - -cleanup: - if (device) - SDL_free(device); - if (viddata) - SDL_free(viddata); - return NULL; -} - -VideoBootStrap KMSDRM_LEGACY_bootstrap = { - "KMSDRM_LEGACY", - "KMS/DRM Video Driver", - KMSDRM_LEGACY_CreateDevice -}; - -static void -KMSDRM_LEGACY_FBDestroyCallback(struct gbm_bo *bo, void *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); - SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "Delete DRM FB %u", fb_info->fb_id); - } - - SDL_free(fb_info); -} - -KMSDRM_LEGACY_FBInfo * -KMSDRM_LEGACY_FBFromBO(_THIS, struct gbm_bo *bo) -{ - SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata); - unsigned w,h; - int ret; - Uint32 stride, handle; - - /* Check for an existing framebuffer */ - KMSDRM_LEGACY_FBInfo *fb_info = (KMSDRM_LEGACY_FBInfo *)KMSDRM_LEGACY_gbm_bo_get_user_data(bo); - - if (fb_info) { - return fb_info; - } - - /* 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_LEGACY_FBInfo)); - - if (!fb_info) { - SDL_OutOfMemory(); - return NULL; - } - - fb_info->drm_fd = viddata->drm_fd; - - /* Create framebuffer object for the buffer */ - w = KMSDRM_LEGACY_gbm_bo_get_width(bo); - h = KMSDRM_LEGACY_gbm_bo_get_height(bo); - stride = KMSDRM_LEGACY_gbm_bo_get_stride(bo); - handle = KMSDRM_LEGACY_gbm_bo_get_handle(bo).u32; - ret = KMSDRM_LEGACY_drmModeAddFB(viddata->drm_fd, w, h, 24, 32, stride, handle, - &fb_info->fb_id); - if (ret) { - SDL_free(fb_info); - return NULL; - } - - SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "New DRM FB (%u): %ux%u, stride %u from BO %p", - 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_LEGACY_FBDestroyCallback); - - return fb_info; -} - -static void -KMSDRM_LEGACY_FlipHandler(int fd, unsigned int frame, unsigned int sec, unsigned int usec, void *data) -{ - *((SDL_bool *) data) = SDL_FALSE; -} - -SDL_bool -KMSDRM_LEGACY_WaitPageFlip(_THIS, SDL_WindowData *windata, int timeout) { - SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata); - drmEventContext ev = {0}; - struct pollfd pfd = {0}; - - ev.version = DRM_EVENT_CONTEXT_VERSION; - ev.page_flip_handler = KMSDRM_LEGACY_FlipHandler; - - pfd.fd = viddata->drm_fd; - pfd.events = POLLIN; - - while (windata->waiting_for_flip) { - pfd.revents = 0; - - if (poll(&pfd, 1, timeout) < 0) { - SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "DRM poll error"); - return SDL_FALSE; - } - - if (pfd.revents & (POLLHUP | POLLERR)) { - SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "DRM poll hup or error"); - return SDL_FALSE; - } - - if (pfd.revents & POLLIN) { - /* Page flip? If so, drmHandleEvent will unset windata->waiting_for_flip */ - KMSDRM_LEGACY_drmHandleEvent(viddata->drm_fd, &ev); - } else { - /* Timed out and page flip didn't happen */ - SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "Dropping frame while waiting_for_flip"); - return SDL_FALSE; - } - } - - return SDL_TRUE; -} - -/*****************************************************************************/ -/* SDL Video and Display initialization/handling functions */ -/* _this is a SDL_VideoDevice * */ -/*****************************************************************************/ - -/* Deinitializes the dispdata members needed for KMSDRM operation that are - inoffeensive for VK compatibility. */ -void KMSDRM_LEGACY_DisplayDataDeinit (_THIS, SDL_DisplayData *dispdata) { - /* Free connector */ - if (dispdata && dispdata->connector) { - KMSDRM_LEGACY_drmModeFreeConnector(dispdata->connector); - dispdata->connector = NULL; - } - - /* Free CRTC */ - if (dispdata && dispdata->crtc) { - KMSDRM_LEGACY_drmModeFreeCrtc(dispdata->crtc); - dispdata->crtc = NULL; - } -} - -/* Initializes the dispdata members needed for KMSDRM operation that are - inoffeensive for VK compatibility, except we must leave the drm_fd - closed when we get to the end of this function. - This is to be called early, in VideoInit(), because it gets us - the videomode information, which SDL needs immediately after VideoInit(). */ -int KMSDRM_LEGACY_DisplayDataInit (_THIS, SDL_DisplayData *dispdata) { - SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata); - - drmModeRes *resources = NULL; - drmModeEncoder *encoder = NULL; - drmModeConnector *connector = NULL; - drmModeCrtc *crtc = NULL; - - int ret = 0; - unsigned i,j; - - dispdata->modeset_pending = SDL_FALSE; - dispdata->gbm_init = SDL_FALSE; - - dispdata->cursor_bo = NULL; - - /* Open /dev/dri/cardNN (/dev/drmN if on OpenBSD) */ - SDL_snprintf(viddata->devpath, sizeof(viddata->devpath), KMSDRM_LEGACY_DRI_CARDPATHFMT, viddata->devindex); - - SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "Opening device %s", viddata->devpath); - viddata->drm_fd = open(viddata->devpath, O_RDWR | O_CLOEXEC); - - if (viddata->drm_fd < 0) { - ret = SDL_SetError("Could not open %s", viddata->devpath); - goto cleanup; - } - - SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "Opened DRM FD (%d)", viddata->drm_fd); - - /* Activate universal planes. */ - KMSDRM_LEGACY_drmSetClientCap(viddata->drm_fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1); - - /* Get all of the available connectors / devices / crtcs */ - resources = KMSDRM_LEGACY_drmModeGetResources(viddata->drm_fd); - if (!resources) { - ret = SDL_SetError("drmModeGetResources(%d) failed", viddata->drm_fd); - goto cleanup; - } - - /* Iterate on the available connectors to find a connected connector. */ - for (i = 0; i < resources->count_connectors; i++) { - drmModeConnector *conn = KMSDRM_LEGACY_drmModeGetConnector(viddata->drm_fd, - resources->connectors[i]); - - if (!conn) { - continue; - } - - if (conn->connection == DRM_MODE_CONNECTED && conn->count_modes) { - connector = conn; - break; - } - - KMSDRM_LEGACY_drmModeFreeConnector(conn); - } - - if (!connector) { - ret = SDL_SetError("No currently active connector found."); - goto cleanup; - } - - /* Try to find the connector's current encoder */ - for (i = 0; i < resources->count_encoders; i++) { - encoder = KMSDRM_LEGACY_drmModeGetEncoder(viddata->drm_fd, resources->encoders[i]); - - if (!encoder) { - continue; - } - - if (encoder->encoder_id == connector->encoder_id) { - break; - } - - KMSDRM_LEGACY_drmModeFreeEncoder(encoder); - encoder = NULL; - } - - if (!encoder) { - /* No encoder was connected, find the first supported one */ - for (i = 0; i < resources->count_encoders; i++) { - encoder = KMSDRM_LEGACY_drmModeGetEncoder(viddata->drm_fd, - resources->encoders[i]); - - if (!encoder) { - continue; - } - - for (j = 0; j < connector->count_encoders; j++) { - if (connector->encoders[j] == encoder->encoder_id) { - break; - } - } - - if (j != connector->count_encoders) { - break; - } - - KMSDRM_LEGACY_drmModeFreeEncoder(encoder); - encoder = NULL; - } - } - - if (!encoder) { - ret = SDL_SetError("No connected encoder found."); - goto cleanup; - } - - /* Try to find a CRTC connected to this encoder */ - crtc = KMSDRM_LEGACY_drmModeGetCrtc(viddata->drm_fd, encoder->crtc_id); - - /* If no CRTC was connected to the encoder, find the first CRTC - that is supported by the encoder, and use that. */ - if (!crtc) { - for (i = 0; i < resources->count_crtcs; i++) { - if (encoder->possible_crtcs & (1 << i)) { - encoder->crtc_id = resources->crtcs[i]; - crtc = KMSDRM_LEGACY_drmModeGetCrtc(viddata->drm_fd, encoder->crtc_id); - break; - } - } - } - - if (!crtc) { - ret = SDL_SetError("No CRTC found."); - goto cleanup; - } - - /* Figure out the default mode to be set. */ - dispdata->mode = crtc->mode; - - /* Save the original mode for restoration on quit. */ - dispdata->original_mode = dispdata->mode; - - if (dispdata->mode.hdisplay == 0 || dispdata->mode.vdisplay == 0 ) { - ret = SDL_SetError("Couldn't get a valid connector videomode."); - goto cleanup; - } - - /* Store the connector and crtc for future use. These are all we keep - from this function, and these are just structs, inoffensive to VK. */ - dispdata->connector = connector; - dispdata->crtc = crtc; - - /***********************************/ - /* Block for Vulkan compatibility. */ - /***********************************/ - - /* THIS IS FOR VULKAN! Leave the FD closed, so VK can work. - Will reopen this in CreateWindow, but only if requested a non-VK window. */ - close (viddata->drm_fd); - viddata->drm_fd = -1; - -cleanup: - if (encoder) - KMSDRM_LEGACY_drmModeFreeEncoder(encoder); - if (resources) - KMSDRM_LEGACY_drmModeFreeResources(resources); - if (ret) { - /* Error (complete) cleanup */ - if (dispdata->connector) { - KMSDRM_LEGACY_drmModeFreeConnector(dispdata->connector); - dispdata->connector = NULL; - } - if (dispdata->crtc) { - KMSDRM_LEGACY_drmModeFreeCrtc(dispdata->crtc); - dispdata->crtc = NULL; - } - if (viddata->drm_fd >= 0) { - close(viddata->drm_fd); - viddata->drm_fd = -1; - } - } - - return ret; -} - -/* Init the Vulkan-INCOMPATIBLE stuff: - Reopen FD, create gbm dev, create dumb buffer and setup display plane. - This is to be called late, in WindowCreate(), and ONLY if this is not - a Vulkan window. - We are doing this so late to allow Vulkan to work if we build a VK window. - These things are incompatible with Vulkan, which accesses the same resources - internally so they must be free when trying to build a Vulkan surface. -*/ -int -KMSDRM_LEGACY_GBMInit (_THIS, SDL_DisplayData *dispdata) -{ - SDL_VideoData *viddata = (SDL_VideoData *)_this->driverdata; - int ret = 0; - - /* Reopen the FD! */ - viddata->drm_fd = open(viddata->devpath, O_RDWR | O_CLOEXEC); - - /* Create the GBM device. */ - viddata->gbm_dev = KMSDRM_LEGACY_gbm_create_device(viddata->drm_fd); - if (!viddata->gbm_dev) { - ret = SDL_SetError("Couldn't create gbm device."); - } - - dispdata->gbm_init = SDL_TRUE; - - return ret; -} - -/* Deinit the Vulkan-incompatible KMSDRM stuff. */ -void -KMSDRM_LEGACY_GBMDeinit (_THIS, SDL_DisplayData *dispdata) -{ - SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata); - - /* Destroy GBM device. GBM surface is destroyed by DestroySurfaces(), - already called when we get here. */ - if (viddata->gbm_dev) { - KMSDRM_LEGACY_gbm_device_destroy(viddata->gbm_dev); - viddata->gbm_dev = NULL; - } - - /* Finally close DRM FD. May be reopen on next non-vulkan window creation. */ - if (viddata->drm_fd >= 0) { - close(viddata->drm_fd); - viddata->drm_fd = -1; - } - - dispdata->gbm_init = SDL_FALSE; -} - -void -KMSDRM_LEGACY_DestroySurfaces(_THIS, SDL_Window *window) -{ - SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata); - SDL_WindowData *windata = (SDL_WindowData *) window->driverdata; - SDL_DisplayData *dispdata = (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata; - int ret; - - /**********************************************/ - /* Wait for last issued pageflip to complete. */ - /**********************************************/ - KMSDRM_LEGACY_WaitPageFlip(_this, windata, -1); - - /***********************************************************************/ - /* Restore the original CRTC configuration: configue the crtc with the */ - /* original video mode and make it point to the original TTY buffer. */ - /***********************************************************************/ - - ret = KMSDRM_LEGACY_drmModeSetCrtc(viddata->drm_fd, dispdata->crtc->crtc_id, - dispdata->crtc->buffer_id, 0, 0, &dispdata->connector->connector_id, 1, - &dispdata->original_mode); - - /* If we failed to set the original mode, try to set the connector prefered mode. */ - if (ret && (dispdata->crtc->mode_valid == 0)) { - ret = KMSDRM_LEGACY_drmModeSetCrtc(viddata->drm_fd, dispdata->crtc->crtc_id, - dispdata->crtc->buffer_id, 0, 0, &dispdata->connector->connector_id, 1, - &dispdata->original_mode); - } - - if(ret) { - SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not restore CRTC"); - } - - /***************************/ - /* Destroy the EGL surface */ - /***************************/ - - SDL_EGL_MakeCurrent(_this, EGL_NO_SURFACE, EGL_NO_CONTEXT); - - if (windata->egl_surface != EGL_NO_SURFACE) { - SDL_EGL_DestroySurface(_this, windata->egl_surface); - windata->egl_surface = EGL_NO_SURFACE; - } - - /***************************/ - /* Destroy the GBM buffers */ - /***************************/ - - if (windata->bo) { - KMSDRM_LEGACY_gbm_surface_release_buffer(windata->gs, windata->bo); - windata->bo = NULL; - } - - if (windata->next_bo) { - KMSDRM_LEGACY_gbm_surface_release_buffer(windata->gs, windata->next_bo); - windata->next_bo = NULL; - } - - /***************************/ - /* Destroy the GBM surface */ - /***************************/ - - if (windata->gs) { - KMSDRM_LEGACY_gbm_surface_destroy(windata->gs); - windata->gs = NULL; - } -} - -int -KMSDRM_LEGACY_CreateSurfaces(_THIS, SDL_Window * window) -{ - SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata); - SDL_WindowData *windata = (SDL_WindowData *)window->driverdata; - SDL_DisplayData *dispdata = (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata; - uint32_t surface_fmt = GBM_FORMAT_ARGB8888; - uint32_t surface_flags = GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING; - uint32_t width, height; - - EGLContext egl_context; - - int ret = 0; - - /* If the current window already has surfaces, destroy them before creating other. - This is mainly for ReconfigureWindow(), where we simply call CreateSurfaces() - for regenerating a window's surfaces. */ - if (windata->gs) { - KMSDRM_LEGACY_DestroySurfaces(_this, window); - } - - if ( ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) - || ((window->flags & SDL_WINDOW_FULLSCREEN) == SDL_WINDOW_FULLSCREEN)) - { - width = dispdata->mode.hdisplay; - height = dispdata->mode.vdisplay; - } else { - width = window->w; - height = window->h; - } - - if (!KMSDRM_LEGACY_gbm_device_is_format_supported(viddata->gbm_dev, - surface_fmt, surface_flags)) { - SDL_LogWarn(SDL_LOG_CATEGORY_VIDEO, - "GBM surface format not supported. Trying anyway."); - } - - windata->gs = KMSDRM_LEGACY_gbm_surface_create(viddata->gbm_dev, - width, height, surface_fmt, surface_flags); - - if (!windata->gs) { - return SDL_SetError("Could not create GBM surface"); - } - - /* We can't get the EGL context yet because SDL_CreateRenderer has not been called, - but we need an EGL surface NOW, or GL won't be able to render into any surface - and we won't see the first frame. */ - SDL_EGL_SetRequiredVisualId(_this, surface_fmt); - windata->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType)windata->gs); - - if (windata->egl_surface == EGL_NO_SURFACE) { - ret = SDL_SetError("Could not create EGL window surface"); - goto cleanup; - } - - /* Current context passing to EGL is now done here. If something fails, - go back to delayed SDL_EGL_MakeCurrent() call in SwapWindow. */ - egl_context = (EGLContext)SDL_GL_GetCurrentContext(); - ret = SDL_EGL_MakeCurrent(_this, windata->egl_surface, egl_context); - -cleanup: - - if (ret) { - /* Error (complete) cleanup. */ - if (windata->gs) { - KMSDRM_LEGACY_gbm_surface_destroy(windata->gs); - windata->gs = NULL; - } - } - - return ret; -} - -int -KMSDRM_LEGACY_VideoInit(_THIS) -{ - int ret = 0; - - SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata); - SDL_DisplayData *dispdata = NULL; - SDL_VideoDisplay display = {0}; - - SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "KMSDRM_VideoInit()"); - - viddata->video_init = SDL_FALSE; - - dispdata = (SDL_DisplayData *) SDL_calloc(1, sizeof(SDL_DisplayData)); - if (!dispdata) { - return SDL_OutOfMemory(); - } - - /* Get KMSDRM resources info and store what we need. Getting and storing - this info isn't a problem for VK compatibility. - For VK-incompatible initializations we have KMSDRM_LEGACY_GBMInit(), which is - called on window creation, and only when we know it's not a VK window. */ - if (KMSDRM_LEGACY_DisplayDataInit(_this, dispdata)) { - ret = SDL_SetError("error getting KMS/DRM information"); - goto cleanup; - } - - /* Setup the single display that's available. - There's no problem with it being still incomplete. */ - display.driverdata = dispdata; - display.desktop_mode.w = dispdata->mode.hdisplay; - display.desktop_mode.h = dispdata->mode.vdisplay; - display.desktop_mode.refresh_rate = dispdata->mode.vrefresh; - display.desktop_mode.format = SDL_PIXELFORMAT_ARGB8888; - display.current_mode = display.desktop_mode; - - /* Add the display only when it's ready, */ - SDL_AddVideoDisplay(&display, SDL_FALSE); - -#ifdef SDL_INPUT_LINUXEV - SDL_EVDEV_Init(); -#endif - - /* Since we create and show the default cursor on KMSDRM_InitMouse() and - we call KMSDRM_InitMouse() everytime we create a new window, we have - to be sure to create and show the default cursor only the first time. - If we don't, new default cursors would stack up on mouse->cursors and SDL - would have to hide and delete them at quit, not to mention the memory leak... */ - dispdata->set_default_cursor_pending = SDL_TRUE; - - viddata->video_init = SDL_TRUE; - -cleanup: - - if (ret) { - /* Error (complete) cleanup */ - if (dispdata->crtc) { - SDL_free(dispdata->crtc); - } - if (dispdata->connector) { - SDL_free(dispdata->connector); - } - - SDL_free(dispdata); - } - - return ret; -} - -/* The driverdata pointers, like dispdata, viddata, windata, etc... - are freed by SDL internals, so not our job. */ -void -KMSDRM_LEGACY_VideoQuit(_THIS) -{ - SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata); - SDL_DisplayData *dispdata = (SDL_DisplayData *)SDL_GetDisplayDriverData(0); - - KMSDRM_LEGACY_DisplayDataDeinit(_this, dispdata); - -#ifdef SDL_INPUT_LINUXEV - SDL_EVDEV_Quit(); -#endif - - /* Clear out the window list */ - SDL_free(viddata->windows); - viddata->windows = NULL; - viddata->max_windows = 0; - viddata->num_windows = 0; - viddata->video_init = SDL_FALSE; -} - -void -KMSDRM_LEGACY_GetDisplayModes(_THIS, SDL_VideoDisplay * display) -{ - SDL_DisplayData *dispdata = display->driverdata; - drmModeConnector *conn = dispdata->connector; - SDL_DisplayMode mode; - int i; - - for (i = 0; i < conn->count_modes; i++) { - SDL_DisplayModeData *modedata = SDL_calloc(1, sizeof(SDL_DisplayModeData)); - - if (modedata) { - modedata->mode_index = i; - } - - mode.w = conn->modes[i].hdisplay; - mode.h = conn->modes[i].vdisplay; - mode.refresh_rate = conn->modes[i].vrefresh; - mode.format = SDL_PIXELFORMAT_ARGB8888; - mode.driverdata = modedata; - - if (!SDL_AddDisplayMode(display, &mode)) { - SDL_free(modedata); - } - } -} - -int -KMSDRM_LEGACY_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode) -{ - SDL_VideoData *viddata = (SDL_VideoData *)_this->driverdata; - SDL_DisplayData *dispdata = (SDL_DisplayData *)display->driverdata; - SDL_DisplayModeData *modedata = (SDL_DisplayModeData *)mode->driverdata; - drmModeConnector *conn = dispdata->connector; - int i; - - if (!modedata) { - return SDL_SetError("Mode doesn't have an associated index"); - } - - dispdata->mode = conn->modes[modedata->mode_index]; - - for (i = 0; i < viddata->num_windows; i++) { - SDL_Window *window = viddata->windows[i]; - SDL_WindowData *windata = (SDL_WindowData *)window->driverdata; - - /* Can't recreate EGL surfaces right now, need to wait until SwapWindow - so the correct thread-local surface and context state are available */ - windata->egl_surface_dirty = 1; - - /* Tell app about the resize */ - SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, mode->w, mode->h); - } - - return 0; -} - -void -KMSDRM_LEGACY_DestroyWindow(_THIS, SDL_Window *window) -{ - SDL_WindowData *windata = (SDL_WindowData *) window->driverdata; - SDL_DisplayData *dispdata = (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata; - SDL_VideoData *viddata = windata->viddata; - SDL_bool is_vulkan = window->flags & SDL_WINDOW_VULKAN; /* Is this a VK window? */ - unsigned int i, j; - - if (!windata) { - return; - } - - if ( !is_vulkan && dispdata->gbm_init ) { - - /* Destroy cursor GBM plane. */ - KMSDRM_LEGACY_DeinitMouse(_this); - - /* Destroy GBM surface and buffers. */ - KMSDRM_LEGACY_DestroySurfaces(_this, window); - - /* Unload EGL library. */ - if (_this->egl_data) { - SDL_EGL_UnloadLibrary(_this); - } - - /* Unload GL library. */ - if (_this->gl_config.driver_loaded) { - SDL_GL_UnloadLibrary(); - } - - /* Free display plane, and destroy GBM device. */ - KMSDRM_LEGACY_GBMDeinit(_this, dispdata); - } - - else { - /* If we were in Vulkan mode, get out of it. */ - if (viddata->vulkan_mode) { - viddata->vulkan_mode = SDL_FALSE; - } - } - - /********************************************/ - /* Remove from the internal SDL window list */ - /********************************************/ - - for (i = 0; i < viddata->num_windows; i++) { - if (viddata->windows[i] == window) { - viddata->num_windows--; - - for (j = i; j < viddata->num_windows; j++) { - viddata->windows[j] = viddata->windows[j + 1]; - } - - break; - } - } - - /*********************************************************************/ - /* Free the window driverdata. Bye bye, surface and buffer pointers! */ - /*********************************************************************/ - window->driverdata = NULL; - SDL_free(windata); -} - -int -KMSDRM_LEGACY_CreateWindow(_THIS, SDL_Window * window) -{ - SDL_WindowData *windata = NULL; - SDL_VideoData *viddata = (SDL_VideoData *)_this->driverdata; - SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); - SDL_DisplayData *dispdata = display->driverdata; - SDL_bool is_vulkan = window->flags & SDL_WINDOW_VULKAN; /* Is this a VK window? */ - SDL_bool vulkan_mode = viddata->vulkan_mode; /* Do we have any Vulkan windows? */ - NativeDisplayType egl_display; - float ratio; - int ret = 0; - - if ( !(dispdata->gbm_init) && !is_vulkan && !vulkan_mode ) { - - /* If this is not a Vulkan Window, then this is a GL window, so at the - end of this function, we must have marked the window as being OPENGL - and we must have loaded the GL library: both things are needed so the - GL_CreateRenderer() and GL_LoadFunctions() calls in SDL_CreateWindow() - succeed without having to re-create the window. - We must load the EGL library too, which can't be loaded until the GBM - device has been created, because SDL_EGL_Library() function uses it. */ - - /* Maybe you didn't ask for an OPENGL window, but that's what you will get. - See previous comment on why. */ - window->flags |= SDL_WINDOW_OPENGL; - - /* We need that the fb that SDL gives us has the same size as the videomode - currently configure on the CRTC, because the LEGACY interface doesn't - support scaling on the primary plane on most hardware (and overlay - planes are not present in all hw), so the CRTC reads the PRIMARY PLANE - without any scaling, and that's all. - So AR-correctin is also impossible on the LEGACY interface. */ - window->w = dispdata->mode.hdisplay; - window->h = dispdata->mode.vdisplay; - - /* Reopen FD, create gbm dev, setup display plane, etc,. - but only when we come here for the first time, - and only if it's not a VK window. */ - if ((ret = KMSDRM_LEGACY_GBMInit(_this, dispdata))) { - goto cleanup; - } - - /* Manually load the GL library. KMSDRM_EGL_LoadLibrary() has already - been called by SDL_CreateWindow() but we don't do anything there, - precisely to be able to load it here. - If we let SDL_CreateWindow() load the lib, it will be loaded - before we call KMSDRM_GBMInit(), causing GLES programs to fail. */ - if (!_this->egl_data) { - egl_display = (NativeDisplayType)((SDL_VideoData *)_this->driverdata)->gbm_dev; - if (SDL_EGL_LoadLibrary(_this, NULL, egl_display, EGL_PLATFORM_GBM_MESA)) { - goto cleanup; - } - - if (SDL_GL_LoadLibrary(NULL) < 0) { - goto cleanup; - } - } - - /* Can't init mouse stuff sooner because cursor plane is not ready, - so we do it here. */ - KMSDRM_LEGACY_InitMouse(_this); - - /* Since we take cursor buffer way from the cursor plane and - destroy the cursor GBM BO when we destroy a window, we must - also manually re-show the cursor on screen, if necessary, - when we create a window. */ - KMSDRM_LEGACY_InitCursor(); - } - - /* Allocate window internal data */ - windata = (SDL_WindowData *)SDL_calloc(1, sizeof(SDL_WindowData)); - if (!windata) { - ret = SDL_OutOfMemory(); - goto cleanup; - } - - if (((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) - || ((window->flags & SDL_WINDOW_FULLSCREEN) == SDL_WINDOW_FULLSCREEN)) - { - windata->src_w = dispdata->mode.hdisplay; - windata->src_h = dispdata->mode.vdisplay; - windata->output_w = dispdata->mode.hdisplay; - windata->output_h = dispdata->mode.vdisplay; - windata->output_x = 0; - } else { - /* Normal non-fullscreen windows are scaled to the in-use video mode - using a PLANE connected to the CRTC, so get input size, - output (CRTC) size, and position. */ - ratio = (float)window->w / (float)window->h; - windata->src_w = window->w; - windata->src_h = window->h; - windata->output_w = dispdata->mode.vdisplay * ratio; - windata->output_h = dispdata->mode.vdisplay; - windata->output_x = (dispdata->mode.hdisplay - windata->output_w) / 2; - } - - /* Don't force fullscreen on all windows: it confuses programs that try - to set a window fullscreen after creating it as non-fullscreen (sm64ex) */ - // window->flags |= SDL_WINDOW_FULLSCREEN; - - /* Setup driver data for this window */ - windata->viddata = viddata; - window->driverdata = windata; - - if (!is_vulkan && !vulkan_mode) { - /* Create the window surfaces. Needs the window diverdata in place. */ - if ((ret = KMSDRM_LEGACY_CreateSurfaces(_this, window))) { - goto cleanup; - } - - /***************************************************************************/ - /* This is fundamental. */ - /* We can't display an fb smaller than the resolution currently configured */ - /* on the CRTC, because the CRTC would be scanning out of bounds, and */ - /* drmModeSetCrtc() would fail. */ - /* A possible solution would be scaling on the primary plane with */ - /* drmModeSetPlane(), but primary plane scaling is not supported in most */ - /* LEGACY-only hardware, so never use drmModeSetPlane(). */ - /***************************************************************************/ - - ret = KMSDRM_LEGACY_drmModeSetCrtc(viddata->drm_fd, dispdata->crtc->crtc_id, - /*fb_info->fb_id*/ -1, 0, 0, &dispdata->connector->connector_id, 1, - &dispdata->mode); - - if (ret) { - SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not set CRTC"); - goto cleanup; - } - } - - /* Add window to the internal list of tracked windows. Note, while it may - seem odd to support multiple fullscreen windows, some apps create an - extra window as a dummy surface when working with multiple contexts */ - if (viddata->num_windows >= viddata->max_windows) { - unsigned int new_max_windows = viddata->max_windows + 1; - viddata->windows = (SDL_Window **)SDL_realloc(viddata->windows, - new_max_windows * sizeof(SDL_Window *)); - viddata->max_windows = new_max_windows; - - if (!viddata->windows) { - ret = SDL_OutOfMemory(); - goto cleanup; - } - } - - viddata->windows[viddata->num_windows++] = window; - - /* If we have just created a Vulkan window, establish that we are in Vulkan mode now. */ - viddata->vulkan_mode = is_vulkan; - - /* Focus on the newly created window */ - SDL_SetMouseFocus(window); - SDL_SetKeyboardFocus(window); - - /***********************************************************/ - /* Tell SDL that the mouse has entered the window using an */ - /* artificial event: we have no windowing system to tell */ - /* SDL that it has happened. This makes SDL set the */ - /* SDL_WINDOW_MOUSE_FOCUS on this window, thus fixing */ - /* Scummvm sticky-on-sides software cursor. */ - /***********************************************************/ - SDL_SendWindowEvent(window, SDL_WINDOWEVENT_ENTER, 0, 0); - -cleanup: - - if (ret) { - /* Allocated windata will be freed in KMSDRM_DestroyWindow */ - KMSDRM_LEGACY_DestroyWindow(_this, window); - } - return ret; -} - -/*****************************************************************************/ -/* Reconfigure the window scaling parameters and re-construct it's surfaces, */ -/* without destroying the window itself. */ -/* To be used by SetWindowSize() and SetWindowFullscreen(). */ -/*****************************************************************************/ -static int -KMSDRM_LEGACY_ReconfigureWindow( _THIS, SDL_Window * window) { - SDL_WindowData *windata = window->driverdata; - SDL_DisplayData *dispdata = (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata; - SDL_bool is_vulkan = window->flags & SDL_WINDOW_VULKAN; /* Is this a VK window? */ - float ratio; - - if (((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) || - ((window->flags & SDL_WINDOW_FULLSCREEN) == SDL_WINDOW_FULLSCREEN)) { - - windata->src_w = dispdata->mode.hdisplay; - windata->src_h = dispdata->mode.vdisplay; - windata->output_w = dispdata->mode.hdisplay; - windata->output_h = dispdata->mode.vdisplay; - windata->output_x = 0; - - } else { - /* Normal non-fullscreen windows are scaled using the CRTC, - so get output (CRTC) size and position, for AR correction. */ - ratio = (float)window->w / (float)window->h; - windata->src_w = window->w; - windata->src_h = window->h; - windata->output_w = dispdata->mode.vdisplay * ratio; - windata->output_h = dispdata->mode.vdisplay; - windata->output_x = (dispdata->mode.hdisplay - windata->output_w) / 2; - } - - if (!is_vulkan) { - if (KMSDRM_LEGACY_CreateSurfaces(_this, window)) { - return -1; - } - } - return 0; -} - -int -KMSDRM_LEGACY_CreateWindowFrom(_THIS, SDL_Window * window, const void *data) -{ - return -1; -} - -void -KMSDRM_LEGACY_SetWindowTitle(_THIS, SDL_Window * window) -{ -} -void -KMSDRM_LEGACY_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon) -{ -} -void -KMSDRM_LEGACY_SetWindowPosition(_THIS, SDL_Window * window) -{ -} -void -KMSDRM_LEGACY_SetWindowSize(_THIS, SDL_Window * window) -{ - if (KMSDRM_LEGACY_ReconfigureWindow(_this, window)) { - SDL_SetError("Can't reconfigure window on SetWindowSize."); - } -} -void -KMSDRM_LEGACY_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen) -{ - if (KMSDRM_LEGACY_ReconfigureWindow(_this, window)) { - SDL_SetError("Can't reconfigure window on SetWindowFullscreen."); - } -} -void -KMSDRM_LEGACY_ShowWindow(_THIS, SDL_Window * window) -{ -} -void -KMSDRM_LEGACY_HideWindow(_THIS, SDL_Window * window) -{ -} -void -KMSDRM_LEGACY_RaiseWindow(_THIS, SDL_Window * window) -{ -} -void -KMSDRM_LEGACY_MaximizeWindow(_THIS, SDL_Window * window) -{ -} -void -KMSDRM_LEGACY_MinimizeWindow(_THIS, SDL_Window * window) -{ -} -void -KMSDRM_LEGACY_RestoreWindow(_THIS, SDL_Window * window) -{ -} -void -KMSDRM_LEGACY_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed) -{ - -} - -/*****************************************************************************/ -/* SDL Window Manager function */ -/*****************************************************************************/ -SDL_bool -KMSDRM_LEGACY_GetWindowWMInfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo *info) -{ - if (info->version.major <= SDL_MAJOR_VERSION) { - return SDL_TRUE; - } else { - SDL_SetError("application not compiled with SDL %d.%d\n", - SDL_MAJOR_VERSION, SDL_MINOR_VERSION); - return SDL_FALSE; - } - - /* Failed to get window manager information */ - return SDL_FALSE; -} - -#endif /* SDL_VIDEO_DRIVER_KMSDRM */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_video.h b/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_video.h deleted file mode 100644 index e1b7d0af9..000000000 --- a/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_video.h +++ /dev/null @@ -1,162 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2021 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -#include "../../SDL_internal.h" - -#ifndef __SDL_KMSDRM_LEGACYVIDEO_H__ -#define __SDL_KMSDRM_LEGACYVIDEO_H__ - -#include "../SDL_sysvideo.h" - -#include -#include -#include -#include -#include -#include - -typedef struct SDL_VideoData -{ - int devindex; /* device index that was passed on creation */ - int drm_fd; /* DRM file desc */ - char devpath[32]; /* DRM dev path. */ - - struct gbm_device *gbm_dev; - - SDL_bool video_init; /* Has VideoInit succeeded? */ - SDL_bool vulkan_mode; /* Are we in Vulkan mode? One VK window is enough to be. */ - - SDL_Window **windows; - int max_windows; - int num_windows; -} SDL_VideoData; - - -typedef struct SDL_DisplayModeData -{ - int mode_index; -} SDL_DisplayModeData; - - -typedef struct SDL_DisplayData -{ - drmModeConnector *connector; - drmModeCrtc *crtc; - drmModeModeInfo mode; - drmModeModeInfo original_mode; - - drmModeCrtc *saved_crtc; /* CRTC to restore on quit */ - - SDL_bool gbm_init; - - /* DRM & GBM cursor stuff lives here, not in an SDL_Cursor's driverdata struct, - because setting/unsetting up these is done on window creation/destruction, - where we may not have an SDL_Cursor at all (so no SDL_Cursor driverdata). - There's only one cursor GBM BO because we only support one cursor. */ - struct gbm_bo *cursor_bo; - uint64_t cursor_w, cursor_h; - - SDL_bool modeset_pending; - - SDL_bool set_default_cursor_pending; - -} SDL_DisplayData; - -typedef struct SDL_WindowData -{ - SDL_VideoData *viddata; - /* SDL internals expect EGL surface to be here, and in KMSDRM the GBM surface is - what supports the EGL surface on the driver side, so all these surfaces and buffers - are expected to be here, in the struct pointed by SDL_Window driverdata pointer: - this one. So don't try to move these to dispdata! */ - struct gbm_surface *gs; - struct gbm_bo *bo; - struct gbm_bo *next_bo; - - SDL_bool waiting_for_flip; - SDL_bool double_buffer; - - int egl_surface_dirty; - EGLSurface egl_surface; - - /* For scaling and AR correction. */ - int32_t src_w; - int32_t src_h; - int32_t output_w; - int32_t output_h; - int32_t output_x; - -} SDL_WindowData; - -typedef struct KMSDRM_LEGACY_FBInfo -{ - int drm_fd; /* DRM file desc */ - uint32_t fb_id; /* DRM framebuffer ID */ -} KMSDRM_LEGACY_FBInfo; - -/* Helper functions */ -int KMSDRM_LEGACY_CreateSurfaces(_THIS, SDL_Window * window); -KMSDRM_LEGACY_FBInfo *KMSDRM_LEGACY_FBFromBO(_THIS, struct gbm_bo *bo); -SDL_bool KMSDRM_LEGACY_WaitPageFlip(_THIS, SDL_WindowData *windata, int timeout); - -/****************************************************************************/ -/* SDL_VideoDevice functions declaration */ -/****************************************************************************/ - -/* Display and window functions */ -int KMSDRM_LEGACY_VideoInit(_THIS); -void KMSDRM_LEGACY_VideoQuit(_THIS); -void KMSDRM_LEGACY_GetDisplayModes(_THIS, SDL_VideoDisplay * display); -int KMSDRM_LEGACY_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode); -int KMSDRM_LEGACY_CreateWindow(_THIS, SDL_Window * window); -int KMSDRM_LEGACY_CreateWindowFrom(_THIS, SDL_Window * window, const void *data); -void KMSDRM_LEGACY_SetWindowTitle(_THIS, SDL_Window * window); -void KMSDRM_LEGACY_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon); -void KMSDRM_LEGACY_SetWindowPosition(_THIS, SDL_Window * window); -void KMSDRM_LEGACY_SetWindowSize(_THIS, SDL_Window * window); -void KMSDRM_LEGACY_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * _display, SDL_bool fullscreen); -void KMSDRM_LEGACY_ShowWindow(_THIS, SDL_Window * window); -void KMSDRM_LEGACY_HideWindow(_THIS, SDL_Window * window); -void KMSDRM_LEGACY_RaiseWindow(_THIS, SDL_Window * window); -void KMSDRM_LEGACY_MaximizeWindow(_THIS, SDL_Window * window); -void KMSDRM_LEGACY_MinimizeWindow(_THIS, SDL_Window * window); -void KMSDRM_LEGACY_RestoreWindow(_THIS, SDL_Window * window); -void KMSDRM_LEGACY_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed); -void KMSDRM_LEGACY_DestroyWindow(_THIS, SDL_Window * window); - -/* Window manager function */ -SDL_bool KMSDRM_LEGACY_GetWindowWMInfo(_THIS, SDL_Window * window, - struct SDL_SysWMinfo *info); - -/* OpenGL/OpenGL ES functions */ -int KMSDRM_LEGACY_GLES_LoadLibrary(_THIS, const char *path); -void *KMSDRM_LEGACY_GLES_GetProcAddress(_THIS, const char *proc); -void KMSDRM_LEGACY_GLES_UnloadLibrary(_THIS); -SDL_GLContext KMSDRM_LEGACY_GLES_CreateContext(_THIS, SDL_Window * window); -int KMSDRM_LEGACY_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context); -int KMSDRM_LEGACY_GLES_SetSwapInterval(_THIS, int interval); -int KMSDRM_LEGACY_GLES_GetSwapInterval(_THIS); -int KMSDRM_LEGACY_GLES_SwapWindow(_THIS, SDL_Window * window); -void KMSDRM_LEGACY_GLES_DeleteContext(_THIS, SDL_GLContext context); - -#endif /* __SDL_KMSDRM_LEGACYVIDEO_H__ */ - -/* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_vulkan.c b/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_vulkan.c deleted file mode 100644 index b1c89d72e..000000000 --- a/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_vulkan.c +++ /dev/null @@ -1,422 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2021 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -/* - * @author Manuel Alfayate Corchere . - * Based on Jacob Lifshay's SDL_x11vulkan.c. - */ - -#include "../../SDL_internal.h" - -#if SDL_VIDEO_VULKAN && SDL_VIDEO_DRIVER_KMSDRM - -#include "SDL_kmsdrm_legacy_video.h" -#include "SDL_kmsdrm_legacy_dyn.h" -#include "SDL_assert.h" - -#include "SDL_loadso.h" -#include "SDL_kmsdrm_legacy_vulkan.h" -#include "SDL_syswm.h" -#include "sys/ioctl.h" - -#if defined(__OpenBSD__) -#define DEFAULT_VULKAN "libvulkan.so" -#else -#define DEFAULT_VULKAN "libvulkan.so.1" -#endif - -int KMSDRM_LEGACY_Vulkan_LoadLibrary(_THIS, const char *path) -{ - VkExtensionProperties *extensions = NULL; - Uint32 i, extensionCount = 0; - SDL_bool hasSurfaceExtension = SDL_FALSE; - SDL_bool hasDisplayExtension = SDL_FALSE; - PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = NULL; - - if(_this->vulkan_config.loader_handle) - return SDL_SetError("Vulkan already loaded"); - - /* Load the Vulkan library */ - if(!path) - path = SDL_getenv("SDL_VULKAN_LIBRARY"); - if(!path) - path = DEFAULT_VULKAN; - - _this->vulkan_config.loader_handle = SDL_LoadObject(path); - - if(!_this->vulkan_config.loader_handle) - return -1; - - SDL_strlcpy(_this->vulkan_config.loader_path, path, - SDL_arraysize(_this->vulkan_config.loader_path)); - - vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)SDL_LoadFunction( - _this->vulkan_config.loader_handle, "vkGetInstanceProcAddr"); - - if(!vkGetInstanceProcAddr) - goto fail; - - _this->vulkan_config.vkGetInstanceProcAddr = (void *)vkGetInstanceProcAddr; - _this->vulkan_config.vkEnumerateInstanceExtensionProperties = - (void *)((PFN_vkGetInstanceProcAddr)_this->vulkan_config.vkGetInstanceProcAddr)( - VK_NULL_HANDLE, "vkEnumerateInstanceExtensionProperties"); - - if(!_this->vulkan_config.vkEnumerateInstanceExtensionProperties) - goto fail; - - extensions = SDL_Vulkan_CreateInstanceExtensionsList( - (PFN_vkEnumerateInstanceExtensionProperties) - _this->vulkan_config.vkEnumerateInstanceExtensionProperties, - &extensionCount); - - if(!extensions) - goto fail; - - for(i = 0; i < extensionCount; i++) - { - if(SDL_strcmp(VK_KHR_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0) - hasSurfaceExtension = SDL_TRUE; - else if(SDL_strcmp(VK_KHR_DISPLAY_EXTENSION_NAME, extensions[i].extensionName) == 0) - hasDisplayExtension = SDL_TRUE; - } - - SDL_free(extensions); - - if(!hasSurfaceExtension) - { - SDL_SetError("Installed Vulkan doesn't implement the " - VK_KHR_SURFACE_EXTENSION_NAME " extension"); - goto fail; - } - else if(!hasDisplayExtension) - { - SDL_SetError("Installed Vulkan doesn't implement the " - VK_KHR_DISPLAY_EXTENSION_NAME "extension"); - goto fail; - } - - return 0; - -fail: - SDL_UnloadObject(_this->vulkan_config.loader_handle); - _this->vulkan_config.loader_handle = NULL; - return -1; -} - -void KMSDRM_LEGACY_Vulkan_UnloadLibrary(_THIS) -{ - if(_this->vulkan_config.loader_handle) - { - SDL_UnloadObject(_this->vulkan_config.loader_handle); - _this->vulkan_config.loader_handle = NULL; - } -} - -/*********************************************************************/ -/* Here we can put whatever Vulkan extensions we want to be enabled */ -/* at instance creation, which is done in the programs, not in SDL. */ -/* So: programs call SDL_Vulkan_GetInstanceExtensions() and here */ -/* we put the extensions specific to this backend so the programs */ -/* get a list with the extension we want, so they can include that */ -/* list in the ppEnabledExtensionNames and EnabledExtensionCount */ -/* members of the VkInstanceCreateInfo struct passed to */ -/* vkCreateInstance(). */ -/*********************************************************************/ -SDL_bool KMSDRM_LEGACY_Vulkan_GetInstanceExtensions(_THIS, - SDL_Window *window, - unsigned *count, - const char **names) -{ - static const char *const extensionsForKMSDRM[] = { - VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_DISPLAY_EXTENSION_NAME - }; - if(!_this->vulkan_config.loader_handle) - { - SDL_SetError("Vulkan is not loaded"); - return SDL_FALSE; - } - return SDL_Vulkan_GetInstanceExtensions_Helper( - count, names, SDL_arraysize(extensionsForKMSDRM), - extensionsForKMSDRM); -} - -void KMSDRM_LEGACY_Vulkan_GetDrawableSize(_THIS, SDL_Window *window, int *w, int *h) -{ - if (w) { - *w = window->w; - } - - if (h) { - *h = window->h; - } -} - -/***********************************************************************/ -/* First thing to know is that we don't call vkCreateInstance() here. */ -/* Instead, programs using SDL and Vulkan create their Vulkan instance */ -/* and we get it here, ready to use. */ -/* Extensions specific for this platform are activated in */ -/* KMSDRM_LEGACY_Vulkan_GetInstanceExtensions(), like we do with */ -/* VK_KHR_DISPLAY_EXTENSION_NAME, which is what we need for x-less VK. */ -/***********************************************************************/ -SDL_bool KMSDRM_LEGACY_Vulkan_CreateSurface(_THIS, - SDL_Window *window, - VkInstance instance, - VkSurfaceKHR *surface) -{ - VkPhysicalDevice gpu; - uint32_t gpu_count; - uint32_t display_count; - uint32_t mode_count; - uint32_t plane_count; - - VkPhysicalDevice *physical_devices = NULL; - VkDisplayPropertiesKHR *displays_props = NULL; - VkDisplayModePropertiesKHR *modes_props = NULL; - VkDisplayPlanePropertiesKHR *planes_props = NULL; - - VkDisplayModeCreateInfoKHR display_mode_create_info; - VkDisplaySurfaceCreateInfoKHR display_plane_surface_create_info; - - VkExtent2D image_size; - VkDisplayModeKHR *display_mode = NULL; - VkDisplayModePropertiesKHR display_mode_props = {0}; - VkDisplayModeParametersKHR new_mode_parameters = { {0, 0}, 0}; - - VkResult result; - SDL_bool ret = SDL_FALSE; - SDL_bool mode_found = SDL_FALSE; - - /* We don't receive a display index in KMSDRM_LEGACY_CreateDevice(), only - a device index, which determines the GPU to use, but not the output. - So we simply use the first connected output (ie, the first connected - video output) for now. - In other words, change this index to select a different output. Easy! */ - int display_index = 0; - - int i; - - SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata); - - /* Get the function pointers for the functions we will use. */ - PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = - (PFN_vkGetInstanceProcAddr)_this->vulkan_config.vkGetInstanceProcAddr; - - PFN_vkCreateDisplayPlaneSurfaceKHR vkCreateDisplayPlaneSurfaceKHR = - (PFN_vkCreateDisplayPlaneSurfaceKHR)vkGetInstanceProcAddr( - instance, "vkCreateDisplayPlaneSurfaceKHR"); - - PFN_vkEnumeratePhysicalDevices vkEnumeratePhysicalDevices = - (PFN_vkEnumeratePhysicalDevices)vkGetInstanceProcAddr( - instance, "vkEnumeratePhysicalDevices"); - - PFN_vkGetPhysicalDeviceDisplayPropertiesKHR vkGetPhysicalDeviceDisplayPropertiesKHR = - (PFN_vkGetPhysicalDeviceDisplayPropertiesKHR)vkGetInstanceProcAddr( - instance, "vkGetPhysicalDeviceDisplayPropertiesKHR"); - - PFN_vkGetDisplayModePropertiesKHR vkGetDisplayModePropertiesKHR = - (PFN_vkGetDisplayModePropertiesKHR)vkGetInstanceProcAddr( - instance, "vkGetDisplayModePropertiesKHR"); - - PFN_vkGetPhysicalDeviceDisplayPlanePropertiesKHR vkGetPhysicalDeviceDisplayPlanePropertiesKHR = - (PFN_vkGetPhysicalDeviceDisplayPlanePropertiesKHR)vkGetInstanceProcAddr( - instance, "vkGetPhysicalDeviceDisplayPlanePropertiesKHR"); - - /*PFN_vkGetDisplayPlaneSupportedDisplaysKHR vkGetDisplayPlaneSupportedDisplaysKHR = - (PFN_vkGetDisplayPlaneSupportedDisplaysKHR)vkGetInstanceProcAddr( - instance, "vkGetDisplayPlaneSupportedDisplaysKHR"); - - PFN_vkGetDisplayPlaneCapabilitiesKHR vkGetDisplayPlaneCapabilitiesKHR = - (PFN_vkGetDisplayPlaneCapabilitiesKHR)vkGetInstanceProcAddr( - instance, "vkGetDisplayPlaneCapabilitiesKHR"); - */ - - PFN_vkCreateDisplayModeKHR vkCreateDisplayModeKHR = - (PFN_vkCreateDisplayModeKHR)vkGetInstanceProcAddr( - instance, "vkCreateDisplayModeKHR"); - - if(!_this->vulkan_config.loader_handle) - { - SDL_SetError("Vulkan is not loaded"); - goto clean; - } - - /*************************************/ - /* Block for vulkan surface creation */ - /*************************************/ - - /****************************************************************/ - /* If we got vkCreateDisplayPlaneSurfaceKHR() pointer, it means */ - /* that the VK_KHR_Display extension is active on the instance. */ - /* That's the central extension we need for x-less VK! */ - /****************************************************************/ - if(!vkCreateDisplayPlaneSurfaceKHR) - { - SDL_SetError(VK_KHR_DISPLAY_EXTENSION_NAME - " extension is not enabled in the Vulkan instance."); - goto clean; - } - - /* Get the physical device count. */ - vkEnumeratePhysicalDevices(instance, &gpu_count, NULL); - - if (gpu_count == 0) { - SDL_SetError("Vulkan can't find physical devices (gpus)."); - goto clean; - } - - /* Get the physical devices. */ - physical_devices = SDL_malloc(sizeof(VkPhysicalDevice) * gpu_count); - vkEnumeratePhysicalDevices(instance, &gpu_count, physical_devices); - - /* A GPU (or physical_device, in vkcube terms) is a GPU. A machine with more - than one video output doen't need to have more than one GPU, like the Pi4 - which has 1 GPU and 2 video outputs. - We grab the GPU/physical_device with the index we got in KMSDR_CreateDevice(). */ - gpu = physical_devices[viddata->devindex]; - - /* A display is a video output. 1 GPU can have N displays. - Vulkan only counts the connected displays. - Get the display count of the GPU. */ - vkGetPhysicalDeviceDisplayPropertiesKHR(gpu, &display_count, NULL); - if (display_count == 0) { - SDL_SetError("Vulkan can't find any displays."); - goto clean; - } - - /* Get the props of the displays of the physical device. */ - displays_props = (VkDisplayPropertiesKHR *) SDL_malloc(display_count * sizeof(*displays_props)); - vkGetPhysicalDeviceDisplayPropertiesKHR(gpu, - &display_count, - displays_props); - - /* Get the videomode count for the first display. */ - vkGetDisplayModePropertiesKHR(gpu, - displays_props[display_index].display, - &mode_count, NULL); - - if (mode_count == 0) { - SDL_SetError("Vulkan can't find any video modes for display %i (%s)\n", 0, - displays_props[display_index].displayName); - goto clean; - } - - /* Get the props of the videomodes for the first display. */ - modes_props = (VkDisplayModePropertiesKHR *) SDL_malloc(mode_count * sizeof(*modes_props)); - vkGetDisplayModePropertiesKHR(gpu, - displays_props[display_index].display, - &mode_count, modes_props); - - /* Get the planes count of the physical device. */ - vkGetPhysicalDeviceDisplayPlanePropertiesKHR(gpu, &plane_count, NULL); - if (plane_count == 0) { - SDL_SetError("Vulkan can't find any planes."); - goto clean; - } - - /* Get the props of the planes for the physical device. */ - planes_props = SDL_malloc(sizeof(VkDisplayPlanePropertiesKHR) * plane_count); - vkGetPhysicalDeviceDisplayPlanePropertiesKHR(gpu, &plane_count, planes_props); - - /* Get a video mode equal or smaller than the window size. REMEMBER: - We have to get a small enough videomode for the window size, - because videomode determines how big the scanout region is and we can't - scanout a region bigger than the window (we would be reading past the - buffer, and Vulkan would give us a confusing VK_ERROR_SURFACE_LOST_KHR). */ - for (i = 0; i < mode_count; i++) { - if (modes_props[i].parameters.visibleRegion.width <= window->w && - modes_props[i].parameters.visibleRegion.height <= window->h) - { - display_mode_props = modes_props[i]; - mode_found = SDL_TRUE; - break; - } - } - - if (mode_found && - display_mode_props.parameters.visibleRegion.width > 0 && - display_mode_props.parameters.visibleRegion.height > 0 ) { - /* Found a suitable mode among the predefined ones. Use that. */ - display_mode = &(display_mode_props.displayMode); - } else { - /* Can't find a suitable mode among the predefined ones, so try to create our own. */ - new_mode_parameters.visibleRegion.width = window->w; - new_mode_parameters.visibleRegion.height = window->h; - new_mode_parameters.refreshRate = 60000; /* Always use 60Hz for now. */ - display_mode_create_info.sType = VK_STRUCTURE_TYPE_DISPLAY_MODE_CREATE_INFO_KHR; - display_mode_create_info.parameters = new_mode_parameters; - result = vkCreateDisplayModeKHR(gpu, - displays_props[display_index].display, - &display_mode_create_info, - NULL, display_mode); - if (result != VK_SUCCESS) { - SDL_SetError("Vulkan couldn't find a predefined mode for that window size and couldn't create a suitable mode."); - goto clean; - } - } - - /* Just in case we get here without a display_mode. */ - if (!display_mode) { - SDL_SetError("Vulkan couldn't get a display mode."); - goto clean; - } - - /********************************************/ - /* Let's finally create the Vulkan surface! */ - /********************************************/ - - image_size.width = window->w; - image_size.height = window->h; - - display_plane_surface_create_info.sType = VK_STRUCTURE_TYPE_DISPLAY_SURFACE_CREATE_INFO_KHR; - display_plane_surface_create_info.displayMode = *display_mode; - /* For now, simply use the first plane. */ - display_plane_surface_create_info.planeIndex = 0; - display_plane_surface_create_info.imageExtent = image_size; - result = vkCreateDisplayPlaneSurfaceKHR(instance, - &display_plane_surface_create_info, - NULL, - surface); - if(result != VK_SUCCESS) - { - SDL_SetError("vkCreateDisplayPlaneSurfaceKHR failed: %s", - SDL_Vulkan_GetResultString(result)); - goto clean; - } - - ret = SDL_TRUE; - -clean: - if (physical_devices) - SDL_free (physical_devices); - if (displays_props) - SDL_free (displays_props); - if (planes_props) - SDL_free (planes_props); - if (modes_props) - SDL_free (modes_props); - - return ret; -} - -#endif - -/* vim: set ts=4 sw=4 expandtab: */ diff --git a/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_vulkan.h b/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_vulkan.h deleted file mode 100644 index a635bed1d..000000000 --- a/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_vulkan.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2021 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -/* - * @author Manuel Alfayate Corchere . - * Based on Jacob Lifshay's SDL_x11vulkan.c. - */ - -#include "../../SDL_internal.h" - -#ifndef SDL_kmsdrm_legacy_vulkan_h_ -#define SDL_kmsdrm_legacy_vulkan_h_ - -#include "../SDL_vulkan_internal.h" -#include "../SDL_sysvideo.h" - -#if SDL_VIDEO_VULKAN && SDL_VIDEO_DRIVER_KMSDRM - -int KMSDRM_LEGACY_Vulkan_LoadLibrary(_THIS, const char *path); -void KMSDRM_LEGACY_Vulkan_UnloadLibrary(_THIS); -SDL_bool KMSDRM_LEGACY_Vulkan_GetInstanceExtensions(_THIS, - SDL_Window *window, - unsigned *count, - const char **names); -void KMSDRM_LEGACY_Vulkan_GetDrawableSize(_THIS, SDL_Window *window, int *w, int *h); -SDL_bool KMSDRM_LEGACY_Vulkan_CreateSurface(_THIS, - SDL_Window *window, - VkInstance instance, - VkSurfaceKHR *surface); - -#endif - -#endif /* SDL_kmsdrm_legacy_vulkan_h_ */ - -/* vi: set ts=4 sw=4 expandtab: */