summaryrefslogtreecommitdiff
path: root/randr/rrscreen.c
diff options
context:
space:
mode:
authorKeith Packard <keithp@guitar.keithp.com>2006-09-19 22:48:54 -0700
committerKeith Packard <keithp@guitar.keithp.com>2006-09-19 22:48:54 -0700
commitef1f3248cb5fff0a02c0059f865c4d931eba23a6 (patch)
treeeba375889f7b55b520ba875e7adcf7f599f8ab42 /randr/rrscreen.c
parent07112adb0802d28488de5a495aa61bb3cfc280b6 (diff)
Split out 1.0-style info and new property routines to their own files.
Diffstat (limited to 'randr/rrscreen.c')
-rw-r--r--randr/rrscreen.c651
1 files changed, 651 insertions, 0 deletions
diff --git a/randr/rrscreen.c b/randr/rrscreen.c
index 47ba12d39..58d5152d0 100644
--- a/randr/rrscreen.c
+++ b/randr/rrscreen.c
@@ -203,3 +203,654 @@ RRScreenSizeSet (ScreenPtr pScreen,
return FALSE;
}
+/*
+ * Retrieve valid screen size range
+ */
+int
+ProcRRGetScreenSizeRange (ClientPtr client)
+{
+ REQUEST(xRRGetScreenSizeRangeReq);
+ xRRGetScreenSizeRangeReply rep;
+ WindowPtr pWin;
+ ScreenPtr pScreen;
+ rrScrPrivPtr pScrPriv;
+
+ REQUEST_SIZE_MATCH(xRRGetScreenInfoReq);
+ pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client,
+ SecurityReadAccess);
+
+ if (!pWin)
+ return BadWindow;
+
+ pScreen = pWin->drawable.pScreen;
+ pScrPriv = rrGetScrPriv(pScreen);
+
+ rep.type = X_Reply;
+ rep.pad = 0;
+ rep.sequenceNumber = client->sequence;
+ rep.length = 0;
+
+ if (pScrPriv)
+ {
+ RRGetInfo (pScreen);
+ 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;
+ }
+ 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);
+ return (client->noClientException);
+}
+
+int
+ProcRRSetScreenSize (ClientPtr client)
+{
+ REQUEST(xRRSetScreenSizeReq);
+ WindowPtr pWin;
+ ScreenPtr pScreen;
+ rrScrPrivPtr pScrPriv;
+ RRCrtcPtr crtc;
+ int i;
+
+ REQUEST_SIZE_MATCH(xRRSetScreenSizeReq);
+ pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client,
+ SecurityReadAccess);
+
+ if (!pWin)
+ return BadWindow;
+
+ pScreen = pWin->drawable.pScreen;
+ pScrPriv = rrGetScrPriv(pScreen);
+ 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++) {
+ crtc = pScrPriv->crtcs[i];
+ if (crtc->mode &&
+ (crtc->x + crtc->mode->mode.width > stuff->width ||
+ crtc->y + crtc->mode->mode.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)
+{
+ REQUEST(xRRGetScreenResourcesReq);
+ xRRGetScreenResourcesReply rep;
+ WindowPtr pWin;
+ ScreenPtr pScreen;
+ rrScrPrivPtr pScrPriv;
+ CARD8 *extra;
+ unsigned long extraLen;
+ int i;
+ RRCrtc *crtcs;
+ RROutput *outputs;
+ xRRModeInfo *modeinfos;
+ CARD8 *names;
+ int n;
+
+ REQUEST_SIZE_MATCH(xRRGetScreenResourcesReq);
+ pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client,
+ SecurityReadAccess);
+
+ if (!pWin)
+ return BadWindow;
+
+ pScreen = pWin->drawable.pScreen;
+ pScrPriv = rrGetScrPriv(pScreen);
+ rep.pad = 0;
+
+ if (pScrPriv)
+ RRGetInfo (pScreen);
+
+ 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
+ {
+ rep.type = X_Reply;
+ rep.sequenceNumber = client->sequence;
+ rep.length = 0;
+ rep.timestamp = currentTime.milliseconds;
+ rep.configTimestamp = currentTime.milliseconds;
+ rep.nCrtcs = pScrPriv->numCrtcs;
+ rep.nOutputs = pScrPriv->numOutputs;
+ rep.nModes = pScrPriv->numModes;;
+ rep.nbytesNames = 0;
+
+ for (i = 0; i < pScrPriv->numModes; i++)
+ rep.nbytesNames += pScrPriv->modes[i]->mode.nameLength;
+
+ rep.length = (pScrPriv->numCrtcs +
+ pScrPriv->numOutputs +
+ pScrPriv->numModes * 10 +
+ ((rep.nbytesNames + 3) >> 2));
+
+ extraLen = rep.length << 2;
+ extra = xalloc (extraLen);
+ if (!extra)
+ return BadAlloc;
+
+ crtcs = (RRCrtc *) extra;
+ outputs = (RROutput *) (crtcs + pScrPriv->numCrtcs);
+ modeinfos = (xRRModeInfo *) (outputs + pScrPriv->numOutputs);
+ names = (CARD8 *) (modeinfos + pScrPriv->numModes);
+
+ 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 < pScrPriv->numModes; i++)
+ {
+ modeinfos[i] = pScrPriv->modes[i]->mode;
+ if (client->swapped)
+ {
+ swapl (&modeinfos[i].id, n);
+ swaps (&modeinfos[i].width, n);
+ swaps (&modeinfos[i].height, n);
+ swapl (&modeinfos[i].mmWidth, n);
+ swapl (&modeinfos[i].mmHeight, 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, pScrPriv->modes[i]->name,
+ pScrPriv->modes[i]->mode.nameLength);
+ names += pScrPriv->modes[i]->mode.nameLength;
+ }
+ assert ((names + 3 >> 3) == 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 client->noClientException;
+}
+
+typedef struct _RR10Data {
+ RRScreenSizePtr sizes;
+ 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)
+{
+ RR10DataPtr data;
+ RRScreenSizePtr size;
+ int nmode = output->numModes;
+ int i, j, k;
+ RRScreenRatePtr refresh;
+ CARD16 vRefresh;
+ RRModePtr mode;
+
+ /* Make sure there is plenty of space for any combination */
+ data = malloc (sizeof (RR10DataRec) +
+ sizeof (RRScreenSize) * nmode +
+ sizeof (RRScreenRate) * nmode);
+ if (!data)
+ return NULL;
+ size = (RRScreenSizePtr) (data + 1);
+ refresh = (RRScreenRatePtr) (size + nmode);
+ data->sizes = size;
+ data->nsize = 0;
+ data->nrefresh = 0;
+ data->size = 0;
+ data->refresh = 0;
+ for (i = 0; i < output->numModes; i++)
+ {
+ mode = output->modes[i];
+ for (j = 0; j < data->nsize; j++)
+ if (mode->mode.width == size[j].width &&
+ mode->mode.height == size[j].height)
+ break;
+ if (j == data->nsize)
+ {
+ size[j].id = j;
+ size[j].width = mode->mode.width;
+ size[j].height = mode->mode.height;
+ size[j].mmWidth = mode->mode.mmWidth;
+ size[j].mmHeight = mode->mode.mmHeight;
+ size[j].nRates = 0;
+ size[j].pRates = &refresh[data->nrefresh];
+ data->nsize++;
+ }
+ vRefresh = RRVerticalRefresh (&mode->mode);
+ for (k = 0; k < size[j].nRates; k++)
+ if (vRefresh == size[j].pRates[k].rate)
+ break;
+ if (k == size[j].nRates)
+ {
+ size[j].pRates[k].rate = vRefresh;
+ size[j].pRates[k].mode = mode;
+ size[j].nRates++;
+ data->nrefresh++;
+ }
+ if (mode == output->crtc->mode)
+ {
+ data->size = j;
+ data->refresh = vRefresh;
+ }
+ }
+ return data;
+}
+
+int
+ProcRRGetScreenInfo (ClientPtr client)
+{
+ REQUEST(xRRGetScreenInfoReq);
+ xRRGetScreenInfoReply rep;
+ WindowPtr pWin;
+ int n;
+ ScreenPtr pScreen;
+ rrScrPrivPtr pScrPriv;
+ CARD8 *extra;
+ unsigned long extraLen;
+ RROutputPtr output;
+
+ REQUEST_SIZE_MATCH(xRRGetScreenInfoReq);
+ pWin = (WindowPtr)SecurityLookupWindow(stuff->window, client,
+ SecurityReadAccess);
+
+ if (!pWin)
+ return BadWindow;
+
+ pScreen = pWin->drawable.pScreen;
+ pScrPriv = rrGetScrPriv(pScreen);
+ rep.pad = 0;
+
+ if (pScrPriv)
+ RRGetInfo (pScreen);
+
+ 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;
+ rep.nrateEnts = pData->nrefresh + pData->nsize;
+ rep.sizeID = pData->size;
+ rep.rate = pData->refresh;
+
+ extraLen = (rep.nSizes * sizeof (xScreenSizes) +
+ rep.nrateEnts * sizeof (CARD16));
+
+ extra = (CARD8 *) xalloc (extraLen);
+ if (!extra)
+ {
+ xfree (pData);
+ return BadAlloc;
+ }
+ /*
+ * 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.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);
+ }
+ return (client->noClientException);
+}
+
+int
+ProcRRSetScreenConfig (ClientPtr client)
+{
+ REQUEST(xRRSetScreenConfigReq);
+ xRRSetScreenConfigReply rep;
+ DrawablePtr pDraw;
+ int n;
+ ScreenPtr pScreen;
+ rrScrPrivPtr pScrPriv;
+ TimeStamp configTime;
+ TimeStamp time;
+ int i;
+ Rotation rotation;
+ int rate;
+ Bool has_rate;
+ RROutputPtr output;
+ RRModePtr mode;
+ RR10DataPtr pData = NULL;
+ RRScreenSizePtr pSize;
+
+ UpdateCurrentTime ();
+
+ if (RRClientKnowsRates (client))
+ {
+ REQUEST_SIZE_MATCH (xRRSetScreenConfigReq);
+ has_rate = TRUE;
+ }
+ else
+ {
+ REQUEST_SIZE_MATCH (xRR1_0SetScreenConfigReq);
+ has_rate = FALSE;
+ }
+
+ SECURITY_VERIFY_DRAWABLE(pDraw, stuff->drawable, client,
+ SecurityWriteAccess);
+
+ pScreen = pDraw->pScreen;
+
+ pScrPriv = rrGetScrPriv(pScreen);
+
+ time = ClientTimeToServerTime(stuff->timestamp);
+ configTime = ClientTimeToServerTime(stuff->configTimestamp);
+
+ 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 the client's config timestamp is not the same as the last config
+ * timestamp, then the config information isn't up-to-date and
+ * can't even be validated
+ */
+ if (CompareTimeStamps (configTime, pScrPriv->lastConfigTime) != 0)
+ {
+ rep.status = RRSetConfigInvalidConfigTime;
+ goto sendReply;
+ }
+
+ pData = RR10GetData (pScreen, output);
+ if (!pData)
+ return BadAlloc;
+
+ if (stuff->sizeID >= pData->nsize)
+ {
+ /*
+ * Invalid size ID
+ */
+ client->errorValue = stuff->sizeID;
+ xfree (pData);
+ return BadValue;
+ }
+ pSize = &pData->sizes[stuff->sizeID];
+
+ /*
+ * Validate requested rotation
+ */
+ rotation = (Rotation) stuff->rotation;
+
+ /* test the rotation bits only! */
+ switch (rotation & 0xf) {
+ case RR_Rotate_0:
+ case RR_Rotate_90:
+ case RR_Rotate_180:
+ case RR_Rotate_270:
+ break;
+ default:
+ /*
+ * Invalid rotation
+ */
+ client->errorValue = stuff->rotation;
+ xfree (pData);
+ return BadValue;
+ }
+
+ if ((~output->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;
+ 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;
+ }
+ else
+ 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;
+ }
+
+ rep.status = RRCrtcSet (output->crtc, mode, 0, 0, stuff->rotation,
+ 1, &output);
+
+sendReply:
+
+ if (pData)
+ xfree (pData);
+
+ rep.type = X_Reply;
+ /* rep.status has already been filled in */
+ rep.length = 0;
+ rep.sequenceNumber = client->sequence;
+
+ rep.newTimestamp = pScrPriv->lastSetTime.milliseconds;
+ 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);
+ }
+ WriteToClient(client, sizeof(xRRSetScreenConfigReply), (char *)&rep);
+
+ return (client->noClientException);
+}
+