Commit Graph

52 Commits

Author SHA1 Message Date
Louis-Francis Ratté-Boulianne
c8c276c956 glamor: Implement PixmapFromBuffers and BuffersFromPixmap
It relies on GBM >= 17.1.0 where we can import BO with multiple
planes and a format modifier (GBM_BO_IMPORT_FD_MODIFIER).

v2: Properly free fds in Xwayland

[Also add glamor_egl_ext.h to Makefile.am for distcheck's sake - ajax]

Signed-off-by: Louis-Francis Ratté-Boulianne <lfrb@collabora.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
Acked-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2018-03-05 13:27:49 -05:00
Adam Jackson
67c303fff3 miinitext: Load GLX on the mi path
Add a stub for Xnest so it continues to link, but otherwise we support
GLX on every server so there's no need to make every DDX add it.

Signed-off-by: Adam Jackson <ajax@redhat.com>
2018-02-14 17:04:48 -05:00
Adam Jackson
d8ec33fe05 glx: Use vnd layer for dispatch (v4)
The big change here is MakeCurrent and context tag tracking. We now
delegate context tags entirely to the vnd layer, and simply store a
pointer to the context state as the tag data. If a context is deleted
while it's current, we allocate a fake ID for the context and move the
context state there, so the tag data still points to a real context. As
a result we can stop trying so hard to detach the client from contexts
at disconnect time and just let resource destruction handle it.

Since vnd handles all the MakeCurrent protocol now, our request handlers
for it can just be return BadImplementation. We also remove a bunch of
LEGAL_NEW_RESOURCE, because now by the time we're called vnd has already
allocated its tracking resource on that XID.

v2: Update to match v2 of the vnd import, and remove more redundant work
like request length checks.

v3: Add/remove the XID map from the vendor private thunk, not the
backend. (Kyle Brenneman)

v4: Fix deletion of ghost contexts (Kyle Brenneman)

Signed-off-by: Adam Jackson <ajax@redhat.com>
2018-02-14 17:04:44 -05:00
Lyude Paul
98edb9a35e xwayland: Don't process cursor warping without an xwl_seat
Unfortunately, on my machine Xwayland immediately crashes when I try to
start it. gdb backtrace:

 #0  0x00007ffff74f0e79 in wl_proxy_marshal () from target:/lib64/libwayland-client.so.0
 #1  0x0000000000413172 in zwp_confined_pointer_v1_destroy (zwp_confined_pointer_v1=0x700000000)
     at hw/xwayland/Xwayland@exe/pointer-constraints-unstable-v1-client-protocol.h:612
 #2  0x0000000000418bc0 in xwl_seat_destroy_confined_pointer (xwl_seat=0x8ba2a0)
     at /home/lyudess/Projects/xserver/hw/xwayland/xwayland-input.c:2839
 #3  0x0000000000418c09 in xwl_seat_unconfine_pointer (xwl_seat=0x8ba2a0)
     at /home/lyudess/Projects/xserver/hw/xwayland/xwayland-input.c:2849
 #4  0x0000000000410d97 in xwl_cursor_confined_to (device=0xa5a000, screen=0x8b9d80, window=0x9bdb70)
     at /home/lyudess/Projects/xserver/hw/xwayland/xwayland.c:328
 #5  0x00000000004a8571 in ConfineCursorToWindow (pDev=0xa5a000, pWin=0x9bdb70, generateEvents=1,
     confineToScreen=0) at /home/lyudess/Projects/xserver/dix/events.c:900
 #6  0x00000000004a94b7 in ScreenRestructured (pScreen=0x8b9d80)
     at /home/lyudess/Projects/xserver/dix/events.c:1387
 #7  0x0000000000502386 in RRScreenSizeNotify (pScreen=0x8b9d80)
     at /home/lyudess/Projects/xserver/randr/rrscreen.c:160
 #8  0x000000000041a83c in update_screen_size (xwl_output=0x8e7670, width=3840, height=2160)
     at /home/lyudess/Projects/xserver/hw/xwayland/xwayland-output.c:203
 #9  0x000000000041a9f0 in apply_output_change (xwl_output=0x8e7670)
     at /home/lyudess/Projects/xserver/hw/xwayland/xwayland-output.c:252
 #10 0x000000000041aaeb in xdg_output_handle_done (data=0x8e7670, xdg_output=0x8e7580)
     at /home/lyudess/Projects/xserver/hw/xwayland/xwayland-output.c:307
 #11 0x00007ffff50e9d1e in ffi_call_unix64 () at ../src/x86/unix64.S:76
 #12 0x00007ffff50e968f in ffi_call (cif=<optimized out>, fn=<optimized out>, rvalue=<optimized out>,
     avalue=<optimized out>) at ../src/x86/ffi64.c:525
 #13 0x00007ffff74f3d8b in wl_closure_invoke () from target:/lib64/libwayland-client.so.0
 #14 0x00007ffff74f0928 in dispatch_event.isra () from target:/lib64/libwayland-client.so.0
 #15 0x00007ffff74f1be4 in wl_display_dispatch_queue_pending () from target:/lib64/libwayland-client.so.0
 #16 0x00007ffff74f200b in wl_display_roundtrip_queue () from target:/lib64/libwayland-client.so.0
 #17 0x0000000000418cad in InitInput (argc=12, argv=0x7fffffffd9c8)
     at /home/lyudess/Projects/xserver/hw/xwayland/xwayland-input.c:2867
 #18 0x00000000004a20e3 in dix_main (argc=12, argv=0x7fffffffd9c8, envp=0x7fffffffda30)
     at /home/lyudess/Projects/xserver/dix/main.c:250
 #19 0x0000000000420cb2 in main (argc=12, argv=0x7fffffffd9c8, envp=0x7fffffffda30)
    at /home/lyudess/Projects/xserver/dix/stubmain.c:34

This appears to be the result of xwl_cursor_confined_to() and
xwl_screen_get_default_seat(). While not against protocol, mutter ends
up sending xdg_output before wl_seat. xwl_screen_get_default_seat()
makes the naïve assumption that we always have a valid seat, we end up
returning a pointer to the empty list itself instead of an actual seat
and causing ourselves to segfault.

So, actually return NULL in xwl_screen_get_default_seat() if the seat
list is empty, and skip any pointer confinement processing in
xwl_cursor_confined_to() when we don't have a seat setup yet.

Signed-off-by: Lyude Paul <lyude@redhat.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2018-02-06 13:47:25 -05:00
Olivier Fourdan
fc8b7d05e7 xwayland: place a manual redirect on windows
Place a manual redirect on windows on xwl_realize_window() and remove
it on xwl_unrealize_window() to avoid the X11 window manager removing
its redirect before Xwayland has unrealized the window (e.g. if the X11
window manager has terminated unexpectedly)

Suggested by Daniel Stone <daniel@fooishbar.org>

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Daniel Stone <daniel@fooishbar.org>
2018-01-25 10:31:50 -05:00
Olivier Fourdan
3362422e84 xwayland: remove dirty window unconditionally on unrealize
This is a rare occurrence of a crash in Xwayland for which I don't have
the reproducing steps, just a core file.

The backtrace looks as follow:

  #0  raise () from /usr/lib64/libc.so.6
  #1  abort () from /usr/lib64/libc.so.6
  #2  OsAbort () at utils.c:1361
  #3  AbortServer () at log.c:877
  #4  FatalError () at log.c:1015
  #5  OsSigHandler () at osinit.c:154
  #6  <signal handler called>
  #7  xwl_glamor_pixmap_get_wl_buffer () at xwayland-glamor.c:162
  #8  xwl_screen_post_damage () at xwayland.c:514
  #9  block_handler () at xwayland.c:665
  #10 BlockHandler () at dixutils.c:388
  #11 WaitForSomething () at WaitFor.c:219
  #12 Dispatch () at dispatch.c:422
  #13 dix_main () at main.c:287

The crash is caused by dereferencing “xwl_pixmap->buffer” in
xwl_glamor_pixmap_get_wl_buffer() because “xwl_pixmap” is NULL.

Reason for this is because the corresponding pixmap is from the root
window and xwayland is rootless by default.

This can happen if the window was mapped, redirected, damaged and
unredirected immediately, before the damage is processed by Xwayland.

Make sure to remove the dirty window from the damage list on unrealize
to prevent this from happening.

Credit goes to Adam Jackson <ajax@nwnk.net> and Daniel Stone
<daniel@fooishbar.org> for finding the root cause the issue.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
2018-01-25 10:31:45 -05:00
Olivier Fourdan
da8de2a7f6 xwayland: Add optional xdg-output support
The xdg-output protocol aims at describing outputs in way which is
more in line with the concept of an output on desktop oriented systems.

For now it just features the position and logical size which describe
the output position and size in the global compositor space.

This is however much useful for Xwayland to advertise the output size
and position to X11 clients which need this to configure their surfaces
in the global compositor space as the compositor may apply a different
scale from what is advertised by the output scaling property (to achieve
fractional scaling, for example).

This was added in wayland-protocols 1.10.

Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
2018-01-24 11:34:59 -05:00
Pekka Paalanen
f72587ecc7 xwayland: reduce over-damage
If an X11 app draws a little here, some there, and a tiny bit in the
opposite corner, using RegionExtents for the damage to be sent to the
Wayland compositor will cause massive over-damaging.

However, we cannot blindly send an arbitrary number of damage
rectangles, because there is a risk of overflowing the Wayland
connection. If that happens, it triggers an abort in libwayland-client.

Try to be more accurate with the damage by sending up to 256 rectangles
per window, and fall back to extents otherwise. The number is completely
arbitrary.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: Daniel Stone <daniels@collabora.com>
2018-01-22 12:27:28 -05:00
Olivier Fourdan
fe46cbea0f xwayland: Give up “cleanly“ on Wayland socket errors
Xwayland is a pretty standard Wayland client, we want to be able to
capture core dumps on crashes.

Yet using "-core" causes any FatalError() to generate a core dump,
meaning that we would get a core file for all Wayland server crashes,
which would generate a lot of false positives.

Instead of using FatalError() on Wayland socket errors, give up cleanly
to avoid dumping core files when "-core" is used.

See also: https://bugzilla.gnome.org/show_bug.cgi?id=790502
     and: https://bugzilla.gnome.org/show_bug.cgi?id=789086

Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
2017-12-13 10:56:10 -05:00
Carlos Garnacho
60f4646ae1 xwayland: Keep separate variables for pointer and tablet foci
The tablet/stylus interfaces reused xwl_seat->focus_window, which
would leave a somewhat inconsistent state of that variable for
wl_pointer purposes (basically, everything) if the pointer happened
to lay on the same surface than the stylus while proximity_out
happens.

We just want the stylus xwl_window to correctly determine we have
stylus focus, and to correctly translate surface-local coordinates
to root coordinates, this can be done using a different variable.

Signed-off-by: Carlos Garnacho <carlosg@gnome.org>
Acked-by: Jason Gerecke <jason.gerecke@wacom.com>
Tested-by: Olivier Fourdan <ofourdan@redhat.com>
2017-12-06 11:00:50 -05:00
Roman Gilg
82df2ce38c xwayland: Avoid repeatedly looping through window ancestor chain
Calling xwl_window_from_window means looping through the window ancestor
chain whenever it is called on a child window or on an automatically
redirected window.

Since these properties and the potential ancestor's xwl_window are constant
between window realization and unrealization, we can omit the looping by
always putting the respective xwl_window in the Window's private field on
its realization. If the Window doesn't feature an xwl_window on its own,
it's the xwl_window of its first ancestor with one.

Signed-off-by: Roman Gilg <subdiff@gmail.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2017-09-13 11:51:10 -04:00
Olivier Fourdan
0a448d133f xwayland: Add grab protocol support
The keyboard grabbing protocol for Xwayland is included in
wayland-protocol 1.9.

Update the wayland-protocol required version in both configure and meson
builds and add support for this new protocol in Xwayland.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-08-01 10:56:42 +01:00
Carlos Garnacho
513e3bd387 xwayland: Update root window size when desktop size changes
This fixes grabs on InputOnly windows whose parent is the root window
failing with GrabNotViewable. This is due to window->borderSize/windowSize
being computed as clipped by its parent, resulting in a null region.

Setting up the right size on the root window makes the InputOnly size
correct too, so the GrabNotViewable paths aren't hit anymore.

Signed-off-by: Carlos Garnacho <carlosg@gnome.org>
Acked-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-06-07 14:45:34 +10:00
Carlos Garnacho
fafdb0cc96 xwayland: "Accept" confineTo on InputOnly windows
Of sorts, actually make it confine to the pointer focus, as the
InputOnly window is entirely invisible to xwayland accounting,
we don't have a xwl_window for it.

Signed-off-by: Carlos Garnacho <carlosg@gnome.org>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-06-07 14:38:14 +10:00
Carlos Garnacho
c217fcb4c4 xwayland: Allow pointer warp on root/None window
Of sorts, as we can't honor pointer warping across the whole root window
coordinates, peek the pointer focus in these cases.

Signed-off-by: Carlos Garnacho <carlosg@gnome.org>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-06-07 14:37:57 +10:00
Lyude
4f29366f1e xwayland: Don't load extension list more than once
When running an Xwayland server from the command line, we end up
resetting the server every time all of the clients connected to the
server leave. This would be fine, except that xwayland makes the mistake
of unconditionally calling LoadExtensionList(). This causes us to setup
the glxExtension twice in a row which means that when we lose our last
client on the second server generation, we end up trying to call the glx
destructors twice in a row resulting in a segfault:

(EE)
(EE) Backtrace:
(EE) 0: Xwayland (OsSigHandler+0x3b) [0x4982f9]
(EE) 1: /lib64/libpthread.so.0 (__restore_rt+0x0) [0x70845bf]
(EE) 2: /usr/lib64/dri/swrast_dri.so (__driDriverGetExtensions_virtio_gpu+0x32897d) [0x1196e5bd]
(EE) 3: /usr/lib64/dri/swrast_dri.so (__driDriverGetExtensions_virtio_gpu+0x328a45) [0x1196e745]
(EE) 4: /usr/lib64/dri/swrast_dri.so (__driDriverGetExtensions_virtio_gpu+0x32665f) [0x11969f7f]
(EE) 5: Xwayland (__glXDRIscreenDestroy+0x30) [0x54686e]
(EE) 6: Xwayland (glxCloseScreen+0x3f) [0x5473db]
(EE) 7: Xwayland (glxCloseScreen+0x53) [0x5473ef]
(EE) 8: Xwayland (dix_main+0x7b6) [0x44c8c9]
(EE) 9: Xwayland (main+0x28) [0x61c503]
(EE) 10: /lib64/libc.so.6 (__libc_start_main+0xf1) [0x72b1401]
(EE) 11: Xwayland (_start+0x2a) [0x4208fa]
(EE) 12: ? (?+0x2a) [0x2a]
(EE)
(EE) Segmentation fault at address 0x18
(EE)
Fatal server error:
(EE) Caught signal 11 (Segmentation fault). Server aborting
(EE)

Easy reproduction recipe:
- Start an Xwayland session with the default settings
- Open a window
- Close that window
- Open another window
- Close that window
- Total annihilation occurs

Signed-off-by: Lyude <lyude@redhat.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-05-31 21:42:04 +10:00
Jason Gerecke
7d48b758a6 xwayland: Bind to wp_tablet_manager if available and get its seats
If we're notified about the existence of the wp_tablet_manager interface,
we bind to it so that we can make use of any tablets that are (or later
become) available. For each seat that exists or comes into existance at
a later point, obtain the associated tablet_seat.

Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com>
Signed-off-by: Carlos Garnacho <carlosg@gnome.org>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Acked-by: Ping Cheng <ping.cheng@wacom.com>
2017-04-28 11:21:24 +10:00
Eric Anholt
c7be7a688a Use #ifdef instead of #if for features to make Meson easier.
We mostly use #ifdef throughout the tree, and this lets the generated
config.h files just be #define TOKEN instead of #define TOKEN 1.

Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Eric Anholt <eric@anholt.net>
2017-04-26 17:30:12 -04:00
Pekka Paalanen
9f4d308cda xwayland: use _XWAYLAND_ALLOW_COMMITS property
The X11 window manager (XWM) of a Wayland compositor can use the
_XWAYLAND_ALLOW_COMMITS property to control when Xwayland sends
wl_surface.commit requests. If the property is not set, the behaviour
remains what it was.

XWM uses the property to inhibit commits until the window is ready to be
shown. This gives XWM time to set up the window decorations and internal
state before Xwayland does the first commit. XWM can use this to ensure
the first commit carries fully drawn decorations and the window
management state is correct when the window becomes visible.

Setting the property to zero inhibits further commits, and setting it to
non-zero allows commits. Deleting the property allows commits.

When the property is changed from zero to non-zero, there will be a
commit on next block_handler() call provided that some damage has been
recorded.

Without this patch (i.e. with the old behaviour) Xwayland can and will
commit the surface very soon as the application window has been realized
and drawn into.  This races with XWM and may cause visible glitches.

v3:
- introduced a simple setter for xwl_window::allow_commits
- split xwl_window_property_allow_commits() out of
  xwl_property_callback()
- check MakeAtom(_XWAYLAND_ALLOW_COMMITS)

v2:
- use PropertyStateCallback instead of XACE, based on the patch
  "xwayland: Track per-window support for netwm frame sync" by
  Adam Jackson
- check property type is XA_CARDINAL
- drop a useless memcpy()

Weston Bug: https://phabricator.freedesktop.org/T7622
Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2017-02-23 13:30:30 -05:00
Pekka Paalanen
a6308cea60 xwayland: fix 'buffer' may be used uninitialized warning
Fix the following warning due to --disable-glamor:

  CC       Xwayland-xwayland.o
In file included from /home/pq/local/include/wayland-client.h:40:0,
                 from xwayland.h:35,
                 from xwayland.c:26:
xwayland.c: In function ‘block_handler’:
/home/pq/local/include/wayland-client-protocol.h:3446:2: warning: ‘buffer’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  wl_proxy_marshal((struct wl_proxy *) wl_surface,
  ^
xwayland.c:466:23: note: ‘buffer’ was declared here
     struct wl_buffer *buffer;
                       ^

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: Olivier Fourdan <ofourdan@redhat.com>
2017-02-23 13:30:11 -05:00
Pekka Paalanen
f7b8560f23 xwayland: refactor into xwl_window_post_damage()
Refactor xwl_screen_post_damage() and split the window specific code
into a new function xwl_window_post_damage().

This is a pure refactoring, there are no behavioral changes. An assert
is added to xwl_window_post_damage() to ensure frame callbacks are not
leaked if a future patch changes the call.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: Olivier Fourdan <ofourdan@redhat.com>
2017-02-23 13:30:11 -05:00
Pekka Paalanen
2de37eb71b xwayland: fix order of calloc() args
The definition by the manual is:
	calloc(size_t nmemb, size_t size)

Swap the arguments of calloc() calls to be the right way around.

Presumably this makes no functional difference, but better follow the
spec.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-11-25 11:35:53 +10:00
Jonas Ådahl
a6e85e6330 xwayland: Add pointer warp emulator
Emulate pointer warps by locking the pointer and sending relative
motion events instead of absolute. X will keep track of the "fake"
pointer cursor position given the relative motion events, and the
client warping the cursor will warp the faked cursor position.

Various requirements need to be met for the pointer warp emulator to
enable:

The cursor must be invisible: since it would not be acceptable that a
fake cursor position would be different from the visual representation
of the cursor, emulation can only be done when there is no visual
representation done by the Wayland compositor. Thus, for the emulator
to enable, the cursor must be hidden, and would the cursor be displayed
while the emulator is active, the emulator would be destroyed.

The window that is warped within must be likely to have pointer focus.
For example, warping outside of the window region will be ignored.

The pointer warp emulator will disable itself once the fake cursor
position leaves the window region, or the cursor is made visible.

This makes various games depending on pointer warping (such as 3D
first-person shooters and stategy games using click-to-drag-map like
things) work.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2016-10-05 13:51:02 -04:00
Jonas Ådahl
467ab142ff xwayland: Translate a pointer grab with confineTo to pointer confinement
Translate grabbing a pointer device with confineTo set to a window into
confining the Wayland pointer using the pointer constraints protocol.
This makes clients that depend on the pointer not going outside of the
window region, such as certain games and virtual machines viewers, to
function more properly.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-10-05 13:50:54 -04:00
Jonas Ådahl
c14a8c6cc0 xwayland: Put getting a xwl_window from a Window in a helper
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-10-05 13:46:30 -04:00
Olivier Fourdan
b79eaf1184 xwayland: handle EAGAIN on Wayland fd
wl_display_flush() can fail with EAGAIN and Xwayland would make this a
fatal error.

When this happens, it means that Xwayland has flooded the Wayland file
descriptor, either because the Wayland compositor cannot cope or more
likely because of a deadlock situation where the Wayland compositor is
blocking, waiting for an X reply while Xwayland tries to write data to
the Wayland file descriptor.

The general consensus to avoid the deadlock is for the Wayland
compositor to never issue blocking X11 roundtrips, but in practice
blocking rountrips can occur in various places, including Xlib calls
themselves so this is not always achievable without major surgery in the
Wayland compositor/Window manager.

What this patch does is to avoid dispatching to the Wayland file
descriptor until it becomes available for writing again, while at the
same time continue processing X11 requests to release the deadlock.

This is not perfect, as there is still the possibility of another X
client hammering the connection and we'll still fail writing to the
Wayland connection eventually, but this improves things enough to avoid
a 100% repeatable crash with vlc and gtkperf.

Also, it is worth considering that window managers and Wayland
compositors such as mutter already have a higher priority than other
regular X clients thanks to XSyncSetPriority(), mitigating the risk.

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1278159
Bugzilla: https://bugzilla.gnome.org/show_bug.cgi?id=763400
Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
2016-09-28 14:23:59 -04:00
Olivier Fourdan
6e5bec261c wayland: Emulate crossing for native window
Emitting a LeaveNotify event every time the pointer leaves an X11 window
may confuse focus follow mouse mode in window managers such as
mutter/gnome-shell.

Keep the previously found X window and compare against the new one, and
if they match then it means the pointer has left an Xwayland window for
a native Wayland surface, only in this case fake the crossing to the
root window.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-08-19 11:04:25 +10:00
Olivier Fourdan
4cbf1fb1f9 xwayland: Avoid double free of RRCrtc and RROutput
At shutdown, the Xserver will free all its resources which includes the
RRCrtc and RROutput created.

Xwayland would do the same in its xwl_output_destroy() called from
xwl_close_screen(), leading to a double free of existing RRCrtc
RROutput:

 Invalid read of size 4
    at 0x4CDA10: RRCrtcDestroy (rrcrtc.c:689)
    by 0x426E75: xwl_output_destroy (xwayland-output.c:301)
    by 0x424144: xwl_close_screen (xwayland.c:117)
    by 0x460E17: CursorCloseScreen (cursor.c:187)
    by 0x4EB5A3: AnimCurCloseScreen (animcur.c:106)
    by 0x4EF431: present_close_screen (present_screen.c:64)
    by 0x556D40: dix_main (main.c:354)
    by 0x6F0D290: (below main) (in /usr/lib/libc-2.24.so)
  Address 0xbb1fc30 is 0 bytes inside a block of size 728 free'd
    at 0x4C2BDB0: free (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x4CCE5F: RRCrtcDestroyResource (rrcrtc.c:719)
    by 0x577541: doFreeResource (resource.c:895)
    by 0x5787B5: FreeClientResources (resource.c:1161)
    by 0x578862: FreeAllResources (resource.c:1176)
    by 0x556C54: dix_main (main.c:323)
    by 0x6F0D290: (below main) (in /usr/lib/libc-2.24.so)
  Block was alloc'd at
    at 0x4C2CA6A: calloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x4CC6DB: RRCrtcCreate (rrcrtc.c:76)
    by 0x426D1C: xwl_output_create (xwayland-output.c:264)
    by 0x4232EC: registry_global (xwayland.c:431)
    by 0x76CB1C7: ffi_call_unix64 (in /usr/lib/libffi.so.6.0.4)
    by 0x76CAC29: ffi_call (in /usr/lib/libffi.so.6.0.4)
    by 0x556CEFD: wl_closure_invoke (connection.c:935)
    by 0x5569CBF: dispatch_event.isra.4 (wayland-client.c:1310)
    by 0x556AF13: dispatch_queue (wayland-client.c:1456)
    by 0x556AF13: wl_display_dispatch_queue_pending
(wayland-client.c:1698)
    by 0x556B33A: wl_display_roundtrip_queue (wayland-client.c:1121)
    by 0x42371C: xwl_screen_init (xwayland.c:631)
    by 0x552F60: AddScreen (dispatch.c:3864)

And:

 Invalid read of size 4
    at 0x522890: RROutputDestroy (rroutput.c:348)
    by 0x42684E: xwl_output_destroy (xwayland-output.c:302)
    by 0x423CF4: xwl_close_screen (xwayland.c:118)
    by 0x4B6377: CursorCloseScreen (cursor.c:187)
    by 0x539503: AnimCurCloseScreen (animcur.c:106)
    by 0x53D081: present_close_screen (present_screen.c:64)
    by 0x43DBF0: dix_main (main.c:354)
    by 0x7068730: (below main) (libc-start.c:289)
  Address 0xc403190 is 0 bytes inside a block of size 154 free'd
    at 0x4C2CD5A: free (vg_replace_malloc.c:530)
    by 0x521DF3: RROutputDestroyResource (rroutput.c:389)
    by 0x45DA61: doFreeResource (resource.c:895)
    by 0x45ECFD: FreeClientResources (resource.c:1161)
    by 0x45EDC2: FreeAllResources (resource.c:1176)
    by 0x43DB04: dix_main (main.c:323)
    by 0x7068730: (below main) (libc-start.c:289)
  Block was alloc'd at
    at 0x4C2BBAD: malloc (vg_replace_malloc.c:299)
    by 0x52206B: RROutputCreate (rroutput.c:84)
    by 0x426763: xwl_output_create (xwayland-output.c:270)
    by 0x422EDC: registry_global (xwayland.c:432)
    by 0x740FC57: ffi_call_unix64 (unix64.S:76)
    by 0x740F6B9: ffi_call (ffi64.c:525)
    by 0x5495A9D: wl_closure_invoke (connection.c:949)
    by 0x549283F: dispatch_event.isra.4 (wayland-client.c:1274)
    by 0x5493A13: dispatch_queue (wayland-client.c:1420)
    by 0x5493A13: wl_display_dispatch_queue_pending
(wayland-client.c:1662)
    by 0x5493D2E: wl_display_roundtrip_queue (wayland-client.c:1085)
    by 0x4232EC: xwl_screen_init (xwayland.c:632)
    by 0x439F50: AddScreen (dispatch.c:3864)

Split xwl_output_destroy() into xwl_output_destroy() which frees the
wl_output and the xwl_output structure, and xwl_output_remove() which
does the RRCrtcDestroy() and RROutputDestroy() and call the latter only
when an output is effectively removed.

An additional benefit, on top of avoiding a double free, is to avoid
updating the screen size at shutdown.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2016-08-15 14:20:54 -04:00
Olivier Fourdan
4d586118c1 xwayland: Plug memleak in frame callbacks
The frame callback set up via wl_surface_frame() needs to be freed with
wl_callback_destroy() or we'll leak memory.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=97065
Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
2016-08-15 12:49:36 -04:00
Keith Packard
9d15912aa4 Remove fd_set from Block/Wakeup handler API
This removes the last uses of fd_set from the server interfaces
outside of the OS layer itself.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2016-07-18 15:27:51 -04:00
Adam Jackson
9fcb554e9b xwayland: Only force monotonic clock once
Otherwise on regeneration we get:

(EE) BUG: triggered 'if (clockid)'
(EE) BUG: utils.c:440 in ForceClockId()
(EE)
(EE) Backtrace:
(EE) 0: ./hw/xwayland/Xwayland (ForceClockId+0x5c) [0x47713c]
(EE) 1: ./hw/xwayland/Xwayland (OsInit+0x25) [0x4763d5]
(EE) 2: ./hw/xwayland/Xwayland (dix_main+0x11c) [0x43e60c]
(EE) 3: /lib64/libc.so.6 (__libc_start_main+0xf1) [0x7f627b2f9731]
(EE) 4: ./hw/xwayland/Xwayland (_start+0x29) [0x4238e9]
(EE) 5: ? (?+0x29) [0x29]

Signed-off-by: Adam Jackson <ajax@redhat.com>
Reviewed-by: Jonas Ådahl <jadahl@gmail.com>
2016-07-15 10:09:24 -04:00
Olivier Fourdan
88e981e708 xwayland: sync event queue to check compositor reply
Read and dispatch pending Wayland events to make sure we do not miss a
possible reply from the compositor prior to discard a key repeat.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-06-03 09:44:09 +02:00
Olivier Fourdan
26ad25a0ed xwayland: refactor Wayland event handling
To be able to reuse some code.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-06-03 09:43:04 +02:00
Jonas Ådahl
a779fda224 xwayland: Use the CLOCK_MONOTONIC clock
By default the X server will try CLOCK_MONOTONIC_COARSE before
CLOCK_MONOTONIC, while A Wayland compositor may only support getting
their timestamps from the CLOCK_MONOTONIC clock. This causes various
issues since it may happen that a timestamp from CLOCK_MONOTONIC
retrieved before a sending an X request will still be "later" than the
timestamp the X server than gets after receiving the request, due to the
fact that CLOCK_MONOTONIC_COARSE has a lower resolution.

To avoid these issues, make Xwayland always use CLOCK_MONOTONIC, so
that it becomes possible for Wayland compositor only supporting
CLOCK_MONOTONIC and X server to use the same clock.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
Acked-by: Daniel Stone <daniels@collabora.com>
Tested-by: Olivier Fourdan <ofourdan@redhat.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-05-31 08:44:38 +10:00
Olivier Fourdan
6070a749d9 xwayland: add partial xvidmode extension support
Older games (mostly those based on SDL 1.x) rely on the XVidMode
extension and would refuse to run without.

Add a simple, limited and read-only xvidmode support that reports the
current mode used so that games that rely on xvidmode extension can run
on XWayland.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=87806
Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
2016-02-29 16:29:17 -05:00
Daniel Stone
e957a2e5dd dix: Add hybrid full-size/empty-clip mode to SetRootClip
216bdbc735 removed the SetRootClip call in the XWayland output-hotplug
handler when running rootless (e.g. as a part of Weston/Mutter), since
the root window has no storage, so generating exposures will result in
writes to invalid memory.

Unfortunately, preventing the segfault also breaks sprite confinement.
SetRootClip updates winSize and borderSize for the root window, which
when combined with RRScreenSizeChanged calling ScreenRestructured,
generates a new sprite-confinment area to update it to the whole screen.

Removing this call results in the window geometry being reported
correctly, but winSize/borderSize never changing from their values at
startup, i.e. out of sync with the root window geometry / screen
information in the connection info / XRandR.

This patch introduces a hybrid mode, where we update winSize and
borderSize for the root window, enabling sprite confinement to work
correctly, but keep the clip emptied so exposures are never generated.

Signed-off-by: Daniel Stone <daniels@collabora.com>
Tested-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2016-02-22 13:26:31 -05:00
Keith Packard
f933a1b38e hw/xwayland: Use NotifyFd handler to monitor wayland socket
Replace the block/wakeup handler with a NotifyFd callback instead.

Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Keith Packard <keithp@keithp.com>
2015-12-01 13:55:28 -05:00
Marek Chalupa
5b2ca34132 xwayland: check if creating xwl_output succeeded
check return values of RR.*Create calls

v2. do not bail out if we don't have any output

Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Reviewed-by: Olivier Fourdan <ofourdan@redhat.com>
2015-11-30 11:56:28 -05:00
Marek Chalupa
646ebea456 xwayland: fix memory leaks on error paths in xwl_realize_window
don't leak memory when realizing window fails

v2. take care of all memory allocation and return values,
    not just one leak

Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Reviewed-by: Olivier Fourdan <ofourdan@redhat.com>
2015-11-30 11:56:28 -05:00
Dima Ryazanov
550984c95e xwayland: Destroy xwl_output when wl_output gets removed
This makes Xwayland correctly handle a monitor getting unplugged.

[Marek]: use xorg_list_for_each_entry_safe

Signed-off-by: Dima Ryazanov <dima@gmail.com>
Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
2015-09-25 15:22:18 +02:00
Carlos Garnacho
44f250a7e8 xwayland: Remove related touchpoints when unrealizing windows
These sequences are forgotten to all purposes.

Signed-off-by: Carlos Garnacho <carlosg@gnome.org>
Reviewed-by: Olivier Fourdan <ofourdan@redhat.com>
2015-09-18 14:55:00 +02:00
Ray Strode
76636ac12f xwayland: default to local user if no xauth file given. [CVE-2015-3164 3/3]
Right now if "-auth" isn't passed on the command line, we let
any user on the system connect to the Xwayland server.

That's clearly suboptimal, given Xwayland is generally designed
to be used by one user at a time.

This commit changes the behavior, so only the user who started the
X server can connect clients to it.

Signed-off-by: Ray Strode <rstrode@redhat.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Signed-off-by: Keith Packard <keithp@keithp.com>
2015-05-26 11:22:24 -07:00
Ray Strode
c4534a38b6 xwayland: Enable access control on open sockets [CVE-2015-3164 1/3]
Xwayland currently allows wide-open access to the X sockets
it listens on, ignoring Xauth access control.

This commit makes sure to enable access control on the sockets,
so one user can't snoop on another user's X-over-wayland
applications.

Signed-off-by: Ray Strode <rstrode@redhat.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Signed-off-by: Keith Packard <keithp@keithp.com>
2015-05-26 11:22:17 -07:00
Carlos Olmedo Escobar
f27d743c18 Avoid possible null pointer dereference.
Signed-off-by: Carlos Olmedo Escobar <carlos.olmedo.e@gmail.com>
Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Signed-off-by: Keith Packard <keithp@keithp.com>
2015-01-23 10:03:57 -08:00
Peter Hutterer
79b9d33545 xwayland: declare fatal log handler as noreturn
xwayland.c:661:1: warning: function 'xwl_log_handler' could be declared with
attribute 'noreturn' [-Wmissing-noreturn]

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-11-12 10:25:00 +10:00
Adam Jackson
d3427717f2 xwayland: Snap damage reports to the bounding box
Instead of sending every little rect.  Lets x11perf run to completion,
makes 'while true; do gtkperf -a; done' take longer to crash.

This is effectively a resend of the same logic against the old
xfree86+xwayland branch:

http://lists.x.org/archives/xorg-devel/2013-October/038453.html

Reviewed-by: Daniel Stone <daniel@fooishbar.org>
Reviewed-by: Kristian Høgsberg <krh@bitplanet.net>
Signed-off-by: Adam Jackson <ajax@redhat.com>
2014-09-11 23:40:30 -06:00
Jasper St. Pierre
5ecc0315a2 xwayland: Implement throttling for surfaces based on the frame event
This implements simple throttling that keeps us to one attach per
frame. There isn't really an active performance benefit, since the
buffers will be redrawn only once per frame anyway, but it does cut down
on the chatty network traffic. Since the Wayland sockets might fill
up as well, the cut down on the volume of data we send out also provides
us with a big stability benefit.

Namely, mutter is a lot more stable running gtkperf, a fairly intensive
X11 application, after this change.

Reviewed-by: Daniel Stone <daniel@fooishbar.org>
Signed-off-by: Jasper St. Pierre <jstpierre@mecheye.net>
2014-09-11 23:40:27 -06:00
Kristian Høgsberg
2f113d68f6 xwayland: Add glamor and DRI3 support
Reviewed-by: Axel Davy <axel.davy@ens.fr>
Signed-off-by: Kristian Høgsberg <krh@bitplanet.net>
Signed-off-by: Keith Packard <keithp@keithp.com>
2014-06-24 15:09:55 -07:00
Kristian Høgsberg
66b6024740 xwayland: Remove left-over ErrorF logging
Reviewed-by: Jasper St. Pierre <jstpierre@mecheye.net>
Signed-off-by: Kristian Høgsberg <krh@bitplanet.net>
2014-04-21 11:25:12 -07:00
Kristian Høgsberg
f618455c80 xwayland: Build without xshmfence
Reviewed-by: Daniel Stone <daniel@fooishbar.org>
Signed-off-by: Kristian Høgsberg <krh@bitplanet.net>
2014-04-21 11:15:49 -07:00