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