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

mmsfbsurfacemanager.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/fb/mmsfbsurfacemanager.h"
00034 #include "mmsgui/fb/mmsfb.h"
00035 
00036 /* initialize the mmsfbsurfacemanager object */
00037 MMSFBSurfaceManager *mmsfbsurfacemanager = new MMSFBSurfaceManager();
00038 
00039 MMSFBSurfaceManager::MMSFBSurfaceManager() {
00040     this->tempsuf = NULL;
00041     this->surface_mem_cnt = 0;
00042     pthread_mutex_init(&this->surface_mem_cnt_lock, NULL);
00043 }
00044 
00045 MMSFBSurfaceManager::~MMSFBSurfaceManager() {
00046     pthread_mutex_destroy(&this->surface_mem_cnt_lock);
00047 }
00048 
00049 MMSFBSurface *MMSFBSurfaceManager::createSurface(int w, int h, MMSFBSurfacePixelFormat pixelformat, int backbuffer, bool systemonly) {
00050 //    DFBResult               dfbres;
00051 //    IDirectFBSurface        *dfbsurface;
00052 //    DFBSurfaceDescription   surface_desc;
00053     MMSFBSurface            *surface;
00054 
00055 #if 0
00056     /* searching for free surface */
00057     for (unsigned int i = 0; i < this->free_surfaces.size(); i++) {
00058         surface = free_surfaces.at(i).surface;
00059         MMSFBSurfaceBuffer *sb = surface->config.surface_buffer;
00060         if   ((surface->config.w == w) && (surface->config.h == h)
00061             &&(sb->pixelformat == pixelformat) && (sb->backbuffer == backbuffer)) {
00062             /* found, return it */
00063             this->free_surfaces.erase(this->free_surfaces.begin()+i);
00064 /*TRACE
00065             this->used_surfaces.push_back(surface);
00066 */
00067 
00068 //DEBUGOUT("reuse surface=%d,%d\n", w,h);
00069 
00070             return surface;
00071         }
00072         else {
00073             // this surface is not the right one, check the timestamp
00074             if (free_surfaces.at(i).insert_time < time(NULL) - 3) {
00075                 // the surface is longer than 3 seconds in the free_surfaces list, remove it
00076                 // TODO: Rewrite memory handling while porting to PXA...
00077                 surface->freeSurfaceBuffer();
00078                 delete surface;
00079                 this->free_surfaces.erase(this->free_surfaces.begin()+i);
00080             }
00081         }
00082     }
00083 #endif
00084 
00085     /* create a new surface instance */
00086     surface = new MMSFBSurface(w, h, pixelformat, backbuffer, systemonly);
00087     if (!surface) {
00088         MMSFB_SetError(0, "cannot create new instance of MMSFBSurface");
00089         return NULL;
00090     }
00091     if (!surface->isInitialized()) {
00092         delete surface;
00093         surface = NULL;
00094         MMSFB_SetError(0, "cannot initialize MMSFBSurface");
00095         return NULL;
00096     }
00097 
00098     // get size of surface memory
00099     int size, bnum;
00100     surface->getMemSize(&size);
00101     surface->getNumberOfBuffers(&bnum);
00102     DEBUGMSG("MMSGUI", "New surface memory allocated: "
00103                             + iToStr(size) + " byte, "
00104                             + iToStr(bnum) + " buffer(s), "
00105                             + iToStr(size/(bnum)) + " byte for each buffer");
00106 
00107     // add size of the surface to my global counter
00108     pthread_mutex_lock(&this->surface_mem_cnt_lock);
00109     this->surface_mem_cnt+=size;
00110     pthread_mutex_unlock(&this->surface_mem_cnt_lock);
00111     DEBUGMSG("MMSGUI", "Sum of allocated surface memory: " + iToStr(this->surface_mem_cnt) + " byte");
00112 
00113     /* add to used surfaces */
00114 /* TRACE
00115     this->used_surfaces.push_back(surface);
00116 */
00117 
00118     return surface;
00119 }
00120 
00121 void MMSFBSurfaceManager::releaseSurface(MMSFBSurface *surface) {
00122 
00123        /* surface->dfbsurface->Release(surface->dfbsurface);
00124 return;*/
00125 
00126 
00127 
00128 //    MMSFBSurface        *new_surface;
00129 //    MMSFBSURMANLIST     sml;
00130 
00131     if (!surface)
00132         return;
00133 
00134     if (surface->config.islayersurface)
00135         return;
00136 
00137     if (surface->is_sub_surface)
00138         return;
00139 
00140     surface->freeSurfaceBuffer();
00141 
00142 #if 0
00143     /* create a new surface instance */
00144     new_surface = new MMSFBSurface(NULL);
00145     if (!new_surface) {
00146         surface->freeSurfaceBuffer();
00147         return;
00148     }
00149 
00150     /* set values to new surface */
00151     new_surface->llsurface = surface->llsurface;
00152     new_surface->config = surface->config;
00153 
00154     /* add to free surfaces */
00155     sml.surface = new_surface;
00156     sml.insert_time = time(NULL);
00157     this->free_surfaces.push_back(sml);
00158 #endif
00159     /* remove from used surfaces */
00160 /*TRACE
00161 
00162     for (unsigned int i = 0; i < this->used_surfaces.size(); i++) {
00163         if (used_surfaces.at(i) == surface) {
00164             this->used_surfaces.erase(this->used_surfaces.begin()+i);
00165             break;
00166         }
00167     }
00168 */
00169 }
00170 
00171 
00172 
00173 bool MMSFBSurfaceManager::createTemporarySurface(int w, int h, MMSFBSurfacePixelFormat pixelformat, bool systemonly) {
00174     if (!this->tempsuf)
00175         mmsfb->createSurface(&this->tempsuf, w, h, pixelformat, 0, systemonly);
00176     if (!this->tempsuf)
00177         return false;
00178     return true;
00179 }
00180 
00181 MMSFBSurface *MMSFBSurfaceManager::getTemporarySurface(int w, int h) {
00182     if (!this->tempsuf)
00183         return NULL;
00184     this->tempsuf->lock();
00185     int ww, hh;
00186     this->tempsuf->getSize(&ww, &hh);
00187     if ((ww>=w)&&(hh>=h))
00188         return this->tempsuf;
00189 
00190     DEBUGMSG("MMSGUI", "the temporary surface " + iToStr(ww) + "x" + iToStr(hh) + " is to small - requested size is "
00191                                              + iToStr(w) + "x" + iToStr(h));
00192     this->tempsuf->unlock();
00193     return NULL;
00194 }
00195 
00196 void MMSFBSurfaceManager::releaseTemporarySurface(MMSFBSurface *tempsuf) {
00197     if (tempsuf!=this->tempsuf)
00198         return;
00199     this->tempsuf->unlock();
00200 }
00201 

Generated by doxygen