home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / qt3_emx.zip / examples / opengl / overlay_x11 / utilities / sovinfo / sovlayerutil.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-05-07  |  4.5 KB  |  151 lines

  1.  
  2. /* Copyright (c) Mark J. Kilgard, 1996. */
  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. #include <stdlib.h>
  9. #include "sovLayerUtil.h"
  10.  
  11. static Bool layersRead;
  12. static Atom overlayVisualsAtom;
  13. static sovOverlayInfo **overlayInfoPerScreen;
  14. static int *numOverlaysPerScreen;
  15.  
  16. sovVisualInfo *
  17. sovGetVisualInfo(Display *display, long lvinfo_mask,
  18.   sovVisualInfo *lvinfo_template, int *nitems_return)
  19. {
  20.   XVisualInfo *vinfo;
  21.   sovVisualInfo *layerInfo;
  22.   Window root;
  23.   Status status;
  24.   Atom actualType;
  25.   unsigned long sizeData, bytesLeft;
  26.   int actualFormat, numVisuals, numScreens, count, i, j;
  27.  
  28.   vinfo = XGetVisualInfo(display, lvinfo_mask & VisualAllMask,
  29.     &lvinfo_template->vinfo, nitems_return);
  30.   if (vinfo == NULL)
  31.     return NULL;
  32.   numVisuals = *nitems_return;
  33.   if (layersRead == False) {
  34.     overlayVisualsAtom = XInternAtom(display, 
  35.       "SERVER_OVERLAY_VISUALS", True);
  36.     if (overlayVisualsAtom != None) {
  37.       numScreens = ScreenCount(display);
  38.       overlayInfoPerScreen = (sovOverlayInfo **)
  39.         malloc(numScreens * sizeof(sovOverlayInfo *));
  40.       numOverlaysPerScreen = (int *) malloc(numScreens * sizeof(int));
  41.       if (overlayInfoPerScreen != NULL &&
  42.         numOverlaysPerScreen != NULL) {
  43.         for (i = 0; i < numScreens; i++) {
  44.           root = RootWindow(display, i);
  45.           status = XGetWindowProperty(display, root, overlayVisualsAtom,
  46.             0L, (long) 10000, False, overlayVisualsAtom,
  47.         &actualType, &actualFormat,
  48.             &sizeData, &bytesLeft,
  49.         (unsigned char **) &overlayInfoPerScreen[i]);
  50.           if (status != Success ||
  51.         actualType != overlayVisualsAtom ||
  52.             actualFormat != 32 || sizeData < 4)
  53.             numOverlaysPerScreen[i] = 0;
  54.           else
  55.             numOverlaysPerScreen[i] = sizeData / 4;
  56.         }
  57.         layersRead = True;
  58.       } else {
  59.         if (overlayInfoPerScreen != NULL)
  60.           free(overlayInfoPerScreen);
  61.         if (numOverlaysPerScreen != NULL)
  62.           free(numOverlaysPerScreen);
  63.       }
  64.     }
  65.   }
  66.   layerInfo = (sovVisualInfo *)
  67.     malloc(numVisuals * sizeof(sovVisualInfo));
  68.   if (layerInfo == NULL) {
  69.     XFree(vinfo);
  70.     return NULL;
  71.   }
  72.   count = 0;
  73.   for (i = 0; i < numVisuals; i++) {
  74.     XVisualInfo *pVinfo;
  75.     int screen;
  76.     sovOverlayInfo *overlayInfo;
  77.  
  78.     pVinfo = &vinfo[i];
  79.     screen = pVinfo->screen;
  80.     overlayInfo = NULL;
  81.     if (layersRead) {
  82.       for (j = 0; j < numOverlaysPerScreen[screen]; j++)
  83.         if (pVinfo->visualid == 
  84.         overlayInfoPerScreen[screen][j].overlay_visual) {
  85.           overlayInfo = &overlayInfoPerScreen[screen][j];
  86.           break;
  87.         }
  88.     }
  89.     if (lvinfo_mask & VisualLayerMask)
  90.       if (overlayInfo == NULL) {
  91.         if (lvinfo_template->layer != 0)
  92.           continue;
  93.       } else if (lvinfo_template->layer != overlayInfo->layer)
  94.         continue;
  95.     if (lvinfo_mask & VisualTransparentType)
  96.       if (overlayInfo == NULL) {
  97.         if (lvinfo_template->type != None)
  98.           continue;
  99.       } else if (lvinfo_template->type !=
  100.         overlayInfo->transparent_type)
  101.         continue;
  102.     if (lvinfo_mask & VisualTransparentValue)
  103.       if (overlayInfo == NULL)
  104.         /* non-overlay visuals have no sense of
  105.            TransparentValue */
  106.         continue;
  107.       else if (lvinfo_template->value != overlayInfo->value)
  108.         continue;
  109.     layerInfo[count].vinfo = *pVinfo;
  110.     if (overlayInfo == NULL) {
  111.       layerInfo[count].layer = 0;
  112.       layerInfo[count].type = None;
  113.       layerInfo[count].value = 0;  /* meaningless */
  114.     } else {
  115.       layerInfo[count].layer = overlayInfo->layer;
  116.       layerInfo[count].type = overlayInfo->transparent_type;
  117.       layerInfo[count].value = overlayInfo->value;
  118.     }
  119.     count++;
  120.   }
  121.   XFree(vinfo);
  122.   *nitems_return = count;
  123.   if (count == 0) {
  124.     XFree(layerInfo);
  125.     return NULL;
  126.   } else
  127.     return layerInfo;
  128. }
  129.  
  130. Status
  131. sovMatchVisualInfo(Display *display, int screen,
  132.   int depth, int class, int layer, sovVisualInfo *lvinfo_return)
  133. {
  134.   sovVisualInfo *lvinfo;
  135.   sovVisualInfo lvinfoTemplate;
  136.   int nitems;
  137.  
  138.   lvinfoTemplate.vinfo.screen = screen;
  139.   lvinfoTemplate.vinfo.depth = depth;
  140.   lvinfoTemplate.vinfo.class = class;
  141.   lvinfoTemplate.layer = layer;
  142.   lvinfo = sovGetVisualInfo(display,
  143.     VisualScreenMask|VisualDepthMask|VisualClassMask|VisualLayerMask,
  144.     &lvinfoTemplate, &nitems);
  145.   if (lvinfo != NULL && nitems > 0) {
  146.     *lvinfo_return = *lvinfo;
  147.     return 1;
  148.   } else
  149.     return 0;
  150. }
  151.