summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAndy Nichols <andy.nichols@digia.com>2013-09-09 13:58:40 +0200
committerAndy Nichols <andy.nichols@digia.com>2013-09-09 13:58:40 +0200
commit82b7f6faed8961acc07ff6ee56236d001000f149 (patch)
tree75d9acd9aba89b927021196d7be8922ad83bece1 /tests
parentaa0584194b5fe3dd01830dbaed231dabfa6d455d (diff)
parent330c429991ef1c32ffdd51cdc8627ef1b71604b3 (diff)
Merge remote-tracking branch 'origin/stable' into dev
Conflicts: qtwayland.pro src/plugins/platforms/wayland_common/qwaylandshellsurface.cpp src/plugins/platforms/wayland_common/qwaylandshellsurface.h src/plugins/platforms/wayland_common/qwaylandwindow.cpp src/plugins/platforms/wayland_common/qwaylandwindow.h Change-Id: Ifa9bc553d826b893b054bbaef5ea3fc3013de3df
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/client/client.pro6
-rw-r--r--tests/auto/client/mockcompositor.cpp30
-rw-r--r--tests/auto/client/mockcompositor.h16
-rw-r--r--tests/auto/client/mockinput.cpp224
-rw-r--r--tests/auto/client/mockinput.h119
-rw-r--r--tests/auto/client/mocksurface.cpp131
-rw-r--r--tests/auto/client/mocksurface.h27
7 files changed, 332 insertions, 221 deletions
diff --git a/tests/auto/client/client.pro b/tests/auto/client/client.pro
index a92aa88b7..448f7d516 100644
--- a/tests/auto/client/client.pro
+++ b/tests/auto/client/client.pro
@@ -10,6 +10,9 @@ QT += core-private gui-private
LIBS += -lwayland-client -lwayland-server
}
+WAYLANDSERVERSOURCES += \
+ ../../../src/3rdparty/protocol/wayland.xml
+
SOURCES += tst_client.cpp \
mockcompositor.cpp \
mockinput.cpp \
@@ -17,4 +20,5 @@ SOURCES += tst_client.cpp \
mocksurface.cpp \
mockoutput.cpp
HEADERS += mockcompositor.h \
- mocksurface.h
+ mockinput.h \
+ mocksurface.h \
diff --git a/tests/auto/client/mockcompositor.cpp b/tests/auto/client/mockcompositor.cpp
index d25f90565..e51f3ed57 100644
--- a/tests/auto/client/mockcompositor.cpp
+++ b/tests/auto/client/mockcompositor.cpp
@@ -40,8 +40,10 @@
****************************************************************************/
#include "mockcompositor.h"
+#include "mockinput.h"
#include "mocksurface.h"
+#include <stdio.h>
MockCompositor::MockCompositor()
: m_alive(true)
, m_ready(false)
@@ -195,34 +197,34 @@ Compositor::Compositor()
{
wl_list_init(&m_outputResources);
- wl_display_add_socket(m_display, 0);
-
- wl_seat_init(&m_seat);
- wl_pointer_init(&m_pointer);
- wl_seat_set_pointer(&m_seat, &m_pointer);
- wl_keyboard_init(&m_keyboard);
- wl_seat_set_keyboard(&m_seat, &m_keyboard);
+ if (wl_display_add_socket(m_display, 0)) {
+ fprintf(stderr, "Fatal: Failed to open server socket\n");
+ exit(EXIT_FAILURE);
+ }
wl_display_add_global(m_display, &wl_compositor_interface, this, bindCompositor);
- wl_display_add_global(m_display, &wl_seat_interface, this, bindSeat);
- wl_display_add_global(m_display, &wl_output_interface, this, bindOutput);
- wl_display_add_global(m_display, &wl_shell_interface, this, bindShell);
wl_display_init_shm(m_display);
+ m_seat.reset(new Seat(this, m_display));
+ m_pointer = m_seat->pointer();
+ m_keyboard = m_seat->keyboard();
+
+ wl_display_add_global(m_display, &wl_output_interface, this, bindOutput);
+ wl_display_add_global(m_display, &wl_shell_interface, this, bindShell);
+
m_loop = wl_display_get_event_loop(m_display);
m_fd = wl_event_loop_get_fd(m_loop);
}
Compositor::~Compositor()
{
- wl_pointer_release(&m_pointer);
- wl_keyboard_release(&m_keyboard);
wl_display_destroy(m_display);
}
void Compositor::dispatchEvents(int timeout)
{
+ wl_display_flush_clients(m_display);
wl_event_loop_dispatch(m_loop, timeout);
}
@@ -285,6 +287,10 @@ void Compositor::addSurface(Surface *surface)
void Compositor::removeSurface(Surface *surface)
{
m_surfaces.remove(m_surfaces.indexOf(surface));
+ if (m_keyboard->focus() == surface)
+ m_keyboard->setFocus(0);
+ if (m_pointer->focus() == surface)
+ m_pointer->setFocus(0, QPoint());
}
}
diff --git a/tests/auto/client/mockcompositor.h b/tests/auto/client/mockcompositor.h
index 6bfd5d6bd..7f3e22683 100644
--- a/tests/auto/client/mockcompositor.h
+++ b/tests/auto/client/mockcompositor.h
@@ -58,6 +58,9 @@ namespace Impl {
typedef void (**Implementation)(void);
+class Keyboard;
+class Pointer;
+class Seat;
class Surface;
class Compositor
@@ -87,16 +90,9 @@ public:
private:
static void bindCompositor(wl_client *client, void *data, uint32_t version, uint32_t id);
- static void bindSeat(wl_client *client, void *data, uint32_t version, uint32_t id);
static void bindOutput(wl_client *client, void *data, uint32_t version, uint32_t id);
static void bindShell(wl_client *client, void *data, uint32_t version, uint32_t id);
- static void get_pointer(wl_client *client, wl_resource *resource, uint32_t id);
- static void get_keyboard(wl_client *client, wl_resource *resource, uint32_t id);
- static void get_touch(wl_client *client, wl_resource *resource, uint32_t id);
-
- static void destroyInputResource(wl_resource *resource);
-
void initShm();
void sendOutputGeometry(wl_resource *resource);
@@ -112,9 +108,9 @@ private:
wl_list m_outputResources;
uint32_t m_time;
- wl_seat m_seat;
- wl_pointer m_pointer;
- wl_keyboard m_keyboard;
+ QScopedPointer<Seat> m_seat;
+ Pointer *m_pointer;
+ Keyboard *m_keyboard;
QVector<Surface *> m_surfaces;
};
diff --git a/tests/auto/client/mockinput.cpp b/tests/auto/client/mockinput.cpp
index 50c8b764c..40b01317f 100644
--- a/tests/auto/client/mockinput.cpp
+++ b/tests/auto/client/mockinput.cpp
@@ -40,164 +40,174 @@
****************************************************************************/
#include "mockcompositor.h"
+#include "mockinput.h"
#include "mocksurface.h"
namespace Impl {
-void Compositor::destroyInputResource(wl_resource *resource)
+static Surface *resolveSurface(const QVariant &v)
{
- Compositor *compositor = static_cast<Compositor *>(resource->data);
- wl_keyboard *keyboard = &compositor->m_keyboard;
- wl_pointer *pointer = &compositor->m_pointer;
+ QSharedPointer<MockSurface> mockSurface = v.value<QSharedPointer<MockSurface> >();
+ return mockSurface ? mockSurface->handle() : 0;
+}
- if (keyboard->focus_resource == resource)
- keyboard->focus_resource = 0;
- if (pointer->focus_resource == resource)
- pointer->focus_resource = 0;
+void Compositor::setKeyboardFocus(void *data, const QList<QVariant> &parameters)
+{
+ Compositor *compositor = static_cast<Compositor *>(data);
+ compositor->m_keyboard->setFocus(resolveSurface(parameters.first()));
+}
- wl_list_remove(&resource->link);
+void Compositor::sendMousePress(void *data, const QList<QVariant> &parameters)
+{
+ Compositor *compositor = static_cast<Compositor *>(data);
+ Surface *surface = resolveSurface(parameters.first());
+ if (!surface)
+ return;
- free(resource);
+ QPoint pos = parameters.last().toPoint();
+ compositor->m_pointer->setFocus(surface, pos);
+ compositor->m_pointer->sendMotion(pos);
+ compositor->m_pointer->sendButton(0x110, 1);
}
-static void destroyInputDevice(wl_resource *resource)
+void Compositor::sendMouseRelease(void *data, const QList<QVariant> &parameters)
{
- wl_list_remove(&resource->link);
- free(resource);
+ Compositor *compositor = static_cast<Compositor *>(data);
+ Surface *surface = resolveSurface(parameters.first());
+ if (!surface)
+ return;
+
+ compositor->m_pointer->sendButton(0x110, 0);
}
-void pointer_attach(wl_client *client,
- wl_resource *device_resource,
- uint32_t time,
- wl_resource *buffer_resource, int32_t x, int32_t y)
+void Compositor::sendKeyPress(void *data, const QList<QVariant> &parameters)
{
- Q_UNUSED(client);
- Q_UNUSED(device_resource);
- Q_UNUSED(time);
- Q_UNUSED(buffer_resource);
- Q_UNUSED(QPoint(x, y));
+ Compositor *compositor = static_cast<Compositor *>(data);
+ Surface *surface = resolveSurface(parameters.first());
+ if (!surface)
+ return;
+
+ compositor->m_keyboard->sendKey(parameters.last().toUInt() - 8, 1);
}
-void Compositor::get_pointer(wl_client *client,
- wl_resource *resource,
- uint32_t id)
+void Compositor::sendKeyRelease(void *data, const QList<QVariant> &parameters)
{
- static const struct wl_pointer_interface pointer_interface = {
- pointer_attach
- };
- Compositor *compositor = static_cast<Compositor *>(resource->data);
- wl_pointer *pointer = &compositor->m_pointer;
- wl_resource *clientResource = wl_client_add_object(client,
- &wl_pointer_interface,
- &pointer_interface,
- id,
- pointer);
- wl_list_insert(&pointer->resource_list, &clientResource->link);
- clientResource->destroy = destroyInputDevice;
+ Compositor *compositor = static_cast<Compositor *>(data);
+ Surface *surface = resolveSurface(parameters.first());
+ if (!surface)
+ return;
+
+ compositor->m_keyboard->sendKey(parameters.last().toUInt() - 8, 0);
}
-void Compositor::get_keyboard(wl_client *client,
- wl_resource *resource,
- uint32_t id)
+Seat::Seat(Compositor *compositor, struct ::wl_display *display)
+ : wl_seat(display)
+ , m_compositor(compositor)
+ , m_keyboard(new Keyboard(compositor))
+ , m_pointer(new Pointer(compositor))
{
- Compositor *compositor = static_cast<Compositor *>(resource->data);
- wl_keyboard *keyboard = &compositor->m_keyboard;
- wl_resource *clientResource = wl_client_add_object(client,
- &wl_keyboard_interface,
- 0,
- id,
- keyboard);
- wl_list_insert(&keyboard->resource_list, &clientResource->link);
- clientResource->destroy = destroyInputDevice;
}
-void Compositor::get_touch(wl_client *client,
- wl_resource *resource,
- uint32_t id)
+Seat::~Seat()
{
- Q_UNUSED(client);
- Q_UNUSED(resource);
- Q_UNUSED(id);
}
-void Compositor::bindSeat(wl_client *client, void *compositorData, uint32_t version, uint32_t id)
+void Seat::seat_bind_resource(Resource *resource)
{
- static const struct wl_seat_interface seatInterface = {
- get_pointer,
- get_keyboard,
- get_touch
- };
+ send_capabilities(resource->handle, capability_keyboard | capability_pointer);
+}
- Q_UNUSED(version);
- wl_resource *resource = wl_client_add_object(client, &wl_seat_interface, &seatInterface, id, compositorData);
- resource->destroy = destroyInputResource;
+void Seat::seat_get_keyboard(Resource *resource, uint32_t id)
+{
+ m_keyboard->add(resource->client(), id);
+}
- Compositor *compositor = static_cast<Compositor *>(compositorData);
- wl_list_insert(&compositor->m_seat.base_resource_list, &resource->link);
+void Seat::seat_get_pointer(Resource *resource, uint32_t id)
+{
+ m_pointer->add(resource->client(), id);
+}
- wl_seat_send_capabilities(resource, WL_SEAT_CAPABILITY_POINTER | WL_SEAT_CAPABILITY_KEYBOARD);
+Keyboard::Keyboard(Compositor *compositor)
+ : wl_keyboard()
+ , m_compositor(compositor)
+{
}
-static wl_surface *resolveSurface(const QVariant &v)
+Keyboard::~Keyboard()
{
- QSharedPointer<MockSurface> mockSurface = v.value<QSharedPointer<MockSurface> >();
- Surface *surface = mockSurface ? mockSurface->handle() : 0;
- return surface ? surface->handle() : 0;
}
-void Compositor::setKeyboardFocus(void *data, const QList<QVariant> &parameters)
+void Keyboard::setFocus(Surface *surface)
{
- Compositor *compositor = static_cast<Compositor *>(data);
- wl_keyboard_set_focus(&compositor->m_keyboard, resolveSurface(parameters.first()));
+ if (m_focusResource && m_focus != surface) {
+ uint32_t serial = m_compositor->nextSerial();
+ send_leave(m_focusResource->handle, serial, m_focus->resource()->handle);
+ }
+
+ Resource *resource = surface ? resourceMap().value(surface->resource()->client()) : 0;
+
+ if (resource && (m_focus != surface || m_focusResource != resource)) {
+ uint32_t serial = m_compositor->nextSerial();
+ send_modifiers(resource->handle, serial, 0, 0, 0, 0);
+ send_enter(resource->handle, serial, surface->resource()->handle, QByteArray());
+ }
+
+ m_focusResource = resource;
+ m_focus = surface;
}
-void Compositor::sendMousePress(void *data, const QList<QVariant> &parameters)
+void Keyboard::sendKey(uint32_t key, uint32_t state)
{
- Compositor *compositor = static_cast<Compositor *>(data);
- wl_surface *surface = resolveSurface(parameters.first());
- if (!surface)
- return;
+ if (m_focusResource) {
+ uint32_t serial = m_compositor->nextSerial();
+ send_key(m_focusResource->handle, serial, m_compositor->time(), key, state);
+ }
+}
- QPoint pos = parameters.last().toPoint();
- wl_pointer_set_focus(&compositor->m_pointer, surface,
- wl_fixed_from_int(pos.x()), wl_fixed_from_int(pos.y()));
- wl_pointer_send_motion(compositor->m_pointer.focus_resource, compositor->time(),
- wl_fixed_from_double(pos.x()), wl_fixed_from_double(pos.y()));
- wl_pointer_send_button(compositor->m_pointer.focus_resource,
- compositor->nextSerial(), compositor->time(), 0x110, 1);
+Pointer::Pointer(Compositor *compositor)
+ : wl_pointer()
+ , m_compositor(compositor)
+{
}
-void Compositor::sendMouseRelease(void *data, const QList<QVariant> &parameters)
+Pointer::~Pointer()
{
- Compositor *compositor = static_cast<Compositor *>(data);
- wl_surface *surface = resolveSurface(parameters.first());
- if (!surface)
- return;
- wl_pointer_send_button(compositor->m_pointer.focus_resource,
- compositor->nextSerial(), compositor->time(), 0x110, 0);
}
-void Compositor::sendKeyPress(void *data, const QList<QVariant> &parameters)
+void Pointer::setFocus(Surface *surface, const QPoint &pos)
{
- Compositor *compositor = static_cast<Compositor *>(data);
- wl_surface *surface = resolveSurface(parameters.first());
- if (!surface)
- return;
+ if (m_focusResource && m_focus != surface) {
+ uint32_t serial = m_compositor->nextSerial();
+ send_leave(m_focusResource->handle, serial, m_focus->resource()->handle);
+ }
+
+ Resource *resource = surface ? resourceMap().value(surface->resource()->client()) : 0;
- wl_keyboard_send_key(compositor->m_keyboard.focus_resource,
- compositor->nextSerial(), compositor->time(), parameters.last().toUInt() - 8, 1);
+ if (resource && (m_focus != surface || resource != m_focusResource)) {
+ uint32_t serial = m_compositor->nextSerial();
+ send_enter(resource->handle, serial, surface->resource()->handle,
+ wl_fixed_from_int(pos.x()), wl_fixed_from_int(pos.y()));
+ }
+
+ m_focusResource = resource;
+ m_focus = surface;
}
-void Compositor::sendKeyRelease(void *data, const QList<QVariant> &parameters)
+void Pointer::sendMotion(const QPoint &pos)
{
- Compositor *compositor = static_cast<Compositor *>(data);
- wl_surface *surface = resolveSurface(parameters.first());
- if (!surface)
- return;
+ if (m_focusResource)
+ send_motion(m_focusResource->handle, m_compositor->time(),
+ wl_fixed_from_int(pos.x()), wl_fixed_from_int(pos.y()));
+}
- wl_keyboard_send_key(compositor->m_keyboard.focus_resource,
- compositor->nextSerial(), compositor->time(), parameters.last().toUInt() - 8, 0);
+void Pointer::sendButton(uint32_t button, uint32_t state)
+{
+ if (m_focusResource) {
+ uint32_t serial = m_compositor->nextSerial();
+ send_button(m_focusResource->handle, serial, m_compositor->time(),
+ button, state);
+ }
}
}
diff --git a/tests/auto/client/mockinput.h b/tests/auto/client/mockinput.h
new file mode 100644
index 000000000..669bfaed6
--- /dev/null
+++ b/tests/auto/client/mockinput.h
@@ -0,0 +1,119 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2013 Klarälvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 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 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MOCKINPUT_H
+#define MOCKINPUT_H
+
+#include <qglobal.h>
+
+#include "qwayland-server-wayland.h"
+
+#include "mockcompositor.h"
+
+namespace Impl {
+
+class Keyboard;
+class Pointer;
+
+class Seat : public QtWaylandServer::wl_seat
+{
+public:
+ Seat(Compositor *compositor, struct ::wl_display *display);
+ ~Seat();
+
+ Compositor *compositor() const { return m_compositor; }
+
+ Keyboard *keyboard() const { return m_keyboard.data(); }
+ Pointer *pointer() const { return m_pointer.data(); }
+
+protected:
+ void seat_bind_resource(Resource *resource) Q_DECL_OVERRIDE;
+ void seat_get_keyboard(Resource *resource, uint32_t id) Q_DECL_OVERRIDE;
+ void seat_get_pointer(Resource *resource, uint32_t id) Q_DECL_OVERRIDE;
+
+private:
+ Compositor *m_compositor;
+
+ QScopedPointer<Keyboard> m_keyboard;
+ QScopedPointer<Pointer> m_pointer;
+};
+
+class Keyboard : public QtWaylandServer::wl_keyboard
+{
+public:
+ Keyboard(Compositor *compositor);
+ ~Keyboard();
+
+ Surface *focus() const { return m_focus; }
+ void setFocus(Surface *surface);
+
+ void sendKey(uint32_t key, uint32_t state);
+
+private:
+ Compositor *m_compositor;
+
+ Resource *m_focusResource;
+ Surface *m_focus;
+};
+
+class Pointer : public QtWaylandServer::wl_pointer
+{
+public:
+ Pointer(Compositor *compositor);
+ ~Pointer();
+
+ Surface *focus() const { return m_focus; }
+
+ void setFocus(Surface *surface, const QPoint &pos);
+ void sendMotion(const QPoint &pos);
+ void sendButton(uint32_t button, uint32_t state);
+
+private:
+ Compositor *m_compositor;
+
+ Resource *m_focusResource;
+ Surface *m_focus;
+};
+
+}
+
+#endif // MOCKINPUT_H
diff --git a/tests/auto/client/mocksurface.cpp b/tests/auto/client/mocksurface.cpp
index 49b672f9d..d5e0367a0 100644
--- a/tests/auto/client/mocksurface.cpp
+++ b/tests/auto/client/mocksurface.cpp
@@ -44,123 +44,94 @@
namespace Impl {
-void destroy_surface(wl_resource *resource)
+Surface::Surface(wl_client *client, uint32_t id, Compositor *compositor)
+ : QtWaylandServer::wl_surface(client, id)
+ , m_compositor(compositor)
+ , m_mockSurface(new MockSurface(this))
{
- Surface *surface = static_cast<Surface *>(resource->data);
- surface->compositor()->removeSurface(surface);
- delete surface;
+ wl_list_init(&m_frameCallbackList);
+}
+
+Surface::~Surface()
+{
+ m_mockSurface->m_surface = 0;
}
-static void surface_destroy(wl_client *, wl_resource *surfaceResource)
+void Surface::surface_destroy_resource(Resource *)
{
- wl_resource_destroy(surfaceResource);
+ compositor()->removeSurface(this);
+ delete this;
}
-void surface_attach(wl_client *client, wl_resource *surfaceResource,
- wl_resource *buffer, int x, int y)
+void Surface::surface_destroy(Resource *resource)
{
- Q_UNUSED(client);
+ wl_resource_destroy(resource->handle);
+}
+
+void Surface::surface_attach(Resource *resource,
+ struct wl_resource *buffer, int x, int y)
+{
+ Q_UNUSED(resource);
Q_UNUSED(x);
Q_UNUSED(y);
-
- Surface *surface = static_cast<Surface *>(surfaceResource->data);
- surface->m_buffer = buffer ? static_cast<wl_buffer *>(buffer->data) : 0;
+ m_buffer = buffer;
if (!buffer)
- surface->m_mockSurface->image = QImage();
+ m_mockSurface->image = QImage();
}
-void surface_damage(wl_client *client, wl_resource *surfaceResource,
- int32_t x, int32_t y, int32_t width, int32_t height)
+void Surface::surface_damage(Resource *resource,
+ int32_t x, int32_t y, int32_t width, int32_t height)
{
- Q_UNUSED(client);
+ Q_UNUSED(resource);
Q_UNUSED(x);
Q_UNUSED(y);
Q_UNUSED(width);
Q_UNUSED(height);
- Surface *surface = static_cast<Surface *>(surfaceResource->data);
- wl_buffer *buffer = surface->m_buffer;
-
- if (!buffer)
+ if (!m_buffer)
return;
- if (wl_buffer_is_shm(buffer)) {
- int stride = wl_shm_buffer_get_stride(buffer);
- uint format = wl_shm_buffer_get_format(buffer);
- (void) format;
- void *data = wl_shm_buffer_get_data(buffer);
+#if WAYLAND_VERSION_CHECK(1, 2, 0)
+ struct ::wl_shm_buffer *shm_buffer = wl_shm_buffer_get(m_buffer);
+#else
+ struct ::wl_buffer *shm_buffer = 0;
+ if (wl_buffer_is_shm(static_cast<struct ::wl_buffer*>(m_buffer->data)))
+ shm_buffer = static_cast<struct ::wl_buffer*>(m_buffer->data);
+#endif
+
+ if (shm_buffer) {
+ int stride = wl_shm_buffer_get_stride(shm_buffer);
+ uint format = wl_shm_buffer_get_format(shm_buffer);
+ Q_UNUSED(format);
+ void *data = wl_shm_buffer_get_data(shm_buffer);
const uchar *char_data = static_cast<const uchar *>(data);
- QImage img(char_data, buffer->width, buffer->height, stride, QImage::Format_ARGB32_Premultiplied);
- surface->m_mockSurface->image = img;
+ QImage img(char_data, wl_shm_buffer_get_width(shm_buffer), wl_shm_buffer_get_height(shm_buffer), stride, QImage::Format_ARGB32_Premultiplied);
+ m_mockSurface->image = img;
}
wl_resource *frameCallback;
- wl_list_for_each(frameCallback, &surface->m_frameCallbackList, link) {
- wl_callback_send_done(frameCallback, surface->m_compositor->time());
+ wl_list_for_each(frameCallback, &m_frameCallbackList, link) {
+ wl_callback_send_done(frameCallback, m_compositor->time());
wl_resource_destroy(frameCallback);
}
- wl_list_init(&surface->m_frameCallbackList);
-}
-
-void surface_frame(wl_client *client,
- wl_resource *surfaceResource,
- uint32_t callback)
-{
- Surface *surface = static_cast<Surface *>(surfaceResource->data);
- wl_resource *frameCallback = wl_client_add_object(client, &wl_callback_interface, 0, callback, surface);
- wl_list_insert(&surface->m_frameCallbackList, &frameCallback->link);
-}
-
-void surface_set_opaque_region(wl_client *client, wl_resource *surfaceResource,
- wl_resource *region)
-{
- Q_UNUSED(client);
- Q_UNUSED(surfaceResource);
- Q_UNUSED(region);
-}
-
-void surface_set_input_region(wl_client *client, wl_resource *surfaceResource,
- wl_resource *region)
-{
- Q_UNUSED(client);
- Q_UNUSED(surfaceResource);
- Q_UNUSED(region);
+ wl_list_init(&m_frameCallbackList);
}
-Surface::Surface(wl_client *client, uint32_t id, Compositor *compositor)
- : m_surface(wl_surface())
- , m_compositor(compositor)
- , m_mockSurface(new MockSurface(this))
+void Surface::surface_frame(Resource *resource,
+ uint32_t callback)
{
- static const struct wl_surface_interface surfaceInterface = {
- surface_destroy,
- surface_attach,
- surface_damage,
- surface_frame,
- surface_set_opaque_region,
- surface_set_input_region
- };
-
- m_surface.resource.object.id = id;
- m_surface.resource.object.interface = &wl_surface_interface;
- m_surface.resource.object.implementation = (Implementation)&surfaceInterface;
- m_surface.resource.data = this;
- m_surface.resource.destroy = destroy_surface;
-
- wl_client_add_resource(client, &m_surface.resource);
-
- wl_list_init(&m_frameCallbackList);
+ wl_resource *frameCallback = wl_client_add_object(resource->client(), &wl_callback_interface, 0, callback, this);
+ wl_list_insert(&m_frameCallbackList, &frameCallback->link);
}
-Surface::~Surface()
+void Surface::surface_commit(Resource *resource)
{
- m_mockSurface->m_surface = 0;
+ Q_UNUSED(resource);
}
}
-
MockSurface::MockSurface(Impl::Surface *surface)
: m_surface(surface)
{
diff --git a/tests/auto/client/mocksurface.h b/tests/auto/client/mocksurface.h
index 74014fcd3..49260f51b 100644
--- a/tests/auto/client/mocksurface.h
+++ b/tests/auto/client/mocksurface.h
@@ -40,37 +40,42 @@
****************************************************************************/
#include <qglobal.h>
-#include <wayland-server.h>
+
+#include "qwayland-server-wayland.h"
#include "mockcompositor.h"
namespace Impl {
-class Surface
+class Surface : public QtWaylandServer::wl_surface
{
public:
Surface(wl_client *client, uint32_t id, Compositor *compositor);
~Surface();
Compositor *compositor() const { return m_compositor; }
- wl_surface *handle() { return &m_surface; }
QSharedPointer<MockSurface> mockSurface() const { return m_mockSurface; }
+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_commit(Resource *resource) Q_DECL_OVERRIDE;
private:
- wl_surface m_surface;
- wl_buffer *m_buffer;
+ wl_resource *m_buffer;
Compositor *m_compositor;
QSharedPointer<MockSurface> m_mockSurface;
wl_list m_frameCallbackList;
-
- friend void surface_attach(wl_client *client, wl_resource *surface,
- wl_resource *buffer, int x, int y);
- friend void surface_damage(wl_client *client, wl_resource *surface,
- int32_t x, int32_t y, int32_t width, int32_t height);
- friend void surface_frame(wl_client *client, wl_resource *surface, uint32_t callback);
};
}