/
multipix.c
86 lines (70 loc) · 2.1 KB
/
multipix.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Test application for determining if a GLX implementation supports multiple
// GLXPixmaps bound to the same Pixmap out of process.
#include <X11/Xlib.h>
#include <GL/glx.h>
#include <stdio.h>
static int verbose;
GLXPixmap
createGLXPixmap(Display* display, Pixmap pixmap)
{
const int attribs[] = {
GLX_RENDER_TYPE, GLX_RGBA_BIT,
GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT,
None
};
int numConfigs = 0;
GLXFBConfig* config = glXChooseFBConfig(display, 0, attribs, &numConfigs);
if (numConfigs == 0) {
fprintf(stderr, "Failed to find a valid GLX FBConfig.\n");
return None;
}
GLXFBConfig cfg = config[0];
if (verbose) {
GLXFBConfigID id;
glXGetFBConfigAttrib(display, cfg, GLX_FBCONFIG_ID, (int*) &id);
printf("Using FBConfig with ID 0x%X\n", id);
}
return glXCreatePixmap(display, cfg, pixmap, NULL);
}
int
main(int argc, char* argv[])
{
verbose = !!getenv("VERBOSE");
Display* display = XOpenDisplay(NULL);
if (!display) {
fprintf(stderr, "Failed to open parent display.\n");
return 1;
}
Window root = XDefaultRootWindow(display);
Pixmap pix = XCreatePixmap(display, root, 1, 1, 24);
GLXPixmap parentPix = None;
if ((parentPix = createGLXPixmap(display, pix)) == None) {
fprintf(stderr, "Failed to create GLXPixmap in parent!\n");
}
if (verbose)
printf("Created parent GLXPixmap %x\n", parentPix);
if (fork() == 0) {
Display* childDisplay = XOpenDisplay(NULL);
if (!childDisplay) {
fprintf(stderr, "Failed to open child display.\n");
return 1;
}
GLXPixmap childPix = None;
if ((childPix = createGLXPixmap(childDisplay, pix)) == None) {
fprintf(stderr, "Failed to create child pixmap!\n");
return 1;
}
if (verbose)
printf("Created child GLXPixmap %x\n", childPix);
} else {
int status;
wait(&status);
if (status == 1) {
fprintf(stderr, "Test failed; your driver likely does not support multiple binding with GLXPixmaps.\n");
return 1;
}
if (verbose)
printf("Successfully created parent and child GLXPixmaps; your driver rocks!\n");
}
return 0;
}