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 __DRIcoreExtension driCoreExtension;
67 extern const __DRIdri2Extension driDRI2Extension;
68 extern const __DRIcopySubBufferExtension driCopySubBufferExtension;
69 extern const __DRIswapControlExtension driSwapControlExtension;
70 extern const __DRImediaStreamCounterExtension driMediaStreamCounterExtension;
71 extern const __DRI2configQueryExtension dri2ConfigQueryExtension;
74 * Used by DRI_VALIDATE_DRAWABLE_INFO
76 #define DRI_VALIDATE_DRAWABLE_INFO_ONCE(pDrawPriv) \
78 if (*(pDrawPriv->pStamp) != pDrawPriv->lastStamp) { \
79 __driUtilUpdateDrawableInfo(pDrawPriv); \
85 * Utility macro to validate the drawable information.
87 * See __DRIdrawable::pStamp and __DRIdrawable::lastStamp.
89 #define DRI_VALIDATE_DRAWABLE_INFO(psp, pdp) \
91 while (*(pdp->pStamp) != pdp->lastStamp) { \
92 register unsigned int hwContext = psp->pSAREA->lock.lock & \
93 ~(DRM_LOCK_HELD | DRM_LOCK_CONT); \
94 DRM_UNLOCK(psp->fd, &psp->pSAREA->lock, hwContext); \
96 DRM_SPINLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID); \
97 DRI_VALIDATE_DRAWABLE_INFO_ONCE(pdp); \
98 DRM_SPINUNLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID); \
100 DRM_LIGHT_LOCK(psp->fd, &psp->pSAREA->lock, hwContext); \
105 * Same as above, but for two drawables simultaneously.
109 #define DRI_VALIDATE_TWO_DRAWABLES_INFO(psp, pdp, prp) \
111 while (*((pdp)->pStamp) != (pdp)->lastStamp || \
112 *((prp)->pStamp) != (prp)->lastStamp) { \
113 register unsigned int hwContext = (psp)->pSAREA->lock.lock & \
114 ~(DRM_LOCK_HELD | DRM_LOCK_CONT); \
115 DRM_UNLOCK((psp)->fd, &(psp)->pSAREA->lock, hwContext); \
117 DRM_SPINLOCK(&(psp)->pSAREA->drawable_lock, (psp)->drawLockID); \
118 DRI_VALIDATE_DRAWABLE_INFO_ONCE(pdp); \
119 DRI_VALIDATE_DRAWABLE_INFO_ONCE(prp); \
120 DRM_SPINUNLOCK(&(psp)->pSAREA->drawable_lock, (psp)->drawLockID); \
122 DRM_LIGHT_LOCK((psp)->fd, &(psp)->pSAREA->lock, hwContext); \
128 * Driver callback functions.
130 * Each DRI driver must have one of these structures with all the pointers set
131 * to appropriate functions within the driver.
133 * When glXCreateContext() is called, for example, it'll call a helper function
134 * dri_util.c which in turn will jump through the \a CreateContext pointer in
137 struct __DriverAPIRec {
138 const __DRIconfig **(*InitScreen) (__DRIscreen * priv);
141 * Screen destruction callback
143 void (*DestroyScreen)(__DRIscreen *driScrnPriv);
146 * Context creation callback
148 GLboolean (*CreateContext)(gl_api api,
149 const struct gl_config *glVis,
150 __DRIcontext *driContextPriv,
151 void *sharedContextPrivate);
154 * Context destruction callback
156 void (*DestroyContext)(__DRIcontext *driContextPriv);
159 * Buffer (drawable) creation callback
161 GLboolean (*CreateBuffer)(__DRIscreen *driScrnPriv,
162 __DRIdrawable *driDrawPriv,
163 const struct gl_config *glVis,
164 GLboolean pixmapBuffer);
167 * Buffer (drawable) destruction callback
169 void (*DestroyBuffer)(__DRIdrawable *driDrawPriv);
172 * Buffer swapping callback
174 void (*SwapBuffers)(__DRIdrawable *driDrawPriv);
177 * Context activation callback
179 GLboolean (*MakeCurrent)(__DRIcontext *driContextPriv,
180 __DRIdrawable *driDrawPriv,
181 __DRIdrawable *driReadPriv);
184 * Context unbinding callback
186 GLboolean (*UnbindContext)(__DRIcontext *driContextPriv);
189 * Retrieves statistics about buffer swap operations. Required if
190 * GLX_OML_sync_control or GLX_MESA_swap_frame_usage is supported.
192 int (*GetSwapInfo)( __DRIdrawable *dPriv, __DRIswapInfo * sInfo );
196 * These are required if GLX_OML_sync_control is supported.
199 int (*WaitForMSC)( __DRIdrawable *priv, int64_t target_msc,
200 int64_t divisor, int64_t remainder,
202 int (*WaitForSBC)( __DRIdrawable *priv, int64_t target_sbc,
203 int64_t * msc, int64_t * sbc );
205 int64_t (*SwapBuffersMSC)( __DRIdrawable *priv, int64_t target_msc,
206 int64_t divisor, int64_t remainder );
208 void (*CopySubBuffer)(__DRIdrawable *driDrawPriv,
209 int x, int y, int w, int h);
212 * New version of GetMSC so we can pass drawable data to the low
213 * level DRM driver (e.g. pipe info). Required if
214 * GLX_SGI_video_sync or GLX_OML_sync_control is supported.
216 int (*GetDrawableMSC) ( __DRIscreen * priv,
217 __DRIdrawable *drawablePrivate,
222 /* DRI2 Entry point */
223 const __DRIconfig **(*InitScreen2) (__DRIscreen * priv);
225 __DRIbuffer *(*AllocateBuffer) (__DRIscreen *screenPrivate,
226 unsigned int attachment,
228 int width, int height);
229 void (*ReleaseBuffer) (__DRIscreen *screenPrivate, __DRIbuffer *buffer);
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 (or
305 * to dri2.stamp if DRI2 is being used).
307 unsigned int *pStamp;
310 * Last value of the stamp.
312 * If this differs from the value stored at __DRIdrawable::pStamp,
313 * then the drawable information has been modified by the X server, and the
314 * drawable information (below) should be retrieved from the X server.
316 unsigned int lastStamp;
321 * Drawable information used in software fallbacks.
329 drm_clip_rect_t *pClipRects;
333 * \name Back and depthbuffer
335 * Information about the back and depthbuffer where different from above.
340 int backClipRectType;
341 int numBackClipRects;
342 drm_clip_rect_t *pBackClipRects;
346 * \name Vertical blank tracking information
347 * Used for waiting on vertical blank events.
351 unsigned int vblFlags;
355 * \name Monotonic MSC tracking
357 * Low level driver is responsible for updating msc_base and
358 * vblSeq values so that higher level code can calculate
359 * a new msc value or msc target for a WaitMSC call. The new value
361 * msc = msc_base + get_vblank_count() - vblank_base;
363 * And for waiting on a value, core code will use:
364 * actual_target = target_msc - msc_base + vblank_base;
372 * Pointer to context to which this drawable is currently bound.
374 __DRIcontext *driContextPriv;
377 * Pointer to screen on which this drawable was created.
379 __DRIscreen *driScreenPriv;
382 * Controls swap interval as used by GLX_SGI_swap_control and
383 * GLX_MESA_swap_control.
385 unsigned int swap_interval;
389 drm_clip_rect_t clipRect;
394 * Per-context private driver information.
396 struct __DRIcontextRec {
398 * Kernel context handle used to access the device lock.
400 drm_context_t hHWContext;
403 * Device driver's private context data. This structure is opaque.
408 * Pointer to drawable currently bound to this context for drawing.
410 __DRIdrawable *driDrawablePriv;
413 * Pointer to drawable currently bound to this context for reading.
415 __DRIdrawable *driReadablePriv;
418 * Pointer to screen on which this context was created.
420 __DRIscreen *driScreenPriv;
423 * The loaders's private context data. This structure is opaque.
434 * Per-screen private driver information.
436 struct __DRIscreenRec {
438 * Current screen's number
443 * Callback functions into the hardware-specific DRI driver code.
445 struct __DriverAPIRec DriverAPI;
447 const __DRIextension **extensions;
449 * DDX / 2D driver version information.
451 __DRIversion ddx_version;
454 * DRI X extension version information.
456 __DRIversion dri_version;
459 * DRM (kernel module) version information.
461 __DRIversion drm_version;
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
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 * Device-dependent private information (not stored in the SAREA).
517 * This pointer is never touched by the DRI layer.
525 /* Extensions provided by the loader. */
526 const __DRIgetDrawableInfoExtension *getDrawableInfo;
527 const __DRIsystemTimeExtension *systemTime;
528 const __DRIdamageExtension *damage;
531 /* Flag to indicate that this is a DRI2 screen. Many of the above
532 * fields will not be valid or initializaed in that case. */
534 __DRIdri2LoaderExtension *loader;
535 __DRIimageLookupExtension *image;
536 __DRIuseInvalidateExtension *useInvalidate;
539 /* The lock actually in use, old sarea or DRI2 */
542 driOptionCache optionInfo;
543 driOptionCache optionCache;
544 unsigned int api_mask;
549 __driUtilUpdateDrawableInfo(__DRIdrawable *pdp);
552 driCalculateSwapUsage( __DRIdrawable *dPriv,
553 int64_t last_swap_ust, int64_t current_ust );
556 driIntersectArea( drm_clip_rect_t rect1, drm_clip_rect_t rect2 );
559 dri2InvalidateDrawable(__DRIdrawable *drawable);
561 #endif /* _DRI_UTIL_H_ */