summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/FbTk/ImageControl.cc59
-rw-r--r--src/FbTk/ImageControl.hh4
2 files changed, 40 insertions, 23 deletions
diff --git a/src/FbTk/ImageControl.cc b/src/FbTk/ImageControl.cc
index 0cb7fbe..6c2e3d6 100644
--- a/src/FbTk/ImageControl.cc
+++ b/src/FbTk/ImageControl.cc
@@ -22,7 +22,7 @@
22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23// DEALINGS IN THE SOFTWARE. 23// DEALINGS IN THE SOFTWARE.
24 24
25// $Id: ImageControl.cc,v 1.10 2004/01/03 01:12:10 fluxgen Exp $ 25// $Id: ImageControl.cc,v 1.11 2004/01/11 12:40:47 fluxgen Exp $
26 26
27#include "ImageControl.hh" 27#include "ImageControl.hh"
28 28
@@ -146,6 +146,7 @@ ImageControl::~ImageControl() {
146 } 146 }
147 147
148 } 148 }
149
149} 150}
150 151
151 152
@@ -167,19 +168,31 @@ Pixmap ImageControl::searchCache(unsigned int width, unsigned int height,
167 return None; 168 return None;
168 } 169 }
169 170
170 Cache tmp; 171 /* Cache tmp;
171 tmp.texture_pixmap = text.pixmap().drawable(); 172 tmp.texture_pixmap = text.pixmap().drawable();
172 tmp.width = width; 173 tmp.width = width;
173 tmp.height = height; 174 tmp.height = height;
174 tmp.texture = text.type(); 175 tmp.texture = text.type();
175 tmp.pixel1 = text.color().pixel(); 176 tmp.pixel1 = text.color().pixel();
176 tmp.pixel2 = text.colorTo().pixel(); 177 tmp.pixel2 = text.colorTo().pixel();
177 CacheList::iterator it = cache.find(&tmp); 178 */
178 if (it == cache.end()) { 179 CacheList::iterator it = cache.begin();
179 return None; 180 CacheList::iterator it_end = cache.end();
180 } else { 181 for (; it != it_end; ++it) {
181 (*it)->count++; 182 if (((*it)->width == width) &&
182 return (*it)->pixmap; 183 ((*it)->height == height) &&
184 ((*it)->texture == text.type()) &&
185 ((*it)->pixel1 == text.color().pixel())) {
186 if (text.type() & FbTk::Texture::GRADIENT) {
187 if ((*it)->pixel2 == text.colorTo().pixel()) {
188 (*it)->count++;
189 return (*it)->pixmap;
190 }
191 } else {
192 (*it)->count++;
193 return (*it)->pixmap;
194 }
195 }
183 } 196 }
184 197
185 return None; 198 return None;
@@ -221,7 +234,7 @@ Pixmap ImageControl::renderImage(unsigned int width, unsigned int height,
221 else 234 else
222 tmp->pixel2 = 0l; 235 tmp->pixel2 = 0l;
223 236
224 cache.insert(tmp); 237 cache.push_back(tmp);
225 238
226 if ((unsigned) cache.size() > cache_max) 239 if ((unsigned) cache.size() > cache_max)
227 cleanCache(); 240 cleanCache();
@@ -243,14 +256,15 @@ void ImageControl::removeImage(Pixmap pixmap) {
243 if ((*it)->pixmap == pixmap) { 256 if ((*it)->pixmap == pixmap) {
244 if ((*it)->count) { 257 if ((*it)->count) {
245 (*it)->count--; 258 (*it)->count--;
246 259 if (s_timed_cache) {
247 if (s_timed_cache)
248 cleanCache(); 260 cleanCache();
249 else if (! (*it)->count) 261 return;
250 cleanCache(); 262 }
251
252 } 263 }
253 264
265 if ((*it)->count <= 0)
266 cleanCache();
267
254 return; 268 return;
255 } 269 }
256 } 270 }
@@ -362,22 +376,25 @@ unsigned long ImageControl::getSqrt(unsigned int x) const {
362 376
363void ImageControl::cleanCache() { 377void ImageControl::cleanCache() {
364 Display *disp = FbTk::App::instance()->display(); 378 Display *disp = FbTk::App::instance()->display();
379 std::list<CacheList::iterator> deadlist;
365 CacheList::iterator it = cache.begin(); 380 CacheList::iterator it = cache.begin();
366 CacheList::iterator it_end = cache.end(); 381 CacheList::iterator it_end = cache.end();
367 for (; it != it_end; ++it) { 382 for (; it != it_end; ++it) {
368 Cache *tmp = (*it); 383 Cache *tmp = (*it);
369
370 if (tmp->count <= 0) { 384 if (tmp->count <= 0) {
371 CacheList::iterator tmp_it = it;
372 ++tmp_it;
373 XFreePixmap(disp, tmp->pixmap); 385 XFreePixmap(disp, tmp->pixmap);
374 cache.erase(it); 386 deadlist.push_back(it);
375 delete tmp; 387 delete tmp;
376 tmp=0; 388 tmp=0;
377 it = tmp_it; 389 }
378 if (it == it_end) break;
379 }
380 } 390 }
391
392 std::list<CacheList::iterator>::iterator dead_it = deadlist.begin();
393 std::list<CacheList::iterator>::iterator dead_it_end = deadlist.end();
394 for (; dead_it != dead_it_end; ++dead_it) {
395 cache.erase(*dead_it);
396 }
397
381} 398}
382 399
383void ImageControl::createColorTable() { 400void ImageControl::createColorTable() {
diff --git a/src/FbTk/ImageControl.hh b/src/FbTk/ImageControl.hh
index 087cd69..5a6a3a7 100644
--- a/src/FbTk/ImageControl.hh
+++ b/src/FbTk/ImageControl.hh
@@ -22,7 +22,7 @@
22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23// DEALINGS IN THE SOFTWARE. 23// DEALINGS IN THE SOFTWARE.
24 24
25// $Id: ImageControl.hh,v 1.8 2004/01/02 22:19:39 fluxgen Exp $ 25// $Id: ImageControl.hh,v 1.9 2004/01/11 12:40:47 fluxgen Exp $
26 26
27#ifndef FBTK_IMAGECONTROL_HH 27#ifndef FBTK_IMAGECONTROL_HH
28#define FBTK_IMAGECONTROL_HH 28#define FBTK_IMAGECONTROL_HH
@@ -127,7 +127,7 @@ private:
127 127
128 128
129 unsigned long cache_max; 129 unsigned long cache_max;
130 typedef std::set<Cache *, ltCacheEntry> CacheList; 130 typedef std::list<Cache *> CacheList;
131 131
132 mutable CacheList cache; 132 mutable CacheList cache;
133 static bool s_timed_cache; 133 static bool s_timed_cache;