From 4ea50fd0c52ab7d66b9c5a56c5525f37fb0c16a0 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Thu, 22 May 2025 15:53:12 +0200 Subject: [PATCH] [client,x11] log XPutImage and XCopyRect --- client/X11/xf_client.c | 12 +++++++----- client/X11/xf_gfx.c | 27 +++++++++++++++------------ client/X11/xf_utils.c | 42 ++++++++++++++++++++++++++++++++++++++++++ client/X11/xf_utils.h | 17 +++++++++++++++++ client/X11/xf_video.c | 12 ++++++------ client/X11/xf_window.c | 21 +++++++++++---------- 6 files changed, 98 insertions(+), 33 deletions(-) diff --git a/client/X11/xf_client.c b/client/X11/xf_client.c index caf5bc951..22d8c7fe5 100644 --- a/client/X11/xf_client.c +++ b/client/X11/xf_client.c @@ -329,8 +329,9 @@ void xf_draw_screen_(xfContext* xfc, int x, int y, int w, int h, const char* fkt } #endif - XCopyArea(xfc->display, xfc->primary, xfc->window->handle, xfc->gc, x, y, - WINPR_ASSERTING_INT_CAST(uint32_t, w), WINPR_ASSERTING_INT_CAST(uint32_t, h), x, y); + LogDynAndXCopyArea(xfc->log, xfc->display, xfc->primary, xfc->window->handle, xfc->gc, x, y, + WINPR_ASSERTING_INT_CAST(uint32_t, w), WINPR_ASSERTING_INT_CAST(uint32_t, h), + x, y); } static BOOL xf_desktop_resize(rdpContext* context) @@ -424,9 +425,10 @@ static BOOL xf_paint(xfContext* xfc, const GDI_RGN* region) } else { - XPutImage(xfc->display, xfc->primary, xfc->gc, xfc->image, region->x, region->y, region->x, - region->y, WINPR_ASSERTING_INT_CAST(UINT16, region->w), - WINPR_ASSERTING_INT_CAST(UINT16, region->h)); + LogDynAndXPutImage(xfc->log, xfc->display, xfc->primary, xfc->gc, xfc->image, region->x, + region->y, region->x, region->y, + WINPR_ASSERTING_INT_CAST(UINT16, region->w), + WINPR_ASSERTING_INT_CAST(UINT16, region->h)); xf_draw_screen(xfc, region->x, region->y, region->w, region->h); } return TRUE; diff --git a/client/X11/xf_gfx.c b/client/X11/xf_gfx.c index bbd49c726..e6d7831ab 100644 --- a/client/X11/xf_gfx.c +++ b/client/X11/xf_gfx.c @@ -94,10 +94,11 @@ static UINT xf_OutputUpdate(xfContext* xfc, xfGfxSurface* surface) if (xfc->remote_app) { - XPutImage(xfc->display, xfc->primary, xfc->gc, surface->image, - WINPR_ASSERTING_INT_CAST(int, nXSrc), WINPR_ASSERTING_INT_CAST(int, nYSrc), - WINPR_ASSERTING_INT_CAST(int, nXDst), WINPR_ASSERTING_INT_CAST(int, nYDst), - dwidth, dheight); + LogDynAndXPutImage(xfc->log, xfc->display, xfc->primary, xfc->gc, surface->image, + WINPR_ASSERTING_INT_CAST(int, nXSrc), + WINPR_ASSERTING_INT_CAST(int, nYSrc), + WINPR_ASSERTING_INT_CAST(int, nXDst), + WINPR_ASSERTING_INT_CAST(int, nYDst), dwidth, dheight); xf_lock_x11(xfc); xf_rail_paint_surface(xfc, surface->gdi.windowId, rect); xf_unlock_x11(xfc); @@ -107,10 +108,11 @@ static UINT xf_OutputUpdate(xfContext* xfc, xfGfxSurface* surface) if (freerdp_settings_get_bool(settings, FreeRDP_SmartSizing) || freerdp_settings_get_bool(settings, FreeRDP_MultiTouchGestures)) { - XPutImage(xfc->display, xfc->primary, xfc->gc, surface->image, - WINPR_ASSERTING_INT_CAST(int, nXSrc), WINPR_ASSERTING_INT_CAST(int, nYSrc), - WINPR_ASSERTING_INT_CAST(int, nXDst), WINPR_ASSERTING_INT_CAST(int, nYDst), - dwidth, dheight); + LogDynAndXPutImage(xfc->log, xfc->display, xfc->primary, xfc->gc, surface->image, + WINPR_ASSERTING_INT_CAST(int, nXSrc), + WINPR_ASSERTING_INT_CAST(int, nYSrc), + WINPR_ASSERTING_INT_CAST(int, nXDst), + WINPR_ASSERTING_INT_CAST(int, nYDst), dwidth, dheight); xf_draw_screen(xfc, WINPR_ASSERTING_INT_CAST(int32_t, nXDst), WINPR_ASSERTING_INT_CAST(int32_t, nYDst), WINPR_ASSERTING_INT_CAST(int32_t, dwidth), @@ -119,10 +121,11 @@ static UINT xf_OutputUpdate(xfContext* xfc, xfGfxSurface* surface) else #endif { - XPutImage(xfc->display, xfc->drawable, xfc->gc, surface->image, - WINPR_ASSERTING_INT_CAST(int, nXSrc), WINPR_ASSERTING_INT_CAST(int, nYSrc), - WINPR_ASSERTING_INT_CAST(int, nXDst), WINPR_ASSERTING_INT_CAST(int, nYDst), - dwidth, dheight); + LogDynAndXPutImage(xfc->log, xfc->display, xfc->drawable, xfc->gc, surface->image, + WINPR_ASSERTING_INT_CAST(int, nXSrc), + WINPR_ASSERTING_INT_CAST(int, nYSrc), + WINPR_ASSERTING_INT_CAST(int, nXDst), + WINPR_ASSERTING_INT_CAST(int, nYDst), dwidth, dheight); } } diff --git a/client/X11/xf_utils.c b/client/X11/xf_utils.c index e18182c60..8ef2c34d7 100644 --- a/client/X11/xf_utils.c +++ b/client/X11/xf_utils.c @@ -243,3 +243,45 @@ const char* x11_error_to_string(xfContext* xfc, int error, char* buffer, size_t WLog_WARN(TAG, "XGetErrorText returned %d", rc); return buffer; } + +int LogDynAndXCopyArea_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, Pixmap src, Window dest, GC gc, int src_x, int src_y, + unsigned int width, unsigned int height, int dest_x, int dest_y) +{ + if (WLog_IsLevelActive(log, log_level)) + { + XWindowAttributes attr = { 0 }; + const Status rc = XGetWindowAttributes(display, dest, &attr); + + write_log(log, log_level, file, fkt, line, + "XCopyArea(%p, src: {}, dest: [%d]{%lu, %d}, gc: {}, src_x: {%d}, src_y: {%d}, " + "width: {%d}, " + "height: {%d}, dest_x: {%d}, dest_y: {%d})", + display, rc, attr.root, attr.depth, src_x, src_y, width, height, dest_x, dest_y); + } + + const int rc = XCopyArea(display, src, dest, gc, src_x, src_y, width, height, dest_x, dest_y); + if (rc) + WLog_WARN(TAG, "XCopyArea returned %d", rc); + return rc; +} + +int LogDynAndXPutImage_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, Drawable d, GC gc, XImage* image, int src_x, int src_y, + int dest_x, int dest_y, unsigned int width, unsigned int height) +{ + if (WLog_IsLevelActive(log, log_level)) + { + write_log(log, log_level, file, fkt, line, + "XPutImage(%p, d: {}, gc: {}, image: [%p]{%d}, src_y: {%d}, dest_x: {%d}, " + "dest_y: {%d}, width: {%d}, " + "height: {%d})", + display, image, image ? image->depth : -1, src_x, src_y, dest_x, dest_y, width, + height); + } + + const int rc = XPutImage(display, d, gc, image, src_x, src_y, dest_x, dest_y, width, height); + if (rc) + WLog_WARN(TAG, "XPutImage returned %d", rc); + return rc; +} diff --git a/client/X11/xf_utils.h b/client/X11/xf_utils.h index 81b020eff..1ed469000 100644 --- a/client/X11/xf_utils.h +++ b/client/X11/xf_utils.h @@ -103,4 +103,21 @@ int LogDynAndXConvertSelection_ex(wLog* log, const char* file, const char* fkt, Display* display, Atom selection, Atom target, Atom property, Window requestor, Time time); +#define LogDynAndXPutImage(log, display, d, gc, image, src_x, src_y, dest_x, dest_y, width, \ + height) \ + LogDynAndXPutImage_ex(log, __FILE__, __func__, __LINE__, (display), (d), (gc), (image), \ + (src_x), (src_y), (dest_x), (dest_y), (width), (height)) +int LogDynAndXPutImage_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, Drawable d, GC gc, XImage* image, int src_x, int src_y, + int dest_x, int dest_y, unsigned int width, unsigned int height); + +#define LogDynAndXCopyArea(log, display, src, dest, gc, src_x, src_y, width, height, dest_x, \ + dest_y) \ + LogDynAndXCopyArea_ex(log, __FILE__, __func__, __LINE__, (display), (src), (dest), (gc), \ + (src_x), (src_y), (width), (height), (dest_x), (dest_y)) +extern int LogDynAndXCopyArea_ex(wLog* log, const char* file, const char* fkt, size_t line, + Display* display, Pixmap src, Window dest, GC gc, int src_x, + int src_y, unsigned int width, unsigned int height, int dest_x, + int dest_y); + BOOL IsGnome(void); diff --git a/client/X11/xf_video.c b/client/X11/xf_video.c index ae406b491..0b607c442 100644 --- a/client/X11/xf_video.c +++ b/client/X11/xf_video.c @@ -83,9 +83,9 @@ static BOOL xfVideoShowSurface(VideoClientContext* video, const VideoSurface* su if (freerdp_settings_get_bool(settings, FreeRDP_SmartSizing) || freerdp_settings_get_bool(settings, FreeRDP_MultiTouchGestures)) { - XPutImage(xfc->display, xfc->primary, xfc->gc, xfSurface->image, 0, 0, - WINPR_ASSERTING_INT_CAST(int, surface->x), - WINPR_ASSERTING_INT_CAST(int, surface->y), surface->w, surface->h); + LogDynAndXPutImage(xfc->log, xfc->display, xfc->primary, xfc->gc, xfSurface->image, 0, 0, + WINPR_ASSERTING_INT_CAST(int, surface->x), + WINPR_ASSERTING_INT_CAST(int, surface->y), surface->w, surface->h); xf_draw_screen(xfc, WINPR_ASSERTING_INT_CAST(int32_t, surface->x), WINPR_ASSERTING_INT_CAST(int32_t, surface->y), WINPR_ASSERTING_INT_CAST(int32_t, surface->w), @@ -94,9 +94,9 @@ static BOOL xfVideoShowSurface(VideoClientContext* video, const VideoSurface* su else #endif { - XPutImage(xfc->display, xfc->drawable, xfc->gc, xfSurface->image, 0, 0, - WINPR_ASSERTING_INT_CAST(int, surface->x), - WINPR_ASSERTING_INT_CAST(int, surface->y), surface->w, surface->h); + LogDynAndXPutImage(xfc->log, xfc->display, xfc->drawable, xfc->gc, xfSurface->image, 0, 0, + WINPR_ASSERTING_INT_CAST(int, surface->x), + WINPR_ASSERTING_INT_CAST(int, surface->y), surface->w, surface->h); } return TRUE; diff --git a/client/X11/xf_window.c b/client/X11/xf_window.c index 9fe9d5900..b7e542bd9 100644 --- a/client/X11/xf_window.c +++ b/client/X11/xf_window.c @@ -1357,14 +1357,14 @@ void xf_UpdateWindowArea(xfContext* xfc, xfAppWindow* appWindow, int x, int y, i if (freerdp_settings_get_bool(settings, FreeRDP_SoftwareGdi)) { - XPutImage(xfc->display, appWindow->pixmap, appWindow->gc, xfc->image, ax, ay, x, y, - WINPR_ASSERTING_INT_CAST(uint32_t, width), - WINPR_ASSERTING_INT_CAST(uint32_t, height)); + LogDynAndXPutImage(xfc->log, xfc->display, appWindow->pixmap, appWindow->gc, xfc->image, ax, + ay, x, y, WINPR_ASSERTING_INT_CAST(uint32_t, width), + WINPR_ASSERTING_INT_CAST(uint32_t, height)); } - XCopyArea(xfc->display, appWindow->pixmap, appWindow->handle, appWindow->gc, x, y, - WINPR_ASSERTING_INT_CAST(uint32_t, width), WINPR_ASSERTING_INT_CAST(uint32_t, height), - x, y); + LogDynAndXCopyArea(xfc->log, xfc->display, appWindow->pixmap, appWindow->handle, appWindow->gc, + x, y, WINPR_ASSERTING_INT_CAST(uint32_t, width), + WINPR_ASSERTING_INT_CAST(uint32_t, height), x, y); XFlush(xfc->display); xf_unlock_x11(xfc); } @@ -1514,11 +1514,12 @@ UINT xf_AppUpdateWindowFromSurface(xfContext* xfc, gdiGfxSurface* surface) const UINT32 width = rect->right - rect->left; const UINT32 height = rect->bottom - rect->top; - XPutImage(xfc->display, appWindow->pixmap, appWindow->gc, image, rect->left, rect->top, - rect->left, rect->top, width, height); + LogDynAndXPutImage(xfc->log, xfc->display, appWindow->pixmap, appWindow->gc, image, + rect->left, rect->top, rect->left, rect->top, width, height); - XCopyArea(xfc->display, appWindow->pixmap, appWindow->handle, appWindow->gc, rect->left, - rect->top, width, height, rect->left, rect->top); + LogDynAndXCopyArea(xfc->log, xfc->display, appWindow->pixmap, appWindow->handle, + appWindow->gc, rect->left, rect->top, width, height, rect->left, + rect->top); } rc = CHANNEL_RC_OK;