[xserver-commit] xserver/dri .cvsignore,NONE,1.1.2.1 Makefile.am,NONE,1.1.2.1 dri.c,NONE,1.1.2.1 dri.h,NONE,1.1.2.1 dristruct.h,NONE,1.1.2.1 sarea.h,NONE,1.1.2.1 xf86dri.c,NONE,1.1.2.1 xf86dri.h,NONE,1.1.2.1 xf86dristr.h,NONE,1.1.2.1

Eric Anholt xserver-commit@pdx.freedesktop.org
Mon, 01 Dec 2003 14:56:05 -0800


Committed by: anholt

Update of /cvs/xserver/xserver/dri
In directory pdx:/home/anholt/xserver-dri/dri

Added Files:
      Tag: dri-0-1-branch
	.cvsignore Makefile.am dri.c dri.h dristruct.h sarea.h 
	xf86dri.c xf86dri.h xf86dristr.h 
Log Message:
- Initial add of enough of the DRI to create a 2d driver that uses
  the DRM for its acceleration.
- Converted the ATI driver to use the DRM to execute rendering
  commands using DMA instead of MMIO when available.


--- NEW FILE: .cvsignore ---
.deps
.libs
Makefile.in
Makefile
*.lo
*.la

--- NEW FILE: Makefile.am ---
INCLUDES = 			\
	-I$(top_srcdir)/mi	\
	-I$(top_srcdir)/drm	\
	@XSERVER_CFLAGS@

noinst_LIBRARIES = libdri.a

libdri_a_SOURCES = 	\
	dri.c		\
	xf86dri.c

--- NEW FILE: dri.c ---
/* $XFree86: xc/programs/Xserver/GL/dri/dri.c,v 1.38 2002/11/20 18:10:24 dawes Exp $ */
/**************************************************************************

Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
Copyright 2000 VA Linux Systems, Inc.
All Rights Reserved.

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, sub license, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice (including the
next paragraph) shall be included in all copies or substantial portions
of the Software.

[...2095 lines suppressed...]
                 *lastBox = tmpBox;
                 firstBox++;
                 lastBox--;
              }

              firstBox = lastBox = pbox;
              y = pbox->y1;
           }
         }
         while((unsigned long)firstBox < (unsigned long)lastBox) {
           tmpBox = *firstBox;
           *firstBox = *lastBox;
           *lastBox = tmpBox;
           firstBox++;
           lastBox--;
        }
     }
   } else *xdir = 1;

}

--- NEW FILE: dri.h ---
/* $XFree86: xc/programs/Xserver/GL/dri/dri.h,v 1.19 2002/10/30 12:52:03 alanh Exp $ */
/**************************************************************************

Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
All Rights Reserved.

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, sub license, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice (including the
next paragraph) shall be included in all copies or substantial portions
of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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

/*
 * Authors:
 *   Jens Owen <jens@tungstengraphics.com>
 *
 */

/* Prototypes for DRI functions */

#ifndef _DRI_H_

#include "scrnintstr.h"
#include "xf86dri.h"

typedef int DRISyncType;

#define DRI_NO_SYNC 0
#define DRI_2D_SYNC 1
#define DRI_3D_SYNC 2

typedef int DRIContextType;

typedef struct _DRIContextPrivRec DRIContextPrivRec, *DRIContextPrivPtr;

typedef enum _DRIContextFlags
{
    DRI_CONTEXT_2DONLY    = 0x01,
    DRI_CONTEXT_PRESERVED = 0x02,
    DRI_CONTEXT_RESERVED  = 0x04 /* DRI Only -- no kernel equivalent */
} DRIContextFlags;

#define DRI_NO_CONTEXT 0
#define DRI_2D_CONTEXT 1
#define DRI_3D_CONTEXT 2

typedef int DRISwapMethod;

#define DRI_HIDE_X_CONTEXT 0
#define DRI_SERVER_SWAP    1
#define DRI_KERNEL_SWAP    2

typedef int DRIWindowRequests;

#define DRI_NO_WINDOWS       0
#define DRI_3D_WINDOWS_ONLY  1
#define DRI_ALL_WINDOWS      2


typedef void (*ClipNotifyPtr)( WindowPtr, int, int );
typedef void (*AdjustFramePtr)(int scrnIndex, int x, int y, int flags);


/*
 * These functions can be wrapped by the DRI.  Each of these have
 * generic default funcs (initialized in DRICreateInfoRec) and can be
 * overridden by the driver in its [driver]DRIScreenInit function.
 */
typedef struct {
    ScreenWakeupHandlerProcPtr   WakeupHandler;
    ScreenBlockHandlerProcPtr    BlockHandler;
    WindowExposuresProcPtr       WindowExposures;
    CopyWindowProcPtr            CopyWindow;
    ValidateTreeProcPtr          ValidateTree;
    PostValidateTreeProcPtr      PostValidateTree;
    ClipNotifyProcPtr            ClipNotify;
    AdjustFramePtr               AdjustFrame;
} DRIWrappedFuncsRec, *DRIWrappedFuncsPtr;




typedef struct {
    /* driver call back functions
     *
     * New fields should be added at the end for backwards compatability.
     * Don't forget to bump the version minor number in 
     *   xc/lib/GL/dri/xf86dristr.h
     */
    Bool	(*CreateContext)(ScreenPtr pScreen,
				 VisualPtr visual,
				 drmContext hHWContext,
				 void* pVisualConfigPriv,
				 DRIContextType context);
    void        (*DestroyContext)(ScreenPtr pScreen,
				  drmContext hHWContext,
                                  DRIContextType context);
    void	(*SwapContext)(ScreenPtr pScreen,
			       DRISyncType syncType,
			       DRIContextType readContextType,
			       void* readContextStore,
			       DRIContextType writeContextType,
			       void* writeContextStore);
    void	(*InitBuffers)(WindowPtr pWin,
			       RegionPtr prgn,
			       CARD32 indx);
    void	(*MoveBuffers)(WindowPtr pWin,
			       DDXPointRec ptOldOrg,
			       RegionPtr prgnSrc,
			       CARD32 indx);
    void        (*TransitionTo3d)(ScreenPtr pScreen);
    void        (*TransitionTo2d)(ScreenPtr pScreen);

    void	(*SetDrawableIndex)(WindowPtr pWin, CARD32 indx);
    Bool        (*OpenFullScreen)(ScreenPtr pScreen);
    Bool        (*CloseFullScreen)(ScreenPtr pScreen);

    /* wrapped functions */
    DRIWrappedFuncsRec  wrap;

    /* device info */
    char*		drmDriverName;
    char*		clientDriverName;
    char*		busIdString;
    int			ddxDriverMajorVersion;
    int			ddxDriverMinorVersion;
    int			ddxDriverPatchVersion;
    CARD32		frameBufferPhysicalAddress;
    long		frameBufferSize;
    long		frameBufferStride;
    long		SAREASize;
    int			maxDrawableTableEntry;
    int			ddxDrawableTableEntry;
    long		contextSize;
    DRISwapMethod	driverSwapMethod;
    DRIWindowRequests	bufferRequests;
    int			devPrivateSize;
    void*		devPrivate;
    Bool		createDummyCtx;
    Bool		createDummyCtxPriv;

    /* New with DRI version 4.1.0 */
    void        (*TransitionSingleToMulti3D)(ScreenPtr pScreen);
    void        (*TransitionMultiToSingle3D)(ScreenPtr pScreen);
} DRIInfoRec, *DRIInfoPtr;


extern Bool DRIScreenInit(ScreenPtr pScreen,
                          DRIInfoPtr pDRIInfo,
                          int *pDRMFD);

extern void DRICloseScreen(ScreenPtr pScreen);

extern Bool DRIExtensionInit(void);

extern void DRIReset(void);

extern Bool DRIQueryDirectRenderingCapable(ScreenPtr pScreen,
                                           Bool *isCapable);

extern Bool DRIOpenConnection(ScreenPtr pScreen,
                              drmHandlePtr hSAREA,
                              char **busIdString);

extern Bool DRIAuthConnection(ScreenPtr pScreen, drmMagic magic);

extern Bool DRICloseConnection(ScreenPtr pScreen);

extern Bool DRIGetClientDriverName(ScreenPtr pScreen,
                                   int* ddxDriverMajorVersion,
                                   int* ddxDriverMinorVersion,
                                   int* ddxDriverPatchVersion,
                                   char** clientDriverName);

extern Bool DRICreateContext(ScreenPtr pScreen,
                             VisualPtr visual,
                             XID context,
                             drmContextPtr pHWContext);

extern Bool DRIDestroyContext(ScreenPtr pScreen, XID context);

extern Bool DRIContextPrivDelete(pointer pResource, XID id);

extern Bool DRICreateDrawable(ScreenPtr pScreen,
                              Drawable id,
                              DrawablePtr pDrawable,
                              drmDrawablePtr hHWDrawable);

extern Bool DRIDestroyDrawable(ScreenPtr pScreen, 
                               Drawable id,
                               DrawablePtr pDrawable);

extern Bool DRIDrawablePrivDelete(pointer pResource,
                                  XID id);

extern Bool DRIGetDrawableInfo(ScreenPtr pScreen,
                               DrawablePtr pDrawable,
                               unsigned int* indx,
                               unsigned int* stamp,
                               int* X,
                               int* Y,
                               int* W,
                               int* H,
                               int* numClipRects,
                               XF86DRIClipRectPtr* pClipRects,
                               int* backX,
                               int* backY,
                               int* numBackClipRects,
                               XF86DRIClipRectPtr* pBackClipRects);

extern Bool DRIGetDeviceInfo(ScreenPtr pScreen,
                             drmHandlePtr hFrameBuffer,
                             int* fbOrigin,
                             int* fbSize,
                             int* fbStride,
                             int* devPrivateSize,
                             void** pDevPrivate);

extern DRIInfoPtr DRICreateInfoRec(void);

extern void DRIDestroyInfoRec(DRIInfoPtr DRIInfo);

extern Bool DRIFinishScreenInit(ScreenPtr pScreen);

extern void DRIWakeupHandler(pointer wakeupData,
                             int result,
                             pointer pReadmask);

extern void DRIBlockHandler(pointer blockData,
                            OSTimePtr pTimeout,
                            pointer pReadmask);

extern void DRIDoWakeupHandler(int screenNum,
                               pointer wakeupData,
                               unsigned long result,
                               pointer pReadmask);

extern void DRIDoBlockHandler(int screenNum,
                              pointer blockData,
                              pointer pTimeout,
                              pointer pReadmask);

extern void DRISwapContext(int drmFD,
                           void *oldctx,
                           void *newctx);

extern void *DRIGetContextStore(DRIContextPrivPtr context);

extern void DRIWindowExposures(WindowPtr pWin,
                              RegionPtr prgn,
                              RegionPtr bsreg);

extern void DRICopyWindow(WindowPtr pWin,
                          DDXPointRec ptOldOrg,
                          RegionPtr prgnSrc);

extern int DRIValidateTree(WindowPtr pParent,
                           WindowPtr pChild,
                           VTKind    kind);

extern void DRIPostValidateTree(WindowPtr pParent,
                                WindowPtr pChild,
                                VTKind    kind);

extern void DRIClipNotify(WindowPtr pWin,
                          int dx,
                          int dy);

extern CARD32 DRIGetDrawableIndex(WindowPtr pWin);

extern void DRIPrintDrawableLock(ScreenPtr pScreen, char *msg);

extern void DRILock(ScreenPtr pScreen, int flags);

extern void DRIUnlock(ScreenPtr pScreen);

extern DRIWrappedFuncsRec *DRIGetWrappedFuncs(ScreenPtr pScreen);

extern void *DRIGetSAREAPrivate(ScreenPtr pScreen);

extern unsigned int DRIGetDrawableStamp(ScreenPtr pScreen,
                                        CARD32 drawable_index);

extern DRIContextPrivPtr DRICreateContextPriv(ScreenPtr pScreen,
                                              drmContextPtr pHWContext,
                                              DRIContextFlags flags);

extern DRIContextPrivPtr DRICreateContextPrivFromHandle(ScreenPtr pScreen,
                                                        drmContext hHWContext,
                                                        DRIContextFlags flags);

extern Bool DRIDestroyContextPriv(DRIContextPrivPtr pDRIContextPriv);

extern drmContext DRIGetContext(ScreenPtr pScreen);

extern void DRIQueryVersion(int *majorVersion,
                            int *minorVersion,
                            int *patchVersion);

extern void DRIAdjustFrame(int scrnIndex, int x, int y, int flags);

extern int  DRIOpenFullScreen(ScreenPtr pScreen, DrawablePtr pDrawable);
extern int  DRICloseFullScreen(ScreenPtr pScreen, DrawablePtr pDrawable);

extern void DRIMoveBuffersHelper(ScreenPtr pScreen, 
                                 int dx,
                                 int dy,
                                 int *xdir, 
                                 int *ydir, 
                                 RegionPtr reg);

/* XXX */
/* extern char *DRICreatePCIBusID(pciVideoPtr PciInfo); */

#define _DRI_H_

#endif

--- NEW FILE: dristruct.h ---
/* $XFree86: xc/programs/Xserver/GL/dri/dristruct.h,v 1.13 2002/11/20 18:10:24 dawes Exp $ */
/**************************************************************************

Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
All Rights Reserved.

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, sub license, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice (including the
next paragraph) shall be included in all copies or substantial portions
of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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

/*
 * Authors:
 *   Jens Owen <jens@tungstengraphics.com>
 *
 */

#ifndef DRI_STRUCT_H
#define DRI_STRUCT_H

#include "libdrm.h"


#define DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin) \
    ((DRIWindowPrivIndex < 0) ? \
     NULL : \
     ((DRIDrawablePrivPtr)((pWin)->devPrivates[DRIWindowPrivIndex].ptr)))

#define DRI_DRAWABLE_PRIV_FROM_PIXMAP(pPix) \
    ((DRIPixmapPrivIndex < 0) ? \
     NULL : \
     ((DRIDrawablePrivPtr)((pPix)->devPrivates[DRIWindowPrivIndex].ptr)))

typedef struct _DRIDrawablePrivRec
{
    drmDrawable		hwDrawable;
    int			drawableIndex;
    ScreenPtr		pScreen;
    int 		refCount;
} DRIDrawablePrivRec, *DRIDrawablePrivPtr;

struct _DRIContextPrivRec
{
    drmContext		hwContext;
    ScreenPtr		pScreen;
    Bool     		valid3D;
    DRIContextFlags     flags;
    void**     		pContextStore;
};

#define DRI_SCREEN_PRIV(pScreen) \
    ((DRIScreenPrivIndex < 0) ? \
     NULL : \
     ((DRIScreenPrivPtr)((pScreen)->devPrivates[DRIScreenPrivIndex].ptr)))

#define DRI_SCREEN_PRIV_FROM_INDEX(screenIndex) ((DRIScreenPrivPtr) \
    (screenInfo.screens[screenIndex]->devPrivates[DRIScreenPrivIndex].ptr))


typedef struct _DRIScreenPrivRec
{
    Bool		directRenderingSupport;
    int			drmFD;	      /* File descriptor for /dev/video/?   */
    drmHandle   	hSAREA;	      /* Handle to SAREA, for mapping       */
    XF86DRISAREAPtr	pSAREA;	      /* Mapped pointer to SAREA            */
    drmHandle   	hFrameBuffer; /* Handle to framebuffer, for mapping */
    drmContext          myContext;    /* DDX Driver's context               */
    DRIContextPrivPtr   myContextPriv;/* Pointer to server's private area   */
    DRIContextPrivPtr   lastPartial3DContext;  /* last one partially saved  */
    void**		hiddenContextStore;    /* hidden X context          */
    void**		partial3DContextStore; /* parital 3D context        */
    DRIInfoPtr		pDriverInfo;
    int                 nrWindows;
    XF86DRIClipRectRec  private_buffer_rect; /* management of private buffers */
    DrawablePtr         fullscreen; /* pointer to fullscreen drawable */
    XF86DRIClipRectRec  fullscreen_rect; /* fake rect for fullscreen mode */
    DRIWrappedFuncsRec	wrap;
    DrawablePtr		DRIDrawables[SAREA_MAX_DRAWABLES];
    DRIContextPrivPtr   dummyCtxPriv; /* Pointer to dummy context */
    Bool		createDummyCtx;
    Bool		createDummyCtxPriv;
    Bool		grabbedDRILock;
    Bool		drmSIGIOHandlerInstalled;
    Bool		wrapped;
} DRIScreenPrivRec, *DRIScreenPrivPtr;

#endif /* DRI_STRUCT_H */

--- NEW FILE: sarea.h ---
/* $XFree86: xc/programs/Xserver/GL/dri/sarea.h,v 1.11 2002/10/30 12:52:03 alanh Exp $ */
/**
 * \file sarea.h 
 * SAREA definitions.
 * 
 * \author Kevin E. Martin <kevin@precisioninsight.com>
 * \author Jens Owen <jens@tungstengraphics.com>
 * \author Rickard E. (Rik) Faith <faith@valinux.com>
 */

/*
 * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
 * Copyright 2000 VA Linux Systems, Inc.
 * All Rights Reserved.
 * 
 * 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, sub license, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 * 
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial portions
 * of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

/* $XFree86: xc/programs/Xserver/GL/dri/sarea.h,v 1.11 2002/10/30 12:52:03 alanh Exp $ */

#ifndef _SAREA_H_
#define _SAREA_H_

#include "libdrm.h"

/* SAREA area needs to be at least a page */
#if defined(__alpha__)
#define SAREA_MAX 			0x2000
#elif defined(__ia64__)
#define SAREA_MAX			0x10000		/* 64kB */
#else
/* Intel 830M driver needs at least 8k SAREA */
#define SAREA_MAX			0x2000
#endif

#define SAREA_MAX_DRAWABLES 		256

#define SAREA_DRAWABLE_CLAIMED_ENTRY	0x80000000

/**
 * SAREA per drawable information.
 *
 * \sa _XF86DRISAREA.
 */
typedef struct _XF86DRISAREADrawable {
    unsigned int	stamp;
    unsigned int	flags;
} XF86DRISAREADrawableRec, *XF86DRISAREADrawablePtr;

/**
 * SAREA frame information.
 *
 * \sa  _XF86DRISAREA.
 */
typedef struct _XF86DRISAREAFrame {
    unsigned int        x;
    unsigned int        y;
    unsigned int        width;
    unsigned int        height;
    unsigned int        fullscreen;
} XF86DRISAREAFrameRec, *XF86DRISAREAFramePtr;

/**
 * SAREA definition.
 */
typedef struct _XF86DRISAREA {
    /** first thing is always the DRM locking structure */
    drmLock			lock;
    /** \todo Use readers/writer lock for drawable_lock */
    drmLock			drawable_lock;
    XF86DRISAREADrawableRec	drawableTable[SAREA_MAX_DRAWABLES];
    XF86DRISAREAFrameRec        frame;
    drmContext			dummy_context;
} XF86DRISAREARec, *XF86DRISAREAPtr;

#endif

--- NEW FILE: xf86dri.c ---
/* $XFree86: xc/programs/Xserver/GL/dri/xf86dri.c,v 1.12 2002/12/14 01:36:08 dawes Exp $ */
/**************************************************************************

Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
Copyright 2000 VA Linux Systems, Inc.
All Rights Reserved.

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, sub license, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice (including the
next paragraph) shall be included in all copies or substantial portions
of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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

/*
 * Authors:
 *   Kevin E. Martin <martin@valinux.com>
 *   Jens Owen <jens@tungstengraphics.com>
 *   Rickard E. (Rik) Faith <faith@valinux.com>
 *
 */

#ifdef XFree86LOADER
#include "xf86.h"
#include "xf86_ansic.h"
#endif

#define NEED_REPLIES
#define NEED_EVENTS
#include <X11/X.h>
#include <X11/Xproto.h>
#include "misc.h"
#include "dixstruct.h"
#include "extnsionst.h"
#include "colormapst.h"
#include "cursorstr.h"
#include "scrnintstr.h"
#include "servermd.h"
#define _XF86DRI_SERVER_
#include "xf86dristr.h"
#include "swaprep.h"
#include "dri.h"
#include "sarea.h"
#include "dristruct.h"
#include "libdrm.h"

static int DRIErrorBase;

static DISPATCH_PROC(ProcXF86DRIQueryVersion);
static DISPATCH_PROC(ProcXF86DRIQueryDirectRenderingCapable);
static DISPATCH_PROC(ProcXF86DRIOpenConnection);
static DISPATCH_PROC(ProcXF86DRICloseConnection);
static DISPATCH_PROC(ProcXF86DRIGetClientDriverName);
static DISPATCH_PROC(ProcXF86DRICreateContext);
static DISPATCH_PROC(ProcXF86DRIDestroyContext);
static DISPATCH_PROC(ProcXF86DRICreateDrawable);
static DISPATCH_PROC(ProcXF86DRIDestroyDrawable);
static DISPATCH_PROC(ProcXF86DRIGetDrawableInfo);
static DISPATCH_PROC(ProcXF86DRIGetDeviceInfo);
static DISPATCH_PROC(ProcXF86DRIDispatch);
static DISPATCH_PROC(ProcXF86DRIAuthConnection);
static DISPATCH_PROC(ProcXF86DRIOpenFullScreen);
static DISPATCH_PROC(ProcXF86DRICloseFullScreen);

static DISPATCH_PROC(SProcXF86DRIQueryVersion);
static DISPATCH_PROC(SProcXF86DRIDispatch);

static void XF86DRIResetProc(ExtensionEntry* extEntry);

static unsigned char DRIReqCode = 0;

extern void XFree86DRIExtensionInit(void);

void
XFree86DRIExtensionInit(void)
{
    ExtensionEntry* extEntry;

#ifdef XF86DRI_EVENTS
    EventType = CreateNewResourceType(XF86DRIFreeEvents);
#endif

    if (
	DRIExtensionInit() &&
#ifdef XF86DRI_EVENTS
        EventType && ScreenPrivateIndex != -1 &&
#endif
	(extEntry = AddExtension(XF86DRINAME,
				 XF86DRINumberEvents,
				 XF86DRINumberErrors,
				 ProcXF86DRIDispatch,
				 SProcXF86DRIDispatch,
				 XF86DRIResetProc,
				 StandardMinorOpcode))) {
	DRIReqCode = (unsigned char)extEntry->base;
	DRIErrorBase = extEntry->errorBase;
    }
}

/*ARGSUSED*/
static void
XF86DRIResetProc (
    ExtensionEntry* extEntry
)
{
    DRIReset();
}

static int
ProcXF86DRIQueryVersion(
    register ClientPtr client
)
{
    xXF86DRIQueryVersionReply rep;
    register int n;

    REQUEST_SIZE_MATCH(xXF86DRIQueryVersionReq);
    rep.type = X_Reply;
    rep.length = 0;
    rep.sequenceNumber = client->sequence;
    rep.majorVersion = XF86DRI_MAJOR_VERSION;
    rep.minorVersion = XF86DRI_MINOR_VERSION;
    rep.patchVersion = XF86DRI_PATCH_VERSION;
    if (client->swapped) {
    	swaps(&rep.sequenceNumber, n);
    	swapl(&rep.length, n);
    }
    WriteToClient(client, sizeof(xXF86DRIQueryVersionReply), (char *)&rep);
    return (client->noClientException);
}

static int
ProcXF86DRIQueryDirectRenderingCapable(
    register ClientPtr client
)
{
    xXF86DRIQueryDirectRenderingCapableReply	rep;
    Bool isCapable;

    REQUEST(xXF86DRIQueryDirectRenderingCapableReq);
    REQUEST_SIZE_MATCH(xXF86DRIQueryDirectRenderingCapableReq);
    if (stuff->screen >= screenInfo.numScreens) {
	client->errorValue = stuff->screen;
	return BadValue;
    }

    rep.type = X_Reply;
    rep.length = 0;
    rep.sequenceNumber = client->sequence;

    if (!DRIQueryDirectRenderingCapable( screenInfo.screens[stuff->screen], 
					 &isCapable)) {
	return BadValue;
    }
    rep.isCapable = isCapable;

    if (!LocalClient(client))
	rep.isCapable = 0;

    WriteToClient(client, 
	sizeof(xXF86DRIQueryDirectRenderingCapableReply), (char *)&rep);
    return (client->noClientException);
}

static int
ProcXF86DRIOpenConnection(
    register ClientPtr client
)
{
    xXF86DRIOpenConnectionReply rep;
    drmHandle			hSAREA;
    char*			busIdString;

    REQUEST(xXF86DRIOpenConnectionReq);
    REQUEST_SIZE_MATCH(xXF86DRIOpenConnectionReq);
    if (stuff->screen >= screenInfo.numScreens) {
	client->errorValue = stuff->screen;
	return BadValue;
    }

    if (!DRIOpenConnection( screenInfo.screens[stuff->screen], 
			    &hSAREA,
			    &busIdString)) {
	return BadValue;
    }

    rep.type = X_Reply;
    rep.sequenceNumber = client->sequence;
    rep.busIdStringLength = 0;
    if (busIdString)
	rep.busIdStringLength = strlen(busIdString);
    rep.length = (SIZEOF(xXF86DRIOpenConnectionReply) - SIZEOF(xGenericReply) +
                  ((rep.busIdStringLength + 3) & ~3)) >> 2;

    rep.hSAREALow  = (CARD32)(hSAREA & 0xffffffff);
#ifdef LONG64
    rep.hSAREAHigh = (CARD32)(hSAREA >> 32);
#else
    rep.hSAREAHigh = 0;
#endif

    WriteToClient(client, sizeof(xXF86DRIOpenConnectionReply), (char *)&rep);
    if (rep.busIdStringLength)
	WriteToClient(client, rep.busIdStringLength, busIdString);
    return (client->noClientException);
}

static int
ProcXF86DRIAuthConnection(
    register ClientPtr client
)
{
    xXF86DRIAuthConnectionReply rep;
    
    REQUEST(xXF86DRIAuthConnectionReq);
    REQUEST_SIZE_MATCH(xXF86DRIAuthConnectionReq);
    if (stuff->screen >= screenInfo.numScreens) {
	client->errorValue = stuff->screen;
	return BadValue;
    }

    rep.type = X_Reply;
    rep.length = 0;
    rep.sequenceNumber = client->sequence;
    rep.authenticated = 1;

    if (!DRIAuthConnection( screenInfo.screens[stuff->screen], stuff->magic)) {
        ErrorF("Failed to authenticate %u\n", stuff->magic);
	rep.authenticated = 0;
    }
    WriteToClient(client, sizeof(xXF86DRIAuthConnectionReply), (char *)&rep);
    return (client->noClientException);
}

static int
ProcXF86DRICloseConnection(
    register ClientPtr client
)
{
    REQUEST(xXF86DRICloseConnectionReq);
    REQUEST_SIZE_MATCH(xXF86DRICloseConnectionReq);
    if (stuff->screen >= screenInfo.numScreens) {
	client->errorValue = stuff->screen;
	return BadValue;
    }

    DRICloseConnection( screenInfo.screens[stuff->screen]);

    return (client->noClientException);
}

static int
ProcXF86DRIGetClientDriverName(
    register ClientPtr client
)
{
    xXF86DRIGetClientDriverNameReply	rep;
    char* clientDriverName;

    REQUEST(xXF86DRIGetClientDriverNameReq);
    REQUEST_SIZE_MATCH(xXF86DRIGetClientDriverNameReq);
    if (stuff->screen >= screenInfo.numScreens) {
	client->errorValue = stuff->screen;
	return BadValue;
    }

    DRIGetClientDriverName( screenInfo.screens[stuff->screen],
			    (int *)&rep.ddxDriverMajorVersion,
			    (int *)&rep.ddxDriverMinorVersion,
			    (int *)&rep.ddxDriverPatchVersion,
			    &clientDriverName);

    rep.type = X_Reply;
    rep.sequenceNumber = client->sequence;
    rep.clientDriverNameLength = 0;
    if (clientDriverName)
	rep.clientDriverNameLength = strlen(clientDriverName);
    rep.length = (SIZEOF(xXF86DRIGetClientDriverNameReply) - 
			SIZEOF(xGenericReply) +
			((rep.clientDriverNameLength + 3) & ~3)) >> 2;

    WriteToClient(client, 
	sizeof(xXF86DRIGetClientDriverNameReply), (char *)&rep);
    if (rep.clientDriverNameLength)
	WriteToClient(client, 
                      rep.clientDriverNameLength, 
                      clientDriverName);
    return (client->noClientException);
}

static int
ProcXF86DRICreateContext(
    register ClientPtr client
)
{
    xXF86DRICreateContextReply	rep;
    ScreenPtr pScreen;
    VisualPtr visual;
    int i;

    REQUEST(xXF86DRICreateContextReq);
    REQUEST_SIZE_MATCH(xXF86DRICreateContextReq);
    if (stuff->screen >= screenInfo.numScreens) {
	client->errorValue = stuff->screen;
	return BadValue;
    }

    rep.type = X_Reply;
    rep.length = 0;
    rep.sequenceNumber = client->sequence;

    pScreen = screenInfo.screens[stuff->screen];
    visual = pScreen->visuals;

    /* Find the requested X visual */
    for (i = 0; i < pScreen->numVisuals; i++, visual++)
	if (visual->vid == stuff->visual)
	    break;
    if (i == pScreen->numVisuals) {
	/* No visual found */
	return BadValue;
    }

    if (!DRICreateContext( pScreen,
			   visual,
			   stuff->context,
			   (drmContextPtr)&rep.hHWContext)) {
	return BadValue;
    }

    WriteToClient(client, sizeof(xXF86DRICreateContextReply), (char *)&rep);
    return (client->noClientException);
}

static int
ProcXF86DRIDestroyContext(
    register ClientPtr client
)
{
    REQUEST(xXF86DRIDestroyContextReq);
    REQUEST_SIZE_MATCH(xXF86DRIDestroyContextReq);
    if (stuff->screen >= screenInfo.numScreens) {
	client->errorValue = stuff->screen;
	return BadValue;
    }

    if (!DRIDestroyContext( screenInfo.screens[stuff->screen],
			    stuff->context)) {
	return BadValue;
    }

    return (client->noClientException);
}

static int
ProcXF86DRICreateDrawable(
    ClientPtr client
)
{
    xXF86DRICreateDrawableReply	rep;
    DrawablePtr pDrawable;

    REQUEST(xXF86DRICreateDrawableReq);
    REQUEST_SIZE_MATCH(xXF86DRICreateDrawableReq);
    if (stuff->screen >= screenInfo.numScreens) {
	client->errorValue = stuff->screen;
	return BadValue;
    }

    rep.type = X_Reply;
    rep.length = 0;
    rep.sequenceNumber = client->sequence;

    if (!(pDrawable = (DrawablePtr)SecurityLookupDrawable(
						(Drawable)stuff->drawable,
						client, 
						SecurityReadAccess))) {
	return BadValue;
    }

    if (!DRICreateDrawable( screenInfo.screens[stuff->screen],
			    (Drawable)stuff->drawable,
			    pDrawable,
			    (drmDrawablePtr)&rep.hHWDrawable)) {
	return BadValue;
    }

    WriteToClient(client, sizeof(xXF86DRICreateDrawableReply), (char *)&rep);
    return (client->noClientException);
}

static int
ProcXF86DRIDestroyDrawable(
    register ClientPtr client
)
{
    REQUEST(xXF86DRIDestroyDrawableReq);
    DrawablePtr pDrawable;
    REQUEST_SIZE_MATCH(xXF86DRIDestroyDrawableReq);
    if (stuff->screen >= screenInfo.numScreens) {
	client->errorValue = stuff->screen;
	return BadValue;
    }

    if (!(pDrawable = (DrawablePtr)SecurityLookupDrawable(
						(Drawable)stuff->drawable,
						client, 
						SecurityReadAccess))) {
	return BadValue;
    }

    if (!DRIDestroyDrawable( screenInfo.screens[stuff->screen], 
			     (Drawable)stuff->drawable,
			     pDrawable)) {
	return BadValue;
    }

    return (client->noClientException);
}

static int
ProcXF86DRIGetDrawableInfo(
    register ClientPtr client
)
{
    xXF86DRIGetDrawableInfoReply	rep;
    DrawablePtr pDrawable;
    int X, Y, W, H;
    XF86DRIClipRectPtr pClipRects;
    XF86DRIClipRectPtr pBackClipRects;
    int backX, backY;

    REQUEST(xXF86DRIGetDrawableInfoReq);
    REQUEST_SIZE_MATCH(xXF86DRIGetDrawableInfoReq);
    if (stuff->screen >= screenInfo.numScreens) {
	client->errorValue = stuff->screen;
	return BadValue;
    }

    rep.type = X_Reply;
    rep.length = 0;
    rep.sequenceNumber = client->sequence;

    if (!(pDrawable = (DrawablePtr)SecurityLookupDrawable(
						(Drawable)stuff->drawable,
						client, 
						SecurityReadAccess))) {
	return BadValue;
    }

    if (!DRIGetDrawableInfo( screenInfo.screens[stuff->screen],
			     pDrawable,
			     (unsigned int*)&rep.drawableTableIndex,
			     (unsigned int*)&rep.drawableTableStamp,
			     (int*)&X,
			     (int*)&Y,
			     (int*)&W,
			     (int*)&H,
			     (int*)&rep.numClipRects,
			     &pClipRects,
			     &backX, 
			     &backY,
			     (int*)&rep.numBackClipRects,
			     &pBackClipRects)) {
	return BadValue;
    }

    rep.drawableX = X;
    rep.drawableY = Y;
    rep.drawableWidth = W;
    rep.drawableHeight = H;
    rep.length = (SIZEOF(xXF86DRIGetDrawableInfoReply) - 
		  SIZEOF(xGenericReply));

    rep.backX = backX;
    rep.backY = backY;
        
    if (rep.numBackClipRects) 
       rep.length += sizeof(XF86DRIClipRectRec) * rep.numBackClipRects;    

    if (rep.numClipRects) 
       rep.length += sizeof(XF86DRIClipRectRec) * rep.numClipRects;
    
    rep.length = ((rep.length + 3) & ~3) >> 2;

    WriteToClient(client, sizeof(xXF86DRIGetDrawableInfoReply), (char *)&rep);

    if (rep.numClipRects) {
	WriteToClient(client,  
		      sizeof(XF86DRIClipRectRec) * rep.numClipRects,
		      (char *)pClipRects);
    }

    if (rep.numBackClipRects) {
       WriteToClient(client, 
		     sizeof(XF86DRIClipRectRec) * rep.numBackClipRects,
		     (char *)pBackClipRects);
    }

    return (client->noClientException);
}

static int
ProcXF86DRIGetDeviceInfo(
    register ClientPtr client
)
{
    xXF86DRIGetDeviceInfoReply	rep;
    drmHandle hFrameBuffer;
    void *pDevPrivate;

    REQUEST(xXF86DRIGetDeviceInfoReq);
    REQUEST_SIZE_MATCH(xXF86DRIGetDeviceInfoReq);
    if (stuff->screen >= screenInfo.numScreens) {
	client->errorValue = stuff->screen;
	return BadValue;
    }

    rep.type = X_Reply;
    rep.length = 0;
    rep.sequenceNumber = client->sequence;

    if (!DRIGetDeviceInfo( screenInfo.screens[stuff->screen],
			   &hFrameBuffer,
			   (int*)&rep.framebufferOrigin,
			   (int*)&rep.framebufferSize,
			   (int*)&rep.framebufferStride,
			   (int*)&rep.devPrivateSize,
			   &pDevPrivate)) {
	return BadValue;
    }

    rep.hFrameBufferLow  = (CARD32)(hFrameBuffer & 0xffffffff);
#ifdef LONG64
    rep.hFrameBufferHigh = (CARD32)(hFrameBuffer >> 32);
#else
    rep.hFrameBufferHigh = 0;
#endif

    rep.length = 0;
    if (rep.devPrivateSize) {
	rep.length = (SIZEOF(xXF86DRIGetDeviceInfoReply) - 
		      SIZEOF(xGenericReply) +
		      ((rep.devPrivateSize + 3) & ~3)) >> 2;
    }

    WriteToClient(client, sizeof(xXF86DRIGetDeviceInfoReply), (char *)&rep);
    if (rep.length) {
	WriteToClient(client, rep.devPrivateSize, (char *)pDevPrivate);
    }
    return (client->noClientException);
}

static int
ProcXF86DRIOpenFullScreen (
    register ClientPtr client
)
{
    REQUEST(xXF86DRIOpenFullScreenReq);
    xXF86DRIOpenFullScreenReply rep;
    DrawablePtr                 pDrawable;

    REQUEST_SIZE_MATCH(xXF86DRIOpenFullScreenReq);
    if (stuff->screen >= screenInfo.numScreens) {
	client->errorValue = stuff->screen;
	return BadValue;
    }

    rep.type           = X_Reply;
    rep.length         = 0;
    rep.sequenceNumber = client->sequence;

    if (!(pDrawable = SecurityLookupDrawable(stuff->drawable,
					     client, 
					     SecurityReadAccess)))
	return BadValue;

    rep.isFullScreen = DRIOpenFullScreen(screenInfo.screens[stuff->screen],
					 pDrawable);
    
    WriteToClient(client, sizeof(xXF86DRIOpenFullScreenReply), (char *)&rep);
    return client->noClientException;
}

static int
ProcXF86DRICloseFullScreen (
    register ClientPtr client
)
{
    REQUEST(xXF86DRICloseFullScreenReq);
    xXF86DRICloseFullScreenReply rep;
    DrawablePtr                  pDrawable;

    REQUEST_SIZE_MATCH(xXF86DRICloseFullScreenReq);
    if (stuff->screen >= screenInfo.numScreens) {
	client->errorValue = stuff->screen;
	return BadValue;
    }

    rep.type           = X_Reply;
    rep.length         = 0;
    rep.sequenceNumber = client->sequence;

    if (!(pDrawable = SecurityLookupDrawable(stuff->drawable,
					     client, 
					     SecurityReadAccess)))
	return BadValue;
    
    DRICloseFullScreen(screenInfo.screens[stuff->screen], pDrawable);
    
    WriteToClient(client, sizeof(xXF86DRICloseFullScreenReply), (char *)&rep);
    return (client->noClientException);
}

static int
ProcXF86DRIDispatch (
    register ClientPtr	client
)
{
    REQUEST(xReq);

    switch (stuff->data)
    {
    case X_XF86DRIQueryVersion:
	return ProcXF86DRIQueryVersion(client);
    case X_XF86DRIQueryDirectRenderingCapable:
	return ProcXF86DRIQueryDirectRenderingCapable(client);
    }

    if (!LocalClient(client))
	return DRIErrorBase + XF86DRIClientNotLocal;

    switch (stuff->data)
    {
    case X_XF86DRIOpenConnection:
	return ProcXF86DRIOpenConnection(client);
    case X_XF86DRICloseConnection:
	return ProcXF86DRICloseConnection(client);
    case X_XF86DRIGetClientDriverName:
	return ProcXF86DRIGetClientDriverName(client);
    case X_XF86DRICreateContext:
	return ProcXF86DRICreateContext(client);
    case X_XF86DRIDestroyContext:
	return ProcXF86DRIDestroyContext(client);
    case X_XF86DRICreateDrawable:
	return ProcXF86DRICreateDrawable(client);
    case X_XF86DRIDestroyDrawable:
	return ProcXF86DRIDestroyDrawable(client);
    case X_XF86DRIGetDrawableInfo:
	return ProcXF86DRIGetDrawableInfo(client);
    case X_XF86DRIGetDeviceInfo:
	return ProcXF86DRIGetDeviceInfo(client);
    case X_XF86DRIAuthConnection:
	return ProcXF86DRIAuthConnection(client);
    case X_XF86DRIOpenFullScreen:
	return ProcXF86DRIOpenFullScreen(client);
    case X_XF86DRICloseFullScreen:
	return ProcXF86DRICloseFullScreen(client);
    default:
	return BadRequest;
    }
}

static int
SProcXF86DRIQueryVersion(
    register ClientPtr	client
)
{
    register int n;
    REQUEST(xXF86DRIQueryVersionReq);
    swaps(&stuff->length, n);
    return ProcXF86DRIQueryVersion(client);
}

static int
SProcXF86DRIDispatch (
    register ClientPtr	client
)
{
    REQUEST(xReq);

    /* It is bound to be non-local when there is byte swapping */
    if (!LocalClient(client))
	return DRIErrorBase + XF86DRIClientNotLocal;

    /* only local clients are allowed DRI access */
    switch (stuff->data)
    {
    case X_XF86DRIQueryVersion:
	return SProcXF86DRIQueryVersion(client);
    default:
	return BadRequest;
    }
}

--- NEW FILE: xf86dri.h ---
/* $XFree86: xc/lib/GL/dri/xf86dri.h,v 1.8 2002/10/30 12:51:25 alanh Exp $ */
/**************************************************************************

Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
Copyright 2000 VA Linux Systems, Inc.
All Rights Reserved.

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, sub license, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice (including the
next paragraph) shall be included in all copies or substantial portions
of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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

/*
 * Authors:
 *   Kevin E. Martin <martin@valinux.com>
 *   Jens Owen <jens@tungstengraphics.com>
 *   Rickard E. (Rik) Faith <faith@valinux.com>
 *
 */

#ifndef _XF86DRI_H_
#define _XF86DRI_H_

#include <X11/Xfuncproto.h>
#include <libdrm.h>

#define X_XF86DRIQueryVersion			0
#define X_XF86DRIQueryDirectRenderingCapable	1
#define X_XF86DRIOpenConnection			2
#define X_XF86DRICloseConnection		3
#define X_XF86DRIGetClientDriverName		4
#define X_XF86DRICreateContext			5
#define X_XF86DRIDestroyContext			6
#define X_XF86DRICreateDrawable			7
#define X_XF86DRIDestroyDrawable		8
#define X_XF86DRIGetDrawableInfo		9
#define X_XF86DRIGetDeviceInfo			10
#define X_XF86DRIAuthConnection                 11
#define X_XF86DRIOpenFullScreen                 12
#define X_XF86DRICloseFullScreen                13

#define XF86DRINumberEvents		0

#define XF86DRIClientNotLocal		0
#define XF86DRIOperationNotSupported	1
#define XF86DRINumberErrors		(XF86DRIOperationNotSupported + 1)

/* Warning : Do not change XF86DRIClipRect without changing the kernel 
 * structure! */
typedef struct _XF86DRIClipRect {
    unsigned short	x1; /* Upper left: inclusive */
    unsigned short	y1;
    unsigned short	x2; /* Lower right: exclusive */
    unsigned short	y2;
} XF86DRIClipRectRec, *XF86DRIClipRectPtr;

#ifndef _XF86DRI_SERVER_

_XFUNCPROTOBEGIN

Bool XF86DRIQueryExtension(
#if NeedFunctionPrototypes
    Display*		/* dpy */,
    int*		/* event_base */,
    int*		/* error_base */
#endif
);

Bool XF86DRIQueryVersion(
#if NeedFunctionPrototypes
    Display*		/* dpy */,
    int*		/* majorVersion */,
    int*		/* minorVersion */,
    int*		/* patchVersion */
#endif
);

Bool XF86DRIQueryDirectRenderingCapable(
#if NeedFunctionPrototypes
    Display*		/* dpy */,
    int			/* screen */,
    Bool*		/* isCapable */
#endif
);

Bool XF86DRIOpenConnection(
#if NeedFunctionPrototypes
    Display*		/* dpy */,
    int			/* screen */,
    drmHandlePtr	/* hSAREA */,
    char**		/* busIDString */
#endif
);

Bool XF86DRIAuthConnection(
#if NeedFunctionPrototypes
    Display*		/* dpy */,
    int			/* screen */,
    drmMagic            /* magic */
#endif
);

Bool XF86DRICloseConnection(
#if NeedFunctionPrototypes
    Display*		/* dpy */,
    int			/* screen */
#endif
);

Bool XF86DRIGetClientDriverName(
#if NeedFunctionPrototypes
    Display*		/* dpy */,
    int			/* screen */,
    int*		/* ddxDriverMajorVersion */,
    int*		/* ddxDriverMinorVersion */,
    int*		/* ddxDriverPatchVersion */,
    char**		/* clientDriverName */
#endif
);

Bool XF86DRICreateContext(
#if NeedFunctionPrototypes
    Display*		/* dpy */,
    int			/* screen */,
    Visual*		/* visual */,
    XID*		/* ptr to returned context id */,
    drmContextPtr	/* hHWContext */
#endif
);

Bool XF86DRIDestroyContext(
#if NeedFunctionPrototypes
    Display*		/* dpy */,
    int			/* screen */,
    XID 	        /* context id */
#endif
);

Bool XF86DRICreateDrawable(
#if NeedFunctionPrototypes
    Display*		/* dpy */,
    int			/* screen */,
    Drawable		/* drawable */,
    drmDrawablePtr 	/* hHWDrawable */
#endif
);

Bool XF86DRIDestroyDrawable(
#if NeedFunctionPrototypes
    Display*		/* dpy */,
    int			/* screen */,
    Drawable 		/* drawable */
#endif
);

Bool XF86DRIGetDrawableInfo(
#if NeedFunctionPrototypes
    Display*		/* dpy */,
    int			/* screen */,
    Drawable 		/* drawable */,
    unsigned int*	/* index */,
    unsigned int*	/* stamp */,
    int*		/* X */,
    int*		/* Y */,
    int*		/* W */,
    int*		/* H */,
    int*		/* numClipRects */,
    XF86DRIClipRectPtr*,/* pClipRects */
    int*		/* backX */,
    int*		/* backY */,
    int*		/* numBackClipRects */,
    XF86DRIClipRectPtr*	/* pBackClipRects */    
#endif
);

Bool XF86DRIGetDeviceInfo(
#if NeedFunctionPrototypes
    Display*		/* dpy */,
    int			/* screen */,
    drmHandlePtr	/* hFrameBuffer */,
    int*		/* fbOrigin */,
    int*		/* fbSize */,
    int*		/* fbStride */,
    int*		/* devPrivateSize */,
    void**		/* pDevPrivate */
#endif
);

Bool XF86DRIOpenFullScreen(
#if NeedFunctionPrototypes
    Display*		/* dpy */,
    int                 /* screen */,
    Drawable 		/* drawable */
#endif
);

Bool XF86DRICloseFullScreen(
#if NeedFunctionPrototypes
    Display*		/* dpy */,
    int                 /* screen */,
    Drawable 		/* drawable */
#endif
);

_XFUNCPROTOEND

#endif /* _XF86DRI_SERVER_ */

#endif /* _XF86DRI_H_ */


--- NEW FILE: xf86dristr.h ---
/* $XFree86: xc/lib/GL/dri/xf86dristr.h,v 1.10 2002/10/30 12:51:25 alanh Exp $ */
/**************************************************************************

Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
Copyright 2000 VA Linux Systems, Inc.
All Rights Reserved.

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, sub license, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice (including the
next paragraph) shall be included in all copies or substantial portions
of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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

/*
 * Authors:
 *   Kevin E. Martin <martin@valinux.com>
 *   Jens Owen <jens@tungstengraphics.com>
 *   Rickard E. (Rik) Fiath <faith@valinux.com>
 *
 */

#ifndef _XF86DRISTR_H_
#define _XF86DRISTR_H_

#include "xf86dri.h"

#define XF86DRINAME "XFree86-DRI"

/* The DRI version number.  This was originally set to be the same of the
 * XFree86 version number.  However, this version is really indepedent of
 * the XFree86 version.
 *
 * Version History:
 *    4.0.0: Original
 *    4.0.1: Patch to bump clipstamp when windows are destroyed, 28 May 02
 *    4.1.0: Add transition from single to multi in DRMInfo rec, 24 Jun 02
 */
#define XF86DRI_MAJOR_VERSION	4
#define XF86DRI_MINOR_VERSION	1
#define XF86DRI_PATCH_VERSION	0

typedef struct _XF86DRIQueryVersion {
    CARD8	reqType;		/* always DRIReqCode */
    CARD8	driReqType;		/* always X_DRIQueryVersion */
    CARD16	length B16;
} xXF86DRIQueryVersionReq;
#define sz_xXF86DRIQueryVersionReq	4

typedef struct {
    BYTE	type;			/* X_Reply */
    BOOL	pad1;
    CARD16	sequenceNumber B16;
    CARD32	length B32;
    CARD16	majorVersion B16;	/* major version of DRI protocol */
    CARD16	minorVersion B16;	/* minor version of DRI protocol */
    CARD32	patchVersion B32;       /* patch version of DRI protocol */
    CARD32	pad3 B32;
    CARD32	pad4 B32;
    CARD32	pad5 B32;
    CARD32	pad6 B32;
} xXF86DRIQueryVersionReply;
#define sz_xXF86DRIQueryVersionReply	32

typedef struct _XF86DRIQueryDirectRenderingCapable {
    CARD8	reqType;		/* always DRIReqCode */
    CARD8	driReqType;		/* X_DRIQueryDirectRenderingCapable */
    CARD16	length B16;
    CARD32	screen B32;
} xXF86DRIQueryDirectRenderingCapableReq;
#define sz_xXF86DRIQueryDirectRenderingCapableReq	8

typedef struct {
    BYTE	type;			/* X_Reply */
    BOOL	pad1;
    CARD16	sequenceNumber B16;
    CARD32	length B32;
    BOOL	isCapable;
    BOOL	pad2;
    BOOL	pad3;
    BOOL	pad4;
    CARD32	pad5 B32;
    CARD32	pad6 B32;
    CARD32	pad7 B32;
    CARD32	pad8 B32;
    CARD32	pad9 B32;
} xXF86DRIQueryDirectRenderingCapableReply;
#define sz_xXF86DRIQueryDirectRenderingCapableReply	32

typedef struct _XF86DRIOpenConnection {
    CARD8	reqType;		/* always DRIReqCode */
    CARD8	driReqType;		/* always X_DRIOpenConnection */
    CARD16	length B16;
    CARD32	screen B32;
} xXF86DRIOpenConnectionReq;
#define sz_xXF86DRIOpenConnectionReq	8

typedef struct {
    BYTE	type;			/* X_Reply */
    BOOL	pad1;
    CARD16	sequenceNumber B16;
    CARD32	length B32;
    CARD32	hSAREALow B32;
    CARD32	hSAREAHigh B32;
    CARD32	busIdStringLength B32;
    CARD32	pad6 B32;
    CARD32	pad7 B32;
    CARD32	pad8 B32;
} xXF86DRIOpenConnectionReply;
#define sz_xXF86DRIOpenConnectionReply	32

typedef struct _XF86DRIAuthConnection {
    CARD8	reqType;		/* always DRIReqCode */
    CARD8	driReqType;		/* always X_DRICloseConnection */
    CARD16	length B16;
    CARD32	screen B32;
    CARD32      magic B32;
} xXF86DRIAuthConnectionReq;
#define sz_xXF86DRIAuthConnectionReq	12

typedef struct {
    BYTE        type;
    BOOL        pad1;
    CARD16      sequenceNumber B16;
    CARD32      length B32;
    CARD32      authenticated B32;
    CARD32      pad2 B32;
    CARD32      pad3 B32;
    CARD32      pad4 B32;
    CARD32      pad5 B32;
    CARD32      pad6 B32;
} xXF86DRIAuthConnectionReply;
#define zx_xXF86DRIAuthConnectionReply  32

typedef struct _XF86DRICloseConnection {
    CARD8	reqType;		/* always DRIReqCode */
    CARD8	driReqType;		/* always X_DRICloseConnection */
    CARD16	length B16;
    CARD32	screen B32;
} xXF86DRICloseConnectionReq;
#define sz_xXF86DRICloseConnectionReq	8

typedef struct _XF86DRIGetClientDriverName {
    CARD8	reqType;		/* always DRIReqCode */
    CARD8	driReqType;		/* always X_DRIGetClientDriverName */
    CARD16	length B16;
    CARD32	screen B32;
} xXF86DRIGetClientDriverNameReq;
#define sz_xXF86DRIGetClientDriverNameReq	8

typedef struct {
    BYTE	type;			/* X_Reply */
    BOOL	pad1;
    CARD16	sequenceNumber B16;
    CARD32	length B32;
    CARD32	ddxDriverMajorVersion B32;
    CARD32	ddxDriverMinorVersion B32;
    CARD32	ddxDriverPatchVersion B32;
    CARD32	clientDriverNameLength B32;
    CARD32	pad5 B32;
    CARD32	pad6 B32;
} xXF86DRIGetClientDriverNameReply;
#define sz_xXF86DRIGetClientDriverNameReply	32

typedef struct _XF86DRICreateContext {
    CARD8	reqType;		/* always DRIReqCode */
    CARD8	driReqType;		/* always X_DRICreateContext */
    CARD16	length B16;
    CARD32	screen B32;
    CARD32	visual B32;
    CARD32	context B32;
} xXF86DRICreateContextReq;
#define sz_xXF86DRICreateContextReq	16

typedef struct {
    BYTE	type;			/* X_Reply */
    BOOL	pad1;
    CARD16	sequenceNumber B16;
    CARD32	length B32;
    CARD32	hHWContext B32;
    CARD32	pad2 B32;
    CARD32	pad3 B32;
    CARD32	pad4 B32;
    CARD32	pad5 B32;
    CARD32	pad6 B32;
} xXF86DRICreateContextReply;
#define sz_xXF86DRICreateContextReply	32

typedef struct _XF86DRIDestroyContext {
    CARD8	reqType;		/* always DRIReqCode */
    CARD8	driReqType;		/* always X_DRIDestroyContext */
    CARD16	length B16;
    CARD32	screen B32;
    CARD32	context B32;
} xXF86DRIDestroyContextReq;
#define sz_xXF86DRIDestroyContextReq	12

typedef struct _XF86DRICreateDrawable {
    CARD8	reqType;		/* always DRIReqCode */
    CARD8	driReqType;		/* always X_DRICreateDrawable */
    CARD16	length B16;
    CARD32	screen B32;
    CARD32	drawable B32;
} xXF86DRICreateDrawableReq;
#define sz_xXF86DRICreateDrawableReq	12

typedef struct {
    BYTE	type;			/* X_Reply */
    BOOL	pad1;
    CARD16	sequenceNumber B16;
    CARD32	length B32;
    CARD32	hHWDrawable B32;
    CARD32	pad2 B32;
    CARD32	pad3 B32;
    CARD32	pad4 B32;
    CARD32	pad5 B32;
    CARD32	pad6 B32;
} xXF86DRICreateDrawableReply;
#define sz_xXF86DRICreateDrawableReply	32

typedef struct _XF86DRIDestroyDrawable {
    CARD8	reqType;		/* always DRIReqCode */
    CARD8	driReqType;		/* always X_DRIDestroyDrawable */
    CARD16	length B16;
    CARD32	screen B32;
    CARD32	drawable B32;
} xXF86DRIDestroyDrawableReq;
#define sz_xXF86DRIDestroyDrawableReq	12

typedef struct _XF86DRIGetDrawableInfo {
    CARD8	reqType;		/* always DRIReqCode */
    CARD8	driReqType;		/* always X_DRIGetDrawableInfo */
    CARD16	length B16;
    CARD32	screen B32;
    CARD32	drawable B32;
} xXF86DRIGetDrawableInfoReq;
#define sz_xXF86DRIGetDrawableInfoReq	12

typedef struct {
    BYTE	type;			/* X_Reply */
    BOOL	pad1;
    CARD16	sequenceNumber B16;
    CARD32	length B32;
    CARD32	drawableTableIndex B32;
    CARD32	drawableTableStamp B32;
    INT16	drawableX B16;
    INT16	drawableY B16;
    INT16	drawableWidth B16;
    INT16	drawableHeight B16;
    CARD32	numClipRects B32;
    INT16       backX B16;
    INT16       backY B16;
    CARD32      numBackClipRects B32;
} xXF86DRIGetDrawableInfoReply;

#define sz_xXF86DRIGetDrawableInfoReply	36


typedef struct _XF86DRIGetDeviceInfo {
    CARD8	reqType;		/* always DRIReqCode */
    CARD8	driReqType;		/* always X_DRIGetDeviceInfo */
    CARD16	length B16;
    CARD32	screen B32;
} xXF86DRIGetDeviceInfoReq;
#define sz_xXF86DRIGetDeviceInfoReq	8

typedef struct {
    BYTE	type;			/* X_Reply */
    BOOL	pad1;
    CARD16	sequenceNumber B16;
    CARD32	length B32;
    CARD32	hFrameBufferLow B32;
    CARD32	hFrameBufferHigh B32;
    CARD32	framebufferOrigin B32;
    CARD32	framebufferSize B32;
    CARD32	framebufferStride B32;
    CARD32	devPrivateSize B32;
} xXF86DRIGetDeviceInfoReply;
#define sz_xXF86DRIGetDeviceInfoReply	32

typedef struct _XF86DRIOpenFullScreen {
    CARD8       reqType;	/* always DRIReqCode */
    CARD8       driReqType;	/* always X_DRIOpenFullScreen */
    CARD16      length B16;
    CARD32      screen B32;
    CARD32      drawable B32;
} xXF86DRIOpenFullScreenReq;
#define sz_xXF86DRIOpenFullScreenReq    12

typedef struct {
    BYTE        type;
    BOOL        pad1;
    CARD16      sequenceNumber B16;
    CARD32      length B32;
    CARD32      isFullScreen B32;
    CARD32      pad2 B32;
    CARD32      pad3 B32;
    CARD32      pad4 B32;
    CARD32      pad5 B32;
    CARD32      pad6 B32;
} xXF86DRIOpenFullScreenReply;
#define sz_xXF86DRIOpenFullScreenReply  32

typedef struct _XF86DRICloseFullScreen {
    CARD8       reqType;	/* always DRIReqCode */
    CARD8       driReqType;	/* always X_DRICloseFullScreen */
    CARD16      length B16;
    CARD32      screen B32;
    CARD32      drawable B32;
} xXF86DRICloseFullScreenReq;
#define sz_xXF86DRICloseFullScreenReq   12

typedef struct {
    BYTE        type;
    BOOL        pad1;
    CARD16      sequenceNumber B16;
    CARD32      length B32;
    CARD32      pad2 B32;
    CARD32      pad3 B32;
    CARD32      pad4 B32;
    CARD32      pad5 B32;
    CARD32      pad6 B32;
    CARD32      pad7 B32;
} xXF86DRICloseFullScreenReply;
#define sz_xXF86DRICloseFullScreenReply  32


#endif /* _XF86DRISTR_H_ */