annotate TaskManager/Test/test_render/fb.h @ 132:e7c80537b6aa

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