From e01b81339a37830c48f2cec0583e5d0aba592601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lind?= Date: Tue, 11 Aug 2015 16:07:23 +0200 Subject: Remove QtWayland::Surface Its enough to have QWaylandSurface and QWaylandSurfacePrivate. Also don't pass QWaylandSurfacePrivate around, but pass QWaylandSurface and then use the QWaylandSurfacePrivate::get function. Change-Id: I915cc9d7b4497ad1c6f1f2dee61d9d0db069ba6b --- .../qwindow-compositor/qwindowcompositor.cpp | 11 +- .../compositor_api/qwaylandcompositor.cpp | 10 +- src/compositor/compositor_api/qwaylandcompositor.h | 1 + src/compositor/compositor_api/qwaylanddrag.cpp | 1 - src/compositor/compositor_api/qwaylandinput.cpp | 1 - .../compositor_api/qwaylandinputpanel.cpp | 6 +- .../compositor_api/qwaylandquickcompositor.cpp | 1 - .../compositor_api/qwaylandquicksurface.cpp | 8 +- src/compositor/compositor_api/qwaylandsurface.cpp | 360 +++++++++++++---- src/compositor/compositor_api/qwaylandsurface.h | 30 +- src/compositor/compositor_api/qwaylandsurface_p.h | 128 +++++- src/compositor/extensions/qwlextendedsurface.cpp | 15 +- src/compositor/extensions/qwlextendedsurface_p.h | 9 +- src/compositor/extensions/qwlinputpanel.cpp | 7 +- src/compositor/extensions/qwlinputpanel_p.h | 7 +- src/compositor/extensions/qwlinputpanelsurface.cpp | 7 +- src/compositor/extensions/qwlinputpanelsurface_p.h | 7 +- src/compositor/extensions/qwlqtkey.cpp | 8 +- src/compositor/extensions/qwlqtkey_p.h | 4 +- src/compositor/extensions/qwlqttouch.cpp | 3 +- src/compositor/extensions/qwlshellsurface.cpp | 34 +- src/compositor/extensions/qwlshellsurface_p.h | 14 +- src/compositor/extensions/qwlsubsurface.cpp | 3 +- src/compositor/extensions/qwlsubsurface_p.h | 8 +- src/compositor/extensions/qwltextinput.cpp | 7 +- src/compositor/extensions/qwltextinput_p.h | 7 +- src/compositor/wayland_wrapper/qwlcompositor.cpp | 10 +- src/compositor/wayland_wrapper/qwlcompositor_p.h | 4 +- src/compositor/wayland_wrapper/qwldatadevice.cpp | 8 +- .../wayland_wrapper/qwldatadevicemanager.cpp | 3 +- src/compositor/wayland_wrapper/qwlinputdevice.cpp | 11 +- src/compositor/wayland_wrapper/qwlinputmethod.cpp | 4 +- src/compositor/wayland_wrapper/qwlinputmethod_p.h | 5 +- src/compositor/wayland_wrapper/qwlkeyboard.cpp | 5 +- src/compositor/wayland_wrapper/qwloutput.cpp | 11 +- src/compositor/wayland_wrapper/qwlpointer.cpp | 7 +- src/compositor/wayland_wrapper/qwlsurface.cpp | 427 --------------------- src/compositor/wayland_wrapper/qwlsurface_p.h | 196 ---------- .../wayland_wrapper/qwlsurfacebuffer.cpp | 9 +- .../wayland_wrapper/qwlsurfacebuffer_p.h | 11 +- src/compositor/wayland_wrapper/qwltouch.cpp | 1 - src/compositor/wayland_wrapper/qwltouch_p.h | 2 +- src/compositor/wayland_wrapper/wayland_wrapper.pri | 2 - .../waylandeglclientbufferintegration.cpp | 1 - 44 files changed, 543 insertions(+), 871 deletions(-) delete mode 100644 src/compositor/wayland_wrapper/qwlsurface.cpp delete mode 100644 src/compositor/wayland_wrapper/qwlsurface_p.h diff --git a/examples/wayland/qwindow-compositor/qwindowcompositor.cpp b/examples/wayland/qwindow-compositor/qwindowcompositor.cpp index 22d097b6b..812398e1a 100644 --- a/examples/wayland/qwindow-compositor/qwindowcompositor.cpp +++ b/examples/wayland/qwindow-compositor/qwindowcompositor.cpp @@ -61,6 +61,7 @@ #include #include +#include QT_BEGIN_NAMESPACE @@ -342,7 +343,7 @@ void QWindowCompositor::render() 0, false, true); foreach (QWaylandSurface *surface, m_surfaces) { - if (!surface->visible()) + if (!surface->isMapped()) continue; drawSubSurface(QPoint(), surface); } @@ -362,8 +363,12 @@ void QWindowCompositor::drawSubSurface(const QPoint &offset, QWaylandSurface *su QPoint pos = view->pos().toPoint() + offset; QRect geo(pos, surface->size()); m_textureBlitter->drawTexture(texture, geo, m_window->size(), 0, false, invert_y); - foreach (QWaylandSurface *child, surface->subSurfaces()) { - drawSubSurface(pos, child); + + QtWayland::SubSurface *subSurface = QtWayland::SubSurface::findIn(surface); + if (subSurface) { + foreach (QWaylandSurface *child, subSurface->subSurfaces()) { + drawSubSurface(pos, child); + } } } diff --git a/src/compositor/compositor_api/qwaylandcompositor.cpp b/src/compositor/compositor_api/qwaylandcompositor.cpp index d358b1d86..d86b48d8a 100644 --- a/src/compositor/compositor_api/qwaylandcompositor.cpp +++ b/src/compositor/compositor_api/qwaylandcompositor.cpp @@ -46,9 +46,10 @@ #include "qwaylandpointer.h" #include "qwaylandtouch.h" +#include "qwaylandsurface_p.h" + #include "wayland_wrapper/qwlcompositor_p.h" #include "wayland_wrapper/qwldatadevice_p.h" -#include "wayland_wrapper/qwlsurface_p.h" #include "wayland_wrapper/qwlinputdevice_p.h" #include "extensions/qwlinputpanel_p.h" @@ -123,6 +124,11 @@ uint32_t QWaylandCompositor::nextSerial() return wl_display_next_serial(waylandDisplay()); } +QListQWaylandCompositor::clients() const +{ + return m_compositor->clients(); +} + void QWaylandCompositor::destroyClientForSurface(QWaylandSurface *surface) { destroyClient(surface->client()); @@ -263,7 +269,7 @@ bool QWaylandCompositor::isDragging() const void QWaylandCompositor::sendDragMoveEvent(const QPoint &global, const QPoint &local, QWaylandSurface *surface) { - m_compositor->sendDragMoveEvent(global, local, surface ? surface->handle() : 0); + m_compositor->sendDragMoveEvent(global, local, surface); } void QWaylandCompositor::sendDragEndEvent() diff --git a/src/compositor/compositor_api/qwaylandcompositor.h b/src/compositor/compositor_api/qwaylandcompositor.h index 3eef0adfa..4e515420c 100644 --- a/src/compositor/compositor_api/qwaylandcompositor.h +++ b/src/compositor/compositor_api/qwaylandcompositor.h @@ -108,6 +108,7 @@ public: ::wl_display *waylandDisplay() const; uint32_t nextSerial(); + QListclients() const; Q_INVOKABLE void destroyClientForSurface(QWaylandSurface *surface); Q_INVOKABLE void destroyClient(QWaylandClient *client); diff --git a/src/compositor/compositor_api/qwaylanddrag.cpp b/src/compositor/compositor_api/qwaylanddrag.cpp index 0dd1c880d..01c6f38b4 100644 --- a/src/compositor/compositor_api/qwaylanddrag.cpp +++ b/src/compositor/compositor_api/qwaylanddrag.cpp @@ -41,7 +41,6 @@ #include "qwlcompositor_p.h" #include "qwlinputdevice_p.h" #include "qwldatadevice_p.h" -#include "qwlsurface_p.h" #include "qwaylandview.h" QT_BEGIN_NAMESPACE diff --git a/src/compositor/compositor_api/qwaylandinput.cpp b/src/compositor/compositor_api/qwaylandinput.cpp index 8064faf3f..69fe45e96 100644 --- a/src/compositor/compositor_api/qwaylandinput.cpp +++ b/src/compositor/compositor_api/qwaylandinput.cpp @@ -39,7 +39,6 @@ #include "qwlinputdevice_p.h" #include "qwlkeyboard_p.h" #include "qwaylandcompositor.h" -#include "qwlsurface_p.h" #include "qwlcompositor_p.h" #include "qwaylandview.h" diff --git a/src/compositor/compositor_api/qwaylandinputpanel.cpp b/src/compositor/compositor_api/qwaylandinputpanel.cpp index c0317c93a..f4cd2476e 100644 --- a/src/compositor/compositor_api/qwaylandinputpanel.cpp +++ b/src/compositor/compositor_api/qwaylandinputpanel.cpp @@ -41,7 +41,6 @@ #include #include "qwlinputpanel_p.h" -#include "qwlsurface_p.h" QT_BEGIN_NAMESPACE @@ -54,10 +53,7 @@ QWaylandSurface *QWaylandInputPanel::focus() const { Q_D(const QWaylandInputPanel); - QtWayland::Surface *surface = d->focus(); - if (surface) - return surface->waylandSurface(); - return 0; + return d->focus(); } bool QWaylandInputPanel::visible() const diff --git a/src/compositor/compositor_api/qwaylandquickcompositor.cpp b/src/compositor/compositor_api/qwaylandquickcompositor.cpp index 14e80f0c3..6ff8374e3 100644 --- a/src/compositor/compositor_api/qwaylandquickcompositor.cpp +++ b/src/compositor/compositor_api/qwaylandquickcompositor.cpp @@ -36,7 +36,6 @@ ****************************************************************************/ #include -#include #include diff --git a/src/compositor/compositor_api/qwaylandquicksurface.cpp b/src/compositor/compositor_api/qwaylandquicksurface.cpp index 3e5f1c656..b91afe58f 100644 --- a/src/compositor/compositor_api/qwaylandquicksurface.cpp +++ b/src/compositor/compositor_api/qwaylandquicksurface.cpp @@ -54,8 +54,8 @@ QT_BEGIN_NAMESPACE class QWaylandQuickSurfacePrivate : public QWaylandSurfacePrivate { public: - QWaylandQuickSurfacePrivate(wl_client *client, quint32 id, int version, QWaylandQuickCompositor *c, QWaylandQuickSurface *surf) - : QWaylandSurfacePrivate(client, id, version, c, surf) + QWaylandQuickSurfacePrivate(wl_client *client, quint32 id, int version, QWaylandQuickCompositor *c) + : QWaylandSurfacePrivate(client, id, version, c) , compositor(c) , useTextureAlpha(true) , clientRenderingEnabled(true) @@ -72,7 +72,7 @@ public: }; QWaylandQuickSurface::QWaylandQuickSurface(wl_client *client, quint32 id, int version, QWaylandQuickCompositor *compositor) - : QWaylandSurface(new QWaylandQuickSurfacePrivate(client, id, version, compositor, this)) + : QWaylandSurface(new QWaylandQuickSurfacePrivate(client, id, version, compositor)) { } @@ -93,7 +93,7 @@ void QWaylandQuickSurface::setUseTextureAlpha(bool useTextureAlpha) if (d->useTextureAlpha != useTextureAlpha) { d->useTextureAlpha = useTextureAlpha; emit useTextureAlphaChanged(); - emit configure(handle()->currentBufferRef().hasBuffer()); + emit configure(d->currentBufferRef().hasBuffer()); } } diff --git a/src/compositor/compositor_api/qwaylandsurface.cpp b/src/compositor/compositor_api/qwaylandsurface.cpp index ca5e3cfb9..fdacee958 100644 --- a/src/compositor/compositor_api/qwaylandsurface.cpp +++ b/src/compositor/compositor_api/qwaylandsurface.cpp @@ -36,21 +36,21 @@ ****************************************************************************/ #include "qwaylandsurface.h" +#include "qwaylandsurface_p.h" #include -#include "wayland_wrapper/qwlsurface_p.h" #include "wayland_wrapper/qwlcompositor_p.h" #include "wayland_wrapper/qwlinputdevice_p.h" #include "wayland_wrapper/qwldatadevice_p.h" #include "wayland_wrapper/qwldatadevicemanager_p.h" +#include "wayland_wrapper/qwlregion_p.h" #include "extensions/qwlextendedsurface_p.h" #include "extensions/qwlsubsurface_p.h" #include "qwaylandcompositor.h" #include "qwaylandclient.h" -#include "qwaylandsurface_p.h" #include "qwaylandview_p.h" #include "qwaylandbufferref.h" @@ -61,12 +61,72 @@ QT_BEGIN_NAMESPACE -QWaylandSurfacePrivate::QWaylandSurfacePrivate(wl_client *wlClient, quint32 id, int version, QWaylandCompositor *compositor, QWaylandSurface *surface) - : QtWayland::Surface(wlClient, id, version, compositor, surface) - , closing(false) +namespace QtWayland { +class FrameCallback { +public: + FrameCallback(QWaylandSurface *surf, wl_resource *res) + : surface(surf) + , resource(res) + , canSend(false) + { +#if WAYLAND_VERSION_MAJOR < 1 || (WAYLAND_VERSION_MAJOR == 1 && WAYLAND_VERSION_MINOR <= 2) + res->data = this; + res->destroy = destroyCallback; +#else + wl_resource_set_implementation(res, 0, this, destroyCallback); +#endif + } + ~FrameCallback() + { + } + void destroy() + { + if (resource) + wl_resource_destroy(resource); + else + delete this; + } + void send(uint time) + { + wl_callback_send_done(resource, time); + wl_resource_destroy(resource); + } + static void destroyCallback(wl_resource *res) + { +#if WAYLAND_VERSION_MAJOR < 1 || (WAYLAND_VERSION_MAJOR == 1 && WAYLAND_VERSION_MINOR <= 2) + FrameCallback *_this = static_cast(res->data); +#else + FrameCallback *_this = static_cast(wl_resource_get_user_data(res)); +#endif + QWaylandSurfacePrivate::get(_this->surface)->removeFrameCallback(_this); + delete _this; + } + QWaylandSurface *surface; + wl_resource *resource; + bool canSend; +}; +} +static QRegion infiniteRegion() { + return QRegion(QRect(QPoint(std::numeric_limits::min(), std::numeric_limits::min()), + QPoint(std::numeric_limits::max(), std::numeric_limits::max()))); +} + +QWaylandSurfacePrivate::QWaylandSurfacePrivate(wl_client *client, quint32 id, int version, QWaylandCompositor *compositor) + : QtWaylandServer::wl_surface(client, id, version) + , m_compositor(compositor) , refCount(1) - , client(QWaylandClient::fromWlClient(compositor, wlClient)) -{} + , client(QWaylandClient::fromWlClient(compositor, client)) + , m_buffer(0) + , m_inputPanelSurface(0) + , m_inputRegion(infiniteRegion()) + , m_isCursorSurface(false) + , m_destroyed(false) + , m_contentOrientation(Qt::PrimaryOrientation) +{ + m_pending.buffer = 0; + m_pending.newlyAttached = false; + m_pending.inputRegion = infiniteRegion(); +} QWaylandSurfacePrivate::~QWaylandSurfacePrivate() { @@ -74,55 +134,233 @@ QWaylandSurfacePrivate::~QWaylandSurfacePrivate() QWaylandViewPrivate::get(views.at(i))->markSurfaceAsDestroyed(q_func()); } views.clear(); + + m_bufferRef = QWaylandBufferRef(); + + for (int i = 0; i < m_bufferPool.size(); i++) + m_bufferPool[i]->setDestroyIfUnused(true); + + foreach (QtWayland::FrameCallback *c, m_pendingFrameCallbacks) + c->destroy(); + foreach (QtWayland::FrameCallback *c, m_frameCallbacks) + c->destroy(); } -QWaylandSurface::QWaylandSurface(wl_client *client, quint32 id, int version, QWaylandCompositor *compositor) - : QObject(*new QWaylandSurfacePrivate(client, id, version, compositor, this)) +void QWaylandSurfacePrivate::setSize(const QSize &size) { + Q_Q(QWaylandSurface); + if (size != m_size) { + m_opaqueRegion = QRegion(); + m_size = size; + q->sizeChanged(); + } } -QWaylandSurface::QWaylandSurface(QWaylandSurfacePrivate *dptr) - : QObject(*dptr) +void QWaylandSurfacePrivate::sendFrameCallback() { + uint time = m_compositor->currentTimeMsecs(); + foreach (QtWayland::FrameCallback *callback, m_frameCallbacks) { + if (callback->canSend) { + callback->send(time); + m_frameCallbacks.removeOne(callback); + } + } } -QWaylandSurface::~QWaylandSurface() +void QWaylandSurfacePrivate::removeFrameCallback(QtWayland::FrameCallback *callback) { - Q_D(QWaylandSurface); - d->m_compositor->unregisterSurface(this); - d->notifyViewsAboutDestruction(); + m_pendingFrameCallbacks.removeOne(callback); + m_frameCallbacks.removeOne(callback); } -QWaylandClient *QWaylandSurface::client() const +void QWaylandSurfacePrivate::frameStarted() { - Q_D(const QWaylandSurface); - if (d->isDestroyed() || !d->compositor()->clients().contains(d->client)) - return Q_NULLPTR; + foreach (QtWayland::FrameCallback *c, m_frameCallbacks) + c->canSend = true; +} - return d->client; +void QWaylandSurfacePrivate::notifyViewsAboutDestruction() +{ + Q_Q(QWaylandSurface); + foreach (QWaylandView *view, views) { + QWaylandViewPrivate::get(view)->markSurfaceAsDestroyed(q); + } } -QWaylandSurface *QWaylandSurface::parentSurface() const +void QWaylandSurfacePrivate::surface_destroy_resource(Resource *) { - Q_D(const QWaylandSurface); - if (d->subSurface() && d->subSurface()->parent()) { - return d->subSurface()->parent()->surface(); + Q_Q(QWaylandSurface); + notifyViewsAboutDestruction(); + + m_destroyed = true; + q->destroy(); + emit q->surfaceDestroyed(); +} + +void QWaylandSurfacePrivate::surface_destroy(Resource *resource) +{ + wl_resource_destroy(resource->handle); +} + +void QWaylandSurfacePrivate::surface_attach(Resource *, struct wl_resource *buffer, int x, int y) +{ + if (m_pending.buffer) + m_pending.buffer->disown(); + m_pending.buffer = createSurfaceBuffer(buffer); + m_pending.offset = QPoint(x, y); + m_pending.newlyAttached = true; +} + +void QWaylandSurfacePrivate::surface_damage(Resource *, int32_t x, int32_t y, int32_t width, int32_t height) +{ + m_pending.damage = m_pending.damage.united(QRect(x, y, width, height)); +} + +void QWaylandSurfacePrivate::surface_frame(Resource *resource, uint32_t callback) +{ + Q_Q(QWaylandSurface); + struct wl_resource *frame_callback = wl_resource_create(resource->client(), &wl_callback_interface, wl_callback_interface.version, callback); + m_pendingFrameCallbacks << new QtWayland::FrameCallback(q, frame_callback); +} + +void QWaylandSurfacePrivate::surface_set_opaque_region(Resource *, struct wl_resource *region) +{ + m_opaqueRegion = region ? QtWayland::Region::fromResource(region)->region() : QRegion(); +} + +void QWaylandSurfacePrivate::surface_set_input_region(Resource *, struct wl_resource *region) +{ + if (region) { + m_pending.inputRegion = QtWayland::Region::fromResource(region)->region(); + } else { + m_pending.inputRegion = infiniteRegion(); } - return 0; } -QLinkedList QWaylandSurface::subSurfaces() const +void QWaylandSurfacePrivate::surface_commit(Resource *) { - Q_D(const QWaylandSurface); - if (d->subSurface()) { - return d->subSurface()->subSurfaces(); + Q_Q(QWaylandSurface); + + if (m_pending.buffer || m_pending.newlyAttached) { + setBackBuffer(m_pending.buffer, m_pending.damage); + } + + m_pending.buffer = 0; + m_pending.offset = QPoint(); + m_pending.newlyAttached = false; + m_pending.damage = QRegion(); + + if (m_buffer) + m_buffer->setCommitted(); + + m_frameCallbacks << m_pendingFrameCallbacks; + m_pendingFrameCallbacks.clear(); + + m_inputRegion = m_pending.inputRegion.intersected(QRect(QPoint(), m_size)); + + emit q->redraw(); +} + +void QWaylandSurfacePrivate::surface_set_buffer_transform(Resource *resource, int32_t orientation) +{ + Q_UNUSED(resource); + Q_Q(QWaylandSurface); + QScreen *screen = QGuiApplication::primaryScreen(); + bool isPortrait = screen->primaryOrientation() == Qt::PortraitOrientation; + Qt::ScreenOrientation oldOrientation = m_contentOrientation; + switch (orientation) { + case WL_OUTPUT_TRANSFORM_90: + m_contentOrientation = isPortrait ? Qt::InvertedLandscapeOrientation : Qt::PortraitOrientation; + break; + case WL_OUTPUT_TRANSFORM_180: + m_contentOrientation = isPortrait ? Qt::InvertedPortraitOrientation : Qt::InvertedLandscapeOrientation; + break; + case WL_OUTPUT_TRANSFORM_270: + m_contentOrientation = isPortrait ? Qt::LandscapeOrientation : Qt::InvertedPortraitOrientation; + break; + default: + m_contentOrientation = Qt::PrimaryOrientation; + } + if (m_contentOrientation != oldOrientation) + emit q->contentOrientationChanged(); +} + +void QWaylandSurfacePrivate::setBackBuffer(QtWayland::SurfaceBuffer *buffer, const QRegion &damage) +{ + Q_Q(QWaylandSurface); + QtWayland::SurfaceBuffer *oldBuffer = m_buffer; + m_buffer = buffer; + m_bufferRef = QWaylandBufferRef(m_buffer); + + if (m_buffer) { + bool valid = m_buffer->waylandBufferHandle() != 0; + if (valid) + setSize(m_buffer->size()); + + m_damage = damage.intersected(QRect(QPoint(), m_size)); + } else { + setSize(QSize()); + m_damage = QRect(); + } + + for (int i = 0; i < views.size(); i++) { + views.at(i)->attach(m_bufferRef, m_damage); + } + + emit q->damaged(m_damage); + if (QtWayland::SurfaceBuffer::hasContent(oldBuffer) != QtWayland::SurfaceBuffer::hasContent(m_buffer)) + emit q->mappedChanged(); + if (!m_pending.offset.isNull()) + emit q->offsetForNextFrame(m_pending.offset); +} + +QtWayland::SurfaceBuffer *QWaylandSurfacePrivate::createSurfaceBuffer(struct ::wl_resource *buffer) +{ + Q_Q(QWaylandSurface); + QtWayland::SurfaceBuffer *newBuffer = 0; + for (int i = 0; i < m_bufferPool.size(); i++) { + if (!m_bufferPool[i]->isRegisteredWithBuffer()) { + newBuffer = m_bufferPool[i]; + newBuffer->initialize(buffer); + break; + } + } + + if (!newBuffer) { + newBuffer = new QtWayland::SurfaceBuffer(q); + newBuffer->initialize(buffer); + m_bufferPool.append(newBuffer); + if (m_bufferPool.size() > 3) + qWarning() << "Increased buffer pool size to" << m_bufferPool.size() << "for surface" << q; } - return QLinkedList(); + + return newBuffer; } -bool QWaylandSurface::visible() const +QWaylandSurface::QWaylandSurface(wl_client *client, quint32 id, int version, QWaylandCompositor *compositor) + : QObject(*new QWaylandSurfacePrivate(client, id, version, compositor)) { - return isMapped(); +} + +QWaylandSurface::QWaylandSurface(QWaylandSurfacePrivate *dptr) + : QObject(*dptr) +{ +} + +QWaylandSurface::~QWaylandSurface() +{ + Q_D(QWaylandSurface); + d->m_compositor->handle()->unregisterSurface(this); + d->notifyViewsAboutDestruction(); +} + +QWaylandClient *QWaylandSurface::client() const +{ + Q_D(const QWaylandSurface); + if (isDestroyed() || !compositor()->clients().contains(d->client)) + return Q_NULLPTR; + + return d->client; } bool QWaylandSurface::isMapped() const @@ -149,16 +387,10 @@ QWaylandSurface::Origin QWaylandSurface::origin() const return d->origin(); } -QtWayland::Surface * QWaylandSurface::handle() -{ - Q_D(QWaylandSurface); - return d; -} - QWaylandCompositor *QWaylandSurface::compositor() const { Q_D(const QWaylandSurface); - return d->compositor()->waylandCompositor(); + return d->compositor(); } void QWaylandSurface::sendFrameCallbacks() @@ -167,18 +399,6 @@ void QWaylandSurface::sendFrameCallbacks() d->sendFrameCallback(); } -QString QWaylandSurface::className() const -{ - Q_D(const QWaylandSurface); - return d->className(); -} - -QString QWaylandSurface::title() const -{ - Q_D(const QWaylandSurface); - return d->title(); -} - bool QWaylandSurface::hasInputPanelSurface() const { Q_D(const QWaylandSurface); @@ -197,6 +417,12 @@ void QWaylandSurface::destroy() deref(); } +bool QWaylandSurface::isDestroyed() const +{ + Q_D(const QWaylandSurface); + return d->isDestroyed(); +} + void QWaylandSurface::markAsCursorSurface(bool cursorSurface) { Q_D(QWaylandSurface); @@ -221,7 +447,7 @@ void QWaylandSurface::updateSelection() if (inputDevice) { const QtWayland::DataDevice *dataDevice = QWaylandInputDevicePrivate::get(inputDevice)->dataDevice(); if (dataDevice) { - d->compositor()->dataDeviceManager()->offerRetainedSelection( + d->compositor()->handle()->dataDeviceManager()->offerRetainedSelection( dataDevice->resourceMap().value(d->resource()->client())->handle); } } @@ -237,7 +463,7 @@ void QWaylandSurface::deref() { Q_D(QWaylandSurface); if (--d->refCount == 0) - compositor()->handle()->destroySurface(d); + compositor()->handle()->destroySurface(this); } QWaylandView *QWaylandSurface::throttlingView() const @@ -273,9 +499,9 @@ QList QWaylandSurface::views() const QWaylandSurface *QWaylandSurface::fromResource(::wl_resource *res) { - QtWayland::Surface *s = QtWayland::Surface::fromResource(res); + QWaylandSurfacePrivate *s = QWaylandSurfacePrivate::fromResource(res); if (s) - return s->waylandSurface(); + return s->q_func(); return Q_NULLPTR; } @@ -290,39 +516,23 @@ QWaylandSurfacePrivate *QWaylandSurfacePrivate::get(QWaylandSurface *surface) return surface ? surface->d_func() : Q_NULLPTR; } -void QWaylandSurfacePrivate::setTitle(const QString &title) -{ - Q_Q(QWaylandSurface); - if (m_title != title) { - m_title = title; - emit q->titleChanged(); - } -} - -void QWaylandSurfacePrivate::setClassName(const QString &className) -{ - Q_Q(QWaylandSurface); - if (m_className != className) { - m_className = className; - emit q->classNameChanged(); - } -} - void QWaylandSurfacePrivate::refView(QWaylandView *view) { + Q_Q(QWaylandSurface); if (views.contains(view)) return; views.append(view); - waylandSurface()->ref(); + q->ref(); } void QWaylandSurfacePrivate::derefView(QWaylandView *view) { + Q_Q(QWaylandSurface); int nViews = views.removeAll(view); for (int i = 0; i < nViews && refCount > 0; i++) { - waylandSurface()->deref(); + q->deref(); } } diff --git a/src/compositor/compositor_api/qwaylandsurface.h b/src/compositor/compositor_api/qwaylandsurface.h index 17f585e73..45e4be94f 100644 --- a/src/compositor/compositor_api/qwaylandsurface.h +++ b/src/compositor/compositor_api/qwaylandsurface.h @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -59,12 +60,6 @@ class QWaylandBufferRef; class QWaylandView; class QWaylandSurfaceOp; -namespace QtWayland { -class Surface; -class SurfacePrivate; -class ExtendedSurface; -} - class Q_COMPOSITOR_EXPORT QWaylandSurface : public QObject, public QWaylandExtensionContainer { Q_OBJECT @@ -72,8 +67,6 @@ class Q_COMPOSITOR_EXPORT QWaylandSurface : public QObject, public QWaylandExten Q_PROPERTY(QWaylandClient *client READ client CONSTANT) Q_PROPERTY(QSize size READ size NOTIFY sizeChanged) Q_PROPERTY(Qt::ScreenOrientation contentOrientation READ contentOrientation NOTIFY contentOrientationChanged) - Q_PROPERTY(QString className READ className NOTIFY classNameChanged) - Q_PROPERTY(QString title READ title NOTIFY titleChanged) Q_PROPERTY(QWaylandSurface::Origin origin READ origin NOTIFY originChanged) Q_PROPERTY(bool isMapped READ isMapped NOTIFY mappedChanged) @@ -87,11 +80,8 @@ public: virtual ~QWaylandSurface(); QWaylandClient *client() const; + struct wl_client *waylandClient() const { return client()->client(); } - QWaylandSurface *parentSurface() const; - QLinkedList subSurfaces() const; - - bool visible() const; bool isMapped() const; QSize size() const; @@ -100,21 +90,14 @@ public: Origin origin() const; - QtWayland::Surface *handle(); - - QByteArray authenticationToken() const; - QWaylandCompositor *compositor() const; - QString className() const; - - QString title() const; - bool hasInputPanelSurface() const; bool inputRegionContains(const QPoint &p) const; Q_INVOKABLE void destroy(); + bool isDestroyed() const; Q_INVOKABLE void sendFrameCallbacks(); @@ -145,19 +128,12 @@ Q_SIGNALS: void sizeChanged(); void offsetForNextFrame(const QPoint &offset); void contentOrientationChanged(); - void extendedSurfaceReady(); - void classNameChanged(); - void titleChanged(); - void raiseRequested(); - void lowerRequested(); void pong(); void surfaceDestroyed(); void originChanged(); void configure(bool hasBuffer); void redraw(); - - friend class QtWayland::Surface; }; QT_END_NAMESPACE diff --git a/src/compositor/compositor_api/qwaylandsurface_p.h b/src/compositor/compositor_api/qwaylandsurface_p.h index 69e2fb6b9..91e5598f6 100644 --- a/src/compositor/compositor_api/qwaylandsurface_p.h +++ b/src/compositor/compositor_api/qwaylandsurface_p.h @@ -41,7 +41,25 @@ #include #include -#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include + +#include QT_BEGIN_NAMESPACE @@ -50,24 +68,116 @@ class QWaylandSurface; class QWaylandView; class QWaylandSurfaceInterface; -class Q_COMPOSITOR_EXPORT QWaylandSurfacePrivate : public QObjectPrivate, public QtWayland::Surface +namespace QtWayland { +class FrameCallback; +} + +class Q_COMPOSITOR_EXPORT QWaylandSurfacePrivate : public QObjectPrivate, public QtWaylandServer::wl_surface { - Q_DECLARE_PUBLIC(QWaylandSurface) public: static QWaylandSurfacePrivate *get(QWaylandSurface *surface); - QWaylandSurfacePrivate(wl_client *wlClient, quint32 id, int version, QWaylandCompositor *compositor, QWaylandSurface *surface); + + QWaylandSurfacePrivate(wl_client *wlClient, quint32 id, int version, QWaylandCompositor *compositor); ~QWaylandSurfacePrivate(); - void setTitle(const QString &title); - void setClassName(const QString &className); + void refView(QWaylandView *view); void derefView(QWaylandView *view); - bool closing; - int refCount; + static QWaylandSurfacePrivate *fromResource(struct ::wl_resource *resource) + { return static_cast(Resource::fromResource(resource)->surface_object); } - QWaylandClient *client; + bool mapped() const { return QtWayland::SurfaceBuffer::hasContent(m_buffer); } + + using QtWaylandServer::wl_surface::resource; + + QSize size() const { return m_size; } + void setSize(const QSize &size); + + QRegion inputRegion() const { return m_inputRegion; } + QRegion opaqueRegion() const { return m_opaqueRegion; } + + void sendFrameCallback(); + void removeFrameCallback(QtWayland::FrameCallback *callback); + + QPoint lastMousePos() const { return m_lastLocalMousePos; } + + void setInputPanelSurface(QtWayland::InputPanelSurface *inputPanelSurface) { m_inputPanelSurface = inputPanelSurface; } + QtWayland::InputPanelSurface *inputPanelSurface() const { return m_inputPanelSurface; } + + QWaylandCompositor *compositor() const { return m_compositor; } + + bool isCursorSurface() const { return m_isCursorSurface; } + void setCursorSurface(bool isCursor) { m_isCursorSurface = isCursor; } + void frameStarted(); + + inline bool isDestroyed() const { return m_destroyed; } + + Qt::ScreenOrientation contentOrientation() const { return m_contentOrientation; } + + QWaylandSurface::Origin origin() const { return m_buffer ? m_buffer->origin() : QWaylandSurface::OriginTopLeft; } + + QWaylandBufferRef currentBufferRef() const { return m_bufferRef; } + + void notifyViewsAboutDestruction(); +protected: + void surface_destroy_resource(Resource *resource) Q_DECL_OVERRIDE; + + void surface_destroy(Resource *resource) Q_DECL_OVERRIDE; + void surface_attach(Resource *resource, + struct wl_resource *buffer, int x, int y) Q_DECL_OVERRIDE; + void surface_damage(Resource *resource, + int32_t x, int32_t y, int32_t width, int32_t height) Q_DECL_OVERRIDE; + void surface_frame(Resource *resource, + uint32_t callback) Q_DECL_OVERRIDE; + void surface_set_opaque_region(Resource *resource, + struct wl_resource *region) Q_DECL_OVERRIDE; + void surface_set_input_region(Resource *resource, + struct wl_resource *region) Q_DECL_OVERRIDE; + void surface_commit(Resource *resource) Q_DECL_OVERRIDE; + void surface_set_buffer_transform(Resource *resource, int32_t transform) Q_DECL_OVERRIDE; + + void setBackBuffer(QtWayland::SurfaceBuffer *buffer, const QRegion &damage); + QtWayland::SurfaceBuffer *createSurfaceBuffer(struct ::wl_resource *buffer); + +protected: //member variables + QWaylandCompositor *m_compositor; + int refCount; + QWaylandClient *client; QList views; + QRegion m_damage; + QtWayland::SurfaceBuffer *m_buffer; + QWaylandBufferRef m_bufferRef; + + struct { + QtWayland::SurfaceBuffer *buffer; + QRegion damage; + QPoint offset; + bool newlyAttached; + QRegion inputRegion; + } m_pending; + + QPoint m_lastLocalMousePos; + QPoint m_lastGlobalMousePos; + + QList m_pendingFrameCallbacks; + QList m_frameCallbacks; + + QtWayland::InputPanelSurface *m_inputPanelSurface; + + QRegion m_inputRegion; + QRegion m_opaqueRegion; + + QVector m_bufferPool; + + QSize m_size; + bool m_isCursorSurface; + bool m_destroyed; + Qt::ScreenOrientation m_contentOrientation; + QWindow::Visibility m_visibility; + + Q_DECLARE_PUBLIC(QWaylandSurface) + Q_DISABLE_COPY(QWaylandSurfacePrivate) }; QT_END_NAMESPACE diff --git a/src/compositor/extensions/qwlextendedsurface.cpp b/src/compositor/extensions/qwlextendedsurface.cpp index c9aae421a..21292c14d 100644 --- a/src/compositor/extensions/qwlextendedsurface.cpp +++ b/src/compositor/extensions/qwlextendedsurface.cpp @@ -37,7 +37,6 @@ #include "qwlextendedsurface_p.h" #include "qwlcompositor_p.h" -#include "qwlsurface_p.h" QT_BEGIN_NAMESPACE @@ -53,12 +52,12 @@ void SurfaceExtensionGlobal::surface_extension_get_extended_surface(Resource *re uint32_t id, struct wl_resource *surface_resource) { - Surface *surface = Surface::fromResource(surface_resource); + QWaylandSurface *surface = QWaylandSurface::fromResource(surface_resource); new ExtendedSurface(resource->client(),id, wl_resource_get_version(resource->handle), surface); } -ExtendedSurface::ExtendedSurface(struct wl_client *client, uint32_t id, int version, Surface *surface) - : QWaylandExtensionTemplate(surface->waylandSurface()) +ExtendedSurface::ExtendedSurface(struct wl_client *client, uint32_t id, int version, QWaylandSurface *surface) + : QWaylandExtensionTemplate(surface) , QtWaylandServer::qt_extended_surface(client, id, version) , m_surface(surface) , m_windowFlags(0) @@ -88,7 +87,7 @@ void ExtendedSurface::setVisibility(QWindow::Visibility visibility) send_onscreen_visibility(visibility); } -void ExtendedSurface::setParentSurface(Surface *surface) +void ExtendedSurface::setParentSurface(QWaylandSurface *surface) { m_surface = surface; } @@ -172,14 +171,12 @@ void ExtendedSurface::extended_surface_destroy_resource(Resource *) void ExtendedSurface::extended_surface_raise(Resource *) { - if (m_surface) - emit m_surface->waylandSurface()->raiseRequested(); + emit raiseRequested(); } void ExtendedSurface::extended_surface_lower(Resource *) { - if (m_surface) - emit m_surface->waylandSurface()->lowerRequested(); + emit lowerRequested(); } } diff --git a/src/compositor/extensions/qwlextendedsurface_p.h b/src/compositor/extensions/qwlextendedsurface_p.h index f666c44a3..052ecf5e4 100644 --- a/src/compositor/extensions/qwlextendedsurface_p.h +++ b/src/compositor/extensions/qwlextendedsurface_p.h @@ -40,7 +40,6 @@ #include #include -#include #include #include @@ -82,7 +81,7 @@ public: }; Q_DECLARE_FLAGS(WindowFlags, WindowFlag) - ExtendedSurface(struct wl_client *client, uint32_t id, int version, Surface *surface); + ExtendedSurface(struct wl_client *client, uint32_t id, int version, QWaylandSurface *surface); ~ExtendedSurface(); void sendGenericProperty(const QString &name, const QVariant &variant); @@ -95,7 +94,7 @@ public: ExtendedSurface *parent() const; void setParent(ExtendedSurface *parent); QLinkedList subSurfaces() const; - void setParentSurface(Surface *s); + void setParentSurface(QWaylandSurface *s); Qt::ScreenOrientations contentOrientationMask() const; @@ -109,11 +108,13 @@ Q_SIGNALS: void contentOrientationMaskChanged(); void windowFlagsChanged(); void windowPropertyChanged(const QString &name, const QVariant &value); + void raiseRequested(); + void lowerRequested(); private: void setWindowPropertyImpl(const QString &name, const QVariant &value); - Surface *m_surface; + QWaylandSurface *m_surface; Qt::ScreenOrientations m_contentOrientationMask; diff --git a/src/compositor/extensions/qwlinputpanel.cpp b/src/compositor/extensions/qwlinputpanel.cpp index 4b0016aa2..cc4836bc7 100644 --- a/src/compositor/extensions/qwlinputpanel.cpp +++ b/src/compositor/extensions/qwlinputpanel.cpp @@ -42,7 +42,6 @@ #include "qwlinputdevice_p.h" #include "qwlinputmethod_p.h" #include "qwlinputpanelsurface_p.h" -#include "qwlsurface_p.h" #include "qwltextinput_p.h" QT_BEGIN_NAMESPACE @@ -68,12 +67,12 @@ QWaylandInputPanel *QWaylandInputPanelPrivate::waylandInputPanel() const return panel; } -QtWayland::Surface *QWaylandInputPanelPrivate::focus() const +QWaylandSurface *QWaylandInputPanelPrivate::focus() const { return m_focus; } -void QWaylandInputPanelPrivate::setFocus(QtWayland::Surface *focus) +void QWaylandInputPanelPrivate::setFocus(QWaylandSurface *focus) { Q_Q(QWaylandInputPanel); if (m_focus == focus) @@ -126,7 +125,7 @@ QWaylandInputPanelPrivate *QWaylandInputPanelPrivate::findIn(QWaylandExtensionCo void QWaylandInputPanelPrivate::input_panel_get_input_panel_surface(Resource *resource, uint32_t id, wl_resource *surface) { - new QtWayland::InputPanelSurface(resource->client(), id, QtWayland::Surface::fromResource(surface)); + new QtWayland::InputPanelSurface(resource->client(), id, QWaylandSurface::fromResource(surface)); } QT_END_NAMESPACE diff --git a/src/compositor/extensions/qwlinputpanel_p.h b/src/compositor/extensions/qwlinputpanel_p.h index 1e41296b5..65718892b 100644 --- a/src/compositor/extensions/qwlinputpanel_p.h +++ b/src/compositor/extensions/qwlinputpanel_p.h @@ -50,7 +50,6 @@ QT_BEGIN_NAMESPACE namespace QtWayland { class Compositor; -class Surface; class TextInput; } @@ -64,8 +63,8 @@ public: QWaylandInputPanel *waylandInputPanel() const; - QtWayland::Surface *focus() const; - void setFocus(QtWayland::Surface *focus); + QWaylandSurface *focus() const; + void setFocus(QWaylandSurface *focus); bool inputPanelVisible() const; void setInputPanelVisible(bool inputPanelVisible); @@ -80,7 +79,7 @@ protected: private: QtWayland::Compositor *m_compositor; - QtWayland::Surface *m_focus; + QWaylandSurface *m_focus; bool m_inputPanelVisible; QRect m_cursorRectangle; }; diff --git a/src/compositor/extensions/qwlinputpanelsurface.cpp b/src/compositor/extensions/qwlinputpanelsurface.cpp index a72afa2b3..55c03eaae 100644 --- a/src/compositor/extensions/qwlinputpanelsurface.cpp +++ b/src/compositor/extensions/qwlinputpanelsurface.cpp @@ -38,20 +38,21 @@ #include "qwlinputpanelsurface_p.h" #include "qwloutput_p.h" -#include "qwlsurface_p.h" + +#include QT_BEGIN_NAMESPACE namespace QtWayland { -InputPanelSurface::InputPanelSurface(wl_client *client, int id, Surface *surface) +InputPanelSurface::InputPanelSurface(wl_client *client, int id, QWaylandSurface *surface) : QtWaylandServer::wl_input_panel_surface(client, id, 1) , m_surface(surface) , m_type(Invalid) , m_output(0) , m_position() { - surface->setInputPanelSurface(this); + QWaylandSurfacePrivate::get(surface)->setInputPanelSurface(this); } InputPanelSurface::Type InputPanelSurface::type() const diff --git a/src/compositor/extensions/qwlinputpanelsurface_p.h b/src/compositor/extensions/qwlinputpanelsurface_p.h index 0591832fb..947c9d95f 100644 --- a/src/compositor/extensions/qwlinputpanelsurface_p.h +++ b/src/compositor/extensions/qwlinputpanelsurface_p.h @@ -40,12 +40,13 @@ #include +#include + QT_BEGIN_NAMESPACE namespace QtWayland { class Output; -class Surface; class InputPanelSurface : public QtWaylandServer::wl_input_panel_surface { @@ -56,7 +57,7 @@ public: OverlayPanel }; - InputPanelSurface(struct ::wl_client *client, int id, Surface *surface); + InputPanelSurface(struct ::wl_client *client, int id, QWaylandSurface *surface); Type type() const; @@ -68,7 +69,7 @@ protected: void input_panel_surface_set_toplevel(Resource *resource, wl_resource *output_resource, uint32_t position) Q_DECL_OVERRIDE; private: - Surface *m_surface; + QWaylandSurface *m_surface; Type m_type; diff --git a/src/compositor/extensions/qwlqtkey.cpp b/src/compositor/extensions/qwlqtkey.cpp index cc6bb7afd..875524bf5 100644 --- a/src/compositor/extensions/qwlqtkey.cpp +++ b/src/compositor/extensions/qwlqtkey.cpp @@ -35,7 +35,7 @@ ****************************************************************************/ #include "qwlqtkey_p.h" -#include "qwlsurface_p.h" +#include #include #include @@ -50,15 +50,15 @@ QtKeyExtensionGlobal::QtKeyExtensionGlobal(Compositor *compositor) { } -bool QtKeyExtensionGlobal::postQtKeyEvent(QKeyEvent *event, Surface *surface) +bool QtKeyExtensionGlobal::postQtKeyEvent(QKeyEvent *event, QWaylandSurface *surface) { uint32_t time = m_compositor->currentTimeMsecs(); - Resource *target = surface ? resourceMap().value(surface->resource()->client()) : 0; + Resource *target = surface ? resourceMap().value(surface->waylandClient()) : 0; if (target) { send_qtkey(target->handle, - surface ? surface->resource()->handle : 0, + surface ? surface->resource() : 0, time, event->type(), event->key(), event->modifiers(), event->nativeScanCode(), event->nativeVirtualKey(), diff --git a/src/compositor/extensions/qwlqtkey_p.h b/src/compositor/extensions/qwlqtkey_p.h index fa78037d3..67474ffc6 100644 --- a/src/compositor/extensions/qwlqtkey_p.h +++ b/src/compositor/extensions/qwlqtkey_p.h @@ -45,8 +45,8 @@ QT_BEGIN_NAMESPACE +class QWaylandSurface; class Compositor; -class Surface; class QKeyEvent; namespace QtWayland { @@ -57,7 +57,7 @@ class QtKeyExtensionGlobal : public QWaylandExtensionTemplate #include @@ -73,7 +72,7 @@ bool TouchExtensionGlobal::postTouchEvent(QTouchEvent *event, QWaylandView *view return false; QPointF surfacePos = view->requestedPosition(); - wl_client *surfaceClient = view->surface()->handle()->resource()->client(); + wl_client *surfaceClient = view->surface()->client()->client(); uint32_t time = m_compositor->currentTimeMsecs(); const int rescount = m_resources.count(); diff --git a/src/compositor/extensions/qwlshellsurface.cpp b/src/compositor/extensions/qwlshellsurface.cpp index 1a4e87bbb..3e0535ca1 100644 --- a/src/compositor/extensions/qwlshellsurface.cpp +++ b/src/compositor/extensions/qwlshellsurface.cpp @@ -38,7 +38,6 @@ #include "qwlshellsurface_p.h" #include "qwlcompositor_p.h" -#include "qwlsurface_p.h" #include "qwloutput_p.h" #include "qwlinputdevice_p.h" #include "qwlsubsurface_p.h" @@ -72,13 +71,13 @@ ShellSurfacePopupGrabber *Shell::getPopupGrabber(QWaylandInputDevice *input) void Shell::shell_get_shell_surface(Resource *resource, uint32_t id, struct ::wl_resource *surface_res) { - Surface *surface = Surface::fromResource(surface_res); + QWaylandSurface *surface = QWaylandSurface::fromResource(surface_res); ShellSurface *shell_surface = new ShellSurface(this, resource->client(), id, surface); - emit shellSurfaceCreated(surface->waylandSurface(), shell_surface); + emit shellSurfaceCreated(surface, shell_surface); } -ShellSurface::ShellSurface(Shell *shell, wl_client *client, uint32_t id, Surface *surface) - : QWaylandExtensionTemplate(surface->waylandSurface()) +ShellSurface::ShellSurface(Shell *shell, wl_client *client, uint32_t id, QWaylandSurface *surface) + : QWaylandExtensionTemplate(surface) , wl_shell_surface(client, id, 1) , m_shell(shell) , m_surface(surface) @@ -92,8 +91,8 @@ ShellSurface::ShellSurface(Shell *shell, wl_client *client, uint32_t id, Surface , m_transientParent(0) , m_transientOffset() { - connect(surface->waylandSurface(), &QWaylandSurface::mappedChanged, this, &ShellSurface::mappedChanged); - connect(surface->waylandSurface(), &QWaylandSurface::offsetForNextFrame, this, &ShellSurface::adjustOffset); + connect(surface, &QWaylandSurface::mappedChanged, this, &ShellSurface::mappedChanged); + connect(surface, &QWaylandSurface::offsetForNextFrame, this, &ShellSurface::adjustOffset); } ShellSurface::~ShellSurface() @@ -108,7 +107,7 @@ void ShellSurface::sendConfigure(uint32_t edges, int32_t width, int32_t height) void ShellSurface::ping() { - uint32_t serial = wl_display_next_serial(m_surface->compositor()->wl_display()); + uint32_t serial = wl_display_next_serial(m_surface->compositor()->waylandDisplay()); ping(serial); } @@ -170,11 +169,11 @@ void ShellSurface::setOffset(const QPointF &offset) void ShellSurface::mappedChanged() { - if (!m_surface->waylandSurface()->isMapped()) + if (!m_surface->isMapped()) return; if (m_surfaceType == Popup) { - if (m_surface->mapped() && m_popupGrabber->grabSerial() == m_popupSerial) { + if (m_surface->isMapped() && m_popupGrabber->grabSerial() == m_popupSerial) { m_popupGrabber->addPopup(this); } else { send_popup_done(); @@ -261,8 +260,6 @@ void ShellSurface::shell_surface_set_toplevel(Resource *resource) setTransientOffset(QPointF(0, 0)); setSurfaceType(Toplevel); - - m_surface->setVisibility(QWindow::Windowed); } void ShellSurface::shell_surface_set_transient(Resource *resource, @@ -283,8 +280,6 @@ void ShellSurface::shell_surface_set_transient(Resource *resource, m_transientInactive = false; setSurfaceType(Transient); - - m_surface->setVisibility(QWindow::AutomaticVisibility); } void ShellSurface::shell_surface_set_fullscreen(Resource *resource, @@ -317,7 +312,6 @@ void ShellSurface::shell_surface_set_fullscreen(Resource *resource, m_view->setRequestedPosition(output->geometry().topLeft()); send_configure(resize_bottom_right, outputSize.width(), outputSize.height()); - m_surface->setVisibility(QWindow::FullScreen); } void ShellSurface::shell_surface_set_popup(Resource *resource, wl_resource *input_device, uint32_t serial, wl_resource *parent, int32_t x, int32_t y, uint32_t flags) @@ -335,7 +329,6 @@ void ShellSurface::shell_surface_set_popup(Resource *resource, wl_resource *inpu setSurfaceType(Popup); - m_surface->setVisibility(QWindow::AutomaticVisibility); } void ShellSurface::shell_surface_set_maximized(Resource *resource, @@ -365,7 +358,6 @@ void ShellSurface::shell_surface_set_maximized(Resource *resource, m_view->setRequestedPosition(output->availableGeometry().topLeft()); send_configure(resize_bottom_right, outputSize.width(), outputSize.height()); - m_surface->setVisibility(QWindow::Maximized); } void ShellSurface::shell_surface_pong(Resource *resource, @@ -373,7 +365,7 @@ void ShellSurface::shell_surface_pong(Resource *resource, { Q_UNUSED(resource); if (m_pings.remove(serial)) - emit m_surface->waylandSurface()->pong(); + emit pong(); else qWarning("Received an unexpected pong!"); } @@ -382,14 +374,16 @@ void ShellSurface::shell_surface_set_title(Resource *resource, const QString &title) { Q_UNUSED(resource); - m_surface->setTitle(title); + m_title = title; + emit titleChanged(); } void ShellSurface::shell_surface_set_class(Resource *resource, const QString &className) { Q_UNUSED(resource); - m_surface->setClassName(className); + m_className = className; + emit classNameChanged(); } ShellSurfaceGrabber::ShellSurfaceGrabber(ShellSurface *shellSurface) diff --git a/src/compositor/extensions/qwlshellsurface_p.h b/src/compositor/extensions/qwlshellsurface_p.h index d222fba03..b7e28f8aa 100644 --- a/src/compositor/extensions/qwlshellsurface_p.h +++ b/src/compositor/extensions/qwlshellsurface_p.h @@ -83,6 +83,8 @@ class Q_COMPOSITOR_EXPORT ShellSurface : public QWaylandExtensionTemplate::iterator it; for (it = m_sub_surfaces.begin(); it != m_sub_surfaces.end(); ++it) { - (*it)->handle()->subSurface()->parentDestroyed(); + SubSurface *subSurfaceSub = SubSurface::findIn(*it); + subSurfaceSub->parentDestroyed(); } } diff --git a/src/compositor/extensions/qwlsubsurface_p.h b/src/compositor/extensions/qwlsubsurface_p.h index d86b6e7ea..70083fca3 100644 --- a/src/compositor/extensions/qwlsubsurface_p.h +++ b/src/compositor/extensions/qwlsubsurface_p.h @@ -37,16 +37,16 @@ #ifndef WLSUBSURFACE_H #define WLSUBSURFACE_H -#include - #include +#include +#include + #include QT_BEGIN_NAMESPACE class Compositor; -class QWaylandSurface; namespace QtWayland { @@ -62,7 +62,7 @@ private: void sub_surface_extension_get_sub_surface_aware_surface(Resource *resource, uint32_t id, struct ::wl_resource *surface) Q_DECL_OVERRIDE; }; -class SubSurface : public QWaylandExtensionTemplate, public QtWaylandServer::qt_sub_surface +class Q_COMPOSITOR_EXPORT SubSurface : public QWaylandExtensionTemplate, public QtWaylandServer::qt_sub_surface { Q_OBJECT Q_PROPERTY(SubSurface *parent READ parent WRITE setParent NOTIFY parentChanged) diff --git a/src/compositor/extensions/qwltextinput.cpp b/src/compositor/extensions/qwltextinput.cpp index 1da6acef1..465972d8f 100644 --- a/src/compositor/extensions/qwltextinput.cpp +++ b/src/compositor/extensions/qwltextinput.cpp @@ -41,7 +41,6 @@ #include "qwlinputmethod_p.h" #include "qwlinputmethodcontext_p.h" #include "qwlinputpanel_p.h" -#include "qwlsurface_p.h" #include @@ -59,7 +58,7 @@ TextInput::TextInput(QWaylandExtensionContainer *container, Compositor *composit { } -Surface *TextInput::focus() const +QWaylandSurface *TextInput::focus() const { return m_focus; } @@ -94,8 +93,8 @@ void TextInput::text_input_destroy_resource(Resource *) void TextInput::text_input_activate(Resource *, wl_resource *seat, wl_resource *surface) { - Surface *oldSurface = m_focus; - m_focus = Surface::fromResource(surface); + QWaylandSurface *oldSurface = m_focus; + m_focus = QWaylandSurface::fromResource(surface); if (oldSurface != m_focus) send_leave(); diff --git a/src/compositor/extensions/qwltextinput_p.h b/src/compositor/extensions/qwltextinput_p.h index 7580c86f2..bd4b212f4 100644 --- a/src/compositor/extensions/qwltextinput_p.h +++ b/src/compositor/extensions/qwltextinput_p.h @@ -44,18 +44,19 @@ QT_BEGIN_NAMESPACE +class QWaylandSurface; + namespace QtWayland { class Compositor; class InputMethod; -class Surface; class TextInput : public QWaylandExtensionTemplate, public QtWaylandServer::wl_text_input { public: explicit TextInput(QWaylandExtensionContainer *container, Compositor *compositor, struct ::wl_client *client, int id); - Surface *focus() const; + QWaylandSurface *focus() const; bool inputPanelVisible() const; QRect cursorRectangle() const; @@ -80,7 +81,7 @@ protected: private: Compositor *m_compositor; QList m_activeInputMethods; - Surface *m_focus; + QWaylandSurface *m_focus; bool m_inputPanelVisible; QRect m_cursorRectangle; diff --git a/src/compositor/wayland_wrapper/qwlcompositor.cpp b/src/compositor/wayland_wrapper/qwlcompositor.cpp index fee40c7ef..65b669a02 100644 --- a/src/compositor/wayland_wrapper/qwlcompositor.cpp +++ b/src/compositor/wayland_wrapper/qwlcompositor.cpp @@ -40,7 +40,7 @@ #include "qwaylandinput.h" #include "qwldisplay_p.h" #include "qwloutput_p.h" -#include "qwlsurface_p.h" +#include "qwaylandsurface_p.h" #include "qwaylandclient.h" #include "qwaylandcompositor.h" #include "qwldatadevicemanager_p.h" @@ -290,11 +290,11 @@ void Compositor::processWaylandEvents() wl_display_flush_clients(m_display->handle()); } -void Compositor::destroySurface(Surface *surface) +void Compositor::destroySurface(QWaylandSurface *surface) { - waylandCompositor()->surfaceAboutToBeDestroyed(surface->waylandSurface()); + waylandCompositor()->surfaceAboutToBeDestroyed(surface); - m_destroyed_surfaces << surface->waylandSurface(); + m_destroyed_surfaces << surface; } void Compositor::unregisterSurface(QWaylandSurface *surface) @@ -440,7 +440,7 @@ bool Compositor::isDragging() const } void Compositor::sendDragMoveEvent(const QPoint &global, const QPoint &local, - Surface *surface) + QWaylandSurface *surface) { Q_UNUSED(global); Q_UNUSED(local); diff --git a/src/compositor/wayland_wrapper/qwlcompositor_p.h b/src/compositor/wayland_wrapper/qwlcompositor_p.h index ce9d95460..fb71ea57c 100644 --- a/src/compositor/wayland_wrapper/qwlcompositor_p.h +++ b/src/compositor/wayland_wrapper/qwlcompositor_p.h @@ -96,7 +96,7 @@ public: QWaylandInputDevice *inputDeviceFor(QInputEvent *inputEvent); void removeInputDevice(QWaylandInputDevice *device); - void destroySurface(Surface *surface); + void destroySurface(QWaylandSurface *surface); void destroyClient(QWaylandClient *client); @@ -131,7 +131,7 @@ public: DataDeviceManager *dataDeviceManager() const; bool isDragging() const; - void sendDragMoveEvent(const QPoint &global, const QPoint &local, Surface *surface); + void sendDragMoveEvent(const QPoint &global, const QPoint &local, QWaylandSurface *surface); void sendDragEndEvent(); void setRetainedSelectionEnabled(bool enabled); diff --git a/src/compositor/wayland_wrapper/qwldatadevice.cpp b/src/compositor/wayland_wrapper/qwldatadevice.cpp index bd370a063..8dd33d3b0 100644 --- a/src/compositor/wayland_wrapper/qwldatadevice.cpp +++ b/src/compositor/wayland_wrapper/qwldatadevice.cpp @@ -42,7 +42,7 @@ #include "qwlinputdevice_p.h" #include "qwlkeyboard_p.h" #include "qwlpointer_p.h" -#include "qwlsurface_p.h" +#include "qwaylandsurface_p.h" #include "qwltouch_p.h" #include "qwldatadevicemanager_p.h" @@ -97,10 +97,10 @@ void DataDevice::setDragFocus(QWaylandView *focus, const QPointF &localPosition) if (!focus) return; - if (!m_dragDataSource && m_dragClient != focus->surface()->handle()->resource()->client()) + if (!m_dragDataSource && m_dragClient != focus->surface()->waylandClient()) return; - Resource *resource = resourceMap().value(focus->surface()->handle()->resource()->client()); + Resource *resource = resourceMap().value(focus->surface()->waylandClient()); if (!resource) return; @@ -112,7 +112,7 @@ void DataDevice::setDragFocus(QWaylandView *focus, const QPointF &localPosition) if (m_dragDataSource && !offer) return; - send_enter(resource->handle, serial, focus->surface()->handle()->resource()->handle, + send_enter(resource->handle, serial, focus->surface()->resource(), wl_fixed_from_double(localPosition.x()), wl_fixed_from_double(localPosition.y()), offer->resource()->handle); diff --git a/src/compositor/wayland_wrapper/qwldatadevicemanager.cpp b/src/compositor/wayland_wrapper/qwldatadevicemanager.cpp index 35bbf59f4..affc17d72 100644 --- a/src/compositor/wayland_wrapper/qwldatadevicemanager.cpp +++ b/src/compositor/wayland_wrapper/qwldatadevicemanager.cpp @@ -41,7 +41,6 @@ #include "qwlinputdevice_p.h" #include "qwlcompositor_p.h" #include "qwldataoffer_p.h" -#include "qwlsurface_p.h" #include "qwaylandmimehelper.h" #include @@ -204,7 +203,7 @@ void DataDeviceManager::overrideSelection(const QMimeData &mimeData) QWaylandSurface *focusSurface = QWaylandInputDevicePrivate::get(dev)->keyboardFocus(); if (focusSurface) offerFromCompositorToClient( - QWaylandInputDevicePrivate::get(dev)->dataDevice()->resourceMap().value(QWaylandSurfacePrivate::get(focusSurface)->resource()->client())->handle); + QWaylandInputDevicePrivate::get(dev)->dataDevice()->resourceMap().value(focusSurface->waylandClient())->handle); } bool DataDeviceManager::offerFromCompositorToClient(wl_resource *clientDataDeviceResource) diff --git a/src/compositor/wayland_wrapper/qwlinputdevice.cpp b/src/compositor/wayland_wrapper/qwlinputdevice.cpp index 80d91e684..858495ac1 100644 --- a/src/compositor/wayland_wrapper/qwlinputdevice.cpp +++ b/src/compositor/wayland_wrapper/qwlinputdevice.cpp @@ -39,7 +39,6 @@ #include "qwlcompositor_p.h" #include "qwldatadevice_p.h" #include "qwlinputmethod_p.h" -#include "qwlsurface_p.h" #include "qwlqttouch_p.h" #include "qwlqtkey_p.h" #include "qwaylandcompositor.h" @@ -160,9 +159,9 @@ void QWaylandInputDevicePrivate::sendMouseReleaseEvent(Qt::MouseButton button) pointerDevice()->sendMouseReleaseEvent(button); } -void QWaylandInputDevicePrivate::sendMouseMoveEvent(QWaylandView *surface, const QPointF &localPos, const QPointF &globalPos) +void QWaylandInputDevicePrivate::sendMouseMoveEvent(QWaylandView *view, const QPointF &localPos, const QPointF &globalPos) { - pointerDevice()->sendMouseMoveEvent(surface, localPos,globalPos); + pointerDevice()->sendMouseMoveEvent(view, localPos,globalPos); } void QWaylandInputDevicePrivate::sendMouseWheelEvent(Qt::Orientation orientation, int delta) @@ -200,7 +199,7 @@ void QWaylandInputDevicePrivate::sendFullKeyEvent(QKeyEvent *event) } QtWayland::QtKeyExtensionGlobal *ext = QtWayland::QtKeyExtensionGlobal::findIn(m_compositor); - if (ext && ext->postQtKeyEvent(event, keyboardFocus()->handle())) + if (ext && ext->postQtKeyEvent(event, keyboardFocus())) return; if (!m_keyboard.isNull() && !event->isAutoRepeat()) { @@ -215,7 +214,7 @@ void QWaylandInputDevicePrivate::sendFullKeyEvent(QWaylandSurface *surface, QKey { QtWayland::QtKeyExtensionGlobal *ext = QtWayland::QtKeyExtensionGlobal::findIn(m_compositor); if (ext) - ext->postQtKeyEvent(event, surface->handle()); + ext->postQtKeyEvent(event, surface); } void QWaylandInputDevicePrivate::sendFullTouchEvent(QTouchEvent *event) @@ -244,7 +243,7 @@ QWaylandSurface *QWaylandInputDevicePrivate::keyboardFocus() const */ bool QWaylandInputDevicePrivate::setKeyboardFocus(QWaylandSurface *surface) { - if (surface && surface->handle()->isDestroyed()) + if (surface && surface->isDestroyed()) return false; if (!m_keyboard.isNull() && m_keyboard->setFocus(surface)) { diff --git a/src/compositor/wayland_wrapper/qwlinputmethod.cpp b/src/compositor/wayland_wrapper/qwlinputmethod.cpp index ca7ce53fd..59f01c666 100644 --- a/src/compositor/wayland_wrapper/qwlinputmethod.cpp +++ b/src/compositor/wayland_wrapper/qwlinputmethod.cpp @@ -55,7 +55,7 @@ InputMethod::InputMethod(QWaylandCompositor *compositor, QWaylandInputDevice *se , m_textInput() , m_context() { - connect(seat->keyboard(), SIGNAL(focusChanged(Surface*)), this, SLOT(focusChanged(Surface*))); + connect(seat->keyboard(), &QWaylandKeyboard::focusChanged, this, &InputMethod::focusChanged); } InputMethod::~InputMethod() @@ -105,7 +105,7 @@ void InputMethod::deactivate() } } -void InputMethod::focusChanged(Surface *surface) +void InputMethod::focusChanged(QWaylandSurface *surface) { if (!m_textInput) return; diff --git a/src/compositor/wayland_wrapper/qwlinputmethod_p.h b/src/compositor/wayland_wrapper/qwlinputmethod_p.h index ee43b7ebc..b49a6668a 100644 --- a/src/compositor/wayland_wrapper/qwlinputmethod_p.h +++ b/src/compositor/wayland_wrapper/qwlinputmethod_p.h @@ -42,6 +42,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE class QWaylandInputDevice; @@ -51,7 +53,6 @@ namespace QtWayland { class InputMethodContext; class TextInput; -class Surface; class InputMethod : public QObject, public QtWaylandServer::wl_input_method { @@ -74,7 +75,7 @@ protected: void input_method_destroy_resource(Resource *resource); private Q_SLOTS: - void focusChanged(Surface *surface); + void focusChanged(QWaylandSurface *surface); private: QWaylandCompositor *m_compositor; diff --git a/src/compositor/wayland_wrapper/qwlkeyboard.cpp b/src/compositor/wayland_wrapper/qwlkeyboard.cpp index d40422c31..c22b0cb26 100644 --- a/src/compositor/wayland_wrapper/qwlkeyboard.cpp +++ b/src/compositor/wayland_wrapper/qwlkeyboard.cpp @@ -43,7 +43,6 @@ #include #include "qwlcompositor_p.h" -#include "qwlsurface_p.h" #include #include @@ -117,11 +116,11 @@ void QWaylandKeyboardPrivate::focused(QWaylandSurface *surface) surface = Q_NULLPTR; if (m_focusResource && m_focus != surface) { uint32_t serial = wl_display_next_serial(compositor()->waylandDisplay()); - send_leave(m_focusResource->handle, serial, m_focus->handle()->resource()->handle); + send_leave(m_focusResource->handle, serial, m_focus->resource()); m_focusDestroyListener.reset(); } - Resource *resource = surface ? resourceMap().value(surface->client()->client()) : 0; + Resource *resource = surface ? resourceMap().value(surface->waylandClient()) : 0; if (resource && (m_focus != surface || m_focusResource != resource)) { uint32_t serial = wl_display_next_serial(compositor()->waylandDisplay()); diff --git a/src/compositor/wayland_wrapper/qwloutput.cpp b/src/compositor/wayland_wrapper/qwloutput.cpp index caffb9028..82278f301 100644 --- a/src/compositor/wayland_wrapper/qwloutput.cpp +++ b/src/compositor/wayland_wrapper/qwloutput.cpp @@ -37,7 +37,6 @@ #include "qwloutput_p.h" #include "qwlcompositor_p.h" -#include "qwlsurface_p.h" #include #include @@ -49,6 +48,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE namespace QtWayland { @@ -332,7 +333,7 @@ void Output::frameStarted() for (int i = 0; i < m_surfaceViews.size(); i++) { SurfaceViewMapper &surfacemapper = m_surfaceViews[i]; if (surfacemapper.maybeThrottelingView()) - surfacemapper.surface->handle()->frameStarted(); + QWaylandSurfacePrivate::get(surfacemapper.surface)->frameStarted(); } } @@ -345,7 +346,7 @@ void Output::sendFrameCallbacks() surfaceEnter(surfacemapper.surface); } if (surfacemapper.maybeThrottelingView()) - surfacemapper.surface->handle()->sendFrameCallback(); + QWaylandSurfacePrivate::get(surfacemapper.surface)->sendFrameCallback(); } } wl_display_flush_clients(compositor()->waylandDisplay()); @@ -355,14 +356,14 @@ void Output::surfaceEnter(QWaylandSurface *surface) { if (!surface) return; - surface->handle()->send_enter(outputForClient(surface->client())->handle); + QWaylandSurfacePrivate::get(surface)->send_enter(outputForClient(surface->client())->handle); } void Output::surfaceLeave(QWaylandSurface *surface) { if (!surface) return; - surface->handle()->send_leave(outputForClient(surface->client())->handle); + QWaylandSurfacePrivate::get(surface)->send_leave(outputForClient(surface->client())->handle); } void Output::addView(QWaylandView *view) diff --git a/src/compositor/wayland_wrapper/qwlpointer.cpp b/src/compositor/wayland_wrapper/qwlpointer.cpp index 13963d269..9e66f4636 100644 --- a/src/compositor/wayland_wrapper/qwlpointer.cpp +++ b/src/compositor/wayland_wrapper/qwlpointer.cpp @@ -40,7 +40,6 @@ #include "qwlcompositor_p.h" #include "qwlinputdevice_p.h" #include "qwlkeyboard_p.h" -#include "qwlsurface_p.h" #include "qwaylandcompositor.h" #include "qwaylandview.h" @@ -164,17 +163,17 @@ void QWaylandPointerPrivate::sendMouseMoveEvent(QWaylandView *view, const QPoint m_localPosition.ry() -= 0.01; } - Resource *resource = view ? resourceMap().value(view->surface()->handle()->resource()->client()) : 0; + Resource *resource = view ? resourceMap().value(view->surface()->waylandClient()) : 0; if (resource && !m_hasSentEnter) { uint32_t serial = compositor()->nextSerial(); QWaylandKeyboard *keyboard = m_seat->keyboard(); if (keyboard) { keyboard->sendKeyModifiers(view->surface()->client(), serial); } - send_enter(resource->handle, serial, view->surface()->handle()->resource()->handle, + send_enter(resource->handle, serial, view->surface()->resource(), wl_fixed_from_double(m_localPosition.x()), wl_fixed_from_double(m_localPosition.y())); - m_focusDestroyListener.listenForDestruction(view->surface()->handle()->resource()->handle); + m_focusDestroyListener.listenForDestruction(view->surface()->resource()); m_hasSentEnter = true; } diff --git a/src/compositor/wayland_wrapper/qwlsurface.cpp b/src/compositor/wayland_wrapper/qwlsurface.cpp deleted file mode 100644 index 45194f13a..000000000 --- a/src/compositor/wayland_wrapper/qwlsurface.cpp +++ /dev/null @@ -1,427 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwlsurface_p.h" - -#include "qwaylandsurface.h" -#include "qwaylandsurface_p.h" -#include "qwaylandview.h" -#include "qwaylandview_p.h" -#include "qwaylandoutput.h" -#include "qwlcompositor_p.h" -#include "qwlinputdevice_p.h" -#include "qwlextendedsurface_p.h" -#include "qwlregion_p.h" -#include "qwlsubsurface_p.h" -#include "qwlsurfacebuffer_p.h" -#include "qwaylandoutput.h" -#include "qwaylandsurface_p.h" - -#include -#include -#include -#include - -#include - -QT_BEGIN_NAMESPACE - -namespace QtWayland { - -class FrameCallback { -public: - FrameCallback(Surface *surf, wl_resource *res) - : surface(surf) - , resource(res) - , canSend(false) - { -#if WAYLAND_VERSION_MAJOR < 1 || (WAYLAND_VERSION_MAJOR == 1 && WAYLAND_VERSION_MINOR <= 2) - res->data = this; - res->destroy = destroyCallback; -#else - wl_resource_set_implementation(res, 0, this, destroyCallback); -#endif - } - ~FrameCallback() - { - } - void destroy() - { - if (resource) - wl_resource_destroy(resource); - else - delete this; - } - void send(uint time) - { - wl_callback_send_done(resource, time); - wl_resource_destroy(resource); - } - static void destroyCallback(wl_resource *res) - { -#if WAYLAND_VERSION_MAJOR < 1 || (WAYLAND_VERSION_MAJOR == 1 && WAYLAND_VERSION_MINOR <= 2) - FrameCallback *_this = static_cast(res->data); -#else - FrameCallback *_this = static_cast(wl_resource_get_user_data(res)); -#endif - _this->surface->removeFrameCallback(_this); - delete _this; - } - Surface *surface; - wl_resource *resource; - bool canSend; -}; - -static QRegion infiniteRegion() { - return QRegion(QRect(QPoint(std::numeric_limits::min(), std::numeric_limits::min()), - QPoint(std::numeric_limits::max(), std::numeric_limits::max()))); -} - -Surface::Surface(struct wl_client *client, uint32_t id, int version, QWaylandCompositor *compositor, QWaylandSurface *surface) - : QtWaylandServer::wl_surface(client, id, version) - , m_compositor(compositor->handle()) - , m_waylandSurface(surface) - , m_buffer(0) - , m_surfaceMapped(false) - , m_subSurface(0) - , m_inputPanelSurface(0) - , m_inputRegion(infiniteRegion()) - , m_isCursorSurface(false) - , m_destroyed(false) - , m_contentOrientation(Qt::PrimaryOrientation) - , m_visibility(QWindow::Hidden) -{ - m_pending.buffer = 0; - m_pending.newlyAttached = false; - m_pending.inputRegion = infiniteRegion(); -} - -Surface::~Surface() -{ - delete m_subSurface; - - m_bufferRef = QWaylandBufferRef(); - - for (int i = 0; i < m_bufferPool.size(); i++) - m_bufferPool[i]->setDestroyIfUnused(true); - - foreach (FrameCallback *c, m_pendingFrameCallbacks) - c->destroy(); - foreach (FrameCallback *c, m_frameCallbacks) - c->destroy(); -} - -Surface *Surface::fromResource(struct ::wl_resource *resource) -{ - return static_cast(Resource::fromResource(resource)->surface_object); -} - -QSize Surface::size() const -{ - return m_size; -} - -void Surface::setSize(const QSize &size) -{ - if (size != m_size) { - m_opaqueRegion = QRegion(); - m_size = size; - m_waylandSurface->sizeChanged(); - } -} - -QRegion Surface::inputRegion() const -{ - return m_inputRegion; -} - -QRegion Surface::opaqueRegion() const -{ - return m_opaqueRegion; -} - -void Surface::sendFrameCallback() -{ - uint time = m_compositor->currentTimeMsecs(); - foreach (FrameCallback *callback, m_frameCallbacks) { - if (callback->canSend) { - callback->send(time); - m_frameCallbacks.removeOne(callback); - } - } -} - -void Surface::removeFrameCallback(FrameCallback *callback) -{ - m_pendingFrameCallbacks.removeOne(callback); - m_frameCallbacks.removeOne(callback); -} - -QWaylandSurface * Surface::waylandSurface() const -{ - return m_waylandSurface; -} - -QPoint Surface::lastMousePos() const -{ - return m_lastLocalMousePos; -} - -void Surface::setSubSurface(SubSurface *subSurface) -{ - m_subSurface = subSurface; -} - -SubSurface *Surface::subSurface() const -{ - return m_subSurface; -} - -void Surface::setInputPanelSurface(InputPanelSurface *inputPanelSurface) -{ - m_inputPanelSurface = inputPanelSurface; -} - -InputPanelSurface *Surface::inputPanelSurface() const -{ - return m_inputPanelSurface; -} - -Compositor *Surface::compositor() const -{ - return m_compositor; -} - -/*! - * Sets the backbuffer for this surface. The back buffer is not yet on - * screen and will become live during the next swapBuffers(). - * - * The backbuffer represents the current state of the surface for the - * purpose of GUI-thread accessible properties such as size and visibility. - */ -void Surface::setBackBuffer(SurfaceBuffer *buffer, const QRegion &damage) -{ - m_buffer = buffer; - m_bufferRef = QWaylandBufferRef(m_buffer); - - if (m_buffer) { - bool valid = m_buffer->waylandBufferHandle() != 0; - if (valid) - setSize(m_buffer->size()); - - m_damage = damage.intersected(QRect(QPoint(), m_size)); - } else { - setSize(QSize()); - m_damage = QRect(); - } - - QWaylandSurfacePrivate *priv = QWaylandSurfacePrivate::get(waylandSurface()); - for (int i = 0; i < priv->views.size(); i++) { - priv->views.at(i)->attach(m_bufferRef, m_damage); - } - - emit m_waylandSurface->damaged(m_damage); - setMapped(m_bufferRef.hasBuffer()); - if (!m_pending.offset.isNull()) - emit m_waylandSurface->offsetForNextFrame(m_pending.offset); -} - -bool Surface::mapped() const -{ - return m_buffer && bool(m_buffer->waylandBufferHandle()); -} - -void Surface::setMapped(bool mapped) -{ - if (m_surfaceMapped == mapped) - return; - - m_surfaceMapped = mapped; - emit m_waylandSurface->mappedChanged(); -} - -SurfaceBuffer *Surface::createSurfaceBuffer(struct ::wl_resource *buffer) -{ - SurfaceBuffer *newBuffer = 0; - for (int i = 0; i < m_bufferPool.size(); i++) { - if (!m_bufferPool[i]->isRegisteredWithBuffer()) { - newBuffer = m_bufferPool[i]; - newBuffer->initialize(buffer); - break; - } - } - - if (!newBuffer) { - newBuffer = new SurfaceBuffer(this); - newBuffer->initialize(buffer); - m_bufferPool.append(newBuffer); - if (m_bufferPool.size() > 3) - qWarning() << "Increased buffer pool size to" << m_bufferPool.size() << "for surface with title:" << title() << "className:" << className(); - } - - return newBuffer; -} - -Qt::ScreenOrientation Surface::contentOrientation() const -{ - return m_contentOrientation; -} - -void Surface::notifyViewsAboutDestruction() -{ - foreach (QWaylandView *view, m_waylandSurface->views()) { - QWaylandViewPrivate::get(view)->markSurfaceAsDestroyed(m_waylandSurface); - } -} - -void Surface::surface_destroy_resource(Resource *) -{ - notifyViewsAboutDestruction(); - - m_destroyed = true; - m_waylandSurface->destroy(); - emit m_waylandSurface->surfaceDestroyed(); -} - -void Surface::surface_destroy(Resource *resource) -{ - wl_resource_destroy(resource->handle); -} - -void Surface::surface_attach(Resource *, struct wl_resource *buffer, int x, int y) -{ - if (m_pending.buffer) - m_pending.buffer->disown(); - m_pending.buffer = createSurfaceBuffer(buffer); - m_pending.offset = QPoint(x, y); - m_pending.newlyAttached = true; -} - -void Surface::surface_damage(Resource *, int32_t x, int32_t y, int32_t width, int32_t height) -{ - m_pending.damage = m_pending.damage.united(QRect(x, y, width, height)); -} - -void Surface::surface_frame(Resource *resource, uint32_t callback) -{ - struct wl_resource *frame_callback = wl_resource_create(resource->client(), &wl_callback_interface, wl_callback_interface.version, callback); - m_pendingFrameCallbacks << new FrameCallback(this, frame_callback); -} - -void Surface::surface_set_opaque_region(Resource *, struct wl_resource *region) -{ - m_opaqueRegion = region ? Region::fromResource(region)->region() : QRegion(); -} - -void Surface::surface_set_input_region(Resource *, struct wl_resource *region) -{ - if (region) { - m_pending.inputRegion = Region::fromResource(region)->region(); - } else { - m_pending.inputRegion = infiniteRegion(); - } -} - -void Surface::surface_commit(Resource *) -{ - if (m_pending.buffer || m_pending.newlyAttached) { - setBackBuffer(m_pending.buffer, m_pending.damage); - } - - m_pending.buffer = 0; - m_pending.offset = QPoint(); - m_pending.newlyAttached = false; - m_pending.damage = QRegion(); - - if (m_buffer) - m_buffer->setCommitted(); - - m_frameCallbacks << m_pendingFrameCallbacks; - m_pendingFrameCallbacks.clear(); - - m_inputRegion = m_pending.inputRegion.intersected(QRect(QPoint(), m_size)); - - emit m_waylandSurface->redraw(); -} - -void Surface::surface_set_buffer_transform(Resource *resource, int32_t orientation) -{ - Q_UNUSED(resource); - QScreen *screen = QGuiApplication::primaryScreen(); - bool isPortrait = screen->primaryOrientation() == Qt::PortraitOrientation; - Qt::ScreenOrientation oldOrientation = m_contentOrientation; - switch (orientation) { - case WL_OUTPUT_TRANSFORM_90: - m_contentOrientation = isPortrait ? Qt::InvertedLandscapeOrientation : Qt::PortraitOrientation; - break; - case WL_OUTPUT_TRANSFORM_180: - m_contentOrientation = isPortrait ? Qt::InvertedPortraitOrientation : Qt::InvertedLandscapeOrientation; - break; - case WL_OUTPUT_TRANSFORM_270: - m_contentOrientation = isPortrait ? Qt::LandscapeOrientation : Qt::InvertedPortraitOrientation; - break; - default: - m_contentOrientation = Qt::PrimaryOrientation; - } - if (m_contentOrientation != oldOrientation) - emit waylandSurface()->contentOrientationChanged(); -} - -void Surface::frameStarted() -{ - foreach (FrameCallback *c, m_frameCallbacks) - c->canSend = true; -} - -void Surface::setClassName(const QString &className) -{ - if (m_className != className) { - m_className = className; - emit waylandSurface()->classNameChanged(); - } -} - -void Surface::setTitle(const QString &title) -{ - if (m_title != title) { - m_title = title; - emit waylandSurface()->titleChanged(); - } -} - -} // namespace Wayland - -QT_END_NAMESPACE diff --git a/src/compositor/wayland_wrapper/qwlsurface_p.h b/src/compositor/wayland_wrapper/qwlsurface_p.h deleted file mode 100644 index ae92d6f47..000000000 --- a/src/compositor/wayland_wrapper/qwlsurface_p.h +++ /dev/null @@ -1,196 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef WL_SURFACE_H -#define WL_SURFACE_H - -#include - -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include - -#include - -#include - -QT_BEGIN_NAMESPACE - -class QTouchEvent; - -namespace QtWayland { - -class Compositor; -class Buffer; -class ExtendedSurface; -class InputPanelSurface; -class SubSurface; -class FrameCallback; - -class Q_COMPOSITOR_EXPORT Surface : public QtWaylandServer::wl_surface -{ -public: - Surface(struct wl_client *client, uint32_t id, int version, QWaylandCompositor *compositor, QWaylandSurface *surface); - ~Surface(); - - static Surface *fromResource(struct ::wl_resource *resource); - - bool mapped() const; - - using QtWaylandServer::wl_surface::resource; - - QSize size() const; - void setSize(const QSize &size); - - QRegion inputRegion() const; - QRegion opaqueRegion() const; - - void sendFrameCallback(); - void removeFrameCallback(FrameCallback *callback); - - QWaylandSurface *waylandSurface() const; - - QPoint lastMousePos() const; - - void setSubSurface(SubSurface *subSurface); - SubSurface *subSurface() const; - - void setInputPanelSurface(InputPanelSurface *inputPanelSurface); - InputPanelSurface *inputPanelSurface() const; - - Compositor *compositor() const; - - QString className() const { return m_className; } - void setClassName(const QString &className); - - QString title() const { return m_title; } - void setTitle(const QString &title); - - bool isCursorSurface() const { return m_isCursorSurface; } - void setCursorSurface(bool isCursor) { m_isCursorSurface = isCursor; } - - void frameStarted(); - - void setMapped(bool mapped); - void setVisibility(QWindow::Visibility visibility) { m_visibility = visibility; } - - inline bool isDestroyed() const { return m_destroyed; } - - Qt::ScreenOrientation contentOrientation() const; - - QWaylandSurface::Origin origin() const { return m_buffer ? m_buffer->origin() : QWaylandSurface::OriginTopLeft; } - - QWaylandBufferRef currentBufferRef() const { return m_bufferRef; } - - void notifyViewsAboutDestruction(); -protected: - void surface_destroy_resource(Resource *resource) Q_DECL_OVERRIDE; - - void surface_destroy(Resource *resource) Q_DECL_OVERRIDE; - void surface_attach(Resource *resource, - struct wl_resource *buffer, int x, int y) Q_DECL_OVERRIDE; - void surface_damage(Resource *resource, - int32_t x, int32_t y, int32_t width, int32_t height) Q_DECL_OVERRIDE; - void surface_frame(Resource *resource, - uint32_t callback) Q_DECL_OVERRIDE; - void surface_set_opaque_region(Resource *resource, - struct wl_resource *region) Q_DECL_OVERRIDE; - void surface_set_input_region(Resource *resource, - struct wl_resource *region) Q_DECL_OVERRIDE; - void surface_commit(Resource *resource) Q_DECL_OVERRIDE; - void surface_set_buffer_transform(Resource *resource, int32_t transform) Q_DECL_OVERRIDE; - - Q_DISABLE_COPY(Surface) - - Compositor *m_compositor; - QWaylandSurface *m_waylandSurface; - - QRegion m_damage; - SurfaceBuffer *m_buffer; - QWaylandBufferRef m_bufferRef; - bool m_surfaceMapped; - - struct { - SurfaceBuffer *buffer; - QRegion damage; - QPoint offset; - bool newlyAttached; - QRegion inputRegion; - } m_pending; - - QPoint m_lastLocalMousePos; - QPoint m_lastGlobalMousePos; - - QList m_pendingFrameCallbacks; - QList m_frameCallbacks; - - SubSurface *m_subSurface; - InputPanelSurface *m_inputPanelSurface; - - QRegion m_inputRegion; - QRegion m_opaqueRegion; - - QVector m_bufferPool; - - QSize m_size; - QString m_className; - QString m_title; - bool m_isCursorSurface; - bool m_destroyed; - Qt::ScreenOrientation m_contentOrientation; - QWindow::Visibility m_visibility; - - void setBackBuffer(SurfaceBuffer *buffer, const QRegion &damage); - - SurfaceBuffer *createSurfaceBuffer(struct ::wl_resource *buffer); - - friend class QWaylandSurface; -}; - -} - -QT_END_NAMESPACE - -#endif //WL_SURFACE_H diff --git a/src/compositor/wayland_wrapper/qwlsurfacebuffer.cpp b/src/compositor/wayland_wrapper/qwlsurfacebuffer.cpp index 225b49f4f..9c7671855 100644 --- a/src/compositor/wayland_wrapper/qwlsurfacebuffer.cpp +++ b/src/compositor/wayland_wrapper/qwlsurfacebuffer.cpp @@ -36,7 +36,6 @@ #include "qwlsurfacebuffer_p.h" -#include "qwlsurface_p.h" #include "qwlcompositor_p.h" #ifdef QT_COMPOSITOR_WAYLAND_GL @@ -53,7 +52,7 @@ QT_BEGIN_NAMESPACE namespace QtWayland { -SurfaceBuffer::SurfaceBuffer(Surface *surface) +SurfaceBuffer::SurfaceBuffer(QWaylandSurface *surface) : m_surface(surface) , m_compositor(surface->compositor()) , m_buffer(0) @@ -161,7 +160,7 @@ QSize SurfaceBuffer::size() const int height = wl_shm_buffer_get_height(shmBuffer); return QSize(width, height); } - if (ClientBufferIntegration *integration = m_compositor->clientBufferIntegration()) { + if (ClientBufferIntegration *integration = m_compositor->handle()->clientBufferIntegration()) { return integration->bufferSize(m_buffer); } @@ -174,7 +173,7 @@ QWaylandSurface::Origin SurfaceBuffer::origin() const return QWaylandSurface::OriginTopLeft; } - if (ClientBufferIntegration *integration = m_compositor->clientBufferIntegration()) { + if (ClientBufferIntegration *integration = m_compositor->handle()->clientBufferIntegration()) { return integration->origin(m_buffer); } return QWaylandSurface::OriginTopLeft; @@ -210,7 +209,7 @@ void SurfaceBuffer::bindToTexture() const glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image.width(), image.height(), 0, GL_RGB, GL_UNSIGNED_BYTE, image.constBits()); } } else { - if (QtWayland::ClientBufferIntegration *clientInt = m_compositor->clientBufferIntegration()) { + if (QtWayland::ClientBufferIntegration *clientInt = m_compositor->handle()->clientBufferIntegration()) { clientInt->bindTextureToBuffer(m_buffer); } } diff --git a/src/compositor/wayland_wrapper/qwlsurfacebuffer_p.h b/src/compositor/wayland_wrapper/qwlsurfacebuffer_p.h index 8eecfa73f..ce2c2686d 100644 --- a/src/compositor/wayland_wrapper/qwlsurfacebuffer_p.h +++ b/src/compositor/wayland_wrapper/qwlsurfacebuffer_p.h @@ -50,12 +50,10 @@ QT_BEGIN_NAMESPACE class QWaylandClientBufferIntegration; class QWaylandBufferRef; +class QWaylandCompositor; namespace QtWayland { -class Surface; -class Compositor; - struct surface_buffer_destroy_listener { struct wl_listener listener; @@ -65,7 +63,7 @@ struct surface_buffer_destroy_listener class SurfaceBuffer { public: - SurfaceBuffer(Surface *surface); + SurfaceBuffer(QWaylandSurface *surface); ~SurfaceBuffer(); @@ -96,13 +94,14 @@ public: QImage image() const; void bindToTexture() const; + static bool hasContent(SurfaceBuffer *buffer) { return buffer && buffer->isRegisteredWithBuffer(); } private: void ref(); void deref(); void destroyIfUnused(); - Surface *m_surface; - Compositor *m_compositor; + QWaylandSurface *m_surface; + QWaylandCompositor *m_compositor; struct ::wl_resource *m_buffer; struct surface_buffer_destroy_listener m_destroy_listener; bool m_committed; diff --git a/src/compositor/wayland_wrapper/qwltouch.cpp b/src/compositor/wayland_wrapper/qwltouch.cpp index 7f69f955f..85675a624 100644 --- a/src/compositor/wayland_wrapper/qwltouch.cpp +++ b/src/compositor/wayland_wrapper/qwltouch.cpp @@ -38,7 +38,6 @@ #include "qwltouch_p.h" #include "qwlcompositor_p.h" -#include "qwlsurface_p.h" #include "qwaylandview.h" #include "qwlqttouch_p.h" diff --git a/src/compositor/wayland_wrapper/qwltouch_p.h b/src/compositor/wayland_wrapper/qwltouch_p.h index 52beb81a6..c970d1c87 100644 --- a/src/compositor/wayland_wrapper/qwltouch_p.h +++ b/src/compositor/wayland_wrapper/qwltouch_p.h @@ -87,7 +87,7 @@ public: if (!mouseFocus || !mouseFocus->surface()) return; - m_focusResource = resourceMap().value(mouseFocus->surface()->client()->client()); + m_focusResource = resourceMap().value(mouseFocus->surface()->waylandClient()); } private: void resetFocusState(); diff --git a/src/compositor/wayland_wrapper/wayland_wrapper.pri b/src/compositor/wayland_wrapper/wayland_wrapper.pri index 2bc732565..cf7194fe6 100644 --- a/src/compositor/wayland_wrapper/wayland_wrapper.pri +++ b/src/compositor/wayland_wrapper/wayland_wrapper.pri @@ -18,7 +18,6 @@ HEADERS += \ wayland_wrapper/qwloutput_p.h \ wayland_wrapper/qwlpointer_p.h \ wayland_wrapper/qwlregion_p.h \ - wayland_wrapper/qwlsurface_p.h \ wayland_wrapper/qwlsurfacebuffer_p.h \ wayland_wrapper/qwltouch_p.h \ ../shared/qwaylandxkb.h \ @@ -37,7 +36,6 @@ SOURCES += \ wayland_wrapper/qwloutput.cpp \ wayland_wrapper/qwlpointer.cpp \ wayland_wrapper/qwlregion.cpp \ - wayland_wrapper/qwlsurface.cpp \ wayland_wrapper/qwlsurfacebuffer.cpp \ wayland_wrapper/qwltouch.cpp \ ../shared/qwaylandxkb.cpp \ diff --git a/src/hardwareintegration/compositor/wayland-egl/waylandeglclientbufferintegration.cpp b/src/hardwareintegration/compositor/wayland-egl/waylandeglclientbufferintegration.cpp index d22b2db04..000e99898 100644 --- a/src/hardwareintegration/compositor/wayland-egl/waylandeglclientbufferintegration.cpp +++ b/src/hardwareintegration/compositor/wayland-egl/waylandeglclientbufferintegration.cpp @@ -37,7 +37,6 @@ #include "waylandeglclientbufferintegration.h" #include -#include #include #include #include -- cgit v1.2.3