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
;
60 typedef struct __DRIextensionRec __DRIextension
;
61 typedef struct __DRIcopySubBufferExtensionRec __DRIcopySubBufferExtension
;
62 typedef struct __DRIswapControlExtensionRec __DRIswapControlExtension
;
63 typedef struct __DRIallocateExtensionRec __DRIallocateExtension
;
64 typedef struct __DRIframeTrackingExtensionRec __DRIframeTrackingExtension
;
65 typedef struct __DRImediaStreamCounterExtensionRec __DRImediaStreamCounterExtension
;
66 typedef struct __DRItexOffsetExtensionRec __DRItexOffsetExtension
;
67 typedef struct __DRItexBufferExtensionRec __DRItexBufferExtension
;
72 * Extension struct. Drivers 'inherit' from this struct by embedding
73 * it as the first element in the extension struct. The
74 * __DRIscreen::getExtensions entry point will return a list of these
75 * structs and the loader can use the extensions it knows about by
76 * casting it to a more specific extension and optionally advertising
77 * the GLX extension. See below for examples.
79 * We never break API in for a DRI extension. If we need to change
80 * the way things work in a non-backwards compatible manner, we
81 * introduce a new extension. During a transition period, we can
82 * leave both the old and the new extension in the driver, which
83 * allows us to move to the new interface without having to update the
84 * loader(s) in lock step.
86 * However, we can add entry points to an extension over time as long
87 * as we don't break the old ones. As we add entry points to an
88 * extension, we increase the version number. The corresponding
89 * #define can be used to guard code that accesses the new entry
90 * points at compile time and the version field in the extension
91 * struct can be used at run-time to determine how to use the
94 struct __DRIextensionRec
{
100 * Used by drivers to indicate support for setting the read drawable.
102 #define __DRI_READ_DRAWABLE "DRI_ReadDrawable"
103 #define __DRI_READ_DRAWABLE_VERSION 1
106 * Used by drivers that implement the GLX_MESA_copy_sub_buffer extension.
108 #define __DRI_COPY_SUB_BUFFER "DRI_CopySubBuffer"
109 #define __DRI_COPY_SUB_BUFFER_VERSION 1
110 struct __DRIcopySubBufferExtensionRec
{
112 void (*copySubBuffer
)(__DRIdrawable
*drawable
, int x
, int y
, int w
, int h
);
116 * Used by drivers that implement the GLX_SGI_swap_control or
117 * GLX_MESA_swap_control extension.
119 #define __DRI_SWAP_CONTROL "DRI_SwapControl"
120 #define __DRI_SWAP_CONTROL_VERSION 1
121 struct __DRIswapControlExtensionRec
{
123 void (*setSwapInterval
)(__DRIdrawable
*drawable
, unsigned int inteval
);
124 unsigned int (*getSwapInterval
)(__DRIdrawable
*drawable
);
128 * Used by drivers that implement the GLX_MESA_allocate_memory.
130 #define __DRI_ALLOCATE "DRI_Allocate"
131 #define __DRI_ALLOCATE_VERSION 1
132 struct __DRIallocateExtensionRec
{
135 void *(*allocateMemory
)(__DRIscreen
*screen
, GLsizei size
,
136 GLfloat readfreq
, GLfloat writefreq
,
139 void (*freeMemory
)(__DRIscreen
*screen
, GLvoid
*pointer
);
141 GLuint (*memoryOffset
)(__DRIscreen
*screen
, const GLvoid
*pointer
);
145 * Used by drivers that implement the GLX_MESA_swap_frame_usage extension.
147 #define __DRI_FRAME_TRACKING "DRI_FrameTracking"
148 #define __DRI_FRAME_TRACKING_VERSION 1
149 struct __DRIframeTrackingExtensionRec
{
153 * Enable or disable frame usage tracking.
155 * \since Internal API version 20030317.
157 int (*frameTracking
)(__DRIdrawable
*drawable
, GLboolean enable
);
160 * Retrieve frame usage information.
162 * \since Internal API version 20030317.
164 int (*queryFrameTracking
)(__DRIdrawable
*drawable
,
165 int64_t * sbc
, int64_t * missedFrames
,
166 float * lastMissedUsage
, float * usage
);
171 * Used by drivers that implement the GLX_SGI_video_sync extension.
173 #define __DRI_MEDIA_STREAM_COUNTER "DRI_MediaStreamCounter"
174 #define __DRI_MEDIA_STREAM_COUNTER_VERSION 2
175 struct __DRImediaStreamCounterExtensionRec
{
179 * Get the number of vertical refreshes since some point in time before
180 * this function was first called (i.e., system start up).
182 int (*getMSC
)(__DRIscreen
*screen
, int64_t *msc
);
185 * Wait for the MSC to equal target_msc, or, if that has already passed,
186 * the next time (MSC % divisor) is equal to remainder. If divisor is
187 * zero, the function will return as soon as MSC is greater than or equal
190 int (*waitForMSC
)(__DRIdrawable
*drawable
,
191 int64_t target_msc
, int64_t divisor
, int64_t remainder
,
192 int64_t * msc
, int64_t * sbc
);
195 * Like the screen version of getMSC, but also takes a drawable so that
196 * the appropriate pipe's counter can be retrieved.
198 * Get the number of vertical refreshes since some point in time before
199 * this function was first called (i.e., system start up).
201 * \since Internal API version 2
203 int (*getDrawableMSC
)(__DRIscreen
*screen
, void *drawablePrivate
,
208 #define __DRI_TEX_OFFSET "DRI_TexOffset"
209 #define __DRI_TEX_OFFSET_VERSION 1
210 struct __DRItexOffsetExtensionRec
{
214 * Method to override base texture image with a driver specific 'offset'.
215 * The depth passed in allows e.g. to ignore the alpha channel of texture
216 * images where the non-alpha components don't occupy a whole texel.
218 * For GLX_EXT_texture_from_pixmap with AIGLX.
220 void (*setTexOffset
)(__DRIcontext
*pDRICtx
, GLint texname
,
221 unsigned long long offset
, GLint depth
, GLuint pitch
);
225 #define __DRI_TEX_BUFFER "DRI_TexBuffer"
226 #define __DRI_TEX_BUFFER_VERSION 1
227 struct __DRItexBufferExtensionRec
{
231 * Method to override base texture image with a DRM memory manager
232 * buffer object. The depth passed in allows e.g. to ignore the
233 * alpha channel of texture images where the non-alpha components
234 * don't occupy a whole texel.
236 * For GLX_EXT_texture_from_pixmap with AIGLX.
238 void (*setTexBuffer
)(__DRIcontext
*pDRICtx
,
239 GLint target
, unsigned long handle
,
240 GLint cpp
, GLuint pitch
, GLuint height
);
245 * Macros for building symbol and strings. Standard CPP two step...
248 #define __DRI_REAL_STRINGIFY(x) # x
249 #define __DRI_STRINGIFY(x) __DRI_REAL_STRINGIFY(x)
250 #define __DRI_REAL_MAKE_VERSION(name, version) name ## _ ## version
251 #define __DRI_MAKE_VERSION(name, version) __DRI_REAL_MAKE_VERSION(name, version)
254 * \name Functions and data provided by the driver.
258 #define __DRI_INTERFACE_VERSION 20070105
260 typedef void *(CREATENEWSCREENFUNC
)(int scr
, __DRIscreen
*psc
,
261 const __DRIversion
* ddx_version
, const __DRIversion
* dri_version
,
262 const __DRIversion
* drm_version
, const __DRIframebuffer
* frame_buffer
,
263 void * pSAREA
, int fd
, int internal_api_version
,
264 const __DRIinterfaceMethods
* interface
,
265 __GLcontextModes
** driver_modes
);
266 typedef CREATENEWSCREENFUNC
* PFNCREATENEWSCREENFUNC
;
268 #define __DRI_CREATE_NEW_SCREEN \
269 __DRI_MAKE_VERSION(__driCreateNewScreen, __DRI_INTERFACE_VERSION)
271 #define __DRI_CREATE_NEW_SCREEN_STRING \
272 __DRI_STRINGIFY(__DRI_CREATE_NEW_SCREEN)
274 extern CREATENEWSCREENFUNC __DRI_CREATE_NEW_SCREEN
;
277 /* DRI2 Entry point */
279 typedef void *(__DRI2_CREATE_NEW_SCREEN_FUNC
)(int scr
, __DRIscreen
*psc
,
280 const __DRIversion
* ddx_version
, const __DRIversion
* dri_version
,
281 const __DRIversion
* drm_version
, int fd
,
282 unsigned int sarea_handle
,
283 const __DRIinterfaceMethods
* interface
,
284 __GLcontextModes
** driver_modes
);
285 #define __DRI2_CREATE_NEW_SCREEN \
286 __DRI_MAKE_VERSION(__dri2CreateNewScreen, __DRI_INTERFACE_VERSION)
288 #define __DRI2_CREATE_NEW_SCREEN_STRING \
289 __DRI_STRINGIFY(__DRI2_CREATE_NEW_SCREEN)
291 extern __DRI2_CREATE_NEW_SCREEN_FUNC __DRI2_CREATE_NEW_SCREEN
;
295 * XML document describing the configuration options supported by the
298 extern const char __driConfigOptions
[];
304 * Stored version of some component (i.e., server-side DRI module, kernel-side
308 * There are several data structures that explicitly store a major version,
309 * minor version, and patch level. These structures should be modified to
310 * have a \c __DRIversionRec instead.
312 struct __DRIversionRec
{
313 int major
; /**< Major version number. */
314 int minor
; /**< Minor version number. */
315 int patch
; /**< Patch-level. */
319 typedef void (*__DRIfuncPtr
)(void);
321 struct __DRIinterfaceMethodsRec
{
323 * Create a list of \c __GLcontextModes structures.
325 __GLcontextModes
* (*createContextModes
)(unsigned count
,
326 size_t minimum_bytes_per_struct
);
329 * Destroy a list of \c __GLcontextModes structures.
332 * Determine if the drivers actually need to call this.
334 void (*destroyContextModes
)( __GLcontextModes
* modes
);
338 * \name Client/server protocol functions.
340 * These functions implement the DRI client/server protocol for
341 * context and drawable operations. Platforms that do not implement
342 * the wire protocol (e.g., EGL) will implement glorified no-op functions.
347 * This function is used to get information about the position, size, and
348 * clip rects of a drawable.
350 GLboolean (* getDrawableInfo
) ( __DRIdrawable
*drawable
,
351 unsigned int * index
, unsigned int * stamp
,
352 int * x
, int * y
, int * width
, int * height
,
353 int * numClipRects
, drm_clip_rect_t
** pClipRects
,
354 int * backX
, int * backY
,
355 int * numBackClipRects
, drm_clip_rect_t
** pBackClipRects
);
360 * \name Timing related functions.
364 * Get the 64-bit unadjusted system time (UST).
366 int (*getUST
)(int64_t * ust
);
369 * Get the media stream counter (MSC) rate.
371 * Matching the definition in GLX_OML_sync_control, this function returns
372 * the rate of the "media stream counter". In practical terms, this is
373 * the frame refresh rate of the display.
375 GLboolean (*getMSCRate
)(__DRIdrawable
*draw
,
376 int32_t * numerator
, int32_t * denominator
);
380 * Reports areas of the given drawable which have been modified by the
383 * \param drawable which the drawing was done to.
384 * \param rects rectangles affected, with the drawable origin as the
386 * \param x X offset of the drawable within the screen (used in the
388 * \param y Y offset of the drawable within the screen.
389 * \param front_buffer boolean flag for whether the drawing to the
390 * drawable was actually done directly to the front buffer (instead
391 * of backing storage, for example)
393 void (*reportDamage
)(__DRIdrawable
*draw
,
395 drm_clip_rect_t
*rects
, int num_rects
,
396 GLboolean front_buffer
);
399 * Ping the windowing system to get it to reemit info for the
400 * specified drawable in the DRI2 event buffer.
402 * \param draw the drawable for which to request info
404 void (*reemitDrawableInfo
)(__DRIdrawable
*draw
);
410 * Framebuffer information record. Used by libGL to communicate information
411 * about the framebuffer to the driver's \c __driCreateNewScreen function.
413 * In XFree86, most of this information is derrived from data returned by
414 * calling \c XF86DRIGetDeviceInfo.
416 * \sa XF86DRIGetDeviceInfo __DRIdisplayRec::createNewScreen
417 * __driUtilCreateNewScreen CallCreateNewScreen
419 * \bug This structure could be better named.
421 struct __DRIframebufferRec
{
422 unsigned char *base
; /**< Framebuffer base address in the CPU's
423 * address space. This value is calculated by
424 * calling \c drmMap on the framebuffer handle
425 * returned by \c XF86DRIGetDeviceInfo (or a
428 int size
; /**< Framebuffer size, in bytes. */
429 int stride
; /**< Number of bytes from one line to the next. */
430 int width
; /**< Pixel width of the framebuffer. */
431 int height
; /**< Pixel height of the framebuffer. */
432 int dev_priv_size
; /**< Size of the driver's dev-priv structure. */
433 void *dev_priv
; /**< Pointer to the driver's dev-priv structure. */
438 * Screen dependent methods. This structure is initialized during the
439 * \c __DRIdisplayRec::createScreen call.
441 struct __DRIscreenRec
{
443 * Method to destroy the private DRI screen data.
445 void (*destroyScreen
)(__DRIscreen
*screen
);
448 * Method to get screen extensions.
450 const __DRIextension
**(*getExtensions
)(__DRIscreen
*screen
);
453 * Method to create the private DRI drawable data and initialize the
454 * drawable dependent methods.
456 void *(*createNewDrawable
)(__DRIscreen
*screen
,
457 const __GLcontextModes
*modes
,
458 __DRIdrawable
*pdraw
,
459 drm_drawable_t hwDrawable
,
460 int renderType
, const int *attrs
);
463 * Opaque pointer to private per screen direct rendering data. \c NULL
464 * if direct rendering is not supported on this screen. Never
465 * dereferenced in libGL.
470 * Method to create the private DRI context data and initialize the
471 * context dependent methods.
473 * \since Internal API version 20031201.
475 void * (*createNewContext
)(__DRIscreen
*screen
,
476 const __GLcontextModes
*modes
,
478 __DRIcontext
*shared
,
479 drm_context_t hwContext
, __DRIcontext
*pctx
);
483 * Context dependent methods. This structure is initialized during the
484 * \c __DRIscreenRec::createContext call.
486 struct __DRIcontextRec
{
488 * Method to destroy the private DRI context data.
490 void (*destroyContext
)(__DRIcontext
*context
);
493 * Opaque pointer to private per context direct rendering data.
494 * \c NULL if direct rendering is not supported on the display or
495 * screen used to create this context. Never dereferenced in libGL.
500 * Method to bind a DRI drawable to a DRI graphics context.
502 * \since Internal API version 20050727.
504 GLboolean (*bindContext
)(__DRIcontext
*ctx
,
505 __DRIdrawable
*pdraw
,
506 __DRIdrawable
*pread
);
509 * Method to unbind a DRI drawable from a DRI graphics context.
511 * \since Internal API version 20050727.
513 GLboolean (*unbindContext
)(__DRIcontext
*ctx
);
517 * Drawable dependent methods. This structure is initialized during the
518 * \c __DRIscreenRec::createDrawable call. \c createDrawable is not called
519 * by libGL at this time. It's currently used via the dri_util.c utility code
522 struct __DRIdrawableRec
{
524 * Method to destroy the private DRI drawable data.
526 void (*destroyDrawable
)(__DRIdrawable
*drawable
);
529 * Method to swap the front and back buffers.
531 void (*swapBuffers
)(__DRIdrawable
*drawable
);
534 * Opaque pointer to private per drawable direct rendering data.
535 * \c NULL if direct rendering is not supported on the display or
536 * screen used to create this drawable. Never dereferenced in libGL.