summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMorten Johan Sørvig <morten.sorvig@digia.com>2014-03-18 13:36:10 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-03-20 08:35:24 +0100
commit5e03c4d97f72f96a8fc97aa87f24c41a043048b7 (patch)
tree59a0a1da9840e331c2e7b7a635b143b747b3a7d3 /src
parent07549de92bcb2e138c2f3c8d555092054a5359db (diff)
QOpenGLWidget retina support.
Use device pixels where appropriate. Change-Id: Ia953e6da4034eecbfccf798701ec1b850eea9d5b Reviewed-by: Paul Olav Tvete <paul.tvete@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/gui/painting/qplatformbackingstore.cpp32
-rw-r--r--src/widgets/kernel/qopenglwidget.cpp2
2 files changed, 29 insertions, 5 deletions
diff --git a/src/gui/painting/qplatformbackingstore.cpp b/src/gui/painting/qplatformbackingstore.cpp
index 4843e93858..add3624feb 100644
--- a/src/gui/painting/qplatformbackingstore.cpp
+++ b/src/gui/painting/qplatformbackingstore.cpp
@@ -186,6 +186,28 @@ void QPlatformTextureList::clear()
*/
#ifndef QT_NO_OPENGL
+
+static QRect deviceRect(const QRect &rect, QWindow *window)
+{
+ QRect deviceRect(rect.topLeft() * window->devicePixelRatio(),
+ rect.size() * window->devicePixelRatio());
+ return deviceRect;
+}
+
+static QRegion deviceRegion(const QRegion &region, QWindow *window)
+{
+ if (!(window->devicePixelRatio() > 1))
+ return region;
+
+ QVector<QRect> rects;
+ foreach (QRect rect, region.rects())
+ rects.append(deviceRect(rect, window));
+
+ QRegion deviceRegion;
+ deviceRegion.setRects(rects.constData(), rects.count());
+ return deviceRegion;
+}
+
/*!
Flushes the given \a region from the specified \a window onto the
screen, and composes it with the specified \a textures.
@@ -205,7 +227,7 @@ void QPlatformBackingStore::composeAndFlush(QWindow *window, const QRegion &regi
context->makeCurrent(window);
QOpenGLFunctions *funcs = context->functions();
- funcs->glViewport(0, 0, window->width(), window->height());
+ funcs->glViewport(0, 0, window->width() * window->devicePixelRatio(), window->height() * window->devicePixelRatio());
if (!d_ptr->blitter) {
d_ptr->blitter = new QOpenGLTextureBlitter;
@@ -214,16 +236,18 @@ void QPlatformBackingStore::composeAndFlush(QWindow *window, const QRegion &regi
d_ptr->blitter->bind();
- QRect windowRect(QPoint(), window->size());
+ QRect windowRect(QPoint(), window->size() * window->devicePixelRatio());
+
for (int i = 0; i < textures->count(); ++i) {
GLuint textureId = textures->textureId(i);
funcs->glBindTexture(GL_TEXTURE_2D, textureId);
- QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(textures->geometry(i), windowRect);
+ QRect targetRect = deviceRect(textures->geometry(i), window);
+ QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(targetRect, windowRect);
d_ptr->blitter->blit(textureId, target, QOpenGLTextureBlitter::OriginBottomLeft);
}
- GLuint textureId = toTexture(region);
+ GLuint textureId = toTexture(deviceRegion(region, window));
if (!textureId)
return;
diff --git a/src/widgets/kernel/qopenglwidget.cpp b/src/widgets/kernel/qopenglwidget.cpp
index e05c03d952..66aacadb28 100644
--- a/src/widgets/kernel/qopenglwidget.cpp
+++ b/src/widgets/kernel/qopenglwidget.cpp
@@ -163,7 +163,7 @@ void QOpenGLWidget::resizeEvent(QResizeEvent *)
d->context.makeCurrent(d->surface());
delete d->fbo; // recreate when resized
- d->fbo = new QOpenGLFramebufferObject(size());
+ d->fbo = new QOpenGLFramebufferObject(size() * devicePixelRatio());
d->fbo->bind();
QOpenGLFunctions *funcs = d->context.functions();
funcs->glBindTexture(GL_TEXTURE_2D, d->fbo->texture());