[PATCH weston v6 12/12] x11: Initialize all outputs at start

Giulio Camuffo giuliocamuffo at gmail.com
Sun Apr 17 14:35:07 UTC 2016


2016-04-16 6:28 GMT+03:00 Bryce Harrington <bryce at osg.samsung.com>:
> We know ahead of time the maximum number of outputs we'll be
> configuring, so just alloc that memory from the get-go, instead of
> realloc'ing for each new output.
>
> Suggested-by: Pekka Paalanen <ppaalanen at gmail.com>
> Signed-off-by: Bryce Harrington <bryce at osg.samsung.com>
> ---
>  src/main.c | 37 ++++++++++++-------------------------
>  1 file changed, 12 insertions(+), 25 deletions(-)
>
> diff --git a/src/main.c b/src/main.c
> index 9a8094f..99e5067 100644
> --- a/src/main.c
> +++ b/src/main.c
> @@ -754,21 +754,6 @@ load_headless_backend(struct weston_compositor *c, char const * backend,
>  }
>
>  static int
> -weston_x11_backend_config_append_output_config(struct weston_x11_backend_config *config,
> -                                              struct weston_x11_backend_output_config *output_config) {
> -       struct weston_x11_backend_output_config *new_outputs;
> -
> -       new_outputs = realloc(config->outputs, (config->num_outputs+1) *
> -                             sizeof(struct weston_x11_backend_output_config));
> -       if (new_outputs == NULL)
> -               return -1;
> -
> -       config->outputs = new_outputs;
> -       config->outputs[(config->num_outputs)++] = *output_config;
> -       return 0;
> -}
> -
> -static int
>  load_x11_backend(struct weston_compositor *c, char const * backend,
>                  int *argc, char **argv, struct weston_config *wc)
>  {
> @@ -797,6 +782,15 @@ load_x11_backend(struct weston_compositor *c, char const * backend,
>
>         parse_options(options, ARRAY_LENGTH(options), argc, argv);
>
> +       if (option_count < 1) {
> +               weston_log("No outputs configured\n");
> +               return -1;
> +       }
> +       config.outputs = zalloc((option_count+1) *
> +                               sizeof(struct weston_x11_backend_output_config));

This doesn't really work. As i said on the reply to patch 6,
option_count will be 0 if the --output-count option is not used, but
in that case we should use a third variable set to 1, to have a
default output. That means that the actual outputs count will be
option_count, if option_count is > 0, otherwise it will be max(1,
<number of outputs in weston.ini>).

> +       if (config.outputs == NULL)
> +               return -1;
> +
>         section = NULL;
>         while (weston_config_next_section(wc, &section, &section_name)) {
>                 struct weston_x11_backend_output_config current_output = { 0, };
> @@ -842,11 +836,7 @@ load_x11_backend(struct weston_compositor *c, char const * backend,
>                                    t, current_output.name);
>                 free(t);
>
> -               if (weston_x11_backend_config_append_output_config(&config, &current_output) < 0) {
> -                       ret = -1;
> -                       goto out;
> -               }
> -
> +               config.outputs[(config.num_outputs)++] = current_output;
>                 output_count++;
>                 if (option_count && output_count >= option_count)
>                         break;
> @@ -861,13 +851,10 @@ load_x11_backend(struct weston_compositor *c, char const * backend,
>         for (i = output_count; i < option_count; i++) {
>                 if (asprintf(default_output.name, "screen%d", i) < 0) {
>                         ret = -1;
> -                       goto error;
> -               }
> -
> -               if (weston_x11_backend_config_append_output_config(&config, &default_output) < 0) {
> -                       ret = -1;
>                         goto out;
>                 }
> +
> +               config.outputs[(config.num_outputs)++] = default_output;
>         }
>
>         config.base.struct_version = WESTON_X11_BACKEND_CONFIG_VERSION;
> --
> 1.9.1
>
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/wayland-devel


More information about the wayland-devel mailing list