Commit beef0cd9 authored by Ulrich Sibiller's avatar Ulrich Sibiller Committed by Mike Gabriel

Drawable.c: refactor nxagentSynchronizeDrawableData

move common code into helper function that also takes care of the ugly alloc/free stuff.
parent 06638575
...@@ -191,45 +191,64 @@ int nxagentSynchronizeDrawable(DrawablePtr pDrawable, int wait, unsigned int bre ...@@ -191,45 +191,64 @@ int nxagentSynchronizeDrawable(DrawablePtr pDrawable, int wait, unsigned int bre
return result; return result;
} }
int nxagentSynchronizeDrawableData(DrawablePtr pDrawable, unsigned int breakMask, WindowPtr owner) static int reallySynchronizeDrawableData(DrawablePtr pDrawable)
{ {
char *data = NULL; GCPtr pGC = nxagentGetGraphicContext(pDrawable);
int success;
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; DrawablePtr pSrcDrawable = (pDrawable -> type == DRAWABLE_PIXMAP ?
int height = pDrawable -> height; ((DrawablePtr) nxagentVirtualPixmap((PixmapPtr) pDrawable)) :
int depth = pDrawable -> depth; pDrawable);
#ifdef TEST int width = pDrawable -> width;
fprintf(stderr, "nxagentSynchronizeDrawableData: Synchronizing drawable (%s) with geometry [%d][%d][%d].\n", int height = pDrawable -> height;
nxagentDrawableType(pDrawable), width, height, depth); 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 #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) fbGetImage(pSrcDrawable, 0, 0, width, height, format, AllPlanes, data);
{
#ifdef WARNING
fprintf(stderr, "nxagentSynchronizeDrawableData: WARNING! Failed to allocate memory for the operation.\n");
#endif
success = 0; nxagentPutImage(pDrawable, pGC, depth, 0, 0,
width, height, 0, format, data);
goto nxagentSynchronizeDrawableDataEnd; SAFE_free(data);
}
DrawablePtr pSrcDrawable = (pDrawable -> type == DRAWABLE_PIXMAP ? return 1;
((DrawablePtr) nxagentVirtualPixmap((PixmapPtr) pDrawable)) : }
pDrawable);
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 * Synchronize the whole pixmap if we need to download a fresh
* copy with lossless compression turned off. * copy with lossless compression turned off.
...@@ -237,33 +256,12 @@ int nxagentSynchronizeDrawableData(DrawablePtr pDrawable, unsigned int breakMask ...@@ -237,33 +256,12 @@ int nxagentSynchronizeDrawableData(DrawablePtr pDrawable, unsigned int breakMask
if (nxagentLosslessTrap == 1) 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 #ifdef TEST
fprintf(stderr, "nxagentSynchronizeDrawableData: Forcing synchronization of " fprintf(stderr, "%s: Forcing synchronization of pixmap at [%p] with lossless compression.\n",
"pixmap at [%p] with lossless compression.\n", (void *) pDrawable); __func__, (void *) pDrawable);
#endif #endif
nxagentPutImage(pDrawable, pGC, depth, 0, 0, success = reallySynchronizeDrawableData(pDrawable);
width, height, leftPad, format, data);
success = 1;
goto nxagentSynchronizeDrawableDataEnd; goto nxagentSynchronizeDrawableDataEnd;
} }
...@@ -278,7 +276,6 @@ int nxagentSynchronizeDrawableData(DrawablePtr pDrawable, unsigned int breakMask ...@@ -278,7 +276,6 @@ int nxagentSynchronizeDrawableData(DrawablePtr pDrawable, unsigned int breakMask
if (pDrawable -> depth == 1) if (pDrawable -> depth == 1)
{ {
#ifdef TEST #ifdef TEST
if (nxagentReconnectTrap == 1) if (nxagentReconnectTrap == 1)
{ {
static int totalLength; static int totalLength;
...@@ -287,44 +284,22 @@ int nxagentSynchronizeDrawableData(DrawablePtr pDrawable, unsigned int breakMask ...@@ -287,44 +284,22 @@ int nxagentSynchronizeDrawableData(DrawablePtr pDrawable, unsigned int breakMask
totalLength += length; totalLength += length;
totalReconnectedPixmaps++; 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", "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); totalLength, totalReconnectedPixmaps);
} }
#endif #endif
pGC = nxagentGetGraphicContext(pDrawable); success = reallySynchronizeDrawableData(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;
goto nxagentSynchronizeDrawableDataEnd; goto nxagentSynchronizeDrawableDataEnd;
} }
else else
{ {
#ifdef TEST #ifdef TEST
fprintf(stderr, "nxagentSynchronizeDrawableData: Skipping synchronization of " fprintf(stderr, "%s: Skipping synchronization of pixmap at [%p][%p] during reconnection.\n",
"pixmap at [%p][%p] during reconnection.\n", (void *) pDrawable, (void*) nxagentVirtualPixmap((PixmapPtr)pDrawable)); __func__, (void *) pDrawable, (void*) nxagentVirtualPixmap((PixmapPtr)pDrawable));
#endif #endif
nxagentMarkCorruptedRegion(pDrawable, NullRegion); nxagentMarkCorruptedRegion(pDrawable, NullRegion);
...@@ -345,7 +320,6 @@ int nxagentSynchronizeDrawableData(DrawablePtr pDrawable, unsigned int breakMask ...@@ -345,7 +320,6 @@ int nxagentSynchronizeDrawableData(DrawablePtr pDrawable, unsigned int breakMask
success = nxagentSynchronizeRegion(pDrawable, NullRegion, breakMask, owner); success = nxagentSynchronizeRegion(pDrawable, NullRegion, breakMask, owner);
nxagentSynchronizeDrawableDataEnd: nxagentSynchronizeDrawableDataEnd:
SAFE_free(data);
return success; return success;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment