diff --git a/src/compositor.c b/src/compositor.c index 07874f62b..44126ddb2 100644 --- a/src/compositor.c +++ b/src/compositor.c @@ -4867,6 +4867,15 @@ weston_compositor_get_user_data(struct weston_compositor *compositor) return compositor->user_data; } +static const char * const backend_map[] = { + [WESTON_BACKEND_DRM] = "drm-backend.so", + [WESTON_BACKEND_FBDEV] = "fbdev-backend.so", + [WESTON_BACKEND_HEADLESS] = "headless-backend.so", + [WESTON_BACKEND_RDP] = "rdp-backend.so", + [WESTON_BACKEND_WAYLAND] = "wayland-backend.so", + [WESTON_BACKEND_X11] = "x11-backend.so", +}; + /** Load a backend into a weston_compositor * * A backend must be loaded to make a weston_compositor work. A backend @@ -4881,13 +4890,16 @@ weston_compositor_get_user_data(struct weston_compositor *compositor) */ WL_EXPORT int weston_compositor_load_backend(struct weston_compositor *compositor, - const char *backend, + enum weston_compositor_backend backend, struct weston_backend_config *config_base) { int (*backend_init)(struct weston_compositor *c, struct weston_backend_config *config_base); - backend_init = weston_load_module(backend, "backend_init"); + if (backend < 0 || backend >= ARRAY_LENGTH(backend_map)) + return -1; + + backend_init = weston_load_module(backend_map[backend], "backend_init"); if (!backend_init) return -1; diff --git a/src/compositor.h b/src/compositor.h index 25407a26b..cccd43483 100644 --- a/src/compositor.h +++ b/src/compositor.h @@ -1466,9 +1466,19 @@ void weston_compositor_destroy(struct weston_compositor *ec); struct weston_compositor * weston_compositor_create(struct wl_display *display, void *user_data); + +enum weston_compositor_backend { + WESTON_BACKEND_DRM, + WESTON_BACKEND_FBDEV, + WESTON_BACKEND_HEADLESS, + WESTON_BACKEND_RDP, + WESTON_BACKEND_WAYLAND, + WESTON_BACKEND_X11, +}; + int weston_compositor_load_backend(struct weston_compositor *compositor, - const char *backend, + enum weston_compositor_backend backend, struct weston_backend_config *config_base); void weston_compositor_exit(struct weston_compositor *ec); diff --git a/src/main.c b/src/main.c index 27276ffcf..9e970d602 100644 --- a/src/main.c +++ b/src/main.c @@ -1003,7 +1003,8 @@ load_drm_backend(struct weston_compositor *c, const char *backend, config.configure_output = drm_configure_output; config.configure_device = configure_input_device; - ret = weston_compositor_load_backend(c, backend, &config.base); + ret = weston_compositor_load_backend(c, WESTON_BACKEND_DRM, + &config.base); free(config.gbm_format); free(config.seat_id); @@ -1042,7 +1043,8 @@ load_headless_backend(struct weston_compositor *c, char const * backend, config.base.struct_size = sizeof(struct weston_headless_backend_config); /* load the actual wayland backend and configure it */ - ret = weston_compositor_load_backend(c, backend, &config.base); + ret = weston_compositor_load_backend(c, WESTON_BACKEND_HEADLESS, + &config.base); return ret; } @@ -1087,7 +1089,8 @@ load_rdp_backend(struct weston_compositor *c, char const * backend, parse_options(rdp_options, ARRAY_LENGTH(rdp_options), argc, argv); - ret = weston_compositor_load_backend(c, backend, &config.base); + ret = weston_compositor_load_backend(c, WESTON_BACKEND_RDP, + &config.base); free(config.bind_address); free(config.rdp_key); @@ -1127,7 +1130,8 @@ load_fbdev_backend(struct weston_compositor *c, char const * backend, config.configure_device = configure_input_device; /* load the actual wayland backend and configure it */ - ret = weston_compositor_load_backend(c, backend, &config.base); + ret = weston_compositor_load_backend(c, WESTON_BACKEND_FBDEV, + &config.base); free(config.device); @@ -1263,7 +1267,8 @@ load_x11_backend(struct weston_compositor *c, char const * backend, config.base.struct_size = sizeof(struct weston_x11_backend_config); /* load the actual backend and configure it */ - ret = weston_compositor_load_backend(c, backend, &config.base); + ret = weston_compositor_load_backend(c, WESTON_BACKEND_X11, + &config.base); out: for (j = 0; j < config.num_outputs; ++j) @@ -1483,7 +1488,8 @@ load_wayland_backend(struct weston_compositor *c, char const * backend, } /* load the actual wayland backend and configure it */ - ret = weston_compositor_load_backend(c, backend, &config.base); + ret = weston_compositor_load_backend(c, WESTON_BACKEND_WAYLAND, + &config.base); weston_wayland_backend_config_release(&config); return ret; }