aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2021-11-24 10:52:39 +0100
committerSimon Zeni <simon@bl4ckb0ne.ca>2021-11-25 15:12:32 +0000
commit2e33139ef732040c86e913ecb984c8eb0bf66cb2 (patch)
tree22d8c1b765b69956ab5d2198952afaee24dc5110
parentf29abe4c777ba8293ab76334ef2ac83eaa0043f6 (diff)
render: introduce WLR_RENDER_DRM_DEVICE
This env var allows to override the DRM node used by the GLES2 and Vulkan renderers. It's especially useful to select a DRM node when running with the headless backend. References: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/2656
-rw-r--r--docs/env_vars.md2
-rw-r--r--render/wlr_renderer.c29
2 files changed, 28 insertions, 3 deletions
diff --git a/docs/env_vars.md b/docs/env_vars.md
index 66c6dcc6..a07b2f19 100644
--- a/docs/env_vars.md
+++ b/docs/env_vars.md
@@ -10,6 +10,8 @@ wlroots reads these environment variables
of following shell search semantics for "Xwayland")
* *WLR_RENDERER*: forces the creation of a specified renderer (available
renderers: gles2, pixman, vulkan)
+* *WLR_RENDER_DRM_DEVICE*: specifies the DRM node to use for
+ hardware-accelerated renderers.
## DRM backend
diff --git a/render/wlr_renderer.c b/render/wlr_renderer.c
index 6667a819..ff315913 100644
--- a/render/wlr_renderer.c
+++ b/render/wlr_renderer.c
@@ -348,18 +348,41 @@ out:
}
struct wlr_renderer *wlr_renderer_autocreate(struct wlr_backend *backend) {
- // Note, drm_fd may be negative if unavailable
- int drm_fd = wlr_backend_get_drm_fd(backend);
+ int drm_fd = -1;
+ int render_drm_fd = -1;
+
+ // Allow the user to override the render node
+ const char *render_name = getenv("WLR_RENDER_DRM_DEVICE");
+ if (render_name != NULL) {
+ wlr_log(WLR_INFO,
+ "Opening DRM render node '%s' from WLR_RENDER_DRM_DEVICE",
+ render_name);
+ render_drm_fd = open(render_name, O_RDWR | O_CLOEXEC);
+ if (render_drm_fd < 0) {
+ wlr_log_errno(WLR_ERROR, "Failed to open '%s'", render_name);
+ return NULL;
+ }
+ if (drmGetNodeTypeFromFd(render_drm_fd) != DRM_NODE_RENDER) {
+ wlr_log(WLR_ERROR, "'%s' is not a DRM render node", render_name);
+ close(render_drm_fd);
+ return NULL;
+ }
+ drm_fd = render_drm_fd;
+ }
+
+ if (drm_fd < 0) {
+ drm_fd = wlr_backend_get_drm_fd(backend);
+ }
// If the backend hasn't picked a DRM FD, but accepts DMA-BUFs, pick an
// arbitrary render node
- int render_drm_fd = -1;
uint32_t backend_caps = backend_get_buffer_caps(backend);
if (drm_fd < 0 && (backend_caps & WLR_BUFFER_CAP_DMABUF) != 0) {
render_drm_fd = open_drm_render_node();
drm_fd = render_drm_fd;
}
+ // Note, drm_fd may be negative if unavailable
struct wlr_renderer *renderer = renderer_autocreate_with_drm_fd(drm_fd);
if (render_drm_fd >= 0) {