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