Mercurial > hg > Members > kono > Cerium
changeset 78:3c6dec161ade
*** empty log message ***
author | chiaki |
---|---|
date | Tue, 19 Feb 2008 15:49:40 +0900 |
parents | 459f54b49648 |
children | 83b57e03d3ef |
files | TaskManager/Test/simple_pack/fb.cpp |
diffstat | 1 files changed, 73 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/simple_pack/fb.cpp Tue Feb 19 15:49:40 2008 +0900 @@ -0,0 +1,73 @@ +#include <iostream> +#include <SDL.h> +#include <SDL_opengl.h> +#include <math.h> +#include <unistd.h> +#include "polygon.h" +#include "viewer.h" +#include "sys.h" +using namespace std; + +void cleanup_fbdev() { + munmap(fbptr, screensize); + close(fd_framebuffer); +} + +void send_current_error_msg(char *ptr) { + fprintf( stderr, "%s\n", ptr); +} + +void send_current_information(char *ptr) { + fprintf( stdout, "%s\n", ptr); +} + +int get_fbdev_addr(void) { + struct fb_var_screeninfo vinfo; + struct fb_fix_screeninfo finfo; + char tmp[DIV_BYTE*10]; + + int xres,yres, vbpp, line_len; + + /* open the file only for read */ + fd_framebuffer = open( DEVICE_NAME, O_RDWR); + if( !fd_framebuffer ) { + send_current_error_msg("Framebuffer device open error\n"); + exit(1); + } + send_current_information("The framebuffer device was opened\n"); + + /* Get the fixed screen info */ + if( ioctl( fd_framebuffer, FBIOGET_FSCREENINFO, &finfo) ) { + send_current_error_msg("Fixed information not gotton !"); + exit(2); + } + + /* Get the flucture screen info */ + if( ioctl( fd_framebuffer, FBIOGET_VSCREENINFO, &vinfo) ) { + send_current_error_msg("Variable information not gotton !"); + exit(3); + } + + xres = vinfo.xres; + yres = vinfo.yres; + vbpp = vinfo.bits_per_pixel; + line_len = finfo.line_length; + sprintf( tmp, "%d(pixel)x%d(line), %dbpp(bits per pixel)", xres, yres, vbpp); + send_current_information( tmp ); + + /* calcurate screen size per byte */ + screensize = xres * yres * vbpp / DIV_BYTE; + + /* mapping device to memory */ + fbptr = (char *)mmap(0,screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fd_framebuffer, 0); + if( (int)fbptr == -1) { + send_current_error_msg("Don't get framebuffer device to memory !"); + exit(4); + } + send_current_information("The framebuffer device was mapped !"); + + printf("fbptr:%x\n",(unsigned int)fbptr); + //munmap(fbptr, screensize); + //close(fd_framebuffer); + return (unsigned int)fbptr; +}