Skip to content

Commit aeba585

Browse files
akarl10XinfengZhang
authored andcommitted
X11 DRI2: check if device is a render node
and if so skip drmGetMagic and VA_DRI2Authenticate. This is essentailly the same as in the pure drm non X11 case
1 parent 3f43acf commit aeba585

File tree

1 file changed

+33
-7
lines changed

1 file changed

+33
-7
lines changed

va/x11/dri2_util.c

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <fcntl.h>
2626
#include <unistd.h>
2727
#include <assert.h>
28+
#include <sys/stat.h>
2829

2930
#include <xf86drm.h>
3031

@@ -171,6 +172,29 @@ dri2Close(VADriverContextP ctx)
171172
close(dri_state->base.fd);
172173
}
173174

175+
int
176+
va_isRenderNodeFd(int fd)
177+
{
178+
struct stat st;
179+
char *name;
180+
181+
/* Check by device node */
182+
if (fstat(fd, &st) == 0)
183+
return S_ISCHR(st.st_mode) && (st.st_rdev & 0x80);
184+
185+
/* Check by device name */
186+
name = drmGetDeviceNameFromFd(fd);
187+
if (name) {
188+
/* drmGetDeviceNameFromFd returns a strdup'ed string */
189+
int r = (strncmp(name, "/dev/dri/renderD", 16) == 0);
190+
drmFree(name);
191+
return r;
192+
}
193+
194+
/* Unrecoverable error */
195+
return -1;
196+
}
197+
174198
Bool
175199
va_isDRI2Connected(VADriverContextP ctx, char **driver_name)
176200
{
@@ -179,6 +203,7 @@ va_isDRI2Connected(VADriverContextP ctx, char **driver_name)
179203
int error_base;
180204
int event_base;
181205
char *device_name = NULL;
206+
int is_render_nodes;
182207
drm_magic_t magic;
183208
*driver_name = NULL;
184209

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

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

201-
if (dri_state->base.fd < 0)
226+
if (dri_state->base.fd < 0 || (is_render_nodes = va_isRenderNodeFd(dri_state->base.fd)) < 0)
202227
goto err_out;
203228

204-
if (drmGetMagic(dri_state->base.fd, &magic))
205-
goto err_out;
206-
207-
if (!VA_DRI2Authenticate(ctx->native_dpy, RootWindow(ctx->native_dpy, ctx->x11_screen),
208-
magic))
209-
goto err_out;
229+
if (!is_render_nodes) {
230+
if (drmGetMagic(dri_state->base.fd, &magic))
231+
goto err_out;
210232

233+
if (!VA_DRI2Authenticate(ctx->native_dpy, RootWindow(ctx->native_dpy, ctx->x11_screen),
234+
magic))
235+
goto err_out;
236+
}
211237
dri_state->base.auth_type = VA_DRI2;
212238
dri_state->createDrawable = dri2CreateDrawable;
213239
dri_state->destroyDrawable = dri2DestroyDrawable;

0 commit comments

Comments
 (0)