back to std list until we get std set working again

This commit is contained in:
fluxgen 2004-01-11 12:40:47 +00:00
parent d5b04d1fa0
commit 135579a9bf
2 changed files with 40 additions and 23 deletions

View file

@ -22,7 +22,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// $Id: ImageControl.cc,v 1.10 2004/01/03 01:12:10 fluxgen Exp $ // $Id: ImageControl.cc,v 1.11 2004/01/11 12:40:47 fluxgen Exp $
#include "ImageControl.hh" #include "ImageControl.hh"
@ -146,6 +146,7 @@ ImageControl::~ImageControl() {
} }
} }
} }
@ -167,19 +168,31 @@ Pixmap ImageControl::searchCache(unsigned int width, unsigned int height,
return None; return None;
} }
Cache tmp; /* Cache tmp;
tmp.texture_pixmap = text.pixmap().drawable(); tmp.texture_pixmap = text.pixmap().drawable();
tmp.width = width; tmp.width = width;
tmp.height = height; tmp.height = height;
tmp.texture = text.type(); tmp.texture = text.type();
tmp.pixel1 = text.color().pixel(); tmp.pixel1 = text.color().pixel();
tmp.pixel2 = text.colorTo().pixel(); tmp.pixel2 = text.colorTo().pixel();
CacheList::iterator it = cache.find(&tmp); */
if (it == cache.end()) { CacheList::iterator it = cache.begin();
return None; CacheList::iterator it_end = cache.end();
} else { for (; it != it_end; ++it) {
(*it)->count++; if (((*it)->width == width) &&
return (*it)->pixmap; ((*it)->height == height) &&
((*it)->texture == text.type()) &&
((*it)->pixel1 == text.color().pixel())) {
if (text.type() & FbTk::Texture::GRADIENT) {
if ((*it)->pixel2 == text.colorTo().pixel()) {
(*it)->count++;
return (*it)->pixmap;
}
} else {
(*it)->count++;
return (*it)->pixmap;
}
}
} }
return None; return None;
@ -221,7 +234,7 @@ Pixmap ImageControl::renderImage(unsigned int width, unsigned int height,
else else
tmp->pixel2 = 0l; tmp->pixel2 = 0l;
cache.insert(tmp); cache.push_back(tmp);
if ((unsigned) cache.size() > cache_max) if ((unsigned) cache.size() > cache_max)
cleanCache(); cleanCache();
@ -243,14 +256,15 @@ void ImageControl::removeImage(Pixmap pixmap) {
if ((*it)->pixmap == pixmap) { if ((*it)->pixmap == pixmap) {
if ((*it)->count) { if ((*it)->count) {
(*it)->count--; (*it)->count--;
if (s_timed_cache) {
if (s_timed_cache)
cleanCache(); cleanCache();
else if (! (*it)->count) return;
cleanCache(); }
} }
if ((*it)->count <= 0)
cleanCache();
return; return;
} }
} }
@ -362,22 +376,25 @@ unsigned long ImageControl::getSqrt(unsigned int x) const {
void ImageControl::cleanCache() { void ImageControl::cleanCache() {
Display *disp = FbTk::App::instance()->display(); Display *disp = FbTk::App::instance()->display();
std::list<CacheList::iterator> deadlist;
CacheList::iterator it = cache.begin(); CacheList::iterator it = cache.begin();
CacheList::iterator it_end = cache.end(); CacheList::iterator it_end = cache.end();
for (; it != it_end; ++it) { for (; it != it_end; ++it) {
Cache *tmp = (*it); Cache *tmp = (*it);
if (tmp->count <= 0) { if (tmp->count <= 0) {
CacheList::iterator tmp_it = it;
++tmp_it;
XFreePixmap(disp, tmp->pixmap); XFreePixmap(disp, tmp->pixmap);
cache.erase(it); deadlist.push_back(it);
delete tmp; delete tmp;
tmp=0; tmp=0;
it = tmp_it; }
if (it == it_end) break;
}
} }
std::list<CacheList::iterator>::iterator dead_it = deadlist.begin();
std::list<CacheList::iterator>::iterator dead_it_end = deadlist.end();
for (; dead_it != dead_it_end; ++dead_it) {
cache.erase(*dead_it);
}
} }
void ImageControl::createColorTable() { void ImageControl::createColorTable() {

View file

@ -22,7 +22,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// $Id: ImageControl.hh,v 1.8 2004/01/02 22:19:39 fluxgen Exp $ // $Id: ImageControl.hh,v 1.9 2004/01/11 12:40:47 fluxgen Exp $
#ifndef FBTK_IMAGECONTROL_HH #ifndef FBTK_IMAGECONTROL_HH
#define FBTK_IMAGECONTROL_HH #define FBTK_IMAGECONTROL_HH
@ -127,7 +127,7 @@ private:
unsigned long cache_max; unsigned long cache_max;
typedef std::set<Cache *, ltCacheEntry> CacheList; typedef std::list<Cache *> CacheList;
mutable CacheList cache; mutable CacheList cache;
static bool s_timed_cache; static bool s_timed_cache;