<p dir="ltr"><br>
On Apr 2, 2014 8:31 AM, "Manuel Bachmann" <<a href="mailto:manuel.bachmann@open.eurogiciel.org">manuel.bachmann@open.eurogiciel.org</a>> wrote:<br>
><br>
> HI Jason,<br>
>  <br>
> Thanks for submitting this interesting patch ; just tested it, works very well !<br>
>  <br>
> There's one missing thing, though : in "screen-share.c", you're using the "os_create_create_anonymous_file()" function, which takes an off_t  as a parameter.<br>
> To make sure that off_t is defined as 64-bit, even on 32-bit systems, you should<br>
>  <br>
> #include "config.h"<br>
>  <br>
> at the beginning ; otherwise building on a 32-bit OS will break.</p>
<p dir="ltr">Thanks, Manuel.  I'll get that fixed in my local version and make sure it gets in the next patch series.</p>
<p dir="ltr">Thanks,<br>
--Jason Ekstrand</p>
<p dir="ltr">>  <br>
> Regards,<br>
> Manuel<br>
><br>
> 2014-02-26 2:26 GMT+01:00 Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>>:<br>
>><br>
>> This adds a plugin called screen-share.so.  If the screen-share.so module<br>
>> is imported, it will add the CTRL+ALT+s keybinding to start a screen<br>
>> sharing session.  If you press CTRL+ALT+S, weston will spawn another copy<br>
>> of weston, this time with the RDP backend, and mirrors the current screen<br>
>> to it and adds any seats from RDP as aditional seats.  The current screen<br>
>> is defined as the one with the mouse pointer.  Currently the CTRL+ALT+s<br>
>> keybinding is hardcoded as the only way to activate screen sharing.  If, at<br>
>> some point, shells want more control over the screen sharing process, the<br>
>> API's should be easy to update and export to make this possible.<br>
>><br>
>> For security, the command and path to weston is currently hard-coded.  It<br>
>> would not take much aditional code to make this configurable or to allow a<br>
>> shell to launch other screen-sharing programs.  However, handling those<br>
>> security issues is outside the scope of this patch so it is hard-coded for<br>
>> now.<br>
>><br>
>> Signed-off-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br>
>> ---<br>
>>  Makefile.am        |   22 ++<br>
>>  <a href="http://configure.ac">configure.ac</a>       |   13 +<br>
>>  src/screen-share.c | 1082 ++++++++++++++++++++++++++++++++++++++++++++++++++++<br>
>>  3 files changed, 1117 insertions(+)<br>
>>  create mode 100644 src/screen-share.c<br>
>><br>
>> diff --git a/Makefile.am b/Makefile.am<br>
>> index 838a051..f0fbec1 100644<br>
>> --- a/Makefile.am<br>
>> +++ b/Makefile.am<br>
>> @@ -707,6 +707,28 @@ nodist_fullscreen_shell_la_SOURCES =                       \<br>
>>         protocol/fullscreen-shell-server-protocol.h<br>
>>  endif<br>
>><br>
>> +if ENABLE_SCREEN_SHARING<br>
>> +<br>
>> +module_LTLIBRARIES += <a href="http://screen-share.la">screen-share.la</a><br>
>> +<br>
>> +screen_share_la_CPPFLAGS = $(AM_CPPFLAGS) -DBINDIR='"$(bindir)"'<br>
>> +screen_share_la_LDFLAGS = -module -avoid-version<br>
>> +screen_share_la_LIBADD =                       \<br>
>> +       $(COMPOSITOR_LIBS)                      \<br>
>> +       $(SCREEN_SHARE_LIBS)                    \<br>
>> +       <a href="http://libshared-cairo.la">libshared-cairo.la</a><br>
>> +screen_share_la_CFLAGS =                       \<br>
>> +       $(COMPOSITOR_CFLAGS)                    \<br>
>> +       $(SCREEN_SHARE_CFLAGS)                  \<br>
>> +       $(GCC_CFLAGS)<br>
>> +screen_share_la_SOURCES =                      \<br>
>> +       src/screen-share.c<br>
>> +nodist_screen_share_la_SOURCES =                       \<br>
>> +       protocol/fullscreen-shell-protocol.c            \<br>
>> +       protocol/fullscreen-shell-client-protocol.h<br>
>> +<br>
>> +endif<br>
>> +<br>
>>  if ENABLE_XWAYLAND<br>
>><br>
>>  module_LTLIBRARIES += <a href="http://xwayland.la">xwayland.la</a><br>
>> diff --git a/<a href="http://configure.ac">configure.ac</a> b/<a href="http://configure.ac">configure.ac</a><br>
>> index 0809614..27fd536 100644<br>
>> --- a/<a href="http://configure.ac">configure.ac</a><br>
>> +++ b/<a href="http://configure.ac">configure.ac</a><br>
>> @@ -212,6 +212,18 @@ if test x$enable_rdp_compositor = xyes; then<br>
>>    CPPFLAGS="$SAVED_CPPFLAGS"<br>
>>  fi<br>
>><br>
>> +AC_ARG_ENABLE([screen-sharing], [--enable-screen-sharing],,<br>
>> +              enable_screen_sharing=no)<br>
>> +AM_CONDITIONAL([ENABLE_SCREEN_SHARING],<br>
>> +               [test x$enable_screen_sharing = xyes])<br>
>> +if test x$enable_screen_sharing = xyes; then<br>
>> +  PKG_CHECK_MODULES(SCREEN_SHARE, [wayland-client])<br>
>> +<br>
>> +  if test x$enable_rdp_compositor != xyes; then<br>
>> +    AC_MSG_WARN([The screen-share.so module requires the RDP backend to work properly.])<br>
>> +  fi<br>
>> +fi<br>
>> +<br>
>>  AC_ARG_WITH(cairo,<br>
>>             AS_HELP_STRING([--with-cairo=@<:@image|gl|glesv2@:>@]<br>
>>                            [Which Cairo renderer to use for the clients]),<br>
>> @@ -513,6 +525,7 @@ AC_MSG_RESULT([<br>
>>         RPI Compositor                  ${enable_rpi_compositor}<br>
>>         FBDEV Compositor                ${enable_fbdev_compositor}<br>
>>         RDP Compositor                  ${enable_rdp_compositor}<br>
>> +       Screen Sharing                  ${enable_screen_sharing}<br>
>><br>
>>         Raspberry Pi BCM headers        ${have_bcm_host}<br>
>><br>
>> diff --git a/src/screen-share.c b/src/screen-share.c<br>
>> new file mode 100644<br>
>> index 0000000..6cc6bd5<br>
>> --- /dev/null<br>
>> +++ b/src/screen-share.c<br>
>> @@ -0,0 +1,1082 @@<br>
>> +/*<br>
>> + * Copyright © 2008-2011 Kristian Høgsberg<br>
>> + * Copyright © 2014 Jason Ekstrand<br>
>> + *<br>
>> + * Permission to use, copy, modify, distribute, and sell this software and<br>
>> + * its documentation for any purpose is hereby granted without fee, provided<br>
>> + * that the above copyright notice appear in all copies and that both that<br>
>> + * copyright notice and this permission notice appear in supporting<br>
>> + * documentation, and that the name of the copyright holders not be used in<br>
>> + * advertising or publicity pertaining to distribution of the software<br>
>> + * without specific, written prior permission.  The copyright holders make<br>
>> + * no representations about the suitability of this software for any<br>
>> + * purpose.  It is provided "as is" without express or implied warranty.<br>
>> + *<br>
>> + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS<br>
>> + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND<br>
>> + * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY<br>
>> + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER<br>
>> + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF<br>
>> + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN<br>
>> + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.<br>
>> + */<br>
>> +<br>
>> +#include <stdlib.h><br>
>> +#include <stdio.h><br>
>> +#include <string.h><br>
>> +#include <unistd.h><br>
>> +#include <sys/socket.h><br>
>> +#include <sys/mman.h><br>
>> +#include <signal.h><br>
>> +#include <linux/input.h><br>
>> +#include <errno.h><br>
>> +<br>
>> +#include <wayland-client.h><br>
>> +<br>
>> +#include "compositor.h"<br>
>> +#include "../shared/os-compatibility.h"<br>
>> +#include "fullscreen-shell-client-protocol.h"<br>
>> +<br>
>> +struct shared_output {<br>
>> +       struct weston_output *output;<br>
>> +       struct wl_listener output_destroyed;<br>
>> +       struct wl_list seat_list;<br>
>> +<br>
>> +       struct {<br>
>> +               struct wl_display *display;<br>
>> +               struct wl_registry *registry;<br>
>> +               struct wl_compositor *compositor;<br>
>> +               struct wl_shm *shm;<br>
>> +               uint32_t shm_formats;<br>
>> +               struct wl_fullscreen_shell *fshell;<br>
>> +               struct wl_output *output;<br>
>> +               struct wl_surface *surface;<br>
>> +               struct wl_callback *frame_cb;<br>
>> +               struct wl_fullscreen_shell_mode_feedback *mode_feedback;<br>
>> +       } parent;<br>
>> +<br>
>> +       struct wl_event_source *event_source;<br>
>> +       struct wl_listener frame_listener;<br>
>> +<br>
>> +       struct {<br>
>> +               int32_t width, height;<br>
>> +<br>
>> +               struct wl_list buffers;<br>
>> +               struct wl_list free_buffers;<br>
>> +       } shm;<br>
>> +<br>
>> +       int cache_dirty;<br>
>> +       pixman_image_t *cache_image;<br>
>> +       uint32_t *tmp_data;<br>
>> +       size_t tmp_data_size;<br>
>> +};<br>
>> +<br>
>> +struct ss_seat {<br>
>> +       struct weston_seat base;<br>
>> +       struct shared_output *output;<br>
>> +       struct wl_list link;<br>
>> +<br>
>> +       struct {<br>
>> +               struct wl_seat *seat;<br>
>> +               struct wl_pointer *pointer;<br>
>> +               struct wl_keyboard *keyboard;<br>
>> +       } parent;<br>
>> +<br>
>> +       enum weston_key_state_update keyboard_state_update;<br>
>> +       uint32_t key_serial;<br>
>> +};<br>
>> +<br>
>> +struct ss_shm_buffer {<br>
>> +       struct shared_output *output;<br>
>> +       struct wl_list link;<br>
>> +       struct wl_list free_link;<br>
>> +<br>
>> +       struct wl_buffer *buffer;<br>
>> +       void *data;<br>
>> +       size_t size;<br>
>> +       pixman_region32_t damage;<br>
>> +<br>
>> +       pixman_image_t *pm_image;<br>
>> +};<br>
>> +<br>
>> +static void<br>
>> +ss_seat_handle_pointer_enter(void *data, struct wl_pointer *pointer,<br>
>> +                            uint32_t serial, struct wl_surface *surface,<br>
>> +                            wl_fixed_t x, wl_fixed_t y)<br>
>> +{<br>
>> +       struct ss_seat *seat = data;<br>
>> +<br>
>> +       /* We make the tacit assumption here that we are always recieving<br>
>> +        * input in output coordinates.<br>
>> +       weston_output_transform_coordinate(&seat->output->base, x, y, &x, &y);<br>
>> +        */<br>
>> +<br>
>> +       notify_pointer_focus(&seat->base, NULL, 0, 0);<br>
>> +}<br>
>> +<br>
>> +static void<br>
>> +ss_seat_handle_pointer_leave(void *data, struct wl_pointer *pointer,<br>
>> +                            uint32_t serial, struct wl_surface *surface)<br>
>> +{<br>
>> +       struct ss_seat *seat = data;<br>
>> +<br>
>> +       notify_pointer_focus(&seat->base, NULL, 0, 0);<br>
>> +}<br>
>> +<br>
>> +static void<br>
>> +ss_seat_handle_motion(void *data, struct wl_pointer *pointer,<br>
>> +                     uint32_t time, wl_fixed_t x, wl_fixed_t y)<br>
>> +{<br>
>> +       struct ss_seat *seat = data;<br>
>> +<br>
>> +       /* We make the tacit assumption here that we are always recieving<br>
>> +        * input in output coordinates.<br>
>> +       weston_output_transform_coordinate(&seat->output->base, x, y, &x, &y);<br>
>> +        */<br>
>> +<br>
>> +       notify_motion_absolute(&seat->base, time, x, y);<br>
>> +}<br>
>> +<br>
>> +static void<br>
>> +ss_seat_handle_button(void *data, struct wl_pointer *pointer,<br>
>> +                     uint32_t serial, uint32_t time, uint32_t button,<br>
>> +                     uint32_t state)<br>
>> +{<br>
>> +       struct ss_seat *seat = data;<br>
>> +<br>
>> +       notify_button(&seat->base, time, button, state);<br>
>> +}<br>
>> +<br>
>> +static void<br>
>> +ss_seat_handle_axis(void *data, struct wl_pointer *pointer,<br>
>> +                   uint32_t time, uint32_t axis, wl_fixed_t value)<br>
>> +{<br>
>> +       struct ss_seat *seat = data;<br>
>> +<br>
>> +       notify_axis(&seat->base, time, axis, value);<br>
>> +}<br>
>> +<br>
>> +static const struct wl_pointer_listener ss_seat_pointer_listener = {<br>
>> +       ss_seat_handle_pointer_enter,<br>
>> +       ss_seat_handle_pointer_leave,<br>
>> +       ss_seat_handle_motion,<br>
>> +       ss_seat_handle_button,<br>
>> +       ss_seat_handle_axis,<br>
>> +};<br>
>> +<br>
>> +static void<br>
>> +ss_seat_handle_keymap(void *data, struct wl_keyboard *keyboard,<br>
>> +                     uint32_t format, int fd, uint32_t size)<br>
>> +{<br>
>> +       struct ss_seat *seat = data;<br>
>> +       struct xkb_keymap *keymap;<br>
>> +       char *map_str;<br>
>> +<br>
>> +       if (!data)<br>
>> +               goto error;<br>
>> +<br>
>> +       if (format == WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) {<br>
>> +               map_str = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);<br>
>> +               if (map_str == MAP_FAILED) {<br>
>> +                       weston_log("mmap failed: %m\n");<br>
>> +                       goto error;<br>
>> +               }<br>
>> +<br>
>> +               keymap = xkb_map_new_from_string(seat->base.compositor->xkb_context,<br>
>> +                                                map_str,<br>
>> +                                                XKB_KEYMAP_FORMAT_TEXT_V1,<br>
>> +                                                0);<br>
>> +               munmap(map_str, size);<br>
>> +<br>
>> +               if (!keymap) {<br>
>> +                       weston_log("failed to compile keymap\n");<br>
>> +                       goto error;<br>
>> +               }<br>
>> +<br>
>> +               seat->keyboard_state_update = STATE_UPDATE_NONE;<br>
>> +       } else if (format == WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP) {<br>
>> +               weston_log("No keymap provided; falling back to defalt\n");<br>
>> +               keymap = NULL;<br>
>> +               seat->keyboard_state_update = STATE_UPDATE_AUTOMATIC;<br>
>> +       } else {<br>
>> +               weston_log("Invalid keymap\n");<br>
>> +               goto error;<br>
>> +       }<br>
>> +<br>
>> +       close(fd);<br>
>> +<br>
>> +       if (seat->base.keyboard)<br>
>> +               weston_seat_update_keymap(&seat->base, keymap);<br>
>> +       else<br>
>> +               weston_seat_init_keyboard(&seat->base, keymap);<br>
>> +<br>
>> +       if (keymap)<br>
>> +               xkb_map_unref(keymap);<br>
>> +<br>
>> +       return;<br>
>> +<br>
>> +error:<br>
>> +       wl_keyboard_release(seat->parent.keyboard);<br>
>> +       close(fd);<br>
>> +}<br>
>> +<br>
>> +static void<br>
>> +ss_seat_handle_keyboard_enter(void *data, struct wl_keyboard *keyboard,<br>
>> +                             uint32_t serial, struct wl_surface *surface,<br>
>> +                             struct wl_array *keys)<br>
>> +{<br>
>> +       struct ss_seat *seat = data;<br>
>> +<br>
>> +       /* XXX: If we get a modifier event immediately before the focus,<br>
>> +        *      we should try to keep the same serial. */<br>
>> +       notify_keyboard_focus_in(&seat->base, keys,<br>
>> +                                STATE_UPDATE_AUTOMATIC);<br>
>> +}<br>
>> +<br>
>> +static void<br>
>> +ss_seat_handle_keyboard_leave(void *data, struct wl_keyboard *keyboard,<br>
>> +                             uint32_t serial, struct wl_surface *surface)<br>
>> +{<br>
>> +       struct ss_seat *seat = data;<br>
>> +<br>
>> +       notify_keyboard_focus_out(&seat->base);<br>
>> +}<br>
>> +<br>
>> +static void<br>
>> +ss_seat_handle_key(void *data, struct wl_keyboard *keyboard,<br>
>> +                  uint32_t serial, uint32_t time,<br>
>> +                  uint32_t key, uint32_t state)<br>
>> +{<br>
>> +       struct ss_seat *seat = data;<br>
>> +<br>
>> +       seat->key_serial = serial;<br>
>> +       notify_key(&seat->base, time, key,<br>
>> +                  state ? WL_KEYBOARD_KEY_STATE_PRESSED :<br>
>> +                          WL_KEYBOARD_KEY_STATE_RELEASED,<br>
>> +                  seat->keyboard_state_update);<br>
>> +}<br>
>> +<br>
>> +static void<br>
>> +ss_seat_handle_modifiers(void *data, struct wl_keyboard *keyboard,<br>
>> +                        uint32_t serial_in, uint32_t mods_depressed,<br>
>> +                        uint32_t mods_latched, uint32_t mods_locked,<br>
>> +                        uint32_t group)<br>
>> +{<br>
>> +       struct ss_seat *seat = data;<br>
>> +       struct weston_compositor *c = seat->output->output->compositor;<br>
>> +       uint32_t serial_out;<br>
>> +<br>
>> +       /* If we get a key event followed by a modifier event with the<br>
>> +        * same serial number, then we try to preserve those semantics by<br>
>> +        * reusing the same serial number on the way out too. */<br>
>> +       if (serial_in == seat->key_serial)<br>
>> +               serial_out = wl_display_get_serial(c->wl_display);<br>
>> +       else<br>
>> +               serial_out = wl_display_next_serial(c->wl_display);<br>
>> +<br>
>> +       xkb_state_update_mask(seat->base.keyboard->xkb_state.state,<br>
>> +                             mods_depressed, mods_latched,<br>
>> +                             mods_locked, 0, 0, group);<br>
>> +       notify_modifiers(&seat->base, serial_out);<br>
>> +}<br>
>> +<br>
>> +static const struct wl_keyboard_listener ss_seat_keyboard_listener = {<br>
>> +       ss_seat_handle_keymap,<br>
>> +       ss_seat_handle_keyboard_enter,<br>
>> +       ss_seat_handle_keyboard_leave,<br>
>> +       ss_seat_handle_key,<br>
>> +       ss_seat_handle_modifiers,<br>
>> +};<br>
>> +<br>
>> +static void<br>
>> +ss_seat_handle_capabilities(void *data, struct wl_seat *seat,<br>
>> +                           enum wl_seat_capability caps)<br>
>> +{<br>
>> +       struct ss_seat *ss_seat = data;<br>
>> +<br>
>> +       if ((caps & WL_SEAT_CAPABILITY_POINTER) && !ss_seat->parent.pointer) {<br>
>> +               ss_seat->parent.pointer = wl_seat_get_pointer(seat);<br>
>> +               wl_pointer_set_user_data(ss_seat->parent.pointer, ss_seat);<br>
>> +               wl_pointer_add_listener(ss_seat->parent.pointer,<br>
>> +                                       &ss_seat_pointer_listener, ss_seat);<br>
>> +               weston_seat_init_pointer(&ss_seat->base);<br>
>> +       } else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && ss_seat->parent.pointer) {<br>
>> +               wl_pointer_destroy(ss_seat->parent.pointer);<br>
>> +               ss_seat->parent.pointer = NULL;<br>
>> +       }<br>
>> +<br>
>> +       if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !ss_seat->parent.keyboard) {<br>
>> +               ss_seat->parent.keyboard = wl_seat_get_keyboard(seat);<br>
>> +               wl_keyboard_set_user_data(ss_seat->parent.keyboard, ss_seat);<br>
>> +               wl_keyboard_add_listener(ss_seat->parent.keyboard,<br>
>> +                                        &ss_seat_keyboard_listener, ss_seat);<br>
>> +       } else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && ss_seat->parent.keyboard) {<br>
>> +               wl_keyboard_destroy(ss_seat->parent.keyboard);<br>
>> +               ss_seat->parent.keyboard = NULL;<br>
>> +       }<br>
>> +}<br>
>> +<br>
>> +static const struct wl_seat_listener ss_seat_listener = {<br>
>> +       ss_seat_handle_capabilities,<br>
>> +};<br>
>> +<br>
>> +static struct ss_seat *<br>
>> +ss_seat_create(struct shared_output *so, uint32_t id)<br>
>> +{<br>
>> +       struct ss_seat *seat;<br>
>> +<br>
>> +       seat = zalloc(sizeof *seat);<br>
>> +       if (seat == NULL)<br>
>> +               return NULL;<br>
>> +<br>
>> +       weston_seat_init(&seat->base, so->output->compositor, "default");<br>
>> +       seat->output = so;<br>
>> +       seat->parent.seat = wl_registry_bind(so->parent.registry, id,<br>
>> +                                            &wl_seat_interface, 1);<br>
>> +       wl_list_insert(so->seat_list.prev, &seat->link);<br>
>> +<br>
>> +       wl_seat_add_listener(seat->parent.seat, &ss_seat_listener, seat);<br>
>> +       wl_seat_set_user_data(seat->parent.seat, seat);<br>
>> +<br>
>> +       return seat;<br>
>> +}<br>
>> +<br>
>> +static void<br>
>> +ss_seat_destroy(struct ss_seat *seat)<br>
>> +{<br>
>> +       if (seat->parent.pointer)<br>
>> +               wl_pointer_release(seat->parent.pointer);<br>
>> +       if (seat->parent.keyboard)<br>
>> +               wl_keyboard_release(seat->parent.keyboard);<br>
>> +       wl_seat_destroy(seat->parent.seat);<br>
>> +<br>
>> +       wl_list_remove(&seat->link);<br>
>> +<br>
>> +       weston_seat_release(&seat->base);<br>
>> +<br>
>> +       free(seat);<br>
>> +}<br>
>> +<br>
>> +static void<br>
>> +ss_shm_buffer_destroy(struct ss_shm_buffer *buffer)<br>
>> +{<br>
>> +       pixman_image_unref(buffer->pm_image);<br>
>> +<br>
>> +       wl_buffer_destroy(buffer->buffer);<br>
>> +       munmap(buffer->data, buffer->size);<br>
>> +<br>
>> +       pixman_region32_fini(&buffer->damage);<br>
>> +<br>
>> +       wl_list_remove(&buffer->link);<br>
>> +       wl_list_remove(&buffer->free_link);<br>
>> +       free(buffer);<br>
>> +}<br>
>> +<br>
>> +static void<br>
>> +buffer_release(void *data, struct wl_buffer *buffer)<br>
>> +{<br>
>> +       struct ss_shm_buffer *sb = data;<br>
>> +<br>
>> +       if (sb->output) {<br>
>> +               wl_list_insert(&sb->output->shm.free_buffers, &sb->free_link);<br>
>> +       } else {<br>
>> +               ss_shm_buffer_destroy(sb);<br>
>> +       }<br>
>> +}<br>
>> +<br>
>> +static const struct wl_buffer_listener buffer_listener = {<br>
>> +       buffer_release<br>
>> +};<br>
>> +<br>
>> +static struct ss_shm_buffer *<br>
>> +shared_output_get_shm_buffer(struct shared_output *so)<br>
>> +{<br>
>> +       struct ss_shm_buffer *sb, *bnext;<br>
>> +       struct wl_shm_pool *pool;<br>
>> +       int width, height, stride;<br>
>> +       int fd;<br>
>> +       unsigned char *data;<br>
>> +<br>
>> +       width = so->output->width;<br>
>> +       height = so->output->height;<br>
>> +       stride = width * 4;<br>
>> +<br>
>> +       /* If the size of the output changed, we free the old buffers and<br>
>> +        * make new ones. */<br>
>> +       if (so->shm.width != width ||<br>
>> +           so->shm.height != height) {<br>
>> +<br>
>> +               /* Destroy free buffers */<br>
>> +               wl_list_for_each_safe(sb, bnext, &so->shm.free_buffers, link)<br>
>> +                       ss_shm_buffer_destroy(sb);<br>
>> +<br>
>> +               /* Orphan in-use buffers so they get destroyed */<br>
>> +               wl_list_for_each(sb, &so->shm.buffers, link)<br>
>> +                       sb->output = NULL;<br>
>> +<br>
>> +               so->shm.width = width;<br>
>> +               so->shm.height = height;<br>
>> +       }<br>
>> +<br>
>> +       if (!wl_list_empty(&so->shm.free_buffers)) {<br>
>> +               sb = container_of(so->shm.free_buffers.next,<br>
>> +                                 struct ss_shm_buffer, free_link);<br>
>> +               wl_list_remove(&sb->free_link);<br>
>> +               wl_list_init(&sb->free_link);<br>
>> +<br>
>> +               return sb;<br>
>> +       }<br>
>> +<br>
>> +       fd = os_create_anonymous_file(height * stride);<br>
>> +       if (fd < 0) {<br>
>> +               perror("os_create_anonymous_file");<br>
>> +               return NULL;<br>
>> +       }<br>
>> +<br>
>> +       data = mmap(NULL, height * stride, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);<br>
>> +       if (data == MAP_FAILED) {<br>
>> +               perror("mmap");<br>
>> +               close(fd);<br>
>> +               return NULL;<br>
>> +       }<br>
>> +<br>
>> +       sb = zalloc(sizeof *sb);<br>
>> +<br>
>> +       sb->output = so;<br>
>> +       wl_list_init(&sb->free_link);<br>
>> +       wl_list_insert(&so->shm.buffers, &sb->link);<br>
>> +<br>
>> +       pixman_region32_init_rect(&sb->damage, 0, 0, width, height);<br>
>> +<br>
>> +       sb->data = data;<br>
>> +       sb->size = height * stride;<br>
>> +<br>
>> +       pool = wl_shm_create_pool(so->parent.shm, fd, sb->size);<br>
>> +<br>
>> +       sb->buffer = wl_shm_pool_create_buffer(pool, 0,<br>
>> +                                              width, height, stride,<br>
>> +                                              WL_SHM_FORMAT_ARGB8888);<br>
>> +       wl_buffer_add_listener(sb->buffer, &buffer_listener, sb);<br>
>> +       wl_shm_pool_destroy(pool);<br>
>> +       close(fd);<br>
>> +<br>
>> +       memset(data, 0, sb->size);<br>
>> +<br>
>> +       sb->pm_image =<br>
>> +               pixman_image_create_bits(PIXMAN_a8r8g8b8, width, height,<br>
>> +                                        (uint32_t *)data, stride);<br>
>> +<br>
>> +       return sb;<br>
>> +}<br>
>> +<br>
>> +static void<br>
>> +output_compute_transform(struct weston_output *output,<br>
>> +                        pixman_transform_t *transform)<br>
>> +{<br>
>> +       pixman_fixed_t fw, fh;<br>
>> +<br>
>> +       pixman_transform_init_identity(transform);<br>
>> +<br>
>> +       fw = pixman_int_to_fixed(output->width);<br>
>> +       fh = pixman_int_to_fixed(output->height);<br>
>> +<br>
>> +       switch (output->transform) {<br>
>> +       case WL_OUTPUT_TRANSFORM_FLIPPED:<br>
>> +       case WL_OUTPUT_TRANSFORM_FLIPPED_90:<br>
>> +       case WL_OUTPUT_TRANSFORM_FLIPPED_180:<br>
>> +       case WL_OUTPUT_TRANSFORM_FLIPPED_270:<br>
>> +               pixman_transform_scale(transform, NULL,<br>
>> +                                      pixman_int_to_fixed (-1),<br>
>> +                                      pixman_int_to_fixed (1));<br>
>> +               pixman_transform_translate(transform, NULL, fw, 0);<br>
>> +       }<br>
>> +<br>
>> +       switch (output->transform) {<br>
>> +       default:<br>
>> +       case WL_OUTPUT_TRANSFORM_NORMAL:<br>
>> +       case WL_OUTPUT_TRANSFORM_FLIPPED:<br>
>> +               break;<br>
>> +       case WL_OUTPUT_TRANSFORM_90:<br>
>> +       case WL_OUTPUT_TRANSFORM_FLIPPED_90:<br>
>> +               pixman_transform_rotate(transform, NULL, 0, pixman_fixed_1);<br>
>> +               pixman_transform_translate(transform, NULL, fh, 0);<br>
>> +               break;<br>
>> +       case WL_OUTPUT_TRANSFORM_180:<br>
>> +       case WL_OUTPUT_TRANSFORM_FLIPPED_180:<br>
>> +               pixman_transform_rotate(transform, NULL, -pixman_fixed_1, 0);<br>
>> +               pixman_transform_translate(transform, NULL, fw, fh);<br>
>> +               break;<br>
>> +       case WL_OUTPUT_TRANSFORM_270:<br>
>> +       case WL_OUTPUT_TRANSFORM_FLIPPED_270:<br>
>> +               pixman_transform_rotate(transform, NULL, 0, -pixman_fixed_1);<br>
>> +               pixman_transform_translate(transform, NULL, 0, fw);<br>
>> +               break;<br>
>> +       }<br>
>> +<br>
>> +       pixman_transform_scale(transform, NULL,<br>
>> +                              pixman_fixed_1 * output->current_scale,<br>
>> +                              pixman_fixed_1 * output->current_scale);<br>
>> +}<br>
>> +<br>
>> +static void<br>
>> +shared_output_destroy(struct shared_output *so);<br>
>> +<br>
>> +static int<br>
>> +shared_output_ensure_tmp_data(struct shared_output *so,<br>
>> +                             pixman_region32_t *region)<br>
>> +{<br>
>> +       pixman_box32_t *ext;<br>
>> +       int32_t area;<br>
>> +       size_t size;<br>
>> +<br>
>> +       if (pixman_region32_not_empty(region)) {<br>
>> +               ext = pixman_region32_extents(region);<br>
>> +               area = (ext->x2 - ext->x1) * (ext->y2 - ext->y1);<br>
>> +       } else {<br>
>> +               return 0;<br>
>> +       }<br>
>> +<br>
>> +       /* Damage is in buffer coordinates */<br>
>> +       area *= so->output->current_scale * so->output->current_scale;<br>
>> +<br>
>> +       size = area * 4;<br>
>> +       if (so->tmp_data != NULL && size <= so->tmp_data_size)<br>
>> +               return 0;<br>
>> +<br>
>> +       free(so->tmp_data);<br>
>> +       so->tmp_data = malloc(size);<br>
>> +       if (so->tmp_data == NULL) {<br>
>> +               so->tmp_data_size = 0;<br>
>> +               errno = ENOMEM;<br>
>> +               return -1;<br>
>> +       }<br>
>> +<br>
>> +       so->tmp_data_size = size;<br>
>> +<br>
>> +       return 0;<br>
>> +}<br>
>> +<br>
>> +static void<br>
>> +shared_output_update(struct shared_output *so);<br>
>> +<br>
>> +static void<br>
>> +shared_output_frame_callback(void *data, struct wl_callback *cb, uint32_t time)<br>
>> +{<br>
>> +       struct shared_output *so = data;<br>
>> +<br>
>> +       if (cb != so->parent.frame_cb)<br>
>> +               return;<br>
>> +<br>
>> +       wl_callback_destroy(cb);<br>
>> +       so->parent.frame_cb = NULL;<br>
>> +<br>
>> +       shared_output_update(so);<br>
>> +}<br>
>> +<br>
>> +static const struct wl_callback_listener shared_output_frame_listener = {<br>
>> +       shared_output_frame_callback<br>
>> +};<br>
>> +<br>
>> +static void<br>
>> +shared_output_update(struct shared_output *so)<br>
>> +{<br>
>> +       struct ss_shm_buffer *sb;<br>
>> +       pixman_box32_t *r;<br>
>> +       int i, nrects;<br>
>> +       pixman_transform_t transform;<br>
>> +<br>
>> +       /* Only update if we need to */<br>
>> +       if (!so->cache_dirty || so->parent.frame_cb)<br>
>> +               return;<br>
>> +<br>
>> +       sb = shared_output_get_shm_buffer(so);<br>
>> +       if (sb == NULL) {<br>
>> +               shared_output_destroy(so);<br>
>> +               return;<br>
>> +       }<br>
>> +<br>
>> +       output_compute_transform(so->output, &transform);<br>
>> +       pixman_image_set_transform(so->cache_image, &transform);<br>
>> +<br>
>> +       pixman_image_set_clip_region32(sb->pm_image, &sb->damage);<br>
>> +<br>
>> +       pixman_image_composite32(PIXMAN_OP_SRC,<br>
>> +                                so->cache_image, /* src */<br>
>> +                                NULL, /* mask */<br>
>> +                                sb->pm_image, /* dest */<br>
>> +                                0, 0, /* src_x, src_y */<br>
>> +                                0, 0, /* mask_x, mask_y */<br>
>> +                                0, 0, /* dest_x, dest_y */<br>
>> +                                so->output->width, /* width */<br>
>> +                                so->output->height /* height */);<br>
>> +<br>
>> +       pixman_image_set_transform(sb->pm_image, NULL);<br>
>> +       pixman_image_set_clip_region32(sb->pm_image, NULL);<br>
>> +<br>
>> +       r = pixman_region32_rectangles(&sb->damage, &nrects);<br>
>> +       for (i = 0; i < nrects; ++i)<br>
>> +               wl_surface_damage(so->parent.surface, r[i].x1, r[i].y1,<br>
>> +                                 r[i].x2 - r[i].x1, r[i].y2 - r[i].y1);<br>
>> +<br>
>> +       wl_surface_attach(so->parent.surface, sb->buffer, 0, 0);<br>
>> +<br>
>> +       so->parent.frame_cb = wl_surface_frame(so->parent.surface);<br>
>> +       wl_callback_add_listener(so->parent.frame_cb,<br>
>> +                                &shared_output_frame_listener, so);<br>
>> +<br>
>> +       wl_surface_commit(so->parent.surface);<br>
>> +       wl_callback_destroy(wl_display_sync(so->parent.display));<br>
>> +       wl_display_flush(so->parent.display);<br>
>> +<br>
>> +       /* Clear the buffer damage */<br>
>> +       pixman_region32_fini(&sb->damage);<br>
>> +       pixman_region32_init(&sb->damage);<br>
>> +}<br>
>> +<br>
>> +static void<br>
>> +shm_handle_format(void *data, struct wl_shm *wl_shm, uint32_t format)<br>
>> +{<br>
>> +       struct shared_output *so = data;<br>
>> +<br>
>> +       so->parent.shm_formats |= (1 << format);<br>
>> +}<br>
>> +<br>
>> +struct wl_shm_listener shm_listener = {<br>
>> +       shm_handle_format<br>
>> +};<br>
>> +<br>
>> +static void<br>
>> +registry_handle_global(void *data, struct wl_registry *registry,<br>
>> +                      uint32_t id, const char *interface, uint32_t version)<br>
>> +{<br>
>> +       struct shared_output *so = data;<br>
>> +<br>
>> +       if (strcmp(interface, "wl_compositor") == 0) {<br>
>> +               so->parent.compositor =<br>
>> +                       wl_registry_bind(registry,<br>
>> +                                        id, &wl_compositor_interface, 1);<br>
>> +       } else if (strcmp(interface, "wl_output") == 0 && !so->parent.output) {<br>
>> +               so->parent.output =<br>
>> +                       wl_registry_bind(registry,<br>
>> +                                        id, &wl_output_interface, 1);<br>
>> +       } else if (strcmp(interface, "wl_seat") == 0) {<br>
>> +               ss_seat_create(so, id);<br>
>> +       } else if (strcmp(interface, "wl_shm") == 0) {<br>
>> +               so->parent.shm =<br>
>> +                       wl_registry_bind(registry,<br>
>> +                                        id, &wl_shm_interface, 1);<br>
>> +               wl_shm_add_listener(so->parent.shm, &shm_listener, so);<br>
>> +       } else if (strcmp(interface, "wl_fullscreen_shell") == 0) {<br>
>> +               so->parent.fshell =<br>
>> +                       wl_registry_bind(registry,<br>
>> +                                        id, &wl_fullscreen_shell_interface, 1);<br>
>> +       }<br>
>> +}<br>
>> +<br>
>> +static void<br>
>> +registry_handle_global_remove(void *data, struct wl_registry *registry,<br>
>> +                             uint32_t name)<br>
>> +{<br>
>> +}<br>
>> +<br>
>> +static const struct wl_registry_listener registry_listener = {<br>
>> +       registry_handle_global,<br>
>> +       registry_handle_global_remove<br>
>> +};<br>
>> +<br>
>> +static int<br>
>> +shared_output_handle_event(int fd, uint32_t mask, void *data)<br>
>> +{<br>
>> +       struct shared_output *so = data;<br>
>> +       int count = 0;<br>
>> +<br>
>> +       if ((mask & WL_EVENT_HANGUP) || (mask & WL_EVENT_ERROR)) {<br>
>> +               shared_output_destroy(so);<br>
>> +               return 0;<br>
>> +       }<br>
>> +<br>
>> +       if (mask & WL_EVENT_READABLE)<br>
>> +               count = wl_display_dispatch(so->parent.display);<br>
>> +       if (mask & WL_EVENT_WRITABLE)<br>
>> +               wl_display_flush(so->parent.display);<br>
>> +<br>
>> +       if (mask == 0) {<br>
>> +               count = wl_display_dispatch_pending(so->parent.display);<br>
>> +               wl_display_flush(so->parent.display);<br>
>> +       }<br>
>> +<br>
>> +       return count;<br>
>> +}<br>
>> +<br>
>> +static void<br>
>> +output_destroyed(struct wl_listener *l, void *data)<br>
>> +{<br>
>> +       struct shared_output *so;<br>
>> +<br>
>> +       so = container_of(l, struct shared_output, output_destroyed);<br>
>> +<br>
>> +       shared_output_destroy(so);<br>
>> +}<br>
>> +<br>
>> +static void<br>
>> +mode_feedback_ok(void *data, struct wl_fullscreen_shell_mode_feedback *fb)<br>
>> +{<br>
>> +       struct shared_output *so = data;<br>
>> +<br>
>> +       wl_fullscreen_shell_mode_feedback_destroy(so->parent.mode_feedback);<br>
>> +}<br>
>> +<br>
>> +static void<br>
>> +mode_feedback_failed(void *data, struct wl_fullscreen_shell_mode_feedback *fb)<br>
>> +{<br>
>> +       struct shared_output *so = data;<br>
>> +<br>
>> +       wl_fullscreen_shell_mode_feedback_destroy(so->parent.mode_feedback);<br>
>> +<br>
>> +       weston_log("Screen share failed: present_surface_for_mode failed\n");<br>
>> +       shared_output_destroy(so);<br>
>> +}<br>
>> +<br>
>> +struct wl_fullscreen_shell_mode_feedback_listener mode_feedback_listener = {<br>
>> +       mode_feedback_ok,<br>
>> +       mode_feedback_failed,<br>
>> +       mode_feedback_ok,<br>
>> +};<br>
>> +<br>
>> +static void<br>
>> +shared_output_repainted(struct wl_listener *listener, void *data)<br>
>> +{<br>
>> +       struct shared_output *so =<br>
>> +               container_of(listener, struct shared_output, frame_listener);<br>
>> +       pixman_region32_t damage;<br>
>> +       struct ss_shm_buffer *sb;<br>
>> +       int32_t x, y, width, height, stride;<br>
>> +       int i, nrects, do_yflip;<br>
>> +       pixman_box32_t *r;<br>
>> +       uint32_t *cache_data;<br>
>> +<br>
>> +       /* Damage in output coordinates */<br>
>> +       pixman_region32_init(&damage);<br>
>> +       pixman_region32_intersect(&damage, &so->output->region,<br>
>> +                                 &so->output->previous_damage);<br>
>> +       pixman_region32_translate(&damage, -so->output->x, -so->output->y);<br>
>> +<br>
>> +       /* Apply damage to all buffers */<br>
>> +       wl_list_for_each(sb, &so->shm.buffers, link)<br>
>> +               pixman_region32_union(&sb->damage, &sb->damage, &damage);<br>
>> +<br>
>> +       /* Transform to buffer coordinates */<br>
>> +       weston_transformed_region(so->output->width, so->output->height,<br>
>> +                                 so->output->transform,<br>
>> +                                 so->output->current_scale,<br>
>> +                                 &damage, &damage);<br>
>> +<br>
>> +       width = so->output->current_mode->width;<br>
>> +       height = so->output->current_mode->height;<br>
>> +       stride = width;<br>
>> +<br>
>> +       if (!so->cache_image ||<br>
>> +           pixman_image_get_width(so->cache_image) != width ||<br>
>> +           pixman_image_get_height(so->cache_image) != height) {<br>
>> +               if (so->cache_image)<br>
>> +                       pixman_image_unref(so->cache_image);<br>
>> +<br>
>> +               so->cache_image =<br>
>> +                       pixman_image_create_bits(PIXMAN_a8r8g8b8,<br>
>> +                                                width, height, NULL,<br>
>> +                                                stride);<br>
>> +               if (!so->cache_image) {<br>
>> +                       shared_output_destroy(so);<br>
>> +                       return;<br>
>> +               }<br>
>> +<br>
>> +               pixman_region32_fini(&damage);<br>
>> +               pixman_region32_init_rect(&damage, 0, 0, width, height);<br>
>> +       }<br>
>> +<br>
>> +       if (shared_output_ensure_tmp_data(so, &damage) < 0) {<br>
>> +               shared_output_destroy(so);<br>
>> +               return;<br>
>> +       }<br>
>> +<br>
>> +       do_yflip = !!(so->output->compositor->capabilities & WESTON_CAP_CAPTURE_YFLIP);<br>
>> +<br>
>> +       cache_data = pixman_image_get_data(so->cache_image);<br>
>> +       r = pixman_region32_rectangles(&damage, &nrects);<br>
>> +       for (i = 0; i < nrects; ++i) {<br>
>> +               x = r[i].x1;<br>
>> +               y = r[i].y1;<br>
>> +               width = r[i].x2 - r[i].x1;<br>
>> +               height = r[i].y2 - r[i].y1;<br>
>> +<br>
>> +               if (do_yflip) {<br>
>> +                       so->output->compositor->renderer->read_pixels(<br>
>> +                               so->output, PIXMAN_a8r8g8b8, so->tmp_data,<br>
>> +                               x, so->output->current_mode->height - r[i].y2,<br>
>> +                               width, height);<br>
>> +<br>
>> +                       pixman_blt(so->tmp_data, cache_data, -width, stride,<br>
>> +                                  32, 32, 0, 1 - height, x, y, width, height);<br>
>> +               } else {<br>
>> +                       so->output->compositor->renderer->read_pixels(<br>
>> +                               so->output, PIXMAN_a8r8g8b8, so->tmp_data,<br>
>> +                               x, y, width, height);<br>
>> +<br>
>> +                       pixman_blt(so->tmp_data, cache_data, width, stride,<br>
>> +                                  32, 32, 0, 0, x, y, width, height);<br>
>> +               }<br>
>> +       }<br>
>> +<br>
>> +       pixman_region32_fini(&damage);<br>
>> +<br>
>> +       so->cache_dirty = 1;<br>
>> +<br>
>> +       shared_output_update(so);<br>
>> +}<br>
>> +<br>
>> +static struct shared_output *<br>
>> +shared_output_create(struct weston_output *output, int parent_fd)<br>
>> +{<br>
>> +       struct shared_output *so;<br>
>> +       struct wl_event_loop *loop;<br>
>> +       struct ss_seat *seat;<br>
>> +       int epoll_fd;<br>
>> +<br>
>> +       so = zalloc(sizeof *so);<br>
>> +       if (so == NULL)<br>
>> +               goto err_close;<br>
>> +<br>
>> +       wl_list_init(&so->seat_list);<br>
>> +<br>
>> +       so->parent.display = wl_display_connect_to_fd(parent_fd);<br>
>> +       if (!so->parent.display)<br>
>> +               goto err_alloc;<br>
>> +<br>
>> +       so->parent.registry = wl_display_get_registry(so->parent.display);<br>
>> +       if (!so->parent.registry)<br>
>> +               goto err_display;<br>
>> +       wl_registry_add_listener(so->parent.registry,<br>
>> +                                &registry_listener, so);<br>
>> +       wl_display_roundtrip(so->parent.display);<br>
>> +       if (so->parent.shm == NULL) {<br>
>> +               weston_log("Screen share failed: No wl_shm found\n");<br>
>> +               goto err_display;<br>
>> +       }<br>
>> +       if (so->parent.fshell == NULL) {<br>
>> +               weston_log("Screen share failed: "<br>
>> +                          "Parent does not support wl_fullscreen_shell\n");<br>
>> +               goto err_display;<br>
>> +       }<br>
>> +       if (so->parent.compositor == NULL) {<br>
>> +               weston_log("Screen share failed: No wl_compositor found\n");<br>
>> +               goto err_display;<br>
>> +       }<br>
>> +<br>
>> +       /* Get SHM formats */<br>
>> +       wl_display_roundtrip(so->parent.display);<br>
>> +       if (!(so->parent.shm_formats & (1 << WL_SHM_FORMAT_XRGB8888))) {<br>
>> +               weston_log("Screen share failed: "<br>
>> +                          "WL_SHM_FORMAT_XRGB8888 not available\n");<br>
>> +               goto err_display;<br>
>> +       }<br>
>> +<br>
>> +       so->parent.surface =<br>
>> +               wl_compositor_create_surface(so->parent.compositor);<br>
>> +       if (!so->parent.surface) {<br>
>> +               weston_log("Screen share failed: %m");<br>
>> +               goto err_display;<br>
>> +       }<br>
>> +<br>
>> +       so->parent.mode_feedback =<br>
>> +               wl_fullscreen_shell_present_surface_for_mode(so->parent.fshell,<br>
>> +                                                            so->parent.surface,<br>
>> +                                                            so->parent.output,<br>
>> +                                                            output->current_mode->refresh);<br>
>> +       if (!so->parent.mode_feedback) {<br>
>> +               weston_log("Screen share failed: %m");<br>
>> +               goto err_display;<br>
>> +       }<br>
>> +       wl_fullscreen_shell_mode_feedback_add_listener(so->parent.mode_feedback,<br>
>> +                                                      &mode_feedback_listener,<br>
>> +                                                      so);<br>
>> +<br>
>> +       loop = wl_display_get_event_loop(output->compositor->wl_display);<br>
>> +<br>
>> +       epoll_fd = wl_display_get_fd(so->parent.display);<br>
>> +       so->event_source =<br>
>> +               wl_event_loop_add_fd(loop, epoll_fd, WL_EVENT_READABLE,<br>
>> +                                    shared_output_handle_event, so);<br>
>> +       if (!so->event_source) {<br>
>> +               weston_log("Screen share failed: %m");<br>
>> +               goto err_display;<br>
>> +       }<br>
>> +<br>
>> +       /* Ok, everything's created.  We should be good to go */<br>
>> +       wl_list_init(&so->shm.buffers);<br>
>> +       wl_list_init(&so->shm.free_buffers);<br>
>> +<br>
>> +       so->output = output;<br>
>> +       so->output_destroyed.notify = output_destroyed;<br>
>> +       wl_signal_add(&so->output->destroy_signal, &so->output_destroyed);<br>
>> +<br>
>> +       so->frame_listener.notify = shared_output_repainted;<br>
>> +       wl_signal_add(&output->frame_signal, &so->frame_listener);<br>
>> +       output->disable_planes++;<br>
>> +       weston_output_damage(output);<br>
>> +<br>
>> +       return so;<br>
>> +<br>
>> +err_display:<br>
>> +       wl_list_for_each(seat, &so->seat_list, link)<br>
>> +               ss_seat_destroy(seat);<br>
>> +       wl_display_disconnect(so->parent.display);<br>
>> +err_alloc:<br>
>> +       free(so);<br>
>> +err_close:<br>
>> +       close(parent_fd);<br>
>> +       return NULL;<br>
>> +}<br>
>> +<br>
>> +static void<br>
>> +shared_output_destroy(struct shared_output *so)<br>
>> +{<br>
>> +       struct ss_shm_buffer *buffer, *bnext;<br>
>> +<br>
>> +       wl_list_for_each_safe(buffer, bnext, &so->shm.buffers, link)<br>
>> +               ss_shm_buffer_destroy(buffer);<br>
>> +       wl_list_for_each_safe(buffer, bnext, &so->shm.free_buffers, link)<br>
>> +               ss_shm_buffer_destroy(buffer);<br>
>> +<br>
>> +       wl_display_disconnect(so->parent.display);<br>
>> +       wl_event_source_remove(so->event_source);<br>
>> +<br>
>> +       wl_list_remove(&so->output_destroyed.link);<br>
>> +       wl_list_remove(&so->frame_listener.link);<br>
>> +<br>
>> +       pixman_image_unref(so->cache_image);<br>
>> +       free(so->tmp_data);<br>
>> +<br>
>> +       free(so);<br>
>> +}<br>
>> +<br>
>> +static struct shared_output *<br>
>> +weston_output_share(struct weston_output *output,<br>
>> +                   const char *path, char *const argv[])<br>
>> +{<br>
>> +       int sv[2];<br>
>> +       char str[32];<br>
>> +       pid_t pid;<br>
>> +       sigset_t allsigs;<br>
>> +<br>
>> +       if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, sv) < 0) {<br>
>> +               weston_log("weston_output_share: socketpair failed: %m\n");<br>
>> +               return NULL;<br>
>> +       }<br>
>> +<br>
>> +       pid = fork();<br>
>> +<br>
>> +       if (pid == -1) {<br>
>> +               close(sv[0]);<br>
>> +               close(sv[1]);<br>
>> +               weston_log("weston_output_share: fork failed: %m\n");<br>
>> +               return NULL;<br>
>> +       }<br>
>> +<br>
>> +       if (pid == 0) {<br>
>> +               /* We don't want anything circular */<br>
>> +               unsetenv("WAYLAND_DISPLAY");<br>
>> +               unsetenv("WAYLAND_SOCKET");<br>
>> +<br>
>> +               setenv("WAYLAND_DEBUG", "server", 1);<br>
>> +<br>
>> +               /* do not give our signal mask to the new process */<br>
>> +               sigfillset(&allsigs);<br>
>> +               sigprocmask(SIG_UNBLOCK, &allsigs, NULL);<br>
>> +<br>
>> +               /* Launch clients as the user. Do not lauch clients with<br>
>> +                * wrong euid. */<br>
>> +               if (seteuid(getuid()) == -1) {<br>
>> +                       weston_log("weston_output_share: setuid failed: %m\n");<br>
>> +                       abort();<br>
>> +               }<br>
>> +<br>
>> +               sv[1] = dup(sv[1]);<br>
>> +               if (sv[1] == -1) {<br>
>> +                       weston_log("weston_output_share: dup failed: %m\n");<br>
>> +                       abort();<br>
>> +               }<br>
>> +<br>
>> +               snprintf(str, sizeof str, "%d", sv[1]);<br>
>> +               setenv("WAYLAND_SERVER_SOCKET", str, 1);<br>
>> +<br>
>> +               execv(path, argv);<br>
>> +               weston_log("weston_output_share: exec failed: %m\n");<br>
>> +               abort();<br>
>> +       } else {<br>
>> +               close(sv[1]);<br>
>> +               return shared_output_create(output, sv[0]);<br>
>> +       }<br>
>> +<br>
>> +       return NULL;<br>
>> +}<br>
>> +<br>
>> +static struct weston_output *<br>
>> +weston_output_find(struct weston_compositor *c, int32_t x, int32_t y)<br>
>> +{<br>
>> +       struct weston_output *output;<br>
>> +<br>
>> +       wl_list_for_each(output, &c->output_list, link) {<br>
>> +               if (x >= output->x && y >= output->y &&<br>
>> +                   x < output->x + output->width &&<br>
>> +                   y < output->y + output->height)<br>
>> +                       return output;<br>
>> +       }<br>
>> +<br>
>> +       return NULL;<br>
>> +}<br>
>> +<br>
>> +static void<br>
>> +share_output_binding(struct weston_seat *seat, uint32_t time, uint32_t key,<br>
>> +                    void *data)<br>
>> +{<br>
>> +       struct weston_output *output;<br>
>> +       const char *path = BINDIR "/weston";<br>
>> +       char width_arg[32], height_arg[32];<br>
>> +<br>
>> +       if (!seat->pointer) {<br>
>> +               weston_log("Cannot pick output: Seat does not have pointer\n");<br>
>> +               return;<br>
>> +       }<br>
>> +<br>
>> +       output = weston_output_find(seat->compositor,<br>
>> +                                   wl_fixed_to_int(seat->pointer->x),<br>
>> +                                   wl_fixed_to_int(seat->pointer->y));<br>
>> +       if (!output) {<br>
>> +               weston_log("Cannot pick output: Pointer not on any output\n");<br>
>> +               return;<br>
>> +       }<br>
>> +<br>
>> +       snprintf(width_arg, sizeof width_arg, "--width=%d", output->width);<br>
>> +       snprintf(height_arg, sizeof height_arg, "--height=%d", output->height);<br>
>> +<br>
>> +       char *const argv[] = {<br>
>> +               "weston",<br>
>> +               "--backend=rdp-backend.so",<br>
>> +               "--shell=fullscreen-shell.so",<br>
>> +               width_arg,<br>
>> +               height_arg,<br>
>> +               NULL<br>
>> +       };<br>
>> +<br>
>> +       weston_output_share(output, path, argv);<br>
>> +}<br>
>> +<br>
>> +WL_EXPORT int<br>
>> +module_init(struct weston_compositor *compositor,<br>
>> +           int *argc, char *argv[])<br>
>> +{<br>
>> +       weston_compositor_add_key_binding(compositor, KEY_S,<br>
>> +                                         MODIFIER_CTRL | MODIFIER_ALT,<br>
>> +                                         share_output_binding, compositor);<br>
>> +       return 0;<br>
>> +}<br>
>> --<br>
>> 1.8.5.3<br>
>><br>
>> _______________________________________________<br>
>> wayland-devel mailing list<br>
>> <a href="mailto:wayland-devel@lists.freedesktop.org">wayland-devel@lists.freedesktop.org</a><br>
>> <a href="http://lists.freedesktop.org/mailman/listinfo/wayland-devel">http://lists.freedesktop.org/mailman/listinfo/wayland-devel</a><br>
><br>
><br>
><br>
><br>
> -- <br>
> Regards,<br>
><br>
> Manuel BACHMANN<br>
> Tizen Project<br>
> VANNES-FR<br>
</p>