From a6b89367bf874913a4be2f0cdffb065840d7d934 Mon Sep 17 00:00:00 2001 From: seife Date: Sat, 25 Dec 2010 17:43:14 +0000 Subject: [PATCH] libtriple: implement init_td_api and shutdown_td_api provide compatibility with cs_api_init() and cs_api_exit() This contains a DirectFB wrapper, needed to make the framebuffer transparent. The framebuffer itself is usable without DFB. Additionally it sets up the system for a changed RC address in "BIOS". git-svn-id: file:///home/bas/coolstream_public_svn/THIRDPARTY/applications/neutrino-experimental@961 e54a6e83-5905-42d5-8d5c-058d10e6a962 --- configure.ac | 3 + lib/libtriple/Makefile.am | 3 +- lib/libtriple/init_td.cpp | 133 ++++++++++++++++++++++++++++++++++++++ lib/libtriple/init_td.h | 17 +++++ src/Makefile.am | 3 +- 5 files changed, 157 insertions(+), 2 deletions(-) create mode 100644 lib/libtriple/init_td.cpp create mode 100644 lib/libtriple/init_td.h diff --git a/configure.ac b/configure.ac index 13b4b18be..eb39ec37c 100644 --- a/configure.ac +++ b/configure.ac @@ -19,6 +19,9 @@ echo "BOXTYPE: $BOXTYPE" TUXBOX_APPS_LIB_PKGCONFIG(TUXBOX,tuxbox) fi fi +if test "$BOXTYPE" = "tripledragon"; then + TUXBOX_APPS_LIB_PKGCONFIG(DIRECTFB, directfb) +fi TUXBOX_APPS_LIB_CONFIG(CURL,curl-config) TUXBOX_APPS_LIB_CONFIG(FREETYPE,freetype-config) # TUXBOX_APPS_LIB_PKGCONFIG(OPENSSL,openssl) diff --git a/lib/libtriple/Makefile.am b/lib/libtriple/Makefile.am index 96560a21f..ee7d2b627 100644 --- a/lib/libtriple/Makefile.am +++ b/lib/libtriple/Makefile.am @@ -3,7 +3,8 @@ INCLUDES = \ -I$(top_srcdir)/lib \ -I$(top_srcdir)/src/zapit/include \ -I$(top_srcdir)/lib/connection \ - -I$(top_srcdir)/lib/libeventserver + -I$(top_srcdir)/lib/libeventserver \ + @DIRECTFB_CFLAGS@ noinst_LIBRARIES = libtriple.a diff --git a/lib/libtriple/init_td.cpp b/lib/libtriple/init_td.cpp new file mode 100644 index 000000000..d56714bf3 --- /dev/null +++ b/lib/libtriple/init_td.cpp @@ -0,0 +1,133 @@ +#include + +#include "init_td.h" +#include +#include +#include +#include +#include +#include + +#include + +extern "C" { +#include +#include +#include +} + +static const char * FILENAME = "init_td.cpp"; + +static bool initialized = false; + +/* the super interface */ +static IDirectFB *dfb; +/* the primary surface */ +static IDirectFBSurface *primary; +static IDirectFBSurface *dest; +static IDirectFBDisplayLayer *layer; + +#define DFBCHECK(x...) \ + err = x; \ + if (err != DFB_OK) { \ + fprintf(stderr, "%s <%d>:\n\t", __FILE__, __LINE__ ); \ + DirectFBErrorFatal(#x, err ); \ + } + +static void dfb_init() +{ + int argc = 0; + DFBResult err; + DFBSurfaceDescription dsc; + DFBSurfacePixelFormat pixelformat; + int SW, SH; + + DFBCHECK(DirectFBInit(&argc, NULL)); + /* neutrino does its own VT handling */ + DirectFBSetOption("no-vt-switch", NULL); + DirectFBSetOption("no-vt", NULL); + /* signal handling seems to interfere with neutrino */ + DirectFBSetOption("no-sighandler", NULL); + /* if DirectFB grabs the remote, neutrino does not get events */ + DirectFBSetOption("disable-module", "tdremote"); + DirectFBSetOption("disable-module", "keyboard"); + DirectFBSetOption("disable-module", "linux_input"); + DFBCHECK(DirectFBCreate(&dfb)); + + err = dfb->SetCooperativeLevel(dfb, DFSCL_FULLSCREEN); + if (err) + DirectFBError("Failed to get exclusive access", err); + + dsc.flags = DSDESC_CAPS; + dsc.caps = DSCAPS_PRIMARY; + + DFBCHECK(dfb->CreateSurface( dfb, &dsc, &primary )); + /* set pixel alpha mode */ + dfb->GetDisplayLayer(dfb, DLID_PRIMARY, &layer); + DFBCHECK(layer->SetCooperativeLevel(layer, DLSCL_EXCLUSIVE)); + DFBDisplayLayerConfig conf; + DFBCHECK(layer->GetConfiguration(layer, &conf)); + conf.flags = DLCONF_OPTIONS; + conf.options = (DFBDisplayLayerOptions)((conf.options & ~DLOP_OPACITY) | DLOP_ALPHACHANNEL); + DFBCHECK(layer->SetConfiguration(layer, &conf)); + + primary->GetPixelFormat(primary, &pixelformat); + primary->GetSize(primary, &SW, &SH); + primary->Clear(primary, 0, 0, 0, 0); + primary->GetSubSurface(primary, NULL, &dest); + dest->Clear(dest, 0, 0, 0, 0); +} + +static void dfb_deinit() +{ + dest->Release(dest); + primary->Release(primary); + layer->Release(layer); + dfb->Release(dfb); +} + +static void rc_init() +{ + /* set remote control address from bootloader config */ + int fd = open("/dev/stb/tdsystem", O_RDWR); + struct BIOS_CONFIG_AREA bca; + unsigned short rc_addr = 0xff; + if (ioctl(fd, IOC_AVS_GET_LOADERCONFIG, &bca) != 0) + fprintf(stderr, "%s: IOC_AVS_GET_LOADERCONFIG failed: %m\n", __FUNCTION__); + else + rc_addr = bca.ir_adrs; + close(fd); + fd = open("/dev/stb/tdremote", O_RDWR); + if (ioctl(fd, IOC_IR_SET_ADDRESS, rc_addr) < 0) + fprintf(stderr, "%s: IOC_IR_SET_ADDRESS %d failed: %m\n", __FUNCTION__, rc_addr); + /* short delay in the driver improves responsiveness and reduces spurious + "key up" events during zapping */ + //ioctl(fd, IOC_IR_SET_DELAY, 1); TODO: needs more work in rcinput + close(fd); + printf("%s: rc_addr=0x%02hx\n", __FUNCTION__, rc_addr); +} + +void init_td_api() +{ + fprintf(stderr, "%s:%s begin, initialized = %d\n", FILENAME, __FUNCTION__, (int)initialized); + if (!initialized) + { + /* DirectFB does setpgid(0,0), which disconnects us from controlling terminal + and thus disables e.g. ctrl-C. work around that. */ + pid_t pid = getpgid(0); + dfb_init(); + if (setpgid(0, pid)) + perror("setpgid"); + rc_init(); + } + initialized = true; + fprintf(stderr, "%s:%s end\n", FILENAME, __FUNCTION__); +} + +void shutdown_td_api() +{ + fprintf(stderr, "%s:%s, initialized = %d\n", FILENAME, __FUNCTION__, (int)initialized); + if (initialized) + dfb_deinit(); + initialized = false; +} diff --git a/lib/libtriple/init_td.h b/lib/libtriple/init_td.h new file mode 100644 index 000000000..a3a0314bc --- /dev/null +++ b/lib/libtriple/init_td.h @@ -0,0 +1,17 @@ +#ifndef __INIT_TD_H +#define __INIT_TD_H +void init_td_api(); +void shutdown_td_api(); + +inline void cs_api_init() +{ + init_td_api(); +}; + +inline void cs_api_exit() +{ + shutdown_td_api(); +}; +#define cs_malloc_uncached malloc +#define cs_free_uncached free +#endif diff --git a/src/Makefile.am b/src/Makefile.am index 8742fa375..81ce83fe6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -81,6 +81,7 @@ neutrino_LDADD += \ endif if BOXTYPE_TRIPLE neutrino_LDADD += \ - $(top_builddir)/lib/libtriple/libtriple.a + $(top_builddir)/lib/libtriple/libtriple.a \ + @DIRECTFB_LIBS@ endif