From 72c40bc7007f6a549d178c97f8aa120704d48ddf Mon Sep 17 00:00:00 2001 From: John Spray Date: Mon, 13 Feb 2006 19:36:10 +0000 Subject: [PATCH] Try to make GPainter a bit more efficient git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13230 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/gtk/ChangeLog | 2 ++ src/frontends/gtk/GPainter.C | 63 ++++++++++++++++++++---------------- src/frontends/gtk/GPainter.h | 13 ++++++-- 3 files changed, 48 insertions(+), 30 deletions(-) diff --git a/src/frontends/gtk/ChangeLog b/src/frontends/gtk/ChangeLog index e840f30c46..3bca6b93a0 100644 --- a/src/frontends/gtk/ChangeLog +++ b/src/frontends/gtk/ChangeLog @@ -6,6 +6,8 @@ mangling some more complicated font names. * lyx_gui.C: use Gtk::Main instead of while() loop: fix eating CPU even when idle + * GPainter.[Ch]: some futile attempts to make painting + faster by diminishing function overhead. 2006-02-12 John Spray * GMenubar.C: assume backend strings in latin1 (bug 1954) diff --git a/src/frontends/gtk/GPainter.C b/src/frontends/gtk/GPainter.C index 61c3f29a1f..766742d5dd 100644 --- a/src/frontends/gtk/GPainter.C +++ b/src/frontends/gtk/GPainter.C @@ -55,7 +55,7 @@ namespace lyx { namespace frontend { GPainter::GPainter(GWorkArea & xwa) - : Painter(), owner_(xwa) + : Painter(), owner_(xwa), currentcolor_(LColor::magenta) { } @@ -72,15 +72,25 @@ int GPainter::paperHeight() const } -void GPainter::setForeground(Glib::RefPtr gc, LColor_color clr) +inline void GPainter::setForeground(LColor_color clr) { - Gdk::Color * gclr = owner_.getColorHandler().getGdkColor(clr); - gc->set_foreground(*gclr); + if (clr != currentcolor_) { + gc_->set_foreground(*(colorhandler_->getGdkColor(clr))); + currentcolor_ = clr; + } +} + + +void GPainter::start() +{ + pixmap_ = owner_.getPixmap(); + colorhandler_ = &(owner_.getColorHandler()); + gc_ = owner_.getGC(); + gc_->set_foreground(*(colorhandler_->getGdkColor(currentcolor_))); } -void GPainter::setLineParam(Glib::RefPtr gc, - line_style ls, line_width lw) +inline void GPainter::setLineParam(line_style ls, line_width lw) { int width = 0; switch (lw) { @@ -101,15 +111,15 @@ void GPainter::setLineParam(Glib::RefPtr gc, style = Gdk::LINE_ON_OFF_DASH; break; } - gc->set_line_attributes(width, style, + gc_->set_line_attributes(width, style, Gdk::CAP_NOT_LAST, Gdk::JOIN_MITER); } void GPainter::point(int x, int y, LColor_color c) { - setForeground(owner_.getGC(), c); - owner_.getPixmap()->draw_point(owner_.getGC(), x, y); + setForeground(c); + pixmap_->draw_point(gc_, x, y); } @@ -119,9 +129,9 @@ void GPainter::line(int x1, int y1, line_style ls, line_width lw) { - setForeground(owner_.getGC(), col); - setLineParam(owner_.getGC(), ls, lw); - owner_.getPixmap()->draw_line(owner_.getGC(), x1, y1, x2, y2); + setForeground(col); + setLineParam(ls, lw); + pixmap_->draw_line(gc_, x1, y1, x2, y2); } @@ -130,15 +140,15 @@ void GPainter::lines(int const * xp, int const * yp, int np, line_style ls, line_width lw) { - setForeground(owner_.getGC(), col); - setLineParam(owner_.getGC(), ls, lw); + setForeground(col); + setLineParam(ls, lw); std::vector points(np); for (int i = 0; i < np; ++i) { points[i].set_x(xp[i]); points[i].set_y(yp[i]); } - owner_.getPixmap()->draw_lines(owner_.getGC(), points); + pixmap_->draw_lines(gc_, points); } @@ -147,39 +157,39 @@ void GPainter::rectangle(int x, int y, int w, int h, line_style ls, line_width lw) { - setForeground(owner_.getGC(), col); - setLineParam(owner_.getGC(), ls, lw); - owner_.getPixmap()->draw_rectangle(owner_.getGC(), false, x, y, w, h); + setForeground(col); + setLineParam(ls, lw); + pixmap_->draw_rectangle(gc_, false, x, y, w, h); } void GPainter::fillRectangle(int x, int y, int w, int h, LColor_color col) { - setForeground(owner_.getGC(), col); - owner_.getPixmap()->draw_rectangle(owner_.getGC(), true, x, y, w, h); + setForeground(col); + pixmap_->draw_rectangle(gc_, true, x, y, w, h); } void GPainter::fillPolygon(int const * xp, int const * yp, int np, LColor_color col) { - setForeground(owner_.getGC(), col); + setForeground(col); std::vector points(np); for (int i = 0; i < np; ++i) { points[i].set_x(xp[i]); points[i].set_y(yp[i]); } - owner_.getPixmap()->draw_polygon(owner_.getGC(), true, points); + pixmap_->draw_polygon(gc_, true, points); } void GPainter::arc(int x, int y, unsigned int w, unsigned int h, int a1, int a2, LColor_color col) { - setForeground(owner_.getGC(), col); - owner_.getPixmap()->draw_arc(owner_.getGC(), + setForeground(col); + pixmap_->draw_arc(gc_, false, x, y, w, h, a1, a2); } @@ -190,9 +200,9 @@ void GPainter::image(int x, int y, int w, int h, graphics::LyXGdkImage const & image = static_cast(i); Glib::RefPtr const & pixbuf = image.pixbuf(); - Glib::RefPtr pixmap = owner_.getPixmap(); + Glib::RefPtr pixmap = pixmap_; - Glib::RefPtr gc = owner_.getGC(); + Glib::RefPtr gc = gc_; pixmap->draw_pixbuf (gc, pixbuf, 0, 0, x, y, w, h, Gdk::RGB_DITHER_NONE, 0, 0); } @@ -226,7 +236,6 @@ void GPainter::text(int x, int y, wchar_t const * s, int ls, LyXFont const & f) XftFont * font = getXftFont(f); XftColor * xftClr = owner_.getColorHandler(). getXftColor(f.realColor()); -// getXftColor(f.realColor()); XftDraw * draw = owner_.getXftDraw(); if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) { XftDrawString32(draw, xftClr, font, x, y, diff --git a/src/frontends/gtk/GPainter.h b/src/frontends/gtk/GPainter.h index 1874f5f464..7526994b36 100644 --- a/src/frontends/gtk/GPainter.h +++ b/src/frontends/gtk/GPainter.h @@ -26,6 +26,7 @@ namespace lyx { namespace frontend { class GWorkArea; +class ColorHandler; /** * GPainter - a painter implementation for Gtkmm @@ -39,9 +40,8 @@ public: /// return the height of the work area in pixels virtual int paperHeight() const; - void setForeground(Glib::RefPtr gc, LColor_color clr); - void setLineParam(Glib::RefPtr gc, - line_style ls, line_width lw); + inline void setForeground(LColor_color clr); + inline void setLineParam(line_style ls, line_width lw); XftColor * getXftColor(LColor_color clr); /// draw a line from point to point virtual void line( @@ -126,9 +126,16 @@ public: XChar2b const * str, size_t l, LyXFont const & f); + void start(); + private: /// our owner who we paint upon GWorkArea & owner_; + + Glib::RefPtr gc_; + Glib::RefPtr pixmap_; + ColorHandler *colorhandler_; + LColor_color currentcolor_; }; } // namespace frontend -- 2.39.5