[RFC weston 11/14] compositor-drm: Use actual drm_plane for cursor_plane

Derek Foreman derekf at osg.samsung.com
Thu May 28 14:49:50 PDT 2015


On 21/05/15 02:29 AM, Daniel Stone wrote:
> Track the cursor plane through a real drm_plane, including pointing it
> to the cursor plane we discover through universal planes, if applicable.
> 
> Signed-off-by: Daniel Stone <daniels at collabora.com>
> ---
>  src/compositor-drm.c | 90 ++++++++++++++++++++++++++++++++++++++++++----------
>  1 file changed, 74 insertions(+), 16 deletions(-)
> 
> diff --git a/src/compositor-drm.c b/src/compositor-drm.c
> index af70a28..d25100d 100644
> --- a/src/compositor-drm.c
> +++ b/src/compositor-drm.c
> @@ -252,7 +252,7 @@ struct drm_output {
>  
>  	struct gbm_surface *surface;
>  	struct gbm_bo *cursor_bo[2];
> -	struct drm_plane cursor_plane;
> +	struct drm_plane *cursor_plane;
>  	struct weston_plane fb_plane;
>  	struct weston_view *cursor_view;
>  	int current_cursor;
> @@ -1005,7 +1005,8 @@ drm_output_repaint(struct weston_output *output_base,
>  
>  	output->page_flip_pending = 1;
>  
> -	drm_output_set_cursor(output);
> +	if (output->cursor_plane)
> +		drm_output_set_cursor(output);
>  
>  	/*
>  	 * Now, update all the sprite surfaces
> @@ -1369,6 +1370,8 @@ drm_output_prepare_cursor_view(struct drm_output *output,
>  
>  	if (c->gbm == NULL)
>  		return NULL;
> +	if (output->cursor_plane == NULL)
> +		return NULL;
>  	if (output->base.transform != WL_OUTPUT_TRANSFORM_NORMAL)
>  		return NULL;
>  	if (viewport->buffer.scale != output->base.current_scale)
> @@ -1388,7 +1391,7 @@ drm_output_prepare_cursor_view(struct drm_output *output,
>  
>  	output->cursor_view = ev;
>  
> -	return &output->cursor_plane.base;
> +	return &output->cursor_plane->base;
>  }
>  
>  static void
> @@ -1430,6 +1433,8 @@ drm_output_set_cursor(struct drm_output *output)
>  	struct gbm_bo *bo;
>  	int x, y;
>  
> +	assert(output->cursor_plane);
> +
>  	output->cursor_view = NULL;
>  	if (ev == NULL) {
>  		drmModeSetCursor(c->drm.fd, output->crtc_id, 0, 0, 0);
> @@ -1439,9 +1444,9 @@ drm_output_set_cursor(struct drm_output *output)
>  	buffer = ev->surface->buffer_ref.buffer;
>  
>  	if (buffer &&
> -	    pixman_region32_not_empty(&output->cursor_plane.base.damage)) {
> -		pixman_region32_fini(&output->cursor_plane.base.damage);
> -		pixman_region32_init(&output->cursor_plane.base.damage);
> +	    pixman_region32_not_empty(&output->cursor_plane->base.damage)) {
> +		pixman_region32_fini(&output->cursor_plane->base.damage);
> +		pixman_region32_init(&output->cursor_plane->base.damage);
>  		output->current_cursor ^= 1;
>  		bo = output->cursor_bo[output->current_cursor];
>  
> @@ -1456,14 +1461,15 @@ drm_output_set_cursor(struct drm_output *output)
>  
>  	x = (ev->geometry.x - output->base.x) * output->base.current_scale;
>  	y = (ev->geometry.y - output->base.y) * output->base.current_scale;
> -	if (output->cursor_plane.base.x != x || output->cursor_plane.base.y != y) {
> +	if (output->cursor_plane->base.x != x ||
> +	    output->cursor_plane->base.y != y) {
>  		if (drmModeMoveCursor(c->drm.fd, output->crtc_id, x, y)) {
>  			weston_log("failed to move cursor: %m\n");
>  			c->cursors_are_broken = 1;
>  		}
>  
> -		output->cursor_plane.base.x = x;
> -		output->cursor_plane.base.y = y;
> +		output->cursor_plane->base.x = x;
> +		output->cursor_plane->base.y = y;
>  	}
>  }
>  
> @@ -1535,7 +1541,8 @@ drm_assign_planes(struct weston_output *output_base)
>  					      &ev->transform.boundingbox);
>  
>  		if (next_plane == primary ||
> -		    next_plane == &output->cursor_plane.base) {
> +		    (output->cursor_plane &&
> +		     next_plane == &output->cursor_plane->base)) {
>  			/* cursor plane involves a copy */
>  			ev->psf_flags = 0;
>  		} else {
> @@ -1592,7 +1599,6 @@ drm_output_destroy(struct weston_output *output_base)
>  	}
>  
>  	weston_plane_release(&output->fb_plane);
> -	weston_plane_release(&output->cursor_plane.base);

Perhaps a totally naive question, but this release has disappeared and
not been moved anywhere else?  Did we just leak something?

>  
>  	weston_output_destroy(&output->base);
>  
> @@ -2472,6 +2478,59 @@ connector_get_current_mode(drmModeConnector *connector, int drm_fd,
>  	return 0;
>  }
>  
> +static void
> +drm_output_init_cursor(struct drm_output *output)
> +{
> +	struct drm_compositor *ec =
> +		(struct drm_compositor *) output->base.compositor;
> +	struct drm_plane *plane;
> +
> +	if (ec->universal_planes) {
> +		wl_list_for_each(plane, &ec->sprite_list, link) {
> +			if (plane->type != WDRM_PLANE_TYPE_CURSOR)
> +				continue;
> +			if (plane->output)
> +				continue;
> +			if (!drm_plane_crtc_supported(output,
> +						      plane->possible_crtcs))
> +				continue;
> +
> +			plane->output = output;
> +			output->cursor_plane = plane;
> +			break;
> +		}
> +	}
> +	else {
> +		/* XXX: Gross open-coding ... ? */
> +		plane = zalloc(sizeof(*plane) + sizeof(uint32_t));
> +		if (!plane) {
> +			weston_log("%s: out of memory\n", __func__);
> +			return;
> +		}
> +
> +		weston_plane_init(&plane->base, &ec->base, 0, 0);
> +		wl_list_init(&plane->link);
> +
> +		plane->plane_id = 0;
> +		plane->possible_crtcs = 0;
> +		plane->output = output;
> +		plane->current = NULL;
> +		plane->next = NULL;
> +		plane->compositor = ec;
> +		plane->count_formats = 1;
> +		plane->formats[0] = GBM_FORMAT_ARGB8888;
> +		plane->type = WDRM_PLANE_TYPE_CURSOR;
> +
> +		output->cursor_plane = plane;
> +	}
> +
> +	if (!output->cursor_plane)
> +		return;
> +
> +	weston_compositor_stack_plane(&ec->base, &output->cursor_plane->base,
> +				      NULL);
> +}
> +
>  static int
>  create_output_for_connector(struct drm_compositor *ec,
>  			    drmModeRes *resources,
> @@ -2579,9 +2638,7 @@ create_output_for_connector(struct drm_compositor *ec,
>  			   connector->mmWidth, connector->mmHeight,
>  			   transform, scale);
>  
> -	weston_plane_init(&output->cursor_plane.base, &ec->base, 0, 0);
> -	weston_compositor_stack_plane(&ec->base, &output->cursor_plane.base,
> -				      NULL);
> +	drm_output_init_cursor(output);
>  
>  	if (ec->use_pixman) {
>  		if (drm_output_init_pixman(output, ec) < 0) {
> @@ -2702,7 +2759,6 @@ drm_plane_create(struct drm_compositor *ec, const drmModePlane *kplane)
>  	else
>  		plane->type = WDRM_PLANE_TYPE_OVERLAY;
>  
> -	weston_plane_init(&plane->base, &ec->base, 0, 0);
>  	wl_list_insert(&ec->sprite_list, &plane->link);
>  
>  	return plane;
> @@ -3049,7 +3105,9 @@ session_notify(struct wl_listener *listener, void *data)
>  
>  		wl_list_for_each(output, &ec->base.output_list, base.link) {
>  			output->base.repaint_needed = 0;
> -			drmModeSetCursor(ec->drm.fd, output->crtc_id, 0, 0, 0);
> +			if (output->cursor_plane)
> +				drmModeSetCursor(ec->drm.fd, output->crtc_id,
> +						 0, 0, 0);
>  		}
>  
>  		output = container_of(ec->base.output_list.next,
> 



More information about the wayland-devel mailing list