[PATCH weston 00/12] libweston: Use struct timespec for time values

2017-11-16 Thread Alexandros Frantzis
This patchset changes libweston to consistently use struct timespec for time
values.

struct timespec is the standard way to represent time on Linux and allows for
an improved range and accuracy compared to the millisecond based uint32_t
values currently used in throughout the codebase. This change provides to users
of libweston timestamps with higher accuracy, and will also allow libweston to
more easily support future wayland interfaces that may require such
high-accuracy timestamps.

Note that this patchset breaks the libweston ABI, so we will need to bump the
ABI version at some point.

Patches (1) and (2) add more functionality to the timespec utilities to support
the new uses cases introduced in the commits that follow.

Patches (3) to (12) gradually transition libweston to use struct timespec.  To
make the changes more reviewable, each patch deals with only a specific aspect
of the codebase. In order to limit the scope of each commit, some commits
include temporary time value conversions to accommodate existing internal APIs.
These temporary conversions are later removed as the internal APIs are
also changed to used struct timespec.

Alexandros Frantzis (12):
  shared: Add timespec_is_zero helper
  shared: Add helpers to convert between various time units and timespec
  libweston: Use struct timespec for animations
  libweston: Use struct timespec for the output presentation timestamp
  libweston: Use struct timespec for motion events
  libweston: Use struct timespec for button events
  libweston: Use struct timespec for axis events
  libweston: Use struct timespec for key events
  libweston: Use struct timespec for touch down events
  libweston: Use struct timespec for touch up events
  libweston: Use struct timespec for touch motion events
  libweston: Use struct timespec for compositor time

 compositor/screen-share.c |  24 +--
 compositor/text-backend.c |  24 +--
 compositor/weston-screenshooter.c |   6 +-
 desktop-shell/exposay.c   |  14 ++--
 desktop-shell/shell.c | 134 +-
 desktop-shell/shell.h |   4 +-
 ivi-shell/hmi-controller.c|  18 +++--
 ivi-shell/ivi-shell.c |   8 ++-
 libweston-desktop/seat.c  |  23 ---
 libweston/animation.c |  29 +
 libweston/bindings.c  |  32 +
 libweston/compositor-drm.c|  16 ++---
 libweston/compositor-rdp.c|  22 +--
 libweston/compositor-wayland.c|  42 +---
 libweston/compositor-x11.c|  45 +++--
 libweston/compositor.c|  24 +++
 libweston/compositor.h|  99 
 libweston/data-device.c   |  34 ++
 libweston/gl-renderer.c   |   6 +-
 libweston/input.c | 117 -
 libweston/launcher-util.c |   2 +-
 libweston/libinput-device.c   |  59 ++---
 libweston/pixman-renderer.c   |   4 +-
 libweston/screenshooter.c |   3 +-
 libweston/spring-tool.c   |  13 ++--
 libweston/zoom.c  |   7 +-
 shared/timespec-util.h|  59 +
 tests/surface-screenshot.c|   4 +-
 tests/timespec-test.c |  83 +++
 tests/weston-test.c   |  17 -
 30 files changed, 647 insertions(+), 325 deletions(-)

-- 
2.14.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH weston 01/12] shared: Add timespec_is_zero helper

2017-11-16 Thread Alexandros Frantzis
Add a helper function to check if a struct timespec is zero. This helper
will be used in the upcoming commits to transition the Weston codebase
to struct timespec.

Signed-off-by: Alexandros Frantzis 
---
 shared/timespec-util.h | 12 
 tests/timespec-test.c  | 11 +++
 2 files changed, 23 insertions(+)

diff --git a/shared/timespec-util.h b/shared/timespec-util.h
index 34a120ae..7260dc8b 100644
--- a/shared/timespec-util.h
+++ b/shared/timespec-util.h
@@ -29,6 +29,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define NSEC_PER_SEC 10
 
@@ -133,6 +134,17 @@ timespec_sub_to_msec(const struct timespec *a, const 
struct timespec *b)
return timespec_sub_to_nsec(a, b) / 100;
 }
 
+/* Check if a timespec is zero
+ *
+ * \param a timespec
+ * \return whether the timespec is zero
+ */
+static inline bool
+timespec_is_zero(const struct timespec *a)
+{
+   return a->tv_sec == 0 && a->tv_nsec == 0;
+}
+
 /* Convert milli-Hertz to nanoseconds
  *
  * \param mhz frequency in mHz, not zero
diff --git a/tests/timespec-test.c b/tests/timespec-test.c
index a5039110..551bc1be 100644
--- a/tests/timespec-test.c
+++ b/tests/timespec-test.c
@@ -164,3 +164,14 @@ ZUC_TEST(timespec_test, timespec_sub_to_msec)
b.tv_nsec = 100L;
ZUC_ASSERT_EQ((998 * 1000) + 1, timespec_sub_to_msec(&a, &b));
 }
+
+ZUC_TEST(timespec_test, timespec_is_zero)
+{
+   struct timespec zero = { 0 };
+   struct timespec non_zero_sec = { 1, 0 };
+   struct timespec non_zero_nsec = { 0, 1 };
+
+   ZUC_ASSERT_TRUE(timespec_is_zero(&zero));
+   ZUC_ASSERT_FALSE(timespec_is_zero(&non_zero_nsec));
+   ZUC_ASSERT_FALSE(timespec_is_zero(&non_zero_sec));
+}
-- 
2.14.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH weston 05/12] libweston: Use struct timespec for motion events

2017-11-16 Thread Alexandros Frantzis
Change code related to motion events to use struct timespec to represent
time.

This commit is part of a larger effort to transition the Weston codebase
to struct timespec.

Signed-off-by: Alexandros Frantzis 
---
 compositor/screen-share.c  |  6 +-
 desktop-shell/exposay.c|  3 ++-
 desktop-shell/shell.c  | 12 
 ivi-shell/hmi-controller.c |  3 ++-
 libweston-desktop/seat.c   |  2 +-
 libweston/compositor-rdp.c | 10 +++---
 libweston/compositor-wayland.c |  5 -
 libweston/compositor-x11.c |  6 --
 libweston/compositor.h | 12 +++-
 libweston/data-device.c|  8 ++--
 libweston/input.c  | 30 ++
 libweston/libinput-device.c| 19 ++-
 tests/weston-test.c|  6 +-
 13 files changed, 79 insertions(+), 43 deletions(-)

diff --git a/compositor/screen-share.c b/compositor/screen-share.c
index a6f82b19..c7aad313 100644
--- a/compositor/screen-share.c
+++ b/compositor/screen-share.c
@@ -44,6 +44,7 @@
 #include "weston.h"
 #include "shared/helpers.h"
 #include "shared/os-compatibility.h"
+#include "shared/timespec-util.h"
 #include "fullscreen-shell-unstable-v1-client-protocol.h"
 
 struct shared_output {
@@ -140,11 +141,14 @@ ss_seat_handle_motion(void *data, struct wl_pointer 
*pointer,
  uint32_t time, wl_fixed_t x, wl_fixed_t y)
 {
struct ss_seat *seat = data;
+   struct timespec ts;
+
+   timespec_from_msec(&ts, time);
 
/* No transformation of input position is required here because we are
 * always receiving the input in the same coordinates as the output. */
 
-   notify_motion_absolute(&seat->base, time,
+   notify_motion_absolute(&seat->base, &ts,
   wl_fixed_to_double(x), wl_fixed_to_double(y));
notify_pointer_frame(&seat->base);
 }
diff --git a/desktop-shell/exposay.c b/desktop-shell/exposay.c
index b11a7f79..15b86863 100644
--- a/desktop-shell/exposay.c
+++ b/desktop-shell/exposay.c
@@ -349,7 +349,8 @@ exposay_focus(struct weston_pointer_grab *grab)
 }
 
 static void
-exposay_motion(struct weston_pointer_grab *grab, uint32_t time,
+exposay_motion(struct weston_pointer_grab *grab,
+  const struct timespec *time,
   struct weston_pointer_motion_event *event)
 {
struct desktop_shell *shell =
diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c
index 55380417..62dfa450 100644
--- a/desktop-shell/shell.c
+++ b/desktop-shell/shell.c
@@ -1482,7 +1482,8 @@ constrain_position(struct weston_move_grab *move, int 
*cx, int *cy)
 }
 
 static void
-move_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
+move_grab_motion(struct weston_pointer_grab *grab,
+const struct timespec *time,
 struct weston_pointer_motion_event *event)
 {
struct weston_move_grab *move = (struct weston_move_grab *) grab;
@@ -1577,7 +1578,8 @@ struct weston_resize_grab {
 };
 
 static void
-resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
+resize_grab_motion(struct weston_pointer_grab *grab,
+  const struct timespec *time,
   struct weston_pointer_motion_event *event)
 {
struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
@@ -1767,7 +1769,8 @@ busy_cursor_grab_focus(struct weston_pointer_grab *base)
 }
 
 static void
-busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
+busy_cursor_grab_motion(struct weston_pointer_grab *grab,
+   const struct timespec *time,
struct weston_pointer_motion_event *event)
 {
weston_pointer_move(grab->pointer, event);
@@ -3443,7 +3446,8 @@ terminate_binding(struct weston_keyboard *keyboard, 
uint32_t time,
 }
 
 static void
-rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
+rotate_grab_motion(struct weston_pointer_grab *grab,
+  const struct timespec *time,
   struct weston_pointer_motion_event *event)
 {
struct rotate_grab *rotate =
diff --git a/ivi-shell/hmi-controller.c b/ivi-shell/hmi-controller.c
index d5403e06..6713eca3 100644
--- a/ivi-shell/hmi-controller.c
+++ b/ivi-shell/hmi-controller.c
@@ -1534,7 +1534,8 @@ layer_set_pos(struct ivi_layout_layer *layer, wl_fixed_t 
pos_x,
 }
 
 static void
-pointer_move_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
+pointer_move_grab_motion(struct weston_pointer_grab *grab,
+const struct timespec *time,
 struct weston_pointer_motion_event *event)
 {
struct pointer_move_grab *pnt_move_grab =
diff --git a/libweston-desktop/seat.c b/libweston-desktop/seat.c
index 96308807..18a329c4 100644
--- a/libweston-desktop/seat.c
+++ b/libweston-desktop/seat.c
@@ -108,7 +108,7 @@ weston_

[PATCH weston 04/12] libweston: Use struct timespec for the output presentation timestamp

2017-11-16 Thread Alexandros Frantzis
Store the output presentation timestamp as struct timespec.

This commit is part of a larger effort to transition the Weston codebase
to struct timespec.

Signed-off-by: Alexandros Frantzis 
---
 libweston/compositor.c| 12 ++--
 libweston/compositor.h|  2 +-
 libweston/screenshooter.c |  3 ++-
 3 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/libweston/compositor.c b/libweston/compositor.c
index 037b4b5f..cfa7eace 100644
--- a/libweston/compositor.c
+++ b/libweston/compositor.c
@@ -2292,15 +2292,13 @@ weston_output_repaint(struct weston_output *output, 
void *repaint_data)
struct wl_list frame_callback_list;
pixman_region32_t output_damage;
int r;
-   struct timespec frame_time;
+   uint32_t frame_time_msec;
 
if (output->destroying)
return 0;
 
TL_POINT("core_repaint_begin", TLP_OUTPUT(output), TLP_END);
 
-   timespec_from_msec(&frame_time, output->frame_time);
-
/* Rebuild the surface list and update surface transforms up front. */
weston_compositor_build_view_list(ec);
 
@@ -2348,14 +2346,16 @@ weston_output_repaint(struct weston_output *output, 
void *repaint_data)
 
weston_compositor_repick(ec);
 
+   frame_time_msec = timespec_to_msec(&output->frame_time);
+
wl_list_for_each_safe(cb, cnext, &frame_callback_list, link) {
-   wl_callback_send_done(cb->resource, output->frame_time);
+   wl_callback_send_done(cb->resource, frame_time_msec);
wl_resource_destroy(cb->resource);
}
 
wl_list_for_each_safe(animation, next, &output->animation_list, link) {
animation->frame_counter++;
-   animation->frame(animation, output, &frame_time);
+   animation->frame(animation, output, &output->frame_time);
}
 
TL_POINT("core_repaint_posted", TLP_OUTPUT(output), TLP_END);
@@ -2520,7 +2520,7 @@ weston_output_finish_frame(struct weston_output *output,
  output->msc,
  presented_flags);
 
-   output->frame_time = timespec_to_msec(stamp);
+   output->frame_time = *stamp;
 
timespec_add_nsec(&output->next_repaint, stamp, refresh_nsec);
timespec_add_msec(&output->next_repaint, &output->next_repaint,
diff --git a/libweston/compositor.h b/libweston/compositor.h
index 23d709ce..59c349d5 100644
--- a/libweston/compositor.h
+++ b/libweston/compositor.h
@@ -193,7 +193,7 @@ struct weston_output {
struct wl_signal frame_signal;
struct wl_signal destroy_signal;
int move_x, move_y;
-   uint32_t frame_time; /* presentation timestamp in milliseconds */
+   struct timespec frame_time; /* presentation timestamp */
uint64_t msc;/* media stream counter */
int disable_planes;
int destroying;
diff --git a/libweston/screenshooter.c b/libweston/screenshooter.c
index 2c5dacc1..f4e3f4de 100644
--- a/libweston/screenshooter.c
+++ b/libweston/screenshooter.c
@@ -36,6 +36,7 @@
 
 #include "compositor.h"
 #include "shared/helpers.h"
+#include "shared/timespec-util.h"
 
 #include "wcap/wcap-decode.h"
 
@@ -259,7 +260,7 @@ weston_recorder_frame_notify(struct wl_listener *listener, 
void *data)
container_of(listener, struct weston_recorder, frame_listener);
struct weston_output *output = data;
struct weston_compositor *compositor = output->compositor;
-   uint32_t msecs = output->frame_time;
+   uint32_t msecs = timespec_to_msec(&output->frame_time);
pixman_box32_t *r;
pixman_region32_t damage, transformed_damage;
int i, j, k, n, width, height, run, stride;
-- 
2.14.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH weston 02/12] shared: Add helpers to convert between various time units and timespec

2017-11-16 Thread Alexandros Frantzis
Add helper functions to make it easy and less error-prone to convert
between values in various time units (nsec, usec, msec) and struct
timespec. These helpers are going to be used in the upcoming commits to
transition the Weston codebase to struct timespec.

Signed-off-by: Alexandros Frantzis 
---
 shared/timespec-util.h | 47 
 tests/timespec-test.c  | 72 ++
 2 files changed, 119 insertions(+)

diff --git a/shared/timespec-util.h b/shared/timespec-util.h
index 7260dc8b..f9736c27 100644
--- a/shared/timespec-util.h
+++ b/shared/timespec-util.h
@@ -134,6 +134,53 @@ timespec_sub_to_msec(const struct timespec *a, const 
struct timespec *b)
return timespec_sub_to_nsec(a, b) / 100;
 }
 
+/* Convert timespec to microseconds
+ *
+ * \param a timespec
+ * \return microseconds
+ *
+ * Rounding to integer microseconds happens always down (floor()).
+ */
+static inline int64_t
+timespec_to_usec(const struct timespec *a)
+{
+   return (int64_t)a->tv_sec * 100 + a->tv_nsec / 1000;
+}
+
+/* Convert nanoseconds to timespec
+ *
+ * \param a timespec
+ * \param b nanoseconds
+ */
+static inline void
+timespec_from_nsec(struct timespec *a, int64_t b)
+{
+   a->tv_sec = b / NSEC_PER_SEC;
+   a->tv_nsec = b % NSEC_PER_SEC;
+}
+
+/* Convert microseconds to timespec
+ *
+ * \param a timespec
+ * \param b microseconds
+ */
+static inline void
+timespec_from_usec(struct timespec *a, int64_t b)
+{
+   timespec_from_nsec(a, b * 1000);
+}
+
+/* Convert milliseconds to timespec
+ *
+ * \param a timespec
+ * \param b milliseconds
+ */
+static inline void
+timespec_from_msec(struct timespec *a, int64_t b)
+{
+   timespec_from_nsec(a, b * 100);
+}
+
 /* Check if a timespec is zero
  *
  * \param a timespec
diff --git a/tests/timespec-test.c b/tests/timespec-test.c
index 551bc1be..7a26d528 100644
--- a/tests/timespec-test.c
+++ b/tests/timespec-test.c
@@ -60,6 +60,15 @@ ZUC_TEST(timespec_test, timespec_to_nsec)
ZUC_ASSERT_EQ(timespec_to_nsec(&a), (NSEC_PER_SEC * 4ULL) + 4);
 }
 
+ZUC_TEST(timespec_test, timespec_to_usec)
+{
+   struct timespec a;
+
+   a.tv_sec = 4;
+   a.tv_nsec = 4000;
+   ZUC_ASSERT_EQ(timespec_to_usec(&a), (400ULL) + 4);
+}
+
 ZUC_TEST(timespec_test, timespec_to_msec)
 {
struct timespec a;
@@ -165,6 +174,69 @@ ZUC_TEST(timespec_test, timespec_sub_to_msec)
ZUC_ASSERT_EQ((998 * 1000) + 1, timespec_sub_to_msec(&a, &b));
 }
 
+ZUC_TEST(timespec_test, timespec_from_nsec)
+{
+   struct timespec a;
+
+   timespec_from_nsec(&a, 0);
+   ZUC_ASSERT_EQ(0, a.tv_sec);
+   ZUC_ASSERT_EQ(0, a.tv_nsec);
+
+   timespec_from_nsec(&a, NSEC_PER_SEC - 1);
+   ZUC_ASSERT_EQ(0, a.tv_sec);
+   ZUC_ASSERT_EQ(NSEC_PER_SEC - 1, a.tv_nsec);
+
+   timespec_from_nsec(&a, NSEC_PER_SEC);
+   ZUC_ASSERT_EQ(1, a.tv_sec);
+   ZUC_ASSERT_EQ(0, a.tv_nsec);
+
+   timespec_from_nsec(&a, (5L * NSEC_PER_SEC) + 1);
+   ZUC_ASSERT_EQ(5, a.tv_sec);
+   ZUC_ASSERT_EQ(1, a.tv_nsec);
+}
+
+ZUC_TEST(timespec_test, timespec_from_usec)
+{
+   struct timespec a;
+
+   timespec_from_usec(&a, 0);
+   ZUC_ASSERT_EQ(0, a.tv_sec);
+   ZUC_ASSERT_EQ(0, a.tv_nsec);
+
+   timespec_from_usec(&a, 99);
+   ZUC_ASSERT_EQ(0, a.tv_sec);
+   ZUC_ASSERT_EQ(99 * 1000, a.tv_nsec);
+
+   timespec_from_usec(&a, 100);
+   ZUC_ASSERT_EQ(1, a.tv_sec);
+   ZUC_ASSERT_EQ(0, a.tv_nsec);
+
+   timespec_from_usec(&a, 501);
+   ZUC_ASSERT_EQ(5, a.tv_sec);
+   ZUC_ASSERT_EQ(1000, a.tv_nsec);
+}
+
+ZUC_TEST(timespec_test, timespec_from_msec)
+{
+   struct timespec a;
+
+   timespec_from_msec(&a, 0);
+   ZUC_ASSERT_EQ(0, a.tv_sec);
+   ZUC_ASSERT_EQ(0, a.tv_nsec);
+
+   timespec_from_msec(&a, 999);
+   ZUC_ASSERT_EQ(0, a.tv_sec);
+   ZUC_ASSERT_EQ(999 * 100, a.tv_nsec);
+
+   timespec_from_msec(&a, 1000);
+   ZUC_ASSERT_EQ(1, a.tv_sec);
+   ZUC_ASSERT_EQ(0, a.tv_nsec);
+
+   timespec_from_msec(&a, 5001);
+   ZUC_ASSERT_EQ(5, a.tv_sec);
+   ZUC_ASSERT_EQ(100, a.tv_nsec);
+}
+
 ZUC_TEST(timespec_test, timespec_is_zero)
 {
struct timespec zero = { 0 };
-- 
2.14.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH weston 03/12] libweston: Use struct timespec for animations

2017-11-16 Thread Alexandros Frantzis
Change code related to animations to use struct timespec to represent
time.

This commit is part of a larger effort to transition the Weston codebase
to struct timespec.

Signed-off-by: Alexandros Frantzis 
---
 desktop-shell/shell.c   | 26 ++
 desktop-shell/shell.h   |  2 +-
 libweston/animation.c   | 29 ++---
 libweston/compositor.c  |  5 -
 libweston/compositor.h  |  7 ---
 libweston/spring-tool.c | 13 -
 libweston/zoom.c|  7 ---
 7 files changed, 53 insertions(+), 36 deletions(-)

diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c
index 1f99efe3..55380417 100644
--- a/desktop-shell/shell.c
+++ b/desktop-shell/shell.c
@@ -41,6 +41,7 @@
 #include "weston-desktop-shell-server-protocol.h"
 #include "shared/config-parser.h"
 #include "shared/helpers.h"
+#include "shared/timespec-util.h"
 #include "libweston-desktop/libweston-desktop.h"
 
 #define DEFAULT_NUM_WORKSPACES 1
@@ -1027,7 +1028,7 @@ reverse_workspace_change_animation(struct desktop_shell 
*shell,
shell->workspaces.anim_to = to;
shell->workspaces.anim_from = from;
shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir;
-   shell->workspaces.anim_timestamp = 0;
+   shell->workspaces.anim_timestamp = (struct timespec) { 0 };
 
weston_layer_set_position(&to->layer, WESTON_LAYER_POSITION_NORMAL);
weston_layer_set_position(&from->layer, WESTON_LAYER_POSITION_NORMAL - 
1);
@@ -1084,14 +1085,15 @@ finish_workspace_change_animation(struct desktop_shell 
*shell,
 
 static void
 animate_workspace_change_frame(struct weston_animation *animation,
-  struct weston_output *output, uint32_t msecs)
+  struct weston_output *output,
+  const struct timespec *time)
 {
struct desktop_shell *shell =
container_of(animation, struct desktop_shell,
 workspaces.animation);
struct workspace *from = shell->workspaces.anim_from;
struct workspace *to = shell->workspaces.anim_to;
-   uint32_t t;
+   int64_t t;
double x, y;
 
if (workspace_is_empty(from) && workspace_is_empty(to)) {
@@ -1099,19 +1101,19 @@ animate_workspace_change_frame(struct weston_animation 
*animation,
return;
}
 
-   if (shell->workspaces.anim_timestamp == 0) {
+   if (timespec_is_zero(&shell->workspaces.anim_timestamp)) {
if (shell->workspaces.anim_current == 0.0)
-   shell->workspaces.anim_timestamp = msecs;
+   shell->workspaces.anim_timestamp = *time;
else
-   shell->workspaces.anim_timestamp =
-   msecs -
+   timespec_add_msec(&shell->workspaces.anim_timestamp,
+   time,
/* Invers of movement function 'y' below. */
-   (asin(1.0 - shell->workspaces.anim_current) *
-DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH *
-M_2_PI);
+   -(asin(1.0 - shell->workspaces.anim_current) *
+ DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH *
+ M_2_PI));
}
 
-   t = msecs - shell->workspaces.anim_timestamp;
+   t = timespec_sub_to_msec(time, &shell->workspaces.anim_timestamp);
 
/*
 * x = [0, π/2]
@@ -1154,7 +1156,7 @@ animate_workspace_change(struct desktop_shell *shell,
shell->workspaces.anim_from = from;
shell->workspaces.anim_to = to;
shell->workspaces.anim_current = 0.0;
-   shell->workspaces.anim_timestamp = 0;
+   shell->workspaces.anim_timestamp = (struct timespec) { 0 };
 
output = container_of(shell->compositor->output_list.next,
  struct weston_output, link);
diff --git a/desktop-shell/shell.h b/desktop-shell/shell.h
index 063641d2..0ff737bb 100644
--- a/desktop-shell/shell.h
+++ b/desktop-shell/shell.h
@@ -188,7 +188,7 @@ struct desktop_shell {
struct weston_animation animation;
struct wl_list anim_sticky_list;
int anim_dir;
-   uint32_t anim_timestamp;
+   struct timespec anim_timestamp;
double anim_current;
struct workspace *anim_from;
struct workspace *anim_to;
diff --git a/libweston/animation.c b/libweston/animation.c
index 914135a2..c2f8b9ba 100644
--- a/libweston/animation.c
+++ b/libweston/animation.c
@@ -30,12 +30,14 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
 

[PATCH weston 08/12] libweston: Use struct timespec for key events

2017-11-16 Thread Alexandros Frantzis
Change code related to key events to use struct timespec to represent
time.

This commit is part of a larger effort to transition the Weston codebase
to struct timespec.

Signed-off-by: Alexandros Frantzis 
---
 compositor/screen-share.c |  8 ---
 compositor/text-backend.c | 13 +---
 compositor/weston-screenshooter.c |  6 +++---
 desktop-shell/exposay.c   |  4 ++--
 desktop-shell/shell.c | 44 +++
 ivi-shell/ivi-shell.c |  2 +-
 libweston-desktop/seat.c  |  3 ++-
 libweston/bindings.c  | 24 +
 libweston/compositor-drm.c| 16 +++---
 libweston/compositor-rdp.c|  4 +++-
 libweston/compositor-wayland.c|  9 +---
 libweston/compositor-x11.c| 14 +
 libweston/compositor.c|  5 +++--
 libweston/compositor.h| 18 +---
 libweston/data-device.c   |  2 +-
 libweston/gl-renderer.c   |  6 --
 libweston/input.c | 13 +++-
 libweston/launcher-util.c |  2 +-
 libweston/libinput-device.c   |  7 +--
 libweston/pixman-renderer.c   |  4 ++--
 tests/surface-screenshot.c|  4 ++--
 tests/weston-test.c   |  5 -
 22 files changed, 126 insertions(+), 87 deletions(-)

diff --git a/compositor/screen-share.c b/compositor/screen-share.c
index 8b2decfd..33de2b1f 100644
--- a/compositor/screen-share.c
+++ b/compositor/screen-share.c
@@ -277,9 +277,11 @@ ss_seat_handle_key(void *data, struct wl_keyboard 
*keyboard,
   uint32_t key, uint32_t state)
 {
struct ss_seat *seat = data;
+   struct timespec ts;
 
+   timespec_from_msec(&ts, time);
seat->key_serial = serial;
-   notify_key(&seat->base, time, key,
+   notify_key(&seat->base, &ts, key,
   state ? WL_KEYBOARD_KEY_STATE_PRESSED :
   WL_KEYBOARD_KEY_STATE_RELEASED,
   seat->keyboard_state_update);
@@ -1092,8 +1094,8 @@ weston_output_find(struct weston_compositor *c, int32_t 
x, int32_t y)
 }
 
 static void
-share_output_binding(struct weston_keyboard *keyboard, uint32_t time, uint32_t 
key,
-void *data)
+share_output_binding(struct weston_keyboard *keyboard,
+const struct timespec *time, uint32_t key, void *data)
 {
struct weston_output *output;
struct weston_pointer *pointer;
diff --git a/compositor/text-backend.c b/compositor/text-backend.c
index bf5c45cc..5f6b5d80 100644
--- a/compositor/text-backend.c
+++ b/compositor/text-backend.c
@@ -38,6 +38,7 @@
 #include "text-input-unstable-v1-server-protocol.h"
 #include "input-method-unstable-v1-server-protocol.h"
 #include "shared/helpers.h"
+#include "shared/timespec-util.h"
 
 struct text_input_manager;
 struct input_method;
@@ -607,11 +608,13 @@ unbind_keyboard(struct wl_resource *resource)
 
 static void
 input_method_context_grab_key(struct weston_keyboard_grab *grab,
- uint32_t time, uint32_t key, uint32_t state_w)
+ const struct timespec *time, uint32_t key,
+ uint32_t state_w)
 {
struct weston_keyboard *keyboard = grab->keyboard;
struct wl_display *display;
uint32_t serial;
+   uint32_t msecs;
 
if (!keyboard->input_method_resource)
return;
@@ -619,8 +622,9 @@ input_method_context_grab_key(struct weston_keyboard_grab 
*grab,
display = wl_client_get_display(
wl_resource_get_client(keyboard->input_method_resource));
serial = wl_display_next_serial(display);
+   msecs = timespec_to_msec(time);
wl_keyboard_send_key(keyboard->input_method_resource,
-serial, time, key, state_w);
+serial, msecs, key, state_w);
 }
 
 static void
@@ -693,8 +697,11 @@ input_method_context_key(struct wl_client *client,
struct weston_seat *seat = context->input_method->seat;
struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat);
struct weston_keyboard_grab *default_grab = &keyboard->default_grab;
+   struct timespec ts;
 
-   default_grab->interface->key(default_grab, time, key, state_w);
+   timespec_from_msec(&ts, time);
+
+   default_grab->interface->key(default_grab, &ts, key, state_w);
 }
 
 static void
diff --git a/compositor/weston-screenshooter.c 
b/compositor/weston-screenshooter.c
index f874c3eb..f0bc0e1e 100644
--- a/compositor/weston-screenshooter.c
+++ b/compositor/weston-screenshooter.c
@@ -112,8 +112,8 @@ screenshooter_sigchld(struct weston_process *process, int 
status)
 }
 
 static void
-screenshooter_binding(struct weston_keyboard *keyboard, uint32_t time,
- uint32_t key,

[PATCH weston 10/12] libweston: Use struct timespec for touch up events

2017-11-16 Thread Alexandros Frantzis
Change code related to touch up events to use struct timespec to represent
time.

This commit is part of a larger effort to transition the Weston codebase
to struct timespec.

Signed-off-by: Alexandros Frantzis 
---
 desktop-shell/shell.c  |  3 ++-
 ivi-shell/hmi-controller.c |  3 ++-
 libweston-desktop/seat.c   |  3 ++-
 libweston/compositor.h |  5 +++--
 libweston/data-device.c|  2 +-
 libweston/input.c  | 11 +++
 6 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c
index 30cffed1..5823a481 100644
--- a/desktop-shell/shell.c
+++ b/desktop-shell/shell.c
@@ -1338,7 +1338,8 @@ touch_move_grab_down(struct weston_touch_grab *grab,
 }
 
 static void
-touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id)
+touch_move_grab_up(struct weston_touch_grab *grab, const struct timespec *time,
+  int touch_id)
 {
struct weston_touch_move_grab *move =
(struct weston_touch_move_grab *) container_of(
diff --git a/ivi-shell/hmi-controller.c b/ivi-shell/hmi-controller.c
index 9b99668c..f9500ef5 100644
--- a/ivi-shell/hmi-controller.c
+++ b/ivi-shell/hmi-controller.c
@@ -1591,7 +1591,8 @@ touch_nope_grab_down(struct weston_touch_grab *grab,
 }
 
 static void
-touch_move_workspace_grab_up(struct weston_touch_grab *grab, uint32_t time,
+touch_move_workspace_grab_up(struct weston_touch_grab *grab,
+const struct timespec *time,
 int touch_id)
 {
struct touch_move_grab *tch_move_grab = (struct touch_move_grab *)grab;
diff --git a/libweston-desktop/seat.c b/libweston-desktop/seat.c
index 3e044fe1..e160fd18 100644
--- a/libweston-desktop/seat.c
+++ b/libweston-desktop/seat.c
@@ -189,7 +189,8 @@ weston_desktop_seat_popup_grab_touch_down(struct 
weston_touch_grab *grab,
 
 static void
 weston_desktop_seat_popup_grab_touch_up(struct weston_touch_grab *grab,
-   uint32_t time, int touch_id)
+   const struct timespec *time,
+   int touch_id)
 {
weston_touch_send_up(grab->touch, time, touch_id);
 }
diff --git a/libweston/compositor.h b/libweston/compositor.h
index 9aadd83f..40d192ee 100644
--- a/libweston/compositor.h
+++ b/libweston/compositor.h
@@ -310,7 +310,7 @@ struct weston_touch_grab_interface {
wl_fixed_t sx,
wl_fixed_t sy);
void (*up)(struct weston_touch_grab *grab,
-   uint32_t time,
+   const struct timespec *time,
int touch_id);
void (*motion)(struct weston_touch_grab *grab,
uint32_t time,
@@ -519,7 +519,8 @@ void
 weston_touch_send_down(struct weston_touch *touch, const struct timespec *time,
   int touch_id, wl_fixed_t x, wl_fixed_t y);
 void
-weston_touch_send_up(struct weston_touch *touch, uint32_t time, int touch_id);
+weston_touch_send_up(struct weston_touch *touch, const struct timespec *time,
+int touch_id);
 void
 weston_touch_send_motion(struct weston_touch *touch, uint32_t time,
 int touch_id, wl_fixed_t x, wl_fixed_t y);
diff --git a/libweston/data-device.c b/libweston/data-device.c
index 1c7d546c..5821386e 100644
--- a/libweston/data-device.c
+++ b/libweston/data-device.c
@@ -738,7 +738,7 @@ data_device_end_touch_drag_grab(struct weston_touch_drag 
*drag)
 
 static void
 drag_grab_touch_up(struct weston_touch_grab *grab,
-   uint32_t time, int touch_id)
+  const struct timespec *time, int touch_id)
 {
struct weston_touch_drag *touch_drag =
container_of(grab, struct weston_touch_drag, grab);
diff --git a/libweston/input.c b/libweston/input.c
index 73334bf8..996c00f7 100644
--- a/libweston/input.c
+++ b/libweston/input.c
@@ -713,25 +713,28 @@ default_grab_touch_down(struct weston_touch_grab *grab,
  * resources of the client which currently has the surface with touch focus.
  */
 WL_EXPORT void
-weston_touch_send_up(struct weston_touch *touch, uint32_t time, int touch_id)
+weston_touch_send_up(struct weston_touch *touch, const struct timespec *time,
+int touch_id)
 {
struct wl_display *display = touch->seat->compositor->wl_display;
uint32_t serial;
struct wl_resource *resource;
struct wl_list *resource_list;
+   uint32_t msecs;
 
if (!weston_touch_has_focus_resource(touch))
return;
 
resource_list = &touch->focus_resource_list;
serial = wl_display_next_serial(display);
+   msecs = timespec_to_msec(time);
wl_resource_for_each(resource, resource_list)
-   wl_touch_send_up(resource, serial, time, touch_id);
+   wl_touch_send_up(resource, serial, msecs, touch_id)

[PATCH weston 07/12] libweston: Use struct timespec for axis events

2017-11-16 Thread Alexandros Frantzis
Change code related to axis events to use struct timespec to represent
time.

This commit is part of a larger effort to transition the Weston codebase
to struct timespec.

Signed-off-by: Alexandros Frantzis 
---
 compositor/screen-share.c  |  5 -
 desktop-shell/exposay.c|  3 ++-
 desktop-shell/shell.c  | 18 --
 ivi-shell/hmi-controller.c |  2 +-
 libweston-desktop/seat.c   |  2 +-
 libweston/bindings.c   |  2 +-
 libweston/compositor-rdp.c |  5 +++--
 libweston/compositor-wayland.c | 10 --
 libweston/compositor-x11.c | 20 
 libweston/compositor.h | 11 ++-
 libweston/data-device.c|  3 ++-
 libweston/input.c  | 16 +---
 libweston/libinput-device.c| 12 ++--
 13 files changed, 63 insertions(+), 46 deletions(-)

diff --git a/compositor/screen-share.c b/compositor/screen-share.c
index 368d0cd6..8b2decfd 100644
--- a/compositor/screen-share.c
+++ b/compositor/screen-share.c
@@ -173,12 +173,15 @@ ss_seat_handle_axis(void *data, struct wl_pointer 
*pointer,
 {
struct ss_seat *seat = data;
struct weston_pointer_axis_event weston_event;
+   struct timespec ts;
 
weston_event.axis = axis;
weston_event.value = wl_fixed_to_double(value);
weston_event.has_discrete = false;
 
-   notify_axis(&seat->base, time, &weston_event);
+   timespec_from_msec(&ts, time);
+
+   notify_axis(&seat->base, &ts, &weston_event);
notify_pointer_frame(&seat->base);
 }
 
diff --git a/desktop-shell/exposay.c b/desktop-shell/exposay.c
index 3571c5d7..5b23adf7 100644
--- a/desktop-shell/exposay.c
+++ b/desktop-shell/exposay.c
@@ -390,7 +390,8 @@ exposay_button(struct weston_pointer_grab *grab, const 
struct timespec *time,
 
 static void
 exposay_axis(struct weston_pointer_grab *grab,
-uint32_t time, struct weston_pointer_axis_event *event)
+const struct timespec *time,
+struct weston_pointer_axis_event *event)
 {
 }
 
diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c
index 2d2a6c8b..5f6c6d19 100644
--- a/desktop-shell/shell.c
+++ b/desktop-shell/shell.c
@@ -1431,7 +1431,8 @@ noop_grab_focus(struct weston_pointer_grab *grab)
 
 static void
 noop_grab_axis(struct weston_pointer_grab *grab,
-  uint32_t time, struct weston_pointer_axis_event *event)
+  const struct timespec *time,
+  struct weston_pointer_axis_event *event)
 {
 }
 
@@ -3344,7 +3345,8 @@ resize_binding(struct weston_pointer *pointer, const 
struct timespec *time,
 }
 
 static void
-surface_opacity_binding(struct weston_pointer *pointer, uint32_t time,
+surface_opacity_binding(struct weston_pointer *pointer,
+   const struct timespec *time,
struct weston_pointer_axis_event *event,
void *data)
 {
@@ -3374,8 +3376,8 @@ surface_opacity_binding(struct weston_pointer *pointer, 
uint32_t time,
 }
 
 static void
-do_zoom(struct weston_seat *seat, uint32_t time, uint32_t key, uint32_t axis,
-   double value)
+do_zoom(struct weston_seat *seat, const struct timespec *time, uint32_t key,
+   uint32_t axis, double value)
 {
struct weston_compositor *compositor = seat->compositor;
struct weston_pointer *pointer = weston_seat_get_pointer(seat);
@@ -3424,7 +3426,7 @@ do_zoom(struct weston_seat *seat, uint32_t time, uint32_t 
key, uint32_t axis,
 }
 
 static void
-zoom_axis_binding(struct weston_pointer *pointer, uint32_t time,
+zoom_axis_binding(struct weston_pointer *pointer, const struct timespec *time,
  struct weston_pointer_axis_event *event,
  void *data)
 {
@@ -3435,7 +3437,11 @@ static void
 zoom_key_binding(struct weston_keyboard *keyboard, uint32_t time,
 uint32_t key, void *data)
 {
-   do_zoom(keyboard->seat, time, key, 0, 0);
+   struct timespec ts;
+
+   timespec_from_msec(&ts, time);
+
+   do_zoom(keyboard->seat, &ts, key, 0, 0);
 }
 
 static void
diff --git a/ivi-shell/hmi-controller.c b/ivi-shell/hmi-controller.c
index b91b7f2b..d61e26b5 100644
--- a/ivi-shell/hmi-controller.c
+++ b/ivi-shell/hmi-controller.c
@@ -1461,7 +1461,7 @@ pointer_noop_grab_focus(struct weston_pointer_grab *grab)
 
 static void
 pointer_default_grab_axis(struct weston_pointer_grab *grab,
- uint32_t time,
+ const struct timespec *time,
  struct weston_pointer_axis_event *event)
 {
weston_pointer_send_axis(grab->pointer, time, event);
diff --git a/libweston-desktop/seat.c b/libweston-desktop/seat.c
index 2c62f4fd..150229f8 100644
--- a/libweston-desktop/seat.c
+++ b/libweston-desktop/seat.c
@@ -139,7 +139,7 @@ weston_desktop_seat_popup_grab_pointer_button(struct 
weston_pointer_grab *grab,
 
 static void
 weston_desktop_seat

[PATCH weston 06/12] libweston: Use struct timespec for button events

2017-11-16 Thread Alexandros Frantzis
Change code related to button events to use struct timespec to represent
time.

This commit is part of a larger effort to transition the Weston codebase
to struct timespec.

Signed-off-by: Alexandros Frantzis 
---
 compositor/screen-share.c  |  5 -
 desktop-shell/exposay.c|  4 ++--
 desktop-shell/shell.c  | 22 +-
 ivi-shell/hmi-controller.c |  2 +-
 ivi-shell/ivi-shell.c  |  3 ++-
 libweston-desktop/seat.c   |  7 +--
 libweston/bindings.c   |  3 ++-
 libweston/compositor-rdp.c |  3 ++-
 libweston/compositor-wayland.c |  4 +++-
 libweston/compositor-x11.c |  6 --
 libweston/compositor.h | 18 +++---
 libweston/data-device.c|  3 ++-
 libweston/input.c  | 18 ++
 libweston/libinput-device.c|  7 +--
 tests/weston-test.c|  6 +-
 15 files changed, 71 insertions(+), 40 deletions(-)

diff --git a/compositor/screen-share.c b/compositor/screen-share.c
index c7aad313..368d0cd6 100644
--- a/compositor/screen-share.c
+++ b/compositor/screen-share.c
@@ -159,8 +159,11 @@ ss_seat_handle_button(void *data, struct wl_pointer 
*pointer,
  uint32_t state)
 {
struct ss_seat *seat = data;
+   struct timespec ts;
+
+   timespec_from_msec(&ts, time);
 
-   notify_button(&seat->base, time, button, state);
+   notify_button(&seat->base, &ts, button, state);
notify_pointer_frame(&seat->base);
 }
 
diff --git a/desktop-shell/exposay.c b/desktop-shell/exposay.c
index 15b86863..3571c5d7 100644
--- a/desktop-shell/exposay.c
+++ b/desktop-shell/exposay.c
@@ -364,8 +364,8 @@ exposay_motion(struct weston_pointer_grab *grab,
 }
 
 static void
-exposay_button(struct weston_pointer_grab *grab, uint32_t time, uint32_t 
button,
-   uint32_t state_w)
+exposay_button(struct weston_pointer_grab *grab, const struct timespec *time,
+  uint32_t button, uint32_t state_w)
 {
struct desktop_shell *shell =
container_of(grab, struct desktop_shell, exposay.grab_ptr);
diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c
index 62dfa450..2d2a6c8b 100644
--- a/desktop-shell/shell.c
+++ b/desktop-shell/shell.c
@@ -1507,7 +1507,7 @@ move_grab_motion(struct weston_pointer_grab *grab,
 
 static void
 move_grab_button(struct weston_pointer_grab *grab,
-uint32_t time, uint32_t button, uint32_t state_w)
+const struct timespec *time, uint32_t button, uint32_t state_w)
 {
struct shell_grab *shell_grab = container_of(grab, struct shell_grab,
grab);
@@ -1634,7 +1634,8 @@ resize_grab_motion(struct weston_pointer_grab *grab,
 
 static void
 resize_grab_button(struct weston_pointer_grab *grab,
-  uint32_t time, uint32_t button, uint32_t state_w)
+  const struct timespec *time,
+  uint32_t button, uint32_t state_w)
 {
struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
struct weston_pointer *pointer = grab->pointer;
@@ -1778,7 +1779,8 @@ busy_cursor_grab_motion(struct weston_pointer_grab *grab,
 
 static void
 busy_cursor_grab_button(struct weston_pointer_grab *base,
-   uint32_t time, uint32_t button, uint32_t state)
+   const struct timespec *time,
+   uint32_t button, uint32_t state)
 {
struct shell_grab *grab = (struct shell_grab *) base;
struct shell_surface *shsurf = grab->shsurf;
@@ -3203,7 +3205,7 @@ static const struct weston_desktop_shell_interface 
desktop_shell_implementation
 };
 
 static void
-move_binding(struct weston_pointer *pointer, uint32_t time,
+move_binding(struct weston_pointer *pointer, const struct timespec *time,
 uint32_t button, void *data)
 {
struct weston_surface *focus;
@@ -3295,7 +3297,7 @@ touch_move_binding(struct weston_touch *touch, uint32_t 
time, void *data)
 }
 
 static void
-resize_binding(struct weston_pointer *pointer, uint32_t time,
+resize_binding(struct weston_pointer *pointer, const struct timespec *time,
   uint32_t button, void *data)
 {
struct weston_surface *focus;
@@ -3515,7 +3517,8 @@ rotate_grab_motion(struct weston_pointer_grab *grab,
 
 static void
 rotate_grab_button(struct weston_pointer_grab *grab,
-  uint32_t time, uint32_t button, uint32_t state_w)
+  const struct timespec *time,
+  uint32_t button, uint32_t state_w)
 {
struct rotate_grab *rotate =
container_of(grab, struct rotate_grab, base.grab);
@@ -3593,8 +3596,8 @@ surface_rotate(struct shell_surface *shsurf, struct 
weston_pointer *pointer)
 }
 
 static void
-rotate_binding(struct weston_pointer *pointer, uint32_t time, uint32_t button,
-  void *data)
+rotate_binding(struct weston_pointer *p

[PATCH weston 09/12] libweston: Use struct timespec for touch down events

2017-11-16 Thread Alexandros Frantzis
Change code related to touch down events to use struct timespec to
represent time.

This commit is part of a larger effort to transition the Weston codebase
to struct timespec.

Signed-off-by: Alexandros Frantzis 
---
 desktop-shell/shell.c  |  8 +---
 ivi-shell/hmi-controller.c |  3 ++-
 ivi-shell/ivi-shell.c  |  3 ++-
 libweston-desktop/seat.c   |  3 ++-
 libweston/bindings.c   |  3 ++-
 libweston/compositor-wayland.c | 14 +++---
 libweston/compositor.h | 15 ---
 libweston/data-device.c|  5 +++--
 libweston/input.c  | 22 +-
 libweston/libinput-device.c| 14 +-
 10 files changed, 57 insertions(+), 33 deletions(-)

diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c
index b8f00eb1..30cffed1 100644
--- a/desktop-shell/shell.c
+++ b/desktop-shell/shell.c
@@ -1331,7 +1331,8 @@ take_surface_to_workspace_by_seat(struct desktop_shell 
*shell,
 }
 
 static void
-touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time,
+touch_move_grab_down(struct weston_touch_grab *grab,
+const struct timespec *time,
 int touch_id, wl_fixed_t x, wl_fixed_t y)
 {
 }
@@ -3274,7 +3275,7 @@ fullscreen_binding(struct weston_keyboard *keyboard,
 }
 
 static void
-touch_move_binding(struct weston_touch *touch, uint32_t time, void *data)
+touch_move_binding(struct weston_touch *touch, const struct timespec *time, 
void *data)
 {
struct weston_surface *focus;
struct weston_surface *surface;
@@ -3774,7 +3775,8 @@ click_to_activate_binding(struct weston_pointer *pointer,
 }
 
 static void
-touch_to_activate_binding(struct weston_touch *touch, uint32_t time,
+touch_to_activate_binding(struct weston_touch *touch,
+ const struct timespec *time,
  void *data)
 {
if (touch->grab != &touch->default_grab)
diff --git a/ivi-shell/hmi-controller.c b/ivi-shell/hmi-controller.c
index d61e26b5..9b99668c 100644
--- a/ivi-shell/hmi-controller.c
+++ b/ivi-shell/hmi-controller.c
@@ -1584,7 +1584,8 @@ pointer_move_workspace_grab_button(struct 
weston_pointer_grab *grab,
 }
 
 static void
-touch_nope_grab_down(struct weston_touch_grab *grab, uint32_t time,
+touch_nope_grab_down(struct weston_touch_grab *grab,
+const struct timespec *time,
 int touch_id, wl_fixed_t sx, wl_fixed_t sy)
 {
 }
diff --git a/ivi-shell/ivi-shell.c b/ivi-shell/ivi-shell.c
index e675a3bd..766a1fd1 100644
--- a/ivi-shell/ivi-shell.c
+++ b/ivi-shell/ivi-shell.c
@@ -463,7 +463,8 @@ click_to_activate_binding(struct weston_pointer *pointer,
 }
 
 static void
-touch_to_activate_binding(struct weston_touch *touch, uint32_t time,
+touch_to_activate_binding(struct weston_touch *touch,
+ const struct timespec *time,
  void *data)
 {
if (touch->grab != &touch->default_grab)
diff --git a/libweston-desktop/seat.c b/libweston-desktop/seat.c
index bba2605f..3e044fe1 100644
--- a/libweston-desktop/seat.c
+++ b/libweston-desktop/seat.c
@@ -180,7 +180,8 @@ static const struct weston_pointer_grab_interface 
weston_desktop_seat_pointer_po
 
 static void
 weston_desktop_seat_popup_grab_touch_down(struct weston_touch_grab *grab,
- uint32_t time, int touch_id,
+ const struct timespec *time,
+ int touch_id,
  wl_fixed_t sx, wl_fixed_t sy)
 {
weston_touch_send_down(grab->touch, time, touch_id, sx, sy);
diff --git a/libweston/bindings.c b/libweston/bindings.c
index 79c043e9..d9e280e4 100644
--- a/libweston/bindings.c
+++ b/libweston/bindings.c
@@ -377,7 +377,8 @@ weston_compositor_run_button_binding(struct 
weston_compositor *compositor,
 
 void
 weston_compositor_run_touch_binding(struct weston_compositor *compositor,
-   struct weston_touch *touch, uint32_t time,
+   struct weston_touch *touch,
+   const struct timespec *time,
int touch_type)
 {
struct weston_binding *b, *tmp;
diff --git a/libweston/compositor-wayland.c b/libweston/compositor-wayland.c
index 7b96b7be..3bdfb03e 100644
--- a/libweston/compositor-wayland.c
+++ b/libweston/compositor-wayland.c
@@ -1974,10 +1974,13 @@ input_handle_touch_down(void *data, struct wl_touch 
*wl_touch,
bool first_touch;
int32_t fx, fy;
double x, y;
+   struct timespec ts;
 
x = wl_fixed_to_double(fixed_x);
y = wl_fixed_to_double(fixed_y);
 
+   timespec_from_msec(&ts, time);
+
first_touch = (input->touch_points == 0);
input->touch_points++;
 
@@ -2015,7 +2018,7 @@ input_handle_touch_down(void 

[PATCH weston 12/12] libweston: Use struct timespec for compositor time

2017-11-16 Thread Alexandros Frantzis
Change weston_compositor_get_time to return the current compositor time
as a struct timespec. Also, use clock_gettime (with CLOCK_REALTIME) to
get the time, since it's equivalent to the currently used gettimeofday
call, but returns the data directly in a struct timespec.

This commit is part of a larger effort to transition the Weston codebase
to struct timespec.

Signed-off-by: Alexandros Frantzis 
---
 compositor/text-backend.c  | 11 +++
 desktop-shell/shell.c  |  8 
 desktop-shell/shell.h  |  2 +-
 libweston/compositor-rdp.c | 10 +-
 libweston/compositor-x11.c | 21 ++---
 libweston/compositor.c | 10 +++---
 libweston/compositor.h |  4 ++--
 7 files changed, 32 insertions(+), 34 deletions(-)

diff --git a/compositor/text-backend.c b/compositor/text-backend.c
index 5f6b5d80..e10f9576 100644
--- a/compositor/text-backend.c
+++ b/compositor/text-backend.c
@@ -106,7 +106,7 @@ struct text_backend {
struct wl_client *client;
 
unsigned deathcount;
-   uint32_t deathstamp;
+   struct timespec deathstamp;
} input_method;
 
struct wl_listener client_listener;
@@ -938,11 +938,14 @@ static void launch_input_method(struct text_backend 
*text_backend);
 static void
 respawn_input_method_process(struct text_backend *text_backend)
 {
-   uint32_t time;
+   struct timespec time;
+   int64_t tdiff;
 
/* if input_method dies more than 5 times in 10 seconds, give up */
-   time = weston_compositor_get_time();
-   if (time - text_backend->input_method.deathstamp > 1) {
+   weston_compositor_get_time(&time);
+   tdiff = timespec_sub_to_msec(&time,
+&text_backend->input_method.deathstamp);
+   if (tdiff > 1) {
text_backend->input_method.deathstamp = time;
text_backend->input_method.deathcount = 0;
}
diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c
index 564cbb58..a0070a04 100644
--- a/desktop-shell/shell.c
+++ b/desktop-shell/shell.c
@@ -4209,11 +4209,11 @@ static void launch_desktop_shell_process(void *data);
 static void
 respawn_desktop_shell_process(struct desktop_shell *shell)
 {
-   uint32_t time;
+   struct timespec time;
 
/* if desktop-shell dies more than 5 times in 30 seconds, give up */
-   time = weston_compositor_get_time();
-   if (time - shell->child.deathstamp > 3) {
+   weston_compositor_get_time(&time);
+   if (timespec_sub_to_msec(&time, &shell->child.deathstamp) > 3) {
shell->child.deathstamp = time;
shell->child.deathcount = 0;
}
@@ -5043,7 +5043,7 @@ wet_shell_init(struct weston_compositor *ec,
 shell, bind_desktop_shell) == NULL)
return -1;
 
-   shell->child.deathstamp = weston_compositor_get_time();
+   weston_compositor_get_time(&shell->child.deathstamp);
 
shell->panel_position = WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP;
 
diff --git a/desktop-shell/shell.h b/desktop-shell/shell.h
index 0ff737bb..fb8c2bf0 100644
--- a/desktop-shell/shell.h
+++ b/desktop-shell/shell.h
@@ -161,7 +161,7 @@ struct desktop_shell {
struct wl_listener client_destroy_listener;
 
unsigned deathcount;
-   uint32_t deathstamp;
+   struct timespec deathstamp;
} child;
 
bool locked;
diff --git a/libweston/compositor-rdp.c b/libweston/compositor-rdp.c
index 5cc56457..02535d16 100644
--- a/libweston/compositor-rdp.c
+++ b/libweston/compositor-rdp.c
@@ -1035,7 +1035,7 @@ xf_mouseEvent(rdpInput *input, UINT16 flags, UINT16 x, 
UINT16 y)
if (flags & PTR_FLAGS_MOVE) {
output = peerContext->rdpBackend->output;
if (x < output->base.width && y < output->base.height) {
-   timespec_from_msec(&time, weston_compositor_get_time());
+   weston_compositor_get_time(&time);
notify_motion_absolute(peerContext->item.seat, &time,
x, y);
need_frame = true;
@@ -1050,7 +1050,7 @@ xf_mouseEvent(rdpInput *input, UINT16 flags, UINT16 x, 
UINT16 y)
button = BTN_MIDDLE;
 
if (button) {
-   timespec_from_msec(&time, weston_compositor_get_time());
+   weston_compositor_get_time(&time);
notify_button(peerContext->item.seat, &time, button,
(flags & PTR_FLAGS_DOWN) ? 
WL_POINTER_BUTTON_STATE_PRESSED : WL_POINTER_BUTTON_STATE_RELEASED
);
@@ -1076,7 +1076,7 @@ xf_mouseEvent(rdpInput *input, UINT16 flags, UINT16 x, 
UINT16 y)
weston_event.d

[PATCH weston 11/12] libweston: Use struct timespec for touch motion events

2017-11-16 Thread Alexandros Frantzis
Change code related to touch motion events to use struct timespec to
represent time.

This commit is part of a larger effort to transition the Weston codebase
to struct timespec.

Signed-off-by: Alexandros Frantzis 
---
 desktop-shell/shell.c  |  5 +++--
 ivi-shell/hmi-controller.c |  5 +++--
 libweston-desktop/seat.c   |  3 ++-
 libweston/compositor.h |  7 ---
 libweston/data-device.c| 11 +++
 libweston/input.c  | 17 ++---
 6 files changed, 29 insertions(+), 19 deletions(-)

diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c
index 5823a481..564cbb58 100644
--- a/desktop-shell/shell.c
+++ b/desktop-shell/shell.c
@@ -1355,8 +1355,9 @@ touch_move_grab_up(struct weston_touch_grab *grab, const 
struct timespec *time,
 }
 
 static void
-touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time,
-  int touch_id, wl_fixed_t x, wl_fixed_t y)
+touch_move_grab_motion(struct weston_touch_grab *grab,
+  const struct timespec *time, int touch_id,
+  wl_fixed_t x, wl_fixed_t y)
 {
struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) 
grab;
struct shell_surface *shsurf = move->base.shsurf;
diff --git a/ivi-shell/hmi-controller.c b/ivi-shell/hmi-controller.c
index f9500ef5..5a2ff78c 100644
--- a/ivi-shell/hmi-controller.c
+++ b/ivi-shell/hmi-controller.c
@@ -1551,8 +1551,9 @@ pointer_move_grab_motion(struct weston_pointer_grab *grab,
 }
 
 static void
-touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time,
-  int touch_id, wl_fixed_t x, wl_fixed_t y)
+touch_move_grab_motion(struct weston_touch_grab *grab,
+  const struct timespec *time, int touch_id,
+  wl_fixed_t x, wl_fixed_t y)
 {
struct touch_move_grab *tch_move_grab = (struct touch_move_grab *)grab;
 
diff --git a/libweston-desktop/seat.c b/libweston-desktop/seat.c
index e160fd18..382b9e41 100644
--- a/libweston-desktop/seat.c
+++ b/libweston-desktop/seat.c
@@ -197,7 +197,8 @@ weston_desktop_seat_popup_grab_touch_up(struct 
weston_touch_grab *grab,
 
 static void
 weston_desktop_seat_popup_grab_touch_motion(struct weston_touch_grab *grab,
-   uint32_t time, int touch_id,
+   const struct timespec *time,
+   int touch_id,
wl_fixed_t sx, wl_fixed_t sy)
 {
weston_touch_send_motion(grab->touch, time, touch_id, sx, sy);
diff --git a/libweston/compositor.h b/libweston/compositor.h
index 40d192ee..5eff0262 100644
--- a/libweston/compositor.h
+++ b/libweston/compositor.h
@@ -313,7 +313,7 @@ struct weston_touch_grab_interface {
const struct timespec *time,
int touch_id);
void (*motion)(struct weston_touch_grab *grab,
-   uint32_t time,
+   const struct timespec *time,
int touch_id,
wl_fixed_t sx,
wl_fixed_t sy);
@@ -522,8 +522,9 @@ void
 weston_touch_send_up(struct weston_touch *touch, const struct timespec *time,
 int touch_id);
 void
-weston_touch_send_motion(struct weston_touch *touch, uint32_t time,
-int touch_id, wl_fixed_t x, wl_fixed_t y);
+weston_touch_send_motion(struct weston_touch *touch,
+const struct timespec *time, int touch_id,
+wl_fixed_t x, wl_fixed_t y);
 void
 weston_touch_send_frame(struct weston_touch *touch);
 
diff --git a/libweston/data-device.c b/libweston/data-device.c
index 5821386e..b4bb4b37 100644
--- a/libweston/data-device.c
+++ b/libweston/data-device.c
@@ -770,14 +770,16 @@ drag_grab_touch_focus(struct weston_touch_drag *drag)
 }
 
 static void
-drag_grab_touch_motion(struct weston_touch_grab *grab, uint32_t time,
-   int touch_id, wl_fixed_t x, wl_fixed_t y)
+drag_grab_touch_motion(struct weston_touch_grab *grab,
+  const struct timespec *time,
+  int touch_id, wl_fixed_t x, wl_fixed_t y)
 {
struct weston_touch_drag *touch_drag =
container_of(grab, struct weston_touch_drag, grab);
struct weston_touch *touch = grab->touch;
wl_fixed_t view_x, view_y;
float fx, fy;
+   uint32_t msecs;
 
if (touch_id != touch->grab_touch_id)
return;
@@ -791,11 +793,12 @@ drag_grab_touch_motion(struct weston_touch_grab *grab, 
uint32_t time,
}
 
if (touch_drag->base.focus_resource) {
+   msecs = timespec_to_msec(time);
weston_view_from_global_fixed(touch_drag->base.focus,
touch->grab_x, touch->grab_y,

[PATCH weston] ivi-shell: Fix incorrect use of logical instead of bitwise operator

2017-11-17 Thread Alexandros Frantzis
Fix the code to use the correct bitwise AND operator '&', instead of the
currently used logical AND operator '&&', to check the value of a bit
flag in a bit mask.

This problem was reported as a warning when building with clang.
---
 ivi-shell/ivi-layout.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ivi-shell/ivi-layout.c b/ivi-shell/ivi-layout.c
index 87adde32..394179b8 100644
--- a/ivi-shell/ivi-layout.c
+++ b/ivi-shell/ivi-layout.c
@@ -617,7 +617,7 @@ commit_changes(struct ivi_layout *layout)
* the weston_view below this ivi_view. Otherwise content
* of this ivi_view will stay visible.
*/
-   if ((ivilayer->prop.event_mask | 
ivisurf->prop.event_mask) &&
+   if ((ivilayer->prop.event_mask | 
ivisurf->prop.event_mask) &
IVI_NOTIFICATION_VISIBILITY)
weston_view_damage_below(ivi_view->view);
 
-- 
2.14.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[RFC wayland] protocol: Add high-resolution wl_touch timestamp event

2017-11-21 Thread Alexandros Frantzis
wl_touch events currently use a 32-bit timestamp with millisecond
resolution. In some cases, notably latency measurements, this resolution
is too coarse-grained to be useful.

This protocol update adds a wl_touch.timestamp event, which is emitted
just before an up, motion or down touch event. The timestamp event
contains a high-resolution, and ideally higher-accuracy, version of the
'time' argument of the up/motion/down event that follows.

From a client implementation perspective clients can just ignore this event if
they don't care about the improved resolution. Clients that care just need to
keep track of the last timestamp event they receive and associate it with the
next up/motion/down event that arrives.

Some points for discussion:

1. Should there be a request to explicitly enable/disable the timestamp event
   (to reduce extra event overhead when improved timestamps are not needed)?

2. Should we introduce similar timestamp events for keyboard and pointer?

3. Should this be a separate protocol instead of a core update (being separate
   would also take care of point (1))?

A proof of concept implementation for weston can be found at:

https://git.collabora.com/cgit/user/alf/weston.git/log/?h=wl-touch-v7

Note that the weston implementation depends on a patchset that changes weston
to use higher resolution timestamps internally. The patchset been submitted
for review at:

https://lists.freedesktop.org/archives/wayland-devel/2017-November/035851.html

Signed-off-by: Alexandros Frantzis 
---
 protocol/wayland.xml | 27 +++
 1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/protocol/wayland.xml b/protocol/wayland.xml
index aabc7ae..b01811e 100644
--- a/protocol/wayland.xml
+++ b/protocol/wayland.xml
@@ -1657,7 +1657,7 @@
 

 
-  
+  
 
   A seat is a group of keyboards, pointer and touch devices. This
   object is published as a global during start up, or when such a
@@ -1766,7 +1766,7 @@
 
   
 
-  
+  
 
   The wl_pointer interface represents one or more input devices,
   such as mice, which control the pointer location and pointer_focus
@@ -2089,7 +2089,7 @@
 
   
 
-  
+  
 
   The wl_keyboard interface represents one or more keyboards
   associated with a seat.
@@ -2200,7 +2200,7 @@
 
   
 
-  
+  
 
   The wl_touch interface represents a touchscreen
   associated with a seat.
@@ -2342,6 +2342,25 @@
   
   
 
+
+
+
+
+  
+The timestamp event is sent just before a wl_touch.up, wl_touch.motion
+or wl_touch.down event and provides a high-resolution version of the
+time argument of the event that follows.
+
+The timestamp provided by this event is at least as accurate
+as the timestamp provided by the wl_touch event that follows.
+  
+  
+  
+  
+
   
 
   
-- 
2.14.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


Re: [RFC wayland] protocol: Add high-resolution wl_touch timestamp event

2017-11-21 Thread Alexandros Frantzis
On Tue, Nov 21, 2017 at 10:52:00PM +0800, Jonas Ådahl wrote:
> On Tue, Nov 21, 2017 at 03:45:48PM +0200, Alexandros Frantzis wrote:
> > wl_touch events currently use a 32-bit timestamp with millisecond
> > resolution. In some cases, notably latency measurements, this resolution
> > is too coarse-grained to be useful.
> > 
> > This protocol update adds a wl_touch.timestamp event, which is emitted
> > just before an up, motion or down touch event. The timestamp event
> > contains a high-resolution, and ideally higher-accuracy, version of the
> > 'time' argument of the up/motion/down event that follows.
> > 
> > From a client implementation perspective clients can just ignore this event 
> > if
> > they don't care about the improved resolution. Clients that care just need 
> > to
> > keep track of the last timestamp event they receive and associate it with 
> > the
> > next up/motion/down event that arrives.
> > 
> > Some points for discussion:
> > 
> > 1. Should there be a request to explicitly enable/disable the timestamp 
> > event
> >(to reduce extra event overhead when improved timestamps are not needed)?
> 
> Is there any overhead though? Or are you assuming compositors compress
> events when it wouldn't be enabled, or that it'd some how take more
> effort to fetch higher resolution timestamps?

I am more concerned with the potential overhead of sending, receiving
and handling two events instead of one for each touch event (timestamp
followed by up/down/motion). I don't know if the overhead is important
enough to be a real concern, but I know it's not zero.

The issue is somewhat mitigated at the moment since if a client doesn't
care about the new timestamp the wl_touch version number will probably
be < 7, so no event will be sent at all. However, if we add new features
in versions > 7 and a client needs them, they will also get the
timestamp events, which they may not care about.


> > +
> > +
> > +
> > +  
> > +The timestamp event is sent just before a wl_touch.up, 
> > wl_touch.motion
> > +or wl_touch.down event and provides a high-resolution version of 
> > the
> > +time argument of the event that follows.
> > +
> > +The timestamp provided by this event is at least as accurate
> > +as the timestamp provided by the wl_touch event that follows.
> > +  
> > +   > +   summary="high 32 bits of the seconds part of the timestamp"/>
> > +   > +   summary="low 32 bits of the seconds part of the timestamp"/>
> > +   > +   summary="nanoseconds part of the timestamp"/>
> 
> Is nano-seconds really necessary? FWIW, you'll only get timestamps with
> up to micro seconds granularity from libinput, and protocol wise it'd be
> a simple usec_hi::u32, usec_lo::u32 pair, and in code it could be passed
> around as a uint64_t (as is done in libinput).
>
> ALso, tv_nsec as a 32 bit uint doesn't seem enough. In struct timesec
> tv_nsec is 64 bit.

I chose this scheme for two reasons:

1. Primarily to be consistent with how other events carry high-resolution
   timestamp information. In particular I copied the scheme from
   wp_presentation.presented.

2. Secondarily because it ~matches timespec, which is a standard posix
   type.

In this scheme, nanoseconds being 32 bits is fine for normalized
representations of timespec, i.e, where nsec is always < 10^9 (1 sec),
and I think this was the rationale for using 32 bits for it (but I will
let Pekka answer authoritatively).

I am not overly attached to this scheme, but there is some precedence
for it in existing protocols, and I would rather we didn't introduce yet
another scheme, unless it's one that we decide that we want to try to
standardize on, or at least recommend, for future high-res
timestamps.

Thanks,
Alexandros
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


Re: [PATCH weston 05/12] libweston: Use struct timespec for motion events

2017-11-24 Thread Alexandros Frantzis
On Fri, Nov 24, 2017 at 03:29:11PM +0200, Pekka Paalanen wrote:
> On Thu, 16 Nov 2017 18:20:54 +0200
> Alexandros Frantzis  wrote:
> 
> > Change code related to motion events to use struct timespec to represent
> > time.
> > 
> > This commit is part of a larger effort to transition the Weston codebase
> > to struct timespec.
> > 
> > Signed-off-by: Alexandros Frantzis 
> > ---
> >  compositor/screen-share.c  |  6 +-
> >  desktop-shell/exposay.c|  3 ++-
> >  desktop-shell/shell.c  | 12 
> >  ivi-shell/hmi-controller.c |  3 ++-
> >  libweston-desktop/seat.c   |  2 +-
> >  libweston/compositor-rdp.c | 10 +++---
> >  libweston/compositor-wayland.c |  5 -
> >  libweston/compositor-x11.c |  6 --
> >  libweston/compositor.h | 12 +++-
> >  libweston/data-device.c|  8 ++--
> >  libweston/input.c  | 30 ++
> >  libweston/libinput-device.c| 19 ++-
> >  tests/weston-test.c|  6 +-
> >  13 files changed, 79 insertions(+), 43 deletions(-)
> > 
> 
> 
> > diff --git a/libweston/libinput-device.c b/libweston/libinput-device.c
> > index b1d269db..b1087ba5 100644
> > --- a/libweston/libinput-device.c
> > +++ b/libweston/libinput-device.c
> > @@ -39,6 +39,7 @@
> >  #include "compositor.h"
> >  #include "libinput-device.h"
> >  #include "shared/helpers.h"
> > +#include "shared/timespec-util.h"
> >  
> >  void
> >  evdev_led_update(struct evdev_device *device, enum weston_led weston_leds)
> > @@ -86,26 +87,25 @@ handle_pointer_motion(struct libinput_device 
> > *libinput_device,
> > struct evdev_device *device =
> > libinput_device_get_user_data(libinput_device);
> > struct weston_pointer_motion_event event = { 0 };
> > -   uint64_t time_usec =
> > -   libinput_event_pointer_get_time_usec(pointer_event);
> > +   struct timespec time;
> > double dx_unaccel, dy_unaccel;
> >  
> > +   timespec_from_usec(&time,
> > +  libinput_event_pointer_get_time_usec(pointer_event));
> > dx_unaccel = libinput_event_pointer_get_dx_unaccelerated(pointer_event);
> > dy_unaccel = libinput_event_pointer_get_dy_unaccelerated(pointer_event);
> >  
> > event = (struct weston_pointer_motion_event) {
> > .mask = WESTON_POINTER_MOTION_REL |
> > WESTON_POINTER_MOTION_REL_UNACCEL,
> > -   .time_usec = time_usec,
> > +   .time = time,
> > .dx = libinput_event_pointer_get_dx(pointer_event),
> > .dy = libinput_event_pointer_get_dy(pointer_event),
> > .dx_unaccel = dx_unaccel,
> > .dy_unaccel = dy_unaccel,
> > };
> >  
> > -   notify_motion(device->seat,
> > - libinput_event_pointer_get_time(pointer_event),
> > - &event);
> > +   notify_motion(device->seat, &time, &event);
> >  
> > return true;
> >  }
> > @@ -118,14 +118,15 @@ handle_pointer_motion_absolute(
> > struct evdev_device *device =
> > libinput_device_get_user_data(libinput_device);
> > struct weston_output *output = device->output;
> > -   uint32_t time;
> > +   struct timespec time;
> > double x, y;
> > uint32_t width, height;
> >  
> > if (!output)
> > return false;
> >  
> > -   time = libinput_event_pointer_get_time(pointer_event);
> > +   timespec_from_usec(&time,
> > +  libinput_event_pointer_get_time(pointer_event));
> 
> Hi,
> 
> I think the time here was msec, not usec. Libinput documentation does
> not say what the unit for libinput_event_pointer_get_time() is, but
> since there also exists libinput_event_pointer_get_time_usec(), I
> believe the former returns milliseconds.
> 
> > width = device->output->current_mode->width;
> > height = device->output->current_mode->height;
> >  
> > @@ -135,7 +136,7 @@ handle_pointer_motion_absolute(
> >   height);
> >  
> > weston_output_transform_coordinate(device->output, x, y, &x, &y);
> > -   notify_motion_absolute(device->seat, time, x, y);
> > +   notify_motion_absolute(device->seat, &time, x, y);
> >  
> > return true;
> >  }
> 
> That was the only problem I could see in this patch, everything else
> looks good.
> 
> 
> Thanks,
> pq

Hi Pekka,

yes you are right, this should be changed to use
libinput_event_pointer_get_time_usec() (like all the other events)).

I will fix this in v2.

Thanks,
Alexandros
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH weston v2 05/12] libweston: Use struct timespec for motion events

2017-11-24 Thread Alexandros Frantzis
Change code related to motion events to use struct timespec to represent
time.

This commit is part of a larger effort to transition the Weston codebase
to struct timespec.

Signed-off-by: Alexandros Frantzis 
---

Changes in v2:
 - Fix handle_pointer_motion_absolute to use the event time in
   microseconds with libinput_event_pointer_get_time_usec.

 compositor/screen-share.c  |  6 +-
 desktop-shell/exposay.c|  3 ++-
 desktop-shell/shell.c  | 12 
 ivi-shell/hmi-controller.c |  3 ++-
 libweston-desktop/seat.c   |  2 +-
 libweston/compositor-rdp.c | 10 +++---
 libweston/compositor-wayland.c |  5 -
 libweston/compositor-x11.c |  6 --
 libweston/compositor.h | 12 +++-
 libweston/data-device.c|  8 ++--
 libweston/input.c  | 30 ++
 libweston/libinput-device.c| 19 ++-
 tests/weston-test.c|  6 +-
 13 files changed, 79 insertions(+), 43 deletions(-)

diff --git a/compositor/screen-share.c b/compositor/screen-share.c
index a6f82b19..c7aad313 100644
--- a/compositor/screen-share.c
+++ b/compositor/screen-share.c
@@ -44,6 +44,7 @@
 #include "weston.h"
 #include "shared/helpers.h"
 #include "shared/os-compatibility.h"
+#include "shared/timespec-util.h"
 #include "fullscreen-shell-unstable-v1-client-protocol.h"
 
 struct shared_output {
@@ -140,11 +141,14 @@ ss_seat_handle_motion(void *data, struct wl_pointer 
*pointer,
  uint32_t time, wl_fixed_t x, wl_fixed_t y)
 {
struct ss_seat *seat = data;
+   struct timespec ts;
+
+   timespec_from_msec(&ts, time);
 
/* No transformation of input position is required here because we are
 * always receiving the input in the same coordinates as the output. */
 
-   notify_motion_absolute(&seat->base, time,
+   notify_motion_absolute(&seat->base, &ts,
   wl_fixed_to_double(x), wl_fixed_to_double(y));
notify_pointer_frame(&seat->base);
 }
diff --git a/desktop-shell/exposay.c b/desktop-shell/exposay.c
index b11a7f79..15b86863 100644
--- a/desktop-shell/exposay.c
+++ b/desktop-shell/exposay.c
@@ -349,7 +349,8 @@ exposay_focus(struct weston_pointer_grab *grab)
 }
 
 static void
-exposay_motion(struct weston_pointer_grab *grab, uint32_t time,
+exposay_motion(struct weston_pointer_grab *grab,
+  const struct timespec *time,
   struct weston_pointer_motion_event *event)
 {
struct desktop_shell *shell =
diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c
index 55380417..62dfa450 100644
--- a/desktop-shell/shell.c
+++ b/desktop-shell/shell.c
@@ -1482,7 +1482,8 @@ constrain_position(struct weston_move_grab *move, int 
*cx, int *cy)
 }
 
 static void
-move_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
+move_grab_motion(struct weston_pointer_grab *grab,
+const struct timespec *time,
 struct weston_pointer_motion_event *event)
 {
struct weston_move_grab *move = (struct weston_move_grab *) grab;
@@ -1577,7 +1578,8 @@ struct weston_resize_grab {
 };
 
 static void
-resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
+resize_grab_motion(struct weston_pointer_grab *grab,
+  const struct timespec *time,
   struct weston_pointer_motion_event *event)
 {
struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
@@ -1767,7 +1769,8 @@ busy_cursor_grab_focus(struct weston_pointer_grab *base)
 }
 
 static void
-busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
+busy_cursor_grab_motion(struct weston_pointer_grab *grab,
+   const struct timespec *time,
struct weston_pointer_motion_event *event)
 {
weston_pointer_move(grab->pointer, event);
@@ -3443,7 +3446,8 @@ terminate_binding(struct weston_keyboard *keyboard, 
uint32_t time,
 }
 
 static void
-rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
+rotate_grab_motion(struct weston_pointer_grab *grab,
+  const struct timespec *time,
   struct weston_pointer_motion_event *event)
 {
struct rotate_grab *rotate =
diff --git a/ivi-shell/hmi-controller.c b/ivi-shell/hmi-controller.c
index d5403e06..6713eca3 100644
--- a/ivi-shell/hmi-controller.c
+++ b/ivi-shell/hmi-controller.c
@@ -1534,7 +1534,8 @@ layer_set_pos(struct ivi_layout_layer *layer, wl_fixed_t 
pos_x,
 }
 
 static void
-pointer_move_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
+pointer_move_grab_motion(struct weston_pointer_grab *grab,
+const struct timespec *time,
 struct weston_pointer_motion_event *event)
 {
struct pointer_move_grab *pnt_move_grab =
diff --git a/libweston-desktop/seat.c b/libwe

[PATCH weston v2 01/12] shared: Add timespec_is_zero helper

2017-11-27 Thread Alexandros Frantzis
Add a helper function to check if a struct timespec is zero. This helper
will be used in the upcoming commits to transition the Weston codebase
to struct timespec.

Signed-off-by: Alexandros Frantzis 
---

Changes in v2:
 - Use designated initializers to initialize members of struct timespec
   in test.

 shared/timespec-util.h | 12 
 tests/timespec-test.c  | 11 +++
 2 files changed, 23 insertions(+)

diff --git a/shared/timespec-util.h b/shared/timespec-util.h
index 34a120ae..7260dc8b 100644
--- a/shared/timespec-util.h
+++ b/shared/timespec-util.h
@@ -29,6 +29,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define NSEC_PER_SEC 10
 
@@ -133,6 +134,17 @@ timespec_sub_to_msec(const struct timespec *a, const 
struct timespec *b)
return timespec_sub_to_nsec(a, b) / 100;
 }
 
+/* Check if a timespec is zero
+ *
+ * \param a timespec
+ * \return whether the timespec is zero
+ */
+static inline bool
+timespec_is_zero(const struct timespec *a)
+{
+   return a->tv_sec == 0 && a->tv_nsec == 0;
+}
+
 /* Convert milli-Hertz to nanoseconds
  *
  * \param mhz frequency in mHz, not zero
diff --git a/tests/timespec-test.c b/tests/timespec-test.c
index a5039110..4e83605d 100644
--- a/tests/timespec-test.c
+++ b/tests/timespec-test.c
@@ -164,3 +164,14 @@ ZUC_TEST(timespec_test, timespec_sub_to_msec)
b.tv_nsec = 100L;
ZUC_ASSERT_EQ((998 * 1000) + 1, timespec_sub_to_msec(&a, &b));
 }
+
+ZUC_TEST(timespec_test, timespec_is_zero)
+{
+   struct timespec zero = { 0 };
+   struct timespec non_zero_sec = { .tv_sec = 1, .tv_nsec = 0 };
+   struct timespec non_zero_nsec = { .tv_sec = 0, .tv_nsec = 1 };
+
+   ZUC_ASSERT_TRUE(timespec_is_zero(&zero));
+   ZUC_ASSERT_FALSE(timespec_is_zero(&non_zero_nsec));
+   ZUC_ASSERT_FALSE(timespec_is_zero(&non_zero_sec));
+}
-- 
2.14.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


Re: [PATCH weston 01/12] shared: Add timespec_is_zero helper

2017-11-27 Thread Alexandros Frantzis
On Mon, Nov 27, 2017 at 10:20:35AM +0200, Pekka Paalanen wrote:
> On Fri, 24 Nov 2017 18:36:43 +
> Emil Velikov  wrote:
> 
> > Hi Alexandros,
> > 
> > On 16 November 2017 at 16:20, Alexandros Frantzis
> >  wrote:
> > 
> > > +ZUC_TEST(timespec_test, timespec_is_zero)
> > > +{
> > > +   struct timespec zero = { 0 };
> > > +   struct timespec non_zero_sec = { 1, 0 };
> > > +   struct timespec non_zero_nsec = { 0, 1 };
> > > +  
> > The standard (be that POSIX or C99) does not guarantee the layout of
> > the struct. Hence the above approach may work, but it's a bad idea.
> > Personally I'm a fan of C99 designated initializers, although one
> > could set the tv_sec and tv_nsec individually.
> > 
> > Same comment applies through the rest of the series.
> 
> That's actually a very good point, I missed it!
> 
> Alexandros, can you revise, please?
> 
> Thanks,
> pq

Hi Pekka and Emil,

I have sent v2 for the 01/12 patch with the fix. I checked the rest of
the patches and this is the only point the struct members are
initialized without using the member names.

Thank you,
Alexandros
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[RFC wayland-protocols] unstable: Add input-timestamps protocol

2017-11-29 Thread Alexandros Frantzis
wl_pointer, wl_keyboard and wl_touch events currently use a 32-bit
timestamp with millisecond resolution. In some cases, notably latency
measurements, this resolution is too coarse to be useful.

This protocol provides additional timestamps events, which are emitted
just before the corresponding input event. Each timestamp event contains
a high-resolution, and ideally higher-accuracy, version of the 'time'
argument of the event that follows.

Clients that care about high-resolution timestamps just need to keep
track of the last timestamp event they receive and associate it with the
next input event that arrives.

Some notes and possible points for discussion:

1. Supported pointer/keyboard/touch events

   At the moment the protocol is phrased to be forward-compatible with
   new pointer/keyboard/touch events. For example, for touch:

   "represents a subscription to high-resolution timestamp events for
   for all wl_touch events that carry a timestamp."

   This guards against making input-timestamps protocol updates for new
   input events (unless we add a new input category), and is easy to
   implement in practice.

2. Guaranteed timestamp accuracy?

   Currently: "The timestamp provided by this event is at least as
   accurate as the timestamp provided by the input event that follows".

   In a previous discussion it was suggested that an option would be for
   the server to advertise support for this protocol only if it can
   provide better (than millisecond) accuracy. My concern with such an
   approach is that there may be cases where only some input objects can
   provide high-accuracy timestamps, so the guarantee may not be
   globally applicable.

3. Clocks domains

   The high-resolution timestamps are guaranteed to be in the same clock
   domain as the input event timestamps (for which the clock domain is
   currently unspecified).

A proof of concept implementation for weston can be found at:

https://gitlab.collabora.com/alf/weston/commits/zwp-input-timestamps

Currently only touch timestamps are implemented, but supporting pointer
and keyboard event timestamps will be similar.

Signed-off-by: Alexandros Frantzis 
---
 Makefile.am|   1 +
 unstable/input-timestamps/README   |   4 +
 .../input-timestamps-unstable-v1.xml   | 132 +
 3 files changed, 137 insertions(+)
 create mode 100644 unstable/input-timestamps/README
 create mode 100644 unstable/input-timestamps/input-timestamps-unstable-v1.xml

diff --git a/Makefile.am b/Makefile.am
index 0296d5d..a4fd82e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -16,6 +16,7 @@ unstable_protocols =  
\
unstable/xwayland-keyboard-grab/xwayland-keyboard-grab-unstable-v1.xml  
\

unstable/keyboard-shortcuts-inhibit/keyboard-shortcuts-inhibit-unstable-v1.xml \
unstable/xdg-output/xdg-output-unstable-v1.xml  
\
+   unstable/input-timestamps/input-timestamps-unstable-v1.xml  \
$(NULL)
 
 stable_protocols = 
\
diff --git a/unstable/input-timestamps/README b/unstable/input-timestamps/README
new file mode 100644
index 000..3e82890
--- /dev/null
+++ b/unstable/input-timestamps/README
@@ -0,0 +1,4 @@
+High-resolution timestamps for input events.
+
+Maintainers:
+Alexandros Frantzis 
diff --git a/unstable/input-timestamps/input-timestamps-unstable-v1.xml 
b/unstable/input-timestamps/input-timestamps-unstable-v1.xml
new file mode 100644
index 000..73500d0
--- /dev/null
+++ b/unstable/input-timestamps/input-timestamps-unstable-v1.xml
@@ -0,0 +1,132 @@
+
+
+
+  
+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.
+  
+
+  
+This pr

Re: [RFC wayland] protocol: Add high-resolution wl_touch timestamp event

2017-11-29 Thread Alexandros Frantzis
On Wed, Nov 29, 2017 at 09:26:07AM +0200, Pekka Paalanen wrote:
> On Tue, 28 Nov 2017 14:16:32 +
> Daniel Stone  wrote:
> 
> > Hi,
> > 
> > On 24 November 2017 at 11:59, Pekka Paalanen  wrote:
> > > On Tue, 21 Nov 2017 15:45:48 +0200
> > > Alexandros Frantzis  wrote:  
> > >> 2. Should we introduce similar timestamp events for keyboard and 
> > >> pointer?  
> > >
> > > No, unless someone actually has a use for them. That brings the
> > > question, why are you only interested in touch timestamps and not
> > > keyboard and pointer?
> > >
> > > Why are keyboard and pointer latency not interesting to you?  
> > 
> > I would very much suggest doing so, yeah. Having timestamps for
> > high-frequency/resolution mice seems like a real need. Given the need
> > to correllate the event streams (e.g. 'is someone holding down Ctrl
> > whilst I scroll?'), it makes it easier for clients if we have
> > comparable timestamps between the two.
> 
> Right, let's have them for all the timestamped core input events, not
> only touch.
> 
> 
> Thanks,
> pq

Hi,

thank you all for your thoughts and suggestions. I have pushed a new RFC
for a separate protocol providing this functionality:

https://lists.freedesktop.org/archives/wayland-devel/2017-November/035980.html

Thanks,
Alexandros
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


Re: [RFC wayland-protocols] unstable: Add input-timestamps protocol

2017-11-30 Thread Alexandros Frantzis
On Thu, Nov 30, 2017 at 04:08:06PM +1000, Peter Hutterer wrote:
> On Wed, Nov 29, 2017 at 12:42:57PM +0200, Alexandros Frantzis wrote:
> > wl_pointer, wl_keyboard and wl_touch events currently use a 32-bit
> > timestamp with millisecond resolution. In some cases, notably latency
> > measurements, this resolution is too coarse to be useful.
> > 
> > This protocol provides additional timestamps events, which are emitted
> > just before the corresponding input event. Each timestamp event contains
> > a high-resolution, and ideally higher-accuracy, version of the 'time'
> > argument of the event that follows.
> > 
> > Clients that care about high-resolution timestamps just need to keep
> > track of the last timestamp event they receive and associate it with the
> > next input event that arrives.
> > 
> > Some notes and possible points for discussion:
> > 
> > 1. Supported pointer/keyboard/touch events
> > 
> >At the moment the protocol is phrased to be forward-compatible with
> >new pointer/keyboard/touch events. For example, for touch:
> > 
> >"represents a subscription to high-resolution timestamp events for
> >for all wl_touch events that carry a timestamp."
> > 
> >This guards against making input-timestamps protocol updates for new
> >input events (unless we add a new input category), and is easy to
> >implement in practice.
> > 
> > 2. Guaranteed timestamp accuracy?
> > 
> >Currently: "The timestamp provided by this event is at least as
> >accurate as the timestamp provided by the input event that follows".
> > 
> >In a previous discussion it was suggested that an option would be for
> >the server to advertise support for this protocol only if it can
> >provide better (than millisecond) accuracy. My concern with such an
> >approach is that there may be cases where only some input objects can
> >provide high-accuracy timestamps, so the guarantee may not be
> >globally applicable.
> > 
> > 3. Clocks domains
> > 
> >The high-resolution timestamps are guaranteed to be in the same clock
> >domain as the input event timestamps (for which the clock domain is
> >currently unspecified).
> > 
> > A proof of concept implementation for weston can be found at:
> > 
> > https://gitlab.collabora.com/alf/weston/commits/zwp-input-timestamps
> > 
> > Currently only touch timestamps are implemented, but supporting pointer
> > and keyboard event timestamps will be similar.
> > 
> > Signed-off-by: Alexandros Frantzis 
> > ---
> >  Makefile.am|   1 +
> >  unstable/input-timestamps/README   |   4 +
> >  .../input-timestamps-unstable-v1.xml   | 132 
> > +
> >  3 files changed, 137 insertions(+)
> >  create mode 100644 unstable/input-timestamps/README
> >  create mode 100644 
> > unstable/input-timestamps/input-timestamps-unstable-v1.xml
> > 
> > diff --git a/Makefile.am b/Makefile.am
> > index 0296d5d..a4fd82e 100644
> > --- a/Makefile.am
> > +++ b/Makefile.am
> > @@ -16,6 +16,7 @@ unstable_protocols =  
> > \
> > unstable/xwayland-keyboard-grab/xwayland-keyboard-grab-unstable-v1.xml  
> > \
> > 
> > unstable/keyboard-shortcuts-inhibit/keyboard-shortcuts-inhibit-unstable-v1.xml
> >  \
> > unstable/xdg-output/xdg-output-unstable-v1.xml  
> > \
> > +   unstable/input-timestamps/input-timestamps-unstable-v1.xml  \
> > $(NULL)
> >  
> >  stable_protocols = 
> > \
> > diff --git a/unstable/input-timestamps/README 
> > b/unstable/input-timestamps/README
> > new file mode 100644
> > index 000..3e82890
> > --- /dev/null
> > +++ b/unstable/input-timestamps/README
> > @@ -0,0 +1,4 @@
> > +High-resolution timestamps for input events.
> > +
> > +Maintainers:
> > +Alexandros Frantzis 
> > diff --git a/unstable/input-timestamps/input-timestamps-unstable-v1.xml 
> > b/unstable/input-timestamps/input-timestamps-unstable-v1.xml
> > new file mode 100644
> > index 000..73500d0
> > --- /dev/null
> > +++ b/unstable/input-timestamps/input-timestamps-unstable-v1.xml
> > @@ -0,0 +1,132 @@
> > +
> > +
> > +
> > +  
> > +Copyright © 2017 Collabora Ltd.
> > +
> > +

[PATCH weston] tests: Fix integer overflows on 32-bit systems

2017-12-01 Thread Alexandros Frantzis
Ensure that the integer type used in expressions involving
multiplication with NSEC_PER_SEC is large enough to avoid overflows on
32-bit systems. In the expressions fixed by this patch a 64-bit type
(long long) is required.

Signed-off-by: Alexandros Frantzis 
---
 tests/timespec-test.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tests/timespec-test.c b/tests/timespec-test.c
index f127bcee..31a6f146 100644
--- a/tests/timespec-test.c
+++ b/tests/timespec-test.c
@@ -160,7 +160,7 @@ ZUC_TEST(timespec_test, timespec_sub_to_nsec)
a.tv_nsec = 1;
b.tv_sec = 1;
b.tv_nsec = 2;
-   ZUC_ASSERT_EQ((999L * NSEC_PER_SEC) - 1, timespec_sub_to_nsec(&a, &b));
+   ZUC_ASSERT_EQ((999LL * NSEC_PER_SEC) - 1, timespec_sub_to_nsec(&a, &b));
 }
 
 ZUC_TEST(timespec_test, timespec_sub_to_msec)
@@ -190,7 +190,7 @@ ZUC_TEST(timespec_test, timespec_from_nsec)
ZUC_ASSERT_EQ(1, a.tv_sec);
ZUC_ASSERT_EQ(0, a.tv_nsec);
 
-   timespec_from_nsec(&a, (5L * NSEC_PER_SEC) + 1);
+   timespec_from_nsec(&a, (5LL * NSEC_PER_SEC) + 1);
ZUC_ASSERT_EQ(5, a.tv_sec);
ZUC_ASSERT_EQ(1, a.tv_nsec);
 }
-- 
2.14.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH weston 1/8] shared: Add timespec_normalize helper

2017-12-04 Thread Alexandros Frantzis
Add a helper function to normalize struct timespec values so that the
nanoseconds part is less than 1 second and has the same sign as the
seconds part (if the seconds part is not 0).

Normalization is required to ensure we can safely convert timespec
values to wayland protocol data, i.e, to tv_sec_hi, tv_sec_lo,
tv_sec_nsec triplets, and will be used in upcoming commits.

Signed-off-by: Alexandros Frantzis 
---
 shared/timespec-util.h | 28 ++
 tests/timespec-test.c  | 65 ++
 2 files changed, 93 insertions(+)

diff --git a/shared/timespec-util.h b/shared/timespec-util.h
index f9736c27..a10edf5b 100644
--- a/shared/timespec-util.h
+++ b/shared/timespec-util.h
@@ -33,6 +33,34 @@
 
 #define NSEC_PER_SEC 10
 
+/* Normalize a timespec
+ *
+ * \param r[out] normalized timespec
+ * \param a[in] timespec to normalize
+ *
+ * Normalize a timespec so that tv_nsec is less than 1 second
+ * and has the same sign as tv_sec (if tv_sec is non-zero).
+ *
+ */
+static inline void
+timespec_normalize(struct timespec *r, const struct timespec *a)
+{
+   if (a->tv_nsec >= NSEC_PER_SEC || a->tv_nsec <= -NSEC_PER_SEC) {
+   r->tv_sec = a->tv_sec + a->tv_nsec / NSEC_PER_SEC;
+   r->tv_nsec = a->tv_nsec % NSEC_PER_SEC;
+   } else {
+   *r = *a;
+   }
+
+   if (r->tv_sec > 0 && r->tv_nsec < 0) {
+   r->tv_sec -= 1;
+   r->tv_nsec += NSEC_PER_SEC;
+   } else if (r->tv_sec < 0 && r->tv_nsec > 0) {
+   r->tv_sec += 1;
+   r->tv_nsec -= NSEC_PER_SEC;
+   }
+}
+
 /* Subtract timespecs
  *
  * \param r[out] result: a - b
diff --git a/tests/timespec-test.c b/tests/timespec-test.c
index f127bcee..8c2296d1 100644
--- a/tests/timespec-test.c
+++ b/tests/timespec-test.c
@@ -38,6 +38,71 @@
 #include "shared/helpers.h"
 #include "zunitc/zunitc.h"
 
+ZUC_TEST(timespec_test, timespec_normalize)
+{
+   struct timespec a, r;
+
+   a.tv_sec = 0;
+   a.tv_nsec = 0;
+   timespec_normalize(&r, &a);
+   ZUC_ASSERT_EQ(r.tv_sec, 0);
+   ZUC_ASSERT_EQ(r.tv_nsec, 0);
+
+   a.tv_sec = 1;
+   a.tv_nsec = NSEC_PER_SEC - 1;
+   timespec_normalize(&r, &a);
+   ZUC_ASSERT_EQ(r.tv_sec, 1);
+   ZUC_ASSERT_EQ(r.tv_nsec, NSEC_PER_SEC - 1);
+
+   a.tv_sec = 1;
+   a.tv_nsec = NSEC_PER_SEC;
+   timespec_normalize(&r, &a);
+   ZUC_ASSERT_EQ(r.tv_sec, 2);
+   ZUC_ASSERT_EQ(r.tv_nsec, 0);
+
+   a.tv_sec = 1;
+   a.tv_nsec = NSEC_PER_SEC + 1;
+   timespec_normalize(&r, &a);
+   ZUC_ASSERT_EQ(r.tv_sec, 2);
+   ZUC_ASSERT_EQ(r.tv_nsec, 1);
+
+   a.tv_sec = -1;
+   a.tv_nsec = -NSEC_PER_SEC;
+   timespec_normalize(&r, &a);
+   ZUC_ASSERT_EQ(r.tv_sec, -2);
+   ZUC_ASSERT_EQ(r.tv_nsec, 0);
+
+   a.tv_sec = -1;
+   a.tv_nsec = -(NSEC_PER_SEC + 1);
+   timespec_normalize(&r, &a);
+   ZUC_ASSERT_EQ(r.tv_sec, -2);
+   ZUC_ASSERT_EQ(r.tv_nsec, -1);
+
+   a.tv_sec = -3;
+   a.tv_nsec = NSEC_PER_SEC + 1;
+   timespec_normalize(&r, &a);
+   ZUC_ASSERT_EQ(r.tv_sec, -1);
+   ZUC_ASSERT_EQ(r.tv_nsec, -(NSEC_PER_SEC - 1));
+
+   a.tv_sec = 3;
+   a.tv_nsec = -(NSEC_PER_SEC + 1);
+   timespec_normalize(&r, &a);
+   ZUC_ASSERT_EQ(r.tv_sec, 1);
+   ZUC_ASSERT_EQ(r.tv_nsec, NSEC_PER_SEC - 1);
+
+   a.tv_sec = -1;
+   a.tv_nsec = 2 * NSEC_PER_SEC + 1;
+   timespec_normalize(&r, &a);
+   ZUC_ASSERT_EQ(r.tv_sec, 1);
+   ZUC_ASSERT_EQ(r.tv_nsec, 1);
+
+   a.tv_sec = 1;
+   a.tv_nsec = -(2 * NSEC_PER_SEC + 1);
+   timespec_normalize(&r, &a);
+   ZUC_ASSERT_EQ(r.tv_sec, -1);
+   ZUC_ASSERT_EQ(r.tv_nsec, -1);
+}
+
 ZUC_TEST(timespec_test, timespec_sub)
 {
struct timespec a, b, r;
-- 
2.14.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH weston 0/8] tests: Add input event timestamp tests

2017-12-04 Thread Alexandros Frantzis
This patchset enhances the test suite with test cases that verify that
the server correctly sets input event timestamps. In the process the
input tests have been reorganized and cleaned up to make it easier to
support the new test cases.

A secondary goal of this patchset is to prepare the test suite for
testing a potential implementation of new high-resolution input
timestamps in the form of a new protocol (discussions on an RFC proposal
are already on-going in the mailing list).

Patches (1) and (2) add timespec helpers to enable safe conversions
between timespec and protocol data triplets.

Patches (3) and (4) reorganize the pointer tests to make it easier to
add new test cases.

Patches (5) to (8) add tests for input events with a focus on verifying
event timestamps.

Alexandros Frantzis (8):
  shared: Add timespec_normalize helper
  shared: Add helpers to convert between protocol data and timespec
  tests: Move wl_pointer tests to their own file
  tests: Use separate test cases for pointer motion and button tests
  tests: Add checks for pointer motion and button event timestamps
  tests: Add test for pointer axis events
  tests: Add test for keyboard key event timestamps
  tests: Add test for touch event timestamps

 Makefile.am   |  15 +-
 clients/presentation-shm.c|   9 +-
 libweston/compositor.c|   9 +-
 protocol/weston-test.xml  |  25 +++
 shared/timespec-util.h|  67 ++
 tests/event-test.c| 256 --
 tests/internal-screenshot-test.c  |   2 +-
 tests/keyboard-test.c |  58 +++--
 tests/pointer-test.c  | 385 ++
 tests/presentation-test.c |   9 +-
 tests/subsurface-shot-test.c  |   2 +-
 tests/timespec-test.c | 131 
 tests/{button-test.c => touch-test.c} |  58 ++---
 tests/weston-test-client-helper.c |  19 +-
 tests/weston-test-client-helper.h |  10 +
 tests/weston-test.c   |  45 +++-
 16 files changed, 777 insertions(+), 323 deletions(-)
 create mode 100644 tests/pointer-test.c
 rename tests/{button-test.c => touch-test.c} (50%)

-- 
2.14.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH weston 4/8] tests: Use separate test cases for pointer motion and button tests

2017-12-04 Thread Alexandros Frantzis
Split pointer motion and pointer button tests so that each test case is
more focused and self-contained.

Signed-off-by: Alexandros Frantzis 
---
 tests/pointer-test.c | 36 +---
 1 file changed, 25 insertions(+), 11 deletions(-)

diff --git a/tests/pointer-test.c b/tests/pointer-test.c
index d0b85f5d..e0e700e0 100644
--- a/tests/pointer-test.c
+++ b/tests/pointer-test.c
@@ -69,6 +69,17 @@ check_pointer_move(struct client *client, int x, int y)
check_pointer(client, x, y);
 }
 
+static struct client *
+create_client_with_pointer_focus(int x, int y, int w, int h)
+{
+   struct client *cl = create_client_and_test_surface(x, y, w, h);
+   assert(cl);
+   /* Move the pointer inside the surface to ensure that the surface
+* has the pointer focus. */
+   check_pointer_move(cl, x, y);
+   return cl;
+}
+
 TEST(test_pointer_top_left)
 {
struct client *client;
@@ -286,23 +297,26 @@ TEST(test_pointer_surface_move)
check_pointer(client, 50, 50);
 }
 
-TEST(simple_pointer_button_test)
+TEST(pointer_motion_events)
 {
-   struct client *client;
-   struct pointer *pointer;
-
-   client = create_client_and_test_surface(100, 100, 100, 100);
-   assert(client);
-
-   pointer = client->input->pointer;
-
-   assert(pointer->button == 0);
-   assert(pointer->state == 0);
+   struct client *client = create_client_with_pointer_focus(100, 100,
+100, 100);
+   struct pointer *pointer = client->input->pointer;
 
weston_test_move_pointer(client->test->weston_test, 150, 150);
client_roundtrip(client);
assert(pointer->x == 50);
assert(pointer->y == 50);
+}
+
+TEST(pointer_button_events)
+{
+   struct client *client = create_client_with_pointer_focus(100, 100,
+100, 100);
+   struct pointer *pointer = client->input->pointer;
+
+   assert(pointer->button == 0);
+   assert(pointer->state == 0);
 
weston_test_send_button(client->test->weston_test, BTN_LEFT,
WL_POINTER_BUTTON_STATE_PRESSED);
-- 
2.14.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH weston 5/8] tests: Add checks for pointer motion and button event timestamps

2017-12-04 Thread Alexandros Frantzis
Enhance the existing pointer motion and button event tests to
additionally verify the event timestamps. This requires updating the
weston-test protocol to support passing motion and button event
timestamps.

Signed-off-by: Alexandros Frantzis 
---
 protocol/weston-test.xml  |  6 ++
 tests/internal-screenshot-test.c  |  2 +-
 tests/pointer-test.c  | 45 ++-
 tests/subsurface-shot-test.c  |  2 +-
 tests/weston-test-client-helper.c |  2 ++
 tests/weston-test-client-helper.h |  2 ++
 tests/weston-test.c   |  6 --
 7 files changed, 51 insertions(+), 14 deletions(-)

diff --git a/protocol/weston-test.xml b/protocol/weston-test.xml
index 74a15214..ae3349ed 100644
--- a/protocol/weston-test.xml
+++ b/protocol/weston-test.xml
@@ -40,10 +40,16 @@
   
 
 
+  
+  
+  
   
   
 
 
+  
+  
+  
   
   
 
diff --git a/tests/internal-screenshot-test.c b/tests/internal-screenshot-test.c
index 3bf9b31b..2a7424b8 100644
--- a/tests/internal-screenshot-test.c
+++ b/tests/internal-screenshot-test.c
@@ -97,7 +97,7 @@ TEST(internal_screenshot)
 */
 
/* Move the pointer away from the screenshot area. */
-   weston_test_move_pointer(client->test->weston_test, 0, 0);
+   weston_test_move_pointer(client->test->weston_test, 0, 1, 0, 0, 0);
 
buf = create_shm_buffer_a8r8g8b8(client, 100, 100);
draw_stuff(buf->image);
diff --git a/tests/pointer-test.c b/tests/pointer-test.c
index e0e700e0..c241fa1d 100644
--- a/tests/pointer-test.c
+++ b/tests/pointer-test.c
@@ -28,8 +28,36 @@
 
 #include 
 
+#include "shared/timespec-util.h"
 #include "weston-test-client-helper.h"
 
+static const struct timespec t0 = { .tv_sec = 0, .tv_nsec = 1 };
+static const struct timespec t1 = { .tv_sec = 1, .tv_nsec = 101 };
+static const struct timespec t2 = { .tv_sec = 2, .tv_nsec = 201 };
+
+static void
+send_motion(struct client *client, const struct timespec *time, int x, int y)
+{
+   uint32_t tv_sec_hi, tv_sec_lo, tv_nsec;
+
+   timespec_to_proto(time, &tv_sec_hi, &tv_sec_lo, &tv_nsec);
+   weston_test_move_pointer(client->test->weston_test, tv_sec_hi, 
tv_sec_lo,
+tv_nsec, x, y);
+   client_roundtrip(client);
+}
+
+static void
+send_button(struct client *client, const struct timespec *time,
+   uint32_t button, uint32_t state)
+{
+   uint32_t tv_sec_hi, tv_sec_lo, tv_nsec;
+
+   timespec_to_proto(time, &tv_sec_hi, &tv_sec_lo, &tv_nsec);
+   weston_test_send_button(client->test->weston_test, tv_sec_hi, tv_sec_lo,
+   tv_nsec, button, state);
+   client_roundtrip(client);
+}
+
 static void
 check_pointer(struct client *client, int x, int y)
 {
@@ -64,8 +92,7 @@ check_pointer(struct client *client, int x, int y)
 static void
 check_pointer_move(struct client *client, int x, int y)
 {
-   weston_test_move_pointer(client->test->weston_test, x, y);
-   client_roundtrip(client);
+   send_motion(client, &t0, x, y);
check_pointer(client, x, y);
 }
 
@@ -303,10 +330,10 @@ TEST(pointer_motion_events)
 100, 100);
struct pointer *pointer = client->input->pointer;
 
-   weston_test_move_pointer(client->test->weston_test, 150, 150);
-   client_roundtrip(client);
+   send_motion(client, &t1, 150, 150);
assert(pointer->x == 50);
assert(pointer->y == 50);
+   assert(pointer->motion_time == timespec_to_msec(&t1));
 }
 
 TEST(pointer_button_events)
@@ -318,15 +345,13 @@ TEST(pointer_button_events)
assert(pointer->button == 0);
assert(pointer->state == 0);
 
-   weston_test_send_button(client->test->weston_test, BTN_LEFT,
-   WL_POINTER_BUTTON_STATE_PRESSED);
-   client_roundtrip(client);
+   send_button(client, &t1, BTN_LEFT, WL_POINTER_BUTTON_STATE_PRESSED);
assert(pointer->button == BTN_LEFT);
assert(pointer->state == WL_POINTER_BUTTON_STATE_PRESSED);
+   assert(pointer->button_time == timespec_to_msec(&t1));
 
-   weston_test_send_button(client->test->weston_test, BTN_LEFT,
-   WL_POINTER_BUTTON_STATE_RELEASED);
-   client_roundtrip(client);
+   send_button(client, &t2, BTN_LEFT, WL_POINTER_BUTTON_STATE_RELEASED);
assert(pointer->button == BTN_LEFT);
assert(pointer->state == WL_POINTER_BUTTON_STATE_RELEASED);
+   assert(pointer->button_time == timespec_to_msec(&t2));
 }
diff --git a/tests/subsurface-shot-test.c b/tests/subsurface-shot-test.c
index 10415ec7..e8bab676 100644
--- a/tests/subsurface-shot-test.c
+++ b/tests/subsurface-shot-test

[PATCH weston 3/8] tests: Move wl_pointer tests to their own file

2017-12-04 Thread Alexandros Frantzis
Move wl_pointer tests from event-test.c to their own pointer-test.c
file. This move makes the test organization clearer and more consistent,
and will make addition of further pointer tests easier.

Signed-off-by: Alexandros Frantzis 
---
 Makefile.am  |   8 +-
 tests/button-test.c  |  61 --
 tests/event-test.c   | 256 -
 tests/pointer-test.c | 318 +++
 4 files changed, 322 insertions(+), 321 deletions(-)
 delete mode 100644 tests/button-test.c
 create mode 100644 tests/pointer-test.c

diff --git a/Makefile.am b/Makefile.am
index e7e6a0ed..47b110df 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1224,7 +1224,7 @@ weston_tests =\
bad_buffer.weston   \
keyboard.weston \
event.weston\
-   button.weston   \
+   pointer.weston  \
text.weston \
presentation.weston \
viewporter.weston   \
@@ -1381,9 +1381,9 @@ event_weston_SOURCES = tests/event-test.c
 event_weston_CFLAGS = $(AM_CFLAGS) $(TEST_CLIENT_CFLAGS)
 event_weston_LDADD = libtest-client.la
 
-button_weston_SOURCES = tests/button-test.c
-button_weston_CFLAGS = $(AM_CFLAGS) $(TEST_CLIENT_CFLAGS)
-button_weston_LDADD = libtest-client.la
+pointer_weston_SOURCES = tests/pointer-test.c
+pointer_weston_CFLAGS = $(AM_CFLAGS) $(TEST_CLIENT_CFLAGS)
+pointer_weston_LDADD = libtest-client.la
 
 devices_weston_SOURCES = tests/devices-test.c
 devices_weston_CFLAGS = $(AM_CFLAGS) $(TEST_CLIENT_CFLAGS)
diff --git a/tests/button-test.c b/tests/button-test.c
deleted file mode 100644
index afa6320f..
--- a/tests/button-test.c
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright © 2012 Intel Corporation
- *
- * 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 
-
-#include "weston-test-client-helper.h"
-
-TEST(simple_button_test)
-{
-   struct client *client;
-   struct pointer *pointer;
-
-   client = create_client_and_test_surface(100, 100, 100, 100);
-   assert(client);
-
-   pointer = client->input->pointer;
-
-   assert(pointer->button == 0);
-   assert(pointer->state == 0);
-
-   weston_test_move_pointer(client->test->weston_test, 150, 150);
-   client_roundtrip(client);
-   assert(pointer->x == 50);
-   assert(pointer->y == 50);
-
-   weston_test_send_button(client->test->weston_test, BTN_LEFT,
-   WL_POINTER_BUTTON_STATE_PRESSED);
-   client_roundtrip(client);
-   assert(pointer->button == BTN_LEFT);
-   assert(pointer->state == WL_POINTER_BUTTON_STATE_PRESSED);
-
-   weston_test_send_button(client->test->weston_test, BTN_LEFT,
-   WL_POINTER_BUTTON_STATE_RELEASED);
-   client_roundtrip(client);
-   assert(pointer->button == BTN_LEFT);
-   assert(pointer->state == WL_POINTER_BUTTON_STATE_RELEASED);
-}
diff --git a/tests/event-test.c b/tests/event-test.c
index 64dd7a0c..c1ba3ac1 100644
--- a/tests/event-test.c
+++ b/tests/event-test.c
@@ -28,262 +28,6 @@
 
 #include "weston-test-client-helper.h"
 
-static void
-check_pointer(struct client *client, int x, int y)
-{
-   int sx, sy;
-
-   /* check that the client got the global pointer update */
-   assert(client->test->pointer_x == x);
-   assert(client->test->pointer_y == y);
-
-   /* Does global pointer map onto the surface? */
-   if (surface_contains(client->surface, x, y)) {
-   /* check that the surface has the pointer focus */
-   assert(client->input-&g

[PATCH weston 2/8] shared: Add helpers to convert between protocol data and timespec

2017-12-04 Thread Alexandros Frantzis
Add helpers to safely convert between struct timespec values and
tv_sec_hi, tv_sec_lo, tv_nsec triplets used for sending high-resolution
timestamp data over the wayland protocol. Replace existing conversion
code with the helper functions.

Signed-off-by: Alexandros Frantzis 
---
 clients/presentation-shm.c |  9 +--
 libweston/compositor.c |  9 ---
 shared/timespec-util.h | 39 +++
 tests/presentation-test.c  |  9 +--
 tests/timespec-test.c  | 66 ++
 5 files changed, 112 insertions(+), 20 deletions(-)

diff --git a/clients/presentation-shm.c b/clients/presentation-shm.c
index c9fb66cc..d6a939e5 100644
--- a/clients/presentation-shm.c
+++ b/clients/presentation-shm.c
@@ -39,6 +39,7 @@
 #include 
 #include "shared/helpers.h"
 #include "shared/zalloc.h"
+#include "shared/timespec-util.h"
 #include "shared/os-compatibility.h"
 #include "presentation-time-client-protocol.h"
 
@@ -383,14 +384,6 @@ timespec_to_ms(const struct timespec *ts)
return (uint32_t)ts->tv_sec * 1000 + ts->tv_nsec / 100;
 }
 
-static void
-timespec_from_proto(struct timespec *tm, uint32_t tv_sec_hi,
-   uint32_t tv_sec_lo, uint32_t tv_nsec)
-{
-   tm->tv_sec = ((uint64_t)tv_sec_hi << 32) + tv_sec_lo;
-   tm->tv_nsec = tv_nsec;
-}
-
 static int
 timespec_diff_to_usec(const struct timespec *a, const struct timespec *b)
 {
diff --git a/libweston/compositor.c b/libweston/compositor.c
index 7d7a17ed..083664fd 100644
--- a/libweston/compositor.c
+++ b/libweston/compositor.c
@@ -341,7 +341,9 @@ weston_presentation_feedback_present(
 {
struct wl_client *client = wl_resource_get_client(feedback->resource);
struct wl_resource *o;
-   uint64_t secs;
+   uint32_t tv_sec_hi;
+   uint32_t tv_sec_lo;
+   uint32_t tv_nsec;
 
wl_resource_for_each(o, &output->resource_list) {
if (wl_resource_get_client(o) != client)
@@ -350,10 +352,9 @@ weston_presentation_feedback_present(
wp_presentation_feedback_send_sync_output(feedback->resource, 
o);
}
 
-   secs = ts->tv_sec;
+   timespec_to_proto(ts, &tv_sec_hi, &tv_sec_lo, &tv_nsec);
wp_presentation_feedback_send_presented(feedback->resource,
-   secs >> 32, secs & 0x,
-   ts->tv_nsec,
+   tv_sec_hi, tv_sec_lo, tv_nsec,
refresh_nsec,
seq >> 32, seq & 0x,
flags | feedback->psf_flags);
diff --git a/shared/timespec-util.h b/shared/timespec-util.h
index a10edf5b..c734accd 100644
--- a/shared/timespec-util.h
+++ b/shared/timespec-util.h
@@ -175,6 +175,30 @@ timespec_to_usec(const struct timespec *a)
return (int64_t)a->tv_sec * 100 + a->tv_nsec / 1000;
 }
 
+/* Convert timespec to protocol data
+ *
+ * \param a timespec
+ * \param tv_sec_hi[out] the high bytes of the seconds part
+ * \param tv_sec_lo[out] the low bytes of the seconds part
+ * \param tv_nsec[out] the nanoseconds part
+ *
+ * The timespec is normalized before being converted to protocol data.
+ */
+static inline void
+timespec_to_proto(const struct timespec *a, uint32_t *tv_sec_hi,
+  uint32_t *tv_sec_lo, uint32_t *tv_nsec)
+{
+   struct timespec r;
+
+   timespec_normalize(&r, a);
+
+   /* We check the size of tv_sec, so that we shift only if the size
+* is 64-bits, in order to avoid sign extension on 32-bit systems. */
+   *tv_sec_hi = sizeof(r.tv_sec) == 8 ? (int64_t)r.tv_sec >> 32 : 0;
+   *tv_sec_lo = r.tv_sec;
+   *tv_nsec = r.tv_nsec;
+}
+
 /* Convert nanoseconds to timespec
  *
  * \param a timespec
@@ -209,6 +233,21 @@ timespec_from_msec(struct timespec *a, int64_t b)
timespec_from_nsec(a, b * 100);
 }
 
+/* Convert protocol data to timespec
+ *
+ * \param a[out] timespec
+ * \param tv_sec_hi the high bytes of seconds part
+ * \param tv_sec_lo the low bytes of seconds part
+ * \param tv_nsec the nanoseconds part
+ */
+static inline void
+timespec_from_proto(struct timespec *a, uint32_t tv_sec_hi,
+uint32_t tv_sec_lo, uint32_t tv_nsec)
+{
+   a->tv_sec = ((uint64_t)tv_sec_hi << 32) + tv_sec_lo;
+   a->tv_nsec = tv_nsec;
+}
+
 /* Check if a timespec is zero
  *
  * \param a timespec
diff --git a/tests/presentation-test.c b/tests/presentation-test.c
index f12f8eef..f6ffe480 100644
--- a/tests/presentation-test.c
+++ b/tests/presentation-test.c
@@ -34,6 +34,7 @@
 
 #include "shared/helpers.h"
 #include "shared/xalloc.h"
+#include "shared/timespec-util.h"
 #include &quo

[PATCH weston 7/8] tests: Add test for keyboard key event timestamps

2017-12-04 Thread Alexandros Frantzis
Add test to verify that the server correctly sets the timestamps of
keyboard key events. This requires updating the weston-test protocol to
support passing key event timestamps.

Signed-off-by: Alexandros Frantzis 
---
 protocol/weston-test.xml  |  3 ++
 tests/keyboard-test.c | 58 +++
 tests/weston-test-client-helper.c |  1 +
 tests/weston-test-client-helper.h |  1 +
 tests/weston-test.c   |  3 +-
 5 files changed, 53 insertions(+), 13 deletions(-)

diff --git a/protocol/weston-test.xml b/protocol/weston-test.xml
index a4a7ad4e..37fa221f 100644
--- a/protocol/weston-test.xml
+++ b/protocol/weston-test.xml
@@ -64,6 +64,9 @@
   
 
 
+  
+  
+  
   
   
 
diff --git a/tests/keyboard-test.c b/tests/keyboard-test.c
index 6b4ba19d..df1940f8 100644
--- a/tests/keyboard-test.c
+++ b/tests/keyboard-test.c
@@ -27,21 +27,45 @@
 
 #include 
 
+#include "shared/timespec-util.h"
 #include "weston-test-client-helper.h"
 
+static const struct timespec t1 = { .tv_sec = 1, .tv_nsec = 101 };
+static const struct timespec t2 = { .tv_sec = 2, .tv_nsec = 201 };
+
+static struct client *
+create_client_with_keyboard_focus(void)
+{
+   struct client *cl = create_client_and_test_surface(10, 10, 1, 1);
+   assert(cl);
+
+   weston_test_activate_surface(cl->test->weston_test,
+cl->surface->wl_surface);
+   client_roundtrip(cl);
+
+   return cl;
+}
+
+static void
+send_key(struct client *client, const struct timespec *time,
+uint32_t key, uint32_t state)
+{
+   uint32_t tv_sec_hi, tv_sec_lo, tv_nsec;
+
+   timespec_to_proto(time, &tv_sec_hi, &tv_sec_lo, &tv_nsec);
+   weston_test_send_key(client->test->weston_test, tv_sec_hi, tv_sec_lo,
+tv_nsec, key, state);
+   client_roundtrip(client);
+}
+
 TEST(simple_keyboard_test)
 {
-   struct client *client;
-   struct surface *expect_focus = NULL;
-   struct keyboard *keyboard;
+   struct client *client = create_client_with_keyboard_focus();
+   struct keyboard *keyboard = client->input->keyboard;
+   struct surface *expect_focus = client->surface;
uint32_t expect_key = 0;
uint32_t expect_state = 0;
 
-   client = create_client_and_test_surface(10, 10, 1, 1);
-   assert(client);
-
-   keyboard = client->input->keyboard;
-
while (1) {
assert(keyboard->key == expect_key);
assert(keyboard->state == expect_state);
@@ -49,8 +73,7 @@ TEST(simple_keyboard_test)
 
if (keyboard->state == WL_KEYBOARD_KEY_STATE_PRESSED) {
expect_state = WL_KEYBOARD_KEY_STATE_RELEASED;
-   weston_test_send_key(client->test->weston_test,
-expect_key, expect_state);
+   send_key(client, &t1, expect_key, expect_state);
} else if (keyboard->focus) {
expect_focus = NULL;
weston_test_activate_surface(
@@ -62,8 +85,7 @@ TEST(simple_keyboard_test)
weston_test_activate_surface(
client->test->weston_test,
expect_focus->wl_surface);
-   weston_test_send_key(client->test->weston_test,
-expect_key, expect_state);
+   send_key(client, &t1, expect_key, expect_state);
} else {
break;
}
@@ -71,3 +93,15 @@ TEST(simple_keyboard_test)
client_roundtrip(client);
}
 }
+
+TEST(keyboard_key_event_time)
+{
+   struct client *client = create_client_with_keyboard_focus();
+   struct keyboard *keyboard = client->input->keyboard;
+
+   send_key(client, &t1, 0, WL_KEYBOARD_KEY_STATE_PRESSED);
+   assert(keyboard->key_time == timespec_to_msec(&t1));
+
+   send_key(client, &t2, 0, WL_KEYBOARD_KEY_STATE_RELEASED);
+   assert(keyboard->key_time == timespec_to_msec(&t2));
+}
diff --git a/tests/weston-test-client-helper.c 
b/tests/weston-test-client-helper.c
index 92def14d..ef58d77a 100644
--- a/tests/weston-test-client-helper.c
+++ b/tests/weston-test-client-helper.c
@@ -280,6 +280,7 @@ keyboard_handle_key(void *data, struct wl_keyboard 
*wl_keyboard,
 
keyboard->key = key;
keyboard->state = state;
+   keyboard->key_time = time;
 
fprintf(stderr, "test-client: got keyboard key %u %u\n", key, state);
 }
diff --git a/tests/weston-test-client-helper.h 
b/tests/weston-test-client-helper.h
index 1b4d83c7..1be727c1 100644
--- a/tests/weston-test-client-helper.h
+++ b/tests/weston-test-client-helper.h
@@ -111,6 +111,7 @@ 

[PATCH weston 6/8] tests: Add test for pointer axis events

2017-12-04 Thread Alexandros Frantzis
Add test to verify the server correctly emits pointer axis events.  This
requires updating the weston-test protocol with a new request for
pointer axis events.

Signed-off-by: Alexandros Frantzis 
---
 protocol/weston-test.xml  |  7 +++
 tests/pointer-test.c  | 28 
 tests/weston-test-client-helper.c | 13 -
 tests/weston-test-client-helper.h |  4 
 tests/weston-test.c   | 20 
 5 files changed, 71 insertions(+), 1 deletion(-)

diff --git a/protocol/weston-test.xml b/protocol/weston-test.xml
index ae3349ed..a4a7ad4e 100644
--- a/protocol/weston-test.xml
+++ b/protocol/weston-test.xml
@@ -53,6 +53,13 @@
   
   
 
+
+  
+  
+  
+  
+  
+
 
   
 
diff --git a/tests/pointer-test.c b/tests/pointer-test.c
index c241fa1d..b0eb6f6f 100644
--- a/tests/pointer-test.c
+++ b/tests/pointer-test.c
@@ -58,6 +58,18 @@ send_button(struct client *client, const struct timespec 
*time,
client_roundtrip(client);
 }
 
+static void
+send_axis(struct client *client, const struct timespec *time, uint32_t axis,
+ double value)
+{
+   uint32_t tv_sec_hi, tv_sec_lo, tv_nsec;
+
+   timespec_to_proto(time, &tv_sec_hi, &tv_sec_lo, &tv_nsec);
+   weston_test_send_axis(client->test->weston_test, tv_sec_hi, tv_sec_lo,
+ tv_nsec, axis, wl_fixed_from_double(value));
+   client_roundtrip(client);
+}
+
 static void
 check_pointer(struct client *client, int x, int y)
 {
@@ -355,3 +367,19 @@ TEST(pointer_button_events)
assert(pointer->state == WL_POINTER_BUTTON_STATE_RELEASED);
assert(pointer->button_time == timespec_to_msec(&t2));
 }
+
+TEST(pointer_axis_events)
+{
+   struct client *client = create_client_with_pointer_focus(100, 100,
+100, 100);
+   struct pointer *pointer = client->input->pointer;
+
+   send_axis(client, &t1, 1, 1.0);
+   assert(pointer->axis == 1);
+   assert(pointer->axis_value == 1.0);
+   assert(pointer->axis_time == timespec_to_msec(&t1));
+
+   send_axis(client, &t2, 2, 0.0);
+   assert(pointer->axis == 2);
+   assert(pointer->axis_stop_time == timespec_to_msec(&t2));
+}
diff --git a/tests/weston-test-client-helper.c 
b/tests/weston-test-client-helper.c
index 108fecfb..92def14d 100644
--- a/tests/weston-test-client-helper.c
+++ b/tests/weston-test-client-helper.c
@@ -179,6 +179,12 @@ static void
 pointer_handle_axis(void *data, struct wl_pointer *wl_pointer,
uint32_t time, uint32_t axis, wl_fixed_t value)
 {
+   struct pointer *pointer = data;
+
+   pointer->axis = axis;
+   pointer->axis_value = wl_fixed_to_double(value);
+   pointer->axis_time = time;
+
fprintf(stderr, "test-client: got pointer axis %u %f\n",
axis, wl_fixed_to_double(value));
 }
@@ -200,7 +206,12 @@ static void
 pointer_handle_axis_stop(void *data, struct wl_pointer *wl_pointer,
 uint32_t time, uint32_t axis)
 {
-   fprintf(stderr, "test-client: got pointer axis stop\n");
+   struct pointer *pointer = data;
+
+   pointer->axis = axis;
+   pointer->axis_stop_time = time;
+
+   fprintf(stderr, "test-client: got pointer axis stop %u\n", axis);
 }
 
 static void
diff --git a/tests/weston-test-client-helper.h 
b/tests/weston-test-client-helper.h
index 08817242..1b4d83c7 100644
--- a/tests/weston-test-client-helper.h
+++ b/tests/weston-test-client-helper.h
@@ -90,8 +90,12 @@ struct pointer {
int y;
uint32_t button;
uint32_t state;
+   uint32_t axis;
+   double axis_value;
uint32_t motion_time;
uint32_t button_time;
+   double axis_time;
+   double axis_stop_time;
 };
 
 struct keyboard {
diff --git a/tests/weston-test.c b/tests/weston-test.c
index 1799de92..bb1a4cd4 100644
--- a/tests/weston-test.c
+++ b/tests/weston-test.c
@@ -183,6 +183,25 @@ send_button(struct wl_client *client, struct wl_resource 
*resource,
notify_button(seat, &time, button, state);
 }
 
+static void
+send_axis(struct wl_client *client, struct wl_resource *resource,
+ uint32_t tv_sec_hi, uint32_t tv_sec_lo, uint32_t tv_nsec,
+ uint32_t axis, wl_fixed_t value)
+{
+   struct weston_test *test = wl_resource_get_user_data(resource);
+   struct weston_seat *seat = get_seat(test);
+   struct timespec time;
+   struct weston_pointer_axis_event axis_event;
+
+   timespec_from_proto(&time, tv_sec_hi, tv_sec_lo, tv_nsec);
+   axis_event.axis = axis;
+   axis_event.value = wl_fixed_to_double(value);
+   axis_event.has_discrete = false;
+   axis_event.discrete = 0;
+
+   notify_axis(seat, &time, &axis_event);
+}
+
 static void
 

[PATCH weston 8/8] tests: Add test for touch event timestamps

2017-12-04 Thread Alexandros Frantzis
Add test to verify that the server correctly sets the timestamps of
touch events. This requires updating the weston-test protocol with a new
request for touch events.

Signed-off-by: Alexandros Frantzis 
---
 Makefile.am   |  7 +++-
 protocol/weston-test.xml  |  9 +
 tests/touch-test.c| 71 +++
 tests/weston-test-client-helper.c |  3 ++
 tests/weston-test-client-helper.h |  3 ++
 tests/weston-test.c   | 16 +
 6 files changed, 108 insertions(+), 1 deletion(-)
 create mode 100644 tests/touch-test.c

diff --git a/Makefile.am b/Makefile.am
index 47b110df..c7141734 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1231,7 +1231,8 @@ weston_tests =\
roles.weston\
subsurface.weston   \
subsurface-shot.weston  \
-   devices.weston
+   devices.weston  \
+   touch.weston
 
 ivi_tests =
 
@@ -1426,6 +1427,10 @@ nodist_viewporter_weston_SOURCES =   \
 viewporter_weston_CFLAGS = $(AM_CFLAGS) $(TEST_CLIENT_CFLAGS)
 viewporter_weston_LDADD = libtest-client.la
 
+touch_weston_SOURCES = tests/touch-test.c
+touch_weston_CFLAGS = $(AM_CFLAGS) $(TEST_CLIENT_CFLAGS)
+touch_weston_LDADD = libtest-client.la
+
 if ENABLE_XWAYLAND_TEST
 weston_tests +=xwayland-test.weston
 xwayland_test_weston_SOURCES = tests/xwayland-test.c
diff --git a/protocol/weston-test.xml b/protocol/weston-test.xml
index 37fa221f..00b7185d 100644
--- a/protocol/weston-test.xml
+++ b/protocol/weston-test.xml
@@ -96,6 +96,15 @@
provided buffer.
  
 
+
+  
+  
+  
+  
+  
+  
+  
+
   
 
   
diff --git a/tests/touch-test.c b/tests/touch-test.c
new file mode 100644
index ..374df116
--- /dev/null
+++ b/tests/touch-test.c
@@ -0,0 +1,71 @@
+/*
+ * 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 
+
+#include "shared/timespec-util.h"
+#include "weston-test-client-helper.h"
+#include "wayland-server-protocol.h"
+
+static const struct timespec t1 = { .tv_sec = 1, .tv_nsec = 101 };
+static const struct timespec t2 = { .tv_sec = 2, .tv_nsec = 201 };
+static const struct timespec t3 = { .tv_sec = 3, .tv_nsec = 301 };
+
+static struct client *
+create_touch_test_client(void)
+{
+   struct client *cl = create_client_and_test_surface(0, 0, 100, 100);
+   assert(cl);
+   return cl;
+}
+
+static void
+send_touch(struct client *client, const struct timespec *time,
+  uint32_t touch_type)
+{
+   uint32_t tv_sec_hi, tv_sec_lo, tv_nsec;
+
+   timespec_to_proto(time, &tv_sec_hi, &tv_sec_lo, &tv_nsec);
+   weston_test_send_touch(client->test->weston_test, tv_sec_hi, tv_sec_lo,
+  tv_nsec, 1, 1, 1, touch_type);
+   client_roundtrip(client);
+}
+
+TEST(touch_events)
+{
+   struct client *client = create_touch_test_client();
+   struct touch *touch = client->input->touch;
+
+   send_touch(client, &t1, WL_TOUCH_DOWN);
+   assert(touch->down_time == timespec_to_msec(&t1));
+
+   send_touch(client, &t2, WL_TOUCH_MOTION);
+   assert(touch->motion_time == timespec_to_msec(&t2));
+
+   send_touch(client, &t3, WL_TOUCH_UP);
+   assert(touch->up_time == timespec_to_msec(&t3));
+}
diff --git a/tests/weston-test-client-helper.c 
b/tests/weston-test-client-helper.c
index ef58d77a..7266e028 100644
--- a/tests/weston-test-client-helper.c
+++ b/tests/weston-test-client-helper.c
@@ -334,6 +334,7 @@ touch_handle_down(void *data, struct wl_touch *wl_touch,
touch->down_x = wl_

[PATCH wayland-protocols] unstable: Add input-timestamps protocol

2017-12-05 Thread Alexandros Frantzis
wl_pointer, wl_keyboard and wl_touch events currently use a 32-bit
timestamp with millisecond resolution. In some cases, notably latency
measurements, this resolution is too coarse to be useful.

This protocol provides additional high-resolution timestamps events,
which are emitted before the corresponding input event. Each timestamp
event contains a high-resolution, and ideally higher-accuracy, version
of the 'time' argument of the first subsequent supported input event.

Clients that care about high-resolution timestamps just need to keep
track of the last timestamp event they receive and associate it with the
next supported input event that arrives.

Signed-off-by: Alexandros Frantzis 
---
 Makefile.am|   1 +
 unstable/input-timestamps/README   |   4 +
 .../input-timestamps-unstable-v1.xml   | 138 +
 3 files changed, 143 insertions(+)
 create mode 100644 unstable/input-timestamps/README
 create mode 100644 unstable/input-timestamps/input-timestamps-unstable-v1.xml

diff --git a/Makefile.am b/Makefile.am
index cabc279..4b9a901 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -16,6 +16,7 @@ unstable_protocols =  
\
unstable/xwayland-keyboard-grab/xwayland-keyboard-grab-unstable-v1.xml  
\

unstable/keyboard-shortcuts-inhibit/keyboard-shortcuts-inhibit-unstable-v1.xml \
unstable/xdg-output/xdg-output-unstable-v1.xml  
\
+   unstable/input-timestamps/input-timestamps-unstable-v1.xml  \
$(NULL)
 
 stable_protocols = 
\
diff --git a/unstable/input-timestamps/README b/unstable/input-timestamps/README
new file mode 100644
index 000..3e82890
--- /dev/null
+++ b/unstable/input-timestamps/README
@@ -0,0 +1,4 @@
+High-resolution timestamps for input events.
+
+Maintainers:
+Alexandros Frantzis 
diff --git a/unstable/input-timestamps/input-timestamps-unstable-v1.xml 
b/unstable/input-timestamps/input-timestamps-unstable-v1.xml
new file mode 100644
index 000..5a9d120
--- /dev/null
+++ b/unstable/input-timestamps/input-timestamps-unstable-v1.xml
@@ -0,0 +1,138 @@
+
+
+
+  
+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.
+  
+
+  
+This protocol specifies a way for a client to request and receive
+high-resolution timestamps for input events.
+
+Warning! The protocol described in this file is experimental and
+backward incompatible changes may be made. Backward compatible changes
+may be added together with the corresponding interface version bump.
+Backward incompatible changes are done by bumping the version number in
+the protocol and interface names and resetting the interface version.
+Once the protocol is to be declared stable, the 'z' prefix and the
+version number in the protocol and interface names are removed and the
+interface version number is reset.
+  
+
+  
+
+  A global interface used for requesting high-resolution timestamps
+  for input events.
+
+
+
+  
+Informs the server that the client will no longer be using this
+protocol object. Existing objects created by this object are not
+affected.
+  
+
+
+
+  
+Creates a new input timestamps object that represents a subscription
+to high-resolution timestamp events for all wl_keyboard events that
+carry a timestamp.
+
+If the associated wl_keyboard object is invalidated, either through
+client action (e.g. release) or server-side changes, the input
+timestamps object becomes inert and the client should destroy it
+by calling zwp_input_timestamps_v1.destroy.
+  
+  
+  

Re: [PATCH wayland-protocols] unstable: Add input-timestamps protocol

2017-12-05 Thread Alexandros Frantzis
On Tue, Dec 05, 2017 at 06:07:02PM +0200, Alexandros Frantzis wrote:
> wl_pointer, wl_keyboard and wl_touch events currently use a 32-bit
> timestamp with millisecond resolution. In some cases, notably latency
> measurements, this resolution is too coarse to be useful.
> 
> This protocol provides additional high-resolution timestamps events,
> which are emitted before the corresponding input event. Each timestamp
> event contains a high-resolution, and ideally higher-accuracy, version
> of the 'time' argument of the first subsequent supported input event.
> 
> Clients that care about high-resolution timestamps just need to keep
> track of the last timestamp event they receive and associate it with the
> next supported input event that arrives.
> 

Hi all,

a few additional discussion notes (some copied from the RFC discussion):

1. Supported pointer/keyboard/touch events

   At the moment the protocol is phrased to be forward-compatible with
   new pointer/keyboard/touch events. For example, for touch:

   "represents a subscription to high-resolution timestamp events for
   for all wl_touch events that carry a timestamp."

   This guards against making input-timestamps protocol updates for new
   input events (unless we add a new input category), and is easy to
   implement in practice.

2. Timestamp accuracy guarantee

   Currently: "The timestamp provided by this event ... is at least as
   accurate as the associated input event timestamp."

   In a previous discussion it was suggested that an option would be for
   the server to advertise support for this protocol only if it can
   provide better (than millisecond) accuracy. My concern with such an
   approach is that there may be cases where only some input objects can
   provide high-accuracy timestamps, so the guarantee may not be
   globally applicable.

3. Clocks domains

   The high-resolution timestamps are guaranteed to be in the same clock
   domain as the input event timestamps (for which the clock domain is
   currently unspecified).

4. Support for input events from unstable protocols (e.g. tablet)
   
   I opted not to include support for input events from unstable
   protocols. The rationale is that this protocol was created in order
   to fix the deficiencies (for certain use cases) of protocols that we
   are unable to change due to compatibility restrictions. Unstable
   protocols are not subject to such restrictions and can therefore be
   updated to use high-resolution timestamps instead of relying on an
   external protocol to provide such functionality.

5. Frame event timestamps

   It was suggested that this protocol could provide timestamps for
   frame events which currently don't carry one in the core protocol. In
   this proposal I have chosen to maintain consistency with the way
   timestamps are emitted in the core protocol, i.e., emit timestamp
   events only for input events that already carry a timestamp. Adding a
   frame timestamp when one is not already present would also further
   complicate client implementations that need to support falling back
   to the normal timestamps when this protocol is not present.

A proof of concept implementation for weston can be found at:

https://gitlab.collabora.com/alf/weston/commits/zwp-input-timestamps

Thanks,
Alexandros
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


Re: [PATCH weston 1/8] shared: Add timespec_normalize helper

2017-12-12 Thread Alexandros Frantzis
On Tue, Dec 12, 2017 at 11:50:49AM +0200, Pekka Paalanen wrote:
> On Mon,  4 Dec 2017 15:34:01 +0200
> Alexandros Frantzis  wrote:
> 
> > Add a helper function to normalize struct timespec values so that the
> > nanoseconds part is less than 1 second and has the same sign as the
> > seconds part (if the seconds part is not 0).
> > 
> > Normalization is required to ensure we can safely convert timespec
> > values to wayland protocol data, i.e, to tv_sec_hi, tv_sec_lo,
> > tv_sec_nsec triplets, and will be used in upcoming commits.
> > 
> > Signed-off-by: Alexandros Frantzis 
> > ---
> >  shared/timespec-util.h | 28 ++
> >  tests/timespec-test.c  | 65 
> > ++
> >  2 files changed, 93 insertions(+)
> > 
> > diff --git a/shared/timespec-util.h b/shared/timespec-util.h
> > index f9736c27..a10edf5b 100644
> > --- a/shared/timespec-util.h
> > +++ b/shared/timespec-util.h
> > @@ -33,6 +33,34 @@
> >  
> >  #define NSEC_PER_SEC 10
> >  
> > +/* Normalize a timespec
> > + *
> > + * \param r[out] normalized timespec
> > + * \param a[in] timespec to normalize
> > + *
> > + * Normalize a timespec so that tv_nsec is less than 1 second
> > + * and has the same sign as tv_sec (if tv_sec is non-zero).
> 
> Hi,

Hi Pekka,

thanks for the review.

> why does it need to have the same sign?
> E.g. timespec_sub() ensures nsec is non-negative, as do the add
> functions.

The goal was to make timespec_normalize more generally useful and
independent of any current behavior. I didn't want to assume that the
provided timespec would be produced necessarily by using the
aforementioned functions that already provide the same-sign guarantee.

> Otherwise this is fine, but I would also have the protocol spec forbid
> non-normalized timespec values like the presentation-timing extension
> does.

That's a good point. I will update the input-timestamps spec wording.

Thanks,
Alexandros
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


Re: [PATCH weston 2/8] shared: Add helpers to convert between protocol data and timespec

2017-12-12 Thread Alexandros Frantzis
On Tue, Dec 12, 2017 at 12:09:59PM +0200, Pekka Paalanen wrote:
> On Mon,  4 Dec 2017 15:34:02 +0200
> Alexandros Frantzis  wrote:
> 
> > Add helpers to safely convert between struct timespec values and
> > tv_sec_hi, tv_sec_lo, tv_nsec triplets used for sending high-resolution
> > timestamp data over the wayland protocol. Replace existing conversion
> > code with the helper functions.
> > 
> > Signed-off-by: Alexandros Frantzis 
> > ---
> >  clients/presentation-shm.c |  9 +--
> >  libweston/compositor.c |  9 ---
> >  shared/timespec-util.h | 39 +++
> >  tests/presentation-test.c  |  9 +--
> >  tests/timespec-test.c  | 66 
> > ++
> >  5 files changed, 112 insertions(+), 20 deletions(-)
> 
> Hi,

Hi,

> 
> I have questions below that will have implications to the protocol
> extension spec as well. I would like to require the time values in
> protocol to be normalized.

Ack.

> > 
> > diff --git a/clients/presentation-shm.c b/clients/presentation-shm.c
> > index c9fb66cc..d6a939e5 100644
> > --- a/clients/presentation-shm.c
> > +++ b/clients/presentation-shm.c
> > @@ -39,6 +39,7 @@
> >  #include 
> >  #include "shared/helpers.h"
> >  #include "shared/zalloc.h"
> > +#include "shared/timespec-util.h"
> >  #include "shared/os-compatibility.h"
> >  #include "presentation-time-client-protocol.h"
> >  
> > @@ -383,14 +384,6 @@ timespec_to_ms(const struct timespec *ts)
> > return (uint32_t)ts->tv_sec * 1000 + ts->tv_nsec / 100;
> >  }
> >  
> > -static void
> > -timespec_from_proto(struct timespec *tm, uint32_t tv_sec_hi,
> > -   uint32_t tv_sec_lo, uint32_t tv_nsec)
> > -{
> > -   tm->tv_sec = ((uint64_t)tv_sec_hi << 32) + tv_sec_lo;
> > -   tm->tv_nsec = tv_nsec;
> > -}
> > -
> >  static int
> >  timespec_diff_to_usec(const struct timespec *a, const struct timespec *b)
> >  {
> > diff --git a/libweston/compositor.c b/libweston/compositor.c
> > index 7d7a17ed..083664fd 100644
> > --- a/libweston/compositor.c
> > +++ b/libweston/compositor.c
> > @@ -341,7 +341,9 @@ weston_presentation_feedback_present(
> >  {
> > struct wl_client *client = wl_resource_get_client(feedback->resource);
> > struct wl_resource *o;
> > -   uint64_t secs;
> > +   uint32_t tv_sec_hi;
> > +   uint32_t tv_sec_lo;
> > +   uint32_t tv_nsec;
> 
> A suggestion: how about introducing
> 
> struct timespec_proto {
>   uint32_t sec_hi;
>   uint32_t sec_lo;
>   uint32_t nsec;
> };
> 
> and using that in timespec_to_proto()?
> 
> (Not useful for timespec_from_proto() because the three variables are
> already declared.)

I am not opposed to introducing a struct timespec_proto in general, but
using it in only one of the two functions feels inconsistent.

> > wl_resource_for_each(o, &output->resource_list) {
> > if (wl_resource_get_client(o) != client)
> > @@ -350,10 +352,9 @@ weston_presentation_feedback_present(
> > wp_presentation_feedback_send_sync_output(feedback->resource, 
> > o);
> > }
> >  
> > -   secs = ts->tv_sec;
> > +   timespec_to_proto(ts, &tv_sec_hi, &tv_sec_lo, &tv_nsec);
> > wp_presentation_feedback_send_presented(feedback->resource,
> > -   secs >> 32, secs & 0x,
> > -   ts->tv_nsec,
> > +   tv_sec_hi, tv_sec_lo, tv_nsec,
> > refresh_nsec,
> > seq >> 32, seq & 0x,
> > flags | feedback->psf_flags);
> > diff --git a/shared/timespec-util.h b/shared/timespec-util.h
> > index a10edf5b..c734accd 100644
> > --- a/shared/timespec-util.h
> > +++ b/shared/timespec-util.h
> > @@ -175,6 +175,30 @@ timespec_to_usec(const struct timespec *a)
> > return (int64_t)a->tv_sec * 100 + a->tv_nsec / 1000;
> >  }
> >  
> > +/* Convert timespec to protocol data
> > + *
> > + * \param a timespec
> > + * \param tv_sec_hi[out] the high bytes of the seconds part
> > + * \param tv_sec_lo[out] the low bytes of the seconds part
> > + * \param tv_nsec[out] the nanoseconds part
> > + *
> > + * The timespec is normalized befo

Re: [PATCH weston 1/8] shared: Add timespec_normalize helper

2017-12-12 Thread Alexandros Frantzis
On Tue, Dec 12, 2017 at 12:55:27PM +0200, Pekka Paalanen wrote:
> On Tue, 12 Dec 2017 12:36:39 +0200
> Alexandros Frantzis  wrote:
> 
> > On Tue, Dec 12, 2017 at 11:50:49AM +0200, Pekka Paalanen wrote:
> > > On Mon,  4 Dec 2017 15:34:01 +0200
> > > Alexandros Frantzis  wrote:
> > >   
> > > > Add a helper function to normalize struct timespec values so that the
> > > > nanoseconds part is less than 1 second and has the same sign as the
> > > > seconds part (if the seconds part is not 0).
> > > > 
> > > > Normalization is required to ensure we can safely convert timespec
> > > > values to wayland protocol data, i.e, to tv_sec_hi, tv_sec_lo,
> > > > tv_sec_nsec triplets, and will be used in upcoming commits.
> > > > 
> > > > Signed-off-by: Alexandros Frantzis 
> > > > ---
> > > >  shared/timespec-util.h | 28 ++
> > > >  tests/timespec-test.c  | 65 
> > > > ++
> > > >  2 files changed, 93 insertions(+)
> > > > 
> > > > diff --git a/shared/timespec-util.h b/shared/timespec-util.h
> > > > index f9736c27..a10edf5b 100644
> > > > --- a/shared/timespec-util.h
> > > > +++ b/shared/timespec-util.h
> > > > @@ -33,6 +33,34 @@
> > > >  
> > > >  #define NSEC_PER_SEC 10
> > > >  
> > > > +/* Normalize a timespec
> > > > + *
> > > > + * \param r[out] normalized timespec
> > > > + * \param a[in] timespec to normalize
> > > > + *
> > > > + * Normalize a timespec so that tv_nsec is less than 1 second
> > > > + * and has the same sign as tv_sec (if tv_sec is non-zero).  
> > > 
> > > Hi,  
> > 
> > Hi Pekka,
> > 
> > thanks for the review.
> > 
> > > why does it need to have the same sign?
> > > E.g. timespec_sub() ensures nsec is non-negative, as do the add
> > > functions.  
> > 
> > The goal was to make timespec_normalize more generally useful and
> > independent of any current behavior. I didn't want to assume that the
> > provided timespec would be produced necessarily by using the
> > aforementioned functions that already provide the same-sign guarantee.
> 
> They don't provide the same-sign guarantee. They ensure nsec is
> non-negative, regardless of the sign of sec.

Ah, I misunderstood.

> The question here is, what is the normalized form?
>
> We have not had use for negative time values in the protocol, and the
> new proposal does not either, so protocol specs do not offer any
> precendent. Computationally they could appear in programs, so the
> definition of "normalized" for these helper functions will be purely
> libweston-internal.
> 
> I'd go with non-negative instead of same-sign, because the existing
> code is already like that. I'd like to hear about any better
> justification one way or another, since I have little else. I believe
> non-negative lead to simpler code.

The main justification for same sign is a more intuitive representation
for humans. That is, it's more natural to think of -1.5 as -1 + -0.5,
rather than -2 + 0.5.

However, that's not a problem from the computer's point of view and I
had missed the pre-existing non-negative nsec guarantee in other
functions.  Also, since in the normalized form nsec < 1 sec, checking
the sign of tv_sec is enough to determine the sign of the timespec which
is a nice property to maintain.

So, bottom line, I am convinced. I will change timespec_normalize to
provide the non-negative nsec guarantee.

Thanks,
Alexandros
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


Re: [PATCH weston 5/8] tests: Add checks for pointer motion and button event timestamps

2017-12-12 Thread Alexandros Frantzis
On Tue, Dec 12, 2017 at 02:13:26PM +0200, Pekka Paalanen wrote:
> On Mon,  4 Dec 2017 15:34:05 +0200
> Alexandros Frantzis  wrote:
> 
> > Enhance the existing pointer motion and button event tests to
> > additionally verify the event timestamps. This requires updating the
> > weston-test protocol to support passing motion and button event
> > timestamps.
> > 
> > Signed-off-by: Alexandros Frantzis 
> > ---
> >  protocol/weston-test.xml  |  6 ++
> >  tests/internal-screenshot-test.c  |  2 +-
> >  tests/pointer-test.c  | 45 
> > ++-
> >  tests/subsurface-shot-test.c  |  2 +-
> >  tests/weston-test-client-helper.c |  2 ++
> >  tests/weston-test-client-helper.h |  2 ++
> >  tests/weston-test.c   |  6 --
> >  7 files changed, 51 insertions(+), 14 deletions(-)
> > 
> > diff --git a/protocol/weston-test.xml b/protocol/weston-test.xml
> > index 74a15214..ae3349ed 100644
> > --- a/protocol/weston-test.xml
> > +++ b/protocol/weston-test.xml
> > @@ -40,10 +40,16 @@
> >
> >  
> >  
> > +  
> > +  
> > +  
> >
> >
> >  
> >  
> > +  
> > +  
> > +  
> >
> >
> >  
> 
> Hi Alf,
> 
> this patch looks good, just one idea below.

Hi Pekka,

> > diff --git a/tests/weston-test-client-helper.h 
> > b/tests/weston-test-client-helper.h
> > index a288af7e..08817242 100644
> > --- a/tests/weston-test-client-helper.h
> > +++ b/tests/weston-test-client-helper.h
> > @@ -90,6 +90,8 @@ struct pointer {
> > int y;
> > uint32_t button;
> > uint32_t state;
> > +   uint32_t motion_time;
> > +   uint32_t button_time;
> 
> I assume these will either be replaced or complemented with the precise
> timestamp values in the future. For that and also in general, it would
> be nice to use names like motion_msec or motion_time_msec to carry the
> units. Personally I've found it very easy to forget what they are
> otherwise.
> 
> This applies to all patches in this series.

In the current iteration of the Weston input-timestamps proof of concept
branch I am using a different test helper object to store the precise
timestamps (I wanted to keep non-core functionality separate), so there
is no confusion, but of course this may change.

Regardless of the above, I named the variables after the event name
fields (e.g. motion.time), but it's indeed helpful to add the unit info
in the name (since unfortunately it's not part of the type) for clarity.
I will update the code to use the prefix.

Thanks,
Alexandros
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


Re: [PATCH weston 2/8] shared: Add helpers to convert between protocol data and timespec

2017-12-12 Thread Alexandros Frantzis
On Tue, Dec 12, 2017 at 03:09:56PM +0200, Pekka Paalanen wrote:
> On Tue, 12 Dec 2017 14:43:11 +0200
> Alexandros Frantzis  wrote:
> 
> > On Tue, Dec 12, 2017 at 12:09:59PM +0200, Pekka Paalanen wrote:
> > > On Mon,  4 Dec 2017 15:34:02 +0200
> > > Alexandros Frantzis  wrote:
> > >   
> > > > Add helpers to safely convert between struct timespec values and
> > > > tv_sec_hi, tv_sec_lo, tv_nsec triplets used for sending high-resolution
> > > > timestamp data over the wayland protocol. Replace existing conversion
> > > > code with the helper functions.
> > > > 
> > > > Signed-off-by: Alexandros Frantzis 
> > > > ---
> > > >  clients/presentation-shm.c |  9 +--
> > > >  libweston/compositor.c |  9 ---
> > > >  shared/timespec-util.h | 39 +++
> > > >  tests/presentation-test.c  |  9 +--
> > > >  tests/timespec-test.c  | 66 
> > > > ++
> > > >  5 files changed, 112 insertions(+), 20 deletions(-)  
> > > 
> > > Hi,  
> > 
> > Hi,
> > 
> > > 
> > > I have questions below that will have implications to the protocol
> > > extension spec as well. I would like to require the time values in
> > > protocol to be normalized.  
> > 
> > Ack.
> > 
> > > > 
> > > > diff --git a/clients/presentation-shm.c b/clients/presentation-shm.c
> > > > index c9fb66cc..d6a939e5 100644
> > > > --- a/clients/presentation-shm.c
> > > > +++ b/clients/presentation-shm.c
> > > > @@ -39,6 +39,7 @@
> > > >  #include 
> > > >  #include "shared/helpers.h"
> > > >  #include "shared/zalloc.h"
> > > > +#include "shared/timespec-util.h"
> > > >  #include "shared/os-compatibility.h"
> > > >  #include "presentation-time-client-protocol.h"
> > > >  
> > > > @@ -383,14 +384,6 @@ timespec_to_ms(const struct timespec *ts)
> > > > return (uint32_t)ts->tv_sec * 1000 + ts->tv_nsec / 100;
> > > >  }
> > > >  
> > > > -static void
> > > > -timespec_from_proto(struct timespec *tm, uint32_t tv_sec_hi,
> > > > -   uint32_t tv_sec_lo, uint32_t tv_nsec)
> > > > -{
> > > > -   tm->tv_sec = ((uint64_t)tv_sec_hi << 32) + tv_sec_lo;
> > > > -   tm->tv_nsec = tv_nsec;
> > > > -}
> > > > -
> > > >  static int
> > > >  timespec_diff_to_usec(const struct timespec *a, const struct timespec 
> > > > *b)
> > > >  {
> > > > diff --git a/libweston/compositor.c b/libweston/compositor.c
> > > > index 7d7a17ed..083664fd 100644
> > > > --- a/libweston/compositor.c
> > > > +++ b/libweston/compositor.c
> > > > @@ -341,7 +341,9 @@ weston_presentation_feedback_present(
> > > >  {
> > > > struct wl_client *client = 
> > > > wl_resource_get_client(feedback->resource);
> > > > struct wl_resource *o;
> > > > -   uint64_t secs;
> > > > +   uint32_t tv_sec_hi;
> > > > +   uint32_t tv_sec_lo;
> > > > +   uint32_t tv_nsec;  
> > > 
> > > A suggestion: how about introducing
> > > 
> > > struct timespec_proto {
> > >   uint32_t sec_hi;
> > >   uint32_t sec_lo;
> > >   uint32_t nsec;
> > > };
> > > 
> > > and using that in timespec_to_proto()?
> > > 
> > > (Not useful for timespec_from_proto() because the three variables are
> > > already declared.)  
> > 
> > I am not opposed to introducing a struct timespec_proto in general, but
> > using it in only one of the two functions feels inconsistent.
> 
> Ok. I was thinking of saving in the number of local variables on every
> call site of timespec_to_proto().
> 
> > > > wl_resource_for_each(o, &output->resource_list) {
> > > > if (wl_resource_get_client(o) != client)
> > > > @@ -350,10 +352,9 @@ weston_presentation_feedback_present(
> > > > 
> > > > wp_presentation_feedback_send_sync_output(feedback->resource, o);
> > > > }
> > > >  
> > > > -   secs = ts->tv_sec;
> > > > +   timespec_to_proto(ts, &tv_sec_

[PATCH weston v2 3/6] tests: Add checks for pointer motion and button event timestamps

2017-12-13 Thread Alexandros Frantzis
Enhance the existing pointer motion and button event tests to
additionally verify the event timestamps. This requires updating the
weston-test protocol to support passing motion and button event
timestamps.

Signed-off-by: Alexandros Frantzis 
---

Changes in v2:
 - Add unit suffix "msec" to variables that hold event time.

 protocol/weston-test.xml  |  6 ++
 tests/internal-screenshot-test.c  |  2 +-
 tests/pointer-test.c  | 45 ++-
 tests/subsurface-shot-test.c  |  2 +-
 tests/weston-test-client-helper.c |  6 --
 tests/weston-test-client-helper.h |  2 ++
 tests/weston-test.c   |  6 --
 7 files changed, 53 insertions(+), 16 deletions(-)

diff --git a/protocol/weston-test.xml b/protocol/weston-test.xml
index 74a15214..ae3349ed 100644
--- a/protocol/weston-test.xml
+++ b/protocol/weston-test.xml
@@ -40,10 +40,16 @@
   
 
 
+  
+  
+  
   
   
 
 
+  
+  
+  
   
   
 
diff --git a/tests/internal-screenshot-test.c b/tests/internal-screenshot-test.c
index 3bf9b31b..2a7424b8 100644
--- a/tests/internal-screenshot-test.c
+++ b/tests/internal-screenshot-test.c
@@ -97,7 +97,7 @@ TEST(internal_screenshot)
 */
 
/* Move the pointer away from the screenshot area. */
-   weston_test_move_pointer(client->test->weston_test, 0, 0);
+   weston_test_move_pointer(client->test->weston_test, 0, 1, 0, 0, 0);
 
buf = create_shm_buffer_a8r8g8b8(client, 100, 100);
draw_stuff(buf->image);
diff --git a/tests/pointer-test.c b/tests/pointer-test.c
index e0e700e0..61bf83b7 100644
--- a/tests/pointer-test.c
+++ b/tests/pointer-test.c
@@ -28,8 +28,36 @@
 
 #include 
 
+#include "shared/timespec-util.h"
 #include "weston-test-client-helper.h"
 
+static const struct timespec t0 = { .tv_sec = 0, .tv_nsec = 1 };
+static const struct timespec t1 = { .tv_sec = 1, .tv_nsec = 101 };
+static const struct timespec t2 = { .tv_sec = 2, .tv_nsec = 201 };
+
+static void
+send_motion(struct client *client, const struct timespec *time, int x, int y)
+{
+   uint32_t tv_sec_hi, tv_sec_lo, tv_nsec;
+
+   timespec_to_proto(time, &tv_sec_hi, &tv_sec_lo, &tv_nsec);
+   weston_test_move_pointer(client->test->weston_test, tv_sec_hi, 
tv_sec_lo,
+tv_nsec, x, y);
+   client_roundtrip(client);
+}
+
+static void
+send_button(struct client *client, const struct timespec *time,
+   uint32_t button, uint32_t state)
+{
+   uint32_t tv_sec_hi, tv_sec_lo, tv_nsec;
+
+   timespec_to_proto(time, &tv_sec_hi, &tv_sec_lo, &tv_nsec);
+   weston_test_send_button(client->test->weston_test, tv_sec_hi, tv_sec_lo,
+   tv_nsec, button, state);
+   client_roundtrip(client);
+}
+
 static void
 check_pointer(struct client *client, int x, int y)
 {
@@ -64,8 +92,7 @@ check_pointer(struct client *client, int x, int y)
 static void
 check_pointer_move(struct client *client, int x, int y)
 {
-   weston_test_move_pointer(client->test->weston_test, x, y);
-   client_roundtrip(client);
+   send_motion(client, &t0, x, y);
check_pointer(client, x, y);
 }
 
@@ -303,10 +330,10 @@ TEST(pointer_motion_events)
 100, 100);
struct pointer *pointer = client->input->pointer;
 
-   weston_test_move_pointer(client->test->weston_test, 150, 150);
-   client_roundtrip(client);
+   send_motion(client, &t1, 150, 150);
assert(pointer->x == 50);
assert(pointer->y == 50);
+   assert(pointer->motion_time_msec == timespec_to_msec(&t1));
 }
 
 TEST(pointer_button_events)
@@ -318,15 +345,13 @@ TEST(pointer_button_events)
assert(pointer->button == 0);
assert(pointer->state == 0);
 
-   weston_test_send_button(client->test->weston_test, BTN_LEFT,
-   WL_POINTER_BUTTON_STATE_PRESSED);
-   client_roundtrip(client);
+   send_button(client, &t1, BTN_LEFT, WL_POINTER_BUTTON_STATE_PRESSED);
assert(pointer->button == BTN_LEFT);
assert(pointer->state == WL_POINTER_BUTTON_STATE_PRESSED);
+   assert(pointer->button_time_msec == timespec_to_msec(&t1));
 
-   weston_test_send_button(client->test->weston_test, BTN_LEFT,
-   WL_POINTER_BUTTON_STATE_RELEASED);
-   client_roundtrip(client);
+   send_button(client, &t2, BTN_LEFT, WL_POINTER_BUTTON_STATE_RELEASED);
assert(pointer->button == BTN_LEFT);
assert(pointer->state == WL_POINTER_BUTTON_STATE_RELEASED);
+   assert(pointer->button_time_msec == timespec_to_msec(&t2));
 }
diff --git a/tests/subsurface-shot-test.c b/tests/subsurface-shot-test.c
index 10415ec7.

[PATCH weston v2 0/6] tests: Add input event timestamp tests

2017-12-13 Thread Alexandros Frantzis
This patchset enhances the test suite with test cases that verify that
the server correctly sets input event timestamps. In the process the
input tests have been reorganized and cleaned up to make it easier to
support the new test cases.

A secondary goal of this patchset is to prepare the test suite for
testing a potential implementation of new high-resolution input
timestamps in the form of a new protocol (discussions on the proposal
are already on-going in the mailing list).

Patches (1) and (2) add timespec helpers to enable conversions
between timespec and protocol data triplets.

Patches (3) to (6) add tests for input events with a focus on verifying
event timestamps.

In v2 of this patchset I have not included the patch that introduces
timespec_normalize ([PATCH weston 1/8]), since normalized timespecs are
now a precondition of the timespec_to_proto helper function, and
existing timespec functions already produce normalized representations.
We can reintroduce it if required, e.g., if we need to normalize
timespecs from untrusted sources.

Patch-specific changes are listed in each individual patch.

Alexandros Frantzis (6):
  shared: Add timespec_from_proto helper function
  shared: Add timespec_to_proto helper function
  tests: Add checks for pointer motion and button event timestamps
  tests: Add test for pointer axis events
  tests: Add test for keyboard key event timestamps
  tests: Add test for touch event timestamps

 Makefile.am   |  7 +++-
 clients/presentation-shm.c|  9 +
 libweston/compositor.c|  9 ++---
 protocol/weston-test.xml  | 25 ++
 shared/timespec-util.h| 39 +
 tests/internal-screenshot-test.c  |  2 +-
 tests/keyboard-test.c | 61 
 tests/pointer-test.c  | 73 +--
 tests/presentation-test.c |  9 +
 tests/subsurface-shot-test.c  |  2 +-
 tests/timespec-test.c | 46 
 tests/touch-test.c| 71 +
 tests/weston-test-client-helper.c | 39 +++--
 tests/weston-test-client-helper.h | 10 ++
 tests/weston-test.c   | 45 ++--
 15 files changed, 387 insertions(+), 60 deletions(-)
 create mode 100644 tests/touch-test.c

-- 
2.14.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH weston v2 1/6] shared: Add timespec_from_proto helper function

2017-12-13 Thread Alexandros Frantzis
Add helper function to convert tv_sec_hi, tv_sec_lo, tv_nsec triplets,
used for sending high-resolution timestamp data over the wayland
protocol, to struct timespec values. Replace existing conversion code
with the helper function.

Signed-off-by: Alexandros Frantzis 
---

Changes in v2:
 - New patch, previously part of [PATCH weston 2/8].
 - Cast long long value to time_t to ensure correct check in test.

 clients/presentation-shm.c |  9 +
 shared/timespec-util.h | 15 +++
 tests/presentation-test.c  |  9 +
 tests/timespec-test.c  | 17 +
 4 files changed, 34 insertions(+), 16 deletions(-)

diff --git a/clients/presentation-shm.c b/clients/presentation-shm.c
index c9fb66cc..d6a939e5 100644
--- a/clients/presentation-shm.c
+++ b/clients/presentation-shm.c
@@ -39,6 +39,7 @@
 #include 
 #include "shared/helpers.h"
 #include "shared/zalloc.h"
+#include "shared/timespec-util.h"
 #include "shared/os-compatibility.h"
 #include "presentation-time-client-protocol.h"
 
@@ -383,14 +384,6 @@ timespec_to_ms(const struct timespec *ts)
return (uint32_t)ts->tv_sec * 1000 + ts->tv_nsec / 100;
 }
 
-static void
-timespec_from_proto(struct timespec *tm, uint32_t tv_sec_hi,
-   uint32_t tv_sec_lo, uint32_t tv_nsec)
-{
-   tm->tv_sec = ((uint64_t)tv_sec_hi << 32) + tv_sec_lo;
-   tm->tv_nsec = tv_nsec;
-}
-
 static int
 timespec_diff_to_usec(const struct timespec *a, const struct timespec *b)
 {
diff --git a/shared/timespec-util.h b/shared/timespec-util.h
index f9736c27..5184d281 100644
--- a/shared/timespec-util.h
+++ b/shared/timespec-util.h
@@ -181,6 +181,21 @@ timespec_from_msec(struct timespec *a, int64_t b)
timespec_from_nsec(a, b * 100);
 }
 
+/* Convert protocol data to timespec
+ *
+ * \param a[out] timespec
+ * \param tv_sec_hi the high bytes of seconds part
+ * \param tv_sec_lo the low bytes of seconds part
+ * \param tv_nsec the nanoseconds part
+ */
+static inline void
+timespec_from_proto(struct timespec *a, uint32_t tv_sec_hi,
+uint32_t tv_sec_lo, uint32_t tv_nsec)
+{
+   a->tv_sec = ((uint64_t)tv_sec_hi << 32) + tv_sec_lo;
+   a->tv_nsec = tv_nsec;
+}
+
 /* Check if a timespec is zero
  *
  * \param a timespec
diff --git a/tests/presentation-test.c b/tests/presentation-test.c
index f12f8eef..f6ffe480 100644
--- a/tests/presentation-test.c
+++ b/tests/presentation-test.c
@@ -34,6 +34,7 @@
 
 #include "shared/helpers.h"
 #include "shared/xalloc.h"
+#include "shared/timespec-util.h"
 #include "weston-test-client-helper.h"
 #include "presentation-time-client-protocol.h"
 
@@ -85,14 +86,6 @@ struct feedback {
uint32_t flags;
 };
 
-static void
-timespec_from_proto(struct timespec *tm, uint32_t tv_sec_hi,
-   uint32_t tv_sec_lo, uint32_t tv_nsec)
-{
-   tm->tv_sec = ((uint64_t)tv_sec_hi << 32) + tv_sec_lo;
-   tm->tv_nsec = tv_nsec;
-}
-
 static void
 feedback_sync_output(void *data,
 struct wp_presentation_feedback *presentation_feedback,
diff --git a/tests/timespec-test.c b/tests/timespec-test.c
index f10ed76c..a4d8dcfb 100644
--- a/tests/timespec-test.c
+++ b/tests/timespec-test.c
@@ -238,6 +238,23 @@ ZUC_TEST(timespec_test, timespec_from_msec)
ZUC_ASSERT_EQ(100, a.tv_nsec);
 }
 
+ZUC_TEST(timespec_test, timespec_from_proto)
+{
+   struct timespec a;
+
+   timespec_from_proto(&a, 0, 0, 0);
+   ZUC_ASSERT_EQ(0, a.tv_sec);
+   ZUC_ASSERT_EQ(0, a.tv_nsec);
+
+   timespec_from_proto(&a, 0, 1234, );
+   ZUC_ASSERT_EQ(1234, a.tv_sec);
+   ZUC_ASSERT_EQ(, a.tv_nsec);
+
+   timespec_from_proto(&a, 0x1234, 0x5678, 1);
+   ZUC_ASSERT_EQ((time_t)0x12345678LL, a.tv_sec);
+   ZUC_ASSERT_EQ(1, a.tv_nsec);
+}
+
 ZUC_TEST(timespec_test, timespec_is_zero)
 {
struct timespec zero = { 0 };
-- 
2.14.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH weston v2 4/6] tests: Add test for pointer axis events

2017-12-13 Thread Alexandros Frantzis
Add test to verify the server correctly emits pointer axis events.  This
requires updating the weston-test protocol with a new request for
pointer axis events.

Signed-off-by: Alexandros Frantzis 
---

Changes in v2:
 - Add unit suffix "msec" to variables that hold event time.

 protocol/weston-test.xml  |  7 +++
 tests/pointer-test.c  | 28 
 tests/weston-test-client-helper.c | 17 ++---
 tests/weston-test-client-helper.h |  4 
 tests/weston-test.c   | 20 
 5 files changed, 73 insertions(+), 3 deletions(-)

diff --git a/protocol/weston-test.xml b/protocol/weston-test.xml
index ae3349ed..a4a7ad4e 100644
--- a/protocol/weston-test.xml
+++ b/protocol/weston-test.xml
@@ -53,6 +53,13 @@
   
   
 
+
+  
+  
+  
+  
+  
+
 
   
 
diff --git a/tests/pointer-test.c b/tests/pointer-test.c
index 61bf83b7..4c438a22 100644
--- a/tests/pointer-test.c
+++ b/tests/pointer-test.c
@@ -58,6 +58,18 @@ send_button(struct client *client, const struct timespec 
*time,
client_roundtrip(client);
 }
 
+static void
+send_axis(struct client *client, const struct timespec *time, uint32_t axis,
+ double value)
+{
+   uint32_t tv_sec_hi, tv_sec_lo, tv_nsec;
+
+   timespec_to_proto(time, &tv_sec_hi, &tv_sec_lo, &tv_nsec);
+   weston_test_send_axis(client->test->weston_test, tv_sec_hi, tv_sec_lo,
+ tv_nsec, axis, wl_fixed_from_double(value));
+   client_roundtrip(client);
+}
+
 static void
 check_pointer(struct client *client, int x, int y)
 {
@@ -355,3 +367,19 @@ TEST(pointer_button_events)
assert(pointer->state == WL_POINTER_BUTTON_STATE_RELEASED);
assert(pointer->button_time_msec == timespec_to_msec(&t2));
 }
+
+TEST(pointer_axis_events)
+{
+   struct client *client = create_client_with_pointer_focus(100, 100,
+100, 100);
+   struct pointer *pointer = client->input->pointer;
+
+   send_axis(client, &t1, 1, 1.0);
+   assert(pointer->axis == 1);
+   assert(pointer->axis_value == 1.0);
+   assert(pointer->axis_time_msec == timespec_to_msec(&t1));
+
+   send_axis(client, &t2, 2, 0.0);
+   assert(pointer->axis == 2);
+   assert(pointer->axis_stop_time_msec == timespec_to_msec(&t2));
+}
diff --git a/tests/weston-test-client-helper.c 
b/tests/weston-test-client-helper.c
index 203cd441..0a6f2a41 100644
--- a/tests/weston-test-client-helper.c
+++ b/tests/weston-test-client-helper.c
@@ -177,8 +177,14 @@ pointer_handle_button(void *data, struct wl_pointer 
*wl_pointer,
 
 static void
 pointer_handle_axis(void *data, struct wl_pointer *wl_pointer,
-   uint32_t time, uint32_t axis, wl_fixed_t value)
+   uint32_t time_msec, uint32_t axis, wl_fixed_t value)
 {
+   struct pointer *pointer = data;
+
+   pointer->axis = axis;
+   pointer->axis_value = wl_fixed_to_double(value);
+   pointer->axis_time_msec = time_msec;
+
fprintf(stderr, "test-client: got pointer axis %u %f\n",
axis, wl_fixed_to_double(value));
 }
@@ -198,9 +204,14 @@ pointer_handle_axis_source(void *data, struct wl_pointer 
*wl_pointer,
 
 static void
 pointer_handle_axis_stop(void *data, struct wl_pointer *wl_pointer,
-uint32_t time, uint32_t axis)
+uint32_t time_msec, uint32_t axis)
 {
-   fprintf(stderr, "test-client: got pointer axis stop\n");
+   struct pointer *pointer = data;
+
+   pointer->axis = axis;
+   pointer->axis_stop_time_msec = time_msec;
+
+   fprintf(stderr, "test-client: got pointer axis stop %u\n", axis);
 }
 
 static void
diff --git a/tests/weston-test-client-helper.h 
b/tests/weston-test-client-helper.h
index 6f5f9c41..76f07491 100644
--- a/tests/weston-test-client-helper.h
+++ b/tests/weston-test-client-helper.h
@@ -90,8 +90,12 @@ struct pointer {
int y;
uint32_t button;
uint32_t state;
+   uint32_t axis;
+   double axis_value;
uint32_t motion_time_msec;
uint32_t button_time_msec;
+   double axis_time_msec;
+   double axis_stop_time_msec;
 };
 
 struct keyboard {
diff --git a/tests/weston-test.c b/tests/weston-test.c
index 1799de92..bb1a4cd4 100644
--- a/tests/weston-test.c
+++ b/tests/weston-test.c
@@ -183,6 +183,25 @@ send_button(struct wl_client *client, struct wl_resource 
*resource,
notify_button(seat, &time, button, state);
 }
 
+static void
+send_axis(struct wl_client *client, struct wl_resource *resource,
+ uint32_t tv_sec_hi, uint32_t tv_sec_lo, uint32_t tv_nsec,
+ uint32_t axis, wl_fixed_t value)
+{
+   struct weston_test *test = wl_resource_get_user_data(resource);
+   

[PATCH weston v2 2/6] shared: Add timespec_to_proto helper function

2017-12-13 Thread Alexandros Frantzis
Add helper function to convert from struct timespec values to tv_sec_hi,
tv_sec_lo, tv_nsec triplets used for sending high-resolution timestamp
data over the wayland protocol. Replace existing conversion code with
the helper function.

Signed-off-by: Alexandros Frantzis 
---

Changes in v2:
 - New patch, previously part of [PATCH weston 2/8].
 - Make normalized and non-negative input timespecs a precondition
   of timespec_to_proto (use assert() to check).
 - Simplify extracting the high and low bytes from the seconds part
   of the timespec in timespec_to_proto.
 - Remove test cases that are now unsupported.

 libweston/compositor.c |  9 +
 shared/timespec-util.h | 24 
 tests/timespec-test.c  | 29 +
 3 files changed, 58 insertions(+), 4 deletions(-)

diff --git a/libweston/compositor.c b/libweston/compositor.c
index 7d7a17ed..083664fd 100644
--- a/libweston/compositor.c
+++ b/libweston/compositor.c
@@ -341,7 +341,9 @@ weston_presentation_feedback_present(
 {
struct wl_client *client = wl_resource_get_client(feedback->resource);
struct wl_resource *o;
-   uint64_t secs;
+   uint32_t tv_sec_hi;
+   uint32_t tv_sec_lo;
+   uint32_t tv_nsec;
 
wl_resource_for_each(o, &output->resource_list) {
if (wl_resource_get_client(o) != client)
@@ -350,10 +352,9 @@ weston_presentation_feedback_present(
wp_presentation_feedback_send_sync_output(feedback->resource, 
o);
}
 
-   secs = ts->tv_sec;
+   timespec_to_proto(ts, &tv_sec_hi, &tv_sec_lo, &tv_nsec);
wp_presentation_feedback_send_presented(feedback->resource,
-   secs >> 32, secs & 0x,
-   ts->tv_nsec,
+   tv_sec_hi, tv_sec_lo, tv_nsec,
refresh_nsec,
seq >> 32, seq & 0x,
flags | feedback->psf_flags);
diff --git a/shared/timespec-util.h b/shared/timespec-util.h
index 5184d281..5f4b2b9e 100644
--- a/shared/timespec-util.h
+++ b/shared/timespec-util.h
@@ -147,6 +147,30 @@ timespec_to_usec(const struct timespec *a)
return (int64_t)a->tv_sec * 100 + a->tv_nsec / 1000;
 }
 
+/* Convert timespec to protocol data
+ *
+ * \param a timespec
+ * \param tv_sec_hi[out] the high bytes of the seconds part
+ * \param tv_sec_lo[out] the low bytes of the seconds part
+ * \param tv_nsec[out] the nanoseconds part
+ *
+ * The input timespec must be normalized (the nanoseconds part should
+ * be less than 1 second) and non-negative.
+ */
+static inline void
+timespec_to_proto(const struct timespec *a, uint32_t *tv_sec_hi,
+  uint32_t *tv_sec_lo, uint32_t *tv_nsec)
+{
+   assert(a->tv_sec >= 0);
+   assert(a->tv_nsec >= 0 && a->tv_nsec < NSEC_PER_SEC);
+
+   uint64_t sec64 = a->tv_sec;
+
+   *tv_sec_hi = sec64 >> 32;
+   *tv_sec_lo = sec64 & 0x;
+   *tv_nsec = a->tv_nsec;
+}
+
 /* Convert nanoseconds to timespec
  *
  * \param a timespec
diff --git a/tests/timespec-test.c b/tests/timespec-test.c
index a4d8dcfb..54230f89 100644
--- a/tests/timespec-test.c
+++ b/tests/timespec-test.c
@@ -79,6 +79,35 @@ ZUC_TEST(timespec_test, timespec_to_msec)
ZUC_ASSERT_EQ(timespec_to_msec(&a), (4000ULL) + 4);
 }
 
+ZUC_TEST(timespec_test, timespec_to_proto)
+{
+   struct timespec a;
+   uint32_t tv_sec_hi;
+   uint32_t tv_sec_lo;
+   uint32_t tv_nsec;
+
+   a.tv_sec = 0;
+   a.tv_nsec = 0;
+   timespec_to_proto(&a, &tv_sec_hi, &tv_sec_lo, &tv_nsec);
+   ZUC_ASSERT_EQ(0, tv_sec_hi);
+   ZUC_ASSERT_EQ(0, tv_sec_lo);
+   ZUC_ASSERT_EQ(0, tv_nsec);
+
+   a.tv_sec = 1234;
+   a.tv_nsec = NSEC_PER_SEC - 1;
+   timespec_to_proto(&a, &tv_sec_hi, &tv_sec_lo, &tv_nsec);
+   ZUC_ASSERT_EQ(0, tv_sec_hi);
+   ZUC_ASSERT_EQ(1234, tv_sec_lo);
+   ZUC_ASSERT_EQ(NSEC_PER_SEC - 1, tv_nsec);
+
+   a.tv_sec = (time_t)0x7000123470005678LL;
+   a.tv_nsec = 1;
+   timespec_to_proto(&a, &tv_sec_hi, &tv_sec_lo, &tv_nsec);
+   ZUC_ASSERT_EQ((uint64_t)a.tv_sec >> 32, tv_sec_hi);
+   ZUC_ASSERT_EQ(0x70005678, tv_sec_lo);
+   ZUC_ASSERT_EQ(1, tv_nsec);
+}
+
 ZUC_TEST(timespec_test, millihz_to_nsec)
 {
ZUC_ASSERT_EQ(millihz_to_nsec(6), 1666);
-- 
2.14.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH weston v2 5/6] tests: Add test for keyboard key event timestamps

2017-12-13 Thread Alexandros Frantzis
Add test to verify that the server correctly sets the timestamps of
keyboard key events. This requires updating the weston-test protocol to
support passing key event timestamps.

simple_keyboard_test now uses the create_client_with_keyboard_focus()
helper function which changes the initial state of the surface to be
focused. This leads to one additional iteration of the test loop when
starting, during which the surface is deactivated, i.e., loses focus.
After this initial iteration the test continues as before.

Furthermore, simple_keyboard_test now uses the send_key() helper
function which performs a roundtrip internally. To account for this, the
client_roundtrip() function is now directly called in the loop only when
it is still required, i.e., when deactivating the surface.

Signed-off-by: Alexandros Frantzis 
---

Changes in v2:
 - Add unit suffix "msec" to variables that hold event time.
 - Avoid double roundtrips in simple_keyboard_test.
 - Justify test changes in commit message.
 - Use the known good value 1 instead of 0 (KEY_RESERVED) when
   sending keys in tests.

 protocol/weston-test.xml  |  3 ++
 tests/keyboard-test.c | 61 ++-
 tests/weston-test-client-helper.c |  3 +-
 tests/weston-test-client-helper.h |  1 +
 tests/weston-test.c   |  3 +-
 5 files changed, 55 insertions(+), 16 deletions(-)

diff --git a/protocol/weston-test.xml b/protocol/weston-test.xml
index a4a7ad4e..37fa221f 100644
--- a/protocol/weston-test.xml
+++ b/protocol/weston-test.xml
@@ -64,6 +64,9 @@
   
 
 
+  
+  
+  
   
   
 
diff --git a/tests/keyboard-test.c b/tests/keyboard-test.c
index 6b4ba19d..722bfd32 100644
--- a/tests/keyboard-test.c
+++ b/tests/keyboard-test.c
@@ -27,21 +27,45 @@
 
 #include 
 
+#include "shared/timespec-util.h"
 #include "weston-test-client-helper.h"
 
+static const struct timespec t1 = { .tv_sec = 1, .tv_nsec = 101 };
+static const struct timespec t2 = { .tv_sec = 2, .tv_nsec = 201 };
+
+static struct client *
+create_client_with_keyboard_focus(void)
+{
+   struct client *cl = create_client_and_test_surface(10, 10, 1, 1);
+   assert(cl);
+
+   weston_test_activate_surface(cl->test->weston_test,
+cl->surface->wl_surface);
+   client_roundtrip(cl);
+
+   return cl;
+}
+
+static void
+send_key(struct client *client, const struct timespec *time,
+uint32_t key, uint32_t state)
+{
+   uint32_t tv_sec_hi, tv_sec_lo, tv_nsec;
+
+   timespec_to_proto(time, &tv_sec_hi, &tv_sec_lo, &tv_nsec);
+   weston_test_send_key(client->test->weston_test, tv_sec_hi, tv_sec_lo,
+tv_nsec, key, state);
+   client_roundtrip(client);
+}
+
 TEST(simple_keyboard_test)
 {
-   struct client *client;
-   struct surface *expect_focus = NULL;
-   struct keyboard *keyboard;
+   struct client *client = create_client_with_keyboard_focus();
+   struct keyboard *keyboard = client->input->keyboard;
+   struct surface *expect_focus = client->surface;
uint32_t expect_key = 0;
uint32_t expect_state = 0;
 
-   client = create_client_and_test_surface(10, 10, 1, 1);
-   assert(client);
-
-   keyboard = client->input->keyboard;
-
while (1) {
assert(keyboard->key == expect_key);
assert(keyboard->state == expect_state);
@@ -49,12 +73,12 @@ TEST(simple_keyboard_test)
 
if (keyboard->state == WL_KEYBOARD_KEY_STATE_PRESSED) {
expect_state = WL_KEYBOARD_KEY_STATE_RELEASED;
-   weston_test_send_key(client->test->weston_test,
-expect_key, expect_state);
+   send_key(client, &t1, expect_key, expect_state);
} else if (keyboard->focus) {
expect_focus = NULL;
weston_test_activate_surface(
client->test->weston_test, NULL);
+   client_roundtrip(client);
} else if (expect_key < 10) {
expect_key++;
expect_focus = client->surface;
@@ -62,12 +86,21 @@ TEST(simple_keyboard_test)
weston_test_activate_surface(
client->test->weston_test,
expect_focus->wl_surface);
-   weston_test_send_key(client->test->weston_test,
-expect_key, expect_state);
+   send_key(client, &t1, expect_key, expect_state);
} else {
break;
}
-
-   client_roundtrip(client);
}
 }
+
+TEST(keyboard_key_event_time)
+{

[PATCH weston v2 6/6] tests: Add test for touch event timestamps

2017-12-13 Thread Alexandros Frantzis
Add test to verify that the server correctly sets the timestamps of
touch events. This requires updating the weston-test protocol with a new
request for touch events.

Signed-off-by: Alexandros Frantzis 
---

Changes in v2:
 - Add unit suffix "msec" to variables that hold event time.

 Makefile.am   |  7 +++-
 protocol/weston-test.xml  |  9 +
 tests/touch-test.c| 71 +++
 tests/weston-test-client-helper.c | 13 ---
 tests/weston-test-client-helper.h |  3 ++
 tests/weston-test.c   | 16 +
 6 files changed, 114 insertions(+), 5 deletions(-)
 create mode 100644 tests/touch-test.c

diff --git a/Makefile.am b/Makefile.am
index 7adc6254..4eb4f0da 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1233,7 +1233,8 @@ weston_tests =\
roles.weston\
subsurface.weston   \
subsurface-shot.weston  \
-   devices.weston
+   devices.weston  \
+   touch.weston
 
 ivi_tests =
 
@@ -1428,6 +1429,10 @@ nodist_viewporter_weston_SOURCES =   \
 viewporter_weston_CFLAGS = $(AM_CFLAGS) $(TEST_CLIENT_CFLAGS)
 viewporter_weston_LDADD = libtest-client.la
 
+touch_weston_SOURCES = tests/touch-test.c
+touch_weston_CFLAGS = $(AM_CFLAGS) $(TEST_CLIENT_CFLAGS)
+touch_weston_LDADD = libtest-client.la
+
 if ENABLE_XWAYLAND_TEST
 weston_tests +=xwayland-test.weston
 xwayland_test_weston_SOURCES = tests/xwayland-test.c
diff --git a/protocol/weston-test.xml b/protocol/weston-test.xml
index 37fa221f..00b7185d 100644
--- a/protocol/weston-test.xml
+++ b/protocol/weston-test.xml
@@ -96,6 +96,15 @@
provided buffer.
  
 
+
+  
+  
+  
+  
+  
+  
+  
+
   
 
   
diff --git a/tests/touch-test.c b/tests/touch-test.c
new file mode 100644
index ..9635257f
--- /dev/null
+++ b/tests/touch-test.c
@@ -0,0 +1,71 @@
+/*
+ * 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 
+
+#include "shared/timespec-util.h"
+#include "weston-test-client-helper.h"
+#include "wayland-server-protocol.h"
+
+static const struct timespec t1 = { .tv_sec = 1, .tv_nsec = 101 };
+static const struct timespec t2 = { .tv_sec = 2, .tv_nsec = 201 };
+static const struct timespec t3 = { .tv_sec = 3, .tv_nsec = 301 };
+
+static struct client *
+create_touch_test_client(void)
+{
+   struct client *cl = create_client_and_test_surface(0, 0, 100, 100);
+   assert(cl);
+   return cl;
+}
+
+static void
+send_touch(struct client *client, const struct timespec *time,
+  uint32_t touch_type)
+{
+   uint32_t tv_sec_hi, tv_sec_lo, tv_nsec;
+
+   timespec_to_proto(time, &tv_sec_hi, &tv_sec_lo, &tv_nsec);
+   weston_test_send_touch(client->test->weston_test, tv_sec_hi, tv_sec_lo,
+  tv_nsec, 1, 1, 1, touch_type);
+   client_roundtrip(client);
+}
+
+TEST(touch_events)
+{
+   struct client *client = create_touch_test_client();
+   struct touch *touch = client->input->touch;
+
+   send_touch(client, &t1, WL_TOUCH_DOWN);
+   assert(touch->down_time_msec == timespec_to_msec(&t1));
+
+   send_touch(client, &t2, WL_TOUCH_MOTION);
+   assert(touch->motion_time_msec == timespec_to_msec(&t2));
+
+   send_touch(client, &t3, WL_TOUCH_UP);
+   assert(touch->up_time_msec == timespec_to_msec(&t3));
+}
diff --git a/tests/weston-test-client-helper.c 
b/tests/weston-test-client-helper.c
index 1ddb5454..6e0a5246 100644
--- a/tests/weston-test-client-helper.c
+++ b/tests/weston-test-client-helper.c
@@ 

Re: [PATCH wayland-protocols] unstable: Add input-timestamps protocol

2017-12-13 Thread Alexandros Frantzis
On Mon, Dec 11, 2017 at 03:25:28PM +0200, Pekka Paalanen wrote:
> On Tue,  5 Dec 2017 18:07:02 +0200
> Alexandros Frantzis  wrote:
> 
> > wl_pointer, wl_keyboard and wl_touch events currently use a 32-bit
> > timestamp with millisecond resolution. In some cases, notably latency
> > measurements, this resolution is too coarse to be useful.
> > 
> > This protocol provides additional high-resolution timestamps events,
> > which are emitted before the corresponding input event. Each timestamp
> > event contains a high-resolution, and ideally higher-accuracy, version
> > of the 'time' argument of the first subsequent supported input event.
> > 
> > Clients that care about high-resolution timestamps just need to keep
> > track of the last timestamp event they receive and associate it with the
> > next supported input event that arrives.
> > 
> > Signed-off-by: Alexandros Frantzis 
> > ---
> >  Makefile.am|   1 +
> >  unstable/input-timestamps/README   |   4 +
> >  .../input-timestamps-unstable-v1.xml   | 138 
> > +
> >  3 files changed, 143 insertions(+)
> >  create mode 100644 unstable/input-timestamps/README
> >  create mode 100644 
> > unstable/input-timestamps/input-timestamps-unstable-v1.xml
> 
> Hi Alf,
> 
> nice work, a comment below.

Hi Pekka,

thanks for the review, some comments below.

> > 
> > diff --git a/Makefile.am b/Makefile.am
> > index cabc279..4b9a901 100644
> > --- a/Makefile.am
> > +++ b/Makefile.am
> > @@ -16,6 +16,7 @@ unstable_protocols =  
> > \
> > unstable/xwayland-keyboard-grab/xwayland-keyboard-grab-unstable-v1.xml  
> > \
> > 
> > unstable/keyboard-shortcuts-inhibit/keyboard-shortcuts-inhibit-unstable-v1.xml
> >  \
> > unstable/xdg-output/xdg-output-unstable-v1.xml  
> > \
> > +   unstable/input-timestamps/input-timestamps-unstable-v1.xml  \
> > $(NULL)
> >  
> >  stable_protocols = 
> > \
> > diff --git a/unstable/input-timestamps/README 
> > b/unstable/input-timestamps/README
> > new file mode 100644
> > index 000..3e82890
> > --- /dev/null
> > +++ b/unstable/input-timestamps/README
> > @@ -0,0 +1,4 @@
> > +High-resolution timestamps for input events.
> > +
> > +Maintainers:
> > +Alexandros Frantzis 
> > diff --git a/unstable/input-timestamps/input-timestamps-unstable-v1.xml 
> > b/unstable/input-timestamps/input-timestamps-unstable-v1.xml
> > new file mode 100644
> > index 000..5a9d120
> > --- /dev/null
> > +++ b/unstable/input-timestamps/input-timestamps-unstable-v1.xml
> > @@ -0,0 +1,138 @@
> > +
> > +
> > +
> > +  
> > +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.
> > +  
> > +
> > +  
> > +This protocol specifies a way for a client to request and receive
> > +high-resolution timestamps for input events.
> > +
> > +Warning! The protocol described in this file is experimental and
> > +backward incompatible changes may be made. Backward 

[PATCH weston v3] tests: Add test for pointer axis events

2017-12-18 Thread Alexandros Frantzis
Add test to verify the server correctly emits pointer axis events.  This
requires updating the weston-test protocol with a new request for
pointer axis events.

Signed-off-by: Alexandros Frantzis 
---

Changes in v3:
 - Use uint32_t, not double, for event time variables.

Changes in v2:
 - Add unit suffix "msec" to variables that hold event time.

 protocol/weston-test.xml  |  7 +++
 tests/pointer-test.c  | 28 
 tests/weston-test-client-helper.c | 17 ++---
 tests/weston-test-client-helper.h |  4 
 tests/weston-test.c   | 20 
 5 files changed, 73 insertions(+), 3 deletions(-)

diff --git a/protocol/weston-test.xml b/protocol/weston-test.xml
index fa3d15e1..00b7185d 100644
--- a/protocol/weston-test.xml
+++ b/protocol/weston-test.xml
@@ -53,6 +53,13 @@
   
   
 
+
+  
+  
+  
+  
+  
+
 
   
 
diff --git a/tests/pointer-test.c b/tests/pointer-test.c
index 61bf83b7..4c438a22 100644
--- a/tests/pointer-test.c
+++ b/tests/pointer-test.c
@@ -58,6 +58,18 @@ send_button(struct client *client, const struct timespec 
*time,
client_roundtrip(client);
 }
 
+static void
+send_axis(struct client *client, const struct timespec *time, uint32_t axis,
+ double value)
+{
+   uint32_t tv_sec_hi, tv_sec_lo, tv_nsec;
+
+   timespec_to_proto(time, &tv_sec_hi, &tv_sec_lo, &tv_nsec);
+   weston_test_send_axis(client->test->weston_test, tv_sec_hi, tv_sec_lo,
+ tv_nsec, axis, wl_fixed_from_double(value));
+   client_roundtrip(client);
+}
+
 static void
 check_pointer(struct client *client, int x, int y)
 {
@@ -355,3 +367,19 @@ TEST(pointer_button_events)
assert(pointer->state == WL_POINTER_BUTTON_STATE_RELEASED);
assert(pointer->button_time_msec == timespec_to_msec(&t2));
 }
+
+TEST(pointer_axis_events)
+{
+   struct client *client = create_client_with_pointer_focus(100, 100,
+100, 100);
+   struct pointer *pointer = client->input->pointer;
+
+   send_axis(client, &t1, 1, 1.0);
+   assert(pointer->axis == 1);
+   assert(pointer->axis_value == 1.0);
+   assert(pointer->axis_time_msec == timespec_to_msec(&t1));
+
+   send_axis(client, &t2, 2, 0.0);
+   assert(pointer->axis == 2);
+   assert(pointer->axis_stop_time_msec == timespec_to_msec(&t2));
+}
diff --git a/tests/weston-test-client-helper.c 
b/tests/weston-test-client-helper.c
index c5a00320..6e0a5246 100644
--- a/tests/weston-test-client-helper.c
+++ b/tests/weston-test-client-helper.c
@@ -177,8 +177,14 @@ pointer_handle_button(void *data, struct wl_pointer 
*wl_pointer,
 
 static void
 pointer_handle_axis(void *data, struct wl_pointer *wl_pointer,
-   uint32_t time, uint32_t axis, wl_fixed_t value)
+   uint32_t time_msec, uint32_t axis, wl_fixed_t value)
 {
+   struct pointer *pointer = data;
+
+   pointer->axis = axis;
+   pointer->axis_value = wl_fixed_to_double(value);
+   pointer->axis_time_msec = time_msec;
+
fprintf(stderr, "test-client: got pointer axis %u %f\n",
axis, wl_fixed_to_double(value));
 }
@@ -198,9 +204,14 @@ pointer_handle_axis_source(void *data, struct wl_pointer 
*wl_pointer,
 
 static void
 pointer_handle_axis_stop(void *data, struct wl_pointer *wl_pointer,
-uint32_t time, uint32_t axis)
+uint32_t time_msec, uint32_t axis)
 {
-   fprintf(stderr, "test-client: got pointer axis stop\n");
+   struct pointer *pointer = data;
+
+   pointer->axis = axis;
+   pointer->axis_stop_time_msec = time_msec;
+
+   fprintf(stderr, "test-client: got pointer axis stop %u\n", axis);
 }
 
 static void
diff --git a/tests/weston-test-client-helper.h 
b/tests/weston-test-client-helper.h
index 86ecb640..09a5df4a 100644
--- a/tests/weston-test-client-helper.h
+++ b/tests/weston-test-client-helper.h
@@ -90,8 +90,12 @@ struct pointer {
int y;
uint32_t button;
uint32_t state;
+   uint32_t axis;
+   double axis_value;
uint32_t motion_time_msec;
uint32_t button_time_msec;
+   uint32_t axis_time_msec;
+   uint32_t axis_stop_time_msec;
 };
 
 struct keyboard {
diff --git a/tests/weston-test.c b/tests/weston-test.c
index 14030f4c..80b3d65b 100644
--- a/tests/weston-test.c
+++ b/tests/weston-test.c
@@ -183,6 +183,25 @@ send_button(struct wl_client *client, struct wl_resource 
*resource,
notify_button(seat, &time, button, state);
 }
 
+static void
+send_axis(struct wl_client *client, struct wl_resource *resource,
+ uint32_t tv_sec_hi, uint32_t tv_sec_lo, uint32_t tv_nsec,
+ uint32_t axis, wl_fixed_t value)
+{
+   struct weston_

Re: [PATCH weston v2 4/6] tests: Add test for pointer axis events

2017-12-18 Thread Alexandros Frantzis
On Mon, Dec 18, 2017 at 11:53:24AM +0200, Pekka Paalanen wrote:
> On Wed, 13 Dec 2017 13:27:56 +0200
> Alexandros Frantzis  wrote:
> 
> > Add test to verify the server correctly emits pointer axis events.  This
> > requires updating the weston-test protocol with a new request for
> > pointer axis events.
> > 
> > Signed-off-by: Alexandros Frantzis 
> > ---
> > 
> > Changes in v2:
> >  - Add unit suffix "msec" to variables that hold event time.
> > 
> >  protocol/weston-test.xml  |  7 +++
> >  tests/pointer-test.c  | 28 
> >  tests/weston-test-client-helper.c | 17 ++---
> >  tests/weston-test-client-helper.h |  4 
> >  tests/weston-test.c   | 20 
> >  5 files changed, 73 insertions(+), 3 deletions(-)
> 
> > diff --git a/tests/weston-test-client-helper.h 
> > b/tests/weston-test-client-helper.h
> > index 6f5f9c41..76f07491 100644
> > --- a/tests/weston-test-client-helper.h
> > +++ b/tests/weston-test-client-helper.h
> > @@ -90,8 +90,12 @@ struct pointer {
> > int y;
> > uint32_t button;
> > uint32_t state;
> > +   uint32_t axis;
> > +   double axis_value;
> > uint32_t motion_time_msec;
> > uint32_t button_time_msec;
> > +   double axis_time_msec;
> > +   double axis_stop_time_msec;
> 
> Why are these times doubles instead of uint32_t?

A mistake, fixed in v3.

Thanks,
Alexandros
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


Re: [PATCH wayland-protocols] unstable: Add input-timestamps protocol

2017-12-18 Thread Alexandros Frantzis
On Mon, Dec 18, 2017 at 12:50:30PM +0200, Pekka Paalanen wrote:
> On Wed, 13 Dec 2017 16:48:28 +0200
> Alexandros Frantzis  wrote:
> 
> > On Mon, Dec 11, 2017 at 03:25:28PM +0200, Pekka Paalanen wrote:
> > > On Tue,  5 Dec 2017 18:07:02 +0200
> > > Alexandros Frantzis  wrote:
> > >   
> > > > wl_pointer, wl_keyboard and wl_touch events currently use a 32-bit
> > > > timestamp with millisecond resolution. In some cases, notably latency
> > > > measurements, this resolution is too coarse to be useful.
> > > > 
> > > > This protocol provides additional high-resolution timestamps events,
> > > > which are emitted before the corresponding input event. Each timestamp
> > > > event contains a high-resolution, and ideally higher-accuracy, version
> > > > of the 'time' argument of the first subsequent supported input event.
> > > > 
> > > > Clients that care about high-resolution timestamps just need to keep
> > > > track of the last timestamp event they receive and associate it with the
> > > > next supported input event that arrives.
> > > > 
> > > > Signed-off-by: Alexandros Frantzis 
> > > > ---
> > > >  Makefile.am|   1 +
> > > >  unstable/input-timestamps/README   |   4 +
> > > >  .../input-timestamps-unstable-v1.xml   | 138 
> > > > +
> > > >  3 files changed, 143 insertions(+)
> > > >  create mode 100644 unstable/input-timestamps/README
> > > >  create mode 100644 
> > > > unstable/input-timestamps/input-timestamps-unstable-v1.xml  
> > > 
> > > Hi Alf,
> > > 
> > > nice work, a comment below.  
> > 
> > Hi Pekka,
> > 
> > thanks for the review, some comments below.
> > 
> > > > 
> > > > diff --git a/Makefile.am b/Makefile.am
> > > > index cabc279..4b9a901 100644
> > > > --- a/Makefile.am
> > > > +++ b/Makefile.am
> > > > @@ -16,6 +16,7 @@ unstable_protocols =  
> > > > \
> > > > 
> > > > unstable/xwayland-keyboard-grab/xwayland-keyboard-grab-unstable-v1.xml  
> > > > \
> > > > 
> > > > unstable/keyboard-shortcuts-inhibit/keyboard-shortcuts-inhibit-unstable-v1.xml
> > > >  \
> > > > unstable/xdg-output/xdg-output-unstable-v1.xml  
> > > >     \
> > > > +   unstable/input-timestamps/input-timestamps-unstable-v1.xml  
> > > > \
> > > > $(NULL)
> > > >  
> > > >  stable_protocols = 
> > > > \
> > > > diff --git a/unstable/input-timestamps/README 
> > > > b/unstable/input-timestamps/README
> > > > new file mode 100644
> > > > index 000..3e82890
> > > > --- /dev/null
> > > > +++ b/unstable/input-timestamps/README
> > > > @@ -0,0 +1,4 @@
> > > > +High-resolution timestamps for input events.
> > > > +
> > > > +Maintainers:
> > > > +Alexandros Frantzis 
> > > > diff --git a/unstable/input-timestamps/input-timestamps-unstable-v1.xml 
> > > > b/unstable/input-timestamps/input-timestamps-unstable-v1.xml
> > > > new file mode 100644
> > > > index 000..5a9d120
> > > > --- /dev/null
> > > > +++ b/unstable/input-timestamps/input-timestamps-unstable-v1.xml
> > > > @@ -0,0 +1,138 @@
> > > > +
> > > > +
> > > > +
> 
> Hi Alf

Hi Pekka,

> > > > +  
> > > > +
> > > > +  Provides high-resolution timestamp events for a set of 
> > > > subscribed input
> > > > +  events. The set of subscribed input events is determined by the
> > > > +  zwp_input_timestamps_manager_v1 request used to create this 
> > > > object.
> > > > +
> > > > +
> > > > +
> > > > +  
> > > > +Informs the server that the client will no longer be using this
> > > > +protocol object. After the server processes the request, no 
> > > > more
> > > > +timestamp events will be emitted.  
> > > 
> > > This could be said simply:
> > > "Cancel the subsc

[PATCH wayland-protocols v2] unstable: Add input-timestamps protocol

2017-12-18 Thread Alexandros Frantzis
wl_pointer, wl_keyboard and wl_touch events currently use a 32-bit
timestamp with millisecond resolution. In some cases, notably latency
measurements, this resolution is too coarse to be useful.

This protocol provides additional high-resolution timestamps events,
which are emitted before the corresponding input event. Each timestamp
event contains a high-resolution, and ideally higher-accuracy, version
of the 'time' argument of the first subsequent supported input event.

Clients that care about high-resolution timestamps just need to keep
track of the last timestamp event they receive and associate it with the
next supported input event that arrives.

Signed-off-by: Alexandros Frantzis 
Reviewed-by: Pekka Paalanen 
Acked-by: Jonas Ådahl 
---

Changes in v2:
 - Add '...carrying a timestamp...' to better describe the set of subsequent
   input events in the timestamp event description. 
 - Clarify normalization requirements of tv_sec_hi, tv_sec_lo, tv_nsec
   timestamp representation.

 Makefile.am|   1 +
 unstable/input-timestamps/README   |   4 +
 .../input-timestamps-unstable-v1.xml   | 145 +
 3 files changed, 150 insertions(+)
 create mode 100644 unstable/input-timestamps/README
 create mode 100644 unstable/input-timestamps/input-timestamps-unstable-v1.xml

diff --git a/Makefile.am b/Makefile.am
index cabc279..4b9a901 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -16,6 +16,7 @@ unstable_protocols =  
\
unstable/xwayland-keyboard-grab/xwayland-keyboard-grab-unstable-v1.xml  
\

unstable/keyboard-shortcuts-inhibit/keyboard-shortcuts-inhibit-unstable-v1.xml \
unstable/xdg-output/xdg-output-unstable-v1.xml  
\
+   unstable/input-timestamps/input-timestamps-unstable-v1.xml  \
$(NULL)
 
 stable_protocols = 
\
diff --git a/unstable/input-timestamps/README b/unstable/input-timestamps/README
new file mode 100644
index 000..3e82890
--- /dev/null
+++ b/unstable/input-timestamps/README
@@ -0,0 +1,4 @@
+High-resolution timestamps for input events.
+
+Maintainers:
+Alexandros Frantzis 
diff --git a/unstable/input-timestamps/input-timestamps-unstable-v1.xml 
b/unstable/input-timestamps/input-timestamps-unstable-v1.xml
new file mode 100644
index 000..7c5e082
--- /dev/null
+++ b/unstable/input-timestamps/input-timestamps-unstable-v1.xml
@@ -0,0 +1,145 @@
+
+
+
+  
+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.
+  
+
+  
+This protocol specifies a way for a client to request and receive
+high-resolution timestamps for input events.
+
+Warning! The protocol described in this file is experimental and
+backward incompatible changes may be made. Backward compatible changes
+may be added together with the corresponding interface version bump.
+Backward incompatible changes are done by bumping the version number in
+the protocol and interface names and resetting the interface version.
+Once the protocol is to be declared stable, the 'z' prefix and the
+version number in the protocol and interface names are removed and the
+interface version number is reset.
+  
+
+  
+
+  A global interface used for requesting high-resolution timestamps
+  for input events.
+
+
+
+  
+Informs the server that the client will no longer be using this
+protocol object. Existing objects created by this object are not
+affected.
+  
+
+
+
+  
+Creates a new input timestamps object that represents a subscription
+to high-resolution timestamp events for all wl_keyboard events that
+carry a t

Re: [PATCH wayland-protocols v2] unstable: Add input-timestamps protocol

2017-12-19 Thread Alexandros Frantzis
On Tue, Dec 19, 2017 at 10:15:06AM +0200, Pekka Paalanen wrote:
> On Mon, 18 Dec 2017 14:55:00 +0200
> Alexandros Frantzis  wrote:
> 
> > wl_pointer, wl_keyboard and wl_touch events currently use a 32-bit
> > timestamp with millisecond resolution. In some cases, notably latency
> > measurements, this resolution is too coarse to be useful.
> > 
> > This protocol provides additional high-resolution timestamps events,
> > which are emitted before the corresponding input event. Each timestamp
> > event contains a high-resolution, and ideally higher-accuracy, version
> > of the 'time' argument of the first subsequent supported input event.
> > 
> > Clients that care about high-resolution timestamps just need to keep
> > track of the last timestamp event they receive and associate it with the
> > next supported input event that arrives.
> > 
> > Signed-off-by: Alexandros Frantzis 
> > Reviewed-by: Pekka Paalanen 
> > Acked-by: Jonas Ådahl 
> > ---
> > 
> > Changes in v2:
> >  - Add '...carrying a timestamp...' to better describe the set of subsequent
> >input events in the timestamp event description. 
> >  - Clarify normalization requirements of tv_sec_hi, tv_sec_lo, tv_nsec
> >timestamp representation.
> > 
> >  Makefile.am|   1 +
> >  unstable/input-timestamps/README   |   4 +
> >  .../input-timestamps-unstable-v1.xml   | 145 
> > +
> >  3 files changed, 150 insertions(+)
> >  create mode 100644 unstable/input-timestamps/README
> >  create mode 100644 
> > unstable/input-timestamps/input-timestamps-unstable-v1.xml
> 
> Cool! I suppose we want to see the Weston implementation patches posted
> to the list before landing this?

The plan is to refresh and clean up the proof-of-concept Weston
implementation and propose it. For those interested to take an
early look the p-o-c code is at:

https://gitlab.collabora.com/alf/weston/commits/zwp-input-timestamps

> Alf, what would you have for the client side of the implementation?

The weston p-o-c implementation branch includes tests that I think
exhibit well the client side use of this protocol, but if that's not
sufficient I am happy to add or enhance an example client to use this
protocol.

Thanks,
Alexandros
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH weston 0/6] libweston: Support input_timestamps_unstable_v1

2017-12-20 Thread Alexandros Frantzis
The input_timestamps_unstable_v1 protocol allows clients to subscribe to
high-resolution timestamp events for input events (see [1]).

This patchset implements the input_timestamps_unstable_v1 protocol in libweston
and also adds tests for the implementation in the weston test suite. Note that,
as expected, this patchset depends on the presence of the protocol description
file, which is currently pending inclusion in wayland-protocols.

Patches (1) and (2) introduce some helper code which is used by later patches.
Patch (2) in particular adds test helpers that also act as a nice example of a
client side implementation of the input_timestamps_unstable_v1 protocol.

Patch (3) introduces some common support code in libweston, which allows for
cleaner and more focused patches for keyboard, pointer and touch timestamp
event support in patches (4), (5) and (6) respectively.

[1] 
https://lists.freedesktop.org/archives/wayland-devel/2017-December/036320.html

Alexandros Frantzis (6):
  shared: Add timespec_eq helper function
  tests: Introduce input timestamps helper
  libweston: Introduce input-timestamps support
  libweston: Implement keyboard timestamps for
input_timestamps_unstable_v1
  libweston: Implement pointer timestamps for
input_timestamps_unstable_v1
  libweston: Implement touch timestamps for input_timestamps_unstable_v1

 Makefile.am   |  20 ++-
 libweston/compositor.h|   6 +
 libweston/input.c | 250 --
 shared/timespec-util.h|  13 ++
 tests/input-timestamps-helper.c   | 177 +++
 tests/input-timestamps-helper.h   |  46 +++
 tests/keyboard-test.c |  45 +++
 tests/pointer-test.c  |  66 ++
 tests/timespec-test.c |  12 ++
 tests/touch-test.c|  46 +++
 tests/weston-test-client-helper.c |  16 +++
 tests/weston-test-client-helper.h |  12 ++
 12 files changed, 690 insertions(+), 19 deletions(-)
 create mode 100644 tests/input-timestamps-helper.c
 create mode 100644 tests/input-timestamps-helper.h

-- 
2.14.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH weston 3/6] libweston: Introduce input-timestamps support code

2017-12-20 Thread Alexandros Frantzis
Introduce code to support the implementation of the
input_timestamps_unstable_v1 protocol in libweston. This commit does not
implement the actual timestamp subscriptions, but lays the foundation so
timestamp subscriptions for keyboard/pointer/touch can be added cleanly
in upcoming commits.

Signed-off-by: Alexandros Frantzis 
---
 Makefile.am   |   4 +-
 libweston/input.c | 115 ++
 2 files changed, 118 insertions(+), 1 deletion(-)

diff --git a/Makefile.am b/Makefile.am
index 0b616c11..823e9845 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -181,7 +181,9 @@ nodist_libweston_@LIBWESTON_MAJOR@_la_SOURCES = 
\
protocol/relative-pointer-unstable-v1-protocol.c\
protocol/relative-pointer-unstable-v1-server-protocol.h \
protocol/pointer-constraints-unstable-v1-protocol.c \
-   protocol/pointer-constraints-unstable-v1-server-protocol.h
+   protocol/pointer-constraints-unstable-v1-server-protocol.h  \
+   protocol/input-timestamps-unstable-v1-protocol.c\
+   protocol/input-timestamps-unstable-v1-server-protocol.h
 
 BUILT_SOURCES += $(nodist_libweston_@LIBWESTON_MAJOR@_la_SOURCES)
 
diff --git a/libweston/input.c b/libweston/input.c
index 94a3423a..a682fa94 100644
--- a/libweston/input.c
+++ b/libweston/input.c
@@ -42,6 +42,7 @@
 #include "compositor.h"
 #include "relative-pointer-unstable-v1-server-protocol.h"
 #include "pointer-constraints-unstable-v1-server-protocol.h"
+#include "input-timestamps-unstable-v1-server-protocol.h"
 
 enum pointer_constraint_type {
POINTER_CONSTRAINT_TYPE_LOCK,
@@ -86,6 +87,42 @@ region_init_infinite(pixman_region32_t *region)
  UINT32_MAX, UINT32_MAX);
 }
 
+static void
+send_timestamp(struct wl_resource *resource,
+  const struct timespec *time)
+{
+   uint32_t tv_sec_hi, tv_sec_lo, tv_nsec;
+
+   timespec_to_proto(time, &tv_sec_hi, &tv_sec_lo, &tv_nsec);
+   zwp_input_timestamps_v1_send_timestamp(resource, tv_sec_hi, tv_sec_lo,
+  tv_nsec);
+}
+
+static void
+send_timestamps_for_input_resource(struct wl_resource *input_resource,
+  struct wl_list *list,
+  const struct timespec *time)
+{
+   struct wl_resource *resource;
+
+   wl_resource_for_each(resource, list) {
+   if (wl_resource_get_user_data(resource) == input_resource)
+   send_timestamp(resource, time);
+   }
+}
+
+static void
+remove_input_resource_from_timestamps(struct wl_resource *input_resource,
+ struct wl_list *list)
+{
+   struct wl_resource *resource;
+
+   wl_resource_for_each(resource, list) {
+   if (wl_resource_get_user_data(resource) == input_resource)
+   wl_resource_set_user_data(resource, NULL);
+   }
+}
+
 static struct weston_pointer_client *
 weston_pointer_client_create(struct wl_client *client)
 {
@@ -4493,6 +4530,79 @@ bind_pointer_constraints(struct wl_client *client, void 
*data,
   NULL, NULL);
 }
 
+static void
+input_timestamps_destroy(struct wl_client *client,
+struct wl_resource *resource)
+{
+   wl_resource_destroy(resource);
+}
+
+static const struct zwp_input_timestamps_v1_interface
+   input_timestamps_interface = {
+   input_timestamps_destroy,
+};
+
+static void
+input_timestamps_manager_destroy(struct wl_client *client,
+struct wl_resource *resource)
+{
+   wl_resource_destroy(resource);
+}
+
+static void
+input_timestamps_manager_get_keyboard_timestamps(struct wl_client *client,
+struct wl_resource *resource,
+uint32_t id,
+struct wl_resource 
*keyboard_resource)
+{
+   wl_client_post_no_memory(client);
+}
+
+static void
+input_timestamps_manager_get_pointer_timestamps(struct wl_client *client,
+   struct wl_resource *resource,
+   uint32_t id,
+   struct wl_resource 
*pointer_resource)
+{
+   wl_client_post_no_memory(client);
+}
+
+static void
+input_timestamps_manager_get_touch_timestamps(struct wl_client *client,
+ struct wl_resource *resource,
+ uint32_t id,
+ struct wl_resource 
*touch_resource)
+{
+   wl_client_post_no_memory(client);
+}
+
+static const struct zwp_input_timestamps_manager_v1_interface
+ 

[PATCH weston 5/6] libweston: Implement pointer timestamps for input_timestamps_unstable_v1

2017-12-20 Thread Alexandros Frantzis
Implement the zwp_input_timestamps_v1.get_pointer_timestamps request to
subscribe to timestamp events for wl_pointer resources.

Signed-off-by: Alexandros Frantzis 
---
 libweston/compositor.h |  2 ++
 libweston/input.c  | 50 +-
 tests/pointer-test.c   | 66 ++
 3 files changed, 112 insertions(+), 6 deletions(-)

diff --git a/libweston/compositor.h b/libweston/compositor.h
index 85f59d45..7fa88800 100644
--- a/libweston/compositor.h
+++ b/libweston/compositor.h
@@ -391,6 +391,8 @@ struct weston_pointer {
uint32_t button_count;
 
struct wl_listener output_destroy_listener;
+
+   struct wl_list timestamps_list;
 };
 
 
diff --git a/libweston/input.c b/libweston/input.c
index 8a27fc08..9aceccb1 100644
--- a/libweston/input.c
+++ b/libweston/input.c
@@ -205,12 +205,14 @@ unbind_pointer_client_resource(struct wl_resource 
*resource)
 {
struct weston_pointer *pointer = wl_resource_get_user_data(resource);
struct wl_client *client = wl_resource_get_client(resource);
+   struct wl_list *timestamps_list = &pointer->timestamps_list;
struct weston_pointer_client *pointer_client;
 
pointer_client = weston_pointer_get_pointer_client(pointer, client);
assert(pointer_client);
 
wl_list_remove(wl_resource_get_link(resource));
+   remove_input_resource_from_timestamps(resource, timestamps_list);
weston_pointer_cleanup_pointer_client(pointer, pointer_client);
 }
 
@@ -407,6 +409,9 @@ pointer_send_relative_motion(struct weston_pointer *pointer,
dyf_unaccel = wl_fixed_from_double(dy_unaccel);
 
wl_resource_for_each(resource, resource_list) {
+   send_timestamps_for_input_resource(resource,
+   &pointer->timestamps_list,
+   time);
zwp_relative_pointer_v1_send_relative_motion(
resource,
(uint32_t) (time_usec >> 32),
@@ -430,8 +435,12 @@ pointer_send_motion(struct weston_pointer *pointer,
 
resource_list = &pointer->focus_client->pointer_resources;
msecs = timespec_to_msec(time);
-   wl_resource_for_each(resource, resource_list)
+   wl_resource_for_each(resource, resource_list) {
+   send_timestamps_for_input_resource(resource,
+   &pointer->timestamps_list,
+   time);
wl_pointer_send_motion(resource, msecs, sx, sy);
+   }
 }
 
 WL_EXPORT void
@@ -512,8 +521,12 @@ weston_pointer_send_button(struct weston_pointer *pointer,
resource_list = &pointer->focus_client->pointer_resources;
serial = wl_display_next_serial(display);
msecs = timespec_to_msec(time);
-   wl_resource_for_each(resource, resource_list)
+   wl_resource_for_each(resource, resource_list) {
+   send_timestamps_for_input_resource(resource,
+   &pointer->timestamps_list,
+   time);
wl_pointer_send_button(resource, serial, msecs, button, state);
+   }
 }
 
 static void
@@ -570,14 +583,21 @@ weston_pointer_send_axis(struct weston_pointer *pointer,
wl_pointer_send_axis_discrete(resource, event->axis,
  event->discrete);
 
-   if (event->value)
+   if (event->value) {
+   send_timestamps_for_input_resource(resource,
+  
&pointer->timestamps_list,
+  time);
wl_pointer_send_axis(resource, msecs,
 event->axis,
 
wl_fixed_from_double(event->value));
-   else if (wl_resource_get_version(resource) >=
-WL_POINTER_AXIS_STOP_SINCE_VERSION)
+   } else if (wl_resource_get_version(resource) >=
+WL_POINTER_AXIS_STOP_SINCE_VERSION) {
+   send_timestamps_for_input_resource(resource,
+  
&pointer->timestamps_list,
+  time);
wl_pointer_send_axis_stop(resource, msecs,
  event->axis);
+   }
}
 }
 
@@ -1112,6 +1132,7 @@ weston_pointer_create(struct weston_seat *seat)
wl_signal_init(&pointer->focus_signal);
wl_list_init(&pointer->focus_view_listener.link);
   

[PATCH weston 4/6] libweston: Implement keyboard timestamps for input_timestamps_unstable_v1

2017-12-20 Thread Alexandros Frantzis
Implement the zwp_input_timestamps_v1.get_keyboard_timestamps request to
subscribe to timestamp events for wl_keyboard resources.

Signed-off-by: Alexandros Frantzis 
---
 libweston/compositor.h |  2 ++
 libweston/input.c  | 38 +++---
 tests/keyboard-test.c  | 45 +
 3 files changed, 82 insertions(+), 3 deletions(-)

diff --git a/libweston/compositor.h b/libweston/compositor.h
index dffcba89..85f59d45 100644
--- a/libweston/compositor.h
+++ b/libweston/compositor.h
@@ -605,6 +605,8 @@ struct weston_keyboard {
enum weston_led leds;
} xkb_state;
struct xkb_keymap *pending_keymap;
+
+   struct wl_list timestamps_list;
 };
 
 struct weston_seat {
diff --git a/libweston/input.c b/libweston/input.c
index a682fa94..8a27fc08 100644
--- a/libweston/input.c
+++ b/libweston/input.c
@@ -904,8 +904,12 @@ weston_keyboard_send_key(struct weston_keyboard *keyboard,
resource_list = &keyboard->focus_resource_list;
serial = wl_display_next_serial(display);
msecs = timespec_to_msec(time);
-   wl_resource_for_each(resource, resource_list)
+   wl_resource_for_each(resource, resource_list) {
+   send_timestamps_for_input_resource(resource,
+  &keyboard->timestamps_list,
+  time);
wl_keyboard_send_key(resource, serial, msecs, key, state);
+   }
 };
 
 static void
@@ -1171,6 +1175,7 @@ weston_keyboard_create(void)
keyboard->default_grab.keyboard = keyboard;
keyboard->grab = &keyboard->default_grab;
wl_signal_init(&keyboard->focus_signal);
+   wl_list_init(&keyboard->timestamps_list);
 
return keyboard;
 }
@@ -2453,6 +2458,16 @@ seat_get_pointer(struct wl_client *client, struct 
wl_resource *resource,
}
 }
 
+static void
+destroy_keyboard_resource(struct wl_resource *resource)
+{
+   struct weston_seat *seat = wl_resource_get_user_data(resource);
+   struct wl_list *timestamps_list = 
&seat->keyboard_state->timestamps_list;
+
+   wl_list_remove(wl_resource_get_link(resource));
+   remove_input_resource_from_timestamps(resource, timestamps_list);
+}
+
 static void
 keyboard_release(struct wl_client *client, struct wl_resource *resource)
 {
@@ -2516,7 +2531,7 @@ seat_get_keyboard(struct wl_client *client, struct 
wl_resource *resource,
 * focused */
wl_list_insert(&keyboard->resource_list, wl_resource_get_link(cr));
wl_resource_set_implementation(cr, &keyboard_interface,
-  seat, unbind_resource);
+  seat, destroy_keyboard_resource);
 
if (wl_resource_get_version(cr) >= 
WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION) {
wl_keyboard_send_repeat_info(cr,
@@ -4555,7 +4570,24 @@ input_timestamps_manager_get_keyboard_timestamps(struct 
wl_client *client,
 uint32_t id,
 struct wl_resource 
*keyboard_resource)
 {
-   wl_client_post_no_memory(client);
+   struct weston_seat *seat = wl_resource_get_user_data(keyboard_resource);
+   struct wl_resource *input_ts;
+
+   input_ts = wl_resource_create(client,
+ &zwp_input_timestamps_v1_interface,
+ 1, id);
+   if (!input_ts) {
+   wl_client_post_no_memory(client);
+   return;
+   }
+
+   wl_resource_set_implementation(input_ts,
+  &input_timestamps_interface,
+  keyboard_resource,
+  unbind_resource);
+
+   wl_list_insert(&seat->keyboard_state->timestamps_list,
+  wl_resource_get_link(input_ts));
 }
 
 static void
diff --git a/tests/keyboard-test.c b/tests/keyboard-test.c
index 722bfd32..daad8e81 100644
--- a/tests/keyboard-test.c
+++ b/tests/keyboard-test.c
@@ -27,6 +27,7 @@
 
 #include 
 
+#include "input-timestamps-helper.h"
 #include "shared/timespec-util.h"
 #include "weston-test-client-helper.h"
 
@@ -97,10 +98,54 @@ TEST(keyboard_key_event_time)
 {
struct client *client = create_client_with_keyboard_focus();
struct keyboard *keyboard = client->input->keyboard;
+   struct input_timestamps *input_ts =
+   input_timestamps_create_for_keyboard(client);
 
send_key(client, &t1, 1, WL_KEYBOARD_KEY_STATE_PRESSED);
assert(keyboard->key_time_msec == timespec_to_msec(&t1));
+   assert(timespec_eq(&keyboard->key_time_timespec, &t1));
 
send_key(client, &t2, 1, WL_KEYBOARD_KEY_STATE_RELEASED);
assert(keyb

[PATCH weston 6/6] libweston: Implement touch timestamps for input_timestamps_unstable_v1

2017-12-20 Thread Alexandros Frantzis
Implement the zwp_input_timestamps_v1.get_touch_timestamps request to
subscribe to timestamp events for wl_touch resources.

Signed-off-by: Alexandros Frantzis 
---
 libweston/compositor.h |  2 ++
 libweston/input.c  | 53 +++---
 tests/touch-test.c | 46 +++
 3 files changed, 94 insertions(+), 7 deletions(-)

diff --git a/libweston/compositor.h b/libweston/compositor.h
index 7fa88800..71d5892c 100644
--- a/libweston/compositor.h
+++ b/libweston/compositor.h
@@ -415,6 +415,8 @@ struct weston_touch {
wl_fixed_t grab_x, grab_y;
uint32_t grab_serial;
struct timespec grab_time;
+
+   struct wl_list timestamps_list;
 };
 
 void
diff --git a/libweston/input.c b/libweston/input.c
index 9aceccb1..72b53dba 100644
--- a/libweston/input.c
+++ b/libweston/input.c
@@ -745,10 +745,14 @@ weston_touch_send_down(struct weston_touch *touch, const 
struct timespec *time,
resource_list = &touch->focus_resource_list;
serial = wl_display_next_serial(display);
msecs = timespec_to_msec(time);
-   wl_resource_for_each(resource, resource_list)
-   wl_touch_send_down(resource, serial, msecs,
-  touch->focus->surface->resource,
-  touch_id, sx, sy);
+   wl_resource_for_each(resource, resource_list) {
+   send_timestamps_for_input_resource(resource,
+  &touch->timestamps_list,
+  time);
+   wl_touch_send_down(resource, serial, msecs,
+  touch->focus->surface->resource,
+  touch_id, sx, sy);
+   }
 }
 
 static void
@@ -785,8 +789,12 @@ weston_touch_send_up(struct weston_touch *touch, const 
struct timespec *time,
resource_list = &touch->focus_resource_list;
serial = wl_display_next_serial(display);
msecs = timespec_to_msec(time);
-   wl_resource_for_each(resource, resource_list)
+   wl_resource_for_each(resource, resource_list) {
+   send_timestamps_for_input_resource(resource,
+  &touch->timestamps_list,
+  time);
wl_touch_send_up(resource, serial, msecs, touch_id);
+   }
 }
 
 static void
@@ -826,6 +834,9 @@ weston_touch_send_motion(struct weston_touch *touch,
resource_list = &touch->focus_resource_list;
msecs = timespec_to_msec(time);
wl_resource_for_each(resource, resource_list) {
+   send_timestamps_for_input_resource(resource,
+  &touch->timestamps_list,
+  time);
wl_touch_send_motion(resource, msecs,
 touch_id, sx, sy);
}
@@ -1244,6 +1255,7 @@ weston_touch_create(void)
touch->default_grab.touch = touch;
touch->grab = &touch->default_grab;
wl_signal_init(&touch->focus_signal);
+   wl_list_init(&touch->timestamps_list);
 
return touch;
 }
@@ -2591,6 +2603,16 @@ seat_get_keyboard(struct wl_client *client, struct 
wl_resource *resource,
}
 }
 
+static void
+destroy_touch_resource(struct wl_resource *resource)
+{
+   struct weston_seat *seat = wl_resource_get_user_data(resource);
+   struct wl_list *timestamps_list = &seat->touch_state->timestamps_list;
+
+   wl_list_remove(wl_resource_get_link(resource));
+   remove_input_resource_from_timestamps(resource, timestamps_list);
+}
+
 static void
 touch_release(struct wl_client *client, struct wl_resource *resource)
 {
@@ -2636,7 +2658,7 @@ seat_get_touch(struct wl_client *client, struct 
wl_resource *resource,
   wl_resource_get_link(cr));
}
wl_resource_set_implementation(cr, &touch_interface,
-  seat, unbind_resource);
+  seat, destroy_touch_resource);
 }
 
 static void
@@ -4643,7 +4665,24 @@ input_timestamps_manager_get_touch_timestamps(struct 
wl_client *client,
  uint32_t id,
  struct wl_resource 
*touch_resource)
 {
-   wl_client_post_no_memory(client);
+   struct weston_seat *seat = wl_resource_get_user_data(touch_resource);
+   struct wl_resource *input_ts;
+
+   input_ts = wl_resource_create(client,
+ &zwp_input_timestamps_v1_interface,
+ 1, id);
+   if (!input_ts) {
+   wl_client_po

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

2017-12-20 Thread Alexandros Frantzis
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.

Signed-off-by: Alexandros Frantzis 
---
 Makefile.am   |  16 ++--
 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 +++
 5 files changed, 262 insertions(+), 5 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 883249c0..0b616c11 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -894,7 +894,9 @@ BUILT_SOURCES +=\
protocol/ivi-hmi-controller-protocol.c  \
protocol/ivi-hmi-controller-client-protocol.h   \
protocol/ivi-application-protocol.c \
-   protocol/ivi-application-client-protocol.h
+   protocol/ivi-application-client-protocol.h  \
+   protocol/input-timestamps-unstable-v1-protocol.c\
+   protocol/input-timestamps-unstable-v1-client-protocol.h
 
 westondatadir = $(datadir)/weston
 dist_westondata_DATA = \
@@ -1351,10 +1353,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/tests/input-timestamps-helper.c b/tests/input-timestamps-helper.c
new file mode 100644
index ..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 
+#include 
+#include 
+#include 
+
+#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

[PATCH weston 1/6] shared: Add timespec_eq helper function

2017-12-20 Thread Alexandros Frantzis
Add a helper function to check if two struct timespec values are equal.
This helper function will be used in upcoming commits that implement the
input_timestamps_unstable_v1 protocol.

Signed-off-by: Alexandros Frantzis 
---
 shared/timespec-util.h | 13 +
 tests/timespec-test.c  | 12 
 2 files changed, 25 insertions(+)

diff --git a/shared/timespec-util.h b/shared/timespec-util.h
index 5f4b2b9e..ca0156af 100644
--- a/shared/timespec-util.h
+++ b/shared/timespec-util.h
@@ -231,6 +231,19 @@ timespec_is_zero(const struct timespec *a)
return a->tv_sec == 0 && a->tv_nsec == 0;
 }
 
+/* Check if two timespecs are equal
+ *
+ * \param a[in] timespec to check
+ * \param b[in] timespec to check
+ * \return whether timespecs a and b are equal
+ */
+static inline bool
+timespec_eq(const struct timespec *a, const struct timespec *b)
+{
+   return a->tv_sec == b->tv_sec &&
+  a->tv_nsec == b->tv_nsec;
+}
+
 /* Convert milli-Hertz to nanoseconds
  *
  * \param mhz frequency in mHz, not zero
diff --git a/tests/timespec-test.c b/tests/timespec-test.c
index 54230f89..24400187 100644
--- a/tests/timespec-test.c
+++ b/tests/timespec-test.c
@@ -294,3 +294,15 @@ ZUC_TEST(timespec_test, timespec_is_zero)
ZUC_ASSERT_FALSE(timespec_is_zero(&non_zero_nsec));
ZUC_ASSERT_FALSE(timespec_is_zero(&non_zero_sec));
 }
+
+ZUC_TEST(timespec_test, timespec_eq)
+{
+   struct timespec a = { .tv_sec = 2, .tv_nsec = 1 };
+   struct timespec b = { .tv_sec = -1, .tv_nsec = 2 };
+
+   ZUC_ASSERT_TRUE(timespec_eq(&a, &a));
+   ZUC_ASSERT_TRUE(timespec_eq(&b, &b));
+
+   ZUC_ASSERT_FALSE(timespec_eq(&a, &b));
+   ZUC_ASSERT_FALSE(timespec_eq(&b, &a));
+}
-- 
2.14.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


Re: [PATCH wayland-protocols v2] unstable: Add input-timestamps protocol

2017-12-20 Thread Alexandros Frantzis
On Tue, Dec 19, 2017 at 01:06:11PM +0200, Alexandros Frantzis wrote:
> On Tue, Dec 19, 2017 at 10:15:06AM +0200, Pekka Paalanen wrote:
> > On Mon, 18 Dec 2017 14:55:00 +0200
> > Alexandros Frantzis  wrote:
> > 
> > > wl_pointer, wl_keyboard and wl_touch events currently use a 32-bit
> > > timestamp with millisecond resolution. In some cases, notably latency
> > > measurements, this resolution is too coarse to be useful.
> > > 
> > > This protocol provides additional high-resolution timestamps events,
> > > which are emitted before the corresponding input event. Each timestamp
> > > event contains a high-resolution, and ideally higher-accuracy, version
> > > of the 'time' argument of the first subsequent supported input event.
> > > 
> > > Clients that care about high-resolution timestamps just need to keep
> > > track of the last timestamp event they receive and associate it with the
> > > next supported input event that arrives.
> > > 
> > > Signed-off-by: Alexandros Frantzis 
> > > Reviewed-by: Pekka Paalanen 
> > > Acked-by: Jonas Ådahl 
> > > ---
> > > 
> > > Changes in v2:
> > >  - Add '...carrying a timestamp...' to better describe the set of 
> > > subsequent
> > >input events in the timestamp event description. 
> > >  - Clarify normalization requirements of tv_sec_hi, tv_sec_lo, tv_nsec
> > >timestamp representation.
> > > 
> > >  Makefile.am|   1 +
> > >  unstable/input-timestamps/README   |   4 +
> > >  .../input-timestamps-unstable-v1.xml   | 145 
> > > +
> > >  3 files changed, 150 insertions(+)
> > >  create mode 100644 unstable/input-timestamps/README
> > >  create mode 100644 
> > > unstable/input-timestamps/input-timestamps-unstable-v1.xml
> > 
> > Cool! I suppose we want to see the Weston implementation patches posted
> > to the list before landing this?
> 
> The plan is to refresh and clean up the proof-of-concept Weston
> implementation and propose it. For those interested to take an
> early look the p-o-c code is at:
> 
> https://gitlab.collabora.com/alf/weston/commits/zwp-input-timestamps

Hi all,

a heads-up that I have posted the libweston input-timestamps patchset
for review at:

https://lists.freedesktop.org/archives/wayland-devel/2017-December/036392.html

Thanks,
Alexandros
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH weston 4/8] libweston: Make weston_seat release safe

2018-01-26 Thread Alexandros Frantzis
Ensure the server can safely handle client requests for wl_seat resource
that have become inert due to weston_seat object release and subsequent
destruction.

The clean-up involves, among other things, unsetting the destroyed
weston_seat object from the user data of wl_seat resources, and handling
this NULL user data case where required.

Signed-off-by: Alexandros Frantzis 
---
 libweston/input.c | 45 +++--
 1 file changed, 35 insertions(+), 10 deletions(-)

diff --git a/libweston/input.c b/libweston/input.c
index 48bcc55c..e4daa56b 100644
--- a/libweston/input.c
+++ b/libweston/input.c
@@ -2412,6 +2412,13 @@ seat_get_pointer(struct wl_client *client, struct 
wl_resource *resource,
 uint32_t id)
 {
struct weston_seat *seat = wl_resource_get_user_data(resource);
+   struct weston_pointer *pointer;
+   struct wl_resource *cr;
+   struct weston_pointer_client *pointer_client;
+
+   if (!seat)
+   return;
+
/* We use the pointer_state directly, which means we'll
 * give a wl_pointer if the seat has ever had one - even though
 * the spec explicitly states that this request only takes effect
@@ -2420,10 +2427,7 @@ seat_get_pointer(struct wl_client *client, struct 
wl_resource *resource,
 * This prevents a race between the compositor sending new
 * capabilities and the client trying to use the old ones.
 */
-   struct weston_pointer *pointer = seat->pointer_state;
-   struct wl_resource *cr;
-   struct weston_pointer_client *pointer_client;
-
+   pointer = seat->pointer_state;
if (!pointer)
return;
 
@@ -2499,6 +2503,12 @@ seat_get_keyboard(struct wl_client *client, struct 
wl_resource *resource,
  uint32_t id)
 {
struct weston_seat *seat = wl_resource_get_user_data(resource);
+   struct weston_keyboard *keyboard;
+   struct wl_resource *cr;
+
+   if (!seat)
+   return;
+
/* We use the keyboard_state directly, which means we'll
 * give a wl_keyboard if the seat has ever had one - even though
 * the spec explicitly states that this request only takes effect
@@ -2507,9 +2517,7 @@ seat_get_keyboard(struct wl_client *client, struct 
wl_resource *resource,
 * This prevents a race between the compositor sending new
 * capabilities and the client trying to use the old ones.
 */
-   struct weston_keyboard *keyboard = seat->keyboard_state;
-   struct wl_resource *cr;
-
+   keyboard = seat->keyboard_state;
if (!keyboard)
return;
 
@@ -2579,6 +2587,12 @@ seat_get_touch(struct wl_client *client, struct 
wl_resource *resource,
   uint32_t id)
 {
struct weston_seat *seat = wl_resource_get_user_data(resource);
+   struct weston_touch *touch;
+   struct wl_resource *cr;
+
+   if (!seat)
+   return;
+
/* We use the touch_state directly, which means we'll
 * give a wl_touch if the seat has ever had one - even though
 * the spec explicitly states that this request only takes effect
@@ -2587,9 +2601,7 @@ seat_get_touch(struct wl_client *client, struct 
wl_resource *resource,
 * This prevents a race between the compositor sending new
 * capabilities and the client trying to use the old ones.
 */
-   struct weston_touch *touch = seat->touch_state;
-   struct wl_resource *cr;
-
+   touch = seat->touch_state;
if (!touch)
return;
 
@@ -3087,6 +3099,19 @@ weston_seat_init(struct weston_seat *seat, struct 
weston_compositor *ec,
 WL_EXPORT void
 weston_seat_release(struct weston_seat *seat)
 {
+   struct wl_resource *resource;
+
+   wl_resource_for_each(resource, &seat->base_resource_list) {
+   wl_resource_set_user_data(resource, NULL);
+   }
+
+   wl_resource_for_each(resource, &seat->drag_resource_list) {
+   wl_resource_set_user_data(resource, NULL);
+   }
+
+   wl_list_remove(&seat->base_resource_list);
+   wl_list_remove(&seat->drag_resource_list);
+
wl_list_remove(&seat->link);
 
if (seat->saved_kbd_focus)
-- 
2.14.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH weston 2/8] libweston: Make weston_keyboard destruction safe

2018-01-26 Thread Alexandros Frantzis
Ensure the server can safely handle client requests for wl_keyboard
resources that have become inert due to a weston_keyboard object
destruction.

This change involves, among other things, setting the weston_keyboard
object, instead of the weston_seat object, as the user data for
wl_keyboard resources.  Although this is not strictly required at the
moment (since no code is using the wl_keyboard user data), it makes the
code safer:

 * It makes more sense conceptually.
 * It is consistent with how wl_pointer resources are handled.
 * It allows us to clear the user data during weston_keyboard
   destruction, so other code can check whether the resource is inert.

Signed-off-by: Alexandros Frantzis 
---
 libweston/input.c | 15 +--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/libweston/input.c b/libweston/input.c
index 01f0d568..96cabf25 100644
--- a/libweston/input.c
+++ b/libweston/input.c
@@ -1166,7 +1166,18 @@ weston_xkb_info_destroy(struct weston_xkb_info 
*xkb_info);
 WL_EXPORT void
 weston_keyboard_destroy(struct weston_keyboard *keyboard)
 {
-   /* XXX: What about keyboard->resource_list? */
+   struct wl_resource *resource;
+
+   wl_resource_for_each(resource, &keyboard->resource_list) {
+   wl_resource_set_user_data(resource, NULL);
+   }
+
+   wl_resource_for_each(resource, &keyboard->focus_resource_list) {
+   wl_resource_set_user_data(resource, NULL);
+   }
+
+   wl_list_remove(&keyboard->resource_list);
+   wl_list_remove(&keyboard->focus_resource_list);
 
xkb_state_unref(keyboard->xkb_state.state);
if (keyboard->xkb_info)
@@ -2504,7 +2515,7 @@ seat_get_keyboard(struct wl_client *client, struct 
wl_resource *resource,
 * focused */
wl_list_insert(&keyboard->resource_list, wl_resource_get_link(cr));
wl_resource_set_implementation(cr, &keyboard_interface,
-  seat, unbind_resource);
+  keyboard, unbind_resource);
 
if (wl_resource_get_version(cr) >= 
WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION) {
wl_keyboard_send_repeat_info(cr,
-- 
2.14.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH weston 3/8] libweston: Make weston_touch destruction safe

2018-01-26 Thread Alexandros Frantzis
Ensure the server can safely handle client requests for wl_touch
resources that have become inert due to a weston_touch object
destruction.

This change involves, among other things, setting the weston_touch
object, instead of the weston_seat object, as the user data for wl_touch
resources. Although this is not strictly required at the moment (since
no code is using the wl_touch user data), it makes the code safer:

 * It makes more sense conceptually.
 * It is consistent with how wl_pointer resources are handled.
 * It allows us to clear the user data during weston_touch
   destruction, so other code can check whether the resource is
   inert.

Signed-off-by: Alexandros Frantzis 
---
 libweston/input.c | 14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/libweston/input.c b/libweston/input.c
index 96cabf25..48bcc55c 100644
--- a/libweston/input.c
+++ b/libweston/input.c
@@ -1221,8 +1221,18 @@ weston_touch_create(void)
 WL_EXPORT void
 weston_touch_destroy(struct weston_touch *touch)
 {
-   /* XXX: What about touch->resource_list? */
+   struct wl_resource *resource;
+
+   wl_resource_for_each(resource, &touch->resource_list) {
+   wl_resource_set_user_data(resource, NULL);
+   }
+
+   wl_resource_for_each(resource, &touch->focus_resource_list) {
+   wl_resource_set_user_data(resource, NULL);
+   }
 
+   wl_list_remove(&touch->resource_list);
+   wl_list_remove(&touch->focus_resource_list);
wl_list_remove(&touch->focus_view_listener.link);
wl_list_remove(&touch->focus_resource_listener.link);
free(touch);
@@ -2599,7 +2609,7 @@ seat_get_touch(struct wl_client *client, struct 
wl_resource *resource,
   wl_resource_get_link(cr));
}
wl_resource_set_implementation(cr, &touch_interface,
-  seat, unbind_resource);
+  touch, unbind_resource);
 }
 
 static void
-- 
2.14.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH weston 1/8] libweston: Make weston_pointer destruction safe

2018-01-26 Thread Alexandros Frantzis
Properly clean up all sub-objects (e.g., weston_pointer_client objects)
when a weston_pointer object is destroyed. The clean-up ensures that the
server is able to safely handle client requests to any associated
pointer resources, which, as a consenquence of a weston_pointer
destruction, have now become inert.

The clean-up involves, among other things, unsetting the destroyed
weston_pointer object from the user data of pointer resources, and
handling this NULL user data case where required.

Signed-off-by: Alexandros Frantzis 
---
 libweston/input.c | 41 -
 1 file changed, 36 insertions(+), 5 deletions(-)

diff --git a/libweston/input.c b/libweston/input.c
index 94a3423a..01f0d568 100644
--- a/libweston/input.c
+++ b/libweston/input.c
@@ -105,6 +105,19 @@ weston_pointer_client_create(struct wl_client *client)
 static void
 weston_pointer_client_destroy(struct weston_pointer_client *pointer_client)
 {
+   struct wl_resource *resource;
+
+   wl_resource_for_each(resource, &pointer_client->pointer_resources) {
+   wl_resource_set_user_data(resource, NULL);
+   }
+
+   wl_resource_for_each(resource,
+&pointer_client->relative_pointer_resources) {
+   wl_resource_set_user_data(resource, NULL);
+   }
+
+   wl_list_remove(&pointer_client->pointer_resources);
+   wl_list_remove(&pointer_client->relative_pointer_resources);
free(pointer_client);
 }
 
@@ -170,11 +183,14 @@ unbind_pointer_client_resource(struct wl_resource 
*resource)
struct wl_client *client = wl_resource_get_client(resource);
struct weston_pointer_client *pointer_client;
 
-   pointer_client = weston_pointer_get_pointer_client(pointer, client);
-   assert(pointer_client);
-
wl_list_remove(wl_resource_get_link(resource));
-   weston_pointer_cleanup_pointer_client(pointer, pointer_client);
+
+   if (pointer) {
+   pointer_client = weston_pointer_get_pointer_client(pointer,
+  client);
+   assert(pointer_client);
+   weston_pointer_cleanup_pointer_client(pointer, pointer_client);
+   }
 }
 
 static void unbind_resource(struct wl_resource *resource)
@@ -1092,12 +1108,18 @@ weston_pointer_create(struct weston_seat *seat)
 WL_EXPORT void
 weston_pointer_destroy(struct weston_pointer *pointer)
 {
+   struct weston_pointer_client *pointer_client, *tmp;
+
wl_signal_emit(&pointer->destroy_signal, pointer);
 
if (pointer->sprite)
pointer_unmap_sprite(pointer);
 
-   /* XXX: What about pointer->resource_list? */
+   wl_list_for_each_safe(pointer_client, tmp, &pointer->pointer_clients,
+ link) {
+   wl_list_remove(&pointer_client->link);
+   weston_pointer_client_destroy(pointer_client);
+   }
 
wl_list_remove(&pointer->focus_resource_listener.link);
wl_list_remove(&pointer->focus_view_listener.link);
@@ -2297,6 +2319,9 @@ pointer_set_cursor(struct wl_client *client, struct 
wl_resource *resource,
struct weston_pointer *pointer = wl_resource_get_user_data(resource);
struct weston_surface *surface = NULL;
 
+   if (!pointer)
+   return;
+
if (surface_resource)
surface = wl_resource_get_user_data(surface_resource);
 
@@ -3674,6 +3699,9 @@ pointer_constraints_lock_pointer(struct wl_client *client,
struct weston_region *region = region_resource ?
wl_resource_get_user_data(region_resource) : NULL;
 
+   if (!pointer)
+   return;
+
init_pointer_constraint(resource, id, surface, pointer, region, 
lifetime,
&zwp_locked_pointer_v1_interface,
&locked_pointer_interface,
@@ -4467,6 +4495,9 @@ pointer_constraints_confine_pointer(struct wl_client 
*client,
struct weston_region *region = region_resource ?
wl_resource_get_user_data(region_resource) : NULL;
 
+   if (!pointer)
+   return;
+
init_pointer_constraint(resource, id, surface, pointer, region, 
lifetime,
&zwp_confined_pointer_v1_interface,
&confined_pointer_interface,
-- 
2.14.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH weston 5/8] tests: Support setting the test client input dynamically

2018-01-26 Thread Alexandros Frantzis
The current test client code waits for all wl_seat globals to arrive
before checking them and deciding which one is the test seat global to
use for the input object. This method doesn't support dynamic addition
of the test seat global (i.e., after client start-up), which will be
needed in upcoming commits.

This commit changes the code to check for the test seat and set up the
input object while handling the wl_seat information events.

Signed-off-by: Alexandros Frantzis 
---
 tests/weston-test-client-helper.c | 78 ++-
 tests/weston-test-client-helper.h |  1 +
 2 files changed, 46 insertions(+), 33 deletions(-)

diff --git a/tests/weston-test-client-helper.c 
b/tests/weston-test-client-helper.c
index 6e0a5246..854978d0 100644
--- a/tests/weston-test-client-helper.c
+++ b/tests/weston-test-client-helper.c
@@ -538,6 +538,14 @@ static const struct weston_test_listener test_listener = {
test_handle_capture_screenshot_done,
 };
 
+static void
+input_destroy(struct input *inp)
+{
+   wl_list_remove(&inp->link);
+   wl_seat_destroy(inp->wl_seat);
+   free(inp);
+}
+
 static void
 input_update_devices(struct input *input)
 {
@@ -598,22 +606,56 @@ seat_handle_capabilities(void *data, struct wl_seat *seat,
 
/* we will create/update the devices only with the right (test) seat.
 * If we haven't discovered which seat is the test seat, just
-* store capabilities and bail out */
-   if (input->seat_name && strcmp(input->seat_name, "test-seat") == 0)
+* store capabilities and bail out. Note that we don't need to
+* check the name contents here, since only the test seat input will
+* have its name set */
+   if (input->seat_name) {
input_update_devices(input);
+   input->client->input = input;
+   }
+
 
fprintf(stderr, "test-client: got seat %p capabilities: %x\n",
input, caps);
 }
 
+static struct input *
+client_find_input_with_seat_name(struct client *client, const char *name)
+{
+   struct input *input;
+
+   wl_list_for_each(input, &client->inputs, link) {
+   if (input->seat_name && strcmp(input->seat_name, name) == 0)
+   return input;
+   }
+
+   return NULL;
+}
+
 static void
 seat_handle_name(void *data, struct wl_seat *seat, const char *name)
 {
struct input *input = data;
 
+   /* We don't care about seats other than the test seat */
+   if (strcmp(name, "test-seat") != 0) {
+   input_destroy(input);
+   return;
+   }
+
+   assert(!client_find_input_with_seat_name(input->client, name) &&
+  "Multiple test seats detected!");
+
input->seat_name = strdup(name);
assert(input->seat_name && "No memory");
 
+   /* We assume that the test seat always has some capabilities,
+* so caps == 0 just means that we haven't received them yet */
+   if (input->caps != 0) {
+   input_update_devices(input);
+   input->client->input = input;
+   }
+
fprintf(stderr, "test-client: got seat %p name: \'%s\'\n",
input, name);
 }
@@ -705,6 +747,7 @@ handle_global(void *data, struct wl_registry *registry,
 &wl_compositor_interface, version);
} else if (strcmp(interface, "wl_seat") == 0) {
input = xzalloc(sizeof *input);
+   input->client = client;
input->wl_seat =
wl_registry_bind(registry, id,
 &wl_seat_interface, version);
@@ -809,34 +852,6 @@ log_handler(const char *fmt, va_list args)
vfprintf(stderr, fmt, args);
 }
 
-static void
-input_destroy(struct input *inp)
-{
-   wl_list_remove(&inp->link);
-   wl_seat_destroy(inp->wl_seat);
-   free(inp);
-}
-
-/* find the test-seat and set it in client.
- * Destroy other inputs */
-static void
-client_set_input(struct client *cl)
-{
-   struct input *inp, *inptmp;
-   wl_list_for_each_safe(inp, inptmp, &cl->inputs, link) {
-   assert(inp->seat_name && "BUG: input with no name");
-   if (strcmp(inp->seat_name, "test-seat") == 0) {
-   cl->input = inp;
-   input_update_devices(inp);
-   } else {
-   input_destroy(inp);
-   }
-   }
-
-   /* we keep only one input */
-   assert(wl_list_length(&cl->inputs) == 1);
-}
-
 struct client *
 create_client(void)
 {
@@ -862,9 +877,6 @@ create_client(void)
 * events */
client_roundtrip(client);
 
-   /* find the right

[PATCH weston 0/8] libweston: Make input object destruction safe

2018-01-26 Thread Alexandros Frantzis
When an weston seat or input object is destroyed, any associated client
resources should become inert and put in a state in which they can
safely handle client requests. Currently, client requests to such
resources may lead to crashes and/or memory errors in the server.

This patchset aims to fix (or at least greatly improve) the situation.

Patches (1) to (4) ensure that when the various input objects are
destroyed, any associated resources are made inert and can safely handle
client requests.

Patches (5) to (7) update the test infrastructure to properly support
requests to dynamically add and remove the test seat.

Patch (8) introduces a test for removing and re-adding the test seat.
This test indirectly checks some of the input code fixes made in the
patches 1-4. Two things to note about this test:

1. As mentioned in more detail in the commit, the test needs to be in
its own file for now.  I haven't investigated in depth but the problem
seems to be in desktop-shell's lack of support for wl_seat
removal/re-addition. As a test, I tried running with the
fullscreen-shell and the problem is gone. This was too deep of a rabbit
hole to go into in this patchset, but I will investigate further and
hopefully we can remove this workaround.

2. Even without some of the fixes in the patches 1-4, the test may seem
to pass. However, running with a memory debugger reveals a different
story, since without the fixes we encounter various memory errors.

Alexandros Frantzis (8):
  libweston: Make weston_pointer destruction safe
  libweston: Make weston_keyboard destruction safe
  libweston: Make weston_touch destruction safe
  libweston: Make weston_seat release safe
  tests: Support setting the test client input dynamically
  tests: Support weston_test request for adding a test seat
  tests: Handle removal of seat global in test clients
  tests: Add test for seat destruction and creation

 Makefile.am   |   5 ++
 libweston/input.c | 115 -
 tests/devices-seat-test.c |  53 ++
 tests/weston-test-client-helper.c | 147 +-
 tests/weston-test-client-helper.h |   2 +
 tests/weston-test.c   |  32 +++--
 6 files changed, 294 insertions(+), 60 deletions(-)
 create mode 100644 tests/devices-seat-test.c

-- 
2.14.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH weston 8/8] tests: Add test for seat destruction and creation

2018-01-26 Thread Alexandros Frantzis
Add a test to check that we can destroy and create the test seat. Since
after test seat destruction the test client releases any associated
input resources, this test also checks that libweston properly handles
release requests for inert input resources.

The test is placed in its own file for the time being, so it can run
independently. This is needed because the desktop shell, which is used
when running tests, doesn't deal well with seat destruction and creation
at the moment and may causes crashes in other tests. When this is fixed
we can merge this test into devices-test.c.

Signed-off-by: Alexandros Frantzis 
---
 Makefile.am   |  5 +
 tests/devices-seat-test.c | 53 +++
 2 files changed, 58 insertions(+)
 create mode 100644 tests/devices-seat-test.c

diff --git a/Makefile.am b/Makefile.am
index e224d606..f0370973 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1234,6 +1234,7 @@ weston_tests =\
subsurface.weston   \
subsurface-shot.weston  \
devices.weston  \
+   devices-seat.weston \
touch.weston
 
 ivi_tests =
@@ -1392,6 +1393,10 @@ devices_weston_SOURCES = tests/devices-test.c
 devices_weston_CFLAGS = $(AM_CFLAGS) $(TEST_CLIENT_CFLAGS)
 devices_weston_LDADD = libtest-client.la
 
+devices_seat_weston_SOURCES = tests/devices-seat-test.c
+devices_seat_weston_CFLAGS = $(AM_CFLAGS) $(TEST_CLIENT_CFLAGS)
+devices_seat_weston_LDADD = libtest-client.la
+
 text_weston_SOURCES = tests/text-test.c
 nodist_text_weston_SOURCES =   \
protocol/text-input-unstable-v1-protocol.c  \
diff --git a/tests/devices-seat-test.c b/tests/devices-seat-test.c
new file mode 100644
index ..182df1d5
--- /dev/null
+++ b/tests/devices-seat-test.c
@@ -0,0 +1,53 @@
+/*
+ * Copyright © 2018 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 "weston-test-client-helper.h"
+
+/**
+ * Test destroying/recreating seats
+ *
+ * The seat destroy/recreate test is placed in its own file for the time
+ * being, so it can run independently. This is needed because the desktop
+ * shell, which is used when running tests, doesn't deal well with seat
+ * destruction and recreation at the moment and may causes crashes in other
+ * tests. When this is fixed we can merge this test into devices-test.c.
+ */
+
+TEST(seat_destroy_and_recreate)
+{
+   struct client *cl = create_client_and_test_surface(100, 100, 100, 100);
+
+   weston_test_device_release(cl->test->weston_test, "seat");
+   /* Roundtrip to receive and handle the seat global removal event */
+   client_roundtrip(cl);
+
+   weston_test_device_add(cl->test->weston_test, "seat");
+   /* First roundtrip to send request and receive new seat global */
+   client_roundtrip(cl);
+   /* Second roundtrip to handle seat events and set up input devices */
+   client_roundtrip(cl);
+}
-- 
2.14.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH weston 6/8] tests: Support weston_test request for adding a test seat

2018-01-26 Thread Alexandros Frantzis
Support adding a test seat using the weston_test.device_add request.
This will be used in tests in upcoming commits where we will need to
re-add the seat after having it removed.

We only support one test seat at the moment, so this commit also
introduces checks to ensure the client doesn't try to create multiple
test seats or try to remove an already removed test seat.

Signed-off-by: Alexandros Frantzis 
---
 tests/weston-test.c | 32 +---
 1 file changed, 25 insertions(+), 7 deletions(-)

diff --git a/tests/weston-test.c b/tests/weston-test.c
index 80b3d65b..9a2fd286 100644
--- a/tests/weston-test.c
+++ b/tests/weston-test.c
@@ -50,6 +50,7 @@ struct weston_test {
struct weston_layer layer;
struct weston_process process;
struct weston_seat seat;
+   bool is_seat_initialized;
 };
 
 struct weston_test_surface {
@@ -76,6 +77,22 @@ test_client_sigchld(struct weston_process *process, int 
status)
wl_display_terminate(test->compositor->wl_display);
 }
 
+static int
+test_seat_init(struct weston_test *test)
+{
+   /* create our own seat */
+   weston_seat_init(&test->seat, test->compositor, "test-seat");
+   test->is_seat_initialized = true;
+
+   /* add devices */
+   weston_seat_init_pointer(&test->seat);
+   if (weston_seat_init_keyboard(&test->seat, NULL) < 0)
+   return -1;
+   weston_seat_init_touch(&test->seat);
+
+   return 0;
+}
+
 static struct weston_seat *
 get_seat(struct weston_test *test)
 {
@@ -253,7 +270,10 @@ device_release(struct wl_client *client,
} else if (strcmp(device, "touch") == 0) {
weston_seat_release_touch(seat);
} else if (strcmp(device, "seat") == 0) {
+   assert(test->is_seat_initialized &&
+  "Trying to release already released test seat");
weston_seat_release(seat);
+   test->is_seat_initialized = false;
} else {
assert(0 && "Unsupported device");
}
@@ -272,6 +292,10 @@ device_add(struct wl_client *client,
weston_seat_init_keyboard(seat, NULL);
} else if (strcmp(device, "touch") == 0) {
weston_seat_init_touch(seat);
+   } else if (strcmp(device, "seat") == 0) {
+   assert(!test->is_seat_initialized &&
+  "Trying to add already added test seat");
+   test_seat_init(test);
} else {
assert(0 && "Unsupported device");
}
@@ -611,14 +635,8 @@ wet_module_init(struct weston_compositor *ec,
 test, bind_test) == NULL)
return -1;
 
-   /* create our own seat */
-   weston_seat_init(&test->seat, ec, "test-seat");
-
-   /* add devices */
-   weston_seat_init_pointer(&test->seat);
-   if (weston_seat_init_keyboard(&test->seat, NULL) < 0)
+   if (test_seat_init(test) == -1)
return -1;
-   weston_seat_init_touch(&test->seat);
 
loop = wl_display_get_event_loop(ec->wl_display);
wl_event_loop_add_idle(loop, idle_launch_client, test);
-- 
2.14.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH weston 7/8] tests: Handle removal of seat global in test clients

2018-01-26 Thread Alexandros Frantzis
The current test client code completely ignores removal of globals.
This commit updates the code to properly handle removal of globals in
general, and of seat globals in particular. This ensures that the test
client objects are in sync with the server and any relevant resources
are released accordingly.

This update will be used by upcoming tests to check that seat removal
and re-addition is working properly.

Signed-off-by: Alexandros Frantzis 
---
 tests/weston-test-client-helper.c | 71 +--
 tests/weston-test-client-helper.h |  1 +
 2 files changed, 70 insertions(+), 2 deletions(-)

diff --git a/tests/weston-test-client-helper.c 
b/tests/weston-test-client-helper.c
index 854978d0..6dc72213 100644
--- a/tests/weston-test-client-helper.c
+++ b/tests/weston-test-client-helper.c
@@ -541,8 +541,23 @@ static const struct weston_test_listener test_listener = {
 static void
 input_destroy(struct input *inp)
 {
+   if (inp->pointer) {
+   if (inp->pointer->wl_pointer)
+   wl_pointer_release(inp->pointer->wl_pointer);
+   free(inp->pointer);
+   }
+   if (inp->keyboard) {
+   if (inp->keyboard->wl_keyboard)
+   wl_keyboard_release(inp->keyboard->wl_keyboard);
+   free(inp->keyboard);
+   }
+   if (inp->touch) {
+   if (inp->touch->wl_touch)
+   wl_touch_release(inp->touch->wl_touch);
+   free(inp->touch);
+   }
wl_list_remove(&inp->link);
-   wl_seat_destroy(inp->wl_seat);
+   wl_seat_release(inp->wl_seat);
free(inp);
 }
 
@@ -748,6 +763,7 @@ handle_global(void *data, struct wl_registry *registry,
} else if (strcmp(interface, "wl_seat") == 0) {
input = xzalloc(sizeof *input);
input->client = client;
+   input->global_name = global->name;
input->wl_seat =
wl_registry_bind(registry, id,
 &wl_seat_interface, version);
@@ -778,8 +794,59 @@ handle_global(void *data, struct wl_registry *registry,
}
 }
 
+static struct global *
+client_find_global_with_name(struct client *client, uint32_t name)
+{
+   struct global *global;
+
+   wl_list_for_each(global, &client->global_list, link) {
+   if (global->name == name)
+   return global;
+   }
+
+   return NULL;
+}
+
+static struct input *
+client_find_input_with_name(struct client *client, uint32_t name)
+{
+   struct input *input;
+
+   wl_list_for_each(input, &client->inputs, link) {
+   if (input->global_name == name)
+   return input;
+   }
+
+   return NULL;
+}
+
+static void
+handle_global_remove(void *data, struct wl_registry *registry, uint32_t name)
+{
+   struct client *client = data;
+   struct global *global;
+   struct input *input;
+
+   global = client_find_global_with_name(client, name);
+   assert(global && "Request to remove unknown global");
+
+   if (strcmp(global->interface, "wl_seat") == 0) {
+   input = client_find_input_with_name(client, name);
+   if (input) {
+   if (client->input == input)
+   client->input = NULL;
+   input_destroy(input);
+   }
+   }
+
+   wl_list_remove(&global->link);
+   free(global->interface);
+   free(global);
+}
+
 static const struct wl_registry_listener registry_listener = {
-   handle_global
+   handle_global,
+   handle_global_remove,
 };
 
 void
diff --git a/tests/weston-test-client-helper.h 
b/tests/weston-test-client-helper.h
index f16356e5..255bbf66 100644
--- a/tests/weston-test-client-helper.h
+++ b/tests/weston-test-client-helper.h
@@ -75,6 +75,7 @@ struct test {
 
 struct input {
struct client *client;
+   uint32_t global_name;
struct wl_seat *wl_seat;
struct pointer *pointer;
struct keyboard *keyboard;
-- 
2.14.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


Re: [PATCH weston 6/6] libweston: Implement touch timestamps for input_timestamps_unstable_v1

2018-01-26 Thread Alexandros Frantzis
On Fri, Jan 19, 2018 at 12:18:38PM +0200, Pekka Paalanen wrote:
> On Wed, 20 Dec 2017 16:18:01 +0200
> Alexandros Frantzis  wrote:
> 
> > Implement the zwp_input_timestamps_v1.get_touch_timestamps request to
> > subscribe to timestamp events for wl_touch resources.
> > 
> > Signed-off-by: Alexandros Frantzis 
> > ---
> >  libweston/compositor.h |  2 ++
> >  libweston/input.c  | 53 
> > +++---
> >  tests/touch-test.c | 46 +++
> >  3 files changed, 94 insertions(+), 7 deletions(-)
> 
> > @@ -4643,7 +4665,24 @@ input_timestamps_manager_get_touch_timestamps(struct 
> > wl_client *client,
> >   uint32_t id,
> >   struct wl_resource 
> > *touch_resource)
> >  {
> > -   wl_client_post_no_memory(client);
> > +   struct weston_seat *seat = wl_resource_get_user_data(touch_resource);
> > +   struct wl_resource *input_ts;
> > +
> > +   input_ts = wl_resource_create(client,
> > + &zwp_input_timestamps_v1_interface,
> > + 1, id);
> > +   if (!input_ts) {
> > +   wl_client_post_no_memory(client);
> > +   return;
> > +   }
> > +
> > +   wl_resource_set_implementation(input_ts,
> > +  &input_timestamps_interface,
> > +  touch_resource,
> > +  unbind_resource);
> > +
> > +   wl_list_insert(&seat->touch_state->timestamps_list,
> > +  wl_resource_get_link(input_ts));
> 
> Btw. each of the three patches adds a new list to weston_keyboard,
> weston_pointer, weston_touch, but following the example already set in
> the code, do not handle that struct getting destroyed while client
> resources for it still exist. This would be good to fix, at least for
> the new lists introduced in these patches. I only realized that after
> sending the earlier R-bs.
> 
> You can find the places with:
>   $ git grep -p 'XXX: What about'
> 
> Otherwise the patch looks good, tests included. Nice work with the
> series.
> 
> Thanks,
> pq

Hi Pekka,

thanks for the review.

While investigating how to best solve this I realized that in order to
safely destroy the timestamp(_manager) objects, I had to first ensure
that the input objects are also properly destroyed. I have posted a
proposal for making the destruction of input objects safe here:

https://lists.freedesktop.org/archives/wayland-devel/2018-January/036701.html

When the input object destruction issues are resolved I will post
an updated version of this proposal.

Thanks,
Alexandros


___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


Re: [PATCH weston 4/8] libweston: Make weston_seat release safe

2018-01-31 Thread Alexandros Frantzis
On Wed, Jan 31, 2018 at 03:21:07PM +0200, Pekka Paalanen wrote:
> On Fri, 26 Jan 2018 18:47:58 +0200
> Alexandros Frantzis  wrote:
> 
> > Ensure the server can safely handle client requests for wl_seat resource
> > that have become inert due to weston_seat object release and subsequent
> > destruction.
> > 
> > The clean-up involves, among other things, unsetting the destroyed
> > weston_seat object from the user data of wl_seat resources, and handling
> > this NULL user data case where required.
> > 
> > Signed-off-by: Alexandros Frantzis 
> > ---
> >  libweston/input.c | 45 +++--
> >  1 file changed, 35 insertions(+), 10 deletions(-)
> > 
> > diff --git a/libweston/input.c b/libweston/input.c
> > index 48bcc55c..e4daa56b 100644
> > --- a/libweston/input.c
> > +++ b/libweston/input.c
> > @@ -2412,6 +2412,13 @@ seat_get_pointer(struct wl_client *client, struct 
> > wl_resource *resource,
> >  uint32_t id)
> >  {
> > struct weston_seat *seat = wl_resource_get_user_data(resource);
> > +   struct weston_pointer *pointer;
> > +   struct wl_resource *cr;
> > +   struct weston_pointer_client *pointer_client;
> > +
> > +   if (!seat)
> > +   return;
> > +
> > /* We use the pointer_state directly, which means we'll
> >  * give a wl_pointer if the seat has ever had one - even though
> >  * the spec explicitly states that this request only takes effect
> > @@ -2420,10 +2427,7 @@ seat_get_pointer(struct wl_client *client, struct 
> > wl_resource *resource,
> >  * This prevents a race between the compositor sending new
> >  * capabilities and the client trying to use the old ones.
> >  */
> > -   struct weston_pointer *pointer = seat->pointer_state;
> > -   struct wl_resource *cr;
> > -   struct weston_pointer_client *pointer_client;
> > -
> > +   pointer = seat->pointer_state;
> > if (!pointer)
> > return;
> >  
> > @@ -2499,6 +2503,12 @@ seat_get_keyboard(struct wl_client *client, struct 
> > wl_resource *resource,
> >   uint32_t id)
> >  {
> > struct weston_seat *seat = wl_resource_get_user_data(resource);
> > +   struct weston_keyboard *keyboard;
> > +   struct wl_resource *cr;
> > +
> > +   if (!seat)
> > +   return;
> > +
> > /* We use the keyboard_state directly, which means we'll
> >  * give a wl_keyboard if the seat has ever had one - even though
> >  * the spec explicitly states that this request only takes effect
> > @@ -2507,9 +2517,7 @@ seat_get_keyboard(struct wl_client *client, struct 
> > wl_resource *resource,
> >  * This prevents a race between the compositor sending new
> >  * capabilities and the client trying to use the old ones.
> >  */
> > -   struct weston_keyboard *keyboard = seat->keyboard_state;
> > -   struct wl_resource *cr;
> > -
> > +   keyboard = seat->keyboard_state;
> > if (!keyboard)
> > return;
> >  
> > @@ -2579,6 +2587,12 @@ seat_get_touch(struct wl_client *client, struct 
> > wl_resource *resource,
> >uint32_t id)
> >  {
> > struct weston_seat *seat = wl_resource_get_user_data(resource);
> > +   struct weston_touch *touch;
> > +   struct wl_resource *cr;
> > +
> > +   if (!seat)
> > +   return;
> > +
> > /* We use the touch_state directly, which means we'll
> >  * give a wl_touch if the seat has ever had one - even though
> >  * the spec explicitly states that this request only takes effect
> > @@ -2587,9 +2601,7 @@ seat_get_touch(struct wl_client *client, struct 
> > wl_resource *resource,
> >  * This prevents a race between the compositor sending new
> >  * capabilities and the client trying to use the old ones.
> >  */
> > -   struct weston_touch *touch = seat->touch_state;
> > -   struct wl_resource *cr;
> > -
> > +   touch = seat->touch_state;
> > if (!touch)
> > return;
> 
> Hi,

Hi Pekka,

thanks for the review.

> all the seat_get_*() changes have the same problem that they skip
> calling wl_resource_create() which will lead to protocol state
> mismatch. These functions need to create inert wl_resources, but
> thankfully the earlier patches already take care of handling them
> further.

I was misunderstanding how this worked. I will update these to properly
create (inert) resources in v2.

> > @@ -3

Re: [PATCH weston 5/8] tests: Support setting the test client input dynamically

2018-01-31 Thread Alexandros Frantzis
On Wed, Jan 31, 2018 at 04:25:15PM +0200, Pekka Paalanen wrote:
> On Fri, 26 Jan 2018 18:47:59 +0200
> Alexandros Frantzis  wrote:
> 
> > The current test client code waits for all wl_seat globals to arrive
> > before checking them and deciding which one is the test seat global to
> > use for the input object. This method doesn't support dynamic addition
> > of the test seat global (i.e., after client start-up), which will be
> > needed in upcoming commits.
> > 
> > This commit changes the code to check for the test seat and set up the
> > input object while handling the wl_seat information events.
> > 
> > Signed-off-by: Alexandros Frantzis 
> > ---
> >  tests/weston-test-client-helper.c | 78 
> > ++-
> >  tests/weston-test-client-helper.h |  1 +
> >  2 files changed, 46 insertions(+), 33 deletions(-)
> 
> Hi Alexandros,

Hi Pekka,

thanks for the review.

> essentially patches 5-7 want to support dynamically creating and
> removing wl_seats. The current test protocol is poorly suited for it as
> it assumes the single test-seat in all requests. I would like to have a
> protocol that better matches the structure of input devices and seats
> and how weston core consumes input. However, that's a big task and it
> would be outrageous to ask for that right here, so I think your
> intention here is fine.
> 
> I presume the idea is that device_add("seat") and
> device_release("seat") will create and destroy the test-seat,
> respectively, regardless of the current capabilities.

Correct. Patches 5-7 prepare the test infrastructure so we can
add a test that removes and re-adds the test seat (patch 8).

> > 
> > diff --git a/tests/weston-test-client-helper.c 
> > b/tests/weston-test-client-helper.c
> > index 6e0a5246..854978d0 100644
> > --- a/tests/weston-test-client-helper.c
> > +++ b/tests/weston-test-client-helper.c
> 
> > @@ -862,9 +877,6 @@ create_client(void)
> >  * events */
> > client_roundtrip(client);
> >  
> > -   /* find the right input for us */
> > -   client_set_input(client);
> > -
> 
> The original idea here was that the two roundtrips above guarantee that
> we have processed all global advertisements and all wl_seat name and
> capapbility events. Then we can ensure that Weston indeed provided
> exactly one test-seat, and that all seats had a name provided.
> 
> I don't think that's in any way contradictory to allowing the test-seat
> then to be removed and re-added, so I'm not quite sure why this patch
> is needed or what it even does?

The client_set_input() call (and function) is removed because the same
functionality is now implemented when we handle information events about
seats. The two roundtrips are still required for the reasons you
mention above.

As an example exhibiting the reason for this change, assume that the
server has removed the seat, in which case the client->input object has
been freed (see patch 7). A test that wants to re-add the test seat will
call (copied from patch 8):

  weston_test_device_add(cl->test->weston_test, "seat");
  /* First roundtrip to send request and receive new seat global */
  client_roundtrip(cl);
  /* Second roundtrip to handle seat events and set up input devices */
  client_roundtrip(cl);

Without this patch, the test would also need to call client_set_input()
in order for the seat addition to take effect (populate client->input
etc). However, this is an extra internal implementation detail of the
test infrastructure which I would prefer not to reveal to tests. This
patch automatically updates the client->input as seats come and go, so
the code above just works. Similarly for when we remove the test seat.

So, to sum up, it's not that client_set_input couldn't be used in this
case, we could make it public and call it in the tests, but I think the
proposed approach provides a more intuitive interface for writing tests
(for our current needs, at least).

Thanks,
Alexandros
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


Re: [PATCH weston 5/8] tests: Support setting the test client input dynamically

2018-02-01 Thread Alexandros Frantzis
On Thu, Feb 01, 2018 at 12:00:44PM +0200, Pekka Paalanen wrote:
> On Wed, 31 Jan 2018 17:14:49 +0200
> Alexandros Frantzis  wrote:
> 
> > On Wed, Jan 31, 2018 at 04:25:15PM +0200, Pekka Paalanen wrote:
> > > On Fri, 26 Jan 2018 18:47:59 +0200
> > > Alexandros Frantzis  wrote:
> > >   
> > > > The current test client code waits for all wl_seat globals to arrive
> > > > before checking them and deciding which one is the test seat global to
> > > > use for the input object. This method doesn't support dynamic addition
> > > > of the test seat global (i.e., after client start-up), which will be
> > > > needed in upcoming commits.
> > > > 
> > > > This commit changes the code to check for the test seat and set up the
> > > > input object while handling the wl_seat information events.
> > > > 
> > > > Signed-off-by: Alexandros Frantzis 
> > > > ---
> > > >  tests/weston-test-client-helper.c | 78 
> > > > ++-
> > > >  tests/weston-test-client-helper.h |  1 +
> > > >  2 files changed, 46 insertions(+), 33 deletions(-)  
> > > 
> > > Hi Alexandros,  
> > 
> > Hi Pekka,
> > 
> > thanks for the review.
> > 
> > > essentially patches 5-7 want to support dynamically creating and
> > > removing wl_seats. The current test protocol is poorly suited for it as
> > > it assumes the single test-seat in all requests. I would like to have a
> > > protocol that better matches the structure of input devices and seats
> > > and how weston core consumes input. However, that's a big task and it
> > > would be outrageous to ask for that right here, so I think your
> > > intention here is fine.
> > > 
> > > I presume the idea is that device_add("seat") and
> > > device_release("seat") will create and destroy the test-seat,
> > > respectively, regardless of the current capabilities.  
> > 
> > Correct. Patches 5-7 prepare the test infrastructure so we can
> > add a test that removes and re-adds the test seat (patch 8).
> > 
> > > > 
> > > > diff --git a/tests/weston-test-client-helper.c 
> > > > b/tests/weston-test-client-helper.c
> > > > index 6e0a5246..854978d0 100644
> > > > --- a/tests/weston-test-client-helper.c
> > > > +++ b/tests/weston-test-client-helper.c  
> > >   
> > > > @@ -862,9 +877,6 @@ create_client(void)
> > > >  * events */
> > > > client_roundtrip(client);
> > > >  
> > > > -   /* find the right input for us */
> > > > -   client_set_input(client);
> > > > -  
> > > 
> > > The original idea here was that the two roundtrips above guarantee that
> > > we have processed all global advertisements and all wl_seat name and
> > > capapbility events. Then we can ensure that Weston indeed provided
> > > exactly one test-seat, and that all seats had a name provided.
> > > 
> > > I don't think that's in any way contradictory to allowing the test-seat
> > > then to be removed and re-added, so I'm not quite sure why this patch
> > > is needed or what it even does?  
> > 
> > The client_set_input() call (and function) is removed because the same
> > functionality is now implemented when we handle information events about
> > seats. The two roundtrips are still required for the reasons you
> > mention above.
> 
> You seemed to have removed the check for "each seat has a name". I also
> had trouble following the code flow.

The "each seat has a name" part was indeed removed, since it doesn't
work with this method and it seemed to be a secondary concern. I focused
on the primary function which is "find the test seat and use it for the
input object".

My proposal would be to reintroduce this check by means of a new
explicit test, instead of implicitly testing it in the test
infrastructure. I think this would be good to do regardless of this
proposal. How does this sound?

> > As an example exhibiting the reason for this change, assume that the
> > server has removed the seat, in which case the client->input object has
> > been freed (see patch 7). A test that wants to re-add the test seat will
> > call (copied from patch 8):
> > 
> >   weston_test_device_add(cl->test->weston_test, "seat");
> >   /* First roundtrip to send request and receive new seat global */
> &g

Re: [PATCH weston 8/8] tests: Add test for seat destruction and creation

2018-02-01 Thread Alexandros Frantzis
On Thu, Feb 01, 2018 at 12:46:13PM +0200, Pekka Paalanen wrote:
> On Fri, 26 Jan 2018 18:48:02 +0200
> Alexandros Frantzis  wrote:
> 
> > Add a test to check that we can destroy and create the test seat. Since
> > after test seat destruction the test client releases any associated
> > input resources, this test also checks that libweston properly handles
> > release requests for inert input resources.
> > 
> > The test is placed in its own file for the time being, so it can run
> > independently. This is needed because the desktop shell, which is used
> > when running tests, doesn't deal well with seat destruction and creation
> > at the moment and may causes crashes in other tests. When this is fixed
> > we can merge this test into devices-test.c.
> > 
> > Signed-off-by: Alexandros Frantzis 
> > ---
> >  Makefile.am   |  5 +
> >  tests/devices-seat-test.c | 53 
> > +++
> >  2 files changed, 58 insertions(+)
> >  create mode 100644 tests/devices-seat-test.c
> > 
> > diff --git a/Makefile.am b/Makefile.am
> > index e224d606..f0370973 100644
> > --- a/Makefile.am
> > +++ b/Makefile.am
> > @@ -1234,6 +1234,7 @@ weston_tests =
> > \
> > subsurface.weston   \
> > subsurface-shot.weston  \
> > devices.weston  \
> > +   devices-seat.weston \
> > touch.weston
> >  
> >  ivi_tests =
> > @@ -1392,6 +1393,10 @@ devices_weston_SOURCES = tests/devices-test.c
> >  devices_weston_CFLAGS = $(AM_CFLAGS) $(TEST_CLIENT_CFLAGS)
> >  devices_weston_LDADD = libtest-client.la
> >  
> > +devices_seat_weston_SOURCES = tests/devices-seat-test.c
> > +devices_seat_weston_CFLAGS = $(AM_CFLAGS) $(TEST_CLIENT_CFLAGS)
> > +devices_seat_weston_LDADD = libtest-client.la
> > +
> >  text_weston_SOURCES = tests/text-test.c
> >  nodist_text_weston_SOURCES =   \
> > protocol/text-input-unstable-v1-protocol.c  \
> > diff --git a/tests/devices-seat-test.c b/tests/devices-seat-test.c
> > new file mode 100644
> > index ..182df1d5
> > --- /dev/null
> > +++ b/tests/devices-seat-test.c
> > @@ -0,0 +1,53 @@
> > +/*
> > + * Copyright © 2018 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 "weston-test-client-helper.h"
> > +
> > +/**
> > + * Test destroying/recreating seats
> > + *
> > + * The seat destroy/recreate test is placed in its own file for the time
> > + * being, so it can run independently. This is needed because the desktop
> > + * shell, which is used when running tests, doesn't deal well with seat
> > + * destruction and recreation at the moment and may causes crashes in other
> > + * tests. When this is fixed we can merge this test into devices-test.c.
> > + */
> 
> Hi,
> 
> this is suspicious. It could cause random crashes just in this test as
> well, could it not?

In practice I have found that this causes problems only in subsequent
tests when using the same server (i.e., tests in the same test file) and
only with desktop-shell, but you are correct that since we don't know
the exact caus

Re: [PATCH weston 5/8] tests: Support setting the test client input dynamically

2018-02-01 Thread Alexandros Frantzis
On Thu, Feb 01, 2018 at 12:20:44PM +0200, Pekka Paalanen wrote:
> On Fri, 26 Jan 2018 18:47:59 +0200
> Alexandros Frantzis  wrote:
> 
> > The current test client code waits for all wl_seat globals to arrive
> > before checking them and deciding which one is the test seat global to
> > use for the input object. This method doesn't support dynamic addition
> > of the test seat global (i.e., after client start-up), which will be
> > needed in upcoming commits.
> > 
> > This commit changes the code to check for the test seat and set up the
> > input object while handling the wl_seat information events.
> > 
> > Signed-off-by: Alexandros Frantzis 
> > ---
> >  tests/weston-test-client-helper.c | 78 
> > ++-
> >  tests/weston-test-client-helper.h |  1 +
> >  2 files changed, 46 insertions(+), 33 deletions(-)
> 
> Hi,
> 
> I feel this patch might be doing more than what it says on the tin:
> - move input_update_devices() call from client_set_input() into the
>   event handlers
> - remove the check for all seats must have a name
> 
> I suppose justifying these in the commit message would be enough in
> this case.
> 


Hi Pekka,

I have been thinking a bit more about the direction that we might want
this code to move toward.

One thought was to provide struct input objects for all seats (perhaps
also rename struct input -> struct seat), and provide a
client_get_seat_with_name(name) helper function, or even
client_get_test_seat() for extra convenience. I think this would keep
the code relatively simple and also general enough for future use (e.g.
test multiple seats).

What do you think?

Thanks,
Alexandros

> > diff --git a/tests/weston-test-client-helper.c 
> > b/tests/weston-test-client-helper.c
> > index 6e0a5246..854978d0 100644
> > --- a/tests/weston-test-client-helper.c
> > +++ b/tests/weston-test-client-helper.c
> > @@ -538,6 +538,14 @@ static const struct weston_test_listener test_listener 
> > = {
> > test_handle_capture_screenshot_done,
> >  };
> >  
> > +static void
> > +input_destroy(struct input *inp)
> > +{
> > +   wl_list_remove(&inp->link);
> > +   wl_seat_destroy(inp->wl_seat);
> > +   free(inp);
> > +}
> > +
> >  static void
> >  input_update_devices(struct input *input)
> >  {
> > @@ -598,22 +606,56 @@ seat_handle_capabilities(void *data, struct wl_seat 
> > *seat,
> >  
> > /* we will create/update the devices only with the right (test) seat.
> >  * If we haven't discovered which seat is the test seat, just
> > -* store capabilities and bail out */
> > -   if (input->seat_name && strcmp(input->seat_name, "test-seat") == 0)
> > +* store capabilities and bail out. Note that we don't need to
> > +* check the name contents here, since only the test seat input will
> > +* have its name set */
> > +   if (input->seat_name) {
> > input_update_devices(input);
> 
> In fact, this bit of old code was not actually necessary, because
> client_set_input() would have done the right thing anyway. Your patch
> fixes this "imbalance" by making both event handlers call
> input_update_devices().
> 
> > +   input->client->input = input;
> > +   }
> > +
> >  
> > fprintf(stderr, "test-client: got seat %p capabilities: %x\n",
> > input, caps);
> >  }
> >  
> > +static struct input *
> > +client_find_input_with_seat_name(struct client *client, const char *name)
> > +{
> 
> This function seems unnecessary, because...
> 
> > +   struct input *input;
> > +
> > +   wl_list_for_each(input, &client->inputs, link) {
> > +   if (input->seat_name && strcmp(input->seat_name, name) == 0)
> > +   return input;
> > +   }
> > +
> > +   return NULL;
> > +}
> > +
> >  static void
> >  seat_handle_name(void *data, struct wl_seat *seat, const char *name)
> >  {
> > struct input *input = data;
> >  
> > +   /* We don't care about seats other than the test seat */
> > +   if (strcmp(name, "test-seat") != 0) {
> > +   input_destroy(input);
> > +   return;
> > +   }
> > +
> > +   assert(!client_find_input_with_seat_name(input->client, name) &&
> > +  "Multiple test seats detected!");
> 
> ..this test could as well be done...
> 
> > +
> > input->seat_name = strdup(name

Re: [PATCH weston 5/8] tests: Support setting the test client input dynamically

2018-02-01 Thread Alexandros Frantzis
On Thu, Feb 01, 2018 at 02:09:32PM +0200, Pekka Paalanen wrote:
> On Thu, 1 Feb 2018 13:30:25 +0200
> Alexandros Frantzis  wrote:
> 
> > On Thu, Feb 01, 2018 at 12:20:44PM +0200, Pekka Paalanen wrote:
> > > On Fri, 26 Jan 2018 18:47:59 +0200
> > > Alexandros Frantzis  wrote:
> > >   
> > > > The current test client code waits for all wl_seat globals to arrive
> > > > before checking them and deciding which one is the test seat global to
> > > > use for the input object. This method doesn't support dynamic addition
> > > > of the test seat global (i.e., after client start-up), which will be
> > > > needed in upcoming commits.
> > > > 
> > > > This commit changes the code to check for the test seat and set up the
> > > > input object while handling the wl_seat information events.
> > > > 
> > > > Signed-off-by: Alexandros Frantzis 
> > > > ---
> > > >  tests/weston-test-client-helper.c | 78 
> > > > ++-
> > > >  tests/weston-test-client-helper.h |  1 +
> > > >  2 files changed, 46 insertions(+), 33 deletions(-)  
> > > 
> > > Hi,
> > > 
> > > I feel this patch might be doing more than what it says on the tin:
> > > - move input_update_devices() call from client_set_input() into the
> > >   event handlers
> > > - remove the check for all seats must have a name
> > > 
> > > I suppose justifying these in the commit message would be enough in
> > > this case.
> > >   
> > 
> > 
> > Hi Pekka,
> > 
> > I have been thinking a bit more about the direction that we might want
> > this code to move toward.
> > 
> > One thought was to provide struct input objects for all seats (perhaps
> > also rename struct input -> struct seat), and provide a
> > client_get_seat_with_name(name) helper function, or even
> > client_get_test_seat() for extra convenience. I think this would keep
> > the code relatively simple and also general enough for future use (e.g.
> > test multiple seats).
> > 
> > What do you think?
> 
> Hi,
> 
> I think a good general guideline is to not implement any infrastructure
> that is not going to get used very soon. In that sense going for the
> smallest modification is a good plan. Keeping that in mind, it is of
> course nice to clean up and streamline the existing infrastructure.
> 
> Anticipating future needs is good, but it should not go too far to
> possibly end up unsuitable and wasted work.

I agree about not doing unecessary work ("YAGNI"), but this is
functionality that could be immediately useful. For example the explicit
test to check that all seats have a name could be written very easily if
we exposed all seats.

This change would also simplify the logic of handling seat
addition/removal, since we wouldn't need the dynamic
creation/destruction of input objects inside the seat information event
handlers.

> We could create input objects for all seats, but I'd be more wary of
> creating the wl_pointer/wl_keyboard/wl_touch objects for non-test
> seats. So far non-test seats are never useful in tests and unexpected
> input events could even cause confusion.

Each input event should only affect the relevant input object (and
sub-objects), so I don't expect any interference with the tests if they
are properly written, but perhaps I am missing some interaction. Plus,
as you say, we could actually skip creating the pointer/keyboard/touch
sub-objects for non-test seats.

Having said all the above, mostly to present a more complete argument
for this idea, I am fine continuing with a minimal change approach at
this time. We can consider alternative approaches in the future as we
get more need for them.

Thanks,
Alexandros
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH weston v2 6/7] tests: Run devices tests using the test desktop shell

2018-02-08 Thread Alexandros Frantzis
Use the weston-test-desktop-shell to run the devices tests, instead of
the currently used desktop-shell. The test desktop shell doesn't
interact with temporary globals (e.g. wl_seat), thus avoiding an
inherent race in the current wayland protocol when removing globals.
This will allow us to safely add tests which add/remove such globals in
upcoming commits.

Signed-off-by: Alexandros Frantzis 
---
Changes in v2:
 - New in v2.

 tests/devices-test.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tests/devices-test.c b/tests/devices-test.c
index ce1cea3b..a6ec6eaf 100644
--- a/tests/devices-test.c
+++ b/tests/devices-test.c
@@ -40,6 +40,8 @@
WL_SEAT_CAPABILITY_POINTER  |\
WL_SEAT_CAPABILITY_TOUCH)
 
+char *server_parameters = "--shell=weston-test-desktop-shell.so";
+
 /* simply test if weston sends the right capabilities when
  * some devices are removed */
 TEST(seat_capabilities_test)
-- 
2.14.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH weston v2 3/7] libweston: Make weston_seat release safe

2018-02-08 Thread Alexandros Frantzis
Ensure the server can safely handle client requests for wl_seat resource
that have become inert due to weston_seat object release and subsequent
destruction.

The clean-up involves, among other things, unsetting the destroyed
weston_seat object from the user data of wl_seat resources, and handling
this NULL user data case where required.

The list of sites extracting and using weston_seat object from wl_seat
resources which were audited for this patch are:

Legend:
N/A = Not Applicable (not implemented by weston)
FIXED = Fixed in the commit
OK = Already works correctly

== keyboard_shortcuts_inhibit_unstable_v1 ==
[N/A] zwp_keyboard_shortcuts_inhibit_manager_v1.inhibit_shortcuts
== tablet_input_unstable_v{1,2} ==
[N/A] zwp_tablet_manager_v{1,2}.get_tablet_seat
== text_input_unstable_v1 ==
[FIXED] zwp_text_input_v1.activate
[FIXED] zwp_text_input_v1.deactivate
== wl_data_device ==
[FIXED] wl_data_device_manager.get_data_device
[OK] wl_data_device.start_drag
[FIXED] wl_data_device.set_selection
[OK] wl_data_device.release
== wl_shell ==
[FIXED] wl_shell_surface.move
[FIXED] wl_shell_surface.resize
[FIXED] wl_shell_surface.set_popup
== xdg_shell and xdg_shell_unstable_v6 ==
[FIXED] xdg_toplevel.show_window_menu
[FIXED] xdg_toplevel.move
[FIXED] xdg_toplevel.resize
[FIXED] xdg_popup.grab
== xdg_shell_unstable_v5 ==
[FIXED] xdg_shell.get_xdg_popup
[FIXED] xdg_surface.show_window_menu
[FIXED] xdg_surface.move
[FIXED] xdg_surface.resize

Signed-off-by: Alexandros Frantzis 
---
Changes in v2:
 - Properly create inert resources in seat_get_pointer/touch/keyboard.
 - Ensure all sites which have a wl_seat input resource can deal
   with inert resources.

 compositor/text-backend.c|  8 --
 libweston-desktop/wl-shell.c | 12 +++-
 libweston-desktop/xdg-shell-v5.c | 16 ++-
 libweston-desktop/xdg-shell-v6.c | 18 +++-
 libweston/data-device.c  | 15 ++
 libweston/input.c| 61 
 6 files changed, 102 insertions(+), 28 deletions(-)

diff --git a/compositor/text-backend.c b/compositor/text-backend.c
index e6ee249c..4d8c085b 100644
--- a/compositor/text-backend.c
+++ b/compositor/text-backend.c
@@ -193,10 +193,14 @@ text_input_activate(struct wl_client *client,
 {
struct text_input *text_input = wl_resource_get_user_data(resource);
struct weston_seat *weston_seat = wl_resource_get_user_data(seat);
-   struct input_method *input_method = weston_seat->input_method;
+   struct input_method *input_method;
struct weston_compositor *ec = text_input->ec;
struct text_input *current;
 
+   if (!weston_seat)
+   return;
+
+   input_method = weston_seat->input_method;
if (input_method->input == text_input)
return;
 
@@ -237,7 +241,7 @@ text_input_deactivate(struct wl_client *client,
 {
struct weston_seat *weston_seat = wl_resource_get_user_data(seat);
 
-   if (weston_seat->input_method->input)
+   if (weston_seat && weston_seat->input_method->input)
deactivate_input_method(weston_seat->input_method);
 }
 
diff --git a/libweston-desktop/wl-shell.c b/libweston-desktop/wl-shell.c
index 66553f45..3386d48b 100644
--- a/libweston-desktop/wl-shell.c
+++ b/libweston-desktop/wl-shell.c
@@ -220,6 +220,9 @@ weston_desktop_wl_shell_surface_protocol_move(struct 
wl_client *wl_client,
struct weston_desktop_wl_shell_surface *surface =
weston_desktop_surface_get_implementation_data(dsurface);
 
+   if (seat == NULL)
+   return;
+
weston_desktop_api_move(surface->desktop, dsurface, seat, serial);
 }
 
@@ -238,6 +241,9 @@ weston_desktop_wl_shell_surface_protocol_resize(struct 
wl_client *wl_client,
enum weston_desktop_surface_edge surf_edges =
(enum weston_desktop_surface_edge) edges;
 
+   if (seat == NULL)
+   return;
+
weston_desktop_api_resize(surface->desktop, dsurface, seat, serial, 
surf_edges);
 }
 
@@ -321,13 +327,17 @@ weston_desktop_wl_shell_surface_protocol_set_popup(struct 
wl_client *wl_client,
struct weston_desktop_surface *dsurface =
wl_resource_get_user_data(resource);
struct weston_seat *wseat = wl_resource_get_user_data(seat_resource);
-   struct weston_desktop_seat *seat = weston_desktop_seat_from_seat(wseat);
+   struct weston_desktop_seat *seat;
struct weston_surface *parent =
wl_resource_get_user_data(parent_resource);
struct weston_desktop_surface *parent_surface;
struct weston_desktop_wl_shell_surface *surface =
weston_desktop_surface_get_implementation_data(dsurface);
 
+   if (wseat == NULL)
+   return;
+
+   seat = weston_desktop_seat_from_seat(wseat);
if (seat == NULL) {
wl_client_post_no_memory(wl_client);
return;
diff

[PATCH weston v2 0/7] libweston: Make input object destruction safe

2018-02-08 Thread Alexandros Frantzis
When a weston seat or input object is destroyed, any associated client
resources should become inert and put in a state in which they can
safely handle client requests. Currently, client requests to such
resources may lead to crashes and/or memory errors in the server.

This patchset aims to fix (or at least greatly improve) the situation.

Patches (1) to (3) ensure that when the various input objects are
destroyed, any associated resources are made inert and can safely handle
client requests.

Patches (4) to (6) update the test infrastructure to properly support
requests to dynamically add and remove the test seat.

Patch (7) introduces a test for removing and re-adding the test seat.
This test indirectly checks some of the input code fixes made in patches
(1) to (3).  Even without some of the fixes, the test may seem to pass.
However, running with a memory debugger reveals a different story, since
without the fixes we encounter various memory errors.

Since the v1 proposal, I have been able to investigate the issues
triggered by the new test. The conclusion is that the problem was caused
by the desktop shell due to an inherent race in the way wayland deals
with removal of globals. In particular, if a global is removed while a
client has in-flight requests for it, the server will reply with a
protocol error and kill the client. To work around this, v2 changes the
devices tests to use the test desktop shell which doesn't deal with
wl_seat globals and is thus not affected by this race.

More detailed changes introduced in v2 are provided in each patch.

Alexandros Frantzis (7):
  libweston: Support NULL weston_pointer in init_pointer_constraint
  libweston: Make weston_pointer destruction safe
  libweston: Make weston_seat release safe
  tests: Handle removal of seat global in test clients
  tests: Support setting the test client input dynamically
  tests: Run devices tests using the test desktop shell
  tests: Add test for seat destruction and creation

 compositor/text-backend.c |   8 ++-
 libweston-desktop/wl-shell.c  |  12 +++-
 libweston-desktop/xdg-shell-v5.c  |  16 +-
 libweston-desktop/xdg-shell-v6.c  |  18 +-
 libweston/data-device.c   |  15 +++--
 libweston/input.c | 117 --
 libweston/zoom.c  |   5 +-
 tests/devices-test.c  |  34 +++
 tests/weston-test-client-helper.c | 116 ++---
 tests/weston-test-client-helper.h |   2 +
 10 files changed, 269 insertions(+), 74 deletions(-)

-- 
2.14.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH weston v2 1/7] libweston: Support NULL weston_pointer in init_pointer_constraint

2018-02-08 Thread Alexandros Frantzis
Fix init_pointer_constraint so that it creates a valid, but inert,
resource if a NULL weston_pointer value is passed in. In that case no
constraint object is associated with the resource, but this is not an
issue since affected code can already handle NULL constraint objects.

Signed-off-by: Alexandros Frantzis 
---
Changes in v2:
 - New patch

 libweston/input.c | 21 +
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/libweston/input.c b/libweston/input.c
index 96cded47..390698c7 100644
--- a/libweston/input.c
+++ b/libweston/input.c
@@ -3572,7 +3572,7 @@ init_pointer_constraint(struct wl_resource 
*pointer_constraints_resource,
struct wl_resource *cr;
struct weston_pointer_constraint *constraint;
 
-   if (get_pointer_constraint_for_pointer(surface, pointer)) {
+   if (pointer && get_pointer_constraint_for_pointer(surface, pointer)) {
wl_resource_post_error(pointer_constraints_resource,
   
ZWP_POINTER_CONSTRAINTS_V1_ERROR_ALREADY_CONSTRAINED,
   "the pointer has a lock/confine request 
on this surface");
@@ -3587,18 +3587,23 @@ init_pointer_constraint(struct wl_resource 
*pointer_constraints_resource,
return;
}
 
-   constraint = weston_pointer_constraint_create(surface, pointer,
- region, lifetime,
- cr, grab_interface);
-   if (constraint == NULL) {
-   wl_client_post_no_memory(client);
-   return;
+   if (pointer) {
+   constraint = weston_pointer_constraint_create(surface, pointer,
+ region, lifetime,
+ cr, 
grab_interface);
+   if (constraint == NULL) {
+   wl_client_post_no_memory(client);
+   return;
+   }
+   } else {
+   constraint = NULL;
}
 
wl_resource_set_implementation(cr, implementation, constraint,
   
pointer_constraint_constrain_resource_destroyed);
 
-   maybe_enable_pointer_constraint(constraint);
+   if (constraint)
+   maybe_enable_pointer_constraint(constraint);
 }
 
 static void
-- 
2.14.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH weston v2 5/7] tests: Support setting the test client input dynamically

2018-02-08 Thread Alexandros Frantzis
The current test client code waits for all wl_seat globals to arrive
before checking them and deciding which one is the test seat global to
use for the input object. Test code that needs to add/remove test seats
would have to call the client_set_input() function for any seat changes
to take effect. Although we could allow this by making
client_set_input() public, we would be exposing unecessary
implementation details.

This commit applies any seat changes immediately upon arrival of the
seat name, freeing test code from needing to call extra functions like
client_set_input(). To achieve this the call to input_data_devices() is
moved from client_set_input() to the seat name event handler.

This commit also moves the check that all seats have names to an
explicit test. To support this test, inputs corresponding to non-test
seats are not destroyed (unless their seat global is removed), as
was previously the case.

Signed-off-by: Alexandros Frantzis 
---
Changes in v2:
 - Add explicit test for seat names.
 - Don't destroy input objects for non-test seats unconditionally.
 - Simplify devices handling in seat name handler.

 tests/devices-test.c  | 10 ++
 tests/weston-test-client-helper.c | 33 ++---
 tests/weston-test-client-helper.h |  1 +
 3 files changed, 21 insertions(+), 23 deletions(-)

diff --git a/tests/devices-test.c b/tests/devices-test.c
index 450713e7..ce1cea3b 100644
--- a/tests/devices-test.c
+++ b/tests/devices-test.c
@@ -310,3 +310,13 @@ TEST(get_device_after_destroy_multiple)
get_device_after_destroy();
}
 }
+
+TEST(seats_have_names)
+{
+   struct client *cl = create_client_and_test_surface(100, 100, 100, 100);
+   struct input *input;
+
+   wl_list_for_each(input, &cl->inputs, link) {
+   assert(input->seat_name);
+   }
+}
diff --git a/tests/weston-test-client-helper.c 
b/tests/weston-test-client-helper.c
index 5ee032ca..dc69e151 100644
--- a/tests/weston-test-client-helper.c
+++ b/tests/weston-test-client-helper.c
@@ -635,6 +635,15 @@ seat_handle_name(void *data, struct wl_seat *seat, const 
char *name)
input->seat_name = strdup(name);
assert(input->seat_name && "No memory");
 
+   /* We only update the devices and set client input for the test seat */
+   if (strcmp(name, "test-seat") == 0) {
+   assert(!input->client->input &&
+  "Multiple test seats detected!");
+
+   input_update_devices(input);
+   input->client->input = input;
+   }
+
fprintf(stderr, "test-client: got seat %p name: \'%s\'\n",
input, name);
 }
@@ -726,6 +735,7 @@ handle_global(void *data, struct wl_registry *registry,
 &wl_compositor_interface, version);
} else if (strcmp(interface, "wl_seat") == 0) {
input = xzalloc(sizeof *input);
+   input->client = client;
input->global_name = global->name;
input->wl_seat =
wl_registry_bind(registry, id,
@@ -882,26 +892,6 @@ log_handler(const char *fmt, va_list args)
vfprintf(stderr, fmt, args);
 }
 
-/* find the test-seat and set it in client.
- * Destroy other inputs */
-static void
-client_set_input(struct client *cl)
-{
-   struct input *inp, *inptmp;
-   wl_list_for_each_safe(inp, inptmp, &cl->inputs, link) {
-   assert(inp->seat_name && "BUG: input with no name");
-   if (strcmp(inp->seat_name, "test-seat") == 0) {
-   cl->input = inp;
-   input_update_devices(inp);
-   } else {
-   input_destroy(inp);
-   }
-   }
-
-   /* we keep only one input */
-   assert(wl_list_length(&cl->inputs) == 1);
-}
-
 struct client *
 create_client(void)
 {
@@ -927,9 +917,6 @@ create_client(void)
 * events */
client_roundtrip(client);
 
-   /* find the right input for us */
-   client_set_input(client);
-
/* must have WL_SHM_FORMAT_ARGB32 */
assert(client->has_argb);
 
diff --git a/tests/weston-test-client-helper.h 
b/tests/weston-test-client-helper.h
index fb31125c..255bbf66 100644
--- a/tests/weston-test-client-helper.h
+++ b/tests/weston-test-client-helper.h
@@ -74,6 +74,7 @@ struct test {
 };
 
 struct input {
+   struct client *client;
uint32_t global_name;
struct wl_seat *wl_seat;
struct pointer *pointer;
-- 
2.14.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH weston v2 4/7] tests: Handle removal of seat global in test clients

2018-02-08 Thread Alexandros Frantzis
The current test client code completely ignores removal of globals.
This commit updates the code to properly handle removal of globals in
general, and of seat globals in particular. This ensures that the test
client objects are in sync with the server and any relevant resources
are released accordingly.

This update will be used by upcoming tests to check that seat removal
and re-addition is working properly.

Signed-off-by: Alexandros Frantzis 
---
Changes in v2:
 - Simplify input_destroy, no need to check for validity of wl_* objects.

 tests/weston-test-client-helper.c | 83 ++-
 tests/weston-test-client-helper.h |  1 +
 2 files changed, 75 insertions(+), 9 deletions(-)

diff --git a/tests/weston-test-client-helper.c 
b/tests/weston-test-client-helper.c
index 6e0a5246..5ee032ca 100644
--- a/tests/weston-test-client-helper.c
+++ b/tests/weston-test-client-helper.c
@@ -538,6 +538,27 @@ static const struct weston_test_listener test_listener = {
test_handle_capture_screenshot_done,
 };
 
+static void
+input_destroy(struct input *inp)
+{
+   if (inp->pointer) {
+   wl_pointer_release(inp->pointer->wl_pointer);
+   free(inp->pointer);
+   }
+   if (inp->keyboard) {
+   wl_keyboard_release(inp->keyboard->wl_keyboard);
+   free(inp->keyboard);
+   }
+   if (inp->touch) {
+   wl_touch_release(inp->touch->wl_touch);
+   free(inp->touch);
+   }
+   wl_list_remove(&inp->link);
+   wl_seat_release(inp->wl_seat);
+   free(inp->seat_name);
+   free(inp);
+}
+
 static void
 input_update_devices(struct input *input)
 {
@@ -705,6 +726,7 @@ handle_global(void *data, struct wl_registry *registry,
 &wl_compositor_interface, version);
} else if (strcmp(interface, "wl_seat") == 0) {
input = xzalloc(sizeof *input);
+   input->global_name = global->name;
input->wl_seat =
wl_registry_bind(registry, id,
 &wl_seat_interface, version);
@@ -735,8 +757,59 @@ handle_global(void *data, struct wl_registry *registry,
}
 }
 
+static struct global *
+client_find_global_with_name(struct client *client, uint32_t name)
+{
+   struct global *global;
+
+   wl_list_for_each(global, &client->global_list, link) {
+   if (global->name == name)
+   return global;
+   }
+
+   return NULL;
+}
+
+static struct input *
+client_find_input_with_name(struct client *client, uint32_t name)
+{
+   struct input *input;
+
+   wl_list_for_each(input, &client->inputs, link) {
+   if (input->global_name == name)
+   return input;
+   }
+
+   return NULL;
+}
+
+static void
+handle_global_remove(void *data, struct wl_registry *registry, uint32_t name)
+{
+   struct client *client = data;
+   struct global *global;
+   struct input *input;
+
+   global = client_find_global_with_name(client, name);
+   assert(global && "Request to remove unknown global");
+
+   if (strcmp(global->interface, "wl_seat") == 0) {
+   input = client_find_input_with_name(client, name);
+   if (input) {
+   if (client->input == input)
+   client->input = NULL;
+   input_destroy(input);
+   }
+   }
+
+   wl_list_remove(&global->link);
+   free(global->interface);
+   free(global);
+}
+
 static const struct wl_registry_listener registry_listener = {
-   handle_global
+   handle_global,
+   handle_global_remove,
 };
 
 void
@@ -809,14 +882,6 @@ log_handler(const char *fmt, va_list args)
vfprintf(stderr, fmt, args);
 }
 
-static void
-input_destroy(struct input *inp)
-{
-   wl_list_remove(&inp->link);
-   wl_seat_destroy(inp->wl_seat);
-   free(inp);
-}
-
 /* find the test-seat and set it in client.
  * Destroy other inputs */
 static void
diff --git a/tests/weston-test-client-helper.h 
b/tests/weston-test-client-helper.h
index 09a5df4a..fb31125c 100644
--- a/tests/weston-test-client-helper.h
+++ b/tests/weston-test-client-helper.h
@@ -74,6 +74,7 @@ struct test {
 };
 
 struct input {
+   uint32_t global_name;
struct wl_seat *wl_seat;
struct pointer *pointer;
struct keyboard *keyboard;
-- 
2.14.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH weston v2 2/7] libweston: Make weston_pointer destruction safe

2018-02-08 Thread Alexandros Frantzis
Properly clean up all sub-objects (e.g., weston_pointer_client objects)
when a weston_pointer object is destroyed. The clean-up ensures that the
server is able to safely handle client requests to any associated
pointer resources, which, as a consenquence of a weston_pointer
destruction, have now become inert.

The clean-up involves, among other things, unsetting the destroyed
weston_pointer object from the user data of pointer resources, and
handling this NULL user data case where required. Note that in many
sites affected by this change the existing code already properly handles
NULL weston_pointer (e.g. in init_pointer_constraint), so there is no
need for additional updates there.

Signed-off-by: Alexandros Frantzis 
---
Changes in v2:
 - Removed NULL check before calling init_pointer_constraint, since
   init_pointer_constraint now handles this case.
 - Handle NULL weston_pointer in zoom functions.

 libweston/input.c | 35 ++-
 libweston/zoom.c  |  5 -
 2 files changed, 34 insertions(+), 6 deletions(-)

diff --git a/libweston/input.c b/libweston/input.c
index 390698c7..647268af 100644
--- a/libweston/input.c
+++ b/libweston/input.c
@@ -105,6 +105,19 @@ weston_pointer_client_create(struct wl_client *client)
 static void
 weston_pointer_client_destroy(struct weston_pointer_client *pointer_client)
 {
+   struct wl_resource *resource;
+
+   wl_resource_for_each(resource, &pointer_client->pointer_resources) {
+   wl_resource_set_user_data(resource, NULL);
+   }
+
+   wl_resource_for_each(resource,
+&pointer_client->relative_pointer_resources) {
+   wl_resource_set_user_data(resource, NULL);
+   }
+
+   wl_list_remove(&pointer_client->pointer_resources);
+   wl_list_remove(&pointer_client->relative_pointer_resources);
free(pointer_client);
 }
 
@@ -170,11 +183,14 @@ unbind_pointer_client_resource(struct wl_resource 
*resource)
struct wl_client *client = wl_resource_get_client(resource);
struct weston_pointer_client *pointer_client;
 
-   pointer_client = weston_pointer_get_pointer_client(pointer, client);
-   assert(pointer_client);
-
wl_list_remove(wl_resource_get_link(resource));
-   weston_pointer_cleanup_pointer_client(pointer, pointer_client);
+
+   if (pointer) {
+   pointer_client = weston_pointer_get_pointer_client(pointer,
+  client);
+   assert(pointer_client);
+   weston_pointer_cleanup_pointer_client(pointer, pointer_client);
+   }
 }
 
 static void unbind_resource(struct wl_resource *resource)
@@ -1092,12 +1108,18 @@ weston_pointer_create(struct weston_seat *seat)
 WL_EXPORT void
 weston_pointer_destroy(struct weston_pointer *pointer)
 {
+   struct weston_pointer_client *pointer_client, *tmp;
+
wl_signal_emit(&pointer->destroy_signal, pointer);
 
if (pointer->sprite)
pointer_unmap_sprite(pointer);
 
-   /* XXX: What about pointer->resource_list? */
+   wl_list_for_each_safe(pointer_client, tmp, &pointer->pointer_clients,
+ link) {
+   wl_list_remove(&pointer_client->link);
+   weston_pointer_client_destroy(pointer_client);
+   }
 
wl_list_remove(&pointer->focus_resource_listener.link);
wl_list_remove(&pointer->focus_view_listener.link);
@@ -2318,6 +2340,9 @@ pointer_set_cursor(struct wl_client *client, struct 
wl_resource *resource,
struct weston_pointer *pointer = wl_resource_get_user_data(resource);
struct weston_surface *surface = NULL;
 
+   if (!pointer)
+   return;
+
if (surface_resource)
surface = wl_resource_get_user_data(surface_resource);
 
diff --git a/libweston/zoom.c b/libweston/zoom.c
index 84f1a320..b89264f7 100644
--- a/libweston/zoom.c
+++ b/libweston/zoom.c
@@ -125,6 +125,9 @@ weston_output_update_zoom(struct weston_output *output)
struct weston_seat *seat = output->zoom.seat;
struct weston_pointer *pointer = weston_seat_get_pointer(seat);
 
+   if (!pointer)
+   return;
+
assert(output->zoom.active);
 
output->zoom.current.x = wl_fixed_to_double(pointer->x);
@@ -151,7 +154,7 @@ weston_output_activate_zoom(struct weston_output *output,
 {
struct weston_pointer *pointer = weston_seat_get_pointer(seat);
 
-   if (output->zoom.active)
+   if (!pointer || output->zoom.active)
return;
 
output->zoom.active = true;
-- 
2.14.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH weston v2 7/7] tests: Add test for seat destruction and creation

2018-02-08 Thread Alexandros Frantzis
Add a test to check that we can destroy and create the test seat. Since
after test seat destruction the test client releases any associated
input resources, this test also checks that libweston properly handles
release requests for inert input resources.

Signed-off-by: Alexandros Frantzis 
---
Changes in v2:
 - Add assertions for client->input state.

 tests/devices-test.c | 22 ++
 1 file changed, 22 insertions(+)

diff --git a/tests/devices-test.c b/tests/devices-test.c
index a6ec6eaf..147a2791 100644
--- a/tests/devices-test.c
+++ b/tests/devices-test.c
@@ -322,3 +322,25 @@ TEST(seats_have_names)
assert(input->seat_name);
}
 }
+
+TEST(seat_destroy_and_recreate)
+{
+   struct client *cl = create_client_and_test_surface(100, 100, 100, 100);
+
+   weston_test_device_release(cl->test->weston_test, "seat");
+   /* Roundtrip to receive and handle the seat global removal event */
+   client_roundtrip(cl);
+
+   assert(!cl->input);
+
+   weston_test_device_add(cl->test->weston_test, "seat");
+   /* First roundtrip to send request and receive new seat global */
+   client_roundtrip(cl);
+   /* Second roundtrip to handle seat events and set up input devices */
+   client_roundtrip(cl);
+
+   assert(cl->input);
+   assert(cl->input->pointer);
+   assert(cl->input->keyboard);
+   assert(cl->input->touch);
+}
-- 
2.14.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH weston] libweston-desktop/xdg-shell-v5: Drop xdg-shell v5 support

2018-02-13 Thread Alexandros Frantzis
Drop support for the obsolete xdg-shell v5 protocol. This clears the
path to properly support xdg-shell stable, since xdg-shell stable and
xdg-shell v5 can't currently co-exist in the same compositor, as both
define structures with the same name (such as struct
xdg_surface_interface).

Signed-off-by: Alexandros Frantzis 
---
 Makefile.am   |   6 +-
 libweston-desktop/internal.h  |   3 -
 libweston-desktop/libweston-desktop.c |  10 -
 libweston-desktop/xdg-shell-v5.c  | 911 --
 4 files changed, 1 insertion(+), 929 deletions(-)
 delete mode 100644 libweston-desktop/xdg-shell-v5.c

diff --git a/Makefile.am b/Makefile.am
index 32c9a0f2..189e7d8a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -132,19 +132,15 @@ libweston_desktop_@LIBWESTON_MAJOR@_la_SOURCES =  \
libweston-desktop/surface.c \
libweston-desktop/wl-shell.c\
libweston-desktop/xdg-shell-v6.c\
-   libweston-desktop/xdg-shell-v5.c\
libweston-desktop/xwayland.c
 
 nodist_libweston_desktop_@LIBWESTON_MAJOR@_la_SOURCES =\
protocol/xdg-shell-unstable-v6-protocol.c   \
-   protocol/xdg-shell-unstable-v6-server-protocol.h\
-   protocol/xdg-shell-unstable-v5-protocol.c   \
-   protocol/xdg-shell-unstable-v5-server-protocol.h
+   protocol/xdg-shell-unstable-v6-server-protocol.h
 
 BUILT_SOURCES += $(nodist_libweston_desktop_@LIBWESTON_MAJOR@_la_SOURCES)
 
 libweston-desktop-@LIBWESTON_MAJOR@.la 
libweston-desktop/libweston_desktop_@LIBWESTON_MAJOR@_la-xdg-shell-v6.lo: 
protocol/xdg-shell-unstable-v6-server-protocol.h
-libweston-desktop-@LIBWESTON_MAJOR@.la 
libweston-desktop/libweston_desktop_@LIBWESTON_MAJOR@_la-xdg-shell-v5.lo: 
protocol/xdg-shell-unstable-v5-server-protocol.h
 
 if SYSTEMD_NOTIFY_SUPPORT
 module_LTLIBRARIES += systemd-notify.la
diff --git a/libweston-desktop/internal.h b/libweston-desktop/internal.h
index 763355bf..564f7b3c 100644
--- a/libweston-desktop/internal.h
+++ b/libweston-desktop/internal.h
@@ -230,9 +230,6 @@ struct wl_global *
 weston_desktop_xdg_shell_v6_create(struct weston_desktop *desktop,
   struct wl_display *display);
 struct wl_global *
-weston_desktop_xdg_shell_v5_create(struct weston_desktop *desktop,
-  struct wl_display *display);
-struct wl_global *
 weston_desktop_wl_shell_create(struct weston_desktop *desktop,
   struct wl_display *display);
 void
diff --git a/libweston-desktop/libweston-desktop.c 
b/libweston-desktop/libweston-desktop.c
index 48e90009..c840a8a9 100644
--- a/libweston-desktop/libweston-desktop.c
+++ b/libweston-desktop/libweston-desktop.c
@@ -41,7 +41,6 @@ struct weston_desktop {
struct weston_desktop_api api;
void *user_data;
struct wl_global *xdg_shell_v6;
-   struct wl_global *xdg_shell_v5;
struct wl_global *wl_shell;
 };
 
@@ -77,13 +76,6 @@ weston_desktop_create(struct weston_compositor *compositor,
return NULL;
}
 
-   desktop->xdg_shell_v5 =
-   weston_desktop_xdg_shell_v5_create(desktop, display);
-   if (desktop->xdg_shell_v5 == NULL) {
-   weston_desktop_destroy(desktop);
-   return NULL;
-   }
-
desktop->wl_shell =
weston_desktop_wl_shell_create(desktop, display);
if (desktop->wl_shell == NULL) {
@@ -104,8 +96,6 @@ weston_desktop_destroy(struct weston_desktop *desktop)
 
if (desktop->wl_shell != NULL)
wl_global_destroy(desktop->wl_shell);
-   if (desktop->xdg_shell_v5 != NULL)
-   wl_global_destroy(desktop->xdg_shell_v5);
if (desktop->xdg_shell_v6 != NULL)
wl_global_destroy(desktop->xdg_shell_v6);
 
diff --git a/libweston-desktop/xdg-shell-v5.c b/libweston-desktop/xdg-shell-v5.c
deleted file mode 100644
index ebe7940e..
--- a/libweston-desktop/xdg-shell-v5.c
+++ /dev/null
@@ -1,911 +0,0 @@
-/*
- * Copyright © 2010-2012 Intel Corporation
- * Copyright © 2011-2012 Collabora, Ltd.
- * Copyright © 2013 Raspberry Pi Foundation
- * Copyright © 2016 Quentin "Sardem FF7" Glidic
- *
- * 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
- * Soft

[PATCH weston v3 3/7] libweston: Make weston_seat release safe

2018-02-14 Thread Alexandros Frantzis
Ensure the server can safely handle client requests for wl_seat resource
that have become inert due to weston_seat object release and subsequent
destruction.

The clean-up involves, among other things, unsetting the destroyed
weston_seat object from the user data of wl_seat resources, and handling
this NULL user data case where required.

The list of sites extracting and using weston_seat object from wl_seat
resources which were audited for this patch are:

Legend:
N/A = Not Applicable (not implemented by weston)
FIXED = Fixed in the commit
OK = Already works correctly

== keyboard_shortcuts_inhibit_unstable_v1 ==
[N/A] zwp_keyboard_shortcuts_inhibit_manager_v1.inhibit_shortcuts
== tablet_input_unstable_v{1,2} ==
[N/A] zwp_tablet_manager_v{1,2}.get_tablet_seat
== text_input_unstable_v1 ==
[FIXED] zwp_text_input_v1.activate
[FIXED] zwp_text_input_v1.deactivate
== wl_data_device ==
[FIXED] wl_data_device_manager.get_data_device
[OK] wl_data_device.start_drag
[FIXED] wl_data_device.set_selection
[OK] wl_data_device.release
== wl_shell ==
[FIXED] wl_shell_surface.move
[FIXED] wl_shell_surface.resize
[FIXED] wl_shell_surface.set_popup
== xdg_shell and xdg_shell_unstable_v6 ==
[FIXED] xdg_toplevel.show_window_menu
[FIXED] xdg_toplevel.move
[FIXED] xdg_toplevel.resize
[FIXED] xdg_popup.grab
== xdg_shell_unstable_v5 ==
[FIXED] xdg_shell.get_xdg_popup
[FIXED] xdg_surface.show_window_menu
[FIXED] xdg_surface.move
[FIXED] xdg_surface.resize

Signed-off-by: Alexandros Frantzis 
Reviewed-by: Pekka Paalanen 
---
Changes in v3:
 - Drop xdg_shell v5 changes since support for v5 has been removed.
 - Handle inert seats more transparently in libweston-desktop, by ensuring that
   the weston_desktop_seat_from_seat,
   weston_desktop_seat_popup_grab_get_topmost_surface, and
   weston desktop_seat_popup_grab_start functions gracefully handle NULL
   seat pointer arguments internally.

Changes in v2:
 - Properly create inert resources in seat_get_pointer/touch/keyboard.
 - Ensure all sites which have a wl_seat input resource can deal
   with inert resources.

 compositor/text-backend.c|  8 --
 libweston-desktop/seat.c | 13 ++---
 libweston-desktop/wl-shell.c |  9 +-
 libweston-desktop/xdg-shell-v6.c | 24 
 libweston/data-device.c  | 15 ++
 libweston/input.c| 61 
 6 files changed, 100 insertions(+), 30 deletions(-)

diff --git a/compositor/text-backend.c b/compositor/text-backend.c
index e6ee249c..4d8c085b 100644
--- a/compositor/text-backend.c
+++ b/compositor/text-backend.c
@@ -193,10 +193,14 @@ text_input_activate(struct wl_client *client,
 {
struct text_input *text_input = wl_resource_get_user_data(resource);
struct weston_seat *weston_seat = wl_resource_get_user_data(seat);
-   struct input_method *input_method = weston_seat->input_method;
+   struct input_method *input_method;
struct weston_compositor *ec = text_input->ec;
struct text_input *current;
 
+   if (!weston_seat)
+   return;
+
+   input_method = weston_seat->input_method;
if (input_method->input == text_input)
return;
 
@@ -237,7 +241,7 @@ text_input_deactivate(struct wl_client *client,
 {
struct weston_seat *weston_seat = wl_resource_get_user_data(seat);
 
-   if (weston_seat->input_method->input)
+   if (weston_seat && weston_seat->input_method->input)
deactivate_input_method(weston_seat->input_method);
 }
 
diff --git a/libweston-desktop/seat.c b/libweston-desktop/seat.c
index 382b9e41..4e51ee0f 100644
--- a/libweston-desktop/seat.c
+++ b/libweston-desktop/seat.c
@@ -242,6 +242,9 @@ weston_desktop_seat_from_seat(struct weston_seat *wseat)
struct wl_listener *listener;
struct weston_desktop_seat *seat;
 
+   if (wseat == NULL)
+   return NULL;
+
listener = wl_signal_get(&wseat->destroy_signal,
 weston_desktop_seat_destroy);
if (listener != NULL)
@@ -270,7 +273,7 @@ weston_desktop_seat_from_seat(struct weston_seat *wseat)
 struct weston_desktop_surface *
 weston_desktop_seat_popup_grab_get_topmost_surface(struct weston_desktop_seat 
*seat)
 {
-   if (wl_list_empty(&seat->popup_grab.surfaces))
+   if (seat == NULL || wl_list_empty(&seat->popup_grab.surfaces))
return NULL;
 
struct wl_list *grab_link = seat->popup_grab.surfaces.next;
@@ -284,9 +287,11 @@ weston_desktop_seat_popup_grab_start(struct 
weston_desktop_seat *seat,
 {
assert(seat->popup_grab.client == NULL || seat->popup_grab.client == 
client);
 
-   struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat->seat);
-   struct weston_pointer *pointer = weston_seat_get_pointer(seat->seat);
-   struct weston_touch *touch = weston_seat_get_touch(seat->s

[PATCH weston v4 3/7] libweston: Make weston_seat release safe

2018-02-15 Thread Alexandros Frantzis
Ensure the server can safely handle client requests for wl_seat resource
that have become inert due to weston_seat object release and subsequent
destruction.

The clean-up involves, among other things, unsetting the destroyed
weston_seat object from the user data of wl_seat resources, and handling
this NULL user data case where required.

The list of sites extracting and using weston_seat object from wl_seat
resources which were audited for this patch are:

Legend:
N/A = Not Applicable (not implemented by weston)
FIXED = Fixed in the commit
OK = Already works correctly

== keyboard_shortcuts_inhibit_unstable_v1 ==
[N/A] zwp_keyboard_shortcuts_inhibit_manager_v1.inhibit_shortcuts
== tablet_input_unstable_v{1,2} ==
[N/A] zwp_tablet_manager_v{1,2}.get_tablet_seat
== text_input_unstable_v1 ==
[FIXED] zwp_text_input_v1.activate
[FIXED] zwp_text_input_v1.deactivate
== wl_data_device ==
[FIXED] wl_data_device_manager.get_data_device
[OK] wl_data_device.start_drag
[FIXED] wl_data_device.set_selection
[OK] wl_data_device.release
== wl_shell ==
[FIXED] wl_shell_surface.move
[FIXED] wl_shell_surface.resize
[FIXED] wl_shell_surface.set_popup
== xdg_shell and xdg_shell_unstable_v6 ==
[FIXED] xdg_toplevel.show_window_menu
[FIXED] xdg_toplevel.move
[FIXED] xdg_toplevel.resize
[FIXED] xdg_popup.grab
== xdg_shell_unstable_v5 ==
[FIXED] xdg_shell.get_xdg_popup
[FIXED] xdg_surface.show_window_menu
[FIXED] xdg_surface.move
[FIXED] xdg_surface.resize

Signed-off-by: Alexandros Frantzis 
Reviewed-by: Pekka Paalanen 
Reviewed-by: Quentin Glidic 
---
Changes in v4:
 - Add seat == NULL in assert in weston_desktop_seat_popup_grab_start.
 - Move check for NULL seat after checking for toplevel configured in
   weston_desktop_xdg_toplevel_protocol_{show_window_menu, move, resize}
Changes in v3:
 - Drop xdg_shell v5 changes since support for v5 has been removed.
 - Handle inert seats more transparently in libweston-desktop, by ensuring
   that the weston_desktop_seat_from_seat,
   weston_desktop_seat_popup_grab_get_topmost_surface, and
   weston desktop_seat_popup_grab_start functions gracefully handle NULL
   seat pointer arguments internally.
   
Changes in v2:
 - Properly create inert resources in seat_get_pointer/touch/keyboard.
 - Ensure all sites which have a wl_seat input resource can deal
   with inert resources.

 compositor/text-backend.c|  8 --
 libweston-desktop/seat.c | 18 
 libweston-desktop/wl-shell.c |  9 +-
 libweston-desktop/xdg-shell-v6.c | 24 
 libweston/data-device.c  | 15 ++
 libweston/input.c| 61 
 6 files changed, 103 insertions(+), 32 deletions(-)

diff --git a/compositor/text-backend.c b/compositor/text-backend.c
index e6ee249c..4d8c085b 100644
--- a/compositor/text-backend.c
+++ b/compositor/text-backend.c
@@ -193,10 +193,14 @@ text_input_activate(struct wl_client *client,
 {
struct text_input *text_input = wl_resource_get_user_data(resource);
struct weston_seat *weston_seat = wl_resource_get_user_data(seat);
-   struct input_method *input_method = weston_seat->input_method;
+   struct input_method *input_method;
struct weston_compositor *ec = text_input->ec;
struct text_input *current;
 
+   if (!weston_seat)
+   return;
+
+   input_method = weston_seat->input_method;
if (input_method->input == text_input)
return;
 
@@ -237,7 +241,7 @@ text_input_deactivate(struct wl_client *client,
 {
struct weston_seat *weston_seat = wl_resource_get_user_data(seat);
 
-   if (weston_seat->input_method->input)
+   if (weston_seat && weston_seat->input_method->input)
deactivate_input_method(weston_seat->input_method);
 }
 
diff --git a/libweston-desktop/seat.c b/libweston-desktop/seat.c
index 382b9e41..ae1c5e9f 100644
--- a/libweston-desktop/seat.c
+++ b/libweston-desktop/seat.c
@@ -242,6 +242,9 @@ weston_desktop_seat_from_seat(struct weston_seat *wseat)
struct wl_listener *listener;
struct weston_desktop_seat *seat;
 
+   if (wseat == NULL)
+   return NULL;
+
listener = wl_signal_get(&wseat->destroy_signal,
 weston_desktop_seat_destroy);
if (listener != NULL)
@@ -270,7 +273,7 @@ weston_desktop_seat_from_seat(struct weston_seat *wseat)
 struct weston_desktop_surface *
 weston_desktop_seat_popup_grab_get_topmost_surface(struct weston_desktop_seat 
*seat)
 {
-   if (wl_list_empty(&seat->popup_grab.surfaces))
+   if (seat == NULL || wl_list_empty(&seat->popup_grab.surfaces))
return NULL;
 
struct wl_list *grab_link = seat->popup_grab.surfaces.next;
@@ -282,11 +285,14 @@ bool
 weston_desktop_seat_popup_grab_start(struct weston_desktop_seat *seat,
 struct wl_client *client, uint32_

[PATCH weston v2 0/6] libweston: Support input_timestamps_unstable_v1

2018-02-16 Thread Alexandros Frantzis
The input_timestamps_unstable_v1 protocol allows clients to subscribe to
high-resolution timestamp events for input events (see [1]).

This patchset implements the input_timestamps_unstable_v1 protocol in libweston
and also adds tests for the implementation in the weston test suite.

Patches (1) and (2) introduce some helper code which is used by later patches.
Patch (2) in particular adds test helpers that also act as a nice example of a
client side implementation of the input_timestamps_unstable_v1 protocol.

Patches (3) to (6) implement the protocol in libweston.

v2 of this patchset has been rebased on the recent libweston changes to improve
handling of inert input resources, and is thus able to provide similar robust
handling of inert resources for the input_timestamps_unstable_v1 objects.  See
each patch for more detailed changes in v2.

[1] 
https://lists.freedesktop.org/archives/wayland-devel/2017-December/036320.html

Alexandros Frantzis (6):
  shared: Add timespec_eq helper function
  tests: Introduce input timestamps helper
  libweston: Introduce input-timestamps support
  libweston: Implement keyboard timestamps for
input_timestamps_unstable_v1
  libweston: Implement pointer timestamps for
input_timestamps_unstable_v1
  libweston: Implement touch timestamps for input_timestamps_unstable_v1

 Makefile.am   |  20 ++-
 configure.ac  |   2 +-
 libweston/compositor.h|   6 +
 libweston/input.c | 270 --
 shared/timespec-util.h|  13 ++
 tests/input-timestamps-helper.c   | 177 +
 tests/input-timestamps-helper.h   |  46 +++
 tests/keyboard-test.c |  45 +++
 tests/pointer-test.c  |  66 ++
 tests/timespec-test.c |  12 ++
 tests/touch-test.c|  46 +++
 tests/weston-test-client-helper.c |  16 +++
 tests/weston-test-client-helper.h |  12 ++
 13 files changed, 711 insertions(+), 20 deletions(-)
 create mode 100644 tests/input-timestamps-helper.c
 create mode 100644 tests/input-timestamps-helper.h

-- 
2.14.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


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

2018-02-16 Thread Alexandros Frantzis
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 
Reviewed-by: Pekka Paalanen 
---
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 ..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 
+#include 
+#include 
+#include 
+
+#include "input-timestamps-helper.h"
+#include "protocol/input-timestamps-unstable-v1-client-protocol.h"
+#include "shared/timespec-util.h"
+#include "shared/zalloc.h"
+#in

[PATCH weston v2 4/6] libweston: Implement keyboard timestamps for input_timestamps_unstable_v1

2018-02-16 Thread Alexandros Frantzis
Implement the zwp_input_timestamps_manager_v1.get_keyboard_timestamps
request to subscribe to timestamp events for wl_keyboard resources.
Ensure that the request handling code can gracefully handle inert
keyboard resources.

This commit introduces a few internal helper functions which will also
be useful in the implementation of the remaining
zwp_input_timestamps_manager_v1 requests.

Signed-off-by: Alexandros Frantzis 
---
Changes in v2:
 - Merge helper functions from v1 3/6 commit in this one to avoid
   warnings in 3/6 commit.
 - Remove the head of timestamps_list in weston_keyboard_destroy.
 - Gracefully handle inert keyboard resources in destroy_keyboard_resource
   and input_timestamps_manager_get_keyboard_timestamps.

 libweston/compositor.h |  2 ++
 libweston/input.c  | 95 --
 tests/keyboard-test.c  | 45 
 3 files changed, 139 insertions(+), 3 deletions(-)

diff --git a/libweston/compositor.h b/libweston/compositor.h
index ca1acc60..1566677f 100644
--- a/libweston/compositor.h
+++ b/libweston/compositor.h
@@ -605,6 +605,8 @@ struct weston_keyboard {
enum weston_led leds;
} xkb_state;
struct xkb_keymap *pending_keymap;
+
+   struct wl_list timestamps_list;
 };
 
 struct weston_seat {
diff --git a/libweston/input.c b/libweston/input.c
index 2e8bd088..8028ec20 100644
--- a/libweston/input.c
+++ b/libweston/input.c
@@ -87,6 +87,42 @@ region_init_infinite(pixman_region32_t *region)
  UINT32_MAX, UINT32_MAX);
 }
 
+static void
+send_timestamp(struct wl_resource *resource,
+  const struct timespec *time)
+{
+   uint32_t tv_sec_hi, tv_sec_lo, tv_nsec;
+
+   timespec_to_proto(time, &tv_sec_hi, &tv_sec_lo, &tv_nsec);
+   zwp_input_timestamps_v1_send_timestamp(resource, tv_sec_hi, tv_sec_lo,
+  tv_nsec);
+}
+
+static void
+send_timestamps_for_input_resource(struct wl_resource *input_resource,
+  struct wl_list *list,
+  const struct timespec *time)
+{
+   struct wl_resource *resource;
+
+   wl_resource_for_each(resource, list) {
+   if (wl_resource_get_user_data(resource) == input_resource)
+   send_timestamp(resource, time);
+   }
+}
+
+static void
+remove_input_resource_from_timestamps(struct wl_resource *input_resource,
+ struct wl_list *list)
+{
+   struct wl_resource *resource;
+
+   wl_resource_for_each(resource, list) {
+   if (wl_resource_get_user_data(resource) == input_resource)
+   wl_resource_set_user_data(resource, NULL);
+   }
+}
+
 static struct weston_pointer_client *
 weston_pointer_client_create(struct wl_client *client)
 {
@@ -884,8 +920,12 @@ weston_keyboard_send_key(struct weston_keyboard *keyboard,
resource_list = &keyboard->focus_resource_list;
serial = wl_display_next_serial(display);
msecs = timespec_to_msec(time);
-   wl_resource_for_each(resource, resource_list)
+   wl_resource_for_each(resource, resource_list) {
+   send_timestamps_for_input_resource(resource,
+  &keyboard->timestamps_list,
+  time);
wl_keyboard_send_key(resource, serial, msecs, key, state);
+   }
 };
 
 static void
@@ -1157,6 +1197,7 @@ weston_keyboard_create(void)
keyboard->default_grab.keyboard = keyboard;
keyboard->grab = &keyboard->default_grab;
wl_signal_init(&keyboard->focus_signal);
+   wl_list_init(&keyboard->timestamps_list);
 
return keyboard;
 }
@@ -1187,6 +1228,7 @@ weston_keyboard_destroy(struct weston_keyboard *keyboard)
 
wl_array_release(&keyboard->keys);
wl_list_remove(&keyboard->focus_resource_listener.link);
+   wl_list_remove(&keyboard->timestamps_list);
free(keyboard);
 }
 
@@ -2467,6 +2509,19 @@ seat_get_pointer(struct wl_client *client, struct 
wl_resource *resource,
}
 }
 
+static void
+destroy_keyboard_resource(struct wl_resource *resource)
+{
+   struct weston_keyboard *keyboard = wl_resource_get_user_data(resource);
+
+   wl_list_remove(wl_resource_get_link(resource));
+
+   if (keyboard) {
+   remove_input_resource_from_timestamps(resource,
+ 
&keyboard->timestamps_list);
+   }
+}
+
 static void
 keyboard_release(struct wl_client *client, struct wl_resource *resource)
 {
@@ -2524,7 +2579,7 @@ seat_get_keyboard(struct wl_client *client, struct 
wl_resource *resource,
 
wl_list_init(wl_resource_get_link(cr));
wl_resource_set_implementation(cr, &

[PATCH weston v2 1/6] shared: Add timespec_eq helper function

2018-02-16 Thread Alexandros Frantzis
Add a helper function to check if two struct timespec values are equal.
This helper function will be used in upcoming commits that implement the
input_timestamps_unstable_v1 protocol.

Signed-off-by: Alexandros Frantzis 
Reviewed-by: Pekka Paalanen 
---
Changes in v2:
 - No changes.

 shared/timespec-util.h | 13 +
 tests/timespec-test.c  | 12 
 2 files changed, 25 insertions(+)

diff --git a/shared/timespec-util.h b/shared/timespec-util.h
index 5f4b2b9e..ca0156af 100644
--- a/shared/timespec-util.h
+++ b/shared/timespec-util.h
@@ -231,6 +231,19 @@ timespec_is_zero(const struct timespec *a)
return a->tv_sec == 0 && a->tv_nsec == 0;
 }
 
+/* Check if two timespecs are equal
+ *
+ * \param a[in] timespec to check
+ * \param b[in] timespec to check
+ * \return whether timespecs a and b are equal
+ */
+static inline bool
+timespec_eq(const struct timespec *a, const struct timespec *b)
+{
+   return a->tv_sec == b->tv_sec &&
+  a->tv_nsec == b->tv_nsec;
+}
+
 /* Convert milli-Hertz to nanoseconds
  *
  * \param mhz frequency in mHz, not zero
diff --git a/tests/timespec-test.c b/tests/timespec-test.c
index 54230f89..24400187 100644
--- a/tests/timespec-test.c
+++ b/tests/timespec-test.c
@@ -294,3 +294,15 @@ ZUC_TEST(timespec_test, timespec_is_zero)
ZUC_ASSERT_FALSE(timespec_is_zero(&non_zero_nsec));
ZUC_ASSERT_FALSE(timespec_is_zero(&non_zero_sec));
 }
+
+ZUC_TEST(timespec_test, timespec_eq)
+{
+   struct timespec a = { .tv_sec = 2, .tv_nsec = 1 };
+   struct timespec b = { .tv_sec = -1, .tv_nsec = 2 };
+
+   ZUC_ASSERT_TRUE(timespec_eq(&a, &a));
+   ZUC_ASSERT_TRUE(timespec_eq(&b, &b));
+
+   ZUC_ASSERT_FALSE(timespec_eq(&a, &b));
+   ZUC_ASSERT_FALSE(timespec_eq(&b, &a));
+}
-- 
2.14.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH weston v2 3/6] libweston: Introduce input-timestamps support

2018-02-16 Thread Alexandros Frantzis
Introduce code to support the implementation of the
input_timestamps_unstable_v1 protocol in libweston. This commit does not
implement the actual timestamp subscriptions, but sets up the
zwp_input_timestamps_manager_v1 object and introduces dummy request
handling functions for it, laying the foundation for timestamp
subscriptions for keyboard/pointer/touch to be added cleanly in upcoming
commits.

Signed-off-by: Alexandros Frantzis 
---
Changes in v2:
 - Move unused helper functions to next patch to avoid warnings, keep
   only zwp_input_timestamps_manager_v1 code in this patch.

 Makefile.am   |  4 +++-
 libweston/input.c | 67 +++
 2 files changed, 70 insertions(+), 1 deletion(-)

diff --git a/Makefile.am b/Makefile.am
index 679e6b78..e028a2a1 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -166,7 +166,9 @@ nodist_libweston_@LIBWESTON_MAJOR@_la_SOURCES = 
\
protocol/relative-pointer-unstable-v1-protocol.c\
protocol/relative-pointer-unstable-v1-server-protocol.h \
protocol/pointer-constraints-unstable-v1-protocol.c \
-   protocol/pointer-constraints-unstable-v1-server-protocol.h
+   protocol/pointer-constraints-unstable-v1-server-protocol.h  \
+   protocol/input-timestamps-unstable-v1-protocol.c\
+   protocol/input-timestamps-unstable-v1-server-protocol.h
 
 BUILT_SOURCES += $(nodist_libweston_@LIBWESTON_MAJOR@_la_SOURCES)
 
diff --git a/libweston/input.c b/libweston/input.c
index da002548..2e8bd088 100644
--- a/libweston/input.c
+++ b/libweston/input.c
@@ -42,6 +42,7 @@
 #include "compositor.h"
 #include "relative-pointer-unstable-v1-server-protocol.h"
 #include "pointer-constraints-unstable-v1-server-protocol.h"
+#include "input-timestamps-unstable-v1-server-protocol.h"
 
 enum pointer_constraint_type {
POINTER_CONSTRAINT_TYPE_LOCK,
@@ -4569,6 +4570,67 @@ bind_pointer_constraints(struct wl_client *client, void 
*data,
   NULL, NULL);
 }
 
+static void
+input_timestamps_manager_destroy(struct wl_client *client,
+struct wl_resource *resource)
+{
+   wl_resource_destroy(resource);
+}
+
+static void
+input_timestamps_manager_get_keyboard_timestamps(struct wl_client *client,
+struct wl_resource *resource,
+uint32_t id,
+struct wl_resource 
*keyboard_resource)
+{
+   wl_client_post_no_memory(client);
+}
+
+static void
+input_timestamps_manager_get_pointer_timestamps(struct wl_client *client,
+   struct wl_resource *resource,
+   uint32_t id,
+   struct wl_resource 
*pointer_resource)
+{
+   wl_client_post_no_memory(client);
+}
+
+static void
+input_timestamps_manager_get_touch_timestamps(struct wl_client *client,
+ struct wl_resource *resource,
+ uint32_t id,
+ struct wl_resource 
*touch_resource)
+{
+   wl_client_post_no_memory(client);
+}
+
+static const struct zwp_input_timestamps_manager_v1_interface
+   input_timestamps_manager_interface = {
+   input_timestamps_manager_destroy,
+   input_timestamps_manager_get_keyboard_timestamps,
+   input_timestamps_manager_get_pointer_timestamps,
+   input_timestamps_manager_get_touch_timestamps,
+};
+
+static void
+bind_input_timestamps_manager(struct wl_client *client, void *data,
+ uint32_t version, uint32_t id)
+{
+   struct wl_resource *resource =
+   wl_resource_create(client,
+  &zwp_input_timestamps_manager_v1_interface,
+  1, id);
+
+   if (resource == NULL) {
+   wl_client_post_no_memory(client);
+   return;
+   }
+
+   wl_resource_set_implementation(resource,
+  &input_timestamps_manager_interface,
+  NULL, NULL);
+}
+
 int
 weston_input_init(struct weston_compositor *compositor)
 {
@@ -4582,5 +4644,10 @@ weston_input_init(struct weston_compositor *compositor)
  NULL, bind_pointer_constraints))
return -1;
 
+   if (!wl_global_create(compositor->wl_display,
+ &zwp_input_timestamps_manager_v1_interface, 1,
+ NULL, bind_input_timestamps_manager))
+   return -1;
+
return 0;
 }
-- 
2.14.1

___
wayland-devel

[PATCH weston v2 5/6] libweston: Implement pointer timestamps for input_timestamps_unstable_v1

2018-02-16 Thread Alexandros Frantzis
Implement the zwp_input_timestamps_manager_v1.get_pointer_timestamps
request to subscribe to timestamp events for wl_pointer resources.
Ensure that the request handling code can gracefully handle inert
pointer resources.

Signed-off-by: Alexandros Frantzis 
---
Changes in v2:
 - Remove the head of timestamps_list in weston_pointer_destroy.
 - Gracefully handle inert pointer resources in
   input_timestamps_manager_get_pointer_timestamps.

 libweston/compositor.h |  2 ++
 libweston/input.c  | 53 +++-
 tests/pointer-test.c   | 66 ++
 3 files changed, 115 insertions(+), 6 deletions(-)

diff --git a/libweston/compositor.h b/libweston/compositor.h
index 1566677f..78d2668e 100644
--- a/libweston/compositor.h
+++ b/libweston/compositor.h
@@ -391,6 +391,8 @@ struct weston_pointer {
uint32_t button_count;
 
struct wl_listener output_destroy_listener;
+
+   struct wl_list timestamps_list;
 };
 
 
diff --git a/libweston/input.c b/libweston/input.c
index 8028ec20..632c9c3c 100644
--- a/libweston/input.c
+++ b/libweston/input.c
@@ -226,6 +226,8 @@ unbind_pointer_client_resource(struct wl_resource *resource)
pointer_client = weston_pointer_get_pointer_client(pointer,
   client);
assert(pointer_client);
+   remove_input_resource_from_timestamps(resource,
+ 
&pointer->timestamps_list);
weston_pointer_cleanup_pointer_client(pointer, pointer_client);
}
 }
@@ -446,8 +448,12 @@ pointer_send_motion(struct weston_pointer *pointer,
 
resource_list = &pointer->focus_client->pointer_resources;
msecs = timespec_to_msec(time);
-   wl_resource_for_each(resource, resource_list)
+   wl_resource_for_each(resource, resource_list) {
+   send_timestamps_for_input_resource(resource,
+   &pointer->timestamps_list,
+   time);
wl_pointer_send_motion(resource, msecs, sx, sy);
+   }
 }
 
 WL_EXPORT void
@@ -528,8 +534,12 @@ weston_pointer_send_button(struct weston_pointer *pointer,
resource_list = &pointer->focus_client->pointer_resources;
serial = wl_display_next_serial(display);
msecs = timespec_to_msec(time);
-   wl_resource_for_each(resource, resource_list)
+   wl_resource_for_each(resource, resource_list) {
+   send_timestamps_for_input_resource(resource,
+   &pointer->timestamps_list,
+   time);
wl_pointer_send_button(resource, serial, msecs, button, state);
+   }
 }
 
 static void
@@ -586,14 +596,21 @@ weston_pointer_send_axis(struct weston_pointer *pointer,
wl_pointer_send_axis_discrete(resource, event->axis,
  event->discrete);
 
-   if (event->value)
+   if (event->value) {
+   send_timestamps_for_input_resource(resource,
+  
&pointer->timestamps_list,
+  time);
wl_pointer_send_axis(resource, msecs,
 event->axis,
 
wl_fixed_from_double(event->value));
-   else if (wl_resource_get_version(resource) >=
-WL_POINTER_AXIS_STOP_SINCE_VERSION)
+   } else if (wl_resource_get_version(resource) >=
+WL_POINTER_AXIS_STOP_SINCE_VERSION) {
+   send_timestamps_for_input_resource(resource,
+  
&pointer->timestamps_list,
+  time);
wl_pointer_send_axis_stop(resource, msecs,
  event->axis);
+   }
}
 }
 
@@ -1128,6 +1145,7 @@ weston_pointer_create(struct weston_seat *seat)
wl_signal_init(&pointer->focus_signal);
wl_list_init(&pointer->focus_view_listener.link);
wl_signal_init(&pointer->destroy_signal);
+   wl_list_init(&pointer->timestamps_list);
 
pointer->sprite_destroy_listener.notify = pointer_handle_sprite_destroy;
 
@@ -1165,6 +1183,7 @@ weston_pointer_destroy(struct weston_pointer *pointer)
wl_list_remove(&pointer->focus_resource_listener.link);
wl_list_remove(&pointer->focus_view_listener.link);
wl_list_remove(&pointer

[PATCH weston v2 6/6] libweston: Implement touch timestamps for input_timestamps_unstable_v1

2018-02-16 Thread Alexandros Frantzis
Implement the zwp_input_timestamps_manager_v1.get_touch_timestamps
request to subscribe to timestamp events for wl_touch resources. Ensure
that the request handling code can gracefully handle inert touch
resources.

Signed-off-by: Alexandros Frantzis 
---
Changes in v2:
 - Remove the head of timestamps_list in weston_touch_destroy.
 - Gracefully handle inert pointer resources in destroy_touch_resource
   and input_timestamps_manager_get_touch_timestamps.

 libweston/compositor.h |  2 ++
 libweston/input.c  | 61 --
 tests/touch-test.c | 46 +
 3 files changed, 102 insertions(+), 7 deletions(-)

diff --git a/libweston/compositor.h b/libweston/compositor.h
index 78d2668e..010f1fa8 100644
--- a/libweston/compositor.h
+++ b/libweston/compositor.h
@@ -415,6 +415,8 @@ struct weston_touch {
wl_fixed_t grab_x, grab_y;
uint32_t grab_serial;
struct timespec grab_time;
+
+   struct wl_list timestamps_list;
 };
 
 void
diff --git a/libweston/input.c b/libweston/input.c
index 632c9c3c..3f616941 100644
--- a/libweston/input.c
+++ b/libweston/input.c
@@ -758,10 +758,14 @@ weston_touch_send_down(struct weston_touch *touch, const 
struct timespec *time,
resource_list = &touch->focus_resource_list;
serial = wl_display_next_serial(display);
msecs = timespec_to_msec(time);
-   wl_resource_for_each(resource, resource_list)
-   wl_touch_send_down(resource, serial, msecs,
-  touch->focus->surface->resource,
-  touch_id, sx, sy);
+   wl_resource_for_each(resource, resource_list) {
+   send_timestamps_for_input_resource(resource,
+  &touch->timestamps_list,
+  time);
+   wl_touch_send_down(resource, serial, msecs,
+  touch->focus->surface->resource,
+  touch_id, sx, sy);
+   }
 }
 
 static void
@@ -798,8 +802,12 @@ weston_touch_send_up(struct weston_touch *touch, const 
struct timespec *time,
resource_list = &touch->focus_resource_list;
serial = wl_display_next_serial(display);
msecs = timespec_to_msec(time);
-   wl_resource_for_each(resource, resource_list)
+   wl_resource_for_each(resource, resource_list) {
+   send_timestamps_for_input_resource(resource,
+  &touch->timestamps_list,
+  time);
wl_touch_send_up(resource, serial, msecs, touch_id);
+   }
 }
 
 static void
@@ -839,6 +847,9 @@ weston_touch_send_motion(struct weston_touch *touch,
resource_list = &touch->focus_resource_list;
msecs = timespec_to_msec(time);
wl_resource_for_each(resource, resource_list) {
+   send_timestamps_for_input_resource(resource,
+  &touch->timestamps_list,
+  time);
wl_touch_send_motion(resource, msecs,
 touch_id, sx, sy);
}
@@ -1276,6 +1287,7 @@ weston_touch_create(void)
touch->default_grab.touch = touch;
touch->grab = &touch->default_grab;
wl_signal_init(&touch->focus_signal);
+   wl_list_init(&touch->timestamps_list);
 
return touch;
 }
@@ -1297,6 +1309,7 @@ weston_touch_destroy(struct weston_touch *touch)
wl_list_remove(&touch->focus_resource_list);
wl_list_remove(&touch->focus_view_listener.link);
wl_list_remove(&touch->focus_resource_listener.link);
+   wl_list_remove(&touch->timestamps_list);
free(touch);
 }
 
@@ -2647,6 +2660,19 @@ seat_get_keyboard(struct wl_client *client, struct 
wl_resource *resource,
}
 }
 
+static void
+destroy_touch_resource(struct wl_resource *resource)
+{
+   struct weston_touch *touch = wl_resource_get_user_data(resource);
+
+   wl_list_remove(wl_resource_get_link(resource));
+
+   if (touch) {
+   remove_input_resource_from_timestamps(resource,
+ &touch->timestamps_list);
+   }
+}
+
 static void
 touch_release(struct wl_client *client, struct wl_resource *resource)
 {
@@ -2682,7 +2708,7 @@ seat_get_touch(struct wl_client *client, struct 
wl_resource *resource,
 
wl_list_init(wl_resource_get_link(cr));
wl_resource_set_implementation(cr, &touch_interface,
-  touch, unbind_resource);
+  touch, destroy_touch_resource);
 

Re: [PATCH weston v2 6/6] libweston: Implement touch timestamps for input_timestamps_unstable_v1

2018-02-16 Thread Alexandros Frantzis
On Fri, Feb 16, 2018 at 06:44:19PM +0200, Alexandros Frantzis wrote:
> Implement the zwp_input_timestamps_manager_v1.get_touch_timestamps
> request to subscribe to timestamp events for wl_touch resources. Ensure
> that the request handling code can gracefully handle inert touch
> resources.
> 
> Signed-off-by: Alexandros Frantzis 
> ---
> Changes in v2:
>  - Remove the head of timestamps_list in weston_touch_destroy.
>  - Gracefully handle inert pointer resources in destroy_touch_resource
>and input_timestamps_manager_get_touch_timestamps.

There is an error in the "Changes in v2" text, I meant:

  - Gracefully handle inert *touch* resources in destroy_touch_resource...

Thanks,
Alexandros
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH weston v3 4/6] libweston: Implement keyboard timestamps for input_timestamps_unstable_v1

2018-02-20 Thread Alexandros Frantzis
Implement the zwp_input_timestamps_manager_v1.get_keyboard_timestamps
request to subscribe to timestamp events for wl_keyboard resources.
Ensure that the request handling code can gracefully handle inert
keyboard resources.

This commit introduces a few internal helper functions which will also
be useful in the implementation of the remaining
zwp_input_timestamps_manager_v1 requests.

Signed-off-by: Alexandros Frantzis 
---
Changes in v3:
 - In keyboard_timestamps_stop_after_client_releases_wl_keyboard test
   check for changes to keyboard->input_timestamp instead of
   keyboard->key_time_timespec.

Changes in v2:
 - Merge helper functions from v1 3/6 commit in this one to avoid
   warnings in 3/6 commit.
 - Remove the head of timestamps_list in weston_keyboard_destroy.
 - Gracefully handle inert keyboard resources in destroy_keyboard_resource
   and input_timestamps_manager_get_keyboard_timestamps.

 libweston/compositor.h |  2 ++
 libweston/input.c  | 95 --
 tests/keyboard-test.c  | 51 +++
 3 files changed, 145 insertions(+), 3 deletions(-)

diff --git a/libweston/compositor.h b/libweston/compositor.h
index ca1acc60..1566677f 100644
--- a/libweston/compositor.h
+++ b/libweston/compositor.h
@@ -605,6 +605,8 @@ struct weston_keyboard {
enum weston_led leds;
} xkb_state;
struct xkb_keymap *pending_keymap;
+
+   struct wl_list timestamps_list;
 };
 
 struct weston_seat {
diff --git a/libweston/input.c b/libweston/input.c
index 2e8bd088..8028ec20 100644
--- a/libweston/input.c
+++ b/libweston/input.c
@@ -87,6 +87,42 @@ region_init_infinite(pixman_region32_t *region)
  UINT32_MAX, UINT32_MAX);
 }
 
+static void
+send_timestamp(struct wl_resource *resource,
+  const struct timespec *time)
+{
+   uint32_t tv_sec_hi, tv_sec_lo, tv_nsec;
+
+   timespec_to_proto(time, &tv_sec_hi, &tv_sec_lo, &tv_nsec);
+   zwp_input_timestamps_v1_send_timestamp(resource, tv_sec_hi, tv_sec_lo,
+  tv_nsec);
+}
+
+static void
+send_timestamps_for_input_resource(struct wl_resource *input_resource,
+  struct wl_list *list,
+  const struct timespec *time)
+{
+   struct wl_resource *resource;
+
+   wl_resource_for_each(resource, list) {
+   if (wl_resource_get_user_data(resource) == input_resource)
+   send_timestamp(resource, time);
+   }
+}
+
+static void
+remove_input_resource_from_timestamps(struct wl_resource *input_resource,
+ struct wl_list *list)
+{
+   struct wl_resource *resource;
+
+   wl_resource_for_each(resource, list) {
+   if (wl_resource_get_user_data(resource) == input_resource)
+   wl_resource_set_user_data(resource, NULL);
+   }
+}
+
 static struct weston_pointer_client *
 weston_pointer_client_create(struct wl_client *client)
 {
@@ -884,8 +920,12 @@ weston_keyboard_send_key(struct weston_keyboard *keyboard,
resource_list = &keyboard->focus_resource_list;
serial = wl_display_next_serial(display);
msecs = timespec_to_msec(time);
-   wl_resource_for_each(resource, resource_list)
+   wl_resource_for_each(resource, resource_list) {
+   send_timestamps_for_input_resource(resource,
+  &keyboard->timestamps_list,
+  time);
wl_keyboard_send_key(resource, serial, msecs, key, state);
+   }
 };
 
 static void
@@ -1157,6 +1197,7 @@ weston_keyboard_create(void)
keyboard->default_grab.keyboard = keyboard;
keyboard->grab = &keyboard->default_grab;
wl_signal_init(&keyboard->focus_signal);
+   wl_list_init(&keyboard->timestamps_list);
 
return keyboard;
 }
@@ -1187,6 +1228,7 @@ weston_keyboard_destroy(struct weston_keyboard *keyboard)
 
wl_array_release(&keyboard->keys);
wl_list_remove(&keyboard->focus_resource_listener.link);
+   wl_list_remove(&keyboard->timestamps_list);
free(keyboard);
 }
 
@@ -2467,6 +2509,19 @@ seat_get_pointer(struct wl_client *client, struct 
wl_resource *resource,
}
 }
 
+static void
+destroy_keyboard_resource(struct wl_resource *resource)
+{
+   struct weston_keyboard *keyboard = wl_resource_get_user_data(resource);
+
+   wl_list_remove(wl_resource_get_link(resource));
+
+   if (keyboard) {
+   remove_input_resource_from_timestamps(resource,
+ 
&keyboard->timestamps_list);
+   }
+}
+
 static void
 keyboard_release(struct wl_client *client, struct wl_resource *resource)
 {
@@ -2524,7 +2579,7 @@ seat_get_keyboard(struct wl_cli

[PATCH weston v3 5/6] libweston: Implement pointer timestamps for input_timestamps_unstable_v1

2018-02-20 Thread Alexandros Frantzis
Implement the zwp_input_timestamps_manager_v1.get_pointer_timestamps
request to subscribe to timestamp events for wl_pointer resources.
Ensure that the request handling code can gracefully handle inert
pointer resources.

Signed-off-by: Alexandros Frantzis 
---
Changes in v3:
 - In pointer_timestamps_stop_after_client_releases_wl_pointer test
   check for changes to pointer->input_timestamp instead of
   pointer->motion_time_timespec.

Changes in v2:
 - Remove the head of timestamps_list in weston_pointer_destroy.
 - Gracefully handle inert pointer resources in
   input_timestamps_manager_get_pointer_timestamps.

 libweston/compositor.h |  2 ++
 libweston/input.c  | 53 +-
 tests/pointer-test.c   | 70 ++
 3 files changed, 119 insertions(+), 6 deletions(-)

diff --git a/libweston/compositor.h b/libweston/compositor.h
index 1566677f..78d2668e 100644
--- a/libweston/compositor.h
+++ b/libweston/compositor.h
@@ -391,6 +391,8 @@ struct weston_pointer {
uint32_t button_count;
 
struct wl_listener output_destroy_listener;
+
+   struct wl_list timestamps_list;
 };
 
 
diff --git a/libweston/input.c b/libweston/input.c
index 8028ec20..632c9c3c 100644
--- a/libweston/input.c
+++ b/libweston/input.c
@@ -226,6 +226,8 @@ unbind_pointer_client_resource(struct wl_resource *resource)
pointer_client = weston_pointer_get_pointer_client(pointer,
   client);
assert(pointer_client);
+   remove_input_resource_from_timestamps(resource,
+ 
&pointer->timestamps_list);
weston_pointer_cleanup_pointer_client(pointer, pointer_client);
}
 }
@@ -446,8 +448,12 @@ pointer_send_motion(struct weston_pointer *pointer,
 
resource_list = &pointer->focus_client->pointer_resources;
msecs = timespec_to_msec(time);
-   wl_resource_for_each(resource, resource_list)
+   wl_resource_for_each(resource, resource_list) {
+   send_timestamps_for_input_resource(resource,
+   &pointer->timestamps_list,
+   time);
wl_pointer_send_motion(resource, msecs, sx, sy);
+   }
 }
 
 WL_EXPORT void
@@ -528,8 +534,12 @@ weston_pointer_send_button(struct weston_pointer *pointer,
resource_list = &pointer->focus_client->pointer_resources;
serial = wl_display_next_serial(display);
msecs = timespec_to_msec(time);
-   wl_resource_for_each(resource, resource_list)
+   wl_resource_for_each(resource, resource_list) {
+   send_timestamps_for_input_resource(resource,
+   &pointer->timestamps_list,
+   time);
wl_pointer_send_button(resource, serial, msecs, button, state);
+   }
 }
 
 static void
@@ -586,14 +596,21 @@ weston_pointer_send_axis(struct weston_pointer *pointer,
wl_pointer_send_axis_discrete(resource, event->axis,
  event->discrete);
 
-   if (event->value)
+   if (event->value) {
+   send_timestamps_for_input_resource(resource,
+  
&pointer->timestamps_list,
+  time);
wl_pointer_send_axis(resource, msecs,
 event->axis,
 
wl_fixed_from_double(event->value));
-   else if (wl_resource_get_version(resource) >=
-WL_POINTER_AXIS_STOP_SINCE_VERSION)
+   } else if (wl_resource_get_version(resource) >=
+WL_POINTER_AXIS_STOP_SINCE_VERSION) {
+   send_timestamps_for_input_resource(resource,
+  
&pointer->timestamps_list,
+  time);
wl_pointer_send_axis_stop(resource, msecs,
  event->axis);
+   }
}
 }
 
@@ -1128,6 +1145,7 @@ weston_pointer_create(struct weston_seat *seat)
wl_signal_init(&pointer->focus_signal);
wl_list_init(&pointer->focus_view_listener.link);
wl_signal_init(&pointer->destroy_signal);
+   wl_list_init(&pointer->timestamps_list);
 
pointer->sprite_destroy_listener.notify = pointer_handle_sprite_destroy;
 
@@ -1165,6 +1183,7 @@ weston_pointer_destroy(struct weston_pointer *pointer)
  

[PATCH weston v3 6/6] libweston: Implement touch timestamps for input_timestamps_unstable_v1

2018-02-20 Thread Alexandros Frantzis
Implement the zwp_input_timestamps_manager_v1.get_touch_timestamps
request to subscribe to timestamp events for wl_touch resources. Ensure
that the request handling code can gracefully handle inert touch
resources.

Signed-off-by: Alexandros Frantzis 
---
Changes in v3:
 - In touch_timestamps_stop_after_client_releases_wl_touch test
   check for changes to touch->input_timestamp instead of 
   touch->up_time_timespec.

Changes in v2:
 - Remove the head of timestamps_list in weston_touch_destroy.
 - Gracefully handle inert touch resources in destroy_touch_resource
   and input_timestamps_manager_get_touch_timestamps.

 libweston/compositor.h |  2 ++
 libweston/input.c  | 61 --
 tests/touch-test.c | 52 ++
 3 files changed, 108 insertions(+), 7 deletions(-)

diff --git a/libweston/compositor.h b/libweston/compositor.h
index 78d2668e..010f1fa8 100644
--- a/libweston/compositor.h
+++ b/libweston/compositor.h
@@ -415,6 +415,8 @@ struct weston_touch {
wl_fixed_t grab_x, grab_y;
uint32_t grab_serial;
struct timespec grab_time;
+
+   struct wl_list timestamps_list;
 };
 
 void
diff --git a/libweston/input.c b/libweston/input.c
index 632c9c3c..3f616941 100644
--- a/libweston/input.c
+++ b/libweston/input.c
@@ -758,10 +758,14 @@ weston_touch_send_down(struct weston_touch *touch, const 
struct timespec *time,
resource_list = &touch->focus_resource_list;
serial = wl_display_next_serial(display);
msecs = timespec_to_msec(time);
-   wl_resource_for_each(resource, resource_list)
-   wl_touch_send_down(resource, serial, msecs,
-  touch->focus->surface->resource,
-  touch_id, sx, sy);
+   wl_resource_for_each(resource, resource_list) {
+   send_timestamps_for_input_resource(resource,
+  &touch->timestamps_list,
+  time);
+   wl_touch_send_down(resource, serial, msecs,
+  touch->focus->surface->resource,
+  touch_id, sx, sy);
+   }
 }
 
 static void
@@ -798,8 +802,12 @@ weston_touch_send_up(struct weston_touch *touch, const 
struct timespec *time,
resource_list = &touch->focus_resource_list;
serial = wl_display_next_serial(display);
msecs = timespec_to_msec(time);
-   wl_resource_for_each(resource, resource_list)
+   wl_resource_for_each(resource, resource_list) {
+   send_timestamps_for_input_resource(resource,
+  &touch->timestamps_list,
+  time);
wl_touch_send_up(resource, serial, msecs, touch_id);
+   }
 }
 
 static void
@@ -839,6 +847,9 @@ weston_touch_send_motion(struct weston_touch *touch,
resource_list = &touch->focus_resource_list;
msecs = timespec_to_msec(time);
wl_resource_for_each(resource, resource_list) {
+   send_timestamps_for_input_resource(resource,
+  &touch->timestamps_list,
+  time);
wl_touch_send_motion(resource, msecs,
 touch_id, sx, sy);
}
@@ -1276,6 +1287,7 @@ weston_touch_create(void)
touch->default_grab.touch = touch;
touch->grab = &touch->default_grab;
wl_signal_init(&touch->focus_signal);
+   wl_list_init(&touch->timestamps_list);
 
return touch;
 }
@@ -1297,6 +1309,7 @@ weston_touch_destroy(struct weston_touch *touch)
wl_list_remove(&touch->focus_resource_list);
wl_list_remove(&touch->focus_view_listener.link);
wl_list_remove(&touch->focus_resource_listener.link);
+   wl_list_remove(&touch->timestamps_list);
free(touch);
 }
 
@@ -2647,6 +2660,19 @@ seat_get_keyboard(struct wl_client *client, struct 
wl_resource *resource,
}
 }
 
+static void
+destroy_touch_resource(struct wl_resource *resource)
+{
+   struct weston_touch *touch = wl_resource_get_user_data(resource);
+
+   wl_list_remove(wl_resource_get_link(resource));
+
+   if (touch) {
+   remove_input_resource_from_timestamps(resource,
+ &touch->timestamps_list);
+   }
+}
+
 static void
 touch_release(struct wl_client *client, struct wl_resource *resource)
 {
@@ -2682,7 +2708,7 @@ seat_get_touch(struct wl_client *client, struct 
wl_resource *resource,
 
wl_list_init(wl_resource_get_link(cr));
wl_resource_set_implementation(cr, &touch_interface,

Re: [RFC,wayland-protocols] Add alpha-compositing protocol

2018-09-10 Thread Alexandros Frantzis
On Fri, Sep 07, 2018 at 04:02:24PM +0200, Gary Bisson wrote:
> Hi Alexandros, All,
> 
> On Tue, Aug 08, 2017 at 05:24:58PM +0300, Alexandros Frantzis wrote:
> > This protocol specifies a set of interfaces used to control the alpha
> > compositing and blending of surface contents.
> > 
> > It's based on the Chromium Wayland protocol of the same name ([1]),
> > with a few changes made to the blending_equation enumeration.
> > 
> > A proof-of-concept implementation for Weston can be found at:
> > 
> > https://git.collabora.com/cgit/user/alf/weston.git/log/?h=alpha-compositing-v1
> > 
> > [1] 
> > https://chromium.googlesource.com/chromium/src/+/master/third_party/wayland-protocols/unstable/alpha-compositing/alpha-compositing-unstable-v1.xml
> 
> Was there any feedback on this RFC? On top of Chromium, it seems that
> NXP is now also using it for its i.MX processors [2]. So it would
> definitely be great to have this protocol upstream.
> 
> Note that NXP apparently modified this version of the patch a bit.
> 
> Regards,
> Gary
> 
> [2] 
> https://source.codeaurora.org/external/imx/wayland-protocols-imx/commit/?id=799164a4

Hi Gary,

thanks for bringing the i.MX version to my/our attention.

I haven't received any feedback about this proposal so far, but I am
happy to revive the upstreaming effort as soon as I do. To this end, I
have also added Haihua Hu (from NXP) to the CC list for this thread.

Thanks,
Alexandros
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


  1   2   >