rrsdispatch.c revision 4642e01f
1/*
2 * Copyright © 2006 Keith Packard
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission.  The copyright holders make no representations
11 * about the suitability of this software for any purpose.  It is provided "as
12 * is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20 * OF THIS SOFTWARE.
21 */
22
23#include "randrstr.h"
24
25static int
26SProcRRQueryVersion (ClientPtr client)
27{
28    register int n;
29    REQUEST(xRRQueryVersionReq);
30
31    swaps(&stuff->length, n);
32    swapl(&stuff->majorVersion, n);
33    swapl(&stuff->minorVersion, n);
34    return (*ProcRandrVector[stuff->randrReqType]) (client);
35}
36
37static int
38SProcRRGetScreenInfo (ClientPtr client)
39{
40    register int n;
41    REQUEST(xRRGetScreenInfoReq);
42
43    swaps(&stuff->length, n);
44    swapl(&stuff->window, n);
45    return (*ProcRandrVector[stuff->randrReqType]) (client);
46}
47
48static int
49SProcRRSetScreenConfig (ClientPtr client)
50{
51    register int n;
52    REQUEST(xRRSetScreenConfigReq);
53
54    if (RRClientKnowsRates (client))
55    {
56	REQUEST_SIZE_MATCH (xRRSetScreenConfigReq);
57	swaps (&stuff->rate, n);
58    }
59    else
60    {
61	REQUEST_SIZE_MATCH (xRR1_0SetScreenConfigReq);
62    }
63
64    swaps(&stuff->length, n);
65    swapl(&stuff->drawable, n);
66    swapl(&stuff->timestamp, n);
67    swaps(&stuff->sizeID, n);
68    swaps(&stuff->rotation, n);
69    return (*ProcRandrVector[stuff->randrReqType]) (client);
70}
71
72static int
73SProcRRSelectInput (ClientPtr client)
74{
75    register int n;
76    REQUEST(xRRSelectInputReq);
77
78    swaps(&stuff->length, n);
79    swapl(&stuff->window, n);
80    swaps(&stuff->enable, n);
81    return (*ProcRandrVector[stuff->randrReqType]) (client);
82}
83
84static int
85SProcRRGetScreenSizeRange (ClientPtr client)
86{
87    int n;
88    REQUEST(xRRGetScreenSizeRangeReq);
89
90    REQUEST_SIZE_MATCH(xRRGetScreenSizeRangeReq);
91    swaps(&stuff->length, n);
92    swapl(&stuff->window, n);
93    return (*ProcRandrVector[stuff->randrReqType]) (client);
94}
95
96static int
97SProcRRSetScreenSize (ClientPtr client)
98{
99    int n;
100    REQUEST(xRRSetScreenSizeReq);
101
102    REQUEST_SIZE_MATCH(xRRSetScreenSizeReq);
103    swaps(&stuff->length, n);
104    swapl(&stuff->window, n);
105    swaps(&stuff->width, n);
106    swaps(&stuff->height, n);
107    swapl(&stuff->widthInMillimeters, n);
108    swapl(&stuff->heightInMillimeters, n);
109    return (*ProcRandrVector[stuff->randrReqType]) (client);
110}
111
112static int
113SProcRRGetScreenResources (ClientPtr client)
114{
115    int n;
116    REQUEST(xRRGetScreenResourcesReq);
117
118    REQUEST_SIZE_MATCH(xRRGetScreenResourcesReq);
119    swaps(&stuff->length, n);
120    swapl(&stuff->window, n);
121    return (*ProcRandrVector[stuff->randrReqType]) (client);
122}
123
124static int
125SProcRRGetOutputInfo (ClientPtr client)
126{
127    int n;
128    REQUEST(xRRGetOutputInfoReq);
129
130    REQUEST_SIZE_MATCH(xRRGetOutputInfoReq);
131    swaps(&stuff->length, n);
132    swapl(&stuff->output, n);
133    swapl(&stuff->configTimestamp, n);
134    return (*ProcRandrVector[stuff->randrReqType]) (client);
135}
136
137static int
138SProcRRListOutputProperties (ClientPtr client)
139{
140    int n;
141    REQUEST(xRRListOutputPropertiesReq);
142
143    REQUEST_SIZE_MATCH(xRRListOutputPropertiesReq);
144    swaps(&stuff->length, n);
145    swapl(&stuff->output, n);
146    return (*ProcRandrVector[stuff->randrReqType]) (client);
147}
148
149static int
150SProcRRQueryOutputProperty (ClientPtr client)
151{
152    int n;
153    REQUEST(xRRQueryOutputPropertyReq);
154
155    REQUEST_SIZE_MATCH(xRRQueryOutputPropertyReq);
156    swaps(&stuff->length, n);
157    swapl(&stuff->output, n);
158    swapl(&stuff->property, n);
159    return (*ProcRandrVector[stuff->randrReqType]) (client);
160}
161
162static int
163SProcRRConfigureOutputProperty (ClientPtr client)
164{
165    int n;
166    REQUEST(xRRConfigureOutputPropertyReq);
167
168    swaps(&stuff->length, n);
169    swapl(&stuff->output, n);
170    swapl(&stuff->property, n);
171    SwapRestL(stuff);
172    return (*ProcRandrVector[stuff->randrReqType]) (client);
173}
174
175static int
176SProcRRChangeOutputProperty (ClientPtr client)
177{
178    int n;
179    REQUEST(xRRChangeOutputPropertyReq);
180
181    REQUEST_AT_LEAST_SIZE (xRRChangeOutputPropertyReq);
182    swaps(&stuff->length, n);
183    swapl(&stuff->output, n);
184    swapl(&stuff->property, n);
185    swapl(&stuff->type, n);
186    swapl(&stuff->nUnits, n);
187    switch(stuff->format) {
188	case 8:
189	    break;
190	case 16:
191	    SwapRestS(stuff);
192	    break;
193	case 32:
194	    SwapRestL(stuff);
195	    break;
196	default:
197	    client->errorValue = stuff->format;
198	    return BadValue;
199    }
200    return (*ProcRandrVector[stuff->randrReqType]) (client);
201}
202
203static int
204SProcRRDeleteOutputProperty (ClientPtr client)
205{
206    int n;
207    REQUEST(xRRDeleteOutputPropertyReq);
208
209    REQUEST_SIZE_MATCH(xRRDeleteOutputPropertyReq);
210    swaps(&stuff->length, n);
211    swapl(&stuff->output, n);
212    swapl(&stuff->property, n);
213    return (*ProcRandrVector[stuff->randrReqType]) (client);
214}
215
216static int
217SProcRRGetOutputProperty (ClientPtr client)
218{
219    int n;
220    REQUEST(xRRGetOutputPropertyReq);
221
222    REQUEST_SIZE_MATCH(xRRGetOutputPropertyReq);
223    swaps(&stuff->length, n);
224    swapl(&stuff->output, n);
225    swapl(&stuff->property, n);
226    swapl(&stuff->type, n);
227    swapl(&stuff->longOffset, n);
228    swapl(&stuff->longLength, n);
229    return (*ProcRandrVector[stuff->randrReqType]) (client);
230}
231
232static int
233SProcRRCreateMode (ClientPtr client)
234{
235    int n;
236    xRRModeInfo *modeinfo;
237    REQUEST(xRRCreateModeReq);
238
239    REQUEST_AT_LEAST_SIZE(xRRCreateModeReq);
240    swaps(&stuff->length, n);
241    swapl(&stuff->window, n);
242
243    modeinfo = &stuff->modeInfo;
244    swapl(&modeinfo->id, n);
245    swaps(&modeinfo->width, n);
246    swaps(&modeinfo->height, n);
247    swapl(&modeinfo->dotClock, n);
248    swaps(&modeinfo->hSyncStart, n);
249    swaps(&modeinfo->hSyncEnd, n);
250    swaps(&modeinfo->hTotal, n);
251    swaps(&modeinfo->vSyncStart, n);
252    swaps(&modeinfo->vSyncEnd, n);
253    swaps(&modeinfo->vTotal, n);
254    swaps(&modeinfo->nameLength, n);
255    swapl(&modeinfo->modeFlags, n);
256    return (*ProcRandrVector[stuff->randrReqType]) (client);
257}
258
259static int
260SProcRRDestroyMode (ClientPtr client)
261{
262    int n;
263    REQUEST(xRRDestroyModeReq);
264
265    REQUEST_SIZE_MATCH(xRRDestroyModeReq);
266    swaps(&stuff->length, n);
267    swapl(&stuff->mode, n);
268    return (*ProcRandrVector[stuff->randrReqType]) (client);
269}
270
271static int
272SProcRRAddOutputMode (ClientPtr client)
273{
274    int n;
275    REQUEST(xRRAddOutputModeReq);
276
277    REQUEST_SIZE_MATCH(xRRAddOutputModeReq);
278    swaps(&stuff->length, n);
279    swapl(&stuff->output, n);
280    swapl(&stuff->mode, n);
281    return (*ProcRandrVector[stuff->randrReqType]) (client);
282}
283
284static int
285SProcRRDeleteOutputMode (ClientPtr client)
286{
287    int n;
288    REQUEST(xRRDeleteOutputModeReq);
289
290    REQUEST_SIZE_MATCH(xRRDeleteOutputModeReq);
291    swaps(&stuff->length, n);
292    swapl(&stuff->output, n);
293    swapl(&stuff->mode, n);
294    return (*ProcRandrVector[stuff->randrReqType]) (client);
295}
296
297static int
298SProcRRGetCrtcInfo (ClientPtr client)
299{
300    int n;
301    REQUEST(xRRGetCrtcInfoReq);
302
303    REQUEST_SIZE_MATCH(xRRGetCrtcInfoReq);
304    swaps(&stuff->length, n);
305    swapl(&stuff->crtc, n);
306    swapl(&stuff->configTimestamp, n);
307    return (*ProcRandrVector[stuff->randrReqType]) (client);
308}
309
310static int
311SProcRRSetCrtcConfig (ClientPtr client)
312{
313    int n;
314    REQUEST(xRRSetCrtcConfigReq);
315
316    REQUEST_AT_LEAST_SIZE(xRRSetCrtcConfigReq);
317    swaps(&stuff->length, n);
318    swapl(&stuff->crtc, n);
319    swapl(&stuff->timestamp, n);
320    swapl(&stuff->configTimestamp, n);
321    swaps(&stuff->x, n);
322    swaps(&stuff->y, n);
323    swapl(&stuff->mode, n);
324    swaps(&stuff->rotation, n);
325    SwapRestL(stuff);
326    return (*ProcRandrVector[stuff->randrReqType]) (client);
327}
328
329static int
330SProcRRGetCrtcGammaSize (ClientPtr client)
331{
332    int n;
333    REQUEST(xRRGetCrtcGammaSizeReq);
334
335    REQUEST_SIZE_MATCH(xRRGetCrtcGammaSizeReq);
336    swaps(&stuff->length, n);
337    swapl(&stuff->crtc, n);
338    return (*ProcRandrVector[stuff->randrReqType]) (client);
339}
340
341static int
342SProcRRGetCrtcGamma (ClientPtr client)
343{
344    int n;
345    REQUEST(xRRGetCrtcGammaReq);
346
347    REQUEST_SIZE_MATCH(xRRGetCrtcGammaReq);
348    swaps(&stuff->length, n);
349    swapl(&stuff->crtc, n);
350    return (*ProcRandrVector[stuff->randrReqType]) (client);
351}
352
353static int
354SProcRRSetCrtcGamma (ClientPtr client)
355{
356    int n;
357    REQUEST(xRRSetCrtcGammaReq);
358
359    REQUEST_AT_LEAST_SIZE(xRRSetCrtcGammaReq);
360    swaps(&stuff->length, n);
361    swapl(&stuff->crtc, n);
362    swaps(&stuff->size, n);
363    SwapRestS(stuff);
364    return (*ProcRandrVector[stuff->randrReqType]) (client);
365}
366
367static int
368SProcRRSetCrtcTransform (ClientPtr client)
369{
370    int n, nparams;
371    char *filter;
372    CARD32 *params;
373    REQUEST(xRRSetCrtcTransformReq);
374
375    REQUEST_AT_LEAST_SIZE(xRRSetCrtcTransformReq);
376    swaps(&stuff->length, n);
377    swapl(&stuff->crtc, n);
378    SwapLongs((CARD32 *)&stuff->transform, (sizeof(xRenderTransform)) >> 2);
379    swaps(&stuff->nbytesFilter, n);
380    filter = (char *)(stuff + 1);
381    params = (CARD32 *) (filter + ((stuff->nbytesFilter + 3) & ~3));
382    nparams = ((CARD32 *) stuff + client->req_len) - params;
383    if (nparams < 0)
384	return BadLength;
385
386    SwapLongs(params, nparams);
387    return (*ProcRandrVector[stuff->randrReqType]) (client);
388}
389
390static int
391SProcRRGetCrtcTransform (ClientPtr client)
392{
393    int n;
394    REQUEST(xRRGetCrtcTransformReq);
395
396    REQUEST_SIZE_MATCH(xRRGetCrtcTransformReq);
397    swaps(&stuff->length, n);
398    swapl(&stuff->crtc, n);
399    return (*ProcRandrVector[stuff->randrReqType]) (client);
400}
401
402static int
403SProcRRGetPanning (ClientPtr client)
404{
405    int n;
406    REQUEST(xRRGetPanningReq);
407
408    REQUEST_SIZE_MATCH(xRRGetPanningReq);
409    swaps(&stuff->length, n);
410    swapl(&stuff->crtc, n);
411    return (*ProcRandrVector[stuff->randrReqType]) (client);
412}
413
414static int
415SProcRRSetPanning (ClientPtr client)
416{
417    int n;
418    REQUEST(xRRSetPanningReq);
419
420    REQUEST_SIZE_MATCH(xRRSetPanningReq);
421    swaps(&stuff->length, n);
422    swapl(&stuff->crtc, n);
423    swapl(&stuff->timestamp, n);
424    swaps(&stuff->left, n);
425    swaps(&stuff->top, n);
426    swaps(&stuff->width, n);
427    swaps(&stuff->height, n);
428    swaps(&stuff->track_left, n);
429    swaps(&stuff->track_top, n);
430    swaps(&stuff->track_width, n);
431    swaps(&stuff->track_height, n);
432    swaps(&stuff->border_left, n);
433    swaps(&stuff->border_top, n);
434    swaps(&stuff->border_right, n);
435    swaps(&stuff->border_bottom, n);
436    return (*ProcRandrVector[stuff->randrReqType]) (client);
437}
438
439static int
440SProcRRSetOutputPrimary (ClientPtr client)
441{
442    int n;
443    REQUEST(xRRSetOutputPrimaryReq);
444
445    REQUEST_SIZE_MATCH(xRRSetOutputPrimaryReq);
446    swaps(&stuff->length, n);
447    swapl(&stuff->window, n);
448    swapl(&stuff->output, n);
449    return ProcRandrVector[stuff->randrReqType](client);
450}
451
452static int
453SProcRRGetOutputPrimary (ClientPtr client)
454{
455    int n;
456    REQUEST(xRRSetOutputPrimaryReq);
457
458    REQUEST_SIZE_MATCH(xRRGetOutputPrimaryReq);
459    swaps(&stuff->length, n);
460    swapl(&stuff->window, n);
461    return ProcRandrVector[stuff->randrReqType](client);
462}
463
464int (*SProcRandrVector[RRNumberRequests])(ClientPtr) = {
465    SProcRRQueryVersion,	/* 0 */
466/* we skip 1 to make old clients fail pretty immediately */
467    NULL,			/* 1 SProcRandrOldGetScreenInfo */
468/* V1.0 apps share the same set screen config request id */
469    SProcRRSetScreenConfig,	/* 2 */
470    NULL,			/* 3 SProcRandrOldScreenChangeSelectInput */
471/* 3 used to be ScreenChangeSelectInput; deprecated */
472    SProcRRSelectInput,		/* 4 */
473    SProcRRGetScreenInfo,    	/* 5 */
474/* V1.2 additions */
475    SProcRRGetScreenSizeRange,	/* 6 */
476    SProcRRSetScreenSize,	/* 7 */
477    SProcRRGetScreenResources,	/* 8 */
478    SProcRRGetOutputInfo,	/* 9 */
479    SProcRRListOutputProperties,/* 10 */
480    SProcRRQueryOutputProperty,	/* 11 */
481    SProcRRConfigureOutputProperty,  /* 12 */
482    SProcRRChangeOutputProperty,/* 13 */
483    SProcRRDeleteOutputProperty,/* 14 */
484    SProcRRGetOutputProperty,	/* 15 */
485    SProcRRCreateMode,		/* 16 */
486    SProcRRDestroyMode,		/* 17 */
487    SProcRRAddOutputMode,	/* 18 */
488    SProcRRDeleteOutputMode,	/* 19 */
489    SProcRRGetCrtcInfo,		/* 20 */
490    SProcRRSetCrtcConfig,	/* 21 */
491    SProcRRGetCrtcGammaSize,	/* 22 */
492    SProcRRGetCrtcGamma,	/* 23 */
493    SProcRRSetCrtcGamma,	/* 24 */
494/* V1.3 additions */
495    SProcRRGetScreenResources,	/* 25 GetScreenResourcesCurrent */
496    SProcRRSetCrtcTransform,	/* 26 */
497    SProcRRGetCrtcTransform,	/* 27 */
498    SProcRRGetPanning,		/* 28 */
499    SProcRRSetPanning,		/* 29 */
500    SProcRRSetOutputPrimary,	/* 30 */
501    SProcRRGetOutputPrimary,	/* 31 */
502};
503
504