Skip to content

Commit

Permalink
Revert "Revert "Introducing QWindow::requestUpdate().""
Browse files Browse the repository at this point in the history
This reverts commit c141ab0.
  • Loading branch information
sletta committed Apr 14, 2015
1 parent d87abe9 commit 6a58eca
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/gui/kernel/qplatformwindow.cpp
Expand Up @@ -566,6 +566,36 @@ QRect QPlatformWindow::initialGeometry(const QWindow *w,
return rect;
}

/*!
Requests an QEvent::UpdateRequest event. The event will be
delivered to the QWindow.
QPlatformWindow subclasses can re-implement this function to
provide display refresh synchronized updates. The event
should be delivered using QWindowPrivate::deliverUpdateRequest()
to not get out of sync with the the internal state of QWindow.
The default implementation posts an UpdateRequest event to the
window after 5 ms. The additional time is there to give the event
loop a bit of idle time to gather system events.
*/
void QPlatformWindow::requestUpdate()
{
static int timeout = -1;
if (timeout == -1) {
bool ok = false;
timeout = qgetenv("QT_QPA_UPDATE_IDLE_TIME").toInt(&ok);
if (!ok)
timeout = 5;
}

QWindow *w = window();
QWindowPrivate *wp = (QWindowPrivate *) QObjectPrivate::get(w);
Q_ASSERT(wp->updateTimer == 0);
wp->updateTimer = w->startTimer(timeout, Qt::PreciseTimer);
}

/*!
\class QPlatformWindow
\since 4.8
Expand Down
1 change: 1 addition & 0 deletions src/gui/kernel/qplatformwindow.h
Expand Up @@ -136,6 +136,7 @@ class Q_GUI_EXPORT QPlatformWindow : public QPlatformSurface
static QRect initialGeometry(const QWindow *w,
const QRect &initialGeometry, int defaultWidth, int defaultHeight);

virtual void requestUpdate();
protected:
static QString formatWindowTitle(const QString &title, const QString &separator);

Expand Down
44 changes: 44 additions & 0 deletions src/gui/kernel/qwindow.cpp
Expand Up @@ -1945,12 +1945,56 @@ bool QWindow::event(QEvent *ev)
break;
#endif

case QEvent::Timer: {
Q_D(QWindow);
if (static_cast<QTimerEvent *>(ev)->timerId() == d->updateTimer) {
killTimer(d->updateTimer);
d->updateTimer = 0;
d->deliverUpdateRequest();
} else {
QObject::event(ev);
}
break;
}

default:
return QObject::event(ev);
}
return true;
}

void QWindowPrivate::deliverUpdateRequest()
{
Q_Q(QWindow);
updateRequestPending = false;
QEvent request(QEvent::UpdateRequest);
QCoreApplication::sendEvent(q, &request);
}

/*!
Schedules a QEvent::UpdateRequest event to be delivered to this window.
The event is delivered in sync with the display vsync on platforms
where this is possible. When driving animations, this function should
be called once after drawing has completed.
Calling this function multiple times will result in a single event
being delivered to the window.
Subclasses of QWindow should reimplement QWindow::event(), intercept
the event and call the application's rendering code, then call the
base class implementation.
*/

void QWindow::requestUpdate()
{
Q_D(QWindow);
if (d->updateRequestPending || !d->platformWindow)
return;
d->updateRequestPending = true;
d->platformWindow->requestUpdate();
}

/*!
Override this to handle key press events (\a ev).
Expand Down
2 changes: 2 additions & 0 deletions src/gui/kernel/qwindow.h
Expand Up @@ -293,6 +293,8 @@ public Q_SLOTS:

Q_REVISION(1) void alert(int msec);

Q_REVISION(3) void requestUpdate();

Q_SIGNALS:
void screenChanged(QScreen *screen);
void modalityChanged(Qt::WindowModality modality);
Expand Down
7 changes: 7 additions & 0 deletions src/gui/kernel/qwindow_p.h
Expand Up @@ -94,6 +94,8 @@ class Q_GUI_EXPORT QWindowPrivate : public QObjectPrivate
, maximumSize(QWINDOWSIZE_MAX, QWINDOWSIZE_MAX)
, modality(Qt::NonModal)
, blockedByModalWindow(false)
, updateRequestPending(false)
, updateTimer(0)
, transientParent(0)
, screen(0)
#ifndef QT_NO_CURSOR
Expand All @@ -114,6 +116,8 @@ class Q_GUI_EXPORT QWindowPrivate : public QObjectPrivate
void applyCursor();
#endif

void deliverUpdateRequest();

QPoint globalPosition() const {
Q_Q(const QWindow);
QPoint offset = q->position();
Expand Down Expand Up @@ -160,6 +164,9 @@ class Q_GUI_EXPORT QWindowPrivate : public QObjectPrivate
Qt::WindowModality modality;
bool blockedByModalWindow;

bool updateRequestPending;
int updateTimer;

QPointer<QWindow> transientParent;
QScreen *screen;

Expand Down

0 comments on commit 6a58eca

Please sign in to comment.