1 At 100% zoom: kpMainWindow::drawTransparentBackground() accounts for
2 about 75% of kpView::paintEvent()'s time. Bottleneck is
3 QPainter::fillRect(). QPainter::drawPixmap() seems much faster. For
4 800x600, renderer goes from 10ms to 1ms.
7 Have not reprofiled KolourPaint under Qt4 to determine whether this patch
8 is still worthwhile (I suspect it still is since QPainter/X11 could not
9 magically have gotten faster). In any case, the patch needs to be updated
12 --- kpmainwindow.cpp 2004-08-05 02:10:38.000000000 +1000
13 +++ kpmainwindow.cpp 2004-09-29 11:24:45.000000000 +1000
14 @@ -838,12 +838,116 @@
19 +// (indexed by [isPreview][parity])
20 +static QPixmap *checkerBoardCache [2][2] = {{0, 0}, {0, 0}};
23 +static int checkerBoardCellSize (bool isPreview)
25 + return !isPreview ? 16 : 10;
30 +static QPixmap *createCheckerBoardCache (bool isPreview, bool parity)
32 + int cellSize = checkerBoardCellSize (isPreview);
33 + const int rep = 2; // must be multiple of 2
35 + QPixmap *newPixmap = new QPixmap (cellSize * rep, cellSize * rep);
36 + QPainter painter (newPixmap);
38 + int parityAsInt = parity ? 1 : 0;
39 + for (int y = 0; y < rep; y++)
41 + for (int x = 0; x < rep; x++)
45 + if ((parityAsInt + x + y) % 2)
48 + col = QColor (213, 213, 213);
50 + col = QColor (224, 224, 224);
55 + painter.fillRect (x * cellSize, y * cellSize,
65 +void kpMainWindow::drawTransparentBackground (QPainter *painter,
66 + int /*viewWidth*/, int /*viewHeight*/,
70 +#if DEBUG_KP_MAIN_WINDOW && 1 || 1
71 + kDebug () << "\tkpMainWindow::drawTransparentBackground(rect="
72 + << rect << ")" << endl;
73 + QTime totalTimer; totalTimer.start ();
76 + int cellSize = checkerBoardCellSize (isPreview);
79 + int starty = rect.y ();
80 + if (starty % cellSize)
81 + starty -= (starty % cellSize);
83 + int startx = rect.x ();
84 + if (startx % cellSize)
85 + startx -= (startx % cellSize);
88 + int parity = ((startx / cellSize + starty / cellSize) % 2) ? 1 : 0;
90 + if (!checkerBoardCache [isPreview][parity])
92 + checkerBoardCache [isPreview][parity] = createCheckerBoardCache (isPreview, parity);
95 + QPixmap *tilePixmap = checkerBoardCache [isPreview][parity];
96 + for (int y = starty; y <= rect.bottom (); y += tilePixmap->height ())
98 + for (int x = startx; x <= rect.right (); x += tilePixmap->width ())
100 + painter->drawPixmap (x - rect.x (), y - rect.y (), *tilePixmap);
104 +#if DEBUG_KP_MAIN_WINDOW && 1 || 1
106 + const int totalTimerElapsed = totalTimer.elapsed ();
107 + kDebug () << "\t\ttotal=" << totalTimerElapsed << endl;
116 void kpMainWindow::drawTransparentBackground (QPainter *painter,
117 int /*viewWidth*/, int /*viewHeight*/,
121 +#if DEBUG_KP_MAIN_WINDOW && 1
122 + kDebug () << "\tkpMainWindow::drawTransparentBackground(rect="
123 + << rect << ")" << endl;
124 + QTime totalTimer; totalTimer.start ();
128 const int cellSize = !isPreview ? 16 : 10;
130 int starty = rect.y ();
137 +#if DEBUG_KP_MAIN_WINDOW && 1 || 1
139 + const int totalTimerElapsed = totalTimer.elapsed ();
140 + kDebug () << "\t\ttotal=" << totalTimerElapsed << endl;
147 void kpMainWindow::slotUpdateCaption ()