home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / dix / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-24  |  18.3 KB  |  627 lines

  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. /* $XConsortium: main.c,v 5.17 91/07/24 12:33:14 rws 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 "font.h"
  40. #include "opaque.h"
  41. #include "servermd.h"
  42. #include "site.h"
  43.  
  44. extern long defaultScreenSaverTime;
  45. extern long defaultScreenSaverInterval;
  46. extern int defaultScreenSaverBlanking;
  47. extern int defaultScreenSaverAllowExposures;
  48.  
  49. void ddxGiveUp();
  50.  
  51. extern char *display;
  52. char *ConnectionInfo;
  53. xConnSetupPrefix connSetupPrefix;
  54.  
  55. extern WindowPtr *WindowTable;
  56. extern FontPtr defaultFont;
  57.  
  58. extern void SetInputCheck();
  59. extern void InitProcVectors();
  60. extern void InitEvents();
  61. extern void InitExtensions();
  62. extern void DefineInitialRootWindow();
  63. extern void QueryMinMaxKeyCodes();
  64. extern Bool InitClientResources();
  65. static Bool CreateConnectionBlock();
  66. extern Bool CreateGCperDepthArray();
  67. extern Bool CreateDefaultStipple();
  68. extern void ResetWellKnownSockets();
  69. extern void ResetWindowPrivates();
  70. extern void ResetGCPrivates();
  71. static void FreeScreen();
  72. static void ResetScreenPrivates();
  73.  
  74. PaddingInfo PixmapWidthPaddingInfo[33];
  75. int connBlockScreenStart;
  76.  
  77. static int restart = 0;
  78.  
  79. void
  80. NotImplemented()
  81. {
  82.     FatalError("Not implemented");
  83. }
  84.  
  85. /*
  86.  * This array encodes the answer to the question "what is the log base 2
  87.  * of the number of pixels that fit in a scanline pad unit?"
  88.  * Note that ~0 is an invalid entry (mostly for the benefit of the reader).
  89.  */
  90. static int answer[6][3] = {
  91.     /* pad   pad   pad */
  92.     /*  8     16    32 */
  93.  
  94.     {   3,     4,    5 },    /* 1 bit per pixel */
  95.     {   1,     2,    3 },    /* 4 bits per pixel */
  96.     {   0,     1,    2 },    /* 8 bits per pixel */
  97.     {   ~0,    0,    1 },    /* 16 bits per pixel */
  98.     {   ~0,    ~0,   0 },    /* 24 bits per pixel */
  99.     {   ~0,    ~0,   0 }    /* 32 bits per pixel */
  100. };
  101.  
  102. /*
  103.  * This array gives the answer to the question "what is the first index for
  104.  * the answer array above given the number of bits per pixel?"
  105.  * Note that ~0 is an invalid entry (mostly for the benefit of the reader).
  106.  */
  107. static int indexForBitsPerPixel[ 33 ] = {
  108.     ~0, 0, ~0, ~0,    /* 1 bit per pixel */
  109.     1, ~0, ~0, ~0,    /* 4 bits per pixel */
  110.     2, ~0, ~0, ~0,    /* 8 bits per pixel */
  111.     ~0,~0, ~0, ~0,
  112.     3, ~0, ~0, ~0,    /* 16 bits per pixel */
  113.     ~0,~0, ~0, ~0,
  114.     4, ~0, ~0, ~0,    /* 24 bits per pixel */
  115.     ~0,~0, ~0, ~0,
  116.     5        /* 32 bits per pixel */
  117. };
  118.  
  119. /*
  120.  * This array gives the answer to the question "what is the second index for
  121.  * the answer array above given the number of bits per scanline pad unit?"
  122.  * Note that ~0 is an invalid entry (mostly for the benefit of the reader).
  123.  */
  124. static int indexForScanlinePad[ 33 ] = {
  125.     ~0, ~0, ~0, ~0,
  126.     ~0, ~0, ~0, ~0,
  127.     0,  ~0, ~0, ~0,    /* 8 bits per scanline pad unit */
  128.     ~0, ~0, ~0, ~0,
  129.     1,  ~0, ~0, ~0,    /* 16 bits per scanline pad unit */
  130.     ~0, ~0, ~0, ~0,
  131.     ~0, ~0, ~0, ~0,
  132.     ~0, ~0, ~0, ~0,
  133.     2        /* 32 bits per scanline pad unit */
  134. };
  135.  
  136. main(argc, argv)
  137.     int        argc;
  138.     char    *argv[];
  139. {
  140.     int        i, j, k;
  141.     long    alwaysCheckForInput[2];
  142.  
  143.     /* Notice if we're restart.  Probably this is because we jumped through
  144.      * uninitialized pointer */
  145.     if (restart)
  146.     FatalError("server restarted. Jumped through uninitialized pointer?\n");
  147.     else
  148.     restart = 1;
  149.     /* These are needed by some routines which are called from interrupt
  150.      * handlers, thus have no direct calling path back to main and thus
  151.      * can't be passed argc, argv as parameters */
  152.     argcGlobal = argc;
  153.     argvGlobal = argv;
  154.     display = "0";
  155.     ProcessCommandLine(argc, argv);
  156.  
  157.     alwaysCheckForInput[0] = 0;
  158.     alwaysCheckForInput[1] = 1;
  159.     while(1)
  160.     {
  161.     serverGeneration++;
  162.         ScreenSaverTime = defaultScreenSaverTime;
  163.     ScreenSaverInterval = defaultScreenSaverInterval;
  164.     ScreenSaverBlanking = defaultScreenSaverBlanking;
  165.     ScreenSaverAllowExposures = defaultScreenSaverAllowExposures;
  166.     InitBlockAndWakeupHandlers();
  167.     /* Perform any operating system dependent initializations you'd like */
  168.     OsInit();        
  169.     if(serverGeneration == 1)
  170.     {
  171.         CreateWellKnownSockets();
  172.         InitProcVectors();
  173.         clients = (ClientPtr *)xalloc(MAXCLIENTS * sizeof(ClientPtr));
  174.         if (!clients)
  175.         FatalError("couldn't create client array");
  176.         for (i=1; i<MAXCLIENTS; i++) 
  177.         clients[i] = NullClient;
  178.         serverClient = (ClientPtr)xalloc(sizeof(ClientRec));
  179.         if (!serverClient)
  180.         FatalError("couldn't create server client");
  181.             serverClient->sequence = 0;
  182.             serverClient->closeDownMode = RetainPermanent;
  183.             serverClient->clientGone = FALSE;
  184.             serverClient->lastDrawable = (DrawablePtr)NULL;
  185.         serverClient->lastDrawableID = INVALID;
  186.             serverClient->lastGC = (GCPtr)NULL;
  187.         serverClient->lastGCID = INVALID;
  188.         serverClient->numSaved = 0;
  189.         serverClient->saveSet = (pointer *)NULL;
  190.         serverClient->index = 0;
  191.         serverClient->clientAsMask = (Mask)0;
  192.         serverClient->noClientException = Success;
  193.     }
  194.     else
  195.         ResetWellKnownSockets ();
  196.         clients[0] = serverClient;
  197.         currentMaxClients = 1;
  198.  
  199.     if (!InitClientResources(serverClient))      /* for root resources */
  200.         FatalError("couldn't init server resources");
  201.  
  202.     SetInputCheck(&alwaysCheckForInput[0], &alwaysCheckForInput[1]);
  203.     screenInfo.arraySize = MAXSCREENS;
  204.     screenInfo.numScreens = 0;
  205.     WindowTable = (WindowPtr *)xalloc(MAXSCREENS * sizeof(WindowPtr));
  206.     if (!WindowTable)
  207.         FatalError("couldn't create root window table");
  208.  
  209.     /*
  210.      * Just in case the ddx doesnt supply a format for depth 1 (like qvss).
  211.      */
  212.     j = indexForBitsPerPixel[ 1 ];
  213.     k = indexForScanlinePad[ BITMAP_SCANLINE_PAD ];
  214.     PixmapWidthPaddingInfo[1].padRoundUp = BITMAP_SCANLINE_PAD-1;
  215.     PixmapWidthPaddingInfo[1].padPixelsLog2 = answer[j][k];
  216.      j = indexForBitsPerPixel[8]; /* bits per byte */
  217.      PixmapWidthPaddingInfo[1].padBytesLog2 = answer[j][k];
  218.  
  219.     InitAtoms();
  220.     InitEvents();
  221.     ResetScreenPrivates();
  222.     ResetWindowPrivates();
  223.     ResetGCPrivates();
  224.     ResetFontPrivateIndex();
  225.     InitOutput(&screenInfo, argc, argv);
  226.     if (screenInfo.numScreens < 1)
  227.         FatalError("no screens found");
  228.     InitExtensions(argc, argv);
  229.     for (i = 0; i < screenInfo.numScreens; i++)
  230.     {
  231.         if (!CreateGCperDepth(i))
  232.         FatalError("failed to create scratch GCs");
  233.         if (!CreateDefaultStipple(i))
  234.         FatalError("failed to create default stipple");
  235.         if (!CreateRootWindow(screenInfo.screens[i]))
  236.         FatalError("failed to create root window");
  237.     }
  238.     InitInput(argc, argv);
  239.     if (InitAndStartDevices() != Success)
  240.         FatalError("failed to initialize core devices");
  241.  
  242.     InitFonts ();
  243.     if (SetDefaultFontPath(defaultFontPath, &i) != Success)
  244.         ErrorF("failed to set default font path '%s'", defaultFontPath);
  245.     if (!SetDefaultFont(defaultTextFont))
  246.         FatalError("could not open default font '%s'", defaultTextFont);
  247.     if (!(rootCursor = CreateRootCursor(defaultCursorFont, 0)))
  248.         FatalError("could not open default cursor font '%s'",
  249.                defaultCursorFont);
  250.     for (i = 0; i < screenInfo.numScreens; i++)
  251.         InitRootWindow(WindowTable[i]);
  252.         DefineInitialRootWindow(WindowTable[0]);
  253.  
  254.     if (!CreateConnectionBlock())
  255.         FatalError("could not create connection block info");
  256.  
  257.     Dispatch();
  258.  
  259.     /* Now free up whatever must be freed */
  260.     CloseDownExtensions();
  261.     FreeAllResources();
  262.     CloseDownDevices();
  263.     for (i = screenInfo.numScreens - 1; i >= 0; i--)
  264.     {
  265.         FreeGCperDepth(i);
  266.         FreeDefaultStipple(i);
  267.         (* screenInfo.screens[i]->CloseScreen)(i, screenInfo.screens[i]);
  268.         FreeScreen(screenInfo.screens[i]);
  269.         screenInfo.numScreens = i;
  270.     }
  271.     xfree(WindowTable);
  272.  
  273.     FreeFonts ();
  274.  
  275.     if (dispatchException & DE_TERMINATE)
  276.     {
  277.         ddxGiveUp();
  278.         break;
  279.     }
  280.  
  281.     xfree(ConnectionInfo);
  282.     }
  283.     exit(0);
  284. }
  285.  
  286. static int padlength[4] = {0, 3, 2, 1};
  287.  
  288. static Bool
  289. CreateConnectionBlock()
  290. {
  291.     xConnSetup setup;
  292.     xWindowRoot root;
  293.     xDepth    depth;
  294.     xVisualType visual;
  295.     xPixmapFormat format;
  296.     unsigned long vid;
  297.     int i, j, k,
  298.         lenofblock,
  299.         sizesofar = 0;
  300.     char *pBuf;
  301.  
  302.     
  303.     /* Leave off the ridBase and ridMask, these must be sent with 
  304.        connection */
  305.  
  306.     setup.release = VENDOR_RELEASE;
  307.     /*
  308.      * per-server image and bitmap parameters are defined in Xmd.h
  309.      */
  310.     setup.imageByteOrder = screenInfo.imageByteOrder;
  311.     setup.bitmapScanlineUnit  = screenInfo.bitmapScanlineUnit;
  312.     setup.bitmapScanlinePad = screenInfo.bitmapScanlinePad;
  313.     setup.bitmapBitOrder = screenInfo.bitmapBitOrder;
  314.     setup.motionBufferSize = NumMotionEvents();
  315.     setup.numRoots = screenInfo.numScreens;
  316.     setup.nbytesVendor = strlen(VENDOR_STRING); 
  317.     setup.numFormats = screenInfo.numPixmapFormats;
  318.     setup.maxRequestSize = MAX_REQUEST_SIZE;
  319.     QueryMinMaxKeyCodes(&setup.minKeyCode, &setup.maxKeyCode);
  320.     
  321.     lenofblock = sizeof(xConnSetup) + 
  322.             ((setup.nbytesVendor + 3) & ~3) +
  323.         (setup.numFormats * sizeof(xPixmapFormat)) +
  324.             (setup.numRoots * sizeof(xWindowRoot));
  325.     ConnectionInfo = (char *) xalloc(lenofblock);
  326.     if (!ConnectionInfo)
  327.     return FALSE;
  328.  
  329.     bcopy((char *)&setup, ConnectionInfo, sizeof(xConnSetup));
  330.     sizesofar = sizeof(xConnSetup);
  331.     pBuf = ConnectionInfo + sizeof(xConnSetup);
  332.  
  333.     bcopy(VENDOR_STRING, pBuf, (int)setup.nbytesVendor);
  334.     sizesofar += setup.nbytesVendor;
  335.     pBuf += setup.nbytesVendor;
  336.     i = padlength[setup.nbytesVendor & 3];
  337.     sizesofar += i;
  338.     while (--i >= 0)
  339.         *pBuf++ = 0;
  340.     
  341.     for (i=0; i<screenInfo.numPixmapFormats; i++)
  342.     {
  343.     format.depth = screenInfo.formats[i].depth;
  344.     format.bitsPerPixel = screenInfo.formats[i].bitsPerPixel;
  345.     format.scanLinePad = screenInfo.formats[i].scanlinePad;
  346.     bcopy((char *)&format, pBuf, sizeof(xPixmapFormat));
  347.     pBuf += sizeof(xPixmapFormat);
  348.     sizesofar += sizeof(xPixmapFormat);
  349.     }
  350.  
  351.     connBlockScreenStart = sizesofar;
  352.     for (i=0; i<screenInfo.numScreens; i++) 
  353.     {
  354.     ScreenPtr    pScreen;
  355.     DepthPtr    pDepth;
  356.     VisualPtr    pVisual;
  357.  
  358.     pScreen = screenInfo.screens[i];
  359.     root.windowId = WindowTable[i]->drawable.id;
  360.     root.defaultColormap = pScreen->defColormap;
  361.     root.whitePixel = pScreen->whitePixel;
  362.     root.blackPixel = pScreen->blackPixel;
  363.     root.currentInputMask = 0;    /* filled in when sent */
  364.     root.pixWidth = pScreen->width;
  365.     root.pixHeight = pScreen->height;
  366.     root.mmWidth = pScreen->mmWidth;
  367.     root.mmHeight = pScreen->mmHeight;
  368.     root.minInstalledMaps = pScreen->minInstalledCmaps;
  369.     root.maxInstalledMaps = pScreen->maxInstalledCmaps; 
  370.     root.rootVisualID = pScreen->rootVisual;        
  371.     root.backingStore = pScreen->backingStoreSupport;
  372.     root.saveUnders = pScreen->saveUnderSupport != NotUseful;
  373.     root.rootDepth = pScreen->rootDepth;
  374.     root.nDepths = pScreen->numDepths;
  375.     bcopy((char *)&root, pBuf, sizeof(xWindowRoot));
  376.     sizesofar += sizeof(xWindowRoot);
  377.     pBuf += sizeof(xWindowRoot);
  378.  
  379.     pDepth = pScreen->allowedDepths;
  380.     for(j = 0; j < pScreen->numDepths; j++, pDepth++)
  381.     {
  382.         lenofblock += sizeof(xDepth) + 
  383.             (pDepth->numVids * sizeof(xVisualType));
  384.         pBuf = (char *)xrealloc(ConnectionInfo, lenofblock);
  385.         if (!pBuf)
  386.         {
  387.         xfree(ConnectionInfo);
  388.         return FALSE;
  389.         }
  390.         ConnectionInfo = pBuf;
  391.         pBuf += sizesofar;            
  392.         depth.depth = pDepth->depth;
  393.         depth.nVisuals = pDepth->numVids;
  394.         bcopy((char *)&depth, pBuf, sizeof(xDepth));
  395.         pBuf += sizeof(xDepth);
  396.         sizesofar += sizeof(xDepth);
  397.         for(k = 0; k < pDepth->numVids; k++)
  398.         {
  399.         vid = pDepth->vids[k];
  400.         for (pVisual = pScreen->visuals;
  401.              pVisual->vid != vid;
  402.              pVisual++)
  403.             ;
  404.         visual.visualID = vid;
  405.         visual.class = pVisual->class;
  406.         visual.bitsPerRGB = pVisual->bitsPerRGBValue;
  407.         visual.colormapEntries = pVisual->ColormapEntries;
  408.         visual.redMask = pVisual->redMask;
  409.         visual.greenMask = pVisual->greenMask;
  410.         visual.blueMask = pVisual->blueMask;
  411.         bcopy((char *)&visual, pBuf, sizeof(xVisualType));
  412.         pBuf += sizeof(xVisualType);
  413.         sizesofar += sizeof(xVisualType);
  414.         }
  415.     }
  416.     }
  417.     connSetupPrefix.success = xTrue;
  418.     connSetupPrefix.length = lenofblock/4;
  419.     connSetupPrefix.majorVersion = X_PROTOCOL;
  420.     connSetupPrefix.minorVersion = X_PROTOCOL_REVISION;
  421.     return TRUE;
  422. }
  423.  
  424. static int  screenPrivateCount;
  425.  
  426. static void
  427. ResetScreenPrivates()
  428. {
  429.     screenPrivateCount = 0;
  430. }
  431.  
  432. /* this can be called after some screens have been created,
  433.  * so we have to worry about resizing existing devPrivates
  434.  */
  435. int
  436. AllocateScreenPrivateIndex()
  437. {
  438.     int        index;
  439.     int        i;
  440.     ScreenPtr    pScreen;
  441.     DevUnion    *nprivs;
  442.  
  443.     index = screenPrivateCount++;
  444.     for (i = 0; i < screenInfo.numScreens; i++)
  445.     {
  446.     pScreen = screenInfo.screens[i];
  447.     nprivs = (DevUnion *)xrealloc(pScreen->devPrivates,
  448.                       screenPrivateCount * sizeof(DevUnion));
  449.     if (!nprivs)
  450.     {
  451.         screenPrivateCount--;
  452.         return -1;
  453.     }
  454.     pScreen->devPrivates = nprivs;
  455.     }
  456.     return index;
  457. }
  458.  
  459. Bool
  460. AllocateWindowPrivate(pScreen, index, amount)
  461.     register ScreenPtr pScreen;
  462.     int index;
  463.     unsigned amount;
  464. {
  465.     unsigned oldamount;
  466.  
  467.     if (index >= pScreen->WindowPrivateLen)
  468.     {
  469.     unsigned *nsizes;
  470.     nsizes = (unsigned *)xrealloc(pScreen->WindowPrivateSizes,
  471.                       (index + 1) * sizeof(unsigned));
  472.     if (!nsizes)
  473.         return FALSE;
  474.     while (pScreen->WindowPrivateLen <= index)
  475.     {
  476.         nsizes[pScreen->WindowPrivateLen++] = 0;
  477.         pScreen->totalWindowSize += sizeof(DevUnion);
  478.     }
  479.     pScreen->WindowPrivateSizes = nsizes;
  480.     }
  481.     oldamount = pScreen->WindowPrivateSizes[index];
  482.     if (amount > oldamount)
  483.     {
  484.     pScreen->WindowPrivateSizes[index] = amount;
  485.     pScreen->totalWindowSize += (amount - oldamount);
  486.     }
  487.     return TRUE;
  488. }
  489.  
  490. Bool
  491. AllocateGCPrivate(pScreen, index, amount)
  492.     register ScreenPtr pScreen;
  493.     int index;
  494.     unsigned amount;
  495. {
  496.     unsigned oldamount;
  497.  
  498.     if (index >= pScreen->GCPrivateLen)
  499.     {
  500.     unsigned *nsizes;
  501.     nsizes = (unsigned *)xrealloc(pScreen->GCPrivateSizes,
  502.                       (index + 1) * sizeof(unsigned));
  503.     if (!nsizes)
  504.         return FALSE;
  505.     while (pScreen->GCPrivateLen <= index)
  506.     {
  507.         nsizes[pScreen->GCPrivateLen++] = 0;
  508.         pScreen->totalGCSize += sizeof(DevUnion);
  509.     }
  510.     pScreen->GCPrivateSizes = nsizes;
  511.     }
  512.     oldamount = pScreen->GCPrivateSizes[index];
  513.     if (amount > oldamount)
  514.     {
  515.     pScreen->GCPrivateSizes[index] = amount;
  516.     pScreen->totalGCSize += (amount - oldamount);
  517.     }
  518.     return TRUE;
  519. }
  520.  
  521. /*
  522.     grow the array of screenRecs if necessary.
  523.     call the device-supplied initialization procedure 
  524. with its screen number, a pointer to its ScreenRec, argc, and argv.
  525.     return the number of successfully installed screens.
  526.  
  527. */
  528.  
  529. int
  530. AddScreen(pfnInit, argc, argv)
  531.     Bool    (* pfnInit)();
  532.     int argc;
  533.     char **argv;
  534. {
  535.  
  536.     int i;
  537.     int scanlinepad, format, depth, bitsPerPixel, j, k;
  538.     ScreenPtr pScreen;
  539. #ifdef DEBUG
  540.     void    (**jNI) ();
  541. #endif /* DEBUG */
  542.  
  543.     i = screenInfo.numScreens;
  544.     if (i == MAXSCREENS)
  545.     return -1;
  546.  
  547.     pScreen = (ScreenPtr) xalloc(sizeof(ScreenRec));
  548.     if (!pScreen)
  549.     return -1;
  550.  
  551.     pScreen->devPrivates = (DevUnion *)xalloc(screenPrivateCount *
  552.                           sizeof(DevUnion));
  553.     if (!pScreen->devPrivates && screenPrivateCount)
  554.     {
  555.     xfree(pScreen);
  556.     return -1;
  557.     }
  558.     pScreen->myNum = i;
  559.     pScreen->WindowPrivateLen = 0;
  560.     pScreen->WindowPrivateSizes = (unsigned *)NULL;
  561.     pScreen->totalWindowSize = sizeof(WindowRec);
  562.     pScreen->GCPrivateLen = 0;
  563.     pScreen->GCPrivateSizes = (unsigned *)NULL;
  564.     pScreen->totalGCSize = sizeof(GC);
  565.     pScreen->ClipNotify = (void (*)())NULL; /* for R4 ddx compatibility */
  566.     
  567. #ifdef DEBUG
  568.     for (jNI = &pScreen->QueryBestSize; 
  569.      jNI < (void (**) ()) &pScreen->SendGraphicsExpose;
  570.      jNI++)
  571.     *jNI = NotImplemented;
  572. #endif /* DEBUG */
  573.  
  574.     /*
  575.      * This loop gets run once for every Screen that gets added,
  576.      * but thats ok.  If the ddx layer initializes the formats
  577.      * one at a time calling AddScreen() after each, then each
  578.      * iteration will make it a little more accurate.  Worst case
  579.      * we do this loop N * numPixmapFormats where N is # of screens.
  580.      * Anyway, this must be called after InitOutput and before the
  581.      * screen init routine is called.
  582.      */
  583.     for (format=0; format<screenInfo.numPixmapFormats; format++)
  584.     {
  585.      depth = screenInfo.formats[format].depth;
  586.      bitsPerPixel = screenInfo.formats[format].bitsPerPixel;
  587.       scanlinepad = screenInfo.formats[format].scanlinePad;
  588.      j = indexForBitsPerPixel[ bitsPerPixel ];
  589.       k = indexForScanlinePad[ scanlinepad ];
  590.      PixmapWidthPaddingInfo[ depth ].padPixelsLog2 = answer[j][k];
  591.      PixmapWidthPaddingInfo[ depth ].padRoundUp =
  592.          (scanlinepad/bitsPerPixel) - 1;
  593.      j = indexForBitsPerPixel[ 8 ]; /* bits per byte */
  594.      PixmapWidthPaddingInfo[ depth ].padBytesLog2 = answer[j][k];
  595.     }
  596.   
  597.     /* This is where screen specific stuff gets initialized.  Load the
  598.        screen structure, call the hardware, whatever.
  599.        This is also where the default colormap should be allocated and
  600.        also pixel values for blackPixel, whitePixel, and the cursor
  601.        Note that InitScreen is NOT allowed to modify argc, argv, or
  602.        any of the strings pointed to by argv.  They may be passed to
  603.        multiple screens. 
  604.     */ 
  605.     pScreen->rgf = ~0L;  /* there are no scratch GCs yet*/
  606.     WindowTable[i] = NullWindow;
  607.     screenInfo.screens[i] = pScreen;
  608.     screenInfo.numScreens++;
  609.     if (!(*pfnInit)(i, pScreen, argc, argv))
  610.     {
  611.     FreeScreen(pScreen);
  612.     screenInfo.numScreens--;
  613.     return -1;
  614.     }
  615.     return i;
  616. }
  617.  
  618. static void
  619. FreeScreen(pScreen)
  620.     ScreenPtr pScreen;
  621. {
  622.     xfree(pScreen->WindowPrivateSizes);
  623.     xfree(pScreen->GCPrivateSizes);
  624.     xfree(pScreen->devPrivates);
  625.     xfree(pScreen);
  626. }
  627.