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 */
59 /* typedef Bool ( * PFNGLXGETMSCRATEOMLPROC) (Display *dpy, GLXDrawable drawable, int32_t *numerator, int32_t *denominator); */
60 #include "drm.h" /* for drm_clip_rect_t */
61 #include "sarea.h" /* for XF86DRISAREAPtr */
62 #include "GL/internal/glcore.h" /* for __GLcontextModes */
65 typedef struct __DRIdisplayPrivateRec __DRIdisplayPrivate
;
66 typedef struct __DRIscreenPrivateRec __DRIscreenPrivate
;
67 typedef struct __DRIcontextPrivateRec __DRIcontextPrivate
;
68 typedef struct __DRIdrawablePrivateRec __DRIdrawablePrivate
;
69 typedef struct __DRIswapInfoRec __DRIswapInfo
;
73 * Used by DRI_VALIDATE_DRAWABLE_INFO
75 #define DRI_VALIDATE_DRAWABLE_INFO_ONCE(pDrawPriv) \
77 if (*(pDrawPriv->pStamp) != pDrawPriv->lastStamp) { \
78 __driUtilUpdateDrawableInfo(pDrawPriv); \
84 * Utility macro to validate the drawable information.
86 * See __DRIdrawablePrivate::pStamp and __DRIdrawablePrivate::lastStamp.
88 #define DRI_VALIDATE_DRAWABLE_INFO(psp, pdp) \
90 while (*(pdp->pStamp) != pdp->lastStamp) { \
91 DRM_UNLOCK(psp->fd, &psp->pSAREA->lock, \
92 pdp->driContextPriv->hHWContext); \
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, \
99 pdp->driContextPriv->hHWContext); \
105 * Driver callback functions.
107 * Each DRI driver must have one of these structures with all the pointers set
108 * to appropriate functions within the driver.
110 * When glXCreateContext() is called, for example, it'll call a helper function
111 * dri_util.c which in turn will jump through the \a CreateContext pointer in
114 struct __DriverAPIRec
{
116 * Driver initialization callback
118 GLboolean (*InitDriver
)(__DRIscreenPrivate
*driScrnPriv
);
121 * Screen destruction callback
123 void (*DestroyScreen
)(__DRIscreenPrivate
*driScrnPriv
);
126 * Context creation callback
128 GLboolean (*CreateContext
)(const __GLcontextModes
*glVis
,
129 __DRIcontextPrivate
*driContextPriv
,
130 void *sharedContextPrivate
);
133 * Context destruction callback
135 void (*DestroyContext
)(__DRIcontextPrivate
*driContextPriv
);
138 * Buffer (drawable) creation callback
140 GLboolean (*CreateBuffer
)(__DRIscreenPrivate
*driScrnPriv
,
141 __DRIdrawablePrivate
*driDrawPriv
,
142 const __GLcontextModes
*glVis
,
143 GLboolean pixmapBuffer
);
146 * Buffer (drawable) destruction callback
148 void (*DestroyBuffer
)(__DRIdrawablePrivate
*driDrawPriv
);
151 * Buffer swapping callback
153 void (*SwapBuffers
)(__DRIdrawablePrivate
*driDrawPriv
);
156 * Context activation callback
158 GLboolean (*MakeCurrent
)(__DRIcontextPrivate
*driContextPriv
,
159 __DRIdrawablePrivate
*driDrawPriv
,
160 __DRIdrawablePrivate
*driReadPriv
);
163 * Context unbinding callback
165 GLboolean (*UnbindContext
)(__DRIcontextPrivate
*driContextPriv
);
168 * Full screen mode opening callback.
171 * Full screen functionality is no longer used by DRI. Drivers should
172 * simply install a function returning \c GL_TRUE for backwards
176 * Nothing calls this function anymore. Since this data structure is only
177 * accessed with in the driver (i.e., libGL never sees it), we need to
178 * remove the other cases that set this field and remove the field.
180 GLboolean (*OpenFullScreen
)(__DRIcontextPrivate
*driContextPriv
);
183 * Full screen mode closing callback.
186 * Full screen functionality is no longer used by DRI. Drivers should
187 * simply install a function returning \c GL_TRUE for backwards
191 * Nothing calls this function anymore. Since this data structure is only
192 * accessed with in the driver (i.e., libGL never sees it), we need to
193 * remove the other cases that set this field and remove the field.
195 GLboolean (*CloseFullScreen
)(__DRIcontextPrivate
*driContextPriv
);
198 * Retrieves statistics about buffer swap operations. Required if
199 * GLX_OML_sync_control or GLX_MESA_swap_frame_usage is supported.
201 int (*GetSwapInfo
)( __DRIdrawablePrivate
*dPriv
, __DRIswapInfo
* sInfo
);
205 * Required if GLX_SGI_video_sync or GLX_OML_sync_control is
208 int (*GetMSC
)( __DRIscreenPrivate
* priv
, int64_t * count
);
211 * These are required if GLX_OML_sync_control is supported.
214 int (*WaitForMSC
)( __DRIdrawablePrivate
*priv
, int64_t target_msc
,
215 int64_t divisor
, int64_t remainder
,
217 int (*WaitForSBC
)( __DRIdrawablePrivate
*priv
, int64_t target_sbc
,
218 int64_t * msc
, int64_t * sbc
);
220 int64_t (*SwapBuffersMSC
)( __DRIdrawablePrivate
*priv
, int64_t target_msc
,
221 int64_t divisor
, int64_t remainder
);
226 struct __DRIswapInfoRec
{
228 * Number of swapBuffers operations that have been *completed*.
233 * Unadjusted system time of the last buffer swap. This is the time
234 * when the swap completed, not the time when swapBuffers was called.
239 * Number of swap operations that occurred after the swap deadline. That
240 * is if a swap happens more than swap_interval frames after the previous
241 * swap, it has missed its deadline. If swap_interval is 0, then the
242 * swap deadline is 1 frame after the previous swap.
244 uint64_t swap_missed_count
;
247 * Amount of time used by the last swap that missed its deadline. This
248 * is calculated as (__glXGetUST() - swap_ust) / (swap_interval *
249 * time_for_single_vrefresh)). If the actual value of swap_interval is
250 * 0, then 1 is used instead. If swap_missed_count is non-zero, this
251 * should be greater-than 1.0.
253 float swap_missed_usage
;
258 * Per-drawable private DRI driver information.
260 struct __DRIdrawablePrivateRec
{
262 * Kernel drawable handle
264 drmDrawable hHWDrawable
;
267 * Driver's private drawable information.
269 * This structure is opaque.
274 * X's drawable ID associated with this private drawable.
277 __DRIdrawable
*pdraw
;
280 * Reference count for number of context's currently bound to this
283 * Once it reaches zero, the drawable can be destroyed.
285 * \note This behavior will change with GLX 1.3.
290 * Index of this drawable information in the SAREA.
295 * Pointer to the "drawable has changed ID" stamp in the SAREA.
297 unsigned int *pStamp
;
300 * Last value of the stamp.
302 * If this differs from the value stored at __DRIdrawablePrivate::pStamp,
303 * then the drawable information has been modified by the X server, and the
304 * drawable information (below) should be retrieved from the X server.
306 unsigned int lastStamp
;
311 * Drawable information used in software fallbacks.
319 drm_clip_rect_t
*pClipRects
;
323 * \name Back and depthbuffer
325 * Information about the back and depthbuffer where different from above.
330 int backClipRectType
;
331 int numBackClipRects
;
332 drm_clip_rect_t
*pBackClipRects
;
336 * Pointer to context to which this drawable is currently bound.
338 __DRIcontextPrivate
*driContextPriv
;
341 * Pointer to screen on which this drawable was created.
343 __DRIscreenPrivate
*driScreenPriv
;
346 * \name Display and screen information.
348 * Basically just need these for when the locking code needs to call
349 * __driUtilUpdateDrawableInfo() which calls XF86DRIGetDrawableInfo().
352 __DRInativeDisplay
*display
;
357 * Called via glXSwapBuffers().
359 void (*swapBuffers
)( __DRIdrawablePrivate
*dPriv
);
362 * Get information about the location, size, and clip rects of the
363 * drawable within the display.
365 PFNGLXGETDRAWABLEINFOPROC getInfo
;
369 * Per-context private driver information.
371 struct __DRIcontextPrivateRec
{
373 * Kernel context handle used to access the device lock.
378 * Kernel context handle used to access the device lock.
380 drmContext hHWContext
;
383 * Device driver's private context data. This structure is opaque.
388 * This context's display pointer.
390 __DRInativeDisplay
*display
;
393 * Pointer to drawable currently bound to this context.
395 __DRIdrawablePrivate
*driDrawablePriv
;
398 * Pointer to screen on which this context was created.
400 __DRIscreenPrivate
*driScreenPriv
;
404 * Per-screen private driver information.
406 struct __DRIscreenPrivateRec
{
408 * Display for this screen
410 __DRInativeDisplay
*display
;
413 * Current screen's number
418 * Callback functions into the hardware-specific DRI driver code.
420 struct __DriverAPIRec DriverAPI
;
424 * DDX / 2D driver version information.
425 * \todo Replace these fields with a \c __DRIversionRec.
435 * DRI X extension version information.
436 * \todo Replace these fields with a \c __DRIversionRec.
446 * DRM (kernel module) version information.
447 * \todo Replace these fields with a \c __DRIversionRec.
456 * ID used when the client sets the drawable lock.
458 * The X server uses this value to detect if the client has died while
459 * holding the drawable lock.
464 * File descriptor returned when the kernel device driver is opened.
467 * - authenticate client to kernel
468 * - map the frame buffer, SAREA, etc.
469 * - close the kernel device driver
478 * - the device-independent per-drawable and per-context(?) information
480 XF86DRISAREAPtr pSAREA
;
483 * \name Direct frame buffer access information
484 * Used for software fallbacks.
497 * \name Device-dependent private information (stored in the SAREA).
499 * This data is accessed by the client driver only.
507 * Dummy context to which drawables are bound when not bound to any
510 * A dummy hHWContext is created for this context, and is used by the GL
511 * core when a hardware lock is required but the drawable is not currently
512 * bound (e.g., potentially during a SwapBuffers request). The dummy
513 * context is created when the first "real" context is created on this
516 __DRIcontextPrivate dummyContextPriv
;
519 * Hash table to hold the drawable information for this screen.
524 * Device-dependent private information (not stored in the SAREA).
526 * This pointer is never touched by the DRI layer.
531 * GLX visuals / FBConfigs for this screen. These are stored as a
535 * This field is \b only used in conjunction with the old interfaces. If
536 * the new interfaces are used, this field will be set to \c NULL and will
537 * not be dereferenced.
539 __GLcontextModes
*modes
;
542 * Pointer back to the \c __DRIscreen that contains this structure.
551 __driUtilMessage(const char *f
, ...);
555 __driUtilUpdateDrawableInfo(__DRIdrawablePrivate
*pdp
);
558 extern __DRIscreenPrivate
* __driUtilCreateNewScreen( __DRInativeDisplay
*dpy
,
559 int scrn
, __DRIscreen
*psc
, __GLcontextModes
* modes
,
560 const __DRIversion
* ddx_version
, const __DRIversion
* dri_version
,
561 const __DRIversion
* drm_version
, const __DRIframebuffer
* frame_buffer
,
562 drmAddress pSAREA
, int fd
, int internal_api_version
,
563 const struct __DriverAPIRec
*driverAPI
);
565 #ifndef DRI_NEW_INTERFACE_ONLY
566 extern __DRIscreenPrivate
*
567 __driUtilCreateScreen(Display
*dpy
, int scrn
, __DRIscreen
*psc
,
568 int numConfigs
, __GLXvisualConfig
*config
,
569 const struct __DriverAPIRec
*driverAPI
);
570 #endif /* DRI_NEW_INTERFACE_ONLY */
572 /* Test the version of the internal GLX API. Returns a value like strcmp. */
574 driCompareGLXAPIVersion( GLuint required_version
);
577 driCalculateSwapUsage( __DRIdrawablePrivate
*dPriv
,
578 int64_t last_swap_ust
, int64_t current_ust
);
580 #endif /* GLX_DIRECT_RENDERING */
582 #endif /* _DRI_UTIL_H_ */