This commit is contained in:
elwrcl committed 2026-06-06 13:25:15 +03:00
1 parent 04d4dc8b09
commit 818cab85dc
12511 files changed
+6156641

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
# Copyright © 2017 Intel Corporation
# SPDX-License-Identifier: MIT
inc_loader_x11 = include_directories('.')
loader_x11_files = files(
'x11_display.c',
)
if with_dri_platform == 'drm' or with_dri_platform == 'pseudo-drm'
loader_x11_files += files('x11_dri3.c')
endif
libloader_x11 = static_library(
'loader_x11',
loader_x11_files,
gnu_symbol_visibility : 'hidden',
include_directories : [inc_include, inc_src],
dependencies : [
idep_mesautil,
dep_libdrm, dep_xcb_dri3, dep_xcb_present, dep_xcb_sync, dep_xshmfence,
dep_xcb_xfixes, dep_x11
],
build_by_default : false,
)
+128
View File
@@ -0,0 +1,128 @@
/*
* Copyright © 2025 Collabora, Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#include "x11_display.h"
#include "util/macros.h"
#include "util/log.h"
#include <stdio.h>
#include <X11/Xlibint.h>
#ifdef HAVE_SYS_SHM_H
#include <xcb/shm.h>
#include <sys/shm.h>
#endif
bool
x11_xlib_display_is_thread_safe(Display *dpy)
{
static bool warned = false;
/* 'lock_fns' is the XLockDisplay function pointer of the X11 display 'dpy'.
* It will be NULL if XInitThreads wasn't called.
*/
if (likely(dpy->lock_fns != NULL))
return true;
if (unlikely(!warned)) {
fprintf(stderr, "Xlib is not thread-safe. This should never be the "
"case starting with XLib 1.8. Either upgrade XLib "
"or call XInitThreads() from your app.\n");
warned = true;
}
return false;
}
#ifdef HAVE_SYS_SHM_H
bool
x11_xcb_display_supports_xshm(xcb_connection_t *con)
{
xcb_generic_error_t *error;
xcb_query_extension_cookie_t shm_cookie;
xcb_query_extension_reply_t *shm_reply;
bool has_mit_shm;
int shmid;
void *shm_addr = (void *) -1;
xcb_shm_seg_t shm_seg;
bool ret = true;
shm_cookie = xcb_query_extension(con, 7, "MIT-SHM");
shm_reply = xcb_query_extension_reply(con, shm_cookie, NULL);
has_mit_shm = shm_reply && shm_reply->present;
free(shm_reply);
if (!has_mit_shm)
return false;
/* Check if we're a remote client by attempting to detach segment 0.
* Remote clients will get BadRequest, local clients get BadValue,
* since 'info' has an invalid segment name.
*/
if ((error = xcb_request_check(con,
xcb_shm_detach_checked(con, 0)))) {
bool is_remote = error->error_code == BadRequest;
free(error);
if (is_remote)
return false;
}
/* We're a local client. Now verify we can actually attach SHM.
* In some container setups, the X server reports MIT-SHM support
* but the client lacks permission to attach shared memory.
*/
shmid = shmget(IPC_PRIVATE, 4096, IPC_CREAT | 0600);
if (shmid < 0) {
mesa_logd("shared memory allocation error: %s", strerror(errno));
return false;
}
shm_addr = shmat(shmid, NULL, 0);
if (shm_addr == (void *) -1) {
mesa_logd("shmat failed: %s", strerror(errno));
ret = false;
goto check_xshm_cleanup;
}
shm_seg = xcb_generate_id(con);
error = xcb_request_check(con,
xcb_shm_attach_checked(con,
shm_seg, shmid, 0));
if (error) {
mesa_logd("Failed to attach to x11 shm with error: %u", error->error_code);
free(error);
ret = false;
goto check_xshm_cleanup;
}
/* Only detach if it was attached successfully */
xcb_shm_detach(con, shm_seg);
check_xshm_cleanup:
if (shm_addr != (void *) -1)
shmdt(shm_addr);
shmctl(shmid, IPC_RMID, NULL);
return ret;
}
#endif
+47
View File
@@ -0,0 +1,47 @@
/*
* Copyright © 2025 Collabora, Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#ifndef _UTIL_X11_H
#define _UTIL_X11_H
#include <stdbool.h>
#include <X11/Xlib.h>
#ifdef HAVE_SYS_SHM_H
#include <xcb/xcb.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
bool x11_xlib_display_is_thread_safe(Display *dpy);
#ifdef HAVE_SYS_SHM_H
bool x11_xcb_display_supports_xshm(xcb_connection_t *con);
#endif
#ifdef __cplusplus
} /* extern C */
#endif
#endif /* _UTIL_X11_H */
+146
View File
@@ -0,0 +1,146 @@
/*
* Copyright © 2013 Keith Packard
* Copyright © 2015 Boyan Ding
*
* 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.
*/
#include "x11_dri3.h"
#include <stdbool.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <xcb/xcb.h>
#include <xcb/dri3.h>
#include <xcb/present.h>
#include <xcb/xfixes.h>
/** x11_dri3_open
*
* Wrapper around xcb_dri3_open
*/
int
x11_dri3_open(xcb_connection_t *conn,
xcb_window_t root,
uint32_t provider)
{
xcb_dri3_open_cookie_t cookie;
xcb_dri3_open_reply_t *reply;
xcb_xfixes_query_version_cookie_t fixes_cookie;
xcb_xfixes_query_version_reply_t *fixes_reply;
int fd;
const xcb_query_extension_reply_t *extension;
xcb_prefetch_extension_data(conn, &xcb_dri3_id);
extension = xcb_get_extension_data(conn, &xcb_dri3_id);
if (!(extension && extension->present))
return -1;
cookie = xcb_dri3_open(conn,
root,
provider);
reply = xcb_dri3_open_reply(conn, cookie, NULL);
if (!reply || reply->nfd != 1) {
free(reply);
return -1;
}
fd = xcb_dri3_open_reply_fds(conn, reply)[0];
free(reply);
fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
/* let the server know our xfixes level */
fixes_cookie = xcb_xfixes_query_version(conn,
XCB_XFIXES_MAJOR_VERSION,
XCB_XFIXES_MINOR_VERSION);
fixes_reply = xcb_xfixes_query_version_reply(conn, fixes_cookie, NULL);
if (fixes_reply->major_version < 2) {
close(fd);
fd = -1;
}
free(fixes_reply);
return fd;
}
/* Only request versions of these protocols which we actually support. */
#define DRI3_SUPPORTED_MAJOR 1
#define PRESENT_SUPPORTED_MAJOR 1
#ifdef HAVE_X11_DRM
#define DRI3_SUPPORTED_MINOR 2
#define PRESENT_SUPPORTED_MINOR 2
#else
#define PRESENT_SUPPORTED_MINOR 0
#define DRI3_SUPPORTED_MINOR 0
#endif
bool
x11_dri3_has_multibuffer(xcb_connection_t *c)
{
xcb_dri3_query_version_cookie_t dri3_cookie;
xcb_dri3_query_version_reply_t *dri3_reply;
xcb_present_query_version_cookie_t present_cookie;
xcb_present_query_version_reply_t *present_reply;
xcb_generic_error_t *error;
const xcb_query_extension_reply_t *extension;
xcb_prefetch_extension_data(c, &xcb_dri3_id);
xcb_prefetch_extension_data(c, &xcb_present_id);
extension = xcb_get_extension_data(c, &xcb_dri3_id);
if (!(extension && extension->present))
return false;
extension = xcb_get_extension_data(c, &xcb_present_id);
if (!(extension && extension->present))
return false;
dri3_cookie = xcb_dri3_query_version(c,
DRI3_SUPPORTED_MAJOR,
DRI3_SUPPORTED_MINOR);
present_cookie = xcb_present_query_version(c,
PRESENT_SUPPORTED_MAJOR,
PRESENT_SUPPORTED_MINOR);
dri3_reply = xcb_dri3_query_version_reply(c, dri3_cookie, &error);
if (!dri3_reply) {
free(error);
return false;
}
int dri3Major = dri3_reply->major_version;
int dri3Minor = dri3_reply->minor_version;
free(dri3_reply);
present_reply = xcb_present_query_version_reply(c, present_cookie, &error);
if (!present_reply) {
free(error);
return false;
}
int presentMajor = present_reply->major_version;
int presentMinor = present_reply->minor_version;
free(present_reply);
return (presentMajor > 1 || (presentMajor == 1 && presentMinor >= 2)) &&
(dri3Major > 1 || (dri3Major == 1 && dri3Minor >= 2));
}
+34
View File
@@ -0,0 +1,34 @@
/*
* Copyright © 2013 Keith Packard
* Copyright © 2015 Boyan Ding
*
* 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.
*/
#ifndef LOADER_X11_H
#define LOADER_X11_H
#include <xcb/xcb.h>
#include <inttypes.h>
#include <stdbool.h>
int x11_dri3_open(xcb_connection_t *conn, xcb_window_t root, uint32_t provider);
bool x11_dri3_has_multibuffer(xcb_connection_t *c);
#endif