optimize widget background painting for the case of multiple region rectangles

essentially saving multiple painter state changes and whatnot, performance
for single region rectangle remains the same

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2024-03-14 02:57:19 +02:00
parent f638484d11
commit 1ac3daf78c
2 changed files with 20 additions and 16 deletions

View file

@ -1687,9 +1687,13 @@ static inline void fillRegion(QPainter *painter, const QRegion &rgn, const QBrus
painter->fillRect(0, 0, painter->device()->width(), painter->device()->height(), brush);
painter->restore();
} else {
const QVector<QRect> &rects = rgn.rects();
for (int i = 0; i < rects.size(); ++i)
painter->fillRect(rects.at(i), brush);
QPen oldPen = painter->pen();
QBrush oldBrush = painter->brush();
painter->setPen(Qt::NoPen);
painter->setBrush(brush);
painter->drawRects(rgn.rects());
painter->setBrush(oldBrush);
painter->setPen(oldPen);
}
}
@ -1715,8 +1719,7 @@ void QWidgetPrivate::paintBackground(QPainter *painter, const QRegion &rgn, int
const QBrush autoFillBrush = q->palette().brush(q->backgroundRole());
if ((flags & DrawAsRoot) && !(q->autoFillBackground() && autoFillBrush.isOpaque())) {
const QBrush bg = q->palette().brush(QPalette::Window);
fillRegion(painter, rgn, bg);
fillRegion(painter, rgn, q->palette().brush(QPalette::Window));
}
if (q->autoFillBackground())

View file

@ -1258,26 +1258,27 @@ void QWidgetPrivate::updateSystemBackground()
|| type == Qt::Popup || type == Qt::ToolTip) {
if (QX11Info::isCompositingManagerRunning()
&& q->testAttribute(Qt::WA_TranslucentBackground)
&& !(q->parent()))
&& !(q->parent())) {
XSetWindowBackground(qt_x11Data->display, q->internalWinId(),
QX11Data::XColorPixel(xinfo.screen(), Qt::transparent));
else
} else {
XSetWindowBackgroundPixmap(qt_x11Data->display, q->internalWinId(), XNone);
}
else if (brush.style() == Qt::SolidPattern && brush.isOpaque())
} else if (brush.style() == Qt::SolidPattern && brush.isOpaque()) {
XSetWindowBackground(qt_x11Data->display, q->internalWinId(),
QX11Data::XColorPixel(xinfo.screen(), brush.color()));
else if (isBackgroundInherited())
} else if (isBackgroundInherited()) {
XSetWindowBackgroundPixmap(qt_x11Data->display, q->internalWinId(), ParentRelative);
else if (brush.style() == Qt::TexturePattern) {
} else if (brush.style() == Qt::TexturePattern) {
const Qt::HANDLE bgpixmap = brush.texture().toX11Pixmap();
XSetWindowBackgroundPixmap(qt_x11Data->display, q->internalWinId(), bgpixmap);
if (bgpixmap) {
XFreePixmap(qt_x11Data->display, bgpixmap);
}
} else
} else {
XSetWindowBackground(qt_x11Data->display, q->internalWinId(),
QX11Data::XColorPixel(xinfo.screen(), brush.color()));
}
}
#ifndef QT_NO_CURSOR