aboutsummaryrefslogtreecommitdiffstats
path: root/egltest.c
blob: fdafa146ec6f34042aa25fc4f01273d8e9ad7c20 (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
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
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <inttypes.h>
#include <getopt.h>
#include <assert.h>

#include <gbm.h>
#include <epoxy/gl.h>
#include <epoxy/egl.h>

#include <xf86drm.h>
#include <xf86drmMode.h>

#include <cairo.h>
#include <pixman.h>

#include "drmtools.h"
#include "ttytools.h"

/* ------------------------------------------------------------------ */

static void egl_print_info(void)
{
    printf("version:  %s\n", glGetString(GL_VERSION));
    printf("vendor:   %s\n", glGetString(GL_VENDOR));
    printf("renderer: %s\n", glGetString(GL_RENDERER));
}

static void egl_draw(void)
{
    /* green background */
    glClearColor(0.0, 0.6, 0.0, 1.0);
    glClear(GL_COLOR_BUFFER_BIT);
    glFlush();
}

/* ------------------------------------------------------------------ */

static void usage(FILE *fp)
{
    fprintf(fp,
            "\n"
            "usage: egltest [ options ]\n"
            "\n"
            "options:\n"
            "  -h         print this\n"
            "  -a         autotest mode\n"
            "  -c <nr>    pick card\n"
            "  -s <secs>  set sleep time (default: 60)\n"
            "  -i         print device info\n"
            "\n");
}

int main(int argc, char **argv)
{
    int card = 0;
    int secs = 60;
    char *output = NULL;
    char *modename = NULL;
    bool printinfo = false;
    bool autotest = false;
    char buf[32];
    int c;

    for (;;) {
        c = getopt(argc, argv, "haic:s:");
        if (c == -1)
            break;
        switch (c) {
        case 'c':
            card = atoi(optarg);
            break;
        case 's':
            secs = atoi(optarg);
            break;
        case 'i':
            printinfo = true;
            break;
        case 'a':
            autotest = true;
            break;
        case 'h':
            usage(stdout);
            exit(0);
        default:
            usage(stderr);
            exit(1);
        }
    }

    drm_init_dev(card, output, modename, false);
    drm_setup_egl();

    if (printinfo) {
        egl_print_info();
        goto done;
    }

    egl_draw();
    drm_egl_flush_display();

    if (autotest)
        fprintf(stdout, "---ok---\n");

    tty_raw();
    kbd_wait(secs);
    read(0, buf, sizeof(buf));
    tty_restore();

done:
    drm_fini_dev();
    return 0;
}