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 "qemu-common.h"
8 #include "ui/console.h"
9 #include "standard-headers/drm/drm_fourcc.h"
11 PixelFormat
qemu_pixelformat_from_pixman(pixman_format_code_t format
)
16 bpp
= pf
.bits_per_pixel
= PIXMAN_FORMAT_BPP(format
);
17 pf
.bytes_per_pixel
= PIXMAN_FORMAT_BPP(format
) / 8;
18 pf
.depth
= PIXMAN_FORMAT_DEPTH(format
);
20 pf
.abits
= PIXMAN_FORMAT_A(format
);
21 pf
.rbits
= PIXMAN_FORMAT_R(format
);
22 pf
.gbits
= PIXMAN_FORMAT_G(format
);
23 pf
.bbits
= PIXMAN_FORMAT_B(format
);
25 switch (PIXMAN_FORMAT_TYPE(format
)) {
26 case PIXMAN_TYPE_ARGB
:
27 pf
.ashift
= pf
.bbits
+ pf
.gbits
+ pf
.rbits
;
28 pf
.rshift
= pf
.bbits
+ pf
.gbits
;
32 case PIXMAN_TYPE_ABGR
:
33 pf
.ashift
= pf
.rbits
+ pf
.gbits
+ pf
.bbits
;
34 pf
.bshift
= pf
.rbits
+ pf
.gbits
;
38 case PIXMAN_TYPE_BGRA
:
39 pf
.bshift
= bpp
- pf
.bbits
;
40 pf
.gshift
= bpp
- (pf
.bbits
+ pf
.gbits
);
41 pf
.rshift
= bpp
- (pf
.bbits
+ pf
.gbits
+ pf
.rbits
);
44 case PIXMAN_TYPE_RGBA
:
45 pf
.rshift
= bpp
- pf
.rbits
;
46 pf
.gshift
= bpp
- (pf
.rbits
+ pf
.gbits
);
47 pf
.bshift
= bpp
- (pf
.rbits
+ pf
.gbits
+ pf
.bbits
);
51 g_assert_not_reached();
55 pf
.amax
= (1 << pf
.abits
) - 1;
56 pf
.rmax
= (1 << pf
.rbits
) - 1;
57 pf
.gmax
= (1 << pf
.gbits
) - 1;
58 pf
.bmax
= (1 << pf
.bbits
) - 1;
59 pf
.amask
= pf
.amax
<< pf
.ashift
;
60 pf
.rmask
= pf
.rmax
<< pf
.rshift
;
61 pf
.gmask
= pf
.gmax
<< pf
.gshift
;
62 pf
.bmask
= pf
.bmax
<< pf
.bshift
;
67 pixman_format_code_t
qemu_default_pixman_format(int bpp
, bool native_endian
)
72 return PIXMAN_x1r5g5b5
;
78 return PIXMAN_x8r8g8b8
;
85 return PIXMAN_b8g8r8x8
;
92 /* Note: drm is little endian, pixman is native endian */
93 pixman_format_code_t
qemu_drm_format_to_pixman(uint32_t drm_format
)
97 pixman_format_code_t pixman
;
99 { DRM_FORMAT_RGB888
, PIXMAN_LE_r8g8b8
},
100 { DRM_FORMAT_ARGB8888
, PIXMAN_LE_a8r8g8b8
},
101 { DRM_FORMAT_XRGB8888
, PIXMAN_LE_x8r8g8b8
}
105 for (i
= 0; i
< ARRAY_SIZE(map
); i
++) {
106 if (drm_format
== map
[i
].drm_format
) {
107 return map
[i
].pixman
;
113 int qemu_pixman_get_type(int rshift
, int gshift
, int bshift
)
115 int type
= PIXMAN_TYPE_OTHER
;
117 if (rshift
> gshift
&& gshift
> bshift
) {
119 type
= PIXMAN_TYPE_ARGB
;
121 type
= PIXMAN_TYPE_RGBA
;
123 } else if (rshift
< gshift
&& gshift
< bshift
) {
125 type
= PIXMAN_TYPE_ABGR
;
127 type
= PIXMAN_TYPE_BGRA
;
133 pixman_format_code_t
qemu_pixman_get_format(PixelFormat
*pf
)
135 pixman_format_code_t format
;
138 type
= qemu_pixman_get_type(pf
->rshift
, pf
->gshift
, pf
->bshift
);
139 format
= PIXMAN_FORMAT(pf
->bits_per_pixel
, type
,
140 pf
->abits
, pf
->rbits
, pf
->gbits
, pf
->bbits
);
141 if (!pixman_format_supported_source(format
)) {
148 * Return true for known-good pixman conversions.
150 * UIs using pixman for format conversion can hook this into
151 * DisplayChangeListenerOps->dpy_gfx_check_format
153 bool qemu_pixman_check_format(DisplayChangeListener
*dcl
,
154 pixman_format_code_t format
)
158 case PIXMAN_x8r8g8b8
:
159 case PIXMAN_a8r8g8b8
:
160 case PIXMAN_b8g8r8x8
:
161 case PIXMAN_b8g8r8a8
:
166 case PIXMAN_x1r5g5b5
:
174 pixman_image_t
*qemu_pixman_linebuf_create(pixman_format_code_t format
,
177 pixman_image_t
*image
= pixman_image_create_bits(format
, width
, 1, NULL
, 0);
178 assert(image
!= NULL
);
182 /* fill linebuf from framebuffer */
183 void qemu_pixman_linebuf_fill(pixman_image_t
*linebuf
, pixman_image_t
*fb
,
184 int width
, int x
, int y
)
186 pixman_image_composite(PIXMAN_OP_SRC
, fb
, NULL
, linebuf
,
187 x
, y
, 0, 0, 0, 0, width
, 1);
190 /* copy linebuf to framebuffer */
191 void qemu_pixman_linebuf_copy(pixman_image_t
*fb
, int width
, int x
, int y
,
192 pixman_image_t
*linebuf
)
194 pixman_image_composite(PIXMAN_OP_SRC
, linebuf
, NULL
, fb
,
195 0, 0, 0, 0, x
, y
, width
, 1);
198 pixman_image_t
*qemu_pixman_mirror_create(pixman_format_code_t format
,
199 pixman_image_t
*image
)
201 return pixman_image_create_bits(format
,
202 pixman_image_get_width(image
),
203 pixman_image_get_height(image
),
205 pixman_image_get_stride(image
));
208 void qemu_pixman_image_unref(pixman_image_t
*image
)
213 pixman_image_unref(image
);
216 pixman_color_t
qemu_pixman_color(PixelFormat
*pf
, uint32_t color
)
220 c
.red
= ((color
& pf
->rmask
) >> pf
->rshift
) << (16 - pf
->rbits
);
221 c
.green
= ((color
& pf
->gmask
) >> pf
->gshift
) << (16 - pf
->gbits
);
222 c
.blue
= ((color
& pf
->bmask
) >> pf
->bshift
) << (16 - pf
->bbits
);
223 c
.alpha
= ((color
& pf
->amask
) >> pf
->ashift
) << (16 - pf
->abits
);
227 pixman_image_t
*qemu_pixman_glyph_from_vgafont(int height
, const uint8_t *font
,
230 pixman_image_t
*glyph
;
235 glyph
= pixman_image_create_bits(PIXMAN_a8
, 8, height
,
237 data
= (uint8_t *)pixman_image_get_data(glyph
);
240 for (y
= 0; y
< height
; y
++, font
++) {
241 for (x
= 0; x
< 8; x
++, data
++) {
242 bit
= (*font
) & (1 << (7-x
));
243 *data
= bit
? 0xff : 0x00;
249 void qemu_pixman_glyph_render(pixman_image_t
*glyph
,
250 pixman_image_t
*surface
,
251 pixman_color_t
*fgcol
,
252 pixman_color_t
*bgcol
,
253 int x
, int y
, int cw
, int ch
)
255 pixman_image_t
*ifg
= pixman_image_create_solid_fill(fgcol
);
256 pixman_image_t
*ibg
= pixman_image_create_solid_fill(bgcol
);
258 pixman_image_composite(PIXMAN_OP_SRC
, ibg
, NULL
, surface
,
262 pixman_image_composite(PIXMAN_OP_OVER
, ifg
, glyph
, surface
,
266 pixman_image_unref(ifg
);
267 pixman_image_unref(ibg
);