996
|
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 close(fb.fd);
|
|
92
|
|
93 void *p;
|
|
94 Uint32 *gUra;
|
|
95
|
|
96 //posix_memalign((void**)&gUra, 16, fb.width*fb.height*4);
|
|
97
|
|
98 gUra = (Uint32*)malloc(fb.width*fb.height*4);
|
|
99 Uint32 *tmp = (Uint32*)malloc(fb.width*fb.height*4);
|
|
100
|
|
101 printf("fb.height %d \n", fb.height);
|
|
102
|
|
103 int i;
|
|
104 int color = 0x000000ff;
|
|
105
|
|
106 for (i = 0; i < fb.width*fb.height; i++) {
|
|
107 gUra[i] = color;
|
|
108 }
|
|
109
|
|
110
|
|
111 //初期化
|
|
112 if (SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK ) < 0) {
|
|
113 printf("SDL_Init failed\n");
|
|
114 return -1;
|
|
115 }
|
|
116
|
|
117 printf("fb.width %d fb.height %d fb.bpp %d \n",fb.width, fb.height, fb.bpp);
|
|
118
|
|
119 SDL_Surface *screen=SDL_SetVideoMode(fb.width,fb.height,fb.bpp,SDL_HWSURFACE);
|
|
120 if (screen == NULL) {
|
|
121 printf("SDL_Surface failed\n");
|
|
122 SDL_Quit();
|
|
123 return -1;
|
|
124 }
|
|
125
|
|
126 int done = 0;
|
|
127 SDL_Event event;
|
|
128
|
|
129 int fps=0;
|
|
130
|
|
131 Uint32 t1=SDL_GetTicks();
|
|
132
|
|
133 while(!done){
|
|
134 while(SDL_PollEvent(&event)){
|
|
135 switch(event.type){
|
|
136 case SDL_QUIT:
|
|
137 done = 1;
|
|
138 break;
|
|
139 case SDL_KEYDOWN:
|
|
140 if(event.key.keysym.sym == SDLK_ESCAPE){
|
|
141 done = 1;
|
|
142 }
|
|
143 break;
|
|
144 }
|
|
145 }
|
|
146
|
|
147
|
|
148 //ここに処理を追加して変化を見る
|
|
149 SDL_Surface *bitmap = SDL_CreateRGBSurfaceFrom((void *)gUra,fb.width,fb.height,fb.bpp,fb.width*4,redMask,greenMask,blueMask,alphaMask);
|
|
150 SDL_BlitSurface(bitmap,NULL,screen,NULL);
|
|
151 SDL_UpdateRect(screen,0,0,0,0);
|
|
152
|
|
153
|
|
154 if (SDL_GetTicks() < t1 + 1000){
|
|
155 fps++;
|
|
156 } else{
|
|
157 printf("fps=%d\n", fps);
|
|
158 fps=0;
|
|
159 t1=SDL_GetTicks();
|
|
160 }
|
|
161 }
|
|
162
|
|
163 SDL_Quit();
|
|
164
|
|
165 return 0;
|
|
166
|
|
167 }
|
|
168
|