aboutsummaryrefslogtreecommitdiff
path: root/nx-X11
diff options
context:
space:
mode:
authorUlrich Sibiller <uli42@gmx.de>2020-01-08 22:28:11 +0100
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2020-05-07 12:55:04 +0200
commitbeef0cd99e476188165425fd6516a0b02ce54a80 (patch)
tree5f3d47b35676028b802069dd1db51b79a2f77e22 /nx-X11
parent06638575702dec2b58ea6c2a4098c2d5b4c30dd0 (diff)
downloadnx-libs-beef0cd99e476188165425fd6516a0b02ce54a80.tar.gz
nx-libs-beef0cd99e476188165425fd6516a0b02ce54a80.tar.bz2
nx-libs-beef0cd99e476188165425fd6516a0b02ce54a80.zip
Drawable.c: refactor nxagentSynchronizeDrawableData
move common code into helper function that also takes care of the ugly alloc/free stuff.
Diffstat (limited to 'nx-X11')
-rw-r--r--nx-X11/programs/Xserver/hw/nxagent/Drawable.c130
1 files 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;
}