fbcon.c

来自「优龙2410linux2.6.8内核源代码」· C语言 代码 · 共 2,412 行 · 第 1/5 页

C
2,412
字号
		pitch = ((image.width + 7) >> 3) + scan_align;		pitch &= ~scan_align;		size = pitch * image.height + buf_align;		size &= ~buf_align;		dst = fb_get_buffer_offset(info, &info->pixmap, size);		image.data = dst;		if (mod) {			while (k--) {				src = vc->vc_font.data + (scr_readw(s++)&							  charmask)*cellsize;				move_unaligned(info, &info->pixmap, dst, pitch,					       src, idx, image.height,					       shift_high, shift_low, mod);				shift_low += mod;				dst += (shift_low >= 8) ? width : width - 1;				shift_low &= 7;				shift_high = 8 - shift_low;			}		} else {			while (k--) {				src = vc->vc_font.data + (scr_readw(s++)&							  charmask)*cellsize;				move_aligned(info, &info->pixmap, dst, pitch,					     src, idx, image.height);				dst += width;			}		}		info->fbops->fb_imageblit(info, &image);		image.dx += cnt * vc->vc_font.width;		count -= cnt;	}}void accel_clear_margins(struct vc_data *vc, struct fb_info *info,				int bottom_only){	int bgshift = (vc->vc_hi_font_mask) ? 13 : 12;	unsigned int cw = vc->vc_font.width;	unsigned int ch = vc->vc_font.height;	unsigned int rw = info->var.xres - (vc->vc_cols*cw);	unsigned int bh = info->var.yres - (vc->vc_rows*ch);	unsigned int rs = info->var.xres - rw;	unsigned int bs = info->var.yres - bh;	struct fb_fillrect region;	region.color = attr_bgcol_ec(bgshift, vc);	region.rop = ROP_COPY;	if (rw && !bottom_only) {		region.dx = info->var.xoffset + rs;		region.dy = 0;		region.width = rw;		region.height = info->var.yres_virtual;		info->fbops->fb_fillrect(info, &region);	}	if (bh) {		region.dx = info->var.xoffset;		region.dy = info->var.yoffset + bs;		region.width = rs;		region.height = bh;		info->fbops->fb_fillrect(info, &region);	}	}	/* *  Low Level Operations *//* NOTE: fbcon cannot be __init: it may be called from take_over_console later */static const char *fbcon_startup(void){	const char *display_desc = "frame buffer device";	struct display *p = &fb_display[fg_console];	struct vc_data *vc = vc_cons[fg_console].d;	struct font_desc *font = NULL;	struct module *owner;	struct fb_info *info = NULL;	int rows, cols;	int irqres;	irqres = 1;	/*	 *  If num_registered_fb is zero, this is a call for the dummy part.	 *  The frame buffer devices weren't initialized yet.	 */	if (!num_registered_fb || info_idx == -1)		return display_desc;	/*	 * Instead of blindly using registered_fb[0], we use info_idx, set by	 * fb_console_init();	 */	info = registered_fb[info_idx];	if (!info)		return NULL;	info->currcon = -1;		owner = info->fbops->owner;	if (!try_module_get(owner))		return NULL;	if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {		module_put(owner);		return NULL;	}	if (info->fix.type != FB_TYPE_TEXT) {		if (fbcon_softback_size) {			if (!softback_buf) {				softback_buf =				    (unsigned long)				    kmalloc(fbcon_softback_size,					    GFP_KERNEL);				if (!softback_buf) {					fbcon_softback_size = 0;					softback_top = 0;				}			}		} else {			if (softback_buf) {				kfree((void *) softback_buf);				softback_buf = 0;				softback_top = 0;			}		}		if (softback_buf)			softback_in = softback_top = softback_curr =			    softback_buf;		softback_lines = 0;	}	/* Setup default font */	if (!p->fontdata) {		if (!fontname[0] || !(font = find_font(fontname)))			font = get_default_font(info->var.xres,						   info->var.yres);		vc->vc_font.width = font->width;		vc->vc_font.height = font->height;		vc->vc_font.data = p->fontdata = font->data;		vc->vc_font.charcount = 256; /* FIXME  Need to support more fonts */	}	cols = info->var.xres / vc->vc_font.width;	rows = info->var.yres / vc->vc_font.height;	vc_resize(vc->vc_num, cols, rows);	DPRINTK("mode:   %s\n", info->fix.id);	DPRINTK("visual: %d\n", info->fix.visual);	DPRINTK("res:    %dx%d-%d\n", info->var.xres,		info->var.yres,		info->var.bits_per_pixel);	con_set_default_unimap(vc->vc_num);#ifdef CONFIG_ATARI	if (MACH_IS_ATARI) {		cursor_blink_rate = ATARI_CURSOR_BLINK_RATE;		irqres =		    request_irq(IRQ_AUTO_4, fb_vbl_handler,				IRQ_TYPE_PRIO, "framebuffer vbl",				info);	}#endif				/* CONFIG_ATARI */#ifdef CONFIG_MAC	/*	 * On a Macintoy, the VBL interrupt may or may not be active. 	 * As interrupt based cursor is more reliable and race free, we 	 * probe for VBL interrupts.	 */	if (MACH_IS_MAC) {		int ct = 0;		/*		 * Probe for VBL: set temp. handler ...		 */		irqres = request_irq(IRQ_MAC_VBL, fb_vbl_detect, 0,				     "framebuffer vbl", info);		vbl_detected = 0;		/*		 * ... and spin for 20 ms ...		 */		while (!vbl_detected && ++ct < 1000)			udelay(20);		if (ct == 1000)			printk			    ("fbcon_startup: No VBL detected, using timer based cursor.\n");		free_irq(IRQ_MAC_VBL, fb_vbl_detect);		if (vbl_detected) {			/*			 * interrupt based cursor ok			 */			cursor_blink_rate = MAC_CURSOR_BLINK_RATE;			irqres =			    request_irq(IRQ_MAC_VBL, fb_vbl_handler, 0,					"framebuffer vbl", info);		} else {			/*			 * VBL not detected: fall through, use timer based cursor			 */			irqres = 1;		}	}#endif				/* CONFIG_MAC */#if defined(__arm__) && defined(IRQ_VSYNCPULSE)	cursor_blink_rate = ARM_CURSOR_BLINK_RATE;	irqres = request_irq(IRQ_VSYNCPULSE, fb_vbl_handler, SA_SHIRQ,			     "framebuffer vbl", info);#endif	/* Initialize the work queue. If the driver provides its	 * own work queue this means it will use something besides 	 * default timer to flash the cursor. */	if (!info->queue.func) {		INIT_WORK(&info->queue, fb_flashcursor, info);		init_timer(&info->cursor_timer);		info->cursor_timer.function = cursor_timer_handler;		info->cursor_timer.expires = jiffies + HZ / 5;		info->cursor_timer.data = (unsigned long ) info;		add_timer(&info->cursor_timer);	}	return display_desc;}static void fbcon_init(struct vc_data *vc, int init){	struct fb_info *info = registered_fb[(int) con2fb_map[vc->vc_num]];	struct vc_data **default_mode = vc->vc_display_fg;	struct display *t, *p = &fb_display[vc->vc_num];	int display_fg = (*default_mode)->vc_num;	int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;	unsigned short *save = NULL, *r, *q;	int cap = info->flags;	if (info_idx == -1 || info == NULL)	    return;	if (vc->vc_num != display_fg || (info->flags & FBINFO_MODULE) ||	    (info->fix.type == FB_TYPE_TEXT))		logo = 0;	info->var.xoffset = info->var.yoffset = p->yscroll = 0;	/* reset wrap/pan */	/* If we are not the first console on this	   fb, copy the font from that console */	t = &fb_display[display_fg];	if (!vc->vc_font.data) {		vc->vc_font.data = p->fontdata = t->fontdata;		vc->vc_font.width = (*default_mode)->vc_font.width;		vc->vc_font.height = (*default_mode)->vc_font.height;		p->userfont = t->userfont;		if (p->userfont)			REFCOUNT(p->fontdata)++;		con_copy_unimap(vc->vc_num, display_fg);	}	if (p->userfont)		charcnt = FNTCHARCNT(p->fontdata);	vc->vc_can_do_color = info->var.bits_per_pixel != 1;	vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;	if (charcnt == 256) {		vc->vc_hi_font_mask = 0;	} else {		vc->vc_hi_font_mask = 0x100;		if (vc->vc_can_do_color)			vc->vc_complement_mask <<= 1;	}	cols = vc->vc_cols;	rows = vc->vc_rows;	new_cols = info->var.xres / vc->vc_font.width;	new_rows = info->var.yres / vc->vc_font.height;	vc_resize(vc->vc_num, new_cols, new_rows);	/*	 * We must always set the mode. The mode of the previous console	 * driver could be in the same resolution but we are using different	 * hardware so we have to initialize the hardware.	 *	 * We need to do it in fbcon_init() to prevent screen corruption.	 */	if (CON_IS_VISIBLE(vc) && info->fbops->fb_set_par)		info->fbops->fb_set_par(info);	if ((cap & FBINFO_HWACCEL_COPYAREA) &&	    !(cap & FBINFO_HWACCEL_DISABLED))		p->scrollmode = SCROLL_MOVE;	else /* default to something safe */		p->scrollmode = SCROLL_REDRAW;	/*	 *  ++guenther: console.c:vc_allocate() relies on initializing	 *  vc_{cols,rows}, but we must not set those if we are only	 *  resizing the console.	 */	if (!init) {		vc->vc_cols = new_cols;		vc->vc_rows = new_rows;	}	if (logo) {		/* Need to make room for the logo */		int cnt;		int step;		logo_height = fb_prepare_logo(info);		logo_lines = (logo_height + vc->vc_font.height - 1) /			     vc->vc_font.height;		q = (unsigned short *) (vc->vc_origin +					vc->vc_size_row * rows);		step = logo_lines * cols;		for (r = q - logo_lines * cols; r < q; r++)			if (scr_readw(r) != vc->vc_video_erase_char)				break;		if (r != q && new_rows >= rows + logo_lines) {			save = kmalloc(logo_lines * new_cols * 2, GFP_KERNEL);			if (save) {				int i = cols < new_cols ? cols : new_cols;				scr_memsetw(save, vc->vc_video_erase_char,					    logo_lines * new_cols * 2);				r = q - step;				for (cnt = 0; cnt < logo_lines; cnt++, r += i)					scr_memcpyw(save + cnt * new_cols, r, 2 * i);				r = q;			}		}		if (r == q) {			/* We can scroll screen down */			r = q - step - cols;			for (cnt = rows - logo_lines; cnt > 0; cnt--) {				scr_memcpyw(r + step, r, vc->vc_size_row);				r -= cols;			}			if (!save) {				vc->vc_y += logo_lines;				vc->vc_pos += logo_lines * vc->vc_size_row;			}		}		scr_memsetw((unsigned short *) vc->vc_origin,			    vc->vc_video_erase_char,			    vc->vc_size_row * logo_lines);		if (CON_IS_VISIBLE(vc) && vt_cons[vc->vc_num]->vc_mode == KD_TEXT) {			accel_clear_margins(vc, info, 0);			update_screen(vc->vc_num);		}		if (save) {			q = (unsigned short *) (vc->vc_origin +						vc->vc_size_row *						rows);			scr_memcpyw(q, save, logo_lines * new_cols * 2);			vc->vc_y += logo_lines;			vc->vc_pos += logo_lines * vc->vc_size_row;			kfree(save);		}		if (logo_lines > vc->vc_bottom) {			logo_shown = -1;			printk(KERN_INFO			       "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");		} else {			logo_shown = -2;			vc->vc_top = logo_lines;		}	}	if (vc->vc_num == display_fg && softback_buf) {		int l = fbcon_softback_size / vc->vc_size_row;		if (l > 5)			softback_end = softback_buf + l * vc->vc_size_row;		else {			/* Smaller scrollback makes no sense, and 0 would screw			   the operation totally */			softback_top = 0;		}	}}static void fbcon_deinit(struct vc_data *vc){	struct display *p = &fb_display[vc->vc_num];	if (info_idx != -1)	    return;	fbcon_free_font(p);}/* ====================================================================== *//*  fbcon_XXX routines - interface used by the world * *  This system is now divided into two levels because of complications *  caused by hardware scrolling. Top level functions: * *	fbcon_bmove(), fbcon_clear(), fbcon_putc() * *  handles y values in range [0, scr_height-1] that correspond to real *  screen positions. y_wrap shift means that first line of bitmap may be *  anywhere on this display. These functions convert lineoffsets to *  bitmap offsets and deal with the wrap-around case by splitting blits. * *	fbcon_bmove_physical_8()    -- These functions fast implementations *	fbcon_clear_physical_8()    -- of original fbcon_XXX fns. *	fbcon_putc_physical_8()	    -- (font width != 8) may be added later * *  WARNING: * *  At the moment fbcon_putc() cannot blit across vertical wrap boundary *  Implies should only really hardware scroll in rows. Only reason for *  restriction is simplicity & efficiency at the moment. */static __inline__ int real_y(struct display *p, int ypos){	int rows = p->vrows;	ypos += p->yscroll;	return ypos < rows ? ypos : ypos - rows;}static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,			int width){	struct fb_info *info = registered_fb[(int) con2fb_map[vc->vc_num]];		struct display *p = &fb_display[vc->vc_num];	u_int y_break;	if (!info->fbops->fb_blank && console_blanked)		return;	if (info->state != FBINFO_STATE_RUNNING)		return;	if (!height || !width)		return;	/* Split blits that cross physical y_wrap boundary */	y_break = p->vrows - p->yscroll;	if (sy < y_break && sy + height - 1 >= y_break) {		u_int b = y_break - sy;		accel_clear(vc, info, real_y(p, sy), sx, b, width);		accel_clear(vc, info, real_y(p, sy + b), sx, height - b,				 width);	} else		accel_clear(vc, info, real_y(p, sy), sx, height, width);}static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos){	struct fb_info *info = registered_fb[(int) con2fb_map[vc->vc_num]];	unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;	unsigned int scan_align = info->pixmap.scan_align - 1;	unsigned int buf_align = info->pixmap.buf_align - 1;	unsigned int width = (vc->vc_font.width + 7) >> 3;	int bgshift = (vc->vc_hi_font_mask) ? 13 : 12;	int fgshift = (vc->vc_hi_font_mask) ? 9 : 8;	struct display *p = &fb_display[vc->vc_num];	unsigned int size, pitch;	struct fb_image image;	u8 *src, *dst;	if (!info->fbops->fb_blank && console_blanked)		return;	if (info->state != FBINFO_STATE_RUNNING)		return;	if (vt_cons[vc->vc_num]->vc_mode != KD_TEXT)		return;	image.dx = xpos * vc->vc_font.width;	image.dy = real_y(p, ypos) * vc->vc_font.height;	image.width = vc->vc_font.width;	image.height = vc->vc_font.height;	image.fg_color = attr_fgcol(fgshift, c);	image.bg_color = attr_bgcol(bgshift, c);	image.depth = 1;	src = vc->vc_font.data + (c & charmask) * vc->vc_font.height * width;	pitch = width + scan_align;	pitch &= ~scan_align;	size = pitch * vc->vc_font.height;	size += buf_align;	size &= ~buf_align;

⌨️ 快捷键说明

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