compositor,main: use weston_compositor_load_backend()

Move load_backend_new() from main.c to weston_compositor_load_backend()
in compositor.c.

This makes libweston load its own backends without leaking the details
to the user.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: Quentin Glidic <sardemff7+git@sardemff7.net>
Reviewed-by: Giulio Camuffo <giuliocamuffo@gmail.com>
diff --git a/src/compositor.c b/src/compositor.c
index 3904ef0..682357b 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -4866,3 +4866,32 @@
 {
 	return compositor->user_data;
 }
+
+/** Load a backend into a weston_compositor
+ *
+ * A backend must be loaded to make a weston_compositor work. A backend
+ * provides input and output capabilities, and determines the renderer to use.
+ *
+ * \param compositor A compositor that has not had a backend loaded yet.
+ * \param backend Name of the backend file.
+ * \param config_base A pointer to a backend-specific configuration
+ * structure's 'base' member.
+ *
+ * \return 0 on success, or -1 on error.
+ */
+WL_EXPORT int
+weston_compositor_load_backend(struct weston_compositor *compositor,
+			       const char *backend,
+			       struct weston_backend_config *config_base)
+{
+	int (*backend_init)(struct weston_compositor *c,
+			    int *argc, char *argv[],
+			    struct weston_config *config,
+			    struct weston_backend_config *config_base);
+
+	backend_init = weston_load_module(backend, "backend_init");
+	if (!backend_init)
+		return -1;
+
+	return backend_init(compositor, NULL, NULL, NULL, config_base);
+}
diff --git a/src/compositor.h b/src/compositor.h
index de8a3b6..bec0112 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -1466,6 +1466,10 @@
 weston_compositor_destroy(struct weston_compositor *ec);
 struct weston_compositor *
 weston_compositor_create(struct wl_display *display, void *user_data);
+int
+weston_compositor_load_backend(struct weston_compositor *compositor,
+			       const char *backend,
+			       struct weston_backend_config *config_base);
 void
 weston_compositor_exit(struct weston_compositor *ec);
 void *
diff --git a/src/main.c b/src/main.c
index 8bf824e..27276ff 100644
--- a/src/main.c
+++ b/src/main.c
@@ -909,36 +909,6 @@
 	wl_display_terminate(c->wl_display);
 }
 
-/** Main module call-point for backends.
- *
- * All backends should use this routine to access their init routine.
- * Backends may subclass weston_backend_config to add their own
- * configuration data, setting the major/minor version in config_base
- * accordingly.
- *
- * The config_base object should be treated as temporary, and any data
- * copied out of it by backend_init before returning.  The load_backend_new
- * callers may then free the config_base object.
- *
- * NOTE: This is a temporary function intended to eventually be replaced
- * by weston_compositor_load_backend().
- */
-static int
-load_backend_new(struct weston_compositor *compositor, const char *backend,
-		 struct weston_backend_config *config_base)
-{
-	int (*backend_init)(struct weston_compositor *c,
-			    int *argc, char *argv[],
-			    struct weston_config *config,
-			    struct weston_backend_config *config_base);
-
-	backend_init = weston_load_module(backend, "backend_init");
-	if (!backend_init)
-		return -1;
-
-	return backend_init(compositor, NULL, NULL, NULL, config_base);
-}
-
 static enum weston_drm_backend_output_mode
 drm_configure_output(struct weston_compositor *c,
 		     bool use_current_mode,
@@ -1033,7 +1003,7 @@
 	config.configure_output = drm_configure_output;
 	config.configure_device = configure_input_device;
 
-	ret = load_backend_new(c, backend, &config.base);
+	ret = weston_compositor_load_backend(c, backend, &config.base);
 
 	free(config.gbm_format);
 	free(config.seat_id);
@@ -1072,7 +1042,7 @@
 	config.base.struct_size = sizeof(struct weston_headless_backend_config);
 
 	/* load the actual wayland backend and configure it */
-	ret = load_backend_new(c, backend, &config.base);
+	ret = weston_compositor_load_backend(c, backend, &config.base);
 
 	return ret;
 }
@@ -1117,7 +1087,7 @@
 
 	parse_options(rdp_options, ARRAY_LENGTH(rdp_options), argc, argv);
 
-	ret = load_backend_new(c, backend, &config.base);
+	ret = weston_compositor_load_backend(c, backend, &config.base);
 
 	free(config.bind_address);
 	free(config.rdp_key);
@@ -1157,7 +1127,7 @@
 	config.configure_device = configure_input_device;
 
 	/* load the actual wayland backend and configure it */
-	ret = load_backend_new(c, backend, &config.base);
+	ret = weston_compositor_load_backend(c, backend, &config.base);
 
 	free(config.device);
 
@@ -1293,7 +1263,7 @@
 	config.base.struct_size = sizeof(struct weston_x11_backend_config);
 
 	/* load the actual backend and configure it */
-	ret = load_backend_new(c, backend, &config.base);
+	ret = weston_compositor_load_backend(c, backend, &config.base);
 
 out:
 	for (j = 0; j < config.num_outputs; ++j)
@@ -1513,7 +1483,7 @@
 	}
 
 	/* load the actual wayland backend and configure it */
-	ret = load_backend_new(c, backend, &config.base);
+	ret = weston_compositor_load_backend(c, backend, &config.base);
 	weston_wayland_backend_config_release(&config);
 	return ret;
 }