home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / src / exampleCode / opengl / GLUT / lib / glut / layerutil.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-11  |  5.4 KB  |  189 lines

  1.  
  2. /* Copyright (c) Mark J. Kilgard, 1993, 1994. */
  3.  
  4. /* This program is freely distributable without licensing fees
  5.    and is provided without guarantee or warrantee expressed or
  6.    implied. This program is -not- in the public domain. */
  7.  
  8. /* Based on XLayerUtil.c: Revision: 1.5 */
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include "layerutil.h"
  13.  
  14. Bool layersRead = False;
  15. OverlayInfo **overlayInfoPerScreen;
  16. unsigned long *numOverlaysPerScreen;
  17.  
  18. void
  19. findServerOverlayVisualsInfo(Display * dpy)
  20. {
  21.   static Atom overlayVisualsAtom;
  22.   Atom actualType;
  23.   Status status;
  24.   unsigned long sizeData, bytesLeft;
  25.   Window root;
  26.   int actualFormat, numScreens, i;
  27.  
  28.   if (layersRead == False) {
  29.     overlayVisualsAtom = XInternAtom(dpy,
  30.       "SERVER_OVERLAY_VISUALS", True);
  31.     if (overlayVisualsAtom != None) {
  32.       numScreens = ScreenCount(dpy);
  33.       overlayInfoPerScreen = (OverlayInfo **)
  34.         malloc(numScreens * sizeof(OverlayInfo *));
  35.       numOverlaysPerScreen = (unsigned long *)
  36.         malloc(numScreens * sizeof(unsigned long));
  37.       if (overlayInfoPerScreen != NULL &&
  38.         numOverlaysPerScreen != NULL) {
  39.         for (i = 0; i < numScreens; i++) {
  40.           root = RootWindow(dpy, i);
  41.           status = XGetWindowProperty(dpy, root,
  42.             overlayVisualsAtom, 0L, (long) 10000, False,
  43.             overlayVisualsAtom, &actualType, &actualFormat,
  44.             &sizeData, &bytesLeft,
  45.             (unsigned char **) &overlayInfoPerScreen[i]);
  46.           if (status != Success ||
  47.             actualType != overlayVisualsAtom ||
  48.             actualFormat != 32 || sizeData < 4)
  49.             numOverlaysPerScreen[i] = 0;
  50.           else
  51.             /* four 32-bit quantities per
  52.                SERVER_OVERLAY_VISUALS entry */
  53.             numOverlaysPerScreen[i] = sizeData / 4;
  54.         }
  55.         layersRead = True;
  56.       } else {
  57.         if (overlayInfoPerScreen != NULL)
  58.           free(overlayInfoPerScreen);
  59.         if (numOverlaysPerScreen != NULL)
  60.           free(numOverlaysPerScreen);
  61.       }
  62.     }
  63.   }
  64. }
  65.  
  66. int
  67. __glutGetTransparentPixel(Display * dpy, XVisualInfo * vinfo)
  68. {
  69.   int i, screen = vinfo->screen;
  70.   OverlayInfo *overlayInfo;
  71.  
  72.   findServerOverlayVisualsInfo(dpy);
  73.   if (layersRead) {
  74.     for (i = 0; i < numOverlaysPerScreen[screen]; i++) {
  75.       overlayInfo = &overlayInfoPerScreen[screen][i];
  76.       if (vinfo->visualid == overlayInfo->overlay_visual) {
  77.         if (overlayInfo->transparent_type == TransparentPixel) {
  78.           return (int) overlayInfo->value;
  79.         } else {
  80.           return -1;
  81.         }
  82.       }
  83.     }
  84.   }
  85.   return -1;
  86. }
  87.  
  88. XLayerVisualInfo *
  89. __glutXGetLayerVisualInfo(Display * dpy, long lvinfo_mask,
  90.   XLayerVisualInfo * lvinfo_template, int *nitems_return)
  91. {
  92.   XVisualInfo *vinfo;
  93.   XLayerVisualInfo *layerInfo;
  94.   int numVisuals, count, i, j;
  95.  
  96.   vinfo = XGetVisualInfo(dpy, lvinfo_mask & VisualAllMask,
  97.     &lvinfo_template->vinfo, nitems_return);
  98.   if (vinfo == NULL)
  99.     return NULL;
  100.   numVisuals = *nitems_return;
  101.   findServerOverlayVisualsInfo(dpy);
  102.   layerInfo = (XLayerVisualInfo *)
  103.     malloc(numVisuals * sizeof(XLayerVisualInfo));
  104.   if (layerInfo == NULL) {
  105.     XFree(vinfo);
  106.     return NULL;
  107.   }
  108.   count = 0;
  109.   for (i = 0; i < numVisuals; i++) {
  110.     XVisualInfo *pVinfo = &vinfo[i];
  111.     int screen = pVinfo->screen;
  112.     OverlayInfo *overlayInfo = NULL;
  113.  
  114.     overlayInfo = NULL;
  115.     if (layersRead) {
  116.       for (j = 0; j < numOverlaysPerScreen[screen]; j++)
  117.         if (pVinfo->visualid ==
  118.           overlayInfoPerScreen[screen][j].overlay_visual) {
  119.           overlayInfo = &overlayInfoPerScreen[screen][j];
  120.           break;
  121.         }
  122.     }
  123.     if (lvinfo_mask & VisualLayerMask)
  124.       if (overlayInfo == NULL) {
  125.         if (lvinfo_template->layer != 0)
  126.           continue;
  127.       } else if (lvinfo_template->layer != overlayInfo->layer)
  128.         continue;
  129.     if (lvinfo_mask & VisualTransparentType)
  130.       if (overlayInfo == NULL) {
  131.         if (lvinfo_template->type != None)
  132.           continue;
  133.       } else if (lvinfo_template->type !=
  134.         overlayInfo->transparent_type)
  135.         continue;
  136.     if (lvinfo_mask & VisualTransparentValue)
  137.       if (overlayInfo == NULL)
  138.         /* non-overlay visuals have no sense of
  139.            TransparentValue */
  140.         continue;
  141.       else if (lvinfo_template->value != overlayInfo->value)
  142.         continue;
  143.     layerInfo[count].vinfo = *pVinfo;
  144.     if (overlayInfo == NULL) {
  145.       layerInfo[count].layer = 0;
  146.       layerInfo[count].type = None;
  147.       layerInfo[count].value = 0;  /* meaningless */
  148.     } else {
  149.       layerInfo[count].layer = overlayInfo->layer;
  150.       layerInfo[count].type = overlayInfo->transparent_type;
  151.       layerInfo[count].value = overlayInfo->value;
  152.     }
  153.     count++;
  154.   }
  155.   XFree(vinfo);
  156.   *nitems_return = count;
  157.   if (count == 0) {
  158.     XFree(layerInfo);
  159.     return NULL;
  160.   } else
  161.     return layerInfo;
  162. }
  163.  
  164. #if 0                   /* Unused by GLUT. */
  165. Status
  166. __glutXMatchLayerVisualInfo(Display * dpy, int screen,
  167.   int depth, int class, int layer,
  168.   XLayerVisualInfo * lvinfo_return)
  169. {
  170.   XLayerVisualInfo *lvinfo;
  171.   XLayerVisualInfo lvinfoTemplate;
  172.   int nitems;
  173.  
  174.   lvinfoTemplate.vinfo.screen = screen;
  175.   lvinfoTemplate.vinfo.depth = depth;
  176.   lvinfoTemplate.vinfo.class = class;
  177.   lvinfoTemplate.layer = layer;
  178.   lvinfo = __glutXGetLayerVisualInfo(dpy,
  179.     VisualScreenMask | VisualDepthMask |
  180.     VisualClassMask | VisualLayerMask,
  181.     &lvinfoTemplate, &nitems);
  182.   if (lvinfo != NULL && nitems > 0) {
  183.     *lvinfo_return = *lvinfo;
  184.     return 1;
  185.   } else
  186.     return 0;
  187. }
  188. #endif
  189.