From 9709b10d691857209a684495799d163098bb44eb Mon Sep 17 00:00:00 2001 From: Tom Cooksey Date: Mon, 28 Dec 2009 10:31:22 +0100 Subject: Move the 0.5 offset we add for aliased rendering to updateMatrix() The old code set and unset a temporary matrix for every draw command when doing aliased rendering. Instead, we just use a flag to indicate that updateMatrix() should add the offset. This means the offset is added only once. When doing lots of small rendering operations on a (non-multisampled) QGLWidget, this gives up to 72% performance boost on the SGX. Reviewed-By: Kim --- .../gl2paintengineex/qpaintengineex_opengl2.cpp | 75 +++++++++++++--------- .../gl2paintengineex/qpaintengineex_opengl2_p.h | 5 +- 2 files changed, 47 insertions(+), 33 deletions(-) diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp index 32fa3dc..bfc640f 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp @@ -608,12 +608,18 @@ void QGL2PaintEngineExPrivate::updateMatrix() const GLfloat wfactor = 2.0f / width; const GLfloat hfactor = -2.0f / height; + if (addOffset) { + pmvMatrix[2][0] = (wfactor * (transform.dx() + 0.49f)) - transform.m33(); + pmvMatrix[2][1] = (hfactor * (transform.dy() + 0.49f)) + transform.m33(); + } else { + pmvMatrix[2][0] = (wfactor * transform.dx()) - transform.m33(); + pmvMatrix[2][1] = (hfactor * transform.dy()) + transform.m33(); + } + pmvMatrix[0][0] = (wfactor * transform.m11()) - transform.m13(); pmvMatrix[1][0] = (wfactor * transform.m21()) - transform.m23(); - pmvMatrix[2][0] = (wfactor * transform.dx() ) - transform.m33(); pmvMatrix[0][1] = (hfactor * transform.m12()) + transform.m13(); pmvMatrix[1][1] = (hfactor * transform.m22()) + transform.m23(); - pmvMatrix[2][1] = (hfactor * transform.dy() ) + transform.m33(); pmvMatrix[0][2] = transform.m13(); pmvMatrix[1][2] = transform.m23(); pmvMatrix[2][2] = transform.m33(); @@ -705,6 +711,12 @@ void QGL2PaintEngineExPrivate::drawTexture(const QGLRect& dest, const QGLRect& s // Setup for texture drawing currentBrush = noBrush; shaderManager->setSrcPixelType(pattern ? QGLEngineShaderManager::PatternSrc : QGLEngineShaderManager::ImageSrc); + + if (addOffset) { + addOffset = false; + matrixDirty = true; + } + if (prepareForDraw(opaque)) shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::ImageTexture), QT_IMAGE_TEXTURE_UNIT); @@ -867,6 +879,16 @@ void QGL2PaintEngineExPrivate::fill(const QVectorPath& path) { transferMode(BrushDrawingMode); + const QOpenGL2PaintEngineState *s = q->state(); + const bool newAddOffset = !(s->renderHints & QPainter::Antialiasing) && + (qbrush_style(currentBrush) == Qt::SolidPattern) && + !multisamplingAlwaysEnabled; + + if (addOffset != newAddOffset) { + addOffset = newAddOffset; + matrixDirty = true; + } + // Might need to call updateMatrix to re-calculate inverseScale if (matrixDirty) updateMatrix(); @@ -1278,31 +1300,14 @@ void QGL2PaintEngineEx::fill(const QVectorPath &path, const QBrush &brush) { Q_D(QGL2PaintEngineEx); - Qt::BrushStyle style = qbrush_style(brush); - if (style == Qt::NoBrush) + if (qbrush_style(brush) == Qt::NoBrush) return; + if (!d->inRenderText) ensureActive(); - QOpenGL2PaintEngineState *s = state(); - bool doOffset = !(s->renderHints & QPainter::Antialiasing) && - (style == Qt::SolidPattern) && - !d->multisamplingAlwaysEnabled; - - if (doOffset) { - d->temporaryTransform = s->matrix; - QTransform tx = QTransform::fromTranslate(.49, .49); - s->matrix = s->matrix * tx; - d->matrixDirty = true; - } - d->setBrush(brush); d->fill(path); - - if (doOffset) { - s->matrix = d->temporaryTransform; - d->matrixDirty = true; - } } extern bool qt_scaleForTransform(const QTransform &transform, qreal *scale); // qtransform.cpp @@ -1326,11 +1331,9 @@ void QGL2PaintEngineEx::stroke(const QVectorPath &path, const QPen &pen) ensureActive(); - bool doOffset = !(s->renderHints & QPainter::Antialiasing) && !d->multisamplingAlwaysEnabled; - if (doOffset) { - d->temporaryTransform = s->matrix; - QTransform tx = QTransform::fromTranslate(0.49, .49); - s->matrix = s->matrix * tx; + const bool newAddOffset = !(s->renderHints & QPainter::Antialiasing) && !d->multisamplingAlwaysEnabled; + if (d->addOffset != newAddOffset) { + d->addOffset = newAddOffset; d->matrixDirty = true; } @@ -1401,11 +1404,6 @@ void QGL2PaintEngineEx::stroke(const QVectorPath &path, const QPen &pen) d->updateClipScissorTest(); } - - if (doOffset) { - s->matrix = d->temporaryTransform; - d->matrixDirty = true; - } } void QGL2PaintEngineEx::penChanged() { } @@ -1613,6 +1611,11 @@ void QGL2PaintEngineExPrivate::drawCachedGlyphs(const QPointF &p, QFontEngineGly if (textureCoordinateArray.data() != oldTextureCoordinateDataPtr) glVertexAttribPointer(QT_TEXTURE_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, textureCoordinateArray.data()); + if (addOffset) { + addOffset = false; + matrixDirty = true; + } + QBrush pensBrush = q->state()->pen.brush(); setBrush(pensBrush); @@ -1725,6 +1728,11 @@ void QGL2PaintEngineEx::drawPixmaps(const QDrawPixmaps::Data *drawingData, int d d->textureCoordinateArray.clear(); d->opacityArray.reset(); + if (d->addOffset) { + d->addOffset = false; + d->matrixDirty = true; + } + bool allOpaque = true; for (int i = 0; i < dataCount; ++i) { @@ -2006,6 +2014,11 @@ void QGL2PaintEngineExPrivate::writeClip(const QVectorPath &path, uint value) { transferMode(BrushDrawingMode); + if (addOffset) { + addOffset = false; + matrixDirty = true; + } + if (matrixDirty) updateMatrix(); diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h b/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h index 8de4a82..4ace030 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h @@ -171,6 +171,7 @@ public: q(q_ptr), width(0), height(0), ctx(0), + addOffset(false), inverseScale(1), shaderManager(0), inRenderText(false) @@ -246,8 +247,6 @@ public: QBrush currentBrush; // May not be the state's brush! const QBrush noBrush; - GLfloat inverseScale; - QGL2PEXVertexArray vertexCoordinateArray; QGL2PEXVertexArray textureCoordinateArray; QDataBuffer opacityArray; @@ -255,7 +254,9 @@ public: GLfloat staticVertexCoordinateArray[8]; GLfloat staticTextureCoordinateArray[8]; + bool addOffset; // When enabled, adds a 0.49,0.49 offset to matrix in updateMatrix GLfloat pmvMatrix[3][3]; + GLfloat inverseScale; QGLEngineShaderManager* shaderManager; -- cgit v0.12