sunInit.c revision cb17d216
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 } 515 inited = 1; 516 } 517} 518 519void 520OsVendorFatalError(void) 521{ 522} 523 524/*- 525 *----------------------------------------------------------------------- 526 * InitOutput -- 527 * Initialize screenInfo for all actually accessible framebuffers. 528 * The 529 * 530 * Results: 531 * screenInfo init proc field set 532 * 533 * Side Effects: 534 * None 535 * 536 *----------------------------------------------------------------------- 537 */ 538 539void 540InitOutput(ScreenInfo *pScreenInfo, int argc, char **argv) 541{ 542 int i, scr; 543 int nonBlockConsole = 0; 544 char **devList; 545 static int setup_on_exit = 0; 546 547 if (!monitorResolution) 548 monitorResolution = 90; 549 if (RunFromSigStopParent) 550 nonBlockConsole = 1; 551 for (i = 1; i < argc; i++) { 552 if (!strcmp(argv[i],"-debug")) 553 nonBlockConsole = 0; 554 } 555 556 /* 557 * Writes to /dev/console can block - causing an 558 * excess of error messages to hang the server in 559 * deadlock. So....... 560 */ 561 if (nonBlockConsole) { 562 if (!setup_on_exit) { 563#if defined(SVR4) || defined(CSRG_BASED) 564 if (atexit(sunNonBlockConsoleOff)) 565#else 566 if (on_exit(sunNonBlockConsoleOff, (char *)0)) 567#endif 568 ErrorF("InitOutput: can't register NBIO exit handler\n"); 569 570 setup_on_exit = 1; 571 } 572 i = fcntl(2, F_GETFL, 0); 573 if (i >= 0) 574 i = fcntl(2, F_SETFL, i | FNDELAY); 575 if (i < 0) { 576 Error("fcntl"); 577 ErrorF("InitOutput: can't put stderr in non-block mode\n"); 578 } 579 } 580 pScreenInfo->imageByteOrder = IMAGE_BYTE_ORDER; 581 pScreenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT; 582 pScreenInfo->bitmapScanlinePad = BITMAP_SCANLINE_PAD; 583 pScreenInfo->bitmapBitOrder = BITMAP_BIT_ORDER; 584 585 pScreenInfo->numPixmapFormats = NUMFORMATS; 586 for (i=0; i< NUMFORMATS; i++) 587 pScreenInfo->formats[i] = formats[i]; 588 if (!sunDevsInited) { 589 /* first time ever */ 590 for (scr = 0; scr < MAXSCREENS; scr++) 591 sunFbs[scr].fd = -1; 592 devList = GetDeviceList (argc, argv); 593 for (i = 0, scr = 0; devList[i] != NULL && scr < MAXSCREENS; i++) 594 if (OpenFrameBuffer (devList[i], scr)) 595 scr++; 596 sunDevsInited = TRUE; 597 xfree (devList); 598 } 599 for (scr = 0; scr < MAXSCREENS; scr++) 600 if (sunFbs[scr].fd != -1) 601 (void) AddScreen (sunFbData[sunFbs[scr].info.fb_type].init, 602 argc, argv); 603 (void) OsSignal(SIGWINCH, SIG_IGN); 604} 605 606/*- 607 *----------------------------------------------------------------------- 608 * InitInput -- 609 * Initialize all supported input devices...what else is there 610 * besides pointer and keyboard? 611 * 612 * Results: 613 * None. 614 * 615 * Side Effects: 616 * Two DeviceRec's are allocated and registered as the system pointer 617 * and keyboard devices. 618 * 619 *----------------------------------------------------------------------- 620 */ 621void 622InitInput(int argc, char **argv) 623{ 624 int rc; 625 626 rc = AllocDevicePair(serverClient, "sun", 627 &sunPointerDevice, &sunKeyboardDevice, 628 sunMouseProc, sunKbdProc, FALSE); 629 if (rc != Success) 630 FatalError("Failed to init sun default input devices.\n"); 631 632 GetEventList(&sunEvents); 633 634 (void)mieqInit(); 635#define SET_FLOW(fd) fcntl(fd, F_SETFL, FNDELAY | FASYNC) 636#ifdef SVR4 637 (void) OsSignal(SIGPOLL, SigIOHandler); 638#define WANT_SIGNALS(fd) ioctl(fd, I_SETSIG, S_INPUT | S_HIPRI) 639#else 640 (void) OsSignal(SIGIO, SigIOHandler); 641#define WANT_SIGNALS(fd) fcntl(fd, F_SETOWN, getpid()) 642#endif 643 if (sunKbdPriv.fd >= 0) { 644 if (SET_FLOW(sunKbdPriv.fd) == -1 || WANT_SIGNALS(sunKbdPriv.fd) == -1) { 645 (void) close (sunKbdPriv.fd); 646 sunKbdPriv.fd = -1; 647 FatalError("Async kbd I/O failed in InitInput"); 648 } 649 } 650 if (sunPtrPriv.fd >= 0) { 651 if (SET_FLOW(sunPtrPriv.fd) == -1 || WANT_SIGNALS(sunPtrPriv.fd) == -1) { 652 (void) close (sunPtrPriv.fd); 653 sunPtrPriv.fd = -1; 654 FatalError("Async mouse I/O failed in InitInput"); 655 } 656 } 657} 658 659void 660CloseInput(void) 661{ 662} 663 664#if SUNMAXDEPTH == 8 665 666Bool 667sunCfbSetupScreen( 668 ScreenPtr pScreen, 669 pointer pbits, /* pointer to screen bitmap */ 670 int xsize, /* in pixels */ 671 int ysize, /* in pixels */ 672 int dpix, /* dots per inch */ 673 int dpiy, /* dots per inch */ 674 int width, /* pixel width of frame buffer */ 675 int bpp /* bits per pixel of root */ 676) 677{ 678 return fbSetupScreen(pScreen, pbits, xsize, ysize, dpix, dpiy, 679 width, bpp); 680} 681 682Bool 683sunCfbFinishScreenInit( 684 ScreenPtr pScreen, 685 pointer pbits, /* pointer to screen bitmap */ 686 int xsize, /* in pixels */ 687 int ysize, /* in pixels */ 688 int dpix, /* dots per inch */ 689 int dpiy, /* dots per inch */ 690 int width, /* pixel width of frame buffer */ 691 int bpp /* bits per pixel of root */ 692) 693{ 694 return fbFinishScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, 695 width, bpp); 696} 697 698Bool 699sunCfbScreenInit( 700 ScreenPtr pScreen, 701 pointer pbits, /* pointer to screen bitmap */ 702 int xsize, /* in pixels */ 703 int ysize, /* in pixels */ 704 int dpix, /* dots per inch */ 705 int dpiy, /* dots per inch */ 706 int width, /* pixel width of frame buffer */ 707 int bpp /* bits per pixel of root */ 708) 709{ 710 return fbScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width, bpp); 711} 712 713#else /* SUNMAXDEPTH != 8 */ 714#if SUNMAXDEPTH == 32 715 716static Bool 717sunCfbCreateGC(GCPtr pGC) 718{ 719 return fbCreateGC (pGC); 720} 721 722static void 723sunCfbGetSpans( 724 DrawablePtr pDrawable, /* drawable from which to get bits */ 725 int wMax, /* largest value of all *pwidths */ 726 DDXPointPtr ppt, /* points to start copying from */ 727 int *pwidth, /* list of number of bits to copy */ 728 int nspans, /* number of scanlines to copy */ 729 char *pdstStart /* where to put the bits */ 730) 731{ 732 fbGetSpans(pDrawable, wMax, ppt, pwidth, nspans, pdstStart); 733} 734 735static void 736sunCfbGetImage(DrawablePtr pDrawable, int sx, int sy, int w, int h, unsigned int format, unsigned long planeMask, char *pdstLine) 737{ 738 fbGetImage(pDrawable, sx, sy, w, h, format, planeMask, pdstLine); 739} 740 741Bool 742sunCfbSetupScreen( 743 ScreenPtr pScreen, 744 pointer pbits, /* pointer to screen bitmap */ 745 int xsize, /* in pixels */ 746 int ysize, /* in pixels */ 747 int dpix, /* dots per inch */ 748 int dpiy, /* dots per inch */ 749 int width, /* pixel width of frame buffer */ 750 int bpp /* bits per pixel of root */ 751) 752{ 753 int ret; 754 755 ret = fbSetupScreen(pScreen, pbits, xsize, ysize, dpix, dpiy, width, bpp); 756 pScreen->CreateGC = sunCfbCreateGC; 757 pScreen->GetImage = sunCfbGetImage; 758 pScreen->GetSpans = sunCfbGetSpans; 759 return ret; 760} 761 762/* Adapt cfb logic */ 763 764Bool 765sunCfbFinishScreenInit( 766 ScreenPtr pScreen, 767 pointer pbits, /* pointer to screen bitmap */ 768 int xsize, /* in pixels */ 769 int ysize, /* in pixels */ 770 int dpix, /* dots per inch */ 771 int dpiy, /* dots per inch */ 772 int width, /* pixel width of frame buffer */ 773 int bpp 774) 775{ 776 VisualPtr visuals; 777 int nvisuals; 778 DepthPtr depths; 779 int ndepths; 780 VisualID defaultVisual; 781 int rootdepth = 0; 782 783 if (!fbInitVisuals(&visuals, &depths, &nvisuals, &ndepths, 784 &rootdepth, &defaultVisual, 1 << (bpp - 1), 8)) 785 return FALSE; 786 if (! miScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width, 787 rootdepth, ndepths, depths, 788 defaultVisual, nvisuals, visuals)) 789 return FALSE; 790 pScreen->CloseScreen = fbCloseScreen; 791 return TRUE; 792} 793 794 795Bool 796sunCfbScreenInit( 797 ScreenPtr pScreen, 798 pointer pbits, /* pointer to screen bitmap */ 799 int xsize, /* in pixels */ 800 int ysize, /* in pixels */ 801 int dpix, /* dots per inch */ 802 int dpiy, /* dots per inch */ 803 int width, /* pixel width of frame buffer */ 804 int bpp 805) 806{ 807 if (!sunCfbSetupScreen(pScreen, pbits, xsize, ysize, dpix, dpiy, 808 width, bpp)) 809 return FALSE; 810 return sunCfbFinishScreenInit(pScreen, pbits, xsize, ysize, dpix, 811 dpiy, width, bpp); 812} 813 814#endif /* SUNMAXDEPTH == 32 */ 815#endif /* SUNMAXDEPTH */ 816