Peter Kümmel wrote:
Abdelrazak Younes wrote:

Yes. I have been experimenting with a QPicture cache between
QLPainter::start() and QLPainter::end() which would replay the QPicture
into the QWorkArea painting_device_  (which is a QPixmap). The speedup
is awesome. Unfortunately the core is not prepared for that kind of
"meta" drawing.

Abdel.

Great! Do you have a patch - I'm very interested, or is it already in
the mailing list archive?
With my timing functions I could then measure the speed up - this will
become very interesting.

Please find attached the patch. The main problem with it is that everything that is drawn in screen stays. So it conflict with the background drawing that the kernel does to erase something. If you manage to catch that background cache command and send it to /dev/null, I think it is possible to do something.

Abdel.
Index: QLPainter.C
===================================================================
--- QLPainter.C (revision 14001)
+++ QLPainter.C (working copy)
@@ -43,7 +43,18 @@
 {
 }
 
+void QLPainter::start()
+{
+       picture_.reset(new QPicture);
+}
 
+
+void QLPainter::end()
+{
+       QPainter qp(qwa_->paintDevice());
+       qp.drawPicture(0,0,*picture_.get());
+}
+
 int QLPainter::paperWidth() const
 {
        return qwa_->viewport()->width();
@@ -79,7 +90,7 @@
 
 void QLPainter::point(int x, int y, LColor_color c)
 {
-       QPainter qp(qwa_->paintDevice());
+       QPainter qp(picture_.get());
        setQPainterPen(qp, c).drawPoint(x, y);
 }
 
@@ -89,7 +100,7 @@
        line_style ls,
        line_width lw)
 {
-       QPainter qp(qwa_->paintDevice());
+       QPainter qp(picture_.get());
        setQPainterPen(qp, col, ls, lw).drawLine(x1, y1, x2, y2);
 }
 
@@ -109,7 +120,7 @@
                points[i].setY(yp[i]);
        }
 
-       QPainter qp(qwa_->paintDevice());
+       QPainter qp(picture_.get());
        setQPainterPen(qp, col, ls, lw).drawPolyline(points.get(), np);
 }
 
@@ -119,14 +130,14 @@
        line_style ls,
        line_width lw)
 {
-       QPainter qp(qwa_->paintDevice());
+       QPainter qp(picture_.get());
        setQPainterPen(qp, col, ls, lw).drawRect(x, y, w, h);
 }
 
 
 void QLPainter::fillRectangle(int x, int y, int w, int h, LColor_color col)
 {
-       QPainter qp(qwa_->paintDevice());
+       QPainter qp(picture_.get());
        qp.fillRect(x, y, w, h, lcolorcache.get(col));
 }
 
@@ -142,7 +153,7 @@
                points[i].setY(yp[i]);
        }
 
-       QPainter qp(qwa_->paintDevice());
+       QPainter qp(picture_.get());
        setQPainterPen(qp, col);
        qp.setBrush(lcolorcache.get(col));
        qp.drawPolygon(points.get(), np);
@@ -154,7 +165,7 @@
        int a1, int a2, LColor_color col)
 {
        // LyX usings 1/64ths degree, Qt usings 1/16th
-       QPainter qp(qwa_->paintDevice());
+       QPainter qp(picture_.get());
        setQPainterPen(qp, col).drawArc(x, y, w, h, a1 / 4, a2 / 4);
 }
 
@@ -167,7 +178,7 @@
 
        fillRectangle(x, y, w, h, LColor::graphicsbg);
 
-       QPainter qp(qwa_->paintDevice());
+       QPainter qp(picture_.get());
        qp.drawImage(x, y, qlimage.qimage(), 0, 0, w, h);
 }
 
@@ -196,7 +207,7 @@
        QFontMetrics const & qfontm = QFontMetrics(qfont);
        QFontMetrics const & qsmallfontm = QFontMetrics(qsmallfont);
 
-       QPainter qp(qwa_->paintDevice());
+       QPainter qp(picture_.get());
        int tmpx = x;
        size_t ls = s.length();
        for (size_t i = 0; i < ls; ++i) {
@@ -218,7 +229,7 @@
 void QLPainter::text(int x, int y, char const * s, size_t ls,
        LyXFont const & f)
 {
-       QPainter qp(qwa_->paintDevice());
+       QPainter qp(picture_.get());
        setQPainterPen(qp, f.realColor());
 
        Encoding const * encoding = f.language()->encoding();
@@ -252,12 +263,12 @@
 /// draw a pixmap from the image cache
 void QLPainter::drawPixmap(int x, int y, QPixmap const & pixmap)
 {
-       QPainter qp(qwa_->paintDevice());
+       QPainter qp(picture_.get());
        qp.drawPixmap(x, y, pixmap);
 }
 
 void QLPainter::drawImage(int x, int y, QImage const & image)
 {
-       QPainter qp(qwa_->paintDevice());
+       QPainter qp(picture_.get());
        qp.drawImage(x, y, image);
 }
Index: QLPainter.h
===================================================================
--- QLPainter.h (revision 14001)
+++ QLPainter.h (working copy)
@@ -20,6 +20,7 @@
 class LyXFont;
 class QPaintDevice;
 class QPainter;
+class QPicture;
 class QString;
 class QPixmap;
 class QImage;
@@ -38,13 +39,13 @@
        /**
        Not used in the the Qt4 frontend.
        */
-       virtual void start() {}
+       virtual void start(); 
 
        /// end painting
        /**
        Not used in the the Qt4 frontend.
        */
-       virtual void end() {}
+       virtual void end();
 
        /// return the width of the work area in pixels
        virtual int paperWidth() const;
@@ -145,6 +146,9 @@
        /// our qt painter
        boost::scoped_ptr<QPainter> qp_;
 
+       /// our qt painter
+       boost::scoped_ptr<QPicture> picture_;
+
        /// the working area
        QWorkArea * qwa_;
 };

Reply via email to