summaryrefslogtreecommitdiff
path: root/compositor
diff options
context:
space:
mode:
authorDaniel Stone <daniels@collabora.com>2022-12-29 17:27:58 +0000
committerMarius Vlad <marius.vlad@collabora.com>2023-01-10 10:59:04 +0200
commit59968f7d785f92edd429ee01c65704b8490569b5 (patch)
tree45fbfeaa8e8c52ec3c4580bff9d7ff03d7eeb976 /compositor
parentef87ad2237183dd9e6f19f7dfe05fdabedd12a5a (diff)
downloadweston-59968f7d785f92edd429ee01c65704b8490569b5.tar.gz
frontend: Use enums for backend type, not strings
Convert our backend type to an enum early, and use it in place of a string. Signed-off-by: Daniel Stone <daniels@collabora.com>
Diffstat (limited to 'compositor')
-rw-r--r--compositor/config-helpers.c64
-rw-r--r--compositor/main.c38
-rw-r--r--compositor/meson.build1
-rw-r--r--compositor/weston-private.h4
4 files changed, 89 insertions, 18 deletions
diff --git a/compositor/config-helpers.c b/compositor/config-helpers.c
new file mode 100644
index 00000000..a012e723
--- /dev/null
+++ b/compositor/config-helpers.c
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2022 Collabora, Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include "config.h"
+
+#include <string.h>
+
+#include <libweston/libweston.h>
+#include <libweston/config-parser.h>
+
+#include "shared/helpers.h"
+#include "weston-private.h"
+
+struct {
+ char *short_name;
+ char *long_name;
+ enum weston_compositor_backend backend;
+} backend_name_map[] = {
+ { "drm", "drm-backend.so", WESTON_BACKEND_DRM },
+ { "headless", "headless-backend.so", WESTON_BACKEND_HEADLESS },
+ { "rdp", "rdp-backend.so", WESTON_BACKEND_RDP },
+ { "vnc", "vnc-backend.so", WESTON_BACKEND_VNC },
+ { "wayland", "wayland-backend.so", WESTON_BACKEND_WAYLAND },
+ { "x11", "x11-backend.so", WESTON_BACKEND_X11 },
+};
+
+bool
+get_backend_from_string(const char *name,
+ enum weston_compositor_backend *backend)
+{
+ size_t i;
+
+ for (i = 0; i < ARRAY_LENGTH(backend_name_map); i++) {
+ if (strcmp(name, backend_name_map[i].short_name) == 0 ||
+ strcmp(name, backend_name_map[i].long_name) == 0) {
+ *backend = backend_name_map[i].backend;
+ return true;
+ }
+ }
+
+ return false;
+}
diff --git a/compositor/main.c b/compositor/main.c
index 6f0c4fbe..938a10e7 100644
--- a/compositor/main.c
+++ b/compositor/main.c
@@ -3481,30 +3481,32 @@ load_wayland_backend(struct weston_compositor *c,
static int
-load_backend(struct weston_compositor *compositor, const char *backend,
+load_backend(struct weston_compositor *compositor, const char *name,
int *argc, char **argv, struct weston_config *config)
{
- if (strcmp(backend, "headless") == 0 ||
- strstr(backend, "headless-backend.so"))
+ enum weston_compositor_backend backend;
+
+ if (!get_backend_from_string(name, &backend)) {
+ weston_log("Error: unknown backend \"%s\"\n", name);
+ return -1;
+ }
+
+ switch (backend) {
+ case WESTON_BACKEND_DRM:
+ return load_drm_backend(compositor, argc, argv, config);
+ case WESTON_BACKEND_HEADLESS:
return load_headless_backend(compositor, argc, argv, config);
- else if (strcmp(backend, "rdp") == 0 ||
- strstr(backend, "rdp-backend.so"))
+ case WESTON_BACKEND_RDP:
return load_rdp_backend(compositor, argc, argv, config);
- else if (strcmp(backend, "vnc") == 0 ||
- strstr(backend, "vnc-backend.so"))
+ case WESTON_BACKEND_VNC:
return load_vnc_backend(compositor, argc, argv, config);
- else if (strcmp(backend, "drm") == 0 ||
- strstr(backend, "drm-backend.so"))
- return load_drm_backend(compositor, argc, argv, config);
- else if (strcmp(backend, "x11") == 0 ||
- strstr(backend, "x11-backend.so"))
- return load_x11_backend(compositor, argc, argv, config);
- else if (strcmp(backend, "wayland") == 0 ||
- strstr(backend, "wayland-backend.so"))
+ case WESTON_BACKEND_WAYLAND:
return load_wayland_backend(compositor, argc, argv, config);
-
- weston_log("Error: unknown backend \"%s\"\n", backend);
- return -1;
+ case WESTON_BACKEND_X11:
+ return load_x11_backend(compositor, argc, argv, config);
+ default:
+ unreachable("unknown backend type in load_backend()");
+ }
}
static char *
diff --git a/compositor/meson.build b/compositor/meson.build
index 8960cea5..37f52290 100644
--- a/compositor/meson.build
+++ b/compositor/meson.build
@@ -2,6 +2,7 @@ srcs_weston = [
git_version_h,
'main.c',
'text-backend.c',
+ 'config-helpers.c',
'weston-screenshooter.c',
text_input_unstable_v1_server_protocol_h,
text_input_unstable_v1_protocol_c,
diff --git a/compositor/weston-private.h b/compositor/weston-private.h
index 01b37dcf..6d6bda4a 100644
--- a/compositor/weston-private.h
+++ b/compositor/weston-private.h
@@ -28,6 +28,10 @@
#include <libweston/libweston.h>
#include <libweston/config-parser.h>
+bool
+get_backend_from_string(const char *name,
+ enum weston_compositor_backend *backend);
+
int
wet_output_set_color_characteristics(struct weston_output *output,
struct weston_config *wc,