diff options
| author | Morten Johan Sorvig <morten.sorvig@digia.com> | 2012-12-14 17:25:56 +0100 |
|---|---|---|
| committer | Tor Arne Vestbø <tor.arne.vestbo@digia.com> | 2013-02-27 23:55:55 +0100 |
| commit | a593de41edfac04f3e3c6dd5bb024254e7e6ff4e (patch) | |
| tree | 102c21430083e2023485501333e8883940b2114d | |
| parent | d665ba2a9454dbd2ed9f4384e04c31d232b0c5eb (diff) | |
| download | qtbase-a593de41edfac04f3e3c6dd5bb024254e7e6ff4e.tar.gz | |
iOS: Retina display support.
Scale the OpenGL paint device size and physical dpi
by the device pixel ratio.
Change-Id: I8b576f23129aafc47371795151c548663e94ad52
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@digia.com>
| -rw-r--r-- | src/gui/opengl/qopenglpaintdevice.cpp | 14 | ||||
| -rw-r--r-- | src/gui/opengl/qopenglpaintdevice.h | 1 | ||||
| -rw-r--r-- | src/plugins/platforms/ios/qiosbackingstore.mm | 10 | ||||
| -rw-r--r-- | src/plugins/platforms/ios/qioswindow.h | 2 | ||||
| -rw-r--r-- | src/plugins/platforms/ios/qioswindow.mm | 21 |
5 files changed, 41 insertions, 7 deletions
diff --git a/src/gui/opengl/qopenglpaintdevice.cpp b/src/gui/opengl/qopenglpaintdevice.cpp index 0b3d9dc46d..d55d6a91bf 100644 --- a/src/gui/opengl/qopenglpaintdevice.cpp +++ b/src/gui/opengl/qopenglpaintdevice.cpp @@ -116,6 +116,7 @@ public: qreal dpmx; qreal dpmy; + qreal devicePixelRatio; bool flipped; @@ -178,6 +179,7 @@ QOpenGLPaintDevicePrivate::QOpenGLPaintDevicePrivate(const QSize &sz) , ctx(QOpenGLContext::currentContext()) , dpmx(qt_defaultDpiX() * 100. / 2.54) , dpmy(qt_defaultDpiY() * 100. / 2.54) + , devicePixelRatio(1.0) , flipped(false) , engine(0) { @@ -249,6 +251,14 @@ void QOpenGLPaintDevice::setSize(const QSize &size) } /*! + Sets the device pixel ratio for the paint device to \a devicePixelRatio. +*/ +void QOpenGLPaintDevice::setDevicePixelRatio(qreal devicePixelRatio) +{ + d_ptr->devicePixelRatio = devicePixelRatio; +} + +/*! \reimp */ @@ -272,9 +282,9 @@ int QOpenGLPaintDevice::metric(QPaintDevice::PaintDeviceMetric metric) const case PdmDpiY: return qRound(d_ptr->dpmy * 0.0254); case PdmPhysicalDpiX: - return qRound(d_ptr->dpmx * 0.0254); + return qRound(d_ptr->dpmx * 0.0254 * d_ptr->devicePixelRatio); case PdmPhysicalDpiY: - return qRound(d_ptr->dpmy * 0.0254); + return qRound(d_ptr->dpmy * 0.0254 * d_ptr->devicePixelRatio); default: qWarning("QOpenGLPaintDevice::metric() - metric %d not known", metric); return 0; diff --git a/src/gui/opengl/qopenglpaintdevice.h b/src/gui/opengl/qopenglpaintdevice.h index 731000f131..5868a5740a 100644 --- a/src/gui/opengl/qopenglpaintdevice.h +++ b/src/gui/opengl/qopenglpaintdevice.h @@ -68,6 +68,7 @@ public: QOpenGLContext *context() const; QSize size() const; void setSize(const QSize &size); + void setDevicePixelRatio(qreal devicePixelRatio); qreal dotsPerMeterX() const; qreal dotsPerMeterY() const; diff --git a/src/plugins/platforms/ios/qiosbackingstore.mm b/src/plugins/platforms/ios/qiosbackingstore.mm index 6bae08ce2b..5ee048cb2f 100644 --- a/src/plugins/platforms/ios/qiosbackingstore.mm +++ b/src/plugins/platforms/ios/qiosbackingstore.mm @@ -71,12 +71,18 @@ void QIOSBackingStore::beginPaint(const QRegion &) m_context->makeCurrent(window()); static_cast<QOpenGLPaintDevice *>(paintDevice())->setSize(window()->size()); + QIOSWindow *iosWindow = static_cast<QIOSWindow *>(window()->handle()); + static_cast<QOpenGLPaintDevice *>(paintDevice())->setSize(window()->size() * iosWindow->devicePixelRatio()); } QPaintDevice *QIOSBackingStore::paintDevice() { - if (!m_device) - m_device = new QOpenGLPaintDevice; + if (!m_device) { + QIOSWindow *iosWindow = static_cast<QIOSWindow *>(window()->handle()); + QOpenGLPaintDevice *openGLDevice = new QOpenGLPaintDevice(window()->size() * iosWindow->devicePixelRatio()); + openGLDevice->setDevicePixelRatio(iosWindow->devicePixelRatio()); + m_device = openGLDevice; + } return m_device; } diff --git a/src/plugins/platforms/ios/qioswindow.h b/src/plugins/platforms/ios/qioswindow.h index 3a05901ae7..cb2854d60e 100644 --- a/src/plugins/platforms/ios/qioswindow.h +++ b/src/plugins/platforms/ios/qioswindow.h @@ -90,6 +90,7 @@ public: GLuint framebufferObject(const QIOSContext &context) const; GLuint colorRenderbuffer(const QIOSContext &context) const; + qreal devicePixelRatio() const; EAGLView *nativeView() const { return m_view; } @@ -104,6 +105,7 @@ private: GLint renderbufferWidth; GLint renderbufferHeight; } m_glData; + qreal m_devicePixelRatio; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/ios/qioswindow.mm b/src/plugins/platforms/ios/qioswindow.mm index cc016da106..e3da694bac 100644 --- a/src/plugins/platforms/ios/qioswindow.mm +++ b/src/plugins/platforms/ios/qioswindow.mm @@ -126,8 +126,7 @@ static QRect fromCGRect(const CGRect &rect) { UITouch *touch = [touches anyObject]; CGPoint locationInView = [touch locationInView:self]; - CGFloat scaleFactor = [self contentScaleFactor]; - QPoint p(locationInView.x * scaleFactor, locationInView.y * scaleFactor); + QPoint p(locationInView.x , locationInView.y); // TODO handle global touch point? for status bar? QWindowSystemInterface::handleMouseEvent(m_qioswindow->window(), (ulong)(event.timestamp*1000), p, p, buttons); @@ -204,11 +203,21 @@ QIOSWindow::QIOSWindow(QWindow *window) , m_view([[EAGLView alloc] initWithQIOSWindow:this]) , m_requestedGeometry(QPlatformWindow::geometry()) , m_glData() + , m_devicePixelRatio(1.0) { if ([[UIApplication sharedApplication].delegate isKindOfClass:[QIOSApplicationDelegate class]]) [[UIApplication sharedApplication].delegate.window.rootViewController.view addSubview:m_view]; setWindowState(window->windowState()); + + // Retina support: get screen scale factor and set it in the content view. + // This will make framebufferObject() create a 2x frame buffer on retina + // displays. Also set m_devicePixelRatio which is used for scaling the + // paint device. + if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] == YES) { + m_devicePixelRatio = [[UIScreen mainScreen] scale]; + [m_view setContentScaleFactor : m_devicePixelRatio]; + } } QIOSWindow::~QIOSWindow() @@ -304,7 +313,8 @@ GLuint QIOSWindow::framebufferObject(const QIOSContext &context) const GLuint QIOSWindow::colorRenderbuffer(const QIOSContext &context) const { if (!m_glData.colorRenderbuffer || - m_glData.renderbufferWidth != geometry().width() || m_glData.renderbufferHeight != geometry().height()) { + m_glData.renderbufferWidth != geometry().width() * m_devicePixelRatio || + m_glData.renderbufferHeight != geometry().height() *m_devicePixelRatio) { glBindRenderbuffer(GL_RENDERBUFFER, m_glData.colorRenderbuffer); [context.nativeContext() renderbufferStorage:GL_RENDERBUFFER fromDrawable:static_cast<CAEAGLLayer *>(m_view.layer)]; @@ -329,4 +339,9 @@ GLuint QIOSWindow::colorRenderbuffer(const QIOSContext &context) const return m_glData.colorRenderbuffer; } +qreal QIOSWindow::devicePixelRatio() const +{ + return m_devicePixelRatio; +} + QT_END_NAMESPACE |
