2 * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * DRI utility functions definitions.
30 * This module acts as glue between GLX and the actual hardware driver. A DRI
31 * driver doesn't really \e have to use any of this - it's optional. But, some
32 * useful stuff is done here that otherwise would have to be duplicated in most
35 * Basically, these utility functions take care of some of the dirty details of
36 * screen initialization, context creation, context binding, DRM setup, etc.
38 * These functions are compiled into each DRI driver so libGL.so knows nothing
43 * \author Kevin E. Martin <kevin@precisioninsight.com>
44 * \author Brian Paul <brian@precisioninsight.com>
52 #include <drm_sarea.h>
54 #include "xmlconfig.h"
55 #include "main/glheader.h"
56 #include "main/mtypes.h"
57 #include "GL/internal/dri_interface.h"
59 #define GLX_BAD_CONTEXT 5
61 typedef struct __DRIswapInfoRec __DRIswapInfo
;
66 extern const __DRIlegacyExtension driLegacyExtension
;
67 extern const __DRIcoreExtension driCoreExtension
;
68 extern const __DRIdri2Extension driDRI2Extension
;
69 extern const __DRIextension driReadDrawableExtension
;
70 extern const __DRIcopySubBufferExtension driCopySubBufferExtension
;
71 extern const __DRIswapControlExtension driSwapControlExtension
;
72 extern const __DRImediaStreamCounterExtension driMediaStreamCounterExtension
;
73 extern const __DRI2configQueryExtension dri2ConfigQueryExtension
;
76 * Used by DRI_VALIDATE_DRAWABLE_INFO
78 #define DRI_VALIDATE_DRAWABLE_INFO_ONCE(pDrawPriv) \
80 if (*(pDrawPriv->pStamp) != pDrawPriv->lastStamp) { \
81 __driUtilUpdateDrawableInfo(pDrawPriv); \
87 * Utility macro to validate the drawable information.
89 * See __DRIdrawable::pStamp and __DRIdrawable::lastStamp.
91 #define DRI_VALIDATE_DRAWABLE_INFO(psp, pdp) \
93 while (*(pdp->pStamp) != pdp->lastStamp) { \
94 register unsigned int hwContext = psp->pSAREA->lock.lock & \
95 ~(DRM_LOCK_HELD | DRM_LOCK_CONT); \
96 DRM_UNLOCK(psp->fd, &psp->pSAREA->lock, hwContext); \
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, hwContext); \
107 * Same as above, but for two drawables simultaneously.
111 #define DRI_VALIDATE_TWO_DRAWABLES_INFO(psp, pdp, prp) \
113 while (*((pdp)->pStamp) != (pdp)->lastStamp || \
114 *((prp)->pStamp) != (prp)->lastStamp) { \
115 register unsigned int hwContext = (psp)->pSAREA->lock.lock & \
116 ~(DRM_LOCK_HELD | DRM_LOCK_CONT); \
117 DRM_UNLOCK((psp)->fd, &(psp)->pSAREA->lock, hwContext); \
119 DRM_SPINLOCK(&(psp)->pSAREA->drawable_lock, (psp)->drawLockID); \
120 DRI_VALIDATE_DRAWABLE_INFO_ONCE(pdp); \
121 DRI_VALIDATE_DRAWABLE_INFO_ONCE(prp); \
122 DRM_SPINUNLOCK(&(psp)->pSAREA->drawable_lock, (psp)->drawLockID); \
124 DRM_LIGHT_LOCK((psp)->fd, &(psp)->pSAREA->lock, hwContext); \
130 * Driver callback functions.
132 * Each DRI driver must have one of these structures with all the pointers set
133 * to appropriate functions within the driver.
135 * When glXCreateContext() is called, for example, it'll call a helper function
136 * dri_util.c which in turn will jump through the \a CreateContext pointer in
139 struct __DriverAPIRec
{
140 const __DRIconfig
**(*InitScreen
) (__DRIscreen
* priv
);
143 * Screen destruction callback
145 void (*DestroyScreen
)(__DRIscreen
*driScrnPriv
);
148 * Context creation callback
150 GLboolean (*CreateContext
)(gl_api api
,
151 const struct gl_config
*glVis
,
152 __DRIcontext
*driContextPriv
,
153 void *sharedContextPrivate
);
156 * Context destruction callback
158 void (*DestroyContext
)(__DRIcontext
*driContextPriv
);
161 * Buffer (drawable) creation callback
163 GLboolean (*CreateBuffer
)(__DRIscreen
*driScrnPriv
,
164 __DRIdrawable
*driDrawPriv
,
165 const struct gl_config
*glVis
,
166 GLboolean pixmapBuffer
);
169 * Buffer (drawable) destruction callback
171 void (*DestroyBuffer
)(__DRIdrawable
*driDrawPriv
);
174 * Buffer swapping callback
176 void (*SwapBuffers
)(__DRIdrawable
*driDrawPriv
);
179 * Context activation callback
181 GLboolean (*MakeCurrent
)(__DRIcontext
*driContextPriv
,
182 __DRIdrawable
*driDrawPriv
,
183 __DRIdrawable
*driReadPriv
);
186 * Context unbinding callback
188 GLboolean (*UnbindContext
)(__DRIcontext
*driContextPriv
);
191 * Retrieves statistics about buffer swap operations. Required if
192 * GLX_OML_sync_control or GLX_MESA_swap_frame_usage is supported.
194 int (*GetSwapInfo
)( __DRIdrawable
*dPriv
, __DRIswapInfo
* sInfo
);
198 * These are required if GLX_OML_sync_control is supported.
201 int (*WaitForMSC
)( __DRIdrawable
*priv
, int64_t target_msc
,
202 int64_t divisor
, int64_t remainder
,
204 int (*WaitForSBC
)( __DRIdrawable
*priv
, int64_t target_sbc
,
205 int64_t * msc
, int64_t * sbc
);
207 int64_t (*SwapBuffersMSC
)( __DRIdrawable
*priv
, int64_t target_msc
,
208 int64_t divisor
, int64_t remainder
);
210 void (*CopySubBuffer
)(__DRIdrawable
*driDrawPriv
,
211 int x
, int y
, int w
, int h
);
214 * New version of GetMSC so we can pass drawable data to the low
215 * level DRM driver (e.g. pipe info). Required if
216 * GLX_SGI_video_sync or GLX_OML_sync_control is supported.
218 int (*GetDrawableMSC
) ( __DRIscreen
* priv
,
219 __DRIdrawable
*drawablePrivate
,
224 /* DRI2 Entry point */
225 const __DRIconfig
**(*InitScreen2
) (__DRIscreen
* priv
);
228 extern const struct __DriverAPIRec driDriverAPI
;
231 struct __DRIswapInfoRec
{
233 * Number of swapBuffers operations that have been *completed*.
238 * Unadjusted system time of the last buffer swap. This is the time
239 * when the swap completed, not the time when swapBuffers was called.
244 * Number of swap operations that occurred after the swap deadline. That
245 * is if a swap happens more than swap_interval frames after the previous
246 * swap, it has missed its deadline. If swap_interval is 0, then the
247 * swap deadline is 1 frame after the previous swap.
249 uint64_t swap_missed_count
;
252 * Amount of time used by the last swap that missed its deadline. This
253 * is calculated as (__glXGetUST() - swap_ust) / (swap_interval *
254 * time_for_single_vrefresh)). If the actual value of swap_interval is
255 * 0, then 1 is used instead. If swap_missed_count is non-zero, this
256 * should be greater-than 1.0.
258 float swap_missed_usage
;
263 * Per-drawable private DRI driver information.
265 struct __DRIdrawableRec
{
267 * Kernel drawable handle
269 drm_drawable_t hHWDrawable
;
272 * Driver's private drawable information.
274 * This structure is opaque.
279 * Private data from the loader. We just hold on to it and pass
280 * it back when calling into loader provided functions.
285 * Reference count for number of context's currently bound to this
288 * Once it reaches zero, the drawable can be destroyed.
290 * \note This behavior will change with GLX 1.3.
295 * Index of this drawable information in the SAREA.
300 * Pointer to the "drawable has changed ID" stamp in the SAREA (or
301 * to dri2.stamp if DRI2 is being used).
303 unsigned int *pStamp
;
306 * Last value of the stamp.
308 * If this differs from the value stored at __DRIdrawable::pStamp,
309 * then the drawable information has been modified by the X server, and the
310 * drawable information (below) should be retrieved from the X server.
312 unsigned int lastStamp
;
317 * Drawable information used in software fallbacks.
325 drm_clip_rect_t
*pClipRects
;
329 * \name Back and depthbuffer
331 * Information about the back and depthbuffer where different from above.
336 int backClipRectType
;
337 int numBackClipRects
;
338 drm_clip_rect_t
*pBackClipRects
;
342 * \name Vertical blank tracking information
343 * Used for waiting on vertical blank events.
347 unsigned int vblFlags
;
351 * \name Monotonic MSC tracking
353 * Low level driver is responsible for updating msc_base and
354 * vblSeq values so that higher level code can calculate
355 * a new msc value or msc target for a WaitMSC call. The new value
357 * msc = msc_base + get_vblank_count() - vblank_base;
359 * And for waiting on a value, core code will use:
360 * actual_target = target_msc - msc_base + vblank_base;
368 * Pointer to context to which this drawable is currently bound.
370 __DRIcontext
*driContextPriv
;
373 * Pointer to screen on which this drawable was created.
375 __DRIscreen
*driScreenPriv
;
378 * Controls swap interval as used by GLX_SGI_swap_control and
379 * GLX_MESA_swap_control.
381 unsigned int swap_interval
;
385 drm_clip_rect_t clipRect
;
390 * Per-context private driver information.
392 struct __DRIcontextRec
{
394 * Kernel context handle used to access the device lock.
396 drm_context_t hHWContext
;
399 * Device driver's private context data. This structure is opaque.
404 * Pointer to drawable currently bound to this context for drawing.
406 __DRIdrawable
*driDrawablePriv
;
409 * Pointer to drawable currently bound to this context for reading.
411 __DRIdrawable
*driReadablePriv
;
414 * Pointer to screen on which this context was created.
416 __DRIscreen
*driScreenPriv
;
419 * The loaders's private context data. This structure is opaque.
430 * Per-screen private driver information.
432 struct __DRIscreenRec
{
434 * Current screen's number
439 * Callback functions into the hardware-specific DRI driver code.
441 struct __DriverAPIRec DriverAPI
;
443 const __DRIextension
**extensions
;
445 * DDX / 2D driver version information.
447 __DRIversion ddx_version
;
450 * DRI X extension version information.
452 __DRIversion dri_version
;
455 * DRM (kernel module) version information.
457 __DRIversion drm_version
;
460 * ID used when the client sets the drawable lock.
462 * The X server uses this value to detect if the client has died while
463 * holding the drawable lock.
468 * File descriptor returned when the kernel device driver is opened.
471 * - authenticate client to kernel
472 * - map the frame buffer, SAREA, etc.
473 * - close the kernel device driver
482 * - the device-independent per-drawable and per-context(?) information
487 * \name Direct frame buffer access information
488 * Used for software fallbacks.
501 * \name Device-dependent private information (stored in the SAREA).
503 * This data is accessed by the client driver only.
511 * Device-dependent private information (not stored in the SAREA).
513 * This pointer is never touched by the DRI layer.
521 /* Extensions provided by the loader. */
522 const __DRIgetDrawableInfoExtension
*getDrawableInfo
;
523 const __DRIsystemTimeExtension
*systemTime
;
524 const __DRIdamageExtension
*damage
;
527 /* Flag to indicate that this is a DRI2 screen. Many of the above
528 * fields will not be valid or initializaed in that case. */
530 __DRIdri2LoaderExtension
*loader
;
531 __DRIimageLookupExtension
*image
;
532 __DRIuseInvalidateExtension
*useInvalidate
;
535 /* The lock actually in use, old sarea or DRI2 */
538 driOptionCache optionInfo
;
539 driOptionCache optionCache
;
540 unsigned int api_mask
;
545 __driUtilUpdateDrawableInfo(__DRIdrawable
*pdp
);
548 driCalculateSwapUsage( __DRIdrawable
*dPriv
,
549 int64_t last_swap_ust
, int64_t current_ust
);
552 driIntersectArea( drm_clip_rect_t rect1
, drm_clip_rect_t rect2
);
555 dri2InvalidateDrawable(__DRIdrawable
*drawable
);
557 #endif /* _DRI_UTIL_H_ */