#include #include "framebuffer.hpp" using namespace net::lliurex::bootcookie; using namespace std; Exception::Exception(int type,const char * msg) { this->type=type; this->message=string(msg); } FrameBuffer * FrameBuffer::factory = NULL; FrameBuffer * FrameBuffer::GetDefault() { if(FrameBuffer::factory==NULL) { FrameBuffer::factory = new FrameBuffer(); } return FrameBuffer::factory; } FrameBuffer::FrameBuffer() { //opening framebuffer fbfd = open("/dev/fb0", O_RDWR); if(fbfd==-1)throw Exception(BK_EXCEPTION_OPEN,"Failed to open FB0"); if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo) == -1)throw Exception(BK_EXCEPTION_INFO,"Failed to retrieve fscreen info"); if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo) == -1)throw Exception(BK_EXCEPTION_INFO,"Failed to retrieve vscreen info"); cout<<"FrameBuffer info:"<=8) screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8; else //assuming 4bpp { throw Exception(BK_EXCEPTION_COLOR_DEPTH,"Unsupported color depth"); } // Map the device to memory buffer = (uint8_t *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0); if (buffer == MAP_FAILED) { throw Exception(BK_EXCEPTION_MMAP,"Failed to map framebuffer device to memory"); } //Loading resources palette.Load("../data/256.pal"); switch(vinfo.bits_per_pixel) { /* RGB modes*/ case 32: case 24: cout<<"* RGB color depth"<width; yb = y + surface->height; //CLIP ONE if(x>=vinfo.xres || y>=vinfo.yres)return; //CLIP TWO if( (x + surface->width) >= vinfo.xres ) { xb = vinfo.xres - 1; } if( (y + surface->height) >= vinfo.yres ) { yb = vinfo.yres - 1; } //CLIP THREE if( (x + surface->width) < 0 || (y + surface->height)<0 )return; //CLIP FOUR if(x<0 && (x+surface->width)>=0) { xa=0; } if(y<0 && (y+surface->height)>=0) { ya=0; } int index; long int p; //cout <<"debug x: "<pixels[i+j*surface->width]; if(index==0)continue; switch(vinfo.bits_per_pixel) { case 32: *(buffer + p + 2) = palette.red[index]; *(buffer + p + 1) = palette.green[index]; *(buffer + p + 0) = palette.blue[index]; *(buffer + p + 3) = 0xFF; break; case 24: *(buffer + p + 2) = palette.red[index]; *(buffer + p + 1) = palette.green[index]; *(buffer + p + 0) = palette.blue[index]; break; case 16: b = palette.blue[index]; g = palette.green[index]; r = palette.blue[index]; r=r>>3; g=g>>2; b=b>>3; *(buffer +p + 0) = g<<5 | b; *(buffer +p + 1) = r<<3 | g>>3; break; case 8: *(buffer + p) = index; break; } } } } void FrameBuffer::Destroy() { munmap(buffer, screensize); }