summaryrefslogtreecommitdiffstatsci
path: root/src/cairo-glx.cpp
blob: 647d7b518ddbc80e236ac7d29068bc6aa77ee327 (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
 * Copyright 2014 © Samsung Research America, Silicon Valley
 *
 * Use of this source code is governed by the 3-Clause BSD license
 * specified in the COPYING file included with this source code.
 */
#include <config.h>

#include <err.h>
#include <stdlib.h>

#include <cairo.h>
#include <cairo-gl.h>

#include "glx.h"
#include "device_config.h"

static glx_state_t *state;

cairo_surface_t *
create_cairo_surface_glx (const device_config_t& config)
{
    cairo_device_t *cairo_device;
    cairo_surface_t *cairo_surface;

    state = (glx_state_t*) malloc (sizeof (glx_state_t));
    if (!state) {
        warnx ("Out of memory\n");
        return NULL;
    }

    if (!createGLXContextAndWindow(state, config.width, config.height)) {
        cleanup_state_glx(state);
        errx (-1, "Could not create GLX context and window\n");
    }

    cairo_device = cairo_glx_device_create (state->dpy, state->glx_context);
    cairo_status_t status = cairo_device_status (cairo_device);
    if (status != CAIRO_STATUS_SUCCESS)
        errx (-1, "Could not create GLX device: (%d) %s\n", status, cairo_status_to_string (status) );

    cairo_gl_device_set_thread_aware (cairo_device, 0);
    cairo_surface = cairo_gl_surface_create_for_window (cairo_device,
                                                        state->window,
                                                        config.width, config.height);
    cairo_device_destroy (cairo_device);

    glClearColor(1, 1, 1, 1);
    glClear(GL_COLOR_BUFFER_BIT);

    return cairo_surface;
}

void
destroy_cairo_glx(void)
{
    cleanup_state_glx(state);
}

void
update_cairo_glx(void)
{
    cairo_gl_surface_swapbuffers (cairo_surface);
}

/*
  Local Variables:
  mode:c++
  c-file-style:"stroustrup"
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
  indent-tabs-mode:nil
  fill-column:99
  End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :