[PATCH weston v2 2/6] tests: Introduce input timestamps helper

Alexandros Frantzis alexandros.frantzis at collabora.com
Fri Feb 16 16:44:15 UTC 2018


Introduce helper test code to implement the client side of the
input_timestamps_unstable_v1 protocol. This helper will be used in
upcoming commits to test the server side implementation of the protocol
in libweston.

The input_timestamps_unstable_v1 protocol was introduced in version 1.13
of wayland-protocols, so this commit updates the version dependency in
configure.ac accordingly.

Signed-off-by: Alexandros Frantzis <alexandros.frantzis at collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
---
Changes in v2:
 - Update wayland-protocols version dependency to 1.13.

 Makefile.am                       |  16 ++--
 configure.ac                      |   2 +-
 tests/input-timestamps-helper.c   | 177 ++++++++++++++++++++++++++++++++++++++
 tests/input-timestamps-helper.h   |  46 ++++++++++
 tests/weston-test-client-helper.c |  16 ++++
 tests/weston-test-client-helper.h |  12 +++
 6 files changed, 263 insertions(+), 6 deletions(-)
 create mode 100644 tests/input-timestamps-helper.c
 create mode 100644 tests/input-timestamps-helper.h

diff --git a/Makefile.am b/Makefile.am
index b5c29c04..679e6b78 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -879,7 +879,9 @@ BUILT_SOURCES +=					\
 	protocol/ivi-application-protocol.c		\
 	protocol/ivi-application-client-protocol.h	\
 	protocol/linux-dmabuf-unstable-v1-protocol.c	\
-	protocol/linux-dmabuf-unstable-v1-client-protocol.h
+	protocol/linux-dmabuf-unstable-v1-client-protocol.h		\
+	protocol/input-timestamps-unstable-v1-protocol.c		\
+	protocol/input-timestamps-unstable-v1-client-protocol.h
 
 westondatadir = $(datadir)/weston
 dist_westondata_DATA =				\
@@ -1335,10 +1337,14 @@ vertex_clip_test_LDADD = libtest-runner.la -lm $(CLOCK_GETTIME_LIBS)
 
 libtest_client_la_SOURCES =			\
 	tests/weston-test-client-helper.c	\
-	tests/weston-test-client-helper.h
-nodist_libtest_client_la_SOURCES =		\
-	protocol/weston-test-protocol.c	\
-	protocol/weston-test-client-protocol.h
+	tests/weston-test-client-helper.h	\
+	tests/input-timestamps-helper.c		\
+	tests/input-timestamps-helper.h
+nodist_libtest_client_la_SOURCES =				\
+	protocol/weston-test-protocol.c				\
+	protocol/weston-test-client-protocol.h			\
+	protocol/input-timestamps-unstable-v1-protocol.c	\
+	protocol/input-timestamps-unstable-v1-client-protocol.h
 libtest_client_la_CFLAGS = $(AM_CFLAGS) $(TEST_CLIENT_CFLAGS) $(CAIRO_CFLAGS)
 libtest_client_la_LIBADD = libshared.la libtest-runner.la $(TEST_CLIENT_LIBS) $(CAIRO_LIBS)
 
diff --git a/configure.ac b/configure.ac
index dd344d6a..033b9484 100644
--- a/configure.ac
+++ b/configure.ac
@@ -218,7 +218,7 @@ fi
 PKG_CHECK_MODULES(LIBINPUT_BACKEND, [libinput >= 0.8.0])
 PKG_CHECK_MODULES(COMPOSITOR, [$COMPOSITOR_MODULES])
 
-PKG_CHECK_MODULES(WAYLAND_PROTOCOLS, [wayland-protocols >= 1.8],
+PKG_CHECK_MODULES(WAYLAND_PROTOCOLS, [wayland-protocols >= 1.13],
 		  [ac_wayland_protocols_pkgdatadir=`$PKG_CONFIG --variable=pkgdatadir wayland-protocols`])
 AC_SUBST(WAYLAND_PROTOCOLS_DATADIR, $ac_wayland_protocols_pkgdatadir)
 
diff --git a/tests/input-timestamps-helper.c b/tests/input-timestamps-helper.c
new file mode 100644
index 00000000..9e90fc07
--- /dev/null
+++ b/tests/input-timestamps-helper.c
@@ -0,0 +1,177 @@
+/*
+ * Copyright © 2017 Collabora, Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include "config.h"
+
+#include <assert.h>
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+
+#include "input-timestamps-helper.h"
+#include "protocol/input-timestamps-unstable-v1-client-protocol.h"
+#include "shared/timespec-util.h"
+#include "shared/zalloc.h"
+#include "weston-test-client-helper.h"
+
+struct input_timestamps {
+	struct zwp_input_timestamps_v1 *proxy;
+};
+
+static struct zwp_input_timestamps_manager_v1 *
+get_input_timestamps_manager(struct client *client)
+{
+	struct global *g;
+	struct global *global_ts = NULL;
+	struct zwp_input_timestamps_manager_v1 *ts = NULL;
+
+	wl_list_for_each(g, &client->global_list, link) {
+		if (strcmp(g->interface, zwp_input_timestamps_manager_v1_interface.name))
+			continue;
+
+		if (global_ts)
+			assert(!"Multiple input timestamp managers");
+
+		global_ts = g;
+	}
+
+	assert(global_ts);
+	assert(global_ts->version == 1);
+
+	ts = wl_registry_bind(client->wl_registry, global_ts->name,
+			      &zwp_input_timestamps_manager_v1_interface, 1);
+	assert(ts);
+
+	return ts;
+}
+
+static void
+input_timestamp(void *data,
+		struct zwp_input_timestamps_v1 *zwp_input_timestamps_v1,
+		uint32_t tv_sec_hi,
+		uint32_t tv_sec_lo,
+		uint32_t tv_nsec)
+{
+	struct timespec *timestamp = data;
+
+	timespec_from_proto(timestamp, tv_sec_hi, tv_sec_lo,
+			    tv_nsec);
+
+	fprintf(stderr, "test-client: got input timestamp %ld.%ld\n",
+		timestamp->tv_sec, timestamp->tv_nsec);
+}
+
+static const struct zwp_input_timestamps_v1_listener
+input_timestamps_listener = {
+       .timestamp = input_timestamp,
+};
+
+struct input_timestamps *
+input_timestamps_create_for_keyboard(struct client *client)
+{
+	struct zwp_input_timestamps_manager_v1 *manager =
+		get_input_timestamps_manager(client);
+	struct timespec *timestamp= &client->input->keyboard->input_timestamp;
+	struct input_timestamps *input_ts;
+
+	input_ts = zalloc(sizeof *input_ts);
+	assert(input_ts);
+
+	input_ts->proxy =
+		zwp_input_timestamps_manager_v1_get_keyboard_timestamps(
+			manager, client->input->keyboard->wl_keyboard);
+	assert(input_ts->proxy);
+
+	zwp_input_timestamps_v1_add_listener(input_ts->proxy,
+					     &input_timestamps_listener,
+					     timestamp);
+
+	zwp_input_timestamps_manager_v1_destroy(manager);
+
+	client_roundtrip(client);
+
+	return input_ts;
+}
+
+struct input_timestamps *
+input_timestamps_create_for_pointer(struct client *client)
+{
+	struct zwp_input_timestamps_manager_v1 *manager =
+		get_input_timestamps_manager(client);
+	struct timespec *timestamp= &client->input->pointer->input_timestamp;
+	struct input_timestamps *input_ts;
+
+	input_ts = zalloc(sizeof *input_ts);
+	assert(input_ts);
+
+	input_ts->proxy =
+		zwp_input_timestamps_manager_v1_get_pointer_timestamps(
+			manager, client->input->pointer->wl_pointer);
+	assert(input_ts->proxy);
+
+	zwp_input_timestamps_v1_add_listener(input_ts->proxy,
+					     &input_timestamps_listener,
+					     timestamp);
+
+	zwp_input_timestamps_manager_v1_destroy(manager);
+
+	client_roundtrip(client);
+
+	return input_ts;
+}
+
+struct input_timestamps *
+input_timestamps_create_for_touch(struct client *client)
+{
+	struct zwp_input_timestamps_manager_v1 *manager =
+		get_input_timestamps_manager(client);
+	struct timespec *timestamp= &client->input->touch->input_timestamp;
+	struct input_timestamps *input_ts;
+
+	input_ts = zalloc(sizeof *input_ts);
+	assert(input_ts);
+
+	input_ts->proxy =
+		zwp_input_timestamps_manager_v1_get_touch_timestamps(
+			manager, client->input->touch->wl_touch);
+	assert(input_ts->proxy);
+
+	zwp_input_timestamps_v1_add_listener(input_ts->proxy,
+					     &input_timestamps_listener,
+					     timestamp);
+
+	zwp_input_timestamps_manager_v1_destroy(manager);
+
+	client_roundtrip(client);
+
+	return input_ts;
+}
+
+void
+input_timestamps_destroy(struct input_timestamps *input_ts)
+{
+	zwp_input_timestamps_v1_destroy(input_ts->proxy);
+	free(input_ts);
+}
diff --git a/tests/input-timestamps-helper.h b/tests/input-timestamps-helper.h
new file mode 100644
index 00000000..5301df0e
--- /dev/null
+++ b/tests/input-timestamps-helper.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright © 2017 Collabora, Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef INPUT_TIMESTAMPS_HELPER_H
+#define INPUT_TIMESTAMPS_HELPER_H
+
+#include "config.h"
+
+struct client;
+struct input_timestamps;
+
+struct input_timestamps *
+input_timestamps_create_for_keyboard(struct client *client);
+
+struct input_timestamps *
+input_timestamps_create_for_pointer(struct client *client);
+
+struct input_timestamps *
+input_timestamps_create_for_touch(struct client *client);
+
+void
+input_timestamps_destroy(struct input_timestamps *input_ts);
+
+#endif /* INPUT_TIMESTAMPS_HELPER_H */
diff --git a/tests/weston-test-client-helper.c b/tests/weston-test-client-helper.c
index dc69e151..ea202c0c 100644
--- a/tests/weston-test-client-helper.c
+++ b/tests/weston-test-client-helper.c
@@ -155,6 +155,8 @@ pointer_handle_motion(void *data, struct wl_pointer *wl_pointer,
 	pointer->x = wl_fixed_to_int(x);
 	pointer->y = wl_fixed_to_int(y);
 	pointer->motion_time_msec = time_msec;
+	pointer->motion_time_timespec = pointer->input_timestamp;
+	pointer->input_timestamp = (struct timespec) { 0 };
 
 	fprintf(stderr, "test-client: got pointer motion %d %d\n",
 		pointer->x, pointer->y);
@@ -170,6 +172,8 @@ pointer_handle_button(void *data, struct wl_pointer *wl_pointer,
 	pointer->button = button;
 	pointer->state = state;
 	pointer->button_time_msec = time_msec;
+	pointer->button_time_timespec = pointer->input_timestamp;
+	pointer->input_timestamp = (struct timespec) { 0 };
 
 	fprintf(stderr, "test-client: got pointer button %u %u\n",
 		button, state);
@@ -184,6 +188,8 @@ pointer_handle_axis(void *data, struct wl_pointer *wl_pointer,
 	pointer->axis = axis;
 	pointer->axis_value = wl_fixed_to_double(value);
 	pointer->axis_time_msec = time_msec;
+	pointer->axis_time_timespec = pointer->input_timestamp;
+	pointer->input_timestamp = (struct timespec) { 0 };
 
 	fprintf(stderr, "test-client: got pointer axis %u %f\n",
 		axis, wl_fixed_to_double(value));
@@ -210,6 +216,8 @@ pointer_handle_axis_stop(void *data, struct wl_pointer *wl_pointer,
 
 	pointer->axis = axis;
 	pointer->axis_stop_time_msec = time_msec;
+	pointer->axis_stop_time_timespec = pointer->input_timestamp;
+	pointer->input_timestamp = (struct timespec) { 0 };
 
 	fprintf(stderr, "test-client: got pointer axis stop %u\n", axis);
 }
@@ -281,6 +289,8 @@ keyboard_handle_key(void *data, struct wl_keyboard *wl_keyboard,
 	keyboard->key = key;
 	keyboard->state = state;
 	keyboard->key_time_msec = time_msec;
+	keyboard->key_time_timespec = keyboard->input_timestamp;
+	keyboard->input_timestamp = (struct timespec) { 0 };
 
 	fprintf(stderr, "test-client: got keyboard key %u %u\n", key, state);
 }
@@ -336,6 +346,8 @@ touch_handle_down(void *data, struct wl_touch *wl_touch,
 	touch->down_y = wl_fixed_to_int(y_w);
 	touch->id = id;
 	touch->down_time_msec = time_msec;
+	touch->down_time_timespec = touch->input_timestamp;
+	touch->input_timestamp = (struct timespec) { 0 };
 
 	fprintf(stderr, "test-client: got touch down %d %d, surf: %p, id: %d\n",
 		touch->down_x, touch->down_y, surface, id);
@@ -348,6 +360,8 @@ touch_handle_up(void *data, struct wl_touch *wl_touch,
 	struct touch *touch = data;
 	touch->up_id = id;
 	touch->up_time_msec = time_msec;
+	touch->up_time_timespec = touch->input_timestamp;
+	touch->input_timestamp = (struct timespec) { 0 };
 
 	fprintf(stderr, "test-client: got touch up, id: %d\n", id);
 }
@@ -361,6 +375,8 @@ touch_handle_motion(void *data, struct wl_touch *wl_touch,
 	touch->x = wl_fixed_to_int(x_w);
 	touch->y = wl_fixed_to_int(y_w);
 	touch->motion_time_msec = time_msec;
+	touch->motion_time_timespec = touch->input_timestamp;
+	touch->input_timestamp = (struct timespec) { 0 };
 
 	fprintf(stderr, "test-client: got touch motion, %d %d, id: %d\n",
 		touch->x, touch->y, id);
diff --git a/tests/weston-test-client-helper.h b/tests/weston-test-client-helper.h
index 255bbf66..52e8a560 100644
--- a/tests/weston-test-client-helper.h
+++ b/tests/weston-test-client-helper.h
@@ -31,6 +31,7 @@
 #include <assert.h>
 #include <stdbool.h>
 #include <stdint.h>
+#include <time.h>
 #include <pixman.h>
 
 #include <wayland-client-protocol.h>
@@ -98,6 +99,11 @@ struct pointer {
 	uint32_t button_time_msec;
 	uint32_t axis_time_msec;
 	uint32_t axis_stop_time_msec;
+	struct timespec input_timestamp;
+	struct timespec motion_time_timespec;
+	struct timespec button_time_timespec;
+	struct timespec axis_time_timespec;
+	struct timespec axis_stop_time_timespec;
 };
 
 struct keyboard {
@@ -114,6 +120,8 @@ struct keyboard {
 		int delay;
 	} repeat_info;
 	uint32_t key_time_msec;
+	struct timespec input_timestamp;
+	struct timespec key_time_timespec;
 };
 
 struct touch {
@@ -129,6 +137,10 @@ struct touch {
 	uint32_t down_time_msec;
 	uint32_t up_time_msec;
 	uint32_t motion_time_msec;
+	struct timespec input_timestamp;
+	struct timespec down_time_timespec;
+	struct timespec up_time_timespec;
+	struct timespec motion_time_timespec;
 };
 
 struct output {
-- 
2.14.1



More information about the wayland-devel mailing list