blob: 3957fc7523e2495ab397696e21dc8129eb3e39ff [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/drivers/video/softcursor.c -- Generic software cursor for frame buffer devices
3 *
Antonino A. Daplasc465e052005-11-07 01:00:35 -08004 * Created 14 Nov 2002 by James Simmons
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
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
Adrian Bunka0aa7d02006-01-09 20:54:04 -080020#include "fbcon.h"
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022int 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, *src;
29
30 if (info->state != FBINFO_STATE_RUNNING)
31 return 0;
32
33 s_pitch = (cursor->image.width + 7) >> 3;
34 dsize = s_pitch * cursor->image.height;
35
36 src = kmalloc(dsize + sizeof(struct fb_image), GFP_ATOMIC);
37 if (!src)
38 return -ENOMEM;
39
40 image = (struct fb_image *) (src + dsize);
41 *image = cursor->image;
42 d_pitch = (s_pitch + scan_align) & ~scan_align;
43
44 size = d_pitch * image->height + buf_align;
45 size &= ~buf_align;
46 dst = fb_get_buffer_offset(info, &info->pixmap, size);
47
48 if (cursor->enable) {
49 switch (cursor->rop) {
50 case ROP_XOR:
51 for (i = 0; i < dsize; i++)
52 src[i] = image->data[i] ^ cursor->mask[i];
53 break;
54 case ROP_COPY:
55 default:
56 for (i = 0; i < dsize; i++)
57 src[i] = image->data[i] & cursor->mask[i];
58 break;
59 }
Antonino A. Daplasc465e052005-11-07 01:00:35 -080060 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 memcpy(src, image->data, dsize);
Antonino A. Daplasc465e052005-11-07 01:00:35 -080062
James Simmonsf1ab5da2005-06-21 17:17:07 -070063 fb_pad_aligned_buffer(dst, d_pitch, src, s_pitch, image->height);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 image->data = dst;
65 info->fbops->fb_imageblit(info, image);
66 kfree(src);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 return 0;
68}
69
70EXPORT_SYMBOL(soft_cursor);
Antonino A. Daplasc465e052005-11-07 01:00:35 -080071
Linus Torvalds1da177e2005-04-16 15:20:36 -070072MODULE_AUTHOR("James Simmons <jsimmons@users.sf.net>");
73MODULE_DESCRIPTION("Generic software cursor");
74MODULE_LICENSE("GPL");