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 __DRIcopySubBufferExtension driCopySubBufferExtension
;
80 extern const __DRIswapControlExtension driSwapControlExtension
;
83 * Used by DRI_VALIDATE_DRAWABLE_INFO
85 #define DRI_VALIDATE_DRAWABLE_INFO_ONCE(pDrawPriv) \
87 if (*(pDrawPriv->pStamp) != pDrawPriv->lastStamp) { \
88 __driUtilUpdateDrawableInfo(pDrawPriv); \
94 * Utility macro to validate the drawable information.
96 * See __DRIdrawablePrivate::pStamp and __DRIdrawablePrivate::lastStamp.
98 #define DRI_VALIDATE_DRAWABLE_INFO(psp, pdp) \
100 while (*(pdp->pStamp) != pdp->lastStamp) { \
101 register unsigned int hwContext = psp->pSAREA->lock.lock & \
102 ~(DRM_LOCK_HELD | DRM_LOCK_CONT); \
103 DRM_UNLOCK(psp->fd, &psp->pSAREA->lock, hwContext); \
105 DRM_SPINLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID); \
106 DRI_VALIDATE_DRAWABLE_INFO_ONCE(pdp); \
107 DRM_SPINUNLOCK(&psp->pSAREA->drawable_lock, psp->drawLockID); \
109 DRM_LIGHT_LOCK(psp->fd, &psp->pSAREA->lock, hwContext); \
115 * Driver callback functions.
117 * Each DRI driver must have one of these structures with all the pointers set
118 * to appropriate functions within the driver.
120 * When glXCreateContext() is called, for example, it'll call a helper function
121 * dri_util.c which in turn will jump through the \a CreateContext pointer in
124 struct __DriverAPIRec
{
126 * Screen destruction callback
128 void (*DestroyScreen
)(__DRIscreenPrivate
*driScrnPriv
);
131 * Context creation callback
133 GLboolean (*CreateContext
)(const __GLcontextModes
*glVis
,
134 __DRIcontextPrivate
*driContextPriv
,
135 void *sharedContextPrivate
);
138 * Context destruction callback
140 void (*DestroyContext
)(__DRIcontextPrivate
*driContextPriv
);
143 * Buffer (drawable) creation callback
145 GLboolean (*CreateBuffer
)(__DRIscreenPrivate
*driScrnPriv
,
146 __DRIdrawablePrivate
*driDrawPriv
,
147 const __GLcontextModes
*glVis
,
148 GLboolean pixmapBuffer
);
151 * Buffer (drawable) destruction callback
153 void (*DestroyBuffer
)(__DRIdrawablePrivate
*driDrawPriv
);
156 * Buffer swapping callback
158 void (*SwapBuffers
)(__DRIdrawablePrivate
*driDrawPriv
);
161 * Context activation callback
163 GLboolean (*MakeCurrent
)(__DRIcontextPrivate
*driContextPriv
,
164 __DRIdrawablePrivate
*driDrawPriv
,
165 __DRIdrawablePrivate
*driReadPriv
);
168 * Context unbinding callback
170 GLboolean (*UnbindContext
)(__DRIcontextPrivate
*driContextPriv
);
173 * Retrieves statistics about buffer swap operations. Required if
174 * GLX_OML_sync_control or GLX_MESA_swap_frame_usage is supported.
176 int (*GetSwapInfo
)( __DRIdrawablePrivate
*dPriv
, __DRIswapInfo
* sInfo
);
180 * Required if GLX_SGI_video_sync or GLX_OML_sync_control is
183 int (*GetMSC
)( __DRIscreenPrivate
* priv
, int64_t * count
);
186 * These are required if GLX_OML_sync_control is supported.
189 int (*WaitForMSC
)( __DRIdrawablePrivate
*priv
, int64_t target_msc
,
190 int64_t divisor
, int64_t remainder
,
192 int (*WaitForSBC
)( __DRIdrawablePrivate
*priv
, int64_t target_sbc
,
193 int64_t * msc
, int64_t * sbc
);
195 int64_t (*SwapBuffersMSC
)( __DRIdrawablePrivate
*priv
, int64_t target_msc
,
196 int64_t divisor
, int64_t remainder
);
198 void (*CopySubBuffer
)(__DRIdrawablePrivate
*driDrawPriv
,
199 int x
, int y
, int w
, int h
);
202 * See corresponding field in \c __DRIscreenRec.
204 void (*setTexOffset
)(__DRIcontext
*pDRICtx
, GLint texname
,
205 unsigned long long offset
, GLint depth
, GLuint pitch
);
209 struct __DRIswapInfoRec
{
211 * Number of swapBuffers operations that have been *completed*.
213 u_int64_t swap_count
;
216 * Unadjusted system time of the last buffer swap. This is the time
217 * when the swap completed, not the time when swapBuffers was called.
222 * Number of swap operations that occurred after the swap deadline. That
223 * is if a swap happens more than swap_interval frames after the previous
224 * swap, it has missed its deadline. If swap_interval is 0, then the
225 * swap deadline is 1 frame after the previous swap.
227 u_int64_t swap_missed_count
;
230 * Amount of time used by the last swap that missed its deadline. This
231 * is calculated as (__glXGetUST() - swap_ust) / (swap_interval *
232 * time_for_single_vrefresh)). If the actual value of swap_interval is
233 * 0, then 1 is used instead. If swap_missed_count is non-zero, this
234 * should be greater-than 1.0.
236 float swap_missed_usage
;
241 * Per-drawable private DRI driver information.
243 struct __DRIdrawablePrivateRec
{
245 * Kernel drawable handle
247 drm_drawable_t hHWDrawable
;
250 * Driver's private drawable information.
252 * This structure is opaque.
257 * X's drawable ID associated with this private drawable.
259 __DRIdrawable
*pdraw
;
262 * Reference count for number of context's currently bound to this
265 * Once it reaches zero, the drawable can be destroyed.
267 * \note This behavior will change with GLX 1.3.
272 * Index of this drawable information in the SAREA.
277 * Pointer to the "drawable has changed ID" stamp in the SAREA.
279 unsigned int *pStamp
;
282 * Last value of the stamp.
284 * If this differs from the value stored at __DRIdrawablePrivate::pStamp,
285 * then the drawable information has been modified by the X server, and the
286 * drawable information (below) should be retrieved from the X server.
288 unsigned int lastStamp
;
293 * Drawable information used in software fallbacks.
301 drm_clip_rect_t
*pClipRects
;
305 * \name Back and depthbuffer
307 * Information about the back and depthbuffer where different from above.
312 int backClipRectType
;
313 int numBackClipRects
;
314 drm_clip_rect_t
*pBackClipRects
;
318 * Pointer to context to which this drawable is currently bound.
320 __DRIcontextPrivate
*driContextPriv
;
323 * Pointer to screen on which this drawable was created.
325 __DRIscreenPrivate
*driScreenPriv
;
328 * Called via glXSwapBuffers().
330 void (*swapBuffers
)( __DRIdrawablePrivate
*dPriv
);
333 * Controls swap interval as used by GLX_SGI_swap_control and
334 * GLX_MESA_swap_control.
336 unsigned int swap_interval
;
340 * Per-context private driver information.
342 struct __DRIcontextPrivateRec
{
344 * Kernel context handle used to access the device lock.
346 drm_context_t hHWContext
;
349 * Device driver's private context data. This structure is opaque.
354 * Pointer back to the \c __DRIcontext that contains this structure.
359 * Pointer to drawable currently bound to this context for drawing.
361 __DRIdrawablePrivate
*driDrawablePriv
;
364 * Pointer to drawable currently bound to this context for reading.
366 __DRIdrawablePrivate
*driReadablePriv
;
369 * Pointer to screen on which this context was created.
371 __DRIscreenPrivate
*driScreenPriv
;
375 * Per-screen private driver information.
377 struct __DRIscreenPrivateRec
{
379 * Current screen's number
384 * Callback functions into the hardware-specific DRI driver code.
386 struct __DriverAPIRec DriverAPI
;
389 * DDX / 2D driver version information.
391 __DRIversion ddx_version
;
394 * DRI X extension version information.
396 __DRIversion dri_version
;
399 * DRM (kernel module) version information.
401 __DRIversion drm_version
;
404 * ID used when the client sets the drawable lock.
406 * The X server uses this value to detect if the client has died while
407 * holding the drawable lock.
412 * File descriptor returned when the kernel device driver is opened.
415 * - authenticate client to kernel
416 * - map the frame buffer, SAREA, etc.
417 * - close the kernel device driver
426 * - the device-independent per-drawable and per-context(?) information
431 * \name Direct frame buffer access information
432 * Used for software fallbacks.
445 * \name Device-dependent private information (stored in the SAREA).
447 * This data is accessed by the client driver only.
455 * Dummy context to which drawables are bound when not bound to any
458 * A dummy hHWContext is created for this context, and is used by the GL
459 * core when a hardware lock is required but the drawable is not currently
460 * bound (e.g., potentially during a SwapBuffers request). The dummy
461 * context is created when the first "real" context is created on this
464 __DRIcontextPrivate dummyContextPriv
;
467 * Device-dependent private information (not stored in the SAREA).
469 * This pointer is never touched by the DRI layer.
474 * Pointer back to the \c __DRIscreen that contains this structure.
479 * Extensions provided by this driver.
481 const __DRIextension
**extensions
;
486 * Used to store a version which includes a major range instead of a single
487 * major version number.
489 struct __DRIutilversionRec2
{
490 int major_min
; /** min allowed Major version number. */
491 int major_max
; /** max allowed Major version number. */
492 int minor
; /**< Minor version number. */
493 int patch
; /**< Patch-level. */
498 __driUtilMessage(const char *f
, ...);
502 __driUtilUpdateDrawableInfo(__DRIdrawablePrivate
*pdp
);
505 extern __DRIscreenPrivate
* __driUtilCreateNewScreen( int scr
, __DRIscreen
*psc
,
506 __GLcontextModes
* modes
,
507 const __DRIversion
* ddx_version
, const __DRIversion
* dri_version
,
508 const __DRIversion
* drm_version
, const __DRIframebuffer
* frame_buffer
,
509 drm_sarea_t
*pSAREA
, int fd
, int internal_api_version
,
510 const struct __DriverAPIRec
*driverAPI
);
512 /* Test the version of the internal GLX API. Returns a value like strcmp. */
514 driCompareGLXAPIVersion( GLint required_version
);
517 driCalculateSwapUsage( __DRIdrawablePrivate
*dPriv
,
518 int64_t last_swap_ust
, int64_t current_ust
);
521 * Pointer to the \c __DRIinterfaceMethods passed to the driver by the loader.
523 * This pointer is set in the driver's \c __driCreateNewScreen function and
524 * is defined in dri_util.c.
526 extern const __DRIinterfaceMethods
* dri_interface
;
528 #endif /* _DRI_UTIL_H_ */