qemu-pixman.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * This work is licensed under the terms of the GNU GPL, version 2 or later.
  3. * See the COPYING file in the top-level directory.
  4. */
  5. #include "qemu-common.h"
  6. #include "ui/console.h"
  7. int qemu_pixman_get_type(int rshift, int gshift, int bshift)
  8. {
  9. int type = PIXMAN_TYPE_OTHER;
  10. if (rshift > gshift && gshift > bshift) {
  11. if (bshift == 0) {
  12. type = PIXMAN_TYPE_ARGB;
  13. } else {
  14. #if PIXMAN_VERSION >= PIXMAN_VERSION_ENCODE(0, 21, 8)
  15. type = PIXMAN_TYPE_RGBA;
  16. #endif
  17. }
  18. } else if (rshift < gshift && gshift < bshift) {
  19. if (rshift == 0) {
  20. type = PIXMAN_TYPE_ABGR;
  21. } else {
  22. #if PIXMAN_VERSION >= PIXMAN_VERSION_ENCODE(0, 16, 0)
  23. type = PIXMAN_TYPE_BGRA;
  24. #endif
  25. }
  26. }
  27. return type;
  28. }
  29. pixman_format_code_t qemu_pixman_get_format(PixelFormat *pf)
  30. {
  31. pixman_format_code_t format;
  32. int type;
  33. type = qemu_pixman_get_type(pf->rshift, pf->gshift, pf->bshift);
  34. format = PIXMAN_FORMAT(pf->bits_per_pixel, type,
  35. pf->abits, pf->rbits, pf->gbits, pf->bbits);
  36. if (!pixman_format_supported_source(format)) {
  37. return 0;
  38. }
  39. return format;
  40. }
  41. pixman_image_t *qemu_pixman_linebuf_create(pixman_format_code_t format,
  42. int width)
  43. {
  44. pixman_image_t *image = pixman_image_create_bits(format, width, 1, NULL, 0);
  45. assert(image != NULL);
  46. return image;
  47. }
  48. void qemu_pixman_linebuf_fill(pixman_image_t *linebuf, pixman_image_t *fb,
  49. int width, int x, int y)
  50. {
  51. pixman_image_composite(PIXMAN_OP_SRC, fb, NULL, linebuf,
  52. x, y, 0, 0, 0, 0, width, 1);
  53. }
  54. pixman_image_t *qemu_pixman_mirror_create(pixman_format_code_t format,
  55. pixman_image_t *image)
  56. {
  57. pixman_image_t *mirror;
  58. mirror = pixman_image_create_bits(format,
  59. pixman_image_get_width(image),
  60. pixman_image_get_height(image),
  61. NULL,
  62. pixman_image_get_stride(image));
  63. return mirror;
  64. }
  65. void qemu_pixman_image_unref(pixman_image_t *image)
  66. {
  67. if (image == NULL) {
  68. return;
  69. }
  70. pixman_image_unref(image);
  71. }