put App::instance()->display() to FbDrawable::s_display to avoid too much

unnecessary calls
This commit is contained in:
akir 2004-09-10 15:46:08 +00:00
parent 631dfbbc63
commit a7967dfb25
5 changed files with 116 additions and 109 deletions

View file

@ -19,7 +19,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
// $Id: FbDrawable.cc,v 1.2 2003/09/06 15:39:06 fluxgen Exp $
// $Id: FbDrawable.cc,v 1.3 2004/09/10 15:46:08 akir Exp $
#include "FbDrawable.hh"
@ -27,13 +27,22 @@
namespace FbTk {
Display *FbDrawable::s_display = 0;
FbDrawable::FbDrawable() {
if (s_display == 0) {
s_display = FbTk::App::instance()->display();
}
}
void FbDrawable::copyArea(Drawable src, GC gc,
int src_x, int src_y,
int dest_x, int dest_y,
unsigned int width, unsigned int height) {
if (drawable() == 0 || src == 0 || gc == 0)
return;
XCopyArea(FbTk::App::instance()->display(),
XCopyArea(s_display,
src, drawable(), gc,
src_x, src_y,
width, height,
@ -44,7 +53,7 @@ void FbDrawable::fillRectangle(GC gc, int x, int y,
unsigned int width, unsigned int height) {
if (drawable() == 0 || gc == 0)
return;
XFillRectangle(FbTk::App::instance()->display(),
XFillRectangle(s_display,
drawable(), gc,
x, y,
width, height);
@ -54,7 +63,7 @@ void FbDrawable::drawRectangle(GC gc, int x, int y,
unsigned int width, unsigned int height) {
if (drawable() == 0 || gc == 0)
return;
XDrawRectangle(FbTk::App::instance()->display(),
XDrawRectangle(s_display,
drawable(), gc,
x, y,
width, height);
@ -64,7 +73,7 @@ void FbDrawable::drawLine(GC gc, int start_x, int start_y,
int end_x, int end_y) {
if (drawable() == 0 || gc == 0)
return;
XDrawLine(FbTk::App::instance()->display(),
XDrawLine(s_display,
drawable(),
gc,
start_x, start_y,
@ -75,7 +84,7 @@ void FbDrawable::fillPolygon(GC gc, XPoint *points, int npoints,
int shape, int mode) {
if (drawable() == 0 || gc == 0 || points == 0 || npoints == 0)
return;
XFillPolygon(FbTk::App::instance()->display(),
XFillPolygon(s_display,
drawable(), gc, points, npoints,
shape, mode);
}
@ -83,11 +92,11 @@ void FbDrawable::fillPolygon(GC gc, XPoint *points, int npoints,
void FbDrawable::drawPoint(GC gc, int x, int y) {
if (drawable() == 0 || gc == 0)
return;
XDrawPoint(FbTk::App::instance()->display(), drawable(), gc, x, y);
XDrawPoint(s_display, drawable(), gc, x, y);
}
XImage *FbDrawable::image(int x, int y, unsigned int width, unsigned int height) const {
return XGetImage(FbTk::App::instance()->display(), drawable(),
return XGetImage(s_display, drawable(),
x, y, width, height,
AllPlanes, // plane mask
ZPixmap);

View file

@ -19,7 +19,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
// $Id: FbDrawable.hh,v 1.4 2003/12/16 17:06:49 fluxgen Exp $
// $Id: FbDrawable.hh,v 1.5 2004/09/10 15:46:08 akir Exp $
#ifndef FBTK_FBDRAWABLE_HH
#define FBTK_FBDRAWABLE_HH
@ -30,6 +30,7 @@ namespace FbTk {
/// Basic drawing functions for X drawables
class FbDrawable {
public:
FbDrawable();
virtual ~FbDrawable() { }
virtual void copyArea(Drawable src, GC gc,
int src_x, int src_y,
@ -55,6 +56,8 @@ public:
virtual Drawable drawable() const = 0;
virtual unsigned int width() const = 0;
virtual unsigned int height() const = 0;
protected:
static Display *s_display; // display connection // display connection
};
} // end namespace FbTk

View file

@ -19,7 +19,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
// $Id: FbPixmap.cc,v 1.13 2004/09/09 14:29:10 akir Exp $
// $Id: FbPixmap.cc,v 1.14 2004/09/10 15:46:08 akir Exp $
#include "FbPixmap.hh"
#include "App.hh"
@ -33,12 +33,13 @@ using namespace std;
namespace FbTk {
FbPixmap::FbPixmap():m_pm(0),
m_width(0), m_height(0),
m_depth(0) { }
FbPixmap::FbPixmap(const FbPixmap &the_copy):m_pm(0),
m_width(0), m_height(0),
m_depth(0) {
}
FbPixmap::FbPixmap(const FbPixmap &the_copy):FbDrawable(), m_pm(0),
m_width(0), m_height(0),
m_depth(0){
copy(the_copy);
}
@ -89,7 +90,7 @@ FbPixmap &FbPixmap::operator = (Pixmap pm) {
Window root;
int x, y;
unsigned int border_width, bpp;
XGetGeometry(FbTk::App::instance()->display(),
XGetGeometry(s_display,
pm,
&root,
&x, &y,
@ -147,7 +148,7 @@ void FbPixmap::copy(Pixmap pm) {
unsigned int border_width, bpp;
unsigned int new_width, new_height;
XGetGeometry(FbTk::App::instance()->display(),
XGetGeometry(s_display,
pm,
&root,
&x, &y,
@ -157,24 +158,20 @@ void FbPixmap::copy(Pixmap pm) {
// create new pixmap and copy area
create(root, new_width, new_height, bpp);
Display *disp = FbTk::App::instance()->display();
GC gc = XCreateGC(s_display, drawable(), 0, 0);
GC gc = XCreateGC(disp, drawable(), 0, 0);
XCopyArea(disp, pm, drawable(), gc,
XCopyArea(s_display, pm, drawable(), gc,
0, 0,
width(), height(),
0, 0);
XFreeGC(disp, gc);
XFreeGC(s_display, gc);
}
void FbPixmap::rotate() {
Display *dpy = FbTk::App::instance()->display();
// make an image copy
XImage *src_image = XGetImage(dpy, drawable(),
XImage *src_image = XGetImage(s_display, drawable(),
0, 0, // pos
width(), height(), // size
~0, // plane mask
@ -185,11 +182,11 @@ void FbPixmap::rotate() {
GContext gc(drawable());
// copy new area
for (int y = 0; y < static_cast<signed>(height()); ++y) {
for (int x = 0; x < static_cast<signed>(width()); ++x) {
for (unsigned int y = 0; y < height(); ++y) {
for (unsigned int x = 0; x < width(); ++x) {
gc.setForeground(XGetPixel(src_image, x, y));
// revers coordinates
XDrawPoint(dpy, new_pm.drawable(), gc.gc(), y, x);
XDrawPoint(s_display, new_pm.drawable(), gc.gc(), y, x);
}
}
@ -209,9 +206,7 @@ void FbPixmap::scale(unsigned int dest_width, unsigned int dest_height) {
(dest_width == width() && dest_height == height()))
return;
Display *dpy = FbTk::App::instance()->display();
XImage *src_image = XGetImage(dpy, drawable(),
XImage *src_image = XGetImage(s_display, drawable(),
0, 0, // pos
width(), height(), // size
~0, // plane mask
@ -229,13 +224,13 @@ void FbPixmap::scale(unsigned int dest_width, unsigned int dest_height) {
// start scaling
float src_x = 0, src_y = 0;
for (int tx=0; tx < static_cast<signed>(dest_width); ++tx, src_x += zoom_x) {
for (unsigned int tx=0; tx < dest_width; ++tx, src_x += zoom_x) {
src_y = 0;
for (int ty=0; ty < static_cast<signed>(dest_height); ++ty, src_y += zoom_y) {
for (unsigned int ty=0; ty < dest_height; ++ty, src_y += zoom_y) {
gc.setForeground(XGetPixel(src_image,
static_cast<int>(src_x),
static_cast<int>(src_y)));
XDrawPoint(dpy, new_pm.drawable(), gc.gc(), tx, ty);
XDrawPoint(s_display, new_pm.drawable(), gc.gc(), tx, ty);
}
}
@ -288,44 +283,59 @@ Pixmap FbPixmap::release() {
Pixmap FbPixmap::getRootPixmap(int screen_num) {
Pixmap root_pm = 0;
// get root pixmap for transparency
Display *disp = FbTk::App::instance()->display();
Atom real_type;
int real_format;
unsigned long items_read, items_left;
unsigned int *data;
if (XGetWindowProperty(disp, RootWindow(disp, screen_num),
XInternAtom(disp, "_XROOTPMAP_ID", false),
0L, 1L,
false, XA_PIXMAP, &real_type,
&real_format, &items_read, &items_left,
unsigned int prop = 0;
static const char* prop_ids[] = {
"_XROOTPMAP_ID",
"_XSETROOT_ID",
0
};
static bool print_error = true; // print error_message only once
static const char* error_message = { "\n\n !!! WARNING WARNING WARNING WARNING !!!!!\n"
" if you experience problems with transparency:\n"
" you are using a wallpapersetter that \n"
" uses _XSETROOT_ID .. which we do not support.\n"
" consult 'fbsetbg -i' or try any other wallpapersetter\n"
" that uses _XROOTPMAP_ID !\n"
" !!! WARNING WARNING WARNING WARNING !!!!!!\n\n"
};
Pixmap root_pm = None;
for (prop = 0; prop_ids[prop]; prop++) {
if (XGetWindowProperty(s_display,
RootWindow(s_display, screen_num),
XInternAtom(s_display, prop_ids[prop], False),
0L, 4,
False, XA_PIXMAP,
&real_type, &real_format,
&items_read, &items_left,
(unsigned char **) &data) == Success &&
items_read) {
real_format == 32 && items_read == 1) {
if (strcmp(prop_ids[prop], "_XSETROOT_ID") == 0) {
if (print_error) {
fprintf(stderr, "%s", error_message);
print_error = false;
}
} else
root_pm = (Pixmap) (*data);
XFree(data);
/* TODO: analyze why this doesnt work
} else if (XGetWindowProperty(disp, RootWindow(disp, screen_num),
XInternAtom(disp, "_XSETROOT_ID", false),
0L, 1L,
false, XA_PIXMAP, &real_type,
&real_format, &items_read, &items_left,
(unsigned char **) &data) == Success &&
items_read) {
root_pm = (Pixmap) (*data);
XFree(data);
*/
break;
}
}
return root_pm;
}
void FbPixmap::free() {
if (m_pm != 0) {
XFreePixmap(FbTk::App::instance()->display(), m_pm);
XFreePixmap(s_display, m_pm);
m_pm = 0;
}
m_width = 0;
@ -339,7 +349,7 @@ void FbPixmap::create(Drawable src,
if (src == 0)
return;
m_pm = XCreatePixmap(FbTk::App::instance()->display(),
m_pm = XCreatePixmap(s_display,
src, width, height, depth);
if (m_pm == 0)
return;

View file

@ -19,7 +19,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
// $Id: FbWindow.cc,v 1.38 2004/09/09 14:29:10 akir Exp $
// $Id: FbWindow.cc,v 1.39 2004/09/10 15:46:08 akir Exp $
#include "FbWindow.hh"
#include "FbPixmap.hh"
@ -44,14 +44,10 @@
namespace FbTk {
Display *FbWindow::s_display = 0;
FbWindow::FbWindow():m_parent(0), m_screen_num(0), m_window(0), m_x(0), m_y(0),
FbWindow::FbWindow():FbDrawable(), m_parent(0), m_screen_num(0), m_window(0), m_x(0), m_y(0),
m_width(0), m_height(0), m_border_width(0), m_depth(0), m_destroy(true),
m_buffer_pm(0) {
m_buffer_pm(0){
if (s_display == 0)
s_display = App::instance()->display();
}
FbWindow::FbWindow(const FbWindow& the_copy):m_parent(the_copy.parent()),
@ -61,9 +57,6 @@ FbWindow::FbWindow(const FbWindow& the_copy):m_parent(the_copy.parent()),
m_border_width(the_copy.borderWidth()),
m_depth(the_copy.depth()), m_destroy(true),
m_buffer_pm(0) {
if (s_display == 0)
s_display = App::instance()->display();
the_copy.m_window = 0;
}
@ -75,12 +68,13 @@ FbWindow::FbWindow(int screen_num,
bool save_unders,
int depth,
int class_type):
FbDrawable(),
m_parent(0),
m_screen_num(screen_num),
m_destroy(true),
m_buffer_pm(0) {
create(RootWindow(FbTk::App::instance()->display(), screen_num),
create(RootWindow(s_display, screen_num),
x, y, width, height, eventmask,
override_redirect, save_unders, depth, class_type);
};
@ -102,7 +96,7 @@ FbWindow::FbWindow(const FbWindow &parent,
};
FbWindow::FbWindow(Window client):m_parent(0),
FbWindow::FbWindow(Window client):FbDrawable(), m_parent(0),
m_screen_num(0),
m_window(0),
m_x(0), m_y(0),
@ -112,9 +106,6 @@ FbWindow::FbWindow(Window client):m_parent(0),
m_destroy(false), // don't destroy this window
m_buffer_pm(0) {
if (s_display == 0)
s_display = App::instance()->display();
setNew(client);
}
@ -258,8 +249,6 @@ FbWindow &FbWindow::operator = (Window win) {
}
void FbWindow::setNew(Window win) {
if (s_display == 0)
s_display = App::instance()->display();
if (m_window != 0 && m_destroy)
XDestroyWindow(s_display, m_window);
@ -423,9 +412,6 @@ void FbWindow::create(Window parent, int x, int y,
bool save_unders, int depth, int class_type) {
if (s_display == 0)
s_display = FbTk::App::instance()->display();
m_border_width = 0;
long valmask = CWEventMask;

View file

@ -19,7 +19,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
// $Id: FbWindow.hh,v 1.32 2004/06/13 00:32:40 fluxgen Exp $
// $Id: FbWindow.hh,v 1.33 2004/09/10 15:46:08 akir Exp $
#ifndef FBTK_FBWINDOW_HH
#define FBTK_FBWINDOW_HH
@ -179,7 +179,6 @@ private:
bool save_unders,
int depth,
int class_type);
static Display *s_display; ///< display connection
const FbWindow *m_parent; ///< parent FbWindow
int m_screen_num; ///< screen num on which this window exist
mutable Window m_window; ///< the X window