glx: Check that xshm can be attached

Cc: mesa-stable
Co-authored-by: Carlos Lopez <clopez@igalia.com>
(cherry picked from commit a67af81944)

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/40359>
This commit is contained in:
Lucas Fryzek 2025-05-28 08:25:08 -04:00 committed by Eric Engestrom
parent 2c4c7fbfa9
commit 5f4eccf1fb
2 changed files with 6 additions and 40 deletions

View file

@ -2404,7 +2404,7 @@
"description": "glx: Check that xshm can be attached",
"nominated": true,
"nomination_type": 1,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": null,
"notes": null

View file

@ -40,11 +40,13 @@
#include <vulkan/vulkan_core.h>
#include <vulkan/vulkan_xcb.h>
#include "util/u_debug.h"
#include "util/log.h"
#include "kopper_interface.h"
#include "loader_dri_helper.h"
#include "dri_util.h"
#include "mesa/glapi/glapi/glapi.h"
#include "dispatch.h"
#include "x11_display.h"
static int xshm_error = 0;
static int xshm_opcode = -1;
@ -581,44 +583,6 @@ drisw_copy_sub_buffer(__GLXDRIdrawable * pdraw,
driswCopySubBuffer(pdraw->dri_drawable, x, y, width, height);
}
static int
check_xshm(Display *dpy)
{
xcb_connection_t *c = XGetXCBConnection(dpy);
xcb_void_cookie_t cookie;
xcb_generic_error_t *error;
int ret = True;
xcb_query_extension_cookie_t shm_cookie;
xcb_query_extension_reply_t *shm_reply;
shm_cookie = xcb_query_extension(c, 7, "MIT-SHM");
shm_reply = xcb_query_extension_reply(c, shm_cookie, NULL);
if (shm_reply) {
bool has_mit_shm = shm_reply->present;
if (has_mit_shm)
xshm_opcode = shm_reply->major_opcode;
free(shm_reply);
if (!has_mit_shm)
return False;
}
cookie = xcb_shm_detach_checked(c, 0);
if ((error = xcb_request_check(c, cookie))) {
/* BadRequest means we're a remote client. If we were local we'd
* expect BadValue since 'info' has an invalid segment name.
*/
if (error->error_code == BadRequest)
ret = False;
free(error);
}
return ret;
}
static int
driswKopperSetSwapInterval(__GLXDRIdrawable *pdraw, int interval)
{
@ -677,8 +641,10 @@ driswCreateScreen(int screen, struct glx_display *priv, enum glx_driver glx_driv
if (glx_driver)
loader_extensions_local = kopper_extensions_noshm;
else if (!check_xshm(priv->dpy))
#ifdef HAVE_SYS_SHM_H
else if (!x11_xcb_display_supports_xshm(XGetXCBConnection(priv->dpy)))
loader_extensions_local = loader_extensions_noshm;
#endif
else
loader_extensions_local = loader_extensions_shm;
priv->driver = glx_driver ? GLX_DRIVER_ZINK_YES : GLX_DRIVER_SW;