[PATCH] uml ubd driver: change ubd_lock to be a mutex
[linux-2.6/verdex.git] / drivers / video / console / softcursor.c
blob7d07d838356904e0b14462a9f50911abaaa92257
1 /*
2 * linux/drivers/video/softcursor.c -- Generic software cursor for frame buffer devices
4 * Created 14 Nov 2002 by James Simmons
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
8 * for more details.
9 */
11 #include <linux/module.h>
12 #include <linux/string.h>
13 #include <linux/fb.h>
14 #include <linux/slab.h>
16 #include <asm/uaccess.h>
17 #include <asm/io.h>
19 #include "fbcon.h"
21 int soft_cursor(struct fb_info *info, struct fb_cursor *cursor)
23 struct fbcon_ops *ops = info->fbcon_par;
24 unsigned int scan_align = info->pixmap.scan_align - 1;
25 unsigned int buf_align = info->pixmap.buf_align - 1;
26 unsigned int i, size, dsize, s_pitch, d_pitch;
27 struct fb_image *image;
28 u8 *dst;
30 if (info->state != FBINFO_STATE_RUNNING)
31 return 0;
33 s_pitch = (cursor->image.width + 7) >> 3;
34 dsize = s_pitch * cursor->image.height;
36 if (dsize + sizeof(struct fb_image) != ops->cursor_size) {
37 if (ops->cursor_src != NULL)
38 kfree(ops->cursor_src);
39 ops->cursor_size = dsize + sizeof(struct fb_image);
41 ops->cursor_src = kmalloc(ops->cursor_size, GFP_ATOMIC);
42 if (!ops->cursor_src) {
43 ops->cursor_size = 0;
44 return -ENOMEM;
48 image = (struct fb_image *) (ops->cursor_src + dsize);
49 *image = cursor->image;
50 d_pitch = (s_pitch + scan_align) & ~scan_align;
52 size = d_pitch * image->height + buf_align;
53 size &= ~buf_align;
54 dst = fb_get_buffer_offset(info, &info->pixmap, size);
56 if (cursor->enable) {
57 switch (cursor->rop) {
58 case ROP_XOR:
59 for (i = 0; i < dsize; i++)
60 ops->cursor_src[i] = image->data[i] ^
61 cursor->mask[i];
62 break;
63 case ROP_COPY:
64 default:
65 for (i = 0; i < dsize; i++)
66 ops->cursor_src[i] = image->data[i] &
67 cursor->mask[i];
68 break;
70 } else
71 memcpy(ops->cursor_src, image->data, dsize);
73 fb_pad_aligned_buffer(dst, d_pitch, ops->cursor_src, s_pitch,
74 image->height);
75 image->data = dst;
76 info->fbops->fb_imageblit(info, image);
77 return 0;
80 EXPORT_SYMBOL(soft_cursor);
82 MODULE_AUTHOR("James Simmons <jsimmons@users.sf.net>");
83 MODULE_DESCRIPTION("Generic software cursor");
84 MODULE_LICENSE("GPL");