softcursor.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * linux/drivers/video/console/softcursor.c
  3. *
  4. * Generic software cursor for frame buffer devices
  5. *
  6. * Created 14 Nov 2002 by James Simmons
  7. *
  8. * 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.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/string.h>
  14. #include <linux/fb.h>
  15. #include <linux/slab.h>
  16. #include <asm/uaccess.h>
  17. #include <asm/io.h>
  18. #include "fbcon.h"
  19. int soft_cursor(struct fb_info *info, struct fb_cursor *cursor)
  20. {
  21. struct fbcon_ops *ops = info->fbcon_par;
  22. unsigned int scan_align = info->pixmap.scan_align - 1;
  23. unsigned int buf_align = info->pixmap.buf_align - 1;
  24. unsigned int i, size, dsize, s_pitch, d_pitch;
  25. struct fb_image *image;
  26. u8 *src, *dst;
  27. if (info->state != FBINFO_STATE_RUNNING)
  28. return 0;
  29. s_pitch = (cursor->image.width + 7) >> 3;
  30. dsize = s_pitch * cursor->image.height;
  31. if (dsize + sizeof(struct fb_image) != ops->cursor_size) {
  32. if (ops->cursor_src != NULL)
  33. kfree(ops->cursor_src);
  34. ops->cursor_size = dsize + sizeof(struct fb_image);
  35. ops->cursor_src = kmalloc(ops->cursor_size, GFP_ATOMIC);
  36. if (!ops->cursor_src) {
  37. ops->cursor_size = 0;
  38. return -ENOMEM;
  39. }
  40. }
  41. src = ops->cursor_src + sizeof(struct fb_image);
  42. image = (struct fb_image *)ops->cursor_src;
  43. *image = cursor->image;
  44. d_pitch = (s_pitch + scan_align) & ~scan_align;
  45. size = d_pitch * image->height + buf_align;
  46. size &= ~buf_align;
  47. dst = fb_get_buffer_offset(info, &info->pixmap, size);
  48. if (cursor->enable) {
  49. switch (cursor->rop) {
  50. case ROP_XOR:
  51. for (i = 0; i < dsize; i++)
  52. src[i] = image->data[i] ^ cursor->mask[i];
  53. break;
  54. case ROP_COPY:
  55. default:
  56. for (i = 0; i < dsize; i++)
  57. src[i] = image->data[i] & cursor->mask[i];
  58. break;
  59. }
  60. } else
  61. memcpy(src, image->data, dsize);
  62. fb_pad_aligned_buffer(dst, d_pitch, src, s_pitch, image->height);
  63. image->data = dst;
  64. info->fbops->fb_imageblit(info, image);
  65. return 0;
  66. }
  67. EXPORT_SYMBOL(soft_cursor);
  68. MODULE_AUTHOR("James Simmons <jsimmons@users.sf.net>");
  69. MODULE_DESCRIPTION("Generic software cursor");
  70. MODULE_LICENSE("GPL");