From d8bdda582bc7f4d56f882fd3e43833880c3800da Mon Sep 17 00:00:00 2001 From: Jay Sorg Date: Thu, 22 Aug 2013 17:59:46 -0700 Subject: [PATCH] X11rdp: work on kill disconnect, drawinging fixes, off screen, don't remote till used twice --- xorg/X11R7.6/rdp/rdp.h | 6 ++++ xorg/X11R7.6/rdp/rdpdraw.c | 32 +++++++++++++---- xorg/X11R7.6/rdp/rdpinput.c | 12 ++++--- xorg/X11R7.6/rdp/rdpup.c | 70 ++++++++++++++++++++++++++++++++++++- 4 files changed, 108 insertions(+), 12 deletions(-) diff --git a/xorg/X11R7.6/rdp/rdp.h b/xorg/X11R7.6/rdp/rdp.h index 8eae5b3e..c9afd285 100644 --- a/xorg/X11R7.6/rdp/rdp.h +++ b/xorg/X11R7.6/rdp/rdp.h @@ -256,6 +256,8 @@ struct rdp_draw_item union urdp_draw_item u; }; +#define XRDP_USE_COUNT_THRESHOLD 1 + struct _rdpPixmapRec { int status; @@ -264,6 +266,10 @@ struct _rdpPixmapRec int is_dirty; int is_scratch; int kind_width; + /* number of times used in a remote operation + if this gets above XRDP_USE_COUNT_THRESHOLD + then we force remote the pixmap */ + int use_count; struct rdp_draw_item* draw_item_head; struct rdp_draw_item* draw_item_tail; }; diff --git a/xorg/X11R7.6/rdp/rdpdraw.c b/xorg/X11R7.6/rdp/rdpdraw.c index 4b900f4e..ecc7dbda 100644 --- a/xorg/X11R7.6/rdp/rdpdraw.c +++ b/xorg/X11R7.6/rdp/rdpdraw.c @@ -804,11 +804,14 @@ xrdp_is_os(PixmapPtr pix, rdpPixmapPtr priv) rdpup_end_update(); rdpup_switch_os_surface(-1); } + priv->use_count++; return 1; } } + priv->use_count++; return 0; } + priv->use_count++; return 1; } @@ -1035,7 +1038,9 @@ rdpCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr pOldRegion) BoxRec box2; BoxPtr box3; - LLOGLN(10, ("in rdpCopyWindow")); + LLOGLN(10, ("rdpCopyWindow:")); + LLOGLN(10, ("rdpCopyWindow: new x %d new y %d old x %d old y %d", + pWin->drawable.x, pWin->drawable.y, ptOldOrg.x, ptOldOrg.y)); RegionInit(®, NullBox, 0); RegionCopy(®, pOldRegion); RegionInit(&clip, NullBox, 0); @@ -1047,18 +1052,28 @@ rdpCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr pOldRegion) { rdpup_check_dirty_screen(&g_screenPriv); } - rdpup_begin_update(); + + g_pScreen->CopyWindow = g_rdpScreen.CopyWindow; + g_pScreen->CopyWindow(pWin, ptOldOrg, pOldRegion); + g_pScreen->CopyWindow = rdpCopyWindow; + num_clip_rects = REGION_NUM_RECTS(&clip); num_reg_rects = REGION_NUM_RECTS(®); LLOGLN(10, ("rdpCopyWindow: num_clip_rects %d num_reg_rects %d", num_clip_rects, num_reg_rects)); + if ((num_clip_rects == 0) || (num_reg_rects == 0)) + { + return; + } + rdpup_begin_update(); + /* when there is a huge list of screen copies, just send as bitmap firefox dragging test does this */ if ((num_clip_rects > 16) && (num_reg_rects > 16)) { box3 = RegionExtents(®); - rdpup_send_area(0, box3->x1, box3->y1, + rdpup_send_area(10, box3->x1 + dx, box3->y1 + dy, box3->x2 - box3->x1, box3->y2 - box3->y1); } @@ -1073,6 +1088,8 @@ rdpCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr pOldRegion) for (j = 0; j < num_clip_rects; j++) { box1 = REGION_RECTS(&clip)[j]; + LLOGLN(10, ("clip x %d y %d w %d h %d", box1.x1, box1.y1, + box1.x2 - box1.x1, box1.y2 - box1.y1)); rdpup_set_clip(box1.x1, box1.y1, box1.x2 - box1.x1, box1.y2 - box1.y1); @@ -1080,6 +1097,8 @@ rdpCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr pOldRegion) for (i = 0; i < num_reg_rects; i++) { box2 = REGION_RECTS(®)[i]; + LLOGLN(10, ("reg x %d y %d w %d h %d", box2.x1, box2.y1, + box2.x2 - box2.x1, box2.y2 - box2.y1)); rdpup_screen_blt(box2.x1 + dx, box2.y1 + dy, box2.x2 - box2.x1, box2.y2 - box2.y1, @@ -1092,6 +1111,8 @@ rdpCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr pOldRegion) for (j = num_clip_rects - 1; j >= 0; j--) { box1 = REGION_RECTS(&clip)[j]; + LLOGLN(10, ("clip x %d y %d w %d h %d", box1.x1, box1.y1, + box1.x2 - box1.x1, box1.y2 - box1.y1)); rdpup_set_clip(box1.x1, box1.y1, box1.x2 - box1.x1, box1.y2 - box1.y1); @@ -1099,6 +1120,8 @@ rdpCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr pOldRegion) for (i = num_reg_rects - 1; i >= 0; i--) { box2 = REGION_RECTS(®)[i]; + LLOGLN(10, ("reg x %d y %d w %d h %d", box2.x1, box2.y1, + box2.x2 - box2.x1, box2.y2 - box2.y1)); rdpup_screen_blt(box2.x1 + dx, box2.y1 + dy, box2.x2 - box2.x1, box2.y2 - box2.y1, @@ -1113,9 +1136,6 @@ rdpCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr pOldRegion) RegionUninit(®); RegionUninit(&clip); - g_pScreen->CopyWindow = g_rdpScreen.CopyWindow; - g_pScreen->CopyWindow(pWin, ptOldOrg, pOldRegion); - g_pScreen->CopyWindow = rdpCopyWindow; } /******************************************************************************/ diff --git a/xorg/X11R7.6/rdp/rdpinput.c b/xorg/X11R7.6/rdp/rdpinput.c index f91f2c12..18e267b6 100644 --- a/xorg/X11R7.6/rdp/rdpinput.c +++ b/xorg/X11R7.6/rdp/rdpinput.c @@ -69,7 +69,7 @@ static OsTimerPtr g_timer = 0; static int g_x = 0; static int g_y = 0; static int g_timer_schedualed = 0; -static int g_delay_motion = 1; +static int g_delay_motion = 1; /* turn on or off */ #define MIN_KEY_CODE 8 #define MAX_KEY_CODE 255 @@ -756,12 +756,13 @@ rdpEnqueueMotion(int x, int y) EventListPtr rdp_events; xEvent *pev; + LLOGLN(10, ("rdpEnqueueMotion: x %d y %d", x, y)); # if 0 if (x < 128) { rdpup_begin_update(); - rdpup_send_area(0, 0, 1024, 768); + rdpup_send_area(0, 0, 0, 1024, 768); rdpup_end_update(); } @@ -825,7 +826,7 @@ rdpEnqueueKey(int type, int scancode) static CARD32 rdpDeferredInputCallback(OsTimerPtr timer, CARD32 now, pointer arg) { - LLOGLN(10, ("rdpDeferredInputCallback")); + LLOGLN(10, ("rdpDeferredInputCallback:")); g_timer_schedualed = 0; rdpEnqueueMotion(g_x, g_y); return 0; @@ -840,9 +841,10 @@ PtrAddEvent(int buttonMask, int x, int y) int buttons; int send_now; - LLOGLN(10, ("PtrAddEvent:")); + LLOGLN(10, ("PtrAddEvent: x %d y %d", x, y)); send_now = (buttonMask ^ g_old_button_mask) || (g_delay_motion == 0); - LLOGLN(10, ("PtrAddEvent: send_now %d", send_now)); + LLOGLN(10, ("PtrAddEvent: send_now %d g_timer_schedualed %d", + send_now, g_timer_schedualed)); if (send_now) { if (g_timer_schedualed) diff --git a/xorg/X11R7.6/rdp/rdpup.c b/xorg/X11R7.6/rdp/rdpup.c index 19fba755..765269e4 100644 --- a/xorg/X11R7.6/rdp/rdpup.c +++ b/xorg/X11R7.6/rdp/rdpup.c @@ -22,8 +22,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "rdp.h" #include "xrdp_rail.h" +#include #include #include +#include #define LOG_LEVEL 1 #define LLOG(_level, _args) \ @@ -31,7 +33,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define LLOGLN(_level, _args) \ do { if (_level < LOG_LEVEL) { ErrorF _args ; ErrorF("\n"); } } while (0) -static int g_use_shmem = 1; +static int g_use_shmem = 1; /* turns on or off */ static int g_shmemid = 0; static char *g_shmemptr = 0; static int g_shmem_lineBytes = 0; @@ -132,12 +134,67 @@ static int g_rdp_opcodes[16] = 0xff /* GXset 0xf 1 */ }; +static int g_do_kill_disconnected = 0; /* turn on or off */ +static OsTimerPtr g_dis_timer = 0; +static int g_disconnect_scheduled = 0; +static CARD32 g_disconnect_timeout = 60 * 1000; /* 60 seconds */ +static CARD32 g_disconnect_time = 0; /* time of disconnect */ + +/******************************************************************************/ +static CARD32 +rdpDeferredDisconnectCallback(OsTimerPtr timer, CARD32 now, pointer arg) +{ + CARD32 lnow; + + LLOGLN(10, ("rdpDeferredDisconnectCallback")); + if (g_connected) + { + /* this should not happen */ + LLOGLN(0, ("rdpDeferredDisconnectCallback: connected")); + if (g_dis_timer != 0) + { + LLOGLN(0, ("rdpDeferredDisconnectCallback: canceling g_dis_timer")); + TimerCancel(g_dis_timer); + TimerFree(g_dis_timer); + g_dis_timer = 0; + } + g_disconnect_scheduled = 0; + return 0; + } + else + { + LLOGLN(10, ("rdpDeferredDisconnectCallback: not connected")); + } + lnow = GetTimeInMillis(); + if (lnow - g_disconnect_time > g_disconnect_timeout) + { + LLOGLN(0, ("rdpDeferredDisconnectCallback: exit X11rdp")); + kill(getpid(), SIGTERM); + return 0; + } + g_dis_timer = TimerSet(g_dis_timer, 0, 1000 * 10, + rdpDeferredDisconnectCallback, 0); + return 0; +} + /*****************************************************************************/ static int rdpup_disconnect(void) { int index; + if (g_do_kill_disconnected) + { + if (!g_disconnect_scheduled) + { + LLOGLN(0, ("rdpup_disconnect: starting g_dis_timer")); + g_dis_timer = TimerSet(g_dis_timer, 0, 1000 * 10, + rdpDeferredDisconnectCallback, 0); + g_disconnect_scheduled = 1; + } + g_disconnect_time = GetTimeInMillis(); + } + RemoveEnabledDevice(g_sck); g_connected = 0; g_tcp_close(g_sck); @@ -1036,6 +1093,16 @@ rdpup_check(void) g_begin = 0; g_con_number++; AddEnabledDevice(g_sck); + + if (g_dis_timer != 0) + { + LLOGLN(0, ("rdpup_check: canceling g_dis_timer")); + TimerCancel(g_dis_timer); + TimerFree(g_dis_timer); + g_dis_timer = 0; + } + g_disconnect_scheduled = 0; + } } @@ -1732,6 +1799,7 @@ rdpup_send_area(struct image_data *id, int x, int y, int w, int h) if (id->shmem_pixels != 0) { + LLOGLN(10, ("rdpup_send_area: using shmem")); box.x1 = x; box.y1 = y; box.x2 = box.x1 + w;