xref: /openbmc/qemu/include/ui/qemu-pixman.h (revision 99029be1)
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 /* pixman-0.16.0 headers have a redundant declaration */
10 #ifdef CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE
11 #pragma GCC diagnostic push
12 #pragma GCC diagnostic ignored "-Wredundant-decls"
13 #endif
14 #include <pixman.h>
15 #ifdef CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE
16 #pragma GCC diagnostic pop
17 #endif
18 
19 /*
20  * pixman image formats are defined to be native endian,
21  * that means host byte order on qemu.  So we go define
22  * fixed formats here for cases where it is needed, like
23  * feeding libjpeg / libpng and writing screenshots.
24  */
25 
26 #ifdef HOST_WORDS_BIGENDIAN
27 # define PIXMAN_BE_r8g8b8     PIXMAN_r8g8b8
28 # define PIXMAN_BE_x8r8g8b8   PIXMAN_x8r8g8b8
29 # define PIXMAN_BE_a8r8g8b8   PIXMAN_a8r8g8b8
30 # define PIXMAN_BE_b8g8r8x8   PIXMAN_b8g8r8x8
31 # define PIXMAN_BE_b8g8r8a8   PIXMAN_b8g8r8a8
32 # define PIXMAN_BE_r8g8b8x8   PIXMAN_r8g8b8x8
33 # define PIXMAN_BE_r8g8b8a8   PIXMAN_r8g8b8a8
34 # define PIXMAN_BE_x8b8g8r8   PIXMAN_x8b8g8r8
35 # define PIXMAN_BE_a8b8g8r8   PIXMAN_a8b8g8r8
36 # define PIXMAN_LE_r8g8b8     PIXMAN_b8g8r8
37 # define PIXMAN_LE_a8r8g8b8   PIXMAN_b8g8r8a8
38 # define PIXMAN_LE_x8r8g8b8   PIXMAN_b8g8r8x8
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 #endif
53 
54 /* -------------------------------------------------------------------- */
55 
56 typedef struct PixelFormat {
57     uint8_t bits_per_pixel;
58     uint8_t bytes_per_pixel;
59     uint8_t depth; /* color depth in bits */
60     uint32_t rmask, gmask, bmask, amask;
61     uint8_t rshift, gshift, bshift, ashift;
62     uint8_t rmax, gmax, bmax, amax;
63     uint8_t rbits, gbits, bbits, abits;
64 } PixelFormat;
65 
66 PixelFormat qemu_pixelformat_from_pixman(pixman_format_code_t format);
67 pixman_format_code_t qemu_default_pixman_format(int bpp, bool native_endian);
68 pixman_format_code_t qemu_drm_format_to_pixman(uint32_t drm_format);
69 int qemu_pixman_get_type(int rshift, int gshift, int bshift);
70 pixman_format_code_t qemu_pixman_get_format(PixelFormat *pf);
71 bool qemu_pixman_check_format(DisplayChangeListener *dcl,
72                               pixman_format_code_t format);
73 
74 pixman_image_t *qemu_pixman_linebuf_create(pixman_format_code_t format,
75                                            int width);
76 void qemu_pixman_linebuf_fill(pixman_image_t *linebuf, pixman_image_t *fb,
77                               int width, int x, int y);
78 void qemu_pixman_linebuf_copy(pixman_image_t *fb, int width, int x, int y,
79                               pixman_image_t *linebuf);
80 pixman_image_t *qemu_pixman_mirror_create(pixman_format_code_t format,
81                                           pixman_image_t *image);
82 void qemu_pixman_image_unref(pixman_image_t *image);
83 
84 pixman_color_t qemu_pixman_color(PixelFormat *pf, uint32_t color);
85 pixman_image_t *qemu_pixman_glyph_from_vgafont(int height, const uint8_t *font,
86                                                unsigned int ch);
87 void qemu_pixman_glyph_render(pixman_image_t *glyph,
88                               pixman_image_t *surface,
89                               pixman_color_t *fgcol,
90                               pixman_color_t *bgcol,
91                               int x, int y, int cw, int ch);
92 
93 G_DEFINE_AUTOPTR_CLEANUP_FUNC(pixman_image_t, qemu_pixman_image_unref)
94 
95 #endif /* QEMU_PIXMAN_H */
96