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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
#include <cairo-gl.h>
#include "demo.h"
#include <stdlib.h>
#include <string.h>
#include <X11/X.h>
struct glx_device {
struct device base;
struct framebuffer fb;
Display *display;
Window drawable;
GLXContext ctx;
cairo_device_t *device;
int double_buffered;
};
static void
destroy (struct framebuffer *fb)
{
}
static void
show (struct framebuffer *fb)
{
struct glx_device *device = (struct glx_device *) fb->device;
if (device->double_buffered) {
cairo_t *cr = cairo_create (device->base.scanout);
cairo_set_source_surface (cr, fb->surface, 0, 0);
cairo_paint (cr);
cairo_destroy (cr);
}
cairo_gl_surface_swapbuffers (device->base.scanout);
}
static struct framebuffer *
get_fb (struct device *abstract_device)
{
struct glx_device *device = (struct glx_device *) abstract_device;
return &device->fb;
}
struct device *
glx_open (int argc, char **argv)
{
int rgba_attribs[] = {
GLX_RGBA,
GLX_RED_SIZE, 1,
GLX_GREEN_SIZE, 1,
GLX_BLUE_SIZE, 1,
GLX_ALPHA_SIZE, 1,
GLX_DOUBLEBUFFER,
None };
XVisualInfo *vi;
struct glx_device *device;
Display *dpy;
Screen *scr;
int screen;
XSetWindowAttributes attr;
int i, x, y;
dpy = XOpenDisplay (NULL);
if (dpy == NULL)
return NULL;
device = malloc(sizeof(struct glx_device));
device->base.name = "glx";
device->base.get_framebuffer = get_fb;
device->display = dpy;
device->fb.device = &device->base;
device->fb.show = show;
device->fb.destroy = destroy;
device->double_buffered = 0;
for (i = 1; i < argc; i++) {
if (strcmp (argv[i], "--double") == 0)
device->double_buffered = 1;
}
screen = DefaultScreen (dpy);
scr = XScreenOfDisplay (dpy, screen);
device->base.width = WidthOfScreen (scr);
device->base.height = HeightOfScreen (scr);
device_get_size (argc, argv,
&device->base.width, &device->base.height);
x = y = 0;
switch (device_get_split(argc, argv)) {
case SPLIT_NONE:
break;
case SPLIT_LEFT:
device->base.width /= 2;
break;
case SPLIT_RIGHT:
x = device->base.width /= 2;
break;
case SPLIT_TOP:
device->base.height /= 2;
break;
case SPLIT_BOTTOM:
y = device->base.height /= 2;
break;
case SPLIT_BOTTOM_LEFT:
device->base.width /= 2;
y = device->base.height /= 2;
break;
case SPLIT_BOTTOM_RIGHT:
x = device->base.width /= 2;
y = device->base.height /= 2;
break;
case SPLIT_TOP_LEFT:
device->base.width /= 2;
device->base.height /= 2;
break;
case SPLIT_TOP_RIGHT:
x = device->base.width /= 2;
device->base.height /= 2;
break;
}
vi = glXChooseVisual (dpy, DefaultScreen (dpy), rgba_attribs);
if (vi == NULL) {
XCloseDisplay (dpy);
free (device);
return NULL;
}
attr.colormap = XCreateColormap (dpy,
RootWindow (dpy, vi->screen),
vi->visual,
AllocNone);
attr.border_pixel = 0;
attr.override_redirect = True;
device->drawable = XCreateWindow (dpy, DefaultRootWindow (dpy),
x, y,
device->base.width, device->base.height, 0,
vi->depth, InputOutput, vi->visual,
CWOverrideRedirect | CWBorderPixel | CWColormap,
&attr);
XMapWindow (dpy, device->drawable);
device->ctx = glXCreateContext(dpy, vi, NULL, True);
XFree(vi);
device->device = cairo_glx_device_create(dpy, device->ctx);
device->base.scanout =
cairo_gl_surface_create_for_window (device->device,
device->drawable,
device->base.width,
device->base.height);
if (device->double_buffered) {
device->fb.surface = cairo_surface_create_similar (device->base.scanout,
CAIRO_CONTENT_COLOR,
device->base.width,
device->base.height);
} else {
device->fb.surface = device->base.scanout;
}
return &device->base;
}
|