From b6a10ea451fc7e92535d9c8208cb89b44bb10a3a Mon Sep 17 00:00:00 2001 From: Vic Lee Date: Tue, 16 Aug 2011 14:37:11 +0800 Subject: [PATCH] libfreerdp-core/fastpath: add FastPath Input, enabled by default. --- include/freerdp/input.h | 7 ----- libfreerdp-core/fastpath.c | 28 +++++++++++++++++ libfreerdp-core/fastpath.h | 3 ++ libfreerdp-core/input.c | 77 +++++++++++++++++++++++++++++++++++++++++++--- libfreerdp-core/input.h | 25 +++++++++++++++ libfreerdp-core/settings.c | 2 ++ libfreerdp-utils/args.c | 6 ++-- 7 files changed, 133 insertions(+), 15 deletions(-) diff --git a/include/freerdp/input.h b/include/freerdp/input.h index ec28db0..469cd16 100644 --- a/include/freerdp/input.h +++ b/include/freerdp/input.h @@ -20,13 +20,6 @@ #ifndef __INPUT_API_H #define __INPUT_API_H -/* Input Events */ -#define INPUT_EVENT_SYNC 0x0000 -#define INPUT_EVENT_SCANCODE 0x0004 -#define INPUT_EVENT_UNICODE 0x0005 -#define INPUT_EVENT_MOUSE 0x8001 -#define INPUT_EVENT_MOUSEX 0x8002 - /* keyboard Flags */ #define KBD_FLAGS_EXTENDED 0x0100 #define KBD_FLAGS_DOWN 0x4000 diff --git a/libfreerdp-core/fastpath.c b/libfreerdp-core/fastpath.c index 31d8f3f..0dfa1f5 100644 --- a/libfreerdp-core/fastpath.c +++ b/libfreerdp-core/fastpath.c @@ -254,6 +254,34 @@ void fastpath_recv_updates(rdpFastPath* fastpath, STREAM* s) IFCALL(update->EndPaint, update); } +STREAM* fastpath_pdu_init(rdpFastPath* fastpath) +{ + STREAM* s; + s = transport_send_stream_init(fastpath->rdp->transport, 127); + stream_seek(s, 2); /* fpInputHeader and length1 */ + /* length2 is not necessary since input PDU should not exceed 127 bytes */ + return s; +} + +void fastpath_send_pdu(rdpFastPath* fastpath, STREAM* s, uint8 numberEvents) +{ + int length; + + length = stream_get_length(s); + if (length > 127) + { + printf("Maximum FastPath PDU length is 127\n"); + return; + } + + stream_set_pos(s, 0); + stream_write_uint8(s, (numberEvents << 2)); + stream_write_uint8(s, length); + + stream_set_pos(s, length); + transport_write(fastpath->rdp->transport, s); +} + rdpFastPath* fastpath_new(rdpRdp* rdp) { rdpFastPath* fastpath; diff --git a/libfreerdp-core/fastpath.h b/libfreerdp-core/fastpath.h index 20111e4..c1df080 100644 --- a/libfreerdp-core/fastpath.h +++ b/libfreerdp-core/fastpath.h @@ -82,6 +82,9 @@ struct rdp_fastpath uint16 fastpath_read_header(rdpFastPath* fastpath, STREAM* s); void fastpath_recv_updates(rdpFastPath* fastpath, STREAM* s); +STREAM* fastpath_pdu_init(rdpFastPath* fastpath); +void fastpath_send_pdu(rdpFastPath* fastpath, STREAM* s, uint8 numberEvents); + rdpFastPath* fastpath_new(rdpRdp* rdp); void fastpath_free(rdpFastPath* fastpath); diff --git a/libfreerdp-core/input.c b/libfreerdp-core/input.c index 72f6dae..fca754f 100644 --- a/libfreerdp-core/input.c +++ b/libfreerdp-core/input.c @@ -119,6 +119,62 @@ void input_send_extended_mouse_event(rdpInput* input, uint16 flags, uint16 x, ui rdp_send_client_input_pdu(input->rdp, s); } +STREAM* rdp_client_fastpath_input_pdu_init(rdpRdp* rdp, uint8 flags, uint8 code) +{ + STREAM* s; + s = fastpath_pdu_init(rdp->fastpath); + stream_write_uint8(s, flags | (code << 5)); /* eventHeader */ + return s; +} + +void rdp_send_client_fastpath_input_pdu(rdpRdp* rdp, STREAM* s) +{ + fastpath_send_pdu(rdp->fastpath, s, 1); +} + +void input_send_fastpath_synchronize_event(rdpInput* input, uint32 flags) +{ + STREAM* s; + /* The FastPath Synchronization eventFlags has identical values as SlowPath */ + s = rdp_client_fastpath_input_pdu_init(input->rdp, (uint8)flags, FASTPATH_INPUT_EVENT_SYNC); + rdp_send_client_fastpath_input_pdu(input->rdp, s); +} + +void input_send_fastpath_keyboard_event(rdpInput* input, uint16 flags, uint16 code) +{ + STREAM* s; + uint8 eventFlags = 0; + eventFlags |= (flags & KBD_FLAGS_RELEASE) ? FASTPATH_INPUT_KBDFLAGS_RELEASE : 0; + eventFlags |= (flags & KBD_FLAGS_EXTENDED) ? FASTPATH_INPUT_KBDFLAGS_EXTENDED : 0; + s = rdp_client_fastpath_input_pdu_init(input->rdp, eventFlags, FASTPATH_INPUT_EVENT_SCANCODE); + stream_write_uint8(s, code); /* keyCode (1 byte) */ + rdp_send_client_fastpath_input_pdu(input->rdp, s); +} + +void input_send_fastpath_unicode_keyboard_event(rdpInput* input, uint16 code) +{ + STREAM* s; + s = rdp_client_fastpath_input_pdu_init(input->rdp, 0, FASTPATH_INPUT_EVENT_UNICODE); + stream_write_uint16(s, code); /* unicodeCode (2 bytes) */ + rdp_send_client_fastpath_input_pdu(input->rdp, s); +} + +void input_send_fastpath_mouse_event(rdpInput* input, uint16 flags, uint16 x, uint16 y) +{ + STREAM* s; + s = rdp_client_fastpath_input_pdu_init(input->rdp, 0, FASTPATH_INPUT_EVENT_MOUSE); + input_write_mouse_event(s, flags, x, y); + rdp_send_client_fastpath_input_pdu(input->rdp, s); +} + +void input_send_fastpath_extended_mouse_event(rdpInput* input, uint16 flags, uint16 x, uint16 y) +{ + STREAM* s; + s = rdp_client_fastpath_input_pdu_init(input->rdp, 0, FASTPATH_INPUT_EVENT_MOUSEX); + input_write_extended_mouse_event(s, flags, x, y); + rdp_send_client_fastpath_input_pdu(input->rdp, s); +} + rdpInput* input_new(rdpRdp* rdp) { rdpInput* input; @@ -128,11 +184,22 @@ rdpInput* input_new(rdpRdp* rdp) if (input != NULL) { input->rdp = rdp; - input->SynchronizeEvent = input_send_synchronize_event; - input->KeyboardEvent = input_send_keyboard_event; - input->UnicodeKeyboardEvent = input_send_unicode_keyboard_event; - input->MouseEvent = input_send_mouse_event; - input->ExtendedMouseEvent = input_send_extended_mouse_event; + if (rdp->settings->fastpath_input) + { + input->SynchronizeEvent = input_send_fastpath_synchronize_event; + input->KeyboardEvent = input_send_fastpath_keyboard_event; + input->UnicodeKeyboardEvent = input_send_fastpath_unicode_keyboard_event; + input->MouseEvent = input_send_fastpath_mouse_event; + input->ExtendedMouseEvent = input_send_fastpath_extended_mouse_event; + } + else + { + input->SynchronizeEvent = input_send_synchronize_event; + input->KeyboardEvent = input_send_keyboard_event; + input->UnicodeKeyboardEvent = input_send_unicode_keyboard_event; + input->MouseEvent = input_send_mouse_event; + input->ExtendedMouseEvent = input_send_extended_mouse_event; + } } return input; diff --git a/libfreerdp-core/input.h b/libfreerdp-core/input.h index da042f0..a61b068 100644 --- a/libfreerdp-core/input.h +++ b/libfreerdp-core/input.h @@ -21,12 +21,31 @@ #define __INPUT_H #include "rdp.h" +#include "fastpath.h" #include #include #include #include +/* Input Events */ +#define INPUT_EVENT_SYNC 0x0000 +#define INPUT_EVENT_SCANCODE 0x0004 +#define INPUT_EVENT_UNICODE 0x0005 +#define INPUT_EVENT_MOUSE 0x8001 +#define INPUT_EVENT_MOUSEX 0x8002 + +/* FastPath Input Events */ +#define FASTPATH_INPUT_EVENT_SCANCODE 0x0 +#define FASTPATH_INPUT_EVENT_MOUSE 0x1 +#define FASTPATH_INPUT_EVENT_MOUSEX 0x2 +#define FASTPATH_INPUT_EVENT_SYNC 0x3 +#define FASTPATH_INPUT_EVENT_UNICODE 0x4 + +/* FastPath Keyboard Event Flags */ +#define FASTPATH_INPUT_KBDFLAGS_RELEASE 0x01 +#define FASTPATH_INPUT_KBDFLAGS_EXTENDED 0x02 + #define RDP_CLIENT_INPUT_PDU_HEADER_LENGTH 4 void input_send_synchronize_event(rdpInput* input, uint32 flags); @@ -35,6 +54,12 @@ void input_send_unicode_keyboard_event(rdpInput* input, uint16 code); void input_send_mouse_event(rdpInput* input, uint16 flags, uint16 x, uint16 y); void input_send_extended_mouse_event(rdpInput* input, uint16 flags, uint16 x, uint16 y); +void input_send_fastpath_synchronize_event(rdpInput* input, uint32 flags); +void input_send_fastpath_keyboard_event(rdpInput* input, uint16 flags, uint16 code); +void input_send_fastpath_unicode_keyboard_event(rdpInput* input, uint16 code); +void input_send_fastpath_mouse_event(rdpInput* input, uint16 flags, uint16 x, uint16 y); +void input_send_fastpath_extended_mouse_event(rdpInput* input, uint16 flags, uint16 x, uint16 y); + rdpInput* input_new(rdpRdp* rdp); void input_free(rdpInput* input); diff --git a/libfreerdp-core/settings.c b/libfreerdp-core/settings.c index f77d596..27d653b 100644 --- a/libfreerdp-core/settings.c +++ b/libfreerdp-core/settings.c @@ -109,6 +109,8 @@ rdpSettings* settings_new() settings->num_icon_caches = 3; settings->num_icon_cache_entries = 12; + settings->fastpath_input = True; + settings->uniconv = freerdp_uniconv_new(); gethostname(settings->client_hostname, sizeof(settings->client_hostname) - 1); } diff --git a/libfreerdp-utils/args.c b/libfreerdp-utils/args.c index 0f71930..935499f 100644 --- a/libfreerdp-utils/args.c +++ b/libfreerdp-utils/args.c @@ -174,10 +174,10 @@ int freerdp_parse_args(rdpSettings* settings, int argc, char** argv, { settings->offscreen_bitmap_cache = 0; } - else if (strcmp("-fastpath", argv[index]) == 0) + else if (strcmp("--no-fastpath", argv[index]) == 0) { - settings->fastpath_input = True; - settings->fastpath_output = True; + settings->fastpath_input = False; + settings->fastpath_output = False; } else if (strcmp("--rfx", argv[index]) == 0) { -- 2.7.4