comparison Renderer/Engine/fb.h @ 895:b662e9dd26b0 draft

add alignment of classes in SPU width and height are automatically set in frame buffer API
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Fri, 16 Jul 2010 17:23:49 +0900
parents 3bc98f6d31ff
children f3530a4100bf
comparison
equal deleted inserted replaced
894:d9d229ede3ff 895:b662e9dd26b0
12 #include <sys/ioctl.h> 12 #include <sys/ioctl.h>
13 #include <stdlib.h> 13 #include <stdlib.h>
14 #include <iostream> 14 #include <iostream>
15 using namespace std; 15 using namespace std;
16 16
17 #define DEVICE_NAME "/dev/fb0"
18 #define DIV_BYTE 8
19 17
20 /* function prototype */ 18 /* function prototype */
21 void send_current_error_msg(const char *ptr); 19 void send_current_error_msg(const char *ptr);
22 void send_current_information(const char *ptr); 20 void send_current_information(const char *ptr);
23 21
24 /* 22 /*
25 Don't put real function in a header... 23 Don't put real function in a header...
26 */ 24 */
25 typedef struct screen_info {
26 int xres,yres,vbpp,line_len;
27 char *fbptr;
28 } ScreenInfo , *ScreenInfoPtr;
27 29
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 30
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 31
101 #endif 32 #endif
33
34 extern ScreenInfo get_fbdev_addr(void);
35
36 #endif