Annotation of researchv9/X11/src/X.V11R1/server/dix/main.c, revision 1.1

1.1     ! root        1: /***********************************************************
        !             2: Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
        !             3: and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
        !             4: 
        !             5:                         All Rights Reserved
        !             6: 
        !             7: Permission to use, copy, modify, and distribute this software and its 
        !             8: documentation for any purpose and without fee is hereby granted, 
        !             9: provided that the above copyright notice appear in all copies and that
        !            10: both that copyright notice and this permission notice appear in 
        !            11: supporting documentation, and that the names of Digital or MIT not be
        !            12: used in advertising or publicity pertaining to distribution of the
        !            13: software without specific, written prior permission.  
        !            14: 
        !            15: DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
        !            16: ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
        !            17: DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
        !            18: ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
        !            19: WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
        !            20: ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
        !            21: SOFTWARE.
        !            22: 
        !            23: ******************************************************************/
        !            24: /* $Header: main.c,v 1.124 87/09/07 18:17:41 toddb Exp $ */
        !            25: 
        !            26: #include "X.h"
        !            27: #include "Xproto.h"
        !            28: #include "input.h"
        !            29: #include "scrnintstr.h"
        !            30: #include "misc.h"
        !            31: #include "os.h"
        !            32: #include "windowstr.h"
        !            33: #include "resource.h"
        !            34: #include "dixstruct.h"
        !            35: #include "gcstruct.h"
        !            36: #include "extension.h"
        !            37: #include "colormap.h"
        !            38: #include "cursorstr.h"
        !            39: #include "opaque.h"
        !            40: #include "servermd.h"
        !            41: 
        !            42: extern long defaultScreenSaverTime;
        !            43: extern long defaultScreenSaverInterval;
        !            44: extern int defaultScreenSaverBlanking;
        !            45: extern int defaultScreenSaverAllowExposures;
        !            46: 
        !            47: extern char *display;
        !            48: char *ConnectionInfo;
        !            49: xConnSetupPrefix connSetupPrefix;
        !            50: 
        !            51: extern WindowRec WindowTable[];
        !            52: extern xColorItem screenWhite, screenBlack;
        !            53: extern FontPtr defaultFont;
        !            54: 
        !            55: extern void SetInputCheck();
        !            56: extern void AbortServer();
        !            57: 
        !            58: PaddingInfo PixmapWidthPaddingInfo[33];
        !            59: int connBlockScreenStart;
        !            60: 
        !            61: unsigned char *minfree;
        !            62: 
        !            63: static int restart = 0;
        !            64: 
        !            65: int
        !            66: NotImplemented()
        !            67: {
        !            68:     FatalError("Not implemented");
        !            69: }
        !            70: 
        !            71: /*
        !            72:  * This array encodes the answer to the question "what is the log base 2
        !            73:  * of the number of pixels that fit in a scanline pad unit?"
        !            74:  * Note that ~0 is an invalid entry (mostly for the benefit of the reader).
        !            75:  */
        !            76: static int answer[6][3] = {
        !            77:        /* pad   pad   pad */
        !            78:        /*  8     16    32 */
        !            79: 
        !            80:        {   3,     4,    5 },   /* 1 bit per pixel */
        !            81:        {   1,     2,    3 },   /* 4 bits per pixel */
        !            82:        {   0,     1,    2 },   /* 8 bits per pixel */
        !            83:        {   ~0,    0,    1 },   /* 16 bits per pixel */
        !            84:        {   ~0,    ~0,   0 },   /* 24 bits per pixel */
        !            85:        {   ~0,    ~0,   0 }    /* 32 bits per pixel */
        !            86: };
        !            87: 
        !            88: /*
        !            89:  * This array gives the answer to the question "what is the first index for
        !            90:  * the answer array above given the number of bits per pixel?"
        !            91:  * Note that ~0 is an invalid entry (mostly for the benefit of the reader).
        !            92:  */
        !            93: static int indexForBitsPerPixel[ 33 ] = {
        !            94:        ~0, 0, ~0, ~0,  /* 1 bit per pixel */
        !            95:        1, ~0, ~0, ~0,  /* 4 bits per pixel */
        !            96:        2, ~0, ~0, ~0,  /* 8 bits per pixel */
        !            97:        ~0,~0, ~0, ~0,
        !            98:        3, ~0, ~0, ~0,  /* 16 bits per pixel */
        !            99:        ~0,~0, ~0, ~0,
        !           100:        4, ~0, ~0, ~0,  /* 24 bits per pixel */
        !           101:        ~0,~0, ~0, ~0,
        !           102:        5               /* 32 bits per pixel */
        !           103: };
        !           104: 
        !           105: /*
        !           106:  * This array gives the answer to the question "what is the second index for
        !           107:  * the answer array above given the number of bits per scanline pad unit?"
        !           108:  * Note that ~0 is an invalid entry (mostly for the benefit of the reader).
        !           109:  */
        !           110: static int indexForScanlinePad[ 33 ] = {
        !           111:        ~0, ~0, ~0, ~0,
        !           112:        ~0, ~0, ~0, ~0,
        !           113:        0,  ~0, ~0, ~0, /* 8 bits per scanline pad unit */
        !           114:        ~0, ~0, ~0, ~0,
        !           115:        1,  ~0, ~0, ~0, /* 16 bits per scanline pad unit */
        !           116:        ~0, ~0, ~0, ~0,
        !           117:        ~0, ~0, ~0, ~0,
        !           118:        ~0, ~0, ~0, ~0,
        !           119:        2               /* 32 bits per scanline pad unit */
        !           120: };
        !           121: 
        !           122: main(argc, argv)
        !           123:     int                argc;
        !           124:     char       *argv[];
        !           125: {
        !           126:     int                i, j, k, looping;
        !           127:     int                alwaysCheckForInput[2];
        !           128: 
        !           129:     /* Notice if we're restart.  Probably this is because we jumped through
        !           130:      * uninitialized pointer */
        !           131:     minfree = (unsigned char *)sbrk(0);               /* FOR DEBUG       XXX */
        !           132:     if (restart)
        !           133:        FatalError("server restarted. Jumped through uninitialized pointer?\n");
        !           134:     else
        !           135:        restart = 1;
        !           136:     /* These are needed by some routines which are called from interrupt
        !           137:      * handlers, thus have no direct calling path back to main and thus
        !           138:      * can't be passed argc, argv as parameters */
        !           139:     argcGlobal = argc;
        !           140:     argvGlobal = argv;
        !           141:     display = "0";
        !           142:     ProcessCommandLine(argc, argv);
        !           143: 
        !           144:     alwaysCheckForInput[0] = 0;
        !           145:     alwaysCheckForInput[1] = 1;
        !           146:     looping = 0;
        !           147:     while(1)
        !           148:     {
        !           149:         ScreenSaverTime = defaultScreenSaverTime;
        !           150:        ScreenSaverInterval = defaultScreenSaverInterval;
        !           151:        ScreenSaverBlanking = defaultScreenSaverBlanking;
        !           152:        ScreenSaverAllowExposures = defaultScreenSaverAllowExposures;
        !           153: 
        !           154:        /* Perform any operating system dependent initializations you'd like */
        !           155:        OsInit();               
        !           156:        if(!looping)
        !           157:        {
        !           158:            CreateWellKnownSockets();
        !           159:            InitProcVectors();
        !           160:            serverClient = (ClientPtr)Xalloc(sizeof(ClientRec));
        !           161:             serverClient->sequence = 0;
        !           162:             serverClient->closeDownMode = RetainPermanent;
        !           163:             serverClient->clientGone = FALSE;
        !           164:             serverClient->lastDrawable = (DrawablePtr)NULL;
        !           165:            serverClient->lastDrawableID = INVALID;
        !           166:             serverClient->lastGC = (GCPtr)NULL;
        !           167:            serverClient->lastGCID = None;
        !           168:            serverClient->numSaved = None;
        !           169:            serverClient->saveSet = (pointer *)NULL;
        !           170:            serverClient->index = 0;
        !           171:        }
        !           172:         currentMaxClients = 10;
        !           173:         clients = (ClientPtr *)Xalloc(currentMaxClients * sizeof(ClientPtr));
        !           174:         for (i=1; i<currentMaxClients; i++) 
        !           175:             clients[i] = NullClient;
        !           176:         clients[0] = serverClient;
        !           177: 
        !           178:        InitClientResources(serverClient);      /* for root resources */
        !           179: 
        !           180:        SetInputCheck(&alwaysCheckForInput[0], &alwaysCheckForInput[1]);
        !           181:        screenInfo.arraySize = 0;
        !           182:        screenInfo.numScreens = 0;
        !           183:        screenInfo.screen = (ScreenPtr)NULL;
        !           184:        /*
        !           185:         * Just in case the ddx doesnt supply a format for depth 1 (like qvss).
        !           186:         */
        !           187:        j = indexForBitsPerPixel[ 1 ];
        !           188:        k = indexForScanlinePad[ BITMAP_SCANLINE_PAD ];
        !           189:        PixmapWidthPaddingInfo[1].scanlinePad = BITMAP_SCANLINE_PAD-1;
        !           190:        PixmapWidthPaddingInfo[1].bitmapPadLog2 = answer[j][k];
        !           191: 
        !           192:        InitAtoms();
        !           193:        InitExtensions(); 
        !           194:        InitOutput(&screenInfo, argc, argv);
        !           195:        if (screenInfo.numScreens < 1)
        !           196:            FatalError("no screens found\n");
        !           197:        InitEvents();
        !           198:        InitInput(argc, argv);
        !           199:        InitAndStartDevices(argc, argv);
        !           200: 
        !           201:        SetDefaultFontPath(defaultFontPath);    /* default path has no nulls */
        !           202:        if ( ! SetDefaultFont(defaultTextFont))
        !           203:            ErrorF( "main: Could not open default font '%s'\n",
        !           204:                defaultTextFont);
        !           205:        if ( ! (rootCursor = CreateRootCursor(defaultCursorFont, 0)))
        !           206:            ErrorF( "main: Could not open default cursor font '%s'\n",
        !           207:                defaultCursorFont);
        !           208: 
        !           209:        for (i=0; i<screenInfo.numScreens; i++) 
        !           210:        {
        !           211:            CreateRootWindow(i);
        !           212:        }
        !           213:         DefineInitialRootWindow(&WindowTable[0]);
        !           214:        if(!looping)
        !           215:        {
        !           216:            CreateConnectionBlock();
        !           217:        }
        !           218: 
        !           219:        Dispatch();
        !           220: 
        !           221:        /* Now free up whatever must be freed */
        !           222:        CloseDownExtensions();
        !           223:        FreeAllResources();
        !           224:        for ( i = 0; i < screenInfo.numScreens; i++)
        !           225:         {
        !           226:            FreeGCperDepth(i);
        !           227:            FreeDefaultStipple(i);
        !           228:        }
        !           229:        CloseDownDevices(argc, argv);
        !           230:        for (i = 0; i < screenInfo.numScreens; i++)
        !           231:            (* screenInfo.screen[i].CloseScreen)(i, &screenInfo.screen[i]);
        !           232:        Xfree(screenInfo.screen);
        !           233: 
        !           234:         CloseFont(defaultFont);
        !           235:         defaultFont = (FontPtr)NULL;
        !           236: 
        !           237:        ResetHosts(display);
        !           238:         Xfree(clients);
        !           239: 
        !           240:        looping = 1;
        !           241:     }
        !           242: }
        !           243: 
        !           244: static int padlength[4] = {0, 3, 2, 1};
        !           245: 
        !           246: CreateConnectionBlock()
        !           247: {
        !           248:     xConnSetup setup;
        !           249:     xWindowRoot root;
        !           250:     xDepth     depth;
        !           251:     xVisualType visual;
        !           252:     xPixmapFormat format;
        !           253:     int i, j, k, vid, 
        !           254:         lenofblock=0,
        !           255:         sizesofar = 0;
        !           256:     char *pBuf;
        !           257: 
        !           258:     
        !           259:     /* Leave off the ridBase and ridMask, these must be sent with 
        !           260:        connection */
        !           261: 
        !           262:     setup.release = VENDOR_RELEASE;
        !           263:     /*
        !           264:      * per-server image and bitmap parameters are defined in Xmd.h
        !           265:      */
        !           266:     setup.imageByteOrder = screenInfo.imageByteOrder;
        !           267:     setup.bitmapScanlineUnit  = screenInfo.bitmapScanlineUnit;
        !           268:     setup.bitmapScanlinePad = screenInfo.bitmapScanlinePad;
        !           269:     setup.bitmapBitOrder = screenInfo.bitmapBitOrder;
        !           270:     setup.motionBufferSize = NumMotionEvents();
        !           271:     setup.numRoots = screenInfo.numScreens;
        !           272:     setup.nbytesVendor = strlen(VENDOR_STRING); 
        !           273:     setup.numFormats = screenInfo.numPixmapFormats;
        !           274:     setup.maxRequestSize = MAX_REQUEST_SIZE;
        !           275:     QueryMinMaxKeyCodes(&setup.minKeyCode, &setup.maxKeyCode);
        !           276:     
        !           277:     lenofblock = sizeof(xConnSetup) + 
        !           278:             ((setup.nbytesVendor + 3) & ~3) +
        !           279:            (setup.numFormats * sizeof(xPixmapFormat)) +
        !           280:             (setup.numRoots * sizeof(xWindowRoot));
        !           281:     ConnectionInfo = (char *) Xalloc(lenofblock);
        !           282: 
        !           283:     bcopy((char *)&setup, ConnectionInfo, sizeof(xConnSetup));
        !           284:     sizesofar = sizeof(xConnSetup);
        !           285:     pBuf = ConnectionInfo + sizeof(xConnSetup);
        !           286: 
        !           287:     bcopy(VENDOR_STRING, pBuf, setup.nbytesVendor);
        !           288:     sizesofar += setup.nbytesVendor;
        !           289:     pBuf += setup.nbytesVendor;
        !           290:     i = padlength[setup.nbytesVendor & 3];
        !           291:     if (i)
        !           292:     {
        !           293:         char pad[4];
        !           294:         bcopy(pad, pBuf, i);
        !           295:         pBuf += i;
        !           296:        sizesofar += i;
        !           297:     }    
        !           298:     
        !           299:     for (i=0; i<screenInfo.numPixmapFormats; i++)
        !           300:     {
        !           301:        format.depth = screenInfo.formats[i].depth;
        !           302:        format.bitsPerPixel = screenInfo.formats[i].bitsPerPixel;
        !           303:        format.scanLinePad = screenInfo.formats[i].scanlinePad;;
        !           304:        bcopy((char *)&format, pBuf, sizeof(xPixmapFormat));
        !           305:        pBuf += sizeof(xPixmapFormat);
        !           306:        sizesofar += sizeof(xPixmapFormat);
        !           307:     }
        !           308: 
        !           309:     connBlockScreenStart = sizesofar;
        !           310:     for (i=0; i<screenInfo.numScreens; i++) 
        !           311:     {
        !           312:        ScreenPtr       pScreen;
        !           313:        DepthPtr        pDepth;
        !           314:        VisualPtr       pVisual;
        !           315: 
        !           316:        pScreen = &(screenInfo.screen[i]);
        !           317:         root.windowId = WindowTable[i].wid;
        !           318:         root.defaultColormap = pScreen->defColormap;
        !           319:         root.whitePixel = pScreen->whitePixel;
        !           320:        root.blackPixel = pScreen->blackPixel;
        !           321:         root.currentInputMask = 0;    /* filled in when sent */
        !           322:         root.pixWidth = pScreen->width;
        !           323:         root.pixHeight = pScreen->height;
        !           324:         root.mmWidth = pScreen->mmWidth;
        !           325:        root.mmHeight = pScreen->mmHeight;
        !           326:         root.minInstalledMaps = pScreen->minInstalledCmaps;
        !           327:         root.maxInstalledMaps = pScreen->maxInstalledCmaps; 
        !           328:         root.rootVisualID = pScreen->rootVisual;               
        !           329:         root.backingStore = pScreen->backingStoreSupport;
        !           330:         root.saveUnders = pScreen->saveUnderSupport;
        !           331:         root.rootDepth = pScreen->rootDepth;
        !           332:        root.nDepths = pScreen->numDepths;
        !           333:         bcopy((char *)&root, pBuf, sizeof(xWindowRoot));
        !           334:        sizesofar += sizeof(xWindowRoot);
        !           335:         pBuf += sizeof(xWindowRoot);
        !           336: 
        !           337:        pDepth = pScreen->allowedDepths;
        !           338:        for(j = 0; j < pScreen->numDepths; j++, pDepth++)
        !           339:        {
        !           340:            lenofblock += sizeof(xDepth) + 
        !           341:                    (pDepth->numVids * sizeof(xVisualType));
        !           342:             ConnectionInfo = (char *)Xrealloc(ConnectionInfo, lenofblock);
        !           343:             pBuf = ConnectionInfo + sizesofar;            
        !           344:            depth.depth = pDepth->depth;
        !           345:            depth.nVisuals = pDepth->numVids;
        !           346:            bcopy((char *)&depth, pBuf, sizeof(xDepth));
        !           347:            pBuf += sizeof(xDepth);
        !           348:            sizesofar += sizeof(xDepth);
        !           349:            for(k = 0; k < pDepth->numVids; k++)
        !           350:            {
        !           351:                vid = pDepth->vids[k];
        !           352:                pVisual = (VisualPtr) LookupID(vid, RT_VISUALID, RC_CORE);
        !           353:                visual.visualID = pVisual->vid;
        !           354:                visual.class = pVisual->class;
        !           355:                visual.bitsPerRGB = pVisual->bitsPerRGBValue;
        !           356:                visual.colormapEntries = pVisual->ColormapEntries;
        !           357:                visual.redMask = pVisual->redMask;
        !           358:                visual.greenMask = pVisual->greenMask;
        !           359:                visual.blueMask = pVisual->blueMask;
        !           360:                bcopy((char *)&visual, pBuf, sizeof(xVisualType));
        !           361:                pBuf += sizeof(xVisualType);
        !           362:                sizesofar += sizeof(xVisualType);
        !           363:            }
        !           364:        }
        !           365:     }
        !           366:     connSetupPrefix.success = xTrue;
        !           367:     connSetupPrefix.length = lenofblock/4;
        !           368:     connSetupPrefix.majorVersion = X_PROTOCOL;
        !           369:     connSetupPrefix.minorVersion = X_PROTOCOL_REVISION;
        !           370: }
        !           371: 
        !           372: 
        !           373: /* VARARGS */
        !           374: FatalError (msg, v0, v1, v2, v3, v4, v5, v6, v7, v8)
        !           375:     char *msg;
        !           376:     int v0, v1, v2, v3, v4, v5, v6, v7, v8;
        !           377: {
        !           378:     ErrorF("\nFatal server bug!\n");
        !           379:     ErrorF(msg, v0, v1, v2, v3, v4, v5, v6, v7, v8);
        !           380:     ErrorF("\n");
        !           381:     AbortServer();
        !           382: }
        !           383: 
        !           384: /*
        !           385:        grow the array of screenRecs if necessary.
        !           386:        call the device-supplied initialization procedure 
        !           387: with its screen number, a pointer to its ScreenRec, argc, and argv.
        !           388:        return the number of successfully installed screens.
        !           389: 
        !           390: */
        !           391: 
        !           392: AddScreen(pfnInit, argc, argv)
        !           393:     Bool       (* pfnInit)();
        !           394:     int argc;
        !           395:     char **argv;
        !           396: {
        !           397: 
        !           398:     int i = screenInfo.numScreens;
        !           399:     int scanlinepad, format, bitsPerPixel, j, k;
        !           400: #ifdef DEBUG
        !           401:     void       (**jNI) ();
        !           402: #endif /* DEBUG */
        !           403: 
        !           404:     if (screenInfo.numScreens == screenInfo.arraySize)
        !           405:     {
        !           406:        screenInfo.arraySize += 5;
        !           407:        screenInfo.screen = (ScreenPtr)Xrealloc(
        !           408:            screenInfo.screen, 
        !           409:            screenInfo.arraySize * sizeof(ScreenRec));
        !           410:     }
        !           411: 
        !           412: #ifdef DEBUG
        !           413:            for (jNI = &screenInfo.screen[i].QueryBestSize; 
        !           414:                 jNI < (void (**) ()) &screenInfo.screen[i].RegionExtents; 
        !           415:                 jNI++)
        !           416:                *jNI = (void (*) ())NotImplemented;
        !           417: #endif /* DEBUG */
        !           418: 
        !           419: 
        !           420:     /*
        !           421:      * This loop gets run once for every Screen that gets added,
        !           422:      * but thats ok.  If the ddx layer initializes the formats
        !           423:      * one at a time calling AddScreen() after each, then each
        !           424:      * iteration will make it a little more accurate.  Worst case
        !           425:      * we do this loop N * numPixmapFormats where N is # of screens.
        !           426:      * Anyway, this must be called after InitOutput and before the
        !           427:      * screen init routine is called.
        !           428:      */
        !           429:     for (format=0; format<screenInfo.numPixmapFormats; format++)
        !           430:     {
        !           431:        bitsPerPixel = screenInfo.formats[format].bitsPerPixel;
        !           432:        scanlinepad = screenInfo.formats[format].scanlinePad;
        !           433:        j = indexForBitsPerPixel[ bitsPerPixel ];
        !           434:        k = indexForScanlinePad[ scanlinepad ];
        !           435:        PixmapWidthPaddingInfo[ bitsPerPixel ].bitmapPadLog2 = answer[j][k];
        !           436:        PixmapWidthPaddingInfo[ bitsPerPixel ].scanlinePad =
        !           437:            (scanlinepad/bitsPerPixel) - 1;
        !           438:     }
        !           439:   
        !           440:     /* This is where screen specific stuff gets initialized.  Load the
        !           441:        screen structure, call the hardware, whatever.
        !           442:        This is also where the default colormap should be allocated and
        !           443:        also pixel values for blackPixel, whitePixel, and the cursor
        !           444:        Note that InitScreen is NOT allowed to modify argc, argv, or
        !           445:        any of the strings pointed to by argv.  They may be passed to
        !           446:        multiple screens. 
        !           447:     */ 
        !           448:     screenInfo.screen[i].rgf = ~0;  /* there are no scratch GCs yet*/
        !           449:     screenInfo.screen[i].myNum = i;
        !           450:     if ((*pfnInit)(i, &screenInfo.screen[i], argc, argv))
        !           451:     {
        !           452:        screenInfo.numScreens++;
        !           453:         CreateGCperDepthArray(i);
        !           454:        CreateDefaultStipple(i);
        !           455:     }
        !           456:     else
        !           457:        ErrorF("screen %d failed initialization\n", i);
        !           458: 
        !           459:     return screenInfo.numScreens;
        !           460: }
        !           461: 
        !           462: 

unix.superglobalmegacorp.com

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