~ubuntu-branches/ubuntu/intrepid/xserver-xgl/intrepid

« back to all changes in this revision

Viewing changes to hw/xfree86/common/xf86VidMode.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Garrett
  • Date: 2006-02-13 14:21:43 UTC
  • Revision ID: james.westby@ubuntu.com-20060213142143-mad6z9xzem7hzxz9
Tags: upstream-7.0.0
ImportĀ upstreamĀ versionĀ 7.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86VidMode.c,v 1.17 2003/08/24 17:36:55 dawes Exp $ */
 
2
/*
 
3
 * Copyright (c) 1999-2003 by The XFree86 Project, Inc.
 
4
 *
 
5
 * Permission is hereby granted, free of charge, to any person obtaining a
 
6
 * copy of this software and associated documentation files (the "Software"),
 
7
 * to deal in the Software without restriction, including without limitation
 
8
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 
9
 * and/or sell copies of the Software, and to permit persons to whom the
 
10
 * Software is furnished to do so, subject to the following conditions:
 
11
 *
 
12
 * The above copyright notice and this permission notice shall be included in
 
13
 * all copies or substantial portions of the Software.
 
14
 *
 
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
16
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
17
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 
18
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 
19
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 
20
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 
21
 * OTHER DEALINGS IN THE SOFTWARE.
 
22
 *
 
23
 * Except as contained in this notice, the name of the copyright holder(s)
 
24
 * and author(s) shall not be used in advertising or otherwise to promote
 
25
 * the sale, use or other dealings in this Software without prior written
 
26
 * authorization from the copyright holder(s) and author(s).
 
27
 */
 
28
 
 
29
/*
 
30
 * This file contains the VidMode functions required by the extension.
 
31
 * These have been added to avoid the need for the higher level extension
 
32
 * code to access the private XFree86 data structures directly. Wherever
 
33
 * possible this code uses the functions in xf86Mode.c to do the work,
 
34
 * so that two version of code that do similar things don't have to be
 
35
 * maintained.
 
36
 */
 
37
 
 
38
#ifdef HAVE_XORG_CONFIG_H
 
39
#include <xorg-config.h>
 
40
#endif
 
41
 
 
42
#include <X11/X.h>
 
43
#include "os.h"
 
44
#include "xf86.h"
 
45
#include "xf86Priv.h"
 
46
 
 
47
#ifdef XF86VIDMODE
 
48
#include "vidmodeproc.h"
 
49
#include "xf86cmap.h"
 
50
 
 
51
static int VidModeGeneration = 0;
 
52
static int VidModeIndex = -1;
 
53
static int VidModeCount = 0;
 
54
static Bool VidModeClose(int i, ScreenPtr pScreen);
 
55
 
 
56
#define VMPTR(p) ((VidModePtr)(p)->devPrivates[VidModeIndex].ptr)
 
57
 
 
58
#endif
 
59
 
 
60
#ifdef DEBUG
 
61
# define DEBUG_P(x) ErrorF(x"\n");
 
62
#else
 
63
# define DEBUG_P(x) /**/
 
64
#endif
 
65
 
 
66
Bool
 
67
VidModeExtensionInit(ScreenPtr pScreen)
 
68
{
 
69
#ifdef XF86VIDMODE
 
70
    VidModePtr pVidMode;
 
71
    
 
72
    DEBUG_P("VidModeExtensionInit");
 
73
 
 
74
    if (!xf86GetVidModeEnabled()) {
 
75
        DEBUG_P("!xf86GetVidModeEnabled()");
 
76
        return FALSE;
 
77
    }
 
78
 
 
79
    if (serverGeneration != VidModeGeneration) {
 
80
        if ((VidModeIndex = AllocateScreenPrivateIndex()) < 0) {
 
81
            DEBUG_P("AllocateScreenPrivateIndex() failed");
 
82
            return FALSE;
 
83
        }
 
84
        VidModeGeneration = serverGeneration;
 
85
    }
 
86
 
 
87
    if (!(pScreen->devPrivates[VidModeIndex].ptr = xcalloc(sizeof(VidModeRec), 1))) {
 
88
        DEBUG_P("xcalloc failed");
 
89
        return FALSE;
 
90
    }
 
91
 
 
92
    pVidMode = VMPTR(pScreen);
 
93
    pVidMode->Flags = 0;
 
94
    pVidMode->Next = NULL;
 
95
    pVidMode->CloseScreen = pScreen->CloseScreen;
 
96
    pScreen->CloseScreen = VidModeClose;
 
97
    VidModeCount++;
 
98
    return TRUE;
 
99
#else
 
100
    DEBUG_P("no vidmode extension");
 
101
    return FALSE;
 
102
#endif
 
103
}
 
104
 
 
105
 
 
106
#ifdef XF86VIDMODE
 
107
 
 
108
static Bool
 
109
VidModeClose(int i, ScreenPtr pScreen)
 
110
{
 
111
    VidModePtr pVidMode = VMPTR(pScreen);
 
112
 
 
113
    DEBUG_P("VidModeClose");
 
114
 
 
115
    /* This shouldn't happen */
 
116
    if (!pVidMode)
 
117
        return FALSE;
 
118
 
 
119
    pScreen->CloseScreen = pVidMode->CloseScreen;
 
120
 
 
121
    if (--VidModeCount == 0) {
 
122
        if (pScreen->devPrivates[VidModeIndex].ptr)
 
123
          xfree(pScreen->devPrivates[VidModeIndex].ptr);
 
124
        pScreen->devPrivates[VidModeIndex].ptr = NULL;
 
125
        VidModeIndex = -1;
 
126
    }
 
127
    return pScreen->CloseScreen(i, pScreen);
 
128
}
 
129
 
 
130
Bool
 
131
VidModeAvailable(int scrnIndex)
 
132
{
 
133
    ScrnInfoPtr pScrn;
 
134
    VidModePtr pVidMode;
 
135
 
 
136
    DEBUG_P("VidModeAvailable");
 
137
 
 
138
    if (VidModeIndex < 0) {
 
139
        DEBUG_P("VidModeIndex < 0");
 
140
        return FALSE;
 
141
    }
 
142
 
 
143
    pScrn = xf86Screens[scrnIndex];
 
144
    if (pScrn == NULL) {
 
145
        DEBUG_P("pScrn == NULL");
 
146
        return FALSE;
 
147
    }
 
148
    
 
149
    pVidMode = VMPTR(pScrn->pScreen);
 
150
    if (pVidMode)
 
151
        return TRUE;
 
152
    else {
 
153
        DEBUG_P("pVidMode == NULL");
 
154
        return FALSE;
 
155
    }
 
156
}
 
157
 
 
158
Bool
 
159
VidModeGetCurrentModeline(int scrnIndex, pointer *mode, int *dotClock)
 
160
{
 
161
    ScrnInfoPtr pScrn;
 
162
 
 
163
    DEBUG_P("VidModeGetCurrentModeline");
 
164
 
 
165
    if (!VidModeAvailable(scrnIndex))
 
166
        return FALSE;
 
167
 
 
168
    pScrn = xf86Screens[scrnIndex];
 
169
    *mode = (pointer)(pScrn->currentMode);
 
170
    *dotClock = pScrn->currentMode->Clock;
 
171
 
 
172
    return TRUE;
 
173
}
 
174
 
 
175
int
 
176
VidModeGetDotClock(int scrnIndex, int Clock)
 
177
{
 
178
    ScrnInfoPtr pScrn;
 
179
 
 
180
    DEBUG_P("VidModeGetDotClock");
 
181
 
 
182
    if (!VidModeAvailable(scrnIndex))
 
183
        return 0;
 
184
 
 
185
    pScrn = xf86Screens[scrnIndex];
 
186
    if ((pScrn->progClock) || (Clock > MAXCLOCKS))
 
187
        return Clock;
 
188
    else  
 
189
        return pScrn->clock[Clock];
 
190
}
 
191
 
 
192
int
 
193
VidModeGetNumOfClocks(int scrnIndex, Bool *progClock)
 
194
{
 
195
    ScrnInfoPtr pScrn;
 
196
 
 
197
    DEBUG_P("VidModeGetNumOfClocks");
 
198
 
 
199
    if (!VidModeAvailable(scrnIndex))
 
200
        return 0;
 
201
 
 
202
    pScrn = xf86Screens[scrnIndex];
 
203
    if (pScrn->progClock){
 
204
        *progClock = TRUE;
 
205
        return 0;
 
206
    } else {
 
207
        *progClock = FALSE;
 
208
        return pScrn->numClocks;
 
209
    }
 
210
}
 
211
 
 
212
Bool
 
213
VidModeGetClocks(int scrnIndex, int *Clocks)
 
214
{
 
215
    ScrnInfoPtr pScrn;
 
216
    int i;
 
217
 
 
218
    DEBUG_P("VidModeGetClocks");
 
219
 
 
220
    if (!VidModeAvailable(scrnIndex))
 
221
        return FALSE;
 
222
 
 
223
    pScrn = xf86Screens[scrnIndex];
 
224
 
 
225
    if (pScrn->progClock)
 
226
        return FALSE;
 
227
 
 
228
    for (i = 0;  i < pScrn->numClocks;  i++)
 
229
        *Clocks++ = pScrn->clock[i];
 
230
 
 
231
    return TRUE;
 
232
}
 
233
 
 
234
 
 
235
Bool
 
236
VidModeGetFirstModeline(int scrnIndex, pointer *mode, int *dotClock)
 
237
{
 
238
    ScrnInfoPtr pScrn;
 
239
    VidModePtr pVidMode;
 
240
 
 
241
    DEBUG_P("VidModeGetFirstModeline");
 
242
 
 
243
    if (!VidModeAvailable(scrnIndex))
 
244
        return FALSE;
 
245
 
 
246
    pScrn = xf86Screens[scrnIndex];
 
247
    pVidMode = VMPTR(pScrn->pScreen);
 
248
    pVidMode->First = pScrn->modes;
 
249
    pVidMode->Next =  pVidMode->First->next;
 
250
 
 
251
    if (pVidMode->First->status == MODE_OK) {
 
252
      *mode = (pointer)(pVidMode->First);
 
253
      *dotClock = VidModeGetDotClock(scrnIndex, pVidMode->First->Clock);
 
254
      return TRUE;
 
255
    }
 
256
 
 
257
    return VidModeGetNextModeline(scrnIndex, mode, dotClock);
 
258
}
 
259
 
 
260
Bool
 
261
VidModeGetNextModeline(int scrnIndex, pointer *mode, int *dotClock)
 
262
{
 
263
    ScrnInfoPtr pScrn;
 
264
    VidModePtr pVidMode;
 
265
    DisplayModePtr p;
 
266
 
 
267
    DEBUG_P("VidModeGetNextModeline");
 
268
 
 
269
    if (!VidModeAvailable(scrnIndex))
 
270
        return FALSE;
 
271
 
 
272
    pScrn = xf86Screens[scrnIndex];
 
273
    pVidMode = VMPTR(pScrn->pScreen);
 
274
 
 
275
    for (p = pVidMode->Next; p != NULL && p != pVidMode->First; p = p->next) {
 
276
        if (p->status == MODE_OK) {
 
277
            pVidMode->Next = p->next;
 
278
            *mode = (pointer)p;
 
279
            *dotClock = VidModeGetDotClock(scrnIndex, p->Clock);
 
280
            return TRUE;
 
281
        }
 
282
    }
 
283
    
 
284
    return FALSE;
 
285
}
 
286
 
 
287
Bool
 
288
VidModeDeleteModeline(int scrnIndex, pointer mode)
 
289
{
 
290
    ScrnInfoPtr pScrn;
 
291
 
 
292
    DEBUG_P("VidModeDeleteModeline");
 
293
 
 
294
    if ((mode == NULL) || (!VidModeAvailable(scrnIndex)))
 
295
        return FALSE;
 
296
 
 
297
    pScrn = xf86Screens[scrnIndex];
 
298
    xf86DeleteMode(&(pScrn->modes), (DisplayModePtr)mode);
 
299
    return TRUE;
 
300
}
 
301
 
 
302
Bool
 
303
VidModeZoomViewport(int scrnIndex, int zoom)
 
304
{
 
305
    ScrnInfoPtr pScrn;
 
306
 
 
307
    DEBUG_P("VidModeZoomViewPort");
 
308
 
 
309
    if (!VidModeAvailable(scrnIndex))
 
310
        return FALSE;
 
311
 
 
312
    pScrn = xf86Screens[scrnIndex];
 
313
    xf86ZoomViewport(pScrn->pScreen, zoom);
 
314
    return TRUE;
 
315
}
 
316
 
 
317
Bool
 
318
VidModeSetViewPort(int scrnIndex, int x, int y)
 
319
{
 
320
    ScrnInfoPtr pScrn;
 
321
 
 
322
    DEBUG_P("VidModeSetViewPort");
 
323
 
 
324
    if (!VidModeAvailable(scrnIndex))
 
325
        return FALSE;
 
326
 
 
327
    pScrn = xf86Screens[scrnIndex];
 
328
    pScrn->frameX0 = min( max(x, 0),
 
329
                         pScrn->virtualX - pScrn->currentMode->HDisplay );
 
330
    pScrn->frameX1 = pScrn->frameX0 + pScrn->currentMode->HDisplay - 1;
 
331
    pScrn->frameY0 = min( max(y, 0),
 
332
                         pScrn->virtualY - pScrn->currentMode->VDisplay );
 
333
    pScrn->frameY1 = pScrn->frameY0 + pScrn->currentMode->VDisplay - 1;
 
334
    if (pScrn->AdjustFrame != NULL)
 
335
        (pScrn->AdjustFrame)(scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
 
336
 
 
337
    return TRUE;
 
338
}
 
339
 
 
340
Bool
 
341
VidModeGetViewPort(int scrnIndex, int *x, int *y)
 
342
{
 
343
    ScrnInfoPtr pScrn;
 
344
 
 
345
    DEBUG_P("VidModeGetViewPort");
 
346
 
 
347
    if (!VidModeAvailable(scrnIndex))
 
348
        return FALSE;
 
349
 
 
350
    pScrn = xf86Screens[scrnIndex];
 
351
    *x = pScrn->frameX0;
 
352
    *y = pScrn->frameY0;
 
353
    return TRUE;
 
354
}
 
355
 
 
356
Bool
 
357
VidModeSwitchMode(int scrnIndex, pointer mode)
 
358
{
 
359
    ScrnInfoPtr pScrn;
 
360
    DisplayModePtr pTmpMode;
 
361
    Bool retval;
 
362
 
 
363
    DEBUG_P("VidModeSwitchMode");
 
364
 
 
365
    if (!VidModeAvailable(scrnIndex))
 
366
        return FALSE;
 
367
 
 
368
    pScrn = xf86Screens[scrnIndex];
 
369
    /* save in case we fail */
 
370
    pTmpMode = pScrn->currentMode;
 
371
    /* Force a mode switch */
 
372
    pScrn->currentMode = NULL;
 
373
    retval = xf86SwitchMode(pScrn->pScreen, mode);
 
374
    /* we failed: restore it */
 
375
    if (retval == FALSE)
 
376
        pScrn->currentMode = pTmpMode;
 
377
    return retval;
 
378
}
 
379
 
 
380
Bool
 
381
VidModeLockZoom(int scrnIndex, Bool lock)
 
382
{
 
383
    ScrnInfoPtr pScrn;
 
384
 
 
385
    DEBUG_P("VidModeLockZoom");
 
386
 
 
387
    if (!VidModeAvailable(scrnIndex))
 
388
        return FALSE;
 
389
 
 
390
    pScrn = xf86Screens[scrnIndex];
 
391
 
 
392
    if (xf86Info.dontZoom)
 
393
        return FALSE;
 
394
 
 
395
    xf86LockZoom(pScrn->pScreen, lock);
 
396
    return TRUE;
 
397
}
 
398
 
 
399
Bool
 
400
VidModeGetMonitor(int scrnIndex, pointer *monitor)
 
401
{
 
402
    ScrnInfoPtr pScrn;
 
403
 
 
404
    DEBUG_P("VidModeGetMonitor");
 
405
 
 
406
    if (!VidModeAvailable(scrnIndex))
 
407
        return FALSE;
 
408
 
 
409
    pScrn = xf86Screens[scrnIndex];
 
410
    *monitor = (pointer)(pScrn->monitor);
 
411
 
 
412
    return TRUE;
 
413
}
 
414
 
 
415
ModeStatus
 
416
VidModeCheckModeForMonitor(int scrnIndex, pointer mode)
 
417
{
 
418
    ScrnInfoPtr pScrn;
 
419
 
 
420
    DEBUG_P("VidModeCheckModeForMonitor");
 
421
 
 
422
    if ((mode == NULL) || (!VidModeAvailable(scrnIndex)))
 
423
        return MODE_ERROR;
 
424
 
 
425
    pScrn = xf86Screens[scrnIndex];
 
426
 
 
427
    return xf86CheckModeForMonitor((DisplayModePtr)mode, pScrn->monitor);
 
428
}
 
429
 
 
430
ModeStatus
 
431
VidModeCheckModeForDriver(int scrnIndex, pointer mode)
 
432
{
 
433
    ScrnInfoPtr pScrn;
 
434
 
 
435
    DEBUG_P("VidModeCheckModeForDriver");
 
436
 
 
437
    if ((mode == NULL) || (!VidModeAvailable(scrnIndex)))
 
438
        return MODE_ERROR;
 
439
 
 
440
    pScrn = xf86Screens[scrnIndex];
 
441
 
 
442
    return xf86CheckModeForDriver(pScrn, (DisplayModePtr)mode, 0);
 
443
}
 
444
 
 
445
void
 
446
VidModeSetCrtcForMode(int scrnIndex, pointer mode)
 
447
{
 
448
    ScrnInfoPtr pScrn;
 
449
    DisplayModePtr ScreenModes;
 
450
    
 
451
    DEBUG_P("VidModeSetCrtcForMode");
 
452
 
 
453
    if ((mode == NULL) || (!VidModeAvailable(scrnIndex)))
 
454
        return;
 
455
 
 
456
    /* Ugly hack so that the xf86Mode.c function can be used without change */
 
457
    pScrn = xf86Screens[scrnIndex];
 
458
    ScreenModes = pScrn->modes;
 
459
    pScrn->modes = (DisplayModePtr)mode;
 
460
    
 
461
    xf86SetCrtcForModes(pScrn, pScrn->adjustFlags);
 
462
    pScrn->modes = ScreenModes;
 
463
    return;
 
464
}
 
465
 
 
466
Bool
 
467
VidModeAddModeline(int scrnIndex, pointer mode)
 
468
{
 
469
    ScrnInfoPtr pScrn;
 
470
    
 
471
    DEBUG_P("VidModeAddModeline");
 
472
 
 
473
    if ((mode == NULL) || (!VidModeAvailable(scrnIndex)))
 
474
        return FALSE;
 
475
 
 
476
    pScrn = xf86Screens[scrnIndex];
 
477
 
 
478
    ((DisplayModePtr)mode)->name         = strdup(""); /* freed by deletemode */
 
479
    ((DisplayModePtr)mode)->status       = MODE_OK;
 
480
    ((DisplayModePtr)mode)->next         = pScrn->modes->next;
 
481
    ((DisplayModePtr)mode)->prev         = pScrn->modes;
 
482
    pScrn->modes->next                   = (DisplayModePtr)mode;
 
483
    if( ((DisplayModePtr)mode)->next != NULL )
 
484
      ((DisplayModePtr)mode)->next->prev   = (DisplayModePtr)mode;
 
485
 
 
486
    return TRUE;
 
487
}
 
488
 
 
489
int
 
490
VidModeGetNumOfModes(int scrnIndex)
 
491
{
 
492
    pointer mode = NULL;
 
493
    int dotClock= 0, nummodes = 0;
 
494
  
 
495
    DEBUG_P("VidModeGetNumOfModes");
 
496
 
 
497
    if (!VidModeGetFirstModeline(scrnIndex, &mode, &dotClock))
 
498
        return nummodes;
 
499
 
 
500
    do {
 
501
        nummodes++;
 
502
        if (!VidModeGetNextModeline(scrnIndex, &mode, &dotClock))
 
503
            return nummodes;
 
504
    } while (TRUE);
 
505
}
 
506
 
 
507
Bool
 
508
VidModeSetGamma(int scrnIndex, float red, float green, float blue)
 
509
{
 
510
    ScrnInfoPtr pScrn;
 
511
    Gamma gamma;
 
512
 
 
513
    DEBUG_P("VidModeSetGamma");
 
514
 
 
515
    if (!VidModeAvailable(scrnIndex))
 
516
        return FALSE;
 
517
 
 
518
    pScrn = xf86Screens[scrnIndex];
 
519
    gamma.red = red;
 
520
    gamma.green = green;
 
521
    gamma.blue = blue;
 
522
    if (xf86ChangeGamma(pScrn->pScreen, gamma) != Success)
 
523
        return FALSE;
 
524
    else
 
525
        return TRUE;
 
526
}
 
527
 
 
528
Bool
 
529
VidModeGetGamma(int scrnIndex, float *red, float *green, float *blue)
 
530
{
 
531
    ScrnInfoPtr pScrn;
 
532
 
 
533
    DEBUG_P("VidModeGetGamma");
 
534
 
 
535
    if (!VidModeAvailable(scrnIndex))
 
536
        return FALSE;
 
537
 
 
538
    pScrn = xf86Screens[scrnIndex];
 
539
    *red = pScrn->gamma.red;
 
540
    *green = pScrn->gamma.green;
 
541
    *blue = pScrn->gamma.blue;
 
542
    return TRUE;
 
543
}
 
544
 
 
545
Bool
 
546
VidModeSetGammaRamp(int scrnIndex, int size, CARD16 *r, CARD16 *g, CARD16 *b)
 
547
{
 
548
    ScrnInfoPtr pScrn;
 
549
 
 
550
    if (!VidModeAvailable(scrnIndex))
 
551
        return FALSE;
 
552
 
 
553
    pScrn = xf86Screens[scrnIndex];
 
554
    xf86ChangeGammaRamp(pScrn->pScreen, size, r, g, b);
 
555
    return TRUE;
 
556
}
 
557
 
 
558
Bool
 
559
VidModeGetGammaRamp(int scrnIndex, int size, CARD16 *r, CARD16 *g, CARD16 *b)
 
560
{
 
561
    ScrnInfoPtr pScrn;
 
562
 
 
563
    if (!VidModeAvailable(scrnIndex))
 
564
        return FALSE;
 
565
 
 
566
    pScrn = xf86Screens[scrnIndex];
 
567
    xf86GetGammaRamp(pScrn->pScreen, size, r, g, b);
 
568
    return TRUE;
 
569
}
 
570
 
 
571
int
 
572
VidModeGetGammaRampSize(int scrnIndex)
 
573
{
 
574
    if (!VidModeAvailable(scrnIndex))
 
575
        return 0;
 
576
 
 
577
    return xf86GetGammaRampSize(xf86Screens[scrnIndex]->pScreen);
 
578
}
 
579
 
 
580
pointer
 
581
VidModeCreateMode(void)
 
582
{
 
583
    DisplayModePtr mode;
 
584
  
 
585
    mode = xalloc(sizeof(DisplayModeRec));
 
586
    if (mode != NULL) {
 
587
        mode->name          = "";
 
588
        mode->VScan         = 1;    /* divides refresh rate. default = 1 */
 
589
        mode->Private       = NULL;
 
590
        mode->next          = mode;
 
591
        mode->prev          = mode;
 
592
    }
 
593
    return mode;
 
594
}
 
595
 
 
596
void
 
597
VidModeCopyMode(pointer modefrom, pointer modeto)
 
598
{
 
599
  memcpy(modeto, modefrom, sizeof(DisplayModeRec));
 
600
}
 
601
 
 
602
 
 
603
int
 
604
VidModeGetModeValue(pointer mode, int valtyp)
 
605
{
 
606
  int ret = 0;
 
607
  
 
608
  switch (valtyp) {
 
609
    case VIDMODE_H_DISPLAY:
 
610
        ret = ((DisplayModePtr) mode)->HDisplay;
 
611
        break;
 
612
    case VIDMODE_H_SYNCSTART:
 
613
        ret = ((DisplayModePtr)mode)->HSyncStart;
 
614
        break;
 
615
    case VIDMODE_H_SYNCEND:
 
616
        ret = ((DisplayModePtr)mode)->HSyncEnd;
 
617
        break;
 
618
    case VIDMODE_H_TOTAL:
 
619
        ret = ((DisplayModePtr)mode)->HTotal;
 
620
        break;
 
621
    case VIDMODE_H_SKEW:
 
622
        ret = ((DisplayModePtr)mode)->HSkew;
 
623
        break;
 
624
    case VIDMODE_V_DISPLAY:
 
625
        ret = ((DisplayModePtr)mode)->VDisplay;
 
626
        break;
 
627
    case VIDMODE_V_SYNCSTART:
 
628
        ret = ((DisplayModePtr)mode)->VSyncStart;
 
629
        break;
 
630
    case VIDMODE_V_SYNCEND:
 
631
        ret = ((DisplayModePtr)mode)->VSyncEnd;
 
632
        break;
 
633
    case VIDMODE_V_TOTAL:
 
634
        ret = ((DisplayModePtr)mode)->VTotal;
 
635
        break;
 
636
    case VIDMODE_FLAGS:
 
637
        ret = ((DisplayModePtr)mode)->Flags;
 
638
        break;
 
639
    case VIDMODE_CLOCK:
 
640
        ret = ((DisplayModePtr)mode)->Clock;
 
641
        break;
 
642
  }
 
643
  return ret;
 
644
}
 
645
 
 
646
void
 
647
VidModeSetModeValue(pointer mode, int valtyp, int val)
 
648
{
 
649
  switch (valtyp) {
 
650
    case VIDMODE_H_DISPLAY:
 
651
        ((DisplayModePtr)mode)->HDisplay = val;
 
652
        break;
 
653
    case VIDMODE_H_SYNCSTART:
 
654
        ((DisplayModePtr)mode)->HSyncStart = val;
 
655
        break;
 
656
    case VIDMODE_H_SYNCEND:
 
657
        ((DisplayModePtr)mode)->HSyncEnd = val;
 
658
        break;
 
659
    case VIDMODE_H_TOTAL:
 
660
        ((DisplayModePtr)mode)->HTotal = val;
 
661
        break;
 
662
    case VIDMODE_H_SKEW:
 
663
        ((DisplayModePtr)mode)->HSkew = val;
 
664
        break;
 
665
    case VIDMODE_V_DISPLAY:
 
666
        ((DisplayModePtr)mode)->VDisplay = val;
 
667
        break;
 
668
    case VIDMODE_V_SYNCSTART:
 
669
        ((DisplayModePtr)mode)->VSyncStart = val;
 
670
        break;
 
671
    case VIDMODE_V_SYNCEND:
 
672
        ((DisplayModePtr)mode)->VSyncEnd = val;
 
673
        break;
 
674
    case VIDMODE_V_TOTAL:
 
675
        ((DisplayModePtr)mode)->VTotal = val;
 
676
        break;
 
677
    case VIDMODE_FLAGS:
 
678
        ((DisplayModePtr)mode)->Flags = val;
 
679
        break;
 
680
    case VIDMODE_CLOCK:
 
681
        ((DisplayModePtr)mode)->Clock = val;
 
682
        break;
 
683
  }
 
684
  return;
 
685
}
 
686
 
 
687
vidMonitorValue
 
688
VidModeGetMonitorValue(pointer monitor, int valtyp, int indx)
 
689
{
 
690
  vidMonitorValue ret;
 
691
  
 
692
  switch (valtyp) {
 
693
    case VIDMODE_MON_VENDOR:
 
694
        ret.ptr = (((MonPtr)monitor)->vendor);
 
695
        break;
 
696
    case VIDMODE_MON_MODEL:
 
697
        ret.ptr = (((MonPtr)monitor)->model);
 
698
        break;
 
699
    case VIDMODE_MON_NHSYNC:
 
700
        ret.i = ((MonPtr)monitor)->nHsync;
 
701
        break;
 
702
    case VIDMODE_MON_NVREFRESH:
 
703
        ret.i = ((MonPtr)monitor)->nVrefresh;
 
704
        break;
 
705
    case VIDMODE_MON_HSYNC_LO:
 
706
        ret.f = (100.0 * ((MonPtr)monitor)->hsync[indx].lo);
 
707
        break;
 
708
    case VIDMODE_MON_HSYNC_HI:
 
709
        ret.f = (100.0 * ((MonPtr)monitor)->hsync[indx].hi);
 
710
        break;
 
711
    case VIDMODE_MON_VREFRESH_LO:
 
712
        ret.f = (100.0 * ((MonPtr)monitor)->vrefresh[indx].lo);
 
713
        break;
 
714
    case VIDMODE_MON_VREFRESH_HI:
 
715
        ret.f = (100.0 * ((MonPtr)monitor)->vrefresh[indx].hi);
 
716
        break;
 
717
  }
 
718
  return ret;
 
719
}
 
720
 
 
721
 
 
722
#endif /* XF86VIDMODE */