Skip to content

Commit

Permalink
egl-wayland: Make sure that the EGLDevice search matches the right de…
Browse files Browse the repository at this point in the history
…vice node

In checkNvidiaDrmDevice, while we've got the device open, call
drmGetDevice and make sure that wlEglGetPlatformDisplayExport is
matching the render node, regardless of whether the server sends back
the render or primary node.
  • Loading branch information
kbrenneman authored and Erik Kurzinger committed Oct 18, 2023
1 parent ba6c38a commit ea62b68
Showing 1 changed file with 34 additions and 8 deletions.
42 changes: 34 additions & 8 deletions src/wayland-egldisplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,7 @@ static EGLBoolean checkNvidiaDrmDevice(WlServerProtocols *protocols)
int fd = -1;
EGLBoolean result = EGL_FALSE;
drmVersion *version = NULL;
drmDevice *dev = NULL;

if (protocols->drm_name == NULL) {
goto done;
Expand All @@ -729,23 +730,48 @@ static EGLBoolean checkNvidiaDrmDevice(WlServerProtocols *protocols)
goto done;
}

version = drmGetVersion(fd);
if (version == NULL) {
goto done;
}
if (drmGetDevice(fd, &dev) == 0) {
if (dev->available_nodes & (1 << DRM_NODE_RENDER)) {
// Make sure that drm_name is the path to the render node, which is
// what wlEglGetPlatformDisplayExport checks for.
if (strcmp(protocols->drm_name, dev->nodes[DRM_NODE_RENDER]) != 0) {
free(protocols->drm_name);
protocols->drm_name = strdup(dev->nodes[DRM_NODE_RENDER]);
if (protocols->drm_name == NULL) {
goto done;
}
}
}

if (version->name != NULL) {
if (strcmp(version->name, "nvidia-drm") == 0
|| strcmp(version->name, "tegra-udrm") == 0
|| strcmp(version->name, "tegra") == 0) {
/*
* Since we've already called drmGetDevice anyway, if this is a PCI
* device, then check if the vendor ID is for NVIDIA. If this is a
* Tegra device, though, then it won't be a PCI device, so we'll need
* to call drmGetVesion and look at the driver name instead.
*/
if (dev->bustype == DRM_BUS_PCI && dev->deviceinfo.pci->vendor_id == 0x10de) {
result = EGL_TRUE;
}
}

if (!result) {
version = drmGetVersion(fd);
if (version != NULL && version->name != NULL) {
if (strcmp(version->name, "nvidia-drm") == 0
|| strcmp(version->name, "tegra-udrm") == 0
|| strcmp(version->name, "tegra") == 0) {
result = EGL_TRUE;
}
}
}

done:
if (version != NULL) {
drmFreeVersion(version);
}
if (dev != NULL) {
drmFreeDevice(&dev);
}
if (fd >= 0) {
close(fd);
}
Expand Down

0 comments on commit ea62b68

Please sign in to comment.