132 lines
3.5 KiB
C
Raw Normal View History

2012-06-10 21:59:05 +01:00
/*
droid VNC server - a vnc server for android
Copyright (C) 2011 Jose Pereira <onaips@gmail.com>
Other contributors:
Oleksandr Andrushchenko <andr2000@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "framebuffer.h"
#include "gui.h"
int fbfd = -1;
2012-06-11 20:08:17 +01:00
unsigned int *fbmmap;
2012-06-10 21:59:05 +01:00
char framebuffer_device[256] = "/dev/graphics/fb0";
2012-06-11 20:08:17 +01:00
struct fb_var_screeninfo scrinfo;
struct fb_fix_screeninfo fscrinfo;
2012-06-10 21:59:05 +01:00
2012-06-11 20:08:17 +01:00
void FB_setDevice(char *s)
2012-06-10 21:59:05 +01:00
{
strcpy(framebuffer_device,s);
}
2012-06-11 20:08:17 +01:00
void update_fb_info(void)
{
if (ioctl(fbfd, FBIOGET_VSCREENINFO, &scrinfo) != 0) {
L("ioctl error\n");
sendMsgToGui("~SHOW|Framebuffer ioctl error, please try out other display grab method\n");
exit(EXIT_FAILURE);
}
}
int initFB(void)
2012-06-10 21:59:05 +01:00
{
L("--Initializing framebuffer access method--\n");
fbmmap = MAP_FAILED;
2012-06-11 20:03:54 +01:00
if ((fbfd = open(framebuffer_device, O_RDWR)) == -1) {
2012-06-10 21:59:05 +01:00
L("Cannot open fb device %s\n", framebuffer_device);
sendMsgToGui("~SHOW|Cannot open fb device, please try out other display grab method\n");
return -1;
}
update_fb_info();
2012-06-11 20:03:54 +01:00
if (ioctl(fbfd, FBIOGET_FSCREENINFO, &fscrinfo) != 0) {
2012-06-10 21:59:05 +01:00
L("ioctl error\n");
return -1;
}
L("line_lenght=%d xres=%d, yres=%d, xresv=%d, yresv=%d, xoffs=%d, yoffs=%d, bpp=%d\n",
(int)fscrinfo.line_length,(int)scrinfo.xres, (int)scrinfo.yres,
(int)scrinfo.xres_virtual, (int)scrinfo.yres_virtual,
(int)scrinfo.xoffset, (int)scrinfo.yoffset,
(int)scrinfo.bits_per_pixel);
2012-06-11 20:03:54 +01:00
size_t size = scrinfo.yres_virtual;
if (size < scrinfo.yres * 2) {
2012-06-10 21:59:05 +01:00
L("Using Droid workaround\n");
2012-06-11 20:03:54 +01:00
size = scrinfo.yres * 2;
2012-06-10 21:59:05 +01:00
}
2012-06-11 20:08:17 +01:00
if ((scrinfo.bits_per_pixel == 24)) {
scrinfo.bits_per_pixel = 32;
L("24-bit XRGB display detected\n");
}
2012-06-10 21:59:05 +01:00
size_t fbSize = roundUpToPageSize(fscrinfo.line_length * size);
fbmmap = mmap(NULL, fbSize , PROT_READ|PROT_WRITE , MAP_SHARED , fbfd, 0);
2012-06-11 20:03:54 +01:00
if (fbmmap == MAP_FAILED) {
2012-06-10 21:59:05 +01:00
L("mmap failed\n");
sendMsgToGui("~SHOW|Framebuffer mmap failed, please try out other display grab method\n");
return -1;
}
2012-06-11 20:08:17 +01:00
screenformat.bitsPerPixel = scrinfo.bits_per_pixel;
screenformat.size = scrinfo.xres * scrinfo.yres * scrinfo.bits_per_pixel / CHAR_BIT;
screenformat.width = scrinfo.xres;
screenformat.height = scrinfo.yres;
screenformat.redShift = scrinfo.red.offset;
screenformat.redMax = scrinfo.red.length;
screenformat.greenShift = scrinfo.green.offset;
screenformat.greenMax = scrinfo.green.length;
screenformat.blueShift = scrinfo.blue.offset;
screenformat.blueMax = scrinfo.blue.length;
screenformat.alphaShift = scrinfo.transp.offset;
screenformat.alphaMax = scrinfo.transp.length;
2012-06-11 20:03:54 +01:00
return 1;
2012-06-10 21:59:05 +01:00
}
2012-06-11 20:08:17 +01:00
void closeFB(void)
2012-06-10 21:59:05 +01:00
{
if(fbfd != -1)
2012-06-11 20:03:54 +01:00
close(fbfd);
2012-06-10 21:59:05 +01:00
}
2012-06-11 20:08:17 +01:00
struct fb_var_screeninfo FB_getscrinfo(void)
{
return scrinfo;
}
2012-06-10 21:59:05 +01:00
2012-06-11 20:08:17 +01:00
unsigned int *readBufferFB(void)
{
update_fb_info();
return fbmmap;
}
2012-06-10 21:59:05 +01:00
inline int roundUpToPageSize(int x) {
return (x + (PAGE_SIZE-1)) & ~(PAGE_SIZE-1);
}