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/glcore.h"
58 #include "GL/internal/dri_interface.h"
60 #define GLX_BAD_CONTEXT 5
62 typedef struct __DRIswapInfoRec __DRIswapInfo
;
67 extern const __DRIlegacyExtension driLegacyExtension
;
68 extern const __DRIcoreExtension driCoreExtension
;
69 extern const __DRIdri2Extension driDRI2Extension
;
70 extern const __DRIextension driReadDrawableExtension
;
71 extern const __DRIcopySubBufferExtension driCopySubBufferExtension
;
72 extern const __DRIswapControlExtension driSwapControlExtension
;
73 extern const __DRImediaStreamCounterExtension driMediaStreamCounterExtension
;
74 extern const __DRI2configQueryExtension dri2ConfigQueryExtension
;
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 __DRIdrawable::pStamp and __DRIdrawable::lastStamp.
92 #define DRI_VALIDATE_DRAWABLE_INFO(psp, pdp) \
94 while (*(pdp->pStamp) != pdp->lastStamp) { \
95 register unsigned int hwContext = psp->pSAREA->lock.lock & \
96 ~(DRM_LOCK_HELD | DRM_LOCK_CONT); \
97 DRM_UNLOCK(psp->fd, &psp->pSAREA->lock, hwContext); \
99 DRM_SPINLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID); \
100 DRI_VALIDATE_DRAWABLE_INFO_ONCE(pdp); \
101 DRM_SPINUNLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID); \
103 DRM_LIGHT_LOCK(psp->fd, &psp->pSAREA->lock, hwContext); \
108 * Same as above, but for two drawables simultaneously.
112 #define DRI_VALIDATE_TWO_DRAWABLES_INFO(psp, pdp, prp) \
114 while (*((pdp)->pStamp) != (pdp)->lastStamp || \
115 *((prp)->pStamp) != (prp)->lastStamp) { \
116 register unsigned int hwContext = (psp)->pSAREA->lock.lock & \
117 ~(DRM_LOCK_HELD | DRM_LOCK_CONT); \
118 DRM_UNLOCK((psp)->fd, &(psp)->pSAREA->lock, hwContext); \
120 DRM_SPINLOCK(&(psp)->pSAREA->drawable_lock, (psp)->drawLockID); \
121 DRI_VALIDATE_DRAWABLE_INFO_ONCE(pdp); \
122 DRI_VALIDATE_DRAWABLE_INFO_ONCE(prp); \
123 DRM_SPINUNLOCK(&(psp)->pSAREA->drawable_lock, (psp)->drawLockID); \
125 DRM_LIGHT_LOCK((psp)->fd, &(psp)->pSAREA->lock, hwContext); \
131 * Driver callback functions.
133 * Each DRI driver must have one of these structures with all the pointers set
134 * to appropriate functions within the driver.
136 * When glXCreateContext() is called, for example, it'll call a helper function
137 * dri_util.c which in turn will jump through the \a CreateContext pointer in
140 struct __DriverAPIRec
{
141 const __DRIconfig
**(*InitScreen
) (__DRIscreen
* priv
);
144 * Screen destruction callback
146 void (*DestroyScreen
)(__DRIscreen
*driScrnPriv
);
149 * Context creation callback
151 GLboolean (*CreateContext
)(gl_api api
,
152 const __GLcontextModes
*glVis
,
153 __DRIcontext
*driContextPriv
,
154 void *sharedContextPrivate
);
157 * Context destruction callback
159 void (*DestroyContext
)(__DRIcontext
*driContextPriv
);
162 * Buffer (drawable) creation callback
164 GLboolean (*CreateBuffer
)(__DRIscreen
*driScrnPriv
,
165 __DRIdrawable
*driDrawPriv
,
166 const __GLcontextModes
*glVis
,
167 GLboolean pixmapBuffer
);
170 * Buffer (drawable) destruction callback
172 void (*DestroyBuffer
)(__DRIdrawable
*driDrawPriv
);
175 * Buffer swapping callback
177 void (*SwapBuffers
)(__DRIdrawable
*driDrawPriv
);
180 * Context activation callback
182 GLboolean (*MakeCurrent
)(__DRIcontext
*driContextPriv
,
183 __DRIdrawable
*driDrawPriv
,
184 __DRIdrawable
*driReadPriv
);
187 * Context unbinding callback
189 GLboolean (*UnbindContext
)(__DRIcontext
*driContextPriv
);
192 * Retrieves statistics about buffer swap operations. Required if
193 * GLX_OML_sync_control or GLX_MESA_swap_frame_usage is supported.
195 int (*GetSwapInfo
)( __DRIdrawable
*dPriv
, __DRIswapInfo
* sInfo
);
199 * These are required if GLX_OML_sync_control is supported.
202 int (*WaitForMSC
)( __DRIdrawable
*priv
, int64_t target_msc
,
203 int64_t divisor
, int64_t remainder
,
205 int (*WaitForSBC
)( __DRIdrawable
*priv
, int64_t target_sbc
,
206 int64_t * msc
, int64_t * sbc
);
208 int64_t (*SwapBuffersMSC
)( __DRIdrawable
*priv
, int64_t target_msc
,
209 int64_t divisor
, int64_t remainder
);
211 void (*CopySubBuffer
)(__DRIdrawable
*driDrawPriv
,
212 int x
, int y
, int w
, int h
);
215 * New version of GetMSC so we can pass drawable data to the low
216 * level DRM driver (e.g. pipe info). Required if
217 * GLX_SGI_video_sync or GLX_OML_sync_control is supported.
219 int (*GetDrawableMSC
) ( __DRIscreen
* priv
,
220 __DRIdrawable
*drawablePrivate
,
225 /* DRI2 Entry point */
226 const __DRIconfig
**(*InitScreen2
) (__DRIscreen
* priv
);
229 extern const struct __DriverAPIRec driDriverAPI
;
232 struct __DRIswapInfoRec
{
234 * Number of swapBuffers operations that have been *completed*.
239 * Unadjusted system time of the last buffer swap. This is the time
240 * when the swap completed, not the time when swapBuffers was called.
245 * Number of swap operations that occurred after the swap deadline. That
246 * is if a swap happens more than swap_interval frames after the previous
247 * swap, it has missed its deadline. If swap_interval is 0, then the
248 * swap deadline is 1 frame after the previous swap.
250 uint64_t swap_missed_count
;
253 * Amount of time used by the last swap that missed its deadline. This
254 * is calculated as (__glXGetUST() - swap_ust) / (swap_interval *
255 * time_for_single_vrefresh)). If the actual value of swap_interval is
256 * 0, then 1 is used instead. If swap_missed_count is non-zero, this
257 * should be greater-than 1.0.
259 float swap_missed_usage
;
264 * Per-drawable private DRI driver information.
266 struct __DRIdrawableRec
{
268 * Kernel drawable handle
270 drm_drawable_t hHWDrawable
;
273 * Driver's private drawable information.
275 * This structure is opaque.
280 * Private data from the loader. We just hold on to it and pass
281 * it back when calling into loader provided functions.
286 * Reference count for number of context's currently bound to this
289 * Once it reaches zero, the drawable can be destroyed.
291 * \note This behavior will change with GLX 1.3.
296 * Index of this drawable information in the SAREA.
301 * Pointer to the "drawable has changed ID" stamp in the SAREA (or
302 * to dri2.stamp if DRI2 is being used).
304 unsigned int *pStamp
;
307 * Last value of the stamp.
309 * If this differs from the value stored at __DRIdrawable::pStamp,
310 * then the drawable information has been modified by the X server, and the
311 * drawable information (below) should be retrieved from the X server.
313 unsigned int lastStamp
;
318 * Drawable information used in software fallbacks.
326 drm_clip_rect_t
*pClipRects
;
330 * \name Back and depthbuffer
332 * Information about the back and depthbuffer where different from above.
337 int backClipRectType
;
338 int numBackClipRects
;
339 drm_clip_rect_t
*pBackClipRects
;
343 * \name Vertical blank tracking information
344 * Used for waiting on vertical blank events.
348 unsigned int vblFlags
;
352 * \name Monotonic MSC tracking
354 * Low level driver is responsible for updating msc_base and
355 * vblSeq values so that higher level code can calculate
356 * a new msc value or msc target for a WaitMSC call. The new value
358 * msc = msc_base + get_vblank_count() - vblank_base;
360 * And for waiting on a value, core code will use:
361 * actual_target = target_msc - msc_base + vblank_base;
369 * Pointer to context to which this drawable is currently bound.
371 __DRIcontext
*driContextPriv
;
374 * Pointer to screen on which this drawable was created.
376 __DRIscreen
*driScreenPriv
;
379 * Controls swap interval as used by GLX_SGI_swap_control and
380 * GLX_MESA_swap_control.
382 unsigned int swap_interval
;
386 drm_clip_rect_t clipRect
;
391 * Per-context private driver information.
393 struct __DRIcontextRec
{
395 * Kernel context handle used to access the device lock.
397 drm_context_t hHWContext
;
400 * Device driver's private context data. This structure is opaque.
405 * Pointer to drawable currently bound to this context for drawing.
407 __DRIdrawable
*driDrawablePriv
;
410 * Pointer to drawable currently bound to this context for reading.
412 __DRIdrawable
*driReadablePriv
;
415 * Pointer to screen on which this context was created.
417 __DRIscreen
*driScreenPriv
;
420 * The loaders's private context data. This structure is opaque.
431 * Per-screen private driver information.
433 struct __DRIscreenRec
{
435 * Current screen's number
440 * Callback functions into the hardware-specific DRI driver code.
442 struct __DriverAPIRec DriverAPI
;
444 const __DRIextension
**extensions
;
446 * DDX / 2D driver version information.
448 __DRIversion ddx_version
;
451 * DRI X extension version information.
453 __DRIversion dri_version
;
456 * DRM (kernel module) version information.
458 __DRIversion drm_version
;
461 * ID used when the client sets the drawable lock.
463 * The X server uses this value to detect if the client has died while
464 * holding the drawable lock.
469 * File descriptor returned when the kernel device driver is opened.
472 * - authenticate client to kernel
473 * - map the frame buffer, SAREA, etc.
474 * - close the kernel device driver
483 * - the device-independent per-drawable and per-context(?) information
488 * \name Direct frame buffer access information
489 * Used for software fallbacks.
502 * \name Device-dependent private information (stored in the SAREA).
504 * This data is accessed by the client driver only.
512 * Device-dependent private information (not stored in the SAREA).
514 * This pointer is never touched by the DRI layer.
522 /* Extensions provided by the loader. */
523 const __DRIgetDrawableInfoExtension
*getDrawableInfo
;
524 const __DRIsystemTimeExtension
*systemTime
;
525 const __DRIdamageExtension
*damage
;
528 /* Flag to indicate that this is a DRI2 screen. Many of the above
529 * fields will not be valid or initializaed in that case. */
531 __DRIdri2LoaderExtension
*loader
;
532 __DRIimageLookupExtension
*image
;
533 __DRIuseInvalidateExtension
*useInvalidate
;
536 /* The lock actually in use, old sarea or DRI2 */
539 driOptionCache optionInfo
;
540 driOptionCache optionCache
;
541 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_ */