summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Airlie <airlied@linux.ie>2010-10-31 16:26:16 +1000
committerDave Airlie <airlied@linux.ie>2010-10-31 16:26:16 +1000
commitf6a05444d1a5c8f9929fde72834102dde61adbc4 (patch)
treec354b38774c270be4182ebdab134c8a48f0d20e2
parent36ede5034dbc2709548eedd9f31b7454ee020c45 (diff)
add colormap/gc/pixmap duplication.
fix a bug in window duplication getting wrong pScreen set
-rw-r--r--Xext/panoramiX.c92
-rw-r--r--Xext/panoramiXprocs.c4
-rw-r--r--dix/colormap.c29
-rw-r--r--dix/pixmap.c16
-rw-r--r--dix/window.c1
-rw-r--r--include/colormap.h3
-rw-r--r--include/pixmap.h1
7 files changed, 139 insertions, 7 deletions
diff --git a/Xext/panoramiX.c b/Xext/panoramiX.c
index 755f83d95..f8bd35c00 100644
--- a/Xext/panoramiX.c
+++ b/Xext/panoramiX.c
@@ -1077,9 +1077,95 @@ static void print_xrt(pointer value, XID id, pointer cdata)
// if (xrt->type == XRT_PICTURE)
// ErrorF("pic: %p: %d %p\n", cdata, id, xrt);
+}
+
+static void duplicate_pixmap(pointer value, XID id, pointer cdata)
+{
+ PanoramiXRes *xrt = value;
+ ClientPtr client = cdata;
+ PixmapPtr pPixmap, pNewPixmap;
+ int i = 1;
+
+ int result;
+
+ result = dixLookupResourceByType(&pPixmap, xrt->info[0].id, RT_PIXMAP, client, DixGetAttrAccess);
+ if (result != Success)
+ return;
+
+ if (xrt->info[i].id)
+ return;
+
+ xrt->info[i].id = FakeClientID(client->index);
+
+ pNewPixmap = DuplicatePixmap(xrt->info[i].id, screenInfo.screens[i], pPixmap);
+
+ if (!AddResource(xrt->info[i].id, RT_PIXMAP, (pointer)pNewPixmap)) {
+ ErrorF("failed to add resource\n");
+ return;
+ }
+
+ return;
+}
+
+static void duplicate_gc(pointer value, XID id, pointer cdata)
+{
+ PanoramiXRes *xrt = value;
+ ClientPtr client = cdata;
+ GCPtr pGC, pNewGC;
+ int i = 1;
+
+ int result;
+ result = dixLookupGC(&pGC, xrt->info[0].id, client, DixGetAttrAccess);
+ if (result != Success)
+ return;
+ if (xrt->info[i].id)
+ return;
+
+ xrt->info[i].id = FakeClientID(client->index);
+
+ pNewGC = DuplicateGC(xrt->info[i].id, screenInfo.screens[i], pGC);
+
+ if (!(*pNewGC->pScreen->CreateGC)(pNewGC))
+ return;
+
+ if (!AddResource(xrt->info[i].id, RT_GC, (pointer)pNewGC)) {
+ ErrorF("failed to add resource\n");
+ return;
+ }
+
+ return;
}
+static void duplicate_cmap(pointer value, XID id, pointer cdata)
+{
+ PanoramiXRes *xrt = value;
+ ClientPtr client = cdata;
+ ColormapPtr pcmap, pnewcmap;
+ int i = 1;
+
+ int result;
+
+ result = dixLookupResourceByType((pointer *)&pcmap, xrt->info[0].id,
+ RT_COLORMAP, client, DixReadAccess);
+ if (result != Success)
+ return;
+
+ if (xrt->info[i].id)
+ return;
+
+ xrt->info[i].id = FakeClientID(client->index);
+
+ pnewcmap = DuplicateColormap(xrt->info[i].id, screenInfo.screens[i], pcmap);
+
+ if (!AddResource(xrt->info[i].id, RT_COLORMAP, (pointer)pnewcmap)) {
+ ErrorF("failed to add resource\n");
+ return;
+ }
+
+ return;
+}
+
int
XineramaDoBasicScreenInit(ScreenPtr pScreen, int i)
{
@@ -1186,9 +1272,9 @@ XineramaDoMigrateScreen(void)
for (i = currentMaxClients; --i >= 0; )
{
// FindClientResourcesByType(clients[i], XRT_WINDOW, print_xrt, clients[i]);
- FindClientResourcesByType(clients[i], XRT_PIXMAP, print_xrt, clients[i]);
- FindClientResourcesByType(clients[i], XRT_GC, print_xrt, clients[i]);
- FindClientResourcesByType(clients[i], XRT_COLORMAP, print_xrt, clients[i]);
+ FindClientResourcesByType(clients[i], XRT_PIXMAP, duplicate_pixmap, clients[i]);
+ FindClientResourcesByType(clients[i], XRT_GC, duplicate_gc, clients[i]);
+ FindClientResourcesByType(clients[i], XRT_COLORMAP, duplicate_cmap, clients[i]);
}
return Success;
}
diff --git a/Xext/panoramiXprocs.c b/Xext/panoramiXprocs.c
index 8be3249c1..cba71e32e 100644
--- a/Xext/panoramiXprocs.c
+++ b/Xext/panoramiXprocs.c
@@ -763,7 +763,7 @@ int PanoramiXCreateGC(ClientPtr client)
}
}
- if(!(newGC = malloc(sizeof(PanoramiXRes))))
+ if(!(newGC = calloc(1, sizeof(PanoramiXRes))))
return BadAlloc;
newGC->type = XRT_GC;
@@ -2117,7 +2117,7 @@ int PanoramiXCreateColormap(ClientPtr client)
if (result != Success)
return result;
- if(!(newCmap = malloc(sizeof(PanoramiXRes))))
+ if(!(newCmap = calloc(1, sizeof(PanoramiXRes))))
return BadAlloc;
newCmap->type = XRT_COLORMAP;
diff --git a/dix/colormap.c b/dix/colormap.c
index ba4d1dbd9..a67cd0b4b 100644
--- a/dix/colormap.c
+++ b/dix/colormap.c
@@ -246,9 +246,34 @@ typedef struct _colorResource
ColormapPtr DuplicateColormap(Colormap mid, ScreenPtr pScreen,
- ColormapPtr *pSrc)
+ ColormapPtr pSrc)
{
-
+ ColormapPtr pmap;
+ unsigned sizebytes, size;
+
+ size = pSrc->pVisual->ColormapEntries;
+ sizebytes = (size * sizeof(Entry)) +
+ (MAXCLIENTS * sizeof(Pixel *)) +
+ (MAXCLIENTS * sizeof(int));
+ if ((pSrc->class | DynamicClass) == DirectColor)
+ sizebytes *= 3;
+ sizebytes += sizeof(ColormapRec);
+
+ if (mid == pScreen->defColormap) {
+ ErrorF("default colormap\n");
+ }
+
+ pmap = _dixAllocateObjectWithPrivates(sizebytes, sizebytes,
+ offsetof(ColormapRec, devPrivates), PRIVATE_COLORMAP);
+ if (!pmap)
+ return NULL;
+
+ *pmap = *pSrc;
+ pmap->mid = mid;
+ pmap->pScreen = pScreen;
+
+ return pmap;
+
}
/**
diff --git a/dix/pixmap.c b/dix/pixmap.c
index cbb5e7f99..9ae4cfc17 100644
--- a/dix/pixmap.c
+++ b/dix/pixmap.c
@@ -135,3 +135,19 @@ FreePixmap(PixmapPtr pPixmap)
dixFiniPrivates(pPixmap, PRIVATE_PIXMAP);
free(pPixmap);
}
+
+PixmapPtr DuplicatePixmap(XID pid, ScreenPtr pScreen, PixmapPtr pSrc)
+{
+ PixmapPtr pMap;
+ pMap = (PixmapPtr)(*pScreen->CreatePixmap)
+ (pScreen, pSrc->drawable.width,
+ pSrc->drawable.height, pSrc->drawable.depth, 0);
+ if (!pMap)
+ return NULL;
+
+
+ if (AddResource(pid, RT_PIXMAP, (pointer)pMap))
+ return pMap;
+
+ return NULL;
+}
diff --git a/dix/window.c b/dix/window.c
index 6cc9702be..f11be7cf6 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -553,6 +553,7 @@ DuplicateWindow(Window wid, WindowPtr pParent, WindowPtr pSrc)
*pWin = *pSrc;
pWin->devPrivates = devPrivates;
pWin->drawable.id = wid;
+ pWin->drawable.pScreen = pScreen;
pWin->parent = pParent;
pWin->nextSib = NULL;
diff --git a/include/colormap.h b/include/colormap.h
index 1b1574839..427a2832b 100644
--- a/include/colormap.h
+++ b/include/colormap.h
@@ -186,4 +186,7 @@ extern _X_EXPORT Bool ResizeVisualArray(
int /* new_vis_count */,
DepthPtr /* depth */);
+ColormapPtr DuplicateColormap(Colormap mid, ScreenPtr pScreen,
+ ColormapPtr pSrc);
+
#endif /* CMAP_H */
diff --git a/include/pixmap.h b/include/pixmap.h
index 014a11183..34cdf197b 100644
--- a/include/pixmap.h
+++ b/include/pixmap.h
@@ -116,4 +116,5 @@ extern _X_EXPORT PixmapPtr AllocatePixmap(
extern _X_EXPORT void FreePixmap(
PixmapPtr /*pPixmap*/);
+PixmapPtr DuplicatePixmap(XID pid, ScreenPtr pScreen, PixmapPtr pSrc);
#endif /* PIXMAP_H */