2 * Copyright (c) 1997-2003 by The XFree86 Project, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
22 * Except as contained in this notice, the name of the copyright holder(s)
23 * and author(s) shall not be used in advertising or otherwise to promote
24 * the sale, use or other dealings in this Software without prior written
25 * authorization from the copyright holder(s) and author(s).
29 * Authors: Dirk Hohndel <hohndel@XFree86.Org>
30 * David Dawes <dawes@XFree86.Org>
33 * This file includes the helper functions that the server provides for
37 #ifdef HAVE_XORG_CONFIG_H
38 #include <xorg-config.h>
44 #include "pixmapstr.h"
45 #include "windowstr.h"
46 #include "propertyst.h"
48 #include "loaderProcs.h"
51 #include "xf86_OSlib.h"
54 #include "xf86Xinput.h"
55 #include "xf86InPriv.h"
56 #include "mivalidate.h"
59 /* For xf86GetClocks */
60 #if defined(CSRG_BASED) || defined(__GNU__)
61 #define HAS_SETPRIORITY
62 #include <sys/resource.h>
65 static int xf86ScrnInfoPrivateCount
= 0;
67 /* Add a pointer to a new DriverRec to xf86DriverList */
70 xf86AddDriver(DriverPtr driver
, pointer module
, int flags
)
72 /* Don't add null entries */
76 if (xf86DriverList
== NULL
)
80 xf86DriverList
= xnfrealloc(xf86DriverList
,
81 xf86NumDrivers
* sizeof(DriverPtr
));
82 xf86DriverList
[xf86NumDrivers
- 1] = xnfalloc(sizeof(DriverRec
));
83 if (flags
& HaveDriverFuncs
)
84 *xf86DriverList
[xf86NumDrivers
- 1] = *driver
;
86 (void) memset(xf86DriverList
[xf86NumDrivers
- 1], 0, sizeof(DriverRec
));
87 (void) memcpy(xf86DriverList
[xf86NumDrivers
- 1], driver
,
91 xf86DriverList
[xf86NumDrivers
- 1]->module
= module
;
92 xf86DriverList
[xf86NumDrivers
- 1]->refCount
= 0;
96 xf86DeleteDriver(int drvIndex
)
98 if (xf86DriverList
[drvIndex
]
99 && (!xf86DriverHasEntities(xf86DriverList
[drvIndex
]))) {
100 if (xf86DriverList
[drvIndex
]->module
)
101 UnloadModule(xf86DriverList
[drvIndex
]->module
);
102 free(xf86DriverList
[drvIndex
]);
103 xf86DriverList
[drvIndex
] = NULL
;
107 /* Add a pointer to a new InputDriverRec to xf86InputDriverList */
110 xf86AddInputDriver(InputDriverPtr driver
, pointer module
, int flags
)
112 /* Don't add null entries */
116 if (xf86InputDriverList
== NULL
)
117 xf86NumInputDrivers
= 0;
119 xf86NumInputDrivers
++;
120 xf86InputDriverList
= xnfrealloc(xf86InputDriverList
,
121 xf86NumInputDrivers
*
122 sizeof(InputDriverPtr
));
123 xf86InputDriverList
[xf86NumInputDrivers
- 1] =
124 xnfalloc(sizeof(InputDriverRec
));
125 *xf86InputDriverList
[xf86NumInputDrivers
- 1] = *driver
;
126 xf86InputDriverList
[xf86NumInputDrivers
- 1]->module
= module
;
130 xf86DeleteInputDriver(int drvIndex
)
132 if (xf86InputDriverList
[drvIndex
] && xf86InputDriverList
[drvIndex
]->module
)
133 UnloadModule(xf86InputDriverList
[drvIndex
]->module
);
134 free(xf86InputDriverList
[drvIndex
]);
135 xf86InputDriverList
[drvIndex
] = NULL
;
139 xf86LookupInputDriver(const char *name
)
143 for (i
= 0; i
< xf86NumInputDrivers
; i
++) {
144 if (xf86InputDriverList
[i
] && xf86InputDriverList
[i
]->driverName
&&
145 xf86NameCmp(name
, xf86InputDriverList
[i
]->driverName
) == 0)
146 return xf86InputDriverList
[i
];
152 xf86LookupInput(const char *name
)
156 for (p
= xf86InputDevs
; p
!= NULL
; p
= p
->next
) {
157 if (strcmp(name
, p
->name
) == 0)
164 /* Allocate a new ScrnInfoRec in xf86Screens */
167 xf86AllocateScreen(DriverPtr drv
, int flags
)
172 if (flags
& XF86_ALLOCATE_GPU_SCREEN
) {
173 if (xf86GPUScreens
== NULL
)
174 xf86NumGPUScreens
= 0;
175 i
= xf86NumGPUScreens
++;
176 xf86GPUScreens
= xnfrealloc(xf86GPUScreens
, xf86NumGPUScreens
* sizeof(ScrnInfoPtr
));
177 xf86GPUScreens
[i
] = xnfcalloc(sizeof(ScrnInfoRec
), 1);
178 pScrn
= xf86GPUScreens
[i
];
179 pScrn
->scrnIndex
= i
+ GPU_SCREEN_OFFSET
; /* Changes when a screen is removed */
180 pScrn
->is_gpu
= TRUE
;
182 if (xf86Screens
== NULL
)
185 i
= xf86NumScreens
++;
186 xf86Screens
= xnfrealloc(xf86Screens
, xf86NumScreens
* sizeof(ScrnInfoPtr
));
187 xf86Screens
[i
] = xnfcalloc(sizeof(ScrnInfoRec
), 1);
188 pScrn
= xf86Screens
[i
];
190 pScrn
->scrnIndex
= i
; /* Changes when a screen is removed */
193 pScrn
->origIndex
= pScrn
->scrnIndex
; /* This never changes */
194 pScrn
->privates
= xnfcalloc(sizeof(DevUnion
), xf86ScrnInfoPrivateCount
);
196 * EnableDisableFBAccess now gets initialized in InitOutput()
197 * pScrn->EnableDisableFBAccess = xf86EnableDisableFBAccess;
202 pScrn
->module
= DuplicateModule(drv
->module
, NULL
);
204 pScrn
->DriverFunc
= drv
->driverFunc
;
210 * Remove an entry from xf86Screens. Ideally it should free all allocated
211 * data. To do this properly may require a driver hook.
215 xf86DeleteScreen(ScrnInfoPtr pScrn
)
225 /* First check if the screen is valid */
226 if (xf86NumGPUScreens
== 0 || xf86GPUScreens
== NULL
)
230 /* First check if the screen is valid */
231 if (xf86NumScreens
== 0 || xf86Screens
== NULL
)
235 scrnIndex
= pScrn
->scrnIndex
;
236 /* If a FreeScreen function is defined, call it here */
237 if (pScrn
->FreeScreen
!= NULL
)
238 pScrn
->FreeScreen(pScrn
);
241 xf86DeleteMode(&pScrn
->modes
, pScrn
->modes
);
243 while (pScrn
->modePool
)
244 xf86DeleteMode(&pScrn
->modePool
, pScrn
->modePool
);
246 xf86OptionListFree(pScrn
->options
);
249 UnloadModule(pScrn
->module
);
252 pScrn
->drv
->refCount
--;
254 free(pScrn
->privates
);
256 xf86ClearEntityListForScreen(pScrn
);
260 /* Move the other entries down, updating their scrnIndex fields */
264 scrnIndex
-= GPU_SCREEN_OFFSET
;
265 for (i
= scrnIndex
; i
< xf86NumGPUScreens
; i
++) {
266 xf86GPUScreens
[i
] = xf86GPUScreens
[i
+ 1];
267 xf86GPUScreens
[i
]->scrnIndex
= i
+ GPU_SCREEN_OFFSET
;
268 /* Also need to take care of the screen layout settings */
274 for (i
= scrnIndex
; i
< xf86NumScreens
; i
++) {
275 xf86Screens
[i
] = xf86Screens
[i
+ 1];
276 xf86Screens
[i
]->scrnIndex
= i
;
277 /* Also need to take care of the screen layout settings */
283 * Allocate a private in ScrnInfoRec.
287 xf86AllocateScrnInfoPrivateIndex(void)
293 idx
= xf86ScrnInfoPrivateCount
++;
294 for (i
= 0; i
< xf86NumScreens
; i
++) {
295 pScr
= xf86Screens
[i
];
296 nprivs
= xnfrealloc(pScr
->privates
,
297 xf86ScrnInfoPrivateCount
* sizeof(DevUnion
));
298 /* Zero the new private */
299 memset(&nprivs
[idx
], 0, sizeof(DevUnion
));
300 pScr
->privates
= nprivs
;
302 for (i
= 0; i
< xf86NumGPUScreens
; i
++) {
303 pScr
= xf86GPUScreens
[i
];
304 nprivs
= xnfrealloc(pScr
->privates
,
305 xf86ScrnInfoPrivateCount
* sizeof(DevUnion
));
306 /* Zero the new private */
307 memset(&nprivs
[idx
], 0, sizeof(DevUnion
));
308 pScr
->privates
= nprivs
;
314 xf86AddPixFormat(ScrnInfoPtr pScrn
, int depth
, int bpp
, int pad
)
318 if (pScrn
->numFormats
>= MAXFORMATS
)
326 else if (depth
<= 16)
328 else if (depth
<= 32)
334 pad
= BITMAP_SCANLINE_PAD
;
336 i
= pScrn
->numFormats
++;
337 pScrn
->formats
[i
].depth
= depth
;
338 pScrn
->formats
[i
].bitsPerPixel
= bpp
;
339 pScrn
->formats
[i
].scanlinePad
= pad
;
344 * Set the depth we are using based on (in the following order of preference):
345 * - values given on the command line
346 * - values given in the config file
347 * - values provided by the driver
348 * - an overall default when nothing else is given
350 * Also find a Display subsection matching the depth/bpp found.
352 * Sets the following ScrnInfoRec fields:
353 * bitsPerPixel, pixmap24, depth, display, imageByteOrder,
354 * bitmapScanlinePad, bitmapScanlineUnit, bitmapBitOrder, numFormats,
358 /* Can the screen handle 24 bpp pixmaps */
359 #define DO_PIX24(f) ((f & Support24bppFb) || \
360 ((f & Support32bppFb) && (f & SupportConvert24to32)))
362 /* Can the screen handle 32 bpp pixmaps */
363 #define DO_PIX32(f) ((f & Support32bppFb) || \
364 ((f & Support24bppFb) && (f & SupportConvert32to24)))
366 /* Does the screen prefer 32bpp fb for 24bpp pixmaps */
367 #define CHOOSE32FOR24(f) ((f & Support32bppFb) && (f & SupportConvert24to32) \
368 && (f & PreferConvert24to32))
370 /* Does the screen prefer 24bpp fb for 32bpp pixmaps */
371 #define CHOOSE24FOR32(f) ((f & Support24bppFb) && (f & SupportConvert32to24) \
372 && (f & PreferConvert32to24))
374 /* Can the screen handle 32bpp pixmaps for 24bpp fb */
375 #define DO_PIX32FOR24(f) ((f & Support24bppFb) && (f & SupportConvert32to24))
377 /* Can the screen handle 24bpp pixmaps for 32bpp fb */
378 #define DO_PIX24FOR32(f) ((f & Support32bppFb) && (f & SupportConvert24to32))
380 #ifndef GLOBAL_DEFAULT_DEPTH
381 #define GLOBAL_DEFAULT_DEPTH 24
385 xf86SetDepthBpp(ScrnInfoPtr scrp
, int depth
, int dummy
, int fbbpp
,
390 Pix24Flags pix24
= xf86Info
.pixmap24
;
391 Bool nomatch
= FALSE
;
393 scrp
->bitsPerPixel
= -1;
395 scrp
->pixmap24
= Pix24DontCare
;
396 scrp
->bitsPerPixelFrom
= X_DEFAULT
;
397 scrp
->depthFrom
= X_DEFAULT
;
400 scrp
->bitsPerPixel
= xf86FbBpp
;
401 scrp
->bitsPerPixelFrom
= X_CMDLINE
;
405 scrp
->depth
= xf86Depth
;
406 scrp
->depthFrom
= X_CMDLINE
;
409 if (xf86FbBpp
< 0 && xf86Depth
< 0) {
410 if (scrp
->confScreen
->defaultfbbpp
> 0) {
411 scrp
->bitsPerPixel
= scrp
->confScreen
->defaultfbbpp
;
412 scrp
->bitsPerPixelFrom
= X_CONFIG
;
414 if (scrp
->confScreen
->defaultdepth
> 0) {
415 scrp
->depth
= scrp
->confScreen
->defaultdepth
;
416 scrp
->depthFrom
= X_CONFIG
;
419 if (scrp
->confScreen
->defaultfbbpp
<= 0 &&
420 scrp
->confScreen
->defaultdepth
<= 0) {
422 * Check for DefaultDepth and DefaultFbBpp options in the
429 for (i
= 0; i
< scrp
->numEntities
; i
++) {
430 device
= xf86GetDevFromEntity(scrp
->entityList
[i
],
431 scrp
->entityInstanceList
[i
]);
432 if (device
&& device
->options
) {
433 if (xf86FindOption(device
->options
, "DefaultDepth")) {
434 scrp
->depth
= xf86SetIntOption(device
->options
,
436 scrp
->depthFrom
= X_CONFIG
;
439 if (xf86FindOption(device
->options
, "DefaultFbBpp")) {
440 scrp
->bitsPerPixel
= xf86SetIntOption(device
->options
,
443 scrp
->bitsPerPixelFrom
= X_CONFIG
;
453 /* If none of these is set, pick a default */
454 if (scrp
->bitsPerPixel
< 0 && scrp
->depth
< 0) {
455 if (fbbpp
> 0 || depth
> 0) {
457 scrp
->bitsPerPixel
= fbbpp
;
462 scrp
->depth
= GLOBAL_DEFAULT_DEPTH
;
466 /* If any are not given, determine a default for the others */
468 if (scrp
->bitsPerPixel
< 0) {
469 /* The depth must be set */
470 if (scrp
->depth
> -1) {
471 if (scrp
->depth
== 1)
472 scrp
->bitsPerPixel
= 1;
473 else if (scrp
->depth
<= 4)
474 scrp
->bitsPerPixel
= 4;
475 else if (scrp
->depth
<= 8)
476 scrp
->bitsPerPixel
= 8;
477 else if (scrp
->depth
<= 16)
478 scrp
->bitsPerPixel
= 16;
479 else if (scrp
->depth
<= 24) {
481 * Figure out if a choice is possible based on the depth24
484 /* Check pix24 first */
485 if (pix24
!= Pix24DontCare
) {
486 if (pix24
== Pix24Use32
) {
487 if (DO_PIX32(depth24flags
)) {
488 if (CHOOSE24FOR32(depth24flags
))
489 scrp
->bitsPerPixel
= 24;
491 scrp
->bitsPerPixel
= 32;
497 else if (pix24
== Pix24Use24
) {
498 if (DO_PIX24(depth24flags
)) {
499 if (CHOOSE32FOR24(depth24flags
))
500 scrp
->bitsPerPixel
= 32;
502 scrp
->bitsPerPixel
= 24;
510 if (DO_PIX32(depth24flags
)) {
511 if (CHOOSE24FOR32(depth24flags
))
512 scrp
->bitsPerPixel
= 24;
514 scrp
->bitsPerPixel
= 32;
516 else if (DO_PIX24(depth24flags
)) {
517 if (CHOOSE32FOR24(depth24flags
))
518 scrp
->bitsPerPixel
= 32;
520 scrp
->bitsPerPixel
= 24;
524 else if (scrp
->depth
<= 32)
525 scrp
->bitsPerPixel
= 32;
527 xf86DrvMsg(scrp
->scrnIndex
, X_ERROR
,
528 "Specified depth (%d) is greater than 32\n",
534 xf86DrvMsg(scrp
->scrnIndex
, X_ERROR
,
535 "xf86SetDepthBpp: internal error: depth and fbbpp"
536 " are both not set\n");
539 if (scrp
->bitsPerPixel
< 0) {
541 xf86DrvMsg(scrp
->scrnIndex
, X_ERROR
,
542 "Driver can't support depth 24 pixmap format (%d)\n",
544 else if ((depth24flags
& (Support24bppFb
| Support32bppFb
)) ==
546 xf86DrvMsg(scrp
->scrnIndex
, X_ERROR
,
547 "Driver can't support depth 24\n");
549 xf86DrvMsg(scrp
->scrnIndex
, X_ERROR
,
550 "Can't find fbbpp for depth 24\n");
553 scrp
->bitsPerPixelFrom
= X_PROBED
;
556 if (scrp
->depth
<= 0) {
557 /* bitsPerPixel is already set */
558 switch (scrp
->bitsPerPixel
) {
563 /* 1, 4, 8, 16 and 24 */
564 scrp
->depth
= scrp
->bitsPerPixel
;
567 scrp
->depthFrom
= X_PROBED
;
571 if (scrp
->depth
< 1 || scrp
->depth
> 32) {
572 xf86DrvMsg(scrp
->scrnIndex
, X_ERROR
,
573 "Specified depth (%d) is not in the range 1-32\n",
577 switch (scrp
->bitsPerPixel
) {
586 xf86DrvMsg(scrp
->scrnIndex
, X_ERROR
,
587 "Specified fbbpp (%d) is not a permitted value\n",
591 if (scrp
->depth
> scrp
->bitsPerPixel
) {
592 xf86DrvMsg(scrp
->scrnIndex
, X_ERROR
,
593 "Specified depth (%d) is greater than the fbbpp (%d)\n",
594 scrp
->depth
, scrp
->bitsPerPixel
);
598 /* set scrp->pixmap24 if the driver isn't flexible */
599 if (scrp
->bitsPerPixel
== 24 && !DO_PIX32FOR24(depth24flags
)) {
600 scrp
->pixmap24
= Pix24Use24
;
602 if (scrp
->bitsPerPixel
== 32 && !DO_PIX24FOR32(depth24flags
)) {
603 scrp
->pixmap24
= Pix24Use32
;
607 * Find the Display subsection matching the depth/fbbpp and initialise
608 * scrp->display with it.
610 for (i
= 0, disp
= scrp
->confScreen
->displays
;
611 i
< scrp
->confScreen
->numdisplays
; i
++, disp
++) {
612 if ((disp
->depth
== scrp
->depth
&& disp
->fbbpp
== scrp
->bitsPerPixel
)
613 || (disp
->depth
== scrp
->depth
&& disp
->fbbpp
<= 0)
614 || (disp
->fbbpp
== scrp
->bitsPerPixel
&& disp
->depth
<= 0)) {
615 scrp
->display
= disp
;
621 * If an exact match can't be found, see if there is one with no
622 * depth or fbbpp specified.
624 if (i
== scrp
->confScreen
->numdisplays
) {
625 for (i
= 0, disp
= scrp
->confScreen
->displays
;
626 i
< scrp
->confScreen
->numdisplays
; i
++, disp
++) {
627 if (disp
->depth
<= 0 && disp
->fbbpp
<= 0) {
628 scrp
->display
= disp
;
635 * If all else fails, create a default one.
637 if (i
== scrp
->confScreen
->numdisplays
) {
638 scrp
->confScreen
->numdisplays
++;
639 scrp
->confScreen
->displays
=
640 xnfrealloc(scrp
->confScreen
->displays
,
641 scrp
->confScreen
->numdisplays
* sizeof(DispRec
));
642 xf86DrvMsg(scrp
->scrnIndex
, X_INFO
,
643 "Creating default Display subsection in Screen section\n"
644 "\t\"%s\" for depth/fbbpp %d/%d\n",
645 scrp
->confScreen
->id
, scrp
->depth
, scrp
->bitsPerPixel
);
646 memset(&scrp
->confScreen
->displays
[i
], 0, sizeof(DispRec
));
647 scrp
->confScreen
->displays
[i
].blackColour
.red
= -1;
648 scrp
->confScreen
->displays
[i
].blackColour
.green
= -1;
649 scrp
->confScreen
->displays
[i
].blackColour
.blue
= -1;
650 scrp
->confScreen
->displays
[i
].whiteColour
.red
= -1;
651 scrp
->confScreen
->displays
[i
].whiteColour
.green
= -1;
652 scrp
->confScreen
->displays
[i
].whiteColour
.blue
= -1;
653 scrp
->confScreen
->displays
[i
].defaultVisual
= -1;
654 scrp
->confScreen
->displays
[i
].modes
= xnfalloc(sizeof(char *));
655 scrp
->confScreen
->displays
[i
].modes
[0] = NULL
;
656 scrp
->confScreen
->displays
[i
].depth
= depth
;
657 scrp
->confScreen
->displays
[i
].fbbpp
= fbbpp
;
658 scrp
->display
= &scrp
->confScreen
->displays
[i
];
662 * Setup defaults for the display-wide attributes the framebuffer will
663 * need. These defaults should eventually be set globally, and not
664 * dependent on the screens.
666 scrp
->imageByteOrder
= IMAGE_BYTE_ORDER
;
667 scrp
->bitmapScanlinePad
= BITMAP_SCANLINE_PAD
;
668 if (scrp
->depth
< 8) {
669 /* Planar modes need these settings */
670 scrp
->bitmapScanlineUnit
= 8;
671 scrp
->bitmapBitOrder
= MSBFirst
;
674 scrp
->bitmapScanlineUnit
= BITMAP_SCANLINE_UNIT
;
675 scrp
->bitmapBitOrder
= BITMAP_BIT_ORDER
;
679 * If an unusual depth is required, add it to scrp->formats. The formats
680 * for the common depths are handled globally in InitOutput
682 switch (scrp
->depth
) {
689 /* Common depths. Nothing to do for them */
692 if (!xf86AddPixFormat(scrp
, scrp
->depth
, 0, 0)) {
693 xf86DrvMsg(scrp
->scrnIndex
, X_ERROR
,
694 "Can't add pixmap format for depth %d\n", scrp
->depth
);
699 /* Initialise the framebuffer format for this screen */
700 scrp
->fbFormat
.depth
= scrp
->depth
;
701 scrp
->fbFormat
.bitsPerPixel
= scrp
->bitsPerPixel
;
702 scrp
->fbFormat
.scanlinePad
= BITMAP_SCANLINE_PAD
;
708 * Print out the selected depth and bpp.
711 xf86PrintDepthBpp(ScrnInfoPtr scrp
)
713 xf86DrvMsg(scrp
->scrnIndex
, scrp
->depthFrom
, "Depth %d, ", scrp
->depth
);
714 xf86Msg(scrp
->bitsPerPixelFrom
, "framebuffer bpp %d\n", scrp
->bitsPerPixel
);
718 * xf86SetWeight sets scrp->weight, scrp->mask, scrp->offset, and for depths
719 * greater than MAX_PSEUDO_DEPTH also scrp->rgbBits.
722 xf86SetWeight(ScrnInfoPtr scrp
, rgb weight
, rgb mask
)
724 MessageType weightFrom
= X_DEFAULT
;
726 scrp
->weight
.red
= 0;
727 scrp
->weight
.green
= 0;
728 scrp
->weight
.blue
= 0;
730 if (xf86Weight
.red
> 0 && xf86Weight
.green
> 0 && xf86Weight
.blue
> 0) {
731 scrp
->weight
= xf86Weight
;
732 weightFrom
= X_CMDLINE
;
734 else if (scrp
->display
->weight
.red
> 0 && scrp
->display
->weight
.green
> 0
735 && scrp
->display
->weight
.blue
> 0) {
736 scrp
->weight
= scrp
->display
->weight
;
737 weightFrom
= X_CONFIG
;
739 else if (weight
.red
> 0 && weight
.green
> 0 && weight
.blue
> 0) {
740 scrp
->weight
= weight
;
743 switch (scrp
->depth
) {
747 scrp
->weight
.red
= scrp
->weight
.green
=
748 scrp
->weight
.blue
= scrp
->rgbBits
;
751 scrp
->weight
.red
= scrp
->weight
.green
= scrp
->weight
.blue
= 5;
754 scrp
->weight
.red
= scrp
->weight
.blue
= 5;
755 scrp
->weight
.green
= 6;
758 scrp
->weight
.red
= scrp
->weight
.green
= scrp
->weight
.blue
= 6;
761 scrp
->weight
.red
= scrp
->weight
.green
= scrp
->weight
.blue
= 8;
764 scrp
->weight
.red
= scrp
->weight
.green
= scrp
->weight
.blue
= 10;
769 if (scrp
->weight
.red
)
770 xf86DrvMsg(scrp
->scrnIndex
, weightFrom
, "RGB weight %d%d%d\n",
771 (int) scrp
->weight
.red
, (int) scrp
->weight
.green
,
772 (int) scrp
->weight
.blue
);
774 if (scrp
->depth
> MAX_PSEUDO_DEPTH
&&
775 (scrp
->depth
!= scrp
->weight
.red
+ scrp
->weight
.green
+
776 scrp
->weight
.blue
)) {
777 xf86DrvMsg(scrp
->scrnIndex
, X_ERROR
,
778 "Weight given (%d%d%d) is inconsistent with the "
780 (int) scrp
->weight
.red
, (int) scrp
->weight
.green
,
781 (int) scrp
->weight
.blue
, scrp
->depth
);
784 if (scrp
->depth
> MAX_PSEUDO_DEPTH
&& scrp
->weight
.red
) {
786 * XXX Does this even mean anything for TrueColor visuals?
787 * If not, we shouldn't even be setting it here. However, this
788 * matches the behaviour of 3.x versions of XFree86.
790 scrp
->rgbBits
= scrp
->weight
.red
;
791 if (scrp
->weight
.green
> scrp
->rgbBits
)
792 scrp
->rgbBits
= scrp
->weight
.green
;
793 if (scrp
->weight
.blue
> scrp
->rgbBits
)
794 scrp
->rgbBits
= scrp
->weight
.blue
;
797 /* Set the mask and offsets */
798 if (mask
.red
== 0 || mask
.green
== 0 || mask
.blue
== 0) {
799 /* Default to a setting common to PC hardware */
800 scrp
->offset
.red
= scrp
->weight
.green
+ scrp
->weight
.blue
;
801 scrp
->offset
.green
= scrp
->weight
.blue
;
802 scrp
->offset
.blue
= 0;
803 scrp
->mask
.red
= ((1 << scrp
->weight
.red
) - 1) << scrp
->offset
.red
;
804 scrp
->mask
.green
= ((1 << scrp
->weight
.green
) - 1)
805 << scrp
->offset
.green
;
806 scrp
->mask
.blue
= (1 << scrp
->weight
.blue
) - 1;
809 /* Initialise to the values passed */
810 scrp
->mask
.red
= mask
.red
;
811 scrp
->mask
.green
= mask
.green
;
812 scrp
->mask
.blue
= mask
.blue
;
813 scrp
->offset
.red
= ffs(mask
.red
);
814 scrp
->offset
.green
= ffs(mask
.green
);
815 scrp
->offset
.blue
= ffs(mask
.blue
);
821 xf86SetDefaultVisual(ScrnInfoPtr scrp
, int visual
)
823 MessageType visualFrom
= X_DEFAULT
;
825 if (defaultColorVisualClass
>= 0) {
826 scrp
->defaultVisual
= defaultColorVisualClass
;
827 visualFrom
= X_CMDLINE
;
829 else if (scrp
->display
->defaultVisual
>= 0) {
830 scrp
->defaultVisual
= scrp
->display
->defaultVisual
;
831 visualFrom
= X_CONFIG
;
833 else if (visual
>= 0) {
834 scrp
->defaultVisual
= visual
;
837 if (scrp
->depth
== 1)
838 scrp
->defaultVisual
= StaticGray
;
839 else if (scrp
->depth
== 4)
840 scrp
->defaultVisual
= StaticColor
;
841 else if (scrp
->depth
<= MAX_PSEUDO_DEPTH
)
842 scrp
->defaultVisual
= PseudoColor
;
844 scrp
->defaultVisual
= TrueColor
;
846 switch (scrp
->defaultVisual
) {
853 xf86DrvMsg(scrp
->scrnIndex
, visualFrom
, "Default visual is %s\n",
854 xf86VisualNames
[scrp
->defaultVisual
]);
858 xf86DrvMsg(scrp
->scrnIndex
, X_ERROR
,
859 "Invalid default visual class (%d)\n", scrp
->defaultVisual
);
864 #define TEST_GAMMA(g) \
865 (g).red > GAMMA_ZERO || (g).green > GAMMA_ZERO || (g).blue > GAMMA_ZERO
867 #define SET_GAMMA(g) \
868 (g) > GAMMA_ZERO ? (g) : 1.0
871 xf86SetGamma(ScrnInfoPtr scrp
, Gamma gamma
)
873 MessageType from
= X_DEFAULT
;
876 xf86MonPtr DDC
= (xf86MonPtr
) (scrp
->monitor
->DDC
);
878 if (TEST_GAMMA(xf86Gamma
)) {
880 scrp
->gamma
.red
= SET_GAMMA(xf86Gamma
.red
);
881 scrp
->gamma
.green
= SET_GAMMA(xf86Gamma
.green
);
882 scrp
->gamma
.blue
= SET_GAMMA(xf86Gamma
.blue
);
884 else if (TEST_GAMMA(scrp
->monitor
->gamma
)) {
886 scrp
->gamma
.red
= SET_GAMMA(scrp
->monitor
->gamma
.red
);
887 scrp
->gamma
.green
= SET_GAMMA(scrp
->monitor
->gamma
.green
);
888 scrp
->gamma
.blue
= SET_GAMMA(scrp
->monitor
->gamma
.blue
);
891 else if (DDC
&& DDC
->features
.gamma
> GAMMA_ZERO
) {
893 scrp
->gamma
.red
= SET_GAMMA(DDC
->features
.gamma
);
894 scrp
->gamma
.green
= SET_GAMMA(DDC
->features
.gamma
);
895 scrp
->gamma
.blue
= SET_GAMMA(DDC
->features
.gamma
);
896 /* EDID structure version 2 gives optional seperate red, green & blue gamma values
897 * in bytes 0x57-0x59 */
900 else if (TEST_GAMMA(gamma
)) {
901 scrp
->gamma
.red
= SET_GAMMA(gamma
.red
);
902 scrp
->gamma
.green
= SET_GAMMA(gamma
.green
);
903 scrp
->gamma
.blue
= SET_GAMMA(gamma
.blue
);
906 scrp
->gamma
.red
= 1.0;
907 scrp
->gamma
.green
= 1.0;
908 scrp
->gamma
.blue
= 1.0;
910 /* Pretend we succeeded if we support better a gamma system.
911 * This avoids a confusing message.
913 if (xf86_crtc_supports_gamma(scrp
))
915 xf86DrvMsg(scrp
->scrnIndex
, from
,
916 "Using gamma correction (%.1f, %.1f, %.1f)\n",
917 scrp
->gamma
.red
, scrp
->gamma
.green
, scrp
->gamma
.blue
);
926 * Set the DPI from the command line option. XXX should allow it to be
927 * calculated from the widthmm/heightmm values.
931 #define MMPERINCH 25.4
934 xf86SetDpi(ScrnInfoPtr pScrn
, int x
, int y
)
936 MessageType from
= X_DEFAULT
;
937 xf86MonPtr DDC
= (xf86MonPtr
) (pScrn
->monitor
->DDC
);
938 int ddcWidthmm
, ddcHeightmm
;
939 int widthErr
, heightErr
;
941 /* XXX Maybe there is no need for widthmm/heightmm in ScrnInfoRec */
942 pScrn
->widthmm
= pScrn
->monitor
->widthmm
;
943 pScrn
->heightmm
= pScrn
->monitor
->heightmm
;
945 if (DDC
&& (DDC
->features
.hsize
> 0 && DDC
->features
.vsize
> 0)) {
946 /* DDC gives display size in mm for individual modes,
949 ddcWidthmm
= DDC
->features
.hsize
* 10; /* 10mm in 1cm */
950 ddcHeightmm
= DDC
->features
.vsize
* 10; /* 10mm in 1cm */
953 ddcWidthmm
= ddcHeightmm
= 0;
956 if (monitorResolution
> 0) {
957 pScrn
->xDpi
= monitorResolution
;
958 pScrn
->yDpi
= monitorResolution
;
961 else if (pScrn
->widthmm
> 0 || pScrn
->heightmm
> 0) {
963 if (pScrn
->widthmm
> 0) {
965 (int) ((double) pScrn
->virtualX
* MMPERINCH
/ pScrn
->widthmm
);
967 if (pScrn
->heightmm
> 0) {
969 (int) ((double) pScrn
->virtualY
* MMPERINCH
/ pScrn
->heightmm
);
971 if (pScrn
->xDpi
> 0 && pScrn
->yDpi
<= 0)
972 pScrn
->yDpi
= pScrn
->xDpi
;
973 if (pScrn
->yDpi
> 0 && pScrn
->xDpi
<= 0)
974 pScrn
->xDpi
= pScrn
->yDpi
;
975 xf86DrvMsg(pScrn
->scrnIndex
, from
, "Display dimensions: (%d, %d) mm\n",
976 pScrn
->widthmm
, pScrn
->heightmm
);
978 /* Warn if config and probe disagree about display size */
979 if (ddcWidthmm
&& ddcHeightmm
) {
980 if (pScrn
->widthmm
> 0) {
981 widthErr
= abs(ddcWidthmm
- pScrn
->widthmm
);
986 if (pScrn
->heightmm
> 0) {
987 heightErr
= abs(ddcHeightmm
- pScrn
->heightmm
);
992 if (widthErr
> 10 || heightErr
> 10) {
993 /* Should include config file name for monitor here */
994 xf86DrvMsg(pScrn
->scrnIndex
, X_WARNING
,
995 "Probed monitor is %dx%d mm, using Displaysize %dx%d mm\n",
996 ddcWidthmm
, ddcHeightmm
, pScrn
->widthmm
,
1001 else if (ddcWidthmm
&& ddcHeightmm
) {
1003 xf86DrvMsg(pScrn
->scrnIndex
, from
, "Display dimensions: (%d, %d) mm\n",
1004 ddcWidthmm
, ddcHeightmm
);
1005 pScrn
->widthmm
= ddcWidthmm
;
1006 pScrn
->heightmm
= ddcHeightmm
;
1007 if (pScrn
->widthmm
> 0) {
1009 (int) ((double) pScrn
->virtualX
* MMPERINCH
/ pScrn
->widthmm
);
1011 if (pScrn
->heightmm
> 0) {
1013 (int) ((double) pScrn
->virtualY
* MMPERINCH
/ pScrn
->heightmm
);
1015 if (pScrn
->xDpi
> 0 && pScrn
->yDpi
<= 0)
1016 pScrn
->yDpi
= pScrn
->xDpi
;
1017 if (pScrn
->yDpi
> 0 && pScrn
->xDpi
<= 0)
1018 pScrn
->xDpi
= pScrn
->yDpi
;
1024 pScrn
->xDpi
= DEFAULT_DPI
;
1028 pScrn
->yDpi
= DEFAULT_DPI
;
1030 xf86DrvMsg(pScrn
->scrnIndex
, from
, "DPI set to (%d, %d)\n",
1031 pScrn
->xDpi
, pScrn
->yDpi
);
1037 xf86SetBlackWhitePixels(ScreenPtr pScreen
)
1039 if (xf86FlipPixels
) {
1040 pScreen
->whitePixel
= 0;
1041 pScreen
->blackPixel
= 1;
1044 pScreen
->whitePixel
= 1;
1045 pScreen
->blackPixel
= 0;
1050 * Function to enable/disable access to the frame buffer
1052 * This is used when VT switching and when entering/leaving DGA direct mode.
1054 * This has been rewritten again to eliminate the saved pixmap. The
1055 * devPrivate field in the screen pixmap is set to NULL to catch code
1056 * accidentally referencing the frame buffer while the X server is not
1057 * supposed to touch it.
1059 * Here, we exchange the pixmap private data, rather than the pixmaps
1060 * themselves to avoid having to find and change any references to the screen
1061 * pixmap such as GC's, window privates etc. This also means that this code
1062 * does not need to know exactly how the pixmap pixels are accessed. Further,
1063 * this exchange is >not< done through the screen's ModifyPixmapHeader()
1064 * vector. This means the called frame buffer code layers can determine
1065 * whether they are switched in or out by keeping track of the root pixmap's
1066 * private data, and therefore don't need to access pScrnInfo->vtSema.
1069 xf86EnableDisableFBAccess(ScrnInfoPtr pScrnInfo
, Bool enable
)
1071 ScreenPtr pScreen
= pScrnInfo
->pScreen
;
1074 pspix
= (*pScreen
->GetScreenPixmap
) (pScreen
);
1077 * Restore all of the clip lists on the screen
1080 SetRootClip(pScreen
, TRUE
);
1085 * Empty all of the clip lists on the screen
1087 SetRootClip(pScreen
, FALSE
);
1091 /* Print driver messages in the standard format of
1092 (<type>) <screen name>(<screen index>): <message> */
1094 xf86VDrvMsgVerb(int scrnIndex
, MessageType type
, int verb
, const char *format
,
1097 /* Prefix the scrnIndex name to the format string. */
1098 if (scrnIndex
>= 0 && scrnIndex
< xf86NumScreens
&&
1099 xf86Screens
[scrnIndex
]->name
)
1100 LogHdrMessageVerb(type
, verb
, format
, args
, "%s(%d): ",
1101 xf86Screens
[scrnIndex
]->name
, scrnIndex
);
1102 else if (scrnIndex
>= GPU_SCREEN_OFFSET
&&
1103 scrnIndex
< GPU_SCREEN_OFFSET
+ xf86NumGPUScreens
&&
1104 xf86GPUScreens
[scrnIndex
- GPU_SCREEN_OFFSET
]->name
)
1105 LogHdrMessageVerb(type
, verb
, format
, args
, "%s(G%d): ",
1106 xf86GPUScreens
[scrnIndex
- GPU_SCREEN_OFFSET
]->name
, scrnIndex
- GPU_SCREEN_OFFSET
);
1108 LogVMessageVerb(type
, verb
, format
, args
);
1111 /* Print driver messages, with verbose level specified directly */
1113 xf86DrvMsgVerb(int scrnIndex
, MessageType type
, int verb
, const char *format
,
1118 va_start(ap
, format
);
1119 xf86VDrvMsgVerb(scrnIndex
, type
, verb
, format
, ap
);
1123 /* Print driver messages, with verbose level of 1 (default) */
1125 xf86DrvMsg(int scrnIndex
, MessageType type
, const char *format
, ...)
1129 va_start(ap
, format
);
1130 xf86VDrvMsgVerb(scrnIndex
, type
, 1, format
, ap
);
1134 /* Print input driver messages in the standard format of
1135 (<type>) <driver>: <device name>: <message> */
1137 xf86VIDrvMsgVerb(InputInfoPtr dev
, MessageType type
, int verb
,
1138 const char *format
, va_list args
)
1140 const char *driverName
= NULL
;
1141 const char *deviceName
= NULL
;
1143 /* Prefix driver and device names to formatted message. */
1145 deviceName
= dev
->name
;
1147 driverName
= dev
->drv
->driverName
;
1150 LogHdrMessageVerb(type
, verb
, format
, args
, "%s: %s: ", driverName
,
1154 /* Print input driver message, with verbose level specified directly */
1156 xf86IDrvMsgVerb(InputInfoPtr dev
, MessageType type
, int verb
,
1157 const char *format
, ...)
1161 va_start(ap
, format
);
1162 xf86VIDrvMsgVerb(dev
, type
, verb
, format
, ap
);
1166 /* Print input driver messages, with verbose level of 1 (default) */
1168 xf86IDrvMsg(InputInfoPtr dev
, MessageType type
, const char *format
, ...)
1172 va_start(ap
, format
);
1173 xf86VIDrvMsgVerb(dev
, type
, 1, format
, ap
);
1177 /* Print non-driver messages with verbose level specified directly */
1179 xf86MsgVerb(MessageType type
, int verb
, const char *format
, ...)
1183 va_start(ap
, format
);
1184 LogVMessageVerb(type
, verb
, format
, ap
);
1188 /* Print non-driver messages with verbose level of 1 (default) */
1190 xf86Msg(MessageType type
, const char *format
, ...)
1194 va_start(ap
, format
);
1195 LogVMessageVerb(type
, 1, format
, ap
);
1199 /* Just like ErrorF, but with the verbose level checked */
1201 xf86ErrorFVerb(int verb
, const char *format
, ...)
1205 va_start(ap
, format
);
1206 if (xf86Verbose
>= verb
|| xf86LogVerbose
>= verb
)
1207 LogVWrite(verb
, format
, ap
);
1211 /* Like xf86ErrorFVerb, but with an implied verbose level of 1 */
1213 xf86ErrorF(const char *format
, ...)
1217 va_start(ap
, format
);
1218 if (xf86Verbose
>= 1 || xf86LogVerbose
>= 1)
1219 LogVWrite(1, format
, ap
);
1228 #define LOGSUFFIX ".log"
1229 #define LOGOLDSUFFIX ".old"
1231 /* Get the log file name */
1232 if (xf86LogFileFrom
== X_DEFAULT
) {
1233 /* Append the display number and ".log" */
1234 if (asprintf(&lf
, "%s%%s" LOGSUFFIX
, xf86LogFile
) == -1)
1235 FatalError("Cannot allocate space for the log file name\n");
1239 xf86LogFile
= LogInit(xf86LogFile
, LOGOLDSUFFIX
);
1240 xf86LogFileWasOpened
= TRUE
;
1242 xf86SetVerbosity(xf86Verbose
);
1243 xf86SetLogVerbosity(xf86LogVerbose
);
1252 xf86CloseLog(enum ExitCode error
)
1258 * Drivers can use these for using their own SymTabRecs.
1262 xf86TokenToString(SymTabPtr table
, int token
)
1266 for (i
= 0; table
[i
].token
>= 0 && table
[i
].token
!= token
; i
++);
1268 if (table
[i
].token
< 0)
1271 return table
[i
].name
;
1275 xf86StringToToken(SymTabPtr table
, const char *string
)
1282 for (i
= 0; table
[i
].token
>= 0 && xf86NameCmp(string
, table
[i
].name
); i
++);
1284 return table
[i
].token
;
1288 * helper to display the clocks found on a card
1291 xf86ShowClocks(ScrnInfoPtr scrp
, MessageType from
)
1295 xf86DrvMsg(scrp
->scrnIndex
, from
, "Pixel clocks available:");
1296 for (j
= 0; j
< scrp
->numClocks
; j
++) {
1299 xf86DrvMsg(scrp
->scrnIndex
, from
, "pixel clocks:");
1301 xf86ErrorF(" %7.3f", (double) scrp
->clock
[j
] / 1000.0);
1307 * This prints out the driver identify message, including the names of
1308 * the supported chipsets.
1310 * XXX This makes assumptions about the line width, etc. Maybe we could
1311 * use a more general "pretty print" function for messages.
1314 xf86PrintChipsets(const char *drvname
, const char *drvmsg
, SymTabPtr chips
)
1318 len
= 6 + strlen(drvname
) + 2 + strlen(drvmsg
) + 2;
1319 xf86Msg(X_INFO
, "%s: %s:", drvname
, drvmsg
);
1320 for (i
= 0; chips
[i
].name
!= NULL
; i
++) {
1325 if (len
+ 2 + strlen(chips
[i
].name
) < 78) {
1333 xf86ErrorF("%s", chips
[i
].name
);
1334 len
+= strlen(chips
[i
].name
);
1340 xf86MatchDevice(const char *drivername
, GDevPtr
** sectlist
)
1342 GDevPtr gdp
, *pgdp
= NULL
;
1343 confScreenPtr screensecptr
;
1350 * This can happen when running Xorg -showopts and a module like ati
1351 * or vmware tries to load its submodules when xf86ConfigLayout is empty
1353 if (!xf86ConfigLayout
.screens
)
1357 * This is a very important function that matches the device sections
1358 * as they show up in the config file with the drivers that the server
1359 * loads at run time.
1361 * ChipProbe can call
1362 * int xf86MatchDevice(char * drivername, GDevPtr ** sectlist)
1363 * with its driver name. The function allocates an array of GDevPtr and
1364 * returns this via sectlist and returns the number of elements in
1365 * this list as return value. 0 means none found, -1 means fatal error.
1367 * It can figure out which of the Device sections to use for which card
1368 * (using things like the Card statement, etc). For single headed servers
1369 * there will of course be just one such Device section.
1374 * first we need to loop over all the Screens sections to get to all
1375 * 'active' device sections
1377 for (j
= 0; xf86ConfigLayout
.screens
[j
].screen
!= NULL
; j
++) {
1378 screensecptr
= xf86ConfigLayout
.screens
[j
].screen
;
1379 if ((screensecptr
->device
->driver
!= NULL
)
1380 && (xf86NameCmp(screensecptr
->device
->driver
, drivername
) == 0)
1381 && (!screensecptr
->device
->claimed
)) {
1383 * we have a matching driver that wasn't claimed, yet
1385 pgdp
= xnfrealloc(pgdp
, (i
+ 2) * sizeof(GDevPtr
));
1386 pgdp
[i
++] = screensecptr
->device
;
1390 /* Then handle the inactive devices */
1392 while (xf86ConfigLayout
.inactives
[j
].identifier
) {
1393 gdp
= &xf86ConfigLayout
.inactives
[j
];
1394 if (gdp
->driver
&& !gdp
->claimed
&&
1395 !xf86NameCmp(gdp
->driver
, drivername
)) {
1396 /* we have a matching driver that wasn't claimed yet */
1397 pgdp
= xnfrealloc(pgdp
, (i
+ 2) * sizeof(GDevPtr
));
1404 * make the array NULL terminated and return its address
1417 xf86GetVisualName(int visual
)
1419 if (visual
< 0 || visual
> DirectColor
)
1422 return xf86VisualNames
[visual
];
1426 xf86GetVerbosity(void)
1428 return max(xf86Verbose
, xf86LogVerbose
);
1434 return xf86Info
.pixmap24
;
1456 xf86GetFlipPixels(void)
1458 return xf86FlipPixels
;
1462 xf86GetServerName(void)
1464 return xf86ServerName
;
1468 xf86ServerIsExiting(void)
1470 return (dispatchException
& DE_TERMINATE
) == DE_TERMINATE
;
1474 xf86ServerIsResetting(void)
1476 return xf86Resetting
;
1480 xf86ServerIsInitialising(void)
1482 return xf86Initialising
;
1486 xf86ServerIsOnlyDetecting(void)
1488 return xf86DoConfigure
;
1492 xf86CaughtSignal(void)
1494 return xf86Info
.caughtSignal
;
1498 xf86GetVidModeAllowNonLocal(void)
1500 return xf86Info
.vidModeAllowNonLocal
;
1504 xf86GetVidModeEnabled(void)
1506 return xf86Info
.vidModeEnabled
;
1510 xf86GetModInDevAllowNonLocal(void)
1512 return xf86Info
.miscModInDevAllowNonLocal
;
1516 xf86GetModInDevEnabled(void)
1518 return xf86Info
.miscModInDevEnabled
;
1522 xf86GetAllowMouseOpenFail(void)
1524 return xf86Info
.allowMouseOpenFail
;
1528 xf86DisableRandR(void)
1530 xf86Info
.disableRandR
= TRUE
;
1531 xf86Info
.randRFrom
= X_PROBED
;
1535 xf86GetModuleVersion(pointer module
)
1537 return (CARD32
) LoaderGetModuleVersion(module
);
1541 xf86LoadDrvSubModule(DriverPtr drv
, const char *name
)
1544 int errmaj
= 0, errmin
= 0;
1546 ret
= LoadSubModule(drv
->module
, name
, NULL
, NULL
, NULL
, NULL
,
1549 LoaderErrorMsg(NULL
, name
, errmaj
, errmin
);
1554 xf86LoadSubModule(ScrnInfoPtr pScrn
, const char *name
)
1557 int errmaj
= 0, errmin
= 0;
1559 ret
= LoadSubModule(pScrn
->module
, name
, NULL
, NULL
, NULL
, NULL
,
1562 LoaderErrorMsg(pScrn
->name
, name
, errmaj
, errmin
);
1567 * xf86LoadOneModule loads a single module.
1570 xf86LoadOneModule(char *name
, pointer opt
)
1579 /* Normalise the module name */
1580 Name
= xf86NormalizeName(name
);
1582 /* Skip empty names */
1585 if (*Name
== '\0') {
1590 mod
= LoadModule(Name
, NULL
, NULL
, NULL
, opt
, NULL
, &errmaj
, &errmin
);
1592 LoaderErrorMsg(NULL
, Name
, errmaj
, errmin
);
1598 xf86UnloadSubModule(pointer mod
)
1600 UnloadSubModule(mod
);
1604 xf86LoaderCheckSymbol(const char *name
)
1606 return LoaderSymbol(name
) != NULL
;
1610 OPTION_BACKING_STORE
1613 static const OptionInfoRec BSOptions
[] = {
1614 {OPTION_BACKING_STORE
, "BackingStore", OPTV_BOOLEAN
, {0}, FALSE
},
1615 {-1, NULL
, OPTV_NONE
, {0}, FALSE
}
1619 xf86SetBackingStore(ScreenPtr pScreen
)
1622 MessageType from
= X_DEFAULT
;
1623 ScrnInfoPtr pScrn
= xf86ScreenToScrn(pScreen
);
1624 OptionInfoPtr options
;
1626 options
= xnfalloc(sizeof(BSOptions
));
1627 (void) memcpy(options
, BSOptions
, sizeof(BSOptions
));
1628 xf86ProcessOptions(pScrn
->scrnIndex
, pScrn
->options
, options
);
1630 /* check for commandline option here */
1631 if (xf86bsEnableFlag
) {
1635 else if (xf86bsDisableFlag
) {
1640 if (xf86GetOptValBool(options
, OPTION_BACKING_STORE
, &useBS
))
1643 if (from
!= X_CONFIG
)
1644 useBS
= xf86ReturnOptValBool(options
, OPTION_BACKING_STORE
,
1645 !noCompositeExtension
);
1649 pScreen
->backingStoreSupport
= useBS
? WhenMapped
: NotUseful
;
1650 if (serverGeneration
== 1)
1651 xf86DrvMsg(pScreen
->myNum
, from
, "Backing store %s\n",
1652 useBS
? "enabled" : "disabled");
1659 static const OptionInfoRec SMOptions
[] = {
1660 {OPTION_SILKEN_MOUSE
, "SilkenMouse", OPTV_BOOLEAN
, {0}, FALSE
},
1661 {-1, NULL
, OPTV_NONE
, {0}, FALSE
}
1665 xf86SetSilkenMouse(ScreenPtr pScreen
)
1668 MessageType from
= X_DEFAULT
;
1669 ScrnInfoPtr pScrn
= xf86ScreenToScrn(pScreen
);
1670 OptionInfoPtr options
;
1672 options
= xnfalloc(sizeof(SMOptions
));
1673 (void) memcpy(options
, SMOptions
, sizeof(SMOptions
));
1674 xf86ProcessOptions(pScrn
->scrnIndex
, pScrn
->options
, options
);
1676 /* check for commandline option here */
1677 /* disable if screen shares resources */
1678 /* TODO VGA arb disable silken mouse */
1679 if (xf86silkenMouseDisableFlag
) {
1684 if (xf86GetOptValBool(options
, OPTION_SILKEN_MOUSE
, &useSM
))
1689 * XXX quick hack to report correctly for OSs that can't do SilkenMouse
1690 * yet. Should handle this differently so that alternate async methods
1691 * work correctly with this too.
1693 pScrn
->silkenMouse
= useSM
&& xf86Info
.useSIGIO
&& xf86SIGIOSupported();
1694 if (serverGeneration
== 1)
1695 xf86DrvMsg(pScreen
->myNum
, from
, "Silken mouse %s\n",
1696 pScrn
->silkenMouse
? "enabled" : "disabled");
1699 /* Wrote this function for the PM2 Xv driver, preliminary. */
1702 xf86FindXvOptions(ScrnInfoPtr pScrn
, int adaptor_index
, char *port_name
,
1703 char **adaptor_name
, pointer
*adaptor_options
)
1705 confXvAdaptorPtr adaptor
;
1708 if (adaptor_index
>= pScrn
->confScreen
->numxvadaptors
) {
1710 *adaptor_name
= NULL
;
1711 if (adaptor_options
)
1712 *adaptor_options
= NULL
;
1716 adaptor
= &pScrn
->confScreen
->xvadaptors
[adaptor_index
];
1718 *adaptor_name
= adaptor
->identifier
;
1719 if (adaptor_options
)
1720 *adaptor_options
= adaptor
->options
;
1722 for (i
= 0; i
< adaptor
->numports
; i
++)
1723 if (!xf86NameCmp(adaptor
->ports
[i
].identifier
, port_name
))
1724 return adaptor
->ports
[i
].options
;
1729 /* Rather than duplicate loader's get OS function, just include it directly */
1730 #define LoaderGetOS xf86GetOS
1731 #include "loader/os.c"
1734 xf86ConfigFbEntityInactive(EntityInfoPtr pEnt
, EntityProc init
,
1735 EntityProc enter
, EntityProc leave
, pointer
private)
1739 if ((pScrn
= xf86FindScreenForEntity(pEnt
->index
)))
1740 xf86RemoveEntityFromScreen(pScrn
, pEnt
->index
);
1741 xf86SetEntityFuncs(pEnt
->index
, init
, enter
, leave
, private);
1745 xf86ConfigFbEntity(ScrnInfoPtr pScrn
, int scrnFlag
, int entityIndex
,
1746 EntityProc init
, EntityProc enter
, EntityProc leave
,
1749 EntityInfoPtr pEnt
= xf86GetEntityInfo(entityIndex
);
1754 if (!(pEnt
->location
.type
== BUS_NONE
)) {
1759 if (!pEnt
->active
) {
1760 xf86ConfigFbEntityInactive(pEnt
, init
, enter
, leave
, private);
1766 pScrn
= xf86AllocateScreen(pEnt
->driver
, scrnFlag
);
1767 xf86AddEntityToScreen(pScrn
, entityIndex
);
1769 xf86SetEntityFuncs(entityIndex
, init
, enter
, leave
, private);
1776 xf86IsScreenPrimary(ScrnInfoPtr pScrn
)
1780 for (i
= 0; i
< pScrn
->numEntities
; i
++) {
1781 if (xf86IsEntityPrimary(i
))
1788 xf86RegisterRootWindowProperty(int ScrnIndex
, Atom property
, Atom type
,
1789 int format
, unsigned long len
, pointer value
)
1791 RootWinPropPtr pNewProp
= NULL
, pRegProp
;
1792 Bool existing
= FALSE
;
1794 DebugF("xf86RegisterRootWindowProperty(%d, %ld, %ld, %d, %ld, %p)\n",
1795 ScrnIndex
, property
, type
, format
, len
, value
);
1797 if (ScrnIndex
< 0 || ScrnIndex
>= xf86NumScreens
) {
1801 if (xf86RegisteredPropertiesTable
&&
1802 xf86RegisteredPropertiesTable
[ScrnIndex
]) {
1803 for (pNewProp
= xf86RegisteredPropertiesTable
[ScrnIndex
];
1804 pNewProp
; pNewProp
= pNewProp
->next
) {
1805 if (strcmp(pNewProp
->name
, NameForAtom(property
)) == 0)
1811 if ((pNewProp
= (RootWinPropPtr
) malloc(sizeof(RootWinProp
))) == NULL
) {
1815 * We will put this property at the end of the list so that
1816 * the changes are made in the order they were requested.
1818 pNewProp
->next
= NULL
;
1821 free(pNewProp
->name
);
1825 pNewProp
->name
= xnfstrdup(NameForAtom(property
));
1826 pNewProp
->type
= type
;
1827 pNewProp
->format
= format
;
1828 pNewProp
->size
= len
;
1829 pNewProp
->data
= value
;
1831 DebugF("new property filled\n");
1833 if (xf86RegisteredPropertiesTable
== NULL
) {
1834 DebugF("creating xf86RegisteredPropertiesTable[] size %d\n",
1836 xf86RegisteredPropertiesTable
=
1837 xnfcalloc(sizeof(RootWinProp
), xf86NumScreens
);
1840 DebugF("xf86RegisteredPropertiesTable %p\n",
1841 (void *) xf86RegisteredPropertiesTable
);
1842 DebugF("xf86RegisteredPropertiesTable[%d] %p\n",
1843 ScrnIndex
, (void *) xf86RegisteredPropertiesTable
[ScrnIndex
]);
1846 if (xf86RegisteredPropertiesTable
[ScrnIndex
] == NULL
) {
1847 xf86RegisteredPropertiesTable
[ScrnIndex
] = pNewProp
;
1850 pRegProp
= xf86RegisteredPropertiesTable
[ScrnIndex
];
1851 while (pRegProp
->next
!= NULL
) {
1852 DebugF("- next %p\n", (void *) pRegProp
);
1853 pRegProp
= pRegProp
->next
;
1855 pRegProp
->next
= pNewProp
;
1858 DebugF("xf86RegisterRootWindowProperty succeeded\n");
1863 xf86IsUnblank(int mode
)
1866 case SCREEN_SAVER_OFF
:
1867 case SCREEN_SAVER_FORCER
:
1869 case SCREEN_SAVER_ON
:
1870 case SCREEN_SAVER_CYCLE
:
1873 xf86MsgVerb(X_WARNING
, 0, "Unexpected save screen mode: %d\n", mode
);
1879 xf86MotionHistoryAllocate(InputInfoPtr pInfo
)
1881 AllocateMotionHistory(pInfo
->dev
);
1885 xf86ScreenToScrn(ScreenPtr pScreen
)
1887 if (pScreen
->isGPU
) {
1888 assert(pScreen
->myNum
- GPU_SCREEN_OFFSET
< xf86NumGPUScreens
);
1889 return xf86GPUScreens
[pScreen
->myNum
- GPU_SCREEN_OFFSET
];
1891 assert(pScreen
->myNum
< xf86NumScreens
);
1892 return xf86Screens
[pScreen
->myNum
];
1897 xf86ScrnToScreen(ScrnInfoPtr pScrn
)
1899 if (pScrn
->is_gpu
) {
1900 assert(pScrn
->scrnIndex
- GPU_SCREEN_OFFSET
< screenInfo
.numGPUScreens
);
1901 return screenInfo
.gpuscreens
[pScrn
->scrnIndex
- GPU_SCREEN_OFFSET
];
1903 assert(pScrn
->scrnIndex
< screenInfo
.numScreens
);
1904 return screenInfo
.screens
[pScrn
->scrnIndex
];
1909 xf86UpdateDesktopDimensions(void)
1911 update_desktop_dimensions();