Re: race between (say) wl_display_sync and wl_callback_add_listener?

2023-09-26 Thread Alexandros Frantzis
On Tue, Sep 26, 2023 at 10:08:55AM +0100, John Cox wrote:
> Hi
> 
> Many thanks for your comprehensive answer
> 
> >On Mon, Sep 25, 2023 at 05:10:30PM +0100, John Cox wrote:
> >> Hi
> >
> >Hi,
> >
> >> Assuming I have a separate poll/read_events/dispatch_queue thread to my
> >> main thread. If I go wl_display_sync/wl_callback_add_listener on the
> >> main thread is there a race condition between those two calls where the
> >> other thread can read & dispatch the callback before the listener is
> >> added or is there some magic s.t. adding the listener will always work
> >> as expected?
> >
> >This is indeed a racy interaction, in more ways than one:
> >
> >1. There is an inherent data race setting and using the
> >   listener/user_data concurrently from different threads.
> >   Neither adding a listener/user_data (see wl_proxy_add_listener()),
> >   nor the actual dispatching operation in libwayland (which uses the
> >   listener, see wayland-client.c:dispatch_event()) is protected by
> >   the internal "display lock".
> 
> So are all interactions from another thread than the dispatch thread
> unsafe e.g. buffer creation, setup & assignment to a surface or is it
> just the obviously racy subset?

>From a low-level libwayland API perspective, creating objects or making
requests from another thread is generally fine. It's this particular
case of requests that create object and cause events to be emitted
immediately for them that's problematic.

Many requests that fall in this category are in fact global binds (e.g.,
wl_shm, wl_seat, wl_output), which are typically handled in the context of the
wl_registry.global handler, thus in the dispatch thread, in which case no
special consideration is required.

There are also some requests that at first glance seem problematic,
but in fact they are not (if things are done properly, and assuming
correct compositor behavior). For example:

  struct wl_callback *wl_surface_frame(struct wl_surface *surface);

seems suspiciously similar to wl_display_sync(). However, this request
takes effect (i.e., the callback will receive events) only after the next
wl_surface_commit(), so the following is safe:

cb = wl_surface_frame(surface);
/* As long as the listener is set before the commit we are good. */
wl_callback_add_listener(cb);
wl_surface_commit(surface);

Of course, on top of all these there are also the typical higher-level
multithreading synchronization considerations.



> >Finally, you might also want to consider a different design more in line
> >with the libwayland API expectations, if possible.
> 
> Not really possible - there are some things I need done (buffer reclaim
> mostly) async as soon as possible and I don't have control over the main
> loop.

Buffer reclaiming (if by that you mean handling wl_buffer.release and
making the buffer available for drawing again) is a good case for a
separate queue, since wl_buffers are "independent" objects, as long as you
can dispatch on demand: when you need a new buffer and don't have any you
can dispatch the queue to check if the compositor has released one.

> There may be a document that sets out everything you've said above and
> gives the exact expectations but I failed to find it. In general the
> individual call documentation is great but how interactions between
> calls are managed is harder to find. I started from an (incorrect)
> assumption that everything was fully async and could be called from any
> thread (my natural progamming style) and so there must be magic to
> enable that and have only slowly been corrected by reality.

I wouldn't mind an official Wayland API/technical FAQ myself :)

Thanks,
Alexandros


Re: race between (say) wl_display_sync and wl_callback_add_listener?

2023-09-26 Thread Alexandros Frantzis
On Mon, Sep 25, 2023 at 05:10:30PM +0100, John Cox wrote:
> Hi

Hi,

> Assuming I have a separate poll/read_events/dispatch_queue thread to my
> main thread. If I go wl_display_sync/wl_callback_add_listener on the
> main thread is there a race condition between those two calls where the
> other thread can read & dispatch the callback before the listener is
> added or is there some magic s.t. adding the listener will always work
> as expected?

This is indeed a racy interaction, in more ways than one:

1. There is an inherent data race setting and using the
   listener/user_data concurrently from different threads.
   Neither adding a listener/user_data (see wl_proxy_add_listener()),
   nor the actual dispatching operation in libwayland (which uses the
   listener, see wayland-client.c:dispatch_event()) is protected by
   the internal "display lock".

2. Even ignoring the above, if the callback done event is received and
   dispatched before the listener is actually set, the callback will
   not get called.
   
> I assume it must be safe if dispatch & create/add_listener are in the
> same thread.

Yes, a single thread guarantees that the listener is properly set before
any relevant event is dispatched (assuming you don't dispatch events
before setting the listener!).

> The same question applies to adding listeners after binding (say) the
> shm extension where the bind provokes a set of events giving formats.

Yes, any object creation that may cause the compositor to send events as
an immediate response has this problem.
 
> Is there a safe way of doing this? (mutex around the dispatch and
> create/add_listener pairs would seem plausible even if really not what I
> want to do)

Here are some ideas:

Use a separate queue in the main thread for this event. Special care is
needed to ensure the event is actually dispatched on that queue. See
wl_proxy_create_wrapper(), and wl_display_roundtrip_queue() for a
function that uses a wrapper. Note that using a separate queue may
cause the event(s) to be handled out of order relative to the events
in the main queue. This may or may not be a problem depending on the
specific scenario.

Using a mutex as you describe is also a possible solution. The typical
caveats apply: holding a mutex when calling out to potentially arbitrary
code (i.e., dispatch handlers) may increase deadlock risk etc.

Another alternative would be to introduce a mechanism to pause and
resume the dispatch thread (e.g., wake up the poll with a pipe/eventfd
and then wait on some condition variable to resume), which would be used
like:

pause_dispatch_thread();
... sync and add listener ...
resume_dispatch_thread();

You could also introduce a mechanism to schedule your own function
calls in the dispatch thread:

schedule_in_dispatch_thread(sync_and_add_listener, data);

Finally, you might also want to consider a different design more in line
with the libwayland API expectations, if possible.

HTH,
Alexandros


Re: Weston 8: kiosk-shell background is black but should be grey

2022-10-04 Thread Alexandros Frantzis
On Tue, Oct 04, 2022 at 08:55:22AM +0100, Terry Barnaby wrote:
> From what I can see the kiosk-shell in Weston 9.0 should draw a grey (0.5,
> 0.5, 0.5) solid colour background. However on my NXP embedded system it
> shows as black.
> 
> Should the kiosk-shell in Weston 9.0 actually draw grey ?
> 
> If so is there some configuration I'm missing or is there a bug with that
> release ?
> 
> Terry

Hi Terry,

kiosk-shell until some point after 9.0.0 (until commit 73aaf14e to be
precise), has a hardcoded grey background. I just verified this works
fine with 9.0.0, at least with an Intel GPU.

The aforementioned commit changes the default background to black and
allows reading a background color value from the .ini file, like
desktop-shell does.

If you are not seeing a grey background, could it be the case that the
Weston version you are using is not actually pure 9.0.0 but is based on
some commit after 9.0.0 (so really version 9.0.9x) that also includes the
background-color support?

The first lines of your Weston log should provide information about the
exact version/build you are running. What do the lines say?

In the email subject you wrote "Weston 8", is this a typo?

Thanks,
Alexandros


Re: Weston window move to second monitor

2022-10-03 Thread Alexandros Frantzis
On Sun, Oct 02, 2022 at 09:13:27AM +0100, Terry Barnaby wrote:
> Hi,
> 
> I am developing software for an instrument embedded system using NXP CPU's
> and the Wayland/Weston GUI system.
> 
> The hardware platform has a main LCD panel and an optional plug-in HDMI
> monitor. The GUI is currently running with the Weston kiosk-shell and a
> single application is shown full screen on the LCD. Weston is configured so
> that the HDMI monitor appears to the right of the LCD screen and if the
> desktop-shell is used applications can be dragged across.
> 
> Now what I would like is for the application to be moved to the HDMI
> monitor/screen when the monitor is plugged in (resizing as needed).
> 
> With X11 I would have simply, from the application, moved its top level
> window coordinates and without a window manager or with a simple window
> manager the window would move to the area of the second screen.
> 
> Now I understand that Weston and the standard Wayland protocol's do not even
> allow a window move request to be made.
> 
> So I assume I might have to implement a whole new Weston shell, perhaps
> based on the kiosk-shell, and either invent some form of protocol to allow
> the application to request the shell to move it or get the shell to see HDMI
> plug in events and move the application and tell it to resize.
> 
> I don't have much knowledge of Wayland/Weston internals (lots of X11), so
> can anyone give me any pointers on how I might achieve this in the
> simplest/quickest way ?
> 
> Terry

Hi Terry,

Assuming you only care about the fullscreen case, an application can
request (but not force) a fullscreen placement for a toplevel surface
with:

xdg_toplevel_set_fullscreen(xdg_toplevel, wl_output)

In your application you could listen for advertised wl_output globals
and issue a set_fullscreen request for the preferred wl_output (e.g.,
based on the wl_output/xdg_output name). Since you are only dealing with
a specific compositor under your control, you can be fairly confident
that you will get consistent behavior here, i.e., the compositor will
honor your request.

Note that kiosk-shell provides a mechanism in the .ini file to declare
the placement of applications on specific outputs. However, the output
placement decision is static, made only when the surface is first
created/committed to, not for any subsequent output reconfigurations.
Making this output placement in kiosk-shell work more dynamically
(optionally), with the shell moving the surface to the preferred output,
could possibly be a useful enhancement for some use cases.

HTH,
Alexandros


Re: Questions about wl_pointer.set_cursor

2020-11-18 Thread Alexandros Frantzis
On Wed, Nov 18, 2020 at 12:10:45PM +0200, Pekka Paalanen wrote:
> On Tue, 17 Nov 2020 17:38:32 +0200
> Alexandros Frantzis  wrote:
> 
> > Hi everyone!
> 
> Hi Alf
> 

Hi Pekka,

> > I have some questions about the expected behavior of
> > wl_pointer.set_cursor:
> > 
> > 1. Is setting the same surface as the cursor for multiple pointers allowed?
> >I don't see anything disallowing this in the spec (but see (2)).
> >If this is allowed, are there any useful scenarios for this?
> 
> If possible, I would like to forbid this in the protocol spec to make
> things more clear and simple.
> 
> If a client has multiple wl_seats, the pointer for each may have a
> different position, hence there is no reason to assume that the cursor
> image should be the same for them all. Therefore it's simple to just
> have a separate wl_surface for each.
> 
> If a client has multiple wl_pointer for the same wl_seat, the client
> may be fighting with itself about what the cursor image should be. It
> is not Wayland's job to referee that fight, so I see no reason to
> even consider it.
> 
> > 2. Is the cursor role for a surface specific to a particular pointer?
> >That is, is the role == "cursor", or role == "cursor-for-pointer-X"
> >(which would implicitly disallow reusing the surface on multiple
> >pointers)?
> 
> Assuming we forbid using a wl_surface simultaneously on multiple
> wl_pointers, this question comes down to whether it is ok to migrate a
> wl_surface from being a cursor for one wl_pointer to another wl_pointer.
> 
> I'm not sure there is any reason to allow the migration, but I'm also
> not sure how to word the spec to that effect.

One way is for the spec to explicitly mention that the role is
"cursor-for-pointer-X" (instead of just "cursor"). This will disallow
any reuse of the surface for any other role, including as a cursor
for other pointers. Anyone who wants to migrate will need to first
unset the surface from the pointer (thus dropping any cursor role),
and set it to another pointer.

> > 
> > 3. When, after an enter event, we set a cursor surface that has a
> >attached buffer from a previous enter, is there any requirement to
> >recommit the buffer? It doesn't seem this is the case from the spec,
> >but Weston doesn't like it if we don't recommit. This is likely a bug,
> >but just making sure.
> 
> This is an interesting question, and it involves a race. Let's assume a
> client does this:
> 
> 1. wl_pointer.set_cursor(surface)
> 2. wl_surface.attach(buffer)
> 3. wl_surface.commit
> 
> If the surface already has content before step 1, but that content is
> incorrect, then if the compositor happens to repaint between steps 1
> and 3, the cursor will show incorrect for a moment. A glitch.
> 
> That glitch does not happen if the order is reversed:
> 
> 1. wl_surface.attach(buffer)
> 2. wl_surface.commit
> 3. wl_pointer.set_cursor(surface)
> 
> However, your question says that this order does not work with Weston.
> I'm not surprised, it seems a little off nowadays to give content to a
> surface before giving it a role. xdg-shell outright forbids that, for
> instance.

A clarification: both the first and second sequences you mention work
with weston, assuming no enter/leave in between. What doesn't work is
the following:

1. Enter
2. wl_surface.attach, wl_surface.commit, wl_pointer.set_cursor (order
doesn't matter for this scenario, glitches aside)
3. Leave
4. Enter
5. wl_pointer.set_cursor(surface_with_already_attached_buffer)

After (5) nothing is displayed for the cursor, where I would expect that
the cursor would use the buffer already attached during (2).

I have tried sway and gnome with an test client and they both exhibit
the expected behavior. I looked a bit more into Weston and have a
potential fix for this, if this behavior is indeed a bug.

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


Questions about wl_pointer.set_cursor

2020-11-17 Thread Alexandros Frantzis
Hi everyone!

I have some questions about the expected behavior of
wl_pointer.set_cursor:

1. Is setting the same surface as the cursor for multiple pointers allowed?
   I don't see anything disallowing this in the spec (but see (2)).
   If this is allowed, are there any useful scenarios for this?

2. Is the cursor role for a surface specific to a particular pointer?
   That is, is the role == "cursor", or role == "cursor-for-pointer-X"
   (which would implicitly disallow reusing the surface on multiple
   pointers)?

3. When, after an enter event, we set a cursor surface that has a
   attached buffer from a previous enter, is there any requirement to
   recommit the buffer? It doesn't seem this is the case from the spec,
   but Weston doesn't like it if we don't recommit. This is likely a bug,
   but just making sure.

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


Re: Upcoming release

2019-01-30 Thread Alexandros Frantzis
On Fri, Jan 25, 2019 at 10:05:47AM -0600, Derek Foreman wrote:
> On 1/18/19 4:20 PM, Derek Foreman wrote:
> > Hi all,
> > 
> > It's been quite some time since our last weston release, and there's
> > been some discussion of getting the next one out in the January to March
> > timeframe (this would be the last release to have an autotools build, btw).
> > 
> > Does anyone have objections to an early February freeze and a March
> > release?  Anyone with large series near completion?
> > 
> > Also, I'd like to float the idea of removing the fbdev backend for this
> > release (or the next).  The bulk of the interesting features target the
> > drm backend, and it feels like fbdev can sometimes be a bit of a pain to
> > update when changes are required elsewhere.  Any strong opinions either way?
> 
> Ok, I've heard no complaints, and we really are overdue...
> 
> There's been some reasonable pushback against dropping fbdev
> immediately, so let's leave that in for this release.
> 
> As to the release schedule, maybe:
> February 1, Alpha
> February 15, Beta
> March 1, RC1
> March 8 as a first potential final release date.
> 
> Is this too soon to enter freeze?  It's not a lot of warning.
> 
> Wayland has had enough changes that I think another joint release makes
> sense.
> 
> Thanks,
> Derek

Hi Derek,

it would be nice if we could also try to get the weston support for the
zwp_linux_explicit_synchronization_unstable_v1 protocol in the next
release, given that the protocol itself has landed since some time now
(wayland-protocols 1.17).

The MR for the explicit sync implementation is at:

https://gitlab.freedesktop.org/wayland/weston/merge_requests/32

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


Re: [PATCH wayland-protocols v7] Add zwp_linux_explicit_synchronization_v1

2018-12-17 Thread Alexandros Frantzis
On Monday, December 17, 2018 12:44 GMT, Tomek Bury  
wrote: 
> On Wed, 28 Nov 2018 at 14:35, Tomek Bury  wrote:
> > Hi Pekka,
> >
> > > I suppose the compositor-side copy of buffers you mentioned is for the
> > > lack of release fences, not acquire fences?
> > Yes, the lack of release fences is the very reason for the copy. I could
> > cook something up for the acquire fence, but that wouldn't synchronise the
> > buffer access anyway. The only way I can be sure the client doesn't
> > overwrite a buffer still in use by the GPU was to texture from a copy and
> > let the compositor release the original without waiting for the GPU and
> > without a fence.
> >
> > Cheers,
> > Tomek
> >
> Hi Pekka, Alexandros,
> 
> Here's a patch containing all I had to do in order to test the explicit
> sync support Alexandros has implemented in Weston.
> 
> Thanks,
> Tomek

Hi Tomek,

I have now updated the weston explicit-sync gitlab MR [1] to support,
among other things, minor version 2 of the protocol. Instead of
completely removing the checks, I have updated them to check for and
accept all non-SHM buffers, which is adequate for current needs. There
are other ways to deal with these checks if we think we need a more
versatile approach (e.g., asking the renderer to tell us if it support fences
for a particular buffer). Please see the MR comments for more info and
discussion.

Thanks,
Alexandros
 
[1] https://gitlab.freedesktop.org/wayland/weston/merge_requests/32

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


[PATCH wayland-protocols 3/3] linux-explicit-synchronization: Clarify implicit synchronization guarantees of release events

2018-11-29 Thread Alexandros Frantzis
Clarify that after zwp_buffer_release_v1 events, otherwise unused
buffers can be reused without any additional implicit synchronization.
This is in contrast to wl_buffer.release, which doesn't guarantee that
implicit synchronization is not required to safely use a buffer after
the event is received.

Signed-off-by: Alexandros Frantzis 
---
 .../linux-explicit-synchronization-unstable-v1.xml | 10 ++
 1 file changed, 10 insertions(+)

diff --git 
a/unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml
 
b/unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml
index 6d5783d..d0a8cf0 100644
--- 
a/unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml
+++ 
b/unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml
@@ -226,6 +226,11 @@
 signaled when all operations by the compositor on that buffer for that
 commit have finished.
 
+Once the fence has signaled, and assuming the associated buffer is not
+pending release from other wl_surface.commit requests, no additional
+explicit or implicit synchronization is required to safely reuse or
+destroy the buffer.
+
 This event destroys the zwp_linux_buffer_release_v1 object.
   
   
@@ -238,6 +243,11 @@
 using it, or has a guarantee that all its operations on that buffer for
 that commit have finished.
 
+Once this event is received, and assuming the associated buffer is not
+pending release from other wl_surface.commit requests, no additional
+explicit or implicit synchronization is required to safely reuse or
+destroy the buffer.
+
 This event destroys the zwp_linux_buffer_release_v1 object.
   
 
-- 
2.19.2

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


[PATCH wayland-protocols 0/3] Updates to linux-explicit-synchronization

2018-11-29 Thread Alexandros Frantzis
A series of assorted updates and clarifications for the
linux-explicit-synchronization protocol.

Alexandros Frantzis (3):
  linux-explicit-synchronization: Allow fences with opaque EGL buffers
  linux-explicit-synchronization: Warn about using the protocol while
using graphics APIs
  linux-explicit-synchronization: Clarify implicit synchronization
guarantees of release events

 ...x-explicit-synchronization-unstable-v1.xml | 29 ---
 1 file changed, 25 insertions(+), 4 deletions(-)

-- 
2.19.2

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


[PATCH wayland-protocols 2/3] linux-explicit-synchronization: Warn about using the protocol while using graphics APIs

2018-11-29 Thread Alexandros Frantzis
Graphics APIs are expected to use this protocol under the hood, and
since there can only be one user of explicit synchronization per
surface, warn about using the protocol directly in such cases.

Signed-off-by: Alexandros Frantzis 
---
 .../linux-explicit-synchronization-unstable-v1.xml  | 6 ++
 1 file changed, 6 insertions(+)

diff --git 
a/unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml
 
b/unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml
index 5809b42..6d5783d 100644
--- 
a/unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml
+++ 
b/unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml
@@ -66,6 +66,12 @@
 
 If the given wl_surface already has an explicit synchronization object
 associated, the synchronization_exists protocol error is raised.
+
+Graphics APIs, like EGL or Vulkan, that manage the buffer queue and
+commits of a wl_surface themselves, are likely to be using this
+extension internally. If a client is using such an API for a
+wl_surface, it should not directly use this extension on that surface,
+to avoid raising a synchronization_exists protocol error.
   
 
   https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH wayland-protocols 1/3] linux-explicit-synchronization: Allow fences with opaque EGL buffers

2018-11-29 Thread Alexandros Frantzis
Add opaque EGL buffers to the supported buffer types for use with the
explicit synchronization protocol. Opaque EGL buffers rely on the same
EGL implementation in both the compositor and clients, which makes it
straightforward to manage client expectations about fence support for
such buffers.

Also make it clearer that implementations are free to support other
buffer types beyond the required ones.

Signed-off-by: Alexandros Frantzis 
---
 .../linux-explicit-synchronization-unstable-v1.xml  | 13 +
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git 
a/unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml
 
b/unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml
index db36284..5809b42 100644
--- 
a/unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml
+++ 
b/unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml
@@ -26,7 +26,7 @@
 DEALINGS IN THE SOFTWARE.
   
 
-  
+  
 
   This global is a factory interface, allowing clients to request
   explicit synchronization for buffers on a per-surface basis.
@@ -76,7 +76,7 @@
 
   
 
-  
+  
 
   This object implements per-surface explicit synchronization.
 
@@ -101,8 +101,13 @@
   Each surface can be associated with only one object of this interface at
   any time.
 
-  Explicit synchronization is guaranteed to be supported only for buffers
-  created with any version of the wp_linux_dmabuf buffer factory.
+  In version 1 of this interface, explicit synchronization is only
+  guaranteed to be supported for buffers created with any version of the
+  wp_linux_dmabuf buffer factory. Version 2 additionally guarantees
+  explicit synchronization support for opaque EGL buffers, which is a type
+  of platform specific buffers described in the EGL_WL_bind_wayland_display
+  extension. Compositors are free to support explicit synchronization for
+  additional buffer types.
 
 
 
-- 
2.19.2

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


Re: [PATCH wayland-protocols v7] Add zwp_linux_explicit_synchronization_v1

2018-11-27 Thread Alexandros Frantzis
On Tue, Nov 27, 2018 at 05:17:40PM +0200, Alexandros Frantzis wrote:
> On Tue, Nov 27, 2018 at 10:53:45AM +0200, Pekka Paalanen wrote:
> > Yes, we probably should have some wording that if a client is letting
> > something like EGL to commit the buffers, it must not attempt to use
> > the fence extension on that wl_surface itself because EGL will probably
> > be using the extension already.
> > 
> > Alf?
> 
> Hi Pekka and Tomek,
> 
> I will send a patch with a proposal for the discussed wording updates to
> the list soon (probably tomorrow).
> 
> I agree it's fine for the spec to be relaxed for the opaque EGL buffers.
> As Pekka mentioned, we explicitly limited the spec to support only
> zwp_linux_dmabuf to avoid the problem of having to deal with unsupported
> buffer/fence combinations, and opaque EGL buffers are not likely to pose
> problems in this regard.

Note that this will require a v2 of this protocol since we will be
requiring more from implementations compared to v1 (unless we can cheat
and not bump?). The current protocol says:

"Explicit synchronization is guaranteed to be supported only for buffers
   
 created with any version of the wp_linux_dmabuf buffer factory."

which upon rereading isn't clear enough about if implementations are
required to support *only* linux_dmabuf, or if implementations need
to support *at least* linux_dmabuf.

If we don't want to commit to general opaque EGL buffer support,
perhaps an option here would be to change this to the more clear:

"Explicit synchronization is only guaranteed to be supported for buffers
   
 created with any version of the wp_linux_dmabuf buffer factory, but
 implementations are free to also support it for other buffer types."

This allows us to stay at v1 without explicitly naming out opaque EGL
buffers, while still allowing Weston to support opaque EGL buffers.

I guess it depends if we think the explicit sync + opaque EGL buffer
case will be interesting enough to be used outside of environments with
a controlled compositor and clients.

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


Re: [PATCH wayland-protocols v7] Add zwp_linux_explicit_synchronization_v1

2018-11-27 Thread Alexandros Frantzis
On Tue, Nov 27, 2018 at 10:53:45AM +0200, Pekka Paalanen wrote:
> Yes, we probably should have some wording that if a client is letting
> something like EGL to commit the buffers, it must not attempt to use
> the fence extension on that wl_surface itself because EGL will probably
> be using the extension already.
> 
> Alf?

Hi Pekka and Tomek,

I will send a patch with a proposal for the discussed wording updates to
the list soon (probably tomorrow).

I agree it's fine for the spec to be relaxed for the opaque EGL buffers.
As Pekka mentioned, we explicitly limited the spec to support only
zwp_linux_dmabuf to avoid the problem of having to deal with unsupported
buffer/fence combinations, and opaque EGL buffers are not likely to pose
problems in this regard.

In practice we can probably support all buffers that can be imported
into the graphics API without requiring a client-side wait in the
compositor ("client" from a graphics API perspective) for proper use,
but that's harder to specify. There were discussions about allowing
everything other than wl_shm, but we decided against it, since that
would make the protocol too fragile.

Relaxing the spec further will probably require more radical changes,
though, e.g., advertising supported buffer types, or similar.

I will also add some notes/warnings about using this protocol with
graphics APIs that handle buffers internally.

This is also a good chance to propose some other clarifications to the
spec I have been thinking about.

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


Re: [PATCH wayland-protocols v7] Add zwp_linux_explicit_synchronization_v1

2018-11-13 Thread Alexandros Frantzis
On Mon, Nov 12, 2018 at 12:39:58PM +, Tomek Bury wrote:
> On Mon, Nov 12, 2018 at 11:15 AM Daniel Stone  wrote:
> 
> > On Fri, 9 Nov 2018 at 10:48, Pekka Paalanen  wrote:
> > > I can add that while pushing upstream, if there are no other changes
> > > coming.
> > >
> > > Reviewed-by: Pekka Paalanen 
> > >
> > > You have ensured that the C files generated from this revision build
> > > fine in Weston, right?
> > >
> > > David, Daniel, since your name is in the maintainers, can I have your
> > > R-b, please?
> >
> > The protocol is:
> > Reviewed-by: Daniel Stone 
> >
> > The Weston implementation looks pretty good so far, though there's no
> > full implementation of release yet.
> >
> > Cheers,
> > Daniel
> > ___
> > wayland-devel mailing list
> > wayland-devel@lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/wayland-devel
> >
> 
> HI Daniel,
> 
> Where can I find the work-in-progress implementation? I'd like to try it
> out with Broadcom driver which doesn't have implicit cross-process sync. I
> can add the explicit sync protocol implementation on the driver side but
> I'd need a reference to test it against.
> 
> Cheers,
> Tomek

Hi Tomek,

the WIP implementation can be found here [1]. I hope to push an update,
including some zwp_buffer_release_v1 correctness fixes, in the following
days.

Thanks,
Alexandros

[1] https://gitlab.freedesktop.org/wayland/weston/merge_requests/32
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


Re: [PATCH wayland-protocols v7] Add zwp_linux_explicit_synchronization_v1

2018-11-12 Thread Alexandros Frantzis
On Fri, Nov 09, 2018 at 04:24:56PM +0200, Alexandros Frantzis wrote:
> On Fri, Nov 09, 2018 at 12:48:09PM +0200, Pekka Paalanen wrote:
> > On Fri,  9 Nov 2018 09:46:36 +0200
> > Alexandros Frantzis  wrote:
> > 
> > > Signed-off-by: Alexandros Frantzis 
> > 
> > Hi Alf,
> 
> Hi Pekka,
> 
> thanks for the review!
> 
> > could you come up with some rationale to put in the commit message on
> > why this extension is being added?
> > 
> > I can add that while pushing upstream, if there are no other changes
> > coming.
> 
> How about:
> 
> This protocol enables explicit synchronization of asynchronous graphics
> operations on buffers on a per-commit basis. Support is currently
> limited to dmabuf buffers and dma_fence fence FDs.
> 
> Explicit synchronization provides a more versatile notification
> mechanism for buffer readiness and availability, and can be used to
> improve efficiency by integrating with related functionality in display
> and graphics APIs.
> 
> Finally, the per-commit nature of the release events provided by this
> protocol offer a solution to a deficiency of the wl_buffer.release event
> (see https://gitlab.freedesktop.org/wayland/wayland/issues/46).

v2 of the text, with some more ChromeOS related information:

This protocol enables explicit synchronization of asynchronous graphics
operations on buffers on a per-commit basis. Support is currently
limited to dmabuf buffers and dma_fence fence FDs.

Explicit synchronization provides a more versatile notification
mechanism for buffer readiness and availability, and can be used to
improve efficiency by integrating with related functionality in display
and graphics APIs.

This protocol is also useful in ChromeOS ARC++ (running Android apps
inside ChromeOS, using Wayland as the communication protocol), where it
can enable integration of the ChromeOS compositor with the explicit
synchronization mechanisms of the Android display subsystem.

Finally, the per-commit nature of the release events provided by this
protocol potentially offers a solution to a deficiency of the
wl_buffer.release event (see
https://gitlab.freedesktop.org/wayland/wayland/issues/46).

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


Re: [PATCH wayland-protocols v7] Add zwp_linux_explicit_synchronization_v1

2018-11-09 Thread Alexandros Frantzis
On Fri, Nov 09, 2018 at 12:48:09PM +0200, Pekka Paalanen wrote:
> On Fri,  9 Nov 2018 09:46:36 +0200
> Alexandros Frantzis  wrote:
> 
> > Signed-off-by: Alexandros Frantzis 
> 
> Hi Alf,

Hi Pekka,

thanks for the review!

> could you come up with some rationale to put in the commit message on
> why this extension is being added?
> 
> I can add that while pushing upstream, if there are no other changes
> coming.

How about:

This protocol enables explicit synchronization of asynchronous graphics
operations on buffers on a per-commit basis. Support is currently
limited to dmabuf buffers and dma_fence fence FDs.

Explicit synchronization provides a more versatile notification
mechanism for buffer readiness and availability, and can be used to
improve efficiency by integrating with related functionality in display
and graphics APIs.

Finally, the per-commit nature of the release events provided by this
protocol offer a solution to a deficiency of the wl_buffer.release event
(see https://gitlab.freedesktop.org/wayland/wayland/issues/46).

> Reviewed-by: Pekka Paalanen 
> 
> You have ensured that the C files generated from this revision build
> fine in Weston, right?

Yes, I have been working locally with this revision in Weston, and
everything builds and runs fine.

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


[PATCH wayland-protocols v7] Add zwp_linux_explicit_synchronization_v1

2018-11-08 Thread Alexandros Frantzis
Signed-off-by: Alexandros Frantzis 
---

Changes in patch v7:
  - Added linux_ prefix to interface names.

Changes in patch v6:
  - Fixed wl_buffer.attach -> wl_surface.attach typos.
  - Added NO_BUFFER error and update request descriptions.
  - Consistently used "error is raised" phrasing.
  - Add comment about buffer_release object destruction in event
descriptions.

Changes in patch v5:
  - Further clarified the per-commit nature of buffer_release.
  - Used the wp_linux_dmabuf name to refer to all versions of that protocol.
  - Fixed wl_buffer.attach typo.
  - Clarified when an INVALID_FENCE error is raised.
  - Improved wording explaining the double-buffer state of buffer_release.
  - Allowed get_release requests on all non-null buffers.
  - Clarified that the compositor is free to select buffer_release events
on a release by release basis.
  - Changed buffer_release to be self-destroyed after it emits an event.

Changes in patch v4:
  - Guaranteed protocol compatibility only with zwp_linux_dmabuf buffers.
  - Added the UNSUPPORTED_BUFFER error.

Changes in patch v3:
  - Reworded implicit/explicit synchronization intro in
zwp_surface_synchronization_v1 description.
  - Removed confusing mention of wl_buffer.release in
zwp_surface_synchronization_v1 description.
  - Clarified which fences are affected on sync object destruction.
  - Removed unclear mention about wl_buffer destruction
in fenced_release description.
  - Clarified that the release events and their guarantees apply to
the relevant commit only.
  - Reformatted text.

Changes in patch v2:
  - Added NO_SURFACE error for zwp_surface_synchronization_v1 requests.
  - Removed restriction to destroy a zwp_surface_synchronization_v1 object
after the associated wl_surface is destroyed.
  - Clarified which buffer the acquire fence is associated with.
  - Clarified that exactly one event, either a fenced_release or a
immediate_release, will be emitted for each commit.

 Makefile.am   |   1 +
 .../linux-explicit-synchronization/README |   6 +
 ...x-explicit-synchronization-unstable-v1.xml | 235 ++
 3 files changed, 242 insertions(+)
 create mode 100644 unstable/linux-explicit-synchronization/README
 create mode 100644 
unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml

diff --git a/Makefile.am b/Makefile.am
index 6394e26..7dfbb9e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -21,6 +21,7 @@ unstable_protocols =  
\
unstable/xdg-output/xdg-output-unstable-v1.xml  
\
unstable/input-timestamps/input-timestamps-unstable-v1.xml  \
unstable/xdg-decoration/xdg-decoration-unstable-v1.xml  \
+   
unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml
 \
$(NULL)
 
 stable_protocols = 
\
diff --git a/unstable/linux-explicit-synchronization/README 
b/unstable/linux-explicit-synchronization/README
new file mode 100644
index 000..f13b404
--- /dev/null
+++ b/unstable/linux-explicit-synchronization/README
@@ -0,0 +1,6 @@
+Linux explicit synchronization (dma-fence) protocol
+
+Maintainers:
+David Reveman 
+Daniel Stone 
+Alexandros Frantzis 
diff --git 
a/unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml
 
b/unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml
new file mode 100644
index 000..db36284
--- /dev/null
+++ 
b/unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml
@@ -0,0 +1,235 @@
+
+
+
+  
+Copyright 2016 The Chromium Authors.
+Copyright 2017 Intel Corporation
+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 OT

Re: [PATCH wayland-protocols v6] Add zwp_linux_explicit_synchronization_v1

2018-11-08 Thread Alexandros Frantzis
On Thu, Nov 08, 2018 at 05:43:42PM +0200, Pekka Paalanen wrote:
> On Thu, 8 Nov 2018 16:34:52 +0200
> Alexandros Frantzis  wrote:
> 
> > On Thu, Nov 08, 2018 at 03:00:58PM +0200, Pekka Paalanen wrote:
> > > On Wed, 07 Nov 2018 20:22:38 +
> > > Simon Ser  wrote:
> > >   
> > > > Thanks! With these fixes, this is now
> > > > 
> > > > Reviewed-by: Simon Ser 
> > > > 
> > > > Below is a small comment, I don't know if it's relevant or not, I just 
> > > > wanted to
> > > > point it out.
> > > >   
> > 
> > ...
> > 
> > > > > +  
> > > > 
> > > > I missed this before, but: is there a reason why the "linux" prefix has 
> > > > been
> > > > dropped here? Maybe it should be renamed to
> > > > zwp_linux_surface_synchronization_v1? What about zwp_buffer_release_v1? 
> > > >  
> > > 
> > > That's a good question, because these names are kind of global. Not
> > > really global, but it could cause some name conflicts if the same
> > > program or a compilation unit needed to use two different but
> > > same-named interfaces. They are less global than the same of the global
> > > interface though, which needs to be unique per platform for real.
> > > 
> > > The stable names would be wp_surface_synchronization and
> > > wp_buffer_release, with the root interface being
> > > wp_linux_explicit_synchronization.
> > > 
> > > The dmabuf extension relies of the Linux definition of a dmabuf. This
> > > extension relies on the Linux definition of a fence, AFAIU.
> > > 
> > > So yes, I think repeating "linux" in the interface names would be
> > > appropriate.  
> > 
> > Hi Pekka and Simon,
> > 
> > adding the linux_ prefix is reasonable (and means we could be winning at
> > the longest interface name competition :)).
> > 
> > This got me thinking (also see Daniel's email), though, if there would
> > be benefit in moving in the other direction: making this protocol
> > agnostic of the fence type details. So, instead of
> > "zwp_linux_explicit_synchronization_v1" we will have
> > "zwp_explicit_synchronization_v1" with the passed fd being an opaque fd
> > from a protocol perspective.
> > 
> > Of course, this reintroduces the problem of how the client can figure
> > out what kind of buffer/fence combinations the server can accept, which
> > we have resolved here by limiting this protocol to dmabuf/dma_fences.
> > One way would be to allow per-platform protocols that just advertise
> > supported combinations, e.g., having
> > "zwp_linux_explicit_synchronization_v1" just means that the
> > dmabuf/dmafence combo is supported for zwp_explicit_synchronization
> > operations.
> > 
> > Finally, if we think an opaque fd may be limiting, there are other
> > options to explore (e.g., a zwp_fence interface with factories in
> > per-platform extensions).
> 
> Hi Alf,
> 
> I'd keep it simple. Leave out other fence types until we have a use
> case. It's still an unstable protocol, and we can see if other types
> appear by the time people want to declare it stable.
> 
> An opaque fd is kind of useless. If the spec does not say what it is,
> how could a compositor or a client do anything with it?

...

The idea is to have something akin to how the EGL_KHR_image_base and
EGL_KHR_image_* extensions are structured.

So, the base protocol, wp_explicit_synchronization, would just define
the operations but not any acceptable fence types. Then we could have
platform-specific protocols like
wp_{linux,dmafence,syncobj...}_explicit_synchronization, which would
just state what the acceptable fence types are, and possibly which
buffer types these fences can be associated with. Their presence would
let the client know how to create the fence. In order to have a usable
implementation, the server will need to expose at least one of these
platform-specific protocols.

As for the server detecting the fence fd type internally, in case
multiple fence types are supported, we can express this in terms of
checking for fence validity, which we already need in order to support
the INVALID_FENCE error.

Even if this is overkill for now, I think it's a viable design to keep
in mind if in the future we need to support multiple fence types.

> For simplicity, I'd go with "linux" in the name and the explicit
> connection with linux_dmabuf buffers.

Fine with me.

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


Re: [PATCH wayland-protocols v6] Add zwp_linux_explicit_synchronization_v1

2018-11-08 Thread Alexandros Frantzis
On Thu, Nov 08, 2018 at 03:00:58PM +0200, Pekka Paalanen wrote:
> On Wed, 07 Nov 2018 20:22:38 +
> Simon Ser  wrote:
> 
> > Thanks! With these fixes, this is now
> > 
> > Reviewed-by: Simon Ser 
> > 
> > Below is a small comment, I don't know if it's relevant or not, I just 
> > wanted to
> > point it out.
> > 

...

> > > +
> > 
> > I missed this before, but: is there a reason why the "linux" prefix has been
> > dropped here? Maybe it should be renamed to
> > zwp_linux_surface_synchronization_v1? What about zwp_buffer_release_v1?
> 
> That's a good question, because these names are kind of global. Not
> really global, but it could cause some name conflicts if the same
> program or a compilation unit needed to use two different but
> same-named interfaces. They are less global than the same of the global
> interface though, which needs to be unique per platform for real.
> 
> The stable names would be wp_surface_synchronization and
> wp_buffer_release, with the root interface being
> wp_linux_explicit_synchronization.
> 
> The dmabuf extension relies of the Linux definition of a dmabuf. This
> extension relies on the Linux definition of a fence, AFAIU.
> 
> So yes, I think repeating "linux" in the interface names would be
> appropriate.

Hi Pekka and Simon,

adding the linux_ prefix is reasonable (and means we could be winning at
the longest interface name competition :)).

This got me thinking (also see Daniel's email), though, if there would
be benefit in moving in the other direction: making this protocol
agnostic of the fence type details. So, instead of
"zwp_linux_explicit_synchronization_v1" we will have
"zwp_explicit_synchronization_v1" with the passed fd being an opaque fd
from a protocol perspective.

Of course, this reintroduces the problem of how the client can figure
out what kind of buffer/fence combinations the server can accept, which
we have resolved here by limiting this protocol to dmabuf/dma_fences.
One way would be to allow per-platform protocols that just advertise
supported combinations, e.g., having
"zwp_linux_explicit_synchronization_v1" just means that the
dmabuf/dmafence combo is supported for zwp_explicit_synchronization
operations.

Finally, if we think an opaque fd may be limiting, there are other
options to explore (e.g., a zwp_fence interface with factories in
per-platform extensions).

Thoughts?

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


[PATCH wayland-protocols v6] Add zwp_linux_explicit_synchronization_v1

2018-11-07 Thread Alexandros Frantzis
Signed-off-by: Alexandros Frantzis 
---

Changes in patch v6:
  - Fixed wl_buffer.attach -> wl_surface.attach typos.
  - Added NO_BUFFER error and updated request descriptions.
  - Consistently used "error is raised" phrasing.
  - Added comment about buffer_release object destruction in event
descriptions.

Changes in patch v5:
  - Further clarified the per-commit nature of buffer_release.
  - Used the wp_linux_dmabuf name to refer to all versions of that protocol.
  - Fixed wl_buffer.attach typo.
  - Clarified when an INVALID_FENCE error is raised.
  - Improved wording explaining the double-buffer state of buffer_release.
  - Allowed get_release requests on all non-null buffers.
  - Clarified that the compositor is free to select buffer_release events
on a release by release basis.
  - Changed buffer_release to be self-destroyed after it emits an event.

Changes in patch v4:
  - Guaranteed protocol compatibility only with zwp_linux_dmabuf buffers.
  - Added the UNSUPPORTED_BUFFER error.

Changes in patch v3:
  - Reworded implicit/explicit synchronization intro in
zwp_surface_synchronization_v1 description.
  - Removed confusing mention of wl_buffer.release in
zwp_surface_synchronization_v1 description.
  - Clarified which fences are affected on sync object destruction.
  - Removed unclear mention about wl_buffer destruction
in fenced_release description.
  - Clarified that the release events and their guarantees apply to
the relevant commit only.
  - Reformatted text.

Changes in patch v2:
  - Added NO_SURFACE error for zwp_surface_synchronization_v1 requests.
  - Removed restriction to destroy a zwp_surface_synchronization_v1 object
after the associated wl_surface is destroyed.
  - Clarified which buffer the acquire fence is associated with.
  - Clarified that exactly one event, either a fenced_release or a
immediate_release, will be emitted for each commit.

 Makefile.am   |   1 +
 .../linux-explicit-synchronization/README |   6 +
 ...x-explicit-synchronization-unstable-v1.xml | 234 ++
 3 files changed, 241 insertions(+)
 create mode 100644 unstable/linux-explicit-synchronization/README
 create mode 100644 
unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml

diff --git a/Makefile.am b/Makefile.am
index 6394e26..7dfbb9e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -21,6 +21,7 @@ unstable_protocols =  
\
unstable/xdg-output/xdg-output-unstable-v1.xml  
\
unstable/input-timestamps/input-timestamps-unstable-v1.xml  \
unstable/xdg-decoration/xdg-decoration-unstable-v1.xml  \
+   
unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml
 \
$(NULL)
 
 stable_protocols = 
\
diff --git a/unstable/linux-explicit-synchronization/README 
b/unstable/linux-explicit-synchronization/README
new file mode 100644
index 000..f13b404
--- /dev/null
+++ b/unstable/linux-explicit-synchronization/README
@@ -0,0 +1,6 @@
+Linux explicit synchronization (dma-fence) protocol
+
+Maintainers:
+David Reveman 
+Daniel Stone 
+Alexandros Frantzis 
diff --git 
a/unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml
 
b/unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml
new file mode 100644
index 000..b87663f
--- /dev/null
+++ 
b/unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml
@@ -0,0 +1,234 @@
+
+
+
+  
+Copyright 2016 The Chromium Authors.
+Copyright 2017 Intel Corporation
+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.
+  
+
+  
+
+  This global

[PATCH wayland-protocols v5] Add zwp_linux_explicit_synchronization_v1

2018-11-06 Thread Alexandros Frantzis
Signed-off-by: Alexandros Frantzis 
---

Changes in patch v5:
  - Further clarified the per-commit nature of buffer_release.
  - Used the wp_linux_dmabuf name to refer to all versions of that protocol.
  - Fixed wl_buffer.attach typo.
  - Clarified when an INVALID_FENCE error is raised.
  - Improved wording explaining the double-buffer state of buffer_release.
  - Allowed get_release requests on all non-null buffers.
  - Clarified that the compositor is free to select buffer_release events
on a release by release basis.
  - Changed buffer_release to be self-destroyed after it emits an event.

Changes in patch v4:
  - Guaranteed protocol compatibility only with zwp_linux_dmabuf buffers.
  - Added the UNSUPPORTED_BUFFER error.

Changes in patch v3:
  - Reworded implicit/explicit synchronization intro in
zwp_surface_synchronization_v1 description.
  - Removed confusing mention of wl_buffer.release in
zwp_surface_synchronization_v1 description.
  - Clarified which fences are affected on sync object destruction.
  - Removed unclear mention about wl_buffer destruction
in fenced_release description.
  - Clarified that the release events and their guarantees apply to
the relevant commit only.
  - Reformatted text.

Changes in patch v2:
  - Added NO_SURFACE error for zwp_surface_synchronization_v1 requests.
  - Removed restriction to destroy a zwp_surface_synchronization_v1 object
after the associated wl_surface is destroyed.
  - Clarified which buffer the acquire fence is associated with.
  - Clarified that exactly one event, either a fenced_release or a
immediate_release, will be emitted for each commit.

 Makefile.am   |   1 +
 .../linux-explicit-synchronization/README |   6 +
 ...x-explicit-synchronization-unstable-v1.xml | 226 ++
 3 files changed, 233 insertions(+)
 create mode 100644 unstable/linux-explicit-synchronization/README
 create mode 100644 
unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml

diff --git a/Makefile.am b/Makefile.am
index 6394e26..7dfbb9e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -21,6 +21,7 @@ unstable_protocols =  
\
unstable/xdg-output/xdg-output-unstable-v1.xml  
\
unstable/input-timestamps/input-timestamps-unstable-v1.xml  \
unstable/xdg-decoration/xdg-decoration-unstable-v1.xml  \
+   
unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml
 \
$(NULL)
 
 stable_protocols = 
\
diff --git a/unstable/linux-explicit-synchronization/README 
b/unstable/linux-explicit-synchronization/README
new file mode 100644
index 000..f13b404
--- /dev/null
+++ b/unstable/linux-explicit-synchronization/README
@@ -0,0 +1,6 @@
+Linux explicit synchronization (dma-fence) protocol
+
+Maintainers:
+David Reveman 
+Daniel Stone 
+Alexandros Frantzis 
diff --git 
a/unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml
 
b/unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml
new file mode 100644
index 000..834f2e0
--- /dev/null
+++ 
b/unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml
@@ -0,0 +1,226 @@
+
+
+
+  
+Copyright 2016 The Chromium Authors.
+Copyright 2017 Intel Corporation
+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.
+  
+
+  
+
+  This global is a factory interface, allowing clients to request
+  explicit synchronization for buffers on a per-surface basis.
+
+  See zwp_surface_synchronization_v1 for more information.
+
+  This interface is derived from Chromium's
+  zcr_linux_explicit_synchronization_

Re: [PATCH wayland-protocols v4] Add zwp_linux_explicit_synchronization_v1

2018-11-06 Thread Alexandros Frantzis
On Mon, Nov 05, 2018 at 06:07:56PM +, Simon Ser wrote:
> On Monday, November 5, 2018 10:50 AM, Alexandros Frantzis 
>  wrote:
> > On Sat, Nov 03, 2018 at 02:44:53PM +, Simon Ser wrote:
> >
> > Hi Simon,
> >
> > > > > > +  Explicit synchronization is guaranteed to be supported only 
> > > > > > for buffers
> > > > > > +  created with any version of the zwp_linux_dmabuf buffer 
> > > > > > factory.
> > > > >
> > > > > I think we can drop the "z" prefix here.
> > > >
> > > > Hmm, not sure about this. We would be using a protocol prefix/name
> > > > combination that doesn't exist (yet). Of course the intention is clear,
> > > > but I think it would be better to update this to, e.g.,
> > > > (z)wp_linux_dmabuf, when linux_dmabuf actually becomes stable.
> > >
> > > Then add the v1 suffix zwp_linux_dmabuf_v1?
> >
> > The "any version" of zwp_linux_dmabuf was meant to cover both _v* and
> > version="*", but I guess that's not clear enough. Perhaps "with any
> > version of zwp_linux_dmabuf_v*"? In any case, I am also fine with just
> > adding _v1 for now and updating as needed in the future.
> 
> It's not uncommon to refer to the not-yet-existing stable versions of the
> protocols in their unstable versions.

Since there are precedents in the repo of using the not-yet-existing
stable name, and as long as it's clear that this is a general reference
to all unstable and stable versions, I will go with that.

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


Re: [PATCH wayland-protocols v4] Add zwp_linux_explicit_synchronization_v1

2018-11-05 Thread Alexandros Frantzis
On Sat, Nov 03, 2018 at 02:44:53PM +, Simon Ser wrote:

Hi Simon,

> > > > +  Explicit synchronization is guaranteed to be supported only for 
> > > > buffers
> > > > +  created with any version of the zwp_linux_dmabuf buffer factory.
> > >
> > > I think we can drop the "z" prefix here.
> >
> > Hmm, not sure about this. We would be using a protocol prefix/name
> > combination that doesn't exist (yet). Of course the intention is clear,
> > but I think it would be better to update this to, e.g.,
> > (z)wp_linux_dmabuf, when linux_dmabuf actually becomes stable.
> 
> Then add the v1 suffix zwp_linux_dmabuf_v1?

The "any version" of zwp_linux_dmabuf was meant to cover both _v* and
version="*", but I guess that's not clear enough. Perhaps "with any
version of zwp_linux_dmabuf_v*"? In any case, I am also fine with just
adding _v1 for now and updating as needed in the future.

> > > > +
> > > > +  
> > > > +Sent when the compositor has finalised its usage of the 
> > > > associated
> > > > +buffer for the relevant commit, providing a dma_fence which 
> > > > will be
> > > > +signaled when all operations by the compositor on that buffer 
> > > > for that
> > > > +commit have finished.
> > > > +
> > > > +Clients must not perform any destructive operations (e.g. 
> > > > clearing or
> > > > +rendering) on the buffer until that fence has signaled.
> > >
> > > We should probably add to this request and to immediate_release something 
> > > among
> > > the lines of:
> > >
> > > > Upon receiving this event, the client should destroy this object.
> >
> > In v5 I am changing zwp_buffer_release to use destroy-on-event, so this
> > doesn't apply any more. Of course, the client should still destroy the
> > proxy, but I don't think this is something we need to explicitly state.
> 
> Hmm. One should be careful when choosing destroy-on-event, it makes it
> impossible to add requests to the interface later on.

We discussed a bit about this in an earlier email, and the conclusion
was that buffer_release is expected to remain a pure event interface.
It's not expected to gain any requests, or to be used as an argument to
other requests. Of course, if people have any such use cases in mind I
would be happy to hear about them and discuss further.

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


Re: [PATCH wayland-protocols v4] Add zwp_linux_explicit_synchronization_v1

2018-11-02 Thread Alexandros Frantzis
On Thu, Nov 01, 2018 at 10:10:40PM +, Simon Ser wrote:
> Hi Alexandros,
> 
> Here are a few comments about someone who doesn't know a lot about
> explicit synchronization. Let me know if I got something wrong. :)
> 
> Overall this looks pretty good.

Hi Simon,

thanks for the review. My comments are below. I agree with everything I
have left out.

> > +  Explicit synchronization is guaranteed to be supported only for 
> > buffers  
> > +  created with any version of the zwp_linux_dmabuf buffer factory. 
>
> I think we can drop the "z" prefix here. 

Hmm, not sure about this. We would be using a protocol prefix/name
combination that doesn't exist (yet). Of course the intention is clear,
but I think it would be better to update this to, e.g.,
(z)wp_linux_dmabuf, when linux_dmabuf actually becomes stable.

> > +is a dma_fence kernel object.
> > +
> > +The acquire fence is double-buffered state, and will be applied on 
> > the
> > +next wl_surface.commit request for the associated surface. Thus, it
> > +applies only to the buffer that is attached to the surface at 
> > commit
> > +time.
> > +
> > +If the fence could not be imported, an INVALID_FENCE error is 
> > raised.
> 
> I wonder if failures to import a fence should really be protocol errors.
> Protocol errors are meant to be used for protocol violations. I understand 
> that
> a client can send an invalid fence, but are there other reasons why a fence
> cannot be imported? Maybe we could change this to "if the file descriptor 
> isn't
> a dma_fence"?

Yes, the this is all about having a valid fence (and that's how it's
implemented in the WIP branch). Requiring something more from this
request would be asking too much, both from the server and the client. I
will rephrase.

It's unlikely that we won't be able to use valid fence at a later point.
If this happens it's most likely a driver issue (or we have messed up in
weston), in which case I think disconnecting the client is a valid
option (compared to allowing bad data on screen), but that's a different
case and error. 

> > +
> > +  
> > +Create a listener for the release of the buffer attached by the
> > +client with wl_buffer.attach. See zwp_buffer_release_v1
> > +documentation for more information.
> > +
> > +The release object is double-buffered state, and will be applied
> > +on the next wl_surface.commit request for the associated surface.
> 
> "will be applied" is a little bit strange for this request. Maybe change to
> "will provide release information about the next wl_surface.commit request"?

"will be applied" tries to convey that the release will be associated
with the buffer that is attached at commit time (instead of any
intermediate attachments).

So, perhaps "will be associated with the buffer that is attached to the
surface at wl_surface.commit time"?

> > +  
> > +
> > +  This object is instantiated in response to a
> > +  zwp_surface_synchronization_v1.get_release request.
> > +
> > +  It provides an alternative to wl_buffer.release events, providing a 
> > unique
> > +  release from a single wl_surface.commit request. The release event 
> > also
> > +  supports explicit synchronization, providing a fence FD where 
> > relevant for
> > +  the client to synchronize against before reusing the buffer.
> > +
> > +  Exactly one event, either a fenced_release or an immediate_release, 
> > will
> > +  be emitted for each wl_surface.commit request.
> 
> This makes it sound like this object can be used for multiple commits. Maybe 
> we
> can change the wording to "will be emitted after the wl_surface.commit 
> request".

Perhaps "will be emitted for the wl_surface.commit request", instead? My
concern is that "after" may be misread as the commit immediately
triggering an event (which, to be fair, doesn't make sense in this
context).

> > +
> > +  
> > +Sent when the compositor has finalised its usage of the associated
> > +buffer for the relevant commit, providing a dma_fence which will be
> > +signaled when all operations by the compositor on that buffer for 
> > that
> > +commit have finished.
> > +
> > +Clients must not perform any destructive operations (e.g. clearing 
> > or
> > +rendering) on the buffer until that fence has signaled.
> 
> We should probably add to this request and to immediate_release something 
> among
> the lines of:
> 
> > Upon receiving this event, the client should destroy this object.

In v5 I am changing zwp_buffer_release to use destroy-on-event, so this
doesn't apply any more. Of course, the client should still destroy the
proxy, but I don't think this is something we need to explicitly state.

Thanks,
Alexandros
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org

Re: [PATCH wayland-protocols v2] Add zwp_linux_explicit_synchronization_v1

2018-10-31 Thread Alexandros Frantzis
On Wed, Oct 31, 2018 at 11:59:34AM +0200, Pekka Paalanen wrote:
> On Mon, 15 Oct 2018 17:16:59 +0300
> Alexandros Frantzis  wrote:

...

> > 
> > The main scenario is an early exit from some code using this
> > object, in which case it will be easier to correctly synchronize proper
> > destruction of any user data used by the zwp_buffer_release_v1 listener,
> > when having an explicit destroy request.
> > 
> > This isn't particular to this protocol though, it's a general
> > (theoretical) concern of mine with the destroy-on-event pattern.  But if
> > this has worked well for wp_presentation_feedback, perhaps it's not a big
> > deal.
> 
> Hi Alf,
> 
> I'm not sure what you mean with that concern.
> 
> When an event destroys a protocol object, the compositor will
> unconditionally destroy the wl_resource right after sending the event.
> That means the server-side request listener cannot receive any messages
> anymore, so any user data would be destroyed at the same time anyway.
> 
> On client side, regardless of whether there is destroy request or not,
> the client will destroy the wl_proxy. The request would only let the
> compositor know that the protocol object is no more. Regardless of a
> destroy request, the client side will automatically ignore any events
> to the destroyed wl_proxy. That ignoring is what makes client initiated
> object destruction safe in the first place.
> 
> When the client destroys the wl_proxy, it can also free any user data
> associated with it, because that will guarantee that the listeners
> cannot be called anymore.
> 
> If we have a destructor event, and the client destroys the wl_proxy
> before that event is sent, then the event will simply be ignored. Once
> the compositor sends the event, then both client and compositor again
> agree that the protocol object no longer exists.
> 
> wl_display has a "secret" event that tells libwayland-client when the
> server has destroyed the protocol object, which makes all the above
> work.
> 
> 
> Thanks,
> pq

Hi Pekka,

thanks for the detailed explanation. I was misunderstanding how
destroy-on-event is expected to work.

I'll update the protocol to use destroy-on-event in v5.

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


[PATCH wayland-protocols v4] Add zwp_linux_explicit_synchronization_v1

2018-10-18 Thread Alexandros Frantzis
Signed-off-by: Alexandros Frantzis 
---

Changes in patch v4:
  - Guarantee protocol compatibility only with zwp_linux_dmabuf buffers.
  - Add the UNSUPPORTED_BUFFER error.

Changes in patch v3:
  - Reworded implicit/explicit synchronization intro in
zwp_surface_synchronization_v1 description.
  - Removed confusing mention of wl_buffer.release in
zwp_surface_synchronization_v1 description.
  - Clarified which fences are affected on sync object destruction.
  - Removed unclear mention about wl_buffer destruction
in fenced_release description.
  - Clarified that the release events and their guarantees apply to
the relevant commit only.
  - Reformatted text.

Changes in patch v2:
  - Added NO_SURFACE error for zwp_surface_synchronization_v1 requests.
  - Removed restriction to destroy a zwp_surface_synchronization_v1 object
after the associated wl_surface is destroyed.
  - Clarified which buffer the acquire fence is associated with.
  - Clarified that exactly one event, either a fenced_release or a
immediate_release, will be emitted for each commit.

patch v1 here: https://patchwork.freedesktop.org/patch/177866/

 Makefile.am   |   1 +
 .../linux-explicit-synchronization/README |   6 +
 ...x-explicit-synchronization-unstable-v1.xml | 232 ++
 3 files changed, 239 insertions(+)
 create mode 100644 unstable/linux-explicit-synchronization/README
 create mode 100644 
unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml

diff --git a/Makefile.am b/Makefile.am
index 6394e26..7dfbb9e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -21,6 +21,7 @@ unstable_protocols =  
\
unstable/xdg-output/xdg-output-unstable-v1.xml  
\
unstable/input-timestamps/input-timestamps-unstable-v1.xml  \
unstable/xdg-decoration/xdg-decoration-unstable-v1.xml  \
+   
unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml
 \
$(NULL)
 
 stable_protocols = 
\
diff --git a/unstable/linux-explicit-synchronization/README 
b/unstable/linux-explicit-synchronization/README
new file mode 100644
index 000..f13b404
--- /dev/null
+++ b/unstable/linux-explicit-synchronization/README
@@ -0,0 +1,6 @@
+Linux explicit synchronization (dma-fence) protocol
+
+Maintainers:
+David Reveman 
+Daniel Stone 
+Alexandros Frantzis 
diff --git 
a/unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml
 
b/unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml
new file mode 100644
index 000..4800756
--- /dev/null
+++ 
b/unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml
@@ -0,0 +1,232 @@
+
+
+
+  
+Copyright 2016 The Chromium Authors.
+Copyright 2017 Intel Corporation
+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.
+  
+
+  
+
+  This global is a factory interface, allowing clients to request
+  explicit synchronization for buffers on a per-surface basis.
+
+  See zwp_surface_synchronization_v1 for more information.
+
+  This interface is derived from Chromium's
+  zcr_linux_explicit_synchronization_v1.
+
+  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

Re: [PATCH wayland-protocols v2] Add zwp_linux_explicit_synchronization_v1

2018-10-15 Thread Alexandros Frantzis
On Fri, Oct 12, 2018 at 03:24:30PM +0300, Pekka Paalanen wrote:
> Hi,
> 
> this is a good specification, all my comments are clarifications or
> minor adjustments. The fundamental design looks fine to me.

Hi Pekka,

thanks for the review! My answers are inline. I have sent a updated
version (v3) of this proposal based on this discussion.

> On Tue,  9 Oct 2018 18:11:22 +0300
> Alexandros Frantzis  wrote:
> 
> > Signed-off-by: Alexandros Frantzis 
> > ---
> > 
> > patch v1 here: https://patchwork.freedesktop.org/patch/177866/
> > Changes since patch v1:
> >   - Add NO_SURFACE error for zwp_surface_synchronization_v1 requests.
> >   - Remove restriction to destroy a zwp_surface_synchronization_v1 object
> > after the associated wl_surface is destroyed.
> >   - Clarify which buffer the acquire fence is associated with.
> >   - Clarify that exactly one event, either a fenced_release or a
> > immediate_release, will be emitted for each commit.
> > 
> >  Makefile.am   |   1 +
> >  .../linux-explicit-synchronization/README |   6 +
> >  ...x-explicit-synchronization-unstable-v1.xml | 222 ++
> >  3 files changed, 229 insertions(+)
> >  create mode 100644 unstable/linux-explicit-synchronization/README
> >  create mode 100644 
> > unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml



> > +  
> > +
> > +  This object implements per-surface explicit synchronization.
> > +
> > +  Explicit synchronization refers to co-ordination of pipelined
> 
> Strike "Explicit"? It's odd because this starts with "explicit
> synchronization refers to..." and then ends saying this is "implicit
> synchronization.

See below.

> > +  operations performed on buffers. Most GPU clients will schedule
> > +  an asynchronous operation to render to the buffer, then immediately
> > +  send the buffer to the compositor to be attached to a surface.
> 
> Should there be a paragraph break here?

See below.

> > +  Ensuring that the rendering operation is complete before the
> > +  compositor displays the buffer is an implementation detail handled
> > +  by either the kernel or userspace graphics driver. This is referred
> > +  to as 'implicit synchronization'.
> > +
> > +  By contrast, explicit synchronization takes dma_fence objects as a
> > +  marker of when the asynchronous operations are complete. The fence
> > +  provided by the client will be waited on before the compositor
> > +  accesses the buffer. Conversely, in place of wl_buffer.release
> > +  events, the Wayland server will inform the client when the buffer
> > +  can be destructively accessed through a zwp_buffer_release_v1
> > +  object.
> 
> So this guarantees that no more wl_buffer.release events can be triggered
> by commits that used explicit sync?

See below.

> > +
> > +  This interface cannot be instantiated multiple times for a single
> > +  surface, and as such should only be used by the component which
> > +  performs the wl_surface.attach request. Whenever control of
> 
> > +  buffer attachments is released, the releasing component should
> > +  ensure it destroys the zwp_surface_synchronization_v1 object.
> 
> Is the last sentence necessary? It might confuse things as it can
> easily be read as if zwp_surface_synchronization_v1 was a one-shot
> thing.

Ack on all of the above. In v3 I have reworded a big part of this
section, taking into account the points you brought up.

> > +
> > +
> > +
> > +  
> > +Destroy this explicit synchronization object.
> > +
> > +Any fence set with set_acquire_fence in this commit cycle will
> > +be invalidated in the server.
> 
> This means that if zwp_surface_synchronization_v1 object is
> destroyed before issuing wl_surface.commit, then the pending acquire
> fence is discarded by the server, right?

Yes, reworded to make this more clear.

> > +
> > +zwp_buffer_release_v1 objects created by this object are not 
> > affected
> > +by this request.
> 
> And after wl_surface.commit, destruction has no effect on the commit.
> 

I have clarified this in the previous paragraph about set_acquire_fence. 

> > +  
> > +
> > +
> > +
> > +   > + summary="the fence specified by the client could not be 
> > imported"/>
> > +   > + summary="multiple fences added

[PATCH wayland-protocols v3] Add zwp_linux_explicit_synchronization_v1

2018-10-15 Thread Alexandros Frantzis
Signed-off-by: Alexandros Frantzis 
---

Changes in patch v3:
  - Reworded implicit/explicit synchronization intro in
zwp_surface_synchronization_v1 description.
  - Removed confusing mention of wl_buffer.release in
zwp_surface_synchronization_v1 description.
  - Clarified which fences are affected on sync object destruction.
  - Removed unclear mention about wl_buffer destruction
in fenced_release description.
  - Clarified that the release events and their guarantees apply to
the relevant commit only.
  - Reformatted text.

Changes in patch v2:
  - Added NO_SURFACE error for zwp_surface_synchronization_v1 requests.
  - Removed restriction to destroy a zwp_surface_synchronization_v1 object
after the associated wl_surface is destroyed.
  - Clarified which buffer the acquire fence is associated with.
  - Clarified that exactly one event, either a fenced_release or a
immediate_release, will be emitted for each commit.

patch v1 here: https://patchwork.freedesktop.org/patch/177866/

 Makefile.am   |   1 +
 .../linux-explicit-synchronization/README |   6 +
 ...x-explicit-synchronization-unstable-v1.xml | 219 ++
 3 files changed, 226 insertions(+)
 create mode 100644 unstable/linux-explicit-synchronization/README
 create mode 100644 
unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml

diff --git a/Makefile.am b/Makefile.am
index 6394e26..7dfbb9e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -21,6 +21,7 @@ unstable_protocols =  
\
unstable/xdg-output/xdg-output-unstable-v1.xml  
\
unstable/input-timestamps/input-timestamps-unstable-v1.xml  \
unstable/xdg-decoration/xdg-decoration-unstable-v1.xml  \
+   
unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml
 \
$(NULL)
 
 stable_protocols = 
\
diff --git a/unstable/linux-explicit-synchronization/README 
b/unstable/linux-explicit-synchronization/README
new file mode 100644
index 000..f13b404
--- /dev/null
+++ b/unstable/linux-explicit-synchronization/README
@@ -0,0 +1,6 @@
+Linux explicit synchronization (dma-fence) protocol
+
+Maintainers:
+David Reveman 
+Daniel Stone 
+Alexandros Frantzis 
diff --git 
a/unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml
 
b/unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml
new file mode 100644
index 000..c2f44a9
--- /dev/null
+++ 
b/unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml
@@ -0,0 +1,219 @@
+
+
+
+  
+Copyright 2016 The Chromium Authors.
+Copyright 2017 Intel Corporation
+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.
+  
+
+  
+
+  This global is a factory interface, allowing clients to request
+  explicit synchronization for buffers on a per-surface basis.
+
+  See zwp_surface_synchronization_v1 for more information.
+
+  This interface is derived from Chromium's
+  zcr_linux_explicit_synchronization_v1.
+
+  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.
+
+
+
+  
+Destroy this explicit syn

[PATCH wayland-protocols v2] Add zwp_linux_explicit_synchronization_v1

2018-10-09 Thread Alexandros Frantzis
Signed-off-by: Alexandros Frantzis 
---

patch v1 here: https://patchwork.freedesktop.org/patch/177866/
Changes since patch v1:
  - Add NO_SURFACE error for zwp_surface_synchronization_v1 requests.
  - Remove restriction to destroy a zwp_surface_synchronization_v1 object
after the associated wl_surface is destroyed.
  - Clarify which buffer the acquire fence is associated with.
  - Clarify that exactly one event, either a fenced_release or a
immediate_release, will be emitted for each commit.

 Makefile.am   |   1 +
 .../linux-explicit-synchronization/README |   6 +
 ...x-explicit-synchronization-unstable-v1.xml | 222 ++
 3 files changed, 229 insertions(+)
 create mode 100644 unstable/linux-explicit-synchronization/README
 create mode 100644 
unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml

diff --git a/Makefile.am b/Makefile.am
index 6394e26..7dfbb9e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -21,6 +21,7 @@ unstable_protocols =  
\
unstable/xdg-output/xdg-output-unstable-v1.xml  
\
unstable/input-timestamps/input-timestamps-unstable-v1.xml  \
unstable/xdg-decoration/xdg-decoration-unstable-v1.xml  \
+   
unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml
 \
$(NULL)
 
 stable_protocols = 
\
diff --git a/unstable/linux-explicit-synchronization/README 
b/unstable/linux-explicit-synchronization/README
new file mode 100644
index 000..f13b404
--- /dev/null
+++ b/unstable/linux-explicit-synchronization/README
@@ -0,0 +1,6 @@
+Linux explicit synchronization (dma-fence) protocol
+
+Maintainers:
+David Reveman 
+Daniel Stone 
+Alexandros Frantzis 
diff --git 
a/unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml
 
b/unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml
new file mode 100644
index 000..11ef3f0
--- /dev/null
+++ 
b/unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml
@@ -0,0 +1,222 @@
+
+
+
+  
+Copyright 2016 The Chromium Authors.
+Copyright 2017 Intel Corporation
+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.
+  
+
+  
+
+  This global is a factory interface, allowing clients to request
+  explicit synchronization for buffers on a per-surface basis.
+
+  See zwp_surface_synchronization_v1 for more information.
+
+  This interface is derived from Chromium's
+  zcr_linux_explicit_synchronization_v1.
+
+  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.
+
+
+
+  
+Destroy this explicit synchronization factory object. Other objects,
+including zwp_surface_synchronization_v1 objects created by this
+factory, shall not be affected by this request.
+  
+
+
+
+  
+
+
+
+  
+Instantiate an interface extension for the given wl_surface to
+provide explicit synchronization.
+
+If the given wl_surface already has an explicit synchronization object
+associated, the synchronization_exists prot

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


[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 <alexandros.frant...@collabora.com>
---
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 = >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,
+  >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 = >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,
+  >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 = >focus_resource_list;
msecs = timespec_to_msec(time);
wl_resource_for_each(resource, resource_list) {
+   send_timestamps_for_input_resource(resource,
+  >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 = >default_grab;
wl_signal_init(>focus_signal);
+   wl_list_init(>timestamps_list);
 
return touch;
 }
@@ -1297,6 +1309,7 @@ weston_touch_destroy(struct weston_touch *touch)
wl_list_remove(>focus_resource_list);
wl_list_remove(>focus_view_listener.link);
wl_list_remove(>focus_resource_listener.link);
+   wl_list_remove(>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,
+ >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, _interface,
-  touch, unbind_resource);
+  touch, destroy_touch_res

[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 <alexandros.frant...@collabora.com>
---
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,
+ 
>timestamps_list);
weston_pointer_cleanup_pointer_client(pointer, pointer_client);
}
 }
@@ -446,8 +448,12 @@ pointer_send_motion(struct weston_pointer *pointer,
 
resource_list = >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,
+   >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 = >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,
+   >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,
+  
>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,
+  
>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(>focus_signal);
wl_list_init(>focus_view_listener.link);
wl_signal_init(>destroy_signal);
+   wl_list_init(>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(>focus_resource_listener.link);
wl_list_remove(>focus_view_listen

[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 <alexandros.frant...@collabora.com>
---
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, _sec_hi, _sec_lo, _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 = >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,
+  >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 = >default_grab;
wl_signal_init(>focus_signal);
+   wl_list_init(>timestamps_list);
 
return keyboard;
 }
@@ -1187,6 +1228,7 @@ weston_keyboard_destroy(struct weston_keyboard *keyboard)
 
wl_array_release(>keys);
wl_list_remove(>focus_resource_listener.link);
+   wl_list_remove(>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,
+ 
>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));

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 <alexandros.frant...@collabora.com>
> ---
> 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 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 <alexandros.frant...@collabora.com>
---
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 = >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,
+  >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 = >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,
+  >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 = >focus_resource_list;
msecs = timespec_to_msec(time);
wl_resource_for_each(resource, resource_list) {
+   send_timestamps_for_input_resource(resource,
+  >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 = >default_grab;
wl_signal_init(>focus_signal);
+   wl_list_init(>timestamps_list);
 
return touch;
 }
@@ -1297,6 +1309,7 @@ weston_touch_destroy(struct weston_touch *touch)
wl_list_remove(>focus_resource_list);
wl_list_remove(>focus_view_listener.link);
wl_list_remove(>focus_resource_listener.link);
+   wl_list_remove(>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,
+ >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, _interface,
-  touch, unbind_resource);
+  touch, destroy_touch_resource);
 
/* If we don't have a touch_state, the resource is inert, so there
 * is nothing more to set up */
@@ -4731,7 +4757,28 @@

[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 <alexandros.frant...@collabora.com>
---
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,
+ 
>timestamps_list);
weston_pointer_cleanup_pointer_client(pointer, pointer_client);
}
 }
@@ -446,8 +448,12 @@ pointer_send_motion(struct weston_pointer *pointer,
 
resource_list = >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,
+   >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 = >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,
+   >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,
+  
>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,
+  
>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(>focus_signal);
wl_list_init(>focus_view_listener.link);
wl_signal_init(>destroy_signal);
+   wl_list_init(>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(>focus_resource_listener.link);
wl_list_remove(>focus_view_listener.link);
wl_list_remove(>output_destroy_listener.link);
+   wl_list_remove(>timestamps_list);
free(pointer);
 }
 
@@ -4681,

[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 <alexandros.frant...@collabora.com>
---
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,
+  _input_timestamps_manager_v1_interface,
+  1, id);
+
+   if (resource == NULL) {
+   wl_client_post_no_memory(client);
+   return;
+   }
+
+   wl_resource_set_implementation(resource,
+  _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,
+ _input_timestamps_manager_v1_interface, 1,
+ NULL, bind_input_timestamps_manager))
+   return -1;
+
return 0;
 }
-- 
2.14.1

___
wayland-devel

[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 <alexandros.frant...@collabora.com>
---
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, _sec_hi, _sec_lo, _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 = >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,
+  >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 = >default_grab;
wl_signal_init(>focus_signal);
+   wl_list_init(>timestamps_list);
 
return keyboard;
 }
@@ -1187,6 +1228,7 @@ weston_keyboard_destroy(struct weston_keyboard *keyboard)
 
wl_array_release(>keys);
wl_list_remove(>focus_resource_listener.link);
+   wl_list_remove(>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,
+ 
>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, _interface,
-  keyboard, unbind_resource);
+  keyboard, destroy_keyboard_r

[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 <alexandros.frant...@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paala...@collabora.co.uk>
---
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(_zero_nsec));
ZUC_ASSERT_FALSE(timespec_is_zero(_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(, ));
+   ZUC_ASSERT_TRUE(timespec_eq(, ));
+
+   ZUC_ASSERT_FALSE(timespec_eq(, ));
+   ZUC_ASSERT_FALSE(timespec_eq(, ));
+}
-- 
2.14.1

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


[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 <alexandros.frant...@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paala...@collabora.co.uk>
---
Changes in v2:
 - Update wayland-protocols version dependency to 1.13.

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

diff --git a/Makefile.am b/Makefile.am
index b5c29c04..679e6b78 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -879,7 +879,9 @@ BUILT_SOURCES +=\
protocol/ivi-application-protocol.c \
protocol/ivi-application-client-protocol.h  \
protocol/linux-dmabuf-unstable-v1-protocol.c\
-   protocol/linux-dmabuf-unstable-v1-client-protocol.h
+   protocol/linux-dmabuf-unstable-v1-client-protocol.h \
+   protocol/input-timestamps-unstable-v1-protocol.c\
+   protocol/input-timestamps-unstable-v1-client-protocol.h
 
 westondatadir = $(datadir)/weston
 dist_westondata_DATA = \
@@ -1335,10 +1337,14 @@ vertex_clip_test_LDADD = libtest-runner.la -lm 
$(CLOCK_GETTIME_LIBS)
 
 libtest_client_la_SOURCES =\
tests/weston-test-client-helper.c   \
-   tests/weston-test-client-helper.h
-nodist_libtest_client_la_SOURCES = \
-   protocol/weston-test-protocol.c \
-   protocol/weston-test-client-protocol.h
+   tests/weston-test-client-helper.h   \
+   tests/input-timestamps-helper.c \
+   tests/input-timestamps-helper.h
+nodist_libtest_client_la_SOURCES = \
+   protocol/weston-test-protocol.c \
+   protocol/weston-test-client-protocol.h  \
+   protocol/input-timestamps-unstable-v1-protocol.c\
+   protocol/input-timestamps-unstable-v1-client-protocol.h
 libtest_client_la_CFLAGS = $(AM_CFLAGS) $(TEST_CLIENT_CFLAGS) $(CAIRO_CFLAGS)
 libtest_client_la_LIBADD = libshared.la libtest-runner.la $(TEST_CLIENT_LIBS) 
$(CAIRO_LIBS)
 
diff --git a/configure.ac b/configure.ac
index dd344d6a..033b9484 100644
--- a/configure.ac
+++ b/configure.ac
@@ -218,7 +218,7 @@ fi
 PKG_CHECK_MODULES(LIBINPUT_BACKEND, [libinput >= 0.8.0])
 PKG_CHECK_MODULES(COMPOSITOR, [$COMPOSITOR_MODULES])
 
-PKG_CHECK_MODULES(WAYLAND_PROTOCOLS, [wayland-protocols >= 1.8],
+PKG_CHECK_MODULES(WAYLAND_PROTOCOLS, [wayland-protocols >= 1.13],
  [ac_wayland_protocols_pkgdatadir=`$PKG_CONFIG 
--variable=pkgdatadir wayland-protocols`])
 AC_SUBST(WAYLAND_PROTOCOLS_DATADIR, $ac_wayland_protocols_pkgdatadir)
 
diff --git a/tests/input-timestamps-helper.c b/tests/input-timestamps-helper.c
new file mode 100644
index ..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

[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 <alexandros.frant...@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paala...@collabora.co.uk>
Reviewed-by: Quentin Glidic <sardemff7+...@sardemff7.net>
---
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(>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(>popup_grab.surfaces))
+   if (seat == NULL || wl_list_empty(>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_

[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 <alexandros.frant...@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paala...@collabora.co.uk>
---
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(>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(>popup_grab.surfaces))
+   if (seat == NULL || wl_list_empty(>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

[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 <alexandros.frant...@collabora.com>
---
 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 i

[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 <alexandros.frant...@collabora.com>
---
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 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 <alexandros.frant...@collabora.com>
---
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, _client->pointer_resources) {
+   wl_resource_set_user_data(resource, NULL);
+   }
+
+   wl_resource_for_each(resource,
+_client->relative_pointer_resources) {
+   wl_resource_set_user_data(resource, NULL);
+   }
+
+   wl_list_remove(_client->pointer_resources);
+   wl_list_remove(_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(>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_clients,
+ link) {
+   wl_list_remove(_client->link);
+   weston_pointer_client_destroy(pointer_client);
+   }
 
wl_list_remove(>focus_resource_listener.link);
wl_list_remove(>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 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 <alexandros.frant...@collabora.com>
---
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, >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,
 _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, >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(>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 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 <alexandros.frant...@collabora.com>
---
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 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 <alexandros.frant...@collabora.com>
---
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 <alexandros.frant...@collabora.com>
---
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

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 <alexandros.frant...@collabora.com> 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 <alexandros.frant...@collabora.com> 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 <alexandros.frant...@collabora.com>
> > > > ---
> > > >  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


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 <alexandros.frant...@collabora.com> 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 <alexandros.frant...@collabora.com>
> > ---
> >  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(>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, >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...
> 
> > +
> >  

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 <alexandros.frant...@collabora.com> 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 <alexandros.frant...@collabora.com>
> > ---
> >  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 

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 <alexandros.frant...@collabora.com> 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 <alexandros.frant...@collabora.com> 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 <alexandros.frant...@collabora.com>
> > > > ---
> > > >  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, "s

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 <alexandros.frant...@collabora.com> 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 <alexandros.frant...@collabora.com>
> > ---
> >  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 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 <alexandros.frant...@collabora.com> 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 <alexandros.frant...@collabora.com>
> > ---
> >  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 pr

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 <alexandros.frant...@collabora.com> 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 <alexandros.frant...@collabora.com>
> > ---
> >  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,
> > + _input_timestamps_v1_interface,
> > + 1, id);
> > +   if (!input_ts) {
> > +   wl_client_post_no_memory(client);
> > +   return;
> > +   }
> > +
> > +   wl_resource_set_implementation(input_ts,
> > +  _timestamps_interface,
> > +  touch_resource,
> > +  unbind_resource);
> > +
> > +   wl_list_insert(>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


[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 <alexandros.frant...@collabora.com>
---
 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(>seat, test->compositor, "test-seat");
+   test->is_seat_initialized = true;
+
+   /* add devices */
+   weston_seat_init_pointer(>seat);
+   if (weston_seat_init_keyboard(>seat, NULL) < 0)
+   return -1;
+   weston_seat_init_touch(>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(>seat, ec, "test-seat");
-
-   /* add devices */
-   weston_seat_init_pointer(>seat);
-   if (weston_seat_init_keyboard(>seat, NULL) < 0)
+   if (test_seat_init(test) == -1)
return -1;
-   weston_seat_init_touch(>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 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 <alexandros.frant...@collabora.com>
---
 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 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 <alexandros.frant...@collabora.com>
---
 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(>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,
 _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, >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, >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(>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


[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 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 <alexandros.frant...@collabora.com>
---
 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(>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, >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,
 _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,
 _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(>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, >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(>inputs) == 1);
-}
-
 struct client *
 create_client(void)
 {
@@ -862,9 +877,6 @@ create_client(void)
 * events */
client_roundtrip(client);
 
-   /* find the right input for us */
-   client_set_input(client);
-

[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 <alexandros.frant...@collabora.com>
---
 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, _client->pointer_resources) {
+   wl_resource_set_user_data(resource, NULL);
+   }
+
+   wl_resource_for_each(resource,
+_client->relative_pointer_resources) {
+   wl_resource_set_user_data(resource, NULL);
+   }
+
+   wl_list_remove(_client->pointer_resources);
+   wl_list_remove(_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(>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_clients,
+ link) {
+   wl_list_remove(_client->link);
+   weston_pointer_client_destroy(pointer_client);
+   }
 
wl_list_remove(>focus_resource_listener.link);
wl_list_remove(>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,
_locked_pointer_v1_interface,
_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,
_confined_pointer_v1_interface,
_pointer_interface,
-- 
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 <alexandros.frant...@collabora.com>
---
 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, >resource_list) {
+   wl_resource_set_user_data(resource, NULL);
+   }
+
+   wl_resource_for_each(resource, >focus_resource_list) {
+   wl_resource_set_user_data(resource, NULL);
+   }
 
+   wl_list_remove(>resource_list);
+   wl_list_remove(>focus_resource_list);
wl_list_remove(>focus_view_listener.link);
wl_list_remove(>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, _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 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 <alexandros.frant...@collabora.com>
---
 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, >base_resource_list) {
+   wl_resource_set_user_data(resource, NULL);
+   }
+
+   wl_resource_for_each(resource, >drag_resource_list) {
+   wl_resource_set_user_data(resource, NULL);
+   }
+
+   wl_list_remove(>base_resource_list);
+   wl_list_remove(>drag_resource_list);
+
wl_list_remove(>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 <alexandros.frant...@collabora.com>
---
 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, >resource_list) {
+   wl_resource_set_user_data(resource, NULL);
+   }
+
+   wl_resource_for_each(resource, >focus_resource_list) {
+   wl_resource_set_user_data(resource, NULL);
+   }
+
+   wl_list_remove(>resource_list);
+   wl_list_remove(>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(>resource_list, wl_resource_get_link(cr));
wl_resource_set_implementation(cr, _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


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 <alexandros.frant...@collabora.com> 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 <alexandros.frant...@collabora.com>
> > > Reviewed-by: Pekka Paalanen <pekka.paala...@collabora.co.uk>
> > > Acked-by: Jonas Ådahl <jad...@gmail.com>
> > > ---
> > > 
> > > 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/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 <alexandros.frant...@collabora.com>
---
 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 = >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,
+  >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 = >default_grab;
wl_signal_init(>focus_signal);
+   wl_list_init(>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 = 
>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(>resource_list, wl_resource_get_link(cr));
wl_resource_set_implementation(cr, _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,
+ _input_timestamps_v1_interface,
+ 1, id);
+   if (!input_ts) {
+   wl_client_post_no_memory(client);
+   return;
+   }
+
+   wl_resource_set_implementation(input_ts,
+  _timestamps_interface,
+  keyboard_resource,
+  unbind_resource);
+
+   wl_list_insert(>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, , 1, WL_KEYBOARD_KEY_STATE_PRESSED);
assert(keyboard->key_time_msec == timespec_to_msec());
+   assert(timespec_eq(>key_time_timespec, ));
 
send_key(client, , 1, WL_KEYBOARD_KEY_STATE_RELEASED);
assert(keyboard->key_time_msec == timespec_to_msec());
+   assert(timespec_eq(>key_time_timespec, ));
+
+   input_timestamps_dest

[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 <alexandros.frant...@collabora.com>
---
 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 = >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,
+  >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 = >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,
+  >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 = >focus_resource_list;
msecs = timespec_to_msec(time);
wl_resource_for_each(resource, resource_list) {
+   send_timestamps_for_input_resource(resource,
+  >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 = >default_grab;
wl_signal_init(>focus_signal);
+   wl_list_init(>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 = >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, _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,
+ _input_timestamps_v1_interface,
+ 1, id);
+   if (!input_ts) {
+   wl_client_post_no_memory(client);
+   return;
+   }
+
+   wl_resource_set_implementation(input_t

[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 <alexandros.frant...@collabora.com>
---
 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, >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,
+

[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 <alexandros.frant...@collabora.com>
---
 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(_zero_nsec));
ZUC_ASSERT_FALSE(timespec_is_zero(_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(, ));
+   ZUC_ASSERT_TRUE(timespec_eq(, ));
+
+   ZUC_ASSERT_FALSE(timespec_eq(, ));
+   ZUC_ASSERT_FALSE(timespec_eq(, ));
+}
-- 
2.14.1

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


[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 <alexandros.frant...@collabora.com>
---
 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 = >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,
+   >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 = >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,
+   >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 = >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,
+   >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,
+  
>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,
+  
>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(>focus_signal);
wl_list_init(>focus_view_listener.link);
wl_signal_init(>destroy_signal);
+   wl_list_init(>timestamps_list);
 
pointer->s

[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 <alexandros.frant...@collabora.com>
---
 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, _sec_hi, _sec_lo, _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 st

[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


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 <alexandros.frant...@collabora.com> 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 <alexandros.frant...@collabora.com>
> > Reviewed-by: Pekka Paalanen <pekka.paala...@collabora.co.uk>
> > Acked-by: Jonas Ådahl <jad...@gmail.com>
> > ---
> > 
> > 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 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 <alexandros.frant...@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paala...@collabora.co.uk>
Acked-by: Jonas Ådahl <jad...@gmail.com>
---

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 <alexandros.frant...@collabora.com>
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 represent

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 <alexandros.frant...@collabora.com> 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 <alexandros.frant...@collabora.com> 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 <alexandros.frant...@collabora.com>
> > > > ---
> > > >  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 <alexandros.frant...@collabora.com>
> > > > 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
> >

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 <alexandros.frant...@collabora.com> 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 <alexandros.frant...@collabora.com>
> > ---
> > 
> > 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


[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 <alexandros.frant...@collabora.com>
---

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, _sec_hi, _sec_lo, _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());
 }
+
+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, , 1, 1.0);
+   assert(pointer->axis == 1);
+   assert(pointer->axis_value == 1.0);
+   assert(pointer->axis_time_msec == timespec_to_msec());
+
+   send_axis(client, , 2, 0.0);
+   assert(pointer->axis == 2);
+   assert(pointer->axis_stop_time_msec == timespec_to_msec());
+}
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, , 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_resou

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 <alexandros.frant...@collabora.com> 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 <alexandros.frant...@collabora.com>
> > ---
> >  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 <alexandros.frant...@collabora.com>
> > 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! T

[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 <alexandros.frant...@collabora.com>
---

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, _sec_hi, _sec_lo, _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, , WL_TOUCH_DOWN);
+   assert(touch->down_time_msec == timespec_to_msec());
+
+   send_touch(client, , WL_TOUCH_MOTION);
+   assert(touch->motion_time_msec == timespec_to_msec());
+
+   send_touch(client, , WL_TOUCH_UP);
+   assert(touch->up_time_msec == timespec_to_msec());
+}
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
@@ -326,14 +326,16 @@ stati

[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 <alexandros.frant...@collabora.com>
---

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, _sec_hi, _sec_lo, _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, , 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, , expect_key, expect_state);
} else {
break;
}
-
-   client_roundtrip(client);
}
 }
+
+TEST(keyboard_key_event_time)

[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 <alexandros.frant...@collabora.com>
---

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, _sec_hi, _sec_lo, _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());
 }
+
+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, , 1, 1.0);
+   assert(pointer->axis == 1);
+   assert(pointer->axis_value == 1.0);
+   assert(pointer->axis_time_msec == timespec_to_msec());
+
+   send_axis(client, , 2, 0.0);
+   assert(pointer->axis == 2);
+   assert(pointer->axis_stop_time_msec == timespec_to_msec());
+}
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, , 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

[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 <alexandros.frant...@collabora.com>
---

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, _sec_hi, _sec_lo, _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, _sec_hi, _sec_lo, _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, , 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, , 150, 150);
assert(pointer->x == 50);
assert(pointer->y == 50);
+   assert(pointer->motion_time_msec == timespec_to_msec());
 }
 
 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, , 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());
 
-   weston_test_send_button(client->test->weston_test, BTN_LEFT,
-   WL_POINTER_BUTTON_STATE_RELEASED);
-   client_roundtrip(client);
+   send_button(client, , 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());
 }
diff --git a/tests/subsurface-shot-test.c b/tests/subsurface-shot-test.c
index 10415ec7..e8bab676 100644
--- a/tests/subsurface-shot-t

[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 <alexandros.frant...@collabora.com>
---

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(, 0, 0, 0);
+   ZUC_ASSERT_EQ(0, a.tv_sec);
+   ZUC_ASSERT_EQ(0, a.tv_nsec);
+
+   timespec_from_proto(, 0, 1234, );
+   ZUC_ASSERT_EQ(1234, a.tv_sec);
+   ZUC_ASSERT_EQ(, a.tv_nsec);
+
+   timespec_from_proto(, 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 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 <alexandros.frant...@collabora.com>
---

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, >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, _sec_hi, _sec_lo, _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(), (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(, _sec_hi, _sec_lo, _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(, _sec_hi, _sec_lo, _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(, _sec_hi, _sec_lo, _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


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 <alexandros.frant...@collabora.com> 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 <alexandros.frant...@collabora.com> 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 <alexandros.frant...@collabora.com>
> > > > ---
> > > >  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, >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);
> > > > }
> > > >  
&

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 <alexandros.frant...@collabora.com> 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 <alexandros.frant...@collabora.com>
> > ---
> >  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 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 <alexandros.frant...@collabora.com> 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 <alexandros.frant...@collabora.com> 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 <alexandros.frant...@collabora.com>
> > > > ---
> > > >  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 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 <alexandros.frant...@collabora.com> 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 <alexandros.frant...@collabora.com>
> > ---
> >  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, >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, _sec_hi, _sec_lo, _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
> > + *
&

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 <alexandros.frant...@collabora.com> 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 <alexandros.frant...@collabora.com>
> > ---
> >  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 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


[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 <alexandros.frant...@collabora.com>
---
 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 <alexandros.frant...@collabora.com>
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

[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 <alexandros.frant...@collabora.com>
---
 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, _sec_hi, _sec_lo, _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, , WL_TOUCH_DOWN);
+   assert(touch->down_time == timespec_to_msec());
+
+   send_touch(client, , WL_TOUCH_MOTION);
+   assert(touch->motion_time == timespec_to_msec());
+
+   send_touch(client, , WL_TOUCH_UP);
+   assert(touch->up_time == timespec_to_msec());
+}
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_fixed_to_int(x_w);
tou

[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 <alexandros.frant...@collabora.com>
---
 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, _sec_hi, _sec_lo, _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, , 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, , 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, , 0, WL_KEYBOARD_KEY_STATE_PRESSED);
+   assert(keyboard->key_time == timespec_to_msec());
+
+   send_key(client, , 0, WL_KEYBOARD_KEY_STATE_RELEASED);
+   assert(keyboard->key_time == timespec_to_msec());
+}
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 @@ struct keyboard {

[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 <alexandros.frant...@collabora.com>
---
 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, _sec_hi, _sec_lo, _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());
 }
+
+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, , 1, 1.0);
+   assert(pointer->axis == 1);
+   assert(pointer->axis_value == 1.0);
+   assert(pointer->axis_time == timespec_to_msec());
+
+   send_axis(client, , 2, 0.0);
+   assert(pointer->axis == 2);
+   assert(pointer->axis_stop_time == timespec_to_msec());
+}
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, , 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(, 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, , _event);
+}
+
 static void
 activate_surface(struct wl_client *client, struct wl_

[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 <alexandros.frant...@collabora.com>
---
 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 */

  1   2   >