998
|
1 #include "fb.h"
|
|
2 #include <SDL.h>
|
|
3 using namespace std;
|
|
4
|
|
5 void send_current_error_msg(const char *ptr)
|
|
6 {
|
|
7 fprintf( stderr , "%s\n" , ptr );
|
|
8 }
|
|
9
|
|
10 void send_current_information(const char *ptr)
|
|
11 {
|
|
12 fprintf( stdout , "%s\n" , ptr );
|
|
13 }
|
|
14
|
|
15 const int redMask = 0x00ff0000;
|
|
16 const int greenMask = 0x0000ff00;
|
|
17 const int blueMask = 0x000000ff;
|
|
18 const int alphaMask = 0xff000000;
|
|
19
|
|
20 fb_t
|
|
21 get_fbdev_addr(void)
|
|
22 {
|
|
23 int fd_framebuffer ;
|
|
24 struct fb_var_screeninfo vinfo;
|
|
25 struct fb_fix_screeninfo finfo;
|
|
26 long int screensize ;
|
|
27 //long int location;
|
|
28 char *fbptr ;
|
|
29 char tmp[DIV_BYTE*10];
|
|
30
|
|
31 //int x , y ;
|
|
32 int xres,yres,vbpp,line_len;
|
|
33 //unsigned short tcolor ;
|
|
34
|
|
35 /* 読み書き用にファイルを開く */
|
|
36 fd_framebuffer = open( DEVICE_NAME , O_RDWR);
|
|
37 if ( !fd_framebuffer ) {
|
|
38 send_current_error_msg("Framebuffer device open error !");
|
|
39 exit(1);
|
|
40 }
|
|
41 send_current_information("The framebuffer device was opened !");
|
|
42
|
|
43 /* 固定スクリーン情報取得 */
|
|
44 if ( ioctl( fd_framebuffer , FBIOGET_FSCREENINFO , &finfo ) ) {
|
|
45 send_current_error_msg("Fixed information not gotton !");
|
|
46 exit(2);
|
|
47 }
|
|
48
|
|
49 /* 変動スクリーン情報取得 */
|
|
50 if ( ioctl( fd_framebuffer , FBIOGET_VSCREENINFO , &vinfo ) ) {
|
|
51 send_current_error_msg("Variable information not gotton !");
|
|
52 exit(3);
|
|
53 }
|
|
54 xres = vinfo.xres ;
|
|
55 yres = vinfo.yres ;
|
|
56 printf("vinfo.yres %d \n", vinfo.yres);
|
|
57 vbpp = vinfo.bits_per_pixel ;
|
|
58 line_len = finfo.line_length ;
|
|
59 sprintf( tmp , "%d(pixel)x%d(line), %dbpp(bits per pixel)",xres,yres,vbpp);
|
|
60 sprintf( tmp , "%d(xoffset)x%d(yoffset)",vinfo.xoffset, vinfo.yoffset);
|
|
61 send_current_information( tmp );
|
|
62
|
|
63 /* バイト単位でのスクリーンのサイズを計算 */
|
|
64 screensize = xres * yres * vbpp / DIV_BYTE ;
|
|
65
|
|
66 /* デバイスをメモリにマップする */
|
|
67 fbptr = (char *)mmap(0,screensize,PROT_READ | PROT_WRITE,MAP_SHARED,fd_framebuffer,0);
|
|
68 if ( (int)fbptr == -1 ) {
|
|
69 send_current_error_msg("Don't get framebuffer device to memory !");
|
|
70 exit(4);
|
|
71 }
|
|
72 send_current_information("The framebuffer device was mapped !");
|
|
73
|
|
74 printf("fb: 0x%x \n", (unsigned int)fbptr);
|
|
75
|
|
76 fb_t fb;
|
|
77 fb.pixels = fbptr;
|
|
78 fb.size = screensize;
|
|
79 fb.width = xres;
|
|
80 fb.height = yres;
|
|
81 fb.bpp = vbpp;
|
|
82 fb.fd = fd_framebuffer;
|
|
83
|
|
84 return fb;
|
|
85
|
|
86 }
|
|
87
|
|
88 int main() {
|
|
89
|
|
90 fb_t fb = get_fbdev_addr();
|
|
91
|
|
92 void *p;
|
|
93 Uint32 *gUra;
|
|
94
|
|
95 gUra = (Uint32*)fb.pixels;
|
|
96 //gUra = (Uint32*)malloc(fb.width*fb.height*4);
|
|
97
|
|
98 printf("fb.height %d \n", fb.height);
|
|
99
|
|
100 int i;
|
|
101 int color = 0;
|
|
102
|
|
103 for (i = 0; i < fb.width*fb.height; i++) {
|
|
104 gUra[i] = color;
|
|
105 }
|
|
106
|
|
107
|
|
108 //初期化
|
|
109 if (SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK ) < 0) {
|
|
110 printf("SDL_Init failed\n");
|
|
111 return -1;
|
|
112 }
|
|
113
|
|
114 printf("fb.width %d fb.height %d fb.bpp %d \n",fb.width, fb.height, fb.bpp);
|
|
115
|
|
116 SDL_Surface *screen=SDL_SetVideoMode(fb.width,fb.height,fb.bpp,SDL_HWSURFACE);
|
|
117 if (screen == NULL) {
|
|
118 printf("SDL_Surface failed\n");
|
|
119 SDL_Quit();
|
|
120 return -1;
|
|
121 }
|
|
122
|
|
123 int done = 0;
|
|
124 SDL_Event event;
|
|
125
|
|
126 int fps=0;
|
|
127
|
|
128 Uint32 t1=SDL_GetTicks();
|
|
129
|
|
130 while(!done){
|
|
131 while(SDL_PollEvent(&event)){
|
|
132 switch(event.type){
|
|
133 case SDL_QUIT:
|
|
134 done = 1;
|
|
135 break;
|
|
136 case SDL_KEYDOWN:
|
|
137 if(event.key.keysym.sym == SDLK_ESCAPE){
|
|
138 done = 1;
|
|
139 }
|
|
140 break;
|
|
141 }
|
|
142 }
|
|
143
|
|
144 if (color == 0xffffffff) {
|
|
145 color = 0;
|
|
146 } else {
|
|
147
|
|
148 char r = ((color & redMask) >> 16) + 1;
|
|
149 char g = ((color & greenMask) >> 8) + 1;
|
|
150 char b = (color & blueMask) + 1;
|
|
151
|
|
152 color = alphaMask + (r << 16) + (g << 8) + b;
|
|
153
|
|
154 }
|
|
155
|
|
156 for (i = 0; i < fb.width*fb.height; i++) {
|
|
157 gUra[i] = color;
|
|
158 }
|
|
159
|
|
160
|
|
161 if (SDL_GetTicks() < t1 + 1000){
|
|
162 fps++;
|
|
163 } else{
|
|
164 printf("fps=%d\n", fps);
|
|
165 fps=0;
|
|
166 t1=SDL_GetTicks();
|
|
167 }
|
|
168 }
|
|
169
|
|
170 for (i = 0; i < fb.width*fb.height; i++) {
|
|
171 gUra[i] = 0;
|
|
172 }
|
|
173 munmap(fb.pixels, fb.size);
|
|
174 close(fb.fd);
|
|
175 SDL_Quit();
|
|
176
|
|
177
|
|
178 return 0;
|
|
179
|
|
180 }
|
|
181
|