File: rotatefb.c

package info (click to toggle)
android-platform-system-core 21-6
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 5,624 kB
  • ctags: 11,983
  • sloc: ansic: 70,139; cpp: 14,766; asm: 1,774; sh: 875; yacc: 137; python: 131; makefile: 120; lex: 103; java: 79
file content (71 lines) | stat: -rw-r--r-- 1,681 bytes parent folder | download
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
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include <errno.h>
#include <linux/fb.h>


int rotatefb_main(int argc, char *argv[])
{
    int c;
    char *fbdev = "/dev/graphics/fb0";
    int rotation = 0;
    int fd;
    int res;
    struct fb_var_screeninfo fbinfo;

    do {
        c = getopt(argc, argv, "d:");
        if (c == EOF)
            break;
        switch (c) {
        case 'd':
            fbdev = optarg;
            break;
        case '?':
            fprintf(stderr, "%s: invalid option -%c\n",
                argv[0], optopt);
            exit(1);
        }
    } while (1);

    if(optind + 1 != argc) {
        fprintf(stderr, "%s: specify rotation\n", argv[0]);
        exit(1);
    }
    rotation = atoi(argv[optind]);

    fd = open(fbdev, O_RDWR);
    if(fd < 0) {
        fprintf(stderr, "cannot open %s\n", fbdev);
        return 1;
    }

    res = ioctl(fd, FBIOGET_VSCREENINFO, &fbinfo);
    if(res < 0) {
        fprintf(stderr, "failed to get fbinfo: %s\n", strerror(errno));
        return 1;
    }
    if((fbinfo.rotate ^ rotation) & 1) {
        unsigned int xres = fbinfo.yres;
        fbinfo.yres = fbinfo.xres;
        fbinfo.xres = xres;
        fbinfo.xres_virtual = fbinfo.xres;
        fbinfo.yres_virtual = fbinfo.yres * 2;
        if(fbinfo.yoffset == xres)
            fbinfo.yoffset = fbinfo.yres;
    }
    fbinfo.rotate = rotation; 
    res = ioctl(fd, FBIOPUT_VSCREENINFO, &fbinfo);
    if(res < 0) {
        fprintf(stderr, "failed to set fbinfo: %s\n", strerror(errno));
        return 1;
    }

    return 0;
}