sunInit.c revision b9325ec5
1/* $Xorg: sunInit.c,v 1.4 2000/08/17 19:48:29 cpqbld Exp $ */
2/*
3 * sunInit.c --
4 *	Initialization functions for screen/keyboard/mouse, etc.
5 *
6 * Copyright 1987 by the Regents of the University of California
7 *
8 * Permission to use, copy, modify, and distribute this
9 * software and its documentation for any purpose and without
10 * fee is hereby granted, provided that the above copyright
11 * notice appear in all copies.  The University of California
12 * makes no representations about the suitability of this
13 * software for any purpose.  It is provided "as is" without
14 * express or implied warranty.
15 *
16 *
17 */
18/* $XFree86: xc/programs/Xserver/hw/sun/sunInit.c,v 3.14 2004/06/02 22:43:00 dawes Exp $ */
19
20/************************************************************
21Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA.
22
23                    All Rights Reserved
24
25Permission  to  use,  copy,  modify,  and  distribute   this
26software  and  its documentation for any purpose and without
27fee is hereby granted, provided that the above copyright no-
28tice  appear  in all copies and that both that copyright no-
29tice and this permission notice appear in  supporting  docu-
30mentation,  and  that the names of Sun or The Open Group
31not be used in advertising or publicity pertaining to
32distribution  of  the software  without specific prior
33written permission. Sun and The Open Group make no
34representations about the suitability of this software for
35any purpose. It is provided "as is" without any express or
36implied warranty.
37
38SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO  THIS  SOFTWARE,
39INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
40NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE  LI-
41ABLE  FOR  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
42ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,  DATA  OR
43PROFITS,  WHETHER  IN  AN  ACTION OF CONTRACT, NEGLIGENCE OR
44OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
45THE USE OR PERFORMANCE OF THIS SOFTWARE.
46
47*******************************************************/
48
49#include    "sun.h"
50#include    "gcstruct.h"
51#include    "mi.h"
52#include    "fb.h"
53
54/* maximum pixmap depth */
55#ifndef SUNMAXDEPTH
56#define SUNMAXDEPTH 8
57#endif
58
59#ifdef i386 /* { */
60#define BW2I NULL
61#else /* }{ */
62#define BW2I sunBW2Init
63#endif /* } */
64
65#ifdef LOWMEMFTPT
66#undef  BW2I
67#define BW2I NULL
68#endif /* ifdef LOWMEMFTPT */
69
70#if SUNMAXDEPTH == 1 /* { */
71#define CG2I NULL
72#define CG3I NULL
73#define CG4I NULL
74#define CG6I NULL
75#define CG8I NULL
76#define TCXI NULL
77#else /* }{ */
78#define CG3I sunCG3Init
79#if defined(i386) || defined(__bsdi__) /* { */
80#define CG2I NULL
81#define CG4I NULL
82#else /* }{ */
83#ifdef INCLUDE_CG2_HEADER
84#define CG2I sunCG2Init
85#endif /* INCLUDE_CG2_HEADER */
86#define CG4I sunCG4Init
87#endif /* } */
88#ifdef FBTYPE_SUNFAST_COLOR /* { */
89#define CG6I sunCG6Init
90#else /* }{ */
91#define CG6I NULL
92#endif /* } */
93#ifdef XFBTYPE_TCX  /* { */
94#define TCXI sunTCXInit
95#else /* }{ */
96#define TCXI NULL
97#endif /* } */
98#if SUNMAXDEPTH > 8 /* { */
99#ifdef FBTYPE_MEMCOLOR /* { */
100#define CG8I sunCG8Init
101#else /* }{ */
102#define CG8I NULL
103#endif /* } */
104#else /* }{ */
105#define CG8I NULL
106#endif /* } */
107
108#endif /* } */
109
110static int OpenFrameBuffer(char *, int);
111static void SigIOHandler(int);
112static char** GetDeviceList(int, char **);
113static void getKbdType(void);
114
115#if SUNMAXDEPTH == 32
116static Bool sunCfbCreateGC(GCPtr);
117static void sunCfbGetSpans(DrawablePtr, int, DDXPointPtr, int *, int, char *);
118static void sunCfbGetImage(DrawablePtr, int,int, int, int, unsigned int, unsigned long, char *);
119#endif /* SUNMAXDEPTH == 32 */
120
121static Bool	sunDevsInited = FALSE;
122
123EventList *sunEvents = NULL;
124
125Bool sunAutoRepeatHandlersInstalled;	/* FALSE each time InitOutput called */
126Bool sunSwapLkeys = FALSE;
127Bool sunFlipPixels = FALSE;
128Bool sunFbInfo = FALSE;
129Bool sunCG4Frob = FALSE;
130Bool sunNoGX = FALSE;
131
132sunKbdPrivRec sunKbdPriv = {
133    -1,		/* fd */
134    -1,		/* type */
135    -1,		/* layout */
136    0,		/* click */
137    (Leds)0,	/* leds */
138};
139
140sunPtrPrivRec sunPtrPriv = {
141    -1,		/* fd */
142    0		/* Current button state */
143};
144
145/*
146 * The name member in the following table corresponds to the
147 * FBTYPE_* macros defined in /usr/include/sun/fbio.h file
148 */
149sunFbDataRec sunFbData[XFBTYPE_LASTPLUSONE] = {
150  { NULL, "SUN1BW        (bw1)" },
151  { NULL, "SUN1COLOR     (cg1)" },
152  { BW2I, "SUN2BW        (bw2)" },
153#ifdef INCLUDE_CG2_HEADER
154  { CG2I, "SUN2COLOR     (cg2)" },
155#else
156  { NULL, "SUN2COLOR     (cg2)" },
157#endif /* INCLUDE_CG2_HEADER */
158  { NULL, "SUN2GP        (gp1/gp2)" },
159  { NULL, "SUN5COLOR     (cg5/386i accel)" },
160  { CG3I, "SUN3COLOR     (cg3)" },
161  { CG8I, "MEMCOLOR      (cg8)" },
162  { CG4I, "SUN4COLOR     (cg4)" },
163  { NULL, "NOTSUN1" },
164  { NULL, "NOTSUN2" },
165  { NULL, "NOTSUN3" }
166#ifndef i386 /* { */
167 ,{ CG6I, "SUNFAST_COLOR (cg6/gx)" },
168  { NULL, "SUNROP_COLOR  (cg9)" },
169  { NULL, "SUNFB_VIDEO" },
170  { NULL, "SUNGIFB" },
171  { NULL, "SUNPLAS" },
172#ifdef FBTYPE_SUNGP3
173  { NULL, "SUNGP3        (cg12/gs)" },
174#endif
175#ifdef FBTYPE_SUNGT
176  { NULL, "SUNGT         (gt)" },
177#endif
178#ifdef FBTYPE_SUNLEO
179  { NULL, "SUNLEO        (zx)" },
180#endif
181#ifdef FBTYPE_MDICOLOR
182  { NULL, "MDICOLOR      (cgfourteen)" },
183#endif
184#ifdef XFBTYPE_TCX
185  { TCXI, "TCX           (tcx)" },
186#endif
187#endif /* } */
188};
189
190/*
191 * a list of devices to try if there is no environment or command
192 * line list of devices
193 */
194#if SUNMAXDEPTH == 1 /* { */
195static char *fallbackList[] = {
196    BWTWO0DEV, BWTWO1DEV, BWTWO2DEV
197};
198#else /* }{ */
199static char *fallbackList[] = {
200#ifndef i386 /* { */
201    CGTWO0DEV, CGTWO1DEV, CGTWO2DEV,
202#if (MAXSCREENS == 4)
203    CGTWO3DEV,
204#endif
205#endif /* } */
206    CGTHREE0DEV,
207#ifndef i386 /* { */
208    CGTHREE1DEV, CGTHREE2DEV,
209#if (MAXSCREENS == 4)
210    CGTHREE3DEV,
211#endif
212#endif /* } */
213#ifdef FBTYPE_SUNFAST_COLOR /* { */
214    CGSIX0DEV, CGSIX1DEV, CGSIX2DEV,
215#if (MAXSCREENS == 4)
216    CGSIX3DEV,
217#endif
218#endif /* } */
219#ifndef i386 /* { */
220    CGFOUR0DEV, BWTWO0DEV, BWTWO1DEV, BWTWO2DEV,
221#if (MAXSCREENS == 4)
222    BWTWO3DEV,
223#endif
224#endif /* } */
225#if SUNMAXDEPTH > 8 /* { */
226    CGEIGHT0DEV,
227#if 0
228#ifdef XFBTYPE_TCX
229    TCX0DEV,
230#endif
231#endif
232#endif /* } */
233    "/dev/fb"
234};
235#endif /* } */
236
237#define FALLBACK_LIST_LEN sizeof fallbackList / sizeof fallbackList[0]
238
239fbFd sunFbs[MAXSCREENS];
240
241static PixmapFormatRec	formats[] = {
242    { 1, 1, BITMAP_SCANLINE_PAD	} /* 1-bit deep */
243#if SUNMAXDEPTH > 1
244    ,{ 8, 8, BITMAP_SCANLINE_PAD} /* 8-bit deep */
245#if SUNMAXDEPTH > 8
246    ,{ 12, 24, BITMAP_SCANLINE_PAD } /* 12-bit deep */
247    ,{ 24, 32, BITMAP_SCANLINE_PAD } /* 24-bit deep */
248#endif
249#endif
250};
251#define NUMFORMATS	(sizeof formats)/(sizeof formats[0])
252
253/*
254 * OpenFrameBuffer --
255 *	Open a frame buffer according to several rules.
256 *	Find the device to use by looking in the sunFbData table,
257 *	an XDEVICE envariable, a -dev switch or using /dev/fb if trying
258 *	to open screen 0 and all else has failed.
259 *
260 * Results:
261 *	The fd of the framebuffer.
262 */
263static int
264OpenFrameBuffer(
265    char		*device,	/* e.g. "/dev/cgtwo0" */
266    int			screen    	/* what screen am I going to be */
267)
268{
269    int			ret = TRUE;
270    struct fbgattr	*fbattr;
271    static int		devFbUsed;
272
273    sunFbs[screen].fd = -1;
274    if (strcmp (device, "/dev/fb") == 0 && devFbUsed)
275	return FALSE;
276    if (access (device, R_OK | W_OK) == -1)
277	return FALSE;
278    if ((sunFbs[screen].fd = open(device, O_RDWR, 0)) == -1)
279	ret = FALSE;
280    else {
281	fbattr = (struct fbgattr *) xalloc (sizeof (struct fbgattr));
282	if (ioctl(sunFbs[screen].fd, FBIOGATTR, fbattr) == -1) {
283	    /*
284		This is probably a bwtwo; the $64,000 question is:
285		is it the mono plane of a cgfour, or is it really a
286		real bwtwo?  If there is only a cgfour in the box or
287		only a bwtwo in the box, then it isn't a problem.  If
288		it's a 3/60, which has a bwtwo on the mother board *and*
289		a cgfour, then things get tricky because there's no way
290		to tell if the bwtwo is really being emulated by the cgfour.
291	    */
292	    xfree (fbattr);
293	    fbattr = NULL;
294	    if (ioctl(sunFbs[screen].fd, FBIOGTYPE, &sunFbs[screen].info) == -1) {
295		Error("unable to get frame buffer attributes");
296		(void) close(sunFbs[screen].fd);
297		sunFbs[screen].fd = -1;
298		return FALSE;
299	    }
300	}
301	if (ret) {
302	    devFbUsed = TRUE;
303	    if (fbattr) {
304		if (fbattr->fbtype.fb_type >= XFBTYPE_LASTPLUSONE) {
305		    ErrorF ("%s is an unknown framebuffer type\n", device);
306		    (void) close(sunFbs[screen].fd);
307		    sunFbs[screen].fd = -1;
308		    return FALSE;
309		}
310		sunFbs[screen].info = fbattr->fbtype;
311	    }
312	    sunFbs[screen].fbPriv = (pointer) fbattr;
313	    if (fbattr && !sunFbData[fbattr->fbtype.fb_type].init) {
314		int _i;
315		ret = FALSE;
316		for (_i = 0; _i < FB_ATTR_NEMUTYPES; _i++) {
317		    if (sunFbData[fbattr->emu_types[_i]].init) {
318			sunFbs[screen].info.fb_type = fbattr->emu_types[_i];
319			ret = TRUE;
320			if (sunFbInfo)
321			    ErrorF ("%s is emulating a %s\n", device,
322				sunFbData[fbattr->fbtype.fb_type].name);
323			break;
324		    }
325		}
326	    }
327	    if (sunFbInfo)
328		ErrorF ("%s is really a %s\n", device,
329		    sunFbData[fbattr ? fbattr->fbtype.fb_type : sunFbs[screen].info.fb_type].name);
330	}
331    }
332    if (!ret)
333	sunFbs[screen].fd = -1;
334    return ret;
335}
336
337/*-
338 *-----------------------------------------------------------------------
339 * SigIOHandler --
340 *	Signal handler for SIGIO - input is available.
341 *
342 * Results:
343 *	sunSigIO is set - ProcessInputEvents() will be called soon.
344 *
345 * Side Effects:
346 *	None
347 *
348 *-----------------------------------------------------------------------
349 */
350/*ARGSUSED*/
351static void
352SigIOHandler(int sig)
353{
354    int olderrno = errno;
355    sunEnqueueEvents ();
356    errno = olderrno;
357}
358
359/*-
360 *-----------------------------------------------------------------------
361 * sunNonBlockConsoleOff --
362 *	Turn non-blocking mode on the console off, so you don't get logged
363 *	out when the server exits.
364 *
365 * Results:
366 *	None.
367 *
368 * Side Effects:
369 *	None.
370 *
371 *-----------------------------------------------------------------------
372 */
373void
374sunNonBlockConsoleOff(
375#if defined(SVR4) || defined(CSRG_BASED)
376    void
377#else
378    char* arg
379#endif
380)
381{
382    register int i;
383
384    i = fcntl(2, F_GETFL, 0);
385    if (i >= 0)
386	(void) fcntl(2, F_SETFL, i & ~FNDELAY);
387}
388
389static char**
390GetDeviceList(int argc, char **argv)
391{
392    int		i;
393    char	*envList = NULL;
394    char	*cmdList = NULL;
395    char	**deviceList = (char **)NULL;
396
397    for (i = 1; i < argc; i++)
398	if (strcmp (argv[i], "-dev") == 0 && i+1 < argc) {
399	    cmdList = argv[i + 1];
400	    break;
401	}
402    if (!cmdList)
403	envList = getenv ("XDEVICE");
404
405    if (cmdList || envList) {
406	char	*_tmpa;
407	char	*_tmpb;
408	int	_i1;
409	deviceList = (char **) xalloc ((MAXSCREENS + 1) * sizeof (char *));
410	_tmpa = (cmdList) ? cmdList : envList;
411	for (_i1 = 0; _i1 < MAXSCREENS; _i1++) {
412	    _tmpb = strtok (_tmpa, ":");
413	    if (_tmpb)
414		deviceList[_i1] = _tmpb;
415	    else
416		deviceList[_i1] = NULL;
417	    _tmpa = NULL;
418	}
419	deviceList[MAXSCREENS] = NULL;
420    }
421    if (!deviceList) {
422	/* no environment and no cmdline, so default */
423	deviceList =
424	    (char **) xalloc ((FALLBACK_LIST_LEN + 1) * sizeof (char *));
425	for (i = 0; i < FALLBACK_LIST_LEN; i++)
426	    deviceList[i] = fallbackList[i];
427	deviceList[FALLBACK_LIST_LEN] = NULL;
428    }
429    return deviceList;
430}
431
432static void
433getKbdType(void)
434{
435/*
436 * The Sun 386i has system include files that preclude this pre SunOS 4.1
437 * test for the presence of a type 4 keyboard however it really doesn't
438 * matter since no 386i has ever been shipped with a type 3 keyboard.
439 * SunOS 4.1 no longer needs this kludge.
440 */
441#if !defined(i386) && !defined(KIOCGKEY)
442#define TYPE4KEYBOARDOVERRIDE
443#endif
444
445    int ii;
446
447    for (ii = 0; ii < 3; ii++) {
448	sunKbdWait();
449	(void) ioctl (sunKbdPriv.fd, KIOCTYPE, &sunKbdPriv.type);
450#ifdef TYPE4KEYBOARDOVERRIDE
451	/*
452	 * Magic. Look for a key which is non-existent on a real type
453	 * 3 keyboard but does exist on a type 4 keyboard.
454	 */
455	if (sunKbdPriv.type == KB_SUN3) {
456	    struct kiockeymap key;
457
458	    key.kio_tablemask = 0;
459	    key.kio_station = 118;
460	    if (ioctl(sunKbdPriv.fd, KIOCGKEY, &key) == -1) {
461		Error( "ioctl KIOCGKEY" );
462		FatalError("Can't KIOCGKEY on fd %d\n", sunKbdPriv.fd);
463	    }
464	    if (key.kio_entry != HOLE)
465		sunKbdPriv.type = KB_SUN4;
466	}
467#endif
468	switch (sunKbdPriv.type) {
469	case KB_SUN2:
470	case KB_SUN3:
471	case KB_SUN4: return;
472	default:
473	    sunChangeKbdTranslation(sunKbdPriv.fd, FALSE);
474	    continue;
475	}
476    }
477    FatalError ("Unsupported keyboard type %d\n", sunKbdPriv.type);
478}
479
480void
481OsVendorInit(void)
482{
483    static int inited;
484    if (!inited) {
485#ifndef i386
486	struct rlimit rl;
487
488	/*
489	 * one per client, one per screen, one per listen endpoint,
490	 * keyboard, mouse, and stderr
491	 */
492	int maxfds = MAXCLIENTS + MAXSCREENS + 5;
493
494	if (getrlimit (RLIMIT_NOFILE, &rl) == 0) {
495	    rl.rlim_cur = maxfds < rl.rlim_max ? maxfds : rl.rlim_max;
496	    (void) setrlimit (RLIMIT_NOFILE, &rl);
497	}
498#endif
499	sunKbdPriv.fd = open ("/dev/kbd", O_RDWR, 0);
500	if (sunKbdPriv.fd < 0)
501	    FatalError ("Cannot open /dev/kbd, error %d\n", errno);
502	sunPtrPriv.fd = open ("/dev/mouse", O_RDWR, 0);
503	if (sunPtrPriv.fd < 0)
504	    FatalError ("Cannot open /dev/mouse, error %d\n", errno);
505	getKbdType ();
506	if (sunKbdPriv.type == KB_SUN4) {
507	    (void) ioctl (sunKbdPriv.fd, KIOCLAYOUT, &sunKbdPriv.layout);
508	    if (sunKbdPriv.layout < 0 ||
509		sunKbdPriv.layout > sunMaxLayout ||
510		sunType4KeyMaps[sunKbdPriv.layout] == NULL)
511		FatalError ("Unsupported keyboard type 4 layout %d\n",
512			    sunKbdPriv.layout);
513	    sunKeySyms[KB_SUN4].map = sunType4KeyMaps[sunKbdPriv.layout];
514	    sunModMaps[KB_SUN4] = sunType4ModMaps[sunKbdPriv.layout];
515        }
516	inited = 1;
517    }
518}
519
520void
521OsVendorFatalError(void)
522{
523}
524
525/*-
526 *-----------------------------------------------------------------------
527 * InitOutput --
528 *	Initialize screenInfo for all actually accessible framebuffers.
529 *	The
530 *
531 * Results:
532 *	screenInfo init proc field set
533 *
534 * Side Effects:
535 *	None
536 *
537 *-----------------------------------------------------------------------
538 */
539
540void
541InitOutput(ScreenInfo *pScreenInfo, int argc, char **argv)
542{
543    int     	i, scr;
544    int		nonBlockConsole = 0;
545    char	**devList;
546    static int	setup_on_exit = 0;
547
548    if (!monitorResolution)
549	monitorResolution = 90;
550    if (RunFromSigStopParent)
551	nonBlockConsole = 1;
552    for (i = 1; i < argc; i++) {
553	if (!strcmp(argv[i],"-debug"))
554	    nonBlockConsole = 0;
555    }
556
557    /*
558     *	Writes to /dev/console can block - causing an
559     *	excess of error messages to hang the server in
560     *	deadlock.  So.......
561     */
562    if (nonBlockConsole) {
563	if (!setup_on_exit) {
564#if defined(SVR4) || defined(CSRG_BASED)
565	    if (atexit(sunNonBlockConsoleOff))
566#else
567	    if (on_exit(sunNonBlockConsoleOff, (char *)0))
568#endif
569		ErrorF("InitOutput: can't register NBIO exit handler\n");
570
571	    setup_on_exit = 1;
572	}
573	i = fcntl(2, F_GETFL, 0);
574	if (i >= 0)
575	    i = fcntl(2, F_SETFL, i | FNDELAY);
576	if (i < 0) {
577	    Error("fcntl");
578	    ErrorF("InitOutput: can't put stderr in non-block mode\n");
579	}
580    }
581    pScreenInfo->imageByteOrder = IMAGE_BYTE_ORDER;
582    pScreenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT;
583    pScreenInfo->bitmapScanlinePad = BITMAP_SCANLINE_PAD;
584    pScreenInfo->bitmapBitOrder = BITMAP_BIT_ORDER;
585
586    pScreenInfo->numPixmapFormats = NUMFORMATS;
587    for (i=0; i< NUMFORMATS; i++)
588        pScreenInfo->formats[i] = formats[i];
589    if (!sunDevsInited) {
590	/* first time ever */
591	for (scr = 0; scr < MAXSCREENS; scr++)
592	    sunFbs[scr].fd = -1;
593	devList = GetDeviceList (argc, argv);
594	for (i = 0, scr = 0; devList[i] != NULL && scr < MAXSCREENS; i++)
595	    if (OpenFrameBuffer (devList[i], scr))
596		scr++;
597	sunDevsInited = TRUE;
598	xfree (devList);
599    }
600    for (scr = 0; scr < MAXSCREENS; scr++)
601	if (sunFbs[scr].fd != -1)
602	    (void) AddScreen (sunFbData[sunFbs[scr].info.fb_type].init,
603			      argc, argv);
604    (void) OsSignal(SIGWINCH, SIG_IGN);
605}
606
607/*-
608 *-----------------------------------------------------------------------
609 * InitInput --
610 *	Initialize all supported input devices...what else is there
611 *	besides pointer and keyboard?
612 *
613 * Results:
614 *	None.
615 *
616 * Side Effects:
617 *	Two DeviceRec's are allocated and registered as the system pointer
618 *	and keyboard devices.
619 *
620 *-----------------------------------------------------------------------
621 */
622void
623InitInput(int argc, char **argv)
624{
625    int rc;
626
627    rc = AllocDevicePair(serverClient, "sun",
628			 &sunPointerDevice, &sunKeyboardDevice,
629			 sunMouseProc, sunKbdProc, FALSE);
630    if (rc != Success)
631	FatalError("Failed to init sun default input devices.\n");
632
633    GetEventList(&sunEvents);
634
635    (void)mieqInit();
636#define SET_FLOW(fd) fcntl(fd, F_SETFL, FNDELAY | FASYNC)
637#ifdef SVR4
638    (void) OsSignal(SIGPOLL, SigIOHandler);
639#define WANT_SIGNALS(fd) ioctl(fd, I_SETSIG, S_INPUT | S_HIPRI)
640#else
641    (void) OsSignal(SIGIO, SigIOHandler);
642#define WANT_SIGNALS(fd) fcntl(fd, F_SETOWN, getpid())
643#endif
644    if (sunKbdPriv.fd >= 0) {
645	if (SET_FLOW(sunKbdPriv.fd) == -1 || WANT_SIGNALS(sunKbdPriv.fd) == -1) {
646	    (void) close (sunKbdPriv.fd);
647	    sunKbdPriv.fd = -1;
648	    FatalError("Async kbd I/O failed in InitInput");
649	}
650    }
651    if (sunPtrPriv.fd >= 0) {
652	if (SET_FLOW(sunPtrPriv.fd) == -1 || WANT_SIGNALS(sunPtrPriv.fd) == -1) {
653	    (void) close (sunPtrPriv.fd);
654	    sunPtrPriv.fd = -1;
655	    FatalError("Async mouse I/O failed in InitInput");
656	}
657    }
658}
659
660void
661CloseInput(void)
662{
663}
664
665#if SUNMAXDEPTH == 8
666
667Bool
668sunCfbSetupScreen(
669    ScreenPtr pScreen,
670    pointer pbits,		/* pointer to screen bitmap */
671    int xsize,			/* in pixels */
672    int ysize,			/* in pixels */
673    int dpix,			/* dots per inch */
674    int dpiy,			/* dots per inch */
675    int width,			/* pixel width of frame buffer */
676    int	bpp			/* bits per pixel of root */
677)
678{
679    return fbSetupScreen(pScreen, pbits, xsize, ysize, dpix, dpiy,
680			 width, bpp);
681}
682
683Bool
684sunCfbFinishScreenInit(
685    ScreenPtr pScreen,
686    pointer pbits,		/* pointer to screen bitmap */
687    int xsize,			/* in pixels */
688    int ysize,			/* in pixels */
689    int dpix,			/* dots per inch */
690    int dpiy,			/* dots per inch */
691    int width,			/* pixel width of frame buffer */
692    int bpp			/* bits per pixel of root */
693)
694{
695    return fbFinishScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy,
696			      width, bpp);
697}
698
699Bool
700sunCfbScreenInit(
701    ScreenPtr pScreen,
702    pointer pbits,		/* pointer to screen bitmap */
703    int xsize,			/* in pixels */
704    int ysize,			/* in pixels */
705    int dpix,			/* dots per inch */
706    int dpiy,			/* dots per inch */
707    int width,			/* pixel width of frame buffer */
708    int bpp			/* bits per pixel of root */
709)
710{
711    return fbScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width, bpp);
712}
713
714#else /* SUNMAXDEPTH != 8 */
715#if SUNMAXDEPTH == 32
716
717static Bool
718sunCfbCreateGC(GCPtr pGC)
719{
720    return fbCreateGC (pGC);
721}
722
723static void
724sunCfbGetSpans(
725    DrawablePtr		pDrawable,	/* drawable from which to get bits */
726    int			wMax,		/* largest value of all *pwidths */
727    DDXPointPtr		ppt,		/* points to start copying from */
728    int			*pwidth,	/* list of number of bits to copy */
729    int			nspans,		/* number of scanlines to copy */
730    char		*pdstStart	/* where to put the bits */
731)
732{
733    fbGetSpans(pDrawable, wMax, ppt, pwidth, nspans, pdstStart);
734}
735
736static void
737sunCfbGetImage(DrawablePtr pDrawable, int sx, int sy, int w, int h, unsigned int format, unsigned long planeMask, char *pdstLine)
738{
739    fbGetImage(pDrawable, sx, sy, w, h, format, planeMask, pdstLine);
740}
741
742Bool
743sunCfbSetupScreen(
744    ScreenPtr pScreen,
745    pointer pbits,		/* pointer to screen bitmap */
746    int xsize,			/* in pixels */
747    int ysize,			/* in pixels */
748    int dpix,			/* dots per inch */
749    int dpiy,			/* dots per inch */
750    int width,			/* pixel width of frame buffer */
751    int	bpp			/* bits per pixel of root */
752)
753{
754    int ret;
755
756    ret = fbSetupScreen(pScreen, pbits, xsize, ysize, dpix, dpiy, width, bpp);
757    pScreen->CreateGC = sunCfbCreateGC;
758    pScreen->GetImage = sunCfbGetImage;
759    pScreen->GetSpans = sunCfbGetSpans;
760    return ret;
761}
762
763/* Adapt cfb logic */
764
765Bool
766sunCfbFinishScreenInit(
767    ScreenPtr pScreen,
768    pointer pbits,		/* pointer to screen bitmap */
769    int xsize,			/* in pixels */
770    int ysize,			/* in pixels */
771    int dpix,			/* dots per inch */
772    int dpiy,			/* dots per inch */
773    int width,			/* pixel width of frame buffer */
774    int bpp
775)
776{
777    VisualPtr	visuals;
778    int		nvisuals;
779    DepthPtr	depths;
780    int		ndepths;
781    VisualID	defaultVisual;
782    int		rootdepth = 0;
783
784    if (!fbInitVisuals(&visuals, &depths, &nvisuals, &ndepths,
785		       &rootdepth, &defaultVisual, 1 << (bpp - 1), 8))
786	return FALSE;
787    if (! miScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width,
788			rootdepth, ndepths, depths,
789			defaultVisual, nvisuals, visuals))
790	return FALSE;
791    pScreen->CloseScreen = fbCloseScreen;
792    return TRUE;
793}
794
795
796Bool
797sunCfbScreenInit(
798    ScreenPtr pScreen,
799    pointer pbits,		/* pointer to screen bitmap */
800    int xsize,			/* in pixels */
801    int ysize,			/* in pixels */
802    int dpix,			/* dots per inch */
803    int dpiy,			/* dots per inch */
804    int width,			/* pixel width of frame buffer */
805    int bpp
806)
807{
808    if (!sunCfbSetupScreen(pScreen, pbits, xsize, ysize, dpix, dpiy,
809			   width, bpp))
810	return FALSE;
811    return sunCfbFinishScreenInit(pScreen, pbits, xsize, ysize, dpix,
812				  dpiy, width, bpp);
813}
814
815#endif  /* SUNMAXDEPTH == 32 */
816#endif  /* SUNMAXDEPTH */
817