blob: c860dbb2e564ed28ae13138f1822a631086db9c3 [file] [log] [blame]
Corentin Chary70a45682010-05-03 14:31:34 +02001/*
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
27#include "vnc.h"
28
29static void hextile_enc_cord(uint8_t *ptr, int x, int y, int w, int h)
30{
31 ptr[0] = ((x & 0x0F) << 4) | (y & 0x0F);
32 ptr[1] = (((w - 1) & 0x0F) << 4) | ((h - 1) & 0x0F);
33}
34
35#define BPP 8
Corentin Chary245f7b52010-07-07 20:57:53 +020036#include "vnc-enc-hextile-template.h"
Corentin Chary70a45682010-05-03 14:31:34 +020037#undef BPP
38
39#define BPP 16
Corentin Chary245f7b52010-07-07 20:57:53 +020040#include "vnc-enc-hextile-template.h"
Corentin Chary70a45682010-05-03 14:31:34 +020041#undef BPP
42
43#define BPP 32
Corentin Chary245f7b52010-07-07 20:57:53 +020044#include "vnc-enc-hextile-template.h"
Corentin Chary70a45682010-05-03 14:31:34 +020045#undef BPP
46
47#define GENERIC
48#define BPP 8
Corentin Chary245f7b52010-07-07 20:57:53 +020049#include "vnc-enc-hextile-template.h"
Corentin Chary70a45682010-05-03 14:31:34 +020050#undef BPP
51#undef GENERIC
52
53#define GENERIC
54#define BPP 16
Corentin Chary245f7b52010-07-07 20:57:53 +020055#include "vnc-enc-hextile-template.h"
Corentin Chary70a45682010-05-03 14:31:34 +020056#undef BPP
57#undef GENERIC
58
59#define GENERIC
60#define BPP 32
Corentin Chary245f7b52010-07-07 20:57:53 +020061#include "vnc-enc-hextile-template.h"
Corentin Chary70a45682010-05-03 14:31:34 +020062#undef BPP
63#undef GENERIC
64
Corentin Charya8852112010-05-19 09:24:09 +020065int vnc_hextile_send_framebuffer_update(VncState *vs, int x,
66 int y, int w, int h)
Corentin Chary70a45682010-05-03 14:31:34 +020067{
68 int i, j;
69 int has_fg, has_bg;
70 uint8_t *last_fg, *last_bg;
71 VncDisplay *vd = vs->vd;
72
Anthony Liguori7267c092011-08-20 22:09:37 -050073 last_fg = (uint8_t *) g_malloc(vd->server->pf.bytes_per_pixel);
74 last_bg = (uint8_t *) g_malloc(vd->server->pf.bytes_per_pixel);
Corentin Chary70a45682010-05-03 14:31:34 +020075 has_fg = has_bg = 0;
76 for (j = y; j < (y + h); j += 16) {
77 for (i = x; i < (x + w); i += 16) {
Corentin Charyd1af0e02010-07-07 20:57:59 +020078 vs->hextile.send_tile(vs, i, j,
Corentin Chary70a45682010-05-03 14:31:34 +020079 MIN(16, x + w - i), MIN(16, y + h - j),
80 last_bg, last_fg, &has_bg, &has_fg);
81 }
82 }
Stefan Weilae878b12011-10-07 21:15:20 +020083 g_free(last_fg);
84 g_free(last_bg);
Corentin Chary70a45682010-05-03 14:31:34 +020085
Corentin Charya8852112010-05-19 09:24:09 +020086 return 1;
Corentin Chary70a45682010-05-03 14:31:34 +020087}
88
89void vnc_hextile_set_pixel_conversion(VncState *vs, int generic)
90{
91 if (!generic) {
92 switch (vs->ds->surface->pf.bits_per_pixel) {
93 case 8:
Corentin Charyd1af0e02010-07-07 20:57:59 +020094 vs->hextile.send_tile = send_hextile_tile_8;
Corentin Chary70a45682010-05-03 14:31:34 +020095 break;
96 case 16:
Corentin Charyd1af0e02010-07-07 20:57:59 +020097 vs->hextile.send_tile = send_hextile_tile_16;
Corentin Chary70a45682010-05-03 14:31:34 +020098 break;
99 case 32:
Corentin Charyd1af0e02010-07-07 20:57:59 +0200100 vs->hextile.send_tile = send_hextile_tile_32;
Corentin Chary70a45682010-05-03 14:31:34 +0200101 break;
102 }
103 } else {
104 switch (vs->ds->surface->pf.bits_per_pixel) {
105 case 8:
Corentin Charyd1af0e02010-07-07 20:57:59 +0200106 vs->hextile.send_tile = send_hextile_tile_generic_8;
Corentin Chary70a45682010-05-03 14:31:34 +0200107 break;
108 case 16:
Corentin Charyd1af0e02010-07-07 20:57:59 +0200109 vs->hextile.send_tile = send_hextile_tile_generic_16;
Corentin Chary70a45682010-05-03 14:31:34 +0200110 break;
111 case 32:
Corentin Charyd1af0e02010-07-07 20:57:59 +0200112 vs->hextile.send_tile = send_hextile_tile_generic_32;
Corentin Chary70a45682010-05-03 14:31:34 +0200113 break;
114 }
115 }
116}