From beef0cd99e476188165425fd6516a0b02ce54a80 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Wed, 8 Jan 2020 22:28:11 +0100 Subject: Drawable.c: refactor nxagentSynchronizeDrawableData move common code into helper function that also takes care of the ugly alloc/free stuff. --- nx-X11/programs/Xserver/hw/nxagent/Drawable.c | 130 +++++++++++--------------- 1 file changed, 52 insertions(+), 78 deletions(-) diff --git a/nx-X11/programs/Xserver/hw/nxagent/Drawable.c b/nx-X11/programs/Xserver/hw/nxagent/Drawable.c index 7f1d2dec5..5527e5d67 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Drawable.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Drawable.c @@ -191,45 +191,64 @@ int nxagentSynchronizeDrawable(DrawablePtr pDrawable, int wait, unsigned int bre return result; } -int nxagentSynchronizeDrawableData(DrawablePtr pDrawable, unsigned int breakMask, WindowPtr owner) +static int reallySynchronizeDrawableData(DrawablePtr pDrawable) { - char *data = NULL; - int success; + GCPtr pGC = nxagentGetGraphicContext(pDrawable); - if (pDrawable -> type == DRAWABLE_PIXMAP) + if (pGC == NULL) { - GCPtr pGC; + #ifdef WARNING + fprintf(stderr, "%s: WARNING! Failed to get the temporary GC.\n", __func__); + #endif - unsigned int leftPad = 0; + return 0; + } - int width = pDrawable -> width; - int height = pDrawable -> height; - int depth = pDrawable -> depth; + DrawablePtr pSrcDrawable = (pDrawable -> type == DRAWABLE_PIXMAP ? + ((DrawablePtr) nxagentVirtualPixmap((PixmapPtr) pDrawable)) : + pDrawable); - #ifdef TEST - fprintf(stderr, "nxagentSynchronizeDrawableData: Synchronizing drawable (%s) with geometry [%d][%d][%d].\n", - nxagentDrawableType(pDrawable), width, height, depth); + int width = pDrawable -> width; + int height = pDrawable -> height; + int depth = pDrawable -> depth; + + #ifdef TEST + fprintf(stderr, "%s: Synchronizing drawable (%s) with geometry [%d][%d][%d].\n", + __func__, nxagentDrawableType(pDrawable), width, height, depth); + #endif + + unsigned int format = (depth == 1) ? XYPixmap : ZPixmap; + + int length = nxagentImageLength(width, height, format, 0, depth); + + char *data = malloc(length); + if (data == NULL) + { + #ifdef WARNING + fprintf(stderr, "%s: WARNING! Failed to allocate memory for the operation.\n", __func__); #endif - unsigned int format = (depth == 1) ? XYPixmap : ZPixmap; + return 0; + } - int length = nxagentImageLength(width, height, format, leftPad, depth); + ValidateGC(pDrawable, pGC); - if ((data = malloc(length)) == NULL) - { - #ifdef WARNING - fprintf(stderr, "nxagentSynchronizeDrawableData: WARNING! Failed to allocate memory for the operation.\n"); - #endif + fbGetImage(pSrcDrawable, 0, 0, width, height, format, AllPlanes, data); - success = 0; + nxagentPutImage(pDrawable, pGC, depth, 0, 0, + width, height, 0, format, data); - goto nxagentSynchronizeDrawableDataEnd; - } + SAFE_free(data); - DrawablePtr pSrcDrawable = (pDrawable -> type == DRAWABLE_PIXMAP ? - ((DrawablePtr) nxagentVirtualPixmap((PixmapPtr) pDrawable)) : - pDrawable); + return 1; +} + +int nxagentSynchronizeDrawableData(DrawablePtr pDrawable, unsigned int breakMask, WindowPtr owner) +{ + int success; + if (pDrawable -> type == DRAWABLE_PIXMAP) + { /* * Synchronize the whole pixmap if we need to download a fresh * copy with lossless compression turned off. @@ -237,33 +256,12 @@ int nxagentSynchronizeDrawableData(DrawablePtr pDrawable, unsigned int breakMask if (nxagentLosslessTrap == 1) { - pGC = nxagentGetGraphicContext(pDrawable); - - if (pGC == NULL) - { - #ifdef WARNING - fprintf(stderr, "nxagentSynchronizeDrawableData: WARNING! Failed to get the temporary GC.\n"); - #endif - - success = 0; - - goto nxagentSynchronizeDrawableDataEnd; - } - - ValidateGC(pDrawable, pGC); - - fbGetImage(pSrcDrawable, 0, 0, - width, height, format, AllPlanes, data); - #ifdef TEST - fprintf(stderr, "nxagentSynchronizeDrawableData: Forcing synchronization of " - "pixmap at [%p] with lossless compression.\n", (void *) pDrawable); + fprintf(stderr, "%s: Forcing synchronization of pixmap at [%p] with lossless compression.\n", + __func__, (void *) pDrawable); #endif - nxagentPutImage(pDrawable, pGC, depth, 0, 0, - width, height, leftPad, format, data); - - success = 1; + success = reallySynchronizeDrawableData(pDrawable); goto nxagentSynchronizeDrawableDataEnd; } @@ -278,7 +276,6 @@ int nxagentSynchronizeDrawableData(DrawablePtr pDrawable, unsigned int breakMask if (pDrawable -> depth == 1) { #ifdef TEST - if (nxagentReconnectTrap == 1) { static int totalLength; @@ -287,44 +284,22 @@ int nxagentSynchronizeDrawableData(DrawablePtr pDrawable, unsigned int breakMask totalLength += length; totalReconnectedPixmaps++; - fprintf(stderr, "nxagentSynchronizeDrawableData: Reconnecting pixmap at [%p] [%dx%d] " + fprintf(stderr, "%s: Reconnecting pixmap at [%p] [%dx%d] " "Depth [%d] Size [%d]. Total size [%d]. Total reconnected pixmaps [%d].\n", - (void *) pDrawable, width, height, depth, length, + __func__, (void *) pDrawable, width, height, depth, length, totalLength, totalReconnectedPixmaps); } - #endif - pGC = nxagentGetGraphicContext(pDrawable); - - if (pGC == NULL) - { - #ifdef WARNING - fprintf(stderr, "nxagentSynchronizeDrawableData: WARNING! Failed to create the temporary GC.\n"); - #endif - - success = 0; - - goto nxagentSynchronizeDrawableDataEnd; - } - - ValidateGC(pDrawable, pGC); - - fbGetImage(pSrcDrawable, 0, 0, - width, height, format, AllPlanes, data); - - nxagentPutImage(pDrawable, pGC, depth, 0, 0, - width, height, leftPad, format, data); - - success = 1; + success = reallySynchronizeDrawableData(pDrawable); goto nxagentSynchronizeDrawableDataEnd; } else { #ifdef TEST - fprintf(stderr, "nxagentSynchronizeDrawableData: Skipping synchronization of " - "pixmap at [%p][%p] during reconnection.\n", (void *) pDrawable, (void*) nxagentVirtualPixmap((PixmapPtr)pDrawable)); + fprintf(stderr, "%s: Skipping synchronization of pixmap at [%p][%p] during reconnection.\n", + __func__, (void *) pDrawable, (void*) nxagentVirtualPixmap((PixmapPtr)pDrawable)); #endif nxagentMarkCorruptedRegion(pDrawable, NullRegion); @@ -345,7 +320,6 @@ int nxagentSynchronizeDrawableData(DrawablePtr pDrawable, unsigned int breakMask success = nxagentSynchronizeRegion(pDrawable, NullRegion, breakMask, owner); nxagentSynchronizeDrawableDataEnd: - SAFE_free(data); return success; } -- cgit v1.2.3