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 #ifdef GLX_DIRECT_RENDERING
54 #define CAPI /* XXX this should be globally defined somewhere */
57 #include "glxclient.h" /* for GLXDrawable */
58 #include "drm.h" /* for drm_clip_rect_t */
59 #include "drm_sarea.h" /* for XF86DRISAREAPtr */
60 #include "GL/internal/glcore.h" /* for __GLcontextModes */
62 /* This is a temporary relic. Once all drivers are converted to support
63 * the new interface, it can go away.
65 #ifdef DRI_NEW_INTERFACE_ONLY
66 #define USE_NEW_INTERFACE
69 typedef struct __DRIdisplayPrivateRec __DRIdisplayPrivate
;
70 typedef struct __DRIscreenPrivateRec __DRIscreenPrivate
;
71 typedef struct __DRIcontextPrivateRec __DRIcontextPrivate
;
72 typedef struct __DRIdrawablePrivateRec __DRIdrawablePrivate
;
73 typedef struct __DRIswapInfoRec __DRIswapInfo
;
77 * Used by DRI_VALIDATE_DRAWABLE_INFO
79 #define DRI_VALIDATE_DRAWABLE_INFO_ONCE(pDrawPriv) \
81 if (*(pDrawPriv->pStamp) != pDrawPriv->lastStamp) { \
82 __driUtilUpdateDrawableInfo(pDrawPriv); \
88 * Utility macro to validate the drawable information.
90 * See __DRIdrawablePrivate::pStamp and __DRIdrawablePrivate::lastStamp.
92 #define DRI_VALIDATE_DRAWABLE_INFO(psp, pdp) \
94 while (*(pdp->pStamp) != pdp->lastStamp) { \
95 DRM_UNLOCK(psp->fd, &psp->pSAREA->lock, \
96 pdp->driContextPriv->hHWContext); \
98 DRM_SPINLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID); \
99 DRI_VALIDATE_DRAWABLE_INFO_ONCE(pdp); \
100 DRM_SPINUNLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID); \
102 DRM_LIGHT_LOCK(psp->fd, &psp->pSAREA->lock, \
103 pdp->driContextPriv->hHWContext); \
109 * Driver callback functions.
111 * Each DRI driver must have one of these structures with all the pointers set
112 * to appropriate functions within the driver.
114 * When glXCreateContext() is called, for example, it'll call a helper function
115 * dri_util.c which in turn will jump through the \a CreateContext pointer in
118 struct __DriverAPIRec
{
120 * Driver initialization callback
122 GLboolean (*InitDriver
)(__DRIscreenPrivate
*driScrnPriv
);
125 * Screen destruction callback
127 void (*DestroyScreen
)(__DRIscreenPrivate
*driScrnPriv
);
130 * Context creation callback
132 GLboolean (*CreateContext
)(const __GLcontextModes
*glVis
,
133 __DRIcontextPrivate
*driContextPriv
,
134 void *sharedContextPrivate
);
137 * Context destruction callback
139 void (*DestroyContext
)(__DRIcontextPrivate
*driContextPriv
);
142 * Buffer (drawable) creation callback
144 GLboolean (*CreateBuffer
)(__DRIscreenPrivate
*driScrnPriv
,
145 __DRIdrawablePrivate
*driDrawPriv
,
146 const __GLcontextModes
*glVis
,
147 GLboolean pixmapBuffer
);
150 * Buffer (drawable) destruction callback
152 void (*DestroyBuffer
)(__DRIdrawablePrivate
*driDrawPriv
);
155 * Buffer swapping callback
157 void (*SwapBuffers
)(__DRIdrawablePrivate
*driDrawPriv
);
160 * Context activation callback
162 GLboolean (*MakeCurrent
)(__DRIcontextPrivate
*driContextPriv
,
163 __DRIdrawablePrivate
*driDrawPriv
,
164 __DRIdrawablePrivate
*driReadPriv
);
167 * Context unbinding callback
169 GLboolean (*UnbindContext
)(__DRIcontextPrivate
*driContextPriv
);
172 * Retrieves statistics about buffer swap operations. Required if
173 * GLX_OML_sync_control or GLX_MESA_swap_frame_usage is supported.
175 int (*GetSwapInfo
)( __DRIdrawablePrivate
*dPriv
, __DRIswapInfo
* sInfo
);
179 * Required if GLX_SGI_video_sync or GLX_OML_sync_control is
182 int (*GetMSC
)( __DRIscreenPrivate
* priv
, int64_t * count
);
185 * These are required if GLX_OML_sync_control is supported.
188 int (*WaitForMSC
)( __DRIdrawablePrivate
*priv
, int64_t target_msc
,
189 int64_t divisor
, int64_t remainder
,
191 int (*WaitForSBC
)( __DRIdrawablePrivate
*priv
, int64_t target_sbc
,
192 int64_t * msc
, int64_t * sbc
);
194 int64_t (*SwapBuffersMSC
)( __DRIdrawablePrivate
*priv
, int64_t target_msc
,
195 int64_t divisor
, int64_t remainder
);
200 struct __DRIswapInfoRec
{
202 * Number of swapBuffers operations that have been *completed*.
207 * Unadjusted system time of the last buffer swap. This is the time
208 * when the swap completed, not the time when swapBuffers was called.
213 * Number of swap operations that occurred after the swap deadline. That
214 * is if a swap happens more than swap_interval frames after the previous
215 * swap, it has missed its deadline. If swap_interval is 0, then the
216 * swap deadline is 1 frame after the previous swap.
218 uint64_t swap_missed_count
;
221 * Amount of time used by the last swap that missed its deadline. This
222 * is calculated as (__glXGetUST() - swap_ust) / (swap_interval *
223 * time_for_single_vrefresh)). If the actual value of swap_interval is
224 * 0, then 1 is used instead. If swap_missed_count is non-zero, this
225 * should be greater-than 1.0.
227 float swap_missed_usage
;
232 * Per-drawable private DRI driver information.
234 struct __DRIdrawablePrivateRec
{
236 * Kernel drawable handle
238 drm_drawable_t hHWDrawable
;
241 * Driver's private drawable information.
243 * This structure is opaque.
248 * X's drawable ID associated with this private drawable.
251 __DRIdrawable
*pdraw
;
254 * Reference count for number of context's currently bound to this
257 * Once it reaches zero, the drawable can be destroyed.
259 * \note This behavior will change with GLX 1.3.
264 * Index of this drawable information in the SAREA.
269 * Pointer to the "drawable has changed ID" stamp in the SAREA.
271 unsigned int *pStamp
;
274 * Last value of the stamp.
276 * If this differs from the value stored at __DRIdrawablePrivate::pStamp,
277 * then the drawable information has been modified by the X server, and the
278 * drawable information (below) should be retrieved from the X server.
280 unsigned int lastStamp
;
285 * Drawable information used in software fallbacks.
293 drm_clip_rect_t
*pClipRects
;
297 * \name Back and depthbuffer
299 * Information about the back and depthbuffer where different from above.
304 int backClipRectType
;
305 int numBackClipRects
;
306 drm_clip_rect_t
*pBackClipRects
;
310 * Pointer to context to which this drawable is currently bound.
312 __DRIcontextPrivate
*driContextPriv
;
315 * Pointer to screen on which this drawable was created.
317 __DRIscreenPrivate
*driScreenPriv
;
320 * \name Display and screen information.
322 * Basically just need these for when the locking code needs to call
323 * __driUtilUpdateDrawableInfo() which calls XF86DRIGetDrawableInfo().
326 __DRInativeDisplay
*display
;
331 * Called via glXSwapBuffers().
333 void (*swapBuffers
)( __DRIdrawablePrivate
*dPriv
);
336 * Get information about the location, size, and clip rects of the
337 * drawable within the display.
339 PFNGLXGETDRAWABLEINFOPROC getInfo
;
343 * Per-context private driver information.
345 struct __DRIcontextPrivateRec
{
347 * Kernel context handle used to access the device lock.
352 * Kernel context handle used to access the device lock.
354 drm_context_t hHWContext
;
357 * Device driver's private context data. This structure is opaque.
362 * This context's display pointer.
364 __DRInativeDisplay
*display
;
367 * Pointer to drawable currently bound to this context.
369 __DRIdrawablePrivate
*driDrawablePriv
;
372 * Pointer to screen on which this context was created.
374 __DRIscreenPrivate
*driScreenPriv
;
378 * Per-screen private driver information.
380 struct __DRIscreenPrivateRec
{
382 * Display for this screen
384 __DRInativeDisplay
*display
;
387 * Current screen's number
392 * Callback functions into the hardware-specific DRI driver code.
394 struct __DriverAPIRec DriverAPI
;
398 * DDX / 2D driver version information.
399 * \todo Replace these fields with a \c __DRIversionRec.
409 * DRI X extension version information.
410 * \todo Replace these fields with a \c __DRIversionRec.
420 * DRM (kernel module) version information.
421 * \todo Replace these fields with a \c __DRIversionRec.
430 * ID used when the client sets the drawable lock.
432 * The X server uses this value to detect if the client has died while
433 * holding the drawable lock.
438 * File descriptor returned when the kernel device driver is opened.
441 * - authenticate client to kernel
442 * - map the frame buffer, SAREA, etc.
443 * - close the kernel device driver
452 * - the device-independent per-drawable and per-context(?) information
457 * \name Direct frame buffer access information
458 * Used for software fallbacks.
471 * \name Device-dependent private information (stored in the SAREA).
473 * This data is accessed by the client driver only.
481 * Dummy context to which drawables are bound when not bound to any
484 * A dummy hHWContext is created for this context, and is used by the GL
485 * core when a hardware lock is required but the drawable is not currently
486 * bound (e.g., potentially during a SwapBuffers request). The dummy
487 * context is created when the first "real" context is created on this
490 __DRIcontextPrivate dummyContextPriv
;
493 * Hash table to hold the drawable information for this screen.
498 * Device-dependent private information (not stored in the SAREA).
500 * This pointer is never touched by the DRI layer.
505 * GLX visuals / FBConfigs for this screen. These are stored as a
509 * This field is \b only used in conjunction with the old interfaces. If
510 * the new interfaces are used, this field will be set to \c NULL and will
511 * not be dereferenced.
513 __GLcontextModes
*modes
;
516 * Pointer back to the \c __DRIscreen that contains this structure.
525 __driUtilMessage(const char *f
, ...);
529 __driUtilUpdateDrawableInfo(__DRIdrawablePrivate
*pdp
);
532 extern __DRIscreenPrivate
* __driUtilCreateNewScreen( __DRInativeDisplay
*dpy
,
533 int scrn
, __DRIscreen
*psc
, __GLcontextModes
* modes
,
534 const __DRIversion
* ddx_version
, const __DRIversion
* dri_version
,
535 const __DRIversion
* drm_version
, const __DRIframebuffer
* frame_buffer
,
536 drm_sarea_t
*pSAREA
, int fd
, int internal_api_version
,
537 const struct __DriverAPIRec
*driverAPI
);
539 #ifndef DRI_NEW_INTERFACE_ONLY
540 extern __DRIscreenPrivate
*
541 __driUtilCreateScreen(Display
*dpy
, int scrn
, __DRIscreen
*psc
,
542 int numConfigs
, __GLXvisualConfig
*config
,
543 const struct __DriverAPIRec
*driverAPI
);
544 #endif /* DRI_NEW_INTERFACE_ONLY */
546 /* Test the version of the internal GLX API. Returns a value like strcmp. */
548 driCompareGLXAPIVersion( GLuint required_version
);
551 driCalculateSwapUsage( __DRIdrawablePrivate
*dPriv
,
552 int64_t last_swap_ust
, int64_t current_ust
);
554 #endif /* GLX_DIRECT_RENDERING */
556 #endif /* _DRI_UTIL_H_ */