[PATCH v2 weston 06/16] compositor-drm: Refactor code into cursor_bo_update()

Daniel Stone daniels at collabora.com
Mon Jun 22 09:25:11 PDT 2015


From: Pekka Paalanen <pekka.paalanen at collabora.co.uk>

Cut a chunk of code out from drm_output_set_cursor() and form a new
function for writing a cursor bo data from a weston_view with a wl_shm
buffer.

Add more asserts to verify the assumptions in there.

v2: Use drm_compositor::cursor_{width,height} instead of hard-coded 64.

Signed-off-by: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
Signed-off-by: Daniel Stone <daniels at collabora.com>
---
 src/compositor-drm.c | 48 +++++++++++++++++++++++++++++++++---------------
 1 file changed, 33 insertions(+), 15 deletions(-)

diff --git a/src/compositor-drm.c b/src/compositor-drm.c
index 30d1223..1b26756 100644
--- a/src/compositor-drm.c
+++ b/src/compositor-drm.c
@@ -1023,17 +1023,45 @@ drm_output_prepare_cursor_view(struct drm_output *output,
 }
 
 static void
+cursor_bo_update(struct drm_compositor *ec, struct gbm_bo *bo,
+		 struct weston_view *ev)
+{
+	struct weston_buffer *buffer = ev->surface->buffer_ref.buffer;
+	uint32_t buf[ec->cursor_width * ec->cursor_height];
+	int32_t stride;
+	uint8_t *s;
+	int i;
+
+	assert(buffer && buffer->shm_buffer);
+	assert(buffer->shm_buffer == wl_shm_buffer_get(buffer->resource));
+	assert(ev->surface->width <= ec->cursor_width);
+	assert(ev->surface->height <= ec->cursor_height);
+
+	memset(buf, 0, sizeof buf);
+	stride = wl_shm_buffer_get_stride(buffer->shm_buffer);
+	s = wl_shm_buffer_get_data(buffer->shm_buffer);
+
+	wl_shm_buffer_begin_access(buffer->shm_buffer);
+	for (i = 0; i < ev->surface->height; i++)
+		memcpy(buf + i * ec->cursor_width,
+		       s + i * stride,
+		       ev->surface->width * 4);
+	wl_shm_buffer_end_access(buffer->shm_buffer);
+
+	if (gbm_bo_write(bo, buf, sizeof buf) < 0)
+		weston_log("failed update cursor: %m\n");
+}
+
+static void
 drm_output_set_cursor(struct drm_output *output)
 {
 	struct weston_view *ev = output->cursor_view;
 	struct weston_buffer *buffer;
 	struct drm_compositor *c =
 		(struct drm_compositor *) output->base.compositor;
-	EGLint handle, stride;
+	EGLint handle;
 	struct gbm_bo *bo;
-	uint32_t buf[c->cursor_width * c->cursor_height];
-	unsigned char *s;
-	int i, x, y;
+	int x, y;
 
 	output->cursor_view = NULL;
 	if (ev == NULL) {
@@ -1049,18 +1077,8 @@ drm_output_set_cursor(struct drm_output *output)
 		pixman_region32_init(&output->cursor_plane.damage);
 		output->current_cursor ^= 1;
 		bo = output->cursor_bo[output->current_cursor];
-		memset(buf, 0, sizeof buf);
-		stride = wl_shm_buffer_get_stride(buffer->shm_buffer);
-		s = wl_shm_buffer_get_data(buffer->shm_buffer);
-		wl_shm_buffer_begin_access(buffer->shm_buffer);
-		for (i = 0; i < ev->surface->height; i++)
-			memcpy(buf + i * c->cursor_width, s + i * stride,
-			       ev->surface->width * 4);
-		wl_shm_buffer_end_access(buffer->shm_buffer);
-
-		if (gbm_bo_write(bo, buf, sizeof buf) < 0)
-			weston_log("failed update cursor: %m\n");
 
+		cursor_bo_update(c, bo, ev);
 		handle = gbm_bo_get_handle(bo).s32;
 		if (drmModeSetCursor(c->drm.fd, output->crtc_id, handle,
 				c->cursor_width, c->cursor_height)) {
-- 
2.4.3



More information about the wayland-devel mailing list