aboutsummaryrefslogtreecommitdiff
path: root/render
diff options
context:
space:
mode:
Diffstat (limited to 'render')
-rw-r--r--render/egl.c4
-rw-r--r--render/wlr_renderer.c78
2 files changed, 47 insertions, 35 deletions
diff --git a/render/egl.c b/render/egl.c
index 168e358c..ee961f4b 100644
--- a/render/egl.c
+++ b/render/egl.c
@@ -11,6 +11,7 @@
#include <wlr/util/region.h>
#include <xf86drm.h>
#include "render/egl.h"
+#include "util/env.h"
static enum wlr_log_importance egl_log_importance_to_wlr(EGLint type) {
switch (type) {
@@ -284,8 +285,7 @@ static bool egl_init_display(struct wlr_egl *egl, EGLDisplay *display) {
}
if (check_egl_ext(device_exts_str, "EGL_MESA_device_software")) {
- const char *allow_software = getenv("WLR_RENDERER_ALLOW_SOFTWARE");
- if (allow_software != NULL && strcmp(allow_software, "1") == 0) {
+ if (env_parse_bool("WLR_RENDERER_ALLOW_SOFTWARE")) {
wlr_log(WLR_INFO, "Using software rendering");
} else {
wlr_log(WLR_ERROR, "Software rendering detected, please use "
diff --git a/render/wlr_renderer.c b/render/wlr_renderer.c
index 622f5f96..f140f9af 100644
--- a/render/wlr_renderer.c
+++ b/render/wlr_renderer.c
@@ -28,6 +28,7 @@
#include "backend/backend.h"
#include "render/pixel_format.h"
#include "render/wlr_renderer.h"
+#include "util/env.h"
void wlr_renderer_init(struct wlr_renderer *renderer,
const struct wlr_renderer_impl *impl) {
@@ -266,54 +267,65 @@ bool wlr_renderer_init_wl_display(struct wlr_renderer *r,
return true;
}
+static void log_creation_failure(bool is_auto, const char *msg) {
+ wlr_log(is_auto ? WLR_DEBUG : WLR_ERROR, "%s%s", msg, is_auto ? ". Skipping!" : "");
+}
+
struct wlr_renderer *renderer_autocreate_with_drm_fd(int drm_fd) {
- const char *name = getenv("WLR_RENDERER");
- if (name) {
- wlr_log(WLR_INFO, "Loading user-specified renderer due to WLR_RENDERER: %s",
- name);
+ const char *renderer_options[] = {
+ "auto",
+#if WLR_HAS_GLES2_RENDERER
+ "gles2",
+#endif
+#if WLR_HAS_VULKAN_RENDERER
+ "vulkan",
+#endif
+ "pixman",
+ NULL
+ };
+
+ const char *renderer_name = renderer_options[env_parse_switch("WLR_RENDERER", renderer_options)];
+ bool is_auto = strcmp(renderer_name, "auto") == 0;
+ struct wlr_renderer *renderer = NULL;
#if WLR_HAS_GLES2_RENDERER
- if (strcmp(name, "gles2") == 0) {
- if (drm_fd < 0) {
- wlr_log(WLR_ERROR, "Cannot create GLES2 renderer: "
- "no DRM FD available");
- return NULL;
+ if (!renderer && (is_auto || strcmp(renderer_name, "gles2") == 0)) {
+ if (drm_fd < 0) {
+ log_creation_failure(is_auto, "Cannot create GLES2 renderer: no DRM FD available");
+ } else {
+ renderer = wlr_gles2_renderer_create_with_drm_fd(drm_fd);
+ if (!renderer) {
+ log_creation_failure(is_auto, "Failed to create a GLES2 renderer");
}
- return wlr_gles2_renderer_create_with_drm_fd(drm_fd);
}
+ }
#endif
+
#if WLR_HAS_VULKAN_RENDERER
- if (strcmp(name, "vulkan") == 0) {
- return wlr_vk_renderer_create_with_drm_fd(drm_fd);
- }
-#endif
- if (strcmp(name, "pixman") == 0) {
- return wlr_pixman_renderer_create();
+ if (!renderer && (is_auto || strcmp(renderer_name, "vulkan") == 0)) {
+ if (drm_fd < 0) {
+ log_creation_failure(is_auto, "Cannot create Vulkan renderer: no DRM FD available");
+ } else {
+ renderer = wlr_vk_renderer_create_with_drm_fd(drm_fd);
+ if (!renderer) {
+ log_creation_failure(is_auto, "Failed to create a Vulkan renderer");
+ }
}
-
- wlr_log(WLR_ERROR, "Invalid WLR_RENDERER value: '%s'", name);
- return NULL;
}
+#endif
- struct wlr_renderer *renderer = NULL;
-#if WLR_HAS_GLES2_RENDERER
- if (drm_fd >= 0) {
- if ((renderer = wlr_gles2_renderer_create_with_drm_fd(drm_fd)) != NULL) {
- return renderer;
+ if (!renderer && (is_auto || strcmp(renderer_name, "pixman") == 0)) {
+ renderer = wlr_pixman_renderer_create();
+ if (!renderer) {
+ log_creation_failure(is_auto, "Failed to create a pixman renderer");
}
- wlr_log(WLR_DEBUG, "Failed to create GLES2 renderer");
- } else {
- wlr_log(WLR_DEBUG, "Skipping GLES2 renderer: no DRM FD available");
}
-#endif
- if ((renderer = wlr_pixman_renderer_create()) != NULL) {
- return renderer;
+ if (!renderer) {
+ wlr_log(WLR_ERROR, "Could not initialize renderer");
}
- wlr_log(WLR_DEBUG, "Failed to create pixman renderer");
- wlr_log(WLR_ERROR, "Could not initialize renderer");
- return NULL;
+ return renderer;
}
static int open_drm_render_node(void) {