aboutsummaryrefslogtreecommitdiff
path: root/render/egl.c
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2023-11-20 20:48:55 +0100
committerSimon Ser <contact@emersion.fr>2023-11-28 13:12:43 +0000
commit395a08f5d19151b6a1a6e788c9f112a00953ec37 (patch)
tree330dc7553fd39c96c75a45ccbf16aaeb98825aab /render/egl.c
parent9a0a4ce221e30f5193a4a05571dd1517777687fa (diff)
render/egl: fallback to GBM FD if EGLDevice is not available
It's possible that we don't have an EGLDevice if we created the EGL context from a GBM device. Let's ensure all GPU-accelerated renderers always have a DRM FD to return by falling back to GBM's FD.
Diffstat (limited to 'render/egl.c')
-rw-r--r--render/egl.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/render/egl.c b/render/egl.c
index 8a1e6dae..162634be 100644
--- a/render/egl.c
+++ b/render/egl.c
@@ -954,7 +954,7 @@ static char *get_render_name(const char *name) {
return render_name;
}
-int wlr_egl_dup_drm_fd(struct wlr_egl *egl) {
+static int dup_egl_device_drm_fd(struct wlr_egl *egl) {
if (egl->device == EGL_NO_DEVICE_EXT || (!egl->exts.EXT_device_drm &&
!egl->exts.EXT_device_drm_render_node)) {
return -1;
@@ -1001,3 +1001,21 @@ int wlr_egl_dup_drm_fd(struct wlr_egl *egl) {
return render_fd;
}
+
+int wlr_egl_dup_drm_fd(struct wlr_egl *egl) {
+ int fd = dup_egl_device_drm_fd(egl);
+ if (fd >= 0) {
+ return fd;
+ }
+
+ // Fallback to GBM's FD if we can't use EGLDevice
+ if (egl->gbm_device == NULL) {
+ return -1;
+ }
+
+ fd = fcntl(gbm_device_get_fd(egl->gbm_device), F_DUPFD_CLOEXEC, 0);
+ if (fd < 0) {
+ wlr_log_errno(WLR_ERROR, "Failed to dup GBM FD");
+ }
+ return fd;
+}