Back to home page

OSCL-LXR

 
 

    


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