0a2ed2fd3341836ad84f8836e31c7b087f19aef6
[linux-2.6.git] / drivers / video / console / softcursor.c
1 /*
2  * linux/drivers/video/softcursor.c -- Generic software cursor for frame buffer devices
3  *
4  *  Created 14 Nov 2002 by James Simmons
5  *
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  */
10
11 #include <linux/module.h>
12 #include <linux/string.h>
13 #include <linux/tty.h>
14 #include <linux/fb.h>
15 #include <linux/slab.h>
16
17 #include <asm/uaccess.h>
18 #include <asm/io.h>
19
20 #include "fbcon.h"
21
22 int soft_cursor(struct fb_info *info, struct fb_cursor *cursor)
23 {
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;
29         static u8 *src=NULL;
30         static int allocsize=0;
31
32         if (info->state != FBINFO_STATE_RUNNING)
33                 return 0;
34
35         s_pitch = (cursor->image.width + 7) >> 3;
36         dsize = s_pitch * cursor->image.height;
37
38         if (dsize + sizeof(struct fb_image) != allocsize) {
39                 if (src != NULL)
40                         kfree(src);
41                 allocsize = dsize + sizeof(struct fb_image);
42
43                 src = kmalloc(allocsize, GFP_ATOMIC);
44                 if (!src)
45                         return -ENOMEM;
46         }
47
48         image = (struct fb_image *) (src + dsize);
49         *image = cursor->image;
50         d_pitch = (s_pitch + scan_align) & ~scan_align;
51
52         size = d_pitch * image->height + buf_align;
53         size &= ~buf_align;
54         dst = fb_get_buffer_offset(info, &info->pixmap, size);
55
56         if (cursor->enable) {
57                 switch (cursor->rop) {
58                 case ROP_XOR:
59                         for (i = 0; i < dsize; i++)
60                                 src[i] = image->data[i] ^ cursor->mask[i];
61                         break;
62                 case ROP_COPY:
63                 default:
64                         for (i = 0; i < dsize; i++)
65                                 src[i] = image->data[i] & cursor->mask[i];
66                         break;
67                 }
68         } else
69                 memcpy(src, image->data, dsize);
70
71         fb_pad_aligned_buffer(dst, d_pitch, src, s_pitch, image->height);
72         image->data = dst;
73         info->fbops->fb_imageblit(info, image);
74         return 0;
75 }
76
77 EXPORT_SYMBOL(soft_cursor);
78
79 MODULE_AUTHOR("James Simmons <jsimmons@users.sf.net>");
80 MODULE_DESCRIPTION("Generic software cursor");
81 MODULE_LICENSE("GPL");