QAndroidPlatformScreen: Use an event rather than a QTimer

It looks like the origins of this timer may come from QFbScreen. QFbScreen,
however, changed away from a timer in d7068cbe1b.

There are other reasons to avoid a timer in this case, though: a timer may be
pre-empted by application events (like other timers), which may mean a
significant amount of time could pass between starting the timer and pushing the
contents out to the actual screen (in doRedraw).

This has the effect that flush becomes synchronous, which matches the
behavior of the other platforms as far as I can tell.

Change-Id: Ic67ae6c82945a247dceac44ee1bf7d2940f79d07
Reviewed-by: BogDan Vatra <bogdan@kdab.com>
This commit is contained in:
Robin Burchell 2017-02-28 03:55:18 +11:00
parent e91726ef9e
commit b018a5ecef
2 changed files with 19 additions and 7 deletions

View File

@ -85,7 +85,8 @@ private:
# define PROFILE_SCOPE
#endif
QAndroidPlatformScreen::QAndroidPlatformScreen():QObject(),QPlatformScreen()
QAndroidPlatformScreen::QAndroidPlatformScreen()
: QObject(), QPlatformScreen()
{
m_availableGeometry = QRect(0, 0, QAndroidPlatformIntegration::m_defaultGeometryWidth, QAndroidPlatformIntegration::m_defaultGeometryHeight);
m_size = QSize(QAndroidPlatformIntegration::m_defaultScreenWidth, QAndroidPlatformIntegration::m_defaultScreenHeight);
@ -100,9 +101,6 @@ QAndroidPlatformScreen::QAndroidPlatformScreen():QObject(),QPlatformScreen()
}
m_physicalSize.setHeight(QAndroidPlatformIntegration::m_defaultPhysicalSizeHeight);
m_physicalSize.setWidth(QAndroidPlatformIntegration::m_defaultPhysicalSizeWidth);
m_redrawTimer.setSingleShot(true);
m_redrawTimer.setInterval(0);
connect(&m_redrawTimer, SIGNAL(timeout()), this, SLOT(doRedraw()));
connect(qGuiApp, &QGuiApplication::applicationStateChanged, this, &QAndroidPlatformScreen::applicationStateChanged);
}
@ -136,6 +134,16 @@ QWindow *QAndroidPlatformScreen::topLevelAt(const QPoint &p) const
return 0;
}
bool QAndroidPlatformScreen::event(QEvent *event)
{
if (event->type() == QEvent::UpdateRequest) {
doRedraw();
m_updatePending = false;
return true;
}
return QObject::event(event);
}
void QAndroidPlatformScreen::addWindow(QAndroidPlatformWindow *window)
{
if (window->parent() && window->isRaster())
@ -209,8 +217,10 @@ void QAndroidPlatformScreen::lower(QAndroidPlatformWindow *window)
void QAndroidPlatformScreen::scheduleUpdate()
{
if (!m_redrawTimer.isActive())
m_redrawTimer.start();
if (!m_updatePending) {
m_updatePending = true;
QCoreApplication::postEvent(this, new QEvent(QEvent::UpdateRequest));
}
}
void QAndroidPlatformScreen::setDirty(const QRect &rect)

View File

@ -89,10 +89,12 @@ public slots:
void setSize(const QSize &size);
protected:
bool event(QEvent *event);
typedef QList<QAndroidPlatformWindow *> WindowStackType;
WindowStackType m_windowStack;
QRect m_dirtyRect;
QTimer m_redrawTimer;
bool m_updatePending = false;
QRect m_availableGeometry;
int m_depth;