home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / dec / ws / cfbinit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-08  |  10.0 KB  |  393 lines

  1. /* $XConsortium: cfbinit.c,v 1.2 91/07/08 11:16:22 keith Exp $ */
  2. /***********************************************************
  3. Copyright 1991 by Digital Equipment Corporation, Maynard, Massachusetts,
  4. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  5.  
  6.                         All Rights Reserved
  7.  
  8. Permission to use, copy, modify, and distribute this software and its 
  9. documentation for any purpose and without fee is hereby granted, 
  10. provided that the above copyright notice appear in all copies and that
  11. both that copyright notice and this permission notice appear in 
  12. supporting documentation, and that the names of Digital or MIT not be
  13. used in advertising or publicity pertaining to distribution of the
  14. software without specific, written prior permission.  
  15.  
  16. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  17. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  18. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  19. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  20. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  21. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  22. SOFTWARE.
  23.  
  24. ******************************************************************/
  25. /*     
  26.     Todo. 
  27.     -----
  28.   ****    Fix plane mask handling.  The screen devprivate should have
  29.     a hardware specific planemask setting proc.  For now, since
  30.     pmax is the only machine with a plane mask, so keep it global
  31.     for now.
  32. */
  33.  
  34. #include <stdio.h>
  35. #include <sys/types.h>
  36. #include <sys/file.h>
  37. #include <sys/time.h>
  38. #include <sys/tty.h>
  39. #include <errno.h>
  40. #include <sys/devio.h>
  41.  
  42.  
  43. #include "misc.h"
  44. #include "X.h"
  45. #include "scrnintstr.h"
  46. #include "pixmap.h"
  47. #include "input.h"
  48. #include "cursorstr.h"
  49. #include "regionstr.h"
  50. #include "resource.h"
  51. #include "dixstruct.h"
  52.  
  53. #include <sys/workstation.h>
  54. #include <sys/inputdevice.h>
  55. #include "ws.h"
  56.  
  57. #include "mfb.h"
  58.  
  59. extern int wsScreenPrivateIndex;
  60. extern int lastEventTime;
  61. extern int defaultColorVisualClass;
  62. void wsQueryBestSize();
  63. Bool wsRealizeCursor();
  64. Bool wsUnrealizeCursor();
  65. Bool wsDisplayCursor();
  66. void wsRecolorCursor();
  67. void wsCursorControl();
  68. Bool wsSetCursorPosition();
  69. void wsCursorLimits();
  70. void wsConstrainCursor();
  71. void wsPointerNonInterestBox();
  72. void wsChangeKeyboardControl();
  73. void wsChangePointerControl();
  74. void wsClick();
  75.  
  76. extern    ws_event_queue    *queue;
  77. #undef VSYNCFIXED
  78. #ifdef VSYNCFIXED
  79. #define CURRENT_TIME    queue->time
  80. #else
  81. #define CURRENT_TIME    GetTimeInMillis()
  82. #endif
  83.  
  84. extern int wsScreenInit();
  85. extern void miRecolorCursor();
  86. extern void NoopDDA();
  87. extern void NewCurrentScreen();
  88. extern int wsFd;
  89. extern ws_screen_descriptor screenDesc[];
  90. static ws_depth_descriptor depthDesc[MAXSCREENS];
  91. static mapped[MAXSCREENS];
  92. char *planemask_addr;
  93.  
  94. /*
  95.  * XXX  this needs to get fixed to accept a screen!!!  jmg
  96.  */
  97. unsigned int
  98. cfbpmaxSetPlaneMask(planemask, pScreen)
  99.     unsigned int planemask;
  100.     ScreenPtr *pScreen;
  101. {
  102.     static unsigned int currentmask = ~0;
  103.     unsigned int result = currentmask;
  104.     if(planemask_addr == 0)
  105.     {
  106.     currentmask =  planemask;
  107.     }
  108.     else
  109.     {
  110.         *planemask_addr = currentmask = planemask;
  111.  
  112.     }
  113.     return result;
  114. }
  115.  
  116.  
  117. void
  118. wsQueryBestSize16(class, pwidth, pheight)
  119.     int class;
  120.     short *pwidth;
  121.     short *pheight;
  122. {
  123.     unsigned width, test;
  124.  
  125.     if (*pwidth > 0)
  126.     {
  127.       switch(class)
  128.       {
  129.         case CursorShape:
  130.       *pwidth = 16;
  131.       *pheight = 16;
  132.       break;
  133.     default: 
  134.       mfbQueryBestSize(class, pwidth, pheight);
  135.       break;
  136.        }
  137.     }
  138. }
  139.  
  140.  
  141. void
  142. wsQueryBestSize64(class, pwidth, pheight)
  143.     int class;
  144.     short *pwidth;
  145.     short *pheight;
  146. {
  147.     unsigned width, test;
  148.  
  149.     if (*pwidth > 0)
  150.     {
  151.       switch(class)
  152.       {
  153.         case CursorShape:
  154.       *pwidth = 64;
  155.       *pheight = 64;
  156.       break;
  157.     default: 
  158.       mfbQueryBestSize(class, pwidth, pheight);
  159.       break;
  160.        }
  161.     }
  162. }
  163.  
  164. Bool
  165. wsScreenClose(index, pScreen)
  166.     int index;
  167.     ScreenPtr pScreen;
  168. {
  169.     wsScreenPrivate *wsp = (wsScreenPrivate *)
  170.         pScreen->devPrivates[wsScreenPrivateIndex].ptr;
  171.  
  172.     pScreen->CloseScreen = wsp->CloseScreen;
  173.     Xfree(wsp);
  174.     return (*pScreen->CloseScreen) (index, pScreen);
  175. }
  176.  
  177.  
  178. static void
  179. colorNameToColor( pname, pred, pgreen, pblue)
  180.     char *      pname;
  181.     unsigned short *     pred;
  182.     unsigned short *     pgreen;
  183.     unsigned short *     pblue;
  184. {
  185.     if ( *pname == '#')
  186.     {
  187.         pname++;                /* skip over # */
  188.         sscanf( pname, "%2x", pred);
  189.         *pred <<= 8;
  190.  
  191.         pname += 2;
  192.         sscanf( pname, "%2x", pgreen);
  193.         *pgreen <<= 8;
  194.  
  195.         pname += 2;
  196.         sscanf( pname, "%2x", pblue);
  197.         *pblue <<= 8;
  198.     }
  199.     else /* named color */
  200.     {
  201.         OsLookupColor( 0 /*"screen", not used*/, pname, strlen( pname),
  202.                 pred, pgreen, pblue);
  203.     }
  204. }
  205.  
  206.  
  207. Bool
  208. fbInitProc(index, pScreen, argc, argv)
  209.     int index;
  210.     ScreenPtr pScreen;
  211.     int argc;
  212.     char **argv;
  213. {
  214.     register    PixmapPtr pPixmap;
  215.     int        dpix, dpiy, i;
  216.     static int  mapOnce = FALSE;
  217.     wsScreenPrivate *wsp;
  218.     Bool success = FALSE;
  219.     ws_depth_descriptor *dd;
  220.     ws_visual_descriptor vd;
  221.     static ws_map_control mc;
  222.     VisualPtr        pVisual;
  223.     ColormapPtr        pCmap;
  224. /* for initializing color map entries */
  225.     unsigned short blackred      = 0x0000;
  226.     unsigned short blackgreen    = 0x0000; 
  227.     unsigned short blackblue     = 0x0000;
  228.  
  229.     unsigned short whitered      = 0xffff;
  230.     unsigned short whitegreen    = 0xffff;
  231.     unsigned short whiteblue     = 0xffff;
  232.  
  233.     lastEventTime = CURRENT_TIME;
  234.  
  235.     wsp = (wsScreenPrivate *) Xalloc(sizeof(wsScreenPrivate));
  236.     wsp->pInstalledMap = NOMAPYET;
  237.     pScreen->devPrivates[wsScreenPrivateIndex].ptr = (pointer) wsp;
  238.  
  239.     wsp->screenDesc = &screenDesc[index];    
  240.     wsp->args = &screenArgs[index];
  241.  
  242.     /* since driver does not support unmap (yet), only map screen once */
  243.     if (! mapped[index]) {
  244.     depthDesc[index].screen = screenDesc[index].screen;
  245.     for (i = 0; i < wsp->screenDesc->allowed_depths; i++) {
  246.         depthDesc[index].which_depth = i;    
  247.         if (ioctl(wsFd, GET_DEPTH_INFO, &depthDesc[index]) == -1) {
  248.             ErrorF("GET_DEPTH_INFO failed");
  249.             exit (1);
  250.         }
  251.         if (depthDesc[index].depth == 8 ||depthDesc[index].depth == 1){
  252.             success = TRUE;
  253.             break;
  254.         }
  255.     }
  256.     if (!success) return FALSE;
  257.  
  258.     mc.screen = screenDesc[index].screen;
  259.     mc.which_depth = i;
  260.     mc.map_unmap = MAP_SCREEN;
  261.     if (ioctl(wsFd,  MAP_SCREEN_AT_DEPTH, &mc) == -1)    {
  262.         ErrorF("MAP_SCREEN_AT_DEPTH failed");
  263.         free ((char *) wsp);
  264.         return FALSE;
  265.     }
  266.     /* 
  267.      * reget the depth desc.  It now contains the user-mapped bitmap
  268.      * addr. 
  269.      */
  270.     if (ioctl(wsFd, GET_DEPTH_INFO, &depthDesc[index]) == -1) 
  271.     {
  272.         ErrorF("GET_DEPTH_INFO failed");
  273.         return FALSE;
  274.     }
  275.     mapped[index] = TRUE;
  276.     }
  277.  
  278.     /* ws routines knows how to initialize many functions, so call init. */
  279.     if (wsScreenInit(index, pScreen, argc, argv) == -1) 
  280.     return FALSE;
  281.  
  282.     dd = &depthDesc[index];
  283.  
  284.     if (index > 0) 
  285.     wsCursorControl(index, CURSOR_OFF);
  286.     wsScreens[index] = pScreen;
  287.  
  288. /* 
  289.  * this is really dumb.  The driver has the screen geometry in mm.
  290.  * The screen wants it stored as mm, but the damn interface passes
  291.  * inches.  mm => inches => mm.  What a waste.  Should we change cfbscrinit.c?
  292.  * -jmg.
  293.  */
  294.  
  295.     if (screenArgs[index].flags & ARG_DPIX)
  296.     dpix = screenArgs[index].dpix;
  297.     else
  298.     dpix =  ( wsp->screenDesc->width)  / 
  299.         ((wsp->screenDesc->monitor_type.mm_width  * 10) / 254);
  300.  
  301.     if (screenArgs[index].flags & ARG_DPIY)
  302.     dpiy = screenArgs[index].dpiy;
  303.     else
  304.     dpiy =  ( wsp->screenDesc->height) / 
  305.         ((wsp->screenDesc->monitor_type.mm_height * 10) / 254);
  306.  
  307.     vd.screen = screenDesc[index].screen; 
  308.     vd.which_visual = 0;    /* jmg ? */
  309.      if (ioctl(wsFd, GET_VISUAL_INFO, &vd) == -1) 
  310.      {
  311.          ErrorF("GET_VISUAL_INFO failed");
  312.         return FALSE;
  313.     }
  314.  
  315.     defaultColorVisualClass = vd.screen_class;
  316.     if(screenArgs[index].flags & ARG_CLASS) 
  317.     defaultColorVisualClass = screenArgs[index].class;
  318.  
  319.     /* Might want to make this table driven  - jmg */
  320.  
  321.     switch (dd->bits_per_pixel)
  322.     {
  323.     case 1:
  324.     if (!mfbScreenInit(pScreen, dd->pixmap, wsp->screenDesc->width,
  325.         wsp->screenDesc->height, dpix, dpiy, dd->fb_width))
  326.     {
  327.         return FALSE;
  328.     }
  329.     pScreen->blackPixel = 0;
  330.     pScreen->whitePixel = 1;
  331.         if(screenArgs[index].flags & ARG_BLACKVALUE)
  332.         if((i = atoi(screenArgs[index].blackValue)) == 0 || i == 1)
  333.             pScreen->blackPixel = i;
  334.         else
  335.             wsPixelError(index);
  336.     
  337.         if(screenArgs[index].flags & ARG_WHITEVALUE)
  338.         if((i = atoi(screenArgs[index].whiteValue)) == 0 || i == 1)
  339.             pScreen->whitePixel = i;
  340.         else
  341.             wsPixelError(index);
  342.     if (!(mfbCreateDefColormap (pScreen)))
  343.         return FALSE;
  344.     break;
  345.     case 8:
  346.     if (!cfbScreenInit(pScreen, dd->pixmap, wsp->screenDesc->width,
  347.         wsp->screenDesc->height, dpix, dpiy, dd->fb_width))
  348.     {
  349.         return FALSE;
  350.     }
  351.         if(screenArgs[index].flags & ARG_BLACKVALUE)
  352.         colorNameToColor(screenArgs[index].blackValue, &blackred,
  353.                  &blackgreen, &blackblue); 
  354.     
  355.         if(screenArgs[index].flags & ARG_WHITEVALUE)
  356.         colorNameToColor(screenArgs[index].whiteValue, &whitered, 
  357.                 &whitegreen, &whiteblue);
  358.  
  359.     /* copy of cfbCreateDefColormap, except variable colors */
  360.         for (pVisual = pScreen->visuals;
  361.          pVisual->vid != pScreen->rootVisual;
  362.          pVisual++)
  363.         ;
  364.     
  365.         if (CreateColormap(pScreen->defColormap, pScreen, pVisual, &pCmap,
  366.                       (pVisual->class & DynamicClass) ? AllocNone : AllocAll,
  367.                       0)
  368.         != Success)
  369.         return FALSE;
  370.         if ((AllocColor(pCmap, &whitered, &whitegreen, &whiteblue,
  371.                 &(pScreen->whitePixel), 0) != Success) ||
  372.             (AllocColor(pCmap, &blackred, &blackgreen, &blackblue,
  373.                 &(pScreen->blackPixel), 0) != Success))
  374.     {
  375.             return FALSE;
  376.     }
  377.         (*pScreen->InstallColormap)(pCmap);
  378.     break;
  379.     }
  380.  
  381.     planemask_addr = dd->plane_mask;
  382.     
  383.     /* Wrap screen close routine to avoid memory leak */
  384.     wsp->CloseScreen = pScreen->CloseScreen;
  385.     pScreen->CloseScreen = wsScreenClose;
  386.  
  387.     if(wsp->screenDesc->cursor_width == 64)
  388.      pScreen->QueryBestSize = wsQueryBestSize64;
  389.     else
  390.      pScreen->QueryBestSize = wsQueryBestSize16;
  391.     return TRUE;
  392. }
  393.