fbcon-cfb2.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:5k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  *  linux/drivers/video/cfb2.c -- Low level frame buffer operations for 2 bpp
  3.  *   packed pixels
  4.  *
  5.  * Created 26 Dec 1997 by Michael Schmitz
  6.  * Based on cfb4.c
  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/tty.h>
  14. #include <linux/console.h>
  15. #include <linux/string.h>
  16. #include <linux/fb.h>
  17. #include <video/fbcon.h>
  18. #include <video/fbcon-cfb2.h>
  19.     /*
  20.      *  2 bpp packed pixels
  21.      */
  22.     /*
  23.      *  IFF the font is even pixel aligned (that is to say each
  24.      *  character start is a byte start in the pixel pairs). That
  25.      *  avoids us having to mask bytes and means we won't be here
  26.      *  all week. On a MacII that matters _lots_
  27.      */
  28. static u_char nibbletab_cfb2[]={
  29. #if defined(__BIG_ENDIAN)
  30. 0x00,0x03,0x0c,0x0f,
  31. 0x30,0x33,0x3c,0x3f,
  32. 0xc0,0xc3,0xcc,0xcf,
  33. 0xf0,0xf3,0xfc,0xff
  34. #elif defined(__LITTLE_ENDIAN)
  35. 0x00,0xc0,0x30,0xf0,
  36. 0x0c,0xcc,0x3c,0xfc,
  37. 0x03,0xc3,0x33,0xf3,
  38. 0x0f,0xcf,0x3f,0xff
  39. #else
  40. #error FIXME: No endianness??
  41. #endif
  42. };
  43.  
  44. void fbcon_cfb2_setup(struct display *p)
  45. {
  46.     p->next_line = p->line_length ? p->line_length : p->var.xres_virtual>>2;
  47.     p->next_plane = 0;
  48. }
  49. void fbcon_cfb2_bmove(struct display *p, int sy, int sx, int dy, int dx,
  50.       int height, int width)
  51. {
  52. int bytes = p->next_line, linesize = bytes * fontheight(p), rows;
  53. u8 *src,*dst;
  54. if (sx == 0 && dx == 0 && width * 2 == bytes) {
  55. fb_memmove(p->screen_base + dy * linesize,
  56.   p->screen_base + sy * linesize,
  57.   height * linesize);
  58. }
  59. else {
  60. if (dy < sy || (dy == sy && dx < sx)) {
  61. src = p->screen_base + sy * linesize + sx * 2;
  62. dst = p->screen_base + dy * linesize + dx * 2;
  63. for (rows = height * fontheight(p) ; rows-- ;) {
  64. fb_memmove(dst, src, width * 2);
  65. src += bytes;
  66. dst += bytes;
  67. }
  68. }
  69. else {
  70. src = p->screen_base + (sy+height) * linesize + sx * 2
  71. - bytes;
  72. dst = p->screen_base + (dy+height) * linesize + dx * 2
  73. - bytes;
  74. for (rows = height * fontheight(p) ; rows-- ;) {
  75. fb_memmove(dst, src, width * 2);
  76. src -= bytes;
  77. dst -= bytes;
  78. }
  79. }
  80. }
  81. }
  82. void fbcon_cfb2_clear(struct vc_data *conp, struct display *p, int sy, int sx,
  83.       int height, int width)
  84. {
  85. u8 *dest0,*dest;
  86. int bytes=p->next_line,lines=height * fontheight(p), rows, i;
  87. u32 bgx;
  88. dest = p->screen_base + sy * fontheight(p) * bytes + sx * 2;
  89. bgx=attr_bgcol_ec(p,conp);
  90. bgx |= (bgx << 2); /* expand the colour to 16 bits */
  91. bgx |= (bgx << 4);
  92. bgx |= (bgx << 8);
  93. if (sx == 0 && width * 2 == bytes) {
  94. for (i = 0 ; i < lines * width ; i++) {
  95. fb_writew (bgx, dest);
  96. dest+=2;
  97. }
  98. } else {
  99. dest0=dest;
  100. for (rows = lines; rows-- ; dest0 += bytes) {
  101. dest=dest0;
  102. for (i = 0 ; i < width ; i++) {
  103. /* memset ?? */
  104. fb_writew (bgx, dest);
  105. dest+=2;
  106. }
  107. }
  108. }
  109. }
  110. void fbcon_cfb2_putc(struct vc_data *conp, struct display *p, int c, int yy,
  111.      int xx)
  112. {
  113. u8 *dest,*cdat;
  114. int bytes=p->next_line,rows;
  115. u32 eorx,fgx,bgx;
  116. dest = p->screen_base + yy * fontheight(p) * bytes + xx * 2;
  117. cdat = p->fontdata + (c & p->charmask) * fontheight(p);
  118. fgx=3;/*attr_fgcol(p,c);*/
  119. bgx=attr_bgcol(p,c);
  120. fgx |= (fgx << 2); /* expand color to 8 bits */
  121. fgx |= (fgx << 4);
  122. bgx |= (bgx << 2);
  123. bgx |= (bgx << 4);
  124. eorx = fgx ^ bgx;
  125. for (rows = fontheight(p) ; rows-- ; dest += bytes) {
  126. fb_writeb((nibbletab_cfb2[*cdat >> 4] & eorx) ^ bgx, dest+0);
  127. fb_writeb((nibbletab_cfb2[*cdat++ & 0xf] & eorx) ^ bgx, dest+1);
  128. }
  129. }
  130. void fbcon_cfb2_putcs(struct vc_data *conp, struct display *p, const unsigned short *s,
  131.       int count, int yy, int xx)
  132. {
  133. u8 *cdat, *dest, *dest0;
  134. u16 c;
  135. int rows,bytes=p->next_line;
  136. u32 eorx, fgx, bgx;
  137. dest0 = p->screen_base + yy * fontheight(p) * bytes + xx * 2;
  138. c = scr_readw(s);
  139. fgx = 3/*attr_fgcol(p, c)*/;
  140. bgx = attr_bgcol(p, c);
  141. fgx |= (fgx << 2);
  142. fgx |= (fgx << 4);
  143. bgx |= (bgx << 2);
  144. bgx |= (bgx << 4);
  145. eorx = fgx ^ bgx;
  146. while (count--) {
  147. c = scr_readw(s++) & p->charmask;
  148. cdat = p->fontdata + c * fontheight(p);
  149. for (rows = fontheight(p), dest = dest0; rows-- ; dest += bytes) {
  150. fb_writeb((nibbletab_cfb2[*cdat >> 4] & eorx) ^ bgx, dest+0);
  151. fb_writeb((nibbletab_cfb2[*cdat++ & 0xf] & eorx) ^ bgx, dest+1);
  152. }
  153. dest0+=2;
  154. }
  155. }
  156. void fbcon_cfb2_revc(struct display *p, int xx, int yy)
  157. {
  158. u8 *dest;
  159. int bytes=p->next_line, rows;
  160. dest = p->screen_base + yy * fontheight(p) * bytes + xx * 2;
  161. for (rows = fontheight(p) ; rows-- ; dest += bytes) {
  162. fb_writew(fb_readw(dest) ^ 0xffff, dest);
  163. }
  164. }
  165.     /*
  166.      *  `switch' for the low level operations
  167.      */
  168. struct display_switch fbcon_cfb2 = {
  169.     setup: fbcon_cfb2_setup,
  170.     bmove: fbcon_cfb2_bmove,
  171.     clear: fbcon_cfb2_clear,
  172.     putc: fbcon_cfb2_putc,
  173.     putcs: fbcon_cfb2_putcs,
  174.     revc: fbcon_cfb2_revc,
  175.     fontwidthmask: FONTWIDTH(8)
  176. };
  177. #ifdef MODULE
  178. MODULE_LICENSE("GPL");
  179. int init_module(void)
  180. {
  181.     return 0;
  182. }
  183. void cleanup_module(void)
  184. {}
  185. #endif /* MODULE */
  186.     /*
  187.      *  Visible symbols for modules
  188.      */
  189. EXPORT_SYMBOL(fbcon_cfb2);
  190. EXPORT_SYMBOL(fbcon_cfb2_setup);
  191. EXPORT_SYMBOL(fbcon_cfb2_bmove);
  192. EXPORT_SYMBOL(fbcon_cfb2_clear);
  193. EXPORT_SYMBOL(fbcon_cfb2_putc);
  194. EXPORT_SYMBOL(fbcon_cfb2_putcs);
  195. EXPORT_SYMBOL(fbcon_cfb2_revc);