Corentin Chary | 70a4568 | 2010-05-03 14:31:34 +0200 | [diff] [blame] | 1 | /* |
| 2 | * QEMU VNC display driver: hextile encoding |
| 3 | * |
| 4 | * Copyright (C) 2006 Anthony Liguori <anthony@codemonkey.ws> |
| 5 | * Copyright (C) 2006 Fabrice Bellard |
| 6 | * Copyright (C) 2009 Red Hat, Inc |
| 7 | * |
| 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 | * of this software and associated documentation files (the "Software"), to deal |
| 10 | * in the Software without restriction, including without limitation the rights |
| 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 12 | * copies of the Software, and to permit persons to whom the Software is |
| 13 | * furnished to do so, subject to the following conditions: |
| 14 | * |
| 15 | * The above copyright notice and this permission notice shall be included in |
| 16 | * all copies or substantial portions of the Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 21 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 24 | * THE SOFTWARE. |
| 25 | */ |
| 26 | |
Peter Maydell | e16f4c8 | 2016-01-29 17:49:51 +0000 | [diff] [blame] | 27 | #include "qemu/osdep.h" |
Corentin Chary | 70a4568 | 2010-05-03 14:31:34 +0200 | [diff] [blame] | 28 | #include "vnc.h" |
| 29 | |
| 30 | static void hextile_enc_cord(uint8_t *ptr, int x, int y, int w, int h) |
| 31 | { |
| 32 | ptr[0] = ((x & 0x0F) << 4) | (y & 0x0F); |
| 33 | ptr[1] = (((w - 1) & 0x0F) << 4) | ((h - 1) & 0x0F); |
| 34 | } |
| 35 | |
Corentin Chary | 70a4568 | 2010-05-03 14:31:34 +0200 | [diff] [blame] | 36 | #define BPP 32 |
Corentin Chary | 245f7b5 | 2010-07-07 20:57:53 +0200 | [diff] [blame] | 37 | #include "vnc-enc-hextile-template.h" |
Corentin Chary | 70a4568 | 2010-05-03 14:31:34 +0200 | [diff] [blame] | 38 | #undef BPP |
| 39 | |
| 40 | #define GENERIC |
Corentin Chary | 70a4568 | 2010-05-03 14:31:34 +0200 | [diff] [blame] | 41 | #define BPP 32 |
Corentin Chary | 245f7b5 | 2010-07-07 20:57:53 +0200 | [diff] [blame] | 42 | #include "vnc-enc-hextile-template.h" |
Corentin Chary | 70a4568 | 2010-05-03 14:31:34 +0200 | [diff] [blame] | 43 | #undef BPP |
| 44 | #undef GENERIC |
| 45 | |
Corentin Chary | a885211 | 2010-05-19 09:24:09 +0200 | [diff] [blame] | 46 | int vnc_hextile_send_framebuffer_update(VncState *vs, int x, |
| 47 | int y, int w, int h) |
Corentin Chary | 70a4568 | 2010-05-03 14:31:34 +0200 | [diff] [blame] | 48 | { |
| 49 | int i, j; |
| 50 | int has_fg, has_bg; |
| 51 | uint8_t *last_fg, *last_bg; |
Corentin Chary | 70a4568 | 2010-05-03 14:31:34 +0200 | [diff] [blame] | 52 | |
Gerd Hoffmann | 9f64916 | 2012-10-10 13:29:43 +0200 | [diff] [blame] | 53 | last_fg = (uint8_t *) g_malloc(VNC_SERVER_FB_BYTES); |
| 54 | last_bg = (uint8_t *) g_malloc(VNC_SERVER_FB_BYTES); |
Corentin Chary | 70a4568 | 2010-05-03 14:31:34 +0200 | [diff] [blame] | 55 | has_fg = has_bg = 0; |
| 56 | for (j = y; j < (y + h); j += 16) { |
| 57 | for (i = x; i < (x + w); i += 16) { |
Corentin Chary | d1af0e0 | 2010-07-07 20:57:59 +0200 | [diff] [blame] | 58 | vs->hextile.send_tile(vs, i, j, |
Corentin Chary | 70a4568 | 2010-05-03 14:31:34 +0200 | [diff] [blame] | 59 | MIN(16, x + w - i), MIN(16, y + h - j), |
| 60 | last_bg, last_fg, &has_bg, &has_fg); |
| 61 | } |
| 62 | } |
Stefan Weil | ae878b1 | 2011-10-07 21:15:20 +0200 | [diff] [blame] | 63 | g_free(last_fg); |
| 64 | g_free(last_bg); |
Corentin Chary | 70a4568 | 2010-05-03 14:31:34 +0200 | [diff] [blame] | 65 | |
Corentin Chary | a885211 | 2010-05-19 09:24:09 +0200 | [diff] [blame] | 66 | return 1; |
Corentin Chary | 70a4568 | 2010-05-03 14:31:34 +0200 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | void vnc_hextile_set_pixel_conversion(VncState *vs, int generic) |
| 70 | { |
| 71 | if (!generic) { |
Gerd Hoffmann | 9f64916 | 2012-10-10 13:29:43 +0200 | [diff] [blame] | 72 | switch (VNC_SERVER_FB_BITS) { |
Gerd Hoffmann | 9f64916 | 2012-10-10 13:29:43 +0200 | [diff] [blame] | 73 | case 32: |
| 74 | vs->hextile.send_tile = send_hextile_tile_32; |
| 75 | break; |
Corentin Chary | 70a4568 | 2010-05-03 14:31:34 +0200 | [diff] [blame] | 76 | } |
| 77 | } else { |
Gerd Hoffmann | 9f64916 | 2012-10-10 13:29:43 +0200 | [diff] [blame] | 78 | switch (VNC_SERVER_FB_BITS) { |
Gerd Hoffmann | 9f64916 | 2012-10-10 13:29:43 +0200 | [diff] [blame] | 79 | case 32: |
| 80 | vs->hextile.send_tile = send_hextile_tile_generic_32; |
| 81 | break; |
Corentin Chary | 70a4568 | 2010-05-03 14:31:34 +0200 | [diff] [blame] | 82 | } |
| 83 | } |
| 84 | } |