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 "GL/internal/glcore.h"
57 #include "GL/internal/dri_interface.h"
59 #define GLX_BAD_CONTEXT 5
61 typedef struct __DRIdisplayPrivateRec __DRIdisplayPrivate
;
62 typedef struct __DRIscreenPrivateRec __DRIscreenPrivate
;
63 typedef struct __DRIcontextPrivateRec __DRIcontextPrivate
;
64 typedef struct __DRIdrawablePrivateRec __DRIdrawablePrivate
;
65 typedef struct __DRIswapInfoRec __DRIswapInfo
;
66 typedef struct __DRIutilversionRec2 __DRIutilversion2
;
70 * Driver specific entry point. Implemented by the driver. Called
71 * from the top level createNewScreen entry point to initialize the
72 * __DRIscreenPrivate struct.
74 extern __GLcontextModes
*__driDriverInitScreen(__DRIscreenPrivate
*psp
);
79 extern const __DRIextension driReadDrawableExtension
;
80 extern const __DRIcopySubBufferExtension driCopySubBufferExtension
;
81 extern const __DRIswapControlExtension driSwapControlExtension
;
82 extern const __DRIframeTrackingExtension driFrameTrackingExtension
;
83 extern const __DRImediaStreamCounterExtension driMediaStreamCounterExtension
;
86 * Used by DRI_VALIDATE_DRAWABLE_INFO
88 #define DRI_VALIDATE_DRAWABLE_INFO_ONCE(pDrawPriv) \
90 if (*(pDrawPriv->pStamp) != pDrawPriv->lastStamp) { \
91 __driUtilUpdateDrawableInfo(pDrawPriv); \
97 * Utility macro to validate the drawable information.
99 * See __DRIdrawablePrivate::pStamp and __DRIdrawablePrivate::lastStamp.
101 #define DRI_VALIDATE_DRAWABLE_INFO(psp, pdp) \
103 while (*(pdp->pStamp) != pdp->lastStamp) { \
104 register unsigned int hwContext = psp->pSAREA->lock.lock & \
105 ~(DRM_LOCK_HELD | DRM_LOCK_CONT); \
106 DRM_UNLOCK(psp->fd, &psp->pSAREA->lock, hwContext); \
108 DRM_SPINLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID); \
109 DRI_VALIDATE_DRAWABLE_INFO_ONCE(pdp); \
110 DRM_SPINUNLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID); \
112 DRM_LIGHT_LOCK(psp->fd, &psp->pSAREA->lock, hwContext); \
118 * Driver callback functions.
120 * Each DRI driver must have one of these structures with all the pointers set
121 * to appropriate functions within the driver.
123 * When glXCreateContext() is called, for example, it'll call a helper function
124 * dri_util.c which in turn will jump through the \a CreateContext pointer in
127 struct __DriverAPIRec
{
129 * Screen destruction callback
131 void (*DestroyScreen
)(__DRIscreenPrivate
*driScrnPriv
);
134 * Context creation callback
136 GLboolean (*CreateContext
)(const __GLcontextModes
*glVis
,
137 __DRIcontextPrivate
*driContextPriv
,
138 void *sharedContextPrivate
);
141 * Context destruction callback
143 void (*DestroyContext
)(__DRIcontextPrivate
*driContextPriv
);
146 * Buffer (drawable) creation callback
148 GLboolean (*CreateBuffer
)(__DRIscreenPrivate
*driScrnPriv
,
149 __DRIdrawablePrivate
*driDrawPriv
,
150 const __GLcontextModes
*glVis
,
151 GLboolean pixmapBuffer
);
154 * Buffer (drawable) destruction callback
156 void (*DestroyBuffer
)(__DRIdrawablePrivate
*driDrawPriv
);
159 * Buffer swapping callback
161 void (*SwapBuffers
)(__DRIdrawablePrivate
*driDrawPriv
);
164 * Context activation callback
166 GLboolean (*MakeCurrent
)(__DRIcontextPrivate
*driContextPriv
,
167 __DRIdrawablePrivate
*driDrawPriv
,
168 __DRIdrawablePrivate
*driReadPriv
);
171 * Context unbinding callback
173 GLboolean (*UnbindContext
)(__DRIcontextPrivate
*driContextPriv
);
176 * Retrieves statistics about buffer swap operations. Required if
177 * GLX_OML_sync_control or GLX_MESA_swap_frame_usage is supported.
179 int (*GetSwapInfo
)( __DRIdrawablePrivate
*dPriv
, __DRIswapInfo
* sInfo
);
183 * Required if GLX_SGI_video_sync or GLX_OML_sync_control is
186 int (*GetMSC
)( __DRIscreenPrivate
* priv
, int64_t * count
);
189 * These are required if GLX_OML_sync_control is supported.
192 int (*WaitForMSC
)( __DRIdrawablePrivate
*priv
, int64_t target_msc
,
193 int64_t divisor
, int64_t remainder
,
195 int (*WaitForSBC
)( __DRIdrawablePrivate
*priv
, int64_t target_sbc
,
196 int64_t * msc
, int64_t * sbc
);
198 int64_t (*SwapBuffersMSC
)( __DRIdrawablePrivate
*priv
, int64_t target_msc
,
199 int64_t divisor
, int64_t remainder
);
201 void (*CopySubBuffer
)(__DRIdrawablePrivate
*driDrawPriv
,
202 int x
, int y
, int w
, int h
);
205 * See corresponding field in \c __DRIscreenRec.
207 void (*setTexOffset
)(__DRIcontext
*pDRICtx
, GLint texname
,
208 unsigned long long offset
, GLint depth
, GLuint pitch
);
211 * New version of GetMSC so we can pass drawable data to the low level
212 * DRM driver (e.g. pipe info).
214 int (*GetDrawableMSC
) ( __DRIscreenPrivate
* priv
,
215 __DRIdrawablePrivate
*drawablePrivate
,
220 struct __DRIswapInfoRec
{
222 * Number of swapBuffers operations that have been *completed*.
224 u_int64_t swap_count
;
227 * Unadjusted system time of the last buffer swap. This is the time
228 * when the swap completed, not the time when swapBuffers was called.
233 * Number of swap operations that occurred after the swap deadline. That
234 * is if a swap happens more than swap_interval frames after the previous
235 * swap, it has missed its deadline. If swap_interval is 0, then the
236 * swap deadline is 1 frame after the previous swap.
238 u_int64_t swap_missed_count
;
241 * Amount of time used by the last swap that missed its deadline. This
242 * is calculated as (__glXGetUST() - swap_ust) / (swap_interval *
243 * time_for_single_vrefresh)). If the actual value of swap_interval is
244 * 0, then 1 is used instead. If swap_missed_count is non-zero, this
245 * should be greater-than 1.0.
247 float swap_missed_usage
;
252 * Per-drawable private DRI driver information.
254 struct __DRIdrawablePrivateRec
{
256 * Kernel drawable handle
258 drm_drawable_t hHWDrawable
;
261 * Driver's private drawable information.
263 * This structure is opaque.
268 * X's drawable ID associated with this private drawable.
270 __DRIdrawable
*pdraw
;
273 * Reference count for number of context's currently bound to this
276 * Once it reaches zero, the drawable can be destroyed.
278 * \note This behavior will change with GLX 1.3.
283 * Index of this drawable information in the SAREA.
288 * Pointer to the "drawable has changed ID" stamp in the SAREA.
290 unsigned int *pStamp
;
293 * Last value of the stamp.
295 * If this differs from the value stored at __DRIdrawablePrivate::pStamp,
296 * then the drawable information has been modified by the X server, and the
297 * drawable information (below) should be retrieved from the X server.
299 unsigned int lastStamp
;
304 * Drawable information used in software fallbacks.
312 drm_clip_rect_t
*pClipRects
;
316 * \name Back and depthbuffer
318 * Information about the back and depthbuffer where different from above.
323 int backClipRectType
;
324 int numBackClipRects
;
325 drm_clip_rect_t
*pBackClipRects
;
329 * \name Vertical blank tracking information
330 * Used for waiting on vertical blank events.
334 unsigned int vblFlags
;
338 * \name Monotonic MSC tracking
340 * Low level driver is responsible for updating msc_base and
341 * vblSeq values so that higher level code can calculate
342 * a new msc value or msc target for a WaitMSC call. The new value
344 * msc = msc_base + get_vblank_count() - vblank_base;
346 * And for waiting on a value, core code will use:
347 * actual_target = target_msc - msc_base + vblank_base;
355 * Pointer to context to which this drawable is currently bound.
357 __DRIcontextPrivate
*driContextPriv
;
360 * Pointer to screen on which this drawable was created.
362 __DRIscreenPrivate
*driScreenPriv
;
365 * Called via glXSwapBuffers().
367 void (*swapBuffers
)( __DRIdrawablePrivate
*dPriv
);
370 * Controls swap interval as used by GLX_SGI_swap_control and
371 * GLX_MESA_swap_control.
373 unsigned int swap_interval
;
377 * Per-context private driver information.
379 struct __DRIcontextPrivateRec
{
381 * Kernel context handle used to access the device lock.
383 drm_context_t hHWContext
;
386 * Device driver's private context data. This structure is opaque.
391 * Pointer back to the \c __DRIcontext that contains this structure.
396 * Pointer to drawable currently bound to this context for drawing.
398 __DRIdrawablePrivate
*driDrawablePriv
;
401 * Pointer to drawable currently bound to this context for reading.
403 __DRIdrawablePrivate
*driReadablePriv
;
406 * Pointer to screen on which this context was created.
408 __DRIscreenPrivate
*driScreenPriv
;
412 * Per-screen private driver information.
414 struct __DRIscreenPrivateRec
{
416 * Current screen's number
421 * Callback functions into the hardware-specific DRI driver code.
423 struct __DriverAPIRec DriverAPI
;
426 * DDX / 2D driver version information.
428 __DRIversion ddx_version
;
431 * DRI X extension version information.
433 __DRIversion dri_version
;
436 * DRM (kernel module) version information.
438 __DRIversion drm_version
;
441 * ID used when the client sets the drawable lock.
443 * The X server uses this value to detect if the client has died while
444 * holding the drawable lock.
449 * File descriptor returned when the kernel device driver is opened.
452 * - authenticate client to kernel
453 * - map the frame buffer, SAREA, etc.
454 * - close the kernel device driver
463 * - the device-independent per-drawable and per-context(?) information
468 * \name Direct frame buffer access information
469 * Used for software fallbacks.
482 * \name Device-dependent private information (stored in the SAREA).
484 * This data is accessed by the client driver only.
492 * Dummy context to which drawables are bound when not bound to any
495 * A dummy hHWContext is created for this context, and is used by the GL
496 * core when a hardware lock is required but the drawable is not currently
497 * bound (e.g., potentially during a SwapBuffers request). The dummy
498 * context is created when the first "real" context is created on this
501 __DRIcontextPrivate dummyContextPriv
;
504 * Device-dependent private information (not stored in the SAREA).
506 * This pointer is never touched by the DRI layer.
511 * Pointer back to the \c __DRIscreen that contains this structure.
516 * Extensions provided by this driver.
518 const __DRIextension
**extensions
;
523 * Used to store a version which includes a major range instead of a single
524 * major version number.
526 struct __DRIutilversionRec2
{
527 int major_min
; /** min allowed Major version number. */
528 int major_max
; /** max allowed Major version number. */
529 int minor
; /**< Minor version number. */
530 int patch
; /**< Patch-level. */
535 __driUtilMessage(const char *f
, ...);
539 __driUtilUpdateDrawableInfo(__DRIdrawablePrivate
*pdp
);
542 extern __DRIscreenPrivate
* __driUtilCreateNewScreen( int scr
, __DRIscreen
*psc
,
543 __GLcontextModes
* modes
,
544 const __DRIversion
* ddx_version
, const __DRIversion
* dri_version
,
545 const __DRIversion
* drm_version
, const __DRIframebuffer
* frame_buffer
,
546 drm_sarea_t
*pSAREA
, int fd
, int internal_api_version
,
547 const struct __DriverAPIRec
*driverAPI
);
549 /* Test the version of the internal GLX API. Returns a value like strcmp. */
551 driCompareGLXAPIVersion( GLint required_version
);
554 driCalculateSwapUsage( __DRIdrawablePrivate
*dPriv
,
555 int64_t last_swap_ust
, int64_t current_ust
);
558 * Pointer to the \c __DRIinterfaceMethods passed to the driver by the loader.
560 * This pointer is set in the driver's \c __driCreateNewScreen function and
561 * is defined in dri_util.c.
563 extern const __DRIinterfaceMethods
* dri_interface
;
565 #endif /* _DRI_UTIL_H_ */