Use env helpers

Alexander Orzechowski 2 years ago
parent 31a9fc1fb6
commit 8bd7170fd9

@ -17,6 +17,7 @@
#include "backend/backend.h" #include "backend/backend.h"
#include "backend/multi.h" #include "backend/multi.h"
#include "render/allocator/allocator.h" #include "render/allocator/allocator.h"
#include "util/env.h"
#if WLR_HAS_DRM_BACKEND #if WLR_HAS_DRM_BACKEND
#include <wlr/backend/drm.h> #include <wlr/backend/drm.h>
@ -364,8 +365,7 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) {
} }
wlr_multi_backend_add(backend, libinput); wlr_multi_backend_add(backend, libinput);
#else #else
const char *no_devs = getenv("WLR_LIBINPUT_NO_DEVICES"); if (env_parse_bool("WLR_LIBINPUT_NO_DEVICES")) {
if (no_devs && strcmp(no_devs, "1") == 0) {
wlr_log(WLR_INFO, "WLR_LIBINPUT_NO_DEVICES is set, " wlr_log(WLR_INFO, "WLR_LIBINPUT_NO_DEVICES is set, "
"starting without libinput backend"); "starting without libinput backend");
} else { } else {

@ -29,6 +29,7 @@
#include "render/drm_format_set.h" #include "render/drm_format_set.h"
#include "render/swapchain.h" #include "render/swapchain.h"
#include "render/wlr_renderer.h" #include "render/wlr_renderer.h"
#include "util/env.h"
// Output state which needs a KMS commit to be applied // Output state which needs a KMS commit to be applied
static const uint32_t COMMIT_OUTPUT_STATE = static const uint32_t COMMIT_OUTPUT_STATE =
@ -74,8 +75,7 @@ bool check_drm_features(struct wlr_drm_backend *drm) {
return false; return false;
} }
const char *no_atomic = getenv("WLR_DRM_NO_ATOMIC"); if (env_parse_bool("WLR_DRM_NO_ATOMIC")) {
if (no_atomic && strcmp(no_atomic, "1") == 0) {
wlr_log(WLR_DEBUG, wlr_log(WLR_DEBUG,
"WLR_DRM_NO_ATOMIC set, forcing legacy DRM interface"); "WLR_DRM_NO_ATOMIC set, forcing legacy DRM interface");
drm->iface = &legacy_iface; drm->iface = &legacy_iface;
@ -91,8 +91,7 @@ bool check_drm_features(struct wlr_drm_backend *drm) {
int ret = drmGetCap(drm->fd, DRM_CAP_TIMESTAMP_MONOTONIC, &cap); int ret = drmGetCap(drm->fd, DRM_CAP_TIMESTAMP_MONOTONIC, &cap);
drm->clock = (ret == 0 && cap == 1) ? CLOCK_MONOTONIC : CLOCK_REALTIME; drm->clock = (ret == 0 && cap == 1) ? CLOCK_MONOTONIC : CLOCK_REALTIME;
const char *no_modifiers = getenv("WLR_DRM_NO_MODIFIERS"); if (env_parse_bool("WLR_DRM_NO_MODIFIERS")) {
if (no_modifiers != NULL && strcmp(no_modifiers, "1") == 0) {
wlr_log(WLR_DEBUG, "WLR_DRM_NO_MODIFIERS set, disabling modifiers"); wlr_log(WLR_DEBUG, "WLR_DRM_NO_MODIFIERS set, disabling modifiers");
} else { } else {
ret = drmGetCap(drm->fd, DRM_CAP_ADDFB2_MODIFIERS, &cap); ret = drmGetCap(drm->fd, DRM_CAP_ADDFB2_MODIFIERS, &cap);

@ -6,6 +6,7 @@
#include <wlr/backend/session.h> #include <wlr/backend/session.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include "backend/libinput.h" #include "backend/libinput.h"
#include "util/env.h"
static struct wlr_libinput_backend *get_libinput_backend_from_backend( static struct wlr_libinput_backend *get_libinput_backend_from_backend(
struct wlr_backend *wlr_backend) { struct wlr_backend *wlr_backend) {
@ -103,13 +104,8 @@ static bool backend_start(struct wlr_backend *wlr_backend) {
libinput_log_set_priority(backend->libinput_context, LIBINPUT_LOG_PRIORITY_ERROR); libinput_log_set_priority(backend->libinput_context, LIBINPUT_LOG_PRIORITY_ERROR);
int libinput_fd = libinput_get_fd(backend->libinput_context); int libinput_fd = libinput_get_fd(backend->libinput_context);
char *no_devs = getenv("WLR_LIBINPUT_NO_DEVICES");
if (no_devs) { if (!env_parse_bool("WLR_LIBINPUT_NO_DEVICES") && wl_list_empty(&backend->devices)) {
if (strcmp(no_devs, "1") != 0) {
no_devs = NULL;
}
}
if (!no_devs && wl_list_empty(&backend->devices)) {
handle_libinput_readable(libinput_fd, WL_EVENT_READABLE, backend); handle_libinput_readable(libinput_fd, WL_EVENT_READABLE, backend);
if (wl_list_empty(&backend->devices)) { if (wl_list_empty(&backend->devices)) {
wlr_log(WLR_ERROR, "libinput initialization failed, no input devices"); wlr_log(WLR_ERROR, "libinput initialization failed, no input devices");

@ -11,6 +11,7 @@
#include <wlr/util/region.h> #include <wlr/util/region.h>
#include <xf86drm.h> #include <xf86drm.h>
#include "render/egl.h" #include "render/egl.h"
#include "util/env.h"
static enum wlr_log_importance egl_log_importance_to_wlr(EGLint type) { static enum wlr_log_importance egl_log_importance_to_wlr(EGLint type) {
switch (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")) { if (check_egl_ext(device_exts_str, "EGL_MESA_device_software")) {
const char *allow_software = getenv("WLR_RENDERER_ALLOW_SOFTWARE"); if (env_parse_bool("WLR_RENDERER_ALLOW_SOFTWARE")) {
if (allow_software != NULL && strcmp(allow_software, "1") == 0) {
wlr_log(WLR_INFO, "Using software rendering"); wlr_log(WLR_INFO, "Using software rendering");
} else { } else {
wlr_log(WLR_ERROR, "Software rendering detected, please use " wlr_log(WLR_ERROR, "Software rendering detected, please use "

@ -28,6 +28,7 @@
#include "backend/backend.h" #include "backend/backend.h"
#include "render/pixel_format.h" #include "render/pixel_format.h"
#include "render/wlr_renderer.h" #include "render/wlr_renderer.h"
#include "util/env.h"
void wlr_renderer_init(struct wlr_renderer *renderer, void wlr_renderer_init(struct wlr_renderer *renderer,
const struct wlr_renderer_impl *impl) { const struct wlr_renderer_impl *impl) {
@ -266,54 +267,65 @@ bool wlr_renderer_init_wl_display(struct wlr_renderer *r,
return true; 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) { struct wlr_renderer *renderer_autocreate_with_drm_fd(int drm_fd) {
const char *name = getenv("WLR_RENDERER"); const char *renderer_options[] = {
if (name) { "auto",
wlr_log(WLR_INFO, "Loading user-specified renderer due to WLR_RENDERER: %s", #if WLR_HAS_GLES2_RENDERER
name); "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 WLR_HAS_GLES2_RENDERER
if (strcmp(name, "gles2") == 0) { if (!renderer && (is_auto || strcmp(renderer_name, "gles2") == 0)) {
if (drm_fd < 0) { if (drm_fd < 0) {
wlr_log(WLR_ERROR, "Cannot create GLES2 renderer: " log_creation_failure(is_auto, "Cannot create GLES2 renderer: no DRM FD available");
"no DRM FD available"); } else {
return NULL; 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 #endif
#if WLR_HAS_VULKAN_RENDERER #if WLR_HAS_VULKAN_RENDERER
if (strcmp(name, "vulkan") == 0) { if (!renderer && (is_auto || strcmp(renderer_name, "vulkan") == 0)) {
return wlr_vk_renderer_create_with_drm_fd(drm_fd); if (drm_fd < 0) {
} log_creation_failure(is_auto, "Cannot create Vulkan renderer: no DRM FD available");
#endif } else {
if (strcmp(name, "pixman") == 0) { renderer = wlr_vk_renderer_create_with_drm_fd(drm_fd);
return wlr_pixman_renderer_create(); 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 (!renderer && (is_auto || strcmp(renderer_name, "pixman") == 0)) {
#if WLR_HAS_GLES2_RENDERER renderer = wlr_pixman_renderer_create();
if (drm_fd >= 0) { if (!renderer) {
if ((renderer = wlr_gles2_renderer_create_with_drm_fd(drm_fd)) != NULL) { log_creation_failure(is_auto, "Failed to create a pixman renderer");
return 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) { if (!renderer) {
return 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 renderer;
return NULL;
} }
static int open_drm_render_node(void) { static int open_drm_render_node(void) {

@ -10,6 +10,7 @@
#include "render/allocator/allocator.h" #include "render/allocator/allocator.h"
#include "render/swapchain.h" #include "render/swapchain.h"
#include "types/wlr_output.h" #include "types/wlr_output.h"
#include "util/env.h"
#include "util/global.h" #include "util/global.h"
#define OUTPUT_VERSION 4 #define OUTPUT_VERSION 4
@ -366,11 +367,9 @@ void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend,
wl_signal_init(&output->events.destroy); wl_signal_init(&output->events.destroy);
output_state_init(&output->pending); output_state_init(&output->pending);
const char *no_hardware_cursors = getenv("WLR_NO_HARDWARE_CURSORS"); output->software_cursor_locks = env_parse_bool("WLR_NO_HARDWARE_CURSORS");
if (no_hardware_cursors != NULL && strcmp(no_hardware_cursors, "1") == 0) { if (output->software_cursor_locks) {
wlr_log(WLR_DEBUG, wlr_log(WLR_DEBUG, "WLR_NO_HARDWARE_CURSORS set, forcing software cursors");
"WLR_NO_HARDWARE_CURSORS set, forcing software cursors");
output->software_cursor_locks = 1;
} }
wlr_addon_set_init(&output->addons); wlr_addon_set_init(&output->addons);

@ -14,6 +14,7 @@
#include "types/wlr_buffer.h" #include "types/wlr_buffer.h"
#include "types/wlr_scene.h" #include "types/wlr_scene.h"
#include "util/array.h" #include "util/array.h"
#include "util/env.h"
#include "util/time.h" #include "util/time.h"
#define HIGHLIGHT_DAMAGE_FADEOUT_TIME 250 #define HIGHLIGHT_DAMAGE_FADEOUT_TIME 250
@ -150,49 +151,16 @@ struct wlr_scene *wlr_scene_create(void) {
wl_list_init(&scene->outputs); wl_list_init(&scene->outputs);
wl_list_init(&scene->presentation_destroy.link); wl_list_init(&scene->presentation_destroy.link);
char *debug_damage = getenv("WLR_SCENE_DEBUG_DAMAGE"); const char *debug_damage_options[] = {
if (debug_damage) { "none",
wlr_log(WLR_INFO, "Loading WLR_SCENE_DEBUG_DAMAGE option: %s", debug_damage); "rerender",
} "highlight",
NULL
if (!debug_damage || strcmp(debug_damage, "none") == 0) { };
scene->debug_damage_option = WLR_SCENE_DEBUG_DAMAGE_NONE;
} else if (strcmp(debug_damage, "rerender") == 0) {
scene->debug_damage_option = WLR_SCENE_DEBUG_DAMAGE_RERENDER;
} else if (strcmp(debug_damage, "highlight") == 0) {
scene->debug_damage_option = WLR_SCENE_DEBUG_DAMAGE_HIGHLIGHT;
} else {
wlr_log(WLR_ERROR, "Unknown WLR_SCENE_DEBUG_DAMAGE option: %s", debug_damage);
scene->debug_damage_option = WLR_SCENE_DEBUG_DAMAGE_NONE;
}
char *disable_direct_scanout = getenv("WLR_SCENE_DISABLE_DIRECT_SCANOUT");
if (disable_direct_scanout) {
wlr_log(WLR_INFO, "Loading WLR_SCENE_DISABLE_DIRECT_SCANOUT option: %s", disable_direct_scanout);
}
if (!disable_direct_scanout || strcmp(disable_direct_scanout, "0") == 0) {
scene->direct_scanout = true;
} else if (strcmp(disable_direct_scanout, "1") == 0) {
scene->direct_scanout = false;
} else {
wlr_log(WLR_ERROR, "Unknown WLR_SCENE_DISABLE_DIRECT_SCANOUT option: %s", disable_direct_scanout);
scene->direct_scanout = true;
}
char *visibility_disabled = getenv("WLR_SCENE_DISABLE_VISIBILITY");
if (visibility_disabled) {
wlr_log(WLR_INFO, "Loading WLR_SCENE_DISABLE_VISIBILITY option: %s", visibility_disabled);
}
if (!visibility_disabled || strcmp(visibility_disabled, "0") == 0) { scene->debug_damage_option = env_parse_switch("WLR_SCENE_DEBUG_DAMAGE", debug_damage_options);
scene->calculate_visibility = true; scene->direct_scanout = !env_parse_bool("WLR_SCENE_DISABLE_DIRECT_SCANOUT");
} else if (strcmp(visibility_disabled, "1") == 0) { scene->calculate_visibility = !env_parse_bool("WLR_SCENE_DISABLE_VISIBILITY");
scene->calculate_visibility = false;
} else {
wlr_log(WLR_ERROR, "Unknown WLR_SCENE_DISABLE_VISIBILITY option: %s", visibility_disabled);
scene->calculate_visibility = true;
}
return scene; return scene;
} }

Loading…
Cancel
Save