Warning, /graphics/kolourpaint/patches/checkerboard-faster-render.diff is written in an unsupported language. File is not indexed.

0001 At 100% zoom: kpMainWindow::drawTransparentBackground() accounts for
0002 about 75% of kpView::paintEvent()'s time.  Bottleneck is
0003 QPainter::fillRect().  QPainter::drawPixmap() seems much faster.  For
0004 800x600, renderer goes from 10ms to 1ms.
0005 
0006 2007-10-12:
0007 Have not reprofiled KolourPaint under Qt4 to determine whether this patch
0008 is still worthwhile (I suspect it still is since QPainter/X11 could not
0009 magically have gotten faster).  In any case, the patch needs to be updated
0010 before being applied.
0011 
0012 --- kpmainwindow.cpp    2004-08-05 02:10:38.000000000 +1000
0013 +++ kpmainwindow.cpp    2004-09-29 11:24:45.000000000 +1000
0014 @@ -838,12 +838,116 @@
0015  }
0016  
0017  
0018 +#if 1
0019 +// (indexed by [isPreview][parity])
0020 +static QPixmap *checkerBoardCache [2][2] = {{0, 0}, {0, 0}};
0021 +
0022 +
0023 +static int checkerBoardCellSize (bool isPreview)
0024 +{
0025 +    return !isPreview ? 16 : 10;
0026 +}
0027 +
0028 +
0029 +// public
0030 +static QPixmap *createCheckerBoardCache (bool isPreview, bool parity)
0031 +{
0032 +    int cellSize = checkerBoardCellSize (isPreview);
0033 +    const int rep = 2;  // must be multiple of 2
0034 +
0035 +    QPixmap *newPixmap = new QPixmap (cellSize * rep, cellSize * rep);
0036 +    QPainter painter (newPixmap);
0037 +
0038 +    int parityAsInt = parity ? 1 : 0;
0039 +    for (int y = 0; y < rep; y++)
0040 +    {
0041 +        for (int x = 0; x < rep; x++)
0042 +        {
0043 +            QColor col;
0044 +
0045 +            if ((parityAsInt + x + y) % 2)
0046 +            {
0047 +                if (!isPreview)
0048 +                    col = QColor (213, 213, 213);
0049 +                else
0050 +                    col = QColor (224, 224, 224);
0051 +            }
0052 +            else
0053 +                col = Qt::white;
0054 +
0055 +            painter.fillRect (x * cellSize, y * cellSize,
0056 +                              cellSize, cellSize,
0057 +                              col);
0058 +        }
0059 +    }
0060 +
0061 +    painter.end ();
0062 +    return newPixmap;
0063 +}
0064 +
0065 +void kpMainWindow::drawTransparentBackground (QPainter *painter,
0066 +                                              int /*viewWidth*/, int /*viewHeight*/,
0067 +                                              const QRect &rect,
0068 +                                              bool isPreview)
0069 +{
0070 +#if DEBUG_KP_MAIN_WINDOW && 1 || 1
0071 +    kDebug () << "\tkpMainWindow::drawTransparentBackground(rect="
0072 +               << rect << ")" << endl;
0073 +    QTime totalTimer; totalTimer.start ();
0074 +#endif
0075 +
0076 +    int cellSize = checkerBoardCellSize (isPreview);
0077 +
0078 +
0079 +    int starty = rect.y ();
0080 +    if (starty % cellSize)
0081 +        starty -= (starty % cellSize);
0082 +
0083 +    int startx = rect.x ();
0084 +    if (startx % cellSize)
0085 +        startx -= (startx % cellSize);
0086 +
0087 +
0088 +    int parity = ((startx / cellSize + starty / cellSize) % 2) ? 1 : 0;
0089 +
0090 +    if (!checkerBoardCache [isPreview][parity])
0091 +    {
0092 +        checkerBoardCache [isPreview][parity] = createCheckerBoardCache (isPreview, parity);
0093 +    }
0094 +
0095 +    QPixmap *tilePixmap = checkerBoardCache [isPreview][parity];
0096 +    for (int y = starty; y <= rect.bottom (); y += tilePixmap->height ())
0097 +    {
0098 +        for (int x = startx; x <= rect.right (); x += tilePixmap->width ())
0099 +        {
0100 +            painter->drawPixmap (x - rect.x (), y - rect.y (), *tilePixmap);
0101 +        }
0102 +    }
0103 +
0104 +#if DEBUG_KP_MAIN_WINDOW && 1 || 1
0105 +{
0106 +    const int totalTimerElapsed = totalTimer.elapsed ();
0107 +    kDebug () << "\t\ttotal=" << totalTimerElapsed << endl;
0108 +}
0109 +#endif
0110 +}
0111 +
0112 +
0113 +#else
0114 +
0115  // public
0116  void kpMainWindow::drawTransparentBackground (QPainter *painter,
0117                                                int /*viewWidth*/, int /*viewHeight*/,
0118                                                const QRect &rect,
0119                                                bool isPreview)
0120  {
0121 +#if DEBUG_KP_MAIN_WINDOW && 1
0122 +    kDebug () << "\tkpMainWindow::drawTransparentBackground(rect="
0123 +               << rect << ")" << endl;
0124 +    QTime totalTimer; totalTimer.start ();
0125 +#endif
0126 +
0127 +
0128      const int cellSize = !isPreview ? 16 : 10;
0129  
0130      int starty = rect.y ();
0131 @@ -877,8 +982,15 @@
0132          }
0133      }
0134      painter->restore ();
0135 -}
0136  
0137 +#if DEBUG_KP_MAIN_WINDOW && 1 || 1
0138 +{
0139 +    const int totalTimerElapsed = totalTimer.elapsed ();
0140 +    kDebug () << "\t\ttotal=" << totalTimerElapsed << endl;
0141 +}
0142 +#endif
0143 +}
0144 +#endif
0145  
0146  // private slot
0147  void kpMainWindow::slotUpdateCaption ()