2 * linux/drivers/video/console/bitblit.c -- BitBlitting Operation
4 * Originally from the 'accel_*' routines in drivers/video/console/fbcon.c
6 * Copyright (C) 2004 Antonino Daplas <adaplas @pol.net>
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file COPYING in the main directory of this archive for
13 #include <linux/config.h>
14 #include <linux/module.h>
15 #include <linux/string.h>
17 #include <linux/vt_kern.h>
18 #include <linux/console.h>
19 #include <asm/types.h>
23 * Accelerated handlers.
25 #define FBCON_ATTRIBUTE_UNDERLINE 1
26 #define FBCON_ATTRIBUTE_REVERSE 2
27 #define FBCON_ATTRIBUTE_BOLD 4
29 static inline int real_y(struct display *p, int ypos)
34 return ypos < rows ? ypos : ypos - rows;
38 static inline int get_attribute(struct fb_info *info, u16 c)
42 if (fb_get_color_depth(&info->var) == 1) {
43 if (attr_underline(c))
44 attribute |= FBCON_ATTRIBUTE_UNDERLINE;
46 attribute |= FBCON_ATTRIBUTE_REVERSE;
48 attribute |= FBCON_ATTRIBUTE_BOLD;
54 static inline void update_attr(u8 *dst, u8 *src, int attribute,
57 int i, offset = (vc->vc_font.height < 10) ? 1 : 2;
58 int width = (vc->vc_font.width + 7) >> 3;
59 unsigned int cellsize = vc->vc_font.height * width;
62 offset = cellsize - (offset * width);
63 for (i = 0; i < cellsize; i++) {
65 if (attribute & FBCON_ATTRIBUTE_UNDERLINE && i >= offset)
67 if (attribute & FBCON_ATTRIBUTE_BOLD)
69 if (attribute & FBCON_ATTRIBUTE_REVERSE)
75 static void bit_bmove(struct vc_data *vc, struct fb_info *info, int sy,
76 int sx, int dy, int dx, int height, int width)
78 struct fb_copyarea area;
80 area.sx = sx * vc->vc_font.width;
81 area.sy = sy * vc->vc_font.height;
82 area.dx = dx * vc->vc_font.width;
83 area.dy = dy * vc->vc_font.height;
84 area.height = height * vc->vc_font.height;
85 area.width = width * vc->vc_font.width;
87 info->fbops->fb_copyarea(info, &area);
90 static void bit_clear(struct vc_data *vc, struct fb_info *info, int sy,
91 int sx, int height, int width)
93 int bgshift = (vc->vc_hi_font_mask) ? 13 : 12;
94 struct fb_fillrect region;
96 region.color = attr_bgcol_ec(bgshift, vc);
97 region.dx = sx * vc->vc_font.width;
98 region.dy = sy * vc->vc_font.height;
99 region.width = width * vc->vc_font.width;
100 region.height = height * vc->vc_font.height;
101 region.rop = ROP_COPY;
103 info->fbops->fb_fillrect(info, ®ion);
106 static void bit_putcs(struct vc_data *vc, struct fb_info *info,
107 const unsigned short *s, int count, int yy, int xx,
110 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
111 unsigned int width = (vc->vc_font.width + 7) >> 3;
112 unsigned int cellsize = vc->vc_font.height * width;
113 unsigned int maxcnt = info->pixmap.size/cellsize;
114 unsigned int scan_align = info->pixmap.scan_align - 1;
115 unsigned int buf_align = info->pixmap.buf_align - 1;
116 unsigned int shift_low = 0, mod = vc->vc_font.width % 8;
117 unsigned int shift_high = 8, pitch, cnt, size, k;
118 unsigned int idx = vc->vc_font.width >> 3;
119 unsigned int attribute = get_attribute(info, scr_readw(s));
120 struct fb_image image;
121 u8 *src, *dst, *buf = NULL;
124 buf = kmalloc(cellsize, GFP_KERNEL);
132 image.dx = xx * vc->vc_font.width;
133 image.dy = yy * vc->vc_font.height;
134 image.height = vc->vc_font.height;
143 image.width = vc->vc_font.width * cnt;
144 pitch = ((image.width + 7) >> 3) + scan_align;
145 pitch &= ~scan_align;
146 size = pitch * image.height + buf_align;
148 dst = fb_get_buffer_offset(info, &info->pixmap, size);
152 src = vc->vc_font.data + (scr_readw(s++)&
156 update_attr(buf, src, attribute, vc);
160 fb_sysmove_buf_unaligned(info, &info->pixmap, dst, pitch,
161 src, idx, image.height,
162 shift_high, shift_low, mod);
164 dst += (shift_low >= 8) ? width : width - 1;
166 shift_high = 8 - shift_low;
170 src = vc->vc_font.data + (scr_readw(s++)&
174 update_attr(buf, src, attribute, vc);
178 fb_sysmove_buf_aligned(info, &info->pixmap, dst, pitch,
179 src, idx, image.height);
183 info->fbops->fb_imageblit(info, &image);
184 image.dx += cnt * vc->vc_font.width;
188 /* buf is always NULL except when in monochrome mode, so in this case
189 it's a gain to check buf against NULL even though kfree() handles
190 NULL pointers just fine */
195 static void bit_clear_margins(struct vc_data *vc, struct fb_info *info,
198 int bgshift = (vc->vc_hi_font_mask) ? 13 : 12;
199 unsigned int cw = vc->vc_font.width;
200 unsigned int ch = vc->vc_font.height;
201 unsigned int rw = info->var.xres - (vc->vc_cols*cw);
202 unsigned int bh = info->var.yres - (vc->vc_rows*ch);
203 unsigned int rs = info->var.xres - rw;
204 unsigned int bs = info->var.yres - bh;
205 struct fb_fillrect region;
207 region.color = attr_bgcol_ec(bgshift, vc);
208 region.rop = ROP_COPY;
210 if (rw && !bottom_only) {
211 region.dx = info->var.xoffset + rs;
214 region.height = info->var.yres_virtual;
215 info->fbops->fb_fillrect(info, ®ion);
219 region.dx = info->var.xoffset;
220 region.dy = info->var.yoffset + bs;
223 info->fbops->fb_fillrect(info, ®ion);
227 static void bit_cursor(struct vc_data *vc, struct fb_info *info,
228 struct display *p, int mode, int softback_lines, int fg, int bg)
230 struct fb_cursor cursor;
231 struct fbcon_ops *ops = (struct fbcon_ops *) info->fbcon_par;
232 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
233 int w = (vc->vc_font.width + 7) >> 3, c;
234 int y = real_y(p, vc->vc_y);
235 int attribute, use_sw = (vc->vc_cursor_type & 0x10);
240 if (softback_lines) {
241 if (y + softback_lines >= vc->vc_rows) {
243 ops->cursor_flash = 0;
249 c = scr_readw((u16 *) vc->vc_pos);
250 attribute = get_attribute(info, c);
251 src = vc->vc_font.data + ((c & charmask) * (w * vc->vc_font.height));
253 if (ops->cursor_state.image.data != src ||
255 ops->cursor_state.image.data = src;
256 cursor.set |= FB_CUR_SETIMAGE;
262 dst = kmalloc(w * vc->vc_font.height, GFP_ATOMIC);
265 kfree(ops->cursor_data);
266 ops->cursor_data = dst;
267 update_attr(dst, src, attribute, vc);
271 if (ops->cursor_state.image.fg_color != fg ||
272 ops->cursor_state.image.bg_color != bg ||
274 ops->cursor_state.image.fg_color = fg;
275 ops->cursor_state.image.bg_color = bg;
276 cursor.set |= FB_CUR_SETCMAP;
279 if ((ops->cursor_state.image.dx != (vc->vc_font.width * vc->vc_x)) ||
280 (ops->cursor_state.image.dy != (vc->vc_font.height * y)) ||
282 ops->cursor_state.image.dx = vc->vc_font.width * vc->vc_x;
283 ops->cursor_state.image.dy = vc->vc_font.height * y;
284 cursor.set |= FB_CUR_SETPOS;
287 if (ops->cursor_state.image.height != vc->vc_font.height ||
288 ops->cursor_state.image.width != vc->vc_font.width ||
290 ops->cursor_state.image.height = vc->vc_font.height;
291 ops->cursor_state.image.width = vc->vc_font.width;
292 cursor.set |= FB_CUR_SETSIZE;
295 if (ops->cursor_state.hot.x || ops->cursor_state.hot.y ||
297 ops->cursor_state.hot.x = cursor.hot.y = 0;
298 cursor.set |= FB_CUR_SETHOT;
301 if (cursor.set & FB_CUR_SETSIZE ||
302 vc->vc_cursor_type != p->cursor_shape ||
303 ops->cursor_state.mask == NULL ||
305 char *mask = kmalloc(w*vc->vc_font.height, GFP_ATOMIC);
306 int cur_height, size, i = 0;
312 kfree(ops->cursor_state.mask);
313 ops->cursor_state.mask = mask;
315 p->cursor_shape = vc->vc_cursor_type;
316 cursor.set |= FB_CUR_SETSHAPE;
318 switch (p->cursor_shape & CUR_HWMASK) {
323 cur_height = (vc->vc_font.height < 10) ? 1 : 2;
325 case CUR_LOWER_THIRD:
326 cur_height = vc->vc_font.height/3;
329 cur_height = vc->vc_font.height >> 1;
332 cur_height = (vc->vc_font.height << 1)/3;
336 cur_height = vc->vc_font.height;
339 size = (vc->vc_font.height - cur_height) * w;
342 size = cur_height * w;
349 ops->cursor_state.enable = 0;
354 ops->cursor_state.enable = (use_sw) ? 0 : 1;
358 cursor.image.data = src;
359 cursor.image.fg_color = ops->cursor_state.image.fg_color;
360 cursor.image.bg_color = ops->cursor_state.image.bg_color;
361 cursor.image.dx = ops->cursor_state.image.dx;
362 cursor.image.dy = ops->cursor_state.image.dy;
363 cursor.image.height = ops->cursor_state.image.height;
364 cursor.image.width = ops->cursor_state.image.width;
365 cursor.hot.x = ops->cursor_state.hot.x;
366 cursor.hot.y = ops->cursor_state.hot.y;
367 cursor.mask = ops->cursor_state.mask;
368 cursor.enable = ops->cursor_state.enable;
369 cursor.image.depth = 1;
370 cursor.rop = ROP_XOR;
372 info->fbops->fb_cursor(info, &cursor);
374 ops->cursor_reset = 0;
377 void fbcon_set_bitops(struct fbcon_ops *ops)
379 ops->bmove = bit_bmove;
380 ops->clear = bit_clear;
381 ops->putcs = bit_putcs;
382 ops->clear_margins = bit_clear_margins;
383 ops->cursor = bit_cursor;
386 EXPORT_SYMBOL(fbcon_set_bitops);
388 MODULE_AUTHOR("Antonino Daplas <adaplas@pol.net>");
389 MODULE_DESCRIPTION("Bit Blitting Operation");
390 MODULE_LICENSE("GPL");