Re: [weston, v12, 09/40] compositor-drm: Move repaint state application to flush

2017-09-28 Thread Sergi Granell
On Tue, 2017-09-26 at 18:15 +0100, Daniel Stone wrote:
> Split repaint into two stages, as implied by the grouped-repaint
> interface: drm_output_repaint generates the repaint state only, and
> drm_repaint_flush applies it.
> 
> This also moves DPMS into output state. Previously, the usual way to
> DPMS off was that repaint would be called and apply its state, followed
> by set_dpms being called afterwards to push the DPMS state separately.
> As this happens before the repaint_flush hook, with no change to DPMS we
> would set DPMS off, then immediately re-enable the output by posting the
> repaint. Not ideal.
> 
> Moving DPMS application at the same time complicates this patch, but I
> couldn't find a way to split it; if we keep set_dpms before begin_flush
> then we break DPMS off, or if we try to move DPMS to output state before
> using the repaint flush, we get stuck as the repaint hook generates an
> asynchronous state update, followed immediately by set_dpms generating a
> synchronous state update.
> 
> Signed-off-by: Daniel Stone 
> ---
>  libweston/compositor-drm.c | 313 ++-
> --
>  1 file changed, 240 insertions(+), 73 deletions(-)
> 
> diff --git a/libweston/compositor-drm.c b/libweston/compositor-drm.c
> index 530b0fd5..6c1c6881 100644
> --- a/libweston/compositor-drm.c
> +++ b/libweston/compositor-drm.c

[snip]

> @@ -1790,13 +1844,101 @@ drm_output_repaint(struct weston_output
> *output_base,
>   }
>   }
>  
> + if (dpms_prop->prop_id && state->dpms != output->state_cur-
> >dpms) {
> + ret = drmModeConnectorSetProperty(backend->drm.fd,
> +   output->connector_id,
> +   dpms_prop->prop_id,
> +   state->dpms);
> + if (ret) {
> + weston_log("DRM: DPMS: failed property set for
> %s\n",
> +output->base.name);
> + }
> + }
> +
> + drm_output_assign_state(state,
> DRM_OUTPUT_STATE_UPDATE_ASYNCHRONOUS);
> +
>   return 0;
>  
>  err:
>   output->cursor_view = NULL;
> -
>   drm_output_state_free(state);
> + return -1;
> +}
> +
> +static int
> +drm_pending_state_apply(struct drm_pending_state *pending_state)
> +{
> + struct drm_backend *b = pending_state->backend;
> + struct drm_output_state *output_state, *tmp;
> + uint32_t *unused;
> +
> + if (b->state_invalid) {
> + /* If we need to reset all our state (e.g. because we've
> +  * just started, or just been VT-switched in),
> explicitly
> +  * disable all the CRTCs we aren't using. This also
> disables
> +  * all connectors on these CRTCs, so we don't need to do
> that
> +  * separately with the pre-atomic API. */
> + wl_array_for_each(unused, &b->unused_crtcs)
> + drmModeSetCrtc(b->drm.fd, *unused, 0, 0, 0,
> NULL, 0,
> +NULL);
> + }
> +
> + wl_list_for_each_safe(output_state, tmp, &pending_state-
> >output_list,
> +   link) {
> + struct drm_output *output = output_state->output;
> + int ret;
> +
> + ret = drm_output_apply_state(output_state);
> + if (ret != 0) {
> + weston_log("Couldn't apply state for output
> %s\n",
> +output->base.name);
> + }
> + }
> +
> + b->state_invalid = false;
> +
> + assert(wl_list_empty(&pending_state->output_list));
>  
> + drm_pending_state_free(pending_state);
> +
> + return 0;
> +}
> +
> +static int
> +drm_output_repaint(struct weston_output *output_base,
> +pixman_region32_t *damage,
> +void *repaint_data)
> +{
> + struct drm_pending_state *pending_state = repaint_data;
> + struct drm_output *output = to_drm_output(output_base);
> + struct drm_output_state *state;
> + struct drm_plane_state *scanout_state;
> +
> + if (output->disable_pending || output->destroy_pending)
> + goto err;

If this goes to 'err', 'drm_output_state_free' will be called
with an uninitialized 'state'.

> +
> + assert(!output->state_last);
> +
> + /* If planes have been disabled in the core, we might not have
> +  * hit assign_planes at all, so might not have valid output
> state
> +  * here. */
> + state = drm_pending_state_get_output(pending_state, output);
> + if (!state)
> + state = drm_output_state_duplicate(output->state_cur,
> +pending_state,
> +DRM_OUTPUT_STATE_CLEA
> R_PLANES);
> + state->dpms = WESTON_DPMS_ON;
> +
> + drm_output_render(state, damage);
> + scanout_state = drm_output_state_get_plane(state,
> +

[PATCH weston v2] compositor-wayland: destroy the appropriate output instead of exiting when receiving an xdg_toplevel::close event

2017-09-27 Thread Sergi Granell
v2: Fix use after free spotted by Daniel Stone

Signed-off-by: Sergi Granell 
---
 libweston/compositor-wayland.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libweston/compositor-wayland.c b/libweston/compositor-wayland.c
index a99d4a5c..507262e3 100644
--- a/libweston/compositor-wayland.c
+++ b/libweston/compositor-wayland.c
@@ -1098,8 +1098,12 @@ static void
 handle_xdg_toplevel_close(void *data, struct zxdg_toplevel_v6 *xdg_toplevel)
 {
struct wayland_output *output = data;
+   struct weston_compositor *compositor = output->base.compositor;
 
-   weston_compositor_exit(output->base.compositor);
+   wayland_output_destroy(&output->base);
+
+   if (wl_list_empty(&compositor->output_list))
+   weston_compositor_exit(compositor);
 }
 
 static const struct zxdg_toplevel_v6_listener xdg_toplevel_listener = {
-- 
2.14.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


Re: connection: add sanity check to avoid buffer overflow

2017-09-26 Thread Sergi Granell
On Thu, 2017-09-14 at 09:21 +0900, Boram Park wrote:
> Before putting data into a buffer, we have to make sure that the data
> size is
> smaller than not only the buffer's full size but also the buffer's empty
> size.
> 
> https://bugs.freedesktop.org/show_bug.cgi?id=102690
> 
> Signed-off-by: Boram Park 
> Acked-by: Pekka Paalanen 
> ---
>  src/connection.c | 9 ++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/src/connection.c b/src/connection.c
> index 5c3d187..53b1621 100644
> --- a/src/connection.c
> +++ b/src/connection.c
> @@ -63,14 +63,17 @@ struct wl_connection {
>   int want_flush;
>  };
>  
> +static uint32_t wl_buffer_size(struct wl_buffer *b);
> +

I think it would be a better idea to move the wl_buffer_size definition
at the top to avoid this forward declaration.

>  static int
>  wl_buffer_put(struct wl_buffer *b, const void *data, size_t count)
>  {
> - uint32_t head, size;
> + uint32_t head, size, empty;
>  
> - if (count > sizeof(b->data)) {
> + empty = sizeof(b->data) - wl_buffer_size(b);
> + if (count > empty) {
>   wl_log("Data too big for buffer (%d > %d).\n",
> -count, sizeof(b->data));
> +    count, empty);
>   errno = E2BIG;
>   return -1;
>   }

Other than that,

Reviewed-by: Sergi Granell 
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH weston] compositor-wayland: destroy the appropriate output instead of exiting when receiving an xdg_toplevel::close event

2017-09-25 Thread Sergi Granell
Signed-off-by: Sergi Granell 
---
 libweston/compositor-wayland.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libweston/compositor-wayland.c b/libweston/compositor-wayland.c
index a99d4a5c..17b5dbfd 100644
--- a/libweston/compositor-wayland.c
+++ b/libweston/compositor-wayland.c
@@ -1099,7 +1099,10 @@ handle_xdg_toplevel_close(void *data, struct 
zxdg_toplevel_v6 *xdg_toplevel)
 {
struct wayland_output *output = data;
 
-   weston_compositor_exit(output->base.compositor);
+   wayland_output_destroy(&output->base);
+
+   if (wl_list_empty(&output->base.compositor->output_list))
+   weston_compositor_exit(output->base.compositor);
 }
 
 static const struct zxdg_toplevel_v6_listener xdg_toplevel_listener = {
-- 
2.14.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH] compositor-wayland: use input region instead of opaque region to zxdg_shell_v6::set_window_geometry

2017-09-25 Thread Sergi Granell
The opaque region is a few pixels off due to the rounded corners
of the frame decorations, and, therefore, the input region
matches the window's geometry more closely.

Signed-off-by: Sergi Granell 
---
 libweston/compositor-wayland.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/libweston/compositor-wayland.c b/libweston/compositor-wayland.c
index b144d6e5..a99d4a5c 100644
--- a/libweston/compositor-wayland.c
+++ b/libweston/compositor-wayland.c
@@ -779,12 +779,6 @@ wayland_output_resize_surface(struct wayland_output 
*output)
wl_surface_set_input_region(output->parent.surface, region);
wl_region_destroy(region);
 
-   frame_opaque_rect(output->frame, &ix, &iy, &iwidth, &iheight);
-   region = wl_compositor_create_region(b->parent.compositor);
-   wl_region_add(region, ix, iy, iwidth, iheight);
-   wl_surface_set_opaque_region(output->parent.surface, region);
-   wl_region_destroy(region);
-
if (output->parent.xdg_surface) {

zxdg_surface_v6_set_window_geometry(output->parent.xdg_surface,
ix,
@@ -793,6 +787,12 @@ wayland_output_resize_surface(struct wayland_output 
*output)
iheight);
}
 
+   frame_opaque_rect(output->frame, &ix, &iy, &iwidth, &iheight);
+   region = wl_compositor_create_region(b->parent.compositor);
+   wl_region_add(region, ix, iy, iwidth, iheight);
+   wl_surface_set_opaque_region(output->parent.surface, region);
+   wl_region_destroy(region);
+
width = frame_width(output->frame);
height = frame_height(output->frame);
} else {
-- 
2.14.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH weston] wcap: Prevent fd leak in wcap_decoder_create() fail path

2017-03-29 Thread Sergi Granell
Signed-off-by: Sergi Granell 
---
 wcap/wcap-decode.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/wcap/wcap-decode.c b/wcap/wcap-decode.c
index e3b8985f..7e8c8477 100644
--- a/wcap/wcap-decode.c
+++ b/wcap/wcap-decode.c
@@ -131,6 +131,7 @@ wcap_decoder_create(const char *filename)
PROT_READ, MAP_PRIVATE, decoder->fd, 0);
if (decoder->map == MAP_FAILED) {
fprintf(stderr, "mmap failed\n");
+   close(decoder->fd);
free(decoder);
return NULL;
}
@@ -146,6 +147,7 @@ wcap_decoder_create(const char *filename)
frame_size = header->width * header->height * 4;
decoder->frame = malloc(frame_size);
if (decoder->frame == NULL) {
+   close(decoder->fd);
free(decoder);
return NULL;
}
-- 
2.12.2

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH weston] compositor-drm: Add missing drmModeFreeResources in drm_device_is_kms

2017-03-28 Thread Sergi Granell
Signed-off-by: Sergi Granell 
---
 libweston/compositor-drm.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libweston/compositor-drm.c b/libweston/compositor-drm.c
index 4cb27b1d..3f7e97e6 100644
--- a/libweston/compositor-drm.c
+++ b/libweston/compositor-drm.c
@@ -3055,6 +3055,8 @@ drm_device_is_kms(struct drm_backend *b, struct 
udev_device *device)
b->drm.id = id;
b->drm.filename = strdup(filename);
 
+   drmModeFreeResources(res);
+
return true;
 
 out_res:
-- 
2.12.2

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH weston] compositor-wayland: Call weston_compositor_exit when receiving an xdg toplevel close event

2017-03-25 Thread Sergi Granell
Signed-off-by: Sergi Granell 
---
 libweston/compositor-wayland.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libweston/compositor-wayland.c b/libweston/compositor-wayland.c
index 1900ab08..a76dd08e 100644
--- a/libweston/compositor-wayland.c
+++ b/libweston/compositor-wayland.c
@@ -1097,6 +1097,9 @@ handle_xdg_toplevel_configure(void *data, struct 
zxdg_toplevel_v6 *toplevel,
 static void
 handle_xdg_toplevel_close(void *data, struct zxdg_toplevel_v6 *xdg_toplevel)
 {
+   struct wayland_output *output = data;
+
+   weston_compositor_exit(output->base.compositor);
 }
 
 static const struct zxdg_toplevel_v6_listener xdg_toplevel_listener = {
-- 
2.12.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH weston] compositor-wayland: Call set_window_geometry when using zxdg_shell_v6

2017-03-24 Thread Sergi Granell
This way Wayland compositors will be aware of Weston's
"visible bounds" (and ignore its shadows).

Signed-off-by: Sergi Granell 
---
 libweston/compositor-wayland.c | 16 
 1 file changed, 16 insertions(+)

diff --git a/libweston/compositor-wayland.c b/libweston/compositor-wayland.c
index 27beff62..1900ab08 100644
--- a/libweston/compositor-wayland.c
+++ b/libweston/compositor-wayland.c
@@ -785,6 +785,14 @@ wayland_output_resize_surface(struct wayland_output 
*output)
wl_surface_set_opaque_region(output->parent.surface, region);
wl_region_destroy(region);
 
+   if (output->parent.xdg_surface) {
+   
zxdg_surface_v6_set_window_geometry(output->parent.xdg_surface,
+   ix,
+   iy,
+   iwidth,
+   iheight);
+   }
+
width = frame_width(output->frame);
height = frame_height(output->frame);
} else {
@@ -797,6 +805,14 @@ wayland_output_resize_surface(struct wayland_output 
*output)
wl_region_add(region, 0, 0, width, height);
wl_surface_set_opaque_region(output->parent.surface, region);
wl_region_destroy(region);
+
+   if (output->parent.xdg_surface) {
+   
zxdg_surface_v6_set_window_geometry(output->parent.xdg_surface,
+   0,
+   0,
+   width,
+   height);
+   }
}
 
 #ifdef ENABLE_EGL
-- 
2.12.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH weston v2 1/2] compositor-wayland: Refactor struct wayland_output::name usage

2017-03-24 Thread Sergi Granell
struct wayland_output::name was used but never initialized.
Also zxdg_toplevel_v6_set_title was only called for windowed outputs,
and some compositors let you see the client's name even when it is
fullscreen (GNOME Shell's Activities menu for example).

So rename struct wayland_output::name to struct wayland_output::title and
precompute it on wayland_output_create_common(), so it can be later used
on xdg's set_title and frame_create.

v2: Move zxdg_toplevel_v6_set_title() before the wl_surface_commit()
as per Quentin Glidic's suggestion.

Signed-off-by: Sergi Granell 
---
 libweston/compositor-wayland.c | 67 +++---
 1 file changed, 30 insertions(+), 37 deletions(-)

diff --git a/libweston/compositor-wayland.c b/libweston/compositor-wayland.c
index ebdbd13b..2bbf4cf0 100644
--- a/libweston/compositor-wayland.c
+++ b/libweston/compositor-wayland.c
@@ -111,7 +111,7 @@ struct wayland_output {
 
int keyboard_count;
 
-   char *name;
+   char *title;
struct frame *frame;
 
struct {
@@ -708,6 +708,7 @@ wayland_output_destroy(struct weston_output *base)
if (output->frame_cb)
wl_callback_destroy(output->frame_cb);
 
+   free(output->title);
free(output);
 }
 
@@ -835,36 +836,17 @@ wayland_output_set_windowed(struct wayland_output *output)
 {
struct wayland_backend *b =
to_wayland_backend(output->base.compositor);
-   int tlen;
-   char *title;
 
if (output->frame)
return 0;
 
-   if (output->name) {
-   tlen = strlen(output->name) + strlen(WINDOW_TITLE " - ");
-   title = malloc(tlen + 1);
-   if (!title)
-   return -1;
-
-   snprintf(title, tlen + 1, WINDOW_TITLE " - %s", output->name);
-   } else {
-   title = strdup(WINDOW_TITLE);
-   }
-
-   if (output->parent.xdg_toplevel)
-   zxdg_toplevel_v6_set_title(output->parent.xdg_toplevel, title);
-
if (!b->theme) {
b->theme = theme_create();
-   if (!b->theme) {
-   free(title);
+   if (!b->theme)
return -1;
-   }
}
output->frame = frame_create(b->theme, 100, 100,
-FRAME_BUTTON_CLOSE, title);
-   free(title);
+FRAME_BUTTON_CLOSE, output->title);
if (!output->frame)
return -1;
 
@@ -1132,6 +1114,8 @@ wayland_backend_create_output_surface(struct 
wayland_output *output)
zxdg_toplevel_v6_add_listener(output->parent.xdg_toplevel,
  &xdg_toplevel_listener, output);
 
+   zxdg_toplevel_v6_set_title(output->parent.xdg_toplevel, 
output->title);
+
wl_surface_commit(output->parent.surface);
 
output->parent.wait_for_configure = true;
@@ -1239,9 +1223,13 @@ err_output:
 }
 
 static struct wayland_output *
-wayland_output_create_common(void)
+wayland_output_create_common(const char *name)
 {
struct wayland_output *output;
+   size_t len;
+
+   /* name can't be NULL. */
+   assert(name);
 
output = zalloc(sizeof *output);
if (output == NULL) {
@@ -1252,6 +1240,18 @@ wayland_output_create_common(void)
output->base.destroy = wayland_output_destroy;
output->base.disable = wayland_output_disable;
output->base.enable = wayland_output_enable;
+   output->base.name = strdup(name);
+
+   /* setup output name/title. */
+   len = strlen(WINDOW_TITLE " - ") + strlen(name) + 1;
+   output->title = zalloc(len);
+   if (!output->title) {
+   free(output->base.name);
+   free(output);
+   return NULL;
+   }
+
+   snprintf(output->title, len, WINDOW_TITLE " - %s", name);
 
return output;
 }
@@ -1259,12 +1259,7 @@ wayland_output_create_common(void)
 static int
 wayland_output_create(struct weston_compositor *compositor, const char *name)
 {
-   struct wayland_output *output = wayland_output_create_common();
-
-   /* name can't be NULL. */
-   assert(name);
-
-   output->base.name = strdup(name);
+   struct wayland_output *output = wayland_output_create_common(name);
 
weston_output_init(&output->base, compositor);
weston_compositor_add_pending_output(&output->base, compositor);
@@ -1324,11 +1319,9 @@ static int
 wayland_output_create_for_parent_output(struct wayland_backend *b,
struct wayland_parent_output *poutput)
 {
-   struct wayland_output *output = wayland_output_create_common();
+   struct way

[PATCH weston v2 2/2] compositor-wayland: Check the return value of wayland_output_create_common

2017-03-24 Thread Sergi Granell
If wayland_output_create_common returns NULL, it means that
the output creation failed.

Signed-off-by: Sergi Granell 
---
 libweston/compositor-wayland.c | 15 +--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/libweston/compositor-wayland.c b/libweston/compositor-wayland.c
index 2bbf4cf0..27beff62 100644
--- a/libweston/compositor-wayland.c
+++ b/libweston/compositor-wayland.c
@@ -1261,6 +1261,9 @@ wayland_output_create(struct weston_compositor 
*compositor, const char *name)
 {
struct wayland_output *output = wayland_output_create_common(name);
 
+   if (!output)
+   return -1;
+
weston_output_init(&output->base, compositor);
weston_compositor_add_pending_output(&output->base, compositor);
 
@@ -1319,9 +1322,13 @@ static int
 wayland_output_create_for_parent_output(struct wayland_backend *b,
struct wayland_parent_output *poutput)
 {
-   struct wayland_output *output = 
wayland_output_create_common("wlparent");
+   struct wayland_output *output;
struct weston_mode *mode;
 
+   output = wayland_output_create_common("wlparent");
+   if (!output)
+   return -1;
+
if (poutput->current_mode) {
mode = poutput->current_mode;
} else if (poutput->preferred_mode) {
@@ -1367,9 +1374,13 @@ out:
 static int
 wayland_output_create_fullscreen(struct wayland_backend *b)
 {
-   struct wayland_output *output = 
wayland_output_create_common("wayland-fullscreen");
+   struct wayland_output *output;
int width = 0, height = 0;
 
+   output = wayland_output_create_common("wayland-fullscreen");
+   if (!output)
+   return -1;
+
weston_output_init(&output->base, b->compositor);
 
output->base.scale = 1;
-- 
2.12.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH weston 2/2] compositor-wayland: Check the return value of wayland_output_create_common

2017-03-24 Thread Sergi Granell
If wayland_output_create_common returns NULL, it means that
the output creation failed.

Signed-off-by: Sergi Granell 
---
 libweston/compositor-wayland.c | 15 +--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/libweston/compositor-wayland.c b/libweston/compositor-wayland.c
index 41834692..c8eceee7 100644
--- a/libweston/compositor-wayland.c
+++ b/libweston/compositor-wayland.c
@@ -1261,6 +1261,9 @@ wayland_output_create(struct weston_compositor 
*compositor, const char *name)
 {
struct wayland_output *output = wayland_output_create_common(name);
 
+   if (!output)
+   return -1;
+
weston_output_init(&output->base, compositor);
weston_compositor_add_pending_output(&output->base, compositor);
 
@@ -1319,9 +1322,13 @@ static int
 wayland_output_create_for_parent_output(struct wayland_backend *b,
struct wayland_parent_output *poutput)
 {
-   struct wayland_output *output = 
wayland_output_create_common("wlparent");
+   struct wayland_output *output;
struct weston_mode *mode;
 
+   output = wayland_output_create_common("wlparent");
+   if (!output)
+   return -1;
+
if (poutput->current_mode) {
mode = poutput->current_mode;
} else if (poutput->preferred_mode) {
@@ -1367,9 +1374,13 @@ out:
 static int
 wayland_output_create_fullscreen(struct wayland_backend *b)
 {
-   struct wayland_output *output = 
wayland_output_create_common("wayland-fullscreen");
+   struct wayland_output *output;
int width = 0, height = 0;
 
+   output = wayland_output_create_common("wayland-fullscreen");
+   if (!output)
+   return -1;
+
weston_output_init(&output->base, b->compositor);
 
output->base.scale = 1;
-- 
2.12.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH weston 1/2] compositor-wayland: Refactor struct wayland_output::name usage

2017-03-24 Thread Sergi Granell
struct wayland_output::name was used but never initialized.
Also zxdg_toplevel_v6_set_title was only called for windowed outputs,
and some compositors let you see the client's name even when it is
fullscreen (GNOME Shell's Activities menu for example).

So rename struct wayland_output::name to struct wayland_output::title and
precompute it on wayland_output_create_common(), so it can be later used
on xdg's set_title and frame_create.

Signed-off-by: Sergi Granell 
---
 libweston/compositor-wayland.c | 67 +++---
 1 file changed, 30 insertions(+), 37 deletions(-)

diff --git a/libweston/compositor-wayland.c b/libweston/compositor-wayland.c
index ebdbd13b..41834692 100644
--- a/libweston/compositor-wayland.c
+++ b/libweston/compositor-wayland.c
@@ -111,7 +111,7 @@ struct wayland_output {
 
int keyboard_count;
 
-   char *name;
+   char *title;
struct frame *frame;
 
struct {
@@ -708,6 +708,7 @@ wayland_output_destroy(struct weston_output *base)
if (output->frame_cb)
wl_callback_destroy(output->frame_cb);
 
+   free(output->title);
free(output);
 }
 
@@ -835,36 +836,17 @@ wayland_output_set_windowed(struct wayland_output *output)
 {
struct wayland_backend *b =
to_wayland_backend(output->base.compositor);
-   int tlen;
-   char *title;
 
if (output->frame)
return 0;
 
-   if (output->name) {
-   tlen = strlen(output->name) + strlen(WINDOW_TITLE " - ");
-   title = malloc(tlen + 1);
-   if (!title)
-   return -1;
-
-   snprintf(title, tlen + 1, WINDOW_TITLE " - %s", output->name);
-   } else {
-   title = strdup(WINDOW_TITLE);
-   }
-
-   if (output->parent.xdg_toplevel)
-   zxdg_toplevel_v6_set_title(output->parent.xdg_toplevel, title);
-
if (!b->theme) {
b->theme = theme_create();
-   if (!b->theme) {
-   free(title);
+   if (!b->theme)
return -1;
-   }
}
output->frame = frame_create(b->theme, 100, 100,
-FRAME_BUTTON_CLOSE, title);
-   free(title);
+FRAME_BUTTON_CLOSE, output->title);
if (!output->frame)
return -1;
 
@@ -1139,6 +1121,8 @@ wayland_backend_create_output_surface(struct 
wayland_output *output)
while (output->parent.wait_for_configure)
wl_display_dispatch(b->parent.wl_display);
 
+   zxdg_toplevel_v6_set_title(output->parent.xdg_toplevel, 
output->title);
+
weston_log("wayland-backend: Using xdg_shell_v6\n");
}
else if (b->parent.shell) {
@@ -1239,9 +1223,13 @@ err_output:
 }
 
 static struct wayland_output *
-wayland_output_create_common(void)
+wayland_output_create_common(const char *name)
 {
struct wayland_output *output;
+   size_t len;
+
+   /* name can't be NULL. */
+   assert(name);
 
output = zalloc(sizeof *output);
if (output == NULL) {
@@ -1252,6 +1240,18 @@ wayland_output_create_common(void)
output->base.destroy = wayland_output_destroy;
output->base.disable = wayland_output_disable;
output->base.enable = wayland_output_enable;
+   output->base.name = strdup(name);
+
+   /* setup output name/title. */
+   len = strlen(WINDOW_TITLE " - ") + strlen(name) + 1;
+   output->title = zalloc(len);
+   if (!output->title) {
+   free(output->base.name);
+   free(output);
+   return NULL;
+   }
+
+   snprintf(output->title, len, WINDOW_TITLE " - %s", name);
 
return output;
 }
@@ -1259,12 +1259,7 @@ wayland_output_create_common(void)
 static int
 wayland_output_create(struct weston_compositor *compositor, const char *name)
 {
-   struct wayland_output *output = wayland_output_create_common();
-
-   /* name can't be NULL. */
-   assert(name);
-
-   output->base.name = strdup(name);
+   struct wayland_output *output = wayland_output_create_common(name);
 
weston_output_init(&output->base, compositor);
weston_compositor_add_pending_output(&output->base, compositor);
@@ -1324,11 +1319,9 @@ static int
 wayland_output_create_for_parent_output(struct wayland_backend *b,
struct wayland_parent_output *poutput)
 {
-   struct wayland_output *output = wayland_output_create_common();
+   struct wayland_output *output = 
wayland_output_create_common("wlparent");
struct weston_mode *mode;
 
-   output->base.name = strdup("w

[PATCH] Fix uninitialized msec_to_next in output_repaint_timer_arm

2017-03-18 Thread Sergi Granell
Signed-off-by: Sergi Granell 
---
 libweston/compositor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libweston/compositor.c b/libweston/compositor.c
index fb647daa..048b195c 100644
--- a/libweston/compositor.c
+++ b/libweston/compositor.c
@@ -2388,7 +2388,7 @@ output_repaint_timer_arm(struct weston_compositor 
*compositor)
struct weston_output *output;
bool any_should_repaint = false;
struct timespec now;
-   int64_t msec_to_next;
+   int64_t msec_to_next = INT64_MAX;
 
weston_compositor_read_presentation_clock(compositor, &now);
 
-- 
2.12.0

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH] wayland-server: Remove unused members from struct wl_client

2017-02-26 Thread Sergi Granell
Those struct members are no longer used so we can remove them.

Signed-off-by: Sergi Granell 
---
 src/wayland-server.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/src/wayland-server.c b/src/wayland-server.c
index 6a8b3e4..82a3b01 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -74,8 +74,6 @@ struct wl_client {
struct wl_event_source *source;
struct wl_display *display;
struct wl_resource *display_resource;
-   uint32_t id_count;
-   uint32_t mask;
struct wl_list link;
struct wl_map objects;
struct wl_priv_signal destroy_signal;
-- 
2.12.0

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


Re: Student project

2017-02-20 Thread Sergi Granell
Hi,

exactly, helping to get Daniel's atomic modesetting patches landed is
my first priority. Maybe it would be a good idea to write some kind of
Weston client demo that makes extensive use of subsurfarces in some
way, in order to make Weston use and change plane configurations in
atomic commits to help test those patches.

On my side, I'll be using a Raspberry Pi 3 as my test platform (my
laptop is too old to have atomic DRM drivers), which I'm currently
setting up (I expect to have it done in 1-2 more days).

About the automated testing, I don't know if the Raspi's display
controller supports image writeback, but if it does that would be an
interesting thing to look into (as it would not only be useful to test
Weston atomic modesetting, but also to test the DRM drivers).

Other than that, I haven't thought of any other ideas, since I think
getting the patches merged and the testing and bug fixing afterwards
will take most of my available time for this project.
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


Student project

2017-02-17 Thread Sergi Granell
Hi everyone!

My name is Sergi Granell and I am a last year student at the
Facultat d'Informàtica de Barcelona in the Universitat Politècnica de
Catalunya [1].
As this is my last semester there, I have to do my end of degree
project.
I have been interested in Wayland for a long time, and also following
this mailing list. In fact, I sent a few (but simple) patches last
year.
Since I have wanted to contribute to Wayland (or Weston) for a long
time, but being busy with the university kept me from doing it, I have
decided that now it would be a good time to do it: as my end of degree
project.

I have decided that I'd like to improve the atomic mode-setting and
hardware planes usage in Weston, since that could improve the user
experience and reduce the power consumption and memory bandwidth needed
compared to rendering using OpenGL ES for example.

The project starts right now and it lasts until June approximately, so
I will try to do my best! Also I am always wandering around the IRC
channel, so expect me to be somewhat active there too :)

Anyways, let me know if you have any questions, comments or ideas.

[1] http://www.fib.upc.edu
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH] server: Fix shm_create_pool size fail path fd leak

2016-02-18 Thread Sergi Granell
If the client passed a size <= 0 to shm_create_pool, it would
go to err_free, which wouldn't close the fd, and thus leave it opened.

We can also move the size check before the struct wl_shm_pool
malloc, so in case the client passes a wrong size, it won't
do an unnecessary malloc and then free.
---
 src/wayland-shm.c | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/wayland-shm.c b/src/wayland-shm.c
index a4343a4..81bf657 100644
--- a/src/wayland-shm.c
+++ b/src/wayland-shm.c
@@ -230,17 +230,17 @@ shm_create_pool(struct wl_client *client, struct 
wl_resource *resource,
 {
struct wl_shm_pool *pool;
 
-   pool = malloc(sizeof *pool);
-   if (pool == NULL) {
-   wl_client_post_no_memory(client);
-   goto err_close;
-   }
-
if (size <= 0) {
wl_resource_post_error(resource,
   WL_SHM_ERROR_INVALID_STRIDE,
   "invalid size (%d)", size);
-   goto err_free;
+   goto err_close;
+   }
+
+   pool = malloc(sizeof *pool);
+   if (pool == NULL) {
+   wl_client_post_no_memory(client);
+   goto err_close;
}
 
pool->refcount = 1;
@@ -251,7 +251,7 @@ shm_create_pool(struct wl_client *client, struct 
wl_resource *resource,
wl_resource_post_error(resource,
   WL_SHM_ERROR_INVALID_FD,
   "failed mmap fd %d", fd);
-   goto err_close;
+   goto err_free;
}
close(fd);
 
@@ -270,10 +270,10 @@ shm_create_pool(struct wl_client *client, struct 
wl_resource *resource,
 
return;
 
-err_close:
-   close(fd);
 err_free:
free(pool);
+err_close:
+   close(fd);
 }
 
 static const struct wl_shm_interface shm_interface = {
-- 
2.7.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH] cosmetic: add an space after if

2016-02-04 Thread Sergi Granell
---
 src/wayland-shm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/wayland-shm.c b/src/wayland-shm.c
index 8e7adc9..a4343a4 100644
--- a/src/wayland-shm.c
+++ b/src/wayland-shm.c
@@ -117,7 +117,7 @@ format_is_supported(struct wl_client *client, uint32_t 
format)
default:
formats = wl_display_get_additional_shm_formats(display);
wl_array_for_each(p, formats)
-   if(*p == format)
+   if (*p == format)
return true;
}
 
-- 
2.7.0

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH] cosmetic: use tabs instead of spaces

2016-02-04 Thread Sergi Granell
---
 src/wayland-util.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/wayland-util.c b/src/wayland-util.c
index 3f95877..748476a 100644
--- a/src/wayland-util.c
+++ b/src/wayland-util.c
@@ -123,7 +123,7 @@ wl_array_add(struct wl_array *array, size_t size)
if (array->alloc < alloc) {
if (array->alloc > 0)
data = realloc(array->data, alloc);
-   else
+   else
data = malloc(alloc);
 
if (data == NULL)
-- 
2.7.0

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH] server: Fix possible wl_display_add_socket_fd memleak

2016-02-01 Thread Sergi Granell
If wl_event_loop_add_fd failed, the fail path didn't free the
newly allocated struct wl_socket.
---
 src/wayland-server.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/wayland-server.c b/src/wayland-server.c
index 6654cd7..3ba8a5d 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -1268,17 +1268,18 @@ wl_display_add_socket_fd(struct wl_display *display, 
int sock_fd)
if (s == NULL)
return -1;
 
-   /* Reuse the existing fd */
-   s->fd = sock_fd;
-
-   s->source = wl_event_loop_add_fd(display->loop, s->fd,
+   s->source = wl_event_loop_add_fd(display->loop, sock_fd,
 WL_EVENT_READABLE,
 socket_data, display);
if (s->source == NULL) {
wl_log("failed to establish event source\n");
+   wl_socket_destroy(s);
return -1;
}
 
+   /* Reuse the existing fd */
+   s->fd = sock_fd;
+
wl_list_insert(display->socket_list.prev, &s->link);
 
return 0;
-- 
2.7.0

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/wayland-devel