Skip to content
Snippets Groups Projects
Commit d1af0e05 authored by Corentin Chary's avatar Corentin Chary Committed by Anthony Liguori
Browse files

vnc: encapsulate encoding members


This will allow to implement the threaded VNC server in a
more cleaner way.

Signed-off-by: default avatarCorentin Chary <corentincj@iksaif.net>
Signed-off-by: default avatarAnthony Liguori <aliguori@us.ibm.com>
parent 5136a052
No related branches found
No related tags found
No related merge requests found
......@@ -75,7 +75,7 @@ int vnc_hextile_send_framebuffer_update(VncState *vs, int x,
has_fg = has_bg = 0;
for (j = y; j < (y + h); j += 16) {
for (i = x; i < (x + w); i += 16) {
vs->send_hextile_tile(vs, i, j,
vs->hextile.send_tile(vs, i, j,
MIN(16, x + w - i), MIN(16, y + h - j),
last_bg, last_fg, &has_bg, &has_fg);
}
......@@ -91,25 +91,25 @@ void vnc_hextile_set_pixel_conversion(VncState *vs, int generic)
if (!generic) {
switch (vs->ds->surface->pf.bits_per_pixel) {
case 8:
vs->send_hextile_tile = send_hextile_tile_8;
vs->hextile.send_tile = send_hextile_tile_8;
break;
case 16:
vs->send_hextile_tile = send_hextile_tile_16;
vs->hextile.send_tile = send_hextile_tile_16;
break;
case 32:
vs->send_hextile_tile = send_hextile_tile_32;
vs->hextile.send_tile = send_hextile_tile_32;
break;
}
} else {
switch (vs->ds->surface->pf.bits_per_pixel) {
case 8:
vs->send_hextile_tile = send_hextile_tile_generic_8;
vs->hextile.send_tile = send_hextile_tile_generic_8;
break;
case 16:
vs->send_hextile_tile = send_hextile_tile_generic_16;
vs->hextile.send_tile = send_hextile_tile_generic_16;
break;
case 32:
vs->send_hextile_tile = send_hextile_tile_generic_32;
vs->hextile.send_tile = send_hextile_tile_generic_32;
break;
}
}
......
This diff is collapsed.
......@@ -47,21 +47,21 @@ void vnc_zlib_zfree(void *x, void *addr)
static void vnc_zlib_start(VncState *vs)
{
buffer_reset(&vs->zlib);
buffer_reset(&vs->zlib.zlib);
// make the output buffer be the zlib buffer, so we can compress it later
vs->zlib_tmp = vs->output;
vs->output = vs->zlib;
vs->zlib.tmp = vs->output;
vs->output = vs->zlib.zlib;
}
static int vnc_zlib_stop(VncState *vs)
{
z_streamp zstream = &vs->zlib_stream;
z_streamp zstream = &vs->zlib.stream;
int previous_out;
// switch back to normal output/zlib buffers
vs->zlib = vs->output;
vs->output = vs->zlib_tmp;
vs->zlib.zlib = vs->output;
vs->output = vs->zlib.tmp;
// compress the zlib buffer
......@@ -75,7 +75,7 @@ static int vnc_zlib_stop(VncState *vs)
zstream->zalloc = vnc_zlib_zalloc;
zstream->zfree = vnc_zlib_zfree;
err = deflateInit2(zstream, vs->tight_compression, Z_DEFLATED, MAX_WBITS,
err = deflateInit2(zstream, vs->tight.compression, Z_DEFLATED, MAX_WBITS,
MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY);
if (err != Z_OK) {
......@@ -83,24 +83,24 @@ static int vnc_zlib_stop(VncState *vs)
return -1;
}
vs->zlib_level = vs->tight_compression;
vs->zlib.level = vs->tight.compression;
zstream->opaque = vs;
}
if (vs->tight_compression != vs->zlib_level) {
if (deflateParams(zstream, vs->tight_compression,
if (vs->tight.compression != vs->zlib.level) {
if (deflateParams(zstream, vs->tight.compression,
Z_DEFAULT_STRATEGY) != Z_OK) {
return -1;
}
vs->zlib_level = vs->tight_compression;
vs->zlib.level = vs->tight.compression;
}
// reserve memory in output buffer
buffer_reserve(&vs->output, vs->zlib.offset + 64);
buffer_reserve(&vs->output, vs->zlib.zlib.offset + 64);
// set pointers
zstream->next_in = vs->zlib.buffer;
zstream->avail_in = vs->zlib.offset;
zstream->next_in = vs->zlib.zlib.buffer;
zstream->avail_in = vs->zlib.zlib.offset;
zstream->next_out = vs->output.buffer + vs->output.offset;
zstream->avail_out = vs->output.capacity - vs->output.offset;
zstream->data_type = Z_BINARY;
......@@ -145,8 +145,8 @@ int vnc_zlib_send_framebuffer_update(VncState *vs, int x, int y, int w, int h)
void vnc_zlib_clear(VncState *vs)
{
if (vs->zlib_stream.opaque) {
deflateEnd(&vs->zlib_stream);
if (vs->zlib.stream.opaque) {
deflateEnd(&vs->zlib.stream);
}
buffer_free(&vs->zlib);
buffer_free(&vs->zlib.zlib);
}
......@@ -1642,8 +1642,8 @@ static void set_encodings(VncState *vs, int32_t *encodings, size_t n_encodings)
vs->features = 0;
vs->vnc_encoding = 0;
vs->tight_compression = 9;
vs->tight_quality = -1; /* Lossless by default */
vs->tight.compression = 9;
vs->tight.quality = -1; /* Lossless by default */
vs->absolute = -1;
/*
......@@ -1695,10 +1695,10 @@ static void set_encodings(VncState *vs, int32_t *encodings, size_t n_encodings)
vs->features |= VNC_FEATURE_WMVI_MASK;
break;
case VNC_ENCODING_COMPRESSLEVEL0 ... VNC_ENCODING_COMPRESSLEVEL0 + 9:
vs->tight_compression = (enc & 0x0F);
vs->tight.compression = (enc & 0x0F);
break;
case VNC_ENCODING_QUALITYLEVEL0 ... VNC_ENCODING_QUALITYLEVEL0 + 9:
vs->tight_quality = (enc & 0x0F);
vs->tight.quality = (enc & 0x0F);
break;
default:
VNC_DEBUG("Unknown encoding: %d (0x%.8x): %d\n", i, enc, enc);
......
......@@ -122,6 +122,36 @@ struct VncDisplay
#endif
};
typedef struct VncTight {
int type;
uint8_t quality;
uint8_t compression;
uint8_t pixel24;
Buffer tight;
Buffer tmp;
Buffer zlib;
Buffer gradient;
#ifdef CONFIG_VNC_JPEG
Buffer jpeg;
#endif
#ifdef CONFIG_VNC_PNG
Buffer png;
#endif
int levels[4];
z_stream stream[4];
} VncTight;
typedef struct VncHextile {
VncSendHextileTile *send_tile;
} VncHextile;
typedef struct VncZlib {
Buffer zlib;
Buffer tmp;
z_stream stream;
int level;
} VncZlib;
struct VncState
{
int csock;
......@@ -170,33 +200,10 @@ struct VncState
QEMUPutLEDEntry *led;
/* Encoding specific */
VncTight tight;
VncZlib zlib;
VncHextile hextile;
/* Tight */
int tight_type;
uint8_t tight_quality;
uint8_t tight_compression;
uint8_t tight_pixel24;
Buffer tight;
Buffer tight_tmp;
Buffer tight_zlib;
Buffer tight_gradient;
#ifdef CONFIG_VNC_JPEG
Buffer tight_jpeg;
#endif
#ifdef CONFIG_VNC_PNG
Buffer tight_png;
#endif
int tight_levels[4];
z_stream tight_stream[4];
/* Hextile */
VncSendHextileTile *send_hextile_tile;
/* Zlib */
Buffer zlib;
Buffer zlib_tmp;
z_stream zlib_stream;
int zlib_level;
Notifier mouse_mode_notifier;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment