Update tests so that it does not deadlock
still failes though Change-Id: I7978c752b02f32a2e2c587c0ad674c51c5e0ad22 Reviewed-by: Andy Nichols <andy.nichols@digia.com>
This commit is contained in:
parent
9c4036ce6a
commit
ed089d9b7a
@ -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 \
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include "mockcompositor.h"
|
||||
#include "mocksurface.h"
|
||||
|
||||
#include <stdio.h>
|
||||
MockCompositor::MockCompositor()
|
||||
: m_alive(true)
|
||||
, m_ready(false)
|
||||
@ -195,7 +196,10 @@ Compositor::Compositor()
|
||||
{
|
||||
wl_list_init(&m_outputResources);
|
||||
|
||||
wl_display_add_socket(m_display, 0);
|
||||
if (wl_display_add_socket(m_display, 0)) {
|
||||
fprintf(stderr, "Fatal: Failed to open server socket\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
wl_seat_init(&m_seat);
|
||||
wl_pointer_init(&m_pointer);
|
||||
@ -204,11 +208,13 @@ Compositor::Compositor()
|
||||
wl_seat_set_keyboard(&m_seat, &m_keyboard);
|
||||
|
||||
wl_display_add_global(m_display, &wl_compositor_interface, this, bindCompositor);
|
||||
|
||||
wl_display_init_shm(m_display);
|
||||
|
||||
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_loop = wl_display_get_event_loop(m_display);
|
||||
m_fd = wl_event_loop_get_fd(m_loop);
|
||||
@ -223,6 +229,7 @@ Compositor::~Compositor()
|
||||
|
||||
void Compositor::dispatchEvents(int timeout)
|
||||
{
|
||||
wl_display_flush_clients(m_display);
|
||||
wl_event_loop_dispatch(m_loop, timeout);
|
||||
}
|
||||
|
||||
|
@ -142,7 +142,7 @@ static wl_surface *resolveSurface(const QVariant &v)
|
||||
{
|
||||
QSharedPointer<MockSurface> mockSurface = v.value<QSharedPointer<MockSurface> >();
|
||||
Surface *surface = mockSurface ? mockSurface->handle() : 0;
|
||||
return surface ? surface->handle() : 0;
|
||||
return surface ? surface->base() : 0;
|
||||
}
|
||||
|
||||
void Compositor::setKeyboardFocus(void *data, const QList<QVariant> ¶meters)
|
||||
|
@ -44,113 +44,11 @@
|
||||
|
||||
namespace Impl {
|
||||
|
||||
void destroy_surface(wl_resource *resource)
|
||||
{
|
||||
Surface *surface = static_cast<Surface *>(resource->data);
|
||||
surface->compositor()->removeSurface(surface);
|
||||
delete surface;
|
||||
}
|
||||
|
||||
static void surface_destroy(wl_client *, wl_resource *surfaceResource)
|
||||
{
|
||||
wl_resource_destroy(surfaceResource);
|
||||
}
|
||||
|
||||
void surface_attach(wl_client *client, wl_resource *surfaceResource,
|
||||
wl_resource *buffer, int x, int y)
|
||||
{
|
||||
Q_UNUSED(client);
|
||||
Q_UNUSED(x);
|
||||
Q_UNUSED(y);
|
||||
|
||||
Surface *surface = static_cast<Surface *>(surfaceResource->data);
|
||||
surface->m_buffer = buffer ? static_cast<wl_buffer *>(buffer->data) : 0;
|
||||
|
||||
if (!buffer)
|
||||
surface->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)
|
||||
{
|
||||
Q_UNUSED(client);
|
||||
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)
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
wl_resource *frameCallback;
|
||||
wl_list_for_each(frameCallback, &surface->m_frameCallbackList, link) {
|
||||
wl_callback_send_done(frameCallback, surface->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);
|
||||
}
|
||||
|
||||
Surface::Surface(wl_client *client, uint32_t id, Compositor *compositor)
|
||||
: m_surface(wl_surface())
|
||||
: QtWaylandServer::wl_surface(client, &base()->resource, id)
|
||||
, m_compositor(compositor)
|
||||
, m_mockSurface(new MockSurface(this))
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
@ -159,8 +57,73 @@ Surface::~Surface()
|
||||
m_mockSurface->m_surface = 0;
|
||||
}
|
||||
|
||||
void Surface::surface_destroy_resource(Resource *)
|
||||
{
|
||||
compositor()->removeSurface(this);
|
||||
delete this;
|
||||
}
|
||||
|
||||
void Surface::surface_destroy(Resource *resource)
|
||||
{
|
||||
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);
|
||||
m_buffer = buffer ? static_cast<wl_buffer *>(buffer->data) : 0;
|
||||
|
||||
if (!buffer)
|
||||
m_mockSurface->image = QImage();
|
||||
}
|
||||
|
||||
void Surface::surface_damage(Resource *resource,
|
||||
int32_t x, int32_t y, int32_t width, int32_t height)
|
||||
{
|
||||
Q_UNUSED(resource);
|
||||
Q_UNUSED(x);
|
||||
Q_UNUSED(y);
|
||||
Q_UNUSED(width);
|
||||
Q_UNUSED(height);
|
||||
|
||||
if (!m_buffer)
|
||||
return;
|
||||
|
||||
if (wl_buffer_is_shm(m_buffer)) {
|
||||
int stride = wl_shm_buffer_get_stride(m_buffer);
|
||||
uint format = wl_shm_buffer_get_format(m_buffer);
|
||||
Q_UNUSED(format);
|
||||
void *data = wl_shm_buffer_get_data(m_buffer);
|
||||
const uchar *char_data = static_cast<const uchar *>(data);
|
||||
QImage img(char_data, m_buffer->width, m_buffer->height, stride, QImage::Format_ARGB32_Premultiplied);
|
||||
m_mockSurface->image = img;
|
||||
}
|
||||
|
||||
wl_resource *frameCallback;
|
||||
wl_list_for_each(frameCallback, &m_frameCallbackList, link) {
|
||||
wl_callback_send_done(frameCallback, m_compositor->time());
|
||||
wl_resource_destroy(frameCallback);
|
||||
}
|
||||
|
||||
wl_list_init(&m_frameCallbackList);
|
||||
}
|
||||
|
||||
void Surface::surface_frame(Resource *resource,
|
||||
uint32_t callback)
|
||||
{
|
||||
wl_resource *frameCallback = wl_client_add_object(resource->client(), &wl_callback_interface, 0, callback, this);
|
||||
wl_list_insert(&m_frameCallbackList, &frameCallback->link);
|
||||
}
|
||||
|
||||
void Surface::surface_commit(Resource *resource)
|
||||
{
|
||||
Q_UNUSED(resource);
|
||||
}
|
||||
|
||||
}
|
||||
MockSurface::MockSurface(Impl::Surface *surface)
|
||||
: m_surface(surface)
|
||||
{
|
||||
|
@ -40,37 +40,44 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include <qglobal.h>
|
||||
#include <wayland-server.h>
|
||||
|
||||
#include <QtCompositor/qwaylandobject.h>
|
||||
|
||||
#include "qwayland-server-wayland.h"
|
||||
|
||||
#include "mockcompositor.h"
|
||||
|
||||
namespace Impl {
|
||||
|
||||
class Surface
|
||||
class Surface : public QtWayland::Object<struct ::wl_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;
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user