fbcon_ccw.c 11 KB

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