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 #ifndef DRI_INTERFACE_H
39 #define DRI_INTERFACE_H
41 #include <GL/internal/glcore.h>
46 * \name DRI interface structures
48 * The following structures define the interface between the GLX client
49 * side library and the DRI (direct rendering infrastructure).
52 typedef struct __DRIdisplayRec __DRIdisplay
;
53 typedef struct __DRIscreenRec __DRIscreen
;
54 typedef struct __DRIcontextRec __DRIcontext
;
55 typedef struct __DRIdrawableRec __DRIdrawable
;
56 typedef struct __DRIdriverRec __DRIdriver
;
57 typedef struct __DRIframebufferRec __DRIframebuffer
;
58 typedef struct __DRIversionRec __DRIversion
;
59 typedef struct __DRIinterfaceMethodsRec __DRIinterfaceMethods
;
60 typedef unsigned long __DRIid
;
61 typedef void __DRInativeDisplay
;
66 * \name Functions provided by the driver loader.
70 * Type of a pointer to \c glXGetScreenDriver, as returned by
71 * \c glXGetProcAddress. This function is used to get the name of the DRI
72 * driver for the specified screen of the specified display. The driver
73 * name is typically used with \c glXGetDriverConfig.
75 * \sa glXGetScreenDriver, glXGetProcAddress, glXGetDriverConfig
77 typedef const char * (* PFNGLXGETSCREENDRIVERPROC
) (__DRInativeDisplay
*dpy
, int scrNum
);
80 * Type of a pointer to \c glXGetDriverConfig, as returned by
81 * \c glXGetProcAddress. This function is used to get the XML document
82 * describing the configuration options available for the specified driver.
84 * \sa glXGetDriverConfig, glXGetProcAddress, glXGetScreenDriver
86 typedef const char * (* PFNGLXGETDRIVERCONFIGPROC
) (const char *driverName
);
89 * Type of a pointer to \c glxEnableExtension, as returned by
90 * \c __DRIinterfaceMethods::getProcAddress. This function is used to enable
91 * a GLX extension on the specified screen.
93 typedef void (* PFNGLXSCRENABLEEXTENSIONPROC
) ( void *psc
, const char * name
);
98 * \name Functions and data provided by the driver.
102 typedef void *(CREATENEWSCREENFUNC
)(__DRInativeDisplay
*dpy
, int scrn
,
103 __DRIscreen
*psc
, const __GLcontextModes
* modes
,
104 const __DRIversion
* ddx_version
, const __DRIversion
* dri_version
,
105 const __DRIversion
* drm_version
, const __DRIframebuffer
* frame_buffer
,
106 void * pSAREA
, int fd
, int internal_api_version
,
107 const __DRIinterfaceMethods
* interface
,
108 __GLcontextModes
** driver_modes
);
109 typedef CREATENEWSCREENFUNC
* PFNCREATENEWSCREENFUNC
;
110 extern CREATENEWSCREENFUNC __driCreateNewScreen_20050727
;
114 * XML document describing the configuration options supported by the
117 extern const char __driConfigOptions
[];
123 * Stored version of some component (i.e., server-side DRI module, kernel-side
127 * There are several data structures that explicitly store a major version,
128 * minor version, and patch level. These structures should be modified to
129 * have a \c __DRIversionRec instead.
131 struct __DRIversionRec
{
132 int major
; /**< Major version number. */
133 int minor
; /**< Minor version number. */
134 int patch
; /**< Patch-level. */
138 typedef void (*__DRIfuncPtr
)(void);
140 struct __DRIinterfaceMethodsRec
{
142 * Get pointer to named function.
144 __DRIfuncPtr (*getProcAddress
)( const char * proc_name
);
147 * Create a list of \c __GLcontextModes structures.
149 __GLcontextModes
* (*createContextModes
)(unsigned count
,
150 size_t minimum_bytes_per_struct
);
153 * Destroy a list of \c __GLcontextModes structures.
156 * Determine if the drivers actually need to call this.
158 void (*destroyContextModes
)( __GLcontextModes
* modes
);
161 * Get the \c __DRIscreen for a given display and screen number.
163 __DRIscreen
*(*getScreen
)(__DRInativeDisplay
*dpy
, int screenNum
);
167 * \name Client/server protocol functions.
169 * These functions implement the DRI client/server protocol for
170 * context and drawable operations. Platforms that do not implement
171 * the wire protocol (e.g., EGL) will implement glorified no-op functions.
175 * Determine if the specified window ID still exists.
178 * Implementations may assume that the driver will only pass an ID into
179 * this function that actually corresponds to a window. On
180 * implementations where windows can only be destroyed by the DRI driver
181 * (e.g., EGL), this function is allowed to always return \c GL_TRUE.
183 GLboolean (*windowExists
)(__DRInativeDisplay
*dpy
, __DRIid draw
);
186 * Create the server-side portion of the GL context.
188 GLboolean (* createContext
)( __DRInativeDisplay
*dpy
, int screenNum
,
189 int configID
, void * contextID
, drm_context_t
* hw_context
);
192 * Destroy the server-side portion of the GL context.
194 GLboolean (* destroyContext
)( __DRInativeDisplay
*dpy
, int screenNum
,
198 * Create the server-side portion of the drawable.
200 GLboolean (*createDrawable
)( __DRInativeDisplay
* ndpy
, int screen
,
201 __DRIid drawable
, drm_drawable_t
* hHWDrawable
);
204 * Destroy the server-side portion of the drawable.
206 GLboolean (*destroyDrawable
)( __DRInativeDisplay
* ndpy
, int screen
,
210 * This function is used to get information about the position, size, and
211 * clip rects of a drawable.
213 GLboolean (* getDrawableInfo
) ( __DRInativeDisplay
*dpy
, int scrn
,
214 __DRIid draw
, unsigned int * index
, unsigned int * stamp
,
215 int * x
, int * y
, int * width
, int * height
,
216 int * numClipRects
, drm_clip_rect_t
** pClipRects
,
217 int * backX
, int * backY
,
218 int * numBackClipRects
, drm_clip_rect_t
** pBackClipRects
);
223 * \name Timing related functions.
227 * Get the 64-bit unadjusted system time (UST).
229 int (*getUST
)(int64_t * ust
);
232 * Get the media stream counter (MSC) rate.
234 * Matching the definition in GLX_OML_sync_control, this function returns
235 * the rate of the "media stream counter". In practical terms, this is
236 * the frame refresh rate of the display.
238 GLboolean (*getMSCRate
)(__DRInativeDisplay
* dpy
, __DRIid drawable
,
239 int32_t * numerator
, int32_t * denominator
);
245 * Framebuffer information record. Used by libGL to communicate information
246 * about the framebuffer to the driver's \c __driCreateNewScreen function.
248 * In XFree86, most of this information is derrived from data returned by
249 * calling \c XF86DRIGetDeviceInfo.
251 * \sa XF86DRIGetDeviceInfo __DRIdisplayRec::createNewScreen
252 * __driUtilCreateNewScreen CallCreateNewScreen
254 * \bug This structure could be better named.
256 struct __DRIframebufferRec
{
257 unsigned char *base
; /**< Framebuffer base address in the CPU's
258 * address space. This value is calculated by
259 * calling \c drmMap on the framebuffer handle
260 * returned by \c XF86DRIGetDeviceInfo (or a
263 int size
; /**< Framebuffer size, in bytes. */
264 int stride
; /**< Number of bytes from one line to the next. */
265 int width
; /**< Pixel width of the framebuffer. */
266 int height
; /**< Pixel height of the framebuffer. */
267 int dev_priv_size
; /**< Size of the driver's dev-priv structure. */
268 void *dev_priv
; /**< Pointer to the driver's dev-priv structure. */
273 * Screen dependent methods. This structure is initialized during the
274 * \c __DRIdisplayRec::createScreen call.
276 struct __DRIscreenRec
{
278 * Method to destroy the private DRI screen data.
280 void (*destroyScreen
)(__DRInativeDisplay
*dpy
, int scrn
, void *screenPrivate
);
283 * Method to create the private DRI drawable data and initialize the
284 * drawable dependent methods.
286 void *(*createNewDrawable
)(__DRInativeDisplay
*dpy
, const __GLcontextModes
*modes
,
287 __DRIid draw
, __DRIdrawable
*pdraw
,
288 int renderType
, const int *attrs
);
291 * Method to return a pointer to the DRI drawable data.
293 __DRIdrawable
*(*getDrawable
)(__DRInativeDisplay
*dpy
, __DRIid draw
,
294 void *drawablePrivate
);
297 * Opaque pointer to private per screen direct rendering data. \c NULL
298 * if direct rendering is not supported on this screen. Never
299 * dereferenced in libGL.
304 * Get the number of vertical refreshes since some point in time before
305 * this function was first called (i.e., system start up).
307 * \since Internal API version 20030317.
309 int (*getMSC
)( void *screenPrivate
, int64_t *msc
);
312 * Opaque pointer that points back to the containing
313 * \c __GLXscreenConfigs. This data structure is shared with DRI drivers
314 * but \c __GLXscreenConfigs is not. However, they are needed by some GLX
315 * functions called by DRI drivers.
317 * \since Internal API version 20030813.
322 * Functions associated with MESA_allocate_memory.
324 * \since Internal API version 20030815.
327 void *(*allocateMemory
)(__DRInativeDisplay
*dpy
, int scrn
, GLsizei size
,
328 GLfloat readfreq
, GLfloat writefreq
,
331 void (*freeMemory
)(__DRInativeDisplay
*dpy
, int scrn
, GLvoid
*pointer
);
333 GLuint (*memoryOffset
)(__DRInativeDisplay
*dpy
, int scrn
, const GLvoid
*pointer
);
337 * Method to create the private DRI context data and initialize the
338 * context dependent methods.
340 * \since Internal API version 20031201.
342 void * (*createNewContext
)(__DRInativeDisplay
*dpy
, const __GLcontextModes
*modes
,
344 void *sharedPrivate
, __DRIcontext
*pctx
);
348 * Context dependent methods. This structure is initialized during the
349 * \c __DRIscreenRec::createContext call.
351 struct __DRIcontextRec
{
353 * Method to destroy the private DRI context data.
355 void (*destroyContext
)(__DRInativeDisplay
*dpy
, int scrn
, void *contextPrivate
);
358 * Opaque pointer to private per context direct rendering data.
359 * \c NULL if direct rendering is not supported on the display or
360 * screen used to create this context. Never dereferenced in libGL.
365 * Pointer to the mode used to create this context.
367 * \since Internal API version 20040317.
369 const __GLcontextModes
* mode
;
372 * Method to bind a DRI drawable to a DRI graphics context.
374 * \since Internal API version 20050727.
376 GLboolean (*bindContext
)(__DRInativeDisplay
*dpy
, int scrn
, __DRIid draw
,
377 __DRIid read
, __DRIcontext
*ctx
);
380 * Method to unbind a DRI drawable from a DRI graphics context.
382 * \since Internal API version 20050727.
384 GLboolean (*unbindContext
)(__DRInativeDisplay
*dpy
, int scrn
, __DRIid draw
,
385 __DRIid read
, __DRIcontext
*ctx
);
389 * Drawable dependent methods. This structure is initialized during the
390 * \c __DRIscreenRec::createDrawable call. \c createDrawable is not called
391 * by libGL at this time. It's currently used via the dri_util.c utility code
394 struct __DRIdrawableRec
{
396 * Method to destroy the private DRI drawable data.
398 void (*destroyDrawable
)(__DRInativeDisplay
*dpy
, void *drawablePrivate
);
401 * Method to swap the front and back buffers.
403 void (*swapBuffers
)(__DRInativeDisplay
*dpy
, void *drawablePrivate
);
406 * Opaque pointer to private per drawable direct rendering data.
407 * \c NULL if direct rendering is not supported on the display or
408 * screen used to create this drawable. Never dereferenced in libGL.
413 * Get the number of completed swap buffers for this drawable.
415 * \since Internal API version 20030317.
417 int (*getSBC
)(__DRInativeDisplay
*dpy
, void *drawablePrivate
, int64_t *sbc
);
420 * Wait for the SBC to be greater than or equal target_sbc.
422 * \since Internal API version 20030317.
424 int (*waitForSBC
)( __DRInativeDisplay
* dpy
, void *drawablePriv
,
426 int64_t * msc
, int64_t * sbc
);
429 * Wait for the MSC to equal target_msc, or, if that has already passed,
430 * the next time (MSC % divisor) is equal to remainder. If divisor is
431 * zero, the function will return as soon as MSC is greater than or equal
434 * \since Internal API version 20030317.
436 int (*waitForMSC
)( __DRInativeDisplay
* dpy
, void *drawablePriv
,
437 int64_t target_msc
, int64_t divisor
, int64_t remainder
,
438 int64_t * msc
, int64_t * sbc
);
441 * Like \c swapBuffers, but does NOT have an implicit \c glFlush. Once
442 * rendering is complete, waits until MSC is equal to target_msc, or
443 * if that has already passed, waits until (MSC % divisor) is equal
444 * to remainder. If divisor is zero, the swap will happen as soon as
445 * MSC is greater than or equal to target_msc.
447 * \since Internal API version 20030317.
449 int64_t (*swapBuffersMSC
)(__DRInativeDisplay
*dpy
, void *drawablePrivate
,
451 int64_t divisor
, int64_t remainder
);
454 * Enable or disable frame usage tracking.
456 * \since Internal API version 20030317.
458 int (*frameTracking
)(__DRInativeDisplay
*dpy
, void *drawablePrivate
, GLboolean enable
);
461 * Retrieve frame usage information.
463 * \since Internal API version 20030317.
465 int (*queryFrameTracking
)(__DRInativeDisplay
*dpy
, void *drawablePrivate
,
466 int64_t * sbc
, int64_t * missedFrames
,
467 float * lastMissedUsage
, float * usage
);
470 * Used by drivers that implement the GLX_SGI_swap_control or
471 * GLX_MESA_swap_control extension.
473 * \since Internal API version 20030317.
475 unsigned swap_interval
;