1 /* $XFree86: xc/lib/GL/dri/dri_util.h,v 1.1 2002/02/22 21:32:52 dawes Exp $ */
4 * DRI utility functions definitions.
6 * This module acts as glue between GLX and the actual hardware driver. A DRI
7 * driver doesn't really \e have to use any of this - it's optional. But, some
8 * useful stuff is done here that otherwise would have to be duplicated in most
11 * Basically, these utility functions take care of some of the dirty details of
12 * screen initialization, context creation, context binding, DRM setup, etc.
14 * These functions are compiled into each DRI driver so libGL.so knows nothing
19 * \author Kevin E. Martin <kevin@precisioninsight.com>
20 * \author Brian Paul <brian@precisioninsight.com>
24 * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
25 * All Rights Reserved.
27 * Permission is hereby granted, free of charge, to any person obtaining a
28 * copy of this software and associated documentation files (the
29 * "Software"), to deal in the Software without restriction, including
30 * without limitation the rights to use, copy, modify, merge, publish,
31 * distribute, sub license, and/or sell copies of the Software, and to
32 * permit persons to whom the Software is furnished to do so, subject to
33 * the following conditions:
35 * The above copyright notice and this permission notice (including the
36 * next paragraph) shall be included in all copies or substantial portions
39 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
40 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
41 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
42 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
43 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
44 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
45 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
52 #define CAPI /* XXX this should be globally defined somewhere */
56 #include "drm_sarea.h"
58 #include "GL/internal/glcore.h"
59 #include "GL/internal/dri_interface.h"
61 #define GLX_BAD_CONTEXT 5
63 typedef struct __DRIdisplayPrivateRec __DRIdisplayPrivate
;
64 typedef struct __DRIscreenPrivateRec __DRIscreenPrivate
;
65 typedef struct __DRIcontextPrivateRec __DRIcontextPrivate
;
66 typedef struct __DRIdrawablePrivateRec __DRIdrawablePrivate
;
67 typedef struct __DRIswapInfoRec __DRIswapInfo
;
68 typedef struct __DRIutilversionRec2 __DRIutilversion2
;
72 * Used by DRI_VALIDATE_DRAWABLE_INFO
74 #define DRI_VALIDATE_DRAWABLE_INFO_ONCE(pDrawPriv) \
76 if (*(pDrawPriv->pStamp) != pDrawPriv->lastStamp) { \
77 __driUtilUpdateDrawableInfo(pDrawPriv); \
83 * Utility macro to validate the drawable information.
85 * See __DRIdrawablePrivate::pStamp and __DRIdrawablePrivate::lastStamp.
87 #define DRI_VALIDATE_DRAWABLE_INFO(psp, pdp) \
89 while (*(pdp->pStamp) != pdp->lastStamp) { \
90 register unsigned int hwContext = psp->pSAREA->lock.lock & \
91 ~(DRM_LOCK_HELD | DRM_LOCK_CONT); \
92 DRM_UNLOCK(psp->fd, &psp->pSAREA->lock, hwContext); \
94 DRM_SPINLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID); \
95 DRI_VALIDATE_DRAWABLE_INFO_ONCE(pdp); \
96 DRM_SPINUNLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID); \
98 DRM_LIGHT_LOCK(psp->fd, &psp->pSAREA->lock, hwContext); \
104 * Driver callback functions.
106 * Each DRI driver must have one of these structures with all the pointers set
107 * to appropriate functions within the driver.
109 * When glXCreateContext() is called, for example, it'll call a helper function
110 * dri_util.c which in turn will jump through the \a CreateContext pointer in
113 struct __DriverAPIRec
{
115 * Driver initialization callback
117 GLboolean (*InitDriver
)(__DRIscreenPrivate
*driScrnPriv
);
120 * Screen destruction callback
122 void (*DestroyScreen
)(__DRIscreenPrivate
*driScrnPriv
);
125 * Context creation callback
127 GLboolean (*CreateContext
)(const __GLcontextModes
*glVis
,
128 __DRIcontextPrivate
*driContextPriv
,
129 void *sharedContextPrivate
);
132 * Context destruction callback
134 void (*DestroyContext
)(__DRIcontextPrivate
*driContextPriv
);
137 * Buffer (drawable) creation callback
139 GLboolean (*CreateBuffer
)(__DRIscreenPrivate
*driScrnPriv
,
140 __DRIdrawablePrivate
*driDrawPriv
,
141 const __GLcontextModes
*glVis
,
142 GLboolean pixmapBuffer
);
145 * Buffer (drawable) destruction callback
147 void (*DestroyBuffer
)(__DRIdrawablePrivate
*driDrawPriv
);
150 * Buffer swapping callback
152 void (*SwapBuffers
)(__DRIdrawablePrivate
*driDrawPriv
);
155 * Context activation callback
157 GLboolean (*MakeCurrent
)(__DRIcontextPrivate
*driContextPriv
,
158 __DRIdrawablePrivate
*driDrawPriv
,
159 __DRIdrawablePrivate
*driReadPriv
);
162 * Context unbinding callback
164 GLboolean (*UnbindContext
)(__DRIcontextPrivate
*driContextPriv
);
167 * Retrieves statistics about buffer swap operations. Required if
168 * GLX_OML_sync_control or GLX_MESA_swap_frame_usage is supported.
170 int (*GetSwapInfo
)( __DRIdrawablePrivate
*dPriv
, __DRIswapInfo
* sInfo
);
174 * Required if GLX_SGI_video_sync or GLX_OML_sync_control is
177 int (*GetMSC
)( __DRIscreenPrivate
* priv
, int64_t * count
);
180 * These are required if GLX_OML_sync_control is supported.
183 int (*WaitForMSC
)( __DRIdrawablePrivate
*priv
, int64_t target_msc
,
184 int64_t divisor
, int64_t remainder
,
186 int (*WaitForSBC
)( __DRIdrawablePrivate
*priv
, int64_t target_sbc
,
187 int64_t * msc
, int64_t * sbc
);
189 int64_t (*SwapBuffersMSC
)( __DRIdrawablePrivate
*priv
, int64_t target_msc
,
190 int64_t divisor
, int64_t remainder
);
192 void (*CopySubBuffer
)(__DRIdrawablePrivate
*driDrawPriv
,
193 int x
, int y
, int w
, int h
);
197 struct __DRIswapInfoRec
{
199 * Number of swapBuffers operations that have been *completed*.
201 u_int64_t swap_count
;
204 * Unadjusted system time of the last buffer swap. This is the time
205 * when the swap completed, not the time when swapBuffers was called.
210 * Number of swap operations that occurred after the swap deadline. That
211 * is if a swap happens more than swap_interval frames after the previous
212 * swap, it has missed its deadline. If swap_interval is 0, then the
213 * swap deadline is 1 frame after the previous swap.
215 u_int64_t swap_missed_count
;
218 * Amount of time used by the last swap that missed its deadline. This
219 * is calculated as (__glXGetUST() - swap_ust) / (swap_interval *
220 * time_for_single_vrefresh)). If the actual value of swap_interval is
221 * 0, then 1 is used instead. If swap_missed_count is non-zero, this
222 * should be greater-than 1.0.
224 float swap_missed_usage
;
229 * Per-drawable private DRI driver information.
231 struct __DRIdrawablePrivateRec
{
233 * Kernel drawable handle
235 drm_drawable_t hHWDrawable
;
238 * Driver's private drawable information.
240 * This structure is opaque.
245 * X's drawable ID associated with this private drawable.
248 __DRIdrawable
*pdraw
;
251 * Reference count for number of context's currently bound to this
254 * Once it reaches zero, the drawable can be destroyed.
256 * \note This behavior will change with GLX 1.3.
261 * Index of this drawable information in the SAREA.
266 * Pointer to the "drawable has changed ID" stamp in the SAREA.
268 unsigned int *pStamp
;
271 * Last value of the stamp.
273 * If this differs from the value stored at __DRIdrawablePrivate::pStamp,
274 * then the drawable information has been modified by the X server, and the
275 * drawable information (below) should be retrieved from the X server.
277 unsigned int lastStamp
;
282 * Drawable information used in software fallbacks.
290 drm_clip_rect_t
*pClipRects
;
294 * \name Back and depthbuffer
296 * Information about the back and depthbuffer where different from above.
301 int backClipRectType
;
302 int numBackClipRects
;
303 drm_clip_rect_t
*pBackClipRects
;
307 * Pointer to context to which this drawable is currently bound.
309 __DRIcontextPrivate
*driContextPriv
;
312 * Pointer to screen on which this drawable was created.
314 __DRIscreenPrivate
*driScreenPriv
;
317 * \name Display and screen information.
319 * Basically just need these for when the locking code needs to call
320 * \c __driUtilUpdateDrawableInfo.
323 __DRInativeDisplay
*display
;
328 * Called via glXSwapBuffers().
330 void (*swapBuffers
)( __DRIdrawablePrivate
*dPriv
);
334 * Per-context private driver information.
336 struct __DRIcontextPrivateRec
{
338 * Kernel context handle used to access the device lock.
343 * Kernel context handle used to access the device lock.
345 drm_context_t hHWContext
;
348 * Device driver's private context data. This structure is opaque.
353 * This context's display pointer.
355 __DRInativeDisplay
*display
;
358 * Pointer to drawable currently bound to this context for drawing.
360 __DRIdrawablePrivate
*driDrawablePriv
;
363 * Pointer to drawable currently bound to this context for reading.
365 __DRIdrawablePrivate
*driReadablePriv
;
368 * Pointer to screen on which this context was created.
370 __DRIscreenPrivate
*driScreenPriv
;
374 * Per-screen private driver information.
376 struct __DRIscreenPrivateRec
{
378 * Display for this screen
380 __DRInativeDisplay
*display
;
383 * Current screen's number
388 * Callback functions into the hardware-specific DRI driver code.
390 struct __DriverAPIRec DriverAPI
;
394 * DDX / 2D driver version information.
395 * \todo Replace these fields with a \c __DRIversionRec.
405 * DRI X extension version information.
406 * \todo Replace these fields with a \c __DRIversionRec.
416 * DRM (kernel module) version information.
417 * \todo Replace these fields with a \c __DRIversionRec.
426 * ID used when the client sets the drawable lock.
428 * The X server uses this value to detect if the client has died while
429 * holding the drawable lock.
434 * File descriptor returned when the kernel device driver is opened.
437 * - authenticate client to kernel
438 * - map the frame buffer, SAREA, etc.
439 * - close the kernel device driver
448 * - the device-independent per-drawable and per-context(?) information
453 * \name Direct frame buffer access information
454 * Used for software fallbacks.
467 * \name Device-dependent private information (stored in the SAREA).
469 * This data is accessed by the client driver only.
477 * Dummy context to which drawables are bound when not bound to any
480 * A dummy hHWContext is created for this context, and is used by the GL
481 * core when a hardware lock is required but the drawable is not currently
482 * bound (e.g., potentially during a SwapBuffers request). The dummy
483 * context is created when the first "real" context is created on this
486 __DRIcontextPrivate dummyContextPriv
;
489 * Hash table to hold the drawable information for this screen.
494 * Device-dependent private information (not stored in the SAREA).
496 * This pointer is never touched by the DRI layer.
501 * GLX visuals / FBConfigs for this screen. These are stored as a
505 * This field is \b only used in conjunction with the old interfaces. If
506 * the new interfaces are used, this field will be set to \c NULL and will
507 * not be dereferenced.
509 __GLcontextModes
*modes
;
512 * Pointer back to the \c __DRIscreen that contains this structure.
520 * Used to store a version which includes a major range instead of a single
521 * major version number.
523 struct __DRIutilversionRec2
{
524 int major_min
; /** min allowed Major version number. */
525 int major_max
; /** max allowed Major version number. */
526 int minor
; /**< Minor version number. */
527 int patch
; /**< Patch-level. */
532 __driUtilMessage(const char *f
, ...);
536 __driUtilUpdateDrawableInfo(__DRIdrawablePrivate
*pdp
);
539 extern __DRIscreenPrivate
* __driUtilCreateNewScreen( __DRInativeDisplay
*dpy
,
540 int scrn
, __DRIscreen
*psc
, __GLcontextModes
* modes
,
541 const __DRIversion
* ddx_version
, const __DRIversion
* dri_version
,
542 const __DRIversion
* drm_version
, const __DRIframebuffer
* frame_buffer
,
543 drm_sarea_t
*pSAREA
, int fd
, int internal_api_version
,
544 const struct __DriverAPIRec
*driverAPI
);
546 /* Test the version of the internal GLX API. Returns a value like strcmp. */
548 driCompareGLXAPIVersion( GLint required_version
);
551 driCalculateSwapUsage( __DRIdrawablePrivate
*dPriv
,
552 int64_t last_swap_ust
, int64_t current_ust
);
555 * Pointer to the \c __DRIinterfaceMethods passed to the driver by the loader.
557 * This pointer is set in the driver's \c __driCreateNewScreen function and
558 * is defined in dri_util.c.
560 extern const __DRIinterfaceMethods
* dri_interface
;
562 #endif /* _DRI_UTIL_H_ */