Merge branch 'mesa_7_6_branch' of git+ssh://agd5f@git.freedesktop.org/git/mesa/mesa
[mesa.git] / src / mesa / drivers / dri / common / dri_util.h
index e6659811d75dee5541515c99943897e9413bee00..c95a5c8299a11c672527137bea9f78b4bbea3cf6 100644 (file)
@@ -1,25 +1,3 @@
-/* $XFree86: xc/lib/GL/dri/dri_util.h,v 1.1 2002/02/22 21:32:52 dawes Exp $ */
-/**
- * \file dri_util.h
- * DRI utility functions definitions.
- *
- * This module acts as glue between GLX and the actual hardware driver.  A DRI
- * driver doesn't really \e have to use any of this - it's optional.  But, some
- * useful stuff is done here that otherwise would have to be duplicated in most
- * drivers.
- * 
- * Basically, these utility functions take care of some of the dirty details of
- * screen initialization, context creation, context binding, DRM setup, etc.
- *
- * These functions are compiled into each DRI driver so libGL.so knows nothing
- * about them.
- *
- * \sa dri_util.c.
- * 
- * \author Kevin E. Martin <kevin@precisioninsight.com>
- * \author Brian Paul <brian@precisioninsight.com>
- */
-
 /*
  * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
  * All Rights Reserved.
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 
+/**
+ * \file dri_util.h
+ * DRI utility functions definitions.
+ *
+ * This module acts as glue between GLX and the actual hardware driver.  A DRI
+ * driver doesn't really \e have to use any of this - it's optional.  But, some
+ * useful stuff is done here that otherwise would have to be duplicated in most
+ * drivers.
+ * 
+ * Basically, these utility functions take care of some of the dirty details of
+ * screen initialization, context creation, context binding, DRM setup, etc.
+ *
+ * These functions are compiled into each DRI driver so libGL.so knows nothing
+ * about them.
+ *
+ * \sa dri_util.c.
+ * 
+ * \author Kevin E. Martin <kevin@precisioninsight.com>
+ * \author Brian Paul <brian@precisioninsight.com>
+ */
 
 #ifndef _DRI_UTIL_H_
 #define _DRI_UTIL_H_
 
 #include <GL/gl.h>
-#include "drm.h"
-#include "drm_sarea.h"
-#include "xf86drm.h"
+#include <drm.h>
+#include <drm_sarea.h>
+#include <xf86drm.h>
+#include "main/glheader.h"
 #include "GL/internal/glcore.h"
 #include "GL/internal/dri_interface.h"
-#include "GL/internal/dri_sarea.h"
 
 #define GLX_BAD_CONTEXT                    5
 
-typedef struct __DRIdisplayPrivateRec  __DRIdisplayPrivate;
-typedef struct __DRIscreenPrivateRec   __DRIscreenPrivate;
-typedef struct __DRIcontextPrivateRec  __DRIcontextPrivate;
-typedef struct __DRIdrawablePrivateRec __DRIdrawablePrivate;
 typedef struct __DRIswapInfoRec        __DRIswapInfo;
-typedef struct __DRIutilversionRec2    __DRIutilversion2;
-
-
-/**
- * Driver specific entry point.  Implemented by the driver.  Called
- * from the top level createNewScreen entry point to initialize the
- * __DRIscreenPrivate struct.
- */
-extern __GLcontextModes *__driDriverInitScreen(__DRIscreenPrivate *psp);
 
-/** Ditto for DRI2 capable drivers. */
-extern __GLcontextModes *__dri2DriverInitScreen(__DRIscreenPrivate *psp);
+/* Typedefs to avoid rewriting the world. */
+typedef struct __DRIscreenRec  __DRIscreenPrivate;
+typedef struct __DRIdrawableRec        __DRIdrawablePrivate;
+typedef struct __DRIcontextRec __DRIcontextPrivate;
 
 /**
  * Extensions.
  */
+extern const __DRIlegacyExtension driLegacyExtension;
+extern const __DRIcoreExtension driCoreExtension;
 extern const __DRIextension driReadDrawableExtension;
 extern const __DRIcopySubBufferExtension driCopySubBufferExtension;
 extern const __DRIswapControlExtension driSwapControlExtension;
@@ -100,7 +89,7 @@ extern const __DRImediaStreamCounterExtension driMediaStreamCounterExtension;
 /**
  * Utility macro to validate the drawable information.
  *
- * See __DRIdrawablePrivate::pStamp and __DRIdrawablePrivate::lastStamp.
+ * See __DRIdrawable::pStamp and __DRIdrawable::lastStamp.
  */
 #define DRI_VALIDATE_DRAWABLE_INFO(psp, pdp)                            \
 do {                                                                    \
@@ -117,6 +106,28 @@ do {                                                                    \
     }                                                                   \
 } while (0)
 
+/**
+ * Same as above, but for two drawables simultaneously.
+ *
+ */
+
+#define DRI_VALIDATE_TWO_DRAWABLES_INFO(psp, pdp, prp)                 \
+do {                                                           \
+    while (*((pdp)->pStamp) != (pdp)->lastStamp ||                     \
+          *((prp)->pStamp) != (prp)->lastStamp) {                      \
+        register unsigned int hwContext = (psp)->pSAREA->lock.lock &   \
+           ~(DRM_LOCK_HELD | DRM_LOCK_CONT);                           \
+       DRM_UNLOCK((psp)->fd, &(psp)->pSAREA->lock, hwContext);         \
+                                                                       \
+       DRM_SPINLOCK(&(psp)->pSAREA->drawable_lock, (psp)->drawLockID); \
+       DRI_VALIDATE_DRAWABLE_INFO_ONCE(pdp);                           \
+       DRI_VALIDATE_DRAWABLE_INFO_ONCE(prp);                           \
+       DRM_SPINUNLOCK(&(psp)->pSAREA->drawable_lock, (psp)->drawLockID); \
+                                                                       \
+       DRM_LIGHT_LOCK((psp)->fd, &(psp)->pSAREA->lock, hwContext);     \
+    }                                                                   \
+} while (0)
+
 
 /**
  * Driver callback functions.
@@ -129,74 +140,76 @@ do {                                                                    \
  * this structure.
  */
 struct __DriverAPIRec {
+    const __DRIconfig **(*InitScreen) (__DRIscreen * priv);
+
     /**
      * Screen destruction callback
      */
-    void (*DestroyScreen)(__DRIscreenPrivate *driScrnPriv);
+    void (*DestroyScreen)(__DRIscreen *driScrnPriv);
 
     /**
      * Context creation callback
      */                    
     GLboolean (*CreateContext)(const __GLcontextModes *glVis,
-                               __DRIcontextPrivate *driContextPriv,
+                               __DRIcontext *driContextPriv,
                                void *sharedContextPrivate);
 
     /**
      * Context destruction callback
      */
-    void (*DestroyContext)(__DRIcontextPrivate *driContextPriv);
+    void (*DestroyContext)(__DRIcontext *driContextPriv);
 
     /**
      * Buffer (drawable) creation callback
      */
-    GLboolean (*CreateBuffer)(__DRIscreenPrivate *driScrnPriv,
-                              __DRIdrawablePrivate *driDrawPriv,
+    GLboolean (*CreateBuffer)(__DRIscreen *driScrnPriv,
+                              __DRIdrawable *driDrawPriv,
                               const __GLcontextModes *glVis,
                               GLboolean pixmapBuffer);
     
     /**
      * Buffer (drawable) destruction callback
      */
-    void (*DestroyBuffer)(__DRIdrawablePrivate *driDrawPriv);
+    void (*DestroyBuffer)(__DRIdrawable *driDrawPriv);
 
     /**
      * Buffer swapping callback 
      */
-    void (*SwapBuffers)(__DRIdrawablePrivate *driDrawPriv);
+    void (*SwapBuffers)(__DRIdrawable *driDrawPriv);
 
     /**
      * Context activation callback
      */
-    GLboolean (*MakeCurrent)(__DRIcontextPrivate *driContextPriv,
-                             __DRIdrawablePrivate *driDrawPriv,
-                             __DRIdrawablePrivate *driReadPriv);
+    GLboolean (*MakeCurrent)(__DRIcontext *driContextPriv,
+                             __DRIdrawable *driDrawPriv,
+                             __DRIdrawable *driReadPriv);
 
     /**
      * Context unbinding callback
      */
-    GLboolean (*UnbindContext)(__DRIcontextPrivate *driContextPriv);
+    GLboolean (*UnbindContext)(__DRIcontext *driContextPriv);
   
     /**
      * Retrieves statistics about buffer swap operations.  Required if
      * GLX_OML_sync_control or GLX_MESA_swap_frame_usage is supported.
      */
-    int (*GetSwapInfo)( __DRIdrawablePrivate *dPriv, __DRIswapInfo * sInfo );
+    int (*GetSwapInfo)( __DRIdrawable *dPriv, __DRIswapInfo * sInfo );
 
 
     /**
      * These are required if GLX_OML_sync_control is supported.
      */
     /*@{*/
-    int (*WaitForMSC)( __DRIdrawablePrivate *priv, int64_t target_msc, 
+    int (*WaitForMSC)( __DRIdrawable *priv, int64_t target_msc, 
                       int64_t divisor, int64_t remainder,
                       int64_t * msc );
-    int (*WaitForSBC)( __DRIdrawablePrivate *priv, int64_t target_sbc,
+    int (*WaitForSBC)( __DRIdrawable *priv, int64_t target_sbc,
                       int64_t * msc, int64_t * sbc );
 
-    int64_t (*SwapBuffersMSC)( __DRIdrawablePrivate *priv, int64_t target_msc,
+    int64_t (*SwapBuffersMSC)( __DRIdrawable *priv, int64_t target_msc,
                               int64_t divisor, int64_t remainder );
     /*@}*/
-    void (*CopySubBuffer)(__DRIdrawablePrivate *driDrawPriv,
+    void (*CopySubBuffer)(__DRIdrawable *driDrawPriv,
                          int x, int y, int w, int h);
 
     /**
@@ -204,21 +217,24 @@ struct __DriverAPIRec {
      * level DRM driver (e.g. pipe info).  Required if
      * GLX_SGI_video_sync or GLX_OML_sync_control is supported.
      */
-    int (*GetDrawableMSC) ( __DRIscreenPrivate * priv,
-                           __DRIdrawablePrivate *drawablePrivate,
+    int (*GetDrawableMSC) ( __DRIscreen * priv,
+                           __DRIdrawable *drawablePrivate,
                            int64_t *count);
 
-    /* DRI2 Entry points */
-    void (*UpdateBuffer)(__DRIdrawablePrivate *dPriv,
-                        unsigned int *event);
+
+
+    /* DRI2 Entry point */
+    const __DRIconfig **(*InitScreen2) (__DRIscreen * priv);
 };
 
+extern const struct __DriverAPIRec driDriverAPI;
+
 
 struct __DRIswapInfoRec {
     /** 
      * Number of swapBuffers operations that have been *completed*. 
      */
-    u_int64_t swap_count;
+    uint64_t swap_count;
 
     /**
      * Unadjusted system time of the last buffer swap.  This is the time
@@ -232,7 +248,7 @@ struct __DRIswapInfoRec {
      * swap, it has missed its deadline.  If swap_interval is 0, then the
      * swap deadline is 1 frame after the previous swap.
      */
-    u_int64_t swap_missed_count;
+    uint64_t swap_missed_count;
 
     /**
      * Amount of time used by the last swap that missed its deadline.  This
@@ -248,7 +264,7 @@ struct __DRIswapInfoRec {
 /**
  * Per-drawable private DRI driver information.
  */
-struct __DRIdrawablePrivateRec {
+struct __DRIdrawableRec {
     /**
      * Kernel drawable handle
      */
@@ -262,9 +278,10 @@ struct __DRIdrawablePrivateRec {
     void *driverPrivate;
 
     /**
-     * X's drawable ID associated with this private drawable.
+     * Private data from the loader.  We just hold on to it and pass
+     * it back when calling into loader provided functions.
      */
-    __DRIdrawable *pdraw;
+    void *loaderPrivate;
 
     /**
      * Reference count for number of context's currently bound to this
@@ -289,7 +306,7 @@ struct __DRIdrawablePrivateRec {
     /**
      * Last value of the stamp.
      *
-     * If this differs from the value stored at __DRIdrawablePrivate::pStamp,
+     * If this differs from the value stored at __DRIdrawable::pStamp,
      * then the drawable information has been modified by the X server, and the
      * drawable information (below) should be retrieved from the X server.
      */
@@ -351,32 +368,24 @@ struct __DRIdrawablePrivateRec {
     /**
      * Pointer to context to which this drawable is currently bound.
      */
-    __DRIcontextPrivate *driContextPriv;
+    __DRIcontext *driContextPriv;
 
     /**
      * Pointer to screen on which this drawable was created.
      */
-    __DRIscreenPrivate *driScreenPriv;
-
-    /**
-     * Called via glXSwapBuffers().
-     */
-    void (*swapBuffers)( __DRIdrawablePrivate *dPriv );
+    __DRIscreen *driScreenPriv;
 
     /**
      * Controls swap interval as used by GLX_SGI_swap_control and
      * GLX_MESA_swap_control.
      */
     unsigned int swap_interval;
-    struct {
-       unsigned int tail;
-    } dri2;
 };
 
 /**
  * Per-context private driver information.
  */
-struct __DRIcontextPrivateRec {
+struct __DRIcontextRec {
     /**
      * Kernel context handle used to access the device lock.
      */
@@ -395,23 +404,23 @@ struct __DRIcontextPrivateRec {
     /**
      * Pointer to drawable currently bound to this context for drawing.
      */
-    __DRIdrawablePrivate *driDrawablePriv;
+    __DRIdrawable *driDrawablePriv;
 
     /**
      * Pointer to drawable currently bound to this context for reading.
      */
-    __DRIdrawablePrivate *driReadablePriv;
+    __DRIdrawable *driReadablePriv;
 
     /**
      * Pointer to screen on which this context was created.
      */
-    __DRIscreenPrivate *driScreenPriv;
+    __DRIscreen *driScreenPriv;
 };
 
 /**
  * Per-screen private driver information.
  */
-struct __DRIscreenPrivateRec {
+struct __DRIscreenRec {
     /**
      * Current screen's number
      */
@@ -422,6 +431,7 @@ struct __DRIscreenPrivateRec {
      */
     struct __DriverAPIRec DriverAPI;
 
+    const __DRIextension **extensions;
     /**
      * DDX / 2D driver version information.
      */
@@ -498,7 +508,7 @@ struct __DRIscreenPrivateRec {
      * context is created when the first "real" context is created on this
      * screen.
      */
-    __DRIcontextPrivate dummyContextPriv;
+    __DRIcontext dummyContextPriv;
 
     /**
      * Device-dependent private information (not stored in the SAREA).
@@ -512,13 +522,7 @@ struct __DRIscreenPrivateRec {
      */
     __DRIscreen *psc;
 
-    /**
-     * Extensions provided by this driver.
-     */
-    const __DRIextension **extensions;
-
     /* Extensions provided by the loader. */
-    const __DRIcontextModesExtension *contextModes;
     const __DRIgetDrawableInfoExtension *getDrawableInfo;
     const __DRIsystemTimeExtension *systemTime;
     const __DRIdamageExtension *damage;
@@ -527,42 +531,25 @@ struct __DRIscreenPrivateRec {
        /* Flag to indicate that this is a DRI2 screen.  Many of the above
         * fields will not be valid or initializaed in that case. */
        int enabled;
-       drmBO sareaBO;
-       void *sarea;
-       __DRIEventBuffer *buffer;
-       __DRILock *lock;
-       __DRIcoreDRI2Extension *core;
+       __DRIdri2LoaderExtension *loader;
     } dri2;
 
     /* The lock actually in use, old sarea or DRI2 */
     drmLock *lock;
 };
 
-
-/**
- * Used to store a version which includes a major range instead of a single
- * major version number.
- */
-struct __DRIutilversionRec2 {
-    int    major_min;    /** min allowed Major version number. */
-    int    major_max;    /** max allowed Major version number. */
-    int    minor;        /**< Minor version number. */
-    int    patch;        /**< Patch-level. */
-};
-
-
 extern void
 __driUtilMessage(const char *f, ...);
 
 
 extern void
-__driUtilUpdateDrawableInfo(__DRIdrawablePrivate *pdp);
-
-extern int
-__driParseEvents(__DRIscreenPrivate *psp, __DRIdrawablePrivate *pdp);
+__driUtilUpdateDrawableInfo(__DRIdrawable *pdp);
 
 extern float
-driCalculateSwapUsage( __DRIdrawablePrivate *dPriv,
+driCalculateSwapUsage( __DRIdrawable *dPriv,
                       int64_t last_swap_ust, int64_t current_ust );
 
+extern GLint
+driIntersectArea( drm_clip_rect_t rect1, drm_clip_rect_t rect2 );
+
 #endif /* _DRI_UTIL_H_ */