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, &info->fix) == 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 inline void bit_putcs_aligned(struct vc_data *vc, struct fb_info *info,
107 const u16 *s, u32 attr, u32 cnt,
108 u32 d_pitch, u32 s_pitch, u32 cellsize,
109 struct fb_image *image, u8 *buf, u8 *dst)
111 u16 charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
112 u32 idx = vc->vc_font.width >> 3;
116 src = vc->vc_font.data + (scr_readw(s++)&
120 update_attr(buf, src, attr, vc);
124 if (likely(idx == 1))
125 __fb_pad_aligned_buffer(dst, d_pitch, src, idx,
128 fb_pad_aligned_buffer(dst, d_pitch, src, idx,
134 info->fbops->fb_imageblit(info, image);
137 static inline void bit_putcs_unaligned(struct vc_data *vc,
138 struct fb_info *info, const u16 *s,
139 u32 attr, u32 cnt, u32 d_pitch,
140 u32 s_pitch, u32 cellsize,
141 struct fb_image *image, u8 *buf,
144 u16 charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
145 u32 shift_low = 0, mod = vc->vc_font.width % 8;
147 u32 idx = vc->vc_font.width >> 3;
151 src = vc->vc_font.data + (scr_readw(s++)&
155 update_attr(buf, src, attr, vc);
159 fb_pad_unaligned_buffer(dst, d_pitch, src, idx,
160 image->height, shift_high,
163 dst += (shift_low >= 8) ? s_pitch : s_pitch - 1;
165 shift_high = 8 - shift_low;
168 info->fbops->fb_imageblit(info, image);
172 static void bit_putcs(struct vc_data *vc, struct fb_info *info,
173 const unsigned short *s, int count, int yy, int xx,
176 struct fb_image image;
177 u32 width = (vc->vc_font.width + 7)/8;
178 u32 cellsize = width * vc->vc_font.height;
179 u32 maxcnt = info->pixmap.size/cellsize;
180 u32 scan_align = info->pixmap.scan_align - 1;
181 u32 buf_align = info->pixmap.buf_align - 1;
182 u32 mod = vc->vc_font.width % 8, cnt, pitch, size;
183 u32 attribute = get_attribute(info, scr_readw(s));
184 u8 *dst, *buf = NULL;
188 image.dx = xx * vc->vc_font.width;
189 image.dy = yy * vc->vc_font.height;
190 image.height = vc->vc_font.height;
194 buf = kmalloc(cellsize, GFP_KERNEL);
205 image.width = vc->vc_font.width * cnt;
206 pitch = ((image.width + 7) >> 3) + scan_align;
207 pitch &= ~scan_align;
208 size = pitch * image.height + buf_align;
210 dst = fb_get_buffer_offset(info, &info->pixmap, size);
214 bit_putcs_aligned(vc, info, s, attribute, cnt, pitch,
215 width, cellsize, &image, buf, dst);
217 bit_putcs_unaligned(vc, info, s, attribute, cnt,
218 pitch, width, cellsize, &image,
221 image.dx += cnt * vc->vc_font.width;
226 /* buf is always NULL except when in monochrome mode, so in this case
227 it's a gain to check buf against NULL even though kfree() handles
228 NULL pointers just fine */
234 static void bit_clear_margins(struct vc_data *vc, struct fb_info *info,
237 int bgshift = (vc->vc_hi_font_mask) ? 13 : 12;
238 unsigned int cw = vc->vc_font.width;
239 unsigned int ch = vc->vc_font.height;
240 unsigned int rw = info->var.xres - (vc->vc_cols*cw);
241 unsigned int bh = info->var.yres - (vc->vc_rows*ch);
242 unsigned int rs = info->var.xres - rw;
243 unsigned int bs = info->var.yres - bh;
244 struct fb_fillrect region;
246 region.color = attr_bgcol_ec(bgshift, vc);
247 region.rop = ROP_COPY;
249 if (rw && !bottom_only) {
250 region.dx = info->var.xoffset + rs;
253 region.height = info->var.yres_virtual;
254 info->fbops->fb_fillrect(info, ®ion);
258 region.dx = info->var.xoffset;
259 region.dy = info->var.yoffset + bs;
262 info->fbops->fb_fillrect(info, ®ion);
266 static void bit_cursor(struct vc_data *vc, struct fb_info *info,
267 struct display *p, int mode, int softback_lines, int fg, int bg)
269 struct fb_cursor cursor;
270 struct fbcon_ops *ops = (struct fbcon_ops *) info->fbcon_par;
271 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
272 int w = (vc->vc_font.width + 7) >> 3, c;
273 int y = real_y(p, vc->vc_y);
274 int attribute, use_sw = (vc->vc_cursor_type & 0x10);
279 if (softback_lines) {
280 if (y + softback_lines >= vc->vc_rows) {
282 ops->cursor_flash = 0;
288 c = scr_readw((u16 *) vc->vc_pos);
289 attribute = get_attribute(info, c);
290 src = vc->vc_font.data + ((c & charmask) * (w * vc->vc_font.height));
292 if (ops->cursor_state.image.data != src ||
294 ops->cursor_state.image.data = src;
295 cursor.set |= FB_CUR_SETIMAGE;
301 dst = kmalloc(w * vc->vc_font.height, GFP_ATOMIC);
304 kfree(ops->cursor_data);
305 ops->cursor_data = dst;
306 update_attr(dst, src, attribute, vc);
310 if (ops->cursor_state.image.fg_color != fg ||
311 ops->cursor_state.image.bg_color != bg ||
313 ops->cursor_state.image.fg_color = fg;
314 ops->cursor_state.image.bg_color = bg;
315 cursor.set |= FB_CUR_SETCMAP;
318 if ((ops->cursor_state.image.dx != (vc->vc_font.width * vc->vc_x)) ||
319 (ops->cursor_state.image.dy != (vc->vc_font.height * y)) ||
321 ops->cursor_state.image.dx = vc->vc_font.width * vc->vc_x;
322 ops->cursor_state.image.dy = vc->vc_font.height * y;
323 cursor.set |= FB_CUR_SETPOS;
326 if (ops->cursor_state.image.height != vc->vc_font.height ||
327 ops->cursor_state.image.width != vc->vc_font.width ||
329 ops->cursor_state.image.height = vc->vc_font.height;
330 ops->cursor_state.image.width = vc->vc_font.width;
331 cursor.set |= FB_CUR_SETSIZE;
334 if (ops->cursor_state.hot.x || ops->cursor_state.hot.y ||
336 ops->cursor_state.hot.x = cursor.hot.y = 0;
337 cursor.set |= FB_CUR_SETHOT;
340 if (cursor.set & FB_CUR_SETSIZE ||
341 vc->vc_cursor_type != p->cursor_shape ||
342 ops->cursor_state.mask == NULL ||
344 char *mask = kmalloc(w*vc->vc_font.height, GFP_ATOMIC);
345 int cur_height, size, i = 0;
351 kfree(ops->cursor_state.mask);
352 ops->cursor_state.mask = mask;
354 p->cursor_shape = vc->vc_cursor_type;
355 cursor.set |= FB_CUR_SETSHAPE;
357 switch (p->cursor_shape & CUR_HWMASK) {
362 cur_height = (vc->vc_font.height < 10) ? 1 : 2;
364 case CUR_LOWER_THIRD:
365 cur_height = vc->vc_font.height/3;
368 cur_height = vc->vc_font.height >> 1;
371 cur_height = (vc->vc_font.height << 1)/3;
375 cur_height = vc->vc_font.height;
378 size = (vc->vc_font.height - cur_height) * w;
381 size = cur_height * w;
388 ops->cursor_state.enable = 0;
393 ops->cursor_state.enable = (use_sw) ? 0 : 1;
397 cursor.image.data = src;
398 cursor.image.fg_color = ops->cursor_state.image.fg_color;
399 cursor.image.bg_color = ops->cursor_state.image.bg_color;
400 cursor.image.dx = ops->cursor_state.image.dx;
401 cursor.image.dy = ops->cursor_state.image.dy;
402 cursor.image.height = ops->cursor_state.image.height;
403 cursor.image.width = ops->cursor_state.image.width;
404 cursor.hot.x = ops->cursor_state.hot.x;
405 cursor.hot.y = ops->cursor_state.hot.y;
406 cursor.mask = ops->cursor_state.mask;
407 cursor.enable = ops->cursor_state.enable;
408 cursor.image.depth = 1;
409 cursor.rop = ROP_XOR;
411 info->fbops->fb_cursor(info, &cursor);
413 ops->cursor_reset = 0;
416 void fbcon_set_bitops(struct fbcon_ops *ops)
418 ops->bmove = bit_bmove;
419 ops->clear = bit_clear;
420 ops->putcs = bit_putcs;
421 ops->clear_margins = bit_clear_margins;
422 ops->cursor = bit_cursor;
425 EXPORT_SYMBOL(fbcon_set_bitops);
427 MODULE_AUTHOR("Antonino Daplas <adaplas@pol.net>");
428 MODULE_DESCRIPTION("Bit Blitting Operation");
429 MODULE_LICENSE("GPL");