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