From 3edf4baf237d05966780aa8e20970f2a73651a30 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Mon, 22 Jul 2024 15:59:41 +0200 Subject: [PATCH] (submit/vrr-driver-api) dix: add generic Xinerama capable VRR infrastructure We don't have a standard protocol for enabling VRR yet, but some time ago an ad-hoc had been made in the amdgpu driver (later also copied to modsetting), which works by client setting the _VARIABLE_REFRESH window property. The way it's currently done - driver is highjacking the X_ChangeProperty and X_DeleteProperty request handlers - is pretty fragile, and is also a violation of layers: drivers never should be twisted with core protocol details. (And in the future, this should be done by some suitable extension). Another problem is Xinerama: when it's enabled, this only works on the first screen - the others won't ever see this signal, no matter on which one(s) the Window is physically placed (for the wire protocol, all windows are on screen 0, unless the client explicitly creates them on another one) This commit adds a generic Screen proc for telling the DDX, whether the VRR mode shall be changed (for now, it's only DISABLED and ENABLED). Drivers can hook into here in order to receive this signal, w/o having to highjack any core request handlers. Catching the property change is now entirely done in the DIX. The (non-standard) status qou of (ab)using window properties is kept, but it's now also easy to add a new signaling mechanism, in case a standard is agreed on. Yet a quite naive implementation (eg. not acting on moving windows between screens), but enough to fix the most pressing problems supporting extra screens in general, as well as stopping the highjacking of core request handlers by drivers. Signed-off-by: Enrico Weigelt, metux IT consult --- dix/property.c | 54 +++++++++++++++++++++++++++++++++++++++++++- include/meson.build | 1 + include/scrnintstr.h | 8 +++++++ 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/dix/property.c b/dix/property.c index 22f4d1603..8e60f2010 100644 --- a/dix/property.c +++ b/dix/property.c @@ -60,6 +60,11 @@ SOFTWARE. #include "swaprep.h" #include "xace.h" +#ifdef PANORAMIX +#include "Xext/panoramiX.h" +#include "Xext/panoramiXsrv.h" +#endif + /***************************************************************** * Property Stuff * @@ -108,6 +113,46 @@ dixLookupProperty(PropertyPtr *result, WindowPtr pWin, Atom propertyName, return rc; } +static void +setVRRMode(WindowPtr pWin, WindowVRRMode mode) +{ + SetWindowVRRModeProcPtr proc = pWin->drawable.pScreen->SetWindowVRRMode; + if (proc != NULL) + proc(pWin, mode); +} + +static void +notifyVRRMode(ClientPtr pClient, WindowPtr pWindow, int state, PropertyPtr pProp) +{ + const char *pName = NameForAtom(pProp->propertyName); + if (pName == NULL || strcmp(pName, "_VARIABLE_REFRESH") || pProp->format != 32 || pProp->size != 1) + return; + + WindowVRRMode mode = (WindowVRRMode)(state == PropertyNewValue ? (*((uint32_t*)pProp->data)) : 0); + +#ifdef PANORAMIX + if (!noPanoramiXExtension) { + PanoramiXRes *win; + int rc, j; + + rc = dixLookupResourceByType((void **) &win, pWindow->drawable.id, XRT_WINDOW, + pClient, DixWriteAccess); + if (rc != Success) + goto no_panoramix; + + FOR_NSCREENS_BACKWARD(j) { + WindowPtr pWin; + rc = dixLookupWindow(&pWin, win->info[j].id, pClient, DixSetPropAccess); + if (rc == Success) + setVRRMode(pWin, mode); + } + } + return; +no_panoramix: +#endif + setVRRMode(pWindow, mode); +} + CallbackListPtr PropertyStateCallback; static void @@ -188,6 +233,7 @@ ProcRotateProperties(ClientPtr client) for (i = 0; i < stuff->nAtoms; i++) { j = (i + delta) % stuff->nAtoms; deliverPropertyNotifyEvent(pWin, PropertyNewValue, props[i]); + notifyVRRMode(client, pWin, PropertyNewValue, props[i]); /* Preserve name and devPrivates */ props[j]->type = saved[i].type; @@ -363,8 +409,10 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property, else return rc; - if (sendevent) + if (sendevent) { deliverPropertyNotifyEvent(pWin, PropertyNewValue, pProp); + notifyVRRMode(pClient, pWin, PropertyNewValue, pProp); + } return Success; } @@ -394,6 +442,7 @@ DeleteProperty(ClientPtr client, WindowPtr pWin, Atom propName) } deliverPropertyNotifyEvent(pWin, PropertyDelete, pProp); + notifyVRRMode(client, pWin, PropertyDelete, pProp); free(pProp->data); dixFreeObjectWithPrivates(pProp, PRIVATE_PROPERTY); } @@ -530,7 +579,10 @@ ProcGetProperty(ClientPtr client) }; if (stuff->delete && (reply.bytesAfter == 0)) + { deliverPropertyNotifyEvent(pWin, PropertyDelete, pProp); + notifyVRRMode(client, pWin, PropertyDelete, pProp); + } WriteReplyToClient(client, sizeof(xGenericReply), &reply); if (len) { diff --git a/include/meson.build b/include/meson.build index 77c761862..3bc50e610 100644 --- a/include/meson.build +++ b/include/meson.build @@ -324,6 +324,7 @@ conf_data.set('SYSCONS_SUPPORT', supports_syscons ? '1' : false) conf_data.set('WSCONS_SUPPORT', supports_wscons ? '1' : false) conf_data.set('XSERVER_LIBPCIACCESS', get_option('pciaccess') ? '1' : false) conf_data.set('XSERVER_PLATFORM_BUS', build_udev_kms ? '1' : false) +conf_data.set('XSERVER_SCREEN_VRR', '1') configure_file(output : 'dix-config.h', configuration : conf_data) diff --git a/include/scrnintstr.h b/include/scrnintstr.h index 98f47bf51..f2e501aa3 100644 --- a/include/scrnintstr.h +++ b/include/scrnintstr.h @@ -90,6 +90,11 @@ typedef struct _ScreenSaverStuff { Bool /*force */ ); } ScreenSaverStuffRec; +typedef enum { + WINDOW_VRR_DISABLED = 0, + WINDOW_VRR_ENABLED, +} WindowVRRMode; + /* * There is a typedef for each screen function pointer so that code that * needs to declare a screen function pointer (e.g. in a screen private @@ -177,6 +182,8 @@ typedef void (*ClipNotifyProcPtr) (WindowPtr /*pWindow */ , int /*dx */ , int /*dy */ ); +typedef void (*SetWindowVRRModeProcPtr) (WindowPtr pWindow, WindowVRRMode mode); + /* pixmap will exist only for the duration of the current rendering operation */ #define CREATE_PIXMAP_USAGE_SCRATCH 1 /* pixmap will be the backing pixmap for a redirected window */ @@ -545,6 +552,7 @@ typedef struct _Screen { ClipNotifyProcPtr ClipNotify; RestackWindowProcPtr RestackWindow; PaintWindowProcPtr PaintWindow; + SetWindowVRRModeProcPtr SetWindowVRRMode; /* Pixmap procedures */