From: Alexander Graf <agraf@suse.de>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 2/7] Use VNC protocol defines
Date: Thu, 29 Jan 2009 12:24:53 +0100 [thread overview]
Message-ID: <1233228298-4844-3-git-send-email-agraf@suse.de> (raw)
In-Reply-To: <1233228298-4844-2-git-send-email-agraf@suse.de>
Now that we have nice defines for all sorts of constants, let's
use them!
This patch also takes the "feature variables", currently called has_*
into a single feature int. This way adding new features is a lot
easier and doesn't clutter the VncState struct.
Signed-off-by: Alexander Graf <agraf@suse.de>
---
vnc.c | 97 +++++++++++++++++++++++++++++++++-------------------------------
1 files changed, 50 insertions(+), 47 deletions(-)
diff --git a/vnc.c b/vnc.c
index e88f38f..6b885d3 100644
--- a/vnc.c
+++ b/vnc.c
@@ -98,10 +98,7 @@ struct VncState
int need_update;
uint32_t dirty_row[VNC_MAX_HEIGHT][VNC_DIRTY_WORDS];
char *old_data;
- int has_resize;
- int has_hextile;
- int has_pointer_type_change;
- int has_WMVi;
+ uint32_t features;
int absolute;
int last_x;
int last_y;
@@ -164,6 +161,10 @@ void do_info_vnc(void)
}
}
+static inline uint32_t vnc_has_feature(VncState *vs, int feature) {
+ return (vs->features & (1 << feature));
+}
+
/* TODO
1) Get the queue working for IO.
2) there is some weirdness when using the -S option (the screen is grey
@@ -277,11 +278,12 @@ static void vnc_dpy_resize(DisplayState *ds)
ds_get_height(ds) != vs->serverds.height;
vs->serverds = *(ds->surface);
if (size_changed) {
- if (vs->csock != -1 && vs->has_resize) {
+ if (vs->csock != -1 && vnc_has_feature(vs, VNC_FEATURE_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_get_width(ds), ds_get_height(ds), -223);
+ vnc_framebuffer_update(vs, 0, 0, ds_get_width(ds), ds_get_height(ds),
+ VNC_ENCODING_DESKTOPRESIZE);
vnc_flush(vs);
}
}
@@ -378,7 +380,7 @@ static void send_framebuffer_update_raw(VncState *vs, int x, int y, int w, int h
int i;
uint8_t *row;
- vnc_framebuffer_update(vs, x, y, w, h, 0);
+ vnc_framebuffer_update(vs, x, y, w, h, VNC_ENCODING_RAW);
row = ds_get_data(vs->ds) + y * ds_get_linesize(vs->ds) + x * ds_get_bytes_per_pixel(vs->ds);
for (i = 0; i < h; i++) {
@@ -429,7 +431,7 @@ static void send_framebuffer_update_hextile(VncState *vs, int x, int y, int w, i
int has_fg, has_bg;
uint8_t *last_fg, *last_bg;
- vnc_framebuffer_update(vs, x, y, w, h, 5);
+ vnc_framebuffer_update(vs, x, y, w, h, VNC_ENCODING_HEXTILE);
last_fg = (uint8_t *) malloc(vs->serverds.pf.bytes_per_pixel);
last_bg = (uint8_t *) malloc(vs->serverds.pf.bytes_per_pixel);
@@ -448,7 +450,7 @@ static void send_framebuffer_update_hextile(VncState *vs, int x, int y, int w, i
static void send_framebuffer_update(VncState *vs, int x, int y, int w, int h)
{
- if (vs->has_hextile)
+ if (vnc_has_feature(vs, VNC_FEATURE_HEXTILE))
send_framebuffer_update_hextile(vs, x, y, w, h);
else
send_framebuffer_update_raw(vs, x, y, w, h);
@@ -463,7 +465,7 @@ static void vnc_copy(DisplayState *ds, int src_x, int src_y, int dst_x, int dst_
vnc_write_u8(vs, 0); /* msg id */
vnc_write_u8(vs, 0);
vnc_write_u16(vs, 1); /* number of rects */
- vnc_framebuffer_update(vs, dst_x, dst_y, w, h, 1);
+ vnc_framebuffer_update(vs, dst_x, dst_y, w, h, VNC_ENCODING_COPYRECT);
vnc_write_u16(vs, src_x);
vnc_write_u16(vs, src_y);
vnc_flush(vs);
@@ -919,12 +921,13 @@ static void client_cut_text(VncState *vs, size_t len, uint8_t *text)
static void check_pointer_type_change(VncState *vs, int absolute)
{
- if (vs->has_pointer_type_change && vs->absolute != absolute) {
+ if (vnc_has_feature(vs, VNC_FEATURE_POINTER_TYPE_CHANGE) && vs->absolute != absolute) {
vnc_write_u8(vs, 0);
vnc_write_u8(vs, 0);
vnc_write_u16(vs, 1);
vnc_framebuffer_update(vs, absolute, 0,
- ds_get_width(vs->ds), ds_get_height(vs->ds), -257);
+ ds_get_width(vs->ds), ds_get_height(vs->ds),
+ VNC_ENCODING_POINTER_TYPE_CHANGE);
vnc_flush(vs);
}
vs->absolute = absolute;
@@ -950,7 +953,7 @@ static void pointer_event(VncState *vs, int button_mask, int x, int y)
kbd_mouse_event(x * 0x7FFF / (ds_get_width(vs->ds) - 1),
y * 0x7FFF / (ds_get_height(vs->ds) - 1),
dz, buttons);
- } else if (vs->has_pointer_type_change) {
+ } else if (vnc_has_feature(vs, VNC_FEATURE_POINTER_TYPE_CHANGE)) {
x -= 0x7FFF;
y -= 0x7FFF;
@@ -1140,7 +1143,8 @@ static void send_ext_key_event_ack(VncState *vs)
vnc_write_u8(vs, 0);
vnc_write_u8(vs, 0);
vnc_write_u16(vs, 1);
- vnc_framebuffer_update(vs, 0, 0, ds_get_width(vs->ds), ds_get_height(vs->ds), -258);
+ vnc_framebuffer_update(vs, 0, 0, ds_get_width(vs->ds), ds_get_height(vs->ds),
+ VNC_ENCODING_EXT_KEY_EVENT);
vnc_flush(vs);
}
@@ -1149,50 +1153,50 @@ static void send_ext_audio_ack(VncState *vs)
vnc_write_u8(vs, 0);
vnc_write_u8(vs, 0);
vnc_write_u16(vs, 1);
- vnc_framebuffer_update(vs, 0, 0, ds_get_width(vs->ds), ds_get_height(vs->ds), -259);
+ vnc_framebuffer_update(vs, 0, 0, ds_get_width(vs->ds), ds_get_height(vs->ds),
+ VNC_ENCODING_AUDIO);
vnc_flush(vs);
}
static void set_encodings(VncState *vs, int32_t *encodings, size_t n_encodings)
{
int i;
+ unsigned int enc = 0;
- vs->has_hextile = 0;
- vs->has_resize = 0;
- vs->has_pointer_type_change = 0;
- vs->has_WMVi = 0;
+ vs->features = 0;
vs->absolute = -1;
dcl->dpy_copy = NULL;
for (i = n_encodings - 1; i >= 0; i--) {
- switch (encodings[i]) {
- case 0: /* Raw */
- vs->has_hextile = 0;
- break;
- case 1: /* CopyRect */
- dcl->dpy_copy = vnc_copy;
- break;
- case 5: /* Hextile */
- vs->has_hextile = 1;
- break;
- case -223: /* DesktopResize */
- vs->has_resize = 1;
- break;
- case -257:
- vs->has_pointer_type_change = 1;
- break;
- case -258:
+ enc = encodings[i];
+ switch (enc) {
+ case VNC_ENCODING_RAW:
+ break;
+ case VNC_ENCODING_COPYRECT:
+ dcl->dpy_copy = vnc_copy;
+ break;
+ case VNC_ENCODING_HEXTILE:
+ vs->features |= VNC_FEATURE_HEXTILE_MASK;
+ break;
+ case VNC_ENCODING_DESKTOPRESIZE:
+ vs->features |= VNC_FEATURE_RESIZE_MASK;
+ break;
+ case VNC_ENCODING_POINTER_TYPE_CHANGE:
+ vs->features |= VNC_FEATURE_POINTER_TYPE_CHANGE_MASK;
+ break;
+ case VNC_ENCODING_EXT_KEY_EVENT:
send_ext_key_event_ack(vs);
break;
- case -259:
+ case VNC_ENCODING_AUDIO:
send_ext_audio_ack(vs);
break;
- case 0x574D5669:
- vs->has_WMVi = 1;
+ case VNC_ENCODING_WMVi:
+ vs->features |= VNC_FEATURE_WMVI_MASK;
break;
- default:
- break;
- }
+ default:
+ printf("Unknown encoding: %d (0x%.8x): %d\n", i, enc, enc);
+ break;
+ }
}
check_pointer_type_change(vs, kbd_mouse_is_absolute());
@@ -1306,12 +1310,13 @@ static void vnc_colordepth(DisplayState *ds)
{
struct VncState *vs = ds->opaque;
- if (vs->csock != -1 && vs->has_WMVi) {
+ if (vs->csock != -1 && vnc_has_feature(vs, VNC_FEATURE_WMVI)) {
/* Sending a WMVi message to notify the client*/
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_get_width(ds), ds_get_height(ds), 0x574D5669);
+ vnc_framebuffer_update(vs, 0, 0, ds_get_width(ds), ds_get_height(ds),
+ VNC_ENCODING_WMVi);
pixel_format_message(vs);
vnc_flush(vs);
} else {
@@ -2079,9 +2084,7 @@ static void vnc_connect(VncState *vs)
vnc_read_when(vs, protocol_version, 12);
memset(vs->old_data, 0, ds_get_linesize(vs->ds) * ds_get_height(vs->ds));
memset(vs->dirty_row, 0xFF, sizeof(vs->dirty_row));
- vs->has_resize = 0;
- vs->has_hextile = 0;
- vs->has_WMVi = 0;
+ vs->features = 0;
dcl->dpy_copy = NULL;
vnc_update_client(vs);
reset_keys(vs);
--
1.6.0.2
next prev parent reply other threads:[~2009-01-29 11:25 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-29 11:24 [Qemu-devel] [PATCH 0/7] Add tight support to VNC Alexander Graf
2009-01-29 11:24 ` [Qemu-devel] [PATCH 1/7] Split VNC defines to vnc.h Alexander Graf
2009-01-29 11:24 ` Alexander Graf [this message]
2009-01-29 11:24 ` [Qemu-devel] [PATCH 3/7] Fix invalid #if in vnc.c when debugging is enabled Alexander Graf
2009-01-29 11:24 ` [Qemu-devel] [PATCH 4/7] Make vnc buffer big-chunk aware Alexander Graf
2009-01-29 11:24 ` [Qemu-devel] [PATCH 5/7] Split vnc authentication code Alexander Graf
2009-01-29 11:24 ` [Qemu-devel] [PATCH 6/7] Add tight protocol awareness to vnc.c Alexander Graf
2009-01-29 11:24 ` [Qemu-devel] [PATCH 7/7] Add tight encoding (jpeg) " Alexander Graf
2009-01-29 15:17 ` [Qemu-devel] " Anthony Liguori
2009-01-29 15:23 ` Stefano Stabellini
2009-01-29 15:47 ` Anthony Liguori
2009-01-29 15:13 ` [Qemu-devel] Re: [PATCH 6/7] Add tight protocol awareness " Anthony Liguori
2009-01-29 15:24 ` Alexander Graf
2009-01-29 15:43 ` Anthony Liguori
2009-01-29 15:11 ` [Qemu-devel] Re: [PATCH 4/7] Make vnc buffer big-chunk aware Anthony Liguori
2009-01-29 15:16 ` Alexander Graf
2009-01-29 15:22 ` [Qemu-devel] Re: [PATCH 1/7] Split VNC defines to vnc.h Anthony Liguori
2009-01-29 15:29 ` Alexander Graf
2009-01-29 15:46 ` Anthony Liguori
-- strict thread matches above, loose matches on Subject: below --
2009-01-30 14:38 [Qemu-devel] [PATCH 0/7] Add zlib support to VNC server Alexander Graf
2009-01-30 14:38 ` [Qemu-devel] [PATCH 1/7] Split VNC defines to vnc.h Alexander Graf
2009-01-30 14:38 ` [Qemu-devel] [PATCH 2/7] Use VNC protocol defines Alexander Graf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1233228298-4844-3-git-send-email-agraf@suse.de \
--to=agraf@suse.de \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).