bitblit.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. /*
  2. * linux/drivers/video/console/bitblit.c -- BitBlitting Operation
  3. *
  4. * Originally from the 'accel_*' routines in drivers/video/console/fbcon.c
  5. *
  6. * Copyright (C) 2004 Antonino Daplas <adaplas @pol.net>
  7. *
  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
  10. * more details.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/string.h>
  14. #include <linux/fb.h>
  15. #include <linux/vt_kern.h>
  16. #include <linux/console.h>
  17. #include <asm/types.h>
  18. #include "fbcon.h"
  19. /*
  20. * Accelerated handlers.
  21. */
  22. static inline void update_attr(u8 *dst, u8 *src, int attribute,
  23. struct vc_data *vc)
  24. {
  25. int i, offset = (vc->vc_font.height < 10) ? 1 : 2;
  26. int width = (vc->vc_font.width + 7) >> 3;
  27. unsigned int cellsize = vc->vc_font.height * width;
  28. u8 c;
  29. offset = cellsize - (offset * width);
  30. for (i = 0; i < cellsize; i++) {
  31. c = src[i];
  32. if (attribute & FBCON_ATTRIBUTE_UNDERLINE && i >= offset)
  33. c = 0xff;
  34. if (attribute & FBCON_ATTRIBUTE_BOLD)
  35. c |= c >> 1;
  36. if (attribute & FBCON_ATTRIBUTE_REVERSE)
  37. c = ~c;
  38. dst[i] = c;
  39. }
  40. }
  41. static void bit_bmove(struct vc_data *vc, struct fb_info *info, int sy,
  42. int sx, int dy, int dx, int height, int width)
  43. {
  44. struct fb_copyarea area;
  45. area.sx = sx * vc->vc_font.width;
  46. area.sy = sy * vc->vc_font.height;
  47. area.dx = dx * vc->vc_font.width;
  48. area.dy = dy * vc->vc_font.height;
  49. area.height = height * vc->vc_font.height;
  50. area.width = width * vc->vc_font.width;
  51. info->fbops->fb_copyarea(info, &area);
  52. }
  53. static void bit_clear(struct vc_data *vc, struct fb_info *info, int sy,
  54. int sx, int height, int width)
  55. {
  56. int bgshift = (vc->vc_hi_font_mask) ? 13 : 12;
  57. struct fb_fillrect region;
  58. region.color = attr_bgcol_ec(bgshift, vc, info);
  59. region.dx = sx * vc->vc_font.width;
  60. region.dy = sy * vc->vc_font.height;
  61. region.width = width * vc->vc_font.width;
  62. region.height = height * vc->vc_font.height;
  63. region.rop = ROP_COPY;
  64. info->fbops->fb_fillrect(info, &region);
  65. }
  66. static inline void bit_putcs_aligned(struct vc_data *vc, struct fb_info *info,
  67. const u16 *s, u32 attr, u32 cnt,
  68. u32 d_pitch, u32 s_pitch, u32 cellsize,
  69. struct fb_image *image, u8 *buf, u8 *dst)
  70. {
  71. u16 charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
  72. u32 idx = vc->vc_font.width >> 3;
  73. u8 *src;
  74. while (cnt--) {
  75. src = vc->vc_font.data + (scr_readw(s++)&
  76. charmask)*cellsize;
  77. if (attr) {
  78. update_attr(buf, src, attr, vc);
  79. src = buf;
  80. }
  81. if (likely(idx == 1))
  82. __fb_pad_aligned_buffer(dst, d_pitch, src, idx,
  83. image->height);
  84. else
  85. fb_pad_aligned_buffer(dst, d_pitch, src, idx,
  86. image->height);
  87. dst += s_pitch;
  88. }
  89. info->fbops->fb_imageblit(info, image);
  90. }
  91. static inline void bit_putcs_unaligned(struct vc_data *vc,
  92. struct fb_info *info, const u16 *s,
  93. u32 attr, u32 cnt, u32 d_pitch,
  94. u32 s_pitch, u32 cellsize,
  95. struct fb_image *image, u8 *buf,
  96. u8 *dst)
  97. {
  98. u16 charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
  99. u32 shift_low = 0, mod = vc->vc_font.width % 8;
  100. u32 shift_high = 8;
  101. u32 idx = vc->vc_font.width >> 3;
  102. u8 *src;
  103. while (cnt--) {
  104. src = vc->vc_font.data + (scr_readw(s++)&
  105. charmask)*cellsize;
  106. if (attr) {
  107. update_attr(buf, src, attr, vc);
  108. src = buf;
  109. }
  110. fb_pad_unaligned_buffer(dst, d_pitch, src, idx,
  111. image->height, shift_high,
  112. shift_low, mod);
  113. shift_low += mod;
  114. dst += (shift_low >= 8) ? s_pitch : s_pitch - 1;
  115. shift_low &= 7;
  116. shift_high = 8 - shift_low;
  117. }
  118. info->fbops->fb_imageblit(info, image);
  119. }
  120. static void bit_putcs(struct vc_data *vc, struct fb_info *info,
  121. const unsigned short *s, int count, int yy, int xx,
  122. int fg, int bg)
  123. {
  124. struct fb_image image;
  125. u32 width = (vc->vc_font.width + 7)/8;
  126. u32 cellsize = width * vc->vc_font.height;
  127. u32 maxcnt = info->pixmap.size/cellsize;
  128. u32 scan_align = info->pixmap.scan_align - 1;
  129. u32 buf_align = info->pixmap.buf_align - 1;
  130. u32 mod = vc->vc_font.width % 8, cnt, pitch, size;
  131. u32 attribute = get_attribute(info, scr_readw(s));
  132. u8 *dst, *buf = NULL;
  133. image.fg_color = fg;
  134. image.bg_color = bg;
  135. image.dx = xx * vc->vc_font.width;
  136. image.dy = yy * vc->vc_font.height;
  137. image.height = vc->vc_font.height;
  138. image.depth = 1;
  139. if (attribute) {
  140. buf = kmalloc(cellsize, GFP_KERNEL);
  141. if (!buf)
  142. return;
  143. }
  144. while (count) {
  145. if (count > maxcnt)
  146. cnt = maxcnt;
  147. else
  148. cnt = count;
  149. image.width = vc->vc_font.width * cnt;
  150. pitch = ((image.width + 7) >> 3) + scan_align;
  151. pitch &= ~scan_align;
  152. size = pitch * image.height + buf_align;
  153. size &= ~buf_align;
  154. dst = fb_get_buffer_offset(info, &info->pixmap, size);
  155. image.data = dst;
  156. if (!mod)
  157. bit_putcs_aligned(vc, info, s, attribute, cnt, pitch,
  158. width, cellsize, &image, buf, dst);
  159. else
  160. bit_putcs_unaligned(vc, info, s, attribute, cnt,
  161. pitch, width, cellsize, &image,
  162. buf, dst);
  163. image.dx += cnt * vc->vc_font.width;
  164. count -= cnt;
  165. s += cnt;
  166. }
  167. /* buf is always NULL except when in monochrome mode, so in this case
  168. it's a gain to check buf against NULL even though kfree() handles
  169. NULL pointers just fine */
  170. if (unlikely(buf))
  171. kfree(buf);
  172. }
  173. static void bit_clear_margins(struct vc_data *vc, struct fb_info *info,
  174. int bottom_only)
  175. {
  176. int bgshift = (vc->vc_hi_font_mask) ? 13 : 12;
  177. unsigned int cw = vc->vc_font.width;
  178. unsigned int ch = vc->vc_font.height;
  179. unsigned int rw = info->var.xres - (vc->vc_cols*cw);
  180. unsigned int bh = info->var.yres - (vc->vc_rows*ch);
  181. unsigned int rs = info->var.xres - rw;
  182. unsigned int bs = info->var.yres - bh;
  183. struct fb_fillrect region;
  184. region.color = attr_bgcol_ec(bgshift, vc, info);
  185. region.rop = ROP_COPY;
  186. if (rw && !bottom_only) {
  187. region.dx = info->var.xoffset + rs;
  188. region.dy = 0;
  189. region.width = rw;
  190. region.height = info->var.yres_virtual;
  191. info->fbops->fb_fillrect(info, &region);
  192. }
  193. if (bh) {
  194. region.dx = info->var.xoffset;
  195. region.dy = info->var.yoffset + bs;
  196. region.width = rs;
  197. region.height = bh;
  198. info->fbops->fb_fillrect(info, &region);
  199. }
  200. }
  201. static void bit_cursor(struct vc_data *vc, struct fb_info *info, int mode,
  202. int softback_lines, int fg, int bg)
  203. {
  204. struct fb_cursor cursor;
  205. struct fbcon_ops *ops = info->fbcon_par;
  206. unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
  207. int w = (vc->vc_font.width + 7) >> 3, c;
  208. int y = real_y(ops->p, vc->vc_y);
  209. int attribute, use_sw = (vc->vc_cursor_type & 0x10);
  210. int err = 1;
  211. char *src;
  212. cursor.set = 0;
  213. if (softback_lines) {
  214. if (y + softback_lines >= vc->vc_rows) {
  215. mode = CM_ERASE;
  216. ops->cursor_flash = 0;
  217. return;
  218. } else
  219. y += softback_lines;
  220. }
  221. c = scr_readw((u16 *) vc->vc_pos);
  222. attribute = get_attribute(info, c);
  223. src = vc->vc_font.data + ((c & charmask) * (w * vc->vc_font.height));
  224. if (ops->cursor_state.image.data != src ||
  225. ops->cursor_reset) {
  226. ops->cursor_state.image.data = src;
  227. cursor.set |= FB_CUR_SETIMAGE;
  228. }
  229. if (attribute) {
  230. u8 *dst;
  231. dst = kmalloc(w * vc->vc_font.height, GFP_ATOMIC);
  232. if (!dst)
  233. return;
  234. kfree(ops->cursor_data);
  235. ops->cursor_data = dst;
  236. update_attr(dst, src, attribute, vc);
  237. src = dst;
  238. }
  239. if (ops->cursor_state.image.fg_color != fg ||
  240. ops->cursor_state.image.bg_color != bg ||
  241. ops->cursor_reset) {
  242. ops->cursor_state.image.fg_color = fg;
  243. ops->cursor_state.image.bg_color = bg;
  244. cursor.set |= FB_CUR_SETCMAP;
  245. }
  246. if ((ops->cursor_state.image.dx != (vc->vc_font.width * vc->vc_x)) ||
  247. (ops->cursor_state.image.dy != (vc->vc_font.height * y)) ||
  248. ops->cursor_reset) {
  249. ops->cursor_state.image.dx = vc->vc_font.width * vc->vc_x;
  250. ops->cursor_state.image.dy = vc->vc_font.height * y;
  251. cursor.set |= FB_CUR_SETPOS;
  252. }
  253. if (ops->cursor_state.image.height != vc->vc_font.height ||
  254. ops->cursor_state.image.width != vc->vc_font.width ||
  255. ops->cursor_reset) {
  256. ops->cursor_state.image.height = vc->vc_font.height;
  257. ops->cursor_state.image.width = vc->vc_font.width;
  258. cursor.set |= FB_CUR_SETSIZE;
  259. }
  260. if (ops->cursor_state.hot.x || ops->cursor_state.hot.y ||
  261. ops->cursor_reset) {
  262. ops->cursor_state.hot.x = cursor.hot.y = 0;
  263. cursor.set |= FB_CUR_SETHOT;
  264. }
  265. if (cursor.set & FB_CUR_SETSIZE ||
  266. vc->vc_cursor_type != ops->p->cursor_shape ||
  267. ops->cursor_state.mask == NULL ||
  268. ops->cursor_reset) {
  269. char *mask = kmalloc(w*vc->vc_font.height, GFP_ATOMIC);
  270. int cur_height, size, i = 0;
  271. u8 msk = 0xff;
  272. if (!mask)
  273. return;
  274. kfree(ops->cursor_state.mask);
  275. ops->cursor_state.mask = mask;
  276. ops->p->cursor_shape = vc->vc_cursor_type;
  277. cursor.set |= FB_CUR_SETSHAPE;
  278. switch (ops->p->cursor_shape & CUR_HWMASK) {
  279. case CUR_NONE:
  280. cur_height = 0;
  281. break;
  282. case CUR_UNDERLINE:
  283. cur_height = (vc->vc_font.height < 10) ? 1 : 2;
  284. break;
  285. case CUR_LOWER_THIRD:
  286. cur_height = vc->vc_font.height/3;
  287. break;
  288. case CUR_LOWER_HALF:
  289. cur_height = vc->vc_font.height >> 1;
  290. break;
  291. case CUR_TWO_THIRDS:
  292. cur_height = (vc->vc_font.height << 1)/3;
  293. break;
  294. case CUR_BLOCK:
  295. default:
  296. cur_height = vc->vc_font.height;
  297. break;
  298. }
  299. size = (vc->vc_font.height - cur_height) * w;
  300. while (size--)
  301. mask[i++] = ~msk;
  302. size = cur_height * w;
  303. while (size--)
  304. mask[i++] = msk;
  305. }
  306. switch (mode) {
  307. case CM_ERASE:
  308. ops->cursor_state.enable = 0;
  309. break;
  310. case CM_DRAW:
  311. case CM_MOVE:
  312. default:
  313. ops->cursor_state.enable = (use_sw) ? 0 : 1;
  314. break;
  315. }
  316. cursor.image.data = src;
  317. cursor.image.fg_color = ops->cursor_state.image.fg_color;
  318. cursor.image.bg_color = ops->cursor_state.image.bg_color;
  319. cursor.image.dx = ops->cursor_state.image.dx;
  320. cursor.image.dy = ops->cursor_state.image.dy;
  321. cursor.image.height = ops->cursor_state.image.height;
  322. cursor.image.width = ops->cursor_state.image.width;
  323. cursor.hot.x = ops->cursor_state.hot.x;
  324. cursor.hot.y = ops->cursor_state.hot.y;
  325. cursor.mask = ops->cursor_state.mask;
  326. cursor.enable = ops->cursor_state.enable;
  327. cursor.image.depth = 1;
  328. cursor.rop = ROP_XOR;
  329. if (info->fbops->fb_cursor)
  330. err = info->fbops->fb_cursor(info, &cursor);
  331. if (err)
  332. soft_cursor(info, &cursor);
  333. ops->cursor_reset = 0;
  334. }
  335. static int bit_update_start(struct fb_info *info)
  336. {
  337. struct fbcon_ops *ops = info->fbcon_par;
  338. int err;
  339. err = fb_pan_display(info, &ops->var);
  340. ops->var.xoffset = info->var.xoffset;
  341. ops->var.yoffset = info->var.yoffset;
  342. ops->var.vmode = info->var.vmode;
  343. return err;
  344. }
  345. void fbcon_set_bitops(struct fbcon_ops *ops)
  346. {
  347. ops->bmove = bit_bmove;
  348. ops->clear = bit_clear;
  349. ops->putcs = bit_putcs;
  350. ops->clear_margins = bit_clear_margins;
  351. ops->cursor = bit_cursor;
  352. ops->update_start = bit_update_start;
  353. ops->rotate_font = NULL;
  354. if (ops->rotate)
  355. fbcon_set_rotate(ops);
  356. }
  357. EXPORT_SYMBOL(fbcon_set_bitops);
  358. MODULE_AUTHOR("Antonino Daplas <adaplas@pol.net>");
  359. MODULE_DESCRIPTION("Bit Blitting Operation");
  360. MODULE_LICENSE("GPL");