Commit graph

1440 commits

Author SHA1 Message Date
Kristian Høgsberg
853c24e699 client: Introduce functions to allocate and marshal proxies atomically
The server requires clients to only allocate one ID ahead of the previously
highest ID in order to keep the ID range tight.  Failure to do so will
make the server close the client connection.  However, the way we allocate
new IDs is racy.  The generated code looks like:

  new_proxy = wl_proxy_create(...);
  wl_proxy_marshal(proxy, ... new_proxy, ...);

If two threads do this at the same time, there's a chance that thread A
will allocate a proxy, then get pre-empted by thread B which then allocates
a proxy and then passes it to wl_proxy_marshal().  The ID for thread As
proxy will be one higher that the currently highest ID, but the ID for
thread Bs proxy will be two higher.  But since thread B prempted thread A
before it could send its new ID, B will send its new ID first, the server
will see the ID from thread Bs proxy first, and will reject it.

We fix this by introducing wl_proxy_marshal_constructor().  This
function is identical to wl_proxy_marshal(), except that it will
allocate a wl_proxy for NEW_ID arguments and send it, all under the
display mutex.  By introducing a new function, we maintain backwards
compatibility with older code from the generator, and make sure that
the new generated code has an explicit dependency on a new enough
libwayland-client.so.

A virtual Wayland merit badge goes to Kalle Vahlman, who tracked this
down and analyzed the issue.

Reported-by: Kalle Vahlman <kalle.vahlman@movial.com>
2013-11-15 20:49:36 -08:00
Pekka Paalanen
81c57614d1 protocol: add sub-surfaces to the core
The sub-surface protocol was originally committed into Weston on May
10th, 2013, in commit 2396aec6842c709a714f3825dbad9fd88478f2e6. The
design for the protocol had started in the beginning of December 2012. I
think it is high time to move this into the core now.

This patch copies the sub-surface protocol as it was in Weston on Nov
15th, 2013, into Wayland. Weston gets a patch to remove the protocol from
there.

Sub-surface is a wl_surface role. You create a wl_surface as usual, and
assign it the sub-surface role and a parent wl_surface. Sub-surfaces are
an integral part of the parent surface, and stay glued to the parent.
For window management, a window is the union of the top-level
wl_surface and all its sub-surfaces. Sub-surfaces are not clipped to the
parent, and the union of the surface tree can be larger than the
(top-level) wl_surface at its root.

The representative use case for sub-surfaces is a video player window.
When the video content is given its own wl_surface, there is no need to
modify the video frame contents after decoding or copy them into a whole
window sized buffer before submitting it to the compositor. This allows
efficient, zero-copy video presentation paths, where video decoding
hardware produces a (YUV) buffer, which eventually ends up in a
(YUV-capable) hardware overlay and is scanned out directly.

This can also be used for zero-copy presentation of windowed OpenGL
content, where the OpenGL rendering engine does not need to draw or
avoid window decorations.

Sub-surfaces allow mixing different buffer types into the same window,
e.g. software-rendered decorations in wl_shm buffers, and live content
in EGL-based buffers.

However, the sub-surface extension does not offer clipping or scaling
facilities, or accurate presentation timing. Those are topics for
additional extensions.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2013-11-15 20:49:36 -08:00
Lubomir Rintel
4a196570a3 shm: Avoid file descriptor leak upon unsuccessful mmap
It would be possible to make the compositor leak file descriptors by
passing descriptors of open unmmapable files to it, such as /dev/null.

Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
2013-11-15 16:21:45 -08:00
Neil Roberts
c2bba88ccd Add documentation for wl_shm_buffer_begin/end_access
It's not obvious that these functions are needed so it would be good
to have some documentation for them.
2013-11-15 14:46:48 -08:00
Kristian Høgsberg
a71cf48ce0 scanner: Add location to elements so we can give better errors/warnings 2013-11-15 14:44:39 -08:00
Kristian Høgsberg
5a4dd76495 scanner: Make fail() function use va_list and elaborate a few errors 2013-11-15 14:44:39 -08:00
Kristian Høgsberg
db8ae8903f scanner: Introduce struct location for tracking source locations 2013-11-15 14:44:39 -08:00
Kristian Høgsberg
3470fa17b5 scanner: Warn about requests with more than one new-id and don't generate stubs
The generated code only support one new-id per request, since the stubs
return the new proxy.  It's still possible to send requests with multiple
new-id arguments, but it must be done with
wl_proxy_marshal_array_constructor().
2013-11-15 14:44:39 -08:00
Kristian Høgsberg
b583b54560 server: Start documenting the server side API
This is now public, stable API, so it seems prudent to actually document it.
2013-11-13 21:11:17 -08:00
Neil Roberts
cf4f5995dc 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.
2013-11-13 16:31:28 -08:00
Peter Hutterer
05f95c85c8 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.
2013-10-25 10:58:06 -07:00
Kristian Høgsberg
16b2dab4e4 configure.ac: Bump version to 1.3.90 for the master branch 2013-10-23 09:25:08 -07:00
Kristian Høgsberg
deddea6549 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
2013-10-21 14:39:06 -07:00
José Bollo
84247b7513 protocol: Fix typo in documentation 2013-10-11 10:04:43 -07:00
Kristian Høgsberg
2c3dbb8903 configure.ac: Bump version to 1.3 2013-10-09 16:20:54 -07:00
Kristian Høgsberg
bb6f6faaa2 scanner: Handle unrecognized invocation mode
Print usage if we don't recognize the invocation mode.  Also fixes
uninitialized variable warning.
2013-10-07 21:36:31 -07:00
Kristian Høgsberg
260d73b449 configure.ac: Bump version to 1.2.92 2013-10-02 22:14:57 -07:00
Neil Roberts
799ea7206b 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.
2013-09-25 10:11:20 -07:00
Kristian Høgsberg
4125367f20 configure.ac: Bump version to 1.2.91 2013-09-22 14:12:26 -07:00
Jason Ekstrand
ba90497b87 Export the Wayland protocol XML file
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-09-21 21:48:56 -07:00
Marek Ch
b99edb8b7e tests: add wl_resource tests 2013-09-21 11:38:32 -07:00
Marek Ch
6f1569bd38 tests: add unit tests for wl_signal
Test wl_signal initialization, adding and getting listeners and emitting
2013-09-21 11:37:38 -07:00
Marek Ch
ec08c5c3e9 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.
2013-09-21 11:36:33 -07:00
Chang Liu
5cf31443c5 client: fix an inconsistency in documentation
The errno is set to EAGAIN when there are undispatched events, according
to L1066 of wayland-client.c.
2013-09-21 11:34:57 -07:00
Aaron Faanes
5a92553237 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.
2013-09-21 11:31:50 -07:00
Aaron Faanes
8267f283dc utils: Document wl_container_of 2013-09-21 11:31:41 -07:00
Aaron Faanes
217909c18d 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>
2013-09-21 11:29:08 -07:00
Aaron Faanes
2e3af5e5d7 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.
2013-09-16 22:00:00 -07:00
Aaron Faanes
5197aa30c8 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.
2013-09-16 21:59:28 -07:00
Aaron Faanes
fffcdb25de 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.
2013-09-16 21:59:12 -07:00
Aaron Faanes
bc30c5eb8a utils: Reference some useful methods in wl_signal's doxygen
This commit adds a bit more detail on the lifecycle of a signal.
2013-09-16 21:59:00 -07:00
Aaron Faanes
f8b2730039 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.
2013-09-16 21:47:52 -07:00
Chang Liu
9a5ed7877d gitignore: add ./compile
./compile is a GNU autotools helper script and should be ignored by git
2013-09-11 12:15:11 -07:00
Rob Bradford
656f3ea5b3 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.
2013-09-11 12:03:22 -07:00
Aaron Faanes
a27b730490 utils: tweak wl_list for better doxygen output 2013-09-11 10:53:39 -07:00
Aaron Faanes
660f2d7acc wayland-server: Document wl_signal 2013-09-11 10:52:41 -07:00
Aaron Faanes
cdea669858 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.
2013-09-11 10:42:37 -07:00
Kristian Høgsberg
10dcf86f7d configure.ac: Bump version to 1.2.90 for master branch 2013-08-30 15:53:55 -07:00
Kristian Høgsberg
b76a6968fc 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.
2013-08-30 15:53:55 -07:00
Kristian Høgsberg
ea1fb51aae 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.
2013-08-30 15:46:41 -07:00
Jason Ekstrand
eb947e9408 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>
2013-08-19 16:23:08 -07:00
Jason Ekstrand
c44090908d 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>
2013-08-19 16:23:08 -07:00
Jason Ekstrand
6b8eef962f 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>
2013-08-19 16:23:08 -07:00
Jason Ekstrand
52de023482 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>
2013-08-19 16:23:02 -07:00
Peter Hutterer
2cc551b1ec 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.
2013-08-15 14:42:44 -07:00
Bryce W. Harrington
f169614738 protocol: Improve a bit of grammar for wl_surface::attach description
Signed-off-by: Bryce Harrington <b.harrington@samsung.com>
2013-08-12 21:25:48 -07:00
Rob Bradford
4ad58fbb4a 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.
2013-08-12 16:26:36 -07:00
Rob Bradford
748c20c46f 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.
2013-08-12 16:26:36 -07:00
Bryce W. Harrington
dbc41f0344 protocol: Fix pluralization of user in popup_done description
Signed-off-by: Bryce Harrington <b.harrington@samsung.com>
2013-08-08 21:42:38 -07:00
Bryce W. Harrington
b5e7f9caef protocol: Improve grammar for set class description
Signed-off-by: Bryce Harrington <b.harrington@samsung.com>
2013-08-08 21:42:26 -07:00