home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / cfb / cfbscrinit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-28  |  6.5 KB  |  203 lines

  1. /************************************************************
  2. Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA.
  3.  
  4.                     All Rights Reserved
  5.  
  6. Permission  to  use,  copy,  modify,  and  distribute   this
  7. software  and  its documentation for any purpose and without
  8. fee is hereby granted, provided that the above copyright no-
  9. tice  appear  in all copies and that both that copyright no-
  10. tice and this permission notice appear in  supporting  docu-
  11. mentation,  and  that the names of Sun or MIT not be used in
  12. advertising or publicity pertaining to distribution  of  the
  13. software  without specific prior written permission. Sun and
  14. M.I.T. make no representations about the suitability of this
  15. software for any purpose. It is provided "as is" without any
  16. express or implied warranty.
  17.  
  18. SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO  THIS  SOFTWARE,
  19. INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
  20. NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE  LI-
  21. ABLE  FOR  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  22. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,  DATA  OR
  23. PROFITS,  WHETHER  IN  AN  ACTION OF CONTRACT, NEGLIGENCE OR
  24. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
  25. THE USE OR PERFORMANCE OF THIS SOFTWARE.
  26.  
  27. ********************************************************/
  28. /* $XConsortium: cfbscrinit.c,v 5.19 91/06/28 12:40:07 keith Exp $ */
  29.  
  30. #include "X.h"
  31. #include "Xmd.h"
  32. #include "servermd.h"
  33. #include "scrnintstr.h"
  34. #include "pixmapstr.h"
  35. #include "resource.h"
  36. #include "colormap.h"
  37. #include "colormapst.h"
  38. #include "cfb.h"
  39. #include "mi.h"
  40. #include "mistruct.h"
  41. #include "dix.h"
  42. #include "cfbmskbits.h"
  43. #include "mibstore.h"
  44.  
  45. extern RegionPtr mfbPixmapToRegion();
  46. extern RegionPtr cfbCopyPlane();
  47. extern Bool mfbAllocatePrivates();
  48.  
  49. extern int defaultColorVisualClass;
  50.  
  51. #define _BP 8
  52. #define _RZ ((PSZ + 2) / 3)
  53. #define _RS 0
  54. #define _RM ((1 << _RZ) - 1)
  55. #define _GZ ((PSZ - _RZ + 1) / 2)
  56. #define _GS _RZ
  57. #define _GM (((1 << _GZ) - 1) << _GS)
  58. #define _BZ (PSZ - _RZ - _GZ)
  59. #define _BS (_RZ + _GZ)
  60. #define _BM (((1 << _BZ) - 1) << _BS)
  61. #define _CE (1 << _RZ)
  62.  
  63. static VisualRec visuals[] = {
  64. /* vid  class        bpRGB cmpE nplan rMask gMask bMask oRed oGreen oBlue */
  65. #ifndef STATIC_COLOR
  66.     0,  PseudoColor, _BP,  1<<PSZ,   PSZ,  0,   0,   0,   0,   0,   0,
  67.     0,  DirectColor, _BP, _CE,       PSZ,  _RM, _GM, _BM, _RS, _GS, _BS,
  68.     0,  GrayScale,   _BP,  1<<PSZ,   PSZ,  0,   0,   0,   0,   0,   0,
  69.     0,  StaticGray,  _BP,  1<<PSZ,   PSZ,  0,   0,   0,   0,   0,   0,
  70. #endif
  71.     0,  StaticColor, _BP,  1<<PSZ,   PSZ,  _RM, _GM, _BM, _RS, _GS, _BS,
  72.     0,  TrueColor,   _BP, _CE,       PSZ,  _RM, _GM, _BM, _RS, _GS, _BS
  73. };
  74.  
  75. #define    NUMVISUALS    ((sizeof visuals)/(sizeof visuals[0]))
  76.  
  77. static  VisualID VIDs[NUMVISUALS];
  78.  
  79. static DepthRec depths[] = {
  80. /* depth    numVid        vids */
  81.     1,        0,        NULL,
  82.     8,        NUMVISUALS,    VIDs
  83. };
  84.  
  85. #define NUMDEPTHS    ((sizeof depths)/(sizeof depths[0]))
  86.  
  87. int cfbWindowPrivateIndex;
  88. int cfbGCPrivateIndex;
  89.  
  90. static unsigned long cfbGeneration = 0;
  91.  
  92. miBSFuncRec cfbBSFuncRec = {
  93.     cfbSaveAreas,
  94.     cfbRestoreAreas,
  95.     (void (*)()) 0,
  96.     (PixmapPtr (*)()) 0,
  97.     (PixmapPtr (*)()) 0,
  98. };
  99.  
  100. Bool
  101. cfbSetupScreen(pScreen, pbits, xsize, ysize, dpix, dpiy, width)
  102.     register ScreenPtr pScreen;
  103.     pointer pbits;        /* pointer to screen bitmap */
  104.     int xsize, ysize;        /* in pixels */
  105.     int dpix, dpiy;        /* dots per inch */
  106.     int width;            /* pixel width of frame buffer */
  107. {
  108.     int    i;
  109.  
  110.     if (cfbGeneration != serverGeneration)
  111.     {
  112.     /*  Set up the visual IDs */
  113.     for (i = 0; i < NUMVISUALS; i++) {
  114.         visuals[i].vid = FakeClientID(0);
  115.         VIDs[i] = visuals[i].vid;
  116.     }
  117.     cfbGeneration = serverGeneration;
  118.     }
  119.     if (!mfbAllocatePrivates(pScreen,
  120.                  &cfbWindowPrivateIndex, &cfbGCPrivateIndex))
  121.     return FALSE;
  122.     if (!AllocateWindowPrivate(pScreen, cfbWindowPrivateIndex,
  123.                    sizeof(cfbPrivWin)) ||
  124.     !AllocateGCPrivate(pScreen, cfbGCPrivateIndex, sizeof(cfbPrivGC)))
  125.     return FALSE;
  126.     pScreen->defColormap = FakeClientID(0);
  127.     /* let CreateDefColormap do whatever it wants for pixels */ 
  128.     pScreen->blackPixel = pScreen->whitePixel = (Pixel) 0;
  129.     pScreen->QueryBestSize = mfbQueryBestSize;
  130.     /* SaveScreen */
  131.     pScreen->GetImage = cfbGetImage;
  132.     pScreen->GetSpans = cfbGetSpans;
  133.     pScreen->CreateWindow = cfbCreateWindow;
  134.     pScreen->DestroyWindow = cfbDestroyWindow;
  135.     pScreen->PositionWindow = cfbPositionWindow;
  136.     pScreen->ChangeWindowAttributes = cfbChangeWindowAttributes;
  137.     pScreen->RealizeWindow = cfbMapWindow;
  138.     pScreen->UnrealizeWindow = cfbUnmapWindow;
  139.     pScreen->PaintWindowBackground = cfbPaintWindow;
  140.     pScreen->PaintWindowBorder = cfbPaintWindow;
  141.     pScreen->CopyWindow = cfbCopyWindow;
  142.     pScreen->CreatePixmap = cfbCreatePixmap;
  143.     pScreen->DestroyPixmap = cfbDestroyPixmap;
  144.     pScreen->RealizeFont = mfbRealizeFont;
  145.     pScreen->UnrealizeFont = mfbUnrealizeFont;
  146.     pScreen->CreateGC = cfbCreateGC;
  147.     pScreen->CreateColormap = cfbInitializeColormap;
  148.     pScreen->DestroyColormap = NoopDDA;
  149. #ifdef    STATIC_COLOR
  150.     pScreen->InstallColormap = cfbInstallColormap;
  151.     pScreen->UninstallColormap = cfbUninstallColormap;
  152.     pScreen->ListInstalledColormaps = cfbListInstalledColormaps;
  153.     pScreen->StoreColors = NoopDDA;
  154. #endif
  155.     pScreen->ResolveColor = cfbResolveColor;
  156.     pScreen->BitmapToRegion = mfbPixmapToRegion;
  157.  
  158.     mfbRegisterCopyPlaneProc (pScreen, cfbCopyPlane);
  159.     return TRUE;
  160. }
  161.  
  162. cfbFinishScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width)
  163.     register ScreenPtr pScreen;
  164.     pointer pbits;        /* pointer to screen bitmap */
  165.     int xsize, ysize;        /* in pixels */
  166.     int dpix, dpiy;        /* dots per inch */
  167.     int width;            /* pixel width of frame buffer */
  168. {
  169.     int    i;
  170.  
  171.     if (defaultColorVisualClass < 0)
  172.     {
  173.     i = 0;
  174.     }
  175.     else
  176.     {
  177.     for (i = 0;
  178.          (i < NUMVISUALS) && (visuals[i].class != defaultColorVisualClass);
  179.          i++)
  180.         ;
  181.     if (i >= NUMVISUALS)
  182.         i = 0;
  183.     }
  184.     return miScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width,
  185.             8, NUMDEPTHS, depths,
  186.             visuals[i].vid, NUMVISUALS, visuals,
  187.             &cfbBSFuncRec);
  188. }
  189.  
  190. /* dts * (inch/dot) * (25.4 mm / inch) = mm */
  191. Bool
  192. cfbScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width)
  193.     register ScreenPtr pScreen;
  194.     pointer pbits;        /* pointer to screen bitmap */
  195.     int xsize, ysize;        /* in pixels */
  196.     int dpix, dpiy;        /* dots per inch */
  197.     int width;            /* pixel width of frame buffer */
  198. {
  199.     if (!cfbSetupScreen(pScreen, pbits, xsize, ysize, dpix, dpiy, width))
  200.     return FALSE;
  201.     return cfbFinishScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width);
  202. }
  203.