summaryrefslogtreecommitdiff
path: root/randr
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2018-02-12 13:51:56 -0800
committerAdam Jackson <ajax@redhat.com>2018-02-27 12:39:50 -0500
commite4e3447603b5fd3a38a92c3f972396d1f81168ad (patch)
tree46492faafe60037e5112d6b6702b7dc9b17987df /randr
parent023d4aba8d45e9e3630b944ecfb650c081799b96 (diff)
Add RandR leases with modesetting driver support [v6]
This adds support for RandR CRTC/Output leases through the modesetting driver, creating a lease using new kernel infrastructure and returning that to a client through an fd which will have access to only those resources. v2: Restore CRTC mode when leases terminate When a lease terminates for a crtc we have saved data for, go ahead and restore the saved mode. v3: Report RR_Rotate_0 rotations for leased crtcs. Ignore leased CRTCs when selecting screen size. Stop leasing encoders, the kernel doesn't do that anymore. Turn off crtc->enabled while leased so that modesetting ignores them. Check lease status before calling any driver mode functions When starting a lease, mark leased CRTCs as disabled and hide their cursors. Also, check to see if there are other non-leased CRTCs which are driving leased Outputs and mark them as disabled as well. Sometimes an application will lease an idle crtc instead of the one already associated with the leased output. When terminating a lease, reset any CRTCs which are driving outputs that are no longer leased so that they start working again. This required splitting the DIX level lease termination code into two pieces, one to remove the lease from the system (RRLeaseTerminated) and a new function that frees the lease data structure (RRLeaseFree). v4: Report RR_Rotate_0 rotation for leased crtcs. v5: Terminate all leases on server reset. Leases hang around after the associated client exits so that the client doesn't need to occupy an X server client slot and consume a file descriptor once it has gotten the output resources necessary. Any leases still hanging around when the X server resets or shuts down need to be cleaned up by calling the kernel to terminate the lease and freeing any DIX structures. Note that we cannot simply use the existing drmmode_terminate_lease function on each lease as that wants to also reset the video mode, and during server shut down that modesetting: Validate leases on VT enter The kernel doesn't allow any master ioctls to run when another VT is active, including simple things like listing the active leases. To deal with that, we check the list of leases whenever the X server VT is activated. xfree86: hide disabled cursors when resetting after lease termination The lessee may well have played with cursors and left one active on our screen. Just tell the kernel to turn it off. v6: Add meson build infrastructure [Also bumped libdrm requirement - ajax] Signed-off-by: Keith Packard <keithp@keithp.com> Reviewed-by: Adam Jackson <ajax@redhat.com>
Diffstat (limited to 'randr')
-rw-r--r--randr/Makefile.am1
-rw-r--r--randr/meson.build1
-rw-r--r--randr/randr.c29
-rw-r--r--randr/randrstr.h68
-rw-r--r--randr/rrcrtc.c147
-rw-r--r--randr/rrdispatch.c4
-rw-r--r--randr/rrlease.c351
-rw-r--r--randr/rrmode.c6
-rw-r--r--randr/rroutput.c138
-rw-r--r--randr/rrproperty.c6
-rw-r--r--randr/rrscreen.c2
-rw-r--r--randr/rrsdispatch.c27
12 files changed, 672 insertions, 108 deletions
diff --git a/randr/Makefile.am b/randr/Makefile.am
index 90dc9ec9a..f9cefd18a 100644
--- a/randr/Makefile.am
+++ b/randr/Makefile.am
@@ -14,6 +14,7 @@ librandr_la_SOURCES = \
rrcrtc.c \
rrdispatch.c \
rrinfo.c \
+ rrlease.c \
rrmode.c \
rrmonitor.c \
rroutput.c \
diff --git a/randr/meson.build b/randr/meson.build
index 69fab24e2..cc0e8efe9 100644
--- a/randr/meson.build
+++ b/randr/meson.build
@@ -3,6 +3,7 @@ srcs_randr = [
'rrcrtc.c',
'rrdispatch.c',
'rrinfo.c',
+ 'rrlease.c',
'rrmode.c',
'rrmonitor.c',
'rroutput.c',
diff --git a/randr/randr.c b/randr/randr.c
index 507158eb6..339ad3ece 100644
--- a/randr/randr.c
+++ b/randr/randr.c
@@ -2,6 +2,7 @@
* Copyright © 2000 Compaq Computer Corporation
* Copyright © 2002 Hewlett-Packard Company
* Copyright © 2006 Intel Corporation
+ * Copyright © 2017 Keith Packard
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
@@ -223,6 +224,19 @@ SRRResourceChangeNotifyEvent(xRRResourceChangeNotifyEvent * from,
}
static void _X_COLD
+SRRLeaseNotifyEvent(xRRLeaseNotifyEvent * from,
+ xRRLeaseNotifyEvent * to)
+{
+ to->type = from->type;
+ to->subCode = from->subCode;
+ cpswaps(from->sequenceNumber, to->sequenceNumber);
+ cpswapl(from->timestamp, to->timestamp);
+ cpswapl(from->window, to->window);
+ cpswapl(from->lease, to->lease);
+ to->created = from->created;
+}
+
+static void _X_COLD
SRRNotifyEvent(xEvent *from, xEvent *to)
{
switch (from->u.u.detail) {
@@ -249,6 +263,11 @@ SRRNotifyEvent(xEvent *from, xEvent *to)
case RRNotify_ResourceChange:
SRRResourceChangeNotifyEvent((xRRResourceChangeNotifyEvent *) from,
(xRRResourceChangeNotifyEvent *) to);
+ break;
+ case RRNotify_Lease:
+ SRRLeaseNotifyEvent((xRRLeaseNotifyEvent *) from,
+ (xRRLeaseNotifyEvent *) to);
+ break;
default:
break;
}
@@ -268,6 +287,8 @@ RRInit(void)
return FALSE;
if (!RRProviderInit())
return FALSE;
+ if (!RRLeaseInit())
+ return FALSE;
RRGeneration = serverGeneration;
}
if (!dixRegisterPrivateKey(&rrPrivKeyRec, PRIVATE_SCREEN, 0))
@@ -335,6 +356,8 @@ RRScreenInit(ScreenPtr pScreen)
pScrPriv->numCrtcs = 0;
pScrPriv->crtcs = NULL;
+ xorg_list_init(&pScrPriv->leases);
+
RRMonitorInit(pScreen);
RRNScreens += 1; /* keep count of screens that implement randr */
@@ -532,6 +555,12 @@ TellChanged(WindowPtr pWin, void *value)
RRDeliverResourceEvent(client, pWin);
}
}
+
+ if (pRREvent->mask & RRLeaseNotifyMask) {
+ if (pScrPriv->leasesChanged) {
+ RRDeliverLeaseEvent(client, pWin);
+ }
+ }
}
return WT_WALKCHILDREN;
}
diff --git a/randr/randrstr.h b/randr/randrstr.h
index b4fe833d9..f94174b54 100644
--- a/randr/randrstr.h
+++ b/randr/randrstr.h
@@ -63,6 +63,7 @@ typedef XID RRMode;
typedef XID RROutput;
typedef XID RRCrtc;
typedef XID RRProvider;
+typedef XID RRLease;
extern int RREventBase, RRErrorBase;
@@ -81,6 +82,7 @@ typedef struct _rrCrtc RRCrtcRec, *RRCrtcPtr;
typedef struct _rrOutput RROutputRec, *RROutputPtr;
typedef struct _rrProvider RRProviderRec, *RRProviderPtr;
typedef struct _rrMonitor RRMonitorRec, *RRMonitorPtr;
+typedef struct _rrLease RRLeaseRec, *RRLeasePtr;
struct _rrMode {
int refcnt;
@@ -188,6 +190,20 @@ struct _rrMonitor {
RRMonitorGeometryRec geometry;
};
+typedef enum _rrLeaseState { RRLeaseCreating, RRLeaseRunning, RRLeaseTerminating } RRLeaseState;
+
+struct _rrLease {
+ struct xorg_list list;
+ ScreenPtr screen;
+ RRLease id;
+ RRLeaseState state;
+ void *devPrivate;
+ int numCrtcs;
+ RRCrtcPtr *crtcs;
+ int numOutputs;
+ RROutputPtr *outputs;
+};
+
#if RANDR_12_INTERFACE
typedef Bool (*RRScreenSetSizeProcPtr) (ScreenPtr pScreen,
CARD16 width,
@@ -255,6 +271,15 @@ typedef Bool (*RRProviderSetOffloadSinkProcPtr)(ScreenPtr pScreen,
typedef void (*RRProviderDestroyProcPtr)(ScreenPtr pScreen,
RRProviderPtr provider);
+/* Additions for 1.6 */
+
+typedef int (*RRCreateLeaseProcPtr)(ScreenPtr screen,
+ RRLeasePtr lease,
+ int *fd);
+
+typedef void (*RRTerminateLeaseProcPtr)(ScreenPtr screen,
+ RRLeasePtr lease);
+
/* These are for 1.0 compatibility */
typedef struct _rrRefresh {
@@ -327,6 +352,10 @@ typedef struct _rrScrPriv {
RRProviderSetOffloadSinkProcPtr rrProviderSetOffloadSink;
RRProviderGetPropertyProcPtr rrProviderGetProperty;
RRProviderSetPropertyProcPtr rrProviderSetProperty;
+
+ RRCreateLeaseProcPtr rrCreateLease;
+ RRTerminateLeaseProcPtr rrTerminateLease;
+
/*
* Private part of the structure; not considered part of the ABI
*/
@@ -338,6 +367,7 @@ typedef struct _rrScrPriv {
Bool configChanged; /* configuration changed */
Bool layoutChanged; /* screen layout changed */
Bool resourcesChanged; /* screen resources change */
+ Bool leasesChanged; /* leases change */
CARD16 minWidth, minHeight;
CARD16 maxWidth, maxHeight;
@@ -377,6 +407,7 @@ typedef struct _rrScrPriv {
int numMonitors;
RRMonitorPtr *monitors;
+ struct xorg_list leases;
} rrScrPrivRec, *rrScrPrivPtr;
extern _X_EXPORT DevPrivateKeyRec rrPrivKeyRec;
@@ -420,7 +451,7 @@ extern RESTYPE RRClientType, RREventType; /* resource types for event masks
extern DevPrivateKeyRec RRClientPrivateKeyRec;
#define RRClientPrivateKey (&RRClientPrivateKeyRec)
-extern _X_EXPORT RESTYPE RRCrtcType, RRModeType, RROutputType, RRProviderType;
+extern _X_EXPORT RESTYPE RRCrtcType, RRModeType, RROutputType, RRProviderType, RRLeaseType;
#define VERIFY_RR_OUTPUT(id, ptr, a)\
{\
@@ -462,6 +493,16 @@ extern _X_EXPORT RESTYPE RRCrtcType, RRModeType, RROutputType, RRProviderType;
}\
}
+#define VERIFY_RR_LEASE(id, ptr, a)\
+ {\
+ int rc = dixLookupResourceByType((void **)&(ptr), id,\
+ RRLeaseType, client, a);\
+ if (rc != Success) {\
+ client->errorValue = id;\
+ return rc;\
+ }\
+ }
+
#define GetRRClient(pClient) ((RRClientPtr)dixLookupPrivate(&(pClient)->devPrivates, RRClientPrivateKey))
#define rrClientPriv(pClient) RRClientPtr pRRClient = GetRRClient(pClient)
@@ -772,6 +813,25 @@ void
extern _X_EXPORT Bool
RRClientKnowsRates(ClientPtr pClient);
+/* rrlease.c */
+void
+RRDeliverLeaseEvent(ClientPtr client, WindowPtr window);
+
+extern _X_EXPORT void
+RRLeaseTerminated(RRLeasePtr lease);
+
+extern _X_EXPORT void
+RRLeaseFree(RRLeasePtr lease);
+
+extern _X_EXPORT Bool
+RRCrtcIsLeased(RRCrtcPtr crtc);
+
+extern _X_EXPORT Bool
+RROutputIsLeased(RROutputPtr output);
+
+Bool
+RRLeaseInit(void);
+
/* rrmode.c */
/*
* Find, and if necessary, create a mode
@@ -1062,6 +1122,12 @@ ProcRRSetMonitor(ClientPtr client);
int
ProcRRDeleteMonitor(ClientPtr client);
+int
+ProcRRCreateLease(ClientPtr client);
+
+int
+ProcRRFreeLease(ClientPtr client);
+
#endif /* _RANDRSTR_H_ */
/*
diff --git a/randr/rrcrtc.c b/randr/rrcrtc.c
index 39af679b2..338064f9f 100644
--- a/randr/rrcrtc.c
+++ b/randr/rrcrtc.c
@@ -1075,7 +1075,7 @@ ProcRRGetCrtcInfo(ClientPtr client)
REQUEST(xRRGetCrtcInfoReq);
xRRGetCrtcInfoReply rep;
RRCrtcPtr crtc;
- CARD8 *extra;
+ CARD8 *extra = NULL;
unsigned long extraLen;
ScreenPtr pScreen;
rrScrPrivPtr pScrPriv;
@@ -1085,10 +1085,13 @@ ProcRRGetCrtcInfo(ClientPtr client)
int i, j, k;
int width, height;
BoxRec panned_area;
+ Bool leased;
REQUEST_SIZE_MATCH(xRRGetCrtcInfoReq);
VERIFY_RR_CRTC(stuff->crtc, crtc, DixReadAccess);
+ leased = RRCrtcIsLeased(crtc);
+
/* All crtcs must be associated with screens before client
* requests are processed
*/
@@ -1104,61 +1107,77 @@ ProcRRGetCrtcInfo(ClientPtr client)
.length = 0,
.timestamp = pScrPriv->lastSetTime.milliseconds
};
- if (pScrPriv->rrGetPanning &&
- pScrPriv->rrGetPanning(pScreen, crtc, &panned_area, NULL, NULL) &&
- (panned_area.x2 > panned_area.x1) && (panned_area.y2 > panned_area.y1))
- {
- rep.x = panned_area.x1;
- rep.y = panned_area.y1;
- rep.width = panned_area.x2 - panned_area.x1;
- rep.height = panned_area.y2 - panned_area.y1;
- }
- else {
- RRCrtcGetScanoutSize(crtc, &width, &height);
- rep.x = crtc->x;
- rep.y = crtc->y;
- rep.width = width;
- rep.height = height;
- }
- rep.mode = mode ? mode->mode.id : 0;
- rep.rotation = crtc->rotation;
- rep.rotations = crtc->rotations;
- rep.nOutput = crtc->numOutputs;
- k = 0;
- for (i = 0; i < pScrPriv->numOutputs; i++)
- for (j = 0; j < pScrPriv->outputs[i]->numCrtcs; j++)
- if (pScrPriv->outputs[i]->crtcs[j] == crtc)
- k++;
- rep.nPossibleOutput = k;
-
- rep.length = rep.nOutput + rep.nPossibleOutput;
-
- extraLen = rep.length << 2;
- if (extraLen) {
- extra = malloc(extraLen);
- if (!extra)
- return BadAlloc;
- }
- else
- extra = NULL;
-
- outputs = (RROutput *) extra;
- possible = (RROutput *) (outputs + rep.nOutput);
-
- for (i = 0; i < crtc->numOutputs; i++) {
- outputs[i] = crtc->outputs[i]->id;
- if (client->swapped)
- swapl(&outputs[i]);
- }
- k = 0;
- for (i = 0; i < pScrPriv->numOutputs; i++)
- for (j = 0; j < pScrPriv->outputs[i]->numCrtcs; j++)
- if (pScrPriv->outputs[i]->crtcs[j] == crtc) {
- possible[k] = pScrPriv->outputs[i]->id;
- if (client->swapped)
- swapl(&possible[k]);
- k++;
+ if (leased) {
+ rep.x = rep.y = rep.width = rep.height = 0;
+ rep.mode = 0;
+ rep.rotation = RR_Rotate_0;
+ rep.rotations = RR_Rotate_0;
+ rep.nOutput = 0;
+ rep.nPossibleOutput = 0;
+ rep.length = 0;
+ extraLen = 0;
+ } else {
+ if (pScrPriv->rrGetPanning &&
+ pScrPriv->rrGetPanning(pScreen, crtc, &panned_area, NULL, NULL) &&
+ (panned_area.x2 > panned_area.x1) && (panned_area.y2 > panned_area.y1))
+ {
+ rep.x = panned_area.x1;
+ rep.y = panned_area.y1;
+ rep.width = panned_area.x2 - panned_area.x1;
+ rep.height = panned_area.y2 - panned_area.y1;
+ }
+ else {
+ RRCrtcGetScanoutSize(crtc, &width, &height);
+ rep.x = crtc->x;
+ rep.y = crtc->y;
+ rep.width = width;
+ rep.height = height;
+ }
+ rep.mode = mode ? mode->mode.id : 0;
+ rep.rotation = crtc->rotation;
+ rep.rotations = crtc->rotations;
+ rep.nOutput = crtc->numOutputs;
+ k = 0;
+ for (i = 0; i < pScrPriv->numOutputs; i++) {
+ if (!RROutputIsLeased(pScrPriv->outputs[i])) {
+ for (j = 0; j < pScrPriv->outputs[i]->numCrtcs; j++)
+ if (pScrPriv->outputs[i]->crtcs[j] == crtc)
+ k++;
+ }
+ }
+
+ rep.nPossibleOutput = k;
+
+ rep.length = rep.nOutput + rep.nPossibleOutput;
+
+ extraLen = rep.length << 2;
+ if (extraLen) {
+ extra = malloc(extraLen);
+ if (!extra)
+ return BadAlloc;
+ }
+
+ outputs = (RROutput *) extra;
+ possible = (RROutput *) (outputs + rep.nOutput);
+
+ for (i = 0; i < crtc->numOutputs; i++) {
+ outputs[i] = crtc->outputs[i]->id;
+ if (client->swapped)
+ swapl(&outputs[i]);
+ }
+ k = 0;
+ for (i = 0; i < pScrPriv->numOutputs; i++) {
+ if (!RROutputIsLeased(pScrPriv->outputs[i])) {
+ for (j = 0; j < pScrPriv->outputs[i]->numCrtcs; j++)
+ if (pScrPriv->outputs[i]->crtcs[j] == crtc) {
+ possible[k] = pScrPriv->outputs[i]->id;
+ if (client->swapped)
+ swapl(&possible[k]);
+ k++;
+ }
}
+ }
+ }
if (client->swapped) {
swaps(&rep.sequenceNumber);
@@ -1205,6 +1224,9 @@ ProcRRSetCrtcConfig(ClientPtr client)
VERIFY_RR_CRTC(stuff->crtc, crtc, DixSetAttrAccess);
+ if (RRCrtcIsLeased(crtc))
+ return BadAccess;
+
if (stuff->mode == None) {
mode = NULL;
if (numOutputs > 0)
@@ -1231,6 +1253,12 @@ ProcRRSetCrtcConfig(ClientPtr client)
free(outputs);
return ret;
}
+
+ if (RROutputIsLeased(outputs[i])) {
+ free(outputs);
+ return BadAccess;
+ }
+
/* validate crtc for this output */
for (j = 0; j < outputs[i]->numCrtcs; j++)
if (outputs[i]->crtcs[j] == crtc)
@@ -1474,6 +1502,9 @@ ProcRRSetPanning(ClientPtr client)
REQUEST_SIZE_MATCH(xRRSetPanningReq);
VERIFY_RR_CRTC(stuff->crtc, crtc, DixReadAccess);
+ if (RRCrtcIsLeased(crtc))
+ return BadAccess;
+
/* All crtcs must be associated with screens before client
* requests are processed
*/
@@ -1614,6 +1645,9 @@ ProcRRSetCrtcGamma(ClientPtr client)
REQUEST_AT_LEAST_SIZE(xRRSetCrtcGammaReq);
VERIFY_RR_CRTC(stuff->crtc, crtc, DixReadAccess);
+ if (RRCrtcIsLeased(crtc))
+ return BadAccess;
+
len = client->req_len - bytes_to_int32(sizeof(xRRSetCrtcGammaReq));
if (len < (stuff->size * 3 + 1) >> 1)
return BadLength;
@@ -1647,6 +1681,9 @@ ProcRRSetCrtcTransform(ClientPtr client)
REQUEST_AT_LEAST_SIZE(xRRSetCrtcTransformReq);
VERIFY_RR_CRTC(stuff->crtc, crtc, DixReadAccess);
+ if (RRCrtcIsLeased(crtc))
+ return BadAccess;
+
PictTransform_from_xRenderTransform(&transform, &stuff->transform);
pixman_f_transform_from_pixman_transform(&f_transform, &transform);
if (!pixman_f_transform_invert(&f_inverse, &f_transform))
diff --git a/randr/rrdispatch.c b/randr/rrdispatch.c
index 314e4ea52..a5b390914 100644
--- a/randr/rrdispatch.c
+++ b/randr/rrdispatch.c
@@ -256,7 +256,11 @@ int (*ProcRandrVector[RRNumberRequests]) (ClientPtr) = {
ProcRRChangeProviderProperty, /* 39 */
ProcRRDeleteProviderProperty, /* 40 */
ProcRRGetProviderProperty, /* 41 */
+/* V1.5 additions */
ProcRRGetMonitors, /* 42 */
ProcRRSetMonitor, /* 43 */
ProcRRDeleteMonitor, /* 44 */
+/* V1.6 additions */
+ ProcRRCreateLease, /* 45 */
+ ProcRRFreeLease, /* 46 */
};
diff --git a/randr/rrlease.c b/randr/rrlease.c
new file mode 100644
index 000000000..b4a8827cc
--- /dev/null
+++ b/randr/rrlease.c
@@ -0,0 +1,351 @@
+/*
+ * Copyright © 2017 Keith Packard
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission. The copyright holders make no representations
+ * about the suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#include "randrstr.h"
+#include "swaprep.h"
+#include <unistd.h>
+
+RESTYPE RRLeaseType;
+
+/*
+ * Notify of some lease change
+ */
+void
+RRDeliverLeaseEvent(ClientPtr client, WindowPtr window)
+{
+ ScreenPtr screen = window->drawable.pScreen;
+ rrScrPrivPtr scr_priv = rrGetScrPriv(screen);
+ RRLeasePtr lease;
+
+ UpdateCurrentTimeIf();
+ xorg_list_for_each_entry(lease, &scr_priv->leases, list) {
+ if (lease->id != None && (lease->state == RRLeaseCreating ||
+ lease->state == RRLeaseTerminating))
+ {
+ xRRLeaseNotifyEvent le = (xRRLeaseNotifyEvent) {
+ .type = RRNotify + RREventBase,
+ .subCode = RRNotify_Lease,
+ .timestamp = currentTime.milliseconds,
+ .window = window->drawable.id,
+ .lease = lease->id,
+ .created = lease->state == RRLeaseCreating,
+ };
+ WriteEventsToClient(client, 1, (xEvent *) &le);
+ }
+ }
+}
+
+/*
+ * Change the state of a lease and let anyone watching leases know
+ */
+static void
+RRLeaseChangeState(RRLeasePtr lease, RRLeaseState old, RRLeaseState new)
+{
+ ScreenPtr screen = lease->screen;
+ rrScrPrivPtr scr_priv = rrGetScrPriv(screen);
+
+ lease->state = old;
+ scr_priv->leasesChanged = TRUE;
+ RRSetChanged(lease->screen);
+ RRTellChanged(lease->screen);
+ scr_priv->leasesChanged = FALSE;
+ lease->state = new;
+}
+
+/*
+ * Allocate and initialize a lease
+ */
+static RRLeasePtr
+RRLeaseAlloc(ScreenPtr screen, RRLease lid, int numCrtcs, int numOutputs)
+{
+ RRLeasePtr lease;
+ lease = calloc(1,
+ sizeof(RRLeaseRec) +
+ numCrtcs * sizeof (RRCrtcPtr) +
+ numOutputs * sizeof(RROutputPtr));
+ if (!lease)
+ return NULL;
+ lease->screen = screen;
+ xorg_list_init(&lease->list);
+ lease->id = lid;
+ lease->state = RRLeaseCreating;
+ lease->numCrtcs = numCrtcs;
+ lease->numOutputs = numOutputs;
+ lease->crtcs = (RRCrtcPtr *) (lease + 1);
+ lease->outputs = (RROutputPtr *) (lease->crtcs + numCrtcs);
+ return lease;
+}
+
+/*
+ * Check if a crtc is leased
+ */
+Bool
+RRCrtcIsLeased(RRCrtcPtr crtc)
+{
+ ScreenPtr screen = crtc->pScreen;
+ rrScrPrivPtr scr_priv = rrGetScrPriv(screen);
+ RRLeasePtr lease;
+ int c;
+
+ xorg_list_for_each_entry(lease, &scr_priv->leases, list) {
+ for (c = 0; c < lease->numCrtcs; c++)
+ if (lease->crtcs[c] == crtc)
+ return TRUE;
+ }
+ return FALSE;
+}
+
+/*
+ * Check if an output is leased
+ */
+Bool
+RROutputIsLeased(RROutputPtr output)
+{
+ ScreenPtr screen = output->pScreen;
+ rrScrPrivPtr scr_priv = rrGetScrPriv(screen);
+ RRLeasePtr lease;
+ int o;
+
+ xorg_list_for_each_entry(lease, &scr_priv->leases, list) {
+ for (o = 0; o < lease->numOutputs; o++)
+ if (lease->outputs[o] == output)
+ return TRUE;
+ }
+ return FALSE;
+}
+
+/*
+ * A lease has been terminated.
+ * The driver is responsible for noticing and
+ * calling this function when that happens
+ */
+
+void
+RRLeaseTerminated(RRLeasePtr lease)
+{
+ /* Notify clients with events, but only if this isn't during lease creation */
+ if (lease->state == RRLeaseRunning)
+ RRLeaseChangeState(lease, RRLeaseTerminating, RRLeaseTerminating);
+
+ if (lease->id != None)
+ FreeResource(lease->id, RT_NONE);
+
+ xorg_list_del(&lease->list);
+}
+
+/*
+ * A lease is completely shut down and is
+ * ready to be deallocated
+ */
+
+void
+RRLeaseFree(RRLeasePtr lease)
+{
+ free(lease);
+}
+
+/*
+ * Ask the driver to terminate a lease. The
+ * driver will call RRLeaseTerminated when that has
+ * finished, which may be some time after this function returns
+ * if the driver operation is asynchronous
+ */
+static void
+RRTerminateLease(RRLeasePtr lease)
+{
+ ScreenPtr screen = lease->screen;
+ rrScrPrivPtr scr_priv = rrGetScrPriv(screen);
+
+ scr_priv->rrTerminateLease(screen, lease);
+}
+
+/*
+ * Destroy a lease resource ID. All this
+ * does is note that the lease no longer has an ID, and
+ * so doesn't appear over the protocol anymore.
+ */
+static int
+RRLeaseDestroyResource(void *value, XID pid)
+{
+ RRLeasePtr lease = value;
+
+ lease->id = None;
+ return 1;
+}
+
+/*
+ * Create the lease resource type during server initialization
+ */
+Bool
+RRLeaseInit(void)
+{
+ RRLeaseType = CreateNewResourceType(RRLeaseDestroyResource, "LEASE");
+ if (!RRLeaseType)
+ return FALSE;
+ return TRUE;
+}
+
+int
+ProcRRCreateLease(ClientPtr client)
+{
+ REQUEST(xRRCreateLeaseReq);
+ xRRCreateLeaseReply rep;
+ WindowPtr window;
+ ScreenPtr screen;
+ rrScrPrivPtr scr_priv;
+ RRLeasePtr lease;
+ RRCrtc *crtcIds;
+ RROutput *outputIds;
+ int fd;
+ int rc;
+ unsigned long len;
+ int c, o;
+
+ REQUEST_AT_LEAST_SIZE(xRRCreateLeaseReq);
+
+ LEGAL_NEW_RESOURCE(stuff->lid, client);
+
+ rc = dixLookupWindow(&window, stuff->window, client, DixGetAttrAccess);
+ if (rc != Success)
+ return rc;
+
+ len = client->req_len - bytes_to_int32(sizeof(xRRCreateLeaseReq));
+
+ if (len != stuff->nCrtcs + stuff->nOutputs)
+ return BadLength;
+
+ screen = window->drawable.pScreen;
+ scr_priv = rrGetScrPriv(screen);
+
+ if (!scr_priv)
+ return BadMatch;
+
+ if (!scr_priv->rrCreateLease)
+ return BadMatch;
+
+ /* Allocate a structure to hold all of the lease information */
+
+ lease = RRLeaseAlloc(screen, stuff->lid, stuff->nCrtcs, stuff->nOutputs);
+ if (!lease)
+ return BadAlloc;
+
+ /* Look up all of the crtcs */
+ crtcIds = (RRCrtc *) (stuff + 1);
+ for (c = 0; c < stuff->nCrtcs; c++) {
+ RRCrtcPtr crtc;
+
+ rc = dixLookupResourceByType((void **)&crtc, crtcIds[c],
+ RRCrtcType, client, DixSetAttrAccess);
+
+ if (rc != Success) {
+ client->errorValue = crtcIds[c];
+ goto bail_lease;
+ }
+
+ if (RRCrtcIsLeased(crtc)) {
+ client->errorValue = crtcIds[c];
+ rc = BadAccess;
+ goto bail_lease;
+ }
+
+ lease->crtcs[c] = crtc;
+ }
+
+ /* Look up all of the outputs */
+ outputIds = (RROutput *) (crtcIds + stuff->nCrtcs);
+ for (o = 0; o < stuff->nOutputs; o++) {
+ RROutputPtr output;
+
+ rc = dixLookupResourceByType((void **)&output, outputIds[o],
+ RROutputType, client, DixSetAttrAccess);
+ if (rc != Success) {
+ client->errorValue = outputIds[o];
+ goto bail_lease;
+ }
+
+ if (RROutputIsLeased(output)) {
+ client->errorValue = outputIds[o];
+ rc = BadAccess;
+ goto bail_lease;
+ }
+
+ lease->outputs[o] = output;
+ }
+
+ rc = scr_priv->rrCreateLease(screen, lease, &fd);
+ if (rc != Success)
+ goto bail_lease;
+
+ xorg_list_add(&scr_priv->leases, &lease->list);
+
+ if (!AddResource(stuff->lid, RRLeaseType, lease)) {
+ close(fd);
+ return BadAlloc;
+ }
+
+ if (WriteFdToClient(client, fd, TRUE) < 0) {
+ RRTerminateLease(lease);
+ close(fd);
+ return BadAlloc;
+ }
+
+ RRLeaseChangeState(lease, RRLeaseCreating, RRLeaseRunning);
+
+ rep = (xRRCreateLeaseReply) {
+ .type = X_Reply,
+ .nfd = 1,
+ .sequenceNumber = client->sequence,
+ .length = 0,
+ };
+
+ if (client->swapped) {
+ swaps(&rep.sequenceNumber);
+ swapl(&rep.length);
+ }
+
+ WriteToClient(client, sizeof (rep), &rep);
+
+ return Success;
+
+bail_lease:
+ free(lease);
+ return rc;
+}
+
+int
+ProcRRFreeLease(ClientPtr client)
+{
+ REQUEST(xRRFreeLeaseReq);
+ RRLeasePtr lease;
+
+ REQUEST_SIZE_MATCH(xRRFreeLeaseReq);
+
+ VERIFY_RR_LEASE(stuff->lid, lease, DixDestroyAccess);
+
+ if (stuff->terminate)
+ RRTerminateLease(lease);
+ else
+ /* Get rid of the resource database entry */
+ FreeResource(stuff->lid, RT_NONE);
+
+ return Success;
+}
diff --git a/randr/rrmode.c b/randr/rrmode.c
index a7aa43320..d34025bd0 100644
--- a/randr/rrmode.c
+++ b/randr/rrmode.c
@@ -357,6 +357,9 @@ ProcRRAddOutputMode(ClientPtr client)
VERIFY_RR_OUTPUT(stuff->output, output, DixReadAccess);
VERIFY_RR_MODE(stuff->mode, mode, DixUseAccess);
+ if (RROutputIsLeased(output))
+ return BadAccess;
+
return RROutputAddUserMode(output, mode);
}
@@ -371,5 +374,8 @@ ProcRRDeleteOutputMode(ClientPtr client)
VERIFY_RR_OUTPUT(stuff->output, output, DixReadAccess);
VERIFY_RR_MODE(stuff->mode, mode, DixUseAccess);
+ if (RROutputIsLeased(output))
+ return BadAccess;
+
return RROutputDeleteUserMode(output, mode);
}
diff --git a/randr/rroutput.c b/randr/rroutput.c
index d5c30aded..b0ffedea8 100644
--- a/randr/rroutput.c
+++ b/randr/rroutput.c
@@ -449,66 +449,99 @@ ProcRRGetOutputInfo(ClientPtr client)
RROutput *clones;
char *name;
int i;
+ Bool leased;
REQUEST_SIZE_MATCH(xRRGetOutputInfoReq);
VERIFY_RR_OUTPUT(stuff->output, output, DixReadAccess);
+ leased = RROutputIsLeased(output);
+
pScreen = output->pScreen;
pScrPriv = rrGetScrPriv(pScreen);
- rep = (xRRGetOutputInfoReply) {
- .type = X_Reply,
- .status = RRSetConfigSuccess,
- .sequenceNumber = client->sequence,
- .length = bytes_to_int32(OutputInfoExtra),
- .timestamp = pScrPriv->lastSetTime.milliseconds,
- .crtc = output->crtc ? output->crtc->id : None,
- .mmWidth = output->mmWidth,
- .mmHeight = output->mmHeight,
- .connection = output->nonDesktop ? RR_Disconnected : output->connection,
- .connection = output->connection,
- .subpixelOrder = output->subpixelOrder,
- .nCrtcs = output->numCrtcs,
- .nModes = output->numModes + output->numUserModes,
- .nPreferred = output->numPreferred,
- .nClones = output->numClones,
- .nameLength = output->nameLength
- };
- extraLen = ((output->numCrtcs +
- output->numModes + output->numUserModes +
- output->numClones + bytes_to_int32(rep.nameLength)) << 2);
-
- if (extraLen) {
- rep.length += bytes_to_int32(extraLen);
- extra = calloc(1, extraLen);
- if (!extra)
- return BadAlloc;
- }
- else
- extra = NULL;
+ if (leased) {
+ rep = (xRRGetOutputInfoReply) {
+ .type = X_Reply,
+ .status = RRSetConfigSuccess,
+ .sequenceNumber = client->sequence,
+ .length = bytes_to_int32(OutputInfoExtra),
+ .timestamp = pScrPriv->lastSetTime.milliseconds,
+ .crtc = None,
+ .mmWidth = 0,
+ .mmHeight = 0,
+ .connection = RR_Disconnected,
+ .subpixelOrder = SubPixelUnknown,
+ .nCrtcs = 0,
+ .nModes = 0,
+ .nPreferred = 0,
+ .nClones = 0,
+ .nameLength = output->nameLength
+ };
+ extraLen = bytes_to_int32(rep.nameLength) << 2;
+ if (extraLen) {
+ rep.length += bytes_to_int32(extraLen);
+ extra = calloc(1, extraLen);
+ if (!extra)
+ return BadAlloc;
+ }
+ else
+ extra = NULL;
+
+ name = (char *) extra;
+ } else {
+ rep = (xRRGetOutputInfoReply) {
+ .type = X_Reply,
+ .status = RRSetConfigSuccess,
+ .sequenceNumber = client->sequence,
+ .length = bytes_to_int32(OutputInfoExtra),
+ .timestamp = pScrPriv->lastSetTime.milliseconds,
+ .crtc = output->crtc ? output->crtc->id : None,
+ .mmWidth = output->mmWidth,
+ .mmHeight = output->mmHeight,
+ .connection = output->nonDesktop ? RR_Disconnected : output->connection,
+ .subpixelOrder = output->subpixelOrder,
+ .nCrtcs = output->numCrtcs,
+ .nModes = output->numModes + output->numUserModes,
+ .nPreferred = output->numPreferred,
+ .nClones = output->numClones,
+ .nameLength = output->nameLength
+ };
+ extraLen = ((output->numCrtcs +
+ output->numModes + output->numUserModes +
+ output->numClones + bytes_to_int32(rep.nameLength)) << 2);
+
+ if (extraLen) {
+ rep.length += bytes_to_int32(extraLen);
+ extra = calloc(1, extraLen);
+ if (!extra)
+ return BadAlloc;
+ }
+ else
+ extra = NULL;
- crtcs = (RRCrtc *) extra;
- modes = (RRMode *) (crtcs + output->numCrtcs);
- clones = (RROutput *) (modes + output->numModes + output->numUserModes);
- name = (char *) (clones + output->numClones);
+ crtcs = (RRCrtc *) extra;
+ modes = (RRMode *) (crtcs + output->numCrtcs);
+ clones = (RROutput *) (modes + output->numModes + output->numUserModes);
+ name = (char *) (clones + output->numClones);
- for (i = 0; i < output->numCrtcs; i++) {
- crtcs[i] = output->crtcs[i]->id;
- if (client->swapped)
- swapl(&crtcs[i]);
- }
- for (i = 0; i < output->numModes + output->numUserModes; i++) {
- if (i < output->numModes)
- modes[i] = output->modes[i]->mode.id;
- else
- modes[i] = output->userModes[i - output->numModes]->mode.id;
- if (client->swapped)
- swapl(&modes[i]);
- }
- for (i = 0; i < output->numClones; i++) {
- clones[i] = output->clones[i]->id;
- if (client->swapped)
- swapl(&clones[i]);
+ for (i = 0; i < output->numCrtcs; i++) {
+ crtcs[i] = output->crtcs[i]->id;
+ if (client->swapped)
+ swapl(&crtcs[i]);
+ }
+ for (i = 0; i < output->numModes + output->numUserModes; i++) {
+ if (i < output->numModes)
+ modes[i] = output->modes[i]->mode.id;
+ else
+ modes[i] = output->userModes[i - output->numModes]->mode.id;
+ if (client->swapped)
+ swapl(&modes[i]);
+ }
+ for (i = 0; i < output->numClones; i++) {
+ clones[i] = output->clones[i]->id;
+ if (client->swapped)
+ swapl(&clones[i]);
+ }
}
memcpy(name, output->name, output->nameLength);
if (client->swapped) {
@@ -575,6 +608,9 @@ ProcRRSetOutputPrimary(ClientPtr client)
if (stuff->output) {
VERIFY_RR_OUTPUT(stuff->output, output, DixReadAccess);
+ if (RROutputIsLeased(output))
+ return BadAccess;
+
if (!output->pScreen->isGPU && output->pScreen != pWin->drawable.pScreen) {
client->errorValue = stuff->window;
return BadMatch;
diff --git a/randr/rrproperty.c b/randr/rrproperty.c
index 6598f6259..c2fb9585c 100644
--- a/randr/rrproperty.c
+++ b/randr/rrproperty.c
@@ -512,6 +512,9 @@ ProcRRConfigureOutputProperty(ClientPtr client)
VERIFY_RR_OUTPUT(stuff->output, output, DixReadAccess);
+ if (RROutputIsLeased(output))
+ return BadAccess;
+
num_valid =
stuff->length - bytes_to_int32(sizeof(xRRConfigureOutputPropertyReq));
return RRConfigureOutputProperty(output, stuff->property, stuff->pending,
@@ -582,6 +585,9 @@ ProcRRDeleteOutputProperty(ClientPtr client)
UpdateCurrentTime();
VERIFY_RR_OUTPUT(stuff->output, output, DixReadAccess);
+ if (RROutputIsLeased(output))
+ return BadAccess;
+
if (!ValidAtom(stuff->property)) {
client->errorValue = stuff->property;
return BadAtom;
diff --git a/randr/rrscreen.c b/randr/rrscreen.c
index d059ce74a..58fd47be0 100644
--- a/randr/rrscreen.c
+++ b/randr/rrscreen.c
@@ -267,7 +267,7 @@ ProcRRSetScreenSize(ClientPtr client)
RRCrtcPtr crtc = pScrPriv->crtcs[i];
RRModePtr mode = crtc->mode;
- if (mode) {
+ if (!RRCrtcIsLeased(crtc) && mode) {
int source_width = mode->mode.width;
int source_height = mode->mode.height;
Rotation rotation = crtc->rotation;
diff --git a/randr/rrsdispatch.c b/randr/rrsdispatch.c
index e0ffaa4d5..7d7b5a884 100644
--- a/randr/rrsdispatch.c
+++ b/randr/rrsdispatch.c
@@ -613,6 +613,29 @@ SProcRRDeleteMonitor(ClientPtr client) {
return ProcRandrVector[stuff->randrReqType] (client);
}
+static int _X_COLD
+SProcRRCreateLease(ClientPtr client) {
+ REQUEST(xRRCreateLeaseReq);
+
+ REQUEST_AT_LEAST_SIZE(xRRCreateLeaseReq);
+ swaps(&stuff->length);
+ swapl(&stuff->window);
+ swaps(&stuff->nCrtcs);
+ swaps(&stuff->nOutputs);
+ SwapRestL(stuff);
+ return ProcRandrVector[stuff->randrReqType] (client);
+}
+
+static int _X_COLD
+SProcRRFreeLease(ClientPtr client) {
+ REQUEST(xRRFreeLeaseReq);
+
+ REQUEST_SIZE_MATCH(xRRFreeLeaseReq);
+ swaps(&stuff->length);
+ swapl(&stuff->lid);
+ return ProcRandrVector[stuff->randrReqType] (client);
+}
+
int (*SProcRandrVector[RRNumberRequests]) (ClientPtr) = {
SProcRRQueryVersion, /* 0 */
/* we skip 1 to make old clients fail pretty immediately */
@@ -662,7 +685,11 @@ int (*SProcRandrVector[RRNumberRequests]) (ClientPtr) = {
SProcRRChangeProviderProperty, /* 39 */
SProcRRDeleteProviderProperty, /* 40 */
SProcRRGetProviderProperty, /* 41 */
+/* V1.5 additions */
SProcRRGetMonitors, /* 42 */
SProcRRSetMonitor, /* 43 */
SProcRRDeleteMonitor, /* 44 */
+/* V1.6 additions */
+ SProcRRCreateLease, /* 45 */
+ SProcRRFreeLease, /* 46 */
};