aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk
diff options
context:
space:
mode:
authorrathnor <rathnor>2003-10-09 16:48:09 (GMT)
committerrathnor <rathnor>2003-10-09 16:48:09 (GMT)
commit018665d7a3ae8cb642880176d415f57fc178c299 (patch)
tree05a21b11a9f28bd8b456e080be52148de30f5018 /src/FbTk
parent075dc35b5eeb875e971842e8230338395367e08f (diff)
downloadfluxbox-018665d7a3ae8cb642880176d415f57fc178c299.zip
fluxbox-018665d7a3ae8cb642880176d415f57fc178c299.tar.bz2
drawing optimisations and fixes
Diffstat (limited to 'src/FbTk')
-rw-r--r--src/FbTk/Color.hh12
-rw-r--r--src/FbTk/GContext.cc64
-rw-r--r--src/FbTk/GContext.hh63
-rw-r--r--src/FbTk/ImageControl.cc29
-rw-r--r--src/FbTk/ImageControl.hh21
5 files changed, 107 insertions, 82 deletions
diff --git a/src/FbTk/Color.hh b/src/FbTk/Color.hh
index f9c1600..b699dcc 100644
--- a/src/FbTk/Color.hh
+++ b/src/FbTk/Color.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: Color.hh,v 1.4 2003/05/10 13:29:13 fluxgen Exp $ 25// $Id: Color.hh,v 1.5 2003/10/09 16:48:09 rathnor Exp $
26 26
27#ifndef FBTK_COLOR_HH 27#ifndef FBTK_COLOR_HH
28#define FBTK_COLOR_HH 28#define FBTK_COLOR_HH
@@ -49,11 +49,11 @@ public:
49 // TODO 49 // TODO
50 //Color &operator = (const Color &col_copy); 50 //Color &operator = (const Color &col_copy);
51 51
52 bool isAllocated() const { return m_allocated; } 52 inline bool isAllocated() const { return m_allocated; }
53 unsigned short red() const { return m_red; } 53 inline unsigned short red() const { return m_red; }
54 unsigned short green() const { return m_green; } 54 inline unsigned short green() const { return m_green; }
55 unsigned short blue() const { return m_blue; } 55 inline unsigned short blue() const { return m_blue; }
56 unsigned long pixel() const { return m_pixel; } 56 inline unsigned long pixel() const { return m_pixel; }
57 57
58private: 58private:
59 void free(); 59 void free();
diff --git a/src/FbTk/GContext.cc b/src/FbTk/GContext.cc
index f3fcaf4..6b41726 100644
--- a/src/FbTk/GContext.cc
+++ b/src/FbTk/GContext.cc
@@ -19,7 +19,7 @@
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE. 20// DEALINGS IN THE SOFTWARE.
21 21
22// $Id: GContext.cc,v 1.3 2003/09/11 19:57:38 fluxgen Exp $ 22// $Id: GContext.cc,v 1.4 2003/10/09 16:48:09 rathnor Exp $
23 23
24#include "GContext.hh" 24#include "GContext.hh"
25 25
@@ -32,74 +32,30 @@
32namespace FbTk { 32namespace FbTk {
33 33
34GContext::GContext(const FbTk::FbDrawable &drawable): 34GContext::GContext(const FbTk::FbDrawable &drawable):
35 m_gc(XCreateGC(FbTk::App::instance()->display(), 35 m_display(FbTk::App::instance()->display()),
36 m_gc(XCreateGC(m_display,
36 drawable.drawable(), 37 drawable.drawable(),
37 0, 0)) { 38 0, 0)) {
38 setGraphicsExposure(false); 39 setGraphicsExposure(false);
39} 40}
40 41
41GContext::GContext(Drawable drawable): 42GContext::GContext(Drawable drawable):
42 m_gc(XCreateGC(FbTk::App::instance()->display(), 43 m_display(FbTk::App::instance()->display()),
44 m_gc(XCreateGC(m_display,
43 drawable, 45 drawable,
44 0, 0)) { 46 0, 0))
47{
45 setGraphicsExposure(false); 48 setGraphicsExposure(false);
46} 49}
47 50
48GContext::~GContext() { 51GContext::~GContext() {
49 if (m_gc) 52 if (m_gc)
50 XFreeGC(FbTk::App::instance()->display(), m_gc); 53 XFreeGC(m_display, m_gc);
51}
52
53void GContext::setForeground(const FbTk::Color &color) {
54 setForeground(color.pixel());
55}
56
57void GContext::setForeground(long pixel_value) {
58 XSetForeground(FbTk::App::instance()->display(), m_gc,
59 pixel_value);
60}
61
62void GContext::setBackground(const FbTk::Color &color) {
63 setBackground(color.pixel());
64}
65
66void GContext::setBackground(long pixel_value) {
67 XSetBackground(FbTk::App::instance()->display(), m_gc,
68 pixel_value);
69} 54}
70 55
71/// not implemented! 56/// not implemented!
72void GContext::setFont(const FbTk::Font &font) { 57//void GContext::setFont(const FbTk::Font &font) {
73 //!! TODO 58 //!! TODO
74} 59//}
75
76void GContext::setFont(int fid) {
77 XSetFont(FbTk::App::instance()->display(), m_gc, fid);
78}
79void GContext::setClipMask(const FbTk::FbPixmap &mask) {
80 XSetClipMask(FbTk::App::instance()->display(), m_gc,
81 mask.drawable());
82}
83
84void GContext::setClipOrigin(int x, int y) {
85 XSetClipOrigin(FbTk::App::instance()->display(), m_gc,
86 x, y);
87}
88
89void GContext::setGraphicsExposure(bool flag) {
90 XSetGraphicsExposures(FbTk::App::instance()->display(), m_gc,
91 flag);
92}
93
94void GContext::setFunction(int func) {
95 XSetFunction(FbTk::App::instance()->display(), m_gc,
96 func);
97}
98
99void GContext::setSubwindowMode(int mode) {
100 XSetSubwindowMode(FbTk::App::instance()->display(), m_gc,
101 mode);
102}
103
104 60
105} // end namespace FbTk 61} // end namespace FbTk
diff --git a/src/FbTk/GContext.hh b/src/FbTk/GContext.hh
index 6175b2d..c192879 100644
--- a/src/FbTk/GContext.hh
+++ b/src/FbTk/GContext.hh
@@ -19,19 +19,20 @@
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE. 20// DEALINGS IN THE SOFTWARE.
21 21
22// $Id: GContext.hh,v 1.3 2003/09/11 19:57:38 fluxgen Exp $ 22// $Id: GContext.hh,v 1.4 2003/10/09 16:48:09 rathnor Exp $
23 23
24#ifndef FBTK_GCONTEXT_HH 24#ifndef FBTK_GCONTEXT_HH
25#define FBTK_GCONTEXT_HH 25#define FBTK_GCONTEXT_HH
26 26
27#include "Color.hh"
28#include "FbPixmap.hh"
29
27#include <X11/Xlib.h> 30#include <X11/Xlib.h>
28 31
29namespace FbTk { 32namespace FbTk {
30 33
31class FbDrawable; 34class FbDrawable;
32class FbPixmap;
33class Font; 35class Font;
34class Color;
35 36
36/// wrapper for X GC 37/// wrapper for X GC
37class GContext { 38class GContext {
@@ -43,23 +44,55 @@ public:
43 44
44 virtual ~GContext(); 45 virtual ~GContext();
45 46
46 void setForeground(const FbTk::Color &color); 47 inline void setForeground(const FbTk::Color &color) {
47 void setForeground(long pixel_value); 48 setForeground(color.pixel());
48 void setBackground(const FbTk::Color &color); 49 }
49 void setBackground(long pixel_value); 50
51 inline void setForeground(long pixel_value) {
52 XSetForeground(m_display, m_gc,
53 pixel_value);
54 }
55
56 inline void setBackground(const FbTk::Color &color) {
57 setBackground(color.pixel());
58 }
59
60 inline void setBackground(long pixel_value) {
61 XSetBackground(m_display, m_gc, pixel_value);
62 }
63
50 /// not implemented 64 /// not implemented
51 void setFont(const FbTk::Font &font); 65 inline void setFont(const FbTk::Font &font) {}
66
52 /// set font id 67 /// set font id
53 void setFont(int fid); 68 inline void setFont(int fid) {
54 void setClipMask(const FbTk::FbPixmap &pm); 69 XSetFont(m_display, m_gc, fid);
55 void setClipOrigin(int x, int y); 70 }
56 void setGraphicsExposure(bool value); 71
57 void setFunction(int func); 72 inline void setClipMask(const FbTk::FbPixmap &mask) {
58 void setSubwindowMode(int mode); 73 XSetClipMask(m_display, m_gc, mask.drawable());
74 }
75
76 inline void setClipOrigin(int x, int y) {
77 XSetClipOrigin(m_display, m_gc, x, y);
78 }
79
80 inline void setGraphicsExposure(bool value) {
81 XSetGraphicsExposures(m_display, m_gc, value);
82 }
83
84 inline void setFunction(int func) {
85 XSetFunction(m_display, m_gc, func);
86 }
87
88 inline void setSubwindowMode(int mode) {
89 XSetSubwindowMode(m_display, m_gc, mode);
90 }
59 91
60 GC gc() const { return m_gc; } 92 inline GC gc() const { return m_gc; }
61 93
62private: 94private:
95 Display *m_display; // worth caching
63 GC m_gc; 96 GC m_gc;
64}; 97};
65 98
diff --git a/src/FbTk/ImageControl.cc b/src/FbTk/ImageControl.cc
index 915dc1c..2ceb106 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.5 2003/08/18 11:37:14 fluxgen Exp $ 25// $Id: ImageControl.cc,v 1.6 2003/10/09 16:48:09 rathnor Exp $
26 26
27#include "ImageControl.hh" 27#include "ImageControl.hh"
28 28
@@ -152,6 +152,21 @@ ImageControl::~ImageControl() {
152Pixmap ImageControl::searchCache(unsigned int width, unsigned int height, 152Pixmap ImageControl::searchCache(unsigned int width, unsigned int height,
153 unsigned long texture_type, 153 unsigned long texture_type,
154 const FbTk::Color &color, const FbTk::Color &color_to) const { 154 const FbTk::Color &color, const FbTk::Color &color_to) const {
155 Cache tmp;
156 tmp.width = width;
157 tmp.height = height;
158 tmp.texture = texture_type;
159 tmp.pixel1 = color.pixel();
160 tmp.pixel2 = color_to.pixel();
161 CacheList::iterator it = cache.find(&tmp);
162 if (it == cache.end()) {
163 return None;
164 } else {
165 (*it)->count++;
166 return (*it)->pixmap;
167 }
168
169 /*
155 CacheList::iterator it = cache.begin(); 170 CacheList::iterator it = cache.begin();
156 CacheList::iterator it_end = cache.end(); 171 CacheList::iterator it_end = cache.end();
157 for (; it != it_end; ++it) { 172 for (; it != it_end; ++it) {
@@ -170,8 +185,8 @@ Pixmap ImageControl::searchCache(unsigned int width, unsigned int height,
170 } 185 }
171 } 186 }
172 } 187 }
173
174 return None; 188 return None;
189 */
175} 190}
176 191
177 192
@@ -187,7 +202,7 @@ Pixmap ImageControl::renderImage(unsigned int width, unsigned int height,
187 if (pixmap) 202 if (pixmap)
188 return pixmap; // return cache item 203 return pixmap; // return cache item
189 204
190 // render new image 205 // render new image
191 TextureRender image(*this, width, height, m_colors, m_num_colors); 206 TextureRender image(*this, width, height, m_colors, m_num_colors);
192 pixmap = image.render(texture); 207 pixmap = image.render(texture);
193 208
@@ -208,7 +223,7 @@ Pixmap ImageControl::renderImage(unsigned int width, unsigned int height,
208 else 223 else
209 tmp->pixel2 = 0l; 224 tmp->pixel2 = 0l;
210 225
211 cache.push_back(tmp); 226 cache.insert(tmp);
212 227
213 if ((unsigned) cache.size() > cache_max) 228 if ((unsigned) cache.size() > cache_max)
214 cleanCache(); 229 cleanCache();
@@ -355,9 +370,13 @@ void ImageControl::cleanCache() {
355 Cache *tmp = (*it); 370 Cache *tmp = (*it);
356 371
357 if (tmp->count <= 0) { 372 if (tmp->count <= 0) {
373 CacheList::iterator tmp_it = it;
374 ++tmp_it;
358 XFreePixmap(disp, tmp->pixmap); 375 XFreePixmap(disp, tmp->pixmap);
359 it = cache.erase(it); 376 cache.erase(it);
360 delete tmp; 377 delete tmp;
378 tmp=0;
379 it = tmp_it;
361 if (it == it_end) break; 380 if (it == it_end) break;
362 } 381 }
363 } 382 }
diff --git a/src/FbTk/ImageControl.hh b/src/FbTk/ImageControl.hh
index c43c5a0..29c43d6 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.4 2003/08/18 11:37:15 fluxgen Exp $ 25// $Id: ImageControl.hh,v 1.5 2003/10/09 16:48:09 rathnor Exp $
26 26
27#ifndef FBTK_IMAGECONTROL_HH 27#ifndef FBTK_IMAGECONTROL_HH
28#define FBTK_IMAGECONTROL_HH 28#define FBTK_IMAGECONTROL_HH
@@ -34,6 +34,7 @@
34#include <X11/Xlib.h> 34#include <X11/Xlib.h>
35#include <X11/Xutil.h> 35#include <X11/Xutil.h>
36#include <list> 36#include <list>
37#include <set>
37 38
38namespace FbTk { 39namespace FbTk {
39 40
@@ -114,9 +115,25 @@ private:
114 unsigned int count, width, height; 115 unsigned int count, width, height;
115 unsigned long pixel1, pixel2, texture; 116 unsigned long pixel1, pixel2, texture;
116 } Cache; 117 } Cache;
118
119 struct ltCacheEntry
120 {
121 bool operator()(const Cache* s1, const Cache* s2) const
122 {
123 return
124 (s1->width < s2->width || s1->width == s2->width &&
125 (s1->height < s2->height || s1->height == s2->height &&
126 (s1->texture < s2->texture || s1->texture == s2->texture &&
127 s1->pixel1 < s2->pixel1 || s1->pixel1 == s2->pixel2 &&
128 (s1->texture & FbTk::Texture::GRADIENT) &&
129 s1->pixel2 < s2->pixel2)
130 ));
131 }
132 };
133
117 134
118 unsigned long cache_max; 135 unsigned long cache_max;
119 typedef std::list<Cache *> CacheList; 136 typedef std::set<Cache *, ltCacheEntry> CacheList;
120 137
121 mutable CacheList cache; 138 mutable CacheList cache;
122 static bool s_timed_cache; 139 static bool s_timed_cache;