Mercurial > hg > Members > kono > Cerium
comparison TaskManager/Test/simple_pack/fb.cpp @ 78:3c6dec161ade
*** empty log message ***
author | chiaki |
---|---|
date | Tue, 19 Feb 2008 15:49:40 +0900 |
parents | |
children | 4d6bd3c0d90b |
comparison
equal
deleted
inserted
replaced
77:459f54b49648 | 78:3c6dec161ade |
---|---|
1 #include <iostream> | |
2 #include <SDL.h> | |
3 #include <SDL_opengl.h> | |
4 #include <math.h> | |
5 #include <unistd.h> | |
6 #include "polygon.h" | |
7 #include "viewer.h" | |
8 #include "sys.h" | |
9 using namespace std; | |
10 | |
11 void cleanup_fbdev() { | |
12 munmap(fbptr, screensize); | |
13 close(fd_framebuffer); | |
14 } | |
15 | |
16 void send_current_error_msg(char *ptr) { | |
17 fprintf( stderr, "%s\n", ptr); | |
18 } | |
19 | |
20 void send_current_information(char *ptr) { | |
21 fprintf( stdout, "%s\n", ptr); | |
22 } | |
23 | |
24 int get_fbdev_addr(void) { | |
25 struct fb_var_screeninfo vinfo; | |
26 struct fb_fix_screeninfo finfo; | |
27 char tmp[DIV_BYTE*10]; | |
28 | |
29 int xres,yres, vbpp, line_len; | |
30 | |
31 /* open the file only for read */ | |
32 fd_framebuffer = open( DEVICE_NAME, O_RDWR); | |
33 if( !fd_framebuffer ) { | |
34 send_current_error_msg("Framebuffer device open error\n"); | |
35 exit(1); | |
36 } | |
37 send_current_information("The framebuffer device was opened\n"); | |
38 | |
39 /* Get the fixed screen info */ | |
40 if( ioctl( fd_framebuffer, FBIOGET_FSCREENINFO, &finfo) ) { | |
41 send_current_error_msg("Fixed information not gotton !"); | |
42 exit(2); | |
43 } | |
44 | |
45 /* Get the flucture screen info */ | |
46 if( ioctl( fd_framebuffer, FBIOGET_VSCREENINFO, &vinfo) ) { | |
47 send_current_error_msg("Variable information not gotton !"); | |
48 exit(3); | |
49 } | |
50 | |
51 xres = vinfo.xres; | |
52 yres = vinfo.yres; | |
53 vbpp = vinfo.bits_per_pixel; | |
54 line_len = finfo.line_length; | |
55 sprintf( tmp, "%d(pixel)x%d(line), %dbpp(bits per pixel)", xres, yres, vbpp); | |
56 send_current_information( tmp ); | |
57 | |
58 /* calcurate screen size per byte */ | |
59 screensize = xres * yres * vbpp / DIV_BYTE; | |
60 | |
61 /* mapping device to memory */ | |
62 fbptr = (char *)mmap(0,screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fd_framebuffer, 0); | |
63 if( (int)fbptr == -1) { | |
64 send_current_error_msg("Don't get framebuffer device to memory !"); | |
65 exit(4); | |
66 } | |
67 send_current_information("The framebuffer device was mapped !"); | |
68 | |
69 printf("fbptr:%x\n",(unsigned int)fbptr); | |
70 //munmap(fbptr, screensize); | |
71 //close(fd_framebuffer); | |
72 return (unsigned int)fbptr; | |
73 } |