Re: [PATCH v17 11/14] compositor-drm: Return plane state from plane preparation

2018-07-10 Thread Pekka Paalanen
On Mon,  9 Jul 2018 14:23:17 +0100
Daniel Stone  wrote:

> Return a pointer to the plane state, rather than indirecting via a
> weston_plane.
> 
> Signed-off-by: Daniel Stone 
> Tested-by: Emre Ucan 
> ---
>  libweston/compositor-drm.c | 71 +-
>  1 file changed, 39 insertions(+), 32 deletions(-)
> 
> diff --git a/libweston/compositor-drm.c b/libweston/compositor-drm.c
> index c91428d96..ec0f9e7eb 100644
> --- a/libweston/compositor-drm.c
> +++ b/libweston/compositor-drm.c
> @@ -1934,7 +1934,7 @@ enum drm_output_propose_state_mode {
>   DRM_OUTPUT_PROPOSE_STATE_PLANES_ONLY, /**< only assign to planes */
>  };
>  
> -static struct weston_plane *
> +static struct drm_plane_state *
>  drm_output_prepare_scanout_view(struct drm_output_state *output_state,
>   struct weston_view *ev)
>  {
> @@ -1991,7 +1991,7 @@ drm_output_prepare_scanout_view(struct drm_output_state 
> *output_state,
>   state->dest_h != (unsigned) output->base.current_mode->height)
>   goto err;
>  
> - return &scanout_plane->base;
> + return state;
>  
>  err:
>   drm_plane_state_put_back(state);
> @@ -2157,7 +2157,6 @@ drm_output_apply_state_legacy(struct drm_output_state 
> *state)
>   struct drm_property_info *dpms_prop;
>   struct drm_plane_state *scanout_state;
>   struct drm_plane_state *ps;
> - struct drm_plane *p;

This...

>   struct drm_mode *mode;
>   struct drm_head *head;
>   uint32_t connectors[MAX_CLONED_CONNECTORS];
> @@ -2184,7 +2183,7 @@ drm_output_apply_state_legacy(struct drm_output_state 
> *state)
>  
>   if (state->dpms != WESTON_DPMS_ON) {
>   wl_list_for_each(ps, &state->plane_list, link) {
> - p = ps->plane;
> + struct drm_plane *p = ps->plane;

...this, and...

>   assert(ps->fb == NULL);
>   assert(ps->output == NULL);
>  
> @@ -2274,8 +2273,8 @@ drm_output_apply_state_legacy(struct drm_output_state 
> *state)
>   .request.type = DRM_VBLANK_RELATIVE | DRM_VBLANK_EVENT,
>   .request.sequence = 1,
>   };
> + struct drm_plane *p = ps->plane;
>  
> - p = ps->plane;

...this are unrelated but trivial changes.

Btw. this raises a style question. In the past I assumed it was ok to
declare variables at the beginning of a block, it still avoids mixed
code and declarations, but I recall being corrected that variables
should be declared in the beginning of the function only. I don't see
it written down at all, though.

Anyway, beginning of a block is my preferred way, so these bits are ok
by me.

>   if (p->type != WDRM_PLANE_TYPE_OVERLAY)
>   continue;
>  
> @@ -2987,7 +2986,7 @@ atomic_flip_handler(int fd, unsigned int frame, 
> unsigned int sec,
>  }
>  #endif
>  
> -static struct weston_plane *
> +static struct drm_plane_state *
>  drm_output_prepare_overlay_view(struct drm_output_state *output_state,
>   struct weston_view *ev)
>  {
> @@ -3059,7 +3058,7 @@ drm_output_prepare_overlay_view(struct drm_output_state 
> *output_state,
>   state->src_h != state->dest_h << 16)
>   goto err;
>  
> - return &p->base;
> + return state;
>  
>  err:
>   drm_plane_state_put_back(state);
> @@ -3103,7 +3102,7 @@ cursor_bo_update(struct drm_plane_state *plane_state, 
> struct weston_view *ev)
>   weston_log("failed update cursor: %m\n");
>  }
>  
> -static struct weston_plane *
> +static struct drm_plane_state *
>  drm_output_prepare_cursor_view(struct drm_output_state *output_state,
>  struct weston_view *ev)
>  {
> @@ -3190,7 +3189,7 @@ drm_output_prepare_cursor_view(struct drm_output_state 
> *output_state,
>   plane_state->dest_w = b->cursor_width;
>   plane_state->dest_h = b->cursor_height;
>  
> - return &plane->base;
> + return plane_state;
>  
>  err:
>   drm_plane_state_put_back(plane_state);
> @@ -3260,7 +3259,6 @@ drm_output_propose_state(struct weston_output 
> *output_base,
>   struct drm_output_state *state;
>   struct weston_view *ev;
>   pixman_region32_t surface_overlap, renderer_region, occluded_region;
> - struct weston_plane *primary = &output_base->compositor->primary_plane;
>   bool renderer_ok = (mode != DRM_OUTPUT_PROPOSE_STATE_PLANES_ONLY);
>   bool planes_ok = !b->sprites_are_broken;
>  
> @@ -3286,7 +3284,8 @@ drm_output_propose_state(struct weston_output 
> *output_base,
>   pixman_region32_init(&occluded_region);
>  
>   wl_list_for_each(ev, &output_base->compositor->view_list, link) {
> - struct weston_plane *next_plane = NULL;
> + struct drm_plane_state *ps = NULL;
> + bool force_renderer = false;
>   pixman_region32_t clipped_view;
>   bool occluded = false;
>  
> @@ -3298

[PATCH v17 11/14] compositor-drm: Return plane state from plane preparation

2018-07-09 Thread Daniel Stone
Return a pointer to the plane state, rather than indirecting via a
weston_plane.

Signed-off-by: Daniel Stone 
Tested-by: Emre Ucan 
---
 libweston/compositor-drm.c | 71 +-
 1 file changed, 39 insertions(+), 32 deletions(-)

diff --git a/libweston/compositor-drm.c b/libweston/compositor-drm.c
index c91428d96..ec0f9e7eb 100644
--- a/libweston/compositor-drm.c
+++ b/libweston/compositor-drm.c
@@ -1934,7 +1934,7 @@ enum drm_output_propose_state_mode {
DRM_OUTPUT_PROPOSE_STATE_PLANES_ONLY, /**< only assign to planes */
 };
 
-static struct weston_plane *
+static struct drm_plane_state *
 drm_output_prepare_scanout_view(struct drm_output_state *output_state,
struct weston_view *ev)
 {
@@ -1991,7 +1991,7 @@ drm_output_prepare_scanout_view(struct drm_output_state 
*output_state,
state->dest_h != (unsigned) output->base.current_mode->height)
goto err;
 
-   return &scanout_plane->base;
+   return state;
 
 err:
drm_plane_state_put_back(state);
@@ -2157,7 +2157,6 @@ drm_output_apply_state_legacy(struct drm_output_state 
*state)
struct drm_property_info *dpms_prop;
struct drm_plane_state *scanout_state;
struct drm_plane_state *ps;
-   struct drm_plane *p;
struct drm_mode *mode;
struct drm_head *head;
uint32_t connectors[MAX_CLONED_CONNECTORS];
@@ -2184,7 +2183,7 @@ drm_output_apply_state_legacy(struct drm_output_state 
*state)
 
if (state->dpms != WESTON_DPMS_ON) {
wl_list_for_each(ps, &state->plane_list, link) {
-   p = ps->plane;
+   struct drm_plane *p = ps->plane;
assert(ps->fb == NULL);
assert(ps->output == NULL);
 
@@ -2274,8 +2273,8 @@ drm_output_apply_state_legacy(struct drm_output_state 
*state)
.request.type = DRM_VBLANK_RELATIVE | DRM_VBLANK_EVENT,
.request.sequence = 1,
};
+   struct drm_plane *p = ps->plane;
 
-   p = ps->plane;
if (p->type != WDRM_PLANE_TYPE_OVERLAY)
continue;
 
@@ -2987,7 +2986,7 @@ atomic_flip_handler(int fd, unsigned int frame, unsigned 
int sec,
 }
 #endif
 
-static struct weston_plane *
+static struct drm_plane_state *
 drm_output_prepare_overlay_view(struct drm_output_state *output_state,
struct weston_view *ev)
 {
@@ -3059,7 +3058,7 @@ drm_output_prepare_overlay_view(struct drm_output_state 
*output_state,
state->src_h != state->dest_h << 16)
goto err;
 
-   return &p->base;
+   return state;
 
 err:
drm_plane_state_put_back(state);
@@ -3103,7 +3102,7 @@ cursor_bo_update(struct drm_plane_state *plane_state, 
struct weston_view *ev)
weston_log("failed update cursor: %m\n");
 }
 
-static struct weston_plane *
+static struct drm_plane_state *
 drm_output_prepare_cursor_view(struct drm_output_state *output_state,
   struct weston_view *ev)
 {
@@ -3190,7 +3189,7 @@ drm_output_prepare_cursor_view(struct drm_output_state 
*output_state,
plane_state->dest_w = b->cursor_width;
plane_state->dest_h = b->cursor_height;
 
-   return &plane->base;
+   return plane_state;
 
 err:
drm_plane_state_put_back(plane_state);
@@ -3260,7 +3259,6 @@ drm_output_propose_state(struct weston_output 
*output_base,
struct drm_output_state *state;
struct weston_view *ev;
pixman_region32_t surface_overlap, renderer_region, occluded_region;
-   struct weston_plane *primary = &output_base->compositor->primary_plane;
bool renderer_ok = (mode != DRM_OUTPUT_PROPOSE_STATE_PLANES_ONLY);
bool planes_ok = !b->sprites_are_broken;
 
@@ -3286,7 +3284,8 @@ drm_output_propose_state(struct weston_output 
*output_base,
pixman_region32_init(&occluded_region);
 
wl_list_for_each(ev, &output_base->compositor->view_list, link) {
-   struct weston_plane *next_plane = NULL;
+   struct drm_plane_state *ps = NULL;
+   bool force_renderer = false;
pixman_region32_t clipped_view;
bool occluded = false;
 
@@ -3298,7 +3297,7 @@ drm_output_propose_state(struct weston_output 
*output_base,
/* We only assign planes to views which are exclusively present
 * on our output. */
if (ev->output_mask != (1u << output->base.id))
-   next_plane = primary;
+   force_renderer = true;
 
/* Ignore views we know to be totally occluded. */
pixman_region32_init(&clipped_view);
@@ -3322,40 +3321,48 @@ drm_output_propose_state(struct weston_output 
*output_base,
pixman_region32_intersect(&surface_overlap, &renderer_region,