compositor: add weston_surface_set_label_func()

When printing out logs from Weston's actions, mainly for debugging, it
can be very difficult to identify the different surfaces.  Inspecting
the configure function pointer is not useful, as the configure functions
may live in modules.

Add vfunc get_label to weston_surface, which will produce a short,
human-readable description of the surface, which allows identifying it
better, rather than just looking at the surface size, for instance.

Set the label function from most parts of Weston, to identify cursors and
drag icons, and panels, backgrounds, screensavers and lock surfaces, and
the desktop shell's application surfaces.

v2: renamed 'description' to 'label', so we get
	weston_surface_set_label_func().

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
compositor: Implement JSON-timeline logging

Logging is activated and deactivated with the debug key binding 't'.
When activated, it creates a new log file, where it records the events.
The log file contains events and detailed object information entries in
JSON format, and is meant to be parsed in sequence from beginning to the
end.

The emitted events are mostly related to the output repaint cycle, like
when repaint begins, is submitted to GPU, and when it completes on a
vblank. This is recorded per-output. Also some per-surface events are
recorded, including when surface damage is flushed.

To reduce the log size, events refer to objects like outputs and
surfaces by id numbers. Detailed object information is emitted only as
needed: on the first object occurrence, and afterwards only if
weston_timeline_object::force_refresh asks for it.

The detailed information for surfaces includes the string returned by
weston_surface::get_label. Therefore it is important to set
weston_timeline_object::force_refresh = 1 whenever the string would
change, so that the new details get recorded.

A rudimentary parser and SVG generator can be found at:
https://github.com/ppaalanen/wesgr

The timeline logs can answer questions including:
- How does the compositor repaint cycle work timing-wise?
- When was the vblank deadline missed?
- What is the latency from surface commit to showing the new content on
  screen?
- How long does it take to process the scenegraph?

v2: weston_surface::get_description renamed to get_label.
v3: reafctor a bit into fprint_quoted_string().

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
tests:  Fix minor typo
xwm: fix a crash in handle_state

To produce the bug, build and run: (you don't need the game data to test)

https://github.com/clintbellanger/flare-engine/

$ mv ~/.config/flare ~/.config/flare.bak
$ ./flare  # click 'configure', set full screen mode then click 'ok'
           # weston will crash and dump core.

[Pekka: edited the commit message]
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
window: use roundtrip instead of dispatch after get_registry

wl_display_dispatch() just dispatches events that are in
default and display queues and if there are no events,
then it will wait for them. But only dispatching
the events doesn't guarantee that we got all the global announcements,
we need to do sync too. Therefore use wl_display_roundtrip() instead
of wl_display_dispatch().

Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
screenshooter: fix various memory handling

There were unchecked malloc and no free for this memory.
Also simplify error handling in one function.

v2. remove check if memory is NULL, according to man pages,
    free(NULL) is a no-op

Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
clipboard: set fd member of clipboard_source

The fd member of clipboard_source structure was not set
but was used in close().

v2. don't do unnecessary changes

Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
compositor: introduce struct weston_backend

This is a preliminary change for libweston, with no functional modifications.
Separate the backends and the core weston_compositor struct, by creating
the weston_compositor in the main(), and having the various backends extend
the weston_backend struct, an instance of which is returned by the backend
entry point.
don't use weston_config in the backends code

This is to make them usable by future libweston users, since they will
not use weston_config.
weston_config is still used in the backends entry points, which will
later on live in their own files.
compositor: remove the weston_config field from weston_compositor

Instead of the central weston_config pointer we now store it in some
module-specific pointers. This way we can remove them one by one.
compositor: add API to manage compositor instances
compositor: move the main() to a new weston.c file
build a libweston.so used by the weston binary
libweston: allow compositors to define the logging behavior
libweston: move the child process launching and monitoring to weston

libweston still internally uses those functions, so it is not linkable
yet by other compositors.
libweston: handle the screenshoot and record bindings in weston.c

Move the code launching the screenshooter client and implementing
the screenshot protocol out of libweston, and make screenshooter.c
a generic way to hook screenshoot protocols into weston.
text: build the text-backend in weston

It uses the weston_client_launch API, which is not available in
libweston.
libweston: expose the X11 backend's API
libweston: expose the drm backend's API
libweston: make a shared library for compositor launchers