aboutsummaryrefslogtreecommitdiffstats
path: root/fbtest.c
blob: 24ebdff552acd1bcae7bf7e8e0279280a74e87f4 (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
118
119
120
121
122
123
#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 <sys/ioctl.h>
#include <sys/mman.h>

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

#include "fbtools.h"
#include "ttytools.h"
#include "render.h"
#include "image.h"

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

/* cairo */
static cairo_surface_t *cs;

/* user options */
static cairo_surface_t *image;

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

static void fb_draw(bool autotest)
{
    char info1[80];
    char info2[80];
    char info3[80];
    cairo_t *cr;

    snprintf(info1, sizeof(info1), "mode: %dx%d", fb_var.xres, fb_var.yres);
    snprintf(info2, sizeof(info2), "%d bpp, rgba %d,%d,%d,%d",
             fb_var.bits_per_pixel,
             fb_var.red.length,
             fb_var.green.length,
             fb_var.blue.length,
             fb_var.transp.length);
    snprintf(info3, sizeof(info3), "fb driver: %s", fb_fix.id);

    cr = cairo_create(cs);
    if (image) {
        render_image(cr, fb_var.xres, fb_var.yres, image);
    } else {
        render_test(cr, fb_var.xres, fb_var.yres, info1, info2,
                    autotest ? NULL : info3);
    }
    cairo_destroy(cr);
}

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

static void usage(FILE *fp)
{
    fprintf(fp,
            "\n"
            "usage: fbtest [ options ]\n"
            "\n"
            "options:\n"
            "  -h         print this\n"
            "  -a         autotest mode (don't print hardware info)\n"
            "  -f <nr>    pick framebuffer\n"
            "  -s <secs>  set sleep time (default: 60)\n"
            "  -i <file>  load and display image <file>\n"
            "\n");
}

int main(int argc, char **argv)
{
    int framebuffer = 0;
    int secs = 60;
    bool autotest = false;
    char buf[32];
    int c;

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

    fb_init(framebuffer);
    cs = cairo_image_surface_create_for_data(fb_mem + fb_mem_offset,
                                             fb_format,
                                             fb_var.xres,
                                             fb_var.yres,
                                             fb_fix.line_length);
    fb_draw(autotest);

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

    fb_fini();
    return 0;
}