drawing optimisations and fixes

This commit is contained in:
rathnor 2003-10-09 16:48:09 +00:00
parent 075dc35b5e
commit 018665d7a3
10 changed files with 138 additions and 101 deletions

View file

@ -1,5 +1,11 @@
(Format: Year/Month/Day) (Format: Year/Month/Day)
Changes for 0.9.6: Changes for 0.9.6:
*03/10/10:
* Various drawing-related optimisations and bug fixes (Simon)
- fixes toolbar random colour flicker on workspace change
- speeds up pixmap rendering a little (inlining and friends!)
FbWinFrame.cc GContext.hh/cc Color.hh ImageControl.hh/cc
IconbarTool.cc fluxbox.cc Container.cc
*03/10/08: *03/10/08:
* fluxbox-generate_menu update from Han * fluxbox-generate_menu update from Han
- replace getopts with portable workaround - replace getopts with portable workaround

View file

@ -20,7 +20,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: Container.cc,v 1.4 2003/09/15 20:13:24 fluxgen Exp $ // $Id: Container.cc,v 1.5 2003/10/09 16:48:09 rathnor Exp $
#include "FbTk/Button.hh" #include "FbTk/Button.hh"
#include "Container.hh" #include "Container.hh"
@ -128,6 +128,7 @@ void Container::removeItem(int index) {
void Container::removeAll() { void Container::removeAll() {
m_selected = 0; m_selected = 0;
m_item_list.clear(); m_item_list.clear();
if (!m_update_lock)
clear(); clear();
} }
@ -162,6 +163,7 @@ void Container::setSelected(int pos) {
} }
void Container::exposeEvent(XExposeEvent &event) { void Container::exposeEvent(XExposeEvent &event) {
if (!m_update_lock)
clearArea(event.x, event.y, event.width, event.height); clearArea(event.x, event.y, event.width, event.height);
} }

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: Color.hh,v 1.4 2003/05/10 13:29:13 fluxgen Exp $ // $Id: Color.hh,v 1.5 2003/10/09 16:48:09 rathnor Exp $
#ifndef FBTK_COLOR_HH #ifndef FBTK_COLOR_HH
#define FBTK_COLOR_HH #define FBTK_COLOR_HH
@ -49,11 +49,11 @@ public:
// TODO // TODO
//Color &operator = (const Color &col_copy); //Color &operator = (const Color &col_copy);
bool isAllocated() const { return m_allocated; } inline bool isAllocated() const { return m_allocated; }
unsigned short red() const { return m_red; } inline unsigned short red() const { return m_red; }
unsigned short green() const { return m_green; } inline unsigned short green() const { return m_green; }
unsigned short blue() const { return m_blue; } inline unsigned short blue() const { return m_blue; }
unsigned long pixel() const { return m_pixel; } inline unsigned long pixel() const { return m_pixel; }
private: private:
void free(); void free();

View file

@ -19,7 +19,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: GContext.cc,v 1.3 2003/09/11 19:57:38 fluxgen Exp $ // $Id: GContext.cc,v 1.4 2003/10/09 16:48:09 rathnor Exp $
#include "GContext.hh" #include "GContext.hh"
@ -32,74 +32,30 @@
namespace FbTk { namespace FbTk {
GContext::GContext(const FbTk::FbDrawable &drawable): GContext::GContext(const FbTk::FbDrawable &drawable):
m_gc(XCreateGC(FbTk::App::instance()->display(), m_display(FbTk::App::instance()->display()),
m_gc(XCreateGC(m_display,
drawable.drawable(), drawable.drawable(),
0, 0)) { 0, 0)) {
setGraphicsExposure(false); setGraphicsExposure(false);
} }
GContext::GContext(Drawable drawable): GContext::GContext(Drawable drawable):
m_gc(XCreateGC(FbTk::App::instance()->display(), m_display(FbTk::App::instance()->display()),
m_gc(XCreateGC(m_display,
drawable, drawable,
0, 0)) { 0, 0))
{
setGraphicsExposure(false); setGraphicsExposure(false);
} }
GContext::~GContext() { GContext::~GContext() {
if (m_gc) if (m_gc)
XFreeGC(FbTk::App::instance()->display(), m_gc); XFreeGC(m_display, m_gc);
}
void GContext::setForeground(const FbTk::Color &color) {
setForeground(color.pixel());
}
void GContext::setForeground(long pixel_value) {
XSetForeground(FbTk::App::instance()->display(), m_gc,
pixel_value);
}
void GContext::setBackground(const FbTk::Color &color) {
setBackground(color.pixel());
}
void GContext::setBackground(long pixel_value) {
XSetBackground(FbTk::App::instance()->display(), m_gc,
pixel_value);
} }
/// not implemented! /// not implemented!
void GContext::setFont(const FbTk::Font &font) { //void GContext::setFont(const FbTk::Font &font) {
//!! TODO //!! TODO
} //}
void GContext::setFont(int fid) {
XSetFont(FbTk::App::instance()->display(), m_gc, fid);
}
void GContext::setClipMask(const FbTk::FbPixmap &mask) {
XSetClipMask(FbTk::App::instance()->display(), m_gc,
mask.drawable());
}
void GContext::setClipOrigin(int x, int y) {
XSetClipOrigin(FbTk::App::instance()->display(), m_gc,
x, y);
}
void GContext::setGraphicsExposure(bool flag) {
XSetGraphicsExposures(FbTk::App::instance()->display(), m_gc,
flag);
}
void GContext::setFunction(int func) {
XSetFunction(FbTk::App::instance()->display(), m_gc,
func);
}
void GContext::setSubwindowMode(int mode) {
XSetSubwindowMode(FbTk::App::instance()->display(), m_gc,
mode);
}
} // end namespace FbTk } // end namespace FbTk

View file

@ -19,19 +19,20 @@
// 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: GContext.hh,v 1.3 2003/09/11 19:57:38 fluxgen Exp $ // $Id: GContext.hh,v 1.4 2003/10/09 16:48:09 rathnor Exp $
#ifndef FBTK_GCONTEXT_HH #ifndef FBTK_GCONTEXT_HH
#define FBTK_GCONTEXT_HH #define FBTK_GCONTEXT_HH
#include "Color.hh"
#include "FbPixmap.hh"
#include <X11/Xlib.h> #include <X11/Xlib.h>
namespace FbTk { namespace FbTk {
class FbDrawable; class FbDrawable;
class FbPixmap;
class Font; class Font;
class Color;
/// wrapper for X GC /// wrapper for X GC
class GContext { class GContext {
@ -43,23 +44,55 @@ public:
virtual ~GContext(); virtual ~GContext();
void setForeground(const FbTk::Color &color); inline void setForeground(const FbTk::Color &color) {
void setForeground(long pixel_value); setForeground(color.pixel());
void setBackground(const FbTk::Color &color); }
void setBackground(long pixel_value);
/// not implemented
void setFont(const FbTk::Font &font);
/// set font id
void setFont(int fid);
void setClipMask(const FbTk::FbPixmap &pm);
void setClipOrigin(int x, int y);
void setGraphicsExposure(bool value);
void setFunction(int func);
void setSubwindowMode(int mode);
GC gc() const { return m_gc; } inline void setForeground(long pixel_value) {
XSetForeground(m_display, m_gc,
pixel_value);
}
inline void setBackground(const FbTk::Color &color) {
setBackground(color.pixel());
}
inline void setBackground(long pixel_value) {
XSetBackground(m_display, m_gc, pixel_value);
}
/// not implemented
inline void setFont(const FbTk::Font &font) {}
/// set font id
inline void setFont(int fid) {
XSetFont(m_display, m_gc, fid);
}
inline void setClipMask(const FbTk::FbPixmap &mask) {
XSetClipMask(m_display, m_gc, mask.drawable());
}
inline void setClipOrigin(int x, int y) {
XSetClipOrigin(m_display, m_gc, x, y);
}
inline void setGraphicsExposure(bool value) {
XSetGraphicsExposures(m_display, m_gc, value);
}
inline void setFunction(int func) {
XSetFunction(m_display, m_gc, func);
}
inline void setSubwindowMode(int mode) {
XSetSubwindowMode(m_display, m_gc, mode);
}
inline GC gc() const { return m_gc; }
private: private:
Display *m_display; // worth caching
GC m_gc; GC m_gc;
}; };

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.5 2003/08/18 11:37:14 fluxgen Exp $ // $Id: ImageControl.cc,v 1.6 2003/10/09 16:48:09 rathnor Exp $
#include "ImageControl.hh" #include "ImageControl.hh"
@ -152,6 +152,21 @@ ImageControl::~ImageControl() {
Pixmap ImageControl::searchCache(unsigned int width, unsigned int height, Pixmap ImageControl::searchCache(unsigned int width, unsigned int height,
unsigned long texture_type, unsigned long texture_type,
const FbTk::Color &color, const FbTk::Color &color_to) const { const FbTk::Color &color, const FbTk::Color &color_to) const {
Cache tmp;
tmp.width = width;
tmp.height = height;
tmp.texture = texture_type;
tmp.pixel1 = color.pixel();
tmp.pixel2 = color_to.pixel();
CacheList::iterator it = cache.find(&tmp);
if (it == cache.end()) {
return None;
} else {
(*it)->count++;
return (*it)->pixmap;
}
/*
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) {
@ -170,8 +185,8 @@ Pixmap ImageControl::searchCache(unsigned int width, unsigned int height,
} }
} }
} }
return None; return None;
*/
} }
@ -208,7 +223,7 @@ Pixmap ImageControl::renderImage(unsigned int width, unsigned int height,
else else
tmp->pixel2 = 0l; tmp->pixel2 = 0l;
cache.push_back(tmp); cache.insert(tmp);
if ((unsigned) cache.size() > cache_max) if ((unsigned) cache.size() > cache_max)
cleanCache(); cleanCache();
@ -355,9 +370,13 @@ void ImageControl::cleanCache() {
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);
it = cache.erase(it); cache.erase(it);
delete tmp; delete tmp;
tmp=0;
it = tmp_it;
if (it == it_end) break; if (it == it_end) break;
} }
} }

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.4 2003/08/18 11:37:15 fluxgen Exp $ // $Id: ImageControl.hh,v 1.5 2003/10/09 16:48:09 rathnor Exp $
#ifndef FBTK_IMAGECONTROL_HH #ifndef FBTK_IMAGECONTROL_HH
#define FBTK_IMAGECONTROL_HH #define FBTK_IMAGECONTROL_HH
@ -34,6 +34,7 @@
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include <list> #include <list>
#include <set>
namespace FbTk { namespace FbTk {
@ -115,8 +116,24 @@ private:
unsigned long pixel1, pixel2, texture; unsigned long pixel1, pixel2, texture;
} Cache; } Cache;
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->pixel2 &&
(s1->texture & FbTk::Texture::GRADIENT) &&
s1->pixel2 < s2->pixel2)
));
}
};
unsigned long cache_max; unsigned long cache_max;
typedef std::list<Cache *> CacheList; typedef std::set<Cache *, ltCacheEntry> CacheList;
mutable CacheList cache; mutable CacheList cache;
static bool s_timed_cache; static bool s_timed_cache;

View file

@ -19,7 +19,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: FbWinFrame.cc,v 1.58 2003/10/06 09:28:35 rathnor Exp $ // $Id: FbWinFrame.cc,v 1.59 2003/10/09 16:48:09 rathnor Exp $
#include "FbWinFrame.hh" #include "FbWinFrame.hh"
@ -238,8 +238,8 @@ void FbWinFrame::setFocus(bool newvalue) {
m_focused = newvalue; m_focused = newvalue;
renderTitlebar();
renderButtons(); renderButtons();
renderTitlebar();
renderHandles(); renderHandles();
} }
@ -726,10 +726,10 @@ void FbWinFrame::redrawTitle() {
} }
if (isVisible()) { if (isVisible()) {
m_titlebar.clear();
m_titlebar.updateTransparent();
m_label.clear(); m_label.clear();
m_label.updateTransparent(); m_label.updateTransparent();
m_titlebar.clear();
m_titlebar.updateTransparent();
} }
} }
@ -1004,6 +1004,7 @@ void FbWinFrame::setupButton(FbTk::Button &btn) {
void FbWinFrame::render(const FbTk::Texture &tex, FbTk::Color &col, Pixmap &pm, void FbWinFrame::render(const FbTk::Texture &tex, FbTk::Color &col, Pixmap &pm,
unsigned int w, unsigned int h) { unsigned int w, unsigned int h) {
Pixmap tmp = pm; Pixmap tmp = pm;
if (tex.type() == (FbTk::Texture::FLAT | FbTk::Texture::SOLID)) { if (tex.type() == (FbTk::Texture::FLAT | FbTk::Texture::SOLID)) {
pm = None; pm = None;
@ -1051,6 +1052,7 @@ void FbWinFrame::getUnfocusPixmap(Pixmap &label_pm, Pixmap &title_pm,
} }
void FbWinFrame::renderLabelButtons() { void FbWinFrame::renderLabelButtons() {
Pixmap label_pm = 0; Pixmap label_pm = 0;
Pixmap not_used_pm = 0; Pixmap not_used_pm = 0;
FbTk::Color label_color; FbTk::Color label_color;
@ -1126,6 +1128,7 @@ void FbWinFrame::renderButtonFocus(FbTk::TextButton &button) {
} }
void FbWinFrame::renderButtonUnfocus(FbTk::TextButton &button) { void FbWinFrame::renderButtonUnfocus(FbTk::TextButton &button) {
button.setGC(theme().labelTextUnfocusGC()); button.setGC(theme().labelTextUnfocusGC());
button.setJustify(theme().justify()); button.setJustify(theme().justify());
button.setBorderWidth(1); button.setBorderWidth(1);

View file

@ -20,7 +20,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: IconbarTool.cc,v 1.13 2003/10/06 06:22:42 rathnor Exp $ // $Id: IconbarTool.cc,v 1.14 2003/10/09 16:48:09 rathnor Exp $
#include "IconbarTool.hh" #include "IconbarTool.hh"
@ -372,11 +372,11 @@ void IconbarTool::update(FbTk::Subject *subj) {
} }
// unlock container and update graphics // unlock container and update graphics
m_icon_container.setUpdateLock(false);
m_icon_container.showSubwindows();
m_icon_container.update();
renderTheme(); renderTheme();
m_icon_container.setUpdateLock(false);
m_icon_container.update();
m_icon_container.showSubwindows();
} }
void IconbarTool::renderWindow(FluxboxWindow &win) { void IconbarTool::renderWindow(FluxboxWindow &win) {

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: fluxbox.cc,v 1.197 2003/10/06 09:55:36 rathnor Exp $ // $Id: fluxbox.cc,v 1.198 2003/10/09 16:48:09 rathnor Exp $
#include "fluxbox.hh" #include "fluxbox.hh"
@ -614,10 +614,11 @@ Fluxbox::~Fluxbox() {
} }
void Fluxbox::eventLoop() { void Fluxbox::eventLoop() {
Display *disp = display();
while (!m_shutdown) { while (!m_shutdown) {
if (XPending(display())) { if (XPending(disp)) {
XEvent e; XEvent e;
XNextEvent(display(), &e); XNextEvent(disp, &e);
if (last_bad_window != None && e.xany.window == last_bad_window && if (last_bad_window != None && e.xany.window == last_bad_window &&
e.type != DestroyNotify) { // we must let the actual destroys through e.type != DestroyNotify) { // we must let the actual destroys through
@ -633,7 +634,7 @@ void Fluxbox::eventLoop() {
} }
} }
} else { } else {
FbTk::Timer::updateTimers(ConnectionNumber(display())); //handle all timers FbTk::Timer::updateTimers(ConnectionNumber(disp)); //handle all timers
} }
} }
} }