[ozone/wayland] Do not use possibly blocking dispatch API

Using wl_display_dispatch is a wrong thing to do as it is a blocking
method (see [1]). It can cause freezes and deadlocks.

Instead, we need to do something like this -

while (wl_display_prepare_read_queue(display, queue) != 0)
        wl_display_dispatch_queue_pending(display, queue);
wl_display_flush(display);

ret = poll(fds, nfds, -1);
if (has_error(ret))
        wl_display_cancel_read(display);
else
        wl_display_read_events(display);

wl_display_dispatch_queue_pending(display, queue);

However, there is no need to do a second poll as long
as we are notified by libevent that the display fd is
non-blocking. However, to ensure we can read, we have
to prepare the queue, which tells other clients we
are going to read from the queue. If prepare fails,
it means there is nothing to read. Thus, we push
the events into the queue and return early instead.

We have also to add an "automatic" flush as part
of the polling mechanism. This poll must ensure
that all the data has been written to the queue.
If not, -1 is returned and EAGAIN is set. In this
case, we have to stop watching the fd for read
access and start watching it for the write access.

As soon as all the data is written, we can get
back to reading.

[1] https://people.freedesktop.org/~whot/wayland-doxygen/wayland/Client/classwl__display.html#a30a9c4f020f3e77581c7a81ecdb4913d

Bug: 987821
Change-Id: I536513034c18a47da079a2b56a75d32f20f72ad6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1730159
Reviewed-by: Robert Kroeger <rjkroege@chromium.org>
Commit-Queue: Maksim Sisov <msisov@igalia.com>
Cr-Commit-Position: refs/heads/master@{#685148}
9 files changed