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