VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[linux-2.6.git] / drivers / video / softcursor.c
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/tty.h>
14 #include <linux/fb.h>
15 #include <linux/slab.h>
16
17 #include <asm/uaccess.h>
18 #include <asm/io.h>
19
20 int soft_cursor(struct fb_info *info, struct fb_cursor *cursor)
21 {
22         unsigned int scan_align = info->sprite.scan_align - 1;
23         unsigned int buf_align = info->sprite.buf_align - 1;
24         unsigned int i, size, dsize, s_pitch, d_pitch;
25         u8 *dst, src[64];
26
27         if (cursor->set & FB_CUR_SETSIZE) {
28                 info->cursor.image.height = cursor->image.height;
29                 info->cursor.image.width = cursor->image.width;
30         }
31
32         if (cursor->set & FB_CUR_SETPOS) {
33                 info->cursor.image.dx = cursor->image.dx;
34                 info->cursor.image.dy = cursor->image.dy;
35         }
36
37         if (cursor->set & FB_CUR_SETHOT)
38                 info->cursor.hot = cursor->hot;
39         
40         if (cursor->set & FB_CUR_SETCMAP) {
41                 if (cursor->image.depth == 1) {
42                         info->cursor.image.bg_color = cursor->image.bg_color;
43                         info->cursor.image.fg_color = cursor->image.fg_color;
44                 } else {
45                         if (cursor->image.cmap.len)
46                                 fb_copy_cmap(&cursor->image.cmap, &info->cursor.image.cmap);
47                 }
48                 info->cursor.image.depth = cursor->image.depth;
49         }       
50
51         if (info->state != FBINFO_STATE_RUNNING)
52                 return 0;
53
54         s_pitch = (info->cursor.image.width + 7) >> 3;
55         dsize = s_pitch * info->cursor.image.height;
56         d_pitch = (s_pitch + scan_align) & ~scan_align;
57         size = d_pitch * info->cursor.image.height + buf_align;
58         size &= ~buf_align;
59         dst = fb_get_buffer_offset(info, &info->sprite, size);
60
61         if (info->cursor.enable) {
62                 switch (info->cursor.rop) {
63                 case ROP_XOR:
64                         for (i = 0; i < dsize; i++)
65                                 src[i] = cursor->image.data[i] ^ info->cursor.mask[i]; 
66                         break;
67                 case ROP_COPY:
68                 default:
69                         for (i = 0; i < dsize; i++)
70                                 src[i] = cursor->image.data[i] & info->cursor.mask[i];
71                         break;
72                 }
73         } else 
74                 memcpy(src, cursor->image.data, dsize);
75         
76         if (info->sprite.outbuf)
77                 fb_iomove_buf_aligned(info, &info->sprite, dst, d_pitch, src,
78                                   s_pitch, info->cursor.image.height);
79         else
80                 fb_sysmove_buf_aligned(info, &info->sprite, dst, d_pitch, src,
81                                    s_pitch, info->cursor.image.height);
82         info->cursor.image.data = dst;
83         
84         info->fbops->fb_imageblit(info, &info->cursor.image);
85         return 0;
86 }
87
88 EXPORT_SYMBOL(soft_cursor);
89  
90 MODULE_AUTHOR("James Simmons <jsimmons@users.sf.net>");
91 MODULE_DESCRIPTION("Generic software cursor");
92 MODULE_LICENSE("GPL");