From b943cfe2afbd593e814de47b2f13f8b3b1af78da Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Tue, 7 Jun 2016 10:14:50 +0200 Subject: Drop trailing whitespaces (randr extension) sed -i "s/[ ]\+$//g" randr/*.{c,h} happy reviewing... git diff -w is an empty diff. --- nx-X11/programs/Xserver/randr/rrscreen.c | 84 ++++++++++++++++---------------- 1 file changed, 42 insertions(+), 42 deletions(-) (limited to 'nx-X11/programs/Xserver/randr/rrscreen.c') diff --git a/nx-X11/programs/Xserver/randr/rrscreen.c b/nx-X11/programs/Xserver/randr/rrscreen.c index 70a9be0c6..a13b01dcb 100644 --- a/nx-X11/programs/Xserver/randr/rrscreen.c +++ b/nx-X11/programs/Xserver/randr/rrscreen.c @@ -71,7 +71,7 @@ RREditConnectionInfo (ScreenPtr pScreen) sizeof (xPixmapFormat) * screenInfo.numPixmapFormats); while (screen != pScreen->myNum) { - depth = (xDepth *) ((char *) root + + depth = (xDepth *) ((char *) root + sizeof (xWindowRoot)); for (d = 0; d < root->nDepths; d++) { @@ -102,7 +102,7 @@ RRSendConfigNotify (ScreenPtr pScreen) event.u.configureNotify.y = 0; /* XXX xinerama stuff ? */ - + event.u.configureNotify.width = pWin->drawable.width; event.u.configureNotify.height = pWin->drawable.height; event.u.configureNotify.borderWidth = wBorderWidth (pWin); @@ -117,7 +117,7 @@ RRDeliverScreenEvent (ClientPtr client, WindowPtr pWin, ScreenPtr pScreen) xRRScreenChangeNotifyEvent se; RRCrtcPtr crtc = pScrPriv->numCrtcs ? pScrPriv->crtcs[0] : NULL; WindowPtr pRoot = WindowTable[pScreen->myNum]; - + se.type = RRScreenChangeNotify + RREventBase; se.rotation = (CARD8) (crtc ? crtc->rotation : RR_Rotate_0); se.timestamp = pScrPriv->lastSetTime.milliseconds; @@ -167,7 +167,7 @@ RRScreenSizeNotify (ScreenPtr pScreen) pScrPriv->mmWidth == pScreen->mmWidth && pScrPriv->mmHeight == pScreen->mmHeight) return; - + pScrPriv->width = pScreen->width; pScrPriv->height = pScreen->height; pScrPriv->mmWidth = pScreen->mmWidth; @@ -178,7 +178,7 @@ RRScreenSizeNotify (ScreenPtr pScreen) RRTellChanged (pScreen); RRSendConfigNotify (pScreen); RREditConnectionInfo (pScreen); - + RRPointerScreenConfigured (pScreen); /* * Fix pointer bounds and location @@ -218,7 +218,7 @@ RRScreenSizeSet (ScreenPtr pScreen, /* * Retrieve valid screen size range */ -int +int ProcRRGetScreenSizeRange (ClientPtr client) { REQUEST(xRRGetScreenSizeRangeReq); @@ -227,7 +227,7 @@ ProcRRGetScreenSizeRange (ClientPtr client) ScreenPtr pScreen; rrScrPrivPtr pScrPriv; int rc; - + REQUEST_SIZE_MATCH(xRRGetScreenSizeRangeReq); #ifndef NXAGENT_SERVER rc = dixLookupWindow(&pWin, stuff->window, client, DixReadAccess); @@ -240,13 +240,13 @@ ProcRRGetScreenSizeRange (ClientPtr client) pScreen = pWin->drawable.pScreen; pScrPriv = rrGetScrPriv(pScreen); - + rep.type = X_Reply; rep.pad = 0; rep.sequenceNumber = client->sequence; rep.length = 0; - - if (pScrPriv) + + if (pScrPriv) { if (!RRGetInfo (pScreen)) return BadAlloc; @@ -260,7 +260,7 @@ ProcRRGetScreenSizeRange (ClientPtr client) rep.maxWidth = rep.minWidth = pScreen->width; rep.maxHeight = rep.minHeight = pScreen->height; } - if (client->swapped) + if (client->swapped) { int n; @@ -283,7 +283,7 @@ ProcRRSetScreenSize (ClientPtr client) ScreenPtr pScreen; rrScrPrivPtr pScrPriv; int i, rc; - + REQUEST_SIZE_MATCH(xRRSetScreenSizeReq); #ifndef NXAGENT_SERVER rc = dixLookupWindow(&pWin, stuff->window, client, DixReadAccess); @@ -301,13 +301,13 @@ ProcRRSetScreenSize (ClientPtr client) client->errorValue = stuff->width; return BadValue; } - if (stuff->height < pScrPriv->minHeight || + if (stuff->height < pScrPriv->minHeight || pScrPriv->maxHeight < stuff->height) { client->errorValue = stuff->height; return BadValue; } - for (i = 0; i < pScrPriv->numCrtcs; i++) + for (i = 0; i < pScrPriv->numCrtcs; i++) { RRCrtcPtr crtc = pScrPriv->crtcs[i]; RRModePtr mode = crtc->mode; @@ -322,7 +322,7 @@ ProcRRSetScreenSize (ClientPtr client) source_width = mode->mode.height; source_height = mode->mode.width; } - + if (crtc->x + source_width > stuff->width || crtc->y + source_height > stuff->height) return BadMatch; @@ -333,7 +333,7 @@ ProcRRSetScreenSize (ClientPtr client) client->errorValue = 0; return BadValue; } - if (!RRScreenSizeSet (pScreen, + if (!RRScreenSizeSet (pScreen, stuff->width, stuff->height, stuff->widthInMillimeters, stuff->heightInMillimeters)) @@ -358,7 +358,7 @@ ProcRRGetScreenResources (ClientPtr client) RROutput *outputs; xRRModeInfo *modeinfos; CARD8 *names; - + REQUEST_SIZE_MATCH(xRRGetScreenResourcesReq); #ifndef NXAGENT_SERVER rc = dixLookupWindow(&pWin, stuff->window, client, DixReadAccess); @@ -368,11 +368,11 @@ ProcRRGetScreenResources (ClientPtr client) #endif if (rc != Success) return rc; - + pScreen = pWin->drawable.pScreen; pScrPriv = rrGetScrPriv(pScreen); rep.pad = 0; - + if (pScrPriv) if (!RRGetInfo (pScreen)) return BadAlloc; @@ -413,8 +413,8 @@ ProcRRGetScreenResources (ClientPtr client) for (i = 0; i < num_modes; i++) rep.nbytesNames += modes[i]->mode.nameLength; - rep.length = (pScrPriv->numCrtcs + - pScrPriv->numOutputs + + rep.length = (pScrPriv->numCrtcs + + pScrPriv->numOutputs + num_modes * (SIZEOF(xRRModeInfo) >> 2) + ((rep.nbytesNames + 3) >> 2)); @@ -470,14 +470,14 @@ ProcRRGetScreenResources (ClientPtr client) swaps (&modeinfos[i].nameLength, n); swapl (&modeinfos[i].modeFlags, n); } - memcpy (names, mode->name, + memcpy (names, mode->name, mode->mode.nameLength); names += mode->mode.nameLength; } xfree (modes); assert (((((char *) names - (char *) extra) + 3) >> 2) == rep.length); } - + if (client->swapped) { swaps(&rep.sequenceNumber, n); swapl(&rep.length, n); @@ -521,8 +521,8 @@ RR10GetData (ScreenPtr pScreen, RROutputPtr output) Bool *used; /* Make sure there is plenty of space for any combination */ - data = malloc (sizeof (RR10DataRec) + - sizeof (RRScreenSize) * nmode + + data = malloc (sizeof (RR10DataRec) + + sizeof (RRScreenSize) * nmode + sizeof (RRScreenRate) * nmode + sizeof (Bool) * nmode); if (!data) @@ -536,7 +536,7 @@ RR10GetData (ScreenPtr pScreen, RROutputPtr output) data->nrefresh = 0; data->size = 0; data->refresh = 0; - + /* * find modes not yet listed */ @@ -626,13 +626,13 @@ ProcRRGetScreenInfo (ClientPtr client) pScreen = pWin->drawable.pScreen; pScrPriv = rrGetScrPriv(pScreen); rep.pad = 0; - + if (pScrPriv) if (!RRGetInfo (pScreen)) return BadAlloc; output = RRFirstOutput (pScreen); - + if (!pScrPriv || !output) { rep.type = X_Reply; @@ -659,7 +659,7 @@ ProcRRGetScreenInfo (ClientPtr client) Bool has_rate = RRClientKnowsRates (client); RR10DataPtr pData; RRScreenSizePtr pSize; - + pData = RR10GetData (pScreen, output); if (!pData) return BadAlloc; @@ -781,7 +781,7 @@ ProcRRSetScreenConfig (ClientPtr client) RR10DataPtr pData = NULL; RRScreenSizePtr pSize; int width, height; - + UpdateCurrentTime (); if (RRClientKnowsRates (client)) @@ -794,7 +794,7 @@ ProcRRSetScreenConfig (ClientPtr client) REQUEST_SIZE_MATCH (xRR1_0SetScreenConfigReq); has_rate = FALSE; } - + #ifndef NXAGENT_SERVER rc = dixLookupDrawable(&pDraw, stuff->drawable, client, 0, DixWriteAccess); #else @@ -807,9 +807,9 @@ ProcRRSetScreenConfig (ClientPtr client) pScreen = pDraw->pScreen; pScrPriv = rrGetScrPriv(pScreen); - + time = ClientTimeToServerTime(stuff->timestamp); - + if (!pScrPriv) { time = currentTime; @@ -818,7 +818,7 @@ ProcRRSetScreenConfig (ClientPtr client) } if (!RRGetInfo (pScreen)) return BadAlloc; - + output = RRFirstOutput (pScreen); if (!output) { @@ -843,11 +843,11 @@ ProcRRSetScreenConfig (ClientPtr client) rep.status = RRSetConfigInvalidConfigTime; goto sendReply; } - + pData = RR10GetData (pScreen, output); if (!pData) return BadAlloc; - + if (stuff->sizeID >= pData->nsize) { /* @@ -858,7 +858,7 @@ ProcRRSetScreenConfig (ClientPtr client) return BadValue; } pSize = &pData->sizes[stuff->sizeID]; - + /* * Validate requested rotation */ @@ -918,7 +918,7 @@ ProcRRSetScreenConfig (ClientPtr client) } else mode = pSize->pRates[0].mode; - + /* * Make sure the requested set-time is not older than * the last set-time @@ -985,9 +985,9 @@ ProcRRSetScreenConfig (ClientPtr client) /* * XXX Configure other crtcs to mirror as much as possible */ - + sendReply: - + if (pData) xfree (pData); @@ -1000,7 +1000,7 @@ sendReply: rep.newConfigTimestamp = pScrPriv->lastConfigTime.milliseconds; rep.root = WindowTable[pDraw->pScreen->myNum]->drawable.id; - if (client->swapped) + if (client->swapped) { swaps(&rep.sequenceNumber, n); swapl(&rep.length, n); @@ -1018,7 +1018,7 @@ RR10CurrentSizeID (ScreenPtr pScreen) { CARD16 sizeID = 0xffff; RROutputPtr output = RRFirstOutput (pScreen); - + if (output) { RR10DataPtr data = RR10GetData (pScreen, output); -- cgit v1.2.3 From e440ea768d004ca83993dfb5774daa7971d90c10 Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Tue, 7 Jun 2016 10:26:58 +0200 Subject: randr extension: Convert to Xorg coding style. The reformatting has been achieved by applying x-indent.sh to all .c and .h files in Xserver/randr/. --- nx-X11/programs/Xserver/randr/rrscreen.c | 1272 ++++++++++++++---------------- 1 file changed, 607 insertions(+), 665 deletions(-) (limited to 'nx-X11/programs/Xserver/randr/rrscreen.c') diff --git a/nx-X11/programs/Xserver/randr/rrscreen.c b/nx-X11/programs/Xserver/randr/rrscreen.c index a13b01dcb..458416c1f 100644 --- a/nx-X11/programs/Xserver/randr/rrscreen.c +++ b/nx-X11/programs/Xserver/randr/rrscreen.c @@ -39,49 +39,46 @@ #include "randrstr.h" -extern char *ConnectionInfo; +extern char *ConnectionInfo; -static int padlength[4] = {0, 3, 2, 1}; +static int padlength[4] = { 0, 3, 2, 1 }; static CARD16 -RR10CurrentSizeID (ScreenPtr pScreen); + RR10CurrentSizeID(ScreenPtr pScreen); /* * Edit connection information block so that new clients * see the current screen size on connect */ static void -RREditConnectionInfo (ScreenPtr pScreen) +RREditConnectionInfo(ScreenPtr pScreen) { - xConnSetup *connSetup; - char *vendor; - xPixmapFormat *formats; - xWindowRoot *root; - xDepth *depth; - xVisualType *visual; - int screen = 0; - int d; + xConnSetup *connSetup; + char *vendor; + xPixmapFormat *formats; + xWindowRoot *root; + xDepth *depth; + xVisualType *visual; + int screen = 0; + int d; connSetup = (xConnSetup *) ConnectionInfo; - vendor = (char *) connSetup + sizeof (xConnSetup); + vendor = (char *) connSetup + sizeof(xConnSetup); formats = (xPixmapFormat *) ((char *) vendor + - connSetup->nbytesVendor + - padlength[connSetup->nbytesVendor & 3]); + connSetup->nbytesVendor + + padlength[connSetup->nbytesVendor & 3]); root = (xWindowRoot *) ((char *) formats + - sizeof (xPixmapFormat) * screenInfo.numPixmapFormats); - while (screen != pScreen->myNum) - { - depth = (xDepth *) ((char *) root + - sizeof (xWindowRoot)); - for (d = 0; d < root->nDepths; d++) - { - visual = (xVisualType *) ((char *) depth + - sizeof (xDepth)); - depth = (xDepth *) ((char *) visual + - depth->nVisuals * sizeof (xVisualType)); - } - root = (xWindowRoot *) ((char *) depth); - screen++; + sizeof(xPixmapFormat) * + screenInfo.numPixmapFormats); + while (screen != pScreen->myNum) { + depth = (xDepth *) ((char *) root + sizeof(xWindowRoot)); + for (d = 0; d < root->nDepths; d++) { + visual = (xVisualType *) ((char *) depth + sizeof(xDepth)); + depth = (xDepth *) ((char *) visual + + depth->nVisuals * sizeof(xVisualType)); + } + root = (xWindowRoot *) ((char *) depth); + screen++; } root->pixWidth = pScreen->width; root->pixHeight = pScreen->height; @@ -90,10 +87,10 @@ RREditConnectionInfo (ScreenPtr pScreen) } void -RRSendConfigNotify (ScreenPtr pScreen) +RRSendConfigNotify(ScreenPtr pScreen) { - WindowPtr pWin = WindowTable[pScreen->myNum]; - xEvent event; + WindowPtr pWin = WindowTable[pScreen->myNum]; + xEvent event; event.u.u.type = ConfigureNotify; event.u.configureNotify.window = pWin->drawable.id; @@ -105,48 +102,49 @@ RRSendConfigNotify (ScreenPtr pScreen) event.u.configureNotify.width = pWin->drawable.width; event.u.configureNotify.height = pWin->drawable.height; - event.u.configureNotify.borderWidth = wBorderWidth (pWin); + event.u.configureNotify.borderWidth = wBorderWidth(pWin); event.u.configureNotify.override = pWin->overrideRedirect; DeliverEvents(pWin, &event, 1, NullWindow); } void -RRDeliverScreenEvent (ClientPtr client, WindowPtr pWin, ScreenPtr pScreen) +RRDeliverScreenEvent(ClientPtr client, WindowPtr pWin, ScreenPtr pScreen) { - rrScrPriv (pScreen); - xRRScreenChangeNotifyEvent se; - RRCrtcPtr crtc = pScrPriv->numCrtcs ? pScrPriv->crtcs[0] : NULL; - WindowPtr pRoot = WindowTable[pScreen->myNum]; + rrScrPriv(pScreen); + xRRScreenChangeNotifyEvent se; + RRCrtcPtr crtc = pScrPriv->numCrtcs ? pScrPriv->crtcs[0] : NULL; + WindowPtr pRoot = WindowTable[pScreen->myNum]; se.type = RRScreenChangeNotify + RREventBase; se.rotation = (CARD8) (crtc ? crtc->rotation : RR_Rotate_0); se.timestamp = pScrPriv->lastSetTime.milliseconds; se.sequenceNumber = client->sequence; se.configTimestamp = pScrPriv->lastConfigTime.milliseconds; - se.root = pRoot->drawable.id; + se.root = pRoot->drawable.id; se.window = pWin->drawable.id; #ifdef RENDER - se.subpixelOrder = PictureGetSubpixelOrder (pScreen); + se.subpixelOrder = PictureGetSubpixelOrder(pScreen); #else se.subpixelOrder = SubPixelUnknown; #endif se.sequenceNumber = client->sequence; - se.sizeID = RR10CurrentSizeID (pScreen); + se.sizeID = RR10CurrentSizeID(pScreen); if (se.rotation & (RR_Rotate_90 | RR_Rotate_270)) { - se.widthInPixels = pScreen->height; - se.heightInPixels = pScreen->width; - se.widthInMillimeters = pScreen->mmHeight; - se.heightInMillimeters = pScreen->mmWidth; - } else { - se.widthInPixels = pScreen->width; - se.heightInPixels = pScreen->height; - se.widthInMillimeters = pScreen->mmWidth; - se.heightInMillimeters = pScreen->mmHeight; + se.widthInPixels = pScreen->height; + se.heightInPixels = pScreen->width; + se.widthInMillimeters = pScreen->mmHeight; + se.heightInMillimeters = pScreen->mmWidth; + } + else { + se.widthInPixels = pScreen->width; + se.heightInPixels = pScreen->height; + se.widthInMillimeters = pScreen->mmWidth; + se.heightInMillimeters = pScreen->mmHeight; } - WriteEventsToClient (client, 1, (xEvent *) &se); + WriteEventsToClient(client, 1, (xEvent *) &se); } /* @@ -155,7 +153,7 @@ RRDeliverScreenEvent (ClientPtr client, WindowPtr pWin, ScreenPtr pScreen) * the size of the screen */ void -RRScreenSizeNotify (ScreenPtr pScreen) +RRScreenSizeNotify(ScreenPtr pScreen) { rrScrPriv(pScreen); /* @@ -163,10 +161,10 @@ RRScreenSizeNotify (ScreenPtr pScreen) * pixel size */ if (pScrPriv->width == pScreen->width && - pScrPriv->height == pScreen->height && - pScrPriv->mmWidth == pScreen->mmWidth && - pScrPriv->mmHeight == pScreen->mmHeight) - return; + pScrPriv->height == pScreen->height && + pScrPriv->mmWidth == pScreen->mmWidth && + pScrPriv->mmHeight == pScreen->mmHeight) + return; pScrPriv->width = pScreen->width; pScrPriv->height = pScreen->height; @@ -175,41 +173,35 @@ RRScreenSizeNotify (ScreenPtr pScreen) pScrPriv->changed = TRUE; /* pScrPriv->sizeChanged = TRUE; */ - RRTellChanged (pScreen); - RRSendConfigNotify (pScreen); - RREditConnectionInfo (pScreen); + RRTellChanged(pScreen); + RRSendConfigNotify(pScreen); + RREditConnectionInfo(pScreen); - RRPointerScreenConfigured (pScreen); + RRPointerScreenConfigured(pScreen); /* * Fix pointer bounds and location */ - ScreenRestructured (pScreen); + ScreenRestructured(pScreen); } /* * Request that the screen be resized */ Bool -RRScreenSizeSet (ScreenPtr pScreen, - CARD16 width, - CARD16 height, - CARD32 mmWidth, - CARD32 mmHeight) +RRScreenSizeSet(ScreenPtr pScreen, + CARD16 width, CARD16 height, CARD32 mmWidth, CARD32 mmHeight) { rrScrPriv(pScreen); #if RANDR_12_INTERFACE - if (pScrPriv->rrScreenSetSize) - { - return (*pScrPriv->rrScreenSetSize) (pScreen, - width, height, - mmWidth, mmHeight); + if (pScrPriv->rrScreenSetSize) { + return (*pScrPriv->rrScreenSetSize) (pScreen, + width, height, mmWidth, mmHeight); } #endif #if RANDR_10_INTERFACE - if (pScrPriv->rrSetConfig) - { - return TRUE; /* can't set size separately */ + if (pScrPriv->rrSetConfig) { + return TRUE; /* can't set size separately */ } #endif return FALSE; @@ -219,24 +211,24 @@ RRScreenSizeSet (ScreenPtr pScreen, * Retrieve valid screen size range */ int -ProcRRGetScreenSizeRange (ClientPtr client) +ProcRRGetScreenSizeRange(ClientPtr client) { REQUEST(xRRGetScreenSizeRangeReq); - xRRGetScreenSizeRangeReply rep; - WindowPtr pWin; - ScreenPtr pScreen; - rrScrPrivPtr pScrPriv; - int rc; + xRRGetScreenSizeRangeReply rep; + WindowPtr pWin; + ScreenPtr pScreen; + rrScrPrivPtr pScrPriv; + int rc; REQUEST_SIZE_MATCH(xRRGetScreenSizeRangeReq); - #ifndef NXAGENT_SERVER +#ifndef NXAGENT_SERVER rc = dixLookupWindow(&pWin, stuff->window, client, DixReadAccess); - #else +#else pWin = SecurityLookupWindow(stuff->window, client, SecurityReadAccess); rc = pWin ? Success : BadWindow; - #endif +#endif if (rc != Success) - return rc; + return rc; pScreen = pWin->drawable.pScreen; pScrPriv = rrGetScrPriv(pScreen); @@ -246,291 +238,272 @@ ProcRRGetScreenSizeRange (ClientPtr client) rep.sequenceNumber = client->sequence; rep.length = 0; - if (pScrPriv) - { - if (!RRGetInfo (pScreen)) - return BadAlloc; - rep.minWidth = pScrPriv->minWidth; - rep.minHeight = pScrPriv->minHeight; - rep.maxWidth = pScrPriv->maxWidth; - rep.maxHeight = pScrPriv->maxHeight; + if (pScrPriv) { + if (!RRGetInfo(pScreen)) + return BadAlloc; + rep.minWidth = pScrPriv->minWidth; + rep.minHeight = pScrPriv->minHeight; + rep.maxWidth = pScrPriv->maxWidth; + rep.maxHeight = pScrPriv->maxHeight; } - else - { - rep.maxWidth = rep.minWidth = pScreen->width; - rep.maxHeight = rep.minHeight = pScreen->height; + else { + rep.maxWidth = rep.minWidth = pScreen->width; + rep.maxHeight = rep.minHeight = pScreen->height; } - if (client->swapped) - { - int n; - - swaps(&rep.sequenceNumber, n); - swapl(&rep.length, n); - swaps(&rep.minWidth, n); - swaps(&rep.minHeight, n); - swaps(&rep.maxWidth, n); - swaps(&rep.maxHeight, n); + if (client->swapped) { + int n; + + swaps(&rep.sequenceNumber, n); + swapl(&rep.length, n); + swaps(&rep.minWidth, n); + swaps(&rep.minHeight, n); + swaps(&rep.maxWidth, n); + swaps(&rep.maxHeight, n); } - WriteToClient(client, sizeof(xRRGetScreenSizeRangeReply), (char *)&rep); + WriteToClient(client, sizeof(xRRGetScreenSizeRangeReply), (char *) &rep); return (client->noClientException); } int -ProcRRSetScreenSize (ClientPtr client) +ProcRRSetScreenSize(ClientPtr client) { REQUEST(xRRSetScreenSizeReq); - WindowPtr pWin; - ScreenPtr pScreen; - rrScrPrivPtr pScrPriv; - int i, rc; + WindowPtr pWin; + ScreenPtr pScreen; + rrScrPrivPtr pScrPriv; + int i, rc; REQUEST_SIZE_MATCH(xRRSetScreenSizeReq); - #ifndef NXAGENT_SERVER +#ifndef NXAGENT_SERVER rc = dixLookupWindow(&pWin, stuff->window, client, DixReadAccess); - #else +#else pWin = SecurityLookupWindow(stuff->window, client, SecurityReadAccess); rc = pWin ? Success : BadWindow; - #endif +#endif if (rc != Success) - return rc; + return rc; pScreen = pWin->drawable.pScreen; pScrPriv = rrGetScrPriv(pScreen); - if (stuff->width < pScrPriv->minWidth || pScrPriv->maxWidth < stuff->width) - { - client->errorValue = stuff->width; - return BadValue; + if (stuff->width < pScrPriv->minWidth || pScrPriv->maxWidth < stuff->width) { + client->errorValue = stuff->width; + return BadValue; } if (stuff->height < pScrPriv->minHeight || - pScrPriv->maxHeight < stuff->height) - { - client->errorValue = stuff->height; - return BadValue; - } - for (i = 0; i < pScrPriv->numCrtcs; i++) - { - RRCrtcPtr crtc = pScrPriv->crtcs[i]; - RRModePtr mode = crtc->mode; - if (mode) - { - int source_width = mode->mode.width; - int source_height = mode->mode.height; - Rotation rotation = crtc->rotation; - - if (rotation == RR_Rotate_90 || rotation == RR_Rotate_270) - { - source_width = mode->mode.height; - source_height = mode->mode.width; - } - - if (crtc->x + source_width > stuff->width || - crtc->y + source_height > stuff->height) - return BadMatch; - } - } - if (stuff->widthInMillimeters == 0 || stuff->heightInMillimeters == 0) - { - client->errorValue = 0; - return BadValue; - } - if (!RRScreenSizeSet (pScreen, - stuff->width, stuff->height, - stuff->widthInMillimeters, - stuff->heightInMillimeters)) - { - return BadMatch; + pScrPriv->maxHeight < stuff->height) { + client->errorValue = stuff->height; + return BadValue; + } + for (i = 0; i < pScrPriv->numCrtcs; i++) { + RRCrtcPtr crtc = pScrPriv->crtcs[i]; + RRModePtr mode = crtc->mode; + + if (mode) { + int source_width = mode->mode.width; + int source_height = mode->mode.height; + Rotation rotation = crtc->rotation; + + if (rotation == RR_Rotate_90 || rotation == RR_Rotate_270) { + source_width = mode->mode.height; + source_height = mode->mode.width; + } + + if (crtc->x + source_width > stuff->width || + crtc->y + source_height > stuff->height) + return BadMatch; + } + } + if (stuff->widthInMillimeters == 0 || stuff->heightInMillimeters == 0) { + client->errorValue = 0; + return BadValue; + } + if (!RRScreenSizeSet(pScreen, + stuff->width, stuff->height, + stuff->widthInMillimeters, + stuff->heightInMillimeters)) { + return BadMatch; } return Success; } int -ProcRRGetScreenResources (ClientPtr client) +ProcRRGetScreenResources(ClientPtr client) { REQUEST(xRRGetScreenResourcesReq); - xRRGetScreenResourcesReply rep; - WindowPtr pWin; - ScreenPtr pScreen; - rrScrPrivPtr pScrPriv; - CARD8 *extra; - unsigned long extraLen; - int i, n, rc; - RRCrtc *crtcs; - RROutput *outputs; - xRRModeInfo *modeinfos; - CARD8 *names; + xRRGetScreenResourcesReply rep; + WindowPtr pWin; + ScreenPtr pScreen; + rrScrPrivPtr pScrPriv; + CARD8 *extra; + unsigned long extraLen; + int i, n, rc; + RRCrtc *crtcs; + RROutput *outputs; + xRRModeInfo *modeinfos; + CARD8 *names; REQUEST_SIZE_MATCH(xRRGetScreenResourcesReq); - #ifndef NXAGENT_SERVER +#ifndef NXAGENT_SERVER rc = dixLookupWindow(&pWin, stuff->window, client, DixReadAccess); - #else +#else pWin = SecurityLookupWindow(stuff->window, client, SecurityReadAccess); rc = pWin ? Success : BadWindow; - #endif +#endif if (rc != Success) - return rc; + return rc; pScreen = pWin->drawable.pScreen; pScrPriv = rrGetScrPriv(pScreen); rep.pad = 0; if (pScrPriv) - if (!RRGetInfo (pScreen)) - return BadAlloc; - - if (!pScrPriv) - { - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = 0; - rep.timestamp = currentTime.milliseconds; - rep.configTimestamp = currentTime.milliseconds; - rep.nCrtcs = 0; - rep.nOutputs = 0; - rep.nModes = 0; - rep.nbytesNames = 0; - extra = NULL; - extraLen = 0; + if (!RRGetInfo(pScreen)) + return BadAlloc; + + if (!pScrPriv) { + rep.type = X_Reply; + rep.sequenceNumber = client->sequence; + rep.length = 0; + rep.timestamp = currentTime.milliseconds; + rep.configTimestamp = currentTime.milliseconds; + rep.nCrtcs = 0; + rep.nOutputs = 0; + rep.nModes = 0; + rep.nbytesNames = 0; + extra = NULL; + extraLen = 0; } - else - { - RRModePtr *modes; - int num_modes; - - modes = RRModesForScreen (pScreen, &num_modes); - if (!modes) - return BadAlloc; - - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = 0; - rep.timestamp = pScrPriv->lastSetTime.milliseconds; - rep.configTimestamp = pScrPriv->lastConfigTime.milliseconds; - rep.nCrtcs = pScrPriv->numCrtcs; - rep.nOutputs = pScrPriv->numOutputs; - rep.nModes = num_modes; - rep.nbytesNames = 0; - - for (i = 0; i < num_modes; i++) - rep.nbytesNames += modes[i]->mode.nameLength; - - rep.length = (pScrPriv->numCrtcs + - pScrPriv->numOutputs + - num_modes * (SIZEOF(xRRModeInfo) >> 2) + - ((rep.nbytesNames + 3) >> 2)); - - extraLen = rep.length << 2; - if (extraLen) - { - extra = xalloc (extraLen); - if (!extra) - { - xfree (modes); - return BadAlloc; - } - } - else - extra = NULL; - - crtcs = (RRCrtc *) extra; - outputs = (RROutput *) (crtcs + pScrPriv->numCrtcs); - modeinfos = (xRRModeInfo *) (outputs + pScrPriv->numOutputs); - names = (CARD8 *) (modeinfos + num_modes); - - for (i = 0; i < pScrPriv->numCrtcs; i++) - { - crtcs[i] = pScrPriv->crtcs[i]->id; - if (client->swapped) - swapl (&crtcs[i], n); - } - - for (i = 0; i < pScrPriv->numOutputs; i++) - { - outputs[i] = pScrPriv->outputs[i]->id; - if (client->swapped) - swapl (&outputs[i], n); - } - - for (i = 0; i < num_modes; i++) - { - RRModePtr mode = modes[i]; - modeinfos[i] = mode->mode; - if (client->swapped) - { - swapl (&modeinfos[i].id, n); - swaps (&modeinfos[i].width, n); - swaps (&modeinfos[i].height, n); - swapl (&modeinfos[i].dotClock, n); - swaps (&modeinfos[i].hSyncStart, n); - swaps (&modeinfos[i].hSyncEnd, n); - swaps (&modeinfos[i].hTotal, n); - swaps (&modeinfos[i].hSkew, n); - swaps (&modeinfos[i].vSyncStart, n); - swaps (&modeinfos[i].vSyncEnd, n); - swaps (&modeinfos[i].vTotal, n); - swaps (&modeinfos[i].nameLength, n); - swapl (&modeinfos[i].modeFlags, n); - } - memcpy (names, mode->name, - mode->mode.nameLength); - names += mode->mode.nameLength; - } - xfree (modes); - assert (((((char *) names - (char *) extra) + 3) >> 2) == rep.length); + else { + RRModePtr *modes; + int num_modes; + + modes = RRModesForScreen(pScreen, &num_modes); + if (!modes) + return BadAlloc; + + rep.type = X_Reply; + rep.sequenceNumber = client->sequence; + rep.length = 0; + rep.timestamp = pScrPriv->lastSetTime.milliseconds; + rep.configTimestamp = pScrPriv->lastConfigTime.milliseconds; + rep.nCrtcs = pScrPriv->numCrtcs; + rep.nOutputs = pScrPriv->numOutputs; + rep.nModes = num_modes; + rep.nbytesNames = 0; + + for (i = 0; i < num_modes; i++) + rep.nbytesNames += modes[i]->mode.nameLength; + + rep.length = (pScrPriv->numCrtcs + + pScrPriv->numOutputs + + num_modes * (SIZEOF(xRRModeInfo) >> 2) + + ((rep.nbytesNames + 3) >> 2)); + + extraLen = rep.length << 2; + if (extraLen) { + extra = xalloc(extraLen); + if (!extra) { + xfree(modes); + return BadAlloc; + } + } + else + extra = NULL; + + crtcs = (RRCrtc *) extra; + outputs = (RROutput *) (crtcs + pScrPriv->numCrtcs); + modeinfos = (xRRModeInfo *) (outputs + pScrPriv->numOutputs); + names = (CARD8 *) (modeinfos + num_modes); + + for (i = 0; i < pScrPriv->numCrtcs; i++) { + crtcs[i] = pScrPriv->crtcs[i]->id; + if (client->swapped) + swapl(&crtcs[i], n); + } + + for (i = 0; i < pScrPriv->numOutputs; i++) { + outputs[i] = pScrPriv->outputs[i]->id; + if (client->swapped) + swapl(&outputs[i], n); + } + + for (i = 0; i < num_modes; i++) { + RRModePtr mode = modes[i]; + + modeinfos[i] = mode->mode; + if (client->swapped) { + swapl(&modeinfos[i].id, n); + swaps(&modeinfos[i].width, n); + swaps(&modeinfos[i].height, n); + swapl(&modeinfos[i].dotClock, n); + swaps(&modeinfos[i].hSyncStart, n); + swaps(&modeinfos[i].hSyncEnd, n); + swaps(&modeinfos[i].hTotal, n); + swaps(&modeinfos[i].hSkew, n); + swaps(&modeinfos[i].vSyncStart, n); + swaps(&modeinfos[i].vSyncEnd, n); + swaps(&modeinfos[i].vTotal, n); + swaps(&modeinfos[i].nameLength, n); + swapl(&modeinfos[i].modeFlags, n); + } + memcpy(names, mode->name, mode->mode.nameLength); + names += mode->mode.nameLength; + } + xfree(modes); + assert(((((char *) names - (char *) extra) + 3) >> 2) == rep.length); } if (client->swapped) { - swaps(&rep.sequenceNumber, n); - swapl(&rep.length, n); - swapl(&rep.timestamp, n); - swapl(&rep.configTimestamp, n); - swaps(&rep.nCrtcs, n); - swaps(&rep.nOutputs, n); - swaps(&rep.nModes, n); - swaps(&rep.nbytesNames, n); + swaps(&rep.sequenceNumber, n); + swapl(&rep.length, n); + swapl(&rep.timestamp, n); + swapl(&rep.configTimestamp, n); + swaps(&rep.nCrtcs, n); + swaps(&rep.nOutputs, n); + swaps(&rep.nModes, n); + swaps(&rep.nbytesNames, n); } - WriteToClient(client, sizeof(xRRGetScreenResourcesReply), (char *)&rep); - if (extraLen) - { - WriteToClient (client, extraLen, (char *) extra); - xfree (extra); + WriteToClient(client, sizeof(xRRGetScreenResourcesReply), (char *) &rep); + if (extraLen) { + WriteToClient(client, extraLen, (char *) extra); + xfree(extra); } return client->noClientException; } typedef struct _RR10Data { RRScreenSizePtr sizes; - int nsize; - int nrefresh; - int size; - CARD16 refresh; + int nsize; + int nrefresh; + int size; + CARD16 refresh; } RR10DataRec, *RR10DataPtr; /* * Convert 1.2 monitor data into 1.0 screen data */ static RR10DataPtr -RR10GetData (ScreenPtr pScreen, RROutputPtr output) +RR10GetData(ScreenPtr pScreen, RROutputPtr output) { - RR10DataPtr data; + RR10DataPtr data; RRScreenSizePtr size; - int nmode = output->numModes + output->numUserModes; - int o, os, l, r; + int nmode = output->numModes + output->numUserModes; + int o, os, l, r; RRScreenRatePtr refresh; - CARD16 vRefresh; - RRModePtr mode; - Bool *used; + CARD16 vRefresh; + RRModePtr mode; + Bool *used; /* Make sure there is plenty of space for any combination */ - data = malloc (sizeof (RR10DataRec) + - sizeof (RRScreenSize) * nmode + - sizeof (RRScreenRate) * nmode + - sizeof (Bool) * nmode); + data = malloc(sizeof(RR10DataRec) + + sizeof(RRScreenSize) * nmode + + sizeof(RRScreenRate) * nmode + sizeof(Bool) * nmode); if (!data) - return NULL; + return NULL; size = (RRScreenSizePtr) (data + 1); refresh = (RRScreenRatePtr) (size + nmode); used = (Bool *) (refresh + nmode); - memset (used, '\0', sizeof (Bool) * nmode); + memset(used, '\0', sizeof(Bool) * nmode); data->sizes = size; data->nsize = 0; data->nrefresh = 0; @@ -540,269 +513,254 @@ RR10GetData (ScreenPtr pScreen, RROutputPtr output) /* * find modes not yet listed */ - for (o = 0; o < output->numModes + output->numUserModes; o++) - { - if (used[o]) continue; - - if (o < output->numModes) - mode = output->modes[o]; - else - mode = output->userModes[o - output->numModes]; - - l = data->nsize; - size[l].id = data->nsize; - size[l].width = mode->mode.width; - size[l].height = mode->mode.height; - if (output->mmWidth && output->mmHeight) { - size[l].mmWidth = output->mmWidth; - size[l].mmHeight = output->mmHeight; - } else { - size[l].mmWidth = pScreen->mmWidth; - size[l].mmHeight = pScreen->mmHeight; - } - size[l].nRates = 0; - size[l].pRates = &refresh[data->nrefresh]; - data->nsize++; - - /* - * Find all modes with matching size - */ - for (os = o; os < output->numModes + output->numUserModes; os++) - { - if (os < output->numModes) - mode = output->modes[os]; - else - mode = output->userModes[os - output->numModes]; - if (mode->mode.width == size[l].width && - mode->mode.height == size[l].height) - { - vRefresh = RRVerticalRefresh (&mode->mode); - used[os] = TRUE; - - for (r = 0; r < size[l].nRates; r++) - if (vRefresh == size[l].pRates[r].rate) - break; - if (r == size[l].nRates) - { - size[l].pRates[r].rate = vRefresh; - size[l].pRates[r].mode = mode; - size[l].nRates++; - data->nrefresh++; - } - if (mode == output->crtc->mode) - { - data->size = l; - data->refresh = vRefresh; - } - } - } + for (o = 0; o < output->numModes + output->numUserModes; o++) { + if (used[o]) + continue; + + if (o < output->numModes) + mode = output->modes[o]; + else + mode = output->userModes[o - output->numModes]; + + l = data->nsize; + size[l].id = data->nsize; + size[l].width = mode->mode.width; + size[l].height = mode->mode.height; + if (output->mmWidth && output->mmHeight) { + size[l].mmWidth = output->mmWidth; + size[l].mmHeight = output->mmHeight; + } + else { + size[l].mmWidth = pScreen->mmWidth; + size[l].mmHeight = pScreen->mmHeight; + } + size[l].nRates = 0; + size[l].pRates = &refresh[data->nrefresh]; + data->nsize++; + + /* + * Find all modes with matching size + */ + for (os = o; os < output->numModes + output->numUserModes; os++) { + if (os < output->numModes) + mode = output->modes[os]; + else + mode = output->userModes[os - output->numModes]; + if (mode->mode.width == size[l].width && + mode->mode.height == size[l].height) { + vRefresh = RRVerticalRefresh(&mode->mode); + used[os] = TRUE; + + for (r = 0; r < size[l].nRates; r++) + if (vRefresh == size[l].pRates[r].rate) + break; + if (r == size[l].nRates) { + size[l].pRates[r].rate = vRefresh; + size[l].pRates[r].mode = mode; + size[l].nRates++; + data->nrefresh++; + } + if (mode == output->crtc->mode) { + data->size = l; + data->refresh = vRefresh; + } + } + } } return data; } int -ProcRRGetScreenInfo (ClientPtr client) +ProcRRGetScreenInfo(ClientPtr client) { REQUEST(xRRGetScreenInfoReq); - xRRGetScreenInfoReply rep; - WindowPtr pWin; - int n, rc; - ScreenPtr pScreen; - rrScrPrivPtr pScrPriv; - CARD8 *extra; - unsigned long extraLen; - RROutputPtr output; + xRRGetScreenInfoReply rep; + WindowPtr pWin; + int n, rc; + ScreenPtr pScreen; + rrScrPrivPtr pScrPriv; + CARD8 *extra; + unsigned long extraLen; + RROutputPtr output; REQUEST_SIZE_MATCH(xRRGetScreenInfoReq); - #ifndef NXAGENT_SERVER +#ifndef NXAGENT_SERVER rc = dixLookupWindow(&pWin, stuff->window, client, DixReadAccess); - #else +#else pWin = SecurityLookupWindow(stuff->window, client, SecurityReadAccess); rc = pWin ? Success : BadWindow; - #endif +#endif if (rc != Success) - return rc; + return rc; pScreen = pWin->drawable.pScreen; pScrPriv = rrGetScrPriv(pScreen); rep.pad = 0; if (pScrPriv) - if (!RRGetInfo (pScreen)) - return BadAlloc; - - output = RRFirstOutput (pScreen); - - if (!pScrPriv || !output) - { - rep.type = X_Reply; - rep.setOfRotations = RR_Rotate_0;; - rep.sequenceNumber = client->sequence; - rep.length = 0; - rep.root = WindowTable[pWin->drawable.pScreen->myNum]->drawable.id; - rep.timestamp = currentTime.milliseconds; - rep.configTimestamp = currentTime.milliseconds; - rep.nSizes = 0; - rep.sizeID = 0; - rep.rotation = RR_Rotate_0; - rep.rate = 0; - rep.nrateEnts = 0; - extra = 0; - extraLen = 0; + if (!RRGetInfo(pScreen)) + return BadAlloc; + + output = RRFirstOutput(pScreen); + + if (!pScrPriv || !output) { + rep.type = X_Reply; + rep.setOfRotations = RR_Rotate_0;; + rep.sequenceNumber = client->sequence; + rep.length = 0; + rep.root = WindowTable[pWin->drawable.pScreen->myNum]->drawable.id; + rep.timestamp = currentTime.milliseconds; + rep.configTimestamp = currentTime.milliseconds; + rep.nSizes = 0; + rep.sizeID = 0; + rep.rotation = RR_Rotate_0; + rep.rate = 0; + rep.nrateEnts = 0; + extra = 0; + extraLen = 0; } - else - { - int i, j; - xScreenSizes *size; - CARD16 *rates; - CARD8 *data8; - Bool has_rate = RRClientKnowsRates (client); - RR10DataPtr pData; - RRScreenSizePtr pSize; - - pData = RR10GetData (pScreen, output); - if (!pData) - return BadAlloc; - - rep.type = X_Reply; - rep.setOfRotations = output->crtc->rotations; - rep.sequenceNumber = client->sequence; - rep.length = 0; - rep.root = WindowTable[pWin->drawable.pScreen->myNum]->drawable.id; - rep.timestamp = pScrPriv->lastSetTime.milliseconds; - rep.configTimestamp = pScrPriv->lastConfigTime.milliseconds; - rep.rotation = output->crtc->rotation; - rep.nSizes = pData->nsize; + else { + int i, j; + xScreenSizes *size; + CARD16 *rates; + CARD8 *data8; + Bool has_rate = RRClientKnowsRates(client); + RR10DataPtr pData; + RRScreenSizePtr pSize; + + pData = RR10GetData(pScreen, output); + if (!pData) + return BadAlloc; + + rep.type = X_Reply; + rep.setOfRotations = output->crtc->rotations; + rep.sequenceNumber = client->sequence; + rep.length = 0; + rep.root = WindowTable[pWin->drawable.pScreen->myNum]->drawable.id; + rep.timestamp = pScrPriv->lastSetTime.milliseconds; + rep.configTimestamp = pScrPriv->lastConfigTime.milliseconds; + rep.rotation = output->crtc->rotation; + rep.nSizes = pData->nsize; rep.nrateEnts = pData->nrefresh + pData->nsize; - rep.sizeID = pData->size; - rep.rate = pData->refresh; - - extraLen = rep.nSizes * sizeof (xScreenSizes); - if (has_rate) - extraLen += rep.nrateEnts * sizeof (CARD16); - - if (extraLen) - { - extra = (CARD8 *) xalloc (extraLen); - if (!extra) - { - xfree (pData); - return BadAlloc; - } - } - else - extra = NULL; - - /* - * First comes the size information - */ - size = (xScreenSizes *) extra; - rates = (CARD16 *) (size + rep.nSizes); - for (i = 0; i < pData->nsize; i++) - { - pSize = &pData->sizes[i]; - size->widthInPixels = pSize->width; - size->heightInPixels = pSize->height; - size->widthInMillimeters = pSize->mmWidth; - size->heightInMillimeters = pSize->mmHeight; - if (client->swapped) - { - swaps (&size->widthInPixels, n); - swaps (&size->heightInPixels, n); - swaps (&size->widthInMillimeters, n); - swaps (&size->heightInMillimeters, n); - } - size++; - if (has_rate) - { - *rates = pSize->nRates; - if (client->swapped) - { - swaps (rates, n); - } - rates++; - for (j = 0; j < pSize->nRates; j++) - { - *rates = pSize->pRates[j].rate; - if (client->swapped) - { - swaps (rates, n); - } - rates++; - } - } - } - xfree (pData); - - data8 = (CARD8 *) rates; - - if (data8 - (CARD8 *) extra != extraLen) - FatalError ("RRGetScreenInfo bad extra len %ld != %ld\n", - (unsigned long)(data8 - (CARD8 *) extra), extraLen); - rep.length = (extraLen + 3) >> 2; + rep.sizeID = pData->size; + rep.rate = pData->refresh; + + extraLen = rep.nSizes * sizeof(xScreenSizes); + if (has_rate) + extraLen += rep.nrateEnts * sizeof(CARD16); + + if (extraLen) { + extra = (CARD8 *) xalloc(extraLen); + if (!extra) { + xfree(pData); + return BadAlloc; + } + } + else + extra = NULL; + + /* + * First comes the size information + */ + size = (xScreenSizes *) extra; + rates = (CARD16 *) (size + rep.nSizes); + for (i = 0; i < pData->nsize; i++) { + pSize = &pData->sizes[i]; + size->widthInPixels = pSize->width; + size->heightInPixels = pSize->height; + size->widthInMillimeters = pSize->mmWidth; + size->heightInMillimeters = pSize->mmHeight; + if (client->swapped) { + swaps(&size->widthInPixels, n); + swaps(&size->heightInPixels, n); + swaps(&size->widthInMillimeters, n); + swaps(&size->heightInMillimeters, n); + } + size++; + if (has_rate) { + *rates = pSize->nRates; + if (client->swapped) { + swaps(rates, n); + } + rates++; + for (j = 0; j < pSize->nRates; j++) { + *rates = pSize->pRates[j].rate; + if (client->swapped) { + swaps(rates, n); + } + rates++; + } + } + } + xfree(pData); + + data8 = (CARD8 *) rates; + + if (data8 - (CARD8 *) extra != extraLen) + FatalError("RRGetScreenInfo bad extra len %ld != %ld\n", + (unsigned long) (data8 - (CARD8 *) extra), extraLen); + rep.length = (extraLen + 3) >> 2; } if (client->swapped) { - swaps(&rep.sequenceNumber, n); - swapl(&rep.length, n); - swapl(&rep.timestamp, n); + swaps(&rep.sequenceNumber, n); + swapl(&rep.length, n); + swapl(&rep.timestamp, n); swapl(&rep.configTimestamp, n); - swaps(&rep.rotation, n); - swaps(&rep.nSizes, n); - swaps(&rep.sizeID, n); - swaps(&rep.rate, n); - swaps(&rep.nrateEnts, n); + swaps(&rep.rotation, n); + swaps(&rep.nSizes, n); + swaps(&rep.sizeID, n); + swaps(&rep.rate, n); + swaps(&rep.nrateEnts, n); } - WriteToClient(client, sizeof(xRRGetScreenInfoReply), (char *)&rep); - if (extraLen) - { - WriteToClient (client, extraLen, (char *) extra); - xfree (extra); + WriteToClient(client, sizeof(xRRGetScreenInfoReply), (char *) &rep); + if (extraLen) { + WriteToClient(client, extraLen, (char *) extra); + xfree(extra); } return (client->noClientException); } int -ProcRRSetScreenConfig (ClientPtr client) +ProcRRSetScreenConfig(ClientPtr client) { REQUEST(xRRSetScreenConfigReq); xRRSetScreenConfigReply rep; - DrawablePtr pDraw; - int n, rc; - ScreenPtr pScreen; - rrScrPrivPtr pScrPriv; - TimeStamp time; - int i; - Rotation rotation; - int rate; - Bool has_rate; - RROutputPtr output; - RRCrtcPtr crtc; - RRModePtr mode; - RR10DataPtr pData = NULL; - RRScreenSizePtr pSize; - int width, height; - - UpdateCurrentTime (); - - if (RRClientKnowsRates (client)) - { - REQUEST_SIZE_MATCH (xRRSetScreenConfigReq); - has_rate = TRUE; + DrawablePtr pDraw; + int n, rc; + ScreenPtr pScreen; + rrScrPrivPtr pScrPriv; + TimeStamp time; + int i; + Rotation rotation; + int rate; + Bool has_rate; + RROutputPtr output; + RRCrtcPtr crtc; + RRModePtr mode; + RR10DataPtr pData = NULL; + RRScreenSizePtr pSize; + int width, height; + + UpdateCurrentTime(); + + if (RRClientKnowsRates(client)) { + REQUEST_SIZE_MATCH(xRRSetScreenConfigReq); + has_rate = TRUE; } - else - { - REQUEST_SIZE_MATCH (xRR1_0SetScreenConfigReq); - has_rate = FALSE; + else { + REQUEST_SIZE_MATCH(xRR1_0SetScreenConfigReq); + has_rate = FALSE; } - #ifndef NXAGENT_SERVER +#ifndef NXAGENT_SERVER rc = dixLookupDrawable(&pDraw, stuff->drawable, client, 0, DixWriteAccess); - #else - pDraw = SecurityLookupDrawable(stuff->drawable, client, SecurityWriteAccess); +#else + pDraw = + SecurityLookupDrawable(stuff->drawable, client, SecurityWriteAccess); rc = pDraw ? Success : BadDrawable; - #endif +#endif if (rc != Success) - return rc; + return rc; pScreen = pDraw->pScreen; @@ -810,21 +768,19 @@ ProcRRSetScreenConfig (ClientPtr client) time = ClientTimeToServerTime(stuff->timestamp); - if (!pScrPriv) - { - time = currentTime; - rep.status = RRSetConfigFailed; - goto sendReply; + if (!pScrPriv) { + time = currentTime; + rep.status = RRSetConfigFailed; + goto sendReply; } - if (!RRGetInfo (pScreen)) - return BadAlloc; - - output = RRFirstOutput (pScreen); - if (!output) - { - time = currentTime; - rep.status = RRSetConfigFailed; - goto sendReply; + if (!RRGetInfo(pScreen)) + return BadAlloc; + + output = RRFirstOutput(pScreen); + if (!output) { + time = currentTime; + rep.status = RRSetConfigFailed; + goto sendReply; } crtc = output->crtc; @@ -838,24 +794,22 @@ ProcRRSetScreenConfig (ClientPtr client) * timestamp, so using CompareTimeStamps here would cause randr to suddenly * stop working after several hours have passed (freedesktop bug #6502). */ - if (stuff->configTimestamp != pScrPriv->lastConfigTime.milliseconds) - { - rep.status = RRSetConfigInvalidConfigTime; - goto sendReply; + if (stuff->configTimestamp != pScrPriv->lastConfigTime.milliseconds) { + rep.status = RRSetConfigInvalidConfigTime; + goto sendReply; } - pData = RR10GetData (pScreen, output); + pData = RR10GetData(pScreen, output); if (!pData) - return BadAlloc; - - if (stuff->sizeID >= pData->nsize) - { - /* - * Invalid size ID - */ - client->errorValue = stuff->sizeID; - xfree (pData); - return BadValue; + return BadAlloc; + + if (stuff->sizeID >= pData->nsize) { + /* + * Invalid size ID + */ + client->errorValue = stuff->sizeID; + xfree(pData); + return BadValue; } pSize = &pData->sizes[stuff->sizeID]; @@ -870,63 +824,58 @@ ProcRRSetScreenConfig (ClientPtr client) case RR_Rotate_90: case RR_Rotate_180: case RR_Rotate_270: - break; + break; default: - /* - * Invalid rotation - */ - client->errorValue = stuff->rotation; - xfree (pData); - return BadValue; + /* + * Invalid rotation + */ + client->errorValue = stuff->rotation; + xfree(pData); + return BadValue; } - if ((~crtc->rotations) & rotation) - { - /* - * requested rotation or reflection not supported by screen - */ - client->errorValue = stuff->rotation; - xfree (pData); - return BadMatch; + if ((~crtc->rotations) & rotation) { + /* + * requested rotation or reflection not supported by screen + */ + client->errorValue = stuff->rotation; + xfree(pData); + return BadMatch; } /* * Validate requested refresh */ if (has_rate) - rate = (int) stuff->rate; + rate = (int) stuff->rate; else - rate = 0; - - if (rate) - { - for (i = 0; i < pSize->nRates; i++) - { - if (pSize->pRates[i].rate == rate) - break; - } - if (i == pSize->nRates) - { - /* - * Invalid rate - */ - client->errorValue = rate; - xfree (pData); - return BadValue; - } - mode = pSize->pRates[i].mode; + rate = 0; + + if (rate) { + for (i = 0; i < pSize->nRates; i++) { + if (pSize->pRates[i].rate == rate) + break; + } + if (i == pSize->nRates) { + /* + * Invalid rate + */ + client->errorValue = rate; + xfree(pData); + return BadValue; + } + mode = pSize->pRates[i].mode; } else - mode = pSize->pRates[0].mode; + mode = pSize->pRates[0].mode; /* * Make sure the requested set-time is not older than * the last set-time */ - if (CompareTimeStamps (time, pScrPriv->lastSetTime) < 0) - { - rep.status = RRSetConfigInvalidTime; - goto sendReply; + if (CompareTimeStamps(time, pScrPriv->lastSetTime) < 0) { + rep.status = RRSetConfigInvalidTime; + goto sendReply; } /* @@ -935,61 +884,56 @@ ProcRRSetScreenConfig (ClientPtr client) */ width = mode->mode.width; height = mode->mode.height; - if (rotation & (RR_Rotate_90|RR_Rotate_270)) - { - width = mode->mode.height; - height = mode->mode.width; + if (rotation & (RR_Rotate_90 | RR_Rotate_270)) { + width = mode->mode.height; + height = mode->mode.width; } if (width < pScrPriv->minWidth || pScrPriv->maxWidth < width) { - client->errorValue = width; - xfree (pData); - return BadValue; + client->errorValue = width; + xfree(pData); + return BadValue; } if (height < pScrPriv->minHeight || pScrPriv->maxHeight < height) { - client->errorValue = height; - xfree (pData); - return BadValue; - } - - if (width != pScreen->width || height != pScreen->height) - { - int c; - - for (c = 0; c < pScrPriv->numCrtcs; c++) - { - if (!RRCrtcSet (pScrPriv->crtcs[c], NULL, 0, 0, RR_Rotate_0, - 0, NULL)) - { - rep.status = RRSetConfigFailed; - /* XXX recover from failure */ - goto sendReply; - } - } - if (!RRScreenSizeSet (pScreen, width, height, - pScreen->mmWidth, pScreen->mmHeight)) - { - rep.status = RRSetConfigFailed; - /* XXX recover from failure */ - goto sendReply; - } - } - - if (!RRCrtcSet (crtc, mode, 0, 0, stuff->rotation, 1, &output)) - rep.status = RRSetConfigFailed; + client->errorValue = height; + xfree(pData); + return BadValue; + } + + if (width != pScreen->width || height != pScreen->height) { + int c; + + for (c = 0; c < pScrPriv->numCrtcs; c++) { + if (!RRCrtcSet(pScrPriv->crtcs[c], NULL, 0, 0, RR_Rotate_0, + 0, NULL)) { + rep.status = RRSetConfigFailed; + /* XXX recover from failure */ + goto sendReply; + } + } + if (!RRScreenSizeSet(pScreen, width, height, + pScreen->mmWidth, pScreen->mmHeight)) { + rep.status = RRSetConfigFailed; + /* XXX recover from failure */ + goto sendReply; + } + } + + if (!RRCrtcSet(crtc, mode, 0, 0, stuff->rotation, 1, &output)) + rep.status = RRSetConfigFailed; else { - pScrPriv->lastSetTime = time; - rep.status = RRSetConfigSuccess; + pScrPriv->lastSetTime = time; + rep.status = RRSetConfigSuccess; } /* * XXX Configure other crtcs to mirror as much as possible */ -sendReply: + sendReply: if (pData) - xfree (pData); + xfree(pData); rep.type = X_Reply; /* rep.status has already been filled in */ @@ -1000,40 +944,38 @@ sendReply: rep.newConfigTimestamp = pScrPriv->lastConfigTime.milliseconds; rep.root = WindowTable[pDraw->pScreen->myNum]->drawable.id; - if (client->swapped) - { - swaps(&rep.sequenceNumber, n); - swapl(&rep.length, n); - swapl(&rep.newTimestamp, n); - swapl(&rep.newConfigTimestamp, n); - swapl(&rep.root, n); + if (client->swapped) { + swaps(&rep.sequenceNumber, n); + swapl(&rep.length, n); + swapl(&rep.newTimestamp, n); + swapl(&rep.newConfigTimestamp, n); + swapl(&rep.root, n); } - WriteToClient(client, sizeof(xRRSetScreenConfigReply), (char *)&rep); + WriteToClient(client, sizeof(xRRSetScreenConfigReply), (char *) &rep); return (client->noClientException); } static CARD16 -RR10CurrentSizeID (ScreenPtr pScreen) +RR10CurrentSizeID(ScreenPtr pScreen) { - CARD16 sizeID = 0xffff; - RROutputPtr output = RRFirstOutput (pScreen); - - if (output) - { - RR10DataPtr data = RR10GetData (pScreen, output); - if (data) - { - int i; - for (i = 0; i < data->nsize; i++) - if (data->sizes[i].width == pScreen->width && - data->sizes[i].height == pScreen->height) - { - sizeID = (CARD16) i; - break; - } - xfree (data); - } + CARD16 sizeID = 0xffff; + RROutputPtr output = RRFirstOutput(pScreen); + + if (output) { + RR10DataPtr data = RR10GetData(pScreen, output); + + if (data) { + int i; + + for (i = 0; i < data->nsize; i++) + if (data->sizes[i].width == pScreen->width && + data->sizes[i].height == pScreen->height) { + sizeID = (CARD16) i; + break; + } + xfree(data); + } } return sizeID; } -- cgit v1.2.3 From c2b1f489d7998c83af73c7cb25bbb2bc53f26094 Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Mon, 20 Jun 2016 11:10:06 +0200 Subject: Backport RANDR proto version 1.5 to nx-X11's Xserver. Backported to X.org's /xorg/xserver Git hash level: a6b6e8ba026acedef6336b17adf06aebddd5f22f. --- nx-X11/programs/Xserver/randr/rrscreen.c | 508 ++++++++++++++++++++++--------- 1 file changed, 368 insertions(+), 140 deletions(-) (limited to 'nx-X11/programs/Xserver/randr/rrscreen.c') diff --git a/nx-X11/programs/Xserver/randr/rrscreen.c b/nx-X11/programs/Xserver/randr/rrscreen.c index 458416c1f..af54d66f5 100644 --- a/nx-X11/programs/Xserver/randr/rrscreen.c +++ b/nx-X11/programs/Xserver/randr/rrscreen.c @@ -39,10 +39,6 @@ #include "randrstr.h" -extern char *ConnectionInfo; - -static int padlength[4] = { 0, 3, 2, 1 }; - static CARD16 RR10CurrentSizeID(ScreenPtr pScreen); @@ -65,8 +61,7 @@ RREditConnectionInfo(ScreenPtr pScreen) connSetup = (xConnSetup *) ConnectionInfo; vendor = (char *) connSetup + sizeof(xConnSetup); formats = (xPixmapFormat *) ((char *) vendor + - connSetup->nbytesVendor + - padlength[connSetup->nbytesVendor & 3]); + pad_to_int32(connSetup->nbytesVendor)); root = (xWindowRoot *) ((char *) formats + sizeof(xPixmapFormat) * screenInfo.numPixmapFormats); @@ -89,21 +84,21 @@ RREditConnectionInfo(ScreenPtr pScreen) void RRSendConfigNotify(ScreenPtr pScreen) { - WindowPtr pWin = WindowTable[pScreen->myNum]; - xEvent event; - + WindowPtr pWin = pScreen->root; + xEvent event = { + .u.configureNotify.window = pWin->drawable.id, + .u.configureNotify.aboveSibling = None, + .u.configureNotify.x = 0, + .u.configureNotify.y = 0, + + /* XXX xinerama stuff ? */ + + .u.configureNotify.width = pWin->drawable.width, + .u.configureNotify.height = pWin->drawable.height, + .u.configureNotify.borderWidth = wBorderWidth(pWin), + .u.configureNotify.override = pWin->overrideRedirect + }; event.u.u.type = ConfigureNotify; - event.u.configureNotify.window = pWin->drawable.id; - event.u.configureNotify.aboveSibling = None; - event.u.configureNotify.x = 0; - event.u.configureNotify.y = 0; - - /* XXX xinerama stuff ? */ - - event.u.configureNotify.width = pWin->drawable.width; - event.u.configureNotify.height = pWin->drawable.height; - event.u.configureNotify.borderWidth = wBorderWidth(pWin); - event.u.configureNotify.override = pWin->overrideRedirect; DeliverEvents(pWin, &event, 1, NullWindow); } @@ -111,25 +106,23 @@ void RRDeliverScreenEvent(ClientPtr client, WindowPtr pWin, ScreenPtr pScreen) { rrScrPriv(pScreen); - xRRScreenChangeNotifyEvent se; RRCrtcPtr crtc = pScrPriv->numCrtcs ? pScrPriv->crtcs[0] : NULL; - WindowPtr pRoot = WindowTable[pScreen->myNum]; - - se.type = RRScreenChangeNotify + RREventBase; - se.rotation = (CARD8) (crtc ? crtc->rotation : RR_Rotate_0); - se.timestamp = pScrPriv->lastSetTime.milliseconds; - se.sequenceNumber = client->sequence; - se.configTimestamp = pScrPriv->lastConfigTime.milliseconds; - se.root = pRoot->drawable.id; - se.window = pWin->drawable.id; -#ifdef RENDER - se.subpixelOrder = PictureGetSubpixelOrder(pScreen); -#else - se.subpixelOrder = SubPixelUnknown; + WindowPtr pRoot = pScreen->root; + + xRRScreenChangeNotifyEvent se = { + .type = RRScreenChangeNotify + RREventBase, +#ifdef NXAGENT_SERVER + .sequenceNumber = client->sequence, #endif + .rotation = (CARD8) (crtc ? crtc->rotation : RR_Rotate_0), + .timestamp = pScrPriv->lastSetTime.milliseconds, + .configTimestamp = pScrPriv->lastConfigTime.milliseconds, + .root = pRoot->drawable.id, + .window = pWin->drawable.id, + .subpixelOrder = PictureGetSubpixelOrder(pScreen), - se.sequenceNumber = client->sequence; - se.sizeID = RR10CurrentSizeID(pScreen); + .sizeID = RR10CurrentSizeID(pScreen) + }; if (se.rotation & (RR_Rotate_90 | RR_Rotate_270)) { se.widthInPixels = pScreen->height; @@ -144,7 +137,7 @@ RRDeliverScreenEvent(ClientPtr client, WindowPtr pWin, ScreenPtr pScreen) se.heightInMillimeters = pScreen->mmHeight; } - WriteEventsToClient(client, 1, (xEvent *) &se); + WriteEventsToClient(client, 1, (xEvent *) (char *) &se); } /* @@ -170,7 +163,7 @@ RRScreenSizeNotify(ScreenPtr pScreen) pScrPriv->height = pScreen->height; pScrPriv->mmWidth = pScreen->mmWidth; pScrPriv->mmHeight = pScreen->mmHeight; - pScrPriv->changed = TRUE; + RRSetChanged(pScreen); /* pScrPriv->sizeChanged = TRUE; */ RRTellChanged(pScreen); @@ -219,27 +212,31 @@ ProcRRGetScreenSizeRange(ClientPtr client) ScreenPtr pScreen; rrScrPrivPtr pScrPriv; int rc; + int n; REQUEST_SIZE_MATCH(xRRGetScreenSizeRangeReq); #ifndef NXAGENT_SERVER - rc = dixLookupWindow(&pWin, stuff->window, client, DixReadAccess); + rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess); #else pWin = SecurityLookupWindow(stuff->window, client, SecurityReadAccess); rc = pWin ? Success : BadWindow; #endif + if (rc != Success) return rc; pScreen = pWin->drawable.pScreen; pScrPriv = rrGetScrPriv(pScreen); - rep.type = X_Reply; - rep.pad = 0; - rep.sequenceNumber = client->sequence; - rep.length = 0; + rep = (xRRGetScreenSizeRangeReply) { + .type = X_Reply, + .pad = 0, + .sequenceNumber = client->sequence, + .length = 0 + }; if (pScrPriv) { - if (!RRGetInfo(pScreen)) + if (!RRGetInfo(pScreen, FALSE)) return BadAlloc; rep.minWidth = pScrPriv->minWidth; rep.minHeight = pScrPriv->minHeight; @@ -251,8 +248,6 @@ ProcRRGetScreenSizeRange(ClientPtr client) rep.maxHeight = rep.minHeight = pScreen->height; } if (client->swapped) { - int n; - swaps(&rep.sequenceNumber, n); swapl(&rep.length, n); swaps(&rep.minWidth, n); @@ -261,7 +256,7 @@ ProcRRGetScreenSizeRange(ClientPtr client) swaps(&rep.maxHeight, n); } WriteToClient(client, sizeof(xRRGetScreenSizeRangeReply), (char *) &rep); - return (client->noClientException); + return Success; } int @@ -275,7 +270,7 @@ ProcRRSetScreenSize(ClientPtr client) REQUEST_SIZE_MATCH(xRRSetScreenSizeReq); #ifndef NXAGENT_SERVER - rc = dixLookupWindow(&pWin, stuff->window, client, DixReadAccess); + rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess); #else pWin = SecurityLookupWindow(stuff->window, client, SecurityReadAccess); rc = pWin ? Success : BadWindow; @@ -285,6 +280,9 @@ ProcRRSetScreenSize(ClientPtr client) pScreen = pWin->drawable.pScreen; pScrPriv = rrGetScrPriv(pScreen); + if (!pScrPriv) + return BadMatch; + if (stuff->width < pScrPriv->minWidth || pScrPriv->maxWidth < stuff->width) { client->errorValue = stuff->width; return BadValue; @@ -326,8 +324,194 @@ ProcRRSetScreenSize(ClientPtr client) return Success; } -int -ProcRRGetScreenResources(ClientPtr client) + +#define update_totals(gpuscreen, pScrPriv) do { \ + total_crtcs += pScrPriv->numCrtcs; \ + total_outputs += pScrPriv->numOutputs; \ + modes = RRModesForScreen(gpuscreen, &num_modes); \ + if (!modes) \ + return BadAlloc; \ + for (j = 0; j < num_modes; j++) \ + total_name_len += modes[j]->mode.nameLength; \ + total_modes += num_modes; \ + xfree(modes); \ +} while(0) + +static inline void +swap_modeinfos(xRRModeInfo * modeinfos, int i) +{ + int n; + + swapl(&modeinfos[i].id, n); + swaps(&modeinfos[i].width, n); + swaps(&modeinfos[i].height, n); + swapl(&modeinfos[i].dotClock, n); + swaps(&modeinfos[i].hSyncStart, n); + swaps(&modeinfos[i].hSyncEnd, n); + swaps(&modeinfos[i].hTotal, n); + swaps(&modeinfos[i].hSkew, n); + swaps(&modeinfos[i].vSyncStart, n); + swaps(&modeinfos[i].vSyncEnd, n); + swaps(&modeinfos[i].vTotal, n); + swaps(&modeinfos[i].nameLength, n); + swapl(&modeinfos[i].modeFlags, n); +} + +#define update_arrays(gpuscreen, pScrPriv, primary_crtc, has_primary) do { \ + for (j = 0; j < pScrPriv->numCrtcs; j++) { \ + if (has_primary && \ + primary_crtc == pScrPriv->crtcs[j]) { \ + has_primary = 0; \ + continue; \ + }\ + crtcs[crtc_count] = pScrPriv->crtcs[j]->id; \ + if (client->swapped) \ + swapl(&crtcs[crtc_count], n); \ + crtc_count++; \ + } \ + for (j = 0; j < pScrPriv->numOutputs; j++) { \ + outputs[output_count] = pScrPriv->outputs[j]->id; \ + if (client->swapped) \ + swapl(&outputs[output_count], n); \ + output_count++; \ + } \ + { \ + RRModePtr mode; \ + modes = RRModesForScreen(gpuscreen, &num_modes); \ + for (j = 0; j < num_modes; j++) { \ + mode = modes[j]; \ + modeinfos[mode_count] = mode->mode; \ + if (client->swapped) { \ + swap_modeinfos(modeinfos, mode_count); \ + } \ + memcpy(names, mode->name, mode->mode.nameLength); \ + names += mode->mode.nameLength; \ + mode_count++; \ + } \ + xfree(modes); \ + } \ + } while (0) + +#ifndef NXAGENT_SERVER +static int +rrGetMultiScreenResources(ClientPtr client, Bool query, ScreenPtr pScreen) +{ + int j; + int total_crtcs, total_outputs, total_modes, total_name_len; + int crtc_count, output_count, mode_count; + ScreenPtr iter; + rrScrPrivPtr pScrPriv; + int num_modes; + RRModePtr *modes; + xRRGetScreenResourcesReply rep; + unsigned long extraLen; + CARD8 *extra; + RRCrtc *crtcs; + RRCrtcPtr primary_crtc = NULL; + RROutput *outputs; + xRRModeInfo *modeinfos; + CARD8 *names; + int has_primary = 0; + int n; + + /* we need to iterate all the GPU masters and all their output slaves */ + total_crtcs = 0; + total_outputs = 0; + total_modes = 0; + total_name_len = 0; + + pScrPriv = rrGetScrPriv(pScreen); + + if (query && pScrPriv) + if (!RRGetInfo(pScreen, query)) + return BadAlloc; + + update_totals(pScreen, pScrPriv); + + xorg_list_for_each_entry(iter, &pScreen->output_slave_list, output_head) { + pScrPriv = rrGetScrPriv(iter); + + if (query) + if (!RRGetInfo(iter, query)) + return BadAlloc; + update_totals(iter, pScrPriv); + } + + pScrPriv = rrGetScrPriv(pScreen); + rep = (xRRGetScreenResourcesReply) { + .type = X_Reply, + .sequenceNumber = client->sequence, + .length = 0, + .timestamp = pScrPriv->lastSetTime.milliseconds, + .configTimestamp = pScrPriv->lastConfigTime.milliseconds, + .nCrtcs = total_crtcs, + .nOutputs = total_outputs, + .nModes = total_modes, + .nbytesNames = total_name_len + }; + + rep.length = (total_crtcs + total_outputs + + total_modes * bytes_to_int32(SIZEOF(xRRModeInfo)) + + bytes_to_int32(total_name_len)); + + extraLen = rep.length << 2; + if (extraLen) { + extra = xalloc(extraLen); + if (!extra) { + return BadAlloc; + } + } + else + extra = NULL; + + crtcs = (RRCrtc *) extra; + outputs = (RROutput *) (crtcs + total_crtcs); + modeinfos = (xRRModeInfo *) (outputs + total_outputs); + names = (CARD8 *) (modeinfos + total_modes); + + crtc_count = 0; + output_count = 0; + mode_count = 0; + + pScrPriv = rrGetScrPriv(pScreen); + if (pScrPriv->primaryOutput && pScrPriv->primaryOutput->crtc) { + has_primary = 1; + primary_crtc = pScrPriv->primaryOutput->crtc; + crtcs[0] = pScrPriv->primaryOutput->crtc->id; + if (client->swapped) + swapl(&crtcs[0], n); + crtc_count = 1; + } + update_arrays(pScreen, pScrPriv, primary_crtc, has_primary); + + xorg_list_for_each_entry(iter, &pScreen->output_slave_list, output_head) { + pScrPriv = rrGetScrPriv(iter); + + update_arrays(iter, pScrPriv, primary_crtc, has_primary); + } + + assert(bytes_to_int32((char *) names - (char *) extra) == rep.length); + if (client->swapped) { + swaps(&rep.sequenceNumber, n); + swapl(&rep.length, n); + swapl(&rep.timestamp, n); + swapl(&rep.configTimestamp, n); + swaps(&rep.nCrtcs, n); + swaps(&rep.nOutputs, n); + swaps(&rep.nModes, n); + swaps(&rep.nbytesNames, n); + } + WriteToClient(client, sizeof(xRRGetScreenResourcesReply), (char *) &rep); + if (extraLen) { + WriteToClient(client, extraLen, (char *) extra); + xfree(extra); + } + return Success; +} +#endif /* !defined(NXAGENT_SERVER) */ + +static int +rrGetScreenResources(ClientPtr client, Bool query) { REQUEST(xRRGetScreenResourcesReq); xRRGetScreenResourcesReply rep; @@ -336,15 +520,17 @@ ProcRRGetScreenResources(ClientPtr client) rrScrPrivPtr pScrPriv; CARD8 *extra; unsigned long extraLen; - int i, n, rc; + int i, rc, has_primary = 0; RRCrtc *crtcs; RROutput *outputs; xRRModeInfo *modeinfos; CARD8 *names; + int n; REQUEST_SIZE_MATCH(xRRGetScreenResourcesReq); + #ifndef NXAGENT_SERVER - rc = dixLookupWindow(&pWin, stuff->window, client, DixReadAccess); + rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess); #else pWin = SecurityLookupWindow(stuff->window, client, SecurityReadAccess); rc = pWin ? Success : BadWindow; @@ -354,22 +540,28 @@ ProcRRGetScreenResources(ClientPtr client) pScreen = pWin->drawable.pScreen; pScrPriv = rrGetScrPriv(pScreen); - rep.pad = 0; - if (pScrPriv) - if (!RRGetInfo(pScreen)) + if (query && pScrPriv) + if (!RRGetInfo(pScreen, query)) return BadAlloc; +#ifndef NXAGENT_SERVER + if (!xorg_list_is_empty(&pScreen->output_slave_list)) + return rrGetMultiScreenResources(client, query, pScreen); +#endif + if (!pScrPriv) { - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = 0; - rep.timestamp = currentTime.milliseconds; - rep.configTimestamp = currentTime.milliseconds; - rep.nCrtcs = 0; - rep.nOutputs = 0; - rep.nModes = 0; - rep.nbytesNames = 0; + rep = (xRRGetScreenResourcesReply) { + .type = X_Reply, + .sequenceNumber = client->sequence, + .length = 0, + .timestamp = currentTime.milliseconds, + .configTimestamp = currentTime.milliseconds, + .nCrtcs = 0, + .nOutputs = 0, + .nModes = 0, + .nbytesNames = 0 + }; extra = NULL; extraLen = 0; } @@ -381,23 +573,25 @@ ProcRRGetScreenResources(ClientPtr client) if (!modes) return BadAlloc; - rep.type = X_Reply; - rep.sequenceNumber = client->sequence; - rep.length = 0; - rep.timestamp = pScrPriv->lastSetTime.milliseconds; - rep.configTimestamp = pScrPriv->lastConfigTime.milliseconds; - rep.nCrtcs = pScrPriv->numCrtcs; - rep.nOutputs = pScrPriv->numOutputs; - rep.nModes = num_modes; - rep.nbytesNames = 0; + rep = (xRRGetScreenResourcesReply) { + .type = X_Reply, + .sequenceNumber = client->sequence, + .length = 0, + .timestamp = pScrPriv->lastSetTime.milliseconds, + .configTimestamp = pScrPriv->lastConfigTime.milliseconds, + .nCrtcs = pScrPriv->numCrtcs, + .nOutputs = pScrPriv->numOutputs, + .nModes = num_modes, + .nbytesNames = 0 + }; for (i = 0; i < num_modes; i++) rep.nbytesNames += modes[i]->mode.nameLength; rep.length = (pScrPriv->numCrtcs + pScrPriv->numOutputs + - num_modes * (SIZEOF(xRRModeInfo) >> 2) + - ((rep.nbytesNames + 3) >> 2)); + num_modes * bytes_to_int32(SIZEOF(xRRModeInfo)) + + bytes_to_int32(rep.nbytesNames)); extraLen = rep.length << 2; if (extraLen) { @@ -415,10 +609,22 @@ ProcRRGetScreenResources(ClientPtr client) modeinfos = (xRRModeInfo *) (outputs + pScrPriv->numOutputs); names = (CARD8 *) (modeinfos + num_modes); + if (pScrPriv->primaryOutput && pScrPriv->primaryOutput->crtc) { + has_primary = 1; + crtcs[0] = pScrPriv->primaryOutput->crtc->id; + if (client->swapped) + swapl(&crtcs[0], n); + } + for (i = 0; i < pScrPriv->numCrtcs; i++) { - crtcs[i] = pScrPriv->crtcs[i]->id; + if (has_primary && + pScrPriv->primaryOutput->crtc == pScrPriv->crtcs[i]) { + has_primary = 0; + continue; + } + crtcs[i + has_primary] = pScrPriv->crtcs[i]->id; if (client->swapped) - swapl(&crtcs[i], n); + swapl(&crtcs[i + has_primary], n); } for (i = 0; i < pScrPriv->numOutputs; i++) { @@ -450,7 +656,7 @@ ProcRRGetScreenResources(ClientPtr client) names += mode->mode.nameLength; } xfree(modes); - assert(((((char *) names - (char *) extra) + 3) >> 2) == rep.length); + assert(bytes_to_int32((char *) names - (char *) extra) == rep.length); } if (client->swapped) { @@ -463,12 +669,25 @@ ProcRRGetScreenResources(ClientPtr client) swaps(&rep.nModes, n); swaps(&rep.nbytesNames, n); } - WriteToClient(client, sizeof(xRRGetScreenResourcesReply), (char *) &rep); + WriteToClient(client, sizeof(xRRGetScreenResourcesReply), + (char *) (char *) &rep); if (extraLen) { - WriteToClient(client, extraLen, (char *) extra); + WriteToClient(client, extraLen, (char *) (char *) extra); xfree(extra); } - return client->noClientException; + return Success; +} + +int +ProcRRGetScreenResources(ClientPtr client) +{ + return rrGetScreenResources(client, TRUE); +} + +int +ProcRRGetScreenResourcesCurrent(ClientPtr client) +{ + return rrGetScreenResources(client, FALSE); } typedef struct _RR10Data { @@ -495,7 +714,7 @@ RR10GetData(ScreenPtr pScreen, RROutputPtr output) Bool *used; /* Make sure there is plenty of space for any combination */ - data = malloc(sizeof(RR10DataRec) + + data = xalloc(sizeof(RR10DataRec) + sizeof(RRScreenSize) * nmode + sizeof(RRScreenRate) * nmode + sizeof(Bool) * nmode); if (!data) @@ -576,46 +795,49 @@ ProcRRGetScreenInfo(ClientPtr client) REQUEST(xRRGetScreenInfoReq); xRRGetScreenInfoReply rep; WindowPtr pWin; - int n, rc; + int rc; ScreenPtr pScreen; rrScrPrivPtr pScrPriv; CARD8 *extra; unsigned long extraLen; RROutputPtr output; + int n; REQUEST_SIZE_MATCH(xRRGetScreenInfoReq); #ifndef NXAGENT_SERVER - rc = dixLookupWindow(&pWin, stuff->window, client, DixReadAccess); + rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess); #else pWin = SecurityLookupWindow(stuff->window, client, SecurityReadAccess); rc = pWin ? Success : BadWindow; #endif + if (rc != Success) return rc; pScreen = pWin->drawable.pScreen; pScrPriv = rrGetScrPriv(pScreen); - rep.pad = 0; if (pScrPriv) - if (!RRGetInfo(pScreen)) + if (!RRGetInfo(pScreen, TRUE)) return BadAlloc; output = RRFirstOutput(pScreen); if (!pScrPriv || !output) { - rep.type = X_Reply; - rep.setOfRotations = RR_Rotate_0;; - rep.sequenceNumber = client->sequence; - rep.length = 0; - rep.root = WindowTable[pWin->drawable.pScreen->myNum]->drawable.id; - rep.timestamp = currentTime.milliseconds; - rep.configTimestamp = currentTime.milliseconds; - rep.nSizes = 0; - rep.sizeID = 0; - rep.rotation = RR_Rotate_0; - rep.rate = 0; - rep.nrateEnts = 0; + rep = (xRRGetScreenInfoReply) { + .type = X_Reply, + .setOfRotations = RR_Rotate_0, + .sequenceNumber = client->sequence, + .length = 0, + .root = pWin->drawable.pScreen->root->drawable.id, + .timestamp = currentTime.milliseconds, + .configTimestamp = currentTime.milliseconds, + .nSizes = 0, + .sizeID = 0, + .rotation = RR_Rotate_0, + .rate = 0, + .nrateEnts = 0 + }; extra = 0; extraLen = 0; } @@ -632,18 +854,20 @@ ProcRRGetScreenInfo(ClientPtr client) if (!pData) return BadAlloc; - rep.type = X_Reply; - rep.setOfRotations = output->crtc->rotations; - rep.sequenceNumber = client->sequence; - rep.length = 0; - rep.root = WindowTable[pWin->drawable.pScreen->myNum]->drawable.id; - rep.timestamp = pScrPriv->lastSetTime.milliseconds; - rep.configTimestamp = pScrPriv->lastConfigTime.milliseconds; - rep.rotation = output->crtc->rotation; - rep.nSizes = pData->nsize; - rep.nrateEnts = pData->nrefresh + pData->nsize; - rep.sizeID = pData->size; - rep.rate = pData->refresh; + rep = (xRRGetScreenInfoReply) { + .type = X_Reply, + .setOfRotations = output->crtc->rotations, + .sequenceNumber = client->sequence, + .length = 0, + .root = pWin->drawable.pScreen->root->drawable.id, + .timestamp = pScrPriv->lastSetTime.milliseconds, + .configTimestamp = pScrPriv->lastConfigTime.milliseconds, + .rotation = output->crtc->rotation, + .nSizes = pData->nsize, + .nrateEnts = pData->nrefresh + pData->nsize, + .sizeID = pData->size, + .rate = pData->refresh + }; extraLen = rep.nSizes * sizeof(xScreenSizes); if (has_rate) @@ -699,7 +923,7 @@ ProcRRGetScreenInfo(ClientPtr client) if (data8 - (CARD8 *) extra != extraLen) FatalError("RRGetScreenInfo bad extra len %ld != %ld\n", (unsigned long) (data8 - (CARD8 *) extra), extraLen); - rep.length = (extraLen + 3) >> 2; + rep.length = bytes_to_int32(extraLen); } if (client->swapped) { swaps(&rep.sequenceNumber, n); @@ -717,7 +941,7 @@ ProcRRGetScreenInfo(ClientPtr client) WriteToClient(client, extraLen, (char *) extra); xfree(extra); } - return (client->noClientException); + return Success; } int @@ -726,7 +950,7 @@ ProcRRSetScreenConfig(ClientPtr client) REQUEST(xRRSetScreenConfigReq); xRRSetScreenConfigReply rep; DrawablePtr pDraw; - int n, rc; + int rc; ScreenPtr pScreen; rrScrPrivPtr pScrPriv; TimeStamp time; @@ -734,12 +958,14 @@ ProcRRSetScreenConfig(ClientPtr client) Rotation rotation; int rate; Bool has_rate; + CARD8 status; RROutputPtr output; RRCrtcPtr crtc; RRModePtr mode; RR10DataPtr pData = NULL; RRScreenSizePtr pSize; int width, height; + int n; UpdateCurrentTime(); @@ -754,11 +980,12 @@ ProcRRSetScreenConfig(ClientPtr client) #ifndef NXAGENT_SERVER rc = dixLookupDrawable(&pDraw, stuff->drawable, client, 0, DixWriteAccess); -#else +#else /* !defined(NXAGENT_SERVER) */ pDraw = SecurityLookupDrawable(stuff->drawable, client, SecurityWriteAccess); rc = pDraw ? Success : BadDrawable; -#endif +#endif /* !defined(NXAGENT_SERVER) */ + if (rc != Success) return rc; @@ -770,16 +997,16 @@ ProcRRSetScreenConfig(ClientPtr client) if (!pScrPriv) { time = currentTime; - rep.status = RRSetConfigFailed; + status = RRSetConfigFailed; goto sendReply; } - if (!RRGetInfo(pScreen)) + if (!RRGetInfo(pScreen, FALSE)) return BadAlloc; output = RRFirstOutput(pScreen); if (!output) { time = currentTime; - rep.status = RRSetConfigFailed; + status = RRSetConfigFailed; goto sendReply; } @@ -795,7 +1022,7 @@ ProcRRSetScreenConfig(ClientPtr client) * stop working after several hours have passed (freedesktop bug #6502). */ if (stuff->configTimestamp != pScrPriv->lastConfigTime.milliseconds) { - rep.status = RRSetConfigInvalidConfigTime; + status = RRSetConfigInvalidConfigTime; goto sendReply; } @@ -874,7 +1101,7 @@ ProcRRSetScreenConfig(ClientPtr client) * the last set-time */ if (CompareTimeStamps(time, pScrPriv->lastSetTime) < 0) { - rep.status = RRSetConfigInvalidTime; + status = RRSetConfigInvalidTime; goto sendReply; } @@ -884,11 +1111,6 @@ ProcRRSetScreenConfig(ClientPtr client) */ width = mode->mode.width; height = mode->mode.height; - if (rotation & (RR_Rotate_90 | RR_Rotate_270)) { - width = mode->mode.height; - height = mode->mode.width; - } - if (width < pScrPriv->minWidth || pScrPriv->maxWidth < width) { client->errorValue = width; xfree(pData); @@ -900,30 +1122,35 @@ ProcRRSetScreenConfig(ClientPtr client) return BadValue; } + if (rotation & (RR_Rotate_90 | RR_Rotate_270)) { + width = mode->mode.height; + height = mode->mode.width; + } + if (width != pScreen->width || height != pScreen->height) { int c; for (c = 0; c < pScrPriv->numCrtcs; c++) { if (!RRCrtcSet(pScrPriv->crtcs[c], NULL, 0, 0, RR_Rotate_0, 0, NULL)) { - rep.status = RRSetConfigFailed; + status = RRSetConfigFailed; /* XXX recover from failure */ goto sendReply; } } if (!RRScreenSizeSet(pScreen, width, height, pScreen->mmWidth, pScreen->mmHeight)) { - rep.status = RRSetConfigFailed; + status = RRSetConfigFailed; /* XXX recover from failure */ goto sendReply; } } if (!RRCrtcSet(crtc, mode, 0, 0, stuff->rotation, 1, &output)) - rep.status = RRSetConfigFailed; + status = RRSetConfigFailed; else { pScrPriv->lastSetTime = time; - rep.status = RRSetConfigSuccess; + status = RRSetConfigSuccess; } /* @@ -932,17 +1159,18 @@ ProcRRSetScreenConfig(ClientPtr client) sendReply: - if (pData) - xfree(pData); - - rep.type = X_Reply; - /* rep.status has already been filled in */ - rep.length = 0; - rep.sequenceNumber = client->sequence; + xfree(pData); - rep.newTimestamp = pScrPriv->lastSetTime.milliseconds; - rep.newConfigTimestamp = pScrPriv->lastConfigTime.milliseconds; - rep.root = WindowTable[pDraw->pScreen->myNum]->drawable.id; + rep = (xRRSetScreenConfigReply) { + .type = X_Reply, + .status = status, + .sequenceNumber = client->sequence, + .length = 0, + .newTimestamp = pScrPriv->lastSetTime.milliseconds, + .newConfigTimestamp = pScrPriv->lastConfigTime.milliseconds, + .root = pDraw->pScreen->root->drawable.id, + /* .subpixelOrder = ?? */ + }; if (client->swapped) { swaps(&rep.sequenceNumber, n); @@ -953,7 +1181,7 @@ ProcRRSetScreenConfig(ClientPtr client) } WriteToClient(client, sizeof(xRRSetScreenConfigReply), (char *) &rep); - return (client->noClientException); + return Success; } static CARD16 -- cgit v1.2.3