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>
45 * \name DRI interface structures
47 * The following structures define the interface between the GLX client
48 * side library and the DRI (direct rendering infrastructure).
51 typedef struct __DRIdisplayRec __DRIdisplay
;
52 typedef struct __DRIscreenRec __DRIscreen
;
53 typedef struct __DRIcontextRec __DRIcontext
;
54 typedef struct __DRIdrawableRec __DRIdrawable
;
55 typedef struct __DRIdriverRec __DRIdriver
;
56 typedef struct __DRIframebufferRec __DRIframebuffer
;
57 typedef struct __DRIversionRec __DRIversion
;
58 typedef struct __DRIinterfaceMethodsRec __DRIinterfaceMethods
;
63 * \name Functions provided by the driver loader.
67 * Type of a pointer to \c glXGetScreenDriver, as returned by
68 * \c glXGetProcAddress. This function is used to get the name of the DRI
69 * driver for the specified screen of the specified display. The driver
70 * name is typically used with \c glXGetDriverConfig.
72 * \sa glXGetScreenDriver, glXGetProcAddress, glXGetDriverConfig
74 typedef const char * (* PFNGLXGETSCREENDRIVERPROC
) (__DRIscreen
*screen
);
77 * Type of a pointer to \c glXGetDriverConfig, as returned by
78 * \c glXGetProcAddress. This function is used to get the XML document
79 * describing the configuration options available for the specified driver.
81 * \sa glXGetDriverConfig, glXGetProcAddress, glXGetScreenDriver
83 typedef const char * (* PFNGLXGETDRIVERCONFIGPROC
) (const char *driverName
);
86 * Type of a pointer to \c glxEnableExtension, as returned by
87 * \c __DRIinterfaceMethods::getProcAddress. This function is used to enable
88 * a GLX extension on the specified screen.
90 typedef void (* PFNGLXSCRENABLEEXTENSIONPROC
) (__DRIscreen
*screen
,
96 * Macros for building symbol and strings. Standard CPP two step...
99 #define __DRI_REAL_STRINGIFY(x) # x
100 #define __DRI_STRINGIFY(x) __DRI_REAL_STRINGIFY(x)
101 #define __DRI_REAL_MAKE_VERSION(name, version) name ## _ ## version
102 #define __DRI_MAKE_VERSION(name, version) __DRI_REAL_MAKE_VERSION(name, version)
104 #define __DRI_CREATE_NEW_SCREEN \
105 __DRI_MAKE_VERSION(__driCreateNewScreen, __DRI_INTERFACE_VERSION)
107 #define __DRI_CREATE_NEW_SCREEN_STRING \
108 __DRI_STRINGIFY(__DRI_CREATE_NEW_SCREEN)
111 * \name Functions and data provided by the driver.
115 #define __DRI_INTERFACE_VERSION 20070105
117 typedef void *(CREATENEWSCREENFUNC
)(int scr
, __DRIscreen
*psc
,
118 const __DRIversion
* ddx_version
, const __DRIversion
* dri_version
,
119 const __DRIversion
* drm_version
, const __DRIframebuffer
* frame_buffer
,
120 void * pSAREA
, int fd
, int internal_api_version
,
121 const __DRIinterfaceMethods
* interface
,
122 __GLcontextModes
** driver_modes
);
123 typedef CREATENEWSCREENFUNC
* PFNCREATENEWSCREENFUNC
;
124 extern CREATENEWSCREENFUNC __DRI_CREATE_NEW_SCREEN
;
129 * XML document describing the configuration options supported by the
132 extern const char __driConfigOptions
[];
138 * Stored version of some component (i.e., server-side DRI module, kernel-side
142 * There are several data structures that explicitly store a major version,
143 * minor version, and patch level. These structures should be modified to
144 * have a \c __DRIversionRec instead.
146 struct __DRIversionRec
{
147 int major
; /**< Major version number. */
148 int minor
; /**< Minor version number. */
149 int patch
; /**< Patch-level. */
153 typedef void (*__DRIfuncPtr
)(void);
155 struct __DRIinterfaceMethodsRec
{
157 * Get pointer to named function.
159 __DRIfuncPtr (*getProcAddress
)( const char * proc_name
);
162 * Create a list of \c __GLcontextModes structures.
164 __GLcontextModes
* (*createContextModes
)(unsigned count
,
165 size_t minimum_bytes_per_struct
);
168 * Destroy a list of \c __GLcontextModes structures.
171 * Determine if the drivers actually need to call this.
173 void (*destroyContextModes
)( __GLcontextModes
* modes
);
177 * \name Client/server protocol functions.
179 * These functions implement the DRI client/server protocol for
180 * context and drawable operations. Platforms that do not implement
181 * the wire protocol (e.g., EGL) will implement glorified no-op functions.
186 * This function is used to get information about the position, size, and
187 * clip rects of a drawable.
189 GLboolean (* getDrawableInfo
) ( __DRIdrawable
*drawable
,
190 unsigned int * index
, unsigned int * stamp
,
191 int * x
, int * y
, int * width
, int * height
,
192 int * numClipRects
, drm_clip_rect_t
** pClipRects
,
193 int * backX
, int * backY
,
194 int * numBackClipRects
, drm_clip_rect_t
** pBackClipRects
);
199 * \name Timing related functions.
203 * Get the 64-bit unadjusted system time (UST).
205 int (*getUST
)(int64_t * ust
);
208 * Get the media stream counter (MSC) rate.
210 * Matching the definition in GLX_OML_sync_control, this function returns
211 * the rate of the "media stream counter". In practical terms, this is
212 * the frame refresh rate of the display.
214 GLboolean (*getMSCRate
)(__DRIdrawable
*draw
,
215 int32_t * numerator
, int32_t * denominator
);
219 * Reports areas of the given drawable which have been modified by the
222 * \param drawable which the drawing was done to.
223 * \param rects rectangles affected, with the drawable origin as the
225 * \param x X offset of the drawable within the screen (used in the
227 * \param y Y offset of the drawable within the screen.
228 * \param front_buffer boolean flag for whether the drawing to the
229 * drawable was actually done directly to the front buffer (instead
230 * of backing storage, for example)
232 void (*reportDamage
)(__DRIdrawable
*draw
,
234 drm_clip_rect_t
*rects
, int num_rects
,
235 GLboolean front_buffer
);
240 * Framebuffer information record. Used by libGL to communicate information
241 * about the framebuffer to the driver's \c __driCreateNewScreen function.
243 * In XFree86, most of this information is derrived from data returned by
244 * calling \c XF86DRIGetDeviceInfo.
246 * \sa XF86DRIGetDeviceInfo __DRIdisplayRec::createNewScreen
247 * __driUtilCreateNewScreen CallCreateNewScreen
249 * \bug This structure could be better named.
251 struct __DRIframebufferRec
{
252 unsigned char *base
; /**< Framebuffer base address in the CPU's
253 * address space. This value is calculated by
254 * calling \c drmMap on the framebuffer handle
255 * returned by \c XF86DRIGetDeviceInfo (or a
258 int size
; /**< Framebuffer size, in bytes. */
259 int stride
; /**< Number of bytes from one line to the next. */
260 int width
; /**< Pixel width of the framebuffer. */
261 int height
; /**< Pixel height of the framebuffer. */
262 int dev_priv_size
; /**< Size of the driver's dev-priv structure. */
263 void *dev_priv
; /**< Pointer to the driver's dev-priv structure. */
268 * Screen dependent methods. This structure is initialized during the
269 * \c __DRIdisplayRec::createScreen call.
271 struct __DRIscreenRec
{
273 * Method to destroy the private DRI screen data.
275 void (*destroyScreen
)(__DRIscreen
*screen
);
278 * Method to create the private DRI drawable data and initialize the
279 * drawable dependent methods.
281 void *(*createNewDrawable
)(__DRIscreen
*screen
,
282 const __GLcontextModes
*modes
,
283 __DRIdrawable
*pdraw
,
284 drm_drawable_t hwDrawable
,
285 int renderType
, const int *attrs
);
288 * Opaque pointer to private per screen direct rendering data. \c NULL
289 * if direct rendering is not supported on this screen. Never
290 * dereferenced in libGL.
295 * Get the number of vertical refreshes since some point in time before
296 * this function was first called (i.e., system start up).
298 * \since Internal API version 20030317.
300 int (*getMSC
)(__DRIscreen
*screen
, int64_t *msc
);
303 * Functions associated with MESA_allocate_memory.
305 * \since Internal API version 20030815.
308 void *(*allocateMemory
)(__DRIscreen
*screen
, GLsizei size
,
309 GLfloat readfreq
, GLfloat writefreq
,
312 void (*freeMemory
)(__DRIscreen
*screen
, GLvoid
*pointer
);
314 GLuint (*memoryOffset
)(__DRIscreen
*screen
, const GLvoid
*pointer
);
318 * Method to create the private DRI context data and initialize the
319 * context dependent methods.
321 * \since Internal API version 20031201.
323 void * (*createNewContext
)(__DRIscreen
*screen
,
324 const __GLcontextModes
*modes
,
327 drm_context_t hwContext
, __DRIcontext
*pctx
);
330 * Method to override base texture image with a driver specific 'offset'.
331 * The depth passed in allows e.g. to ignore the alpha channel of texture
332 * images where the non-alpha components don't occupy a whole texel.
334 * For GLX_EXT_texture_from_pixmap with AIGLX.
336 * \since Internal API version 20070121.
338 void (*setTexOffset
)(__DRIcontext
*pDRICtx
, GLint texname
,
339 unsigned long long offset
, GLint depth
, GLuint pitch
);
343 * Context dependent methods. This structure is initialized during the
344 * \c __DRIscreenRec::createContext call.
346 struct __DRIcontextRec
{
348 * Method to destroy the private DRI context data.
350 void (*destroyContext
)(__DRIcontext
*context
);
353 * Opaque pointer to private per context direct rendering data.
354 * \c NULL if direct rendering is not supported on the display or
355 * screen used to create this context. Never dereferenced in libGL.
360 * Method to bind a DRI drawable to a DRI graphics context.
362 * \since Internal API version 20050727.
364 GLboolean (*bindContext
)(__DRIcontext
*ctx
,
365 __DRIdrawable
*pdraw
,
366 __DRIdrawable
*pread
);
369 * Method to unbind a DRI drawable from a DRI graphics context.
371 * \since Internal API version 20050727.
373 GLboolean (*unbindContext
)(__DRIcontext
*ctx
);
377 * Drawable dependent methods. This structure is initialized during the
378 * \c __DRIscreenRec::createDrawable call. \c createDrawable is not called
379 * by libGL at this time. It's currently used via the dri_util.c utility code
382 struct __DRIdrawableRec
{
384 * Method to destroy the private DRI drawable data.
386 void (*destroyDrawable
)(__DRIdrawable
*drawable
);
389 * Method to swap the front and back buffers.
391 void (*swapBuffers
)(__DRIdrawable
*drawable
);
394 * Opaque pointer to private per drawable direct rendering data.
395 * \c NULL if direct rendering is not supported on the display or
396 * screen used to create this drawable. Never dereferenced in libGL.
401 * Get the number of completed swap buffers for this drawable.
403 * \since Internal API version 20030317.
405 int (*getSBC
)(__DRIdrawable
*drawable
, int64_t *sbc
);
408 * Wait for the SBC to be greater than or equal target_sbc.
410 * \since Internal API version 20030317.
412 int (*waitForSBC
)(__DRIdrawable
*drawable
,
414 int64_t * msc
, int64_t * sbc
);
417 * Wait for the MSC to equal target_msc, or, if that has already passed,
418 * the next time (MSC % divisor) is equal to remainder. If divisor is
419 * zero, the function will return as soon as MSC is greater than or equal
422 * \since Internal API version 20030317.
424 int (*waitForMSC
)(__DRIdrawable
*drawable
,
425 int64_t target_msc
, int64_t divisor
, int64_t remainder
,
426 int64_t * msc
, int64_t * sbc
);
429 * Like \c swapBuffers, but does NOT have an implicit \c glFlush. Once
430 * rendering is complete, waits until MSC is equal to target_msc, or
431 * if that has already passed, waits until (MSC % divisor) is equal
432 * to remainder. If divisor is zero, the swap will happen as soon as
433 * MSC is greater than or equal to target_msc.
435 * \since Internal API version 20030317.
437 int64_t (*swapBuffersMSC
)(__DRIdrawable
*drawable
,
439 int64_t divisor
, int64_t remainder
);
442 * Enable or disable frame usage tracking.
444 * \since Internal API version 20030317.
446 int (*frameTracking
)(__DRIdrawable
*drawable
, GLboolean enable
);
449 * Retrieve frame usage information.
451 * \since Internal API version 20030317.
453 int (*queryFrameTracking
)(__DRIdrawable
*drawable
,
454 int64_t * sbc
, int64_t * missedFrames
,
455 float * lastMissedUsage
, float * usage
);
458 * Used by drivers that implement the GLX_SGI_swap_control or
459 * GLX_MESA_swap_control extension.
461 * \since Internal API version 20030317.
463 unsigned swap_interval
;
466 * Used by drivers that implement the GLX_MESA_copy_sub_buffer extension.
468 * \since Internal API version 20060314.
470 void (*copySubBuffer
)(__DRIdrawable
*drawable
,
471 int x
, int y
, int w
, int h
);