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)
221 /* First check if the screen is valid */
222 if (xf86NumGPUScreens == 0 || xf86GPUScreens == NULL)
226 /* First check if the screen is valid */
227 if (xf86NumScreens == 0 || xf86Screens == NULL)
234 scrnIndex = pScrn->scrnIndex;
235 /* If a FreeScreen function is defined, call it here */
236 if (pScrn->FreeScreen != NULL)
237 pScrn->FreeScreen(pScrn);
240 xf86DeleteMode(&pScrn->modes, pScrn->modes);
242 while (pScrn->modePool)
243 xf86DeleteMode(&pScrn->modePool, pScrn->modePool);
245 xf86OptionListFree(pScrn->options);
248 UnloadModule(pScrn->module);
251 pScrn->drv->refCount--;
253 free(pScrn->privates);
255 xf86ClearEntityListForScreen(pScrn);
259 /* Move the other entries down, updating their scrnIndex fields */
263 scrnIndex -= GPU_SCREEN_OFFSET;
264 for (i = scrnIndex; i < xf86NumGPUScreens; i++) {
265 xf86GPUScreens[i] = xf86GPUScreens[i + 1];
266 xf86GPUScreens[i]->scrnIndex = i + GPU_SCREEN_OFFSET;
267 /* Also need to take care of the screen layout settings */
273 for (i = scrnIndex; i < xf86NumScreens; i++) {
274 xf86Screens[i] = xf86Screens[i + 1];
275 xf86Screens[i]->scrnIndex = i;
276 /* Also need to take care of the screen layout settings */
282 * Allocate a private in ScrnInfoRec.
286 xf86AllocateScrnInfoPrivateIndex(void)
292 idx = xf86ScrnInfoPrivateCount++;
293 for (i = 0; i < xf86NumScreens; i++) {
294 pScr = xf86Screens[i];
295 nprivs = xnfrealloc(pScr->privates,
296 xf86ScrnInfoPrivateCount * sizeof(DevUnion));
297 /* Zero the new private */
298 memset(&nprivs[idx], 0, sizeof(DevUnion));
299 pScr->privates = nprivs;
301 for (i = 0; i < xf86NumGPUScreens; i++) {
302 pScr = xf86GPUScreens[i];
303 nprivs = xnfrealloc(pScr->privates,
304 xf86ScrnInfoPrivateCount * sizeof(DevUnion));
305 /* Zero the new private */
306 memset(&nprivs[idx], 0, sizeof(DevUnion));
307 pScr->privates = nprivs;
313 xf86AddPixFormat(ScrnInfoPtr pScrn, int depth, int bpp, int pad)
317 if (pScrn->numFormats >= MAXFORMATS)
325 else if (depth <= 16)
327 else if (depth <= 32)
333 pad = BITMAP_SCANLINE_PAD;
335 i = pScrn->numFormats++;
336 pScrn->formats[i].depth = depth;
337 pScrn->formats[i].bitsPerPixel = bpp;
338 pScrn->formats[i].scanlinePad = pad;
343 * Set the depth we are using based on (in the following order of preference):
344 * - values given on the command line
345 * - values given in the config file
346 * - values provided by the driver
347 * - an overall default when nothing else is given
349 * Also find a Display subsection matching the depth/bpp found.
351 * Sets the following ScrnInfoRec fields:
352 * bitsPerPixel, pixmap24, depth, display, imageByteOrder,
353 * bitmapScanlinePad, bitmapScanlineUnit, bitmapBitOrder, numFormats,
357 /* Can the screen handle 24 bpp pixmaps */
358 #define DO_PIX24(f) ((f & Support24bppFb) || \
359 ((f & Support32bppFb) && (f & SupportConvert24to32)))
361 /* Can the screen handle 32 bpp pixmaps */
362 #define DO_PIX32(f) ((f & Support32bppFb) || \
363 ((f & Support24bppFb) && (f & SupportConvert32to24)))
365 /* Does the screen prefer 32bpp fb for 24bpp pixmaps */
366 #define CHOOSE32FOR24(f) ((f & Support32bppFb) && (f & SupportConvert24to32) \
367 && (f & PreferConvert24to32))
369 /* Does the screen prefer 24bpp fb for 32bpp pixmaps */
370 #define CHOOSE24FOR32(f) ((f & Support24bppFb) && (f & SupportConvert32to24) \
371 && (f & PreferConvert32to24))
373 /* Can the screen handle 32bpp pixmaps for 24bpp fb */
374 #define DO_PIX32FOR24(f) ((f & Support24bppFb) && (f & SupportConvert32to24))
376 /* Can the screen handle 24bpp pixmaps for 32bpp fb */
377 #define DO_PIX24FOR32(f) ((f & Support32bppFb) && (f & SupportConvert24to32))
379 #ifndef GLOBAL_DEFAULT_DEPTH
380 #define GLOBAL_DEFAULT_DEPTH 24
384 xf86SetDepthBpp(ScrnInfoPtr scrp, int depth, int dummy, int fbbpp,
389 Pix24Flags pix24 = xf86Info.pixmap24;
390 Bool nomatch = FALSE;
392 scrp->bitsPerPixel = -1;
394 scrp->pixmap24 = Pix24DontCare;
395 scrp->bitsPerPixelFrom = X_DEFAULT;
396 scrp->depthFrom = X_DEFAULT;
399 scrp->bitsPerPixel = xf86FbBpp;
400 scrp->bitsPerPixelFrom = X_CMDLINE;
404 scrp->depth = xf86Depth;
405 scrp->depthFrom = X_CMDLINE;
408 if (xf86FbBpp < 0 && xf86Depth < 0) {
409 if (scrp->confScreen->defaultfbbpp > 0) {
410 scrp->bitsPerPixel = scrp->confScreen->defaultfbbpp;
411 scrp->bitsPerPixelFrom = X_CONFIG;
413 if (scrp->confScreen->defaultdepth > 0) {
414 scrp->depth = scrp->confScreen->defaultdepth;
415 scrp->depthFrom = X_CONFIG;
418 if (scrp->confScreen->defaultfbbpp <= 0 &&
419 scrp->confScreen->defaultdepth <= 0) {
421 * Check for DefaultDepth and DefaultFbBpp options in the
428 for (i = 0; i < scrp->numEntities; i++) {
429 device = xf86GetDevFromEntity(scrp->entityList[i],
430 scrp->entityInstanceList[i]);
431 if (device && device->options) {
432 if (xf86FindOption(device->options, "DefaultDepth")) {
433 scrp->depth = xf86SetIntOption(device->options,
435 scrp->depthFrom = X_CONFIG;
438 if (xf86FindOption(device->options, "DefaultFbBpp")) {
439 scrp->bitsPerPixel = xf86SetIntOption(device->options,
442 scrp->bitsPerPixelFrom = X_CONFIG;
452 /* If none of these is set, pick a default */
453 if (scrp->bitsPerPixel < 0 && scrp->depth < 0) {
454 if (fbbpp > 0 || depth > 0) {
456 scrp->bitsPerPixel = fbbpp;
461 scrp->depth = GLOBAL_DEFAULT_DEPTH;
465 /* If any are not given, determine a default for the others */
467 if (scrp->bitsPerPixel < 0) {
468 /* The depth must be set */
469 if (scrp->depth > -1) {
470 if (scrp->depth == 1)
471 scrp->bitsPerPixel = 1;
472 else if (scrp->depth <= 4)
473 scrp->bitsPerPixel = 4;
474 else if (scrp->depth <= 8)
475 scrp->bitsPerPixel = 8;
476 else if (scrp->depth <= 16)
477 scrp->bitsPerPixel = 16;
478 else if (scrp->depth <= 24) {
480 * Figure out if a choice is possible based on the depth24
483 /* Check pix24 first */
484 if (pix24 != Pix24DontCare) {
485 if (pix24 == Pix24Use32) {
486 if (DO_PIX32(depth24flags)) {
487 if (CHOOSE24FOR32(depth24flags))
488 scrp->bitsPerPixel = 24;
490 scrp->bitsPerPixel = 32;
496 else if (pix24 == Pix24Use24) {
497 if (DO_PIX24(depth24flags)) {
498 if (CHOOSE32FOR24(depth24flags))
499 scrp->bitsPerPixel = 32;
501 scrp->bitsPerPixel = 24;
509 if (DO_PIX32(depth24flags)) {
510 if (CHOOSE24FOR32(depth24flags))
511 scrp->bitsPerPixel = 24;
513 scrp->bitsPerPixel = 32;
515 else if (DO_PIX24(depth24flags)) {
516 if (CHOOSE32FOR24(depth24flags))
517 scrp->bitsPerPixel = 32;
519 scrp->bitsPerPixel = 24;
523 else if (scrp->depth <= 32)
524 scrp->bitsPerPixel = 32;
526 xf86DrvMsg(scrp->scrnIndex, X_ERROR,
527 "Specified depth (%d) is greater than 32\n",
533 xf86DrvMsg(scrp->scrnIndex, X_ERROR,
534 "xf86SetDepthBpp: internal error: depth and fbbpp"
535 " are both not set\n");
538 if (scrp->bitsPerPixel < 0) {
540 xf86DrvMsg(scrp->scrnIndex, X_ERROR,
541 "Driver can't support depth 24 pixmap format (%d)\n",
543 else if ((depth24flags & (Support24bppFb | Support32bppFb)) ==
545 xf86DrvMsg(scrp->scrnIndex, X_ERROR,
546 "Driver can't support depth 24\n");
548 xf86DrvMsg(scrp->scrnIndex, X_ERROR,
549 "Can't find fbbpp for depth 24\n");
552 scrp->bitsPerPixelFrom = X_PROBED;
555 if (scrp->depth <= 0) {
556 /* bitsPerPixel is already set */
557 switch (scrp->bitsPerPixel) {
562 /* 1, 4, 8, 16 and 24 */
563 scrp->depth = scrp->bitsPerPixel;
566 scrp->depthFrom = X_PROBED;
570 if (scrp->depth < 1 || scrp->depth > 32) {
571 xf86DrvMsg(scrp->scrnIndex, X_ERROR,
572 "Specified depth (%d) is not in the range 1-32\n",
576 switch (scrp->bitsPerPixel) {
585 xf86DrvMsg(scrp->scrnIndex, X_ERROR,
586 "Specified fbbpp (%d) is not a permitted value\n",
590 if (scrp->depth > scrp->bitsPerPixel) {
591 xf86DrvMsg(scrp->scrnIndex, X_ERROR,
592 "Specified depth (%d) is greater than the fbbpp (%d)\n",
593 scrp->depth, scrp->bitsPerPixel);
597 /* set scrp->pixmap24 if the driver isn't flexible */
598 if (scrp->bitsPerPixel == 24 && !DO_PIX32FOR24(depth24flags)) {
599 scrp->pixmap24 = Pix24Use24;
601 if (scrp->bitsPerPixel == 32 && !DO_PIX24FOR32(depth24flags)) {
602 scrp->pixmap24 = Pix24Use32;
606 * Find the Display subsection matching the depth/fbbpp and initialise
607 * scrp->display with it.
609 for (i = 0, disp = scrp->confScreen->displays;
610 i < scrp->confScreen->numdisplays; i++, disp++) {
611 if ((disp->depth == scrp->depth && disp->fbbpp == scrp->bitsPerPixel)
612 || (disp->depth == scrp->depth && disp->fbbpp <= 0)
613 || (disp->fbbpp == scrp->bitsPerPixel && disp->depth <= 0)) {
614 scrp->display = disp;
620 * If an exact match can't be found, see if there is one with no
621 * depth or fbbpp specified.
623 if (i == scrp->confScreen->numdisplays) {
624 for (i = 0, disp = scrp->confScreen->displays;
625 i < scrp->confScreen->numdisplays; i++, disp++) {
626 if (disp->depth <= 0 && disp->fbbpp <= 0) {
627 scrp->display = disp;
634 * If all else fails, create a default one.
636 if (i == scrp->confScreen->numdisplays) {
637 scrp->confScreen->numdisplays++;
638 scrp->confScreen->displays =
639 xnfrealloc(scrp->confScreen->displays,
640 scrp->confScreen->numdisplays * sizeof(DispRec));
641 xf86DrvMsg(scrp->scrnIndex, X_INFO,
642 "Creating default Display subsection in Screen section\n"
643 "\t\"%s\" for depth/fbbpp %d/%d\n",
644 scrp->confScreen->id, scrp->depth, scrp->bitsPerPixel);
645 memset(&scrp->confScreen->displays[i], 0, sizeof(DispRec));
646 scrp->confScreen->displays[i].blackColour.red = -1;
647 scrp->confScreen->displays[i].blackColour.green = -1;
648 scrp->confScreen->displays[i].blackColour.blue = -1;
649 scrp->confScreen->displays[i].whiteColour.red = -1;
650 scrp->confScreen->displays[i].whiteColour.green = -1;
651 scrp->confScreen->displays[i].whiteColour.blue = -1;
652 scrp->confScreen->displays[i].defaultVisual = -1;
653 scrp->confScreen->displays[i].modes = xnfalloc(sizeof(char *));
654 scrp->confScreen->displays[i].modes[0] = NULL;
655 scrp->confScreen->displays[i].depth = depth;
656 scrp->confScreen->displays[i].fbbpp = fbbpp;
657 scrp->display = &scrp->confScreen->displays[i];
661 * Setup defaults for the display-wide attributes the framebuffer will
662 * need. These defaults should eventually be set globally, and not
663 * dependent on the screens.
665 scrp->imageByteOrder = IMAGE_BYTE_ORDER;
666 scrp->bitmapScanlinePad = BITMAP_SCANLINE_PAD;
667 if (scrp->depth < 8) {
668 /* Planar modes need these settings */
669 scrp->bitmapScanlineUnit = 8;
670 scrp->bitmapBitOrder = MSBFirst;
673 scrp->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT;
674 scrp->bitmapBitOrder = BITMAP_BIT_ORDER;
678 * If an unusual depth is required, add it to scrp->formats. The formats
679 * for the common depths are handled globally in InitOutput
681 switch (scrp->depth) {
688 /* Common depths. Nothing to do for them */
691 if (!xf86AddPixFormat(scrp, scrp->depth, 0, 0)) {
692 xf86DrvMsg(scrp->scrnIndex, X_ERROR,
693 "Can't add pixmap format for depth %d\n", scrp->depth);
698 /* Initialise the framebuffer format for this screen */
699 scrp->fbFormat.depth = scrp->depth;
700 scrp->fbFormat.bitsPerPixel = scrp->bitsPerPixel;
701 scrp->fbFormat.scanlinePad = BITMAP_SCANLINE_PAD;
707 * Print out the selected depth and bpp.
710 xf86PrintDepthBpp(ScrnInfoPtr scrp)
712 xf86DrvMsg(scrp->scrnIndex, scrp->depthFrom, "Depth %d, ", scrp->depth);
713 xf86Msg(scrp->bitsPerPixelFrom, "framebuffer bpp %d\n", scrp->bitsPerPixel);
717 * xf86SetWeight sets scrp->weight, scrp->mask, scrp->offset, and for depths
718 * greater than MAX_PSEUDO_DEPTH also scrp->rgbBits.
721 xf86SetWeight(ScrnInfoPtr scrp, rgb weight, rgb mask)
723 MessageType weightFrom = X_DEFAULT;
725 scrp->weight.red = 0;
726 scrp->weight.green = 0;
727 scrp->weight.blue = 0;
729 if (xf86Weight.red > 0 && xf86Weight.green > 0 && xf86Weight.blue > 0) {
730 scrp->weight = xf86Weight;
731 weightFrom = X_CMDLINE;
733 else if (scrp->display->weight.red > 0 && scrp->display->weight.green > 0
734 && scrp->display->weight.blue > 0) {
735 scrp->weight = scrp->display->weight;
736 weightFrom = X_CONFIG;
738 else if (weight.red > 0 && weight.green > 0 && weight.blue > 0) {
739 scrp->weight = weight;
742 switch (scrp->depth) {
746 scrp->weight.red = scrp->weight.green =
747 scrp->weight.blue = scrp->rgbBits;
750 scrp->weight.red = scrp->weight.green = scrp->weight.blue = 5;
753 scrp->weight.red = scrp->weight.blue = 5;
754 scrp->weight.green = 6;
757 scrp->weight.red = scrp->weight.green = scrp->weight.blue = 6;
760 scrp->weight.red = scrp->weight.green = scrp->weight.blue = 8;
763 scrp->weight.red = scrp->weight.green = scrp->weight.blue = 10;
768 if (scrp->weight.red)
769 xf86DrvMsg(scrp->scrnIndex, weightFrom, "RGB weight %d%d%d\n",
770 (int) scrp->weight.red, (int) scrp->weight.green,
771 (int) scrp->weight.blue);
773 if (scrp->depth > MAX_PSEUDO_DEPTH &&
774 (scrp->depth != scrp->weight.red + scrp->weight.green +
775 scrp->weight.blue)) {
776 xf86DrvMsg(scrp->scrnIndex, X_ERROR,
777 "Weight given (%d%d%d) is inconsistent with the "
779 (int) scrp->weight.red, (int) scrp->weight.green,
780 (int) scrp->weight.blue, scrp->depth);
783 if (scrp->depth > MAX_PSEUDO_DEPTH && scrp->weight.red) {
785 * XXX Does this even mean anything for TrueColor visuals?
786 * If not, we shouldn't even be setting it here. However, this
787 * matches the behaviour of 3.x versions of XFree86.
789 scrp->rgbBits = scrp->weight.red;
790 if (scrp->weight.green > scrp->rgbBits)
791 scrp->rgbBits = scrp->weight.green;
792 if (scrp->weight.blue > scrp->rgbBits)
793 scrp->rgbBits = scrp->weight.blue;
796 /* Set the mask and offsets */
797 if (mask.red == 0 || mask.green == 0 || mask.blue == 0) {
798 /* Default to a setting common to PC hardware */
799 scrp->offset.red = scrp->weight.green + scrp->weight.blue;
800 scrp->offset.green = scrp->weight.blue;
801 scrp->offset.blue = 0;
802 scrp->mask.red = ((1 << scrp->weight.red) - 1) << scrp->offset.red;
803 scrp->mask.green = ((1 << scrp->weight.green) - 1)
804 << scrp->offset.green;
805 scrp->mask.blue = (1 << scrp->weight.blue) - 1;
808 /* Initialise to the values passed */
809 scrp->mask.red = mask.red;
810 scrp->mask.green = mask.green;
811 scrp->mask.blue = mask.blue;
812 scrp->offset.red = ffs(mask.red);
813 scrp->offset.green = ffs(mask.green);
814 scrp->offset.blue = ffs(mask.blue);
820 xf86SetDefaultVisual(ScrnInfoPtr scrp, int visual)
822 MessageType visualFrom = X_DEFAULT;
824 if (defaultColorVisualClass >= 0) {
825 scrp->defaultVisual = defaultColorVisualClass;
826 visualFrom = X_CMDLINE;
828 else if (scrp->display->defaultVisual >= 0) {
829 scrp->defaultVisual = scrp->display->defaultVisual;
830 visualFrom = X_CONFIG;
832 else if (visual >= 0) {
833 scrp->defaultVisual = visual;
836 if (scrp->depth == 1)
837 scrp->defaultVisual = StaticGray;
838 else if (scrp->depth == 4)
839 scrp->defaultVisual = StaticColor;
840 else if (scrp->depth <= MAX_PSEUDO_DEPTH)
841 scrp->defaultVisual = PseudoColor;
843 scrp->defaultVisual = TrueColor;
845 switch (scrp->defaultVisual) {
852 xf86DrvMsg(scrp->scrnIndex, visualFrom, "Default visual is %s\n",
853 xf86VisualNames[scrp->defaultVisual]);
857 xf86DrvMsg(scrp->scrnIndex, X_ERROR,
858 "Invalid default visual class (%d)\n", scrp->defaultVisual);
863 #define TEST_GAMMA(g) \
864 (g).red > GAMMA_ZERO || (g).green > GAMMA_ZERO || (g).blue > GAMMA_ZERO
866 #define SET_GAMMA(g) \
867 (g) > GAMMA_ZERO ? (g) : 1.0
870 xf86SetGamma(ScrnInfoPtr scrp, Gamma gamma)
872 MessageType from = X_DEFAULT;
875 xf86MonPtr DDC = (xf86MonPtr) (scrp->monitor->DDC);
877 if (TEST_GAMMA(xf86Gamma)) {
879 scrp->gamma.red = SET_GAMMA(xf86Gamma.red);
880 scrp->gamma.green = SET_GAMMA(xf86Gamma.green);
881 scrp->gamma.blue = SET_GAMMA(xf86Gamma.blue);
883 else if (TEST_GAMMA(scrp->monitor->gamma)) {
885 scrp->gamma.red = SET_GAMMA(scrp->monitor->gamma.red);
886 scrp->gamma.green = SET_GAMMA(scrp->monitor->gamma.green);
887 scrp->gamma.blue = SET_GAMMA(scrp->monitor->gamma.blue);
890 else if (DDC && DDC->features.gamma > GAMMA_ZERO) {
892 scrp->gamma.red = SET_GAMMA(DDC->features.gamma);
893 scrp->gamma.green = SET_GAMMA(DDC->features.gamma);
894 scrp->gamma.blue = SET_GAMMA(DDC->features.gamma);
895 /* EDID structure version 2 gives optional seperate red, green & blue gamma values
896 * in bytes 0x57-0x59 */
899 else if (TEST_GAMMA(gamma)) {
900 scrp->gamma.red = SET_GAMMA(gamma.red);
901 scrp->gamma.green = SET_GAMMA(gamma.green);
902 scrp->gamma.blue = SET_GAMMA(gamma.blue);
905 scrp->gamma.red = 1.0;
906 scrp->gamma.green = 1.0;
907 scrp->gamma.blue = 1.0;
909 /* Pretend we succeeded if we support better a gamma system.
910 * This avoids a confusing message.
912 if (xf86_crtc_supports_gamma(scrp))
914 xf86DrvMsg(scrp->scrnIndex, from,
915 "Using gamma correction (%.1f, %.1f, %.1f)\n",
916 scrp->gamma.red, scrp->gamma.green, scrp->gamma.blue);
925 * Set the DPI from the command line option. XXX should allow it to be
926 * calculated from the widthmm/heightmm values.
930 #define MMPERINCH 25.4
933 xf86SetDpi(ScrnInfoPtr pScrn, int x, int y)
935 MessageType from = X_DEFAULT;
936 xf86MonPtr DDC = (xf86MonPtr) (pScrn->monitor->DDC);
937 int ddcWidthmm, ddcHeightmm;
938 int widthErr, heightErr;
940 /* XXX Maybe there is no need for widthmm/heightmm in ScrnInfoRec */
941 pScrn->widthmm = pScrn->monitor->widthmm;
942 pScrn->heightmm = pScrn->monitor->heightmm;
944 if (DDC && (DDC->features.hsize > 0 && DDC->features.vsize > 0)) {
945 /* DDC gives display size in mm for individual modes,
948 ddcWidthmm = DDC->features.hsize * 10; /* 10mm in 1cm */
949 ddcHeightmm = DDC->features.vsize * 10; /* 10mm in 1cm */
952 ddcWidthmm = ddcHeightmm = 0;
955 if (monitorResolution > 0) {
956 pScrn->xDpi = monitorResolution;
957 pScrn->yDpi = monitorResolution;
960 else if (pScrn->widthmm > 0 || pScrn->heightmm > 0) {
962 if (pScrn->widthmm > 0) {
964 (int) ((double) pScrn->virtualX * MMPERINCH / pScrn->widthmm);
966 if (pScrn->heightmm > 0) {
968 (int) ((double) pScrn->virtualY * MMPERINCH / pScrn->heightmm);
970 if (pScrn->xDpi > 0 && pScrn->yDpi <= 0)
971 pScrn->yDpi = pScrn->xDpi;
972 if (pScrn->yDpi > 0 && pScrn->xDpi <= 0)
973 pScrn->xDpi = pScrn->yDpi;
974 xf86DrvMsg(pScrn->scrnIndex, from, "Display dimensions: (%d, %d) mm\n",
975 pScrn->widthmm, pScrn->heightmm);
977 /* Warn if config and probe disagree about display size */
978 if (ddcWidthmm && ddcHeightmm) {
979 if (pScrn->widthmm > 0) {
980 widthErr = abs(ddcWidthmm - pScrn->widthmm);
985 if (pScrn->heightmm > 0) {
986 heightErr = abs(ddcHeightmm - pScrn->heightmm);
991 if (widthErr > 10 || heightErr > 10) {
992 /* Should include config file name for monitor here */
993 xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
994 "Probed monitor is %dx%d mm, using Displaysize %dx%d mm\n",
995 ddcWidthmm, ddcHeightmm, pScrn->widthmm,
1000 else if (ddcWidthmm && ddcHeightmm) {
1002 xf86DrvMsg(pScrn->scrnIndex, from, "Display dimensions: (%d, %d) mm\n",
1003 ddcWidthmm, ddcHeightmm);
1004 pScrn->widthmm = ddcWidthmm;
1005 pScrn->heightmm = ddcHeightmm;
1006 if (pScrn->widthmm > 0) {
1008 (int) ((double) pScrn->virtualX * MMPERINCH / pScrn->widthmm);
1010 if (pScrn->heightmm > 0) {
1012 (int) ((double) pScrn->virtualY * MMPERINCH / pScrn->heightmm);
1014 if (pScrn->xDpi > 0 && pScrn->yDpi <= 0)
1015 pScrn->yDpi = pScrn->xDpi;
1016 if (pScrn->yDpi > 0 && pScrn->xDpi <= 0)
1017 pScrn->xDpi = pScrn->yDpi;
1023 pScrn->xDpi = DEFAULT_DPI;
1027 pScrn->yDpi = DEFAULT_DPI;
1029 xf86DrvMsg(pScrn->scrnIndex, from, "DPI set to (%d, %d)\n",
1030 pScrn->xDpi, pScrn->yDpi);
1036 xf86SetBlackWhitePixels(ScreenPtr pScreen)
1038 if (xf86FlipPixels) {
1039 pScreen->whitePixel = 0;
1040 pScreen->blackPixel = 1;
1043 pScreen->whitePixel = 1;
1044 pScreen->blackPixel = 0;
1049 * Function to enable/disable access to the frame buffer
1051 * This is used when VT switching and when entering/leaving DGA direct mode.
1053 * This has been rewritten again to eliminate the saved pixmap. The
1054 * devPrivate field in the screen pixmap is set to NULL to catch code
1055 * accidentally referencing the frame buffer while the X server is not
1056 * supposed to touch it.
1058 * Here, we exchange the pixmap private data, rather than the pixmaps
1059 * themselves to avoid having to find and change any references to the screen
1060 * pixmap such as GC's, window privates etc. This also means that this code
1061 * does not need to know exactly how the pixmap pixels are accessed. Further,
1062 * this exchange is >not< done through the screen's ModifyPixmapHeader()
1063 * vector. This means the called frame buffer code layers can determine
1064 * whether they are switched in or out by keeping track of the root pixmap's
1065 * private data, and therefore don't need to access pScrnInfo->vtSema.
1068 xf86EnableDisableFBAccess(ScrnInfoPtr pScrnInfo, Bool enable)
1070 ScreenPtr pScreen = pScrnInfo->pScreen;
1073 pspix = (*pScreen->GetScreenPixmap) (pScreen);
1076 * Restore all of the clip lists on the screen
1079 SetRootClip(pScreen, TRUE);
1084 * Empty all of the clip lists on the screen
1086 SetRootClip(pScreen, FALSE);
1090 /* Print driver messages in the standard format of
1091 (<type>) <screen name>(<screen index>): <message> */
1093 xf86VDrvMsgVerb(int scrnIndex, MessageType type, int verb, const char *format,
1096 /* Prefix the scrnIndex name to the format string. */
1097 if (scrnIndex >= 0 && scrnIndex < xf86NumScreens &&
1098 xf86Screens[scrnIndex]->name)
1099 LogHdrMessageVerb(type, verb, format, args, "%s(%d): ",
1100 xf86Screens[scrnIndex]->name, scrnIndex);
1101 else if (scrnIndex >= GPU_SCREEN_OFFSET &&
1102 scrnIndex < GPU_SCREEN_OFFSET + xf86NumGPUScreens &&
1103 xf86GPUScreens[scrnIndex - GPU_SCREEN_OFFSET]->name)
1104 LogHdrMessageVerb(type, verb, format, args, "%s(G%d): ",
1105 xf86GPUScreens[scrnIndex - GPU_SCREEN_OFFSET]->name, scrnIndex - GPU_SCREEN_OFFSET);
1107 LogVMessageVerb(type, verb, format, args);
1110 /* Print driver messages, with verbose level specified directly */
1112 xf86DrvMsgVerb(int scrnIndex, MessageType type, int verb, const char *format,
1117 va_start(ap, format);
1118 xf86VDrvMsgVerb(scrnIndex, type, verb, format, ap);
1122 /* Print driver messages, with verbose level of 1 (default) */
1124 xf86DrvMsg(int scrnIndex, MessageType type, const char *format, ...)
1128 va_start(ap, format);
1129 xf86VDrvMsgVerb(scrnIndex, type, 1, format, ap);
1133 /* Print input driver messages in the standard format of
1134 (<type>) <driver>: <device name>: <message> */
1136 xf86VIDrvMsgVerb(InputInfoPtr dev, MessageType type, int verb,
1137 const char *format, va_list args)
1139 const char *driverName = NULL;
1140 const char *deviceName = NULL;
1142 /* Prefix driver and device names to formatted message. */
1144 deviceName = dev->name;
1146 driverName = dev->drv->driverName;
1149 LogHdrMessageVerb(type, verb, format, args, "%s: %s: ", driverName,
1153 /* Print input driver message, with verbose level specified directly */
1155 xf86IDrvMsgVerb(InputInfoPtr dev, MessageType type, int verb,
1156 const char *format, ...)
1160 va_start(ap, format);
1161 xf86VIDrvMsgVerb(dev, type, verb, format, ap);
1165 /* Print input driver messages, with verbose level of 1 (default) */
1167 xf86IDrvMsg(InputInfoPtr dev, MessageType type, const char *format, ...)
1171 va_start(ap, format);
1172 xf86VIDrvMsgVerb(dev, type, 1, format, ap);
1176 /* Print non-driver messages with verbose level specified directly */
1178 xf86MsgVerb(MessageType type, int verb, const char *format, ...)
1182 va_start(ap, format);
1183 LogVMessageVerb(type, verb, format, ap);
1187 /* Print non-driver messages with verbose level of 1 (default) */
1189 xf86Msg(MessageType type, const char *format, ...)
1193 va_start(ap, format);
1194 LogVMessageVerb(type, 1, format, ap);
1198 /* Just like ErrorF, but with the verbose level checked */
1200 xf86ErrorFVerb(int verb, const char *format, ...)
1204 va_start(ap, format);
1205 if (xf86Verbose >= verb || xf86LogVerbose >= verb)
1206 LogVWrite(verb, format, ap);
1210 /* Like xf86ErrorFVerb, but with an implied verbose level of 1 */
1212 xf86ErrorF(const char *format, ...)
1216 va_start(ap, format);
1217 if (xf86Verbose >= 1 || xf86LogVerbose >= 1)
1218 LogVWrite(1, format, ap);
1227 #define LOGSUFFIX ".log"
1228 #define LOGOLDSUFFIX ".old"
1230 /* Get the log file name */
1231 if (xf86LogFileFrom == X_DEFAULT) {
1232 /* Append the display number and ".log" */
1233 if (asprintf(&lf, "%s%%s" LOGSUFFIX, xf86LogFile) == -1)
1234 FatalError("Cannot allocate space for the log file name\n");
1238 xf86LogFile = LogInit(xf86LogFile, LOGOLDSUFFIX);
1239 xf86LogFileWasOpened = TRUE;
1241 xf86SetVerbosity(xf86Verbose);
1242 xf86SetLogVerbosity(xf86LogVerbose);
1251 xf86CloseLog(enum ExitCode error)
1257 * Drivers can use these for using their own SymTabRecs.
1261 xf86TokenToString(SymTabPtr table, int token)
1265 for (i = 0; table[i].token >= 0 && table[i].token != token; i++);
1267 if (table[i].token < 0)
1270 return table[i].name;
1274 xf86StringToToken(SymTabPtr table, const char *string)
1281 for (i = 0; table[i].token >= 0 && xf86NameCmp(string, table[i].name); i++);
1283 return table[i].token;
1287 * helper to display the clocks found on a card
1290 xf86ShowClocks(ScrnInfoPtr scrp, MessageType from)
1294 xf86DrvMsg(scrp->scrnIndex, from, "Pixel clocks available:");
1295 for (j = 0; j < scrp->numClocks; j++) {
1298 xf86DrvMsg(scrp->scrnIndex, from, "pixel clocks:");
1300 xf86ErrorF(" %7.3f", (double) scrp->clock[j] / 1000.0);
1306 * This prints out the driver identify message, including the names of
1307 * the supported chipsets.
1309 * XXX This makes assumptions about the line width, etc. Maybe we could
1310 * use a more general "pretty print" function for messages.
1313 xf86PrintChipsets(const char *drvname, const char *drvmsg, SymTabPtr chips)
1317 len = 6 + strlen(drvname) + 2 + strlen(drvmsg) + 2;
1318 xf86Msg(X_INFO, "%s: %s:", drvname, drvmsg);
1319 for (i = 0; chips[i].name != NULL; i++) {
1324 if (len + 2 + strlen(chips[i].name) < 78) {
1332 xf86ErrorF("%s", chips[i].name);
1333 len += strlen(chips[i].name);
1339 xf86MatchDevice(const char *drivername, GDevPtr ** sectlist)
1341 GDevPtr gdp, *pgdp = NULL;
1342 confScreenPtr screensecptr;
1349 * This can happen when running Xorg -showopts and a module like ati
1350 * or vmware tries to load its submodules when xf86ConfigLayout is empty
1352 if (!xf86ConfigLayout.screens)
1356 * This is a very important function that matches the device sections
1357 * as they show up in the config file with the drivers that the server
1358 * loads at run time.
1360 * ChipProbe can call
1361 * int xf86MatchDevice(char * drivername, GDevPtr ** sectlist)
1362 * with its driver name. The function allocates an array of GDevPtr and
1363 * returns this via sectlist and returns the number of elements in
1364 * this list as return value. 0 means none found, -1 means fatal error.
1366 * It can figure out which of the Device sections to use for which card
1367 * (using things like the Card statement, etc). For single headed servers
1368 * there will of course be just one such Device section.
1373 * first we need to loop over all the Screens sections to get to all
1374 * 'active' device sections
1376 for (j = 0; xf86ConfigLayout.screens[j].screen != NULL; j++) {
1377 screensecptr = xf86ConfigLayout.screens[j].screen;
1378 if ((screensecptr->device->driver != NULL)
1379 && (xf86NameCmp(screensecptr->device->driver, drivername) == 0)
1380 && (!screensecptr->device->claimed)) {
1382 * we have a matching driver that wasn't claimed, yet
1384 pgdp = xnfrealloc(pgdp, (i + 2) * sizeof(GDevPtr));
1385 pgdp[i++] = screensecptr->device;
1389 /* Then handle the inactive devices */
1391 while (xf86ConfigLayout.inactives[j].identifier) {
1392 gdp = &xf86ConfigLayout.inactives[j];
1393 if (gdp->driver && !gdp->claimed &&
1394 !xf86NameCmp(gdp->driver, drivername)) {
1395 /* we have a matching driver that wasn't claimed yet */
1396 pgdp = xnfrealloc(pgdp, (i + 2) * sizeof(GDevPtr));
1403 * make the array NULL terminated and return its address
1416 xf86GetVisualName(int visual)
1418 if (visual < 0 || visual > DirectColor)
1421 return xf86VisualNames[visual];
1425 xf86GetVerbosity(void)
1427 return max(xf86Verbose, xf86LogVerbose);
1433 return xf86Info.pixmap24;
1455 xf86GetFlipPixels(void)
1457 return xf86FlipPixels;
1461 xf86GetServerName(void)
1463 return xf86ServerName;
1467 xf86ServerIsExiting(void)
1469 return (dispatchException & DE_TERMINATE) == DE_TERMINATE;
1473 xf86ServerIsResetting(void)
1475 return xf86Resetting;
1479 xf86ServerIsInitialising(void)
1481 return xf86Initialising;
1485 xf86ServerIsOnlyDetecting(void)
1487 return xf86DoConfigure;
1491 xf86CaughtSignal(void)
1493 return xf86Info.caughtSignal;
1497 xf86GetVidModeAllowNonLocal(void)
1499 return xf86Info.vidModeAllowNonLocal;
1503 xf86GetVidModeEnabled(void)
1505 return xf86Info.vidModeEnabled;
1509 xf86GetModInDevAllowNonLocal(void)
1511 return xf86Info.miscModInDevAllowNonLocal;
1515 xf86GetModInDevEnabled(void)
1517 return xf86Info.miscModInDevEnabled;
1521 xf86GetAllowMouseOpenFail(void)
1523 return xf86Info.allowMouseOpenFail;
1527 xf86DisableRandR(void)
1529 xf86Info.disableRandR = TRUE;
1530 xf86Info.randRFrom = X_PROBED;
1534 xf86GetModuleVersion(pointer module)
1536 return (CARD32) LoaderGetModuleVersion(module);
1540 xf86LoadDrvSubModule(DriverPtr drv, const char *name)
1543 int errmaj = 0, errmin = 0;
1545 ret = LoadSubModule(drv->module, name, NULL, NULL, NULL, NULL,
1548 LoaderErrorMsg(NULL, name, errmaj, errmin);
1553 xf86LoadSubModule(ScrnInfoPtr pScrn, const char *name)
1556 int errmaj = 0, errmin = 0;
1558 ret = LoadSubModule(pScrn->module, name, NULL, NULL, NULL, NULL,
1561 LoaderErrorMsg(pScrn->name, name, errmaj, errmin);
1566 * xf86LoadOneModule loads a single module.
1569 xf86LoadOneModule(char *name, pointer opt)
1578 /* Normalise the module name */
1579 Name = xf86NormalizeName(name);
1581 /* Skip empty names */
1584 if (*Name == '\0') {
1589 mod = LoadModule(Name, NULL, NULL, NULL, opt, NULL, &errmaj, &errmin);
1591 LoaderErrorMsg(NULL, Name, errmaj, errmin);
1597 xf86UnloadSubModule(pointer mod)
1599 UnloadSubModule(mod);
1603 xf86LoaderCheckSymbol(const char *name)
1605 return LoaderSymbol(name) != NULL;
1609 OPTION_BACKING_STORE
1612 static const OptionInfoRec BSOptions[] = {
1613 {OPTION_BACKING_STORE, "BackingStore", OPTV_BOOLEAN, {0}, FALSE},
1614 {-1, NULL, OPTV_NONE, {0}, FALSE}
1618 xf86SetBackingStore(ScreenPtr pScreen)
1621 MessageType from = X_DEFAULT;
1622 ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
1623 OptionInfoPtr options;
1625 options = xnfalloc(sizeof(BSOptions));
1626 (void) memcpy(options, BSOptions, sizeof(BSOptions));
1627 xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, options);
1629 /* check for commandline option here */
1630 if (xf86bsEnableFlag) {
1634 else if (xf86bsDisableFlag) {
1639 if (xf86GetOptValBool(options, OPTION_BACKING_STORE, &useBS))
1643 pScreen->backingStoreSupport = useBS ? Always : NotUseful;
1644 if (serverGeneration == 1)
1645 xf86DrvMsg(pScreen->myNum, from, "Backing store %s\n",
1646 useBS ? "enabled" : "disabled");
1653 static const OptionInfoRec SMOptions[] = {
1654 {OPTION_SILKEN_MOUSE, "SilkenMouse", OPTV_BOOLEAN, {0}, FALSE},
1655 {-1, NULL, OPTV_NONE, {0}, FALSE}
1659 xf86SetSilkenMouse(ScreenPtr pScreen)
1662 MessageType from = X_DEFAULT;
1663 ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
1664 OptionInfoPtr options;
1666 options = xnfalloc(sizeof(SMOptions));
1667 (void) memcpy(options, SMOptions, sizeof(SMOptions));
1668 xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, options);
1670 /* check for commandline option here */
1671 /* disable if screen shares resources */
1672 /* TODO VGA arb disable silken mouse */
1673 if (xf86silkenMouseDisableFlag) {
1678 if (xf86GetOptValBool(options, OPTION_SILKEN_MOUSE, &useSM))
1683 * XXX quick hack to report correctly for OSs that can't do SilkenMouse
1684 * yet. Should handle this differently so that alternate async methods
1685 * work correctly with this too.
1687 pScrn->silkenMouse = useSM && xf86Info.useSIGIO && xf86SIGIOSupported();
1688 if (serverGeneration == 1)
1689 xf86DrvMsg(pScreen->myNum, from, "Silken mouse %s\n",
1690 pScrn->silkenMouse ? "enabled" : "disabled");
1693 /* Wrote this function for the PM2 Xv driver, preliminary. */
1696 xf86FindXvOptions(ScrnInfoPtr pScrn, int adaptor_index, char *port_name,
1697 char **adaptor_name, pointer *adaptor_options)
1699 confXvAdaptorPtr adaptor;
1702 if (adaptor_index >= pScrn->confScreen->numxvadaptors) {
1704 *adaptor_name = NULL;
1705 if (adaptor_options)
1706 *adaptor_options = NULL;
1710 adaptor = &pScrn->confScreen->xvadaptors[adaptor_index];
1712 *adaptor_name = adaptor->identifier;
1713 if (adaptor_options)
1714 *adaptor_options = adaptor->options;
1716 for (i = 0; i < adaptor->numports; i++)
1717 if (!xf86NameCmp(adaptor->ports[i].identifier, port_name))
1718 return adaptor->ports[i].options;
1723 /* Rather than duplicate loader's get OS function, just include it directly */
1724 #define LoaderGetOS xf86GetOS
1725 #include "loader/os.c"
1728 xf86ConfigFbEntityInactive(EntityInfoPtr pEnt, EntityProc init,
1729 EntityProc enter, EntityProc leave, pointer private)
1733 if ((pScrn = xf86FindScreenForEntity(pEnt->index)))
1734 xf86RemoveEntityFromScreen(pScrn, pEnt->index);
1735 xf86SetEntityFuncs(pEnt->index, init, enter, leave, private);
1739 xf86ConfigFbEntity(ScrnInfoPtr pScrn, int scrnFlag, int entityIndex,
1740 EntityProc init, EntityProc enter, EntityProc leave,
1743 EntityInfoPtr pEnt = xf86GetEntityInfo(entityIndex);
1748 if (!(pEnt->location.type == BUS_NONE)) {
1753 if (!pEnt->active) {
1754 xf86ConfigFbEntityInactive(pEnt, init, enter, leave, private);
1760 pScrn = xf86AllocateScreen(pEnt->driver, scrnFlag);
1761 xf86AddEntityToScreen(pScrn, entityIndex);
1763 xf86SetEntityFuncs(entityIndex, init, enter, leave, private);
1770 xf86IsScreenPrimary(ScrnInfoPtr pScrn)
1774 for (i = 0; i < pScrn->numEntities; i++) {
1775 if (xf86IsEntityPrimary(i))
1782 xf86RegisterRootWindowProperty(int ScrnIndex, Atom property, Atom type,
1783 int format, unsigned long len, pointer value)
1785 RootWinPropPtr pNewProp = NULL, pRegProp;
1786 Bool existing = FALSE;
1788 DebugF("xf86RegisterRootWindowProperty(%d, %ld, %ld, %d, %ld, %p)\n",
1789 ScrnIndex, property, type, format, len, value);
1791 if (ScrnIndex < 0 || ScrnIndex >= xf86NumScreens) {
1795 if (xf86RegisteredPropertiesTable &&
1796 xf86RegisteredPropertiesTable[ScrnIndex]) {
1797 for (pNewProp = xf86RegisteredPropertiesTable[ScrnIndex];
1798 pNewProp; pNewProp = pNewProp->next) {
1799 if (strcmp(pNewProp->name, NameForAtom(property)) == 0)
1805 if ((pNewProp = (RootWinPropPtr) malloc(sizeof(RootWinProp))) == NULL) {
1809 * We will put this property at the end of the list so that
1810 * the changes are made in the order they were requested.
1812 pNewProp->next = NULL;
1815 free(pNewProp->name);
1819 pNewProp->name = xnfstrdup(NameForAtom(property));
1820 pNewProp->type = type;
1821 pNewProp->format = format;
1822 pNewProp->size = len;
1823 pNewProp->data = value;
1825 DebugF("new property filled\n");
1827 if (xf86RegisteredPropertiesTable == NULL) {
1828 DebugF("creating xf86RegisteredPropertiesTable[] size %d\n",
1830 xf86RegisteredPropertiesTable =
1831 xnfcalloc(sizeof(RootWinProp), xf86NumScreens);
1834 DebugF("xf86RegisteredPropertiesTable %p\n",
1835 (void *) xf86RegisteredPropertiesTable);
1836 DebugF("xf86RegisteredPropertiesTable[%d] %p\n",
1837 ScrnIndex, (void *) xf86RegisteredPropertiesTable[ScrnIndex]);
1840 if (xf86RegisteredPropertiesTable[ScrnIndex] == NULL) {
1841 xf86RegisteredPropertiesTable[ScrnIndex] = pNewProp;
1844 pRegProp = xf86RegisteredPropertiesTable[ScrnIndex];
1845 while (pRegProp->next != NULL) {
1846 DebugF("- next %p\n", (void *) pRegProp);
1847 pRegProp = pRegProp->next;
1849 pRegProp->next = pNewProp;
1852 DebugF("xf86RegisterRootWindowProperty succeeded\n");
1857 xf86IsUnblank(int mode)
1860 case SCREEN_SAVER_OFF:
1861 case SCREEN_SAVER_FORCER:
1863 case SCREEN_SAVER_ON:
1864 case SCREEN_SAVER_CYCLE:
1867 xf86MsgVerb(X_WARNING, 0, "Unexpected save screen mode: %d\n", mode);
1873 xf86MotionHistoryAllocate(InputInfoPtr pInfo)
1875 AllocateMotionHistory(pInfo->dev);
1879 xf86ScreenToScrn(ScreenPtr pScreen)
1881 if (pScreen->isGPU) {
1882 assert(pScreen->myNum - GPU_SCREEN_OFFSET < xf86NumGPUScreens);
1883 return xf86GPUScreens[pScreen->myNum - GPU_SCREEN_OFFSET];
1885 assert(pScreen->myNum < xf86NumScreens);
1886 return xf86Screens[pScreen->myNum];
1891 xf86ScrnToScreen(ScrnInfoPtr pScrn)
1893 if (pScrn->is_gpu) {
1894 assert(pScrn->scrnIndex - GPU_SCREEN_OFFSET < screenInfo.numGPUScreens);
1895 return screenInfo.gpuscreens[pScrn->scrnIndex - GPU_SCREEN_OFFSET];
1897 assert(pScrn->scrnIndex < screenInfo.numScreens);
1898 return screenInfo.screens[pScrn->scrnIndex];