comparison Renderer/Engine/viewerFB.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 "viewerFB.h"
2 #include "fb.h"
3 #include <stdio.h>
4 #if 0
5 #include <asm/ps3fb.h>
6 #endif
7
8
9 #define default_sdl_flag SDL_INIT_TIMER | SDL_INIT_JOYSTICK
10
11 ViewerFB::ViewerFB() {}
12 ViewerFB::~ViewerFB() {}
13
14 #if defined(__linux__)
15
16 #define DEVICE_NAME "/dev/fb0"
17 #define DIV_BYTE 8
18
19
20 ScreenInfo get_fbdev_addr(void)
21 {
22 ScreenInfo info;
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 vbpp = vinfo.bits_per_pixel ;
57 line_len = finfo.line_length ;
58 sprintf( tmp , "%d(pixel)x%d(line), %dbpp(bits per pixel)",xres,yres,vbpp);
59 send_current_information( tmp );
60
61 /* バイト単位でのスクリーンのサイズを計算 */
62 screensize = xres * yres * vbpp / DIV_BYTE ;
63
64 /* デバイスをメモリにマップする */
65 fbptr = (char *)mmap(0,screensize,PROT_READ | PROT_WRITE,MAP_SHARED,fd_framebuffer,0);
66 if ( (int)fbptr == -1 ) {
67 send_current_error_msg("Don't get framebuffer device to memory !");
68 exit(4);
69 }
70 send_current_information("The framebuffer device was mapped !");
71
72 #if 0
73 // Take control of frame buffer from kernel
74 ioctl(fd_framebuffer, PS3FB_IOCTL_ON, 0);
75 int field_ndx = 0;
76 ioctl(fd_framebuffer , PS3FB_IOCTL_FSEL, &field_ndx );
77 #endif
78
79
80 printf("fb: 0x%x \n", (unsigned int)fbptr);
81 info.xres = xres;
82 info.yres = yres;
83 info.vbpp = vbpp;
84 info.line_len = line_len;
85 info.fbptr[0] = (uint32_t *)fbptr;
86
87 return info;
88 //munmap(fbptr,screensize);
89 //close(fd_framebuffer);
90 //return 0;
91 }
92
93 void send_current_error_msg(const char *ptr)
94 {
95 fprintf( stderr , "%s\n" , ptr );
96 }
97
98 void send_current_information(const char *ptr)
99 {
100 fprintf( stdout , "%s\n" , ptr );
101 }
102
103 #else /* !defined(__linux__) */
104 ScreenInfo get_fbdev_addr(void) {
105 ScreenInfo tmp = {0,0,0,0};
106 return tmp;
107 }
108 #endif /* defined(__linux__) */
109
110
111 Uint32 *
112 ViewerFB::video_init(TaskManager *manager, int bpp, int width, int height)
113 {
114 Uint32 sdl_flag = default_sdl_flag | SDL_INIT_VIDEO;
115
116 if (SDL_Init(sdl_flag) < 0) {
117 fprintf(stderr,"Couldn't initialize SDL: %s\n",SDL_GetError());
118 exit(1);
119 }
120
121 screen_info = get_fbdev_addr();
122 Uint32 *pixels = screen_info.fbptr[0];
123
124 if (pixels == 0) {
125 fprintf(stderr, "Cannot get frame buffer!\n");
126 pixels = (new Uint32[width*height*32/8]);
127 }
128 this->width = screen_info.xres;
129 this->height = screen_info.yres;
130 this->bpp = screen_info.vbpp;
131
132 return pixels;
133 }
134
135 void
136 ViewerFB::clean_pixels()
137 {
138 }
139
140 void
141 ViewerFB::clear_screen()
142 {
143 }
144
145
146 void
147 ViewerFB::free_device()
148 {
149 }
150
151