Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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/fb.h>
14#include <linux/slab.h>
15
16#include <asm/uaccess.h>
17#include <asm/io.h>
18
19#include "fbcon.h"
20
21int soft_cursor(struct fb_info *info, struct fb_cursor *cursor)
22{
23 struct fbcon_ops *ops = info->fbcon_par;
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
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 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);
40
41 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);
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 ops->cursor_src[i] = image->data[i] ^
61 cursor->mask[i];
62 break;
63 case ROP_COPY:
64 default:
65 for (i = 0; i < dsize; i++)
66 ops->cursor_src[i] = image->data[i] &
67 cursor->mask[i];
68 break;
69 }
70 } else
71 memcpy(ops->cursor_src, image->data, dsize);
72
73 fb_pad_aligned_buffer(dst, d_pitch, ops->cursor_src, s_pitch,
74 image->height);
75 image->data = dst;
76 info->fbops->fb_imageblit(info, image);
77 return 0;
78}
79
80EXPORT_SYMBOL(soft_cursor);
81
82MODULE_AUTHOR("James Simmons <jsimmons@users.sf.net>");
83MODULE_DESCRIPTION("Generic software cursor");
84MODULE_LICENSE("GPL");