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/module.h>
14 #include <linux/slab.h>
15 #include <linux/string.h>
17 #include <linux/vt_kern.h>
18 #include <linux/console.h>
19 #include <asm/types.h>
21 #include "fbcondecor.h"
24 * Accelerated handlers.
26 static void update_attr(u8
*dst
, u8
*src
, int attribute
,
29 int i
, offset
= (vc
->vc_font
.height
< 10) ? 1 : 2;
30 int width
= DIV_ROUND_UP(vc
->vc_font
.width
, 8);
31 unsigned int cellsize
= vc
->vc_font
.height
* width
;
34 offset
= cellsize
- (offset
* width
);
35 for (i
= 0; i
< cellsize
; i
++) {
37 if (attribute
& FBCON_ATTRIBUTE_UNDERLINE
&& i
>= offset
)
39 if (attribute
& FBCON_ATTRIBUTE_BOLD
)
41 if (attribute
& FBCON_ATTRIBUTE_REVERSE
)
47 static void bit_bmove(struct vc_data
*vc
, struct fb_info
*info
, int sy
,
48 int sx
, int dy
, int dx
, int height
, int width
)
50 struct fb_copyarea area
;
52 area
.sx
= sx
* vc
->vc_font
.width
;
53 area
.sy
= sy
* vc
->vc_font
.height
;
54 area
.dx
= dx
* vc
->vc_font
.width
;
55 area
.dy
= dy
* vc
->vc_font
.height
;
56 area
.height
= height
* vc
->vc_font
.height
;
57 area
.width
= width
* vc
->vc_font
.width
;
59 if (fbcon_decor_active(info
, vc
)) {
60 area
.sx
+= vc
->vc_decor
.tx
;
61 area
.sy
+= vc
->vc_decor
.ty
;
62 area
.dx
+= vc
->vc_decor
.tx
;
63 area
.dy
+= vc
->vc_decor
.ty
;
66 info
->fbops
->fb_copyarea(info
, &area
);
69 static void bit_clear(struct vc_data
*vc
, struct fb_info
*info
, int sy
,
70 int sx
, int height
, int width
)
72 int bgshift
= (vc
->vc_hi_font_mask
) ? 13 : 12;
73 struct fb_fillrect region
;
75 region
.color
= attr_bgcol_ec(bgshift
, vc
, info
);
76 region
.dx
= sx
* vc
->vc_font
.width
;
77 region
.dy
= sy
* vc
->vc_font
.height
;
78 region
.width
= width
* vc
->vc_font
.width
;
79 region
.height
= height
* vc
->vc_font
.height
;
80 region
.rop
= ROP_COPY
;
82 info
->fbops
->fb_fillrect(info
, ®ion
);
85 static inline void bit_putcs_aligned(struct vc_data
*vc
, struct fb_info
*info
,
86 const u16
*s
, u32 attr
, u32 cnt
,
87 u32 d_pitch
, u32 s_pitch
, u32 cellsize
,
88 struct fb_image
*image
, u8
*buf
, u8
*dst
)
90 u16 charmask
= vc
->vc_hi_font_mask
? 0x1ff : 0xff;
91 u32 idx
= vc
->vc_font
.width
>> 3;
95 src
= vc
->vc_font
.data
+ (scr_readw(s
++)&
99 update_attr(buf
, src
, attr
, vc
);
103 if (likely(idx
== 1))
104 __fb_pad_aligned_buffer(dst
, d_pitch
, src
, idx
,
107 fb_pad_aligned_buffer(dst
, d_pitch
, src
, idx
,
113 info
->fbops
->fb_imageblit(info
, image
);
116 static inline void bit_putcs_unaligned(struct vc_data
*vc
,
117 struct fb_info
*info
, const u16
*s
,
118 u32 attr
, u32 cnt
, u32 d_pitch
,
119 u32 s_pitch
, u32 cellsize
,
120 struct fb_image
*image
, u8
*buf
,
123 u16 charmask
= vc
->vc_hi_font_mask
? 0x1ff : 0xff;
124 u32 shift_low
= 0, mod
= vc
->vc_font
.width
% 8;
126 u32 idx
= vc
->vc_font
.width
>> 3;
130 src
= vc
->vc_font
.data
+ (scr_readw(s
++)&
134 update_attr(buf
, src
, attr
, vc
);
138 fb_pad_unaligned_buffer(dst
, d_pitch
, src
, idx
,
139 image
->height
, shift_high
,
142 dst
+= (shift_low
>= 8) ? s_pitch
: s_pitch
- 1;
144 shift_high
= 8 - shift_low
;
147 info
->fbops
->fb_imageblit(info
, image
);
151 static void bit_putcs(struct vc_data
*vc
, struct fb_info
*info
,
152 const unsigned short *s
, int count
, int yy
, int xx
,
155 struct fb_image image
;
156 u32 width
= DIV_ROUND_UP(vc
->vc_font
.width
, 8);
157 u32 cellsize
= width
* vc
->vc_font
.height
;
158 u32 maxcnt
= info
->pixmap
.size
/cellsize
;
159 u32 scan_align
= info
->pixmap
.scan_align
- 1;
160 u32 buf_align
= info
->pixmap
.buf_align
- 1;
161 u32 mod
= vc
->vc_font
.width
% 8, cnt
, pitch
, size
;
162 u32 attribute
= get_attribute(info
, scr_readw(s
));
163 u8
*dst
, *buf
= NULL
;
167 image
.dx
= xx
* vc
->vc_font
.width
;
168 image
.dy
= yy
* vc
->vc_font
.height
;
169 image
.height
= vc
->vc_font
.height
;
173 buf
= kmalloc(cellsize
, GFP_KERNEL
);
184 image
.width
= vc
->vc_font
.width
* cnt
;
185 pitch
= DIV_ROUND_UP(image
.width
, 8) + scan_align
;
186 pitch
&= ~scan_align
;
187 size
= pitch
* image
.height
+ buf_align
;
189 dst
= fb_get_buffer_offset(info
, &info
->pixmap
, size
);
193 bit_putcs_aligned(vc
, info
, s
, attribute
, cnt
, pitch
,
194 width
, cellsize
, &image
, buf
, dst
);
196 bit_putcs_unaligned(vc
, info
, s
, attribute
, cnt
,
197 pitch
, width
, cellsize
, &image
,
200 image
.dx
+= cnt
* vc
->vc_font
.width
;
205 /* buf is always NULL except when in monochrome mode, so in this case
206 it's a gain to check buf against NULL even though kfree() handles
207 NULL pointers just fine */
213 static void bit_clear_margins(struct vc_data
*vc
, struct fb_info
*info
,
216 int bgshift
= (vc
->vc_hi_font_mask
) ? 13 : 12;
217 unsigned int cw
= vc
->vc_font
.width
;
218 unsigned int ch
= vc
->vc_font
.height
;
219 unsigned int rw
= info
->var
.xres
- (vc
->vc_cols
*cw
);
220 unsigned int bh
= info
->var
.yres
- (vc
->vc_rows
*ch
);
221 unsigned int rs
= info
->var
.xres
- rw
;
222 unsigned int bs
= info
->var
.yres
- bh
;
223 struct fb_fillrect region
;
225 region
.color
= attr_bgcol_ec(bgshift
, vc
, info
);
226 region
.rop
= ROP_COPY
;
228 if (rw
&& !bottom_only
) {
229 region
.dx
= info
->var
.xoffset
+ rs
;
232 region
.height
= info
->var
.yres_virtual
;
233 info
->fbops
->fb_fillrect(info
, ®ion
);
237 region
.dx
= info
->var
.xoffset
;
238 region
.dy
= info
->var
.yoffset
+ bs
;
241 info
->fbops
->fb_fillrect(info
, ®ion
);
245 static void bit_cursor(struct vc_data
*vc
, struct fb_info
*info
, int mode
,
246 int softback_lines
, int fg
, int bg
)
248 struct fb_cursor cursor
;
249 struct fbcon_ops
*ops
= info
->fbcon_par
;
250 unsigned short charmask
= vc
->vc_hi_font_mask
? 0x1ff : 0xff;
251 int w
= DIV_ROUND_UP(vc
->vc_font
.width
, 8), c
;
252 int y
= real_y(ops
->p
, vc
->vc_y
);
253 int attribute
, use_sw
= (vc
->vc_cursor_type
& 0x10);
259 if (softback_lines
) {
260 if (y
+ softback_lines
>= vc
->vc_rows
) {
262 ops
->cursor_flash
= 0;
268 c
= scr_readw((u16
*) vc
->vc_pos
);
269 attribute
= get_attribute(info
, c
);
270 src
= vc
->vc_font
.data
+ ((c
& charmask
) * (w
* vc
->vc_font
.height
));
272 if (ops
->cursor_state
.image
.data
!= src
||
274 ops
->cursor_state
.image
.data
= src
;
275 cursor
.set
|= FB_CUR_SETIMAGE
;
281 dst
= kmalloc(w
* vc
->vc_font
.height
, GFP_ATOMIC
);
284 kfree(ops
->cursor_data
);
285 ops
->cursor_data
= dst
;
286 update_attr(dst
, src
, attribute
, vc
);
290 if (ops
->cursor_state
.image
.fg_color
!= fg
||
291 ops
->cursor_state
.image
.bg_color
!= bg
||
293 ops
->cursor_state
.image
.fg_color
= fg
;
294 ops
->cursor_state
.image
.bg_color
= bg
;
295 cursor
.set
|= FB_CUR_SETCMAP
;
298 if ((ops
->cursor_state
.image
.dx
!= (vc
->vc_font
.width
* vc
->vc_x
)) ||
299 (ops
->cursor_state
.image
.dy
!= (vc
->vc_font
.height
* y
)) ||
301 ops
->cursor_state
.image
.dx
= vc
->vc_font
.width
* vc
->vc_x
;
302 ops
->cursor_state
.image
.dy
= vc
->vc_font
.height
* y
;
303 cursor
.set
|= FB_CUR_SETPOS
;
306 if (ops
->cursor_state
.image
.height
!= vc
->vc_font
.height
||
307 ops
->cursor_state
.image
.width
!= vc
->vc_font
.width
||
309 ops
->cursor_state
.image
.height
= vc
->vc_font
.height
;
310 ops
->cursor_state
.image
.width
= vc
->vc_font
.width
;
311 cursor
.set
|= FB_CUR_SETSIZE
;
314 if (ops
->cursor_state
.hot
.x
|| ops
->cursor_state
.hot
.y
||
316 ops
->cursor_state
.hot
.x
= cursor
.hot
.y
= 0;
317 cursor
.set
|= FB_CUR_SETHOT
;
320 if (cursor
.set
& FB_CUR_SETSIZE
||
321 vc
->vc_cursor_type
!= ops
->p
->cursor_shape
||
322 ops
->cursor_state
.mask
== NULL
||
324 char *mask
= kmalloc(w
*vc
->vc_font
.height
, GFP_ATOMIC
);
325 int cur_height
, size
, i
= 0;
331 kfree(ops
->cursor_state
.mask
);
332 ops
->cursor_state
.mask
= mask
;
334 ops
->p
->cursor_shape
= vc
->vc_cursor_type
;
335 cursor
.set
|= FB_CUR_SETSHAPE
;
337 switch (ops
->p
->cursor_shape
& CUR_HWMASK
) {
342 cur_height
= (vc
->vc_font
.height
< 10) ? 1 : 2;
344 case CUR_LOWER_THIRD
:
345 cur_height
= vc
->vc_font
.height
/3;
348 cur_height
= vc
->vc_font
.height
>> 1;
351 cur_height
= (vc
->vc_font
.height
<< 1)/3;
355 cur_height
= vc
->vc_font
.height
;
358 size
= (vc
->vc_font
.height
- cur_height
) * w
;
361 size
= cur_height
* w
;
368 ops
->cursor_state
.enable
= 0;
373 ops
->cursor_state
.enable
= (use_sw
) ? 0 : 1;
377 cursor
.image
.data
= src
;
378 cursor
.image
.fg_color
= ops
->cursor_state
.image
.fg_color
;
379 cursor
.image
.bg_color
= ops
->cursor_state
.image
.bg_color
;
380 cursor
.image
.dx
= ops
->cursor_state
.image
.dx
;
381 cursor
.image
.dy
= ops
->cursor_state
.image
.dy
;
382 cursor
.image
.height
= ops
->cursor_state
.image
.height
;
383 cursor
.image
.width
= ops
->cursor_state
.image
.width
;
384 cursor
.hot
.x
= ops
->cursor_state
.hot
.x
;
385 cursor
.hot
.y
= ops
->cursor_state
.hot
.y
;
386 cursor
.mask
= ops
->cursor_state
.mask
;
387 cursor
.enable
= ops
->cursor_state
.enable
;
388 cursor
.image
.depth
= 1;
389 cursor
.rop
= ROP_XOR
;
391 if (fbcon_decor_active(info
, vc
)) {
392 fbcon_decor_cursor(info
, &cursor
);
394 if (info
->fbops
->fb_cursor
)
395 err
= info
->fbops
->fb_cursor(info
, &cursor
);
398 soft_cursor(info
, &cursor
);
401 ops
->cursor_reset
= 0;
404 static int bit_update_start(struct fb_info
*info
)
406 struct fbcon_ops
*ops
= info
->fbcon_par
;
409 err
= fb_pan_display(info
, &ops
->var
);
410 ops
->var
.xoffset
= info
->var
.xoffset
;
411 ops
->var
.yoffset
= info
->var
.yoffset
;
412 ops
->var
.vmode
= info
->var
.vmode
;
416 void fbcon_set_bitops(struct fbcon_ops
*ops
)
418 ops
->bmove
= bit_bmove
;
419 ops
->clear
= bit_clear
;
420 ops
->putcs
= bit_putcs
;
421 ops
->clear_margins
= bit_clear_margins
;
422 ops
->cursor
= bit_cursor
;
423 ops
->update_start
= bit_update_start
;
424 ops
->rotate_font
= NULL
;
427 fbcon_set_rotate(ops
);
430 EXPORT_SYMBOL(fbcon_set_bitops
);
432 MODULE_AUTHOR("Antonino Daplas <adaplas@pol.net>");
433 MODULE_DESCRIPTION("Bit Blitting Operation");
434 MODULE_LICENSE("GPL");