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.
6 #include "qemu/osdep.h"
7 #include "ui/console.h"
8 #include "standard-headers/drm/drm_fourcc.h"
10 PixelFormat
qemu_pixelformat_from_pixman(pixman_format_code_t format
)
15 bpp
= pf
.bits_per_pixel
= PIXMAN_FORMAT_BPP(format
);
16 pf
.bytes_per_pixel
= PIXMAN_FORMAT_BPP(format
) / 8;
17 pf
.depth
= PIXMAN_FORMAT_DEPTH(format
);
19 pf
.abits
= PIXMAN_FORMAT_A(format
);
20 pf
.rbits
= PIXMAN_FORMAT_R(format
);
21 pf
.gbits
= PIXMAN_FORMAT_G(format
);
22 pf
.bbits
= PIXMAN_FORMAT_B(format
);
24 switch (PIXMAN_FORMAT_TYPE(format
)) {
25 case PIXMAN_TYPE_ARGB
:
26 pf
.ashift
= pf
.bbits
+ pf
.gbits
+ pf
.rbits
;
27 pf
.rshift
= pf
.bbits
+ pf
.gbits
;
31 case PIXMAN_TYPE_ABGR
:
32 pf
.ashift
= pf
.rbits
+ pf
.gbits
+ pf
.bbits
;
33 pf
.bshift
= pf
.rbits
+ pf
.gbits
;
37 case PIXMAN_TYPE_BGRA
:
38 pf
.bshift
= bpp
- pf
.bbits
;
39 pf
.gshift
= bpp
- (pf
.bbits
+ pf
.gbits
);
40 pf
.rshift
= bpp
- (pf
.bbits
+ pf
.gbits
+ pf
.rbits
);
43 case PIXMAN_TYPE_RGBA
:
44 pf
.rshift
= bpp
- pf
.rbits
;
45 pf
.gshift
= bpp
- (pf
.rbits
+ pf
.gbits
);
46 pf
.bshift
= bpp
- (pf
.rbits
+ pf
.gbits
+ pf
.bbits
);
50 g_assert_not_reached();
54 pf
.amax
= (1 << pf
.abits
) - 1;
55 pf
.rmax
= (1 << pf
.rbits
) - 1;
56 pf
.gmax
= (1 << pf
.gbits
) - 1;
57 pf
.bmax
= (1 << pf
.bbits
) - 1;
58 pf
.amask
= pf
.amax
<< pf
.ashift
;
59 pf
.rmask
= pf
.rmax
<< pf
.rshift
;
60 pf
.gmask
= pf
.gmax
<< pf
.gshift
;
61 pf
.bmask
= pf
.bmax
<< pf
.bshift
;
66 pixman_format_code_t
qemu_default_pixman_format(int bpp
, bool native_endian
)
71 return PIXMAN_x1r5g5b5
;
77 return PIXMAN_x8r8g8b8
;
84 return PIXMAN_b8g8r8x8
;
91 /* Note: drm is little endian, pixman is native endian */
92 pixman_format_code_t
qemu_drm_format_to_pixman(uint32_t drm_format
)
96 pixman_format_code_t pixman
;
98 { DRM_FORMAT_RGB888
, PIXMAN_LE_r8g8b8
},
99 { DRM_FORMAT_ARGB8888
, PIXMAN_LE_a8r8g8b8
},
100 { DRM_FORMAT_XRGB8888
, PIXMAN_LE_x8r8g8b8
}
104 for (i
= 0; i
< ARRAY_SIZE(map
); i
++) {
105 if (drm_format
== map
[i
].drm_format
) {
106 return map
[i
].pixman
;
112 int qemu_pixman_get_type(int rshift
, int gshift
, int bshift
)
114 int type
= PIXMAN_TYPE_OTHER
;
116 if (rshift
> gshift
&& gshift
> bshift
) {
118 type
= PIXMAN_TYPE_ARGB
;
120 type
= PIXMAN_TYPE_RGBA
;
122 } else if (rshift
< gshift
&& gshift
< bshift
) {
124 type
= PIXMAN_TYPE_ABGR
;
126 type
= PIXMAN_TYPE_BGRA
;
132 pixman_format_code_t
qemu_pixman_get_format(PixelFormat
*pf
)
134 pixman_format_code_t format
;
137 type
= qemu_pixman_get_type(pf
->rshift
, pf
->gshift
, pf
->bshift
);
138 format
= PIXMAN_FORMAT(pf
->bits_per_pixel
, type
,
139 pf
->abits
, pf
->rbits
, pf
->gbits
, pf
->bbits
);
140 if (!pixman_format_supported_source(format
)) {
147 * Return true for known-good pixman conversions.
149 * UIs using pixman for format conversion can hook this into
150 * DisplayChangeListenerOps->dpy_gfx_check_format
152 bool qemu_pixman_check_format(DisplayChangeListener
*dcl
,
153 pixman_format_code_t format
)
157 case PIXMAN_x8r8g8b8
:
158 case PIXMAN_a8r8g8b8
:
159 case PIXMAN_b8g8r8x8
:
160 case PIXMAN_b8g8r8a8
:
165 case PIXMAN_x1r5g5b5
:
173 pixman_image_t
*qemu_pixman_linebuf_create(pixman_format_code_t format
,
176 pixman_image_t
*image
= pixman_image_create_bits(format
, width
, 1, NULL
, 0);
177 assert(image
!= NULL
);
181 /* fill linebuf from framebuffer */
182 void qemu_pixman_linebuf_fill(pixman_image_t
*linebuf
, pixman_image_t
*fb
,
183 int width
, int x
, int y
)
185 pixman_image_composite(PIXMAN_OP_SRC
, fb
, NULL
, linebuf
,
186 x
, y
, 0, 0, 0, 0, width
, 1);
189 /* copy linebuf to framebuffer */
190 void qemu_pixman_linebuf_copy(pixman_image_t
*fb
, int width
, int x
, int y
,
191 pixman_image_t
*linebuf
)
193 pixman_image_composite(PIXMAN_OP_SRC
, linebuf
, NULL
, fb
,
194 0, 0, 0, 0, x
, y
, width
, 1);
197 pixman_image_t
*qemu_pixman_mirror_create(pixman_format_code_t format
,
198 pixman_image_t
*image
)
200 return pixman_image_create_bits(format
,
201 pixman_image_get_width(image
),
202 pixman_image_get_height(image
),
204 pixman_image_get_stride(image
));
207 void qemu_pixman_image_unref(pixman_image_t
*image
)
212 pixman_image_unref(image
);
215 pixman_color_t
qemu_pixman_color(PixelFormat
*pf
, uint32_t color
)
219 c
.red
= ((color
& pf
->rmask
) >> pf
->rshift
) << (16 - pf
->rbits
);
220 c
.green
= ((color
& pf
->gmask
) >> pf
->gshift
) << (16 - pf
->gbits
);
221 c
.blue
= ((color
& pf
->bmask
) >> pf
->bshift
) << (16 - pf
->bbits
);
222 c
.alpha
= ((color
& pf
->amask
) >> pf
->ashift
) << (16 - pf
->abits
);
226 pixman_image_t
*qemu_pixman_glyph_from_vgafont(int height
, const uint8_t *font
,
229 pixman_image_t
*glyph
;
234 glyph
= pixman_image_create_bits(PIXMAN_a8
, 8, height
,
236 data
= (uint8_t *)pixman_image_get_data(glyph
);
239 for (y
= 0; y
< height
; y
++, font
++) {
240 for (x
= 0; x
< 8; x
++, data
++) {
241 bit
= (*font
) & (1 << (7-x
));
242 *data
= bit
? 0xff : 0x00;
248 void qemu_pixman_glyph_render(pixman_image_t
*glyph
,
249 pixman_image_t
*surface
,
250 pixman_color_t
*fgcol
,
251 pixman_color_t
*bgcol
,
252 int x
, int y
, int cw
, int ch
)
254 pixman_image_t
*ifg
= pixman_image_create_solid_fill(fgcol
);
255 pixman_image_t
*ibg
= pixman_image_create_solid_fill(bgcol
);
257 pixman_image_composite(PIXMAN_OP_SRC
, ibg
, NULL
, surface
,
261 pixman_image_composite(PIXMAN_OP_OVER
, ifg
, glyph
, surface
,
265 pixman_image_unref(ifg
);
266 pixman_image_unref(ibg
);