diff options
author | Matthieu Herrb <matthieu@cvs.openbsd.org> | 2010-12-05 15:36:12 +0000 |
---|---|---|
committer | Matthieu Herrb <matthieu@cvs.openbsd.org> | 2010-12-05 15:36:12 +0000 |
commit | a90ee792d96752ad1b71b9ada922fa6afe478c99 (patch) | |
tree | 6143b00f7646951d23dfe2a4fe2992ca40b77069 /xserver/dix | |
parent | bc97d4ecc0aa9e1b823565b07282f848700bd11a (diff) |
Upgrade to xorg-server 1.9.2.
Tested by ajacoutot@, krw@, shadchin@ and jasper@ on various configurations
including multihead with both zaphod and xrandr.
Diffstat (limited to 'xserver/dix')
31 files changed, 3882 insertions, 2084 deletions
diff --git a/xserver/dix/Makefile.am b/xserver/dix/Makefile.am index 42b5121fe..5e2dad7d3 100644 --- a/xserver/dix/Makefile.am +++ b/xserver/dix/Makefile.am @@ -32,6 +32,7 @@ libdix_la_SOURCES = \ privates.c \ property.c \ ptrveloc.c \ + region.c \ registry.c \ resource.c \ selection.c \ diff --git a/xserver/dix/Makefile.in b/xserver/dix/Makefile.in index 7b8226a3e..d1179d679 100644 --- a/xserver/dix/Makefile.in +++ b/xserver/dix/Makefile.in @@ -64,8 +64,8 @@ am_libdix_la_OBJECTS = atom.lo colormap.lo cursor.lo deprecated.lo \ events.lo eventconvert.lo extension.lo ffs.lo gc.lo \ getevents.lo globals.lo glyphcurs.lo grabs.lo initatoms.lo \ inpututils.lo pixmap.lo privates.lo property.lo ptrveloc.lo \ - registry.lo resource.lo selection.lo swaprep.lo swapreq.lo \ - tables.lo window.lo + region.lo registry.lo resource.lo selection.lo swaprep.lo \ + swapreq.lo tables.lo window.lo libdix_la_OBJECTS = $(am_libdix_la_OBJECTS) libmain_la_LIBADD = am_libmain_la_OBJECTS = main.lo @@ -133,10 +133,6 @@ BUILDDOCS_TRUE = @BUILDDOCS_TRUE@ BUILD_DATE = @BUILD_DATE@ BUILD_KDRIVEFBDEVLIB_FALSE = @BUILD_KDRIVEFBDEVLIB_FALSE@ BUILD_KDRIVEFBDEVLIB_TRUE = @BUILD_KDRIVEFBDEVLIB_TRUE@ -BUILD_LINUXDOC_FALSE = @BUILD_LINUXDOC_FALSE@ -BUILD_LINUXDOC_TRUE = @BUILD_LINUXDOC_TRUE@ -BUILD_PDFDOC_FALSE = @BUILD_PDFDOC_FALSE@ -BUILD_PDFDOC_TRUE = @BUILD_PDFDOC_TRUE@ BUILD_TIME = @BUILD_TIME@ CC = @CC@ CCAS = @CCAS@ @@ -224,6 +220,8 @@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ +ENABLE_DEVEL_DOCS_FALSE = @ENABLE_DEVEL_DOCS_FALSE@ +ENABLE_DEVEL_DOCS_TRUE = @ENABLE_DEVEL_DOCS_TRUE@ EXEEXT = @EXEEXT@ F77 = @F77@ FBDEVHW_FALSE = @FBDEVHW_FALSE@ @@ -238,6 +236,7 @@ FONTOTFDIR = @FONTOTFDIR@ FONTROOTDIR = @FONTROOTDIR@ FONTTTFDIR = @FONTTTFDIR@ FONTTYPE1DIR = @FONTTYPE1DIR@ +FOP = @FOP@ FREEBSD_KLDLOAD_FALSE = @FREEBSD_KLDLOAD_FALSE@ FREEBSD_KLDLOAD_TRUE = @FREEBSD_KLDLOAD_TRUE@ GLIB_CFLAGS = @GLIB_CFLAGS@ @@ -255,10 +254,14 @@ HAVE_DBUS_FALSE = @HAVE_DBUS_FALSE@ HAVE_DBUS_TRUE = @HAVE_DBUS_TRUE@ HAVE_DOXYGEN_FALSE = @HAVE_DOXYGEN_FALSE@ HAVE_DOXYGEN_TRUE = @HAVE_DOXYGEN_TRUE@ -HAVE_PS2PDF_FALSE = @HAVE_PS2PDF_FALSE@ -HAVE_PS2PDF_TRUE = @HAVE_PS2PDF_TRUE@ +HAVE_FOP_FALSE = @HAVE_FOP_FALSE@ +HAVE_FOP_TRUE = @HAVE_FOP_TRUE@ HAVE_STYLESHEETS_FALSE = @HAVE_STYLESHEETS_FALSE@ HAVE_STYLESHEETS_TRUE = @HAVE_STYLESHEETS_TRUE@ +HAVE_XMLTO_FALSE = @HAVE_XMLTO_FALSE@ +HAVE_XMLTO_TEXT_FALSE = @HAVE_XMLTO_TEXT_FALSE@ +HAVE_XMLTO_TEXT_TRUE = @HAVE_XMLTO_TEXT_TRUE@ +HAVE_XMLTO_TRUE = @HAVE_XMLTO_TRUE@ HP300_VIDEO_FALSE = @HP300_VIDEO_FALSE@ HP300_VIDEO_TRUE = @HP300_VIDEO_TRUE@ HPPA_VIDEO_FALSE = @HPPA_VIDEO_FALSE@ @@ -314,10 +317,11 @@ LIBDRM_CFLAGS = @LIBDRM_CFLAGS@ LIBDRM_LIBS = @LIBDRM_LIBS@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ +LIBSHA1_CFLAGS = @LIBSHA1_CFLAGS@ +LIBSHA1_LIBS = @LIBSHA1_LIBS@ LIBTOOL = @LIBTOOL@ LIB_MAN_DIR = @LIB_MAN_DIR@ LIB_MAN_SUFFIX = @LIB_MAN_SUFFIX@ -LINUXDOC = @LINUXDOC@ LINUX_ALPHA_FALSE = @LINUX_ALPHA_FALSE@ LINUX_ALPHA_TRUE = @LINUX_ALPHA_TRUE@ LINUX_IA64_FALSE = @LINUX_IA64_FALSE@ @@ -335,17 +339,11 @@ MAINTAINER_MODE_FALSE = @MAINTAINER_MODE_FALSE@ MAINTAINER_MODE_TRUE = @MAINTAINER_MODE_TRUE@ MAIN_LIB = @MAIN_LIB@ MAKEINFO = @MAKEINFO@ -MAKE_HTML = @MAKE_HTML@ -MAKE_PDF = @MAKE_PDF@ -MAKE_PS = @MAKE_PS@ -MAKE_TEXT = @MAKE_TEXT@ MAN_SUBSTS = @MAN_SUBSTS@ MISC_MAN_DIR = @MISC_MAN_DIR@ MISC_MAN_SUFFIX = @MISC_MAN_SUFFIX@ MITSHM_FALSE = @MITSHM_FALSE@ MITSHM_TRUE = @MITSHM_TRUE@ -MULTIBUFFER_FALSE = @MULTIBUFFER_FALSE@ -MULTIBUFFER_TRUE = @MULTIBUFFER_TRUE@ NEED_STRLCAT_FALSE = @NEED_STRLCAT_FALSE@ NEED_STRLCAT_TRUE = @NEED_STRLCAT_TRUE@ NEED_VSNPRINTF_FALSE = @NEED_VSNPRINTF_FALSE@ @@ -372,20 +370,23 @@ PCIACCESS_CFLAGS = @PCIACCESS_CFLAGS@ PCIACCESS_LIBS = @PCIACCESS_LIBS@ PCI_TXT_IDS_PATH = @PCI_TXT_IDS_PATH@ PERL = @PERL@ +PIXMAN_CFLAGS = @PIXMAN_CFLAGS@ +PIXMAN_LIBS = @PIXMAN_LIBS@ PKG_CONFIG = @PKG_CONFIG@ PPC_VIDEO_FALSE = @PPC_VIDEO_FALSE@ PPC_VIDEO_TRUE = @PPC_VIDEO_TRUE@ PROJECTROOT = @PROJECTROOT@ -PS2PDF = @PS2PDF@ RANLIB = @RANLIB@ RAWCPP = @RAWCPP@ RAWCPPFLAGS = @RAWCPPFLAGS@ RECORD_FALSE = @RECORD_FALSE@ RECORD_TRUE = @RECORD_TRUE@ +RELEASE_DATE = @RELEASE_DATE@ RES_FALSE = @RES_FALSE@ RES_TRUE = @RES_TRUE@ SCREENSAVER_FALSE = @SCREENSAVER_FALSE@ SCREENSAVER_TRUE = @SCREENSAVER_TRUE@ +SDK_REQUIRED_MODULES = @SDK_REQUIRED_MODULES@ SECURE_RPC_FALSE = @SECURE_RPC_FALSE@ SECURE_RPC_TRUE = @SECURE_RPC_TRUE@ SED = @SED@ @@ -477,6 +478,7 @@ XKB_COMPILED_DIR = @XKB_COMPILED_DIR@ XKM_OUTPUT_DIR = @XKM_OUTPUT_DIR@ XLIB_CFLAGS = @XLIB_CFLAGS@ XLIB_LIBS = @XLIB_LIBS@ +XMLTO = @XMLTO@ XNESTMODULES_CFLAGS = @XNESTMODULES_CFLAGS@ XNESTMODULES_LIBS = @XNESTMODULES_LIBS@ XNEST_FALSE = @XNEST_FALSE@ @@ -654,6 +656,7 @@ libdix_la_SOURCES = \ privates.c \ property.c \ ptrveloc.c \ + region.c \ registry.c \ resource.c \ selection.c \ @@ -761,6 +764,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/privates.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/property.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ptrveloc.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/region.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/registry.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/resource.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/selection.Plo@am__quote@ diff --git a/xserver/dix/atom.c b/xserver/dix/atom.c index f5bf8ad7e..88b40db65 100644 --- a/xserver/dix/atom.c +++ b/xserver/dix/atom.c @@ -68,7 +68,7 @@ typedef struct _Node { } NodeRec, *NodePtr; static Atom lastAtom = None; -static NodePtr atomRoot = (NodePtr)NULL; +static NodePtr atomRoot = NULL; static unsigned long tableLength; static NodePtr *nodeTable; @@ -88,7 +88,7 @@ MakeAtom(const char *string, unsigned len, Bool makeit) fp = fp * 27 + string[i]; fp = fp * 27 + string[len - 1 - i]; } - while (*np != (NodePtr) NULL) + while (*np != NULL) { if (fp < (*np)->fingerPrint) np = &((*np)->left); @@ -109,7 +109,7 @@ MakeAtom(const char *string, unsigned len, Bool makeit) { NodePtr nd; - nd = xalloc(sizeof(NodeRec)); + nd = malloc(sizeof(NodeRec)); if (!nd) return BAD_RESOURCE; if (lastAtom < XA_LAST_PREDEFINED) @@ -118,9 +118,9 @@ MakeAtom(const char *string, unsigned len, Bool makeit) } else { - char *newstring = xalloc(len + 1); + char *newstring = malloc(len + 1); if (!newstring) { - xfree(nd); + free(nd); return BAD_RESOURCE; } strncpy(newstring, string, (int)len); @@ -130,22 +130,23 @@ MakeAtom(const char *string, unsigned len, Bool makeit) if ((lastAtom + 1) >= tableLength) { NodePtr *table; - table = (NodePtr *) xrealloc(nodeTable, - tableLength * (2 * sizeof(NodePtr))); + table = realloc(nodeTable, tableLength * (2 * sizeof(NodePtr))); if (!table) { - if (nd->string != string) - xfree(nd->string); - xfree(nd); + if (nd->string != string) { + /* nd->string has been strdup'ed */ + free((char *)nd->string); + } + free(nd); return BAD_RESOURCE; } tableLength <<= 1; nodeTable = table; } *np = nd; - nd->left = nd->right = (NodePtr) NULL; + nd->left = nd->right = NULL; nd->fingerPrint = fp; - nd->a = (++lastAtom); - *(nodeTable+lastAtom) = nd; + nd->a = ++lastAtom; + nodeTable[lastAtom] = nd; return nd->a; } else @@ -163,7 +164,7 @@ NameForAtom(Atom atom) { NodePtr node; if (atom > lastAtom) return 0; - if ((node = nodeTable[atom]) == (NodePtr)NULL) return 0; + if ((node = nodeTable[atom]) == NULL) return 0; return node->string; } @@ -180,20 +181,25 @@ FreeAtom(NodePtr patom) FreeAtom(patom->left); if(patom->right) FreeAtom(patom->right); - if (patom->a > XA_LAST_PREDEFINED) - xfree(patom->string); - xfree(patom); + if (patom->a > XA_LAST_PREDEFINED) { + /* + * All strings above XA_LAST_PREDEFINED are strdup'ed, so it's safe to + * cast here + */ + free((char *)patom->string); + } + free(patom); } void FreeAllAtoms(void) { - if(atomRoot == (NodePtr)NULL) + if (atomRoot == NULL) return; FreeAtom(atomRoot); - atomRoot = (NodePtr)NULL; - xfree(nodeTable); - nodeTable = (NodePtr *)NULL; + atomRoot = NULL; + free(nodeTable); + nodeTable = NULL; lastAtom = None; } @@ -202,11 +208,11 @@ InitAtoms(void) { FreeAllAtoms(); tableLength = InitialTableSize; - nodeTable = xalloc(InitialTableSize*sizeof(NodePtr)); + nodeTable = malloc(InitialTableSize * sizeof(NodePtr)); if (!nodeTable) AtomError(); - nodeTable[None] = (NodePtr)NULL; + nodeTable[None] = NULL; MakePredeclaredAtoms(); if (lastAtom != XA_LAST_PREDEFINED) - AtomError (); + AtomError(); } diff --git a/xserver/dix/colormap.c b/xserver/dix/colormap.c index bf9794125..2e9a80647 100644 --- a/xserver/dix/colormap.c +++ b/xserver/dix/colormap.c @@ -57,6 +57,7 @@ SOFTWARE. #include <strings.h> #include "misc.h" #include "dix.h" +#include "dixstruct.h" #include "colormapst.h" #include "os.h" #include "scrnintstr.h" @@ -65,8 +66,6 @@ SOFTWARE. #include "privates.h" #include "xace.h" -extern XID clientErrorValue; - static Pixel FindBestPixel( EntryPtr /*pentFirst*/, int /*size*/, @@ -265,7 +264,7 @@ CreateColormap (Colormap mid, ScreenPtr pScreen, VisualPtr pVisual, class = pVisual->class; if(!(class & DynamicClass) && (alloc != AllocNone) && (client != SERVER_ID)) - return (BadMatch); + return BadMatch; size = pVisual->ColormapEntries; sizebytes = (size * sizeof(Entry)) + @@ -274,9 +273,20 @@ CreateColormap (Colormap mid, ScreenPtr pScreen, VisualPtr pVisual, if ((class | DynamicClass) == DirectColor) sizebytes *= 3; sizebytes += sizeof(ColormapRec); - pmap = xalloc(sizebytes); - if (!pmap) - return (BadAlloc); + if (mid == pScreen->defColormap) { + pmap = malloc(sizebytes); + if (!pmap) + return BadAlloc; + if (!dixAllocatePrivates(&pmap->devPrivates, PRIVATE_COLORMAP)) { + free (pmap); + return BadAlloc; + } + } else { + pmap = _dixAllocateObjectWithPrivates(sizebytes, sizebytes, + offsetof(ColormapRec, devPrivates), PRIVATE_COLORMAP); + if (!pmap) + return BadAlloc; + } #if defined(_XSERVER64) pmap->pad0 = 0; pmap->pad1 = 0; @@ -299,8 +309,8 @@ CreateColormap (Colormap mid, ScreenPtr pScreen, VisualPtr pVisual, if ((class | DynamicClass) == DirectColor) size = NUMRED(pVisual); pmap->freeRed = size; - bzero ((char *) pmap->red, (int)sizebytes); - bzero((char *) pmap->numPixelsRed, MAXCLIENTS * sizeof(int)); + memset((char *) pmap->red, 0, (int)sizebytes); + memset((char *) pmap->numPixelsRed, 0, MAXCLIENTS * sizeof(int)); for (pptr = &pmap->clientPixelsRed[MAXCLIENTS]; --pptr >= pmap->clientPixelsRed; ) *pptr = (Pixel *)NULL; if (alloc == AllocAll) @@ -310,11 +320,11 @@ CreateColormap (Colormap mid, ScreenPtr pScreen, VisualPtr pVisual, for (pent = &pmap->red[size - 1]; pent >= pmap->red; pent--) pent->refcnt = AllocPrivate; pmap->freeRed = 0; - ppix = xalloc(size * sizeof(Pixel)); + ppix = malloc(size * sizeof(Pixel)); if (!ppix) { - xfree(pmap); - return (BadAlloc); + free(pmap); + return BadAlloc; } pmap->clientPixelsRed[client] = ppix; for(i = 0; i < size; i++) @@ -337,8 +347,8 @@ CreateColormap (Colormap mid, ScreenPtr pScreen, VisualPtr pVisual, pmap->numPixelsBlue = (int *)((char *)pmap->clientPixelsBlue + (MAXCLIENTS * sizeof(Pixel *))); - bzero ((char *) pmap->green, (int)sizebytes); - bzero ((char *) pmap->blue, (int)sizebytes); + memset((char *) pmap->green, 0, (int)sizebytes); + memset((char *) pmap->blue, 0, (int)sizebytes); memmove((char *) pmap->clientPixelsGreen, (char *) pmap->clientPixelsRed, @@ -346,8 +356,8 @@ CreateColormap (Colormap mid, ScreenPtr pScreen, VisualPtr pVisual, memmove((char *) pmap->clientPixelsBlue, (char *) pmap->clientPixelsRed, MAXCLIENTS * sizeof(Pixel *)); - bzero((char *) pmap->numPixelsGreen, MAXCLIENTS * sizeof(int)); - bzero((char *) pmap->numPixelsBlue, MAXCLIENTS * sizeof(int)); + memset((char *) pmap->numPixelsGreen, 0, MAXCLIENTS * sizeof(int)); + memset((char *) pmap->numPixelsBlue, 0, MAXCLIENTS * sizeof(int)); /* If every cell is allocated, mark its refcnt */ if (alloc == AllocAll) @@ -356,12 +366,12 @@ CreateColormap (Colormap mid, ScreenPtr pScreen, VisualPtr pVisual, for(pent = &pmap->green[size-1]; pent >= pmap->green; pent--) pent->refcnt = AllocPrivate; pmap->freeGreen = 0; - ppix = xalloc(size * sizeof(Pixel)); + ppix = malloc(size * sizeof(Pixel)); if (!ppix) { - xfree(pmap->clientPixelsRed[client]); - xfree(pmap); - return(BadAlloc); + free(pmap->clientPixelsRed[client]); + free(pmap); + return BadAlloc; } pmap->clientPixelsGreen[client] = ppix; for(i = 0; i < size; i++) @@ -372,13 +382,13 @@ CreateColormap (Colormap mid, ScreenPtr pScreen, VisualPtr pVisual, for(pent = &pmap->blue[size-1]; pent >= pmap->blue; pent--) pent->refcnt = AllocPrivate; pmap->freeBlue = 0; - ppix = xalloc(size * sizeof(Pixel)); + ppix = malloc(size * sizeof(Pixel)); if (!ppix) { - xfree(pmap->clientPixelsGreen[client]); - xfree(pmap->clientPixelsRed[client]); - xfree(pmap); - return(BadAlloc); + free(pmap->clientPixelsGreen[client]); + free(pmap->clientPixelsRed[client]); + free(pmap); + return BadAlloc; } pmap->clientPixelsBlue[client] = ppix; for(i = 0; i < size; i++) @@ -386,11 +396,10 @@ CreateColormap (Colormap mid, ScreenPtr pScreen, VisualPtr pVisual, pmap->numPixelsBlue[client] = size; } } - pmap->devPrivates = NULL; pmap->flags |= BeingCreated; if (!AddResource(mid, RT_COLORMAP, (pointer)pmap)) - return (BadAlloc); + return BadAlloc; /* * Security creation/labeling check @@ -412,7 +421,7 @@ CreateColormap (Colormap mid, ScreenPtr pScreen, VisualPtr pVisual, } pmap->flags &= ~BeingCreated; *ppcmap = pmap; - return (Success); + return Success; } /** @@ -439,7 +448,7 @@ FreeColormap (pointer value, XID mid) if(pmap->clientPixelsRed) { for(i = 0; i < MAXCLIENTS; i++) - xfree(pmap->clientPixelsRed[i]); + free(pmap->clientPixelsRed[i]); } if ((pmap->class == PseudoColor) || (pmap->class == GrayScale)) @@ -451,11 +460,11 @@ FreeColormap (pointer value, XID mid) if(pent->fShared) { if (--pent->co.shco.red->refcnt == 0) - xfree(pent->co.shco.red); + free(pent->co.shco.red); if (--pent->co.shco.green->refcnt == 0) - xfree(pent->co.shco.green); + free(pent->co.shco.green); if (--pent->co.shco.blue->refcnt == 0) - xfree(pent->co.shco.blue); + free(pent->co.shco.blue); } } } @@ -463,14 +472,17 @@ FreeColormap (pointer value, XID mid) { for(i = 0; i < MAXCLIENTS; i++) { - xfree(pmap->clientPixelsGreen[i]); - xfree(pmap->clientPixelsBlue[i]); + free(pmap->clientPixelsGreen[i]); + free(pmap->clientPixelsBlue[i]); } } - dixFreePrivates(pmap->devPrivates); - xfree(pmap); - return(Success); + if (pmap->flags & IsDefault) { + dixFreePrivates(pmap->devPrivates, PRIVATE_COLORMAP); + free(pmap); + } else + dixFreeObjectWithPrivates(pmap, PRIVATE_COLORMAP); + return Success; } /* Tell window that pmid has disappeared */ @@ -497,7 +509,7 @@ TellNoMap (WindowPtr pwin, Colormap *pmid) } } - return (WT_WALKCHILDREN); + return WT_WALKCHILDREN; } /* Tell window that pmid got uninstalled */ @@ -522,7 +534,7 @@ TellLostMap (WindowPtr pwin, pointer value) DeliverEvents(pwin, &xE, 1, (WindowPtr)NULL); } - return (WT_WALKCHILDREN); + return WT_WALKCHILDREN; } /* Tell window that pmid got installed */ @@ -547,7 +559,7 @@ TellGainedMap (WindowPtr pwin, pointer value) DeliverEvents(pwin, &xE, 1, (WindowPtr)NULL); } - return (WT_WALKCHILDREN); + return WT_WALKCHILDREN; } @@ -570,7 +582,7 @@ CopyColormapAndFree (Colormap mid, ColormapPtr pSrc, int client) /* If the create returns non-0, it failed */ result = CreateColormap (mid, pScreen, pVisual, &pmap, alloc, client); if(result != Success) - return(result); + return result; if(alloc == AllocAll) { memmove((char *)pmap->red, (char *)pSrc->red, size * sizeof(Entry)); @@ -582,7 +594,7 @@ CopyColormapAndFree (Colormap mid, ColormapPtr pSrc, int client) pSrc->flags &= ~AllAllocated; FreePixels(pSrc, client); UpdateColors(pmap); - return(Success); + return Success; } CopyFree(REDMAP, client, pSrc, pmap); @@ -594,7 +606,7 @@ CopyColormapAndFree (Colormap mid, ColormapPtr pSrc, int client) if (pmap->class & DynamicClass) UpdateColors(pmap); /* XXX should worry about removing any RT_CMAPENTRY resource */ - return(Success); + return Success; } /* Helper routine for freeing large numbers of cells from a map */ @@ -720,11 +732,11 @@ FreeCell (ColormapPtr pmap, Pixel i, int channel) if (pent->fShared) { if(--pent->co.shco.red->refcnt == 0) - xfree(pent->co.shco.red); + free(pent->co.shco.red); if(--pent->co.shco.green->refcnt == 0) - xfree(pent->co.shco.green); + free(pent->co.shco.green); if(--pent->co.shco.blue->refcnt == 0) - xfree(pent->co.shco.blue); + free(pent->co.shco.blue); pent->fShared = FALSE; } pent->refcnt = 0; @@ -743,7 +755,7 @@ UpdateColors (ColormapPtr pmap) pVisual = pmap->pVisual; size = pVisual->ColormapEntries; - defs = xalloc(size * sizeof(xColorItem)); + defs = malloc(size * sizeof(xColorItem)); if (!defs) return; n = 0; @@ -793,7 +805,7 @@ UpdateColors (ColormapPtr pmap) } if (n) (*pmap->pScreen->StoreColors)(pmap, n, defs); - xfree(defs); + free(defs); } /* Get a read-only color from a ColorMap (probably slow for large maps) @@ -840,10 +852,10 @@ AllocColor (ColormapPtr pmap, *pgreen = pmap->red[pixR].co.local.green; *pblue = pmap->red[pixR].co.local.blue; npix = pmap->numPixelsRed[client]; - ppix = (Pixel *) xrealloc(pmap->clientPixelsRed[client], + ppix = (Pixel *) realloc(pmap->clientPixelsRed[client], (npix + 1) * sizeof(Pixel)); if (!ppix) - return (BadAlloc); + return BadAlloc; ppix[npix] = pixR; pmap->clientPixelsRed[client] = ppix; pmap->numPixelsRed[client]++; @@ -863,24 +875,24 @@ AllocColor (ColormapPtr pmap, *pgreen = pmap->green[pixG].co.local.green; *pblue = pmap->blue[pixB].co.local.blue; npix = pmap->numPixelsRed[client]; - ppix = (Pixel *) xrealloc(pmap->clientPixelsRed[client], + ppix = (Pixel *) realloc(pmap->clientPixelsRed[client], (npix + 1) * sizeof(Pixel)); if (!ppix) - return (BadAlloc); + return BadAlloc; ppix[npix] = pixR; pmap->clientPixelsRed[client] = ppix; npix = pmap->numPixelsGreen[client]; - ppix = (Pixel *) xrealloc(pmap->clientPixelsGreen[client], + ppix = (Pixel *) realloc(pmap->clientPixelsGreen[client], (npix + 1) * sizeof(Pixel)); if (!ppix) - return (BadAlloc); + return BadAlloc; ppix[npix] = pixG; pmap->clientPixelsGreen[client] = ppix; npix = pmap->numPixelsBlue[client]; - ppix = (Pixel *) xrealloc(pmap->clientPixelsBlue[client], + ppix = (Pixel *) realloc(pmap->clientPixelsBlue[client], (npix + 1) * sizeof(Pixel)); if (!ppix) - return (BadAlloc); + return BadAlloc; ppix[npix] = pixB; pmap->clientPixelsBlue[client] = ppix; pmap->numPixelsRed[client]++; @@ -903,7 +915,7 @@ AllocColor (ColormapPtr pmap, } if (FindColor(pmap, pmap->red, entries, &rgb, pPix, PSEUDOMAP, client, AllComp) != Success) - return (BadAlloc); + return BadAlloc; break; case DirectColor: @@ -932,13 +944,13 @@ AllocColor (ColormapPtr pmap, pixR = (*pPix & pVisual->redMask) >> pVisual->offsetRed; if (FindColor(pmap, pmap->red, NUMRED(pVisual), &rgb, &pixR, REDMAP, client, RedComp) != Success) - return (BadAlloc); + return BadAlloc; pixG = (*pPix & pVisual->greenMask) >> pVisual->offsetGreen; if (FindColor(pmap, pmap->green, NUMGREEN(pVisual), &rgb, &pixG, GREENMAP, client, GreenComp) != Success) { (void)FreeCo(pmap, client, REDMAP, 1, &pixR, (Pixel)0); - return (BadAlloc); + return BadAlloc; } pixB = (*pPix & pVisual->blueMask) >> pVisual->offsetBlue; if (FindColor(pmap, pmap->blue, NUMBLUE(pVisual), &rgb, &pixB, BLUEMAP, @@ -946,7 +958,7 @@ AllocColor (ColormapPtr pmap, { (void)FreeCo(pmap, client, GREENMAP, 1, &pixG, (Pixel)0); (void)FreeCo(pmap, client, REDMAP, 1, &pixR, (Pixel)0); - return (BadAlloc); + return BadAlloc; } *pPix = pixR | pixG | pixB | ALPHAMASK(pVisual); @@ -962,18 +974,18 @@ AllocColor (ColormapPtr pmap, { colorResource *pcr; - pcr = xalloc(sizeof(colorResource)); + pcr = malloc(sizeof(colorResource)); if (!pcr) { (void)FreeColors(pmap, client, 1, pPix, (Pixel)0); - return (BadAlloc); + return BadAlloc; } pcr->mid = pmap->mid; pcr->client = client; if (!AddResource(FakeClientID(client), RT_CMAPENTRY, (pointer)pcr)) - return (BadAlloc); + return BadAlloc; } - return (Success); + return Success; } /* @@ -1160,7 +1172,7 @@ FindBestPixel(EntryPtr pentFirst, int size, xrgb *prgb, int channel) minval = sum; } } - return(final); + return final; } static void @@ -1268,7 +1280,7 @@ FindColor (ColormapPtr pmap, EntryPtr pentFirst, int size, xrgb *prgb, * a free entry, we're out of luck. Otherwise, we'll usurp a free * entry and fill it in */ if (!foundFree) - return (BadAlloc); + return BadAlloc; pent = pentFirst + Free; pent->fShared = FALSE; pent->refcnt = (client >= 0) ? 1 : AllocTemporary; @@ -1327,7 +1339,7 @@ FindColor (ColormapPtr pmap, EntryPtr pentFirst, int size, xrgb *prgb, gotit: if (pmap->flags & BeingCreated || client == -1) - return(Success); + return Success; /* Now remember the pixel, for freeing later */ switch (channel) { @@ -1348,7 +1360,7 @@ gotit: break; } npix = nump[client]; - ppix = (Pixel *) xrealloc (pixp[client], (npix + 1) * sizeof(Pixel)); + ppix = (Pixel *) realloc(pixp[client], (npix + 1) * sizeof(Pixel)); if (!ppix) { pent->refcnt--; @@ -1366,13 +1378,13 @@ gotit: pmap->freeBlue++; break; } - return(BadAlloc); + return BadAlloc; } ppix[npix] = pixel; pixp[client] = ppix; nump[client]++; - return(Success); + return Success; } /* Comparison functions -- passed to FindColor to determine if an @@ -1383,39 +1395,39 @@ AllComp (EntryPtr pent, xrgb *prgb) if((pent->co.local.red == prgb->red) && (pent->co.local.green == prgb->green) && (pent->co.local.blue == prgb->blue) ) - return (1); - return (0); + return 1; + return 0; } static int RedComp (EntryPtr pent, xrgb *prgb) { if (pent->co.local.red == prgb->red) - return (1); - return (0); + return 1; + return 0; } static int GreenComp (EntryPtr pent, xrgb *prgb) { if (pent->co.local.green == prgb->green) - return (1); - return (0); + return 1; + return 0; } static int BlueComp (EntryPtr pent, xrgb *prgb) { if (pent->co.local.blue == prgb->blue) - return (1); - return (0); + return 1; + return 0; } /* Read the color value of a cell */ int -QueryColors (ColormapPtr pmap, int count, Pixel *ppixIn, xrgb *prgbList) +QueryColors (ColormapPtr pmap, int count, Pixel *ppixIn, xrgb *prgbList, ClientPtr client) { Pixel *ppix, pixel; xrgb *prgb; @@ -1438,14 +1450,14 @@ QueryColors (ColormapPtr pmap, int count, Pixel *ppixIn, xrgb *prgbList) { pixel = *ppix; if (pixel & rgbbad) { - clientErrorValue = pixel; + client->errorValue = pixel; errVal = BadValue; continue; } i = (pixel & pVisual->redMask) >> pVisual->offsetRed; if (i >= numred) { - clientErrorValue = pixel; + client->errorValue = pixel; errVal = BadValue; continue; } @@ -1453,7 +1465,7 @@ QueryColors (ColormapPtr pmap, int count, Pixel *ppixIn, xrgb *prgbList) i = (pixel & pVisual->greenMask) >> pVisual->offsetGreen; if (i >= numgreen) { - clientErrorValue = pixel; + client->errorValue = pixel; errVal = BadValue; continue; } @@ -1461,7 +1473,7 @@ QueryColors (ColormapPtr pmap, int count, Pixel *ppixIn, xrgb *prgbList) i = (pixel & pVisual->blueMask) >> pVisual->offsetBlue; if (i >= numblue) { - clientErrorValue = pixel; + client->errorValue = pixel; errVal = BadValue; continue; } @@ -1475,7 +1487,7 @@ QueryColors (ColormapPtr pmap, int count, Pixel *ppixIn, xrgb *prgbList) pixel = *ppix; if (pixel >= pVisual->ColormapEntries) { - clientErrorValue = pixel; + client->errorValue = pixel; errVal = BadValue; } else @@ -1496,7 +1508,7 @@ QueryColors (ColormapPtr pmap, int count, Pixel *ppixIn, xrgb *prgbList) } } } - return (errVal); + return errVal; } static void @@ -1518,7 +1530,7 @@ FreePixels(ColormapPtr pmap, int client) } } - xfree(ppixStart); + free(ppixStart); pmap->clientPixelsRed[client] = (Pixel *) NULL; pmap->numPixelsRed[client] = 0; if ((class | DynamicClass) == DirectColor) @@ -1527,7 +1539,7 @@ FreePixels(ColormapPtr pmap, int client) if (class & DynamicClass) for (ppix = ppixStart, n = pmap->numPixelsGreen[client]; --n >= 0;) FreeCell(pmap, *ppix++, GREENMAP); - xfree(ppixStart); + free(ppixStart); pmap->clientPixelsGreen[client] = (Pixel *) NULL; pmap->numPixelsGreen[client] = 0; @@ -1535,7 +1547,7 @@ FreePixels(ColormapPtr pmap, int client) if (class & DynamicClass) for (ppix = ppixStart, n = pmap->numPixelsBlue[client]; --n >= 0; ) FreeCell(pmap, *ppix++, BLUEMAP); - xfree(ppixStart); + free(ppixStart); pmap->clientPixelsBlue[client] = (Pixel *) NULL; pmap->numPixelsBlue[client] = 0; } @@ -1558,7 +1570,7 @@ FreeClientPixels (pointer value, XID fakeid) DixRemoveAccess); if (rc == Success) FreePixels((ColormapPtr)pmap, pcr->client); - xfree(pcr); + free(pcr); return Success; } @@ -1574,15 +1586,15 @@ AllocColorCells (int client, ColormapPtr pmap, int colors, int planes, class = pmap->class; if (!(class & DynamicClass)) - return (BadAlloc); /* Shouldn't try on this type */ + return BadAlloc; /* Shouldn't try on this type */ oldcount = pmap->numPixelsRed[client]; if (pmap->class == DirectColor) oldcount += pmap->numPixelsGreen[client] + pmap->numPixelsBlue[client]; if (!oldcount && (CLIENT_ID(pmap->mid) != client)) { - pcr = xalloc(sizeof(colorResource)); + pcr = malloc(sizeof(colorResource)); if (!pcr) - return (BadAlloc); + return BadAlloc; } if (pmap->class == DirectColor) @@ -1627,10 +1639,9 @@ AllocColorCells (int client, ColormapPtr pmap, int colors, int planes, pcr->client = client; if (!AddResource(FakeClientID(client), RT_CMAPENTRY, (pointer)pcr)) ok = BadAlloc; - } else if (pcr) - xfree(pcr); + } else free(pcr); - return (ok); + return ok; } @@ -1649,15 +1660,15 @@ AllocColorPlanes (int client, ColormapPtr pmap, int colors, class = pmap->class; if (!(class & DynamicClass)) - return (BadAlloc); /* Shouldn't try on this type */ + return BadAlloc; /* Shouldn't try on this type */ oldcount = pmap->numPixelsRed[client]; if (class == DirectColor) oldcount += pmap->numPixelsGreen[client] + pmap->numPixelsBlue[client]; if (!oldcount && (CLIENT_ID(pmap->mid) != client)) { - pcr = xalloc(sizeof(colorResource)); + pcr = malloc(sizeof(colorResource)); if (!pcr) - return (BadAlloc); + return BadAlloc; } if (class == DirectColor) @@ -1718,10 +1729,9 @@ AllocColorPlanes (int client, ColormapPtr pmap, int colors, pcr->client = client; if (!AddResource(FakeClientID(client), RT_CMAPENTRY, (pointer)pcr)) ok = BadAlloc; - } else if (pcr) - xfree(pcr); + } else free(pcr); - return (ok); + return ok; } static int @@ -1747,15 +1757,15 @@ AllocDirect (int client, ColormapPtr pmap, int c, int r, int g, int b, Bool cont for(p = pixels; p < pixels + c; p++) *p = 0; - ppixRed = xalloc(npixR * sizeof(Pixel)); - ppixGreen = xalloc(npixG * sizeof(Pixel)); - ppixBlue = xalloc(npixB * sizeof(Pixel)); + ppixRed = malloc(npixR * sizeof(Pixel)); + ppixGreen = malloc(npixG * sizeof(Pixel)); + ppixBlue = malloc(npixB * sizeof(Pixel)); if (!ppixRed || !ppixGreen || !ppixBlue) { - if (ppixBlue) xfree(ppixBlue); - if (ppixGreen) xfree(ppixGreen); - if (ppixRed) xfree(ppixRed); - return(BadAlloc); + free(ppixBlue); + free(ppixGreen); + free(ppixRed); + return BadAlloc; } okR = AllocCP(pmap, pmap->red, c, r, contig, ppixRed, prmask); @@ -1764,17 +1774,17 @@ AllocDirect (int client, ColormapPtr pmap, int c, int r, int g, int b, Bool cont if (okR && okG && okB) { - rpix = (Pixel *) xrealloc(pmap->clientPixelsRed[client], + rpix = (Pixel *) realloc(pmap->clientPixelsRed[client], (pmap->numPixelsRed[client] + (c << r)) * sizeof(Pixel)); if (rpix) pmap->clientPixelsRed[client] = rpix; - gpix = (Pixel *) xrealloc(pmap->clientPixelsGreen[client], + gpix = (Pixel *) realloc(pmap->clientPixelsGreen[client], (pmap->numPixelsGreen[client] + (c << g)) * sizeof(Pixel)); if (gpix) pmap->clientPixelsGreen[client] = gpix; - bpix = (Pixel *) xrealloc(pmap->clientPixelsBlue[client], + bpix = (Pixel *) realloc(pmap->clientPixelsBlue[client], (pmap->numPixelsBlue[client] + (c << b)) * sizeof(Pixel)); if (bpix) @@ -1792,10 +1802,10 @@ AllocDirect (int client, ColormapPtr pmap, int c, int r, int g, int b, Bool cont if (okB) for(ppix = ppixBlue, npix = npixB; --npix >= 0; ppix++) pmap->blue[*ppix].refcnt = 0; - xfree(ppixBlue); - xfree(ppixGreen); - xfree(ppixRed); - return(BadAlloc); + free(ppixBlue); + free(ppixGreen); + free(ppixRed); + return BadAlloc; } *prmask <<= pmap->pVisual->offsetRed; @@ -1836,11 +1846,11 @@ AllocDirect (int client, ColormapPtr pmap, int c, int r, int g, int b, Bool cont for (pDst = pixels; pDst < pixels + c; pDst++) *pDst |= ALPHAMASK(pmap->pVisual); - xfree(ppixBlue); - xfree(ppixGreen); - xfree(ppixRed); + free(ppixBlue); + free(ppixGreen); + free(ppixRed); - return (Success); + return Success; } static int @@ -1853,9 +1863,9 @@ AllocPseudo (int client, ColormapPtr pmap, int c, int r, Bool contig, npix = c << r; if ((r >= 32) || (npix > pmap->freeRed) || (npix < c)) - return(BadAlloc); - if(!(ppixTemp = xalloc(npix * sizeof(Pixel)))) - return(BadAlloc); + return BadAlloc; + if(!(ppixTemp = malloc(npix * sizeof(Pixel)))) + return BadAlloc; ok = AllocCP(pmap, pmap->red, c, r, contig, ppixTemp, pmask); if (ok) @@ -1863,13 +1873,13 @@ AllocPseudo (int client, ColormapPtr pmap, int c, int r, Bool contig, /* all the allocated pixels are added to the client pixel list, * but only the unique ones are returned to the client */ - ppix = (Pixel *)xrealloc(pmap->clientPixelsRed[client], + ppix = (Pixel *)realloc(pmap->clientPixelsRed[client], (pmap->numPixelsRed[client] + npix) * sizeof(Pixel)); if (!ppix) { for (p = ppixTemp; p < ppixTemp + npix; p++) pmap->red[*p].refcnt = 0; - return (BadAlloc); + return BadAlloc; } pmap->clientPixelsRed[client] = ppix; ppix += pmap->numPixelsRed[client]; @@ -1884,8 +1894,8 @@ AllocPseudo (int client, ColormapPtr pmap, int c, int r, Bool contig, pmap->numPixelsRed[client] += npix; pmap->freeRed -= npix; } - xfree(ppixTemp); - return (ok ? Success : BadAlloc); + free(ppixTemp); + return ok ? Success : BadAlloc; } /* Allocates count << planes pixels from colormap pmap for client. If @@ -1931,11 +1941,11 @@ AllocCP (ColormapPtr pmap, EntryPtr pentFirst, int count, int planes, ent->fShared = FALSE; } *pMask = 0; - return (TRUE); + return TRUE; } else if (planes > dplanes) { - return (FALSE); + return FALSE; } /* General case count pixels * 2 ^ planes cells to be allocated */ @@ -1982,7 +1992,7 @@ AllocCP (ColormapPtr pmap, EntryPtr pentFirst, int count, int planes, } } *pMask = mask; - return (TRUE); + return TRUE; } } pixel = save + 1; @@ -1993,7 +2003,7 @@ AllocCP (ColormapPtr pmap, EntryPtr pentFirst, int count, int planes, dplanes = pmap->pVisual->nplanes; if (contig || planes == 1 || dplanes < 3) - return (FALSE); + return FALSE; /* this will be very slow for large maps, need a better algorithm */ @@ -2063,10 +2073,10 @@ AllocCP (ColormapPtr pmap, EntryPtr pentFirst, int count, int planes, } *pMask = mask; - return (TRUE); + return TRUE; } } - return (FALSE); + return FALSE; } /** @@ -2084,16 +2094,16 @@ AllocShared (ColormapPtr pmap, Pixel *ppix, int c, int r, int g, int b, npixClientNew = c << (r + g + b); npixShared = (c << r) + (c << g) + (c << b); - psharedList = xalloc(npixShared * sizeof(SHAREDCOLOR *)); + psharedList = malloc(npixShared * sizeof(SHAREDCOLOR *)); if (!psharedList) return FALSE; ppshared = psharedList; for (z = npixShared; --z >= 0; ) { - if (!(ppshared[z] = xalloc(sizeof(SHAREDCOLOR)))) + if (!(ppshared[z] = malloc(sizeof(SHAREDCOLOR)))) { for (z++ ; z < npixShared; z++) - xfree(ppshared[z]); + free(ppshared[z]); return FALSE; } } @@ -2198,7 +2208,7 @@ AllocShared (ColormapPtr pmap, Pixel *ppix, int c, int r, int g, int b, } } } - xfree(psharedList); + free(psharedList); return TRUE; } @@ -2214,7 +2224,7 @@ FreeColors (ColormapPtr pmap, int client, int count, Pixel *pixels, Pixel mask) class = pmap->class; if (pmap->flags & AllAllocated) - return(BadAccess); + return BadAccess; if ((class | DynamicClass) == DirectColor) { rmask = mask & RGBMASK(pmap->pVisual); @@ -2238,11 +2248,11 @@ FreeColors (ColormapPtr pmap, int client, int count, Pixel *pixels, Pixel mask) } if ((mask != rmask) && count) { - clientErrorValue = *pixels | mask; + clients[client]->errorValue = *pixels | mask; result = BadValue; } /* XXX should worry about removing any RT_CMAPENTRY resource */ - return (result); + return result; } /** @@ -2268,7 +2278,7 @@ FreeCo (ColormapPtr pmap, int client, int color, int npixIn, Pixel *ppixIn, Pixe int offset, numents; if (npixIn == 0) - return (errVal); + return errVal; bits = 0; zapped = 0; base = lowbit (mask); @@ -2320,7 +2330,7 @@ FreeCo (ColormapPtr pmap, int client, int color, int npixIn, Pixel *ppixIn, Pixe pixTest = ((*pptr | bits) & cmask) >> offset; if ((pixTest >= numents) || (*pptr & rgbbad)) { - clientErrorValue = *pptr | bits; + clients[client]->errorValue = *pptr | bits; errVal = BadValue; continue; } @@ -2366,7 +2376,7 @@ FreeCo (ColormapPtr pmap, int client, int color, int npixIn, Pixel *ppixIn, Pixe npix++; } } - pptr = (Pixel *)xrealloc(ppixClient, npixNew * sizeof(Pixel)); + pptr = (Pixel *)realloc(ppixClient, npixNew * sizeof(Pixel)); if (pptr) ppixClient = pptr; npixClient = npixNew; @@ -2374,7 +2384,7 @@ FreeCo (ColormapPtr pmap, int client, int color, int npixIn, Pixel *ppixIn, Pixe else { npixClient = 0; - xfree(ppixClient); + free(ppixClient); ppixClient = (Pixel *)NULL; } switch(color) @@ -2394,14 +2404,14 @@ FreeCo (ColormapPtr pmap, int client, int color, int npixIn, Pixel *ppixIn, Pixe break; } } - return (errVal); + return errVal; } /* Redefine color values */ int -StoreColors (ColormapPtr pmap, int count, xColorItem *defs) +StoreColors (ColormapPtr pmap, int count, xColorItem *defs, ClientPtr client) { Pixel pix; xColorItem *pdef; @@ -2416,7 +2426,7 @@ StoreColors (ColormapPtr pmap, int count, xColorItem *defs) class = pmap->class; if(!(class & DynamicClass) && !(pmap->flags & BeingCreated)) { - return(BadAccess); + return BadAccess; } pVisual = pmap->pVisual; @@ -2439,7 +2449,7 @@ StoreColors (ColormapPtr pmap, int count, xColorItem *defs) if (pdef->pixel & rgbbad) { errVal = BadValue; - clientErrorValue = pdef->pixel; + client->errorValue = pdef->pixel; continue; } pix = (pdef->pixel & pVisual->redMask) >> pVisual->offsetRed; @@ -2511,7 +2521,7 @@ StoreColors (ColormapPtr pmap, int count, xColorItem *defs) defs[idef] = defs[n]; idef++; } else - clientErrorValue = pdef->pixel; + client->errorValue = pdef->pixel; } } else @@ -2522,7 +2532,7 @@ StoreColors (ColormapPtr pmap, int count, xColorItem *defs) ok = TRUE; if (pdef->pixel >= pVisual->ColormapEntries) { - clientErrorValue = pdef->pixel; + client->errorValue = pdef->pixel; errVal = BadValue; ok = FALSE; } @@ -2664,7 +2674,7 @@ StoreColors (ColormapPtr pmap, int count, xColorItem *defs) * count, the count of proposed entries */ if (idef != 0) ( *pmap->pScreen->StoreColors) (pmap, idef, defs); - return (errVal); + return errVal; } int @@ -2673,9 +2683,9 @@ IsMapInstalled(Colormap map, WindowPtr pWin) Colormap *pmaps; int imap, nummaps, found; - pmaps = xalloc(pWin->drawable.pScreen->maxInstalledCmaps*sizeof(Colormap)); + pmaps = malloc(pWin->drawable.pScreen->maxInstalledCmaps*sizeof(Colormap)); if(!pmaps) - return(FALSE); + return FALSE; nummaps = (*pWin->drawable.pScreen->ListInstalledColormaps) (pWin->drawable.pScreen, pmaps); found = FALSE; @@ -2687,8 +2697,8 @@ IsMapInstalled(Colormap map, WindowPtr pWin) break; } } - xfree(pmaps); - return (found); + free(pmaps); + return found; } struct colormap_lookup_data { @@ -2727,7 +2737,7 @@ ResizeVisualArray(ScreenPtr pScreen, int new_visual_count, first_new_vid = depth->numVids; first_new_visual = pScreen->numVisuals; - vids = xrealloc(depth->vids, (depth->numVids + new_visual_count) * sizeof(XID)); + vids = realloc(depth->vids, (depth->numVids + new_visual_count) * sizeof(XID)); if (!vids) return FALSE; @@ -2735,7 +2745,7 @@ ResizeVisualArray(ScreenPtr pScreen, int new_visual_count, depth->vids = vids; numVisuals = pScreen->numVisuals + new_visual_count; - visuals = xrealloc(pScreen->visuals, numVisuals * sizeof(VisualRec)); + visuals = realloc(pScreen->visuals, numVisuals * sizeof(VisualRec)); if (!visuals) { return FALSE; } diff --git a/xserver/dix/cursor.c b/xserver/dix/cursor.c index 5d9c8b080..72a7609dc 100644 --- a/xserver/dix/cursor.c +++ b/xserver/dix/cursor.c @@ -72,6 +72,8 @@ typedef struct _GlyphShare { static GlyphSharePtr sharedGlyphs = (GlyphSharePtr)NULL; +DevPrivateKeyRec cursorScreenDevPriv[MAXSCREENS]; + #ifdef XFIXES static CARD32 cursorSerial; #endif @@ -81,13 +83,12 @@ FreeCursorBits(CursorBitsPtr bits) { if (--bits->refcnt > 0) return; - xfree(bits->source); - xfree(bits->mask); + free(bits->source); + free(bits->mask); #ifdef ARGB_CURSOR - xfree(bits->argb); + free(bits->argb); #endif - dixFreePrivates(bits->devPrivates); - bits->devPrivates = NULL; + dixFiniPrivates(bits, PRIVATE_CURSOR_BITS); if (bits->refcnt == 0) { GlyphSharePtr *prev, this; @@ -100,9 +101,9 @@ FreeCursorBits(CursorBitsPtr bits) { *prev = this->next; CloseFont(this->font, (Font)0); - xfree(this); + free(this); } - xfree(bits); + free(bits); } } @@ -121,17 +122,17 @@ FreeCursor(pointer value, XID cid) DeviceIntPtr pDev = NULL; /* unused anyway */ if ( --pCurs->refcnt != 0) - return(Success); + return Success; for (nscr = 0; nscr < screenInfo.numScreens; nscr++) { pscr = screenInfo.screens[nscr]; (void)( *pscr->UnrealizeCursor)(pDev, pscr, pCurs); } - dixFreePrivates(pCurs->devPrivates); FreeCursorBits(pCurs->bits); - xfree( pCurs); - return(Success); + dixFiniPrivates(pCurs, PRIVATE_CURSOR); + free( pCurs); + return Success; } @@ -217,6 +218,7 @@ RealizeCursorAllScreens(CursorPtr pCurs) return Success; } + /** * does nothing about the resource table, just creates the data structure. * does not copy the src and mask bits @@ -237,14 +239,16 @@ AllocARGBCursor(unsigned char *psrcbits, unsigned char *pmaskbits, int rc; *ppCurs = NULL; - pCurs = (CursorPtr)xcalloc(sizeof(CursorRec) + sizeof(CursorBits), 1); + pCurs = (CursorPtr)calloc(CURSOR_REC_SIZE + CURSOR_BITS_SIZE, 1); if (!pCurs) { - xfree(psrcbits); - xfree(pmaskbits); + free(psrcbits); + free(pmaskbits); return BadAlloc; } - bits = (CursorBitsPtr)((char *)pCurs + sizeof(CursorRec)); + bits = (CursorBitsPtr)((char *)pCurs + CURSOR_REC_SIZE); + dixInitPrivates(pCurs, pCurs + 1, PRIVATE_CURSOR); + dixInitPrivates(bits, bits + 1, PRIVATE_CURSOR_BITS) bits->source = psrcbits; bits->mask = pmaskbits; #ifdef ARGB_CURSOR @@ -255,7 +259,6 @@ AllocARGBCursor(unsigned char *psrcbits, unsigned char *pmaskbits, bits->xhot = cm->xhot; bits->yhot = cm->yhot; pCurs->refcnt = 1; - bits->devPrivates = NULL; bits->refcnt = -1; CheckForEmptyMask(bits); pCurs->bits = bits; @@ -273,7 +276,6 @@ AllocARGBCursor(unsigned char *psrcbits, unsigned char *pmaskbits, pCurs->backBlue = backBlue; pCurs->id = cid; - pCurs->devPrivates = NULL; /* security creation/labeling check */ rc = XaceHook(XACE_RESOURCE_ACCESS, client, cid, RT_CURSOR, @@ -289,9 +291,9 @@ AllocARGBCursor(unsigned char *psrcbits, unsigned char *pmaskbits, return Success; error: - dixFreePrivates(pCurs->devPrivates); FreeCursorBits(bits); - xfree(pCurs); + dixFiniPrivates(pCurs, PRIVATE_CURSOR); + free(pCurs); return rc; } @@ -316,14 +318,14 @@ AllocGlyphCursor(Font source, unsigned sourceChar, Font mask, unsigned maskChar, if (rc != Success) { client->errorValue = source; - return (rc == BadValue) ? BadFont : rc; + return rc; } rc = dixLookupResourceByType((pointer *)&maskfont, mask, RT_FONT, client, DixUseAccess); if (rc != Success && mask != None) { client->errorValue = mask; - return (rc == BadValue) ? BadFont : rc; + return rc; } if (sourcefont != maskfont) pShare = (GlyphSharePtr)NULL; @@ -339,9 +341,10 @@ AllocGlyphCursor(Font source, unsigned sourceChar, Font mask, unsigned maskChar, } if (pShare) { - pCurs = (CursorPtr)xcalloc(sizeof(CursorRec), 1); + pCurs = (CursorPtr)calloc(CURSOR_REC_SIZE, 1); if (!pCurs) return BadAlloc; + dixInitPrivates(pCurs, pCurs + 1, PRIVATE_CURSOR); bits = pShare->bits; bits->refcnt++; } @@ -358,7 +361,7 @@ AllocGlyphCursor(Font source, unsigned sourceChar, Font mask, unsigned maskChar, unsigned char *mskptr; n = BitmapBytePad(cm.width)*(long)cm.height; - mskptr = mskbits = xalloc(n); + mskptr = mskbits = malloc(n); if (!mskptr) return BadAlloc; while (--n >= 0) @@ -376,33 +379,35 @@ AllocGlyphCursor(Font source, unsigned sourceChar, Font mask, unsigned maskChar, } if ((rc = ServerBitsFromGlyph(sourcefont, sourceChar, &cm, &srcbits))) { - xfree(mskbits); + free(mskbits); return rc; } if (sourcefont != maskfont) { pCurs = - (CursorPtr)xcalloc(sizeof(CursorRec) + sizeof(CursorBits), 1); + (CursorPtr)calloc(CURSOR_REC_SIZE + CURSOR_BITS_SIZE, 1); if (pCurs) - bits = (CursorBitsPtr)((char *)pCurs + sizeof(CursorRec)); + bits = (CursorBitsPtr)((char *)pCurs + CURSOR_REC_SIZE); else bits = (CursorBitsPtr)NULL; } else { - pCurs = (CursorPtr)xcalloc(sizeof(CursorRec), 1); + pCurs = (CursorPtr)calloc(CURSOR_REC_SIZE, 1); if (pCurs) - bits = (CursorBitsPtr)xcalloc(sizeof(CursorBits), 1); + bits = (CursorBitsPtr)calloc(CURSOR_BITS_SIZE, 1); else bits = (CursorBitsPtr)NULL; } if (!bits) { - xfree(pCurs); - xfree(mskbits); - xfree(srcbits); + free(pCurs); + free(mskbits); + free(srcbits); return BadAlloc; } + dixInitPrivates(pCurs, pCurs + 1, PRIVATE_CURSOR); + dixInitPrivates(bits, bits + 1, PRIVATE_CURSOR_BITS); bits->source = srcbits; bits->mask = mskbits; #ifdef ARGB_CURSOR @@ -412,13 +417,12 @@ AllocGlyphCursor(Font source, unsigned sourceChar, Font mask, unsigned maskChar, bits->height = cm.height; bits->xhot = cm.xhot; bits->yhot = cm.yhot; - bits->devPrivates = NULL; if (sourcefont != maskfont) bits->refcnt = -1; else { bits->refcnt = 1; - pShare = xalloc(sizeof(GlyphShare)); + pShare = malloc(sizeof(GlyphShare)); if (!pShare) { FreeCursorBits(bits); @@ -451,7 +455,6 @@ AllocGlyphCursor(Font source, unsigned sourceChar, Font mask, unsigned maskChar, pCurs->backBlue = backBlue; pCurs->id = cid; - pCurs->devPrivates = NULL; /* security creation/labeling check */ rc = XaceHook(XACE_RESOURCE_ACCESS, client, cid, RT_CURSOR, @@ -467,9 +470,9 @@ AllocGlyphCursor(Font source, unsigned sourceChar, Font mask, unsigned maskChar, return Success; error: - dixFreePrivates(pCurs->devPrivates); FreeCursorBits(bits); - xfree(pCurs); + dixFiniPrivates(pCurs, PRIVATE_CURSOR); + free(pCurs); return rc; } diff --git a/xserver/dix/devices.c b/xserver/dix/devices.c index 4021cbe8e..2aab67a79 100644 --- a/xserver/dix/devices.c +++ b/xserver/dix/devices.c @@ -77,6 +77,8 @@ SOFTWARE. #include <X11/extensions/XI.h> #include <X11/extensions/XI2.h> #include <X11/extensions/XIproto.h> +#include <math.h> +#include <pixman.h> #include "exglobals.h" #include "exevents.h" #include "xiquerydevice.h" /* for SizeDeviceClasses */ @@ -89,14 +91,49 @@ SOFTWARE. * This file handles input device-related stuff. */ -static int CoreDevicePrivateKeyIndex; -DevPrivateKey CoreDevicePrivateKey = &CoreDevicePrivateKeyIndex; -/* Used to store classes currently not in use by an MD */ -static int UnusedClassesPrivateKeyIndex; -DevPrivateKey UnusedClassesPrivateKey = &UnusedClassesPrivateKeyIndex; +static void RecalculateMasterButtons(DeviceIntPtr slave); + +static void +DeviceSetTransform(DeviceIntPtr dev, float *transform) +{ + struct pixman_f_transform scale; + double sx, sy; + int x, y; + + /** + * calculate combined transformation matrix: + * + * M = InvScale * Transform * Scale + * + * So we can later transform points using M * p + * + * Where: + * Scale scales coordinates into 0..1 range + * Transform is the user supplied (affine) transform + * InvScale scales coordinates back up into their native range + */ + sx = dev->valuator->axes[0].max_value - dev->valuator->axes[0].min_value; + sy = dev->valuator->axes[1].max_value - dev->valuator->axes[1].min_value; + /* invscale */ + pixman_f_transform_init_scale(&scale, sx, sy); + scale.m[0][2] = dev->valuator->axes[0].min_value; + scale.m[1][2] = dev->valuator->axes[1].min_value; -static void RecalculateMasterButtons(DeviceIntPtr slave); + /* transform */ + for (y=0; y<3; y++) + for (x=0; x<3; x++) + dev->transform.m[y][x] = *transform++; + + pixman_f_transform_multiply(&dev->transform, &scale, &dev->transform); + + /* scale */ + pixman_f_transform_init_scale(&scale, 1.0 / sx, 1.0 / sy); + scale.m[0][2] = -dev->valuator->axes[0].min_value / sx; + scale.m[1][2] = -dev->valuator->axes[1].min_value / sy; + + pixman_f_transform_multiply(&dev->transform, &dev->transform, &scale); +} /** * DIX property handler. @@ -122,6 +159,21 @@ DeviceSetProperty(DeviceIntPtr dev, Atom property, XIPropertyValuePtr prop, else if (!(*((CARD8*)prop->data)) && dev->enabled) DisableDevice(dev, TRUE); } + } else if (property == XIGetKnownProperty(XI_PROP_TRANSFORM)) + { + float *f = (float*)prop->data; + int i; + + if (prop->format != 32 || prop->size != 9 || + prop->type != XIGetKnownProperty(XATOM_FLOAT)) + return BadValue; + + for (i=0; i<9; i++) + if (!isfinite(f[i])) + return BadValue; + + if (!checkonly) + DeviceSetTransform(dev, f); } return Success; @@ -148,7 +200,7 @@ PairDevices(ClientPtr client, DeviceIntPtr ptr, DeviceIntPtr kbd) if (kbd->spriteInfo->spriteOwner) { - xfree(kbd->spriteInfo->sprite); + free(kbd->spriteInfo->sprite); kbd->spriteInfo->sprite = NULL; kbd->spriteInfo->spriteOwner = FALSE; } @@ -190,6 +242,7 @@ AddInputDevice(ClientPtr client, DeviceProc deviceProc, Bool autoStart) int devid; char devind[MAXDEVICES]; BOOL enabled; + float transform[9]; /* Find next available id, 0 and 1 are reserved */ memset(devind, 0, sizeof(char)*MAXDEVICES); @@ -202,7 +255,9 @@ AddInputDevice(ClientPtr client, DeviceProc deviceProc, Bool autoStart) if (devid >= MAXDEVICES) return (DeviceIntPtr)NULL; - dev = xcalloc(sizeof(DeviceIntRec) + sizeof(SpriteInfoRec), 1); + dev = _dixAllocateObjectWithPrivates(sizeof(DeviceIntRec) + sizeof(SpriteInfoRec), + sizeof(DeviceIntRec) + sizeof(SpriteInfoRec), + offsetof(DeviceIntRec, devPrivates), PRIVATE_DEVICE); if (!dev) return (DeviceIntPtr)NULL; dev->id = devid; @@ -225,7 +280,7 @@ AddInputDevice(ClientPtr client, DeviceProc deviceProc, Bool autoStart) /* security creation/labeling check */ if (XaceHook(XACE_DEVICE_ACCESS, client, dev, DixCreateAccess)) { - xfree(dev); + free(dev); return NULL; } @@ -241,6 +296,17 @@ AddInputDevice(ClientPtr client, DeviceProc deviceProc, Bool autoStart) XA_INTEGER, 8, PropModeReplace, 1, &enabled, FALSE); XISetDevicePropertyDeletable(dev, XIGetKnownProperty(XI_PROP_ENABLED), FALSE); + + /* unity matrix */ + memset(transform, 0, sizeof(transform)); + transform[0] = transform[4] = transform[8] = 1.0f; + + XIChangeDeviceProperty(dev, XIGetKnownProperty(XI_PROP_TRANSFORM), + XIGetKnownProperty(XATOM_FLOAT), 32, + PropModeReplace, 9, transform, FALSE); + XISetDevicePropertyDeletable(dev, XIGetKnownProperty(XI_PROP_TRANSFORM), + FALSE); + XIRegisterPropertyHandler(dev, DeviceSetProperty, NULL, NULL); return dev; @@ -296,9 +362,9 @@ EnableDevice(DeviceIntPtr dev, BOOL sendevent) /* Sprites appear on first root window, so we can hardcode it */ if (dev->spriteInfo->spriteOwner) { - InitializeSprite(dev, WindowTable[0]); + InitializeSprite(dev, screenInfo.screens[0]->root); /* mode doesn't matter */ - EnterWindow(dev, WindowTable[0], NotifyAncestor); + EnterWindow(dev, screenInfo.screens[0]->root, NotifyAncestor); } else if ((other = NextFreePointerDevice()) == NULL) { @@ -668,37 +734,35 @@ FreeDeviceClass(int type, pointer *class) XkbFreeInfo((*k)->xkbInfo); (*k)->xkbInfo = NULL; } - xfree((*k)); + free((*k)); break; } case ButtonClass: { ButtonClassPtr *b = (ButtonClassPtr*)class; - if ((*b)->xkb_acts) - xfree((*b)->xkb_acts); - xfree((*b)); + free((*b)->xkb_acts); + free((*b)); break; } case ValuatorClass: { ValuatorClassPtr *v = (ValuatorClassPtr*)class; - if ((*v)->motion) - xfree((*v)->motion); - xfree((*v)); + free((*v)->motion); + free((*v)); break; } case FocusClass: { FocusClassPtr *f = (FocusClassPtr*)class; - xfree((*f)->trace); - xfree((*f)); + free((*f)->trace); + free((*f)); break; } case ProximityClass: { ProximityClassPtr *p = (ProximityClassPtr*)class; - xfree((*p)); + free((*p)); break; } } @@ -721,7 +785,7 @@ FreeFeedbackClass(int type, pointer *class) knext = k->next; if (k->xkb_sli) XkbFreeSrvLedInfo(k->xkb_sli); - xfree(k); + free(k); } break; } @@ -732,7 +796,7 @@ FreeFeedbackClass(int type, pointer *class) for (p = (*ptrfeed); p; p = pnext) { pnext = p->next; - xfree(p); + free(p); } break; } @@ -743,7 +807,7 @@ FreeFeedbackClass(int type, pointer *class) for (i = (*intfeed); i; i = inext) { inext = i->next; - xfree(i); + free(i); } break; } @@ -754,9 +818,9 @@ FreeFeedbackClass(int type, pointer *class) for (s = (*stringfeed); s; s = snext) { snext = s->next; - xfree(s->ctrl.symbols_supported); - xfree(s->ctrl.symbols_displayed); - xfree(s); + free(s->ctrl.symbols_supported); + free(s->ctrl.symbols_displayed); + free(s); } break; } @@ -767,7 +831,7 @@ FreeFeedbackClass(int type, pointer *class) for (b = (*bell); b; b = bnext) { bnext = b->next; - xfree(b); + free(b); } break; } @@ -780,7 +844,7 @@ FreeFeedbackClass(int type, pointer *class) lnext = l->next; if (l->xkb_sli) XkbFreeSrvLedInfo(l->xkb_sli); - xfree(l); + free(l); } break; } @@ -842,22 +906,23 @@ CloseDevice(DeviceIntPtr dev) while (dev->xkb_interest) XkbRemoveResourceClient((DevicePtr)dev,dev->xkb_interest->resource); - xfree(dev->name); + free(dev->name); classes = (ClassesPtr)&dev->key; FreeAllDeviceClasses(classes); if (IsMaster(dev)) { - classes = dixLookupPrivate(&dev->devPrivates, UnusedClassesPrivateKey); + classes = dev->unused_classes; FreeAllDeviceClasses(classes); + free(classes); } if (DevHasCursor(dev) && dev->spriteInfo->sprite) { if (dev->spriteInfo->sprite->current) FreeCursor(dev->spriteInfo->sprite->current, None); - xfree(dev->spriteInfo->sprite->spriteTrace); - xfree(dev->spriteInfo->sprite); + free(dev->spriteInfo->sprite->spriteTrace); + free(dev->spriteInfo->sprite); } /* a client may have the device set as client pointer */ @@ -870,9 +935,8 @@ CloseDevice(DeviceIntPtr dev) } } - xfree(dev->deviceGrab.sync.event); - dixFreePrivates(dev->devPrivates); - xfree(dev); + free(dev->deviceGrab.sync.event); + dixFreeObjectWithPrivates(dev, PRIVATE_DEVICE); } /** @@ -1113,7 +1177,7 @@ SetKeySymsMap(KeySymsPtr dst, KeySymsPtr src) else if (src->mapWidth > dst->mapWidth) { i = sizeof(KeySym) * src->mapWidth * (dst->maxKeyCode - dst->minKeyCode + 1); - tmp = xcalloc(sizeof(KeySym), i); + tmp = calloc(sizeof(KeySym), i); if (!tmp) return FALSE; @@ -1121,7 +1185,7 @@ SetKeySymsMap(KeySymsPtr dst, KeySymsPtr src) for (i = 0; i <= dst->maxKeyCode-dst->minKeyCode; i++) memmove(&tmp[i * src->mapWidth], &dst->map[i * dst->mapWidth], dst->mapWidth * sizeof(KeySym)); - xfree(dst->map); + free(dst->map); } dst->mapWidth = src->mapWidth; dst->map = tmp; @@ -1129,7 +1193,7 @@ SetKeySymsMap(KeySymsPtr dst, KeySymsPtr src) else if (!dst->map) { i = sizeof(KeySym) * src->mapWidth * (dst->maxKeyCode - dst->minKeyCode + 1); - tmp = xcalloc(sizeof(KeySym), i); + tmp = calloc(sizeof(KeySym), i); if (!tmp) return FALSE; @@ -1151,7 +1215,7 @@ InitButtonClassDeviceStruct(DeviceIntPtr dev, int numButtons, Atom* labels, ButtonClassPtr butc; int i; - butc = xcalloc(1, sizeof(ButtonClassRec)); + butc = calloc(1, sizeof(ButtonClassRec)); if (!butc) return FALSE; butc->numButtons = numButtons; @@ -1175,7 +1239,7 @@ InitValuatorClassDeviceStruct(DeviceIntPtr dev, int numAxes, Atom *labels, if (!dev) return FALSE; - if (numAxes >= MAX_VALUATORS) + if (numAxes > MAX_VALUATORS) { LogMessage(X_WARNING, "Device '%s' has %d axes, only using first %d.\n", @@ -1183,7 +1247,7 @@ InitValuatorClassDeviceStruct(DeviceIntPtr dev, int numAxes, Atom *labels, numAxes = MAX_VALUATORS; } - valc = (ValuatorClassPtr)xcalloc(1, sizeof(ValuatorClassRec) + + valc = (ValuatorClassPtr)calloc(1, sizeof(ValuatorClassRec) + numAxes * sizeof(AxisInfo) + numAxes * sizeof(double)); if (!valc) @@ -1266,7 +1330,7 @@ InitPointerAccelerationScheme(DeviceIntPtr dev, case PtrAccelPredictable: { DeviceVelocityPtr s; - s = xalloc(sizeof(DeviceVelocityRec)); + s = malloc(sizeof(DeviceVelocityRec)); if(!s) return FALSE; InitVelocityData(s); @@ -1298,7 +1362,7 @@ InitAbsoluteClassDeviceStruct(DeviceIntPtr dev) { AbsoluteClassPtr abs; - abs = xalloc(sizeof(AbsoluteClassRec)); + abs = malloc(sizeof(AbsoluteClassRec)); if (!abs) return FALSE; @@ -1331,7 +1395,7 @@ InitFocusClassDeviceStruct(DeviceIntPtr dev) { FocusClassPtr focc; - focc = xalloc(sizeof(FocusClassRec)); + focc = malloc(sizeof(FocusClassRec)); if (!focc) return FALSE; focc->win = PointerRootWin; @@ -1350,7 +1414,7 @@ InitPtrFeedbackClassDeviceStruct(DeviceIntPtr dev, PtrCtrlProcPtr controlProc) { PtrFeedbackPtr feedc; - feedc = xalloc(sizeof(PtrFeedbackClassRec)); + feedc = malloc(sizeof(PtrFeedbackClassRec)); if (!feedc) return FALSE; feedc->CtrlProc = controlProc; @@ -1388,22 +1452,20 @@ InitStringFeedbackClassDeviceStruct ( int i; StringFeedbackPtr feedc; - feedc = xalloc(sizeof(StringFeedbackClassRec)); + feedc = malloc(sizeof(StringFeedbackClassRec)); if (!feedc) return FALSE; feedc->CtrlProc = controlProc; feedc->ctrl.num_symbols_supported = num_symbols_supported; feedc->ctrl.num_symbols_displayed = 0; feedc->ctrl.max_symbols = max_symbols; - feedc->ctrl.symbols_supported = xalloc (sizeof (KeySym) * num_symbols_supported); - feedc->ctrl.symbols_displayed = xalloc (sizeof (KeySym) * max_symbols); + feedc->ctrl.symbols_supported = malloc(sizeof (KeySym) * num_symbols_supported); + feedc->ctrl.symbols_displayed = malloc(sizeof (KeySym) * max_symbols); if (!feedc->ctrl.symbols_supported || !feedc->ctrl.symbols_displayed) { - if (feedc->ctrl.symbols_supported) - xfree(feedc->ctrl.symbols_supported); - if (feedc->ctrl.symbols_displayed) - xfree(feedc->ctrl.symbols_displayed); - xfree(feedc); + free(feedc->ctrl.symbols_supported); + free(feedc->ctrl.symbols_displayed); + free(feedc); return FALSE; } for (i=0; i<num_symbols_supported; i++) @@ -1424,7 +1486,7 @@ InitBellFeedbackClassDeviceStruct (DeviceIntPtr dev, BellProcPtr bellProc, { BellFeedbackPtr feedc; - feedc = xalloc(sizeof(BellFeedbackClassRec)); + feedc = malloc(sizeof(BellFeedbackClassRec)); if (!feedc) return FALSE; feedc->CtrlProc = controlProc; @@ -1443,7 +1505,7 @@ InitLedFeedbackClassDeviceStruct (DeviceIntPtr dev, LedCtrlProcPtr controlProc) { LedFeedbackPtr feedc; - feedc = xalloc(sizeof(LedFeedbackClassRec)); + feedc = malloc(sizeof(LedFeedbackClassRec)); if (!feedc) return FALSE; feedc->CtrlProc = controlProc; @@ -1462,7 +1524,7 @@ InitIntegerFeedbackClassDeviceStruct (DeviceIntPtr dev, IntegerCtrlProcPtr contr { IntegerFeedbackPtr feedc; - feedc = xalloc(sizeof(IntegerFeedbackClassRec)); + feedc = malloc(sizeof(IntegerFeedbackClassRec)); if (!feedc) return FALSE; feedc->CtrlProc = controlProc; @@ -1538,7 +1600,7 @@ ProcSetModifierMapping(ClientPtr client) rep.success = rc; WriteReplyToClient(client, sizeof(xSetModifierMappingReply), &rep); - return client->noClientException; + return Success; } int @@ -1562,9 +1624,9 @@ ProcGetModifierMapping(ClientPtr client) WriteReplyToClient(client, sizeof(xGetModifierMappingReply), &rep); (void)WriteToClient(client, max_keys_per_mod * 8, (char *) modkeymap); - xfree(modkeymap); + free(modkeymap); - return client->noClientException; + return Success; } int @@ -1622,7 +1684,7 @@ ProcChangeKeyboardMapping(ClientPtr client) stuff->keyCodes, NULL, client); } - return client->noClientException; + return Success; } int @@ -1722,10 +1784,10 @@ ProcGetKeyboardMapping(ClientPtr client) syms->mapWidth * stuff->count * sizeof(KeySym), &syms->map[syms->mapWidth * (stuff->firstKeyCode - syms->minKeyCode)]); - xfree(syms->map); - xfree(syms); + free(syms->map); + free(syms); - return client->noClientException; + return Success; } int @@ -2049,17 +2111,14 @@ ProcChangePointerControl(ClientPtr client) REQUEST(xChangePointerControlReq); REQUEST_SIZE_MATCH(xChangePointerControlReq); - if (!mouse->ptrfeed->CtrlProc) - return BadDevice; - ctrl = mouse->ptrfeed->ctrl; if ((stuff->doAccel != xTrue) && (stuff->doAccel != xFalse)) { client->errorValue = stuff->doAccel; - return(BadValue); + return BadValue; } if ((stuff->doThresh != xTrue) && (stuff->doThresh != xFalse)) { client->errorValue = stuff->doThresh; - return(BadValue); + return BadValue; } if (stuff->doAccel) { if (stuff->accelNum == -1) { @@ -2099,7 +2158,7 @@ ProcChangePointerControl(ClientPtr client) for (dev = inputInfo.devices; dev; dev = dev->next) { if ((dev == mouse || (!IsMaster(dev) && dev->u.master == mouse)) && - dev->ptrfeed && dev->ptrfeed->CtrlProc) { + dev->ptrfeed) { rc = XaceHook(XACE_DEVICE_ACCESS, client, dev, DixManageAccess); if (rc != Success) return rc; @@ -2108,9 +2167,8 @@ ProcChangePointerControl(ClientPtr client) for (dev = inputInfo.devices; dev; dev = dev->next) { if ((dev == mouse || (!IsMaster(dev) && dev->u.master == mouse)) && - dev->ptrfeed && dev->ptrfeed->CtrlProc) { + dev->ptrfeed) { dev->ptrfeed->ctrl = ctrl; - (*dev->ptrfeed->CtrlProc)(dev, &mouse->ptrfeed->ctrl); } } @@ -2217,8 +2275,7 @@ ProcGetMotionEvents(ClientPtr client) WriteSwappedDataToClient(client, nEvents * sizeof(xTimecoord), (char *)coords); } - if (coords) - xfree(coords); + free(coords); return Success; } @@ -2279,7 +2336,7 @@ RecalculateMasterButtons(DeviceIntPtr slave) maxbuttons = max(maxbuttons, dev->button->numButtons); } - if (master->button->numButtons != maxbuttons) + if (master->button && master->button->numButtons != maxbuttons) { int i; DeviceChangedEvent event; @@ -2290,7 +2347,7 @@ RecalculateMasterButtons(DeviceIntPtr slave) event.header = ET_Internal; event.type = ET_DeviceChanged; - event.time = CurrentTime; + event.time = GetTimeInMillis(); event.deviceid = master->id; event.flags = DEVCHANGE_POINTER_EVENT | DEVCHANGE_DEVICE_CHANGE; event.buttons.num_buttons = maxbuttons; @@ -2351,7 +2408,7 @@ AttachDevice(ClientPtr client, DeviceIntPtr dev, DeviceIntPtr master) { screen = miPointerGetScreen(dev); screen->DeviceCursorCleanup(dev, screen); - xfree(dev->spriteInfo->sprite); + free(dev->spriteInfo->sprite); } oldmaster = dev->u.master; @@ -2370,7 +2427,7 @@ AttachDevice(ClientPtr client, DeviceIntPtr dev, DeviceIntPtr master) if (dev->spriteInfo->sprite) currentRoot = dev->spriteInfo->sprite->spriteTrace[0]; else /* new device auto-set to floating */ - currentRoot = WindowTable[0]; + currentRoot = screenInfo.screens[0]->root; /* we need to init a fake sprite */ screen = currentRoot->drawable.pScreen; @@ -2464,7 +2521,6 @@ AllocDevicePair (ClientPtr client, char* name, { DeviceIntPtr pointer; DeviceIntPtr keyboard; - ClassesPtr classes; size_t len; *ptr = *keybd = NULL; @@ -2472,9 +2528,8 @@ AllocDevicePair (ClientPtr client, char* name, pointer = AddInputDevice(client, ptr_proc, TRUE); if (!pointer) return BadAlloc; - len = strlen(name) + strlen(" pointer") + 1; - pointer->name = xcalloc(len, sizeof(char)); + pointer->name = calloc(len, sizeof(char)); snprintf(pointer->name, len, "%s pointer", name); pointer->public.processInputProc = ProcessOtherEvent; @@ -2497,7 +2552,7 @@ AllocDevicePair (ClientPtr client, char* name, } len = strlen(name) + strlen(" keyboard") + 1; - keyboard->name = xcalloc(len, sizeof(char)); + keyboard->name = calloc(len, sizeof(char)); snprintf(keyboard->name, len, "%s keyboard", name); keyboard->public.processInputProc = ProcessOtherEvent; @@ -2512,12 +2567,9 @@ AllocDevicePair (ClientPtr client, char* name, keyboard->last.slave = NULL; keyboard->type = (master) ? MASTER_KEYBOARD : SLAVE; - /* The ClassesRec stores the device classes currently not used. */ - classes = xcalloc(1, sizeof(ClassesRec)); - dixSetPrivate(&pointer->devPrivates, UnusedClassesPrivateKey, classes); - classes = xcalloc(1, sizeof(ClassesRec)); - dixSetPrivate(&keyboard->devPrivates, UnusedClassesPrivateKey, classes); + pointer->unused_classes = calloc(1, sizeof(ClassesRec)); + keyboard->unused_classes = calloc(1, sizeof(ClassesRec)); *ptr = pointer; *keybd = keyboard; diff --git a/xserver/dix/dispatch.c b/xserver/dix/dispatch.c index 982c808c7..0e5aced1a 100644 --- a/xserver/dix/dispatch.c +++ b/xserver/dix/dispatch.c @@ -176,13 +176,6 @@ CallbackListPtr ClientStateCallback; volatile char dispatchException = 0; volatile char isItTimeToYield; -/* Various of the DIX function interfaces were not designed to allow - * the client->errorValue to be set on BadValue and other errors. - * Rather than changing interfaces and breaking untold code we introduce - * a new global that dispatch can use. - */ -XID clientErrorValue; /* XXX this is a kludge */ - #define SAME_SCREENS(a, b) (\ (a.pScreen == b.pScreen)) @@ -359,7 +352,7 @@ Dispatch(void) nextFreeClientID = 1; nClients = 0; - clientReady = xalloc(sizeof(int) * MaxClients); + clientReady = malloc(sizeof(int) * MaxClients); if (!clientReady) return; @@ -444,16 +437,18 @@ Dispatch(void) client->sequence, client->index, result); #endif - if (result != Success) + if (client->noClientException != Success) { - if (client->noClientException != Success) - CloseDownClient(client); - else - SendErrorToClient(client, MAJOROP, - MinorOpcodeOfRequest(client), - client->errorValue, result); + CloseDownClient(client); break; - } + } + else if (result != Success) + { + SendErrorToClient(client, MAJOROP, + MinorOpcodeOfRequest(client), + client->errorValue, result); + break; + } } FlushAllOutput(); client = clients[clientReady[nready]]; @@ -466,7 +461,7 @@ Dispatch(void) ddxBeforeReset (); #endif KillAllClients(); - xfree(clientReady); + free(clientReady); dispatchException &= ~DE_RESET; SmartScheduleLatencyLimited = 0; } @@ -530,7 +525,7 @@ CreateConnectionBlock(void) pad_to_int32(setup.nbytesVendor) + (setup.numFormats * sizeof(xPixmapFormat)) + (setup.numRoots * sizeof(xWindowRoot)); - ConnectionInfo = xalloc(lenofblock); + ConnectionInfo = malloc(lenofblock); if (!ConnectionInfo) return FALSE; @@ -567,7 +562,7 @@ CreateConnectionBlock(void) VisualPtr pVisual; pScreen = screenInfo.screens[i]; - root.windowId = WindowTable[i]->drawable.id; + root.windowId = pScreen->root->drawable.id; root.defaultColormap = pScreen->defColormap; root.whitePixel = pScreen->whitePixel; root.blackPixel = pScreen->blackPixel; @@ -592,10 +587,10 @@ CreateConnectionBlock(void) { lenofblock += sizeof(xDepth) + (pDepth->numVids * sizeof(xVisualType)); - pBuf = (char *)xrealloc(ConnectionInfo, lenofblock); + pBuf = (char *)realloc(ConnectionInfo, lenofblock); if (!pBuf) { - xfree(ConnectionInfo); + free(ConnectionInfo); return FALSE; } ConnectionInfo = pBuf; @@ -636,7 +631,7 @@ CreateConnectionBlock(void) int ProcBadRequest(ClientPtr client) { - return (BadRequest); + return BadRequest; } int @@ -675,10 +670,7 @@ ProcCreateWindow(ClientPtr client) return BadAlloc; pWin->eventMask = mask; } - if (client->noClientException != Success) - return(client->noClientException); - else - return rc; + return rc; } int @@ -686,7 +678,7 @@ ProcChangeWindowAttributes(ClientPtr client) { WindowPtr pWin; REQUEST(xChangeWindowAttributesReq); - int result, len, rc; + int len, rc; Mask access_mode = 0; REQUEST_AT_LEAST_SIZE(xChangeWindowAttributesReq); @@ -698,14 +690,10 @@ ProcChangeWindowAttributes(ClientPtr client) len = client->req_len - bytes_to_int32(sizeof(xChangeWindowAttributesReq)); if (len != Ones(stuff->valueMask)) return BadLength; - result = ChangeWindowAttributes(pWin, + return ChangeWindowAttributes(pWin, stuff->valueMask, (XID *) &stuff[1], client); - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); } int @@ -723,7 +711,7 @@ ProcGetWindowAttributes(ClientPtr client) memset(&wa, 0, sizeof(xGetWindowAttributesReply)); GetWindowAttributes(pWin, client, &wa); WriteReplyToClient(client, sizeof(xGetWindowAttributesReply), &wa); - return(client->noClientException); + return Success; } int @@ -744,7 +732,7 @@ ProcDestroyWindow(ClientPtr client) return rc; FreeResource(stuff->id, RT_NONE); } - return(client->noClientException); + return Success; } int @@ -759,7 +747,7 @@ ProcDestroySubwindows(ClientPtr client) if (rc != Success) return rc; DestroySubwindows(pWin, client); - return(client->noClientException); + return Success; } int @@ -767,7 +755,7 @@ ProcChangeSaveSet(ClientPtr client) { WindowPtr pWin; REQUEST(xChangeSaveSetReq); - int result, rc; + int rc; REQUEST_SIZE_MATCH(xChangeSaveSetReq); rc = dixLookupWindow(&pWin, stuff->window, client, DixManageAccess); @@ -776,18 +764,9 @@ ProcChangeSaveSet(ClientPtr client) if (client->clientAsMask == (CLIENT_BITS(pWin->drawable.id))) return BadMatch; if ((stuff->mode == SetModeInsert) || (stuff->mode == SetModeDelete)) - { - result = AlterSaveSetForClient(client, pWin, stuff->mode, FALSE, TRUE); - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); - } - else - { - client->errorValue = stuff->mode; - return( BadValue ); - } + return AlterSaveSetForClient(client, pWin, stuff->mode, FALSE, TRUE); + client->errorValue = stuff->mode; + return BadValue; } int @@ -795,7 +774,7 @@ ProcReparentWindow(ClientPtr client) { WindowPtr pWin, pParent; REQUEST(xReparentWindowReq); - int result, rc; + int rc; REQUEST_SIZE_MATCH(xReparentWindowReq); rc = dixLookupWindow(&pWin, stuff->window, client, DixManageAccess); @@ -804,23 +783,16 @@ ProcReparentWindow(ClientPtr client) rc = dixLookupWindow(&pParent, stuff->parent, client, DixAddAccess); if (rc != Success) return rc; - if (SAME_SCREENS(pWin->drawable, pParent->drawable)) - { - if ((pWin->backgroundState == ParentRelative) && - (pParent->drawable.depth != pWin->drawable.depth)) - return BadMatch; - if ((pWin->drawable.class != InputOnly) && - (pParent->drawable.class == InputOnly)) - return BadMatch; - result = ReparentWindow(pWin, pParent, - (short)stuff->x, (short)stuff->y, client); - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); - } - else - return (BadMatch); + if (!SAME_SCREENS(pWin->drawable, pParent->drawable)) + return BadMatch; + if ((pWin->backgroundState == ParentRelative) && + (pParent->drawable.depth != pWin->drawable.depth)) + return BadMatch; + if ((pWin->drawable.class != InputOnly) && + (pParent->drawable.class == InputOnly)) + return BadMatch; + return ReparentWindow(pWin, pParent, + (short)stuff->x, (short)stuff->y, client); } int @@ -836,7 +808,7 @@ ProcMapWindow(ClientPtr client) return rc; MapWindow(pWin, client); /* update cache to say it is mapped */ - return(client->noClientException); + return Success; } int @@ -852,7 +824,7 @@ ProcMapSubwindows(ClientPtr client) return rc; MapSubwindows(pWin, client); /* update cache to say it is mapped */ - return(client->noClientException); + return Success; } int @@ -868,7 +840,7 @@ ProcUnmapWindow(ClientPtr client) return rc; UnmapWindow(pWin, FALSE); /* update cache to say it is mapped */ - return(client->noClientException); + return Success; } int @@ -883,7 +855,7 @@ ProcUnmapSubwindows(ClientPtr client) if (rc != Success) return rc; UnmapSubwindows(pWin); - return(client->noClientException); + return Success; } int @@ -891,7 +863,6 @@ ProcConfigureWindow(ClientPtr client) { WindowPtr pWin; REQUEST(xConfigureWindowReq); - int result; int len, rc; REQUEST_AT_LEAST_SIZE(xConfigureWindowReq); @@ -902,12 +873,7 @@ ProcConfigureWindow(ClientPtr client) len = client->req_len - bytes_to_int32(sizeof(xConfigureWindowReq)); if (Ones((Mask)stuff->mask) != len) return BadLength; - result = ConfigureWindow(pWin, (Mask)stuff->mask, (XID *) &stuff[1], - client); - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); + return ConfigureWindow(pWin, (Mask)stuff->mask, (XID *) &stuff[1], client); } int @@ -928,7 +894,7 @@ ProcCirculateWindow(ClientPtr client) if (rc != Success) return rc; CirculateWindow(pWin, (int)stuff->direction, client); - return(client->noClientException); + return Success; } static int @@ -946,7 +912,7 @@ GetGeometry(ClientPtr client, xGetGeometryReply *rep) rep->type = X_Reply; rep->length = 0; rep->sequenceNumber = client->sequence; - rep->root = WindowTable[pDraw->pScreen->myNum]->drawable.id; + rep->root = pDraw->pScreen->root->drawable.id; rep->depth = pDraw->depth; rep->width = pDraw->width; rep->height = pDraw->height; @@ -987,7 +953,7 @@ ProcGetGeometry(ClientPtr client) return status; WriteReplyToClient(client, sizeof(xGetGeometryReply), &rep); - return(client->noClientException); + return Success; } @@ -1006,7 +972,7 @@ ProcQueryTree(ClientPtr client) return rc; memset(&reply, 0, sizeof(xQueryTreeReply)); reply.type = X_Reply; - reply.root = WindowTable[pWin->drawable.pScreen->myNum]->drawable.id; + reply.root = pWin->drawable.pScreen->root->drawable.id; reply.sequenceNumber = client->sequence; if (pWin->parent) reply.parent = pWin->parent->drawable.id; @@ -1019,7 +985,7 @@ ProcQueryTree(ClientPtr client) { int curChild = 0; - childIDs = xalloc(numChildren * sizeof(Window)); + childIDs = malloc(numChildren * sizeof(Window)); if (!childIDs) return BadAlloc; for (pChild = pWin->lastChild; pChild != pHead; pChild = pChild->prevSib) @@ -1034,10 +1000,10 @@ ProcQueryTree(ClientPtr client) { client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write; WriteSwappedDataToClient(client, numChildren * sizeof(Window), childIDs); - xfree(childIDs); + free(childIDs); } - return(client->noClientException); + return Success; } int @@ -1051,7 +1017,7 @@ ProcInternAtom(ClientPtr client) if ((stuff->onlyIfExists != xTrue) && (stuff->onlyIfExists != xFalse)) { client->errorValue = stuff->onlyIfExists; - return(BadValue); + return BadValue; } tchar = (char *) &stuff[1]; atom = MakeAtom(tchar, stuff->nbytes, !stuff->onlyIfExists); @@ -1064,10 +1030,10 @@ ProcInternAtom(ClientPtr client) reply.sequenceNumber = client->sequence; reply.atom = atom; WriteReplyToClient(client, sizeof(xInternAtomReply), &reply); - return(client->noClientException); + return Success; } else - return (BadAlloc); + return BadAlloc; } int @@ -1089,12 +1055,12 @@ ProcGetAtomName(ClientPtr client) reply.nameLength = len; WriteReplyToClient(client, sizeof(xGetAtomNameReply), &reply); (void)WriteToClient(client, len, str); - return(client->noClientException); + return Success; } else { client->errorValue = stuff->id; - return (BadAtom); + return BadAtom; } } @@ -1109,7 +1075,7 @@ ProcGrabServer(ClientPtr client) client->sequence--; BITSET(grabWaiters, client->index); IgnoreClient(client); - return(client->noClientException); + return Success; } rc = OnlyListenToOneClient(client); if (rc != Success) @@ -1125,7 +1091,7 @@ ProcGrabServer(ClientPtr client) CallCallbacks(&ServerGrabCallback, (pointer)&grabinfo); } - return(client->noClientException); + return Success; } static void @@ -1160,7 +1126,7 @@ ProcUngrabServer(ClientPtr client) { REQUEST_SIZE_MATCH(xReq); UngrabServer(client); - return(client->noClientException); + return Success; } int @@ -1213,14 +1179,12 @@ ProcTranslateCoords(ClientPtr client) * borderSize */ && (!wBoundingShape(pWin) || - POINT_IN_REGION(pWin->drawable.pScreen, - &pWin->borderSize, x, y, &box)) + RegionContainsPoint(&pWin->borderSize, x, y, &box)) && (!wInputShape(pWin) || - POINT_IN_REGION(pWin->drawable.pScreen, - wInputShape(pWin), - x - pWin->drawable.x, - y - pWin->drawable.y, &box)) + RegionContainsPoint(wInputShape(pWin), + x - pWin->drawable.x, + y - pWin->drawable.y, &box)) ) { rep.child = pWin->drawable.id; @@ -1234,7 +1198,7 @@ ProcTranslateCoords(ClientPtr client) rep.dstY = y - pDst->drawable.y; } WriteReplyToClient(client, sizeof(xTranslateCoordsReply), &rep); - return(client->noClientException); + return Success; } int @@ -1250,7 +1214,7 @@ ProcOpenFont(ClientPtr client) stuff->nbytes, (char *)&stuff[1]); if (err == Success) { - return(client->noClientException); + return Success; } else return err; @@ -1269,12 +1233,12 @@ ProcCloseFont(ClientPtr client) if (rc == Success) { FreeResource(stuff->id, RT_NONE); - return(client->noClientException); + return Success; } else { client->errorValue = stuff->id; - return (rc == BadValue) ? BadFont : rc; + return rc; } } @@ -1283,22 +1247,13 @@ ProcQueryFont(ClientPtr client) { xQueryFontReply *reply; FontPtr pFont; - GC *pGC; int rc; REQUEST(xResourceReq); REQUEST_SIZE_MATCH(xResourceReq); - client->errorValue = stuff->id; /* EITHER font or gc */ - rc = dixLookupResourceByType((pointer *)&pFont, stuff->id, RT_FONT, client, - DixGetAttrAccess); - if (rc == BadValue) { - rc = dixLookupResourceByType((pointer *)&pGC, stuff->id, RT_GC, client, - DixGetAttrAccess); - if (rc == Success) - pFont = pGC->font; - } + rc = dixLookupFontable(&pFont, stuff->id, client, DixGetAttrAccess); if (rc != Success) - return (rc == BadValue) ? BadFont: rc; + return rc; { xCharInfo *pmax = FONTINKMAX(pFont); @@ -1317,10 +1272,10 @@ ProcQueryFont(ClientPtr client) rlength = sizeof(xQueryFontReply) + FONTINFONPROPS(FONTCHARSET(pFont)) * sizeof(xFontProp) + nprotoxcistructs * sizeof(xCharInfo); - reply = xcalloc(1, rlength); + reply = calloc(1, rlength); if(!reply) { - return(BadAlloc); + return BadAlloc; } reply->type = X_Reply; @@ -1329,8 +1284,8 @@ ProcQueryFont(ClientPtr client) QueryFont( pFont, reply, nprotoxcistructs); WriteReplyToClient(client, rlength, reply); - xfree(reply); - return(client->noClientException); + free(reply); + return Success; } } @@ -1339,35 +1294,26 @@ ProcQueryTextExtents(ClientPtr client) { xQueryTextExtentsReply reply; FontPtr pFont; - GC *pGC; ExtentInfoRec info; unsigned long length; int rc; REQUEST(xQueryTextExtentsReq); REQUEST_AT_LEAST_SIZE(xQueryTextExtentsReq); - client->errorValue = stuff->fid; /* EITHER font or gc */ - rc = dixLookupResourceByType((pointer *)&pFont, stuff->fid, RT_FONT, client, - DixGetAttrAccess); - if (rc == BadValue) { - rc = dixLookupResourceByType((pointer *)&pGC, stuff->fid, RT_GC, client, - DixGetAttrAccess); - if (rc == Success) - pFont = pGC->font; - } + rc = dixLookupFontable(&pFont, stuff->fid, client, DixGetAttrAccess); if (rc != Success) - return (rc == BadValue) ? BadFont: rc; + return rc; length = client->req_len - bytes_to_int32(sizeof(xQueryTextExtentsReq)); length = length << 1; if (stuff->oddLength) { if (length == 0) - return(BadLength); + return BadLength; length--; } if (!QueryTextExtents(pFont, length, (unsigned char *)&stuff[1], &info)) - return(BadAlloc); + return BadAlloc; reply.type = X_Reply; reply.length = 0; reply.sequenceNumber = client->sequence; @@ -1380,7 +1326,7 @@ ProcQueryTextExtents(ClientPtr client) reply.overallLeft = info.overallLeft; reply.overallRight = info.overallRight; WriteReplyToClient(client, sizeof(xQueryTextExtentsReply), &reply); - return(client->noClientException); + return Success; } int @@ -1481,10 +1427,10 @@ CreatePmap: return rc; } if (AddResource(stuff->pid, RT_PIXMAP, (pointer)pMap)) - return(client->noClientException); + return Success; (*pDraw->pScreen->DestroyPixmap)(pMap); } - return (BadAlloc); + return BadAlloc; } int @@ -1500,12 +1446,12 @@ ProcFreePixmap(ClientPtr client) if (rc == Success) { FreeResource(stuff->id, RT_NONE); - return(client->noClientException); + return Success; } else { client->errorValue = stuff->id; - return (rc == BadValue) ? BadPixmap : rc; + return rc; } } @@ -1534,8 +1480,8 @@ ProcCreateGC(ClientPtr client) if (error != Success) return error; if (!AddResource(stuff->gc, RT_GC, (pointer)pGC)) - return (BadAlloc); - return(client->noClientException); + return BadAlloc; + return Success; } int @@ -1555,14 +1501,7 @@ ProcChangeGC(ClientPtr client) if (len != Ones(stuff->mask)) return BadLength; - result = dixChangeGC(client, pGC, stuff->mask, (CARD32 *) &stuff[1], 0); - if (client->noClientException != Success) - return(client->noClientException); - else - { - client->errorValue = clientErrorValue; - return(result); - } + return ChangeGCXIDs(client, pGC, stuff->mask, (CARD32 *) &stuff[1]); } int @@ -1581,15 +1520,13 @@ ProcCopyGC(ClientPtr client) if (result != Success) return result; if ((dstGC->pScreen != pGC->pScreen) || (dstGC->depth != pGC->depth)) - return (BadMatch); - result = CopyGC(pGC, dstGC, stuff->mask); - if (client->noClientException != Success) - return(client->noClientException); - else + return BadMatch; + if (stuff->mask & ~GCAllBits) { - client->errorValue = clientErrorValue; - return(result); + client->errorValue = stuff->mask; + return BadValue; } + return CopyGC(pGC, dstGC, stuff->mask); } int @@ -1610,15 +1547,11 @@ ProcSetDashes(ClientPtr client) if (result != Success) return result; - result = SetDashes(pGC, stuff->dashOffset, stuff->nDashes, + /* If there's an error, either there's no sensible errorValue, + * or there was a dash segment of 0. */ + client->errorValue = 0; + return SetDashes(pGC, stuff->dashOffset, stuff->nDashes, (unsigned char *)&stuff[1]); - if (client->noClientException != Success) - return(client->noClientException); - else - { - client->errorValue = clientErrorValue; - return(result); - } } int @@ -1641,14 +1574,10 @@ ProcSetClipRectangles(ClientPtr client) nr = (client->req_len << 2) - sizeof(xSetClipRectanglesReq); if (nr & 4) - return(BadLength); + return BadLength; nr >>= 3; - result = SetClipRects(pGC, stuff->xOrigin, stuff->yOrigin, + return SetClipRects(pGC, stuff->xOrigin, stuff->yOrigin, nr, (xRectangle *)&stuff[1], (int)stuff->ordering); - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); } int @@ -1664,7 +1593,7 @@ ProcFreeGC(ClientPtr client) return rc; FreeResource(stuff->id, RT_NONE); - return(client->noClientException); + return Success; } int @@ -1681,17 +1610,17 @@ ProcClearToBackground(ClientPtr client) if (pWin->drawable.class == InputOnly) { client->errorValue = stuff->window; - return (BadMatch); + return BadMatch; } if ((stuff->exposures != xTrue) && (stuff->exposures != xFalse)) { client->errorValue = stuff->exposures; - return(BadValue); + return BadValue; } (*pWin->drawable.pScreen->ClearToBackground)(pWin, stuff->x, stuff->y, stuff->width, stuff->height, (Bool)stuff->exposures); - return(client->noClientException); + return Success; } int @@ -1716,7 +1645,7 @@ ProcCopyArea(ClientPtr client) if ((pDst->pScreen != pSrc->pScreen) || (pDst->depth != pSrc->depth)) { client->errorValue = stuff->dstDrawable; - return (BadMatch); + return BadMatch; } } else @@ -1730,10 +1659,10 @@ ProcCopyArea(ClientPtr client) (*pDst->pScreen->SendGraphicsExpose) (client, pRgn, stuff->dstDrawable, X_CopyArea, 0); if (pRgn) - REGION_DESTROY(pDst->pScreen, pRgn); + RegionDestroy(pRgn); } - return(client->noClientException); + return Success; } int @@ -1758,7 +1687,7 @@ ProcCopyPlane(ClientPtr client) if (pdstDraw->pScreen != psrcDraw->pScreen) { client->errorValue = stuff->dstDrawable; - return (BadMatch); + return BadMatch; } } else @@ -1769,7 +1698,7 @@ ProcCopyPlane(ClientPtr client) (stuff->bitPlane > (1L << (psrcDraw->depth - 1)))) { client->errorValue = stuff->bitPlane; - return(BadValue); + return BadValue; } pRgn = (*pGC->ops->CopyPlane)(psrcDraw, pdstDraw, pGC, stuff->srcX, stuff->srcY, @@ -1780,9 +1709,9 @@ ProcCopyPlane(ClientPtr client) (*pdstDraw->pScreen->SendGraphicsExpose) (client, pRgn, stuff->dstDrawable, X_CopyPlane, 0); if (pRgn) - REGION_DESTROY(pdstDraw->pScreen, pRgn); + RegionDestroy(pRgn); } - return(client->noClientException); + return Success; } int @@ -1805,7 +1734,7 @@ ProcPolyPoint(ClientPtr client) if (npoint) (*pGC->ops->PolyPoint)(pDraw, pGC, stuff->coordMode, npoint, (xPoint *) &stuff[1]); - return (client->noClientException); + return Success; } int @@ -1828,7 +1757,7 @@ ProcPolyLine(ClientPtr client) if (npoint > 1) (*pGC->ops->Polylines)(pDraw, pGC, stuff->coordMode, npoint, (DDXPointPtr) &stuff[1]); - return(client->noClientException); + return Success; } int @@ -1843,11 +1772,11 @@ ProcPolySegment(ClientPtr client) VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess); nsegs = (client->req_len << 2) - sizeof(xPolySegmentReq); if (nsegs & 4) - return(BadLength); + return BadLength; nsegs >>= 3; if (nsegs) (*pGC->ops->PolySegment)(pDraw, pGC, nsegs, (xSegment *) &stuff[1]); - return (client->noClientException); + return Success; } int @@ -1862,12 +1791,12 @@ ProcPolyRectangle (ClientPtr client) VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess); nrects = (client->req_len << 2) - sizeof(xPolyRectangleReq); if (nrects & 4) - return(BadLength); + return BadLength; nrects >>= 3; if (nrects) (*pGC->ops->PolyRectangle)(pDraw, pGC, nrects, (xRectangle *) &stuff[1]); - return(client->noClientException); + return Success; } int @@ -1882,11 +1811,11 @@ ProcPolyArc(ClientPtr client) VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess); narcs = (client->req_len << 2) - sizeof(xPolyArcReq); if (narcs % sizeof(xArc)) - return(BadLength); + return BadLength; narcs /= sizeof(xArc); if (narcs) (*pGC->ops->PolyArc)(pDraw, pGC, narcs, (xArc *) &stuff[1]); - return (client->noClientException); + return Success; } int @@ -1917,7 +1846,7 @@ ProcFillPoly(ClientPtr client) (*pGC->ops->FillPolygon) (pDraw, pGC, stuff->shape, stuff->coordMode, things, (DDXPointPtr) &stuff[1]); - return(client->noClientException); + return Success; } int @@ -1932,13 +1861,13 @@ ProcPolyFillRectangle(ClientPtr client) VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess); things = (client->req_len << 2) - sizeof(xPolyFillRectangleReq); if (things & 4) - return(BadLength); + return BadLength; things >>= 3; if (things) (*pGC->ops->PolyFillRect) (pDraw, pGC, things, (xRectangle *) &stuff[1]); - return (client->noClientException); + return Success; } int @@ -1953,11 +1882,11 @@ ProcPolyFillArc(ClientPtr client) VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess); narcs = (client->req_len << 2) - sizeof(xPolyFillArcReq); if (narcs % sizeof(xArc)) - return(BadLength); + return BadLength; narcs /= sizeof(xArc); if (narcs) (*pGC->ops->PolyFillArc) (pDraw, pGC, narcs, (xArc *) &stuff[1]); - return (client->noClientException); + return Success; } #ifdef MATCH_CLIENT_ENDIAN @@ -2068,7 +1997,7 @@ ProcPutImage(ClientPtr client) stuff->width, stuff->height, stuff->leftPad, stuff->format, tmpImage); - return (client->noClientException); + return Success; } static int @@ -2090,7 +2019,7 @@ DoGetImage(ClientPtr client, int format, Drawable drawable, if ((format != XYPixmap) && (format != ZPixmap)) { client->errorValue = format; - return(BadValue); + return BadValue; } rc = dixLookupDrawable(&pDraw, drawable, client, 0, DixReadAccess); if (rc != Success) @@ -2124,7 +2053,7 @@ DoGetImage(ClientPtr client, int format, Drawable drawable, } else { - pBoundingDraw = (DrawablePtr)WindowTable[pDraw->pScreen->myNum]; + pBoundingDraw = (DrawablePtr)pDraw->pScreen->root; } xgi.visual = wVisual (pWin); @@ -2172,9 +2101,9 @@ DoGetImage(ClientPtr client, int format, Drawable drawable, xgi.length = length; if (im_return) { - pBuf = xcalloc(1, sz_xGetImageReply + length); + pBuf = calloc(1, sz_xGetImageReply + length); if (!pBuf) - return (BadAlloc); + return BadAlloc; if (widthBytesLine == 0) linesPerBuf = 0; else @@ -2210,8 +2139,8 @@ DoGetImage(ClientPtr client, int format, Drawable drawable, length += widthBytesLine; } } - if(!(pBuf = xcalloc(1, length))) - return (BadAlloc); + if(!(pBuf = calloc(1, length))) + return BadAlloc; WriteReplyToClient(client, sizeof (xGetImageReply), &xgi); } @@ -2220,8 +2149,7 @@ DoGetImage(ClientPtr client, int format, Drawable drawable, pVisibleRegion = NotClippedByChildren((WindowPtr)pDraw); if (pVisibleRegion) { - REGION_TRANSLATE(pDraw->pScreen, pVisibleRegion, - -pDraw->x, -pDraw->y); + RegionTranslate(pVisibleRegion, -pDraw->x, -pDraw->y); } } @@ -2309,10 +2237,10 @@ DoGetImage(ClientPtr client, int format, Drawable drawable, } } if (pVisibleRegion) - REGION_DESTROY(pDraw->pScreen, pVisibleRegion); + RegionDestroy(pVisibleRegion); if (!im_return) - xfree(pBuf); - return (client->noClientException); + free(pBuf); + return Success; } int @@ -2351,7 +2279,7 @@ ProcPolyText(ClientPtr client) if (err == Success) { - return(client->noClientException); + return Success; } else return err; @@ -2381,7 +2309,7 @@ ProcImageText8(ClientPtr client) if (err == Success) { - return(client->noClientException); + return Success; } else return err; @@ -2411,7 +2339,7 @@ ProcImageText16(ClientPtr client) if (err == Success) { - return(client->noClientException); + return Success; } else return err; @@ -2434,7 +2362,7 @@ ProcCreateColormap(ClientPtr client) if ((stuff->alloc != AllocNone) && (stuff->alloc != AllocAll)) { client->errorValue = stuff->alloc; - return(BadValue); + return BadValue; } mid = stuff->mid; LEGAL_NEW_RESOURCE(mid, client); @@ -2449,15 +2377,11 @@ ProcCreateColormap(ClientPtr client) { if (pVisual->vid != stuff->visual) continue; - result = CreateColormap(mid, pScreen, pVisual, &pmap, + return CreateColormap(mid, pScreen, pVisual, &pmap, (int)stuff->alloc, client->index); - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); } client->errorValue = stuff->visual; - return(BadMatch); + return BadMatch; } int @@ -2475,12 +2399,12 @@ ProcFreeColormap(ClientPtr client) /* Freeing a default colormap is a no-op */ if (!(pmap->flags & IsDefault)) FreeResource(stuff->id, RT_NONE); - return (client->noClientException); + return Success; } else { client->errorValue = stuff->id; - return (rc == BadValue) ? BadColor : rc; + return rc; } } @@ -2499,18 +2423,9 @@ ProcCopyColormapAndFree(ClientPtr client) rc = dixLookupResourceByType((pointer *)&pSrcMap, stuff->srcCmap, RT_COLORMAP, client, DixReadAccess|DixRemoveAccess); if (rc == Success) - { - rc = CopyColormapAndFree(mid, pSrcMap, client->index); - if (client->noClientException != Success) - return(client->noClientException); - else - return rc; - } - else - { - client->errorValue = stuff->srcCmap; - return (rc == BadValue) ? BadColor : rc; - } + return CopyColormapAndFree(mid, pSrcMap, client->index); + client->errorValue = stuff->srcCmap; + return rc; } int @@ -2527,15 +2442,18 @@ ProcInstallColormap(ClientPtr client) goto out; rc = XaceHook(XACE_SCREEN_ACCESS, client, pcmp->pScreen, DixSetAttrAccess); - if (rc != Success) + if (rc != Success) { + if (rc == BadValue) + rc = BadColor; goto out; + } (*(pcmp->pScreen->InstallColormap)) (pcmp); + return Success; - rc = client->noClientException; out: client->errorValue = stuff->id; - return (rc == BadValue) ? BadColor : rc; + return rc; } int @@ -2552,16 +2470,19 @@ ProcUninstallColormap(ClientPtr client) goto out; rc = XaceHook(XACE_SCREEN_ACCESS, client, pcmp->pScreen, DixSetAttrAccess); - if (rc != Success) + if (rc != Success) { + if (rc == BadValue) + rc = BadColor; goto out; + } if(pcmp->mid != pcmp->pScreen->defColormap) (*(pcmp->pScreen->UninstallColormap)) (pcmp); + return Success; - rc = client->noClientException; out: client->errorValue = stuff->id; - return (rc == BadValue) ? BadColor : rc; + return rc; } int @@ -2575,18 +2496,18 @@ ProcListInstalledColormaps(ClientPtr client) rc = dixLookupWindow(&pWin, stuff->id, client, DixGetAttrAccess); if (rc != Success) - goto out; + return rc; rc = XaceHook(XACE_SCREEN_ACCESS, client, pWin->drawable.pScreen, DixGetAttrAccess); if (rc != Success) - goto out; + return rc; - preply = xalloc(sizeof(xListInstalledColormapsReply) + + preply = malloc(sizeof(xListInstalledColormapsReply) + pWin->drawable.pScreen->maxInstalledCmaps * sizeof(Colormap)); if(!preply) - return(BadAlloc); + return BadAlloc; preply->type = X_Reply; preply->sequenceNumber = client->sequence; @@ -2597,10 +2518,8 @@ ProcListInstalledColormaps(ClientPtr client) WriteReplyToClient(client, sizeof (xListInstalledColormapsReply), preply); client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write; WriteSwappedDataToClient(client, nummaps * sizeof(Colormap), &preply[1]); - xfree(preply); - rc = client->noClientException; -out: - return rc; + free(preply); + return Success; } int @@ -2625,23 +2544,18 @@ ProcAllocColor (ClientPtr client) acr.pixel = 0; if( (rc = AllocColor(pmap, &acr.red, &acr.green, &acr.blue, &acr.pixel, client->index)) ) - { - if (client->noClientException != Success) - return(client->noClientException); - else - return rc; - } + return rc; #ifdef PANORAMIX if (noPanoramiXExtension || !pmap->pScreen->myNum) #endif WriteReplyToClient(client, sizeof(xAllocColorReply), &acr); - return (client->noClientException); + return Success; } else { client->errorValue = stuff->cmap; - return (rc == BadValue) ? BadColor : rc; + return rc; } } @@ -2673,26 +2587,21 @@ ProcAllocNamedColor (ClientPtr client) if( (rc = AllocColor(pcmp, &ancr.screenRed, &ancr.screenGreen, &ancr.screenBlue, &ancr.pixel, client->index)) ) - { - if (client->noClientException != Success) - return(client->noClientException); - else - return rc; - } + return rc; #ifdef PANORAMIX if (noPanoramiXExtension || !pcmp->pScreen->myNum) #endif WriteReplyToClient(client, sizeof (xAllocNamedColorReply), &ancr); - return (client->noClientException); + return Success; } else - return(BadName); + return BadName; } else { client->errorValue = stuff->cmap; - return (rc == BadValue) ? BadColor : rc; + return rc; } } @@ -2717,28 +2626,25 @@ ProcAllocColorCells (ClientPtr client) if (!npixels) { client->errorValue = npixels; - return (BadValue); + return BadValue; } if (stuff->contiguous != xTrue && stuff->contiguous != xFalse) { client->errorValue = stuff->contiguous; - return (BadValue); + return BadValue; } nmasks = stuff->planes; length = ((long)npixels + (long)nmasks) * sizeof(Pixel); - ppixels = xalloc(length); + ppixels = malloc(length); if(!ppixels) - return(BadAlloc); + return BadAlloc; pmasks = ppixels + npixels; if( (rc = AllocColorCells(client->index, pcmp, npixels, nmasks, (Bool)stuff->contiguous, ppixels, pmasks)) ) { - xfree(ppixels); - if (client->noClientException != Success) - return(client->noClientException); - else - return rc; + free(ppixels); + return rc; } #ifdef PANORAMIX if (noPanoramiXExtension || !pcmp->pScreen->myNum) @@ -2753,13 +2659,13 @@ ProcAllocColorCells (ClientPtr client) client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write; WriteSwappedDataToClient(client, length, ppixels); } - xfree(ppixels); - return (client->noClientException); + free(ppixels); + return Success; } else { client->errorValue = stuff->cmap; - return (rc == BadValue) ? BadColor : rc; + return rc; } } @@ -2784,30 +2690,27 @@ ProcAllocColorPlanes(ClientPtr client) if (!npixels) { client->errorValue = npixels; - return (BadValue); + return BadValue; } if (stuff->contiguous != xTrue && stuff->contiguous != xFalse) { client->errorValue = stuff->contiguous; - return (BadValue); + return BadValue; } acpr.type = X_Reply; acpr.sequenceNumber = client->sequence; acpr.nPixels = npixels; length = (long)npixels * sizeof(Pixel); - ppixels = xalloc(length); + ppixels = malloc(length); if(!ppixels) - return(BadAlloc); + return BadAlloc; if( (rc = AllocColorPlanes(client->index, pcmp, npixels, (int)stuff->red, (int)stuff->green, (int)stuff->blue, (Bool)stuff->contiguous, ppixels, &acpr.redMask, &acpr.greenMask, &acpr.blueMask)) ) { - xfree(ppixels); - if (client->noClientException != Success) - return(client->noClientException); - else - return rc; + free(ppixels); + return rc; } acpr.length = bytes_to_int32(length); #ifdef PANORAMIX @@ -2818,13 +2721,13 @@ ProcAllocColorPlanes(ClientPtr client) client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write; WriteSwappedDataToClient(client, length, ppixels); } - xfree(ppixels); - return (client->noClientException); + free(ppixels); + return Success; } else { client->errorValue = stuff->cmap; - return (rc == BadValue) ? BadColor : rc; + return rc; } } @@ -2843,23 +2746,15 @@ ProcFreeColors(ClientPtr client) int count; if(pcmp->flags & AllAllocated) - return(BadAccess); + return BadAccess; count = bytes_to_int32((client->req_len << 2) - sizeof(xFreeColorsReq)); - rc = FreeColors(pcmp, client->index, count, + return FreeColors(pcmp, client->index, count, (Pixel *)&stuff[1], (Pixel)stuff->planeMask); - if (client->noClientException != Success) - return(client->noClientException); - else - { - client->errorValue = clientErrorValue; - return rc; - } - } else { client->errorValue = stuff->cmap; - return (rc == BadValue) ? BadColor : rc; + return rc; } } @@ -2879,21 +2774,14 @@ ProcStoreColors (ClientPtr client) count = (client->req_len << 2) - sizeof(xStoreColorsReq); if (count % sizeof(xColorItem)) - return(BadLength); + return BadLength; count /= sizeof(xColorItem); - rc = StoreColors(pcmp, count, (xColorItem *)&stuff[1]); - if (client->noClientException != Success) - return(client->noClientException); - else - { - client->errorValue = clientErrorValue; - return rc; - } + return StoreColors(pcmp, count, (xColorItem *)&stuff[1], client); } else { client->errorValue = stuff->cmap; - return (rc == BadValue) ? BadColor : rc; + return rc; } } @@ -2916,18 +2804,14 @@ ProcStoreNamedColor (ClientPtr client) { def.flags = stuff->flags; def.pixel = stuff->pixel; - rc = StoreColors(pcmp, 1, &def); - if (client->noClientException != Success) - return(client->noClientException); - else - return rc; + return StoreColors(pcmp, 1, &def, client); } - return (BadName); + return BadName; } else { client->errorValue = stuff->cmap; - return (rc == BadValue) ? BadColor : rc; + return rc; } } @@ -2948,19 +2832,13 @@ ProcQueryColors(ClientPtr client) xQueryColorsReply qcr; count = bytes_to_int32((client->req_len << 2) - sizeof(xQueryColorsReq)); - prgbs = xcalloc(1, count * sizeof(xrgb)); + prgbs = calloc(1, count * sizeof(xrgb)); if(!prgbs && count) - return(BadAlloc); - if( (rc = QueryColors(pcmp, count, (Pixel *)&stuff[1], prgbs)) ) + return BadAlloc; + if( (rc = QueryColors(pcmp, count, (Pixel *)&stuff[1], prgbs, client)) ) { - if (prgbs) xfree(prgbs); - if (client->noClientException != Success) - return(client->noClientException); - else - { - client->errorValue = clientErrorValue; - return rc; - } + free(prgbs); + return rc; } memset(&qcr, 0, sizeof(xQueryColorsReply)); qcr.type = X_Reply; @@ -2973,14 +2851,14 @@ ProcQueryColors(ClientPtr client) client->pSwapReplyFunc = (ReplySwapPtr) SQColorsExtend; WriteSwappedDataToClient(client, count * sizeof(xrgb), prgbs); } - if (prgbs) xfree(prgbs); - return(client->noClientException); + free(prgbs); + return Success; } else { client->errorValue = stuff->cmap; - return (rc == BadValue) ? BadColor : rc; + return rc; } } @@ -3012,14 +2890,14 @@ ProcLookupColor(ClientPtr client) &lcr.screenBlue, pcmp->pVisual); WriteReplyToClient(client, sizeof(xLookupColorReply), &lcr); - return(client->noClientException); + return Success; } - return (BadName); + return BadName; } else { client->errorValue = stuff->cmap; - return (rc == BadValue) ? BadColor : rc; + return rc; } } @@ -3045,7 +2923,7 @@ ProcCreateCursor (ClientPtr client) DixReadAccess); if (rc != Success) { client->errorValue = stuff->source; - return (rc == BadValue) ? BadPixmap : rc; + return rc; } rc = dixLookupResourceByType((pointer *)&msk, stuff->mask, RT_PIXMAP, client, @@ -3055,31 +2933,31 @@ ProcCreateCursor (ClientPtr client) if (stuff->mask != None) { client->errorValue = stuff->mask; - return (rc == BadValue) ? BadPixmap : rc; + return rc; } } else if ( src->drawable.width != msk->drawable.width || src->drawable.height != msk->drawable.height || src->drawable.depth != 1 || msk->drawable.depth != 1) - return (BadMatch); + return BadMatch; width = src->drawable.width; height = src->drawable.height; if ( stuff->x > width || stuff->y > height ) - return (BadMatch); + return BadMatch; n = BitmapBytePad(width)*height; - srcbits = xcalloc(1, n); + srcbits = calloc(1, n); if (!srcbits) - return (BadAlloc); - mskbits = xalloc(n); + return BadAlloc; + mskbits = malloc(n); if (!mskbits) { - xfree(srcbits); - return (BadAlloc); + free(srcbits); + return BadAlloc; } (* src->drawable.pScreen->GetImage)( (DrawablePtr)src, 0, 0, width, height, @@ -3093,7 +2971,7 @@ ProcCreateCursor (ClientPtr client) else { /* zeroing the (pad) bits helps some ddx cursor handling */ - bzero((char *)mskbits, n); + memset((char *)mskbits, 0, n); (* msk->drawable.pScreen->GetImage)( (DrawablePtr)msk, 0, 0, width, height, XYPixmap, 1, (pointer)mskbits); } @@ -3111,7 +2989,7 @@ ProcCreateCursor (ClientPtr client) if (!AddResource(stuff->cid, RT_CURSOR, (pointer)pCursor)) return BadAlloc; - return client->noClientException; + return Success; } int @@ -3133,7 +3011,7 @@ ProcCreateGlyphCursor (ClientPtr client) if (res != Success) return res; if (AddResource(stuff->cid, RT_CURSOR, (pointer)pCursor)) - return client->noClientException; + return Success; return BadAlloc; } @@ -3151,12 +3029,12 @@ ProcFreeCursor (ClientPtr client) if (rc == Success) { FreeResource(stuff->id, RT_NONE); - return (client->noClientException); + return Success; } else { client->errorValue = stuff->id; - return (rc == BadValue) ? BadCursor : rc; + return rc; } } @@ -3175,7 +3053,7 @@ ProcQueryBestSize (ClientPtr client) (stuff->class != StippleShape)) { client->errorValue = stuff->class; - return(BadValue); + return BadValue; } rc = dixLookupDrawable(&pDraw, stuff->drawable, client, M_ANY, @@ -3183,7 +3061,7 @@ ProcQueryBestSize (ClientPtr client) if (rc != Success) return rc; if (stuff->class != CursorShape && pDraw->type == UNDRAWABLE_WINDOW) - return (BadMatch); + return BadMatch; pScreen = pDraw->pScreen; rc = XaceHook(XACE_SCREEN_ACCESS, client, pScreen, DixGetAttrAccess); if (rc != Success) @@ -3197,7 +3075,7 @@ ProcQueryBestSize (ClientPtr client) reply.width = stuff->width; reply.height = stuff->height; WriteReplyToClient(client, sizeof(xQueryBestSizeReply), &reply); - return (client->noClientException); + return Success; } @@ -3261,7 +3139,7 @@ ProcSetScreenSaver (ClientPtr client) ScreenSaverInterval = defaultScreenSaverInterval; SetScreenSaverTimer(); - return (client->noClientException); + return Success; } int @@ -3286,31 +3164,24 @@ ProcGetScreenSaver(ClientPtr client) rep.preferBlanking = ScreenSaverBlanking; rep.allowExposures = ScreenSaverAllowExposures; WriteReplyToClient(client, sizeof(xGetScreenSaverReply), &rep); - return (client->noClientException); + return Success; } int ProcChangeHosts(ClientPtr client) { REQUEST(xChangeHostsReq); - int result; REQUEST_FIXED_SIZE(xChangeHostsReq, stuff->hostLength); if(stuff->mode == HostInsert) - result = AddHost(client, (int)stuff->hostFamily, + return AddHost(client, (int)stuff->hostFamily, stuff->hostLength, (pointer)&stuff[1]); - else if (stuff->mode == HostDelete) - result = RemoveHost(client, (int)stuff->hostFamily, + if (stuff->mode == HostDelete) + return RemoveHost(client, (int)stuff->hostFamily, stuff->hostLength, (pointer)&stuff[1]); - else - { - client->errorValue = stuff->mode; - return BadValue; - } - if (!result) - result = client->noClientException; - return (result); + client->errorValue = stuff->mode; + return BadValue; } int @@ -3330,7 +3201,7 @@ ProcListHosts(ClientPtr client) result = GetHosts(&pdata, &nHosts, &len, &reply.enabled); if (result != Success) - return(result); + return result; reply.type = X_Reply; reply.sequenceNumber = client->sequence; reply.nHosts = nHosts; @@ -3341,14 +3212,13 @@ ProcListHosts(ClientPtr client) client->pSwapReplyFunc = (ReplySwapPtr) SLHostsExtend; WriteSwappedDataToClient(client, len, pdata); } - xfree(pdata); - return (client->noClientException); + free(pdata); + return Success; } int ProcChangeAccessControl(ClientPtr client) { - int result; REQUEST(xSetAccessControlReq); REQUEST_SIZE_MATCH(xSetAccessControlReq); @@ -3357,10 +3227,7 @@ ProcChangeAccessControl(ClientPtr client) client->errorValue = stuff->mode; return BadValue; } - result = ChangeAccessControl(client, stuff->mode == EnableAccess); - if (!result) - result = client->noClientException; - return (result); + return ChangeAccessControl(client, stuff->mode == EnableAccess); } /********************* @@ -3396,7 +3263,7 @@ ProcKillClient(ClientPtr client) if (stuff->id == AllTemporary) { CloseDownRetainedResources(); - return (client->noClientException); + return Success; } rc = dixLookupClient(&killclient, stuff->id, client, DixDestroyAccess); @@ -3409,9 +3276,9 @@ ProcKillClient(ClientPtr client) * doesn't try to touch client */ isItTimeToYield = TRUE; - return (Success); + return Success; } - return (client->noClientException); + return Success; } else return rc; @@ -3423,8 +3290,7 @@ ProcSetFontPath(ClientPtr client) unsigned char *ptr; unsigned long nbytes, total; long nfonts; - int n, result; - int error; + int n; REQUEST(xSetFontPathReq); REQUEST_AT_LEAST_SIZE(xSetFontPathReq); @@ -3436,20 +3302,13 @@ ProcSetFontPath(ClientPtr client) while (--nfonts >= 0) { if ((total == 0) || (total < (n = (*ptr + 1)))) - return(BadLength); + return BadLength; total -= n; ptr += n; } if (total >= 4) - return(BadLength); - result = SetFontPath(client, stuff->nFonts, (unsigned char *)&stuff[1], - &error); - if (!result) - { - result = client->noClientException; - client->errorValue = error; - } - return (result); + return BadLength; + return SetFontPath(client, stuff->nFonts, (unsigned char *)&stuff[1]); } int @@ -3473,7 +3332,7 @@ ProcGetFontPath(ClientPtr client) WriteReplyToClient(client, sizeof(xGetFontPathReply), &reply); if (stringLens || numpaths) (void)WriteToClient(client, stringLens + numpaths, (char *)bufferStart); - return(client->noClientException); + return Success; } int @@ -3492,12 +3351,12 @@ ProcChangeCloseDownMode(ClientPtr client) (stuff->mode == RetainTemporary)) { client->closeDownMode = stuff->mode; - return (client->noClientException); + return Success; } else { client->errorValue = stuff->mode; - return (BadValue); + return BadValue; } } @@ -3517,7 +3376,7 @@ int ProcForceScreenSaver(ClientPtr client) rc = dixSaveScreens(client, SCREEN_SAVER_FORCER, (int)stuff->mode); if (rc != Success) return rc; - return client->noClientException; + return Success; } int ProcNoOperation(ClientPtr client) @@ -3525,7 +3384,7 @@ int ProcNoOperation(ClientPtr client) REQUEST_AT_LEAST_SIZE(xReq); /* noop -- don't do anything */ - return(client->noClientException); + return Success; } void @@ -3636,8 +3495,7 @@ CloseDownClient(ClientPtr client) nextFreeClientID = client->index; clients[client->index] = NullClient; SmartLastClient = NullClient; - dixFreePrivates(client->devPrivates); - xfree(client); + dixFreeObjectWithPrivates(client, PRIVATE_CLIENT); while (!clients[currentMaxClients-1]) currentMaxClients--; @@ -3658,7 +3516,6 @@ KillAllClients(void) void InitClient(ClientPtr client, int i, pointer ospriv) { - memset(client, 0, sizeof(*client)); client->index = i; client->clientAsMask = ((Mask)i) << CLIENTOFFSET; client->closeDownMode = i ? DestroyAll : RetainPermanent; @@ -3686,13 +3543,13 @@ ClientPtr NextAvailableClient(pointer ospriv) i = nextFreeClientID; if (i == MAXCLIENTS) return (ClientPtr)NULL; - clients[i] = client = xalloc(sizeof(ClientRec)); + clients[i] = client = dixAllocateObjectWithPrivates(ClientRec, PRIVATE_CLIENT); if (!client) return (ClientPtr)NULL; InitClient(client, i, ospriv); if (!InitClientResources(client)) { - xfree(client); + dixFreeObjectWithPrivates(client, PRIVATE_CLIENT); return (ClientPtr)NULL; } data.reqType = 1; @@ -3700,7 +3557,7 @@ ClientPtr NextAvailableClient(pointer ospriv) if (!InsertFakeRequest(client, (char *)&data, sz_xReq)) { FreeClientResources(client); - xfree(client); + dixFreeObjectWithPrivates(client, PRIVATE_CLIENT); return (ClientPtr)NULL; } if (i == currentMaxClients) @@ -3716,7 +3573,7 @@ ClientPtr NextAvailableClient(pointer ospriv) clientinfo.setup = (xConnSetup *) NULL; CallCallbacks((&ClientStateCallback), (pointer)&clientinfo); } - return(client); + return client; } int @@ -3728,7 +3585,7 @@ ProcInitialConnection(ClientPtr client) prefix = (xConnClientPrefix *)((char *)stuff + sz_xReq); if ((prefix->byteOrder != 'l') && (prefix->byteOrder != 'B')) - return (client->noClientException = -1); + return client->noClientException = -1; if (((*(char *) &whichbyte) && (prefix->byteOrder == 'B')) || (!(*(char *) &whichbyte) && (prefix->byteOrder == 'l'))) { @@ -3743,7 +3600,7 @@ ProcInitialConnection(ClientPtr client) swaps(&stuff->length, whichbyte); } ResetCurrentRequest(client); - return (client->noClientException); + return Success; } static int @@ -3769,7 +3626,7 @@ SendConnSetup(ClientPtr client, char *reason) else (void)WriteToClient(client, sz_xConnSetupPrefix, (char *) &csp); (void)WriteToClient(client, (int)csp.lengthReason, reason); - return (client->noClientException = -1); + return client->noClientException = -1; } numScreens = screenInfo.numScreens; @@ -3804,9 +3661,9 @@ SendConnSetup(ClientPtr client, char *reason) { unsigned int j; xDepth *pDepth; + WindowPtr pRoot = screenInfo.screens[i]->root; - root->currentInputMask = WindowTable[i]->eventMask | - wOtherEventMasks (WindowTable[i]); + root->currentInputMask = pRoot->eventMask | wOtherEventMasks(pRoot); pDepth = (xDepth *)(root + 1); for (j = 0; j < root->nDepths; j++) { @@ -3840,7 +3697,7 @@ SendConnSetup(ClientPtr client, char *reason) clientinfo.setup = (xConnSetup *)lConnectionInfo; CallCallbacks((&ClientStateCallback), (pointer)&clientinfo); } - return (client->noClientException); + return Success; } int @@ -3874,7 +3731,7 @@ ProcEstablishConnection(ClientPtr client) client->clientState = ClientStateCheckedSecurity; else if (client->clientState != ClientStateAuthenticating) return(SendConnSetup(client, reason)); - return(client->noClientException); + return Success; } void @@ -3885,7 +3742,6 @@ SendErrorToClient(ClientPtr client, unsigned majorCode, unsigned minorCode, memset(&rep, 0, sizeof(xError)); rep.type = X_Error; - rep.sequenceNumber = client->sequence; rep.errorCode = errorCode; rep.majorCode = majorCode; rep.minorCode = minorCode; @@ -4003,13 +3859,16 @@ AddScreen( if (i == MAXSCREENS) return -1; - pScreen = (ScreenPtr) xcalloc(1, sizeof(ScreenRec)); + pScreen = (ScreenPtr) calloc(1, sizeof(ScreenRec)); if (!pScreen) return -1; - pScreen->devPrivates = NULL; + if (!dixAllocatePrivates(&pScreen->devPrivates, PRIVATE_SCREEN)) { + free (pScreen); + return -1; + } pScreen->myNum = i; - pScreen->totalPixmapSize = BitmapBytePad(sizeof(PixmapRec)*8); + pScreen->totalPixmapSize = 0; /* computed in CreateScratchPixmapForScreen */ pScreen->ClipNotify = 0; /* for R4 ddx compatibility */ pScreen->CreateScreenResources = 0; @@ -4055,16 +3914,17 @@ AddScreen( any of the strings pointed to by argv. They may be passed to multiple screens. */ - pScreen->rgf = ~0L; /* there are no scratch GCs yet*/ - WindowTable[i] = NullWindow; screenInfo.screens[i] = pScreen; screenInfo.numScreens++; if (!(*pfnInit)(i, pScreen, argc, argv)) { - dixFreePrivates(pScreen->devPrivates); - xfree(pScreen); + dixFreePrivates(pScreen->devPrivates, PRIVATE_SCREEN); + free(pScreen); screenInfo.numScreens--; return -1; } + + dixRegisterPrivateKey(&cursorScreenDevPriv[i], PRIVATE_CURSOR, 0); + return i; } diff --git a/xserver/dix/dixfonts.c b/xserver/dix/dixfonts.c index 6dc819313..e22eabe3a 100644 --- a/xserver/dix/dixfonts.c +++ b/xserver/dix/dixfonts.c @@ -166,7 +166,7 @@ QueueFontWakeup(FontPathElementPtr fpe) } if (num_slept_fpes == size_slept_fpes) { new = (FontPathElementPtr *) - xrealloc(slept_fpes, + realloc(slept_fpes, sizeof(FontPathElementPtr) * (size_slept_fpes + 4)); if (!new) return; @@ -222,8 +222,8 @@ FreeFPE (FontPathElementPtr fpe) fpe->refcount--; if (fpe->refcount == 0) { (*fpe_functions[fpe->type].free_fpe) (fpe); - xfree(fpe->name); - xfree(fpe); + free(fpe->name); + free(fpe); } } @@ -297,7 +297,7 @@ doOpenFont(ClientPtr client, OFclosurePtr c) if (err == FontNameAlias && alias) { newlen = strlen(alias); - newname = (char *) xrealloc(c->fontname, newlen); + newname = (char *) realloc(c->fontname, newlen); if (!newname) { err = AllocError; break; @@ -321,10 +321,10 @@ doOpenFont(ClientPtr client, OFclosurePtr c) continue; } if (err == Suspended) { - if (!c->slept) { - c->slept = TRUE; - ClientSleep(client, (ClientSleepProcPtr)doOpenFont, (pointer) c); - } + if (!ClientIsAsleep(client)) + ClientSleep(client, (ClientSleepProcPtr)doOpenFont, c); + else + goto xinerama_sleep; return TRUE; } break; @@ -373,14 +373,14 @@ bail: SendErrorToClient(c->client, X_OpenFont, 0, c->fontid, FontToXError(err)); } - if (c->slept) - ClientWakeup(c->client); + ClientWakeup(c->client); +xinerama_sleep: for (i = 0; i < c->num_fpes; i++) { FreeFPE(c->fpe_list[i]); } - xfree(c->fpe_list); - xfree(c->fontname); - xfree(c); + free(c->fpe_list); + free(c->fontname); + free(c); return TRUE; } @@ -393,11 +393,11 @@ OpenFont(ClientPtr client, XID fid, Mask flags, unsigned lenfname, char *pfontna #ifdef FONTDEBUG char *f; - f = xalloc(lenfname + 1); + f = malloc(lenfname + 1); memmove(f, pfontname, lenfname); f[lenfname] = '\0'; ErrorF("[dix] OpenFont: fontname is \"%s\"\n", f); - xfree(f); + free(f); #endif if (!lenfname || lenfname > XLFDMAXFONTNAMELEN) return BadName; @@ -430,24 +430,24 @@ OpenFont(ClientPtr client, XID fid, Mask flags, unsigned lenfname, char *pfontna return Success; } } - c = xalloc(sizeof(OFclosureRec)); + c = malloc(sizeof(OFclosureRec)); if (!c) return BadAlloc; - c->fontname = xalloc(lenfname); + c->fontname = malloc(lenfname); c->origFontName = pfontname; c->origFontNameLen = lenfname; if (!c->fontname) { - xfree(c); + free(c); return BadAlloc; } /* * copy the current FPE list, so that if it gets changed by another client * while we're blocking, the request still appears atomic */ - c->fpe_list = xalloc(sizeof(FontPathElementPtr) * num_fpes); + c->fpe_list = malloc(sizeof(FontPathElementPtr) * num_fpes); if (!c->fpe_list) { - xfree(c->fontname); - xfree(c); + free(c->fontname); + free(c); return BadAlloc; } memmove(c->fontname, pfontname, lenfname); @@ -460,7 +460,6 @@ OpenFont(ClientPtr client, XID fid, Mask flags, unsigned lenfname, char *pfontna c->current_fpe = 0; c->num_fpes = num_fpes; c->fnamelen = lenfname; - c->slept = FALSE; c->flags = flags; c->non_cachable_font = cached; @@ -482,7 +481,7 @@ CloseFont(pointer value, XID fid) FontPtr pfont = (FontPtr)value; if (pfont == NullFont) - return (Success); + return Success; if (--pfont->refcnt == 0) { if (patternCache) RemoveCachedFontPattern (patternCache, pfont); @@ -504,7 +503,7 @@ CloseFont(pointer value, XID fid) (*fpe_functions[fpe->type].close_font) (fpe, pfont); FreeFPE(fpe); } - return (Success); + return Success; } @@ -622,12 +621,12 @@ doListFontsAndAliases(ClientPtr client, LFclosurePtr c) c->names); if (err == Suspended) { - if (!c->slept) { - c->slept = TRUE; + if (!ClientIsAsleep(client)) ClientSleep(client, - (ClientSleepProcPtr)doListFontsAndAliases, - (pointer) c); - } + (ClientSleepProcPtr)doListFontsAndAliases, + c); + else + goto xinerama_sleep; return TRUE; } @@ -650,12 +649,12 @@ doListFontsAndAliases(ClientPtr client, LFclosurePtr c) c->current.patlen, c->current.max_names - c->names->nnames, &c->current.private); if (err == Suspended) { - if (!c->slept) { + if (!ClientIsAsleep(client)) ClientSleep(client, (ClientSleepProcPtr)doListFontsAndAliases, - (pointer) c); - c->slept = TRUE; - } + c); + else + goto xinerama_sleep; return TRUE; } if (err == Successful) @@ -668,17 +667,17 @@ doListFontsAndAliases(ClientPtr client, LFclosurePtr c) ((pointer) c->client, fpe, &name, &namelen, &tmpname, &resolvedlen, c->current.private); if (err == Suspended) { - if (!c->slept) { + if (ClientIsAsleep(client)) ClientSleep(client, (ClientSleepProcPtr)doListFontsAndAliases, - (pointer) c); - c->slept = TRUE; - } + c); + else + goto xinerama_sleep; return TRUE; } if (err == FontNameAlias) { - if (resolved) xfree(resolved); - resolved = xalloc(resolvedlen + 1); + free(resolved); + resolved = malloc(resolvedlen + 1); if (resolved) memmove(resolved, tmpname, resolvedlen + 1); } @@ -731,9 +730,8 @@ doListFontsAndAliases(ClientPtr client, LFclosurePtr c) { c->saved = c->current; c->haveSaved = TRUE; - if (c->savedName) - xfree(c->savedName); - c->savedName = xalloc(namelen + 1); + free(c->savedName); + c->savedName = malloc(namelen + 1); if (c->savedName) memmove(c->savedName, name, namelen + 1); c->savedNameLen = namelen; @@ -795,7 +793,7 @@ finish: reply.nFonts = nnames; reply.sequenceNumber = client->sequence; - bufptr = bufferStart = xalloc(reply.length << 2); + bufptr = bufferStart = malloc(reply.length << 2); if (!bufptr && reply.length) { SendErrorToClient(client, X_ListFonts, 0, 0, BadAlloc); @@ -820,18 +818,18 @@ finish: client->pSwapReplyFunc = ReplySwapVector[X_ListFonts]; WriteSwappedDataToClient(client, sizeof(xListFontsReply), &reply); (void) WriteToClient(client, stringLens + nnames, bufferStart); - xfree(bufferStart); + free(bufferStart); bail: - if (c->slept) - ClientWakeup(client); + ClientWakeup(client); +xinerama_sleep: for (i = 0; i < c->num_fpes; i++) FreeFPE(c->fpe_list[i]); - xfree(c->fpe_list); - if (c->savedName) xfree(c->savedName); + free(c->fpe_list); + free(c->savedName); FreeFontNames(names); - xfree(c); - if (resolved) xfree(resolved); + free(c); + free(resolved); return TRUE; } @@ -855,18 +853,18 @@ ListFonts(ClientPtr client, unsigned char *pattern, unsigned length, if (i != Success) return i; - if (!(c = xalloc(sizeof *c))) + if (!(c = malloc(sizeof *c))) return BadAlloc; - c->fpe_list = xalloc(sizeof(FontPathElementPtr) * num_fpes); + c->fpe_list = malloc(sizeof(FontPathElementPtr) * num_fpes); if (!c->fpe_list) { - xfree(c); + free(c); return BadAlloc; } c->names = MakeFontNamesRecord(max_names < 100 ? max_names : 100); if (!c->names) { - xfree(c->fpe_list); - xfree(c); + free(c->fpe_list); + free(c); return BadAlloc; } memmove( c->current.pattern, pattern, length); @@ -882,7 +880,6 @@ ListFonts(ClientPtr client, unsigned char *pattern, unsigned length, c->current.list_started = FALSE; c->current.private = 0; c->haveSaved = FALSE; - c->slept = FALSE; c->savedName = 0; doListFontsAndAliases(client, c); return Success; @@ -929,11 +926,11 @@ doListFontsWithInfo(ClientPtr client, LFWIclosurePtr c) c->current.max_names, &c->current.private); if (err == Suspended) { - if (!c->slept) - { - ClientSleep(client, (ClientSleepProcPtr)doListFontsWithInfo, c); - c->slept = TRUE; - } + if (!ClientIsAsleep(client)) + ClientSleep(client, + (ClientSleepProcPtr)doListFontsWithInfo, c); + else + goto xinerama_sleep; return TRUE; } if (err == Successful) @@ -948,13 +945,11 @@ doListFontsWithInfo(ClientPtr client, LFWIclosurePtr c) &numFonts, c->current.private); if (err == Suspended) { - if (!c->slept) - { + if (!ClientIsAsleep(client)) ClientSleep(client, - (ClientSleepProcPtr)doListFontsWithInfo, - c); - c->slept = TRUE; - } + (ClientSleepProcPtr)doListFontsWithInfo, c); + else + goto xinerama_sleep; return TRUE; } } @@ -994,9 +989,8 @@ doListFontsWithInfo(ClientPtr client, LFWIclosurePtr c) c->saved = c->current; c->haveSaved = TRUE; c->savedNumFonts = numFonts; - if (c->savedName) - xfree(c->savedName); - c->savedName = xalloc(namelen + 1); + free(c->savedName); + c->savedName = malloc(namelen + 1); if (c->savedName) memmove(c->savedName, name, namelen + 1); aliascount = 20; @@ -1039,7 +1033,7 @@ doListFontsWithInfo(ClientPtr client, LFWIclosurePtr c) reply = c->reply; if (c->length < length) { - reply = (xListFontsWithInfoReply *) xrealloc(c->reply, length); + reply = (xListFontsWithInfoReply *) realloc(c->reply, length); if (!reply) { err = AllocError; @@ -1085,29 +1079,29 @@ doListFontsWithInfo(ClientPtr client, LFWIclosurePtr c) (void) WriteToClient(client, namelen, name); if (pFontInfo == &fontInfo) { - xfree(fontInfo.props); - xfree(fontInfo.isStringProp); + free(fontInfo.props); + free(fontInfo.isStringProp); } --c->current.max_names; } } finish: length = sizeof(xListFontsWithInfoReply); - bzero((char *) &finalReply, sizeof(xListFontsWithInfoReply)); + memset((char *) &finalReply, 0, sizeof(xListFontsWithInfoReply)); finalReply.type = X_Reply; finalReply.sequenceNumber = client->sequence; finalReply.length = bytes_to_int32(sizeof(xListFontsWithInfoReply) - sizeof(xGenericReply)); WriteSwappedDataToClient(client, length, &finalReply); bail: - if (c->slept) - ClientWakeup(client); + ClientWakeup(client); +xinerama_sleep: for (i = 0; i < c->num_fpes; i++) FreeFPE(c->fpe_list[i]); - xfree(c->reply); - xfree(c->fpe_list); - if (c->savedName) xfree(c->savedName); - xfree(c); + free(c->reply); + free(c->fpe_list); + free(c->savedName); + free(c); return TRUE; } @@ -1131,12 +1125,12 @@ StartListFontsWithInfo(ClientPtr client, int length, unsigned char *pattern, if (i != Success) return i; - if (!(c = xalloc(sizeof *c))) + if (!(c = malloc(sizeof *c))) goto badAlloc; - c->fpe_list = xalloc(sizeof(FontPathElementPtr) * num_fpes); + c->fpe_list = malloc(sizeof(FontPathElementPtr) * num_fpes); if (!c->fpe_list) { - xfree(c); + free(c); goto badAlloc; } memmove(c->current.pattern, pattern, length); @@ -1156,7 +1150,6 @@ StartListFontsWithInfo(ClientPtr client, int length, unsigned char *pattern, c->current.private = 0; c->savedNumFonts = 0; c->haveSaved = FALSE; - c->slept = FALSE; c->savedName = 0; doListFontsWithInfo(client, c); return Success; @@ -1166,14 +1159,13 @@ badAlloc: #define TextEltHeader 2 #define FontShiftSize 5 -static XID clearGC[] = { CT_NONE }; +static ChangeGCVal clearGC[] = { { .ptr = NullPixmap } }; #define clearGCmask (GCClipMask) int doPolyText(ClientPtr client, PTclosurePtr c) { FontPtr pFont = c->pGC->font, oldpFont; - Font fid, oldfid; int err = Success, lgerr; /* err is in X error, not font error, space */ enum { NEVER_SLEPT, START_SLEEP, SLEEPING } client_state = NEVER_SLEPT; FontPathElementPtr fpe; @@ -1184,7 +1176,7 @@ doPolyText(ClientPtr client, PTclosurePtr c) fpe = c->pGC->font->fpe; (*fpe_functions[fpe->type].client_died) ((pointer) client, fpe); - if (c->slept) + if (ClientIsAsleep(client)) { /* Client has died, but we cannot bail out right now. We need to clean up after the work we did when going to @@ -1201,7 +1193,7 @@ doPolyText(ClientPtr client, PTclosurePtr c) } /* Make sure our drawable hasn't disappeared while we slept. */ - if (c->slept && c->pDraw) + if (ClientIsAsleep(client) && c->pDraw) { DrawablePtr pDraw; dixLookupDrawable(&pDraw, c->did, client, 0, DixWriteAccess); @@ -1215,12 +1207,13 @@ doPolyText(ClientPtr client, PTclosurePtr c) } } - client_state = c->slept ? SLEEPING : NEVER_SLEPT; + client_state = ClientIsAsleep(client) ? SLEEPING : NEVER_SLEPT; while (c->endReq - c->pElt > TextEltHeader) { if (*c->pElt == FontChange) { + Font fid; if (c->endReq - c->pElt < FontShiftSize) { err = BadLength; @@ -1228,20 +1221,17 @@ doPolyText(ClientPtr client, PTclosurePtr c) } oldpFont = pFont; - oldfid = fid; fid = ((Font)*(c->pElt+4)) /* big-endian */ | ((Font)*(c->pElt+3)) << 8 | ((Font)*(c->pElt+2)) << 16 | ((Font)*(c->pElt+1)) << 24; err = dixLookupResourceByType((pointer *)&pFont, fid, RT_FONT, - client, DixReadAccess); + client, DixUseAccess); if (err != Success) { - err = (err == BadValue) ? BadFont : err; - /* restore pFont and fid for step 4 (described below) */ + /* restore pFont for step 4 (described below) */ pFont = oldpFont; - fid = oldfid; /* If we're in START_SLEEP mode, the following step shortens the request... in the unlikely event that @@ -1261,7 +1251,9 @@ doPolyText(ClientPtr client, PTclosurePtr c) { if (pFont != c->pGC->font && c->pDraw) { - ChangeGC( c->pGC, GCFont, &fid); + ChangeGCVal val; + val.ptr = pFont; + ChangeGC(NullClient, c->pGC, GCFont, &val); ValidateGC(c->pDraw, c->pGC); if (c->reqType == X_PolyText8) c->polyText = (PolyTextPtr) c->pGC->ops->PolyText8; @@ -1298,7 +1290,7 @@ doPolyText(ClientPtr client, PTclosurePtr c) if (lgerr == Suspended) { - if (!c->slept) { + if (!ClientIsAsleep(client)) { int len; GC *pGC; PTclosurePtr new_closure; @@ -1320,7 +1312,7 @@ doPolyText(ClientPtr client, PTclosurePtr c) /* Step 1 */ /* Allocate a malloc'd closure structure to replace the local one we were passed */ - new_closure = xalloc(sizeof(PTclosureRec)); + new_closure = malloc(sizeof(PTclosureRec)); if (!new_closure) { err = BadAlloc; @@ -1330,10 +1322,10 @@ doPolyText(ClientPtr client, PTclosurePtr c) c = new_closure; len = c->endReq - c->pElt; - c->data = xalloc(len); + c->data = malloc(len); if (!c->data) { - xfree(c); + free(c); err = BadAlloc; goto bail; } @@ -1346,8 +1338,8 @@ doPolyText(ClientPtr client, PTclosurePtr c) pGC = GetScratchGC(c->pGC->depth, c->pGC->pScreen); if (!pGC) { - xfree(c->data); - xfree(c); + free(c->data); + free(c); err = BadAlloc; goto bail; } @@ -1362,8 +1354,8 @@ doPolyText(ClientPtr client, PTclosurePtr c) Success) { FreeScratchGC(pGC); - xfree(c->data); - xfree(c); + free(c->data); + free(c); err = BadAlloc; goto bail; } @@ -1371,15 +1363,14 @@ doPolyText(ClientPtr client, PTclosurePtr c) c->pGC = pGC; ValidateGC(c->pDraw, c->pGC); - c->slept = TRUE; - ClientSleep(client, - (ClientSleepProcPtr)doPolyText, - (pointer) c); + ClientSleep(client, (ClientSleepProcPtr)doPolyText, c); /* Set up to perform steps 3 and 4 */ client_state = START_SLEEP; continue; /* on to steps 3 and 4 */ } + else + goto xinerama_sleep; return TRUE; } else if (lgerr != Successful) @@ -1404,7 +1395,9 @@ bail: /* Step 4 */ if (pFont != origGC->font) { - ChangeGC(origGC, GCFont, &fid); + ChangeGCVal val; + val.ptr = pFont; + ChangeGC(NullClient, origGC, GCFont, &val); ValidateGC(c->pDraw, origGC); } @@ -1420,18 +1413,19 @@ bail: #endif SendErrorToClient(c->client, c->reqType, 0, 0, err); } - if (c->slept) + if (ClientIsAsleep(client)) { ClientWakeup(c->client); - ChangeGC(c->pGC, clearGCmask, clearGC); +xinerama_sleep: + ChangeGC(NullClient, c->pGC, clearGCmask, clearGC); /* Unreference the font from the scratch GC */ CloseFont(c->pGC->font, (Font)0); c->pGC->font = NullFont; FreeScratchGC(c->pGC); - xfree(c->data); - xfree(c); + free(c->data); + free(c); } return TRUE; } @@ -1461,7 +1455,6 @@ PolyText(ClientPtr client, DrawablePtr pDraw, GC *pGC, unsigned char *pElt, local_closure.pGC = pGC; local_closure.did = did; local_closure.err = Success; - local_closure.slept = FALSE; (void) doPolyText(client, &local_closure); return Success; @@ -1486,7 +1479,7 @@ doImageText(ClientPtr client, ITclosurePtr c) } /* Make sure our drawable hasn't disappeared while we slept. */ - if (c->slept && c->pDraw) + if (ClientIsAsleep(client) && c->pDraw) { DrawablePtr pDraw; dixLookupDrawable(&pDraw, c->did, client, 0, DixWriteAccess); @@ -1503,7 +1496,7 @@ doImageText(ClientPtr client, ITclosurePtr c) lgerr = LoadGlyphs(client, c->pGC->font, c->nChars, c->itemSize, c->data); if (lgerr == Suspended) { - if (!c->slept) { + if (!ClientIsAsleep(client)) { GC *pGC; unsigned char *data; ITclosurePtr new_closure; @@ -1513,7 +1506,7 @@ doImageText(ClientPtr client, ITclosurePtr c) in doPolyText, but much simpler because the request structure is much simpler. */ - new_closure = xalloc(sizeof(ITclosureRec)); + new_closure = malloc(sizeof(ITclosureRec)); if (!new_closure) { err = BadAlloc; @@ -1522,10 +1515,10 @@ doImageText(ClientPtr client, ITclosurePtr c) *new_closure = *c; c = new_closure; - data = xalloc(c->nChars * c->itemSize); + data = malloc(c->nChars * c->itemSize); if (!data) { - xfree(c); + free(c); err = BadAlloc; goto bail; } @@ -1535,8 +1528,8 @@ doImageText(ClientPtr client, ITclosurePtr c) pGC = GetScratchGC(c->pGC->depth, c->pGC->pScreen); if (!pGC) { - xfree(c->data); - xfree(c); + free(c->data); + free(c); err = BadAlloc; goto bail; } @@ -1548,17 +1541,18 @@ doImageText(ClientPtr client, ITclosurePtr c) GCClipYOrigin | GCClipMask)) != Success) { FreeScratchGC(pGC); - xfree(c->data); - xfree(c); + free(c->data); + free(c); err = BadAlloc; goto bail; } c->pGC = pGC; ValidateGC(c->pDraw, c->pGC); - c->slept = TRUE; - ClientSleep(client, (ClientSleepProcPtr)doImageText, (pointer) c); + ClientSleep(client, (ClientSleepProcPtr)doImageText, c); } + else + goto xinerama_sleep; return TRUE; } else if (lgerr != Successful) @@ -1577,18 +1571,19 @@ bail: if (err != Success && c->client != serverClient) { SendErrorToClient(c->client, c->reqType, 0, 0, err); } - if (c->slept) + if (ClientIsAsleep(client)) { ClientWakeup(c->client); - ChangeGC(c->pGC, clearGCmask, clearGC); +xinerama_sleep: + ChangeGC(NullClient, c->pGC, clearGCmask, clearGC); /* Unreference the font from the scratch GC */ CloseFont(c->pGC->font, (Font)0); c->pGC->font = NullFont; FreeScratchGC(c->pGC); - xfree(c->data); - xfree(c); + free(c->data); + free(c); } return TRUE; } @@ -1617,7 +1612,6 @@ ImageText(ClientPtr client, DrawablePtr pDraw, GC *pGC, int nChars, local_closure.itemSize = 2; } local_closure.did = did; - local_closure.slept = FALSE; (void) doImageText(client, &local_closure); return Success; @@ -1659,7 +1653,7 @@ FreeFontPath(FontPathElementPtr *list, int n, Bool force) } FreeFPE(list[i]); } - xfree(list); + free(list); } static FontPathElementPtr @@ -1686,7 +1680,7 @@ SetFontPathElements(int npaths, unsigned char *paths, int *bad, Bool persist) unsigned char *cp = paths; FontPathElementPtr fpe = NULL, *fplist; - fplist = xalloc(sizeof(FontPathElementPtr) * npaths); + fplist = malloc(sizeof(FontPathElementPtr) * npaths); if (!fplist) { *bad = 0; return BadAlloc; @@ -1727,16 +1721,16 @@ SetFontPathElements(int npaths, unsigned char *paths, int *bad, Bool persist) /* if error or can't do it, act like it's a new one */ if (!fpe) { - fpe = xalloc(sizeof(FontPathElementRec)); + fpe = malloc(sizeof(FontPathElementRec)); if (!fpe) { err = BadAlloc; goto bail; } - fpe->name = xalloc(len + 1); + fpe->name = malloc(len + 1); if (!fpe->name) { - xfree(fpe); + free(fpe); err = BadAlloc; goto bail; } @@ -1757,8 +1751,8 @@ SetFontPathElements(int npaths, unsigned char *paths, int *bad, Bool persist) ErrorF("[dix] Could not init font path element %s, removing from list!\n", fpe->name); } - xfree (fpe->name); - xfree (fpe); + free(fpe->name); + free(fpe); } } } @@ -1785,13 +1779,12 @@ bail: *bad = i; while (--valid_paths >= 0) FreeFPE(fplist[valid_paths]); - xfree(fplist); + free(fplist); return FontToXError(err); } -/* XXX -- do we need to pass error down to each renderer? */ int -SetFontPath(ClientPtr client, int npaths, unsigned char *paths, int *error) +SetFontPath(ClientPtr client, int npaths, unsigned char *paths) { int err = XaceHook(XACE_SERVER_ACCESS, client, DixManageAccess); if (err != Success) @@ -1801,7 +1794,9 @@ SetFontPath(ClientPtr client, int npaths, unsigned char *paths, int *error) if (SetDefaultFontPath(defaultFontPath) != Success) return BadValue; } else { - err = SetFontPathElements(npaths, paths, error, FALSE); + int bad; + err = SetFontPathElements(npaths, paths, &bad, FALSE); + client->errorValue = bad; } return err; } @@ -1836,14 +1831,14 @@ SetDefaultFontPath(char *path) if (!start) { temp_path = Xprintf("%s%sbuilt-ins", path, *path ? "," : ""); } else { - temp_path = Xstrdup(path); + temp_path = strdup(path); } if (!temp_path) return BadAlloc; /* get enough for string, plus values -- use up commas */ len = strlen(temp_path) + 1; - nump = cp = newpath = xalloc(len); + nump = cp = newpath = malloc(len); if (!newpath) return BadAlloc; pp = (unsigned char *) temp_path; @@ -1864,8 +1859,8 @@ SetDefaultFontPath(char *path) err = SetFontPathElements(num, newpath, &bad, TRUE); - xfree(newpath); - xfree(temp_path); + free(newpath); + free(temp_path); return err; } @@ -1887,7 +1882,7 @@ GetFontPath(ClientPtr client, int *count, int *length, unsigned char **result) fpe = font_path_elements[i]; len += fpe->name_length + 1; } - font_path_string = (unsigned char *) xrealloc(font_path_string, len); + font_path_string = (unsigned char *) realloc(font_path_string, len); if (!font_path_string) return BadAlloc; @@ -1924,9 +1919,7 @@ InitFonts (void) { patternCache = MakeFontPatternCache(); - BuiltinRegisterFpeFunctions(); - FontFileRegisterFpeFunctions(); - fs_register_fpe_functions(); + register_fpe_functions(); } int @@ -1988,7 +1981,7 @@ RegisterFPEFunctions(NameCheckFunc name_func, FPEFunctions *new; /* grow the list */ - new = (FPEFunctions *) xrealloc(fpe_functions, + new = (FPEFunctions *) realloc(fpe_functions, (num_fpe_types + 1) * sizeof(FPEFunctions)); if (!new) return -1; @@ -2027,7 +2020,7 @@ FreeFonts(void) FreeFontPath(font_path_elements, num_fpes, TRUE); font_path_elements = 0; num_fpes = 0; - xfree(fpe_functions); + free(fpe_functions); num_fpe_types = 0; fpe_functions = (FPEFunctions *) 0; } diff --git a/xserver/dix/dixutils.c b/xserver/dix/dixutils.c index 8278d444b..470bb5dd7 100644 --- a/xserver/dix/dixutils.c +++ b/xserver/dix/dixutils.c @@ -92,6 +92,7 @@ Author: Adobe Systems Incorporated #include "windowstr.h" #include "dixstruct.h" #include "pixmapstr.h" +#include "gcstruct.h" #include "scrnintstr.h" #define XK_LATIN1 #include <X11/keysymdef.h> @@ -230,9 +231,24 @@ dixLookupWindow(WindowPtr *pWin, XID id, ClientPtr client, Mask access) int dixLookupGC(GCPtr *pGC, XID id, ClientPtr client, Mask access) { + return dixLookupResourceByType((pointer *)pGC, id, RT_GC, client, access); +} + +int +dixLookupFontable(FontPtr *pFont, XID id, ClientPtr client, Mask access) +{ int rc; - rc = dixLookupResourceByType((pointer *)pGC, id, RT_GC, client, access); - return (rc == BadValue) ? BadGC : rc; + GC *pGC; + client->errorValue = id; /* EITHER font or gc */ + rc = dixLookupResourceByType((pointer *) pFont, id, RT_FONT, client, access); + if (rc != BadFont) + return rc; + rc = dixLookupResourceByType((pointer *) &pGC, id, RT_GC, client, access); + if (rc == BadGC) + return BadFont; + if (rc == Success) + *pFont = pGC->font; + return rc; } int @@ -280,17 +296,17 @@ AlterSaveSetForClient(ClientPtr client, WindowPtr pWin, unsigned mode, if (mode == SetModeInsert) { if (j < numnow) /* duplicate */ - return(Success); + return Success; numnow++; - pTmp = (SaveSetElt *)xrealloc(client->saveSet, sizeof(*pTmp) * numnow); + pTmp = (SaveSetElt *)realloc(client->saveSet, sizeof(*pTmp) * numnow); if (!pTmp) - return(BadAlloc); + return BadAlloc; client->saveSet = pTmp; client->numSaved = numnow; SaveSetAssignWindow(client->saveSet[numnow - 1], pWin); SaveSetAssignToRoot(client->saveSet[numnow - 1], toRoot); SaveSetAssignMap(client->saveSet[numnow - 1], map); - return(Success); + return Success; } else if ((mode == SetModeDelete) && (j < numnow)) { @@ -302,19 +318,19 @@ AlterSaveSetForClient(ClientPtr client, WindowPtr pWin, unsigned mode, numnow--; if (numnow) { - pTmp = (SaveSetElt *)xrealloc(client->saveSet, sizeof(*pTmp) * numnow); + pTmp = (SaveSetElt *)realloc(client->saveSet, sizeof(*pTmp) * numnow); if (pTmp) client->saveSet = pTmp; } else { - xfree(client->saveSet); + free(client->saveSet); client->saveSet = (SaveSetElt *)NULL; } client->numSaved = numnow; - return(Success); + return Success; } - return(Success); + return Success; } void @@ -435,7 +451,7 @@ RegisterBlockAndWakeupHandlers (BlockHandlerProcPtr blockHandler, if (numHandlers >= sizeHandlers) { - new = (BlockHandlerPtr) xrealloc (handlers, (numHandlers + 1) * + new = (BlockHandlerPtr) realloc(handlers, (numHandlers + 1) * sizeof (BlockHandlerRec)); if (!new) return FALSE; @@ -480,7 +496,7 @@ RemoveBlockAndWakeupHandlers (BlockHandlerProcPtr blockHandler, void InitBlockAndWakeupHandlers (void) { - xfree (handlers); + free(handlers); handlers = (BlockHandlerPtr) 0; numHandlers = 0; sizeHandlers = 0; @@ -512,7 +528,7 @@ ProcessWorkQueue(void) { /* remove q from the list */ *p = q->next; /* don't fetch until after func called */ - xfree (q); + free(q); } else { @@ -535,7 +551,7 @@ ProcessWorkQueueZombies(void) (void) (*q->function) (q->client, q->closure); /* remove q from the list */ *p = q->next; /* don't fetch until after func called */ - xfree (q); + free(q); } else { @@ -552,7 +568,7 @@ QueueWorkProc ( { WorkQueuePtr q; - q = xalloc (sizeof *q); + q = malloc(sizeof *q); if (!q) return FALSE; q->function = function; @@ -586,7 +602,7 @@ ClientSleep (ClientPtr client, ClientSleepProcPtr function, pointer closure) { SleepQueuePtr q; - q = xalloc (sizeof *q); + q = malloc(sizeof *q); if (!q) return FALSE; @@ -623,7 +639,7 @@ ClientWakeup (ClientPtr client) if (q->client == client) { *prev = q->next; - xfree (q); + free(q); if (client->clientGone) /* Oops -- new zombie cleanup code ensures this only * happens from inside CloseDownClient; don't want to @@ -666,7 +682,7 @@ _AddCallback( { CallbackPtr cbr; - cbr = xalloc(sizeof(CallbackRec)); + cbr = malloc(sizeof(CallbackRec)); if (!cbr) return FALSE; cbr->proc = callback; @@ -706,7 +722,7 @@ _DeleteCallback( cbl->list = cbr->next; else pcbr->next = cbr->next; - xfree(cbr); + free(cbr); } return TRUE; } @@ -751,12 +767,12 @@ _CallCallbacks( if (pcbr) { cbr = cbr->next; - xfree(pcbr->next); + free(pcbr->next); pcbr->next = cbr; } else { cbr = cbr->next; - xfree(cbl->list); + free(cbl->list); cbl->list = cbr; } cbl->numDeleted--; @@ -796,9 +812,9 @@ _DeleteCallbackList( for (cbr = cbl->list; cbr != NULL; cbr = nextcbr) { nextcbr = cbr->next; - xfree(cbr); + free(cbr); } - xfree(cbl); + free(cbl); *pcbl = NULL; } @@ -809,7 +825,7 @@ CreateCallbackList(CallbackListPtr *pcbl) int i; if (!pcbl) return FALSE; - cbl = xalloc(sizeof(CallbackListRec)); + cbl = malloc(sizeof(CallbackListRec)); if (!cbl) return FALSE; cbl->inCallback = 0; cbl->deleted = FALSE; @@ -877,7 +893,7 @@ InitCallbackManager(void) { DeleteCallbackList(listsToCleanup[i]); } - if (listsToCleanup) xfree(listsToCleanup); + free(listsToCleanup); numCallbackListsToCleanup = 0; listsToCleanup = NULL; diff --git a/xserver/dix/enterleave.c b/xserver/dix/enterleave.c index c08cc3100..7a3ecf5b0 100644 --- a/xserver/dix/enterleave.c +++ b/xserver/dix/enterleave.c @@ -78,10 +78,19 @@ static WindowPtr FocusWindows[MAXDEVICES]; * window. */ static BOOL -HasPointer(WindowPtr win) +HasPointer(DeviceIntPtr dev, WindowPtr win) { int i; + /* FIXME: The enter/leave model does not cater for grabbed devices. For + * now, a quickfix: if the device about to send an enter/leave event to + * a window is grabbed, assume there is no pointer in that window. + * Fixes fdo 27804. + * There isn't enough beer in my fridge to fix this properly. + */ + if (dev->deviceGrab.grab) + return FALSE; + for (i = 0; i < MAXDEVICES; i++) if (PointerWindows[i] == win) return TRUE; @@ -270,7 +279,7 @@ CoreEnterNotifies(DeviceIntPtr dev, may need to be changed from Virtual to NonlinearVirtual depending on the previous P(W). */ - if (!HasPointer(parent) && !FirstPointerChild(parent)) + if (!HasPointer(dev, parent) && !FirstPointerChild(parent)) CoreEnterLeaveEvent(dev, EnterNotify, mode, detail, parent, child->drawable.id); } @@ -309,7 +318,7 @@ CoreLeaveNotifies(DeviceIntPtr dev, /* If one window has a pointer or a child with a pointer, skip some * work and exit. */ - if (HasPointer(win) || FirstPointerChild(win)) + if (HasPointer(dev, win) || FirstPointerChild(win)) return; CoreEnterLeaveEvent(dev, LeaveNotify, mode, detail, win, child->drawable.id); @@ -373,7 +382,7 @@ CoreEnterLeaveNonLinear(DeviceIntPtr dev, vice versa depending on the the new P(W) */ - if (!HasPointer(A)) + if (!HasPointer(dev, A)) { WindowPtr child = FirstPointerChild(A); if (child) @@ -417,7 +426,7 @@ CoreEnterLeaveNonLinear(DeviceIntPtr dev, The detail may need to be changed from Ancestor to Nonlinear or vice-versa depending on the previous P(W). */ - if (!HasPointer(B)) + if (!HasPointer(dev, B)) { WindowPtr child = FirstPointerChild(B); if (child) @@ -455,7 +464,7 @@ CoreEnterLeaveToAncestor(DeviceIntPtr dev, The detail may need to be changed from Ancestor to Nonlinear or vice versa depending on the the new P(W) */ - if (!HasPointer(A)) + if (!HasPointer(dev, A)) { WindowPtr child = FirstPointerChild(A); if (child) @@ -479,7 +488,7 @@ CoreEnterLeaveToAncestor(DeviceIntPtr dev, P(W) changes from a descendant to W itself. The subwindow field should be set to the child containing the old P(W) <<< WRONG */ - if (!HasPointer(B)) + if (!HasPointer(dev, B)) CoreEnterLeaveEvent(dev, EnterNotify, mode, NotifyInferior, B, None); } @@ -507,7 +516,7 @@ CoreEnterLeaveToDescendant(DeviceIntPtr dev, P(W) changes from W to a descendant of W. The subwindow field is set to the child containing the new P(W) <<< THIS IS WRONG */ - if (!HasPointer(A)) + if (!HasPointer(dev, A)) CoreEnterLeaveEvent(dev, LeaveNotify, mode, NotifyInferior, A, None); @@ -531,7 +540,7 @@ CoreEnterLeaveToDescendant(DeviceIntPtr dev, The detail may need to be changed from Ancestor to Nonlinear or vice-versa depending on the previous P(W). */ - if (!HasPointer(B)) + if (!HasPointer(dev, B)) { WindowPtr child = FirstPointerChild(B); if (child) @@ -1077,7 +1086,7 @@ CoreFocusPointerRootNoneSwitch(DeviceIntPtr dev, for (i = 0; i < nscreens; i++) { - root = WindowTable[i]; + root = screenInfo.screens[i]->root; if (!HasOtherPointer(root, GetPairedDevice(dev)) && !FirstFocusChild(root)) { /* If pointer was on PointerRootWin and changes to NoneWin, and @@ -1138,7 +1147,7 @@ CoreFocusToPointerRootOrNone(DeviceIntPtr dev, for (i = 0; i < nscreens; i++) { - root = WindowTable[i]; + root = screenInfo.screens[i]->root; if (!HasFocus(root) && !FirstFocusChild(root)) { CoreFocusEvent(dev, FocusIn, mode, B ? NotifyPointerRoot : NotifyDetailNone, root); @@ -1169,7 +1178,7 @@ CoreFocusFromPointerRootOrNone(DeviceIntPtr dev, for (i = 0; i < nscreens; i++) { - root = WindowTable[i]; + root = screenInfo.screens[i]->root; if (!HasFocus(root) && !FirstFocusChild(root)) { /* If pointer was on PointerRootWin and changes to NoneWin, and @@ -1279,7 +1288,7 @@ DeviceFocusEvents(DeviceIntPtr dev, NotifyPointer); /* Notify all the roots */ for (i = 0; i < nscreens; i++) - DeviceFocusEvent(dev, XI_FocusOut, mode, out, WindowTable[i]); + DeviceFocusEvent(dev, XI_FocusOut, mode, out, screenInfo.screens[i]->root); } else { @@ -1293,7 +1302,7 @@ DeviceFocusEvents(DeviceIntPtr dev, } /* Notify all the roots */ for (i = 0; i < nscreens; i++) - DeviceFocusEvent(dev, XI_FocusIn, mode, in, WindowTable[i]); + DeviceFocusEvent(dev, XI_FocusIn, mode, in, screenInfo.screens[i]->root); if (to == PointerRootWin) DeviceFocusInEvents(dev, RootWindow(dev), sprite->win, mode, NotifyPointer); } @@ -1305,7 +1314,7 @@ DeviceFocusEvents(DeviceIntPtr dev, DeviceFocusOutEvents(dev, sprite->win, RootWindow(dev), mode, NotifyPointer); for (i = 0; i < nscreens; i++) - DeviceFocusEvent(dev, XI_FocusOut, mode, out, WindowTable[i]); + DeviceFocusEvent(dev, XI_FocusOut, mode, out, screenInfo.screens[i]->root); if (to->parent != NullWindow) DeviceFocusInEvents(dev, RootWindow(dev), to, mode, NotifyNonlinearVirtual); DeviceFocusEvent(dev, XI_FocusIn, mode, NotifyNonlinear, to); diff --git a/xserver/dix/eventconvert.c b/xserver/dix/eventconvert.c index 878dba576..4e3de0b46 100644 --- a/xserver/dix/eventconvert.c +++ b/xserver/dix/eventconvert.c @@ -254,7 +254,7 @@ eventToKeyButtonPointer(DeviceEvent *ev, xEvent **xi, int *count) num_events = (countValuators(ev, &first) + 5)/6; /* valuator ev */ num_events++; /* the actual event event */ - *xi = xcalloc(num_events, sizeof(xEvent)); + *xi = calloc(num_events, sizeof(xEvent)); if (!(*xi)) { return BadAlloc; @@ -462,7 +462,7 @@ eventToDeviceChanged(DeviceChangedEvent *dce, xEvent **xi) len += sizeof(CARD32) * nkeys; /* keycodes */ } - dcce = xcalloc(1, len); + dcce = calloc(1, len); if (!dcce) { ErrorF("[Xi] BadAlloc in SendDeviceChangedEvent.\n"); @@ -545,7 +545,7 @@ eventToDeviceEvent(DeviceEvent *ev, xEvent **xi) vallen = bytes_to_int32(bits_to_bytes(MAX_VALUATORS)); len += vallen * 4; /* valuators mask */ - *xi = xcalloc(1, len); + *xi = calloc(1, len); xde = (xXIDeviceEvent*)*xi; xde->type = GenericEvent; xde->extension = IReqCode; @@ -612,7 +612,7 @@ eventToRawEvent(RawDeviceEvent *ev, xEvent **xi) vallen = bytes_to_int32(bits_to_bytes(MAX_VALUATORS)); len += vallen * 4; /* valuators mask */ - *xi = xcalloc(1, len); + *xi = calloc(1, len); raw = (xXIRawEvent*)*xi; raw->type = GenericEvent; raw->extension = IReqCode; diff --git a/xserver/dix/events.c b/xserver/dix/events.c index 80c29cc00..07f7b1f6b 100644 --- a/xserver/dix/events.c +++ b/xserver/dix/events.c @@ -331,7 +331,7 @@ IsKeyboardDevice(DeviceIntPtr dev) Bool IsMaster(DeviceIntPtr dev) { - return (dev->type == MASTER_POINTER || dev->type == MASTER_KEYBOARD); + return dev->type == MASTER_POINTER || dev->type == MASTER_KEYBOARD; } static WindowPtr XYToWindow( @@ -486,6 +486,13 @@ SyntheticMotion(DeviceIntPtr dev, int x, int y) { static void PostNewCursor(DeviceIntPtr pDev); static Bool +pointOnScreen(ScreenPtr pScreen, int x, int y) +{ + return x >= pScreen->x && x < pScreen->x + pScreen->width && + y >= pScreen->y && y < pScreen->y + pScreen->height; +} + +static Bool XineramaSetCursorPosition( DeviceIntPtr pDev, int x, @@ -493,7 +500,6 @@ XineramaSetCursorPosition( Bool generateEvent ){ ScreenPtr pScreen; - BoxRec box; int i; SpritePtr pSprite = pDev->spriteInfo->sprite; @@ -502,17 +508,16 @@ XineramaSetCursorPosition( that screen are. */ pScreen = pSprite->screen; - x += panoramiXdataPtr[0].x; - y += panoramiXdataPtr[0].y; + x += screenInfo.screens[0]->x; + y += screenInfo.screens[0]->y; - if(!POINT_IN_REGION(pScreen, &XineramaScreenRegions[pScreen->myNum], - x, y, &box)) + if(!pointOnScreen(pScreen, x, y)) { FOR_NSCREENS(i) { if(i == pScreen->myNum) continue; - if(POINT_IN_REGION(pScreen, &XineramaScreenRegions[i], x, y, &box)) + if(pointOnScreen(screenInfo.screens[i], x, y)) { pScreen = screenInfo.screens[i]; break; @@ -521,10 +526,10 @@ XineramaSetCursorPosition( } pSprite->screen = pScreen; - pSprite->hotPhys.x = x - panoramiXdataPtr[0].x; - pSprite->hotPhys.y = y - panoramiXdataPtr[0].y; - x -= panoramiXdataPtr[pScreen->myNum].x; - y -= panoramiXdataPtr[pScreen->myNum].y; + pSprite->hotPhys.x = x - screenInfo.screens[0]->x; + pSprite->hotPhys.y = y - screenInfo.screens[0]->y; + x -= pScreen->x; + y -= pScreen->y; return (*pScreen->SetCursorPosition)(pDev, pScreen, x, y, generateEvent); } @@ -542,10 +547,10 @@ XineramaConstrainCursor(DeviceIntPtr pDev) /* Translate the constraining box to the screen the sprite is actually on */ - newBox.x1 += panoramiXdataPtr[0].x - panoramiXdataPtr[pScreen->myNum].x; - newBox.x2 += panoramiXdataPtr[0].x - panoramiXdataPtr[pScreen->myNum].x; - newBox.y1 += panoramiXdataPtr[0].y - panoramiXdataPtr[pScreen->myNum].y; - newBox.y2 += panoramiXdataPtr[0].y - panoramiXdataPtr[pScreen->myNum].y; + newBox.x1 += screenInfo.screens[0]->x - pScreen->x; + newBox.x2 += screenInfo.screens[0]->x - pScreen->x; + newBox.y1 += screenInfo.screens[0]->y - pScreen->y; + newBox.y2 += screenInfo.screens[0]->y - pScreen->y; (* pScreen->ConstrainCursor)(pDev, pScreen, &newBox); } @@ -556,9 +561,10 @@ XineramaSetWindowPntrs(DeviceIntPtr pDev, WindowPtr pWin) { SpritePtr pSprite = pDev->spriteInfo->sprite; - if(pWin == WindowTable[0]) { - memcpy(pSprite->windows, WindowTable, - PanoramiXNumScreens*sizeof(WindowPtr)); + if(pWin == screenInfo.screens[0]->root) { + int i; + for (i = 0; i < PanoramiXNumScreens; i++) + pSprite->windows[i] = screenInfo.screens[i]->root; } else { PanoramiXRes *win; int rc, i; @@ -592,34 +598,34 @@ XineramaConfineCursorToWindow(DeviceIntPtr pDev, i = PanoramiXNumScreens - 1; - REGION_COPY(pSprite->screen, &pSprite->Reg1, + RegionCopy(&pSprite->Reg1, &pSprite->windows[i]->borderSize); - off_x = panoramiXdataPtr[i].x; - off_y = panoramiXdataPtr[i].y; + off_x = screenInfo.screens[i]->x; + off_y = screenInfo.screens[i]->y; while(i--) { - x = off_x - panoramiXdataPtr[i].x; - y = off_y - panoramiXdataPtr[i].y; + x = off_x - screenInfo.screens[i]->x; + y = off_y - screenInfo.screens[i]->y; if(x || y) - REGION_TRANSLATE(pSprite->screen, &pSprite->Reg1, x, y); + RegionTranslate(&pSprite->Reg1, x, y); - REGION_UNION(pSprite->screen, &pSprite->Reg1, &pSprite->Reg1, + RegionUnion(&pSprite->Reg1, &pSprite->Reg1, &pSprite->windows[i]->borderSize); - off_x = panoramiXdataPtr[i].x; - off_y = panoramiXdataPtr[i].y; + off_x = screenInfo.screens[i]->x; + off_y = screenInfo.screens[i]->y; } - pSprite->hotLimits = *REGION_EXTENTS(pSprite->screen, &pSprite->Reg1); + pSprite->hotLimits = *RegionExtents(&pSprite->Reg1); - if(REGION_NUM_RECTS(&pSprite->Reg1) > 1) + if(RegionNumRects(&pSprite->Reg1) > 1) pSprite->hotShape = &pSprite->Reg1; else pSprite->hotShape = NullRegion; pSprite->confined = FALSE; - pSprite->confineWin = (pWin == WindowTable[0]) ? NullWindow : pWin; + pSprite->confineWin = (pWin == screenInfo.screens[0]->root) ? NullWindow : pWin; CheckPhysLimits(pDev, pSprite->current, generateEvents, FALSE, NULL); } @@ -665,9 +671,9 @@ ConfineToShape(DeviceIntPtr pDev, RegionPtr shape, int *px, int *py) SpritePtr pSprite; pSprite = pDev->spriteInfo->sprite; - if (POINT_IN_REGION(pSprite->hot.pScreen, shape, x, y, &box)) + if (RegionContainsPoint(shape, x, y, &box)) return; - box = *REGION_EXTENTS(pSprite->hot.pScreen, shape); + box = *RegionExtents(shape); /* this is rather crude */ do { x += incx; @@ -689,7 +695,7 @@ ConfineToShape(DeviceIntPtr pDev, RegionPtr shape, int *px, int *py) else if (y < box.y1) return; /* should never get here! */ } - } while (!POINT_IN_REGION(pSprite->hot.pScreen, shape, x, y, &box)); + } while (!RegionContainsPoint(shape, x, y, &box)); *px = x; *py = y; } @@ -811,23 +817,23 @@ CheckVirtualMotion( i = PanoramiXNumScreens - 1; - REGION_COPY(pSprite->screen, &pSprite->Reg2, + RegionCopy(&pSprite->Reg2, &pSprite->windows[i]->borderSize); - off_x = panoramiXdataPtr[i].x; - off_y = panoramiXdataPtr[i].y; + off_x = screenInfo.screens[i]->x; + off_y = screenInfo.screens[i]->y; while(i--) { - x = off_x - panoramiXdataPtr[i].x; - y = off_y - panoramiXdataPtr[i].y; + x = off_x - screenInfo.screens[i]->x; + y = off_y - screenInfo.screens[i]->y; if(x || y) - REGION_TRANSLATE(pSprite->screen, &pSprite->Reg2, x, y); + RegionTranslate(&pSprite->Reg2, x, y); - REGION_UNION(pSprite->screen, &pSprite->Reg2, &pSprite->Reg2, + RegionUnion(&pSprite->Reg2, &pSprite->Reg2, &pSprite->windows[i]->borderSize); - off_x = panoramiXdataPtr[i].x; - off_y = panoramiXdataPtr[i].y; + off_x = screenInfo.screens[i]->x; + off_y = screenInfo.screens[i]->y; } } else #endif @@ -839,7 +845,7 @@ CheckVirtualMotion( } } - lims = *REGION_EXTENTS(pWin->drawable.pScreen, &pWin->borderSize); + lims = *RegionExtents(&pWin->borderSize); if (pSprite->hot.x < lims.x1) pSprite->hot.x = lims.x1; else if (pSprite->hot.x >= lims.x2) @@ -852,7 +858,7 @@ CheckVirtualMotion( #ifdef PANORAMIX if (!noPanoramiXExtension) { - if (REGION_NUM_RECTS(&pSprite->Reg2) > 1) + if (RegionNumRects(&pSprite->Reg2) > 1) reg = &pSprite->Reg2; } else @@ -875,13 +881,12 @@ CheckVirtualMotion( #ifdef PANORAMIX if (noPanoramiXExtension) /* No typo. Only set the root win if disabled */ #endif - RootWindow(pDev) = WindowTable[pSprite->hot.pScreen->myNum]; + RootWindow(pDev) = pSprite->hot.pScreen->root; } static void ConfineCursorToWindow(DeviceIntPtr pDev, WindowPtr pWin, Bool generateEvents, Bool confineToScreen) { - ScreenPtr pScreen = pWin->drawable.pScreen; SpritePtr pSprite = pDev->spriteInfo->sprite; if (syncEvents.playingEvents) @@ -897,11 +902,11 @@ ConfineCursorToWindow(DeviceIntPtr pDev, WindowPtr pWin, Bool generateEvents, Bo return; } #endif - pSprite->hotLimits = *REGION_EXTENTS( pScreen, &pWin->borderSize); + pSprite->hotLimits = *RegionExtents(&pWin->borderSize); pSprite->hotShape = wBoundingShape(pWin) ? &pWin->borderSize : NullRegion; CheckPhysLimits(pDev, pSprite->current, generateEvents, - confineToScreen, pScreen); + confineToScreen, pWin->drawable.pScreen); } } @@ -1123,7 +1128,7 @@ EnqueueEvent(InternalEvent *ev, DeviceIntPtr device) * updated yet. */ if (ev->any.type == ET_Motion) - ev->device_event.root = WindowTable[pSprite->hotPhys.pScreen->myNum]->drawable.id; + ev->device_event.root = pSprite->hotPhys.pScreen->root->drawable.id; eventinfo.event = ev; eventinfo.device = device; @@ -1134,10 +1139,8 @@ EnqueueEvent(InternalEvent *ev, DeviceIntPtr device) { #ifdef PANORAMIX if(!noPanoramiXExtension) { - event->root_x += panoramiXdataPtr[pSprite->screen->myNum].x - - panoramiXdataPtr[0].x; - event->root_y += panoramiXdataPtr[pSprite->screen->myNum].y - - panoramiXdataPtr[0].y; + event->root_x += pSprite->screen->x - screenInfo.screens[0]->x; + event->root_y += pSprite->screen->y - screenInfo.screens[0]->y; } #endif pSprite->hotPhys.x = event->root_x; @@ -1159,7 +1162,7 @@ EnqueueEvent(InternalEvent *ev, DeviceIntPtr device) eventlen = event->length; - qe = xalloc(sizeof(QdEventRec) + eventlen); + qe = malloc(sizeof(QdEventRec) + eventlen); if (!qe) return; qe->next = (QdEventPtr)NULL; @@ -1217,10 +1220,10 @@ PlayReleasedEvents(void) case ET_KeyRelease: case ET_ProximityIn: case ET_ProximityOut: - ev->root_x += panoramiXdataPtr[0].x - - panoramiXdataPtr[pDev->spriteInfo->sprite->screen->myNum].x; - ev->root_y += panoramiXdataPtr[0].y - - panoramiXdataPtr[pDev->spriteInfo->sprite->screen->myNum].y; + ev->root_x += screenInfo.screens[0]->x - + pDev->spriteInfo->sprite->screen->x; + ev->root_y += screenInfo.screens[0]->y - + pDev->spriteInfo->sprite->screen->y; break; default: break; @@ -1229,7 +1232,7 @@ PlayReleasedEvents(void) } #endif (*qe->device->public.processInputProc)(qe->event, qe->device); - xfree(qe); + free(qe); for (dev = inputInfo.devices; dev && dev->deviceGrab.sync.frozen; dev = dev->next) ; if (!dev) @@ -1339,7 +1342,7 @@ playmore: } else ConfineCursorToWindow(dev, - WindowTable[dev->spriteInfo->sprite->hotPhys.pScreen->myNum], + dev->spriteInfo->sprite->hotPhys.pScreen->root, TRUE, FALSE); PostNewCursor(dev); } @@ -1369,7 +1372,7 @@ ScreenRestructured (ScreenPtr pScreen) } else ConfineCursorToWindow(pDev, - WindowTable[pDev->spriteInfo->sprite->hotPhys.pScreen->myNum], + pDev->spriteInfo->sprite->hotPhys.pScreen->root, TRUE, FALSE); } } @@ -1408,12 +1411,8 @@ CheckGrabForSyncs(DeviceIntPtr thisDev, Bool thisMode, Bool otherMode) ComputeFreezes(); } -/* Only ever used if a grab is called on an attached slave device. */ -static int GrabPrivateKeyIndex; -static DevPrivateKey GrabPrivateKey = &GrabPrivateKeyIndex; - /** - * Save the device's master device in the devPrivates. This needs to be done + * Save the device's master device id. This needs to be done * if a client directly grabs a slave device that is attached to a master. For * the duration of the grab, the device is detached, ungrabbing re-attaches it * though. @@ -1424,35 +1423,28 @@ static DevPrivateKey GrabPrivateKey = &GrabPrivateKeyIndex; static void DetachFromMaster(DeviceIntPtr dev) { - intptr_t id; if (!dev->u.master) return; - id = dev->u.master->id; + dev->saved_master_id = dev->u.master->id; - dixSetPrivate(&dev->devPrivates, GrabPrivateKey, (void *)id); AttachDevice(NULL, dev, NULL); } static void ReattachToOldMaster(DeviceIntPtr dev) { - int id; - void *p; DeviceIntPtr master = NULL; if (IsMaster(dev)) return; - - p = dixLookupPrivate(&dev->devPrivates, GrabPrivateKey); - id = (intptr_t) p; /* silence gcc warnings */ - dixLookupDevice(&master, id, serverClient, DixUseAccess); + dixLookupDevice(&master, dev->saved_master_id, serverClient, DixUseAccess); if (master) { AttachDevice(serverClient, dev, master); - dixSetPrivate(&dev->devPrivates, GrabPrivateKey, NULL); + dev->saved_master_id = 0; } } @@ -1852,7 +1844,6 @@ int TryClientEvents (ClientPtr client, DeviceIntPtr dev, xEvent *pEvents, int count, Mask mask, Mask filter, GrabPtr grab) { - int i; int type; #ifdef DEBUG_EVENTS @@ -1919,7 +1910,6 @@ TryClientEvents (ClientPtr client, DeviceIntPtr dev, xEvent *pEvents, { xEvent release = *pEvents; release.u.u.type = KeyRelease; - release.u.u.sequenceNumber = client->sequence; WriteEventsToClient(client, 1, &release); #ifdef DEBUG_EVENTS ErrorF(" (plus fake core release for repeat)"); @@ -1940,7 +1930,6 @@ TryClientEvents (ClientPtr client, DeviceIntPtr dev, xEvent *pEvents, { deviceKeyButtonPointer release = *(deviceKeyButtonPointer *)pEvents; release.type = DeviceKeyRelease; - release.sequenceNumber = client->sequence; #ifdef DEBUG_EVENTS ErrorF(" (plus fake xi1 release for repeat)"); #endif @@ -1954,14 +1943,6 @@ TryClientEvents (ClientPtr client, DeviceIntPtr dev, xEvent *pEvents, } } - type &= 0177; - if (type != KeymapNotify) - { - /* all extension events must have a sequence number */ - for (i = 0; i < count; i++) - pEvents[i].u.u.sequenceNumber = client->sequence; - } - if (BitIsOn(criticalEvents, type)) { if (client->smart_priority < SMART_MAX_PRIORITY) @@ -2446,7 +2427,7 @@ DeliverDeviceEvents(WindowPtr pWin, InternalEvent *event, GrabPtr grab, FixUpEventFromWindow(dev, xi2, pWin, child, FALSE); deliveries = DeliverEventsToWindow(dev, pWin, xi2, 1, filter, grab); - xfree(xi2); + free(xi2); if (deliveries > 0) goto unwind; } else if (rc != BadMatch) @@ -2503,7 +2484,7 @@ DeliverDeviceEvents(WindowPtr pWin, InternalEvent *event, GrabPtr grab, } unwind: - xfree(xE); + free(xE); return deliveries; } @@ -2569,22 +2550,21 @@ static Bool PointInBorderSize(WindowPtr pWin, int x, int y) { BoxRec box; - SpritePtr pSprite = inputInfo.pointer->spriteInfo->sprite; - if(POINT_IN_REGION(pWin->drawable.pScreen, &pWin->borderSize, x, y, &box)) + if(RegionContainsPoint(&pWin->borderSize, x, y, &box)) return TRUE; #ifdef PANORAMIX if(!noPanoramiXExtension && XineramaSetWindowPntrs(inputInfo.pointer, pWin)) { + SpritePtr pSprite = inputInfo.pointer->spriteInfo->sprite; int i; for(i = 1; i < PanoramiXNumScreens; i++) { - if(POINT_IN_REGION(pSprite->screen, - &pSprite->windows[i]->borderSize, - x + panoramiXdataPtr[0].x - panoramiXdataPtr[i].x, - y + panoramiXdataPtr[0].y - panoramiXdataPtr[i].y, - &box)) + if(RegionContainsPoint(&pSprite->windows[i]->borderSize, + x + screenInfo.screens[0]->x - screenInfo.screens[i]->x, + y + screenInfo.screens[0]->y - screenInfo.screens[i]->y, + &box)) return TRUE; } } @@ -2628,10 +2608,9 @@ XYToWindow(DeviceIntPtr pDev, int x, int y) */ && (!wBoundingShape(pWin) || PointInBorderSize(pWin, x, y)) && (!wInputShape(pWin) || - POINT_IN_REGION(pWin->drawable.pScreen, - wInputShape(pWin), - x - pWin->drawable.x, - y - pWin->drawable.y, &box)) + RegionContainsPoint(wInputShape(pWin), + x - pWin->drawable.x, + y - pWin->drawable.y, &box)) #ifdef ROOTLESS /* In rootless mode windows may be offscreen, even when * they're in X's stack. (E.g. if the native window system @@ -2644,7 +2623,7 @@ XYToWindow(DeviceIntPtr pDev, int x, int y) if (pSprite->spriteTraceGood >= pSprite->spriteTraceSize) { pSprite->spriteTraceSize += 10; - pSprite->spriteTrace = xrealloc(pSprite->spriteTrace, + pSprite->spriteTrace = realloc(pSprite->spriteTrace, pSprite->spriteTraceSize*sizeof(WindowPtr)); } pSprite->spriteTrace[pSprite->spriteTraceGood++] = pWin; @@ -2778,17 +2757,15 @@ CheckMotion(DeviceEvent *ev, DeviceIntPtr pDev) /* Motion events entering DIX get translated to Screen 0 coordinates. Replayed events have already been translated since they've entered DIX before */ - ev->root_x += panoramiXdataPtr[pSprite->screen->myNum].x - - panoramiXdataPtr[0].x; - ev->root_y += panoramiXdataPtr[pSprite->screen->myNum].y - - panoramiXdataPtr[0].y; + ev->root_x += pSprite->screen->x - screenInfo.screens[0]->x; + ev->root_y += pSprite->screen->y - screenInfo.screens[0]->y; } else #endif { if (pSprite->hot.pScreen != pSprite->hotPhys.pScreen) { pSprite->hot.pScreen = pSprite->hotPhys.pScreen; - RootWindow(pDev) = WindowTable[pSprite->hot.pScreen->myNum]; + RootWindow(pDev) = pSprite->hot.pScreen->root; } } @@ -2871,7 +2848,7 @@ WindowsRestructured(void) #ifdef PANORAMIX /* This was added to support reconfiguration under Xdmx. The problem is - * that if the 0th screen (i.e., WindowTable[0]) is moved to an origin + * that if the 0th screen (i.e., screenInfo.screens[0]) is moved to an origin * other than 0,0, the information in the private sprite structure must * be updated accordingly, or XYToWindow (and other routines) will not * compute correctly. */ @@ -2900,10 +2877,10 @@ void ReinitializeRootWindow(WindowPtr win, int xoff, int yoff) pSprite->hotLimits.x2 -= xoff; pSprite->hotLimits.y2 -= yoff; - if (REGION_NOTEMPTY(pSprite->screen, &pSprite->Reg1)) - REGION_TRANSLATE(pSprite->screen, &pSprite->Reg1, xoff, yoff); - if (REGION_NOTEMPTY(pSprite->screen, &pSprite->Reg2)) - REGION_TRANSLATE(pSprite->screen, &pSprite->Reg2, xoff, yoff); + if (RegionNotEmpty(&pSprite->Reg1)) + RegionTranslate(&pSprite->Reg1, xoff, yoff); + if (RegionNotEmpty(&pSprite->Reg2)) + RegionTranslate(&pSprite->Reg2, xoff, yoff); /* FIXME: if we call ConfineCursorToWindow, must we do anything else? */ if ((grab = pDev->deviceGrab.grab) && grab->confineTo) { @@ -2914,7 +2891,7 @@ void ReinitializeRootWindow(WindowPtr win, int xoff, int yoff) } else ConfineCursorToWindow( pDev, - WindowTable[pSprite->hotPhys.pScreen->myNum], + pSprite->hotPhys.pScreen->root, TRUE, FALSE); } @@ -2949,7 +2926,7 @@ InitializeSprite(DeviceIntPtr pDev, WindowPtr pWin) { DeviceIntPtr it; - pDev->spriteInfo->sprite = (SpritePtr)xcalloc(1, sizeof(SpriteRec)); + pDev->spriteInfo->sprite = (SpritePtr)calloc(1, sizeof(SpriteRec)); if (!pDev->spriteInfo->sprite) FatalError("InitializeSprite: failed to allocate sprite struct"); @@ -2988,7 +2965,7 @@ InitializeSprite(DeviceIntPtr pDev, WindowPtr pWin) if (pWin) { pCursor = wCursor(pWin); - pSprite->spriteTrace = (WindowPtr *)xcalloc(1, 32*sizeof(WindowPtr)); + pSprite->spriteTrace = (WindowPtr *)calloc(1, 32*sizeof(WindowPtr)); if (!pSprite->spriteTrace) FatalError("Failed to allocate spriteTrace"); pSprite->spriteTraceSize = 32; @@ -3029,17 +3006,17 @@ InitializeSprite(DeviceIntPtr pDev, WindowPtr pWin) } #ifdef PANORAMIX if(!noPanoramiXExtension) { - pSprite->hotLimits.x1 = -panoramiXdataPtr[0].x; - pSprite->hotLimits.y1 = -panoramiXdataPtr[0].y; - pSprite->hotLimits.x2 = PanoramiXPixWidth - panoramiXdataPtr[0].x; - pSprite->hotLimits.y2 = PanoramiXPixHeight - panoramiXdataPtr[0].y; + pSprite->hotLimits.x1 = -screenInfo.screens[0]->x; + pSprite->hotLimits.y1 = -screenInfo.screens[0]->y; + pSprite->hotLimits.x2 = PanoramiXPixWidth - screenInfo.screens[0]->x; + pSprite->hotLimits.y2 = PanoramiXPixHeight - screenInfo.screens[0]->y; pSprite->physLimits = pSprite->hotLimits; pSprite->confineWin = NullWindow; pSprite->hotShape = NullRegion; pSprite->screen = pScreen; /* gotta UNINIT these someplace */ - REGION_NULL(pScreen, &pSprite->Reg1); - REGION_NULL(pScreen, &pSprite->Reg2); + RegionNull(&pSprite->Reg1); + RegionNull(&pSprite->Reg2); } #endif } @@ -3073,7 +3050,7 @@ UpdateSpriteForScreen(DeviceIntPtr pDev, ScreenPtr pScreen) pSprite = pDev->spriteInfo->sprite; - win = WindowTable[pScreen->myNum]; + win = pScreen->root; pSprite->hotPhys.pScreen = pScreen; pSprite->hot = pSprite->hotPhys; @@ -3099,10 +3076,10 @@ UpdateSpriteForScreen(DeviceIntPtr pDev, ScreenPtr pScreen) #ifdef PANORAMIX if(!noPanoramiXExtension) { - pSprite->hotLimits.x1 = -panoramiXdataPtr[0].x; - pSprite->hotLimits.y1 = -panoramiXdataPtr[0].y; - pSprite->hotLimits.x2 = PanoramiXPixWidth - panoramiXdataPtr[0].x; - pSprite->hotLimits.y2 = PanoramiXPixHeight - panoramiXdataPtr[0].y; + pSprite->hotLimits.x1 = -screenInfo.screens[0]->x; + pSprite->hotLimits.y1 = -screenInfo.screens[0]->y; + pSprite->hotLimits.x2 = PanoramiXPixWidth - screenInfo.screens[0]->x; + pSprite->hotLimits.y2 = PanoramiXPixHeight - screenInfo.screens[0]->y; pSprite->physLimits = pSprite->hotLimits; pSprite->screen = pScreen; } @@ -3135,10 +3112,8 @@ NewCurrentScreen(DeviceIntPtr pDev, ScreenPtr newScreen, int x, int y) pSprite->hotPhys.y = y; #ifdef PANORAMIX if(!noPanoramiXExtension) { - pSprite->hotPhys.x += panoramiXdataPtr[newScreen->myNum].x - - panoramiXdataPtr[0].x; - pSprite->hotPhys.y += panoramiXdataPtr[newScreen->myNum].y - - panoramiXdataPtr[0].y; + pSprite->hotPhys.x += newScreen->x - screenInfo.screens[0]->x; + pSprite->hotPhys.y += newScreen->y - screenInfo.screens[0]->y; if (newScreen != pSprite->screen) { pSprite->screen = newScreen; /* Make sure we tell the DDX to update its copy of the screen */ @@ -3146,23 +3121,22 @@ NewCurrentScreen(DeviceIntPtr pDev, ScreenPtr newScreen, int x, int y) XineramaConfineCursorToWindow(pDev, pSprite->confineWin, TRUE); else - XineramaConfineCursorToWindow(pDev, WindowTable[0], TRUE); + XineramaConfineCursorToWindow(pDev, screenInfo.screens[0]->root, TRUE); /* if the pointer wasn't confined, the DDX won't get told of the pointer warp so we reposition it here */ if(!syncEvents.playingEvents) (*pSprite->screen->SetCursorPosition)( pDev, pSprite->screen, - pSprite->hotPhys.x + panoramiXdataPtr[0].x - - panoramiXdataPtr[pSprite->screen->myNum].x, - pSprite->hotPhys.y + panoramiXdataPtr[0].y - - panoramiXdataPtr[pSprite->screen->myNum].y, FALSE); + pSprite->hotPhys.x + screenInfo.screens[0]->x - + pSprite->screen->x, + pSprite->hotPhys.y + screenInfo.screens[0]->y - + pSprite->screen->y, FALSE); } } else #endif if (newScreen != pSprite->hotPhys.pScreen) - ConfineCursorToWindow(pDev, WindowTable[newScreen->myNum], - TRUE, FALSE); + ConfineCursorToWindow(pDev, newScreen->root, TRUE, FALSE); } #ifdef PANORAMIX @@ -3174,32 +3148,29 @@ XineramaPointInWindowIsVisible( int y ) { - ScreenPtr pScreen = pWin->drawable.pScreen; BoxRec box; int i, xoff, yoff; if (!pWin->realized) return FALSE; - if (POINT_IN_REGION(pScreen, &pWin->borderClip, x, y, &box)) + if (RegionContainsPoint(&pWin->borderClip, x, y, &box)) return TRUE; if(!XineramaSetWindowPntrs(inputInfo.pointer, pWin)) return FALSE; - xoff = x + panoramiXdataPtr[0].x; - yoff = y + panoramiXdataPtr[0].y; + xoff = x + screenInfo.screens[0]->x; + yoff = y + screenInfo.screens[0]->y; for(i = 1; i < PanoramiXNumScreens; i++) { pWin = inputInfo.pointer->spriteInfo->sprite->windows[i]; - pScreen = pWin->drawable.pScreen; - x = xoff - panoramiXdataPtr[i].x; - y = yoff - panoramiXdataPtr[i].y; + x = xoff - screenInfo.screens[i]->x; + y = yoff - screenInfo.screens[i]->y; - if(POINT_IN_REGION(pScreen, &pWin->borderClip, x, y, &box) + if(RegionContainsPoint(&pWin->borderClip, x, y, &box) && (!wInputShape(pWin) || - POINT_IN_REGION(pWin->drawable.pScreen, - wInputShape(pWin), - x - pWin->drawable.x, - y - pWin->drawable.y, &box))) + RegionContainsPoint(wInputShape(pWin), + x - pWin->drawable.x, + y - pWin->drawable.y, &box))) return TRUE; } @@ -3237,9 +3208,9 @@ XineramaWarpPointer(ClientPtr client) winX = source->drawable.x; winY = source->drawable.y; - if(source == WindowTable[0]) { - winX -= panoramiXdataPtr[0].x; - winY -= panoramiXdataPtr[0].y; + if(source == screenInfo.screens[0]->root) { + winX -= screenInfo.screens[0]->x; + winY -= screenInfo.screens[0]->y; } if (x < winX + stuff->srcX || y < winY + stuff->srcY || @@ -3253,9 +3224,9 @@ XineramaWarpPointer(ClientPtr client) if (dest) { x = dest->drawable.x; y = dest->drawable.y; - if(dest == WindowTable[0]) { - x -= panoramiXdataPtr[0].x; - y -= panoramiXdataPtr[0].y; + if(dest == screenInfo.screens[0]->root) { + x -= screenInfo.screens[0]->x; + y -= screenInfo.screens[0]->y; } } @@ -3390,7 +3361,7 @@ ProcWarpPointer(ClientPtr client) static Bool BorderSizeNotEmpty(DeviceIntPtr pDev, WindowPtr pWin) { - if(REGION_NOTEMPTY(pDev->spriteInfo->sprite->hotPhys.pScreen, &pWin->borderSize)) + if(RegionNotEmpty(&pWin->borderSize)) return TRUE; #ifdef PANORAMIX @@ -3398,8 +3369,7 @@ BorderSizeNotEmpty(DeviceIntPtr pDev, WindowPtr pWin) int i; for(i = 1; i < PanoramiXNumScreens; i++) { - if(REGION_NOTEMPTY(pDev->spriteInfo->sprite->screen, - &pDev->spriteInfo->sprite->windows[i]->borderSize)) + if(RegionNotEmpty(&pDev->spriteInfo->sprite->windows[i]->borderSize)) return TRUE; } } @@ -3601,13 +3571,13 @@ CheckPassiveGrabsOnWindow( if (grabinfo->sync.state == FROZEN_NO_EVENT) { if (!grabinfo->sync.event) - grabinfo->sync.event = xcalloc(1, sizeof(InternalEvent)); + grabinfo->sync.event = calloc(1, sizeof(InternalEvent)); *grabinfo->sync.event = *event; grabinfo->sync.state = FROZEN_WITH_EVENT; } if (match & (XI_MATCH | XI2_MATCH)) - xfree(xE); /* on core match xE == &core */ + free(xE); /* on core match xE == &core */ return TRUE; } } @@ -3775,10 +3745,8 @@ DeliverFocusedEvent(DeviceIntPtr keybd, InternalEvent *event, WindowPtr window) } unwind: - if (xE) - xfree(xE); - if (xi2) - xfree(xi2); + free(xE); + free(xi2); return; } @@ -3952,16 +3920,14 @@ DeliverGrabbedEvent(InternalEvent *event, DeviceIntPtr thisDev, grabinfo->sync.state = FROZEN_WITH_EVENT; FreezeThaw(thisDev, TRUE); if (!grabinfo->sync.event) - grabinfo->sync.event = xcalloc(1, sizeof(InternalEvent)); + grabinfo->sync.event = calloc(1, sizeof(InternalEvent)); *grabinfo->sync.event = event->device_event; break; } } - if (xi) - xfree(xi); - if (xi2) - xfree(xi2); + free(xi); + free(xi2); } /* This function is used to set the key pressed or key released state - @@ -3971,13 +3937,7 @@ DeliverGrabbedEvent(InternalEvent *event, DeviceIntPtr thisDev, void FixKeyState (DeviceEvent *event, DeviceIntPtr keybd) { - int key, bit; - BYTE *kptr; - KeyClassPtr keyc = keybd->key; - - key = event->detail.key; - kptr = &keyc->down[key >> 3]; - bit = 1 << (key & 7); + int key = event->detail.key; if (event->type == ET_KeyPress) { DebugF("FixKeyState: Key %d %s\n",key, @@ -3985,9 +3945,9 @@ FixKeyState (DeviceEvent *event, DeviceIntPtr keybd) } if (event->type == ET_KeyPress) - *kptr |= bit; + set_key_down(keybd, key, KEY_PROCESSED); else if (event->type == ET_KeyRelease) - *kptr &= ~bit; + set_key_up(keybd, key, KEY_PROCESSED); else FatalError("Impossible keyboard event"); } @@ -4067,9 +4027,9 @@ OtherClientGone(pointer value, XID id) if (!(pWin->optional->otherClients = other->next)) CheckWindowOptionalNeed (pWin); } - xfree(other); + free(other); RecalculateDeliverableEvents(pWin); - return(Success); + return Success; } prev = other; } @@ -4139,7 +4099,7 @@ EventSelectForWindow(WindowPtr pWin, ClientPtr client, Mask mask) check = 0; if (!pWin->optional && !MakeWindowOptional (pWin)) return BadAlloc; - others = xalloc(sizeof(OtherClients)); + others = malloc(sizeof(OtherClients)); if (!others) return BadAlloc; others->mask = mask; @@ -4292,7 +4252,7 @@ CoreEnterLeaveEvent( xKeymapEvent ke; ClientPtr client = grab ? rClient(grab) : wClient(pWin); if (XaceHook(XACE_DEVICE_ACCESS, client, keybd, DixReadAccess)) - bzero((char *)&ke.map[0], 31); + memset((char *)&ke.map[0], 0, 31); else memmove((char *)&ke.map[0], (char *)&keybd->key->down[1], 31); @@ -4330,7 +4290,7 @@ DeviceEnterLeaveEvent( btlen = bytes_to_int32(btlen); len = sizeof(xXIEnterEvent) + btlen * 4; - event = xcalloc(1, len); + event = calloc(1, len); event->type = GenericEvent; event->extension = IReqCode; event->evtype = type; @@ -4380,7 +4340,7 @@ DeviceEnterLeaveEvent( } out: - xfree(event); + free(event); } void @@ -4402,7 +4362,7 @@ CoreFocusEvent(DeviceIntPtr dev, int type, int mode, int detail, WindowPtr pWin) xKeymapEvent ke; ClientPtr client = wClient(pWin); if (XaceHook(XACE_DEVICE_ACCESS, client, dev, DixReadAccess)) - bzero((char *)&ke.map[0], 31); + memset((char *)&ke.map[0], 0, 31); else memmove((char *)&ke.map[0], (char *)&dev->key->down[1], 31); @@ -4474,7 +4434,7 @@ SetInputFocus( /* It is a match error to try to set the input focus to an unviewable window. */ if(!focusWin->realized) - return(BadMatch); + return BadMatch; } rc = XaceHook(XACE_DEVICE_ACCESS, client, dev, DixSetFocusAccess); if (rc != Success) @@ -4511,7 +4471,7 @@ SetInputFocus( if (depth > focus->traceSize) { focus->traceSize = depth+1; - focus->trace = xrealloc(focus->trace, + focus->trace = realloc(focus->trace, focus->traceSize * sizeof(WindowPtr)); } focus->traceGood = depth; @@ -4671,7 +4631,7 @@ ProcChangeActivePointerGrab(ClientPtr client) if (rc != Success) { client->errorValue = stuff->cursor; - return (rc == BadValue) ? BadCursor : rc; + return rc; } } @@ -4794,7 +4754,7 @@ GrabDevice(ClientPtr client, DeviceIntPtr dev, if (rc != Success) { client->errorValue = curs; - return (rc == BadValue) ? BadCursor : rc; + return rc; } access_mode |= DixForceAccess; } @@ -4971,11 +4931,11 @@ ProcQueryPointer(ClientPtr client) #ifdef PANORAMIX if(!noPanoramiXExtension) { - rep.rootX += panoramiXdataPtr[0].x; - rep.rootY += panoramiXdataPtr[0].y; + rep.rootX += screenInfo.screens[0]->x; + rep.rootY += screenInfo.screens[0]->y; if(stuff->id == rep.root) { - rep.winX += panoramiXdataPtr[0].x; - rep.winY += panoramiXdataPtr[0].y; + rep.winX += screenInfo.screens[0]->x; + rep.winY += screenInfo.screens[0]->y; } } #endif @@ -4991,7 +4951,7 @@ ProcQueryPointer(ClientPtr client) WriteReplyToClient(client, sizeof(xQueryPointerReply), &rep); - return(Success); + return Success; } /** @@ -5021,7 +4981,7 @@ InitEvents(void) while (syncEvents.pending) { QdEventPtr next = syncEvents.pending->next; - xfree(syncEvents.pending); + free(syncEvents.pending); syncEvents.pending = next; } syncEvents.pendtail = &syncEvents.pending; @@ -5195,8 +5155,8 @@ ProcUngrabKey(ClientPtr client) tempGrab.next = NULL; if (!DeletePassiveGrabFromList(&tempGrab)) - return(BadAlloc); - return(Success); + return BadAlloc; + return Success; } /** @@ -5317,10 +5277,9 @@ ProcGrabButton(ClientPtr client) rc = dixLookupResourceByType((pointer *)&cursor, stuff->cursor, RT_CURSOR, client, DixUseAccess); if (rc != Success) - if (!cursor) { client->errorValue = stuff->cursor; - return (rc == BadValue) ? BadCursor : rc; + return rc; } access_mode |= DixForceAccess; } @@ -5391,8 +5350,8 @@ ProcUngrabButton(ClientPtr client) tempGrab.next = NULL; if (!DeletePassiveGrabFromList(&tempGrab)) - return(BadAlloc); - return(Success); + return BadAlloc; + return Success; } /** @@ -5583,7 +5542,7 @@ ProcRecolorCursor(ClientPtr client) if (rc != Success) { client->errorValue = stuff->cursor; - return (rc == BadValue) ? BadCursor : rc; + return rc; } pCursor->foreRed = stuff->foreRed; @@ -5606,7 +5565,7 @@ ProcRecolorCursor(ClientPtr client) ( *pscr->RecolorCursor)(PickPointer(client), pscr, pCursor, (pCursor == pSprite->current) && displayed); } - return (Success); + return Success; } /** @@ -5633,12 +5592,19 @@ WriteEventsToClient(ClientPtr pClient, int count, xEvent *events) int i, eventlength = sizeof(xEvent); + if (!pClient || pClient == serverClient || pClient->clientGone) + return; + + for (i = 0; i < count; i++) + if ((events[i].u.u.type & 0x7f) != KeymapNotify) + events[i].u.u.sequenceNumber = pClient->sequence; + /* Let XKB rewrite the state, as it depends on client preferences. */ XkbFilterEvents(pClient, count, events); #ifdef PANORAMIX if(!noPanoramiXExtension && - (panoramiXdataPtr[0].x || panoramiXdataPtr[0].y)) + (screenInfo.screens[0]->x || screenInfo.screens[0]->y)) { switch(events->u.u.type) { case MotionNotify: @@ -5655,13 +5621,13 @@ WriteEventsToClient(ClientPtr pClient, int count, xEvent *events) */ count = 1; /* should always be 1 */ memcpy(&eventCopy, events, sizeof(xEvent)); - eventCopy.u.keyButtonPointer.rootX += panoramiXdataPtr[0].x; - eventCopy.u.keyButtonPointer.rootY += panoramiXdataPtr[0].y; + eventCopy.u.keyButtonPointer.rootX += screenInfo.screens[0]->x; + eventCopy.u.keyButtonPointer.rootY += screenInfo.screens[0]->y; if(eventCopy.u.keyButtonPointer.event == eventCopy.u.keyButtonPointer.root) { - eventCopy.u.keyButtonPointer.eventX += panoramiXdataPtr[0].x; - eventCopy.u.keyButtonPointer.eventY += panoramiXdataPtr[0].y; + eventCopy.u.keyButtonPointer.eventX += screenInfo.screens[0]->x; + eventCopy.u.keyButtonPointer.eventY += screenInfo.screens[0]->y; } events = &eventCopy; break; @@ -5707,7 +5673,7 @@ WriteEventsToClient(ClientPtr pClient, int count, xEvent *events) if (eventlength > swapEventLen) { swapEventLen = eventlength; - swapEvent = Xrealloc(swapEvent, swapEventLen); + swapEvent = realloc(swapEvent, swapEventLen); if (!swapEvent) { FatalError("WriteEventsToClient: Out of memory.\n"); diff --git a/xserver/dix/extension.c b/xserver/dix/extension.c index 0740bfde2..9d20d544d 100644 --- a/xserver/dix/extension.c +++ b/xserver/dix/extension.c @@ -90,27 +90,32 @@ AddExtension(char *name, int NumEvents, int NumErrors, return((ExtensionEntry *) NULL); } - ext = xalloc(sizeof(ExtensionEntry)); + ext = calloc(sizeof (ExtensionEntry), 1); if (!ext) - return(NULL); + return NULL; + if (!dixAllocatePrivates(&ext->devPrivates, PRIVATE_EXTENSION)) { + free(ext); + return NULL; + } buflen = strlen(name) + 1; - ext->name = xalloc(buflen); + ext->name = malloc(buflen); ext->num_aliases = 0; ext->aliases = (char **)NULL; - ext->devPrivates = NULL; if (!ext->name) { - xfree(ext); + dixFreePrivates(ext->devPrivates, PRIVATE_EXTENSION); + free(ext); return((ExtensionEntry *) NULL); } strlcpy(ext->name, name, buflen); i = NumExtensions; - newexts = (ExtensionEntry **) xrealloc(extensions, + newexts = (ExtensionEntry **) realloc(extensions, (i + 1) * sizeof(ExtensionEntry *)); if (!newexts) { - xfree(ext->name); - xfree(ext); + free(ext->name); + dixFreePrivates(ext->devPrivates, PRIVATE_EXTENSION); + free(ext); return((ExtensionEntry *) NULL); } NumExtensions++; @@ -146,7 +151,7 @@ AddExtension(char *name, int NumEvents, int NumErrors, } RegisterExtensionNames(ext); - return(ext); + return ext; } Bool AddExtensionAlias(char *alias, ExtensionEntry *ext) @@ -157,13 +162,13 @@ Bool AddExtensionAlias(char *alias, ExtensionEntry *ext) if (!ext) return FALSE ; - aliases = (char **)xrealloc(ext->aliases, + aliases = (char **)realloc(ext->aliases, (ext->num_aliases + 1) * sizeof(char *)); if (!aliases) return FALSE; ext->aliases = aliases; buflen = strlen(alias) + 1; - name = xalloc(buflen); + name = malloc(buflen); if (!name) return FALSE; strlcpy(name, alias, buflen); @@ -253,14 +258,14 @@ CloseDownExtensions(void) if (extensions[i]->CloseDown) extensions[i]->CloseDown(extensions[i]); NumExtensions = i; - xfree(extensions[i]->name); + free(extensions[i]->name); for (j = extensions[i]->num_aliases; --j >= 0;) - xfree(extensions[i]->aliases[j]); - xfree(extensions[i]->aliases); - dixFreePrivates(extensions[i]->devPrivates); - xfree(extensions[i]); + free(extensions[i]->aliases[j]); + free(extensions[i]->aliases); + dixFreePrivates(extensions[i]->devPrivates, PRIVATE_EXTENSION); + free(extensions[i]); } - xfree(extensions); + free(extensions); extensions = (ExtensionEntry **)NULL; lastEvent = EXTENSION_EVENT_BASE; lastError = FirstExtensionError; @@ -297,7 +302,7 @@ ProcQueryExtension(ClientPtr client) } } WriteReplyToClient(client, sizeof(xQueryExtensionReply), &reply); - return(client->noClientException); + return Success; } int @@ -332,9 +337,9 @@ ProcListExtensions(ClientPtr client) total_length += strlen(extensions[i]->aliases[j]) + 1; } reply.length = bytes_to_int32(total_length); - buffer = bufptr = xalloc(total_length); + buffer = bufptr = malloc(total_length); if (!buffer) - return(BadAlloc); + return BadAlloc; for (i=0; i<NumExtensions; i++) { int len; @@ -356,7 +361,7 @@ ProcListExtensions(ClientPtr client) if (reply.length) { WriteToClient(client, total_length, buffer); - xfree(buffer); + free(buffer); } - return(client->noClientException); + return Success; } diff --git a/xserver/dix/gc.c b/xserver/dix/gc.c index 649016595..6da243e01 100644 --- a/xserver/dix/gc.c +++ b/xserver/dix/gc.c @@ -60,13 +60,13 @@ SOFTWARE. #include "dixfontstr.h" #include "scrnintstr.h" #include "region.h" +#include "dixstruct.h" #include "privates.h" #include "dix.h" #include "xace.h" #include <assert.h> -extern XID clientErrorValue; extern FontPtr defaultFont; static Bool CreateDefaultTile(GCPtr pGC); @@ -82,78 +82,55 @@ ValidateGC(DrawablePtr pDraw, GC *pGC) } -/* dixChangeGC(client, pGC, mask, pC32, pUnion) - * - * This function was created as part of the Security extension - * implementation. The client performing the gc change must be passed so - * that access checks can be performed on any tiles, stipples, or fonts - * that are specified. ddxen can call this too; they should normally - * pass NullClient for the client since any access checking should have +/* + * ChangeGC/ChangeGCXIDs: + * + * The client performing the gc change must be passed so that access + * checks can be performed on any tiles, stipples, or fonts that are + * specified. ddxen can call this too; they should normally pass + * NullClient for the client since any access checking should have * already been done at a higher level. * - * Since we had to create a new function anyway, we decided to change the - * way the list of gc values is passed to eliminate the compiler warnings - * caused by the DoChangeGC interface. You can pass the values via pC32 - * or pUnion, but not both; one of them must be NULL. If you don't need - * to pass any pointers, you can use either one: + * If you have any XIDs, you must use ChangeGCXIDs: * - * example calling dixChangeGC using pC32 parameter - * * CARD32 v[2]; - * v[0] = foreground; - * v[1] = background; - * dixChangeGC(client, pGC, GCForeground|GCBackground, v, NULL); - * - * example calling dixChangeGC using pUnion parameter; - * same effect as above - * - * ChangeGCVal v[2]; - * v[0].val = foreground; - * v[1].val = background; - * dixChangeGC(client, pGC, GCForeground|GCBackground, NULL, v); + * v[0] = FillTiled; + * v[1] = pid; + * ChangeGCXIDs(client, pGC, GCFillStyle|GCTile, v); * - * However, if you need to pass a pointer to a pixmap or font, you MUST - * use the pUnion parameter. + * However, if you need to pass a pointer to a pixmap or font, you must + * use ChangeGC: * - * example calling dixChangeGC passing pointers in the value list - * v[1].ptr is a pointer to a pixmap - * * ChangeGCVal v[2]; * v[0].val = FillTiled; * v[1].ptr = pPixmap; - * dixChangeGC(client, pGC, GCFillStyle|GCTile, NULL, v); - * - * Note: we could have gotten by with just the pUnion parameter, but on - * 64 bit machines that would have forced us to copy the value list that - * comes in the ChangeGC request. + * ChangeGC(client, pGC, GCFillStyle|GCTile, v); * - * Ideally, we'd change all the DoChangeGC calls to dixChangeGC, but this - * is far too many changes to consider at this time, so we've only - * changed the ones that caused compiler warnings. New code should use - * dixChangeGC. - * - * dpw + * If you have neither XIDs nor pointers, you can use either function, + * but ChangeGC will do less work. + * + * ChangeGCVal v[2]; + * v[0].val = foreground; + * v[1].val = background; + * ChangeGC(client, pGC, GCForeground|GCBackground, v); */ #define NEXTVAL(_type, _var) { \ - if (pC32) _var = (_type)*pC32++; \ - else { \ _var = (_type)(pUnion->val); pUnion++; \ - } \ } #define NEXT_PTR(_type, _var) { \ - assert(pUnion); _var = (_type)pUnion->ptr; pUnion++; } + _var = (_type)pUnion->ptr; pUnion++; } int -dixChangeGC(ClientPtr client, GC *pGC, BITS32 mask, CARD32 *pC32, ChangeGCValPtr pUnion) +ChangeGC(ClientPtr client, GC *pGC, BITS32 mask, ChangeGCValPtr pUnion) { BITS32 index2; - int rc, error = 0; + int error = 0; PixmapPtr pPixmap; BITS32 maskQ; - assert( (pC32 && !pUnion) || (!pC32 && pUnion) ); + assert(pUnion); pGC->serialNumber |= GC_CHANGE_SERIAL_BIT; maskQ = mask; /* save these for when we walk the GCque */ @@ -172,7 +149,8 @@ dixChangeGC(ClientPtr client, GC *pGC, BITS32 mask, CARD32 *pC32, ChangeGCValPtr pGC->alu = newalu; else { - clientErrorValue = newalu; + if (client) + client->errorValue = newalu; error = BadValue; } break; @@ -205,7 +183,8 @@ dixChangeGC(ClientPtr client, GC *pGC, BITS32 mask, CARD32 *pC32, ChangeGCValPtr pGC->lineStyle = newlinestyle; else { - clientErrorValue = newlinestyle; + if (client) + client->errorValue = newlinestyle; error = BadValue; } break; @@ -218,7 +197,8 @@ dixChangeGC(ClientPtr client, GC *pGC, BITS32 mask, CARD32 *pC32, ChangeGCValPtr pGC->capStyle = newcapstyle; else { - clientErrorValue = newcapstyle; + if (client) + client->errorValue = newcapstyle; error = BadValue; } break; @@ -231,7 +211,8 @@ dixChangeGC(ClientPtr client, GC *pGC, BITS32 mask, CARD32 *pC32, ChangeGCValPtr pGC->joinStyle = newjoinstyle; else { - clientErrorValue = newjoinstyle; + if (client) + client->errorValue = newjoinstyle; error = BadValue; } break; @@ -244,7 +225,8 @@ dixChangeGC(ClientPtr client, GC *pGC, BITS32 mask, CARD32 *pC32, ChangeGCValPtr pGC->fillStyle = newfillstyle; else { - clientErrorValue = newfillstyle; + if (client) + client->errorValue = newfillstyle; error = BadValue; } break; @@ -257,84 +239,43 @@ dixChangeGC(ClientPtr client, GC *pGC, BITS32 mask, CARD32 *pC32, ChangeGCValPtr pGC->fillRule = newfillrule; else { - clientErrorValue = newfillrule; + if (client) + client->errorValue = newfillrule; error = BadValue; } break; } case GCTile: - { - XID newpix = 0; - if (pUnion) + NEXT_PTR(PixmapPtr, pPixmap); + if ((pPixmap->drawable.depth != pGC->depth) || + (pPixmap->drawable.pScreen != pGC->pScreen)) { - NEXT_PTR(PixmapPtr, pPixmap); - rc = Success; + error = BadMatch; } else { - NEXTVAL(XID, newpix); - rc = dixLookupResourceByType((pointer *)&pPixmap, newpix, - RT_PIXMAP, client, DixReadAccess); - } - if (rc == Success) - { - if ((pPixmap->drawable.depth != pGC->depth) || - (pPixmap->drawable.pScreen != pGC->pScreen)) - { - error = BadMatch; - } - else - { - pPixmap->refcnt++; - if (!pGC->tileIsPixel) - (* pGC->pScreen->DestroyPixmap)(pGC->tile.pixmap); - pGC->tileIsPixel = FALSE; - pGC->tile.pixmap = pPixmap; - } - } - else - { - clientErrorValue = newpix; - error = (rc == BadValue) ? BadPixmap : rc; + pPixmap->refcnt++; + if (!pGC->tileIsPixel) + (* pGC->pScreen->DestroyPixmap)(pGC->tile.pixmap); + pGC->tileIsPixel = FALSE; + pGC->tile.pixmap = pPixmap; } break; - } case GCStipple: - { - XID newstipple = 0; - if (pUnion) + NEXT_PTR(PixmapPtr, pPixmap); + if ((pPixmap->drawable.depth != 1) || + (pPixmap->drawable.pScreen != pGC->pScreen)) { - NEXT_PTR(PixmapPtr, pPixmap); - rc = Success; - } - else - { - NEXTVAL(XID, newstipple) - rc = dixLookupResourceByType((pointer *)&pPixmap, newstipple, - RT_PIXMAP, client, DixReadAccess); - } - if (rc == Success) - { - if ((pPixmap->drawable.depth != 1) || - (pPixmap->drawable.pScreen != pGC->pScreen)) - { - error = BadMatch; - } - else - { - pPixmap->refcnt++; - if (pGC->stipple) - (* pGC->pScreen->DestroyPixmap)(pGC->stipple); - pGC->stipple = pPixmap; - } + error = BadMatch; } else { - clientErrorValue = newstipple; - error = (rc == BadValue) ? BadPixmap : rc; + pPixmap->refcnt++; + if (pGC->stipple) + (* pGC->pScreen->DestroyPixmap)(pGC->stipple); + pGC->stipple = pPixmap; } break; - } case GCTileStipXOrigin: NEXTVAL(INT16, pGC->patOrg.x); break; @@ -344,30 +285,11 @@ dixChangeGC(ClientPtr client, GC *pGC, BITS32 mask, CARD32 *pC32, ChangeGCValPtr case GCFont: { FontPtr pFont; - XID newfont = 0; - if (pUnion) - { - NEXT_PTR(FontPtr, pFont); - rc = Success; - } - else - { - NEXTVAL(XID, newfont) - rc = dixLookupResourceByType((pointer *)&pFont, newfont, - RT_FONT, client, DixUseAccess); - } - if (rc == Success) - { - pFont->refcnt++; - if (pGC->font) - CloseFont(pGC->font, (Font)0); - pGC->font = pFont; - } - else - { - clientErrorValue = newfont; - error = (rc == BadValue) ? BadFont : rc; - } + NEXT_PTR(FontPtr, pFont); + pFont->refcnt++; + if (pGC->font) + CloseFont(pGC->font, (Font)0); + pGC->font = pFont; break; } case GCSubwindowMode: @@ -378,7 +300,8 @@ dixChangeGC(ClientPtr client, GC *pGC, BITS32 mask, CARD32 *pC32, ChangeGCValPtr pGC->subWindowMode = newclipmode; else { - clientErrorValue = newclipmode; + if (client) + client->errorValue = newclipmode; error = BadValue; } break; @@ -391,7 +314,8 @@ dixChangeGC(ClientPtr client, GC *pGC, BITS32 mask, CARD32 *pC32, ChangeGCValPtr pGC->graphicsExposures = newge; else { - clientErrorValue = newge; + if (client) + client->errorValue = newge; error = BadValue; } break; @@ -403,53 +327,20 @@ dixChangeGC(ClientPtr client, GC *pGC, BITS32 mask, CARD32 *pC32, ChangeGCValPtr NEXTVAL(INT16, pGC->clipOrg.y); break; case GCClipMask: - { - Pixmap pid = 0; - int clipType = 0; - - if (pUnion) - { - NEXT_PTR(PixmapPtr, pPixmap); - } - else - { - NEXTVAL(Pixmap, pid) - if (pid == None) - { - clipType = CT_NONE; - pPixmap = NullPixmap; - } - else { - rc = dixLookupResourceByType((pointer *)&pPixmap, pid, - RT_PIXMAP, client, - DixReadAccess); - if (rc != Success) { - clientErrorValue = pid; - error = (rc == BadValue) ? BadPixmap : rc; - } - } - } - + NEXT_PTR(PixmapPtr, pPixmap); if (pPixmap) { if ((pPixmap->drawable.depth != 1) || (pPixmap->drawable.pScreen != pGC->pScreen)) { error = BadMatch; + break; } - else - { - clipType = CT_PIXMAP; - pPixmap->refcnt++; - } - } - if(error == Success) - { - (*pGC->funcs->ChangeClip)(pGC, clipType, - (pointer)pPixmap, 0); + pPixmap->refcnt++; } + (*pGC->funcs->ChangeClip)(pGC, pPixmap ? CT_PIXMAP : CT_NONE, + (pointer)pPixmap, 0); break; - } case GCDashOffset: NEXTVAL(INT16, pGC->dashOffset); break; @@ -461,7 +352,7 @@ dixChangeGC(ClientPtr client, GC *pGC, BITS32 mask, CARD32 *pC32, ChangeGCValPtr { if (pGC->dash != DefaultDash) { - xfree(pGC->dash); + free(pGC->dash); pGC->numInDashList = 2; pGC->dash = DefaultDash; } @@ -470,11 +361,11 @@ dixChangeGC(ClientPtr client, GC *pGC, BITS32 mask, CARD32 *pC32, ChangeGCValPtr { unsigned char *dash; - dash = xalloc(2 * sizeof(unsigned char)); + dash = malloc(2 * sizeof(unsigned char)); if (dash) { if (pGC->dash != DefaultDash) - xfree(pGC->dash); + free(pGC->dash); pGC->numInDashList = 2; pGC->dash = dash; dash[0] = newdash; @@ -485,7 +376,8 @@ dixChangeGC(ClientPtr client, GC *pGC, BITS32 mask, CARD32 *pC32, ChangeGCValPtr } else { - clientErrorValue = newdash; + if (client) + client->errorValue = newdash; error = BadValue; } break; @@ -498,13 +390,15 @@ dixChangeGC(ClientPtr client, GC *pGC, BITS32 mask, CARD32 *pC32, ChangeGCValPtr pGC->arcMode = newarcmode; else { - clientErrorValue = newarcmode; + if (client) + client->errorValue = newarcmode; error = BadValue; } break; } default: - clientErrorValue = maskQ; + if (client) + client->errorValue = maskQ; error = BadValue; break; } @@ -525,45 +419,51 @@ dixChangeGC(ClientPtr client, GC *pGC, BITS32 mask, CARD32 *pC32, ChangeGCValPtr #undef NEXTVAL #undef NEXT_PTR -/* Publically defined entry to ChangeGC. Just calls dixChangeGC and tells - * it that all of the entries are constants or IDs */ -int -ChangeGC(GC *pGC, BITS32 mask, XID *pval) -{ - return (dixChangeGC(NullClient, pGC, mask, pval, NULL)); -} +static const struct { + BITS32 mask; + RESTYPE type; + Mask access_mode; +} xidfields[] = { + { GCTile, RT_PIXMAP, DixReadAccess }, + { GCStipple, RT_PIXMAP, DixReadAccess }, + { GCFont, RT_FONT, DixUseAccess }, + { GCClipMask, RT_PIXMAP, DixReadAccess }, +}; -/* DoChangeGC(pGC, mask, pval, fPointer) - mask is a set of bits indicating which values to change. - pval contains an appropriate value for each mask. - fPointer is true if the values for tiles, stipples, fonts or clipmasks - are pointers instead of IDs. Note: if you are passing pointers you - MUST declare the array of values as type pointer! Other data types - may not be large enough to hold pointers on some machines. Yes, - this means you have to cast to (XID *) when you pass the array to - DoChangeGC. Similarly, if you are not passing pointers (fPointer = 0) you - MUST declare the array as type XID (not unsigned long!), or again the wrong - size data type may be used. To avoid this cruftiness, use dixChangeGC - above. - - if there is an error, the value is marked as changed - anyway, which is probably wrong, but infrequent. - -NOTE: - all values sent over the protocol for ChangeGC requests are -32 bits long -*/ int -DoChangeGC(GC *pGC, BITS32 mask, XID *pval, int fPointer) +ChangeGCXIDs(ClientPtr client, GC *pGC, BITS32 mask, CARD32 *pC32) { - if (fPointer) - /* XXX might be a problem on 64 bit big-endian servers */ - return dixChangeGC(NullClient, pGC, mask, NULL, (ChangeGCValPtr)pval); - else - return dixChangeGC(NullClient, pGC, mask, pval, NULL); + ChangeGCVal vals[GCLastBit + 1]; + int i; + if (mask & ~GCAllBits) + { + client->errorValue = mask; + return BadValue; + } + for (i = Ones(mask); i--; ) + vals[i].val = pC32[i]; + for (i = 0; i < sizeof(xidfields) / sizeof(*xidfields); ++i) + { + int offset, rc; + if (!(mask & xidfields[i].mask)) + continue; + offset = Ones(mask & (xidfields[i].mask - 1)); + if (xidfields[i].mask == GCClipMask && vals[offset].val == None) + { + vals[offset].ptr = NullPixmap; + continue; + } + rc = dixLookupResourceByType(&vals[offset].ptr, vals[offset].val, + xidfields[i].type, client, xidfields[i].access_mode); + if (rc != Success) + { + client->errorValue = vals[offset].val; + return rc; + } + } + return ChangeGC(client, pGC, mask, vals); } - /* CreateGC(pDrawable, mask, pval, pStatus) creates a default GC for the given drawable, using mask to fill in any non-default values. @@ -579,7 +479,7 @@ CreateGC(DrawablePtr pDrawable, BITS32 mask, XID *pval, int *pStatus, { GCPtr pGC; - pGC = xalloc(sizeof(GC)); + pGC = dixAllocateObjectWithPrivates(GC, PRIVATE_GC); if (!pGC) { *pStatus = BadAlloc; @@ -592,7 +492,6 @@ CreateGC(DrawablePtr pDrawable, BITS32 mask, XID *pval, int *pStatus, pGC->planemask = ~0; pGC->serialNumber = GC_CHANGE_SERIAL_BIT; pGC->funcs = 0; - pGC->devPrivates = NULL; pGC->fgPixel = 0; pGC->bgPixel = 1; pGC->lineWidth = 0; @@ -637,17 +536,20 @@ CreateGC(DrawablePtr pDrawable, BITS32 mask, XID *pval, int *pStatus, pGC->stipple = pGC->pScreen->PixmapPerDepth[0]; pGC->stipple->refcnt++; + /* this is not a scratch GC */ + pGC->scratch_inuse = FALSE; + /* security creation/labeling check */ *pStatus = XaceHook(XACE_RESOURCE_ACCESS, client, gcid, RT_GC, pGC, RT_NONE, NULL, DixCreateAccess|DixSetAttrAccess); if (*pStatus != Success) goto out; - pGC->stateChanges = (1 << (GCLastBit+1)) - 1; + pGC->stateChanges = GCAllBits; if (!(*pGC->pScreen->CreateGC)(pGC)) *pStatus = BadAlloc; else if (mask) - *pStatus = ChangeGC(pGC, mask, pval); + *pStatus = ChangeGCXIDs(client, pGC, mask, pval); else *pStatus = Success; @@ -660,13 +562,13 @@ out: pGC = (GCPtr)NULL; } - return (pGC); + return pGC; } static Bool CreateDefaultTile (GCPtr pGC) { - XID tmpval[3]; + ChangeGCVal tmpval[3]; PixmapPtr pTile; GCPtr pgcScratch; xRectangle rect; @@ -687,11 +589,10 @@ CreateDefaultTile (GCPtr pGC) FreeScratchGC(pgcScratch); return FALSE; } - tmpval[0] = GXcopy; - tmpval[1] = pGC->tile.pixel; - tmpval[2] = FillSolid; - (void)ChangeGC(pgcScratch, GCFunction | GCForeground | GCFillStyle, - tmpval); + tmpval[0].val = GXcopy; + tmpval[1].val = pGC->tile.pixel; + tmpval[2].val = FillSolid; + (void)ChangeGC(NullClient, pgcScratch, GCFunction | GCForeground | GCFillStyle, tmpval); ValidateGC((DrawablePtr)pTile, pgcScratch); rect.x = 0; rect.y = 0; @@ -819,7 +720,7 @@ CopyGC(GC *pgcSrc, GC *pgcDst, BITS32 mask) { if (pgcDst->dash != DefaultDash) { - xfree(pgcDst->dash); + free(pgcDst->dash); pgcDst->numInDashList = pgcSrc->numInDashList; pgcDst->dash = pgcSrc->dash; } @@ -829,11 +730,11 @@ CopyGC(GC *pgcSrc, GC *pgcDst, BITS32 mask) unsigned char *dash; unsigned int i; - dash = xalloc(pgcSrc->numInDashList * sizeof(unsigned char)); + dash = malloc(pgcSrc->numInDashList * sizeof(unsigned char)); if (dash) { if (pgcDst->dash != DefaultDash) - xfree(pgcDst->dash); + free(pgcDst->dash); pgcDst->numInDashList = pgcSrc->numInDashList; pgcDst->dash = dash; for (i=0; i<pgcSrc->numInDashList; i++) @@ -847,9 +748,7 @@ CopyGC(GC *pgcSrc, GC *pgcDst, BITS32 mask) pgcDst->arcMode = pgcSrc->arcMode; break; default: - clientErrorValue = maskQ; - error = BadValue; - break; + FatalError ("CopyGC: Unhandled mask!\n"); } } if (pgcDst->fillStyle == FillTiled && pgcDst->tileIsPixel) @@ -884,10 +783,9 @@ FreeGC(pointer value, XID gid) (*pGC->funcs->DestroyGC) (pGC); if (pGC->dash != DefaultDash) - xfree(pGC->dash); - dixFreePrivates(pGC->devPrivates); - xfree(pGC); - return(Success); + free(pGC->dash); + dixFreeObjectWithPrivates(pGC, PRIVATE_GC); + return Success; } /* CreateScratchGC(pScreen, depth) @@ -908,7 +806,7 @@ CreateScratchGC(ScreenPtr pScreen, unsigned depth) { GCPtr pGC; - pGC = xalloc(sizeof(GC)); + pGC = dixAllocateObjectWithPrivates(GC, PRIVATE_GC); if (!pGC) return (GCPtr)NULL; @@ -917,7 +815,6 @@ CreateScratchGC(ScreenPtr pScreen, unsigned depth) pGC->alu = GXcopy; /* dst <- src */ pGC->planemask = ~0; pGC->serialNumber = 0; - pGC->devPrivates = NULL; pGC->fgPixel = 0; pGC->bgPixel = 1; pGC->lineWidth = 0; @@ -947,7 +844,10 @@ CreateScratchGC(ScreenPtr pScreen, unsigned depth) pGC->lastWinOrg.x = 0; pGC->lastWinOrg.y = 0; - pGC->stateChanges = (1 << (GCLastBit+1)) - 1; + /* scratch GCs in the GCperDepth pool start off unused */ + pGC->scratch_inuse = FALSE; + + pGC->stateChanges = GCAllBits; if (!(*pScreen->CreateGC)(pGC)) { FreeGC(pGC, (XID)0); @@ -967,8 +867,10 @@ FreeGCperDepth(int screenNum) ppGC = pScreen->GCperDepth; for (i = 0; i <= pScreen->numDepths; i++) + { (void)FreeGC(ppGC[i], (XID)0); - pScreen->rgf = ~0L; + ppGC[i] = NULL; + } } @@ -981,7 +883,6 @@ CreateGCperDepth(int screenNum) GCPtr *ppGC; pScreen = screenInfo.screens[screenNum]; - pScreen->rgf = 0; ppGC = pScreen->GCperDepth; /* do depth 1 separately because it's not included in list */ if (!(ppGC[0] = CreateScratchGC(pScreen, 1))) @@ -1009,7 +910,7 @@ Bool CreateDefaultStipple(int screenNum) { ScreenPtr pScreen; - XID tmpval[3]; + ChangeGCVal tmpval[3]; xRectangle rect; CARD16 w, h; GCPtr pgcScratch; @@ -1023,14 +924,16 @@ CreateDefaultStipple(int screenNum) (*pScreen->CreatePixmap)(pScreen, w, h, 1, 0))) return FALSE; /* fill stipple with 1 */ - tmpval[0] = GXcopy; tmpval[1] = 1; tmpval[2] = FillSolid; + tmpval[0].val = GXcopy; + tmpval[1].val = 1; + tmpval[2].val = FillSolid; pgcScratch = GetScratchGC(1, pScreen); if (!pgcScratch) { (*pScreen->DestroyPixmap)(pScreen->PixmapPerDepth[0]); return FALSE; } - (void)ChangeGC(pgcScratch, GCFunction|GCForeground|GCFillStyle, tmpval); + (void)ChangeGC(NullClient, pgcScratch, GCFunction|GCForeground|GCFillStyle, tmpval); ValidateGC((DrawablePtr)pScreen->PixmapPerDepth[0], pgcScratch); rect.x = 0; rect.y = 0; @@ -1063,15 +966,14 @@ SetDashes(GCPtr pGC, unsigned offset, unsigned ndash, unsigned char *pdash) if (!*p++) { /* dash segment must be > 0 */ - clientErrorValue = 0; return BadValue; } } if (ndash & 1) - p = xalloc(2 * ndash * sizeof(unsigned char)); + p = malloc(2 * ndash * sizeof(unsigned char)); else - p = xalloc(ndash * sizeof(unsigned char)); + p = malloc(ndash * sizeof(unsigned char)); if (!p) return BadAlloc; @@ -1084,7 +986,7 @@ SetDashes(GCPtr pGC, unsigned offset, unsigned ndash, unsigned char *pdash) } if (pGC->dash != DefaultDash) - xfree(pGC->dash); + free(pGC->dash); pGC->numInDashList = ndash; pGC->dash = p; if (ndash & 1) @@ -1164,9 +1066,9 @@ SetClipRects(GCPtr pGC, int xOrigin, int yOrigin, int nrects, newct = VerifyRectOrder(nrects, prects, ordering); if (newct < 0) - return(BadMatch); + return BadMatch; size = nrects * sizeof(xRectangle); - prectsNew = xalloc(size); + prectsNew = malloc(size); if (!prectsNew && size) return BadAlloc; @@ -1199,12 +1101,11 @@ GetScratchGC(unsigned depth, ScreenPtr pScreen) GCPtr pGC; for (i=0; i<=pScreen->numDepths; i++) - if ( pScreen->GCperDepth[i]->depth == depth && - !(pScreen->rgf & (1L << (i+1))) - ) + { + pGC = pScreen->GCperDepth[i]; + if (pGC && pGC->depth == depth && !pGC->scratch_inuse) { - pScreen->rgf |= (1L << (i+1)); - pGC = (pScreen->GCperDepth[i]); + pGC->scratch_inuse = TRUE; pGC->alu = GXcopy; pGC->planemask = ~0; @@ -1226,9 +1127,10 @@ GetScratchGC(unsigned depth, ScreenPtr pScreen) pGC->clipOrg.y = 0; if (pGC->clientClipType != CT_NONE) (*pGC->funcs->ChangeClip) (pGC, CT_NONE, NULL, 0); - pGC->stateChanges = (1 << (GCLastBit+1)) - 1; + pGC->stateChanges = GCAllBits; return pGC; } + } /* if we make it this far, need to roll our own */ pGC = CreateScratchGC(pScreen, depth); if (pGC) @@ -1244,16 +1146,8 @@ mark it as available. void FreeScratchGC(GCPtr pGC) { - ScreenPtr pScreen = pGC->pScreen; - int i; - - for (i=0; i<=pScreen->numDepths; i++) - { - if ( pScreen->GCperDepth[i] == pGC) - { - pScreen->rgf &= ~(1L << (i+1)); - return; - } - } - (void)FreeGC(pGC, (GContext)0); + if (pGC->scratch_inuse) + pGC->scratch_inuse = FALSE; + else + FreeGC(pGC, (GContext)0); } diff --git a/xserver/dix/getevents.c b/xserver/dix/getevents.c index 197deb4fb..e5134d34b 100644 --- a/xserver/dix/getevents.c +++ b/xserver/dix/getevents.c @@ -33,6 +33,7 @@ #include <X11/X.h> #include <X11/keysym.h> #include <X11/Xproto.h> +#include <math.h> #include "misc.h" #include "resource.h" @@ -56,6 +57,7 @@ #include <X11/extensions/XI.h> #include <X11/extensions/XIproto.h> +#include <pixman.h> #include "exglobals.h" #include "exevents.h" #include "exglobals.h" @@ -89,21 +91,52 @@ GetMotionHistorySize(void) } void +set_button_down(DeviceIntPtr pDev, int button, int type) +{ + if (type == BUTTON_PROCESSED) + SetBit(pDev->button->down, button); + else + SetBit(pDev->button->postdown, button); +} + +void +set_button_up(DeviceIntPtr pDev, int button, int type) +{ + if (type == BUTTON_PROCESSED) + ClearBit(pDev->button->down, button); + else + ClearBit(pDev->button->postdown, button); +} + +Bool +button_is_down(DeviceIntPtr pDev, int button, int type) +{ + int ret = 0; + + if (type & BUTTON_PROCESSED) + ret |= !!BitIsOn(pDev->button->down, button); + if (type & BUTTON_POSTED) + ret |= !!BitIsOn(pDev->button->postdown, button); + + return ret; +} + +void set_key_down(DeviceIntPtr pDev, int key_code, int type) { if (type == KEY_PROCESSED) - pDev->key->down[key_code >> 3] |= (1 << (key_code & 7)); + SetBit(pDev->key->down, key_code); else - pDev->key->postdown[key_code >> 3] |= (1 << (key_code & 7)); + SetBit(pDev->key->postdown, key_code); } void set_key_up(DeviceIntPtr pDev, int key_code, int type) { if (type == KEY_PROCESSED) - pDev->key->down[key_code >> 3] &= ~(1 << (key_code & 7)); + ClearBit(pDev->key->down, key_code); else - pDev->key->postdown[key_code >> 3] &= ~(1 << (key_code & 7)); + ClearBit(pDev->key->postdown, key_code); } Bool @@ -112,9 +145,9 @@ key_is_down(DeviceIntPtr pDev, int key_code, int type) int ret = 0; if (type & KEY_PROCESSED) - ret |= !!(pDev->key->down[key_code >> 3] & (1 << (key_code & 7))); - else if (type & KEY_POSTED) - ret |= !!(pDev->key->postdown[key_code >> 3] & (1 << (key_code & 7))); + ret |= !!BitIsOn(pDev->key->down, key_code); + if (type & KEY_POSTED) + ret |= !!BitIsOn(pDev->key->postdown, key_code); return ret; } @@ -325,8 +358,7 @@ void AllocateMotionHistory(DeviceIntPtr pDev) { int size; - if (pDev->valuator->motion) - xfree(pDev->valuator->motion); + free(pDev->valuator->motion); if (pDev->valuator->numMotionEvents < 1) return; @@ -342,7 +374,7 @@ AllocateMotionHistory(DeviceIntPtr pDev) size += sizeof(Time); - pDev->valuator->motion = xcalloc(pDev->valuator->numMotionEvents, size); + pDev->valuator->motion = calloc(pDev->valuator->numMotionEvents, size); pDev->valuator->first_motion = 0; pDev->valuator->last_motion = 0; if (!pDev->valuator->motion) @@ -384,7 +416,7 @@ GetMotionHistory(DeviceIntPtr pDev, xTimecoord **buff, unsigned long start, else size = (sizeof(INT32) * pDev->valuator->numAxes) + sizeof(Time); - *buff = xalloc(size * pDev->valuator->numMotionEvents); + *buff = malloc(size * pDev->valuator->numMotionEvents); if (!(*buff)) return 0; obuff = (char *)*buff; @@ -620,8 +652,8 @@ clipValuators(DeviceIntPtr pDev, int first_valuator, int num_valuators, * events if a DCCE was generated. * @return The updated @events pointer. */ -static EventListPtr -updateFromMaster(EventListPtr events, DeviceIntPtr dev, int type, int *num_events) +EventListPtr +UpdateFromMaster(EventListPtr events, DeviceIntPtr dev, int type, int *num_events) { DeviceIntPtr master; @@ -880,24 +912,26 @@ GetKeyboardEvents(EventList *events, DeviceIntPtr pDev, int type, int key_code) int GetKeyboardValuatorEvents(EventList *events, DeviceIntPtr pDev, int type, int key_code, int first_valuator, - int num_valuators, int *valuators) { + int num_valuators, int *valuators_in) { int num_events = 0; CARD32 ms = 0; DeviceEvent *event; RawDeviceEvent *raw; + int valuators[MAX_VALUATORS]; /* refuse events from disabled devices */ if (!pDev->enabled) return 0; if (!events ||!pDev->key || !pDev->focus || !pDev->kbdfeed || + num_valuators > MAX_VALUATORS || (type != KeyPress && type != KeyRelease) || (key_code < 8 || key_code > 255)) return 0; num_events = 1; - events = updateFromMaster(events, pDev, DEVCHANGE_KEYBOARD_EVENT, &num_events); + events = UpdateFromMaster(events, pDev, DEVCHANGE_KEYBOARD_EVENT, &num_events); /* Handle core repeating, via press/release/press/release. */ if (type == KeyPress && key_is_down(pDev, key_code, KEY_POSTED)) { @@ -915,6 +949,8 @@ GetKeyboardValuatorEvents(EventList *events, DeviceIntPtr pDev, int type, events++; num_events++; + memcpy(valuators, valuators_in, num_valuators * sizeof(int)); + init_raw(pDev, raw, ms, type, key_code); set_raw_valuators(raw, first_valuator, num_valuators, valuators, raw->valuators.data_raw); @@ -959,20 +995,20 @@ InitEventList(int num_events) EventListPtr events; int i; - events = (EventListPtr)xcalloc(num_events, sizeof(EventList)); + events = (EventListPtr)calloc(num_events, sizeof(EventList)); if (!events) return NULL; for (i = 0; i < num_events; i++) { events[i].evlen = sizeof(InternalEvent); - events[i].event = xcalloc(1, sizeof(InternalEvent)); + events[i].event = calloc(1, sizeof(InternalEvent)); if (!events[i].event) { /* rollback */ while(i--) - xfree(events[i].event); - xfree(events); + free(events[i].event); + free(events); events = NULL; break; } @@ -993,8 +1029,24 @@ FreeEventList(EventListPtr list, int num_events) if (!list) return; while(num_events--) - xfree(list[num_events].event); - xfree(list); + free(list[num_events].event); + free(list); +} + +static void +transformAbsolute(DeviceIntPtr dev, int v[MAX_VALUATORS]) +{ + struct pixman_f_vector p; + + /* p' = M * p in homogeneous coordinates */ + p.v[0] = v[0]; + p.v[1] = v[1]; + p.v[2] = 1.0; + + pixman_f_transform_point(&dev->transform, &p); + + v[0] = lround(p.v[0]); + v[1] = lround(p.v[1]); } /** @@ -1019,7 +1071,7 @@ FreeEventList(EventListPtr list, int num_events) int GetPointerEvents(EventList *events, DeviceIntPtr pDev, int type, int buttons, int flags, int first_valuator, int num_valuators, - int *valuators) { + int *valuators_in) { int num_events = 1; CARD32 ms; DeviceEvent *event; @@ -1028,6 +1080,7 @@ GetPointerEvents(EventList *events, DeviceIntPtr pDev, int type, int buttons, cx, cy; /* only screen coordinates */ float x_frac = 0.0, y_frac = 0.0, cx_frac, cy_frac; ScreenPtr scr = miPointerGetScreen(pDev); + int valuators[MAX_VALUATORS]; /* refuse events from disabled devices */ if (!pDev->enabled) @@ -1036,6 +1089,7 @@ GetPointerEvents(EventList *events, DeviceIntPtr pDev, int type, int buttons, ms = GetTimeInMillis(); /* before pointer update to help precision */ if (!scr || !pDev->valuator || first_valuator < 0 || + num_valuators > MAX_VALUATORS || ((num_valuators + first_valuator) > pDev->valuator->numAxes) || (type != MotionNotify && type != ButtonPress && type != ButtonRelease) || (type != MotionNotify && !pDev->button) || @@ -1043,12 +1097,14 @@ GetPointerEvents(EventList *events, DeviceIntPtr pDev, int type, int buttons, (type == MotionNotify && num_valuators <= 0)) return 0; - events = updateFromMaster(events, pDev, DEVCHANGE_POINTER_EVENT, &num_events); + events = UpdateFromMaster(events, pDev, DEVCHANGE_POINTER_EVENT, &num_events); raw = (RawDeviceEvent*)events->event; events++; num_events++; + memcpy(valuators, valuators_in, num_valuators * sizeof(int)); + init_raw(pDev, raw, ms, type, buttons); set_raw_valuators(raw, first_valuator, num_valuators, valuators, raw->valuators.data_raw); @@ -1068,6 +1124,7 @@ GetPointerEvents(EventList *events, DeviceIntPtr pDev, int type, int buttons, scr->height); } + transformAbsolute(pDev, valuators); moveAbsolute(pDev, &x, &y, first_valuator, num_valuators, valuators); } else { if (flags & POINTER_ACCELERATE) { @@ -1105,11 +1162,11 @@ GetPointerEvents(EventList *events, DeviceIntPtr pDev, int type, int buttons, else { if (type == ButtonPress) { event->type = ET_ButtonPress; - pDev->button->postdown[buttons >> 3] |= (1 << (buttons & 7)); + set_button_down(pDev, buttons, BUTTON_POSTED); } else if (type == ButtonRelease) { event->type = ET_ButtonRelease; - pDev->button->postdown[buttons >> 3] &= ~(1 << (buttons & 7)); + set_button_up(pDev, buttons, BUTTON_POSTED); } event->detail.button = buttons; } @@ -1134,10 +1191,11 @@ GetPointerEvents(EventList *events, DeviceIntPtr pDev, int type, int buttons, */ int GetProximityEvents(EventList *events, DeviceIntPtr pDev, int type, - int first_valuator, int num_valuators, int *valuators) + int first_valuator, int num_valuators, int *valuators_in) { int num_events = 1; DeviceEvent *event; + int valuators[MAX_VALUATORS]; /* refuse events from disabled devices */ if (!pDev->enabled) @@ -1153,18 +1211,20 @@ GetProximityEvents(EventList *events, DeviceIntPtr pDev, int type, num_valuators = 0; /* You fail. */ - if (first_valuator < 0 || + if (first_valuator < 0 || num_valuators > MAX_VALUATORS || (num_valuators + first_valuator) > pDev->valuator->numAxes) return 0; - events = updateFromMaster(events, pDev, DEVCHANGE_POINTER_EVENT, &num_events); + events = UpdateFromMaster(events, pDev, DEVCHANGE_POINTER_EVENT, &num_events); event = (DeviceEvent *) events->event; init_event(pDev, event, GetTimeInMillis()); event->type = (type == ProximityIn) ? ET_ProximityIn : ET_ProximityOut; - if (num_valuators) + if (num_valuators) { + memcpy(valuators, valuators_in, num_valuators * sizeof(int)); clipValuators(pDev, first_valuator, num_valuators, valuators); + } set_valuators(pDev, event, first_valuator, num_valuators, valuators); @@ -1191,8 +1251,8 @@ PostSyntheticMotion(DeviceIntPtr pDev, will translate from sprite screen to screen 0 upon reentry to the DIX layer. */ if (!noPanoramiXExtension) { - x += panoramiXdataPtr[0].x - panoramiXdataPtr[screen].x; - y += panoramiXdataPtr[0].y - panoramiXdataPtr[screen].y; + x += screenInfo.screens[0]->x - screenInfo.screens[screen]->x; + y += screenInfo.screens[0]->y - screenInfo.screens[screen]->y; } #endif diff --git a/xserver/dix/globals.c b/xserver/dix/globals.c index 10b9f931e..1c3cf39ea 100644 --- a/xserver/dix/globals.c +++ b/xserver/dix/globals.c @@ -83,8 +83,6 @@ ClientPtr serverClient; int currentMaxClients; /* current size of clients array */ long maxBigRequestSize = MAX_BIG_REQUEST_SIZE; -WindowPtr WindowTable[MAXSCREENS]; - unsigned long globalSerialNumber = 0; unsigned long serverGeneration = 0; @@ -129,8 +127,6 @@ Bool party_like_its_1989 = TRUE; #endif Bool whiteRoot = FALSE; -int cursorScreenDevPriv[MAXSCREENS]; - TimeStamp currentTime; TimeStamp lastDeviceEventTime; @@ -141,5 +137,3 @@ char *display; char *ConnectionInfo; CARD32 TimeOutValue = DEFAULT_TIMEOUT * MILLI_PER_SECOND; - -DDXPointRec dixScreenOrigins[MAXSCREENS]; diff --git a/xserver/dix/glyphcurs.c b/xserver/dix/glyphcurs.c index f74b13730..fa2aeca26 100644 --- a/xserver/dix/glyphcurs.c +++ b/xserver/dix/glyphcurs.c @@ -91,7 +91,7 @@ ServerBitsFromGlyph(FontPtr pfont, unsigned ch, CursorMetricPtr cm, unsigned cha pScreen = screenInfo.screens[0]; nby = BitmapBytePad(cm->width) * (long)cm->height; - pbits = xcalloc(1, nby); + pbits = calloc(1, nby); if (!pbits) return BadAlloc; @@ -105,7 +105,7 @@ ServerBitsFromGlyph(FontPtr pfont, unsigned ch, CursorMetricPtr cm, unsigned cha (*pScreen->DestroyPixmap)(ppix); if (pGC) FreeScratchGC(pGC); - xfree(pbits); + free(pbits); return BadAlloc; } @@ -118,14 +118,13 @@ ServerBitsFromGlyph(FontPtr pfont, unsigned ch, CursorMetricPtr cm, unsigned cha gcval[0].val = GXcopy; gcval[1].val = 0; gcval[2].ptr = (pointer)pfont; - dixChangeGC(NullClient, pGC, GCFunction | GCForeground | GCFont, - NULL, gcval); + ChangeGC(NullClient, pGC, GCFunction | GCForeground | GCFont, gcval); ValidateGC((DrawablePtr)ppix, pGC); (*pGC->ops->PolyFillRect)((DrawablePtr)ppix, pGC, 1, &rect); /* draw the glyph */ gcval[0].val = 1; - dixChangeGC(NullClient, pGC, GCForeground, NULL, gcval); + ChangeGC(NullClient, pGC, GCForeground, gcval); ValidateGC((DrawablePtr)ppix, pGC); (*pGC->ops->PolyText16)((DrawablePtr)ppix, pGC, cm->xhot, cm->yhot, 1, (unsigned short *)char2b); diff --git a/xserver/dix/grabs.c b/xserver/dix/grabs.c index 4a351d647..f850e3d84 100644 --- a/xserver/dix/grabs.c +++ b/xserver/dix/grabs.c @@ -84,7 +84,7 @@ CreateGrab( { GrabPtr grab; - grab = xcalloc(1, sizeof(GrabRec)); + grab = calloc(1, sizeof(GrabRec)); if (!grab) return (GrabPtr)NULL; grab->resource = FakeClientID(client); @@ -118,15 +118,15 @@ static void FreeGrab(GrabPtr pGrab) { if (pGrab->modifiersDetail.pMask != NULL) - xfree(pGrab->modifiersDetail.pMask); + free(pGrab->modifiersDetail.pMask); if (pGrab->detail.pMask != NULL) - xfree(pGrab->detail.pMask); + free(pGrab->detail.pMask); if (pGrab->cursor) FreeCursor(pGrab->cursor, (Cursor)0); - xfree(pGrab); + free(pGrab); } int @@ -160,7 +160,7 @@ DeleteDetailFromMask(Mask *pDetailMask, unsigned int detail) Mask *mask; int i; - mask = xalloc(sizeof(Mask) * MasksPerDetailMask); + mask = malloc(sizeof(Mask) * MasksPerDetailMask); if (mask) { if (pDetailMask) @@ -435,16 +435,16 @@ DeletePassiveGrabFromList(GrabPtr pMinuendGrab) i++; if (!i) return TRUE; - deletes = xalloc(i * sizeof(GrabPtr)); - adds = xalloc(i * sizeof(GrabPtr)); - updates = xalloc(i * sizeof(Mask **)); - details = xalloc(i * sizeof(Mask *)); + deletes = malloc(i * sizeof(GrabPtr)); + adds = malloc(i * sizeof(GrabPtr)); + updates = malloc(i * sizeof(Mask **)); + details = malloc(i * sizeof(Mask *)); if (!deletes || !adds || !updates || !details) { - if (details) xfree(details); - if (updates) xfree(updates); - if (adds) xfree(adds); - if (deletes) xfree(deletes); + free(details); + free(updates); + free(adds); + free(deletes); return FALSE; } @@ -532,7 +532,7 @@ DeletePassiveGrabFromList(GrabPtr pMinuendGrab) for (i = 0; i < nadds; i++) FreeResource(adds[i]->resource, RT_NONE); for (i = 0; i < nups; i++) - xfree(details[i]); + free(details[i]); } else { @@ -546,14 +546,14 @@ DeletePassiveGrabFromList(GrabPtr pMinuendGrab) } for (i = 0; i < nups; i++) { - xfree(*updates[i]); + free(*updates[i]); *updates[i] = details[i]; } } - xfree(details); - xfree(updates); - xfree(adds); - xfree(deletes); + free(details); + free(updates); + free(adds); + free(deletes); return ok; #undef UPDATE diff --git a/xserver/dix/inpututils.c b/xserver/dix/inpututils.c index 4848c1bc2..8ec80b5e8 100644 --- a/xserver/dix/inpututils.c +++ b/xserver/dix/inpututils.c @@ -88,7 +88,6 @@ do_butmap_change(DeviceIntPtr dev, CARD8 *map, int len, ClientPtr client) if (!XIShouldNotify(clients[i], dev)) continue; - core_mn.u.u.sequenceNumber = clients[i]->sequence; WriteEventsToClient(clients[i], 1, &core_mn); } @@ -311,7 +310,7 @@ int generate_modkeymap(ClientPtr client, DeviceIntPtr dev, } } - modkeymap = xcalloc(max_keys_per_mod * 8, sizeof(KeyCode)); + modkeymap = calloc(max_keys_per_mod * 8, sizeof(KeyCode)); if (!modkeymap) return BadAlloc; @@ -332,3 +331,88 @@ int generate_modkeymap(ClientPtr client, DeviceIntPtr dev, return Success; } + +/** + * Duplicate the InputAttributes in the most obvious way. + * No special memory handling is used to give drivers the maximum + * flexibility with the data. Drivers should be able to call realloc on the + * product string if needed and perform similar operations. + */ +InputAttributes* +DuplicateInputAttributes(InputAttributes *attrs) +{ + InputAttributes *new_attr; + int ntags = 0; + char **tags, **new_tags; + + if (!attrs) + return NULL; + + if (!(new_attr = calloc(1, sizeof(InputAttributes)))) + goto unwind; + + if (attrs->product && !(new_attr->product = strdup(attrs->product))) + goto unwind; + if (attrs->vendor && !(new_attr->vendor = strdup(attrs->vendor))) + goto unwind; + if (attrs->device && !(new_attr->device = strdup(attrs->device))) + goto unwind; + if (attrs->pnp_id && !(new_attr->pnp_id = strdup(attrs->pnp_id))) + goto unwind; + if (attrs->usb_id && !(new_attr->usb_id = strdup(attrs->usb_id))) + goto unwind; + + new_attr->flags = attrs->flags; + + if ((tags = attrs->tags)) + { + while(*tags++) + ntags++; + + new_attr->tags = calloc(ntags + 1, sizeof(char*)); + if (!new_attr->tags) + goto unwind; + + tags = attrs->tags; + new_tags = new_attr->tags; + + while(*tags) + { + *new_tags = strdup(*tags); + if (!*new_tags) + goto unwind; + + tags++; + new_tags++; + } + } + + return new_attr; + +unwind: + FreeInputAttributes(new_attr); + return NULL; +} + +void +FreeInputAttributes(InputAttributes *attrs) +{ + char **tags; + + if (!attrs) + return; + + free(attrs->product); + free(attrs->vendor); + free(attrs->device); + free(attrs->pnp_id); + free(attrs->usb_id); + + if ((tags = attrs->tags)) + while(*tags) + free(*tags++); + + free(attrs->tags); + free(attrs); +} + diff --git a/xserver/dix/main.c b/xserver/dix/main.c index f0235364f..47a932f15 100644 --- a/xserver/dix/main.c +++ b/xserver/dix/main.c @@ -161,9 +161,7 @@ int main(int argc, char *argv[], char *envp[]) ScreenSaverBlanking = defaultScreenSaverBlanking; ScreenSaverAllowExposures = defaultScreenSaverAllowExposures; #ifdef DPMSExtension - DPMSStandbyTime = DEFAULT_SCREEN_SAVER_TIME; - DPMSSuspendTime = DEFAULT_SCREEN_SAVER_TIME; - DPMSOffTime = DEFAULT_SCREEN_SAVER_TIME; + DPMSStandbyTime = DPMSSuspendTime = DPMSOffTime = ScreenSaverTime; DPMSEnabled = TRUE; DPMSPowerLevel = 0; #endif @@ -176,7 +174,7 @@ int main(int argc, char *argv[], char *envp[]) InitProcVectors(); for (i=1; i<MAXCLIENTS; i++) clients[i] = NullClient; - serverClient = xalloc(sizeof(ClientRec)); + serverClient = calloc(sizeof(ClientRec), 1); if (!serverClient) FatalError("couldn't create server client"); InitClient(serverClient, 0, (pointer)NULL); @@ -186,19 +184,25 @@ int main(int argc, char *argv[], char *envp[]) clients[0] = serverClient; currentMaxClients = 1; + /* Initialize privates before first allocation */ + dixResetPrivates(); + + /* Initialize server client devPrivates, to be reallocated as + * more client privates are registered + */ + if (!dixAllocatePrivates(&serverClient->devPrivates, PRIVATE_CLIENT)) + FatalError("failed to create server client privates"); + if (!InitClientResources(serverClient)) /* for root resources */ FatalError("couldn't init server resources"); SetInputCheck(&alwaysCheckForInput[0], &alwaysCheckForInput[1]); - screenInfo.arraySize = MAXSCREENS; screenInfo.numScreens = 0; InitAtoms(); InitEvents(); InitSelections(); InitGlyphCaching(); - if (!dixResetPrivates()) - FatalError("couldn't init private data storage"); dixResetRegistry(); ResetFontPrivateIndex(); InitCallbackManager(); @@ -207,6 +211,7 @@ int main(int argc, char *argv[], char *envp[]) if (screenInfo.numScreens < 1) FatalError("no screens found"); InitExtensions(argc, argv); + for (i = 0; i < screenInfo.numScreens; i++) { ScreenPtr pScreen = screenInfo.screens[i]; @@ -252,7 +257,7 @@ int main(int argc, char *argv[], char *envp[]) #endif for (i = 0; i < screenInfo.numScreens; i++) - InitRootWindow(WindowTable[i]); + InitRootWindow(screenInfo.screens[i]->root); InitCoreDevices(); InitInput(argc, argv); @@ -306,7 +311,8 @@ int main(int argc, char *argv[], char *envp[]) CloseInput(); - memset(WindowTable, 0, sizeof(WindowTable)); + for (i = 0; i < screenInfo.numScreens; i++) + screenInfo.screens[i]->root = NullWindow; CloseDownDevices(); CloseDownEvents(); @@ -316,17 +322,18 @@ int main(int argc, char *argv[], char *envp[]) FreeGCperDepth(i); FreeDefaultStipple(i); (* screenInfo.screens[i]->CloseScreen)(i, screenInfo.screens[i]); - dixFreePrivates(screenInfo.screens[i]->devPrivates); - xfree(screenInfo.screens[i]); + dixFreePrivates(screenInfo.screens[i]->devPrivates, PRIVATE_SCREEN); + free(screenInfo.screens[i]); screenInfo.numScreens = i; } + + dixFreePrivates(serverClient->devPrivates, PRIVATE_CLIENT); + serverClient->devPrivates = NULL; + FreeFonts(); FreeAuditTimer(); - dixFreePrivates(serverClient->devPrivates); - serverClient->devPrivates = NULL; - if (dispatchException & DE_TERMINATE) { CloseWellKnownConnections(); @@ -340,9 +347,9 @@ int main(int argc, char *argv[], char *envp[]) break; } - xfree(ConnectionInfo); + free(ConnectionInfo); ConnectionInfo = NULL; } - return(0); + return 0; } diff --git a/xserver/dix/pixmap.c b/xserver/dix/pixmap.c index 10ec02a78..cbb5e7f99 100644 --- a/xserver/dix/pixmap.c +++ b/xserver/dix/pixmap.c @@ -91,6 +91,11 @@ FreeScratchPixmapHeader(PixmapPtr pPixmap) Bool CreateScratchPixmapsForScreen(int scrnum) { + unsigned int pixmap_size; + + pixmap_size = sizeof(PixmapRec) + dixPrivatesSize(PRIVATE_PIXMAP); + screenInfo.screens[scrnum]->totalPixmapSize = BitmapBytePad(pixmap_size * 8); + /* let it be created on first use */ screenInfo.screens[scrnum]->pScratchPixmap = NULL; return TRUE; @@ -110,13 +115,23 @@ AllocatePixmap(ScreenPtr pScreen, int pixDataSize) { PixmapPtr pPixmap; + assert(pScreen->totalPixmapSize > 0); + if (pScreen->totalPixmapSize > ((size_t)-1) - pixDataSize) return NullPixmap; - pPixmap = xalloc(pScreen->totalPixmapSize + pixDataSize); + pPixmap = malloc(pScreen->totalPixmapSize + pixDataSize); if (!pPixmap) return NullPixmap; - pPixmap->devPrivates = NULL; + dixInitPrivates(pPixmap, pPixmap + 1, PRIVATE_PIXMAP); return pPixmap; } + +/* callable by ddx */ +void +FreePixmap(PixmapPtr pPixmap) +{ + dixFiniPrivates(pPixmap, PRIVATE_PIXMAP); + free(pPixmap); +} diff --git a/xserver/dix/privates.c b/xserver/dix/privates.c index e3e727462..17e1050d9 100644 --- a/xserver/dix/privates.c +++ b/xserver/dix/privates.c @@ -25,6 +25,28 @@ other dealings in this Software without prior written authorization from The Open Group. */ +/* + * Copyright © 2010, Keith Packard + * Copyright © 2010, Jamey Sharp + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that copyright + * notice and this permission notice appear in supporting documentation, and + * that the name of the copyright holders not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. The copyright holders make no representations + * about the suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ #ifdef HAVE_DIX_CONFIG_H #include <dix-config.h> @@ -38,215 +60,328 @@ from The Open Group. #include "cursorstr.h" #include "colormapst.h" #include "inputstr.h" - -struct _Private { - int state; - pointer value; +#include "scrnintstr.h" +#include "extnsionst.h" + +static struct { + DevPrivateKey key; + unsigned offset; + int created; + int allocated; +} keys[PRIVATE_LAST]; + +static const Bool xselinux_private[PRIVATE_LAST] = { + [PRIVATE_SCREEN] = TRUE, + [PRIVATE_CLIENT] = TRUE, + [PRIVATE_WINDOW] = TRUE, + [PRIVATE_PIXMAP] = TRUE, + [PRIVATE_GC] = TRUE, + [PRIVATE_CURSOR] = TRUE, + [PRIVATE_COLORMAP] = TRUE, + [PRIVATE_DEVICE] = TRUE, + [PRIVATE_EXTENSION] = TRUE, + [PRIVATE_SELECTION] = TRUE, + [PRIVATE_PROPERTY] = TRUE, + [PRIVATE_PICTURE] = TRUE, + [PRIVATE_GLYPHSET] = TRUE, }; -typedef struct _PrivateDesc { - DevPrivateKey key; - unsigned size; - CallbackListPtr initfuncs; - CallbackListPtr deletefuncs; -} PrivateDescRec; +typedef Bool (*FixupFunc)(PrivatePtr *privates, int offset, unsigned bytes); -#define PRIV_MAX 256 -#define PRIV_STEP 16 +static Bool +dixReallocPrivates(PrivatePtr *privates, int old_offset, unsigned bytes) +{ + void *new_privates; -/* list of all allocated privates */ -static PrivateDescRec items[PRIV_MAX]; -static int nextPriv; + new_privates = realloc(*privates, old_offset + bytes); + if (!new_privates) + return FALSE; + memset((char *) new_privates + old_offset, '\0', bytes); + *privates = new_privates; + return TRUE; +} -static PrivateDescRec * -findItem(const DevPrivateKey key) +static Bool +dixMovePrivates(PrivatePtr *privates, int new_offset, unsigned bytes) { - if (!*key) { - if (nextPriv >= PRIV_MAX) - return NULL; + memmove((char *) *privates + bytes, *privates, new_offset - bytes); + memset(*privates, '\0', bytes); + return TRUE; +} - items[nextPriv].key = key; - *key = nextPriv; - nextPriv++; - } +static Bool +fixupScreens(FixupFunc fixup, unsigned bytes) +{ + int s; + for (s = 0; s < screenInfo.numScreens; s++) + if (!fixup(&screenInfo.screens[s]->devPrivates, keys[PRIVATE_SCREEN].offset, bytes)) + return FALSE; + return TRUE; +} - return items + *key; +static Bool +fixupServerClient(FixupFunc fixup, unsigned bytes) +{ + if (serverClient) + return fixup(&serverClient->devPrivates, keys[PRIVATE_CLIENT].offset, bytes); + return TRUE; } -static _X_INLINE int -privateExists(PrivateRec **privates, const DevPrivateKey key) +static Bool +fixupExtensions(FixupFunc fixup, unsigned bytes) { - return *key && *privates && - (*privates)[0].state > *key && - (*privates)[*key].state; + unsigned char major; + ExtensionEntry *extension; + for (major = EXTENSION_BASE; (extension = GetExtensionEntry(major)); major++) + if (!fixup(&extension->devPrivates, keys[PRIVATE_EXTENSION].offset, bytes)) + return FALSE; + return TRUE; } -/* - * Request pre-allocated space. - */ -int -dixRequestPrivate(const DevPrivateKey key, unsigned size) +static Bool +fixupDefaultColormaps(FixupFunc fixup, unsigned bytes) { - PrivateDescRec *item = findItem(key); - if (!item) - return FALSE; - if (size > item->size) - item->size = size; + int s; + for (s = 0; s < screenInfo.numScreens; s++) { + ColormapPtr cmap; + dixLookupResourceByType((pointer *) &cmap, screenInfo.screens[s]->defColormap, + RT_COLORMAP, serverClient, DixCreateAccess); + if (cmap && !fixup(&cmap->devPrivates, keys[PRIVATE_COLORMAP].offset, bytes)) + return FALSE; + } return TRUE; } +static Bool (* const allocated_early[PRIVATE_LAST])(FixupFunc, unsigned) = { + [PRIVATE_SCREEN] = fixupScreens, + [PRIVATE_CLIENT] = fixupServerClient, + [PRIVATE_EXTENSION] = fixupExtensions, + [PRIVATE_COLORMAP] = fixupDefaultColormaps, +}; + /* - * Allocate a private and attach it to an existing object. + * Register a private key. This takes the type of object the key will + * be used with, which may be PRIVATE_ALL indicating that this key + * will be used with all of the private objects. If 'size' is + * non-zero, then the specified amount of space will be allocated in + * the private storage. Otherwise, space for a single pointer will + * be allocated which can be set with dixSetPrivate */ -pointer * -dixAllocatePrivate(PrivateRec **privates, const DevPrivateKey key) +Bool +dixRegisterPrivateKey(DevPrivateKey key, DevPrivateType type, unsigned size) { - PrivateDescRec *item = findItem(key); - PrivateCallbackRec calldata; - PrivateRec *ptr; - pointer value; - int oldsize, newsize; - - newsize = (*key / PRIV_STEP + 1) * PRIV_STEP; + DevPrivateType t; + int offset; + unsigned bytes; - /* resize or init privates array */ - if (!item) - return NULL; - - /* initialize privates array if necessary */ - if (!*privates) { - ptr = xcalloc(newsize, sizeof(*ptr)); - if (!ptr) - return NULL; - *privates = ptr; - (*privates)[0].state = newsize; + if (key->initialized) { + assert (size == key->size); + return TRUE; } - oldsize = (*privates)[0].state; + /* Compute required space */ + bytes = size; + if (size == 0) + bytes = sizeof (void *); + + /* align to void * size */ + bytes = (bytes + sizeof (void *) - 1) & ~(sizeof (void *) - 1); + + /* Update offsets for all affected keys */ + if (type == PRIVATE_XSELINUX) { + DevPrivateKey k; + + /* Resize if we can, or make sure nothing's allocated if we can't + */ + for (t = PRIVATE_XSELINUX; t < PRIVATE_LAST; t++) + if (xselinux_private[t]) { + if (!allocated_early[t]) + assert (!keys[t].created); + else if (!allocated_early[t](dixReallocPrivates, bytes)) + return FALSE; + } - /* resize privates array if necessary */ - if (*key >= oldsize) { - ptr = xrealloc(*privates, newsize * sizeof(*ptr)); - if (!ptr) - return NULL; - memset(ptr + oldsize, 0, (newsize - oldsize) * sizeof(*ptr)); - *privates = ptr; - (*privates)[0].state = newsize; - } + /* Move all existing keys up in the privates space to make + * room for this new global key + */ + for (t = PRIVATE_XSELINUX; t < PRIVATE_LAST; t++) { + if (xselinux_private[t]) { + for (k = keys[t].key; k; k = k->next) + k->offset += bytes; + keys[t].offset += bytes; + if (allocated_early[t]) + allocated_early[t](dixMovePrivates, bytes); + } + } - /* initialize slot */ - ptr = *privates + *key; - ptr->state = 1; - if (item->size) { - value = xcalloc(item->size, 1); - if (!value) - return NULL; - ptr->value = value; + offset = 0; + } else { + /* Resize if we can, or make sure nothing's allocated if we can't */ + if (!allocated_early[type]) + assert(!keys[type].created); + else if (!allocated_early[type](dixReallocPrivates, bytes)) + return FALSE; + offset = keys[type].offset; + keys[type].offset += bytes; } - calldata.key = key; - calldata.value = &ptr->value; - CallCallbacks(&item->initfuncs, &calldata); + /* Setup this key */ + key->offset = offset; + key->size = size; + key->initialized = TRUE; + key->type = type; + key->allocated = FALSE; + key->next = keys[type].key; + keys[type].key = key; - return &ptr->value; + return TRUE; } /* - * Look up a private pointer. + * Allocate a new private key. + * + * This manages the storage of the key object itself, freeing it when the + * privates system is restarted at server reset time. All other keys + * are expected to be statically allocated as the privates must be + * reset after all objects have been freed */ -pointer -dixLookupPrivate(PrivateRec **privates, const DevPrivateKey key) +DevPrivateKey +dixCreatePrivateKey(DevPrivateType type, unsigned size) { - pointer *ptr; + DevPrivateKey key; - if (privateExists(privates, key)) - return (*privates)[*key].value; + key = calloc(sizeof (DevPrivateKeyRec), 1); + if (!key) + return NULL; + if (!dixRegisterPrivateKey(key, type, size)) { + free(key); + return NULL; + } + key->allocated = TRUE; + return key; +} + +/* + * Initialize privates by zeroing them + */ +void +_dixInitPrivates(PrivatePtr *privates, void *addr, DevPrivateType type) +{ + keys[type].created++; + if (xselinux_private[type]) + keys[PRIVATE_XSELINUX].created++; + if (keys[type].offset == 0) + addr = 0; + *privates = addr; + memset(addr, '\0', keys[type].offset); +} - ptr = dixAllocatePrivate(privates, key); - return ptr ? *ptr : NULL; +/* + * Clean up privates + */ +void +_dixFiniPrivates(PrivatePtr privates, DevPrivateType type) +{ + keys[type].created--; + if (xselinux_private[type]) + keys[PRIVATE_XSELINUX].created--; } /* - * Look up the address of a private pointer. + * Allocate new object with privates. + * + * This is expected to be invoked from the + * dixAllocateObjectWithPrivates macro */ -pointer * -dixLookupPrivateAddr(PrivateRec **privates, const DevPrivateKey key) +void * +_dixAllocateObjectWithPrivates(unsigned baseSize, unsigned clear, unsigned offset, DevPrivateType type) { - if (privateExists(privates, key)) - return &(*privates)[*key].value; + unsigned totalSize; + void *object; + PrivatePtr privates; + PrivatePtr *devPrivates; + + assert (type > PRIVATE_SCREEN && type < PRIVATE_LAST); + + /* round up so that void * is aligned */ + baseSize = (baseSize + sizeof (void *) - 1) & ~(sizeof (void *) - 1); + totalSize = baseSize + keys[type].offset; + object = malloc(totalSize); + if (!object) + return NULL; - return dixAllocatePrivate(privates, key); + memset(object, '\0', clear); + privates = (PrivatePtr) (((char *) object) + baseSize); + devPrivates = (PrivatePtr *) ((char *) object + offset); + + _dixInitPrivates(devPrivates, privates, type); + + return object; } /* - * Set a private pointer. + * Allocate privates separately from containing object. + * Used for clients and screens. */ -int -dixSetPrivate(PrivateRec **privates, const DevPrivateKey key, pointer val) +Bool +dixAllocatePrivates(PrivatePtr *privates, DevPrivateType type) { - top: - if (privateExists(privates, key)) { - (*privates)[*key].value = val; - return TRUE; + unsigned size; + PrivatePtr p; + + assert (type > PRIVATE_XSELINUX && type < PRIVATE_LAST); + + size = keys[type].offset; + if (!size) { + p = NULL; + } else { + if (!(p = malloc(size))) + return FALSE; } - if (!dixAllocatePrivate(privates, key)) - return FALSE; - goto top; + _dixInitPrivates(privates, p, type); + ++keys[type].allocated; + + return TRUE; } /* - * Called to free privates at object deletion time. + * Free an object that has privates + * + * This is expected to be invoked from the + * dixFreeObjectWithPrivates macro */ void -dixFreePrivates(PrivateRec *privates) +_dixFreeObjectWithPrivates(void *object, PrivatePtr privates, DevPrivateType type) { - int i; - PrivateCallbackRec calldata; - - if (privates) - for (i = 1; i < privates->state; i++) - if (privates[i].state) { - /* call the delete callbacks */ - calldata.key = items[i].key; - calldata.value = &privates[i].value; - CallCallbacks(&items[i].deletefuncs, &calldata); - - /* free pre-allocated memory */ - if (items[i].size) - xfree(privates[i].value); - } - - xfree(privates); + _dixFiniPrivates(privates, type); + free(object); } /* - * Callback registration + * Called to free screen or client privates */ -int -dixRegisterPrivateInitFunc(const DevPrivateKey key, - CallbackProcPtr callback, pointer data) +void +dixFreePrivates(PrivatePtr privates, DevPrivateType type) { - PrivateDescRec *item = findItem(key); - if (!item) - return FALSE; - - return AddCallback(&item->initfuncs, callback, data); + _dixFiniPrivates(privates, type); + --keys[type].allocated; + free(privates); } -int -dixRegisterPrivateDeleteFunc(const DevPrivateKey key, - CallbackProcPtr callback, pointer data) +/* + * Return size of privates for the specified type + */ +extern _X_EXPORT int +dixPrivatesSize(DevPrivateType type) { - PrivateDescRec *item = findItem(key); - if (!item) - return FALSE; + assert (type >= PRIVATE_SCREEN && type < PRIVATE_LAST); - return AddCallback(&item->deletefuncs, callback, data); + return keys[type].offset; } /* Table of devPrivates offsets */ -static const int offsetDefaults[] = { +static const int offsets[] = { -1, /* RT_NONE */ offsetof(WindowRec, devPrivates), /* RT_WINDOW */ offsetof(PixmapRec, devPrivates), /* RT_PIXMAP */ @@ -254,69 +389,106 @@ static const int offsetDefaults[] = { -1, /* RT_FONT */ offsetof(CursorRec, devPrivates), /* RT_CURSOR */ offsetof(ColormapRec, devPrivates), /* RT_COLORMAP */ - -1, /* RT_CMAPENTRY */ - -1, /* RT_OTHERCLIENT */ - -1 /* RT_PASSIVEGRAB */ }; - -static int *offsets = NULL; -static int offsetsSize = 0; -/* - * Specify where the devPrivates field is located in a structure type - */ +#define NUM_OFFSETS (sizeof (offsets) / sizeof (offsets[0])) + int -dixRegisterPrivateOffset(RESTYPE type, int offset) +dixLookupPrivateOffset(RESTYPE type) { - type = type & TypeMask; - - /* resize offsets table if necessary */ - while (type >= offsetsSize) { - unsigned i = offsetsSize * 2 * sizeof(int); - offsets = (int *)xrealloc(offsets, i); - if (!offsets) { - offsetsSize = 0; - return FALSE; - } - for (i=offsetsSize; i < 2*offsetsSize; i++) - offsets[i] = -1; - offsetsSize *= 2; + /* + * Special kludge for DBE which registers a new resource type that + * points at pixmaps (thanks, DBE) + */ + if (type & RC_DRAWABLE) { + if (type == RT_WINDOW) + return offsets[RT_WINDOW & TypeMask]; + else + return offsets[RT_PIXMAP & TypeMask]; } - - offsets[type] = offset; - return TRUE; + type = type & TypeMask; + if (type < NUM_OFFSETS) + return offsets[type]; + return -1; } -int -dixLookupPrivateOffset(RESTYPE type) +static const char *key_names[PRIVATE_LAST] = { + /* XSELinux uses the same private keys for numerous objects */ + [PRIVATE_XSELINUX] = "XSELINUX", + + /* Otherwise, you get a private in just the requested structure + */ + /* These can have objects created before all of the keys are registered */ + [PRIVATE_SCREEN] = "SCREEN", + [PRIVATE_EXTENSION] = "EXTENSION", + [PRIVATE_COLORMAP] = "COLORMAP", + + /* These cannot have any objects before all relevant keys are registered */ + [PRIVATE_DEVICE] = "DEVICE", + [PRIVATE_CLIENT] = "CLIENT", + [PRIVATE_PROPERTY] = "PROPERTY", + [PRIVATE_SELECTION] = "SELECTION", + [PRIVATE_WINDOW] = "WINDOW", + [PRIVATE_PIXMAP] = "PIXMAP", + [PRIVATE_GC] = "GC", + [PRIVATE_CURSOR] = "CURSOR", + [PRIVATE_CURSOR_BITS] = "CURSOR_BITS", + + /* extension privates */ + [PRIVATE_DBE_WINDOW] = "DBE_WINDOW", + [PRIVATE_DAMAGE] = "DAMAGE", + [PRIVATE_GLYPH] = "GLYPH", + [PRIVATE_GLYPHSET] = "GLYPHSET", + [PRIVATE_PICTURE] = "PICTURE", +}; + +void +dixPrivateUsage(void) { - type = type & TypeMask; - assert(type < offsetsSize); - return offsets[type]; + int objects = 0; + int bytes = 0; + int alloc = 0; + DevPrivateType t; + + for (t = PRIVATE_XSELINUX + 1; t < PRIVATE_LAST; t++) { + if (keys[t].offset) { + ErrorF("%s: %d objects of %d bytes = %d total bytes %d private allocs\n", + key_names[t], keys[t].created, keys[t].offset, keys[t].created * keys[t].offset, + keys[t].allocated); + bytes += keys[t].created * keys[t].offset; + objects += keys[t].created; + alloc += keys[t].allocated; + } + } + ErrorF("TOTAL: %d objects, %d bytes, %d allocs\n", + objects, bytes, alloc); } -int +void dixResetPrivates(void) { - int i; - - /* reset private descriptors */ - for (i = 1; i < nextPriv; i++) { - *items[i].key = 0; - items[i].size = 0; - DeleteCallbackList(&items[i].initfuncs); - DeleteCallbackList(&items[i].deletefuncs); + DevPrivateType t; + + for (t = PRIVATE_XSELINUX; t < PRIVATE_LAST; t++) { + DevPrivateKey key, next; + + for (key = keys[t].key; key; key = next) { + next = key->next; + key->offset = 0; + key->initialized = FALSE; + key->size = 0; + key->type = 0; + if (key->allocated) + free(key); + } + if (keys[t].created) { + ErrorF("%d %ss still allocated at reset\n", + keys[t].created, key_names[t]); + dixPrivateUsage(); + } + keys[t].key = NULL; + keys[t].offset = 0; + keys[t].created = 0; + keys[t].allocated = 0; } - nextPriv = 1; - - /* reset offsets */ - if (offsets) - xfree(offsets); - offsetsSize = sizeof(offsetDefaults); - offsets = xalloc(offsetsSize); - offsetsSize /= sizeof(int); - if (!offsets) - return FALSE; - memcpy(offsets, offsetDefaults, sizeof(offsetDefaults)); - return TRUE; } diff --git a/xserver/dix/property.c b/xserver/dix/property.c index 9ec5dc6ae..1d4332a58 100644 --- a/xserver/dix/property.c +++ b/xserver/dix/property.c @@ -137,8 +137,8 @@ ProcRotateProperties(ClientPtr client) return rc; atoms = (Atom *) & stuff[1]; - props = xalloc(stuff->nAtoms * sizeof(PropertyPtr)); - saved = xalloc(stuff->nAtoms * sizeof(PropertyRec)); + props = malloc(stuff->nAtoms * sizeof(PropertyPtr)); + saved = malloc(stuff->nAtoms * sizeof(PropertyRec)); if (!props || !saved) { rc = BadAlloc; goto out; @@ -188,8 +188,8 @@ ProcRotateProperties(ClientPtr client) } } out: - xfree(saved); - xfree(props); + free(saved); + free(props); return rc; } @@ -230,12 +230,12 @@ ProcChangeProperty(ClientPtr client) if (!ValidAtom(stuff->property)) { client->errorValue = stuff->property; - return(BadAtom); + return BadAtom; } if (!ValidAtom(stuff->type)) { client->errorValue = stuff->type; - return(BadAtom); + return BadAtom; } err = dixChangeWindowProperty(client, pWin, stuff->property, stuff->type, @@ -244,7 +244,7 @@ ProcChangeProperty(ClientPtr client) if (err != Success) return err; else - return client->noClientException; + return Success; } int @@ -268,15 +268,15 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property, if (rc == BadMatch) /* just add to list */ { if (!pWin->optional && !MakeWindowOptional (pWin)) - return(BadAlloc); - pProp = xalloc(sizeof(PropertyRec)); + return BadAlloc; + pProp = dixAllocateObjectWithPrivates(PropertyRec, PRIVATE_PROPERTY); if (!pProp) - return(BadAlloc); - data = xalloc(totalSize); + return BadAlloc; + data = malloc(totalSize); if (!data && len) { - xfree(pProp); - return(BadAlloc); + dixFreeObjectWithPrivates(pProp, PRIVATE_PROPERTY); + return BadAlloc; } memcpy(data, value, totalSize); pProp->propertyName = property; @@ -284,12 +284,11 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property, pProp->format = format; pProp->data = data; pProp->size = len; - pProp->devPrivates = NULL; rc = XaceHookPropertyAccess(pClient, pWin, &pProp, DixCreateAccess|DixWriteAccess); if (rc != Success) { - xfree(data); - xfree(pProp); + free(data); + dixFreeObjectWithPrivates(pProp, PRIVATE_PROPERTY); pClient->errorValue = property; return rc; } @@ -304,18 +303,18 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property, "PropModeReplace" since they will be written over. */ if ((format != pProp->format) && (mode != PropModeReplace)) - return(BadMatch); + return BadMatch; if ((pProp->type != type) && (mode != PropModeReplace)) - return(BadMatch); + return BadMatch; /* save the old values for later */ savedProp = *pProp; if (mode == PropModeReplace) { - data = xalloc(totalSize); + data = malloc(totalSize); if (!data && len) - return(BadAlloc); + return BadAlloc; memcpy(data, value, totalSize); pProp->data = data; pProp->size = len; @@ -328,9 +327,9 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property, } else if (mode == PropModeAppend) { - data = xalloc((pProp->size + len) * sizeInBytes); + data = malloc((pProp->size + len) * sizeInBytes); if (!data) - return(BadAlloc); + return BadAlloc; memcpy(data, pProp->data, pProp->size * sizeInBytes); memcpy(data + pProp->size * sizeInBytes, value, totalSize); pProp->data = data; @@ -338,9 +337,9 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property, } else if (mode == PropModePrepend) { - data = xalloc(sizeInBytes * (len + pProp->size)); + data = malloc(sizeInBytes * (len + pProp->size)); if (!data) - return(BadAlloc); + return BadAlloc; memcpy(data + totalSize, pProp->data, pProp->size * sizeInBytes); memcpy(data, value, totalSize); pProp->data = data; @@ -353,12 +352,12 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property, if (rc == Success) { if (savedProp.data != pProp->data) - xfree(savedProp.data); + free(savedProp.data); } else { if (savedProp.data != pProp->data) - xfree(pProp->data); + free(pProp->data); *pProp = savedProp; return rc; } @@ -369,7 +368,7 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property, if (sendevent) deliverPropertyNotifyEvent(pWin, PropertyNewValue, pProp->propertyName); - return(Success); + return Success; } int @@ -405,9 +404,8 @@ DeleteProperty(ClientPtr client, WindowPtr pWin, Atom propName) } deliverPropertyNotifyEvent(pWin, PropertyDelete, pProp->propertyName); - dixFreePrivates(pProp->devPrivates); - xfree(pProp->data); - xfree(pProp); + free(pProp->data); + dixFreeObjectWithPrivates(pProp, PRIVATE_PROPERTY); } return rc; } @@ -422,9 +420,8 @@ DeleteAllWindowProperties(WindowPtr pWin) { deliverPropertyNotifyEvent(pWin, PropertyDelete, pProp->propertyName); pNextProp = pProp->next; - dixFreePrivates(pProp->devPrivates); - xfree(pProp->data); - xfree(pProp); + free(pProp->data); + dixFreeObjectWithPrivates(pProp, PRIVATE_PROPERTY); pProp = pNextProp; } } @@ -442,7 +439,7 @@ NullPropertyReply( reply->propertyType = propertyType; reply->format = format; WriteReplyToClient(client, sizeof(xGenericReply), reply); - return(client->noClientException); + return Success; } /***************** @@ -479,17 +476,17 @@ ProcGetProperty(ClientPtr client) if (!ValidAtom(stuff->property)) { client->errorValue = stuff->property; - return(BadAtom); + return BadAtom; } if ((stuff->delete != xTrue) && (stuff->delete != xFalse)) { client->errorValue = stuff->delete; - return(BadValue); + return BadValue; } if ((stuff->type != AnyPropertyType) && !ValidAtom(stuff->type)) { client->errorValue = stuff->type; - return(BadAtom); + return BadAtom; } memset(&reply, 0, sizeof(xGetPropertyReply)); @@ -515,7 +512,7 @@ ProcGetProperty(ClientPtr client) reply.nItems = 0; reply.propertyType = pProp->type; WriteReplyToClient(client, sizeof(xGenericReply), &reply); - return(Success); + return Success; } /* @@ -570,11 +567,10 @@ ProcGetProperty(ClientPtr client) prevProp->next = pProp->next; } - dixFreePrivates(pProp->devPrivates); - xfree(pProp->data); - xfree(pProp); + free(pProp->data); + dixFreeObjectWithPrivates(pProp, PRIVATE_PROPERTY); } - return(client->noClientException); + return Success; } int @@ -595,7 +591,7 @@ ProcListProperties(ClientPtr client) for (pProp = wUserProps(pWin); pProp; pProp = pProp->next) numProps++; - if (numProps && !(pAtoms = xalloc(numProps * sizeof(Atom)))) + if (numProps && !(pAtoms = malloc(numProps * sizeof(Atom)))) return BadAlloc; numProps = 0; @@ -619,8 +615,8 @@ ProcListProperties(ClientPtr client) client->pSwapReplyFunc = (ReplySwapPtr)Swap32Write; WriteSwappedDataToClient(client, numProps * sizeof(Atom), pAtoms); } - xfree(pAtoms); - return(client->noClientException); + free(pAtoms); + return Success; } int @@ -638,12 +634,8 @@ ProcDeleteProperty(ClientPtr client) if (!ValidAtom(stuff->property)) { client->errorValue = stuff->property; - return (BadAtom); + return BadAtom; } - result = DeleteProperty(client, pWin, stuff->property); - if (client->noClientException != Success) - return(client->noClientException); - else - return(result); + return DeleteProperty(client, pWin, stuff->property); } diff --git a/xserver/dix/ptrveloc.c b/xserver/dix/ptrveloc.c index c2f43784c..30e14b17e 100644 --- a/xserver/dix/ptrveloc.c +++ b/xserver/dix/ptrveloc.c @@ -83,8 +83,6 @@ GetAccelerationProfile(DeviceVelocityPtr vel, int profile_num); /* some int which is not a profile number */ #define PROFILE_UNINITIALIZE (-100) -/* number of properties for predictable acceleration */ -#define NPROPS_PREDICTABLE_ACCEL 4 /** * Init struct so it should match the average case @@ -113,7 +111,7 @@ InitVelocityData(DeviceVelocityPtr vel) */ void FreeVelocityData(DeviceVelocityPtr vel){ - xfree(vel->tracker); + free(vel->tracker); SetAccelerationProfile(vel, PROFILE_UNINITIALIZE); } @@ -129,7 +127,7 @@ AccelerationDefaultCleanup(DeviceIntPtr dev) && dev->valuator->accelScheme.accelData != NULL){ dev->valuator->accelScheme.AccelSchemeProc = NULL; FreeVelocityData(dev->valuator->accelScheme.accelData); - xfree(dev->valuator->accelScheme.accelData); + free(dev->valuator->accelScheme.accelData); dev->valuator->accelScheme.accelData = NULL; DeletePredictableAccelerationProperties(dev); } @@ -323,26 +321,18 @@ AccelInitScaleProperty(DeviceIntPtr dev, DeviceVelocityPtr vel) return XIRegisterPropertyHandler(dev, AccelSetScaleProperty, NULL, NULL); } -static int AccelPropHandlerPrivateKeyIndex; -DevPrivateKey AccelPropHandlerPrivateKey = &AccelPropHandlerPrivateKeyIndex; - BOOL InitializePredictableAccelerationProperties(DeviceIntPtr dev) { DeviceVelocityPtr vel = GetDevicePredictableAccelData(dev); - long *prop_handlers; if(!vel) return FALSE; - prop_handlers = xalloc(NPROPS_PREDICTABLE_ACCEL * sizeof(long)); - - prop_handlers[0] = AccelInitProfileProperty(dev, vel); - prop_handlers[1] = AccelInitDecelProperty(dev, vel); - prop_handlers[2] = AccelInitAdaptDecelProperty(dev, vel); - prop_handlers[3] = AccelInitScaleProperty(dev, vel); - dixSetPrivate(&dev->devPrivates, AccelPropHandlerPrivateKey, - prop_handlers); + vel->prop_handlers[0] = AccelInitProfileProperty(dev, vel); + vel->prop_handlers[1] = AccelInitDecelProperty(dev, vel); + vel->prop_handlers[2] = AccelInitAdaptDecelProperty(dev, vel); + vel->prop_handlers[3] = AccelInitScaleProperty(dev, vel); return TRUE; } @@ -350,8 +340,8 @@ InitializePredictableAccelerationProperties(DeviceIntPtr dev) BOOL DeletePredictableAccelerationProperties(DeviceIntPtr dev) { + DeviceVelocityPtr vel; Atom prop; - long *prop_handlers; int i; prop = XIGetKnownProperty(ACCEL_PROP_VELOCITY_SCALING); @@ -363,13 +353,10 @@ DeletePredictableAccelerationProperties(DeviceIntPtr dev) prop = XIGetKnownProperty(ACCEL_PROP_PROFILE_NUMBER); XIDeleteDeviceProperty(dev, prop, FALSE); - prop_handlers = dixLookupPrivate(&dev->devPrivates, - AccelPropHandlerPrivateKey); - dixSetPrivate(&dev->devPrivates, AccelPropHandlerPrivateKey, NULL); - - for (i = 0; prop_handlers && i < NPROPS_PREDICTABLE_ACCEL; i++) - XIUnregisterPropertyHandler(dev, prop_handlers[i]); - xfree(prop_handlers); + vel = GetDevicePredictableAccelData(dev); + for (i = 0; vel && i < NPROPS_PREDICTABLE_ACCEL; i++) + if (vel->prop_handlers[i]) + XIUnregisterPropertyHandler(dev, vel->prop_handlers[i]); return TRUE; } @@ -385,8 +372,8 @@ InitTrackers(DeviceVelocityPtr vel, int ntracker) ErrorF("(dix ptracc) invalid number of trackers\n"); return; } - xfree(vel->tracker); - vel->tracker = (MotionTrackerPtr)xalloc(ntracker * sizeof(MotionTracker)); + free(vel->tracker); + vel->tracker = (MotionTrackerPtr)malloc(ntracker * sizeof(MotionTracker)); memset(vel->tracker, 0, ntracker * sizeof(MotionTracker)); vel->num_tracker = ntracker; } @@ -507,7 +494,7 @@ CalcTracker(DeviceVelocityPtr vel, int offset, int cur_t){ + vel->tracker[index].dy * vel->tracker[index].dy); int dtime = cur_t - vel->tracker[index].time; if(dtime > 0) - return (dist / dtime); + return dist / dtime; else return 0;/* synonymous for NaN, since we're not C99 */ } @@ -967,7 +954,7 @@ SetAccelerationProfile( if(vel->profile_private != NULL){ /* Here one could free old profile-private data */ - xfree(vel->profile_private); + free(vel->profile_private); vel->profile_private = NULL; } /* Here one could init profile-private data */ diff --git a/xserver/dix/region.c b/xserver/dix/region.c new file mode 100644 index 000000000..5ba345773 --- /dev/null +++ b/xserver/dix/region.c @@ -0,0 +1,1659 @@ +/*********************************************************** + +Copyright 1987, 1988, 1989, 1998 The Open Group + +Permission to use, copy, modify, distribute, and sell this software and its +documentation for any purpose is hereby granted without fee, provided that +the above copyright notice appear in all copies and that both that +copyright notice and this permission notice appear in supporting +documentation. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from The Open Group. + + +Copyright 1987, 1988, 1989 by +Digital Equipment Corporation, Maynard, Massachusetts. + + All Rights Reserved + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose and without fee is hereby granted, +provided that the above copyright notice appear in all copies and that +both that copyright notice and this permission notice appear in +supporting documentation, and that the name of Digital not be +used in advertising or publicity pertaining to distribution of the +software without specific, written prior permission. + +DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING +ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL +DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR +ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS +SOFTWARE. + +******************************************************************/ + +/* The panoramix components contained the following notice */ +/***************************************************************** + +Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING, +BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR +IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of Digital Equipment Corporation +shall not be used in advertising or otherwise to promote the sale, use or other +dealings in this Software without prior written authorization from Digital +Equipment Corporation. + +******************************************************************/ + +#ifdef HAVE_DIX_CONFIG_H +#include <dix-config.h> +#endif + +#include "regionstr.h" +#include <X11/Xprotostr.h> +#include <X11/Xfuncproto.h> +#include "gc.h" +#include <pixman.h> + +#undef assert +#ifdef REGION_DEBUG +#define assert(expr) { \ + CARD32 *foo = NULL; \ + if (!(expr)) { \ + ErrorF("Assertion failed file %s, line %d: %s\n", \ + __FILE__, __LINE__, #expr); \ + *foo = 0xdeadbeef; /* to get a backtrace */ \ + } \ + } +#else +#define assert(expr) +#endif + +#define good(reg) assert(RegionIsValid(reg)) + +/* + * The functions in this file implement the Region abstraction used extensively + * throughout the X11 sample server. A Region is simply a set of disjoint + * (non-overlapping) rectangles, plus an "extent" rectangle which is the + * smallest single rectangle that contains all the non-overlapping rectangles. + * + * A Region is implemented as a "y-x-banded" array of rectangles. This array + * imposes two degrees of order. First, all rectangles are sorted by top side + * y coordinate first (y1), and then by left side x coordinate (x1). + * + * Furthermore, the rectangles are grouped into "bands". Each rectangle in a + * band has the same top y coordinate (y1), and each has the same bottom y + * coordinate (y2). Thus all rectangles in a band differ only in their left + * and right side (x1 and x2). Bands are implicit in the array of rectangles: + * there is no separate list of band start pointers. + * + * The y-x band representation does not minimize rectangles. In particular, + * if a rectangle vertically crosses a band (the rectangle has scanlines in + * the y1 to y2 area spanned by the band), then the rectangle may be broken + * down into two or more smaller rectangles stacked one atop the other. + * + * ----------- ----------- + * | | | | band 0 + * | | -------- ----------- -------- + * | | | | in y-x banded | | | | band 1 + * | | | | form is | | | | + * ----------- | | ----------- -------- + * | | | | band 2 + * -------- -------- + * + * An added constraint on the rectangles is that they must cover as much + * horizontal area as possible: no two rectangles within a band are allowed + * to touch. + * + * Whenever possible, bands will be merged together to cover a greater vertical + * distance (and thus reduce the number of rectangles). Two bands can be merged + * only if the bottom of one touches the top of the other and they have + * rectangles in the same places (of the same width, of course). + * + * Adam de Boor wrote most of the original region code. Joel McCormack + * substantially modified or rewrote most of the core arithmetic routines, + * and added RegionValidate in order to support several speed improvements + * to miValidateTree. Bob Scheifler changed the representation to be more + * compact when empty or a single rectangle, and did a bunch of gratuitous + * reformatting. + */ + +/* true iff two Boxes overlap */ +#define EXTENTCHECK(r1,r2) \ + (!( ((r1)->x2 <= (r2)->x1) || \ + ((r1)->x1 >= (r2)->x2) || \ + ((r1)->y2 <= (r2)->y1) || \ + ((r1)->y1 >= (r2)->y2) ) ) + +/* true iff (x,y) is in Box */ +#define INBOX(r,x,y) \ + ( ((r)->x2 > x) && \ + ((r)->x1 <= x) && \ + ((r)->y2 > y) && \ + ((r)->y1 <= y) ) + +/* true iff Box r1 contains Box r2 */ +#define SUBSUMES(r1,r2) \ + ( ((r1)->x1 <= (r2)->x1) && \ + ((r1)->x2 >= (r2)->x2) && \ + ((r1)->y1 <= (r2)->y1) && \ + ((r1)->y2 >= (r2)->y2) ) + +#define xallocData(n) malloc(RegionSizeof(n)) +#define xfreeData(reg) if ((reg)->data && (reg)->data->size) free((reg)->data) + +#define RECTALLOC_BAIL(pReg,n,bail) \ +if (!(pReg)->data || (((pReg)->data->numRects + (n)) > (pReg)->data->size)) \ + if (!RegionRectAlloc(pReg, n)) { goto bail; } + +#define RECTALLOC(pReg,n) \ +if (!(pReg)->data || (((pReg)->data->numRects + (n)) > (pReg)->data->size)) \ + if (!RegionRectAlloc(pReg, n)) { return FALSE; } + +#define ADDRECT(pNextRect,nx1,ny1,nx2,ny2) \ +{ \ + pNextRect->x1 = nx1; \ + pNextRect->y1 = ny1; \ + pNextRect->x2 = nx2; \ + pNextRect->y2 = ny2; \ + pNextRect++; \ +} + +#define NEWRECT(pReg,pNextRect,nx1,ny1,nx2,ny2) \ +{ \ + if (!(pReg)->data || ((pReg)->data->numRects == (pReg)->data->size))\ + { \ + if (!RegionRectAlloc(pReg, 1)) \ + return FALSE; \ + pNextRect = RegionTop(pReg); \ + } \ + ADDRECT(pNextRect,nx1,ny1,nx2,ny2); \ + pReg->data->numRects++; \ + assert(pReg->data->numRects<=pReg->data->size); \ +} + + +#define DOWNSIZE(reg,numRects) \ +if (((numRects) < ((reg)->data->size >> 1)) && ((reg)->data->size > 50)) \ +{ \ + RegDataPtr NewData; \ + NewData = (RegDataPtr)realloc((reg)->data, RegionSizeof(numRects)); \ + if (NewData) \ + { \ + NewData->size = (numRects); \ + (reg)->data = NewData; \ + } \ +} + + +BoxRec RegionEmptyBox = {0, 0, 0, 0}; +RegDataRec RegionEmptyData = {0, 0}; + +RegDataRec RegionBrokenData = {0, 0}; +static RegionRec RegionBrokenRegion = { { 0, 0, 0, 0 }, &RegionBrokenData }; + +void +InitRegions (void) +{ + pixman_region_set_static_pointers (&RegionEmptyBox, &RegionEmptyData, &RegionBrokenData); +} + +/***************************************************************** + * RegionCreate(rect, size) + * This routine does a simple malloc to make a structure of + * REGION of "size" number of rectangles. + *****************************************************************/ + +RegionPtr +RegionCreate(BoxPtr rect, int size) +{ + RegionPtr pReg; + + pReg = (RegionPtr)malloc(sizeof(RegionRec)); + if (!pReg) + return &RegionBrokenRegion; + + RegionInit (pReg, rect, size); + + return pReg; +} + +void +RegionDestroy(RegionPtr pReg) +{ + pixman_region_fini (pReg); + if (pReg != &RegionBrokenRegion) + free(pReg); +} + +void +RegionPrint(RegionPtr rgn) +{ + int num, size; + int i; + BoxPtr rects; + + num = RegionNumRects(rgn); + size = RegionSize(rgn); + rects = RegionRects(rgn); + ErrorF("[mi] num: %d size: %d\n", num, size); + ErrorF("[mi] extents: %d %d %d %d\n", + rgn->extents.x1, rgn->extents.y1, rgn->extents.x2, rgn->extents.y2); + for (i = 0; i < num; i++) + ErrorF("[mi] %d %d %d %d \n", + rects[i].x1, rects[i].y1, rects[i].x2, rects[i].y2); + ErrorF("[mi] \n"); +} + +#ifdef DEBUG +Bool +RegionIsValid(RegionPtr reg) +{ + int i, numRects; + + if ((reg->extents.x1 > reg->extents.x2) || + (reg->extents.y1 > reg->extents.y2)) + return FALSE; + numRects = RegionNumRects(reg); + if (!numRects) + return ((reg->extents.x1 == reg->extents.x2) && + (reg->extents.y1 == reg->extents.y2) && + (reg->data->size || (reg->data == &RegionEmptyData))); + else if (numRects == 1) + return !reg->data; + else + { + BoxPtr pboxP, pboxN; + BoxRec box; + + pboxP = RegionRects(reg); + box = *pboxP; + box.y2 = pboxP[numRects-1].y2; + pboxN = pboxP + 1; + for (i = numRects; --i > 0; pboxP++, pboxN++) + { + if ((pboxN->x1 >= pboxN->x2) || + (pboxN->y1 >= pboxN->y2)) + return FALSE; + if (pboxN->x1 < box.x1) + box.x1 = pboxN->x1; + if (pboxN->x2 > box.x2) + box.x2 = pboxN->x2; + if ((pboxN->y1 < pboxP->y1) || + ((pboxN->y1 == pboxP->y1) && + ((pboxN->x1 < pboxP->x2) || (pboxN->y2 != pboxP->y2)))) + return FALSE; + } + return ((box.x1 == reg->extents.x1) && + (box.x2 == reg->extents.x2) && + (box.y1 == reg->extents.y1) && + (box.y2 == reg->extents.y2)); + } +} +#endif /* DEBUG */ + +Bool +RegionBreak (RegionPtr pReg) +{ + xfreeData (pReg); + pReg->extents = RegionEmptyBox; + pReg->data = &RegionBrokenData; + return FALSE; +} + +Bool +RegionRectAlloc(RegionPtr pRgn, int n) +{ + RegDataPtr data; + + if (!pRgn->data) + { + n++; + pRgn->data = xallocData(n); + if (!pRgn->data) + return RegionBreak (pRgn); + pRgn->data->numRects = 1; + *RegionBoxptr(pRgn) = pRgn->extents; + } + else if (!pRgn->data->size) + { + pRgn->data = xallocData(n); + if (!pRgn->data) + return RegionBreak (pRgn); + pRgn->data->numRects = 0; + } + else + { + if (n == 1) + { + n = pRgn->data->numRects; + if (n > 500) /* XXX pick numbers out of a hat */ + n = 250; + } + n += pRgn->data->numRects; + data = (RegDataPtr)realloc(pRgn->data, RegionSizeof(n)); + if (!data) + return RegionBreak (pRgn); + pRgn->data = data; + } + pRgn->data->size = n; + return TRUE; +} + +/*====================================================================== + * Generic Region Operator + *====================================================================*/ + +/*- + *----------------------------------------------------------------------- + * RegionCoalesce -- + * Attempt to merge the boxes in the current band with those in the + * previous one. We are guaranteed that the current band extends to + * the end of the rects array. Used only by RegionOp. + * + * Results: + * The new index for the previous band. + * + * Side Effects: + * If coalescing takes place: + * - rectangles in the previous band will have their y2 fields + * altered. + * - pReg->data->numRects will be decreased. + * + *----------------------------------------------------------------------- + */ +_X_INLINE static int +RegionCoalesce ( + RegionPtr pReg, /* Region to coalesce */ + int prevStart, /* Index of start of previous band */ + int curStart) /* Index of start of current band */ +{ + BoxPtr pPrevBox; /* Current box in previous band */ + BoxPtr pCurBox; /* Current box in current band */ + int numRects; /* Number rectangles in both bands */ + int y2; /* Bottom of current band */ + /* + * Figure out how many rectangles are in the band. + */ + numRects = curStart - prevStart; + assert(numRects == pReg->data->numRects - curStart); + + if (!numRects) return curStart; + + /* + * The bands may only be coalesced if the bottom of the previous + * matches the top scanline of the current. + */ + pPrevBox = RegionBox(pReg, prevStart); + pCurBox = RegionBox(pReg, curStart); + if (pPrevBox->y2 != pCurBox->y1) return curStart; + + /* + * Make sure the bands have boxes in the same places. This + * assumes that boxes have been added in such a way that they + * cover the most area possible. I.e. two boxes in a band must + * have some horizontal space between them. + */ + y2 = pCurBox->y2; + + do { + if ((pPrevBox->x1 != pCurBox->x1) || (pPrevBox->x2 != pCurBox->x2)) { + return curStart; + } + pPrevBox++; + pCurBox++; + numRects--; + } while (numRects); + + /* + * The bands may be merged, so set the bottom y of each box + * in the previous band to the bottom y of the current band. + */ + numRects = curStart - prevStart; + pReg->data->numRects -= numRects; + do { + pPrevBox--; + pPrevBox->y2 = y2; + numRects--; + } while (numRects); + return prevStart; +} + + +/* Quicky macro to avoid trivial reject procedure calls to RegionCoalesce */ + +#define Coalesce(newReg, prevBand, curBand) \ + if (curBand - prevBand == newReg->data->numRects - curBand) { \ + prevBand = RegionCoalesce(newReg, prevBand, curBand); \ + } else { \ + prevBand = curBand; \ + } + +/*- + *----------------------------------------------------------------------- + * RegionAppendNonO -- + * Handle a non-overlapping band for the union and subtract operations. + * Just adds the (top/bottom-clipped) rectangles into the region. + * Doesn't have to check for subsumption or anything. + * + * Results: + * None. + * + * Side Effects: + * pReg->data->numRects is incremented and the rectangles overwritten + * with the rectangles we're passed. + * + *----------------------------------------------------------------------- + */ + +_X_INLINE static Bool +RegionAppendNonO ( + RegionPtr pReg, + BoxPtr r, + BoxPtr rEnd, + int y1, + int y2) +{ + BoxPtr pNextRect; + int newRects; + + newRects = rEnd - r; + + assert(y1 < y2); + assert(newRects != 0); + + /* Make sure we have enough space for all rectangles to be added */ + RECTALLOC(pReg, newRects); + pNextRect = RegionTop(pReg); + pReg->data->numRects += newRects; + do { + assert(r->x1 < r->x2); + ADDRECT(pNextRect, r->x1, y1, r->x2, y2); + r++; + } while (r != rEnd); + + return TRUE; +} + +#define FindBand(r, rBandEnd, rEnd, ry1) \ +{ \ + ry1 = r->y1; \ + rBandEnd = r+1; \ + while ((rBandEnd != rEnd) && (rBandEnd->y1 == ry1)) { \ + rBandEnd++; \ + } \ +} + +#define AppendRegions(newReg, r, rEnd) \ +{ \ + int newRects; \ + if ((newRects = rEnd - r)) { \ + RECTALLOC(newReg, newRects); \ + memmove((char *)RegionTop(newReg),(char *)r, \ + newRects * sizeof(BoxRec)); \ + newReg->data->numRects += newRects; \ + } \ +} + +/*- + *----------------------------------------------------------------------- + * RegionOp -- + * Apply an operation to two regions. Called by RegionUnion, RegionInverse, + * RegionSubtract, RegionIntersect.... Both regions MUST have at least one + * rectangle, and cannot be the same object. + * + * Results: + * TRUE if successful. + * + * Side Effects: + * The new region is overwritten. + * pOverlap set to TRUE if overlapFunc ever returns TRUE. + * + * Notes: + * The idea behind this function is to view the two regions as sets. + * Together they cover a rectangle of area that this function divides + * into horizontal bands where points are covered only by one region + * or by both. For the first case, the nonOverlapFunc is called with + * each the band and the band's upper and lower extents. For the + * second, the overlapFunc is called to process the entire band. It + * is responsible for clipping the rectangles in the band, though + * this function provides the boundaries. + * At the end of each band, the new region is coalesced, if possible, + * to reduce the number of rectangles in the region. + * + *----------------------------------------------------------------------- + */ + +typedef Bool (*OverlapProcPtr)( + RegionPtr pReg, + BoxPtr r1, + BoxPtr r1End, + BoxPtr r2, + BoxPtr r2End, + short y1, + short y2, + Bool *pOverlap); + +static Bool +RegionOp( + RegionPtr newReg, /* Place to store result */ + RegionPtr reg1, /* First region in operation */ + RegionPtr reg2, /* 2d region in operation */ + OverlapProcPtr overlapFunc, /* Function to call for over- + * lapping bands */ + Bool appendNon1, /* Append non-overlapping bands */ + /* in region 1 ? */ + Bool appendNon2, /* Append non-overlapping bands */ + /* in region 2 ? */ + Bool *pOverlap) +{ + BoxPtr r1; /* Pointer into first region */ + BoxPtr r2; /* Pointer into 2d region */ + BoxPtr r1End; /* End of 1st region */ + BoxPtr r2End; /* End of 2d region */ + short ybot; /* Bottom of intersection */ + short ytop; /* Top of intersection */ + RegDataPtr oldData; /* Old data for newReg */ + int prevBand; /* Index of start of + * previous band in newReg */ + int curBand; /* Index of start of current + * band in newReg */ + BoxPtr r1BandEnd; /* End of current band in r1 */ + BoxPtr r2BandEnd; /* End of current band in r2 */ + short top; /* Top of non-overlapping band */ + short bot; /* Bottom of non-overlapping band*/ + int r1y1; /* Temps for r1->y1 and r2->y1 */ + int r2y1; + int newSize; + int numRects; + + /* + * Break any region computed from a broken region + */ + if (RegionNar (reg1) || RegionNar(reg2)) + return RegionBreak (newReg); + + /* + * Initialization: + * set r1, r2, r1End and r2End appropriately, save the rectangles + * of the destination region until the end in case it's one of + * the two source regions, then mark the "new" region empty, allocating + * another array of rectangles for it to use. + */ + + r1 = RegionRects(reg1); + newSize = RegionNumRects(reg1); + r1End = r1 + newSize; + numRects = RegionNumRects(reg2); + r2 = RegionRects(reg2); + r2End = r2 + numRects; + assert(r1 != r1End); + assert(r2 != r2End); + + oldData = NULL; + if (((newReg == reg1) && (newSize > 1)) || + ((newReg == reg2) && (numRects > 1))) + { + oldData = newReg->data; + newReg->data = &RegionEmptyData; + } + /* guess at new size */ + if (numRects > newSize) + newSize = numRects; + newSize <<= 1; + if (!newReg->data) + newReg->data = &RegionEmptyData; + else if (newReg->data->size) + newReg->data->numRects = 0; + if (newSize > newReg->data->size) + if (!RegionRectAlloc(newReg, newSize)) + return FALSE; + + /* + * Initialize ybot. + * In the upcoming loop, ybot and ytop serve different functions depending + * on whether the band being handled is an overlapping or non-overlapping + * band. + * In the case of a non-overlapping band (only one of the regions + * has points in the band), ybot is the bottom of the most recent + * intersection and thus clips the top of the rectangles in that band. + * ytop is the top of the next intersection between the two regions and + * serves to clip the bottom of the rectangles in the current band. + * For an overlapping band (where the two regions intersect), ytop clips + * the top of the rectangles of both regions and ybot clips the bottoms. + */ + + ybot = min(r1->y1, r2->y1); + + /* + * prevBand serves to mark the start of the previous band so rectangles + * can be coalesced into larger rectangles. qv. RegionCoalesce, above. + * In the beginning, there is no previous band, so prevBand == curBand + * (curBand is set later on, of course, but the first band will always + * start at index 0). prevBand and curBand must be indices because of + * the possible expansion, and resultant moving, of the new region's + * array of rectangles. + */ + prevBand = 0; + + do { + /* + * This algorithm proceeds one source-band (as opposed to a + * destination band, which is determined by where the two regions + * intersect) at a time. r1BandEnd and r2BandEnd serve to mark the + * rectangle after the last one in the current band for their + * respective regions. + */ + assert(r1 != r1End); + assert(r2 != r2End); + + FindBand(r1, r1BandEnd, r1End, r1y1); + FindBand(r2, r2BandEnd, r2End, r2y1); + + /* + * First handle the band that doesn't intersect, if any. + * + * Note that attention is restricted to one band in the + * non-intersecting region at once, so if a region has n + * bands between the current position and the next place it overlaps + * the other, this entire loop will be passed through n times. + */ + if (r1y1 < r2y1) { + if (appendNon1) { + top = max(r1y1, ybot); + bot = min(r1->y2, r2y1); + if (top != bot) { + curBand = newReg->data->numRects; + RegionAppendNonO(newReg, r1, r1BandEnd, top, bot); + Coalesce(newReg, prevBand, curBand); + } + } + ytop = r2y1; + } else if (r2y1 < r1y1) { + if (appendNon2) { + top = max(r2y1, ybot); + bot = min(r2->y2, r1y1); + if (top != bot) { + curBand = newReg->data->numRects; + RegionAppendNonO(newReg, r2, r2BandEnd, top, bot); + Coalesce(newReg, prevBand, curBand); + } + } + ytop = r1y1; + } else { + ytop = r1y1; + } + + /* + * Now see if we've hit an intersecting band. The two bands only + * intersect if ybot > ytop + */ + ybot = min(r1->y2, r2->y2); + if (ybot > ytop) { + curBand = newReg->data->numRects; + (* overlapFunc)(newReg, r1, r1BandEnd, r2, r2BandEnd, ytop, ybot, + pOverlap); + Coalesce(newReg, prevBand, curBand); + } + + /* + * If we've finished with a band (y2 == ybot) we skip forward + * in the region to the next band. + */ + if (r1->y2 == ybot) r1 = r1BandEnd; + if (r2->y2 == ybot) r2 = r2BandEnd; + + } while (r1 != r1End && r2 != r2End); + + /* + * Deal with whichever region (if any) still has rectangles left. + * + * We only need to worry about banding and coalescing for the very first + * band left. After that, we can just group all remaining boxes, + * regardless of how many bands, into one final append to the list. + */ + + if ((r1 != r1End) && appendNon1) { + /* Do first nonOverlap1Func call, which may be able to coalesce */ + FindBand(r1, r1BandEnd, r1End, r1y1); + curBand = newReg->data->numRects; + RegionAppendNonO(newReg, r1, r1BandEnd, max(r1y1, ybot), r1->y2); + Coalesce(newReg, prevBand, curBand); + /* Just append the rest of the boxes */ + AppendRegions(newReg, r1BandEnd, r1End); + + } else if ((r2 != r2End) && appendNon2) { + /* Do first nonOverlap2Func call, which may be able to coalesce */ + FindBand(r2, r2BandEnd, r2End, r2y1); + curBand = newReg->data->numRects; + RegionAppendNonO(newReg, r2, r2BandEnd, max(r2y1, ybot), r2->y2); + Coalesce(newReg, prevBand, curBand); + /* Append rest of boxes */ + AppendRegions(newReg, r2BandEnd, r2End); + } + + free(oldData); + + if (!(numRects = newReg->data->numRects)) + { + xfreeData(newReg); + newReg->data = &RegionEmptyData; + } + else if (numRects == 1) + { + newReg->extents = *RegionBoxptr(newReg); + xfreeData(newReg); + newReg->data = NULL; + } + else + { + DOWNSIZE(newReg, numRects); + } + + return TRUE; +} + +/*- + *----------------------------------------------------------------------- + * RegionSetExtents -- + * Reset the extents of a region to what they should be. Called by + * Subtract and Intersect as they can't figure it out along the + * way or do so easily, as Union can. + * + * Results: + * None. + * + * Side Effects: + * The region's 'extents' structure is overwritten. + * + *----------------------------------------------------------------------- + */ +static void +RegionSetExtents (RegionPtr pReg) +{ + BoxPtr pBox, pBoxEnd; + + if (!pReg->data) + return; + if (!pReg->data->size) + { + pReg->extents.x2 = pReg->extents.x1; + pReg->extents.y2 = pReg->extents.y1; + return; + } + + pBox = RegionBoxptr(pReg); + pBoxEnd = RegionEnd(pReg); + + /* + * Since pBox is the first rectangle in the region, it must have the + * smallest y1 and since pBoxEnd is the last rectangle in the region, + * it must have the largest y2, because of banding. Initialize x1 and + * x2 from pBox and pBoxEnd, resp., as good things to initialize them + * to... + */ + pReg->extents.x1 = pBox->x1; + pReg->extents.y1 = pBox->y1; + pReg->extents.x2 = pBoxEnd->x2; + pReg->extents.y2 = pBoxEnd->y2; + + assert(pReg->extents.y1 < pReg->extents.y2); + while (pBox <= pBoxEnd) { + if (pBox->x1 < pReg->extents.x1) + pReg->extents.x1 = pBox->x1; + if (pBox->x2 > pReg->extents.x2) + pReg->extents.x2 = pBox->x2; + pBox++; + }; + + assert(pReg->extents.x1 < pReg->extents.x2); +} + +/*====================================================================== + * Region Intersection + *====================================================================*/ +/*- + *----------------------------------------------------------------------- + * RegionIntersectO -- + * Handle an overlapping band for RegionIntersect. + * + * Results: + * TRUE if successful. + * + * Side Effects: + * Rectangles may be added to the region. + * + *----------------------------------------------------------------------- + */ +/*ARGSUSED*/ + +#define MERGERECT(r) \ +{ \ + if (r->x1 <= x2) { \ + /* Merge with current rectangle */ \ + if (r->x1 < x2) *pOverlap = TRUE; \ + if (x2 < r->x2) x2 = r->x2; \ + } else { \ + /* Add current rectangle, start new one */ \ + NEWRECT(pReg, pNextRect, x1, y1, x2, y2); \ + x1 = r->x1; \ + x2 = r->x2; \ + } \ + r++; \ +} + +/*====================================================================== + * Region Union + *====================================================================*/ + +/*- + *----------------------------------------------------------------------- + * RegionUnionO -- + * Handle an overlapping band for the union operation. Picks the + * left-most rectangle each time and merges it into the region. + * + * Results: + * TRUE if successful. + * + * Side Effects: + * pReg is overwritten. + * pOverlap is set to TRUE if any boxes overlap. + * + *----------------------------------------------------------------------- + */ +static Bool +RegionUnionO ( + RegionPtr pReg, + BoxPtr r1, + BoxPtr r1End, + BoxPtr r2, + BoxPtr r2End, + short y1, + short y2, + Bool *pOverlap) +{ + BoxPtr pNextRect; + int x1; /* left and right side of current union */ + int x2; + + assert (y1 < y2); + assert(r1 != r1End && r2 != r2End); + + pNextRect = RegionTop(pReg); + + /* Start off current rectangle */ + if (r1->x1 < r2->x1) + { + x1 = r1->x1; + x2 = r1->x2; + r1++; + } + else + { + x1 = r2->x1; + x2 = r2->x2; + r2++; + } + while (r1 != r1End && r2 != r2End) + { + if (r1->x1 < r2->x1) MERGERECT(r1) else MERGERECT(r2); + } + + /* Finish off whoever (if any) is left */ + if (r1 != r1End) + { + do + { + MERGERECT(r1); + } while (r1 != r1End); + } + else if (r2 != r2End) + { + do + { + MERGERECT(r2); + } while (r2 != r2End); + } + + /* Add current rectangle */ + NEWRECT(pReg, pNextRect, x1, y1, x2, y2); + + return TRUE; +} + +/*====================================================================== + * Batch Rectangle Union + *====================================================================*/ + +/*- + *----------------------------------------------------------------------- + * RegionAppend -- + * + * "Append" the rgn rectangles onto the end of dstrgn, maintaining + * knowledge of YX-banding when it's easy. Otherwise, dstrgn just + * becomes a non-y-x-banded random collection of rectangles, and not + * yet a true region. After a sequence of appends, the caller must + * call RegionValidate to ensure that a valid region is constructed. + * + * Results: + * TRUE if successful. + * + * Side Effects: + * dstrgn is modified if rgn has rectangles. + * + */ +Bool +RegionAppend(RegionPtr dstrgn, RegionPtr rgn) +{ + int numRects, dnumRects, size; + BoxPtr new, old; + Bool prepend; + + if (RegionNar(rgn)) + return RegionBreak (dstrgn); + + if (!rgn->data && (dstrgn->data == &RegionEmptyData)) + { + dstrgn->extents = rgn->extents; + dstrgn->data = NULL; + return TRUE; + } + + numRects = RegionNumRects(rgn); + if (!numRects) + return TRUE; + prepend = FALSE; + size = numRects; + dnumRects = RegionNumRects(dstrgn); + if (!dnumRects && (size < 200)) + size = 200; /* XXX pick numbers out of a hat */ + RECTALLOC(dstrgn, size); + old = RegionRects(rgn); + if (!dnumRects) + dstrgn->extents = rgn->extents; + else if (dstrgn->extents.x2 > dstrgn->extents.x1) + { + BoxPtr first, last; + + first = old; + last = RegionBoxptr(dstrgn) + (dnumRects - 1); + if ((first->y1 > last->y2) || + ((first->y1 == last->y1) && (first->y2 == last->y2) && + (first->x1 > last->x2))) + { + if (rgn->extents.x1 < dstrgn->extents.x1) + dstrgn->extents.x1 = rgn->extents.x1; + if (rgn->extents.x2 > dstrgn->extents.x2) + dstrgn->extents.x2 = rgn->extents.x2; + dstrgn->extents.y2 = rgn->extents.y2; + } + else + { + first = RegionBoxptr(dstrgn); + last = old + (numRects - 1); + if ((first->y1 > last->y2) || + ((first->y1 == last->y1) && (first->y2 == last->y2) && + (first->x1 > last->x2))) + { + prepend = TRUE; + if (rgn->extents.x1 < dstrgn->extents.x1) + dstrgn->extents.x1 = rgn->extents.x1; + if (rgn->extents.x2 > dstrgn->extents.x2) + dstrgn->extents.x2 = rgn->extents.x2; + dstrgn->extents.y1 = rgn->extents.y1; + } + else + dstrgn->extents.x2 = dstrgn->extents.x1; + } + } + if (prepend) + { + new = RegionBox(dstrgn, numRects); + if (dnumRects == 1) + *new = *RegionBoxptr(dstrgn); + else + memmove((char *)new,(char *)RegionBoxptr(dstrgn), + dnumRects * sizeof(BoxRec)); + new = RegionBoxptr(dstrgn); + } + else + new = RegionBoxptr(dstrgn) + dnumRects; + if (numRects == 1) + *new = *old; + else + memmove((char *)new, (char *)old, numRects * sizeof(BoxRec)); + dstrgn->data->numRects += numRects; + return TRUE; +} + + +#define ExchangeRects(a, b) \ +{ \ + BoxRec t; \ + t = rects[a]; \ + rects[a] = rects[b]; \ + rects[b] = t; \ +} + +static void +QuickSortRects( + BoxRec rects[], + int numRects) +{ + int y1; + int x1; + int i, j; + BoxPtr r; + + /* Always called with numRects > 1 */ + + do + { + if (numRects == 2) + { + if (rects[0].y1 > rects[1].y1 || + (rects[0].y1 == rects[1].y1 && rects[0].x1 > rects[1].x1)) + ExchangeRects(0, 1); + return; + } + + /* Choose partition element, stick in location 0 */ + ExchangeRects(0, numRects >> 1); + y1 = rects[0].y1; + x1 = rects[0].x1; + + /* Partition array */ + i = 0; + j = numRects; + do + { + r = &(rects[i]); + do + { + r++; + i++; + } while (i != numRects && + (r->y1 < y1 || (r->y1 == y1 && r->x1 < x1))); + r = &(rects[j]); + do + { + r--; + j--; + } while (y1 < r->y1 || (y1 == r->y1 && x1 < r->x1)); + if (i < j) + ExchangeRects(i, j); + } while (i < j); + + /* Move partition element back to middle */ + ExchangeRects(0, j); + + /* Recurse */ + if (numRects-j-1 > 1) + QuickSortRects(&rects[j+1], numRects-j-1); + numRects = j; + } while (numRects > 1); +} + +/*- + *----------------------------------------------------------------------- + * RegionValidate -- + * + * Take a ``region'' which is a non-y-x-banded random collection of + * rectangles, and compute a nice region which is the union of all the + * rectangles. + * + * Results: + * TRUE if successful. + * + * Side Effects: + * The passed-in ``region'' may be modified. + * pOverlap set to TRUE if any retangles overlapped, else FALSE; + * + * Strategy: + * Step 1. Sort the rectangles into ascending order with primary key y1 + * and secondary key x1. + * + * Step 2. Split the rectangles into the minimum number of proper y-x + * banded regions. This may require horizontally merging + * rectangles, and vertically coalescing bands. With any luck, + * this step in an identity tranformation (ala the Box widget), + * or a coalescing into 1 box (ala Menus). + * + * Step 3. Merge the separate regions down to a single region by calling + * Union. Maximize the work each Union call does by using + * a binary merge. + * + *----------------------------------------------------------------------- + */ + +Bool +RegionValidate(RegionPtr badreg, Bool *pOverlap) +{ + /* Descriptor for regions under construction in Step 2. */ + typedef struct { + RegionRec reg; + int prevBand; + int curBand; + } RegionInfo; + + int numRects; /* Original numRects for badreg */ + RegionInfo *ri; /* Array of current regions */ + int numRI; /* Number of entries used in ri */ + int sizeRI; /* Number of entries available in ri */ + int i; /* Index into rects */ + int j; /* Index into ri */ + RegionInfo *rit; /* &ri[j] */ + RegionPtr reg; /* ri[j].reg */ + BoxPtr box; /* Current box in rects */ + BoxPtr riBox; /* Last box in ri[j].reg */ + RegionPtr hreg; /* ri[j_half].reg */ + Bool ret = TRUE; + + *pOverlap = FALSE; + if (!badreg->data) + { + good(badreg); + return TRUE; + } + numRects = badreg->data->numRects; + if (!numRects) + { + if (RegionNar(badreg)) + return FALSE; + good(badreg); + return TRUE; + } + if (badreg->extents.x1 < badreg->extents.x2) + { + if ((numRects) == 1) + { + xfreeData(badreg); + badreg->data = (RegDataPtr) NULL; + } + else + { + DOWNSIZE(badreg, numRects); + } + good(badreg); + return TRUE; + } + + /* Step 1: Sort the rects array into ascending (y1, x1) order */ + QuickSortRects(RegionBoxptr(badreg), numRects); + + /* Step 2: Scatter the sorted array into the minimum number of regions */ + + /* Set up the first region to be the first rectangle in badreg */ + /* Note that step 2 code will never overflow the ri[0].reg rects array */ + ri = (RegionInfo *) malloc(4 * sizeof(RegionInfo)); + if (!ri) + return RegionBreak (badreg); + sizeRI = 4; + numRI = 1; + ri[0].prevBand = 0; + ri[0].curBand = 0; + ri[0].reg = *badreg; + box = RegionBoxptr(&ri[0].reg); + ri[0].reg.extents = *box; + ri[0].reg.data->numRects = 1; + + /* Now scatter rectangles into the minimum set of valid regions. If the + next rectangle to be added to a region would force an existing rectangle + in the region to be split up in order to maintain y-x banding, just + forget it. Try the next region. If it doesn't fit cleanly into any + region, make a new one. */ + + for (i = numRects; --i > 0;) + { + box++; + /* Look for a region to append box to */ + for (j = numRI, rit = ri; --j >= 0; rit++) + { + reg = &rit->reg; + riBox = RegionEnd(reg); + + if (box->y1 == riBox->y1 && box->y2 == riBox->y2) + { + /* box is in same band as riBox. Merge or append it */ + if (box->x1 <= riBox->x2) + { + /* Merge it with riBox */ + if (box->x1 < riBox->x2) *pOverlap = TRUE; + if (box->x2 > riBox->x2) riBox->x2 = box->x2; + } + else + { + RECTALLOC_BAIL(reg, 1, bail); + *RegionTop(reg) = *box; + reg->data->numRects++; + } + goto NextRect; /* So sue me */ + } + else if (box->y1 >= riBox->y2) + { + /* Put box into new band */ + if (reg->extents.x2 < riBox->x2) reg->extents.x2 = riBox->x2; + if (reg->extents.x1 > box->x1) reg->extents.x1 = box->x1; + Coalesce(reg, rit->prevBand, rit->curBand); + rit->curBand = reg->data->numRects; + RECTALLOC_BAIL(reg, 1, bail); + *RegionTop(reg) = *box; + reg->data->numRects++; + goto NextRect; + } + /* Well, this region was inappropriate. Try the next one. */ + } /* for j */ + + /* Uh-oh. No regions were appropriate. Create a new one. */ + if (sizeRI == numRI) + { + /* Oops, allocate space for new region information */ + sizeRI <<= 1; + rit = (RegionInfo *) realloc(ri, sizeRI * sizeof(RegionInfo)); + if (!rit) + goto bail; + ri = rit; + rit = &ri[numRI]; + } + numRI++; + rit->prevBand = 0; + rit->curBand = 0; + rit->reg.extents = *box; + rit->reg.data = NULL; + if (!RegionRectAlloc(&rit->reg, (i+numRI) / numRI)) /* MUST force allocation */ + goto bail; +NextRect: ; + } /* for i */ + + /* Make a final pass over each region in order to Coalesce and set + extents.x2 and extents.y2 */ + + for (j = numRI, rit = ri; --j >= 0; rit++) + { + reg = &rit->reg; + riBox = RegionEnd(reg); + reg->extents.y2 = riBox->y2; + if (reg->extents.x2 < riBox->x2) reg->extents.x2 = riBox->x2; + Coalesce(reg, rit->prevBand, rit->curBand); + if (reg->data->numRects == 1) /* keep unions happy below */ + { + xfreeData(reg); + reg->data = NULL; + } + } + + /* Step 3: Union all regions into a single region */ + while (numRI > 1) + { + int half = numRI/2; + for (j = numRI & 1; j < (half + (numRI & 1)); j++) + { + reg = &ri[j].reg; + hreg = &ri[j+half].reg; + if (!RegionOp(reg, reg, hreg, RegionUnionO, TRUE, TRUE, pOverlap)) + ret = FALSE; + if (hreg->extents.x1 < reg->extents.x1) + reg->extents.x1 = hreg->extents.x1; + if (hreg->extents.y1 < reg->extents.y1) + reg->extents.y1 = hreg->extents.y1; + if (hreg->extents.x2 > reg->extents.x2) + reg->extents.x2 = hreg->extents.x2; + if (hreg->extents.y2 > reg->extents.y2) + reg->extents.y2 = hreg->extents.y2; + xfreeData(hreg); + } + numRI -= half; + } + *badreg = ri[0].reg; + free(ri); + good(badreg); + return ret; +bail: + for (i = 0; i < numRI; i++) + xfreeData(&ri[i].reg); + free(ri); + return RegionBreak (badreg); +} + +RegionPtr +RegionFromRects(int nrects, xRectangle *prect, int ctype) +{ + + RegionPtr pRgn; + RegDataPtr pData; + BoxPtr pBox; + int i; + int x1, y1, x2, y2; + + pRgn = RegionCreate(NullBox, 0); + if (RegionNar (pRgn)) + return pRgn; + if (!nrects) + return pRgn; + if (nrects == 1) + { + x1 = prect->x; + y1 = prect->y; + if ((x2 = x1 + (int) prect->width) > MAXSHORT) + x2 = MAXSHORT; + if ((y2 = y1 + (int) prect->height) > MAXSHORT) + y2 = MAXSHORT; + if (x1 != x2 && y1 != y2) + { + pRgn->extents.x1 = x1; + pRgn->extents.y1 = y1; + pRgn->extents.x2 = x2; + pRgn->extents.y2 = y2; + pRgn->data = NULL; + } + return pRgn; + } + pData = xallocData(nrects); + if (!pData) + { + RegionBreak (pRgn); + return pRgn; + } + pBox = (BoxPtr) (pData + 1); + for (i = nrects; --i >= 0; prect++) + { + x1 = prect->x; + y1 = prect->y; + if ((x2 = x1 + (int) prect->width) > MAXSHORT) + x2 = MAXSHORT; + if ((y2 = y1 + (int) prect->height) > MAXSHORT) + y2 = MAXSHORT; + if (x1 != x2 && y1 != y2) + { + pBox->x1 = x1; + pBox->y1 = y1; + pBox->x2 = x2; + pBox->y2 = y2; + pBox++; + } + } + if (pBox != (BoxPtr) (pData + 1)) + { + pData->size = nrects; + pData->numRects = pBox - (BoxPtr) (pData + 1); + pRgn->data = pData; + if (ctype != CT_YXBANDED) + { + Bool overlap; /* result ignored */ + pRgn->extents.x1 = pRgn->extents.x2 = 0; + RegionValidate(pRgn, &overlap); + } + else + RegionSetExtents(pRgn); + good(pRgn); + } + else + { + free(pData); + } + return pRgn; +} + +#define ExchangeSpans(a, b) \ +{ \ + DDXPointRec tpt; \ + int tw; \ + \ + tpt = spans[a]; spans[a] = spans[b]; spans[b] = tpt; \ + tw = widths[a]; widths[a] = widths[b]; widths[b] = tw; \ +} + +/* ||| I should apply the merge sort code to rectangle sorting above, and see + if mapping time can be improved. But right now I've been at work 12 hours, + so forget it. +*/ + +static void QuickSortSpans( + DDXPointRec spans[], + int widths[], + int numSpans) +{ + int y; + int i, j, m; + DDXPointPtr r; + + /* Always called with numSpans > 1 */ + /* Sorts only by y, doesn't bother to sort by x */ + + do + { + if (numSpans < 9) + { + /* Do insertion sort */ + int yprev; + + yprev = spans[0].y; + i = 1; + do + { /* while i != numSpans */ + y = spans[i].y; + if (yprev > y) + { + /* spans[i] is out of order. Move into proper location. */ + DDXPointRec tpt; + int tw, k; + + for (j = 0; y >= spans[j].y; j++) {} + tpt = spans[i]; + tw = widths[i]; + for (k = i; k != j; k--) + { + spans[k] = spans[k-1]; + widths[k] = widths[k-1]; + } + spans[j] = tpt; + widths[j] = tw; + y = spans[i].y; + } /* if out of order */ + yprev = y; + i++; + } while (i != numSpans); + return; + } + + /* Choose partition element, stick in location 0 */ + m = numSpans / 2; + if (spans[m].y > spans[0].y) ExchangeSpans(m, 0); + if (spans[m].y > spans[numSpans-1].y) ExchangeSpans(m, numSpans-1); + if (spans[m].y > spans[0].y) ExchangeSpans(m, 0); + y = spans[0].y; + + /* Partition array */ + i = 0; + j = numSpans; + do + { + r = &(spans[i]); + do + { + r++; + i++; + } while (i != numSpans && r->y < y); + r = &(spans[j]); + do + { + r--; + j--; + } while (y < r->y); + if (i < j) + ExchangeSpans(i, j); + } while (i < j); + + /* Move partition element back to middle */ + ExchangeSpans(0, j); + + /* Recurse */ + if (numSpans-j-1 > 1) + QuickSortSpans(&spans[j+1], &widths[j+1], numSpans-j-1); + numSpans = j; + } while (numSpans > 1); +} + +#define NextBand() \ +{ \ + clipy1 = pboxBandStart->y1; \ + clipy2 = pboxBandStart->y2; \ + pboxBandEnd = pboxBandStart + 1; \ + while (pboxBandEnd != pboxLast && pboxBandEnd->y1 == clipy1) { \ + pboxBandEnd++; \ + } \ + for (; ppt != pptLast && ppt->y < clipy1; ppt++, pwidth++) {} \ +} + +/* + Clip a list of scanlines to a region. The caller has allocated the + space. FSorted is non-zero if the scanline origins are in ascending + order. + returns the number of new, clipped scanlines. +*/ + +int +RegionClipSpans( + RegionPtr prgnDst, + DDXPointPtr ppt, + int *pwidth, + int nspans, + DDXPointPtr pptNew, + int *pwidthNew, + int fSorted) +{ + DDXPointPtr pptLast; + int *pwidthNewStart; /* the vengeance of Xerox! */ + int y, x1, x2; + int numRects; + + good(prgnDst); + pptLast = ppt + nspans; + pwidthNewStart = pwidthNew; + + if (!prgnDst->data) + { + /* Do special fast code with clip boundaries in registers(?) */ + /* It doesn't pay much to make use of fSorted in this case, + so we lump everything together. */ + + int clipx1, clipx2, clipy1, clipy2; + + clipx1 = prgnDst->extents.x1; + clipy1 = prgnDst->extents.y1; + clipx2 = prgnDst->extents.x2; + clipy2 = prgnDst->extents.y2; + + for (; ppt != pptLast; ppt++, pwidth++) + { + y = ppt->y; + x1 = ppt->x; + if (clipy1 <= y && y < clipy2) + { + x2 = x1 + *pwidth; + if (x1 < clipx1) x1 = clipx1; + if (x2 > clipx2) x2 = clipx2; + if (x1 < x2) + { + /* part of span in clip rectangle */ + pptNew->x = x1; + pptNew->y = y; + *pwidthNew = x2 - x1; + pptNew++; + pwidthNew++; + } + } + } /* end for */ + + } + else if ((numRects = prgnDst->data->numRects)) + { + /* Have to clip against many boxes */ + BoxPtr pboxBandStart, pboxBandEnd; + BoxPtr pbox; + BoxPtr pboxLast; + int clipy1, clipy2; + + /* In this case, taking advantage of sorted spans gains more than + the sorting costs. */ + if ((! fSorted) && (nspans > 1)) + QuickSortSpans(ppt, pwidth, nspans); + + pboxBandStart = RegionBoxptr(prgnDst); + pboxLast = pboxBandStart + numRects; + + NextBand(); + + for (; ppt != pptLast; ) + { + y = ppt->y; + if (y < clipy2) + { + /* span is in the current band */ + pbox = pboxBandStart; + x1 = ppt->x; + x2 = x1 + *pwidth; + do + { /* For each box in band */ + int newx1, newx2; + + newx1 = x1; + newx2 = x2; + if (newx1 < pbox->x1) newx1 = pbox->x1; + if (newx2 > pbox->x2) newx2 = pbox->x2; + if (newx1 < newx2) + { + /* Part of span in clip rectangle */ + pptNew->x = newx1; + pptNew->y = y; + *pwidthNew = newx2 - newx1; + pptNew++; + pwidthNew++; + } + pbox++; + } while (pbox != pboxBandEnd); + ppt++; + pwidth++; + } + else + { + /* Move to next band, adjust ppt as needed */ + pboxBandStart = pboxBandEnd; + if (pboxBandStart == pboxLast) + break; /* We're completely done */ + NextBand(); + } + } + } + return pwidthNew - pwidthNewStart; +} diff --git a/xserver/dix/registry.c b/xserver/dix/registry.c index 1381a3dcd..fc35dbbc7 100644 --- a/xserver/dix/registry.c +++ b/xserver/dix/registry.c @@ -61,7 +61,7 @@ static int double_size(void *p, unsigned n, unsigned size) n = f = BASE_SIZE * size; } - *ptr = xrealloc(*ptr, n); + *ptr = realloc(*ptr, n); if (!*ptr) { dixResetRegistry(); return FALSE; @@ -285,20 +285,20 @@ dixResetRegistry(void) while (nmajor--) { while (nminor[nmajor]) free(requests[nmajor][--nminor[nmajor]]); - xfree(requests[nmajor]); + free(requests[nmajor]); } - xfree(requests); - xfree(nminor); + free(requests); + free(nminor); while (nevent--) free(events[nevent]); - xfree(events); + free(events); while (nerror--) free(errors[nerror]); - xfree(errors); + free(errors); - xfree(resources); + free(resources); requests = NULL; nminor = NULL; diff --git a/xserver/dix/resource.c b/xserver/dix/resource.c index ab3762eb5..a0fe719de 100644 --- a/xserver/dix/resource.c +++ b/xserver/dix/resource.c @@ -183,7 +183,54 @@ RESTYPE lastResourceType; static RESTYPE lastResourceClass; RESTYPE TypeMask; -static DeleteType *DeleteFuncs = (DeleteType *)NULL; +struct ResourceType { + DeleteType deleteFunc; + int errorValue; +}; + +static struct ResourceType *resourceTypes; +static const struct ResourceType predefTypes[] = { + [RT_NONE & (RC_LASTPREDEF - 1)] = { + .deleteFunc = (DeleteType)NoopDDA, + .errorValue = BadValue, + }, + [RT_WINDOW & (RC_LASTPREDEF - 1)] = { + .deleteFunc = DeleteWindow, + .errorValue = BadWindow, + }, + [RT_PIXMAP & (RC_LASTPREDEF - 1)] = { + .deleteFunc = dixDestroyPixmap, + .errorValue = BadPixmap, + }, + [RT_GC & (RC_LASTPREDEF - 1)] = { + .deleteFunc = FreeGC, + .errorValue = BadGC, + }, + [RT_FONT & (RC_LASTPREDEF - 1)] = { + .deleteFunc = CloseFont, + .errorValue = BadFont, + }, + [RT_CURSOR & (RC_LASTPREDEF - 1)] = { + .deleteFunc = FreeCursor, + .errorValue = BadCursor, + }, + [RT_COLORMAP & (RC_LASTPREDEF - 1)] = { + .deleteFunc = FreeColormap, + .errorValue = BadColor, + }, + [RT_CMAPENTRY & (RC_LASTPREDEF - 1)] = { + .deleteFunc = FreeClientPixels, + .errorValue = BadColor, + }, + [RT_OTHERCLIENT & (RC_LASTPREDEF - 1)] = { + .deleteFunc = OtherClientGone, + .errorValue = BadValue, + }, + [RT_PASSIVEGRAB & (RC_LASTPREDEF - 1)] = { + .deleteFunc = DeletePassiveGrab, + .errorValue = BadValue, + }, +}; CallbackListPtr ResourceStateCallback; @@ -200,20 +247,18 @@ RESTYPE CreateNewResourceType(DeleteType deleteFunc, char *name) { RESTYPE next = lastResourceType + 1; - DeleteType *funcs; + struct ResourceType *types; if (next & lastResourceClass) return 0; - funcs = (DeleteType *)xrealloc(DeleteFuncs, - (next + 1) * sizeof(DeleteType)); - if (!funcs) - return 0; - if (!dixRegisterPrivateOffset(next, -1)) + types = realloc(resourceTypes, (next + 1) * sizeof(*resourceTypes)); + if (!types) return 0; lastResourceType = next; - DeleteFuncs = funcs; - DeleteFuncs[next] = deleteFunc; + resourceTypes = types; + resourceTypes[next].deleteFunc = deleteFunc; + resourceTypes[next].errorValue = BadValue; /* Called even if name is NULL, to remove any previous entry */ RegisterResourceName(next, name); @@ -221,6 +266,12 @@ CreateNewResourceType(DeleteType deleteFunc, char *name) return next; } +void +SetResourceTypeErrorValue(RESTYPE type, int errorValue) +{ + resourceTypes[type & TypeMask].errorValue = errorValue; +} + RESTYPE CreateNewResourceClass(void) { @@ -251,24 +302,14 @@ InitClientResources(ClientPtr client) lastResourceType = RT_LASTPREDEF; lastResourceClass = RC_LASTPREDEF; TypeMask = RC_LASTPREDEF - 1; - if (DeleteFuncs) - xfree(DeleteFuncs); - DeleteFuncs = xalloc((lastResourceType + 1) * sizeof(DeleteType)); - if (!DeleteFuncs) + free(resourceTypes); + resourceTypes = malloc(sizeof(predefTypes)); + if (!resourceTypes) return FALSE; - DeleteFuncs[RT_NONE & TypeMask] = (DeleteType)NoopDDA; - DeleteFuncs[RT_WINDOW & TypeMask] = DeleteWindow; - DeleteFuncs[RT_PIXMAP & TypeMask] = dixDestroyPixmap; - DeleteFuncs[RT_GC & TypeMask] = FreeGC; - DeleteFuncs[RT_FONT & TypeMask] = CloseFont; - DeleteFuncs[RT_CURSOR & TypeMask] = FreeCursor; - DeleteFuncs[RT_COLORMAP & TypeMask] = FreeColormap; - DeleteFuncs[RT_CMAPENTRY & TypeMask] = FreeClientPixels; - DeleteFuncs[RT_OTHERCLIENT & TypeMask] = OtherClientGone; - DeleteFuncs[RT_PASSIVEGRAB & TypeMask] = DeletePassiveGrab; + memcpy(resourceTypes, predefTypes, sizeof(predefTypes)); } clientTable[i = client->index].resources = - xalloc(INITBUCKETS*sizeof(ResourcePtr)); + malloc(INITBUCKETS*sizeof(ResourcePtr)); if (!clientTable[i].resources) return FALSE; clientTable[i].buckets = INITBUCKETS; @@ -459,10 +500,10 @@ AddResource(XID id, RESTYPE type, pointer value) (rrec->hashsize < MAXHASHSIZE)) RebuildTable(client); head = &rrec->resources[Hash(client, id)]; - res = xalloc(sizeof(ResourceRec)); + res = malloc(sizeof(ResourceRec)); if (!res) { - (*DeleteFuncs[type & TypeMask])(value, id); + (*resourceTypes[type & TypeMask].deleteFunc)(value, id); return FALSE; } res->next = *head; @@ -491,13 +532,13 @@ RebuildTable(int client) */ j = 2 * clientTable[client].buckets; - tails = xalloc(j * sizeof(ResourcePtr *)); + tails = malloc(j * sizeof(ResourcePtr *)); if (!tails) return; - resources = xalloc(j * sizeof(ResourcePtr)); + resources = malloc(j * sizeof(ResourcePtr)); if (!resources) { - xfree(tails); + free(tails); return; } for (rptr = resources, tptr = tails; --j >= 0; rptr++, tptr++) @@ -520,9 +561,9 @@ RebuildTable(int client) *tptr = &res->next; } } - xfree(tails); + free(tails); clientTable[client].buckets *= 2; - xfree(clientTable[client].resources); + free(clientTable[client].resources); clientTable[client].resources = resources; } @@ -557,8 +598,8 @@ FreeResource(XID id, RESTYPE skipDeleteFuncType) CallResourceStateCallback(ResourceStateFreeing, res); if (rtype != skipDeleteFuncType) - (*DeleteFuncs[rtype & TypeMask])(res->value, res->id); - xfree(res); + (*resourceTypes[rtype & TypeMask].deleteFunc)(res->value, res->id); + free(res); if (*eltptr != elements) prev = head; /* prev may no longer be valid */ } @@ -594,8 +635,8 @@ FreeResourceByType(XID id, RESTYPE type, Bool skipFree) CallResourceStateCallback(ResourceStateFreeing, res); if (!skipFree) - (*DeleteFuncs[type & TypeMask])(res->value, res->id); - xfree(res); + (*resourceTypes[type & TypeMask].deleteFunc)(res->value, res->id); + free(res); break; } else @@ -761,8 +802,8 @@ FreeClientNeverRetainResources(ClientPtr client) CallResourceStateCallback(ResourceStateFreeing, this); elements = *eltptr; - (*DeleteFuncs[rtype & TypeMask])(this->value, this->id); - xfree(this); + (*resourceTypes[rtype & TypeMask].deleteFunc)(this->value, this->id); + free(this); if (*eltptr != elements) prev = &resources[j]; /* prev may no longer be valid */ } @@ -815,11 +856,11 @@ FreeClientResources(ClientPtr client) CallResourceStateCallback(ResourceStateFreeing, this); - (*DeleteFuncs[rtype & TypeMask])(this->value, this->id); - xfree(this); + (*resourceTypes[rtype & TypeMask].deleteFunc)(this->value, this->id); + free(this); } } - xfree(clientTable[client->index].resources); + free(clientTable[client->index].resources); clientTable[client->index].resources = NULL; clientTable[client->index].buckets = 0; } @@ -860,7 +901,7 @@ LegalNewID(XID id, ClientPtr client) rc = dixLookupResourceByClass(&val, id, RC_ANY, serverClient, DixGetAttrAccess); - return (rc == BadValue); + return rc == BadValue; } return FALSE; } @@ -873,6 +914,8 @@ dixLookupResourceByType(pointer *result, XID id, RESTYPE rtype, ResourcePtr res = NULL; *result = NULL; + if ((rtype & TypeMask) > lastResourceType) + return BadImplementation; if ((cid < MAXCLIENTS) && clientTable[cid].buckets) { res = clientTable[cid].resources[Hash(cid, id)]; @@ -882,12 +925,14 @@ dixLookupResourceByType(pointer *result, XID id, RESTYPE rtype, break; } if (!res) - return BadValue; + return resourceTypes[rtype & TypeMask].errorValue; if (client) { client->errorValue = id; cid = XaceHook(XACE_RESOURCE_ACCESS, client, id, res->type, res->value, RT_NONE, NULL, mode); + if (cid == BadValue) + return resourceTypes[rtype & TypeMask].errorValue; if (cid != Success) return cid; } diff --git a/xserver/dix/selection.c b/xserver/dix/selection.c index d72f381ca..87ed1abe9 100644 --- a/xserver/dix/selection.c +++ b/xserver/dix/selection.c @@ -94,8 +94,7 @@ InitSelections(void) pSel = CurrentSelections; while (pSel) { pNextSel = pSel->next; - dixFreePrivates(pSel->devPrivates); - xfree(pSel); + dixFreeObjectWithPrivates(pSel, PRIVATE_SELECTION); pSel = pNextSel; } @@ -189,8 +188,7 @@ ProcSetSelectionOwner(ClientPtr client) event.u.selectionClear.time = time.milliseconds; event.u.selectionClear.window = pSel->window; event.u.selectionClear.atom = pSel->selection; - TryClientEvents(pSel->client, NULL, &event, 1, NoEventMask, - NoEventMask /* CantBeFiltered */, NullGrab); + WriteEventsToClient(pSel->client, 1, &event); } } else if (rc == BadMatch) @@ -198,18 +196,17 @@ ProcSetSelectionOwner(ClientPtr client) /* * It doesn't exist, so add it... */ - pSel = xalloc(sizeof(Selection)); + pSel = dixAllocateObjectWithPrivates(Selection, PRIVATE_SELECTION); if (!pSel) return BadAlloc; pSel->selection = stuff->selection; - pSel->devPrivates = NULL; /* security creation/labeling check */ rc = XaceHookSelectionAccess(client, &pSel, DixCreateAccess|DixSetAttrAccess); if (rc != Success) { - xfree(pSel); + free(pSel); return rc; } @@ -225,7 +222,7 @@ ProcSetSelectionOwner(ClientPtr client) pSel->client = (pWin ? client : NullClient); CallSelectionCallback(pSel, client, SelectionSetOwner); - return client->noClientException; + return Success; } int @@ -257,7 +254,7 @@ ProcGetSelectionOwner(ClientPtr client) return rc; WriteReplyToClient(client, sizeof(xGetSelectionOwnerReply), &reply); - return client->noClientException; + return Success; } int @@ -296,9 +293,11 @@ ProcConvertSelection(ClientPtr client) event.u.selectionRequest.selection = stuff->selection; event.u.selectionRequest.target = stuff->target; event.u.selectionRequest.property = stuff->property; - if (TryClientEvents(pSel->client, NULL, &event, 1, NoEventMask, - NoEventMask /* CantBeFiltered */, NullGrab)) - return client->noClientException; + if (pSel->client && pSel->client != serverClient && !pSel->client->clientGone) + { + WriteEventsToClient(pSel->client, 1, &event); + return Success; + } } event.u.u.type = SelectionNotify; @@ -307,7 +306,6 @@ ProcConvertSelection(ClientPtr client) event.u.selectionNotify.selection = stuff->selection; event.u.selectionNotify.target = stuff->target; event.u.selectionNotify.property = None; - TryClientEvents(client, NULL, &event, 1, NoEventMask, - NoEventMask /* CantBeFiltered */, NullGrab); - return client->noClientException; + WriteEventsToClient(client, 1, &event); + return Success; } diff --git a/xserver/dix/swaprep.c b/xserver/dix/swaprep.c index 12c6dbd26..c173411ab 100644 --- a/xserver/dix/swaprep.c +++ b/xserver/dix/swaprep.c @@ -99,7 +99,7 @@ CopySwap32Write(ClientPtr pClient, int size, CARD32 *pbuf) CARD32 tmpbuf[1]; /* Allocate as big a buffer as we can... */ - while (!(pbufT = xalloc(bufsize))) + while (!(pbufT = malloc(bufsize))) { bufsize >>= 1; if (bufsize == 4) @@ -131,7 +131,7 @@ CopySwap32Write(ClientPtr pClient, int size, CARD32 *pbuf) } if (pbufT != tmpbuf) - xfree (pbufT); + free(pbufT); } /** @@ -147,7 +147,7 @@ CopySwap16Write(ClientPtr pClient, int size, short *pbuf) short tmpbuf[2]; /* Allocate as big a buffer as we can... */ - while (!(pbufT = xalloc(bufsize))) + while (!(pbufT = malloc(bufsize))) { bufsize >>= 1; if (bufsize == 4) @@ -179,7 +179,7 @@ CopySwap16Write(ClientPtr pClient, int size, short *pbuf) } if (pbufT != tmpbuf) - xfree (pbufT); + free(pbufT); } @@ -1262,7 +1262,7 @@ WriteSConnectionInfo(ClientPtr pClient, unsigned long size, char *pInfo) { char *pInfoTBase; - pInfoTBase = xalloc(size); + pInfoTBase = malloc(size); if (!pInfoTBase) { pClient->noClientException = -1; @@ -1270,7 +1270,7 @@ WriteSConnectionInfo(ClientPtr pClient, unsigned long size, char *pInfo) } SwapConnSetupInfo(pInfo, pInfoTBase); (void)WriteToClient(pClient, (int)size, (char *) pInfoTBase); - xfree(pInfoTBase); + free(pInfoTBase); } void diff --git a/xserver/dix/swapreq.c b/xserver/dix/swapreq.c index 5d7d71c8f..2e34711c0 100644 --- a/xserver/dix/swapreq.c +++ b/xserver/dix/swapreq.c @@ -318,7 +318,7 @@ SProcSendEvent(ClientPtr client) /* Swap event */ proc = EventSwapVector[stuff->event.u.u.type & 0177]; if (!proc || proc == NotImplemented) /* no swapping proc; invalid event type? */ - return (BadValue); + return BadValue; (*proc)(&stuff->event, &eventT); stuff->event = eventT; diff --git a/xserver/dix/window.c b/xserver/dix/window.c index c7201df09..1913030cf 100644 --- a/xserver/dix/window.c +++ b/xserver/dix/window.c @@ -151,13 +151,7 @@ WindowSeekDeviceCursor(WindowPtr pWin, int screenIsSaved = SCREEN_SAVER_OFF; -ScreenSaverStuffRec savedScreenInfo[MAXSCREENS]; - -static int FocusPrivatesKeyIndex; -DevPrivateKey FocusPrivatesKey = &FocusPrivatesKeyIndex; - -static Bool TileScreenSaver(int i, int kind); - +static Bool TileScreenSaver(ScreenPtr pScreen, int kind); #define INPUTONLY_LEGAL_MASK (CWWinGravity | CWEventMask | \ CWDontPropagate | CWOverrideRedirect | CWCursor ) @@ -197,7 +191,7 @@ PrintChildren(WindowPtr p1, int indent) ErrorF("[dix] "); for (i=0; i<indent; i++) ErrorF(" "); ErrorF("%lx\n", p1->drawable.id); - miPrintRegion(&p1->clipList); + RegionPrint(&p1->clipList); PrintChildren(p2, indent+4); p1 = p1->nextSib; } @@ -212,8 +206,8 @@ PrintWindowTree(void) for (i=0; i<screenInfo.numScreens; i++) { ErrorF("[dix] WINDOW %d\n", i); - pWin = WindowTable[i]; - miPrintRegion(&pWin->clipList); + pWin = screenInfo.screens[i]->root; + RegionPrint(&pWin->clipList); p1 = pWin->firstChild; PrintChildren(p1, 4); } @@ -227,12 +221,12 @@ TraverseTree(WindowPtr pWin, VisitWindowProcPtr func, pointer data) WindowPtr pChild; if (!(pChild = pWin)) - return(WT_NOMATCH); + return WT_NOMATCH; while (1) { result = (* func)(pChild, data); if (result == WT_STOPWALKING) - return(WT_STOPWALKING); + return WT_STOPWALKING; if ((result == WT_WALKCHILDREN) && pChild->firstChild) { pChild = pChild->firstChild; @@ -244,7 +238,7 @@ TraverseTree(WindowPtr pWin, VisitWindowProcPtr func, pointer data) break; pChild = pChild->nextSib; } - return(WT_NOMATCH); + return WT_NOMATCH; } /***** @@ -258,7 +252,7 @@ TraverseTree(WindowPtr pWin, VisitWindowProcPtr func, pointer data) int WalkTree(ScreenPtr pScreen, VisitWindowProcPtr func, pointer data) { - return(TraverseTree(WindowTable[pScreen->myNum], func, data)); + return(TraverseTree(pScreen->root, func, data)); } /* hack for forcing backing store on all windows */ @@ -323,12 +317,12 @@ MakeRootTile(WindowPtr pWin) FatalError("could not create root tile"); { - CARD32 attributes[2]; + ChangeGCVal attributes[2]; - attributes[0] = pScreen->whitePixel; - attributes[1] = pScreen->blackPixel; + attributes[0].val = pScreen->whitePixel; + attributes[1].val = pScreen->blackPixel; - (void)ChangeGC(pGC, GCForeground | GCBackground, attributes); + (void)ChangeGC(NullClient, pGC, GCForeground | GCBackground, attributes); } ValidateGC((DrawablePtr)pWin->background.pixmap, pGC); @@ -359,20 +353,19 @@ CreateRootWindow(ScreenPtr pScreen) BoxRec box; PixmapFormatRec *format; - pWin = xalloc(sizeof(WindowRec)); + pWin = dixAllocateObjectWithPrivates(WindowRec, PRIVATE_WINDOW); if (!pWin) return FALSE; - savedScreenInfo[pScreen->myNum].pWindow = NULL; - savedScreenInfo[pScreen->myNum].wid = FakeClientID(0); - savedScreenInfo[pScreen->myNum].ExternalScreenSaver = NULL; + pScreen->screensaver.pWindow = NULL; + pScreen->screensaver.wid = FakeClientID(0); + pScreen->screensaver.ExternalScreenSaver = NULL; screenIsSaved = SCREEN_SAVER_OFF; - WindowTable[pScreen->myNum] = pWin; + pScreen->root = pWin; pWin->drawable.pScreen = pScreen; pWin->drawable.type = DRAWABLE_WINDOW; - pWin->devPrivates = NULL; pWin->drawable.depth = pScreen->rootDepth; for (format = screenInfo.formats; @@ -386,7 +379,7 @@ CreateRootWindow(ScreenPtr pScreen) pWin->parent = NullWindow; SetWindowToDefaults(pWin); - pWin->optional = xalloc (sizeof (WindowOptRec)); + pWin->optional = malloc(sizeof (WindowOptRec)); if (!pWin->optional) return FALSE; @@ -418,10 +411,10 @@ CreateRootWindow(ScreenPtr pScreen) box.y1 = 0; box.x2 = pScreen->width; box.y2 = pScreen->height; - REGION_INIT(pScreen, &pWin->clipList, &box, 1); - REGION_INIT(pScreen, &pWin->winSize, &box, 1); - REGION_INIT(pScreen, &pWin->borderSize, &box, 1); - REGION_INIT(pScreen, &pWin->borderClip, &box, 1); + RegionInit(&pWin->clipList, &box, 1); + RegionInit(&pWin->winSize, &box, 1); + RegionInit(&pWin->borderSize, &box, 1); + RegionInit(&pWin->borderClip, &box, 1); pWin->drawable.class = InputOutput; pWin->optional->visual = pScreen->rootVisual; @@ -496,12 +489,8 @@ ClippedRegionFromBox(WindowPtr pWin, RegionPtr Rgn, int x, int y, int w, int h) { - ScreenPtr pScreen; - BoxRec box; - - pScreen = pWin->drawable.pScreen; + BoxRec box = *RegionExtents(&pWin->winSize); - box = *(REGION_EXTENTS(pScreen, &pWin->winSize)); /* we do these calculations to avoid overflows */ if (x > box.x1) box.x1 = x; @@ -517,8 +506,8 @@ ClippedRegionFromBox(WindowPtr pWin, RegionPtr Rgn, box.x2 = box.x1; if (box.y1 > box.y2) box.y2 = box.y1; - REGION_RESET(pScreen, Rgn, &box); - REGION_INTERSECT(pScreen, Rgn, Rgn, &pWin->winSize); + RegionReset(Rgn, &box); + RegionIntersect(Rgn, Rgn, &pWin->winSize); } static RealChildHeadProc realChildHeadProc = NULL; @@ -539,10 +528,10 @@ RealChildHead(WindowPtr pWin) if (!pWin->parent && (screenIsSaved == SCREEN_SAVER_ON) && - (HasSaverWindow (pWin->drawable.pScreen->myNum))) - return (pWin->firstChild); + (HasSaverWindow (pWin->drawable.pScreen))) + return pWin->firstChild; else - return (NullWindow); + return NullWindow; } /***** @@ -639,14 +628,13 @@ CreateWindow(Window wid, WindowPtr pParent, int x, int y, unsigned w, return NullWindow; } - pWin = xalloc(sizeof(WindowRec)); + pWin = dixAllocateObjectWithPrivates(WindowRec, PRIVATE_WINDOW); if (!pWin) { *error = BadAlloc; return NullWindow; } pWin->drawable = pParent->drawable; - pWin->devPrivates = NULL; pWin->drawable.depth = depth; if (depth == pParent->drawable.depth) pWin->drawable.bitsPerPixel = pParent->drawable.bitsPerPixel; @@ -670,7 +658,7 @@ CreateWindow(Window wid, WindowPtr pParent, int x, int y, unsigned w, { if (!MakeWindowOptional (pWin)) { - xfree (pWin); + dixFreeObjectWithPrivates(pWin, PRIVATE_WINDOW); *error = BadAlloc; return NullWindow; } @@ -685,7 +673,7 @@ CreateWindow(Window wid, WindowPtr pParent, int x, int y, unsigned w, *error = XaceHook(XACE_RESOURCE_ACCESS, client, wid, RT_WINDOW, pWin, RT_WINDOW, pWin->parent, DixCreateAccess|DixSetAttrAccess); if (*error != Success) { - xfree(pWin); + dixFreeObjectWithPrivates(pWin, PRIVATE_WINDOW); return NullWindow; } @@ -705,10 +693,10 @@ CreateWindow(Window wid, WindowPtr pParent, int x, int y, unsigned w, pWin->drawable.y = pParent->drawable.y + y + (int)bw; /* set up clip list correctly for unobscured WindowPtr */ - REGION_NULL(pScreen, &pWin->clipList); - REGION_NULL(pScreen, &pWin->borderClip); - REGION_NULL(pScreen, &pWin->winSize); - REGION_NULL(pScreen, &pWin->borderSize); + RegionNull(&pWin->clipList); + RegionNull(&pWin->borderClip); + RegionNull(&pWin->winSize); + RegionNull(&pWin->borderSize); pHead = RealChildHead(pParent); if (pHead) @@ -809,12 +797,12 @@ DisposeWindowOptional (WindowPtr pWin) FreeCursor(pList->cursor, (XID)0); pPrev = pList; pList = pList->next; - xfree(pPrev); + free(pPrev); } pWin->optional->deviceCursors = NULL; } - xfree (pWin->optional); + free(pWin->optional); pWin->optional = NULL; } @@ -826,16 +814,16 @@ FreeWindowResources(WindowPtr pWin) DeleteWindowFromAnySaveSet(pWin); DeleteWindowFromAnySelections(pWin); DeleteWindowFromAnyEvents(pWin, TRUE); - REGION_UNINIT(pScreen, &pWin->clipList); - REGION_UNINIT(pScreen, &pWin->winSize); - REGION_UNINIT(pScreen, &pWin->borderClip); - REGION_UNINIT(pScreen, &pWin->borderSize); + RegionUninit(&pWin->clipList); + RegionUninit(&pWin->winSize); + RegionUninit(&pWin->borderClip); + RegionUninit(&pWin->borderSize); if (wBoundingShape (pWin)) - REGION_DESTROY(pScreen, wBoundingShape (pWin)); + RegionDestroy(wBoundingShape (pWin)); if (wClipShape (pWin)) - REGION_DESTROY(pScreen, wClipShape (pWin)); + RegionDestroy(wClipShape (pWin)); if (wInputShape (pWin)) - REGION_DESTROY(pScreen, wInputShape (pWin)); + RegionDestroy(wInputShape (pWin)); if (pWin->borderIsPixel == FALSE) (*pScreen->DestroyPixmap)(pWin->border.pixmap); if (pWin->backgroundState == BackgroundPixmap) @@ -883,8 +871,7 @@ CrushTree(WindowPtr pWin) (*UnrealizeWindow)(pChild); } FreeWindowResources(pChild); - dixFreePrivates(pChild->devPrivates); - xfree(pChild); + dixFreeObjectWithPrivates(pChild, PRIVATE_WINDOW); if ( (pChild = pSib) ) break; pChild = pParent; @@ -934,9 +921,9 @@ DeleteWindow(pointer value, XID wid) if (pWin->prevSib) pWin->prevSib->nextSib = pWin->nextSib; } - xfree(dixLookupPrivate(&pWin->devPrivates, FocusPrivatesKey)); - dixFreePrivates(pWin->devPrivates); - xfree(pWin); + else + pWin->drawable.pScreen->root = NULL; + dixFreeObjectWithPrivates(pWin, PRIVATE_WINDOW); return Success; } @@ -1056,7 +1043,7 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client) } else { - error = (rc == BadValue) ? BadPixmap : rc; + error = rc; client->errorValue = pixID; goto PatchUp; } @@ -1116,7 +1103,7 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client) } else { - error = (rc == BadValue) ? BadPixmap : rc; + error = rc; client->errorValue = pixID; goto PatchUp; } @@ -1264,7 +1251,7 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client) client, DixUseAccess); if (rc != Success) { - error = (rc == BadValue) ? BadColor : rc; + error = rc; client->errorValue = cmap; goto PatchUp; } @@ -1329,7 +1316,7 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client) */ if ( cursorID == None) { - if (pWin == WindowTable[pWin->drawable.pScreen->myNum]) + if (pWin == pWin->drawable.pScreen->root) pCursor = rootCursor; else pCursor = (CursorPtr) None; @@ -1340,7 +1327,7 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client) RT_CURSOR, client, DixUseAccess); if (rc != Success) { - error = (rc == BadValue) ? BadCursor : rc; + error = rc; client->errorValue = cursorID; goto PatchUp; } @@ -1433,10 +1420,10 @@ PatchUp: { RegionRec exposed; - REGION_NULL(pScreen, &exposed); - REGION_SUBTRACT(pScreen, &exposed, &pWin->borderClip, &pWin->winSize); + RegionNull(&exposed); + RegionSubtract(&exposed, &pWin->borderClip, &pWin->winSize); miPaintWindow(pWin, &exposed, PW_BORDER); - REGION_UNINIT(pScreen, &exposed); + RegionUninit(&exposed); } return error; } @@ -1564,7 +1551,7 @@ MoveWindowInStack(WindowPtr pWin, WindowPtr pNextSib) (*pWin->drawable.pScreen->RestackWindow)(pWin, pWin->nextSib); #endif - return( pFirstChange ); + return pFirstChange; } void @@ -1583,7 +1570,7 @@ SetWinSize (WindowPtr pWin) box.y1 = pWin->drawable.y; box.x2 = pWin->drawable.x + pWin->drawable.width; box.y2 = pWin->drawable.y + pWin->drawable.height; - REGION_RESET (pScreen, &pWin->winSize, &box); + RegionReset(&pWin->winSize, &box); } else #endif @@ -1592,18 +1579,15 @@ SetWinSize (WindowPtr pWin) (int)pWin->drawable.width, (int)pWin->drawable.height); if (wBoundingShape (pWin) || wClipShape (pWin)) { - ScreenPtr pScreen; - pScreen = pWin->drawable.pScreen; - - REGION_TRANSLATE(pScreen, &pWin->winSize, - pWin->drawable.x, + RegionTranslate(&pWin->winSize, - pWin->drawable.x, - pWin->drawable.y); if (wBoundingShape (pWin)) - REGION_INTERSECT(pScreen, &pWin->winSize, &pWin->winSize, + RegionIntersect(&pWin->winSize, &pWin->winSize, wBoundingShape (pWin)); if (wClipShape (pWin)) - REGION_INTERSECT(pScreen, &pWin->winSize, &pWin->winSize, + RegionIntersect(&pWin->winSize, &pWin->winSize, wClipShape (pWin)); - REGION_TRANSLATE(pScreen, &pWin->winSize, pWin->drawable.x, + RegionTranslate(&pWin->winSize, pWin->drawable.x, pWin->drawable.y); } } @@ -1628,7 +1612,7 @@ SetBorderSize (WindowPtr pWin) box.y1 = pWin->drawable.y - bw; box.x2 = pWin->drawable.x + pWin->drawable.width + bw; box.y2 = pWin->drawable.y + pWin->drawable.height + bw; - REGION_RESET (pScreen, &pWin->borderSize, &box); + RegionReset(&pWin->borderSize, &box); } else #endif @@ -1637,21 +1621,17 @@ SetBorderSize (WindowPtr pWin) (int)(pWin->drawable.width + (bw<<1)), (int)(pWin->drawable.height + (bw<<1))); if (wBoundingShape (pWin)) { - ScreenPtr pScreen; - pScreen = pWin->drawable.pScreen; - - REGION_TRANSLATE(pScreen, &pWin->borderSize, - pWin->drawable.x, + RegionTranslate(&pWin->borderSize, - pWin->drawable.x, - pWin->drawable.y); - REGION_INTERSECT(pScreen, &pWin->borderSize, &pWin->borderSize, + RegionIntersect(&pWin->borderSize, &pWin->borderSize, wBoundingShape (pWin)); - REGION_TRANSLATE(pScreen, &pWin->borderSize, pWin->drawable.x, + RegionTranslate(&pWin->borderSize, pWin->drawable.x, pWin->drawable.y); - REGION_UNION(pScreen, &pWin->borderSize, &pWin->borderSize, + RegionUnion(&pWin->borderSize, &pWin->borderSize, &pWin->winSize); } } else { - REGION_COPY(pWin->drawable.pScreen, &pWin->borderSize, - &pWin->winSize); + RegionCopy(&pWin->borderSize, &pWin->winSize); } } @@ -1817,12 +1797,12 @@ IsSiblingAboveMe( while (pWin) { if (pWin == pSib) - return(Above); + return Above; else if (pWin == pMe) - return(Below); + return Below; pWin = pWin->nextSib; } - return(Below); + return Below; } static BoxPtr @@ -1836,7 +1816,7 @@ WindowExtents( + wBorderWidth (pWin); pBox->y2 = pWin->drawable.y + (int)pWin->drawable.height + wBorderWidth (pWin); - return(pBox); + return pBox; } #define IS_SHAPED(pWin) (wBoundingShape (pWin) != (RegionPtr) NULL) @@ -1846,17 +1826,11 @@ MakeBoundingRegion ( WindowPtr pWin, BoxPtr pBox) { - RegionPtr pRgn; - ScreenPtr pScreen; - pScreen = pWin->drawable.pScreen; - - pRgn = REGION_CREATE(pScreen, pBox, 1); + RegionPtr pRgn = RegionCreate(pBox, 1); if (wBoundingShape (pWin)) { - REGION_TRANSLATE(pScreen, pRgn, -pWin->origin.x, - -pWin->origin.y); - REGION_INTERSECT(pScreen, pRgn, pRgn, wBoundingShape (pWin)); - REGION_TRANSLATE(pScreen, pRgn, pWin->origin.x, - pWin->origin.y); + RegionTranslate(pRgn, -pWin->origin.x, -pWin->origin.y); + RegionIntersect(pRgn, pRgn, wBoundingShape (pWin)); + RegionTranslate(pRgn, pWin->origin.x, pWin->origin.y); } return pRgn; } @@ -1869,18 +1843,16 @@ ShapeOverlap ( BoxPtr pSibBox) { RegionPtr pWinRgn, pSibRgn; - ScreenPtr pScreen; Bool ret; if (!IS_SHAPED(pWin) && !IS_SHAPED(pSib)) return TRUE; - pScreen = pWin->drawable.pScreen; pWinRgn = MakeBoundingRegion (pWin, pWinBox); pSibRgn = MakeBoundingRegion (pSib, pSibBox); - REGION_INTERSECT(pScreen, pWinRgn, pWinRgn, pSibRgn); - ret = REGION_NOTEMPTY(pScreen, pWinRgn); - REGION_DESTROY(pScreen, pWinRgn); - REGION_DESTROY(pScreen, pSibRgn); + RegionIntersect(pWinRgn, pWinRgn, pSibRgn); + ret = RegionNotEmpty(pWinRgn); + RegionDestroy(pWinRgn); + RegionDestroy(pSibRgn); return ret; } @@ -1902,10 +1874,10 @@ AnyWindowOverlapsMe( if (BOXES_OVERLAP(sbox, box) && ShapeOverlap (pWin, box, pSib, sbox) ) - return(TRUE); + return TRUE; } } - return(FALSE); + return FALSE; } static Bool @@ -1925,10 +1897,10 @@ IOverlapAnyWindow( if (BOXES_OVERLAP(sbox, box) && ShapeOverlap (pWin, box, pSib, sbox) ) - return(TRUE); + return TRUE; } } - return(FALSE); + return FALSE; } /* @@ -1970,7 +1942,6 @@ WhereDoIGoInTheStack( int smode) { BoxRec box; - ScreenPtr pScreen; WindowPtr pHead, pFirst; if ((pWin == pWin->parent->firstChild) && @@ -1978,7 +1949,6 @@ WhereDoIGoInTheStack( return((WindowPtr ) NULL); pHead = RealChildHead(pWin->parent); pFirst = pHead ? pHead->nextSib : pWin->parent->firstChild; - pScreen = pWin->drawable.pScreen; box.x1 = x; box.y1 = y; box.x2 = x + (int)w; @@ -1987,63 +1957,63 @@ WhereDoIGoInTheStack( { case Above: if (pSib) - return(pSib); + return pSib; else if (pWin == pFirst) - return(pWin->nextSib); + return pWin->nextSib; else - return(pFirst); + return pFirst; case Below: if (pSib) if (pSib->nextSib != pWin) - return(pSib->nextSib); + return pSib->nextSib; else - return(pWin->nextSib); + return pWin->nextSib; else return NullWindow; case TopIf: if ((!pWin->mapped || (pSib && !pSib->mapped))) - return(pWin->nextSib); + return pWin->nextSib; else if (pSib) { if ((IsSiblingAboveMe(pWin, pSib) == Above) && - (RECT_IN_REGION(pScreen, &pSib->borderSize, &box) != rgnOUT)) - return(pFirst); + (RegionContainsRect(&pSib->borderSize, &box) != rgnOUT)) + return pFirst; else - return(pWin->nextSib); + return pWin->nextSib; } else if (AnyWindowOverlapsMe(pWin, pHead, &box)) - return(pFirst); + return pFirst; else - return(pWin->nextSib); + return pWin->nextSib; case BottomIf: if ((!pWin->mapped || (pSib && !pSib->mapped))) - return(pWin->nextSib); + return pWin->nextSib; else if (pSib) { if ((IsSiblingAboveMe(pWin, pSib) == Below) && - (RECT_IN_REGION(pScreen, &pSib->borderSize, &box) != rgnOUT)) + (RegionContainsRect(&pSib->borderSize, &box) != rgnOUT)) return NullWindow; else - return(pWin->nextSib); + return pWin->nextSib; } else if (IOverlapAnyWindow(pWin, &box)) return NullWindow; else - return(pWin->nextSib); + return pWin->nextSib; case Opposite: if ((!pWin->mapped || (pSib && !pSib->mapped))) - return(pWin->nextSib); + return pWin->nextSib; else if (pSib) { - if (RECT_IN_REGION(pScreen, &pSib->borderSize, &box) != rgnOUT) + if (RegionContainsRect(&pSib->borderSize, &box) != rgnOUT) { if (IsSiblingAboveMe(pWin, pSib) == Above) - return(pFirst); + return pFirst; else return NullWindow; } else - return(pWin->nextSib); + return pWin->nextSib; } else if (AnyWindowOverlapsMe(pWin, pHead, &box)) { @@ -2051,7 +2021,7 @@ WhereDoIGoInTheStack( * if (pWin == pWin->parent->firstChild) * return pWin->nextSib; */ - return(pFirst); + return pFirst; } else if (IOverlapAnyWindow(pWin, &box)) return NullWindow; @@ -2126,10 +2096,10 @@ ConfigureWindow(WindowPtr pWin, Mask mask, XID *vlist, ClientPtr client) xEvent event; if ((pWin->drawable.class == InputOnly) && (mask & IllegalInputOnlyConfigureMask)) - return(BadMatch); + return BadMatch; if ((mask & CWSibling) && !(mask & CWStackMode)) - return(BadMatch); + return BadMatch; pVlist = vlist; @@ -2186,9 +2156,9 @@ ConfigureWindow(WindowPtr pWin, Mask mask, XID *vlist, ClientPtr client) return rc; } if (pSib->parent != pParent) - return(BadMatch); + return BadMatch; if (pSib == pWin) - return(BadMatch); + return BadMatch; break; case CWStackMode: GET_CARD8(CWStackMode, smode); @@ -2196,12 +2166,12 @@ ConfigureWindow(WindowPtr pWin, Mask mask, XID *vlist, ClientPtr client) (smode != Opposite) && (smode != Above) && (smode != Below)) { client->errorValue = smode; - return(BadValue); + return BadValue; } break; default: client->errorValue = mask; - return(BadValue); + return BadValue; } } /* root really can't be reconfigured, so just return */ @@ -2238,8 +2208,8 @@ ConfigureWindow(WindowPtr pWin, Mask mask, XID *vlist, ClientPtr client) event.u.configureRequest.y = y; #ifdef PANORAMIX if(!noPanoramiXExtension && (!pParent || !pParent->parent)) { - event.u.configureRequest.x += panoramiXdataPtr[0].x; - event.u.configureRequest.y += panoramiXdataPtr[0].y; + event.u.configureRequest.x += screenInfo.screens[0]->x; + event.u.configureRequest.y += screenInfo.screens[0]->y; } #endif event.u.configureRequest.width = w; @@ -2249,7 +2219,7 @@ ConfigureWindow(WindowPtr pWin, Mask mask, XID *vlist, ClientPtr client) event.u.configureRequest.parent = pParent->drawable.id; if (MaybeDeliverEventsToClient(pParent, &event, 1, SubstructureRedirectMask, client) == 1) - return(Success); + return Success; } if (action == RESIZE_WIN) { @@ -2300,11 +2270,18 @@ ConfigureWindow(WindowPtr pWin, Mask mask, XID *vlist, ClientPtr client) #endif goto ActuallyDoSomething; } - return(Success); + return Success; ActuallyDoSomething: if (pWin->drawable.pScreen->ConfigNotify) - (*pWin->drawable.pScreen->ConfigNotify)(pWin, x, y, w, h, bw, pSib); + { + int ret; + ret = (*pWin->drawable.pScreen->ConfigNotify)(pWin, x, y, w, h, bw, pSib); + if (ret) { + client->errorValue = 0; + return ret; + } + } if (SubStrSend(pWin, pParent)) { @@ -2319,8 +2296,8 @@ ActuallyDoSomething: event.u.configureNotify.y = y; #ifdef PANORAMIX if(!noPanoramiXExtension && (!pParent || !pParent->parent)) { - event.u.configureNotify.x += panoramiXdataPtr[0].x; - event.u.configureNotify.y += panoramiXdataPtr[0].y; + event.u.configureNotify.x += screenInfo.screens[0]->x; + event.u.configureNotify.y += screenInfo.screens[0]->y; } #endif event.u.configureNotify.width = w; @@ -2356,7 +2333,7 @@ ActuallyDoSomething: if (action != RESTACK_WIN) CheckCursorConfinement(pWin); - return(Success); + return Success; #undef RESTACK_WIN #undef MOVE_WIN #undef RESIZE_WIN @@ -2417,7 +2394,7 @@ CirculateWindow(WindowPtr pParent, int direction, ClientPtr client) event.u.u.type = CirculateRequest; if (MaybeDeliverEventsToClient(pParent, &event, 1, SubstructureRedirectMask, client) == 1) - return(Success); + return Success; } event.u.u.type = CirculateNotify; @@ -2426,7 +2403,7 @@ CirculateWindow(WindowPtr pParent, int direction, ClientPtr client) (direction == RaiseLowest) ? pFirst : NullWindow, VTStack); - return(Success); + return Success; } static int @@ -2437,9 +2414,9 @@ CompareWIDs( Window *wid = (Window *)value; if (pWin->drawable.id == *wid) - return(WT_STOPWALKING); + return WT_STOPWALKING; else - return(WT_WALKCHILDREN); + return WT_WALKCHILDREN; } /***** @@ -2458,9 +2435,9 @@ ReparentWindow(WindowPtr pWin, WindowPtr pParent, pScreen = pWin->drawable.pScreen; if (TraverseTree(pWin, CompareWIDs, (pointer)&pParent->drawable.id) == WT_STOPWALKING) - return(BadMatch); + return BadMatch; if (!MakeWindowOptional(pWin)) - return(BadAlloc); + return BadAlloc; if (WasMapped) UnmapWindow(pWin, FALSE); @@ -2473,8 +2450,8 @@ ReparentWindow(WindowPtr pWin, WindowPtr pParent, event.u.reparent.y = y; #ifdef PANORAMIX if(!noPanoramiXExtension && !pParent->parent) { - event.u.reparent.x += panoramiXdataPtr[0].x; - event.u.reparent.y += panoramiXdataPtr[0].y; + event.u.reparent.x += screenInfo.screens[0]->x; + event.u.reparent.y += screenInfo.screens[0]->y; } #endif event.u.reparent.override = pWin->overrideRedirect; @@ -2536,7 +2513,7 @@ ReparentWindow(WindowPtr pWin, WindowPtr pParent, if (WasMapped) MapWindow(pWin, client); RecalculateDeliverableEvents(pWin); - return(Success); + return Success; } static void @@ -2609,7 +2586,7 @@ MapWindow(WindowPtr pWin, ClientPtr client) WindowPtr pLayerWin; if (pWin->mapped) - return(Success); + return Success; /* general check for permission to map window */ if (XaceHook(XACE_RESOURCE_ACCESS, client, pWin->drawable.id, RT_WINDOW, @@ -2633,7 +2610,7 @@ MapWindow(WindowPtr pWin, ClientPtr client) if (MaybeDeliverEventsToClient(pParent, &event, 1, SubstructureRedirectMask, client) == 1) - return(Success); + return Success; } pWin->mapped = TRUE; @@ -2647,7 +2624,7 @@ MapWindow(WindowPtr pWin, ClientPtr client) } if (!pParent->realized) - return(Success); + return Success; RealizeTree(pWin); if (pWin->viewable) { @@ -2676,13 +2653,13 @@ MapWindow(WindowPtr pWin, ClientPtr client) (*pScreen->ClipNotify) (pWin, 0, 0); if (pScreen->PostValidateTree) (*pScreen->PostValidateTree)(NullWindow, pWin, VTMap); - REGION_NULL(pScreen, &temp); - REGION_COPY(pScreen, &temp, &pWin->clipList); + RegionNull(&temp); + RegionCopy(&temp, &pWin->clipList); (*pScreen->WindowExposures) (pWin, &temp, NullRegion); - REGION_UNINIT(pScreen, &temp); + RegionUninit(&temp); } - return(Success); + return Success; } @@ -2777,7 +2754,6 @@ UnrealizeTree( WindowPtr pChild; UnrealizeWindowProcPtr Unrealize; MarkUnrealizedWindowProcPtr MarkUnrealizedWindow; - int rc; Unrealize = pWin->drawable.pScreen->UnrealizeWindow; MarkUnrealizedWindow = pWin->drawable.pScreen->MarkUnrealizedWindow; @@ -2791,7 +2767,7 @@ UnrealizeTree( #ifdef PANORAMIX if(!noPanoramiXExtension && !pChild->drawable.pScreen->myNum) { PanoramiXRes *win; - rc = dixLookupResourceByType((pointer *)&win, + int rc = dixLookupResourceByType((pointer *)&win, pChild->drawable.id, XRT_WINDOW, serverClient, DixWriteAccess); if (rc == Success) @@ -2839,7 +2815,7 @@ UnmapWindow(WindowPtr pWin, Bool fromConfigure) WindowPtr pLayerWin = pWin; if ((!pWin->mapped) || (!(pParent = pWin->parent))) - return(Success); + return Success; if (SubStrSend(pWin, pParent) && MapUnmapEventsEnabled(pWin)) { memset(&event, 0, sizeof(xEvent)); @@ -2869,7 +2845,7 @@ UnmapWindow(WindowPtr pWin, Bool fromConfigure) } if (wasRealized && !fromConfigure) WindowsRestructured (); - return(Success); + return Success; } /***** @@ -2967,7 +2943,7 @@ HandleSaveSet(ClientPtr client) pWin = SaveSetWindow(client->saveSet[j]); #ifdef XFIXES if (SaveSetToRoot(client->saveSet[j])) - pParent = WindowTable[pWin->drawable.pScreen->myNum]; + pParent = pWin->drawable.pScreen->root; else #endif { @@ -2997,7 +2973,7 @@ HandleSaveSet(ClientPtr client) MapWindow(pWin, client); } } - xfree(client->saveSet); + free(client->saveSet); client->numSaved = 0; client->saveSet = (SaveSetElt *)NULL; } @@ -3012,43 +2988,37 @@ PointInWindowIsVisible(WindowPtr pWin, int x, int y) BoxRec box; if (!pWin->realized) - return (FALSE); - if (POINT_IN_REGION(pWin->drawable.pScreen, &pWin->borderClip, + return FALSE; + if (RegionContainsPoint(&pWin->borderClip, x, y, &box) && (!wInputShape(pWin) || - POINT_IN_REGION(pWin->drawable.pScreen, - wInputShape(pWin), - x - pWin->drawable.x, - y - pWin->drawable.y, &box))) - return(TRUE); - return(FALSE); + RegionContainsPoint(wInputShape(pWin), + x - pWin->drawable.x, + y - pWin->drawable.y, &box))) + return TRUE; + return FALSE; } RegionPtr NotClippedByChildren(WindowPtr pWin) { - ScreenPtr pScreen; - RegionPtr pReg; - - pScreen = pWin->drawable.pScreen; - pReg = REGION_CREATE(pScreen, NullBox, 1); + RegionPtr pReg = RegionCreate(NullBox, 1); if (pWin->parent || screenIsSaved != SCREEN_SAVER_ON || - !HasSaverWindow (pWin->drawable.pScreen->myNum)) + !HasSaverWindow (pWin->drawable.pScreen)) { - REGION_INTERSECT(pScreen, pReg, &pWin->borderClip, &pWin->winSize); + RegionIntersect(pReg, &pWin->borderClip, &pWin->winSize); } - return(pReg); + return pReg; } void SendVisibilityNotify(WindowPtr pWin) { xEvent event; -#ifndef NO_XINERAMA_PORT unsigned int visibility = pWin->visibility; -#endif + if (!MapUnmapEventsEnabled(pWin)) return; #ifdef PANORAMIX @@ -3153,33 +3123,33 @@ dixSaveScreens(ClientPtr client, int on, int mode) } for (i = 0; i < screenInfo.numScreens; i++) { + ScreenPtr pScreen = screenInfo.screens[i]; if (on == SCREEN_SAVER_FORCER) - (* screenInfo.screens[i]->SaveScreen) (screenInfo.screens[i], on); - if (savedScreenInfo[i].ExternalScreenSaver) + (* pScreen->SaveScreen) (pScreen, on); + if (pScreen->screensaver.ExternalScreenSaver) { - if ((*savedScreenInfo[i].ExternalScreenSaver) - (screenInfo.screens[i], type, on == SCREEN_SAVER_FORCER)) + if ((*pScreen->screensaver.ExternalScreenSaver) + (pScreen, type, on == SCREEN_SAVER_FORCER)) continue; } if (type == screenIsSaved) continue; switch (type) { case SCREEN_SAVER_OFF: - if (savedScreenInfo[i].blanked == SCREEN_IS_BLANKED) + if (pScreen->screensaver.blanked == SCREEN_IS_BLANKED) { - (* screenInfo.screens[i]->SaveScreen) (screenInfo.screens[i], - what); + (* pScreen->SaveScreen) (pScreen, what); } - else if (HasSaverWindow (i)) + else if (HasSaverWindow (pScreen)) { - savedScreenInfo[i].pWindow = NullWindow; - FreeResource(savedScreenInfo[i].wid, RT_NONE); + pScreen->screensaver.pWindow = NullWindow; + FreeResource(pScreen->screensaver.wid, RT_NONE); } break; case SCREEN_SAVER_CYCLE: - if (savedScreenInfo[i].blanked == SCREEN_IS_TILED) + if (pScreen->screensaver.blanked == SCREEN_IS_TILED) { - WindowPtr pWin = savedScreenInfo[i].pWindow; + WindowPtr pWin = pScreen->screensaver.pWindow; /* make it look like screen saver is off, so that * NotClippedByChildren will compute a clip list * for the root window, so miPaintWindow works @@ -3203,35 +3173,33 @@ dixSaveScreens(ClientPtr client, int on, int mode) * Call the DDX saver in case it wants to do something * at cycle time */ - else if (savedScreenInfo[i].blanked == SCREEN_IS_BLANKED) + else if (pScreen->screensaver.blanked == SCREEN_IS_BLANKED) { - (* screenInfo.screens[i]->SaveScreen) (screenInfo.screens[i], - type); + (* pScreen->SaveScreen) (pScreen, type); } break; case SCREEN_SAVER_ON: if (ScreenSaverBlanking != DontPreferBlanking) { - if ((* screenInfo.screens[i]->SaveScreen) - (screenInfo.screens[i], what)) + if ((* pScreen->SaveScreen) (pScreen, what)) { - savedScreenInfo[i].blanked = SCREEN_IS_BLANKED; + pScreen->screensaver.blanked = SCREEN_IS_BLANKED; continue; } if ((ScreenSaverAllowExposures != DontAllowExposures) && - TileScreenSaver(i, SCREEN_IS_BLACK)) + TileScreenSaver(pScreen, SCREEN_IS_BLACK)) { - savedScreenInfo[i].blanked = SCREEN_IS_BLACK; + pScreen->screensaver.blanked = SCREEN_IS_BLACK; continue; } } if ((ScreenSaverAllowExposures != DontAllowExposures) && - TileScreenSaver(i, SCREEN_IS_TILED)) + TileScreenSaver(pScreen, SCREEN_IS_TILED)) { - savedScreenInfo[i].blanked = SCREEN_IS_TILED; + pScreen->screensaver.blanked = SCREEN_IS_TILED; } else - savedScreenInfo[i].blanked = SCREEN_ISNT_SAVED; + pScreen->screensaver.blanked = SCREEN_ISNT_SAVED; break; } } @@ -3253,7 +3221,7 @@ SaveScreens(int on, int mode) } static Bool -TileScreenSaver(int i, int kind) +TileScreenSaver(ScreenPtr pScreen, int kind) { int j; int result; @@ -3270,9 +3238,9 @@ TileScreenSaver(int i, int kind) attri = 0; switch (kind) { case SCREEN_IS_TILED: - switch (WindowTable[i]->backgroundState) { + switch (pScreen->root->backgroundState) { case BackgroundPixel: - attributes[attri++] = WindowTable[i]->background.pixel; + attributes[attri++] = pScreen->root->background.pixel; mask |= CWBackPixel; break; case BackgroundPixmap: @@ -3284,7 +3252,7 @@ TileScreenSaver(int i, int kind) } break; case SCREEN_IS_BLACK: - attributes[attri++] = WindowTable[i]->drawable.pScreen->blackPixel; + attributes[attri++] = pScreen->root->drawable.pScreen->blackPixel; mask |= CWBackPixel; break; } @@ -3299,12 +3267,12 @@ TileScreenSaver(int i, int kind) cm.height=16; cm.xhot=8; cm.yhot=8; - srcbits = xalloc( BitmapBytePad(32)*16); - mskbits = xalloc( BitmapBytePad(32)*16); + srcbits = malloc( BitmapBytePad(32)*16); + mskbits = malloc( BitmapBytePad(32)*16); if (!srcbits || !mskbits) { - xfree(srcbits); - xfree(mskbits); + free(srcbits); + free(mskbits); cursor = 0; } else @@ -3326,19 +3294,19 @@ TileScreenSaver(int i, int kind) } else { - xfree (srcbits); - xfree (mskbits); + free(srcbits); + free(mskbits); } } - pWin = savedScreenInfo[i].pWindow = - CreateWindow(savedScreenInfo[i].wid, - WindowTable[i], + pWin = pScreen->screensaver.pWindow = + CreateWindow(pScreen->screensaver.wid, + pScreen->root, -RANDOM_WIDTH, -RANDOM_WIDTH, - (unsigned short)screenInfo.screens[i]->width + RANDOM_WIDTH, - (unsigned short)screenInfo.screens[i]->height + RANDOM_WIDTH, + (unsigned short)pScreen->width + RANDOM_WIDTH, + (unsigned short)pScreen->height + RANDOM_WIDTH, 0, InputOutput, mask, attributes, 0, serverClient, - wVisual (WindowTable[i]), &result); + wVisual (pScreen->root), &result); if (cursor) FreeResource (cursorID, RT_NONE); @@ -3347,7 +3315,7 @@ TileScreenSaver(int i, int kind) return FALSE; if (!AddResource(pWin->drawable.id, RT_WINDOW, - (pointer)savedScreenInfo[i].pWindow)) + (pointer)pScreen->screensaver.pWindow)) return FALSE; if (mask & CWBackPixmap) @@ -3457,7 +3425,7 @@ MakeWindowOptional (WindowPtr pWin) if (pWin->optional) return TRUE; - optional = xalloc (sizeof (WindowOptRec)); + optional = malloc(sizeof (WindowOptRec)); if (!optional) return FALSE; optional->dontPropagateMask = DontPropagateMasks[pWin->dontPropagate]; @@ -3548,7 +3516,7 @@ ChangeWindowDeviceCursor(WindowPtr pWin, /* first item in list */ pWin->optional->deviceCursors = pNode->next; - xfree(pNode); + free(pNode); goto out; } @@ -3560,7 +3528,7 @@ ChangeWindowDeviceCursor(WindowPtr pWin, if (!pCursor) return Success; - pNewNode = xalloc(sizeof(DevCursNodeRec)); + pNewNode = malloc(sizeof(DevCursNodeRec)); pNewNode->dev = pDev; pNewNode->next = pWin->optional->deviceCursors; pWin->optional->deviceCursors = pNewNode; @@ -3744,7 +3712,7 @@ DrawLogo(WindowPtr pWin) querypixels[0] = fore[0].val; querypixels[1] = pWin->background.pixel; - QueryColors(cmap, 2, querypixels, rgb); + QueryColors(cmap, 2, querypixels, rgb, serverClient); if ((rgb[0].red == rgb[1].red) && (rgb[0].green == rgb[1].green) && (rgb[0].blue == rgb[1].blue)) { @@ -3764,8 +3732,7 @@ DrawLogo(WindowPtr pWin) } else { back[0].val = 0; back[1].val = 0; - dixChangeGC(NullClient, pGC, GCTileStipXOrigin|GCTileStipYOrigin, - NULL, back); + ChangeGC(NullClient, pGC, GCTileStipXOrigin|GCTileStipYOrigin, back); back[0].val = FillTiled; back[1].ptr = pWin->background.pixmap; bmask = GCFillStyle|GCTile; @@ -3803,7 +3770,7 @@ DrawLogo(WindowPtr pWin) poly[1].x = x + size-d31; poly[1].y = y; poly[2].x = x + 0; poly[2].y = y + size; poly[3].x = x + d31; poly[3].y = y + size; - dixChangeGC(NullClient, pGC, fmask, NULL, fore); + ChangeGC(NullClient, pGC, fmask, fore); ValidateGC(pDraw, pGC); (*pGC->ops->FillPolygon)(pDraw, pGC, Convex, CoordModeOrigin, 4, poly); @@ -3822,7 +3789,7 @@ DrawLogo(WindowPtr pWin) poly[1].x = x + size / 2; poly[1].y = y + size/2; poly[2].x = x + (size/2)+(d31-(d31/2)); poly[2].y = y + size/2; poly[3].x = x + d31; poly[3].y = y + size; - dixChangeGC(NullClient, pGC, bmask, NULL, back); + ChangeGC(NullClient, pGC, bmask, back); ValidateGC(pDraw, pGC); (*pGC->ops->FillPolygon)(pDraw, pGC, Convex, CoordModeOrigin, 4, poly); @@ -3861,7 +3828,7 @@ DrawLogo(WindowPtr pWin) poly[1].x = x + size/4; poly[1].y = y; poly[2].x = x + size; poly[2].y = y + size; poly[3].x = x + size - size/4; poly[3].y = y + size; - dixChangeGC(NullClient, pGC, fmask, NULL, fore); + ChangeGC(NullClient, pGC, fmask, fore); ValidateGC(pDraw, pGC); (*pGC->ops->FillPolygon)(pDraw, pGC, Convex, CoordModeOrigin, 4, poly); @@ -3879,7 +3846,7 @@ DrawLogo(WindowPtr pWin) poly[1].x = x + size-( thin+gap); poly[1].y = y; poly[2].x = x + thin; poly[2].y = y + size; poly[3].x = x + thin + gap; poly[3].y = y + size; - dixChangeGC(NullClient, pGC, bmask, NULL, back); + ChangeGC(NullClient, pGC, bmask, back); ValidateGC(pDraw, pGC); (*pGC->ops->FillPolygon)(pDraw, pGC, Convex, CoordModeOrigin, 4, poly); |