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