Annotation of researchv9/X11/src/X.V11R1/server/ddx/sun/sunCG4C.c, revision 1.1.1.1

1.1       root        1: /*-
                      2:  * sunCG4C.c --
                      3:  *     Functions to support the sun CG4 board as a memory frame buffer.
                      4:  */
                      5: 
                      6: /************************************************************
                      7: Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA.
                      8: 
                      9:                     All Rights Reserved
                     10: 
                     11: Permission  to  use,  copy,  modify,  and  distribute   this
                     12: software  and  its documentation for any purpose and without
                     13: fee is hereby granted, provided that the above copyright no-
                     14: tice  appear  in all copies and that both that copyright no-
                     15: tice and this permission notice appear in  supporting  docu-
                     16: mentation,  and  that the names of Sun or MIT not be used in
                     17: advertising or publicity pertaining to distribution  of  the
                     18: software  without specific prior written permission. Sun and
                     19: M.I.T. make no representations about the suitability of this
                     20: software for any purpose. It is provided "as is" without any
                     21: express or implied warranty.
                     22: 
                     23: SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO  THIS  SOFTWARE,
                     24: INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
                     25: NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE  LI-
                     26: ABLE  FOR  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
                     27: ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,  DATA  OR
                     28: PROFITS,  WHETHER  IN  AN  ACTION OF CONTRACT, NEGLIGENCE OR
                     29: OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
                     30: THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     31: 
                     32: ********************************************************/
                     33: 
                     34: #ifndef        lint
                     35: static char sccsid[] = "@(#)sunCG4C.c  1.4 6/1/87 Copyright 1987 Sun Micro";
                     36: #endif
                     37: 
                     38: #include    "sun.h"
                     39: 
                     40: #include    <sys/mman.h>
                     41: #include    <pixrect/memreg.h>
                     42: #include    <sundev/cg4reg.h>
                     43: #include    "colormap.h"
                     44: #include    "colormapst.h"
                     45: #include    "resource.h"
                     46: #include    <struct.h>
                     47: 
                     48: /*-
                     49:  * The cg4 frame buffer is divided into several pieces.
                     50:  *     1) an array of 8-bit pixels
                     51:  *     2) a one-bit deep overlay plane
                     52:  *     3) an enable plane
                     53:  *     4) a colormap and status register
                     54:  *
                     55:  * XXX - put the cursor in the overlay plane
                     56:  */
                     57: #define        CG4_HEIGHT      900
                     58: #define        CG4_WIDTH       1152
                     59: 
                     60: typedef struct cg4c {
                     61:        u_char mpixel[128*1024];                /* bit-per-pixel memory */
                     62:        u_char epixel[128*1024];                /* enable plane */
                     63:        u_char cpixel[CG4_HEIGHT][CG4_WIDTH];   /* byte-per-pixel memory */
                     64: } CG4C, CG4CRec, *CG4CPtr;
                     65: 
                     66: #define CG4C_IMAGE(fb)     ((caddr_t)(&(fb)->cpixel))
                     67: #define CG4C_IMAGEOFF      ((off_t)0x0)
                     68: #define CG4C_IMAGELEN      (((CG4_HEIGHT*CG4_WIDTH + 8191)/8192)*8192)
                     69: #define        CG4C_MONO(fb)       ((caddr_t)(&(fb)->mpixel))
                     70: #define        CG4C_MONOLEN        (128*1024)
                     71: #define        CG4C_ENABLE(fb)     ((caddr_t)(&(fb)->epixel))
                     72: #define        CG4C_ENBLEN         CG4C_MONOLEN
                     73: 
                     74: static CG4CPtr CG4Cfb = NULL;
                     75: 
                     76: /* XXX - next line means only one CG4 - fix this */
                     77: static ColormapPtr sunCG4CInstalledMap;
                     78: 
                     79: extern int TellLostMap(), TellGainedMap();
                     80: 
                     81: static void
                     82: sunCG4CUpdateColormap(pScreen, index, count, rmap, gmap, bmap)
                     83:     ScreenPtr  pScreen;
                     84:     int                index, count;
                     85:     u_char     *rmap, *gmap, *bmap;
                     86: {
                     87:     struct fbcmap sunCmap;
                     88: 
                     89:     sunCmap.index = index;
                     90:     sunCmap.count = count;
                     91:     sunCmap.red = &rmap[index];
                     92:     sunCmap.green = &gmap[index];
                     93:     sunCmap.blue = &bmap[index];
                     94: 
                     95: #ifdef SUN_WINDOWS
                     96:     if (sunUseSunWindows()) {
                     97:        static Pixwin *pw = 0;
                     98: 
                     99:        if (! pw) {
                    100:            if ( ! (pw = pw_open(windowFd)) )
                    101:                FatalError( "sunCG4CUpdateColormap: pw_open failed\n" );
                    102:            pw_setcmsname(pw, "X.V11");
                    103:        }
                    104:        pw_putcolormap(
                    105:            pw, index, count, &rmap[index], &gmap[index], &bmap[index]);
                    106:     }
                    107: #endif SUN_WINDOWS
                    108: 
                    109:     if (ioctl(sunFbs[pScreen->myNum].fd, FBIOPUTCMAP, &sunCmap) < 0) {
                    110:        perror("sunCG4CUpdateColormap");
                    111:        FatalError( "sunCG4CUpdateColormap: FBIOPUTCMAP failed\n" );
                    112:     }
                    113: }
                    114: 
                    115: /*-
                    116:  *-----------------------------------------------------------------------
                    117:  * sunCG4CSaveScreen --
                    118:  *     Preserve the color screen by turning on or off the video
                    119:  *
                    120:  * Results:
                    121:  *     None.
                    122:  *
                    123:  * Side Effects:
                    124:  *     Video state is switched
                    125:  *
                    126:  *-----------------------------------------------------------------------
                    127:  */
                    128: static Bool
                    129: sunCG4CSaveScreen (pScreen, on)
                    130:     ScreenPtr    pScreen;
                    131:     Bool         on;
                    132: {
                    133:     int                state = on;
                    134: 
                    135:     switch (on) {
                    136:     case SCREEN_SAVER_FORCER:
                    137:        SetTimeSinceLastInputEvent();
                    138:        screenSaved = FALSE;
                    139:        state = 1;
                    140:        break;
                    141:     case SCREEN_SAVER_OFF:
                    142:        screenSaved = FALSE;
                    143:        state = 1;
                    144:        break;
                    145:     case SCREEN_SAVER_ON:
                    146:     default:
                    147:        screenSaved = TRUE;
                    148:        state = 0;
                    149:        break;
                    150:     }
                    151:     (void) ioctl(sunFbs[pScreen->myNum].fd, FBIOSVIDEO, &state);
                    152:     return( TRUE );
                    153: }
                    154: 
                    155: /*-
                    156:  *-----------------------------------------------------------------------
                    157:  * sunCG4CCloseScreen --
                    158:  *     called to ensure video is enabled when server exits.
                    159:  *
                    160:  * Results:
                    161:  *     Screen is unsaved.
                    162:  *
                    163:  * Side Effects:
                    164:  *     None
                    165:  *
                    166:  *-----------------------------------------------------------------------
                    167:  */
                    168: /*ARGSUSED*/
                    169: static Bool
                    170: sunCG4CCloseScreen(i, pScreen)
                    171:     int                i;
                    172:     ScreenPtr  pScreen;
                    173: {
                    174:     sunCG4CInstalledMap = NULL;
                    175:     return (pScreen->SaveScreen(pScreen, SCREEN_SAVER_OFF));
                    176: }
                    177: 
                    178: /*-
                    179:  *-----------------------------------------------------------------------
                    180:  * sunCG4CInstallColormap --
                    181:  *     Install given colormap.
                    182:  *
                    183:  * Results:
                    184:  *     None
                    185:  *
                    186:  * Side Effects:
                    187:  *     Existing map is uninstalled.
                    188:  *     All clients requesting ColormapNotify are notified
                    189:  *
                    190:  *-----------------------------------------------------------------------
                    191:  */
                    192: static void
                    193: sunCG4CInstallColormap(cmap)
                    194:     ColormapPtr        cmap;
                    195: {
                    196:     register int i;
                    197:     register Entry *pent = cmap->red;
                    198:     u_char       rmap[256], gmap[256], bmap[256];
                    199: 
                    200:     if (cmap == sunCG4CInstalledMap)
                    201:        return;
                    202:     if (sunCG4CInstalledMap)
                    203:        WalkTree(sunCG4CInstalledMap->pScreen, TellLostMap,
                    204:                 (char *) &(sunCG4CInstalledMap->mid));
                    205:     for (i = 0; i < cmap->pVisual->ColormapEntries; i++) {
                    206:        if (pent->fShared) {
                    207:            rmap[i] = pent->co.shco.red->color >> 8;
                    208:            gmap[i] = pent->co.shco.green->color >> 8;
                    209:            bmap[i] = pent->co.shco.blue->color >> 8;
                    210:        }
                    211:        else {
                    212:            rmap[i] = pent->co.local.red >> 8;
                    213:            gmap[i] = pent->co.local.green >> 8;
                    214:            bmap[i] = pent->co.local.blue >> 8;
                    215:        }
                    216:        pent++;
                    217:     }
                    218:     sunCG4CInstalledMap = cmap;
                    219:     sunCG4CUpdateColormap(cmap->pScreen, 0, 256, rmap, gmap, bmap);
                    220:     WalkTree(cmap->pScreen, TellGainedMap, (char *) &(cmap->mid));
                    221: }
                    222: 
                    223: /*-
                    224:  *-----------------------------------------------------------------------
                    225:  * sunCG4CUninstallColormap --
                    226:  *     Uninstall given colormap.
                    227:  *
                    228:  * Results:
                    229:  *     None
                    230:  *
                    231:  * Side Effects:
                    232:  *     default map is installed
                    233:  *     All clients requesting ColormapNotify are notified
                    234:  *
                    235:  *-----------------------------------------------------------------------
                    236:  */
                    237: static void
                    238: sunCG4CUninstallColormap(cmap)
                    239:     ColormapPtr        cmap;
                    240: {
                    241:     if (cmap == sunCG4CInstalledMap) {
                    242:        Colormap defMapID = cmap->pScreen->defColormap;
                    243: 
                    244:        if (cmap->mid != defMapID) {
                    245:            ColormapPtr defMap = (ColormapPtr) LookupID(defMapID, RT_COLORMAP, RC_CORE);
                    246: 
                    247:            if (defMap)
                    248:                sunCG4CInstallColormap(defMap);
                    249:            else
                    250:                ErrorF("sunCG4C: Can't find default colormap\n");
                    251:        }
                    252:     }
                    253: }
                    254: 
                    255: /*-
                    256:  *-----------------------------------------------------------------------
                    257:  * sunCG4CListInstalledColormaps --
                    258:  *     Fills in the list with the IDs of the installed maps
                    259:  *
                    260:  * Results:
                    261:  *     Returns the number of IDs in the list
                    262:  *
                    263:  * Side Effects:
                    264:  *     None
                    265:  *
                    266:  *-----------------------------------------------------------------------
                    267:  */
                    268: /*ARGSUSED*/
                    269: static int
                    270: sunCG4CListInstalledColormaps(pScreen, pCmapList)
                    271:     ScreenPtr  pScreen;
                    272:     Colormap   *pCmapList;
                    273: {
                    274:     *pCmapList = sunCG4CInstalledMap->mid;
                    275:     return (1);
                    276: }
                    277: 
                    278: 
                    279: /*-
                    280:  *-----------------------------------------------------------------------
                    281:  * sunCG4CStoreColors --
                    282:  *     Sets the pixels in pdefs into the specified map.
                    283:  *
                    284:  * Results:
                    285:  *     None
                    286:  *
                    287:  * Side Effects:
                    288:  *     None
                    289:  *
                    290:  *-----------------------------------------------------------------------
                    291:  */
                    292: static void
                    293: sunCG4CStoreColors(pmap, ndef, pdefs)
                    294:     ColormapPtr        pmap;
                    295:     int                ndef;
                    296:     xColorItem *pdefs;
                    297: {
                    298:     switch (pmap->class) {
                    299:     case PseudoColor:
                    300:        if (pmap == sunCG4CInstalledMap) {
                    301:            /* We only have a single colormap */
                    302:            u_char      rmap[256], gmap[256], bmap[256];
                    303: 
                    304:            while (ndef--) {
                    305:                register unsigned index = pdefs->pixel&0xff;
                    306: 
                    307:                /* PUTCMAP assumes colors to be assigned start at 0 */
                    308:                rmap[index] = (pdefs->red) >> 8;
                    309:                gmap[index] = (pdefs->green) >> 8;
                    310:                bmap[index] = (pdefs->blue) >> 8;
                    311:                sunCG4CUpdateColormap(pmap->pScreen,
                    312:                                      index, 1, rmap, gmap, bmap);
                    313:                pdefs++;
                    314:            }
                    315:        }
                    316:        break;
                    317:     case DirectColor:
                    318:     default:
                    319:        ErrorF("sunCG4CStoreColors: bad class %d\n", pmap->class);
                    320:        break;
                    321:     }
                    322: }
                    323: 
                    324: /*-
                    325:  *-----------------------------------------------------------------------
                    326:  * sunCG4CResolvePseudoColor --
                    327:  *     Adjust specified RGB values to closest values hardware can do.
                    328:  *
                    329:  * Results:
                    330:  *     Args are modified.
                    331:  *
                    332:  * Side Effects:
                    333:  *     None
                    334:  *
                    335:  *-----------------------------------------------------------------------
                    336:  */
                    337: /*ARGSUSED*/
                    338: static void
                    339: sunCG4CResolvePseudoColor(pRed, pGreen, pBlue, pVisual)
                    340:     CARD16     *pRed, *pGreen, *pBlue;
                    341:     VisualPtr  pVisual;
                    342: {
                    343:     *pRed &= 0xff00;
                    344:     *pGreen &= 0xff00;
                    345:     *pBlue &= 0xff00;
                    346: }
                    347: 
                    348: /*-
                    349:  *-----------------------------------------------------------------------
                    350:  * sunCG4CInit --
                    351:  *     Attempt to find and initialize a cg4 framebuffer used as mono
                    352:  *
                    353:  * Results:
                    354:  *     TRUE if everything went ok. FALSE if not.
                    355:  *
                    356:  * Side Effects:
                    357:  *     Most of the elements of the ScreenRec are filled in. Memory is
                    358:  *     allocated for the frame buffer and the buffer is mapped. The
                    359:  *     video is enabled for the frame buffer...
                    360:  *
                    361:  *-----------------------------------------------------------------------
                    362:  */
                    363: /*ARGSUSED*/
                    364: static Bool
                    365: sunCG4CInit (index, pScreen, argc, argv)
                    366:     int                  index;        /* The index of pScreen in the ScreenInfo */
                    367:     ScreenPtr    pScreen;      /* The Screen to initialize */
                    368:     int                  argc;         /* The number of the Server's arguments. */
                    369:     char         **argv;       /* The arguments themselves. Don't change! */
                    370: {
                    371:     CARD16     zero = 0, ones = ~0;
                    372: #ifdef notdef
                    373:     u_char       rmap[256], gmap[256], bmap[256];
                    374: #endif
                    375: 
                    376:     if (!cfbScreenInit (index, pScreen, CG4Cfb->cpixel,        
                    377:                            sunFbs[index].info.fb_width,
                    378:                            sunFbs[index].info.fb_height, 90))
                    379:        return (FALSE);
                    380: 
                    381:     pScreen->SaveScreen =              sunCG4CSaveScreen;
                    382:     pScreen->RealizeCursor =           sunRealizeCursor;
                    383:     pScreen->UnrealizeCursor =         sunUnrealizeCursor;
                    384:     pScreen->DisplayCursor =           sunDisplayCursor;
                    385:     pScreen->SetCursorPosition =       sunSetCursorPosition;
                    386:     pScreen->CursorLimits =            sunCursorLimits;
                    387:     pScreen->PointerNonInterestBox =   sunPointerNonInterestBox;
                    388:     pScreen->ConstrainCursor =                 sunConstrainCursor;
                    389:     pScreen->RecolorCursor =           sunRecolorCursor;
                    390: 
                    391: #ifdef STATIC_COLOR
                    392:     pScreen->InstallColormap = NoopDDA;
                    393:     pScreen->UninstallColormap = NoopDDA;
                    394:     pScreen->ListInstalledColormaps = (int (*)())NoopDDA;
                    395:     pScreen->StoreColors = NoopDDA;
                    396:     pScreen->ResolveColor = cfbResolveStaticColor;
                    397: #else STATIC_COLOR
                    398:     pScreen->InstallColormap = sunCG4CInstallColormap;
                    399:     pScreen->UninstallColormap = sunCG4CUninstallColormap;
                    400:     pScreen->ListInstalledColormaps = sunCG4CListInstalledColormaps;
                    401:     pScreen->StoreColors = sunCG4CStoreColors;
                    402:     pScreen->ResolveColor = sunCG4CResolvePseudoColor;
                    403: #endif
                    404: 
                    405: #ifdef notdef
                    406:     /*
                    407:      * Fill the color map with a color cube 
                    408:      */
                    409:     for (i = 0; i < 256; i++) {
                    410:        rmap[i] = (i & 0x7) << 5;
                    411:        gmap[i] = (i & 0x38) << 2;
                    412:        bmap[i] = (i & 0xc0);
                    413:     }
                    414: 
                    415:     sunCG4CUpdateColormap(pScreenInfo->screen[index], 0, 256, rmap, gmap, bmap);
                    416: #endif
                    417: 
                    418:     {
                    419:        ColormapPtr cmap = (ColormapPtr)LookupID(pScreen->defColormap, RT_COLORMAP, RC_CORE);
                    420: 
                    421:        if (!cmap)
                    422:            FatalError("Can't find default colormap\n");
                    423:        if (AllocColor(cmap, &ones, &ones, &ones, &(pScreen->whitePixel), 0)
                    424:            || AllocColor(cmap, &zero, &zero, &zero, &(pScreen->blackPixel), 0))
                    425:                FatalError("Can't alloc black & white pixels in cfbScreeninit\n");
                    426:        sunCG4CInstallColormap(cmap);
                    427:     }
                    428: 
                    429: 
                    430:     sunCG4CSaveScreen( pScreen, SCREEN_SAVER_FORCER );
                    431:     sunScreenInit (pScreen);
                    432:     return (TRUE);
                    433: }
                    434: 
                    435: /*-
                    436:  *--------------------------------------------------------------
                    437:  * sunCG4CSwitch --
                    438:  *      Enable or disable color plane 
                    439:  *
                    440:  * Results:
                    441:  *      Color plane enabled for select =0, disabled otherwise.
                    442:  *
                    443:  *--------------------------------------------------------------
                    444:  */
                    445: static void
                    446: sunCG4CSwitch (pScreen, select)
                    447:    ScreenPtr  pScreen;
                    448:    u_char     select;
                    449: {
                    450:    int index;
                    451:    register int j;
                    452: 
                    453:    index = pScreen->myNum;
                    454:    CG4Cfb = (CG4CPtr) sunFbs[index].fb;
                    455: 
                    456:    for (j = 0; j < 128*1024; j++)
                    457:         CG4Cfb->epixel[j] = (!select) ? 0 : 0xff;
                    458: }
                    459: 
                    460: /*-
                    461:  *-----------------------------------------------------------------------
                    462:  * sunCG4CProbe --
                    463:  *     Attempt to find and initialize a cg4 framebuffer used as mono
                    464:  *
                    465:  * Results:
                    466:  *     TRUE if everything went ok. FALSE if not.
                    467:  *
                    468:  * Side Effects:
                    469:  *     Memory is allocated for the frame buffer and the buffer is mapped.
                    470:  *
                    471:  *-----------------------------------------------------------------------
                    472:  */
                    473: Bool
                    474: sunCG4CProbe (pScreenInfo, index, fbNum, argc, argv)
                    475:     ScreenInfo   *pScreenInfo; /* The screenInfo struct */
                    476:     int                  index;        /* The index of pScreen in the ScreenInfo */
                    477:     int                  fbNum;        /* Index into the sunFbData array */
                    478:     int                  argc;         /* The number of the Server's arguments. */
                    479:     char         **argv;       /* The arguments themselves. Don't change! */
                    480: {
                    481:     int         i, oldNumScreens;
                    482: 
                    483:     if (sunFbData[fbNum].probeStatus == probedAndFailed) {
                    484:        return FALSE;
                    485:     }
                    486: 
                    487:     if (sunFbData[fbNum].probeStatus == neverProbed) {
                    488:        int         fd;
                    489:        struct fbtype fbType;
                    490: 
                    491:        if ((fd = sunOpenFrameBuffer(FBTYPE_SUN4COLOR, &fbType, index, fbNum,
                    492:                                     argc, argv)) < 0) {
                    493:            sunFbData[fbNum].probeStatus = probedAndFailed;
                    494:            return FALSE;
                    495:        }
                    496: 
                    497: #ifdef _MAP_NEW
                    498:        if ((int)(CG4Cfb = (CG4CPtr) mmap((caddr_t) 0,
                    499:                 CG4C_MONOLEN + CG4C_ENBLEN + CG4C_IMAGELEN,
                    500:                 PROT_READ | PROT_WRITE,
                    501:                 MAP_SHARED | _MAP_NEW, fd, 0)) == -1) {
                    502:            Error("Mapping cg4c");
                    503:            sunFbData[fbNum].probeStatus = probedAndFailed;
                    504:            (void) close(fd);
                    505:            return FALSE;
                    506:        }
                    507: #else  _MAP_NEW
                    508:        CG4Cfb = (CG4CPtr) valloc(CG4C_MONOLEN + CG4C_ENBLEN + CG4C_IMAGELEN);
                    509:        if (CG4Cfb == (CG4CPtr) NULL) {
                    510:            ErrorF("Could not allocate room for frame buffer.\n");
                    511:            sunFbData[fbNum].probeStatus = probedAndFailed;
                    512:            return FALSE;
                    513:        }
                    514: 
                    515:        if (mmap((caddr_t) CG4Cfb, CG4C_MONOLEN + CG4C_ENBLEN + CG4C_IMAGELEN,
                    516:                 PROT_READ | PROT_WRITE,
                    517:                 MAP_SHARED, fd, 0) < 0) {
                    518:            Error("Mapping cg4c");
                    519:            sunFbData[fbNum].probeStatus = probedAndFailed;
                    520:            (void) close(fd);
                    521:            return FALSE;
                    522:        }
                    523: #endif _MAP_NEW
                    524: 
                    525:        sunFbs[index].fd = fd;
                    526:        sunFbs[index].info = fbType;
                    527:        sunFbs[index].fb = (pointer) CG4Cfb;
                    528:         sunFbs[index].EnterLeave = sunCG4CSwitch;
                    529:        sunFbData[fbNum].probeStatus = probedAndSucceeded;
                    530: 
                    531:     }
                    532: 
                    533:     /*
                    534:      * If we've ever successfully probed this device, do the following. 
                    535:      */
                    536: 
                    537:     oldNumScreens = pScreenInfo->numScreens;
                    538:     i = AddScreen(sunCG4CInit, argc, argv);
                    539:     pScreenInfo->screen[index].CloseScreen = sunCG4CCloseScreen;
                    540:     /* Now set the enable plane for color */
                    541:     if (index == 0) sunCG4CSwitch (&(pScreenInfo->screen[0]), 0);
                    542: 
                    543:     return (i > oldNumScreens);
                    544: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.