home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / sun / sunCG.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-23  |  6.8 KB  |  256 lines

  1. /*
  2.  * $XConsortium: sunCG.c,v 1.4 91/08/23 16:11:04 keith Exp $
  3.  *
  4.  * Copyright 1990 Massachusetts Institute of Technology
  5.  *
  6.  * Permission to use, copy, modify, distribute, and sell this software and its
  7.  * documentation for any purpose is hereby granted without fee, provided that
  8.  * the above copyright notice appear in all copies and that both that
  9.  * copyright notice and this permission notice appear in supporting
  10.  * documentation, and that the name of M.I.T. not be used in advertising or
  11.  * publicity pertaining to distribution of the software without specific,
  12.  * written prior permission.  M.I.T. makes no representations about the
  13.  * suitability of this software for any purpose.  It is provided "as is"
  14.  * without express or implied warranty.
  15.  *
  16.  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  17.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  18.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  20.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
  21.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  *
  23.  * Author:  Keith Packard, MIT X Consortium
  24.  */
  25.  
  26. /*
  27.  * sunCG.c
  28.  *
  29.  * Routines for managing a sun colormap
  30.  */
  31.  
  32. #include    "sun.h"
  33.  
  34. #include    <sys/mman.h>
  35. #include    <pixrect/memreg.h>
  36. #include    "colormapst.h"
  37. #include    "resource.h"
  38. #include    <struct.h>
  39.  
  40. extern int TellLostMap(), TellGainedMap();
  41.  
  42. static void
  43. sunCGUpdateColormap(pScreen, index, count, rmap, gmap, bmap)
  44.     ScreenPtr    pScreen;
  45.     int        index, count;
  46.     u_char    *rmap, *gmap, *bmap;
  47. {
  48.     struct fbcmap sunCmap;
  49.  
  50.     sunCmap.index = index;
  51.     sunCmap.count = count;
  52.     sunCmap.red = &rmap[index];
  53.     sunCmap.green = &gmap[index];
  54.     sunCmap.blue = &bmap[index];
  55.  
  56. #ifdef SUN_WINDOWS
  57.     if (sunUseSunWindows()) {
  58.     static Pixwin *pw = 0;
  59.  
  60.     if (! pw) {
  61.         if ( ! (pw = pw_open(windowFd)) )
  62.         FatalError( "sunCGUpdateColormap: pw_open failed\n" );
  63.         pw_setcmsname(pw, "X.V11");
  64.     }
  65.     pw_putcolormap(
  66.         pw, index, count, &rmap[index], &gmap[index], &bmap[index]);
  67.     }
  68. #endif SUN_WINDOWS
  69.  
  70.     if (ioctl(sunFbs[pScreen->myNum].fd, FBIOPUTCMAP, &sunCmap) < 0) {
  71.     perror("sunCGUpdateColormap");
  72.     FatalError( "sunCGUpdateColormap: FBIOPUTCMAP failed\n" );
  73.     }
  74. }
  75.  
  76.  
  77. /*-
  78.  *-----------------------------------------------------------------------
  79.  * sunCGInstallColormap --
  80.  *    Install given colormap.
  81.  *
  82.  * Results:
  83.  *    None
  84.  *
  85.  * Side Effects:
  86.  *    Existing map is uninstalled.
  87.  *    All clients requesting ColormapNotify are notified
  88.  *
  89.  *-----------------------------------------------------------------------
  90.  */
  91. static void
  92. sunCGInstallColormap(cmap)
  93.     ColormapPtr    cmap;
  94. {
  95.     SetupScreen(cmap->pScreen);
  96.     register int i;
  97.     register Entry *pent;
  98.     register VisualPtr pVisual = cmap->pVisual;
  99.     u_char      rmap[256], gmap[256], bmap[256];
  100.  
  101.     if (cmap == pPrivate->installedMap)
  102.     return;
  103.     if (pPrivate->installedMap)
  104.     WalkTree(pPrivate->installedMap->pScreen, TellLostMap,
  105.          (pointer) &(pPrivate->installedMap->mid));
  106.     if ((pVisual->class | DynamicClass) == DirectColor) {
  107.     for (i = 0; i < 256; i++) {
  108.         pent = &cmap->red[(i & pVisual->redMask) >>
  109.                   pVisual->offsetRed];
  110.         rmap[i] = pent->co.local.red >> 8;
  111.         pent = &cmap->green[(i & pVisual->greenMask) >>
  112.                 pVisual->offsetGreen];
  113.         gmap[i] = pent->co.local.green >> 8;
  114.         pent = &cmap->blue[(i & pVisual->blueMask) >>
  115.                    pVisual->offsetBlue];
  116.         bmap[i] = pent->co.local.blue >> 8;
  117.     }
  118.     } else {
  119.     for (i = 0, pent = cmap->red;
  120.          i < pVisual->ColormapEntries;
  121.          i++, pent++) {
  122.         if (pent->fShared) {
  123.         rmap[i] = pent->co.shco.red->color >> 8;
  124.         gmap[i] = pent->co.shco.green->color >> 8;
  125.         bmap[i] = pent->co.shco.blue->color >> 8;
  126.         }
  127.         else {
  128.         rmap[i] = pent->co.local.red >> 8;
  129.         gmap[i] = pent->co.local.green >> 8;
  130.         bmap[i] = pent->co.local.blue >> 8;
  131.         }
  132.     }
  133.     }
  134.     pPrivate->installedMap = cmap;
  135.     (*pPrivate->UpdateColormap) (cmap->pScreen, 0, 256, rmap, gmap, bmap);
  136.     WalkTree(cmap->pScreen, TellGainedMap, (pointer) &(cmap->mid));
  137. }
  138.  
  139. /*-
  140.  *-----------------------------------------------------------------------
  141.  * sunCGUninstallColormap --
  142.  *    Uninstall given colormap.
  143.  *
  144.  * Results:
  145.  *    None
  146.  *
  147.  * Side Effects:
  148.  *    default map is installed
  149.  *    All clients requesting ColormapNotify are notified
  150.  *
  151.  *-----------------------------------------------------------------------
  152.  */
  153. static void
  154. sunCGUninstallColormap(cmap)
  155.     ColormapPtr    cmap;
  156. {
  157.     SetupScreen(cmap->pScreen);
  158.     if (cmap == pPrivate->installedMap) {
  159.     Colormap defMapID = cmap->pScreen->defColormap;
  160.  
  161.     if (cmap->mid != defMapID) {
  162.         ColormapPtr defMap = (ColormapPtr) LookupIDByType(defMapID,
  163.                                   RT_COLORMAP);
  164.  
  165.         if (defMap)
  166.         (*cmap->pScreen->InstallColormap)(defMap);
  167.         else
  168.             ErrorF("sunCG: Can't find default colormap\n");
  169.     }
  170.     }
  171. }
  172.  
  173. /*-
  174.  *-----------------------------------------------------------------------
  175.  * sunCGListInstalledColormaps --
  176.  *    Fills in the list with the IDs of the installed maps
  177.  *
  178.  * Results:
  179.  *    Returns the number of IDs in the list
  180.  *
  181.  * Side Effects:
  182.  *    None
  183.  *
  184.  *-----------------------------------------------------------------------
  185.  */
  186. /*ARGSUSED*/
  187. static int
  188. sunCGListInstalledColormaps(pScreen, pCmapList)
  189.     ScreenPtr    pScreen;
  190.     Colormap    *pCmapList;
  191. {
  192.     SetupScreen(pScreen);
  193.     *pCmapList = pPrivate->installedMap->mid;
  194.     return (1);
  195. }
  196.  
  197.  
  198. /*-
  199.  *-----------------------------------------------------------------------
  200.  * sunCGStoreColors --
  201.  *    Sets the pixels in pdefs into the specified map.
  202.  *
  203.  * Results:
  204.  *    None
  205.  *
  206.  * Side Effects:
  207.  *    None
  208.  *
  209.  *-----------------------------------------------------------------------
  210.  */
  211. static void
  212. sunCGStoreColors(pmap, ndef, pdefs)
  213.     ColormapPtr    pmap;
  214.     int        ndef;
  215.     xColorItem    *pdefs;
  216. {
  217.     SetupScreen(pmap->pScreen);
  218.     u_char    rmap[256], gmap[256], bmap[256];
  219.     xColorItem    expanddefs[256];
  220.     register int i;
  221.  
  222.     if (pmap != pPrivate->installedMap)
  223.     return;
  224.     if ((pmap->pVisual->class | DynamicClass) == DirectColor) {
  225.     ndef = cfbExpandDirectColors(pmap, ndef, pdefs, expanddefs);
  226.     pdefs = expanddefs;
  227.     }
  228.     while (ndef--) {
  229.     i = pdefs->pixel;
  230.     rmap[i] = pdefs->red >> 8;
  231.     gmap[i] = pdefs->green >> 8;
  232.     bmap[i] = pdefs->blue >> 8;
  233.     (*pPrivate->UpdateColormap) (pmap->pScreen, i, 1, rmap, gmap, bmap);
  234.     pdefs++;
  235.     }
  236. }
  237.  
  238. sunCGScreenInit (pScreen)
  239.     ScreenPtr    pScreen;
  240. {
  241. #ifndef STATIC_COLOR
  242.     extern Bool    FlipPixels;
  243.     SetupScreen (pScreen);
  244.     pScreen->InstallColormap = sunCGInstallColormap;
  245.     pScreen->UninstallColormap = sunCGUninstallColormap;
  246.     pScreen->ListInstalledColormaps = sunCGListInstalledColormaps;
  247.     pScreen->StoreColors = sunCGStoreColors;
  248.     pPrivate->UpdateColormap = sunCGUpdateColormap;
  249.     if (FlipPixels)
  250.     {
  251.     pScreen->whitePixel = 1;
  252.     pScreen->blackPixel = 0;
  253.     }
  254. #endif
  255. }
  256.