⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fbcon.c

📁 omap3 linux 2.6 用nocc去除了冗余代码
💻 C
📖 第 1 页 / 共 5 页
字号:
	fb_set_var(info, &var);	ops->var = info->var;	if (old_info != NULL && (old_info != info ||				 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {		if (info->fbops->fb_set_par)			info->fbops->fb_set_par(info);		if (old_info != info)			fbcon_del_cursor_timer(old_info);	}	if (fbcon_is_inactive(vc, info) ||	    ops->blank_state != FB_BLANK_UNBLANK)		fbcon_del_cursor_timer(info);	else		fbcon_add_cursor_timer(info);	set_blitting_type(vc, info);	ops->cursor_reset = 1;	if (ops->rotate_font && ops->rotate_font(info, vc)) {		ops->rotate = FB_ROTATE_UR;		set_blitting_type(vc, info);	}	vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);	vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;	if (p->userfont)		charcnt = FNTCHARCNT(vc->vc_font.data);	if (charcnt > 256)		vc->vc_complement_mask <<= 1;	updatescrollmode(p, info, vc);	switch (p->scrollmode) {	case SCROLL_WRAP_MOVE:		scrollback_phys_max = p->vrows - vc->vc_rows;		break;	case SCROLL_PAN_MOVE:	case SCROLL_PAN_REDRAW:		scrollback_phys_max = p->vrows - 2 * vc->vc_rows;		if (scrollback_phys_max < 0)			scrollback_phys_max = 0;		break;	default:		scrollback_phys_max = 0;		break;	}	scrollback_max = 0;	scrollback_current = 0;	if (!fbcon_is_inactive(vc, info)) {	    ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;	    ops->update_start(info);	}	fbcon_set_palette(vc, color_table); 		fbcon_clear_margins(vc, 0);	if (logo_shown == FBCON_LOGO_DRAW) {		logo_shown = fg_console;		/* This is protected above by initmem_freed */		fb_show_logo(info, ops->rotate);		update_region(vc,			      vc->vc_origin + vc->vc_size_row * vc->vc_top,			      vc->vc_size_row * (vc->vc_bottom -						 vc->vc_top) / 2);		return 0;	}	return 1;}static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,				int blank){	struct fb_event event;	if (blank) {		unsigned short charmask = vc->vc_hi_font_mask ?			0x1ff : 0xff;		unsigned short oldc;		oldc = vc->vc_video_erase_char;		vc->vc_video_erase_char &= charmask;		fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);		vc->vc_video_erase_char = oldc;	}	event.info = info;	event.data = &blank;	fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);}static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch){	struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];	struct fbcon_ops *ops = info->fbcon_par;	if (mode_switch) {		struct fb_var_screeninfo var = info->var;		ops->graphics = 1;		if (!blank) {			if (info->fbops->fb_save_state)				info->fbops->fb_save_state(info);			var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;			fb_set_var(info, &var);			ops->graphics = 0;			ops->var = info->var;		} else if (info->fbops->fb_restore_state)			info->fbops->fb_restore_state(info);	} 	if (!fbcon_is_inactive(vc, info)) {		if (ops->blank_state != blank) {			ops->blank_state = blank;			fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);			ops->cursor_flash = (!blank);			if (fb_blank(info, blank))				fbcon_generic_blank(vc, info, blank);		}		if (!blank)			update_screen(vc);	}	if (fbcon_is_inactive(vc, info) ||	    ops->blank_state != FB_BLANK_UNBLANK)		fbcon_del_cursor_timer(info);	else		fbcon_add_cursor_timer(info);	return 0;}static int fbcon_get_font(struct vc_data *vc, struct console_font *font){	u8 *fontdata = vc->vc_font.data;	u8 *data = font->data;	int i, j;	font->width = vc->vc_font.width;	font->height = vc->vc_font.height;	font->charcount = vc->vc_hi_font_mask ? 512 : 256;	if (!font->data)		return 0;	if (font->width <= 8) {		j = vc->vc_font.height;		for (i = 0; i < font->charcount; i++) {			memcpy(data, fontdata, j);			memset(data + j, 0, 32 - j);			data += 32;			fontdata += j;		}	} else if (font->width <= 16) {		j = vc->vc_font.height * 2;		for (i = 0; i < font->charcount; i++) {			memcpy(data, fontdata, j);			memset(data + j, 0, 64 - j);			data += 64;			fontdata += j;		}	} else if (font->width <= 24) {		for (i = 0; i < font->charcount; i++) {			for (j = 0; j < vc->vc_font.height; j++) {				*data++ = fontdata[0];				*data++ = fontdata[1];				*data++ = fontdata[2];				fontdata += sizeof(u32);			}			memset(data, 0, 3 * (32 - j));			data += 3 * (32 - j);		}	} else {		j = vc->vc_font.height * 4;		for (i = 0; i < font->charcount; i++) {			memcpy(data, fontdata, j);			memset(data + j, 0, 128 - j);			data += 128;			fontdata += j;		}	}	return 0;}static int fbcon_do_set_font(struct vc_data *vc, int w, int h,			     const u8 * data, int userfont){	struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];	struct fbcon_ops *ops = info->fbcon_par;	struct display *p = &fb_display[vc->vc_num];	int resize;	int cnt;	char *old_data = NULL;	if (CON_IS_VISIBLE(vc) && softback_lines)		fbcon_set_origin(vc);	resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);	if (p->userfont)		old_data = vc->vc_font.data;	if (userfont)		cnt = FNTCHARCNT(data);	else		cnt = 256;	vc->vc_font.data = (void *)(p->fontdata = data);	if ((p->userfont = userfont))		REFCOUNT(data)++;	vc->vc_font.width = w;	vc->vc_font.height = h;	if (vc->vc_hi_font_mask && cnt == 256) {		vc->vc_hi_font_mask = 0;		if (vc->vc_can_do_color) {			vc->vc_complement_mask >>= 1;			vc->vc_s_complement_mask >>= 1;		}					/* ++Edmund: reorder the attribute bits */		if (vc->vc_can_do_color) {			unsigned short *cp =			    (unsigned short *) vc->vc_origin;			int count = vc->vc_screenbuf_size / 2;			unsigned short c;			for (; count > 0; count--, cp++) {				c = scr_readw(cp);				scr_writew(((c & 0xfe00) >> 1) |					   (c & 0xff), cp);			}			c = vc->vc_video_erase_char;			vc->vc_video_erase_char =			    ((c & 0xfe00) >> 1) | (c & 0xff);			vc->vc_attr >>= 1;		}	} else if (!vc->vc_hi_font_mask && cnt == 512) {		vc->vc_hi_font_mask = 0x100;		if (vc->vc_can_do_color) {			vc->vc_complement_mask <<= 1;			vc->vc_s_complement_mask <<= 1;		}					/* ++Edmund: reorder the attribute bits */		{			unsigned short *cp =			    (unsigned short *) vc->vc_origin;			int count = vc->vc_screenbuf_size / 2;			unsigned short c;			for (; count > 0; count--, cp++) {				unsigned short newc;				c = scr_readw(cp);				if (vc->vc_can_do_color)					newc =					    ((c & 0xff00) << 1) | (c &								   0xff);				else					newc = c & ~0x100;				scr_writew(newc, cp);			}			c = vc->vc_video_erase_char;			if (vc->vc_can_do_color) {				vc->vc_video_erase_char =				    ((c & 0xff00) << 1) | (c & 0xff);				vc->vc_attr <<= 1;			} else				vc->vc_video_erase_char = c & ~0x100;		}	}	if (resize) {		int cols, rows;		cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);		rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);		cols /= w;		rows /= h;		vc_resize(vc, cols, rows);		if (CON_IS_VISIBLE(vc) && softback_buf)			fbcon_update_softback(vc);	} else if (CON_IS_VISIBLE(vc)		   && vc->vc_mode == KD_TEXT) {		fbcon_clear_margins(vc, 0);		update_screen(vc);	}	if (old_data && (--REFCOUNT(old_data) == 0))		kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));	return 0;}static int fbcon_copy_font(struct vc_data *vc, int con){	struct display *od = &fb_display[con];	struct console_font *f = &vc->vc_font;	if (od->fontdata == f->data)		return 0;	/* already the same font... */	return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);}/* *  User asked to set font; we are guaranteed that *	a) width and height are in range 1..32 *	b) charcount does not exceed 512 *  but lets not assume that, since someone might someday want to use larger *  fonts. And charcount of 512 is small for unicode support. * *  However, user space gives the font in 32 rows , regardless of *  actual font height. So a new API is needed if support for larger fonts *  is ever implemented. */static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags){	struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];	unsigned charcount = font->charcount;	int w = font->width;	int h = font->height;	int size;	int i, csum;	u8 *new_data, *data = font->data;	int pitch = (font->width+7) >> 3;	/* Is there a reason why fbconsole couldn't handle any charcount >256?	 * If not this check should be changed to charcount < 256 */	if (charcount != 256 && charcount != 512)		return -EINVAL;	/* Make sure drawing engine can handle the font */	if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||	    !(info->pixmap.blit_y & (1 << (font->height - 1))))		return -EINVAL;	/* Make sure driver can handle the font length */	if (fbcon_invalid_charcount(info, charcount))		return -EINVAL;	size = h * pitch * charcount;	new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);	if (!new_data)		return -ENOMEM;	new_data += FONT_EXTRA_WORDS * sizeof(int);	FNTSIZE(new_data) = size;	FNTCHARCNT(new_data) = charcount;	REFCOUNT(new_data) = 0;	/* usage counter */	for (i=0; i< charcount; i++) {		memcpy(new_data + i*h*pitch, data +  i*32*pitch, h*pitch);	}	/* Since linux has a nice crc32 function use it for counting font	 * checksums. */	csum = crc32(0, new_data, size);	FNTSUM(new_data) = csum;	/* Check if the same font is on some other console already */	for (i = first_fb_vc; i <= last_fb_vc; i++) {		struct vc_data *tmp = vc_cons[i].d;				if (fb_display[i].userfont &&		    fb_display[i].fontdata &&		    FNTSUM(fb_display[i].fontdata) == csum &&		    FNTSIZE(fb_display[i].fontdata) == size &&		    tmp->vc_font.width == w &&		    !memcmp(fb_display[i].fontdata, new_data, size)) {			kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));			new_data = (u8 *)fb_display[i].fontdata;			break;		}	}	return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);}static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name){	struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];	const struct font_desc *f;	if (!name)		f = get_default_font(info->var.xres, info->var.yres,				     info->pixmap.blit_x, info->pixmap.blit_y);	else if (!(f = find_font(name)))		return -ENOENT;	font->width = f->width;	font->height = f->height;	return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);}static u16 palette_red[16];static u16 palette_green[16];static u16 palette_blue[16];static struct fb_cmap palette_cmap = {	0, 16, palette_red, palette_green, palette_blue, NULL};static int fbcon_set_palette(struct vc_data *vc, unsigned char *table){	struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];	int i, j, k, depth;	u8 val;	if (fbcon_is_inactive(vc, info))		return -EINVAL;	if (!CON_IS_VISIBLE(vc))		return 0;	depth = fb_get_color_depth(&info->var, &info->fix);	if (depth > 3) {		for (i = j = 0; i < 16; i++) {			k = table[i];			val = vc->vc_palette[j++];			palette_red[k] = (val << 8) | val;			val = vc->vc_palette[j++];			palette_green[k] = (val << 8) | val;			val = vc->vc_palette[j++];			palette_blue[k] = (val << 8) | val;		}		palette_cmap.len = 16;		palette_cmap.start = 0;	/*	 * If framebuffer is capable of less than 16 colors,	 * use default palette of fbcon.	 */	} else		fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);	return fb_set_cmap(&palette_cmap, info);}static u16 *fbcon_screen_pos(struct vc_data *vc, int offset){	unsigned long p;	int line;		if (vc->vc_num != fg_console || !softback_lines)		return (u16 *) (vc->vc_origin + offset);	line = offset / vc->vc_size_row;	if (line >= softback_lines)		return (u16 *) (vc->vc_origin + offset -				softback_lines * vc->vc_size_row);	p = softback_curr + offset;	if (p >= softback_end)		p += softback_buf - softback_end;	return (u16 *) p;}static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,				 int *px, int *py){	unsigned long ret;	int x, y;	if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {		unsigned long offset = (pos - vc->vc_origin) / 2;		x = offset % vc->vc_cols;		y = offset / vc->vc_cols;		if (vc->vc_num == fg_console)			y += softback_lines;		ret = pos + (vc->vc_cols - x) * 2;	} else if (vc->vc_num == fg_console && softback_lines) {		unsigned long offset = pos - softback_curr;		if (pos < softback_curr)			offset += softback_end - softback_buf;		offset /= 2;		x = offset % vc->vc_cols;		y = offset / vc->vc_cols;		ret = pos + (vc->vc_cols - x) * 2;		if (ret == softback_end)			ret = softback_buf;		if (ret == softback_in)			ret = vc->vc_origin;	} else {		/* Should not happen */		x = y = 0;		ret = vc->vc_origin;	}	if (px)		*px = x;	if (py)		*py = y;	return ret;}/* As we might be inside of softback, we may work with non-contiguous buffer,   that's why we have to use a separate rout

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -