diff options
author | Jens Bache-Wiig <jbache@trolltech.com> | 2010-06-02 10:58:17 (GMT) |
---|---|---|
committer | Jens Bache-Wiig <jbache@trolltech.com> | 2010-06-02 11:19:30 (GMT) |
commit | 7644a925dab5400280228cd2f7381030368c6913 (patch) | |
tree | 8a75c4740c62a507de70a363cb6b0919601a926e /src/gui/styles | |
parent | 417f3a4ece9403d1eb37ce0ecdf74cf670bdd0ff (diff) | |
download | Qt-7644a925dab5400280228cd2f7381030368c6913.zip Qt-7644a925dab5400280228cd2f7381030368c6913.tar.gz Qt-7644a925dab5400280228cd2f7381030368c6913.tar.bz2 |
More Pixmap cache key optimizations
Reviewed-by: ogoffart
Diffstat (limited to 'src/gui/styles')
-rw-r--r-- | src/gui/styles/qgtkpainter.cpp | 51 | ||||
-rw-r--r-- | src/gui/styles/qgtkstyle.cpp | 2 | ||||
-rw-r--r-- | src/gui/styles/qplastiquestyle.cpp | 37 | ||||
-rw-r--r-- | src/gui/styles/qwindowsstyle.cpp | 5 |
4 files changed, 52 insertions, 43 deletions
diff --git a/src/gui/styles/qgtkpainter.cpp b/src/gui/styles/qgtkpainter.cpp index 79c53e9..0217a39 100644 --- a/src/gui/styles/qgtkpainter.cpp +++ b/src/gui/styles/qgtkpainter.cpp @@ -241,8 +241,10 @@ void QGtkPainter::paintBoxGap(GtkWidget *gtkWidget, const gchar* part, if (rect.height() > maxHeight && (gap_side == GTK_POS_TOP || gap_side == GTK_POS_BOTTOM)) rect.setHeight(2 * border + 1); - QString gapExtras = QString(QLS("s %0 w %1 g %2")).arg(gap_side).arg(width).arg(x); - QString pixmapName = uniqueName(QLS(part), state, shadow, rect.size(), gtkWidget) + gapExtras; + QString pixmapName = uniqueName(QLS(part), state, shadow, rect.size(), gtkWidget) + % HexString<uchar>(gap_side) + % HexString<gint>(width) + % HexString<gint>(x); if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_box_gap (style, @@ -307,7 +309,7 @@ void QGtkPainter::paintBox(GtkWidget *gtkWidget, const gchar* part, rect.setHeight(2 * border + 1); QString pixmapName = uniqueName(QLS(part), state, shadow, - rect.size(), gtkWidget) + pmKey; + rect.size(), gtkWidget) % pmKey; if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_box (style, @@ -357,9 +359,11 @@ void QGtkPainter::paintHline(GtkWidget *gtkWidget, const gchar* part, return; QPixmap cache; - QString hLineExtras = QString(QLS("%0 %1 %2")).arg(x1).arg(x2).arg(y); QString pixmapName = uniqueName(QLS(part), state, GTK_SHADOW_NONE, rect.size(), gtkWidget) - + hLineExtras + pmKey; + % HexString<int>(x1) + % HexString<int>(x2) + % HexString<int>(y) + % pmKey; if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_hline (style, pixmap, @@ -384,9 +388,12 @@ void QGtkPainter::paintVline(GtkWidget *gtkWidget, const gchar* part, return; QPixmap cache; - QString vLineExtras = QString(QLS("%0 %1 %2")).arg(y1).arg(y2).arg(x); - QString pixmapName = uniqueName(QLS(part), state, GTK_SHADOW_NONE, rect.size(), - gtkWidget) + vLineExtras +pmKey; + QString pixmapName = uniqueName(QLS(part), state, GTK_SHADOW_NONE, rect.size(), gtkWidget) + % HexString<int>(y1) + % HexString<int>(y2) + % HexString<int>(x) + % pmKey; + if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_vline (style, pixmap, @@ -412,8 +419,10 @@ void QGtkPainter::paintExpander(GtkWidget *gtkWidget, return; QPixmap cache; - QString pixmapName = uniqueName(QLS(part), state, GTK_SHADOW_NONE, rect.size(), - gtkWidget) + QString::number(expander_state) + pmKey; + QString pixmapName = uniqueName(QLS(part), state, GTK_SHADOW_NONE, rect.size(), gtkWidget) + % HexString<uchar>(expander_state) + % pmKey; + if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_expander (style, pixmap, state, NULL, @@ -436,7 +445,7 @@ void QGtkPainter::paintFocus(GtkWidget *gtkWidget, const gchar* part, return; QPixmap cache; - QString pixmapName = uniqueName(QLS(part), state, GTK_SHADOW_NONE, rect.size(), gtkWidget) + pmKey; + QString pixmapName = uniqueName(QLS(part), state, GTK_SHADOW_NONE, rect.size(), gtkWidget) % pmKey; if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_focus (style, pixmap, state, NULL, gtkWidget, @@ -461,7 +470,7 @@ void QGtkPainter::paintResizeGrip(GtkWidget *gtkWidget, const gchar* part, return; QPixmap cache; - QString pixmapName = uniqueName(QLS(part), state, shadow, rect.size(), gtkWidget) + pmKey; + QString pixmapName = uniqueName(QLS(part), state, shadow, rect.size(), gtkWidget) % pmKey; if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_resize_grip (style, pixmap, state, NULL, gtkWidget, @@ -486,8 +495,9 @@ void QGtkPainter::paintArrow(GtkWidget *gtkWidget, const gchar* part, return; QPixmap cache; - QString pixmapName = uniqueName(QLS(part), state, shadow, rect.size()) + - QString::number((int)arrow_type) + pmKey; + QString pixmapName = uniqueName(QLS(part), state, shadow, rect.size()) + % HexString<uchar>(arrow_type) + % pmKey; GdkRectangle gtkCliprect = {0, 0, rect.width(), rect.height()}; int xOffset = m_cliprect.isValid() ? arrowrect.x() - m_cliprect.x() : 0; @@ -518,7 +528,8 @@ void QGtkPainter::paintHandle(GtkWidget *gtkWidget, const gchar* part, const QRe QPixmap cache; QString pixmapName = uniqueName(QLS(part), state, shadow, rect.size()) - + QString::number(orientation); + % HexString<uchar>(orientation); + if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_handle (style, pixmap, @@ -546,7 +557,7 @@ void QGtkPainter::paintSlider(GtkWidget *gtkWidget, const gchar* part, const QRe return; QPixmap cache; - QString pixmapName = uniqueName(QLS(part), state, shadow, rect.size(), gtkWidget) + pmKey; + QString pixmapName = uniqueName(QLS(part), state, shadow, rect.size(), gtkWidget) % pmKey; if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_slider (style, pixmap, @@ -577,7 +588,7 @@ void QGtkPainter::paintShadow(GtkWidget *gtkWidget, const gchar* part, QRect r = rect; QPixmap cache; - QString pixmapName = uniqueName(QLS(part), state, shadow, rect.size()) + pmKey; + QString pixmapName = uniqueName(QLS(part), state, shadow, rect.size()) % pmKey; if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_shadow(style, pixmap, state, shadow, NULL, gtkWidget, part, 0, 0, rect.width(), rect.height())); @@ -596,7 +607,7 @@ void QGtkPainter::paintFlatBox(GtkWidget *gtkWidget, const gchar* part, return; QRect r = rect; QPixmap cache; - QString pixmapName = uniqueName(QLS(part), state, shadow, rect.size()) + pmKey; + QString pixmapName = uniqueName(QLS(part), state, shadow, rect.size()) % pmKey; if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_flat_box (style, pixmap, @@ -623,8 +634,8 @@ void QGtkPainter::paintExtention(GtkWidget *gtkWidget, QRect r = rect; QPixmap cache; - QString pixmapName = uniqueName(QLS(part), state, shadow, rect.size(), gtkWidget); - pixmapName += QString::number(gap_pos); + QString pixmapName = uniqueName(QLS(part), state, shadow, rect.size(), gtkWidget) + % HexString<uchar>(gap_pos); if (!m_usePixmapCache || !QPixmapCache::find(pixmapName, cache)) { DRAW_TO_CACHE(QGtkStylePrivate::gtk_paint_extension (style, pixmap, state, shadow, diff --git a/src/gui/styles/qgtkstyle.cpp b/src/gui/styles/qgtkstyle.cpp index 9d6dc9a..5465c7b 100644 --- a/src/gui/styles/qgtkstyle.cpp +++ b/src/gui/styles/qgtkstyle.cpp @@ -692,7 +692,7 @@ void QGtkStyle::drawPrimitive(PrimitiveElement element, // thin rectangular images const int pmSize = 64; const int border = proxy()->pixelMetric(PM_DefaultFrameWidth, option, widget); - const QString pmKey = QString(QLS("windowframe %0")).arg(option->state); + const QString pmKey = QLatin1Literal("windowframe") % HexString<uint>(option->state); QPixmap pixmap; QRect pmRect(QPoint(0,0), QSize(pmSize, pmSize)); diff --git a/src/gui/styles/qplastiquestyle.cpp b/src/gui/styles/qplastiquestyle.cpp index c8711f6..20d9bd9 100644 --- a/src/gui/styles/qplastiquestyle.cpp +++ b/src/gui/styles/qplastiquestyle.cpp @@ -488,7 +488,9 @@ static void qBrushSetAlphaF(QBrush *brush, qreal alpha) // Modify the texture - ridiculously expensive. QPixmap texture = brush->texture(); QPixmap pixmap; - QString name = QString::fromLatin1("qbrushtexture-alpha-%1-%2").arg(alpha).arg(texture.cacheKey()); + QString name = QLatin1Literal("qbrushtexture-alpha") + % HexString<qreal>(alpha) + % HexString<qint64>(texture.cacheKey()); if (!QPixmapCache::find(name, pixmap)) { QImage image = texture.toImage(); QRgb *rgb = reinterpret_cast<QRgb *>(image.bits()); @@ -549,7 +551,10 @@ static QBrush qBrushLight(QBrush brush, int light) // Modify the texture - ridiculously expensive. QPixmap texture = brush.texture(); QPixmap pixmap; - QString name = QString::fromLatin1("qbrushtexture-light-%1-%2").arg(light).arg(texture.cacheKey()); + QString name = QLatin1Literal("qbrushtexture-light") + % HexString<int>(light) + % HexString<qint64>(texture.cacheKey()); + if (!QPixmapCache::find(name, pixmap)) { QImage image = texture.toImage(); QRgb *rgb = reinterpret_cast<QRgb *>(image.bits()); @@ -608,7 +613,10 @@ static QBrush qBrushDark(QBrush brush, int dark) // Modify the texture - ridiculously expensive. QPixmap texture = brush.texture(); QPixmap pixmap; - QString name = QString::fromLatin1("qbrushtexture-dark-%1-%2").arg(dark).arg(brush.texture().cacheKey()); + QString name = QLatin1Literal("qbrushtexture-dark") + % HexString<int>(dark) + % HexString<qint64>(texture.cacheKey()); + if (!QPixmapCache::find(name, pixmap)) { QImage image = texture.toImage(); QRgb *rgb = reinterpret_cast<QRgb *>(image.bits()); @@ -732,8 +740,12 @@ static QColor mergedColors(const QColor &colorA, const QColor &colorB, int facto static void qt_plastique_draw_gradient(QPainter *painter, const QRect &rect, const QColor &gradientStart, const QColor &gradientStop) { - QString gradientName; - gradientName.sprintf("%dx%d-%x-%x", rect.width(), rect.height(), gradientStart.rgba(), gradientStop.rgba()); + QString gradientName = QLatin1Literal("qplastique-g") + % HexString<int>(rect.width()) + % HexString<int>(rect.height()) + % HexString<QRgb>(gradientStart.rgba()) + % HexString<QRgb>(gradientStop.rgba()); + QPixmap cache; QPainter *p = painter; QRect r = rect; @@ -1092,14 +1104,6 @@ void QPlastiqueStyle::drawPrimitive(PrimitiveElement element, const QStyleOption Q_ASSERT(option); QColor borderColor = option->palette.background().color().darker(178); - QColor gradientStartColor = option->palette.button().color().lighter(104); - QColor gradientStopColor = option->palette.button().color().darker(105); - QColor highlightedGradientStartColor = option->palette.button().color().lighter(101); - QColor highlightedGradientStopColor = mergedColors(option->palette.button().color(), option->palette.highlight().color(), 85); - QColor highlightedBaseGradientStartColor = option->palette.base().color(); - QColor highlightedBaseGradientStopColor = mergedColors(option->palette.base().color().darker(105), option->palette.highlight().color(), 70); - QColor highlightedDarkInnerBorderColor = mergedColors(option->palette.button().color(), option->palette.highlight().color(), 35); - QColor highlightedLightInnerBorderColor = mergedColors(option->palette.button().color(), option->palette.highlight().color(), 58); QColor alphaCornerColor; if (widget) { // ### backgroundrole/foregroundrole should be part of the style option @@ -1107,13 +1111,7 @@ void QPlastiqueStyle::drawPrimitive(PrimitiveElement element, const QStyleOption } else { alphaCornerColor = mergedColors(option->palette.background().color(), borderColor); } - QColor alphaInnerColor = mergedColors(highlightedLightInnerBorderColor, gradientStartColor); - QColor alphaInnerColorNoHover = mergedColors(borderColor, gradientStartColor); QColor alphaTextColor = mergedColors(option->palette.background().color(), option->palette.text().color()); - QColor alphaLightTextColor = mergedColors(option->palette.background().color().lighter(250), option->palette.text().color().lighter(250)); - QColor lightShadow = option->palette.button().color().lighter(105); - QColor shadowGradientStartColor = option->palette.button().color().darker(115); - QColor shadow = shadowGradientStartColor; switch (element) { case PE_IndicatorButtonDropDown: @@ -2057,7 +2055,6 @@ void QPlastiqueStyle::drawControl(ControlElement element, const QStyleOption *op bool reverse = (tab->direction == Qt::RightToLeft); int lowerTop = selected ? 0 : 3; // to make the selected tab bigger than the rest - QRect adjustedRect; bool atEnd = (tab->position == QStyleOptionTab::End) || onlyTab; bool atBeginning = ((tab->position == QStyleOptionTab::Beginning) || onlyTab) && !leftCornerWidget; diff --git a/src/gui/styles/qwindowsstyle.cpp b/src/gui/styles/qwindowsstyle.cpp index 0314c6f..579dd0b 100644 --- a/src/gui/styles/qwindowsstyle.cpp +++ b/src/gui/styles/qwindowsstyle.cpp @@ -1388,8 +1388,9 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QRect r = opt->rect; int size = qMin(r.height(), r.width()); QPixmap pixmap; - QString pixmapName = QStyleHelper::uniqueName(QLatin1String("$qt_ia-") + QLatin1String(metaObject()->className()), opt, QSize(size, size)) - + QLatin1Char('-') + QString::number(pe); + QString pixmapName = QStyleHelper::uniqueName(QLatin1String("$qt_ia-") + % QLatin1String(metaObject()->className()), opt, QSize(size, size)) + % HexString<uint>(pe); if (!QPixmapCache::find(pixmapName, pixmap)) { int border = size/5; int sqsize = 2*(size/2); |