25
25
#include <fcntl.h>
26
26
#include <unistd.h>
27
27
#include <assert.h>
28
+ #include <sys/stat.h>
28
29
29
30
#include <xf86drm.h>
30
31
@@ -171,6 +172,29 @@ dri2Close(VADriverContextP ctx)
171
172
close (dri_state -> base .fd );
172
173
}
173
174
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
+
174
198
Bool
175
199
va_isDRI2Connected (VADriverContextP ctx , char * * driver_name )
176
200
{
@@ -179,6 +203,7 @@ va_isDRI2Connected(VADriverContextP ctx, char **driver_name)
179
203
int error_base ;
180
204
int event_base ;
181
205
char * device_name = NULL ;
206
+ int is_render_nodes ;
182
207
drm_magic_t magic ;
183
208
* driver_name = NULL ;
184
209
@@ -198,16 +223,17 @@ va_isDRI2Connected(VADriverContextP ctx, char **driver_name)
198
223
199
224
dri_state -> base .fd = open (device_name , O_RDWR );
200
225
201
- if (dri_state -> base .fd < 0 )
226
+ if (dri_state -> base .fd < 0 || ( is_render_nodes = va_isRenderNodeFd ( dri_state -> base . fd )) < 0 )
202
227
goto err_out ;
203
228
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 ;
210
232
233
+ if (!VA_DRI2Authenticate (ctx -> native_dpy , RootWindow (ctx -> native_dpy , ctx -> x11_screen ),
234
+ magic ))
235
+ goto err_out ;
236
+ }
211
237
dri_state -> base .auth_type = VA_DRI2 ;
212
238
dri_state -> createDrawable = dri2CreateDrawable ;
213
239
dri_state -> destroyDrawable = dri2DestroyDrawable ;
0 commit comments