| 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 | |
| 6 | #ifndef QEMU_PIXMAN_H |
| 7 | #define QEMU_PIXMAN_H |
| 8 | |
| 9 | #ifdef CONFIG_PIXMAN |
| 10 | #include <pixman.h> |
| 11 | #include "qemu-pixman-helpers.h" |
| 12 | #else |
| 13 | #include "pixman-minimal.h" |
| 14 | #endif |
| 15 | |
| 16 | #include "qapi/error.h" |
| 17 | |
| 18 | /* |
| 19 | * pixman image formats are defined to be native endian, |
| 20 | * that means host byte order on qemu. So we go define |
| 21 | * fixed formats here for cases where it is needed, like |
| 22 | * feeding libjpeg / libpng and writing screenshots. |
| 23 | */ |
| 24 | |
| 25 | #if HOST_BIG_ENDIAN |
| 26 | # define PIXMAN_BE_r8g8b8 PIXMAN_r8g8b8 |
| 27 | # define PIXMAN_BE_x8r8g8b8 PIXMAN_x8r8g8b8 |
| 28 | # define PIXMAN_BE_a8r8g8b8 PIXMAN_a8r8g8b8 |
| 29 | # define PIXMAN_BE_b8g8r8x8 PIXMAN_b8g8r8x8 |
| 30 | # define PIXMAN_BE_b8g8r8a8 PIXMAN_b8g8r8a8 |
| 31 | # define PIXMAN_BE_r8g8b8x8 PIXMAN_r8g8b8x8 |
| 32 | # define PIXMAN_BE_r8g8b8a8 PIXMAN_r8g8b8a8 |
| 33 | # define PIXMAN_BE_x8b8g8r8 PIXMAN_x8b8g8r8 |
| 34 | # define PIXMAN_BE_a8b8g8r8 PIXMAN_a8b8g8r8 |
| 35 | # define PIXMAN_LE_r8g8b8 PIXMAN_b8g8r8 |
| 36 | # define PIXMAN_LE_a8r8g8b8 PIXMAN_b8g8r8a8 |
| 37 | # define PIXMAN_LE_x8r8g8b8 PIXMAN_b8g8r8x8 |
| 38 | # define PIXMAN_LE_a8b8g8r8 PIXMAN_r8g8b8a8 |
| 39 | # define PIXMAN_LE_x8b8g8r8 PIXMAN_r8g8b8x8 |
| 40 | #else |
| 41 | # define PIXMAN_BE_r8g8b8 PIXMAN_b8g8r8 |
| 42 | # define PIXMAN_BE_x8r8g8b8 PIXMAN_b8g8r8x8 |
| 43 | # define PIXMAN_BE_a8r8g8b8 PIXMAN_b8g8r8a8 |
| 44 | # define PIXMAN_BE_b8g8r8x8 PIXMAN_x8r8g8b8 |
| 45 | # define PIXMAN_BE_b8g8r8a8 PIXMAN_a8r8g8b8 |
| 46 | # define PIXMAN_BE_r8g8b8x8 PIXMAN_x8b8g8r8 |
| 47 | # define PIXMAN_BE_r8g8b8a8 PIXMAN_a8b8g8r8 |
| 48 | # define PIXMAN_BE_x8b8g8r8 PIXMAN_r8g8b8x8 |
| 49 | # define PIXMAN_BE_a8b8g8r8 PIXMAN_r8g8b8a8 |
| 50 | # define PIXMAN_LE_r8g8b8 PIXMAN_r8g8b8 |
| 51 | # define PIXMAN_LE_a8r8g8b8 PIXMAN_a8r8g8b8 |
| 52 | # define PIXMAN_LE_x8r8g8b8 PIXMAN_x8r8g8b8 |
| 53 | # define PIXMAN_LE_a8b8g8r8 PIXMAN_a8b8g8r8 |
| 54 | # define PIXMAN_LE_x8b8g8r8 PIXMAN_x8b8g8r8 |
| 55 | #endif |
| 56 | |
| 57 | #define QEMU_PIXMAN_COLOR(r, g, b) \ |
| 58 | { .red = r << 8, .green = g << 8, .blue = b << 8, .alpha = 0xffff } |
| 59 | |
| 60 | #define QEMU_PIXMAN_COLOR_BLACK QEMU_PIXMAN_COLOR(0x00, 0x00, 0x00) |
| 61 | #define QEMU_PIXMAN_COLOR_GRAY QEMU_PIXMAN_COLOR(0xaa, 0xaa, 0xaa) |
| 62 | |
| 63 | /* -------------------------------------------------------------------- */ |
| 64 | |
| 65 | typedef struct PixelFormat { |
| 66 | uint8_t bits_per_pixel; |
| 67 | uint8_t bytes_per_pixel; |
| 68 | uint8_t depth; /* color depth in bits */ |
| 69 | uint32_t rmask, gmask, bmask, amask; |
| 70 | uint8_t rshift, gshift, bshift, ashift; |
| 71 | uint8_t rmax, gmax, bmax, amax; |
| 72 | uint8_t rbits, gbits, bbits, abits; |
| 73 | } PixelFormat; |
| 74 | |
| 75 | PixelFormat qemu_pixelformat_from_pixman(pixman_format_code_t format); |
| 76 | pixman_format_code_t qemu_default_pixman_format(int bpp, bool native_endian); |
| 77 | |
| 78 | static inline PixelFormat qemu_default_pixelformat(int bpp) |
| 79 | { |
| 80 | pixman_format_code_t fmt = qemu_default_pixman_format(bpp, true); |
| 81 | PixelFormat pf = qemu_pixelformat_from_pixman(fmt); |
| 82 | return pf; |
| 83 | } |
| 84 | |
| 85 | pixman_format_code_t qemu_drm_format_to_pixman(uint32_t drm_format); |
| 86 | uint32_t qemu_pixman_to_drm_format(pixman_format_code_t pixman); |
| 87 | int qemu_pixman_get_type(int rshift, int gshift, int bshift, int endian); |
| 88 | bool qemu_pixman_check_format(DisplayChangeListener *dcl, |
| 89 | pixman_format_code_t format); |
| 90 | |
| 91 | #ifdef CONFIG_PIXMAN |
| 92 | pixman_format_code_t qemu_pixman_get_format(PixelFormat *pf, int endian); |
| 93 | pixman_image_t *qemu_pixman_linebuf_create(pixman_format_code_t format, |
| 94 | int width); |
| 95 | void qemu_pixman_linebuf_fill(pixman_image_t *linebuf, pixman_image_t *fb, |
| 96 | int width, int x, int y); |
| 97 | pixman_image_t *qemu_pixman_mirror_create(pixman_format_code_t format, |
| 98 | pixman_image_t *image); |
| 99 | |
| 100 | pixman_image_t *qemu_pixman_glyph_from_vgafont(int height, const uint8_t *font, |
| 101 | unsigned int ch); |
| 102 | void qemu_pixman_glyph_render(pixman_image_t *glyph, |
| 103 | pixman_image_t *surface, |
| 104 | pixman_color_t *fgcol, |
| 105 | pixman_color_t *bgcol, |
| 106 | int x, int y, int cw, int ch); |
| 107 | #endif |
| 108 | |
| 109 | void qemu_pixman_image_unref(pixman_image_t *image); |
| 110 | |
| 111 | #ifdef WIN32 |
| 112 | typedef HANDLE qemu_pixman_shareable; |
| 113 | #define SHAREABLE_NONE (NULL) |
| 114 | #define SHAREABLE_TO_PTR(handle) (handle) |
| 115 | #define PTR_TO_SHAREABLE(ptr) (ptr) |
| 116 | #else |
| 117 | typedef int qemu_pixman_shareable; |
| 118 | #define SHAREABLE_NONE (-1) |
| 119 | #define SHAREABLE_TO_PTR(handle) GINT_TO_POINTER(handle) |
| 120 | #define PTR_TO_SHAREABLE(ptr) GPOINTER_TO_INT(ptr) |
| 121 | #endif |
| 122 | |
| 123 | bool qemu_pixman_image_new_shareable( |
| 124 | pixman_image_t **image, |
| 125 | qemu_pixman_shareable *handle, |
| 126 | const char *name, |
| 127 | pixman_format_code_t format, |
| 128 | int width, |
| 129 | int height, |
| 130 | int rowstride_bytes, |
| 131 | Error **errp); |
| 132 | |
| 133 | G_DEFINE_AUTOPTR_CLEANUP_FUNC(pixman_image_t, qemu_pixman_image_unref) |
| 134 | |
| 135 | #endif /* QEMU_PIXMAN_H */ |