Skip to content

Commit ecd26b3

Browse files
computersforpeaceXinfengZhang
authored andcommitted
test_va_api: Don't assume our DRM node is first
Similar to: bfb6b98 exclude vgem node and invalid drm node in vainfo But adapted to use drmGetDevices2() for more generic handling. It's possible to have a vgem node at 128, and the VA-API node is at 129, for example. Signed-off-by: Brian Norris <[email protected]>
1 parent 3c5f3fb commit ecd26b3

File tree

3 files changed

+40
-16
lines changed

3 files changed

+40
-16
lines changed

common/Makefile.am

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ endif
4141

4242
if USE_DRM
4343
source_c += va_display_drm.c
44-
libva_display_cflags += $(DRM_CFLAGS) $(LIBVA_DRM_CFLAGS) $(DRM_CFLAGS)
45-
libva_display_libs += $(DRM_LIBS) $(LIBVA_DRM_LIBS)
44+
libva_display_cflags += $(LIBVA_DRM_CFLAGS)
45+
libva_display_libs += $(LIBVA_DRM_LIBS)
4646
endif
4747

4848
if USE_WAYLAND

configure.ac

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,7 @@ fi
143143
AM_CONDITIONAL(USE_SSP, test "$ssp_cc" = "yes")
144144

145145
# Check for DRM (mandatory)
146-
PKG_CHECK_MODULES([LIBVA_DRM], [libva-drm])
147-
PKG_CHECK_MODULES([DRM], [libdrm])
146+
PKG_CHECK_MODULES([LIBVA_DRM], [libva-drm libdrm])
148147

149148
# Check for libva (for dynamic linking)
150149
LIBVA_API_MIN_VERSION=libva_api_min_version

test/test_va_api_fixture.cpp

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@
2929

3030
#include <fcntl.h> // for O_RDWR
3131
#include <limits>
32+
#include <string.h>
3233

3334
#if defined(_WIN32)
3435
#include <va/va_win32.h>
3536
#include <compat_win32.h>
3637
#else
3738
#include <unistd.h> // for close()
3839
#include <va/va_drm.h>
40+
#include <xf86drm.h>
3941
#endif
4042

4143
namespace VAAPI
@@ -91,22 +93,45 @@ static VADisplay getWin32Display(LUID* adapter)
9193
#else
9294
static VADisplay getDrmDisplay(int &fd)
9395
{
94-
typedef std::vector<std::string> DevicePaths;
95-
typedef DevicePaths::const_iterator DevicePathsIterator;
96+
drmDevicePtr devices[32];
97+
int ret, max_devices = sizeof(devices) / sizeof(devices[0]);
9698

97-
static DevicePaths paths({"/dev/dri/renderD128", "/dev/dri/card0"});
99+
ret = drmGetDevices2(0, devices, max_devices);
100+
EXPECT_TRUE(ret >= 0);
101+
if (ret < 0)
102+
return NULL;
103+
max_devices = ret;
104+
105+
for (int i = 0; i < max_devices; i++) {
106+
for (int j = DRM_NODE_MAX - 1; j >= 0; j--) {
107+
drmVersionPtr version;
108+
109+
if (!(devices[i]->available_nodes & 1 << j))
110+
continue;
98111

99-
const DevicePathsIterator endIt(paths.end());
100-
for (DevicePathsIterator it(paths.begin()); it != endIt; ++it) {
101-
fd = open(it->c_str(), O_RDWR);
102-
if (fd < 0)
103-
continue;
104-
VADisplay disp = vaGetDisplayDRM(fd);
112+
fd = open(devices[i]->nodes[j], O_RDWR);
113+
if (fd < 0)
114+
continue;
105115

106-
if (disp)
107-
return disp;
116+
version = drmGetVersion(fd);
117+
if (!version) {
118+
close(fd);
119+
continue;
120+
}
121+
if (!strncmp(version->name, "vgem", 4)) {
122+
drmFreeVersion(version);
123+
close(fd);
124+
continue;
125+
}
126+
drmFreeVersion(version);
108127

109-
close(fd);
128+
VADisplay disp = vaGetDisplayDRM(fd);
129+
130+
if (disp)
131+
return disp;
132+
133+
close(fd);
134+
}
110135
}
111136

112137
return NULL;

0 commit comments

Comments
 (0)