comparison Renderer/Engine/fb.h @ 507:735f76483bb2

Reorganization..
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 12 Oct 2009 09:39:35 +0900
parents Renderer/test_render/fb.h@58fd16298954
children bed529c55eda
comparison
equal deleted inserted replaced
506:1d4a8a86f26b 507:735f76483bb2
1 #ifndef FB_H
2 #define FB_H
3
4 #if defined(__linux__)
5
6 #include <unistd.h>
7 #include <stdio.h>
8 #include <fcntl.h>
9 #include <linux/fb.h>
10 #include <linux/fs.h>
11 #include <sys/mman.h>
12 #include <sys/ioctl.h>
13 #include <stdlib.h>
14 #include <iostream>
15 using namespace std;
16
17 #define DEVICE_NAME "/dev/fb0"
18 #define DIV_BYTE 8
19
20 /* function prototype */
21 void send_current_error_msg(const char *ptr);
22 void send_current_information(const char *ptr);
23
24 /*
25 Don't put real function in a header...
26 */
27
28 int get_fbdev_addr(void)
29 {
30 int fd_framebuffer ;
31 struct fb_var_screeninfo vinfo;
32 struct fb_fix_screeninfo finfo;
33 long int screensize ;
34 //long int location;
35 char *fbptr ;
36 char tmp[DIV_BYTE*10];
37
38 //int x , y ;
39 int xres,yres,vbpp,line_len;
40 //unsigned short tcolor ;
41
42 /* 読み書き用にファイルを開く */
43 fd_framebuffer = open( DEVICE_NAME , O_RDWR);
44 if ( !fd_framebuffer ) {
45 send_current_error_msg("Framebuffer device open error !");
46 exit(1);
47 }
48 send_current_information("The framebuffer device was opened !");
49
50 /* 固定スクリーン情報取得 */
51 if ( ioctl( fd_framebuffer , FBIOGET_FSCREENINFO , &finfo ) ) {
52 send_current_error_msg("Fixed information not gotton !");
53 exit(2);
54 }
55
56 /* 変動スクリーン情報取得 */
57 if ( ioctl( fd_framebuffer , FBIOGET_VSCREENINFO , &vinfo ) ) {
58 send_current_error_msg("Variable information not gotton !");
59 exit(3);
60 }
61 xres = vinfo.xres ;
62 yres = vinfo.yres ;
63 vbpp = vinfo.bits_per_pixel ;
64 line_len = finfo.line_length ;
65 sprintf( tmp , "%d(pixel)x%d(line), %dbpp(bits per pixel)",xres,yres,vbpp);
66 send_current_information( tmp );
67
68 /* バイト単位でのスクリーンのサイズを計算 */
69 screensize = xres * yres * vbpp / DIV_BYTE ;
70
71 /* デバイスをメモリにマップする */
72 fbptr = (char *)mmap(0,screensize,PROT_READ | PROT_WRITE,MAP_SHARED,fd_framebuffer,0);
73 if ( (int)fbptr == -1 ) {
74 send_current_error_msg("Don't get framebuffer device to memory !");
75 exit(4);
76 }
77 send_current_information("The framebuffer device was mapped !");
78
79 printf("fb: 0x%x \n", (unsigned int)fbptr);
80 return (int)fbptr;
81 //munmap(fbptr,screensize);
82 //close(fd_framebuffer);
83 //return 0;
84 }
85
86 void send_current_error_msg(const char *ptr)
87 {
88 fprintf( stderr , "%s\n" , ptr );
89 }
90
91 void send_current_information(const char *ptr)
92 {
93 fprintf( stdout , "%s\n" , ptr );
94 }
95 #else /* !defined(__linux__) */
96 int get_fbdev_addr(void) {return 0;}
97 #endif /* defined(__linux__) */
98
99 extern int get_fbdev_addr(void);
100
101 #endif