2014-03-12 00:11:39 +01:00
|
|
|
/*
|
|
|
|
* Copyright © 2011-2014 Intel Corporation
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software
|
|
|
|
* and its documentation for any purpose is hereby granted without
|
|
|
|
* fee, provided that the above copyright notice appear in all copies
|
|
|
|
* and that both that copyright notice and this permission notice
|
|
|
|
* appear in supporting documentation, and that the name of the
|
|
|
|
* copyright holders not be used in advertising or publicity
|
|
|
|
* pertaining to distribution of the software without specific,
|
|
|
|
* written prior permission. The copyright holders make no
|
|
|
|
* representations about the suitability of this software for any
|
|
|
|
* purpose. It is provided "as is" without express or implied
|
|
|
|
* warranty.
|
|
|
|
*
|
|
|
|
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
|
|
|
|
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
* FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
|
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
|
|
|
|
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2019-12-18 15:00:11 +01:00
|
|
|
#include <xwayland-config.h>
|
|
|
|
|
2014-03-12 00:11:39 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2016-11-23 12:30:53 +01:00
|
|
|
#include <X11/Xatom.h>
|
2014-03-12 00:11:39 +01:00
|
|
|
#include <selection.h>
|
|
|
|
#include <micmap.h>
|
|
|
|
#include <misyncshm.h>
|
|
|
|
#include <compositeext.h>
|
2018-01-25 13:43:09 +01:00
|
|
|
#include <compint.h>
|
2014-03-12 00:11:39 +01:00
|
|
|
#include <glx_extinit.h>
|
2016-05-24 12:46:42 +02:00
|
|
|
#include <os.h>
|
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-15 15:59:07 +02:00
|
|
|
#include <xserver_poll.h>
|
2016-11-23 12:30:53 +01:00
|
|
|
#include <propertyst.h>
|
2014-03-12 00:11:39 +01:00
|
|
|
|
2019-12-18 10:03:43 +01:00
|
|
|
#include "xwayland-screen.h"
|
2019-12-18 11:18:22 +01:00
|
|
|
#include "xwayland-vidmode.h"
|
2019-12-16 17:07:02 +01:00
|
|
|
|
2016-02-10 09:35:39 +01:00
|
|
|
#ifdef XF86VIDMODE
|
|
|
|
#include <X11/extensions/xf86vmproto.h>
|
|
|
|
_X_EXPORT Bool noXFree86VidModeExtension;
|
|
|
|
#endif
|
|
|
|
|
2014-03-12 00:11:39 +01:00
|
|
|
void
|
|
|
|
ddxGiveUp(enum ExitCode error)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
OsVendorInit(void)
|
|
|
|
{
|
2016-07-08 21:17:05 +02:00
|
|
|
if (serverGeneration == 1)
|
|
|
|
ForceClockId(CLOCK_MONOTONIC);
|
2014-03-12 00:11:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
OsVendorFatalError(const char *f, va_list args)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(DDXBEFORERESET)
|
|
|
|
void
|
|
|
|
ddxBeforeReset(void)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2019-02-22 00:22:57 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if INPUTTHREAD
|
|
|
|
/** This function is called in Xserver/os/inputthread.c when starting
|
|
|
|
the input thread. */
|
|
|
|
void
|
|
|
|
ddxInputThreadInit(void)
|
|
|
|
{
|
|
|
|
}
|
2014-03-12 00:11:39 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
|
|
|
ddxUseMsg(void)
|
|
|
|
{
|
|
|
|
ErrorF("-rootless run rootless, requires wm support\n");
|
|
|
|
ErrorF("-wm fd create X client for wm on given fd\n");
|
2019-07-20 00:16:43 +02:00
|
|
|
ErrorF("-initfd fd add given fd as a listen socket for initialization clients\n");
|
|
|
|
ErrorF("-listenfd fd add given fd as a listen socket\n");
|
2019-06-19 09:19:24 +02:00
|
|
|
ErrorF("-listen fd deprecated, use \"-listenfd\" instead\n");
|
xwayland: Add glamor egl_backend for EGLStreams
This adds initial support for displaying Xwayland applications through
the use of EGLStreams and nvidia's custom wayland protocol by adding
another egl_backend driver. This also adds some additional egl_backend
hooks that are required to make things work properly.
EGLStreams work a lot differently then the traditional way of handling
buffers with wayland. Unfortunately, there are also a LOT of various
pitfalls baked into it's design that need to be explained.
This has a very large and unfortunate implication: direct rendering is,
for the time being at least, impossible to do through EGLStreams. The
main reason being that the EGLStream spec mandates that we lose the
entire color buffer contents with each eglSwapBuffers(), which goes
against X's requirement of not losing data with pixmaps. no way to use
an allocated EGLSurface as the storage for glamor rendering like we do
with GBM, we have to rely on blitting each pixmap to it's respective
EGLSurface producer each frame. In order to pull this off, we add two
different additional egl_backend hooks that GBM opts out of
implementing:
- egl_backend.allow_commits for holding off displaying any EGLStream
backed pixmaps until the point where it's stream is completely
initialized and ready for use
- egl_backend.post_damage for blitting the content of the EGLStream
surface producer before Xwayland actually damages and commits the
wl_surface to the screen.
The other big pitfall here is that using nvidia's wayland-eglstreams
helper library is also not possible for the most part. All of it's API
for creating and destroying streams rely on being able to perform a
roundtrip in order to bring each stream to completion since the wayland
compositor must perform it's job of connecting a consumer to each
EGLstream. Because Xwayland has to potentially handle both responding to
the wayland compositor and it's own X clients, the situation of the
wayland compositor being one of our X clients must be considered. If we
perform a roundtrip with the Wayland compositor, it's possible that the
wayland compositor might currently be connected to us as an X client and
thus hang while both Xwayland and the wayland compositor await responses
from eachother. To avoid this, we work directly with the wayland
protocol and use wl_display_sync() events along with release() events to
set up and destroy EGLStreams asynchronously alongside handling X
clients.
Additionally, since setting up EGLStreams is not an atomic operation we
have to take into consideration the fact that an EGLStream can
potentially be created in response to a window resize, then immediately
deleted due to another pending window resize in the same X client's
pending reqests before Xwayland hits the part of it's event loop where
we read from the wayland compositor. To make this even more painful, we
also have to take into consideration that since EGLStreams are not
atomic that it's possible we could delete wayland resources for an
EGLStream before the compositor even finishes using them and thus run
into errors. So, we use quite a bit of tracking logic to keep EGLStream
objects alive until we know the compositor isn't using them (even if
this means the stream outlives the pixmap it backed).
While the default backend for glamor remains GBM, this patch exists for
users who have had to deal with the reprecussion of their GPU
manufacturers ignoring the advice of upstream and the standardization of
GBM across most major GPU manufacturers. It is not intended to be a
final solution to the GBM debate, but merely a baindaid so our users
don't have to suffer from the consequences of companies avoiding working
upstream. New drivers are strongly encouraged not to use this as a
backend, and use GBM like everyone else. We even spit this out as an
error from Xwayland when using the eglstream backend.
Signed-off-by: Lyude Paul <lyude@redhat.com>
Acked-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2018-04-20 20:38:05 +02:00
|
|
|
ErrorF("-eglstream use eglstream backend for nvidia GPUs\n");
|
2014-03-12 00:11:39 +01:00
|
|
|
}
|
|
|
|
|
2019-07-20 00:16:43 +02:00
|
|
|
static int init_fd = -1;
|
2018-10-23 20:33:24 +02:00
|
|
|
static int wm_fd = -1;
|
|
|
|
static int listen_fds[5] = { -1, -1, -1, -1, -1 };
|
2019-01-02 21:55:23 +01:00
|
|
|
static int listen_fd_count = 0;
|
2018-10-23 20:33:24 +02:00
|
|
|
|
2019-06-19 09:19:24 +02:00
|
|
|
static void
|
|
|
|
xwl_add_listen_fd(int argc, char *argv[], int i)
|
|
|
|
{
|
|
|
|
NoListenAll = TRUE;
|
|
|
|
if (listen_fd_count == ARRAY_SIZE(listen_fds))
|
|
|
|
FatalError("Too many -listen arguments given, max is %zu\n",
|
|
|
|
ARRAY_SIZE(listen_fds));
|
|
|
|
|
|
|
|
listen_fds[listen_fd_count++] = atoi(argv[i + 1]);
|
|
|
|
}
|
|
|
|
|
2014-03-12 00:11:39 +01:00
|
|
|
int
|
|
|
|
ddxProcessArgument(int argc, char *argv[], int i)
|
|
|
|
{
|
|
|
|
if (strcmp(argv[i], "-rootless") == 0) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else if (strcmp(argv[i], "-listen") == 0) {
|
2018-10-23 20:33:24 +02:00
|
|
|
CHECK_FOR_REQUIRED_ARGUMENTS(1);
|
|
|
|
|
2019-06-18 10:41:02 +02:00
|
|
|
/* Not an FD */
|
|
|
|
if (!isdigit(*argv[i + 1]))
|
|
|
|
return 0;
|
|
|
|
|
2019-06-19 09:19:24 +02:00
|
|
|
LogMessage(X_WARNING, "Option \"-listen\" for file descriptors is deprecated\n"
|
|
|
|
"Please use \"-listenfd\" instead.\n");
|
|
|
|
|
|
|
|
xwl_add_listen_fd (argc, argv, i);
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
else if (strcmp(argv[i], "-listenfd") == 0) {
|
|
|
|
CHECK_FOR_REQUIRED_ARGUMENTS(1);
|
2018-10-23 20:33:24 +02:00
|
|
|
|
2019-06-19 09:19:24 +02:00
|
|
|
xwl_add_listen_fd (argc, argv, i);
|
2014-03-12 00:11:39 +01:00
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
else if (strcmp(argv[i], "-wm") == 0) {
|
2018-10-23 20:33:24 +02:00
|
|
|
CHECK_FOR_REQUIRED_ARGUMENTS(1);
|
|
|
|
wm_fd = atoi(argv[i + 1]);
|
2014-03-12 00:11:39 +01:00
|
|
|
return 2;
|
|
|
|
}
|
2019-07-20 00:16:43 +02:00
|
|
|
else if (strcmp(argv[i], "-initfd") == 0) {
|
|
|
|
CHECK_FOR_REQUIRED_ARGUMENTS(1);
|
|
|
|
init_fd = atoi(argv[i + 1]);
|
|
|
|
return 2;
|
|
|
|
}
|
2014-03-12 00:11:39 +01:00
|
|
|
else if (strcmp(argv[i], "-shm") == 0) {
|
|
|
|
return 1;
|
|
|
|
}
|
xwayland: Add glamor egl_backend for EGLStreams
This adds initial support for displaying Xwayland applications through
the use of EGLStreams and nvidia's custom wayland protocol by adding
another egl_backend driver. This also adds some additional egl_backend
hooks that are required to make things work properly.
EGLStreams work a lot differently then the traditional way of handling
buffers with wayland. Unfortunately, there are also a LOT of various
pitfalls baked into it's design that need to be explained.
This has a very large and unfortunate implication: direct rendering is,
for the time being at least, impossible to do through EGLStreams. The
main reason being that the EGLStream spec mandates that we lose the
entire color buffer contents with each eglSwapBuffers(), which goes
against X's requirement of not losing data with pixmaps. no way to use
an allocated EGLSurface as the storage for glamor rendering like we do
with GBM, we have to rely on blitting each pixmap to it's respective
EGLSurface producer each frame. In order to pull this off, we add two
different additional egl_backend hooks that GBM opts out of
implementing:
- egl_backend.allow_commits for holding off displaying any EGLStream
backed pixmaps until the point where it's stream is completely
initialized and ready for use
- egl_backend.post_damage for blitting the content of the EGLStream
surface producer before Xwayland actually damages and commits the
wl_surface to the screen.
The other big pitfall here is that using nvidia's wayland-eglstreams
helper library is also not possible for the most part. All of it's API
for creating and destroying streams rely on being able to perform a
roundtrip in order to bring each stream to completion since the wayland
compositor must perform it's job of connecting a consumer to each
EGLstream. Because Xwayland has to potentially handle both responding to
the wayland compositor and it's own X clients, the situation of the
wayland compositor being one of our X clients must be considered. If we
perform a roundtrip with the Wayland compositor, it's possible that the
wayland compositor might currently be connected to us as an X client and
thus hang while both Xwayland and the wayland compositor await responses
from eachother. To avoid this, we work directly with the wayland
protocol and use wl_display_sync() events along with release() events to
set up and destroy EGLStreams asynchronously alongside handling X
clients.
Additionally, since setting up EGLStreams is not an atomic operation we
have to take into consideration the fact that an EGLStream can
potentially be created in response to a window resize, then immediately
deleted due to another pending window resize in the same X client's
pending reqests before Xwayland hits the part of it's event loop where
we read from the wayland compositor. To make this even more painful, we
also have to take into consideration that since EGLStreams are not
atomic that it's possible we could delete wayland resources for an
EGLStream before the compositor even finishes using them and thus run
into errors. So, we use quite a bit of tracking logic to keep EGLStream
objects alive until we know the compositor isn't using them (even if
this means the stream outlives the pixmap it backed).
While the default backend for glamor remains GBM, this patch exists for
users who have had to deal with the reprecussion of their GPU
manufacturers ignoring the advice of upstream and the standardization of
GBM across most major GPU manufacturers. It is not intended to be a
final solution to the GBM debate, but merely a baindaid so our users
don't have to suffer from the consequences of companies avoiding working
upstream. New drivers are strongly encouraged not to use this as a
backend, and use GBM like everyone else. We even spit this out as an
error from Xwayland when using the eglstream backend.
Signed-off-by: Lyude Paul <lyude@redhat.com>
Acked-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2018-04-20 20:38:05 +02:00
|
|
|
else if (strcmp(argv[i], "-eglstream") == 0) {
|
|
|
|
return 1;
|
|
|
|
}
|
2014-03-12 00:11:39 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static CARD32
|
|
|
|
add_client_fd(OsTimerPtr timer, CARD32 time, void *arg)
|
|
|
|
{
|
2018-10-23 20:33:24 +02:00
|
|
|
if (!AddClientOnOpenFD(wm_fd))
|
2014-03-12 00:11:39 +01:00
|
|
|
FatalError("Failed to add wm client\n");
|
|
|
|
|
|
|
|
TimerFree(timer);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-10-23 20:33:24 +02:00
|
|
|
listen_on_fds(void)
|
2014-03-12 00:11:39 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2018-10-23 20:33:24 +02:00
|
|
|
for (i = 0; i < listen_fd_count; i++)
|
|
|
|
ListenOnOpenFD(listen_fds[i], FALSE);
|
2014-03-12 00:11:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
wm_selection_callback(CallbackListPtr *p, void *data, void *arg)
|
|
|
|
{
|
|
|
|
SelectionInfoRec *info = arg;
|
|
|
|
struct xwl_screen *xwl_screen = data;
|
|
|
|
static const char atom_name[] = "WM_S0";
|
|
|
|
static Atom atom_wm_s0;
|
|
|
|
|
|
|
|
if (atom_wm_s0 == None)
|
|
|
|
atom_wm_s0 = MakeAtom(atom_name, strlen(atom_name), TRUE);
|
|
|
|
if (info->selection->selection != atom_wm_s0 ||
|
|
|
|
info->kind != SelectionSetOwner)
|
|
|
|
return;
|
|
|
|
|
2018-10-23 20:33:24 +02:00
|
|
|
listen_on_fds();
|
2014-03-12 00:11:39 +01:00
|
|
|
|
|
|
|
DeleteCallback(&SelectionCallback, wm_selection_callback, xwl_screen);
|
|
|
|
}
|
|
|
|
|
2014-10-31 00:26:28 +01:00
|
|
|
_X_NORETURN
|
2014-03-12 00:11:39 +01:00
|
|
|
static void _X_ATTRIBUTE_PRINTF(1, 0)
|
|
|
|
xwl_log_handler(const char *format, va_list args)
|
|
|
|
{
|
|
|
|
char msg[256];
|
|
|
|
|
|
|
|
vsnprintf(msg, sizeof msg, format, args);
|
|
|
|
FatalError("%s", msg);
|
|
|
|
}
|
|
|
|
|
2014-04-08 18:17:51 +02:00
|
|
|
static const ExtensionModule xwayland_extensions[] = {
|
2016-02-10 09:35:39 +01:00
|
|
|
#ifdef XF86VIDMODE
|
|
|
|
{ xwlVidModeExtensionInit, XF86VIDMODENAME, &noXFree86VidModeExtension },
|
|
|
|
#endif
|
2014-03-12 00:11:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
InitOutput(ScreenInfo * screen_info, int argc, char **argv)
|
|
|
|
{
|
|
|
|
int depths[] = { 1, 4, 8, 15, 16, 24, 32 };
|
|
|
|
int bpp[] = { 1, 8, 8, 16, 16, 32, 32 };
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(depths); i++) {
|
|
|
|
screen_info->formats[i].depth = depths[i];
|
|
|
|
screen_info->formats[i].bitsPerPixel = bpp[i];
|
|
|
|
screen_info->formats[i].scanlinePad = BITMAP_SCANLINE_PAD;
|
|
|
|
}
|
|
|
|
|
|
|
|
screen_info->imageByteOrder = IMAGE_BYTE_ORDER;
|
|
|
|
screen_info->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT;
|
|
|
|
screen_info->bitmapScanlinePad = BITMAP_SCANLINE_PAD;
|
|
|
|
screen_info->bitmapBitOrder = BITMAP_BIT_ORDER;
|
|
|
|
screen_info->numPixmapFormats = ARRAY_SIZE(depths);
|
|
|
|
|
2017-05-30 22:39:49 +02:00
|
|
|
if (serverGeneration == 1)
|
|
|
|
LoadExtensionList(xwayland_extensions,
|
|
|
|
ARRAY_SIZE(xwayland_extensions), FALSE);
|
2014-03-12 00:11:39 +01:00
|
|
|
|
|
|
|
/* Cast away warning from missing printf annotation for
|
|
|
|
* wl_log_func_t. Wayland 1.5 will have the annotation, so we can
|
|
|
|
* remove the cast and require that when it's released. */
|
|
|
|
wl_log_set_handler_client((void *) xwl_log_handler);
|
|
|
|
|
|
|
|
if (AddScreen(xwl_screen_init, argc, argv) == -1) {
|
|
|
|
FatalError("Couldn't add screen\n");
|
|
|
|
}
|
2015-05-05 22:43:44 +02:00
|
|
|
|
2018-01-10 19:05:45 +01:00
|
|
|
xorgGlxCreateVendor();
|
|
|
|
|
2015-05-05 22:43:44 +02:00
|
|
|
LocalAccessScopeUser();
|
2018-10-23 21:07:48 +02:00
|
|
|
|
2019-07-20 00:16:43 +02:00
|
|
|
if (wm_fd >= 0 || init_fd >= 0) {
|
|
|
|
if (wm_fd >= 0)
|
|
|
|
TimerSet(NULL, 0, 1, add_client_fd, NULL);
|
|
|
|
if (init_fd >= 0)
|
|
|
|
ListenOnOpenFD(init_fd, FALSE);
|
2019-01-02 21:55:23 +01:00
|
|
|
AddCallback(&SelectionCallback, wm_selection_callback, NULL);
|
2019-07-20 00:16:43 +02:00
|
|
|
}
|
|
|
|
else if (listen_fd_count > 0) {
|
2019-01-02 21:55:23 +01:00
|
|
|
listen_on_fds();
|
2018-10-23 21:07:48 +02:00
|
|
|
}
|
2014-03-12 00:11:39 +01:00
|
|
|
}
|