diff options
author | Tor Arne Vestbø <tor.arne.vestbo@digia.com> | 2013-11-15 19:36:40 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-11-22 22:36:23 +0100 |
commit | 1ca27d38bc065b124a8fda6548e41f79c351e17d (patch) | |
tree | 48c18732e9afdb718fc3817dfd2a5d656d96cc11 | |
parent | b6ad2621aa25e94a7caeff9e66ec0064bb8ff260 (diff) |
iOS: Fix when and how we send geometry and expose events
Geometry changes may come from Qt itself, or spontaneously from the windowing
system. In both cases we deal with them through the layoutSubviews callback,
which we now ensure gets called after we set a new geometry on the UIView
frame, by using the setNeedsLayout message.
We take care to persist the requested geometry from Qt immediately in our
setGeometry() function, so that subsequent calls to QWindow::geometry()
will report back the requested geometry. Clients can however not rely
on this geometry until they've received a corresponding resize event,
which we trigger from layoutSubviews.
Since the new geometry reported in layoutSubviews may be different from
what the user requested, we ensure to pass on both the new and the "old"
geometry, so that Qt will send the appropriate resize and move events.
Instead of building expose events on top of the existing layout
mechanism provided by iOS, we hook into the more logical point,
which is the display-phase. Since a EAGL view normally doesn't
need to "display" anything this takes a few overrides on UIView.
Once we have the hooks we need, we can distinguish between a QWindow
backing needing layout, and needing displaying.
Finally, we flush both the resize and expose events, as that's what
iOS expects of us when asking us to layout or display. The result
is that Qt is able to synchronously resize subwindows and prepare
new GL rendering for the next frame.
Change-Id: I4c03e3db3fe886163284ba1a342699e217e88cbb
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@digia.com>
-rw-r--r-- | src/plugins/platforms/ios/qioswindow.mm | 85 |
1 files changed, 72 insertions, 13 deletions
diff --git a/src/plugins/platforms/ios/qioswindow.mm b/src/plugins/platforms/ios/qioswindow.mm index 52851439b1..14220f1139 100644 --- a/src/plugins/platforms/ios/qioswindow.mm +++ b/src/plugins/platforms/ios/qioswindow.mm @@ -153,6 +153,15 @@ self.clipsToBounds = NO; } +- (void)setNeedsDisplay +{ + [super setNeedsDisplay]; + + // We didn't implement drawRect: so we have to manually + // mark the layer as needing display. + [self.layer setNeedsDisplay]; +} + - (void)layoutSubviews { // This method is the de facto way to know that view has been resized, @@ -165,15 +174,39 @@ qWarning() << m_qioswindow->window() << "is backed by a UIView that has a transform set. This is not supported."; - QRect geometry = fromCGRect(self.frame); - m_qioswindow->QPlatformWindow::setGeometry(geometry); - QWindowSystemInterface::handleGeometryChange(m_qioswindow->window(), geometry); - QWindowSystemInterface::handleExposeEvent(m_qioswindow->window(), QRect(QPoint(), geometry.size())); + // The original geometry requested by setGeometry() might be different + // from what we end up with after applying window constraints. + QRect requestedGeometry = m_qioswindow->geometry(); + + // Persist the actual/new geometry so that QWindow::geometry() can + // be queried on the resize event. + QRect actualGeometry = fromCGRect(self.frame); + m_qioswindow->QPlatformWindow::setGeometry(actualGeometry); + + QRect previousGeometry = requestedGeometry != actualGeometry ? + requestedGeometry : qt_window_private(m_qioswindow->window())->geometry; - // If we have a new size here we need to resize the FBO's corresponding buffers, - // but we defer that to when the application calls makeCurrent. + QWindowSystemInterface::handleGeometryChange(m_qioswindow->window(), actualGeometry, previousGeometry); + QWindowSystemInterface::flushWindowSystemEvents(); + + if (actualGeometry.size() != previousGeometry.size()) { + // Trigger expose event on resize + [self setNeedsDisplay]; - [super layoutSubviews]; + // A new size means we also need to resize the FBO's corresponding buffers, + // but we defer that to when the application calls makeCurrent. + } +} + +- (void)displayLayer:(CALayer *)layer +{ + QRect geometry = fromCGRect(layer.frame); + Q_ASSERT(m_qioswindow->geometry() == geometry); + Q_ASSERT(self.hidden == !m_qioswindow->window()->isVisible()); + + QRegion region = self.hidden ? QRegion() : QRect(QPoint(), geometry.size()); + QWindowSystemInterface::handleExposeEvent(m_qioswindow->window(), region); + QWindowSystemInterface::flushWindowSystemEvents(); } - (void)updateTouchList:(NSSet *)touches withState:(Qt::TouchPointState)state @@ -393,8 +426,8 @@ bool QIOSWindow::blockedByModal() void QIOSWindow::setVisible(bool visible) { - QPlatformWindow::setVisible(visible); m_view.hidden = !visible; + [m_view setNeedsDisplay]; if (!isQtApplication()) return; @@ -429,22 +462,48 @@ void QIOSWindow::setVisible(bool visible) void QIOSWindow::setGeometry(const QRect &rect) { - // If the window is in fullscreen, just bookkeep the requested - // geometry in case the window goes into Qt::WindowNoState later: m_normalGeometry = rect; - if (window()->windowState() & (Qt::WindowMaximized | Qt::WindowFullScreen)) + + if (window()->windowState() != Qt::WindowNoState) { + QPlatformWindow::setGeometry(rect); + + // The layout will realize the requested geometry was not applied, and + // send geometry-change events that match the actual geometry. + [m_view setNeedsLayout]; + + if (window()->inherits("QWidgetWindow")) { + // QWidget wrongly assumes that setGeometry resets the window + // state back to Qt::NoWindowState, so we need to inform it that + // that his is not the case by re-issuing the current window state. + QWindowSystemInterface::handleWindowStateChanged(window(), window()->windowState()); + + // It also needs to be told immediately that the geometry it requested + // did not apply, otherwise it will continue on as if it did, instead + // of waiting for a resize event. + [m_view layoutIfNeeded]; + } + return; + } applyGeometry(rect); } void QIOSWindow::applyGeometry(const QRect &rect) { + // Geometry changes are asynchronous, but QWindow::geometry() is + // expected to report back the 'requested geometry' until we get + // a callback with the updated geometry from the window system. + // The baseclass takes care of persisting this for us. + QPlatformWindow::setGeometry(rect); + // Since we don't support transformations on the UIView, we can set the frame // directly and let UIKit deal with translating that into bounds and center. - // Changing the size of the view will end up in a call to -[QUIView layoutSubviews] - // which will update QWindowSystemInterface with the new size. m_view.frame = toCGRect(rect); + + // iOS will automatically trigger -[layoutSubviews:] for resize, + // but not for move, so we force it just in case. + [m_view setNeedsLayout]; } void QIOSWindow::setWindowState(Qt::WindowState state) |