Make the test client more robust and make valgrind happy

Change-Id: I39ce667123391b946711cc2d16d12799e8b7dd2d
Reviewed-by: Robin Burchell <robin.burchell@viroteck.net>
This commit is contained in:
Giulio Camuffo 2014-08-19 16:19:12 +03:00
parent 2efc3bcf4d
commit 76f5ad1784
7 changed files with 63 additions and 51 deletions

View File

@ -135,8 +135,13 @@ QSharedPointer<MockSurface> MockCompositor::surface()
QSharedPointer<MockSurface> result; QSharedPointer<MockSurface> result;
lock(); lock();
QVector<Impl::Surface *> surfaces = m_compositor->surfaces(); QVector<Impl::Surface *> surfaces = m_compositor->surfaces();
if (!surfaces.isEmpty()) foreach (Impl::Surface *surface, surfaces) {
result = surfaces.first()->mockSurface(); // we don't want to mistake the cursor surface for a window surface
if (surface->isMapped()) {
result = surface->mockSurface();
break;
}
}
unlock(); unlock();
return result; return result;
} }
@ -189,11 +194,6 @@ void *MockCompositor::run(void *data)
return 0; return 0;
} }
void MockCompositor::discardSurfaces()
{
m_compositor->discardSurfaces();
}
namespace Impl { namespace Impl {
Compositor::Compositor() Compositor::Compositor()
@ -298,10 +298,5 @@ void Compositor::removeSurface(Surface *surface)
m_pointer->setFocus(0, QPoint()); m_pointer->setFocus(0, QPoint());
} }
void Compositor::discardSurfaces()
{
m_surfaces.clear();
}
} }

View File

@ -81,7 +81,6 @@ public:
void addSurface(Surface *surface); void addSurface(Surface *surface);
void removeSurface(Surface *surface); void removeSurface(Surface *surface);
void discardSurfaces();
static void setKeyboardFocus(void *data, const QList<QVariant> &parameters); static void setKeyboardFocus(void *data, const QList<QVariant> &parameters);
static void sendMousePress(void *data, const QList<QVariant> &parameters); static void sendMousePress(void *data, const QList<QVariant> &parameters);
@ -155,7 +154,6 @@ public:
void sendKeyRelease(const QSharedPointer<MockSurface> &surface, uint code); void sendKeyRelease(const QSharedPointer<MockSurface> &surface, uint code);
QSharedPointer<MockSurface> surface(); QSharedPointer<MockSurface> surface();
void discardSurfaces();
void lock(); void lock();
void unlock(); void unlock();

View File

@ -130,6 +130,8 @@ void Seat::seat_get_pointer(Resource *resource, uint32_t id)
Keyboard::Keyboard(Compositor *compositor) Keyboard::Keyboard(Compositor *compositor)
: wl_keyboard() : wl_keyboard()
, m_compositor(compositor) , m_compositor(compositor)
, m_focusResource(Q_NULLPTR)
, m_focus(Q_NULLPTR)
{ {
} }
@ -174,6 +176,8 @@ void Keyboard::keyboard_destroy_resource(wl_keyboard::Resource *resource)
Pointer::Pointer(Compositor *compositor) Pointer::Pointer(Compositor *compositor)
: wl_pointer() : wl_pointer()
, m_compositor(compositor) , m_compositor(compositor)
, m_focusResource(Q_NULLPTR)
, m_focus(Q_NULLPTR)
{ {
} }

View File

@ -40,6 +40,7 @@
****************************************************************************/ ****************************************************************************/
#include "mockcompositor.h" #include "mockcompositor.h"
#include "mocksurface.h"
namespace Impl { namespace Impl {
@ -173,6 +174,8 @@ static void get_shell_surface(wl_client *client, wl_resource *compositorResource
Q_UNUSED(compositorResource); Q_UNUSED(compositorResource);
wl_client_add_object(client, &wl_shell_surface_interface, &shellSurfaceInterface, id, surfaceResource->data); wl_client_add_object(client, &wl_shell_surface_interface, &shellSurfaceInterface, id, surfaceResource->data);
Surface *surf = Surface::fromResource(surfaceResource);
surf->map();
} }
void Compositor::bindShell(wl_client *client, void *compositorData, uint32_t version, uint32_t id) void Compositor::bindShell(wl_client *client, void *compositorData, uint32_t version, uint32_t id)

View File

@ -46,10 +46,11 @@ namespace Impl {
Surface::Surface(wl_client *client, uint32_t id, Compositor *compositor) Surface::Surface(wl_client *client, uint32_t id, Compositor *compositor)
: QtWaylandServer::wl_surface(client, id) : QtWaylandServer::wl_surface(client, id)
, m_buffer(Q_NULLPTR)
, m_compositor(compositor) , m_compositor(compositor)
, m_mockSurface(new MockSurface(this)) , m_mockSurface(new MockSurface(this))
, m_mapped(false)
{ {
wl_list_init(&m_frameCallbackList);
} }
Surface::~Surface() Surface::~Surface()
@ -57,6 +58,21 @@ Surface::~Surface()
m_mockSurface->m_surface = 0; m_mockSurface->m_surface = 0;
} }
void Surface::map()
{
m_mapped = true;
}
bool Surface::isMapped() const
{
return m_mapped;
}
Surface *Surface::fromResource(struct ::wl_resource *resource)
{
return static_cast<Surface *>(Resource::fromResource(resource)->surface_object);
}
void Surface::surface_destroy_resource(Resource *) void Surface::surface_destroy_resource(Resource *)
{ {
compositor()->removeSurface(this); compositor()->removeSurface(this);
@ -88,47 +104,44 @@ void Surface::surface_damage(Resource *resource,
Q_UNUSED(y); Q_UNUSED(y);
Q_UNUSED(width); Q_UNUSED(width);
Q_UNUSED(height); Q_UNUSED(height);
if (!m_buffer)
return;
#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, 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, &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, void Surface::surface_frame(Resource *resource,
uint32_t callback) uint32_t callback)
{ {
wl_resource *frameCallback = wl_client_add_object(resource->client(), &wl_callback_interface, 0, callback, this); wl_resource *frameCallback = wl_client_add_object(resource->client(), &wl_callback_interface, 0, callback, this);
wl_list_insert(&m_frameCallbackList, &frameCallback->link); m_frameCallbackList << frameCallback;
} }
void Surface::surface_commit(Resource *resource) void Surface::surface_commit(Resource *resource)
{ {
Q_UNUSED(resource); Q_UNUSED(resource);
if (m_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, wl_shm_buffer_get_width(shm_buffer), wl_shm_buffer_get_height(shm_buffer), stride, QImage::Format_ARGB32_Premultiplied);
m_mockSurface->image = img;
}
}
foreach (wl_resource *frameCallback, m_frameCallbackList) {
wl_callback_send_done(frameCallback, m_compositor->time());
wl_resource_destroy(frameCallback);
}
m_frameCallbackList.clear();
} }
} }

View File

@ -54,6 +54,9 @@ public:
~Surface(); ~Surface();
Compositor *compositor() const { return m_compositor; } Compositor *compositor() const { return m_compositor; }
static Surface *fromResource(struct ::wl_resource *resource);
void map();
bool isMapped() const;
QSharedPointer<MockSurface> mockSurface() const { return m_mockSurface; } QSharedPointer<MockSurface> mockSurface() const { return m_mockSurface; }
@ -74,8 +77,8 @@ private:
Compositor *m_compositor; Compositor *m_compositor;
QSharedPointer<MockSurface> m_mockSurface; QSharedPointer<MockSurface> m_mockSurface;
QList<wl_resource *> m_frameCallbackList;
wl_list m_frameCallbackList; bool m_mapped;
}; };
} }

View File

@ -149,11 +149,7 @@ private:
void tst_WaylandClient::screen() void tst_WaylandClient::screen()
{ {
QCoreApplication::processEvents(QEventLoop::AllEvents);
QTRY_COMPARE(QGuiApplication::primaryScreen()->size(), screenSize); QTRY_COMPARE(QGuiApplication::primaryScreen()->size(), screenSize);
// discard the cursor surface created by the QWaylandInputDevice
compositor->discardSurfaces();
} }
void tst_WaylandClient::createDestroyWindow() void tst_WaylandClient::createDestroyWindow()