]> git.lyx.org Git - features.git/commitdiff
Try to make GPainter a bit more efficient
authorJohn Spray <spray@lyx.org>
Mon, 13 Feb 2006 19:36:10 +0000 (19:36 +0000)
committerJohn Spray <spray@lyx.org>
Mon, 13 Feb 2006 19:36:10 +0000 (19:36 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13230 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/gtk/ChangeLog
src/frontends/gtk/GPainter.C
src/frontends/gtk/GPainter.h

index e840f30c464cfb1863c60da8684c52561b24b2ac..3bca6b93a04ae22b86bb02f0fca7231a776a0ee1 100644 (file)
@@ -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
          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  <spray@lyx.org>
        * GMenubar.C: assume backend strings in latin1 (bug 1954)
 
 2006-02-12  John Spray  <spray@lyx.org>
        * GMenubar.C: assume backend strings in latin1 (bug 1954)
index 61c3f29a1fd69176ec054920ee237561c434abf6..766742d5ddf900fddd136b8e1194c8c7dbabb50a 100644 (file)
@@ -55,7 +55,7 @@ namespace lyx {
 namespace frontend {
 
 GPainter::GPainter(GWorkArea & xwa)
 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<Gdk::GC> 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<Gdk::GC> gc,
-                           line_style ls, line_width lw)
+inline void GPainter::setLineParam(line_style ls, line_width lw)
 {
        int width = 0;
        switch (lw) {
 {
        int width = 0;
        switch (lw) {
@@ -101,15 +111,15 @@ void GPainter::setLineParam(Glib::RefPtr<Gdk::GC> gc,
                style = Gdk::LINE_ON_OFF_DASH;
                break;
        }
                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)
 {
                                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)
 {
        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)
 {
        line_style ls,
        line_width lw)
 {
-       setForeground(owner_.getGC(), col);
-       setLineParam(owner_.getGC(), ls, lw);
+       setForeground(col);
+       setLineParam(ls, lw);
        std::vector<Gdk::Point> points(np);
 
        for (int i = 0; i < np; ++i) {
                points[i].set_x(xp[i]);
                points[i].set_y(yp[i]);
        }
        std::vector<Gdk::Point> 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)
 {
        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)
 {
 }
 
 
 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)
 {
 }
 
 
 void GPainter::fillPolygon(int const * xp, int const * yp,
        int np, LColor_color col)
 {
-       setForeground(owner_.getGC(), col);
+       setForeground(col);
        std::vector<Gdk::Point> points(np);
 
        for (int i = 0; i < np; ++i) {
                points[i].set_x(xp[i]);
                points[i].set_y(yp[i]);
        }
        std::vector<Gdk::Point> 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)
 {
 }
 
 
 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);
 }
 
                                     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<graphics::LyXGdkImage const &>(i);
        Glib::RefPtr<Gdk::Pixbuf> const & pixbuf = image.pixbuf();
        graphics::LyXGdkImage const & image =
                static_cast<graphics::LyXGdkImage const &>(i);
        Glib::RefPtr<Gdk::Pixbuf> const & pixbuf = image.pixbuf();
-       Glib::RefPtr<Gdk::Pixmap> pixmap = owner_.getPixmap();
+       Glib::RefPtr<Gdk::Pixmap> pixmap = pixmap_;
 
 
-       Glib::RefPtr<Gdk::GC> gc = owner_.getGC();
+       Glib::RefPtr<Gdk::GC> gc = gc_;
        pixmap->draw_pixbuf (gc, pixbuf, 0, 0, x, y, w, h,
                             Gdk::RGB_DITHER_NONE, 0, 0);
 }
        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());
        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,
        XftDraw * draw = owner_.getXftDraw();
        if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
                XftDrawString32(draw, xftClr, font, x, y,
index 1874f5f464edb62cece1b352f26fed0064a780f5..7526994b364c1763450f58023333b0dc15de27f9 100644 (file)
@@ -26,6 +26,7 @@ namespace lyx {
 namespace frontend {
 
 class GWorkArea;
 namespace frontend {
 
 class GWorkArea;
+class ColorHandler;
 
 /**
  * GPainter - a painter implementation for Gtkmm
 
 /**
  * GPainter - a painter implementation for Gtkmm
@@ -39,9 +40,8 @@ public:
        /// return the height of the work area in pixels
        virtual int paperHeight() const;
 
        /// return the height of the work area in pixels
        virtual int paperHeight() const;
 
-       void setForeground(Glib::RefPtr<Gdk::GC> gc, LColor_color clr);
-       void setLineParam(Glib::RefPtr<Gdk::GC> 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(
        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);
 
                XChar2b const * str, size_t l,
                LyXFont const & f);
 
+       void start();
+
 private:
        /// our owner who we paint upon
        GWorkArea & owner_;
 private:
        /// our owner who we paint upon
        GWorkArea & owner_;
+       
+       Glib::RefPtr<Gdk::GC> gc_;
+       Glib::RefPtr<Gdk::Pixmap> pixmap_;
+       ColorHandler *colorhandler_;
+       LColor_color currentcolor_;
 };
 
 } // namespace frontend
 };
 
 } // namespace frontend