softcursor.c 1.8 KB

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