[PATCH] composior: fix tiny cursor bug with drm compositor

Ander Conselvan de Oliveira ander.conselvan.de.oliveira at intel.com
Thu Oct 27 07:09:17 PDT 2011


The drm compositor always creates a 64x64 bo for the cursor image
regardless of the size of the actual cursor. When the fade animation
kicks in it disables the hardware cursor so that it is rendered as a
regular surface. This surface is rendered to a 32x32 region but using
a 64x64 texture so the cursor gets scaled down.

Fix this by making create_cursor_image return the actual size of the
image created to the compositor.

Signed-off-by: Ander Conselvan de Oliveira <ander.conselvan.de.oliveira at intel.com>
---
 compositor/compositor-drm.c |    9 ++++++---
 compositor/compositor.c     |   15 ++++++++++++---
 compositor/compositor.h     |    2 +-
 3 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/compositor/compositor-drm.c b/compositor/compositor-drm.c
index f3fc194..c0bf9ff 100644
--- a/compositor/compositor-drm.c
+++ b/compositor/compositor-drm.c
@@ -692,7 +692,7 @@ udev_drm_event(int fd, uint32_t mask, void *data)
 
 static EGLImageKHR
 drm_compositor_create_cursor_image(struct wlsc_compositor *ec,
-				   int32_t width, int32_t height)
+				   int32_t *width, int32_t *height)
 {
 	struct drm_compositor *c = (struct drm_compositor *) ec;
 	struct gbm_bo *bo;
@@ -700,7 +700,7 @@ drm_compositor_create_cursor_image(struct wlsc_compositor *ec,
 	uint32_t *pixels;
 	GLuint tex;
 
-	if (width > 64 || height > 64)
+	if (*width > 64 || *height > 64)
 		return EGL_NO_IMAGE_KHR;
 
 	bo = gbm_bo_create(c->gbm,
@@ -714,7 +714,7 @@ drm_compositor_create_cursor_image(struct wlsc_compositor *ec,
 
 	/* If the requested size is smaller than the allocated one, make the
 	 * whole image transparent. */
-	if (width != 64 || height != 64) {
+	if (*width != 64 || *height != 64) {
 		pixels = calloc(64 * 64, sizeof *pixels);
 
 		glGenTextures(1, &tex);
@@ -734,6 +734,9 @@ drm_compositor_create_cursor_image(struct wlsc_compositor *ec,
 
 		glDeleteTextures(1, &tex);
 		free(pixels);
+
+		*width = 64;
+		*height = 64;
 	}
 
 	return image;
diff --git a/compositor/compositor.c b/compositor/compositor.c
index e4b8d92..faece3a 100644
--- a/compositor/compositor.c
+++ b/compositor/compositor.c
@@ -466,7 +466,7 @@ wlsc_sprite_attach(struct wlsc_sprite *sprite, struct wl_surface *surface)
 	struct wlsc_surface *es = (struct wlsc_surface *) surface;
 	struct wlsc_compositor *ec = es->compositor;
 
-	es->pitch = es->width;
+	es->pitch = sprite->width;
 	es->image = sprite->image;
 	if (sprite->image != EGL_NO_IMAGE_KHR) {
 		glBindTexture(GL_TEXTURE_2D, es->texture);
@@ -494,6 +494,7 @@ create_sprite_from_png(struct wlsc_compositor *ec,
 	uint32_t *pixels;
 	struct wlsc_sprite *sprite;
 	int32_t width, height;
+	int32_t egl_img_width, egl_img_height;
 	uint32_t stride;
 
 	pixels = wlsc_load_image(filename, &width, &height, &stride);
@@ -511,8 +512,13 @@ create_sprite_from_png(struct wlsc_compositor *ec,
 	sprite->height = height;
 	sprite->image = EGL_NO_IMAGE_KHR;
 
-	if (usage & SPRITE_USE_CURSOR && ec->create_cursor_image != NULL)
-		sprite->image = ec->create_cursor_image(ec, width, height);
+	if (usage & SPRITE_USE_CURSOR && ec->create_cursor_image != NULL) {
+		egl_img_width = width;
+		egl_img_height = height;
+
+		sprite->image = ec->create_cursor_image(ec, &egl_img_width,
+							&egl_img_height);
+	}
 
 	glGenTextures(1, &sprite->texture);
 	glBindTexture(GL_TEXTURE_2D, sprite->texture);
@@ -525,6 +531,9 @@ create_sprite_from_png(struct wlsc_compositor *ec,
 		ec->image_target_texture_2d(GL_TEXTURE_2D, sprite->image);
 		glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height,
 				GL_BGRA_EXT, GL_UNSIGNED_BYTE, pixels);
+
+		sprite->width = egl_img_width;
+		sprite->height = egl_img_height;
 	} else {
 		glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT, width, height, 0,
 			     GL_BGRA_EXT, GL_UNSIGNED_BYTE, pixels);
diff --git a/compositor/compositor.h b/compositor/compositor.h
index 9a210b9..421b80e 100644
--- a/compositor/compositor.h
+++ b/compositor/compositor.h
@@ -230,7 +230,7 @@ struct wlsc_compositor {
 	void (*destroy)(struct wlsc_compositor *ec);
 	int (*authenticate)(struct wlsc_compositor *c, uint32_t id);
 	EGLImageKHR (*create_cursor_image)(struct wlsc_compositor *c,
-					   int32_t width, int32_t height);
+					   int32_t *width, int32_t *height);
 };
 
 #define MODIFIER_CTRL	(1 << 8)
-- 
1.7.4.1



More information about the wayland-devel mailing list