Logo
  • Main Page
  • Related Pages
  • Modules
  • Classes
  • Files

mmsfbmanager.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005-2007 Stefan Schwarzer, Jens Schneider,             *
00003  *                           Matthias Hardt, Guido Madaus                  *
00004  *                                                                         *
00005  *   Copyright (C) 2007-2008 BerLinux Solutions GbR                        *
00006  *                           Stefan Schwarzer & Guido Madaus               *
00007  *                                                                         *
00008  *   Copyright (C) 2009-2013 BerLinux Solutions GmbH                       *
00009  *                                                                         *
00010  *   Authors:                                                              *
00011  *      Stefan Schwarzer   <stefan.schwarzer@diskohq.org>,                 *
00012  *      Matthias Hardt     <matthias.hardt@diskohq.org>,                   *
00013  *      Jens Schneider     <jens.schneider@diskohq.org>,                   *
00014  *      Guido Madaus       <guido.madaus@diskohq.org>,                     *
00015  *      Patrick Helterhoff <patrick.helterhoff@diskohq.org>,               *
00016  *      René Bählkow       <rene.baehlkow@diskohq.org>                     *
00017  *                                                                         *
00018  *   This library is free software; you can redistribute it and/or         *
00019  *   modify it under the terms of the GNU Lesser General Public            *
00020  *   License version 2.1 as published by the Free Software Foundation.     *
00021  *                                                                         *
00022  *   This library is distributed in the hope that it will be useful,       *
00023  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00024  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00025  *   Lesser General Public License for more details.                       *
00026  *                                                                         *
00027  *   You should have received a copy of the GNU Lesser General Public      *
00028  *   License along with this library; if not, write to the                 *
00029  *   Free Software Foundation, Inc.,                                       *
00030  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
00031  **************************************************************************/
00032 
00033 #include "mmsgui/mmsfbmanager.h"
00034 #include "mmsgui/fb/mmsfbsurfacemanager.h"
00035 #include <string.h>
00036 #include <stdlib.h>
00037 
00038 MMS_CREATEERROR(MMSFBManagerError);
00039 
00040 /* initialize the mmsfbmanager object */
00041 MMSFBManager mmsfbmanager;
00042 
00043 /* exit handler routine */
00044 void mmsfbmanager_onexit(int num, void *arg) {
00045     MMSFBManager *o=(MMSFBManager*)arg;
00046     o->release();
00047 }
00048 
00049 MMSFBManager::MMSFBManager() {
00050     // init me
00051     this->graphicslayer = NULL;
00052     this->videolayer = NULL;
00053     this->graphicslayerid = -1;
00054     this->videolayerid = -1;
00055     this->layercount = 0;
00056 }
00057 
00058 MMSFBManager::~MMSFBManager() {
00059 }
00060 
00061 bool MMSFBManager::init(int argc, char **argv, string appl_name, string appl_icon_name,
00062                         bool virtual_console, bool flip_flush) {
00063     int myargc=argc;
00064     char *myargv[255];
00065     int i;
00066 
00067     // save virtual console state
00068     this->virtual_console = virtual_console;
00069 
00070     // per default we have one layer
00071     this->layercount = 1;
00072 
00073     for(i=0;i<argc;i++)
00074         myargv[i]=strdup(argv[i]);
00075 
00076     DEBUGMSG("MMSGUI", "init mmsfb");
00077     bool ea = config.getExtendedAccel();
00078 #ifdef  __HAVE_DIRECTFB__
00079     if (config.getAllocMethod() == "DFB") {
00080         // use dfb even if extended accel
00081         ea = false;
00082     }
00083 #endif
00084 
00085     if (this->config.getRotateScreen() == 180) {
00086         // set rotate by 180° flag
00087         MMSFBBase_rotate180 = true;
00088     }
00089 
00090     // get layer settings from config
00091     MMSConfigDataLayer videolayer_conf = this->config.getVideoLayer();
00092     MMSConfigDataLayer graphicslayer_conf = this->config.getGraphicsLayer();
00093 
00094 #ifdef  __HAVE_DIRECTFB__
00095     if(videolayer_conf.outputtype == MMSFB_OT_X11) {
00096         myargv[myargc++] = strdup("--dfb:system=x11");
00097         char mode[24];
00098         snprintf(mode, 24, "--dfb:mode=%dx%d", graphicslayer_conf.rect.w, graphicslayer_conf.rect.h);
00099         myargv[myargc++] = strdup(mode);
00100     }
00101 #endif
00102 
00103     // init the MMSFB class
00104     if (!mmsfb->init(myargc, myargv, config.getBackend(), graphicslayer_conf.rect,
00105                      ea, config.getFullScreen(), config.getPointer(), appl_name, appl_icon_name, config.getHideApplication())) {
00106         DEBUGMSG("MMSGUI", "init mmsfb failed!");
00107         throw MMSFBManagerError(0, MMSFB_LastErrorString);
00108     }
00109 
00110     DEBUGMSG("MMSGUI", "get video layer");
00111     if (!mmsfb->getLayer(videolayer_conf.id, &this->videolayer, videolayer_conf.outputtype, this->virtual_console))
00112         throw MMSFBManagerError(0, MMSFB_LastErrorString);
00113 
00114     if (videolayer_conf.id == graphicslayer_conf.id) {
00115         DEBUGMSG("MMSGUI", "video layer and graphics layer are the same");
00116         this->graphicslayer = this->videolayer;
00117 
00118         if (!flip_flush)
00119             this->graphicslayer->setFlipFlags(MMSFB_FLIP_ONSYNC);
00120         else
00121             this->graphicslayer->setFlipFlags(MMSFB_FLIP_ONSYNC | MMSFB_FLIP_FLUSH);
00122     }
00123     else {
00124         this->layercount++;
00125         DEBUGMSG("MMSGUI", "get graphics layer");
00126         if (!mmsfb->getLayer(graphicslayer_conf.id, &this->graphicslayer, graphicslayer_conf.outputtype, false))
00127             throw MMSFBManagerError(0, MMSFB_LastErrorString);
00128 
00129         if (!flip_flush)
00130             this->graphicslayer->setFlipFlags(MMSFB_FLIP_ONSYNC);
00131         else
00132             this->graphicslayer->setFlipFlags(MMSFB_FLIP_ONSYNC | MMSFB_FLIP_FLUSH);
00133 
00134         if (videolayer_conf.outputtype == MMSFB_OT_MATROXFB)
00135             this->videolayer->setFlipFlags(MMSFB_FLIP_WAITFORSYNC);
00136         else
00137             this->videolayer->setFlipFlags(MMSFB_FLIP_ONSYNC);
00138     }
00139 
00140     if (!this->graphicslayer->getID(&this->graphicslayerid))
00141         throw MMSFBManagerError(0, MMSFB_LastErrorString);
00142 
00143     if (!this->videolayer->getID(&this->videolayerid))
00144         throw MMSFBManagerError(0, MMSFB_LastErrorString);
00145 
00146     /* set on exit handler */
00147     on_exit(mmsfbmanager_onexit, this);
00148 
00149     return true;
00150 }
00151 
00152 void MMSFBManager::release() {
00153     DEBUGMSG("MMSGUI", "release mmsfb");
00154     if (this->videolayer)
00155         delete this->videolayer;
00156     mmsfb->release();
00157 }
00158 
00159 void MMSFBManager::applySettings() {
00160     DEBUGMSG("MMSGUI", "configure graphics layer");
00161 
00162     // get layer settings from config
00163     MMSConfigDataLayer videolayer_conf = this->config.getVideoLayer();
00164     MMSConfigDataLayer graphicslayer_conf = this->config.getGraphicsLayer();
00165 
00166     // get the window pixelformat
00167     MMSFBSurfacePixelFormat window_pixelformat = config.getGraphicsWindowPixelformat();
00168     switch (window_pixelformat) {
00169     case MMSFB_PF_ARGB:
00170     case MMSFB_PF_AiRGB:
00171     case MMSFB_PF_AYUV:
00172     case MMSFB_PF_ARGB4444:
00173     case MMSFB_PF_RGB16:
00174         break;
00175     default:
00176         // window pixelformat not set or unsupported, use the layer pixelformat
00177         window_pixelformat = graphicslayer_conf.pixelformat;
00178         if (!isAlphaPixelFormat(window_pixelformat)) {
00179             // the gui internally needs surfaces with alpha channel
00180             // now we have to decide if we are working in RGB or YUV color space
00181             if (!isRGBPixelFormat(window_pixelformat))
00182                 // so switch all non-alpha pixelformats to AYUV
00183                 window_pixelformat = MMSFB_PF_AYUV;
00184             else
00185                 // so switch all non-alpha pixelformats to ARGB
00186                 window_pixelformat = MMSFB_PF_ARGB;
00187         }
00188         else
00189         if (isIndexedPixelFormat(window_pixelformat)) {
00190             // the gui internally needs non-indexed surfaces
00191             // so switch all indexed pixelformats to ARGB
00192             window_pixelformat = MMSFB_PF_ARGB;
00193         }
00194         break;
00195     }
00196 
00197     // get the surface pixelformat
00198     MMSFBSurfacePixelFormat surface_pixelformat = config.getGraphicsSurfacePixelformat();
00199     switch (surface_pixelformat) {
00200     case MMSFB_PF_ARGB:
00201     case MMSFB_PF_AiRGB:
00202     case MMSFB_PF_AYUV:
00203     case MMSFB_PF_ARGB4444:
00204     case MMSFB_PF_RGB16:
00205         break;
00206     default:
00207         // surface pixelformat not set or unsupported, use the layer pixelformat
00208         surface_pixelformat = graphicslayer_conf.pixelformat;
00209         if (!isAlphaPixelFormat(surface_pixelformat)) {
00210             // the gui internally needs surfaces with alpha channel
00211             // now we have to decide if we are working in RGB or YUV color space
00212             if (!isRGBPixelFormat(surface_pixelformat))
00213                 // so switch all non-alpha pixelformats to AYUV
00214                 surface_pixelformat = MMSFB_PF_AYUV;
00215             else
00216                 // so switch all non-alpha pixelformats to ARGB
00217                 surface_pixelformat = MMSFB_PF_ARGB;
00218         }
00219         else
00220         if (isIndexedPixelFormat(surface_pixelformat)) {
00221             // the gui internally needs non-indexed surfaces
00222             // so switch all indexed pixelformats to ARGB
00223             surface_pixelformat = MMSFB_PF_ARGB;
00224         }
00225         break;
00226     }
00227 
00228     // set exclusive access to the graphics layer
00229     DEBUGMSG("MMSGUI", "set exclusive access");
00230     if (!this->graphicslayer->setExclusiveAccess())
00231         throw MMSFBManagerError(0, MMSFB_LastErrorString);
00232 
00233     DEBUGMSG("MMSGUI", "set configuration");
00234     if(!this->graphicslayer->setConfiguration(graphicslayer_conf.rect.w, graphicslayer_conf.rect.h,
00235                                                graphicslayer_conf.pixelformat,
00236                                                graphicslayer_conf.buffermode,
00237                                                graphicslayer_conf.options,
00238                                                window_pixelformat,
00239                                                surface_pixelformat))
00240         throw MMSFBManagerError(0, MMSFB_LastErrorString);
00241 
00242     if (this->videolayerid != this->graphicslayerid) {
00243 #ifdef  __HAVE_DIRECTFB__
00244         if (config.getBackend() == MMSFB_BE_X11) {
00245             //give a little time to window routines
00246             usleep(300000);
00247         }
00248 #endif
00249 
00250         // use both layers
00251         DEBUGMSG("MMSGUI", "configure video layer");
00252 
00253         DEBUGMSG("MMSGUI", "set exclusive access");
00254         // set exclusive access to the video layer
00255         if (!this->videolayer->setExclusiveAccess())
00256             throw MMSFBManagerError(0, MMSFB_LastErrorString);
00257 
00258         DEBUGMSG("MMSGUI", "set configuration");
00259         // set video layer's config
00260         if (!this->videolayer->setConfiguration(videolayer_conf.rect.w, videolayer_conf.rect.h,
00261                                                 videolayer_conf.pixelformat,
00262                                                 videolayer_conf.buffermode,
00263                                                 videolayer_conf.options))
00264             throw MMSFBManagerError(0, MMSFB_LastErrorString);
00265         //this->videolayer->dfblayer->SetFieldParity(this->videolayer->dfblayer,0);
00266 
00267         // set the full opacity of the graphics layer
00268         this->graphicslayer->setOpacity(0);
00269 
00270         if (graphicslayer_conf.outputtype == MMSFB_OT_VIAFB) {
00271             // set the video layer behind the graphics layer
00272             DEBUGMSG("MMSGUI", "set the video layer behind the graphics layer");
00273             this->videolayer->setLevel(-1);
00274         }
00275         else
00276         if (graphicslayer_conf.outputtype == MMSFB_OT_XSHM) {
00277             DEBUGMSG("MMSGUI", "set the video layer behind the graphics layer");
00278             this->graphicslayer->setLevel(+1);
00279         }
00280     }
00281 
00282     // set global surface attributes
00283     string buffermode = graphicslayer_conf.buffermode;
00284     MMSFBSurface *gls;
00285     if (this->graphicslayer->getSurface(&gls, this->virtual_console)) {
00286         // set the static extended accel flag
00287         gls->setExtendedAcceleration(config.getExtendedAccel());
00288 
00289         // set the global alloc method (default is malloc)
00290         if (mmsfb->getBackend() == MMSFB_BE_DFB) {
00291 #ifdef  __HAVE_DIRECTFB__
00292             string am = config.getAllocMethod();
00293             if (am == "MALLOC") {
00294                 if (!config.getExtendedAccel())
00295                     gls->setAllocMethod(MMSFBSurfaceAllocMethod_dfb);
00296             }
00297             else
00298                 gls->setAllocMethod(MMSFBSurfaceAllocMethod_dfb);
00299 #endif
00300         }
00301         else
00302         if (graphicslayer_conf.outputtype == MMSFB_OT_OGL) {
00303             gls->setAllocMethod(MMSFBSurfaceAllocMethod_ogl);
00304         }
00305     }
00306 
00307     // init the mmsfbwindowmanager
00308     mmsfbwindowmanager->init(this->graphicslayer, (config.getPointer()==MMSFB_PM_TRUE));
00309 
00310     DEBUGMSG("MMSGUI", "creating temporary surface: %dx%d, %s", graphicslayer_conf.rect.w, graphicslayer_conf.rect.h, getMMSFBPixelFormatString(surface_pixelformat).c_str());
00311     mmsfbsurfacemanager->createTemporarySurface(graphicslayer_conf.rect.w, graphicslayer_conf.rect.h, surface_pixelformat, (buffermode == MMSFB_BM_BACKSYSTEM));
00312 }
00313 
00314 
00315 MMSFBLayer *MMSFBManager::getVideoLayer() {
00316     return this->videolayer;
00317 }
00318 
00319 MMSFBLayer *MMSFBManager::getGraphicsLayer() {
00320     return this->graphicslayer;
00321 }
00322 
00323 int MMSFBManager::getLayerCount() {
00324     return this->layercount;
00325 }
00326 

Generated by doxygen