summaryrefslogtreecommitdiffstats
path: root/src/gui/opengl
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/opengl')
-rw-r--r--src/gui/opengl/qopengl.h4
-rw-r--r--src/gui/opengl/qopengl_p.h6
-rw-r--r--src/gui/opengl/qopenglbuffer.h4
-rw-r--r--src/gui/opengl/qopenglcustomshaderstage_p.h4
-rw-r--r--src/gui/opengl/qopenglengineshadermanager_p.h4
-rw-r--r--src/gui/opengl/qopenglengineshadersource_p.h4
-rw-r--r--src/gui/opengl/qopenglextensions_p.h4
-rw-r--r--src/gui/opengl/qopenglframebufferobject.h4
-rw-r--r--src/gui/opengl/qopenglfunctions.cpp11
-rw-r--r--src/gui/opengl/qopenglfunctions.h4
-rw-r--r--src/gui/opengl/qopenglpaintdevice.h4
-rw-r--r--src/gui/opengl/qopenglpaintengine.cpp99
-rw-r--r--src/gui/opengl/qopenglpaintengine_p.h7
-rw-r--r--src/gui/opengl/qopenglshadercache_meego_p.h4
-rw-r--r--src/gui/opengl/qopenglshadercache_p.h4
-rw-r--r--src/gui/opengl/qopenglshaderprogram.h4
-rw-r--r--src/gui/opengl/qopengltexturecache.cpp7
-rw-r--r--src/gui/opengl/qopengltexturecache_p.h3
-rw-r--r--src/gui/opengl/qopengltextureglyphcache.cpp44
19 files changed, 116 insertions, 109 deletions
diff --git a/src/gui/opengl/qopengl.h b/src/gui/opengl/qopengl.h
index 9d29e07319..a4a626a0c4 100644
--- a/src/gui/opengl/qopengl.h
+++ b/src/gui/opengl/qopengl.h
@@ -46,8 +46,6 @@
#include <QtCore/qglobal.h>
-QT_BEGIN_HEADER
-
#if defined(QT_OPENGL_ES_2)
# if defined(Q_OS_MAC)
# include <OpenGLES/ES2/gl.h>
@@ -113,8 +111,6 @@ QT_BEGIN_NAMESPACE
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QT_NO_OPENGL
#endif // QOPENGL_H
diff --git a/src/gui/opengl/qopengl_p.h b/src/gui/opengl/qopengl_p.h
index 84245fb670..3cf636751a 100644
--- a/src/gui/opengl/qopengl_p.h
+++ b/src/gui/opengl/qopengl_p.h
@@ -46,11 +46,9 @@
#include <private/qopenglcontext_p.h>
#include <QtCore/qset.h>
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
-class QOpenGLExtensionMatcher
+class Q_GUI_EXPORT QOpenGLExtensionMatcher
{
public:
QOpenGLExtensionMatcher();
@@ -68,6 +66,4 @@ private:
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QOPENGL_H
diff --git a/src/gui/opengl/qopenglbuffer.h b/src/gui/opengl/qopenglbuffer.h
index 5ce8c3db49..014060086d 100644
--- a/src/gui/opengl/qopenglbuffer.h
+++ b/src/gui/opengl/qopenglbuffer.h
@@ -47,8 +47,6 @@
#include <QtCore/qscopedpointer.h>
#include <QtGui/qopengl.h>
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
@@ -128,8 +126,6 @@ private:
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QT_NO_OPENGL
#endif
diff --git a/src/gui/opengl/qopenglcustomshaderstage_p.h b/src/gui/opengl/qopenglcustomshaderstage_p.h
index 2accb03fa3..bb671b0d3b 100644
--- a/src/gui/opengl/qopenglcustomshaderstage_p.h
+++ b/src/gui/opengl/qopenglcustomshaderstage_p.h
@@ -55,8 +55,6 @@
#include <QOpenGLShaderProgram>
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
@@ -87,7 +85,5 @@ private:
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif
diff --git a/src/gui/opengl/qopenglengineshadermanager_p.h b/src/gui/opengl/qopenglengineshadermanager_p.h
index 462ffbf703..49c03a7fee 100644
--- a/src/gui/opengl/qopenglengineshadermanager_p.h
+++ b/src/gui/opengl/qopenglengineshadermanager_p.h
@@ -228,8 +228,6 @@
#include <private/qopenglcontext_p.h>
#include <private/qopenglcustomshaderstage_p.h>
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
@@ -508,6 +506,4 @@ private:
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif //QOPENGLENGINE_SHADER_MANAGER_H
diff --git a/src/gui/opengl/qopenglengineshadersource_p.h b/src/gui/opengl/qopenglengineshadersource_p.h
index f1b1dbe5a6..869bd057f2 100644
--- a/src/gui/opengl/qopenglengineshadersource_p.h
+++ b/src/gui/opengl/qopenglengineshadersource_p.h
@@ -56,8 +56,6 @@
#include "qopenglengineshadermanager_p.h"
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
@@ -523,6 +521,4 @@ static const char* const qopenglslRgbMaskFragmentShaderPass2 = "\n\
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // GLGC_SHADER_SOURCE_H
diff --git a/src/gui/opengl/qopenglextensions_p.h b/src/gui/opengl/qopenglextensions_p.h
index a4e473c049..265771ce1b 100644
--- a/src/gui/opengl/qopenglextensions_p.h
+++ b/src/gui/opengl/qopenglextensions_p.h
@@ -55,8 +55,6 @@
#include "qopenglfunctions.h"
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
@@ -193,6 +191,4 @@ inline void QOpenGLExtensions::glGetBufferSubData(GLenum target, qopengl_GLintpt
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QOPENGL_EXTENSIONS_P_H
diff --git a/src/gui/opengl/qopenglframebufferobject.h b/src/gui/opengl/qopenglframebufferobject.h
index 9dbef318f0..e4fd7c8e95 100644
--- a/src/gui/opengl/qopenglframebufferobject.h
+++ b/src/gui/opengl/qopenglframebufferobject.h
@@ -49,8 +49,6 @@
#include <QtCore/qscopedpointer.h>
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
@@ -161,8 +159,6 @@ private:
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QT_NO_OPENGL
#endif // QOPENGLFRAMEBUFFEROBJECT_H
diff --git a/src/gui/opengl/qopenglfunctions.cpp b/src/gui/opengl/qopenglfunctions.cpp
index ee5855d866..3737df7497 100644
--- a/src/gui/opengl/qopenglfunctions.cpp
+++ b/src/gui/opengl/qopenglfunctions.cpp
@@ -289,7 +289,7 @@ static int qt_gl_resolve_features()
return features;
#else
int features = 0;
- //QOpenGLFormat::OpenGLVersionFlags versions = QOpenGLFormat::openGLVersionFlags();
+ QSurfaceFormat format = QOpenGLContext::currentContext()->format();
QOpenGLExtensionMatcher extensions;
// Recognize features by extension name.
@@ -327,6 +327,10 @@ static int qt_gl_resolve_features()
QOpenGLFunctions::StencilSeparate |
QOpenGLFunctions::BlendEquationSeparate |
QOpenGLFunctions::NPOTTextures;
+
+ if (format.majorVersion() >= 3)
+ features |= QOpenGLFunctions::Framebuffers;
+
return features;
#endif
}
@@ -349,10 +353,13 @@ static int qt_gl_resolve_extensions()
extensions |= QOpenGLExtensions::BGRATextureFormat;
#else
+ QSurfaceFormat format = QOpenGLContext::currentContext()->format();
extensions |= QOpenGLExtensions::ElementIndexUint | QOpenGLExtensions::MapBuffer;
// Recognize features by extension name.
- if (extensionMatcher.match("GL_ARB_framebuffer_object")) {
+ if (format.majorVersion() >= 3
+ || extensionMatcher.match("GL_ARB_framebuffer_object"))
+ {
extensions |= QOpenGLExtensions::FramebufferMultisample |
QOpenGLExtensions::FramebufferBlit |
QOpenGLExtensions::PackedDepthStencil;
diff --git a/src/gui/opengl/qopenglfunctions.h b/src/gui/opengl/qopenglfunctions.h
index 5f3b63d0a0..100e3751be 100644
--- a/src/gui/opengl/qopenglfunctions.h
+++ b/src/gui/opengl/qopenglfunctions.h
@@ -71,8 +71,6 @@
#define Q_OPENGL_FUNCTIONS_DEBUG
#endif
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
@@ -1520,8 +1518,6 @@ inline void QOpenGLFunctions::glVertexAttribPointer(GLuint indx, GLint size, GLe
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QT_NO_OPENGL
#endif
diff --git a/src/gui/opengl/qopenglpaintdevice.h b/src/gui/opengl/qopenglpaintdevice.h
index 66850c73fc..731000f131 100644
--- a/src/gui/opengl/qopenglpaintdevice.h
+++ b/src/gui/opengl/qopenglpaintdevice.h
@@ -48,8 +48,6 @@
#include <QtGui/qopengl.h>
#include <QtGui/qopenglcontext.h>
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
@@ -91,8 +89,6 @@ protected:
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QT_NO_OPENGL
#endif // QOPENGLPAINTDEVICE_H
diff --git a/src/gui/opengl/qopenglpaintengine.cpp b/src/gui/opengl/qopenglpaintengine.cpp
index 9fd8a7ada7..555c47f265 100644
--- a/src/gui/opengl/qopenglpaintengine.cpp
+++ b/src/gui/opengl/qopenglpaintengine.cpp
@@ -624,7 +624,7 @@ void QOpenGL2PaintEngineExPrivate::transferMode(EngineMode newMode)
if (newMode == mode)
return;
- if (mode == TextDrawingMode || mode == ImageDrawingMode || mode == ImageArrayDrawingMode) {
+ if (mode != BrushDrawingMode) {
lastTextureUsed = GLuint(-1);
}
@@ -639,10 +639,12 @@ void QOpenGL2PaintEngineExPrivate::transferMode(EngineMode newMode)
setVertexAttributePointer(QT_TEXTURE_COORDS_ATTR, staticTextureCoordinateArray);
}
- if (newMode == ImageArrayDrawingMode) {
+ if (newMode == ImageArrayDrawingMode || newMode == ImageOpacityArrayDrawingMode) {
setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, (GLfloat*)vertexCoordinateArray.data());
setVertexAttributePointer(QT_TEXTURE_COORDS_ATTR, (GLfloat*)textureCoordinateArray.data());
- setVertexAttributePointer(QT_OPACITY_ATTR, (GLfloat*)opacityArray.data());
+
+ if (newMode == ImageOpacityArrayDrawingMode)
+ setVertexAttributePointer(QT_OPACITY_ATTR, (GLfloat*)opacityArray.data());
}
// This needs to change when we implement high-quality anti-aliasing...
@@ -1069,9 +1071,23 @@ void QOpenGL2PaintEngineExPrivate::resetClipIfNeeded()
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
}
+bool QOpenGL2PaintEngineExPrivate::prepareForCachedGlyphDraw(const QFontEngineGlyphCache &cache)
+{
+ Q_Q(QOpenGL2PaintEngineEx);
+
+ Q_ASSERT(cache.transform().type() <= QTransform::TxScale);
+
+ QTransform &transform = q->state()->matrix;
+ transform.scale(1.0 / cache.transform().m11(), 1.0 / cache.transform().m22());
+ bool ret = prepareForDraw(false);
+ transform.scale(cache.transform().m11(), cache.transform().m22());
+
+ return ret;
+}
+
bool QOpenGL2PaintEngineExPrivate::prepareForDraw(bool srcPixelsAreOpaque)
{
- if (brushTextureDirty && mode != ImageDrawingMode && mode != ImageArrayDrawingMode)
+ if (brushTextureDirty && (mode == TextDrawingMode || mode == BrushDrawingMode))
updateBrushTexture();
if (compositionModeDirty)
@@ -1091,12 +1107,12 @@ bool QOpenGL2PaintEngineExPrivate::prepareForDraw(bool srcPixelsAreOpaque)
}
QOpenGLEngineShaderManager::OpacityMode opacityMode;
- if (mode == ImageArrayDrawingMode) {
+ if (mode == ImageOpacityArrayDrawingMode) {
opacityMode = QOpenGLEngineShaderManager::AttributeOpacity;
} else {
opacityMode = stateHasOpacity ? QOpenGLEngineShaderManager::UniformOpacity
: QOpenGLEngineShaderManager::NoOpacity;
- if (stateHasOpacity && (mode != ImageDrawingMode)) {
+ if (stateHasOpacity && (mode != ImageDrawingMode && mode != ImageArrayDrawingMode)) {
// Using a brush
bool brushIsPattern = (currentBrush.style() >= Qt::Dense1Pattern) &&
(currentBrush.style() <= Qt::DiagCrossPattern);
@@ -1116,7 +1132,7 @@ bool QOpenGL2PaintEngineExPrivate::prepareForDraw(bool srcPixelsAreOpaque)
matrixUniformDirty = true;
}
- if (brushUniformsDirty && mode != ImageDrawingMode && mode != ImageArrayDrawingMode)
+ if (brushUniformsDirty && (mode == TextDrawingMode || mode == BrushDrawingMode))
updateBrushUniforms();
if (opacityMode == QOpenGLEngineShaderManager::UniformOpacity && opacityUniformDirty) {
@@ -1407,11 +1423,9 @@ void QOpenGL2PaintEngineEx::drawStaticTextItem(QStaticTextItem *textItem)
ensureActive();
QPainterState *s = state();
- float det = s->matrix.determinant();
- // don't try to cache huge fonts or vastly transformed fonts
QFontEngine *fontEngine = textItem->fontEngine();
- if (shouldDrawCachedGlyphs(fontEngine, s->matrix) && det >= 0.25f && det <= 4.f) {
+ if (shouldDrawCachedGlyphs(fontEngine, s->matrix)) {
QFontEngineGlyphCache::Type glyphType = fontEngine->glyphFormat >= 0
? QFontEngineGlyphCache::Type(textItem->fontEngine()->glyphFormat)
: d->glyphCacheType;
@@ -1461,13 +1475,6 @@ void QOpenGL2PaintEngineEx::drawTextItem(const QPointF &p, const QTextItem &text
QTransform::TransformationType txtype = s->matrix.type();
- float det = s->matrix.determinant();
- bool drawCached = txtype < QTransform::TxProject;
-
- // don't try to cache huge fonts or vastly transformed fonts
- if (!shouldDrawCachedGlyphs(ti.fontEngine, s->matrix) || det < 0.25f || det > 4.f)
- drawCached = false;
-
QFontEngineGlyphCache::Type glyphType = ti.fontEngine->glyphFormat >= 0
? QFontEngineGlyphCache::Type(ti.fontEngine->glyphFormat)
: d->glyphCacheType;
@@ -1482,7 +1489,7 @@ void QOpenGL2PaintEngineEx::drawTextItem(const QPointF &p, const QTextItem &text
}
}
- if (drawCached) {
+ if (shouldDrawCachedGlyphs(ti.fontEngine, s->matrix)) {
QVarLengthArray<QFixedPoint> positions;
QVarLengthArray<glyph_t> glyphs;
QTransform matrix = QTransform::fromTranslate(p.x(), p.y());
@@ -1531,6 +1538,12 @@ namespace {
// #define QT_OPENGL_DRAWCACHEDGLYPHS_INDEX_ARRAY_VBO
+bool QOpenGL2PaintEngineEx::shouldDrawCachedGlyphs(QFontEngine *fontEngine, const QTransform &t) const
+{
+ // Don't try to cache vastly transformed fonts
+ return t.type() < QTransform::TxProject && QPaintEngineEx::shouldDrawCachedGlyphs(fontEngine, t);
+}
+
void QOpenGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type glyphType,
QStaticTextItem *staticTextItem)
{
@@ -1542,10 +1555,18 @@ void QOpenGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type
bool recreateVertexArrays = false;
QFontEngine *fe = staticTextItem->fontEngine();
+ // We allow scaling, so that the glyph-cache will contain glyphs with the
+ // appropriate resolution in the case of displays with a device-pixel-ratio != 1.
+ QTransform transform = s->matrix.type() < QTransform::TxRotate ?
+ QTransform::fromScale(qAbs(s->matrix.m11()), qAbs(s->matrix.m22())) :
+ QTransform::fromScale(
+ QVector2D(s->matrix.m11(), s->matrix.m12()).length(),
+ QVector2D(s->matrix.m21(), s->matrix.m22()).length());
+
QOpenGLTextureGlyphCache *cache =
- (QOpenGLTextureGlyphCache *) fe->glyphCache(cacheKey, glyphType, QTransform());
+ (QOpenGLTextureGlyphCache *) fe->glyphCache(cacheKey, glyphType, transform);
if (!cache || cache->cacheType() != glyphType || cache->contextGroup() == 0) {
- cache = new QOpenGLTextureGlyphCache(glyphType, QTransform());
+ cache = new QOpenGLTextureGlyphCache(glyphType, transform);
fe->setGlyphCache(cacheKey, cache);
recreateVertexArrays = true;
}
@@ -1583,7 +1604,10 @@ void QOpenGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type
if (cache->width() == 0 || cache->height() == 0)
return;
- transferMode(TextDrawingMode);
+ if (glyphType == QFontEngineGlyphCache::Raster_ARGB)
+ transferMode(ImageArrayDrawingMode);
+ else
+ transferMode(TextDrawingMode);
int margin = fe->glyphMargin(glyphType);
@@ -1637,8 +1661,8 @@ void QOpenGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type
if (c.isNull())
continue;
- int x = qFloor(staticTextItem->glyphPositions[i].x) + c.baseLineX - margin;
- int y = qRound(staticTextItem->glyphPositions[i].y) - c.baseLineY - margin;
+ int x = qFloor(staticTextItem->glyphPositions[i].x.toReal() * cache->transform().m11()) + c.baseLineX - margin;
+ int y = qRound(staticTextItem->glyphPositions[i].y.toReal() * cache->transform().m22()) - c.baseLineY - margin;
vertexCoordinates->addQuad(QRectF(x, y, c.w, c.h));
textureCoordinates->addQuad(QRectF(c.x*dx, c.y*dy, c.w * dx, c.h * dy));
@@ -1679,8 +1703,10 @@ void QOpenGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type
#endif
}
- setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, (GLfloat*)vertexCoordinates->data());
- setVertexAttributePointer(QT_TEXTURE_COORDS_ATTR, (GLfloat*)textureCoordinates->data());
+ if (glyphType != QFontEngineGlyphCache::Raster_ARGB || recreateVertexArrays) {
+ setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, (GLfloat*)vertexCoordinates->data());
+ setVertexAttributePointer(QT_TEXTURE_COORDS_ATTR, (GLfloat*)textureCoordinates->data());
+ }
if (!snapToPixelGrid) {
snapToPixelGrid = true;
@@ -1711,9 +1737,9 @@ void QOpenGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type
}
compositionModeDirty = false; // I can handle this myself, thank you very much
- prepareForDraw(false); // Text always causes src pixels to be transparent
+ prepareForCachedGlyphDraw(*cache);
- // prepareForDraw() have set the opacity on the current shader, so the opacity state can now be reset.
+ // prepareForCachedGlyphDraw() have set the opacity on the current shader, so the opacity state can now be reset.
if (compMode == QPainter::CompositionMode_Source) {
q->state()->opacity = oldOpacity;
opacityUniformDirty = true;
@@ -1734,7 +1760,7 @@ void QOpenGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type
}
compositionModeDirty = false; // I can handle this myself, thank you very much
- prepareForDraw(false); // Text always causes src pixels to be transparent
+ prepareForCachedGlyphDraw(*cache);
glEnable(GL_BLEND);
glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_COLOR);
@@ -1758,22 +1784,31 @@ void QOpenGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type
}
compositionModeDirty = false;
- prepareForDraw(false); // Text always causes src pixels to be transparent
+ prepareForCachedGlyphDraw(*cache);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE);
}
compositionModeDirty = true;
+ } else if (glyphType == QFontEngineGlyphCache::Raster_ARGB) {
+ currentBrush = noBrush;
+ shaderManager->setSrcPixelType(QOpenGLEngineShaderManager::ImageSrc);
+ if (prepareForCachedGlyphDraw(*cache))
+ shaderManager->currentProgram()->setUniformValue(location(QOpenGLEngineShaderManager::ImageTexture), QT_IMAGE_TEXTURE_UNIT);
} else {
// Greyscale/mono glyphs
shaderManager->setMaskType(QOpenGLEngineShaderManager::PixelMask);
- prepareForDraw(false); // Text always causes src pixels to be transparent
+ prepareForCachedGlyphDraw(*cache);
}
QOpenGLTextureGlyphCache::FilterMode filterMode = (s->matrix.type() > QTransform::TxTranslate)?QOpenGLTextureGlyphCache::Linear:QOpenGLTextureGlyphCache::Nearest;
if (lastMaskTextureUsed != cache->texture() || cache->filterMode() != filterMode) {
- funcs.glActiveTexture(GL_TEXTURE0 + QT_MASK_TEXTURE_UNIT);
+ if (glyphType == QFontEngineGlyphCache::Raster_ARGB)
+ funcs.glActiveTexture(GL_TEXTURE0 + QT_IMAGE_TEXTURE_UNIT);
+ else
+ funcs.glActiveTexture(GL_TEXTURE0 + QT_MASK_TEXTURE_UNIT);
+
if (lastMaskTextureUsed != cache->texture()) {
glBindTexture(GL_TEXTURE_2D, cache->texture());
lastMaskTextureUsed = cache->texture();
@@ -1889,7 +1924,7 @@ void QOpenGL2PaintEngineExPrivate::drawPixmapFragments(const QPainter::PixmapFra
funcs.glActiveTexture(GL_TEXTURE0 + QT_IMAGE_TEXTURE_UNIT);
GLuint id = QOpenGLTextureCache::cacheForContext(ctx)->bindTexture(ctx, pixmap);
- transferMode(ImageArrayDrawingMode);
+ transferMode(ImageOpacityArrayDrawingMode);
bool isBitmap = pixmap.isQBitmap();
bool isOpaque = !isBitmap && (!pixmap.hasAlpha() || (hints & QPainter::OpaqueHint)) && allOpaque;
diff --git a/src/gui/opengl/qopenglpaintengine_p.h b/src/gui/opengl/qopenglpaintengine_p.h
index 93e1b4232e..d51f0e5256 100644
--- a/src/gui/opengl/qopenglpaintengine_p.h
+++ b/src/gui/opengl/qopenglpaintengine_p.h
@@ -70,7 +70,8 @@ enum EngineMode {
ImageDrawingMode,
TextDrawingMode,
BrushDrawingMode,
- ImageArrayDrawingMode
+ ImageArrayDrawingMode,
+ ImageOpacityArrayDrawingMode
};
QT_BEGIN_NAMESPACE
@@ -157,7 +158,8 @@ public:
void setRenderTextActive(bool);
bool isNativePaintingActive() const;
- bool supportsTransformations(QFontEngine *, const QTransform &) const { return true; }
+ bool requiresPretransformedGlyphPositions(QFontEngine *, const QTransform &) const { return false; }
+ bool shouldDrawCachedGlyphs(QFontEngine *, const QTransform &) const;
private:
Q_DISABLE_COPY(QOpenGL2PaintEngineEx)
@@ -235,6 +237,7 @@ public:
void setBrush(const QBrush& brush);
void transferMode(EngineMode newMode);
bool prepareForDraw(bool srcPixelsAreOpaque); // returns true if the program has changed
+ bool prepareForCachedGlyphDraw(const QFontEngineGlyphCache &cache);
inline void useSimpleShader();
inline GLuint location(const QOpenGLEngineShaderManager::Uniform uniform) {
return shaderManager->getUniformLocation(uniform);
diff --git a/src/gui/opengl/qopenglshadercache_meego_p.h b/src/gui/opengl/qopenglshadercache_meego_p.h
index 3d62d79ee7..d1c14150d1 100644
--- a/src/gui/opengl/qopenglshadercache_meego_p.h
+++ b/src/gui/opengl/qopenglshadercache_meego_p.h
@@ -68,8 +68,6 @@
# include <syslog.h>
#endif
-QT_BEGIN_HEADER
-
/*
This cache stores internal Qt shader programs in shared memory.
@@ -450,7 +448,5 @@ QT_END_NAMESPACE
#endif
-QT_END_HEADER
-
#endif
#endif
diff --git a/src/gui/opengl/qopenglshadercache_p.h b/src/gui/opengl/qopenglshadercache_p.h
index 0e0b6c3735..17305539df 100644
--- a/src/gui/opengl/qopenglshadercache_p.h
+++ b/src/gui/opengl/qopenglshadercache_p.h
@@ -59,8 +59,6 @@
# include "qopenglshadercache_meego_p.h"
#else
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
@@ -91,7 +89,5 @@ public:
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif
#endif
diff --git a/src/gui/opengl/qopenglshaderprogram.h b/src/gui/opengl/qopenglshaderprogram.h
index cd05d0f96b..f371326239 100644
--- a/src/gui/opengl/qopenglshaderprogram.h
+++ b/src/gui/opengl/qopenglshaderprogram.h
@@ -50,8 +50,6 @@
#include <QtGui/qvector4d.h>
#include <QtGui/qmatrix4x4.h>
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
@@ -293,8 +291,6 @@ private:
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QT_NO_OPENGL
#endif
diff --git a/src/gui/opengl/qopengltexturecache.cpp b/src/gui/opengl/qopengltexturecache.cpp
index fffc3688e3..94b82885ff 100644
--- a/src/gui/opengl/qopengltexturecache.cpp
+++ b/src/gui/opengl/qopengltexturecache.cpp
@@ -95,9 +95,10 @@ void QOpenGLTextureCacheWrapper::cleanupTexturesForPixmapData(QPlatformPixmap *p
cleanupTexturesForCacheKey(pmd->cacheKey());
}
-QOpenGLTextureCache::QOpenGLTextureCache(QOpenGLContext *ctx)
+QOpenGLTextureCache::QOpenGLTextureCache(QOpenGLContext *ctx, bool useByteSwapImage)
: QOpenGLSharedResource(ctx->shareGroup())
, m_cache(64 * 1024) // 64 MB cache
+ , m_useByteSwapImage(useByteSwapImage)
{
}
@@ -180,7 +181,9 @@ GLuint QOpenGLTextureCache::bindTexture(QOpenGLContext *context, qint64 key, con
QImage tx = image.convertToFormat(QImage::Format_ARGB32_Premultiplied);
- qgl_byteSwapImage(tx);
+ // Performance could be improved by skipping qgl_byteSwapImage().
+ if (m_useByteSwapImage)
+ qgl_byteSwapImage(tx);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tx.width(), tx.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, const_cast<const QImage &>(tx).bits());
diff --git a/src/gui/opengl/qopengltexturecache_p.h b/src/gui/opengl/qopengltexturecache_p.h
index 2e82d5f373..d4d3f00069 100644
--- a/src/gui/opengl/qopengltexturecache_p.h
+++ b/src/gui/opengl/qopengltexturecache_p.h
@@ -78,7 +78,7 @@ class Q_GUI_EXPORT QOpenGLTextureCache : public QOpenGLSharedResource
public:
static QOpenGLTextureCache *cacheForContext(QOpenGLContext *context);
- QOpenGLTextureCache(QOpenGLContext *);
+ QOpenGLTextureCache(QOpenGLContext *, bool useByteSwapImage = true);
~QOpenGLTextureCache();
GLuint bindTexture(QOpenGLContext *context, const QPixmap &pixmap);
@@ -94,6 +94,7 @@ private:
QMutex m_mutex;
QCache<quint64, QOpenGLCachedTexture> m_cache;
+ bool m_useByteSwapImage;
};
QT_END_NAMESPACE
diff --git a/src/gui/opengl/qopengltextureglyphcache.cpp b/src/gui/opengl/qopengltextureglyphcache.cpp
index b751629117..83f407575e 100644
--- a/src/gui/opengl/qopengltextureglyphcache.cpp
+++ b/src/gui/opengl/qopengltextureglyphcache.cpp
@@ -120,7 +120,7 @@ void QOpenGLTextureGlyphCache::createTextureData(int width, int height)
m_textureResource->m_width = width;
m_textureResource->m_height = height;
- if (m_type == QFontEngineGlyphCache::Raster_RGBMask) {
+ if (m_type == QFontEngineGlyphCache::Raster_RGBMask || m_type == QFontEngineGlyphCache::Raster_ARGB) {
QVarLengthArray<uchar> data(width * height * 4);
for (int i = 0; i < data.size(); ++i)
data[i] = 0;
@@ -314,30 +314,40 @@ void QOpenGLTextureGlyphCache::fillTexture(const Coord &c, glyph_t glyph, QFixed
for (int x = 0; x < maskWidth; ++x)
src[x] = -src[x]; // convert 0 and 1 into 0 and 255
}
- } else if (mask.format() == QImage::Format_RGB32) {
- // Make the alpha component equal to the average of the RGB values.
- // This is needed when drawing sub-pixel antialiased text on translucent targets.
- for (int y = 0; y < maskHeight; ++y) {
- quint32 *src = (quint32 *) 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 = (quint32(r) + quint32(g) + quint32(b) + 1) / 3; // "+1" for rounding.
+ } else if (mask.depth() == 32) {
+ 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)
+ || !hasBGRA // We need to reverse the bytes
+#endif
+ ) {
+ for (int y = 0; y < maskHeight; ++y) {
+ quint32 *src = (quint32 *) 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;
+ if (mask.format() == QImage::Format_RGB32)
+ avg = (quint32(r) + quint32(g) + quint32(b) + 1) / 3; // "+1" for rounding.
+ else // Format_ARGB_Premultiplied
+ avg = src[x] >> 24;
#if defined(QT_OPENGL_ES_2)
- if (!hasBGRA) {
- // Reverse bytes to match GL_RGBA
- src[x] = (avg << 24) | (quint32(r) << 0) | (quint32(g) << 8) | (quint32(b) << 16);
- } else
+ if (!hasBGRA) {
+ // Reverse bytes to match GL_RGBA
+ src[x] = (avg << 24) | (quint32(r) << 0) | (quint32(g) << 8) | (quint32(b) << 16);
+ } else
#endif
- src[x] = (src[x] & 0x00ffffff) | (avg << 24);
+ src[x] = (src[x] & 0x00ffffff) | (avg << 24);
+ }
}
}
}
glBindTexture(GL_TEXTURE_2D, m_textureResource->m_texture);
- if (mask.format() == QImage::Format_RGB32) {
+ if (mask.depth() == 32) {
#if defined(QT_OPENGL_ES_2)
glTexSubImage2D(GL_TEXTURE_2D, 0, c.x, c.y, maskWidth, maskHeight, hasBGRA ? GL_BGRA_EXT : GL_RGBA, GL_UNSIGNED_BYTE, mask.bits());
#else