Mercurial > hg > Game > Cerium
comparison Renderer/Engine/viewerFB.cc @ 895:b662e9dd26b0 draft
add alignment of classes in SPU
width and height are automatically set in frame buffer API
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 16 Jul 2010 17:23:49 +0900 |
parents | c7afc21e448d |
children | 1760b45ca799 |
comparison
equal
deleted
inserted
replaced
894:d9d229ede3ff | 895:b662e9dd26b0 |
---|---|
1 #include "viewerFB.h" | 1 #include "viewerFB.h" |
2 #include "fb.h" | 2 #include "fb.h" |
3 #include <stdio.h> | |
3 | 4 |
4 #define default_sdl_flag SDL_INIT_TIMER | SDL_INIT_JOYSTICK | 5 #define default_sdl_flag SDL_INIT_TIMER | SDL_INIT_JOYSTICK |
5 //extern void post2runLoop(void *); | 6 |
6 ViewerFB::ViewerFB() {} | 7 ViewerFB::ViewerFB() {} |
7 ViewerFB::~ViewerFB() {} | 8 ViewerFB::~ViewerFB() {} |
9 | |
10 #if defined(__linux__) | |
11 | |
12 #define DEVICE_NAME "/dev/fb0" | |
13 #define DIV_BYTE 8 | |
14 | |
15 | |
16 ScreenInfo get_fbdev_addr(void) | |
17 { | |
18 ScreenInfo info; | |
19 int fd_framebuffer ; | |
20 struct fb_var_screeninfo vinfo; | |
21 struct fb_fix_screeninfo finfo; | |
22 long int screensize ; | |
23 //long int location; | |
24 char *fbptr ; | |
25 char tmp[DIV_BYTE*10]; | |
26 | |
27 //int x , y ; | |
28 int xres,yres,vbpp,line_len; | |
29 //unsigned short tcolor ; | |
30 | |
31 /* 読み書き用にファイルを開く */ | |
32 fd_framebuffer = open( DEVICE_NAME , O_RDWR); | |
33 if ( !fd_framebuffer ) { | |
34 send_current_error_msg("Framebuffer device open error !"); | |
35 exit(1); | |
36 } | |
37 send_current_information("The framebuffer device was opened !"); | |
38 | |
39 /* 固定スクリーン情報取得 */ | |
40 if ( ioctl( fd_framebuffer , FBIOGET_FSCREENINFO , &finfo ) ) { | |
41 send_current_error_msg("Fixed information not gotton !"); | |
42 exit(2); | |
43 } | |
44 | |
45 /* 変動スクリーン情報取得 */ | |
46 if ( ioctl( fd_framebuffer , FBIOGET_VSCREENINFO , &vinfo ) ) { | |
47 send_current_error_msg("Variable information not gotton !"); | |
48 exit(3); | |
49 } | |
50 xres = vinfo.xres ; | |
51 yres = vinfo.yres ; | |
52 vbpp = vinfo.bits_per_pixel ; | |
53 line_len = finfo.line_length ; | |
54 sprintf( tmp , "%d(pixel)x%d(line), %dbpp(bits per pixel)",xres,yres,vbpp); | |
55 send_current_information( tmp ); | |
56 | |
57 /* バイト単位でのスクリーンのサイズを計算 */ | |
58 screensize = xres * yres * vbpp / DIV_BYTE ; | |
59 | |
60 /* デバイスをメモリにマップする */ | |
61 fbptr = (char *)mmap(0,screensize,PROT_READ | PROT_WRITE,MAP_SHARED,fd_framebuffer,0); | |
62 if ( (int)fbptr == -1 ) { | |
63 send_current_error_msg("Don't get framebuffer device to memory !"); | |
64 exit(4); | |
65 } | |
66 send_current_information("The framebuffer device was mapped !"); | |
67 | |
68 printf("fb: 0x%x \n", (unsigned int)fbptr); | |
69 info.xres = xres; | |
70 info.yres = yres; | |
71 info.vbpp = vbpp; | |
72 info.line_len = line_len; | |
73 info.fbptr = fbptr; | |
74 | |
75 return info; | |
76 //munmap(fbptr,screensize); | |
77 //close(fd_framebuffer); | |
78 //return 0; | |
79 } | |
80 | |
81 void send_current_error_msg(const char *ptr) | |
82 { | |
83 fprintf( stderr , "%s\n" , ptr ); | |
84 } | |
85 | |
86 void send_current_information(const char *ptr) | |
87 { | |
88 fprintf( stdout , "%s\n" , ptr ); | |
89 } | |
90 | |
91 #else /* !defined(__linux__) */ | |
92 ScreenInfo get_fbdev_addr(void) { | |
93 ScreenInfo tmp = {0,0,0,0}; | |
94 return tmp; | |
95 } | |
96 #endif /* defined(__linux__) */ | |
97 | |
8 | 98 |
9 Uint32 * | 99 Uint32 * |
10 ViewerFB::video_init(TaskManager *manager, int bpp, int width, int height) | 100 ViewerFB::video_init(TaskManager *manager, int bpp, int width, int height) |
11 { | 101 { |
12 Uint32 sdl_flag = default_sdl_flag | SDL_INIT_VIDEO; | 102 Uint32 sdl_flag = default_sdl_flag | SDL_INIT_VIDEO; |
14 if (SDL_Init(sdl_flag) < 0) { | 104 if (SDL_Init(sdl_flag) < 0) { |
15 fprintf(stderr,"Couldn't initialize SDL: %s\n",SDL_GetError()); | 105 fprintf(stderr,"Couldn't initialize SDL: %s\n",SDL_GetError()); |
16 exit(1); | 106 exit(1); |
17 } | 107 } |
18 | 108 |
19 Uint32 *pixels = (Uint32*)get_fbdev_addr(); | 109 screen_info = get_fbdev_addr(); |
110 Uint32 *pixels = (Uint32*) screen_info.fbptr; | |
20 | 111 |
21 if (pixels == 0) { | 112 if (pixels == 0) { |
113 fprintf(stderr, "Cannot get frame buffer!\n"); | |
22 pixels = (new Uint32[width*height*32/8]); | 114 pixels = (new Uint32[width*height*32/8]); |
23 } | 115 } |
116 width = screen_info.xres; | |
117 height = screen_info.yres; | |
118 bpp = screen_info.vbpp; | |
24 | 119 |
25 return pixels; | 120 return pixels; |
26 } | 121 } |
27 | 122 |
28 void | 123 void |
29 ViewerFB::clean_pixels() | 124 ViewerFB::clean_pixels() |
30 { | 125 { |
31 //bzero(pixels, sizeof(int)*width*height); | |
32 //memset(pixels, 0xFF, sizeof(int)*width*height); | |
33 } | 126 } |
34 | 127 |
35 void | 128 void |
36 ViewerFB::clear_screen() | 129 ViewerFB::clear_screen() |
37 { | 130 { |