add url
[kdegraphics.git] / kolourpaint / patches / checkerboard-faster-render.diff
blob7cc5c8b50f35264081306ae0fa5a4745e9ec24ee
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.
6 2007-10-12:
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
10 before being applied.
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 @@
18 +#if 1
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;
29 +// public
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++)
40 + {
41 + for (int x = 0; x < rep; x++)
42 + {
43 + QColor col;
45 + if ((parityAsInt + x + y) % 2)
46 + {
47 + if (!isPreview)
48 + col = QColor (213, 213, 213);
49 + else
50 + col = QColor (224, 224, 224);
51 + }
52 + else
53 + col = Qt::white;
55 + painter.fillRect (x * cellSize, y * cellSize,
56 + cellSize, cellSize,
57 + col);
58 + }
59 + }
61 + painter.end ();
62 + return newPixmap;
65 +void kpMainWindow::drawTransparentBackground (QPainter *painter,
66 + int /*viewWidth*/, int /*viewHeight*/,
67 + const QRect &rect,
68 + bool isPreview)
70 +#if DEBUG_KP_MAIN_WINDOW && 1 || 1
71 + kDebug () << "\tkpMainWindow::drawTransparentBackground(rect="
72 + << rect << ")" << endl;
73 + QTime totalTimer; totalTimer.start ();
74 +#endif
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])
91 + {
92 + checkerBoardCache [isPreview][parity] = createCheckerBoardCache (isPreview, parity);
93 + }
95 + QPixmap *tilePixmap = checkerBoardCache [isPreview][parity];
96 + for (int y = starty; y <= rect.bottom (); y += tilePixmap->height ())
97 + {
98 + for (int x = startx; x <= rect.right (); x += tilePixmap->width ())
99 + {
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;
109 +#endif
113 +#else
115 // public
116 void kpMainWindow::drawTransparentBackground (QPainter *painter,
117 int /*viewWidth*/, int /*viewHeight*/,
118 const QRect &rect,
119 bool isPreview)
121 +#if DEBUG_KP_MAIN_WINDOW && 1
122 + kDebug () << "\tkpMainWindow::drawTransparentBackground(rect="
123 + << rect << ")" << endl;
124 + QTime totalTimer; totalTimer.start ();
125 +#endif
128 const int cellSize = !isPreview ? 16 : 10;
130 int starty = rect.y ();
131 @@ -877,8 +982,15 @@
134 painter->restore ();
137 +#if DEBUG_KP_MAIN_WINDOW && 1 || 1
139 + const int totalTimerElapsed = totalTimer.elapsed ();
140 + kDebug () << "\t\ttotal=" << totalTimerElapsed << endl;
142 +#endif
144 +#endif
146 // private slot
147 void kpMainWindow::slotUpdateCaption ()