6899630 move libdga to open-src & /usr/X11
authorAlan Coopersmith <Alan.Coopersmith@Sun.COM>
Fri, 13 Nov 2009 13:30:43 -0800
changeset 830 186f3c438b46
parent 829 badaccd24c06
child 831 d0181e5c3d32
6899630 move libdga to open-src & /usr/X11
open-src/lib/Makefile
open-src/lib/libdga/Makefile
open-src/lib/libdga/sun-src/Makefile
open-src/lib/libdga/sun-src/XineramaInfo.h
open-src/lib/libdga/sun-src/cmap_grab.c
open-src/lib/libdga/sun-src/cmap_grab.h
open-src/lib/libdga/sun-src/dga.h
open-src/lib/libdga/sun-src/dga_Xrequests.c
open-src/lib/libdga/sun-src/dga_Xrequests.h
open-src/lib/libdga/sun-src/dga_ab.c
open-src/lib/libdga/sun-src/dga_db.c
open-src/lib/libdga/sun-src/dga_externaldefs.h
open-src/lib/libdga/sun-src/dga_incls.h
open-src/lib/libdga/sun-src/dga_internal.h
open-src/lib/libdga/sun-src/dga_internaldefs.h
open-src/lib/libdga/sun-src/dga_pixshared.h
open-src/lib/libdga/sun-src/dga_rtnshared.h
open-src/lib/libdga/sun-src/dga_winshared.h
open-src/lib/libdga/sun-src/draw_db.c
open-src/lib/libdga/sun-src/draw_inquiry.c
open-src/lib/libdga/sun-src/mapfile
open-src/lib/libdga/sun-src/mbsmemb_inquiry.c
open-src/lib/libdga/sun-src/mbsmemb_update.c
open-src/lib/libdga/sun-src/mbuf_update.c
open-src/lib/libdga/sun-src/mbufset.c
open-src/lib/libdga/sun-src/mbufsetstr.h
open-src/lib/libdga/sun-src/pix_grab.c
open-src/lib/libdga/sun-src/pix_grab.h
open-src/lib/libdga/sun-src/pix_inquiry.c
open-src/lib/libdga/sun-src/pix_update.c
open-src/lib/libdga/sun-src/rtn_grab.c
open-src/lib/libdga/sun-src/rtn_grab.h
open-src/lib/libdga/sun-src/vmbuf_grab.h
open-src/lib/libdga/sun-src/win_grab.c
open-src/lib/libdga/sun-src/win_grab.h
open-src/lib/libdga/sun-src/win_update.c
packages/SUNWxwinc/prototype_com
packages/SUNWxwplt/prototype_com
packages/SUNWxwplt/prototype_sparc
--- a/open-src/lib/Makefile	Wed Nov 11 05:30:06 2009 -0800
+++ b/open-src/lib/Makefile	Fri Nov 13 13:30:43 2009 -0800
@@ -28,7 +28,7 @@
 # or other dealings in this Software without prior written authorization
 # of the copyright holder.
 #
-# ident	"@(#)Makefile	1.33	09/11/09 SMI"
+# ident	"@(#)Makefile	1.34	09/11/09 SMI"
 #
 ###############################################################################
 
@@ -52,6 +52,7 @@
 # Dependencies needed for parallel make:
 DPS: libX11 libXt
 fontconfig: freetype
+libdga: libX11
 libdrm: libpthread-stubs
 libFS: libxtrans
 libICE: libxtrans
@@ -87,6 +88,7 @@
 	DPS \
 	freetype \
 	fontconfig \
+	libdga \
 	libowconfig \
 	libpthread-stubs \
 	libxtrans \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/lib/libdga/Makefile	Fri Nov 13 13:30:43 2009 -0800
@@ -0,0 +1,61 @@
+###############################################################################
+#
+# libdga Makefile (for Xsun SUN_DGA extension)
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+# 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, and/or sell copies of the Software, and to permit persons
+# to whom the Software is furnished to do so, provided that the above
+# copyright notice(s) and this permission notice appear in all copies of
+# the Software and that both the above copyright notice(s) and this
+# permission notice appear in supporting documentation.
+# 
+# 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
+# OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+# HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR 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.
+# 
+# Except as contained in this notice, the name of a copyright holder
+# shall not be used in advertising or otherwise to promote the sale, use
+# or other dealings in this Software without prior written authorization
+# of the copyright holder.
+#
+#ident	"@(#)Makefile	1.1	09/11/09 SMI"
+#
+
+MODULE_NAME=libdga
+
+# No upstream sources, only local sources
+MODULE_VERSION=src
+SOURCE_TARBALL_NAME=NONE
+SOURCE_TARBALL_NAME_SET=yes
+ADDITIONAL_SOURCE_DIR=sun-src
+
+# Library name (used for specfiles/mapfiles)
+LIBNAME=dga
+
+# Man pages to apply Sun footer to & attributes to list
+SUNTOUCHED_MANPAGES= # None
+SUN_PACKAGE=SUNWxwplt
+MODULE_STABILITY=Obsolete
+
+# No configure script to run
+CONFIGURE_TARGETS=
+CONFIGURE_TARGETS_SET=yes
+
+# Since we don't have a configure script, pass configure flags to make
+MODULE_BUILD_MAKEFLAGS=$(CONFIG_ENV) PREFIX=$(MODULE_PREFIX) \
+	X11_INCLUDES_DIR=$(X11_INCLUDES_DIR)
+MODULE_INSTALL_MAKEFLAGS=$(MODULE_BUILD_MAKEFLAGS)
+
+include ../Makefile.inc
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/lib/libdga/sun-src/Makefile	Fri Nov 13 13:30:43 2009 -0800
@@ -0,0 +1,65 @@
+###############################################################################
+#
+# libdga Makefile
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+# 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, and/or sell copies of the Software, and to permit persons
+# to whom the Software is furnished to do so, provided that the above
+# copyright notice(s) and this permission notice appear in all copies of
+# the Software and that both the above copyright notice(s) and this
+# permission notice appear in supporting documentation.
+# 
+# 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
+# OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+# HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR 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.
+# 
+# Except as contained in this notice, the name of a copyright holder
+# shall not be used in advertising or otherwise to promote the sale, use
+# or other dealings in this Software without prior written authorization
+# of the copyright holder.
+#
+# ident	"@(#)Makefile	1.1	09/11/09 SMI"
+#
+
+SHLIBLDFLAGS = -G -z defs $(LDFLAGS)
+REQUIREDLIBS = -lX11 -lsocket -lc
+DEFINES = -D_TS_ERRNO -DMT -DXTHREADS -DPANORAMIX -DIPv6 -DSVR4
+
+HEADERS = dga_Xrequests.h win_grab.h rtn_grab.h cmap_grab.h pix_grab.h \
+	  mbufsetstr.h vmbuf_grab.h dga_incls.h
+SRCS =  dga_Xrequests.c win_grab.c dga_db.c rtn_grab.c cmap_grab.c pix_grab.c \
+	mbsmemb_update.c mbsmemb_inquiry.c win_update.c mbuf_update.c \
+	mbufset.c draw_inquiry.c draw_db.c pix_update.c pix_inquiry.c dga_ab.c
+OBJS = $(SRCS:.c=.o)
+
+# Inspired by automake 1.11 silent rules - hides details by default
+# Run make V=1 to show details
+DEFAULT_V  = 0
+V_CC       = $(V_CC_$(V))
+V_CC_      = $(V_CC_$(DEFAULT_V))
+V_CC_0     = @echo "  CC    " $@;
+
+all: libdga.so.1
+
+libdga.so.1: $(OBJS)
+	$(V_CC)$(LD) $(CFLAGS) -o $@ $(SHLIBLDFLAGS) -h libdga.so.1 \
+		$(OBJS) $(REQUIREDLIBS)
+
+.c.o:
+	$(V_CC)$(CC) -Kpic $(CFLAGS) $(CPPFLAGS) $(DEFINES) -c $<
+
+install: libdga.so.1
+	mkdir -p $(DESTDIR)$(libdir) $(DESTDIR)$(INCDIR)
+	$(INSTALL) libdga.so.1 $(DESTDIR)$(libdir)/libdga.so.1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/lib/libdga/sun-src/XineramaInfo.h	Fri Nov 13 13:30:43 2009 -0800
@@ -0,0 +1,68 @@
+/* Copyright 1999 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ *
+ * 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, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * 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
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR 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.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+#pragma ident	"@(#)XineramaInfo.h	1.3	09/11/09 SMI"
+
+#define XinID	int
+#define MAXSCREEN 16
+#define DELTA	int
+#define POINT	int
+typedef struct subwid
+{
+	XinID	wid;	/* sub window id */
+	DELTA	dx,dy;	/* delta in screen co-ord from virtual zero */
+	POINT	x,y;	/* location of window in screen co-ord */
+	DELTA 	wdx,wdy;/* size of window in screen co-ord */
+}SubWID, *pSubWID;
+
+typedef struct xineramainfo
+{
+	XinID 	wid;	/* Window ID of requested virtual window */
+	SubWID	subs[MAXSCREEN];	/* there will be 16 slots */
+}XineramaInfo, *pXineramaInfo;
+
+typedef struct _XDgaXineramaInfoReply
+{
+	BYTE	type;
+	CARD8	unused;
+	CARD16	sequenceNumber B16;
+	CARD32	length B32;
+	XinID 	wid;	/* Window ID of requested virtual window */
+	SubWID	subs[MAXSCREEN];	/* there will be 16 slots */
+}xDgaXineramaInfoReply;
+
+typedef struct _XDgaXineramaInfoReq
+{
+	CARD8	reqType;
+	CARD8	xdgaReqType;
+	CARD16	length B16;
+	CARD32	visual B32;
+}xDgaXineramaInfoReq;
+#define sz_xDgaXineramaInfoReq 8
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/lib/libdga/sun-src/cmap_grab.c	Fri Nov 13 13:30:43 2009 -0800
@@ -0,0 +1,1162 @@
+/* Copyright 1999 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ *
+ * 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, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * 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
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR 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.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+#pragma ident	"@(#)cmap_grab.c	35.9	09/11/09 SMI"
+
+/*
+ * cmap_grab.c - the client side code for DGA colormap grabber
+ */
+
+
+/*
+ *
+ *	Shared colormap synchronization routines.
+ *
+ *	Client side
+ *
+ *
+ * Functions:
+ *
+ *    Dga_cmap
+ *    dga_cm_grab(devfd, filesuffix)
+ *		int		devfd ;
+ *		unsigned long	filesuffix ;
+ *
+ *	Grab a colormap.  'filesuffix' is the handle returned by
+ *	XDgaGrabColormap.  'devfd' is the file descriptor of the frame buffer
+ *	if any, -1 otherwise.  If you specify -1, dga_cm_grab will open
+ *	the frame buffer.  The frame buffer fd may be inquired from
+ *	the returned dga_cmap structure.
+ *
+ *	Returns a pointer to a dga_cmap structure on success,
+ *	NULL on failure.
+ *
+ *
+ *    void
+ *    dga_cm_ungrab(cginfo,cflag)
+ *		Dga_cmap	cginfo ;
+ *		int		cflag ;
+ *
+ *	Release a colormap.  All resources allocated by dga_cm_grab are
+ *	freed.  The application should call XDgaUnGrabColormap after calling
+ *	dga_cm_ungrab() so that the server may free the colormap info page
+ *	at the other end.
+ *
+ *	if cflag is nonzero, the framebuffr fd described in the info page
+ *	is also closed.  The info page is invalid after this call and
+ *	references to it will probably result in a SIGSEGV.
+ *
+ *
+ *
+ *
+ *    void
+ *    dga_cm_get(cginfo,index,count, red,green,blue)
+ *		Dga_cmap	cginfo ;
+ *		int		index, count ;
+ *		u_char		*red, *green, *blue ;
+ *
+ *	Read colormap values and return them to the application.
+ *
+ *
+ *    void
+ *    dga_cm_put(cginfo,index,count, red,green,blue)
+ *		Dga_cmap	cginfo ;
+ *		int		index, count ;
+ *		u_char		*red, *green, *blue ;
+ *
+ *	Write colormap to hardware if colormap is installed, otherwise
+ *	save them in shared memory.
+ *
+ *
+ *
+ *    void
+ *    dga_cm_write(cginfo,index,count, red,green,blue, putfunc)
+ *      Dga_cmap    cginfo ;
+ *      int     index, count ;
+ *      u_char      *red, *green, *blue ;
+ * 		int		(*putfunc)();
+ *
+ *  Write colormap to hardware by calling the user supplied putfunc 
+ *  if colormap is installed, otherwise save them in shared memory.
+ * 
+ **    void
+ *    dga_cm_read(cginfo,index,count, red,green,blue)
+ *      Dga_cmap    cginfo ;
+ *      int     index, count ;
+ *      u_char      *red, *green, *blue ;
+ * 		int		(*putfunc)();
+ *
+ *	Read colormap values and return them to the application
+ *
+ *	int
+ *	dga_cm_get_devfd(cginfo)
+ *	Dga_cmap cginfo;
+ *
+ *	Return the fd of the device associated with cginfo
+ *
+ *	void
+ *	dga_cm_get_devinfo(cginfo)
+ *	Dga_cmap cginfo;
+ *
+ *	Returns pointer to the device specific info associated with
+ *	cginfo. Used to communicate info bet server and client
+ *
+ *	void
+ *	dga_cm_set_client_infop(cginfo, client_info_ptr)
+ *	Dga_cmap cginfo;
+ *	void*  client_info_ptr;
+ *
+ *	Sets pointer to client specificr-data associated with cginfo.
+ *
+ *	void *
+ *	dga_cm_get_client_infop(cginfo)
+ *	Dga_cmap cginfo;
+ *
+ *	Returns the client specific data pointer associated with cginfo
+
+ ****/
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <sys/ioctl.h>
+#include <sys/time.h>
+#include <errno.h>
+#include <X11/Xlib.h>
+
+#ifdef SVR4
+#include <sys/fbio.h>
+#ifdef SUNWINDOWS	/* see note later */
+#include <sys/cms.h>
+#include <sys/rect.h>
+#include <sys/win_screen.h>
+#include <sys/win_input.h>
+#include <sys/win_ioctl.h>
+#endif /* SUNWINDOWS */
+#include <unistd.h>
+#else
+#include <sun/fbio.h>
+#include <sunwindow/cms.h>
+#include <sunwindow/rect.h>
+#include <sunwindow/win_screen.h>
+#include <sunwindow/win_input.h>
+#include <sunwindow/win_ioctl.h>
+#endif
+
+#ifndef FB_CLUTPOST
+struct  fb_clut {
+        unsigned int    flags;          /* flags                        */
+        int             index;          /* CLUT id                      */
+        int             offset;         /* offset within the CLUT       */
+        int             count;          /* nbr of entries to be posted  */
+        unsigned char   *red;           /* pointer to red table         */
+        unsigned char   *green;         /* pointer to green table       */
+        unsigned char   *blue;          /* pointer to blue table        */
+};
+
+#ifdef SVR4
+#define FB_CLUTPOST	(('t' << 8) | 4)
+#else
+#define FB_CLUTPOST     _IOW(t,   4, struct fb_clut)
+#endif
+#endif
+
+
+#include "cmap_grab.h"
+
+
+/* externs */
+#if 0
+extern	char	*_SysErrorMsg[] ;
+#endif
+
+extern int _dga_winlockat(u_long cookie, int **lockp, int **unlockp);
+extern int _dga_winlockdt(int *lockp, int *unlockp);
+
+#define	GRABFILE	"/tmp/cm"
+#define	NDIGITS		8
+
+#define	MINSHMEMSIZE	(8*1024)
+#define	CG_PAGESZ	(8*1024)
+
+static	Dga_cmap	errret() ;
+static	int		sunwindows_open();
+static	void		sunwindows_close();
+
+static	Dga_cmap	grabbed_list = NULL ;
+
+static	int		cleanup_lockpages();
+
+/*ARGSUSED*/
+Dga_cmap
+dga_cm_grab(fd, filesuffix)
+int		fd ;
+Dga_token	filesuffix ;
+{
+    Grabbedcmap	*infop, tmp ;
+    _Dga_cmap	cmap_grab ;
+    char		fn[sizeof(GRABFILE)+NDIGITS+1];
+    char		*lock, *unlock ;
+    int		lockfd,			/* lock device */
+		devfd,			/* framebuffer */
+		infofd,			/* shared memory file */
+		sunwindows_def_fd,	/* /dev/winXX fd */
+		sunwindows_inst_fd ;	/* /dev/winXX fd */
+    int		locktype = 0 ;		/* use /dev/winlock */
+    int		cflag = 0 ;		/* close devfd */
+    u_long	cookie;
+    int		cmaplen ;
+    int		filelen ;
+    int		ok;
+    struct fbtype   fbd_type;
+
+#ifdef MT
+    mutex_lock(&dgaGlobalMutex);
+#endif
+    /* first and foremost, is this a nested grab? */
+    for(cmap_grab = grabbed_list; cmap_grab != NULL;
+		     cmap_grab = cmap_grab->cm_next) {
+    	if (cmap_grab->cm_token == filesuffix) {
+    		++cmap_grab->cm_grab_count;
+#ifdef MT
+		mutex_unlock(&dgaGlobalMutex);
+#endif
+    		return cmap_grab;
+    	}
+    }
+
+    if((cmap_grab = (_Dga_cmap)calloc(1,sizeof(struct dga_cmap))) == NULL ) {
+#ifdef MT
+	    mutex_unlock(&dgaGlobalMutex);
+#endif
+	    return errret("malloc failed", fn) ;
+    }
+
+    cmap_grab->cm_infofd =
+    cmap_grab->cm_devfd =
+    cmap_grab->cm_lockfd =
+    cmap_grab->cm_sunwindows_def_fd =
+    cmap_grab->cm_sunwindows_inst_fd = -1 ;
+    cmap_grab->cm_grab_count = 1 ;
+    cmap_grab->cm_next = grabbed_list ;
+    grabbed_list = cmap_grab ;
+
+    /* open the file.  Read in enough data to find out long it is. */
+
+    sprintf(fn, "%s%08x", GRABFILE, filesuffix) ;
+
+    if ((infofd = open(fn,O_RDWR,0666))<0) {
+	cleanup_lockpages(cmap_grab,0,0,0) ;
+#ifdef MT
+	mutex_unlock(&dgaGlobalMutex);
+#endif
+	return errret("can't open info page, ", fn) ;
+    }
+
+    if( read(infofd, &tmp, sizeof(tmp)) != sizeof(tmp) ) {
+	cleanup_lockpages(cmap_grab,0,0,0) ;
+#ifdef MT
+	mutex_unlock(&dgaGlobalMutex);
+#endif
+	return errret("info page too short", fn) ;
+    }
+
+    if( tmp.cm_magic != CMMAGIC ) {
+	cleanup_lockpages(cmap_grab,0,0,0) ;
+#ifdef MT
+	mutex_unlock(&dgaGlobalMutex);
+#endif
+	return errret("invalid magic number", fn) ;
+    }
+
+    cookie = tmp.cm_cookie;
+    cmaplen = tmp.cm_reallen ;
+
+    filelen = tmp.cm_shadowofs + 3*cmaplen*sizeof(short) + 4*cmaplen;
+
+    /* map the colormap info area */
+
+    infop = (Grabbedcmap *)mmap(0,
+			filelen,
+			PROT_READ|PROT_WRITE,
+			MAP_SHARED,
+			infofd,
+			(off_t)0);
+
+    /* we're all done with infofd now.  If the info file becomes
+     * subject to growth later, we'll want to keep it open.
+     */
+    (void) close(infofd) ;
+    cmap_grab->cm_infofd = -1 ;
+
+    if (infop == (Grabbedcmap *)-1) {
+	cleanup_lockpages(cmap_grab,0,filelen,0) ;
+#ifdef MT
+	mutex_unlock(&dgaGlobalMutex);
+#endif
+        return errret("can't map info page", fn) ;
+    }
+    cmap_grab->cm_info = (void *) infop ;
+
+
+    /* Open framebuffer if not provided by caller */
+
+    if( fd == -1 ) {
+	devfd = open(infop->cm_devname, O_RDWR,0666) ;
+	if( devfd < 0 ) {
+#ifdef	DEBUG
+	    fprintf(stderr, "wx_cm_grab: cannot open %s, %s\n",
+		infop->cm_devname, strerror(errno)) ;
+#endif	/* DEBUG */
+	    cleanup_lockpages(cmap_grab,0,filelen,0) ;
+#ifdef MT
+	    mutex_unlock(&dgaGlobalMutex);
+#endif
+	    return NULL ;
+	}
+	cflag = 1 ;
+    } else
+	  devfd = fd ;
+
+    cmap_grab->cm_devfd = devfd ;
+
+    locktype = infop->cm_version >= 1 ? infop->cm_locktype : CM_LOCKDEV ;
+
+    switch( locktype ) {
+	case CM_LOCKDEV:
+	    /* if lockdevice explicitly specified by server, we need to
+	     * open it here, even if the calling routine has opened the
+	     * framebuffer for us.  Otherwise, we use the framebuffer device.
+	     */
+
+	    if( infop->cm_lockdevname[0] != '\0' ) {
+		lockfd = open(infop->cm_lockdevname, O_RDWR,0666) ;
+		if( lockfd < 0 ) {
+#ifdef	DEBUG
+		    fprintf(stderr, "wx_cm_grab: cannot open %s, %s\n",
+		    infop->cm_lockdevname, strerror(errno)) ;
+#endif	/* DEBUG */
+		    cleanup_lockpages(cmap_grab,cflag,filelen,locktype) ;
+#ifdef MT
+		    mutex_unlock(&dgaGlobalMutex);
+#endif
+		    return NULL ;
+		}
+	    } else
+		lockfd = devfd ;
+
+	    cmap_grab->cm_lockfd = lockfd ;
+
+	    /* map the lock page */
+	    lock = (char *)mmap(0, 
+		    CM_PAGESZ, 
+		    PROT_READ|PROT_WRITE, 
+		    MAP_SHARED,
+		    lockfd, (off_t)cookie);
+
+	    if (lock == (char *)-1) {
+		cleanup_lockpages(cmap_grab,cflag,filelen,0) ;
+#ifdef MT
+		mutex_unlock(&dgaGlobalMutex);
+#endif
+		return errret("can't map lock page",tmp.cm_devname) ;
+	    }
+	    cmap_grab->cm_lockp = (u_int *) lock ;
+
+	    /* map the unlock page */
+	    unlock = (char *) mmap(0,
+		      CM_PAGESZ, 
+		      PROT_READ|PROT_WRITE, 
+		      MAP_SHARED,
+		      lockfd,(off_t)cookie) ;
+
+	    if( unlock == (char *)-1 ) {
+		cleanup_lockpages(cmap_grab,cflag,filelen,0) ;
+#ifdef MT
+		mutex_unlock(&dgaGlobalMutex);
+#endif
+		return errret("can't map unlock page", tmp.cm_devname) ;
+	    }
+	    cmap_grab->cm_unlockp = (u_int *) unlock ;
+        break ;
+	case CM_WINLOCK:
+	    if( _dga_winlockat(cookie, &lock, &unlock) != 0 ) {
+	      cleanup_lockpages(cmap_grab,cflag,filelen,locktype) ;
+#ifdef MT
+	      mutex_unlock(&dgaGlobalMutex);
+#endif
+	      return errret("can't get lock pages", fn) ;
+	    }
+	    cmap_grab->cm_lockp = (u_int *) lock ;
+	    cmap_grab->cm_unlockp = (u_int *) unlock ;
+        break ;
+    }
+
+    /* fill in the misc stuff */
+
+    sunwindows_def_fd = sunwindows_inst_fd = -1;
+    ok = 1;
+    if (infop->cm_default && (infop->cm_sunwindows_def_devname[0] != '\0')) {
+	if ((sunwindows_def_fd = sunwindows_open(
+			infop->cm_sunwindows_def_devname)) < 0)
+	    ok = 0;
+    }
+    cmap_grab->cm_sunwindows_def_fd = sunwindows_def_fd ;
+    if (ok && (infop->cm_sunwindows_inst_devname[0] != '\0')) {
+        if ((sunwindows_inst_fd = sunwindows_open(
+    		infop->cm_sunwindows_inst_devname)) < 0)
+        ok = 0;
+    }
+    cmap_grab->cm_sunwindows_inst_fd = sunwindows_inst_fd ;
+
+    if(!ok) {
+        cleanup_lockpages(cmap_grab,cflag,filelen,locktype) ;
+#ifdef MT
+	mutex_unlock(&dgaGlobalMutex);
+#endif
+        return errret("/dev/winxx open failed", fn) ;
+    }
+
+    cmap_grab->cm_token = filesuffix;
+    cmap_grab->cm_client = NULL ;
+    cmap_grab->c_chngcnt = -1 ;	/* flag all changes as not seen */
+    cmap_grab->s_chngcnt_p = (u_int *) &(infop->cm_count);
+    cmap_grab->cm_lockcnt = 0 ;
+    cmap_grab->cm_use_new_ioctl = 1 ;	/* try to use new ioctl */
+
+#ifdef MT
+    mutex_unlock(&dgaGlobalMutex);
+#endif
+    return((Dga_cmap)cmap_grab);
+}
+
+
+static int
+cleanup_lockpages(cginfo,cflag,filelen,locktype)
+    _Dga_cmap	cginfo ;
+    int		cflag, filelen, locktype ;
+{
+    int	error = 0 ;
+    _Dga_cmap	p1, p2 ;
+
+    if (cginfo->cm_sunwindows_def_fd >= 0)
+        sunwindows_close(cginfo->cm_sunwindows_def_fd);
+    if (cginfo->cm_sunwindows_inst_fd >= 0)
+        sunwindows_close(cginfo->cm_sunwindows_inst_fd);
+    switch( locktype ) {
+	case CM_LOCKDEV:
+	    if( cginfo->cm_unlockp != NULL )
+	      error |= munmap((char *)cginfo->cm_unlockp,CM_PAGESZ) < 0 ;
+	    if( cginfo->cm_lockp != NULL )
+	      error |= munmap((char *)cginfo->cm_lockp,CM_PAGESZ) < 0 ;
+	    if( cginfo->cm_lockfd != -1 &&
+		cginfo->cm_lockfd != cginfo->cm_devfd )
+	      error |= close(cginfo->cm_lockfd) ;
+	break ;
+	case CM_WINLOCK:
+	   error |= _dga_winlockdt(cginfo->cm_lockp, cginfo->cm_unlockp) < 0 ;
+	break ;
+    }
+    if( cginfo->cm_info != NULL )
+	error |= munmap(cginfo->cm_info, filelen) < 0 ;
+    if( cginfo->cm_infofd != -1 )
+	    error |= close(cginfo->cm_infofd) < 0 ;
+    if( cflag )
+	  error |= close(cginfo->cm_devfd) < 0 ;
+
+    for( p1 = grabbed_list, p2 = NULL ; p1 != NULL  &&  p1 != cginfo;
+			p2 = p1, p1=p1->cm_next) ;
+    if( p1 == NULL )		/* not found?? */
+	error = 1 ;
+    else {
+	if( p2 == NULL )
+	    grabbed_list = p1->cm_next ;
+	  else
+	    p2->cm_next = p1->cm_next ;
+    }
+    free(cginfo);
+    return error ? -1 : 0 ;
+}
+
+void
+dga_cm_ungrab(cginfoi, cflag)
+Dga_cmap	cginfoi ;
+int		cflag ;
+{
+    _Dga_cmap cginfo = (struct dga_cmap *)cginfoi;
+    Grabbedcmap  *infop = (Grabbedcmap *) cginfo->cm_info ;
+    int	cmaplen, filelen ;
+    int	locktype ;
+
+#ifdef MT
+    mutex_lock(&dgaGlobalMutex);
+#endif
+    if( --cginfo->cm_grab_count > 0 ) {
+#ifdef MT
+	  mutex_unlock(&dgaGlobalMutex);
+#endif
+	  return;
+    }
+
+    cmaplen = infop->cm_reallen ;
+    filelen = infop->cm_shadowofs + 3*cmaplen*sizeof(short) + 4*cmaplen ;
+
+    cleanup_lockpages(cginfo,cflag,filelen,
+	      infop->cm_version >= 1 ? infop->cm_locktype : CM_LOCKDEV ) ;
+#ifdef MT
+    mutex_unlock(&dgaGlobalMutex);
+#endif
+}
+
+static Dga_cmap
+errret(msg,file)
+char	*msg, *file ;
+{
+#ifdef	DEBUG
+	fprintf(stderr, "colormap-grab: %s: %s, %s\n",
+		msg, file, strerror(errno)) ;
+#endif	/* DEBUG */
+	return NULL ;
+}
+
+
+
+/*
+ * Read colormap from shared memory.
+ * Shared memory should always be in sync
+ * with server's idea of this X11 colormap's
+ * contents.
+ */
+
+void
+dga_cm_get(cginfoi,index,count, red,green,blue)
+Dga_cmap	cginfoi ;
+int		index, count ;
+u_char		*red, *green, *blue ;
+{
+    _Dga_cmap cginfo = (struct dga_cmap *)cginfoi;
+    Grabbedcmap	*infop = (Grabbedcmap *) cginfo->cm_info ;
+
+#ifdef MT
+    mutex_lock(&dgaGlobalMutex);
+#endif
+    wx_cm_lock(cginfo) ;
+
+    /* REMIND: Currently, we don't need to test for any changes in the
+     * shared memory page; but if we did, right here is where we'd do
+     * it.  We compare infop->cm_count against cginfo->c_chngcnt and
+     * react if there was a difference.  After handling the change,
+     * we'd copy infop->cm_count to cginfo->c_chngcnt.
+     */
+
+    if( index+count > infop->cm_reallen )
+      count = infop->cm_reallen - index ;
+
+    if( count > 0 ) {
+
+	/* copy from shared memory */
+	short *shadow ;
+	short *ip ;
+	u_char *op ;
+	int n ;
+
+	shadow = (short *) ( (u_char *)infop + infop->cm_shadowofs ) ;
+	shadow += index ;
+	for(n=count, op=red, ip=shadow ; --n >= 0 ; *op++ = *ip++>>8 ) ;
+	shadow += infop->cm_reallen ;
+	for(n=count, op=green, ip=shadow ; --n >= 0 ; *op++ = *ip++>>8 ) ;
+	shadow += infop->cm_reallen ;
+	for(n=count, op=blue, ip=shadow ; --n >= 0 ; *op++ = *ip++>>8 ) ;
+    }
+    wx_cm_unlock(cginfo) ;
+#ifdef MT
+    mutex_unlock(&dgaGlobalMutex);
+#endif
+}
+/* This is the new interface that will be publicly exposed */
+void
+dga_cm_read(cginfo,index,count, red,green,blue)
+Dga_cmap cginfo;
+int             index, count ;
+u_char          *red, *green, *blue ;
+{
+    dga_cm_get(cginfo,index,count, red,green,blue);
+}
+
+
+/* write colormap to shared memory, and to DACS if appropriate. */
+
+void
+dga_cm_put(cginfoi,index,count, red,green,blue)
+Dga_cmap cginfoi ;
+int index, count ;
+u_char *red, *green, *blue ;
+{
+    _Dga_cmap cginfo = (struct dga_cmap *)cginfoi;
+    Grabbedcmap	*infop = (Grabbedcmap *) cginfo->cm_info ;
+    short		*shadow ;
+    u_char		*ip ;		/* in pointer */
+    short		*op ;		/* out pointer */
+    u_char		*fp ;		/* flag pointer */
+    int		n ;
+
+#ifdef MT
+    mutex_lock(&dgaGlobalMutex);
+#endif
+    wx_cm_lock(cginfo) ;
+
+    if( index+count > infop->cm_reallen )
+	count = infop->cm_reallen - index ;   
+    if( count > 0 ) {
+	if( index < infop->cm_start )
+	    infop->cm_start = index ;
+	if( index + count > infop->cm_start + infop->cm_len )
+	    infop->cm_len = index + count -infop->cm_start ;
+
+	/* copy to shared memory shadow of grabbed color map */
+	/* "stutter" the 8-bit values into 16 bits */
+
+	shadow = (short *) ( (u_char *)infop + infop->cm_shadowofs ) ;
+	shadow += index ;
+	for(n=count, ip=red, op=shadow ; --n >= 0 ; *op++, *ip++)
+		*op = *ip | (*ip << 8);
+	shadow += infop->cm_reallen ;
+	for(n=count, ip=green, op=shadow ; --n >= 0 ; *op++, *ip++)
+		*op = *ip | (*ip << 8);
+	shadow += infop->cm_reallen ;
+	for(n=count, ip=blue, op=shadow ; --n >= 0 ; *op++, *ip++)
+		*op = *ip | (*ip << 8);
+	fp = (u_char *)infop + infop->cm_shadowofs +
+		3 * infop->cm_reallen * sizeof(short) + index ;
+	for(n=count ; --n >= 0 ; *fp++ = 1 ) ;
+
+	if( infop->cm_installed ) {
+#ifdef COMMENT
+	    /* We no longer need the hw shadow cmap but have to keep
+	     * the structures the same size and so we will just stop
+	     * updating it
+	     */
+	    u_char *hwshadow;
+	
+	    /* copy to shared memory shadow of hardware color map */
+	    hwshadow = (u_char *)infop + infop->cm_shadowofs +
+		3 * infop->cm_reallen * sizeof(short) +
+		infop->cm_reallen + index;
+	    for (n=count, ip=red, fp=hwshadow; --n >= 0; *fp++ = *ip++);
+	    hwshadow += infop->cm_reallen;
+	    for (n=count, ip=green, fp=hwshadow; --n >= 0; *fp++ = *ip++);
+	    hwshadow += infop->cm_reallen;
+	    for (n=count, ip=blue, fp=hwshadow; --n >= 0; *fp++ = *ip++);
+	    hwshadow -= index + 2 * infop->cm_reallen;
+#endif
+	    switch(infop->cm_load_method) {
+
+#ifdef SUNWINDOWS 
+		/* Note from V4 on, SUnwindows include files, support no
+		 * longer exist. I am commenting out the code instead of
+		 * removing it only for completeness. After Mars, time to
+		 * move away from sunwindows....
+		*/
+		case SUNWINDOWS_IOCTL:
+		{
+		    struct cmschange cmschange;
+
+		    if( cginfo->cm_sunwindows_def_fd >= 0 ) {
+			strcpy(cmschange.cc_cms.cms_name,
+			    infop->cm_sunwindows_def_cmapname);
+			cmschange.cc_cms.cms_addr = 0;
+			cmschange.cc_cms.cms_size =
+			    infop->cm_sunwindows_def_cmapsize;
+			cmschange.cc_map.cm_red = hwshadow;
+			cmschange.cc_map.cm_green = 
+			    hwshadow + infop->cm_reallen;
+			cmschange.cc_map.cm_blue = 
+			hwshadow + 2 * infop->cm_reallen;
+
+		    /* HACK ALERT */
+		    /* Adjust SUNWINDOWS cms segment 1st colr != last color */
+		    if ((cmschange.cc_map.cm_red[0] ==
+		      cmschange.cc_map.cm_red[cmschange.cc_cms.cms_size-1]) &&
+		      (cmschange.cc_map.cm_green[0] ==
+		      cmschange.cc_map.cm_green[cmschange.cc_cms.cms_size-1]) &&
+		      (cmschange.cc_map.cm_blue[0] ==
+		      cmschange.cc_map.cm_blue[cmschange.cc_cms.cms_size-1]))
+			{
+			if (cmschange.cc_map.cm_blue[0] > 0)
+			    cmschange.cc_map.cm_blue[0]--;
+			else
+			    cmschange.cc_map.cm_blue[0] = 1;
+			}
+
+		    ioctl(cginfo->cm_sunwindows_def_fd, WINSETCMS, &cmschange);
+		    }
+
+		if( cginfo->cm_sunwindows_inst_fd >= 0 )
+		    {
+		    strcpy(cmschange.cc_cms.cms_name,
+			infop->cm_sunwindows_inst_cmapname);
+		    cmschange.cc_cms.cms_addr = 0;
+		    cmschange.cc_cms.cms_size =
+			infop->cm_sunwindows_inst_cmapsize;
+		    cmschange.cc_map.cm_red = hwshadow;
+		    cmschange.cc_map.cm_green = hwshadow + infop->cm_reallen;
+		    cmschange.cc_map.cm_blue = 
+			hwshadow + 2 * infop->cm_reallen;
+
+		    /* HACK ALERT */
+		    /* Adjust SUNWINDOWS cms segment 1st colr != last color */
+		    if ((cmschange.cc_map.cm_red[0] ==
+		      cmschange.cc_map.cm_red[cmschange.cc_cms.cms_size-1]) &&
+		      (cmschange.cc_map.cm_green[0] ==
+		      cmschange.cc_map.cm_green[cmschange.cc_cms.cms_size-1]) &&
+		      (cmschange.cc_map.cm_blue[0] ==
+		      cmschange.cc_map.cm_blue[cmschange.cc_cms.cms_size-1])) {
+			if (cmschange.cc_map.cm_blue[0] > 0)
+			    cmschange.cc_map.cm_blue[0]--;
+			else
+			    cmschange.cc_map.cm_blue[0] = 1;
+		    }
+
+		    ioctl(cginfo->cm_sunwindows_inst_fd,WINSETCMS,&cmschange);
+		}
+	    }
+	    break;
+#endif /* SUNWINDOWS */
+	    case HW_DEVICE_DIRECT:	/* could have device-specific
+					   routines here; just fall
+					   through to device ioctl
+					   for now */
+
+	    case HW_DEVICE_IOCTL:
+	    default:
+#ifdef	FBIOPUTCMAPI
+		if( cginfo->cm_use_new_ioctl) {
+		    /* try new ioctl */
+		    struct fbcmap_i cmap;
+
+		    cmap.flags = 0 ;
+		    cmap.id = infop->cm_cmapnum ;
+		    cmap.index = infop->cm_ioctlbits | index;
+		    cmap.count = count;
+		    cmap.red   = red;
+		    cmap.green = green;
+		    cmap.blue  = blue;
+		    if( ioctl(cginfo->cm_devfd, FBIOPUTCMAPI, &cmap) == 0 )
+		    break;
+		}
+#endif	/* FBIOPUTCMAPI */
+
+		if( cginfo->cm_use_new_ioctl ) {	
+		    /* try FB_CLUTPOST ioctl */
+		    struct fb_clut cmap;
+
+		    cmap.flags = 0 ;
+		    cmap.index = infop->cm_cmapnum;
+		    cmap.offset = index;
+		    cmap.count = count;
+		    cmap.red   = red;
+		    cmap.green = green;
+		    cmap.blue  = blue;
+		    if( ioctl(cginfo->cm_devfd, FB_CLUTPOST, &cmap) == 0 )
+			break;
+		
+		    cginfo->cm_use_new_ioctl = 0;
+               }
+
+	       if (cginfo->cm_use_new_ioctl == 0) {
+		    struct fbcmap cmap;
+
+		    cmap.index = infop->cm_ioctlbits | index;
+		    cmap.count = count;
+		    cmap.red   = red;
+		    cmap.green = green;
+		    cmap.blue  = blue;
+		    ioctl(cginfo->cm_devfd, FBIOPUTCMAP, &cmap);
+		}
+		break;
+	    }
+	}
+
+	/* We've changed the shared memory page, flag this fact to
+	* the server and to any other clients
+	*/
+	cginfo->c_chngcnt = ++infop->cm_count ;
+    }
+    wx_cm_unlock(cginfo) ;
+#ifdef MT
+    mutex_unlock(&dgaGlobalMutex);
+#endif
+}
+
+/* This is the interfce that will be publicly exposed */
+void
+dga_cm_write(cginfoi,index,count, red,green,blue, putfunc)
+Dga_cmap   cginfoi ;
+int     index, count ;
+u_char  *red, *green, *blue ;
+void		(*putfunc)();
+{
+    _Dga_cmap cginfo = (struct dga_cmap *)cginfoi;
+    Grabbedcmap    *infop = (Grabbedcmap *) cginfo->cm_info ;
+    short       *shadow ;
+    u_char     *ip ;       /* in pointer */
+    short      *op ;       /* out pointer */
+    u_char     *fp ;       /* flag pointer */
+    int        n ;
+ 
+#ifdef MT
+    mutex_lock(&dgaGlobalMutex);
+#endif
+    wx_cm_lock(cginfo) ;
+ 
+    if( index+count > infop->cm_reallen )
+      count = infop->cm_reallen - index ;
+ 
+    if( count > 0 ) {
+	if( index < infop->cm_start )
+	    infop->cm_start = index ;
+ 
+	if( index + count > infop->cm_start + infop->cm_len )
+	    infop->cm_len = index + count -infop->cm_start ;
+ 
+	/* copy to shared memory shadow of grabbed color map */
+	/* "stutter" the 8-bit values into 16 bits */
+ 
+	shadow = (short *) ( (u_char *)infop + infop->cm_shadowofs ) ;
+	shadow += index ;
+	for(n=count, ip=red, op=shadow ; --n >= 0 ; *op++, *ip++)
+	    *op = *ip | (*ip << 8);
+	shadow += infop->cm_reallen ;
+	for(n=count, ip=green, op=shadow ; --n >= 0 ; *op++, *ip++)
+	    *op = *ip | (*ip << 8);
+	shadow += infop->cm_reallen ;
+	for(n=count, ip=blue, op=shadow ; --n >= 0 ; *op++, *ip++)
+	    *op = *ip | (*ip << 8);
+	fp = (u_char *)infop + infop->cm_shadowofs +
+	    3 * infop->cm_reallen * sizeof(short) + index ;
+	for(n=count ; --n >= 0 ; *fp++ = 1 ) ;
+        
+	if( infop->cm_installed ) {
+#ifdef COMMENT
+	    /* We dont need to update thie any more */
+	    u_char *hwshadow;
+ 
+	    /* copy to shared memory shadow of hardware color map */
+	    hwshadow = (u_char *)infop + infop->cm_shadowofs +
+		3 * infop->cm_reallen * sizeof(short) +
+	    infop->cm_reallen + index;
+	    for (n=count, ip=red, fp=hwshadow; --n >= 0; *fp++ = *ip++);
+	    hwshadow += infop->cm_reallen;
+	    for (n=count, ip=green, fp=hwshadow; --n >= 0; *fp++ = *ip++);
+	    hwshadow += infop->cm_reallen;
+	    for (n=count, ip=blue, fp=hwshadow; --n >= 0; *fp++ = *ip++);
+	    hwshadow -= index + 2 * infop->cm_reallen;
+ 
+	    for (n=count, ip=blue, fp=hwshadow; --n >= 0; *fp++ = *ip++);
+	    hwshadow -= index + 2 * infop->cm_reallen;
+#endif
+	    /* Now call the user supplied function for actually
+	    * posting the cmap
+	    */
+	    (*putfunc)( cginfo, index, count, red, green, blue);
+      }
+         
+      /* We've changed the shared memory page, flag this fact to
+       * the server and to any other clients
+       */
+ 
+      cginfo->c_chngcnt = ++infop->cm_count ;
+    }
+    wx_cm_unlock(cginfo) ;
+#ifdef MT
+    mutex_unlock(&dgaGlobalMutex);
+#endif
+}    
+
+/* Interfaces that will be exposed to the public */
+int
+dga_cm_devdfd(cginfoi)
+Dga_cmap   cginfoi ;
+{
+
+    return (((struct dga_cmap *)cginfoi)->cm_devfd);
+}
+
+/* This device info is shared between the server and client */
+void *
+dga_cm_devinfo(cginfoi)
+Dga_cmap   cginfoi ;
+{
+    _Dga_cmap cginfo = (struct dga_cmap *)cginfoi;
+    return ((void *)(((char *)cginfo->cm_info) 
+			+ CM_INFOP(cginfo)->device_offset));
+
+}
+
+/* Each client may store private info in the client info ptr */
+void
+dga_cm_set_client_infop(cginfoi, client_info_ptr)
+Dga_cmap cginfoi;
+void* client_info_ptr;
+{
+    _Dga_cmap cginfo = (struct dga_cmap *)cginfoi;
+    
+    cginfo->cm_client = client_info_ptr;
+}
+
+void *
+dga_cm_get_client_infop(cginfoi) 
+Dga_cmap cginfoi; 
+{
+    _Dga_cmap cginfo = (struct dga_cmap *)cginfoi;
+        
+    return ((void *)cginfo->cm_client); 
+} 
+
+static Cmap_Devlist *devlist = NULL;
+
+static	int
+sunwindows_open(devname)
+char *devname;
+{
+	Cmap_Devlist *dlist = devlist;
+	int fd;
+
+	while (dlist)
+		{
+		if (strcmp(devname, dlist->devname) == 0)
+			{
+			dlist->refcnt++;
+			return(dlist->fd);
+			}
+		dlist = dlist->next;
+		}
+	if ((fd = open(devname, O_RDWR, 0666)) < 0)
+		{
+#ifdef	DEBUG
+		fprintf(stderr, "colormap-grab: open failed %s, %s\n",
+		    devname, strerror(errno)) ;
+#endif	/* DEBUG */
+		return(-1);
+		}
+	if((dlist = (Cmap_Devlist *)malloc(sizeof(Cmap_Devlist))) == NULL )
+		{
+		close(fd);
+#ifdef	DEBUG
+		fprintf(stderr, "colormap-grab: malloc failed %s, %s\n",
+		    devname, strerror(errno)) ;
+#endif	/* DEBUG */
+		return(-1);
+		}
+	dlist->next = devlist;
+	devlist = dlist;
+	dlist->refcnt = 1;
+	dlist->fd = fd;
+	strcpy(dlist->devname, devname);
+	return(fd);
+}
+
+
+static	void
+sunwindows_close(fd)
+int fd;
+{
+	Cmap_Devlist *dlist = devlist;
+	Cmap_Devlist **dlptr = &devlist;
+
+	while (dlist)
+		{
+		if (fd == dlist->fd)
+			{
+			if (--dlist->refcnt == 0)
+				{
+				close(fd);
+				*dlptr = dlist->next;
+				free(dlist);
+				}
+			return;
+			}
+		dlptr = &dlist->next;
+		dlist = dlist->next;
+		}
+}
+
+
+
+
+
+
+/* /dev/winlock management code.  This is a temporary hack so we can
+ * develop the new /dev/winlock interface.  Hopefully, this will become
+ * part of the C library someday.
+ *
+ */
+
+
+#include <sys/ioccom.h>
+
+	/* structure for allocating lock contexts.  The identification
+	 * should be provided as the offset for mmap(2).  The offset is
+	 * the byte-offset relative to the start of the page returned
+	 * by mmap(2).
+	 */
+
+struct	winlockalloc {
+	u_long	sy_key ;	/* user-provided key, if any */
+	u_long	sy_ident ;	/* system-provided identification */
+	} ;
+
+struct	winlocktimeout {
+	u_long	sy_ident ;
+	u_int	sy_timeout ;
+	int	sy_flags ;
+	} ;
+
+
+#ifndef WINLOCKALLOC
+#ifdef	SVR4
+#define WIOC    ('L'<<8)
+#define WINLOCKALLOC            (WIOC|0)
+#define WINLOCKFREE             (WIOC|1)
+#define WINLOCKSETTIMEOUT       (WIOC|2)
+#define WINLOCKGETTIMEOUT       (WIOC|3)
+#define WINLOCKDUMP             (WIOC|4)
+#else	/* SVR4 */
+#define	WINLOCKALLOC	_IOWR(L, 0, struct winlockalloc)
+#define	WINLOCKFREE	_IOW(L, 1, u_long)
+#define	WINLOCKSETTIMEOUT	_IOW(L, 2, struct winlocktimeout)
+#define	WINLOCKGETTIMEOUT	_IOWR(L, 3, struct winlocktimeout)
+#define	WINLOCKDUMP	_IO(L, 4)
+#endif	/* SVR4 */
+#endif	/* WINLOCKALLOC */
+
+
+/* flag bits */
+#define SY_NOTIMEOUT	0x1	/* This client never times out */
+
+
+static	char	*lockdev_name = "/dev/winlock" ;
+static	char	*alt_lockdev_name = "/dev/cgsix0" ;
+
+static	int	lock_fd = -1 ;
+static	u_long	pagemask ;
+static	u_long	pageoffset ;
+static	u_long	pagesize ;
+
+
+
+	/* return non-zero if fail */
+
+static int
+init()
+{
+	if( lock_fd == -1 ) {
+	  if( (lock_fd = open(lockdev_name, O_RDWR, 0)) == -1  &&
+	      (lock_fd = open(alt_lockdev_name, O_RDWR, 0)) == -1 )
+	    return 1 ;
+#ifdef SVR4
+	pagesize = sysconf(_SC_PAGESIZE);
+#else
+	  pagesize = getpagesize() ;
+#endif
+	  pageoffset = pagesize - 1 ;
+	  pagemask = ~pageoffset ;
+	}
+
+	return 0 ;
+}
+
+
+int
+_dga_winlockat(cookie, lockp, unlockp)
+	u_long	cookie ;
+	int	**lockp, **unlockp ;
+{
+	u_long	ofs ;
+	caddr_t	ptr ;
+
+	if( lock_fd == -1  &&  init() )
+	{
+	  errno = EINVAL ;
+	  return -1 ;
+	}
+
+	ofs = cookie & pageoffset ;
+	cookie &= pagemask ;
+
+	ptr = mmap(0, pagesize, PROT_READ|PROT_WRITE,
+		MAP_SHARED, lock_fd, (off_t)cookie) ;
+	if( (int)ptr == -1 )
+	{
+	  errno = ENOSPC ;
+	  return -1 ;
+	}
+	*lockp = (int *) (ptr+ofs) ;
+
+	ptr = mmap(0, pagesize, PROT_READ|PROT_WRITE,
+		MAP_SHARED, lock_fd, (off_t)cookie) ;
+	if( (int)ptr == -1 )
+	{
+	  (void) munmap((caddr_t)*lockp, pagesize) ;
+	  errno = ENOSPC ;
+	  return -1 ;
+	}
+	*unlockp = (int *) (ptr+ofs) ;
+
+	return 0 ;
+}
+
+
+
+int
+_dga_winlockdt(lockp, unlockp)
+	int	*lockp, *unlockp ;
+{
+	caddr_t	ptr ;
+
+	if( lock_fd == -1  &&  init() )
+	{
+	  errno = EINVAL ;
+	  return -1 ;
+	}
+
+	ptr = (caddr_t) ((long)lockp & pagemask) ;
+	if( munmap(ptr, pagesize) )
+	    perror("_dga_winlockdt: munmap:");
+
+        ptr = (caddr_t) ((long)unlockp & pagemask) ;
+        if( munmap(ptr, pagesize) )
+            perror("_dga_winlockdt: munmap:");
+
+	return 0 ;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/lib/libdga/sun-src/cmap_grab.h	Fri Nov 13 13:30:43 2009 -0800
@@ -0,0 +1,231 @@
+/* Copyright 1996 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ *
+ * 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, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * 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
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR 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.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+#pragma ident	"@(#)cmap_grab.h	35.7	09/11/09 SMI"
+
+/*
+ * cmap_grab.h - colormap grabber structures and information
+ */
+
+#ifndef _CMAP_GRAB_H
+#define _CMAP_GRAB_H
+
+
+
+/****
+ *
+ * Colormap grabber header file.
+ *
+ *
+ *
+ * Macros defined here:
+ *
+ *  sh_cm_lock(infop)
+ *  sh_cm_unlock(infop)
+ *	lock and unlock colormap info page.  'infop' is the Grabbedcmap
+ *	pointer returned by cmapgrab_grab()
+ *
+ *  sh_cmapgrab_cookie(infop)
+ *	returns the colormap info page cookie used to map the info page.
+ *	this is the value that should be returned to the requesting
+ *	client.
+ *
+ ****/
+
+
+#include <sys/types.h>
+#ifdef MT
+#include <synch.h>
+#endif
+
+#include "dga.h"
+#include "dga_internal.h"
+
+
+/* method to use to load colormaps */
+
+typedef enum {
+	SUNWINDOWS_IOCTL=0,	/* use /dev/winxx SunWindows device driver */
+	HW_DEVICE_IOCTL=1,	/* use graphics hardware device driver */
+	HW_DEVICE_DIRECT=2	/* access hardware colormap directly */
+} cmap_load_method;
+
+
+#define	CMMAGIC	0x434d4150	/* "CMAP" */
+#define	CMVERS	0
+
+#define	MAX_CM_DEVNAME	40	/* better not have long device names */
+#define DGA_CM_DEV_INFO_SZ 132
+
+	/* device types, from sh_scr_dev.h */
+
+#define	SCR_DEV_GENERIC	0	/* generic class implementations */
+#define	SCR_DEV_MEM1	1	/* depth 1 memory framebuffer */
+#define	SCR_DEV_MEM8	2	/* depth 8 memory framebuffer */
+#define	SCR_DEV_MEM32	3	/* depth 32 memory framebuffer */
+
+#define	SCR_DEV_CG2	4	/* Sun CG2 framebuffer (depth 8) */
+#define	SCR_DEV_BW2	5	/* Sun BW2 framebuffer (depth 1) */
+#define	SCR_DEV_CG4	6	/* Sun CG4 framebuffer (1 or 8) */
+#define	SCR_DEV_CG6	7	/* Sun CG6 (Lego) */
+#define	SCR_DEV_CG3	8	/* Sun CG3 (Color RoadRunner) */
+#define	SCR_DEV_GPFB	9	/* GP1/GP+/GP2 framebuffer (depth 8) */
+#define	SCR_DEV_GP	10	/* GP1/GP+/GP2 accelerator */
+#define	SCR_DEV_CG5	11	/* Sun CG5 framebuffer (depth 8) */
+#define SCR_DEV_CG8	12	/* Sun CG8 framebuffer (depth 8, 24 bit color)*/
+#define SCR_DEV_GT      13      /* Sun GT (Hawk) depth 1, 8, and 24 bit */
+#define SCR_DEV_CG12    14      /* Sun CG12 (Egret) depth 1, 8, and 24 bit */
+#define SCR_DEV_REC     15      /* Recording device type */
+#define SCR_DEV_SMC     16      /* Sun SMC/MDI (SPAM) depth 1, 8, 24-bit */
+
+#define SCR_DEV_LAST    16
+
+
+/* info in shared memory */
+
+typedef	struct _grabbedcmap
+{
+    /* version 0 info starts here */
+	long	cm_magic ;	/* "CMAP" = 0x434d4150 ("PAMC" on 386i) */
+	long	cm_version ;	/* 0 */
+	int	cm_count ;	/* change count */
+	struct _grabbedcmap *cm_ptr ;	/* self-reference */
+	u_long	cm_cmap ;	/* X11 colormap ID */
+
+	u_long	cm_cookie ;	/* lock-page cookie */
+
+	/* server-specific info, not meaningful to client */
+	int	cm_sinfofd ;
+	int	cm_sdevfd ;
+	u_long	*cm_slockp ;
+	u_long	*cm_sunlockp ;
+	int	cm_slockcnt ;
+	int	cm_clientcnt ;
+	int	cm_filesuffix ;
+	caddr_t	cm_shras ;
+
+	char	cm_devname[MAX_CM_DEVNAME] ;
+	char	cm_lockdevname[MAX_CM_DEVNAME] ;
+	int	cm_default ;	/* is it the default colormap for this screen */
+	int	cm_installed ;	/* flag: colormap is installed in HW */
+	cmap_load_method cm_load_method ;   /* see typedef above */
+	char	cm_sunwindows_def_devname[MAX_CM_DEVNAME] ; /* device name, */
+	char	cm_sunwindows_def_cmapname[MAX_CM_DEVNAME] ;/* cmap name, and */
+	int	cm_sunwindows_def_cmapsize; /* size of server's SunWindows
+					       color map "xnews_default" */
+	char	cm_sunwindows_inst_devname[MAX_CM_DEVNAME] ; /* device name, */
+	char	cm_sunwindows_inst_cmapname[MAX_CM_DEVNAME];/* cmap name, and */
+	int	cm_sunwindows_inst_cmapsize; /* size of server's SunWindows
+					       color map "xnews_installed" */
+	int	cm_fbtype ;	/* reserved */
+	int	cm_reallen ;	/* colormap hardware size */
+	int	cm_start ;	/* first valid location */
+	int	cm_len ;	/* number of valid locations */
+	int	cm_cmapnum ;	/* [0]cmap number - FB's with multiple maps */
+	int	cm_ioctlbits ;	/* [0]high-order bits for FBIOPUTCMAP */
+	int	cm_devtype ;	/* device hardware type */
+	int	cm_reserved[5] ;/* reserved */
+
+	long	cm_shadowofs ;	/* byte offset relative to cm_magic of
+				   the start of the shadow colormap */
+
+    /* version 1 info starts here */
+	int	cm_scount ;	/* server's last remembered count */
+	int	cm_locktype ;	/* using /dev/winlock? see below. */
+
+    /* version 2 info starts here */
+	u_int   device_offset;	/* offset to device specific section */
+
+	/* Do NOT add any fields below dev_info */
+	u_char  dev_info[DGA_CM_DEV_INFO_SZ];/* device specific information */
+} Grabbedcmap ;
+
+
+	/* followed by three arrays of u_shorts, length cm_len, for
+	   red, green and blue and one array of bytes which are
+	   the change flags for their respective colors:
+
+		rr
+		rr
+		rr
+		:
+		gg
+		gg
+		gg
+		:
+		bb
+		bb
+		bb
+		:
+		f
+		f
+		f
+		:
+	    
+	    Clients set a flag to non-zero to indicate that the color
+	    has been changed.  The server clears these when the chagnes
+	    have been seen. */
+
+#define	CM_LOCKDEV	0	/* use GRABPAGEALLOC from device */
+#define	CM_WINLOCK	1	/* use winlock functions */
+
+
+
+
+typedef struct cmap_devlist{
+	int fd;
+	int refcnt;
+	char devname[MAX_CM_DEVNAME];
+	struct cmap_devlist *next;
+} Cmap_Devlist;
+
+
+#define CM_PAGESZ       (8*1024)
+#define CM_LOCK(x)      (*(x)) = 1
+#define CM_UNLOCK(x)    (*(x)) = 0
+
+
+#define	wx_cm_lock(infop)		\
+    do {				\
+    if( (infop)->cm_lockcnt++ == 0 )	\
+	*(infop)->cm_lockp = 1 ;	\
+    } while (0)
+
+#define	wx_cm_unlock(infop)		\
+    do {				\
+    if( --(infop)->cm_lockcnt == 0 )	\
+	*(infop)->cm_unlockp = 0 ;	\
+    } while (0)
+
+
+#define CM_INFOP(clientp) ((Grabbedcmap *) ((clientp)->cm_info))
+
+Dga_cmap	wx_cm_grab() ;
+
+#endif /* _CMAP_GRAB_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/lib/libdga/sun-src/dga.h	Fri Nov 13 13:30:43 2009 -0800
@@ -0,0 +1,496 @@
+/* Copyright 1997 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ *
+ * 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, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * 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
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR 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.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+#pragma ident	"@(#)dga.h	35.14	09/11/09 SMI"
+
+/*
+ * dga.h - Sun Direct Graphics Access interface
+ */
+
+#ifndef _DGA_H
+#define _DGA_H
+
+#include <sys/types.h>
+#ifndef	SERVER_DGA
+#include "X11/Xlib.h"
+#endif /* SERVER_DGA */
+#include "dga_externaldefs.h"
+
+#if defined (_POSIX_C_SOURCE)
+#define u_int uint_t
+#endif
+
+#ifdef SERVER_DGA
+#define Display void
+#define Bool    int
+#endif  /* SERVER_DGA */
+
+#define	DGA_X_EOL		(-32767)
+#define	DGA_Y_EOL		(-32768)
+
+#define DGA_DB_DEV_INFO_SZ 	132
+
+#define DGA_RTN_NOT_CACHED      0
+#define DGA_RTN_SAME_DEV        1
+#define DGA_RTN_NEW_DEV         2
+
+#define DGA_CLIENT_VERSION	1
+
+typedef u_int Dga_token;
+
+typedef struct dga_curs_memimage {
+	u_int		width;
+	u_int		height;
+	u_int		depth;
+	u_int		linebytes;
+	void		*memptr;
+} Dga_curs_memimage;
+
+typedef struct dga_dbinfo {
+	short		number_buffers;
+	short		read_buffer;
+	short		write_buffer;
+	short		display_buffer;
+	u_int		reserved_1;	/* for future use */
+	u_int		reserved_2;	/* for future use */
+	u_int		reserved_3;	/* for the future  */
+	u_int		reserved_4;	/* for the future */
+	u_int		reserved_5;	/* for the future */
+	u_int		wid;		/* db window id. */
+	u_int		unique;
+	u_char		device_info[DGA_DB_DEV_INFO_SZ];
+} Dga_dbinfo;
+
+#ifndef DGA_NUM_BUFFER_TYPES
+/* The following buffer types also defined(duplicated) in 
+ * dga_winshared.h file.  * I can't include dga.h in hw/solaris/dga  
+ * due to some declarations inconsistency.
+ * Whenever someone changes/addes/deleted to this enumerated values, 
+ * please also update dga_winshared.h which is located
+ * in xc/include/dga/
+ */
+
+/* Known types of ancillary buffers */
+typedef enum {
+   DGA_DEPTH_BUFFER =0,
+   DGA_STENCIL_BUFFER,
+   DGA_ACCUM_BUFFER,
+   DGA_ALPHA_BUFFER,
+   DGA_BACK_BUFFER,
+   DGA_AUX_BUFFER0,
+   DGA_AUX_BUFFER1,
+   DGA_AUX_BUFFER2,
+   DGA_AUX_BUFFER3
+} Dga_buffer_type;
+ 
+#define DGA_NUM_BUFFER_TYPES (DGA_AUX_BUFFER3+1)
+#endif
+
+typedef void *Dga_buffer;
+
+typedef struct dga_widinfo {
+	short		number_wids;	/* number of contiguous wids alloc */
+	short		start_wid;	/* starting wid */
+	short		wid;		/* current wid */
+	short		reserved_1;	/* for the future */
+} Dga_widinfo;
+
+typedef void* Dga_window;
+typedef void* Dga_cmap;
+
+/* May be either a window, the main window of a multibuffer set, or a pixmap */
+typedef void* Dga_drawable;
+
+typedef struct dga_opaque {
+    int     loc_1;
+    u_int   loc_2;
+    u_int   *loc_3;
+    int	    loc_4;
+    u_int   *loc_5;
+    u_int   *loc_6;
+    int	    (*loc_7)(Dga_window);
+    int	    (*loc_8)(Dga_window);
+    int	    (*loc_9)(Dga_window);
+    int	    loc_10;
+} *Dga_opaque;
+
+typedef struct dga_opaque_draw {
+    int     loc_1;
+    u_int   loc_2;
+    u_int   *loc_3;
+    int	    loc_4;
+    u_int   *loc_5;
+    u_int   *loc_6;
+    int	    (*loc_7)(Dga_drawable);
+    int	    (*loc_8)(Dga_drawable);
+    int	    (*loc_9)(Dga_drawable);
+    int	    loc_10;
+    u_int   loc_11[DGA_MAX_GRABBABLE_BUFS + 1];
+    u_int   *loc_12;
+} *Dga_opaque_draw;
+
+/* Types for drawable notification functions */
+typedef void (*DgaSiteNotifyFunc)(Dga_drawable, short, void *, int);
+typedef void (*DgaMbNotifyFunc)(Dga_drawable, void *, int);
+typedef void (*DgaRendBufNotifyFunc)(Dga_drawable, short, void *);
+typedef void (*DgaCursTakeDownFunc)(void *, Dga_drawable, int, int, Dga_curs_memimage *);
+typedef void (*DgaOvlStateNotifyFunc)(Dga_drawable, void *, int);
+
+#define DGA_LOCK(x)	(*(((Dga_opaque)(x))->loc_5)) = 1
+#define DGA_UNLOCK(x)	(*(((Dga_opaque)(x))->loc_6)) = 0
+
+#define	DGA_WIN_LOCK(win)						\
+    do {								\
+    if ((((Dga_opaque)(win))->loc_4)++ == 0) {				\
+	DGA_LOCK(win);							\
+	((Dga_opaque)win)->loc_10 = (((((Dga_opaque)(win))->loc_2) ==	\
+	    (*(((Dga_opaque)(win))->loc_3))) ?				\
+	    0 : (*(((Dga_opaque)(win))->loc_9))(win));			\
+	}								\
+    } while (0)
+
+#define DGA_WIN_UNLOCK(win)			\
+    do {					\
+    if (--(((Dga_opaque)(win))->loc_4) == 0) { 	\
+	DGA_UNLOCK(win);			\
+	if (((Dga_opaque)(win))->loc_8)		\
+		(*(((Dga_opaque)(win))->loc_8))(win);		\
+	}					\
+    } while (0)
+
+#define	DGA_WIN_MODIF(win)	(((Dga_opaque)win)->loc_10)
+
+
+/* this is so we can we can enter the opaque interface */
+#define DGA_CASTDRAW(dgadraw) ((Dga_opaque_draw)(dgadraw))
+
+typedef int (*DgaDrawUpdateFunc)(Dga_drawable, short);
+#define DGA_CASTFUNC(func)    ((DgaDrawUpdateFunc)(func))
+
+
+#define	DGA_DRAW_LOCK(dgadraw, bufIndex)			              \
+{						                              \
+    if ((DGA_CASTDRAW(dgadraw)->loc_4)++ == 0) {			      \
+    DGA_LOCK(dgadraw);					        	      \
+    DGA_CASTDRAW(dgadraw)->loc_10 =                                           \
+	      (								      \
+	        ((DGA_CASTDRAW(dgadraw)->loc_11[bufIndex + 1]) ==             \
+					   (*(DGA_CASTDRAW(dgadraw)->loc_3))) \
+		    ? 0							      \
+	            : (*DGA_CASTFUNC(DGA_CASTDRAW(dgadraw)->loc_9))           \
+			 		          ((dgadraw), (bufIndex))     \
+	      );							      \
+    }							              \
+}
+
+#define DGA_DRAW_UNLOCK(dgadraw)					      \
+{									      \
+    if (--(DGA_CASTDRAW(dgadraw)->loc_4) == 0) { 			      \
+        DGA_UNLOCK(dgadraw);						      \
+        if (DGA_CASTDRAW(dgadraw)->loc_8)				      \
+	    (*(DGA_CASTDRAW(dgadraw)->loc_8))(dgadraw);			      \
+    }									      \
+}
+
+#define DGA_DRAW_LOCK_SRC_AND_DST(dgasrc, bufIndexSrc, dgadst, bufIndexDst)  \
+{									     \
+    /* Always lock pixmap first. */					     \
+    if ((DGA_CASTDRAW(dgasrc)->loc_1 == DGA_DRAW_WINDOW) &&	             \
+        (DGA_CASTDRAW(dgadst)->loc_1 == DGA_DRAW_PIXMAP)) {	             \
+        DGA_DRAW_LOCK(dgadst, bufIndexDst);				     \
+        DGA_DRAW_LOCK(dgasrc, bufIndexSrc);				     \
+    } else if ((DGA_CASTDRAW(dgasrc)->loc_1 == DGA_DRAW_PIXMAP) &&           \
+               (DGA_CASTDRAW(dgadst)->loc_1 == DGA_DRAW_WINDOW)) {           \
+        DGA_DRAW_LOCK(dgasrc, bufIndexSrc);				     \
+        DGA_DRAW_LOCK(dgadst, bufIndexDst);				     \
+    } else if ((DGA_CASTDRAW(dgasrc)->loc_1 == DGA_DRAW_PIXMAP) &&           \
+               (DGA_CASTDRAW(dgadst)->loc_1 == DGA_DRAW_PIXMAP)) {           \
+        /* We lock the src pixmap and since all pixmaps share the same       \
+         * lock page, the dst pixmap is locked as well. */		     \
+ 									     \
+        DGA_DRAW_LOCK(dgasrc, bufIndexSrc);				     \
+                							     \
+        /* Now update dest pixmap's modif */				     \
+ 									     \
+        DGA_CASTDRAW(dgadst)->loc_10 =					     \
+              (((DGA_CASTDRAW(dgadst)->loc_11[0]) ==   	                     \
+				 (*(DGA_CASTDRAW(dgadst)->loc_3)))           \
+                 ? 0 : (*DGA_CASTFUNC(DGA_CASTDRAW(dgadst)->loc_9))          \
+					       ((dgadst), (bufIndexDst)));   \
+    }									     \
+}
+ 
+#define DGA_DRAW_UNLOCK_SRC_AND_DST(dgasrc, dgadst)			     \
+{									     \
+    /* Always unlock window first */					     \
+    if ((DGA_CASTDRAW(dgasrc)->loc_1 == DGA_DRAW_WINDOW) &&	             \
+        (DGA_CASTDRAW(dgadst)->loc_1 == DGA_DRAW_PIXMAP)) {	             \
+        DGA_DRAW_UNLOCK(dgasrc);					     \
+        DGA_DRAW_UNLOCK(dgadst);					     \
+    } else if ((DGA_CASTDRAW(dgasrc)->loc_1 == DGA_DRAW_PIXMAP) &&           \
+               (DGA_CASTDRAW(dgadst)->loc_1 == DGA_DRAW_WINDOW)) {           \
+        DGA_DRAW_UNLOCK(dgadst);					     \
+        DGA_DRAW_UNLOCK(dgasrc);					     \
+    } else if ((DGA_CASTDRAW(dgasrc)->loc_1 == DGA_DRAW_PIXMAP) &&           \
+               (DGA_CASTDRAW(dgadst)->loc_1 == DGA_DRAW_PIXMAP)) {           \
+        /* Unlock the src pixmap */					     \
+        DGA_DRAW_UNLOCK(dgasrc);					     \
+    }									     \
+}	
+
+#define	DGA_DRAW_MODIF(dgadraw)	(((Dga_opaque_draw)(dgadraw))->loc_10)
+
+#define DGA_INIT()	dga_init_version(DGA_CLIENT_VERSION)
+
+
+#ifdef	__cplusplus
+extern "C" {
+#endif
+
+ /* General DGA functions */
+extern	void		dga_init_version(int);
+/*
+ *  X protocol extension functions
+ */
+extern	Dga_token	XDgaGrabWindow(Display*, Window);
+extern	int		XDgaUnGrabWindow(Display*, Window);
+extern	Dga_token	XDgaGrabColormap(Display*, Colormap);
+extern	int		XDgaUnGrabColormap(Display*, Colormap);
+extern	int		XDgaGrabWids(Display*, Window, int);
+extern	int		XDgaGrabFCS(Display*, Window, int);
+extern	int		XDgaGrabZbuf(Display*, Window, int);
+extern	int		XDgaGrabStereo(Display*, Window, int);
+/*
+ *  Window Compatibility Interface - Window grabber functions
+ */
+
+extern	Dga_window	dga_win_grab(int, Dga_token);
+extern	void		dga_win_ungrab(Dga_window, int);
+extern	char		*dga_win_fbname(Dga_window);
+extern	int		dga_win_devfd(Dga_window);
+extern	int		dga_win_clipchg(Dga_window);
+extern	int		dga_win_curschg(Dga_window);
+extern	int		dga_win_rtnchg(Dga_window);
+extern	short		*dga_win_clipinfo(Dga_window);
+extern	void		dga_win_bbox(Dga_window, int *, int *, int *, int *);
+extern	int		dga_win_singlerect(Dga_window);
+extern	int		dga_win_empty(Dga_window);
+extern	int		dga_win_obscured(Dga_window);
+extern	int		dga_win_cursactive(Dga_window);
+extern	void		dga_win_cursupdate(Dga_window, void(*)(void *,
+			    Dga_window, int, int, Dga_curs_memimage*), void *);
+extern	Dga_dbinfo	*dga_win_dbinfop(Dga_window);
+extern	Dga_widinfo	*dga_win_widinfop(Dga_window);
+extern  void		*dga_win_bboxinfop(Dga_window);
+extern u_char		dga_win_depth(Dga_window);
+extern u_short		dga_win_borderwidth(Dga_window);
+extern void		dga_win_set_client_infop(Dga_window, void *);
+extern void		*dga_win_get_client_infop(Dga_window);
+
+/*
+ *  Colormap grabber functions
+ */
+
+extern	Dga_cmap	dga_cm_grab(int, Dga_token);
+extern	void		dga_cm_ungrab(Dga_cmap, int);
+extern	void		dga_cm_read(Dga_cmap, int, int, u_char *, u_char *,
+					u_char *);
+extern	void		dga_cm_write(Dga_cmap, int, int, u_char *, u_char*,
+					u_char *, void (*)(Dga_window, int,
+					int, u_char *, u_char *, u_char *));
+extern int		dga_cm_devfd(Dga_cmap);
+extern void		dga_cm_set_client_infop(Dga_cmap, void *);
+extern void		*dga_cm_get_client_infop(Dga_cmap);
+extern void		*dga_cm_devinfop(Dga_cmap);
+
+/*
+ *  Window Compatibility Interface - double buffering functions
+ */
+
+extern	int		dga_db_grab(Dga_window, int, int (*)(Dga_window),
+			     u_int * );
+extern	int		dga_db_ungrab(Dga_window);
+extern	void		dga_db_write(Dga_window, int,
+			    int(*)(void*, Dga_window, int), void *);
+extern	void		dga_db_read(Dga_window,int,
+			    int(*)(void*, Dga_window, int), void *);
+extern	void		dga_db_display(Dga_window, int,
+			    int(*)(void*, Dga_window, int), void *);
+extern	void		dga_db_interval(Dga_window, int);
+extern	void		dga_db_interval_wait(Dga_window);
+extern	int		dga_db_interval_check(Dga_window);
+extern	int		dga_db_write_inquire(Dga_window);
+extern	int		dga_db_read_inquire(Dga_window);
+extern	int		dga_db_display_inquire(Dga_window);
+extern	int		dga_db_display_done(Dga_window, int, 
+			    int (*)(Dga_window));
+/*
+ *  Window Compatibility Interface - Retained window grabber functions
+ */
+
+extern	int		dga_rtn_grab(Dga_window);
+extern	int		dga_rtn_ungrab(Dga_window);
+extern	int		dga_rtn_active(Dga_window);
+extern	int		dga_rtn_cached(Dga_window);
+extern	void		*dga_rtn_devinfo(Dga_window);
+extern	void		dga_rtn_devtype(Dga_window, u_char *, char **);
+extern	void		dga_rtn_dimensions(Dga_window, short *, short *,
+			    u_int*);
+extern	void		*dga_rtn_pixels(Dga_window);
+
+/*
+ *  Drawable grabber functions
+ */
+
+extern Dga_drawable	XDgaGrabDrawable(Display *dpy, Drawable drawid);
+extern int 		XDgaUnGrabDrawable(Dga_drawable dgadraw);
+extern Display *	dga_draw_display (Dga_drawable dgadraw);
+extern Drawable 	dga_draw_id(Dga_drawable);
+extern int		dga_draw_type (Dga_drawable dgadraw);
+extern char *		dga_draw_devname (Dga_drawable dgadraw);
+extern int		dga_draw_devfd (Dga_drawable dgadraw);
+extern int		dga_draw_depth (Dga_drawable dgadraw);
+extern void		dga_draw_set_client_infop (Dga_drawable dgadraw, void *client_info_ptr);
+extern void *		dga_draw_get_client_infop (Dga_drawable dgadraw);
+extern void *		dga_draw_devinfo (Dga_drawable dgadraw);
+extern int		dga_draw_sitechg (Dga_drawable dgadraw, int *reason);
+extern void		dga_draw_sitesetnotify (Dga_drawable dgadraw, 
+						    DgaSiteNotifyFunc site_notify_func,
+						    void *client_data);
+extern void		dga_draw_sitegetnotify (Dga_drawable dgadraw, 
+						    DgaSiteNotifyFunc *site_notify_func,
+						    void **client_data);
+extern int		dga_draw_site (Dga_drawable dgadraw);
+extern void *		dga_draw_address (Dga_drawable dgadraw);
+extern int		dga_draw_linebytes (Dga_drawable dgadraw);
+extern int		dga_draw_clipchg (Dga_drawable dgadraw);
+extern void		dga_draw_bbox(Dga_drawable dgadraw, int *xp, int *yp, 
+					  int *widthp, int *heightp);
+extern int		dga_draw_visibility (Dga_drawable dgadraw);
+extern int		dga_draw_empty (Dga_drawable dgadraw);
+extern short *		dga_draw_clipinfo (Dga_drawable dgadraw);
+extern int		dga_draw_singlerect (Dga_drawable dgadraw);
+extern int		dga_draw_obscured (Dga_drawable dgadraw);
+extern u_short		dga_draw_borderwidth (Dga_drawable dgadraw);
+extern void		dga_draw_curshandle (Dga_drawable dgadraw, 
+					     DgaCursTakeDownFunc take_down_func,
+					     void *client_data);
+extern int		dga_draw_rtngrab (Dga_drawable dgadraw);
+extern int		dga_draw_rtnungrab (Dga_drawable dgadraw);
+extern int		dga_draw_rtnchg (Dga_drawable dgadraw);
+extern int		dga_draw_rtnactive (Dga_drawable dgadraw);
+extern int		dga_draw_rtncached (Dga_drawable dgadraw);
+extern void *		dga_draw_rtndevinfop (Dga_drawable dgadraw);
+extern void		dga_draw_rtndevtype (Dga_drawable dgadraw, u_char *type, 
+					     char **name);
+extern void		dga_draw_rtndimensions (Dga_drawable dgadraw, short *width, 
+						short *height, u_int *linebytes);
+extern void *		dga_draw_rtnpixels (Dga_drawable dgadraw);
+extern int		dga_draw_mbchg (Dga_drawable dgadraw, int *reason);
+extern void		dga_draw_mbsetnotify (Dga_drawable dgadraw, DgaMbNotifyFunc mb_notify_func,
+						  void *client_data);
+extern void		dga_draw_mbgetnotify (Dga_drawable dgadraw, DgaMbNotifyFunc *mb_notify_func,
+						  void **client_data);
+extern int		dga_draw_mbaccessmode (Dga_drawable dgadraw);
+extern int		dga_draw_mbsitetypeconst (Dga_drawable dgadraw);
+extern void		dga_draw_mbsetrendbufnotify (Dga_drawable dgadraw, 
+							 DgaRendBufNotifyFunc rb_notify_func,
+							 void *client_data);
+extern void		dga_draw_mbgetrendbufnotify (Dga_drawable dgadraw, 
+							 DgaRendBufNotifyFunc *rb_notify_func,
+							 void **client_data);
+extern int		dga_draw_ovlstatechg (Dga_drawable dgadraw);
+extern int		dga_draw_ovlstate (Dga_drawable dgadraw);
+extern void		dga_draw_ovlstatesetnotify (Dga_drawable dgadraw, 
+						    DgaOvlStateNotifyFunc ovlstate_notify_func,
+						    void *client_data);
+extern void		dga_draw_ovlstategetnotify (Dga_drawable dgadraw, 
+						    DgaOvlStateNotifyFunc *ovlstate_notify_func,
+						    void **client_data);
+
+
+/*
+ *  Drawable grabber functions - Buffer Control Compatibility
+ */
+
+extern int		dga_draw_db_grab (Dga_drawable dgadraw, int nbuffers, 
+			  int (*vrtfunc)(Dga_drawable), u_int *vrtcounterp);
+extern int		dga_draw_db_ungrab (Dga_drawable dgadraw);
+extern void		dga_draw_db_write (Dga_drawable dgadraw, int buffer,
+			   int (*writefunc)(void*, Dga_drawable, int), 
+			   void *data);
+extern void		dga_draw_db_read (Dga_drawable dgadraw, int buffer,
+			  int (*readfunc)(void*, Dga_drawable, int), 
+			  void *data);
+extern void		dga_draw_db_display (Dga_drawable dgadraw, int buffer,
+			  int (*visfunc)(void*, Dga_drawable, int), 
+			  void *data);
+extern void		dga_draw_db_interval (Dga_drawable dgadraw, int interval);
+extern void		dga_draw_db_interval_wait (Dga_drawable dgadraw);
+extern int		dga_draw_db_interval_check (Dga_drawable dgadraw);
+extern int		dga_draw_db_write_inquire (Dga_drawable dgadraw);
+extern int		dga_draw_db_read_inquire (Dga_drawable dgadraw);
+extern int		dga_draw_db_display_inquire (Dga_drawable dgadraw);
+extern int		dga_draw_db_display_done (Dga_drawable dgadraw, int flag, 
+			  int (*display_done_func)(Dga_drawable));
+extern Dga_dbinfo 	*dga_draw_db_dbinfop (Dga_drawable dgadraw);
+extern int		dga_draw_devinfochg(Dga_drawable dgadraw);
+
+/*
+ *  Misc. grabber functions
+ */
+
+extern	int		XDgaDrawGrabWids(Display*, Drawable, int);
+extern	Dga_widinfo	*dga_draw_widinfop(Dga_drawable);
+extern	int		XDgaDrawGrabFCS(Display*, Drawable, int);
+extern	int		XDgaDrawGrabZbuf(Display*, Drawable, int);
+extern	int		XDgaDrawGrabStereo(Display*, Drawable, int);
+
+/*
+ *  Window Compatibility Interface - Ancillary buffers functions
+ *  New feature for 2.6
+ */
+
+extern Dga_buffer      dga_draw_grab_buffer(Dga_drawable, 
+                                            Dga_buffer_type, int);
+extern int             dga_draw_ungrab_buffer(Dga_drawable, Dga_buffer_type);
+extern int             dga_draw_get_buffers(Dga_drawable, Dga_buffer **);
+extern Dga_buffer_type dga_buffer_type(Dga_buffer);
+extern int             dga_buffer_site(Dga_buffer);
+extern int             dga_draw_bufferchg(Dga_drawable);
+extern int             dga_buffer_sitechg(Dga_buffer, int *);
+extern void*           dga_buffer_address(Dga_buffer);
+extern int             dga_buffer_linebytes(Dga_buffer);
+extern int             dga_buffer_bitsperpixel(Dga_buffer);
+
+#ifdef	__cplusplus
+}
+#endif
+
+#endif /* _DGA_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/lib/libdga/sun-src/dga_Xrequests.c	Fri Nov 13 13:30:43 2009 -0800
@@ -0,0 +1,1592 @@
+/* Copyright 2001 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ *
+ * 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, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * 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
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR 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.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+#pragma ident	"@(#)dga_Xrequests.c	35.19	09/11/09 SMI"
+ 
+/* 
+ * dga_Xrequests.c - the client side code for DGA X11 requests
+ */
+
+/*
+ *-----------------------------------------------------------------------
+ * 
+ * This code uses the standard extension mechanism for sending
+ * SUN_DGA private extension requests.
+ *
+ *-----------------------------------------------------------------------
+ */
+
+#define	NEED_REPLIES
+#define NEED_EVENTS
+
+#ifdef SERVER_DGA
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include "resource.h"
+#include "dixstruct.h"
+#include <stdio.h>
+#include "pixmapstr.h"
+#else
+
+#include <X11/Xlibint.h>
+#include <sys/resource.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <sys/un.h>
+#include <netdb.h>
+
+#ifdef SVR4
+#include <sys/utsname.h>
+#endif
+#endif /* SERVER_DGA */
+
+
+#include "dga.h"
+#include "dga_Xrequests.h"
+#include "dga_incls.h"
+
+#include "XineramaInfo.h"
+
+#ifdef SERVER_DGA
+#define NEW             1     /* Flag for SHAPES to use new window grabber */
+#define BadCookie 0
+#endif
+
+#define X_DGA 0 /* a hack, so GetReq and GetResReq work below */
+
+#ifndef	MIN
+#define	MIN(i,j)	((i)<(j)?(i):(j))
+#endif
+
+static struct dga_extinfo **dga_extinfo_table = 0; /* No table to start with */
+static int dga_extinfo_table_size = 0;
+
+static int terminate_dga_ext();
+static int islocalhost();
+static int dga_winlist_add();
+static int dga_winlist_free();
+       void * _dga_is_X_window();
+       int dga_pixlist_add();
+static int dga_pixlist_free();
+       void *_dga_is_X_pixmap();
+  
+extern void dgai_win_ungrab_common();
+extern int _thr_main();
+
+#ifdef SVR4
+
+#ifdef MT
+mutex_t	dgaGlobalMutex;
+mutex_t	dgaGlobalPixmapMutex;
+int	dgaThreaded;	/* 1 == linked with libthread, else 0 */
+int	dgaMTOn;	/* 1 == MT per-drawable locking is turned on, else 0 */
+#endif
+int	_dga_client_version = -1;
+
+void
+dga_init_version(ver)
+int ver;
+{
+if (ver > -1)
+	_dga_client_version = ver;
+#ifdef MT
+dgaThreaded = (_thr_main() != -1) ? 1 : 0;
+	dgaMTOn = 0;
+	mutex_init(&dgaGlobalMutex, USYNC_THREAD, NULL);
+	mutex_init(&dgaGlobalPixmapMutex, USYNC_THREAD, NULL);
+#endif
+}
+
+#endif
+
+#ifndef SERVER_DGA
+static struct dga_extinfo *
+init_dga_ext(dpy)
+Display *dpy;
+{
+	int			protmajor, protminor;
+	XExtCodes		*xecp;
+	struct dga_extinfo	*infop;
+
+#ifdef SVR4
+	if (_dga_client_version < 0)
+		return 0;
+#endif
+	if (dga_extinfo_table_size < (dpy->fd + 1)) {
+
+		/* We've got to allocate or grow the table */
+		struct rlimit		rl;
+		int			size;
+		struct dga_extinfo	**tblptr;
+
+		size = (getrlimit(RLIMIT_NOFILE, &rl) < 0) ?
+		    dga_extinfo_table_size : rl.rlim_cur;
+		if (size < (dpy->fd + 1))
+			return 0;
+		tblptr = (struct dga_extinfo **) ((dga_extinfo_table_size) ?
+		    realloc(dga_extinfo_table, sizeof(struct dga_extinfo *) *
+			size) :
+		    malloc(sizeof(struct dga_extinfo *) * size));
+		if (tblptr == NULL)
+			return 0;
+		dga_extinfo_table = tblptr;
+		memset((char *) &dga_extinfo_table[dga_extinfo_table_size],
+		    (int)'\0',
+		    sizeof(struct dga_extinfo *) *
+			(size - dga_extinfo_table_size));
+		dga_extinfo_table_size = size;
+		}
+
+	if (dga_extinfo_table[dpy->fd] != NULL)
+		return dga_extinfo_table[dpy->fd];
+
+	if (!islocalhost(dpy))
+		return 0;
+
+	if ((xecp = XInitExtension(dpy, "SUN_DGA")) != NULL) {
+		if (XDgaQueryVersion(dpy, &protmajor, &protminor) == 0) {
+			protmajor = 3;
+/*			protminor = 0; let minor number pass through */
+			}
+		}
+	else if ((xecp = XInitExtension(dpy, "SunWindowGrabber")) != NULL) {
+		if (strcmp(ServerVendor(dpy),
+		    "X11/NeWS - Sun Microsystems Inc.") == 0) {
+			if (VendorRelease(dpy) >= 3000) {
+				protmajor = 2;
+				protminor = 0;
+				}
+			else if (VendorRelease(dpy) >= 2000) {
+				protmajor = 1;
+				protminor = 0;
+				}
+			}
+		else
+			return 0;
+		}
+	else
+		return 0;
+
+	if ((infop = (struct dga_extinfo *)
+	    malloc(sizeof(struct dga_extinfo))) == NULL)
+		return 0;
+
+	infop->protocol_major_version = protmajor;
+	infop->protocol_minor_version = protminor;
+	infop->extension = xecp->extension;
+	infop->major_opcode = xecp->major_opcode;
+	dga_extinfo_table[dpy->fd] = infop;
+	XESetCloseDisplay(dpy, infop->extension, terminate_dga_ext);
+	return infop;
+}
+
+static int
+islocalhost(dpy)
+Display *dpy;
+{
+        char    hostname[256];
+	char	*colon;
+	unsigned int	namelen;
+	size_t	hostlen, phostlen;
+#ifdef IPv6
+        struct addrinfo *localhostaddr;
+        struct addrinfo *otherhostaddr;
+        struct addrinfo *i, *j;
+        int equiv = 0;
+	char host[NI_MAXHOST];
+#else
+	struct hostent *phost;
+	struct hostent *h;
+#endif
+	union genericaddr {
+		struct sockaddr	generic;
+		struct sockaddr_in	internet;
+#ifdef IPv6
+		struct sockaddr_in6	internetv6;
+ 	        struct sockaddr_storage maximumsize;
+#endif
+		struct sockaddr_un	nuxi;
+  		} addr;
+  
+	if (dpy->display_name[0] == ':')
+		return 1;
+#ifdef SVR4
+	colon = strrchr(dpy->display_name, ':');
+#else
+	colon = rindex(dpy->display_name, ':');
+#endif
+	phostlen = strlen(dpy->display_name) - (colon ? strlen(colon) : 0);
+	if((strncmp("unix", dpy->display_name, MIN(phostlen, 4)) == 0) ||
+	    (strncmp("localhost", dpy->display_name, MIN(phostlen, 9)) == 0))
+		return 1;
+
+	/* We're not a unix domain connection so what are we? */
+
+	namelen = sizeof addr;
+	memset((char *) &addr, (int)'\0', sizeof addr);
+	if(getpeername(dpy->fd, (struct sockaddr *) &addr,
+	    &namelen) < 0)
+		return 0;
+
+	hostlen = _X11TransGetHostname(hostname, sizeof(hostname));
+      
+#ifdef IPv6
+        if (getaddrinfo(hostname, NULL, NULL, &localhostaddr) != 0)
+            return 0;
+	if (getnameinfo(&addr.generic, namelen, host, sizeof(host),
+	  NULL, 0, 0) != 0) {
+	    freeaddrinfo(localhostaddr);
+	    return 0;
+	}
+        if (getaddrinfo(host, NULL, NULL, &otherhostaddr) != 0) {
+            freeaddrinfo(localhostaddr);
+            return 0;
+        }
+
+        for (i = localhostaddr; i != NULL && equiv == 0; i = i->ai_next) {
+            for (j = otherhostaddr; j != NULL && equiv == 0; j = j->ai_next) {
+                if (i->ai_family == j->ai_family) {
+                    if (i->ai_family == AF_INET) {
+                        struct sockaddr_in *sinA 
+                          = (struct sockaddr_in *) i->ai_addr;
+                        struct sockaddr_in *sinB
+                          = (struct sockaddr_in *) j->ai_addr;
+                        struct in_addr *A = &sinA->sin_addr;
+                        struct in_addr *B = &sinB->sin_addr;
+
+                        if (memcmp(A,B,sizeof(struct in_addr)) == 0) {
+                            equiv = 1;
+                        }
+                    } else if (i->ai_family == AF_INET6) {
+                        struct sockaddr_in6 *sinA 
+                          = (struct sockaddr_in6 *) i->ai_addr;
+                        struct sockaddr_in6 *sinB 
+                          = (struct sockaddr_in6 *) j->ai_addr;
+                        struct in6_addr *A = &sinA->sin6_addr;
+                        struct in6_addr *B = &sinB->sin6_addr;
+
+                        if (memcmp(A,B,sizeof(struct in6_addr)) == 0) {
+                            equiv = 1;
+                        }
+                    }
+                }
+            }
+        }
+        
+        freeaddrinfo(localhostaddr);
+        freeaddrinfo(otherhostaddr);
+        return equiv;
+#else
+        if ((addr.generic.sa_family !=  AF_INET) ||
+            ((h  =  gethostbyaddr((char *)&addr.internet.sin_addr,
+            sizeof addr.internet.sin_addr,
+            addr.internet.sin_family)) == 0))
+                return 0;
+
+        /* Find real host name on TCPIP */
+        phost = gethostbyname(h->h_name);
+        phostlen = strlen(phost->h_name);
+
+	if (strncmp(hostname, phost->h_name, MIN(phostlen, hostlen)))
+		return 0;
+
+	return 1;
+#endif
+
+}
+
+static struct dga_extinfo *
+lookup_dga_ext(dpy)
+Display *dpy;
+{
+	if (dga_extinfo_table_size < (dpy->fd + 1))
+		return 0;
+	return dga_extinfo_table[dpy->fd];
+}
+
+static int
+terminate_dga_ext(dpy, codes)
+Display		*dpy;
+XExtCodes	*codes;
+{ 
+	free(dga_extinfo_table[dpy->fd]);
+	dga_extinfo_table[dpy->fd] = NULL;
+	dga_winlist_free(dpy, NULL);
+	/* TODO: free pixmaps as well? */
+	return(1);
+}
+#endif /* SERVER_DGA */
+
+Dga_token 
+XDgaGrabWindow(dpy, win)
+Display		*dpy;
+Window		win;
+{
+#ifdef SERVER_DGA
+    int val;
+    WindowPtr pWin = (WindowPtr)LookupIDByType(win, RT_WINDOW);
+    if (!pWin) 
+        return (BadCookie);
+
+    if (((DrawablePtr)pWin)->type == DRAWABLE_PIXMAP) 
+        return (BadCookie);
+    val = DgaWgGrab(pWin, NEW);
+
+    if (val) {
+        if (dga_winlist_add(val, dpy, win) == 0) {
+            XDgaUnGrabWindow(dpy, win);
+            return 0;
+        }
+    }
+    return val;
+#else
+	xResourceReq		*req;
+	xGenericReply		rep;
+	struct dga_extinfo	*extinfop;
+
+	if ((extinfop = init_dga_ext(dpy)) == NULL)
+		return 0;
+	LockDisplay(dpy);
+	GetResReq(DGA, win, req);
+	req->reqType = extinfop->major_opcode;
+	req->pad = (extinfop->protocol_major_version >= 2) ?
+	    X_DgaGrabWindow : X_DgaGrabWindow_Old ;
+	if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) {
+		UnlockDisplay(dpy);
+		SyncHandle();
+		return 0;
+		}
+	UnlockDisplay(dpy);
+	SyncHandle();
+	if (rep.data00) {
+		if (dga_winlist_add(rep.data00, dpy, win) == 0) {
+			XDgaUnGrabWindow(dpy, win);
+			return 0;
+			}
+		}
+	return rep.data00;
+#endif /* SERVER_DGA */
+}
+
+int
+XDgaUnGrabWindow(dpy, win)
+Display *dpy;
+Window win;
+{
+#ifdef SERVER_DGA
+    WindowPtr pWin = (WindowPtr)LookupIDByType(win, RT_WINDOW);
+    int val;
+
+    if (!pWin) 
+        return (BadCookie);
+    if (((DrawablePtr)pWin)->type == DRAWABLE_PIXMAP) 
+        return (BadCookie);
+    val = DgaWgUngrab(pWin, NEW);
+
+    if (val) {
+        if (dga_winlist_free(dpy, win) == 0)
+            return 0;
+    }
+    return val;
+#else
+	xResourceReq		*req;
+	xGenericReply		rep;
+	struct dga_extinfo      *extinfop;
+
+	if ((extinfop = lookup_dga_ext(dpy)) == NULL)
+		return 0;
+	LockDisplay(dpy);
+	GetResReq(DGA, win, req);
+	req->reqType = extinfop->major_opcode;
+	req->pad = (extinfop->protocol_major_version >= 2) ?
+	    X_DgaUnGrabWindow : X_DgaUnGrabWindow_Old;
+	if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) {
+		UnlockDisplay(dpy);
+		SyncHandle();
+		return 0;
+		}
+	UnlockDisplay(dpy);
+	SyncHandle();
+	if (rep.data00) {
+		if (dga_winlist_free(dpy, win) == 0)
+			return 0;
+		}
+	return rep.data00;		/* Status */
+#endif /* SERVER_DGA */
+}
+
+
+#ifndef SERVER_DGA
+Dga_token 
+XDgaGrabColormap(dpy, cmap)
+Display		*dpy;
+Colormap	cmap;
+{
+	xResourceReq	*req;
+	xGenericReply		rep;
+	struct dga_extinfo	*extinfop;
+
+#ifdef MT
+	mutex_lock(&dgaGlobalMutex);
+#endif
+	if ((extinfop = init_dga_ext(dpy)) == NULL) {
+#ifdef MT
+		mutex_unlock(&dgaGlobalMutex);
+#endif
+		return 0;
+	}
+	LockDisplay(dpy);
+	GetResReq(DGA, cmap, req);
+	req->reqType = extinfop->major_opcode;
+	req->pad = (extinfop->protocol_major_version >= 3) ?
+	    X_DgaGrabColormap : X_DgaGrabColormap_Old;
+	if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) {
+		UnlockDisplay(dpy);
+		SyncHandle();
+#ifdef MT
+		mutex_unlock(&dgaGlobalMutex);
+#endif
+		return 0;
+		}
+	UnlockDisplay(dpy);
+	SyncHandle();
+#ifdef MT
+	mutex_unlock(&dgaGlobalMutex);
+#endif
+	return rep.data00;
+}
+
+int
+XDgaUnGrabColormap(dpy, cmap)
+Display		*dpy;
+Colormap	cmap;
+{
+	xResourceReq *req;
+	xGenericReply rep;
+	struct dga_extinfo	*extinfop;
+
+#ifdef MT
+	mutex_lock(&dgaGlobalMutex);
+#endif
+	if ((extinfop = lookup_dga_ext(dpy)) == NULL) {
+#ifdef MT
+		mutex_unlock(&dgaGlobalMutex);
+#endif
+		return 0;
+	}
+	LockDisplay(dpy);
+	GetResReq(DGA, cmap, req);
+	req->reqType = extinfop->major_opcode;
+	req->pad = (extinfop->protocol_major_version >= 3) ?
+	    X_DgaUnGrabColormap : X_DgaUnGrabColormap_Old;
+	if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) {
+		UnlockDisplay(dpy);
+		SyncHandle();
+#ifdef MT
+		mutex_unlock(&dgaGlobalMutex);
+#endif
+		return 0;
+		}
+	UnlockDisplay(dpy);
+	SyncHandle();
+#ifdef MT
+	mutex_unlock(&dgaGlobalMutex);
+#endif
+	return rep.data00;		/* Status */
+}
+#endif /* SERVER_DGA */
+
+int 
+XDgaDrawGrabWids(dpy, drawid, nwids)
+Display		*dpy;
+Drawable 	drawid;
+int			nwids;
+{
+#ifdef SERVER_DGA
+    WindowPtr pWin = (WindowPtr)LookupIDByType(drawid, RT_WINDOW);
+
+    if (!pWin) 
+        return (BadCookie);
+    if (((DrawablePtr)pWin)->type == DRAWABLE_PIXMAP) 
+        return (BadCookie);
+    return(DgaWidGrab(pWin, nwids));
+#else
+	xDGAReq			*req;
+	xGenericReply		rep;
+	struct dga_extinfo	*extinfop;
+
+#ifdef MT
+	mutex_lock(&dgaGlobalMutex);
+#endif
+	if (((extinfop = lookup_dga_ext(dpy)) == NULL) ||
+	    (extinfop->protocol_major_version < 2)) {
+#ifdef MT
+		mutex_unlock(&dgaGlobalMutex);
+#endif
+		return 0;
+	}
+	LockDisplay(dpy);
+	GetReq(DGA, req);
+	req->reqType = extinfop->major_opcode;
+	req->pad = X_DgaGrabWids;
+	req->id = drawid;
+	req->number_objects = nwids;
+	if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) {
+		UnlockDisplay(dpy);
+		SyncHandle();
+#ifdef MT
+		mutex_unlock(&dgaGlobalMutex);
+#endif
+		return 0;
+		}
+	UnlockDisplay(dpy);
+	SyncHandle();
+#ifdef MT
+	mutex_unlock(&dgaGlobalMutex);
+#endif
+	return rep.data00;
+#endif /* SERVER_DGA */
+}
+
+int 
+XDgaGrabWids(dpy, win, nwids)
+Display	*dpy;
+Window 	win;
+int			nwids;
+{
+    return (XDgaDrawGrabWids(dpy, (Drawable)win, nwids));
+}
+
+int 
+XDgaDrawGrabFCS(dpy, drawid, nfcs)
+Display		*dpy;
+Drawable	drawid;
+int			nfcs;
+{
+#ifdef SERVER_DGA
+    WindowPtr pWin = (WindowPtr)LookupIDByType(drawid, RT_WINDOW);
+
+    if (!pWin) 
+        return (BadCookie);
+    if (((DrawablePtr)pWin)->type == DRAWABLE_PIXMAP) 
+        return (BadCookie);
+    /* When OWGX supports PIXMAPS, can be reomoved */
+    return(DgaFcsGrab(pWin, nfcs));
+#else
+	xDGAReq			*req;
+	xGenericReply		rep;
+	struct dga_extinfo	*extinfop;
+
+#ifdef MT
+	mutex_lock(&dgaGlobalMutex);
+#endif
+	if (((extinfop = lookup_dga_ext(dpy)) == NULL) ||
+	    (extinfop->protocol_major_version < 2)) {
+#ifdef MT
+		mutex_unlock(&dgaGlobalMutex);
+#endif
+		return 0;
+	}
+	LockDisplay(dpy);
+	GetReq(DGA, req);
+	req->reqType = extinfop->major_opcode;
+	req->pad = X_DgaGrabFCS;
+	req->id = drawid;
+	req->number_objects = nfcs;
+	if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) {
+		UnlockDisplay(dpy);
+		SyncHandle();
+#ifdef MT
+		mutex_unlock(&dgaGlobalMutex);
+#endif
+		return 0;
+		}
+	UnlockDisplay(dpy);
+	SyncHandle();
+#ifdef MT
+	mutex_unlock(&dgaGlobalMutex);
+#endif
+	return(rep.data00);
+#endif /* SERVER_DGA */
+}
+
+int 
+XDgaGrabFCS(dpy, win, nfcs)
+Display		*dpy;
+Window		win;
+int			nfcs;
+{
+    return (XDgaDrawGrabFCS(dpy, (Drawable)win, nfcs));
+}
+
+int 
+XDgaDrawGrabZbuf(dpy, drawid, nzbuftype)
+Display		*dpy;
+Drawable	drawid;
+int			nzbuftype;
+{
+#ifdef SERVER_DGA
+    WindowPtr pWin = (WindowPtr)LookupIDByType(drawid, RT_WINDOW);
+
+    if (!pWin) 
+        return (BadCookie);
+    if (((DrawablePtr)pWin)->type == DRAWABLE_PIXMAP) 
+        return (BadCookie);
+    return(DgaZbufGrab(pWin, nzbuftype));
+#else
+	xDGAReq *req;
+	xGenericReply rep;
+	struct dga_extinfo	*extinfop;
+
+#ifdef MT
+	mutex_lock(&dgaGlobalMutex);
+#endif
+	if (((extinfop = lookup_dga_ext(dpy)) == NULL) ||
+	    (extinfop->protocol_major_version < 2)) {
+#ifdef MT
+		mutex_unlock(&dgaGlobalMutex);
+#endif
+		return 0;
+	}
+	LockDisplay(dpy);
+	GetReq(DGA, req);
+	req->reqType = extinfop->major_opcode;
+	req->pad = X_DgaGrabZbuf;
+	req->id = drawid;
+	req->number_objects = nzbuftype;
+	if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) {
+		UnlockDisplay(dpy);
+		SyncHandle();
+#ifdef MT
+		mutex_unlock(&dgaGlobalMutex);
+#endif
+		return 0;
+		}
+	UnlockDisplay(dpy);
+	SyncHandle();
+#ifdef MT
+	mutex_unlock(&dgaGlobalMutex);
+#endif
+	return(rep.data00);
+#endif /* SERVER_DGA */
+}
+
+int 
+XDgaGrabZbuf(dpy, win, nzbuftype)
+Display		*dpy;
+Window		win;
+int			nzbuftype;
+{
+    return (XDgaDrawGrabZbuf(dpy, (Drawable)win, nzbuftype));
+}
+
+int 
+XDgaDrawGrabStereo(dpy, drawid, st_mode)
+Display		*dpy;
+Drawable	drawid;
+int			st_mode;
+{
+#ifdef SERVER_DGA
+    WindowPtr pWin = (WindowPtr)LookupIDByType(drawid, RT_WINDOW);
+ 
+    if (!pWin) 
+        return (BadCookie);
+    if (((DrawablePtr)pWin)->type == DRAWABLE_PIXMAP) 
+        return (BadCookie);
+    return(DgaStereoGrab(pWin, st_mode));
+#else
+	xDGAReq			*req;
+	xGenericReply		rep;
+	struct dga_extinfo	*extinfop;
+
+#ifdef MT
+	mutex_lock(&dgaGlobalMutex);
+#endif
+	if (((extinfop = lookup_dga_ext(dpy)) == NULL) ||
+	    (extinfop->protocol_major_version < 2)) {
+#ifdef MT
+		mutex_unlock(&dgaGlobalMutex);
+#endif
+		return 0;
+	}
+	LockDisplay(dpy);
+	GetReq(DGA, req);
+	req->reqType = extinfop->major_opcode;
+	req->pad = X_DgaGrabStereo;
+	req->id = drawid;
+	req->number_objects = st_mode;
+	if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) {
+		UnlockDisplay(dpy);
+		SyncHandle();
+#ifdef MT
+		mutex_unlock(&dgaGlobalMutex);
+#endif
+		return 0;
+		}
+	UnlockDisplay(dpy);
+	SyncHandle();
+#ifdef MT
+	mutex_unlock(&dgaGlobalMutex);
+#endif
+	return rep.data00;
+#endif /* SERVER_DGA */
+}
+
+int 
+XDgaGrabStereo(dpy, win, st_mode)
+Display		*dpy;
+Window		win;
+int			st_mode;
+{
+    return (XDgaDrawGrabStereo(dpy, (Drawable)win, st_mode));
+}
+
+int
+XDgaGrabABuffers(dpy, win, type, buffer_site)
+Display        *dpy;
+Window         win;
+int                     type;
+int                     buffer_site;
+{
+#ifdef SERVER_DGA
+    WindowPtr pWin = (WindowPtr)LookupIDByType(win, RT_WINDOW);
+ 
+    if (!pWin)
+        return (BadCookie);
+    if (((DrawablePtr)pWin)->type == DRAWABLE_PIXMAP)
+        return (BadCookie);
+    /* Some surf prep may be needed for mpg */
+    return(DgaABuffersGrabInfo((DrawablePtr)pWin, type, buffer_site));
+#else
+        xDgaGrabABuffersReq    *req;
+        xGenericReply           rep;
+        struct dga_extinfo      *extinfop;
+ 
+        if ((extinfop = lookup_dga_ext(dpy)) == NULL)
+                return 0;
+        if (extinfop->protocol_major_version < 2)
+                return 0;
+        LockDisplay(dpy);
+        GetReq(DgaGrabABuffers, req);
+        req->reqType = extinfop->major_opcode;
+        req->pad = X_DgaGrabABuffers;
+        req->id = win;
+        req->type = type;
+        req->buffer_site = buffer_site;
+        if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) {
+                UnlockDisplay(dpy);
+                SyncHandle();
+                return 0;
+                }
+        UnlockDisplay(dpy);
+        SyncHandle();
+        return rep.data00;
+#endif /* SERVER_DGA */
+}
+
+int
+XDgaUnGrabABuffers(dpy, win, type)
+Display        *dpy;
+Window         win;
+int                     type;
+{
+#ifdef SERVER_DGA
+    WindowPtr pWin = (WindowPtr)LookupIDByType(win, RT_WINDOW);
+ 
+    if (!pWin)
+        return (BadCookie);
+    if (((DrawablePtr)pWin)->type == DRAWABLE_PIXMAP)
+        return (BadCookie);
+    return(DgaABuffersUngrabInfo((DrawablePtr)pWin, type));
+#else
+        xDgaGrabABuffersReq    *req;
+        xGenericReply           rep;
+        struct dga_extinfo      *extinfop;
+ 
+        if ((extinfop = lookup_dga_ext(dpy)) == NULL)
+                return 0;
+        if (extinfop->protocol_major_version < 2)
+                return 0;
+        LockDisplay(dpy);
+        GetReq(DgaGrabABuffers, req);
+        req->reqType = extinfop->major_opcode;
+        req->pad = X_DgaUnGrabABuffers;
+        req->id = win;
+        req->type = type;
+        req->buffer_site = 0;
+        if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) {
+                UnlockDisplay(dpy);
+                SyncHandle();
+                return 0;
+                }
+        UnlockDisplay(dpy);
+        SyncHandle();
+        return rep.data00;
+#endif /* SERVER_DGA */
+}
+
+int 
+XDgaGrabBuffers(dpy, win, nbuffers)
+Display		*dpy;
+Window		win;
+int			nbuffers;
+{
+#ifdef SERVER_DGA
+    WindowPtr pWin = (WindowPtr)LookupIDByType(win, RT_WINDOW);
+ 
+    if (!pWin) 
+        return (BadCookie);
+    if (((DrawablePtr)pWin)->type == DRAWABLE_PIXMAP) 
+        return (BadCookie);
+    /* Some surf prep may be needed for mpg */
+    return(DgaBufGrab(pWin, nbuffers));
+#else
+	xDGAReq	*req;
+	xGenericReply		rep;
+	struct dga_extinfo	*extinfop;
+
+	if ((extinfop = lookup_dga_ext(dpy)) == NULL)
+		return 0;
+	if (extinfop->protocol_major_version < 2)
+		return 0;
+	LockDisplay(dpy);
+	GetReq(DGA, req);
+	req->reqType = extinfop->major_opcode;
+	req->pad = X_DgaGrabBuffers;
+	req->id = win;
+	req->number_objects = nbuffers;
+	if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) {
+		UnlockDisplay(dpy);
+		SyncHandle();
+		return 0;
+		}
+	UnlockDisplay(dpy);
+	SyncHandle();
+	return rep.data00;
+#endif /* SERVER_DGA */
+}
+
+
+int
+XDgaUnGrabBuffers(dpy, win)
+Display		*dpy;
+Window		win;
+{
+#ifdef SERVER_DGA
+    WindowPtr pWin = (WindowPtr)LookupIDByType(win, RT_WINDOW);
+
+    if (!pWin) 
+        return (BadCookie);                               
+    if (((DrawablePtr)pWin)->type == DRAWABLE_PIXMAP) 
+        return (BadCookie);
+    return(DgaBufUngrab(pWin));
+#else
+	xResourceReq		*req;
+	xGenericReply		rep;
+	struct dga_extinfo	*extinfop;
+
+	if ((extinfop = lookup_dga_ext(dpy)) == NULL)
+		return 0;
+	if (extinfop->protocol_major_version < 2)
+		return 0;
+	LockDisplay(dpy);
+	GetResReq(DGA, win, req);
+	req->reqType = extinfop->major_opcode;
+	req->pad = X_DgaUnGrabBuffers;
+	if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) {
+		UnlockDisplay(dpy);
+		SyncHandle();
+		return 0;
+		}
+	UnlockDisplay(dpy);
+	SyncHandle();
+	return rep.data00;
+#endif /* SERVER_DGA */
+}
+
+
+int 
+XDgaGrabRetainedWindow(dpy, win)
+Display		*dpy;
+Window		win;
+{
+#ifdef SERVER_DGA
+    WindowPtr pWin = (WindowPtr)LookupIDByType(win, RT_WINDOW);
+ 
+    if (!pWin) 
+        return (BadCookie);
+    if (((DrawablePtr)pWin)->type == DRAWABLE_PIXMAP) 
+        return (BadCookie);
+    return(DgaSharedRetained(pWin, 1, win));
+#else
+	xResourceReq	*req;
+	xGenericReply		rep;
+	struct dga_extinfo	*extinfop;
+
+	if ((extinfop = lookup_dga_ext(dpy)) == NULL)
+		return 0;
+	if (extinfop->protocol_major_version < 3)
+		return 0;
+	LockDisplay(dpy);
+	GetResReq(DGA, win, req);
+	req->reqType = extinfop->major_opcode;
+	req->pad = X_DgaGrabRetained;
+	if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) {
+		UnlockDisplay(dpy);
+		SyncHandle();
+		return 0;
+		}
+	UnlockDisplay(dpy);
+	SyncHandle();
+	return rep.data00;
+#endif /* SERVER_DGA */
+}
+
+
+int
+XDgaUnGrabRetainedWindow(dpy, win)
+Display		*dpy;
+Window		win;
+{
+#ifdef SERVER_DGA
+    WindowPtr pWin = (WindowPtr)LookupIDByType(win, RT_WINDOW);
+ 
+    if (!pWin) 
+        return (BadCookie);
+    if (((DrawablePtr)pWin)->type == DRAWABLE_PIXMAP) 
+        return (BadCookie);
+    return(DgaSharedRetained(pWin, 0, win));
+#else
+	xResourceReq		*req;
+	xGenericReply		rep;
+	struct dga_extinfo	*extinfop;
+
+	if ((extinfop = lookup_dga_ext(dpy)) == NULL)
+		return 0;
+	if (extinfop->protocol_major_version < 3)
+		return 0;
+	LockDisplay(dpy);
+	GetResReq(DGA, win, req);
+	req->reqType = extinfop->major_opcode;
+	req->pad = X_DgaUnGrabRetained;
+	if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) {
+		UnlockDisplay(dpy);
+		SyncHandle();
+		return 0;
+		}
+	UnlockDisplay(dpy);
+	SyncHandle();
+	return rep.data00; /* Status */
+#endif /* SERVER_DGA */
+}
+
+
+int
+XDgaGetRetainedPath(dpy, win, path)
+Display		*dpy;
+Window		win;
+char			*path;
+{
+#ifdef SERVER_DGA
+    extern char *DgaSharedRetainedPath;
+ 
+    if (DgaSharedRetainedPath)
+        strcpy((char *)path, (char *)DgaSharedRetainedPath);
+    return 1;
+#else
+	xResourceReq		*req;
+	xDGARtndPathReply	rep;
+	struct dga_extinfo	*extinfop;
+
+	if ((extinfop = lookup_dga_ext(dpy)) == NULL)
+		return 0;
+	if (extinfop->protocol_major_version < 3)
+		return 0;
+	LockDisplay(dpy);
+	GetResReq(DGA, win, req);
+	req->reqType = extinfop->major_opcode;
+	req->pad = X_DgaGetRetainedPath;
+	if (!_XReply(dpy, (xReply *) &rep,
+		   (SIZEOF(xDGARtndPathReply) - SIZEOF(xReply)) >> 2, xFalse)) {
+		UnlockDisplay(dpy);
+		SyncHandle();
+		return 0;
+		}
+	UnlockDisplay(dpy);
+	SyncHandle();
+	strcpy(path, (char *) rep.path);
+	return 1;
+#endif /* SERVER_DGA */
+}
+
+
+int
+XDgaQueryVersion(dpy, major_versionp, minor_versionp)
+Display	*dpy;
+int	*major_versionp,
+	*minor_versionp;
+{
+#ifdef SERVER_DGA
+    *major_versionp = SUN_DGA_MAJOR_VERSION;
+    *minor_versionp = SUN_DGA_MINOR_VERSION;
+    return(1);
+#else
+	xDgaQueryVersionReply rep;
+	xDgaQueryVersionReq *req;
+	int opcode, tmp;
+
+	if (XQueryExtension(dpy, "SUN_DGA", &opcode, &tmp, &tmp) == 0)
+		return 0;
+
+	LockDisplay(dpy);
+	GetReq(DgaQueryVersion, req);
+	req->reqType = opcode;
+	req->dgaReqType = X_DgaQueryVersion;
+	if (!_XReply(dpy, (xReply *) & rep, 0, xTrue)) {
+		UnlockDisplay(dpy);
+		SyncHandle();
+		return 0;
+		}
+	*major_versionp = rep.majorVersion;
+	*minor_versionp = rep.minorVersion;
+	UnlockDisplay(dpy);
+	SyncHandle();
+	return 1;
+#endif /* SERVER_DGA */
+}
+
+
+Dga_token 
+XDgaGrabPixmap(dpy, d)
+Display		*dpy;
+Pixmap		d;
+{
+#ifdef SERVER_DGA
+    int val;
+    PixmapPtr pPix = (PixmapPtr)LookupIDByType(d, RT_PIXMAP);
+    if (!pPix)
+        return (BadCookie);
+
+    if (((DrawablePtr)pPix)->type == DRAWABLE_WINDOW)
+        return (BadCookie);
+    val = DgaInitSharedPixmap(pPix, NEW);
+
+    if (val) {
+        if (dga_pixlist_add(val, dpy, d) == 0) {
+            XDgaUnGrabPixmap(dpy, d);
+            return 0;
+        }
+    }    
+    return val;
+#else
+	xResourceReq		*req;
+	xGenericReply		rep;
+	struct dga_extinfo	*extinfop;
+
+	if ((extinfop = init_dga_ext(dpy)) == NULL)
+		return 0;
+	if (extinfop->protocol_major_version < 3)
+		return 0;
+	LockDisplay(dpy);
+	GetResReq(DGA, d, req);
+	req->reqType = extinfop->major_opcode;
+	req->pad = X_DgaGrabPixmap;
+	if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) {
+		UnlockDisplay(dpy);
+		SyncHandle();
+		return 0;
+		}
+	UnlockDisplay(dpy);
+	SyncHandle();
+	if (rep.data00) {
+		if (dga_pixlist_add(rep.data00, dpy, d) == 0) {
+			XDgaUnGrabPixmap(dpy, d);
+			return 0;
+			}
+		}
+	return rep.data00;
+#endif /* SERVER_DGA */
+}
+
+
+int
+XDgaUnGrabPixmap(dpy, d)
+Display		*dpy;
+Pixmap		d;
+{
+#ifdef SERVER_DGA
+    PixmapPtr pPix = (PixmapPtr)LookupIDByType(d, RT_PIXMAP);
+    int val;
+
+    if (!pPix) 
+        return (BadCookie);
+    if (((DrawablePtr)pPix)->type == DRAWABLE_WINDOW) 
+        return (BadCookie);
+    val = DgaDestroySharedPixmap(pPix);
+
+    if (val) {
+        if (dga_pixlist_free(dpy, d) == 0)
+            return 0;
+    }
+    return val;
+#else
+	xResourceReq		*req;
+	xGenericReply		rep;
+	struct dga_extinfo	*extinfop;
+
+	if ((extinfop = lookup_dga_ext(dpy)) == NULL)
+		return 0;
+	if (extinfop->protocol_major_version < 3)
+		return 0;
+	LockDisplay(dpy);
+	GetResReq(DGA, d, req);
+	req->reqType = extinfop->major_opcode;
+	req->pad = X_DgaUnGrabPixmap;
+	if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) {
+		UnlockDisplay(dpy);
+		SyncHandle();
+		return 0;
+		}
+	UnlockDisplay(dpy);
+	SyncHandle();
+	return rep.data00; /* Status */
+#endif /* SERVER_DGA */
+}
+
+
+static Dga_token
+dgai_grabDrawRequest (Display *dpy, Drawable drawid, int *drawType)
+{
+#ifdef SERVER_DGA
+    DrawablePtr pDraw = (DrawablePtr)LookupIDByClass(drawid, RC_DRAWABLE);
+
+    if (!pDraw)
+        return(BadCookie);
+    return(DgaDrawGrab(drawid, pDraw, NEW, drawType));
+#else
+    xResourceReq		*req;
+    xGenericReply		rep;
+    struct dga_extinfo		*extinfop;
+    
+    if ((extinfop = init_dga_ext(dpy)) == NULL)
+	return 0;
+    if (extinfop->protocol_major_version < 3)
+      return 0;
+    LockDisplay(dpy);
+    GetResReq(DGA, drawid, req);
+    req->reqType = extinfop->major_opcode;
+    req->pad = X_DgaGrabDrawable;
+    if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) {
+	UnlockDisplay(dpy);
+	SyncHandle();
+	return 0;
+    }
+    UnlockDisplay(dpy);
+    SyncHandle();
+    
+    /* 
+     ** data00 is the opaque token identifying the drawable shared file.  
+     ** data01 is the type of the drawable: window (0) or pixmap (1),
+     ** (Note: an attempt to grab a multibuffer drawable XID will fail)
+     */
+    if (rep.data00) {
+	*drawType = rep.data01;
+    }
+
+    return (rep.data00);    
+#endif /* SERVER_DGA */
+}
+
+static int
+dgai_ungrabDrawRequest (Display *dpy, Drawable drawid)
+{
+#ifdef SERVER_DGA
+    DrawablePtr pDraw = (DrawablePtr)LookupIDByClass(drawid, RC_DRAWABLE);
+
+    if (!pDraw)
+        return(BadCookie);
+    return(DgaDrawUngrab(drawid, pDraw, NEW));
+#else
+    xResourceReq		*req;
+    xGenericReply		rep;
+    struct dga_extinfo		*extinfop;
+
+    if ((extinfop = lookup_dga_ext(dpy)) == NULL)
+      return 0;
+    if (extinfop->protocol_major_version < 3)
+      return 0;
+    LockDisplay(dpy);
+    GetResReq(DGA, drawid, req);
+    req->reqType = extinfop->major_opcode;
+    req->pad = X_DgaUnGrabDrawable;
+    if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) {
+	UnlockDisplay(dpy);
+	SyncHandle();
+	return 0;
+    }
+    UnlockDisplay(dpy);
+    SyncHandle();
+    return rep.data00; /* Status */
+#endif /* SERVER_DGA */
+}
+
+
+Dga_drawable
+XDgaGrabDrawable(Display *dpy, Drawable drawid)
+{
+    Dga_token   token;
+    int		drawType;
+
+#ifdef MT
+    mutex_lock(&dgaGlobalMutex);
+#endif
+    if (!(token = dgai_grabDrawRequest(dpy, drawid, &drawType))) {
+#ifdef MT
+	mutex_unlock(&dgaGlobalMutex);
+#endif
+	return (NULL);
+    }
+
+    switch (drawType) {
+
+    case DGA_PROTO_OVERLAY:
+    case DGA_PROTO_WINDOW: {
+	_Dga_window	dgawin;
+
+	if (!dga_winlist_add(token, dpy, (Window)drawid)) {
+	    goto Bad;
+	}
+        if (!(dgawin = (_Dga_window) dgai_win_grab_common(dpy, -1, token, 1))) {            goto Bad;
+        }
+	dgawin->w_dpy = dpy;
+	dgawin->w_id = (Window) drawid;
+	if (dgawin->isOverlay = (drawType == DGA_PROTO_OVERLAY)) {
+	    dgawin->s_ovlstate_p = &((WXINFO *)dgawin->w_info)->w_ovlstate;
+	    dgawin->s_ovlshapevalid_p =
+		&((WXINFO *)dgawin->w_info)->w_ovlshapevalid;
+		dgawin->ovlStateNotifyFunc = NULL;
+	}
+#ifdef MT
+	mutex_unlock(&dgaGlobalMutex);
+#endif
+	return ((Dga_drawable)dgawin);
+    }
+
+    case DGA_PROTO_PIXMAP: {
+	_Dga_pixmap	dgapix;
+
+	if (!dga_pixlist_add(token, dpy, (Pixmap)drawid)) {
+	    goto Bad;
+	}
+	if (!(dgapix = (_Dga_pixmap) dga_pix_grab(token, (Pixmap)drawid))) {
+	    goto Bad;
+	}
+	dgapix->p_dpy = dpy;
+	dgapix->p_id = (Pixmap) drawid;
+#ifdef MT
+	mutex_unlock(&dgaGlobalMutex);
+#endif
+	return ((Dga_drawable)dgapix);
+    }
+
+    }
+
+Bad:
+    (void) dgai_ungrabDrawRequest(dpy, drawid);
+#ifdef MT
+    mutex_unlock(&dgaGlobalMutex);
+#endif
+    return (NULL);
+}
+
+
+
+int
+XDgaUnGrabDrawable(Dga_drawable dgadraw)
+{
+    Drawable  drawid = dga_draw_id(dgadraw);
+    Display   *dpy = dga_draw_display(dgadraw);
+    int       type = dga_draw_type(dgadraw);
+    int       status;
+
+#ifdef MT
+    mutex_lock(&dgaGlobalMutex);
+#endif
+    switch (type) {
+    case DGA_DRAW_WINDOW: 
+    case DGA_DRAW_OVERLAY: 
+	dgai_win_ungrab_common((Dga_window)dgadraw, -1,1);
+	break;
+    case DGA_DRAW_PIXMAP:
+	dga_pix_ungrab((Dga_pixmap)dgadraw);
+	break;
+    }
+
+    status = dgai_ungrabDrawRequest(dpy, drawid);
+#ifdef MT
+    mutex_unlock(&dgaGlobalMutex);
+#endif
+    return (status);
+}
+
+
+
+static struct dga_xwinrec *dga_xwinlist = NULL;
+
+static int
+dga_winlist_add(token, dpy, win)
+Dga_token		token;
+Display		*dpy;
+Window		win;
+{
+	struct dga_xwinrec	*recp;
+	Display			*listdpy;
+	Window			listwin;
+
+	while (recp =
+	    (struct dga_xwinrec *) _dga_is_X_window(token,&listdpy,&listwin)) {
+		if ((win == listwin) && (dpy == listdpy)) {
+			recp->refcnt += 1;
+			return 1; /* already in list */
+			}
+		dga_winlist_free(listdpy, listwin); /* remove bogus entry from list */
+		}
+	recp = (struct dga_xwinrec *) malloc(sizeof(struct dga_xwinrec));
+	if (recp == NULL)
+		return 0;
+	recp->next = dga_xwinlist;
+	dga_xwinlist = recp;
+	recp->token = token;
+	recp->dpy = dpy;
+	recp->win = win;
+	recp->refcnt = 1;
+	return 1;
+}
+
+/*
+ * Free dga_xwinrec structure for a particular window and display.
+ * If win is NULL free all entries on list for this display.
+ */
+static int
+dga_winlist_free(dpy, win)
+Display		*dpy;
+Window		win;
+{
+	struct dga_xwinrec	*recp, **prevp;
+	int			match = 0;
+
+	prevp = &dga_xwinlist;
+	recp = dga_xwinlist;
+	while (recp) {
+		if (recp->dpy == dpy) {
+			if (win == NULL) {
+				*prevp = recp->next;
+				free(recp);
+				match = 1;
+				}
+			else if (recp->win == win) {
+				if (--recp->refcnt == 0) {
+					*prevp = recp->next;
+					free(recp);
+					}
+				return 1;
+				}
+			else {
+				prevp = &recp->next;
+				}
+			}
+		else {
+			prevp = &recp->next;
+			}
+		recp = *prevp;
+		}
+	return (match);
+}
+
+
+void *
+_dga_is_X_window(token, dpyp, winp)
+Dga_token		token;
+Display		**dpyp;
+Window		*winp;
+{
+	struct dga_xwinrec	*recp = dga_xwinlist;
+
+	while (recp) {
+		if (recp->token == token) {
+			*dpyp = recp->dpy;
+			*winp = recp->win;
+			return ((void *) recp);
+			}
+		recp = recp->next;
+		}
+	return 0;
+}
+
+static struct dga_xpixrec *dga_xpixlist = NULL;
+
+/* REMIND DARYL:  This routine is used to clean up "bogus" entries from
+ * list. Shouldn't that be done in Ungrab??? */
+int
+dga_pixlist_add(token, dpy, pix)
+Dga_token       token;
+Display    *dpy;
+Pixmap     pix;
+{
+    struct dga_xpixrec  *recp;
+    Display         *listdpy;
+
+    if (recp = (struct dga_xpixrec *) _dga_is_X_pixmap(pix, &listdpy)) {
+        if (dpy == listdpy) {
+            recp->refcnt += 1;
+            return 1; /* already in list */
+        }
+        dga_pixlist_free(dpy, pix); /* remove bogus entry from list */
+    }
+    recp = (struct dga_xpixrec *) malloc(sizeof(struct dga_xpixrec));
+    if (recp == NULL)
+        return 0;
+    recp->next = dga_xpixlist;
+    dga_xpixlist = recp;
+    recp->token = token;
+    recp->dpy = dpy;
+    recp->pix = pix;
+    recp->refcnt = 1;
+    return 1;
+}
+
+static int
+dga_pixlist_free(dpy, pix)
+Display    *dpy;
+Pixmap     pix;
+{
+    struct dga_xpixrec  *recp, **prevp;
+    int         match = 0;
+ 
+    prevp = &dga_xpixlist;
+    recp = dga_xpixlist;
+    while (recp) {
+        if (recp->dpy == dpy) {
+            if (pix == NULL) {
+                *prevp = recp->next;
+                free(recp);
+                match = 1;
+                }
+            else if (recp->pix == pix) {
+                if (--recp->refcnt == 0) {
+                    *prevp = recp->next;
+                    free(recp);
+                    }
+                return 1;
+                }
+            else {
+                prevp = &recp->next;
+                }
+            }
+        else {
+            prevp = &recp->next;
+            }
+        recp = *prevp;
+        }
+    return (match);
+}
+ 
+
+void *
+_dga_is_X_pixmap(pix, dpyp)
+Pixmap 	   pix;
+Display    **dpyp;
+{
+    struct dga_xpixrec  *recp = dga_xpixlist;
+
+    while (recp) {
+        if (recp->pix == pix) {
+	    *dpyp = recp->dpy;
+            return ((void *) recp);
+	}
+        recp = recp->next;
+        }
+    return 0;
+}
+
+#ifndef SERVER_DGA
+
+/************************************
+
+Addition to DGA for Xinerama extension.
+
+	This code allows the client to mine out
+	the window ID's that would normaly be 
+	hidden from the user in Xinerama mode.
+
+	Xinerama keeps a list of WIDs that are 
+	connected to a virtual WID that the user
+	gets to handle. 
+
+**************************************/
+
+
+BOOL 
+XDgaGetXineramaInfo(dpy , VirtualWID, info )
+Display *dpy;
+XID	VirtualWID;
+XineramaInfo *info;
+{
+register xDgaXineramaInfoReq *req;
+xDgaXineramaInfoReply *rep;
+struct dga_extinfo      *extinfop;
+
+    if ((extinfop = init_dga_ext(dpy)) == NULL)
+        return 0;
+
+    rep = malloc(sizeof(xDgaXineramaInfoReply));
+
+    LockDisplay(dpy);
+    GetReq(DgaXineramaInfo, req);
+    req->reqType = extinfop->major_opcode;
+    req->xdgaReqType = X_DgaXineramaInfo;
+    req->visual = VirtualWID;
+
+    if (!_XReply(dpy, (xReply *)rep, (sizeof(xDgaXineramaInfoReply)-32) >> 2, 
+	xFalse)) 
+    {
+        UnlockDisplay(dpy);
+        SyncHandle();
+	Xfree(rep);
+        return NULL;
+    }
+    info->wid = VirtualWID;
+    memcpy(&info->subs[0],&rep->subs[0],(MAXSCREEN-1) * sizeof(SubWID));
+    UnlockDisplay(dpy);
+    SyncHandle();
+    free(rep);
+    return 1;
+}
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/lib/libdga/sun-src/dga_Xrequests.h	Fri Nov 13 13:30:43 2009 -0800
@@ -0,0 +1,193 @@
+/* Copyright 1999 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ *
+ * 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, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * 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
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR 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.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+#pragma ident	"@(#)dga_Xrequests.h	35.6	09/11/09 SMI"
+
+/*
+ * dga_Xrequests.h - DGA X11 protocol extension definitions
+ */
+ 
+#ifndef _DGA_XREQUESTS_H
+#define _DGA_XREQUESTS_H
+
+/*
+ *
+ *-----------------------------------------------------------------------
+ * DGA minor op codes
+ *-----------------------------------------------------------------------
+ *
+ */
+#define SUN_DGA_MAJOR_VERSION   3       /* current version numbers */
+#define SUN_DGA_MINOR_VERSION   2
+
+/* protocol requests in Protocol Version 1 - OpenWindows 2.0 FCS */
+#define  X_DgaGrabWindow_Old	1
+#define  X_DgaUnGrabWindow_Old	2
+#define  X_DgaGrabColormap_Old 	3
+#define  X_DgaUnGrabColormap_Old 4
+
+
+/* additional protocol requests in Protocol Version 2 - OpenWindows 3.0 Beta */
+#define  X_DgaGrabWids 		5
+#define  X_DgaGrabBuffers 	6
+#define  X_DgaUnGrabBuffers  	7
+#define  X_DgaGrabFCS		8
+#define  X_DgaGrabZbuf		9
+#define  X_DgaGrabStereo       10
+#define  X_DgaGrabWindow       11
+#define  X_DgaUnGrabWindow     12
+
+
+/* additional protocol requests in Protocol Version 3 - OpenWindows 3.0 FCS */
+#define  X_DgaGrabColormap     13
+#define  X_DgaUnGrabColormap   14
+#define  X_DgaGrabRetained     15
+#define  X_DgaUnGrabRetained   16
+#define  X_DgaGetRetainedPath  17
+#define  X_DgaQueryVersion     18
+
+/* additional protocol requests in Protocol Version 3 - OpenWindows 3.0.1 FCS*/
+#define  X_DgaGrabPixmap       19
+#define  X_DgaUnGrabPixmap     20
+
+/* additional protocol requests in Protocol Version 3 - OpenWindows 3.4 FCS*/
+#define  X_DgaGrabDrawable     21
+#define  X_DgaUnGrabDrawable   22
+
+/* additional protocol requests in Protocol Version 4 - OpenWindows 3.6 FCS*/
+#define X_DgaGrabABuffers      23
+#define X_DgaUnGrabABuffers    24
+
+#define X_DgaXineramaInfo	25
+
+/*
+** Types of grabbable drawables
+*/
+
+#define DGA_PROTO_WINDOW  0
+#define DGA_PROTO_PIXMAP  1
+#define DGA_PROTO_OVERLAY 2
+
+/*
+ * DGA request structure
+ */
+
+#define sz_xDGAReq 12
+
+typedef struct {
+    CARD8 reqType;
+    BYTE pad;
+    CARD16 length B16;
+    CARD32 id B32;  /* a Window, Drawable, Font, GContext, Pixmap, etc. */
+    CARD32 number_objects B32;
+    } xDGAReq;
+
+/* DGA Ancillary Buffer request structure */
+typedef struct {
+    CARD8 reqType;
+    BYTE pad;
+    CARD16 length B16;
+    CARD32 id B32;  /* a Window, Drawable, Font, GContext, Pixmap, etc. */
+    CARD32 type B32;
+    CARD32 buffer_site B32;
+    } xDgaGrabABuffersReq;
+
+#define sz_xDgaGrabABuffersReq (sizeof(xDgaGrabABuffersReq))
+ 
+/*
+ * DGA shared retained path request structure
+ */
+
+#define xDGARtndPathLength	200
+#define sz_xDGARtndPathReply	(sizeof(xDGARtndPathReply))
+
+typedef struct {
+    BYTE type;                        /* X_Reply */
+    CARD8 pad;
+    CARD16 sequenceNumber B16;
+    CARD32 length B32;        
+    INT8  path[xDGARtndPathLength];         
+    } xDGARtndPathReply;     
+
+
+
+/*
+ * DgaQueryVersion request and reply structures
+ */
+
+typedef struct {
+    CARD8       reqType;		/* always SUN_DGA major opcode */
+    CARD8       dgaReqType;		/* always X_DgaQueryVersion */
+    CARD16	length B16;
+} xDgaQueryVersionReq;
+#define sz_xDgaQueryVersionReq	4
+
+typedef struct {
+    BYTE        type;			/* X_Reply */
+    CARD8       unused;
+    CARD16	sequenceNumber B16;
+    CARD32	length B32;
+    CARD16	majorVersion B16;
+    CARD16	minorVersion B16;
+    CARD32	pad0 B32;
+    CARD32	pad1 B32;
+    CARD32	pad2 B32;
+    CARD32	pad3 B32;
+    CARD32	pad4 B32;
+} xDgaQueryVersionReply;
+#define sz_xDgaQueryVersionReply	32
+
+
+struct dga_extinfo {
+	int protocol_major_version;	/* major version num of DGA protocol */
+	int protocol_minor_version;	/* minor version num of DGA protocol */
+	int extension;			/* extension number */
+	int major_opcode;		/* major op-code assigned by server */
+	};
+
+
+struct dga_xwinrec {
+	struct dga_xwinrec	*next;
+	Dga_token		token;
+	Display			*dpy;
+	Window			win;
+	int			refcnt;
+	};
+
+struct dga_xpixrec {
+    struct dga_xpixrec  *next;
+    Dga_token       token;
+    Display         *dpy;
+    Pixmap          pix;
+    int         refcnt;
+    };
+ 
+
+
+#endif /* _DGA_XREQUESTS_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/lib/libdga/sun-src/dga_ab.c	Fri Nov 13 13:30:43 2009 -0800
@@ -0,0 +1,777 @@
+/* Copyright 1999 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ *
+ * 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, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * 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
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR 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.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+#pragma ident	"@(#)dga_ab.c	1.14	09/11/09 SMI"
+ 
+/*
+ * dga_ab.c - the client side code for Ancillary Buffers (ABMG ) 
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <sys/fcntl.h>
+#include <X11/X.h>
+#include "dga_incls.h"
+
+extern int XDgaGrabABuffers(Display *dpy, Window win, int type, int buffer_site);
+extern int XDgaUnGrabABuffers(Display *dpy, Window win, int type);
+extern void *_dga_is_X_window(Dga_token token, Display **dpyp, Window *winp);
+
+#ifdef DEBUG
+#define assert(expr) \
+if(!(expr)) \
+{fprintf(stderr, "Assertion fails in file %s, line %d: expr\n",__FILE__,__LINE__); \
+abort();}
+#else
+#define assert(expr)
+#endif /* DEBUG */
+
+#define UNMAP_BUFFER(addr, allocsize) \
+    if ( addr ) { \
+        munmap((char *)addr, allocsize); \
+        addr = NULL; \
+    }
+
+#define GET_SW_HW_BUFFER(dgawin_buf, fname, bufsize)  \
+    bufferp = (dga_buffer)get_specified_buffer((char *)fname, bufsize); \
+    (dgawin_buf)->bufferp  = bufferp; \
+    (dgawin_buf)->pDraw    = dgadraw; \
+    (dgawin_buf)->buf_size = bufsize; \
+    ret_buf = dgawin_buf;
+
+#define STORE_BUFFERS(buf_addr, filename, fn_addr0, allocsize) \
+    bufferp = (buf_addr)->bufferp; \
+    if ( bufferp) { \
+        if (resize_flag) \
+            UNMAP_BUFFER(bufferp, (buf_addr)->buf_size) \
+        if ( filename && fn_addr0)  { \
+            if ( bufferp ) { \
+                buffers[count++] = (Dga_buffer *)buf_addr; \
+                bufferp->pDraw = dgadraw; \
+            } \
+            else {\
+                (buf_addr)->bufferp = bufferp = (void *) \
+                    get_specified_buffer((char *)filename, allocsize); \
+                 (buf_addr)->pDraw = dgadraw; \
+                 if (bufferp) { \
+                     buffers[count++] = (Dga_buffer *)buf_addr; \
+                     bufferp->pDraw = dgadraw; \
+                     (buf_addr)->buf_size = allocsize; \
+                 } \
+                 else { \
+                     (buf_addr)->buf_size = 0; \
+                 } \
+            }\
+        }\
+    }
+
+static dga_buffer
+get_specified_buffer(char *filename, int allocsize)
+{
+    int         filefd = -1;
+    dga_buffer  return_buf = NULL;
+
+    if ( filename && filename[0] ) {
+        if ((filefd = open(filename,O_RDWR,0666)) != -1 ) {
+            return_buf = (dga_buffer)mmap(0, allocsize,
+                PROT_READ|PROT_WRITE, MAP_SHARED, filefd, (off_t)0);
+            close (filefd);  /* May need to keep trap of fds... */
+
+            if ( return_buf == (dga_buffer) -1)
+                return ( (dga_buffer)NULL ); /* mmap failed. */
+
+            /* Set the data filed properly */
+	    assert(sizeof(dga_buffer_rec) & 0x7 == 0);
+            return_buf->data = (char *)(return_buf + 1);
+        }
+    }
+    return return_buf;
+
+}
+
+static void
+remap_buffers(Dga_drawable dgadraw)
+{
+    int         filefd = -1;
+    char        *filename;
+    int         count = 0;
+    dga_buffer  bufferp = NULL;
+    static      void     *buffers[DGA_NUM_BUFFER_TYPES];
+    _Dga_window dgawin = (_Dga_window)dgadraw;
+    WXINFO      *infop = wx_infop(dgawin);
+    int         resize_flag = True;
+ 
+    if ( dgawin->buf_resize_flag >= infop->wx_abuf.s_modified )
+        return;
+
+    STORE_BUFFERS((dga_internal_buffer)dgawin->back, infop->wx_abuf.back_fn, infop->wx_abuf.back_fn[0], infop->wx_abuf.back_size);
+
+    STORE_BUFFERS((dga_internal_buffer)dgawin->depth, infop->wx_abuf.depth_fn, infop->wx_abuf.depth_fn[0], infop->wx_abuf.depth_size);
+
+    STORE_BUFFERS((dga_internal_buffer)dgawin->stencil, infop->wx_abuf.stencil_fn, infop->wx_abuf.stencil_fn[0], infop->wx_abuf.stencil_size);
+
+    STORE_BUFFERS((dga_internal_buffer)dgawin->accum, infop->wx_abuf.accum_fn, infop->wx_abuf.accum_fn[0], infop->wx_abuf.accum_size);
+
+    STORE_BUFFERS((dga_internal_buffer)dgawin->alpha, infop->wx_abuf.alpha_fn, infop->wx_abuf.alpha_fn[0], infop->wx_abuf.alpha_size);
+
+    dgawin->buf_resize_flag = infop->wx_abuf.s_modified;
+
+    return;
+}
+
+/*
+ * Name    : dga_draw_grab_buffer
+ * Synopsis: This function requests the window system to provide 
+ * ancillary buffer service for the grabbed drawable name in the
+ * dgadraw argument.  The call requests  the type of the buffer
+ * specified to be grabbed to the client.  If buffer_site is 
+ * DGA_SITE_SYSTEM, server allocates the buffer in the shared 
+ * memory.  If it is DGA_SITE_DEVICE, the server tries to grab
+ * hardware buffers.  If the device does not support the given 
+ * buffer type in hardware, the request fails.
+ * The drawable must have been grabbed previously via XDgaGrabDrawable.
+ * 
+ * Implementation:  If buffer_stie is DGA_SITE_SYSTEM, this function
+ * increments the grab_cnt if the buffer is already grabbed by other clients.
+ * If this client has grabbed the specified buffer already, this function
+ * returns the grabbed buffer pointer.
+ * Otherwise, it sends a request to the server to grab a buffer.
+ * If the request is successful, this function returns the buffer 
+ * address.
+ * A special case where if the grab_cnt is "0", this function still sends
+ * a request to the server to grab the buffer  because there is a chance
+ * that the visual capabilities of the window might have been changed. 
+ */
+
+Dga_buffer 
+dga_draw_grab_buffer(Dga_drawable dgadraw, Dga_buffer_type type, int buffer_site)
+{
+    _Dga_window dgawin = (struct dga_window *)dgadraw;
+    Dga_window  clientpi = (Dga_window)dgawin;
+    _Dga_window clientp = (struct dga_window *)clientpi;
+    WXINFO      *infop;
+    Display     *dpy;
+    Window      win;
+    int         depth  = 0;
+    dga_buffer  bufferp = NULL;
+    dga_internal_buffer ret_buf = NULL;
+    dga_internal_buffer c_bufferp = NULL;
+
+    /* Ancillary Buffers are not supported for drawable_type 
+     * DGA_DRAW_PIXMAP
+     */
+    if ( ((_Dga_drawable)dgadraw)->drawable_type != DGA_DRAW_WINDOW ) 
+        return (0);
+
+    if (!DGA_LOCKSUBJ_WINDOW(dgawin, dgawin->eLockSubj)) 
+        return (0);
+
+    if ((clientp == (_Dga_window) NULL)) {
+#ifdef DEBUG
+        (void) fprintf(stderr, "dga_draw_grab_buffer: passed null pointer\n");
+#endif
+        return (0);
+    }
+
+    /*
+     *  Find out if this is an X window.  If so get the Display and window
+     *  id.
+     */
+    if (!_dga_is_X_window(clientp->w_token, &dpy, &win)) {
+#ifdef DEBUG
+        (void) fprintf(stderr, "dga_draw_grab_buffer: Unsupported window type\n");
+#endif
+        return (0);
+    }
+
+    infop = wx_infop(dgawin) ;
+
+    if ( dgawin->buf_resize_flag < infop->wx_abuf.s_modified )
+        remap_buffers(dgadraw);
+ 
+    switch ( type ) {
+    case DGA_BACK_BUFFER:
+        c_bufferp = (dga_internal_buffer)dgawin->back;
+        if ( c_bufferp->bufferp )
+            return dgawin->back;
+        GET_SW_HW_BUFFER(c_bufferp, infop->wx_abuf.back_fn, infop->wx_abuf.back_size);
+        break;
+    case DGA_DEPTH_BUFFER:
+        c_bufferp = (dga_internal_buffer)dgawin->depth;
+        if ( c_bufferp->bufferp )
+            return dgawin->depth;
+        GET_SW_HW_BUFFER(c_bufferp, infop->wx_abuf.depth_fn, infop->wx_abuf.depth_size);
+        break;
+    case DGA_STENCIL_BUFFER:
+        c_bufferp = (dga_internal_buffer)dgawin->stencil;
+        if ( c_bufferp->bufferp )
+            return dgawin->stencil;
+        GET_SW_HW_BUFFER(c_bufferp, infop->wx_abuf.stencil_fn, infop->wx_abuf.stencil_size);
+        break;
+    case DGA_ACCUM_BUFFER:
+        c_bufferp = (dga_internal_buffer)dgawin->accum;
+        if ( c_bufferp->bufferp )
+            return dgawin->accum;
+        GET_SW_HW_BUFFER(c_bufferp, infop->wx_abuf.accum_fn, infop->wx_abuf.accum_size);
+        break;
+    case DGA_ALPHA_BUFFER:
+        c_bufferp = (dga_internal_buffer)dgawin->alpha;
+        if ( c_bufferp->bufferp )
+            return dgawin->alpha;
+        GET_SW_HW_BUFFER(c_bufferp, infop->wx_abuf.alpha_fn, infop->wx_abuf.alpha_size);
+        break;
+    default:
+        return (0);
+    }
+
+    /* If grab_cnt is "0", then the reinitialization should go thru'
+     * server.  We can not just increment the grab_cnt.
+     * There is a chance that the buffers capabilities might have
+     * been changed in which case the server gets the bitsPerPixel
+     * from SunExtVis info struct and reallocates the buffer.
+     * If buffer_site is not DGA_SITE_SYSTEM, then it might be
+     * a Hardware Buffers.
+     */
+    if ( bufferp && (bufferp->buffer_site == DGA_SITE_SYSTEM) &&  
+            bufferp->grab_cnt > 0 ) {
+        bufferp->grab_cnt++;
+        return (Dga_buffer ) ret_buf;
+    }
+
+    /*
+     *  Request the server to allow DGA to the buffers associated
+     *  with this Dga_window.
+     */
+    if (!XDgaGrabABuffers(dpy, win, type, buffer_site)) {
+#ifdef DEBUG
+        (void)fprintf(stderr, "dga_draw_grab_buffer: XDgaGrabABuffers failed\n");
+#endif
+        return (0);
+    }
+
+    /* infop will contain the proper pointer to the selected buffer since
+     * it is in the dga shared page.
+     */
+    infop = wx_infop(dgawin) ;
+ 
+    /* get_specified_buffer:  This function checks on the filenames
+     * where if it is software buffer this member should have a 
+     * valid file name.
+     * If it is NULL, then it may be a hardware buffer and just
+     * return from this point where the hardware buffer would have
+     * been allocated already.
+     */
+    switch ( type ) {
+    case DGA_BACK_BUFFER:
+        c_bufferp = (dga_internal_buffer)dgawin->back;
+        GET_SW_HW_BUFFER(c_bufferp, infop->wx_abuf.back_fn, infop->wx_abuf.back_size);
+        break;
+        
+    case DGA_DEPTH_BUFFER:
+        c_bufferp = (dga_internal_buffer)dgawin->depth;
+        GET_SW_HW_BUFFER(c_bufferp, infop->wx_abuf.depth_fn, infop->wx_abuf.depth_size);
+        break;
+
+    case DGA_STENCIL_BUFFER:
+        c_bufferp = (dga_internal_buffer)dgawin->stencil;
+        GET_SW_HW_BUFFER(c_bufferp, infop->wx_abuf.stencil_fn, infop->wx_abuf.stencil_size);
+        break;
+
+    case DGA_ACCUM_BUFFER:
+        c_bufferp = (dga_internal_buffer)dgawin->accum;
+        GET_SW_HW_BUFFER(c_bufferp, infop->wx_abuf.accum_fn, infop->wx_abuf.accum_size);
+        break;
+
+    case DGA_ALPHA_BUFFER:
+        c_bufferp = (dga_internal_buffer)dgawin->alpha;
+        GET_SW_HW_BUFFER(c_bufferp, infop->wx_abuf.alpha_fn, infop->wx_abuf.alpha_size);
+        break; 
+
+    }
+
+    if ( bufferp ) {
+        bufferp->pDraw = ret_buf->pDraw = dgadraw;
+        return (Dga_buffer) ret_buf;
+    } else {
+        if (buffer_site == DGA_SITE_DEVICE)
+            return (Dga_buffer) c_bufferp;
+    }
+
+    return NULL;
+}
+
+/*
+ * Name    : dga_draw_ungrab_buffer
+ * Synopsis: This function ungrabs the buffer for the specified drawable
+ * which has been grabbed previously. Note that ungrabbing a buffer does
+ * not necessarily cause it to be freed.  If any of these steps fail,
+ * zero is returned.  True is returned upon success.
+ *
+ * Implementation: If the buffer is grabbed already, this function
+ * decrements the grab_cnt.  If grab_cnt  is negative, it will be 
+ * reset to "0".  
+ * If this client hasn't grabbed the buffer already, this function returns 0.
+ * This function will send a request to the server to ungrab the
+ * buffer only if buffer grabbed is in DGA_SITE_DEVICE ( Hardware ).
+ */
+int
+dga_draw_ungrab_buffer(Dga_drawable dgadraw, Dga_buffer_type type)
+{
+    _Dga_window dgawin = (_Dga_window)dgadraw;
+    WXINFO     *infop;
+    Display     *dpy;
+    Window       win;
+    dga_buffer  bufferp = NULL;
+    dga_internal_buffer ret_buf = NULL;
+    dga_internal_buffer c_bufferp = NULL;
+
+    /* Ancillary Buffers are not supported for drawable_type 
+     * DGA_DRAW_PIXMAP
+     */
+    if ( ((_Dga_drawable)dgadraw)->drawable_type != DGA_DRAW_WINDOW ) 
+        return (0);
+
+    if (!DGA_LOCKSUBJ_WINDOW(dgawin, dgawin->eLockSubj)) 
+        return (0);
+
+    if ((dgawin == (_Dga_window) NULL)) {
+#ifdef DEBUG
+        (void) fprintf(stderr, "dga_draw_ungrab_buffer: passed null pointer\n");
+#endif
+        return (0);
+    }
+
+    /*
+     *  Find out if this is an X window.  If so get the Display and window
+     *  id.
+     */
+    if (!_dga_is_X_window(dgawin->w_token, &dpy, &win)) {
+#ifdef DEBUG
+        (void) fprintf(stderr, "dga_draw_ungrab_buffer: Unsupported window type\n");
+#endif
+        return (0);
+    }
+
+    infop = wx_infop(dgawin) ;
+ 
+    switch ( type ) {
+    case DGA_BACK_BUFFER:
+        c_bufferp = (dga_internal_buffer)dgawin->back;
+        if ( c_bufferp->bufferp )
+            return 0;   
+        GET_SW_HW_BUFFER(c_bufferp, infop->wx_abuf.back_fn, infop->wx_abuf.back_size);
+        break;
+    case DGA_DEPTH_BUFFER:
+        c_bufferp = (dga_internal_buffer)dgawin->depth;
+        if ( c_bufferp->bufferp )
+            return 0;   
+        GET_SW_HW_BUFFER(c_bufferp, infop->wx_abuf.depth_fn, infop->wx_abuf.depth_size);
+        break;
+    case DGA_STENCIL_BUFFER:
+        c_bufferp = (dga_internal_buffer)dgawin->stencil;
+        if ( c_bufferp->bufferp )
+            return 0;   
+        GET_SW_HW_BUFFER(c_bufferp, infop->wx_abuf.stencil_fn, infop->wx_abuf.stencil_size);
+        break;
+    case DGA_ACCUM_BUFFER:
+        c_bufferp = (dga_internal_buffer)dgawin->accum;
+        if ( c_bufferp->bufferp )
+            return 0;   
+        GET_SW_HW_BUFFER(c_bufferp, infop->wx_abuf.accum_fn, infop->wx_abuf.accum_size);
+        break;
+    case DGA_ALPHA_BUFFER:
+        c_bufferp = (dga_internal_buffer)dgawin->alpha;
+        if ( c_bufferp->bufferp )
+            return 0;   
+        GET_SW_HW_BUFFER(c_bufferp, infop->wx_abuf.alpha_fn, infop->wx_abuf.alpha_size);
+        break;
+    default:
+        return (0);
+    } /* end of switch ( type ).. */
+
+/* Currently Just decrement the grab_cnt and if there is no grab
+ * don't free it.  Next time when it is getting grabbed, we will
+ * increment the count
+ * If the when the grab_cnt is "0" and the dga_drawable is getting
+ * resized then the buffers are thrown away.
+ */
+
+    if ( !bufferp )
+        return (0);
+        
+    if ( bufferp->buffer_site == DGA_SITE_SYSTEM ) {
+        bufferp->grab_cnt--;
+
+        if ( bufferp->grab_cnt < 0 ) 
+            bufferp->grab_cnt = 0;
+
+        switch ( type ) {
+        case DGA_BACK_BUFFER:
+            ((dga_internal_buffer)dgawin->back)->bufferp = NULL;
+            break;
+        case DGA_DEPTH_BUFFER:
+            ((dga_internal_buffer)dgawin->depth)->bufferp = NULL;
+            break;
+        case DGA_STENCIL_BUFFER:
+            ((dga_internal_buffer)dgawin->stencil)->bufferp = NULL;
+            break;
+        case DGA_ACCUM_BUFFER:
+            ((dga_internal_buffer)dgawin->accum)->bufferp = NULL;
+            break;
+        case DGA_ALPHA_BUFFER:
+            ((dga_internal_buffer)dgawin->alpha)->bufferp = NULL;
+            break;
+        default:
+            return (0);
+        } /* end of switch */
+    }
+    else {
+        /* Buffer site is DGA_SITE_DEVICE */
+        if (!XDgaUnGrabABuffers(dpy, win, type)) {
+#ifdef DEBUG
+        (void) fprintf(stderr, "dga_draw_ungrab_buffer: XDgaUnGrabABuffers failed\n");
+#endif
+        return (0);
+
+        }
+    } /* end of ( ret_buf->buffer_site == DGA_SITE_SYSTEM ).. */
+
+    return 1;
+}
+
+/*
+ * Name    : dga_draw_get_buffers
+ * Synopsis: This function returns the number of ancillary buffers
+ * associated with the specified dgadraw and an arry of buffer
+ * pointers.  Note that only buffers which have been grabbed by
+ * the client are returned.  Buffers which might exist (because of 
+ * grabs by other clients or the server) are not returned.
+ */
+int
+dga_draw_get_buffers(Dga_drawable dgadraw, Dga_buffer **pBufs )
+{
+    char        *filename;
+    int         count = 0;
+    dga_buffer  bufferp = NULL;
+    static      void     *buffers[DGA_NUM_BUFFER_TYPES];
+    _Dga_window dgawin = (_Dga_window)dgadraw;
+    WXINFO      *infop = wx_infop(dgawin);
+    int         resize_flag = False;
+    
+    if ( dgawin->buf_resize_flag < infop->wx_abuf.s_modified )
+        resize_flag = True;
+
+    STORE_BUFFERS((dga_internal_buffer)dgawin->back, infop->wx_abuf.back_fn, infop->wx_abuf.back_fn[0], infop->wx_abuf.back_size);
+
+    STORE_BUFFERS((dga_internal_buffer)dgawin->depth, infop->wx_abuf.depth_fn, infop->wx_abuf.depth_fn[0], infop->wx_abuf.depth_size);
+
+    STORE_BUFFERS((dga_internal_buffer)dgawin->stencil, infop->wx_abuf.stencil_fn, infop->wx_abuf.stencil_fn[0], infop->wx_abuf.stencil_size);
+
+    STORE_BUFFERS((dga_internal_buffer)dgawin->accum, infop->wx_abuf.accum_fn, infop->wx_abuf.accum_fn[0], infop->wx_abuf.accum_size);
+
+    STORE_BUFFERS((dga_internal_buffer)dgawin->alpha, infop->wx_abuf.alpha_fn, infop->wx_abuf.alpha_fn[0], infop->wx_abuf.alpha_size);
+
+    if ( resize_flag )
+        dgawin->buf_resize_flag = infop->wx_abuf.s_modified;
+ 
+    *pBufs = buffers;
+
+    return count;
+}
+
+
+/*
+ * Name    : dga_buffer_type
+ * Synopsis: This function returns the type of the buffer specified.
+ */
+Dga_buffer_type
+dga_buffer_type(Dga_buffer bufferp)
+{
+    _Dga_window dgawin;
+    WXINFO      *infop;
+    dga_buffer local_buf;
+ 
+    if ( !bufferp || !(local_buf = ((dga_internal_buffer)bufferp)->bufferp))
+        return -1;
+ 
+    dgawin =  (_Dga_window)((dga_internal_buffer)bufferp)->pDraw;
+    infop  = wx_infop(dgawin);
+ 
+    if ( dgawin->buf_resize_flag < infop->wx_abuf.s_modified ) {
+        remap_buffers((Dga_drawable)((dga_internal_buffer)bufferp)->pDraw);
+        local_buf = ((dga_internal_buffer)bufferp)->bufferp;
+    }
+ 
+    return local_buf->buffer_type;
+}
+
+
+#if 0
+/* We had this function for completeness. */
+/*
+ * Name    : dga_buffer_get_drawable
+ * Synopsis: This function returns the Dga_drawable associated with the
+ * buffer specified.
+ */
+Dga_drawable
+dga_buffer_get_drawable(Dga_buffer bufferp )
+{
+    if ( !bufferp )
+        return NULL;
+
+    return ((dga_buffer)bufferp)->pDraw;
+}
+#endif
+
+
+/*
+ * Name    : dga_buffer_site (Lock Only)
+ * Synopsis: This function returns the site of the buffer specified.
+ * The values are the same as those returned by dga_draw_site().
+ * DGA_SITE_SYSTEM, DGA_SITE_DEVICE and DGA_SITE_NULL.
+ */
+int
+dga_buffer_site(Dga_buffer bufferp)
+{
+    _Dga_window dgawin;
+    WXINFO      *infop;
+    dga_buffer local_buf;
+ 
+    if ( !bufferp || !(local_buf = ((dga_internal_buffer)bufferp)->bufferp))
+        return DGA_SITE_NULL;  
+ 
+    dgawin =  (_Dga_window)((dga_internal_buffer)bufferp)->pDraw;
+    infop  = wx_infop(dgawin);
+ 
+    if ( dgawin->buf_resize_flag < infop->wx_abuf.s_modified ) {
+        remap_buffers((Dga_drawable)((dga_internal_buffer)bufferp)->pDraw);
+        local_buf = ((dga_internal_buffer)bufferp)->bufferp;
+    }
+
+    return local_buf->buffer_site;
+}
+
+
+/*
+ * Name    : dga_draw_bufferchg
+ * Synopsis: This function returns True if any of the buffers 
+ * associated with the dgadraw have undergone a state change
+ * since the last lock.  When dga_draw_bufferchg returns True,
+ * the client should call dga_buffer_sitechg for each of the
+ * Drawable's buffers.
+ */
+int
+dga_draw_bufferchg(Dga_drawable dgadraw)
+{
+    _Dga_window dgawin = (_Dga_window)dgadraw;
+    WXINFO      *infop = wx_infop(dgawin);
+
+    if (infop && (infop->wx_abuf.s_modified))
+        return True;
+ 
+    return False;
+}
+
+/*
+ * Name    : dga_buffer_sitechg
+ * Synopsis: This function returns True if the buffer has sitechg 
+ * flag set.  Note that this function always returns False for 
+ * device buffers.  Only memory buffers ever have a site chagne.
+ * dga_buffer_sitechg() also returns the reason for site change.
+ * Currenly the only possible values for reason are DGA_SITECHG_INITIAL,
+ * which is reported the first time a Drawable is locaked after a buffer
+ * has been created and DGA_SITECHG_CACHE which indicates that the
+ * buffer has been resized since the time that the Dga_drawable was last 
+ * locked.
+ */
+int
+dga_buffer_sitechg(Dga_buffer bufferp, int *reason)
+{
+    _Dga_window dgawin; 
+    WXINFO      *infop; 
+    dga_buffer local_buf;
+ 
+    if ( !bufferp || !(local_buf = ((dga_internal_buffer)bufferp)->bufferp))
+        return False; /* Returning False may mislead the developer */
+ 
+    dgawin =  (_Dga_window)((dga_internal_buffer)bufferp)->pDraw;
+    infop  = wx_infop(dgawin);
+ 
+    if ( dgawin->buf_resize_flag < infop->wx_abuf.s_modified ) {
+        remap_buffers((Dga_drawable)((dga_internal_buffer)bufferp)->pDraw);
+        local_buf = ((dga_internal_buffer)bufferp)->bufferp;
+    }
+ 
+    if  (local_buf->buffer_site != DGA_SITE_SYSTEM)
+        return False;
+
+    if (local_buf->sitechg) {
+        *reason = local_buf->sitechg;
+        local_buf->sitechg = DGA_SITECHG_UNKNOWN;
+        return True;
+    } else
+        return False;
+}
+
+/*
+ * Name    : dga_buffer_address (Lock Only)
+ * Synopsis: This function returns the data pointer from the shared
+ * buffer page of the buffer specified.  An address will be returned
+ * only for buffers which are located in system memory.  
+ * If dga_buffer_address is called on a buffer located with 
+ * DGA_SITE_DEVICE, NULL will be returned.  The value returned 
+ * remains valid across locks until a sitechg is reported as 
+ * described above.
+ */
+void *
+dga_buffer_address(Dga_buffer bufferp)
+{
+    _Dga_window dgawin; 
+    WXINFO      *infop; 
+    dga_buffer local_buf;
+ 
+    if ( !bufferp || !(local_buf = ((dga_internal_buffer)bufferp)->bufferp))
+        return NULL;
+ 
+    dgawin =  (_Dga_window)((dga_internal_buffer)bufferp)->pDraw;
+    infop  = wx_infop(dgawin);
+
+    if ( dgawin->buf_resize_flag < infop->wx_abuf.s_modified ) {
+        remap_buffers((Dga_drawable)((dga_internal_buffer)bufferp)->pDraw);
+        local_buf = ((dga_internal_buffer)bufferp)->bufferp;
+    }
+ 
+    if  (local_buf->buffer_site == DGA_SITE_SYSTEM) {
+        local_buf->data = (char *)(local_buf + 1);
+        return local_buf->data; 
+    }
+    else
+        return NULL;
+}
+
+/*
+ * Name    : dga_buffer_linebytes
+ * Synopsis: This function returns the number of bytes per scanline
+ * of the buffer specified.  Only buffers which are located in
+ * system memory are addressable.  If dga_buffer_linebytes is called
+ * for a buffer located on the device, "0" is returned.
+ */
+int
+dga_buffer_linebytes(Dga_buffer bufferp)
+{
+    _Dga_window dgawin; 
+    WXINFO      *infop; 
+    dga_buffer local_buf;
+
+    if ( !bufferp || !(local_buf = ((dga_internal_buffer)bufferp)->bufferp))
+        return 0;
+ 
+    dgawin =  (_Dga_window)((dga_internal_buffer)bufferp)->pDraw;
+    infop  = wx_infop(dgawin);
+ 
+    if ( dgawin->buf_resize_flag < infop->wx_abuf.s_modified ) {
+        remap_buffers((Dga_drawable)((dga_internal_buffer)bufferp)->pDraw);
+        local_buf = ((dga_internal_buffer)bufferp)->bufferp;
+    }
+
+    if  (local_buf->buffer_site == DGA_SITE_SYSTEM)
+        return local_buf->linebytes; 
+    else
+        return 0;
+}
+
+/*
+ * Name    : dga_buffer_bitsperpixel
+ * Synopsis: This function returns bitsperpixel of the buffer 
+ * specified if the buffer is located in system memory.  If the
+ * buffer is located on the device, zero is returned.  Note that
+ * the value might be different than the number of significant bits.
+ * For example, an unpacked 4 bit stencil buffer would return
+ * 8 bits per pixel, and a 24 bit Z buffer would return 
+ * 32 bits per pixel.
+ */
+int
+dga_buffer_bitsperpixel(Dga_buffer bufferp)
+{
+    _Dga_window dgawin; 
+    WXINFO      *infop; 
+    dga_buffer local_buf;
+
+    if ( !bufferp || !(local_buf = ((dga_internal_buffer)bufferp)->bufferp))
+        return 0;
+
+    dgawin =  (_Dga_window)((dga_internal_buffer)bufferp)->pDraw;
+    infop  = wx_infop(dgawin);
+
+    if ( dgawin->buf_resize_flag < infop->wx_abuf.s_modified ) {
+        remap_buffers((Dga_drawable)((dga_internal_buffer)bufferp)->pDraw);
+        local_buf = ((dga_internal_buffer)bufferp)->bufferp;
+    }
+
+    if  (local_buf->buffer_site == DGA_SITE_SYSTEM)
+        return local_buf->bitsPerPixel; 
+    else
+        return 0;
+}
+
+void
+dga_draw_buffer_swap(Dga_drawable dgadraw, int (*visfunc)(Dga_window))
+{
+     _Dga_window dgawin = (_Dga_window)dgadraw;
+     WXINFO      *infop = wx_infop(dgawin);
+
+    if (visfunc)
+        (*visfunc)(dgawin);
+
+    if ( infop && infop->wx_abuf.back_fn && infop->wx_abuf.back_fn[0] 
+                && infop->wx_abuf.back ) {
+        infop->wx_abuf.buffer_swap++;
+        dgawin->c_buffer_swap = infop->wx_abuf.buffer_swap;
+    }
+ 
+    return; 
+}
+
+int
+dga_draw_swap_check(Dga_drawable dgadraw)
+{
+    _Dga_window dgawin = (_Dga_window)dgadraw;
+    WXINFO      *infop = wx_infop(dgawin);
+ 
+    if ( infop && infop->wx_abuf.back_fn && infop->wx_abuf.back_fn[0]  
+           && infop->wx_abuf.back 
+           && ( dgawin->c_buffer_swap != infop->wx_abuf.buffer_swap)) {
+        dgawin->c_buffer_swap = infop->wx_abuf.buffer_swap;
+        return 1;
+    }
+
+    return 0; 
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/lib/libdga/sun-src/dga_db.c	Fri Nov 13 13:30:43 2009 -0800
@@ -0,0 +1,576 @@
+/* Copyright 1999 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ *
+ * 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, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * 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
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR 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.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+#pragma ident	"@(#)dga_db.c	35.5	09/11/09 SMI"
+ 
+/* 
+ * dga_db.c - the client side code for DGA double buffering
+ */
+
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <X11/Xlib.h>
+
+#include <sys/fbio.h>
+
+#ifndef FBIOVRTOFFSET
+#ifdef SVR4
+#define FBIOVRTOFFSET	(FIOC | 38)
+#else
+#define FBIOVRTOFFSET   _IOR(F, 38, int)
+#endif
+#endif
+
+#include <netdb.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include "dga_incls.h"
+
+#define	DGA_WIN_LOCK_NOMODIF(win)			\
+{							\
+    if ((((_Dga_window)(win))->w_lockcnt)++ == 0) {	\
+	DGA_LOCK(win);					\
+	}						\
+}
+
+#define DGA_WIN_UNLOCK_NOMODIF(win)		\
+{						\
+    if (--(((_Dga_window)(win))->w_lockcnt) == 0) \
+	DGA_UNLOCK(win);			\
+}
+    
+extern void *_dga_is_X_window(Dga_token token, Display **dpyp, Window *winp);
+
+#ifdef _LP64
+static int _dga_db_vrtfunc_internal(Dga_window);
+#else  /* _LP64 */
+#if defined(__STDC__)
+static int _dga_db_vrtfunc_internal(Dga_window);
+#else
+static int _dga_db_vrtfunc_internal();
+#endif
+#endif /* _LP64 */
+
+static u_int *dga_vrt_access();
+static void dga_vrt_release();
+
+int 
+dga_db_access(wg_clientpi)
+     Dga_window wg_clientpi ;
+{
+    _Dga_window wg_clientp = (struct dga_window *)wg_clientpi;
+     WXINFO	*infop = wx_infop(wg_clientp) ;
+     u_int	*cpage;
+     u_int	*dga_vrt_access();
+
+    if (wg_clientp->db_enabled)
+	return 0;
+    if (infop->wx_dbuf.number_buffers < 2)
+	return 1;
+
+    cpage = dga_vrt_access(wg_clientp->w_devfd);
+
+    if (cpage)
+    {
+	wg_clientp->db_enabled = 1;
+	wg_clientp->db_vrtcntrp = cpage;
+	wg_clientp->db_lastvrtcntr = *cpage;
+	wg_clientp->db_swapint = 1;
+	wg_clientp->vrt_func = _dga_db_vrtfunc_internal ;
+	if ((infop->wx_dbuf.display_buffer < 0) ||
+	 (infop->wx_dbuf.display_buffer > (infop->wx_dbuf.number_buffers - 1)))
+		infop->wx_dbuf.display_buffer = 0;
+	if ((infop->wx_dbuf.read_buffer < 0) ||
+	   (infop->wx_dbuf.read_buffer > (infop->wx_dbuf.number_buffers - 1)))
+		infop->wx_dbuf.read_buffer = 1;
+	if ((infop->wx_dbuf.write_buffer < 0) ||
+	    (infop->wx_dbuf.write_buffer > (infop->wx_dbuf.number_buffers - 1)))
+		infop->wx_dbuf.write_buffer = 1;
+	return(0);
+    }
+    else
+	return(1);
+}
+
+void
+dga_db_release(wg_clientpi)
+     Dga_window wg_clientpi ;
+{
+     void	dga_vrt_release();
+    _Dga_window wg_clientp = (struct dga_window *)wg_clientpi;
+    
+     if (wg_clientp->db_vrtcntrp)
+         dga_vrt_release(wg_clientp->db_vrtcntrp);
+     wg_clientp->db_enabled = 0;
+ 
+}
+
+
+void
+dga_db_write(wg_clientpi,buffer,writefunc,data)
+     Dga_window wg_clientpi ;
+     int buffer;
+#ifdef _LP64
+     int (*writefunc)(void*, Dga_window, int);
+#else  /* _LP64 */
+#if defined (__STDC__)
+     int (*writefunc)(void*, Dga_window, int);
+#else
+    int (*writefunc)();
+#endif
+#endif /* _LP64 */
+     void* data;
+{
+    _Dga_window wg_clientp = (struct dga_window *)wg_clientpi;
+    
+     DGA_WIN_LOCK_NOMODIF(wg_clientp);
+     if (writefunc)
+	(*writefunc) (data,wg_clientpi,buffer);
+     wx_infop(wg_clientp)->wx_dbuf.write_buffer = buffer; 
+     DGA_WIN_UNLOCK_NOMODIF(wg_clientp);
+}
+
+void
+dga_db_read(wg_clientpi,buffer,readfunc,data)
+     Dga_window wg_clientpi ;
+     int buffer;
+#ifdef _LP64
+     int (*readfunc)(void*, Dga_window, int);
+#else  /* _LP64 */
+#if defined (__STDC__)
+     int (*readfunc)(void*, Dga_window, int);
+#else
+    int (*readfunc)();
+#endif
+#endif /* _LP64 */
+     void* data;
+{
+    _Dga_window wg_clientp = (struct dga_window *)wg_clientpi;
+    
+     DGA_WIN_LOCK_NOMODIF(wg_clientp);
+     wx_infop(wg_clientp)->wx_dbuf.read_buffer = buffer; 
+     if (readfunc)
+	(*readfunc) (data,wg_clientpi,buffer);
+     DGA_WIN_UNLOCK_NOMODIF(wg_clientp);
+}
+
+
+void
+dga_db_display(wg_clientpi,buffer,visfunc,data)
+     Dga_window wg_clientpi ;
+     int buffer;
+#ifdef _LP64
+     int (*visfunc)(void*, Dga_window, int);
+#else  /* _LP64 */
+#if defined (__STDC__)
+     int (*visfunc)(void*, Dga_window, int);
+#else
+    int (*visfunc)();
+#endif
+#endif /* _LP64 */
+     void* data;
+{
+    _Dga_window wg_clientp = (struct dga_window *)wg_clientpi;
+    
+    if (!dga_db_interval_check(wg_clientpi))
+       dga_db_interval_wait(wg_clientpi);
+    if (visfunc) 
+	(*visfunc)(data, wg_clientpi, buffer);
+    if (wg_clientp->db_vrtcntrp)
+        wg_clientp->db_lastvrtcntr = *wg_clientp->db_vrtcntrp;
+    wx_infop(wg_clientp)->wx_dbuf.display_buffer = buffer;
+}
+
+void
+dga_db_interval(wg_clientpi,interval)
+     Dga_window wg_clientpi ;
+     int interval;		/* number of milliseconds */
+{
+     int ref_rate;
+     float rr;
+     _Dga_window wg_clientp = (struct dga_window *)wg_clientpi;
+
+     ref_rate  = wx_infop(wg_clientp)->w_refresh_period;
+    if (ref_rate == 0) ref_rate = 66000;
+
+    if (interval < 0)
+	interval = 0;
+    if (interval > ref_rate)
+	interval = ref_rate;
+    rr = ((float)ref_rate)* 0.001;
+    wg_clientp->db_swapint = rr * ((float)interval* 0.001);
+
+    if (wg_clientp->db_swapint == 0)
+        wg_clientp->db_swapint = 1;
+}
+
+
+void
+dga_db_interval_wait(wg_clientpi)
+     Dga_window wg_clientpi ;
+{
+    _Dga_window wg_clientp = (struct dga_window *)wg_clientpi;
+    u_int *counter = wg_clientp->db_vrtcntrp;
+
+    /* Do a block if necessary and if vrt_func has been supplied */
+
+    if (!wg_clientp->vrt_func || !wg_clientp->db_vrtcntrp) return;
+
+    while (((u_int) (*counter - wg_clientp->db_lastvrtcntr))
+          < wg_clientp->db_swapint)
+    {
+	if ((*(wg_clientp->vrt_func))(wg_clientpi) < 0) return ;;
+    }
+    return;
+}
+
+int
+dga_db_interval_check(wg_clientpi)
+     Dga_window wg_clientpi ;
+{
+    _Dga_window wg_clientp = (struct dga_window *)wg_clientpi;
+     u_int *counter = wg_clientp->db_vrtcntrp;
+
+     if ((wg_clientp->db_vrtcntrp) && 
+	 ((u_int) (*counter - wg_clientp->db_lastvrtcntr))
+          < wg_clientp->db_swapint)
+        return(0);
+     else
+   	return(1);
+}
+
+int
+dga_db_write_inquire(wg_clientpi)
+     Dga_window wg_clientpi ;
+{
+    _Dga_window wg_clientp = (struct dga_window *)wg_clientpi;
+     return(wx_infop(wg_clientp)->wx_dbuf.write_buffer);
+}
+
+int
+dga_db_read_inquire(wg_clientpi)
+     Dga_window wg_clientpi ;
+{
+    _Dga_window wg_clientp = (struct dga_window *)wg_clientpi;
+    
+     return(wx_infop(wg_clientp)->wx_dbuf.read_buffer);
+}
+
+int
+dga_db_display_inquire(wg_clientpi)
+     Dga_window wg_clientpi ;
+{
+    _Dga_window wg_clientp = (struct dga_window *)wg_clientpi;
+     return(wx_infop(wg_clientp)->wx_dbuf.display_buffer);
+}
+
+/* INTERNAL INTERFACE */
+int
+dga_db_display_complete(wg_clientpi, flag)
+    Dga_window wg_clientpi ;
+    int flag;
+{
+    _Dga_window wg_clientp = (struct dga_window *)wg_clientpi;
+    if (wg_clientp->db_vrtcntrp && 
+	(wg_clientp->db_lastvrtcntr != *(wg_clientp->db_vrtcntrp)))
+	return 1;
+    if (flag == 0)
+	return 0;
+    if (ioctl(wg_clientp->w_devfd,FBIOVERTICAL,0) < 0)
+	return 0;
+    return 1;
+}
+
+/* INTERNAL INTERFACE */
+static u_int
+*dga_vrt_access(devfd)
+   int devfd;
+{
+        u_int *cpage;
+        u_int dev_offset;
+	u_int pagesize;
+
+        dev_offset = 0;
+        if (ioctl(devfd, FBIOVRTOFFSET, &dev_offset) < 0)
+           return (NULL);
+
+#ifdef SVR4
+	pagesize = sysconf(_SC_PAGESIZE);
+#else
+	pagesize = getpagesize();
+#endif
+
+	/*
+	 * the driver provides the dev_offset into the mmaped page
+	 * where the vertical retrace counter word is.
+	 * We will mmap a shared memory page that is on a
+	 * page boundary then modify the pointer to the
+	 * vertical retrace counter to reflect the exact
+	 * location where the counter word exists
+	 */
+
+	cpage = (u_int *) mmap((char *)0,
+				pagesize,
+				PROT_READ | PROT_WRITE,
+				MAP_SHARED | _MAP_NEW,
+				devfd,
+				(off_t) (dev_offset & ~(pagesize - 1)));
+
+	/* if the mmap failed then return NULL otherwide return
+	 * the computed address of the vertical retract counter
+	 * by adding the beginning of the mmaped page to the
+	 * dev_offset into the page returned by the device driver
+	 */
+
+	if (cpage == (u_int *) -1)
+		return NULL;
+
+        return ((u_int *) ((int) cpage | (dev_offset & (pagesize - 1))));
+}
+
+static void
+dga_vrt_release(counter)
+u_int *counter;
+{
+	char *counter_page;
+	int pagesize;
+
+#ifdef SVR4
+	pagesize = sysconf(_SC_PAGESIZE);
+#else
+	pagesize = getpagesize();
+#endif
+
+	/* Unmap the page for this client.
+	 * remove the offset computation and munmap the
+	 * vertical retrace counter page.  we remove the
+	 * offset by simply setting the lower bits of 
+	 * the address to 0
+	 */
+
+	counter_page = (char *) (((int) counter) & (~(pagesize - 1)));
+        munmap(counter_page, pagesize) ;
+	return;
+}
+
+/* New routines that will be exposed to the public */
+
+int 
+dga_db_display_done(wg_clientpi,flag, display_done_func)
+Dga_window wg_clientpi;
+int flag;
+#ifdef _LP64
+int (*display_done_func)(Dga_window);
+{
+    int (*vrt_func)(Dga_window);
+#else  /* _LP64 */
+#if defined (__STDC__)
+int (*display_done_func)(Dga_window);
+#else
+int (*display_done_func)();
+#endif
+{
+#if defined (__STDC__)
+    int (*vrt_func)(Dga_window);
+#else
+    int (*vrt_func)();
+#endif
+#endif /* _LP64 */
+    _Dga_window wg_clientp = (struct dga_window *)wg_clientpi;
+    int ret_val;
+    
+    /* Return 1 = done, 0 = not done, -1 = error */
+    ret_val = (*display_done_func)(wg_clientpi);
+
+    /* If the user does not want to block or if the
+     * display_done_func() returned a non-zero, we return
+     * else we try till success after each vrt_retrace()
+    */
+    if ((!flag) || (ret_val != 0))
+	return (ret_val);
+    
+    vrt_func = wg_clientp->vrt_func;
+    if (!vrt_func) return 1;
+
+    while((ret_val = (*display_done_func)(wg_clientpi)) == 0)
+	if (vrt_func(wg_clientpi) < 0) return -1;
+    return (ret_val);
+}
+
+/* Returns 0 on fail and non-zero on success */
+int
+dga_db_grab(clientpi, nbuffers, vrtfunc, vrtcounterp)
+Dga_window clientpi;
+int nbuffers;
+#ifdef _LP64
+int (*vrtfunc)(Dga_window);
+#else  /* _LP64 */
+#if defined (__STDC__)
+int (*vrtfunc)(Dga_window);
+#else
+int (*vrtfunc)();
+#endif
+#endif /* _LP64 */
+u_int *vrtcounterp;
+{
+    Display	*dpy;
+    Window	 win;
+
+    /*
+     *  Check for an invalid Dga_window
+     */
+     _Dga_window clientp = (struct dga_window *)clientpi;
+     WXINFO	*infop;
+    
+    if ((clientp == (_Dga_window) NULL)) {
+#ifdef DEBUG
+	(void) fprintf(stderr, "dga_db_grab: passed null pointer\n");
+#endif
+	return (0);
+    }
+
+    /*
+     *  If the buffers has already been grabbed. Don't
+     *  do anything.
+     */
+    if (clientp->db_enabled)
+	return (1);
+
+    /*
+     *  Find out if this is an X window.  If so get the Display and window
+     *  id.  
+     */
+     if (!_dga_is_X_window(clientp->w_token, &dpy, &win)) {
+#ifdef DEBUG
+	(void) fprintf(stderr, "dga_db_grab: Unsupported window type\n");
+#endif
+	return (0);
+    }
+
+    /*
+     *  Request the server to allow DGA to the buffers associated
+     *  with this Dga_window.
+     */
+    if (!XDgaGrabBuffers(dpy, win, nbuffers)) {
+#ifdef DEBUG
+	(void) fprintf(stderr, "dga_db_grab: XDgaGrabBuffers failed\n");
+#endif
+	return (0);
+    }
+
+    /* Now if they supplied vrtfunc, update the clientp
+     */
+
+    infop =wx_infop(clientp) ;
+    clientp->vrt_func = vrtfunc;
+
+    /* Now update the clientp pointer with other info */
+    if (vrtcounterp) {
+	clientp->db_enabled = 1;
+	clientp->db_vrtcntrp = (u_int *)vrtcounterp;
+	clientp->db_lastvrtcntr = *vrtcounterp;
+	clientp->db_swapint = 1;
+	if ((infop->wx_dbuf.display_buffer < 0) ||
+	 (infop->wx_dbuf.display_buffer > (infop->wx_dbuf.number_buffers - 1)))
+		infop->wx_dbuf.display_buffer = 0;
+	if ((infop->wx_dbuf.read_buffer < 0) ||
+	   (infop->wx_dbuf.read_buffer > (infop->wx_dbuf.number_buffers - 1)))
+		infop->wx_dbuf.read_buffer = 1;
+	if ((infop->wx_dbuf.write_buffer < 0) ||
+	   (infop->wx_dbuf.write_buffer > (infop->wx_dbuf.number_buffers - 1)))
+		infop->wx_dbuf.write_buffer = 1;
+	return(1);
+    } else {
+
+	/* Even though they have not supplied vrtp we allow the db_grab
+	 * to succeed but we null out vrtfunc and set vrtcntrp to point
+	 * to itself!
+	*/
+	clientp->db_enabled = 1;
+	clientp->vrt_func = NULL;
+	clientp->db_vrtcntrp = NULL;
+	return(1);
+    }
+    
+}
+
+/* Returns 0 on failure and non-zero on success */
+int
+dga_db_ungrab(clientpi)
+Dga_window clientpi;
+{
+    _Dga_window clientp = (struct dga_window *)clientpi;    
+    Display    *dpy;
+    Window	win;
+    int		status = -1;
+
+    /*
+     *  Check for an invalid Dga_window
+     */
+    if ((clientp == (Dga_window) NULL)) {
+#ifdef DEBUG
+        (void) fprintf(stderr, "dga_db_ungrab: passed null pointer\n");
+#endif
+        return (0);
+    }
+    
+    /* If it wasm't grabbed in the first place. don't do anything */
+    if (!clientp->db_enabled)
+	return 1;
+
+
+    /*
+     *  Find out if this is an X window.  If so get the Display and window
+     *  id.  
+     */
+     if (!_dga_is_X_window(clientp->w_token, &dpy, &win)) {
+#ifdef DEBUG
+        (void) fprintf(stderr, "dga_db_ungrab: Unsupported window type\n");
+#endif
+        return (0);
+    }
+    /* Mark the window as single buffered */
+    clientp->db_enabled = 0;
+
+    /* Tell server t ungrab */
+    return (XDgaUnGrabBuffers(dpy, win));
+
+    
+}
+/* This is just for internal use */
+static int
+_dga_db_vrtfunc_internal(wg_clientp)
+Dga_window wg_clientp;
+{
+   ( ioctl(((_Dga_window)wg_clientp)->w_devfd,FBIOVERTICAL,0));
+   return(1);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/lib/libdga/sun-src/dga_externaldefs.h	Fri Nov 13 13:30:43 2009 -0800
@@ -0,0 +1,73 @@
+/* Copyright 1994 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ *
+ * 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, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * 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
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR 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.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+#pragma ident	"@(#)dga_externaldefs.h	35.3	09/11/09 SMI"
+
+#ifndef	_DGA_EXTERNALDEFS_H
+#define	_DGA_EXTERNALDEFS_H
+
+/*
+** External defines for libdga.
+*/
+
+#define DGA_DRAW_WINDOW			0
+#define DGA_DRAW_PIXMAP			1
+#define DGA_DRAW_OVERLAY		2
+
+#define DGA_MBACCESS_NONE		0
+#define DGA_MBACCESS_SINGLEADDR		1
+#define DGA_MBACCESS_MULTIADDR		2
+
+#define DGA_SITE_NULL			0
+#define DGA_SITE_DEVICE			1
+#define DGA_SITE_SYSTEM			2
+
+#define DGA_SITECHG_UNKNOWN		0
+#define DGA_SITECHG_INITIAL		1
+#define DGA_SITECHG_ZOMBIE		2
+#define DGA_SITECHG_ALIAS		3
+#define DGA_SITECHG_CACHE		4
+#define DGA_SITECHG_MB			5
+
+#define DGA_MBCHG_UNKNOWN		0
+#define DGA_MBCHG_ACTIVATION		1
+#define DGA_MBCHG_DEACTIVATION		2
+#define DGA_MBCHG_REPLACEMENT	        3
+
+#define DGA_VIS_UNOBSCURED		0
+#define DGA_VIS_PARTIALLY_OBSCURED	1
+#define DGA_VIS_FULLY_OBSCURED		2
+
+#define DGA_OVLSTATE_SAFE		0
+#define DGA_OVLSTATE_MULTIWID		1
+#define DGA_OVLSTATE_CONFLICT		2
+
+#define DGA_MAX_GRABBABLE_BUFS       16
+
+#endif /* _DGA_EXTERNALDEFS_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/lib/libdga/sun-src/dga_incls.h	Fri Nov 13 13:30:43 2009 -0800
@@ -0,0 +1,53 @@
+/* Copyright 1994 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ *
+ * 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, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * 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
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR 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.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+#pragma ident	"@(#)dga_incls.h	35.6	09/11/09 SMI"
+
+#ifndef	_DGA_INCLS_H
+#define	_DGA_INCLS_H
+
+/*
+** Pervasive include files used by DGA-internal files
+*/
+
+#include <sys/types.h>
+#ifdef MT
+#include <synch.h>
+#endif
+#include <X11/Xmd.h>
+#include "dga.h"
+#include "dga_internaldefs.h"
+#include "vmbuf_grab.h"
+#include "dga_internal.h"
+#include "win_grab.h"
+#include "dga_winshared.h"
+#include "dga_pixshared.h"
+#include "dga_rtnshared.h"
+
+#endif /* _DGA_INCLS_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/lib/libdga/sun-src/dga_internal.h	Fri Nov 13 13:30:43 2009 -0800
@@ -0,0 +1,500 @@
+/* Copyright 1997 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ *
+ * 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, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * 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
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR 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.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+#pragma ident	"@(#)dga_internal.h	35.12	09/11/09 SMI"
+
+#ifndef _DGA_INTERNAL_H
+#define _DGA_INTERNAL_H
+
+/*
+ * dga_internal.h - Sun Direct Graphics Access interface internal include file
+ */
+
+/* Note that _Dga_window, _Dga_cmap, _Dga_pixmap are all internal declarations
+ * for the externally visible Dga_window, Dga_cmap and Dga_pixmap ( no leading
+ * underscore). In the externally visible include file, these are all declared
+ * as void * and thus quite opaque.
+ *
+ * Note: there is a DGA_FAST_DRAW_LOCK() macro that also access the
+ * fields in struct dga_window and dga_pixmap but is not currently in dga.h.
+ * Consider this macro before modifying fields.
+*/
+
+typedef u_int   *Dga_lockp;
+ 
+typedef struct dga_mbufset *DgaMbufSetPtr;
+
+
+/* used only to get at the drawable type.  After that, we vector off
+   to either a window or pixmap routine */
+typedef struct dga_drawable {
+        int	    drawable_type;	/* pointer to drawable type */
+} *_Dga_drawable;
+
+typedef	struct dga_window {
+	int	    drawable_type;	/* pointer to drawable type */
+	u_int	    c_chngcnt;          /* last recorded window change count */
+	u_int	    *s_chngcnt_p;	/* ptr to server's global change cnt */
+	int	    w_lockcnt;	        /* lock count for nested locks */
+	Dga_lockp   w_lockp;		/* pointer to lock page */
+	Dga_lockp   w_unlockp;		/* points to unlock page */
+#ifdef MT
+	mutex_t	    *mutexp;   		/* points to drawable's mutex */
+#else
+	int	    (*w_lock_func)();   /* alternate function for locking */
+#endif
+	int	    (*w_unlock_func)(); /* alternate func for unlocking */
+	int	    (*w_update_func)(); 
+	int	    w_modif;		/* cached result of update check */
+	u_int       c_wm_chngcnt[17];	/* last recorded global change counts */
+	u_int       *w_wm_2nd;          /* Ptr to second entry in wm_chngcnt[]*/
+	void	    *w_info;	        /* pointer to shared memory */
+	u_int	    c_clipseq;		/* last recorded clip change count */
+	u_int	    *s_clipseq_p;	/* ptr to server's clip change count */
+	short	    *w_clipptr;		/* client virtual ptr to clip array. */
+	u_int	    w_cliplen;		/* client's size of cliplist in bytes*/
+	Dga_token   w_token;		/* token used to grab window */
+	int	    w_infofd;		/* fd of shared memory file */
+	int	    w_devfd;		/* fd of framebuffer */
+	int	    w_grab_count;	/* how many times we've grabbed it */
+	struct dga_window *w_next;	/* used to link all grabbed windows */
+	void	    *w_lib_private;	/* library private data */
+	void	    *w_client;		/* for client use */
+
+
+	/* cursor grabber info */
+	void	    *curs_info;		/* pointer to client's cursor info */
+	int	    curs_fd;		/* Client side file descriptor */
+	u_int	    c_curseq;		/* last recorded cursor change count */
+	u_int	    *s_curseq_p;	/* ptr to server's cursor change cnt */
+
+        /* Ancillay Buffer info */
+        void   *back;
+        void   *depth;
+        void   *stencil;
+        void   *accum;
+        void   *alpha;
+        int    buf_resize_flag;
+        u_int  c_buffer_swap;
+
+	/* double buffering info */
+	u_int	    db_enabled;		/* flag to tell if initialized */
+	u_int	    *db_vrtcntrp;	/* Client's ptr to VRT counter */
+	u_int	    db_lastvrtcntr;	/* VRT counter value at last flip */
+	u_int	    db_swapint;		/* number of intervals between flips */
+	int	   (*vrt_func)(Dga_window);/* user supplied vrt retrace func */
+
+	/* retained window grabber info */
+	int	    rtn_fd;	/* Client side fd for shared memory */
+	u_int	    rtn_size;	/* Client size of pixel block in bytes */
+	u_int	    c_rtnseq;	/* Client rtn modification counter */
+	u_int	    *s_rtnseq_p;/* Ptr to server's rtn mod counter */
+	u_int	    c_rtncachseq;/* Client device cache modification counter */
+	u_int	    *s_rtncachseq_p; /* Ptr to server's dev cache modification counter */
+	void	    *rtn_info;	/* Ptr to Shared memory structure */
+	void	    *rtn_pixels;	/* Client ptr to Client pixel mapping */
+	u_int	    rtn_flags;	/* to record state of retained grab */
+
+	/*
+	** New fields for drawable grabber.
+        */
+
+	Display     	*w_dpy;			/* display the window belongs to */
+	Window		w_id;			/* XID of window */
+	DgaMbufSetPtr	pMbs;			/* Non-null for multibuf wins */
+	u_int		*s_mbufseq_p;		/* pointer to mbuf seq in shinfo */
+	u_int		c_mbufseq;		/* last mbufset composition sequence count */
+	u_int		*s_mbcomposseq_p;	/* pointer to mbufset compos seq in shinfo */
+	u_int		c_mbcomposseq;		/* last mb state sequence count */
+	u_int		*s_devinfoseq_p;	/* pointer to devinfo seq in shinfo */
+	u_int		c_devinfoseq;		/* last devinfo state sequence count */
+
+	/* notification functions */
+	DgaSiteNotifyFunc    siteNotifyFunc;
+	void		     *siteNotifyClientData;
+	DgaMbNotifyFunc	     mbNotifyFunc;
+	void		     *mbNotifyClientData;
+	DgaRendBufNotifyFunc rendBufNotifyFunc;
+	void		     *rendBufNotifyClientData;
+
+	/*  real lock subject - the win/mbuf currently locked by the client */
+	short		rLockSubj;
+
+	/*  effective lock subject - the actual lock subject. This will be used by
+	    the DGA state inquiry functions called by the client.   If the 
+	    win/mbuf is not aliased, eLockSubj will be the same as rLockSubj */
+	short		eLockSubj;
+
+	/*  previous effective lock subject - the lock subject for which a
+	    change was last signalled to the client.  It is assumed that the
+	    client synchronized its state to this lock subject.  This is always
+	    true for well-behaved DGA clients */
+	short		eLockSubjPrev;
+	
+	/* mbChgReason is the reason for an mbufset change.  prevWasMbuffered 
+	   is used to help us figure this out.  It is set during the update
+	   phase and may be used during the inquiry phase */
+	char   		prevWasMbuffered;
+        char		mbChgReason;
+
+	/* used during update phase to indicate what state changed */
+	u_int		changeMask;
+
+	/* reason for any site change */
+        char		siteChgReason;
+
+	/* Has the window been previously locked? */
+	char		prevLocked;
+
+	u_char	        alignPad[2];
+
+	/* overlay info
+	 *
+	 * If the window is an overlay, the isOverlay flag will be set to
+	 * true and the s_ovlstate_p pointer will point to the ovlstate
+	 * flag on the shared page and the s_ovlshapevalid_p pointer will
+	 * point to the w_ovl_shape_valid flag.
+	 */
+	int		isOverlay;
+	int		c_ovlstate;
+	int		*s_ovlstate_p;
+	int		*s_ovlshapevalid_p;
+	DgaOvlStateNotifyFunc ovlStateNotifyFunc;
+	void		*ovlStateNotifyClientData;
+
+#ifdef MT
+	/* For the threaded case, this stores the real change counts while
+	 * c_wm_chngcnt[] is used to force the update function to be called.
+	 */
+	u_int		shadow_chngcnt[17];
+#endif
+
+} *_Dga_window;
+
+
+typedef struct _dgaLastSeqs {
+    u_int	mbufseq;
+    u_int 	clipseq;
+    u_int 	curseq;
+    u_int 	rtnseq;
+} DgaLastSeqs, *DgaLastSeqsPtr;
+
+typedef	struct dga_cmap {
+	void	    *cm_info;/* pointer to shared memory */
+	u_int	    c_chngcnt;		/* last recorded change count */
+	u_int	    *s_chngcnt_p;	/* last recorded change count */
+	int	    cm_lockcnt;		/* lock count for nested locks */
+	u_int	    *cm_lockp;		/* pointer to lock page */
+	u_int	    *cm_unlockp;	/* pointer to unlock page */
+	int	    cm_use_new_ioctl; 	/* use new hardware ioctl? */
+	Dga_token   cm_token;		/* token used to grab cmap */
+	int	    cm_infofd;		/* fd of shared memory file */
+	int	    cm_devfd;		/* fd of framebuffer */
+	int	    cm_lockfd;		/* fd of lock device 
+					 * (if not framebuffer) */
+	int	    cm_sunwindows_def_fd; /* client fd for server's
+				   	SunWindows default cmap window */
+	int	    cm_sunwindows_inst_fd; /* client fd for server's
+					   SunWindows installed cmap window */
+	int	    cm_grab_count;	/* how many times we've grabbed it */
+	struct dga_cmap *cm_next;	/* used to link all grabbed cmaps */
+	void	    *cm_lib_private;	/* library private data */
+	void	    *cm_client;		/* for client use */
+} *_Dga_cmap;
+
+/*
+* When the pixmap interface is made public, this declaration should be
+* moved into the dga.h file and taken out of the dga_internal.h file
+* Also the lock routiens currently in pix_grab,c should be made into
+* macros and added to dga.h
+*/
+
+typedef struct dga_pixmap {
+    int     	drawable_type;  /* pointer to drawable type - window/pixmap*/
+    u_int       obsolete;       /* last recorded global change count */
+    u_int       *s_chngcnt_p;   /* ptr to server's global change cnt */
+    int		p_lockcnt;	/* lock count for nested locks */
+    Dga_lockp   p_lockp;        /* pointer to lock page */
+    Dga_lockp   p_unlockp;      /* points to unlock page */
+#ifdef MT
+    mutex_t	*mutexp;   		/* points to drawable's mutex */
+#else
+    int         (*p_lock_func)(); /* alternate function for locking */
+#endif
+    int         (*p_unlock_func)(); /* alternate func for unlocking */
+    int         (*p_update_func)(); /* function to call for updates */
+    int         p_modif;        /* cached result of update check ?? */
+    u_int	c_chngcnt[1];   /* Last recorded global change count */
+    u_int       *p_chngcnt_2nd;  /* Pts to c_chngcnt[0]*/
+    void     	*p_infop;        /* pointer to shared pixmap memory*/
+/* TODO: Why are the next two entries in here?  It's not clear to me why
+ * the client side cares if the shpx_dir changes. The only time a pixmap
+ * is removed from the directory structure is when it is destroyed and
+ * then the obsolete flag is set. */
+    u_int       c_dirchngcnt;   /* Client's last recorderd dir chng cnt */
+    u_int       *s_dirchngcnt_p;/* Ptr to server's dir chng cnt */
+    u_int	c_devinfocnt;   /* Client's last recorded devinfo seq cnt */
+    u_int	*s_devinfocnt_p; /* Ptr to server's devinfo seq cnt */
+    u_int       c_cachecnt;     /* Client's last recorded cache sequence cnt */
+    u_int       *s_cachecnt_p;  /* ptr to Server cache sequence count */
+    u_char      c_cached;       /* Client's last recorded cache state */
+    u_char      *s_cached_p;   /* Ptr to server's cache state */
+    u_int       p_dir_index;    /* Client's pixmap's directory index */
+    void     	*p_shpx_dir;     /* Client's ptr to the shpx dir */
+    void     	*p_shpx_client;     /* Client's ptr to the shpx client struct */
+    Dga_token   p_token;        /* token used to grab window */
+    u_int       c_size;         /* Client's size of pixel array */
+    u_char      *c_pixels;       /* pointer to clients pixels */ 
+    u_char      depth;          /* pixmap depth in bits */
+    char        pad0;          /* padding to align to int */
+    u_short     pad1;          /* padding to align to int */
+    u_int       linebytes;       /* pixmap linebyte */    
+    struct dga_pixmap *p_next;  /* used to link all grabbed pixmaps */
+    int         p_infofd;       /* fd of shared memory file */  
+    u_int       pix_flags;      /* to record state of grab ?? */
+    Display	*p_dpy;
+    Pixmap	p_id;		/* XID of pixmap */
+    void	*p_client;	/* for client use */
+
+    /* used during update phase to indicate what state changed */
+    u_int		changeMask;
+
+    /* reason for any site change */
+    char		siteChgReason;
+    u_char	        alignPad[3];
+
+    DgaSiteNotifyFunc    siteNotifyFunc;
+    void        	*siteNotifyClientData;
+#ifdef MT
+    /* For the threaded case, this stores the real change counts while
+     * c_chngcnt[] is used to force the update function to be called.
+     */
+    u_int	shadow_chngcnt[1];
+#endif
+} *_Dga_pixmap;
+
+typedef void * Dga_pixmap;
+
+#ifdef	__cplusplus
+extern "C" {
+#endif
+
+#ifdef MT
+extern mutex_t		dgaGlobalMutex;
+extern mutex_t		dgaGlobalPixmapMutex;
+extern int		dgaThreaded;
+extern int		dgaMTOn;
+#endif
+
+#ifdef MT
+extern int		dgai_unlock(Dga_drawable dgadraw);
+#endif
+
+/* Pixmap grabber routines - these are not Public yet */
+extern	Dga_token	XDgaGrabPixmap(Display*, Pixmap);
+extern	int		XDgaUnGrabPixmap(Display*, Pixmap);
+extern Dga_pixmap	dga_pix_grab(Dga_token, Pixmap);
+extern	void		dga_pix_ungrab(Dga_pixmap);
+extern	int		dga_pix_cachechg(Dga_pixmap);
+extern	int		dga_pix_cached(Dga_pixmap);
+extern	char*		dga_pix_devname(Dga_pixmap);
+extern	void		*dga_pix_pixels(Dga_pixmap);
+extern	int		dga_pix_linebytes(Dga_pixmap);
+extern	u_char		dga_pix_depth(Dga_pixmap);
+extern	void		*dga_pix_devinfo(Dga_pixmap);
+
+
+/* These are always going to be private routines  to be backward
+ * compatible
+*/
+extern	int		XDgaGrabRetainedWindow(Display*, Window);
+extern	int		XDgaUnGrabRetainedWindow(Display *, Window);
+extern	int		XDgaGetRetainedPath(Display*, Window, char*);
+extern	int		XDgaQueryVersion(Display*, int*, int*);
+extern	int		XDgaGrabBuffers(Display *, Window, int	);
+extern	int		XDgaUnGrabBuffers(Display *, Window);
+extern	void		dga_cm_get(Dga_cmap, int, int, u_char *, u_char *,
+					u_char *);
+extern	void		dga_cm_put(Dga_cmap, int, int, u_char *, u_char*,
+					u_char *);
+extern	int		dga_db_access(Dga_window);
+extern	void		dga_db_release(Dga_window);
+extern	int		dga_db_display_complete(Dga_window, int);
+extern void		*dga_rtn_devinfo(Dga_window);
+
+/*
+** Internal mbuf grab routine
+*/
+
+extern Dga_window	dga_mbuf_grab (int devfd, Dga_token winToken);
+
+/*
+** Internal mbufset member update routines
+*/
+
+extern int		dgai_mbsmemb_update (Dga_drawable dgadraw, short bufIndex);
+extern int		dgai_mbsmemb_syncZombie (_Dga_window dgawin);
+extern void		dgai_mbsmemb_syncMbufset (_Dga_window dgawin);
+extern void		dgai_mbsmemb_syncRendBuf (_Dga_window dgawin);
+extern void		dgai_mbsmemb_figureDerivChgs (_Dga_window dgawin);
+extern void		dgai_mbsmemb_notify (_Dga_window dgawin);
+extern void		dgai_mbsmemb_devinfo_update(_Dga_window dgawin);
+
+
+/*
+** Internal window update routines
+*/
+
+extern Dga_window	dgai_win_grab_common (Display *dpy, int devfd, Dga_token token, int drawableGrabber);
+extern int 		dgai_win_update (_Dga_window dgawin, short bufIndex);
+extern void		dgai_win_clip_update(_Dga_window dgawin);
+extern void		dgai_win_curs_update(_Dga_window dgawin);
+extern void		dgai_win_rtn_update(_Dga_window dgawin);
+extern void		dgai_win_syncChanges (_Dga_window dgawin, DgaLastSeqsPtr pLastSeqs);
+extern int		dgai_win_visibility(Dga_window wini);
+
+/*
+** Internal multibuffer update routines
+*/
+
+extern int		dgai_mbuf_update (_Dga_window dgawin, short bufIndex);
+extern void		dgai_vmbuf_syncChanges (_Dga_window dgawin, DgaLastSeqsPtr pLastSeqs, short bufIndex);
+extern void		dgai_nmbuf_syncChanges (_Dga_window dgawin);
+extern void		dgai_nmbuf_cache_update(_Dga_window dgawin);
+extern void		dgai_nmbuf_devinfo_update(_Dga_window dgawin);
+
+/*
+** Internal multibuffer set routines
+*/
+
+extern DgaMbufSetPtr	dgai_mbufset_create (_Dga_window dgawin);
+extern void		dgai_mbufset_incref (DgaMbufSetPtr pMbs);
+extern void		dgai_mbufset_decref (DgaMbufSetPtr pMbs);
+
+/*
+** Internal mbufset member inquiry routines
+*/
+
+extern Display *	dgai_mbsmemb_display (_Dga_window dgawin);
+extern char *		dgai_mbsmemb_devname (_Dga_window dgawin);
+extern int		dgai_mbsmemb_devfd (_Dga_window dgawin);
+extern int		dgai_mbsmemb_depth (_Dga_window dgawin);
+extern void		dgai_mbsmemb_set_client_infop (_Dga_window dgawin, void *client_info_ptr);
+extern void *		dgai_mbsmemb_get_client_infop (_Dga_window dgawin);
+extern void *		dgai_mbsmemb_devinfo (_Dga_window dgawin);
+extern int		dgai_mbsmemb_sitechg (_Dga_window dgawin, int *reason);
+extern void		dgai_mbsmemb_sitesetnotify (_Dga_window dgawin, 
+						    DgaSiteNotifyFunc site_notify_func,
+						    void *client_data);
+extern void		dgai_mbsmemb_sitegetnotify (_Dga_window dgawin, 
+						    DgaSiteNotifyFunc *site_notify_func,
+						    void **client_data);
+extern int		dgai_mbsmemb_site (_Dga_window dgawin);
+extern void *		dgai_mbsmemb_address (_Dga_window dgawin);
+extern int		dgai_mbsmemb_linebytes (_Dga_window dgawin);
+extern int		dgai_mbsmemb_bitsperpixel (_Dga_window dgawin);
+extern int		dgai_mbsmemb_clipchg (_Dga_window dgawin);
+extern void		dgai_mbsmemb_bbox(_Dga_window dgawin, int *xp, int *yp, 
+					  int *widthp, int *heightp);
+extern int		dgai_mbsmemb_visibility (_Dga_window dgawin);
+extern int		dgai_mbsmemb_empty (_Dga_window dgawin);
+extern short *		dgai_mbsmemb_clipinfo (_Dga_window dgawin);
+extern int		dgai_mbsmemb_singlerect (_Dga_window dgawin);
+extern int		dgai_mbsmemb_obscured (_Dga_window dgawin);
+extern u_short		dgai_mbsmemb_borderwidth (_Dga_window dgawin);
+extern void		dgai_mbsmemb_curshandle (_Dga_window dgawin, DgaCursTakeDownFunc take_down_func,
+						 void *client_data);
+extern int		dgai_mbsmemb_rtngrab (_Dga_window dgawin);
+extern int		dgai_mbsmemb_rtnungrab (_Dga_window dgawin);
+extern int		dgai_mbsmemb_rtnchg (_Dga_window dgawin);
+extern int		dgai_mbsmemb_rtnactive (_Dga_window dgawin);
+extern int		dgai_mbsmemb_rtncached (_Dga_window dgawin);
+extern void *		dgai_mbsmemb_rtndevinfop (_Dga_window dgawin);
+extern void		dgai_mbsmemb_rtndevtype (_Dga_window dgawin, u_char *type, 
+						 char **name);
+extern void		dgai_mbsmemb_rtndimensions (_Dga_window dgawin, short *width, 
+						    short *height, u_int *linebytes);
+extern int		dgai_mbsmemb_rtnbitsperpixel(_Dga_window dgawin);
+extern void *		dgai_mbsmemb_rtnpixels (_Dga_window dgawin);
+extern int		dgai_mbsmemb_mbchg (_Dga_window dgawin, int *reason);
+extern void		dgai_mbsmemb_mbsetnotify (_Dga_window dgawin, DgaMbNotifyFunc mb_notify_func,
+						  void *client_data);
+extern void		dgai_mbsmemb_mbgetnotify (_Dga_window dgawin, DgaMbNotifyFunc *mb_notify_func,
+						  void **client_data);
+extern int		dgai_mbsmemb_mbaccessmode (_Dga_window dgawin);
+extern int		dgai_mbsmemb_mbsitetypeconst (_Dga_window dgawin);
+extern void		dgai_mbsmemb_mbsetrendbufnotify (_Dga_window dgawin, 
+							 DgaRendBufNotifyFunc rb_notify_func,
+							 void *client_data);
+extern void		dgai_mbsmemb_mbgetrendbufnotify (_Dga_window dgawin, 
+							 DgaRendBufNotifyFunc *rb_notify_func,
+							 void **client_data);
+extern int		dgai_mbsmemb_ovlstatechg (_Dga_window dgawin);
+extern int		dgai_mbsmemb_ovlstate (_Dga_window dgawin);
+extern void		dgai_mbsmemb_setovlstatenotify (_Dga_window dgawin, 
+							DgaOvlStateNotifyFunc ovlstate_notify_func,
+							void *client_data);
+extern void		dgai_mbsmemb_getovlstatenotify (_Dga_window dgawin, 
+							DgaOvlStateNotifyFunc *ovlstate_notify_func,
+							void **client_data);
+
+
+/*
+** Internal pixmap inquiry routines
+*/
+
+/* TODO: dhuff: must supply */
+
+extern int		dgai_pix_update(Dga_drawable dgadraw, short bufIndex);
+extern Display *	dgai_pix_display (_Dga_pixmap dgapix);
+extern char *		dgai_pix_devname (_Dga_pixmap dgapix);
+extern int		dgai_pix_devfd (_Dga_pixmap dgapix);
+extern int		dgai_pix_depth (_Dga_pixmap dgapix);
+extern void		dgai_pix_set_client_infop (_Dga_pixmap dgapix, void *client_info_ptr);
+extern void *		dgai_pix_get_client_infop (_Dga_pixmap dgapix);
+extern void *		dgai_pix_devinfo (_Dga_pixmap dgapix);
+extern int		dgai_pix_sitechg (_Dga_pixmap dgapix, int *reason);
+extern void		dgai_pix_sitesetnotify (_Dga_pixmap dgapix, 
+						    DgaSiteNotifyFunc site_notify_func,
+						    void *client_data);
+extern void		dgai_pix_sitegetnotify (_Dga_pixmap dgapix, 
+						    DgaSiteNotifyFunc *site_notify_func,
+						    void **client_data);
+extern int		dgai_pix_site (_Dga_pixmap dgapix);
+extern void *		dgai_pix_address (_Dga_pixmap dgapix);
+extern int		dgai_pix_linebytes (_Dga_pixmap dgapix);
+extern int		dgai_pix_bitsperpixel (_Dga_pixmap dgapix);
+extern int		dgai_pix_clipchg (_Dga_pixmap dgapix);
+extern void		dgai_pix_bbox(_Dga_pixmap dgapix, int *xp, int *yp, 
+					  int *widthp, int *heightp);
+extern int		dgai_pix_empty (_Dga_pixmap dgapix);
+extern short *		dgai_pix_clipinfo (_Dga_pixmap dgapix);
+
+#endif /* _DGA_INTERNAL_H */
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/lib/libdga/sun-src/dga_internaldefs.h	Fri Nov 13 13:30:43 2009 -0800
@@ -0,0 +1,121 @@
+/* Copyright 1994 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ *
+ * 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, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * 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
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR 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.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+#pragma ident	"@(#)dga_internaldefs.h	35.3	09/11/09 SMI"
+
+#ifndef	_DGA_INTERNALDEFS_H
+#define	_DGA_INTERNALDEFS_H
+
+#include "dga_externaldefs.h"
+/*
+** Defined symbols and macros used internally within DGA
+*/
+
+#define DGA_MBFLIP_VIDEO		0
+#define DGA_MBFLIP_COPY			1
+
+/* Basic changes - attribute changes */
+#define DGA_CHANGE_CLIP		(1L<<0)
+#define DGA_CHANGE_CURSOR	(1L<<1)
+#define DGA_CHANGE_BSTORE	(1L<<2)
+#define DGA_CHANGE_CACHE	(1L<<3)
+#define DGA_CHANGE_ZOMBIE	(1L<<4)
+
+/* Basic changes - "major boundary" changes */
+#define DGA_CHANGE_MBUFSET	(1L<<5)
+#define DGA_CHANGE_ALIAS	(1L<<6)
+
+/* Always a derivative change */
+#define DGA_CHANGE_SITE		(1L<<7)
+
+/* Device dependent information change */
+#define DGA_CHANGE_DEVINFO      (1L<<8)
+
+/* Overlay state information change */
+#define DGA_CHANGE_OVLSTATE	(1L<<9)
+
+#define DGA_WIN_CHANGEABLE_ATTRS \
+    (DGA_CHANGE_CLIP | DGA_CHANGE_CURSOR | DGA_CHANGE_BSTORE)
+
+/* note: bstore needs to be included because prev lock subject could have
+   been a win with bstore and vmbufs never have bstore */
+#define DGA_VMBUF_CHANGEABLE_ATTRS \
+    (DGA_CHANGE_CLIP |  DGA_CHANGE_CURSOR | DGA_CHANGE_BSTORE)
+
+/* note: bstore needs to be included because prev lock subject could have
+   been a win with bstore and nmbufs never have bstore */
+#define DGA_NMBUF_CHANGEABLE_ATTRS \
+    (DGA_CHANGE_CLIP |  DGA_CHANGE_CURSOR | DGA_CHANGE_BSTORE | DGA_CHANGE_CACHE)
+
+#define DGA_LOCKSUBJ_INVALID	(-2)
+
+#define DGA_LOCKSUBJ_VALID(dgawin, lockSubj) \
+    ((lockSubj) != DGA_LOCKSUBJ_INVALID)
+
+#define DGA_MBUFFER_MASK(bufIndex) \
+    (1L<<(bufIndex))
+
+/* lock subject is a window? */
+#define DGA_LOCKSUBJ_WINDOW(dgawin, lockSubj) \
+    ((lockSubj) == -1)
+
+/* lock subject is a multibuffer? */
+#define DGA_LOCKSUBJ_MBUFFER(dgawin, lockSubj) \
+    (!DGA_LOCKSUBJ_WINDOW((dgawin), (lockSubj)) && \
+     DGA_LOCKSUBJ_VALID((dgawin), (lockSubj)))
+
+/* lock subject is a viewable multibuffer? */
+#define DGA_LOCKSUBJ_VMBUFFER(dgawin, lockSubj) \
+    (DGA_LOCKSUBJ_MBUFFER((dgawin), (lockSubj)) \
+         ? DGA_MBUF_ISVIEWABLE((dgawin)->pMbs, (lockSubj)) \
+         : 0) \
+
+/* effective lock subject is a nonviewable multibuffer? */
+#define DGA_LOCKSUBJ_NMBUFFER(dgawin, lockSubj) \
+    (DGA_LOCKSUBJ_MBUFFER((dgawin), (lockSubj)) \
+         ? !DGA_LOCKSUBJ_VMBUFFER((dgawin), (lockSubj)) \
+         : 0) \
+
+/* is lock subject viewable? (zombies are considered not viewable) */
+#define DGA_LOCKSUBJ_VIEWABLE(dgawin, lockSubj) \
+     ( !((dgawin)->changeMask & DGA_CHANGE_ZOMBIE) && \
+       ((lockSubj) != DGA_LOCKSUBJ_INVALID) && \
+       ( (DGA_LOCKSUBJ_WINDOW((dgawin), (lockSubj))) || \
+         (DGA_MBUF_ISVIEWABLE((dgawin)->pMbs, (lockSubj))) \
+       ) \
+     )
+
+/* is window or mbuffer aliased? */
+#define DGA_MBSMEMB_ALIASED(dgawin) \
+    ((dgawin)->eLockSubj != (dgawin)->rLockSubj)
+
+#define DGA_MBUF_ISVIEWABLE(pMbs, bufIndex) \
+    (!((pMbs)->pNbShinfo[(bufIndex)]))
+
+#endif /* _DGA_INTERNALDEFS_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/lib/libdga/sun-src/dga_pixshared.h	Fri Nov 13 13:30:43 2009 -0800
@@ -0,0 +1,116 @@
+/* Copyright 1998 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ *
+ * 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, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * 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
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR 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.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+#pragma ident	"@(#)dga_pixshared.h	1.4	09/11/09 SMI"
+
+#ifndef _DGA_PIXSHARED_H
+#define _DGA_PIXSHARED_H
+
+/*
+ * dga_pixshared.h - Sun Direct Graphics Access shared page include file.
+ */
+
+/* Below is the definition of the pixmap shared page structure plus all
+ * the other misc. definitions and structures that are used in both the
+ * server and dga client library.
+ *
+ *  Shared Pixmap Information.  This structure contains the information
+ *  necessary to allow the server and client to share access to a DGA
+ *  pixmap .  This information is located in the first page of
+ *  the shared memory created by the server in response to a call to
+ *  XDgaGrabPixmap().  The server communicates the current state
+ *  of the shared pixmap to the client through the fields within
+ *  this structure.
+ */
+
+typedef u_int *PX_LOCKP_T;
+
+#define PXMPMAGIC 0x50584D50 /* "PXMP"=0x50584D50 */
+#define PXMPVERS        0       /* Current version number */
+
+typedef struct shpx_entry_0 {
+    u_int s_fd;           /* server's file descriptor */
+    u_int offset;         /* offset to first pixmap info struct*/
+    u_int s_size;         /* current total file size */
+} SHPX_ENTRY_0;
+
+typedef struct shpx_entry_1 {
+    int   s_num_shpx;     /* current number of shared pixmaps */
+    u_int s_dir_seq;      /* server's shpx directory change cnt*/
+    u_int s_next_offset;  /* server's next avail offset */
+} SHPX_ENTRY_1;
+
+typedef struct shpx_entry {
+    u_int xid;            /* xid of shared pixmap */
+    u_int offset;         /* offset to info struct */
+    u_int size;           /* total size of this pixmap */
+} SHPX_ENTRY;
+
+typedef union shpx_directory {
+    SHPX_ENTRY_0 shpx_entry_0;
+    SHPX_ENTRY_1 shpx_entry_1;
+    SHPX_ENTRY shpx_entry;
+} SHPX_DIRECTORY;
+
+typedef struct shared_pixmap_info {
+    u_int   magic;        /* magic number, "PXMP"=0x50584D50 */
+    u_char  version;      /* version, currently 0 */
+    u_char  obsolete;     /* pixmap info obsolete flag */
+    u_char  device;       /* device type identifier from fbio.h ???*/
+    u_char  cached;       /* 1 = pixels cached on hw; 0 = pixels in mem */
+    u_int   s_cacheseq;   /* server's cache sequence count */
+    u_int   s_modified;   /* server has changed this data struct*/
+    u_int   data_offset;  /* offset to pixel data */
+    u_int   device_offset;      /* offset to device specific section */
+    short   width;        /* pixmap width */
+    short   height;       /* pixmap height */
+    u_int   linebytes;    /* bytes per scanline */
+    u_char  depth;        /* pixmap depth */
+    u_char  bitsperpixel;   /* pixmap bitsPerPixel */
+    u_char  pad1[2];        /* Unused pad area */
+    u_int   s_fd;         /* server's file descriptor */
+    u_int   s_size;       /* server's size of pixel array */
+    u_int   s_dir_index;  /* server's shpx directory index */
+    SHPX_DIRECTORY  *s_shpx_dir;    /* server's pointer to shpx dir */
+    u_char  *s_pixels;    /* server shared pixel memory pointer*/
+    u_char  scr_name[32]; /* screen name for cached pixmap */
+    u_char  fn[256];      /* Shared file name */
+    u_int   p_refcnt;     /* for nested locking */
+    PX_LOCKP_T   p_lockp;       /* pointer to lockpage */
+    PX_LOCKP_T   p_unlockp;     /* pointer to unlockpage */
+    uint32_t  p_cookie;        /* "cookie" for lock pages */
+    int     locktype;       /* type of locking */
+    u_int   s_devinfoseq;   /* indicates change to dev_info */
+    /* DO NOT ADD ANYTHING BELOW dev_info  - if you need to any any
+     * thing, do so after this line and above dev_info
+    */
+    char dev_info[32];    /* device specific information */
+} SHARED_PIXMAP_INFO;
+
+#endif /* _DGA_PIXSHARED_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/lib/libdga/sun-src/dga_rtnshared.h	Fri Nov 13 13:30:43 2009 -0800
@@ -0,0 +1,111 @@
+/* Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ *
+ * 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, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * 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
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR 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.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+#pragma ident	"@(#)dga_rtnshared.h	1.3	09/11/09 SMI"
+
+#ifndef _DGA_RTNSHARED_H
+#define _DGA_RTNSHARED_H
+
+/*
+ * dga_rtnshared.h - Sun Direct Graphics Access shared page include file.
+ */
+
+/*
+ *  These structures and definitions are for the DGA
+ *  shared memory retained window grabber.
+ *
+ *  Note: It is intended that grabbed retained windows are used in
+ *        conjunction with grabbbed visible windows.  Therefore the
+ *        visible window must be grabbed prior to grabbing the
+ *        retained window.  The client then accesses the retained
+ *        window structures indirectly through the dga_window
+ *        structure defined for the associated grabbed visible
+ *        window.
+ */
+#define RTN_MAGIC       0x52544E44      /* "RTND" = 0x52544E44 */
+#define RTN_VERS        0               /* Current version number */
+#define RTN_FILE        "/shrtndm"      /* Shared info file base name.  Full  */
+                                        /* name is base name + port # + '.'  */
+                                        /* + window id */
+#define RTN_MAXPATH     237             /* 237 = Allocated size (256) - the  */
+                                        /* length of the filename (18) - 1   */
+                                        /* for the null character */
+#define RTN_FAILED      0               /* Value returned from rtn funcs */
+                                        /* upon failure */
+#define RTN_PASSED      -1              /* Value returned from rtn funcs */
+                                        /* upon success */
+#define RTN_GRABBED     1               /* Flag that signifies that the */
+                                        /* window is shared retained */
+#define RTN_MAPPED      2               /* Flag that signifies that the */
+                                        /* shared retained window is mapped  */
+#define RTN_MAPCHG      4               /* Flag that signifies that the */
+                                        /* shared info has gone from mapped  */
+                                        /* to unmapped.  */
+/*
+ *  Shared Retained Information.  This structure contains the information
+ *  necessary to allow the server and client to share access to a DGA
+ *  retained window.  This information is located in the first page of
+ *  the shared memory created by the server in response to a call to
+ *  XDgaGrabRetainedWindow().  The server communicates the current state
+ *  of the shared retained raster to the client through the fields within
+ *  this structure.
+ */
+
+typedef struct shared_retained_info
+{
+    u_int       magic;                  /* magic number, "RTND"=0x52544E44   */
+    u_char      version;                /* version, currently 0 */
+    u_char      obsolete;               /* file obsolete information flag    */
+    u_char      device;                 /* device type identifier from fbio.h*/
+    u_char      cached;                 /* pixels currently cached on device */
+    u_int       s_cacheseq;             /* server's cache sequence count */
+    u_int       s_modified;             /*server has changed this data struct*/
+    u_char      *s_wxlink;              /* server's link to WXINFO struct    */
+    u_int       first_mmap_offset;      /* mmap offset to next file section  */
+    u_int       device_offset;          /* offset to device specific section */
+    short       width;                  /* raster width */
+    short       height;                 /* raster height */
+    u_int       linebytes;              /* bytes per scanline */
+    int         s_fd;                   /* server's file descriptor */
+    u_int       s_size;                 /* server size of pixel array */
+    u_char      *s_pixels;              /* server shared pixel memory pointer*/
+    u_char      fn[256];                /* shared file name */
+    u_char      scr_name[32];           /* screen name for cached rasters    */
+    int         c_fd;                   /* client's file descriptor */
+    u_int       c_size;                 /* client size of pixel array */
+    u_char      *c_pixels;              /* client shared pixel memory pointer*/
+    u_int       c_modified;             /* client noticed server mods */
+    u_int       c_cacheseq;             /* client noticed server cache mods  */
+    u_char      bitsperpixel;           /* bits per pixel */
+    u_char      pad1[155];              /* unused pad area up to 512 bytes   */
+    u_char      dev_info[32];            /* device specific information */
+} SHARED_RETAINED_INFO;
+
+
+#endif /* _DGA_RTNSHARED_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/lib/libdga/sun-src/dga_winshared.h	Fri Nov 13 13:30:43 2009 -0800
@@ -0,0 +1,675 @@
+/* Copyright 1998 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ *
+ * 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, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * 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
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR 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.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+#pragma ident	"@(#)dga_winshared.h	1.16	09/11/09 SMI"
+
+/*
+ * dga_winshared.h - Sun Direct Graphics Access shared page include file.
+ */
+
+#ifndef _DGA_WINSHARED_H
+#define _DGA_WINSHARED_H
+
+#include "dga_externaldefs.h"
+#include <sys/int_types.h>
+
+
+
+/* Mbufset Shared Info format */
+typedef struct dga_mbufset_shinfo {
+    unsigned int    mbufseq;        /* incremented on composition or display
+                                     * change */
+    unsigned int    compositionseq; /* incremented on composition change */
+    unsigned char   enabled;        /* nonzero if an mbufset is active */
+    unsigned char   flipMode;       /* 0 = video flip; 1 = copy flip */
+    unsigned char   accessMode;     /* 0 = single addr; 1 = multi addr */
+    unsigned char   siteTypeConst;  /* zero if access mode can change */
+    uint32_t		bufViewableFlags; /* bit n is 1 if buf n is viewable */
+    unsigned int    nmbufShpxToken; /* token for shared pixmap file nonviewable
+                                     * multibuf */
+    XID             nmbufIds[DGA_MAX_GRABBABLE_BUFS];   /* XID's of nonviewable
+                                                         * mbufs */
+#if !defined(_LP64) && !defined(_I32LPX)
+	int				pad_bufIds[DGA_MAX_GRABBABLE_BUFS];
+#endif
+} DgaMbufSetShinfo, *DgaMbufSetShinfoPtr;
+
+
+/*
+ * This portion of the file file describes the shared memory info page 
+ * used by the window
+ * grabber.  Many of the structures are shapes specific, and their
+ * definitions are copied from shapes #include files.  If the shapes
+ * structures are changed, then this file would be messed up; but
+ * if that happens, a lot of other things would get messed up too, so
+ * let's hope that it never happens.
+ *
+ * This structure is defined in such a way as to allow expansion.  In
+ * particular, the field 'w_clipoff' contains the offset, in bytes, of
+ * the clip data relative to the start of the window information area.
+ * Do not attempt to refer directly to the 'w_shape_hdr' element of
+ * this structure, as that can cause old executables to break with new
+ * servers.
+ *
+ * Here is a brief description of the WXINFO structure elements
+ * which are relavent to the client:
+ *
+ *      w_flag          set to WMODIF by the server whenever any field
+ *                      in the window info area is changed.  Set back to
+ *                      WSEEN by the client once the info has been read.
+ *                      The window-info area should be locked while examining
+ *                      this flag and copying information from the
+ *                      window-info area.
+ *      w_magic         Set to 0x47524142 ("GRAB").
+ *      w_version       version of window-info area.  This header file
+ *                      currently describes version 1.  Programs should
+ *                      check the version number and either refuse to run
+ *                      with older versions or at least be careful not to
+ *                      use fields not defined in older versions.  The
+ *                      comments in the WXINFO structure definition will
+ *                      show you which these are.
+ *      w_devname       Ascii device name.  Let's hope there's never a
+ *                      framebuffer with a filename larger than 20 characters.
+ *      w_cinfofd       File descriptor of wininfo file.  This file has
+ *                      been mmap'ed, so there is no reason for the
+ *                      application to need to use this.
+ *      w_cdevfd        File descriptor of the framebuffer named in w_devname.
+ *      w_crefcnt       Lock count for nested locking.
+ *      w_cookie        Internal use only.  NOT related to the window cookie
+ *                      that was returned by X_GrabWindow().
+ *      w_clockp        pointer to lockpage, used by wx_lock().
+ *      w_clipoff       Byte offset from start of info page to start of
+ *                      clip list.
+ *      w_clipsize      size of cliplist.
+ *      w_org, w_dim    window dimensions, i.e. bounding box of whole window
+ *                      In 16-bit signed fract format.
+ *      w_shape         cliplist info
+ *      w_depth         depth of window
+ *      w_borderwidth   server's idea of the window's bw. This need not be
+ *                      equal to what the client requested since
+ *                      something like OLWM could override the client
+ *                      request and the clinet now has wrong bw.
+ *
+ * Interpreting the clip info:
+ *
+ *  The client is interested in the following structures:
+ *    w_shape_hdr       pointed to via the wx_clipinfo macro.
+ *    w_shape           contains flags and a bounding-box for the cliplist.
+ *    cliparray         follows w_shape.  Contains the clip list.
+ *
+ *  w_shape.SHAPE_FLAGS contains flags that describe the cliplist.  If
+ *  DGA_SH_EMPTY_FLAG is set, then the clip list is empty (window obscured or
+ *  something).
+ *
+ *  If DGA_SH_RECT_FLAG is set, the clip list is a single rectangle
+ *  described by w_shape->SHAPE_{XMIN,YMIN,XMAX,YMAX}.
+ *
+ *  For non-empty cliplists, use the dga_win_clipinfo(win) routine to get
+ *  a pointer to the cliplist.
+ *
+ *  "Normal" cliplists are a sequence of signed shorts which describes
+ *  a sequence of rectangles.  The data consists of a sequence of one
+ *  or more ymin,ymax pairs, each of which is followed by a sequence of
+ *  one or more xmin,xmax pairs.  xmin,xmax sequences are terminated by
+ *  a single value of DGA_X_EOL.  ymin,ymax sequences are terminated by a
+ *  single value of DGA_Y_EOL.  This is best described with some sample
+ *  code:
+ *
+ *      short x0,y0,x1,y1;
+ *
+ *      ptr = dga_win_clipinfo(win);
+ *      while( (y0=*ptr++) != DGA_Y_EOL )
+ *      {
+ *        y1 = *ptr++;
+ *        while( (x0=*ptr++) != DGA_X_EOL )
+ *        {
+ *          x1 = *ptr++;
+ *          printf("rectangle from (%d,%d) to (%d,%d)\n",x0,y0,x1-1,y1-1);
+ *        }
+ *      }
+ *
+ *  Note that the xmax, ymax values are actually one pixel too high.  This
+ *  may be a bug or a feature, I don't know.
+ *
+ */
+
+#define DGA_DB_DEV_INFO_SZ  132
+
+#if !defined (WMODIF)               /* cliplist flag, one of: */
+#define WMODIF      1               /* server has set a new cliplist */
+#define WEXTEND     2               /* extended cliplist present    */
+#define WXMAGIC     0x47524142      /* "GRAB" */
+#endif  /* WMODIF */
+
+#define WX_PAGESZ   (8*1024)
+
+
+typedef struct {
+    unsigned int    t;
+    int             x, y;
+} POINT_B2D;
+
+
+typedef struct {
+    short   x, y;
+} Dga_coord_2d;
+
+
+#if !defined (_SH_CLASS)
+#if defined(_LP64) || defined(_I32LPX)
+typedef int OBJID;
+typedef OBJID   CLASS_OPER;
+#else
+typedef void    *OBJID;
+typedef OBJID   (*CLASS_OPER)();
+#endif
+
+
+typedef struct {
+    unsigned char   type;
+    unsigned char   id;
+} CLASS;
+
+
+struct  obj_hdr {
+    unsigned int    obj_flags :  8;
+    unsigned int    obj_size  : 24;
+    CLASS           obj_class;
+    unsigned short  obj_use;
+    CLASS_OPER     *obj_func;
+#if !defined(_LP64) && !defined(_I32LPX)
+	int32_t        pad_func;
+#endif
+};
+#endif  /* _SH_CLASS */
+
+
+#if !defined (_SH_SHAPE_INT)
+struct  class_SHAPE_vn {
+    unsigned char   SHAPE_FLAGS;
+    unsigned char   SHAPE_SIZE;     /* new with 1.1 */
+    short           SHAPE_YMIN;
+    short           SHAPE_YMAX;
+    short           SHAPE_XMIN;
+    short           SHAPE_XMAX;
+    short           SHAPE_X_EOL;
+#if 0
+#if !defined(_LP64) && !defined(_I32LPX)
+	char 			pad_to_y_eol[2];
+#endif
+#endif
+    union {
+        short   SHAPE_Y_EOL;
+        OBJID   obj;                /* new with 1.1 */
+    } u;
+#if 0
+#if !defined(_LP64) && !defined(_I32LPX)
+	int32_t        pad_obj;
+#endif
+#endif
+
+#define shape_obj           u.obj
+#define shape_xeol          SHAPE_X_EOL
+#define shape_yeol          u.SHAPE_Y_EOL
+#define SHAPE_RECT_SIZE     (6 * sizeof (short))
+#define SHAPE_NO_SIZE       0xFF
+};
+ 
+struct  class_SHAPE_v0 {
+    unsigned char   SHAPE_FLAGS;
+    short           SHAPE_YMIN;
+    short           SHAPE_YMAX;
+    short           SHAPE_XMIN;
+    short           SHAPE_XMAX;
+    short           SHAPE_X_EOL;
+    short           SHAPE_Y_EOL;
+};
+#endif  /*_SH_SHAPE_INT*/
+
+
+/* Cursor Grabber defines and structures */
+
+#define DGA_CURSOR_DOWN     0
+#define DGA_CURSOR_UP       1
+#define DGA_CURG_MAGIC      0x43555247
+
+
+typedef struct dga_curs_mpr {
+    u_int           curg_linebytes;
+    Dga_coord_2d    curg_dim;
+    u_char          curg_depth;
+    /* image data floats under here */
+} Dga_curs_mpr;
+
+
+typedef struct dga_cursinfo
+{
+    u_int           c_magic;        /* magic no, "CURG"=0x43555247 */
+    u_int           c_filesuffix;   /* to derive cursor grabber filename */
+    uint32_t		c_pad;          /* No longer used */
+    int             c_scurgfd;      /* file descriptor for server */
+    int             c_ref_cnt;      /* total number of cur-grabbers*/
+    int             c_state_flag;   /* client/server can set this */
+    u_int           c_chng_cnt;     /* Change count */
+    int             c_index;        /* entry no. in global array */
+    Dga_coord_2d    c_org;          /* top left */
+    Dga_coord_2d    c_hot_spot;     /* why bother with this? */
+    int             c_offset;       /* offset in bytes from top of
+                                     * page to save_under info */
+    Dga_curs_mpr    *c_sptr;        /* server's ptr to save_unders*/
+    u_int           c_cookie;       /* "cookie" for lock pages */
+#if defined(_LP64) || defined(_I32LPX)
+    void*           c_slockp;       /* all windows on this screen use */
+    void*           c_sunlockp;     /* the same lock context */
+#else
+    void*           c_slockp;       /* all windows on this screen use */
+    void*           c_sunlockp;     /* the same lock context */
+#endif
+    int             c_locktype;
+    int             c_smemsize;     /* number of bytes for saved cursor */
+ 
+    /*
+     * FLOATING INFO STARTS HERE, CLIENT DO NOT
+     * REFER DIRECTLY TO ANYTHING BELOW THIS LINE.
+     */
+ 
+    Dga_curs_mpr    c_saved_under;  /* this gets puts back up */
+
+} Dga_cursinfo;
+
+
+typedef struct wx_dbinfo {
+        short   number_buffers;
+        short   read_buffer;
+        short   write_buffer;
+        short   display_buffer;
+        u_int   reserved_1;
+        u_int   reserved_2;
+        u_int   reserved_3;
+        u_int   reserved_4;
+        u_int   reserved_5;
+        u_int   WID;            /* Mpg window id. */
+        u_int   UNIQUE;
+        u_char  device_info[DGA_DB_DEV_INFO_SZ];
+} DBINFO;
+
+/* Ancillary Buffers ... */
+#ifndef True
+#define True  1
+#define False 0
+#endif
+
+#ifndef DGA_NUM_BUFFER_TYPES
+/* The following buffer types also defined(duplicated) in dga.h file.
+ * I can't include dga.h in hw/solaris/dga due to some declarations 
+ * inconsistency.  Whenever someone changes/addes/deleted
+ * to this enumerated values, please also update dga.h which is located
+ * in xc/include/dga/.  Also ddx uses this. 
+ */
+typedef enum {
+   DGA_DEPTH_BUFFER = 0,
+   DGA_STENCIL_BUFFER,
+   DGA_ACCUM_BUFFER,
+   DGA_ALPHA_BUFFER,
+   DGA_BACK_BUFFER,
+   DGA_AUX_BUFFER0,
+   DGA_AUX_BUFFER1,
+   DGA_AUX_BUFFER2,
+   DGA_AUX_BUFFER3
+} Dga_buffer_type;
+ 
+#define DGA_NUM_BUFFER_TYPES (DGA_AUX_BUFFER3+1)
+#endif
+ 
+/* dga_buffer:  This structure will contain pDraw pointer and
+ * buffer_site as his first two members, since all the buffer
+ * API's type case the pointer to dga_buffer and dereference
+ * the buffer_site value.
+ *   pDraw        ->  Will be assigned at the client side.
+ *   buffer_site  ->  Software Buffers - DGA_SITE_SYSTEM
+ *                    Hardware Buffers - DGA_SITE_DEVICE 
+ *   fn           ->  shared of file name of the specified buffer.
+ *   buffer_type  ->  Type of the buffer.
+ *   sitechg      ->  Initialized to DGA_SITECHG_INITIAL when the
+ *                    buffer is created. When the buffer is getting
+ *                    reallocated, this will have DGA_SITECHG_CACHE.
+ *   bitsPerPixel ->  depth of the buffer 
+ *   bytesPerPixel->  (bitsPerPixel +7) >> 3
+ *   width        ->  buffer width (Window's width)
+ *   height       ->  buffer height (Window's height)
+ *   linebytes    ->  ((bytesPerPixel * width) + 3) & ~3
+ *   b_offset     ->  offset to data member from buffer address 
+ *   allocsize    ->  Shared file size.
+ *   data         ->  Buffer data bits pointer.
+ *   pad	  ->  Padding to make sure it is 64-bit aligned, for now.
+ */
+typedef struct {
+#if defined(_LP64) || defined(_I32LPX)
+    void 				*pDraw;
+#else
+    void*               pDraw;
+	int					pad_pdraw;
+#endif
+    Bool                buffer_site;
+    int                 buffer_type;
+    Bool                sitechg;
+    int                 grab_cnt;
+    u_char              fn[256];
+    int                 width;
+    int                 height;
+    int                 bitsPerPixel;
+    int                 bytesPerPixel;
+    int                 linebytes;
+    int                 b_offset;
+    int                 allocsize;
+#if defined(_LP64) || defined(_I32LPX)
+    uint32_t               data;
+#else
+    void*               data;
+#endif
+    char		pad[4];
+} dga_buffer_rec, * dga_buffer;
+
+
+typedef struct {
+#if defined(_LP64) || defined(_I32LPX)
+    dga_buffer bufferp;
+    void	*pDraw;
+#else
+    dga_buffer bufferp;
+	int			pad_bufferp;
+    void *pDraw;
+	int			pad_pdraw;
+#endif
+    int   buf_size;
+} dga_internal_buffer_rec, *dga_internal_buffer;
+
+
+/* ABINFO:  This structure contains buffer pointers and their
+ * respective filenames.  
+ * s_modified  -> Will be set to "1" when the buffer is resized.
+ * remap_flag  -> This is used across server and client dga implementation
+ * buffer_swap -> swap counter.
+ */
+ 
+typedef struct wx_abinfo {
+    int                 s_modified;
+    u_int               buffer_swap; 
+    int                 width;  /* width & height are used to detect resize */
+    int                 height;
+    u_char              back_fn[256];
+    u_char              depth_fn[256];
+    u_char              stencil_fn[256];
+    u_char              accum_fn[256];
+    u_char              alpha_fn[256];
+#if defined(_LP64) || defined(_I32LPX)
+    dga_buffer          back;
+    dga_buffer          depth;
+    dga_buffer          stencil;
+    dga_buffer          accum;
+    dga_buffer          alpha;
+#else
+    dga_buffer          back;
+	int					pad_1_bufinfo;
+    dga_buffer          depth;
+	int					pad_2_bufinfo;
+    dga_buffer          stencil;
+	int					pad_3_bufinfo;
+    dga_buffer          accum;
+	int					pad_4_bufinfo;
+    dga_buffer          alpha;
+	int					pad_5_bufinfo;
+#endif
+    Bool                extPixmap;
+#if !defined(_LP64) && !defined(_I32LPX)
+	int					pad_pix;
+#endif
+    XID                 tag;
+#if !defined(_LP64) && !defined(_I32LPX)
+	int					pad_tag;
+#endif
+    XID                 vid;
+#if !defined(_LP64) && !defined(_I32LPX)
+	int					pad_vid;
+#endif
+    int                 back_size;
+    int                 depth_size;
+    int                 stencil_size;
+    int                 accum_size;
+    int                 alpha_size;
+} ABINFO;
+
+typedef struct  wx_winfo
+{
+    /* VERSION 0 INFO STARTS HERE */
+
+    uint32_t      w_flag;         /* cliplist flag */
+    int32_t        w_magic;        /* magic number, "GRAB" = 0x47524142 */
+    int32_t        w_version;      /* version, currently 4 */
+#if defined(_LP64) || defined(_I32LPX)
+    uint32_t      w_cunlockp;     /* used to be w_list */
+                                /* points to unlock page */
+#else
+    u_int      *w_cunlockp;     /* used to be w_list */
+                                /* points to unlock page */
+
+#endif
+    /* server info, meaningless to client */
+
+    int         w_sinfofd;      /* fd of wxinfo file */
+    int         w_sdevfd;       /* fd of framebuffer */
+#if defined(_LP64) || defined(_I32LPX)
+    uint32_t      w_slockp;       /* pointer to lockpage */
+#else
+    u_int      *w_slockp;       /* pointer to lockpage */
+#endif
+    int         w_srefcnt;      /* lock count for nested locks */
+
+
+    /* client info */
+
+    char        w_devname[20];  /* framebuffer device name */
+    int         w_cinfofd;      /* fd of wxinfo file */
+    int         w_cdevfd;       /* fd of framebuffer */
+    int         w_crefcnt;      /* lock count for nested locks */
+
+    uint32_t      w_cookie;       /* "cookie" for lock pages */
+    uint32_t      w_filesuffix;   /* "cookie" for info file */
+#if defined(_LP64) || defined(_I32LPX)
+    uint32_t      w_clockp;       /* pointer to lock page */
+#else
+    u_int      *w_clockp;       /* pointer to lock page */
+#endif
+
+
+    /* clipping info */
+
+#if defined(_LP64) || defined(_I32LPX)
+    uint32_t	w_cclipptr;     /* client virtual pointer to clip array. */
+#else
+    short      *w_cclipptr;     /* client virtual pointer to clip array. */
+#endif
+    u_int       w_scliplen;     /* server's size of cliplist in bytes. */
+
+
+    /* shapes stuff */
+    
+    POINT_B2D   w_org;          /* origin of window */
+    POINT_B2D   w_dim;          /* size of window */
+
+
+    /* VERSION 1 INFO STARTS HERE */
+#if !defined(_LP64) && !defined(_I32LPX)
+	char		pad_to_union[4];
+#endif
+
+    union {
+        struct {
+            int32_t    w_clipoff;  /* byte offset from wx_info to w_cliparray. */
+            int32_t    w_shapeoff; /* byte offset from wx_info to w_shape. */
+            u_int   w_clipseq;  /* clip sequence number */
+            int32_t    w_ccliplen; /* client's size of clip list in bytes. */
+#if defined(_LP64) || defined(_I32LPX)
+            uint32_t    w_sclipptr; /* server's pointer to clip array */
+#else
+            int    *w_sclipptr; /* server's pointer to clip array */
+#endif
+        } vn;
+        struct {
+            struct  obj_hdr         w_shape_hdr;    /* not useful to client */
+            struct  class_SHAPE_v0  w_shape;
+            short                   w_cliparray;
+        } v0;
+    } u;
+
+    /* VERSION 2 INFO STARTS HERE */
+
+    /* cursor grabber info */
+
+    u_int       c_filesuffix;   /* to derive shared cursor filename */
+#if defined(_LP64) || defined(_I32LPX)
+    uint32_t	c_sinfo;      /* pointer to server's cursor info */
+    uint32_t	c_pad1;         /* obsolete */
+#else
+    Dga_cursinfo *c_sinfo;      /* pointer to server's cursor info */
+    void       *c_pad1;         /* obsolete */
+#endif
+    int         c_pad2;         /* obsolete */
+
+    /* wid info */
+
+    struct {
+        short   number_wids;    /* number of contiguous wids alloc */
+        short   start_wid;      /* starting wid */
+        short   wid;            /* current wid */
+        short   reserved_1;     /* for the future */
+    } w_wid_info;               /* WID info structure */
+
+    /* integer version of window bounds */
+
+    struct {
+        int     xleft, ytop;    /* upper-left corner, in pixels */
+        int     width, height;  /* dimensions, in pixels */
+    } w_window_boundary;
+
+
+    /* db info */
+
+    struct      wx_dbinfo wx_dbuf;  /* double buffer info structure */
+
+    int         w_auxdevfd;         /* Aux fd for asynch devices */
+    char        w_auxdevname[20];   /* Asynch device name */
+    short       w_auxdevid;         /* ID number for aux dev type */
+    short       w_auxserveronly;    /* To keep SERVER_ONLY's in sync */
+#if defined(_LP64) || defined(_I32LPX)
+    uint32_t      w_sunlockp;         /* pointer to unlockpage */
+#else
+    u_int      *w_sunlockp;         /* pointer to unlockpage */
+#endif
+    int         w_extnd_seq;        /* cliplist extension counter */
+    int         w_clientcnt;        /* # of clients using new protocol */
+    int         w_oldproto;         /* client used old protocol */
+    int         w_locktype;         /* what type of locking */
+
+#if defined(_LP64) || defined(_I32LPX)
+    uint32_t	wdev;               /* pointer to server-internal data  */
+    uint32_t	w_srtndlink;        /* server's retained struct pointer */
+#else
+    void       *wdev;               /* pointer to server-internal data  */
+    char       *w_srtndlink;        /* server's retained struct pointer */
+#endif
+    u_int       w_chng_cnt;         /* bumped when anything changes */
+
+
+    /* VERSION 3 INFO STARTS HERE */
+
+    u_char      w_depth;            /* Window depth */
+    u_char      pad[1];             /* Padding for int alignment */
+    u_short     w_borderwidth;      /* Actual bw of the window */
+    float       w_refresh_period;   /* monitor refresh period- millisec */
+#if !defined(_LP64) && !defined(_I32LPX)
+	char pad_rfresh[4];
+#endif
+ 
+    /*
+     * Attributes of multibuffer set
+     *
+     * Note: the number of buffers in an mbuf set is specified by
+     * wx_dbuf.number_buffers.
+     */
+
+    DgaMbufSetShinfo    w_mbsInfo;  /*info for multibuf set (if win is mbuf) */
+#if !defined(_LP64) && !defined(_I32LPX)
+	char pad_mbsinfo[4];
+#endif
+    u_int       w_devinfoseq;       /*devinfo seq. # in the Dga_dbinfo struct.*/
+    int         w_obsolete;         /* 0 when shinfo no longer is valid */
+    int         w_visibility;       /* visibility of window. */
+
+    /* VERSION 4 INFO STARTS HERE */
+
+    Bool        w_ovlshapevalid;    /* client will clear this when locking */
+                                    /* so the server knows to recalculate */
+                                    /* the overlay's opaque shape */
+    int         w_ovlstate;         /* conflict mode of an overlay, one of: */
+                                    /* MPG_NONE => DGA_OVLSTATE_SAFE     */
+                                    /* MPG_SAFE => DGA_OVLSTATE_SAFE     */
+                                    /* MPG_SOFT => DGA_OVLSTATE_MULTIWID */
+                                    /* MPG_HARD => DGA_OVLSTATE_CONFLICT */
+
+    /* VERSION 5 INFO STARTS HERE */
+#if !defined(_LP64) && !defined(_I32LPX)
+	char pad_ovlstate[4];
+#endif
+ 
+    struct      wx_abinfo wx_abuf;  /* Ancillay Buffers info structure */
+#if !defined(_LP64) && !defined(_I32LPX)
+	char pad_szinfo[4];
+#endif
+	int 					info_sz;
+ 
+  /*
+   * FLOATING INFO STARTS HERE, DO NOT REFER
+   * DIRECTLY TO ANYTHING BELOW THIS LINE.
+   */
+#if 0
+#if !defined(_LP64) && !defined(_I32LPX)
+	char pad_abinfo[4];
+#endif
+#endif
+
+    struct class_SHAPE_vn   w_shape;
+    short                   w_cliparray;
+ 
+} WXINFO;
+
+#define WG_LOCKDEV      0       /* use GRABPAGEALLOC from fb */
+#define WG_WINLOCK      1       /* use winlock functions */
+
+#endif  /* _DGA_WINSHARED_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/lib/libdga/sun-src/draw_db.c	Fri Nov 13 13:30:43 2009 -0800
@@ -0,0 +1,272 @@
+/* Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ *
+ * 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, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * 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
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR 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.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+#pragma ident	"@(#)draw_db.c	35.2	09/11/09 SMI"
+
+/* 
+** draw_db.c - Drawable veneer for DGA window buffer control routines
+*/
+
+#ifdef SERVER_DGA
+#include <X11/Xlib.h>
+#endif  /* SERVER_DGA */
+#include "dga_incls.h"
+
+int
+dga_draw_db_grab (Dga_drawable dgadraw, int nbuffers, 
+		  int (*vrtfunc)(Dga_drawable), u_int *vrtcounterp)
+{
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW: {
+	_Dga_window dgawin = (_Dga_window)dgadraw;
+	if (!DGA_LOCKSUBJ_WINDOW(dgawin, dgawin->eLockSubj)) {
+	    return (0);
+	}
+	return (dga_db_grab((Dga_window)dgawin, nbuffers, vrtfunc, vrtcounterp));
+    }
+    case DGA_DRAW_PIXMAP:
+	return (0);
+    }
+}
+
+int
+dga_draw_db_ungrab (Dga_drawable dgadraw)
+{
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW: {
+	_Dga_window dgawin = (_Dga_window)dgadraw;
+	if (!DGA_LOCKSUBJ_WINDOW(dgawin, dgawin->eLockSubj)) {
+	    return (0);
+	}
+	return (dga_db_ungrab((Dga_window)dgawin));
+    }
+    case DGA_DRAW_PIXMAP:
+	return (0);
+    }
+}
+
+void
+dga_draw_db_write (Dga_drawable dgadraw, int buffer,
+		   int (*writefunc)(void*, Dga_drawable, int), 
+		   void *data)
+{
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW: {
+	_Dga_window dgawin = (_Dga_window)dgadraw;
+	if (!DGA_LOCKSUBJ_WINDOW(dgawin, dgawin->eLockSubj)) {
+	    break;
+	}
+	dga_db_write((Dga_window)dgawin, buffer, writefunc, data);
+	break;
+    }
+    case DGA_DRAW_PIXMAP:
+	break;
+    }
+}
+
+void
+dga_draw_db_read (Dga_drawable dgadraw, int buffer,
+		  int (*readfunc)(void*, Dga_drawable, int), 
+		  void *data)
+{
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW: {
+	_Dga_window dgawin = (_Dga_window)dgadraw;
+	if (!DGA_LOCKSUBJ_WINDOW(dgawin, dgawin->eLockSubj)) {
+	    break;
+	}
+	dga_db_read((Dga_window)dgawin, buffer, readfunc, data);
+	break;
+    }
+    case DGA_DRAW_PIXMAP:
+	break;
+    }
+}
+
+void
+dga_draw_db_display (Dga_drawable dgadraw, int buffer,
+		    int (*visfunc)(void*, Dga_drawable, int), 
+		     void *data)
+{
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW: {
+	_Dga_window dgawin = (_Dga_window)dgadraw;
+	if (!DGA_LOCKSUBJ_WINDOW(dgawin, dgawin->eLockSubj)) {
+	    break;
+	}
+	dga_db_display((Dga_window)dgawin, buffer, visfunc, data);
+	break;
+    }
+    case DGA_DRAW_PIXMAP:
+	break;
+    }
+}
+
+void
+dga_draw_db_interval (Dga_drawable dgadraw, int interval)
+{
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW: {
+	_Dga_window dgawin = (_Dga_window)dgadraw;
+	if (!DGA_LOCKSUBJ_WINDOW(dgawin, dgawin->eLockSubj)) {
+	    break;
+	}
+	dga_db_interval((Dga_window)dgawin, interval);
+	break;
+    }
+    case DGA_DRAW_PIXMAP:
+	break;
+    }
+}
+
+void
+dga_draw_db_interval_wait (Dga_drawable dgadraw)
+{
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW: {
+	_Dga_window dgawin = (_Dga_window)dgadraw;
+	if (!DGA_LOCKSUBJ_WINDOW(dgawin, dgawin->eLockSubj)) {
+	    break;
+	}
+	dga_db_interval_wait((Dga_window)dgawin);
+	break;
+    }
+    case DGA_DRAW_PIXMAP:
+	break;
+    }
+}
+
+int
+dga_draw_db_interval_check (Dga_drawable dgadraw)
+{
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW: {
+	_Dga_window dgawin = (_Dga_window)dgadraw;
+	if (!DGA_LOCKSUBJ_WINDOW(dgawin, dgawin->eLockSubj)) {
+	    /* not applicable to multibuffers - consider interval always expired */
+	    return (1);
+	}
+	return (dga_db_interval_check((Dga_window)dgawin));
+    }
+    case DGA_DRAW_PIXMAP:
+	/* not applicable to pixmaps - consider interval always expired */
+	return (1);
+    }
+}
+
+int
+dga_draw_db_write_inquire (Dga_drawable dgadraw)
+{
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW: {
+	_Dga_window dgawin = (_Dga_window)dgadraw;
+	if (!DGA_LOCKSUBJ_WINDOW(dgawin, dgawin->eLockSubj)) {
+	    /* not applicable to multibuffers - always return an invalid buffer index */
+	    return (-1);
+	}
+	return (dga_db_write_inquire((Dga_window)dgawin));
+    }
+    case DGA_DRAW_PIXMAP:
+	/* not applicable to pixmaps - always return an invalid buffer index */
+	return (-1);
+    }
+}
+
+int
+dga_draw_db_read_inquire (Dga_drawable dgadraw)
+{
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW: {
+	_Dga_window dgawin = (_Dga_window)dgadraw;
+	if (!DGA_LOCKSUBJ_WINDOW(dgawin, dgawin->eLockSubj)) {
+	    /* not applicable to multibuffers - always return an invalid buffer index */
+	    return (-1);
+	}
+	return (dga_db_read_inquire((Dga_window)dgawin));
+    }
+    case DGA_DRAW_PIXMAP:
+	/* not applicable to pixmaps - always return an invalid buffer index */
+	return (-1);
+    }
+}
+
+int
+dga_draw_db_display_inquire (Dga_drawable dgadraw)
+{
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW: {
+	_Dga_window dgawin = (_Dga_window)dgadraw;
+	if (!DGA_LOCKSUBJ_WINDOW(dgawin, dgawin->eLockSubj)) {
+	    /* not applicable to multibuffers - always return an invalid buffer index */
+	    return (-1);
+	}
+	return (dga_db_display_inquire((Dga_window)dgawin));
+    }
+    case DGA_DRAW_PIXMAP:
+	/* not applicable to pixmaps - always return an invalid buffer index */
+	return (-1);
+    }
+}
+
+int
+dga_draw_db_display_done (Dga_drawable dgadraw, int flag, 
+			  int (*display_done_func)(Dga_drawable))
+{
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW: {
+	_Dga_window dgawin = (_Dga_window)dgadraw;
+	if (!DGA_LOCKSUBJ_WINDOW(dgawin, dgawin->eLockSubj)) {
+	    /* not applicable to multibuffers - consider display done (to prevent hangs) */
+	    return (1);
+	}
+	return (dga_db_display_done((Dga_window)dgawin, flag, display_done_func));
+    }
+    case DGA_DRAW_PIXMAP:
+	/* not applicable to pixmaps - consider display done (to prevent hangs) */
+	return (1);
+    }
+}
+
+Dga_dbinfo *
+dga_draw_db_dbinfop (Dga_drawable dgadraw)
+{
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW: {
+	_Dga_window dgawin = (_Dga_window)dgadraw;
+	if (!DGA_LOCKSUBJ_WINDOW(dgawin, dgawin->eLockSubj)) {
+	    /* not applicable to multibuffers - return NULL */
+	    return (NULL);
+	}
+	return (dga_win_dbinfop((Dga_window)dgawin));
+    }
+    case DGA_DRAW_PIXMAP:
+	/* not applicable to pixmaps - return NULL */
+	return (NULL);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/lib/libdga/sun-src/draw_inquiry.c	Fri Nov 13 13:30:43 2009 -0800
@@ -0,0 +1,960 @@
+/* Copyright 1997 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ *
+ * 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, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * 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
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR 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.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+#pragma ident	"@(#)draw_inquiry.c	35.7	09/11/09 SMI"
+
+/* 
+** draw_inquiry.c - state inquiry routines for drawable veneer.
+*/
+
+#ifdef SERVER_DGA
+#include <X11/Xlib.h>
+#endif /* SERVER_DGA */
+#include "dga_incls.h"
+
+extern int dgai_mbsmemb_devinfochg (_Dga_window dgawin);
+extern int dgai_pix_devinfochg(_Dga_pixmap dgapix);
+
+Display *
+dga_draw_display (Dga_drawable dgadraw)
+{
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	return (dgai_mbsmemb_display((_Dga_window)dgadraw));
+    case DGA_DRAW_PIXMAP:
+	return (dgai_pix_display((_Dga_pixmap)dgadraw));
+    }
+}
+
+Drawable
+dga_draw_id (Dga_drawable dgadraw)
+{
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	return ((Drawable)((_Dga_window)dgadraw)->w_id);
+    case DGA_DRAW_PIXMAP:
+	return ((Drawable)((_Dga_pixmap)dgadraw)->p_id);
+    }
+}
+
+int
+dga_draw_type (Dga_drawable dgadraw)
+{
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	return ((((_Dga_window)dgadraw)->isOverlay)
+		? (DGA_DRAW_OVERLAY)
+		: (DGA_DRAW_WINDOW));
+    case DGA_DRAW_PIXMAP:
+	return (DGA_DRAW_PIXMAP);
+    }
+}
+
+char *
+dga_draw_devname (Dga_drawable dgadraw)
+{
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	return (dgai_mbsmemb_devname((_Dga_window)dgadraw));
+    case DGA_DRAW_PIXMAP:
+	return (dgai_pix_devname((_Dga_pixmap)dgadraw));
+    }
+}
+
+int
+dga_draw_devfd (Dga_drawable dgadraw)
+{
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	return (dgai_mbsmemb_devfd((_Dga_window)dgadraw));
+    case DGA_DRAW_PIXMAP:
+	return (dgai_pix_devfd((_Dga_pixmap)dgadraw));
+    }
+}
+
+int
+dga_draw_depth (Dga_drawable dgadraw)
+{
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	return (dgai_mbsmemb_depth((_Dga_window)dgadraw));
+    case DGA_DRAW_PIXMAP:
+	return (dgai_pix_depth((_Dga_pixmap)dgadraw));
+    }
+}
+
+void
+dga_draw_set_client_infop (Dga_drawable dgadraw, void *client_info_ptr)
+{
+#ifdef MT
+    mutex_lock(&dgaGlobalMutex);
+#endif
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	dgai_mbsmemb_set_client_infop((_Dga_window)dgadraw, client_info_ptr);
+	break;
+    case DGA_DRAW_PIXMAP:
+	dgai_pix_set_client_infop((_Dga_pixmap)dgadraw, client_info_ptr);
+	break;
+    }
+#ifdef MT
+    mutex_unlock(&dgaGlobalMutex);
+#endif
+}
+
+void *
+dga_draw_get_client_infop (Dga_drawable dgadraw)
+{
+    void *rval;
+#ifdef MT
+    mutex_lock(&dgaGlobalMutex);
+#endif
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	rval = dgai_mbsmemb_get_client_infop((_Dga_window)dgadraw);
+	break;
+    case DGA_DRAW_PIXMAP:
+	rval = dgai_pix_get_client_infop((_Dga_pixmap)dgadraw);
+	break;
+    }
+#ifdef MT
+    mutex_unlock(&dgaGlobalMutex);
+#endif
+    return (rval);
+}
+
+int
+dga_draw_devinfochg (Dga_drawable dgadraw)
+{
+    int rval;
+
+#ifdef MT
+    mutex_lock(&dgaGlobalMutex);
+#endif
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	rval = dgai_mbsmemb_devinfochg((_Dga_window)dgadraw);
+	break;
+    case DGA_DRAW_PIXMAP:
+	rval = dgai_pix_devinfochg((_Dga_pixmap)dgadraw);
+	break;
+    }
+#ifdef MT
+    mutex_unlock(&dgaGlobalMutex);
+#endif
+    return (rval);
+}
+
+void *
+dga_draw_devinfo (Dga_drawable dgadraw)
+{
+    void *rval;
+
+#ifdef MT
+    mutex_lock(&dgaGlobalMutex);
+#endif
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	rval = dgai_mbsmemb_devinfo((_Dga_window)dgadraw);
+	break;
+    case DGA_DRAW_PIXMAP:
+	rval = dgai_pix_devinfo((_Dga_pixmap)dgadraw);
+	break;
+    }
+#ifdef MT
+    mutex_unlock(&dgaGlobalMutex);
+#endif
+    return (rval);
+}
+
+int
+dga_draw_sitechg (Dga_drawable dgadraw, int *reason)
+{
+    int rval;
+
+#ifdef MT
+    mutex_lock(&dgaGlobalMutex);
+#endif
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	rval = dgai_mbsmemb_sitechg((_Dga_window)dgadraw, reason);
+	break;
+    case DGA_DRAW_PIXMAP:
+	rval = dgai_pix_sitechg((_Dga_pixmap)dgadraw, reason);
+	break;
+    }
+#ifdef MT
+    mutex_unlock(&dgaGlobalMutex);
+#endif
+    return (rval);
+}
+
+void
+dga_draw_sitesetnotify (Dga_drawable dgadraw, DgaSiteNotifyFunc site_notify_func,
+			   void *client_data)
+{
+#ifdef MT
+    mutex_lock(&dgaGlobalMutex);
+#endif
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	dgai_mbsmemb_sitesetnotify((_Dga_window)dgadraw, site_notify_func, client_data);
+	break;
+    case DGA_DRAW_PIXMAP:
+	dgai_pix_sitesetnotify((_Dga_pixmap)dgadraw, site_notify_func, client_data);
+	break;
+    }
+#ifdef MT
+    mutex_unlock(&dgaGlobalMutex);
+#endif
+}
+
+void
+dga_draw_sitegetnotify (Dga_drawable dgadraw, DgaSiteNotifyFunc *site_notify_func,
+			   void **client_data)
+{
+#ifdef MT
+    mutex_lock(&dgaGlobalMutex);
+#endif
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	dgai_mbsmemb_sitegetnotify((_Dga_window)dgadraw, site_notify_func, client_data);
+	break;
+    case DGA_DRAW_PIXMAP:
+	dgai_pix_sitegetnotify((_Dga_pixmap)dgadraw, site_notify_func, client_data);
+	break;
+    }
+#ifdef MT
+    mutex_unlock(&dgaGlobalMutex);
+#endif
+}
+
+int
+dga_draw_site (Dga_drawable dgadraw)
+{
+    int rval;
+
+#ifdef MT
+    mutex_lock(&dgaGlobalMutex);
+#endif
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	rval = dgai_mbsmemb_site((_Dga_window)dgadraw);
+	break;
+    case DGA_DRAW_PIXMAP:
+	rval = dgai_pix_site((_Dga_pixmap)dgadraw);
+	break;
+    }
+#ifdef MT
+    mutex_unlock(&dgaGlobalMutex);
+#endif
+    return (rval);
+}
+
+void *
+dga_draw_address (Dga_drawable dgadraw)
+{
+    void *rval;
+
+#ifdef MT
+    mutex_lock(&dgaGlobalMutex);
+#endif
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	rval = dgai_mbsmemb_address((_Dga_window)dgadraw);
+	break;
+    case DGA_DRAW_PIXMAP:
+	rval = dgai_pix_address((_Dga_pixmap)dgadraw);
+	break;
+    }
+#ifdef MT
+    mutex_unlock(&dgaGlobalMutex);
+#endif
+    return (rval);
+}
+
+int
+dga_draw_linebytes (Dga_drawable dgadraw)
+{
+    int rval;
+
+#ifdef MT
+    mutex_lock(&dgaGlobalMutex);
+#endif
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	rval = dgai_mbsmemb_linebytes((_Dga_window)dgadraw);
+	break;
+    case DGA_DRAW_PIXMAP:
+	rval = dgai_pix_linebytes((_Dga_pixmap)dgadraw);
+	break;
+    }
+#ifdef MT
+    mutex_unlock(&dgaGlobalMutex);
+#endif
+    return (rval);
+}
+
+int
+dga_draw_bitsperpixel (Dga_drawable dgadraw)
+{
+    int rval;
+
+#ifdef MT
+    mutex_lock(&dgaGlobalMutex);
+#endif
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	rval = dgai_mbsmemb_bitsperpixel((_Dga_window)dgadraw);
+	break;
+    case DGA_DRAW_PIXMAP:
+	rval = dgai_pix_bitsperpixel((_Dga_pixmap)dgadraw);
+	break;
+    }
+#ifdef MT
+    mutex_unlock(&dgaGlobalMutex);
+#endif
+    return (rval);
+}
+
+int
+dga_draw_clipchg (Dga_drawable dgadraw)
+{
+    int rval;
+
+#ifdef MT
+    mutex_lock(&dgaGlobalMutex);
+#endif
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	rval = dgai_mbsmemb_clipchg((_Dga_window)dgadraw);
+	break;
+    case DGA_DRAW_PIXMAP:
+	rval = dgai_pix_clipchg((_Dga_pixmap)dgadraw);
+	break;
+    }
+#ifdef MT
+    mutex_unlock(&dgaGlobalMutex);
+#endif
+    return (rval);
+}
+
+void
+dga_draw_bbox(Dga_drawable dgadraw, int *xp, int *yp, int *widthp, int *heightp)
+{
+#ifdef MT
+    mutex_lock(&dgaGlobalMutex);
+#endif
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	dgai_mbsmemb_bbox((_Dga_window)dgadraw, xp, yp, widthp, heightp);
+	break;
+    case DGA_DRAW_PIXMAP:
+	dgai_pix_bbox((_Dga_pixmap)dgadraw, xp, yp, widthp, heightp);
+	break;
+    }
+#ifdef MT
+    mutex_unlock(&dgaGlobalMutex);
+#endif
+}
+
+int
+dga_draw_visibility (Dga_drawable dgadraw)
+{ 
+    int rval;
+
+#ifdef MT
+    mutex_lock(&dgaGlobalMutex);
+#endif
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	rval = dgai_mbsmemb_visibility((_Dga_window)dgadraw);
+	break;
+    case DGA_DRAW_PIXMAP:
+	/* always unobscured */
+	rval = DGA_VIS_UNOBSCURED;
+	break;
+    }
+#ifdef MT
+    mutex_unlock(&dgaGlobalMutex);
+#endif
+    return (rval);
+}
+
+int
+dga_draw_empty (Dga_drawable dgadraw)
+{ 
+    int rval;
+
+#ifdef MT
+    mutex_lock(&dgaGlobalMutex);
+#endif
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	rval = dgai_mbsmemb_empty((_Dga_window)dgadraw);
+	break;
+    case DGA_DRAW_PIXMAP:
+	rval = dgai_pix_empty((_Dga_pixmap)dgadraw);
+	break;
+    }
+#ifdef MT
+    mutex_unlock(&dgaGlobalMutex);
+#endif
+    return (rval);
+}
+
+short *
+dga_draw_clipinfo (Dga_drawable dgadraw)
+{
+    short *rval;
+
+#ifdef MT
+    mutex_lock(&dgaGlobalMutex);
+#endif
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	rval = dgai_mbsmemb_clipinfo((_Dga_window)dgadraw);
+	break;
+    case DGA_DRAW_PIXMAP:
+	rval = dgai_pix_clipinfo((_Dga_pixmap)dgadraw);
+	break;
+    }
+#ifdef MT
+    mutex_unlock(&dgaGlobalMutex);
+#endif
+    return (rval);
+}
+
+
+int
+dga_draw_singlerect (Dga_drawable dgadraw)
+{
+    int rval;
+
+#ifdef MT
+    mutex_lock(&dgaGlobalMutex);
+#endif
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	rval = dgai_mbsmemb_singlerect((_Dga_window)dgadraw);
+	break;
+    case DGA_DRAW_PIXMAP:
+	/* always a single rect */
+	rval = 1;
+	break;
+    }
+#ifdef MT
+    mutex_unlock(&dgaGlobalMutex);
+#endif
+    return (rval);
+}
+
+int
+dga_draw_obscured (Dga_drawable dgadraw)
+{
+    int rval;
+
+#ifdef MT
+    mutex_lock(&dgaGlobalMutex);
+#endif
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	rval = dgai_mbsmemb_obscured((_Dga_window)dgadraw);
+	break;
+    case DGA_DRAW_PIXMAP:
+	/* never obscured */
+	rval = 0;
+	break;
+    }
+#ifdef MT
+    mutex_unlock(&dgaGlobalMutex);
+#endif
+    return (rval);
+}
+
+
+/* CONSOLIDATION PRIVATE */
+u_short
+dga_draw_borderwidth (Dga_drawable dgadraw) 
+{ 
+    u_short rval;
+
+#ifdef MT
+    mutex_lock(&dgaGlobalMutex);
+#endif
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	rval = dgai_mbsmemb_borderwidth((_Dga_window)dgadraw);
+	break;
+    case DGA_DRAW_PIXMAP:
+	/* always 0 */
+	rval = 0;
+	break;
+    }
+#ifdef MT
+    mutex_unlock(&dgaGlobalMutex);
+#endif
+    return (rval);
+} 
+
+
+void
+dga_draw_curshandle (Dga_drawable dgadraw, DgaCursTakeDownFunc take_down_func,
+		        void *client_data)
+{
+#ifdef MT
+    mutex_lock(&dgaGlobalMutex);
+#endif
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	dgai_mbsmemb_curshandle((_Dga_window)dgadraw, take_down_func, client_data);
+	break;
+    case DGA_DRAW_PIXMAP:
+	/* pixmaps never have cursors */
+	break;
+    }
+#ifdef MT
+    mutex_unlock(&dgaGlobalMutex);
+#endif
+}
+
+
+int		
+dga_draw_rtngrab (Dga_drawable dgadraw)
+{
+    int rval;
+
+#ifdef MT
+    mutex_lock(&dgaGlobalMutex);
+#endif
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	rval = dgai_mbsmemb_rtngrab((_Dga_window)dgadraw);
+	break;
+    case DGA_DRAW_PIXMAP:
+	/* not applicable to pixmaps */
+	rval = 0;
+	break;
+    }
+#ifdef MT
+    mutex_unlock(&dgaGlobalMutex);
+#endif
+    return (rval);
+}
+
+int		
+dga_draw_rtnungrab (Dga_drawable dgadraw)
+{
+    int rval;
+
+#ifdef MT
+    mutex_lock(&dgaGlobalMutex);
+#endif
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	rval = dgai_mbsmemb_rtnungrab((_Dga_window)dgadraw);
+	break;
+    case DGA_DRAW_PIXMAP:
+	/* not applicable to pixmaps */
+	rval = 0;
+	break;
+    }
+#ifdef MT
+    mutex_unlock(&dgaGlobalMutex);
+#endif
+    return (rval);
+}
+
+int		
+dga_draw_rtnchg (Dga_drawable dgadraw)
+{
+    int rval;
+
+#ifdef MT
+    mutex_lock(&dgaGlobalMutex);
+#endif
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	rval = dgai_mbsmemb_rtnchg((_Dga_window)dgadraw);
+	break;
+    case DGA_DRAW_PIXMAP:
+	/* not applicable to pixmaps -- force a query for active */
+	rval = 1;
+	break;
+    }
+#ifdef MT
+    mutex_unlock(&dgaGlobalMutex);
+#endif
+    return (rval);
+}
+
+int		
+dga_draw_rtnactive (Dga_drawable dgadraw)
+{
+    int rval;
+
+#ifdef MT
+    mutex_lock(&dgaGlobalMutex);
+#endif
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	rval = dgai_mbsmemb_rtnactive((_Dga_window)dgadraw);
+	break;
+    case DGA_DRAW_PIXMAP:
+	/* not applicable to pixmaps -- never active */
+	rval = 0;
+	break;
+    }
+#ifdef MT
+    mutex_unlock(&dgaGlobalMutex);
+#endif
+    return (rval);
+}
+
+int		
+dga_draw_rtncached (Dga_drawable dgadraw)
+{
+    int rval;
+
+#ifdef MT
+    mutex_lock(&dgaGlobalMutex);
+#endif
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	rval = dgai_mbsmemb_rtncached((_Dga_window)dgadraw);
+	break;
+    case DGA_DRAW_PIXMAP:
+	/* not applicable to pixmaps -- consider never cached */
+	rval = 0;
+	break;
+    }
+#ifdef MT
+    mutex_unlock(&dgaGlobalMutex);
+#endif
+    return (rval);
+}
+
+void *		
+dga_draw_rtndevinfop (Dga_drawable dgadraw)
+{
+    void *rval;
+
+#ifdef MT
+    mutex_lock(&dgaGlobalMutex);
+#endif
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	rval = dgai_mbsmemb_rtndevinfop((_Dga_window)dgadraw);
+	break;
+    case DGA_DRAW_PIXMAP:
+	/* not applicable to pixmaps -- doesn't have devinfo */
+	rval = NULL;
+	break;
+    }
+#ifdef MT
+    mutex_unlock(&dgaGlobalMutex);
+#endif
+    return (rval);
+}
+
+/* This routine is for compatibility only. In the old interface both
+ * the "p" and the "non-p" version were in but the "p" version was the
+ * one that was documented. */
+void *		
+dga_draw_rtndevinfo (Dga_drawable dgadraw)
+{
+    return(dga_draw_rtndevinfop (dgadraw));
+}
+
+void
+dga_draw_rtndevtype (Dga_drawable dgadraw, u_char *type, 
+		     char **name)
+{
+#ifdef MT
+    mutex_lock(&dgaGlobalMutex);
+#endif
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	dgai_mbsmemb_rtndevtype((_Dga_window)dgadraw, type, name);
+	break;
+    case DGA_DRAW_PIXMAP:
+	/* not applicable to pixmaps -- no dev type and name */
+	*type = (u_char) 0;
+	*name = NULL;
+	break;
+    }
+#ifdef MT
+    mutex_unlock(&dgaGlobalMutex);
+#endif
+}
+
+void
+dga_draw_rtndimensions (Dga_drawable dgadraw, short *width, 
+			short *height, u_int *linebytes)
+{
+#ifdef MT
+    mutex_lock(&dgaGlobalMutex);
+#endif
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	dgai_mbsmemb_rtndimensions((_Dga_window)dgadraw, width, height, linebytes);
+	break;
+    case DGA_DRAW_PIXMAP:
+	/* not applicable to pixmaps -- no dimensions */
+	*width = 0;
+	*height = 0;
+	*linebytes = 0;
+	break;
+    }
+#ifdef MT
+    mutex_unlock(&dgaGlobalMutex);
+#endif
+}
+
+int
+dga_draw_rtnbitsperpixel (Dga_drawable dgadraw)
+{
+    int rval;
+
+#ifdef MT
+    mutex_lock(&dgaGlobalMutex);
+#endif
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	rval = dgai_mbsmemb_rtnbitsperpixel((_Dga_window)dgadraw);
+	break;
+    case DGA_DRAW_PIXMAP:
+	/* not applicable to pixmaps */
+	rval = 0;
+	break;
+    }
+#ifdef MT
+    mutex_unlock(&dgaGlobalMutex);
+#endif
+    return (rval);
+}
+
+void *
+dga_draw_rtnpixels (Dga_drawable dgadraw)
+{
+    void *rval;
+
+#ifdef MT
+    mutex_lock(&dgaGlobalMutex);
+#endif
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	rval = dgai_mbsmemb_rtnpixels((_Dga_window)dgadraw);
+	break;
+    case DGA_DRAW_PIXMAP:
+	/* not applicable to pixmaps -- doesn't have retained pixels */
+	rval = NULL;
+	break;
+    }
+#ifdef MT
+    mutex_unlock(&dgaGlobalMutex);
+#endif
+    return (rval);
+}
+
+Dga_widinfo *
+dga_draw_widinfop (Dga_drawable dgadraw)
+{
+    Dga_widinfo *rval;
+
+#ifdef MT
+    mutex_lock(&dgaGlobalMutex);
+#endif
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	rval = dga_win_widinfop((Dga_window)dgadraw);
+	break;
+    case DGA_DRAW_PIXMAP:
+	/* not applicable to pixmaps -- doesn't have retained pixels */
+	rval = NULL;
+	break;
+    }
+#ifdef MT
+    mutex_unlock(&dgaGlobalMutex);
+#endif
+    return (rval);
+}
+
+
+/* Note: the following routines are consolidation private.  They are not
+   a part of the public interface. */
+
+int
+dga_draw_mbchg (Dga_drawable dgadraw, int *reason)
+{
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	return (dgai_mbsmemb_mbchg((_Dga_window)dgadraw, reason));
+    case DGA_DRAW_PIXMAP:
+	/* pixmaps never are multibuffered */
+	return (0);
+    }
+}
+ 
+void
+dga_draw_mbsetnotify (Dga_drawable dgadraw, DgaMbNotifyFunc mb_notify_func,
+			   void *client_data)
+{
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	dgai_mbsmemb_mbsetnotify((_Dga_window)dgadraw, mb_notify_func, client_data);
+	break;
+    case DGA_DRAW_PIXMAP:
+	/* pixmaps never are multibuffered */
+	break;
+    }
+}
+
+void
+dga_draw_mbgetnotify (Dga_drawable dgadraw, DgaMbNotifyFunc *mb_notify_func,
+			   void **client_data)
+{
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	dgai_mbsmemb_mbgetnotify((_Dga_window)dgadraw, mb_notify_func, client_data);
+	break;
+    case DGA_DRAW_PIXMAP:
+	/* pixmaps never are multibuffered */
+	break;
+    }
+}
+
+
+int
+dga_draw_mbaccessmode (Dga_drawable dgadraw)
+{
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	return (dgai_mbsmemb_mbaccessmode((_Dga_window)dgadraw));
+    case DGA_DRAW_PIXMAP:
+	return (DGA_MBACCESS_NONE);
+    }
+}
+
+int
+dga_draw_mbsitetypeconst (Dga_drawable dgadraw)
+{
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	return (dgai_mbsmemb_mbsitetypeconst((_Dga_window)dgadraw));
+    case DGA_DRAW_PIXMAP:
+	/* can't tell for pixmaps - be conservative */
+	return (0);
+    }
+}
+
+void
+dga_draw_mbsetrendbufnotify (Dga_drawable dgadraw, DgaRendBufNotifyFunc rb_notify_func,
+				void *client_data)
+{
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	dgai_mbsmemb_mbsetrendbufnotify((_Dga_window)dgadraw, rb_notify_func, client_data);
+	break;
+    case DGA_DRAW_PIXMAP:
+	/* pixmaps never are multibuffered */
+	break;
+    }
+}
+
+void
+dga_draw_mbgetrendbufnotify (Dga_drawable dgadraw, DgaRendBufNotifyFunc *rb_notify_func,
+				void **client_data)
+{
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	dgai_mbsmemb_mbgetrendbufnotify((_Dga_window)dgadraw, rb_notify_func, client_data);
+	break;
+    case DGA_DRAW_PIXMAP:
+	/* pixmaps never are multibuffered */
+	break;
+    }
+}
+
+
+int
+dga_draw_ovlstatechg (Dga_drawable dgadraw)
+{
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	return (dgai_mbsmemb_ovlstatechg((_Dga_window)dgadraw));
+    case DGA_DRAW_PIXMAP:
+	/* Pixmaps never have an ovlstate */
+	return (0);
+    }
+}
+
+int
+dga_draw_ovlstate (Dga_drawable dgadraw)
+{
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	return (dgai_mbsmemb_ovlstate((_Dga_window)dgadraw));
+    case DGA_DRAW_PIXMAP:
+	/* Pixmaps never have an ovlstate */
+	return (DGA_OVLSTATE_CONFLICT);
+    }
+}
+
+void
+dga_draw_ovlstatesetnotify (Dga_drawable dgadraw, 
+			    DgaOvlStateNotifyFunc ovlstate_notify_func,
+			    void *client_data)
+{
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	dgai_mbsmemb_setovlstatenotify((_Dga_window)dgadraw,
+				       ovlstate_notify_func,
+				       client_data);
+    case DGA_DRAW_PIXMAP:
+	/* Pixmaps never have an ovlstate */
+	break;
+    }
+}
+
+void
+dga_draw_ovlstategetnotify (Dga_drawable dgadraw, 
+			    DgaOvlStateNotifyFunc *ovlstate_notify_func,
+			    void **client_data)
+{
+    switch ( ((_Dga_drawable)dgadraw)->drawable_type) {
+    case DGA_DRAW_WINDOW:
+	dgai_mbsmemb_getovlstatenotify((_Dga_window)dgadraw,
+				       ovlstate_notify_func,
+				       client_data);
+    case DGA_DRAW_PIXMAP:
+	/* Pixmaps never have an ovlstate */
+	break;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/lib/libdga/sun-src/mapfile	Fri Nov 13 13:30:43 2009 -0800
@@ -0,0 +1,311 @@
+###############################################################################
+#
+# libdga mapfile
+#
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+# 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, and/or sell copies of the Software, and to permit persons
+# to whom the Software is furnished to do so, provided that the above
+# copyright notice(s) and this permission notice appear in all copies of
+# the Software and that both the above copyright notice(s) and this
+# permission notice appear in supporting documentation.
+# 
+# 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
+# OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+# HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR 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.
+# 
+# Except as contained in this notice, the name of a copyright holder
+# shall not be used in advertising or otherwise to promote the sale, use
+# or other dealings in this Software without prior written authorization
+# of the copyright holder.
+#
+# ident	"@(#)mapfile	1.1	09/11/09 SMI"
+#
+
+SUNWprivate {
+    global:
+	_dga_client_version;
+	_dga_is_X_pixmap;
+	_dga_is_X_window;
+	_dga_rtn_map;
+	_dga_rtn_unmap;
+	_dga_winlockat;
+	_dga_winlockdt;
+	dga_buffer_address;
+	dga_buffer_bitsperpixel;
+	dga_buffer_linebytes;
+	dga_buffer_site;
+	dga_buffer_sitechg;
+	dga_buffer_type;
+	dga_cm_devdfd;
+	dga_cm_devinfo;
+	dga_cm_get_client_infop;
+	dga_cm_get;
+	dga_cm_grab;
+	dga_cm_put;
+	dga_cm_read;
+	dga_cm_set_client_infop;
+	dga_cm_ungrab;
+	dga_cm_write;
+	dga_db_access;
+	dga_db_display_complete;
+	dga_db_display_done;
+	dga_db_display_inquire;
+	dga_db_display;
+	dga_db_grab;
+	dga_db_interval_check;
+	dga_db_interval_wait;
+	dga_db_interval;
+	dga_db_read_inquire;
+	dga_db_read;
+	dga_db_release;
+	dga_db_ungrab;
+	dga_db_write_inquire;
+	dga_db_write;
+	dga_draw_address;
+	dga_draw_bbox;
+	dga_draw_bitsperpixel;
+	dga_draw_borderwidth;
+	dga_draw_buffer_swap;
+	dga_draw_bufferchg;
+	dga_draw_clipchg;
+	dga_draw_clipinfo;
+	dga_draw_curshandle;
+	dga_draw_db_dbinfop;
+	dga_draw_db_display_done;
+	dga_draw_db_display_inquire;
+	dga_draw_db_display;
+	dga_draw_db_grab;
+	dga_draw_db_interval_check;
+	dga_draw_db_interval_wait;
+	dga_draw_db_interval;
+	dga_draw_db_read_inquire;
+	dga_draw_db_read;
+	dga_draw_db_ungrab;
+	dga_draw_db_write_inquire;
+	dga_draw_db_write;
+	dga_draw_depth;
+	dga_draw_devfd;
+	dga_draw_devinfo;
+	dga_draw_devinfochg;
+	dga_draw_devname;
+	dga_draw_display;
+	dga_draw_empty;
+	dga_draw_get_buffers;
+	dga_draw_get_client_infop;
+	dga_draw_grab_buffer;
+	dga_draw_id;
+	dga_draw_linebytes;
+	dga_draw_mbaccessmode;
+	dga_draw_mbchg;
+	dga_draw_mbgetnotify;
+	dga_draw_mbgetrendbufnotify;
+	dga_draw_mbsetnotify;
+	dga_draw_mbsetrendbufnotify;
+	dga_draw_mbsitetypeconst;
+	dga_draw_obscured;
+	dga_draw_ovlstate;
+	dga_draw_ovlstatechg;
+	dga_draw_ovlstategetnotify;
+	dga_draw_ovlstatesetnotify;
+	dga_draw_rtnactive;
+	dga_draw_rtnbitsperpixel;
+	dga_draw_rtncached;
+	dga_draw_rtnchg;
+	dga_draw_rtndevinfo;
+	dga_draw_rtndevinfop;
+	dga_draw_rtndevtype;
+	dga_draw_rtndimensions;
+	dga_draw_rtngrab;
+	dga_draw_rtnpixels;
+	dga_draw_rtnungrab;
+	dga_draw_set_client_infop;
+	dga_draw_singlerect;
+	dga_draw_site;
+	dga_draw_sitechg;
+	dga_draw_sitegetnotify;
+	dga_draw_sitesetnotify;
+	dga_draw_swap_check;
+	dga_draw_type;
+	dga_draw_ungrab_buffer;
+	dga_draw_visibility;
+	dga_draw_widinfop;
+	dga_init_version;
+	dga_pix_cachechg;
+	dga_pix_cached;
+	dga_pix_depth;
+	dga_pix_devinfo;
+	dga_pix_devname;
+	dga_pix_grab;
+	dga_pix_linebytes;
+	dga_pix_pixels;
+	dga_pix_ungrab;
+	dga_pixlist_add;
+	dga_rtn_active;
+	dga_rtn_bitsperpixel;
+	dga_rtn_cached;
+	dga_rtn_devinfo;
+	dga_rtn_devinfop;
+	dga_rtn_devtype;
+	dga_rtn_dimensions;
+	dga_rtn_grab;
+	dga_rtn_pixels;
+	dga_rtn_ungrab;
+	dga_win_bbox;
+	dga_win_bboxinfop;
+	dga_win_borderwidth;
+	dga_win_clipchg;
+	dga_win_clipinfo;
+	dga_win_cursactive;
+	dga_win_curschg;
+	dga_win_cursupdate;
+	dga_win_dbinfop;
+	dga_win_depth;
+	dga_win_devfd;
+	dga_win_empty;
+	dga_win_fbname;
+	dga_win_get_client_infop;
+	dga_win_grab;
+	dga_win_obscured;
+	dga_win_rtnchg;
+	dga_win_set_client_infop;
+	dga_win_singlerect;
+	dga_win_ungrab;
+	dga_win_widinfop;
+	dgaGlobalMutex;
+	dgaGlobalPixmapMutex;
+	dgai_mbsmemb_address;
+	dgai_mbsmemb_bbox;
+	dgai_mbsmemb_bitsperpixel;
+	dgai_mbsmemb_borderwidth;
+	dgai_mbsmemb_clipchg;
+	dgai_mbsmemb_clipinfo;
+	dgai_mbsmemb_curshandle;
+	dgai_mbsmemb_depth;
+	dgai_mbsmemb_devfd;
+	dgai_mbsmemb_devinfo_update;
+	dgai_mbsmemb_devinfo;
+	dgai_mbsmemb_devinfochg;
+	dgai_mbsmemb_devname;
+	dgai_mbsmemb_display;
+	dgai_mbsmemb_empty;
+	dgai_mbsmemb_figureDerivChgs;
+	dgai_mbsmemb_get_client_infop;
+	dgai_mbsmemb_getovlstatenotify;
+	dgai_mbsmemb_linebytes;
+	dgai_mbsmemb_mbaccessmode;
+	dgai_mbsmemb_mbchg;
+	dgai_mbsmemb_mbgetnotify;
+	dgai_mbsmemb_mbgetrendbufnotify;
+	dgai_mbsmemb_mbsetnotify;
+	dgai_mbsmemb_mbsetrendbufnotify;
+	dgai_mbsmemb_mbsitetypeconst;
+	dgai_mbsmemb_notify;
+	dgai_mbsmemb_obscured;
+	dgai_mbsmemb_ovlstate;
+	dgai_mbsmemb_ovlstatechg;
+	dgai_mbsmemb_rtnactive;
+	dgai_mbsmemb_rtnbitsperpixel;
+	dgai_mbsmemb_rtncached;
+	dgai_mbsmemb_rtnchg;
+	dgai_mbsmemb_rtndevinfop;
+	dgai_mbsmemb_rtndevtype;
+	dgai_mbsmemb_rtndimensions;
+	dgai_mbsmemb_rtngrab;
+	dgai_mbsmemb_rtnpixels;
+	dgai_mbsmemb_rtnungrab;
+	dgai_mbsmemb_set_client_infop;
+	dgai_mbsmemb_setovlstatenotify;
+	dgai_mbsmemb_singlerect;
+	dgai_mbsmemb_site;
+	dgai_mbsmemb_sitechg;
+	dgai_mbsmemb_sitegetnotify;
+	dgai_mbsmemb_sitesetnotify;
+	dgai_mbsmemb_syncMbufset;
+	dgai_mbsmemb_syncRendBuf;
+	dgai_mbsmemb_syncZombie;
+	dgai_mbsmemb_update;
+	dgai_mbsmemb_visibility;
+	dgai_mbuf_update;
+	dgai_mbufset_create;
+	dgai_mbufset_decref;
+	dgai_mbufset_incref;
+	dgai_nmbuf_cache_update;
+	dgai_nmbuf_devinfo_update;
+	dgai_nmbuf_syncChanges;
+	dgai_pix_address;
+	dgai_pix_bbox;
+	dgai_pix_bitsperpixel;
+	dgai_pix_clipchg;
+	dgai_pix_clipinfo;
+	dgai_pix_depth;
+	dgai_pix_devfd;
+	dgai_pix_devinfo;
+	dgai_pix_devinfochg;
+	dgai_pix_devname;
+	dgai_pix_display;
+	dgai_pix_empty;
+	dgai_pix_get_client_infop;
+	dgai_pix_linebytes;
+	dgai_pix_notify;
+	dgai_pix_set_client_infop;
+	dgai_pix_site;
+	dgai_pix_sitechg;
+	dgai_pix_sitegetnotify;
+	dgai_pix_sitesetnotify;
+	dgai_pix_update;
+	dgai_rtn_ungrab_common;
+	dgai_unlock;
+	dgai_vmbuf_syncChanges;
+	dgai_win_check_multiple_grab;
+	dgai_win_clip_update;
+	dgai_win_curs_update;
+	dgai_win_grab_common;
+	dgai_win_rtn_update;
+	dgai_win_syncChanges;
+	dgai_win_ungrab_common;
+	dgai_win_update;
+	dgai_win_visibility;
+	dgaMTOn;
+	dgaThreaded;
+	safe_free_clientp;
+	XDgaDrawGrabFCS;
+	XDgaDrawGrabStereo;
+	XDgaDrawGrabWids;
+	XDgaDrawGrabZbuf;
+	XDgaGetRetainedPath;
+	XDgaGetXineramaInfo;
+	XDgaGrabABuffers;
+	XDgaGrabBuffers;
+	XDgaGrabColormap;
+	XDgaGrabDrawable;
+	XDgaGrabFCS;
+	XDgaGrabPixmap;
+	XDgaGrabRetainedWindow;
+	XDgaGrabStereo;
+	XDgaGrabWids;
+	XDgaGrabWindow;
+	XDgaGrabZbuf;
+	XDgaQueryVersion;
+	XDgaUnGrabABuffers;
+	XDgaUnGrabBuffers;
+	XDgaUnGrabColormap;
+	XDgaUnGrabDrawable;
+	XDgaUnGrabPixmap;
+	XDgaUnGrabRetainedWindow;
+	XDgaUnGrabWindow;
+    local:
+	*;
+};
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/lib/libdga/sun-src/mbsmemb_inquiry.c	Fri Nov 13 13:30:43 2009 -0800
@@ -0,0 +1,652 @@
+/* Copyright 1997 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ *
+ * 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, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * 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
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR 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.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+#pragma ident	"@(#)mbsmemb_inquiry.c	35.4	09/11/09 SMI"
+
+/* 
+** mbsmemb_inquiry.c - state inquiry routines for mbufset members.
+*/
+
+#ifdef SERVER_DGA
+#include <X11/Xlib.h>
+#endif  /* SERVER_DGA */
+#include "dga_incls.h"
+#include "pix_grab.h"
+#include "mbufsetstr.h"
+
+extern int dgai_rtn_ungrab_common(_Dga_window dgawin, int drawableGrabber);
+extern int dga_rtn_bitsperpixel(Dga_window clientpi);
+
+Display *
+dgai_mbsmemb_display (_Dga_window dgawin)
+{
+    return (dgawin->w_dpy);
+}
+
+char *
+dgai_mbsmemb_devname (_Dga_window dgawin)
+{
+    if (dgawin->changeMask & DGA_CHANGE_ZOMBIE)
+	return (NULL);
+
+    return(((WXINFO *) (dgawin->w_info))->w_devname);
+}
+
+int
+dgai_mbsmemb_devfd (_Dga_window dgawin)
+{
+    return(dgawin->w_devfd);
+}
+
+int
+dgai_mbsmemb_depth (_Dga_window dgawin)
+{
+    WXINFO *infop = (WXINFO *) dgawin->w_info;
+	
+    if (dgawin->changeMask & DGA_CHANGE_ZOMBIE)
+	return (NULL);
+
+    if (infop->w_version >= 3) 
+	return((int)infop->w_depth);
+    else 
+	return (0);
+}
+
+void
+dgai_mbsmemb_set_client_infop (_Dga_window dgawin, void *client_info_ptr)
+{
+    dgawin->w_client = client_info_ptr;
+}
+
+void *
+dgai_mbsmemb_get_client_infop (_Dga_window dgawin)
+{
+    return (dgawin->w_client);
+}
+
+void *
+dgai_mbsmemb_devinfo (_Dga_window dgawin)
+{
+    SHARED_PIXMAP_INFO *infop;
+
+    if ((dgawin->eLockSubj == DGA_LOCKSUBJ_INVALID) ||
+	dgawin->changeMask & DGA_CHANGE_ZOMBIE) {
+	return (NULL);
+    }
+
+    if (dgawin->eLockSubj == -1) {
+        WXINFO *infop = (WXINFO *) dgawin->w_info;
+
+        return ((void *) &(infop->wx_dbuf.device_info));
+    }
+    infop = dgawin->pMbs->pNbShinfo[dgawin->eLockSubj];
+    return (((char *)infop) + infop->device_offset);
+}
+
+int
+dgai_mbsmemb_devinfochg (_Dga_window dgawin)
+{
+    if (dgawin->changeMask & DGA_CHANGE_DEVINFO) {
+	dgawin->changeMask &= ~DGA_CHANGE_DEVINFO;
+	return (1);
+    } else {
+	return (0);
+    }
+}
+
+int
+dgai_mbsmemb_sitechg (_Dga_window dgawin, int *reason)
+{
+    if (dgawin->changeMask & DGA_CHANGE_SITE) {
+	dgawin->changeMask &= ~DGA_CHANGE_SITE;
+	*reason = dgawin->siteChgReason;
+	return (1);
+    } else {
+	*reason = DGA_SITECHG_UNKNOWN;
+	return (0);
+    }
+}
+
+void
+dgai_mbsmemb_sitesetnotify (_Dga_window dgawin, DgaSiteNotifyFunc site_notify_func,
+			   void *client_data)
+{
+    dgawin->siteNotifyFunc = site_notify_func;
+    dgawin->siteNotifyClientData = client_data;
+}
+
+void
+dgai_mbsmemb_sitegetnotify (_Dga_window dgawin, DgaSiteNotifyFunc *site_notify_func,
+			   void **client_data)
+{
+    *site_notify_func = dgawin->siteNotifyFunc;
+    *client_data = dgawin->siteNotifyClientData;
+}
+
+int
+dgai_mbsmemb_site (_Dga_window dgawin)
+{
+    SHARED_PIXMAP_INFO *infop;
+
+    if ((dgawin->eLockSubj == DGA_LOCKSUBJ_INVALID)||
+	 dgawin->changeMask & DGA_CHANGE_ZOMBIE) {
+	return (DGA_SITE_NULL);
+    }
+
+    /* viewable drawables always are in device site */
+    if (DGA_LOCKSUBJ_VIEWABLE(dgawin, dgawin->eLockSubj)) {
+	return (DGA_SITE_DEVICE);
+    }
+
+    /* the site of a nonviewable multibuffer depends on whether or not
+       it is cached */
+
+    infop = dgawin->pMbs->pNbShinfo[dgawin->eLockSubj];
+    return (infop->cached ? DGA_SITE_DEVICE : DGA_SITE_SYSTEM);
+}
+
+void *
+dgai_mbsmemb_address (_Dga_window dgawin)
+{
+    SHARED_PIXMAP_INFO *infop;
+    
+    if ((dgawin->eLockSubj == DGA_LOCKSUBJ_INVALID) ||
+    	dgawin->changeMask & DGA_CHANGE_ZOMBIE ||
+	DGA_LOCKSUBJ_VIEWABLE(dgawin, dgawin->eLockSubj)) {
+	return (NULL);
+    }
+
+    /* the return value is only valid for nonviewable multibuffers that
+       are not cached */
+    	infop = dgawin->pMbs->pNbShinfo[dgawin->eLockSubj];
+    	return (infop->cached ? NULL : (void *)(infop + 1));
+}
+
+int
+dgai_mbsmemb_linebytes (_Dga_window dgawin)
+{
+    SHARED_PIXMAP_INFO *infop;
+    
+    if ((dgawin->eLockSubj == DGA_LOCKSUBJ_INVALID) ||
+	dgawin->changeMask & DGA_CHANGE_ZOMBIE ||
+	DGA_LOCKSUBJ_VIEWABLE(dgawin, dgawin->eLockSubj)) {
+	return (0);
+    }
+
+    /* the return value is only valid for nonviewable multibuffers that
+       are not cached */
+    infop = dgawin->pMbs->pNbShinfo[dgawin->eLockSubj];
+    return (infop->cached ? 0 : infop->linebytes);
+}
+
+int
+dgai_mbsmemb_bitsperpixel (_Dga_window dgawin)
+{
+    SHARED_PIXMAP_INFO *infop;
+    
+    if ((dgawin->eLockSubj == DGA_LOCKSUBJ_INVALID) ||
+	dgawin->changeMask & DGA_CHANGE_ZOMBIE ||
+	DGA_LOCKSUBJ_VIEWABLE(dgawin, dgawin->eLockSubj)) {
+	return (0);
+    }
+
+    /* the return value is only valid for nonviewable multibuffers that
+       are not cached */
+    infop = dgawin->pMbs->pNbShinfo[dgawin->eLockSubj];
+    return (infop->cached ? 0 : infop->bitsperpixel);
+}
+
+int
+dgai_mbsmemb_clipchg (_Dga_window dgawin)
+{
+    /* always force a clip change on a zombie to get the client
+       to notice */
+    if (dgawin->changeMask & DGA_CHANGE_ZOMBIE) {
+	return (1);
+    }
+
+    if (DGA_LOCKSUBJ_VIEWABLE(dgawin, dgawin->eLockSubj)) {
+	if (dga_win_clipchg((Dga_window)dgawin) || 
+	    (dgawin->changeMask & DGA_CHANGE_CLIP)) {
+	    dgawin->changeMask &= ~DGA_CHANGE_CLIP;
+	    return (1);
+	} else {
+	    return (0);
+	}
+    } else {
+	/* nonviewable */
+	if (dgawin->changeMask & DGA_CHANGE_CLIP) {
+	    dgawin->changeMask &= ~DGA_CHANGE_CLIP;
+	    return (1);
+        } else {
+	    return (0);
+	}
+    }
+}
+
+void
+dgai_mbsmemb_bbox(_Dga_window dgawin, int *xp, int *yp, int *widthp, int *heightp)
+{
+    if ((dgawin->eLockSubj == DGA_LOCKSUBJ_INVALID) ||
+	dgawin->changeMask & DGA_CHANGE_ZOMBIE) {
+	*xp = 0;
+	*yp = 0;
+	*widthp = 0;
+	*heightp = 0;
+	return;
+    }
+
+    if (DGA_LOCKSUBJ_VIEWABLE(dgawin, dgawin->eLockSubj)) {
+	dga_win_bbox((Dga_window)dgawin, xp, yp, widthp, heightp);
+    } else {
+	/* nonviewable */
+	SHARED_PIXMAP_INFO *infop;
+
+	infop = dgawin->pMbs->pNbShinfo[dgawin->eLockSubj];
+	*xp = 0;
+	*yp = 0;
+	*widthp = infop->width;
+	*heightp = infop->height;
+    }
+}
+
+int
+dgai_mbsmemb_visibility (_Dga_window dgawin)
+{
+    if (dgawin->changeMask & DGA_CHANGE_ZOMBIE) {
+	return (DGA_VIS_FULLY_OBSCURED);
+    }
+
+    if (DGA_LOCKSUBJ_VIEWABLE(dgawin, dgawin->eLockSubj)) {
+	return (dgai_win_visibility((Dga_window)dgawin));
+    } else {
+        /* Non viewable mbufs are always unobscured */
+        return (DGA_VIS_UNOBSCURED);
+    }
+}
+
+int
+dgai_mbsmemb_empty (_Dga_window dgawin)
+{ 
+    if ((dgawin->eLockSubj == DGA_LOCKSUBJ_INVALID)||
+	dgawin->changeMask & DGA_CHANGE_ZOMBIE) {
+	return (1);
+    }
+
+    if (DGA_LOCKSUBJ_VIEWABLE(dgawin, dgawin->eLockSubj)) {
+	return (dga_win_empty((Dga_window)dgawin));
+    } else {
+	/* nonviewable */
+	SHARED_PIXMAP_INFO *infop;
+
+	infop = dgawin->pMbs->pNbShinfo[dgawin->eLockSubj];
+	return (infop->width <= 0 || infop->height <= 0);
+    }
+}
+
+static short nonviewableShape[] = {
+    0, /* ymin */
+    0, /* ymax: fill in based on height */
+    0, /* xmin */
+    0, /* xmax: fill in based on width */
+    DGA_X_EOL,
+    DGA_Y_EOL,
+};
+
+#define YMAX_INDEX 1
+#define XMAX_INDEX 3
+
+short *
+dgai_mbsmemb_clipinfo (_Dga_window dgawin)
+{
+    if ((dgawin->eLockSubj == DGA_LOCKSUBJ_INVALID) ||
+	 dgawin->changeMask & DGA_CHANGE_ZOMBIE) {
+	return (NULL);
+    }
+
+    if (DGA_LOCKSUBJ_VIEWABLE(dgawin, dgawin->eLockSubj)) {
+	return (dga_win_clipinfo((Dga_window)dgawin));
+    } else {
+	/* nonviewable */
+	SHARED_PIXMAP_INFO *infop;
+
+	/* build a dummy shape describing the rectangle */
+	infop = dgawin->pMbs->pNbShinfo[dgawin->eLockSubj];
+	if (infop->width <= 0 || infop->height <= 0) {
+	    return (NULL);
+	} else {
+	    nonviewableShape[YMAX_INDEX] = infop->height - 1;
+	    nonviewableShape[XMAX_INDEX] = infop->width - 1;
+	    return (nonviewableShape);
+	}
+    }
+}
+
+
+int
+dgai_mbsmemb_singlerect (_Dga_window dgawin)
+{
+    if (dgawin->changeMask & DGA_CHANGE_ZOMBIE) {
+	/* consider a zombie to be a "single rectangle" of 0 width and height */
+	return (1);
+    }
+
+    if (DGA_LOCKSUBJ_VIEWABLE(dgawin, dgawin->eLockSubj)) {
+	return (dga_win_singlerect((Dga_window)dgawin));
+    } else {
+	/* nonviewable is always a single rectangle */
+	return (1);
+    }
+}
+
+int
+dgai_mbsmemb_obscured (_Dga_window dgawin)
+{
+    if (dgawin->changeMask & DGA_CHANGE_ZOMBIE) {
+	/* consider a zombie to be always fully obscured */
+	return (1);
+    }
+
+    if (DGA_LOCKSUBJ_VIEWABLE(dgawin, dgawin->eLockSubj)) {
+	return (dga_win_obscured((Dga_window)dgawin));
+    } else {
+	/* nonviewable can never be obscured */
+	return (0);
+    }
+}
+
+
+u_short
+dgai_mbsmemb_borderwidth (_Dga_window dgawin) 
+{ 
+    if (dgawin->changeMask & DGA_CHANGE_ZOMBIE) {
+	/* zombies don't have borders */
+	return (0);
+    }
+
+    if (DGA_LOCKSUBJ_WINDOW(dgawin, dgawin->eLockSubj)) {
+	return (dga_win_borderwidth((Dga_window)dgawin));
+    } else {
+	/* multibuffers don't have borders */
+	return (0);
+    }
+} 
+
+
+typedef void (*DgaCursTakeDownFuncOld)();
+
+void
+dgai_mbsmemb_curshandle (_Dga_window dgawin, DgaCursTakeDownFunc take_down_func,
+		        void *client_data)
+{
+    Dga_window dgaw;
+
+    /* Nonviewable drawables never have a cursor */
+    if (!DGA_LOCKSUBJ_VIEWABLE(dgawin, dgawin->eLockSubj)) {
+	return;
+    }
+
+    /* viewable multibuffers share the cursor of the main window */
+    dgaw = (Dga_window) dgawin;    
+    if (dga_win_curschg(dgaw)) {
+	if (dga_win_cursactive(dgaw)) {
+	    dga_win_cursupdate(dgaw, 
+			       (DgaCursTakeDownFuncOld)take_down_func,
+			       client_data);
+	}
+    }
+}
+
+
+int
+dgai_mbsmemb_rtngrab (_Dga_window dgawin)
+{
+    /* rtngrab is not something that must be called from inside a lock
+     * and therefore the eLockSubj is meaningless.  Just do a
+     * dga_rtn_grab() on the window. */
+
+    return (dga_rtn_grab((Dga_window)dgawin));
+}
+
+int
+dgai_mbsmemb_rtnungrab (_Dga_window dgawin)
+{
+    return (dgai_rtn_ungrab_common(dgawin,1));
+}
+
+int
+dgai_mbsmemb_rtnchg (_Dga_window dgawin)
+{
+    if (DGA_LOCKSUBJ_WINDOW(dgawin, dgawin->eLockSubj)) {
+	return (dga_win_rtnchg((Dga_window)dgawin));
+    } else {
+	/* rtn is not applicable to multibuffers -- always force an activity check */
+	return (1);
+    }
+}
+
+int
+dgai_mbsmemb_rtnactive (_Dga_window dgawin)
+{
+    if (DGA_LOCKSUBJ_WINDOW(dgawin, dgawin->eLockSubj)) {
+	return (dga_rtn_active((Dga_window)dgawin));
+    } else {
+	/* rtn is not applicable to multibuffers -- never active */
+	return (0);
+    }
+}
+
+int
+dgai_mbsmemb_rtncached (_Dga_window dgawin)
+{
+    if (DGA_LOCKSUBJ_WINDOW(dgawin, dgawin->eLockSubj)) {
+	return (dga_rtn_cached((Dga_window)dgawin));
+    } else {
+	/* rtn is not applicable to multibuffers -- never cached */
+	return (0);
+    }
+}
+
+void *
+dgai_mbsmemb_rtndevinfop (_Dga_window dgawin)
+{
+    if (DGA_LOCKSUBJ_WINDOW(dgawin, dgawin->eLockSubj)) {
+	return (dga_rtn_devinfo((Dga_window)dgawin));
+    } else {
+	/* rtn is not applicable to multibuffers -- no devinfo */
+	return (NULL);
+    }
+}
+
+void
+dgai_mbsmemb_rtndevtype (_Dga_window dgawin, u_char *type, char **name)
+{
+    if (DGA_LOCKSUBJ_WINDOW(dgawin, dgawin->eLockSubj)) {
+	dga_rtn_devtype((Dga_window)dgawin, type, name);
+    } else {
+	/* rtn is not applicable to multibuffers -- values of return args are arbitrary */
+	*type = (u_char) 0;
+	*name = NULL;
+    }
+}
+
+void
+dgai_mbsmemb_rtndimensions (_Dga_window dgawin, short *width, short *height, 
+			    u_int *linebytes)
+{
+    if (DGA_LOCKSUBJ_WINDOW(dgawin, dgawin->eLockSubj)) {
+	dga_rtn_dimensions((Dga_window)dgawin, width, height, linebytes);
+    } else {
+	/* rtn is not applicable to multibuffers -- values of return args are arbitrary */
+	*width =  0;
+	*height = 0;
+	*linebytes = 0;
+    }
+}
+
+int
+dgai_mbsmemb_rtnbitsperpixel (_Dga_window dgawin)
+{
+    if (DGA_LOCKSUBJ_WINDOW(dgawin, dgawin->eLockSubj)) {
+	return (dga_rtn_bitsperpixel((Dga_window)dgawin));
+    } else {
+	/* rtn is not applicable to multibuffers -- values of return args are arbitrary */
+	return (0);
+    }
+}
+
+void *
+dgai_mbsmemb_rtnpixels (_Dga_window dgawin)
+{
+    if (DGA_LOCKSUBJ_WINDOW(dgawin, dgawin->eLockSubj)) {
+	return (dga_rtn_pixels((Dga_window)dgawin));
+    } else {
+	/* rtn is not applicable to multibuffers -- return NULL */
+	return (NULL);
+    }
+}
+
+
+int
+dgai_mbsmemb_mbchg (_Dga_window dgawin, int *reason)
+{
+    if (dgawin->changeMask & DGA_CHANGE_MBUFSET) {
+	dgawin->changeMask &= ~DGA_CHANGE_MBUFSET;
+	*reason = dgawin->mbChgReason;
+	return (1);
+    } else {
+	*reason = DGA_MBCHG_UNKNOWN;
+	return (0);
+    }
+}
+ 
+void
+dgai_mbsmemb_mbsetnotify (_Dga_window dgawin, DgaMbNotifyFunc mb_notify_func,
+			   void *client_data)
+{
+    dgawin->mbNotifyFunc = mb_notify_func;
+    dgawin->mbNotifyClientData = client_data;
+}
+
+void
+dgai_mbsmemb_mbgetnotify (_Dga_window dgawin, DgaMbNotifyFunc *mb_notify_func,
+			   void **client_data)
+{
+    *mb_notify_func = dgawin->mbNotifyFunc;
+    *client_data = dgawin->mbNotifyClientData;
+}
+
+
+int
+dgai_mbsmemb_mbaccessmode (_Dga_window dgawin)
+{
+    if (!dgawin->pMbs) {
+	return (DGA_MBACCESS_NONE);
+    } else {
+	WXINFO	*infop;
+	
+	infop = (WXINFO *) dgawin->w_info;
+	
+	return (infop->w_mbsInfo.accessMode);
+    }
+}
+
+int
+dgai_mbsmemb_mbsitetypeconst (_Dga_window dgawin)
+{
+    if (!dgawin->pMbs) {
+	return (1);
+    } else {
+	WXINFO	*infop;
+	
+	infop = (WXINFO *) dgawin->w_info;
+
+	return (infop->w_mbsInfo.siteTypeConst);
+    }
+}
+
+void
+dgai_mbsmemb_mbsetrendbufnotify (_Dga_window dgawin, DgaRendBufNotifyFunc rb_notify_func,
+				void *client_data)
+{
+    dgawin->rendBufNotifyFunc = rb_notify_func;
+    dgawin->rendBufNotifyClientData = client_data;
+}
+
+void
+dgai_mbsmemb_mbgetrendbufnotify (_Dga_window dgawin, DgaRendBufNotifyFunc *rb_notify_func,
+				void **client_data)
+{
+    *rb_notify_func = dgawin->rendBufNotifyFunc;
+    *client_data = dgawin->rendBufNotifyClientData;
+}
+
+int
+dgai_mbsmemb_ovlstatechg (_Dga_window dgawin)
+{
+    if (dgawin->changeMask & DGA_CHANGE_OVLSTATE) {
+	dgawin->changeMask &= ~DGA_CHANGE_OVLSTATE;
+	return (1);
+    } else {
+	return (0);
+    }
+}
+
+int
+dgai_mbsmemb_ovlstate (_Dga_window dgawin)
+{
+    /* REMIND: Do we need to check this stuff? */
+    if ((dgawin->eLockSubj == DGA_LOCKSUBJ_INVALID) ||
+	(dgawin->changeMask & DGA_CHANGE_ZOMBIE)) {
+	return (DGA_OVLSTATE_CONFLICT);
+    }
+    if (!dgawin->isOverlay)
+	/* Don't let clients do "overlay" rendering to regular windows! */
+	return DGA_OVLSTATE_CONFLICT;
+    else
+	return dgawin->c_ovlstate;
+}
+
+void
+dgai_mbsmemb_setovlstatenotify (_Dga_window dgawin, 
+				DgaOvlStateNotifyFunc ovlstate_notify_func,
+				void *client_data)
+{
+    dgawin->ovlStateNotifyFunc = ovlstate_notify_func;
+    dgawin->ovlStateNotifyClientData = client_data;
+}
+
+void
+dgai_mbsmemb_getovlstatenotify (_Dga_window dgawin, 
+				DgaOvlStateNotifyFunc *ovlstate_notify_func,
+				void **client_data)
+{
+    *ovlstate_notify_func = dgawin->ovlStateNotifyFunc;
+    *client_data = dgawin->ovlStateNotifyClientData;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/lib/libdga/sun-src/mbsmemb_update.c	Fri Nov 13 13:30:43 2009 -0800
@@ -0,0 +1,395 @@
+/* Copyright 1999 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ *
+ * 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, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * 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
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR 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.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+#pragma ident	"@(#)mbsmemb_update.c	35.8	09/11/09 SMI"
+
+/*
+**
+** mbsmemb_update.c
+**
+** Routines of the update phase that apply equally to both types of
+** multibuffer set members, windows and multibuffers.
+*/
+
+#include <stdio.h>
+#include <sys/types.h>
+#ifdef SERVER_DGA
+#include <X11/Xlib.h>
+#endif /* SERVER_DGA */
+#include "dga_incls.h"
+#include "pix_grab.h"
+#include "mbufsetstr.h"
+
+static void 		dgai_mbsmemb_notifySiteChg (_Dga_window dgawin);
+static void		dgai_mbsmemb_notifyMbChg (_Dga_window dgawin);
+static void		dgai_mbsmemb_notifyOvlState (_Dga_window dgawin);
+
+/*
+** The update phase entry routine for mbufset members.
+** Called if the master change count of the shared info
+** differs from the last recorded count in the client structure.
+*/
+
+int
+dgai_mbsmemb_update (Dga_drawable dgadraw, short bufIndex)
+{
+    _Dga_window dgawin = (_Dga_window) dgadraw;
+    int status;
+
+#ifdef MT
+    if (dgaMTOn) {
+	mutex_lock(dgawin->mutexp);  /* lock the per-window mutex */
+	DGA_LOCK(dgadraw);
+	/* check the real change count that we saved away */
+	if (dgawin->shadow_chngcnt[bufIndex + 1] == *dgawin->s_chngcnt_p) {
+	    DGA_UNLOCK(dgadraw);
+	    mutex_unlock(dgawin->mutexp);
+	    return (0);
+	}
+    }
+    mutex_lock(&dgaGlobalMutex);
+#endif
+    /* establish the new real lock subject */
+    dgawin->rLockSubj = bufIndex;
+
+    /* save last lock subject.  This may be used later in the update phase */
+    dgawin->eLockSubjPrev = dgawin->eLockSubj;
+    
+    /* start out assuming we're not aliased.  This may change if we detect
+       aliasing later in the update phase */
+    dgawin->eLockSubj = dgawin->rLockSubj;
+
+    /* the first thing we do is distinguish between locking a window
+       and a multibuffer.  The update logic is different */
+    if (bufIndex == -1) {
+	status = dgai_win_update(dgawin, bufIndex);
+    } else {
+	status = dgai_mbuf_update(dgawin, bufIndex);
+    }
+#ifdef MT
+    if (dgaMTOn) {
+	/* save the real change count */
+	dgawin->shadow_chngcnt[bufIndex + 1] =
+	    dgawin->c_wm_chngcnt[bufIndex + 1];
+	/* For the MT case, make sure that this update function gets called
+	 * the next time around, so overwrite the change count to make it
+	 * different.
+	 */
+	dgawin->c_wm_chngcnt[bufIndex + 1] = *dgawin->s_chngcnt_p - 1;
+	DGA_UNLOCK(dgadraw);
+	mutex_unlock(dgawin->mutexp);  /* unlock the per-window mutex */
+    }
+    mutex_unlock(&dgaGlobalMutex);
+#endif
+    return (status);
+}
+
+
+/*
+** See if the shared info of the main window is still valid.
+** Nonzero is returned if it is no longer valid and has become
+** a zombie.
+*/
+
+int
+dgai_mbsmemb_syncZombie (_Dga_window dgawin)
+{
+    WXINFO *infop;
+
+    infop = (WXINFO *) dgawin->w_info;
+
+    if (infop->w_obsolete) {
+	dgawin->changeMask |= DGA_CHANGE_ZOMBIE;
+	return (1);
+    } else {
+	return (0);
+    }
+}
+
+/*
+** The way we deal with any composition change is to destroy the old
+** multibuffer set and establish a new one.
+*/
+
+void
+dgai_mbsmemb_syncMbufset (_Dga_window dgawin)
+{
+
+    DgaMbufSetPtr	pMbs;
+    WXINFO 		*infop;
+
+    /* check to see if this is an actual composition change or simply
+       a display change */
+    if (dgawin->c_mbcomposseq == *dgawin->s_mbcomposseq_p) {
+	/* no change -- must be only a display change */
+	return;
+    }
+
+    /* this is a real composition change.  Destroy the old mbufset (if any)
+       and create a new one */
+
+    infop = (WXINFO *) dgawin->w_info;
+    pMbs = dgawin->pMbs;
+
+    /* remember whether window was previously multibuffered.  This is 
+       used later in the update phase to determine the reason for the
+       mbufset change */
+    dgawin->prevWasMbuffered = (pMbs != NULL);
+
+    /* destroy the old one */
+    if (pMbs) {
+	dgai_mbufset_decref(pMbs);
+	dgawin->pMbs = NULL;
+    }
+
+    dgawin->c_mbcomposseq = *dgawin->s_mbcomposseq_p;
+
+    if (!infop->w_mbsInfo.enabled) {
+	return;
+    }
+    
+    /* create a new one */
+    pMbs = dgai_mbufset_create(dgawin);
+    
+    if (!pMbs) {
+	/* TODO: really the only way we have of responding to this is treat 
+	   it as a zombie.  It's not ideal, but what else can we do? */
+	dgawin->changeMask |= DGA_CHANGE_ZOMBIE;
+    }
+
+    dgawin->pMbs = pMbs;
+}
+
+
+/*
+** If a render buffer notification function has been registered
+** and the current effective lock subject differs from the current
+** write buffer, call the notification function to change the render 
+** buffer state.
+*/
+
+void
+dgai_mbsmemb_syncRendBuf (_Dga_window dgawin)
+{
+    WXINFO	*infop;
+    short	*pRendBuf;
+	
+    infop = (WXINFO *) dgawin->w_info;
+
+    /* has client registered the notification function? */
+    if (!dgawin->rendBufNotifyFunc) {
+	return;
+    }
+
+    /* we only need to notify in single-address access mode */
+    if (infop->w_mbsInfo.accessMode != DGA_MBACCESS_SINGLEADDR) {
+	return;
+    }
+
+    /* 
+     * Only notify if rend buf is different from what we want it to be 
+     * Note: we treat the write buffer index as the render buffer and ignore
+     * the read buffer index.
+     */
+    pRendBuf = &infop->wx_dbuf.write_buffer;
+    if (*pRendBuf != dgawin->eLockSubj) {
+	(*dgawin->rendBufNotifyFunc)((Dga_drawable)dgawin, dgawin->eLockSubj,
+				    dgawin->rendBufNotifyClientData);
+
+	/* update the shared info so both the server and other clients can
+	   see and react to the change */
+	*pRendBuf = dgawin->eLockSubj;
+    }
+}
+
+/*
+** A derivative change is one which is dependent on changes discovered 
+** earlier in the update phase (i.e. the basic changes).  We determine here which ones need
+** to be reported.  Derivative changes may be reported along with 
+** the basic changes.  The derivative changes in common for mbufset
+** members are: site change.
+*/
+
+void
+dgai_mbsmemb_figureDerivChgs (_Dga_window dgawin)
+{
+    /* safety */
+    dgawin->siteChgReason = DGA_SITECHG_UNKNOWN;
+
+    /* check for zombie */
+    if (dgawin->changeMask & DGA_CHANGE_ZOMBIE) {
+	/* report both a site change and a clip for zombies.  This is simply
+	   more insurance that the client will sync up with the null clip. */
+	dgawin->changeMask |= (DGA_CHANGE_SITE | DGA_CHANGE_CLIP);
+	dgawin->siteChgReason = DGA_SITECHG_ZOMBIE;
+	return;
+    }
+
+    /* check for first time */
+    if ((dgawin->eLockSubj == -1) && !dgawin->prevLocked) {
+	dgawin->changeMask |= DGA_CHANGE_SITE;
+	dgawin->siteChgReason = DGA_SITECHG_INITIAL;
+	dgawin->prevLocked = 1;
+	return;
+    } else if ((dgawin->eLockSubj >= 0) &&
+               !dgawin->pMbs->prevLocked[(int)dgawin->eLockSubj]) {
+	dgawin->changeMask |= DGA_CHANGE_SITE;
+	dgawin->siteChgReason = DGA_SITECHG_INITIAL;
+	dgawin->pMbs->prevLocked[dgawin->eLockSubj] = 1;
+	return;
+    }
+
+    /* check for cache change */
+    if (dgawin->changeMask & DGA_CHANGE_CACHE) {
+	dgawin->changeMask |= DGA_CHANGE_SITE;
+	dgawin->siteChgReason = DGA_SITECHG_CACHE;
+	return;
+    }
+
+    /* check for alias change */
+    if (dgawin->changeMask & DGA_CHANGE_ALIAS) {
+	dgawin->changeMask |= DGA_CHANGE_SITE;
+	dgawin->siteChgReason = DGA_SITECHG_ALIAS;
+	return;
+    }
+
+    /* check for mbufset composition change */
+    if (dgawin->changeMask & DGA_CHANGE_MBUFSET) {
+	dgawin->changeMask |= DGA_CHANGE_SITE;
+	dgawin->siteChgReason = DGA_SITECHG_MB;
+	return;
+    }
+}
+
+
+/*
+** If we can report any changes through notification, do so now.
+*/
+
+void
+dgai_mbsmemb_notify (_Dga_window dgawin)
+{
+    /* report any mbufset change */
+    if (dgawin->changeMask & DGA_CHANGE_MBUFSET) {
+	dgai_mbsmemb_notifyMbChg(dgawin);
+    }
+
+    if (dgawin->changeMask & DGA_CHANGE_SITE) {
+	 dgai_mbsmemb_notifySiteChg(dgawin);
+    }
+
+    if (dgawin->changeMask & DGA_CHANGE_OVLSTATE) {
+	dgai_mbsmemb_notifyOvlState(dgawin);
+    }
+
+    /* there are no notify functions for the following:
+       clip, cursor, bstore, cache */
+}
+
+void
+dgai_mbsmemb_devinfo_update(_Dga_window dgawin)
+{
+    if (!DGA_LOCKSUBJ_VALID(dgawin, dgawin->eLockSubj) || 
+	dgawin->changeMask & DGA_CHANGE_ZOMBIE) {
+	return;
+    }
+
+    if        (DGA_LOCKSUBJ_WINDOW(dgawin, dgawin->eLockSubj)) {
+	/* check for window devinfo change */
+	if (dgawin->c_devinfoseq != *dgawin->s_devinfoseq_p) {
+	    dgawin->changeMask |= DGA_CHANGE_DEVINFO;
+	    dgawin->c_devinfoseq = *dgawin->s_devinfoseq_p;
+	}
+    } else if (!DGA_LOCKSUBJ_VIEWABLE(dgawin, dgawin->eLockSubj)) {
+	/* check for nonviewable mbuf devinfo change */
+	dgai_nmbuf_devinfo_update(dgawin);
+    }
+
+    /* Note: viewable mbufs don't have dev info */
+}
+
+static void
+dgai_mbsmemb_notifySiteChg (_Dga_window dgawin)
+{
+    if (dgawin->siteNotifyFunc) {
+	(*dgawin->siteNotifyFunc)((Dga_drawable)dgawin, dgawin->eLockSubj,
+				  dgawin->siteNotifyClientData,
+				  dgawin->siteChgReason);
+	dgawin->changeMask &= ~DGA_CHANGE_SITE;
+	dgawin->siteChgReason = DGA_SITECHG_UNKNOWN;
+    } else {
+	/* client must find out through dga_draw_sitechg */
+    }
+}
+
+
+static void
+dgai_mbsmemb_notifyMbChg (_Dga_window dgawin)
+{
+    /* figure out reason for change */
+    if        (!dgawin->prevWasMbuffered && dgawin->pMbs) {
+	dgawin->mbChgReason = DGA_MBCHG_ACTIVATION;
+    } else if (dgawin->prevWasMbuffered && !dgawin->pMbs) {
+	dgawin->mbChgReason = DGA_MBCHG_DEACTIVATION;
+    } else if (dgawin->prevWasMbuffered && dgawin->pMbs) {
+	dgawin->mbChgReason = DGA_MBCHG_REPLACEMENT;
+    } else {
+	/* this might happen if the mbufset was activated and then, in
+	   the same update phase, deactivated.  In this case, allow it,
+	   but just don't report any changes */
+	dgawin->changeMask &= ~DGA_CHANGE_MBUFSET;
+	dgawin->mbChgReason = DGA_MBCHG_UNKNOWN;
+	return;
+    }
+    
+    if (dgawin->mbNotifyFunc) {
+	(*dgawin->mbNotifyFunc)((Dga_drawable)dgawin, 
+				dgawin->mbNotifyClientData,
+				dgawin->mbChgReason); 
+	dgawin->changeMask &= ~DGA_CHANGE_MBUFSET;
+	dgawin->mbChgReason = DGA_MBCHG_UNKNOWN;
+    } else {
+	/* client must find out through dga_draw_mbchg */
+    }
+}
+
+
+static void
+dgai_mbsmemb_notifyOvlState (_Dga_window dgawin)
+{
+    if (dgawin->ovlStateNotifyFunc) {
+	(*dgawin->ovlStateNotifyFunc)((Dga_drawable)dgawin,
+				      dgawin->ovlStateNotifyClientData,
+				      dgawin->c_ovlstate);
+	dgawin->changeMask &= ~DGA_CHANGE_OVLSTATE;
+    } else {
+	/* client must find out through dga_draw_sitechg */
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/lib/libdga/sun-src/mbuf_update.c	Fri Nov 13 13:30:43 2009 -0800
@@ -0,0 +1,453 @@
+/* Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ *
+ * 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, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * 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
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR 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.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+#pragma ident	"@(#)mbuf_update.c	35.2	09/11/09 SMI"
+
+/*
+** mbuf_update.c
+**
+** Routines of the update phase for multibuffers.
+*/
+
+#include <assert.h>
+#ifdef SERVER_DGA
+#include <X11/Xlib.h>
+#endif /* SERVER_DGA */
+#include "dga_incls.h"
+#include "pix_grab.h"
+#include "mbufsetstr.h"
+
+static void	dgai_mbuf_getLastSeqs (_Dga_window dgawin, DgaLastSeqsPtr pLastSeqs, short bufIndex);
+static int	dgai_mbuf_syncAgain (_Dga_window dgawin, DgaLastSeqsPtr pLastSeqs);
+static void	dgai_mbuf_mb_update (_Dga_window dgawin);
+static void	dgai_mbuf_syncLockSubj (_Dga_window dgawin);
+static void	dgai_mbuf_figureDerivChgs (_Dga_window dgawin);
+
+/*
+** Note: On every alias or mbufset change, we will report the following
+** types of changes. See comment at start of win_update.c for reason why we
+** don't try to optimize change reporting.  
+**
+**	site
+**	clip
+**	curs
+**      bstore
+**	cache (nonviewable mbufs only)
+**
+** TODO: ISSUE: since an alias change occurs on every multibuffer frame,
+** if we don't optimize for multibuffers this could add unwanted per-frame 
+** overhead.  Is it significant?  If so, we are forced to optimize alias 
+** change reporting.  Composition changes are so infrequent that it still 
+** won't be worth optimizing the reporting of them. (Note: this issue 
+** doesn't apply to windows.)
+*/
+
+
+/*
+** ENTRY ROUTINE FOR MULTIBUFFER UPDATE PHASE 
+*/
+
+int
+dgai_mbuf_update (_Dga_window dgawin, short bufIndex)
+{
+    DgaLastSeqs		lastSeqs;
+    DgaMbufSetPtr	pMbufSet;
+
+    /*
+     * Before we get going check to make sure that composition changes
+     * have been noticed.  If we don't and the number of multibuffers
+     * has increased bad things will happen.
+     */
+
+    if (dgawin->c_mbufseq != *dgawin->s_mbufseq_p)
+	dgai_mbsmemb_syncMbufset(dgawin);
+
+    /*
+    ** 1. The first thing we do in the update phase is to synchronize
+    **    the client structure.  When all pertinent client change
+    **    counters match the server, we are synchronized.  The 
+    **    reason we must do this in a loop is that some of the
+    **    synchronizations require us to temporarily unlock and 
+    **    relock.  While the drawable is unlocked, it can undergo
+    **    more changes, so we may need to start the synchronization
+    **    process over.
+    */
+
+    pMbufSet = dgawin->pMbs;
+    /* Determine sequence counts for state reported to client */
+    dgai_mbuf_getLastSeqs(dgawin, &lastSeqs, bufIndex);
+
+    /* start accumulating changes */
+    dgawin->changeMask = 0;
+
+    /* repeat synchronization functions as needed through possible unlock/relocks */
+    do {
+
+	/* first, see if the window shared info is still valid */
+	if (dgai_mbsmemb_syncZombie(dgawin)) {
+	    break;
+        }
+
+	/* the first thing we must change is the multibuffer state.
+	   This may later the effective lock subject, whose type the
+	   other synchronization checks depend on */
+	if (lastSeqs.mbufseq != *dgawin->s_mbufseq_p) {
+	    dgai_mbuf_mb_update(dgawin);
+	    lastSeqs.mbufseq = *dgawin->s_mbufseq_p;
+	    pMbufSet->mbufseq[bufIndex] = lastSeqs.mbufseq;
+	}
+
+	/* synchronize with current changes to attributes of
+	   the effective lock subject -- depends on the type
+	   of the current lock subject */
+	if        (DGA_LOCKSUBJ_WINDOW(dgawin, dgawin->eLockSubj)) {
+	    dgai_win_syncChanges(dgawin, &lastSeqs);
+	} else if (DGA_LOCKSUBJ_VMBUFFER(dgawin, dgawin->eLockSubj)) {
+	    dgai_vmbuf_syncChanges(dgawin, &lastSeqs, bufIndex);
+	} else if (DGA_LOCKSUBJ_NMBUFFER(dgawin, dgawin->eLockSubj)) {
+	    dgai_nmbuf_syncChanges(dgawin);
+	} else {
+	    /* should never happen */
+	    assert(0);
+	}
+
+	/* Note: whether we need to sync again depends on the type too */
+    } while (dgai_mbuf_syncAgain(dgawin, &lastSeqs));
+
+    /* Check if the devinfo has changed */
+    dgai_mbsmemb_devinfo_update(dgawin);
+
+    /* 
+    ** 2. The foregoing synchronization step has determined whether 
+    **    any attribute changes have occurred.  We must now determine
+    **    if there are any derivative changes to report.
+    */
+    dgai_mbuf_figureDerivChgs(dgawin);
+
+
+    /* 
+    ** 3. Next, we must report changes through notification functions,
+    **    if possible.
+    */
+
+    /* report any changes that we can through notification */
+    dgai_mbsmemb_notify(dgawin);
+
+
+    /* 
+    ** 4. Lastly, indicate that we are fully synchronized and get out.
+    */
+
+    /* the dgawin client structure is now fully synchronized with the
+       shared info */
+    dgawin->c_wm_chngcnt[bufIndex + 1] = *dgawin->s_chngcnt_p;
+
+    /* if there are still any changes that were not notified through notification
+       functions, DGA_DRAW_MODIF will return nonzero (the client is
+       supposed to call this routine immediately following the lock).
+       This will cause a well-behaved client to synchronize with 
+       the remaining unreported changes */
+    return (dgawin->changeMask);
+}
+
+
+static void
+dgai_mbuf_getLastSeqs (_Dga_window dgawin, DgaLastSeqsPtr pLastSeqs, short bufIndex)
+{
+    DgaMbufSetPtr	pMbufSet = dgawin->pMbs;
+
+    if (DGA_LOCKSUBJ_WINDOW(dgawin, dgawin->eLockSubj)) {
+        pLastSeqs->mbufseq = dgawin->c_mbufseq;
+        pLastSeqs->clipseq = dgawin->c_clipseq;
+        pLastSeqs->curseq = dgawin->c_curseq;
+        pLastSeqs->rtnseq = dgawin->c_rtnseq;
+    } else {
+        pLastSeqs->mbufseq = pMbufSet->mbufseq[bufIndex];
+        pLastSeqs->clipseq = pMbufSet->clipseq[bufIndex];
+        pLastSeqs->curseq = pMbufSet->curseq[bufIndex];
+        pLastSeqs->rtnseq = dgawin->c_rtnseq;
+    }
+}
+
+
+/*
+** Returns nonzero if we are still not synchronized 
+*/
+
+static int
+dgai_mbuf_syncAgain (_Dga_window dgawin, DgaLastSeqsPtr pLastSeqs)
+{
+    /* if a multibuffer change happened, we're still not done */
+    if (pLastSeqs->mbufseq != *dgawin->s_mbufseq_p) {
+	return (1);
+    }
+
+    if (DGA_LOCKSUBJ_WINDOW(dgawin, dgawin->eLockSubj)) {
+	if ((pLastSeqs->clipseq == *dgawin->s_clipseq_p)  &&
+	    (pLastSeqs->curseq  == *dgawin->s_curseq_p)   &&
+	    (pLastSeqs->rtnseq  == *dgawin->s_rtnseq_p)) {
+	    return (0);
+	}
+    } else if (DGA_LOCKSUBJ_VMBUFFER(dgawin, dgawin->eLockSubj)) {
+	if ((pLastSeqs->clipseq == *dgawin->s_clipseq_p)  &&
+	    (pLastSeqs->curseq  == *dgawin->s_curseq_p)) {
+	    /* Note: viewable mbuf never has bstore to sync up to */
+	    return (0);
+	}
+    } else if (DGA_LOCKSUBJ_NMBUFFER(dgawin, dgawin->eLockSubj)) {
+	/* Note: we don't need to check the cacheseq here, because for
+	   a nonviewable drawable the cache is the only thing to sync 
+	   so there will never be any reason for it to be out-of-sync 
+	   when we get here */
+        return (0);
+    }
+
+    /* we're now all synchronized */
+    return (1);
+}
+
+
+/* 
+** Called at window lock time when we have detected an mbufset change.
+** At the return of this routine, dgawin->eLockSubj indicates the member
+** drawable for which subsequent changes are to be detected.
+*/
+
+static void
+dgai_mbuf_mb_update (_Dga_window dgawin)
+{
+    /* react to enable and composition changes */
+    dgai_mbsmemb_syncMbufset(dgawin);
+
+    /* if window is multibuffered we may need to synchronize */
+    if (dgawin->pMbs) {
+	WXINFO	*infop;
+	
+	infop = (WXINFO *) dgawin->w_info;
+
+	/* Now that we know the current mbufset composition, we know the
+	   number of multibuffers. if the real lock subject is beyond
+	   this, treat it as a zombie */
+	if (dgawin->rLockSubj != -1 &&
+	    dgawin->rLockSubj >= infop->wx_dbuf.number_buffers) {
+	    dgawin->changeMask |= DGA_CHANGE_ZOMBIE;
+	    return;
+	}	    
+
+	/* synchronize with any display buffer change */
+	dgai_mbuf_syncLockSubj(dgawin);
+
+	/* synchronize render buffer state (if necessary) */
+	dgai_mbsmemb_syncRendBuf(dgawin);
+
+    } else {
+	/* The window is no longer multibuffered. This multibuffer is a zombie */
+	dgawin->changeMask |= DGA_CHANGE_ZOMBIE;
+	return;
+    }
+
+    /* an mbufset change causes us to report changes to all attrs  */
+    { u_int reportChanges;
+      if (DGA_LOCKSUBJ_WINDOW(dgawin, dgawin->eLockSubj)) {
+	  reportChanges = DGA_WIN_CHANGEABLE_ATTRS;
+      } else if (DGA_LOCKSUBJ_VMBUFFER(dgawin, dgawin->eLockSubj)) {
+	  reportChanges = DGA_VMBUF_CHANGEABLE_ATTRS;
+      } else {
+	  reportChanges = DGA_NMBUF_CHANGEABLE_ATTRS;
+      }
+      dgawin->changeMask |= (DGA_CHANGE_MBUFSET | reportChanges);
+    }
+}
+
+/*
+** Determine effective lock subject for a multibuffered window.
+*/
+
+static void
+dgai_mbuf_syncLockSubj (_Dga_window dgawin)
+{
+    WXINFO	*infop;
+	
+    infop = (WXINFO *) dgawin->w_info;
+
+    /* see if there is buffer aliasing.  Buffer aliasing
+       can only happen in copy flip mode */
+    /* TODO Daryl  Is this true?  In document it talks about
+     * buffer aliasing with DGA_MBFLIP_VIDEO mode. */
+    if ((infop->w_mbsInfo.flipMode == DGA_MBFLIP_COPY) &&
+	(infop->wx_dbuf.display_buffer == dgawin->rLockSubj)) {
+	
+	/* when the buffer is aliased, the effective lock subject is
+	   always the main window */
+	dgawin->eLockSubj = -1;
+
+	if (dgawin->eLockSubj != dgawin->eLockSubjPrev) {
+
+	    /* an alias change causes us to report changes on all attributes */
+	    dgawin->changeMask |= (DGA_CHANGE_ALIAS | DGA_WIN_CHANGEABLE_ATTRS);
+
+	}
+    }
+}
+
+
+/*
+** In addition to the mbufset-common types of derivative changes, 
+** we may also need to cause a clip change to be reported.
+*/
+
+static void
+dgai_mbuf_figureDerivChgs (_Dga_window dgawin)
+{
+    int 	curViewable;
+    int		prevViewable;
+
+    /* common changes */
+    dgai_mbsmemb_figureDerivChgs(dgawin);
+
+    /* 
+    ** If we've switched from a viewable lock subject to 
+    ** a nonviewable one (or vice versa) force a clip change even
+    ** if the clip of the current effective lock subject has not changed.
+    ** This is because the clips of nonviewable drawables are
+    ** always rectangular and those of viewable ones may not be.
+    */
+    curViewable = DGA_LOCKSUBJ_VALID(dgawin, dgawin->eLockSubj) &&
+                  (dgawin->eLockSubj == -1 || 
+		   DGA_MBUF_ISVIEWABLE(dgawin->pMbs, dgawin->eLockSubj));
+    prevViewable = DGA_LOCKSUBJ_VALID(dgawin, dgawin->eLockSubjPrev) &&
+                  (dgawin->eLockSubjPrev == -1 || 
+		   DGA_MBUF_ISVIEWABLE(dgawin->pMbs, dgawin->eLockSubjPrev));
+    
+    if ((curViewable && !prevViewable) || 
+	(!curViewable && prevViewable)) {
+	dgawin->changeMask |= DGA_CHANGE_CLIP;
+    }
+}
+
+
+/*
+** Current lock subject is a viewable multibuffer. Synchronize with changes.
+*/
+
+void
+dgai_vmbuf_syncChanges (_Dga_window dgawin, DgaLastSeqsPtr pLastSeqs, short bufIndex)
+{
+    /* Note: viewable multibuffers share the clip and cursor state 
+       of the main window */
+
+    /* clip state of main window has changed? */
+    if (pLastSeqs->clipseq != *dgawin->s_clipseq_p) {
+	dgawin->changeMask |= DGA_CHANGE_CLIP;
+	dgai_win_clip_update(dgawin);
+	pLastSeqs->clipseq = *dgawin->s_clipseq_p;
+	dgawin->pMbs->clipseq[bufIndex] = pLastSeqs->clipseq;
+    }
+
+    /* cursor state of main window has changed? */
+    if (pLastSeqs->curseq != *dgawin->s_curseq_p) {
+	dgawin->changeMask |= DGA_CHANGE_CURSOR;
+	dgai_win_curs_update(dgawin);
+	pLastSeqs->curseq = *dgawin->s_curseq_p;
+	dgawin->pMbs->curseq[bufIndex] = pLastSeqs->curseq;
+    }
+
+    /* Note: viewable multibuffers do not yet have backing store */
+}
+
+
+/*
+** Current lock subject is a non-viewable multibuffer. Synchronize with changes.
+*/
+
+void
+dgai_nmbuf_syncChanges (_Dga_window dgawin)
+{
+    SHARED_PIXMAP_INFO	*infop;
+
+    /* don't try to synchronize if multibuffer is a zombie */
+    if ((dgawin->changeMask & DGA_CHANGE_ZOMBIE)) {
+	return;
+    }
+
+    /* first, see if the shared info is still valid */
+    infop = dgawin->pMbs->pNbShinfo[dgawin->eLockSubj];
+    if (infop->obsolete) {
+        dgawin->changeMask |= DGA_CHANGE_ZOMBIE;
+	return;
+    }
+
+    /* Note: a non-viewable multibuffer never has a cursor
+       or backing store.  And it's clip is always constant.  The
+       only thing that can change is the cache or devinfo state */
+
+    /* Has the cache changed? */
+    dgai_nmbuf_cache_update(dgawin);
+
+    /* Has the dev_info changed? */
+    dgai_nmbuf_devinfo_update(dgawin);
+}
+
+
+void 
+dgai_nmbuf_cache_update (_Dga_window dgawin) 
+{
+    DgaMbufSetPtr 		pMbs;
+    u_int			*s_cacheseq_p;
+
+    pMbs = dgawin->pMbs;
+    s_cacheseq_p = &(pMbs->pNbShinfo[dgawin->eLockSubj]->s_cacheseq);
+
+    if (pMbs->cacheSeqs[dgawin->eLockSubj] != *s_cacheseq_p) {
+	dgawin->changeMask |= DGA_CHANGE_CACHE;
+
+	/* synchronize change counts */
+	pMbs->cacheSeqs[dgawin->eLockSubj] = *s_cacheseq_p;
+    }
+}
+
+void 
+dgai_nmbuf_devinfo_update (_Dga_window dgawin) 
+{
+    DgaMbufSetPtr 		pMbs;
+    u_int			*s_devinfoseq_p;
+
+    pMbs = dgawin->pMbs;
+    s_devinfoseq_p = &(pMbs->pNbShinfo[dgawin->eLockSubj]->s_devinfoseq);
+
+    if (pMbs->devInfoSeqs[dgawin->eLockSubj] != *s_devinfoseq_p) {
+	dgawin->changeMask |= DGA_CHANGE_DEVINFO;
+
+	/* synchronize change counts */
+	pMbs->devInfoSeqs[dgawin->eLockSubj] = *s_devinfoseq_p;
+    }
+}
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/lib/libdga/sun-src/mbufset.c	Fri Nov 13 13:30:43 2009 -0800
@@ -0,0 +1,142 @@
+/* Copyright 1997 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ *
+ * 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, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * 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
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR 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.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+#pragma ident	"@(#)mbufset.c	35.3	09/11/09 SMI"
+
+/* 
+** mbufset.c - Routines to manipulate multibuffer set objects.
+*/
+
+#include <malloc.h>
+#ifdef SERVER_DGA
+#include <X11/Xlib.h>
+#endif /* SERVER_DGA */
+#include "dga_incls.h"
+#include "pix_grab.h"
+#include "mbufsetstr.h"
+
+static void dgai_mbufset_destroy (DgaMbufSetPtr pMbs);
+
+extern int dga_pixlist_add(Dga_token token, Display *dpy, Pixmap pix);
+
+/*
+** Create a client-side multibuffer set object based on information
+** in the shinfo of a window.  The window must be locked prior to calling.
+*/
+
+DgaMbufSetPtr
+dgai_mbufset_create (_Dga_window dgawin)
+{
+    DgaMbufSetPtr 	pMbs;
+    WXINFO		*infop;
+    DgaMbufSetShinfoPtr	pMbsInfo;
+    short		numBufs, i;
+    unsigned long	bufViewableFlags, bufMask;
+    Dga_token		token;
+    _Dga_pixmap		dgapix;
+    XID			*pShinfoId;
+
+    infop = (WXINFO *) dgawin->w_info;
+    pMbsInfo = &infop->w_mbsInfo;    
+    token = (Dga_token) pMbsInfo->nmbufShpxToken;
+    pShinfoId = &(pMbsInfo->nmbufIds[0]);
+
+    /* allocate mbufset client structure */
+    if (!(pMbs = (DgaMbufSetPtr) malloc(sizeof(DgaMbufSet)))) {
+	return (NULL);
+    }
+
+    numBufs = infop->wx_dbuf.number_buffers;
+    pMbs->numBufs = numBufs;
+
+    for (i = 0; i < numBufs;  i++) {
+	pMbs->pNbPixmaps[i] = NULL;
+    }
+
+    bufViewableFlags = pMbsInfo->bufViewableFlags;
+    bufMask = 1L;
+    for (i = 0; i < numBufs;  i++, pShinfoId++) {
+	if (!(bufViewableFlags & bufMask)) {
+	    if (!dga_pixlist_add(token, dgawin->w_dpy, (Pixmap)*pShinfoId) ||
+	        !(dgapix = dga_pix_grab(token, (Pixmap)*pShinfoId))) {
+		goto Bad;
+	    }
+	    pMbs->pNbPixmaps[i] = dgapix;
+	    pMbs->pNbShinfo[i] = (SHARED_PIXMAP_INFO *)dgapix->p_infop;
+	} else {
+	    pMbs->pNbShinfo[i] = NULL;
+	}
+	pMbs->mbufseq[i] = 0;
+	pMbs->clipseq[i] = 0;
+	pMbs->curseq[i] = 0;
+	pMbs->cacheSeqs[i] = 0;
+	pMbs->devInfoSeqs[i] = 0;
+	pMbs->prevLocked[i] = 0;
+	bufMask = bufMask << 1;
+    }
+
+    /* success */
+    pMbs->refcnt = 1;
+    return (pMbs);
+
+Bad:
+    dgai_mbufset_destroy(pMbs);
+    return (NULL);
+}
+
+
+void
+dgai_mbufset_incref (DgaMbufSetPtr pMbs)
+{
+    pMbs->refcnt++;
+}
+
+
+static void
+dgai_mbufset_destroy (DgaMbufSetPtr pMbs)
+{
+    short i;
+
+    for (i = 0; i < pMbs->numBufs;  i++) {
+	if (pMbs->pNbPixmaps[i]) {
+	    dga_pix_ungrab(pMbs->pNbPixmaps[i]);
+	}
+    }
+    free(pMbs);
+}
+
+void
+dgai_mbufset_decref (DgaMbufSetPtr pMbs)
+{
+    if ((int)(--(pMbs->refcnt)) <= 0) {
+	dgai_mbufset_destroy(pMbs);
+    }
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/lib/libdga/sun-src/mbufsetstr.h	Fri Nov 13 13:30:43 2009 -0800
@@ -0,0 +1,73 @@
+/* Copyright 1994 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ *
+ * 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, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * 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
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR 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.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+#pragma ident	"@(#)mbufsetstr.h	35.2	09/11/09 SMI"
+
+#ifndef	_DGA_MBUFSETSTR_H
+#define	_DGA_MBUFSETSTR_H
+
+/*
+** Client structure for multibuffer set.
+*/
+
+/*
+** A "multibuffer set" (mbufset) stores client-side info about the multibuffers
+** attached to a multibuffered window.
+*/
+
+typedef struct dga_mbufset {
+    unsigned int	refcnt;
+    short		numBufs;
+    _Dga_pixmap		pNbPixmaps[DGA_MAX_GRABBABLE_BUFS];	
+
+    /* shared info for nonviewable mbufs.  Indices that
+       correspond to viewable mbufs are always NULL */
+    SHARED_PIXMAP_INFO	*pNbShinfo[DGA_MAX_GRABBABLE_BUFS];	
+
+    u_int		mbufseq[DGA_MAX_GRABBABLE_BUFS];
+    u_int		clipseq[DGA_MAX_GRABBABLE_BUFS];
+    u_int		curseq[DGA_MAX_GRABBABLE_BUFS];
+
+    /* last recorded cache count for nonviewable mbufs.  Indices that
+       correspond to viewable mbufs are always 0 */
+    u_int		cacheSeqs[DGA_MAX_GRABBABLE_BUFS];	
+
+    /* last recorded cache count for nonviewable mbufs.  Indices that
+       correspond to viewable mbufs are always 0 (viewable mbufs 
+       don't have devce info) */
+    u_int		devInfoSeqs[DGA_MAX_GRABBABLE_BUFS];	
+
+    /* Has the buffer been locked previously? */
+    char		prevLocked[DGA_MAX_GRABBABLE_BUFS];
+
+} DgaMbufSet;
+
+
+#endif /* _DGA_MBUFSETSTR_H */
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/lib/libdga/sun-src/pix_grab.c	Fri Nov 13 13:30:43 2009 -0800
@@ -0,0 +1,539 @@
+/* Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ *
+ * 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, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * 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
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR 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.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+#pragma ident	"@(#)pix_grab.c	35.10	09/11/09 SMI"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <netdb.h>
+#ifdef SERVER_DGA
+#include <X11/Xlib.h>
+#else
+#include <unistd.h>
+#include <sys/fcntl.h>
+#include <sys/mman.h>
+#endif /* SERVER_DGA */
+
+#include "dga_incls.h"
+#include "pix_grab.h"
+
+
+
+#define NDIGITS     8
+#define MINSHMEMSIZE    (8*1024)
+#define MAXSHMEMSIZE    (0x00040000)
+#define MAXSHPXMEMSIZE    (0x01000000)
+#define SHPX_MAX_CLIENTS    64
+#define SHPX_MAX_PIXMAPS    341
+
+
+
+/* Some structure definition for internal bookkeeping
+ * NOTE: there is only one locking window created per device for
+ * the use of all pixmaps on that device 
+*/
+typedef struct dga_pixlist {
+    Dga_token       	p_token;     	  /* Token associated with pix */
+    int             	num_clientp;
+    struct dga_pixmap   *dga_clientplist; /*List of client ptrs in pix */
+    struct dga_pixlist  *next_plist;  	  /* Next link in the dga list */
+} *Dga_pixlist;
+
+static struct dga_pixlist *dga_plist = NULL;
+#ifdef SERVER_DGA
+extern  SHPX_CLIENT_ENTRY    shpx_client_directory[];
+extern  int                 Dga_shpx_client_count;
+#else
+static  SHPX_CLIENT_ENTRY   shpx_client_directory[SHPX_MAX_CLIENTS];
+static  int                 Dga_shpx_client_count = 0;
+#endif /* SERVER_DGA */
+static u_long pagesize;
+
+extern int _dga_winlockat(u_long cookie, int **lockp, int **unlockp);
+extern int _dga_winlockdt(int *lockp, int *unlockp);
+extern void *_dga_is_X_pixmap(Pixmap pix, Display **dpyp);
+
+/******************************************
+ *
+ * dga_pix_grab:
+ *
+ *  create shared memory file for pixmap information
+ *  map to lock page
+ *
+ *  arguments:
+ *
+ *  Dga_token   token;  INPUT
+ *      magic cookie supplied by the server
+ *
+ *  returns a user virtual address for a dga_window structure.
+ *  returns NULL if anything goes awry.
+ *
+ *****************************************/
+
+Dga_pixmap
+dga_pix_grab(token, pix)
+    Dga_token   token;
+    Pixmap  pix;
+{
+    SHARED_PIXMAP_INFO *infop;
+    _Dga_pixmap clientp ;
+    Display  *dpy;
+    int c_fd, i, entry_found;
+    u_int	port;
+    size_t size;
+    SHPX_DIRECTORY  *shpx_dir;
+    char    c_fn[256];
+    char   *dpystr;
+    static char    path[256];
+    char    host[MAXHOSTNAMELEN];
+    Dga_lockp	lockp, unlockp;
+
+    /* Remember to account for multiple clients grabbing the same pixmap
+     * later
+     */ 
+
+    /* First determine if this is a X pixmap - if so, get 
+     * the dpy and pixid
+    */
+    if (!_dga_is_X_pixmap(pix, &dpy)) {
+#ifdef DEBUG
+        (void) fprintf(stderr, "dga_pix_grab: Unsupported pixmap type\n");
+#endif
+        return (PIX_FAILED);
+    }
+
+    if (!dga_plist) {
+	/* This is the first time through this code so get the
+	 * retained path */
+	if (!XDgaGetRetainedPath(dpy, pix, path)) {
+#ifdef DEBUG
+	    (void) fprintf(stderr, 
+		"dga_pix_grab: XDgaGetRetainedPath failed\n");
+#endif
+	    return (PIX_FAILED);
+	}	
+    }
+#ifndef SERVER_DGA
+    /*  Now get the port number for this display */
+    dpystr = DisplayString(dpy);
+    if (dpystr[0] == ':')
+        (void) sscanf(dpystr, ":%u", &port);
+    else
+        (void) sscanf(dpystr, "%[^:]:%u", host, &port);
+
+    if (Dga_shpx_client_count == 0) {
+    	/* Now start by initializing all the per client structs - 
+    	 * all 64 of them  - if thie is the first time you 
+    	 * are grabbing  a pixmap
+    	*/
+        for (i = 0; i < SHPX_MAX_CLIENTS; i++) {
+        	shpx_client_directory[i].cid = 0;
+        	shpx_client_directory[i].shpx_directory = NULL;
+        	shpx_client_directory[i].fd = 0;
+        	shpx_client_directory[i].size = 0;
+        	shpx_client_directory[i].npix = 0;
+        }
+    } else 
+#endif /* SERVER_DGA */
+    {
+    	/* If it is not the first time, see if this client has grabbed
+	 * a pixmap before and therefore done all the set up.
+	 * Search through the client structures for matching token
+	 */
+        i = 0;
+        while ((i < SHPX_MAX_CLIENTS) &&
+        	(shpx_client_directory[i].cid != token)) {
+            i++;
+	}
+        if ((i == SHPX_MAX_CLIENTS) &&
+        	(Dga_shpx_client_count == SHPX_MAX_CLIENTS)) {
+            return(0);
+        }
+    }
+    
+    if ((Dga_shpx_client_count > 0) && (i < SHPX_MAX_CLIENTS)) {
+	/* We found a match and the pixmap already has been grabbed before */
+        shpx_dir = shpx_client_directory[i].shpx_directory;
+	shpx_client_directory[i].npix++;
+    } 
+#ifndef SERVER_DGA
+    else {
+	/* This client has Never grabbed before set up the direct 
+	 * structure etc.
+         * Open the shared file using server command line 
+	 * -sharedretainedpath variable for file path if it is 
+	 * set, else use /tmp.  This is because these files can 
+	 * be very big and there usually isn't much space in /tmp.
+         */
+        c_fn[0] = 0;
+
+
+        if ((path) && (strlen(path) > 0))
+	    strcpy(c_fn, path);
+         else 
+	    strcpy(c_fn, "/tmp");
+
+        strcat(c_fn, PIX_FILE);
+        size = strlen(c_fn);
+        sprintf(c_fn+size,"%01x.%08x", port, token);
+ 
+#ifdef SYSV
+        pagesize = sysconf(_SC_PAGESIZE);
+#else
+        pagesize = getpagesize();
+#endif
+        i = 0;
+        while ((i < SHPX_MAX_CLIENTS) && (shpx_client_directory[i].cid != 0))
+        	i++;
+        if ((c_fd = open(c_fn,O_RDWR ,0666)) < 0) 
+        	return(0);
+        /* map the shpx directory for this client and map at 4 megabytes */
+        shpx_dir =   (SHPX_DIRECTORY *)mmap(0,
+                MAXSHPXMEMSIZE,
+                PROT_READ|PROT_WRITE,
+                MAP_SHARED,
+                c_fd,
+                (off_t)0);
+ 
+        if (shpx_dir == (SHPX_DIRECTORY *)-1) {
+	    close(c_fd);
+	    return(0);
+        }
+        Dga_shpx_client_count++;
+        shpx_client_directory[i].cid = token; /* BMAC - correct?? */
+        shpx_client_directory[i].shpx_directory = shpx_dir;
+        shpx_client_directory[i].fd = c_fd; /* no longer need to save it */
+	shpx_client_directory[i].size = shpx_dir[0].shpx_entry_0.s_size;
+	shpx_client_directory[i].npix = 1;
+    }
+#endif /* SERVER_DGA */
+
+    /* The first 2 entries on the file have special meaning. */
+    i = 2;
+    entry_found = 0;
+    while ((i < SHPX_MAX_PIXMAPS) && (!entry_found)) {
+	if (shpx_dir[i].shpx_entry.xid == pix) 
+	    entry_found = 1;
+        else 
+	    i++;
+    }
+ 
+    if (!entry_found) {
+#ifndef SERVER_DGA
+        close(c_fd);
+#endif /* SERVER_DGA */
+        return(0);
+    }
+    infop = (SHARED_PIXMAP_INFO *)
+            (((u_char *)shpx_dir) + shpx_dir[i].shpx_entry.offset);
+ 
+    if ((infop->magic != PXMPMAGIC) || (infop->version > PXMPVERS)) {
+#ifndef SERVER_DGA
+        close(c_fd);
+#endif /* SERVER_DGA */
+        return(0);
+    }
+    if (infop->obsolete) {
+#ifndef SERVER_DGA
+        close(c_fd);
+#endif /* SERVER_DGA */
+        return(0);
+    }
+    /* BMAC - Find out about the rache code - what should I do there? */
+
+    /* Now fill out the Dga_pixmap structure */
+    if( (clientp = (_Dga_pixmap) malloc(sizeof(struct dga_pixmap))) == NULL )
+        return NULL ;
+
+    clientp->drawable_type = DGA_DRAW_PIXMAP;
+    clientp->p_lockcnt = 0;
+    clientp->obsolete = 0;
+    clientp->p_modif = NULL;
+    clientp->p_infop = (void *)infop ;
+    clientp->c_chngcnt[0] = 0; 
+#ifdef MT
+    clientp->shadow_chngcnt[0] = 0;
+#endif
+    /* This is the new location added for locking performance
+     * For windows it pts to the second member in the c_wm_chngcnt
+     * array but here I think that it just pts to the previous field
+     * since for pixmaps the array ctr is -1 always
+    */
+    clientp->p_chngcnt_2nd = clientp->c_chngcnt +1;
+
+    clientp->s_chngcnt_p = &(infop->s_modified);	
+    clientp->c_dirchngcnt = shpx_dir[1].shpx_entry_1.s_dir_seq;
+    clientp->s_dirchngcnt_p = &(shpx_dir[1].shpx_entry_1.s_dir_seq);
+    clientp->c_devinfocnt = 0;
+    clientp->s_devinfocnt_p = &(infop->s_devinfoseq);
+    clientp->c_cachecnt = 0;
+    clientp->s_cachecnt_p = &(infop->s_cacheseq);	
+    clientp->c_cached = 0;
+    clientp->s_cached_p = &(infop->cached);	
+    clientp->p_dir_index = i;
+    clientp->p_shpx_dir = (void *)shpx_dir; /*CHECK ME */
+#ifdef MT
+    if (dgaThreaded) {
+	clientp->p_unlock_func = dgai_unlock;
+    } else {
+	clientp->p_unlock_func = NULL;
+    }
+#else
+    clientp->p_lock_func = NULL;
+    clientp->p_unlock_func = NULL;
+#endif
+    clientp->p_update_func = (int(*)())dgai_pix_update;
+    clientp->p_shpx_client = NULL;
+    clientp->p_token = token;
+    clientp->c_size = infop->s_size;
+    clientp->c_pixels = (u_char *)(infop + 1);
+    clientp->depth = infop->depth;
+    clientp->linebytes = infop->linebytes;
+    clientp->p_next = NULL;
+    clientp->p_infofd = NULL;
+    clientp->pix_flags = PIX_NOTICE_CLIPCHG;	
+    clientp->p_dpy = 0;
+    clientp->p_id = NULL;
+    clientp->p_client = NULL;
+    clientp->changeMask = NULL;
+    clientp->siteChgReason = NULL;
+    clientp->siteNotifyFunc = NULL;
+    clientp->siteNotifyClientData = NULL;
+
+#ifdef SERVER_DGA
+    clientp->p_lockp = infop->p_lockp;
+    clientp->p_unlockp = infop->p_unlockp;
+#else
+    lockp = NULL;	/* init to NULL for check below */
+    unlockp = NULL;
+
+    /* Check to see if there are already a lockp and unlockp 
+     * for this device--if not create 'em
+    */
+    if (dga_plist) {
+	lockp = dga_plist->dga_clientplist->p_lockp;
+	unlockp = dga_plist->dga_clientplist->p_unlockp;
+    }
+
+    if (!lockp) {
+	/* only get new lock pages if necessary */
+        if( _dga_winlockat(infop->p_cookie, &lockp, &unlockp) != 0 ) {
+            munmap((caddr_t)infop, MAXSHPXMEMSIZE);
+/* REMIND Daryl: What else do we need to clean up? */
+            free(clientp) ;
+            return(NULL);
+        }
+    }
+
+    clientp->p_lockp = lockp;
+    clientp->p_unlockp = unlockp;
+#endif /* SERVER_DGA */
+
+    /* add to linked list of grabbed pixmaps - for internal bookkeeping
+    */
+    if (!dga_plist) {
+       if ((dga_plist =
+	    (Dga_pixlist) malloc(sizeof(struct dga_pixlist))) == NULL )
+            return NULL ;
+       	dga_plist->p_token = token;
+       	dga_plist->num_clientp = 1;
+       	dga_plist->dga_clientplist = clientp;
+       	dga_plist->next_plist = NULL;
+    } else {
+       struct dga_pixlist *new_plist;
+
+       if ((new_plist =               
+                   (Dga_pixlist) malloc(sizeof(struct dga_pixlist))) == NULL )
+        return NULL;
+       new_plist->p_token = token;
+       new_plist->num_clientp = 1;
+       new_plist->dga_clientplist = clientp;
+       new_plist->next_plist = dga_plist;
+       dga_plist = new_plist;
+    }
+#ifdef MT
+    if (dgaThreaded) {
+	clientp->mutexp = &dgaGlobalPixmapMutex;
+    } else {
+	clientp->mutexp = NULL;
+    }
+#endif
+    return ((Dga_pixmap) clientp);
+}
+
+void
+dga_pix_ungrab(clientpi)
+Dga_pixmap clientpi;
+{
+    _Dga_pixmap clientp = (struct dga_pixmap *)clientpi;
+    Dga_pixlist	prev_pixlist = NULL;
+    Dga_pixlist pixlist = dga_plist;
+    u_int	i;
+    
+    /* Find pixmap in dga_plist */
+    while (pixlist) {
+	if (pixlist->dga_clientplist == clientp) {
+#ifndef SERVER_DGA
+            i = 0;
+            while ((i < SHPX_MAX_CLIENTS) &&
+        	    (shpx_client_directory[i].cid != pixlist->p_token)) {
+                i++;
+	    }
+            if ((i == SHPX_MAX_CLIENTS) &&
+        	    (Dga_shpx_client_count == SHPX_MAX_CLIENTS)) {
+                return;
+            }
+	    shpx_client_directory[i].npix--;
+	    if (!shpx_client_directory[i].npix) {
+		munmap((caddr_t)shpx_client_directory[i].shpx_directory, 
+		       MAXSHPXMEMSIZE);
+		close(shpx_client_directory[i].fd);
+		shpx_client_directory[i].cid = 0;
+		shpx_client_directory[i].shpx_directory = NULL;
+		shpx_client_directory[i].fd = 0;
+		shpx_client_directory[i].size = 0;
+	    }	
+#endif /* SERVER_DGA */
+
+	    if (prev_pixlist)
+	        prev_pixlist->next_plist = pixlist->next_plist;
+            else
+		dga_plist = pixlist->next_plist;
+#ifndef SERVER_DGA
+            if (!dga_plist)  {
+                _dga_winlockdt(clientp->p_lockp, clientp->p_unlockp);
+            }
+#endif /* SERVER_DGA */
+	    free(pixlist);
+	    free(clientp);
+		if(--Dga_shpx_client_count < 0) 
+			Dga_shpx_client_count = 0;
+	    return;
+        } else {
+	    prev_pixlist = pixlist;
+	    pixlist = pixlist->next_plist;
+        }
+    }
+}
+
+#ifdef COMMENT
+/* TODO: Daryl what is this routine supposed to be used for??? */
+int 
+dga_pix_sync(clientpi)
+Dga_pixmap clientpi;
+{
+    _Dga_pixmap clientp = (struct dga_pixmap *)clientpi;
+	/* this checks to see if the shared pixmap info
+	 * area has changed and if so reinits the data
+	*/
+	/* This routine seems to requoire that the handle have
+	1. if the pixmap is cached or not
+	2. what type the pixmap is = like retained one??
+	3. something called sh_rache_scr0, sh_rache_scr1;
+	4. something called sh_Scr_Virt[];      virtual screen table */
+}
+#endif
+
+int 
+dga_pix_cachechg(clientpi)
+Dga_pixmap clientpi;
+{
+    _Dga_pixmap clientp = (struct dga_pixmap *)clientpi;
+    
+    if (clientp->c_cachecnt != *(clientp->s_cachecnt_p)) {
+	/* Something changed */
+	clientp->c_cachecnt = *(clientp->s_cachecnt_p);
+	return 1;
+    } else
+	/* Nothing has changed */
+	return 0;
+}
+
+int 
+dga_pix_cached(clientpi)
+Dga_pixmap clientpi;
+{
+    _Dga_pixmap clientp = (struct dga_pixmap *)clientpi;
+
+    if (clientp->c_cached != *(clientp->s_cached_p)) {
+	/* Something changed */
+	clientp->c_cached = *(clientp->s_cached_p);
+	return 1;
+    } else
+	/* Nothing has changed */
+	return 0;
+}
+
+char *
+dga_pix_devname(clientpi)
+Dga_pixmap clientpi;
+{
+    _Dga_pixmap clientp = (struct dga_pixmap *)clientpi;
+    /* CHECK THIS ! */
+    return ((char *) PIX_INFOP(clientp)->scr_name);
+}
+
+void * 
+dga_pix_pixels(clientpi)
+Dga_pixmap clientpi;
+{
+    _Dga_pixmap clientp = (struct dga_pixmap *)clientpi;
+    
+    return ((void*)clientp->c_pixels);
+}
+
+int 
+dga_pix_linebytes(clientpi)
+Dga_pixmap clientpi;
+{
+    _Dga_pixmap clientp = (struct dga_pixmap *)clientpi;
+    
+    return (clientp->linebytes);
+}
+
+
+u_char 
+dga_pix_depth(clientpi)
+Dga_pixmap clientpi;
+{
+   _Dga_pixmap clientp = (struct dga_pixmap *)clientpi; 
+    return (clientp->depth);
+}
+
+void * 
+dga_pix_devinfo(clientpi)
+Dga_pixmap clientpi;
+{
+    _Dga_pixmap clientp = (struct dga_pixmap *)clientpi;
+    return (((char *)clientp->p_infop) + PIX_INFOP(clientp)->device_offset);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/lib/libdga/sun-src/pix_grab.h	Fri Nov 13 13:30:43 2009 -0800
@@ -0,0 +1,76 @@
+/* Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ *
+ * 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, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * 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
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR 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.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+#pragma ident	"@(#)pix_grab.h	35.2	09/11/09 SMI"
+
+#ifndef _PIX_GRAB_H
+#define _PIX_GRAB_H
+
+#ifndef PMODIF          	
+#define PMODIF  1       	/* server has set a new cache */
+#define PIX_FILE "/shpxm"  	/* Shared info file base name*/
+                    		/* name is base name + port # + '.'  */
+                    		/* + pixmap id               */
+#define PIX_FAILED  0           /* Fail Value returned from pix funcs     */
+#define PIX_PASSED  -1          /* Pass Value returned from pix funcs     */
+
+/* client structure's pix_flag values */
+#define PIX_NOTICE_CLIPCHG	1
+
+/*
+ *  Shared Pixmap Information.  This structure contains the information
+ *  necessary to allow the server and client to share access to a DGA
+ *  pixmap .  This information is located in the first page of
+ *  the shared memory created by the server in response to a call to
+ *  XDgaGrabPixmap().  The server communicates the current state
+ *  of the shared pixmap to the client through the fields within
+ *  this structure.
+ */
+ 
+typedef struct shpx_client_entry {
+    u_int     cid;         /* client id */
+    SHPX_DIRECTORY  *shpx_directory; /* server's per client shpx dir */
+    u_int     fd;      	   /* server's per client file descrptr*/
+    u_int     size;        /* client file size */
+    u_int     npix;        /* number of pixmaps using this entry */
+} SHPX_CLIENT_ENTRY;
+
+
+/*
+ *  Internal DGA Pixmap Macros
+ */
+ 
+#define PIX_INFOP(clientp) ((SHARED_PIXMAP_INFO *) ((clientp)->p_infop))
+
+/* definitions of lock marcos for pixmaps - move this to dga.h later */
+
+
+/* DGA_LOCK_SRC_AND_DST will go here after they are debugged */ 
+#endif  /* PMODIF */
+#endif /* _PIX_GRAB_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/lib/libdga/sun-src/pix_inquiry.c	Fri Nov 13 13:30:43 2009 -0800
@@ -0,0 +1,254 @@
+/* Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ *
+ * 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, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * 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
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR 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.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+#pragma ident	"@(#)pix_inquiry.c	35.2	09/11/09 SMI"
+
+/*
+** pix_inquiry.c - state inquiry routines for pixmaps.
+*/
+
+#ifdef SERVER_DGA
+#include <X11/Xlib.h>
+#endif /* SERVER_DGA */
+#include "dga_incls.h"
+#include "pix_grab.h"
+
+Display *
+dgai_pix_display(_Dga_pixmap dgapix)
+{
+    return (dgapix->p_dpy);
+}
+
+char *
+dgai_pix_devname(_Dga_pixmap dgapix)
+{
+    if (dgapix->changeMask & DGA_CHANGE_ZOMBIE)
+	return (NULL);
+    return((char *)(((SHARED_PIXMAP_INFO *)(dgapix->p_infop))->scr_name));
+}
+
+int
+dgai_pix_devfd(_Dga_pixmap dgapix)
+{
+    return(dgapix->p_infofd);
+}
+
+int
+dgai_pix_depth(_Dga_pixmap dgapix)
+{
+    return(dgapix->depth);
+}
+
+void
+dgai_pix_set_client_infop(_Dga_pixmap dgapix, void *client_info_ptr)
+{
+    dgapix->p_client = client_info_ptr;
+}
+
+void *
+dgai_pix_get_client_infop(_Dga_pixmap dgapix)
+{
+    return(dgapix->p_client);
+}
+
+void *
+dgai_pix_devinfo(_Dga_pixmap dgapix)
+{
+    if (dgapix->changeMask & DGA_CHANGE_ZOMBIE)
+	return (NULL);
+    return(((char *)dgapix->p_infop) + PIX_INFOP(dgapix)->device_offset);
+}
+
+int
+dgai_pix_devinfochg(_Dga_pixmap dgapix)
+{
+    if (dgapix->changeMask & DGA_CHANGE_DEVINFO) {
+	dgapix->changeMask &= ~DGA_CHANGE_DEVINFO;
+	return (1);
+    } else {
+	return (0);
+    }
+}
+
+int
+dgai_pix_sitechg(_Dga_pixmap dgapix, int *reason)
+{
+    if (dgapix->changeMask & DGA_CHANGE_SITE) {
+	dgapix->changeMask &= ~DGA_CHANGE_SITE;
+	*reason = dgapix->siteChgReason;
+	return (1);
+    } else {
+	*reason = DGA_SITECHG_UNKNOWN;
+	return (0);
+    }
+}
+
+void
+dgai_pix_sitesetnotify(_Dga_pixmap dgapix, 
+		       DgaSiteNotifyFunc site_notify_func, void *client_data)
+{
+    dgapix->siteNotifyFunc = site_notify_func;
+    dgapix->siteNotifyClientData = client_data;
+}
+
+void
+dgai_pix_sitegetnotify(_Dga_pixmap dgapix, 
+		       DgaSiteNotifyFunc *site_notify_func, void **client_data)
+{
+    *site_notify_func = dgapix->siteNotifyFunc;
+    *client_data = dgapix->siteNotifyClientData;
+}
+
+int
+dgai_pix_site(_Dga_pixmap dgapix)
+{
+    SHARED_PIXMAP_INFO *infop;
+
+    if (dgapix->changeMask & DGA_CHANGE_ZOMBIE) {
+        return (DGA_SITE_NULL);
+    }
+
+    infop = PIX_INFOP(dgapix);
+    return (infop->cached ? DGA_SITE_DEVICE : DGA_SITE_SYSTEM);
+}
+
+void *
+dgai_pix_address(_Dga_pixmap dgapix)
+{
+    SHARED_PIXMAP_INFO *infop;
+
+    if (dgapix->changeMask & DGA_CHANGE_ZOMBIE)
+	return (NULL);
+
+    infop = PIX_INFOP(dgapix);
+    return(infop->cached ? NULL : (void *)(infop + 1));
+}
+
+int
+dgai_pix_linebytes(_Dga_pixmap dgapix)
+{
+    SHARED_PIXMAP_INFO *infop;
+
+    if (dgapix->changeMask & DGA_CHANGE_ZOMBIE)
+	return (NULL);
+
+    infop = PIX_INFOP(dgapix);
+    return(infop->cached ? 0 : infop->linebytes);
+}
+
+int
+dgai_pix_bitsperpixel(_Dga_pixmap dgapix)
+{
+    SHARED_PIXMAP_INFO *infop;
+
+    if (dgapix->changeMask & DGA_CHANGE_ZOMBIE)
+	return (NULL);
+
+    infop = PIX_INFOP(dgapix);
+    return(infop->cached ? 0 : infop->bitsperpixel);
+}
+
+int
+dgai_pix_clipchg(_Dga_pixmap dgapix)
+{
+    /* always force a clip change on a zombie to get the client
+       to notice */
+    if ((dgapix->changeMask & DGA_CHANGE_ZOMBIE) ||
+	(dgapix->pix_flags & PIX_NOTICE_CLIPCHG)){
+	dgapix->pix_flags &= ~PIX_NOTICE_CLIPCHG;
+        return (1);
+    } else {
+        return(0);
+    }
+
+}
+
+void
+dgai_pix_bbox(_Dga_pixmap dgapix, int *xp, int *yp, int *widthp, int *heightp)
+{
+    if (dgapix->changeMask & DGA_CHANGE_ZOMBIE) {
+        *xp = 0;
+        *yp = 0;
+        *widthp = 0;
+        *heightp = 0;
+    } else {
+        SHARED_PIXMAP_INFO *infop;
+ 
+        infop = PIX_INFOP(dgapix);
+        *xp = 0;
+        *yp = 0;
+        *widthp = infop->width;
+        *heightp = infop->height;
+    }
+}
+
+int
+dgai_pix_empty(_Dga_pixmap dgapix)
+{
+    if (dgapix->changeMask & DGA_CHANGE_ZOMBIE) {
+        return (1);
+    } else {
+        SHARED_PIXMAP_INFO *infop;
+ 
+        infop = PIX_INFOP(dgapix);
+        return (infop->width <= 0 || infop->height <= 0);
+    }
+}
+
+static short nonviewableShape[] = {
+    0, /* ymin */
+    0, /* ymax: fill in based on height */
+    0, /* xmin */
+    0, /* xmax: fill in based on width */
+    DGA_X_EOL,
+    DGA_Y_EOL,
+};
+ 
+#define YMAX_INDEX 1
+#define XMAX_INDEX 3
+
+short *
+dgai_pix_clipinfo(_Dga_pixmap dgapix)
+{
+    if (dgapix->changeMask & DGA_CHANGE_ZOMBIE) {
+        return (NULL);
+    } else {
+        SHARED_PIXMAP_INFO *infop;
+ 
+        infop = PIX_INFOP(dgapix);
+        if (infop->width <= 0 || infop->height <= 0) {
+            return (NULL);
+        } else {
+            nonviewableShape[YMAX_INDEX] = infop->height - 1;
+            nonviewableShape[XMAX_INDEX] = infop->width - 1;
+            return (nonviewableShape);
+        }
+    }    
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/lib/libdga/sun-src/pix_update.c	Fri Nov 13 13:30:43 2009 -0800
@@ -0,0 +1,121 @@
+/* Copyright 2002 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ *
+ * 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, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * 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
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR 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.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+#pragma ident	"@(#)pix_update.c	35.6	09/11/09 SMI"
+
+/*
+** pix_update.c
+**
+** Routines of the update phase for pixmaps.
+*/
+
+#ifdef SERVER_DGA
+#include <X11/Xlib.h>
+#endif /* SERVER_DGA */
+#include "dga_incls.h"
+#include "pix_grab.h"
+
+void
+dgai_pix_notify(_Dga_pixmap dgapix)
+{
+    if (dgapix->siteNotifyFunc && (dgapix->changeMask & DGA_CHANGE_SITE)) {
+	(*dgapix->siteNotifyFunc)((Dga_drawable)dgapix, -1,
+				  dgapix->siteNotifyClientData,
+				  dgapix->siteChgReason);
+        dgapix->changeMask &= ~DGA_CHANGE_SITE;
+    }
+}
+
+int
+dgai_pix_update(Dga_drawable dgadraw, short bufIndex)
+{
+    _Dga_pixmap dgapix = (_Dga_pixmap)dgadraw;
+    SHARED_PIXMAP_INFO *infop;
+
+#ifdef MT
+    if (dgaMTOn) {
+	mutex_lock(dgapix->mutexp);
+	DGA_LOCK(dgadraw);
+	/* check the real change count that we saved away */
+	if (dgapix->shadow_chngcnt[0] == *dgapix->s_chngcnt_p) {
+	    mutex_unlock(dgapix->mutexp);
+            DGA_UNLOCK(dgadraw);
+	    return (0);
+	}
+    }
+#endif
+
+    infop = PIX_INFOP(dgapix);
+
+    dgapix->changeMask = 0;
+
+    /* first, see if the shared info is still valid */
+    if (infop->obsolete) {
+        dgapix->changeMask |= DGA_CHANGE_ZOMBIE;
+    }
+    if (dgapix->changeMask & DGA_CHANGE_ZOMBIE) {
+        dgapix->changeMask |= (DGA_CHANGE_SITE | DGA_CHANGE_CLIP);
+        dgapix->siteChgReason = DGA_SITECHG_ZOMBIE;
+    }
+
+    /* see if the dev_info has changed */
+    if (dgapix->c_devinfocnt != *dgapix->s_devinfocnt_p) {
+	dgapix->changeMask |= DGA_CHANGE_DEVINFO;
+        dgapix->c_devinfocnt = *dgapix->s_devinfocnt_p;
+    }
+
+    /* Has the cache changed? */
+    if (dgapix->c_cachecnt != *dgapix->s_cachecnt_p) {
+        dgapix->changeMask |= (DGA_CHANGE_CACHE | DGA_CHANGE_SITE);
+	dgapix->siteChgReason = DGA_SITECHG_CACHE;
+        dgapix->c_cached = *dgapix->s_cached_p;
+        dgapix->c_cachecnt = *dgapix->s_cachecnt_p;
+    }
+
+    dgai_pix_notify(dgapix);
+
+#ifdef MT
+    if (dgaMTOn) {
+	/* save the real change count */
+	dgapix->shadow_chngcnt[0] = *dgapix->s_chngcnt_p;
+	/* For the MT case, make sure that this update function gets called
+	 * the next time around, so make the change count different.
+	 */
+	dgapix->c_chngcnt[0] = *dgapix->s_chngcnt_p - 1;
+	mutex_unlock(dgapix->mutexp);
+        DGA_UNLOCK(dgadraw);
+    } else {
+	dgapix->c_chngcnt[0] = *dgapix->s_chngcnt_p;
+    }
+#else
+    dgapix->c_chngcnt[0] = *dgapix->s_chngcnt_p;
+#endif
+    return(dgapix->changeMask);
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/lib/libdga/sun-src/rtn_grab.c	Fri Nov 13 13:30:43 2009 -0800
@@ -0,0 +1,993 @@
+/* Copyright 1998 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ *
+ * 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, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * 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
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR 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.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+#pragma ident	"@(#)rtn_grab.c	35.5	09/11/10 SMI"
+
+/*
+ *
+ *
+ *      @@@@   @@@@@  @   @          @@@@  @@@@    @@@   @@@@
+ *      @   @    @    @@  @         @      @   @  @   @  @   @
+ *      @@@@     @    @ @ @         @ @@@  @@@@   @@@@@  @@@@
+ *      @  @     @    @  @@         @   @  @  @   @   @  @   @
+ *      @   @    @    @   @  @@@@@   @@@@  @   @  @   @  @@@@
+ *
+ *      DGA shared retained window access routines
+ *
+ *	int
+ *	dga_rtn_active(clientp)
+ *	    Dga_window clientp;
+ *
+ *	u_char
+ *	dga_rtn_cached(clientp)
+ *	    Dga_window clientp;
+ *
+ *	void *	
+ *	dga_rtn_devinfo(clientp)
+ *	    Dga_window clientp;
+ *
+ *	void
+ *	dga_rtn_devtype(clientp, type, name)
+ *	    Dga_window   clientp;
+ *	    u_char      *type;
+ *	    char       **name;
+ *
+ *	void 
+ *	dga_rtn_dimensions(clientp, width, height, linebytes) 
+ *	    Dga_window  clientp; 
+ *	    short      *width; 
+ *	    short      *height; 
+ *	    u_int      *linebytes;
+ *
+ *	int
+ *	dga_rtn_grab(clientp)
+ *	    Dga_window  clientp; 
+ *
+ *	void *
+ *	dga_rtn_pixels(clientp)
+ *	    Dga_window clientp;
+ *
+ *	int
+ *	dga_rtn_ungrab(clientp)
+ *	    Dga_window  clientp; 
+ *
+ *	int
+ *	_dga_rtn_map(clientp)
+ *	    Dga_window  clientp;
+ *
+ *	int
+ *	_dga_rtn_unmap(clientp)
+ *	    Dga_window clientp;
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <unistd.h>
+#ifdef SERVER_DGA
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include "windowstr.h"
+#include "dga_externaldefs.h"
+#include "dga/dgawinstr.h"
+#else
+#include <fcntl.h>
+#include <sys/mman.h>
+
+#ifdef SVR4
+#include <netdb.h>
+#include <sys/stat.h>
+#else
+#include <sys/param.h>
+#endif
+
+#include <X11/Xlib.h>
+#endif /* SERVER_DGA */
+
+#include "dga_incls.h"
+#include "rtn_grab.h"
+
+int dgai_rtn_ungrab_common();
+extern int dgai_win_check_multiple_grab(_Dga_window clientp, int drawableGrabber);
+extern void *_dga_is_X_window(Dga_token token, Display **dpyp, Window *winp);
+
+/*
+ *
+ *  dga_rtn_active()
+ *
+ *  DGA Retained Windows Active.  This function is called to determine
+ *  if DGA to the retained portion of the specified dga_window is currently
+ *  active.  Since the server can drop support for this functionality at 
+ *  any time, the client should always call this function when a change has 
+ *  been has been recorded in the retained window information.  This function 
+ *  should be called prior to accessing any other retained window information.
+ *  The function returns a non-zero result if DGA to the retained portion
+ *  of the window is active.  A zero result is returned if support has
+ *  been dropped.  
+ *
+ *  Inputs:     Dga_window - Pointer to the client structure.
+ *
+ *  Outputs:     0 - DGA Retained window support has been dropped.
+ *		-1 - DGA Retained window support continues.
+ *
+ *  Globals:    None.
+ *
+ *  Externals:  None.
+ *
+ */
+int
+dga_rtn_active(clientpi)
+    Dga_window clientpi;
+{
+    _Dga_window clientp = (struct dga_window *)clientpi;
+    
+    if ((clientp->rtn_flags & RTN_MAPPED))
+	return (RTN_PASSED);
+    else
+	return (RTN_FAILED);
+}
+
+/*
+ *
+ *  dga_rtn_cached()
+ *
+ *  DGA Retained HW Cache status.  This function returns a non-zero
+ *  value if the retained raster is cached in hardware.  If set to
+ *  DGA_RTN_NEW_DEV then the server has re-cached the retained
+ *  raster from one device to another.  If set to DGA_RTN_SAME_DEV
+ *  the raster remains cached in the same device as previously
+ *  recorded.  If the retained raster is not cached in hw then the
+ *  function returns DGA_RTN_NOT_CACHED (0).
+ *
+ *  Inputs:     Dga_window - Pointer to the client structure.
+ *
+ *  Outputs:    DGA_RTN_NOT_CACHED - not cached in hw
+ *		DGA_RTN_SAME_DEV   - cached in the same hw device
+ *		DGA_RTN_NEW_DEV    - cached in the new hw device
+ *
+ *  Globals:    None.
+ *
+ *  Externals:  RTN_INFOP()	Internal MACRO
+ *
+ *
+ */
+int
+dga_rtn_cached(clientpi)
+    Dga_window clientpi;
+{
+    _Dga_window clientp = (struct dga_window *)clientpi;
+    
+    if (RTN_INFOP(clientp)->cached) 
+	if (clientp->c_rtncachseq != *(clientp->s_rtncachseq_p)) {
+	    clientp->c_rtncachseq = *(clientp->s_rtncachseq_p);
+	    return (DGA_RTN_NEW_DEV);
+	}
+	else
+	    return (DGA_RTN_SAME_DEV);
+    else
+	return (DGA_RTN_NOT_CACHED);
+}
+
+/*
+ *
+ *  dga_rtn_devinfop()	<---external interface just to be consistent 
+ *  dga_rtn_devinfo()
+ *
+ *  DGA Retained Device Info.  This function returns a pointer to
+ *  the shared device specific retained raster information when
+ *  the retained raster is cached in hw.  The pointer is invalid
+ *  if the retained raster isn't cached in hw.
+ *
+ *  Inputs:     Dga_window - Pointer to the client structure.
+ *
+ *  Outputs:    void *  - Pointer to the device specific information
+ *
+ *  Globals:    None.
+ *
+ *  Externals:  RTN_INFOP()	Internal MACRO
+ *
+ */
+void *
+dga_rtn_devinfo(clientpi)
+    Dga_window clientpi;
+{   
+    /* This is the internal interface */
+    _Dga_window clientp = (struct dga_window *)clientpi;
+    
+    return (((char *)clientp->rtn_info) + RTN_INFOP(clientp)->device_offset);
+}
+
+void *
+dga_rtn_devinfop(clientpi)
+    Dga_window clientpi;
+{
+    _Dga_window clientp = (struct dga_window *)clientpi;
+    
+    return (((char *)clientp->rtn_info) + RTN_INFOP(clientp)->device_offset);
+}
+
+/*
+ *
+ *  dga_rtn_devtype()
+ *
+ *  DGA Retained Device Type.  This function is used to obtain
+ *  the retained raster hardware cache device type and name.
+ *
+ *  Inputs:     Dga_window - Pointer to the client structure.
+ *		Unsign8 *  - Pointer to location to store device type.
+ *		char **    - Pointer to location to store name string pointer.
+ *
+ *  Outputs:    None.
+ *
+ *  Globals:    None.
+ *
+ *  Externals:  RTN_INFOP()	Internal MACRO
+ * 
+ */
+void
+dga_rtn_devtype(clientpi, type, name)
+    Dga_window  clientpi;
+    u_char     *type;
+    char      **name;
+{
+    _Dga_window clientp = (struct dga_window *)clientpi;
+    
+    *type = RTN_INFOP(clientp)->device;
+    *name = (char *) RTN_INFOP(clientp)->scr_name;
+}
+    
+/*
+ *
+ *  dga_rtn_dimensions()
+ *
+ *  DGA Retained Raster Dimensions.  This function is used to obtain
+ *  the retained raster's dimensions.
+ *
+ *  Inputs:     Dga_window - Pointer to the client structure.
+ *              short    * - Pointer to location to store the width.
+ *              short    * - Pointer to location to store the height.
+ *		u_int	 * - Pointer to the location to store the linebytes.
+ *
+ *  Outputs:    None.
+ *
+ *  Globals:    None.
+ *
+ *  Externals:  RTN_INFOP()	Internal MACRO
+ *
+ */
+void
+dga_rtn_dimensions(clientpi, width, height, linebytes)
+    Dga_window  clientpi;
+    short      *width;
+    short      *height;
+    u_int      *linebytes;
+{
+    _Dga_window clientp = (struct dga_window *)clientpi;
+    
+    *width = RTN_INFOP(clientp)->width;
+    *height = RTN_INFOP(clientp)->height;
+    *linebytes = RTN_INFOP(clientp)->linebytes;
+}
+
+int
+dga_rtn_bitsperpixel(Dga_window clientpi)
+{
+    _Dga_window clientp = (struct dga_window *)clientpi;
+    
+    return(RTN_INFOP(clientp)->bitsperpixel);
+}
+
+/*
+ *
+ *  dga_rtn_grab()
+ *
+ *  DGA Retained Window Grab.  This function creates the shared memory
+ *  interface to allow the calling process Direct Graphics Access (DGA)
+ *  to the retained raster associated with the specified DGA window.
+ *  A request to allow DGA access to the retained raster is sent to the
+ *  X/NeWS server.  Should the server honor this request, shared memory 
+ *  mappings within the calling process's address space are then created. 
+ *  Should any of these steps fail, 0 is returned and the calling process 
+ *  is not allowed DGA to the retained raster.  A non-zero result is 
+ *  returned upon success.
+ *
+ *  Inputs:     Dga_window - Pointer to the Dga_window for which DGA
+ *			     to the retained raster is desired.
+ *
+ *  Outputs:     0 - failed
+ *		-1 - passed
+ *
+ *  Globals:    None.
+ *
+ *  Externals:	XDgaGrabRetainedWindow()
+ *		XDgaUnGrabRetainedWindow()
+ *		_dga_is_X_window()
+ *		_dga_rtn_map()
+ *		fprintf()			DEBUG ONLY
+ *
+ */
+int
+dga_rtn_grab(clientpi)
+    Dga_window	 clientpi;
+{
+    Display	*dpy;
+    Window	 win;
+#ifdef SERVER_DGA
+    WXINFO  *infop;
+    WindowPtr pWin;
+#endif /* SERVER_DGA */
+
+    /*
+     *  Check for an invalid Dga_window
+     */
+     _Dga_window clientp = (struct dga_window *)clientpi;
+    
+    if ((clientp == (_Dga_window) NULL)) {
+#ifdef DEBUG
+	(void) fprintf(stderr, "dga_rtn_grab: passed null pointer\n");
+#endif
+	return (RTN_FAILED);
+    }
+
+#ifdef SERVER_DGA
+        /* Determine the window associated with this clientp */
+    infop = (WXINFO *) clientp->w_info;
+    pWin = (((WDEV *)(infop->wdev))->pWin);
+
+    /* Check to see if backing store has been turned on for thw window */
+    if (pWin->backingStore == NotUseful)
+	return (RTN_FAILED);
+
+
+    if (!DgaSharedRetained(pWin, 1, pWin->drawable.id)) {
+        return (RTN_FAILED);
+    }
+   /* Map the shared memory into the calling process's address space.*/
+   if (!_dga_rtn_map(clientp)) {
+
+                /* Ungrab the retained raster */
+        (void) DgaSharedRetained(pWin, 0, pWin->drawable.id);
+        return (RTN_FAILED);
+    }
+#else
+    /*
+     *  If the retained raster has already been grabbed. Don't
+     *  do anything.
+     */
+    if (clientp->rtn_flags & RTN_GRABBED)
+	return (RTN_PASSED);
+
+    /*
+     *  Find out if this is an X window.  If so get the Display and window
+     *  id.  These are used to determine the name of the shared retained
+     *  info file.  NOTE:  DGA to retained rasters are currently supported
+     *  only for X windows.
+     */
+     if (!_dga_is_X_window(clientp->w_token, &dpy, &win)) {
+#ifdef DEBUG
+	(void) fprintf(stderr, "dga_rtn_grab: Unsupported window type\n");
+#endif
+	return (RTN_FAILED);
+    }
+    /* Check to see if backing store is turned on for this window; if not
+     * report failure
+   */
+   {
+	XWindowAttributes	attr;
+   	XGetWindowAttributes(dpy,win,&attr);
+	if (attr.backing_store == NotUseful) {
+#ifdef DEBUG
+		(void) fprintf(stderr,"dga_rtn_grab: Window has no backing store\n");
+#endif
+		return (RTN_FAILED);
+	}
+   }
+   
+
+    /*
+     *  Request the server to allow DGA to the retained raster associated
+     *  with this Dga_window.
+     */
+    if (!XDgaGrabRetainedWindow(dpy, win)) {
+#ifdef DEBUG
+	(void) fprintf(stderr, "dga_rtn_grab: XDgaGrabRetainedWindow failed\n");
+#endif
+	return (RTN_FAILED);
+    }
+   /*
+    *  Now map the shared memory into the calling process's address
+    *  space.
+    */
+   if (!_dga_rtn_map(clientp)) {
+#ifdef DEBUG
+	(void) fprintf(stderr, "dga_rtn_grab: unable to map shared info\n");
+#endif
+	/*
+	 *  Ungrab the retained raster
+	 */
+	(void) XDgaUnGrabRetainedWindow(dpy, win);
+	return (RTN_FAILED);
+    }
+#endif /* SERVER_DGA */
+    clientp->rtn_flags |= RTN_GRABBED;
+    return (RTN_PASSED);
+}
+
+/*
+ *
+ *  dga_rtn_pixels()
+ *
+ *  DGA Retained Pixel Memory .  This function returns a pointer
+ *  to the shared retained pixel memory.
+ *
+ *  Inputs:     Dga_window - Pointer to the client structure.
+ *
+ *  Outputs:    u_char * - Pointer to retained pixel memory.
+ *
+ *  Globals:    None.
+ *
+ *  Externals:  None.
+ *
+ *
+ */
+void *
+dga_rtn_pixels(clientpi)
+    Dga_window clientpi;
+{
+    _Dga_window clientp = (struct dga_window *)clientpi;
+    
+    return ((void *)clientp->rtn_pixels);
+}
+
+/*
+ *
+ *  dga_rtn_ungrab()
+ *
+ *  DGA Retained Window Ungrab.  This function frees the resources 
+ *  associated with a DGA retained retained raster.  The shared
+ *  memory mappings in the calling process's address space are 
+ *  unmapped, the shared info file is closed, and the server is
+ *  notified through a protocol extension to free all its resources
+ *  associated with the DGA retained raster.  Should any of these 
+ *  steps fail, 0 is returned.  A non-zero result is returned upon 
+ *  success.
+ *
+ *  Inputs:     Dga_window - Pointer to the Dga_window for which DGA
+ *                           to the retained raster is desired.
+ *
+ *  Outputs:     0 - failed
+ *              -1 - passed
+ *
+ *  Globals:    None.
+ *
+ *  Externals:  DisplayString()                 X11 MACRO
+ *              XDgaUnGrabRetainedWindow()
+ *		_dga_is_X_window()
+ *              _dga_rtn_unmap()
+ *              fprintf()                       DEBUG ONLY
+ *
+ */
+int
+dga_rtn_ungrab(clientpi)
+    Dga_window	clientpi;
+{
+    _Dga_window clientp = (struct dga_window *)clientpi;    
+
+    return (dgai_rtn_ungrab_common(clientp, 0));
+}
+
+int
+dgai_rtn_ungrab_common(clientp, drawableGrabber)
+    _Dga_window  clientp;
+    int	drawableGrabber;
+{
+    int		status = -1;
+#ifdef SERVER_DGA
+    WindowPtr      pWin;
+    WXINFO  *infop;
+#else
+    Display    *dpy;
+    Window	win;
+#endif /* SERVER_DGA */
+
+    /*
+     *  Check for an invalid Dga_window
+     */
+    if ((clientp == (Dga_window) NULL)) {
+#ifdef DEBUG
+        (void) fprintf(stderr, "dga_rtn_ungrab: passed null pointer\n");
+#endif
+        return (RTN_FAILED);
+    }
+
+    /*
+     *  If the retained window has not been grabbed then don't
+     *  do anything.
+     */
+    if ((clientp->rtn_flags & RTN_GRABBED) == 0)
+	return (RTN_FAILED);
+
+    /*
+     *  Unmap the calling process's resources if present.
+     */
+    status &= _dga_rtn_unmap(clientp);
+
+    /*
+     *  Set the dga_window retained window server sequence counter pointer
+     *  to reflect that the retained raster has NOT been grabbed.
+     */
+    clientp->s_rtnseq_p = &(clientp->c_rtnseq);
+
+#ifdef SERVER_DGA
+    /* Determine the window associated with this clientp */
+    infop = (WXINFO *) clientp->w_info;
+    pWin = (((WDEV *)(infop->wdev))->pWin);
+       
+    status &= DgaSharedRetained(pWin, 0, pWin->drawable.id);
+#else
+    /*
+     *  Find out if this is an X window.  If so get the Display and window
+     *  id.  These are used to determine the name of the shared retained
+     *  info file.  NOTE:  DGA to retained rasters is currently supported
+     *  only for X windows.
+     */
+     if (!_dga_is_X_window(clientp->w_token, &dpy, &win)) {
+#ifdef DEBUG
+        (void) fprintf(stderr, "dga_rtn_grab: Unsupported window type\n");
+#endif
+        return (RTN_FAILED);
+    }
+
+    /*
+     *  Tell the server to deallocate its retained window
+     *  resources.if there are no other clients grabbing this window
+     */
+    if (!dgai_win_check_multiple_grab(clientp,drawableGrabber))
+	status &= XDgaUnGrabRetainedWindow(dpy, win);
+
+#endif /* SERVER_DGA */
+
+    clientp->rtn_flags = 0;
+
+    if (status)
+	return (RTN_PASSED);
+    else
+	return (RTN_FAILED);
+}
+
+/*
+ *
+ *  _dga_rtn_map()
+ *
+ *  DGA Retained Window Map.  This function maps the retained window
+ *  shared memory into the clients address space after determining 
+ *  the path to the retained window information file.  The shared 
+ *  retained info structure is mapped followed by the actual pixel 
+ *  array used when the pixels are not cached in hardware.  The 
+ *  address of the shared retained info structure is then place in 
+ *  the dga_window structure along with the client dependent information.
+ *  Should any operation fail, a NULL pointer is placed in the dga_window 
+ *  structure and 0 is returned.
+ *  
+ *  Inputs:	Dga_window - Pointer to the dga_window structure
+ *
+ *  Outputs:	 0 - failed
+ *		-1 - passed
+ *
+ *  Globals:	None.
+ *	
+ *  Externals:	DisplayString()		X11 MACRO
+ *		XDgaGetRetainedPath()
+ *		_dga_is_X_window()
+ *		close()
+ *		fprintf()		DEBUG ONLY
+ *		fstat()
+ *		getpagesize() 		SUNOS ONLY
+ *		mmap()
+ *		munmap()
+ *		open()
+ *		sprintf()
+ *		sscanf()
+ *		strcat()
+ *		strcpy()
+ *		strlen()
+ *		sysconf()		SVR4  ONLY
+ *		unlink()
+ *		
+ */
+int
+_dga_rtn_map(clientp)
+_Dga_window clientp; 
+{
+    SHARED_RETAINED_INFO	*infop;
+#ifdef SERVER_DGA
+    WXINFO  			*winfop;
+#else
+    u_char			*pixels;
+    int				 filefd;
+    size_t			 size;
+    size_t			 pagesize;
+    u_int			 port;
+    Display			*dpy;
+    Window			 win;
+    char			*dpystr;
+    struct stat			 rstat;
+    char			 path[256];
+    char			 host[MAXHOSTNAMELEN];
+#endif /* SERVER_DGA */
+
+    /*
+     *  Check for a non-zero pointer.
+     */
+    if (clientp == (_Dga_window) NULL) {
+#ifdef DEBUG
+	(void) fprintf(stderr, "_dga_rtn_map: dga_window pointer (NULL)\n");
+#endif
+	return (RTN_FAILED);
+    }
+
+    /*
+     *  If the shared retained information has already been mapped don't 
+     *  do anything.
+     */
+    if ((clientp->rtn_flags & RTN_MAPPED))
+	return (RTN_PASSED);
+
+#ifdef SERVER_DGA
+    /* Determine the window associated with this clientp */
+    winfop = (WXINFO *) clientp->w_info;
+    infop = (SHARED_RETAINED_INFO *)winfop->w_srtndlink;
+ 
+    /* Initialise clientp's retained info structure - refer dga.h */
+    clientp->rtn_fd = 0; /* I don't think that it is needed any more */
+    clientp->rtn_size = infop->s_size;
+    clientp->c_rtnseq = 0;
+    clientp->s_rtnseq_p = (u_int *)&(infop->s_modified);
+    clientp->c_rtncachseq = 0;
+    clientp->s_rtncachseq_p = (u_int *)&(infop->s_cacheseq);
+    clientp->rtn_info = (caddr_t)infop;
+    clientp->rtn_pixels = (caddr_t)(infop->s_pixels);
+    clientp->rtn_flags |= RTN_MAPPED;
+ 
+        return (RTN_PASSED);
+#else /* SERVER_DGA */
+    /*
+     *  Find out if this is an X window.  If so get the Display and window
+     *  id.  These are used to determine the name of the shared retained
+     *  info file.  NOTE:  DGA to retained rasters are currently supported
+     *  only for X windows.
+     */
+     if (!_dga_is_X_window(clientp->w_token, &dpy, &win)) {
+#ifdef DEBUG
+        (void) fprintf(stderr, "_dga_rtn_map: Unsupported window type\n");
+#endif
+        return (RTN_FAILED);
+    }
+
+    /*
+     *  Now locate the shared retained info file within the file system.
+     *  This file is located in /tmp by default, but through a server
+     *  command line option, can be located anywhere on the system in
+     *  question.  Get the path from the server using the protocol
+     *  extension.  Then create the filename using the display string
+     *  and the port number.
+     */
+    if (!XDgaGetRetainedPath(dpy, win, path)) {
+#ifdef DEBUG
+	(void) fprintf(stderr, "_dga_rtn_map: XDgaGetRetainedPath failed\n");
+#endif
+	return (RTN_FAILED);
+    }
+
+    /*
+     *  If the path is equal to "", then use the default directory
+     *  path.
+     */
+    if (!(*path)) 
+	(void) strcpy(path, "/tmp");
+    else if (strlen(path) > RTN_MAXPATH) {
+#ifdef DEBUG
+	(void) fprintf(stderr, "_dga_rtn_map: path longer than supported\n");
+#endif
+	return (RTN_FAILED);
+    }
+    (void) strcat(path, RTN_FILE);
+
+    /*
+     *  Now get the port number for this display
+     */   
+    dpystr = DisplayString(dpy);
+    if (dpystr[0] == ':') 
+	(void) sscanf(dpystr, ":%u", &port);
+    else
+	(void) sscanf(dpystr, "%[^:]:%u", host, &port);
+
+   /*
+    *  Combine the port number and the window id with the path
+    *  string.
+    */
+    size = strlen(path);
+    (void) sprintf(path+size, "%01x.%08x", port, win);
+
+    if ((filefd = open(path,O_RDWR,0666))<0) {
+#ifdef DEBUG
+	(void) fprintf(stderr, "_dga_rtn_map: unable to open file %s\n", 
+		       path);
+#endif
+	return (RTN_FAILED);
+    }
+
+    /*
+     *  Now unlink the file to guarantee that it will disappear
+     *  should the client or server crash.
+     */
+    (void) unlink(path);
+
+#ifdef SVR4
+    pagesize = sysconf(_SC_PAGESIZE);
+#else
+    pagesize = getpagesize();
+#endif
+
+    /*
+     *  Check the state of the file.  If the size of the file
+     *  is insufficient to contain the first page of the shared
+     *  retained info structure (ie < pagesize) report a failure.
+     */
+    if (fstat(filefd, &rstat) < 0) {
+#ifdef DEBUG
+        (void) fprintf(stderr, "_dga_rtn_map: unable get file status\n");
+#endif
+        (void) close(filefd);
+        return (RTN_FAILED);
+    }
+    if (rstat.st_size < pagesize) {
+#ifdef DEBUG
+        (void) fprintf(stderr, "_dga_rtn_map: file not correct size, %ld\n",
+                rstat.st_size);
+#endif
+        (void) close(filefd);
+        return (RTN_FAILED);
+    }
+
+    /*
+     *  Map the SHARED_RETAINED_INFO structure
+     */
+    infop = (SHARED_RETAINED_INFO *) mmap(0,
+                            pagesize,
+                            PROT_READ|PROT_WRITE,
+                            MAP_SHARED,
+                            filefd,
+                            (off_t)0);
+
+    if (infop == (SHARED_RETAINED_INFO *) -1) {
+#ifdef DEBUG
+	(void) fprintf(stderr, "_dga_rtn_map: unable to mmap file %s\n", 
+		       path);
+#endif
+	(void) close(filefd);
+	return (RTN_FAILED);
+    }
+
+    /*
+     *  If the file is not actually a shared retained information file
+     *  or its the wrong version, unmap the shared memory, close the
+     *  file and return the error status.
+     */
+    if ((infop->magic != RTN_MAGIC) || (infop->version > RTN_VERS)) {
+#ifdef DEBUG
+	(void) fprintf(stderr, "_dga_rtn_map: contents of file %s incorrect\n", 
+		       path);
+#endif
+        (void) munmap((caddr_t) infop, pagesize);
+        (void) close(filefd);
+	return (RTN_FAILED);
+    }
+
+    /* 
+     *  Map the pixel page
+     */
+    pixels = (u_char *) mmap(0,
+                        infop->s_size,
+                        PROT_READ|PROT_WRITE,
+                        MAP_SHARED,
+                        filefd,
+			(off_t)infop->first_mmap_offset);
+ 
+    if (pixels == (u_char *) -1) {
+#ifdef DEBUG
+	(void) fprintf(stderr, "_dga_rtn_map: unable to mmap pixel area\n");
+#endif
+        (void) munmap((caddr_t) infop, pagesize);
+        (void) close(filefd);
+	return (RTN_FAILED);
+    }
+
+    /*
+     *  Set the fields of the client information.
+     */
+    clientp->rtn_fd = filefd;
+    clientp->rtn_size = infop->s_size;
+    clientp->c_rtnseq = 0;
+    clientp->s_rtnseq_p = &(infop->s_modified);
+    clientp->c_rtncachseq = 0;
+    clientp->s_rtncachseq_p = &(infop->s_cacheseq);
+    clientp->rtn_info = (void *) infop;
+    clientp->rtn_pixels = (void *) pixels;
+    clientp->rtn_flags |= RTN_MAPPED;
+
+#ifdef DEBUG
+    _dga_rtn_dump(infop);
+#endif
+
+    return (RTN_PASSED);
+#endif /* SERVER_DGA */
+}
+
+/*
+ *
+ *  _dga_rtn_unmap()
+ *
+ *  DGA Retained Window Unmap.  This function unmaps the retained window
+ *  shared memory from the clients address space given the pointer to the 
+ *  dga_window structure.  The pixel array associated with the retained info 
+ *  structure is unmapped first followed by the shared retained info 
+ *  structure.  The pointer to the shared memory info structure within the
+ *  dga_window structure is set to NULL and the shared memory file is then 
+ *  closed.  Should any operation fail zero is returned.
+ *
+ *  Inputs:     Dga_window - Pointer to the dga_window structure for which
+ *			     the the shared retained info structure is to 
+ *			     be removed.
+ *
+ *  Outputs:     0 - failed
+ *		-1 - passed
+ *
+ *  Globals:    None.
+ *
+ *  Externals:  close()
+ *		fprintf()	DEBUG ONLY
+ *              getpagesize()   SUNOS ONLY
+ *              munmap()
+ *              sysconf()       SVR4  ONLY
+ *              unlink()
+ *
+ */
+int
+_dga_rtn_unmap(clientp)
+    _Dga_window	clientp;
+{
+    size_t	 pagesize;
+    int		 status = 0;
+
+    if ((clientp->rtn_flags & RTN_MAPPED) == 0)
+	return (RTN_FAILED);
+
+#ifndef SERVER_DGA
+#ifdef SVR4
+        pagesize = sysconf(_SC_PAGESIZE);
+#else
+        pagesize = getpagesize();
+#endif
+
+    if (munmap(clientp->rtn_pixels, clientp->rtn_size)) {
+#ifdef DEBUG
+	(void) fprintf(stderr, "_dga_rtn_unmap: pixel unmap failed\n");
+#endif
+	status++;
+    }
+    if (munmap(clientp->rtn_info, pagesize)) {
+#ifdef DEBUG
+	(void) fprintf(stderr, "_dga_rtn_unmap: info page unmap failed\n");
+#endif
+	status++;
+    }
+#endif /*SERVER_DGA */
+    clientp->rtn_info = (void *) NULL;
+    clientp->c_rtnseq = 0;
+    clientp->s_rtnseq_p = (u_int *) &(clientp->s_rtnseq_p);
+    clientp->c_rtncachseq = 0;
+    clientp->s_rtncachseq_p = &(clientp->c_rtncachseq);
+    clientp->rtn_pixels = (void*) NULL;
+    (void) close(clientp->rtn_fd);
+    clientp->rtn_fd = -1;
+    clientp->rtn_flags &= ~(RTN_MAPPED);
+    clientp->rtn_flags |= RTN_MAPCHG;
+    if (status)
+        return (RTN_FAILED);
+    else
+        return (RTN_PASSED);
+}
+
+#ifdef DEBUG
+/*
+ *
+ *  _dga_rtn_dump()
+ *
+ *  DGA Retained Info Structure Dump.  This function prints out the contents
+ *  of the shared retained info structure found at the specified address.
+ *
+ *  Inputs:     SHARED_RETAINED_INFO * - Pointer to the structure to dump.
+ *
+ *  Outputs:    None.
+ *
+ *  Globals:    None.
+ *
+ *  Externals:  printf()
+ *              
+ */
+void
+_dga_rtn_dump(infop)
+    SHARED_RETAINED_INFO *infop;
+{
+
+    if (infop == (SHARED_RETAINED_INFO *) NULL) 
+	(void) printf("NULL info pointer passed to _dga_rtn_dump\n");
+    else {
+	(void) printf("Retained window info page is %p\n", infop);
+	(void) printf("\tmagic =\t\t%u\n", infop->magic);
+	(void) printf("\tversion =\t%u\n", infop->version);
+	(void) printf("\tobsolete =\t%u\n", infop->obsolete);
+	(void) printf("\tdevice =\t%u\n", infop->device);
+	(void) printf("\tcached =\t%u\n", infop->cached);
+	(void) printf("\ts_cacheseq =\t%u\n", infop->s_cacheseq);
+	(void) printf("\ts_modified =\t%u\n", infop->s_modified);
+	(void) printf("\ts_wxlink =\t%p\n", infop->s_wxlink);
+	(void) printf("\tfirst_mmap_offset =\t%u\n", infop->first_mmap_offset);
+	(void) printf("\tdevice_offset =\t%u\n", infop->device_offset);
+	(void) printf("\twidth =\t\t%d\n", infop->width);
+	(void) printf("\theight =\t%d\n", infop->height);
+	(void) printf("\tlineybtes =\t%u\n", infop->linebytes);
+	(void) printf("\ts_fd =\t\t%d\n", infop->s_fd);
+	(void) printf("\ts_size =\t%u\n", infop->s_size);
+	(void) printf("\ts_pixels =\t%p\n", infop->s_pixels);
+	(void) printf("\tfn = \t\t%s\n", infop->fn);
+	(void) printf("\tscr_name = \t%s\n", infop->scr_name);
+	(void) printf("\tc_fd =\t\t%d\n", infop->c_fd);
+	(void) printf("\tc_size =\t%u\n", infop->c_size);
+	(void) printf("\tc_pixels =\t%p\n", infop->c_pixels);
+	(void) printf("\tc_modified =\t%u\n", infop->c_modified);
+	(void) printf("\tc_cacheseq =\t%u\n", infop->c_cacheseq);
+    }
+}
+#endif
+
+
+void *
+dga_win_bboxinfop(clientpi)
+Dga_window clientpi;
+{
+    _Dga_window clientp = (struct dga_window *)clientpi;
+    WXINFO *infop = (WXINFO *) clientp->w_info;
+
+    if (infop->w_version < 2)
+                return 0;
+    return (void *) &(infop->w_window_boundary);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/lib/libdga/sun-src/rtn_grab.h	Fri Nov 13 13:30:43 2009 -0800
@@ -0,0 +1,56 @@
+/* Copyright 1996 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ *
+ * 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, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * 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
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR 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.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+#pragma ident	"@(#)rtn_grab.h	35.3	09/11/09 SMI"
+
+/*
+ *  rtn_grab.h DGA Retained Window Grabber Definitions
+ *
+ */
+
+#ifndef	_RTN_GRAB_H
+#define	_RTN_GRAB_H
+
+/*
+ *  Internal DGA Retained Window Macros
+ */
+
+#define RTN_INFOP(clientp) ((SHARED_RETAINED_INFO *) ((clientp)->rtn_info))
+
+/*
+ * DGA Retained Window Functions 
+ */
+
+extern int	_dga_rtn_map();
+extern int	_dga_rtn_unmap();
+#ifdef DEBUG
+extern void	_dga_rtn_dump();
+#endif
+
+#endif /* _RTN_GRAB_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/lib/libdga/sun-src/vmbuf_grab.h	Fri Nov 13 13:30:43 2009 -0800
@@ -0,0 +1,73 @@
+/* Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ *
+ * 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, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * 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
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR 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.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+#pragma ident	"@(#)vmbuf_grab.h	35.2	09/11/09 SMI"
+
+/*
+ * vmbuf_grab.h - Viewable multibuffer shared file definition
+ */
+
+#ifndef _VMBUF_GRAB_H
+#define _VMBUF_GRAB_H
+
+/* 
+** Currently, the code for the viewable multibuffer shared info is commented
+** out because there is nothing to put in it.  If something needs to be
+** added, define this symbol and complete the code (warning: the code 
+** for this is not yet fully complete).
+*/
+#undef VBSHINFO
+
+#ifdef VBSHINFO
+
+#define	VBMAGIC	0x47524143	/* "GRABBED VIEWABLE MULTIBUFFERS" */
+#define VBVERS          4	/* multibuffer grabber version */
+
+typedef	struct _vbinfo
+{
+    /* Shared data */
+    long	magic;		/* magic number: VBMAGIC */
+    long	version;	/* version: VBVERS */
+    Dga_token	winToken;	/* opaque cookie for shinfo of main window */
+
+    u_int	masterChngCnt;	/* bumped when anything changes in any buffer */
+    u_int	chngCnts[DGA_MAX_GRABBABLE_BUFS];	
+    				/* change counts for individual buffers */
+
+    /* Server only data */
+    u_long	s_filesuffix;	/* "cookie" for info file */
+    u_char	*s_wxlink;	/* server's ptr to shinfo of main window */
+
+    /* FUTURE: may include backing store information */
+
+} VBINFO;
+
+#endif /*VBSHINFO*/
+
+#endif /* _VMBUF_GRAB_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/lib/libdga/sun-src/win_grab.c	Fri Nov 13 13:30:43 2009 -0800
@@ -0,0 +1,1820 @@
+/* Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ *
+ * 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, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * 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
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR 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.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+#pragma ident	"@(#)win_grab.c	35.22	09/11/09 SMI"
+
+/* 
+ * win_grab.c - the client side code for DGA window grabber
+ */
+
+/****
+ *
+ *
+ *	Shared window synchronization routines - client side
+ *
+ *
+ *
+ * Functions:
+ *
+ *    Dga_window
+ *    dga_win_grab(devfd, token)
+ *		int		devfd ;
+ *		Dga_token	token ;
+ *
+ *	Grab a window.  'token' is the window-info handle returned by
+ *	XDgaGrabWindow.  'devfd' is the file descriptor of the frame buffer
+ *	if known, -1 otherwise.  If you specify -1, dga_win_grab will open the
+ *	frame buffer.  The frame buffer fd may be inquired from the returned
+ *	Dga_window structure via the dga_win_devfd() routine.
+ *
+ *	Returns a pointer to the a struct dga_window on success, NULL on
+ *	failure.
+ *
+ *
+ *
+ *    dga_win_ungrab(infop, cflag)
+ *		Dga_window	infop ;
+ *		int		cflag ;
+ *
+ *	Ungrab a window.  All resources allocated by dga_win_grab are freed.
+ *	If 'cflag' is nonzero, the framebuffer fd described for the device
+ *	is also closed.
+ *
+ *	The application should call XDgaUnGrabWindow(dpy,win) after
+ *	calling dga_win_ungrab() so that the server may free the window-info
+ *	page at the other end.
+ *
+ *
+ *
+ *	short *
+ *	dga_win_clipinfo(win)
+ *		Dga_window	win ;
+ *
+ *	Returns pointer to cliplist.  Replaces old wx_sh_clipinfo_c() macro.
+ *
+ *
+ *
+ *	char *
+ *	dga_win_fbname(win)
+ *		Dga_window	win ;
+ *
+ *	Returns name of fb.  Replaces old wx_devname_c() macro.
+ *
+ *
+ *
+ *	int
+ *	dga_win_clipchg(win)
+ *		Dga_window	win ;
+ *
+ *	Returns 1 if cliplist changed since last call.  Replaces old
+ *	wx_modif_c() and wx_seen_c() macros.
+ *
+ *
+ *
+ *	int
+ *	dga_win_curschg(win)
+ *		Dga_window	win ;
+ *
+ *	Returns 1 if cursor changed since last call.
+ *
+ *
+ *
+ *	int
+ *	dga_win_rtnchg(win)
+ *		Dga_window	win ;
+ *
+ *	Returns 1 if retained info changed since last call.
+ *
+ *
+ *
+ *	int
+ *	dga_win_devfd(win)
+ *		Dga_window	win ;
+ *
+ *	Returns framebuffer fd.
+ *
+ *
+ *
+ *	dga_win_bbox(win, xp, yp, widthp, heightp)
+ *		Dga_window win;
+ *		int *xp, *yp, *widthp, *heightp;
+ *
+ *	Returns window bounding box
+ *
+ *
+ *
+ *	int
+ *	dga_win_singlerect(win)
+ *		Dga_window win;
+ *
+ *	Returns nonzero if the window is a single rectangle.
+ *
+ *
+ *
+ *	int
+ *	dga_win_empty(win)
+ *		Dga_window win;
+ *
+ *	Returns nonzero if the window is empty.
+ *
+ *
+ *
+ *	int
+ *	dga_win_obscured(win)
+ *		Dga_window win;
+ *
+ *	Returns nonzero if the window is obscured.
+ *
+ *
+ *
+ *	int
+ *	dga_win_cursactive(win)
+ *		Dga_window win;
+ *
+ *	Returns nonzero if the cursor grabber is active.
+ *
+ *
+ *
+ *	void
+ *	dga_win_cursupdate(win, func, data)
+ *		Dga_window	win;
+ *		void		(*func)();
+ *		void*		data;
+ *
+ *	Decide if the cursor needs to be taken down, and if so, call
+ *		(*func)(data, win, x, y, mem)
+ *			void*		data ;
+ *			Dga_window	win ;
+ *			int		x,y ;
+ *			Dga_curs_mpr	*mem ;
+ *
+ *
+ *
+ *	Dga_dbinfo *
+ *	dga_win_dbinfop(win)
+ *		Dga_window win;
+ *
+ *	Return dbinfo pointer.
+ *
+ *
+ *
+ *	Dga_widinfo *
+ *	dga_win_widinfop(win)
+ *		Dga_window win;
+ *
+ *	Return window id info pointer.
+ *
+ *      dga_win_depth(win)
+ *              Dga_window win;
+ *
+ *      Return windows depth .
+ *
+ *
+ *      dga_win_borderwidth(win) 
+ *              Dga_window win; 
+ * 
+ *      Return windows borderwidth .   
+ *
+ * 	void 
+ * 	dga_win_set_client_infop(win, client_info_ptr)
+ *		Dga_window win;
+ *		void* client_info_ptr;
+ *	Sets a client specific pointer in Dga_window
+ *
+ *
+ *      dga_win_get_client_infop(win) 
+ *              Dga_window win;
+ * 	Returns the client specific pointer
+ *
+ ****/
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#ifdef SERVER_DGA
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include "windowstr.h"
+#include "dga_externaldefs.h"
+#include "dga/dgawinstr.h"
+#else
+#include <sys/file.h>
+#include <sys/mman.h>
+#include <sys/ioctl.h>
+#include <errno.h>
+#include <X11/Xlib.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#ifdef SVR4
+#include <sys/fbio.h>
+#include <sys/fcntl.h>
+#else
+#include <sun/fbio.h>
+#include <fcntl.h>
+#endif
+#endif /* SERVER_DGA */
+
+#include "dga_incls.h"
+#include "rtn_grab.h"
+ 
+#define	GRABFILE	"/tmp/wg"
+#define	CURGFILE	"/tmp/curg"
+#define	NDIGITS		8
+
+#define	MINSHMEMSIZE	(8*1024)
+#define	MAXSHMEMSIZE	(0x00040000)
+#define WX_PAGESZ       (8*1024)
+
+#if 0
+#ifdef DEBUG
+extern	int	sys_nerr;
+extern	char	*sys_errlist[] ;
+#endif
+#endif
+
+extern int _dga_winlockat(u_long cookie, int **lockp, int **unlockp);
+extern int _dga_winlockdt(int *lockp, int *unlockp);
+
+/* Some structure definition for internal bookkeeping */
+typedef struct dga_winlist {
+    Dga_token		w_token;	 /* Token associated with win */
+    struct dga_window	*dga_clientplist;/*List of client ptrs in win */
+    struct dga_window	*dga_clientplist_draw; /* List of client ptrs in win
+						* using drawable i/f. */
+    struct dga_winlist	*next_winlist;  /* Next link in the dga list */
+#ifdef MT
+    mutex_t		mutex;
+#endif
+	
+} *Dga_winlist;
+
+static struct dga_winlist *dga_wlist = NULL;
+
+static int 	dga_win_update(Dga_drawable dgawin);
+static int	dgai_win_initMbufset (_Dga_window dgawin);
+static void	release_lockpages(int devfd, _Dga_window clientp);
+static _Dga_window check_other_curg_windows(WXINFO *);
+void     dgai_win_ungrab_common(_Dga_window dgawin, int cflag,int drawableGrabber);
+int 	dgai_win_check_multiple_grab(_Dga_window dgawin, int drawableGrabber);
+void safe_free_clientp(_Dga_window clientp);
+
+/*bug fix for 4248958: use safe_free_client() to replace free() */
+void
+safe_free_clientp(clientp)
+    _Dga_window  clientp;
+{
+     
+    if(clientp){
+        if(clientp->back) free(clientp->back);
+        if(clientp->depth) free(clientp->depth);
+        if(clientp->stencil) free(clientp->stencil);
+        if(clientp->accum) free(clientp->accum);
+        if(clientp->alpha) free(clientp->alpha);
+        free(clientp);
+    }
+}
+
+/******************************************
+ *
+ * dgai_win_grab_common:
+ *
+ *	create shared memory file for window information
+ *	map to lock page
+ *
+ *	arguments:
+ *
+ *	int	devfd;	INPUT
+ *		file descriptor of graphics device
+ *
+ *	Dga_token	token;	INPUT
+ *		magic cookie supplied by the server
+ *
+ *	returns a user virtual address for a dga_window structure.
+ *	returns NULL if anything goes awry.
+ *
+ *	'devfd' is the file descriptor of the frame buffer, if known,
+ *	-1 otherwise.  If you specify -1, wx_grab will open the
+ *	frame buffer.  The frame buffer fd may be inquired from the returned
+ *	Dga_window ptr to the struct dga_window via the dga_win_devfd() routine.
+ *
+ *****************************************/
+
+
+/*
+** Shared between both drawable grabber and window compatibility interface.
+*/
+
+Dga_window
+dgai_win_grab_common (Display *dpy, int devfd, Dga_token token, int drawableGrabber)
+{
+	WXINFO	*infop;
+	_Dga_window clientp = NULL;
+	Dga_winlist wlist;
+	int	lockfd ;
+	Dga_lockp	lockp, unlockp ;
+	char	filename[sizeof(GRABFILE)+NDIGITS+1];
+	int	filefd;
+	int	locktype ;
+	int	i;
+#ifdef SERVER_DGA
+	WindowPtr	pWin;
+	Window		win;
+
+	if (!_dga_is_X_window(token, &dpy, &win)) {
+	    return  NULL;
+        }
+	pWin = (WindowPtr)LookupIDByType(win, RT_WINDOW);
+#endif /* SERVER_DGA */
+
+	/* First, check if already grabbed by this client. Note that we
+	   always treat the new drawable and old window grabbers separately */
+	for(wlist = dga_wlist;wlist != NULL;wlist = wlist->next_winlist) {
+	    if (wlist->w_token == token) {
+		_Dga_window orig_clientp,new_clientp;
+
+		/* If multiple clients are grabbing the same
+		 * window, then we duplicate the per client info
+		 * structure and return that instead of the original
+		 * allocated clientp structure. Also remember to add
+		 * this new info structure to the linked list. This 
+		 * change obsoletes the w_grab_count field which
+		 * will always be equal to 1
+		 */
+
+		if ((new_clientp =  
+		  (_Dga_window) malloc(sizeof(struct dga_window))) == NULL)
+		    return NULL ;
+
+		if (drawableGrabber) {
+		    if (wlist->dga_clientplist_draw)
+		        orig_clientp = wlist->dga_clientplist_draw;
+                    else
+			orig_clientp = wlist->dga_clientplist;
+		    *new_clientp = *orig_clientp;
+		    new_clientp->w_lockcnt =0;
+		    new_clientp->w_grab_count =1;
+    
+		    if (wlist->dga_clientplist_draw) {
+		        /* Add it to the list of clientp structure associated
+		         * with this window */
+
+		        new_clientp->w_next = orig_clientp;
+		    } else {
+			
+			/* Need to initialize all drawableGrabber
+			 * specific data. */
+
+			infop = (WXINFO *)new_clientp->w_info;
+			if (infop->info_sz != sizeof(WXINFO)) {
+				/* mismatch on 64 bit port or other trouble */
+	    		fprintf(stderr, 
+"wx_grab: mismatch on shared WXINFO size info page is %d sizeof is %d \n",
+				infop->info_sz, sizeof(WXINFO));
+				return(NULL);
+			}
+			new_clientp->drawable_type = DGA_DRAW_WINDOW;
+			new_clientp->w_update_func = 
+				      (int(*)())dgai_mbsmemb_update;
+                        new_clientp->c_mbufseq = 0;
+                        new_clientp->s_mbufseq_p = &infop->w_mbsInfo.mbufseq;
+                        new_clientp->c_mbcomposseq = 0;
+                        new_clientp->s_mbcomposseq_p = 
+                                          &infop->w_mbsInfo.compositionseq;
+                        new_clientp->s_devinfoseq_p = &infop->w_devinfoseq;
+                        new_clientp->c_devinfoseq = 0;
+                        new_clientp->siteNotifyFunc = NULL;
+                        new_clientp->siteNotifyClientData = NULL;
+                        new_clientp->mbNotifyFunc = NULL;
+                        new_clientp->mbNotifyClientData = NULL;
+                        new_clientp->rendBufNotifyFunc = NULL;
+                        new_clientp->rendBufNotifyClientData = NULL;
+                        new_clientp->rLockSubj = DGA_LOCKSUBJ_INVALID;
+                        new_clientp->eLockSubj = DGA_LOCKSUBJ_INVALID;
+                        new_clientp->eLockSubjPrev = DGA_LOCKSUBJ_INVALID;
+                        new_clientp->changeMask = 0;
+                        new_clientp->prevWasMbuffered = 0;
+                        new_clientp->mbChgReason = DGA_MBCHG_UNKNOWN;
+                        new_clientp->siteChgReason = DGA_SITECHG_UNKNOWN;
+                        new_clientp->prevLocked = 0;
+			if ((dpy != NULL) && drawableGrabber) {
+			    if (!dgai_win_initMbufset(new_clientp)) {
+				dga_win_ungrab(new_clientp, 0);
+			    }
+                        }
+			new_clientp->w_next = NULL;
+		    }
+		    wlist->dga_clientplist_draw = new_clientp;
+
+		    /* the same mbufset is shared between all client 
+		     * structures for this window */
+
+		    if (orig_clientp->pMbs) {
+		        dgai_mbufset_incref(orig_clientp->pMbs);
+		    }
+#ifdef MT
+		    new_clientp->mutexp = &wlist->mutex;
+			/* Same window was grabbed 2 or more times via the
+             * drawable interface so turn per-drawable MT
+             * locking on if we are linked with -lthread also.
+             */
+            if (dgaThreaded) {
+            /* Currently, this variable gets set to 1 and
+             * never gets turned off.  This could be optimized
+             * if needed.
+             */
+            dgaMTOn = 1;
+            }
+#endif
+		    return new_clientp;
+
+		} else {
+		    if (wlist->dga_clientplist)
+		        orig_clientp = wlist->dga_clientplist;
+		    else
+			orig_clientp = wlist->dga_clientplist_draw;
+		    *new_clientp = *orig_clientp;
+	            new_clientp->w_update_func = dga_win_update;
+		    new_clientp->w_lockcnt =0;
+		    new_clientp->w_grab_count =1;
+
+		    if (wlist->dga_clientplist) {
+			/* Add it to the list of clientp structure associated
+		         * with this window */
+		        new_clientp->w_next = orig_clientp;
+                    } else {
+			new_clientp->w_next = NULL;
+		    }
+		    wlist->dga_clientplist = new_clientp;
+#ifdef MT
+		    new_clientp->mutexp = &wlist->mutex;
+#endif
+		    return new_clientp;
+
+		}
+	    }
+	}
+
+	if( (clientp = 
+	    (_Dga_window) malloc(sizeof(struct dga_window))) == NULL )
+	    return NULL ;
+	memset(clientp, 0, sizeof(struct dga_window));
+	
+#ifdef SERVER_DGA
+        {                  
+            /* Now get a pointer to the shared info page from
+             * pWin's private data */
+     
+            DgaSetupWindow(pWin);
+            WDEV    *wdev;
+     
+            wdev = pDgaWindow->pDgaWdev;
+            infop = (WXINFO *)wdev->infop;
+            if (infop == NULL) return NULL;
+         }
+#else
+	sprintf(filename, "%s%08x", GRABFILE, token);
+
+        if ((filefd = open(filename,O_RDWR,0666))<0) {
+	    return((Dga_window)NULL);
+	}
+
+	/* map the wx_winfo area */
+        infop = (WXINFO *)mmap(0,
+		    MAXSHMEMSIZE,
+		    PROT_READ|PROT_WRITE,
+		    MAP_SHARED,
+		    filefd,
+		    (off_t)0);
+
+	if (infop == (WXINFO *)-1) {
+	    close(filefd);
+	    safe_free_clientp(clientp) ;
+	    return((Dga_window)NULL);
+	}
+	if (infop->info_sz != sizeof(WXINFO)) {
+		/* mismatch on 64 bit port or other trouble */
+#ifdef DEBUG
+   		fprintf(stderr, 
+	"wx_grab: mismatch on WXINFO size info page is %d sizeof is %d \n",
+			infop->info_sz, sizeof(WXINFO));
+#endif
+				return(NULL);
+	}
+
+	/* open the frame buffer if not already opened by client */
+	if( devfd >= 0 )
+	  lockfd = devfd ;
+	else {
+	  lockfd = open(infop->w_devname, O_RDWR,0666) ;
+	  if( lockfd < 0 )  {
+#ifdef DEBUG
+	    fprintf(stderr, "wx_grab: cannot open %s, %s\n",
+		infop->w_devname, strerror(errno)) ;
+#endif
+	    munmap((caddr_t)infop, MAXSHMEMSIZE) ;
+	    close(filefd) ;
+	    safe_free_clientp(clientp) ;
+	    return NULL ;
+	  }
+	}
+#endif /* SERVER_DGA */
+
+	if (drawableGrabber) {
+	    clientp->drawable_type = DGA_DRAW_WINDOW;
+	}
+	clientp->w_dpy = dpy;
+	clientp->w_info = (void*)infop ;
+	clientp->w_infofd = 0; /* no longer needed */
+	clientp->w_next = NULL;
+
+	clientp->curs_info = NULL; /* must set up here, may be changed below */
+	clientp->curs_fd = -1;
+
+#ifdef SERVER_DGA
+	clientp->w_devfd = infop->w_sdevfd; ;
+        clientp->w_lockp = (Dga_lockp)infop->w_slockp;
+        clientp->w_unlockp = (Dga_lockp)infop->w_slockp;
+    
+        clientp->w_lib_private = (void *) infop; /* PRIVATE DATA  */
+#else
+	clientp->w_devfd = lockfd ;
+	lockp = NULL; /* init to NULL for check below */
+	unlockp = NULL;
+
+	/* On cursor-grabbed devices, find out if we already have a
+	 * lockp, unlockp, and cursor page mapping for this device.
+	 * We don't want to grab the same lockpage, etc. twice.
+	 */
+	if (infop->w_version >= 2  &&  infop->c_sinfo) {
+	    _Dga_window winp;
+
+	    winp = check_other_curg_windows(infop);
+	    if (winp) {
+		clientp->curs_fd = winp->curs_fd;
+		clientp->curs_info = winp->curs_info;
+		lockp = winp->w_lockp;
+		unlockp = winp->w_unlockp;
+	    }
+	}
+
+	if (lockp == NULL) { 
+	    /* only get new lock pages if necessary */
+	    locktype = infop->w_version >= 2 ? infop->w_locktype : WG_LOCKDEV ;
+	    switch( locktype ) {
+		case WG_LOCKDEV:
+		    /* map the lock page */
+		    lockp = (Dga_lockp)mmap(0,
+			WX_PAGESZ,
+			PROT_READ|PROT_WRITE,
+			MAP_SHARED,
+			lockfd,(off_t)infop->w_cookie);
+
+		    if (lockp == (Dga_lockp)-1) {
+#ifdef DEBUG
+		    fprintf(stderr, "wx_grab: cannot map lock page, %s\n",
+			strerror(errno)) ;
+#endif
+		    munmap((caddr_t)infop, MAXSHMEMSIZE) ;
+		    close(filefd);
+		    if( devfd < 0 )
+		    close(lockfd) ;
+		    safe_free_clientp(clientp) ;
+		    return(NULL);
+		}
+
+		/* map the unlock page */
+		unlockp = (Dga_lockp)mmap(0,
+			WX_PAGESZ,
+			PROT_READ|PROT_WRITE,
+			MAP_SHARED,
+			lockfd,(off_t)infop->w_cookie) ;
+
+		if(unlockp == (Dga_lockp)-1) {
+#ifdef DEBUG
+		fprintf(stderr, "wx_grab: cannot map unlock page\n") ;
+#endif
+		munmap((caddr_t)lockp, WX_PAGESZ) ;
+		munmap((caddr_t)infop, MAXSHMEMSIZE) ;
+		close(filefd);
+		if( devfd < 0 )
+		  close(lockfd) ;
+		safe_free_clientp(clientp) ;
+		return(NULL);
+	    }
+	    break ;
+
+	    case WG_WINLOCK:
+		if( _dga_winlockat(infop->w_cookie, &lockp, &unlockp) != 0 ) {
+		    munmap((caddr_t)infop, MAXSHMEMSIZE);
+		    close(filefd);
+		    if( devfd < 0 )
+			close(lockfd) ;
+		    safe_free_clientp(clientp) ;
+		    return(NULL);
+		}
+	    break ;
+	  }
+	}
+
+	clientp->w_lockp = lockp ;
+	clientp->w_unlockp = unlockp ;
+
+	/* cursor grabber stuff */
+	if ((infop->w_version >= 2)  &&  (infop->c_sinfo) &&
+	  ((clientp->curs_fd == -1) || (clientp->curs_info == NULL))) {
+	    char    cfn[sizeof(CURGFILE)+NDIGITS+1];
+	    int	    curs_fd;
+	    
+	    strcpy(cfn,CURGFILE);
+	    sprintf(cfn+sizeof(CURGFILE)-1,"%08x", infop->c_filesuffix);
+	    
+	    /* open the shared cursor page */
+	    if ((curs_fd = open(cfn, O_RDWR,0666))<0) {
+#ifdef DEBUG
+		fprintf(stderr, "wx_grab: cannot open cursor grabber page\n") ;
+#endif		
+		release_lockpages(devfd, clientp);
+		return((Dga_window)NULL);
+	    }
+	    clientp->curs_fd = curs_fd;
+
+	    /* Map it */
+	    clientp->curs_info = (caddr_t) mmap(0,
+			MINSHMEMSIZE,	
+			PROT_READ|PROT_WRITE,
+			MAP_SHARED,
+			curs_fd,
+			(off_t)0);
+			
+	    if (clientp->curs_info == (caddr_t) -1) {
+#ifdef DEBUG
+		fprintf(stderr, "wx_grab: cannot map cursor page, %s\n",
+		    strerror(errno)) ;
+#endif
+		close(curs_fd);
+		release_lockpages(devfd, clientp);
+		return(NULL);
+	    }
+	    /* check to see if you have a good magic number */
+	    if (((Dga_cursinfo *) (clientp->curs_info))->c_magic !=
+		DGA_CURG_MAGIC) {
+#ifdef DEBUG
+		fprintf(stderr, "wx_grab: wrong cursor page mapped, %s\n",
+		    strerror(errno)) ;
+#endif		
+		munmap(clientp->curs_info, MINSHMEMSIZE) ;
+		close(curs_fd);
+		release_lockpages(devfd, clientp);
+		return(NULL);
+	    }
+	}
+#endif /* SERVER_DGA */
+
+	/* success, fill out rest of structure */
+	clientp->w_token = token;
+	clientp->w_client = 0 ;
+	clientp->c_clipseq = 0 ;
+	clientp->s_clipseq_p = &(infop->u.vn.w_clipseq) ;
+	if (drawableGrabber) {
+	    clientp->w_update_func = (int(*)())dgai_mbsmemb_update;
+	} else {
+	    /* compatibility */
+	    clientp->w_update_func = dga_win_update;
+	}
+#ifdef MT
+	if (dgaThreaded) {
+	    clientp->w_unlock_func = dgai_unlock;
+	} else {
+	    clientp->w_unlock_func = NULL;
+	}
+#else
+	clientp->w_lock_func = NULL;
+	clientp->w_unlock_func = NULL;
+#endif
+	clientp->w_lockcnt = 0;
+	if (infop->w_version != 0) {
+	  clientp->w_clipptr = (short *)((char *)infop+infop->u.vn.w_clipoff);
+          clientp->w_cliplen = 0;
+        }
+	if (infop->w_version < 2) {
+	    clientp->c_chngcnt = 0;
+	    clientp->s_chngcnt_p = clientp->s_clipseq_p;
+	} else {
+	    clientp->c_chngcnt = 0;
+	    clientp->s_chngcnt_p = &(infop->w_chng_cnt);
+	    for (i = 0; i < DGA_MAX_GRABBABLE_BUFS + 1; i ++) {
+	        clientp->c_wm_chngcnt[i] = 0;
+#ifdef MT
+	        clientp->shadow_chngcnt[i] = 0;
+#endif
+	    }
+	}
+        /* Now initialize the next field to pt to the second member of
+         * c_wm_chngcnt array - this is specifically for performance
+         * tuning of the lock macro
+        */
+        clientp->w_wm_2nd = clientp->c_wm_chngcnt + 1;
+
+	if ((infop->w_version < 2) || (clientp->curs_info == NULL)) {
+	    clientp->s_curseq_p = &clientp->c_curseq;
+	    clientp->c_curseq = 0;
+	} else {
+	    clientp->s_curseq_p =
+	        &(((Dga_cursinfo *) (clientp->curs_info))->c_chng_cnt);
+	    clientp->c_curseq =
+		((Dga_cursinfo *) (clientp->curs_info))->c_chng_cnt - 1;
+	    /* so first test of dga_win_curschg will see a change */
+	}
+
+        clientp->back = (void *)malloc(sizeof(dga_internal_buffer_rec));
+        if ( !clientp->back )
+            return NULL;
+
+        clientp->depth = (void *)malloc(sizeof(dga_internal_buffer_rec));
+        if ( !clientp->depth )
+            return NULL;
+
+        clientp->stencil = (void *)malloc(sizeof(dga_internal_buffer_rec));
+        if ( !clientp->stencil )
+            return NULL;
+
+        clientp->accum = (void *)malloc(sizeof(dga_internal_buffer_rec));
+        if ( !clientp->accum )
+            return NULL;
+
+        clientp->alpha = (void *)malloc(sizeof(dga_internal_buffer_rec));
+        if ( !clientp->alpha )
+            return NULL;
+
+        ((dga_internal_buffer)clientp->back)->bufferp = NULL;
+        ((dga_internal_buffer)clientp->depth)->bufferp = NULL;
+        ((dga_internal_buffer)clientp->stencil)->bufferp = NULL;
+        ((dga_internal_buffer)clientp->accum)->bufferp = NULL;
+        ((dga_internal_buffer)clientp->alpha)->bufferp = NULL;
+
+        ((dga_internal_buffer)clientp->back)->pDraw = (Dga_drawable)clientp;
+        ((dga_internal_buffer)clientp->depth)->pDraw = (Dga_drawable)clientp;
+        ((dga_internal_buffer)clientp->stencil)->pDraw = (Dga_drawable)clientp;
+        ((dga_internal_buffer)clientp->accum)->pDraw = (Dga_drawable)clientp;
+        ((dga_internal_buffer)clientp->alpha)->pDraw = (Dga_drawable)clientp;
+
+        ((dga_internal_buffer)clientp->back)->buf_size = 0;
+        ((dga_internal_buffer)clientp->depth)->buf_size = 0;
+        ((dga_internal_buffer)clientp->stencil)->buf_size = 0;
+        ((dga_internal_buffer)clientp->accum)->buf_size = 0;
+        ((dga_internal_buffer)clientp->alpha)->buf_size =  0;
+
+        clientp->buf_resize_flag = 0;
+        clientp->c_buffer_swap = 0;
+
+	clientp->db_enabled = 0;
+	clientp->c_rtnseq = 0;
+	clientp->s_rtnseq_p = &clientp->c_rtnseq;
+	clientp->rtn_info = NULL;
+	clientp->rtn_flags = 0;
+
+        /* initialization for drawable grabber code */
+	clientp->pMbs = NULL;
+	if (drawableGrabber) {
+	    clientp->c_mbufseq = 0;
+	    clientp->s_mbufseq_p = &infop->w_mbsInfo.mbufseq;
+	    clientp->c_mbcomposseq = 0;
+	    clientp->s_mbcomposseq_p = &infop->w_mbsInfo.compositionseq;
+	    clientp->s_devinfoseq_p = &infop->w_devinfoseq;
+	    clientp->c_devinfoseq = 0;
+	    clientp->siteNotifyFunc = NULL;
+	    clientp->siteNotifyClientData = NULL;
+	    clientp->mbNotifyFunc = NULL;
+	    clientp->mbNotifyClientData = NULL;
+	    clientp->rendBufNotifyFunc = NULL;
+	    clientp->rendBufNotifyClientData = NULL;
+	    clientp->rLockSubj = DGA_LOCKSUBJ_INVALID;
+	    clientp->eLockSubj = DGA_LOCKSUBJ_INVALID;
+	    clientp->eLockSubjPrev = DGA_LOCKSUBJ_INVALID;
+	    clientp->changeMask = 0;
+	    clientp->prevWasMbuffered = 0;
+	    clientp->mbChgReason = DGA_MBCHG_UNKNOWN;
+	    clientp->siteChgReason = DGA_SITECHG_UNKNOWN;
+	    clientp->prevLocked = 0;
+	}
+
+	/* add to linked list of grabbed windows - for internal bookkeeping
+	 * Note: this should be done last in order for other code, e.g.
+	 * check_other_curg_windows() to work correctly
+	 */
+	if (!dga_wlist) {
+
+	   if ((dga_wlist = 
+	    (Dga_winlist) malloc(sizeof(struct dga_winlist))) == NULL )
+	    return NULL ;
+	   dga_wlist->w_token = token;
+	   if (drawableGrabber) {
+	       dga_wlist->dga_clientplist_draw = clientp;
+	       dga_wlist->dga_clientplist = NULL;
+	   } else {
+	       dga_wlist->dga_clientplist_draw = NULL;
+	       dga_wlist->dga_clientplist = clientp;
+	   }
+	   dga_wlist->next_winlist = NULL;
+	} else {
+	   struct dga_winlist *new_wlist;
+		
+	   if ((new_wlist =
+                   (Dga_winlist) malloc(sizeof(struct dga_winlist))) == NULL )
+		return NULL;
+	   new_wlist->w_token = token;
+	   if (drawableGrabber) {
+	       new_wlist->dga_clientplist_draw = clientp;
+	       new_wlist->dga_clientplist = NULL;
+	   } else {
+	       new_wlist->dga_clientplist_draw = NULL;
+	       new_wlist->dga_clientplist = clientp;
+	   }
+	   new_wlist->next_winlist = dga_wlist;
+	   dga_wlist = new_wlist;
+	}
+#ifndef SERVER_DGA
+	close(filefd) ;
+#endif /* SERVER_DGA */
+
+#ifdef MT
+	mutex_init(&dga_wlist->mutex, USYNC_THREAD, NULL);
+	clientp->mutexp = &dga_wlist->mutex;
+#endif
+
+	/* If window is multibuffered, initialize multibuffer set */
+	/* If window is being grabbed through the old interface don't
+	 * init the mbufset since mbuffers where not supported int
+	 * older versions of DGA */
+	if ((dpy != NULL) && drawableGrabber) {
+	    if (!dgai_win_initMbufset(clientp)) {
+		dga_win_ungrab(clientp, 0);
+	    }
+	}
+
+	return((Dga_window)clientp);
+}
+
+
+Dga_window
+dga_win_grab(devfd, token)
+	int		devfd;
+	Dga_token	token;
+{
+    /* Call the common grab routine with dpy == NULL to signify that
+     * mbuffers are not to be initialized. */
+
+    return (dgai_win_grab_common(NULL, devfd, token, 0));
+}
+
+
+#ifndef SERVER_DGA
+static _Dga_window
+check_other_curg_windows(infop)
+WXINFO *infop;
+{
+	Dga_winlist winp;
+	_Dga_window clientp;
+	WXINFO *linfop;
+
+	for(winp = dga_wlist; winp != NULL; winp = winp->next_winlist) {
+	    if (clientp = winp->dga_clientplist_draw) {
+		linfop = (WXINFO *) clientp->w_info;
+		if (strcmp(linfop->w_devname, infop->w_devname) == 0) {
+		    return(clientp);
+		}
+	    }
+	    if (clientp = winp->dga_clientplist) {
+		linfop = (WXINFO *) clientp->w_info;
+		if (strcmp(linfop->w_devname, infop->w_devname) == 0) {
+		    return(clientp);
+		}
+	    }
+	}
+	return NULL;
+}
+
+
+static void
+release_lockpages(devfd, clientp)
+	int		devfd ;
+	_Dga_window	clientp;
+{
+	int		lockfd = clientp->w_devfd ;
+	WXINFO		*infop = (WXINFO *) clientp->w_info ;
+	Dga_lockp	lockp = clientp->w_lockp ;
+	Dga_lockp	unlockp = clientp->w_unlockp ;
+	int		locktype ;
+
+	if ((clientp->curs_info ||
+	     ((infop->w_version >= 2)  &&  (infop->c_sinfo))) &&
+	    ((check_other_curg_windows(infop) != NULL) ||
+	     (check_other_curg_windows(infop) == NULL && infop->w_devname[0] == 0))) { 
+	    /* don't free lock pages
+	     * Note: check both clientp->curs_info and infop->c_sinfo because
+	     * this routine is called both at grab and ungrab time.  Client
+	     * may not have set curs_info non-zero at grab time.  Server may
+	     * set c_sinfo NULL at window destroy time.
+	     */
+	} else {
+	    locktype = infop->w_version >= 2 ? infop->w_locktype : WG_LOCKDEV ;
+	    switch(locktype ) {
+	      case WG_LOCKDEV:
+	        munmap((caddr_t)lockp, WX_PAGESZ) ;
+	        munmap((caddr_t)unlockp, WX_PAGESZ) ;
+	        break ;
+	      case WG_WINLOCK:
+	        (void) _dga_winlockdt((int *)lockp, (int *)unlockp) ;
+	        break ;
+	    }
+	}
+	if( devfd < 0 )
+	     close(lockfd) ;
+	munmap((caddr_t)infop, MAXSHMEMSIZE) ;
+	safe_free_clientp(clientp) ;
+}
+#endif /* SERVER_DGA */
+
+void
+dga_win_ungrab(clientpi, cflag)
+    Dga_window  clientpi;
+    int cflag ;
+{
+    _Dga_window clientp = (struct dga_window *)clientpi;
+ 
+    dgai_win_ungrab_common(clientpi,cflag, 0);
+}
+
+void
+dgai_win_ungrab_common(clientp, cflag,drawableGrabber)
+    _Dga_window	clientp;
+    int	cflag ;
+    int drawableGrabber;
+{
+
+    WXINFO	*infop = (WXINFO *) clientp->w_info ;
+    int	infofd, devfd , curs_fd, match;
+    struct dga_winlist	*prevwinp, *winp;
+
+    /* remove from linked list of grabbed windows
+     * Note: this should be done first in order for other code, e.g.
+     * check_other_curg_windows() to work correctly
+     */
+    match = 0;
+    winp = dga_wlist;
+    prevwinp = NULL;
+    while (winp) {
+	if (winp->w_token == clientp->w_token) {
+	    struct dga_window *clntp, *prevclntp;
+	    if (drawableGrabber)			
+	    	clntp = winp->dga_clientplist_draw;
+	    else
+		clntp = winp->dga_clientplist;
+
+	    prevclntp = NULL;
+	    while (clntp) {
+		if (clntp == clientp) {
+		    match = 1;
+		    if( prevclntp )
+			prevclntp->w_next = clntp->w_next;
+		    else {
+			if (drawableGrabber)
+			    winp->dga_clientplist_draw = clntp->w_next;
+			else
+			    winp->dga_clientplist = clntp->w_next;
+		    }
+		    break;
+		}
+		prevclntp = clntp;
+		clntp = clntp->w_next;
+	    }
+	    if (!match) {
+		/* Check for old style clients */
+	        clntp = winp->dga_clientplist;
+	        prevclntp = NULL;
+	        while (clntp) {
+		    if (clntp == clientp) {
+		        match = 1;
+		        if( prevclntp )
+			    prevclntp->w_next = clntp->w_next;
+		        else {
+			    if (drawableGrabber)
+				winp->dga_clientplist_draw = clntp->w_next; 
+			    else
+			        winp->dga_clientplist = clntp->w_next;
+			}
+		        break;
+		    }
+		    prevclntp = clntp;
+		    clntp = clntp->w_next;
+	        }
+	    }
+	    break ;
+	}
+	prevwinp = winp;
+	winp = winp->next_winlist;
+    }
+
+    if (!match)
+	return;	/* error */
+
+    /* TODO: do this for every client, or only once? */
+    if ((clientp->rtn_flags & RTN_GRABBED) && (!winp->dga_clientplist))
+	dga_rtn_ungrab(clientp);
+    if (clientp->db_enabled && (!winp->dga_clientplist))
+	dga_db_release(clientp);
+    devfd = clientp->w_devfd ;
+
+#ifndef SERVER_DGA
+    /* Cursor grabber stuff */
+    /* TODO: do this for every client, or only once? */
+    if ((clientp->curs_info) && (check_other_curg_windows(infop) == NULL) &&
+	(!infop->c_sinfo)) { 
+	curs_fd = clientp->curs_fd;
+	munmap(clientp->curs_info, MINSHMEMSIZE) ;
+	close(curs_fd);
+    }
+#endif /* SERVER_DGA */
+
+    /* deref any associated multibuffer set */
+    if (clientp->pMbs) {
+	dgai_mbufset_decref(clientp->pMbs);
+	clientp->pMbs = NULL;
+    }
+
+    /* TODO: shouldn't we free the clientp??? */
+    /* Now check to see  if all that needs to be freed has been freed */
+    if ((winp->dga_clientplist_draw == NULL) && 
+	(winp->dga_clientplist == NULL)){
+#ifndef SERVER_DGA
+	release_lockpages( cflag ? -1 : 0, clientp ) ;
+#endif /* SERVER_DGA */
+	/* Then free this node and unlink it from the list */	
+	if( prevwinp != NULL )
+	    prevwinp->next_winlist = winp->next_winlist ;
+	else
+	    dga_wlist = winp->next_winlist ;
+#ifdef MT
+	mutex_destroy(&winp->mutex);
+#endif
+	free(winp);
+    }
+}
+
+int
+dgai_win_check_multiple_grab(clientp, drawableGrabber)
+_Dga_window clientp;
+{
+
+    struct dga_winlist *winp;
+    int match;
+
+    /* Checking to see if this client is grabbing a multiply grabbed
+     * window	
+    */
+    match = 0;
+    winp = dga_wlist;
+
+    while (winp) {
+	if (winp->w_token == clientp->w_token) {
+	    /* Now we have the correct window */
+	    struct dga_window *clntp, *prevclntp;
+
+            if (drawableGrabber)         
+                clntp = winp->dga_clientplist_draw;
+            else
+                clntp = winp->dga_clientplist;
+
+            prevclntp = NULL;
+            while (clntp) {
+		/* Now we have the correct client */
+                if (clntp == clientp) {
+		   /* Check to see if there are any more... */
+		   if (prevclntp || clntp->w_next) {
+			match = 1;
+			break;	
+		    }	
+		}
+		prevclntp = clntp;
+		clntp = clntp->w_next;
+	    }
+	    if (match) break;
+        }
+	winp = winp->next_winlist;
+    }
+    return match; 
+}
+
+short *
+dga_win_clipinfo(wini)
+Dga_window	wini ;
+{
+    _Dga_window win = (struct dga_window *)wini;
+    WXINFO	*infop = (WXINFO *) win->w_info ;
+
+    if (wx_shape_flags(infop) & DGA_SH_RECT_FLAG)
+	  return((short *)&((struct class_SHAPE_vn *)((char *)(infop) +
+	      (infop)->u.vn.w_shapeoff))->SHAPE_YMIN);
+    return(win->w_clipptr);
+}
+
+
+char *
+dga_win_fbname(wini)
+Dga_window wini;
+{
+    _Dga_window win = (struct dga_window *)wini;
+    
+    return(((WXINFO *) (win->w_info))->w_devname);
+}
+
+int
+dga_win_clipchg(wini)
+Dga_window wini;
+{
+    _Dga_window win = (struct dga_window *)wini;
+    
+    if (win->c_clipseq != *(win->s_clipseq_p)) {
+	((WXINFO *) win->w_info)->w_flag &= ~WMODIF;
+	win->c_clipseq = *(win->s_clipseq_p);
+	return 1;
+    }
+    return 0;
+}
+
+int
+dga_win_curschg(wini)
+Dga_window wini;
+{
+    _Dga_window win = (struct dga_window *)wini;
+    
+    if (win->c_curseq != *(win->s_curseq_p)) {
+	win->c_curseq = *(win->s_curseq_p);
+	return 1;
+    }
+    return 0;
+}
+
+int
+dga_win_rtnchg(wini)
+Dga_window wini;
+{
+    _Dga_window win = (struct dga_window *)wini;
+    if ((win->rtn_flags & RTN_GRABBED) && !(win->rtn_flags & RTN_MAPPED)) {
+	/* rtn grabbed, but not currently mapped */
+	if (win->rtn_flags & RTN_MAPCHG) {
+	    /* just went unmapped */
+	    win->rtn_flags &= ~RTN_MAPCHG;
+	    return 1;
+	}
+	return 0;
+    }
+    /* otherwise either not rtn grabbed or have a rtn mapping */
+    if (win->c_rtnseq != *(win->s_rtnseq_p)) {
+	win->c_rtnseq = *(win->s_rtnseq_p);
+	return 1;
+    }
+    return 0;
+}
+
+int
+dga_win_devfd(wini)
+Dga_window wini;
+{
+    _Dga_window win = (struct dga_window *)wini;
+    return(win->w_devfd);
+}
+
+void
+dga_win_bbox(wini, xp, yp, widthp, heightp)
+Dga_window wini;
+int *xp, *yp, *widthp, *heightp;
+{
+    _Dga_window win = (struct dga_window *)wini;
+    WXINFO *infop = (WXINFO *) win->w_info;
+
+    if (infop->w_version < 2) {
+	*xp = infop->w_org.x >> 16;
+	*yp = infop->w_org.y >> 16;
+	*widthp = infop->w_dim.x >> 16;
+	*heightp = infop->w_dim.y >> 16;
+	return;
+    }
+    *xp = infop->w_window_boundary.xleft;
+    *yp = infop->w_window_boundary.ytop;
+    *widthp = infop->w_window_boundary.width;
+    *heightp = infop->w_window_boundary.height;
+}
+
+int
+dga_win_singlerect(wini)
+Dga_window wini;
+{
+    _Dga_window win = (struct dga_window *)wini;
+    WXINFO *infop = (WXINFO *) win->w_info;
+
+    return(wx_shape_flags(infop) & DGA_SH_RECT_FLAG);
+}
+
+int
+dga_win_empty(wini)
+Dga_window wini; 
+{ 
+    _Dga_window win = (struct dga_window *)wini;
+    WXINFO *infop = (WXINFO *) win->w_info;
+
+    return(wx_shape_flags(infop) & DGA_SH_EMPTY_FLAG);
+}
+
+u_char
+dga_win_depth(wini)
+Dga_window wini;
+{
+    _Dga_window win = (struct dga_window *)wini;
+    WXINFO *infop = (WXINFO *) win->w_info;
+	
+    if (infop->w_version >= 3) 
+	return(infop->w_depth);
+    else 
+	return 0;
+}
+
+u_short
+dga_win_borderwidth(wini) 
+Dga_window wini; 
+{ 
+    _Dga_window win = (struct dga_window *)wini;
+    WXINFO *infop = (WXINFO *) win->w_info; 
+      
+    if (infop->w_version >= 3) 
+        return(infop->w_borderwidth);
+    else  
+        return 0; 
+} 
+
+int
+dga_win_obscured(wini)
+Dga_window wini;
+{
+    _Dga_window win = (struct dga_window *)wini;
+    WXINFO *infop = (WXINFO *) win->w_info;
+    int xb, yb, wb, hb;
+    int ytop, ybot, xleft, xright;
+    int tmp;
+    short *ptr;
+
+    if (wx_shape_flags(infop) & DGA_SH_RECT_FLAG) {
+	dga_win_bbox(win, &xb, &yb, &wb, &hb);
+	ptr = dga_win_clipinfo(win);
+	ytop = *ptr++; ybot = *ptr++; xleft = *ptr++; xright = *ptr++;
+	if (ytop > ybot) {
+	    tmp = ytop; ytop = ybot; ybot = tmp;
+	}
+	if (xleft > xright) {
+	    tmp = xleft; xleft = xright; xright = tmp;
+	}
+	if ((yb == ytop) && (xb == xleft) &&
+	    (hb == (ybot - ytop)) && (wb == (xright - xleft))) {
+		return 1;
+	}
+    }
+    return 0;
+}
+
+int
+dgai_win_visibility(Dga_window wini)
+{
+    if (dga_win_empty(wini))
+	return (DGA_VIS_FULLY_OBSCURED);
+    /* This routine returns the reverse of what one would think.
+     * it returns true if the window is unobscured false otherwise. */
+    else if (!dga_win_obscured(wini))
+	return (DGA_VIS_PARTIALLY_OBSCURED);
+    
+    return (DGA_VIS_UNOBSCURED);
+
+    /*  This will work when we get to R6 but for now the visibility
+     * entry in the window structure (which is where this comes from)
+     * is bogus.  I looked at the R6 code and it looks like they
+     * attempted to get this working.
+    _Dga_window win = (struct dga_window *)wini;
+    WXINFO *infop = (WXINFO *) win->w_info;
+    
+    return (infop->w_visibility);
+    */
+}	
+
+#define	ROUNDUP(i)	(((i)+WX_PAGESZ-1)&~(WX_PAGESZ-1))
+
+void
+dgai_win_clip_update (_Dga_window clientp)
+{
+    /* Do anything here that may require unlock/relock, because
+    * it takes so long.
+    */
+
+    WXINFO	*infop = (WXINFO *) clientp->w_info ;
+    unsigned int	cliplen;
+    short	*clipptr;
+    short	*cmclip;
+#ifndef SERVER_DGA
+    char	filename[sizeof(GRABFILE)+NDIGITS+1];
+    int		filefd;
+#endif /*SERVER_DGA */
+
+    cmclip = (short *)((char *)infop+infop->u.vn.w_clipoff);
+
+#ifdef SERVER_DGA
+    if (infop->w_flag & WEXTEND) { /* server has an extended mapping */
+        if (clientp->w_clipptr == cmclip) {
+            clientp->w_cliplen = infop->w_scliplen;
+            clientp->w_clipptr = (short *)infop->u.vn.w_sclipptr;
+        }
+    } else {
+        if (clientp->w_clipptr != cmclip) {
+            clientp->w_clipptr = cmclip;
+        }
+    }
+#else
+    while(1) {
+	if (infop->w_flag & WEXTEND) { 
+	    /* server has an extended mapping */
+	    if (clientp->w_clipptr == cmclip) { 
+		/* ...and we don't. */
+		cliplen = infop->w_scliplen;
+		DGA_UNLOCK(clientp);
+		sprintf(filename, "%s%08x", GRABFILE, clientp->w_token);
+
+		if ((filefd = open(filename,O_RDWR,0666))<0) {
+		    return;
+		}
+		if (ftruncate(filefd,MINSHMEMSIZE+cliplen)<0) {
+		    close(filefd);
+		    return;
+		}
+
+		close(filefd);
+
+		clipptr = (short *)((char *)infop + MINSHMEMSIZE);
+
+		DGA_LOCK(clientp);
+		if ((int)clipptr != -1) {
+		    clientp->w_cliplen = cliplen;
+		    clientp->w_clipptr = clipptr;
+		}
+		continue;  /* at while */
+	    }
+	    if (clientp->w_cliplen != infop->w_scliplen) {
+		/* ...and we do... but the wrong size. */
+		cliplen = infop->w_scliplen;
+		DGA_UNLOCK(clientp);
+		sprintf(filename, "%s%08x", GRABFILE, clientp->w_token);
+
+		if ((filefd = open(filename,O_RDWR,0666))<0) {
+		    return;
+		}
+		if (ftruncate(filefd,MINSHMEMSIZE+cliplen)<0) {
+		    close(filefd);
+		    return;
+		}
+		close(filefd);
+		clipptr = (short *)((char *)infop + MINSHMEMSIZE);
+
+		DGA_LOCK(clientp);
+		if ((int)clipptr == -1)
+		    clientp->w_clipptr = cmclip;
+		else {
+		    clientp->w_cliplen = cliplen;
+		    clientp->w_clipptr = clipptr;
+		}
+		continue;  /* at while */
+	    }
+	} else { 	
+	    /* server doesn't have an extended mapping */
+            if (clientp->w_clipptr != cmclip) { 
+		/* ...and we do. */
+                DGA_UNLOCK(clientp);
+		sprintf(filename, "%s%08x", GRABFILE, clientp->w_token);
+
+		if ((filefd = open(filename,O_RDWR,0666))<0) {
+		    clientp->w_clipptr = cmclip;
+		    return;
+		}
+		if (ftruncate(filefd,MINSHMEMSIZE)<0) {
+		    clientp->w_clipptr = cmclip;
+		    close(filefd);
+		    return;
+		}
+		close(filefd);
+
+                DGA_LOCK(clientp);
+		clientp->w_clipptr = cmclip;
+		continue;  /* at while */
+	    }
+	    /*
+	    else {	 ...nor do we
+		break;
+	    }
+	    */
+	}
+    break;
+    }
+#endif /* SERVER_DGA */
+}
+
+void
+dgai_win_curs_update(_Dga_window win)
+{
+    /* Do anything here that may require unlock/relock, because
+    * it takes so long.
+    *
+    * We can add code here in the future to remap the cursor page,
+    * etc., if we want.
+    */
+    return;
+}
+
+
+/*
+ *
+ *  dgai_rtn_update()
+ *
+ *  Do anything here that may require unlock/relock, because
+ *  it takes so long.  Remap retained info, etc.
+ *
+ *  DGA Retained Window Information Update.  This function checks that the
+ *  shared retained information structure hasn't become obsolete.  If the
+ *  structure is found to be obsolete, this routine attempts to free and
+ *  re-allocate the resources associated with the retained window.  Nothing
+ *  is done in the event that the shared retained information is not obsolete.
+ *
+ *  Inputs:     Dga_window - Pointer to the dga_window structure for which
+ *                           the the shared retained info structure is to
+ *                           be removed.
+ *
+ *  Outputs:    None.
+ *
+ *  Globals:    None.
+ *
+ *  Externals:  DGA_LOCK()              DGA MACRO
+ *              DGA_UNLOCK()            DGA MACRO
+ *              RTN_INFOP()             DGA MACRO
+ *              _dga_rtn_map()
+ *              _dga_rtn_unmap()
+ *
+ */
+void
+dgai_win_rtn_update (_Dga_window clientp)
+{
+    unsigned int         mapped;
+ 
+#ifdef SERVER_DGA
+    mapped = clientp->rtn_flags & RTN_MAPPED;
+    if (mapped && RTN_INFOP(clientp)->obsolete) {
+        /* mapped, but obsolete */
+        (void) _dga_rtn_unmap(clientp);
+        (void)  _dga_rtn_map(clientp);
+    }
+ 
+    if (!mapped && (((WXINFO *) clientp->w_info)->w_srtndlink != NULL)) {
+        /* unmapped on client side, but server has valid w_srtndlink */
+        (void) _dga_rtn_map(clientp);
+    }
+#else
+    while (1) {
+	mapped = clientp->rtn_flags & RTN_MAPPED;
+        if (mapped && RTN_INFOP(clientp)->obsolete) {
+	    /* mapped, but obsolete */
+            DGA_UNLOCK(clientp);
+            (void) _dga_rtn_unmap(clientp);
+            (void)  _dga_rtn_map(clientp);
+            DGA_LOCK(clientp);
+            continue;
+        } 
+	if (!mapped && (((WXINFO *) clientp->w_info)->w_srtndlink != NULL)) {
+	    /* unmapped on client side, but server has valid w_srtndlink */
+	    DGA_UNLOCK(clientp);
+	    (void) _dga_rtn_map(clientp);
+	    DGA_LOCK(clientp);
+	    continue;
+	}
+        break;
+    }    
+#endif /* SERVER_DGA */
+}
+
+
+static int
+dga_win_update(wini)
+Dga_window wini;
+{
+    _Dga_window win = (struct dga_window *)wini;
+    WXINFO *infop = (WXINFO *) win->w_info;
+    unsigned int sav_clipseq, sav_curseq, sav_rtnseq;
+
+    /* establish the new real lock subject */
+    win->rLockSubj = -1;
+ 
+    /* save last lock subject.  This may be used later in the update phase */
+    win->eLockSubjPrev = win->eLockSubj;
+
+    /* start out assuming we're not aliased.  This may change if we detect
+       aliasing later in the update phase */
+    win->eLockSubj = win->rLockSubj;
+
+    /* Do anything here that may require unlock/relock, because
+    * it takes so long.  Also, update win->c_chngcnt.
+    */
+
+    sav_clipseq = win->c_clipseq;
+    sav_curseq = win->c_curseq;
+    sav_rtnseq = win->c_rtnseq;
+    do {
+	/* repeat update functions as needed
+	 * through possible unlock/relocks
+	*/
+	if (sav_clipseq != *win->s_clipseq_p) {
+	    dgai_win_clip_update(win);
+	    sav_clipseq = *win->s_clipseq_p;
+	}
+	if (sav_curseq != *win->s_curseq_p) {
+	    dgai_win_curs_update(win);
+	    sav_curseq = *win->s_curseq_p;
+	}
+	if ((sav_rtnseq != *win->s_rtnseq_p) ||
+	    ((win->rtn_flags & RTN_GRABBED) &&
+	     !(win->rtn_flags & RTN_MAPPED))) {
+		dgai_win_rtn_update(win);
+		sav_rtnseq = *win->s_rtnseq_p;
+	}
+    } while ((sav_clipseq != *win->s_clipseq_p) ||
+	 (sav_curseq != *win->s_curseq_p) ||
+	 (sav_rtnseq != *win->s_rtnseq_p));
+
+    if (infop->w_version < 2) {	
+	/* pre OWV3 */
+	win->c_chngcnt = *win->s_chngcnt_p;
+	return 1;
+    } else {		
+	/* post OWV3 beta */
+	win->c_chngcnt = *win->s_chngcnt_p;
+	return 1;
+    }
+}
+
+int
+dga_win_cursactive(wini)
+Dga_window wini;
+{
+    _Dga_window win = (struct dga_window *)wini;
+    if (win->curs_info)
+	return 1;
+    return 0;
+}
+
+void
+dga_win_cursupdate(wini, func, data)
+Dga_window	wini;
+void		(*func)();
+void*		data;
+{
+    _Dga_window win = (struct dga_window *)wini;
+    /* assumes the window is already locked */
+
+    Dga_cursinfo	*curgp = (Dga_cursinfo *) (win->curs_info);
+    Dga_curs_mpr	*curg_mpr;
+    Dga_curs_memimage curg_mem;
+    int		x, y, w, h;
+
+    if ((curgp == 0) || (curgp->c_state_flag != DGA_CURSOR_UP))
+		return;
+
+    curg_mpr = (Dga_curs_mpr *) ((char *) curgp + curgp->c_offset);
+
+    dga_win_bbox(win, &x, &y, &w, &h);
+    if (((curgp->c_org.x + curg_mpr->curg_dim.x) < x) ||
+        (curgp->c_org.x > (x + w)) ||
+        ((curgp->c_org.y + curg_mpr->curg_dim.y) < y) ||
+        (curgp->c_org.y > (y + h)))
+    	return;
+
+    if (func) {
+	curg_mem.width = curg_mpr->curg_dim.x;
+	curg_mem.height = curg_mpr->curg_dim.y;
+	curg_mem.depth = curg_mpr->curg_depth;
+	curg_mem.linebytes = curg_mpr->curg_linebytes;
+#ifdef _LP64
+	curg_mem.memptr = (void *)(curg_mpr + 1);
+#else  /* _LP64 */
+	curg_mem.memptr = ((caddr_t) curg_mpr) + sizeof(Dga_curs_mpr);
+#endif /* _LP64 */
+	(*func) (data, win, curgp->c_org.x, curgp->c_org.y, &curg_mem);
+	curgp->c_state_flag = DGA_CURSOR_DOWN;
+	/* have to bump the shared memory counter, so update the saved
+	* version as well
+	*/
+	win->c_curseq = ++(curgp->c_chng_cnt); 
+    }
+}
+
+Dga_dbinfo *
+dga_win_dbinfop(wini)
+Dga_window wini;
+{
+    _Dga_window win = (struct dga_window *)wini;
+    return ((Dga_dbinfo *)&(((WXINFO *) win->w_info)->wx_dbuf));
+}
+
+Dga_widinfo *
+dga_win_widinfop(wini)
+Dga_window wini;
+{
+    _Dga_window win = (struct dga_window *)wini;
+    return ((Dga_widinfo *)(&(((WXINFO *) win->w_info)->w_wid_info)));
+}
+
+void
+dga_win_set_client_infop(wini, client_info_ptr)
+Dga_window wini;
+void* client_info_ptr;
+{
+    _Dga_window win = (struct dga_window *)wini;
+    win->w_client = client_info_ptr;
+}
+
+void *
+dga_win_get_client_infop(wini)
+Dga_window wini;
+{
+    _Dga_window win = (struct dga_window *)wini;
+    return (void *)(win->w_client);
+}
+
+
+static int
+dgai_win_initMbufset (_Dga_window dgawin)
+{
+    WXINFO	*infop;
+    int		status = 0; 
+
+    /* Lock the window to see if it is multibuffered */
+#ifndef SERVER_DGA
+    DGA_LOCK(dgawin);
+#endif /* SERVER_DGA */
+
+    infop = (WXINFO *) dgawin->w_info;
+    if (!infop->w_mbsInfo.enabled) {
+	/* it's okay if it's not multibuffered; return success */
+	dgawin->pMbs = NULL;
+	status = 1;
+	goto Exit;
+    }
+
+    if (!(dgawin->pMbs = dgai_mbufset_create(dgawin))) {
+	goto Exit;
+    }
+
+    dgawin->c_mbcomposseq = *dgawin->s_mbcomposseq_p;
+
+    /* success */
+    status = 1;
+
+Exit:
+#ifndef SERVER_DGA
+    DGA_UNLOCK(dgawin);
+#endif /* SERVER_DGA */
+    return (status);
+}
+
+#ifdef SERVER_DGA
+/*
+ *  There is no equivalent for the following function in client side
+ *  The main purpose of this function is to isolate SHAPES header files
+ *  and XGL files.
+ */
+
+void
+dga_win_lock(win)
+Dga_window win;
+{
+       _Dga_window 	wini = (_Dga_window)win;
+
+       if (((wini)->w_lockcnt)++ == 0) {
+            wg_lock((WXINFO *) (wini->w_lib_private));
+            DGA_S_LOCK(wini);
+            wini->w_modif = ((((wini)->c_chngcnt) == (*((wini)->s_chngcnt_p)))
+                 ? 0 : (*((wini)->w_update_func))(wini));
+       } 
+ 
+}
+ 
+/*
+ *  There is no equivalent for the following function in client side
+ *  The main purpose of this function is to isolate SHAPES header file
+ *  and XGL files.
+ */
+ 
+void
+dga_win_unlock(win)
+Dga_window win;
+{
+       _Dga_window 	wini = (_Dga_window)win;
+
+        if (--((wini)->w_lockcnt) == 0) {
+                        wg_unlock((WXINFO *) (wini->w_lib_private));
+                        if ((wini)->w_unlock_func)
+                                (*((wini)->w_unlock_func))(wini);
+        }
+ 
+}
+#endif /* SERVER_DGA */
+
+
+#ifdef	DEBUG
+dga_win_dump(clientpi)
+	Dga_window	clientpi ;
+{
+	_Dga_window clientp = (struct dga_window *)clientpi;
+WXINFO	*infop = (WXINFO *) clientp->w_info ;
+
+	printf("client page is %p\n", clientp) ;
+	printf("  w_info = %p\n", (WXINFO *) clientp->w_info) ;
+	printf("  w_next = %p\n", clientp->w_next) ;
+	printf("  w_client = %p\n", clientp->w_client) ;
+	printf("  c_clipseq = %u\n", clientp->c_clipseq) ;
+	printf("  s_clipseq_p = %p\n", clientp->s_clipseq_p) ;
+	printf("  w_update_func = %p\n", clientp->w_update_func) ;
+	printf("  w_infofd = %d\n", clientp->w_infofd) ;
+	printf("  w_devfd = %d\n", clientp->w_devfd) ;
+	printf("  w_lockcnt = %d\n", clientp->w_lockcnt) ;
+	printf("  w_lockp = %p\n", clientp->w_lockp) ;
+	printf("  w_unlockp = %p\n", clientp->w_unlockp) ;
+	printf("  w_clipptr = %p\n", clientp->w_clipptr) ;
+	printf("  w_cliplen = %u\n", clientp->w_cliplen) ;
+
+	printf("info page is %p\n", infop) ;
+	printf("  w_flag = %lu\n", infop->w_flag) ;
+	printf("  w_magic = %ld\n", infop->w_magic) ;
+	printf("  w_version = %ld\n", infop->w_version) ;
+	printf("  w_cunlockp = %p\n", infop->w_cunlockp) ;
+	printf("  w_devname = %s\n", infop->w_devname) ;
+	printf("  w_cookie = %lu\n", infop->w_cookie) ;
+	printf("  w_clipoff = %ld\n", infop->u.vn.w_clipoff) ;
+	printf("  w_scliplen = %u\n", infop->w_scliplen) ;
+	printf("  w_org = %u,(%f,%f)\n",
+		infop->w_org.t, infop->w_org.x/65536., infop->w_org.y/65536.) ;
+	printf("  w_dim = %u,(%f,%f)\n",
+		infop->w_dim.t, infop->w_dim.x/65536., infop->w_dim.y/65536.) ;
+	printf("  &w_shape_hdr = %p\n", &infop->u.v0.w_shape_hdr) ;
+	printf("  &w_shape = %p\n", &infop->w_shape) ;
+	printf("  w_shape.SHAPE_FLAGS = %u\n", infop->w_shape.SHAPE_FLAGS) ;
+	printf("  w_shape.SHAPE_YMIN = %d\n", infop->w_shape.SHAPE_YMIN) ;
+	printf("  w_shape.SHAPE_YMAX = %d\n", infop->w_shape.SHAPE_YMAX) ;
+	printf("  w_shape.SHAPE_XMIN = %d\n", infop->w_shape.SHAPE_XMIN) ;
+	printf("  w_shape.SHAPE_XMAX = %d\n", infop->w_shape.SHAPE_XMAX) ;
+	printf("  w_shape.SHAPE_X_EOL = %d\n", infop->w_shape.SHAPE_X_EOL) ;
+	printf("  w_shape.SHAPE_Y_EOL = %d\n", infop->w_shape.u.SHAPE_Y_EOL) ;
+	printf("  &w_cliparray = %p\n", &infop->w_cliparray) ;
+}
+#endif /* DEBUG */
+
+#ifdef MT
+int
+dgai_unlock(Dga_drawable dgadraw)
+{
+    _Dga_window dgawin;
+
+    if (dgaMTOn) {
+	dgawin = (_Dga_window) dgadraw;
+	mutex_unlock(dgawin->mutexp);
+    }
+}
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/lib/libdga/sun-src/win_grab.h	Fri Nov 13 13:30:43 2009 -0800
@@ -0,0 +1,81 @@
+/* Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ *
+ * 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, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * 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
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR 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.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+#pragma ident	"@(#)win_grab.h	35.2	09/11/09 SMI"
+
+/*
+ * win_grab.h - DGA Window Grabber definitions
+ */
+
+#ifndef _WIN_GRAB_H
+#define _WIN_GRAB_H
+
+
+/****
+ *
+ * WIN_GRAB.H Window Grabber
+ *
+ * MACROS: These return info from the client page.
+ *
+ *	wx_infop(clientp)	the info page.
+ *	wx_devname_c(clientp)	returns the w_devname field.
+ *	wx_version_c(clientp)	the version
+ *	wx_lock_c(clientp)	locks the info page.
+ *	wx_unlock_c(clientp)	unlocks the info page.
+ *
+ * These return info from the info page.
+ *
+ *	wx_devname(infop)	returns the w_devname field.
+ *	wx_version(infop)	the version
+ *
+ *	wx_shape_flags(infop)	Shapes flag
+ *
+ ****/
+
+
+
+#define	DGA_SH_RECT_FLAG	1
+#define	DGA_SH_EMPTY_FLAG	128
+
+
+/*
+ *  Window grabber info macros
+ */
+
+#define	wx_infop(clientp)	((WXINFO *) (clientp)->w_info)
+
+#define	wx_version(infop)	((infop)->w_version)
+
+#define wx_shape_flags(infop)			\
+	(((struct class_SHAPE_vn *)		\
+	    ((char *)(infop) +			\
+	     (infop)->u.vn.w_shapeoff))->SHAPE_FLAGS)	\
+
+
+#endif /* _WIN_GRAB_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/lib/libdga/sun-src/win_update.c	Fri Nov 13 13:30:43 2009 -0800
@@ -0,0 +1,332 @@
+/* Copyright 1994 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ *
+ * 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, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ *
+ * 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
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR 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.
+ *
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+#pragma ident	"@(#)win_update.c	35.3	09/11/09 SMI"
+
+/*
+**
+** win_update.c
+**
+** Routines of the update phase for windows.
+*/
+
+#include <assert.h>
+#ifdef SERVER_DGA
+#include <X11/Xlib.h>
+#endif /* SERVER_DGA */
+#include "dga_incls.h"
+#include "pix_grab.h"
+#include "mbufsetstr.h"
+#include "rtn_grab.h"
+
+static void	dgai_win_getLastSeqs (_Dga_window dgawin, DgaLastSeqsPtr pLastSeqs);
+static int	dgai_win_syncAgain (_Dga_window dgawin, DgaLastSeqsPtr pLastSeqs);
+static void 	dgai_win_mb_update (_Dga_window dgawin);
+static void	dgai_mbwin_syncLockSubj (_Dga_window dgawin);
+
+
+/*
+** Note: for the sake of simplicity, we always report the following
+** types of changes whenever an alias or mbufset composition change
+** occurs.  We could try to optimize the change reporting and only
+** report an attribute change if we know that the attribute has definitely
+** changed since the last lock.  But this requires a lot of comparison
+** between the current and previous lock subjects and the decision
+** tree gets quite large.  This method of "over reporting" may result 
+** in some redundant change reports.  If we want to do this type of optimization
+** in the future, we still can.  But for now we keep it simple.
+**
+** These are the window changes that are automatically reported whenever
+** an alias or mbufset composition change occurs.
+**
+**	site
+**	clip
+**	curs
+**      bstore
+*/
+
+
+/*
+** ENTRY ROUTINE FOR WINDOW UPDATE PHASE 
+*/
+
+int
+dgai_win_update (_Dga_window dgawin, short bufIndex)
+{
+    DgaLastSeqs	lastSeqs;
+
+    /*
+    ** 1. The first thing we do in the update phase is to synchronize
+    **    the client structure.  When all pertinent client change
+    **    counters match the server, we are synchronized.  The 
+    **    reason we must do this in a loop is that some of the
+    **    synchronizations require us to temporarily unlock and 
+    **    relock.  While the drawable is unlocked, it can undergo
+    **    more changes, so we may need to start the synchronization
+    **    process over.
+    */
+
+    /* Determine sequence counts for state reported to client */
+    dgai_win_getLastSeqs(dgawin, &lastSeqs);
+
+    /* start accumulating changes */
+    dgawin->changeMask = 0;
+
+    /* repeat synchronization functions as needed through possible unlock/relocks */
+    do {
+
+	/* first, see if the window shared info is still valid */
+	if (dgai_mbsmemb_syncZombie(dgawin)) {
+	    break;
+        }
+
+	/* next, we must check the multibuffer state.
+	   This may alter the effective lock subject, whose type the
+	   other synchronization checks depend on */
+	if (lastSeqs.mbufseq != *dgawin->s_mbufseq_p) {
+	    dgai_win_mb_update(dgawin);
+	    lastSeqs.mbufseq = *dgawin->s_mbufseq_p;
+	    dgawin->c_mbufseq = lastSeqs.mbufseq;
+	}
+
+	/* synchronize with current changes to attributes of
+	   the effective lock subject -- depends on the type
+	   of the current lock subject */
+	if        (DGA_LOCKSUBJ_WINDOW(dgawin, dgawin->eLockSubj)) {
+	    dgai_win_syncChanges(dgawin, &lastSeqs);
+	} else if (DGA_LOCKSUBJ_VMBUFFER(dgawin, dgawin->eLockSubj)) {
+	    dgai_vmbuf_syncChanges(dgawin, &lastSeqs, bufIndex);
+	} else {
+	    /* should never happen */
+	    assert(0);
+	}
+
+	/* Note: whether we need to sync again depends on the type too */
+    } while (dgai_win_syncAgain(dgawin, &lastSeqs));
+
+    /* Check if the devinfo has changed */
+    dgai_mbsmemb_devinfo_update(dgawin);
+
+    /* 
+    ** 2. The foregoing synchronization step has determined whether 
+    **    any attribute changes have occurred.  We must now determine
+    **    if there are any derivative changes to report.
+    **
+    **    Currently, the only derivative changes for a window or viewable 
+    ** 	  multibuffer are those in common with all mbufset members.
+    */
+    dgai_mbsmemb_figureDerivChgs(dgawin);
+
+    /* 
+    ** 3. Next, we must report changes through notification functions,
+    **    if possible.
+    */
+
+    /* report any changes that we can through notification */
+    dgai_mbsmemb_notify(dgawin);
+
+
+    /* 
+    ** 4. Lastly, indicate that we are fully synchronized and get out.
+    */
+
+    /* the dgawin client structure is now fully synchronized with the
+       shared info */
+    dgawin->c_wm_chngcnt[bufIndex + 1] = *dgawin->s_chngcnt_p;
+
+    /*
+    ** 5. If this is an overlay window, then we need to tell the
+    **    server that we may have modified the opaque shape.
+    */
+    if (dgawin->isOverlay && dgawin->c_ovlstate != DGA_OVLSTATE_CONFLICT)
+	*dgawin->s_ovlshapevalid_p = 0;
+
+    /* if there are still any changes that were not notified through notification
+       functions, DGA_DRAW_MODIF will return nonzero (the client is
+       supposed to call this routine immediately following the lock).
+       This will cause a well-behaved client to synchronize with 
+       the remaining unreported changes */
+    return (dgawin->changeMask);
+}
+
+
+static void
+dgai_win_getLastSeqs (_Dga_window dgawin, DgaLastSeqsPtr pLastSeqs)
+{
+    pLastSeqs->mbufseq = dgawin->c_mbufseq;
+    pLastSeqs->clipseq = dgawin->c_clipseq;
+    pLastSeqs->curseq = dgawin->c_curseq;
+    pLastSeqs->rtnseq = dgawin->c_rtnseq;
+}
+
+
+/*
+** Returns nonzero if we are still not synchronized 
+*/
+
+static int
+dgai_win_syncAgain (_Dga_window dgawin, DgaLastSeqsPtr pLastSeqs)
+{
+    /* if a multibuffer change happened, we're still not done */
+    if (pLastSeqs->mbufseq != *dgawin->s_mbufseq_p) {
+	return (1);
+    }
+
+    /* Note: there's no need to check cacheseq because the effective lock subject
+       of a window can only be a window or viewable multibuffer.
+       Neither of these are cached */	
+
+    if (DGA_LOCKSUBJ_WINDOW(dgawin, dgawin->eLockSubj)) {
+	if ((pLastSeqs->clipseq == *dgawin->s_clipseq_p)  &&
+	    (pLastSeqs->curseq  == *dgawin->s_curseq_p)   &&
+	    (pLastSeqs->rtnseq  == *dgawin->s_rtnseq_p)   &&
+	    (!dgawin->isOverlay
+	     || dgawin->c_ovlstate == *dgawin->s_ovlstate_p)) {
+	    return (0);
+	}
+    } else if (DGA_LOCKSUBJ_VMBUFFER(dgawin, dgawin->eLockSubj)) {
+	if ((pLastSeqs->clipseq == *dgawin->s_clipseq_p)  &&
+	    (pLastSeqs->curseq  == *dgawin->s_curseq_p)) {
+	    /* Note: viewable mbuf never has bstore to sync up to */
+	    return (0);
+	}
+    } else {
+	/* should never happen */
+	assert(0);
+    }
+
+    /* we're not synchronized; need to go around the loop again */
+    return (1);
+}
+
+
+/* 
+** Called at window lock time when we have detected an mbufset change.
+** At the return of this routine, dgawin->eLockSubj indicates the member
+** drawable for which subsequent changes are to be detected.
+*/
+
+static void
+dgai_win_mb_update (_Dga_window dgawin)
+{
+    /* react to enable and composition changes */
+    dgai_mbsmemb_syncMbufset(dgawin);
+
+    /* if window is multibuffered we may need synchronization */
+    if (dgawin->pMbs) {
+
+	/* synchronize with any display buffer change */
+	dgai_mbwin_syncLockSubj(dgawin);
+
+	/* synchronize render buffer state (if necessary) */
+	dgai_mbsmemb_syncRendBuf(dgawin);
+    }
+
+    /* an mbufset change causes us to report changes to all attrs  */
+    { u_int reportChanges;
+      if (DGA_LOCKSUBJ_WINDOW(dgawin, dgawin->eLockSubj)) {
+	  reportChanges = DGA_WIN_CHANGEABLE_ATTRS;
+      } else if (DGA_LOCKSUBJ_VMBUFFER(dgawin, dgawin->eLockSubj)) {
+	  reportChanges = DGA_VMBUF_CHANGEABLE_ATTRS;
+      } else {
+	  /* should never happen */
+	  assert(0);
+      }
+      dgawin->changeMask |= (DGA_CHANGE_MBUFSET | reportChanges);
+    }
+}
+
+/*
+** Determine effective lock subject for a multibuffered window.
+*/
+
+static void
+dgai_mbwin_syncLockSubj (_Dga_window dgawin)
+{
+    WXINFO		*infop;
+	
+    infop = (WXINFO *) dgawin->w_info;
+
+    /* see if there is window aliasing.  Window aliasing
+       can only happen in video flip mode */
+    if (infop->w_mbsInfo.flipMode == DGA_MBFLIP_VIDEO) {
+	
+	/* when the window is aliased, the effective lock subject is the 
+	   currently displayed buffer */
+	dgawin->eLockSubj = infop->wx_dbuf.display_buffer;
+
+	if (dgawin->eLockSubj != dgawin->eLockSubjPrev) {
+
+	    /* an alias change causes us to report changes on all attributes */
+	    dgawin->changeMask |= (DGA_CHANGE_ALIAS | DGA_WIN_CHANGEABLE_ATTRS);
+
+	}
+    }
+}
+
+
+/*
+** Current lock subject is a window. Synchronize with changes.
+*/
+
+void
+dgai_win_syncChanges (_Dga_window dgawin, DgaLastSeqsPtr pLastSeqs)
+{
+    /* clip state has changed? */
+    if (pLastSeqs->clipseq != *dgawin->s_clipseq_p) {
+	dgawin->changeMask |= DGA_CHANGE_CLIP;
+	dgai_win_clip_update(dgawin);
+	pLastSeqs->clipseq = *dgawin->s_clipseq_p;
+    }
+
+    /* cursor state has changed? */
+    if (pLastSeqs->curseq != *dgawin->s_curseq_p) {
+	dgawin->changeMask |= DGA_CHANGE_CURSOR;
+	dgai_win_curs_update(dgawin);
+	pLastSeqs->curseq = *dgawin->s_curseq_p;
+    }
+
+    /* backing store state has changed? */
+    if ((pLastSeqs->rtnseq != *dgawin->s_rtnseq_p) ||
+	((dgawin->rtn_flags & RTN_GRABBED) &&
+	 !(dgawin->rtn_flags & RTN_MAPPED))) {
+	dgawin->changeMask |= DGA_CHANGE_BSTORE;
+	dgai_win_rtn_update(dgawin);
+	pLastSeqs->rtnseq = *dgawin->s_rtnseq_p;
+    }
+
+    if (dgawin->isOverlay && dgawin->c_ovlstate != *dgawin->s_ovlstate_p) {
+	dgawin->changeMask |= DGA_CHANGE_OVLSTATE;
+	dgawin->c_ovlstate = *dgawin->s_ovlstate_p;
+    }
+}
+
+
+
+
--- a/packages/SUNWxwinc/prototype_com	Wed Nov 11 05:30:06 2009 -0800
+++ b/packages/SUNWxwinc/prototype_com	Fri Nov 13 13:30:43 2009 -0800
@@ -28,7 +28,7 @@
 # of the copyright holder.
 # 
 #
-# ident	"@(#)prototype_com	35.105	09/11/09 SMI"
+# ident	"@(#)prototype_com	35.106	09/11/09 SMI"
 #
 #  X Window System include files
 
@@ -51,12 +51,6 @@
 d none openwin/share/include/X11 0755 root bin
 s none openwin/share/include/Xau=./X11
 
-d none openwin/share/include/dga 0755 root bin
-!search                $HOME/openwin/include/dga
-f none openwin/share/include/dga/dga.h 0644 root bin
-f none openwin/share/include/dga/dga_externaldefs.h 0644 root bin
-f none openwin/share/include/dga/XineramaInfo.h 0644 root bin
-
 d none X11 				0755 root bin
 d none X11/include			0755 root bin
 d none X11/include/X11			0755 root bin
--- a/packages/SUNWxwplt/prototype_com	Wed Nov 11 05:30:06 2009 -0800
+++ b/packages/SUNWxwplt/prototype_com	Fri Nov 13 13:30:43 2009 -0800
@@ -27,7 +27,7 @@
 # or other dealings in this Software without prior written authorization
 # of the copyright holder.
 # 
-# ident	"@(#)prototype_com	35.223	09/11/09 SMI"
+# ident	"@(#)prototype_com	35.224	09/11/09 SMI"
 #
 # X Window System required core package
 
@@ -54,6 +54,7 @@
 
 d none openwin 			0755 root bin
 d none openwin/bin 		0755 root bin
+d none openwin/lib 		0755 root bin
 
 #### applications replaced with new versions from open-src/app
 
@@ -258,8 +259,6 @@
 f none X11/bin/xwud 			0755 root bin
 s none openwin/bin/xwud=../../X11/bin/xwud
 
-d none openwin/lib 			0755 root bin
-
 # open-src/app/xrx
 f none X11/bin/xrx			0755 root bin
 s none openwin/bin/xrx=../../X11/bin/xrx
@@ -268,11 +267,6 @@
 f none X11/bin/winsysck 		0755 root bin
 s none openwin/bin/winsysck=../../X11/bin/winsysck
 
-!search  $HOME/openwin/lib
-
-s none openwin/lib/libdga.so=./libdga.so.1
-f none openwin/lib/libdga.so.1		 	0755 root bin
-
 #### libraries replaced with new versions from open-src/lib
 
 ## 32-bit versions
@@ -294,6 +288,11 @@
 f none X11/lib/libdpstk.so.5		0555 root bin
 f none X11/lib/libpsres.so.5		0555 root bin
 
+# open-src/lib/libdga (runtime only - no compile links,
+# needed for binary compatibility for old Java runtimes)
+s none openwin/lib/libdga.so.1=../../X11/lib/libdga.so.1
+f none X11/lib/libdga.so.1	 	0555 root bin
+
 # open-src/lib/libX11
 # The libX11.so.5 -> libX11.so.4 symlink is required by SVID3 ABI.
 s none lib/libX11.so=./libX11.so.4
--- a/packages/SUNWxwplt/prototype_sparc	Wed Nov 11 05:30:06 2009 -0800
+++ b/packages/SUNWxwplt/prototype_sparc	Fri Nov 13 13:30:43 2009 -0800
@@ -27,17 +27,18 @@
 # or other dealings in this Software without prior written authorization
 # of the copyright holder.
 #
-# ident	"@(#)prototype_sparc	1.53	09/11/09 SMI"
+# ident	"@(#)prototype_sparc	1.55	09/11/13 SMI"
 #
 #
 # Include ISA independent files (prototype_com)
 #
 !include prototype_com
 
-!HOME=../openwin
-
-#   X Window System 64-bit library software
+#   X Window System SPARC-specific 64-bit library software
 
-!search  $HOME/lib/sparcv9
-s none openwin/lib/sparcv9/libdga.so=./libdga.so.1
-f none openwin/lib/sparcv9/libdga.so.1 		0755 root bin
+!search  $HOME/X11/lib/sparcv9
+# open-src/lib/libdga (runtime only - no compile links,
+# needed for binary compatibility for old Java runtimes,
+# sparc only since Xsun/DGA was already obsolete before amd64)
+s none openwin/lib/sparcv9/libdga.so.1=../../../X11/lib/sparcv9/libdga.so.1
+f none X11/lib/sparcv9/libdga.so.1	 	0555 root bin