2 * linux/drivers/video/console/bitblit.c -- BitBlitting Operation
4 * Originally from the 'accel_*' routines in drivers/video/console/fbcon.c
6 * Copyright (C) 2004 Antonino Daplas <adaplas @pol.net>
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
13 #include <linux/config.h>
14 #include <linux/module.h>
15 #include <linux/string.h>
17 #include <linux/vt_kern.h>
18 #include <linux/console.h>
19 #include <asm/types.h>
23 * Accelerated handlers.
25 #define FBCON_ATTRIBUTE_UNDERLINE 1
26 #define FBCON_ATTRIBUTE_REVERSE 2
27 #define FBCON_ATTRIBUTE_BOLD 4
29 static inline int real_y(struct display
*p
, int ypos
)
34 return ypos
< rows
? ypos
: ypos
- rows
;
38 static inline int get_attribute(struct fb_info
*info
, u16 c
)
42 if (fb_get_color_depth(&info
->var
) == 1) {
43 if (attr_underline(c
))
44 attribute
|= FBCON_ATTRIBUTE_UNDERLINE
;
46 attribute
|= FBCON_ATTRIBUTE_REVERSE
;
48 attribute
|= FBCON_ATTRIBUTE_BOLD
;
54 static inline void update_attr(u8
*dst
, u8
*src
, int attribute
,
57 int i
, offset
= (vc
->vc_font
.height
< 10) ? 1 : 2;
58 int width
= (vc
->vc_font
.width
+ 7) >> 3;
59 unsigned int cellsize
= vc
->vc_font
.height
* width
;
62 offset
= cellsize
- (offset
* width
);
63 for (i
= 0; i
< cellsize
; i
++) {
65 if (attribute
& FBCON_ATTRIBUTE_UNDERLINE
&& i
>= offset
)
67 if (attribute
& FBCON_ATTRIBUTE_BOLD
)
69 if (attribute
& FBCON_ATTRIBUTE_REVERSE
)
75 static void bit_bmove(struct vc_data
*vc
, struct fb_info
*info
, int sy
,
76 int sx
, int dy
, int dx
, int height
, int width
)
78 struct fb_copyarea area
;
80 area
.sx
= sx
* vc
->vc_font
.width
;
81 area
.sy
= sy
* vc
->vc_font
.height
;
82 area
.dx
= dx
* vc
->vc_font
.width
;
83 area
.dy
= dy
* vc
->vc_font
.height
;
84 area
.height
= height
* vc
->vc_font
.height
;
85 area
.width
= width
* vc
->vc_font
.width
;
87 info
->fbops
->fb_copyarea(info
, &area
);
90 static void bit_clear(struct vc_data
*vc
, struct fb_info
*info
, int sy
,
91 int sx
, int height
, int width
)
93 int bgshift
= (vc
->vc_hi_font_mask
) ? 13 : 12;
94 struct fb_fillrect region
;
96 region
.color
= attr_bgcol_ec(bgshift
, vc
);
97 region
.dx
= sx
* vc
->vc_font
.width
;
98 region
.dy
= sy
* vc
->vc_font
.height
;
99 region
.width
= width
* vc
->vc_font
.width
;
100 region
.height
= height
* vc
->vc_font
.height
;
101 region
.rop
= ROP_COPY
;
103 info
->fbops
->fb_fillrect(info
, ®ion
);
106 static void bit_putcs(struct vc_data
*vc
, struct fb_info
*info
,
107 const unsigned short *s
, int count
, int yy
, int xx
,
110 unsigned short charmask
= vc
->vc_hi_font_mask
? 0x1ff : 0xff;
111 unsigned int width
= (vc
->vc_font
.width
+ 7) >> 3;
112 unsigned int cellsize
= vc
->vc_font
.height
* width
;
113 unsigned int maxcnt
= info
->pixmap
.size
/cellsize
;
114 unsigned int scan_align
= info
->pixmap
.scan_align
- 1;
115 unsigned int buf_align
= info
->pixmap
.buf_align
- 1;
116 unsigned int shift_low
= 0, mod
= vc
->vc_font
.width
% 8;
117 unsigned int shift_high
= 8, pitch
, cnt
, size
, k
;
118 unsigned int idx
= vc
->vc_font
.width
>> 3;
119 unsigned int attribute
= get_attribute(info
, scr_readw(s
));
120 struct fb_image image
;
121 u8
*src
, *dst
, *buf
= NULL
;
124 buf
= kmalloc(cellsize
, GFP_KERNEL
);
132 image
.dx
= xx
* vc
->vc_font
.width
;
133 image
.dy
= yy
* vc
->vc_font
.height
;
134 image
.height
= vc
->vc_font
.height
;
143 image
.width
= vc
->vc_font
.width
* cnt
;
144 pitch
= ((image
.width
+ 7) >> 3) + scan_align
;
145 pitch
&= ~scan_align
;
146 size
= pitch
* image
.height
+ buf_align
;
148 dst
= fb_get_buffer_offset(info
, &info
->pixmap
, size
);
152 src
= vc
->vc_font
.data
+ (scr_readw(s
++)&
156 update_attr(buf
, src
, attribute
, vc
);
160 fb_pad_unaligned_buffer(dst
, pitch
, src
, idx
,
161 image
.height
, shift_high
,
164 dst
+= (shift_low
>= 8) ? width
: width
- 1;
166 shift_high
= 8 - shift_low
;
170 src
= vc
->vc_font
.data
+ (scr_readw(s
++)&
174 update_attr(buf
, src
, attribute
, vc
);
178 fb_pad_aligned_buffer(dst
, pitch
, src
, idx
, image
.height
);
182 info
->fbops
->fb_imageblit(info
, &image
);
183 image
.dx
+= cnt
* vc
->vc_font
.width
;
187 /* buf is always NULL except when in monochrome mode, so in this case
188 it's a gain to check buf against NULL even though kfree() handles
189 NULL pointers just fine */
194 static void bit_clear_margins(struct vc_data
*vc
, struct fb_info
*info
,
197 int bgshift
= (vc
->vc_hi_font_mask
) ? 13 : 12;
198 unsigned int cw
= vc
->vc_font
.width
;
199 unsigned int ch
= vc
->vc_font
.height
;
200 unsigned int rw
= info
->var
.xres
- (vc
->vc_cols
*cw
);
201 unsigned int bh
= info
->var
.yres
- (vc
->vc_rows
*ch
);
202 unsigned int rs
= info
->var
.xres
- rw
;
203 unsigned int bs
= info
->var
.yres
- bh
;
204 struct fb_fillrect region
;
206 region
.color
= attr_bgcol_ec(bgshift
, vc
);
207 region
.rop
= ROP_COPY
;
209 if (rw
&& !bottom_only
) {
210 region
.dx
= info
->var
.xoffset
+ rs
;
213 region
.height
= info
->var
.yres_virtual
;
214 info
->fbops
->fb_fillrect(info
, ®ion
);
218 region
.dx
= info
->var
.xoffset
;
219 region
.dy
= info
->var
.yoffset
+ bs
;
222 info
->fbops
->fb_fillrect(info
, ®ion
);
226 static void bit_cursor(struct vc_data
*vc
, struct fb_info
*info
,
227 struct display
*p
, int mode
, int softback_lines
, int fg
, int bg
)
229 struct fb_cursor cursor
;
230 struct fbcon_ops
*ops
= (struct fbcon_ops
*) info
->fbcon_par
;
231 unsigned short charmask
= vc
->vc_hi_font_mask
? 0x1ff : 0xff;
232 int w
= (vc
->vc_font
.width
+ 7) >> 3, c
;
233 int y
= real_y(p
, vc
->vc_y
);
234 int attribute
, use_sw
= (vc
->vc_cursor_type
& 0x10);
239 if (softback_lines
) {
240 if (y
+ softback_lines
>= vc
->vc_rows
) {
242 ops
->cursor_flash
= 0;
248 c
= scr_readw((u16
*) vc
->vc_pos
);
249 attribute
= get_attribute(info
, c
);
250 src
= vc
->vc_font
.data
+ ((c
& charmask
) * (w
* vc
->vc_font
.height
));
252 if (ops
->cursor_state
.image
.data
!= src
||
254 ops
->cursor_state
.image
.data
= src
;
255 cursor
.set
|= FB_CUR_SETIMAGE
;
261 dst
= kmalloc(w
* vc
->vc_font
.height
, GFP_ATOMIC
);
264 kfree(ops
->cursor_data
);
265 ops
->cursor_data
= dst
;
266 update_attr(dst
, src
, attribute
, vc
);
270 if (ops
->cursor_state
.image
.fg_color
!= fg
||
271 ops
->cursor_state
.image
.bg_color
!= bg
||
273 ops
->cursor_state
.image
.fg_color
= fg
;
274 ops
->cursor_state
.image
.bg_color
= bg
;
275 cursor
.set
|= FB_CUR_SETCMAP
;
278 if ((ops
->cursor_state
.image
.dx
!= (vc
->vc_font
.width
* vc
->vc_x
)) ||
279 (ops
->cursor_state
.image
.dy
!= (vc
->vc_font
.height
* y
)) ||
281 ops
->cursor_state
.image
.dx
= vc
->vc_font
.width
* vc
->vc_x
;
282 ops
->cursor_state
.image
.dy
= vc
->vc_font
.height
* y
;
283 cursor
.set
|= FB_CUR_SETPOS
;
286 if (ops
->cursor_state
.image
.height
!= vc
->vc_font
.height
||
287 ops
->cursor_state
.image
.width
!= vc
->vc_font
.width
||
289 ops
->cursor_state
.image
.height
= vc
->vc_font
.height
;
290 ops
->cursor_state
.image
.width
= vc
->vc_font
.width
;
291 cursor
.set
|= FB_CUR_SETSIZE
;
294 if (ops
->cursor_state
.hot
.x
|| ops
->cursor_state
.hot
.y
||
296 ops
->cursor_state
.hot
.x
= cursor
.hot
.y
= 0;
297 cursor
.set
|= FB_CUR_SETHOT
;
300 if (cursor
.set
& FB_CUR_SETSIZE
||
301 vc
->vc_cursor_type
!= p
->cursor_shape
||
302 ops
->cursor_state
.mask
== NULL
||
304 char *mask
= kmalloc(w
*vc
->vc_font
.height
, GFP_ATOMIC
);
305 int cur_height
, size
, i
= 0;
311 kfree(ops
->cursor_state
.mask
);
312 ops
->cursor_state
.mask
= mask
;
314 p
->cursor_shape
= vc
->vc_cursor_type
;
315 cursor
.set
|= FB_CUR_SETSHAPE
;
317 switch (p
->cursor_shape
& CUR_HWMASK
) {
322 cur_height
= (vc
->vc_font
.height
< 10) ? 1 : 2;
324 case CUR_LOWER_THIRD
:
325 cur_height
= vc
->vc_font
.height
/3;
328 cur_height
= vc
->vc_font
.height
>> 1;
331 cur_height
= (vc
->vc_font
.height
<< 1)/3;
335 cur_height
= vc
->vc_font
.height
;
338 size
= (vc
->vc_font
.height
- cur_height
) * w
;
341 size
= cur_height
* w
;
348 ops
->cursor_state
.enable
= 0;
353 ops
->cursor_state
.enable
= (use_sw
) ? 0 : 1;
357 cursor
.image
.data
= src
;
358 cursor
.image
.fg_color
= ops
->cursor_state
.image
.fg_color
;
359 cursor
.image
.bg_color
= ops
->cursor_state
.image
.bg_color
;
360 cursor
.image
.dx
= ops
->cursor_state
.image
.dx
;
361 cursor
.image
.dy
= ops
->cursor_state
.image
.dy
;
362 cursor
.image
.height
= ops
->cursor_state
.image
.height
;
363 cursor
.image
.width
= ops
->cursor_state
.image
.width
;
364 cursor
.hot
.x
= ops
->cursor_state
.hot
.x
;
365 cursor
.hot
.y
= ops
->cursor_state
.hot
.y
;
366 cursor
.mask
= ops
->cursor_state
.mask
;
367 cursor
.enable
= ops
->cursor_state
.enable
;
368 cursor
.image
.depth
= 1;
369 cursor
.rop
= ROP_XOR
;
371 info
->fbops
->fb_cursor(info
, &cursor
);
373 ops
->cursor_reset
= 0;
376 void fbcon_set_bitops(struct fbcon_ops
*ops
)
378 ops
->bmove
= bit_bmove
;
379 ops
->clear
= bit_clear
;
380 ops
->putcs
= bit_putcs
;
381 ops
->clear_margins
= bit_clear_margins
;
382 ops
->cursor
= bit_cursor
;
385 EXPORT_SYMBOL(fbcon_set_bitops
);
387 MODULE_AUTHOR("Antonino Daplas <adaplas@pol.net>");
388 MODULE_DESCRIPTION("Bit Blitting Operation");
389 MODULE_LICENSE("GPL");