mirror of
https://gitlab.freedesktop.org/mesa/vulkan-wsi-layer.git
synced 2025-12-20 04:30:11 +01:00
Scan DRM device nodes for the VK_KHR_display backend
To specify a DRM device node for the VK_KHR_display backend, WSI_DISPLAY_DRI_DEV environment variable needs to be set. If WSI_DISPLAY_DRI_DEV is not set, the VK_KHR_display backend now scans all DRM device node, and uses the first node that has a display connected. Signed-off-by: Fufu Fang <fufu.fang@arm.com> Change-Id: Idbcda60cf3b1656784e6d3b0547cc70e99f0fc52
This commit is contained in:
parent
edcd2c2629
commit
5e53d9637f
1 changed files with 36 additions and 6 deletions
|
|
@ -34,14 +34,14 @@
|
|||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
#include <drm_fourcc.h>
|
||||
#include <dirent.h>
|
||||
|
||||
namespace wsi
|
||||
{
|
||||
|
||||
namespace display
|
||||
{
|
||||
|
||||
const std::string default_dri_device_name{ "/dev/dri/card0" };
|
||||
|
||||
drm_display::drm_display(util::fd_owner drm_fd, int crtc_id, drm_connector_owner drm_connector,
|
||||
util::unique_ptr<util::vector<util::drm::drm_format_pair>> supported_formats,
|
||||
util::unique_ptr<drm_display_mode> display_modes, size_t num_display_modes, uint32_t max_width,
|
||||
|
|
@ -355,12 +355,42 @@ std::optional<drm_display> &drm_display::get_display()
|
|||
|
||||
std::call_once(flag, []() {
|
||||
const char *dri_device = std::getenv("WSI_DISPLAY_DRI_DEV");
|
||||
if (!dri_device)
|
||||
if (dri_device)
|
||||
{
|
||||
dri_device = default_dri_device_name.c_str();
|
||||
display = drm_display::make_display(util::allocator::get_generic(), dri_device);
|
||||
if (!display.has_value())
|
||||
{
|
||||
WSI_LOG_ERROR("Failed to open DRM device: %s", dri_device);
|
||||
}
|
||||
else
|
||||
{
|
||||
WSI_LOG_INFO("Using DRM device from WSI_DISPLAY_DRI_DEV: %s", dri_device);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const char *dri_dir = "/dev/dri";
|
||||
DIR *dir = opendir(dri_dir);
|
||||
if (!dir)
|
||||
{
|
||||
return;
|
||||
}
|
||||
struct dirent *entry;
|
||||
while ((entry = readdir(dir)) != nullptr)
|
||||
{
|
||||
if (strncmp(entry->d_name, "card", 4) == 0)
|
||||
{
|
||||
std::string path = std::string(dri_dir) + "/" + entry->d_name;
|
||||
display = drm_display::make_display(util::allocator::get_generic(), path.c_str());
|
||||
if (display.has_value())
|
||||
{
|
||||
WSI_LOG_INFO("Using DRM device: %s", path.c_str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
}
|
||||
|
||||
display = drm_display::make_display(util::allocator::get_generic(), dri_device);
|
||||
});
|
||||
return display;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue