qemu-pixman.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. }
  72. pixman_color_t qemu_pixman_color(PixelFormat *pf, uint32_t color)
  73. {
  74. pixman_color_t c;
  75. c.red = ((color & pf->rmask) >> pf->rshift) << (16 - pf->rbits);
  76. c.green = ((color & pf->gmask) >> pf->gshift) << (16 - pf->gbits);
  77. c.blue = ((color & pf->bmask) >> pf->bshift) << (16 - pf->bbits);
  78. c.alpha = ((color & pf->amask) >> pf->ashift) << (16 - pf->abits);
  79. return c;
  80. }
  81. pixman_image_t *qemu_pixman_glyph_from_vgafont(int height, const uint8_t *font,
  82. unsigned int ch)
  83. {
  84. pixman_image_t *glyph;
  85. uint8_t *data;
  86. bool bit;
  87. int x, y;
  88. glyph = pixman_image_create_bits(PIXMAN_a8, 8, height,
  89. NULL, 0);
  90. data = (uint8_t *)pixman_image_get_data(glyph);
  91. font += height * ch;
  92. for (y = 0; y < height; y++, font++) {
  93. for (x = 0; x < 8; x++, data++) {
  94. bit = (*font) & (1 << (7-x));
  95. *data = bit ? 0xff : 0x00;
  96. }
  97. }
  98. return glyph;
  99. }
  100. void qemu_pixman_glyph_render(pixman_image_t *glyph,
  101. pixman_image_t *surface,
  102. pixman_color_t *fgcol,
  103. pixman_color_t *bgcol,
  104. int x, int y, int cw, int ch)
  105. {
  106. pixman_image_t *ifg = pixman_image_create_solid_fill(fgcol);
  107. pixman_image_t *ibg = pixman_image_create_solid_fill(bgcol);
  108. pixman_image_composite(PIXMAN_OP_SRC, ibg, NULL, surface,
  109. 0, 0, 0, 0,
  110. cw * x, ch * y,
  111. cw, ch);
  112. pixman_image_composite(PIXMAN_OP_OVER, ifg, glyph, surface,
  113. 0, 0, 0, 0,
  114. cw * x, ch * y,
  115. cw, ch);
  116. pixman_image_unref(ifg);
  117. pixman_image_unref(ibg);
  118. }