From e6a32812db7d2461eac610589d192e5cf50636c1 Mon Sep 17 00:00:00 2001 From: Stefan Seyfried Date: Sun, 25 Feb 2018 02:38:08 +0100 Subject: [PATCH] remove old framebuffer code files the new structure seems to be working well, so remove unused stuff Conflicts: src/driver/framebuffer.cpp src/driver/framebuffer_ng.cpp src/driver/framebuffer_ng.h --- src/driver/fbaccel.cpp | 1129 ----------------- src/driver/fbaccel.h | 94 -- src/driver/framebuffer.cpp | 2200 --------------------------------- src/driver/framebuffer_ng.cpp | 1393 --------------------- src/driver/framebuffer_ng.h | 323 ----- 5 files changed, 5139 deletions(-) delete mode 100644 src/driver/fbaccel.cpp delete mode 100644 src/driver/fbaccel.h delete mode 100644 src/driver/framebuffer.cpp delete mode 100644 src/driver/framebuffer_ng.cpp delete mode 100644 src/driver/framebuffer_ng.h diff --git a/src/driver/fbaccel.cpp b/src/driver/fbaccel.cpp deleted file mode 100644 index cab2efc34..000000000 --- a/src/driver/fbaccel.cpp +++ /dev/null @@ -1,1129 +0,0 @@ -/* - Neutrino-GUI - DBoxII-Project - - Copyright (C) 2001 Steffen Hehn 'McClean' - 2003 thegoodguy - Copyright (C) 2007-2013 Stefan Seyfried - - Framebuffer acceleration hardware abstraction functions. - The various hardware dependent framebuffer acceleration functions - are represented in this class. - - License: GPL - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -#if HAVE_COOL_HARDWARE -#include -#include -#endif -#if HAVE_SPARK_HARDWARE -#include -#include -#endif -#if HAVE_GENERIC_HARDWARE -#include -extern GLFramebuffer *glfb; -#endif - -#include -#include - -#if HAVE_COOL_HARDWARE || HAVE_TRIPLEDRAGON -#define NEED_BLIT_THREAD 0 -#else -#define NEED_BLIT_THREAD 1 -#endif - -/* note that it is *not* enough to just change those values */ -#define DEFAULT_XRES 1280 -#define DEFAULT_YRES 720 -#define DEFAULT_BPP 32 - -//#undef USE_NEVIS_GXA //FIXME -/*******************************************************************************/ -#ifdef USE_NEVIS_GXA -#define GXA_POINT(x, y) (((y) & 0x0FFF) << 16) | ((x) & 0x0FFF) -#define GXA_SRC_BMP_SEL(x) (x << 8) -#define GXA_DST_BMP_SEL(x) (x << 5) -#define GXA_PARAM_COUNT(x) (x << 2) - -#define GXA_CMD_REG 0x001C -#define GXA_FG_COLOR_REG 0x0020 -#define GXA_BG_COLOR_REG 0x0024 -#define GXA_LINE_CONTROL_REG 0x0038 -#define GXA_BMP1_TYPE_REG 0x0048 -#define GXA_BMP1_ADDR_REG 0x004C -#define GXA_BMP2_TYPE_REG 0x0050 -#define GXA_BMP2_ADDR_REG 0x0054 -#define GXA_BMP3_TYPE_REG 0x0058 -#define GXA_BMP3_ADDR_REG 0x005C -#define GXA_BMP4_TYPE_REG 0x0060 -#define GXA_BMP4_ADDR_REG 0x0064 -#define GXA_BMP5_TYPE_REG 0x0068 -#define GXA_BMP5_ADDR_REG 0x006C -#define GXA_BMP6_TYPE_REG 0x0070 -#define GXA_BMP7_TYPE_REG 0x0078 -#define GXA_DEPTH_REG 0x00F4 -#define GXA_CONTENT_ID_REG 0x0144 - -#define GXA_CMD_BLT 0x00010800 -#define GXA_CMD_NOT_ALPHA 0x00011000 -#define GXA_CMD_NOT_TEXT 0x00018000 -#define GXA_CMD_QMARK 0x00001000 - -#define GXA_BLEND_CFG_REG 0x003C -#define GXA_CFG_REG 0x0030 -#define GXA_CFG2_REG 0x00FC -/* -static unsigned int _read_gxa(volatile unsigned char *base_addr, unsigned int offset) -{ - return *(volatile unsigned int *)(base_addr + offset); -} -*/ - -static unsigned int _mark = 0; - -static void _write_gxa(volatile unsigned char *base_addr, unsigned int offset, unsigned int value) -{ - while ((*(volatile unsigned int *)(base_addr + GXA_DEPTH_REG)) & 0x40000000) {}; - *(volatile unsigned int *)(base_addr + offset) = value; -} - -/* this adds a tagged marker into the GXA queue. Once this comes out - of the other end of the queue, all commands before it are finished */ -void CFbAccel::add_gxa_sync_marker(void) -{ - unsigned int cmd = GXA_CMD_QMARK | GXA_PARAM_COUNT(1); - // TODO: locking? - _mark++; - _mark &= 0x0000001F; /* bit 0x20 crashes the kernel, if set */ - _write_gxa(gxa_base, cmd, _mark); - //fprintf(stderr, "%s: wrote %02x\n", __FUNCTION__, _mark); -} - -/* wait until the current marker comes out of the GXA command queue */ -void CFbAccel::waitForIdle(void) -{ - unsigned int cfg, count = 0; - do { - cfg = *(volatile unsigned int *)(gxa_base + GXA_CMD_REG); - cfg >>= 24; /* the token is stored in bits 31...24 */ - if (cfg == _mark) - break; - /* usleep is too coarse, because of CONFIG_HZ=100 in kernel - so use sched_yield to at least give other threads a chance to run */ - sched_yield(); - //fprintf(stderr, "%s: read %02x, expected %02x\n", __FUNCTION__, cfg, _mark); - } while(++count < 8192); /* don't deadlock here if there is an error */ - - if (count > 2048) /* more than 2000 are unlikely, even for large BMP6 blits */ - fprintf(stderr, "CFbAccel::waitForIdle: count is big (%d)!\n", count); -} -#elif HAVE_TRIPLEDRAGON -#include -#include -extern IDirectFB *dfb; -extern IDirectFBSurface *dfbdest; -extern int gfxfd; -void CFbAccel::waitForIdle(void) -{ -#if 0 - struct timeval ts, te; - gettimeofday(&ts, NULL); -#endif - /* does not work: DFBResult r = dfb->WaitForSync(dfb); */ - ioctl(gfxfd, STB04GFX_ENGINE_SYNC); -#if 0 - gettimeofday(&te, NULL); - printf("STB04GFX_ENGINE_SYNC took %lld us\n", (te.tv_sec * 1000000LL + te.tv_usec) - (ts.tv_sec * 1000000LL + ts.tv_usec)); -#endif -} -#elif HAVE_SPARK_HARDWARE - -static int bpafd = -1; -static size_t lbb_sz = 1920 * 1080; /* offset from fb start in 'pixels' */ -static size_t lbb_off = lbb_sz * sizeof(fb_pixel_t); /* same in bytes */ -static int backbuf_sz = 0; - -void CFbAccel::waitForIdle(void) -{ -#if 0 /* blits too often and does not seem to be necessary */ - blit_mutex.lock(); - if (blit_pending) - { - blit_mutex.unlock(); - _blit(); - return; - } - blit_mutex.unlock(); -#endif - OpenThreads::ScopedLock m_lock(mutex); - ioctl(fb->fd, STMFBIO_SYNC_BLITTER); -} -#else -void CFbAccel::waitForIdle(void) -{ -} -#endif - -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 - if (fb->available < 12*1024*1024) - { - /* for old installations that did not upgrade their module config - * it will still work good enough to display the message below */ - fprintf(stderr, "[neutrino] WARNING: not enough framebuffer memory available!\n"); - fprintf(stderr, "[neutrino] I need at least 12MB.\n"); - FILE *f = fopen("/tmp/infobar.txt", "w"); - if (f) { - fprintf(f, "NOT ENOUGH FRAMEBUFFER MEMORY!"); - fclose(f); - } - lbb_sz = 0; - lbb_off = 0; - } - lbb = fb->lfb + lbb_sz; - bpafd = open("/dev/bpamem0", O_RDWR | O_CLOEXEC); - if (bpafd < 0) - { - fprintf(stderr, "[neutrino] FB: cannot open /dev/bpamem0: %m\n"); - return; - } - backbuf_sz = 1280 * 720 * sizeof(fb_pixel_t); - BPAMemAllocMemData bpa_data; - bpa_data.bpa_part = (char *)"LMI_VID"; - bpa_data.mem_size = backbuf_sz; - int res; - res = ioctl(bpafd, BPAMEMIO_ALLOCMEM, &bpa_data); - if (res) - { - fprintf(stderr, "[neutrino] FB: cannot allocate from bpamem: %m\n"); - fprintf(stderr, "backbuf_sz: %d\n", backbuf_sz); - close(bpafd); - bpafd = -1; - return; - } - close(bpafd); - - char bpa_mem_device[30]; - sprintf(bpa_mem_device, "/dev/bpamem%d", bpa_data.device_num); - bpafd = open(bpa_mem_device, O_RDWR | O_CLOEXEC); - if (bpafd < 0) - { - fprintf(stderr, "[neutrino] FB: cannot open secondary %s: %m\n", bpa_mem_device); - return; - } - - backbuffer = (fb_pixel_t *)mmap(0, bpa_data.mem_size, PROT_WRITE|PROT_READ, MAP_SHARED, bpafd, 0); - if (backbuffer == MAP_FAILED) - { - fprintf(stderr, "[neutrino] FB: cannot map from bpamem: %m\n"); - ioctl(bpafd, BPAMEMIO_FREEMEM); - close(bpafd); - bpafd = -1; - return; - } -#ifdef PARTIAL_BLIT - to_blit.xs = to_blit.ys = INT_MAX; - to_blit.xe = to_blit.ye = 0; - last_xres = 0; -#endif -#endif - -#ifdef USE_NEVIS_GXA - /* Open /dev/mem for HW-register access */ - devmem_fd = open("/dev/mem", O_RDWR | O_SYNC | O_CLOEXEC); - if (devmem_fd < 0) { - perror("CFbAccel open /dev/mem"); - goto error; - } - - /* mmap the GXA's base address */ - gxa_base = (volatile unsigned char*)mmap(0, 0x00040000, PROT_READ|PROT_WRITE, MAP_SHARED, devmem_fd, 0xE0600000); - if (gxa_base == (void *)-1) { - perror("CFbAccel mmap /dev/mem"); - goto error; - } - - setupGXA(); - error: - /* TODO: what to do here? does this really happen? */ - ; -#endif /* USE_NEVIS_GXA */ - -#if NEED_BLIT_THREAD - /* start the autoblit-thread (run() function) */ - OpenThreads::Thread::start(); -#endif -}; - -CFbAccel::~CFbAccel() -{ - if (blit_thread) - { - blit_thread = false; - blit(); /* wakes up the thread */ - OpenThreads::Thread::join(); - } -#if HAVE_SPARK_HARDWARE - if (backbuffer) - { - fprintf(stderr, "CFbAccel: unmap backbuffer\n"); - munmap(backbuffer, backbuf_sz); - } - if (bpafd != -1) - { - fprintf(stderr, "CFbAccel: BPAMEMIO_FREEMEM\n"); - ioctl(bpafd, BPAMEMIO_FREEMEM); - close(bpafd); - } -#endif -#ifdef USE_NEVIS_GXA - if (gxa_base != MAP_FAILED) - munmap((void *)gxa_base, 0x40000); - if (devmem_fd != -1) - close(devmem_fd); -#endif -#if ! HAVE_GENERIC_HARDWARE - if (fb->lfb) - munmap(fb->lfb, fb->available); - if (fb->fd > -1) - close(fb->fd); -#endif -} - -void CFbAccel::update() -{ -#ifndef HAVE_SPARK_HARDWARE - int needmem = fb->stride * fb->yRes * 2; - if (fb->available >= needmem) - { - backbuffer = fb->lfb + fb->stride / sizeof(fb_pixel_t) * fb->yRes; - return; - } - fprintf(stderr, "CFbAccel: not enough FB memory (have %d, need %d)\n", fb->available, needmem); - backbuffer = fb->lfb; /* will not work well, but avoid crashes */ -#endif -} - -void CFbAccel::setColor(fb_pixel_t col) -{ -#if HAVE_TRIPLEDRAGON - if (col == lastcol) - return; - char *c = (char *)&col; - dfbdest->SetColor(dfbdest, c[1], c[2], c[3], c[0]); - lastcol = col; -#elif defined USE_NEVIS_GXA - if (col == lastcol) - return; - _write_gxa(gxa_base, GXA_FG_COLOR_REG, (unsigned int)col); /* setup the drawing color */ - lastcol = col; -#else - (void)col; /* avoid "unused parameter" compiler warning */ -#endif -} - -void CFbAccel::paintRect(const int x, const int y, const int dx, const int dy, const fb_pixel_t col) -{ -#if HAVE_TRIPLEDRAGON - setColor(col); - dfbdest->FillRectangle(dfbdest, x, y, dx, dy); -#elif defined(USE_NEVIS_GXA) - OpenThreads::ScopedLock m_lock(mutex); - unsigned int cmd = GXA_CMD_BLT | GXA_CMD_NOT_TEXT | GXA_CMD_NOT_ALPHA | - GXA_SRC_BMP_SEL(6) | GXA_DST_BMP_SEL(2) | GXA_PARAM_COUNT(2); - - _write_gxa(gxa_base, GXA_BG_COLOR_REG, (unsigned int)col); /* setup the drawing color */ - _write_gxa(gxa_base, GXA_BMP6_TYPE_REG, (3 << 16) | (1 << 27)); /* 3 == 32bpp, 1<<27 == fill */ - _write_gxa(gxa_base, cmd, GXA_POINT(x, y)); /* destination pos */ - _write_gxa(gxa_base, cmd, GXA_POINT(dx, dy)); /* destination size */ - _write_gxa(gxa_base, GXA_BG_COLOR_REG, (unsigned int)fb->backgroundColor); - - /* the GXA seems to do asynchronous rendering, so we add a sync marker - to which the fontrenderer code can synchronize */ - add_gxa_sync_marker(); -#elif HAVE_SPARK_HARDWARE - if (dx <= 0 || dy <= 0) - return; - - // The STM blitter introduces considerable overhead probably not worth for single lines. --martii - if (dx == 1) { - waitForIdle(); - fb_pixel_t *fbs = fb->getFrameBufferPointer() + (DEFAULT_XRES * y) + x; - fb_pixel_t *fbe = fbs + DEFAULT_XRES * dy; - while (fbs < fbe) { - *fbs = col; - fbs += DEFAULT_XRES; - } - mark(x , y, x + 1, y + dy); - return; - } - if (dy == 1) { - waitForIdle(); - fb_pixel_t *fbs = fb->getFrameBufferPointer() + (DEFAULT_XRES * y) + x; - fb_pixel_t *fbe = fbs + dx; - while (fbs < fbe) - *fbs++ = col; - mark(x , y, x + dx, y + 1); - return; - } - - /* function has const parameters, so copy them here... */ - int width = dx; - int height = dy; - int xx = x; - int yy = y; - /* maybe we should just return instead of fixing this up... */ - if (x < 0) { - fprintf(stderr, "[neutrino] fb::%s: x < 0 (%d)\n", __func__, x); - width += x; - if (width <= 0) - return; - xx = 0; - } - - if (y < 0) { - fprintf(stderr, "[neutrino] fb::%s: y < 0 (%d)\n", __func__, y); - height += y; - if (height <= 0) - return; - yy = 0; - } - - int right = xx + width; - int bottom = yy + height; - - if (right > (int)fb->xRes) { - if (xx >= (int)fb->xRes) { - fprintf(stderr, "[neutrino] fb::%s: x >= xRes (%d > %d)\n", __func__, xx, fb->xRes); - return; - } - fprintf(stderr, "[neutrino] fb::%s: x+w > xRes! (%d+%d > %d)\n", __func__, xx, width, fb->xRes); - right = fb->xRes; - } - if (bottom > (int)fb->yRes) { - if (yy >= (int)fb->yRes) { - fprintf(stderr, "[neutrino] fb::%s: y >= yRes (%d > %d)\n", __func__, yy, fb->yRes); - return; - } - fprintf(stderr, "[neutrino] fb::%s: y+h > yRes! (%d+%d > %d)\n", __func__, yy, height, fb->yRes); - bottom = fb->yRes; - } - - STMFBIO_BLT_DATA bltData; - memset(&bltData, 0, sizeof(STMFBIO_BLT_DATA)); - - bltData.operation = BLT_OP_FILL; - bltData.dstOffset = lbb_off; - bltData.dstPitch = fb->stride; - - bltData.dst_left = xx; - bltData.dst_top = yy; - bltData.dst_right = right; - bltData.dst_bottom = bottom; - - bltData.dstFormat = SURF_ARGB8888; - bltData.srcFormat = SURF_ARGB8888; - bltData.dstMemBase = STMFBGP_FRAMEBUFFER; - bltData.srcMemBase = STMFBGP_FRAMEBUFFER; - bltData.colour = col; - - mark(xx, yy, bltData.dst_right, bltData.dst_bottom); - OpenThreads::ScopedLock m_lock(mutex); - if (ioctl(fb->fd, STMFBIO_BLT, &bltData ) < 0) - fprintf(stderr, "blitRect FBIO_BLIT: %m x:%d y:%d w:%d h:%d s:%d\n", xx,yy,width,height,fb->stride); -#else - int line = 0; - int swidth = fb->stride / sizeof(fb_pixel_t); - fb_pixel_t *fbp = fb->getFrameBufferPointer() + (swidth * y); - int pos; - while (line < dy) - { - for (pos = x; pos < x + dx; pos++) - *(fbp + pos) = col; - fbp += swidth; - line++; - } -#endif - blit(); -} - -void CFbAccel::paintPixel(const int x, const int y, const fb_pixel_t col) -{ -#if HAVE_TRIPLEDRAGON - setColor(col); - dfbdest->DrawLine(dfbdest, x, y, x, y); -#elif defined (USE_NEVIS_GXA) - paintLine(x, y, x + 1, y, col); -#else - fb_pixel_t *pos = fb->getFrameBufferPointer(); - pos += (fb->stride / sizeof(fb_pixel_t)) * y; - pos += x; - *pos = col; -#endif -} - -void CFbAccel::paintLine(int xa, int ya, int xb, int yb, const fb_pixel_t col) -{ -#if HAVE_TRIPLEDRAGON - setColor(col); - dfbdest->DrawLine(dfbdest, xa, ya, xb, yb); -#elif defined(USE_NEVIS_GXA) - OpenThreads::ScopedLock m_lock(mutex); - /* draw a single vertical line from point xa/ya to xb/yb */ - unsigned int cmd = GXA_CMD_NOT_TEXT | GXA_SRC_BMP_SEL(2) | GXA_DST_BMP_SEL(2) | GXA_PARAM_COUNT(2) | GXA_CMD_NOT_ALPHA; - - setColor(col); - _write_gxa(gxa_base, GXA_LINE_CONTROL_REG, 0x00000404); /* X is major axis, skip last pixel */ - _write_gxa(gxa_base, cmd, GXA_POINT(xb, yb)); /* end point */ - _write_gxa(gxa_base, cmd, GXA_POINT(xa, ya)); /* start point */ -#else - int dx = abs (xa - xb); - int dy = abs (ya - yb); - if (dy == 0) /* horizontal line */ - { - /* paintRect actually is 1 pixel short to the right, - * but that's bug-compatibility with the GXA code */ - paintRect(xa, ya, xb - xa, 1, col); - return; - } - if (dx == 0) /* vertical line */ - { - paintRect(xa, ya, 1, yb - ya, col); - return; - } - int x; - int y; - int End; - int step; - - if (dx > dy) - { - int p = 2 * dy - dx; - int twoDy = 2 * dy; - int twoDyDx = 2 * (dy-dx); - - if (xa > xb) - { - x = xb; - y = yb; - End = xa; - step = ya < yb ? -1 : 1; - } - else - { - x = xa; - y = ya; - End = xb; - step = yb < ya ? -1 : 1; - } - - paintPixel(x, y, col); - - while (x < End) - { - x++; - if (p < 0) - p += twoDy; - else - { - y += step; - p += twoDyDx; - } - paintPixel(x, y, col); - } - } - else - { - int p = 2 * dx - dy; - int twoDx = 2 * dx; - int twoDxDy = 2 * (dx-dy); - - if (ya > yb) - { - x = xb; - y = yb; - End = ya; - step = xa < xb ? -1 : 1; - } - else - { - x = xa; - y = ya; - End = yb; - step = xb < xa ? -1 : 1; - } - - paintPixel(x, y, col); - - while (y < End) - { - y++; - if (p < 0) - p += twoDx; - else - { - x += step; - p += twoDxDy; - } - paintPixel(x, y, col); - } - } - mark(xa, ya, xb, yb); - blit(); -#endif -} - -#if !HAVE_TRIPLEDRAGON -void CFbAccel::blit2FB(void *fbbuff, uint32_t width, uint32_t height, uint32_t xoff, uint32_t yoff, uint32_t xp, uint32_t yp, bool transp) -{ -#if !HAVE_SPARK_HARDWARE - int xc, yc; - xc = (width > fb->xRes) ? fb->xRes : width; - yc = (height > fb->yRes) ? fb->yRes : height; -#endif -#ifdef USE_NEVIS_GXA - (void)transp; - u32 cmd; - void *uKva; - - uKva = cs_phys_addr(fbbuff); - //printf("CFbAccel::blit2FB: data %x Kva %x\n", (int) fbbuff, (int) uKva); - - if (uKva != NULL) { - OpenThreads::ScopedLock m_lock(mutex); - cmd = GXA_CMD_BLT | GXA_CMD_NOT_TEXT | GXA_SRC_BMP_SEL(1) | GXA_DST_BMP_SEL(2) | GXA_PARAM_COUNT(3); - - _write_gxa(gxa_base, GXA_BMP1_TYPE_REG, (3 << 16) | width); - _write_gxa(gxa_base, GXA_BMP1_ADDR_REG, (unsigned int)uKva); - - _write_gxa(gxa_base, cmd, GXA_POINT(xoff, yoff)); /* destination pos */ - _write_gxa(gxa_base, cmd, GXA_POINT(xc, yc)); /* source width, FIXME real or adjusted xc, yc ? */ - _write_gxa(gxa_base, cmd, GXA_POINT(xp, yp)); /* source pos */ - - return; - } -#elif HAVE_SPARK_HARDWARE - int x, y, dw, dh; - x = xoff; - y = yoff; - dw = width - xp; - dh = height - yp; - - size_t mem_sz = width * height * sizeof(fb_pixel_t); - unsigned long ulFlags = 0; - if (!transp) /* transp == false (default): use transparency from source alphachannel */ - ulFlags = BLT_OP_FLAGS_BLEND_SRC_ALPHA|BLT_OP_FLAGS_BLEND_DST_MEMORY; // we need alpha blending - - STMFBIO_BLT_EXTERN_DATA blt_data; - memset(&blt_data, 0, sizeof(STMFBIO_BLT_EXTERN_DATA)); - blt_data.operation = BLT_OP_COPY; - blt_data.ulFlags = ulFlags; - blt_data.srcOffset = 0; - blt_data.srcPitch = width * 4; - blt_data.dstOffset = lbb_off; - blt_data.dstPitch = fb->stride; - blt_data.src_left = xp; - blt_data.src_top = yp; - blt_data.src_right = width; - blt_data.src_bottom = height; - blt_data.dst_left = x; - blt_data.dst_top = y; - blt_data.dst_right = x + dw; - blt_data.dst_bottom = y + dh; - blt_data.srcFormat = SURF_ARGB8888; - blt_data.dstFormat = SURF_ARGB8888; - blt_data.srcMemBase = (char *)backbuffer; - blt_data.dstMemBase = (char *)fb->lfb; - blt_data.srcMemSize = mem_sz; - blt_data.dstMemSize = fb->stride * fb->yRes + lbb_off; - - mark(x, y, blt_data.dst_right, blt_data.dst_bottom); - OpenThreads::ScopedLock m_lock(mutex); - ioctl(fb->fd, STMFBIO_SYNC_BLITTER); - if (fbbuff != backbuffer) - memmove(backbuffer, fbbuff, mem_sz); - // icons are so small that they will still be in cache - msync(backbuffer, backbuf_sz, MS_SYNC); - - if (ioctl(fb->fd, STMFBIO_BLT_EXTERN, &blt_data) < 0) - perror("CFbAccel blit2FB STMFBIO_BLT_EXTERN"); - return; -#else - fb_pixel_t *data = (fb_pixel_t *) fbbuff; - - uint8_t *d = (uint8_t *)lbb + xoff * sizeof(fb_pixel_t) + fb->stride * yoff; - fb_pixel_t * d2; - - for (int count = 0; count < yc; count++ ) { - fb_pixel_t *pixpos = &data[(count + yp) * width]; - d2 = (fb_pixel_t *) d; - for (int count2 = 0; count2 < xc; count2++ ) { - fb_pixel_t pix = *(pixpos + xp); - if (transp || (pix & 0xff000000) == 0xff000000) - *d2 = pix; - else { - uint8_t *in = (uint8_t *)(pixpos + xp); - uint8_t *out = (uint8_t *)d2; - int a = in[3]; /* TODO: big/little endian */ - *out = (*out + ((*in - *out) * a) / 256); - in++; out++; - *out = (*out + ((*in - *out) * a) / 256); - in++; out++; - *out = (*out + ((*in - *out) * a) / 256); - } - d2++; - pixpos++; - } - d += fb->stride; - } - blit(); -#if 0 - for(int i = 0; i < yc; i++){ - memmove(clfb + (i + yoff)*stride + xoff*4, ip + (i + yp)*width + xp, xc*4); - } -#endif -#endif -} -#else -void CFbAccel::blit2FB(void *fbbuff, uint32_t width, uint32_t height, uint32_t xoff, uint32_t yoff, uint32_t xp, uint32_t yp, bool transp) -{ - DFBRectangle src; - DFBResult err; - IDirectFBSurface *surf; - DFBSurfaceDescription dsc; - - src.x = xp; - src.y = yp; - src.w = width - xp; - src.h = height - yp; - - dsc.flags = (DFBSurfaceDescriptionFlags)(DSDESC_CAPS | DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PREALLOCATED); - dsc.caps = DSCAPS_NONE; - dsc.width = width; - dsc.height = height; - dsc.preallocated[0].data = fbbuff; - dsc.preallocated[0].pitch = width * sizeof(fb_pixel_t); - err = dfb->CreateSurface(dfb, &dsc, &surf); - /* TODO: maybe we should not die if this fails? */ - if (err != DFB_OK) { - fprintf(stderr, "CFbAccel::blit2FB: "); - DirectFBErrorFatal("dfb->CreateSurface(dfb, &dsc, &surf)", err); - } - - if (transp) - { - surf->SetSrcColorKey(surf, 0, 0, 0); - dfbdest->SetBlittingFlags(dfbdest, DSBLIT_SRC_COLORKEY); - } - else - dfbdest->SetBlittingFlags(dfbdest, DSBLIT_BLEND_ALPHACHANNEL); - - dfbdest->Blit(dfbdest, surf, &src, xoff, yoff); - surf->Release(surf); - return; -} -#endif - -#ifdef USE_NEVIS_GXA -void CFbAccel::setupGXA() -{ - // We (re)store the GXA regs here in case DFB override them and was not - // able to restore them. - _write_gxa(gxa_base, GXA_BMP2_TYPE_REG, (3 << 16) | (unsigned int)fb->screeninfo.xres); - _write_gxa(gxa_base, GXA_BMP2_ADDR_REG, (unsigned int) fb->fix.smem_start); - _write_gxa(gxa_base, GXA_BLEND_CFG_REG, 0x00089064); - // TODO check mono-flip, bit 8 - _write_gxa(gxa_base, GXA_CFG_REG, 0x100 | (1 << 12) | (1 << 29)); - _write_gxa(gxa_base, GXA_CFG2_REG, 0x1FF); - _write_gxa(gxa_base, GXA_BG_COLOR_REG, (unsigned int)fb->backgroundColor); - add_gxa_sync_marker(); -} -#endif - -#define BLIT_INTERVAL_MIN 40 -#define BLIT_INTERVAL_MAX 250 -void CFbAccel::run() -{ - printf("CFbAccel::run start\n"); - time_t last_blit = 0; - blit_pending = false; - blit_thread = true; - blit_mutex.lock(); - set_threadname("fb::autoblit"); - while (blit_thread) { - blit_cond.wait(&blit_mutex, blit_pending ? BLIT_INTERVAL_MIN : BLIT_INTERVAL_MAX); - time_t now = time_monotonic_ms(); - if (now - last_blit < BLIT_INTERVAL_MIN) - { - blit_pending = true; - //printf("CFbAccel::run: skipped, time %ld\n", now - last_blit); - } - else - { - blit_pending = false; - blit_mutex.unlock(); - _blit(); - blit_mutex.lock(); - last_blit = now; - } - } - blit_mutex.unlock(); - printf("CFbAccel::run end\n"); -} - -void CFbAccel::blit() -{ - //printf("CFbAccel::blit\n"); - blit_mutex.lock(); - blit_cond.signal(); - blit_mutex.unlock(); -} - -#if HAVE_SPARK_HARDWARE -void CFbAccel::_blit() -{ -#if 0 - static time_t last = 0; - time_t now = time_monotonic_ms(); - printf("%s %ld\n", __func__, now - last); - last = now; -#endif - OpenThreads::ScopedLock m_lock(mutex); -#ifdef PARTIAL_BLIT - if (to_blit.xs == INT_MAX) - return; - - int srcXa = to_blit.xs; - int srcYa = to_blit.ys; - int srcXb = to_blit.xe; - int srcYb = to_blit.ye; -#else - const int srcXa = 0; - const int srcYa = 0; - int srcXb = fb->xRes; - int srcYb = fb->yRes; -#endif - STMFBIO_BLT_DATA bltData; - memset(&bltData, 0, sizeof(STMFBIO_BLT_DATA)); - - bltData.operation = BLT_OP_COPY; - //bltData.ulFlags = BLT_OP_FLAGS_BLEND_SRC_ALPHA | BLT_OP_FLAGS_BLEND_DST_MEMORY; // we need alpha blending - // src - bltData.srcOffset = lbb_off; - bltData.srcPitch = fb->stride; - - bltData.src_left = srcXa; - bltData.src_top = srcYa; - bltData.src_right = srcXb; - bltData.src_bottom = srcYb; - - bltData.srcFormat = SURF_BGRA8888; - bltData.srcMemBase = STMFBGP_FRAMEBUFFER; - - /* calculate dst/blit factor */ - fb_var_screeninfo s; - if (ioctl(fb->fd, FBIOGET_VSCREENINFO, &s) == -1) - perror("CFbAccel "); - -#ifdef PARTIAL_BLIT - if (s.xres != last_xres) /* fb resolution has changed -> clear artifacts */ - { - last_xres = s.xres; - bltData.src_left = 0; - bltData.src_top = 0; - bltData.src_right = fb->xRes; - bltData.src_bottom = fb->yRes; - } - - double xFactor = (double)s.xres/(double)fb->xRes; - double yFactor = (double)s.yres/(double)fb->yRes; - - int desXa = xFactor * bltData.src_left; - int desYa = yFactor * bltData.src_top; - int desXb = xFactor * bltData.src_right; - int desYb = yFactor * bltData.src_bottom; -#else - const int desXa = 0; - const int desYa = 0; - int desXb = s.xres; - int desYb = s.yres; -#endif - - /* dst */ - bltData.dstOffset = 0; - bltData.dstPitch = s.xres * 4; - - bltData.dst_left = desXa; - bltData.dst_top = desYa; - bltData.dst_right = desXb; - bltData.dst_bottom = desYb; - - bltData.dstFormat = SURF_BGRA8888; - bltData.dstMemBase = STMFBGP_FRAMEBUFFER; - - //printf("CFbAccel::blit: sx:%d sy:%d sxe:%d sye: %d dx:%d dy:%d dxe:%d dye:%d\n", srcXa, srcYa, srcXb, srcYb, desXa, desYa, desXb, desYb); - if ((bltData.dst_right > s.xres) || (bltData.dst_bottom > s.yres)) - printf("CFbAccel::blit: values out of range desXb:%d desYb:%d\n", - bltData.dst_right, bltData.dst_bottom); - - if(ioctl(fb->fd, STMFBIO_SYNC_BLITTER) < 0) - perror("CFbAccel::blit ioctl STMFBIO_SYNC_BLITTER 1"); - msync(lbb, fb->xRes * 4 * fb->yRes, MS_SYNC); - if (ioctl(fb->fd, STMFBIO_BLT, &bltData ) < 0) - perror("STMFBIO_BLT"); - if(ioctl(fb->fd, STMFBIO_SYNC_BLITTER) < 0) - perror("CFbAccel::blit ioctl STMFBIO_SYNC_BLITTER 2"); - -#ifdef PARTIAL_BLIT - to_blit.xs = to_blit.ys = INT_MAX; - to_blit.xe = to_blit.ye = 0; -#endif -} - -#elif HAVE_AZBOX_HARDWARE - -#ifndef FBIO_WAITFORVSYNC -#define FBIO_WAITFORVSYNC _IOW('F', 0x20, __u32) -#endif -#ifndef FBIO_BLIT -#define FBIO_BLIT 0x22 -#define FBIO_SET_MANUAL_BLIT _IOW('F', 0x21, __u8) -#endif -static bool autoblit = getenv("AZBOX_KERNEL_BLIT") ? true : false; -void CFbAccel::_blit() -{ - if (autoblit) - return; - // blit - if (ioctl(fb->fd, FBIO_BLIT) < 0) - perror("CFbAccel FBIO_BLIT"); -#if 0 - // sync bliter - int c = 0; - if( ioctl(fd, FBIO_WAITFORVSYNC, &c) < 0 ) - perror("FBIO_WAITFORVSYNC"); -#endif -} - -#else -/* not azbox and not spark -> no blit() needed */ -void CFbAccel::_blit() -{ -#if HAVE_GENERIC_HARDWARE - if (glfb) - glfb->blit(); -#endif -} -#endif - -/* not really used yet */ -#ifdef PARTIAL_BLIT -void CFbAccel::mark(int xs, int ys, int xe, int ye) -{ - OpenThreads::ScopedLock m_lock(mutex); - if (xs < to_blit.xs) - to_blit.xs = xs; - if (ys < to_blit.ys) - to_blit.ys = ys; - if (xe > to_blit.xe) { - if (xe >= (int)fb->xRes) - to_blit.xe = fb->xRes - 1; - else - to_blit.xe = xe; - } - if (ye > to_blit.ye) { - if (ye >= (int)fb->xRes) - to_blit.ye = fb->yRes - 1; - else - to_blit.ye = ye; - } -#if 0 - /* debug code that kills neutrino right away if the blit area is invalid - * only enable this for creating a coredumo for debugging */ - fb_var_screeninfo s; - if (ioctl(fb->fd, FBIOGET_VSCREENINFO, &s) == -1) - perror("CFbAccel "); - if ((xe > s.xres) || (ye > s.yres)) { - fprintf(stderr, "CFbAccel::mark: values out of range xe:%d ye:%d\n", xe, ye); - int *kill = NULL; - *kill = 1; /* oh my */ - } -#endif -} -#else -void CFbAccel::mark(int, int, int, int) -{ -} -#endif - -bool CFbAccel::init(void) -{ - fb_pixel_t *lfb; - fb->lfb = NULL; - fb->fd = -1; -#if HAVE_GENERIC_HARDWARE - 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(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 /* ! GENERIC_HARDWARE */ - - memset(lfb, 0, fb->available); - fb->lfb = lfb; - return true; -} - -/* wrong name... */ -int CFbAccel::setMode(void) -{ - int fd = fb->fd; - t_fb_var_screeninfo *si = &fb->screeninfo; -#if HAVE_AZBOX_HARDWARE - // set auto blit if AZBOX_KERNEL_BLIT environment variable is set - unsigned char tmp = getenv("AZBOX_KERNEL_BLIT") ? 0 : 1; - if (ioctl(fd, FBIO_SET_MANUAL_BLIT, &tmp) < 0) - perror("FBIO_SET_MANUAL_BLIT"); - - const unsigned int nxRes = DEFAULT_XRES; - const unsigned int nyRes = DEFAULT_YRES; - const unsigned int nbpp = DEFAULT_BPP; - si->xres_virtual = si->xres = nxRes; - si->yres_virtual = (si->yres = nyRes) * 2; - si->height = 0; - si->width = 0; - si->xoffset = si->yoffset = 0; - si->bits_per_pixel = nbpp; - - si->transp.offset = 24; - si->transp.length = 8; - si->red.offset = 16; - si->red.length = 8; - si->green.offset = 8; - si->green.length = 8; - si->blue.offset = 0; - si->blue.length = 8; - - if (ioctl(fd, FBIOPUT_VSCREENINFO, si) < 0) { - // try single buffering - si->yres_virtual = si->yres = nyRes; - if (ioctl(fd, FBIOPUT_VSCREENINFO, si) < 0) - perror("FBIOPUT_VSCREENINFO"); - printf("FB: double buffering not available.\n"); - } - else - printf("FB: double buffering available!\n"); - - ioctl(fd, FBIOGET_VSCREENINFO, si); - - if (si->xres != nxRes || si->yres != nyRes || si->bits_per_pixel != nbpp) - { - printf("SetMode failed: wanted: %dx%dx%d, got %dx%dx%d\n", - nxRes, nyRes, nbpp, - si->xres, si->yres, si->bits_per_pixel); - } -#endif -#if HAVE_SPARK_HARDWARE - /* it's all fake... :-) */ - si->xres = si->xres_virtual = DEFAULT_XRES; - si->yres = si->yres_virtual = DEFAULT_YRES; - si->bits_per_pixel = DEFAULT_BPP; - fb->stride = si->xres * si->bits_per_pixel / 8; -#else -#if ! HAVE_GENERIC_HARDWARE - fb_fix_screeninfo _fix; - - if (ioctl(fd, FBIOGET_FSCREENINFO, &_fix) < 0) { - perror("FBIOGET_FSCREENINFO"); - return -1; - } - fb->stride = _fix.line_length; -#endif -#endif -#if HAVE_COOL_HARDWARE - if (ioctl(fd, FBIOBLANK, FB_BLANK_UNBLANK) < 0) - printf("screen unblanking failed\n"); -#endif - /* avoid compiler warnings on various platforms */ - (void) fd; - (void) si; - return 0; -} diff --git a/src/driver/fbaccel.h b/src/driver/fbaccel.h deleted file mode 100644 index 965df48c9..000000000 --- a/src/driver/fbaccel.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - Copyright (C) 2007-2013 Stefan Seyfried - - License: GPL - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - - private functions for the fbaccel class (only used in CFrameBuffer) -*/ - - -#ifndef __fbaccel__ -#define __fbaccel__ -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#if HAVE_SPARK_HARDWARE -#define PARTIAL_BLIT 1 -#endif - -class CFrameBuffer; -class CFbAccel - : public OpenThreads::Thread -{ - private: - CFrameBuffer *fb; - fb_pixel_t lastcol; - OpenThreads::Mutex mutex; -#ifdef USE_NEVIS_GXA - int devmem_fd; /* to access the GXA register we use /dev/mem */ - unsigned int smem_start; /* as aquired from the fbdev, the framebuffers physical start address */ - volatile uint8_t *gxa_base; /* base address for the GXA's register access */ - void add_gxa_sync_marker(void); -#endif /* USE_NEVIS_GXA */ - void setColor(fb_pixel_t col); - void run(void); - void blit(void); - void _blit(void); - bool blit_thread; - bool blit_pending; - OpenThreads::Condition blit_cond; - OpenThreads::Mutex blit_mutex; -#ifdef PARTIAL_BLIT - OpenThreads::Mutex to_blit_mutex; - struct { - int xs; - int ys; - int xe; - int ye; - } to_blit; - uint32_t last_xres; -#endif - public: - fb_pixel_t *backbuffer; - fb_pixel_t *lbb; - CFbAccel(CFrameBuffer *fb); - ~CFbAccel(); - bool init(void); - int setMode(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); - void blit2FB(void *fbbuff, uint32_t width, uint32_t height, uint32_t xoff, uint32_t yoff, uint32_t xp, uint32_t yp, bool transp); - void waitForIdle(void); - void mark(int x, int y, int dx, int dy); - void update(); -#ifdef USE_NEVIS_GXA - void setupGXA(void); -#endif -}; - -#endif diff --git a/src/driver/framebuffer.cpp b/src/driver/framebuffer.cpp deleted file mode 100644 index eafe6d325..000000000 --- a/src/driver/framebuffer.cpp +++ /dev/null @@ -1,2200 +0,0 @@ -/* - Neutrino-GUI - DBoxII-Project - - Copyright (C) 2001 Steffen Hehn 'McClean' - 2003 thegoodguy - - mute icon handling from tuxbox project - Copyright (C) 2009 Stefan Seyfried - mute icon & info clock handling - Copyright (C) 2013 M. Liebmann (micha-bbg) - - License: GPL - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This program 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 - General Public License for more details. - - You should have received a copy of the GNU General Public - License along with this program; if not, write to the - Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef HAVE_COOL_HARDWARE -#include -#endif - -extern cVideo * videoDecoder; - -extern CPictureViewer * g_PicViewer; -#define ICON_CACHE_SIZE 1024*1024*2 // 2mb - -#define BACKGROUNDIMAGEWIDTH 720 - -#ifdef BOXMODEL_CS_HD2 -#ifndef FB_HW_ACCELERATION -#define FB_HW_ACCELERATION -#endif -#endif -#if defined(FB_HW_ACCELERATION) && defined(USE_NEVIS_GXA) -#error -#endif -//#undef USE_NEVIS_GXA //FIXME -/*******************************************************************************/ -#ifdef USE_NEVIS_GXA - -#ifdef GXA_FG_COLOR_REG -#undef GXA_FG_COLOR_REG -#endif -#ifdef GXA_BG_COLOR_REG -#undef GXA_BG_COLOR_REG -#endif -#ifdef GXA_LINE_CONTROL_REG -#undef GXA_LINE_CONTROL_REG -#endif -#ifdef GXA_DEPTH_REG -#undef GXA_DEPTH_REG -#endif -#ifdef GXA_CONTENT_ID_REG -#undef GXA_CONTENT_ID_REG -#endif - -#define GXA_POINT(x, y) (((y) & 0x0FFF) << 16) | ((x) & 0x0FFF) -#define GXA_SRC_BMP_SEL(x) (x << 8) -#define GXA_DST_BMP_SEL(x) (x << 5) -#define GXA_PARAM_COUNT(x) (x << 2) - -#define GXA_CMD_REG 0x001C -#define GXA_FG_COLOR_REG 0x0020 -#define GXA_BG_COLOR_REG 0x0024 -#define GXA_LINE_CONTROL_REG 0x0038 -#define GXA_BMP2_TYPE_REG 0x0050 -#define GXA_BMP2_ADDR_REG 0x0054 -#define GXA_DEPTH_REG 0x00F4 -#define GXA_CONTENT_ID_REG 0x0144 -#define GXA_BLT_CONTROL_REG 0x0034 - -#define GXA_CMD_BLT 0x00010800 -#define GXA_CMD_NOT_ALPHA 0x00011000 -#define GXA_CMD_NOT_TEXT 0x00018000 -#define GXA_CMD_QMARK 0x00001000 - -#define GXA_BMP1_TYPE_REG 0x0048 -#define GXA_BMP1_ADDR_REG 0x004C -#define GXA_BMP7_TYPE_REG 0x0078 - -#define GXA_BLEND_CFG_REG 0x003C -#define GXA_CFG_REG 0x0030 -#define GXA_CFG2_REG 0x00FC -/* -static unsigned int _read_gxa(volatile unsigned char *base_addr, unsigned int offset) -{ - return *(volatile unsigned int *)(base_addr + offset); -} -*/ - -static unsigned int _mark = 0; - -static void _write_gxa(volatile unsigned char *base_addr, unsigned int offset, unsigned int value) -{ - while( (*(volatile unsigned int *)(base_addr + GXA_DEPTH_REG)) & 0x40000000) - {}; - *(volatile unsigned int *)(base_addr + offset) = value; -} - -/* this adds a tagged marker into the GXA queue. Once this comes out - of the other end of the queue, all commands before it are finished */ -void CFrameBuffer::add_gxa_sync_marker(void) -{ - unsigned int cmd = GXA_CMD_QMARK | GXA_PARAM_COUNT(1); - // TODO: locking? - _mark++; - _mark &= 0x0000001F; /* bit 0x20 crashes the kernel, if set */ - _write_gxa(gxa_base, cmd, _mark); - //fprintf(stderr, "%s: wrote %02x\n", __FUNCTION__, _mark); -} - -/* wait until the current marker comes out of the GXA command queue */ -void CFrameBuffer::waitForIdle(const char* func) -{ - unsigned int cfg, count = 0; - do { - cfg = *(volatile unsigned int *)(gxa_base + GXA_CMD_REG); - cfg >>= 24; /* the token is stored in bits 31...24 */ - if (cfg == _mark) - break; - /* usleep is too coarse, because of CONFIG_HZ=100 in kernel - so use sched_yield to at least give other threads a chance to run */ - sched_yield(); - //fprintf(stderr, "%s: read %02x, expected %02x\n", __FUNCTION__, cfg, _mark); - } while(++count < 2048); /* don't deadlock here if there is an error */ - - if (count > 512) /* more than 100 are unlikely, */{ - if (func != NULL) - fprintf(stderr, "CFrameBuffer::waitForIdle: count is big (%04u) [%s]!\n", count, func); - else - fprintf(stderr, "CFrameBuffer::waitForIdle: count is big (%u)!\n", count); - } -} -#endif /* USE_NEVIS_GXA */ - -/*******************************************************************************/ - -static uint8_t * virtual_fb = NULL; -inline unsigned int make16color(uint16_t r, uint16_t g, uint16_t b, uint16_t t, - uint32_t /*rl*/ = 0, uint32_t /*ro*/ = 0, - uint32_t /*gl*/ = 0, uint32_t /*go*/ = 0, - uint32_t /*bl*/ = 0, uint32_t /*bo*/ = 0, - uint32_t /*tl*/ = 0, uint32_t /*to*/ = 0) -{ - return ((t << 24) & 0xFF000000) | ((r << 8) & 0xFF0000) | ((g << 0) & 0xFF00) | (b >> 8 & 0xFF); -} - -CFrameBuffer::CFrameBuffer() -: active ( true ) -{ - iconBasePath = ""; - available = 0; - cmap.start = 0; - cmap.len = 256; - cmap.red = red; - cmap.green = green; - cmap.blue = blue; - cmap.transp = trans; - backgroundColor = 0; - useBackgroundPaint = false; - background = NULL; - backupBackground = NULL; - backgroundFilename = ""; - fd = 0; - tty = 0; - m_transparent_default = CFrameBuffer::TM_BLACK; // TM_BLACK: Transparency when black content ('pseudo' transparency) - // TM_NONE: No 'pseudo' transparency - // TM_INI: Transparency depends on g_settings.infobar_alpha ??? - m_transparent = m_transparent_default; - q_circle = NULL; - initQCircle(); - corner_tl = false; - corner_tr = false; - corner_bl = false; - corner_br = false; -//FIXME: test - memset(red, 0, 256*sizeof(__u16)); - memset(green, 0, 256*sizeof(__u16)); - memset(blue, 0, 256*sizeof(__u16)); - memset(trans, 0, 256*sizeof(__u16)); - fbAreaActiv = false; - fb_no_check = false; - do_paint_mute_icon = true; -} - -CFrameBuffer* CFrameBuffer::getInstance() -{ - static CFrameBuffer* frameBuffer = NULL; - - if(!frameBuffer) { - frameBuffer = new CFrameBuffer(); - printf("[neutrino] frameBuffer Instance created\n"); - } else { - //printf("[neutrino] frameBuffer Instace requested\n"); - } - return frameBuffer; -} - -#ifdef USE_NEVIS_GXA -void CFrameBuffer::setupGXA(void) -{ - // We (re)store the GXA regs here in case DFB override them and was not - // able to restore them. - _write_gxa(gxa_base, GXA_BMP2_TYPE_REG, (3 << 16) | screeninfo.xres); - _write_gxa(gxa_base, GXA_BMP2_ADDR_REG, (unsigned int) fix.smem_start); - _write_gxa(gxa_base, GXA_BLEND_CFG_REG, 0x00089064); - // TODO check mono-flip, bit 8 - _write_gxa(gxa_base, GXA_CFG_REG, 0x100 | (1 << 12) | (1 << 29)); - _write_gxa(gxa_base, GXA_CFG2_REG, 0x1FF); - _write_gxa(gxa_base, GXA_BG_COLOR_REG, (unsigned int) backgroundColor); - _write_gxa(gxa_base, GXA_BMP7_TYPE_REG, (3 << 16) | screeninfo.xres | (1 << 27)); -} -#endif -void CFrameBuffer::init(const char * const fbDevice) -{ - int tr = 0xFF; - - 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) { - perror("mmap"); - goto nolfb; - } - -#ifdef USE_NEVIS_GXA - /* Open /dev/mem for HW-register access */ - devmem_fd = open("/dev/mem", O_RDWR | O_SYNC); - if (devmem_fd < 0) { - perror("Unable to open /dev/mem"); - goto nolfb; - } - - /* mmap the GXA's base address */ - gxa_base = (volatile unsigned char*) mmap(0, 0x00040000, PROT_READ | PROT_WRITE, MAP_SHARED, devmem_fd, 0xE0600000); - if (gxa_base == (void*) -1){ - perror("Unable to mmap /dev/mem"); - goto nolfb; - } - - /* tell the GXA where the framebuffer to draw on starts */ - smem_start = (unsigned int) fix.smem_start; - printf("smem_start %x\n", smem_start); - - setupGXA(); -#endif - cache_size = 0; - - /* Windows Colors */ - paletteSetColor(0x1, 0x010101, tr); - paletteSetColor(0x2, 0x800000, tr); - paletteSetColor(0x3, 0x008000, tr); - paletteSetColor(0x4, 0x808000, tr); - paletteSetColor(0x5, 0x000080, tr); - paletteSetColor(0x6, 0x800080, tr); - paletteSetColor(0x7, 0x008080, tr); - paletteSetColor(0x8, 0xA0A0A0, tr); - paletteSetColor(0x9, 0x505050, tr); - paletteSetColor(0xA, 0xFF0000, tr); - paletteSetColor(0xB, 0x00FF00, tr); - paletteSetColor(0xC, 0xFFFF00, tr); - paletteSetColor(0xD, 0x0000FF, tr); - paletteSetColor(0xE, 0xFF00FF, tr); - paletteSetColor(0xF, 0x00FFFF, tr); - paletteSetColor(0x10, 0xFFFFFF, tr); - paletteSetColor(0x11, 0x000000, tr); - paletteSetColor(COL_BACKGROUND, 0x000000, 0x0); - - paletteSet(); - - useBackground(false); - m_transparent = m_transparent_default; -#if 0 - if ((tty=open("/dev/vc/0", O_RDWR))<0) { - perror("open (tty)"); - goto nolfb; - } - - struct sigaction act; - - memset(&act,0,sizeof(act)); - act.sa_handler = switch_signal; - sigemptyset(&act.sa_mask); - sigaction(SIGUSR1,&act,NULL); - sigaction(SIGUSR2,&act,NULL); - - struct vt_mode mode; - - if (-1 == ioctl(tty,KDGETMODE, &kd_mode)) { - perror("ioctl KDGETMODE"); - goto nolfb; - } - - if (-1 == ioctl(tty,VT_GETMODE, &vt_mode)) { - perror("ioctl VT_GETMODE"); - goto nolfb; - } - - if (-1 == ioctl(tty,VT_GETMODE, &mode)) { - perror("ioctl VT_GETMODE"); - goto nolfb; - } - - mode.mode = VT_PROCESS; - mode.waitv = 0; - mode.relsig = SIGUSR1; - mode.acqsig = SIGUSR2; - - if (-1 == ioctl(tty,VT_SETMODE, &mode)) { - perror("ioctl VT_SETMODE"); - goto nolfb; - } - - if (-1 == ioctl(tty,KDSETMODE, KD_GRAPHICS)) { - perror("ioctl KDSETMODE"); - goto nolfb; - } -#endif - - return; - -nolfb: - printf("framebuffer not available.\n"); - lfb=0; -} - - -CFrameBuffer::~CFrameBuffer() -{ - std::map::iterator it; - - for(it = icon_cache.begin(); it != icon_cache.end(); ++it) { - /* printf("FB: delete cached icon %s: %x\n", it->first.c_str(), (int) it->second.data); */ - cs_free_uncached(it->second.data); - } - icon_cache.clear(); - - if (background) { - delete[] background; - background = NULL; - } - - if (backupBackground) { - delete[] backupBackground; - backupBackground = NULL; - } - - if (q_circle) { - delete[] q_circle; - q_circle = NULL; - } - -#if 0 - if (-1 == ioctl(tty,VT_SETMODE, &vt_mode)) - perror("ioctl VT_SETMODE"); - - if (available) - ioctl(fd, FBIOPUT_VSCREENINFO, &oldscreen); -#endif - if (lfb) - munmap(lfb, available); - - if (virtual_fb){ - delete[] virtual_fb; - virtual_fb = NULL; - } - close(fd); - close(tty); - - v_fbarea.clear(); -} - -int CFrameBuffer::getFileHandle() const -{ - return fd; -} - -unsigned int CFrameBuffer::getStride() const -{ - return stride; -} - -unsigned int CFrameBuffer::getScreenWidth(bool real) -{ - if(real) - return xRes; - else - return g_settings.screen_EndX - g_settings.screen_StartX; -} - -unsigned int CFrameBuffer::getScreenHeight(bool real) -{ - if(real) - return yRes; - else - return g_settings.screen_EndY - g_settings.screen_StartY; -} - -unsigned int CFrameBuffer::getWindowWidth(bool force_small) -{ - int percent = force_small ? WINDOW_SIZE_SMALL : g_settings.window_width; - // always reduce a possible detailsline - return (g_settings.screen_EndX - g_settings.screen_StartX - 2*DETAILSLINE_WIDTH) * percent / 100; -} - -unsigned int CFrameBuffer::getWindowHeight(bool force_small) -{ - int percent = force_small ? WINDOW_SIZE_SMALL : g_settings.window_height; - return (g_settings.screen_EndY - g_settings.screen_StartY) * percent / 100; -} - -unsigned int CFrameBuffer::getScreenX() -{ - return g_settings.screen_StartX; -} - -unsigned int CFrameBuffer::getScreenY() -{ - return g_settings.screen_StartY; -} - -fb_pixel_t * CFrameBuffer::getFrameBufferPointer() const -{ - if (active || (virtual_fb == NULL)) - return lfb; - else - return (fb_pixel_t *) virtual_fb; -} - -bool CFrameBuffer::getActive() const -{ - return (active || (virtual_fb != NULL)); -} - -void CFrameBuffer::setActive(bool enable) -{ - active = enable; -} - -t_fb_var_screeninfo *CFrameBuffer::getScreenInfo() -{ - return &screeninfo; -} - -int CFrameBuffer::setMode(unsigned int /*nxRes*/, unsigned int /*nyRes*/, unsigned int /*nbpp*/) -{ - if (!available&&!active) - return -1; - -#if 0 - screeninfo.xres_virtual=screeninfo.xres=nxRes; - screeninfo.yres_virtual=screeninfo.yres=nyRes; - screeninfo.height=0; - screeninfo.width=0; - screeninfo.xoffset=screeninfo.yoffset=0; - screeninfo.bits_per_pixel=nbpp; - - if (ioctl(fd, FBIOPUT_VSCREENINFO, &screeninfo)<0) { - perror("FBIOPUT_VSCREENINFO"); - } - - if(1) { - printf("SetMode: %dbits, red %d:%d green %d:%d blue %d:%d transp %d:%d\n", - screeninfo.bits_per_pixel, screeninfo.red.length, screeninfo.red.offset, screeninfo.green.length, screeninfo.green.offset, screeninfo.blue.length, screeninfo.blue.offset, screeninfo.transp.length, screeninfo.transp.offset); - } - if ((screeninfo.xres!=nxRes) && (screeninfo.yres!=nyRes) && (screeninfo.bits_per_pixel!=nbpp)) - { - printf("SetMode failed: wanted: %dx%dx%d, got %dx%dx%d\n", - nxRes, nyRes, nbpp, - screeninfo.xres, screeninfo.yres, screeninfo.bits_per_pixel); - return -1; - } -#endif - - xRes = screeninfo.xres; - yRes = screeninfo.yres; - bpp = screeninfo.bits_per_pixel; - fb_fix_screeninfo _fix; - - if (ioctl(fd, FBIOGET_FSCREENINFO, &_fix)<0) { - perror("FBIOGET_FSCREENINFO"); - return -1; - } - - stride = _fix.line_length; - printf("FB: %dx%dx%d line length %d. %s accelerator.\n", xRes, yRes, bpp, stride, -#if defined(USE_NEVIS_GXA) - "Using nevis GXA" -#elif defined(FB_HW_ACCELERATION) - "Using fb hw graphics" -#else - "Not using graphics" -#endif - ); - - //memset(getFrameBufferPointer(), 0, stride * yRes); - paintBackground(); - if (ioctl(fd, FBIOBLANK, FB_BLANK_UNBLANK) < 0) { - printf("screen unblanking failed\n"); - } - return 0; -} -#if 0 -//never used -void CFrameBuffer::setTransparency( int /*tr*/ ) -{ -} -#endif -void CFrameBuffer::setBlendMode(uint8_t mode) -{ -#ifdef HAVE_COOL_HARDWARE - if (ioctl(fd, FBIO_SETBLENDMODE, mode)) - printf("FBIO_SETBLENDMODE failed.\n"); -#endif -} - -void CFrameBuffer::setBlendLevel(int level) -{ -#ifdef HAVE_COOL_HARDWARE - //printf("CFrameBuffer::setBlendLevel %d\n", level); - unsigned char value = 0xFF; - if((level >= 0) && (level <= 100)) - value = convertSetupAlpha2Alpha(level); - - if (ioctl(fd, FBIO_SETOPACITY, value)) - printf("FBIO_SETOPACITY failed.\n"); -#ifndef BOXMODEL_CS_HD2 - if(level == 100) // TODO: sucks. - usleep(20000); -#endif -#endif -} - -#if 0 -//never used -void CFrameBuffer::setAlphaFade(int in, int num, int tr) -{ - for (int i=0; i>16)*level; - *g= ((rgb2&0x00FF00)>>8 )*level; - *b= ((rgb2&0x0000FF) )*level; - *r+=((rgb1&0xFF0000)>>16)*(255-level); - *g+=((rgb1&0x00FF00)>>8 )*(255-level); - *b+=((rgb1&0x0000FF) )*(255-level); -} - -void CFrameBuffer::paletteGenFade(int in, __u32 rgb1, __u32 rgb2, int num, int tr) -{ - for (int i=0; i>8; - cmap.green[i] =(rgb&0x00FF00) ; - cmap.blue[i] =(rgb&0x0000FF)<<8; - cmap.transp[i] = tr; -} - -void CFrameBuffer::paletteSet(struct fb_cmap *map) -{ - if (!active) - return; - - if(map == NULL) - map = &cmap; - - if(bpp == 8) { - //printf("Set palette for %dbit\n", bpp); - ioctl(fd, FBIOPUTCMAP, map); - } - - uint32_t rl, ro, gl, go, bl, bo, tl, to; - - rl = screeninfo.red.length; - ro = screeninfo.red.offset; - gl = screeninfo.green.length; - go = screeninfo.green.offset; - bl = screeninfo.blue.length; - bo = screeninfo.blue.offset; - tl = screeninfo.transp.length; - to = screeninfo.transp.offset; - for (int i = 0; i < 256; i++) { - realcolor[i] = make16color(cmap.red[i], cmap.green[i], cmap.blue[i], cmap.transp[i], - rl, ro, gl, go, bl, bo, tl, to); - } - OnAfterSetPallette(); -} - -void CFrameBuffer::paintHLineRelInternal2Buf(const int& x, const int& dx, const int& y, const int& box_dx, const fb_pixel_t& col, fb_pixel_t* buf) -{ - uint8_t * pos = ((uint8_t *)buf) + x * sizeof(fb_pixel_t) + box_dx * sizeof(fb_pixel_t) * y; - fb_pixel_t * dest = (fb_pixel_t *)pos; - for (int i = 0; i < dx; i++) - *(dest++) = col; -} - -fb_pixel_t* CFrameBuffer::paintBoxRel2Buf(const int dx, const int dy, const int w_align, const int offs_align, const fb_pixel_t col, fb_pixel_t* buf/* = NULL*/, int radius/* = 0*/, int type/* = CORNER_ALL*/) -{ - if (!getActive()) - return buf; - if (dx < 1 || dy < 1) { - dprintf(DEBUG_INFO, "[CFrameBuffer] [%s - %d]: radius %d, dx %d dy %d\n", __func__, __LINE__, radius, dx, dy); - return buf; - } - - fb_pixel_t* pixBuf = buf; - if (pixBuf == NULL) { - pixBuf = (fb_pixel_t*) cs_malloc_uncached(w_align*dy*sizeof(fb_pixel_t)); - if (pixBuf == NULL) { - dprintf(DEBUG_NORMAL, "[%s #%d] Error cs_malloc_uncached\n", __func__, __LINE__); - return NULL; - } - } - memset((void*)pixBuf, '\0', w_align*dy*sizeof(fb_pixel_t)); - - if (type && radius) { - setCornerFlags(type); - radius = limitRadius(dx, dy, radius); - - int line = 0; - while (line < dy) { - int ofl, ofr; - calcCorners(NULL, &ofl, &ofr, dy, line, radius, type); - if (dx-ofr-ofl < 1) { - if (dx-ofr-ofl == 0) { - dprintf(DEBUG_INFO, "[%s - %d]: radius %d, end x %d y %d\n", __func__, __LINE__, radius, dx-ofr-ofl, line); - } - else { - dprintf(DEBUG_INFO, "[%s - %04d]: Calculated width: %d\n (radius %d, dx %d, offsetLeft %d, offsetRight %d).\n Width can not be less than 0, abort.\n", - __func__, __LINE__, dx-ofr-ofl, radius, dx, ofl, ofr); - } - line++; - continue; - } - paintHLineRelInternal2Buf(ofl+offs_align, dx-ofl-ofr, line, w_align, col, pixBuf); - line++; - } - } else { - fb_pixel_t *bp = pixBuf; - int line = 0; - while (line < dy) { - for (int pos = offs_align; pos < dx+offs_align; pos++) - *(bp + pos) = col; - bp += w_align; - line++; - } - } - return pixBuf; -} - -fb_pixel_t* CFrameBuffer::paintBoxRel(const int x, const int y, const int dx, const int dy, - const fb_pixel_t /*col*/, gradientData_t *gradientData, - int radius, int type) -{ - if (!getActive()) - return NULL; - - checkFbArea(x, y, dx, dy, true); - - fb_pixel_t MASK = 0xFFFFFFFF; - int _dx = dx; - int w_align; - int offs_align; - -#ifdef BOXMODEL_CS_HD2 - if (_dx%4 != 0) { - w_align = GetWidth4FB_HW_ACC(x, _dx, true); - if (w_align < _dx) - _dx = w_align; - offs_align = w_align - _dx; - if ((x - offs_align) < 0) - offs_align = 0; - } - else { - w_align = _dx; - offs_align = 0; - } -#else - w_align = _dx; - offs_align = 0; -#endif - - fb_pixel_t* boxBuf = paintBoxRel2Buf(_dx, dy, w_align, offs_align, MASK, NULL, radius, type); - if (boxBuf == NULL) { - checkFbArea(x, y, dx, dy, false); - return NULL; - } - fb_pixel_t *bp = boxBuf; - fb_pixel_t *gra = gradientData->gradientBuf; - gradientData->boxBuf = boxBuf; - gradientData->x = x - offs_align; - gradientData->dx = w_align; - - if (gradientData->direction == gradientVertical) { - // vertical - for (int pos = offs_align; pos < _dx+offs_align; pos++) { - for(int count = 0; count < dy; count++) { - if (*(bp + pos) == MASK) - *(bp + pos) = (fb_pixel_t)(*(gra + count)); - bp += w_align; - } - bp = boxBuf; - } - } else { - // horizontal - for (int line = 0; line < dy; line++) { - int gra_pos = 0; - for (int pos = 0; pos < w_align; pos++) { - if ((*(bp + pos) == MASK) && (pos >= offs_align) && (gra_pos < _dx)) { - *(bp + pos) = (fb_pixel_t)(*(gra + gra_pos)); - gra_pos++; - } - } - bp += w_align; - } - } - - if ((gradientData->mode & pbrg_noPaint) == pbrg_noPaint) { - checkFbArea(x, y, dx, dy, false); - return boxBuf; - } - - blitBox2FB(boxBuf, w_align, dy, x-offs_align, y); - - if ((gradientData->mode & pbrg_noFree) == pbrg_noFree) { - checkFbArea(x, y, dx, dy, false); - return boxBuf; - } - - cs_free_uncached(boxBuf); - - checkFbArea(x, y, dx, dy, false); - return NULL; -} - -void CFrameBuffer::paintBoxRel(const int x, const int y, const int dx, const int dy, const fb_pixel_t col, int radius, int type) -{ - /* draw a filled rectangle (with additional round corners) */ - - if (!getActive()) - return; - - if (dx == 0 || dy == 0) { - dprintf(DEBUG_DEBUG, "[CFrameBuffer] [%s - %d]: radius %d, start x %d y %d end x %d y %d\n", __func__, __LINE__, radius, x, y, x+dx, y+dy); - return; - } - if (radius < 0) - dprintf(DEBUG_NORMAL, "[CFrameBuffer] [%s - %d]: WARNING! radius < 0 [%d] FIXME\n", __func__, __LINE__, radius); - - checkFbArea(x, y, dx, dy, true); - -#if defined(FB_HW_ACCELERATION) - fb_fillrect fillrect; - fillrect.color = col; - fillrect.rop = ROP_COPY; -#elif defined(USE_NEVIS_GXA) - if (!fb_no_check) - OpenThreads::ScopedLock m_lock(mutex); - /* solid fill with background color */ - unsigned int cmd = GXA_CMD_BLT | GXA_CMD_NOT_TEXT | GXA_SRC_BMP_SEL(7) | GXA_DST_BMP_SEL(2) | GXA_PARAM_COUNT(2) | GXA_CMD_NOT_ALPHA; - _write_gxa(gxa_base, GXA_BG_COLOR_REG, (unsigned int) col); /* setup the drawing color */ -#endif - - if (type && radius) { - setCornerFlags(type); - radius = limitRadius(dx, dy, radius); - - int line = 0; - while (line < dy) { - int ofl, ofr; - if (calcCorners(NULL, &ofl, &ofr, dy, line, radius, type)) { - //printf("3: x %d y %d dx %d dy %d rad %d line %d\n", x, y, dx, dy, radius, line); -#if defined(FB_HW_ACCELERATION) || defined(USE_NEVIS_GXA) - int rect_height_mult = ((type & CORNER_TOP) && (type & CORNER_BOTTOM)) ? 2 : 1; -#if defined(FB_HW_ACCELERATION) - fillrect.dx = x; - fillrect.dy = y + line; - fillrect.width = dx; - fillrect.height = dy - (radius * rect_height_mult); - - ioctl(fd, FBIO_FILL_RECT, &fillrect); -#elif defined(USE_NEVIS_GXA) - _write_gxa(gxa_base, GXA_BLT_CONTROL_REG, 0); - _write_gxa(gxa_base, cmd, GXA_POINT(x, y + line)); /* destination x/y */ - _write_gxa(gxa_base, cmd, GXA_POINT(dx, dy - (radius * rect_height_mult))); /* width/height */ -#endif - line += dy - (radius * rect_height_mult); - continue; -#endif - } - - if (dx-ofr-ofl < 1) { - if (dx-ofr-ofl == 0){ - dprintf(DEBUG_INFO, "[CFrameBuffer] [%s - %d]: radius %d, start x %d y %d end x %d y %d\n", __func__, __LINE__, radius, x, y, x+dx-ofr-ofl, y+line); - }else{ - dprintf(DEBUG_INFO, "[CFrameBuffer] [%s - %04d]: Calculated width: %d\n (radius %d, dx %d, offsetLeft %d, offsetRight %d).\n Width can not be less than 0, abort.\n", - __func__, __LINE__, dx-ofr-ofl, radius, dx, ofl, ofr); - } - line++; - continue; - } -#ifdef USE_NEVIS_GXA - _write_gxa(gxa_base, GXA_BLT_CONTROL_REG, 0); - _write_gxa(gxa_base, cmd, GXA_POINT(x + ofl, y + line)); /* destination x/y */ - _write_gxa(gxa_base, cmd, GXA_POINT(dx-ofl-ofr, 1)); /* width/height */ -#else - paintHLineRelInternal(x+ofl, dx-ofl-ofr, y+line, col); -#endif - line++; - } - } else { -#if defined(FB_HW_ACCELERATION) - /* FIXME small size faster to do by software */ - if (dx > 10 || dy > 10) { - fillrect.dx = x; - fillrect.dy = y; - fillrect.width = dx; - fillrect.height = dy; - ioctl(fd, FBIO_FILL_RECT, &fillrect); - checkFbArea(x, y, dx, dy, false); - return; - } -#endif -#if defined(USE_NEVIS_GXA) - _write_gxa(gxa_base, GXA_BLT_CONTROL_REG, 0); - _write_gxa(gxa_base, cmd, GXA_POINT(x, y)); /* destination x/y */ - _write_gxa(gxa_base, cmd, GXA_POINT(dx, dy)); /* width/height */ -#else - int swidth = stride / sizeof(fb_pixel_t); - fb_pixel_t *fbp = getFrameBufferPointer() + (swidth * y); - int line = 0; - while (line < dy) { - for (int pos = x; pos < x + dx; pos++) - *(fbp + pos) = col; - - fbp += swidth; - line++; - } -#endif - } -#ifdef USE_NEVIS_GXA - _write_gxa(gxa_base, GXA_BG_COLOR_REG, (unsigned int) backgroundColor); //FIXME needed ? - /* the GXA seems to do asynchronous rendering, so we add a sync marker - * to which the fontrenderer code can synchronize - */ - add_gxa_sync_marker(); -#endif - checkFbArea(x, y, dx, dy, false); -} - -void CFrameBuffer::paintVLineRelInternal(int x, int y, int dy, const fb_pixel_t col) -{ - -#if defined(FB_HW_ACCELERATION) - fb_fillrect fillrect; - fillrect.dx = x; - fillrect.dy = y; - fillrect.width = 1; - fillrect.height = dy; - fillrect.color = col; - fillrect.rop = ROP_COPY; - ioctl(fd, FBIO_FILL_RECT, &fillrect); -#elif defined(USE_NEVIS_GXA) - /* draw a single vertical line from point x/y with hight dx */ - unsigned int cmd = GXA_CMD_NOT_TEXT | GXA_SRC_BMP_SEL(2) | GXA_DST_BMP_SEL(2) | GXA_PARAM_COUNT(2) | GXA_CMD_NOT_ALPHA; - - _write_gxa(gxa_base, GXA_FG_COLOR_REG, (unsigned int) col); /* setup the drawing color */ - _write_gxa(gxa_base, GXA_LINE_CONTROL_REG, 0x00000404); /* X is major axis, skip last pixel */ - _write_gxa(gxa_base, cmd, GXA_POINT(x, y + dy)); /* end point */ - _write_gxa(gxa_base, cmd, GXA_POINT(x, y)); /* start point */ -#else /* USE_NEVIS_GXA */ - uint8_t * pos = ((uint8_t *)getFrameBufferPointer()) + x * sizeof(fb_pixel_t) + stride * y; - - for(int count=0;count m_lock(mutex); -#endif - paintVLineRelInternal(x, y, dy, col); -} - -void CFrameBuffer::paintHLineRelInternal(int x, int dx, int y, const fb_pixel_t col) -{ -#if defined(FB_HW_ACCELERATION) - if (dx >= 10) { - fb_fillrect fillrect; - fillrect.dx = x; - fillrect.dy = y; - fillrect.width = dx; - fillrect.height = 1; - fillrect.color = col; - fillrect.rop = ROP_COPY; - ioctl(fd, FBIO_FILL_RECT, &fillrect); - return; - } -#endif -#if defined(USE_NEVIS_GXA) - /* draw a single horizontal line from point x/y with width dx */ - unsigned int cmd = GXA_CMD_NOT_TEXT | GXA_SRC_BMP_SEL(2) | GXA_DST_BMP_SEL(2) | GXA_PARAM_COUNT(2) | GXA_CMD_NOT_ALPHA; - - _write_gxa(gxa_base, GXA_FG_COLOR_REG, (unsigned int) col); /* setup the drawing color */ - _write_gxa(gxa_base, GXA_LINE_CONTROL_REG, 0x00000404); /* X is major axis, skip last pixel */ - _write_gxa(gxa_base, cmd, GXA_POINT(x + dx, y)); /* end point */ - _write_gxa(gxa_base, cmd, GXA_POINT(x, y)); /* start point */ -#else /* USE_NEVIS_GXA */ - uint8_t * pos = ((uint8_t *)getFrameBufferPointer()) + x * sizeof(fb_pixel_t) + stride * y; - - fb_pixel_t * dest = (fb_pixel_t *)pos; - for (int i = 0; i < dx; i++) - *(dest++) = col; -#endif /* USE_NEVIS_GXA */ -} - -void CFrameBuffer::paintHLineRel(int x, int dx, int y, const fb_pixel_t col) -{ - if (!getActive()) - return; - -#if defined(USE_NEVIS_GXA) - OpenThreads::ScopedLock m_lock(mutex); -#endif - paintHLineRelInternal(x, dx, y, col); -} - -void CFrameBuffer::setIconBasePath(const std::string & iconPath) -{ - iconBasePath = iconPath; -} - -std::string CFrameBuffer::getIconPath(std::string icon_name, std::string file_type) -{ - std::string path, filetype; - filetype = "." + file_type; - path = std::string(ICONSDIR_VAR) + "/" + icon_name + filetype; - if (access(path.c_str(), F_OK)) - path = iconBasePath + "/" + icon_name + filetype; - if (icon_name.find("/", 0) != std::string::npos) - path = icon_name; - return path; -} - -void CFrameBuffer::getIconSize(const char * const filename, int* width, int *height) -{ - *width = 0; - *height = 0; - - if(filename == NULL) - return; - //check for full path, icon don't have full path, or ? - if (filename[0]== '/'){ - return; - } - - std::map::iterator it; - - - /* if code ask for size, lets cache it. assume we have enough ram for cache */ - /* FIXME offset seems never used in code, always default = 1 ? */ - - it = icon_cache.find(filename); - if(it == icon_cache.end()) { - if(paintIcon(filename, 0, 0, 0, 1, false)) { - it = icon_cache.find(filename); - } - } - if(it != icon_cache.end()) { - *width = it->second.width; - *height = it->second.height; - } -} - -bool CFrameBuffer::paintIcon8(const std::string & filename, const int x, const int y, const unsigned char offset) -{ - if (!getActive()) - return false; - -//printf("%s(file, %d, %d, %d)\n", __FUNCTION__, x, y, offset); - - struct rawHeader header; - uint16_t width, height; - int lfd; - - lfd = open((iconBasePath + "/" + filename).c_str(), O_RDONLY); - - if (lfd == -1) { - printf("paintIcon8: error while loading icon: %s/%s\n", iconBasePath.c_str(), filename.c_str()); - return false; - } - - read(lfd, &header, sizeof(struct rawHeader)); - - width = (header.width_hi << 8) | header.width_lo; - height = (header.height_hi << 8) | header.height_lo; - - unsigned char pixbuf[768]; - - uint8_t * d = ((uint8_t *)getFrameBufferPointer()) + x * sizeof(fb_pixel_t) + stride * y; - fb_pixel_t * d2; - for (int count=0; count::iterator it; - - if (!getActive()) - return false; - - int yy = y; - //printf("CFrameBuffer::paintIcon: load %s\n", filename.c_str());fflush(stdout); - - /* we cache and check original name */ - it = icon_cache.find(filename); - if(it == icon_cache.end()) { - std::string newname = getIconPath(filename); - //printf("CFrameBuffer::paintIcon: check for %s\n", newname.c_str());fflush(stdout); - - data = g_PicViewer->getIcon(newname, &width, &height); - - if(data) { //TODO: intercepting of possible full icon cache, that could cause strange behavior while painting of uncached icons - int dsize = width*height*sizeof(fb_pixel_t); - //printf("CFrameBuffer::paintIcon: %s found, data %x size %d x %d\n", newname.c_str(), data, width, height);fflush(stdout); - if(cache_size+dsize < ICON_CACHE_SIZE) { - cache_size += dsize; - tmpIcon.width = width; - tmpIcon.height = height; - tmpIcon.data = data; - icon_cache.insert(std::pair (filename, tmpIcon)); - //printf("Cached %s, cache size %d\n", newname.c_str(), cache_size); - } - goto _display; - } - - newname = getIconPath(filename, "raw"); - - int lfd = open(newname.c_str(), O_RDONLY); - - if (lfd == -1) { - //printf("paintIcon: error while loading icon: %s\n", newname.c_str()); - return false; - } - - ssize_t s = read(lfd, &header, sizeof(struct rawHeader)); - if (s < 0) { - perror("read"); - return false; - } - - if (s < (ssize_t) sizeof(rawHeader)){ - printf("paintIcon: error while loading icon: %s, header too small\n", newname.c_str()); - return false; - } - - - tmpIcon.width = width = (header.width_hi << 8) | header.width_lo; - tmpIcon.height = height = (header.height_hi << 8) | header.height_lo; - if (!width || !height) { - printf("paintIcon: error while loading icon: %s, wrong dimensions (%dHx%dW)\n", newname.c_str(), height, width); - return false; - } - - int dsize = width*height*sizeof(fb_pixel_t); - - tmpIcon.data = (fb_pixel_t*) cs_malloc_uncached(dsize); - data = tmpIcon.data; - - unsigned char pixbuf[768]; - for (int count = 0; count < height; count ++ ) { - read(lfd, &pixbuf[0], width >> 1 ); - unsigned char *pixpos = &pixbuf[0]; - for (int count2 = 0; count2 < width >> 1; count2 ++ ) { - unsigned char compressed = *pixpos; - unsigned char pix1 = (compressed & 0xf0) >> 4; - unsigned char pix2 = (compressed & 0x0f); - if (pix1 != header.transp) - *data++ = realcolor[pix1+offset]; - else - *data++ = 0; - if (pix2 != header.transp) - *data++ = realcolor[pix2+offset]; - else - *data++ = 0; - pixpos++; - } - } - close(lfd); - - data = tmpIcon.data; - - if(cache_size+dsize < ICON_CACHE_SIZE) { - cache_size += dsize; - icon_cache.insert(std::pair (filename, tmpIcon)); - //printf("Cached %s, cache size %d\n", newname.c_str(), cache_size); - } - } else { - data = it->second.data; - width = it->second.width; - height = it->second.height; - //printf("paintIcon: already cached %s %d x %d\n", newname.c_str(), width, height); - } -_display: - if(!paint) - return true; - - if (h != 0) - yy += (h - height) / 2; - - checkFbArea(x, yy, width, height, true); - if (paintBg) - paintBoxRel(x, yy, width, height, colBg); - blit2FB(data, width, height, x, yy, 0, 0, true); - checkFbArea(x, yy, width, height, false); - return true; -} - -void CFrameBuffer::loadPal(const std::string & filename, const unsigned char offset, const unsigned char endidx) -{ - if (!getActive()) - return; - -//printf("%s()\n", __FUNCTION__); - - struct rgbData rgbdata; - int lfd; - - lfd = open((iconBasePath + "/" + filename).c_str(), O_RDONLY); - - if (lfd == -1) { - printf("error while loading palette: %s/%s\n", iconBasePath.c_str(), filename.c_str()); - return; - } - - int pos = 0; - int readb = read(lfd, &rgbdata, sizeof(rgbdata) ); - while(readb) { - __u32 rgb = (rgbdata.r<<16) | (rgbdata.g<<8) | (rgbdata.b); - int colpos = offset+pos; - if( colpos>endidx) - break; - - paletteSetColor(colpos, rgb, 0xFF); - readb = read(lfd, &rgbdata, sizeof(rgbdata) ); - pos++; - } - paletteSet(&cmap); - close(lfd); -} - -void CFrameBuffer::paintPixel(const int x, const int y, const fb_pixel_t col) -{ - if (!getActive()) - return; - - #ifdef USE_NEVIS_GXA - paintHLineRel(x, 1, y, col); - #else - fb_pixel_t * pos = getFrameBufferPointer(); - pos += (stride / sizeof(fb_pixel_t)) * y; - pos += x; - - *pos = col; - #endif -} - -void CFrameBuffer::paintShortHLineRelInternal(const int& x, const int& dx, const int& y, const fb_pixel_t& col) -{ - uint8_t * pos = ((uint8_t *)getFrameBufferPointer()) + x * sizeof(fb_pixel_t) + stride * y; - fb_pixel_t * dest = (fb_pixel_t *)pos; - for (int i = 0; i < dx; i++) - *(dest++) = col; -} - -int CFrameBuffer::limitRadius(const int& dx, const int& dy, int& radius) -{ - if (radius > dx) - return dx; - if (radius > dy) - return dy; - if (radius > 540) - return 540; - return radius; -} - -void CFrameBuffer::setCornerFlags(const int& type) -{ - corner_tl = (type & CORNER_TOP_LEFT) == CORNER_TOP_LEFT; - corner_tr = (type & CORNER_TOP_RIGHT) == CORNER_TOP_RIGHT; - corner_bl = (type & CORNER_BOTTOM_LEFT) == CORNER_BOTTOM_LEFT; - corner_br = (type & CORNER_BOTTOM_RIGHT) == CORNER_BOTTOM_RIGHT; -} - -void CFrameBuffer::initQCircle() -{ - /* this table contains the x coordinates for a quarter circle (the bottom right quarter) with fixed - radius of 540 px which is the half of the max HD graphics size of 1080 px. So with that table we - ca draw boxes with round corners and als circles by just setting dx = dy = radius (max 540). */ - static const int _q_circle[541] = { - 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, - 540, 540, 540, 540, 539, 539, 539, 539, 539, 539, 539, 539, 539, 539, 539, 539, 539, 539, 539, 539, - 539, 538, 538, 538, 538, 538, 538, 538, 538, 538, 538, 538, 538, 537, 537, 537, 537, 537, 537, 537, - 537, 537, 536, 536, 536, 536, 536, 536, 536, 536, 535, 535, 535, 535, 535, 535, 535, 535, 534, 534, - 534, 534, 534, 534, 533, 533, 533, 533, 533, 533, 532, 532, 532, 532, 532, 532, 531, 531, 531, 531, - 531, 531, 530, 530, 530, 530, 529, 529, 529, 529, 529, 529, 528, 528, 528, 528, 527, 527, 527, 527, - 527, 526, 526, 526, 526, 525, 525, 525, 525, 524, 524, 524, 524, 523, 523, 523, 523, 522, 522, 522, - 522, 521, 521, 521, 521, 520, 520, 520, 519, 519, 519, 518, 518, 518, 518, 517, 517, 517, 516, 516, - 516, 515, 515, 515, 515, 514, 514, 514, 513, 513, 513, 512, 512, 512, 511, 511, 511, 510, 510, 510, - 509, 509, 508, 508, 508, 507, 507, 507, 506, 506, 506, 505, 505, 504, 504, 504, 503, 503, 502, 502, - 502, 501, 501, 500, 500, 499, 499, 499, 498, 498, 498, 497, 497, 496, 496, 496, 495, 495, 494, 494, - 493, 493, 492, 492, 491, 491, 490, 490, 490, 489, 489, 488, 488, 487, 487, 486, 486, 485, 485, 484, - 484, 483, 483, 482, 482, 481, 481, 480, 480, 479, 479, 478, 478, 477, 477, 476, 476, 475, 475, 474, - 473, 473, 472, 472, 471, 471, 470, 470, 469, 468, 468, 467, 466, 466, 465, 465, 464, 464, 463, 462, - 462, 461, 460, 460, 459, 459, 458, 458, 457, 456, 455, 455, 454, 454, 453, 452, 452, 451, 450, 450, - 449, 449, 448, 447, 446, 446, 445, 445, 444, 443, 442, 441, 441, 440, 440, 439, 438, 437, 436, 436, - 435, 435, 434, 433, 432, 431, 431, 430, 429, 428, 427, 427, 426, 425, 425, 424, 423, 422, 421, 421, - 420, 419, 418, 417, 416, 416, 415, 414, 413, 412, 412, 411, 410, 409, 408, 407, 406, 405, 404, 403, - 403, 402, 401, 400, 399, 398, 397, 397, 395, 394, 393, 393, 392, 391, 390, 389, 388, 387, 386, 385, - 384, 383, 382, 381, 380, 379, 378, 377, 376, 375, 374, 373, 372, 371, 369, 368, 367, 367, 365, 364, - 363, 362, 361, 360, 358, 357, 356, 355, 354, 353, 352, 351, 350, 348, 347, 346, 345, 343, 342, 341, - 340, 339, 337, 336, 335, 334, 332, 331, 329, 328, 327, 326, 324, 323, 322, 321, 319, 317, 316, 315, - 314, 312, 310, 309, 308, 307, 305, 303, 302, 301, 299, 297, 296, 294, 293, 291, 289, 288, 287, 285, - 283, 281, 280, 278, 277, 275, 273, 271, 270, 268, 267, 265, 263, 261, 259, 258, 256, 254, 252, 250, - 248, 246, 244, 242, 240, 238, 236, 234, 232, 230, 228, 225, 223, 221, 219, 217, 215, 212, 210, 207, - 204, 202, 200, 197, 195, 192, 190, 187, 184, 181, 179, 176, 173, 170, 167, 164, 160, 157, 154, 150, - 147, 144, 140, 136, 132, 128, 124, 120, 115, 111, 105, 101, 95, 89, 83, 77, 69, 61, 52, 40, - 23}; - if (q_circle == NULL) - q_circle = new int[sizeof(_q_circle) / sizeof(int)]; - memcpy(q_circle, _q_circle, sizeof(_q_circle)); -} - -bool CFrameBuffer::calcCorners(int *ofs, int *ofl, int *ofr, const int& dy, const int& line, const int& radius, const int& type) -{ -/* just an multiplicator for all math to reduce rounding errors */ -#define MUL 32768 - int scl, _ofs = 0; - bool ret = false; - if (ofl != NULL) *ofl = 0; - if (ofr != NULL) *ofr = 0; - int scf = (540 * MUL) / ((radius < 1) ? 1 : radius); - /* one of the top corners */ - if (line < radius && (type & CORNER_TOP)) { - /* uper round corners */ - scl = scf * (radius - line) / MUL; - if ((scf * (radius - line) % MUL) >= (MUL / 2)) /* round up */ - scl++; - _ofs = radius - (q_circle[scl] * MUL / scf); - if (ofl != NULL) *ofl = corner_tl ? _ofs : 0; - if (ofr != NULL) *ofr = corner_tr ? _ofs : 0; - } - /* one of the bottom corners */ - else if ((line >= dy - radius) && (type & CORNER_BOTTOM)) { - /* lower round corners */ - scl = scf * (radius - (dy - (line + 1))) / MUL; - if ((scf * (radius - (dy - (line + 1))) % MUL) >= (MUL / 2)) /* round up */ - scl++; - _ofs = radius - (q_circle[scl] * MUL / scf); - if (ofl != NULL) *ofl = corner_bl ? _ofs : 0; - if (ofr != NULL) *ofr = corner_br ? _ofs : 0; - } - else - ret = true; - if (ofs != NULL) *ofs = _ofs; - return ret; -} - -void CFrameBuffer::paintBoxFrame(const int x, const int y, const int dx, const int dy, const int px, const fb_pixel_t col, int radius, int type) -{ - if (!getActive()) - return; - - if (dx == 0 || dy == 0) { - dprintf(DEBUG_NORMAL, "[CFrameBuffer] [%s - %d]: radius %d, start x %d y %d end x %d y %d\n", __func__, __LINE__, radius, x, y, x+dx, y+dy); - return; - } - if (radius < 0) - dprintf(DEBUG_NORMAL, "[CFrameBuffer] [%s - %d]: WARNING! radius < 0 [%d] FIXIT\n", __func__, __LINE__, radius); - - setCornerFlags(type); - int rad_tl = 0, rad_tr = 0, rad_bl = 0, rad_br = 0; - if (type && radius) { - int x_rad = radius - 1; - if (corner_tl) rad_tl = x_rad; - if (corner_tr) rad_tr = x_rad; - if (corner_bl) rad_bl = x_rad; - if (corner_br) rad_br = x_rad; - } - paintBoxRel(x + rad_tl , y , dx - rad_tl - rad_tr, px , col); // top horizontal - paintBoxRel(x + rad_bl , y + dy - px, dx - rad_bl - rad_br, px , col); // bottom horizontal - paintBoxRel(x , y + rad_tl , px , dy - rad_tl - rad_bl, col); // left vertical - paintBoxRel(x + dx - px, y + rad_tr , px , dy - rad_tr - rad_br, col); // right vertical - - if (type && radius) { - radius = limitRadius(dx, dy, radius); - int line = 0; - waitForIdle("CFrameBuffer::paintBoxFrame"); - while (line < dy) { - int ofs = 0, ofs_i = 0; - // inner box - if ((line >= px) && (line < (dy - px))) - ofs_i = calcCornersOffset(dy - 2*px, line-px, radius-px, type); - // outer box - ofs = calcCornersOffset(dy, line, radius, type); - - int _x = x + ofs; - int _x_end = x + dx; - int _y = y + line; - if ((line < px) || (line >= (dy - px))) { - // left - if (((corner_tl) && (line < radius)) || ((corner_bl) && (line >= dy - radius))) - paintShortHLineRelInternal(_x, radius - ofs, _y, col); - // right - if (((corner_tr) && (line < radius)) || ((corner_br) && (line >= dy - radius))) - paintShortHLineRelInternal(_x_end - radius, radius - ofs, _y, col); - } - else if (line < (dy - px)) { - int _dx = (ofs_i-ofs) + px; - // left - if (((corner_tl) && (line < radius)) || ((corner_bl) && (line >= dy - radius))) - paintShortHLineRelInternal(_x, _dx, _y, col); - // right - if (((corner_tr) && (line < radius)) || ((corner_br) && (line >= dy - radius))) - paintShortHLineRelInternal(_x_end - ofs_i - px, _dx, _y, col); - } - if ((line == radius) && (dy > 2*radius)) - // line outside the rounded corners - line = dy - radius; - else - line++; - } - } -} - -void CFrameBuffer::paintLine(int xa, int ya, int xb, int yb, const fb_pixel_t col) -{ - if (!getActive()) - return; - -//printf("%s(%d, %d, %d, %d, %.8X)\n", __FUNCTION__, xa, ya, xb, yb, col); - - int dx = abs (xa - xb); - int dy = abs (ya - yb); - int x; - int y; - int End; - int step; - - if ( dx > dy ) - { - int p = 2 * dy - dx; - int twoDy = 2 * dy; - int twoDyDx = 2 * (dy-dx); - - if ( xa > xb ) - { - x = xb; - y = yb; - End = xa; - step = ya < yb ? -1 : 1; - } - else - { - x = xa; - y = ya; - End = xb; - step = yb < ya ? -1 : 1; - } - - paintPixel (x, y, col); - - while( x < End ) - { - x++; - if ( p < 0 ) - p += twoDy; - else - { - y += step; - p += twoDyDx; - } - paintPixel (x, y, col); - } - } - else - { - int p = 2 * dx - dy; - int twoDx = 2 * dx; - int twoDxDy = 2 * (dx-dy); - - if ( ya > yb ) - { - x = xb; - y = yb; - End = ya; - step = xa < xb ? -1 : 1; - } - else - { - x = xa; - y = ya; - End = yb; - step = xb < xa ? -1 : 1; - } - - paintPixel (x, y, col); - - while( y < End ) - { - y++; - if ( p < 0 ) - p += twoDx; - else - { - x += step; - p += twoDxDy; - } - paintPixel (x, y, col); - } - } -} -#if 0 -//never used -void CFrameBuffer::setBackgroundColor(const fb_pixel_t color) -{ - backgroundColor = color; -} - -bool CFrameBuffer::loadPictureToMem(const std::string & filename, const uint16_t width, const uint16_t height, const uint16_t pstride, fb_pixel_t * memp) -{ - struct rawHeader header; - int lfd; - -//printf("%s(%d, %d, memp)\n", __FUNCTION__, width, height); - - lfd = open((iconBasePath + "/" + filename).c_str(), O_RDONLY ); - - if (lfd == -1) - { - printf("error while loading icon: %s/%s\n", iconBasePath.c_str(), filename.c_str()); - return false; - } - - read(lfd, &header, sizeof(struct rawHeader)); - - if ((width != ((header.width_hi << 8) | header.width_lo)) || - (height != ((header.height_hi << 8) | header.height_lo))) - { - printf("error while loading icon: %s - invalid resolution = %hux%hu\n", filename.c_str(), width, height); - close(lfd); - return false; - } - - if ((pstride == 0) || (pstride == width * sizeof(fb_pixel_t))) - read(lfd, memp, height * width * sizeof(fb_pixel_t)); - else - for (int i = 0; i < height; i++) - read(lfd, ((uint8_t *)memp) + i * pstride, width * sizeof(fb_pixel_t)); - - close(lfd); - return true; -} - -bool CFrameBuffer::loadPicture2Mem(const std::string & filename, fb_pixel_t * memp) -{ - return loadPictureToMem(filename, BACKGROUNDIMAGEWIDTH, 576, 0, memp); -} - -bool CFrameBuffer::loadPicture2FrameBuffer(const std::string & filename) -{ - if (!getActive()) - return false; - - return loadPictureToMem(filename, BACKGROUNDIMAGEWIDTH, 576, getStride(), getFrameBufferPointer()); -} - -bool CFrameBuffer::savePictureFromMem(const std::string & filename, const fb_pixel_t * const memp) -{ - struct rawHeader header; - uint16_t width, height; - int lfd; - - width = BACKGROUNDIMAGEWIDTH; - height = 576; - - header.width_lo = width & 0xFF; - header.width_hi = width >> 8; - header.height_lo = height & 0xFF; - header.height_hi = height >> 8; - header.transp = 0; - - lfd = open((iconBasePath + "/" + filename).c_str(), O_WRONLY | O_CREAT, 0644); - - if (lfd==-1) - { - printf("error while saving icon: %s/%s", iconBasePath.c_str(), filename.c_str() ); - return false; - } - - write(lfd, &header, sizeof(struct rawHeader)); - - write(lfd, memp, width * height * sizeof(fb_pixel_t)); - - close(lfd); - return true; -} - -bool CFrameBuffer::loadBackground(const std::string & filename, const unsigned char offset) -{ - if ((backgroundFilename == filename) && (background)) - return true; - - if (background) - delete[] background; - - background = new fb_pixel_t[BACKGROUNDIMAGEWIDTH * 576]; - - if (!loadPictureToMem(filename, BACKGROUNDIMAGEWIDTH, 576, 0, background)) - { - delete[] background; - background=0; - return false; - } - - if (offset != 0)//pic-offset - { - fb_pixel_t * bpos = background; - int pos = BACKGROUNDIMAGEWIDTH * 576; - while (pos > 0) - { - *bpos += offset; - bpos++; - pos--; - } - } - - fb_pixel_t * dest = background + BACKGROUNDIMAGEWIDTH * 576; - uint8_t * src = ((uint8_t * )background)+ BACKGROUNDIMAGEWIDTH * 576; - for (int i = 576 - 1; i >= 0; i--) - for (int j = BACKGROUNDIMAGEWIDTH - 1; j >= 0; j--) - { - dest--; - src--; - paintPixel(dest, *src); - } - backgroundFilename = filename; - - return true; -} - -bool CFrameBuffer::loadBackgroundPic(const std::string & filename, bool show) -{ - if ((backgroundFilename == filename) && (background)) - return true; - -//printf("loadBackgroundPic: %s\n", filename.c_str()); - if (background){ - delete[] background; - background = NULL; - } - background = g_PicViewer->getImage(iconBasePath + "/" + filename, BACKGROUNDIMAGEWIDTH, 576); - - if (background == NULL) { - background=0; - return false; - } - - backgroundFilename = filename; - if(show) { - useBackgroundPaint = true; - paintBackground(); - } - return true; -} -#endif -void CFrameBuffer::useBackground(bool ub) -{ - useBackgroundPaint = ub; - if(!useBackgroundPaint) { - delete[] background; - background=0; - } -} - -bool CFrameBuffer::getuseBackground(void) -{ - return useBackgroundPaint; -} - -void CFrameBuffer::saveBackgroundImage(void) -{ - if (backupBackground != NULL){ - delete[] backupBackground; - backupBackground = NULL; - } - backupBackground = background; - //useBackground(false); // <- necessary since no background is available - useBackgroundPaint = false; - background = NULL; -} - -void CFrameBuffer::restoreBackgroundImage(void) -{ - fb_pixel_t * tmp = background; - - if (backupBackground != NULL) - { - background = backupBackground; - backupBackground = NULL; - } - else - useBackground(false); // <- necessary since no background is available - - if (tmp != NULL){ - delete[] tmp; - tmp = NULL; - } -} - -void CFrameBuffer::paintBackgroundBoxRel(int x, int y, int dx, int dy) -{ - if (!getActive()) - return; - - checkFbArea(x, y, dx, dy, true); - if(!useBackgroundPaint) - { - paintBoxRel(x, y, dx, dy, backgroundColor); - } - else - { - uint8_t * fbpos = ((uint8_t *)getFrameBufferPointer()) + x * sizeof(fb_pixel_t) + stride * y; - fb_pixel_t * bkpos = background + x + BACKGROUNDIMAGEWIDTH * y; - for(int count = 0;count < dy; count++) - { - memmove(fbpos, bkpos, dx * sizeof(fb_pixel_t)); - fbpos += stride; - bkpos += BACKGROUNDIMAGEWIDTH; - } - } - checkFbArea(x, y, dx, dy, false); -} - -void CFrameBuffer::paintBackground() -{ - if (!getActive()) - return; - - checkFbArea(0, 0, xRes, yRes, true); - if (useBackgroundPaint && (background != NULL)) - { - for (int i = 0; i < 576; i++) - memmove(((uint8_t *)getFrameBufferPointer()) + i * stride, (background + i * BACKGROUNDIMAGEWIDTH), BACKGROUNDIMAGEWIDTH * sizeof(fb_pixel_t)); - } - else - { - paintBoxRel(0, 0, xRes, yRes, backgroundColor); - } - checkFbArea(0, 0, xRes, yRes, false); -} - -void CFrameBuffer::SaveScreen(int x, int y, int dx, int dy, fb_pixel_t * const memp) -{ - if (!getActive()) - return; - - checkFbArea(x, y, dx, dy, true); - uint8_t * pos = ((uint8_t *)getFrameBufferPointer()) + x * sizeof(fb_pixel_t) + stride * y; - fb_pixel_t * bkpos = memp; - for (int count = 0; count < dy; count++) { - fb_pixel_t * dest = (fb_pixel_t *)pos; - for (int i = 0; i < dx; i++) - //*(dest++) = col; - *(bkpos++) = *(dest++); - pos += stride; - } -#if 0 //FIXME test to flush cache - if (ioctl(fd, 1, FB_BLANK_UNBLANK) < 0); -#endif - //RestoreScreen(x, y, dx, dy, memp); //FIXME -#if 0 - uint8_t * fbpos = ((uint8_t *)getFrameBufferPointer()) + x * sizeof(fb_pixel_t) + stride * y; - fb_pixel_t * bkpos = memp; - for (int count = 0; count < dy; count++) - { - memmove(bkpos, fbpos, dx * sizeof(fb_pixel_t)); - fbpos += stride; - bkpos += dx; - } -#endif - checkFbArea(x, y, dx, dy, false); - -} - -void CFrameBuffer::RestoreScreen(int x, int y, int dx, int dy, fb_pixel_t * const memp) -{ - if (!getActive()) - return; - - checkFbArea(x, y, dx, dy, true); - uint8_t * fbpos = ((uint8_t *)getFrameBufferPointer()) + x * sizeof(fb_pixel_t) + stride * y; - fb_pixel_t * bkpos = memp; - for (int count = 0; count < dy; count++) - { - memmove(fbpos, bkpos, dx * sizeof(fb_pixel_t)); - fbpos += stride; - bkpos += dx; - } - checkFbArea(x, y, dx, dy, false); -} -#if 0 -//never used -void CFrameBuffer::switch_signal (int signal) -{ - CFrameBuffer * thiz = CFrameBuffer::getInstance(); - if (signal == SIGUSR1) { - if (virtual_fb != NULL) - delete[] virtual_fb; - virtual_fb = new uint8_t[thiz->stride * thiz->yRes]; - thiz->active = false; - if (virtual_fb != NULL) - memmove(virtual_fb, thiz->lfb, thiz->stride * thiz->yRes); - ioctl(thiz->tty, VT_RELDISP, 1); - printf ("release display\n"); - } - else if (signal == SIGUSR2) { - ioctl(thiz->tty, VT_RELDISP, VT_ACKACQ); - thiz->active = true; - printf ("acquire display\n"); - thiz->paletteSet(NULL); - if (virtual_fb != NULL) - memmove(thiz->lfb, virtual_fb, thiz->stride * thiz->yRes); - else - memset(thiz->lfb, 0, thiz->stride * thiz->yRes); - } -} -#endif - -void CFrameBuffer::Clear() -{ - paintBackground(); - //memset(getFrameBufferPointer(), 0, stride * yRes); -} - -void CFrameBuffer::showFrame(const std::string & filename) -{ - std::string picture = std::string(ICONSDIR_VAR) + "/" + filename; - if (access(picture.c_str(), F_OK)) - picture = iconBasePath + "/" + filename; - if (filename.find("/", 0) != std::string::npos) - picture = filename; - - videoDecoder->ShowPicture(picture.c_str()); -} - -void CFrameBuffer::stopFrame() -{ - videoDecoder->StopPicture(); -} - -bool CFrameBuffer::Lock() -{ - if(locked) - return false; - locked = true; - return true; -} - -void CFrameBuffer::Unlock() -{ - locked = false; -} - -void * CFrameBuffer::int_convertRGB2FB(unsigned char *rgbbuff, unsigned long x, unsigned long y, int transp, bool alpha) -{ - unsigned long i; - unsigned int *fbbuff; - unsigned long count; - - if (!x || !y) { - printf("convertRGB2FB%s: Error: invalid dimensions (%luX x %luY)\n", - ((alpha) ? " (Alpha)" : ""), x, y); - return NULL; - } - - count = x * y; - - fbbuff = (unsigned int *) cs_malloc_uncached(count * sizeof(unsigned int)); - if(fbbuff == NULL) { - printf("convertRGB2FB%s: Error: cs_malloc_uncached\n", ((alpha) ? " (Alpha)" : "")); - return NULL; - } - - if (alpha) { - for(i = 0; i < count ; i++) - fbbuff[i] = ((rgbbuff[i*4+3] << 24) & 0xFF000000) | - ((rgbbuff[i*4] << 16) & 0x00FF0000) | - ((rgbbuff[i*4+1] << 8) & 0x0000FF00) | - ((rgbbuff[i*4+2]) & 0x000000FF); - } else { - switch (m_transparent) { - case CFrameBuffer::TM_BLACK: - for(i = 0; i < count ; i++) { - transp = 0; - if(rgbbuff[i*3] || rgbbuff[i*3+1] || rgbbuff[i*3+2]) - transp = 0xFF; - fbbuff[i] = (transp << 24) | ((rgbbuff[i*3] << 16) & 0xFF0000) | ((rgbbuff[i*3+1] << 8) & 0xFF00) | (rgbbuff[i*3+2] & 0xFF); - } - break; - case CFrameBuffer::TM_INI: - for(i = 0; i < count ; i++) - fbbuff[i] = (transp << 24) | ((rgbbuff[i*3] << 16) & 0xFF0000) | ((rgbbuff[i*3+1] << 8) & 0xFF00) | (rgbbuff[i*3+2] & 0xFF); - break; - case CFrameBuffer::TM_NONE: - default: - for(i = 0; i < count ; i++) - fbbuff[i] = 0xFF000000 | ((rgbbuff[i*3] << 16) & 0xFF0000) | ((rgbbuff[i*3+1] << 8) & 0xFF00) | (rgbbuff[i*3+2] & 0xFF); - break; - } - } - return (void *) fbbuff; -} - -void * CFrameBuffer::convertRGB2FB(unsigned char *rgbbuff, unsigned long x, unsigned long y, int transp) -{ - return int_convertRGB2FB(rgbbuff, x, y, transp, false); -} - -void * CFrameBuffer::convertRGBA2FB(unsigned char *rgbbuff, unsigned long x, unsigned long y) -{ - return int_convertRGB2FB(rgbbuff, x, y, 0, true); -} - -void CFrameBuffer::blit2FB(void *fbbuff, uint32_t width, uint32_t height, uint32_t xoff, uint32_t yoff, uint32_t xp, uint32_t yp, bool /*transp*/) -{ - int xc, yc; - - xc = (width > xRes) ? xRes : width; - yc = (height > yRes) ? yRes : height; - -#if defined(FB_HW_ACCELERATION) - if(!(width%4)) { - fb_image image; - image.dx = xoff; - image.dy = yoff; - image.width = xc; - image.height = yc; - image.cmap.len = 0; - image.depth = 32; -#if 1 - image.data = (const char*)fbbuff; - ioctl(fd, FBIO_IMAGE_BLT, &image); -#else - for (int count = 0; count < yc; count++ ) { - fb_pixel_t* data = (fb_pixel_t *) fbbuff; - fb_pixel_t *pixpos = &data[(count + yp) * width]; - image.data = (const char*) pixpos; //fbbuff +(count + yp)*width; - image.dy = yoff+count; - image.height = 1; - ioctl(fd, FBIO_IMAGE_BLT, &image); - } -#endif - //printf("\033[34m>>>>\033[0m [%s:%s:%d] FB_HW_ACCELERATION (image) x: %d, y: %d, w: %d, h: %d\n", __file__, __func__, __LINE__, xoff, yoff, xc, yc); - return; - } - -#elif defined(USE_NEVIS_GXA) - u32 cmd; - void * uKva; - - uKva = cs_phys_addr(fbbuff); - //printf("CFrameBuffer::blit2FB: data %x Kva %x\n", (int) fbbuff, (int) uKva); - - if(uKva != NULL) { - OpenThreads::ScopedLock m_lock(mutex); - cmd = GXA_CMD_BLT | GXA_CMD_NOT_TEXT | GXA_SRC_BMP_SEL(1) | GXA_DST_BMP_SEL(2) | GXA_PARAM_COUNT(3); - - _write_gxa(gxa_base, GXA_BMP1_TYPE_REG, (3 << 16) | width); - _write_gxa(gxa_base, GXA_BMP1_ADDR_REG, (unsigned int) uKva); - - _write_gxa(gxa_base, cmd, GXA_POINT(xoff, yoff)); /* destination pos */ - _write_gxa(gxa_base, cmd, GXA_POINT(xc, yc)); /* source width, FIXME real or adjusted xc, yc ? */ - _write_gxa(gxa_base, cmd, GXA_POINT(xp, yp)); /* source pos */ - - return; - } -#endif - fb_pixel_t* data = (fb_pixel_t *) fbbuff; - - uint8_t * d = ((uint8_t *)getFrameBufferPointer()) + xoff * sizeof(fb_pixel_t) + stride * yoff; - fb_pixel_t * d2; - - for (int count = 0; count < yc; count++ ) { - fb_pixel_t *pixpos = &data[(count + yp) * width]; - d2 = (fb_pixel_t *) d; - for (int count2 = 0; count2 < xc; count2++ ) { - fb_pixel_t pix = *(pixpos + xp); - if ((pix & 0xff000000) == 0xff000000) - *d2 = pix; - else { - uint8_t *in = (uint8_t *)(pixpos + xp); - uint8_t *out = (uint8_t *)d2; - int a = in[3]; /* TODO: big/little endian */ - *out = (*out + ((*in - *out) * a) / 256); - in++; out++; - *out = (*out + ((*in - *out) * a) / 256); - in++; out++; - *out = (*out + ((*in - *out) * a) / 256); - } - d2++; - pixpos++; - } - d += stride; - } -} - -void CFrameBuffer::blitBox2FB(const fb_pixel_t* boxBuf, uint32_t width, uint32_t height, uint32_t xoff, uint32_t yoff) -{ - if(width <1 || height <1 || !boxBuf ) - return; - - uint32_t xc = (width > xRes) ? (uint32_t)xRes : width; - uint32_t yc = (height > yRes) ? (uint32_t)yRes : height; - -#if defined(FB_HW_ACCELERATION) - if (!(width%4)) { - fb_image image; - image.dx = xoff; - image.dy = yoff; - image.width = xc; - image.height = yc; - image.cmap.len = 0; - image.depth = 32; - image.data = (const char*)boxBuf; - ioctl(fd, FBIO_IMAGE_BLT, &image); - //printf("\033[33m>>>>\033[0m [%s:%s:%d] FB_HW_ACCELERATION x: %d, y: %d, w: %d, h: %d\n", __file__, __func__, __LINE__, xoff, yoff, xc, yc); - return; - } - printf("\033[31m>>>>\033[0m [%s:%s:%d] Not use FB_HW_ACCELERATION x: %d, y: %d, w: %d, h: %d\n", __file__, __func__, __LINE__, xoff, yoff, xc, yc); -#elif defined(USE_NEVIS_GXA) - void* uKva = cs_phys_addr((void*)boxBuf); - if(uKva != NULL) { - OpenThreads::ScopedLock m_lock(mutex); - u32 cmd = GXA_CMD_BLT | GXA_CMD_NOT_TEXT | GXA_SRC_BMP_SEL(1) | GXA_DST_BMP_SEL(2) | GXA_PARAM_COUNT(3); - _write_gxa(gxa_base, GXA_BMP1_TYPE_REG, (3 << 16) | width); - _write_gxa(gxa_base, GXA_BMP1_ADDR_REG, (unsigned int) uKva); - _write_gxa(gxa_base, cmd, GXA_POINT(xoff, yoff)); - _write_gxa(gxa_base, cmd, GXA_POINT(xc, yc)); - _write_gxa(gxa_base, cmd, GXA_POINT(0, 0)); - //printf("\033[33m>>>>\033[0m [%s:%s:%d] USE_NEVIS_GXA x: %d, y: %d, w: %d, h: %d\n", __file__, __func__, __LINE__, xoff, yoff, xc, yc); - add_gxa_sync_marker(); - return; - } - printf("\033[31m>>>>\033[0m [%s:%s:%d] Not use USE_NEVIS_GXA x: %d, y: %d, w: %d, h: %d\n", __file__, __func__, __LINE__, xoff, yoff, xc, yc); -#endif - uint32_t swidth = stride / sizeof(fb_pixel_t); - fb_pixel_t *fbp = getFrameBufferPointer() + (swidth * yoff); - fb_pixel_t* data = (fb_pixel_t*)boxBuf; - - uint32_t line = 0; - while (line < yc) { - fb_pixel_t *pixpos = &data[line * xc]; - for (uint32_t pos = xoff; pos < xoff + xc; pos++) { - //don't paint backgroundcolor (*pixpos = 0x00000000) - if (*pixpos) - *(fbp + pos) = *pixpos; - pixpos++; - } - fbp += swidth; - line++; - } -} - -void CFrameBuffer::displayRGB(unsigned char *rgbbuff, int x_size, int y_size, int x_pan, int y_pan, int x_offs, int y_offs, bool clearfb, int transp) -{ - void *fbbuff = NULL; - - if(rgbbuff == NULL) - return; - - /* correct panning */ - if(x_pan > x_size - (int)xRes) x_pan = 0; - if(y_pan > y_size - (int)yRes) y_pan = 0; - - /* correct offset */ - if(x_offs + x_size > (int)xRes) x_offs = 0; - if(y_offs + y_size > (int)yRes) y_offs = 0; - - /* blit buffer 2 fb */ - fbbuff = convertRGB2FB(rgbbuff, x_size, y_size, transp); - if(fbbuff==NULL) - return; - - /* ClearFB if image is smaller */ - /* if(x_size < (int)xRes || y_size < (int)yRes) */ - if(clearfb) - CFrameBuffer::getInstance()->Clear(); - - blit2FB(fbbuff, x_size, y_size, x_offs, y_offs, x_pan, y_pan); - cs_free_uncached(fbbuff); -} - -// ## AudioMute / Clock ###################################### - -void CFrameBuffer::setFbArea(int element, int _x, int _y, int _dx, int _dy) -{ - if (_x == 0 && _y == 0 && _dx == 0 && _dy == 0) { - // delete area - for (fbarea_iterator_t it = v_fbarea.begin(); it != v_fbarea.end(); ++it) { - if (it->element == element) { - v_fbarea.erase(it); - break; - } - } - if (v_fbarea.empty()) { - fbAreaActiv = false; - } - } - else { - // change area - bool found = false; - for (unsigned int i = 0; i < v_fbarea.size(); i++) { - if (v_fbarea[i].element == element) { - v_fbarea[i].x = _x; - v_fbarea[i].y = _y; - v_fbarea[i].dx = _dx; - v_fbarea[i].dy = _dy; - found = true; - break; - } - } - // set new area - if (!found) { - fb_area_t area; - area.x = _x; - area.y = _y; - area.dx = _dx; - area.dy = _dy; - area.element = element; - v_fbarea.push_back(area); - } - fbAreaActiv = true; - } -} - -int CFrameBuffer::checkFbAreaElement(int _x, int _y, int _dx, int _dy, fb_area_t *area) -{ - if (fb_no_check) - return FB_PAINTAREA_MATCH_NO; - - if (_y > area->y + area->dy) - return FB_PAINTAREA_MATCH_NO; - if (_x + _dx < area->x) - return FB_PAINTAREA_MATCH_NO; - if (_x > area->x + area->dx) - return FB_PAINTAREA_MATCH_NO; - if (_y + _dy < area->y) - return FB_PAINTAREA_MATCH_NO; - return FB_PAINTAREA_MATCH_OK; -} - -bool CFrameBuffer::_checkFbArea(int _x, int _y, int _dx, int _dy, bool prev) -{ - if (v_fbarea.empty()) - return true; - - static bool firstMutePaint = true; - - for (unsigned int i = 0; i < v_fbarea.size(); i++) { - int ret = checkFbAreaElement(_x, _y, _dx, _dy, &v_fbarea[i]); - if (ret == FB_PAINTAREA_MATCH_OK) { - switch (v_fbarea[i].element) { - case FB_PAINTAREA_MUTEICON1: - if (!do_paint_mute_icon) - break; -// waitForIdle(); - fb_no_check = true; - if (prev) { - firstMutePaint = false; - CAudioMute::getInstance()->hide(); - } - else { - if (!firstMutePaint) - CAudioMute::getInstance()->paint(); - } - fb_no_check = false; - break; - default: - break; - } - } - } - - return true; -} diff --git a/src/driver/framebuffer_ng.cpp b/src/driver/framebuffer_ng.cpp deleted file mode 100644 index b7fa12fb9..000000000 --- a/src/driver/framebuffer_ng.cpp +++ /dev/null @@ -1,1393 +0,0 @@ -/* - Neutrino-GUI - DBoxII-Project - - Copyright (C) 2001 Steffen Hehn 'McClean' - 2003 thegoodguy - Copyright (C) 2007-2015 Stefan Seyfried - - License: GPL - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#ifdef HAVE_COOL_HARDWARE -#include -#endif -#if HAVE_TRIPLEDRAGON -#ifdef SCALE -#undef SCALE -#endif -#include -extern int gfxfd; -#endif - -extern CPictureViewer * g_PicViewer; -#define ICON_CACHE_SIZE 1024*1024*2 // 2mb - -#define BACKGROUNDIMAGEWIDTH 720 - -/* note that it is *not* enough to just change those values */ -#define DEFAULT_XRES 1280 -#define DEFAULT_YRES 720 -#define DEFAULT_BPP 32 - -/*******************************************************************************/ - -void CFrameBuffer::waitForIdle(const char *) -{ - accel->waitForIdle(); -} - -/*******************************************************************************/ - -static uint8_t * virtual_fb = NULL; -inline unsigned int make16color(uint16_t r, uint16_t g, uint16_t b, uint16_t t, - uint32_t /*rl*/ = 0, uint32_t /*ro*/ = 0, - uint32_t /*gl*/ = 0, uint32_t /*go*/ = 0, - uint32_t /*bl*/ = 0, uint32_t /*bo*/ = 0, - uint32_t /*tl*/ = 0, uint32_t /*to*/ = 0) -{ - return ((t << 24) & 0xFF000000) | ((r << 8) & 0xFF0000) | ((g << 0) & 0xFF00) | (b >> 8 & 0xFF); -} - -/* this table contains the x coordinates for a quarter circle (the bottom right quarter) with fixed - radius of 540 px which is the half of the max HD graphics size of 1080 px. So with that table we - ca draw boxes with round corners and als circles by just setting dx = dy = radius (max 540). */ -static const int q_circle[541] = { - 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, 540, - 540, 540, 540, 540, 539, 539, 539, 539, 539, 539, 539, 539, 539, 539, 539, 539, 539, 539, 539, 539, - 539, 538, 538, 538, 538, 538, 538, 538, 538, 538, 538, 538, 538, 537, 537, 537, 537, 537, 537, 537, - 537, 537, 536, 536, 536, 536, 536, 536, 536, 536, 535, 535, 535, 535, 535, 535, 535, 535, 534, 534, - 534, 534, 534, 534, 533, 533, 533, 533, 533, 533, 532, 532, 532, 532, 532, 532, 531, 531, 531, 531, - 531, 531, 530, 530, 530, 530, 529, 529, 529, 529, 529, 529, 528, 528, 528, 528, 527, 527, 527, 527, - 527, 526, 526, 526, 526, 525, 525, 525, 525, 524, 524, 524, 524, 523, 523, 523, 523, 522, 522, 522, - 522, 521, 521, 521, 521, 520, 520, 520, 519, 519, 519, 518, 518, 518, 518, 517, 517, 517, 516, 516, - 516, 515, 515, 515, 515, 514, 514, 514, 513, 513, 513, 512, 512, 512, 511, 511, 511, 510, 510, 510, - 509, 509, 508, 508, 508, 507, 507, 507, 506, 506, 506, 505, 505, 504, 504, 504, 503, 503, 502, 502, - 502, 501, 501, 500, 500, 499, 499, 499, 498, 498, 498, 497, 497, 496, 496, 496, 495, 495, 494, 494, - 493, 493, 492, 492, 491, 491, 490, 490, 490, 489, 489, 488, 488, 487, 487, 486, 486, 485, 485, 484, - 484, 483, 483, 482, 482, 481, 481, 480, 480, 479, 479, 478, 478, 477, 477, 476, 476, 475, 475, 474, - 473, 473, 472, 472, 471, 471, 470, 470, 469, 468, 468, 467, 466, 466, 465, 465, 464, 464, 463, 462, - 462, 461, 460, 460, 459, 459, 458, 458, 457, 456, 455, 455, 454, 454, 453, 452, 452, 451, 450, 450, - 449, 449, 448, 447, 446, 446, 445, 445, 444, 443, 442, 441, 441, 440, 440, 439, 438, 437, 436, 436, - 435, 435, 434, 433, 432, 431, 431, 430, 429, 428, 427, 427, 426, 425, 425, 424, 423, 422, 421, 421, - 420, 419, 418, 417, 416, 416, 415, 414, 413, 412, 412, 411, 410, 409, 408, 407, 406, 405, 404, 403, - 403, 402, 401, 400, 399, 398, 397, 397, 395, 394, 393, 393, 392, 391, 390, 389, 388, 387, 386, 385, - 384, 383, 382, 381, 380, 379, 378, 377, 376, 375, 374, 373, 372, 371, 369, 368, 367, 367, 365, 364, - 363, 362, 361, 360, 358, 357, 356, 355, 354, 353, 352, 351, 350, 348, 347, 346, 345, 343, 342, 341, - 340, 339, 337, 336, 335, 334, 332, 331, 329, 328, 327, 326, 324, 323, 322, 321, 319, 317, 316, 315, - 314, 312, 310, 309, 308, 307, 305, 303, 302, 301, 299, 297, 296, 294, 293, 291, 289, 288, 287, 285, - 283, 281, 280, 278, 277, 275, 273, 271, 270, 268, 267, 265, 263, 261, 259, 258, 256, 254, 252, 250, - 248, 246, 244, 242, 240, 238, 236, 234, 232, 230, 228, 225, 223, 221, 219, 217, 215, 212, 210, 207, - 204, 202, 200, 197, 195, 192, 190, 187, 184, 181, 179, 176, 173, 170, 167, 164, 160, 157, 154, 150, - 147, 144, 140, 136, 132, 128, 124, 120, 115, 111, 105, 101, 95, 89, 83, 77, 69, 61, 52, 40, - 23}; - -static inline bool calcCorners(int *ofs, int *ofl, int *ofr, const int& dy, const int& line, const int& radius, - const bool& tl, const bool& tr, const bool& bl, const bool& br) -{ -/* just a multiplicator for all math to reduce rounding errors */ -#define MUL 32768 - int scl, _ofs = 0; - bool ret = false; - if (ofl != NULL) *ofl = 0; - if (ofr != NULL) *ofr = 0; - int scf = 540 * MUL / radius; - /* one of the top corners */ - if (line < radius && (tl || tr)) { - /* uper round corners */ - scl = scf * (radius - line) / MUL; - if ((scf * (radius - line) % MUL) >= (MUL / 2)) /* round up */ - scl++; - _ofs = radius - (q_circle[scl] * MUL / scf); - if (ofl != NULL && tl) *ofl = _ofs; - if (ofr != NULL && tr) *ofr = _ofs; - } - /* one of the bottom corners */ - else if ((line >= dy - radius) && (bl || br)) { - /* lower round corners */ - scl = scf * (radius - (dy - (line + 1))) / MUL; - if ((scf * (radius - (dy - (line + 1))) % MUL) >= (MUL / 2)) /* round up */ - scl++; - _ofs = radius - (q_circle[scl] * MUL / scf); - if (ofl != NULL && bl) *ofl = _ofs; - if (ofr != NULL && br) *ofr = _ofs; - } - else - ret = true; - if (ofs != NULL) *ofs = _ofs; - return ret; -} - -static inline int limitRadius(const int& dx, const int& dy, const int& radius) -{ - int m = std::min(dx, dy); - if (radius > m) - return m; - if (radius > 540) - return 540; - return radius; -} - -CFrameBuffer::CFrameBuffer() -: active ( true ) -{ - iconBasePath = ""; - available = 0; - cmap.start = 0; - cmap.len = 256; - cmap.red = red; - cmap.green = green; - cmap.blue = blue; - cmap.transp = trans; - backgroundColor = 0; - useBackgroundPaint = false; - background = NULL; - backupBackground = NULL; - backgroundFilename = ""; - fbAreaActiv = false; - fb_no_check = false; - fd = 0; - tty = 0; - bpp = 0; - locked = false; - m_transparent_default = CFrameBuffer::TM_BLACK; // TM_BLACK: Transparency when black content ('pseudo' transparency) - // TM_NONE: No 'pseudo' transparency - // TM_INI: Transparency depends on g_settings.infobar_alpha ??? - m_transparent = m_transparent_default; -//FIXME: test - memset(red, 0, 256*sizeof(__u16)); - memset(green, 0, 256*sizeof(__u16)); - memset(blue, 0, 256*sizeof(__u16)); - memset(trans, 0, 256*sizeof(__u16)); -} - -CFrameBuffer* CFrameBuffer::getInstance() -{ - static CFrameBuffer* frameBuffer = NULL; - - if(!frameBuffer) { - frameBuffer = new CFrameBuffer(); - printf("[neutrino] frameBuffer Instance created\n"); - } else { - //printf("[neutrino] frameBuffer Instace requested\n"); - } - return frameBuffer; -} - -#ifdef USE_NEVIS_GXA -void CFrameBuffer::setupGXA(void) -{ - accel->setupGXA(); -} -#endif - -void CFrameBuffer::init(const char * const) -{ - int tr = 0xFF; - accel = new CFbAccel(this); - cache_size = 0; - - /* Windows Colors */ - paletteSetColor(0x1, 0x010101, tr); - paletteSetColor(0x2, 0x800000, tr); - paletteSetColor(0x3, 0x008000, tr); - paletteSetColor(0x4, 0x808000, tr); - paletteSetColor(0x5, 0x000080, tr); - paletteSetColor(0x6, 0x800080, tr); - paletteSetColor(0x7, 0x008080, tr); - paletteSetColor(0x8, 0xA0A0A0, tr); - paletteSetColor(0x9, 0x505050, tr); - paletteSetColor(0xA, 0xFF0000, tr); - paletteSetColor(0xB, 0x00FF00, tr); - paletteSetColor(0xC, 0xFFFF00, tr); - paletteSetColor(0xD, 0x0000FF, tr); - paletteSetColor(0xE, 0xFF00FF, tr); - paletteSetColor(0xF, 0x00FFFF, tr); - paletteSetColor(0x10, 0xFFFFFF, tr); - paletteSetColor(0x11, 0x000000, tr); - paletteSetColor(COL_BACKGROUND, 0x000000, 0x0); - - paletteSet(); - - useBackground(false); - m_transparent = m_transparent_default; - return; -} - - -CFrameBuffer::~CFrameBuffer() -{ - active = false; /* keep people/infoclocks from accessing */ - std::map::iterator it; - - for(it = icon_cache.begin(); it != icon_cache.end(); ++it) { - /* printf("FB: delete cached icon %s: %x\n", it->first.c_str(), (int) it->second.data); */ - cs_free_uncached(it->second.data); - } - icon_cache.clear(); - - if (background) { - delete[] background; - background = NULL; - } - - if (backupBackground) { - delete[] backupBackground; - backupBackground = NULL; - } - - if (virtual_fb){ - delete[] virtual_fb; - virtual_fb = NULL; - } - delete accel; -} - -int CFrameBuffer::getFileHandle() const -{ - fprintf(stderr, "[fb]::%s: WARNING, this should never be used, please report!\n", __func__); - return fd; -} - -unsigned int CFrameBuffer::getStride() const -{ - return stride; -} - -unsigned int CFrameBuffer::getScreenWidth(bool real) -{ - if(real) - return xRes; - else - return g_settings.screen_EndX - g_settings.screen_StartX; -} - -unsigned int CFrameBuffer::getScreenHeight(bool real) -{ - if(real) - return yRes; - else - return g_settings.screen_EndY - g_settings.screen_StartY; -} - -unsigned int CFrameBuffer::getWindowWidth(bool force_small) -{ - int percent = force_small ? WINDOW_SIZE_SMALL : g_settings.window_width; - // always reduce a possible detailline - return (g_settings.screen_EndX - g_settings.screen_StartX - 2*ConnectLineBox_Width) * percent / 100; -} - -unsigned int CFrameBuffer::getWindowHeight(bool force_small) -{ - int percent = force_small ? WINDOW_SIZE_SMALL : g_settings.window_height; - return (g_settings.screen_EndY - g_settings.screen_StartY) * percent / 100; -} - -unsigned int CFrameBuffer::getScreenX() -{ - return g_settings.screen_StartX; -} - -unsigned int CFrameBuffer::getScreenY() -{ - return g_settings.screen_StartY; -} - -fb_pixel_t * CFrameBuffer::getFrameBufferPointer() const -{ - if (active || (virtual_fb == NULL)) - return accel->lbb; - else - return (fb_pixel_t *)virtual_fb; -} - -fb_pixel_t * CFrameBuffer::getBackBufferPointer() const -{ - return accel->backbuffer; -} - -bool CFrameBuffer::getActive() const -{ - return (active || (virtual_fb != NULL)); -} - -void CFrameBuffer::setActive(bool enable) -{ - active = enable; -} - -t_fb_var_screeninfo *CFrameBuffer::getScreenInfo() -{ - return &screeninfo; -} - -int CFrameBuffer::setMode(unsigned int /*nxRes*/, unsigned int /*nyRes*/, unsigned int /*nbpp*/) -{ -fprintf(stderr, "CFrameBuffer::setMode avail: %d active: %d\n", available, active); - if (!available&&!active) - return -1; - - int ret = accel->setMode(); - xRes = screeninfo.xres; - yRes = screeninfo.yres; - bpp = screeninfo.bits_per_pixel; - printf("FB: %dx%dx%d line length %d. %s nevis GXA accelerator.\n", xRes, yRes, bpp, stride, -#ifdef USE_NEVIS_GXA - "Using" -#else - "Not using" -#endif - ); - accel->update(); /* just in case we need to update stuff */ - - //memset(getFrameBufferPointer(), 0, stride * yRes); - paintBackground(); - return ret; -} -#if 0 -//never used -void CFrameBuffer::setTransparency( int /*tr*/ ) -{ -} -#endif - -#if !HAVE_TRIPLEDRAGON -void CFrameBuffer::setBlendMode(uint8_t mode) -{ - (void)mode; -#ifdef HAVE_COOL_HARDWARE - if (ioctl(fd, FBIO_SETBLENDMODE, mode)) - printf("FBIO_SETBLENDMODE failed.\n"); -#endif -} - -void CFrameBuffer::setBlendLevel(int level) -{ - (void)level; -#ifdef HAVE_COOL_HARDWARE - //printf("CFrameBuffer::setBlendLevel %d\n", level); - unsigned char value = 0xFF; - if((level >= 0) && (level <= 100)) - value = convertSetupAlpha2Alpha(level); - - if (ioctl(fd, FBIO_SETOPACITY, value)) - printf("FBIO_SETOPACITY failed.\n"); -#if 1 - if(level == 100) // TODO: sucks. - usleep(20000); -#endif -#endif -} -#else -/* TRIPLEDRAGON */ -void CFrameBuffer::setBlendMode(uint8_t mode) -{ - Stb04GFXOsdControl g; - ioctl(gfxfd, STB04GFX_OSD_GETCONTROL, &g); - g.use_global_alpha = (mode == 2); /* 1 == pixel alpha, 2 == global alpha */ - ioctl(gfxfd, STB04GFX_OSD_SETCONTROL, &g); -} - -void CFrameBuffer::setBlendLevel(int level) -{ - /* this is bypassing directfb, but faster and easier */ - Stb04GFXOsdControl g; - ioctl(gfxfd, STB04GFX_OSD_GETCONTROL, &g); - if (g.use_global_alpha == 0) - return; - - if (level < 0 || level > 100) - return; - - /* this is the same as convertSetupAlpha2Alpha(), but non-float */ - g.global_alpha = 255 - (255 * level / 100); - ioctl(gfxfd, STB04GFX_OSD_SETCONTROL, &g); - if (level == 100) // sucks - usleep(20000); -} -#endif - -#if 0 -//never used -void CFrameBuffer::setAlphaFade(int in, int num, int tr) -{ - for (int i=0; i>16)*level; - *g= ((rgb2&0x00FF00)>>8 )*level; - *b= ((rgb2&0x0000FF) )*level; - *r+=((rgb1&0xFF0000)>>16)*(255-level); - *g+=((rgb1&0x00FF00)>>8 )*(255-level); - *b+=((rgb1&0x0000FF) )*(255-level); -} - -void CFrameBuffer::paletteGenFade(int in, __u32 rgb1, __u32 rgb2, int num, int tr) -{ - for (int i=0; i>8; - cmap.green[i] =(rgb&0x00FF00) ; - cmap.blue[i] =(rgb&0x0000FF)<<8; - cmap.transp[i] = tr; -} - -void CFrameBuffer::paletteSet(struct fb_cmap *map) -{ - if (!active) - return; - - if(map == NULL) - map = &cmap; - - if(bpp == 8) { -//printf("Set palette for %dbit\n", bpp); - ioctl(fd, FBIOPUTCMAP, map); - } - uint32_t rl, ro, gl, go, bl, bo, tl, to; - rl = screeninfo.red.length; - ro = screeninfo.red.offset; - gl = screeninfo.green.length; - go = screeninfo.green.offset; - bl = screeninfo.blue.length; - bo = screeninfo.blue.offset; - tl = screeninfo.transp.length; - to = screeninfo.transp.offset; - for (int i = 0; i < 256; i++) { - realcolor[i] = make16color(cmap.red[i], cmap.green[i], cmap.blue[i], cmap.transp[i], - rl, ro, gl, go, bl, bo, tl, to); - } - OnAfterSetPallette(); -} - -void CFrameBuffer::paintHLineRelInternal2Buf(const int& x, const int& dx, const int& y, const int& box_dx, const fb_pixel_t& col, fb_pixel_t* buf) -{ - uint8_t * pos = ((uint8_t *)buf) + x * sizeof(fb_pixel_t) + box_dx * sizeof(fb_pixel_t) * y; - fb_pixel_t * dest = (fb_pixel_t *)pos; - for (int i = 0; i < dx; i++) - *(dest++) = col; -} - -fb_pixel_t* CFrameBuffer::paintBoxRel2Buf(const int dx, const int dy, const fb_pixel_t col, fb_pixel_t* buf/* = NULL*/, int radius/* = 0*/, int type/* = CORNER_ALL*/) -{ - if (!getActive()) - return buf; - if (dx == 0 || dy == 0) { - dprintf(DEBUG_INFO, "[%s - %d]: radius %d, dx %d dy %d\n", __func__, __LINE__, radius, dx, dy); - return buf; - } - - fb_pixel_t* pixBuf = buf; - if (pixBuf == NULL) { - pixBuf = (fb_pixel_t*) cs_malloc_uncached(dx*dy*sizeof(fb_pixel_t)); - if (pixBuf == NULL) { - dprintf(DEBUG_NORMAL, "[%s #%d] Error cs_malloc_uncached\n", __func__, __LINE__); - return NULL; - } - } - memset((void*)pixBuf, '\0', dx*dy*sizeof(fb_pixel_t)); - - if (type && radius) { - //setCornerFlags(type); - radius = limitRadius(dx, dy, radius); - - bool corner_tl = !!(type & CORNER_TOP_LEFT); - bool corner_tr = !!(type & CORNER_TOP_RIGHT); - bool corner_bl = !!(type & CORNER_BOTTOM_LEFT); - bool corner_br = !!(type & CORNER_BOTTOM_RIGHT); - - int line = 0; - while (line < dy) { - int ofl, ofr; - calcCorners(NULL, &ofl, &ofr, dy, line, radius, - corner_tl, corner_tr, corner_bl, corner_br); - if (dx-ofr-ofl < 1) { - if (dx-ofr-ofl == 0) { - dprintf(DEBUG_INFO, "[%s - %d]: radius %d, end x %d y %d\n", __func__, __LINE__, radius, dx-ofr-ofl, line); - } - else { - dprintf(DEBUG_INFO, "[%s - %04d]: Calculated width: %d\n (radius %d, dx %d, offsetLeft %d, offsetRight %d).\n Width can not be less than 0, abort.\n", - __func__, __LINE__, dx-ofr-ofl, radius, dx, ofl, ofr); - } - line++; - continue; - } - paintHLineRelInternal2Buf(ofl, dx-ofl-ofr, line, dx, col, pixBuf); - line++; - } - } else { - fb_pixel_t *bp = pixBuf; - int line = 0; - while (line < dy) { - for (int pos = 0; pos < dx; pos++) - *(bp + pos) = col; - bp += dx; - line++; - } - } - return pixBuf; -} - -fb_pixel_t* CFrameBuffer::paintBoxRel(const int x, const int y, const int dx, const int dy, - const fb_pixel_t /*col*/, gradientData_t *gradientData, - int radius, int type) -{ -#define MASK 0xFFFFFFFF - - fb_pixel_t* boxBuf = paintBoxRel2Buf(dx, dy, MASK, NULL, radius, type); - fb_pixel_t *bp = boxBuf; - fb_pixel_t *gra = gradientData->gradientBuf; - gradientData->boxBuf = boxBuf; - gradientData->x = x; - gradientData->dx = dx; - - if (gradientData->direction == gradientVertical) { - // vertical - for (int pos = 0; pos < dx; pos++) { - for(int count = 0; count < dy; count++) { - if (*(bp + pos) == MASK) - *(bp + pos) = (fb_pixel_t)(*(gra + count)); - bp += dx; - } - bp = boxBuf; - } - } else { - // horizontal - for (int line = 0; line < dy; line++) { - for (int pos = 0; pos < dx; pos++) { - if (*(bp + pos) == MASK) - *(bp + pos) = (fb_pixel_t)(*(gra + pos)); - } - bp += dx; - } - } - - if ((gradientData->mode & pbrg_noPaint) == pbrg_noPaint) - return boxBuf; - -// blit2FB(boxBuf, dx, dy, x, y); - blitBox2FB(boxBuf, dx, dy, x, y); - - if ((gradientData->mode & pbrg_noFree) == pbrg_noFree) - return boxBuf; - - cs_free_uncached(boxBuf); - - return NULL; -} - -void CFrameBuffer::paintBoxRel(const int x, const int y, const int dx, const int dy, const fb_pixel_t col, int radius, int type) -{ - /* draw a filled rectangle (with additional round corners) */ - if (!getActive()) - return; - - bool corner_tl = !!(type & CORNER_TOP_LEFT); - bool corner_tr = !!(type & CORNER_TOP_RIGHT); - bool corner_bl = !!(type & CORNER_BOTTOM_LEFT); - bool corner_br = !!(type & CORNER_BOTTOM_RIGHT); - - checkFbArea(x, y, dx, dy, true); - - if (!type || !radius) - { - accel->paintRect(x, y, dx, dy, col); - checkFbArea(x, y, dx, dy, false); - return; - } - - /* limit the radius */ - radius = limitRadius(dx, dy, radius); - if (radius < 1) /* dx or dy = 0... */ - radius = 1; /* avoid div by zero below */ - - int line = 0; - while (line < dy) { - int ofl, ofr; - if (calcCorners(NULL, &ofl, &ofr, dy, line, radius, - corner_tl, corner_tr, corner_bl, corner_br)) - { - int height = dy - ((corner_tl || corner_tr)?radius: 0 ) - ((corner_bl || corner_br) ? radius : 0); - accel->paintRect(x, y + line, dx, height, col); - line += height; - continue; - } - if (dx - ofr - ofl < 1) { - //printf("FB-NG::%s:%d x %d y %d dx %d dy %d l %d r %d\n", __func__, __LINE__, x,y,dx,dy, ofl, ofr); - line++; - continue; - } - accel->paintLine(x + ofl, y + line, x + dx - ofr, y + line, col); - line++; - } - checkFbArea(x, y, dx, dy, false); - accel->mark(x, y, x+dx, y+dy); -} - -void CFrameBuffer::paintPixel(const int x, const int y, const fb_pixel_t col) -{ - if (!getActive()) - return; - if (x > (int)xRes || y > (int)yRes || x < 0 || y < 0) - return; - - accel->paintPixel(x, y, col); -} - -void CFrameBuffer::paintLine(int xa, int ya, int xb, int yb, const fb_pixel_t col) -{ - if (!getActive()) - return; - - accel->paintLine(xa, ya, xb, yb, col); -} - -void CFrameBuffer::paintVLine(int x, int ya, int yb, const fb_pixel_t col) -{ - paintLine(x, ya, x, yb, col); -} - -void CFrameBuffer::paintVLineRel(int x, int y, int dy, const fb_pixel_t col) -{ - paintLine(x, y, x, y + dy, col); -} - -void CFrameBuffer::paintHLine(int xa, int xb, int y, const fb_pixel_t col) -{ - paintLine(xa, y, xb, y, col); -} - -void CFrameBuffer::paintHLineRel(int x, int dx, int y, const fb_pixel_t col) -{ - paintLine(x, y, x + dx, y, col); -} - -void CFrameBuffer::setIconBasePath(const std::string & iconPath) -{ - iconBasePath = iconPath; - if (!iconBasePath.empty() && '/' == *iconBasePath.rbegin()) /* .back() is only c++11 :-( */ - return; - iconBasePath += "/"; -} - -std::string CFrameBuffer::getIconPath(std::string icon_name, std::string file_type) -{ - std::string path, filetype; - filetype = "." + file_type; - path = std::string(ICONSDIR_VAR) + "/" + icon_name + filetype; - if (access(path.c_str(), F_OK)) - path = iconBasePath + "/" + icon_name + filetype; - if (icon_name.find("/", 0) != std::string::npos) - path = icon_name; - return path; -} - -void CFrameBuffer::getIconSize(const char * const filename, int* width, int *height) -{ - *width = 0; - *height = 0; - - if(filename == NULL) - return; - - std::map::iterator it; - - /* if code ask for size, lets cache it. assume we have enough ram for cache */ - /* FIXME offset seems never used in code, always default = 1 ? */ - - it = icon_cache.find(filename); - if(it == icon_cache.end()) { - if(paintIcon(filename, 0, 0, 0, 1, false)) { - it = icon_cache.find(filename); - } - } - if(it != icon_cache.end()) { - *width = it->second.width; - *height = it->second.height; - } -} - -bool CFrameBuffer::paintIcon8(const std::string & filename, const int x, const int y, const unsigned char offset) -{ - if (!getActive()) - return false; - -//printf("%s(file, %d, %d, %d)\n", __FUNCTION__, x, y, offset); - - struct rawHeader header; - uint16_t width, height; - int lfd; - - lfd = open((iconBasePath + filename).c_str(), O_RDONLY); - - if (lfd == -1) { - printf("paintIcon8: error while loading icon: %s%s\n", iconBasePath.c_str(), filename.c_str()); - return false; - } - - read(lfd, &header, sizeof(struct rawHeader)); - - width = (header.width_hi << 8) | header.width_lo; - height = (header.height_hi << 8) | header.height_lo; - - unsigned char pixbuf[768]; - - uint8_t * d = ((uint8_t *)getFrameBufferPointer()) + x * sizeof(fb_pixel_t) + stride * y; - fb_pixel_t * d2; - for (int count=0; countmark(x, y, x + width, y + height); - return true; -} - -/* paint icon at position x/y, - if height h is given, center vertically between y and y+h - offset is a color offset (probably only useful with palette) */ -bool CFrameBuffer::paintIcon(const std::string & filename, const int x, const int y, - const int h, const unsigned char offset, bool paint, bool paintBg, const fb_pixel_t colBg) -{ - struct rawHeader header; - int width, height; - int lfd; - fb_pixel_t * data; - struct rawIcon tmpIcon; - std::map::iterator it; - int dsize; - - if (!getActive()) - return false; - - int yy = y; - //printf("CFrameBuffer::paintIcon: load %s\n", filename.c_str());fflush(stdout); - - if (filename.empty()) - return false; /* nothing to do */ - /* we cache and check original name */ - it = icon_cache.find(filename); - if(it == icon_cache.end()) { - std::string newname = getIconPath(filename); - //printf("CFrameBuffer::paintIcon: check for %s\n", newname.c_str());fflush(stdout); - - data = g_PicViewer->getIcon(newname, &width, &height); - - if(data) { - dsize = width*height*sizeof(fb_pixel_t); - //printf("CFrameBuffer::paintIcon: %s found, data %x size %d x %d\n", newname.c_str(), data, width, height);fflush(stdout); - if(cache_size+dsize < ICON_CACHE_SIZE) { - cache_size += dsize; - tmpIcon.width = width; - tmpIcon.height = height; - tmpIcon.data = data; - icon_cache.insert(std::pair (filename, tmpIcon)); - //printf("Cached %s, cache size %d\n", newname.c_str(), cache_size); - } - goto _display; - } - - newname = getIconPath(filename, "raw"); - - lfd = open(newname.c_str(), O_RDONLY); - - if (lfd == -1) { - //printf("paintIcon: error while loading icon: %s\n", newname.c_str()); - return false; - } - read(lfd, &header, sizeof(struct rawHeader)); - - tmpIcon.width = width = (header.width_hi << 8) | header.width_lo; - tmpIcon.height = height = (header.height_hi << 8) | header.height_lo; - - dsize = width*height*sizeof(fb_pixel_t); - - tmpIcon.data = (fb_pixel_t*) cs_malloc_uncached(dsize); - data = tmpIcon.data; - - unsigned char pixbuf[768]; - for (int count = 0; count < height; count ++ ) { - read(lfd, &pixbuf[0], width >> 1 ); - unsigned char *pixpos = &pixbuf[0]; - for (int count2 = 0; count2 < width >> 1; count2 ++ ) { - unsigned char compressed = *pixpos; - unsigned char pix1 = (compressed & 0xf0) >> 4; - unsigned char pix2 = (compressed & 0x0f); - if (pix1 != header.transp) - *data++ = realcolor[pix1+offset]; - else - *data++ = 0; - if (pix2 != header.transp) - *data++ = realcolor[pix2+offset]; - else - *data++ = 0; - pixpos++; - } - } - close(lfd); - - data = tmpIcon.data; - - if(cache_size+dsize < ICON_CACHE_SIZE) { - cache_size += dsize; - icon_cache.insert(std::pair (filename, tmpIcon)); - //printf("Cached %s, cache size %d\n", newname.c_str(), cache_size); - } - } else { - data = it->second.data; - width = it->second.width; - height = it->second.height; - //printf("paintIcon: already cached %s %d x %d\n", newname.c_str(), width, height); - } -_display: - if(!paint) - return true; - - if (h != 0) - yy += (h - height) / 2; - - checkFbArea(x, yy, width, height, true); - if (paintBg) - paintBoxRel(x, yy, width, height, colBg); - blit2FB(data, width, height, x, yy); - checkFbArea(x, yy, width, height, false); - return true; - -} - -void CFrameBuffer::loadPal(const std::string & filename, const unsigned char offset, const unsigned char endidx) -{ - if (!getActive()) - return; - -//printf("%s()\n", __FUNCTION__); - - struct rgbData rgbdata; - int lfd; - - lfd = open((iconBasePath + filename).c_str(), O_RDONLY); - - if (lfd == -1) { - printf("error while loading palette: %s%s\n", iconBasePath.c_str(), filename.c_str()); - return; - } - - int pos = 0; - int readb = read(lfd, &rgbdata, sizeof(rgbdata) ); - while(readb) { - __u32 rgb = (rgbdata.r<<16) | (rgbdata.g<<8) | (rgbdata.b); - int colpos = offset+pos; - if( colpos>endidx) - break; - - paletteSetColor(colpos, rgb, 0xFF); - readb = read(lfd, &rgbdata, sizeof(rgbdata) ); - pos++; - } - paletteSet(&cmap); - close(lfd); -} - - -void CFrameBuffer::paintBoxFrame(const int sx, const int sy, const int dx, const int dy, const int px, const fb_pixel_t col, const int rad, int type) -{ - if (!getActive()) - return; - - int radius = rad; - bool corner_tl = !!(type & CORNER_TOP_LEFT); - bool corner_tr = !!(type & CORNER_TOP_RIGHT); - bool corner_bl = !!(type & CORNER_BOTTOM_LEFT); - bool corner_br = !!(type & CORNER_BOTTOM_RIGHT); - - int r_tl = 0, r_tr = 0, r_bl = 0, r_br = 0; - if (type && radius) { - int x_rad = radius - 1; - if (corner_tl) r_tl = x_rad; - if (corner_tr) r_tr = x_rad; - if (corner_bl) r_bl = x_rad; - if (corner_br) r_br = x_rad; - } - paintBoxRel(sx + r_tl, sy , dx - r_tl - r_tr, px, col); // top horizontal - paintBoxRel(sx + r_bl, sy + dy - px, dx - r_bl - r_br, px, col); // bottom horizontal - paintBoxRel(sx , sy + r_tl, px, dy - r_tl - r_bl, col); // left vertical - paintBoxRel(sx + dx - px, sy + r_tr, px, dy - r_tr - r_br, col); // right vertical - - if (!radius || !type) - return; - - radius = limitRadius(dx, dy, radius); - if (radius < 1) /* dx or dy = 0... */ - radius = 1; /* avoid div by zero below */ - int line = 0; - while (line < dy) { - int ofs = 0, ofs_i = 0; - // inner box - if ((line >= px) && (line < (dy - px))) - calcCorners(&ofs_i, NULL, NULL, dy - 2 * px, line - px, radius - px, - corner_tl, corner_tr, corner_bl, corner_br); - // outer box - calcCorners(&ofs, NULL, NULL, dy, line, radius, corner_tl, corner_tr, corner_bl, corner_br); - - int _y = sy + line; - if (line < px || line >= (dy - px)) { - // left - if ((corner_tl && line < radius) || (corner_bl && line >= dy - radius)) - accel->paintLine(sx + ofs, _y, sx + ofs + radius, _y, col); - // right - if ((corner_tr && line < radius) || (corner_br && line >= dy - radius)) - accel->paintLine(sx + dx - radius, _y, sx + dx - ofs, _y, col); - } - else if (line < (dy - px)) { - int _dx = (ofs_i - ofs) + px; - // left - if ((corner_tl && line < radius) || (corner_bl && line >= dy - radius)) - accel->paintLine(sx + ofs, _y, sx + ofs + _dx, _y, col); - // right - if ((corner_tr && line < radius) || (corner_br && line >= dy - radius)) - accel->paintLine(sx + dx - ofs_i - px, _y, sx + dx - ofs_i - px + _dx, _y, col); - } - if (line == radius && dy > 2 * radius) - // line outside the rounded corners - line = dy - radius; - else - line++; - } -} - -void CFrameBuffer::useBackground(bool ub) -{ - useBackgroundPaint = ub; - if(!useBackgroundPaint) { - delete[] background; - background=0; - } -} - -bool CFrameBuffer::getuseBackground(void) -{ - return useBackgroundPaint; -} - -void CFrameBuffer::saveBackgroundImage(void) -{ - if (backupBackground != NULL){ - delete[] backupBackground; - backupBackground = NULL; - } - backupBackground = background; - //useBackground(false); // <- necessary since no background is available - useBackgroundPaint = false; - background = NULL; -} - -void CFrameBuffer::restoreBackgroundImage(void) -{ - fb_pixel_t * tmp = background; - - if (backupBackground != NULL) - { - background = backupBackground; - backupBackground = NULL; - } - else - useBackground(false); // <- necessary since no background is available - - if (tmp != NULL){ - delete[] tmp; - tmp = NULL; - } -} - -void CFrameBuffer::paintBackgroundBoxRel(int x, int y, int dx, int dy) -{ - if (!getActive()) - return; - - if(!useBackgroundPaint) - { - /* paintBoxRel does its own checkFbArea() */ - paintBoxRel(x, y, dx, dy, backgroundColor); - } - else - { - checkFbArea(x, y, dx, dy, true); - uint8_t * fbpos = ((uint8_t *)getFrameBufferPointer()) + x * sizeof(fb_pixel_t) + stride * y; - fb_pixel_t * bkpos = background + x + BACKGROUNDIMAGEWIDTH * y; - for(int count = 0;count < dy; count++) - { - memmove(fbpos, bkpos, dx * sizeof(fb_pixel_t)); - fbpos += stride; - bkpos += BACKGROUNDIMAGEWIDTH; - } - checkFbArea(x, y, dx, dy, false); - accel->mark(x, y, x + dx, y + dy); - } -} - -void CFrameBuffer::paintBackground() -{ - if (!getActive()) - return; - - if (useBackgroundPaint && (background != NULL)) - { - checkFbArea(0, 0, xRes, yRes, true); - /* this does not really work anyway... */ - for (int i = 0; i < 576; i++) - memmove(((uint8_t *)getFrameBufferPointer()) + i * stride, (background + i * BACKGROUNDIMAGEWIDTH), BACKGROUNDIMAGEWIDTH * sizeof(fb_pixel_t)); - checkFbArea(0, 0, xRes, yRes, false); - accel->mark(0, 0, xRes, yRes); - } - else - { - paintBoxRel(0, 0, xRes, yRes, backgroundColor); - } -} - -void CFrameBuffer::SaveScreen(int x, int y, int dx, int dy, fb_pixel_t * const memp) -{ - if (!getActive() || memp == NULL) - return; - - checkFbArea(x, y, dx, dy, true); - uint8_t * pos = ((uint8_t *)getFrameBufferPointer()) + x * sizeof(fb_pixel_t) + stride * y; - fb_pixel_t * bkpos = memp; - for (int count = 0; count < dy; count++) { - fb_pixel_t * dest = (fb_pixel_t *)pos; - for (int i = 0; i < dx; i++) - *(bkpos++) = *(dest++); - pos += stride; - } -#if 0 - /* todo: check what the problem with this is, it should be better -- probably caching issue */ - uint8_t * fbpos = ((uint8_t *)getFrameBufferPointer()) + x * sizeof(fb_pixel_t) + stride * y; - fb_pixel_t * bkpos = memp; - for (int count = 0; count < dy; count++) - { - memmove(bkpos, fbpos, dx * sizeof(fb_pixel_t)); - fbpos += stride; - bkpos += dx; - } -#endif - checkFbArea(x, y, dx, dy, false); -} - -void CFrameBuffer::RestoreScreen(int x, int y, int dx, int dy, fb_pixel_t * const memp) -{ - if (!getActive() || memp == NULL) - return; - - checkFbArea(x, y, dx, dy, true); - uint8_t * fbpos = ((uint8_t *)getFrameBufferPointer()) + x * sizeof(fb_pixel_t) + stride * y; - fb_pixel_t * bkpos = memp; - for (int count = 0; count < dy; count++) - { - memmove(fbpos, bkpos, dx * sizeof(fb_pixel_t)); - fbpos += stride; - bkpos += dx; - } - accel->mark(x, y, x + dx, y + dy); - checkFbArea(x, y, dx, dy, false); -} - -void CFrameBuffer::Clear() -{ - paintBackground(); - //memset(getFrameBufferPointer(), 0, stride * yRes); -} - -bool CFrameBuffer::Lock() -{ - if(locked) - return false; - locked = true; - return true; -} - -void CFrameBuffer::Unlock() -{ - locked = false; -} - -void * CFrameBuffer::int_convertRGB2FB(unsigned char *rgbbuff, unsigned long x, unsigned long y, int transp, bool alpha) -{ - unsigned long i; - unsigned int *fbbuff; - unsigned long count = x * y; - - fbbuff = (unsigned int *) cs_malloc_uncached(count * sizeof(unsigned int)); - if(fbbuff == NULL) { - printf("convertRGB2FB%s: Error: cs_malloc_uncached\n", ((alpha) ? " (Alpha)" : "")); - return NULL; - } - - if (alpha) { - for(i = 0; i < count ; i++) - fbbuff[i] = ((rgbbuff[i*4+3] << 24) & 0xFF000000) | - ((rgbbuff[i*4] << 16) & 0x00FF0000) | - ((rgbbuff[i*4+1] << 8) & 0x0000FF00) | - ((rgbbuff[i*4+2]) & 0x000000FF); - } else { - switch (m_transparent) { - case CFrameBuffer::TM_BLACK: - for(i = 0; i < count ; i++) { - transp = 0; - if(rgbbuff[i*3] || rgbbuff[i*3+1] || rgbbuff[i*3+2]) - transp = 0xFF; - fbbuff[i] = (transp << 24) | ((rgbbuff[i*3] << 16) & 0xFF0000) | ((rgbbuff[i*3+1] << 8) & 0xFF00) | (rgbbuff[i*3+2] & 0xFF); - } - break; - case CFrameBuffer::TM_INI: - for(i = 0; i < count ; i++) - fbbuff[i] = (transp << 24) | ((rgbbuff[i*3] << 16) & 0xFF0000) | ((rgbbuff[i*3+1] << 8) & 0xFF00) | (rgbbuff[i*3+2] & 0xFF); - break; - case CFrameBuffer::TM_NONE: - default: - for(i = 0; i < count ; i++) - fbbuff[i] = 0xFF000000 | ((rgbbuff[i*3] << 16) & 0xFF0000) | ((rgbbuff[i*3+1] << 8) & 0xFF00) | (rgbbuff[i*3+2] & 0xFF); - break; - } - } - return (void *) fbbuff; -} - -void * CFrameBuffer::convertRGB2FB(unsigned char *rgbbuff, unsigned long x, unsigned long y, int transp) -{ - return int_convertRGB2FB(rgbbuff, x, y, transp, false); -} - -void * CFrameBuffer::convertRGBA2FB(unsigned char *rgbbuff, unsigned long x, unsigned long y) -{ - return int_convertRGB2FB(rgbbuff, x, y, 0, true); -} - -void CFrameBuffer::blit2FB(void *fbbuff, uint32_t width, uint32_t height, uint32_t xoff, uint32_t yoff, uint32_t xp, uint32_t yp, bool transp) -{ - accel->blit2FB(fbbuff, width, height, xoff, yoff, xp, yp, transp); -} - -void CFrameBuffer::blitBox2FB(const fb_pixel_t* boxBuf, uint32_t width, uint32_t height, uint32_t xoff, uint32_t yoff) -{ - checkFbArea(xoff, yoff, width, height, true); - - uint32_t swidth = stride / sizeof(fb_pixel_t); - fb_pixel_t *fbp = getFrameBufferPointer() + (swidth * yoff); - fb_pixel_t* data = (fb_pixel_t*)boxBuf; - - uint32_t line = 0; - while (line < height) { - fb_pixel_t *pixpos = &data[line * width]; - for (uint32_t pos = xoff; pos < xoff + width; pos++) { - //don't paint backgroundcolor (*pixpos = 0x00000000) - if (*pixpos) - *(fbp + pos) = *pixpos; - pixpos++; - } - fbp += swidth; - line++; - } - accel->mark(xoff, yoff, xoff + width, yoff + height); - - checkFbArea(xoff, yoff, width, height, false); -} - -void CFrameBuffer::displayRGB(unsigned char *rgbbuff, int x_size, int y_size, int x_pan, int y_pan, int x_offs, int y_offs, bool clearfb, int transp) -{ - void *fbbuff = NULL; - - if(rgbbuff == NULL) - return; - - /* correct panning */ - if(x_pan > x_size - (int)xRes) x_pan = 0; - if(y_pan > y_size - (int)yRes) y_pan = 0; - - /* correct offset */ - if(x_offs + x_size > (int)xRes) x_offs = 0; - if(y_offs + y_size > (int)yRes) y_offs = 0; - - /* blit buffer 2 fb */ - fbbuff = convertRGB2FB(rgbbuff, x_size, y_size, transp); - if(fbbuff==NULL) - return; - - /* ClearFB if image is smaller */ - /* if(x_size < (int)xRes || y_size < (int)yRes) */ - if(clearfb) - CFrameBuffer::getInstance()->Clear(); - - blit2FB(fbbuff, x_size, y_size, x_offs, y_offs, x_pan, y_pan); - cs_free_uncached(fbbuff); -} - -void CFrameBuffer::setFbArea(int element, int _x, int _y, int _dx, int _dy) -{ - if (_x == 0 && _y == 0 && _dx == 0 && _dy == 0) { - // delete area - for (fbarea_iterator_t it = v_fbarea.begin(); it != v_fbarea.end(); ++it) { - if (it->element == element) { - v_fbarea.erase(it); - break; - } - } - if (v_fbarea.empty()) { - fbAreaActiv = false; - } - } - else { - // change area - bool found = false; - for (unsigned int i = 0; i < v_fbarea.size(); i++) { - if (v_fbarea[i].element == element) { - v_fbarea[i].x = _x; - v_fbarea[i].y = _y; - v_fbarea[i].dx = _dx; - v_fbarea[i].dy = _dy; - found = true; - break; - } - } - // set new area - if (!found) { - fb_area_t area; - area.x = _x; - area.y = _y; - area.dx = _dx; - area.dy = _dy; - area.element = element; - v_fbarea.push_back(area); - } - fbAreaActiv = true; - } -} - -int CFrameBuffer::checkFbAreaElement(int _x, int _y, int _dx, int _dy, fb_area_t *area) -{ - if (fb_no_check) - return FB_PAINTAREA_MATCH_NO; - - if (_y > area->y + area->dy) - return FB_PAINTAREA_MATCH_NO; - if (_x + _dx < area->x) - return FB_PAINTAREA_MATCH_NO; - if (_x > area->x + area->dx) - return FB_PAINTAREA_MATCH_NO; - if (_y + _dy < area->y) - return FB_PAINTAREA_MATCH_NO; - return FB_PAINTAREA_MATCH_OK; -} - -bool CFrameBuffer::_checkFbArea(int _x, int _y, int _dx, int _dy, bool prev) -{ - if (v_fbarea.empty()) - return true; - - for (unsigned int i = 0; i < v_fbarea.size(); i++) { - int ret = checkFbAreaElement(_x, _y, _dx, _dy, &v_fbarea[i]); - if (ret == FB_PAINTAREA_MATCH_OK) { - switch (v_fbarea[i].element) { - case FB_PAINTAREA_MUTEICON1: - if (!do_paint_mute_icon) - break; - fb_no_check = true; - if (prev) - CAudioMute::getInstance()->hide(); - else - CAudioMute::getInstance()->paint(); - fb_no_check = false; - break; - default: - break; - } - } - } - - return true; -} - -/* TODO: can we get rid of that? */ -void CFrameBuffer::mark(int x, int y, int dx, int dy) -{ - accel->mark(x, y, dx, dy); -}; - -/* argh. really not the right thing to do here... */ -extern cVideo *videoDecoder; -void CFrameBuffer::showFrame(const std::string & filename) -{ - std::string picture = ICONSDIR_VAR + filename; - if (access(picture.c_str(), F_OK)) - picture = iconBasePath + filename; - if (filename.find("/", 0) != std::string::npos) - picture = filename; - - videoDecoder->ShowPicture(picture.c_str()); -} - -void CFrameBuffer::stopFrame() -{ - videoDecoder->StopPicture(); -} diff --git a/src/driver/framebuffer_ng.h b/src/driver/framebuffer_ng.h deleted file mode 100644 index bc091a4ad..000000000 --- a/src/driver/framebuffer_ng.h +++ /dev/null @@ -1,323 +0,0 @@ -/* - Neutrino-GUI - DBoxII-Project - - Copyright (C) 2001 Steffen Hehn 'McClean' - Homepage: http://dbox.cyberphoria.org/ - - Copyright (C) 2007-2015 Stefan Seyfried - - License: GPL - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - - -#ifndef __framebuffer_ng__ -#define __framebuffer_ng__ -#include - -#include -#include -#include - -#include -#include -#include - -#include - -#define fb_pixel_t uint32_t - -typedef struct fb_var_screeninfo t_fb_var_screeninfo; - -typedef struct gradientData_t -{ - fb_pixel_t* gradientBuf; - fb_pixel_t* boxBuf; - bool direction; - int mode; - int x; - int dx; -} gradientData_struct_t; - -#define CORNER_NONE 0x0 -#define CORNER_TOP_LEFT 0x1 -#define CORNER_TOP_RIGHT 0x2 -#define CORNER_TOP 0x3 -#define CORNER_BOTTOM_RIGHT 0x4 -#define CORNER_RIGHT 0x6 -#define CORNER_BOTTOM_LEFT 0x8 -#define CORNER_LEFT 0x9 -#define CORNER_BOTTOM 0xC -#define CORNER_ALL 0xF - -#define FADE_TIME 10000 -#define FADE_STEP 5 -#define FADE_RESET 0xFFFF - -#define WINDOW_SIZE_MAX 100 // % -#define WINDOW_SIZE_MIN 50 // % -#define WINDOW_SIZE_SMALL 80 // % -#define ConnectLineBox_Width 16 // px - -#if HAVE_GENERIC_HARDWARE -#define USE_OPENGL 1 -#endif - -class CFbAccel; -/** Ausfuehrung als Singleton */ -class CFrameBuffer : public sigc::trackable -{ - friend class CFbAccel; - private: - CFrameBuffer(); - - struct rgbData - { - uint8_t r; - uint8_t g; - uint8_t b; - } __attribute__ ((packed)); - - struct rawHeader - { - uint8_t width_lo; - uint8_t width_hi; - uint8_t height_lo; - uint8_t height_hi; - uint8_t transp; - } __attribute__ ((packed)); - - struct rawIcon - { - uint16_t width; - uint16_t height; - uint8_t transp; - fb_pixel_t * data; - }; - - std::string iconBasePath; - - int fd, tty; - fb_pixel_t * lfb; - int available; - fb_pixel_t * background; - fb_pixel_t * backupBackground; - fb_pixel_t backgroundColor; - std::string backgroundFilename; - bool useBackgroundPaint; - unsigned int xRes, yRes, stride, bpp; - t_fb_var_screeninfo screeninfo, oldscreen; - fb_cmap cmap; - __u16 red[256], green[256], blue[256], trans[256]; - - void paletteFade(int i, __u32 rgb1, __u32 rgb2, int level); - - int kd_mode; - struct vt_mode vt_mode; - bool active; - static void switch_signal (int); - fb_fix_screeninfo fix; - bool locked; - std::map icon_cache; - int cache_size; - void * int_convertRGB2FB(unsigned char *rgbbuff, unsigned long x, unsigned long y, int transp, bool alpha); - int m_transparent_default, m_transparent; - CFbAccel *accel; - - inline void paintHLineRelInternal2Buf(const int& x, const int& dx, const int& y, const int& box_dx, const fb_pixel_t& col, fb_pixel_t* buf); - void paintShortHLineRelInternal(const int& x, const int& dx, const int& y, const fb_pixel_t& col); -#if 0 - int limitRadius(const int& dx, const int& dy, int& radius); - void setCornerFlags(const int& type); -#endif - public: - fb_pixel_t realcolor[256]; - - ~CFrameBuffer(); - - static CFrameBuffer* getInstance(); -#ifdef USE_NEVIS_GXA - void setupGXA(void); -#endif - - void init(const char * const fbDevice = "/dev/fb0"); - int setMode(unsigned int xRes, unsigned int yRes, unsigned int bpp); - - enum { - gradientHorizontal, - gradientVertical - }; - - enum { - pbrg_noOption = 0x00, - pbrg_noPaint = 0x01, - pbrg_noFree = 0x02 - }; - - int getFileHandle() const; //only used for plugins (games) !! - t_fb_var_screeninfo *getScreenInfo(); - - fb_pixel_t * getFrameBufferPointer() const; // pointer to framebuffer - fb_pixel_t * getBackBufferPointer() const; // pointer to backbuffer - unsigned int getStride() const; // size of a single line in the framebuffer (in bytes) - unsigned int getScreenWidth(bool real = false); - unsigned int getScreenHeight(bool real = false); - unsigned int getWindowWidth(bool force_small = false); - unsigned int getWindowHeight(bool force_small = false); - unsigned int getScreenX(); - unsigned int getScreenY(); - - bool getActive() const; // is framebuffer active? - void setActive(bool enable); // is framebuffer active? - - void setTransparency( int tr = 0 ); - void setBlendMode(uint8_t mode = 1); - void setBlendLevel(int level); - - //Palette stuff - void setAlphaFade(int in, int num, int tr); - void paletteGenFade(int in, __u32 rgb1, __u32 rgb2, int num, int tr=0); - void paletteSetColor(int i, __u32 rgb, int tr); - void paletteSet(struct fb_cmap *map = NULL); - - //paint functions - inline void paintPixel(fb_pixel_t * const dest, const uint8_t color) const - { - *dest = realcolor[color]; - }; - void paintPixel(int x, int y, const fb_pixel_t col); - - fb_pixel_t* paintBoxRel2Buf(const int dx, const int dy, const fb_pixel_t col, fb_pixel_t* buf = NULL, int radius = 0, int type = CORNER_ALL); - fb_pixel_t* paintBoxRel(const int x, const int y, const int dx, const int dy, const fb_pixel_t col, gradientData_t *gradientData, int radius = 0, int type = CORNER_ALL); - - void paintBoxRel(const int x, const int y, const int dx, const int dy, const fb_pixel_t col, int radius = 0, int type = CORNER_ALL); - inline void paintBox(int xa, int ya, int xb, int yb, const fb_pixel_t col) { paintBoxRel(xa, ya, xb - xa, yb - ya, col); } - inline void paintBox(int xa, int ya, int xb, int yb, const fb_pixel_t col, int radius, int type) { paintBoxRel(xa, ya, xb - xa, yb - ya, col, radius, type); } - - void paintBoxFrame(const int x, const int y, const int dx, const int dy, const int px, const fb_pixel_t col, const int rad = 0, int type = CORNER_ALL); - void paintLine(int xa, int ya, int xb, int yb, const fb_pixel_t col); - - void paintVLine(int x, int ya, int yb, const fb_pixel_t col); - void paintVLineRel(int x, int y, int dy, const fb_pixel_t col); - - void paintHLine(int xa, int xb, int y, const fb_pixel_t col); - void paintHLineRel(int x, int dx, int y, const fb_pixel_t col); - - - void setIconBasePath(const std::string & iconPath); - std::string getIconBasePath(){return iconBasePath;}; - std::string getIconPath(std::string icon_name, std::string file_type = "png"); - - void getIconSize(const char * const filename, int* width, int *height); - /* h is the height of the target "window", if != 0 the icon gets centered in that window */ - bool paintIcon (const std::string & filename, const int x, const int y, - const int h = 0, const unsigned char offset = 1, bool paint = true, bool paintBg = false, const fb_pixel_t colBg = 0); - bool paintIcon8(const std::string & filename, const int x, const int y, const unsigned char offset = 0); - void loadPal (const std::string & filename, const unsigned char offset = 0, const unsigned char endidx = 255); - - bool loadPicture2Mem (const std::string & filename, fb_pixel_t * const memp); - bool loadPicture2FrameBuffer(const std::string & filename); - bool loadPictureToMem (const std::string & filename, const uint16_t width, const uint16_t height, const uint16_t stride, fb_pixel_t * const memp); - bool savePictureFromMem (const std::string & filename, const fb_pixel_t * const memp); - - int getBackgroundColor() { return backgroundColor;} - void setBackgroundColor(const fb_pixel_t color); - bool loadBackground(const std::string & filename, const unsigned char col = 0); - void useBackground(bool); - bool getuseBackground(void); - - void saveBackgroundImage(void); // <- implies useBackground(false); - void restoreBackgroundImage(void); - - void paintBackgroundBoxRel(int x, int y, int dx, int dy); - inline void paintBackgroundBox(int xa, int ya, int xb, int yb) { paintBackgroundBoxRel(xa, ya, xb - xa, yb - ya); } - - void paintBackground(); - - void SaveScreen(int x, int y, int dx, int dy, fb_pixel_t * const memp); - void RestoreScreen(int x, int y, int dx, int dy, fb_pixel_t * const memp); - - void Clear(); - void showFrame(const std::string & filename); - void stopFrame(); - bool loadBackgroundPic(const std::string & filename, bool show = true); - bool Lock(void); - void Unlock(void); - bool Locked(void) { return locked; }; - void waitForIdle(const char *func = NULL); - void* convertRGB2FB(unsigned char *rgbbuff, unsigned long x, unsigned long y, int transp = 0xFF); - void* convertRGBA2FB(unsigned char *rgbbuff, unsigned long x, unsigned long y); - void displayRGB(unsigned char *rgbbuff, int x_size, int y_size, int x_pan, int y_pan, int x_offs, int y_offs, bool clearfb = true, int transp = 0xFF); - void blit2FB(void *fbbuff, uint32_t width, uint32_t height, uint32_t xoff, uint32_t yoff, uint32_t xp = 0, uint32_t yp = 0, bool transp = false); - void blitBox2FB(const fb_pixel_t* boxBuf, uint32_t width, uint32_t height, uint32_t xoff, uint32_t yoff); - - void mark(int x, int y, int dx, int dy); - - enum - { - TM_EMPTY = 0, - TM_NONE = 1, - TM_BLACK = 2, - TM_INI = 3 - }; - void SetTransparent(int t){ m_transparent = t; } - void SetTransparentDefault(){ m_transparent = m_transparent_default; } - -// ## AudioMute / Clock ###################################### - private: - enum { - FB_PAINTAREA_MATCH_NO, - FB_PAINTAREA_MATCH_OK - }; - - typedef struct fb_area_t - { - int x; - int y; - int dx; - int dy; - int element; - } fb_area_struct_t; - - bool fbAreaActiv; - typedef std::vector v_fbarea_t; - typedef v_fbarea_t::iterator fbarea_iterator_t; - v_fbarea_t v_fbarea; - bool fb_no_check; - bool do_paint_mute_icon; - - bool _checkFbArea(int _x, int _y, int _dx, int _dy, bool prev); - int checkFbAreaElement(int _x, int _y, int _dx, int _dy, fb_area_t *area); - - public: - enum { - FB_PAINTAREA_INFOCLOCK, - FB_PAINTAREA_MUTEICON1, - FB_PAINTAREA_MUTEICON2, - - FB_PAINTAREA_MAX - }; - - inline bool checkFbArea(int _x, int _y, int _dx, int _dy, bool prev) { return (fbAreaActiv && !fb_no_check) ? _checkFbArea(_x, _y, _dx, _dy, prev) : true; } - - void setFbArea(int element, int _x=0, int _y=0, int _dx=0, int _dy=0); - void fbNoCheck(bool noCheck) { fb_no_check = noCheck; } - void doPaintMuteIcon(bool mode) { do_paint_mute_icon = mode; } - /* blit() is unnecessary, but here to avoid patches to the neutrino code */ - void blit(void) {} - sigc::signal OnAfterSetPallette; -}; - -#endif