Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/video/softcursor.c -- Generic software cursor for frame buffer devices |
| 3 | * |
Antonino A. Daplas | c465e05 | 2005-11-07 01:00:35 -0800 | [diff] [blame] | 4 | * Created 14 Nov 2002 by James Simmons |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/fb.h> |
| 14 | #include <linux/slab.h> |
| 15 | |
| 16 | #include <asm/uaccess.h> |
| 17 | #include <asm/io.h> |
| 18 | |
Adrian Bunk | a0aa7d0 | 2006-01-09 20:54:04 -0800 | [diff] [blame] | 19 | #include "fbcon.h" |
| 20 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | int soft_cursor(struct fb_info *info, struct fb_cursor *cursor) |
| 22 | { |
Dave Jones | e299dd4 | 2006-10-03 01:14:47 -0700 | [diff] [blame] | 23 | struct fbcon_ops *ops = info->fbcon_par; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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; |
Dave Jones | e299dd4 | 2006-10-03 01:14:47 -0700 | [diff] [blame] | 28 | u8 *dst; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Dave Jones | e299dd4 | 2006-10-03 01:14:47 -0700 | [diff] [blame] | 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); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
Dave Jones | e299dd4 | 2006-10-03 01:14:47 -0700 | [diff] [blame] | 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); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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++) |
Dave Jones | e299dd4 | 2006-10-03 01:14:47 -0700 | [diff] [blame] | 60 | ops->cursor_src[i] = image->data[i] ^ |
| 61 | cursor->mask[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | break; |
| 63 | case ROP_COPY: |
| 64 | default: |
| 65 | for (i = 0; i < dsize; i++) |
Dave Jones | e299dd4 | 2006-10-03 01:14:47 -0700 | [diff] [blame] | 66 | ops->cursor_src[i] = image->data[i] & |
| 67 | cursor->mask[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | break; |
| 69 | } |
Antonino A. Daplas | c465e05 | 2005-11-07 01:00:35 -0800 | [diff] [blame] | 70 | } else |
Dave Jones | e299dd4 | 2006-10-03 01:14:47 -0700 | [diff] [blame] | 71 | memcpy(ops->cursor_src, image->data, dsize); |
Antonino A. Daplas | c465e05 | 2005-11-07 01:00:35 -0800 | [diff] [blame] | 72 | |
Dave Jones | e299dd4 | 2006-10-03 01:14:47 -0700 | [diff] [blame] | 73 | fb_pad_aligned_buffer(dst, d_pitch, ops->cursor_src, s_pitch, |
| 74 | image->height); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | image->data = dst; |
| 76 | info->fbops->fb_imageblit(info, image); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | return 0; |
| 78 | } |
| 79 | |
| 80 | EXPORT_SYMBOL(soft_cursor); |
Antonino A. Daplas | c465e05 | 2005-11-07 01:00:35 -0800 | [diff] [blame] | 81 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | MODULE_AUTHOR("James Simmons <jsimmons@users.sf.net>"); |
| 83 | MODULE_DESCRIPTION("Generic software cursor"); |
| 84 | MODULE_LICENSE("GPL"); |