943N/A/* Copyright (c) 1993, 2001, Oracle and/or its affiliates. All rights reserved.
830N/A *
830N/A * Permission is hereby granted, free of charge, to any person obtaining a
919N/A * copy of this software and associated documentation files (the "Software"),
919N/A * to deal in the Software without restriction, including without limitation
919N/A * the rights to use, copy, modify, merge, publish, distribute, sublicense,
919N/A * and/or sell copies of the Software, and to permit persons to whom the
919N/A * Software is furnished to do so, subject to the following conditions:
830N/A *
919N/A * The above copyright notice and this permission notice (including the next
919N/A * paragraph) shall be included in all copies or substantial portions of the
919N/A * Software.
830N/A *
919N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
919N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
919N/A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
919N/A * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
919N/A * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
919N/A * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
919N/A * DEALINGS IN THE SOFTWARE.
830N/A */
830N/A
830N/A
830N/A/*
830N/A * dga_Xrequests.c - the client side code for DGA X11 requests
830N/A */
830N/A
830N/A/*
830N/A *-----------------------------------------------------------------------
830N/A *
830N/A * This code uses the standard extension mechanism for sending
830N/A * SUN_DGA private extension requests.
830N/A *
830N/A *-----------------------------------------------------------------------
830N/A */
830N/A
830N/A#define NEED_REPLIES
830N/A#define NEED_EVENTS
830N/A
830N/A#ifdef SERVER_DGA
830N/A#include <X11/X.h>
830N/A#include <X11/Xmd.h>
830N/A#include "resource.h"
830N/A#include "dixstruct.h"
830N/A#include <stdio.h>
830N/A#include "pixmapstr.h"
830N/A#else
830N/A
830N/A#include <X11/Xlibint.h>
830N/A#include <sys/resource.h>
830N/A#include <sys/types.h>
830N/A#include <sys/socket.h>
830N/A#include <netinet/in.h>
830N/A#include <sys/un.h>
830N/A#include <netdb.h>
830N/A
830N/A#ifdef SVR4
830N/A#include <sys/utsname.h>
830N/A#endif
830N/A#endif /* SERVER_DGA */
830N/A
830N/A
830N/A#include "dga.h"
830N/A#include "dga_Xrequests.h"
830N/A#include "dga_incls.h"
830N/A
830N/A#include "XineramaInfo.h"
830N/A
830N/A#ifdef SERVER_DGA
830N/A#define NEW 1 /* Flag for SHAPES to use new window grabber */
830N/A#define BadCookie 0
830N/A#endif
830N/A
830N/A#define X_DGA 0 /* a hack, so GetReq and GetResReq work below */
830N/A
830N/A#ifndef MIN
830N/A#define MIN(i,j) ((i)<(j)?(i):(j))
830N/A#endif
830N/A
830N/Astatic struct dga_extinfo **dga_extinfo_table = 0; /* No table to start with */
830N/Astatic int dga_extinfo_table_size = 0;
830N/A
830N/Astatic int terminate_dga_ext();
830N/Astatic int islocalhost();
830N/Astatic int dga_winlist_add();
830N/Astatic int dga_winlist_free();
830N/A void * _dga_is_X_window();
830N/A int dga_pixlist_add();
830N/Astatic int dga_pixlist_free();
830N/A void *_dga_is_X_pixmap();
830N/A
830N/Aextern void dgai_win_ungrab_common();
830N/Aextern int _thr_main();
830N/A
830N/A#ifdef SVR4
830N/A
830N/A#ifdef MT
830N/Amutex_t dgaGlobalMutex;
830N/Amutex_t dgaGlobalPixmapMutex;
830N/Aint dgaThreaded; /* 1 == linked with libthread, else 0 */
830N/Aint dgaMTOn; /* 1 == MT per-drawable locking is turned on, else 0 */
830N/A#endif
830N/Aint _dga_client_version = -1;
830N/A
830N/Avoid
830N/Adga_init_version(ver)
830N/Aint ver;
830N/A{
830N/Aif (ver > -1)
830N/A _dga_client_version = ver;
830N/A#ifdef MT
830N/AdgaThreaded = (_thr_main() != -1) ? 1 : 0;
830N/A dgaMTOn = 0;
830N/A mutex_init(&dgaGlobalMutex, USYNC_THREAD, NULL);
830N/A mutex_init(&dgaGlobalPixmapMutex, USYNC_THREAD, NULL);
830N/A#endif
830N/A}
830N/A
830N/A#endif
830N/A
830N/A#ifndef SERVER_DGA
830N/Astatic struct dga_extinfo *
830N/Ainit_dga_ext(dpy)
830N/ADisplay *dpy;
830N/A{
830N/A int protmajor, protminor;
830N/A XExtCodes *xecp;
830N/A struct dga_extinfo *infop;
830N/A
830N/A#ifdef SVR4
830N/A if (_dga_client_version < 0)
830N/A return 0;
830N/A#endif
830N/A if (dga_extinfo_table_size < (dpy->fd + 1)) {
830N/A
830N/A /* We've got to allocate or grow the table */
830N/A struct rlimit rl;
830N/A int size;
830N/A struct dga_extinfo **tblptr;
830N/A
830N/A size = (getrlimit(RLIMIT_NOFILE, &rl) < 0) ?
830N/A dga_extinfo_table_size : rl.rlim_cur;
830N/A if (size < (dpy->fd + 1))
830N/A return 0;
830N/A tblptr = (struct dga_extinfo **) ((dga_extinfo_table_size) ?
830N/A realloc(dga_extinfo_table, sizeof(struct dga_extinfo *) *
830N/A size) :
830N/A malloc(sizeof(struct dga_extinfo *) * size));
830N/A if (tblptr == NULL)
830N/A return 0;
830N/A dga_extinfo_table = tblptr;
830N/A memset((char *) &dga_extinfo_table[dga_extinfo_table_size],
830N/A (int)'\0',
830N/A sizeof(struct dga_extinfo *) *
830N/A (size - dga_extinfo_table_size));
830N/A dga_extinfo_table_size = size;
830N/A }
830N/A
830N/A if (dga_extinfo_table[dpy->fd] != NULL)
830N/A return dga_extinfo_table[dpy->fd];
830N/A
830N/A if (!islocalhost(dpy))
830N/A return 0;
830N/A
830N/A if ((xecp = XInitExtension(dpy, "SUN_DGA")) != NULL) {
830N/A if (XDgaQueryVersion(dpy, &protmajor, &protminor) == 0) {
830N/A protmajor = 3;
830N/A/* protminor = 0; let minor number pass through */
830N/A }
830N/A }
830N/A else if ((xecp = XInitExtension(dpy, "SunWindowGrabber")) != NULL) {
830N/A if (strcmp(ServerVendor(dpy),
830N/A "X11/NeWS - Sun Microsystems Inc.") == 0) {
830N/A if (VendorRelease(dpy) >= 3000) {
830N/A protmajor = 2;
830N/A protminor = 0;
830N/A }
830N/A else if (VendorRelease(dpy) >= 2000) {
830N/A protmajor = 1;
830N/A protminor = 0;
830N/A }
830N/A }
830N/A else
830N/A return 0;
830N/A }
830N/A else
830N/A return 0;
830N/A
830N/A if ((infop = (struct dga_extinfo *)
830N/A malloc(sizeof(struct dga_extinfo))) == NULL)
830N/A return 0;
830N/A
830N/A infop->protocol_major_version = protmajor;
830N/A infop->protocol_minor_version = protminor;
830N/A infop->extension = xecp->extension;
830N/A infop->major_opcode = xecp->major_opcode;
830N/A dga_extinfo_table[dpy->fd] = infop;
830N/A XESetCloseDisplay(dpy, infop->extension, terminate_dga_ext);
830N/A return infop;
830N/A}
830N/A
830N/Astatic int
830N/Aislocalhost(dpy)
830N/ADisplay *dpy;
830N/A{
830N/A char hostname[256];
830N/A char *colon;
830N/A unsigned int namelen;
830N/A size_t hostlen, phostlen;
830N/A#ifdef IPv6
830N/A struct addrinfo *localhostaddr;
830N/A struct addrinfo *otherhostaddr;
830N/A struct addrinfo *i, *j;
830N/A int equiv = 0;
830N/A char host[NI_MAXHOST];
830N/A#else
830N/A struct hostent *phost;
830N/A struct hostent *h;
830N/A#endif
830N/A union genericaddr {
830N/A struct sockaddr generic;
830N/A struct sockaddr_in internet;
830N/A#ifdef IPv6
830N/A struct sockaddr_in6 internetv6;
830N/A struct sockaddr_storage maximumsize;
830N/A#endif
830N/A struct sockaddr_un nuxi;
830N/A } addr;
830N/A
830N/A if (dpy->display_name[0] == ':')
830N/A return 1;
830N/A#ifdef SVR4
830N/A colon = strrchr(dpy->display_name, ':');
830N/A#else
830N/A colon = rindex(dpy->display_name, ':');
830N/A#endif
830N/A phostlen = strlen(dpy->display_name) - (colon ? strlen(colon) : 0);
830N/A if((strncmp("unix", dpy->display_name, MIN(phostlen, 4)) == 0) ||
830N/A (strncmp("localhost", dpy->display_name, MIN(phostlen, 9)) == 0))
830N/A return 1;
830N/A
830N/A /* We're not a unix domain connection so what are we? */
830N/A
830N/A namelen = sizeof addr;
830N/A memset((char *) &addr, (int)'\0', sizeof addr);
830N/A if(getpeername(dpy->fd, (struct sockaddr *) &addr,
830N/A &namelen) < 0)
830N/A return 0;
830N/A
1029N/A hostlen = _XGetHostname(hostname, sizeof(hostname));
830N/A
830N/A#ifdef IPv6
830N/A if (getaddrinfo(hostname, NULL, NULL, &localhostaddr) != 0)
830N/A return 0;
830N/A if (getnameinfo(&addr.generic, namelen, host, sizeof(host),
830N/A NULL, 0, 0) != 0) {
830N/A freeaddrinfo(localhostaddr);
830N/A return 0;
830N/A }
830N/A if (getaddrinfo(host, NULL, NULL, &otherhostaddr) != 0) {
830N/A freeaddrinfo(localhostaddr);
830N/A return 0;
830N/A }
830N/A
830N/A for (i = localhostaddr; i != NULL && equiv == 0; i = i->ai_next) {
830N/A for (j = otherhostaddr; j != NULL && equiv == 0; j = j->ai_next) {
830N/A if (i->ai_family == j->ai_family) {
830N/A if (i->ai_family == AF_INET) {
830N/A struct sockaddr_in *sinA
830N/A = (struct sockaddr_in *) i->ai_addr;
830N/A struct sockaddr_in *sinB
830N/A = (struct sockaddr_in *) j->ai_addr;
830N/A struct in_addr *A = &sinA->sin_addr;
830N/A struct in_addr *B = &sinB->sin_addr;
830N/A
830N/A if (memcmp(A,B,sizeof(struct in_addr)) == 0) {
830N/A equiv = 1;
830N/A }
830N/A } else if (i->ai_family == AF_INET6) {
830N/A struct sockaddr_in6 *sinA
830N/A = (struct sockaddr_in6 *) i->ai_addr;
830N/A struct sockaddr_in6 *sinB
830N/A = (struct sockaddr_in6 *) j->ai_addr;
830N/A struct in6_addr *A = &sinA->sin6_addr;
830N/A struct in6_addr *B = &sinB->sin6_addr;
830N/A
830N/A if (memcmp(A,B,sizeof(struct in6_addr)) == 0) {
830N/A equiv = 1;
830N/A }
830N/A }
830N/A }
830N/A }
830N/A }
830N/A
830N/A freeaddrinfo(localhostaddr);
830N/A freeaddrinfo(otherhostaddr);
830N/A return equiv;
830N/A#else
830N/A if ((addr.generic.sa_family != AF_INET) ||
830N/A ((h = gethostbyaddr((char *)&addr.internet.sin_addr,
830N/A sizeof addr.internet.sin_addr,
830N/A addr.internet.sin_family)) == 0))
830N/A return 0;
830N/A
830N/A /* Find real host name on TCPIP */
830N/A phost = gethostbyname(h->h_name);
830N/A phostlen = strlen(phost->h_name);
830N/A
830N/A if (strncmp(hostname, phost->h_name, MIN(phostlen, hostlen)))
830N/A return 0;
830N/A
830N/A return 1;
830N/A#endif
830N/A
830N/A}
830N/A
830N/Astatic struct dga_extinfo *
830N/Alookup_dga_ext(dpy)
830N/ADisplay *dpy;
830N/A{
830N/A if (dga_extinfo_table_size < (dpy->fd + 1))
830N/A return 0;
830N/A return dga_extinfo_table[dpy->fd];
830N/A}
830N/A
830N/Astatic int
830N/Aterminate_dga_ext(dpy, codes)
830N/ADisplay *dpy;
830N/AXExtCodes *codes;
830N/A{
830N/A free(dga_extinfo_table[dpy->fd]);
830N/A dga_extinfo_table[dpy->fd] = NULL;
830N/A dga_winlist_free(dpy, NULL);
830N/A /* TODO: free pixmaps as well? */
830N/A return(1);
830N/A}
830N/A#endif /* SERVER_DGA */
830N/A
830N/ADga_token
830N/AXDgaGrabWindow(dpy, win)
830N/ADisplay *dpy;
830N/AWindow win;
830N/A{
830N/A#ifdef SERVER_DGA
830N/A int val;
830N/A WindowPtr pWin = (WindowPtr)LookupIDByType(win, RT_WINDOW);
830N/A if (!pWin)
830N/A return (BadCookie);
830N/A
830N/A if (((DrawablePtr)pWin)->type == DRAWABLE_PIXMAP)
830N/A return (BadCookie);
830N/A val = DgaWgGrab(pWin, NEW);
830N/A
830N/A if (val) {
830N/A if (dga_winlist_add(val, dpy, win) == 0) {
830N/A XDgaUnGrabWindow(dpy, win);
830N/A return 0;
830N/A }
830N/A }
830N/A return val;
830N/A#else
830N/A xResourceReq *req;
830N/A xGenericReply rep;
830N/A struct dga_extinfo *extinfop;
830N/A
830N/A if ((extinfop = init_dga_ext(dpy)) == NULL)
830N/A return 0;
830N/A LockDisplay(dpy);
830N/A GetResReq(DGA, win, req);
830N/A req->reqType = extinfop->major_opcode;
830N/A req->pad = (extinfop->protocol_major_version >= 2) ?
830N/A X_DgaGrabWindow : X_DgaGrabWindow_Old ;
830N/A if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) {
830N/A UnlockDisplay(dpy);
830N/A SyncHandle();
830N/A return 0;
830N/A }
830N/A UnlockDisplay(dpy);
830N/A SyncHandle();
830N/A if (rep.data00) {
830N/A if (dga_winlist_add(rep.data00, dpy, win) == 0) {
830N/A XDgaUnGrabWindow(dpy, win);
830N/A return 0;
830N/A }
830N/A }
830N/A return rep.data00;
830N/A#endif /* SERVER_DGA */
830N/A}
830N/A
830N/Aint
830N/AXDgaUnGrabWindow(dpy, win)
830N/ADisplay *dpy;
830N/AWindow win;
830N/A{
830N/A#ifdef SERVER_DGA
830N/A WindowPtr pWin = (WindowPtr)LookupIDByType(win, RT_WINDOW);
830N/A int val;
830N/A
830N/A if (!pWin)
830N/A return (BadCookie);
830N/A if (((DrawablePtr)pWin)->type == DRAWABLE_PIXMAP)
830N/A return (BadCookie);
830N/A val = DgaWgUngrab(pWin, NEW);
830N/A
830N/A if (val) {
830N/A if (dga_winlist_free(dpy, win) == 0)
830N/A return 0;
830N/A }
830N/A return val;
830N/A#else
830N/A xResourceReq *req;
830N/A xGenericReply rep;
830N/A struct dga_extinfo *extinfop;
830N/A
830N/A if ((extinfop = lookup_dga_ext(dpy)) == NULL)
830N/A return 0;
830N/A LockDisplay(dpy);
830N/A GetResReq(DGA, win, req);
830N/A req->reqType = extinfop->major_opcode;
830N/A req->pad = (extinfop->protocol_major_version >= 2) ?
830N/A X_DgaUnGrabWindow : X_DgaUnGrabWindow_Old;
830N/A if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) {
830N/A UnlockDisplay(dpy);
830N/A SyncHandle();
830N/A return 0;
830N/A }
830N/A UnlockDisplay(dpy);
830N/A SyncHandle();
830N/A if (rep.data00) {
830N/A if (dga_winlist_free(dpy, win) == 0)
830N/A return 0;
830N/A }
830N/A return rep.data00; /* Status */
830N/A#endif /* SERVER_DGA */
830N/A}
830N/A
830N/A
830N/A#ifndef SERVER_DGA
830N/ADga_token
830N/AXDgaGrabColormap(dpy, cmap)
830N/ADisplay *dpy;
830N/AColormap cmap;
830N/A{
830N/A xResourceReq *req;
830N/A xGenericReply rep;
830N/A struct dga_extinfo *extinfop;
830N/A
830N/A#ifdef MT
830N/A mutex_lock(&dgaGlobalMutex);
830N/A#endif
830N/A if ((extinfop = init_dga_ext(dpy)) == NULL) {
830N/A#ifdef MT
830N/A mutex_unlock(&dgaGlobalMutex);
830N/A#endif
830N/A return 0;
830N/A }
830N/A LockDisplay(dpy);
830N/A GetResReq(DGA, cmap, req);
830N/A req->reqType = extinfop->major_opcode;
830N/A req->pad = (extinfop->protocol_major_version >= 3) ?
830N/A X_DgaGrabColormap : X_DgaGrabColormap_Old;
830N/A if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) {
830N/A UnlockDisplay(dpy);
830N/A SyncHandle();
830N/A#ifdef MT
830N/A mutex_unlock(&dgaGlobalMutex);
830N/A#endif
830N/A return 0;
830N/A }
830N/A UnlockDisplay(dpy);
830N/A SyncHandle();
830N/A#ifdef MT
830N/A mutex_unlock(&dgaGlobalMutex);
830N/A#endif
830N/A return rep.data00;
830N/A}
830N/A
830N/Aint
830N/AXDgaUnGrabColormap(dpy, cmap)
830N/ADisplay *dpy;
830N/AColormap cmap;
830N/A{
830N/A xResourceReq *req;
830N/A xGenericReply rep;
830N/A struct dga_extinfo *extinfop;
830N/A
830N/A#ifdef MT
830N/A mutex_lock(&dgaGlobalMutex);
830N/A#endif
830N/A if ((extinfop = lookup_dga_ext(dpy)) == NULL) {
830N/A#ifdef MT
830N/A mutex_unlock(&dgaGlobalMutex);
830N/A#endif
830N/A return 0;
830N/A }
830N/A LockDisplay(dpy);
830N/A GetResReq(DGA, cmap, req);
830N/A req->reqType = extinfop->major_opcode;
830N/A req->pad = (extinfop->protocol_major_version >= 3) ?
830N/A X_DgaUnGrabColormap : X_DgaUnGrabColormap_Old;
830N/A if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) {
830N/A UnlockDisplay(dpy);
830N/A SyncHandle();
830N/A#ifdef MT
830N/A mutex_unlock(&dgaGlobalMutex);
830N/A#endif
830N/A return 0;
830N/A }
830N/A UnlockDisplay(dpy);
830N/A SyncHandle();
830N/A#ifdef MT
830N/A mutex_unlock(&dgaGlobalMutex);
830N/A#endif
830N/A return rep.data00; /* Status */
830N/A}
830N/A#endif /* SERVER_DGA */
830N/A
830N/Aint
830N/AXDgaDrawGrabWids(dpy, drawid, nwids)
830N/ADisplay *dpy;
830N/ADrawable drawid;
830N/Aint nwids;
830N/A{
830N/A#ifdef SERVER_DGA
830N/A WindowPtr pWin = (WindowPtr)LookupIDByType(drawid, RT_WINDOW);
830N/A
830N/A if (!pWin)
830N/A return (BadCookie);
830N/A if (((DrawablePtr)pWin)->type == DRAWABLE_PIXMAP)
830N/A return (BadCookie);
830N/A return(DgaWidGrab(pWin, nwids));
830N/A#else
830N/A xDGAReq *req;
830N/A xGenericReply rep;
830N/A struct dga_extinfo *extinfop;
830N/A
830N/A#ifdef MT
830N/A mutex_lock(&dgaGlobalMutex);
830N/A#endif
830N/A if (((extinfop = lookup_dga_ext(dpy)) == NULL) ||
830N/A (extinfop->protocol_major_version < 2)) {
830N/A#ifdef MT
830N/A mutex_unlock(&dgaGlobalMutex);
830N/A#endif
830N/A return 0;
830N/A }
830N/A LockDisplay(dpy);
830N/A GetReq(DGA, req);
830N/A req->reqType = extinfop->major_opcode;
830N/A req->pad = X_DgaGrabWids;
830N/A req->id = drawid;
830N/A req->number_objects = nwids;
830N/A if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) {
830N/A UnlockDisplay(dpy);
830N/A SyncHandle();
830N/A#ifdef MT
830N/A mutex_unlock(&dgaGlobalMutex);
830N/A#endif
830N/A return 0;
830N/A }
830N/A UnlockDisplay(dpy);
830N/A SyncHandle();
830N/A#ifdef MT
830N/A mutex_unlock(&dgaGlobalMutex);
830N/A#endif
830N/A return rep.data00;
830N/A#endif /* SERVER_DGA */
830N/A}
830N/A
830N/Aint
830N/AXDgaGrabWids(dpy, win, nwids)
830N/ADisplay *dpy;
830N/AWindow win;
830N/Aint nwids;
830N/A{
830N/A return (XDgaDrawGrabWids(dpy, (Drawable)win, nwids));
830N/A}
830N/A
830N/Aint
830N/AXDgaDrawGrabFCS(dpy, drawid, nfcs)
830N/ADisplay *dpy;
830N/ADrawable drawid;
830N/Aint nfcs;
830N/A{
830N/A#ifdef SERVER_DGA
830N/A WindowPtr pWin = (WindowPtr)LookupIDByType(drawid, RT_WINDOW);
830N/A
830N/A if (!pWin)
830N/A return (BadCookie);
830N/A if (((DrawablePtr)pWin)->type == DRAWABLE_PIXMAP)
830N/A return (BadCookie);
830N/A /* When OWGX supports PIXMAPS, can be reomoved */
830N/A return(DgaFcsGrab(pWin, nfcs));
830N/A#else
830N/A xDGAReq *req;
830N/A xGenericReply rep;
830N/A struct dga_extinfo *extinfop;
830N/A
830N/A#ifdef MT
830N/A mutex_lock(&dgaGlobalMutex);
830N/A#endif
830N/A if (((extinfop = lookup_dga_ext(dpy)) == NULL) ||
830N/A (extinfop->protocol_major_version < 2)) {
830N/A#ifdef MT
830N/A mutex_unlock(&dgaGlobalMutex);
830N/A#endif
830N/A return 0;
830N/A }
830N/A LockDisplay(dpy);
830N/A GetReq(DGA, req);
830N/A req->reqType = extinfop->major_opcode;
830N/A req->pad = X_DgaGrabFCS;
830N/A req->id = drawid;
830N/A req->number_objects = nfcs;
830N/A if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) {
830N/A UnlockDisplay(dpy);
830N/A SyncHandle();
830N/A#ifdef MT
830N/A mutex_unlock(&dgaGlobalMutex);
830N/A#endif
830N/A return 0;
830N/A }
830N/A UnlockDisplay(dpy);
830N/A SyncHandle();
830N/A#ifdef MT
830N/A mutex_unlock(&dgaGlobalMutex);
830N/A#endif
830N/A return(rep.data00);
830N/A#endif /* SERVER_DGA */
830N/A}
830N/A
830N/Aint
830N/AXDgaGrabFCS(dpy, win, nfcs)
830N/ADisplay *dpy;
830N/AWindow win;
830N/Aint nfcs;
830N/A{
830N/A return (XDgaDrawGrabFCS(dpy, (Drawable)win, nfcs));
830N/A}
830N/A
830N/Aint
830N/AXDgaDrawGrabZbuf(dpy, drawid, nzbuftype)
830N/ADisplay *dpy;
830N/ADrawable drawid;
830N/Aint nzbuftype;
830N/A{
830N/A#ifdef SERVER_DGA
830N/A WindowPtr pWin = (WindowPtr)LookupIDByType(drawid, RT_WINDOW);
830N/A
830N/A if (!pWin)
830N/A return (BadCookie);
830N/A if (((DrawablePtr)pWin)->type == DRAWABLE_PIXMAP)
830N/A return (BadCookie);
830N/A return(DgaZbufGrab(pWin, nzbuftype));
830N/A#else
830N/A xDGAReq *req;
830N/A xGenericReply rep;
830N/A struct dga_extinfo *extinfop;
830N/A
830N/A#ifdef MT
830N/A mutex_lock(&dgaGlobalMutex);
830N/A#endif
830N/A if (((extinfop = lookup_dga_ext(dpy)) == NULL) ||
830N/A (extinfop->protocol_major_version < 2)) {
830N/A#ifdef MT
830N/A mutex_unlock(&dgaGlobalMutex);
830N/A#endif
830N/A return 0;
830N/A }
830N/A LockDisplay(dpy);
830N/A GetReq(DGA, req);
830N/A req->reqType = extinfop->major_opcode;
830N/A req->pad = X_DgaGrabZbuf;
830N/A req->id = drawid;
830N/A req->number_objects = nzbuftype;
830N/A if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) {
830N/A UnlockDisplay(dpy);
830N/A SyncHandle();
830N/A#ifdef MT
830N/A mutex_unlock(&dgaGlobalMutex);
830N/A#endif
830N/A return 0;
830N/A }
830N/A UnlockDisplay(dpy);
830N/A SyncHandle();
830N/A#ifdef MT
830N/A mutex_unlock(&dgaGlobalMutex);
830N/A#endif
830N/A return(rep.data00);
830N/A#endif /* SERVER_DGA */
830N/A}
830N/A
830N/Aint
830N/AXDgaGrabZbuf(dpy, win, nzbuftype)
830N/ADisplay *dpy;
830N/AWindow win;
830N/Aint nzbuftype;
830N/A{
830N/A return (XDgaDrawGrabZbuf(dpy, (Drawable)win, nzbuftype));
830N/A}
830N/A
830N/Aint
830N/AXDgaDrawGrabStereo(dpy, drawid, st_mode)
830N/ADisplay *dpy;
830N/ADrawable drawid;
830N/Aint st_mode;
830N/A{
830N/A#ifdef SERVER_DGA
830N/A WindowPtr pWin = (WindowPtr)LookupIDByType(drawid, RT_WINDOW);
830N/A
830N/A if (!pWin)
830N/A return (BadCookie);
830N/A if (((DrawablePtr)pWin)->type == DRAWABLE_PIXMAP)
830N/A return (BadCookie);
830N/A return(DgaStereoGrab(pWin, st_mode));
830N/A#else
830N/A xDGAReq *req;
830N/A xGenericReply rep;
830N/A struct dga_extinfo *extinfop;
830N/A
830N/A#ifdef MT
830N/A mutex_lock(&dgaGlobalMutex);
830N/A#endif
830N/A if (((extinfop = lookup_dga_ext(dpy)) == NULL) ||
830N/A (extinfop->protocol_major_version < 2)) {
830N/A#ifdef MT
830N/A mutex_unlock(&dgaGlobalMutex);
830N/A#endif
830N/A return 0;
830N/A }
830N/A LockDisplay(dpy);
830N/A GetReq(DGA, req);
830N/A req->reqType = extinfop->major_opcode;
830N/A req->pad = X_DgaGrabStereo;
830N/A req->id = drawid;
830N/A req->number_objects = st_mode;
830N/A if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) {
830N/A UnlockDisplay(dpy);
830N/A SyncHandle();
830N/A#ifdef MT
830N/A mutex_unlock(&dgaGlobalMutex);
830N/A#endif
830N/A return 0;
830N/A }
830N/A UnlockDisplay(dpy);
830N/A SyncHandle();
830N/A#ifdef MT
830N/A mutex_unlock(&dgaGlobalMutex);
830N/A#endif
830N/A return rep.data00;
830N/A#endif /* SERVER_DGA */
830N/A}
830N/A
830N/Aint
830N/AXDgaGrabStereo(dpy, win, st_mode)
830N/ADisplay *dpy;
830N/AWindow win;
830N/Aint st_mode;
830N/A{
830N/A return (XDgaDrawGrabStereo(dpy, (Drawable)win, st_mode));
830N/A}
830N/A
830N/Aint
830N/AXDgaGrabABuffers(dpy, win, type, buffer_site)
830N/ADisplay *dpy;
830N/AWindow win;
830N/Aint type;
830N/Aint buffer_site;
830N/A{
830N/A#ifdef SERVER_DGA
830N/A WindowPtr pWin = (WindowPtr)LookupIDByType(win, RT_WINDOW);
830N/A
830N/A if (!pWin)
830N/A return (BadCookie);
830N/A if (((DrawablePtr)pWin)->type == DRAWABLE_PIXMAP)
830N/A return (BadCookie);
830N/A /* Some surf prep may be needed for mpg */
830N/A return(DgaABuffersGrabInfo((DrawablePtr)pWin, type, buffer_site));
830N/A#else
830N/A xDgaGrabABuffersReq *req;
830N/A xGenericReply rep;
830N/A struct dga_extinfo *extinfop;
830N/A
830N/A if ((extinfop = lookup_dga_ext(dpy)) == NULL)
830N/A return 0;
830N/A if (extinfop->protocol_major_version < 2)
830N/A return 0;
830N/A LockDisplay(dpy);
830N/A GetReq(DgaGrabABuffers, req);
830N/A req->reqType = extinfop->major_opcode;
830N/A req->pad = X_DgaGrabABuffers;
830N/A req->id = win;
830N/A req->type = type;
830N/A req->buffer_site = buffer_site;
830N/A if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) {
830N/A UnlockDisplay(dpy);
830N/A SyncHandle();
830N/A return 0;
830N/A }
830N/A UnlockDisplay(dpy);
830N/A SyncHandle();
830N/A return rep.data00;
830N/A#endif /* SERVER_DGA */
830N/A}
830N/A
830N/Aint
830N/AXDgaUnGrabABuffers(dpy, win, type)
830N/ADisplay *dpy;
830N/AWindow win;
830N/Aint type;
830N/A{
830N/A#ifdef SERVER_DGA
830N/A WindowPtr pWin = (WindowPtr)LookupIDByType(win, RT_WINDOW);
830N/A
830N/A if (!pWin)
830N/A return (BadCookie);
830N/A if (((DrawablePtr)pWin)->type == DRAWABLE_PIXMAP)
830N/A return (BadCookie);
830N/A return(DgaABuffersUngrabInfo((DrawablePtr)pWin, type));
830N/A#else
830N/A xDgaGrabABuffersReq *req;
830N/A xGenericReply rep;
830N/A struct dga_extinfo *extinfop;
830N/A
830N/A if ((extinfop = lookup_dga_ext(dpy)) == NULL)
830N/A return 0;
830N/A if (extinfop->protocol_major_version < 2)
830N/A return 0;
830N/A LockDisplay(dpy);
830N/A GetReq(DgaGrabABuffers, req);
830N/A req->reqType = extinfop->major_opcode;
830N/A req->pad = X_DgaUnGrabABuffers;
830N/A req->id = win;
830N/A req->type = type;
830N/A req->buffer_site = 0;
830N/A if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) {
830N/A UnlockDisplay(dpy);
830N/A SyncHandle();
830N/A return 0;
830N/A }
830N/A UnlockDisplay(dpy);
830N/A SyncHandle();
830N/A return rep.data00;
830N/A#endif /* SERVER_DGA */
830N/A}
830N/A
830N/Aint
830N/AXDgaGrabBuffers(dpy, win, nbuffers)
830N/ADisplay *dpy;
830N/AWindow win;
830N/Aint nbuffers;
830N/A{
830N/A#ifdef SERVER_DGA
830N/A WindowPtr pWin = (WindowPtr)LookupIDByType(win, RT_WINDOW);
830N/A
830N/A if (!pWin)
830N/A return (BadCookie);
830N/A if (((DrawablePtr)pWin)->type == DRAWABLE_PIXMAP)
830N/A return (BadCookie);
830N/A /* Some surf prep may be needed for mpg */
830N/A return(DgaBufGrab(pWin, nbuffers));
830N/A#else
830N/A xDGAReq *req;
830N/A xGenericReply rep;
830N/A struct dga_extinfo *extinfop;
830N/A
830N/A if ((extinfop = lookup_dga_ext(dpy)) == NULL)
830N/A return 0;
830N/A if (extinfop->protocol_major_version < 2)
830N/A return 0;
830N/A LockDisplay(dpy);
830N/A GetReq(DGA, req);
830N/A req->reqType = extinfop->major_opcode;
830N/A req->pad = X_DgaGrabBuffers;
830N/A req->id = win;
830N/A req->number_objects = nbuffers;
830N/A if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) {
830N/A UnlockDisplay(dpy);
830N/A SyncHandle();
830N/A return 0;
830N/A }
830N/A UnlockDisplay(dpy);
830N/A SyncHandle();
830N/A return rep.data00;
830N/A#endif /* SERVER_DGA */
830N/A}
830N/A
830N/A
830N/Aint
830N/AXDgaUnGrabBuffers(dpy, win)
830N/ADisplay *dpy;
830N/AWindow win;
830N/A{
830N/A#ifdef SERVER_DGA
830N/A WindowPtr pWin = (WindowPtr)LookupIDByType(win, RT_WINDOW);
830N/A
830N/A if (!pWin)
830N/A return (BadCookie);
830N/A if (((DrawablePtr)pWin)->type == DRAWABLE_PIXMAP)
830N/A return (BadCookie);
830N/A return(DgaBufUngrab(pWin));
830N/A#else
830N/A xResourceReq *req;
830N/A xGenericReply rep;
830N/A struct dga_extinfo *extinfop;
830N/A
830N/A if ((extinfop = lookup_dga_ext(dpy)) == NULL)
830N/A return 0;
830N/A if (extinfop->protocol_major_version < 2)
830N/A return 0;
830N/A LockDisplay(dpy);
830N/A GetResReq(DGA, win, req);
830N/A req->reqType = extinfop->major_opcode;
830N/A req->pad = X_DgaUnGrabBuffers;
830N/A if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) {
830N/A UnlockDisplay(dpy);
830N/A SyncHandle();
830N/A return 0;
830N/A }
830N/A UnlockDisplay(dpy);
830N/A SyncHandle();
830N/A return rep.data00;
830N/A#endif /* SERVER_DGA */
830N/A}
830N/A
830N/A
830N/Aint
830N/AXDgaGrabRetainedWindow(dpy, win)
830N/ADisplay *dpy;
830N/AWindow win;
830N/A{
830N/A#ifdef SERVER_DGA
830N/A WindowPtr pWin = (WindowPtr)LookupIDByType(win, RT_WINDOW);
830N/A
830N/A if (!pWin)
830N/A return (BadCookie);
830N/A if (((DrawablePtr)pWin)->type == DRAWABLE_PIXMAP)
830N/A return (BadCookie);
830N/A return(DgaSharedRetained(pWin, 1, win));
830N/A#else
830N/A xResourceReq *req;
830N/A xGenericReply rep;
830N/A struct dga_extinfo *extinfop;
830N/A
830N/A if ((extinfop = lookup_dga_ext(dpy)) == NULL)
830N/A return 0;
830N/A if (extinfop->protocol_major_version < 3)
830N/A return 0;
830N/A LockDisplay(dpy);
830N/A GetResReq(DGA, win, req);
830N/A req->reqType = extinfop->major_opcode;
830N/A req->pad = X_DgaGrabRetained;
830N/A if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) {
830N/A UnlockDisplay(dpy);
830N/A SyncHandle();
830N/A return 0;
830N/A }
830N/A UnlockDisplay(dpy);
830N/A SyncHandle();
830N/A return rep.data00;
830N/A#endif /* SERVER_DGA */
830N/A}
830N/A
830N/A
830N/Aint
830N/AXDgaUnGrabRetainedWindow(dpy, win)
830N/ADisplay *dpy;
830N/AWindow win;
830N/A{
830N/A#ifdef SERVER_DGA
830N/A WindowPtr pWin = (WindowPtr)LookupIDByType(win, RT_WINDOW);
830N/A
830N/A if (!pWin)
830N/A return (BadCookie);
830N/A if (((DrawablePtr)pWin)->type == DRAWABLE_PIXMAP)
830N/A return (BadCookie);
830N/A return(DgaSharedRetained(pWin, 0, win));
830N/A#else
830N/A xResourceReq *req;
830N/A xGenericReply rep;
830N/A struct dga_extinfo *extinfop;
830N/A
830N/A if ((extinfop = lookup_dga_ext(dpy)) == NULL)
830N/A return 0;
830N/A if (extinfop->protocol_major_version < 3)
830N/A return 0;
830N/A LockDisplay(dpy);
830N/A GetResReq(DGA, win, req);
830N/A req->reqType = extinfop->major_opcode;
830N/A req->pad = X_DgaUnGrabRetained;
830N/A if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) {
830N/A UnlockDisplay(dpy);
830N/A SyncHandle();
830N/A return 0;
830N/A }
830N/A UnlockDisplay(dpy);
830N/A SyncHandle();
830N/A return rep.data00; /* Status */
830N/A#endif /* SERVER_DGA */
830N/A}
830N/A
830N/A
830N/Aint
830N/AXDgaGetRetainedPath(dpy, win, path)
830N/ADisplay *dpy;
830N/AWindow win;
830N/Achar *path;
830N/A{
830N/A#ifdef SERVER_DGA
830N/A extern char *DgaSharedRetainedPath;
830N/A
830N/A if (DgaSharedRetainedPath)
830N/A strcpy((char *)path, (char *)DgaSharedRetainedPath);
830N/A return 1;
830N/A#else
830N/A xResourceReq *req;
830N/A xDGARtndPathReply rep;
830N/A struct dga_extinfo *extinfop;
830N/A
830N/A if ((extinfop = lookup_dga_ext(dpy)) == NULL)
830N/A return 0;
830N/A if (extinfop->protocol_major_version < 3)
830N/A return 0;
830N/A LockDisplay(dpy);
830N/A GetResReq(DGA, win, req);
830N/A req->reqType = extinfop->major_opcode;
830N/A req->pad = X_DgaGetRetainedPath;
830N/A if (!_XReply(dpy, (xReply *) &rep,
830N/A (SIZEOF(xDGARtndPathReply) - SIZEOF(xReply)) >> 2, xFalse)) {
830N/A UnlockDisplay(dpy);
830N/A SyncHandle();
830N/A return 0;
830N/A }
830N/A UnlockDisplay(dpy);
830N/A SyncHandle();
830N/A strcpy(path, (char *) rep.path);
830N/A return 1;
830N/A#endif /* SERVER_DGA */
830N/A}
830N/A
830N/A
830N/Aint
830N/AXDgaQueryVersion(dpy, major_versionp, minor_versionp)
830N/ADisplay *dpy;
830N/Aint *major_versionp,
830N/A *minor_versionp;
830N/A{
830N/A#ifdef SERVER_DGA
830N/A *major_versionp = SUN_DGA_MAJOR_VERSION;
830N/A *minor_versionp = SUN_DGA_MINOR_VERSION;
830N/A return(1);
830N/A#else
830N/A xDgaQueryVersionReply rep;
830N/A xDgaQueryVersionReq *req;
830N/A int opcode, tmp;
830N/A
830N/A if (XQueryExtension(dpy, "SUN_DGA", &opcode, &tmp, &tmp) == 0)
830N/A return 0;
830N/A
830N/A LockDisplay(dpy);
830N/A GetReq(DgaQueryVersion, req);
830N/A req->reqType = opcode;
830N/A req->dgaReqType = X_DgaQueryVersion;
830N/A if (!_XReply(dpy, (xReply *) & rep, 0, xTrue)) {
830N/A UnlockDisplay(dpy);
830N/A SyncHandle();
830N/A return 0;
830N/A }
830N/A *major_versionp = rep.majorVersion;
830N/A *minor_versionp = rep.minorVersion;
830N/A UnlockDisplay(dpy);
830N/A SyncHandle();
830N/A return 1;
830N/A#endif /* SERVER_DGA */
830N/A}
830N/A
830N/A
830N/ADga_token
830N/AXDgaGrabPixmap(dpy, d)
830N/ADisplay *dpy;
830N/APixmap d;
830N/A{
830N/A#ifdef SERVER_DGA
830N/A int val;
830N/A PixmapPtr pPix = (PixmapPtr)LookupIDByType(d, RT_PIXMAP);
830N/A if (!pPix)
830N/A return (BadCookie);
830N/A
830N/A if (((DrawablePtr)pPix)->type == DRAWABLE_WINDOW)
830N/A return (BadCookie);
830N/A val = DgaInitSharedPixmap(pPix, NEW);
830N/A
830N/A if (val) {
830N/A if (dga_pixlist_add(val, dpy, d) == 0) {
830N/A XDgaUnGrabPixmap(dpy, d);
830N/A return 0;
830N/A }
830N/A }
830N/A return val;
830N/A#else
830N/A xResourceReq *req;
830N/A xGenericReply rep;
830N/A struct dga_extinfo *extinfop;
830N/A
830N/A if ((extinfop = init_dga_ext(dpy)) == NULL)
830N/A return 0;
830N/A if (extinfop->protocol_major_version < 3)
830N/A return 0;
830N/A LockDisplay(dpy);
830N/A GetResReq(DGA, d, req);
830N/A req->reqType = extinfop->major_opcode;
830N/A req->pad = X_DgaGrabPixmap;
830N/A if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) {
830N/A UnlockDisplay(dpy);
830N/A SyncHandle();
830N/A return 0;
830N/A }
830N/A UnlockDisplay(dpy);
830N/A SyncHandle();
830N/A if (rep.data00) {
830N/A if (dga_pixlist_add(rep.data00, dpy, d) == 0) {
830N/A XDgaUnGrabPixmap(dpy, d);
830N/A return 0;
830N/A }
830N/A }
830N/A return rep.data00;
830N/A#endif /* SERVER_DGA */
830N/A}
830N/A
830N/A
830N/Aint
830N/AXDgaUnGrabPixmap(dpy, d)
830N/ADisplay *dpy;
830N/APixmap d;
830N/A{
830N/A#ifdef SERVER_DGA
830N/A PixmapPtr pPix = (PixmapPtr)LookupIDByType(d, RT_PIXMAP);
830N/A int val;
830N/A
830N/A if (!pPix)
830N/A return (BadCookie);
830N/A if (((DrawablePtr)pPix)->type == DRAWABLE_WINDOW)
830N/A return (BadCookie);
830N/A val = DgaDestroySharedPixmap(pPix);
830N/A
830N/A if (val) {
830N/A if (dga_pixlist_free(dpy, d) == 0)
830N/A return 0;
830N/A }
830N/A return val;
830N/A#else
830N/A xResourceReq *req;
830N/A xGenericReply rep;
830N/A struct dga_extinfo *extinfop;
830N/A
830N/A if ((extinfop = lookup_dga_ext(dpy)) == NULL)
830N/A return 0;
830N/A if (extinfop->protocol_major_version < 3)
830N/A return 0;
830N/A LockDisplay(dpy);
830N/A GetResReq(DGA, d, req);
830N/A req->reqType = extinfop->major_opcode;
830N/A req->pad = X_DgaUnGrabPixmap;
830N/A if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) {
830N/A UnlockDisplay(dpy);
830N/A SyncHandle();
830N/A return 0;
830N/A }
830N/A UnlockDisplay(dpy);
830N/A SyncHandle();
830N/A return rep.data00; /* Status */
830N/A#endif /* SERVER_DGA */
830N/A}
830N/A
830N/A
830N/Astatic Dga_token
830N/Adgai_grabDrawRequest (Display *dpy, Drawable drawid, int *drawType)
830N/A{
830N/A#ifdef SERVER_DGA
830N/A DrawablePtr pDraw = (DrawablePtr)LookupIDByClass(drawid, RC_DRAWABLE);
830N/A
830N/A if (!pDraw)
830N/A return(BadCookie);
830N/A return(DgaDrawGrab(drawid, pDraw, NEW, drawType));
830N/A#else
830N/A xResourceReq *req;
830N/A xGenericReply rep;
830N/A struct dga_extinfo *extinfop;
830N/A
830N/A if ((extinfop = init_dga_ext(dpy)) == NULL)
830N/A return 0;
830N/A if (extinfop->protocol_major_version < 3)
830N/A return 0;
830N/A LockDisplay(dpy);
830N/A GetResReq(DGA, drawid, req);
830N/A req->reqType = extinfop->major_opcode;
830N/A req->pad = X_DgaGrabDrawable;
830N/A if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) {
830N/A UnlockDisplay(dpy);
830N/A SyncHandle();
830N/A return 0;
830N/A }
830N/A UnlockDisplay(dpy);
830N/A SyncHandle();
830N/A
830N/A /*
830N/A ** data00 is the opaque token identifying the drawable shared file.
830N/A ** data01 is the type of the drawable: window (0) or pixmap (1),
830N/A ** (Note: an attempt to grab a multibuffer drawable XID will fail)
830N/A */
830N/A if (rep.data00) {
830N/A *drawType = rep.data01;
830N/A }
830N/A
830N/A return (rep.data00);
830N/A#endif /* SERVER_DGA */
830N/A}
830N/A
830N/Astatic int
830N/Adgai_ungrabDrawRequest (Display *dpy, Drawable drawid)
830N/A{
830N/A#ifdef SERVER_DGA
830N/A DrawablePtr pDraw = (DrawablePtr)LookupIDByClass(drawid, RC_DRAWABLE);
830N/A
830N/A if (!pDraw)
830N/A return(BadCookie);
830N/A return(DgaDrawUngrab(drawid, pDraw, NEW));
830N/A#else
830N/A xResourceReq *req;
830N/A xGenericReply rep;
830N/A struct dga_extinfo *extinfop;
830N/A
830N/A if ((extinfop = lookup_dga_ext(dpy)) == NULL)
830N/A return 0;
830N/A if (extinfop->protocol_major_version < 3)
830N/A return 0;
830N/A LockDisplay(dpy);
830N/A GetResReq(DGA, drawid, req);
830N/A req->reqType = extinfop->major_opcode;
830N/A req->pad = X_DgaUnGrabDrawable;
830N/A if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) {
830N/A UnlockDisplay(dpy);
830N/A SyncHandle();
830N/A return 0;
830N/A }
830N/A UnlockDisplay(dpy);
830N/A SyncHandle();
830N/A return rep.data00; /* Status */
830N/A#endif /* SERVER_DGA */
830N/A}
830N/A
830N/A
830N/ADga_drawable
830N/AXDgaGrabDrawable(Display *dpy, Drawable drawid)
830N/A{
830N/A Dga_token token;
830N/A int drawType;
830N/A
830N/A#ifdef MT
830N/A mutex_lock(&dgaGlobalMutex);
830N/A#endif
830N/A if (!(token = dgai_grabDrawRequest(dpy, drawid, &drawType))) {
830N/A#ifdef MT
830N/A mutex_unlock(&dgaGlobalMutex);
830N/A#endif
830N/A return (NULL);
830N/A }
830N/A
830N/A switch (drawType) {
830N/A
830N/A case DGA_PROTO_OVERLAY:
830N/A case DGA_PROTO_WINDOW: {
830N/A _Dga_window dgawin;
830N/A
830N/A if (!dga_winlist_add(token, dpy, (Window)drawid)) {
830N/A goto Bad;
830N/A }
830N/A if (!(dgawin = (_Dga_window) dgai_win_grab_common(dpy, -1, token, 1))) { goto Bad;
830N/A }
830N/A dgawin->w_dpy = dpy;
830N/A dgawin->w_id = (Window) drawid;
830N/A if (dgawin->isOverlay = (drawType == DGA_PROTO_OVERLAY)) {
830N/A dgawin->s_ovlstate_p = &((WXINFO *)dgawin->w_info)->w_ovlstate;
830N/A dgawin->s_ovlshapevalid_p =
830N/A &((WXINFO *)dgawin->w_info)->w_ovlshapevalid;
830N/A dgawin->ovlStateNotifyFunc = NULL;
830N/A }
830N/A#ifdef MT
830N/A mutex_unlock(&dgaGlobalMutex);
830N/A#endif
830N/A return ((Dga_drawable)dgawin);
830N/A }
830N/A
830N/A case DGA_PROTO_PIXMAP: {
830N/A _Dga_pixmap dgapix;
830N/A
830N/A if (!dga_pixlist_add(token, dpy, (Pixmap)drawid)) {
830N/A goto Bad;
830N/A }
830N/A if (!(dgapix = (_Dga_pixmap) dga_pix_grab(token, (Pixmap)drawid))) {
830N/A goto Bad;
830N/A }
830N/A dgapix->p_dpy = dpy;
830N/A dgapix->p_id = (Pixmap) drawid;
830N/A#ifdef MT
830N/A mutex_unlock(&dgaGlobalMutex);
830N/A#endif
830N/A return ((Dga_drawable)dgapix);
830N/A }
830N/A
830N/A }
830N/A
830N/ABad:
830N/A (void) dgai_ungrabDrawRequest(dpy, drawid);
830N/A#ifdef MT
830N/A mutex_unlock(&dgaGlobalMutex);
830N/A#endif
830N/A return (NULL);
830N/A}
830N/A
830N/A
830N/A
830N/Aint
830N/AXDgaUnGrabDrawable(Dga_drawable dgadraw)
830N/A{
830N/A Drawable drawid = dga_draw_id(dgadraw);
830N/A Display *dpy = dga_draw_display(dgadraw);
830N/A int type = dga_draw_type(dgadraw);
830N/A int status;
830N/A
830N/A#ifdef MT
830N/A mutex_lock(&dgaGlobalMutex);
830N/A#endif
830N/A switch (type) {
830N/A case DGA_DRAW_WINDOW:
830N/A case DGA_DRAW_OVERLAY:
830N/A dgai_win_ungrab_common((Dga_window)dgadraw, -1,1);
830N/A break;
830N/A case DGA_DRAW_PIXMAP:
830N/A dga_pix_ungrab((Dga_pixmap)dgadraw);
830N/A break;
830N/A }
830N/A
830N/A status = dgai_ungrabDrawRequest(dpy, drawid);
830N/A#ifdef MT
830N/A mutex_unlock(&dgaGlobalMutex);
830N/A#endif
830N/A return (status);
830N/A}
830N/A
830N/A
830N/A
830N/Astatic struct dga_xwinrec *dga_xwinlist = NULL;
830N/A
830N/Astatic int
830N/Adga_winlist_add(token, dpy, win)
830N/ADga_token token;
830N/ADisplay *dpy;
830N/AWindow win;
830N/A{
830N/A struct dga_xwinrec *recp;
830N/A Display *listdpy;
830N/A Window listwin;
830N/A
830N/A while (recp =
830N/A (struct dga_xwinrec *) _dga_is_X_window(token,&listdpy,&listwin)) {
830N/A if ((win == listwin) && (dpy == listdpy)) {
830N/A recp->refcnt += 1;
830N/A return 1; /* already in list */
830N/A }
830N/A dga_winlist_free(listdpy, listwin); /* remove bogus entry from list */
830N/A }
830N/A recp = (struct dga_xwinrec *) malloc(sizeof(struct dga_xwinrec));
830N/A if (recp == NULL)
830N/A return 0;
830N/A recp->next = dga_xwinlist;
830N/A dga_xwinlist = recp;
830N/A recp->token = token;
830N/A recp->dpy = dpy;
830N/A recp->win = win;
830N/A recp->refcnt = 1;
830N/A return 1;
830N/A}
830N/A
830N/A/*
830N/A * Free dga_xwinrec structure for a particular window and display.
830N/A * If win is NULL free all entries on list for this display.
830N/A */
830N/Astatic int
830N/Adga_winlist_free(dpy, win)
830N/ADisplay *dpy;
830N/AWindow win;
830N/A{
830N/A struct dga_xwinrec *recp, **prevp;
830N/A int match = 0;
830N/A
830N/A prevp = &dga_xwinlist;
830N/A recp = dga_xwinlist;
830N/A while (recp) {
830N/A if (recp->dpy == dpy) {
830N/A if (win == NULL) {
830N/A *prevp = recp->next;
830N/A free(recp);
830N/A match = 1;
830N/A }
830N/A else if (recp->win == win) {
830N/A if (--recp->refcnt == 0) {
830N/A *prevp = recp->next;
830N/A free(recp);
830N/A }
830N/A return 1;
830N/A }
830N/A else {
830N/A prevp = &recp->next;
830N/A }
830N/A }
830N/A else {
830N/A prevp = &recp->next;
830N/A }
830N/A recp = *prevp;
830N/A }
830N/A return (match);
830N/A}
830N/A
830N/A
830N/Avoid *
830N/A_dga_is_X_window(token, dpyp, winp)
830N/ADga_token token;
830N/ADisplay **dpyp;
830N/AWindow *winp;
830N/A{
830N/A struct dga_xwinrec *recp = dga_xwinlist;
830N/A
830N/A while (recp) {
830N/A if (recp->token == token) {
830N/A *dpyp = recp->dpy;
830N/A *winp = recp->win;
830N/A return ((void *) recp);
830N/A }
830N/A recp = recp->next;
830N/A }
830N/A return 0;
830N/A}
830N/A
830N/Astatic struct dga_xpixrec *dga_xpixlist = NULL;
830N/A
830N/A/* REMIND DARYL: This routine is used to clean up "bogus" entries from
830N/A * list. Shouldn't that be done in Ungrab??? */
830N/Aint
830N/Adga_pixlist_add(token, dpy, pix)
830N/ADga_token token;
830N/ADisplay *dpy;
830N/APixmap pix;
830N/A{
830N/A struct dga_xpixrec *recp;
830N/A Display *listdpy;
830N/A
830N/A if (recp = (struct dga_xpixrec *) _dga_is_X_pixmap(pix, &listdpy)) {
830N/A if (dpy == listdpy) {
830N/A recp->refcnt += 1;
830N/A return 1; /* already in list */
830N/A }
830N/A dga_pixlist_free(dpy, pix); /* remove bogus entry from list */
830N/A }
830N/A recp = (struct dga_xpixrec *) malloc(sizeof(struct dga_xpixrec));
830N/A if (recp == NULL)
830N/A return 0;
830N/A recp->next = dga_xpixlist;
830N/A dga_xpixlist = recp;
830N/A recp->token = token;
830N/A recp->dpy = dpy;
830N/A recp->pix = pix;
830N/A recp->refcnt = 1;
830N/A return 1;
830N/A}
830N/A
830N/Astatic int
830N/Adga_pixlist_free(dpy, pix)
830N/ADisplay *dpy;
830N/APixmap pix;
830N/A{
830N/A struct dga_xpixrec *recp, **prevp;
830N/A int match = 0;
830N/A
830N/A prevp = &dga_xpixlist;
830N/A recp = dga_xpixlist;
830N/A while (recp) {
830N/A if (recp->dpy == dpy) {
830N/A if (pix == NULL) {
830N/A *prevp = recp->next;
830N/A free(recp);
830N/A match = 1;
830N/A }
830N/A else if (recp->pix == pix) {
830N/A if (--recp->refcnt == 0) {
830N/A *prevp = recp->next;
830N/A free(recp);
830N/A }
830N/A return 1;
830N/A }
830N/A else {
830N/A prevp = &recp->next;
830N/A }
830N/A }
830N/A else {
830N/A prevp = &recp->next;
830N/A }
830N/A recp = *prevp;
830N/A }
830N/A return (match);
830N/A}
830N/A
830N/A
830N/Avoid *
830N/A_dga_is_X_pixmap(pix, dpyp)
830N/APixmap pix;
830N/ADisplay **dpyp;
830N/A{
830N/A struct dga_xpixrec *recp = dga_xpixlist;
830N/A
830N/A while (recp) {
830N/A if (recp->pix == pix) {
830N/A *dpyp = recp->dpy;
830N/A return ((void *) recp);
830N/A }
830N/A recp = recp->next;
830N/A }
830N/A return 0;
830N/A}
830N/A
830N/A#ifndef SERVER_DGA
830N/A
830N/A/************************************
830N/A
830N/AAddition to DGA for Xinerama extension.
830N/A
830N/A This code allows the client to mine out
830N/A the window ID's that would normaly be
830N/A hidden from the user in Xinerama mode.
830N/A
830N/A Xinerama keeps a list of WIDs that are
830N/A connected to a virtual WID that the user
830N/A gets to handle.
830N/A
830N/A**************************************/
830N/A
830N/A
830N/ABOOL
830N/AXDgaGetXineramaInfo(dpy , VirtualWID, info )
830N/ADisplay *dpy;
830N/AXID VirtualWID;
830N/AXineramaInfo *info;
830N/A{
830N/Aregister xDgaXineramaInfoReq *req;
830N/AxDgaXineramaInfoReply *rep;
830N/Astruct dga_extinfo *extinfop;
830N/A
830N/A if ((extinfop = init_dga_ext(dpy)) == NULL)
830N/A return 0;
830N/A
830N/A rep = malloc(sizeof(xDgaXineramaInfoReply));
830N/A
830N/A LockDisplay(dpy);
830N/A GetReq(DgaXineramaInfo, req);
830N/A req->reqType = extinfop->major_opcode;
830N/A req->xdgaReqType = X_DgaXineramaInfo;
830N/A req->visual = VirtualWID;
830N/A
830N/A if (!_XReply(dpy, (xReply *)rep, (sizeof(xDgaXineramaInfoReply)-32) >> 2,
830N/A xFalse))
830N/A {
830N/A UnlockDisplay(dpy);
830N/A SyncHandle();
830N/A Xfree(rep);
830N/A return NULL;
830N/A }
830N/A info->wid = VirtualWID;
830N/A memcpy(&info->subs[0],&rep->subs[0],(MAXSCREEN-1) * sizeof(SubWID));
830N/A UnlockDisplay(dpy);
830N/A SyncHandle();
830N/A free(rep);
830N/A return 1;
830N/A}
830N/A#endif