summaryrefslogtreecommitdiffstats
path: root/examples/opengl/overlay_x11/utilities/sovinfo
diff options
context:
space:
mode:
Diffstat (limited to 'examples/opengl/overlay_x11/utilities/sovinfo')
-rw-r--r--examples/opengl/overlay_x11/utilities/sovinfo/sovLayerUtil.h54
-rw-r--r--examples/opengl/overlay_x11/utilities/sovinfo/sovinfo.c95
-rw-r--r--examples/opengl/overlay_x11/utilities/sovinfo/sovlayerutil.c150
3 files changed, 299 insertions, 0 deletions
diff --git a/examples/opengl/overlay_x11/utilities/sovinfo/sovLayerUtil.h b/examples/opengl/overlay_x11/utilities/sovinfo/sovLayerUtil.h
new file mode 100644
index 000000000..f45423a8d
--- /dev/null
+++ b/examples/opengl/overlay_x11/utilities/sovinfo/sovLayerUtil.h
@@ -0,0 +1,54 @@
+#ifndef __sovLayerUtil_h__
+#define __sovLayerUtil_h__
+
+/* Copyright (c) Mark J. Kilgard, 1996. */
+
+/* This program is freely distributable without licensing fees
+ and is provided without guarantee or warrantee expressed or
+ implied. This program is -not- in the public domain. */
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/Xmd.h>
+
+/* Transparent type values */
+/* None 0 */
+#define TransparentPixel 1
+#define TransparentMask 2
+
+/* layered visual info template flags */
+#define VisualLayerMask 0x200
+#define VisualTransparentType 0x400
+#define VisualTransparentValue 0x800
+#define VisualAllLayerMask 0xFFF
+
+/* layered visual info structure */
+typedef struct _sovVisualInfo {
+ XVisualInfo vinfo;
+ int layer;
+ int type;
+ unsigned long value;
+} sovVisualInfo;
+
+/* SERVER_OVERLAY_VISUALS property element */
+typedef struct _sovOverlayInfo {
+ long overlay_visual;
+ long transparent_type;
+ long value;
+ long layer;
+} sovOverlayInfo;
+
+extern sovVisualInfo *sovGetVisualInfo(
+ Display *display,
+ long lvinfo_mask,
+ sovVisualInfo *lvinfo_template,
+ int *nitems_return);
+extern Status sovMatchVisualInfo(
+ Display *display,
+ int screen,
+ int depth,
+ int class,
+ int layer,
+ sovVisualInfo *lvinfo_return);
+
+#endif /* __sovLayerUtil_h__ */
diff --git a/examples/opengl/overlay_x11/utilities/sovinfo/sovinfo.c b/examples/opengl/overlay_x11/utilities/sovinfo/sovinfo.c
new file mode 100644
index 000000000..059050c2f
--- /dev/null
+++ b/examples/opengl/overlay_x11/utilities/sovinfo/sovinfo.c
@@ -0,0 +1,95 @@
+
+/* Copyright (c) Mark J. Kilgard, 1996. */
+
+/* This program is freely distributable without licensing fees
+ and is provided without guarantee or warrantee expressed or
+ implied. This program is -not- in the public domain. */
+
+/* compile: cc -o sovinfo sovinfo.c sovLayerUtil.c -lX11 */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "sovLayerUtil.h"
+
+int
+main(int argc, char *argv[])
+{
+ Display *dpy;
+ char *display_name, *arg, *class;
+ sovVisualInfo template, *lvinfo;
+ int nVisuals, i, overlaysOnly = 0;
+
+ display_name = NULL;
+ for (i = 1; i < argc; i++) {
+ arg = argv[i];
+ if (!strcmp(arg, "-display")) {
+ if (++i >= argc) {
+ fprintf(stderr, "sovinfo: missing argument to -display\n");
+ exit(1);
+ }
+ display_name = argv[i];
+ } else if (!strcmp(arg, "-overlays_only")) {
+ overlaysOnly = 1;
+ } else {
+ fprintf(stderr,
+ "usage: sovinfo [-display dpy] [-overlays_only]\n");
+ exit(1);
+ }
+ }
+ dpy = XOpenDisplay(display_name);
+ if (dpy == NULL) {
+ fprintf(stderr, "sovinfo: cannot open display %s\n",
+ XDisplayName(NULL));
+ exit(1);
+ }
+ lvinfo = sovGetVisualInfo(dpy, 0L, &template, &nVisuals);
+ for (i = 0; i < nVisuals; i++) {
+ if (!overlaysOnly || lvinfo[i].layer > 0) {
+ printf(" Visual ID: 0x%x\n", lvinfo[i].vinfo.visualid);
+ printf(" screen: %d\n", lvinfo[i].vinfo.screen);
+ printf(" depth: %d\n", lvinfo[i].vinfo.depth);
+ switch (lvinfo[i].vinfo.class) {
+ case StaticGray:
+ class = "StaticGray";
+ break;
+ case GrayScale:
+ class = "GrayScale";
+ break;
+ case StaticColor:
+ class = "StaticColor";
+ break;
+ case PseudoColor:
+ class = "PseudoColor";
+ break;
+ case TrueColor:
+ class = "TrueColor";
+ break;
+ case DirectColor:
+ class = "DirectColor";
+ break;
+ default:
+ class = "Unknown";
+ break;
+ }
+ printf(" class: %s\n", class);
+ switch (lvinfo[i].type) {
+ case None:
+ printf(" transparent type: None\n");
+ break;
+ case TransparentPixel:
+ printf(" transparent type: TransparentPixel\n");
+ printf(" pixel value: %d\n", lvinfo[i].value);
+ break;
+ case TransparentMask:
+ printf(" transparent type: TransparentMask\n");
+ printf(" transparency mask: %0x%x\n", lvinfo[i].value);
+ break;
+ default:
+ printf(" transparent type: Unknown or invalid\n");
+ break;
+ }
+ printf(" layer: %d\n", lvinfo[i].layer);
+ }
+ }
+ return 0;
+}
diff --git a/examples/opengl/overlay_x11/utilities/sovinfo/sovlayerutil.c b/examples/opengl/overlay_x11/utilities/sovinfo/sovlayerutil.c
new file mode 100644
index 000000000..8837d06cf
--- /dev/null
+++ b/examples/opengl/overlay_x11/utilities/sovinfo/sovlayerutil.c
@@ -0,0 +1,150 @@
+
+/* Copyright (c) Mark J. Kilgard, 1996. */
+
+/* This program is freely distributable without licensing fees
+ and is provided without guarantee or warrantee expressed or
+ implied. This program is -not- in the public domain. */
+
+#include <stdlib.h>
+#include "sovLayerUtil.h"
+
+static Bool layersRead;
+static Atom overlayVisualsAtom;
+static sovOverlayInfo **overlayInfoPerScreen;
+static int *numOverlaysPerScreen;
+
+sovVisualInfo *
+sovGetVisualInfo(Display *display, long lvinfo_mask,
+ sovVisualInfo *lvinfo_template, int *nitems_return)
+{
+ XVisualInfo *vinfo;
+ sovVisualInfo *layerInfo;
+ Window root;
+ Status status;
+ Atom actualType;
+ unsigned long sizeData, bytesLeft;
+ int actualFormat, numVisuals, numScreens, count, i, j;
+
+ vinfo = XGetVisualInfo(display, lvinfo_mask & VisualAllMask,
+ &lvinfo_template->vinfo, nitems_return);
+ if (vinfo == NULL)
+ return NULL;
+ numVisuals = *nitems_return;
+ if (layersRead == False) {
+ overlayVisualsAtom = XInternAtom(display,
+ "SERVER_OVERLAY_VISUALS", True);
+ if (overlayVisualsAtom != None) {
+ numScreens = ScreenCount(display);
+ overlayInfoPerScreen = (sovOverlayInfo **)
+ malloc(numScreens * sizeof(sovOverlayInfo *));
+ numOverlaysPerScreen = (int *) malloc(numScreens * sizeof(int));
+ if (overlayInfoPerScreen != NULL &&
+ numOverlaysPerScreen != NULL) {
+ for (i = 0; i < numScreens; i++) {
+ root = RootWindow(display, i);
+ status = XGetWindowProperty(display, root, overlayVisualsAtom,
+ 0L, (long) 10000, False, overlayVisualsAtom,
+ &actualType, &actualFormat,
+ &sizeData, &bytesLeft,
+ (unsigned char **) &overlayInfoPerScreen[i]);
+ if (status != Success ||
+ actualType != overlayVisualsAtom ||
+ actualFormat != 32 || sizeData < 4)
+ numOverlaysPerScreen[i] = 0;
+ else
+ numOverlaysPerScreen[i] = sizeData / 4;
+ }
+ layersRead = True;
+ } else {
+ if (overlayInfoPerScreen != NULL)
+ free(overlayInfoPerScreen);
+ if (numOverlaysPerScreen != NULL)
+ free(numOverlaysPerScreen);
+ }
+ }
+ }
+ layerInfo = (sovVisualInfo *)
+ malloc(numVisuals * sizeof(sovVisualInfo));
+ if (layerInfo == NULL) {
+ XFree(vinfo);
+ return NULL;
+ }
+ count = 0;
+ for (i = 0; i < numVisuals; i++) {
+ XVisualInfo *pVinfo;
+ int screen;
+ sovOverlayInfo *overlayInfo;
+
+ pVinfo = &vinfo[i];
+ screen = pVinfo->screen;
+ overlayInfo = NULL;
+ if (layersRead) {
+ for (j = 0; j < numOverlaysPerScreen[screen]; j++)
+ if (pVinfo->visualid ==
+ overlayInfoPerScreen[screen][j].overlay_visual) {
+ overlayInfo = &overlayInfoPerScreen[screen][j];
+ break;
+ }
+ }
+ if (lvinfo_mask & VisualLayerMask)
+ if (overlayInfo == NULL) {
+ if (lvinfo_template->layer != 0)
+ continue;
+ } else if (lvinfo_template->layer != overlayInfo->layer)
+ continue;
+ if (lvinfo_mask & VisualTransparentType)
+ if (overlayInfo == NULL) {
+ if (lvinfo_template->type != None)
+ continue;
+ } else if (lvinfo_template->type !=
+ overlayInfo->transparent_type)
+ continue;
+ if (lvinfo_mask & VisualTransparentValue)
+ if (overlayInfo == NULL)
+ /* non-overlay visuals have no sense of
+ TransparentValue */
+ continue;
+ else if (lvinfo_template->value != overlayInfo->value)
+ continue;
+ layerInfo[count].vinfo = *pVinfo;
+ if (overlayInfo == NULL) {
+ layerInfo[count].layer = 0;
+ layerInfo[count].type = None;
+ layerInfo[count].value = 0; /* meaningless */
+ } else {
+ layerInfo[count].layer = overlayInfo->layer;
+ layerInfo[count].type = overlayInfo->transparent_type;
+ layerInfo[count].value = overlayInfo->value;
+ }
+ count++;
+ }
+ XFree(vinfo);
+ *nitems_return = count;
+ if (count == 0) {
+ XFree(layerInfo);
+ return NULL;
+ } else
+ return layerInfo;
+}
+
+Status
+sovMatchVisualInfo(Display *display, int screen,
+ int depth, int class, int layer, sovVisualInfo *lvinfo_return)
+{
+ sovVisualInfo *lvinfo;
+ sovVisualInfo lvinfoTemplate;
+ int nitems;
+
+ lvinfoTemplate.vinfo.screen = screen;
+ lvinfoTemplate.vinfo.depth = depth;
+ lvinfoTemplate.vinfo.class = class;
+ lvinfoTemplate.layer = layer;
+ lvinfo = sovGetVisualInfo(display,
+ VisualScreenMask|VisualDepthMask|VisualClassMask|VisualLayerMask,
+ &lvinfoTemplate, &nitems);
+ if (lvinfo != NULL && nitems > 0) {
+ *lvinfo_return = *lvinfo;
+ return 1;
+ } else
+ return 0;
+}