Support RasterGLSurface windows

In an attempt to make QOpenGLWidget and QQuickWidget working on Wayland.

Since Qt 5.3 all widget windows are of type RasterGLSurface (given that
the plugin reports this capability which wayland will, with this patch).
Such a window can behave either like a raster or an OpenGL window.

This concept maps badly to platform plugins that have a rigid separation
between raster and OpenGL platform window implementations. From now on,
the OpenGL window implementation, that is used pretty much always,
except for raw RasterSurface windows, must be prepared to behave like
a raster window too, which involves having a backingstore.

Change-Id: I0226704b8d5893843fcae68059c5fe9ad2f5e761
Reviewed-by: Robin Burchell <robin.burchell@viroteck.net>
This commit is contained in:
Laszlo Agocs 2014-08-22 12:41:42 +02:00
parent 611716293c
commit 5d49d5a224
7 changed files with 50 additions and 42 deletions

View File

@ -62,6 +62,8 @@ public:
virtual void initialize(QWaylandDisplay *display) = 0; virtual void initialize(QWaylandDisplay *display) = 0;
virtual bool isValid() const { return true; }
virtual bool supportsThreadedOpenGL() const { return false; } virtual bool supportsThreadedOpenGL() const { return false; }
virtual QWaylandWindow *createEglWindow(QWindow *window) = 0; virtual QWaylandWindow *createEglWindow(QWindow *window) = 0;

View File

@ -42,9 +42,9 @@
#include "qwaylandintegration_p.h" #include "qwaylandintegration_p.h"
#include "qwaylanddisplay_p.h" #include "qwaylanddisplay_p.h"
#include "qwaylandshmwindow_p.h"
#include "qwaylandinputcontext_p.h" #include "qwaylandinputcontext_p.h"
#include "qwaylandshmbackingstore_p.h" #include "qwaylandshmbackingstore_p.h"
#include "qwaylandshmwindow_p.h"
#include "qwaylandnativeinterface_p.h" #include "qwaylandnativeinterface_p.h"
#include "qwaylandclipboard_p.h" #include "qwaylandclipboard_p.h"
#include "qwaylanddnd_p.h" #include "qwaylanddnd_p.h"
@ -162,14 +162,18 @@ bool QWaylandIntegration::hasCapability(QPlatformIntegration::Capability cap) co
case MultipleWindows: case MultipleWindows:
case NonFullScreenWindows: case NonFullScreenWindows:
return true; return true;
case RasterGLSurface:
return true;
default: return QPlatformIntegration::hasCapability(cap); default: return QPlatformIntegration::hasCapability(cap);
} }
} }
QPlatformWindow *QWaylandIntegration::createPlatformWindow(QWindow *window) const QPlatformWindow *QWaylandIntegration::createPlatformWindow(QWindow *window) const
{ {
if (window->surfaceType() == QWindow::OpenGLSurface && mDisplay->clientBufferIntegration()) if ((window->surfaceType() == QWindow::OpenGLSurface || window->surfaceType() == QWindow::RasterGLSurface)
&& mDisplay->clientBufferIntegration())
return mDisplay->clientBufferIntegration()->createEglWindow(window); return mDisplay->clientBufferIntegration()->createEglWindow(window);
return new QWaylandShmWindow(window); return new QWaylandShmWindow(window);
} }
@ -255,7 +259,7 @@ QWaylandClientBufferIntegration *QWaylandIntegration::clientBufferIntegration()
if (!mClientBufferIntegrationInitialized) if (!mClientBufferIntegrationInitialized)
const_cast<QWaylandIntegration *>(this)->initializeClientBufferIntegration(); const_cast<QWaylandIntegration *>(this)->initializeClientBufferIntegration();
return mClientBufferIntegration; return mClientBufferIntegration && mClientBufferIntegration->isValid() ? mClientBufferIntegration : 0;
} }
QWaylandServerBufferIntegration *QWaylandIntegration::serverBufferIntegration() const QWaylandServerBufferIntegration *QWaylandIntegration::serverBufferIntegration() const

View File

@ -39,14 +39,12 @@
** **
****************************************************************************/ ****************************************************************************/
#include "qwaylandshmbackingstore_p.h" #include "qwaylandshmbackingstore_p.h"
#include "qwaylandwindow_p.h"
#include <QtCore/qdebug.h>
#include "qwaylanddisplay_p.h" #include "qwaylanddisplay_p.h"
#include "qwaylandshmwindow_p.h"
#include "qwaylandscreen_p.h" #include "qwaylandscreen_p.h"
#include "qwaylanddecoration_p.h" #include "qwaylanddecoration_p.h"
#include <QtCore/qdebug.h>
#include <QtGui/QPainter> #include <QtGui/QPainter>
#include <wayland-client.h> #include <wayland-client.h>
@ -156,9 +154,7 @@ QWaylandShmBackingStore::~QWaylandShmBackingStore()
QPaintDevice *QWaylandShmBackingStore::paintDevice() QPaintDevice *QWaylandShmBackingStore::paintDevice()
{ {
if (!windowDecoration()) return contentSurface();
return mBackBuffer->image();
return mBackBuffer->imageInsideMargins(windowDecorationMargins());
} }
void QWaylandShmBackingStore::beginPaint(const QRegion &) void QWaylandShmBackingStore::beginPaint(const QRegion &)
@ -166,13 +162,11 @@ void QWaylandShmBackingStore::beginPaint(const QRegion &)
mPainting = true; mPainting = true;
ensureSize(); ensureSize();
if (waylandWindow()->attached() && mBackBuffer == waylandWindow()->attached() && mFrameCallback) { QWaylandWindow *window = waylandWindow();
QWaylandShmWindow *waylandWindow = static_cast<QWaylandShmWindow *>(window()->handle()); if (window->attached() && mBackBuffer == window->attached() && mFrameCallback)
Q_ASSERT(waylandWindow->windowType() == QWaylandWindow::Shm); window->waitForFrameSync();
waylandWindow->waitForFrameSync();
}
waylandWindow()->setCanResize(false); window->setCanResize(false);
} }
void QWaylandShmBackingStore::endPaint() void QWaylandShmBackingStore::endPaint()
@ -190,9 +184,15 @@ void QWaylandShmBackingStore::ensureSize()
void QWaylandShmBackingStore::flush(QWindow *window, const QRegion &region, const QPoint &offset) void QWaylandShmBackingStore::flush(QWindow *window, const QRegion &region, const QPoint &offset)
{ {
// Invoked when the window is of type RasterSurface or when the window is
// RasterGLSurface and there are no child widgets requiring OpenGL composition.
// For the case of RasterGLSurface + having to compose, the composeAndFlush() is
// called instead. The default implementation from QPlatformBackingStore is sufficient
// however so no need to reimplement that.
Q_UNUSED(window); Q_UNUSED(window);
Q_UNUSED(offset); Q_UNUSED(offset);
Q_ASSERT(waylandWindow()->windowType() == QWaylandWindow::Shm);
if (windowDecoration() && windowDecoration()->isDirty()) if (windowDecoration() && windowDecoration()->isDirty())
updateDecorations(); updateDecorations();
@ -260,6 +260,11 @@ QImage *QWaylandShmBackingStore::entireSurface() const
return mBackBuffer->image(); return mBackBuffer->image();
} }
QImage *QWaylandShmBackingStore::contentSurface() const
{
return windowDecoration() ? mBackBuffer->imageInsideMargins(windowDecorationMargins()) : mBackBuffer->image();
}
void QWaylandShmBackingStore::updateDecorations() void QWaylandShmBackingStore::updateDecorations()
{ {
QPainter decorationPainter(entireSurface()); QPainter decorationPainter(entireSurface());
@ -302,11 +307,19 @@ QMargins QWaylandShmBackingStore::windowDecorationMargins() const
return QMargins(); return QMargins();
} }
QWaylandShmWindow *QWaylandShmBackingStore::waylandWindow() const QWaylandWindow *QWaylandShmBackingStore::waylandWindow() const
{ {
return static_cast<QWaylandShmWindow *>(window()->handle()); return static_cast<QWaylandWindow *>(window()->handle());
} }
QImage QWaylandShmBackingStore::toImage() const
{
// Invoked from QPlatformBackingStore::composeAndFlush() that is called
// instead of flush() for widgets that have renderToTexture children
// (QOpenGLWidget, QQuickWidget).
return *contentSurface();
}
void QWaylandShmBackingStore::done(void *data, wl_callback *callback, uint32_t time) void QWaylandShmBackingStore::done(void *data, wl_callback *callback, uint32_t time)
{ {
@ -315,7 +328,7 @@ void QWaylandShmBackingStore::done(void *data, wl_callback *callback, uint32_t t
static_cast<QWaylandShmBackingStore *>(data); static_cast<QWaylandShmBackingStore *>(data);
if (callback != self->mFrameCallback) // others, like QWaylandWindow, may trigger callbacks too if (callback != self->mFrameCallback) // others, like QWaylandWindow, may trigger callbacks too
return; return;
QWaylandShmWindow *window = self->waylandWindow(); QWaylandWindow *window = self->waylandWindow();
wl_callback_destroy(self->mFrameCallback); wl_callback_destroy(self->mFrameCallback);
self->mFrameCallback = 0; self->mFrameCallback = 0;

View File

@ -52,7 +52,7 @@ QT_BEGIN_NAMESPACE
class QWaylandDisplay; class QWaylandDisplay;
class QWaylandDecoration; class QWaylandDecoration;
class QWaylandShmWindow; class QWaylandWindow;
class Q_WAYLAND_CLIENT_EXPORT QWaylandShmBuffer : public QWaylandBuffer { class Q_WAYLAND_CLIENT_EXPORT QWaylandShmBuffer : public QWaylandBuffer {
public: public:
@ -87,11 +87,14 @@ public:
QMargins windowDecorationMargins() const; QMargins windowDecorationMargins() const;
QImage *entireSurface() const; QImage *entireSurface() const;
QImage *contentSurface() const;
void ensureSize(); void ensureSize();
QWaylandShmWindow *waylandWindow() const; QWaylandWindow *waylandWindow() const;
void iterateBuffer(); void iterateBuffer();
QImage toImage() const Q_DECL_OVERRIDE;
private: private:
void updateDecorations(); void updateDecorations();

View File

@ -51,13 +51,11 @@ QT_BEGIN_NAMESPACE
QWaylandShmWindow::QWaylandShmWindow(QWindow *window) QWaylandShmWindow::QWaylandShmWindow(QWindow *window)
: QWaylandWindow(window) : QWaylandWindow(window)
, mBackingStore(0)
{ {
} }
QWaylandShmWindow::~QWaylandShmWindow() QWaylandShmWindow::~QWaylandShmWindow()
{ {
} }
QWaylandWindow::WindowType QWaylandShmWindow::windowType() const QWaylandWindow::WindowType QWaylandShmWindow::windowType() const
@ -65,9 +63,4 @@ QWaylandWindow::WindowType QWaylandShmWindow::windowType() const
return QWaylandWindow::Shm; return QWaylandWindow::Shm;
} }
void QWaylandShmWindow::setBackingStore(QWaylandShmBackingStore *backingStore)
{
mBackingStore = backingStore;
}
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -47,8 +47,6 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QWaylandShmBackingStore;
class Q_WAYLAND_CLIENT_EXPORT QWaylandShmWindow : public QWaylandWindow class Q_WAYLAND_CLIENT_EXPORT QWaylandShmWindow : public QWaylandWindow
{ {
public: public:
@ -57,19 +55,8 @@ public:
WindowType windowType() const; WindowType windowType() const;
QSurfaceFormat format() const { return QSurfaceFormat(); } QSurfaceFormat format() const { return QSurfaceFormat(); }
void setBackingStore(QWaylandShmBackingStore *backingStore);
QWaylandShmBackingStore *backingStore() const;
private:
QWaylandShmBackingStore *mBackingStore;
}; };
inline QWaylandShmBackingStore *QWaylandShmWindow::backingStore() const
{
return mBackingStore;
}
QT_END_NAMESPACE QT_END_NAMESPACE
#endif // QWAYLANDSHMWINDOW_H #endif // QWAYLANDSHMWINDOW_H

View File

@ -63,6 +63,7 @@ class QWaylandSubSurface;
class QWaylandDecoration; class QWaylandDecoration;
class QWaylandInputDevice; class QWaylandInputDevice;
class QWaylandScreen; class QWaylandScreen;
class QWaylandShmBackingStore;
class Q_WAYLAND_CLIENT_EXPORT QWaylandWindowConfigure class Q_WAYLAND_CLIENT_EXPORT QWaylandWindowConfigure
{ {
@ -179,6 +180,9 @@ public:
QVariant property(const QString &name); QVariant property(const QString &name);
QVariant property(const QString &name, const QVariant &defaultValue); QVariant property(const QString &name, const QVariant &defaultValue);
void setBackingStore(QWaylandShmBackingStore *backingStore) { mBackingStore = backingStore; }
QWaylandShmBackingStore *backingStore() const { return mBackingStore; }
public slots: public slots:
void requestResize(); void requestResize();
@ -216,6 +220,8 @@ protected:
Qt::WindowState mState; Qt::WindowState mState;
QWaylandShmBackingStore *mBackingStore;
private: private:
bool setWindowStateInternal(Qt::WindowState flags); bool setWindowStateInternal(Qt::WindowState flags);
void setGeometry_helper(const QRect &rect); void setGeometry_helper(const QRect &rect);