From 64df35c02d6a7bb13f7bf80f1e419a86eb100106 Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Thu, 14 Apr 2016 09:43:35 +0300 Subject: OpenGL: use const (and const APIs) more For CoW types, prefer const methods to avoid needless detach()ing. Change-Id: I211ae74434bf3705914764e1e9d02ae823a1be3a Reviewed-by: Edward Welbourne Reviewed-by: Marc Mutz --- .../gl2paintengineex/qglengineshadermanager.cpp | 2 +- src/opengl/gl2paintengineex/qglgradientcache.cpp | 19 ++++++++----------- src/opengl/qgl.cpp | 2 +- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/opengl/gl2paintengineex/qglengineshadermanager.cpp b/src/opengl/gl2paintengineex/qglengineshadermanager.cpp index fff64506ab..ec673e8726 100644 --- a/src/opengl/gl2paintengineex/qglengineshadermanager.cpp +++ b/src/opengl/gl2paintengineex/qglengineshadermanager.cpp @@ -333,7 +333,7 @@ QByteArray QGLEngineSharedShaders::snippetNameStr(SnippetName name) QGLEngineShaderProg *QGLEngineSharedShaders::findProgramInCache(const QGLEngineShaderProg &prog) { for (int i = 0; i < cachedPrograms.size(); ++i) { - QGLEngineShaderProg *cachedProg = cachedPrograms[i]; + QGLEngineShaderProg *cachedProg = cachedPrograms.at(i); if (*cachedProg == prog) { // Move the program to the top of the list as a poor-man's cache algo cachedPrograms.move(i, 0); diff --git a/src/opengl/gl2paintengineex/qglgradientcache.cpp b/src/opengl/gl2paintengineex/qglgradientcache.cpp index 943560da4a..b4ca49514f 100644 --- a/src/opengl/gl2paintengineex/qglgradientcache.cpp +++ b/src/opengl/gl2paintengineex/qglgradientcache.cpp @@ -102,7 +102,7 @@ GLuint QGL2GradientCache::getBuffer(const QGradient &gradient, qreal opacity) QMutexLocker lock(&m_mutex); quint64 hash_val = 0; - QGradientStops stops = gradient.stops(); + const QGradientStops stops = gradient.stops(); for (int i = 0; i < stops.size() && i <= 2; i++) hash_val += stops[i].second.rgba(); @@ -172,16 +172,12 @@ static inline uint qtToGlColor(uint c) void QGL2GradientCache::generateGradientColorTable(const QGradient& gradient, uint *colorTable, int size, qreal opacity) const { int pos = 0; - QGradientStops s = gradient.stops(); - QVector colors(s.size()); - - for (int i = 0; i < s.size(); ++i) - colors[i] = s[i].second.rgba(); // Qt LIES! It returns ARGB (on little-endian AND on big-endian) - + const QGradientStops s = gradient.stops(); bool colorInterpolation = (gradient.interpolationMode() == QGradient::ColorInterpolation); uint alpha = qRound(opacity * 256); - uint current_color = ARGB_COMBINE_ALPHA(colors[0], alpha); + // Qt LIES! It returns ARGB (on little-endian AND on big-endian) + uint current_color = ARGB_COMBINE_ALPHA(s[0].second.rgba(), alpha); qreal incr = 1.0 / qreal(size); qreal fpos = 1.5 * incr; colorTable[pos++] = qtToGlColor(qPremultiply(current_color)); @@ -195,9 +191,10 @@ void QGL2GradientCache::generateGradientColorTable(const QGradient& gradient, ui if (colorInterpolation) current_color = qPremultiply(current_color); - for (int i = 0; i < s.size() - 1; ++i) { + const int sLast = s.size() - 1; + for (int i = 0; i < sLast; ++i) { qreal delta = 1/(s[i+1].first - s[i].first); - uint next_color = ARGB_COMBINE_ALPHA(colors[i+1], alpha); + uint next_color = ARGB_COMBINE_ALPHA(s[i + 1].second.rgba(), alpha); if (colorInterpolation) next_color = qPremultiply(next_color); @@ -216,7 +213,7 @@ void QGL2GradientCache::generateGradientColorTable(const QGradient& gradient, ui Q_ASSERT(s.size() > 0); - uint last_color = qtToGlColor(qPremultiply(ARGB_COMBINE_ALPHA(colors[s.size() - 1], alpha))); + uint last_color = qtToGlColor(qPremultiply(ARGB_COMBINE_ALPHA(s[sLast].second.rgba(), alpha))); for (;pos < size; ++pos) colorTable[pos] = last_color; diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp index 5c8c1d58eb..fed1779388 100644 --- a/src/opengl/qgl.cpp +++ b/src/opengl/qgl.cpp @@ -5234,7 +5234,7 @@ void QGLContextGroup::removeShare(const QGLContext *context) { // Update context group representative. Q_ASSERT(group->m_shares.size() != 0); if (group->m_context == context) - group->m_context = group->m_shares[0]; + group->m_context = group->m_shares.at(0); // If there is only one context left, then make the list empty. if (group->m_shares.size() == 1) -- cgit v1.2.3