annotate Renderer/Engine/fb.h @ 848:a033d464c812 draft

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