kdrive: Move more glamor-related stuff into kglamor

Signed-off-by: stefan11111 <stefan11111github@gmail.com>
This commit is contained in:
stefan11111 2026-09-14 00:30:18 +03:00 • committed by Enrico Weigelt
commit 859cd31e4f
14 changed files with 119 additions and 218 deletions

View file

@ -46,7 +46,6 @@ typedef struct _fakeScrPriv {
typedef struct _fakeScreenConf {
int shadow;
KdGlamorInfo glamor_info;
const char *dri_path;
} FakeScreenConf;
extern KdCardFuncs fakeFuncs;

View file

@ -5,20 +5,9 @@
#include <kdrive-config.h>
#include "present.h"
#include "Xext/present/present_priv.h" /* extern uint32_t FakeScreenFps; */
#include "fake.h"
#include "kglamor.h"
#include "glamor.h"
#ifdef WITH_LIBDRM
#include <xf86drm.h>
#endif
#include <errno.h>
Bool
fakeInitAccel(ScreenPtr pScreen)
{
@ -26,56 +15,8 @@ fakeInitAccel(ScreenPtr pScreen)
KdScreenInfo *screen = pScreenPriv->screen;
FakeScrPriv *scrpriv = screen->driver;
FakeScreenConf *config = screen->card->closure;
int caps = GLAMOR_EGL_CAP_NONE;
int has_dri3;
if (config->dri_path) {
scrpriv->dri_fd = open(config->dri_path, O_RDWR);
if (scrpriv->dri_fd >= 0) {
#ifdef WITH_LIBDRM
drmDropMaster(scrpriv->dri_fd);
#endif
} else {
LogMessage(X_WARNING, "Xfake(%d): Could not open %s: %s\n", pScreen->myNum, config->dri_path, strerror(errno));
}
} else {
scrpriv->dri_fd = -1;
}
config->glamor_info.dri_fd = scrpriv->dri_fd;
if (!KdGlamorInit(pScreen, &config->glamor_info, &caps)) {
if (scrpriv->dri_fd >= 0) {
close(scrpriv->dri_fd);
scrpriv->dri_fd = -1;
config->glamor_info.dri_fd = -1;
}
return FALSE;
}
#define GLAMOR_EGL_CAP_DRI3_IMPORT_EXPORT (GLAMOR_EGL_CAP_DRI3_IMPORT | GLAMOR_EGL_CAP_DRI3_EXPORT)
has_dri3 = (caps & GLAMOR_EGL_CAP_DRI3_IMPORT_EXPORT) == GLAMOR_EGL_CAP_DRI3_IMPORT_EXPORT;
LogMessage(X_INFO, "Xfake(%d): DRI3 %s initialized\n", pScreen->myNum, has_dri3 ? "" : "not");
#if 0 /* Not yet implemented */
LogMessage(X_INFO, "Xfake(%d): DRI3 explicit sync %s\n", pScreen->myNum,
(caps & GLAMOR_EGL_CAP_DRI3_SYNCOBJ) ?
"available" : "unavailable");
#endif
if (scrpriv->dri_fd >= 0) {
/*
* X clients use present to try to synchronize with the screen
* If no global fake rate was requested, use the highest value dix accepts (600)
*/
if (!FakeScreenFps) {
FakeScreenFps = 600;
present_screen_init(pScreen, NULL);
FakeScreenFps = 0;
}
}
return TRUE;
return KdGlamorInit(pScreen, &config->glamor_info, NULL, &scrpriv->dri_fd);
}
void

View file

@ -32,6 +32,7 @@ static FakeScreenConf *fakeCurrScreen = NULL;
static const FakeScreenConf fakeDefaultConfig = {
.shadow = -1,
.glamor_info = {.fake_rate = 600, .drop_master = TRUE,},
};
void
@ -39,7 +40,6 @@ InitCard(char *name)
{
fakeCurrScreen = XNFalloc(sizeof(*fakeCurrScreen));
*fakeCurrScreen = fakeDefaultConfig;
fakeCurrScreen->glamor_info = kdGlamorDefault;
KdCardInfoAdd(&fakeFuncs, fakeCurrScreen);
}
@ -100,7 +100,7 @@ ddxProcessArgument(int argc, char **argv, int i)
return 1;
}
glamor_arg = KdGlamorParse(&fakeCurrScreen->glamor_info, &fakeCurrScreen->dri_path, argc, argv, i);
glamor_arg = KdGlamorParse(&fakeCurrScreen->glamor_info, argc, argv, i);
if (glamor_arg) {
return glamor_arg;
}

View file

@ -4,10 +4,8 @@ srcs = [
'../../stubs/ddxBeforeReset.c',
]
fake_glamor = []
if build_glamor
srcs += 'fake_glamor.c'
fake_glamor += glamor
endif
xfake_server = executable(
@ -18,10 +16,9 @@ xfake_server = executable(
include_directories('../src'),
include_directories('../os/stub'),
],
dependencies: [ common_dep, libdrm_dep ],
dependencies: common_dep,
link_with: [
libxserver_main,
fake_glamor,
kdrive,
stub,
libxserver_fb,

View file

@ -5,20 +5,9 @@
#include <kdrive-config.h>
#include "present.h"
#include "Xext/present/present_priv.h" /* extern uint32_t FakeScreenFps; */
#include "fbdev.h"
#include "kglamor.h"
#include "glamor.h"
#ifdef WITH_LIBDRM
#include <xf86drm.h>
#endif
#include <errno.h>
Bool
fbdevInitAccel(ScreenPtr pScreen)
{
@ -26,57 +15,12 @@ fbdevInitAccel(ScreenPtr pScreen)
KdScreenInfo *screen = pScreenPriv->screen;
FbdevScrPriv *scrpriv = screen->driver;
FbScreenConf *config = screen->card->closure;
int caps = GLAMOR_EGL_CAP_NONE;
int has_dri3;
if (config->dri_path) {
scrpriv->dri_fd = open(config->dri_path, O_RDWR);
if (scrpriv->dri_fd >= 0) {
#ifdef WITH_LIBDRM
drmDropMaster(scrpriv->dri_fd);
#endif
} else {
LogMessage(X_WARNING, "Xfbdev(%d): Could not open %s: %s\n", pScreen->myNum, config->dri_path, strerror(errno));
}
} else {
scrpriv->dri_fd = -1;
if (screen->rate > 60) {
config->glamor_info.fake_rate = screen->rate;
}
config->glamor_info.dri_fd = scrpriv->dri_fd;
if (!KdGlamorInit(pScreen, &config->glamor_info, &caps)) {
if (scrpriv->dri_fd >= 0) {
close(scrpriv->dri_fd);
scrpriv->dri_fd = -1;
config->glamor_info.dri_fd = -1;
}
return FALSE;
}
#define GLAMOR_EGL_CAP_DRI3_IMPORT_EXPORT (GLAMOR_EGL_CAP_DRI3_IMPORT | GLAMOR_EGL_CAP_DRI3_EXPORT)
has_dri3 = (caps & GLAMOR_EGL_CAP_DRI3_IMPORT_EXPORT) == GLAMOR_EGL_CAP_DRI3_IMPORT_EXPORT;
LogMessage(X_INFO, "Xfbdev(%d): DRI3 %s initialized\n", pScreen->myNum, has_dri3 ? "" : "not");
#if 0 /* Not yet implemented */
LogMessage(X_INFO, "Xfbdev(%d): DRI3 explicit sync %s\n", pScreen->myNum,
(caps & GLAMOR_EGL_CAP_DRI3_SYNCOBJ) ?
"available" : "unavailable");
#endif
if (scrpriv->dri_fd >= 0) {
/*
* X clients use present to try to synchronize with the screen
* If no global fake rate was requested and the screen's rate is sane,
* use that instead of the 60 fps default
*/
if (!FakeScreenFps && (screen->rate >= 60) && (screen->rate <= 600)) {
FakeScreenFps = screen->rate;
present_screen_init(pScreen, NULL);
FakeScreenFps = 0;
}
}
return TRUE;
return KdGlamorInit(pScreen, &config->glamor_info, NULL, &scrpriv->dri_fd);
}
void

View file

@ -57,7 +57,6 @@ typedef struct _fbScreenConf {
const char *fb_path;
Bool shadow;
KdGlamorInfo glamor_info;
const char *dri_path;
} FbScreenConf;
extern KdCardFuncs fbdevFuncs;

View file

@ -36,6 +36,7 @@ static FbScreenConf *fbCurrScreen = NULL;
static const FbScreenConf fbDefaultConfig = {
.fb_path = NULL,
.shadow = TRUE,
.glamor_info = {.drop_master = TRUE,},
};
static void fbdevLogScreenInfo(const FbScreenConf *config, int screen_num);
@ -65,7 +66,6 @@ FbdevLogInit(void)
}
} else {
FbScreenConf fbDummyConfig = fbDefaultConfig;
fbDummyConfig.glamor_info = kdGlamorDefault;
fbdevLogScreenInfo(&fbDummyConfig, 0);
}
}
@ -75,7 +75,6 @@ InitCard(char *name)
{
fbCurrScreen = XNFalloc(sizeof(*fbCurrScreen));
*fbCurrScreen = fbDefaultConfig;
fbCurrScreen->glamor_info = kdGlamorDefault;
KdCardInfoAdd(&fbdevFuncs, fbCurrScreen);
}
@ -93,7 +92,7 @@ fbdevLogScreenInfo(const FbScreenConf *config, int screen_num)
config->glamor_info.glvnd ? config->glamor_info.glvnd : "not passed");
LogMessage(X_INFO, "Xfbdev(%d): dri device: %s\n", screen_num,
config->dri_path ? config->dri_path : "none");
config->glamor_info.dri_path ? config->glamor_info.dri_path : "none");
LogMessage(X_INFO, "Xfbdev(%d): glamor OpenGL contexts %s\n", screen_num,
!config->glamor_info.force_es ? "allowed" : "forbidden");
@ -173,7 +172,7 @@ ddxProcessArgument(int argc, char **argv, int i)
return 1;
}
glamor_arg = KdGlamorParse(&fbCurrScreen->glamor_info, &fbCurrScreen->dri_path, argc, argv, i);
glamor_arg = KdGlamorParse(&fbCurrScreen->glamor_info, argc, argv, i);
if (glamor_arg) {
return glamor_arg;
}

View file

@ -4,10 +4,8 @@ srcs = [
'../../stubs/ddxBeforeReset.c',
]
fbdev_glamor = []
if build_glamor
srcs += 'fb_glamor.c'
fbdev_glamor += glamor
endif
xfbdev_server = executable(
@ -18,10 +16,9 @@ xfbdev_server = executable(
include_directories('../src'),
include_directories('../os/linux'),
],
dependencies: [ common_dep, libdrm_dep ],
dependencies: common_dep,
link_with: [
libxserver_main,
fbdev_glamor,
kdrive,
linux,
libxserver_fb,

View file

@ -4,10 +4,8 @@ srcs = [
'../../stubs/ddxBeforeReset.c',
]
ms_glamor = []
if build_glamor
srcs += 'ms_glamor.c'
ms_glamor += glamor
endif
xmodesetting_server = executable(
@ -22,7 +20,6 @@ xmodesetting_server = executable(
dependencies: [ common_dep, libdrm_dep, gbm_dep ],
link_with: [
libxserver_main,
ms_glamor,
kdrive,
linux,
libxserver_fb,

View file

@ -5,75 +5,32 @@
#include <kdrive-config.h>
#include "present.h"
#include "Xext/present/present_priv.h" /* extern uint32_t FakeScreenFps; */
#include "modesetting.h"
#include "kglamor.h"
#include "glamor.h"
#include <xf86drm.h>
#include <errno.h>
Bool
msInitAccel(ScreenPtr pScreen)
{
KdScreenPriv(pScreen);
KdScreenInfo *screen = pScreenPriv->screen;
msScrPriv *scrpriv = screen->driver;
msPriv *priv = screen->card->driver;
MsScreenConf *config = screen->card->closure;
int caps = GLAMOR_EGL_CAP_NONE;
int has_dri3;
if (config->dri_path) {
scrpriv->dri_fd = open(config->dri_path, O_RDWR);
if (scrpriv->dri_fd >= 0) {
#ifdef WITH_LIBDRM
drmDropMaster(scrpriv->dri_fd);
#endif
} else {
LogMessage(X_WARNING, "Xmodesetting(%d): Could not open %s: %s\n", pScreen->myNum, config->dri_path, strerror(errno));
}
} else {
scrpriv->dri_fd = dup(gbm_device_get_fd(priv->gbm));
if (screen->rate > 60) {
config->glamor_info.fake_rate = screen->rate;
}
config->glamor_info.dri_fd = scrpriv->dri_fd;
if (!KdGlamorInit(pScreen, &config->glamor_info, &caps)) {
if (scrpriv->dri_fd >= 0) {
close(scrpriv->dri_fd);
scrpriv->dri_fd = -1;
config->glamor_info.dri_fd = -1;
}
if (!KdGlamorInit(pScreen, &config->glamor_info, &caps, &scrpriv->dri_fd)) {
return FALSE;
}
#define GLAMOR_EGL_CAP_DRI3_IMPORT_EXPORT (GLAMOR_EGL_CAP_DRI3_IMPORT | GLAMOR_EGL_CAP_DRI3_EXPORT)
has_dri3 = (caps & GLAMOR_EGL_CAP_DRI3_IMPORT_EXPORT) == GLAMOR_EGL_CAP_DRI3_IMPORT_EXPORT;
LogMessage(X_INFO, "Xmodesetting(%d): DRI3 %s initialized\n", pScreen->myNum, has_dri3 ? "" : "not");
#if 0 /* Not yet implemented */
LogMessage(X_INFO, "Xmodesetting(%d): DRI3 explicit sync %s\n", pScreen->myNum,
(caps & GLAMOR_EGL_CAP_DRI3_SYNCOBJ) ?
"available" : "unavailable");
#endif
if (scrpriv->dri_fd >= 0) {
/*
* X clients use present to try to synchronize with the screen
* If no global fake rate was requested and the screen's rate is sane,
* use that instead of the 60 fps default
*/
if (!FakeScreenFps && (screen->rate >= 60) && (screen->rate <= 600)) {
FakeScreenFps = screen->rate;
present_screen_init(pScreen, NULL);
FakeScreenFps = 0;
}
#if 0
if (caps & GLAMOR_EGL_CAP_TEXTURE_GBM_BO) {
}
#endif
return TRUE;
}

View file

@ -25,6 +25,7 @@ static MsScreenConf *msCurrScreen = NULL;
static const MsScreenConf msDefaultConfig = {
.dev_path = NULL,
.shadow = TRUE,
.glamor_info = {.use_gbm = TRUE,},
};
static void msLogScreenInfo(const MsScreenConf *config, int screen_num);
@ -54,7 +55,6 @@ msLogInit(void)
}
} else {
MsScreenConf msDummyConfig = msDefaultConfig;
msDummyConfig.glamor_info = kdGlamorDefault;
msLogScreenInfo(&msDummyConfig, 0);
}
}
@ -64,7 +64,6 @@ InitCard(char *name)
{
msCurrScreen = XNFalloc(sizeof(*msCurrScreen));
*msCurrScreen = msDefaultConfig;
msCurrScreen->glamor_info = kdGlamorDefault;
KdCardInfoAdd(&msFuncs, msCurrScreen);
}
@ -82,7 +81,7 @@ msLogScreenInfo(const MsScreenConf *config, int screen_num)
config->glamor_info.glvnd ? config->glamor_info.glvnd : "not passed");
LogMessage(X_INFO, "Xmodesetting(%d): dri device: %s\n", screen_num,
config->dri_path ? config->dri_path : "none");
config->glamor_info.dri_path ? config->glamor_info.dri_path : "none");
LogMessage(X_INFO, "Xmodesetting(%d): glamor OpenGL contexts %s\n", screen_num,
!config->glamor_info.force_es ? "allowed" : "forbidden");
@ -155,6 +154,9 @@ ddxProcessArgument(int argc, char **argv, int i)
if (!strcmp(argv[i], "-dev")) {
if ((i + 1 < argc) && (argv[i + 1][0] != '-')) {
msCurrScreen->dev_path = argv[i + 1];
if (!msCurrScreen->glamor_info.dri_path) {
msCurrScreen->glamor_info.dri_path = msCurrScreen->dev_path;
}
return 2;
}
UseMsg();
@ -166,7 +168,7 @@ ddxProcessArgument(int argc, char **argv, int i)
return 1;
}
glamor_arg = KdGlamorParse(&msCurrScreen->glamor_info, &msCurrScreen->dri_path, argc, argv, i);
glamor_arg = KdGlamorParse(&msCurrScreen->glamor_info, argc, argv, i);
if (glamor_arg) {
return glamor_arg;
}

View file

@ -11,6 +11,9 @@
#include "os/cmdline.h" /* UseMsg() */
#include "present.h"
#include "Xext/present/present_priv.h" /* extern uint32_t FakeScreenFps; */
#ifdef GLAMOR
#include "glamor.h"
#include "glamor_egl.h"
@ -24,23 +27,49 @@
#include <errno.h>
const KdGlamorInfo kdGlamorDefault = {
.glvnd = NULL,
.dri_fd = -1,
.use_gbm = FALSE,
.direct_dri3 = FALSE,
.force_gl = FALSE,
.force_es = FALSE,
.no_xv = FALSE,
.no_render_accel = FALSE,
.force_render_accel = FALSE,
};
#ifdef WITH_LIBDRM
#include <xf86drm.h>
#else
#ifdef GLAMOR
#ifdef KDRIVE_LINUX
#include <sys/ioctl.h>
#endif
#ifndef DRM_IOCTL_DROP_MASTER
#define DRM_IOCTL_DROP_MASTER 0x641f
#endif
static int
drmIoctl(int fd, unsigned long request, void *arg)
{
#ifdef KDRIVE_LINUX
int ret;
do {
ret = ioctl(fd, request, arg);
} while (ret == -1 && (errno == EINTR || errno == EAGAIN));
return ret;
#else
return -ENOSYS;
#endif
}
static int drmDropMaster(int fd)
{
return drmIoctl(fd, DRM_IOCTL_DROP_MASTER, NULL);
}
#endif
#endif
#ifdef GLAMOR
Bool
KdGlamorInit(ScreenPtr pScreen, const KdGlamorInfo *info, int *caps)
KdGlamorInit(ScreenPtr pScreen, const KdGlamorInfo *info, int *caps, int *dri_fd)
{
int flags = GLAMOR_USE_EGL_SCREEN;
int has_dri3;
int _caps;
int _dri_fd;
glamor_egl_conf_t glamor_egl_conf = {
.server_private = NULL, /* only for xf86 */
@ -48,7 +77,7 @@ KdGlamorInit(ScreenPtr pScreen, const KdGlamorInfo *info, int *caps)
.glamor_egl_priv = NULL, /* only for xf86 */
.GLAMOR_EGL_PRIV_PROC = NULL, /* only for xf86 */
.glvnd_vendor = info->glvnd,
.fd = info->dri_fd,
.fd = -1,
.gbm_forbidden = !info->use_gbm,
.direct_dri3_only = info->direct_dri3,
.auto_dri = FALSE, /* deprecated */
@ -61,10 +90,31 @@ KdGlamorInit(ScreenPtr pScreen, const KdGlamorInfo *info, int *caps)
.force_es = info->force_es,
};
if (caps) {
*caps = GLAMOR_EGL_CAP_NONE;
if (!caps) {
caps = &_caps;
}
*caps = GLAMOR_EGL_CAP_NONE;
if (!dri_fd) {
dri_fd = &_dri_fd;
}
if (info->dri_path) {
*dri_fd = open(info->dri_path, O_RDWR);
if (*dri_fd < 0) {
LogMessage(X_WARNING, "KGlamor(%d): Could not open %s: %s\n", pScreen->myNum, info->dri_path, strerror(errno));
}
} else {
*dri_fd = -1;
}
if ((*dri_fd >= 0) && info->drop_master) {
drmDropMaster(*dri_fd);
}
glamor_egl_conf.fd = *dri_fd;
if (!glamor_egl_init_internal(&glamor_egl_conf, caps)) {
return FALSE;
}
@ -80,7 +130,7 @@ KdGlamorInit(ScreenPtr pScreen, const KdGlamorInfo *info, int *caps)
}
}
if (info->dri_fd < 0) {
if (*dri_fd < 0) {
flags |= GLAMOR_NO_DRI3;
}
@ -88,12 +138,34 @@ KdGlamorInit(ScreenPtr pScreen, const KdGlamorInfo *info, int *caps)
return FALSE;
}
#define GLAMOR_EGL_CAP_DRI3_IMPORT_EXPORT (GLAMOR_EGL_CAP_DRI3_IMPORT | GLAMOR_EGL_CAP_DRI3_EXPORT)
has_dri3 = (*caps & GLAMOR_EGL_CAP_DRI3_IMPORT_EXPORT) == GLAMOR_EGL_CAP_DRI3_IMPORT_EXPORT;
LogMessage(X_INFO, "KGlamor(%d): DRI3 %s initialized\n", pScreen->myNum, has_dri3 ? "" : "not");
#if 0 /* Not yet implemented */
LogMessage(X_INFO, "KGlamor(%d): DRI3 explicit sync %s\n", pScreen->myNum,
(*caps & GLAMOR_EGL_CAP_DRI3_SYNCOBJ) ?
"available" : "unavailable");
#endif
#ifdef XV
if (!info->no_xv) {
kd_glamor_xv_init(pScreen);
}
#endif
if (info->fake_rate && (*dri_fd >= 0)) {
/*
* X clients use present to try to synchronize with the screen
* If no global fake rate was requested and a per-screen rate was requested, use that
*/
if (!FakeScreenFps) {
FakeScreenFps = info->fake_rate;
present_screen_init(pScreen, NULL);
FakeScreenFps = 0;
}
}
return TRUE;
}
@ -115,7 +187,7 @@ KdGlamorFini(ScreenPtr pScreen)
#endif
int
KdGlamorParse(KdGlamorInfo *info, const char **dri_path, int argc, char **argv, int i)
KdGlamorParse(KdGlamorInfo *info, int argc, char **argv, int i)
{
if (!strcmp(argv[i], "-glamor")) {
info->force_render_accel = TRUE;
@ -148,9 +220,7 @@ KdGlamorParse(KdGlamorInfo *info, const char **dri_path, int argc, char **argv,
if (!strcmp(argv[i], "-dri")) {
if ((i + 1 < argc) && (argv[i + 1][0] != '-')) {
if (dri_path) {
*dri_path = argv[i + 1];
}
info->dri_path = argv[i + 1];
return 2;
}
UseMsg();

View file

@ -11,29 +11,28 @@
typedef struct {
/* Passed to glamor_egl */
const char* glvnd; /* glvnd vendor library or driver name */
int dri_fd; /* /dev/dri/[cardxx|renderDxxx] */
const char* dri_path; /* /dev/dri/[cardxx|renderDxxx] */
Bool use_gbm; /* If glamor should try to use libgbm */
Bool direct_dri3; /* If glamor should only use the direct DRI3 implementation */
Bool force_gl; /* If glamor should only create desktop gl contexts */
Bool force_es; /* If glamor should only create gles contexts */
/* Handled by KdGlamorInit */
int fake_rate; /* If a fake refresh rate should be used by present */
Bool drop_master; /* If KdGlamorInit should call drmDropMaster on the dri fd */
Bool no_xv; /* Disable X-Video support */
Bool no_render_accel; /* Disable render acceleration */
Bool force_render_accel; /* Enable render acceleration on top of sw renderers */
} KdGlamorInfo;
/* A sane default config for KdGlamorInit */
extern const KdGlamorInfo kdGlamorDefault;
#ifdef GLAMOR
Bool KdGlamorInit(ScreenPtr pScreen, const KdGlamorInfo *info, int *caps);
Bool KdGlamorInit(ScreenPtr pScreen, const KdGlamorInfo *info, int *caps, int *dri_fd);
void KdGlamorEnable(ScreenPtr pScreen);
void KdGlamorDisable(ScreenPtr pScreen);
void KdGlamorFini(ScreenPtr pScreen);
#endif
int KdGlamorParse(KdGlamorInfo *info, const char **dri, int argc, char **argv, int i);
int KdGlamorParse(KdGlamorInfo *info, int argc, char **argv, int i);
void KdGlamorUseMsg(void);
/* Put each screen on a different card */

View file

@ -37,7 +37,7 @@ configure_file(input : 'kdrive-config.h.meson.in',
kdrive = static_library('kdrive',
srcs_kdrive,
include_directories: inc,
dependencies: common_dep,
dependencies: [ common_dep, libdrm_dep ],
link_with: [
libxserver_miext_shadow,
kdrive_glamor,