comparison Renderer/Engine/viewerSDL.cc @ 0:04e28d8d3c6f

first commit
author Daiki KINJYO <e085722@ie.u-ryukyu.ac.jp>
date Mon, 08 Nov 2010 01:23:25 +0900
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:04e28d8d3c6f
1 #include "viewerSDL.h"
2 #include "Func.h"
3 #include "TaskManager.h"
4 #include "viewer_types.h"
5 #include "fb.h"
6
7 #define UGA 1
8
9 extern void post2runLoop(void *);
10
11 #define default_sdl_flag SDL_INIT_TIMER | SDL_INIT_JOYSTICK
12
13 ViewerSDL::ViewerSDL() {}
14 ViewerSDL::~ViewerSDL() {}
15
16 #define DEVICE_NAME "/dev/fb0"
17 #define DIV_BYTE 8
18
19 Uint32 *
20 ViewerSDL::video_init(TaskManager *manager, int bpp, int width, int height)
21 {
22
23 #if defined(__linux__)
24
25 int fd_framebuffer ;
26 struct fb_var_screeninfo vinfo;
27 struct fb_fix_screeninfo finfo;
28
29 // 読み書き用にファイルを開く
30 fd_framebuffer = open( DEVICE_NAME , O_RDWR);
31 if ( !fd_framebuffer ) {
32 send_current_error_msg("Framebuffer device open error !");
33 exit(1);
34 }
35 send_current_information("The framebuffer device was opened !");
36
37 // 固定スクリーン情報取得
38 if ( ioctl( fd_framebuffer , FBIOGET_FSCREENINFO , &finfo ) ) {
39 send_current_error_msg("Fixed information not gotton !");
40 exit(2);
41 }
42
43 // 変動スクリーン情報取得
44 if ( ioctl( fd_framebuffer , FBIOGET_VSCREENINFO , &vinfo ) ) {
45 send_current_error_msg("Variable information not gotton !");
46 exit(3);
47 }
48
49 close(fd_framebuffer);
50
51 width = vinfo.xres;
52 height = vinfo.yres;
53 bpp = vinfo.bits_per_pixel;
54
55 #endif
56
57 Uint32 sdl_flag = default_sdl_flag | SDL_INIT_VIDEO;
58 Uint32 *p;
59
60 if (SDL_Init(sdl_flag) < 0) {
61 fprintf(stderr,"Couldn't initialize SDL: %s\n", SDL_GetError());
62 exit(1);
63 }
64
65 screen = SDL_SetVideoMode(width, height, bpp, SDL_HWSURFACE);
66 if (screen == NULL) {
67 fprintf(stderr, "Couldn't set SDL mode: %s\n", SDL_GetError());
68 SDL_Quit();
69 exit(1);
70 }
71
72 this->width = screen->w;
73 this->height = screen->h;
74 this->bpp = screen->format->BitsPerPixel;
75
76 p = (Uint32*)manager->allocate(screen->pitch*height);
77
78 return p;
79 }
80
81 void
82 ViewerSDL::clean_pixels()
83 {
84 //bzero(pixels, sizeof(int)*width*height);
85
86 //SDL_FillRect(screen,NULL,SDL_MapRGB(screen->format,0,0,0));
87 }
88
89 void
90 ViewerSDL::clear_screen()
91 {
92
93 #if !UGA
94 SDL_BlitSurface(bitmap, NULL, screen, NULL);
95 SDL_UpdateRect(screen, 0, 0, 0, 0);
96 #endif
97
98 }
99
100 uint32_t *
101 ViewerSDL::flip_screen(uint32_t *old)
102 {
103 #if UGA
104
105 bitmap = SDL_CreateRGBSurfaceFrom((void *)old,
106 screen->w, screen->h,
107 screen->format->BitsPerPixel,
108 screen->pitch,
109 //redMask, greenMask, blueMask, alphaMask);
110 redMask, greenMask, blueMask, 0);
111
112 SDL_BlitSurface(bitmap,NULL,screen,NULL);
113 SDL_UpdateRect(screen,0,0,0,0);
114
115 #endif
116
117 return old;
118 }
119
120 void
121 ViewerSDL::free_device()
122 {
123 free(bitmap->pixels);
124 SDL_FreeSurface(bitmap);
125 }