00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "mmsgui/fb/mmsfbsurfacemanager.h"
00034 #include "mmsgui/fb/mmsfb.h"
00035
00036
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
00051
00052
00053 MMSFBSurface *surface;
00054
00055 #if 0
00056
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
00063 this->free_surfaces.erase(this->free_surfaces.begin()+i);
00064
00065
00066
00067
00068
00069
00070 return surface;
00071 }
00072 else {
00073
00074 if (free_surfaces.at(i).insert_time < time(NULL) - 3) {
00075
00076
00077 surface->freeSurfaceBuffer();
00078 delete surface;
00079 this->free_surfaces.erase(this->free_surfaces.begin()+i);
00080 }
00081 }
00082 }
00083 #endif
00084
00085
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
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
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
00114
00115
00116
00117
00118 return surface;
00119 }
00120
00121 void MMSFBSurfaceManager::releaseSurface(MMSFBSurface *surface) {
00122
00123
00124
00125
00126
00127
00128
00129
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
00144 new_surface = new MMSFBSurface(NULL);
00145 if (!new_surface) {
00146 surface->freeSurfaceBuffer();
00147 return;
00148 }
00149
00150
00151 new_surface->llsurface = surface->llsurface;
00152 new_surface->config = surface->config;
00153
00154
00155 sml.surface = new_surface;
00156 sml.insert_time = time(NULL);
00157 this->free_surfaces.push_back(sml);
00158 #endif
00159
00160
00161
00162
00163
00164
00165
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