* \author Brian Paul <brian@precisioninsight.com>
*/
+/**
+ * The following structs are shared between DRISW and DRI2, the DRISW structs
+ * are essentially base classes of the DRI2 structs. DRISW needs to compile on
+ * platforms without DRM, so keep the structs opaque to DRM.
+ */
+
#ifndef _DRI_UTIL_H_
#define _DRI_UTIL_H_
#include <GL/gl.h>
-#include "drm.h"
-#include "drm_sarea.h"
-#include "xf86drm.h"
-#include "GL/internal/glcore.h"
-#include "GL/internal/dri_interface.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;
-
+#include <GL/internal/dri_interface.h>
+#include "main/mtypes.h"
+#include "xmlconfig.h"
/**
- * Used by DRI_VALIDATE_DRAWABLE_INFO
+ * Extensions.
*/
-#define DRI_VALIDATE_DRAWABLE_INFO_ONCE(pDrawPriv) \
- do { \
- if (*(pDrawPriv->pStamp) != pDrawPriv->lastStamp) { \
- __driUtilUpdateDrawableInfo(pDrawPriv); \
- } \
- } while (0)
-
-
-/**
- * Utility macro to validate the drawable information.
- *
- * See __DRIdrawablePrivate::pStamp and __DRIdrawablePrivate::lastStamp.
- */
-#define DRI_VALIDATE_DRAWABLE_INFO(psp, pdp) \
-do { \
- while (*(pdp->pStamp) != pdp->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); \
- DRM_SPINUNLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID); \
- \
- DRM_LIGHT_LOCK(psp->fd, &psp->pSAREA->lock, hwContext); \
- } \
-} while (0)
-
+extern const __DRIcoreExtension driCoreExtension;
+extern const __DRIswrastExtension driSWRastExtension;
+extern const __DRIdri2Extension driDRI2Extension;
+extern const __DRI2configQueryExtension dri2ConfigQueryExtension;
/**
* Driver callback functions.
* this structure.
*/
struct __DriverAPIRec {
- /**
- * Driver initialization callback
- */
- GLboolean (*InitDriver)(__DRIscreenPrivate *driScrnPriv);
-
- /**
- * Screen destruction callback
- */
- void (*DestroyScreen)(__DRIscreenPrivate *driScrnPriv);
+ const __DRIconfig **(*InitScreen) (__DRIscreen * priv);
- /**
- * Context creation callback
- */
- GLboolean (*CreateContext)(const __GLcontextModes *glVis,
- __DRIcontextPrivate *driContextPriv,
+ void (*DestroyScreen)(__DRIscreen *driScrnPriv);
+
+ GLboolean (*CreateContext)(gl_api api,
+ const struct gl_config *glVis,
+ __DRIcontext *driContextPriv,
+ unsigned major_version,
+ unsigned minor_version,
+ uint32_t flags,
+ unsigned *error,
void *sharedContextPrivate);
- /**
- * Context destruction callback
- */
- void (*DestroyContext)(__DRIcontextPrivate *driContextPriv);
+ void (*DestroyContext)(__DRIcontext *driContextPriv);
- /**
- * Buffer (drawable) creation callback
- */
- GLboolean (*CreateBuffer)(__DRIscreenPrivate *driScrnPriv,
- __DRIdrawablePrivate *driDrawPriv,
- const __GLcontextModes *glVis,
+ GLboolean (*CreateBuffer)(__DRIscreen *driScrnPriv,
+ __DRIdrawable *driDrawPriv,
+ const struct gl_config *glVis,
GLboolean pixmapBuffer);
-
- /**
- * Buffer (drawable) destruction callback
- */
- void (*DestroyBuffer)(__DRIdrawablePrivate *driDrawPriv);
- /**
- * Buffer swapping callback
- */
- void (*SwapBuffers)(__DRIdrawablePrivate *driDrawPriv);
-
- /**
- * Context activation callback
- */
- GLboolean (*MakeCurrent)(__DRIcontextPrivate *driContextPriv,
- __DRIdrawablePrivate *driDrawPriv,
- __DRIdrawablePrivate *driReadPriv);
+ void (*DestroyBuffer)(__DRIdrawable *driDrawPriv);
- /**
- * Context unbinding callback
- */
- GLboolean (*UnbindContext)(__DRIcontextPrivate *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 );
+ void (*SwapBuffers)(__DRIdrawable *driDrawPriv);
+ GLboolean (*MakeCurrent)(__DRIcontext *driContextPriv,
+ __DRIdrawable *driDrawPriv,
+ __DRIdrawable *driReadPriv);
- /**
- * Required if GLX_SGI_video_sync or GLX_OML_sync_control is
- * supported.
- */
- int (*GetMSC)( __DRIscreenPrivate * priv, int64_t * count );
+ GLboolean (*UnbindContext)(__DRIcontext *driContextPriv);
- /**
- * These are required if GLX_OML_sync_control is supported.
- */
- /*@{*/
- int (*WaitForMSC)( __DRIdrawablePrivate *priv, int64_t target_msc,
- int64_t divisor, int64_t remainder,
- int64_t * msc );
- int (*WaitForSBC)( __DRIdrawablePrivate *priv, int64_t target_sbc,
- int64_t * msc, int64_t * sbc );
-
- int64_t (*SwapBuffersMSC)( __DRIdrawablePrivate *priv, int64_t target_msc,
- int64_t divisor, int64_t remainder );
- /*@}*/
- void (*CopySubBuffer)(__DRIdrawablePrivate *driDrawPriv,
- int x, int y, int w, int h);
+ __DRIbuffer *(*AllocateBuffer) (__DRIscreen *screenPrivate,
+ unsigned int attachment,
+ unsigned int format,
+ int width, int height);
- /**
- * See corresponding field in \c __DRIscreenRec.
- */
- void (*setTexOffset)(__DRIcontext *pDRICtx, GLint texname,
- unsigned long long offset, GLint depth, GLuint pitch);
+ void (*ReleaseBuffer) (__DRIscreen *screenPrivate, __DRIbuffer *buffer);
};
-
-struct __DRIswapInfoRec {
- /**
- * Number of swapBuffers operations that have been *completed*.
- */
- uint64_t swap_count;
-
- /**
- * Unadjusted system time of the last buffer swap. This is the time
- * when the swap completed, not the time when swapBuffers was called.
- */
- int64_t swap_ust;
-
- /**
- * Number of swap operations that occurred after the swap deadline. That
- * is if a swap happens more than swap_interval frames after the previous
- * swap, it has missed its deadline. If swap_interval is 0, then the
- * swap deadline is 1 frame after the previous swap.
- */
- uint64_t swap_missed_count;
-
- /**
- * Amount of time used by the last swap that missed its deadline. This
- * is calculated as (__glXGetUST() - swap_ust) / (swap_interval *
- * time_for_single_vrefresh)). If the actual value of swap_interval is
- * 0, then 1 is used instead. If swap_missed_count is non-zero, this
- * should be greater-than 1.0.
- */
- float swap_missed_usage;
-};
+extern const struct __DriverAPIRec driDriverAPI;
/**
- * Per-drawable private DRI driver information.
+ * Per-screen private driver information.
*/
-struct __DRIdrawablePrivateRec {
+struct __DRIscreenRec {
/**
- * Kernel drawable handle
+ * Current screen's number
*/
- drm_drawable_t hHWDrawable;
+ int myNum;
/**
- * Driver's private drawable information.
- *
- * This structure is opaque.
+ * File descriptor returned when the kernel device driver is opened.
+ *
+ * Used to:
+ * - authenticate client to kernel
+ * - map the frame buffer, SAREA, etc.
+ * - close the kernel device driver
*/
- void *driverPrivate;
+ int fd;
/**
- * X's drawable ID associated with this private drawable.
+ * DRM (kernel module) version information.
*/
- __DRIid draw;
- __DRIdrawable *pdraw;
+ __DRIversion drm_version;
/**
- * Reference count for number of context's currently bound to this
- * drawable.
- *
- * Once it reaches zero, the drawable can be destroyed.
- *
- * \note This behavior will change with GLX 1.3.
+ * Device-dependent private information (not stored in the SAREA).
+ *
+ * This pointer is never touched by the DRI layer.
*/
- int refcount;
+ void *driverPrivate;
- /**
- * Index of this drawable information in the SAREA.
- */
- unsigned int index;
+ void *loaderPrivate;
- /**
- * Pointer to the "drawable has changed ID" stamp in the SAREA.
- */
- unsigned int *pStamp;
+ const __DRIextension **extensions;
- /**
- * Last value of the stamp.
- *
- * If this differs from the value stored at __DRIdrawablePrivate::pStamp,
- * then the drawable information has been modified by the X server, and the
- * drawable information (below) should be retrieved from the X server.
- */
- unsigned int lastStamp;
+ const __DRIswrastLoaderExtension *swrast_loader;
- /**
- * \name Drawable
- *
- * Drawable information used in software fallbacks.
- */
- /*@{*/
- int x;
- int y;
- int w;
- int h;
- int numClipRects;
- drm_clip_rect_t *pClipRects;
- /*@}*/
+ struct {
+ /* Flag to indicate that this is a DRI2 screen. Many of the above
+ * fields will not be valid or initializaed in that case. */
+ __DRIdri2LoaderExtension *loader;
+ __DRIimageLookupExtension *image;
+ __DRIuseInvalidateExtension *useInvalidate;
+ } dri2;
- /**
- * \name Back and depthbuffer
- *
- * Information about the back and depthbuffer where different from above.
- */
- /*@{*/
- int backX;
- int backY;
- int backClipRectType;
- int numBackClipRects;
- drm_clip_rect_t *pBackClipRects;
- /*@}*/
+ driOptionCache optionInfo;
+ driOptionCache optionCache;
- /**
- * Pointer to context to which this drawable is currently bound.
- */
- __DRIcontextPrivate *driContextPriv;
-
- /**
- * Pointer to screen on which this drawable was created.
- */
- __DRIscreenPrivate *driScreenPriv;
-
- /**
- * \name Display and screen information.
- *
- * Basically just need these for when the locking code needs to call
- * \c __driUtilUpdateDrawableInfo.
- */
- /*@{*/
- __DRInativeDisplay *display;
- int screen;
- /*@}*/
-
- /**
- * Called via glXSwapBuffers().
- */
- void (*swapBuffers)( __DRIdrawablePrivate *dPriv );
+ unsigned int api_mask;
};
/**
* Per-context private driver information.
*/
-struct __DRIcontextPrivateRec {
- /**
- * Kernel context handle used to access the device lock.
- */
- __DRIid contextID;
-
- /**
- * Kernel context handle used to access the device lock.
- */
- drm_context_t hHWContext;
-
+struct __DRIcontextRec {
/**
* Device driver's private context data. This structure is opaque.
*/
void *driverPrivate;
/**
- * This context's display pointer.
+ * The loaders's private context data. This structure is opaque.
*/
- __DRInativeDisplay *display;
+ void *loaderPrivate;
/**
* 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;
+
+ struct {
+ int draw_stamp;
+ int read_stamp;
+ } dri2;
};
/**
- * Per-screen private driver information.
+ * Per-drawable private DRI driver information.
*/
-struct __DRIscreenPrivateRec {
- /**
- * Display for this screen
- */
- __DRInativeDisplay *display;
-
- /**
- * Current screen's number
- */
- int myNum;
-
- /**
- * Callback functions into the hardware-specific DRI driver code.
- */
- struct __DriverAPIRec DriverAPI;
-
+struct __DRIdrawableRec {
/**
- * \name DDX version
- * DDX / 2D driver version information.
- * \todo Replace these fields with a \c __DRIversionRec.
- */
- /*@{*/
- int ddxMajor;
- int ddxMinor;
- int ddxPatch;
- /*@}*/
-
- /**
- * \name DRI version
- * DRI X extension version information.
- * \todo Replace these fields with a \c __DRIversionRec.
- */
- /*@{*/
- int driMajor;
- int driMinor;
- int driPatch;
- /*@}*/
-
- /**
- * \name DRM version
- * DRM (kernel module) version information.
- * \todo Replace these fields with a \c __DRIversionRec.
- */
- /*@{*/
- int drmMajor;
- int drmMinor;
- int drmPatch;
- /*@}*/
-
- /**
- * ID used when the client sets the drawable lock.
+ * Driver's private drawable information.
*
- * The X server uses this value to detect if the client has died while
- * holding the drawable lock.
+ * This structure is opaque.
*/
- int drawLockID;
+ void *driverPrivate;
/**
- * File descriptor returned when the kernel device driver is opened.
- *
- * Used to:
- * - authenticate client to kernel
- * - map the frame buffer, SAREA, etc.
- * - close the kernel device driver
+ * Private data from the loader. We just hold on to it and pass
+ * it back when calling into loader provided functions.
*/
- int fd;
+ void *loaderPrivate;
/**
- * SAREA pointer
- *
- * Used to access:
- * - the device lock
- * - the device-independent per-drawable and per-context(?) information
+ * Pointer to context to which this drawable is currently bound.
*/
- drm_sarea_t *pSAREA;
+ __DRIcontext *driContextPriv;
/**
- * \name Direct frame buffer access information
- * Used for software fallbacks.
+ * Pointer to screen on which this drawable was created.
*/
- /*@{*/
- unsigned char *pFB;
- int fbSize;
- int fbOrigin;
- int fbStride;
- int fbWidth;
- int fbHeight;
- int fbBPP;
- /*@}*/
+ __DRIscreen *driScreenPriv;
/**
- * \name Device-dependent private information (stored in the SAREA).
+ * Reference count for number of context's currently bound to this
+ * drawable.
*
- * This data is accessed by the client driver only.
- */
- /*@{*/
- void *pDevPriv;
- int devPrivSize;
- /*@}*/
-
- /**
- * Dummy context to which drawables are bound when not bound to any
- * other context.
+ * Once it reaches zero, the drawable can be destroyed.
*
- * A dummy hHWContext is created for this context, and is used by the GL
- * core when a hardware lock is required but the drawable is not currently
- * bound (e.g., potentially during a SwapBuffers request). The dummy
- * context is created when the first "real" context is created on this
- * screen.
- */
- __DRIcontextPrivate dummyContextPriv;
-
- /**
- * Hash table to hold the drawable information for this screen.
+ * \note This behavior will change with GLX 1.3.
*/
- void *drawHash;
+ int refcount;
/**
- * Device-dependent private information (not stored in the SAREA).
- *
- * This pointer is never touched by the DRI layer.
+ * Last value of the stamp.
+ *
+ * If this differs from the value stored at __DRIdrawable::dri2.stamp,
+ * then the drawable information has been modified by the X server, and the
+ * drawable information (below) should be retrieved from the X server.
*/
- void *private;
+ unsigned int lastStamp;
- /**
- * GLX visuals / FBConfigs for this screen. These are stored as a
- * linked list.
- *
- * \note
- * This field is \b only used in conjunction with the old interfaces. If
- * the new interfaces are used, this field will be set to \c NULL and will
- * not be dereferenced.
- */
- __GLcontextModes *modes;
+ int w, h;
/**
- * Pointer back to the \c __DRIscreen that contains this structure.
+ * Drawable timestamp. Increased when the loader calls invalidate.
*/
-
- __DRIscreen *psc;
+ struct {
+ unsigned int stamp;
+ } dri2;
};
-
-/**
- * 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, ...);
-
+dri2InvalidateDrawable(__DRIdrawable *drawable);
extern void
-__driUtilUpdateDrawableInfo(__DRIdrawablePrivate *pdp);
-
-
-extern __DRIscreenPrivate * __driUtilCreateNewScreen( __DRInativeDisplay *dpy,
- int scrn, __DRIscreen *psc, __GLcontextModes * modes,
- const __DRIversion * ddx_version, const __DRIversion * dri_version,
- const __DRIversion * drm_version, const __DRIframebuffer * frame_buffer,
- drm_sarea_t *pSAREA, int fd, int internal_api_version,
- const struct __DriverAPIRec *driverAPI );
-
-/* Test the version of the internal GLX API. Returns a value like strcmp. */
-extern int
-driCompareGLXAPIVersion( GLint required_version );
-
-extern float
-driCalculateSwapUsage( __DRIdrawablePrivate *dPriv,
- int64_t last_swap_ust, int64_t current_ust );
-
-/**
- * Pointer to the \c __DRIinterfaceMethods passed to the driver by the loader.
- *
- * This pointer is set in the driver's \c __driCreateNewScreen function and
- * is defined in dri_util.c.
- */
-extern const __DRIinterfaceMethods * dri_interface;
+driUpdateFramebufferSize(struct gl_context *ctx, const __DRIdrawable *dPriv);
#endif /* _DRI_UTIL_H_ */