Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

X11 DRI2: check if device is a render node #584

Merged
merged 1 commit into from
Apr 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 33 additions & 7 deletions va/x11/dri2_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <fcntl.h>
#include <unistd.h>
#include <assert.h>
#include <sys/stat.h>

#include <xf86drm.h>

Expand Down Expand Up @@ -171,6 +172,29 @@ dri2Close(VADriverContextP ctx)
close(dri_state->base.fd);
}

int
va_isRenderNodeFd(int fd)
{
struct stat st;
char *name;

/* Check by device node */
if (fstat(fd, &st) == 0)
return S_ISCHR(st.st_mode) && (st.st_rdev & 0x80);

/* Check by device name */
name = drmGetDeviceNameFromFd(fd);
if (name) {
/* drmGetDeviceNameFromFd returns a strdup'ed string */
int r = (strncmp(name, "/dev/dri/renderD", 16) == 0);
drmFree(name);
return r;
}

/* Unrecoverable error */
return -1;
}

Bool
va_isDRI2Connected(VADriverContextP ctx, char **driver_name)
{
Expand All @@ -179,6 +203,7 @@ va_isDRI2Connected(VADriverContextP ctx, char **driver_name)
int error_base;
int event_base;
char *device_name = NULL;
int is_render_nodes;
drm_magic_t magic;
*driver_name = NULL;

Expand All @@ -198,16 +223,17 @@ va_isDRI2Connected(VADriverContextP ctx, char **driver_name)

dri_state->base.fd = open(device_name, O_RDWR);

if (dri_state->base.fd < 0)
if (dri_state->base.fd < 0 || (is_render_nodes = va_isRenderNodeFd(dri_state->base.fd)) < 0)
goto err_out;

if (drmGetMagic(dri_state->base.fd, &magic))
goto err_out;

if (!VA_DRI2Authenticate(ctx->native_dpy, RootWindow(ctx->native_dpy, ctx->x11_screen),
magic))
goto err_out;
if (!is_render_nodes) {
if (drmGetMagic(dri_state->base.fd, &magic))
goto err_out;

if (!VA_DRI2Authenticate(ctx->native_dpy, RootWindow(ctx->native_dpy, ctx->x11_screen),
magic))
goto err_out;
}
dri_state->base.auth_type = VA_DRI2;
dri_state->createDrawable = dri2CreateDrawable;
dri_state->destroyDrawable = dri2DestroyDrawable;
Expand Down