Imported Upstream version 1.15.1
[deb_xorg-server.git] / hw / xfree86 / common / xf86vmode.c
CommitLineData
a09e091a
JB
1
2/*
3
4Copyright 1995 Kaleb S. KEITHLEY
5
6Permission is hereby granted, free of charge, to any person obtaining
7a copy of this software and associated documentation files (the
8"Software"), to deal in the Software without restriction, including
9without limitation the rights to use, copy, modify, merge, publish,
10distribute, sublicense, and/or sell copies of the Software, and to
11permit persons to whom the Software is furnished to do so, subject to
12the following conditions:
13
14The above copyright notice and this permission notice shall be
15included in all copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20IN NO EVENT SHALL Kaleb S. KEITHLEY BE LIABLE FOR ANY CLAIM, DAMAGES
21OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23OTHER DEALINGS IN THE SOFTWARE.
24
25Except as contained in this notice, the name of Kaleb S. KEITHLEY
26shall not be used in advertising or otherwise to promote the sale, use
27or other dealings in this Software without prior written authorization
28from Kaleb S. KEITHLEY
29
30*/
31/* THIS IS NOT AN X CONSORTIUM STANDARD OR AN X PROJECT TEAM SPECIFICATION */
32
33#ifdef HAVE_XORG_CONFIG_H
34#include <xorg-config.h>
35#endif
36
37#include <X11/X.h>
38#include <X11/Xproto.h>
39#include "misc.h"
40#include "dixstruct.h"
41#include "extnsionst.h"
42#include "xf86Extensions.h"
43#include "scrnintstr.h"
44#include "servermd.h"
45#include <X11/extensions/xf86vmproto.h>
46#include "swaprep.h"
47#include "xf86.h"
48#include "vidmodeproc.h"
49#include "globals.h"
50#include "protocol-versions.h"
51
52#define DEFAULT_XF86VIDMODE_VERBOSITY 3
53
54static int VidModeErrorBase;
55static DevPrivateKeyRec VidModeClientPrivateKeyRec;
56
57#define VidModeClientPrivateKey (&VidModeClientPrivateKeyRec)
58
59/* This holds the client's version information */
60typedef struct {
61 int major;
62 int minor;
63} VidModePrivRec, *VidModePrivPtr;
64
65#define VM_GETPRIV(c) ((VidModePrivPtr) \
66 dixLookupPrivate(&(c)->devPrivates, VidModeClientPrivateKey))
67#define VM_SETPRIV(c,p) \
68 dixSetPrivate(&(c)->devPrivates, VidModeClientPrivateKey, p)
69
70#if 0
71static unsigned char XF86VidModeReqCode = 0;
72#endif
73
74/* The XF86VIDMODE_EVENTS code is far from complete */
75
76#ifdef XF86VIDMODE_EVENTS
77static int XF86VidModeEventBase = 0;
78
79static void SXF86VidModeNotifyEvent(xXF86VidModeNotifyEvent * /* from */ , xXF86VidModeNotifyEvent * /* to */
80 );
81
82static RESTYPE EventType; /* resource type for event masks */
83
84typedef struct _XF86VidModeEvent *XF86VidModeEventPtr;
85
86typedef struct _XF86VidModeEvent {
87 XF86VidModeEventPtr next;
88 ClientPtr client;
89 ScreenPtr screen;
90 XID resource;
91 CARD32 mask;
92} XF86VidModeEventRec;
93
94static int XF86VidModeFreeEvents();
95
96typedef struct _XF86VidModeScreenPrivate {
97 XF86VidModeEventPtr events;
98 Bool hasWindow;
99} XF86VidModeScreenPrivateRec, *XF86VidModeScreenPrivatePtr;
100
101static DevPrivateKeyRec ScreenPrivateKeyRec;
102
103#define ScreenPrivateKey (&ScreenPrivateKeyRec)
104
105#define GetScreenPrivate(s) ((ScreenSaverScreenPrivatePtr) \
106 dixLookupPrivate(&(s)->devPrivates, ScreenPrivateKey))
107#define SetScreenPrivate(s,v) \
108 dixSetPrivate(&(s)->devPrivates, ScreenPrivateKey, v)
109#define SetupScreen(s) ScreenSaverScreenPrivatePtr pPriv = GetScreenPrivate(s)
110
111#define New(t) (malloc(sizeof (t)))
112#endif
113
114#ifdef DEBUG
115#define DEBUG_P(x) ErrorF(x"\n");
116#else
117#define DEBUG_P(x) /**/
118#endif
119 static int
120ClientMajorVersion(ClientPtr client)
121{
122 VidModePrivPtr pPriv;
123
124 pPriv = VM_GETPRIV(client);
125 if (!pPriv)
126 return 0;
127 else
128 return pPriv->major;
129}
130
131#ifdef XF86VIDMODE_EVENTS
132static void
133CheckScreenPrivate(pScreen)
134ScreenPtr
135 pScreen;
136{
137 SetupScreen(pScreen);
138
139 if (!pPriv)
140 return;
141 if (!pPriv->events && !pPriv->hasWindow) {
142 free(pPriv);
143 SetScreenPrivate(pScreen, NULL);
144 }
145}
146
147static XF86VidModeScreenPrivatePtr
148MakeScreenPrivate(pScreen)
149ScreenPtr
150 pScreen;
151{
152 SetupScreen(pScreen);
153
154 if (pPriv)
155 return pPriv;
156 pPriv = New(XF86VidModeScreenPrivateRec);
157 if (!pPriv)
158 return 0;
159 pPriv->events = 0;
160 pPriv->hasWindow = FALSE;
161 SetScreenPrivate(pScreen, pPriv);
162 return pPriv;
163}
164
165static unsigned long
166getEventMask(ScreenPtr pScreen, ClientPtr client)
167{
168 SetupScreen(pScreen);
169 XF86VidModeEventPtr pEv;
170
171 if (!pPriv)
172 return 0;
173 for (pEv = pPriv->events; pEv; pEv = pEv->next)
174 if (pEv->client == client)
175 return pEv->mask;
176 return 0;
177}
178
179static Bool
180setEventMask(ScreenPtr pScreen, ClientPtr client, unsigned long mask)
181{
182 SetupScreen(pScreen);
183 XF86VidModeEventPtr pEv, *pPrev;
184
185 if (getEventMask(pScreen, client) == mask)
186 return TRUE;
187 if (!pPriv) {
188 pPriv = MakeScreenPrivate(pScreen);
189 if (!pPriv)
190 return FALSE;
191 }
192 for (pPrev = &pPriv->events; pEv = *pPrev; pPrev = &pEv->next)
193 if (pEv->client == client)
194 break;
195 if (mask == 0) {
196 *pPrev = pEv->next;
197 free(pEv);
198 CheckScreenPrivate(pScreen);
199 }
200 else {
201 if (!pEv) {
202 pEv = New(ScreenSaverEventRec);
203 if (!pEv) {
204 CheckScreenPrivate(pScreen);
205 return FALSE;
206 }
207 *pPrev = pEv;
208 pEv->next = NULL;
209 pEv->client = client;
210 pEv->screen = pScreen;
211 pEv->resource = FakeClientID(client->index);
212 }
213 pEv->mask = mask;
214 }
215 return TRUE;
216}
217
218static int
219XF86VidModeFreeEvents(pointer value, XID id)
220{
221 XF86VidModeEventPtr pOld = (XF86VidModeEventPtr) value;
222 ScreenPtr pScreen = pOld->screen;
223
224 SetupScreen(pScreen);
225 XF86VidModeEventPtr pEv, *pPrev;
226
227 if (!pPriv)
228 return TRUE;
229 for (pPrev = &pPriv->events; pEv = *pPrev; pPrev = &pEv->next)
230 if (pEv == pOld)
231 break;
232 if (!pEv)
233 return TRUE;
234 *pPrev = pEv->next;
235 free(pEv);
236 CheckScreenPrivate(pScreen);
237 return TRUE;
238}
239
240static void
241SendXF86VidModeNotify(ScreenPtr pScreen, int state, Bool forced)
242{
243 XF86VidModeScreenPrivatePtr pPriv;
244 unsigned long mask;
245 xXF86VidModeNotifyEvent ev;
246 int kind;
247
248 UpdateCurrentTimeIf();
249 mask = XF86VidModeNotifyMask;
250 pScreen = screenInfo.screens[pScreen->myNum];
251 pPriv = GetScreenPrivate(pScreen);
252 if (!pPriv)
253 return;
254 kind = XF86VidModeModeChange;
255 for (pEv = pPriv->events; pEv; pEv = pEv->next) {
256 if (pEv->mask & mask) {
257 XF86VidModeEventPtr pEv = {
258 .type = XF86VidModeNotify + XF86VidModeEventBase,
259 .state = state,
260 .timestamp = currentTime.milliseconds,
261 .root = pScreen->root->drawable.id,
262 .kind = kind,
263 .forced = forced
264 };
265 WriteEventsToClient(pEv->client, 1, (xEvent *) &ev);
266 }
267 }
268}
269
270static void
271SXF86VidModeNotifyEvent(xXF86VidModeNotifyEvent * from,
272 xXF86VidModeNotifyEvent * to)
273{
274 to->type = from->type;
275 to->state = from->state;
276 cpswaps(from->sequenceNumber, to->sequenceNumber);
277 cpswapl(from->timestamp, to->timestamp);
278 cpswapl(from->root, to->root);
279 to->kind = from->kind;
280 to->forced = from->forced;
281}
282#endif
283
284static int
285ProcXF86VidModeQueryVersion(ClientPtr client)
286{
287 xXF86VidModeQueryVersionReply rep = {
288 .type = X_Reply,
289 .sequenceNumber = client->sequence,
290 .length = 0,
291 .majorVersion = SERVER_XF86VIDMODE_MAJOR_VERSION,
292 .minorVersion = SERVER_XF86VIDMODE_MINOR_VERSION
293 };
294
295 DEBUG_P("XF86VidModeQueryVersion");
296
297 REQUEST_SIZE_MATCH(xXF86VidModeQueryVersionReq);
298
299 if (client->swapped) {
300 swaps(&rep.sequenceNumber);
301 swapl(&rep.length);
302 swaps(&rep.majorVersion);
303 swaps(&rep.minorVersion);
304 }
305 WriteToClient(client, sizeof(xXF86VidModeQueryVersionReply), &rep);
306 return Success;
307}
308
309static int
310ProcXF86VidModeGetModeLine(ClientPtr client)
311{
312 REQUEST(xXF86VidModeGetModeLineReq);
313 xXF86VidModeGetModeLineReply rep = {
314 .type = X_Reply,
315 .sequenceNumber = client->sequence
316 };
317 pointer mode;
318 int dotClock;
319 int ver;
320
321 DEBUG_P("XF86VidModeGetModeline");
322
323 ver = ClientMajorVersion(client);
324 REQUEST_SIZE_MATCH(xXF86VidModeGetModeLineReq);
325
326 if (ver < 2) {
327 rep.length = bytes_to_int32(SIZEOF(xXF86OldVidModeGetModeLineReply) -
328 SIZEOF(xGenericReply));
329 }
330 else {
331 rep.length = bytes_to_int32(SIZEOF(xXF86VidModeGetModeLineReply) -
332 SIZEOF(xGenericReply));
333 }
334
335 if (stuff->screen >= screenInfo.numScreens)
336 return BadValue;
337
338 if (!VidModeGetCurrentModeline(stuff->screen, &mode, &dotClock))
339 return BadValue;
340
341 rep.dotclock = dotClock;
342 rep.hdisplay = VidModeGetModeValue(mode, VIDMODE_H_DISPLAY);
343 rep.hsyncstart = VidModeGetModeValue(mode, VIDMODE_H_SYNCSTART);
344 rep.hsyncend = VidModeGetModeValue(mode, VIDMODE_H_SYNCEND);
345 rep.htotal = VidModeGetModeValue(mode, VIDMODE_H_TOTAL);
346 rep.hskew = VidModeGetModeValue(mode, VIDMODE_H_SKEW);
347 rep.vdisplay = VidModeGetModeValue(mode, VIDMODE_V_DISPLAY);
348 rep.vsyncstart = VidModeGetModeValue(mode, VIDMODE_V_SYNCSTART);
349 rep.vsyncend = VidModeGetModeValue(mode, VIDMODE_V_SYNCEND);
350 rep.vtotal = VidModeGetModeValue(mode, VIDMODE_V_TOTAL);
351 rep.flags = VidModeGetModeValue(mode, VIDMODE_FLAGS);
352
353 if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY) {
354 ErrorF("GetModeLine - scrn: %d clock: %ld\n",
355 stuff->screen, (unsigned long) rep.dotclock);
356 ErrorF("GetModeLine - hdsp: %d hbeg: %d hend: %d httl: %d\n",
357 rep.hdisplay, rep.hsyncstart, rep.hsyncend, rep.htotal);
358 ErrorF(" vdsp: %d vbeg: %d vend: %d vttl: %d flags: %ld\n",
359 rep.vdisplay, rep.vsyncstart, rep.vsyncend,
360 rep.vtotal, (unsigned long) rep.flags);
361 }
362
363 /*
364 * Older servers sometimes had server privates that the VidMode
365 * extention made available. So to be compatiable pretend that
366 * there are no server privates to pass to the client
367 */
368 rep.privsize = 0;
369
370 if (client->swapped) {
371 swaps(&rep.sequenceNumber);
372 swapl(&rep.length);
373 swapl(&rep.dotclock);
374 swaps(&rep.hdisplay);
375 swaps(&rep.hsyncstart);
376 swaps(&rep.hsyncend);
377 swaps(&rep.htotal);
378 swaps(&rep.hskew);
379 swaps(&rep.vdisplay);
380 swaps(&rep.vsyncstart);
381 swaps(&rep.vsyncend);
382 swaps(&rep.vtotal);
383 swapl(&rep.flags);
384 swapl(&rep.privsize);
385 }
386 if (ver < 2) {
387 xXF86OldVidModeGetModeLineReply oldrep = {
388 .type = rep.type,
389 .sequenceNumber = rep.sequenceNumber,
390 .length = rep.length,
391 .dotclock = rep.dotclock,
392 .hdisplay = rep.hdisplay,
393 .hsyncstart = rep.hsyncstart,
394 .hsyncend = rep.hsyncend,
395 .htotal = rep.htotal,
396 .vdisplay = rep.vdisplay,
397 .vsyncstart = rep.vsyncstart,
398 .vsyncend = rep.vsyncend,
399 .vtotal = rep.vtotal,
400 .flags = rep.flags,
401 .privsize = rep.privsize
402 };
403 WriteToClient(client, sizeof(xXF86OldVidModeGetModeLineReply), &oldrep);
404 }
405 else {
406 WriteToClient(client, sizeof(xXF86VidModeGetModeLineReply), &rep);
407 }
408 return Success;
409}
410
411static int
412ProcXF86VidModeGetAllModeLines(ClientPtr client)
413{
414 REQUEST(xXF86VidModeGetAllModeLinesReq);
415 xXF86VidModeGetAllModeLinesReply rep;
416 pointer mode;
417 int modecount, dotClock;
418 int ver;
419
420 DEBUG_P("XF86VidModeGetAllModelines");
421
422 REQUEST_SIZE_MATCH(xXF86VidModeGetAllModeLinesReq);
423
424 if (stuff->screen >= screenInfo.numScreens)
425 return BadValue;
426
427 ver = ClientMajorVersion(client);
428
429 modecount = VidModeGetNumOfModes(stuff->screen);
430 if (modecount < 1)
431 return VidModeErrorBase + XF86VidModeExtensionDisabled;
432
433 if (!VidModeGetFirstModeline(stuff->screen, &mode, &dotClock))
434 return BadValue;
435
436 rep = (xXF86VidModeGetAllModeLinesReply) {
437 .type = X_Reply,
438 .length = SIZEOF(xXF86VidModeGetAllModeLinesReply) -
439 SIZEOF(xGenericReply),
440 .sequenceNumber = client->sequence,
441 .modecount = modecount
442 };
443 if (ver < 2)
444 rep.length += modecount * sizeof(xXF86OldVidModeModeInfo);
445 else
446 rep.length += modecount * sizeof(xXF86VidModeModeInfo);
447 rep.length >>= 2;
448 if (client->swapped) {
449 swaps(&rep.sequenceNumber);
450 swapl(&rep.length);
451 swapl(&rep.modecount);
452 }
453 WriteToClient(client, sizeof(xXF86VidModeGetAllModeLinesReply), &rep);
454
455 do {
456 xXF86VidModeModeInfo mdinf = {
457 .dotclock = dotClock,
458 .hdisplay = VidModeGetModeValue(mode, VIDMODE_H_DISPLAY),
459 .hsyncstart = VidModeGetModeValue(mode, VIDMODE_H_SYNCSTART),
460 .hsyncend = VidModeGetModeValue(mode, VIDMODE_H_SYNCEND),
461 .htotal = VidModeGetModeValue(mode, VIDMODE_H_TOTAL),
462 .hskew = VidModeGetModeValue(mode, VIDMODE_H_SKEW),
463 .vdisplay = VidModeGetModeValue(mode, VIDMODE_V_DISPLAY),
464 .vsyncstart = VidModeGetModeValue(mode, VIDMODE_V_SYNCSTART),
465 .vsyncend = VidModeGetModeValue(mode, VIDMODE_V_SYNCEND),
466 .vtotal = VidModeGetModeValue(mode, VIDMODE_V_TOTAL),
467 .flags = VidModeGetModeValue(mode, VIDMODE_FLAGS),
468 .privsize = 0
469 };
470 if (client->swapped) {
471 swapl(&mdinf.dotclock);
472 swaps(&mdinf.hdisplay);
473 swaps(&mdinf.hsyncstart);
474 swaps(&mdinf.hsyncend);
475 swaps(&mdinf.htotal);
476 swapl(&mdinf.hskew);
477 swaps(&mdinf.vdisplay);
478 swaps(&mdinf.vsyncstart);
479 swaps(&mdinf.vsyncend);
480 swaps(&mdinf.vtotal);
481 swapl(&mdinf.flags);
482 swapl(&mdinf.privsize);
483 }
484 if (ver < 2) {
485 xXF86OldVidModeModeInfo oldmdinf = {
486 .dotclock = mdinf.dotclock,
487 .hdisplay = mdinf.hdisplay,
488 .hsyncstart = mdinf.hsyncstart,
489 .hsyncend = mdinf.hsyncend,
490 .htotal = mdinf.htotal,
491 .vdisplay = mdinf.vdisplay,
492 .vsyncstart = mdinf.vsyncstart,
493 .vsyncend = mdinf.vsyncend,
494 .vtotal = mdinf.vtotal,
495 .flags = mdinf.flags,
496 .privsize = mdinf.privsize
497 };
498 WriteToClient(client, sizeof(xXF86OldVidModeModeInfo), &oldmdinf);
499 }
500 else {
501 WriteToClient(client, sizeof(xXF86VidModeModeInfo), &mdinf);
502 }
503
504 } while (VidModeGetNextModeline(stuff->screen, &mode, &dotClock));
505
506 return Success;
507}
508
509#define MODEMATCH(mode,stuff) \
510 (VidModeGetModeValue(mode, VIDMODE_H_DISPLAY) == stuff->hdisplay \
511 && VidModeGetModeValue(mode, VIDMODE_H_SYNCSTART) == stuff->hsyncstart \
512 && VidModeGetModeValue(mode, VIDMODE_H_SYNCEND) == stuff->hsyncend \
513 && VidModeGetModeValue(mode, VIDMODE_H_TOTAL) == stuff->htotal \
514 && VidModeGetModeValue(mode, VIDMODE_V_DISPLAY) == stuff->vdisplay \
515 && VidModeGetModeValue(mode, VIDMODE_V_SYNCSTART) == stuff->vsyncstart \
516 && VidModeGetModeValue(mode, VIDMODE_V_SYNCEND) == stuff->vsyncend \
517 && VidModeGetModeValue(mode, VIDMODE_V_TOTAL) == stuff->vtotal \
518 && VidModeGetModeValue(mode, VIDMODE_FLAGS) == stuff->flags )
519
520static int
521ProcXF86VidModeAddModeLine(ClientPtr client)
522{
523 REQUEST(xXF86VidModeAddModeLineReq);
524 xXF86OldVidModeAddModeLineReq *oldstuff =
525 (xXF86OldVidModeAddModeLineReq *) client->requestBuffer;
526 xXF86VidModeAddModeLineReq newstuff;
527 pointer mode;
528 int len;
529 int dotClock;
530 int ver;
531
532 DEBUG_P("XF86VidModeAddModeline");
533
534 ver = ClientMajorVersion(client);
535 if (ver < 2) {
536 /* convert from old format */
537 stuff = &newstuff;
538 stuff->length = oldstuff->length;
539 stuff->screen = oldstuff->screen;
540 stuff->dotclock = oldstuff->dotclock;
541 stuff->hdisplay = oldstuff->hdisplay;
542 stuff->hsyncstart = oldstuff->hsyncstart;
543 stuff->hsyncend = oldstuff->hsyncend;
544 stuff->htotal = oldstuff->htotal;
545 stuff->hskew = 0;
546 stuff->vdisplay = oldstuff->vdisplay;
547 stuff->vsyncstart = oldstuff->vsyncstart;
548 stuff->vsyncend = oldstuff->vsyncend;
549 stuff->vtotal = oldstuff->vtotal;
550 stuff->flags = oldstuff->flags;
551 stuff->privsize = oldstuff->privsize;
552 stuff->after_dotclock = oldstuff->after_dotclock;
553 stuff->after_hdisplay = oldstuff->after_hdisplay;
554 stuff->after_hsyncstart = oldstuff->after_hsyncstart;
555 stuff->after_hsyncend = oldstuff->after_hsyncend;
556 stuff->after_htotal = oldstuff->after_htotal;
557 stuff->after_hskew = 0;
558 stuff->after_vdisplay = oldstuff->after_vdisplay;
559 stuff->after_vsyncstart = oldstuff->after_vsyncstart;
560 stuff->after_vsyncend = oldstuff->after_vsyncend;
561 stuff->after_vtotal = oldstuff->after_vtotal;
562 stuff->after_flags = oldstuff->after_flags;
563 }
564 if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY) {
565 ErrorF("AddModeLine - scrn: %d clock: %ld\n",
566 (int) stuff->screen, (unsigned long) stuff->dotclock);
567 ErrorF("AddModeLine - hdsp: %d hbeg: %d hend: %d httl: %d\n",
568 stuff->hdisplay, stuff->hsyncstart,
569 stuff->hsyncend, stuff->htotal);
570 ErrorF(" vdsp: %d vbeg: %d vend: %d vttl: %d flags: %ld\n",
571 stuff->vdisplay, stuff->vsyncstart, stuff->vsyncend,
572 stuff->vtotal, (unsigned long) stuff->flags);
573 ErrorF(" after - scrn: %d clock: %ld\n",
574 (int) stuff->screen, (unsigned long) stuff->after_dotclock);
575 ErrorF(" hdsp: %d hbeg: %d hend: %d httl: %d\n",
576 stuff->after_hdisplay, stuff->after_hsyncstart,
577 stuff->after_hsyncend, stuff->after_htotal);
578 ErrorF(" vdsp: %d vbeg: %d vend: %d vttl: %d flags: %ld\n",
579 stuff->after_vdisplay, stuff->after_vsyncstart,
580 stuff->after_vsyncend, stuff->after_vtotal,
581 (unsigned long) stuff->after_flags);
582 }
583
584 if (ver < 2) {
585 REQUEST_AT_LEAST_SIZE(xXF86OldVidModeAddModeLineReq);
586 len =
587 client->req_len -
588 bytes_to_int32(sizeof(xXF86OldVidModeAddModeLineReq));
589 }
590 else {
591 REQUEST_AT_LEAST_SIZE(xXF86VidModeAddModeLineReq);
592 len =
593 client->req_len -
594 bytes_to_int32(sizeof(xXF86VidModeAddModeLineReq));
595 }
596 if (len != stuff->privsize)
597 return BadLength;
598
599 if (stuff->screen >= screenInfo.numScreens)
600 return BadValue;
601
602 if (stuff->hsyncstart < stuff->hdisplay ||
603 stuff->hsyncend < stuff->hsyncstart ||
604 stuff->htotal < stuff->hsyncend ||
605 stuff->vsyncstart < stuff->vdisplay ||
606 stuff->vsyncend < stuff->vsyncstart || stuff->vtotal < stuff->vsyncend)
607 return BadValue;
608
609 if (stuff->after_hsyncstart < stuff->after_hdisplay ||
610 stuff->after_hsyncend < stuff->after_hsyncstart ||
611 stuff->after_htotal < stuff->after_hsyncend ||
612 stuff->after_vsyncstart < stuff->after_vdisplay ||
613 stuff->after_vsyncend < stuff->after_vsyncstart ||
614 stuff->after_vtotal < stuff->after_vsyncend)
615 return BadValue;
616
617 if (stuff->after_htotal != 0 || stuff->after_vtotal != 0) {
618 Bool found = FALSE;
619
620 if (VidModeGetFirstModeline(stuff->screen, &mode, &dotClock)) {
621 do {
622 if ((VidModeGetDotClock(stuff->screen, stuff->dotclock)
623 == dotClock) && MODEMATCH(mode, stuff)) {
624 found = TRUE;
625 break;
626 }
627 } while (VidModeGetNextModeline(stuff->screen, &mode, &dotClock));
628 }
629 if (!found)
630 return BadValue;
631 }
632
633 mode = VidModeCreateMode();
634 if (mode == NULL)
635 return BadValue;
636
637 VidModeSetModeValue(mode, VIDMODE_CLOCK, stuff->dotclock);
638 VidModeSetModeValue(mode, VIDMODE_H_DISPLAY, stuff->hdisplay);
639 VidModeSetModeValue(mode, VIDMODE_H_SYNCSTART, stuff->hsyncstart);
640 VidModeSetModeValue(mode, VIDMODE_H_SYNCEND, stuff->hsyncend);
641 VidModeSetModeValue(mode, VIDMODE_H_TOTAL, stuff->htotal);
642 VidModeSetModeValue(mode, VIDMODE_H_SKEW, stuff->hskew);
643 VidModeSetModeValue(mode, VIDMODE_V_DISPLAY, stuff->vdisplay);
644 VidModeSetModeValue(mode, VIDMODE_V_SYNCSTART, stuff->vsyncstart);
645 VidModeSetModeValue(mode, VIDMODE_V_SYNCEND, stuff->vsyncend);
646 VidModeSetModeValue(mode, VIDMODE_V_TOTAL, stuff->vtotal);
647 VidModeSetModeValue(mode, VIDMODE_FLAGS, stuff->flags);
648
649 if (stuff->privsize)
650 ErrorF("AddModeLine - Privates in request have been ignored\n");
651
652 /* Check that the mode is consistent with the monitor specs */
653 switch (VidModeCheckModeForMonitor(stuff->screen, mode)) {
654 case MODE_OK:
655 break;
656 case MODE_HSYNC:
657 case MODE_H_ILLEGAL:
658 free(mode);
659 return VidModeErrorBase + XF86VidModeBadHTimings;
660 case MODE_VSYNC:
661 case MODE_V_ILLEGAL:
662 free(mode);
663 return VidModeErrorBase + XF86VidModeBadVTimings;
664 default:
665 free(mode);
666 return VidModeErrorBase + XF86VidModeModeUnsuitable;
667 }
668
669 /* Check that the driver is happy with the mode */
670 if (VidModeCheckModeForDriver(stuff->screen, mode) != MODE_OK) {
671 free(mode);
672 return VidModeErrorBase + XF86VidModeModeUnsuitable;
673 }
674
675 VidModeSetCrtcForMode(stuff->screen, mode);
676
677 VidModeAddModeline(stuff->screen, mode);
678
679 if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY)
680 ErrorF("AddModeLine - Succeeded\n");
681 return Success;
682}
683
684static int
685ProcXF86VidModeDeleteModeLine(ClientPtr client)
686{
687 REQUEST(xXF86VidModeDeleteModeLineReq);
688 xXF86OldVidModeDeleteModeLineReq *oldstuff =
689 (xXF86OldVidModeDeleteModeLineReq *) client->requestBuffer;
690 xXF86VidModeDeleteModeLineReq newstuff;
691 pointer mode;
692 int len, dotClock;
693 int ver;
694
695 DEBUG_P("XF86VidModeDeleteModeline");
696
697 ver = ClientMajorVersion(client);
698 if (ver < 2) {
699 /* convert from old format */
700 stuff = &newstuff;
701 stuff->length = oldstuff->length;
702 stuff->screen = oldstuff->screen;
703 stuff->dotclock = oldstuff->dotclock;
704 stuff->hdisplay = oldstuff->hdisplay;
705 stuff->hsyncstart = oldstuff->hsyncstart;
706 stuff->hsyncend = oldstuff->hsyncend;
707 stuff->htotal = oldstuff->htotal;
708 stuff->hskew = 0;
709 stuff->vdisplay = oldstuff->vdisplay;
710 stuff->vsyncstart = oldstuff->vsyncstart;
711 stuff->vsyncend = oldstuff->vsyncend;
712 stuff->vtotal = oldstuff->vtotal;
713 stuff->flags = oldstuff->flags;
714 stuff->privsize = oldstuff->privsize;
715 }
716 if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY) {
717 ErrorF("DeleteModeLine - scrn: %d clock: %ld\n",
718 (int) stuff->screen, (unsigned long) stuff->dotclock);
719 ErrorF(" hdsp: %d hbeg: %d hend: %d httl: %d\n",
720 stuff->hdisplay, stuff->hsyncstart,
721 stuff->hsyncend, stuff->htotal);
722 ErrorF
723 (" vdsp: %d vbeg: %d vend: %d vttl: %d flags: %ld\n",
724 stuff->vdisplay, stuff->vsyncstart, stuff->vsyncend, stuff->vtotal,
725 (unsigned long) stuff->flags);
726 }
727
728 if (ver < 2) {
729 REQUEST_AT_LEAST_SIZE(xXF86OldVidModeDeleteModeLineReq);
730 len =
731 client->req_len -
732 bytes_to_int32(sizeof(xXF86OldVidModeDeleteModeLineReq));
733 }
734 else {
735 REQUEST_AT_LEAST_SIZE(xXF86VidModeDeleteModeLineReq);
736 len =
737 client->req_len -
738 bytes_to_int32(sizeof(xXF86VidModeDeleteModeLineReq));
739 }
740 if (len != stuff->privsize) {
741 if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY) {
742 ErrorF("req_len = %ld, sizeof(Req) = %d, privsize = %ld, "
743 "len = %d, length = %d\n",
744 (unsigned long) client->req_len,
745 (int) sizeof(xXF86VidModeDeleteModeLineReq) >> 2,
746 (unsigned long) stuff->privsize, len, stuff->length);
747 }
748 return BadLength;
749 }
750
751 if (stuff->screen >= screenInfo.numScreens)
752 return BadValue;
753
754 if (!VidModeGetCurrentModeline(stuff->screen, &mode, &dotClock))
755 return BadValue;
756
757 if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY) {
758 ErrorF("Checking against clock: %d (%d)\n",
759 VidModeGetModeValue(mode, VIDMODE_CLOCK), dotClock);
760 ErrorF(" hdsp: %d hbeg: %d hend: %d httl: %d\n",
761 VidModeGetModeValue(mode, VIDMODE_H_DISPLAY),
762 VidModeGetModeValue(mode, VIDMODE_H_SYNCSTART),
763 VidModeGetModeValue(mode, VIDMODE_H_SYNCEND),
764 VidModeGetModeValue(mode, VIDMODE_H_TOTAL));
765 ErrorF
766 (" vdsp: %d vbeg: %d vend: %d vttl: %d flags: %d\n",
767 VidModeGetModeValue(mode, VIDMODE_V_DISPLAY),
768 VidModeGetModeValue(mode, VIDMODE_V_SYNCSTART),
769 VidModeGetModeValue(mode, VIDMODE_V_SYNCEND),
770 VidModeGetModeValue(mode, VIDMODE_V_TOTAL),
771 VidModeGetModeValue(mode, VIDMODE_FLAGS));
772 }
773 if ((VidModeGetDotClock(stuff->screen, stuff->dotclock) == dotClock) &&
774 MODEMATCH(mode, stuff))
775 return BadValue;
776
777 if (!VidModeGetFirstModeline(stuff->screen, &mode, &dotClock))
778 return BadValue;
779
780 do {
781 if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY) {
782 ErrorF("Checking against clock: %d (%d)\n",
783 VidModeGetModeValue(mode, VIDMODE_CLOCK), dotClock);
784 ErrorF(" hdsp: %d hbeg: %d hend: %d httl: %d\n",
785 VidModeGetModeValue(mode, VIDMODE_H_DISPLAY),
786 VidModeGetModeValue(mode, VIDMODE_H_SYNCSTART),
787 VidModeGetModeValue(mode, VIDMODE_H_SYNCEND),
788 VidModeGetModeValue(mode, VIDMODE_H_TOTAL));
789 ErrorF
790 (" vdsp: %d vbeg: %d vend: %d vttl: %d flags: %d\n",
791 VidModeGetModeValue(mode, VIDMODE_V_DISPLAY),
792 VidModeGetModeValue(mode, VIDMODE_V_SYNCSTART),
793 VidModeGetModeValue(mode, VIDMODE_V_SYNCEND),
794 VidModeGetModeValue(mode, VIDMODE_V_TOTAL),
795 VidModeGetModeValue(mode, VIDMODE_FLAGS));
796 }
797 if ((VidModeGetDotClock(stuff->screen, stuff->dotclock) == dotClock) &&
798 MODEMATCH(mode, stuff)) {
799 VidModeDeleteModeline(stuff->screen, mode);
800 if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY)
801 ErrorF("DeleteModeLine - Succeeded\n");
802 return Success;
803 }
804 } while (VidModeGetNextModeline(stuff->screen, &mode, &dotClock));
805
806 return BadValue;
807}
808
809static int
810ProcXF86VidModeModModeLine(ClientPtr client)
811{
812 REQUEST(xXF86VidModeModModeLineReq);
813 xXF86OldVidModeModModeLineReq *oldstuff =
814 (xXF86OldVidModeModModeLineReq *) client->requestBuffer;
815 xXF86VidModeModModeLineReq newstuff;
816 pointer mode, modetmp;
817 int len, dotClock;
818 int ver;
819
820 DEBUG_P("XF86VidModeModModeline");
821
822 ver = ClientMajorVersion(client);
823 if (ver < 2) {
824 /* convert from old format */
825 stuff = &newstuff;
826 stuff->length = oldstuff->length;
827 stuff->screen = oldstuff->screen;
828 stuff->hdisplay = oldstuff->hdisplay;
829 stuff->hsyncstart = oldstuff->hsyncstart;
830 stuff->hsyncend = oldstuff->hsyncend;
831 stuff->htotal = oldstuff->htotal;
832 stuff->hskew = 0;
833 stuff->vdisplay = oldstuff->vdisplay;
834 stuff->vsyncstart = oldstuff->vsyncstart;
835 stuff->vsyncend = oldstuff->vsyncend;
836 stuff->vtotal = oldstuff->vtotal;
837 stuff->flags = oldstuff->flags;
838 stuff->privsize = oldstuff->privsize;
839 }
840 if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY) {
841 ErrorF("ModModeLine - scrn: %d hdsp: %d hbeg: %d hend: %d httl: %d\n",
842 (int) stuff->screen, stuff->hdisplay, stuff->hsyncstart,
843 stuff->hsyncend, stuff->htotal);
844 ErrorF(" vdsp: %d vbeg: %d vend: %d vttl: %d flags: %ld\n",
845 stuff->vdisplay, stuff->vsyncstart, stuff->vsyncend,
846 stuff->vtotal, (unsigned long) stuff->flags);
847 }
848
849 if (ver < 2) {
850 REQUEST_AT_LEAST_SIZE(xXF86OldVidModeModModeLineReq);
851 len =
852 client->req_len -
853 bytes_to_int32(sizeof(xXF86OldVidModeModModeLineReq));
854 }
855 else {
856 REQUEST_AT_LEAST_SIZE(xXF86VidModeModModeLineReq);
857 len =
858 client->req_len -
859 bytes_to_int32(sizeof(xXF86VidModeModModeLineReq));
860 }
861 if (len != stuff->privsize)
862 return BadLength;
863
864 if (stuff->hsyncstart < stuff->hdisplay ||
865 stuff->hsyncend < stuff->hsyncstart ||
866 stuff->htotal < stuff->hsyncend ||
867 stuff->vsyncstart < stuff->vdisplay ||
868 stuff->vsyncend < stuff->vsyncstart || stuff->vtotal < stuff->vsyncend)
869 return BadValue;
870
871 if (stuff->screen >= screenInfo.numScreens)
872 return BadValue;
873
874 if (!VidModeGetCurrentModeline(stuff->screen, &mode, &dotClock))
875 return BadValue;
876
877 modetmp = VidModeCreateMode();
878 VidModeCopyMode(mode, modetmp);
879
880 VidModeSetModeValue(modetmp, VIDMODE_H_DISPLAY, stuff->hdisplay);
881 VidModeSetModeValue(modetmp, VIDMODE_H_SYNCSTART, stuff->hsyncstart);
882 VidModeSetModeValue(modetmp, VIDMODE_H_SYNCEND, stuff->hsyncend);
883 VidModeSetModeValue(modetmp, VIDMODE_H_TOTAL, stuff->htotal);
884 VidModeSetModeValue(modetmp, VIDMODE_H_SKEW, stuff->hskew);
885 VidModeSetModeValue(modetmp, VIDMODE_V_DISPLAY, stuff->vdisplay);
886 VidModeSetModeValue(modetmp, VIDMODE_V_SYNCSTART, stuff->vsyncstart);
887 VidModeSetModeValue(modetmp, VIDMODE_V_SYNCEND, stuff->vsyncend);
888 VidModeSetModeValue(modetmp, VIDMODE_V_TOTAL, stuff->vtotal);
889 VidModeSetModeValue(modetmp, VIDMODE_FLAGS, stuff->flags);
890
891 if (stuff->privsize)
892 ErrorF("ModModeLine - Privates in request have been ignored\n");
893
894 /* Check that the mode is consistent with the monitor specs */
895 switch (VidModeCheckModeForMonitor(stuff->screen, modetmp)) {
896 case MODE_OK:
897 break;
898 case MODE_HSYNC:
899 case MODE_H_ILLEGAL:
900 free(modetmp);
901 return VidModeErrorBase + XF86VidModeBadHTimings;
902 case MODE_VSYNC:
903 case MODE_V_ILLEGAL:
904 free(modetmp);
905 return VidModeErrorBase + XF86VidModeBadVTimings;
906 default:
907 free(modetmp);
908 return VidModeErrorBase + XF86VidModeModeUnsuitable;
909 }
910
911 /* Check that the driver is happy with the mode */
912 if (VidModeCheckModeForDriver(stuff->screen, modetmp) != MODE_OK) {
913 free(modetmp);
914 return VidModeErrorBase + XF86VidModeModeUnsuitable;
915 }
916 free(modetmp);
917
918 VidModeSetModeValue(mode, VIDMODE_H_DISPLAY, stuff->hdisplay);
919 VidModeSetModeValue(mode, VIDMODE_H_SYNCSTART, stuff->hsyncstart);
920 VidModeSetModeValue(mode, VIDMODE_H_SYNCEND, stuff->hsyncend);
921 VidModeSetModeValue(mode, VIDMODE_H_TOTAL, stuff->htotal);
922 VidModeSetModeValue(mode, VIDMODE_H_SKEW, stuff->hskew);
923 VidModeSetModeValue(mode, VIDMODE_V_DISPLAY, stuff->vdisplay);
924 VidModeSetModeValue(mode, VIDMODE_V_SYNCSTART, stuff->vsyncstart);
925 VidModeSetModeValue(mode, VIDMODE_V_SYNCEND, stuff->vsyncend);
926 VidModeSetModeValue(mode, VIDMODE_V_TOTAL, stuff->vtotal);
927 VidModeSetModeValue(mode, VIDMODE_FLAGS, stuff->flags);
928
929 VidModeSetCrtcForMode(stuff->screen, mode);
930 VidModeSwitchMode(stuff->screen, mode);
931
932 if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY)
933 ErrorF("ModModeLine - Succeeded\n");
934 return Success;
935}
936
937static int
938ProcXF86VidModeValidateModeLine(ClientPtr client)
939{
940 REQUEST(xXF86VidModeValidateModeLineReq);
941 xXF86OldVidModeValidateModeLineReq *oldstuff =
942 (xXF86OldVidModeValidateModeLineReq *) client->requestBuffer;
943 xXF86VidModeValidateModeLineReq newstuff;
944 xXF86VidModeValidateModeLineReply rep;
945 pointer mode, modetmp = NULL;
946 int len, status, dotClock;
947 int ver;
948
949 DEBUG_P("XF86VidModeValidateModeline");
950
951 ver = ClientMajorVersion(client);
952 if (ver < 2) {
953 /* convert from old format */
954 stuff = &newstuff;
955 stuff->length = oldstuff->length;
956 stuff->screen = oldstuff->screen;
957 stuff->dotclock = oldstuff->dotclock;
958 stuff->hdisplay = oldstuff->hdisplay;
959 stuff->hsyncstart = oldstuff->hsyncstart;
960 stuff->hsyncend = oldstuff->hsyncend;
961 stuff->htotal = oldstuff->htotal;
962 stuff->hskew = 0;
963 stuff->vdisplay = oldstuff->vdisplay;
964 stuff->vsyncstart = oldstuff->vsyncstart;
965 stuff->vsyncend = oldstuff->vsyncend;
966 stuff->vtotal = oldstuff->vtotal;
967 stuff->flags = oldstuff->flags;
968 stuff->privsize = oldstuff->privsize;
969 }
970 if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY) {
971 ErrorF("ValidateModeLine - scrn: %d clock: %ld\n",
972 (int) stuff->screen, (unsigned long) stuff->dotclock);
973 ErrorF(" hdsp: %d hbeg: %d hend: %d httl: %d\n",
974 stuff->hdisplay, stuff->hsyncstart,
975 stuff->hsyncend, stuff->htotal);
976 ErrorF
977 (" vdsp: %d vbeg: %d vend: %d vttl: %d flags: %ld\n",
978 stuff->vdisplay, stuff->vsyncstart, stuff->vsyncend, stuff->vtotal,
979 (unsigned long) stuff->flags);
980 }
981
982 if (ver < 2) {
983 REQUEST_AT_LEAST_SIZE(xXF86OldVidModeValidateModeLineReq);
984 len = client->req_len -
985 bytes_to_int32(sizeof(xXF86OldVidModeValidateModeLineReq));
986 }
987 else {
988 REQUEST_AT_LEAST_SIZE(xXF86VidModeValidateModeLineReq);
989 len =
990 client->req_len -
991 bytes_to_int32(sizeof(xXF86VidModeValidateModeLineReq));
992 }
993 if (len != stuff->privsize)
994 return BadLength;
995
996 if (stuff->screen >= screenInfo.numScreens)
997 return BadValue;
998
999 status = MODE_OK;
1000
1001 if (stuff->hsyncstart < stuff->hdisplay ||
1002 stuff->hsyncend < stuff->hsyncstart ||
1003 stuff->htotal < stuff->hsyncend ||
1004 stuff->vsyncstart < stuff->vdisplay ||
1005 stuff->vsyncend < stuff->vsyncstart ||
1006 stuff->vtotal < stuff->vsyncend) {
1007 status = MODE_BAD;
1008 goto status_reply;
1009 }
1010
1011 if (!VidModeGetCurrentModeline(stuff->screen, &mode, &dotClock))
1012 return BadValue;
1013
1014 modetmp = VidModeCreateMode();
1015 VidModeCopyMode(mode, modetmp);
1016
1017 VidModeSetModeValue(modetmp, VIDMODE_H_DISPLAY, stuff->hdisplay);
1018 VidModeSetModeValue(modetmp, VIDMODE_H_SYNCSTART, stuff->hsyncstart);
1019 VidModeSetModeValue(modetmp, VIDMODE_H_SYNCEND, stuff->hsyncend);
1020 VidModeSetModeValue(modetmp, VIDMODE_H_TOTAL, stuff->htotal);
1021 VidModeSetModeValue(modetmp, VIDMODE_H_SKEW, stuff->hskew);
1022 VidModeSetModeValue(modetmp, VIDMODE_V_DISPLAY, stuff->vdisplay);
1023 VidModeSetModeValue(modetmp, VIDMODE_V_SYNCSTART, stuff->vsyncstart);
1024 VidModeSetModeValue(modetmp, VIDMODE_V_SYNCEND, stuff->vsyncend);
1025 VidModeSetModeValue(modetmp, VIDMODE_V_TOTAL, stuff->vtotal);
1026 VidModeSetModeValue(modetmp, VIDMODE_FLAGS, stuff->flags);
1027 if (stuff->privsize)
1028 ErrorF("ValidateModeLine - Privates in request have been ignored\n");
1029
1030 /* Check that the mode is consistent with the monitor specs */
1031 if ((status =
1032 VidModeCheckModeForMonitor(stuff->screen, modetmp)) != MODE_OK)
1033 goto status_reply;
1034
1035 /* Check that the driver is happy with the mode */
1036 status = VidModeCheckModeForDriver(stuff->screen, modetmp);
1037
1038 status_reply:
1039 free(modetmp);
1040
1041 rep = (xXF86VidModeValidateModeLineReply) {
1042 .type = X_Reply,
1043 .sequenceNumber = client->sequence,
1044 .length = bytes_to_int32(SIZEOF(xXF86VidModeValidateModeLineReply)
1045 - SIZEOF(xGenericReply)),
1046 .status = status
1047 };
1048 if (client->swapped) {
1049 swaps(&rep.sequenceNumber);
1050 swapl(&rep.length);
1051 swapl(&rep.status);
1052 }
1053 WriteToClient(client, sizeof(xXF86VidModeValidateModeLineReply), &rep);
1054 if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY)
1055 ErrorF("ValidateModeLine - Succeeded (status = %d)\n", status);
1056 return Success;
1057}
1058
1059static int
1060ProcXF86VidModeSwitchMode(ClientPtr client)
1061{
1062 REQUEST(xXF86VidModeSwitchModeReq);
1063
1064 DEBUG_P("XF86VidModeSwitchMode");
1065
1066 REQUEST_SIZE_MATCH(xXF86VidModeSwitchModeReq);
1067
1068 if (stuff->screen >= screenInfo.numScreens)
1069 return BadValue;
1070
1071 VidModeZoomViewport(stuff->screen, (short) stuff->zoom);
1072
1073 return Success;
1074}
1075
1076static int
1077ProcXF86VidModeSwitchToMode(ClientPtr client)
1078{
1079 REQUEST(xXF86VidModeSwitchToModeReq);
1080 xXF86OldVidModeSwitchToModeReq *oldstuff =
1081 (xXF86OldVidModeSwitchToModeReq *) client->requestBuffer;
1082 xXF86VidModeSwitchToModeReq newstuff;
1083 pointer mode;
1084 int len, dotClock;
1085 int ver;
1086
1087 DEBUG_P("XF86VidModeSwitchToMode");
1088
1089 ver = ClientMajorVersion(client);
1090 if (ver < 2) {
1091 /* convert from old format */
1092 stuff = &newstuff;
1093 stuff->length = oldstuff->length;
1094 stuff->screen = oldstuff->screen;
1095 stuff->dotclock = oldstuff->dotclock;
1096 stuff->hdisplay = oldstuff->hdisplay;
1097 stuff->hsyncstart = oldstuff->hsyncstart;
1098 stuff->hsyncend = oldstuff->hsyncend;
1099 stuff->htotal = oldstuff->htotal;
1100 stuff->hskew = 0;
1101 stuff->vdisplay = oldstuff->vdisplay;
1102 stuff->vsyncstart = oldstuff->vsyncstart;
1103 stuff->vsyncend = oldstuff->vsyncend;
1104 stuff->vtotal = oldstuff->vtotal;
1105 stuff->flags = oldstuff->flags;
1106 stuff->privsize = oldstuff->privsize;
1107 }
1108 if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY) {
1109 ErrorF("SwitchToMode - scrn: %d clock: %ld\n",
1110 (int) stuff->screen, (unsigned long) stuff->dotclock);
1111 ErrorF(" hdsp: %d hbeg: %d hend: %d httl: %d\n",
1112 stuff->hdisplay, stuff->hsyncstart,
1113 stuff->hsyncend, stuff->htotal);
1114 ErrorF
1115 (" vdsp: %d vbeg: %d vend: %d vttl: %d flags: %ld\n",
1116 stuff->vdisplay, stuff->vsyncstart, stuff->vsyncend, stuff->vtotal,
1117 (unsigned long) stuff->flags);
1118 }
1119
1120 if (ver < 2) {
1121 REQUEST_AT_LEAST_SIZE(xXF86OldVidModeSwitchToModeReq);
1122 len =
1123 client->req_len -
1124 bytes_to_int32(sizeof(xXF86OldVidModeSwitchToModeReq));
1125 }
1126 else {
1127 REQUEST_AT_LEAST_SIZE(xXF86VidModeSwitchToModeReq);
1128 len =
1129 client->req_len -
1130 bytes_to_int32(sizeof(xXF86VidModeSwitchToModeReq));
1131 }
1132 if (len != stuff->privsize)
1133 return BadLength;
1134
1135 if (stuff->screen >= screenInfo.numScreens)
1136 return BadValue;
1137
1138 if (!VidModeGetCurrentModeline(stuff->screen, &mode, &dotClock))
1139 return BadValue;
1140
1141 if ((VidModeGetDotClock(stuff->screen, stuff->dotclock) == dotClock)
1142 && MODEMATCH(mode, stuff))
1143 return Success;
1144
1145 if (!VidModeGetFirstModeline(stuff->screen, &mode, &dotClock))
1146 return BadValue;
1147
1148 do {
1149 if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY) {
1150 ErrorF("Checking against clock: %d (%d)\n",
1151 VidModeGetModeValue(mode, VIDMODE_CLOCK), dotClock);
1152 ErrorF(" hdsp: %d hbeg: %d hend: %d httl: %d\n",
1153 VidModeGetModeValue(mode, VIDMODE_H_DISPLAY),
1154 VidModeGetModeValue(mode, VIDMODE_H_SYNCSTART),
1155 VidModeGetModeValue(mode, VIDMODE_H_SYNCEND),
1156 VidModeGetModeValue(mode, VIDMODE_H_TOTAL));
1157 ErrorF
1158 (" vdsp: %d vbeg: %d vend: %d vttl: %d flags: %d\n",
1159 VidModeGetModeValue(mode, VIDMODE_V_DISPLAY),
1160 VidModeGetModeValue(mode, VIDMODE_V_SYNCSTART),
1161 VidModeGetModeValue(mode, VIDMODE_V_SYNCEND),
1162 VidModeGetModeValue(mode, VIDMODE_V_TOTAL),
1163 VidModeGetModeValue(mode, VIDMODE_FLAGS));
1164 }
1165 if ((VidModeGetDotClock(stuff->screen, stuff->dotclock) == dotClock) &&
1166 MODEMATCH(mode, stuff)) {
1167
1168 if (!VidModeSwitchMode(stuff->screen, mode))
1169 return BadValue;
1170
1171 if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY)
1172 ErrorF("SwitchToMode - Succeeded\n");
1173 return Success;
1174 }
1175 } while (VidModeGetNextModeline(stuff->screen, &mode, &dotClock));
1176
1177 return BadValue;
1178}
1179
1180static int
1181ProcXF86VidModeLockModeSwitch(ClientPtr client)
1182{
1183 REQUEST(xXF86VidModeLockModeSwitchReq);
1184
1185 REQUEST_SIZE_MATCH(xXF86VidModeLockModeSwitchReq);
1186
1187 DEBUG_P("XF86VidModeLockModeSwitch");
1188
1189 if (stuff->screen >= screenInfo.numScreens)
1190 return BadValue;
1191
1192 if (!VidModeLockZoom(stuff->screen, (short) stuff->lock))
1193 return VidModeErrorBase + XF86VidModeZoomLocked;
1194
1195 return Success;
1196}
1197
1198static int
1199ProcXF86VidModeGetMonitor(ClientPtr client)
1200{
1201 REQUEST(xXF86VidModeGetMonitorReq);
1202 xXF86VidModeGetMonitorReply rep = {
1203 .type = X_Reply,
1204 .sequenceNumber = client->sequence
1205 };
1206 CARD32 *hsyncdata, *vsyncdata;
1207 int i, nHsync, nVrefresh;
1208 pointer monitor;
1209
1210 DEBUG_P("XF86VidModeGetMonitor");
1211
1212 REQUEST_SIZE_MATCH(xXF86VidModeGetMonitorReq);
1213
1214 if (stuff->screen >= screenInfo.numScreens)
1215 return BadValue;
1216
1217 if (!VidModeGetMonitor(stuff->screen, &monitor))
1218 return BadValue;
1219
1220 nHsync = VidModeGetMonitorValue(monitor, VIDMODE_MON_NHSYNC, 0).i;
1221 nVrefresh = VidModeGetMonitorValue(monitor, VIDMODE_MON_NVREFRESH, 0).i;
1222
1223 if ((char *) (VidModeGetMonitorValue(monitor, VIDMODE_MON_VENDOR, 0)).ptr)
1224 rep.vendorLength = strlen((char *) (VidModeGetMonitorValue(monitor,
1225 VIDMODE_MON_VENDOR,
1226 0)).ptr);
1227 else
1228 rep.vendorLength = 0;
1229 if ((char *) (VidModeGetMonitorValue(monitor, VIDMODE_MON_MODEL, 0)).ptr)
1230 rep.modelLength = strlen((char *) (VidModeGetMonitorValue(monitor,
1231 VIDMODE_MON_MODEL,
1232 0)).ptr);
1233 else
1234 rep.modelLength = 0;
1235 rep.length =
1236 bytes_to_int32(SIZEOF(xXF86VidModeGetMonitorReply) -
1237 SIZEOF(xGenericReply) + (nHsync +
1238 nVrefresh) * sizeof(CARD32) +
1239 pad_to_int32(rep.vendorLength) +
1240 pad_to_int32(rep.modelLength));
1241 rep.nhsync = nHsync;
1242 rep.nvsync = nVrefresh;
1243 hsyncdata = malloc(nHsync * sizeof(CARD32));
1244 if (!hsyncdata) {
1245 return BadAlloc;
1246 }
1247 vsyncdata = malloc(nVrefresh * sizeof(CARD32));
1248
1249 if (!vsyncdata) {
1250 free(hsyncdata);
1251 return BadAlloc;
1252 }
1253
1254 for (i = 0; i < nHsync; i++) {
1255 hsyncdata[i] = (unsigned short) (VidModeGetMonitorValue(monitor,
1256 VIDMODE_MON_HSYNC_LO,
1257 i)).f |
1258 (unsigned
1259 short) (VidModeGetMonitorValue(monitor, VIDMODE_MON_HSYNC_HI,
1260 i)).f << 16;
1261 }
1262 for (i = 0; i < nVrefresh; i++) {
1263 vsyncdata[i] = (unsigned short) (VidModeGetMonitorValue(monitor,
1264 VIDMODE_MON_VREFRESH_LO,
1265 i)).f |
1266 (unsigned
1267 short) (VidModeGetMonitorValue(monitor, VIDMODE_MON_VREFRESH_HI,
1268 i)).f << 16;
1269 }
1270
1271 if (client->swapped) {
1272 swaps(&rep.sequenceNumber);
1273 swapl(&rep.length);
1274 }
1275 WriteToClient(client, SIZEOF(xXF86VidModeGetMonitorReply), &rep);
1276 client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
1277 WriteSwappedDataToClient(client, nHsync * sizeof(CARD32), hsyncdata);
1278 WriteSwappedDataToClient(client, nVrefresh * sizeof(CARD32), vsyncdata);
1279 if (rep.vendorLength)
1280 WriteToClient(client, rep.vendorLength,
1281 (VidModeGetMonitorValue(monitor, VIDMODE_MON_VENDOR, 0)).ptr);
1282 if (rep.modelLength)
1283 WriteToClient(client, rep.modelLength,
1284 (VidModeGetMonitorValue(monitor, VIDMODE_MON_MODEL, 0)).ptr);
1285
1286 free(hsyncdata);
1287 free(vsyncdata);
1288
1289 return Success;
1290}
1291
1292static int
1293ProcXF86VidModeGetViewPort(ClientPtr client)
1294{
1295 REQUEST(xXF86VidModeGetViewPortReq);
1296 xXF86VidModeGetViewPortReply rep;
1297 int x, y;
1298
1299 DEBUG_P("XF86VidModeGetViewPort");
1300
1301 REQUEST_SIZE_MATCH(xXF86VidModeGetViewPortReq);
1302
1303 if (stuff->screen >= screenInfo.numScreens)
1304 return BadValue;
1305
1306 VidModeGetViewPort(stuff->screen, &x, &y);
1307
1308 rep = (xXF86VidModeGetViewPortReply) {
1309 .type = X_Reply,
1310 .sequenceNumber = client->sequence,
1311 .length = 0,
1312 .x = x,
1313 .y = y
1314 };
1315
1316 if (client->swapped) {
1317 swaps(&rep.sequenceNumber);
1318 swapl(&rep.length);
1319 swapl(&rep.x);
1320 swapl(&rep.y);
1321 }
1322 WriteToClient(client, SIZEOF(xXF86VidModeGetViewPortReply), &rep);
1323 return Success;
1324}
1325
1326static int
1327ProcXF86VidModeSetViewPort(ClientPtr client)
1328{
1329 REQUEST(xXF86VidModeSetViewPortReq);
1330
1331 DEBUG_P("XF86VidModeSetViewPort");
1332
1333 REQUEST_SIZE_MATCH(xXF86VidModeSetViewPortReq);
1334
1335 if (stuff->screen >= screenInfo.numScreens)
1336 return BadValue;
1337
1338 if (!VidModeSetViewPort(stuff->screen, stuff->x, stuff->y))
1339 return BadValue;
1340
1341 return Success;
1342}
1343
1344static int
1345ProcXF86VidModeGetDotClocks(ClientPtr client)
1346{
1347 REQUEST(xXF86VidModeGetDotClocksReq);
1348 xXF86VidModeGetDotClocksReply rep;
1349 int n;
1350 int numClocks;
1351 CARD32 dotclock;
1352 int *Clocks = NULL;
1353 Bool ClockProg;
1354
1355 DEBUG_P("XF86VidModeGetDotClocks");
1356
1357 REQUEST_SIZE_MATCH(xXF86VidModeGetDotClocksReq);
1358
1359 if (stuff->screen >= screenInfo.numScreens)
1360 return BadValue;
1361
1362 numClocks = VidModeGetNumOfClocks(stuff->screen, &ClockProg);
1363
1364 rep = (xXF86VidModeGetDotClocksReply) {
1365 .type = X_Reply,
1366 .sequenceNumber = client->sequence,
1367 .length = bytes_to_int32(SIZEOF(xXF86VidModeGetDotClocksReply)
1368 - SIZEOF(xGenericReply) + numClocks),
1369 .clocks = numClocks,
1370 .maxclocks = MAXCLOCKS,
1371 .flags = 0
1372 };
1373
1374 if (!ClockProg) {
1375 Clocks = calloc(numClocks, sizeof(int));
1376 if (!Clocks)
1377 return BadValue;
1378 if (!VidModeGetClocks(stuff->screen, Clocks)) {
1379 free(Clocks);
1380 return BadValue;
1381 }
1382 }
1383 if (ClockProg) {
1384 rep.flags |= CLKFLAG_PROGRAMABLE;
1385 }
1386 if (client->swapped) {
1387 swaps(&rep.sequenceNumber);
1388 swapl(&rep.length);
1389 swapl(&rep.clocks);
1390 swapl(&rep.maxclocks);
1391 swapl(&rep.flags);
1392 }
1393 WriteToClient(client, sizeof(xXF86VidModeGetDotClocksReply), &rep);
1394 if (!ClockProg) {
1395 for (n = 0; n < numClocks; n++) {
1396 dotclock = *Clocks++;
1397 if (client->swapped) {
1398 WriteSwappedDataToClient(client, 4, (char *) &dotclock);
1399 }
1400 else {
1401 WriteToClient(client, 4, &dotclock);
1402 }
1403 }
1404 }
1405
1406 free(Clocks);
1407 return Success;
1408}
1409
1410static int
1411ProcXF86VidModeSetGamma(ClientPtr client)
1412{
1413 REQUEST(xXF86VidModeSetGammaReq);
1414
1415 DEBUG_P("XF86VidModeSetGamma");
1416
1417 REQUEST_SIZE_MATCH(xXF86VidModeSetGammaReq);
1418
1419 if (stuff->screen >= screenInfo.numScreens)
1420 return BadValue;
1421
1422 if (!VidModeSetGamma(stuff->screen, ((float) stuff->red) / 10000.,
1423 ((float) stuff->green) / 10000.,
1424 ((float) stuff->blue) / 10000.))
1425 return BadValue;
1426
1427 return Success;
1428}
1429
1430static int
1431ProcXF86VidModeGetGamma(ClientPtr client)
1432{
1433 REQUEST(xXF86VidModeGetGammaReq);
1434 xXF86VidModeGetGammaReply rep;
1435 float red, green, blue;
1436
1437 DEBUG_P("XF86VidModeGetGamma");
1438
1439 REQUEST_SIZE_MATCH(xXF86VidModeGetGammaReq);
1440
1441 if (stuff->screen >= screenInfo.numScreens)
1442 return BadValue;
1443
1444 if (!VidModeGetGamma(stuff->screen, &red, &green, &blue))
1445 return BadValue;
1446 rep = (xXF86VidModeGetGammaReply) {
1447 .type = X_Reply,
1448 .sequenceNumber = client->sequence,
1449 .length = 0,
1450 .red = (CARD32) (red * 10000.),
1451 .green = (CARD32) (green * 10000.),
1452 .blue = (CARD32) (blue * 10000.)
1453 };
1454 if (client->swapped) {
1455 swaps(&rep.sequenceNumber);
1456 swapl(&rep.length);
1457 swapl(&rep.red);
1458 swapl(&rep.green);
1459 swapl(&rep.blue);
1460 }
1461 WriteToClient(client, sizeof(xXF86VidModeGetGammaReply), &rep);
1462
1463 return Success;
1464}
1465
1466static int
1467ProcXF86VidModeSetGammaRamp(ClientPtr client)
1468{
1469 CARD16 *r, *g, *b;
1470 int length;
1471
1472 REQUEST(xXF86VidModeSetGammaRampReq);
1473
1474 if (stuff->screen >= screenInfo.numScreens)
1475 return BadValue;
1476
1477 if (stuff->size != VidModeGetGammaRampSize(stuff->screen))
1478 return BadValue;
1479
1480 length = (stuff->size + 1) & ~1;
1481
1482 REQUEST_FIXED_SIZE(xXF86VidModeSetGammaRampReq, length * 6);
1483
1484 r = (CARD16 *) &stuff[1];
1485 g = r + length;
1486 b = g + length;
1487
1488 if (!VidModeSetGammaRamp(stuff->screen, stuff->size, r, g, b))
1489 return BadValue;
1490
1491 return Success;
1492}
1493
1494static int
1495ProcXF86VidModeGetGammaRamp(ClientPtr client)
1496{
1497 CARD16 *ramp = NULL;
1498 int length;
1499 size_t ramplen = 0;
1500 xXF86VidModeGetGammaRampReply rep;
1501
1502 REQUEST(xXF86VidModeGetGammaRampReq);
1503
1504 REQUEST_SIZE_MATCH(xXF86VidModeGetGammaRampReq);
1505
1506 if (stuff->screen >= screenInfo.numScreens)
1507 return BadValue;
1508
1509 if (stuff->size != VidModeGetGammaRampSize(stuff->screen))
1510 return BadValue;
1511
1512 length = (stuff->size + 1) & ~1;
1513
1514 if (stuff->size) {
1515 ramplen = length * 3 * sizeof(CARD16);
1516 if (!(ramp = malloc(ramplen)))
1517 return BadAlloc;
1518
1519 if (!VidModeGetGammaRamp(stuff->screen, stuff->size,
1520 ramp, ramp + length, ramp + (length * 2))) {
1521 free(ramp);
1522 return BadValue;
1523 }
1524 }
1525 rep = (xXF86VidModeGetGammaRampReply) {
1526 .type = X_Reply,
1527 .sequenceNumber = client->sequence,
1528 .length = (length >> 1) * 3,
1529 .size = stuff->size
1530 };
1531 if (client->swapped) {
1532 swaps(&rep.sequenceNumber);
1533 swapl(&rep.length);
1534 swaps(&rep.size);
1535 SwapShorts((short *) ramp, length * 3);
1536 }
1537 WriteToClient(client, sizeof(xXF86VidModeGetGammaRampReply), &rep);
1538
1539 if (stuff->size) {
1540 WriteToClient(client, ramplen, ramp);
1541 free(ramp);
1542 }
1543
1544 return Success;
1545}
1546
1547static int
1548ProcXF86VidModeGetGammaRampSize(ClientPtr client)
1549{
1550 xXF86VidModeGetGammaRampSizeReply rep;
1551
1552 REQUEST(xXF86VidModeGetGammaRampSizeReq);
1553
1554 REQUEST_SIZE_MATCH(xXF86VidModeGetGammaRampSizeReq);
1555
1556 if (stuff->screen >= screenInfo.numScreens)
1557 return BadValue;
1558
1559 rep = (xXF86VidModeGetGammaRampSizeReply) {
1560 .type = X_Reply,
1561 .sequenceNumber = client->sequence,
1562 .length = 0,
1563 .size = VidModeGetGammaRampSize(stuff->screen)
1564 };
1565 if (client->swapped) {
1566 swaps(&rep.sequenceNumber);
1567 swapl(&rep.length);
1568 swaps(&rep.size);
1569 }
1570 WriteToClient(client, sizeof(xXF86VidModeGetGammaRampSizeReply), &rep);
1571
1572 return Success;
1573}
1574
1575static int
1576ProcXF86VidModeGetPermissions(ClientPtr client)
1577{
1578 xXF86VidModeGetPermissionsReply rep = {
1579 .type = X_Reply,
1580 .sequenceNumber = client->sequence,
1581 .length = 0,
1582 .permissions = XF86VM_READ_PERMISSION
1583 };
1584
1585 REQUEST(xXF86VidModeGetPermissionsReq);
1586
1587 REQUEST_SIZE_MATCH(xXF86VidModeGetPermissionsReq);
1588
1589 if (stuff->screen >= screenInfo.numScreens)
1590 return BadValue;
1591
1592 if (xf86GetVidModeEnabled() &&
1593 (xf86GetVidModeAllowNonLocal() || client->local)) {
1594 rep.permissions |= XF86VM_WRITE_PERMISSION;
1595 }
1596 if (client->swapped) {
1597 swaps(&rep.sequenceNumber);
1598 swapl(&rep.length);
1599 swapl(&rep.permissions);
1600 }
1601 WriteToClient(client, sizeof(xXF86VidModeGetPermissionsReply), &rep);
1602
1603 return Success;
1604}
1605
1606static int
1607ProcXF86VidModeSetClientVersion(ClientPtr client)
1608{
1609 REQUEST(xXF86VidModeSetClientVersionReq);
1610
1611 VidModePrivPtr pPriv;
1612
1613 DEBUG_P("XF86VidModeSetClientVersion");
1614
1615 REQUEST_SIZE_MATCH(xXF86VidModeSetClientVersionReq);
1616
1617 if ((pPriv = VM_GETPRIV(client)) == NULL) {
1618 pPriv = malloc(sizeof(VidModePrivRec));
1619 if (!pPriv)
1620 return BadAlloc;
1621 VM_SETPRIV(client, pPriv);
1622 }
1623 pPriv->major = stuff->major;
1624
1625 pPriv->minor = stuff->minor;
1626
1627 return Success;
1628}
1629
1630static int
1631ProcXF86VidModeDispatch(ClientPtr client)
1632{
1633 REQUEST(xReq);
1634 switch (stuff->data) {
1635 case X_XF86VidModeQueryVersion:
1636 return ProcXF86VidModeQueryVersion(client);
1637 case X_XF86VidModeGetModeLine:
1638 return ProcXF86VidModeGetModeLine(client);
1639 case X_XF86VidModeGetMonitor:
1640 return ProcXF86VidModeGetMonitor(client);
1641 case X_XF86VidModeGetAllModeLines:
1642 return ProcXF86VidModeGetAllModeLines(client);
1643 case X_XF86VidModeValidateModeLine:
1644 return ProcXF86VidModeValidateModeLine(client);
1645 case X_XF86VidModeGetViewPort:
1646 return ProcXF86VidModeGetViewPort(client);
1647 case X_XF86VidModeGetDotClocks:
1648 return ProcXF86VidModeGetDotClocks(client);
1649 case X_XF86VidModeSetClientVersion:
1650 return ProcXF86VidModeSetClientVersion(client);
1651 case X_XF86VidModeGetGamma:
1652 return ProcXF86VidModeGetGamma(client);
1653 case X_XF86VidModeGetGammaRamp:
1654 return ProcXF86VidModeGetGammaRamp(client);
1655 case X_XF86VidModeGetGammaRampSize:
1656 return ProcXF86VidModeGetGammaRampSize(client);
1657 case X_XF86VidModeGetPermissions:
1658 return ProcXF86VidModeGetPermissions(client);
1659 default:
1660 if (!xf86GetVidModeEnabled())
1661 return VidModeErrorBase + XF86VidModeExtensionDisabled;
1662 if (xf86GetVidModeAllowNonLocal() || client->local) {
1663 switch (stuff->data) {
1664 case X_XF86VidModeAddModeLine:
1665 return ProcXF86VidModeAddModeLine(client);
1666 case X_XF86VidModeDeleteModeLine:
1667 return ProcXF86VidModeDeleteModeLine(client);
1668 case X_XF86VidModeModModeLine:
1669 return ProcXF86VidModeModModeLine(client);
1670 case X_XF86VidModeSwitchMode:
1671 return ProcXF86VidModeSwitchMode(client);
1672 case X_XF86VidModeSwitchToMode:
1673 return ProcXF86VidModeSwitchToMode(client);
1674 case X_XF86VidModeLockModeSwitch:
1675 return ProcXF86VidModeLockModeSwitch(client);
1676 case X_XF86VidModeSetViewPort:
1677 return ProcXF86VidModeSetViewPort(client);
1678 case X_XF86VidModeSetGamma:
1679 return ProcXF86VidModeSetGamma(client);
1680 case X_XF86VidModeSetGammaRamp:
1681 return ProcXF86VidModeSetGammaRamp(client);
1682 default:
1683 return BadRequest;
1684 }
1685 }
1686 else
1687 return VidModeErrorBase + XF86VidModeClientNotLocal;
1688 }
1689}
1690
1691static int
1692SProcXF86VidModeQueryVersion(ClientPtr client)
1693{
1694 REQUEST(xXF86VidModeQueryVersionReq);
1695 swaps(&stuff->length);
1696 return ProcXF86VidModeQueryVersion(client);
1697}
1698
1699static int
1700SProcXF86VidModeGetModeLine(ClientPtr client)
1701{
1702 REQUEST(xXF86VidModeGetModeLineReq);
1703 swaps(&stuff->length);
1704 REQUEST_SIZE_MATCH(xXF86VidModeGetModeLineReq);
1705 swaps(&stuff->screen);
1706 return ProcXF86VidModeGetModeLine(client);
1707}
1708
1709static int
1710SProcXF86VidModeGetAllModeLines(ClientPtr client)
1711{
1712 REQUEST(xXF86VidModeGetAllModeLinesReq);
1713 swaps(&stuff->length);
1714 REQUEST_SIZE_MATCH(xXF86VidModeGetAllModeLinesReq);
1715 swaps(&stuff->screen);
1716 return ProcXF86VidModeGetAllModeLines(client);
1717}
1718
1719static int
1720SProcXF86VidModeAddModeLine(ClientPtr client)
1721{
1722 xXF86OldVidModeAddModeLineReq *oldstuff =
1723 (xXF86OldVidModeAddModeLineReq *) client->requestBuffer;
1724 int ver;
1725
1726 REQUEST(xXF86VidModeAddModeLineReq);
1727 ver = ClientMajorVersion(client);
1728 if (ver < 2) {
1729 swaps(&oldstuff->length);
1730 REQUEST_AT_LEAST_SIZE(xXF86OldVidModeAddModeLineReq);
1731 swapl(&oldstuff->screen);
1732 swaps(&oldstuff->hdisplay);
1733 swaps(&oldstuff->hsyncstart);
1734 swaps(&oldstuff->hsyncend);
1735 swaps(&oldstuff->htotal);
1736 swaps(&oldstuff->vdisplay);
1737 swaps(&oldstuff->vsyncstart);
1738 swaps(&oldstuff->vsyncend);
1739 swaps(&oldstuff->vtotal);
1740 swapl(&oldstuff->flags);
1741 swapl(&oldstuff->privsize);
1742 SwapRestL(oldstuff);
1743 }
1744 else {
1745 swaps(&stuff->length);
1746 REQUEST_AT_LEAST_SIZE(xXF86VidModeAddModeLineReq);
1747 swapl(&stuff->screen);
1748 swaps(&stuff->hdisplay);
1749 swaps(&stuff->hsyncstart);
1750 swaps(&stuff->hsyncend);
1751 swaps(&stuff->htotal);
1752 swaps(&stuff->hskew);
1753 swaps(&stuff->vdisplay);
1754 swaps(&stuff->vsyncstart);
1755 swaps(&stuff->vsyncend);
1756 swaps(&stuff->vtotal);
1757 swapl(&stuff->flags);
1758 swapl(&stuff->privsize);
1759 SwapRestL(stuff);
1760 }
1761 return ProcXF86VidModeAddModeLine(client);
1762}
1763
1764static int
1765SProcXF86VidModeDeleteModeLine(ClientPtr client)
1766{
1767 xXF86OldVidModeDeleteModeLineReq *oldstuff =
1768 (xXF86OldVidModeDeleteModeLineReq *) client->requestBuffer;
1769 int ver;
1770
1771 REQUEST(xXF86VidModeDeleteModeLineReq);
1772 ver = ClientMajorVersion(client);
1773 if (ver < 2) {
1774 swaps(&oldstuff->length);
1775 REQUEST_AT_LEAST_SIZE(xXF86OldVidModeDeleteModeLineReq);
1776 swapl(&oldstuff->screen);
1777 swaps(&oldstuff->hdisplay);
1778 swaps(&oldstuff->hsyncstart);
1779 swaps(&oldstuff->hsyncend);
1780 swaps(&oldstuff->htotal);
1781 swaps(&oldstuff->vdisplay);
1782 swaps(&oldstuff->vsyncstart);
1783 swaps(&oldstuff->vsyncend);
1784 swaps(&oldstuff->vtotal);
1785 swapl(&oldstuff->flags);
1786 swapl(&oldstuff->privsize);
1787 SwapRestL(oldstuff);
1788 }
1789 else {
1790 swaps(&stuff->length);
1791 REQUEST_AT_LEAST_SIZE(xXF86VidModeDeleteModeLineReq);
1792 swapl(&stuff->screen);
1793 swaps(&stuff->hdisplay);
1794 swaps(&stuff->hsyncstart);
1795 swaps(&stuff->hsyncend);
1796 swaps(&stuff->htotal);
1797 swaps(&stuff->hskew);
1798 swaps(&stuff->vdisplay);
1799 swaps(&stuff->vsyncstart);
1800 swaps(&stuff->vsyncend);
1801 swaps(&stuff->vtotal);
1802 swapl(&stuff->flags);
1803 swapl(&stuff->privsize);
1804 SwapRestL(stuff);
1805 }
1806 return ProcXF86VidModeDeleteModeLine(client);
1807}
1808
1809static int
1810SProcXF86VidModeModModeLine(ClientPtr client)
1811{
1812 xXF86OldVidModeModModeLineReq *oldstuff =
1813 (xXF86OldVidModeModModeLineReq *) client->requestBuffer;
1814 int ver;
1815
1816 REQUEST(xXF86VidModeModModeLineReq);
1817 ver = ClientMajorVersion(client);
1818 if (ver < 2) {
1819 swaps(&oldstuff->length);
1820 REQUEST_AT_LEAST_SIZE(xXF86OldVidModeModModeLineReq);
1821 swapl(&oldstuff->screen);
1822 swaps(&oldstuff->hdisplay);
1823 swaps(&oldstuff->hsyncstart);
1824 swaps(&oldstuff->hsyncend);
1825 swaps(&oldstuff->htotal);
1826 swaps(&oldstuff->vdisplay);
1827 swaps(&oldstuff->vsyncstart);
1828 swaps(&oldstuff->vsyncend);
1829 swaps(&oldstuff->vtotal);
1830 swapl(&oldstuff->flags);
1831 swapl(&oldstuff->privsize);
1832 SwapRestL(oldstuff);
1833 }
1834 else {
1835 swaps(&stuff->length);
1836 REQUEST_AT_LEAST_SIZE(xXF86VidModeModModeLineReq);
1837 swapl(&stuff->screen);
1838 swaps(&stuff->hdisplay);
1839 swaps(&stuff->hsyncstart);
1840 swaps(&stuff->hsyncend);
1841 swaps(&stuff->htotal);
1842 swaps(&stuff->hskew);
1843 swaps(&stuff->vdisplay);
1844 swaps(&stuff->vsyncstart);
1845 swaps(&stuff->vsyncend);
1846 swaps(&stuff->vtotal);
1847 swapl(&stuff->flags);
1848 swapl(&stuff->privsize);
1849 SwapRestL(stuff);
1850 }
1851 return ProcXF86VidModeModModeLine(client);
1852}
1853
1854static int
1855SProcXF86VidModeValidateModeLine(ClientPtr client)
1856{
1857 xXF86OldVidModeValidateModeLineReq *oldstuff =
1858 (xXF86OldVidModeValidateModeLineReq *) client->requestBuffer;
1859 int ver;
1860
1861 REQUEST(xXF86VidModeValidateModeLineReq);
1862 ver = ClientMajorVersion(client);
1863 if (ver < 2) {
1864 swaps(&oldstuff->length);
1865 REQUEST_AT_LEAST_SIZE(xXF86OldVidModeValidateModeLineReq);
1866 swapl(&oldstuff->screen);
1867 swaps(&oldstuff->hdisplay);
1868 swaps(&oldstuff->hsyncstart);
1869 swaps(&oldstuff->hsyncend);
1870 swaps(&oldstuff->htotal);
1871 swaps(&oldstuff->vdisplay);
1872 swaps(&oldstuff->vsyncstart);
1873 swaps(&oldstuff->vsyncend);
1874 swaps(&oldstuff->vtotal);
1875 swapl(&oldstuff->flags);
1876 swapl(&oldstuff->privsize);
1877 SwapRestL(oldstuff);
1878 }
1879 else {
1880 swaps(&stuff->length);
1881 REQUEST_AT_LEAST_SIZE(xXF86VidModeValidateModeLineReq);
1882 swapl(&stuff->screen);
1883 swaps(&stuff->hdisplay);
1884 swaps(&stuff->hsyncstart);
1885 swaps(&stuff->hsyncend);
1886 swaps(&stuff->htotal);
1887 swaps(&stuff->hskew);
1888 swaps(&stuff->vdisplay);
1889 swaps(&stuff->vsyncstart);
1890 swaps(&stuff->vsyncend);
1891 swaps(&stuff->vtotal);
1892 swapl(&stuff->flags);
1893 swapl(&stuff->privsize);
1894 SwapRestL(stuff);
1895 }
1896 return ProcXF86VidModeValidateModeLine(client);
1897}
1898
1899static int
1900SProcXF86VidModeSwitchMode(ClientPtr client)
1901{
1902 REQUEST(xXF86VidModeSwitchModeReq);
1903 swaps(&stuff->length);
1904 REQUEST_SIZE_MATCH(xXF86VidModeSwitchModeReq);
1905 swaps(&stuff->screen);
1906 swaps(&stuff->zoom);
1907 return ProcXF86VidModeSwitchMode(client);
1908}
1909
1910static int
1911SProcXF86VidModeSwitchToMode(ClientPtr client)
1912{
1913 REQUEST(xXF86VidModeSwitchToModeReq);
1914 swaps(&stuff->length);
1915 REQUEST_SIZE_MATCH(xXF86VidModeSwitchToModeReq);
1916 swapl(&stuff->screen);
1917 return ProcXF86VidModeSwitchToMode(client);
1918}
1919
1920static int
1921SProcXF86VidModeLockModeSwitch(ClientPtr client)
1922{
1923 REQUEST(xXF86VidModeLockModeSwitchReq);
1924 swaps(&stuff->length);
1925 REQUEST_SIZE_MATCH(xXF86VidModeLockModeSwitchReq);
1926 swaps(&stuff->screen);
1927 swaps(&stuff->lock);
1928 return ProcXF86VidModeLockModeSwitch(client);
1929}
1930
1931static int
1932SProcXF86VidModeGetMonitor(ClientPtr client)
1933{
1934 REQUEST(xXF86VidModeGetMonitorReq);
1935 swaps(&stuff->length);
1936 REQUEST_SIZE_MATCH(xXF86VidModeGetMonitorReq);
1937 swaps(&stuff->screen);
1938 return ProcXF86VidModeGetMonitor(client);
1939}
1940
1941static int
1942SProcXF86VidModeGetViewPort(ClientPtr client)
1943{
1944 REQUEST(xXF86VidModeGetViewPortReq);
1945 swaps(&stuff->length);
1946 REQUEST_SIZE_MATCH(xXF86VidModeGetViewPortReq);
1947 swaps(&stuff->screen);
1948 return ProcXF86VidModeGetViewPort(client);
1949}
1950
1951static int
1952SProcXF86VidModeSetViewPort(ClientPtr client)
1953{
1954 REQUEST(xXF86VidModeSetViewPortReq);
1955 swaps(&stuff->length);
1956 REQUEST_SIZE_MATCH(xXF86VidModeSetViewPortReq);
1957 swaps(&stuff->screen);
1958 swapl(&stuff->x);
1959 swapl(&stuff->y);
1960 return ProcXF86VidModeSetViewPort(client);
1961}
1962
1963static int
1964SProcXF86VidModeGetDotClocks(ClientPtr client)
1965{
1966 REQUEST(xXF86VidModeGetDotClocksReq);
1967 swaps(&stuff->length);
1968 REQUEST_SIZE_MATCH(xXF86VidModeGetDotClocksReq);
1969 swaps(&stuff->screen);
1970 return ProcXF86VidModeGetDotClocks(client);
1971}
1972
1973static int
1974SProcXF86VidModeSetClientVersion(ClientPtr client)
1975{
1976 REQUEST(xXF86VidModeSetClientVersionReq);
1977 swaps(&stuff->length);
1978 REQUEST_SIZE_MATCH(xXF86VidModeSetClientVersionReq);
1979 swaps(&stuff->major);
1980 swaps(&stuff->minor);
1981 return ProcXF86VidModeSetClientVersion(client);
1982}
1983
1984static int
1985SProcXF86VidModeSetGamma(ClientPtr client)
1986{
1987 REQUEST(xXF86VidModeSetGammaReq);
1988 swaps(&stuff->length);
1989 REQUEST_SIZE_MATCH(xXF86VidModeSetGammaReq);
1990 swaps(&stuff->screen);
1991 swapl(&stuff->red);
1992 swapl(&stuff->green);
1993 swapl(&stuff->blue);
1994 return ProcXF86VidModeSetGamma(client);
1995}
1996
1997static int
1998SProcXF86VidModeGetGamma(ClientPtr client)
1999{
2000 REQUEST(xXF86VidModeGetGammaReq);
2001 swaps(&stuff->length);
2002 REQUEST_SIZE_MATCH(xXF86VidModeGetGammaReq);
2003 swaps(&stuff->screen);
2004 return ProcXF86VidModeGetGamma(client);
2005}
2006
2007static int
2008SProcXF86VidModeSetGammaRamp(ClientPtr client)
2009{
2010 int length;
2011
2012 REQUEST(xXF86VidModeSetGammaRampReq);
2013 swaps(&stuff->length);
2014 REQUEST_AT_LEAST_SIZE(xXF86VidModeSetGammaRampReq);
2015 swaps(&stuff->size);
2016 swaps(&stuff->screen);
2017 length = ((stuff->size + 1) & ~1) * 6;
2018 REQUEST_FIXED_SIZE(xXF86VidModeSetGammaRampReq, length);
2019 SwapRestS(stuff);
2020 return ProcXF86VidModeSetGammaRamp(client);
2021}
2022
2023static int
2024SProcXF86VidModeGetGammaRamp(ClientPtr client)
2025{
2026 REQUEST(xXF86VidModeGetGammaRampReq);
2027 swaps(&stuff->length);
2028 REQUEST_SIZE_MATCH(xXF86VidModeGetGammaRampReq);
2029 swaps(&stuff->size);
2030 swaps(&stuff->screen);
2031 return ProcXF86VidModeGetGammaRamp(client);
2032}
2033
2034static int
2035SProcXF86VidModeGetGammaRampSize(ClientPtr client)
2036{
2037 REQUEST(xXF86VidModeGetGammaRampSizeReq);
2038 swaps(&stuff->length);
2039 REQUEST_SIZE_MATCH(xXF86VidModeGetGammaRampSizeReq);
2040 swaps(&stuff->screen);
2041 return ProcXF86VidModeGetGammaRampSize(client);
2042}
2043
2044static int
2045SProcXF86VidModeGetPermissions(ClientPtr client)
2046{
2047 REQUEST(xXF86VidModeGetPermissionsReq);
2048 swaps(&stuff->length);
2049 REQUEST_SIZE_MATCH(xXF86VidModeGetPermissionsReq);
2050 swaps(&stuff->screen);
2051 return ProcXF86VidModeGetPermissions(client);
2052}
2053
2054static int
2055SProcXF86VidModeDispatch(ClientPtr client)
2056{
2057 REQUEST(xReq);
2058 switch (stuff->data) {
2059 case X_XF86VidModeQueryVersion:
2060 return SProcXF86VidModeQueryVersion(client);
2061 case X_XF86VidModeGetModeLine:
2062 return SProcXF86VidModeGetModeLine(client);
2063 case X_XF86VidModeGetMonitor:
2064 return SProcXF86VidModeGetMonitor(client);
2065 case X_XF86VidModeGetAllModeLines:
2066 return SProcXF86VidModeGetAllModeLines(client);
2067 case X_XF86VidModeGetViewPort:
2068 return SProcXF86VidModeGetViewPort(client);
2069 case X_XF86VidModeValidateModeLine:
2070 return SProcXF86VidModeValidateModeLine(client);
2071 case X_XF86VidModeGetDotClocks:
2072 return SProcXF86VidModeGetDotClocks(client);
2073 case X_XF86VidModeSetClientVersion:
2074 return SProcXF86VidModeSetClientVersion(client);
2075 case X_XF86VidModeGetGamma:
2076 return SProcXF86VidModeGetGamma(client);
2077 case X_XF86VidModeGetGammaRamp:
2078 return SProcXF86VidModeGetGammaRamp(client);
2079 case X_XF86VidModeGetGammaRampSize:
2080 return SProcXF86VidModeGetGammaRampSize(client);
2081 case X_XF86VidModeGetPermissions:
2082 return SProcXF86VidModeGetPermissions(client);
2083 default:
2084 if (!xf86GetVidModeEnabled())
2085 return VidModeErrorBase + XF86VidModeExtensionDisabled;
2086 if (xf86GetVidModeAllowNonLocal() || client->local) {
2087 switch (stuff->data) {
2088 case X_XF86VidModeAddModeLine:
2089 return SProcXF86VidModeAddModeLine(client);
2090 case X_XF86VidModeDeleteModeLine:
2091 return SProcXF86VidModeDeleteModeLine(client);
2092 case X_XF86VidModeModModeLine:
2093 return SProcXF86VidModeModModeLine(client);
2094 case X_XF86VidModeSwitchMode:
2095 return SProcXF86VidModeSwitchMode(client);
2096 case X_XF86VidModeSwitchToMode:
2097 return SProcXF86VidModeSwitchToMode(client);
2098 case X_XF86VidModeLockModeSwitch:
2099 return SProcXF86VidModeLockModeSwitch(client);
2100 case X_XF86VidModeSetViewPort:
2101 return SProcXF86VidModeSetViewPort(client);
2102 case X_XF86VidModeSetGamma:
2103 return SProcXF86VidModeSetGamma(client);
2104 case X_XF86VidModeSetGammaRamp:
2105 return SProcXF86VidModeSetGammaRamp(client);
2106 default:
2107 return BadRequest;
2108 }
2109 }
2110 else
2111 return VidModeErrorBase + XF86VidModeClientNotLocal;
2112 }
2113}
2114
2115void
2116XFree86VidModeExtensionInit(void)
2117{
2118 ExtensionEntry *extEntry;
2119 ScreenPtr pScreen;
2120 int i;
2121 Bool enabled = FALSE;
2122
2123 DEBUG_P("XFree86VidModeExtensionInit");
2124
2125 if (!dixRegisterPrivateKey(&VidModeClientPrivateKeyRec, PRIVATE_CLIENT, 0))
2126 return;
2127#ifdef XF86VIDMODE_EVENTS
2128 if (!dixRegisterPrivateKey(&ScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
2129 return;
2130#endif
2131
2132#ifdef XF86VIDMODE_EVENTS
2133 EventType = CreateNewResourceType(XF86VidModeFreeEvents, "VidModeEvent");
2134#endif
2135
2136 for (i = 0; i < screenInfo.numScreens; i++) {
2137 pScreen = screenInfo.screens[i];
2138 if (VidModeExtensionInit(pScreen))
2139 enabled = TRUE;
2140 }
2141 /* This means that the DDX doesn't want the vidmode extension enabled */
2142 if (!enabled)
2143 return;
2144
2145 if (
2146#ifdef XF86VIDMODE_EVENTS
2147 EventType &&
2148#endif
2149 (extEntry = AddExtension(XF86VIDMODENAME,
2150 XF86VidModeNumberEvents,
2151 XF86VidModeNumberErrors,
2152 ProcXF86VidModeDispatch,
2153 SProcXF86VidModeDispatch,
2154 NULL, StandardMinorOpcode))) {
2155#if 0
2156 XF86VidModeReqCode = (unsigned char) extEntry->base;
2157#endif
2158 VidModeErrorBase = extEntry->errorBase;
2159#ifdef XF86VIDMODE_EVENTS
2160 XF86VidModeEventBase = extEntry->eventBase;
2161 EventSwapVector[XF86VidModeEventBase] =
2162 (EventSwapPtr) SXF86VidModeNotifyEvent;
2163#endif
2164 }
2165}