2 * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
3 * (C) Copyright IBM Corporation 2004
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * on the rights to use, copy, modify, merge, publish, distribute, sub
10 * license, and/or sell copies of the Software, and to permit persons to whom
11 * the Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 * THE COPYRIGHT HOLDERS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
23 * USE OR OTHER DEALINGS IN THE SOFTWARE.
27 * \file dri_interface.h
29 * This file contains all the types and functions that define the interface
30 * between a DRI driver and driver loader. Currently, the most common driver
31 * loader is the XFree86 libGL.so. However, other loaders do exist, and in
32 * the future the server-side libglx.a will also be a loader.
34 * \author Kevin E. Martin <kevin@precisioninsight.com>
35 * \author Ian Romanick <idr@us.ibm.com>
38 /* FIXME: With a small amount of work, these two includes can be removed. */
42 #ifndef DRI_NEW_INTERFACE_ONLY
43 #include <GL/glxint.h>
46 #include <GL/internal/glcore.h>
50 * \name DRI interface structures
52 * The following structures define the interface between the GLX client
53 * side library and the DRI (direct rendering infrastructure).
56 typedef struct __DRIdisplayRec __DRIdisplay
;
57 typedef struct __DRIscreenRec __DRIscreen
;
58 typedef struct __DRIcontextRec __DRIcontext
;
59 typedef struct __DRIdrawableRec __DRIdrawable
;
60 typedef struct __DRIdriverRec __DRIdriver
;
61 typedef struct __DRIframebufferRec __DRIframebuffer
;
62 typedef struct __DRIversionRec __DRIversion
;
63 typedef unsigned long __DRIid
;
64 struct _XF86DRIClipRect
;
69 * \name Functions provided by the driver loader.
72 extern __DRIscreen
*__glXFindDRIScreen(Display
*dpy
, int scrn
);
76 * Type of a pointer to \c __glXGetInternalVersion, as returned by
77 * \c glXGetProcAddress.
79 * \sa __glXGetInternalVersion, glXGetProcAddress
81 typedef int (* PFNGLXGETINTERNALVERSIONPROC
) ( void );
84 * Type of a pointer to \c __glXWindowExists, as returned by
85 * \c glXGetProcAddress.
87 * \sa __glXWindowExists, glXGetProcAddress
89 typedef Bool (* PFNGLXWINDOWEXISTSPROC
) (Display
*dpy
, GLXDrawable draw
);
92 * Type of a pointer to \c __glXGetUST, as returned by \c glXGetProcAddress.
94 * \sa __glXGetUST, glXGetProcAddress
96 typedef int (* PFNGLXGETUSTPROC
) ( int64_t * ust
);
99 * Type of pointer to \c __glXCreateContextModes, as returned by
100 * \c glXGetProcAddress.
102 * \sa _gl_context_modes_create, glXGetProcAddress
105 typedef __GLcontextModes
* (* PFNGLXCREATECONTEXTMODES
) ( unsigned count
,
106 size_t minimum_bytes_per_struct
);
109 * Type of a pointer to \c glXGetScreenDriver, as returned by
110 * \c glXGetProcAddress. This function is used to get the name of the DRI
111 * driver for the specified screen of the specified display. The driver
112 * name is typically used with \c glXGetDriverConfig.
114 * \sa glXGetScreenDriver, glXGetProcAddress, glXGetDriverConfig
116 typedef const char * (* PFNGLXGETSCREENDRIVERPROC
) (Display
*dpy
, int scrNum
);
119 * Type of a pointer to \c glXGetDriverConfig, as returned by
120 * \c glXGetProcAddress. This function is used to get the XML document
121 * describing the configuration options available for the specified driver.
123 * \sa glXGetDriverConfig, glXGetProcAddress, glXGetScreenDriver
125 typedef const char * (* PFNGLXGETDRIVERCONFIGPROC
) (const char *driverName
);
128 * Type of a pointer to \c __glXScrEnableExtension, as returned by
129 * \c glXGetProcAddress. This function is used to enable a GLX extension
130 * on the specified screen.
132 * \sa __glXScrEnableExtension, glXGetProcAddress
134 typedef void (* PFNGLXSCRENABLEEXTENSIONPROC
) ( void *psc
, const char * name
);
137 * Type of a pointer to \c __glXGetDrawableInfo, as returned by
138 * \c glXGetProcAddress. This function is used to get information about the
139 * position, size, and clip rects of a drawable.
141 * \sa __glXGetDrawableInfo, glXGetProcAddress
143 typedef Bool (* PFNGLXGETDRAWABLEINFOPROC
) ( Display
*dpy
, int scrn
,
144 Drawable draw
, unsigned int * index
, unsigned int * stamp
,
145 int * x
, int * y
, int * width
, int * height
,
146 int * numClipRects
, struct _XF86DRIClipRect
** pClipRects
,
147 int * backX
, int * backY
,
148 int * numBackClipRects
, struct _XF86DRIClipRect
** pBackClipRects
);
153 * \name Functions and data provided by the driver.
157 extern void * __driCreateNewScreen( Display
*dpy
, int scrn
, __DRIscreen
*psc
,
158 const __GLcontextModes
* modes
, const __DRIversion
* ddx_version
,
159 const __DRIversion
* dri_version
, const __DRIversion
* drm_version
,
160 const __DRIframebuffer
* frame_buffer
, drmAddress pSAREA
, int fd
,
161 int internal_api_version
, __GLcontextModes
** driver_modes
);
163 #ifndef DRI_NEW_INTERFACE_ONLY
165 extern void *__driCreateScreen(Display
*dpy
, int scrn
, __DRIscreen
*psc
,
166 int numConfigs
, __GLXvisualConfig
*config
);
168 /** This is optionally implemented in each driver */
169 extern void __driRegisterExtensions( void );
171 #endif /* DRI_NEW_INTERFACE_ONLY */
175 * XML document describing the configuration options supported by the
178 extern const char __driConfigOptions
[];
184 * Stored version of some component (i.e., server-side DRI module, kernel-side
188 * There are several data structures that explicitly store a major version,
189 * minor version, and patch level. These structures should be modified to
190 * have a \c __DRIversionRec instead.
192 struct __DRIversionRec
{
193 int major
; /**< Major version number. */
194 int minor
; /**< Minor version number. */
195 int patch
; /**< Patch-level. */
199 * Framebuffer information record. Used by libGL to communicate information
200 * about the framebuffer to the driver's \c __driCreateNewScreen function.
202 * In XFree86, most of this information is derrived from data returned by
203 * calling \c XF86DRIGetDeviceInfo.
205 * \sa XF86DRIGetDeviceInfo __DRIdisplayRec::createNewScreen
206 * __driUtilCreateNewScreen CallCreateNewScreen
208 * \bug This structure could be better named.
210 struct __DRIframebufferRec
{
211 unsigned char *base
; /**< Framebuffer base address in the CPU's
212 * address space. This value is calculated by
213 * calling \c drmMap on the framebuffer handle
214 * returned by \c XF86DRIGetDeviceInfo (or a
217 int size
; /**< Framebuffer size, in bytes. */
218 int stride
; /**< Number of bytes from one line to the next. */
219 int width
; /**< Pixel width of the framebuffer. */
220 int height
; /**< Pixel height of the framebuffer. */
221 int dev_priv_size
; /**< Size of the driver's dev-priv structure. */
222 void *dev_priv
; /**< Pointer to the driver's dev-priv structure. */
227 * Screen dependent methods. This structure is initialized during the
228 * \c __DRIdisplayRec::createScreen call.
230 struct __DRIscreenRec
{
232 * Method to destroy the private DRI screen data.
234 void (*destroyScreen
)(Display
*dpy
, int scrn
, void *screenPrivate
);
237 * Method to create the private DRI context data and initialize the
238 * context dependent methods.
240 * \sa __DRIscreenRec::createNewContext driCreateContext
241 * driCreateNewContext
244 * This function has been replaced by \c __DRIscreenRec::createNewContext.
245 * New drivers will continue to export this method, but it will eventually
246 * (in the next XFree86 major relearse) go away.
248 #ifndef DRI_NEW_INTERFACE_ONLY
249 void *(*createContext
)(Display
*dpy
, XVisualInfo
*vis
, void *sharedPrivate
,
252 void * createContext
;
253 #endif /* DRI_NEW_INTERFACE_ONLY */
256 * Method to create the private DRI drawable data and initialize the
257 * drawable dependent methods.
259 void *(*createNewDrawable
)(Display
*dpy
, const __GLcontextModes
*modes
,
260 GLXDrawable draw
, __DRIdrawable
*pdraw
,
261 int renderType
, const int *attrs
);
264 * Method to return a pointer to the DRI drawable data.
266 __DRIdrawable
*(*getDrawable
)(Display
*dpy
, GLXDrawable draw
,
267 void *drawablePrivate
);
270 * Opaque pointer to private per screen direct rendering data. \c NULL
271 * if direct rendering is not supported on this screen. Never
272 * dereferenced in libGL.
277 * Get the number of vertical refreshes since some point in time before
278 * this function was first called (i.e., system start up).
280 * \since Internal API version 20030317.
282 int (*getMSC
)( void *screenPrivate
, int64_t *msc
);
285 * Opaque pointer that points back to the containing
286 * \c __GLXscreenConfigs. This data structure is shared with DRI drivers
287 * but \c __GLXscreenConfigs is not. However, they are needed by some GLX
288 * functions called by DRI drivers.
290 * \since Internal API version 20030813.
295 * Functions associated with MESA_allocate_memory.
297 * \since Internal API version 20030815.
300 void *(*allocateMemory
)(Display
*dpy
, int scrn
, GLsizei size
,
301 GLfloat readfreq
, GLfloat writefreq
,
304 void (*freeMemory
)(Display
*dpy
, int scrn
, GLvoid
*pointer
);
306 GLuint (*memoryOffset
)(Display
*dpy
, int scrn
, const GLvoid
*pointer
);
310 * Method to create the private DRI context data and initialize the
311 * context dependent methods.
313 * \since Internal API version 20031201.
315 void * (*createNewContext
)(Display
*dpy
, const __GLcontextModes
*modes
,
317 void *sharedPrivate
, __DRIcontext
*pctx
);
321 * Context dependent methods. This structure is initialized during the
322 * \c __DRIscreenRec::createContext call.
324 struct __DRIcontextRec
{
326 * Method to destroy the private DRI context data.
328 void (*destroyContext
)(Display
*dpy
, int scrn
, void *contextPrivate
);
331 * Method to bind a DRI drawable to a DRI graphics context.
333 * \deprecated Replaced by bindContext3.
335 #ifndef DRI_NEW_INTERFACE_ONLY
336 Bool (*bindContext
)(Display
*dpy
, int scrn
, GLXDrawable draw
,
340 #endif /* DRI_NEW_INTERFACE_ONLY */
343 * Method to unbind a DRI drawable to a DRI graphics context.
345 * \deprecated Replaced by unbindContext3.
347 #ifndef DRI_NEW_INTERFACE_ONLY
348 Bool (*unbindContext
)(Display
*dpy
, int scrn
, GLXDrawable draw
,
349 GLXContext gc
, int will_rebind
);
352 #endif /* DRI_NEW_INTERFACE_ONLY */
355 * Opaque pointer to private per context direct rendering data.
356 * \c NULL if direct rendering is not supported on the display or
357 * screen used to create this context. Never dereferenced in libGL.
362 * Method to bind a DRI drawable to a DRI graphics context.
364 * \since Internal API version 20030606.
365 * \deprecated Replaced by bindContext3.
367 #ifndef DRI_NEW_INTERFACE_ONLY
368 Bool (*bindContext2
)(Display
*dpy
, int scrn
, GLXDrawable draw
,
369 GLXDrawable read
, GLXContext gc
);
372 #endif /* DRI_NEW_INTERFACE_ONLY */
375 * Method to unbind a DRI drawable from a DRI graphics context.
377 * \since Internal API version 20030606.
378 * \deprecated Replaced by unbindContext3.
380 #ifndef DRI_NEW_INTERFACE_ONLY
381 Bool (*unbindContext2
)(Display
*dpy
, int scrn
, GLXDrawable draw
,
382 GLXDrawable read
, GLXContext gc
);
384 void *unbindContext2
;
385 #endif /* DRI_NEW_INTERFACE_ONLY */
388 * Pointer to the mode used to create this context.
390 * \since Internal API version 20040317.
392 const __GLcontextModes
* mode
;
395 * Method to bind a DRI drawable to a DRI graphics context.
397 * \since Internal API version 20040415.
399 Bool (*bindContext3
)(Display
*dpy
, int scrn
, __DRIid draw
,
400 __DRIid read
, __DRIcontext
*ctx
);
403 * Method to unbind a DRI drawable from a DRI graphics context.
405 * \since Internal API version 20040415.
407 Bool (*unbindContext3
)(Display
*dpy
, int scrn
, __DRIid draw
,
408 __DRIid read
, __DRIcontext
*ctx
);
412 * Drawable dependent methods. This structure is initialized during the
413 * \c __DRIscreenRec::createDrawable call. \c createDrawable is not called
414 * by libGL at this time. It's currently used via the dri_util.c utility code
417 struct __DRIdrawableRec
{
419 * Method to destroy the private DRI drawable data.
421 void (*destroyDrawable
)(Display
*dpy
, void *drawablePrivate
);
424 * Method to swap the front and back buffers.
426 void (*swapBuffers
)(Display
*dpy
, void *drawablePrivate
);
429 * Opaque pointer to private per drawable direct rendering data.
430 * \c NULL if direct rendering is not supported on the display or
431 * screen used to create this drawable. Never dereferenced in libGL.
436 * Get the number of completed swap buffers for this drawable.
438 * \since Internal API version 20030317.
440 int (*getSBC
)(Display
*dpy
, void *drawablePrivate
, int64_t *sbc
);
443 * Wait for the SBC to be greater than or equal target_sbc.
445 * \since Internal API version 20030317.
447 int (*waitForSBC
)( Display
* dpy
, void *drawablePriv
,
449 int64_t * msc
, int64_t * sbc
);
452 * Wait for the MSC to equal target_msc, or, if that has already passed,
453 * the next time (MSC % divisor) is equal to remainder. If divisor is
454 * zero, the function will return as soon as MSC is greater than or equal
457 * \since Internal API version 20030317.
459 int (*waitForMSC
)( Display
* dpy
, void *drawablePriv
,
460 int64_t target_msc
, int64_t divisor
, int64_t remainder
,
461 int64_t * msc
, int64_t * sbc
);
464 * Like \c swapBuffers, but does NOT have an implicit \c glFlush. Once
465 * rendering is complete, waits until MSC is equal to target_msc, or
466 * if that has already passed, waits until (MSC % divisor) is equal
467 * to remainder. If divisor is zero, the swap will happen as soon as
468 * MSC is greater than or equal to target_msc.
470 * \since Internal API version 20030317.
472 int64_t (*swapBuffersMSC
)(Display
*dpy
, void *drawablePrivate
,
474 int64_t divisor
, int64_t remainder
);
477 * Enable or disable frame usage tracking.
479 * \since Internal API version 20030317.
481 int (*frameTracking
)(Display
*dpy
, void *drawablePrivate
, Bool enable
);
484 * Retrieve frame usage information.
486 * \since Internal API version 20030317.
488 int (*queryFrameTracking
)(Display
*dpy
, void *drawablePrivate
,
489 int64_t * sbc
, int64_t * missedFrames
,
490 float * lastMissedUsage
, float * usage
);
493 * Used by drivers that implement the GLX_SGI_swap_control or
494 * GLX_MESA_swap_control extension.
496 * \since Internal API version 20030317.
498 unsigned swap_interval
;