Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  *  linux/drivers/video/console/bitblit.c -- BitBlitting Operation
0003  *
0004  *  Originally from the 'accel_*' routines in drivers/video/console/fbcon.c
0005  *
0006  *      Copyright (C) 2004 Antonino Daplas <adaplas @pol.net>
0007  *
0008  *  This file is subject to the terms and conditions of the GNU General Public
0009  *  License.  See the file COPYING in the main directory of this archive for
0010  *  more details.
0011  */
0012 
0013 #include <linux/module.h>
0014 #include <linux/slab.h>
0015 #include <linux/string.h>
0016 #include <linux/fb.h>
0017 #include <linux/vt_kern.h>
0018 #include <linux/console.h>
0019 #include <asm/types.h>
0020 #include "fbcon.h"
0021 
0022 /*
0023  * Accelerated handlers.
0024  */
0025 static void update_attr(u8 *dst, u8 *src, int attribute,
0026                    struct vc_data *vc)
0027 {
0028     int i, offset = (vc->vc_font.height < 10) ? 1 : 2;
0029     int width = DIV_ROUND_UP(vc->vc_font.width, 8);
0030     unsigned int cellsize = vc->vc_font.height * width;
0031     u8 c;
0032 
0033     offset = cellsize - (offset * width);
0034     for (i = 0; i < cellsize; i++) {
0035         c = src[i];
0036         if (attribute & FBCON_ATTRIBUTE_UNDERLINE && i >= offset)
0037             c = 0xff;
0038         if (attribute & FBCON_ATTRIBUTE_BOLD)
0039             c |= c >> 1;
0040         if (attribute & FBCON_ATTRIBUTE_REVERSE)
0041             c = ~c;
0042         dst[i] = c;
0043     }
0044 }
0045 
0046 static void bit_bmove(struct vc_data *vc, struct fb_info *info, int sy,
0047               int sx, int dy, int dx, int height, int width)
0048 {
0049     struct fb_copyarea area;
0050 
0051     area.sx = sx * vc->vc_font.width;
0052     area.sy = sy * vc->vc_font.height;
0053     area.dx = dx * vc->vc_font.width;
0054     area.dy = dy * vc->vc_font.height;
0055     area.height = height * vc->vc_font.height;
0056     area.width = width * vc->vc_font.width;
0057 
0058     info->fbops->fb_copyarea(info, &area);
0059 }
0060 
0061 static void bit_clear(struct vc_data *vc, struct fb_info *info, int sy,
0062               int sx, int height, int width)
0063 {
0064     int bgshift = (vc->vc_hi_font_mask) ? 13 : 12;
0065     struct fb_fillrect region;
0066 
0067     region.color = attr_bgcol_ec(bgshift, vc, info);
0068     region.dx = sx * vc->vc_font.width;
0069     region.dy = sy * vc->vc_font.height;
0070     region.width = width * vc->vc_font.width;
0071     region.height = height * vc->vc_font.height;
0072     region.rop = ROP_COPY;
0073 
0074     info->fbops->fb_fillrect(info, &region);
0075 }
0076 
0077 static inline void bit_putcs_aligned(struct vc_data *vc, struct fb_info *info,
0078                      const u16 *s, u32 attr, u32 cnt,
0079                      u32 d_pitch, u32 s_pitch, u32 cellsize,
0080                      struct fb_image *image, u8 *buf, u8 *dst)
0081 {
0082     u16 charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
0083     u32 idx = vc->vc_font.width >> 3;
0084     u8 *src;
0085 
0086     while (cnt--) {
0087         src = vc->vc_font.data + (scr_readw(s++)&
0088                       charmask)*cellsize;
0089 
0090         if (attr) {
0091             update_attr(buf, src, attr, vc);
0092             src = buf;
0093         }
0094 
0095         if (likely(idx == 1))
0096             __fb_pad_aligned_buffer(dst, d_pitch, src, idx,
0097                         image->height);
0098         else
0099             fb_pad_aligned_buffer(dst, d_pitch, src, idx,
0100                           image->height);
0101 
0102         dst += s_pitch;
0103     }
0104 
0105     info->fbops->fb_imageblit(info, image);
0106 }
0107 
0108 static inline void bit_putcs_unaligned(struct vc_data *vc,
0109                        struct fb_info *info, const u16 *s,
0110                        u32 attr, u32 cnt, u32 d_pitch,
0111                        u32 s_pitch, u32 cellsize,
0112                        struct fb_image *image, u8 *buf,
0113                        u8 *dst)
0114 {
0115     u16 charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
0116     u32 shift_low = 0, mod = vc->vc_font.width % 8;
0117     u32 shift_high = 8;
0118     u32 idx = vc->vc_font.width >> 3;
0119     u8 *src;
0120 
0121     while (cnt--) {
0122         src = vc->vc_font.data + (scr_readw(s++)&
0123                       charmask)*cellsize;
0124 
0125         if (attr) {
0126             update_attr(buf, src, attr, vc);
0127             src = buf;
0128         }
0129 
0130         fb_pad_unaligned_buffer(dst, d_pitch, src, idx,
0131                     image->height, shift_high,
0132                     shift_low, mod);
0133         shift_low += mod;
0134         dst += (shift_low >= 8) ? s_pitch : s_pitch - 1;
0135         shift_low &= 7;
0136         shift_high = 8 - shift_low;
0137     }
0138 
0139     info->fbops->fb_imageblit(info, image);
0140 
0141 }
0142 
0143 static void bit_putcs(struct vc_data *vc, struct fb_info *info,
0144               const unsigned short *s, int count, int yy, int xx,
0145               int fg, int bg)
0146 {
0147     struct fb_image image;
0148     u32 width = DIV_ROUND_UP(vc->vc_font.width, 8);
0149     u32 cellsize = width * vc->vc_font.height;
0150     u32 maxcnt = info->pixmap.size/cellsize;
0151     u32 scan_align = info->pixmap.scan_align - 1;
0152     u32 buf_align = info->pixmap.buf_align - 1;
0153     u32 mod = vc->vc_font.width % 8, cnt, pitch, size;
0154     u32 attribute = get_attribute(info, scr_readw(s));
0155     u8 *dst, *buf = NULL;
0156 
0157     image.fg_color = fg;
0158     image.bg_color = bg;
0159     image.dx = xx * vc->vc_font.width;
0160     image.dy = yy * vc->vc_font.height;
0161     image.height = vc->vc_font.height;
0162     image.depth = 1;
0163 
0164     if (attribute) {
0165         buf = kmalloc(cellsize, GFP_ATOMIC);
0166         if (!buf)
0167             return;
0168     }
0169 
0170     while (count) {
0171         if (count > maxcnt)
0172             cnt = maxcnt;
0173         else
0174             cnt = count;
0175 
0176         image.width = vc->vc_font.width * cnt;
0177         pitch = DIV_ROUND_UP(image.width, 8) + scan_align;
0178         pitch &= ~scan_align;
0179         size = pitch * image.height + buf_align;
0180         size &= ~buf_align;
0181         dst = fb_get_buffer_offset(info, &info->pixmap, size);
0182         image.data = dst;
0183 
0184         if (!mod)
0185             bit_putcs_aligned(vc, info, s, attribute, cnt, pitch,
0186                       width, cellsize, &image, buf, dst);
0187         else
0188             bit_putcs_unaligned(vc, info, s, attribute, cnt,
0189                         pitch, width, cellsize, &image,
0190                         buf, dst);
0191 
0192         image.dx += cnt * vc->vc_font.width;
0193         count -= cnt;
0194         s += cnt;
0195     }
0196 
0197     /* buf is always NULL except when in monochrome mode, so in this case
0198        it's a gain to check buf against NULL even though kfree() handles
0199        NULL pointers just fine */
0200     if (unlikely(buf))
0201         kfree(buf);
0202 
0203 }
0204 
0205 static void bit_clear_margins(struct vc_data *vc, struct fb_info *info,
0206                   int color, int bottom_only)
0207 {
0208     unsigned int cw = vc->vc_font.width;
0209     unsigned int ch = vc->vc_font.height;
0210     unsigned int rw = info->var.xres - (vc->vc_cols*cw);
0211     unsigned int bh = info->var.yres - (vc->vc_rows*ch);
0212     unsigned int rs = info->var.xres - rw;
0213     unsigned int bs = info->var.yres - bh;
0214     struct fb_fillrect region;
0215 
0216     region.color = color;
0217     region.rop = ROP_COPY;
0218 
0219     if ((int) rw > 0 && !bottom_only) {
0220         region.dx = info->var.xoffset + rs;
0221         region.dy = 0;
0222         region.width = rw;
0223         region.height = info->var.yres_virtual;
0224         info->fbops->fb_fillrect(info, &region);
0225     }
0226 
0227     if ((int) bh > 0) {
0228         region.dx = info->var.xoffset;
0229         region.dy = info->var.yoffset + bs;
0230         region.width = rs;
0231         region.height = bh;
0232         info->fbops->fb_fillrect(info, &region);
0233     }
0234 }
0235 
0236 static void bit_cursor(struct vc_data *vc, struct fb_info *info, int mode,
0237                int fg, int bg)
0238 {
0239     struct fb_cursor cursor;
0240     struct fbcon_ops *ops = info->fbcon_par;
0241     unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
0242     int w = DIV_ROUND_UP(vc->vc_font.width, 8), c;
0243     int y = real_y(ops->p, vc->state.y);
0244     int attribute, use_sw = vc->vc_cursor_type & CUR_SW;
0245     int err = 1;
0246     char *src;
0247 
0248     cursor.set = 0;
0249 
0250     c = scr_readw((u16 *) vc->vc_pos);
0251     attribute = get_attribute(info, c);
0252     src = vc->vc_font.data + ((c & charmask) * (w * vc->vc_font.height));
0253 
0254     if (ops->cursor_state.image.data != src ||
0255         ops->cursor_reset) {
0256         ops->cursor_state.image.data = src;
0257         cursor.set |= FB_CUR_SETIMAGE;
0258     }
0259 
0260     if (attribute) {
0261         u8 *dst;
0262 
0263         dst = kmalloc_array(w, vc->vc_font.height, GFP_ATOMIC);
0264         if (!dst)
0265             return;
0266         kfree(ops->cursor_data);
0267         ops->cursor_data = dst;
0268         update_attr(dst, src, attribute, vc);
0269         src = dst;
0270     }
0271 
0272     if (ops->cursor_state.image.fg_color != fg ||
0273         ops->cursor_state.image.bg_color != bg ||
0274         ops->cursor_reset) {
0275         ops->cursor_state.image.fg_color = fg;
0276         ops->cursor_state.image.bg_color = bg;
0277         cursor.set |= FB_CUR_SETCMAP;
0278     }
0279 
0280     if ((ops->cursor_state.image.dx != (vc->vc_font.width * vc->state.x)) ||
0281         (ops->cursor_state.image.dy != (vc->vc_font.height * y)) ||
0282         ops->cursor_reset) {
0283         ops->cursor_state.image.dx = vc->vc_font.width * vc->state.x;
0284         ops->cursor_state.image.dy = vc->vc_font.height * y;
0285         cursor.set |= FB_CUR_SETPOS;
0286     }
0287 
0288     if (ops->cursor_state.image.height != vc->vc_font.height ||
0289         ops->cursor_state.image.width != vc->vc_font.width ||
0290         ops->cursor_reset) {
0291         ops->cursor_state.image.height = vc->vc_font.height;
0292         ops->cursor_state.image.width = vc->vc_font.width;
0293         cursor.set |= FB_CUR_SETSIZE;
0294     }
0295 
0296     if (ops->cursor_state.hot.x || ops->cursor_state.hot.y ||
0297         ops->cursor_reset) {
0298         ops->cursor_state.hot.x = cursor.hot.y = 0;
0299         cursor.set |= FB_CUR_SETHOT;
0300     }
0301 
0302     if (cursor.set & FB_CUR_SETSIZE ||
0303         vc->vc_cursor_type != ops->p->cursor_shape ||
0304         ops->cursor_state.mask == NULL ||
0305         ops->cursor_reset) {
0306         char *mask = kmalloc_array(w, vc->vc_font.height, GFP_ATOMIC);
0307         int cur_height, size, i = 0;
0308         u8 msk = 0xff;
0309 
0310         if (!mask)
0311             return;
0312 
0313         kfree(ops->cursor_state.mask);
0314         ops->cursor_state.mask = mask;
0315 
0316         ops->p->cursor_shape = vc->vc_cursor_type;
0317         cursor.set |= FB_CUR_SETSHAPE;
0318 
0319         switch (CUR_SIZE(ops->p->cursor_shape)) {
0320         case CUR_NONE:
0321             cur_height = 0;
0322             break;
0323         case CUR_UNDERLINE:
0324             cur_height = (vc->vc_font.height < 10) ? 1 : 2;
0325             break;
0326         case CUR_LOWER_THIRD:
0327             cur_height = vc->vc_font.height/3;
0328             break;
0329         case CUR_LOWER_HALF:
0330             cur_height = vc->vc_font.height >> 1;
0331             break;
0332         case CUR_TWO_THIRDS:
0333             cur_height = (vc->vc_font.height << 1)/3;
0334             break;
0335         case CUR_BLOCK:
0336         default:
0337             cur_height = vc->vc_font.height;
0338             break;
0339         }
0340         size = (vc->vc_font.height - cur_height) * w;
0341         while (size--)
0342             mask[i++] = ~msk;
0343         size = cur_height * w;
0344         while (size--)
0345             mask[i++] = msk;
0346     }
0347 
0348     switch (mode) {
0349     case CM_ERASE:
0350         ops->cursor_state.enable = 0;
0351         break;
0352     case CM_DRAW:
0353     case CM_MOVE:
0354     default:
0355         ops->cursor_state.enable = (use_sw) ? 0 : 1;
0356         break;
0357     }
0358 
0359     cursor.image.data = src;
0360     cursor.image.fg_color = ops->cursor_state.image.fg_color;
0361     cursor.image.bg_color = ops->cursor_state.image.bg_color;
0362     cursor.image.dx = ops->cursor_state.image.dx;
0363     cursor.image.dy = ops->cursor_state.image.dy;
0364     cursor.image.height = ops->cursor_state.image.height;
0365     cursor.image.width = ops->cursor_state.image.width;
0366     cursor.hot.x = ops->cursor_state.hot.x;
0367     cursor.hot.y = ops->cursor_state.hot.y;
0368     cursor.mask = ops->cursor_state.mask;
0369     cursor.enable = ops->cursor_state.enable;
0370     cursor.image.depth = 1;
0371     cursor.rop = ROP_XOR;
0372 
0373     if (info->fbops->fb_cursor)
0374         err = info->fbops->fb_cursor(info, &cursor);
0375 
0376     if (err)
0377         soft_cursor(info, &cursor);
0378 
0379     ops->cursor_reset = 0;
0380 }
0381 
0382 static int bit_update_start(struct fb_info *info)
0383 {
0384     struct fbcon_ops *ops = info->fbcon_par;
0385     int err;
0386 
0387     err = fb_pan_display(info, &ops->var);
0388     ops->var.xoffset = info->var.xoffset;
0389     ops->var.yoffset = info->var.yoffset;
0390     ops->var.vmode = info->var.vmode;
0391     return err;
0392 }
0393 
0394 void fbcon_set_bitops(struct fbcon_ops *ops)
0395 {
0396     ops->bmove = bit_bmove;
0397     ops->clear = bit_clear;
0398     ops->putcs = bit_putcs;
0399     ops->clear_margins = bit_clear_margins;
0400     ops->cursor = bit_cursor;
0401     ops->update_start = bit_update_start;
0402     ops->rotate_font = NULL;
0403 
0404     if (ops->rotate)
0405         fbcon_set_rotate(ops);
0406 }