Skip to contentSkip to conversation

fbdev: Clean up of fbcon/fbdev cursor interface

PATCH New Antonino A. Daplas 1 participant 1 message Oct 20, 2004

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 4/8 fbdev: Clean up of fbcon/fbdev cursor interface

The current cursor interface is confusing. Some fields are taken from the cursor structure in struct fb_info (enable, mask, rop fields) and the rest are taken from the passed cursor structure. These lead to a lot of confusion, making it hard for developers to write their own implementation.

Also, the cursor code has several 'short-circuits', occassionally leading to undefined cursor behavior.

These are the changes brought about by the patch:

- Removed struct fb_cursor and related fields from struct fb_info, and instead, placed them in a struct not visible to fbdev.

- The struct fb_cursor passed to fb_cursor() will _always_ contain valid data with various bitflags indicating which fields have changed

- The struct fb_pixmap sprite in struct fb_info is used only by drivers with hardware cursor implementation. Initializing and allocating memory for this structure is not needed. Remove initialization and memory allocation.

- The FBIO_CURSOR ioctl is broken (because fb_cursor() is broken). For now, remove fb_cursor code and make the FBIO_CURSOR ioctl always return -ENODEV.

- The flag FB_CUR_SETCUR is changed to FB_CUR_SETIMAGE, indicating that the cursor sprite has changed. The image change is now checked by fbcon so drivers will not unnecessarily load the sprite image everytime. This causes hardware cursors to flicker, especially in rivafb.

- Remove fb_load_cursor_image(). This is unused, and should not be implemented generically.

- Documented the usage of the cursor interface in skeletonfb.c

---
 drivers/video/console/bitblit.c |  186 +++++++++++++++++++++-------------------
 drivers/video/console/fbcon.c   |   20 +++-
 drivers/video/console/fbcon.h   |    4
 drivers/video/fbmem.c           |  130 ---------------------------
 drivers/video/skeletonfb.c      |   44 +++++++--
 include/linux/fb.h              |    7 -
 6 files changed, 154 insertions(+), 237 deletions(-)
drivers/video/console/bitblit.c +101 -85
diff -Nru a/drivers/video/console/bitblit.c b/drivers/video/console/bitblit.c
@@ -239,118 +239,134 @@
 		       struct display *p, int mode, int fg, int bg)
 {
 	struct fb_cursor cursor;
+	struct fbcon_ops *ops = (struct fbcon_ops *) info->fbcon_par;
 	unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
 	int w = (vc->vc_font.width + 7) >> 3, c;
 	int y = real_y(p, vc->vc_y);
 	int attribute;
 	char *src;
 
+	cursor.set = 0;
+
  	c = scr_readw((u16 *) vc->vc_pos);
 	attribute = get_attribute(info, c);
 	src = vc->vc_font.data + ((c & charmask) * (w * vc->vc_font.height));
+
+	if (ops->cursor_state.image.data != src) {
+	    ops->cursor_state.image.data = src;
+	    cursor.set |= FB_CUR_SETIMAGE;
+	}
+
 	if (attribute) {
 		u8 *dst;
 
 		dst = kmalloc(w * vc->vc_font.height, GFP_ATOMIC);
 		if (!dst)
 			return;
-		if (info->cursor.data)
-			kfree(info->cursor.data);
-		info->cursor.data = dst;
+		if (ops->cursor_data)
+			kfree(ops->cursor_data);
+		ops->cursor_data = dst;
 		update_attr(dst, src, attribute, vc);
 		src = dst;
 	}
 
-	cursor.image.data = src;
-	cursor.set = FB_CUR_SETCUR;
-	cursor.image.depth = 1;
+	if (ops->cursor_state.image.fg_color != fg ||
+	    ops->cursor_state.image.bg_color != bg) {
+		ops->cursor_state.image.fg_color = fg;
+		ops->cursor_state.image.bg_color = bg;
+		cursor.set |= FB_CUR_SETCMAP;
+	}
 
-	switch (mode) {
-	case CM_ERASE:
-		if (info->cursor.rop == ROP_XOR) {
-			info->cursor.enable = 0;
-			info->cursor.rop = ROP_COPY;
-			info->fbops->fb_cursor(info, &cursor);
-		}
-		break;
-	case CM_MOVE:
-	case CM_DRAW:
-		info->cursor.enable = 1;
-        	info->cursor.rop = ROP_XOR;
+	if ((ops->cursor_state.image.dx != (vc->vc_font.width * vc->vc_x)) ||
+	    (ops->cursor_state.image.dy != (vc->vc_font.height * y))) {
+		ops->cursor_state.image.dx = vc->vc_font.width * vc->vc_x;
+		ops->cursor_state.image.dy = vc->vc_font.height * y;
+		cursor.set |= FB_CUR_SETPOS;
+	}
 
-		if (info->cursor.image.fg_color != fg ||
-		    info->cursor.image.bg_color != bg) {
-			cursor.image.fg_color = fg;
-			cursor.image.bg_color = bg;
-			cursor.set |= FB_CUR_SETCMAP;
-		}
+	if (ops->cursor_state.image.height != vc->vc_font.height ||
+	    ops->cursor_state.image.width != vc->vc_font.width) {
+		ops->cursor_state.image.height = vc->vc_font.height;
+		ops->cursor_state.image.width = vc->vc_font.width;
+		cursor.set |= FB_CUR_SETSIZE;
+	}
 
-		if ((info->cursor.image.dx != (vc->vc_font.width * vc->vc_x)) ||
-		    (info->cursor.image.dy != (vc->vc_font.height * y))) {
-			cursor.image.dx = vc->vc_font.width * vc->vc_x;
-			cursor.image.dy = vc->vc_font.height * y;
-			cursor.set |= FB_CUR_SETPOS;
-		}
+	if (ops->cursor_state.hot.x || ops->cursor_state.hot.y) {
+		ops->cursor_state.hot.x = cursor.hot.y = 0;
+		cursor.set |= FB_CUR_SETHOT;
+	}
 
-		if (info->cursor.image.height != vc->vc_font.height ||
-		    info->cursor.image.width != vc->vc_font.width) {
-			cursor.image.height = vc->vc_font.height;
-			cursor.image.width = vc->vc_font.width;
-			cursor.set |= FB_CUR_SETSIZE;
-		}
+	if ((cursor.set & FB_CUR_SETSIZE) ||
+	    ((vc->vc_cursor_type & 0x0f) != p->cursor_shape)
+	    || ops->cursor_state.mask == NULL) {
+		char *mask = kmalloc(w*vc->vc_font.height, GFP_ATOMIC);
+		int cur_height, size, i = 0;
+		u8 msk = 0xff;
 
-		if (info->cursor.hot.x || info->cursor.hot.y) {
-			cursor.hot.x = cursor.hot.y = 0;
-			cursor.set |= FB_CUR_SETHOT;
-		}
+		if (!mask)
+			return;
 
-		if ((cursor.set & FB_CUR_SETSIZE) ||
-		    ((vc->vc_cursor_type & 0x0f) != p->cursor_shape)
-		    || info->cursor.mask == NULL) {
-			char *mask = kmalloc(w*vc->vc_font.height, GFP_ATOMIC);
-			int cur_height, size, i = 0;
-			u8 msk = 0xff;
-
-			if (!mask)
-				return;
-
-			if (info->cursor.mask)
-				kfree(info->cursor.mask);
-			info->cursor.mask = mask;
-			p->cursor_shape = vc->vc_cursor_type & 0x0f;
-			cursor.set |= FB_CUR_SETSHAPE;
-
-			switch (vc->vc_cursor_type & 0x0f) {
-			case CUR_NONE:
-				cur_height = 0;
-				break;
-			case CUR_UNDERLINE:
-				cur_height = (vc->vc_font.height < 10) ? 1 : 2;
-				break;
-			case CUR_LOWER_THIRD:
-				cur_height = vc->vc_font.height/3;
-				break;
-			case CUR_LOWER_HALF:
-				cur_height = vc->vc_font.height >> 1;
-				break;
-			case CUR_TWO_THIRDS:
-				cur_height = (vc->vc_font.height << 1)/3;
-				break;
-			case CUR_BLOCK:
-			default:
-				cur_height = vc->vc_font.height;
-				break;
-			}
-			size = (vc->vc_font.height - cur_height) * w;
-			while (size--)
-				mask[i++] = ~msk;
-			size = cur_height * w;
-			while (size--)
-				mask[i++] = msk;
-		}
-		info->fbops->fb_cursor(info, &cursor);
+		if (ops->cursor_state.mask)
+			kfree(ops->cursor_state.mask);
+		ops->cursor_state.mask = mask;
+		p->cursor_shape = vc->vc_cursor_type & 0x0f;
+		cursor.set |= FB_CUR_SETSHAPE;
+
+		switch (vc->vc_cursor_type & 0x0f) {
+		case CUR_NONE:
+			cur_height = 0;
+			break;
+		case CUR_UNDERLINE:
+			cur_height = (vc->vc_font.height < 10) ? 1 : 2;
+			break;
+		case CUR_LOWER_THIRD:
+			cur_height = vc->vc_font.height/3;
+			break;
+		case CUR_LOWER_HALF:
+			cur_height = vc->vc_font.height >> 1;
+			break;
+		case CUR_TWO_THIRDS:
+			cur_height = (vc->vc_font.height << 1)/3;
+			break;
+		case CUR_BLOCK:
+		default:
+			cur_height = vc->vc_font.height;
+			break;
+		}
+		size = (vc->vc_font.height - cur_height) * w;
+		while (size--)
+			mask[i++] = ~msk;
+		size = cur_height * w;
+		while (size--)
+			mask[i++] = msk;
+	}
+
+	switch (mode) {
+	case CM_ERASE:
+		ops->cursor_state.enable = 0;
+		break;
+	case CM_DRAW:
+	case CM_MOVE:
+	default:
+		ops->cursor_state.enable = 1;
 		break;
 	}
+
+	cursor.image.data = src;
+	cursor.image.fg_color = ops->cursor_state.image.fg_color;
+	cursor.image.bg_color = ops->cursor_state.image.bg_color;
+	cursor.image.dx = ops->cursor_state.image.dx;
+	cursor.image.dy = ops->cursor_state.image.dy;
+	cursor.image.height = ops->cursor_state.image.height;
+	cursor.image.width = ops->cursor_state.image.width;
+	cursor.hot.x = ops->cursor_state.hot.x;
+	cursor.hot.y = ops->cursor_state.hot.y;
+	cursor.mask = ops->cursor_state.mask;
+	cursor.enable = ops->cursor_state.enable;
+	cursor.image.depth = 1;
+	cursor.rop = ROP_XOR;
+
+	info->fbops->fb_cursor(info, &cursor);
 }
 
 void fbcon_set_bitops(struct fbcon_ops *ops)
drivers/video/console/fbcon.c +14 -6
diff -Nru a/drivers/video/console/fbcon.c b/drivers/video/console/fbcon.c
@@ -245,14 +245,15 @@
 		vc = vc_cons[info->currcon].d;
 
 	if (info->state != FBINFO_STATE_RUNNING ||
-	    !vc || !CON_IS_VISIBLE(vc) || !info->cursor.flash ||
+	    !vc || !CON_IS_VISIBLE(vc) ||
 	    vt_cons[vc->vc_num]->vc_mode != KD_TEXT ||
  	    registered_fb[(int) con2fb_map[vc->vc_num]] != info)
 		return;
+	acquire_console_sem();
 	p = &fb_display[vc->vc_num];
 	c = scr_readw((u16 *) vc->vc_pos);
-	acquire_console_sem();
-	mode = (info->cursor.enable) ? CM_ERASE : CM_DRAW;
+	mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
+		CM_ERASE : CM_DRAW;
 	ops->cursor(vc, info, p, mode, get_color(vc, info, c, 1),
 		    get_color(vc, info, c, 0));
 	release_console_sem();
@@ -533,6 +534,7 @@
 		}
 
 		if (!err) {
+			memset(ops, 0, sizeof(struct fbcon_ops));
 			info->fbcon_par = ops;
 			set_blitting_type(vc, info, NULL);
 		}
@@ -550,6 +552,8 @@
 	 * fbcon should release it.
 	 */
 	if (oldinfo && !search_fb_in_map(oldidx)) {
+		struct fbcon_ops *ops = (struct fbcon_ops *) oldinfo->fbcon_par;
+
 		if (oldinfo->fbops->fb_release &&
 		    oldinfo->fbops->fb_release(oldinfo, 0)) {
 			con2fb_map[unit] = oldidx;
@@ -564,6 +568,8 @@
 		if (oldinfo->queue.func == fb_flashcursor)
 			del_timer_sync(&oldinfo->cursor_timer);
 
+		kfree(ops->cursor_state.mask);
+		kfree(ops->cursor_data);
 		kfree(oldinfo->fbcon_par);
 		module_put(oldinfo->fbops->owner);
 	}
@@ -692,6 +698,7 @@
 		return NULL;
 	}
 
+	memset(ops, 0, sizeof(struct fbcon_ops));
 	info->fbcon_par = ops;
 	set_blitting_type(vc, info, NULL);
 
@@ -1024,13 +1031,13 @@
 	int y = real_y(p, vc->vc_y);
  	int c = scr_readw((u16 *) vc->vc_pos);
 
-	info->cursor.flash = 1;
+	ops->cursor_flash = 1;
 	if (mode & CM_SOFTBACK) {
 		mode &= ~CM_SOFTBACK;
 		if (softback_lines) {
 			if (y + softback_lines >= vc->vc_rows) {
 				mode = CM_ERASE;
-				info->cursor.flash = 0;
+				ops->cursor_flash = 0;
 			}
 			else
 				y += softback_lines;
@@ -1932,6 +1939,7 @@
 {
 	unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
 	struct fb_info *info = registered_fb[(int) con2fb_map[vc->vc_num]];
+	struct fbcon_ops *ops = (struct fbcon_ops *) info->fbcon_par;
 	struct display *p = &fb_display[vc->vc_num];
 
 	if (mode_switch) {
@@ -1961,7 +1969,7 @@
 	}
 
 	fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
-	info->cursor.flash = (!blank);
+	ops->cursor_flash = (!blank);
 
 	if (!info->fbops->fb_blank) {
 		if (blank) {
drivers/video/console/fbcon.h +4 -0
diff -Nru a/drivers/video/console/fbcon.h b/drivers/video/console/fbcon.h
@@ -60,6 +60,10 @@
 			      int bottom_only);
 	void (*cursor)(struct vc_data *vc, struct fb_info *info,
 		       struct display *p, int mode, int fg, int bg);
+
+	struct fb_cursor cursor_state;
+	int    cursor_flash;
+	char  *cursor_data;
 };
     /*
      *  Attribute Decoding
drivers/video/fbmem.c +1 -129

160 lines not on this page · raw message

drivers/video/skeletonfb.c +33 -11

62 lines not on this page · raw message

include/linux/fb.h +1 -6
diff -Nru a/include/linux/fb.h b/include/linux/fb.h
@@ -298,7 +298,7 @@
  * hardware cursor control
  */
 
-#define FB_CUR_SETCUR   0x01
+#define FB_CUR_SETIMAGE 0x01
 #define FB_CUR_SETPOS   0x02
 #define FB_CUR_SETHOT   0x04
 #define FB_CUR_SETCMAP  0x08
@@ -317,9 +317,6 @@
 	const char *mask;	/* cursor mask bits */
 	struct fbcurpos hot;	/* cursor hot spot */
 	struct fb_image	image;	/* Cursor image */
-/* all fields below are for fbcon use only */
-	int   flash;            /* cursor blink */
-	char  *data;             /* copy of bitmap */
 };
 
 #ifdef __KERNEL__
@@ -671,7 +668,6 @@
 	struct fb_var_screeninfo var;	/* Current var */
 	struct fb_fix_screeninfo fix;	/* Current fix */
 	struct fb_monspecs monspecs;	/* Current Monitor specs */
-	struct fb_cursor cursor;	/* Current cursor */	
 	struct work_struct queue;	/* Framebuffer event queue */
 	struct timer_list cursor_timer; /* Cursor timer */
 	struct fb_pixmap pixmap;	/* Image hardware mapper */
@@ -787,7 +783,6 @@
 extern void fb_sysmove_buf_aligned(struct fb_info *info, struct fb_pixmap *buf,
 				u8 *dst, u32 d_pitch, u8 *src, u32 s_pitch,
 				u32 height);
-extern void fb_load_cursor_image(struct fb_info *);
 extern void fb_set_suspend(struct fb_info *info, int state);
 extern int fb_get_color_depth(struct fb_info *info);
 extern int fb_get_options(char *name, char **option);

-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal Use IT products in your business? Tell us what you think of them. Give us Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl