blob: 98fe05f1e791a6a06dcceb890d10cdf93d46e8a7 (
plain)
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
|
#include <err.h>
#include <stdlib.h>
#include <cairo.h>
#include <cairo-gl.h>
struct graphics_state {
Display *dpy;
Window window;
};
static void
cleanup (void *data)
{
struct graphics_state *state = (graphics_state*)data;
/*
XDestroyWindow (state->dpy, state->window);
XCloseDisplay (state->dpy);
*/
free (state);
}
cairo_surface_t *
create_cairo_surface_image (int width, int height)
{
struct graphics_state *state;
cairo_surface_t *cairo_surface;
state = (graphics_state*) malloc (sizeof (struct graphics_state));
if (!state) {
warnx ("Out of memory\n");
return NULL;
}
/*
state->dpy = XOpenDisplay (NULL);
if (state->dpy == NULL) {
warnx ("Failed to open display: %s\n", XDisplayName (0));
return NULL;
}
*/
cairo_surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
width,
height);
if (cairo_surface_set_user_data (cairo_surface,
(cairo_user_data_key_t *) cleanup,
state,
cleanup))
{
warnx ("Failed to setup cleanup callback closure\n");
cleanup (state);
return NULL;
}
return cairo_surface;
}
|