mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-05-20 20:46:02 +08:00
Potential fix for bug 5393 - KMSDRM: using atomic mode setting breaks GPU compatibility
Substring I was trying the KMSDRM video backend with some very simple programs that were working ok on 2.0.12. The same code won?t work on the current dev branch and I get: DEBUG: check_modesetting: probing ?/dev/dri/card0? DEBUG: /dev/dri/card0 connector, encoder and CRTC counts are: 4 5 6 DEBUG: check_modesetting: probing ?/dev/dri/card0? DEBUG: /dev/dri/card0 connector, encoder and CRTC counts are: 4 5 6 DEBUG: KMSDRM_VideoInit() DEBUG: Opening device /dev/dri/card0 DEBUG: Opened DRM FD (3) DEBUG: no atomic modesetting support. DEBUG: Video subsystem has not been initialized INFO: Using SDL video driver: (null) DEBUG: Video subsystem has not been initialized After carefully checking, the radeon driver doesn?t support atomic modesetting. That?s not the only problem : the same happens with the amdgpu driver if we disable Display Core (kernel parameter amdgpu.dc=0, which is required to get analogue outputs working). This is a major regression in the KMSDRM driver. Using atomic mode setting is great, but having no fallback to the "standard KMS" is bad.
This commit is contained in:
@@ -1163,7 +1163,8 @@ macro(CheckKMSDRM)
|
||||
set(HAVE_SDL_VIDEO TRUE)
|
||||
|
||||
file(GLOB KMSDRM_SOURCES ${SDL2_SOURCE_DIR}/src/video/kmsdrm/*.c)
|
||||
set(SOURCE_FILES ${SOURCE_FILES} ${KMSDRM_SOURCES})
|
||||
file(GLOB KMSDRM_LEGACY_SOURCES ${SDL2_SOURCE_DIR}/src/video/kmsdrm_legacy/*.c)
|
||||
set(SOURCE_FILES ${SOURCE_FILES} ${KMSDRM_SOURCES} ${KMSDRM_LEGACY_SOURCES})
|
||||
|
||||
list(APPEND EXTRA_CFLAGS ${KMSDRM_CFLAGS})
|
||||
|
||||
|
||||
@@ -22119,6 +22119,7 @@ fi
|
||||
$as_echo "#define SDL_VIDEO_DRIVER_KMSDRM 1" >>confdefs.h
|
||||
|
||||
SOURCES="$SOURCES $srcdir/src/video/kmsdrm/*.c"
|
||||
SOURCES="$SOURCES $srcdir/src/video/kmsdrm_legacy/*.c"
|
||||
EXTRA_CFLAGS="$EXTRA_CFLAGS $LIBDRM_CFLAGS $LIBGBM_CFLAGS"
|
||||
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for kmsdrm dynamic loading support" >&5
|
||||
|
||||
@@ -2253,6 +2253,7 @@ AS_HELP_STRING([--enable-kmsdrm-shared], [dynamically load kmsdrm support [[defa
|
||||
|
||||
AC_DEFINE(SDL_VIDEO_DRIVER_KMSDRM, 1, [ ])
|
||||
SOURCES="$SOURCES $srcdir/src/video/kmsdrm/*.c"
|
||||
SOURCES="$SOURCES $srcdir/src/video/kmsdrm_legacy/*.c"
|
||||
EXTRA_CFLAGS="$EXTRA_CFLAGS $LIBDRM_CFLAGS $LIBGBM_CFLAGS"
|
||||
|
||||
AC_MSG_CHECKING(for kmsdrm dynamic loading support)
|
||||
|
||||
@@ -429,6 +429,7 @@ extern VideoBootStrap Android_bootstrap;
|
||||
extern VideoBootStrap PSP_bootstrap;
|
||||
extern VideoBootStrap RPI_bootstrap;
|
||||
extern VideoBootStrap KMSDRM_bootstrap;
|
||||
extern VideoBootStrap KMSDRM_LEGACY_bootstrap;
|
||||
extern VideoBootStrap DUMMY_bootstrap;
|
||||
extern VideoBootStrap Wayland_bootstrap;
|
||||
extern VideoBootStrap NACL_bootstrap;
|
||||
|
||||
@@ -96,6 +96,7 @@ static VideoBootStrap *bootstrap[] = {
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_KMSDRM
|
||||
&KMSDRM_bootstrap,
|
||||
&KMSDRM_LEGACY_bootstrap,
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_RPI
|
||||
&RPI_bootstrap,
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
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_HAVE_##modname = 0;
|
||||
#define SDL_KMSDRM_LEGACY_SYM(rc,fn,params) SDL_DYNKMSDRMFN_##fn KMSDRM_##fn = NULL;
|
||||
#define SDL_KMSDRM_LEGACY_SYM_CONST(type,name) SDL_DYNKMSDRMCONST_##name KMSDRM_##name = NULL;
|
||||
#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_HAVE_##modname = 0;
|
||||
#define SDL_KMSDRM_LEGACY_SYM(rc,fn,params) KMSDRM_##fn = NULL;
|
||||
#define SDL_KMSDRM_LEGACY_SYM_CONST(type,name) KMSDRM_##name = NULL;
|
||||
#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_HAVE_##modname = 1; /* default yes */
|
||||
#include "SDL_kmsdrm_legacy_sym.h"
|
||||
|
||||
#define SDL_KMSDRM_LEGACY_MODULE(modname) thismod = &SDL_KMSDRM_HAVE_##modname;
|
||||
#define SDL_KMSDRM_LEGACY_SYM(rc,fn,params) KMSDRM_##fn = (SDL_DYNKMSDRMFN_##fn) KMSDRM_GetSym(#fn,thismod);
|
||||
#define SDL_KMSDRM_LEGACY_SYM_CONST(type,name) KMSDRM_##name = *(SDL_DYNKMSDRMCONST_##name*) KMSDRM_GetSym(#name,thismod);
|
||||
#include "SDL_kmsdrm_legacy_sym.h"
|
||||
|
||||
if ((SDL_KMSDRM_LEGACY_HAVE_LIBDRM) && (SDL_KMSDRM_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_HAVE_##modname = 1; /* default yes */
|
||||
#define SDL_KMSDRM_LEGACY_SYM(rc,fn,params) KMSDRM_##fn = fn;
|
||||
#define SDL_KMSDRM_LEGACY_SYM_CONST(type,name) KMSDRM_##name = name;
|
||||
#include "SDL_kmsdrm_legacy_sym.h"
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_KMSDRM */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
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 <xf86drm.h>
|
||||
#include <xf86drmMode.h>
|
||||
#include <gbm.h>
|
||||
|
||||
#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_##fn;
|
||||
#define SDL_KMSDRM_LEGACY_SYM_CONST(type, name) \
|
||||
typedef type SDL_DYNKMSDRM_LEGACYCONST_##name; \
|
||||
extern SDL_DYNKMSDRM_LEGACYCONST_##name KMSDRM_##name;
|
||||
#include "SDL_kmsdrm_legacy_sym.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SDL_kmsdrmdyn_h_ */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
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 */
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
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_ */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
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 <gbm.h>
|
||||
|
||||
#define MAX_CURSOR_W 512
|
||||
#define MAX_CURSOR_H 512
|
||||
|
||||
typedef struct _KMSDRM_LEGACY_CursorData
|
||||
{
|
||||
struct gbm_bo *bo;
|
||||
uint32_t crtc_id;
|
||||
int hot_x, hot_y;
|
||||
int w, h;
|
||||
} KMSDRM_LEGACY_CursorData;
|
||||
|
||||
extern void KMSDRM_LEGACY_InitMouse(_THIS);
|
||||
extern void KMSDRM_LEGACY_QuitMouse(_THIS);
|
||||
|
||||
#endif /* SDL_KMSDRM_LEGACY_mouse_h_ */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
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_VIDEO_OPENGL_EGL
|
||||
|
||||
#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 */
|
||||
|
||||
int
|
||||
KMSDRM_LEGACY_GLES_LoadLibrary(_THIS, const char *path) {
|
||||
NativeDisplayType display = (NativeDisplayType)((SDL_VideoData *)_this->driverdata)->gbm;
|
||||
return SDL_EGL_LoadLibrary(_this, path, display, EGL_PLATFORM_GBM_MESA);
|
||||
}
|
||||
|
||||
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->curr_bo) {
|
||||
KMSDRM_LEGACY_gbm_surface_release_buffer(windata->gs, windata->curr_bo);
|
||||
/* SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "Released GBM surface %p", (void *)windata->curr_bo); */
|
||||
windata->curr_bo = NULL;
|
||||
}
|
||||
|
||||
windata->curr_bo = windata->next_bo;
|
||||
|
||||
/* Make the current back buffer the next front buffer */
|
||||
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;
|
||||
/* } else {
|
||||
SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "Locked GBM surface %p", (void *)windata->next_bo); */
|
||||
}
|
||||
|
||||
fb_info = KMSDRM_LEGACY_FBFromBO(_this, windata->next_bo);
|
||||
if (!fb_info) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!windata->curr_bo) {
|
||||
/* On the first swap, immediately present the new front buffer. Before
|
||||
drmModePageFlip can be used the CRTC has to be configured to use
|
||||
the current connector and mode with drmModeSetCrtc */
|
||||
ret = KMSDRM_LEGACY_drmModeSetCrtc(viddata->drm_fd, dispdata->crtc_id, fb_info->fb_id, 0,
|
||||
0, &dispdata->conn->connector_id, 1, &dispdata->mode);
|
||||
|
||||
if (ret) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not configure CRTC");
|
||||
}
|
||||
} else {
|
||||
/* On subsequent swaps, queue the new front buffer to be flipped during
|
||||
the next vertical blank */
|
||||
ret = KMSDRM_LEGACY_drmModePageFlip(viddata->drm_fd, dispdata->crtc_id, fb_info->fb_id,
|
||||
DRM_MODE_PAGE_FLIP_EVENT, &windata->waiting_for_flip);
|
||||
/* SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "drmModePageFlip(%d, %u, %u, DRM_MODE_PAGE_FLIP_EVENT, &windata->waiting_for_flip)",
|
||||
viddata->drm_fd, displaydata->crtc_id, fb_info->fb_id); */
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/* Wait immediately for vsync (as if we only had two buffers), for low input-lag scenarios.
|
||||
Run your SDL2 program with "SDL_KMSDRM_LEGACY_DOUBLE_BUFFER=1 <program_name>" 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 && SDL_VIDEO_OPENGL_EGL */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
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 && SDL_VIDEO_OPENGL_EGL
|
||||
|
||||
#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_UnloadLibrary SDL_EGL_UnloadLibrary
|
||||
#define KMSDRM_LEGACY_GLES_DeleteContext SDL_EGL_DeleteContext
|
||||
#define KMSDRM_LEGACY_GLES_GetSwapInterval SDL_EGL_GetSwapInterval
|
||||
|
||||
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 && SDL_VIDEO_OPENGL_EGL */
|
||||
|
||||
#endif /* SDL_kmsdrmopengles_h_ */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
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(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))
|
||||
|
||||
|
||||
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: */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
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 <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <xf86drm.h>
|
||||
#include <xf86drmMode.h>
|
||||
#include <gbm.h>
|
||||
#if SDL_VIDEO_OPENGL_EGL
|
||||
#include <EGL/egl.h>
|
||||
#endif
|
||||
|
||||
typedef struct SDL_VideoData
|
||||
{
|
||||
int devindex; /* device index that was passed on creation */
|
||||
int drm_fd; /* DRM file desc */
|
||||
struct gbm_device *gbm;
|
||||
|
||||
SDL_Window **windows;
|
||||
int max_windows;
|
||||
int num_windows;
|
||||
} SDL_VideoData;
|
||||
|
||||
|
||||
typedef struct SDL_DisplayModeData
|
||||
{
|
||||
int mode_index;
|
||||
} SDL_DisplayModeData;
|
||||
|
||||
|
||||
typedef struct SDL_DisplayData
|
||||
{
|
||||
uint32_t crtc_id;
|
||||
drmModeConnector *conn;
|
||||
drmModeModeInfo mode;
|
||||
drmModeCrtc *saved_crtc; /* CRTC to restore on quit */
|
||||
} SDL_DisplayData;
|
||||
|
||||
|
||||
typedef struct SDL_WindowData
|
||||
{
|
||||
SDL_VideoData *viddata;
|
||||
struct gbm_surface *gs;
|
||||
struct gbm_bo *curr_bo;
|
||||
struct gbm_bo *next_bo;
|
||||
struct gbm_bo *crtc_bo;
|
||||
SDL_bool waiting_for_flip;
|
||||
SDL_bool double_buffer;
|
||||
#if SDL_VIDEO_OPENGL_EGL
|
||||
int egl_surface_dirty;
|
||||
EGLSurface egl_surface;
|
||||
#endif
|
||||
} 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_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_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: */
|
||||
Reference in New Issue
Block a user