Commit 1a21922b authored by Xaver Hugl's avatar Xaver Hugl
Browse files

handle delays in drm lease messages

parent 18c0b841
Pipeline #392983 failed with stages
in 1 minute and 41 seconds
......@@ -48,8 +48,8 @@ drm_lease_handle_lease_fd(void *data,
{
struct xwl_drm_lease *lease = (struct xwl_drm_lease *)data;
lease->answered = TRUE;
lease->fd = lease_fd;
AttendClient(lease->client);
}
static void
......@@ -57,10 +57,18 @@ drm_lease_handle_finished(void *data,
struct wp_drm_lease_v1 *wp_drm_lease_v1)
{
struct xwl_drm_lease *lease = (struct xwl_drm_lease *)data;
struct xwl_output *output;
int i;
lease->answered = TRUE;
if (lease->fd >= 0)
if (lease->fd >= 0) {
RRTerminateLease(lease->rrLease);
} else {
AttendClient(lease->client);
for (i = 0; i < lease->rrLease->numOutputs; ++i) {
output = lease->rrLease->outputs[i]->devPrivate;
output->lease = NULL;
}
}
}
static struct wp_drm_lease_v1_listener drm_lease_listener = {
......@@ -68,8 +76,28 @@ static struct wp_drm_lease_v1_listener drm_lease_listener = {
.finished = drm_lease_handle_finished,
};
void
xwl_randr_get_lease(ClientPtr client, ScreenPtr screen, RRLeasePtr *rrLease, int *fd)
{
struct xwl_screen *xwl_screen;
struct xwl_drm_lease *lease;
xwl_screen = xwl_screen_get(screen);
xorg_list_for_each_entry(lease, &xwl_screen->drm_leases, link) {
if (lease->client == client) {
*rrLease = lease->rrLease;
*fd = lease->fd;
if (lease->fd < 0)
xorg_list_del(&lease->link);
return;
}
}
*rrLease = NULL;
*fd = -1;
}
int
xwl_randr_create_lease(ScreenPtr screen, RRLeasePtr rrLease, int *fd)
xwl_randr_request_lease(ClientPtr client, ScreenPtr screen, RRLeasePtr rrLease)
{
struct xwl_screen *xwl_screen;
struct wp_drm_lease_request_v1 *req;
......@@ -78,7 +106,6 @@ xwl_randr_create_lease(ScreenPtr screen, RRLeasePtr rrLease, int *fd)
struct xwl_drm_lease_device *device_data;
struct xwl_output *output;
int i;
CARD32 time;
xwl_screen = xwl_screen_get(screen);
......@@ -105,38 +132,35 @@ xwl_randr_create_lease(ScreenPtr screen, RRLeasePtr rrLease, int *fd)
}
}
req = wp_drm_lease_device_v1_create_lease_request(
lease_device->drm_lease_device);
for (i = 0; i < rrLease->numOutputs; ++i) {
output = rrLease->outputs[i]->devPrivate;
if (!output || !output->lease_connector) {
wp_drm_lease_request_v1_destroy(req);
if (!output || !output->lease_connector || output->lease) {
return BadValue;
}
wp_drm_lease_request_v1_request_connector(req, output->lease_connector);
}
req = wp_drm_lease_device_v1_create_lease_request(
lease_device->drm_lease_device);
lease_private = calloc(1, sizeof(struct xwl_drm_lease));
for (i = 0; i < rrLease->numOutputs; ++i) {
output = rrLease->outputs[i]->devPrivate;
output->lease = lease_private;
wp_drm_lease_request_v1_request_connector(req, output->lease_connector);
}
lease_private->fd = -1;
lease_private->lease = wp_drm_lease_request_v1_submit(req);
lease_private->rrLease = rrLease;
lease_private->client = client;
rrLease->devPrivate = lease_private;
wp_drm_lease_v1_add_listener(lease_private->lease,
&drm_lease_listener, lease_private);
xorg_list_add(&lease_private->link, &xwl_screen->drm_leases);
time = GetTimeInMillis();
while (!lease_private->answered && GetTimeInMillis() - time < 1000) {
/* Wait for compositor to send along some kind of response */
xwl_sync_events(xwl_screen);
}
if (lease_private->fd < 0) {
ErrorF("Did not receive lease fd from Wayland server\n");
return BadValue;
}
rrLease->devPrivate = lease_private;
ResetCurrentRequest(client);
client->sequence--;
IgnoreClient(client);
*fd = lease_private->fd;
return Success;
}
......@@ -146,6 +170,7 @@ xwl_randr_terminate_lease(ScreenPtr screen, RRLeasePtr lease)
struct xwl_drm_lease *lease_private = lease->devPrivate;
if (lease_private) {
xorg_list_del(&lease_private->link);
if (lease_private->fd >= 0)
close(lease_private->fd);
wp_drm_lease_v1_destroy(lease_private->lease);
......
......@@ -49,13 +49,15 @@ struct xwl_queued_drm_lease_device {
};
struct xwl_drm_lease {
struct xorg_list link;
struct wp_drm_lease_v1 *lease;
RRLeasePtr rrLease;
Bool answered;
ClientPtr client;
int fd;
};
int xwl_randr_create_lease(ScreenPtr screen, RRLeasePtr rrLease, int *fd);
int xwl_randr_request_lease(ClientPtr client, ScreenPtr screen, RRLeasePtr rrLease);
void xwl_randr_get_lease(ClientPtr client, ScreenPtr screen, RRLeasePtr *rrLease, int *fd);
void xwl_randr_terminate_lease(ScreenPtr screen, RRLeasePtr lease);
void xwl_screen_add_drm_lease_device(struct xwl_screen *xwl_screen, uint32_t id);
......
......@@ -854,7 +854,8 @@ xwl_screen_init_output(struct xwl_screen *xwl_screen)
rp->rrModeDestroy = xwl_randr_mode_destroy;
#endif
rp->rrCreateLease = xwl_randr_create_lease;
rp->rrRequestLease = xwl_randr_request_lease;
rp->rrGetLease = xwl_randr_get_lease;
rp->rrTerminateLease = xwl_randr_terminate_lease;
return TRUE;
......
......@@ -662,6 +662,7 @@ xwl_screen_init(ScreenPtr pScreen, int argc, char **argv)
xorg_list_init(&xwl_screen->window_list);
xorg_list_init(&xwl_screen->drm_lease_devices);
xorg_list_init(&xwl_screen->queued_drm_lease_devices);
xorg_list_init(&xwl_screen->drm_leases);
xwl_screen->depth = 24;
if (!monitorResolution)
......
......@@ -89,6 +89,7 @@ struct xwl_screen {
struct wp_viewporter *viewporter;
struct xorg_list drm_lease_devices;
struct xorg_list queued_drm_lease_devices;
struct xorg_list drm_leases;
uint32_t serial;
#define XWL_FORMAT_ARGB8888 (1 << 0)
......
......@@ -280,6 +280,15 @@ typedef int (*RRCreateLeaseProcPtr)(ScreenPtr screen,
typedef void (*RRTerminateLeaseProcPtr)(ScreenPtr screen,
RRLeasePtr lease);
typedef int (*RRRequestLeaseProcPtr)(ClientPtr client,
ScreenPtr screen,
RRLeasePtr lease);
typedef void (*RRGetLeaseProcPtr)(ClientPtr client,
ScreenPtr screen,
RRLeasePtr *lease,
int *fd);
/* These are for 1.0 compatibility */
typedef struct _rrRefresh {
......@@ -354,6 +363,8 @@ typedef struct _rrScrPriv {
RRProviderSetPropertyProcPtr rrProviderSetProperty;
RRCreateLeaseProcPtr rrCreateLease;
RRRequestLeaseProcPtr rrRequestLease;
RRGetLeaseProcPtr rrGetLease;
RRTerminateLeaseProcPtr rrTerminateLease;
/*
......
......@@ -239,9 +239,19 @@ ProcRRCreateLease(ClientPtr client)
if (!scr_priv)
return BadMatch;
if (!scr_priv->rrCreateLease)
if (!scr_priv->rrCreateLease && !scr_priv->rrRequestLease)
return BadMatch;
if (scr_priv->rrGetLease) {
scr_priv->rrGetLease(client, screen, &lease, &fd);
if (lease) {
if (fd >= 0)
goto leaseReturned;
else
goto bail_lease;
}
}
/* Allocate a structure to hold all of the lease information */
lease = RRLeaseAlloc(screen, stuff->lid, stuff->nCrtcs, stuff->nOutputs);
......@@ -291,10 +301,19 @@ ProcRRCreateLease(ClientPtr client)
lease->outputs[o] = output;
}
rc = scr_priv->rrCreateLease(screen, lease, &fd);
if (rc != Success)
goto bail_lease;
if (scr_priv->rrRequestLease) {
rc = scr_priv->rrRequestLease(client, screen, lease);
if (rc == Success)
return Success;
else
goto bail_lease;
} else {
rc = scr_priv->rrCreateLease(screen, lease, &fd);
if (rc != Success)
goto bail_lease;
}
leaseReturned:
xorg_list_add(&scr_priv->leases, &lease->list);
if (!AddResource(stuff->lid, RRLeaseType, lease)) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment