blob: 7d07d838356904e0b14462a9f50911abaaa92257 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/fb.h>
14#include <linux/slab.h>
15
16#include <asm/uaccess.h>
17#include <asm/io.h>
18
Adrian Bunka0aa7d02006-01-09 20:54:04 -080019#include "fbcon.h"
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021int soft_cursor(struct fb_info *info, struct fb_cursor *cursor)
22{
Dave Jonese299dd42006-10-03 01:14:47 -070023 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -070024 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;
Dave Jonese299dd42006-10-03 01:14:47 -070028 u8 *dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
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
Dave Jonese299dd42006-10-03 01:14:47 -070036 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);
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
48 image = (struct fb_image *) (ops->cursor_src + dsize);
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 *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++)
Dave Jonese299dd42006-10-03 01:14:47 -070060 ops->cursor_src[i] = image->data[i] ^
61 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++)
Dave Jonese299dd42006-10-03 01:14:47 -070066 ops->cursor_src[i] = image->data[i] &
67 cursor->mask[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 break;
69 }
Antonino A. Daplasc465e052005-11-07 01:00:35 -080070 } else
Dave Jonese299dd42006-10-03 01:14:47 -070071 memcpy(ops->cursor_src, image->data, dsize);
Antonino A. Daplasc465e052005-11-07 01:00:35 -080072
Dave Jonese299dd42006-10-03 01:14:47 -070073 fb_pad_aligned_buffer(dst, d_pitch, ops->cursor_src, s_pitch,
74 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");