blob: 254bd8ce100d8b9fb2ef64cb31d497fff13909d8 [file] [log] [blame]
Gerd Hoffmanndaa8e5a2012-11-13 09:38:06 +01001/*
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
Peter Maydell0b087862013-01-21 12:03:47 +00006#include "qemu-common.h"
7#include "ui/console.h"
Gerd Hoffmannd2ec7e22012-09-25 16:23:24 +02008
9int qemu_pixman_get_type(int rshift, int gshift, int bshift)
10{
11 int type = PIXMAN_TYPE_OTHER;
12
13 if (rshift > gshift && gshift > bshift) {
14 if (bshift == 0) {
15 type = PIXMAN_TYPE_ARGB;
16 } else {
17#if PIXMAN_VERSION >= PIXMAN_VERSION_ENCODE(0, 21, 8)
18 type = PIXMAN_TYPE_RGBA;
19#endif
20 }
21 } else if (rshift < gshift && gshift < bshift) {
22 if (rshift == 0) {
23 type = PIXMAN_TYPE_ABGR;
24 } else {
Gerd Hoffmannfbddfc72012-12-14 08:54:21 +010025#if PIXMAN_VERSION >= PIXMAN_VERSION_ENCODE(0, 16, 0)
Gerd Hoffmannd2ec7e22012-09-25 16:23:24 +020026 type = PIXMAN_TYPE_BGRA;
Alexander Graf6e727192012-11-26 19:49:58 +010027#endif
Gerd Hoffmannd2ec7e22012-09-25 16:23:24 +020028 }
29 }
30 return type;
31}
32
33pixman_format_code_t qemu_pixman_get_format(PixelFormat *pf)
34{
35 pixman_format_code_t format;
36 int type;
37
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)) {
42 return 0;
43 }
44 return format;
45}
46
47pixman_image_t *qemu_pixman_linebuf_create(pixman_format_code_t format,
48 int width)
49{
50 pixman_image_t *image = pixman_image_create_bits(format, width, 1, NULL, 0);
51 assert(image != NULL);
52 return image;
53}
54
55void qemu_pixman_linebuf_fill(pixman_image_t *linebuf, pixman_image_t *fb,
Gerd Hoffmannbc210eb2012-12-14 07:54:24 +000056 int width, int x, int y)
Gerd Hoffmannd2ec7e22012-09-25 16:23:24 +020057{
58 pixman_image_composite(PIXMAN_OP_SRC, fb, NULL, linebuf,
Gerd Hoffmannbc210eb2012-12-14 07:54:24 +000059 x, y, 0, 0, 0, 0, width, 1);
Gerd Hoffmannd2ec7e22012-09-25 16:23:24 +020060}
61
Gerd Hoffmannd9a86562012-11-02 09:12:49 +010062pixman_image_t *qemu_pixman_mirror_create(pixman_format_code_t format,
63 pixman_image_t *image)
64{
65 pixman_image_t *mirror;
66
67 mirror = pixman_image_create_bits(format,
68 pixman_image_get_width(image),
69 pixman_image_get_height(image),
70 NULL,
71 pixman_image_get_stride(image));
72 return mirror;
73}
74
Gerd Hoffmannd2ec7e22012-09-25 16:23:24 +020075void qemu_pixman_image_unref(pixman_image_t *image)
76{
77 if (image == NULL) {
78 return;
79 }
80 pixman_image_unref(image);
81}
Gerd Hoffmann867c5382013-03-06 14:14:17 +010082
83pixman_color_t qemu_pixman_color(PixelFormat *pf, uint32_t color)
84{
85 pixman_color_t c;
86
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);
91 return c;
92}
Gerd Hoffmannb7627952013-03-07 15:23:48 +010093
94pixman_image_t *qemu_pixman_glyph_from_vgafont(int height, const uint8_t *font,
95 unsigned int ch)
96{
97 pixman_image_t *glyph;
98 uint8_t *data;
99 bool bit;
100 int x, y;
101
102 glyph = pixman_image_create_bits(PIXMAN_a8, 8, height,
103 NULL, 0);
104 data = (uint8_t *)pixman_image_get_data(glyph);
105
106 font += height * ch;
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;
111 }
112 }
113 return glyph;
114}
115
116void 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)
121{
122 pixman_image_t *ifg = pixman_image_create_solid_fill(fgcol);
123 pixman_image_t *ibg = pixman_image_create_solid_fill(bgcol);
124
125 pixman_image_composite(PIXMAN_OP_SRC, ibg, NULL, surface,
126 0, 0, 0, 0,
127 cw * x, ch * y,
128 cw, ch);
129 pixman_image_composite(PIXMAN_OP_OVER, ifg, glyph, surface,
130 0, 0, 0, 0,
131 cw * x, ch * y,
132 cw, ch);
133 pixman_image_unref(ifg);
134 pixman_image_unref(ibg);
135}