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.
54 #include <drm_sarea.h>
56 #include "main/glheader.h"
57 #include "GL/internal/glcore.h"
58 #include "GL/internal/dri_interface.h"
60 #define GLX_BAD_CONTEXT 5
62 typedef struct __DRIswapInfoRec __DRIswapInfo
;
64 /* Typedefs to avoid rewriting the world. */
65 typedef struct __DRIscreenRec __DRIscreenPrivate
;
66 typedef struct __DRIdrawableRec __DRIdrawablePrivate
;
67 typedef struct __DRIcontextRec __DRIcontextPrivate
;
72 extern const __DRIlegacyExtension driLegacyExtension
;
73 extern const __DRIcoreExtension driCoreExtension
;
74 extern const __DRIextension driReadDrawableExtension
;
75 extern const __DRIcopySubBufferExtension driCopySubBufferExtension
;
76 extern const __DRIswapControlExtension driSwapControlExtension
;
77 extern const __DRIframeTrackingExtension driFrameTrackingExtension
;
78 extern const __DRImediaStreamCounterExtension driMediaStreamCounterExtension
;
81 * Used by DRI_VALIDATE_DRAWABLE_INFO
83 #define DRI_VALIDATE_DRAWABLE_INFO_ONCE(pDrawPriv) \
85 if (*(pDrawPriv->pStamp) != pDrawPriv->lastStamp) { \
86 __driUtilUpdateDrawableInfo(pDrawPriv); \
92 * Utility macro to validate the drawable information.
94 * See __DRIdrawable::pStamp and __DRIdrawable::lastStamp.
96 #define DRI_VALIDATE_DRAWABLE_INFO(psp, pdp) \
98 while (*(pdp->pStamp) != pdp->lastStamp) { \
99 register unsigned int hwContext = psp->pSAREA->lock.lock & \
100 ~(DRM_LOCK_HELD | DRM_LOCK_CONT); \
101 DRM_UNLOCK(psp->fd, &psp->pSAREA->lock, hwContext); \
103 DRM_SPINLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID); \
104 DRI_VALIDATE_DRAWABLE_INFO_ONCE(pdp); \
105 DRM_SPINUNLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID); \
107 DRM_LIGHT_LOCK(psp->fd, &psp->pSAREA->lock, hwContext); \
112 * Same as above, but for two drawables simultaneously.
116 #define DRI_VALIDATE_TWO_DRAWABLES_INFO(psp, pdp, prp) \
118 while (*((pdp)->pStamp) != (pdp)->lastStamp || \
119 *((prp)->pStamp) != (prp)->lastStamp) { \
120 register unsigned int hwContext = (psp)->pSAREA->lock.lock & \
121 ~(DRM_LOCK_HELD | DRM_LOCK_CONT); \
122 DRM_UNLOCK((psp)->fd, &(psp)->pSAREA->lock, hwContext); \
124 DRM_SPINLOCK(&(psp)->pSAREA->drawable_lock, (psp)->drawLockID); \
125 DRI_VALIDATE_DRAWABLE_INFO_ONCE(pdp); \
126 DRI_VALIDATE_DRAWABLE_INFO_ONCE(prp); \
127 DRM_SPINUNLOCK(&(psp)->pSAREA->drawable_lock, (psp)->drawLockID); \
129 DRM_LIGHT_LOCK((psp)->fd, &(psp)->pSAREA->lock, hwContext); \
135 * Driver callback functions.
137 * Each DRI driver must have one of these structures with all the pointers set
138 * to appropriate functions within the driver.
140 * When glXCreateContext() is called, for example, it'll call a helper function
141 * dri_util.c which in turn will jump through the \a CreateContext pointer in
144 struct __DriverAPIRec
{
145 const __DRIconfig
**(*InitScreen
) (__DRIscreen
* priv
);
148 * Screen destruction callback
150 void (*DestroyScreen
)(__DRIscreen
*driScrnPriv
);
153 * Context creation callback
155 GLboolean (*CreateContext
)(const __GLcontextModes
*glVis
,
156 __DRIcontext
*driContextPriv
,
157 void *sharedContextPrivate
);
160 * Context destruction callback
162 void (*DestroyContext
)(__DRIcontext
*driContextPriv
);
165 * Buffer (drawable) creation callback
167 GLboolean (*CreateBuffer
)(__DRIscreen
*driScrnPriv
,
168 __DRIdrawable
*driDrawPriv
,
169 const __GLcontextModes
*glVis
,
170 GLboolean pixmapBuffer
);
173 * Buffer (drawable) destruction callback
175 void (*DestroyBuffer
)(__DRIdrawable
*driDrawPriv
);
178 * Buffer swapping callback
180 void (*SwapBuffers
)(__DRIdrawable
*driDrawPriv
);
183 * Context activation callback
185 GLboolean (*MakeCurrent
)(__DRIcontext
*driContextPriv
,
186 __DRIdrawable
*driDrawPriv
,
187 __DRIdrawable
*driReadPriv
);
190 * Context unbinding callback
192 GLboolean (*UnbindContext
)(__DRIcontext
*driContextPriv
);
195 * Retrieves statistics about buffer swap operations. Required if
196 * GLX_OML_sync_control or GLX_MESA_swap_frame_usage is supported.
198 int (*GetSwapInfo
)( __DRIdrawable
*dPriv
, __DRIswapInfo
* sInfo
);
202 * These are required if GLX_OML_sync_control is supported.
205 int (*WaitForMSC
)( __DRIdrawable
*priv
, int64_t target_msc
,
206 int64_t divisor
, int64_t remainder
,
208 int (*WaitForSBC
)( __DRIdrawable
*priv
, int64_t target_sbc
,
209 int64_t * msc
, int64_t * sbc
);
211 int64_t (*SwapBuffersMSC
)( __DRIdrawable
*priv
, int64_t target_msc
,
212 int64_t divisor
, int64_t remainder
);
214 void (*CopySubBuffer
)(__DRIdrawable
*driDrawPriv
,
215 int x
, int y
, int w
, int h
);
218 * New version of GetMSC so we can pass drawable data to the low
219 * level DRM driver (e.g. pipe info). Required if
220 * GLX_SGI_video_sync or GLX_OML_sync_control is supported.
222 int (*GetDrawableMSC
) ( __DRIscreen
* priv
,
223 __DRIdrawable
*drawablePrivate
,
228 /* DRI2 Entry point */
229 const __DRIconfig
**(*InitScreen2
) (__DRIscreen
* priv
);
232 extern const struct __DriverAPIRec driDriverAPI
;
235 struct __DRIswapInfoRec
{
237 * Number of swapBuffers operations that have been *completed*.
242 * Unadjusted system time of the last buffer swap. This is the time
243 * when the swap completed, not the time when swapBuffers was called.
248 * Number of swap operations that occurred after the swap deadline. That
249 * is if a swap happens more than swap_interval frames after the previous
250 * swap, it has missed its deadline. If swap_interval is 0, then the
251 * swap deadline is 1 frame after the previous swap.
253 uint64_t swap_missed_count
;
256 * Amount of time used by the last swap that missed its deadline. This
257 * is calculated as (__glXGetUST() - swap_ust) / (swap_interval *
258 * time_for_single_vrefresh)). If the actual value of swap_interval is
259 * 0, then 1 is used instead. If swap_missed_count is non-zero, this
260 * should be greater-than 1.0.
262 float swap_missed_usage
;
267 * Per-drawable private DRI driver information.
269 struct __DRIdrawableRec
{
271 * Kernel drawable handle
273 drm_drawable_t hHWDrawable
;
276 * Driver's private drawable information.
278 * This structure is opaque.
283 * Private data from the loader. We just hold on to it and pass
284 * it back when calling into loader provided functions.
289 * Reference count for number of context's currently bound to this
292 * Once it reaches zero, the drawable can be destroyed.
294 * \note This behavior will change with GLX 1.3.
299 * Index of this drawable information in the SAREA.
304 * Pointer to the "drawable has changed ID" stamp in the SAREA.
306 unsigned int *pStamp
;
309 * Last value of the stamp.
311 * If this differs from the value stored at __DRIdrawable::pStamp,
312 * then the drawable information has been modified by the X server, and the
313 * drawable information (below) should be retrieved from the X server.
315 unsigned int lastStamp
;
320 * Drawable information used in software fallbacks.
328 drm_clip_rect_t
*pClipRects
;
332 * \name Back and depthbuffer
334 * Information about the back and depthbuffer where different from above.
339 int backClipRectType
;
340 int numBackClipRects
;
341 drm_clip_rect_t
*pBackClipRects
;
345 * \name Vertical blank tracking information
346 * Used for waiting on vertical blank events.
350 unsigned int vblFlags
;
354 * \name Monotonic MSC tracking
356 * Low level driver is responsible for updating msc_base and
357 * vblSeq values so that higher level code can calculate
358 * a new msc value or msc target for a WaitMSC call. The new value
360 * msc = msc_base + get_vblank_count() - vblank_base;
362 * And for waiting on a value, core code will use:
363 * actual_target = target_msc - msc_base + vblank_base;
371 * Pointer to context to which this drawable is currently bound.
373 __DRIcontext
*driContextPriv
;
376 * Pointer to screen on which this drawable was created.
378 __DRIscreen
*driScreenPriv
;
381 * Controls swap interval as used by GLX_SGI_swap_control and
382 * GLX_MESA_swap_control.
384 unsigned int swap_interval
;
388 * Per-context private driver information.
390 struct __DRIcontextRec
{
392 * Kernel context handle used to access the device lock.
394 drm_context_t hHWContext
;
397 * Device driver's private context data. This structure is opaque.
402 * Pointer back to the \c __DRIcontext that contains this structure.
407 * Pointer to drawable currently bound to this context for drawing.
409 __DRIdrawable
*driDrawablePriv
;
412 * Pointer to drawable currently bound to this context for reading.
414 __DRIdrawable
*driReadablePriv
;
417 * Pointer to screen on which this context was created.
419 __DRIscreen
*driScreenPriv
;
423 * Per-screen private driver information.
425 struct __DRIscreenRec
{
427 * Current screen's number
432 * Callback functions into the hardware-specific DRI driver code.
434 struct __DriverAPIRec DriverAPI
;
436 const __DRIextension
**extensions
;
438 * DDX / 2D driver version information.
440 __DRIversion ddx_version
;
443 * DRI X extension version information.
445 __DRIversion dri_version
;
448 * DRM (kernel module) version information.
450 __DRIversion drm_version
;
453 * ID used when the client sets the drawable lock.
455 * The X server uses this value to detect if the client has died while
456 * holding the drawable lock.
461 * File descriptor returned when the kernel device driver is opened.
464 * - authenticate client to kernel
465 * - map the frame buffer, SAREA, etc.
466 * - close the kernel device driver
475 * - the device-independent per-drawable and per-context(?) information
480 * \name Direct frame buffer access information
481 * Used for software fallbacks.
494 * \name Device-dependent private information (stored in the SAREA).
496 * This data is accessed by the client driver only.
504 * Dummy context to which drawables are bound when not bound to any
507 * A dummy hHWContext is created for this context, and is used by the GL
508 * core when a hardware lock is required but the drawable is not currently
509 * bound (e.g., potentially during a SwapBuffers request). The dummy
510 * context is created when the first "real" context is created on this
513 __DRIcontext dummyContextPriv
;
516 * Device-dependent private information (not stored in the SAREA).
518 * This pointer is never touched by the DRI layer.
523 * Pointer back to the \c __DRIscreen that contains this structure.
527 /* Extensions provided by the loader. */
528 const __DRIgetDrawableInfoExtension
*getDrawableInfo
;
529 const __DRIsystemTimeExtension
*systemTime
;
530 const __DRIdamageExtension
*damage
;
533 /* Flag to indicate that this is a DRI2 screen. Many of the above
534 * fields will not be valid or initializaed in that case. */
536 __DRIdri2LoaderExtension
*loader
;
539 /* The lock actually in use, old sarea or DRI2 */
544 __driUtilMessage(const char *f
, ...);
548 __driUtilUpdateDrawableInfo(__DRIdrawable
*pdp
);
551 driCalculateSwapUsage( __DRIdrawable
*dPriv
,
552 int64_t last_swap_ust
, int64_t current_ust
);
555 driIntersectArea( drm_clip_rect_t rect1
, drm_clip_rect_t rect2
);
557 #endif /* _DRI_UTIL_H_ */