softcursor.c 1.8 KB

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