blob: 46dd8f5d2e9e1c899921893f314ce590ea998d10 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Uwe Kleine-König58862692007-05-09 07:51:49 +02002 * linux/drivers/video/console/softcursor.c
Franck Bui-Huu024cd7e2006-12-08 02:40:48 -08003 *
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#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{
Dave Jonese299dd42006-10-03 01:14:47 -070024 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 unsigned int scan_align = info->pixmap.scan_align - 1;
26 unsigned int buf_align = info->pixmap.buf_align - 1;
27 unsigned int i, size, dsize, s_pitch, d_pitch;
28 struct fb_image *image;
Franck Bui-Huu024cd7e2006-12-08 02:40:48 -080029 u8 *src, *dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31 if (info->state != FBINFO_STATE_RUNNING)
32 return 0;
33
34 s_pitch = (cursor->image.width + 7) >> 3;
35 dsize = s_pitch * cursor->image.height;
36
Dave Jonese299dd42006-10-03 01:14:47 -070037 if (dsize + sizeof(struct fb_image) != ops->cursor_size) {
Sachin Kamata240af22012-12-07 12:30:39 -080038 kfree(ops->cursor_src);
Dave Jonese299dd42006-10-03 01:14:47 -070039 ops->cursor_size = dsize + sizeof(struct fb_image);
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
Dave Jonese299dd42006-10-03 01:14:47 -070041 ops->cursor_src = kmalloc(ops->cursor_size, GFP_ATOMIC);
42 if (!ops->cursor_src) {
43 ops->cursor_size = 0;
44 return -ENOMEM;
45 }
46 }
47
Franck Bui-Huu024cd7e2006-12-08 02:40:48 -080048 src = ops->cursor_src + sizeof(struct fb_image);
49 image = (struct fb_image *)ops->cursor_src;
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 *image = cursor->image;
51 d_pitch = (s_pitch + scan_align) & ~scan_align;
52
53 size = d_pitch * image->height + buf_align;
54 size &= ~buf_align;
55 dst = fb_get_buffer_offset(info, &info->pixmap, size);
56
57 if (cursor->enable) {
58 switch (cursor->rop) {
59 case ROP_XOR:
60 for (i = 0; i < dsize; i++)
Franck Bui-Huu024cd7e2006-12-08 02:40:48 -080061 src[i] = image->data[i] ^ cursor->mask[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 break;
63 case ROP_COPY:
64 default:
65 for (i = 0; i < dsize; i++)
Franck Bui-Huu024cd7e2006-12-08 02:40:48 -080066 src[i] = image->data[i] & cursor->mask[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 break;
68 }
Antonino A. Daplasc465e052005-11-07 01:00:35 -080069 } else
Franck Bui-Huu024cd7e2006-12-08 02:40:48 -080070 memcpy(src, image->data, dsize);
Antonino A. Daplasc465e052005-11-07 01:00:35 -080071
Franck Bui-Huu024cd7e2006-12-08 02:40:48 -080072 fb_pad_aligned_buffer(dst, d_pitch, src, s_pitch, image->height);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 image->data = dst;
74 info->fbops->fb_imageblit(info, image);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 return 0;
76}
77
78EXPORT_SYMBOL(soft_cursor);
Antonino A. Daplasc465e052005-11-07 01:00:35 -080079
Linus Torvalds1da177e2005-04-16 15:20:36 -070080MODULE_AUTHOR("James Simmons <jsimmons@users.sf.net>");
81MODULE_DESCRIPTION("Generic software cursor");
82MODULE_LICENSE("GPL");