From a8351096dbe1b8c02bcae858fb03133a5dacffdd Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Mon, 4 Nov 2013 18:19:34 +0100 Subject: [PATCH] Fix ARGB image glyphs on Open GL ES2 or big endian Change Ie891665ad66e31692b69db02d34be8d303a7d631 accidentially removed the condition that would ensure ARGB glyphs would get swizzled on OpenGL ES2. This patch readds a condition to check that, and also fixes the same on big endian hosts by reusing the OpenGL ES2 code path. Change-Id: I55615c498261a43c50e5a6902a7e2e24cddc4f4b Reviewed-by: Gunnar Sletta --- src/gui/opengl/qopengltextureglyphcache.cpp | 27 ++++++++++++--------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/gui/opengl/qopengltextureglyphcache.cpp b/src/gui/opengl/qopengltextureglyphcache.cpp index 506aec0f43..061e8f4166 100644 --- a/src/gui/opengl/qopengltextureglyphcache.cpp +++ b/src/gui/opengl/qopengltextureglyphcache.cpp @@ -43,6 +43,8 @@ #include "qopenglpaintengine_p.h" #include "private/qopenglengineshadersource_p.h" #include "qopenglextensions_p.h" +#include +#include QT_BEGIN_NAMESPACE @@ -316,24 +318,27 @@ void QOpenGLTextureGlyphCache::fillTexture(const Coord &c, glyph_t glyph, QFixed if (mask.format() == QImage::Format_RGB32 // We need to make the alpha component equal to the average of the RGB values. // This is needed when drawing sub-pixel antialiased text on translucent targets. +#if defined(QT_OPENGL_ES_2) || Q_BYTE_ORDER == Q_BIG_ENDIAN + || mask.format() == QImage::Format_ARGB32_Premultiplied +#endif ) { for (int y = 0; y < maskHeight; ++y) { - quint32 *src = (quint32 *) mask.scanLine(y); + QRgb *src = (QRgb *) mask.scanLine(y); for (int x = 0; x < maskWidth; ++x) { - uchar r = src[x] >> 16; - uchar g = src[x] >> 8; - uchar b = src[x]; - quint32 avg; + int r = qRed(src[x]); + int g = qGreen(src[x]); + int b = qBlue(src[x]); + int avg; if (mask.format() == QImage::Format_RGB32) - avg = (quint32(r) + quint32(g) + quint32(b) + 1) / 3; // "+1" for rounding. + avg = (r + g + b + 1) / 3; // "+1" for rounding. else // Format_ARGB_Premultiplied - avg = src[x] >> 24; + avg = qAlpha(src[x]); -#if defined(QT_OPENGL_ES_2) + src[x] = qRgba(r, g, b, avg); +#if defined(QT_OPENGL_ES_2) || Q_BYTE_ORDER == Q_BIG_ENDIAN // swizzle the bits to accommodate for the GL_RGBA upload. - src[x] = (avg << 24) | (quint32(r) << 0) | (quint32(g) << 8) | (quint32(b) << 16); + src[x] = ARGB2RGBA(src[x]); #endif - src[x] = (src[x] & 0x00ffffff) | (avg << 24); } } } @@ -341,7 +346,7 @@ void QOpenGLTextureGlyphCache::fillTexture(const Coord &c, glyph_t glyph, QFixed glBindTexture(GL_TEXTURE_2D, m_textureResource->m_texture); if (mask.depth() == 32) { -#if defined(QT_OPENGL_ES_2) +#if defined(QT_OPENGL_ES_2) || Q_BYTE_ORDER == Q_BIG_ENDIAN glTexSubImage2D(GL_TEXTURE_2D, 0, c.x, c.y, maskWidth, maskHeight, GL_RGBA, GL_UNSIGNED_BYTE, mask.bits()); #else glTexSubImage2D(GL_TEXTURE_2D, 0, c.x, c.y, maskWidth, maskHeight, GL_BGRA, GL_UNSIGNED_BYTE, mask.bits());