From a5be2ef67d91f2cba7551e3a52a6b989c87e8611 Mon Sep 17 00:00:00 2001 From: fluxgen Date: Fri, 2 Jan 2004 22:19:39 +0000 Subject: textured pixmap cache fix --- src/FbTk/ImageControl.cc | 31 ++++++++++++++++++++++--------- src/FbTk/ImageControl.hh | 18 +++++++----------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/FbTk/ImageControl.cc b/src/FbTk/ImageControl.cc index 783f7a7..977d899 100644 --- a/src/FbTk/ImageControl.cc +++ b/src/FbTk/ImageControl.cc @@ -22,7 +22,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: ImageControl.cc,v 1.7 2004/01/02 13:28:00 fluxgen Exp $ +// $Id: ImageControl.cc,v 1.8 2004/01/02 22:19:39 fluxgen Exp $ #include "ImageControl.hh" @@ -150,15 +150,27 @@ ImageControl::~ImageControl() { Pixmap ImageControl::searchCache(unsigned int width, unsigned int height, - unsigned long texture_type, - const FbTk::Color &color, const FbTk::Color &color_to) const { + const Texture &text) const { + if (text.pixmap().drawable() != None) { + // do comparsion with width/height and texture_pixmap + CacheList::iterator it = cache.begin(); + CacheList::iterator it_end = cache.end(); + for (; it != it_end; ++it) { + if ((*it)->texture_pixmap = text.pixmap().drawable() && + (*it)->width == width && (*it)->height == height) + return (*it)->pixmap; + } + return None; + } + Cache tmp; + tmp.texture_pixmap = text.pixmap().drawable(); tmp.width = width; tmp.height = height; - tmp.texture = texture_type; - tmp.pixel1 = color.pixel(); - tmp.pixel2 = color_to.pixel(); + tmp.texture = text.type(); + tmp.pixel1 = text.color().pixel(); + tmp.pixel2 = text.colorTo().pixel(); CacheList::iterator it = cache.find(&tmp); if (it == cache.end()) { return None; @@ -179,10 +191,10 @@ Pixmap ImageControl::renderImage(unsigned int width, unsigned int height, return ParentRelative; // search cache first - Pixmap pixmap = searchCache(width, height, texture.type(), - texture.color(), texture.colorTo()); - if (pixmap) + Pixmap pixmap = searchCache(width, height, texture); + if (pixmap) { return pixmap; // return cache item + } // render new image TextureRender image(*this, width, height, m_colors, m_num_colors); @@ -194,6 +206,7 @@ Pixmap ImageControl::renderImage(unsigned int width, unsigned int height, Cache *tmp = new Cache; tmp->pixmap = pixmap; + tmp->texture_pixmap = texture.pixmap().drawable(); tmp->width = width; tmp->height = height; tmp->count = 1; diff --git a/src/FbTk/ImageControl.hh b/src/FbTk/ImageControl.hh index 0ccb928..087cd69 100644 --- a/src/FbTk/ImageControl.hh +++ b/src/FbTk/ImageControl.hh @@ -22,7 +22,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: ImageControl.hh,v 1.7 2004/01/02 13:27:29 fluxgen Exp $ +// $Id: ImageControl.hh,v 1.8 2004/01/02 22:19:39 fluxgen Exp $ #ifndef FBTK_IMAGECONTROL_HH #define FBTK_IMAGECONTROL_HH @@ -79,8 +79,7 @@ private: Search cache for a specific pixmap @return None if no cache was found */ - Pixmap searchCache(unsigned int width, unsigned int height, unsigned long texture_type, - const FbTk::Color &color, const FbTk::Color &color_to) const; + Pixmap searchCache(unsigned int width, unsigned int height, const Texture &text) const; void createColorTable(); bool m_dither; @@ -109,24 +108,21 @@ private: typedef struct Cache { Pixmap pixmap; - + Pixmap texture_pixmap; unsigned int count, width, height; unsigned long pixel1, pixel2, texture; } Cache; - struct ltCacheEntry - { - bool operator()(const Cache* s1, const Cache* s2) const - { - return - (s1->width < s2->width || s1->width == s2->width && + struct ltCacheEntry { + bool operator()(const Cache* s1, const Cache* s2) const { + return (s1->width < s2->width || s1->width == s2->width && (s1->height < s2->height || s1->height == s2->height && (s1->texture < s2->texture || s1->texture == s2->texture && s1->pixel1 < s2->pixel1 || s1->pixel1 == s2->pixel1 && (s1->texture & FbTk::Texture::GRADIENT) && s1->pixel2 < s2->pixel2) )); - } + } }; -- cgit v0.11.2