diff options
-rw-r--r-- | src/compositor/extensions/extensions.pri | 7 | ||||
-rw-r--r-- | src/compositor/extensions/qwaylandiviapplication.cpp | 150 | ||||
-rw-r--r-- | src/compositor/extensions/qwaylandiviapplication.h | 71 | ||||
-rw-r--r-- | src/compositor/extensions/qwaylandiviapplication_p.h | 79 | ||||
-rw-r--r-- | src/compositor/extensions/qwaylandivisurface.cpp | 191 | ||||
-rw-r--r-- | src/compositor/extensions/qwaylandivisurface.h | 89 | ||||
-rw-r--r-- | src/compositor/extensions/qwaylandivisurface_p.h | 84 | ||||
-rw-r--r-- | tests/auto/compositor/compositor/compositor.pro | 1 | ||||
-rw-r--r-- | tests/auto/compositor/compositor/mockclient.cpp | 29 | ||||
-rw-r--r-- | tests/auto/compositor/compositor/mockclient.h | 9 | ||||
-rw-r--r-- | tests/auto/compositor/compositor/tst_compositor.cpp | 154 |
11 files changed, 863 insertions, 1 deletions
diff --git a/src/compositor/extensions/extensions.pri b/src/compositor/extensions/extensions.pri index e139d9e8c..eda13476b 100644 --- a/src/compositor/extensions/extensions.pri +++ b/src/compositor/extensions/extensions.pri @@ -8,6 +8,7 @@ WAYLANDSERVERSOURCES += \ ../extensions/qt-windowmanager.xml \ ../3rdparty/protocol/text-input-unstable-v2.xml \ ../3rdparty/protocol/xdg-shell.xml \ + ../3rdparty/protocol/ivi-application.xml \ HEADERS += \ extensions/qwlextendedsurface_p.h \ @@ -26,6 +27,10 @@ HEADERS += \ extensions/qwaylandxdgshellv5.h \ extensions/qwaylandxdgshellv5_p.h \ extensions/qwaylandshellsurface.h \ + extensions/qwaylandiviapplication.h \ + extensions/qwaylandiviapplication_p.h \ + extensions/qwaylandivisurface.h \ + extensions/qwaylandivisurface_p.h \ SOURCES += \ extensions/qwlextendedsurface.cpp \ @@ -37,6 +42,8 @@ SOURCES += \ extensions/qwaylandtextinputmanager.cpp \ extensions/qwaylandqtwindowmanager.cpp \ extensions/qwaylandxdgshellv5.cpp \ + extensions/qwaylandiviapplication.cpp \ + extensions/qwaylandivisurface.cpp \ qtHaveModule(quick):contains(QT_CONFIG, opengl) { HEADERS += \ diff --git a/src/compositor/extensions/qwaylandiviapplication.cpp b/src/compositor/extensions/qwaylandiviapplication.cpp new file mode 100644 index 000000000..c3eea08d7 --- /dev/null +++ b/src/compositor/extensions/qwaylandiviapplication.cpp @@ -0,0 +1,150 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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 "qwaylandiviapplication.h" +#include "qwaylandiviapplication_p.h" + +#include <QtWaylandCompositor/QWaylandCompositor> +#include <QtWaylandCompositor/QWaylandSurface> +#include <QtWaylandCompositor/QWaylandIviSurface> +#include <QtWaylandCompositor/QWaylandResource> + +QT_BEGIN_NAMESPACE + +/*! + * Constructs a QWaylandIviApplication object. + */ +QWaylandIviApplication::QWaylandIviApplication() + : QWaylandCompositorExtensionTemplate<QWaylandIviApplication>(*new QWaylandIviApplicationPrivate()) +{ +} + +/*! + * Constructs a QWaylandIviApplication object for the provided \a compositor. + */ +QWaylandIviApplication::QWaylandIviApplication(QWaylandCompositor *compositor) + : QWaylandCompositorExtensionTemplate<QWaylandIviApplication>(compositor, *new QWaylandIviApplicationPrivate()) +{ +} + +/*! + * Initializes the shell extension. + */ +void QWaylandIviApplication::initialize() +{ + Q_D(QWaylandIviApplication); + QWaylandCompositorExtensionTemplate::initialize(); + + QWaylandCompositor *compositor = static_cast<QWaylandCompositor *>(extensionContainer()); + if (!compositor) { + qWarning() << "Failed to find QWaylandCompositor when initializing QWaylandIviApplication"; + return; + } + + d->init(compositor->display(), 1); +} + +/*! + * Returns the Wayland interface for the QWaylandIviApplication. + */ +const struct wl_interface *QWaylandIviApplication::interface() +{ + return QWaylandIviApplicationPrivate::interface(); +} + +QByteArray QWaylandIviApplication::interfaceName() +{ + return QWaylandIviApplicationPrivate::interfaceName(); +} + +/*! + * \fn void QWaylandWlShell::iviSurfaceRequested(QWaylandSurface *surface, uint iviId, const QWaylandResource &resource) + * + * This signal is emitted when the client has requested an \c ivi_surface to be associated + * with \a surface, which is identified by \a id. The handler for this signal is + * expected to create the ivi surface and initialize it within the scope of the + * signal emission. If no ivi surface is created, a default one will be created instead. + */ + +/*! + * \fn void QtWaylandCompositor::IviApplication::iviSurfaceCreated(QWaylandIviSurface *iviSurface) + * + * This signal is emitted when an IviSurface has been created. + */ + +QWaylandIviApplicationPrivate::QWaylandIviApplicationPrivate() + : QWaylandCompositorExtensionPrivate() + , ivi_application() +{ +} + +void QWaylandIviApplicationPrivate::unregisterIviSurface(QWaylandIviSurface *iviSurface) +{ + m_iviSurfaces.remove(iviSurface->iviId()); +} + +void QWaylandIviApplicationPrivate::ivi_application_surface_create(QtWaylandServer::ivi_application::Resource *resource, + uint32_t ivi_id, wl_resource *surfaceResource, uint32_t id) +{ + Q_Q(QWaylandIviApplication); + QWaylandSurface *surface = QWaylandSurface::fromResource(surfaceResource); + + if (m_iviSurfaces.contains(ivi_id)) { + wl_resource_post_error(resource->handle, IVI_APPLICATION_ERROR_IVI_ID, + "Given ivi_id, %d, is already assigned to wl_surface@%d", ivi_id, + wl_resource_get_id(m_iviSurfaces[ivi_id]->surface()->resource())); + return; + } + + if (!surface->setRole(QWaylandIviSurface::role(), resource->handle, IVI_APPLICATION_ERROR_ROLE)) + return; + + QWaylandResource iviSurfaceResource(wl_resource_create(resource->client(), &ivi_surface_interface, + wl_resource_get_version(resource->handle), id)); + + emit q->iviSurfaceRequested(surface, ivi_id, iviSurfaceResource); + + QWaylandIviSurface *iviSurface = QWaylandIviSurface::fromResource(iviSurfaceResource.resource()); + + if (!iviSurface) + iviSurface = new QWaylandIviSurface(q, surface, ivi_id, iviSurfaceResource); + + m_iviSurfaces.insert(ivi_id, iviSurface); + + emit q->iviSurfaceCreated(iviSurface); +} + +QT_END_NAMESPACE diff --git a/src/compositor/extensions/qwaylandiviapplication.h b/src/compositor/extensions/qwaylandiviapplication.h new file mode 100644 index 000000000..a3e057a86 --- /dev/null +++ b/src/compositor/extensions/qwaylandiviapplication.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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 QWAYLANDIVIAPPLICATION_H +#define QWAYLANDIVIAPPLICATION_H + +#include <QtWaylandCompositor/QWaylandCompositorExtension> +#include <QtCore/QSize> + +class QWaylandIviSurface; +class QWaylandSurface; +class QWaylandResource; +class QWaylandIviApplicationPrivate; + +QT_BEGIN_NAMESPACE + +class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandIviApplication : public QWaylandCompositorExtensionTemplate<QWaylandIviApplication> +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QWaylandIviApplication) + +public: + QWaylandIviApplication(); + QWaylandIviApplication(QWaylandCompositor *compositor); + + void initialize() Q_DECL_OVERRIDE; + + static const struct wl_interface *interface(); + static QByteArray interfaceName(); + +Q_SIGNALS: + void iviSurfaceRequested(QWaylandSurface *surface, uint iviId, const QWaylandResource &resource); + void iviSurfaceCreated(QWaylandIviSurface *iviSurface); +}; + +QT_END_NAMESPACE + +#endif // QWAYLANDIVIAPPLICATION_H diff --git a/src/compositor/extensions/qwaylandiviapplication_p.h b/src/compositor/extensions/qwaylandiviapplication_p.h new file mode 100644 index 000000000..ea211a84a --- /dev/null +++ b/src/compositor/extensions/qwaylandiviapplication_p.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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 QWAYLANDIVIAPPLICATION_P_H +#define QWAYLANDIVIAPPLICATION_P_H + +#include <QtWaylandCompositor/private/qwaylandcompositorextension_p.h> +#include <QtWaylandCompositor/private/qwayland-server-ivi-application.h> + +#include <QtWaylandCompositor/QWaylandIviApplication> + +#include <QHash> + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +QT_BEGIN_NAMESPACE + +class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandIviApplicationPrivate + : public QWaylandCompositorExtensionPrivate + , public QtWaylandServer::ivi_application +{ + Q_DECLARE_PUBLIC(QWaylandIviApplication) + +public: + QWaylandIviApplicationPrivate(); + static QWaylandIviApplicationPrivate *get(QWaylandIviApplication *iviApplication) { return iviApplication->d_func(); } + void unregisterIviSurface(QWaylandIviSurface *iviSurface); + + QHash<uint, QWaylandIviSurface*> m_iviSurfaces; + +protected: + void ivi_application_surface_create(Resource *resource, uint32_t ivi_id, wl_resource *surface, uint32_t id) Q_DECL_OVERRIDE; +}; + +QT_END_NAMESPACE + +#endif // QWAYLANDIVIAPPLICATION_P_H diff --git a/src/compositor/extensions/qwaylandivisurface.cpp b/src/compositor/extensions/qwaylandivisurface.cpp new file mode 100644 index 000000000..2de407e11 --- /dev/null +++ b/src/compositor/extensions/qwaylandivisurface.cpp @@ -0,0 +1,191 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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 "qwaylandivisurface.h" +#include "qwaylandivisurface_p.h" +#include "qwaylandiviapplication_p.h" + +#include <QtWaylandCompositor/QWaylandResource> + +QT_BEGIN_NAMESPACE + +QWaylandSurfaceRole QWaylandIviSurfacePrivate::s_role("ivi_surface"); + +/*! + * \class QWaylandIviSurface + * \inmodule QtWaylandCompositor + * \preliminary + * \brief The QWaylandIviSurface class provides a simple way to identify and resize a surface. + * + * This class is part of the QWaylandIviApplication extension and provides a way to + * extend the functionality of an existing QWaylandSurface with features a way to + * resize and identify it. + * + * It corresponds to the Wayland interface ivi_surface. + */ + +/*! + * Constructs a QWaylandIviSurface for \a surface and initializes it with the + * given \a application, \a surface, \a iviId, and resource \a res. + */ +QWaylandIviSurface::QWaylandIviSurface(QWaylandIviApplication *application, QWaylandSurface *surface, uint iviId, const QWaylandResource &resource) + : QWaylandShellSurfaceTemplate<QWaylandIviSurface>(*new QWaylandIviSurfacePrivate()) +{ + initialize(application, surface, iviId, resource); +} + +/*! + * Initializes the QWaylandIviSurface, associating it with the given \a iviApplication, \a surface, + * \a iviId, and \a resource. + */ +void QWaylandIviSurface::initialize(QWaylandIviApplication *iviApplication, QWaylandSurface *surface, uint iviId, const QWaylandResource &resource) +{ + Q_D(QWaylandIviSurface); + + d->m_iviApplication = iviApplication; + d->m_surface = surface; + d->m_iviId = iviId; + + d->init(resource.resource()); + setExtensionContainer(surface); + + emit surfaceChanged(); + emit iviIdChanged(); + + QWaylandCompositorExtension::initialize(); +} + +/*! + * \property QWaylandIviSurface::surface + * + * This property holds the surface associated with this QWaylandIviSurface. + */ +QWaylandSurface *QWaylandIviSurface::surface() const +{ + Q_D(const QWaylandIviSurface); + return d->m_surface; +} + +/*! + * \property QWaylandClient::iviId + * + * This property holds the ivi id of this QWaylandIviSurface. + */ +uint QWaylandIviSurface::iviId() const +{ + Q_D(const QWaylandIviSurface); + return d->m_iviId; +} + +/*! + * Returns the Wayland interface for the QWaylandIviSurface. + */ +const struct wl_interface *QWaylandIviSurface::interface() +{ + return QWaylandIviSurfacePrivate::interface(); +} + +QByteArray QWaylandIviSurface::interfaceName() +{ + return QWaylandIviSurfacePrivate::interfaceName(); +} + +/*! + * Returns the surface role for the QWaylandIviSurface. + */ +QWaylandSurfaceRole *QWaylandIviSurface::role() +{ + return &QWaylandIviSurfacePrivate::s_role; +} + +/*! + * Returns the QWaylandIviSurface corresponding to the \a resource. + */ +QWaylandIviSurface *QWaylandIviSurface::fromResource(wl_resource *resource) +{ + auto iviSurfaceResource = QWaylandIviSurfacePrivate::Resource::fromResource(resource); + if (!iviSurfaceResource) + return nullptr; + return static_cast<QWaylandIviSurfacePrivate *>(iviSurfaceResource->ivi_surface_object)->q_func(); +} + +/*! + * Sends a configure event to the client, telling it to resize the surface to the given \a size. + */ +void QWaylandIviSurface::sendConfigure(const QSize &size) +{ + Q_D(QWaylandIviSurface); + d->send_configure(size.width(), size.height()); +} + +#ifdef QT_WAYLAND_COMPOSITOR_QUICK +QWaylandQuickShellIntegration *QWaylandIviSurface::createIntegration(QWaylandQuickShellSurfaceItem *item) +{ + return nullptr; // TODO +} +#endif + +/*! + * \internal + */ +void QWaylandIviSurface::initialize() +{ + QWaylandShellSurfaceTemplate::initialize(); +} + +QWaylandIviSurfacePrivate::QWaylandIviSurfacePrivate() + : QWaylandCompositorExtensionPrivate() + , ivi_surface() + , m_iviApplication(nullptr) + , m_surface(nullptr) + , m_iviId(UINT_MAX) +{ +} + +void QWaylandIviSurfacePrivate::ivi_surface_destroy_resource(QtWaylandServer::ivi_surface::Resource *resource) +{ + Q_UNUSED(resource); + Q_Q(QWaylandIviSurface); + QWaylandIviApplicationPrivate::get(m_iviApplication)->unregisterIviSurface(q); + delete q; +} + +void QWaylandIviSurfacePrivate::ivi_surface_destroy(QtWaylandServer::ivi_surface::Resource *resource) +{ + wl_resource_destroy(resource->handle); +} + +QT_END_NAMESPACE diff --git a/src/compositor/extensions/qwaylandivisurface.h b/src/compositor/extensions/qwaylandivisurface.h new file mode 100644 index 000000000..37c37c0f3 --- /dev/null +++ b/src/compositor/extensions/qwaylandivisurface.h @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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 QWAYLANDIVISURFACE_H +#define QWAYLANDIVISURFACE_H + +#include <QtWaylandCompositor/QWaylandShellSurface> + +class QWaylandIviSurfacePrivate; +class QWaylandSurface; +class QWaylandIviApplication; +class QWaylandSurfaceRole; +class QWaylandResource; +class wl_resource; + +QT_BEGIN_NAMESPACE + +class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandIviSurface : public QWaylandShellSurfaceTemplate<QWaylandIviSurface> +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QWaylandIviSurface) + Q_PROPERTY(QWaylandSurface *surface READ surface NOTIFY surfaceChanged) + Q_PROPERTY(uint iviId READ iviId NOTIFY iviIdChanged) + +public: + QWaylandIviSurface(); + QWaylandIviSurface(QWaylandIviApplication *application, QWaylandSurface *surface, uint iviId, const QWaylandResource &resource); + + Q_INVOKABLE void initialize(QWaylandIviApplication *iviApplication, QWaylandSurface *surface, + uint iviId, const QWaylandResource &resource); + + QWaylandSurface *surface() const; + uint iviId() const; + + static const struct wl_interface *interface(); + static QByteArray interfaceName(); + static QWaylandSurfaceRole *role(); + static QWaylandIviSurface *fromResource(::wl_resource *resource); + + Q_INVOKABLE void sendConfigure(const QSize &size); + +#ifdef QT_WAYLAND_COMPOSITOR_QUICK + QWaylandQuickShellIntegration *createIntegration(QWaylandQuickShellSurfaceItem *item) Q_DECL_OVERRIDE; +#endif + +Q_SIGNALS: + void surfaceChanged(); + void iviIdChanged(); + +private: + void initialize(); +}; + +QT_END_NAMESPACE + +#endif // QWAYLANDIVISURFACE_H diff --git a/src/compositor/extensions/qwaylandivisurface_p.h b/src/compositor/extensions/qwaylandivisurface_p.h new file mode 100644 index 000000000..db237721d --- /dev/null +++ b/src/compositor/extensions/qwaylandivisurface_p.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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 QWAYLANDIVISURFACE_P_H +#define QWAYLANDIVISURFACE_P_H + +#include <QtWaylandCompositor/private/qwaylandcompositorextension_p.h> +#include <QtWaylandCompositor/private/qwayland-server-ivi-application.h> + +#include <QtWaylandCompositor/QWaylandIviSurface> + +#include <QtWaylandCompositor/QWaylandSurfaceRole> + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +QT_BEGIN_NAMESPACE + +class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandIviSurfacePrivate + : public QWaylandCompositorExtensionPrivate + , public QtWaylandServer::ivi_surface +{ + Q_DECLARE_PUBLIC(QWaylandIviSurface) + +public: + QWaylandIviSurfacePrivate(); + static QWaylandIviSurfacePrivate *get(QWaylandIviSurface *iviSurface) { return iviSurface->d_func(); } + +protected: + void ivi_surface_destroy_resource(Resource *resource) Q_DECL_OVERRIDE; + void ivi_surface_destroy(Resource *resource) Q_DECL_OVERRIDE; + +private: + QWaylandIviApplication *m_iviApplication; + QWaylandSurface *m_surface; + uint m_iviId; + + static QWaylandSurfaceRole s_role; +}; + +QT_END_NAMESPACE + +#endif // QWAYLANDIVISURFACE_P_H diff --git a/tests/auto/compositor/compositor/compositor.pro b/tests/auto/compositor/compositor/compositor.pro index a3748697d..1d4456f6f 100644 --- a/tests/auto/compositor/compositor/compositor.pro +++ b/tests/auto/compositor/compositor/compositor.pro @@ -23,6 +23,7 @@ config_xkbcommon { WAYLANDCLIENTSOURCES += \ ../../../../src/3rdparty/protocol/xdg-shell.xml \ + ../../../../src/3rdparty/protocol/ivi-application.xml \ SOURCES += \ tst_compositor.cpp \ diff --git a/tests/auto/compositor/compositor/mockclient.cpp b/tests/auto/compositor/compositor/mockclient.cpp index 9b6d327a9..f2fbc5de2 100644 --- a/tests/auto/compositor/compositor/mockclient.cpp +++ b/tests/auto/compositor/compositor/mockclient.cpp @@ -51,6 +51,9 @@ MockClient::MockClient() , registry(0) , wlshell(0) , xdgShell(nullptr) + , iviApplication(nullptr) + , error(0 /* means no error according to spec */) + , protocolError({0, 0, nullptr}) { if (!display) qFatal("MockClient(): wl_display_connect() failed"); @@ -117,12 +120,28 @@ void MockClient::outputScale(void *, wl_output *, int) void MockClient::readEvents() { + if (error) + return; wl_display_dispatch(display); } void MockClient::flushDisplay() { - wl_display_dispatch_pending(display); + if (error) + return; + + if (wl_display_prepare_read(display) == 0) { + wl_display_read_events(display); + } + + if (wl_display_dispatch_pending(display) < 0) { + error = wl_display_get_error(display); + if (error == EPROTO) { + protocolError.code = wl_display_get_protocol_error(display, &protocolError.interface, &protocolError.id); + return; + } + } + wl_display_flush(display); } @@ -146,6 +165,8 @@ void MockClient::handleGlobal(uint32_t id, const QByteArray &interface) wlshell = static_cast<wl_shell *>(wl_registry_bind(registry, id, &wl_shell_interface, 1)); } else if (interface == "xdg_shell") { xdgShell = static_cast<xdg_shell *>(wl_registry_bind(registry, id, &xdg_shell_interface, 1)); + } else if (interface == "ivi_application") { + iviApplication = static_cast<ivi_application *>(wl_registry_bind(registry, id, &ivi_application_interface, 1)); } else if (interface == "wl_seat") { wl_seat *s = static_cast<wl_seat *>(wl_registry_bind(registry, id, &wl_seat_interface, 1)); m_seats << new MockSeat(s); @@ -170,6 +191,12 @@ xdg_surface *MockClient::createXdgSurface(wl_surface *surface) return xdg_shell_get_xdg_surface(xdgShell, surface); } +ivi_surface *MockClient::createIviSurface(wl_surface *surface, uint iviId) +{ + flushDisplay(); + return ivi_application_surface_create(iviApplication, iviId, surface); +} + ShmBuffer::ShmBuffer(const QSize &size, wl_shm *shm) : handle(0) { diff --git a/tests/auto/compositor/compositor/mockclient.h b/tests/auto/compositor/compositor/mockclient.h index 33ada638a..ed9319af8 100644 --- a/tests/auto/compositor/compositor/mockclient.h +++ b/tests/auto/compositor/compositor/mockclient.h @@ -28,6 +28,7 @@ #include <wayland-client.h> #include <wayland-xdg-shell-client-protocol.h> +#include <wayland-ivi-application-client-protocol.h> #include <QObject> #include <QImage> @@ -58,6 +59,7 @@ public: wl_surface *createSurface(); wl_shell_surface *createShellSurface(wl_surface *surface); xdg_surface *createXdgSurface(wl_surface *surface); + ivi_surface *createIviSurface(wl_surface *surface, uint iviId); wl_display *display; wl_compositor *compositor; @@ -66,12 +68,19 @@ public: wl_registry *registry; wl_shell *wlshell; xdg_shell *xdgShell; + ivi_application *iviApplication; QList<MockSeat *> m_seats; QRect geometry; int fd; + int error; + struct { + uint id; + uint code; + const wl_interface *interface; + } protocolError; private slots: void readEvents(); diff --git a/tests/auto/compositor/compositor/tst_compositor.cpp b/tests/auto/compositor/compositor/tst_compositor.cpp index d6c72b34c..3052b7b45 100644 --- a/tests/auto/compositor/compositor/tst_compositor.cpp +++ b/tests/auto/compositor/compositor/tst_compositor.cpp @@ -36,9 +36,12 @@ #include "qwaylandseat.h" #include <QtWaylandCompositor/QWaylandXdgShellV5> +#include <QtWaylandCompositor/QWaylandIviApplication> +#include <QtWaylandCompositor/QWaylandIviSurface> #include <QtWaylandCompositor/QWaylandSurface> #include <QtWaylandCompositor/QWaylandResource> #include <qwayland-xdg-shell.h> +#include <qwayland-ivi-application.h> #include <QtTest/QtTest> @@ -57,11 +60,18 @@ private slots: void geometry(); void mapSurface(); void frameCallback(); + void advertisesXdgShellSupport(); void createsXdgSurfaces(); void reportsXdgSurfaceWindowGeometry(); void setsXdgAppId(); void sendsXdgConfigure(); + + void advertisesIviApplicationSupport(); + void createsIviSurfaces(); + void emitsErrorOnSameIviId(); + void sendsIviConfigure(); + void destroysIviSurfaces(); }; void tst_WaylandCompositor::init() { @@ -572,5 +582,149 @@ void tst_WaylandCompositor::sendsXdgConfigure() QTRY_VERIFY(!xdgSurface->resizing()); } +class IviTestCompositor: public TestCompositor { + Q_OBJECT +public: + IviTestCompositor() : iviApplication(this) {} + QWaylandIviApplication iviApplication; +}; + +void tst_WaylandCompositor::advertisesIviApplicationSupport() +{ + IviTestCompositor compositor; + compositor.create(); + + MockClient client; + QTRY_VERIFY(&client.iviApplication); +} + +void tst_WaylandCompositor::createsIviSurfaces() +{ + IviTestCompositor compositor; + compositor.create(); + + MockClient client; + QTRY_VERIFY(&client.iviApplication); + + QSignalSpy iviSurfaceCreatedSpy(&compositor.iviApplication, &QWaylandIviApplication::iviSurfaceRequested); + QWaylandIviSurface *iviSurface = nullptr; + QObject::connect(&compositor.iviApplication, &QWaylandIviApplication::iviSurfaceCreated, [&](QWaylandIviSurface *s) { + iviSurface = s; + }); + + wl_surface *surface = client.createSurface(); + client.createIviSurface(surface, 123); + QTRY_COMPARE(iviSurfaceCreatedSpy.count(), 1); + QTRY_VERIFY(iviSurface); + QTRY_VERIFY(iviSurface->surface()); + QTRY_COMPARE(iviSurface->iviId(), 123u); +} + +void tst_WaylandCompositor::emitsErrorOnSameIviId() +{ + IviTestCompositor compositor; + compositor.create(); + + { + MockClient firstClient; + QTRY_VERIFY(&firstClient.iviApplication); + + QWaylandIviSurface *firstIviSurface = nullptr; + QObject::connect(&compositor.iviApplication, &QWaylandIviApplication::iviSurfaceCreated, [&](QWaylandIviSurface *s) { + firstIviSurface = s; + }); + + firstClient.createIviSurface(firstClient.createSurface(), 123); + QTRY_VERIFY(firstIviSurface); + QTRY_COMPARE(firstIviSurface->iviId(), 123u); + + { + MockClient secondClient; + QTRY_VERIFY(&secondClient.iviApplication); + QTRY_COMPARE(compositor.clients().count(), 2); + + secondClient.createIviSurface(secondClient.createSurface(), 123); + compositor.flushClients(); + + QTRY_COMPARE(secondClient.error, EPROTO); + QTRY_COMPARE(secondClient.protocolError.interface, &ivi_application_interface); + QTRY_COMPARE(static_cast<ivi_application_error>(secondClient.protocolError.code), IVI_APPLICATION_ERROR_IVI_ID); + QTRY_COMPARE(compositor.clients().count(), 1); + } + } + + // The other clients have passed out of scope and have been destroyed, + // it should now be ok to create new application with the same id + MockClient thirdClient; + QTRY_VERIFY(&thirdClient.iviApplication); + + QWaylandIviSurface *thirdIviSurface = nullptr; + QObject::connect(&compositor.iviApplication, &QWaylandIviApplication::iviSurfaceCreated, [&](QWaylandIviSurface *s) { + thirdIviSurface = s; + }); + thirdClient.createIviSurface(thirdClient.createSurface(), 123); + compositor.flushClients(); + + QTRY_VERIFY(thirdIviSurface); + QTRY_COMPARE(thirdIviSurface->iviId(), 123u); + QTRY_COMPARE(thirdClient.error, 0); +} + +void tst_WaylandCompositor::sendsIviConfigure() +{ + class MockIviSurface : public QtWayland::ivi_surface + { + public: + MockIviSurface(::ivi_surface *iviSurface) : QtWayland::ivi_surface(iviSurface) {} + void ivi_surface_configure(int32_t width, int32_t height) Q_DECL_OVERRIDE + { + configureSize = QSize(width, height); + } + QSize configureSize; + }; + + IviTestCompositor compositor; + compositor.create(); + + MockClient client; + QTRY_VERIFY(&client.iviApplication); + + QWaylandIviSurface *iviSurface = nullptr; + QObject::connect(&compositor.iviApplication, &QWaylandIviApplication::iviSurfaceCreated, [&](QWaylandIviSurface *s) { + iviSurface = s; + }); + + wl_surface *surface = client.createSurface(); + ivi_surface *clientIviSurface = client.createIviSurface(surface, 123); + MockIviSurface mockIviSurface(clientIviSurface); + + QTRY_VERIFY(iviSurface); + iviSurface->sendConfigure(QSize(800, 600)); + compositor.flushClients(); + + QTRY_COMPARE(mockIviSurface.configureSize, QSize(800, 600)); +} + +void tst_WaylandCompositor::destroysIviSurfaces() +{ + IviTestCompositor compositor; + compositor.create(); + + MockClient client; + QTRY_VERIFY(&client.iviApplication); + + QWaylandIviSurface *iviSurface = nullptr; + QObject::connect(&compositor.iviApplication, &QWaylandIviApplication::iviSurfaceCreated, [&](QWaylandIviSurface *s) { + iviSurface = s; + }); + + QtWayland::ivi_surface mockIviSurface(client.createIviSurface(client.createSurface(), 123)); + QTRY_VERIFY(iviSurface); + + QSignalSpy destroySpy(iviSurface, SIGNAL(destroyed())); + mockIviSurface.destroy(); + QTRY_VERIFY(destroySpy.count() == 1); +} + #include <tst_compositor.moc> QTEST_MAIN(tst_WaylandCompositor); |