Signed-off-by: Adam Jackson a...@redhat.com
---
dix/colormap.c| 337 +-
dix/dispatch.c| 1 +
dix/dixfonts.c| 12 +-
dix/enterleave.c | 2 +-
dix/enterleave.h | 2 -
dix/main.c| 2 +
hw/xfree86/sdksyms.sh | 2 -
include/Makefile.am | 4 +-
include/colormap.h| 12 --
include/dixfont.h | 35 --
include/dixstruct.h | 27 ++--
include/swaprep.h | 320 +++
include/swapreq.h | 6 +-
mi/miglblt.c | 1 +
miext/damage/damage.c | 1 +
os/utils.c| 1 +
16 files changed, 360 insertions(+), 405 deletions(-)
diff --git a/dix/colormap.c b/dix/colormap.c
index a3e5a2c..89a17c4 100644
--- a/dix/colormap.c
+++ b/dix/colormap.c
@@ -64,6 +64,9 @@ SOFTWARE.
#include privates.h
#include xace.h
+typedef int (*ColorCompareProcPtr) (EntryPtr /*pent */ ,
+xrgb * /*prgb */ );
+
static Pixel FindBestPixel(EntryPtr /*pentFirst */ ,
int /*size */ ,
xrgb * /*prgb */ ,
@@ -748,6 +751,173 @@ UpdateColors(ColormapPtr pmap)
free(defs);
}
+/* Tries to find a color in pmap that exactly matches the one requested in prgb
+ * if it can't it allocates one.
+ * Starts looking at pentFirst + *pPixel, so if you want a specific pixel,
+ * load *pPixel with that value, otherwise set it to 0
+ */
+static int
+FindColor(ColormapPtr pmap, EntryPtr pentFirst, int size, xrgb * prgb,
+ Pixel * pPixel, int channel, int client, ColorCompareProcPtr comp)
+{
+EntryPtr pent;
+Bool foundFree;
+Pixel pixel, Free = 0;
+int npix, count, *nump = NULL;
+Pixel **pixp = NULL, *ppix;
+xColorItem def;
+
+foundFree = FALSE;
+
+if ((pixel = *pPixel) = size)
+pixel = 0;
+/* see if there is a match, and also look for a free entry */
+for (pent = pentFirst + pixel, count = size; --count = 0;) {
+if (pent-refcnt 0) {
+if ((*comp) (pent, prgb)) {
+if (client = 0)
+pent-refcnt++;
+*pPixel = pixel;
+switch (channel) {
+case REDMAP:
+*pPixel = pmap-pVisual-offsetRed;
+case PSEUDOMAP:
+break;
+case GREENMAP:
+*pPixel = pmap-pVisual-offsetGreen;
+break;
+case BLUEMAP:
+*pPixel = pmap-pVisual-offsetBlue;
+break;
+}
+goto gotit;
+}
+}
+else if (!foundFree pent-refcnt == 0) {
+Free = pixel;
+foundFree = TRUE;
+/* If we're initializing the colormap, then we are looking for
+ * the first free cell we can find, not to minimize the number
+ * of entries we use. So don't look any further. */
+if (pmap-flags BeingCreated)
+break;
+}
+pixel++;
+if (pixel = size) {
+pent = pentFirst;
+pixel = 0;
+}
+else
+pent++;
+}
+
+/* If we got here, we didn't find a match. If we also didn't find
+ * a free entry, we're out of luck. Otherwise, we'll usurp a free
+ * entry and fill it in */
+if (!foundFree)
+return BadAlloc;
+pent = pentFirst + Free;
+pent-fShared = FALSE;
+pent-refcnt = (client = 0) ? 1 : AllocTemporary;
+
+switch (channel) {
+case PSEUDOMAP:
+pent-co.local.red = prgb-red;
+pent-co.local.green = prgb-green;
+pent-co.local.blue = prgb-blue;
+def.red = prgb-red;
+def.green = prgb-green;
+def.blue = prgb-blue;
+def.flags = (DoRed | DoGreen | DoBlue);
+if (client = 0)
+pmap-freeRed--;
+def.pixel = Free;
+break;
+
+case REDMAP:
+pent-co.local.red = prgb-red;
+def.red = prgb-red;
+def.green = pmap-green[0].co.local.green;
+def.blue = pmap-blue[0].co.local.blue;
+def.flags = DoRed;
+if (client = 0)
+pmap-freeRed--;
+def.pixel = Free pmap-pVisual-offsetRed;
+break;
+
+case GREENMAP:
+pent-co.local.green = prgb-green;
+def.red = pmap-red[0].co.local.red;
+def.green = prgb-green;
+def.blue = pmap-blue[0].co.local.blue;
+def.flags = DoGreen;
+if (client = 0)
+pmap-freeGreen--;
+def.pixel = Free pmap-pVisual-offsetGreen;
+break;
+
+case BLUEMAP:
+pent-co.local.blue = prgb-blue;
+def.red = pmap-red[0].co.local.red;
+def.green = pmap-green[0].co.local.green;
+def.blue = prgb-blue;
+def.flags = DoBlue;
+if (client = 0)
+pmap-freeBlue--;
+def.pixel = Free pmap-pVisual-offsetBlue;
+