summaryrefslogtreecommitdiff
path: root/vnc.c
diff options
context:
space:
mode:
authoraliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162>2009-01-15 22:14:11 +0000
committeraliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162>2009-01-15 22:14:11 +0000
commit7d957bd8cbcbf56f7916d375e65042d767f544b5 (patch)
treea50286c42b0bbfccf0d6c7edc4cacadb7f301982 /vnc.c
parent8927bcfd339510deedb89ff274ea9cd1d00a2668 (diff)
DisplayState interface change (Stefano Stabellini)
This patch changes the DisplayState interface adding support for multiple frontends at the same time (sdl and vnc) and implements most of the benefit of the shared_buf patch without the added complexity. Currently DisplayState is managed by sdl (or vnc) and sdl (or vnc) is also responsible for allocating the data and setting the depth. Vga.c (or another backend) will do any necessary conversion. The idea is to change it so that is vga.c (or another backend) together with console.c that fully manage the DisplayState interface allocating data and setting the depth (either 16 or 32 bit, if the guest uses a different resolution or is in text mode, vga.c (or another backend) is in charge of doing the conversion seamlessly). The other idea is that DisplayState supports *multiple* frontends like sdl and vnc; each of them can register some callbacks to be called when a display event occurs. The interesting changes are: - the new structures and related functions in console.h and console.c in particular the following functions are very helpful to manage a DisplaySurface: qemu_create_displaysurface qemu_resize_displaysurface qemu_create_displaysurface_from qemu_free_displaysurface - console_select and qemu_console_resize in console.c this two functions manage multiple consoles on a single host display - moving code around in hw/vga.c as for the shared_buf patch this is necessary to be able to handle a dynamic DisplaySurface bpp - changes to vga_draw_graphic in hw/vga.c this is the place where the DisplaySurface buffer is shared with the videoram, when possible; Compared to the last version the only changes are: - do not remove support to dpy_copy in cirrus_vga - change the name of the displaysurface handling functions Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6336 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'vnc.c')
-rw-r--r--vnc.c107
1 files changed, 34 insertions, 73 deletions
diff --git a/vnc.c b/vnc.c
index e1ff4edd75..357ff648f9 100644
--- a/vnc.c
+++ b/vnc.c
@@ -180,6 +180,7 @@ struct VncState
};
static VncState *vnc_state; /* needed for info vnc */
+static DisplayChangeListener *dcl;
void do_info_vnc(void)
{
@@ -213,7 +214,7 @@ static void vnc_flush(VncState *vs);
static void vnc_update_client(void *opaque);
static void vnc_client_read(void *opaque);
-static void vnc_colordepth(DisplayState *ds, int depth);
+static void vnc_colordepth(DisplayState *ds);
static inline void vnc_set_bit(uint32_t *d, int k)
{
@@ -291,35 +292,30 @@ static void vnc_framebuffer_update(VncState *vs, int x, int y, int w, int h,
vnc_write_s32(vs, encoding);
}
-static void vnc_dpy_resize(DisplayState *ds, int w, int h)
+static void vnc_dpy_resize(DisplayState *ds)
{
int size_changed;
VncState *vs = ds->opaque;
- ds->data = qemu_realloc(ds->data, w * h * vs->depth);
- vs->old_data = qemu_realloc(vs->old_data, w * h * vs->depth);
+ vs->old_data = qemu_realloc(vs->old_data, ds_get_linesize(ds) * ds_get_height(ds));
- if (ds->data == NULL || vs->old_data == NULL) {
+ if (vs->old_data == NULL) {
fprintf(stderr, "vnc: memory allocation failed\n");
exit(1);
}
- if (ds->depth != vs->depth * 8) {
- ds->depth = vs->depth * 8;
+ if (ds_get_bytes_per_pixel(ds) != vs->depth)
console_color_init(ds);
- }
- size_changed = ds->width != w || ds->height != h;
- ds->width = w;
- ds->height = h;
- ds->linesize = w * vs->depth;
+ vnc_colordepth(ds);
+ size_changed = ds_get_width(ds) != vs->width || ds_get_height(ds) != vs->height;
if (size_changed) {
- vs->width = ds->width;
- vs->height = ds->height;
+ vs->width = ds_get_width(ds);
+ vs->height = ds_get_height(ds);
if (vs->csock != -1 && vs->has_resize) {
vnc_write_u8(vs, 0); /* msg id */
vnc_write_u8(vs, 0);
vnc_write_u16(vs, 1); /* number of rects */
- vnc_framebuffer_update(vs, 0, 0, ds->width, ds->height, -223);
+ vnc_framebuffer_update(vs, 0, 0, ds_get_width(ds), ds_get_height(ds), -223);
vnc_flush(vs);
}
}
@@ -494,36 +490,10 @@ static void send_framebuffer_update(VncState *vs, int x, int y, int w, int h)
static void vnc_copy(DisplayState *ds, int src_x, int src_y, int dst_x, int dst_y, int w, int h)
{
- int src, dst;
- uint8_t *src_row;
- uint8_t *dst_row;
- char *old_row;
- int y = 0;
- int pitch = ds_get_linesize(ds);
VncState *vs = ds->opaque;
vnc_update_client(vs);
- if (dst_y > src_y) {
- y = h - 1;
- pitch = -pitch;
- }
-
- src = (ds_get_linesize(ds) * (src_y + y) + vs->depth * src_x);
- dst = (ds_get_linesize(ds) * (dst_y + y) + vs->depth * dst_x);
-
- src_row = ds_get_data(ds) + src;
- dst_row = ds_get_data(ds) + dst;
- old_row = vs->old_data + dst;
-
- for (y = 0; y < h; y++) {
- memmove(old_row, src_row, w * vs->depth);
- memmove(dst_row, src_row, w * vs->depth);
- src_row += pitch;
- dst_row += pitch;
- old_row += pitch;
- }
-
vnc_write_u8(vs, 0); /* msg id */
vnc_write_u8(vs, 0);
vnc_write_u16(vs, 1); /* number of rects */
@@ -770,7 +740,7 @@ static int vnc_client_io_error(VncState *vs, int ret, int last_errno)
qemu_set_fd_handler2(vs->csock, NULL, NULL, NULL, NULL);
closesocket(vs->csock);
vs->csock = -1;
- vs->ds->idle = 1;
+ dcl->idle = 1;
buffer_reset(&vs->input);
buffer_reset(&vs->output);
vs->need_update = 0;
@@ -1226,7 +1196,7 @@ static void set_encodings(VncState *vs, int32_t *encodings, size_t n_encodings)
vs->has_pointer_type_change = 0;
vs->has_WMVi = 0;
vs->absolute = -1;
- vs->ds->dpy_copy = NULL;
+ dcl->dpy_copy = NULL;
for (i = n_encodings - 1; i >= 0; i--) {
switch (encodings[i]) {
@@ -1234,7 +1204,7 @@ static void set_encodings(VncState *vs, int32_t *encodings, size_t n_encodings)
vs->has_hextile = 0;
break;
case 1: /* CopyRect */
- vs->ds->dpy_copy = vnc_copy;
+ dcl->dpy_copy = vnc_copy;
break;
case 5: /* Hextile */
vs->has_hextile = 1;
@@ -1387,33 +1357,25 @@ static void pixel_format_message (VncState *vs) {
vnc_write(vs, pad, 3); /* padding */
}
-static void vnc_colordepth(DisplayState *ds, int depth)
+static void vnc_dpy_setdata(DisplayState *ds)
+{
+ /* We don't have to do anything */
+}
+
+static void vnc_colordepth(DisplayState *ds)
{
int host_big_endian_flag;
struct VncState *vs = ds->opaque;
- switch (depth) {
- case 24:
- if (ds->depth == 32) return;
- depth = 32;
- break;
- case 15:
- case 8:
- case 0:
- return;
- default:
- break;
- }
-
#ifdef WORDS_BIGENDIAN
host_big_endian_flag = 1;
#else
host_big_endian_flag = 0;
#endif
- switch (depth) {
+ switch (ds_get_bits_per_pixel(ds)) {
case 8:
- vs->depth = depth / 8;
+ vs->depth = 1;
vs->server_red_max = 7;
vs->server_green_max = 7;
vs->server_blue_max = 3;
@@ -1422,7 +1384,7 @@ static void vnc_colordepth(DisplayState *ds, int depth)
vs->server_blue_shift = 0;
break;
case 16:
- vs->depth = depth / 8;
+ vs->depth = 2;
vs->server_red_max = 31;
vs->server_green_max = 63;
vs->server_blue_max = 31;
@@ -1448,7 +1410,7 @@ static void vnc_colordepth(DisplayState *ds, int depth)
vnc_write_u8(vs, 0); /* msg id */
vnc_write_u8(vs, 0);
vnc_write_u16(vs, 1); /* number of rects */
- vnc_framebuffer_update(vs, 0, 0, ds->width, ds->height, 0x574D5669);
+ vnc_framebuffer_update(vs, 0, 0, ds_get_width(ds), ds_get_height(ds), 0x574D5669);
pixel_format_message(vs);
vnc_flush(vs);
} else {
@@ -2237,7 +2199,7 @@ static int protocol_version(VncState *vs, uint8_t *version, size_t len)
static void vnc_connect(VncState *vs)
{
VNC_DEBUG("New client on socket %d\n", vs->csock);
- vs->ds->idle = 0;
+ dcl->idle = 0;
socket_set_nonblock(vs->csock);
qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, NULL, vs);
vnc_write(vs, "RFB 003.008\n", 12);
@@ -2247,7 +2209,7 @@ static void vnc_connect(VncState *vs)
memset(vs->dirty_row, 0xFF, sizeof(vs->dirty_row));
vs->has_resize = 0;
vs->has_hextile = 0;
- vs->ds->dpy_copy = NULL;
+ dcl->dpy_copy = NULL;
vnc_update_client(vs);
reset_keys(vs);
}
@@ -2272,11 +2234,12 @@ void vnc_display_init(DisplayState *ds)
VncState *vs;
vs = qemu_mallocz(sizeof(VncState));
- if (!vs)
+ dcl = qemu_mallocz(sizeof(DisplayChangeListener));
+ if (!vs || !dcl)
exit(1);
ds->opaque = vs;
- ds->idle = 1;
+ dcl->idle = 1;
vnc_state = vs;
vs->display = NULL;
vs->password = NULL;
@@ -2298,13 +2261,11 @@ void vnc_display_init(DisplayState *ds)
vs->timer = qemu_new_timer(rt_clock, vnc_update_client, vs);
- vs->ds->data = NULL;
- vs->ds->dpy_update = vnc_dpy_update;
- vs->ds->dpy_resize = vnc_dpy_resize;
- vs->ds->dpy_refresh = NULL;
-
- vnc_colordepth(vs->ds, 32);
- vnc_dpy_resize(vs->ds, 640, 400);
+ dcl->dpy_update = vnc_dpy_update;
+ dcl->dpy_resize = vnc_dpy_resize;
+ dcl->dpy_setdata = vnc_dpy_setdata;
+ dcl->dpy_refresh = NULL;
+ register_displaychangelistener(ds, dcl);
vs->as.freq = 44100;
vs->as.nchannels = 2;