Merge pull request #3882 from nfedera/fix-x11-client-perf

some performance fixes
This commit is contained in:
akallabeth 2017-03-28 08:44:29 +02:00 committed by GitHub
commit 13a1d80daf
4 changed files with 97 additions and 45 deletions

View File

@ -968,29 +968,39 @@ static BOOL xf_gdi_surface_update_frame(xfContext* xfc, UINT16 tx, UINT16 ty,
return ret;
}
static BOOL xf_gdi_update_screen(xfContext* xfc,
const SURFACE_BITS_COMMAND* cmd,
const BYTE* pSrcData, UINT32 scanline)
static BOOL xf_gdi_update_screen(xfContext* xfc, const BYTE* pSrcData,
UINT32 scanline, const REGION16* pRegion)
{
BOOL ret = FALSE;
XImage* image;
UINT32 i, nbRects;
const RECTANGLE_16* rects;
if (!xfc || !pSrcData)
return FALSE;
if (!(rects = region16_rects(pRegion, &nbRects)))
return TRUE;
XSetFunction(xfc->display, xfc->gc, GXcopy);
XSetFillStyle(xfc->display, xfc->gc, FillSolid);
image = XCreateImage(xfc->display, xfc->visual, xfc->depth, ZPixmap, 0,
(char*) pSrcData, cmd->width, cmd->height,
xfc->scanline_pad, scanline);
if (image)
for (i = 0; i < nbRects; i++)
{
XPutImage(xfc->display, xfc->primary, xfc->gc, image, 0, 0,
cmd->destLeft, cmd->destTop, cmd->width, cmd->height);
UINT32 left = rects[i].left;
UINT32 top = rects[i].top;
UINT32 width = rects[i].right - rects[i].left;
UINT32 height = rects[i].bottom - rects[i].top;
const BYTE* src = pSrcData + top * scanline + 4 * left;
image = XCreateImage(xfc->display, xfc->visual, xfc->depth, ZPixmap, 0,
(char*) src, width, height, xfc->scanline_pad, scanline);
if (!image)
break;
XPutImage(xfc->display, xfc->primary, xfc->gc, image, 0, 0, left, top, width, height);
XFree(image);
ret = xf_gdi_surface_update_frame(xfc, cmd->destLeft, cmd->destTop, cmd->width,
cmd->height);
ret = xf_gdi_surface_update_frame(xfc, left, top, width, height);
}
XSetClipMask(xfc->display, xfc->gc, None);
@ -1005,20 +1015,30 @@ static BOOL xf_gdi_surface_bits(rdpContext* context,
BOOL ret = FALSE;
DWORD format;
rdpGdi* gdi;
REGION16 region;
RECTANGLE_16 cmdRect;
if (!context || !cmd || !context->gdi)
return FALSE;
region16_init(&region);
cmdRect.left = cmd->destLeft;
cmdRect.top = cmd->destTop;
cmdRect.right = cmdRect.left + cmd->width;
cmdRect.bottom = cmdRect.top + cmd->height;
gdi = context->gdi;
xf_lock_x11(xfc, FALSE);
switch (cmd->codecID)
{
case RDP_CODEC_ID_REMOTEFX:
if (!rfx_process_message(context->codecs->rfx, cmd->bitmapData,
cmd->bitmapDataLength, 0, 0,
cmd->bitmapDataLength, cmd->destLeft, cmd->destTop,
gdi->primary_buffer, gdi->dstFormat, gdi->stride,
gdi->height, NULL))
gdi->height, &region))
goto fail;
break;
@ -1030,6 +1050,7 @@ static BOOL xf_gdi_surface_bits(rdpContext* context,
0, 0, cmd->width, cmd->height, FREERDP_FLIP_VERTICAL))
goto fail;
region16_union_rect(&region, &region, &cmdRect);
break;
case RDP_CODEC_ID_NONE:
@ -1042,6 +1063,7 @@ static BOOL xf_gdi_surface_bits(rdpContext* context,
&xfc->context.gdi->palette, FREERDP_FLIP_VERTICAL))
goto fail;
region16_union_rect(&region, &region, &cmdRect);
break;
default:
@ -1050,8 +1072,9 @@ static BOOL xf_gdi_surface_bits(rdpContext* context,
goto fail;
}
ret = xf_gdi_update_screen(xfc, cmd, gdi->primary_buffer, gdi->stride);
ret = xf_gdi_update_screen(xfc, gdi->primary_buffer, gdi->stride, &region);
fail:
region16_uninit(&region);
xf_unlock_x11(xfc, FALSE);
return ret;
}

View File

@ -76,6 +76,14 @@
static BOOL g_LZCNT = FALSE;
static INIT_ONCE rfx_rlgr_init_once = INIT_ONCE_STATIC_INIT;
static BOOL CALLBACK rfx_rlgr_init(PINIT_ONCE once, PVOID param, PVOID *context)
{
g_LZCNT = IsProcessorFeaturePresentEx(PF_EX_LZCNT);
return TRUE;
}
static INLINE UINT32 lzcnt_s(UINT32 x)
{
if (!x)
@ -116,7 +124,7 @@ int rfx_rlgr_decode(RLGR_MODE mode, const BYTE* pSrcData, UINT32 SrcSize, INT16*
wBitStream* bs;
wBitStream s_bs;
g_LZCNT = IsProcessorFeaturePresentEx(PF_EX_LZCNT);
InitOnceExecuteOnce(&rfx_rlgr_init_once, rfx_rlgr_init, NULL, NULL);
k = 1;
kp = k << LSGR;

View File

@ -972,8 +972,13 @@ BOOL gdi_surface_frame_marker(rdpContext* context,
static BOOL gdi_surface_bits(rdpContext* context,
const SURFACE_BITS_COMMAND* cmd)
{
BOOL result = FALSE;
DWORD format;
rdpGdi* gdi;
REGION16 region;
RECTANGLE_16 cmdRect;
UINT32 i, nbRects;
const RECTANGLE_16* rects;
if (!context || !cmd)
return FALSE;
@ -985,6 +990,13 @@ static BOOL gdi_surface_bits(rdpContext* context,
cmd->destLeft, cmd->destTop, cmd->destRight, cmd->destBottom,
cmd->bpp, cmd->codecID, cmd->width, cmd->height, cmd->bitmapDataLength);
region16_init(&region);
cmdRect.left = cmd->destLeft;
cmdRect.top = cmd->destTop;
cmdRect.right = cmdRect.left + cmd->width;
cmdRect.bottom = cmdRect.top + cmd->height;
switch (cmd->codecID)
{
case RDP_CODEC_ID_REMOTEFX:
@ -992,12 +1004,11 @@ static BOOL gdi_surface_bits(rdpContext* context,
cmd->bitmapDataLength,
cmd->destLeft, cmd->destTop,
gdi->primary_buffer, gdi->dstFormat,
gdi->stride, gdi->height, NULL))
gdi->stride, gdi->height, &region))
{
WLog_ERR(TAG, "Failed to process RemoteFX message");
return FALSE;
goto out;
}
break;
case RDP_CODEC_ID_NSCODEC:
@ -1008,8 +1019,11 @@ static BOOL gdi_surface_bits(rdpContext* context,
cmd->bitmapDataLength, gdi->primary_buffer,
format, gdi->stride, cmd->destLeft, cmd->destTop,
cmd->width, cmd->height, FREERDP_FLIP_VERTICAL))
return FALSE;
{
WLog_ERR(TAG, "Failed to process NSCodec message");
goto out;
}
region16_union_rect(&region, &region, &cmdRect);
break;
case RDP_CODEC_ID_NONE:
@ -1019,8 +1033,11 @@ static BOOL gdi_surface_bits(rdpContext* context,
cmd->destLeft, cmd->destTop, cmd->width, cmd->height,
cmd->bitmapData, format, 0, 0, 0,
&gdi->palette, FREERDP_FLIP_VERTICAL))
return FALSE;
{
WLog_ERR(TAG, "Failed to process nocodec message");
goto out;
}
region16_union_rect(&region, &region, &cmdRect);
break;
default:
@ -1028,14 +1045,27 @@ static BOOL gdi_surface_bits(rdpContext* context,
break;
}
if (!gdi_InvalidateRegion(gdi->primary->hdc, cmd->destLeft, cmd->destTop,
cmd->width, cmd->height))
if (!(rects = region16_rects(&region, &nbRects)))
goto out;
for (i = 0; i < nbRects; i++)
{
WLog_ERR(TAG, "Failed to update invalid region");
return FALSE;
UINT32 left = rects[i].left;
UINT32 top = rects[i].top;
UINT32 width = rects[i].right - rects[i].left;
UINT32 height = rects[i].bottom - rects[i].top;
if (!gdi_InvalidateRegion(gdi->primary->hdc, left, top, width, height))
{
WLog_ERR(TAG, "Failed to update invalid region");
goto out;
}
}
return TRUE;
result = TRUE;
out:
region16_uninit(&region);
return result;
}
/**

View File

@ -67,30 +67,21 @@ void profiler_exit(PROFILER* profiler)
void profiler_print_header(void)
{
WLog_INFO(TAG,
" |-----------------------|-----------------------|");
WLog_INFO(TAG,
" PROFILER | elapsed seconds | FPS |");
WLog_INFO(TAG,
"|--------------------------------------------|-----------------------|-----------------------");
WLog_INFO(TAG,
"| code section | iterations | total | avg. | total | avg. |");
WLog_INFO(TAG,
"|-------------------------------|------------|-----------|-----------|-----------|-----------|");
WLog_INFO(TAG, "-------------------------------+------------+-------------+-----------+-------");
WLog_INFO(TAG, "PROFILER NAME | COUNT | TOTAL | AVG | IPS");
WLog_INFO(TAG, "-------------------------------+------------+-------------+-----------+-------");
}
void profiler_print(PROFILER* profiler)
{
const double elapsed_sec = stopwatch_get_elapsed_time_in_seconds(profiler->stopwatch);
const double avg_sec = elapsed_sec / (double) profiler->stopwatch->count;
const double fps = 1.0 / elapsed_sec;
const double avg_fps = 1.0 / avg_sec;
WLog_INFO(TAG, "| %-30.30s| %10"PRIu32" | %9f | %9f | %9f | %9f |",
profiler->name, profiler->stopwatch->count, elapsed_sec, avg_sec,
fps, avg_fps);
double s = stopwatch_get_elapsed_time_in_seconds(profiler->stopwatch);
double avg = profiler->stopwatch->count == 0 ? 0 : s / profiler->stopwatch->count;
WLog_INFO(TAG, "%-30s | %10u | %10.4fs | %8.6fs | %6.0f",
profiler->name, profiler->stopwatch->count, s, avg, profiler->stopwatch->count / s);
}
void profiler_print_footer(void)
{
WLog_INFO(TAG, "|--------------------------------------------------------------------|");
WLog_INFO(TAG, "-------------------------------+------------+-------------+-----------+-------");
}