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-common.h"
7 #include "ui/console.h"
9 PixelFormat
qemu_pixelformat_from_pixman(pixman_format_code_t format
)
14 bpp
= pf
.bits_per_pixel
= PIXMAN_FORMAT_BPP(format
);
15 pf
.bytes_per_pixel
= PIXMAN_FORMAT_BPP(format
) / 8;
16 pf
.depth
= PIXMAN_FORMAT_DEPTH(format
);
18 pf
.abits
= PIXMAN_FORMAT_A(format
);
19 pf
.rbits
= PIXMAN_FORMAT_R(format
);
20 pf
.gbits
= PIXMAN_FORMAT_G(format
);
21 pf
.bbits
= PIXMAN_FORMAT_B(format
);
23 switch (PIXMAN_FORMAT_TYPE(format
)) {
24 case PIXMAN_TYPE_ARGB
:
25 pf
.ashift
= pf
.bbits
+ pf
.gbits
+ pf
.rbits
;
26 pf
.rshift
= pf
.bbits
+ pf
.gbits
;
30 case PIXMAN_TYPE_ABGR
:
31 pf
.ashift
= pf
.rbits
+ pf
.gbits
+ pf
.bbits
;
32 pf
.bshift
= pf
.rbits
+ pf
.gbits
;
36 case PIXMAN_TYPE_BGRA
:
37 pf
.bshift
= bpp
- pf
.bbits
;
38 pf
.gshift
= bpp
- (pf
.bbits
+ pf
.gbits
);
39 pf
.rshift
= bpp
- (pf
.bbits
+ pf
.gbits
+ pf
.rbits
);
42 case PIXMAN_TYPE_RGBA
:
43 pf
.rshift
= bpp
- pf
.rbits
;
44 pf
.gshift
= bpp
- (pf
.rbits
+ pf
.gbits
);
45 pf
.bshift
= bpp
- (pf
.rbits
+ pf
.gbits
+ pf
.bbits
);
49 g_assert_not_reached();
53 pf
.amax
= (1 << pf
.abits
) - 1;
54 pf
.rmax
= (1 << pf
.rbits
) - 1;
55 pf
.gmax
= (1 << pf
.gbits
) - 1;
56 pf
.bmax
= (1 << pf
.bbits
) - 1;
57 pf
.amask
= pf
.amax
<< pf
.ashift
;
58 pf
.rmask
= pf
.rmax
<< pf
.rshift
;
59 pf
.gmask
= pf
.gmax
<< pf
.gshift
;
60 pf
.bmask
= pf
.bmax
<< pf
.bshift
;
65 pixman_format_code_t
qemu_default_pixman_format(int bpp
, bool native_endian
)
70 return PIXMAN_x1r5g5b5
;
76 return PIXMAN_x8r8g8b8
;
83 return PIXMAN_b8g8r8x8
;
90 int qemu_pixman_get_type(int rshift
, int gshift
, int bshift
)
92 int type
= PIXMAN_TYPE_OTHER
;
94 if (rshift
> gshift
&& gshift
> bshift
) {
96 type
= PIXMAN_TYPE_ARGB
;
98 #if PIXMAN_VERSION >= PIXMAN_VERSION_ENCODE(0, 21, 8)
99 type
= PIXMAN_TYPE_RGBA
;
102 } else if (rshift
< gshift
&& gshift
< bshift
) {
104 type
= PIXMAN_TYPE_ABGR
;
106 #if PIXMAN_VERSION >= PIXMAN_VERSION_ENCODE(0, 16, 0)
107 type
= PIXMAN_TYPE_BGRA
;
114 pixman_format_code_t
qemu_pixman_get_format(PixelFormat
*pf
)
116 pixman_format_code_t format
;
119 type
= qemu_pixman_get_type(pf
->rshift
, pf
->gshift
, pf
->bshift
);
120 format
= PIXMAN_FORMAT(pf
->bits_per_pixel
, type
,
121 pf
->abits
, pf
->rbits
, pf
->gbits
, pf
->bbits
);
122 if (!pixman_format_supported_source(format
)) {
129 * Return true for known-good pixman conversions.
131 * UIs using pixman for format conversion can hook this into
132 * DisplayChangeListenerOps->dpy_gfx_check_format
134 bool qemu_pixman_check_format(DisplayChangeListener
*dcl
,
135 pixman_format_code_t format
)
139 case PIXMAN_x8r8g8b8
:
140 case PIXMAN_a8r8g8b8
:
141 case PIXMAN_b8g8r8x8
:
142 case PIXMAN_b8g8r8a8
:
147 case PIXMAN_x1r5g5b5
:
155 pixman_image_t
*qemu_pixman_linebuf_create(pixman_format_code_t format
,
158 pixman_image_t
*image
= pixman_image_create_bits(format
, width
, 1, NULL
, 0);
159 assert(image
!= NULL
);
163 /* fill linebuf from framebuffer */
164 void qemu_pixman_linebuf_fill(pixman_image_t
*linebuf
, pixman_image_t
*fb
,
165 int width
, int x
, int y
)
167 pixman_image_composite(PIXMAN_OP_SRC
, fb
, NULL
, linebuf
,
168 x
, y
, 0, 0, 0, 0, width
, 1);
171 /* copy linebuf to framebuffer */
172 void qemu_pixman_linebuf_copy(pixman_image_t
*fb
, int width
, int x
, int y
,
173 pixman_image_t
*linebuf
)
175 pixman_image_composite(PIXMAN_OP_SRC
, linebuf
, NULL
, fb
,
176 0, 0, 0, 0, x
, y
, width
, 1);
179 pixman_image_t
*qemu_pixman_mirror_create(pixman_format_code_t format
,
180 pixman_image_t
*image
)
182 pixman_image_t
*mirror
;
184 mirror
= pixman_image_create_bits(format
,
185 pixman_image_get_width(image
),
186 pixman_image_get_height(image
),
188 pixman_image_get_stride(image
));
192 void qemu_pixman_image_unref(pixman_image_t
*image
)
197 pixman_image_unref(image
);
200 pixman_color_t
qemu_pixman_color(PixelFormat
*pf
, uint32_t color
)
204 c
.red
= ((color
& pf
->rmask
) >> pf
->rshift
) << (16 - pf
->rbits
);
205 c
.green
= ((color
& pf
->gmask
) >> pf
->gshift
) << (16 - pf
->gbits
);
206 c
.blue
= ((color
& pf
->bmask
) >> pf
->bshift
) << (16 - pf
->bbits
);
207 c
.alpha
= ((color
& pf
->amask
) >> pf
->ashift
) << (16 - pf
->abits
);
211 pixman_image_t
*qemu_pixman_glyph_from_vgafont(int height
, const uint8_t *font
,
214 pixman_image_t
*glyph
;
219 glyph
= pixman_image_create_bits(PIXMAN_a8
, 8, height
,
221 data
= (uint8_t *)pixman_image_get_data(glyph
);
224 for (y
= 0; y
< height
; y
++, font
++) {
225 for (x
= 0; x
< 8; x
++, data
++) {
226 bit
= (*font
) & (1 << (7-x
));
227 *data
= bit
? 0xff : 0x00;
233 void qemu_pixman_glyph_render(pixman_image_t
*glyph
,
234 pixman_image_t
*surface
,
235 pixman_color_t
*fgcol
,
236 pixman_color_t
*bgcol
,
237 int x
, int y
, int cw
, int ch
)
239 pixman_image_t
*ifg
= pixman_image_create_solid_fill(fgcol
);
240 pixman_image_t
*ibg
= pixman_image_create_solid_fill(bgcol
);
242 pixman_image_composite(PIXMAN_OP_SRC
, ibg
, NULL
, surface
,
246 pixman_image_composite(PIXMAN_OP_OVER
, ifg
, glyph
, surface
,
250 pixman_image_unref(ifg
);
251 pixman_image_unref(ibg
);