blob: f577bd80e020ee832c28657629128d57cd7a73f7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Franck Bui-Huu024cd7e2006-12-08 02:40:48 -08002 * linux/drivers/video/softcursor.c
3 *
4 * Generic software cursor for frame buffer devices
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
Antonino A. Daplasc465e052005-11-07 01:00:35 -08006 * Created 14 Nov 2002 by James Simmons
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
Franck Bui-Huu024cd7e2006-12-08 02:40:48 -08008 * This file is subject to the terms and conditions of the GNU General
9 * Public License. See the file COPYING in the main directory of this
10 * archive for more details.
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 */
12
13#include <linux/module.h>
14#include <linux/string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/fb.h>
16#include <linux/slab.h>
17
18#include <asm/uaccess.h>
19#include <asm/io.h>
20
Adrian Bunka0aa7d02006-01-09 20:54:04 -080021#include "fbcon.h"
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023int soft_cursor(struct fb_info *info, struct fb_cursor *cursor)
24{
Dave Jonese299dd42006-10-03 01:14:47 -070025 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 unsigned int scan_align = info->pixmap.scan_align - 1;
27 unsigned int buf_align = info->pixmap.buf_align - 1;
28 unsigned int i, size, dsize, s_pitch, d_pitch;
29 struct fb_image *image;
Franck Bui-Huu024cd7e2006-12-08 02:40:48 -080030 u8 *src, *dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
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
Dave Jonese299dd42006-10-03 01:14:47 -070038 if (dsize + sizeof(struct fb_image) != ops->cursor_size) {
39 if (ops->cursor_src != NULL)
40 kfree(ops->cursor_src);
41 ops->cursor_size = dsize + sizeof(struct fb_image);
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Dave Jonese299dd42006-10-03 01:14:47 -070043 ops->cursor_src = kmalloc(ops->cursor_size, GFP_ATOMIC);
44 if (!ops->cursor_src) {
45 ops->cursor_size = 0;
46 return -ENOMEM;
47 }
48 }
49
Franck Bui-Huu024cd7e2006-12-08 02:40:48 -080050 src = ops->cursor_src + sizeof(struct fb_image);
51 image = (struct fb_image *)ops->cursor_src;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 *image = cursor->image;
53 d_pitch = (s_pitch + scan_align) & ~scan_align;
54
55 size = d_pitch * image->height + buf_align;
56 size &= ~buf_align;
57 dst = fb_get_buffer_offset(info, &info->pixmap, size);
58
59 if (cursor->enable) {
60 switch (cursor->rop) {
61 case ROP_XOR:
62 for (i = 0; i < dsize; i++)
Franck Bui-Huu024cd7e2006-12-08 02:40:48 -080063 src[i] = image->data[i] ^ cursor->mask[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 break;
65 case ROP_COPY:
66 default:
67 for (i = 0; i < dsize; i++)
Franck Bui-Huu024cd7e2006-12-08 02:40:48 -080068 src[i] = image->data[i] & cursor->mask[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 break;
70 }
Antonino A. Daplasc465e052005-11-07 01:00:35 -080071 } else
Franck Bui-Huu024cd7e2006-12-08 02:40:48 -080072 memcpy(src, image->data, dsize);
Antonino A. Daplasc465e052005-11-07 01:00:35 -080073
Franck Bui-Huu024cd7e2006-12-08 02:40:48 -080074 fb_pad_aligned_buffer(dst, d_pitch, src, s_pitch, image->height);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 image->data = dst;
76 info->fbops->fb_imageblit(info, image);
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 return 0;
78}
79
80EXPORT_SYMBOL(soft_cursor);
Antonino A. Daplasc465e052005-11-07 01:00:35 -080081
Linus Torvalds1da177e2005-04-16 15:20:36 -070082MODULE_AUTHOR("James Simmons <jsimmons@users.sf.net>");
83MODULE_DESCRIPTION("Generic software cursor");
84MODULE_LICENSE("GPL");