1 /* $XFree86: xc/programs/Xserver/hw/xfree68/fbdev/fbdev.c,v 3.1 1996/08/18 03:54:46 dawes Exp $ */
4 * Author: Thomas Gerner. Taken from fbdev.c by Martin Schaller
6 * Generic version by Geert Uytterhoeven (Geert.Uytterhoeven@cs.kuleuven.ac.be)
8 * This version contains support for:
10 * - Monochrome, 1 bitplane [mfb]
11 * - Color, 4/8 interleaved bitplanes with 2 bytes interleave [iplan2p?]
15 #define fbdev_PATCHLEVEL "4"
20 #include "scrnintstr.h"
21 #include "pixmapstr.h"
22 #include "regionstr.h"
23 #include "mipointer.h"
24 #include "cursorstr.h"
31 #include "xf86_OSlib.h"
32 #include "xf86_Config.h"
35 #include "colormapst.h"
40 #include <sys/queue.h>
41 #include "/sys/arch/atari/dev/grfabs_reg.h"
42 #include "/sys/arch/atari/dev/viewioctl.h"
44 static int *fbdevPrivateIndexP
;
45 static void (*fbdevBitBlt
)();
46 static int (*CreateDefColormap
)(ScreenPtr
);
48 extern int mfbCreateDefColormap(ScreenPtr
);
50 #if defined(CONFIG_IPLAN2p2) || defined(CONFIG_IPLAN2p4) || \
51 defined(CONFIG_IPLAN2p8)
52 extern int iplCreateDefColormap(ScreenPtr
);
53 #ifdef CONFIG_IPLAN2p2
54 extern int ipl2p2ScreenPrivateIndex
;
55 extern void ipl2p2DoBitblt();
56 #endif /* CONFIG_IPLAN2p2 */
57 #ifdef CONFIG_IPLAN2p4
58 extern int ipl2p4ScreenPrivateIndex
;
59 extern void ipl2p4DoBitblt();
60 #endif /* CONFIG_IPLAN2p4 */
61 #ifdef CONFIG_IPLAN2p8
62 extern int ipl2p8ScreenPrivateIndex
;
63 extern void ipl2p8DoBitblt();
64 #endif /* CONFIG_IPLAN2p8 */
65 #endif /* defined(CONFIG_IPLAN2p2) || defined(CONFIG_IPLAN2p4) || \
66 defined(CONFIG_IPLAN2p8) */
68 extern int cfb16ScreenPrivateIndex
;
69 extern void cfb16DoBitblt();
70 #endif /* CONFIG_CFB16 */
72 extern int fbdevValidTokens
[];
74 static Bool
fbdevProbe(void);
75 static void fbdevPrintIdent(void);
76 static Bool
fbdevSaveScreen(ScreenPtr pScreen
, int on
);
77 static Bool
fbdevScreenInit(int scr_index
, ScreenPtr pScreen
, int argc
,
79 static void fbdevEnterLeaveVT(Bool enter
, int screen_idx
);
80 static Bool
fbdevCloseScreen(int screen_idx
, ScreenPtr screen
);
81 static Bool
fbdevValidMode(DisplayModePtr mode
);
82 static Bool
fbdevSwitchMode(DisplayModePtr mode
);
84 static void xfree2fbdev(DisplayModePtr mode
, struct view_size
*var
);
85 static void fbdev2xfree(struct view_size
*var
, DisplayModePtr mode
);
87 extern Bool xf86Exiting
, xf86Resetting
, xf86ProbeFailed
;
89 ScrnInfoRec fbdevInfoRec
= {
90 FALSE
, /* Bool configured */
91 -1, /* int tmpIndex */
92 -1, /* int scrnIndex */
93 fbdevProbe
, /* Bool (*Probe)() */
94 fbdevScreenInit
, /* Bool (*Init)() */
95 (Bool (*)())NoopDDA
, /* Bool (*ValidMode)() */
96 fbdevEnterLeaveVT
, /* void (*EnterLeaveVT)() */
97 (void (*)())NoopDDA
, /* void (*EnterLeaveMonitor)() */
98 (void (*)())NoopDDA
, /* void (*EnterLeaveCursor)() */
99 (void (*)())NoopDDA
, /* void (*AdjustFrame)() */
100 (Bool (*)())NoopDDA
, /* void (*SwitchMode)() */
101 (void (*)())NoopDDA
, /* void (*DPMSSet)() */
102 fbdevPrintIdent
, /* void (*PrintIdent)() */
104 {0, }, /* xrgb weight */
105 8, /* int bitsPerPixel */
106 PseudoColor
, /* int defaultVisual */
107 -1, -1, /* int virtualX,virtualY */
108 -1, /* int displayWidth */
109 -1, -1, -1, -1, /* int frameX0, frameY0, frameX1, frameY1 */
110 {0, }, /* OFlagSet options */
111 {0, }, /* OFlagSet clockOptions */
112 {0, }, /* OFlagSet xconfigFlag */
113 NULL
, /* char *chipset */
114 NULL
, /* char *ramdac */
115 {0, }, /* int dacSpeeds[MAXDACSPEEDS] */
116 0, /* int dacSpeed */
118 {0, }, /* int clock[MAXCLOCKS] */
119 0, /* int maxClock */
120 0, /* int videoRam */
121 0, /* int BIOSbase */
122 0, /* unsigned long MemBase */
123 240, 180, /* int width, height */
124 0, /* unsigned long speedup */
125 NULL
, /* DisplayModePtr modes */
126 NULL
, /* MonPtr monitor */
127 NULL
, /* char *clockprog */
128 -1, /* int textclock */
129 FALSE
, /* Bool bankedMono */
130 "FBDev", /* char *name */
131 {0, }, /* RgbRec blackColour */
132 {0, }, /* RgbRec whiteColour */
133 fbdevValidTokens
, /* int *validTokens */
134 fbdev_PATCHLEVEL
, /* char *patchLevel */
135 0, /* unsigned int IObase */
136 0, /* unsigned int DACbase */
137 0, /* unsigned int COPbase */
138 0, /* unsigned int POSbase */
139 0, /* unsigned int instance */
140 0, /* int s3Madjust */
141 0, /* int s3Nadjust */
145 0, /* unsigned long VGAbase */
146 0, /* int s3RefClk */
147 -1, /* int s3BlankDelay */
148 0, /* int textClockFreq */
149 NULL
, /* char *DCConfig */
150 NULL
, /* char *DCOptions */
154 0, /* int directMode */
155 NULL
, /* void (*setBank)() */
156 0, /* unsigned long physBase */
157 0, /* int physSize */
160 NULL
, /* void *device */
164 static pointer fbdevVirtBase
= NULL
;
166 static ScreenPtr savepScreen
= NULL
;
167 static PixmapPtr ppix
= NULL
;
169 extern miPointerScreenFuncRec xf86PointerScreenFuncs
;
171 #define NOMAPYET (ColormapPtr)0
173 static ColormapPtr InstalledMaps
[MAXSCREENS
];
174 /* current colormap for each screen */
177 #define StaticGrayMask (1 << StaticGray)
178 #define GrayScaleMask (1 << GrayScale)
179 #define StaticColorMask (1 << StaticColor)
180 #define PseudoColorMask (1 << PseudoColor)
181 #define TrueColorMask (1 << TrueColor)
182 #define DirectColorMask (1 << DirectColor)
184 #define ALL_VISUALS (StaticGrayMask|\
199 static int fb_fd
= -1;
201 static u_long colorentry
[256];
202 static int colorbitshift
;
203 static struct view_size vs
;
204 static fb_fix_screeninfo fb_fix
;
207 static Bool UseModeDB
= FALSE
;
210 static void open_framebuffer(void)
216 for (i
= 0; i
< 100; i
++) {
217 sprintf(buffer
, "/dev/view%02d", i
);
218 fb_fd
= open(buffer
, O_RDWR
);
219 if (fb_fd
< 0 && errno
!= EBUSY
) {
220 FatalError("open_framebuffer: failed to open %s (%s)\n",
221 buffer
, strerror(errno
));
224 } else if (fb_fd
> 0) {
225 xf86Info
.screenFd
= fb_fd
;
229 FatalError("open_framebuffer: Ran out of views.\n");
233 static void close_framebuffer(void)
241 static pointer
MapVidMem(int ScreenNum
, unsigned long Size
)
246 base
= (pointer
)mmap((caddr_t
)0, Size
, PROT_READ
| PROT_WRITE
,
247 MAP_SHARED
, fb_fd
, (off_t
)0);
248 if ((long)base
== -1)
249 FatalError("MapVidMem: Could not mmap framebuffer (%s)\n",
254 static void UnMapVidMem(int ScreenNum
, unsigned long Size
)
256 munmap(fbdevVirtBase
, Size
);
260 static void fbdevUpdateColormap(ScreenPtr pScreen
, int dex
, int count
,
261 unsigned char *rmap
, unsigned char *gmap
,
265 colormap_t
*cmap
= &fb_fix
.colormap
;
268 /* Switched away from server vt, do nothing. */
273 cmap
->entry
[dex
] = (rmap
[dex
] << 16 | gmap
[dex
] << 8 | bmap
[dex
]);
280 for (i
= 0; i
< count
; i
++, dex
++) {
281 cmap
->entry
[i
] = (rmap
[dex
] << 16 | gmap
[dex
] << 8 | bmap
[dex
]);
284 if (ioctl(fb_fd
, VIOCSCMAP
, cmap
) < 0)
285 FatalError("fbdevUpdateColormap: VIOCSCMAP failed (%s)\n",
289 static int fbdevListInstalledColormaps(ScreenPtr pScreen
, Colormap
*pmaps
)
291 *pmaps
= InstalledMaps
[pScreen
->myNum
]->mid
;
295 static void fbdevStoreColors(ColormapPtr pmap
, int ndef
, xColorItem
*pdefs
)
297 unsigned char rmap
[256], gmap
[256], bmap
[256];
299 register int first
= -256;
300 register int priv
= -256;
301 register int count
= 0;
302 register int bitshift
= colorbitshift
;
304 if (pmap
!= InstalledMaps
[pmap
->pScreen
->myNum
])
311 fbdevUpdateColormap(pmap
->pScreen
, first
, count
, rmap
, gmap
, bmap
);
316 rmap
[i
] = pdefs
->red
>> bitshift
;
317 gmap
[i
] = pdefs
->green
>> bitshift
;
318 bmap
[i
] = pdefs
->blue
>> bitshift
;
323 fbdevUpdateColormap(pmap
->pScreen
, first
, count
, rmap
, gmap
, bmap
);
326 static void fbdevInstallColormap(ColormapPtr pmap
)
328 ColormapPtr oldmap
= InstalledMaps
[pmap
->pScreen
->myNum
];
329 int entries
= pmap
->pVisual
->ColormapEntries
;
332 xColorItem defs
[256];
338 if (oldmap
!= NOMAPYET
)
339 WalkTree(pmap
->pScreen
, TellLostMap
, &oldmap
->mid
);
341 InstalledMaps
[pmap
->pScreen
->myNum
] = pmap
;
343 for (i
= 0 ; i
< entries
; i
++)
345 QueryColors(pmap
, entries
, ppix
, prgb
);
347 for (i
= 0 ; i
< entries
; i
++) {
348 defs
[i
].pixel
= ppix
[i
];
349 defs
[i
].red
= prgb
[i
].red
;
350 defs
[i
].green
= prgb
[i
].green
;
351 defs
[i
].blue
= prgb
[i
].blue
;
354 fbdevStoreColors(pmap
, entries
, defs
);
356 WalkTree(pmap
->pScreen
, TellGainedMap
, &pmap
->mid
);
361 static void fbdevUninstallColormap(ColormapPtr pmap
)
363 ColormapPtr defColormap
;
365 if (pmap
!= InstalledMaps
[pmap
->pScreen
->myNum
])
367 defColormap
= (ColormapPtr
)LookupIDByType(pmap
->pScreen
->defColormap
,
369 if (defColormap
== InstalledMaps
[pmap
->pScreen
->myNum
])
371 (*pmap
->pScreen
->InstallColormap
)(defColormap
);
375 * fbdevPrintIdent -- Prints out identifying strings for drivers included in
379 static void fbdevPrintIdent(void)
381 ErrorF(" %s: Server for frame buffer device\n", fbdevInfoRec
.name
);
382 ErrorF(" (Patchlevel %s): mfb", fbdevInfoRec
.patchLevel
);
383 #ifdef CONFIG_IPLAN2p2
384 ErrorF(", iplan2p2");
386 #ifdef CONFIG_IPLAN2p4
387 ErrorF(", iplan2p4");
389 #ifdef CONFIG_IPLAN2p8
390 ErrorF(", iplan2p8");
399 static Bool
fbdevLookupMode(DisplayModePtr target
)
402 Bool found_mode
= FALSE
;
404 for (p
= fbdevInfoRec
.monitor
->Modes
; p
!= NULL
; p
= p
->next
)
405 if (!strcmp(p
->name
, target
->name
)) {
406 target
->Clock
= p
->Clock
;
407 target
->HDisplay
= p
->HDisplay
;
408 target
->HSyncStart
= p
->HSyncStart
;
409 target
->HSyncEnd
= p
->HSyncEnd
;
410 target
->HTotal
= p
->HTotal
;
411 target
->VDisplay
= p
->VDisplay
;
412 target
->VSyncStart
= p
->VSyncStart
;
413 target
->VSyncEnd
= p
->VSyncEnd
;
414 target
->VTotal
= p
->VTotal
;
415 target
->Flags
= p
->Flags
;
416 target
->SynthClock
= p
->SynthClock
;
417 target
->CrtcHDisplay
= p
->CrtcHDisplay
;
418 target
->CrtcHSyncStart
= p
->CrtcHSyncStart
;
419 target
->CrtcHSyncEnd
= p
->CrtcHSyncEnd
;
420 target
->CrtcHTotal
= p
->CrtcHTotal
;
421 target
->CrtcVDisplay
= p
->CrtcVDisplay
;
422 target
->CrtcVSyncStart
= p
->CrtcVSyncStart
;
423 target
->CrtcVSyncEnd
= p
->CrtcVSyncEnd
;
424 target
->CrtcVTotal
= p
->CrtcVTotal
;
425 target
->CrtcHAdjusted
= p
->CrtcHAdjusted
;
426 target
->CrtcVAdjusted
= p
->CrtcVAdjusted
;
427 if (fbdevValidMode(target
)) {
437 * fbdevProbe -- Probe and initialize the hardware driver
440 static Bool
fbdevProbe(void)
442 DisplayModePtr pMode
, pEnd
;
446 if (ioctl(fb_fd
, VIOCGSIZE
, &vs
))
447 FatalError("fbdevProbe: unable to get screen params (%s)\n",
450 pMode
= fbdevInfoRec
.modes
;
452 FatalError("No modes supplied in XF86Config\n");
454 if (!strcmp(pMode
->name
, "default")) {
455 ErrorF("%s %s: Using default frame buffer video mode\n", XCONFIG_GIVEN
,
457 fbdevInfoRec
.depth
= vs
.depth
;
458 fbdevInfoRec
.bitsPerPixel
= fbdevInfoRec
.depth
;
460 ErrorF("%s %s: Using XF86Config video mode database\n", XCONFIG_GIVEN
,
464 fbdevInfoRec
.bitsPerPixel
= fbdevInfoRec
.depth
;
466 DisplayModePtr pModeSv
;
468 pModeSv
= pMode
->next
;
469 if (!fbdevLookupMode(pMode
))
470 xf86DeleteMode(&fbdevInfoRec
, pMode
);
473 * Successfully looked up this mode. If pEnd isn't
474 * initialized, set it to this mode.
476 if (pEnd
== (DisplayModePtr
)NULL
)
480 } while (pMode
!= pEnd
);
482 fbdevInfoRec
.SwitchMode
= fbdevSwitchMode
;
489 static void fbdevRestoreColors(ScreenPtr pScreen
)
491 ColormapPtr pmap
= InstalledMaps
[pScreen
->myNum
];
495 xColorItem defs
[256];
499 pmap
= (ColormapPtr
) LookupIDByType(pScreen
->defColormap
, RT_COLORMAP
);
500 entries
= pmap
->pVisual
->ColormapEntries
;
502 for (i
= 0 ; i
< entries
; i
++)
504 QueryColors(pmap
, entries
, ppix
, prgb
);
506 for (i
= 0 ; i
< entries
; i
++) {
507 defs
[i
].pixel
= ppix
[i
];
508 defs
[i
].red
= prgb
[i
].red
;
509 defs
[i
].green
= prgb
[i
].green
;
510 defs
[i
].blue
= prgb
[i
].blue
;
513 fbdevStoreColors(pmap
, entries
, defs
);
517 static Bool
fbdevSaveScreen(ScreenPtr pScreen
, int on
)
520 case SCREEN_SAVER_ON
:
522 unsigned char map
[256];
525 numentries
= 1 << fb_fix
.bm
.depth
;
527 for (i
= 0; i
< numentries
; i
++)
529 fbdevUpdateColormap(pScreen
, 0, numentries
, map
, map
, map
);
533 case SCREEN_SAVER_OFF
:
534 fbdevRestoreColors(pScreen
);
540 static Bool
fbdevSaveScreenDummy(ScreenPtr pScreen
, int on
)
546 * fbdevScreenInit -- Attempt to find and initialize a framebuffer
547 * Most of the elements of the ScreenRec are filled in.
548 * The video is enabled for the frame buffer...
550 * Arguments: scr_index : The index of pScreen in the ScreenInfo
551 * pScreen : The Screen to initialize
552 * argc : The number of the Server's arguments.
553 * argv : The arguments themselves. Don't change!
556 static Bool
fbdevScreenInit(int scr_index
, ScreenPtr pScreen
, int argc
,
559 int displayResolution
= 75; /* default to 75dpi */
561 extern int monitorResolution
;
562 struct view_size
*var
= &vs
;
563 static unsigned short bw
[] = {
568 int bpp
, xsize
, ysize
;
570 Bool NoColormap
= FALSE
;
575 * Take display resolution from the -dpi flag if specified
578 if (monitorResolution
)
579 displayResolution
= monitorResolution
;
581 dxres
= displayResolution
;
582 dyres
= displayResolution
;
584 mode
= fbdevInfoRec
.modes
;
586 fbdev2xfree(var
, mode
);
587 mode
->name
= "default";
588 fbdevInfoRec
.virtualX
= var
->x
;
589 fbdevInfoRec
.virtualY
= var
->y
;
591 xfree2fbdev(mode
, var
);
593 if (ioctl(fb_fd
, VIOCSSIZE
, var
))
594 FatalError("fbdevScreenInit: unable to set screen params (%s)\n",
597 if (ioctl(fb_fd
, VIOCGSIZE
, &fb_fix
.vs
))
598 FatalError("ioctl(fd, VIOCGSIZE, ...)");
600 if (ioctl(fb_fd
, VIOCGBMAP
, &fb_fix
.bm
))
601 FatalError("ioctl(fd, VIOCGBMAP, ...)");
603 fb_fix
.colormap
.first
= 0;
604 fb_fix
.colormap
.size
= 1 << fb_fix
.bm
.depth
;
605 fb_fix
.colormap
.entry
= colorentry
;
607 if (ioctl(fb_fd
, VIOCGCMAP
, &fb_fix
.colormap
))
608 FatalError("ioctl(fd, VIOCGCMAP, ...)");
610 if (ioctl(fb_fd
, VIOCDISPLAY
, 0))
611 FatalError("ioctl(fd, VIOCDISPLAY ...)");
613 switch (fb_fix
.colormap
.red_mask
)
625 fb_fix
.smem_len
= fb_fix
.bm
.bytes_per_row
* fb_fix
.bm
.rows
;
626 fbdevInfoRec
.videoRam
= fb_fix
.smem_len
>>10;
629 ErrorF("%s %s: Video memory: %dk\n", XCONFIG_PROBED
, fbdevInfoRec
.name
,
630 fbdevInfoRec
.videoRam
);
631 ErrorF("%s %s: Width %d, Height %d, Depth %d\n", XCONFIG_PROBED
,
632 fbdevInfoRec
.name
, fb_fix
.vs
.width
, fb_fix
.vs
.height
,
636 fbdevVirtBase
= MapVidMem(scr_index
, fb_fix
.smem_len
);
639 bpp
= fb_fix
.bm
.depth
;
640 xsize
= fb_fix
.vs
.width
;
641 ysize
= fb_fix
.vs
.height
;
645 if (xf86FlipPixels
) {
653 if ((xsize
== 1280) && (ysize
== 960)) {
655 temp
= white
; white
= black
; black
= temp
;
658 pScreen
->blackPixel
= black
;
659 pScreen
->whitePixel
= white
;
661 mfbScreenInit(pScreen
, fbdevVirtBase
, xsize
, ysize
, dxres
,
663 fbdevPrivateIndexP
= NULL
;
664 fbdevBitBlt
= mfbDoBitblt
;
665 CreateDefColormap
= mfbCreateDefColormap
;
667 #ifdef CONFIG_IPLAN2p2
670 ipl2p2ScreenInit(pScreen
, fbdevVirtBase
, xsize
,
671 ysize
, dxres
, dyres
, xsize
);
672 fbdevPrivateIndexP
=&ipl2p2ScreenPrivateIndex
;
673 fbdevBitBlt
=ipl2p2DoBitblt
;
674 CreateDefColormap
=iplCreateDefColormap
;
678 #ifdef CONFIG_IPLAN2p4
681 ipl2p4ScreenInit(pScreen
, fbdevVirtBase
, xsize
,
682 ysize
, dxres
, dyres
, xsize
);
683 fbdevPrivateIndexP
=&ipl2p4ScreenPrivateIndex
;
684 fbdevBitBlt
=ipl2p4DoBitblt
;
685 CreateDefColormap
=iplCreateDefColormap
;
689 #ifdef CONFIG_IPLAN2p8
692 ipl2p8ScreenInit(pScreen
, fbdevVirtBase
, xsize
,
693 ysize
, dxres
, dyres
, xsize
);
694 fbdevPrivateIndexP
=&ipl2p8ScreenPrivateIndex
;
695 fbdevBitBlt
=ipl2p8DoBitblt
;
696 CreateDefColormap
=iplCreateDefColormap
;
703 cfb16ScreenInit(pScreen
, fbdevVirtBase
, xsize
, ysize
,
704 dxres
, dyres
, xsize
);
705 fbdevPrivateIndexP
= &cfb16ScreenPrivateIndex
;
706 fbdevBitBlt
= cfb16DoBitblt
;
707 CreateDefColormap
= cfbCreateDefColormap
;
711 FatalError("Unsupported bitmap depth %d\n", bpp
);
714 ErrorF("%s %s: Using %s driver\n", XCONFIG_PROBED
, fbdevInfoRec
.name
,
716 pScreen
->CloseScreen
= fbdevCloseScreen
;
717 pScreen
->SaveScreen
= (SaveScreenProcPtr
)fbdevSaveScreenDummy
;
719 if ((bpp
<=8) && !NoColormap
) {
720 pScreen
->SaveScreen
= (SaveScreenProcPtr
)fbdevSaveScreen
;
721 pScreen
->InstallColormap
= fbdevInstallColormap
;
722 pScreen
->UninstallColormap
= fbdevUninstallColormap
;
723 pScreen
->ListInstalledColormaps
= fbdevListInstalledColormaps
;
724 pScreen
->StoreColors
= fbdevStoreColors
;
726 miDCInitialize(pScreen
, &xf86PointerScreenFuncs
);
728 if (!(*CreateDefColormap
)(pScreen
))
731 savepScreen
= pScreen
;
737 * fbdevEnterLeaveVT -- Grab/ungrab the current VT completely.
740 static void fbdevEnterLeaveVT(Bool enter
, int screen_idx
)
746 ScreenPtr pScreen
= savepScreen
;
748 if (!xf86Resetting
&& !xf86Exiting
) {
749 pixBox
.x1
= 0; pixBox
.x2
= pScreen
->width
;
750 pixBox
.y1
= 0; pixBox
.y2
= pScreen
->height
;
751 pixPt
.x
= 0; pixPt
.y
= 0;
752 (pScreen
->RegionInit
)(&pixReg
, &pixBox
, 1);
753 if (fbdevPrivateIndexP
)
754 pspix
= (PixmapPtr
)pScreen
->devPrivates
[*fbdevPrivateIndexP
].ptr
;
756 pspix
= (PixmapPtr
)pScreen
->devPrivate
;
762 * point pspix back to fbdevVirtBase, and copy the dummy buffer to the
766 if (pspix
->devPrivate
.ptr
!= fbdevVirtBase
&& ppix
) {
767 pspix
->devPrivate
.ptr
= fbdevVirtBase
;
768 (*fbdevBitBlt
)(&ppix
->drawable
, &pspix
->drawable
, GXcopy
,
769 &pixReg
, &pixPt
, ~0);
772 (pScreen
->DestroyPixmap
)(ppix
);
776 if (!xf86Resetting
) {
777 /* Update the colormap */
778 ColormapPtr pmap
= InstalledMaps
[pScreen
->myNum
];
782 xColorItem defs
[256];
786 pmap
= (ColormapPtr
) LookupIDByType(pScreen
->defColormap
,
788 entries
= pmap
->pVisual
->ColormapEntries
;
790 for (i
= 0 ; i
< entries
; i
++)
792 QueryColors (pmap
, entries
, ppix
, prgb
);
794 for (i
= 0 ; i
< entries
; i
++) {
795 defs
[i
].pixel
= ppix
[i
];
796 defs
[i
].red
= prgb
[i
].red
;
797 defs
[i
].green
= prgb
[i
].green
;
798 defs
[i
].blue
= prgb
[i
].blue
;
801 fbdevStoreColors(pmap
, entries
, defs
);
806 * Create a dummy pixmap to write to while VT is switched out.
807 * Copy the screen to that pixmap
810 ppix
= (pScreen
->CreatePixmap
)(pScreen
, pScreen
->width
,
811 pScreen
->height
, pScreen
->rootDepth
);
813 (*fbdevBitBlt
)(&pspix
->drawable
, &ppix
->drawable
, GXcopy
,
814 &pixReg
, &pixPt
, ~0);
815 pspix
->devPrivate
.ptr
= ppix
->devPrivate
.ptr
;
818 if(ioctl(fb_fd
, VIOCREMOVE
, 0))
819 FatalError("ioctl(fd, VIOCREMOVE ...)");
821 UnMapVidMem(screen_idx
, fb_fix
.smem_len
);
826 * fbdevCloseScreen -- Called to ensure video is enabled when server exits.
829 static Bool
fbdevCloseScreen(int screen_idx
, ScreenPtr screen
)
832 * Hmm... The server may shut down even if it is not running on the
833 * current vt. Let's catch this case here.
837 fbdevEnterLeaveVT(LEAVE
, screen_idx
);
840 * 7-Jan-94 CEG: The server is not running on the current vt.
841 * Free the screen snapshot taken when the server vt was left.
843 (savepScreen
->DestroyPixmap
)(ppix
);
850 * fbdevValidMode -- Check whether a mode is valid. If necessary, values will
851 * be rounded up by the Frame Buffer Device
854 static Bool
fbdevValidMode(DisplayModePtr mode
)
860 * fbdevSwitchMode -- Change the video mode `on the fly'
863 static Bool
fbdevSwitchMode(DisplayModePtr mode
)
865 ErrorF("fbdevSwitchMode called\n");
867 struct view_size var
= vs
;
868 ScreenPtr pScreen
= savepScreen
;
872 PixmapPtr pspix
, ppix
;
875 xfree2fbdev(mode
, &var
);
876 var
.x
= fbdevInfoRec
.frameX0
;
877 var
.y
= fbdevInfoRec
.frameY0
;
879 /* Save the screen image */
880 pixBox
.x1
= 0; pixBox
.x2
= pScreen
->width
;
881 pixBox
.y1
= 0; pixBox
.y2
= pScreen
->height
;
882 pixPt
.x
= 0; pixPt
.y
= 0;
883 (pScreen
->RegionInit
)(&pixReg
, &pixBox
, 1);
884 if (fbdevPrivateIndexP
)
885 pspix
= (PixmapPtr
)pScreen
->devPrivates
[*fbdevPrivateIndexP
].ptr
;
887 pspix
= (PixmapPtr
)pScreen
->devPrivate
;
888 ppix
= (pScreen
->CreatePixmap
)(pScreen
, pScreen
->width
, pScreen
->height
,
891 (*fbdevBitBlt
)(&pspix
->drawable
, &ppix
->drawable
, GXcopy
, &pixReg
,
894 if (!ioctl(fb_fd
, VIOCSSIZE
, &var
)) {
895 /* Restore the colormap */
896 fbdevRestoreColors(pScreen
);
897 /* restore the screen image */
899 (*fbdevBitBlt
)(&ppix
->drawable
, &pspix
->drawable
, GXcopy
, &pixReg
,
901 vs
.width
= var
.width
;
902 vs
.height
= var
.height
;
906 (pScreen
->DestroyPixmap
)(ppix
);
915 * Convert timings between the XFree style and the Frame Buffer Device style
918 static void xfree2fbdev(DisplayModePtr mode
, struct view_size
*var
)
920 var
->width
= mode
->HDisplay
;
921 var
->height
= mode
->VDisplay
;
922 var
->depth
= fbdevInfoRec
.bitsPerPixel
;
923 var
->x
= mode
->HDisplay
;
924 var
->y
= mode
->VDisplay
;
927 static void fbdev2xfree(struct view_size
*var
, DisplayModePtr mode
)
930 mode
->HDisplay
= var
->width
;
931 mode
->HSyncStart
= 0;
934 mode
->VDisplay
= var
->height
;
935 mode
->VSyncStart
= 0;
939 mode
->SynthClock
= mode
->Clock
;
940 mode
->CrtcHDisplay
= mode
->HDisplay
;
941 mode
->CrtcHSyncStart
= mode
->HSyncStart
;
942 mode
->CrtcHSyncEnd
= mode
->HSyncEnd
;
943 mode
->CrtcHTotal
= mode
->HTotal
;
944 mode
->CrtcVDisplay
= mode
->VDisplay
;
945 mode
->CrtcVSyncStart
= mode
->VSyncStart
;
946 mode
->CrtcVSyncEnd
= mode
->VSyncEnd
;
947 mode
->CrtcVTotal
= mode
->VTotal
;
948 mode
->CrtcHAdjusted
= FALSE
;
949 mode
->CrtcVAdjusted
= FALSE
;