aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp
diff options
context:
space:
mode:
authorGunnar Sletta <gunnar@sletta.org>2014-10-23 11:28:22 +0200
committerGunnar Sletta <gunnar@sletta.org>2014-10-23 12:06:57 +0200
commit6e883c535b91c55289d54aa639199ca0a4decaec (patch)
tree05903e82d27339da160c4ba0ea8030a9d1b8618c /src/quick/scenegraph/qsgdefaultglyphnode_p.cpp
parente3c6f39734ff54b2d7425f2edaaf6033ef2b1d9e (diff)
Fix pixelgrid snapping of native text on retina displays.
Change 63e6c9ada82dc8f16e705cef5f89292784b7ace4 introduced snapping to the pixel grid in the vertex shader for native text, but this code was broken on retina displays because it assumed integer only positions. Fix it by including the retina scale factor into the rounding. Task-number: QTBUG-38702 Change-Id: I84492b02d64f263c9fe030790e04cf79b0dc4e2f Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
Diffstat (limited to 'src/quick/scenegraph/qsgdefaultglyphnode_p.cpp')
-rw-r--r--src/quick/scenegraph/qsgdefaultglyphnode_p.cpp28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp b/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp
index b30a504da9..5cca474ea1 100644
--- a/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp
+++ b/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp
@@ -59,6 +59,21 @@ static inline QVector4D qsg_premultiply(const QVector4D &c, float globalOpacity)
return QVector4D(c.x() * o, c.y() * o, c.z() * o, o);
}
+static inline int qsg_device_pixel_ratio(QOpenGLContext *ctx)
+{
+ int devicePixelRatio = 1;
+ if (ctx->surface()->surfaceClass() == QSurface::Window) {
+ QWindow *w = static_cast<QWindow *>(ctx->surface());
+ if (QQuickWindow *qw = qobject_cast<QQuickWindow *>(w))
+ devicePixelRatio = qw->effectiveDevicePixelRatio();
+ else
+ devicePixelRatio = w->devicePixelRatio();
+ } else {
+ devicePixelRatio = ctx->screen()->devicePixelRatio();
+ }
+ return devicePixelRatio;
+}
+
class QSGTextMaskShader : public QSGMaterialShader
{
public:
@@ -102,6 +117,7 @@ void QSGTextMaskShader::initialize()
m_matrix_id = program()->uniformLocation("matrix");
m_color_id = program()->uniformLocation("color");
m_textureScale_id = program()->uniformLocation("textureScale");
+ program()->setUniformValue("dpr", (float) qsg_device_pixel_ratio(QOpenGLContext::currentContext()));
}
void QSGTextMaskShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect)
@@ -351,16 +367,8 @@ void QSGTextMaskMaterial::init(QFontEngine::GlyphFormat glyphFormat)
: QFontEngine::Format_A32;
}
- qreal devicePixelRatio;
- if (ctx->surface()->surfaceClass() == QSurface::Window) {
- QWindow *w = static_cast<QWindow *>(ctx->surface());
- if (QQuickWindow *qw = qobject_cast<QQuickWindow *>(w))
- devicePixelRatio = qw->effectiveDevicePixelRatio();
- else
- devicePixelRatio = w->devicePixelRatio();
- } else {
- devicePixelRatio = ctx->screen()->devicePixelRatio();
- }
+ qreal devicePixelRatio = qsg_device_pixel_ratio(ctx);
+
QTransform glyphCacheTransform = QTransform::fromScale(devicePixelRatio, devicePixelRatio);
if (!fontEngine->supportsTransformation(glyphCacheTransform))