home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume14 / ultrix.patch / part01 / server / ddx / dec / ws / cfbinit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-26  |  9.9 KB  |  392 lines

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