Implement the QPlatformWindow::requestUpdate() virtual method.

The implementation will wait for the frame callback before firing
the update event.

Change-Id: Ieea748fda7c2aeb62cc40f35dbd122864c09f7cd
Reviewed-by: Johan Helsing <johan.helsing@theqtcompany.com>
Reviewed-by: Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
This commit is contained in:
Giulio Camuffo 2015-12-11 23:19:55 +02:00 committed by Giulio Camuffo
parent 3e0ad8f7c9
commit 4a7a357aa8
2 changed files with 33 additions and 14 deletions

View File

@ -61,6 +61,7 @@
#include <QGuiApplication> #include <QGuiApplication>
#include <qpa/qwindowsysteminterface.h> #include <qpa/qwindowsysteminterface.h>
#include <QtGui/private/qwindow_p.h>
#include <QtCore/QDebug> #include <QtCore/QDebug>
@ -91,6 +92,7 @@ QWaylandWindow::QWaylandWindow(QWindow *window)
, mState(Qt::WindowNoState) , mState(Qt::WindowNoState)
, mMask() , mMask()
, mBackingStore(Q_NULLPTR) , mBackingStore(Q_NULLPTR)
, mUpdateRequested(false)
{ {
static WId id = 1; static WId id = 1;
mWindowId = id++; mWindowId = id++;
@ -431,10 +433,20 @@ void QWaylandWindow::requestResize()
void QWaylandWindow::attach(QWaylandBuffer *buffer, int x, int y) void QWaylandWindow::attach(QWaylandBuffer *buffer, int x, int y)
{ {
if (buffer) if (mFrameCallback) {
wl_callback_destroy(mFrameCallback);
mFrameCallback = 0;
}
if (buffer) {
mFrameCallback = frame();
wl_callback_add_listener(mFrameCallback, &QWaylandWindow::callbackListener, this);
mWaitingForFrameSync = true;
attach(buffer->buffer(), x, y); attach(buffer->buffer(), x, y);
else } else {
QtWayland::wl_surface::attach(0, 0, 0); QtWayland::wl_surface::attach(0, 0, 0);
}
} }
void QWaylandWindow::attachOffset(QWaylandBuffer *buffer) void QWaylandWindow::attachOffset(QWaylandBuffer *buffer)
@ -445,13 +457,6 @@ void QWaylandWindow::attachOffset(QWaylandBuffer *buffer)
void QWaylandWindow::damage(const QRect &rect) void QWaylandWindow::damage(const QRect &rect)
{ {
//We have to do sync stuff before calling damage, or we might
//get a frame callback before we get the timestamp
if (!mWaitingForFrameSync) {
mFrameCallback = frame();
wl_callback_add_listener(mFrameCallback,&QWaylandWindow::callbackListener,this);
mWaitingForFrameSync = true;
}
damage(rect.x(), rect.y(), rect.width(), rect.height()); damage(rect.x(), rect.y(), rect.width(), rect.height());
} }
@ -463,12 +468,14 @@ void QWaylandWindow::frameCallback(void *data, struct wl_callback *callback, uin
{ {
Q_UNUSED(time); Q_UNUSED(time);
QWaylandWindow *self = static_cast<QWaylandWindow*>(data); QWaylandWindow *self = static_cast<QWaylandWindow*>(data);
if (callback != self->mFrameCallback) // might be a callback caused by the shm backingstore
return;
self->mWaitingForFrameSync = false; self->mWaitingForFrameSync = false;
if (self->mFrameCallback) { wl_callback_destroy(callback);
wl_callback_destroy(self->mFrameCallback); self->mFrameCallback = 0;
self->mFrameCallback = 0; if (self->mUpdateRequested) {
QWindowPrivate *w = QWindowPrivate::get(self->window());
w->deliverUpdateRequest();
self->mUpdateRequested = false;
} }
} }
@ -871,6 +878,14 @@ QVariant QWaylandWindow::property(const QString &name, const QVariant &defaultVa
return m_properties.value(name, defaultValue); return m_properties.value(name, defaultValue);
} }
void QWaylandWindow::requestUpdate()
{
if (!mFrameCallback)
QPlatformWindow::requestUpdate();
else
mUpdateRequested = true;
}
} }
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -199,6 +199,8 @@ public:
bool setKeyboardGrabEnabled(bool) Q_DECL_OVERRIDE { return false; } bool setKeyboardGrabEnabled(bool) Q_DECL_OVERRIDE { return false; }
void propagateSizeHints() Q_DECL_OVERRIDE { } void propagateSizeHints() Q_DECL_OVERRIDE { }
void requestUpdate() Q_DECL_OVERRIDE;
public slots: public slots:
void requestResize(); void requestResize();
@ -245,6 +247,8 @@ private:
void handleMouseEventWithDecoration(QWaylandInputDevice *inputDevice, const QWaylandPointerEvent &e); void handleMouseEventWithDecoration(QWaylandInputDevice *inputDevice, const QWaylandPointerEvent &e);
bool mUpdateRequested;
static const wl_callback_listener callbackListener; static const wl_callback_listener callbackListener;
static void frameCallback(void *data, struct wl_callback *wl_callback, uint32_t time); static void frameCallback(void *data, struct wl_callback *wl_callback, uint32_t time);