Re: [PATCH weston 2/2] compositor: add a masking mechanism to weston_layer

2014-07-18 Thread Jason Ekstrand
One comment below.  Otherwise, it looks good (though I haven't tested it
yet.)  Also, I'd like to decide what I think about the first patch before
merging.  I'll get back to you Monday or Tuesday.
--Jason


On Wed, Jul 9, 2014 at 12:12 PM, Giulio Camuffo 
wrote:

> this adds a mechanism to mask the views belonging to a layer
> to an arbitrary rect, in the global space. The parts that don't fit
> in that rect will be clipped away.
> Supported by the gl and pixman renderer only for now.
> ---
>  src/compositor.c  | 61
> ---
>  src/compositor.h  | 10 +
>  src/gl-renderer.c |  2 +-
>  src/pixman-renderer.c |  2 +-
>  4 files changed, 70 insertions(+), 5 deletions(-)
>
> diff --git a/src/compositor.c b/src/compositor.c
> index 1d8d00e..2b52b4f 100644
> --- a/src/compositor.c
> +++ b/src/compositor.c
> @@ -349,8 +349,11 @@ weston_view_create(struct weston_surface *surface)
>
> view->plane = NULL;
> view->layer_link.layer = NULL;
> +   view->parent_view = NULL;
>
> pixman_region32_init(&view->clip);
> +   pixman_region32_init(&view->transform.masked_boundingbox);
> +   pixman_region32_init(&view->transform.masked_opaque);
>
> view->alpha = 1.0;
> pixman_region32_init(&view->transform.opaque);
> @@ -783,7 +786,7 @@ weston_view_damage_below(struct weston_view *view)
> pixman_region32_t damage;
>
> pixman_region32_init(&damage);
> -   pixman_region32_subtract(&damage, &view->transform.boundingbox,
> +   pixman_region32_subtract(&damage,
> &view->transform.masked_boundingbox,
>  &view->clip);
> if (view->plane)
> pixman_region32_union(&view->plane->damage,
> @@ -1009,10 +1012,20 @@ weston_view_update_transform_enable(struct
> weston_view *view)
> return 0;
>  }
>
> +static struct weston_layer *
> +get_view_layer(struct weston_view *view)
> +{
> +   if (view->parent_view)
> +   return get_view_layer(view->parent_view);
> +   return view->layer_link.layer;
> +}
> +
>  WL_EXPORT void
>  weston_view_update_transform(struct weston_view *view)
>  {
> struct weston_view *parent = view->geometry.parent;
> +   struct weston_layer *layer;
> +   pixman_region32_t mask;
>
> if (!view->transform.dirty)
> return;
> @@ -1040,6 +1053,16 @@ weston_view_update_transform(struct weston_view
> *view)
> weston_view_update_transform_disable(view);
> }
>
> +   layer = get_view_layer(view);
> +   if (layer) {
> +   pixman_region32_init_with_extents(&mask, &layer->mask);
> +
> pixman_region32_intersect(&view->transform.masked_boundingbox,
> +   &view->transform.boundingbox,
> &mask);
> +   pixman_region32_intersect(&view->transform.masked_opaque,
> +   &view->transform.opaque, &mask);
> +   pixman_region32_fini(&mask);
> +   }
>

Don't you want an else case here that just blindly copies the regions?
Maybe it doesn't matter since in that case we're not on a layer.  However,
there should at least be a comment to this effect.


> +
> weston_view_damage_below(view);
>
> weston_view_assign_output(view);
> @@ -1331,10 +1354,15 @@ weston_compositor_pick_view(struct
> weston_compositor *compositor,
> wl_fixed_t *vx, wl_fixed_t *vy)
>  {
> struct weston_view *view;
> +int ix = wl_fixed_to_int(x);
> +int iy = wl_fixed_to_int(y);
>
> wl_list_for_each(view, &compositor->view_list, link) {
> weston_view_from_global_fixed(view, x, y, vx, vy);
> -   if (pixman_region32_contains_point(&view->surface->input,
> +   if (pixman_region32_contains_point(
> +   &view->transform.masked_boundingbox,
> +  ix, iy, NULL) &&
> +   pixman_region32_contains_point(&view->surface->input,
>wl_fixed_to_int(*vx),
>wl_fixed_to_int(*vy),
>NULL))
> @@ -1426,6 +1454,8 @@ weston_view_destroy(struct weston_view *view)
>
> pixman_region32_fini(&view->clip);
> pixman_region32_fini(&view->transform.boundingbox);
> +   pixman_region32_fini(&view->transform.masked_boundingbox);
> +   pixman_region32_fini(&view->transform.masked_opaque);
>
> weston_view_set_transform_parent(view, NULL);
>
> @@ -1625,7 +1655,7 @@ view_accumulate_damage(struct weston_view *view,
>   &view->plane->damage, &damage);
> pixman_region32_fini(&damage);
> pixman_region32_copy(&view->clip, opaque);
> -   pixman_region32_union(opaque, opaque, &view->transform.opaque);
> +  

[PATCH weston 2/2] compositor: add a masking mechanism to weston_layer

2014-07-09 Thread Giulio Camuffo
this adds a mechanism to mask the views belonging to a layer
to an arbitrary rect, in the global space. The parts that don't fit
in that rect will be clipped away.
Supported by the gl and pixman renderer only for now.
---
 src/compositor.c  | 61 ---
 src/compositor.h  | 10 +
 src/gl-renderer.c |  2 +-
 src/pixman-renderer.c |  2 +-
 4 files changed, 70 insertions(+), 5 deletions(-)

diff --git a/src/compositor.c b/src/compositor.c
index 1d8d00e..2b52b4f 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -349,8 +349,11 @@ weston_view_create(struct weston_surface *surface)
 
view->plane = NULL;
view->layer_link.layer = NULL;
+   view->parent_view = NULL;
 
pixman_region32_init(&view->clip);
+   pixman_region32_init(&view->transform.masked_boundingbox);
+   pixman_region32_init(&view->transform.masked_opaque);
 
view->alpha = 1.0;
pixman_region32_init(&view->transform.opaque);
@@ -783,7 +786,7 @@ weston_view_damage_below(struct weston_view *view)
pixman_region32_t damage;
 
pixman_region32_init(&damage);
-   pixman_region32_subtract(&damage, &view->transform.boundingbox,
+   pixman_region32_subtract(&damage, &view->transform.masked_boundingbox,
 &view->clip);
if (view->plane)
pixman_region32_union(&view->plane->damage,
@@ -1009,10 +1012,20 @@ weston_view_update_transform_enable(struct weston_view 
*view)
return 0;
 }
 
+static struct weston_layer *
+get_view_layer(struct weston_view *view)
+{
+   if (view->parent_view)
+   return get_view_layer(view->parent_view);
+   return view->layer_link.layer;
+}
+
 WL_EXPORT void
 weston_view_update_transform(struct weston_view *view)
 {
struct weston_view *parent = view->geometry.parent;
+   struct weston_layer *layer;
+   pixman_region32_t mask;
 
if (!view->transform.dirty)
return;
@@ -1040,6 +1053,16 @@ weston_view_update_transform(struct weston_view *view)
weston_view_update_transform_disable(view);
}
 
+   layer = get_view_layer(view);
+   if (layer) {
+   pixman_region32_init_with_extents(&mask, &layer->mask);
+   pixman_region32_intersect(&view->transform.masked_boundingbox,
+   &view->transform.boundingbox, &mask);
+   pixman_region32_intersect(&view->transform.masked_opaque,
+   &view->transform.opaque, &mask);
+   pixman_region32_fini(&mask);
+   }
+
weston_view_damage_below(view);
 
weston_view_assign_output(view);
@@ -1331,10 +1354,15 @@ weston_compositor_pick_view(struct weston_compositor 
*compositor,
wl_fixed_t *vx, wl_fixed_t *vy)
 {
struct weston_view *view;
+int ix = wl_fixed_to_int(x);
+int iy = wl_fixed_to_int(y);
 
wl_list_for_each(view, &compositor->view_list, link) {
weston_view_from_global_fixed(view, x, y, vx, vy);
-   if (pixman_region32_contains_point(&view->surface->input,
+   if (pixman_region32_contains_point(
+   &view->transform.masked_boundingbox,
+  ix, iy, NULL) &&
+   pixman_region32_contains_point(&view->surface->input,
   wl_fixed_to_int(*vx),
   wl_fixed_to_int(*vy),
   NULL))
@@ -1426,6 +1454,8 @@ weston_view_destroy(struct weston_view *view)
 
pixman_region32_fini(&view->clip);
pixman_region32_fini(&view->transform.boundingbox);
+   pixman_region32_fini(&view->transform.masked_boundingbox);
+   pixman_region32_fini(&view->transform.masked_opaque);
 
weston_view_set_transform_parent(view, NULL);
 
@@ -1625,7 +1655,7 @@ view_accumulate_damage(struct weston_view *view,
  &view->plane->damage, &damage);
pixman_region32_fini(&damage);
pixman_region32_copy(&view->clip, opaque);
-   pixman_region32_union(opaque, opaque, &view->transform.opaque);
+   pixman_region32_union(opaque, opaque, &view->transform.masked_opaque);
 }
 
 static void
@@ -1740,6 +1770,7 @@ view_list_add_subsurface_view(struct weston_compositor 
*compositor,
weston_view_set_transform_parent(view, parent);
}
 
+   view->parent_view = parent;
weston_view_update_transform(view);
 
if (wl_list_empty(&sub->surface->subsurface_list)) {
@@ -1933,11 +1964,35 @@ weston_layer_init(struct weston_layer *layer, struct 
wl_list *below)
 {
wl_list_init(&layer->view_list.link);
layer->view_list.layer = layer;
+   weston_layer_set_mask_infinite(layer);
if (below != 

[PATCH weston 2/2] compositor: add a masking mechanism to weston_layer

2013-12-10 Thread Giulio Camuffo
this adds a mechanism to mask the views belonging to a layer
to an arbitrary rect, in the global space. The parts that don't fit
in that rect will be clipped away.
Implemented in the gl and pixman renderers only for now.
---

v2: do the masking in the renderers

 src/compositor.c  | 26 +-
 src/compositor.h  |  7 +++
 src/gl-renderer.c |  4 
 src/pixman-renderer.c |  4 
 4 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/src/compositor.c b/src/compositor.c
index 705326a..305f995 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -1194,10 +1194,16 @@ weston_compositor_pick_view(struct weston_compositor 
*compositor,
wl_fixed_t *vx, wl_fixed_t *vy)
 {
struct weston_view *view;
+int ix = wl_fixed_to_int(x);
+int iy = wl_fixed_to_int(y);
 
wl_list_for_each(view, &compositor->view_list, link) {
weston_view_from_global_fixed(view, x, y, vx, vy);
-   if (pixman_region32_contains_point(&view->surface->input,
+   if (ix >= view->layer_link.layer->mask.x1 &&
+   iy >= view->layer_link.layer->mask.y1 &&
+   ix <= view->layer_link.layer->mask.x2 &&
+   iy <= view->layer_link.layer->mask.y2 &&
+   pixman_region32_contains_point(&view->surface->input,
   wl_fixed_to_int(*vx),
   wl_fixed_to_int(*vy),
   NULL))
@@ -1793,11 +1799,29 @@ weston_layer_init(struct weston_layer *layer, struct 
wl_list *below)
 {
wl_list_init(&layer->view_list.link);
layer->view_list.layer = layer;
+   weston_layer_set_mask_infinite(layer);
if (below != NULL)
wl_list_insert(below, &layer->link);
 }
 
 WL_EXPORT void
+weston_layer_set_mask(struct weston_layer *layer,
+ int x, int y, int width, int height)
+{
+   layer->mask.x1 = x;
+   layer->mask.x2 = x + width;
+   layer->mask.y1 = y;
+   layer->mask.y2 = y + height;
+}
+
+WL_EXPORT void
+weston_layer_set_mask_infinite(struct weston_layer *layer)
+{
+   weston_layer_set_mask(layer, INT32_MIN, INT32_MIN,
+UINT32_MAX, UINT32_MAX);
+}
+
+WL_EXPORT void
 weston_output_schedule_repaint(struct weston_output *output)
 {
struct weston_compositor *compositor = output->compositor;
diff --git a/src/compositor.h b/src/compositor.h
index 94376f3..d618830 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -524,6 +524,7 @@ struct weston_layer_entry {
 struct weston_layer {
struct weston_layer_entry view_list;
struct wl_list link;
+   pixman_box32_t mask;
 };
 
 struct weston_plane {
@@ -986,6 +987,12 @@ void
 weston_layer_init(struct weston_layer *layer, struct wl_list *below);
 
 void
+weston_layer_set_mask(struct weston_layer *layer, int x, int y, int width, int 
height);
+
+void
+weston_layer_set_mask_infinite(struct weston_layer *layer);
+
+void
 weston_plane_init(struct weston_plane *plane,
struct weston_compositor *ec,
int32_t x, int32_t y);
diff --git a/src/gl-renderer.c b/src/gl-renderer.c
index 0e5afbe..899c280 100644
--- a/src/gl-renderer.c
+++ b/src/gl-renderer.c
@@ -521,6 +521,10 @@ draw_view(struct weston_view *ev, struct weston_output 
*output,
pixman_region32_intersect(&repaint,
  &ev->transform.boundingbox, damage);
pixman_region32_subtract(&repaint, &repaint, &ev->clip);
+   pixman_region32_t mask;
+   pixman_region32_init_with_extents(&mask, &ev->layer_link.layer->mask);
+   pixman_region32_intersect(&repaint, &repaint, &mask);
+   pixman_region32_fini(&mask);
 
if (!pixman_region32_not_empty(&repaint))
goto out;
diff --git a/src/pixman-renderer.c b/src/pixman-renderer.c
index e854e2a..65159c7 100644
--- a/src/pixman-renderer.c
+++ b/src/pixman-renderer.c
@@ -355,6 +355,10 @@ draw_view(struct weston_view *ev, struct weston_output 
*output,
pixman_region32_intersect(&repaint,
  &ev->transform.boundingbox, damage);
pixman_region32_subtract(&repaint, &repaint, &ev->clip);
+   pixman_region32_t mask;
+   pixman_region32_init_with_extents(&mask, &ev->layer_link.layer->mask);
+   pixman_region32_intersect(&repaint, &repaint, &mask);
+   pixman_region32_fini(&mask);
 
if (!pixman_region32_not_empty(&repaint))
goto out;
-- 
1.8.5.1

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