diff options
author | Morten Johan Sørvig <morten.sorvig@theqtcompany.com> | 2015-06-19 16:40:39 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2015-07-30 04:04:01 +0000 |
commit | dcd2debe625841ee8cba6d13a56cde7613c40358 (patch) | |
tree | d1d1e6c98d9cc5d81f29a389721acca6a9f7d150 /src/widgets/kernel/qopenglwidget.cpp | |
parent | 0167ace5f0a7e5ad80ce95efc99c86235bcf8c0d (diff) |
Enable non-integer device pixel ratio
Work around QPaintDevice::metric's int return type
by adding a new metric that returns a scaled devicePixelRatio.
Choose a scale factor that gives us more than enough
range.
The QPaintDevice::devicePixelRatio() convenience accessor
is public API and can unfortunately not be changed
to return a qreal. Add devicePixelRatioF() which
returns the (unscaled) devicePixelRatio.
Change all call sites of QPaintDevice::devicePixelRatio()
to use QPainDevice::devicePixelRatioF().
Task-number: QTBUG-46615
Change-Id: I97ec4000fe379b7ff5e1624a871ae2512790aad9
Reviewed-by: Paul Olav Tvete <paul.tvete@theqtcompany.com>
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Diffstat (limited to 'src/widgets/kernel/qopenglwidget.cpp')
-rw-r--r-- | src/widgets/kernel/qopenglwidget.cpp | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/src/widgets/kernel/qopenglwidget.cpp b/src/widgets/kernel/qopenglwidget.cpp index 1ee28f2e9a..ea7a761bf1 100644 --- a/src/widgets/kernel/qopenglwidget.cpp +++ b/src/widgets/kernel/qopenglwidget.cpp @@ -695,7 +695,7 @@ void QOpenGLWidgetPrivate::recreateFbo() format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); format.setSamples(samples); - const QSize deviceSize = q->size() * q->devicePixelRatio(); + const QSize deviceSize = q->size() * q->devicePixelRatioF(); fbo = new QOpenGLFramebufferObject(deviceSize, format); if (samples > 0) resolvedFbo = new QOpenGLFramebufferObject(deviceSize); @@ -704,7 +704,7 @@ void QOpenGLWidgetPrivate::recreateFbo() context->functions()->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); paintDevice->setSize(deviceSize); - paintDevice->setDevicePixelRatio(q->devicePixelRatio()); + paintDevice->setDevicePixelRatio(q->devicePixelRatioF()); emit q->resized(); } @@ -778,8 +778,8 @@ void QOpenGLWidgetPrivate::initialize() } paintDevice = new QOpenGLWidgetPaintDevice(q); - paintDevice->setSize(q->size() * q->devicePixelRatio()); - paintDevice->setDevicePixelRatio(q->devicePixelRatio()); + paintDevice->setSize(q->size() * q->devicePixelRatioF()); + paintDevice->setDevicePixelRatio(q->devicePixelRatioF()); context = ctx.take(); initialized = true; @@ -808,7 +808,7 @@ void QOpenGLWidgetPrivate::invokeUserPaint() QOpenGLFunctions *f = ctx->functions(); QOpenGLContextPrivate::get(ctx)->defaultFboRedirect = fbo->handle(); - f->glViewport(0, 0, q->width() * q->devicePixelRatio(), q->height() * q->devicePixelRatio()); + f->glViewport(0, 0, q->width() * q->devicePixelRatioF(), q->height() * q->devicePixelRatioF()); q->paintGL(); flushPending = true; @@ -859,8 +859,8 @@ QImage QOpenGLWidgetPrivate::grabFramebuffer() render(); resolveSamples(); q->makeCurrent(); - QImage res = qt_gl_read_framebuffer(q->size() * q->devicePixelRatio(), false, false); - res.setDevicePixelRatio(q->devicePixelRatio()); + QImage res = qt_gl_read_framebuffer(q->size() * q->devicePixelRatioF(), false, false); + res.setDevicePixelRatio(q->devicePixelRatioF()); return res; } @@ -879,7 +879,7 @@ void QOpenGLWidgetPrivate::resizeViewportFramebuffer() if (!initialized) return; - if (!fbo || q->size() * q->devicePixelRatio() != fbo->size()) + if (!fbo || q->size() * q->devicePixelRatioF() != fbo->size()) recreateFbo(); } @@ -1196,6 +1196,7 @@ int QOpenGLWidget::metric(QPaintDevice::PaintDeviceMetric metric) const return QWidget::metric(metric); QWidget *tlw = window(); + QWindow *window = tlw ? tlw->windowHandle() : 0; QScreen *screen = tlw && tlw->windowHandle() ? tlw->windowHandle()->screen() : 0; if (!screen && QGuiApplication::primaryScreen()) screen = QGuiApplication::primaryScreen(); @@ -1243,8 +1244,13 @@ int QOpenGLWidget::metric(QPaintDevice::PaintDeviceMetric metric) const else return qRound(dpmy * 0.0254); case PdmDevicePixelRatio: - if (screen) - return screen->devicePixelRatio(); + if (window) + return int(window->devicePixelRatio()); + else + return 1.0; + case PdmDevicePixelRatioScaled: + if (window) + return int(window->devicePixelRatio() * devicePixelRatioFScale()); else return 1.0; default: @@ -1304,7 +1310,7 @@ bool QOpenGLWidget::event(QEvent *e) } break; case QEvent::ScreenChangeInternal: - if (d->initialized && d->paintDevice->devicePixelRatio() != devicePixelRatio()) + if (d->initialized && d->paintDevice->devicePixelRatioF() != devicePixelRatioF()) d->recreateFbo(); break; default: |