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(-) (limited to 'nx-X11/programs/Xserver/hw/nxagent/Drawable.c') 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 From cc8d8f72de9d30beb1331ecedfa3b329cb4b36f9 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Wed, 8 Jan 2020 22:30:38 +0100 Subject: Drawable.c: get rid of goto code in nxagentSynchronizeDrawableData Now all cleanup code at the end of the function is gone so there's no need for the gotos anymore. Just return directly. --- nx-X11/programs/Xserver/hw/nxagent/Drawable.c | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) (limited to 'nx-X11/programs/Xserver/hw/nxagent/Drawable.c') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Drawable.c b/nx-X11/programs/Xserver/hw/nxagent/Drawable.c index 5527e5d67..6068b16bf 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Drawable.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Drawable.c @@ -245,8 +245,6 @@ static int reallySynchronizeDrawableData(DrawablePtr pDrawable) int nxagentSynchronizeDrawableData(DrawablePtr pDrawable, unsigned int breakMask, WindowPtr owner) { - int success; - if (pDrawable -> type == DRAWABLE_PIXMAP) { /* @@ -261,9 +259,7 @@ int nxagentSynchronizeDrawableData(DrawablePtr pDrawable, unsigned int breakMask __func__, (void *) pDrawable); #endif - success = reallySynchronizeDrawableData(pDrawable); - - goto nxagentSynchronizeDrawableDataEnd; + return reallySynchronizeDrawableData(pDrawable); } else if (nxagentReconnectTrap == 1) { @@ -291,9 +287,7 @@ int nxagentSynchronizeDrawableData(DrawablePtr pDrawable, unsigned int breakMask } #endif - success = reallySynchronizeDrawableData(pDrawable); - - goto nxagentSynchronizeDrawableDataEnd; + return reallySynchronizeDrawableData(pDrawable); } else { @@ -304,9 +298,7 @@ int nxagentSynchronizeDrawableData(DrawablePtr pDrawable, unsigned int breakMask nxagentMarkCorruptedRegion(pDrawable, NullRegion); - success = 1; - - goto nxagentSynchronizeDrawableDataEnd; + return 1; } } } @@ -317,11 +309,7 @@ int nxagentSynchronizeDrawableData(DrawablePtr pDrawable, unsigned int breakMask * the drawable. */ - success = nxagentSynchronizeRegion(pDrawable, NullRegion, breakMask, owner); - -nxagentSynchronizeDrawableDataEnd: - - return success; + return nxagentSynchronizeRegion(pDrawable, NullRegion, breakMask, owner); } /* -- cgit v1.2.3 From dfb18f8fe7c921584b5fcc48a88219151bed6ae3 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Wed, 8 Jan 2020 22:54:32 +0100 Subject: nxagent: simplify nxagentFreeRegion macro Does not require two parameters. It could be replaced by RegionDestroy() entirely but we leave it to have a match to nxagentCreateRegion(). --- nx-X11/programs/Xserver/hw/nxagent/Drawable.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'nx-X11/programs/Xserver/hw/nxagent/Drawable.c') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Drawable.c b/nx-X11/programs/Xserver/hw/nxagent/Drawable.c index 6068b16bf..266ea86da 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Drawable.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Drawable.c @@ -941,7 +941,7 @@ nxagentSynchronizeRegionFree: if (clipRegion != NullRegion) { - nxagentFreeRegion(pDrawable, clipRegion); + nxagentFreeRegion(clipRegion); } SAFE_free(data); @@ -996,7 +996,7 @@ void nxagentSynchronizeBox(DrawablePtr pDrawable, BoxPtr pBox, unsigned int brea pRegion -> extents.x1, pRegion -> extents.y1, pRegion -> extents.x2, pRegion -> extents.y2); #endif - nxagentFreeRegion(pDrawable, pRegion); + nxagentFreeRegion(pRegion); return; } @@ -1009,7 +1009,7 @@ void nxagentSynchronizeBox(DrawablePtr pDrawable, BoxPtr pBox, unsigned int brea nxagentSynchronizeRegion(pDrawable, pRegion, breakMask, NULL); - nxagentFreeRegion(pDrawable, pRegion); + nxagentFreeRegion(pRegion); } } @@ -1520,7 +1520,7 @@ void nxagentMarkCorruptedRegion(DrawablePtr pDrawable, RegionPtr pRegion) RegionUnion(nxagentCorruptedRegion(pDrawable), nxagentCorruptedRegion(pDrawable), pRegion); - nxagentFreeRegion(pDrawable, pRegion); + nxagentFreeRegion(pRegion); } else { @@ -2321,7 +2321,7 @@ void nxagentCorruptedRegionOnWindow(void *p0, XID x, void *p2) RegionIntersect(&visRegion, clipRegion, nxagentCorruptedRegion((DrawablePtr) pWin)); - nxagentFreeRegion(pWin -> drawable.pScreen, clipRegion); + nxagentFreeRegion(clipRegion); if (RegionNil(&visRegion) == 1) { @@ -2528,7 +2528,7 @@ nxagentCreateDrawableBitmapEnd: if (pClipRegion != NullRegion) { - nxagentFreeRegion(pDrawable, pClipRegion); + nxagentFreeRegion(pClipRegion); } if (pGC != NULL) -- cgit v1.2.3 From b7169bdcaf320e219dec23e79882176bc4b69d4c Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Sat, 18 Jan 2020 15:24:20 +0100 Subject: nxagent: make all traps Booleans and use True/False instead of 1/0 --- nx-X11/programs/Xserver/hw/nxagent/Drawable.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'nx-X11/programs/Xserver/hw/nxagent/Drawable.c') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Drawable.c b/nx-X11/programs/Xserver/hw/nxagent/Drawable.c index 266ea86da..ba6d48fa5 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Drawable.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Drawable.c @@ -160,15 +160,15 @@ int nxagentSynchronizeDrawable(DrawablePtr pDrawable, int wait, unsigned int bre * so that the image will be transferred in a single operation. */ - nxagentFBTrap = 1; + nxagentFBTrap = True; - nxagentSplitTrap = 1; + nxagentSplitTrap = True; int result = nxagentSynchronizeDrawableData(pDrawable, breakMask, owner); - nxagentSplitTrap = 0; + nxagentSplitTrap = False; - nxagentFBTrap = 0; + nxagentFBTrap = False; if (wait == DO_WAIT && nxagentSplitResource(pDrawable) != NULL) { @@ -495,11 +495,11 @@ int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned int saveTrap = nxagentGCTrap; - nxagentGCTrap = 0; + nxagentGCTrap = False; - nxagentFBTrap = 1; + nxagentFBTrap = True; - nxagentSplitTrap = 1; + nxagentSplitTrap = True; pGC = nxagentGetGraphicContext(pDrawable); @@ -839,9 +839,9 @@ int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned nxagentSynchronizeRegionStop: - nxagentSplitTrap = 0; + nxagentSplitTrap = False; - nxagentFBTrap = 0; + nxagentFBTrap = False; nxagentGCTrap = saveTrap; @@ -2412,7 +2412,7 @@ void nxagentCreateDrawableBitmap(DrawablePtr pDrawable) int saveTrap = nxagentGCTrap; - nxagentGCTrap = 1; + nxagentGCTrap = True; if (nxagentDrawableStatus(pDrawable) == Synchronized) { -- cgit v1.2.3 From 762bfb50425428dddf5dd7df87836c52d21eb064 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Thu, 30 Jan 2020 22:45:18 +0100 Subject: nxagent: Fix double variables nxagentCorrupted* were defined twice! Fixes ArcticaProject/nx-libs#907 (1/3) --- nx-X11/programs/Xserver/hw/nxagent/Drawable.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'nx-X11/programs/Xserver/hw/nxagent/Drawable.c') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Drawable.c b/nx-X11/programs/Xserver/hw/nxagent/Drawable.c index ba6d48fa5..bdbf4fcf8 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Drawable.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Drawable.c @@ -91,6 +91,11 @@ RESTYPE RT_NX_CORR_WINDOW; RESTYPE RT_NX_CORR_PIXMAP; int nxagentCorruptedPixmaps = 0; + +/* + * Number of windows which need synchronization. + */ + int nxagentCorruptedWindows = 0; int nxagentCorruptedBackgrounds = 0; -- cgit v1.2.3