/************************************************************
Copyright 1989 by The Massachusetts Institute of Technology

Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
no- tice appear in all copies and that both that copyright
no- tice and this permission notice appear in supporting
docu- mentation, and that the name of MIT not be used in
advertising or publicity pertaining to distribution of the
software without specific prior written permission.
M.I.T. makes no representation about the suitability of
this software for any purpose. It is provided "as is"
without any express or implied warranty.

********************************************************/

/* EXPERIMENTAL! THIS HAS NO OFFICIAL X CONSORTIUM BLESSING */

/* $XConsortium: XShm.h,v 1.4 89/08/31 12:58:22 rws Exp $ */

#ifndef _XSHM_H_
#define _XSHM_H_

#ifndef _XSHM_SERVER_
#ifndef _XLIB_H_
#include "../Xlib.h"
#endif
#endif

#define X_ShmQueryVersion		0
#define X_ShmAttach			1
#define X_ShmDetach			2
#define X_ShmPutImage			3
#define X_ShmGetImage			4
#define X_ShmCreatePixmap		5

#define ShmCompletion			0
#define ShmNumberEvents			(ShmCompletion + 1)

#define BadShmSeg			0
#define ShmNumberErrors			(BadShmSeg + 1)

typedef unsigned long ShmSeg;

#ifndef _XSHM_SERVER_
typedef struct {
    int	type;		    /* of event */
    unsigned long serial;   /* # of last request processed by server */
    Bool send_event;	    /* true if this came frome a SendEvent request */
    Display *display;	    /* Display the event was read from */
    Drawable drawable;	    /* drawable of request */
    int major_code;	    /* ShmReqCode */
    int minor_code;	    /* X_ShmPutImage */
    ShmSeg shmseg;	    /* the ShmSeg used in the request */
    unsigned long offset;   /* the offset into ShmSeg used in the request */
} XShmCompletionEvent;

typedef struct {
    ShmSeg shmseg;	/* resource id */
    int shmid;		/* kernel id */
    char *shmaddr;	/* address in client */
    Bool readOnly;	/* how the server should attach it */
} XShmSegmentInfo;

/*
 * NB - the query routine does NOT fill in either the event or
 * the error base pointers!
 */
Bool XShmQueryExtension(Display *dpy, int *event_basep, int*error_basep);
int  XShmGetEventBase(Display *dpy);
Bool XShmQueryVersion(
	Display *,
	int *majorVersion_return,
	int *minorVersion_return,
	Bool *sharedPixmaps		/* Whether client can allocated shared pixmaps */
);

/*
 * Managing shared memory segments.
 */
Status XShmAttach(Display *dpy, XShmSegmentInfo *shminfo);
Status XShmDetach(Display *dpy, XShmSegmentInfo *shminfo);

/*
 * Doing real work.
 */
XImage *XShmCreateImage(	/* In given shared memory */
	Display		*display,
	Visual		*visual,
	unsigned int	depth,
	int		format,
	char		*data,	/* Somewhere in the shared memory! */
	XShmSegmentInfo	*shminfo,
	unsigned int	width,
	unsigned int	height
);
Status XShmPutImage(		/* From shared memory to drawable */
	Display		*display,
	Drawable	drawbable,
	GC		gc,
	XImage		*image,
	int		src_x,
	int		src_y,
	int		dst_x,
	int		dst_y,
	unsigned int	src_width,
	unsigned int	src_height,
	Bool		send_event
);
Status XShmGetImage(		/* From drawable to shared memory */
	Display		*display,
	Drawable	drawable,
	XImage		*image,
	int		x,
	int		y,
	unsigned long	plane_mask
);

Pixmap XShmCreatePixmap(	/* Only if sharedPixmaps */
	Display		*display,
	Drawable	drawable,
	char		*data,
	XShmSegmentInfo	*shminfo,
	unsigned int	width,
	unsigned int	height,
	unsigned int	depth
);

#endif

#endif
