Gerd Hoffmann | daa8e5a | 2012-11-13 09:38:06 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
Gerd Hoffmann | d2ec7e2 | 2012-09-25 16:23:24 +0200 | [diff] [blame] | 6 | #include "qemu-pixman.h" |
| 7 | |
| 8 | int qemu_pixman_get_type(int rshift, int gshift, int bshift) |
| 9 | { |
| 10 | int type = PIXMAN_TYPE_OTHER; |
| 11 | |
| 12 | if (rshift > gshift && gshift > bshift) { |
| 13 | if (bshift == 0) { |
| 14 | type = PIXMAN_TYPE_ARGB; |
| 15 | } else { |
| 16 | #if PIXMAN_VERSION >= PIXMAN_VERSION_ENCODE(0, 21, 8) |
| 17 | type = PIXMAN_TYPE_RGBA; |
| 18 | #endif |
| 19 | } |
| 20 | } else if (rshift < gshift && gshift < bshift) { |
| 21 | if (rshift == 0) { |
| 22 | type = PIXMAN_TYPE_ABGR; |
| 23 | } else { |
Gerd Hoffmann | fbddfc7 | 2012-12-14 08:54:21 +0100 | [diff] [blame] | 24 | #if PIXMAN_VERSION >= PIXMAN_VERSION_ENCODE(0, 16, 0) |
Gerd Hoffmann | d2ec7e2 | 2012-09-25 16:23:24 +0200 | [diff] [blame] | 25 | type = PIXMAN_TYPE_BGRA; |
Alexander Graf | 6e72719 | 2012-11-26 19:49:58 +0100 | [diff] [blame] | 26 | #endif |
Gerd Hoffmann | d2ec7e2 | 2012-09-25 16:23:24 +0200 | [diff] [blame] | 27 | } |
| 28 | } |
| 29 | return type; |
| 30 | } |
| 31 | |
| 32 | pixman_format_code_t qemu_pixman_get_format(PixelFormat *pf) |
| 33 | { |
| 34 | pixman_format_code_t format; |
| 35 | int type; |
| 36 | |
| 37 | type = qemu_pixman_get_type(pf->rshift, pf->gshift, pf->bshift); |
| 38 | format = PIXMAN_FORMAT(pf->bits_per_pixel, type, |
| 39 | pf->abits, pf->rbits, pf->gbits, pf->bbits); |
| 40 | if (!pixman_format_supported_source(format)) { |
| 41 | return 0; |
| 42 | } |
| 43 | return format; |
| 44 | } |
| 45 | |
| 46 | pixman_image_t *qemu_pixman_linebuf_create(pixman_format_code_t format, |
| 47 | int width) |
| 48 | { |
| 49 | pixman_image_t *image = pixman_image_create_bits(format, width, 1, NULL, 0); |
| 50 | assert(image != NULL); |
| 51 | return image; |
| 52 | } |
| 53 | |
| 54 | void qemu_pixman_linebuf_fill(pixman_image_t *linebuf, pixman_image_t *fb, |
Gerd Hoffmann | bc210eb | 2012-12-14 07:54:24 +0000 | [diff] [blame^] | 55 | int width, int x, int y) |
Gerd Hoffmann | d2ec7e2 | 2012-09-25 16:23:24 +0200 | [diff] [blame] | 56 | { |
| 57 | pixman_image_composite(PIXMAN_OP_SRC, fb, NULL, linebuf, |
Gerd Hoffmann | bc210eb | 2012-12-14 07:54:24 +0000 | [diff] [blame^] | 58 | x, y, 0, 0, 0, 0, width, 1); |
Gerd Hoffmann | d2ec7e2 | 2012-09-25 16:23:24 +0200 | [diff] [blame] | 59 | } |
| 60 | |
Gerd Hoffmann | d9a8656 | 2012-11-02 09:12:49 +0100 | [diff] [blame] | 61 | pixman_image_t *qemu_pixman_mirror_create(pixman_format_code_t format, |
| 62 | pixman_image_t *image) |
| 63 | { |
| 64 | pixman_image_t *mirror; |
| 65 | |
| 66 | mirror = pixman_image_create_bits(format, |
| 67 | pixman_image_get_width(image), |
| 68 | pixman_image_get_height(image), |
| 69 | NULL, |
| 70 | pixman_image_get_stride(image)); |
| 71 | return mirror; |
| 72 | } |
| 73 | |
Gerd Hoffmann | d2ec7e2 | 2012-09-25 16:23:24 +0200 | [diff] [blame] | 74 | void qemu_pixman_image_unref(pixman_image_t *image) |
| 75 | { |
| 76 | if (image == NULL) { |
| 77 | return; |
| 78 | } |
| 79 | pixman_image_unref(image); |
| 80 | } |