screenshooter: Add agl-screenshooter protocol
[src/agl-compositor.git] / src / main.c
index 4935a2f..164b45b 100644 (file)
@@ -101,6 +101,12 @@ ivi_output_configure_app_id(struct ivi_output *ivi_output)
                                                 "agl-shell-app-id",
                                                 &ivi_output->app_id,
                                                 NULL);
+
+               if (ivi_output->app_id == NULL)
+                       return;
+
+               weston_log("Will place app_id %s on output %s\n",
+                               ivi_output->app_id, ivi_output->name);
        }
 }
 
@@ -564,6 +570,9 @@ drm_backend_remoted_output_configure(struct weston_output *output,
        char *host = NULL;
        char *pipeline = NULL;
        int port, ret;
+       int32_t scale = 1;
+       uint32_t transform = WL_OUTPUT_TRANSFORM_NORMAL;
+       char *trans;
 
        ret = api->set_mode(output, modeline);
        if (ret < 0) {
@@ -573,9 +582,15 @@ drm_backend_remoted_output_configure(struct weston_output *output,
                return -1;
        }
 
-       /* FIXME: retrieve the scale and the transform from config file */
-       weston_output_set_scale(output, 1);
-       weston_output_set_transform(output, WL_OUTPUT_TRANSFORM_NORMAL);
+       weston_config_section_get_int(section, "scale", &scale, 1);
+       weston_output_set_scale(output, scale);
+
+       weston_config_section_get_string(section, "transform", &trans, "normal");
+       if (parse_transform(trans, &transform) < 0) {
+               weston_log("Invalid transform \"%s\" for output %s\n",
+                          trans, output->name);
+       }
+       weston_output_set_transform(output, transform);
 
        weston_config_section_get_string(section, "gbm-format",
                                         &gbm_format, NULL);
@@ -610,31 +625,31 @@ drm_backend_remoted_output_configure(struct weston_output *output,
 }
 
 
-static void
-remote_output_init(struct weston_compositor *compositor,
+static int
+remote_output_init(struct ivi_output *ivi_output,
+                  struct weston_compositor *compositor,
                   struct weston_config_section *section,
                   const struct weston_remoting_api *api)
 {
-       struct weston_output *output = NULL;
        char *output_name, *modeline = NULL;
-       int ret;
+       int ret = -1;
 
        weston_config_section_get_string(section, "name", &output_name, NULL);
        if (!output_name)
-               return;
+               return ret;
 
        weston_config_section_get_string(section, "mode", &modeline, "off");
        if (strcmp(modeline, "off") == 0)
                goto err;
 
-       output = api->create_output(compositor, output_name);
-       if (!output) {
+       ivi_output->output = api->create_output(compositor, output_name);
+       if (!ivi_output->output) {
                weston_log("Cannot create remoted output \"%s\".\n",
                                output_name);
                goto err;
        }
 
-       ret = drm_backend_remoted_output_configure(output, section,
+       ret = drm_backend_remoted_output_configure(ivi_output->output, section,
                                                   modeline, api);
        if (ret < 0) {
                weston_log("Cannot configure remoted output \"%s\".\n",
@@ -642,7 +657,7 @@ remote_output_init(struct weston_compositor *compositor,
                goto err;
        }
 
-       if (weston_output_enable(output) < 0) {
+       if (weston_output_enable(ivi_output->output) < 0) {
                weston_log("Enabling remoted output \"%s\" failed.\n",
                                output_name);
                goto err;
@@ -650,24 +665,75 @@ remote_output_init(struct weston_compositor *compositor,
 
        free(modeline);
        free(output_name);
-       weston_log("remoted output '%s' enabled\n", output->name);
-       return;
+       weston_log("remoted output '%s' enabled\n", ivi_output->output->name);
+
+       return 0;
 
 err:
        free(modeline);
        free(output_name);
-       if (output)
-               weston_output_destroy(output);
+       if (ivi_output->output)
+               weston_output_destroy(ivi_output->output);
 
+       return ret;
+}
+
+static void
+ivi_enable_remote_outputs(struct ivi_compositor *ivi)
+{
+       struct weston_config_section *remote_section = NULL;
+       const char *section_name;
+       struct weston_config *config = ivi->config;
+
+       while (weston_config_next_section(config, &remote_section, &section_name)) {
+               if (strcmp(section_name, "remote-output"))
+                       continue;
+
+               struct ivi_output *ivi_output = NULL;
+               bool output_found = false;
+               char *_name = NULL;
+
+               weston_config_section_get_string(remote_section,
+                                                "name", &_name, NULL);
+               wl_list_for_each(ivi_output, &ivi->outputs, link) {
+                       if (!strcmp(ivi_output->name, _name)) {
+                               output_found = true;
+                               break;
+                       }
+               }
+
+               if (output_found) {
+                       free(_name);
+                       continue;
+               }
+
+               ivi_output = zalloc(sizeof(*ivi_output));
+
+               ivi_output->ivi = ivi;
+               ivi_output->name = _name;
+               ivi_output->config = remote_section;
+
+               if (remote_output_init(ivi_output, ivi->compositor,
+                                      remote_section, ivi->remoting_api)) {
+                       free(ivi_output->name);
+                       free(ivi_output);
+                       continue;
+               }
+
+               ivi_output->output_destroy.notify = handle_output_destroy;
+               weston_output_add_destroy_listener(ivi_output->output,
+                                                  &ivi_output->output_destroy);
+
+               wl_list_insert(&ivi->outputs, &ivi_output->link);
+               ivi_output_configure_app_id(ivi_output);
+       }
 }
 
 static int
-load_remoting(struct ivi_compositor *ivi, struct weston_config *config)
+load_remoting_plugin(struct ivi_compositor *ivi, struct weston_config *config)
 {
        struct weston_compositor *compositor = ivi->compositor;
        int (*module_init)(struct weston_compositor *wc);
-       struct weston_config_section *remote_section = NULL;
-       const char *section_name;
 
        module_init = weston_load_module("remoting-plugin.so",
                                         "weston_module_init");
@@ -680,18 +746,11 @@ load_remoting(struct ivi_compositor *ivi, struct weston_config *config)
        ivi->remoting_api = weston_remoting_get_api(compositor);
        if (!ivi->remoting_api)
                return -1;
-
-       while (weston_config_next_section(config, &remote_section, &section_name)) {
-               if (strcmp(section_name, "remote-output"))
-                       continue;
-               remote_output_init(compositor, remote_section, ivi->remoting_api);
-       }
-
        return 0;
 }
 #else
 static int
-load_remoting(struct weston_compositor *compositor, struct weston_config *config)
+load_remoting_plugin(struct weston_compositor *compositor, struct weston_config *config)
 {
        return -1;
 }
@@ -744,7 +803,7 @@ load_drm_backend(struct ivi_compositor *ivi, int *argc, char *argv[])
                goto error;
        }
 
-       load_remoting(ivi, ivi->config);
+       load_remoting_plugin(ivi, ivi->config);
 
 error:
        free(config.gbm_format);
@@ -1420,6 +1479,9 @@ int main(int argc, char *argv[])
 
        weston_compositor_flush_heads_changed(ivi.compositor);
 
+       if (ivi.remoting_api)
+               ivi_enable_remote_outputs(&ivi);
+
        ivi_shell_init_black_fs(&ivi);
 
        if (create_listening_socket(display, socket_name) < 0)
@@ -1431,6 +1493,7 @@ int main(int argc, char *argv[])
 
        ivi_shell_create_global(&ivi);
        ivi_launch_shell_client(&ivi);
+       ivi_screenshooter_create(&ivi);
        ivi_agl_systemd_notify(&ivi);
 
        wl_display_run(display);