platform/upstream/wayland.git
10 years agoserver: Start documenting the server side API
Kristian Høgsberg [Thu, 14 Nov 2013 05:11:17 +0000 (21:11 -0800)]
server: Start documenting the server side API

This is now public, stable API, so it seems prudent to actually document it.

10 years agoserver: Add API to protect access to an SHM buffer
Neil Roberts [Wed, 13 Nov 2013 15:32:05 +0000 (15:32 +0000)]
server: Add API to protect access to an SHM buffer

Linux will let you mmap a region of a file that is larger than the
size of the file. If you then try to read from that region the process
will get a SIGBUS signal. Currently the clients can use this to crash
a compositor because it can create a pool and lie about the size of
the file which will cause the compositor to try and read past the end
of it. The compositor can't simply check the size of the file to
verify that it is big enough because then there is a race condition
where the client may truncate the file after the check is performed.

This patch adds the following two public functions in the server API
which can be used wrap access to an SHM buffer:

void wl_shm_buffer_begin_access(struct wl_shm_buffer *buffer);
void wl_shm_buffer_end_access(struct wl_shm_buffer *buffer);

The first time wl_shm_buffer_begin_access is called a signal handler
for SIGBUS will be installed. If the signal is caught then the buffer
for the current pool is remapped to an anonymous private buffer at the
same address which allows the compositor to continue without crashing.
The end_access function will then post an error to the buffer
resource.

The current pool is stored as part of some thread-local storage so
that multiple threads can safely independently access separate
buffers.

Eventually we may want to add some more API so that compositors can
hook into the signal handler or replace it entirely if they also want
to do some SIGBUS handling.

10 years agoprotocol: validate the protocol against a dtd
Peter Hutterer [Wed, 23 Oct 2013 04:56:04 +0000 (14:56 +1000)]
protocol: validate the protocol against a dtd

The scanner is not very forgiving if the protocol doesn't match it's
expectations and crashes without much of a notice. Thus, validate the protocol
against a DTD.

Move the protocol subdir forward so we validate first before trying anything
else, and install the DTD so we can validate weston's protocols as well.

10 years agoconfigure.ac: Bump version to 1.3.90 for the master branch
Kristian Høgsberg [Wed, 23 Oct 2013 16:25:08 +0000 (09:25 -0700)]
configure.ac: Bump version to 1.3.90 for the master branch

10 years agowayland: Be consistent about #include-guard names
Kristian Høgsberg [Mon, 21 Oct 2013 21:39:06 +0000 (14:39 -0700)]
wayland: Be consistent about #include-guard names

We had a mix of inconsistent names, some of which were non-conformant.
Standardize on all-uppercase-and-underscore naming convention.

https://bugs.freedesktop.org/show_bug.cgi?id=70679

10 years agoprotocol: Fix typo in documentation upstream/1.3.0
José Bollo [Fri, 11 Oct 2013 07:14:25 +0000 (09:14 +0200)]
protocol: Fix typo in documentation

10 years agoconfigure.ac: Bump version to 1.3 1.3.0
Kristian Høgsberg [Wed, 9 Oct 2013 23:20:54 +0000 (16:20 -0700)]
configure.ac: Bump version to 1.3

10 years agoscanner: Handle unrecognized invocation mode
Kristian Høgsberg [Tue, 8 Oct 2013 04:36:31 +0000 (21:36 -0700)]
scanner: Handle unrecognized invocation mode

Print usage if we don't recognize the invocation mode.  Also fixes
uninitialized variable warning.

10 years agoconfigure.ac: Bump version to 1.2.92 1.2.92
Kristian Høgsberg [Thu, 3 Oct 2013 05:14:57 +0000 (22:14 -0700)]
configure.ac: Bump version to 1.2.92

10 years agoclient: Fix handling display->reader_count if poll fails
Neil Roberts [Wed, 25 Sep 2013 09:39:12 +0000 (10:39 +0100)]
client: Fix handling display->reader_count if poll fails

In wl_display_dispatch_queue, if poll fails then it would previously
return immediately and leak a reference in display->reader_count. Then
if the application ignores the error and tries to read again it will
block forever. This can happen for example if the poll fails with
EINTR which the application might consider to be a recoverable error.
This patch makes it cancel the read so the reader_count will be
decremented when poll fails.

10 years agoconfigure.ac: Bump version to 1.2.91 1.2.91
Kristian Høgsberg [Sun, 22 Sep 2013 21:12:26 +0000 (14:12 -0700)]
configure.ac: Bump version to 1.2.91

10 years agoExport the Wayland protocol XML file
Jason Ekstrand [Fri, 20 Sep 2013 13:27:06 +0000 (08:27 -0500)]
Export the Wayland protocol XML file

Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
10 years agotests: add wl_resource tests
Marek Ch [Wed, 18 Sep 2013 15:29:50 +0000 (17:29 +0200)]
tests: add wl_resource tests

10 years agotests: add unit tests for wl_signal
Marek Ch [Wed, 18 Sep 2013 15:29:49 +0000 (17:29 +0200)]
tests: add unit tests for wl_signal

Test wl_signal initialization, adding and getting listeners and emitting

10 years agotests: extended message when leak in test is detected
Marek Ch [Wed, 18 Sep 2013 15:29:48 +0000 (17:29 +0200)]
tests: extended message when leak in test is detected

When memory or fd leak is detected, print how many blocks of memory were
allocated and not freed, respectively how many files were opened/unclosed.

10 years agoclient: fix an inconsistency in documentation
Chang Liu [Wed, 18 Sep 2013 10:45:06 +0000 (10:45 +0000)]
client: fix an inconsistency in documentation

The errno is set to EAGAIN when there are undispatched events, according
to L1066 of wayland-client.c.

10 years agodoc: Slight tweaks to wl_listener
Aaron Faanes [Tue, 17 Sep 2013 21:44:24 +0000 (16:44 -0500)]
doc: Slight tweaks to wl_listener

Prefer \comment over // in code blocks for consistency's sake and keep
variable definitions separated by a line from the rest of the body.

10 years agoutils: Document wl_container_of
Aaron Faanes [Tue, 17 Sep 2013 21:42:43 +0000 (16:42 -0500)]
utils: Document wl_container_of

10 years agodoc: Create \comment alias for C-style comments
Aaron Faanes [Tue, 17 Sep 2013 21:40:49 +0000 (16:40 -0500)]
doc: Create \comment alias for C-style comments

Since /* */ do not nest, documentation is forced to either use C++ style
// comments or some other foreign notation. This commit provides an alias
that allows C-style comments to be introduced in code blocks that support
aliases.

It should be noted that this macro will not work within \code blocks, as
Doxygen commands are ignored there. Instead, Doxygen's fenced code
blocks (created via ~~~) must be used for proper output. To demonstrate:

~~~
struct example_node {
        int id;
        \comment{Other members ...}
};
~~~

will roughly yield the following HTML (excluding syntax highlighting):

<pre>
struct example_node {
        int id;
        /* Other members ... */
};
</pre>

10 years agodoc: Include wayland-util.* for doxygen output
Aaron Faanes [Sun, 15 Sep 2013 18:37:09 +0000 (13:37 -0500)]
doc: Include wayland-util.* for doxygen output

This commit creates a shared file list that is included by both the
client and the server for the XML Makefile targets, as classes within
util are used by both the client and the server.

10 years agowayland-server: Improve wording for wl_signal_get's doc
Aaron Faanes [Sun, 15 Sep 2013 18:37:08 +0000 (13:37 -0500)]
wayland-server: Improve wording for wl_signal_get's doc

The old description was a bit vague; this commit hopefully improves
describing what is returned.

10 years agoutils: Add doxygen for wayland-util.h
Aaron Faanes [Sun, 15 Sep 2013 18:37:07 +0000 (13:37 -0500)]
utils: Add doxygen for wayland-util.h

This is needed for doxygen to generate output for macro definitions, such
as wl_container_of, that are contained by this file. Classes like
wl_list would be documented regardless.

10 years agoutils: Reference some useful methods in wl_signal's doxygen
Aaron Faanes [Sun, 15 Sep 2013 18:37:06 +0000 (13:37 -0500)]
utils: Reference some useful methods in wl_signal's doxygen

This commit adds a bit more detail on the lifecycle of a signal.

10 years agowayland-server: Document wl_listener
Aaron Faanes [Sun, 15 Sep 2013 18:09:18 +0000 (13:09 -0500)]
wayland-server: Document wl_listener

This patch takes Kristian's comments into account, adding a demonstration and
giving a more thorough idea of how wl_listener is used.

10 years agogitignore: add ./compile
Chang Liu [Sun, 8 Sep 2013 11:12:33 +0000 (11:12 +0000)]
gitignore: add ./compile

./compile is a GNU autotools helper script and should be ignored by git

10 years agowayland-server: Add a wl_resource_for_each_safe macro
Rob Bradford [Fri, 6 Sep 2013 16:56:27 +0000 (17:56 +0100)]
wayland-server: Add a wl_resource_for_each_safe macro

A version of wl_resource_for_each that is safe for iteration when items
in the list are removed.

10 years agoutils: tweak wl_list for better doxygen output
Aaron Faanes [Wed, 28 Aug 2013 23:02:02 +0000 (18:02 -0500)]
utils: tweak wl_list for better doxygen output

10 years agowayland-server: Document wl_signal
Aaron Faanes [Wed, 28 Aug 2013 23:02:01 +0000 (18:02 -0500)]
wayland-server: Document wl_signal

10 years agowayland-server: Fix a uninitialized warning from clang
Aaron Faanes [Wed, 28 Aug 2013 22:43:34 +0000 (17:43 -0500)]
wayland-server: Fix a uninitialized warning from clang

This warning is unnecessary, since the pointer in question is only used
for pointer arithmetic, but setting it explicitly to NULL doesn't hurt.

10 years agoconfigure.ac: Bump version to 1.2.90 for master branch
Kristian Høgsberg [Fri, 30 Aug 2013 21:54:40 +0000 (14:54 -0700)]
configure.ac: Bump version to 1.2.90 for master branch

10 years agoscanner: Emit wl_*_destroy stub even if interface has a destructor
Kristian Høgsberg [Tue, 13 Aug 2013 19:06:30 +0000 (20:06 +0100)]
scanner: Emit wl_*_destroy stub even if interface has a destructor

If an interface has a destructor but no 'destroy' method we used to
not emit a destroy method.  Now with the fix for missing destroy
requests for wl_pointer etc we need to emit the local wl_*_destroy
always.

10 years agoprotocol: Add release requests for wl_pointer, wl_keyboard, and wl_touch
Kristian Høgsberg [Tue, 13 Aug 2013 19:06:29 +0000 (20:06 +0100)]
protocol: Add release requests for wl_pointer, wl_keyboard, and wl_touch

We missed destroy requests in the 1.0 protocol and since the scanner
generates local-only *_destroy requests in that case we can't add
destroy requests without breaking protocol.  A client needs to verify
that the server provides a version 3 seat to use the protocol destructor
so the name needs to be something else than wl_*_destroy.

v2 (Rob Bradford): Rebased, bumped the protocol versions and added since
attributes to the requests.

10 years agoAdd support for client-side language bindings
Jason Ekstrand [Thu, 18 Jul 2013 02:58:47 +0000 (21:58 -0500)]
Add support for client-side language bindings

This commit adds support for language bindings on the client half of the
library.  The idea is the same as for server-side dispatchers.

Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
10 years agoAdd support for server-side language bindings
Jason Ekstrand [Thu, 18 Jul 2013 02:58:46 +0000 (21:58 -0500)]
Add support for server-side language bindings

This commit adds support for server-side languages bindings.  This is done
in two ways:

1. Adding a wl_resource_set_dispatcher function that corresponds to
wl_resource_set_interface.  The only difference between the two functions
is that the new version takes a dispatcher along with the implementation,
data, and destructor.  This allows for runtime calling of native language
functions for callbacks instead of having to generate function pointers.

2. Adding versions of wl_resource_post_event and wl_resource_queue_event
that take an array of wl_argument instead of a variable argument list.
This allows for easier run-time argument conversion and removes the need
for libffi-based calling of variadic functions.

Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
10 years agodoc: Add a section on interface and protocol object versioning
Jason Ekstrand [Sun, 18 Aug 2013 21:53:54 +0000 (16:53 -0500)]
doc: Add a section on interface and protocol object versioning

There have been a lot of questions asked lately about versioning of
interfaces and protocol objects.  This addition to the documentation should
clear up some of those questions.

Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
10 years agodoc: Update the ID alocation section
Jason Ekstrand [Sun, 18 Aug 2013 21:52:36 +0000 (16:52 -0500)]
doc: Update the ID alocation section

The method described of alocation IDs has been wrong at least since version
1.0.  This commit updates it to correspond to the way IDs are chosen in
versions >= 1.0.

Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
10 years agopublican: only split chapters and top-level sections onto separate pages
Peter Hutterer [Thu, 15 Aug 2013 10:58:10 +0000 (20:58 +1000)]
publican: only split chapters and top-level sections onto separate pages

When generating HTML, don't split once we're into subjections. This
generates a single page for each protocol interface instead of the previous
separate pages for requests, events and enums.
No effect on the rest of the HTML configuration.

10 years agoprotocol: Improve a bit of grammar for wl_surface::attach description
Bryce W. Harrington [Fri, 9 Aug 2013 17:44:59 +0000 (17:44 +0000)]
protocol: Improve a bit of grammar for wl_surface::attach description

Signed-off-by: Bryce Harrington <b.harrington@samsung.com>
10 years agowayland-client: Add wl_proxy_get_listener
Rob Bradford [Mon, 22 Jul 2013 16:30:52 +0000 (17:30 +0100)]
wayland-client: Add wl_proxy_get_listener

This is the mirror function to wl_proxy_add_listener and is useful
inside client libraries to differentiate events on listeners for which
multiple proxies have been created.

10 years agowayland-server: Add a wl_resource_for_each macro
Rob Bradford [Mon, 22 Jul 2013 16:30:51 +0000 (17:30 +0100)]
wayland-server: Add a wl_resource_for_each macro

This macro allows you to correctly iterate through a list of resources
handling the opaque nature of this type.

10 years agoprotocol: Fix pluralization of user in popup_done description
Bryce W. Harrington [Fri, 9 Aug 2013 01:47:07 +0000 (01:47 +0000)]
protocol: Fix pluralization of user in popup_done description

Signed-off-by: Bryce Harrington <b.harrington@samsung.com>
10 years agoprotocol: Improve grammar for set class description
Bryce W. Harrington [Fri, 9 Aug 2013 01:47:07 +0000 (01:47 +0000)]
protocol: Improve grammar for set class description

Signed-off-by: Bryce Harrington <b.harrington@samsung.com>
10 years agoprotocol: Add missing d to 'x an y'
Bryce W. Harrington [Fri, 9 Aug 2013 01:47:07 +0000 (01:47 +0000)]
protocol: Add missing d to 'x an y'

Signed-off-by: Bryce Harrington <b.harrington@samsung.com>
10 years agoprotocol: Fix typo by removing a redundant 'a'
Bryce W. Harrington [Fri, 9 Aug 2013 01:47:07 +0000 (01:47 +0000)]
protocol: Fix typo by removing a redundant 'a'

Signed-off-by: Bryce Harrington <b.harrington@samsung.com>
10 years agoclient: Improve spelling and grammar in comments
Bryce W. Harrington [Fri, 9 Aug 2013 01:47:06 +0000 (01:47 +0000)]
client: Improve spelling and grammar in comments

Signed-off-by: Bryce Harrington <b.harrington@samsung.com>
10 years agopublican: Fix grammar several places in Protocol docs
Bryce W. Harrington [Fri, 9 Aug 2013 01:47:05 +0000 (01:47 +0000)]
publican: Fix grammar several places in Protocol docs

Signed-off-by: Bryce Harrington <b.harrington@samsung.com>
10 years agopublican: Drop unneeded 'of'
Bryce W. Harrington [Fri, 9 Aug 2013 01:47:05 +0000 (01:47 +0000)]
publican: Drop unneeded 'of'

Signed-off-by: Bryce Harrington <b.harrington@samsung.com>
10 years agopublican: Cleanup Preface's grammar.
Bryce W. Harrington [Fri, 9 Aug 2013 01:47:04 +0000 (01:47 +0000)]
publican: Cleanup Preface's grammar.

Signed-off-by: Bryce Harrington <b.harrington@samsung.com>
10 years agoserver: Release additional_shm_formats array at display destruction
Tomeu Vizoso [Thu, 8 Aug 2013 08:31:56 +0000 (10:31 +0200)]
server: Release additional_shm_formats array at display destruction

10 years agoscanner: check for wayland-scanner.pc before using variables
Peter Hutterer [Wed, 7 Aug 2013 01:05:59 +0000 (11:05 +1000)]
scanner: check for wayland-scanner.pc before using variables

If wayland-scanner.pc can't be found the variables end up being set
irrespectively, leaving the user with odd compiler errors about missing
headers, etc.

10 years agoscanner: expand help string
Peter Hutterer [Wed, 7 Aug 2013 01:05:58 +0000 (11:05 +1000)]
scanner: expand help string

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
10 years agoscanner: support help and --help
Peter Hutterer [Wed, 7 Aug 2013 01:05:57 +0000 (11:05 +1000)]
scanner: support help and --help

wayland-scanner without arguments prints out usage. With help or --help it
waits for stdin to supply something which isn't quite as informative as
printing out the help.

This patch also moves the strcmp for args up to have all of them in one
location.

10 years agoDon't include wayland-server.h in wayland-private.h
Kristian Høgsberg [Wed, 7 Aug 2013 16:17:02 +0000 (09:17 -0700)]
Don't include wayland-server.h in wayland-private.h

We just declare struct wl_display manually instead.

10 years agoshm: Add API for renderers to register additional pixel formats
Tomeu Vizoso [Tue, 6 Aug 2013 18:05:53 +0000 (20:05 +0200)]
shm: Add API for renderers to register additional pixel formats

10 years agoserver: Set client->error when we fail to send a closure
Kristian Høgsberg [Tue, 6 Aug 2013 17:15:35 +0000 (10:15 -0700)]
server: Set client->error when we fail to send a closure

We we're using wl_event_loop_add_idle() here, but if we're failing
because of OOM, that will typically also fail.  Instead, use the
existing client->error flag, which will break out of the event
handling loop and shut down the client.

10 years agoserver: Handle OOM properly when we fail to allocate a send closure
Kristian Høgsberg [Tue, 6 Aug 2013 16:50:14 +0000 (09:50 -0700)]
server: Handle OOM properly when we fail to allocate a send closure

If we can't allocate a closure, don't just silently continue.  Set
client->error so we shut down the client when we're done processing events.

11 years agoclient: Simply wl_display_dispatch_queue_pending() and fix return value
Jiergir Ogoerg [Mon, 29 Jul 2013 23:50:44 +0000 (16:50 -0700)]
client: Simply wl_display_dispatch_queue_pending() and fix return value

We're supposed to return number of events dispatched on success, not 0.
Refactor to avoid goto and just return ret.

11 years agoprotocol: Copy missing pixel formats from wl_drm to wl_shm
Tomeu Vizoso [Thu, 11 Jul 2013 14:08:20 +0000 (16:08 +0200)]
protocol: Copy missing pixel formats from wl_drm to wl_shm

11 years agoBump version to 1.2.0 1.2.0 upstream/1.2.0
Kristian Høgsberg [Sat, 13 Jul 2013 05:30:45 +0000 (01:30 -0400)]
Bump version to 1.2.0

11 years agowayland-client: Handle potential NULL-deref
Kristian Høgsberg [Sat, 13 Jul 2013 04:42:14 +0000 (00:42 -0400)]
wayland-client: Handle potential NULL-deref

Instead, return -1 on out-of-memory.  errno will be set to ENOMEM by
the failing malloc.

11 years agoscanner: Fail more gracefully on out-of-memory
Kristian Høgsberg [Sat, 13 Jul 2013 04:35:21 +0000 (00:35 -0400)]
scanner: Fail more gracefully on out-of-memory

Failing with an error message and error code is little nicer.  I doubt we'll
hit this case much, but it makes the static analysis happy.

11 years agoconnection: Handle empty signature and signature with just a version.
Mariusz Ceier [Wed, 10 Jul 2013 21:40:56 +0000 (23:40 +0200)]
connection: Handle empty signature and signature with just a version.

Functions like wl_argument_from_va_list expect from get_next_argument,
to initialize details->type but when the signature is empty or contains
only version (like in desktop-shell-protocol.c in weston) it is left
uninitialized.

This patch fixes it, by initializing details->type with '\0' value,
signaling end of arguments.

Signed-off-by: Mariusz Ceier <mceier+wayland@gmail.com>
11 years agoBump version to 1.1.91 1.1.91
Kristian Høgsberg [Tue, 9 Jul 2013 23:27:08 +0000 (19:27 -0400)]
Bump version to 1.1.91

11 years agoReplace two remaining wl_display_add_gloavl() occurences
Kristian Høgsberg [Tue, 9 Jul 2013 23:18:10 +0000 (19:18 -0400)]
Replace two remaining wl_display_add_gloavl() occurences

11 years agowayland-server: Don't close display fd in fatal error handler
Kristian Høgsberg [Tue, 9 Jul 2013 22:59:11 +0000 (18:59 -0400)]
wayland-server: Don't close display fd in fatal error handler

We can't do that there, we have to make sure it stays a valid fd until
the application calls wl_display_disconnect().  Otherwise the application
may end up poll()ing on a stale or wrong fd in case another part of the
application (or another thread) triggered a fatal error.

11 years agowayland-server: Return 0 from read_events() in case of EAGAIN
Kristian Høgsberg [Tue, 9 Jul 2013 21:55:45 +0000 (17:55 -0400)]
wayland-server: Return 0 from read_events() in case of EAGAIN

Getting no data from the socket is not an error condition.  This may
happen in case of calling prepare_read() and then read_events() with
no other pending readers and no data in the socket.  In general,
read_events() may not queue up events in the given event queue.  From
a given threads point of view it doesn't matter whether events were
read and put in a different event queue or no events were read at all.

11 years agowayland-client: Treat EOF when reading the wayland socket as an error
Neil Roberts [Tue, 9 Jul 2013 13:10:45 +0000 (14:10 +0100)]
wayland-client: Treat EOF when reading the wayland socket as an error

If EOF is encountered while reading from the Wayland socket, make
wl_display_read_events() return -1 so that it will be treated as an
error. The documentation for this function states that it will set
errno when there is an error so it additionally makes up an errno of
EPIPE.

If we don't do this then when the compositor quits the Wayland socket
will be become ready for reading but wl_display_dispatch will do
nothing which typically makes the application take up 100% CPU. In
particular eglSwapBuffers will likely get stuck in an infinite busy
loop because it repeatedly calls wl_display_dispatch_queue while it
waits for the frame callback.

https://bugzilla.gnome.org/show_bug.cgi?id=703892

11 years agowayland-server: Add wl_global_create/destroy()
Kristian Høgsberg [Mon, 8 Jul 2013 22:45:41 +0000 (18:45 -0400)]
wayland-server: Add wl_global_create/destroy()

This patch introduces wl_global_create() and wl_global_destroy() as
replacements for wl_display_add_global() and wl_display_remove_global().
The add/remove_global API did not allow a compositor to indicate
the implemented version of a global, it just took the version from
the interface meta data.  The problem is that the meta data
(which lives in libwayland-server.so) can get out of sync with a
compositor implementation.  The compositor will then advertise a
higher version of a global than what it actually implements.

The new API lets a compositor pass in a version when it registers
a global, which solves the problem.  The add/remove API is deprecated
with this patch and will be removed.

11 years agobuild: Add wayland-scanner.pc.
Daiki Ueno [Tue, 2 Jul 2013 09:38:15 +0000 (18:38 +0900)]
build: Add wayland-scanner.pc.

To allow user program to include wayland-scanner.m4 in tarball, move
the path variables from it into wayland-scanner.pc.

11 years agobuild: Install wayland-scanner.mk under $(pkgdatadir).
Daiki Ueno [Tue, 2 Jul 2013 09:38:14 +0000 (18:38 +0900)]
build: Install wayland-scanner.mk under $(pkgdatadir).

11 years agowayland-server: Free non-legacy wl_resource structs during wl_client_destroy
Kristian Høgsberg [Tue, 2 Jul 2013 20:59:44 +0000 (16:59 -0400)]
wayland-server: Free non-legacy wl_resource structs during wl_client_destroy

We need to free the non-legacy resources during client shutdown as well.

11 years agowayland-server: Remove left-over double free in unbind_resource() helper
Kristian Høgsberg [Tue, 2 Jul 2013 20:57:45 +0000 (16:57 -0400)]
wayland-server: Remove left-over double free in unbind_resource() helper

11 years agowayland-server: Remove error event posting from wl_resource_create
Kristian Høgsberg [Tue, 2 Jul 2013 19:39:03 +0000 (15:39 -0400)]
wayland-server: Remove error event posting from wl_resource_create

The wl_client_add/new_object() functions sends out an NO_MEMORY error if
the allocation fails.  This was convenient in a couple of places where
that was all the error handling that was needed.  Unfortunately that
looks like out-of-memory isn't handled at the call site and set a bad
precedent for not cleaning up properly or not handling at all.

As we're introducing wl_resource_create() as a replacement for those two
functions, let's remove the automatic error event posting and require
the caller to do that if necessary.

This commit also introduces a new helper, wl_client_post_no_memory() to
make it possible to send NO_MEMORY events from bind where we don't have
a wl_resource.

11 years agowayland-server: Mark wl_client_add/new_object as deprecated
Kristian Høgsberg [Tue, 2 Jul 2013 18:34:42 +0000 (14:34 -0400)]
wayland-server: Mark wl_client_add/new_object as deprecated

11 years agowayland-server: Dont free resource in user data destroy callback
Kristian Høgsberg [Tue, 2 Jul 2013 18:09:16 +0000 (14:09 -0400)]
wayland-server: Dont free resource in user data destroy callback

11 years agowayland-server: Verify request versions before invoking handler
Jason Ekstrand [Tue, 2 Jul 2013 18:57:10 +0000 (14:57 -0400)]
wayland-server: Verify request versions before invoking handler

This commit provides a layer of protection for the compositor in the form
of message version checking.  We track version information in the
wl_resource and now use this version information to verify that a request
exists in that protocol version before invoking it.  This way libwayland
won't accidentally invoke a request that does not exist and thereby cause
the compositor to crash.

Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
11 years agoAdd wl_resource_create() and a version field to wl_resource
Jason Ekstrand [Fri, 28 Jun 2013 01:09:20 +0000 (20:09 -0500)]
Add wl_resource_create() and a version field to wl_resource

A new function, wl_resource_create(), lets the compositor create a
wl_resource for a given version of the interface.  Passing 0 for the
object ID will allocate a new ID. The implementation, user data and
destructor can be set with wl_resource_set_implementation().

These two functions deprecates wl_client_add/new_object and the
main difference and motivation is the ability to provide a version number
for the resource.  This lets the compositor track which version of the
interface a client has created and we'll use that to verify incoming requests.

Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
11 years agoAdd version information to wl_message signatures.
Jason Ekstrand [Fri, 28 Jun 2013 01:09:19 +0000 (20:09 -0500)]
Add version information to wl_message signatures.

This commit adds version information to wl_message signatures and a
wl_message_get_since function to retrieve.  The since version comes in the
form of a (possible) integer at the begining of the message.  If the
message starts with an integer, then it specifies the "since" version of
that message.  Messages present in version one do not get this "since"
information.  In this way we can run-time detect the version information
for a structure on a per-message basis.

Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
11 years agoserver: Make wl_object and wl_resource opaque structs
Kristian Høgsberg [Fri, 28 Jun 2013 01:09:18 +0000 (20:09 -0500)]
server: Make wl_object and wl_resource opaque structs

With the work to add wl_resource accessors and port weston to use them,
we're ready to make wl_resource and wl_object opaque structs.  We keep
wl_buffer in the header for EGL stacks to use, but don't expose it by
default.  In time we'll remove it completely, but for now it provides a
transition paths for code that still uses wl_buffer.

Reviewed-by: Jason Ekstrand<jason@jlekstrand.net>
11 years agoprotocol: add no_keymap format to keymap formats
Rob Bradford [Mon, 24 Jun 2013 15:50:41 +0000 (16:50 +0100)]
protocol: add no_keymap format to keymap formats

This format is used to specify that the key button events received are not in
relation to any key map and that the codes should be interpreted directly.

v2: Use zero for the no keymap enum value and enhance the documentation
for the enum entry.

11 years agoChange wl_shm_buffer to use a resource pointer
Jason Ekstrand [Fri, 21 Jun 2013 01:36:49 +0000 (20:36 -0500)]
Change wl_shm_buffer to use a resource pointer

This commit also has the effect of making wl_shm_buffer no longer a
wl_buffer derivative.

Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
11 years agoChange SHM wl_buffer functions to use the wl_shm_buffer structure
Jason Ekstrand [Fri, 21 Jun 2013 01:36:48 +0000 (20:36 -0500)]
Change SHM wl_buffer functions to use the wl_shm_buffer structure

This commit does not break ABI.  It merely changes the types of some things
and adds a wl_shm_buffer_get function.

Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
11 years agoAdd a wl_resource_instance_of function
Jason Ekstrand [Fri, 21 Jun 2013 01:36:47 +0000 (20:36 -0500)]
Add a wl_resource_instance_of function

Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
11 years agoFree non-legacy resources inside wl_resource_destroy
Jason Ekstrand [Tue, 18 Jun 2013 17:42:40 +0000 (12:42 -0500)]
Free non-legacy resources inside wl_resource_destroy

This commit makes wl_resource_destroy automatically free all non-legacy
resource structures.  Since wl_resource is now an opaque structure it
doesn't make sense for the clients to be freeing it.  This checks to make
sure that it was added through wl_client_add_object or wl_client_new_object
and not wl_client_add_resource before it frees it.  This way if it is a
legacy resources embedded in a structure somewhere we don't have an invalid
free.

Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
11 years agodoc: Add a small contributing guide
Ander Conselvan de Oliveira [Tue, 11 Jun 2013 15:21:32 +0000 (18:21 +0300)]
doc: Add a small contributing guide

Document what we expect in terms of commit messages and coding style.
New contributors are usually unaware of this, so it is good to have a
document to point them too.

11 years agoclient: Add wl_display_prepare_read() API to relax thread model assumptions
Kristian Høgsberg [Sun, 17 Mar 2013 18:21:48 +0000 (14:21 -0400)]
client: Add wl_display_prepare_read() API to relax thread model assumptions

The current thread model assumes that the application or toolkit will have
one thread that either polls the display fd and dispatches events or just
dispatches in a loop.  Only this main thread will read from the fd while
all other threads will block on a pthread condition and expect the main
thread to deliver events to them.

This turns out to be too restrictive.  We can't assume that there
always will be a thread like that.  Qt QML threaded rendering will
block the main thread on a condition that's signaled by a rendering
thread after it finishes rendering.  This leads to a deadlock when the
rendering threads blocks in eglSwapBuffers(), and the main thread is
waiting on the condition.  Another problematic use case is with games
that has a rendering thread for a splash screen while the main thread
is busy loading game data or compiling shaders.  The main thread isn't
responsive and ends up blocking eglSwapBuffers() in the rendering thread.

We also can't assume that there will be only one thread polling on the
file descriptor.  A valid use case is a thread receiving data from a
custom wayland interface as well as a device fd or network socket.
The thread may want to wait on either events from the wayland
interface or data from the fd, in which case it needs to poll on both
the wayland display fd and the device/network fd.

The solution seems pretty straightforward: just let all threads read
from the fd.  However, the main-thread restriction was introduced to
avoid a race.  Simplified, main loops will do something like this:

wl_display_dispatch_pending(display);

/* Race here if other thread reads from fd and places events
 * in main eent queue.  We go to sleep in poll while sitting on
 * events that may stall the application if not dispatched. */

poll(fds, nfds, -1);

/* Race here if other thread reads and doesn't queue any
 * events for main queue. wl_display_dispatch() below will block
 * trying to read from the fd, while other fds in the mainloop
 * are ignored. */

wl_display_dispatch(display);

The restriction that only the main thread can read from the fd avoids
these races, but has the problems described above.

This patch introduces new API to solve both problems.  We add

int wl_display_prepare_read(struct wl_display *display);

and

int wl_display_read_events(struct wl_display *display);

wl_display_prepare_read() registers the calling thread as a potential
reader of events.  Once data is available on the fd, all reader
threads must call wl_display_read_events(), at which point one of the
threads will read from the fd and distribute the events to event
queues.  When that is done, all threads return from
wl_display_read_events().

From the point of view of a single thread, this ensures that between
calling wl_display_prepare_read() and wl_display_read_events(), no
other thread will read from the fd and queue events in its event
queue.  This avoids the race conditions described above, and we avoid
relying on any one thread to be available to read events.

11 years agoserver: Add aditional wl_resource accessors
Jason Ekstrand [Fri, 14 Jun 2013 15:07:52 +0000 (10:07 -0500)]
server: Add aditional wl_resource accessors

Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
11 years agoprotocol: Add missing since attribute for name event on wl_seat
Rob Bradford [Wed, 12 Jun 2013 17:17:45 +0000 (18:17 +0100)]
protocol: Add missing since attribute for name event on wl_seat

This event was added in version 2 of the protocol.

11 years agobuild: Fix warning message on syscall failures
Rob Bradford [Wed, 12 Jun 2013 17:17:44 +0000 (18:17 +0100)]
build: Fix warning message on syscall failures

11 years agoserver: Add wl_resource_get_id()
Kristian Høgsberg [Fri, 7 Jun 2013 05:00:30 +0000 (01:00 -0400)]
server: Add wl_resource_get_id()

11 years agoUpdate tests for wl_map changes and add a map_flags test
Jason Ekstrand [Wed, 5 Jun 2013 14:52:39 +0000 (09:52 -0500)]
Update tests for wl_map changes and add a map_flags test

11 years agoRemove incorrect sanity-check from wl_map_insert_at
Jason Ekstrand [Wed, 5 Jun 2013 21:39:51 +0000 (16:39 -0500)]
Remove incorrect sanity-check from wl_map_insert_at

I got a little over-eager with my sanity checks and didn't realize that the
client uses wl_map_insert_at to mark objects as zombies when they come from
the server-side.

Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
11 years agoChange WL_ZOMBIE_OBJECT from 0x2 to an actual pointer
Jason Ekstrand [Wed, 5 Jun 2013 21:39:50 +0000 (16:39 -0500)]
Change WL_ZOMBIE_OBJECT from 0x2 to an actual pointer

In order to use the second-lowest bit of each pointer in wl_map for the
WL_MAP_ENTRY_LEGACY flag, every pointer has to be a multiple of 4.  This
was a good assumption, except with WL_ZOMBIE_OBJECT.  This commit creates
an actual static variable to which WL_ZOMBIE_OBJECT now points.  Since
things are only every compared to WL_ZOMBIE_OBJECT with "==" or "!=", the
only thing that matters is that it is unique.

Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
11 years agoprotocol: Move new name event below existing requests and events and version it
Kristian Høgsberg [Wed, 5 Jun 2013 05:07:28 +0000 (01:07 -0400)]
protocol: Move new name event below existing requests and events and version it

Missed v2 of Robs patch that already did this based on feedback from
Ander and Daniel.

11 years agoAdd accessor functions for wl_resource and deprecate wl_client_add_resource
Jason Ekstrand [Sat, 1 Jun 2013 22:40:54 +0000 (17:40 -0500)]
Add accessor functions for wl_resource and deprecate wl_client_add_resource

This is the first step towards making wl_resource an opaque pointer type.

Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
11 years agoAdd support for flags in the wl_map API and add a WL_MAP_ENTRY_LEGACY flag
Jason Ekstrand [Sat, 1 Jun 2013 22:40:53 +0000 (17:40 -0500)]
Add support for flags in the wl_map API and add a WL_MAP_ENTRY_LEGACY flag

The implementation in this commit allows for one bit worth of flags.  If
more flags are desired at a future date, then the wl_map implementation
will have to change but the wl_map API will not.

Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
11 years agoAdd a "side" field and some sanity checks to wl_map.
Jason Ekstrand [Sat, 1 Jun 2013 22:40:52 +0000 (17:40 -0500)]
Add a "side" field and some sanity checks to wl_map.

The original wl_map implementation did no checking to ensures that ids fell
on the correct side of the WL_SERVER_ID_START line.  This meant that a
client could send the server a server ID and it would happily try to use
it.  Also, there was no distinction between server-side and client-side in
wl_map_remove.  Because wl_map_remove added the entry to the free list
regardless of which side it came from, the following set of actions would
break the map:

1. Client creates a bunch of objects
2. Client deletes one or more of those objects
3. Client does something that causes the server to create an object

Because of the problem in wl_map_remove, the server would take an old
client-side id, apply the WL_SERVER_ID_START offset, and try to use it as a
server-side id regardless of whether or not it was valid.

Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
11 years agoprotocol: Add a name event to give seat name
Rob Bradford [Fri, 31 May 2013 17:08:23 +0000 (18:08 +0100)]
protocol: Add a name event to give seat name

This provides the ability for a client to differentiate events from
different seats in a multiple seat environment.

11 years agobuild: Add declaration checks to check for required syscall flags
Rob Bradford [Tue, 4 Jun 2013 12:27:49 +0000 (13:27 +0100)]
build: Add declaration checks to check for required syscall flags

The required flags are relatively new and some older enterprise distributions
do not feature them.

https://bugs.freedesktop.org/show_bug.cgi?id=63360

11 years agoprotocol: Modes are specified in HW pixels
Alexander Larsson [Tue, 28 May 2013 14:20:52 +0000 (16:20 +0200)]
protocol: Modes are specified in HW pixels

Modes are mainly meant to be used in coordination with fullscreen in
DRIVER mode, by e.g. games. For such games what they generally want
is to match some hardware mode and resize their window for that. We
don't really need to complicate this with the scaling. So, we
keep the resolutions in HW pixels, and drop the SCALED flag (as it
is now useless).

This lets you just create e.g an 800x600 buffer of scale 1 and
fullscreen that, ignoring the output scaling factor (although you can
of course also respect it and create a 400x300 surface at scale 2).
Conceptually the mode change is treated like a scaling which overrides
the normal output scale.

The only complexity is the FILL mode where it can happen that the user
specifies a buffer of the same size as the screen, but the output has scale
2 and the buffer scale 1. Just scanning out this buffer will work, but
effectively this is a downscaling operation, as the "real" size of the surface
in pels is twice the size of the output. We solve this by allowing FILL to
downscale (but still not upscale).