Skip to content

Commit 8e148b4

Browse files
committed
Optimize rapaintings using repaintRegion parameter in paintFrameBackground(), paintTitleBarBackground(), paintCaption()
1 parent 4b71e65 commit 8e148b4

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

src/Decoration.cc

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,9 @@ QPainterPath Decoration::getRoundedPath(const QRectF &rect,
998998

999999
void Decoration::paintFrameBackground(QPainter *painter, const QRectF &repaintRegion) const
10001000
{
1001-
Q_UNUSED(repaintRegion)
1001+
if (!rect().intersects(repaintRegion)) {
1002+
return;
1003+
}
10021004

10031005
painter->save();
10041006

@@ -1061,7 +1063,9 @@ void Decoration::updateColors()
10611063

10621064
void Decoration::paintTitleBarBackground(QPainter *painter, const QRectF &repaintRegion) const
10631065
{
1064-
Q_UNUSED(repaintRegion)
1066+
if (!m_titleBarPath.boundingRect().intersects(repaintRegion)) {
1067+
return;
1068+
}
10651069

10661070
painter->save();
10671071
painter->setRenderHint(QPainter::Antialiasing);
@@ -1075,8 +1079,6 @@ void Decoration::paintTitleBarBackground(QPainter *painter, const QRectF &repain
10751079

10761080
void Decoration::paintCaption(QPainter *painter, const QRectF &repaintRegion) const
10771081
{
1078-
Q_UNUSED(repaintRegion)
1079-
10801082
// 1. Pre-checks and data gathering
10811083
const auto *decoratedClient = window();
10821084
const bool hasAppMenu = decoratedClient->hasApplicationMenu();
@@ -1169,6 +1171,12 @@ void Decoration::paintCaption(QPainter *painter, const QRectF &repaintRegion) co
11691171
return;
11701172
}
11711173

1174+
drawingRect.translate(0, offset);
1175+
1176+
if (!drawingRect.intersects(repaintRegion)) {
1177+
return;
1178+
}
1179+
11721180
// 6. Painter setup and drawing
11731181
painter->save();
11741182
painter->setFont(font);
@@ -1186,7 +1194,6 @@ void Decoration::paintCaption(QPainter *painter, const QRectF &repaintRegion) co
11861194
m_captionCache.alignment = alignment;
11871195
m_captionCache.elidedCaption = fontMetrics.elidedText(fullCaption, Qt::ElideMiddle, drawingRect.width());
11881196
}
1189-
drawingRect.translate(0, offset);
11901197

11911198
painter->drawText(drawingRect, alignment | Qt::TextSingleLine | Qt::AlignVCenter, m_captionCache.elidedCaption);
11921199
painter->restore();

0 commit comments

Comments
 (0)