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
;
257 typedef Bool (GetDrawableInfo
)( Display
*dpy
, int scrn
, Drawable draw
,
258 unsigned int * index
, unsigned int * stamp
,
259 int * x
, int * y
, int * width
, int * height
,
260 int * numClipRects
, drm_clip_rect_t
* pClipRects
,
261 int * backX
, int * backY
,
262 int * numBackClipRects
, drm_clip_rect_t
* pBackClipRects
);
266 * Per-drawable private DRI driver information.
268 struct __DRIdrawablePrivateRec
{
270 * Kernel drawable handle
272 drmDrawable hHWDrawable
;
275 * Driver's private drawable information.
277 * This structure is opaque.
282 * X's drawable ID associated with this private drawable.
285 __DRIdrawable
*pdraw
;
288 * Reference count for number of context's currently bound to this
291 * Once it reaches zero, the drawable can be destroyed.
293 * \note This behavior will change with GLX 1.3.
298 * Index of this drawable information in the SAREA.
303 * Pointer to the "drawable has changed ID" stamp in the SAREA.
305 unsigned int *pStamp
;
308 * Last value of the stamp.
310 * If this differs from the value stored at __DRIdrawablePrivate::pStamp,
311 * then the drawable information has been modified by the X server, and the
312 * drawable information (below) should be retrieved from the X server.
314 unsigned int lastStamp
;
319 * Drawable information used in software fallbacks.
327 drm_clip_rect_t
*pClipRects
;
331 * \name Back and depthbuffer
333 * Information about the back and depthbuffer where different from above.
338 int backClipRectType
;
339 int numBackClipRects
;
340 drm_clip_rect_t
*pBackClipRects
;
344 * Pointer to context to which this drawable is currently bound.
346 __DRIcontextPrivate
*driContextPriv
;
349 * Pointer to screen on which this drawable was created.
351 __DRIscreenPrivate
*driScreenPriv
;
354 * \name Display and screen information.
356 * Basically just need these for when the locking code needs to call
357 * __driUtilUpdateDrawableInfo() which calls XF86DRIGetDrawableInfo().
365 * Called via glXSwapBuffers().
367 void (*swapBuffers
)( __DRIdrawablePrivate
*dPriv
);
370 * Get information about the location, size, and clip rects of the
371 * drawable within the display.
373 GetDrawableInfo
* getInfo
;
377 * Per-context private driver information.
379 struct __DRIcontextPrivateRec
{
381 * Kernel context handle used to access the device lock.
386 * Kernel context handle used to access the device lock.
388 drmContext hHWContext
;
391 * Device driver's private context data. This structure is opaque.
396 * This context's display pointer.
401 * Pointer to drawable currently bound to this context.
403 __DRIdrawablePrivate
*driDrawablePriv
;
406 * Pointer to screen on which this context was created.
408 __DRIscreenPrivate
*driScreenPriv
;
412 * Per-screen private driver information.
414 struct __DRIscreenPrivateRec
{
416 * Display for this screen
421 * Current screen's number
426 * Callback functions into the hardware-specific DRI driver code.
428 struct __DriverAPIRec DriverAPI
;
432 * DDX / 2D driver version information.
433 * \todo Replace these fields with a \c __DRIversionRec.
443 * DRI X extension version information.
444 * \todo Replace these fields with a \c __DRIversionRec.
454 * DRM (kernel module) version information.
455 * \todo Replace these fields with a \c __DRIversionRec.
464 * ID used when the client sets the drawable lock.
466 * The X server uses this value to detect if the client has died while
467 * holding the drawable lock.
472 * File descriptor returned when the kernel device driver is opened.
475 * - authenticate client to kernel
476 * - map the frame buffer, SAREA, etc.
477 * - close the kernel device driver
486 * - the device-independent per-drawable and per-context(?) information
488 XF86DRISAREAPtr pSAREA
;
491 * \name Direct frame buffer access information
492 * Used for software fallbacks.
505 * \name Device-dependent private information (stored in the SAREA).
507 * This data is accessed by the client driver only.
515 * Dummy context to which drawables are bound when not bound to any
518 * A dummy hHWContext is created for this context, and is used by the GL
519 * core when a hardware lock is required but the drawable is not currently
520 * bound (e.g., potentially during a SwapBuffers request). The dummy
521 * context is created when the first "real" context is created on this
524 __DRIcontextPrivate dummyContextPriv
;
527 * Hash table to hold the drawable information for this screen.
532 * Device-dependent private information (not stored in the SAREA).
534 * This pointer is never touched by the DRI layer.
539 * GLX visuals / FBConfigs for this screen. These are stored as a
543 * This field is \b only used in conjunction with the old interfaces. If
544 * the new interfaces are used, this field will be set to \c NULL and will
545 * not be dereferenced.
547 __GLcontextModes
*modes
;
550 * Pointer back to the \c __DRIscreen that contains this structure.
559 __driUtilMessage(const char *f
, ...);
563 __driUtilUpdateDrawableInfo(__DRIdrawablePrivate
*pdp
);
566 extern __DRIscreenPrivate
* __driUtilCreateNewScreen( Display
*dpy
,
567 int scrn
, __DRIscreen
*psc
, __GLcontextModes
* modes
,
568 const __DRIversion
* ddx_version
, const __DRIversion
* dri_version
,
569 const __DRIversion
* drm_version
, const __DRIframebuffer
* frame_buffer
,
570 drmAddress pSAREA
, int fd
, int internal_api_version
,
571 const struct __DriverAPIRec
*driverAPI
);
573 extern __DRIscreenPrivate
*
574 __driUtilCreateScreen(Display
*dpy
, int scrn
, __DRIscreen
*psc
,
575 int numConfigs
, __GLXvisualConfig
*config
,
576 const struct __DriverAPIRec
*driverAPI
);
578 /* Test the version of the internal GLX API. Returns a value like strcmp. */
580 driCompareGLXAPIVersion( GLuint required_version
);
583 driCalculateSwapUsage( __DRIdrawablePrivate
*dPriv
,
584 int64_t last_swap_ust
, int64_t current_ust
);
586 #endif /* GLX_DIRECT_RENDERING */
588 #endif /* _DRI_UTIL_H_ */