[PATCH] compositor-drm: Make unused parts of the cursor image transparent

Ander Conselvan de Oliveira ander.conselvan.de.oliveira at intel.com
Tue Aug 16 04:25:15 PDT 2011


The bo for the cursor image is always created with size 64x64 even if
the actual cursor image is smaller than that. If this memory is not
initialized, random data can create artifacts near the cursor.

Signed-off-by: Ander Conselvan de Oliveira <ander.conselvan.de.oliveira at intel.com>
---
 compositor/compositor-drm.c |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/compositor/compositor-drm.c b/compositor/compositor-drm.c
index b6560bd..bdfb232 100644
--- a/compositor/compositor-drm.c
+++ b/compositor/compositor-drm.c
@@ -679,6 +679,8 @@ drm_compositor_create_cursor_image(struct wlsc_compositor *ec,
 	struct drm_compositor *c = (struct drm_compositor *) ec;
 	struct gbm_bo *bo;
 	EGLImageKHR image;
+	uint32_t *pixels;
+	GLuint tex;
 
 	if (width > 64 || height > 64)
 		return EGL_NO_IMAGE_KHR;
@@ -692,6 +694,26 @@ drm_compositor_create_cursor_image(struct wlsc_compositor *ec,
 				 EGL_NATIVE_PIXMAP_KHR, bo, NULL);
 	gbm_bo_destroy(bo);
 
+	/* If the requested size is smaller than the allocated one, make the
+	 * whole image transparent. */
+	if (width != 64 || height != 64) {
+		pixels = calloc(64 * 64, sizeof *pixels);
+
+		glGenTextures(1, &tex);
+		glBindTexture(GL_TEXTURE_2D, tex);
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+		c->base.image_target_texture_2d(GL_TEXTURE_2D, image);
+		glTexSubImage(GL_TEXTURE_2D, 0, 0, 0, 64, 64,
+				GL_BGRA_EXT, GL_UNSIGNED_BYTE, pixels);
+
+		glDeleteTextures(1, &tex);
+		free(pixels);
+	}
+
 	return image;
 }
 
-- 
1.7.4.1

---------------------------------------------------------------------
Intel Finland Oy
Registered Address: PL 281, 00181 Helsinki 
Business Identity Code: 0357606 - 4 
Domiciled in Helsinki 

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.



More information about the wayland-devel mailing list