Angus Leeming wrote:
> It would appear to me that introducing unicode now will kill off any serious
> attempt to speed up the Qt frontend.
>
> Of course, I'd love to be proved wrong ;-) Maybe Abdel's Qt clean up  will fix
> things as if by magic ;-)

Here some statistics of QLPainter functions:

I've measured the time which the program is
in an scope, see attached patch.

The results are:

complete QLPainter member functions:
Scope 12,    ms : 1236 -> setQPainterPen
Scope 14,    ms : 812 ->  line
Scope 15,    ms : 172
Scope 16,    ms : 46
Scope 17,    ms : 3683 -> fillRectangle
Scope 20,    ms : 16
Scope 22,    ms : 514
Scope 23,    ms : 201
Scope 24,    ms : 25027 -> text

in scope 24 (QLPainter::text)
Scope 31,    ms : 1390 -> setQPainterPen
Scope 32,    ms : 110
Scope 33,    ms : 394  -> str[i] = QChar(encoding->ucs(s[i]));
Scope 34,    ms : 79
Scope 35,    ms : 17400 -> if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) 
{..setFont ... drawText...}
Scope 36,    ms : 142

in scope 35, (if (f.realShape()...):
Scope 40,    ms : 830    -> QPainter::setFont
Scope 41,    ms : 16334  -> QPainter::drawText


The most time is spend in the Qt function QPainter::drawText.
Could this time be reduced?

Peter






Index: QLPainter.C
===================================================================
--- QLPainter.C (Revision 13994)
+++ QLPainter.C (Arbeitskopie)
@@ -9,6 +9,8 @@
  * Full author contact details are available in file CREDITS.
  */
 
+
+
 #include <config.h>
 
 #include "QLPainter.h"
@@ -25,6 +27,7 @@
 
 #include "frontends/font_metrics.h"
 
+#undef QT3_SUPPORT
 #include <QPainter>
 #include <QPicture>
 #include <QPixmap>
@@ -33,14 +36,63 @@
 using std::endl;
 using std::string;
 
+#include <iostream>
+#include <QTime>
 
+const int csize =50;
+
+struct StatData
+{
+       StatData()
+       {
+               for(int i=10;i<csize;i++) 
+                       c[i]=0;
+       }
+
+       ~StatData()
+       {
+               for(int i=10;i<csize;i++) 
+               {
+                       /*
+                       std::cout<< "Scope " << i << ", calls : " << c[i]  << 
"\n";*/
+                       std::cout<< "Scope " << i << ",    ms : " << ms[i] << 
"\n";
+               }
+       }
+
+       int c[csize];
+       int ms[csize];
+};
+
+struct CallStat
+{
+       CallStat(StatData& d, int i) : data(d), index(i)
+       {
+               t.start();
+       }
+       
+       ~CallStat()
+       {
+               ++data.c[index];
+               data.ms[index] += t.elapsed();
+       }
+
+       QTime t;
+       StatData& data;
+       int index;
+
+};
+
+StatData statData;
+
 QLPainter::~QLPainter()
 {
+       CallStat tmp(statData, 11);
 }
 
 QLPainter::QLPainter(QWorkArea * qwa)
        : Painter(), qwa_(qwa)
 {
+       CallStat tmp(statData, 10);
 }
 
 
@@ -58,6 +110,7 @@
 QPainter & QLPainter::setQPainterPen(QPainter & qp, LColor_color c,
        Painter::line_style ls, Painter::line_width lw)
 {
+       CallStat tmp(statData, 12);
        QPen pen = qp.pen();
 
        pen.setColor(lcolorcache.get(c));
@@ -79,6 +132,7 @@
 
 void QLPainter::point(int x, int y, LColor_color c)
 {
+       CallStat tmp(statData, 13);
        QPainter qp(qwa_->paintDevice());
        setQPainterPen(qp, c).drawPoint(x, y);
 }
@@ -89,6 +143,7 @@
        line_style ls,
        line_width lw)
 {
+       CallStat tmp(statData, 14);
        QPainter qp(qwa_->paintDevice());
        setQPainterPen(qp, col, ls, lw).drawLine(x1, y1, x2, y2);
 }
@@ -99,6 +154,7 @@
        line_style ls,
        line_width lw)
 {
+       CallStat tmp(statData, 15);
        // FIXME ?
 
        // Must use new as np is not known at compile time.
@@ -119,6 +175,7 @@
        line_style ls,
        line_width lw)
 {
+       CallStat tmp(statData, 16);
        QPainter qp(qwa_->paintDevice());
        setQPainterPen(qp, col, ls, lw).drawRect(x, y, w, h);
 }
@@ -126,6 +183,7 @@
 
 void QLPainter::fillRectangle(int x, int y, int w, int h, LColor_color col)
 {
+       CallStat tmp(statData, 17);
        QPainter qp(qwa_->paintDevice());
        qp.fillRect(x, y, w, h, lcolorcache.get(col));
 }
@@ -134,6 +192,7 @@
 void QLPainter::fillPolygon(int const * xp, int const * yp,
        int np, LColor_color col)
 {
+       CallStat tmp(statData, 18);
        // Must use new as np is not known at compile time.
        boost::scoped_array<QPoint> points(new QPoint[np]);
 
@@ -153,6 +212,7 @@
 void QLPainter::arc(int x, int y, unsigned int w, unsigned int h,
        int a1, int a2, LColor_color col)
 {
+       CallStat tmp(statData, 19);
        // LyX usings 1/64ths degree, Qt usings 1/16th
        QPainter qp(qwa_->paintDevice());
        setQPainterPen(qp, col).drawArc(x, y, w, h, a1 / 4, a2 / 4);
@@ -162,6 +222,7 @@
 void QLPainter::image(int x, int y, int w, int h,
        lyx::graphics::Image const & i)
 {
+       CallStat tmp(statData, 20);
        lyx::graphics::QLImage const & qlimage =
                static_cast<lyx::graphics::QLImage const &>(i);
 
@@ -180,6 +241,7 @@
 
 void QLPainter::text(int x, int y, char c, LyXFont const & f)
 {
+       CallStat tmp(statData, 22);
        char s[2] = { c, '\0' };
        return text(x, y, s, 1, f);
 }
@@ -188,6 +250,7 @@
 void QLPainter::smallCapsText(int x, int y,
        QString const & s, LyXFont const & f)
 {
+       CallStat tmp(statData, 23);
        LyXFont smallfont(f);
        smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
 
@@ -218,46 +281,73 @@
 void QLPainter::text(int x, int y, char const * s, size_t ls,
        LyXFont const & f)
 {
+       CallStat tmp(statData, 24);
+
        QPainter qp(qwa_->paintDevice());
+
+       {CallStat tmp(statData, 31);
        setQPainterPen(qp, f.realColor());
+       }
+       
+       Encoding const * encoding = f.language()->encoding();
 
-       Encoding const * encoding = f.language()->encoding();
+       {CallStat tmp(statData, 32);
        if (f.isSymbolFont())
                encoding = encodings.symbol_encoding();
+       }
+       
+       QString str;
 
-       QString str;
+       {CallStat tmp(statData, 33);
        str.setLength(ls);
        for (int i = 0; i < ls; ++i)
                // Brain-dead MSVC wants at(i) rather than operator[]
                str[i] = QChar(encoding->ucs(s[i]));
        // HACK: QT3 refuses to show single compose characters
+       }
+
+       {CallStat tmp(statData, 34);
        if (ls == 1 && str[0].unicode() >= 0x05b0 && str[0].unicode() <= 0x05c2)
                str = ' ' + str;
+       }
 
+       {CallStat tmp(statData, 35);
        if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
+               {CallStat tmp(statData, 40);
                qp.setFont(fontloader.get(f));
+               }
                // We need to draw the text as LTR as we use our own bidi
                // code.
+               {CallStat tmp(statData, 41);
                qp.setLayoutDirection(Qt::LeftToRight);
-               qp.drawText(x, y, str, -1);
+               qp.drawText(x, y, str);
+               }
        } else {
+               {CallStat tmp(statData, 40);
                smallCapsText(x, y, str, f);
+               }
        }
+       }
 
+       {CallStat tmp(statData, 36);
+
        if (f.underbar() == LyXFont::ON) {
                underline(f, x, y, font_metrics::width(s, ls, f));
        }
+       }
 
 }
 /// draw a pixmap from the image cache
 void QLPainter::drawPixmap(int x, int y, QPixmap const & pixmap)
 {
+       CallStat tmp(statData, 25);
        QPainter qp(qwa_->paintDevice());
        qp.drawPixmap(x, y, pixmap);
 }
 
 void QLPainter::drawImage(int x, int y, QImage const & image)
 {
+       CallStat tmp(statData, 26);
        QPainter qp(qwa_->paintDevice());
        qp.drawImage(x, y, image);
 }

Reply via email to