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 int qemu_pixman_get_type(int rshift
, int gshift
, int bshift
)
11 int type
= PIXMAN_TYPE_OTHER
;
13 if (rshift
> gshift
&& gshift
> bshift
) {
15 type
= PIXMAN_TYPE_ARGB
;
17 #if PIXMAN_VERSION >= PIXMAN_VERSION_ENCODE(0, 21, 8)
18 type
= PIXMAN_TYPE_RGBA
;
21 } else if (rshift
< gshift
&& gshift
< bshift
) {
23 type
= PIXMAN_TYPE_ABGR
;
25 #if PIXMAN_VERSION >= PIXMAN_VERSION_ENCODE(0, 16, 0)
26 type
= PIXMAN_TYPE_BGRA
;
33 pixman_format_code_t
qemu_pixman_get_format(PixelFormat
*pf
)
35 pixman_format_code_t format
;
38 type
= qemu_pixman_get_type(pf
->rshift
, pf
->gshift
, pf
->bshift
);
39 format
= PIXMAN_FORMAT(pf
->bits_per_pixel
, type
,
40 pf
->abits
, pf
->rbits
, pf
->gbits
, pf
->bbits
);
41 if (!pixman_format_supported_source(format
)) {
47 pixman_image_t
*qemu_pixman_linebuf_create(pixman_format_code_t format
,
50 pixman_image_t
*image
= pixman_image_create_bits(format
, width
, 1, NULL
, 0);
51 assert(image
!= NULL
);
55 void qemu_pixman_linebuf_fill(pixman_image_t
*linebuf
, pixman_image_t
*fb
,
56 int width
, int x
, int y
)
58 pixman_image_composite(PIXMAN_OP_SRC
, fb
, NULL
, linebuf
,
59 x
, y
, 0, 0, 0, 0, width
, 1);
62 pixman_image_t
*qemu_pixman_mirror_create(pixman_format_code_t format
,
63 pixman_image_t
*image
)
65 pixman_image_t
*mirror
;
67 mirror
= pixman_image_create_bits(format
,
68 pixman_image_get_width(image
),
69 pixman_image_get_height(image
),
71 pixman_image_get_stride(image
));
75 void qemu_pixman_image_unref(pixman_image_t
*image
)
80 pixman_image_unref(image
);
83 pixman_color_t
qemu_pixman_color(PixelFormat
*pf
, uint32_t color
)
87 c
.red
= ((color
& pf
->rmask
) >> pf
->rshift
) << (16 - pf
->rbits
);
88 c
.green
= ((color
& pf
->gmask
) >> pf
->gshift
) << (16 - pf
->gbits
);
89 c
.blue
= ((color
& pf
->bmask
) >> pf
->bshift
) << (16 - pf
->bbits
);
90 c
.alpha
= ((color
& pf
->amask
) >> pf
->ashift
) << (16 - pf
->abits
);
94 pixman_image_t
*qemu_pixman_glyph_from_vgafont(int height
, const uint8_t *font
,
97 pixman_image_t
*glyph
;
102 glyph
= pixman_image_create_bits(PIXMAN_a8
, 8, height
,
104 data
= (uint8_t *)pixman_image_get_data(glyph
);
107 for (y
= 0; y
< height
; y
++, font
++) {
108 for (x
= 0; x
< 8; x
++, data
++) {
109 bit
= (*font
) & (1 << (7-x
));
110 *data
= bit
? 0xff : 0x00;
116 void qemu_pixman_glyph_render(pixman_image_t
*glyph
,
117 pixman_image_t
*surface
,
118 pixman_color_t
*fgcol
,
119 pixman_color_t
*bgcol
,
120 int x
, int y
, int cw
, int ch
)
122 pixman_image_t
*ifg
= pixman_image_create_solid_fill(fgcol
);
123 pixman_image_t
*ibg
= pixman_image_create_solid_fill(bgcol
);
125 pixman_image_composite(PIXMAN_OP_SRC
, ibg
, NULL
, surface
,
129 pixman_image_composite(PIXMAN_OP_OVER
, ifg
, glyph
, surface
,
133 pixman_image_unref(ifg
);
134 pixman_image_unref(ibg
);