framebuffer-ng: move hw-specific stuff into fbaccel

hardware initialization is platform specific, so put
it into fbaccel instead.
This commit is contained in:
Stefan Seyfried
2013-11-09 15:47:47 +01:00
parent 5a462721cb
commit 91ee918dd5
3 changed files with 65 additions and 54 deletions

View File

@@ -197,6 +197,7 @@ CFbAccel::CFbAccel(CFrameBuffer *_fb)
{
blit_thread = false;
fb = _fb;
init();
lastcol = 0xffffffff;
lbb = fb->lfb; /* the memory area to draw to... */
#ifdef HAVE_SPARK_HARDWARE
@@ -311,6 +312,12 @@ CFbAccel::~CFbAccel()
if (devmem_fd != -1)
close(devmem_fd);
#endif
#ifndef USE_OPENGL
if (fb->lfb)
munmap(fb->lfb, fb->available);
if (fb->fd > -1)
close(fb->fd);
#endif
}
void CFbAccel::update()
@@ -928,3 +935,57 @@ void CFbAccel::mark(int, int, int, int)
}
#endif
bool CFbAccel::init(void)
{
fb_pixel_t *lfb;
fb->lfb = NULL;
fb->fd = -1;
#ifdef USE_OPENGL
if (!glfb) {
fprintf(stderr, "CFbAccel::init: GL Framebuffer is not set up? we are doomed...\n");
return false;
}
fb->screeninfo = glfb->getScreenInfo();
fb->stride = 4 * fb->screeninfo.xres;
fb->available = glfb->getOSDBuffer()->size(); /* allocated in glfb constructor */
lfb = reinterpret_cast<fb_pixel_t*>(glfb->getOSDBuffer()->data());
#else
int fd;
#if HAVE_TRIPLEDRAGON
/* kernel is too old for O_CLOEXEC :-( */
fd = open("/dev/fb0", O_RDWR);
if (fd != -1)
fcntl(fd, F_SETFD, FD_CLOEXEC);
#else
fd = open("/dev/fb0", O_RDWR|O_CLOEXEC);
#endif
if (fd < 0) {
perror("open /dev/fb0");
return false;
}
fb->fd = fd;
if (ioctl(fd, FBIOGET_VSCREENINFO, &fb->screeninfo) < 0) {
perror("FBIOGET_VSCREENINFO");
return false;
}
if (ioctl(fd, FBIOGET_FSCREENINFO, &fb->fix) < 0) {
perror("FBIOGET_FSCREENINFO");
return false;
}
fb->available = fb->fix.smem_len;
printf("%dk video mem\n", fb->available / 1024);
lfb = (fb_pixel_t *)mmap(0, fb->available, PROT_WRITE|PROT_READ, MAP_SHARED, fd, 0);
if (lfb == MAP_FAILED) {
perror("mmap");
return false;;
}
#endif
memset(lfb, 0, fb->available);
fb->lfb = lfb;
return true;
}

View File

@@ -62,6 +62,7 @@ class CFbAccel
fb_pixel_t *lbb;
CFbAccel(CFrameBuffer *fb);
~CFbAccel();
bool init(void);
void paintPixel(int x, int y, const fb_pixel_t col);
void paintRect(const int x, const int y, const int dx, const int dy, const fb_pixel_t col);
void paintLine(int xa, int ya, int xb, int yb, const fb_pixel_t col);

View File

@@ -219,53 +219,10 @@ void CFrameBuffer::setupGXA(void)
}
#endif
void CFrameBuffer::init(const char * const fbDevice)
void CFrameBuffer::init(const char * const)
{
int tr = 0xFF;
#ifdef USE_OPENGL
(void)fbDevice;
fd = -1;
if (!glfb) {
fprintf(stderr, "CFrameBuffer::init: GL Framebuffer is not set up? we are doomed...\n");
goto nolfb;
}
screeninfo = glfb->getScreenInfo();
stride = 4 * screeninfo.xres;
available = glfb->getOSDBuffer()->size(); /* allocated in glfb constructor */
lfb = reinterpret_cast<fb_pixel_t*>(glfb->getOSDBuffer()->data());
memset(lfb, 0x7f, stride * screeninfo.yres);
#else
fd = open(fbDevice, O_RDWR);
if(!fd) fd = open(fbDevice, O_RDWR);
if (fd<0) {
perror(fbDevice);
goto nolfb;
}
if (ioctl(fd, FBIOGET_VSCREENINFO, &screeninfo)<0) {
perror("FBIOGET_VSCREENINFO");
goto nolfb;
}
memmove(&oldscreen, &screeninfo, sizeof(screeninfo));
if (ioctl(fd, FBIOGET_FSCREENINFO, &fix)<0) {
perror("FBIOGET_FSCREENINFO");
goto nolfb;
}
available=fix.smem_len;
printf("%dk video mem\n", available/1024);
lfb=(fb_pixel_t*)mmap(0, available, PROT_WRITE|PROT_READ, MAP_SHARED, fd, 0);
if (lfb == MAP_FAILED) {
perror("mmap");
goto nolfb;
}
memset(lfb, 0, available);
#endif /* USE_OPENGL */
accel = new CFbAccel(this);
cache_size = 0;
/* Windows Colors */
@@ -292,12 +249,7 @@ void CFrameBuffer::init(const char * const fbDevice)
useBackground(false);
m_transparent = m_transparent_default;
accel = new CFbAccel(this);
return;
nolfb:
printf("framebuffer not available.\n");
lfb=0;
}
@@ -322,19 +274,16 @@ CFrameBuffer::~CFrameBuffer()
backupBackground = NULL;
}
if (lfb)
munmap(lfb, available);
if (virtual_fb){
delete[] virtual_fb;
virtual_fb = NULL;
}
delete accel;
close(fd);
}
int CFrameBuffer::getFileHandle() const
{
fprintf(stderr, "[fb]::%s: WARNING, this should never be used, please report!\n", __func__);
return fd;
}