1245f7b51SCorentin Chary /*
2245f7b51SCorentin Chary * QEMU VNC display driver: hextile encoding
3245f7b51SCorentin Chary *
4245f7b51SCorentin Chary * Copyright (C) 2006 Anthony Liguori <anthony@codemonkey.ws>
5245f7b51SCorentin Chary * Copyright (C) 2006 Fabrice Bellard
6245f7b51SCorentin Chary * Copyright (C) 2009 Red Hat, Inc
7245f7b51SCorentin Chary *
8245f7b51SCorentin Chary * Permission is hereby granted, free of charge, to any person obtaining a copy
9245f7b51SCorentin Chary * of this software and associated documentation files (the "Software"), to deal
10245f7b51SCorentin Chary * in the Software without restriction, including without limitation the rights
11245f7b51SCorentin Chary * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12245f7b51SCorentin Chary * copies of the Software, and to permit persons to whom the Software is
13245f7b51SCorentin Chary * furnished to do so, subject to the following conditions:
14245f7b51SCorentin Chary *
15245f7b51SCorentin Chary * The above copyright notice and this permission notice shall be included in
16245f7b51SCorentin Chary * all copies or substantial portions of the Software.
17245f7b51SCorentin Chary *
18245f7b51SCorentin Chary * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19245f7b51SCorentin Chary * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20245f7b51SCorentin Chary * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21245f7b51SCorentin Chary * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22245f7b51SCorentin Chary * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23245f7b51SCorentin Chary * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24245f7b51SCorentin Chary * THE SOFTWARE.
25245f7b51SCorentin Chary */
26245f7b51SCorentin Chary
27e16f4c87SPeter Maydell #include "qemu/osdep.h"
28245f7b51SCorentin Chary #include "vnc.h"
29245f7b51SCorentin Chary
hextile_enc_cord(uint8_t * ptr,int x,int y,int w,int h)30245f7b51SCorentin Chary static void hextile_enc_cord(uint8_t *ptr, int x, int y, int w, int h)
31245f7b51SCorentin Chary {
32245f7b51SCorentin Chary ptr[0] = ((x & 0x0F) << 4) | (y & 0x0F);
33245f7b51SCorentin Chary ptr[1] = (((w - 1) & 0x0F) << 4) | ((h - 1) & 0x0F);
34245f7b51SCorentin Chary }
35245f7b51SCorentin Chary
36245f7b51SCorentin Chary #define BPP 32
37245f7b51SCorentin Chary #include "vnc-enc-hextile-template.h"
38245f7b51SCorentin Chary #undef BPP
39245f7b51SCorentin Chary
40245f7b51SCorentin Chary #define GENERIC
41245f7b51SCorentin Chary #define BPP 32
42245f7b51SCorentin Chary #include "vnc-enc-hextile-template.h"
43245f7b51SCorentin Chary #undef BPP
44245f7b51SCorentin Chary #undef GENERIC
45245f7b51SCorentin Chary
vnc_hextile_send_framebuffer_update(VncState * vs,int x,int y,int w,int h)46245f7b51SCorentin Chary int vnc_hextile_send_framebuffer_update(VncState *vs, int x,
47245f7b51SCorentin Chary int y, int w, int h)
48245f7b51SCorentin Chary {
49245f7b51SCorentin Chary int i, j;
50245f7b51SCorentin Chary int has_fg, has_bg;
51245f7b51SCorentin Chary uint8_t *last_fg, *last_bg;
52245f7b51SCorentin Chary
53*0a553c12SMarkus Armbruster last_fg = g_malloc(VNC_SERVER_FB_BYTES);
54*0a553c12SMarkus Armbruster last_bg = g_malloc(VNC_SERVER_FB_BYTES);
55245f7b51SCorentin Chary has_fg = has_bg = 0;
56245f7b51SCorentin Chary for (j = y; j < (y + h); j += 16) {
57245f7b51SCorentin Chary for (i = x; i < (x + w); i += 16) {
58d1af0e05SCorentin Chary vs->hextile.send_tile(vs, i, j,
59245f7b51SCorentin Chary MIN(16, x + w - i), MIN(16, y + h - j),
60245f7b51SCorentin Chary last_bg, last_fg, &has_bg, &has_fg);
61245f7b51SCorentin Chary }
62245f7b51SCorentin Chary }
63ae878b17SStefan Weil g_free(last_fg);
64ae878b17SStefan Weil g_free(last_bg);
65245f7b51SCorentin Chary
66245f7b51SCorentin Chary return 1;
67245f7b51SCorentin Chary }
68245f7b51SCorentin Chary
vnc_hextile_set_pixel_conversion(VncState * vs,int generic)69245f7b51SCorentin Chary void vnc_hextile_set_pixel_conversion(VncState *vs, int generic)
70245f7b51SCorentin Chary {
71245f7b51SCorentin Chary if (!generic) {
729f64916dSGerd Hoffmann switch (VNC_SERVER_FB_BITS) {
73245f7b51SCorentin Chary case 32:
74d1af0e05SCorentin Chary vs->hextile.send_tile = send_hextile_tile_32;
75245f7b51SCorentin Chary break;
76245f7b51SCorentin Chary }
77245f7b51SCorentin Chary } else {
789f64916dSGerd Hoffmann switch (VNC_SERVER_FB_BITS) {
79245f7b51SCorentin Chary case 32:
80d1af0e05SCorentin Chary vs->hextile.send_tile = send_hextile_tile_generic_32;
81245f7b51SCorentin Chary break;
82245f7b51SCorentin Chary }
83245f7b51SCorentin Chary }
84245f7b51SCorentin Chary }
85