From 9cd5c614559159fe09b414d568f88a192405b84d Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Mon, 12 Jan 2015 14:57:08 +0100 Subject: Avoid unneeded QBrush::texture() calls If a QBrush has been created without QPixmap the texture() method will create one. This patch avoids that in several places by checking the type of the texture brush before accessing it, or not accessing it at all. Task-number: QTBUG-43766 Change-Id: If6009fe1d5bd51b239ae2c838e5c3b904b56b11a Reviewed-by: Marc Mutz Reviewed-by: Gunnar Sletta --- src/gui/painting/qbrush.cpp | 18 ++++++++++++++---- src/gui/painting/qpdf.cpp | 4 ++-- src/widgets/styles/qfusionstyle_p_p.h | 4 ++-- src/widgets/styles/qwindowsstyle.cpp | 21 +++++++++++++++++---- 4 files changed, 35 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/gui/painting/qbrush.cpp b/src/gui/painting/qbrush.cpp index d136f3a903..40dad85cde 100644 --- a/src/gui/painting/qbrush.cpp +++ b/src/gui/painting/qbrush.cpp @@ -1029,7 +1029,10 @@ QDataStream &operator<<(QDataStream &s, const QBrush &b) s << style << b.color(); if (b.style() == Qt::TexturePattern) { - s << b.texture(); + if (s.version() >= QDataStream::Qt_5_5) + s << b.textureImage(); + else + s << b.texture(); } else if (s.version() >= QDataStream::Qt_4_0 && gradient_style) { const QGradient *gradient = b.gradient(); int type_as_int = int(gradient->type()); @@ -1089,10 +1092,17 @@ QDataStream &operator>>(QDataStream &s, QBrush &b) QColor color; s >> style; s >> color; + b = QBrush(color); if (style == Qt::TexturePattern) { - QPixmap pm; - s >> pm; - b = QBrush(color, pm); + if (s.version() >= QDataStream::Qt_5_5) { + QImage img; + s >> img; + b.setTextureImage(qMove(img)); + } else { + QPixmap pm; + s >> pm; + b.setTexture(qMove(pm)); + } } else if (style == Qt::LinearGradientPattern || style == Qt::RadialGradientPattern || style == Qt::ConicalGradientPattern) { diff --git a/src/gui/painting/qpdf.cpp b/src/gui/painting/qpdf.cpp index 2efaec41ef..687d8efcec 100644 --- a/src/gui/painting/qpdf.cpp +++ b/src/gui/painting/qpdf.cpp @@ -2264,9 +2264,9 @@ int QPdfEnginePrivate::addBrushPattern(const QTransform &m, bool *specifyColor, if (pattern.isEmpty()) { if (brush.style() != Qt::TexturePattern) return 0; - QImage image = brush.texture().toImage(); + QImage image = brush.textureImage(); bool bitmap = true; - imageObject = addImage(image, &bitmap, brush.texture().cacheKey()); + imageObject = addImage(image, &bitmap, image.cacheKey()); if (imageObject != -1) { QImage::Format f = image.format(); if (f != QImage::Format_MonoLSB && f != QImage::Format_Mono) { diff --git a/src/widgets/styles/qfusionstyle_p_p.h b/src/widgets/styles/qfusionstyle_p_p.h index f0f00c4311..21d9d439a4 100644 --- a/src/widgets/styles/qfusionstyle_p_p.h +++ b/src/widgets/styles/qfusionstyle_p_p.h @@ -104,7 +104,7 @@ public: } QColor outline(const QPalette &pal) const { - if (!pal.window().texture().isNull()) + if (pal.window().style() == Qt::TexturePattern) return QColor(0, 0, 0, 160); return pal.background().color().darker(140); } @@ -117,7 +117,7 @@ public: } QColor tabFrameColor(const QPalette &pal) const { - if (!pal.button().texture().isNull()) + if (pal.window().style() == Qt::TexturePattern) return QColor(255, 255, 255, 8); return buttonColor(pal).lighter(104); } diff --git a/src/widgets/styles/qwindowsstyle.cpp b/src/widgets/styles/qwindowsstyle.cpp index 1336c04c42..e39a084cba 100644 --- a/src/widgets/styles/qwindowsstyle.cpp +++ b/src/widgets/styles/qwindowsstyle.cpp @@ -1525,8 +1525,14 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai p->setBackground(opt->palette.dark().color()); p->setBrush(br); } else { - QPixmap pm = opt->palette.brush(QPalette::Light).texture(); - br = !pm.isNull() ? QBrush(pm) : QBrush(opt->palette.light().color(), Qt::Dense4Pattern); + const QBrush paletteBrush = opt->palette.brush(QPalette::Light); + if (paletteBrush.style() == Qt::TexturePattern) { + if (qHasPixmapTexture(paletteBrush)) + br = QBrush(paletteBrush.texture()); + else + br = QBrush(paletteBrush.textureImage()); + } else + br = QBrush(opt->palette.light().color(), Qt::Dense4Pattern); p->setBackground(opt->palette.background().color()); p->setBrush(br); } @@ -1536,8 +1542,15 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai break; } case CE_ScrollBarSlider: if (!(opt->state & State_Enabled)) { - QPixmap pm = opt->palette.brush(QPalette::Light).texture(); - QBrush br = !pm.isNull() ? QBrush(pm) : QBrush(opt->palette.light().color(), Qt::Dense4Pattern); + QBrush br; + const QBrush paletteBrush = opt->palette.brush(QPalette::Light); + if (paletteBrush.style() == Qt::TexturePattern) { + if (qHasPixmapTexture(paletteBrush)) + br = QBrush(paletteBrush.texture()); + else + br = QBrush(paletteBrush.textureImage()); + } else + br = QBrush(opt->palette.light().color(), Qt::Dense4Pattern); p->setPen(Qt::NoPen); p->setBrush(br); p->setBackgroundMode(Qt::OpaqueMode); -- cgit v1.2.3