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 1
175 struct __DRImediaStreamCounterExtensionRec
{
179 * Wait for the MSC to equal target_msc, or, if that has already passed,
180 * the next time (MSC % divisor) is equal to remainder. If divisor is
181 * zero, the function will return as soon as MSC is greater than or equal
184 int (*waitForMSC
)(__DRIdrawable
*drawable
,
185 int64_t target_msc
, int64_t divisor
, int64_t remainder
,
186 int64_t * msc
, int64_t * sbc
);
189 * Get the number of vertical refreshes since some point in time before
190 * this function was first called (i.e., system start up).
192 int (*getDrawableMSC
)(__DRIscreen
*screen
, __DRIdrawable
*drawable
,
197 #define __DRI_TEX_OFFSET "DRI_TexOffset"
198 #define __DRI_TEX_OFFSET_VERSION 1
199 struct __DRItexOffsetExtensionRec
{
203 * Method to override base texture image with a driver specific 'offset'.
204 * The depth passed in allows e.g. to ignore the alpha channel of texture
205 * images where the non-alpha components don't occupy a whole texel.
207 * For GLX_EXT_texture_from_pixmap with AIGLX.
209 void (*setTexOffset
)(__DRIcontext
*pDRICtx
, GLint texname
,
210 unsigned long long offset
, GLint depth
, GLuint pitch
);
214 #define __DRI_TEX_BUFFER "DRI_TexBuffer"
215 #define __DRI_TEX_BUFFER_VERSION 1
216 struct __DRItexBufferExtensionRec
{
220 * Method to override base texture image with a DRM memory manager
221 * buffer object. The depth passed in allows e.g. to ignore the
222 * alpha channel of texture images where the non-alpha components
223 * don't occupy a whole texel.
225 * For GLX_EXT_texture_from_pixmap with AIGLX.
227 void (*setTexBuffer
)(__DRIcontext
*pDRICtx
,
228 GLint target
, unsigned long handle
,
229 GLint cpp
, GLuint pitch
, GLuint height
);
234 * Macros for building symbol and strings. Standard CPP two step...
237 #define __DRI_REAL_STRINGIFY(x) # x
238 #define __DRI_STRINGIFY(x) __DRI_REAL_STRINGIFY(x)
239 #define __DRI_REAL_MAKE_VERSION(name, version) name ## _ ## version
240 #define __DRI_MAKE_VERSION(name, version) __DRI_REAL_MAKE_VERSION(name, version)
243 * \name Functions and data provided by the driver.
247 #define __DRI_INTERFACE_VERSION 20070105
249 typedef void *(CREATENEWSCREENFUNC
)(int scr
, __DRIscreen
*psc
,
250 const __DRIversion
* ddx_version
, const __DRIversion
* dri_version
,
251 const __DRIversion
* drm_version
, const __DRIframebuffer
* frame_buffer
,
252 void * pSAREA
, int fd
, int internal_api_version
,
253 const __DRIinterfaceMethods
* interface
,
254 __GLcontextModes
** driver_modes
);
255 typedef CREATENEWSCREENFUNC
* PFNCREATENEWSCREENFUNC
;
257 #define __DRI_CREATE_NEW_SCREEN \
258 __DRI_MAKE_VERSION(__driCreateNewScreen, __DRI_INTERFACE_VERSION)
260 #define __DRI_CREATE_NEW_SCREEN_STRING \
261 __DRI_STRINGIFY(__DRI_CREATE_NEW_SCREEN)
263 extern CREATENEWSCREENFUNC __DRI_CREATE_NEW_SCREEN
;
266 /* DRI2 Entry point */
268 typedef void *(__DRI2_CREATE_NEW_SCREEN_FUNC
)(int scr
, __DRIscreen
*psc
,
269 const __DRIversion
* ddx_version
, const __DRIversion
* dri_version
,
270 const __DRIversion
* drm_version
, int fd
,
271 unsigned int sarea_handle
,
272 const __DRIinterfaceMethods
* interface
,
273 __GLcontextModes
** driver_modes
);
274 #define __DRI2_CREATE_NEW_SCREEN \
275 __DRI_MAKE_VERSION(__dri2CreateNewScreen, __DRI_INTERFACE_VERSION)
277 #define __DRI2_CREATE_NEW_SCREEN_STRING \
278 __DRI_STRINGIFY(__DRI2_CREATE_NEW_SCREEN)
280 extern __DRI2_CREATE_NEW_SCREEN_FUNC __DRI2_CREATE_NEW_SCREEN
;
284 * XML document describing the configuration options supported by the
287 extern const char __driConfigOptions
[];
293 * Stored version of some component (i.e., server-side DRI module, kernel-side
297 * There are several data structures that explicitly store a major version,
298 * minor version, and patch level. These structures should be modified to
299 * have a \c __DRIversionRec instead.
301 struct __DRIversionRec
{
302 int major
; /**< Major version number. */
303 int minor
; /**< Minor version number. */
304 int patch
; /**< Patch-level. */
308 typedef void (*__DRIfuncPtr
)(void);
310 struct __DRIinterfaceMethodsRec
{
312 * Create a list of \c __GLcontextModes structures.
314 __GLcontextModes
* (*createContextModes
)(unsigned count
,
315 size_t minimum_bytes_per_struct
);
318 * Destroy a list of \c __GLcontextModes structures.
321 * Determine if the drivers actually need to call this.
323 void (*destroyContextModes
)( __GLcontextModes
* modes
);
327 * \name Client/server protocol functions.
329 * These functions implement the DRI client/server protocol for
330 * context and drawable operations. Platforms that do not implement
331 * the wire protocol (e.g., EGL) will implement glorified no-op functions.
336 * This function is used to get information about the position, size, and
337 * clip rects of a drawable.
339 GLboolean (* getDrawableInfo
) ( __DRIdrawable
*drawable
,
340 unsigned int * index
, unsigned int * stamp
,
341 int * x
, int * y
, int * width
, int * height
,
342 int * numClipRects
, drm_clip_rect_t
** pClipRects
,
343 int * backX
, int * backY
,
344 int * numBackClipRects
, drm_clip_rect_t
** pBackClipRects
);
349 * \name Timing related functions.
353 * Get the 64-bit unadjusted system time (UST).
355 int (*getUST
)(int64_t * ust
);
358 * Get the media stream counter (MSC) rate.
360 * Matching the definition in GLX_OML_sync_control, this function returns
361 * the rate of the "media stream counter". In practical terms, this is
362 * the frame refresh rate of the display.
364 GLboolean (*getMSCRate
)(__DRIdrawable
*draw
,
365 int32_t * numerator
, int32_t * denominator
);
369 * Reports areas of the given drawable which have been modified by the
372 * \param drawable which the drawing was done to.
373 * \param rects rectangles affected, with the drawable origin as the
375 * \param x X offset of the drawable within the screen (used in the
377 * \param y Y offset of the drawable within the screen.
378 * \param front_buffer boolean flag for whether the drawing to the
379 * drawable was actually done directly to the front buffer (instead
380 * of backing storage, for example)
382 void (*reportDamage
)(__DRIdrawable
*draw
,
384 drm_clip_rect_t
*rects
, int num_rects
,
385 GLboolean front_buffer
);
388 * Ping the windowing system to get it to reemit info for the
389 * specified drawable in the DRI2 event buffer.
391 * \param draw the drawable for which to request info
393 void (*reemitDrawableInfo
)(__DRIdrawable
*draw
);
399 * Framebuffer information record. Used by libGL to communicate information
400 * about the framebuffer to the driver's \c __driCreateNewScreen function.
402 * In XFree86, most of this information is derrived from data returned by
403 * calling \c XF86DRIGetDeviceInfo.
405 * \sa XF86DRIGetDeviceInfo __DRIdisplayRec::createNewScreen
406 * __driUtilCreateNewScreen CallCreateNewScreen
408 * \bug This structure could be better named.
410 struct __DRIframebufferRec
{
411 unsigned char *base
; /**< Framebuffer base address in the CPU's
412 * address space. This value is calculated by
413 * calling \c drmMap on the framebuffer handle
414 * returned by \c XF86DRIGetDeviceInfo (or a
417 int size
; /**< Framebuffer size, in bytes. */
418 int stride
; /**< Number of bytes from one line to the next. */
419 int width
; /**< Pixel width of the framebuffer. */
420 int height
; /**< Pixel height of the framebuffer. */
421 int dev_priv_size
; /**< Size of the driver's dev-priv structure. */
422 void *dev_priv
; /**< Pointer to the driver's dev-priv structure. */
427 * Screen dependent methods. This structure is initialized during the
428 * \c __DRIdisplayRec::createScreen call.
430 struct __DRIscreenRec
{
432 * Method to destroy the private DRI screen data.
434 void (*destroyScreen
)(__DRIscreen
*screen
);
437 * Method to get screen extensions.
439 const __DRIextension
**(*getExtensions
)(__DRIscreen
*screen
);
442 * Method to create the private DRI drawable data and initialize the
443 * drawable dependent methods.
445 void *(*createNewDrawable
)(__DRIscreen
*screen
,
446 const __GLcontextModes
*modes
,
447 __DRIdrawable
*pdraw
,
448 drm_drawable_t hwDrawable
,
449 int renderType
, const int *attrs
);
452 * Opaque pointer to private per screen direct rendering data. \c NULL
453 * if direct rendering is not supported on this screen. Never
454 * dereferenced in libGL.
459 * Method to create the private DRI context data and initialize the
460 * context dependent methods.
462 * \since Internal API version 20031201.
464 void * (*createNewContext
)(__DRIscreen
*screen
,
465 const __GLcontextModes
*modes
,
467 __DRIcontext
*shared
,
468 drm_context_t hwContext
, __DRIcontext
*pctx
);
472 * Context dependent methods. This structure is initialized during the
473 * \c __DRIscreenRec::createContext call.
475 struct __DRIcontextRec
{
477 * Method to destroy the private DRI context data.
479 void (*destroyContext
)(__DRIcontext
*context
);
482 * Opaque pointer to private per context direct rendering data.
483 * \c NULL if direct rendering is not supported on the display or
484 * screen used to create this context. Never dereferenced in libGL.
489 * Method to bind a DRI drawable to a DRI graphics context.
491 * \since Internal API version 20050727.
493 GLboolean (*bindContext
)(__DRIcontext
*ctx
,
494 __DRIdrawable
*pdraw
,
495 __DRIdrawable
*pread
);
498 * Method to unbind a DRI drawable from a DRI graphics context.
500 * \since Internal API version 20050727.
502 GLboolean (*unbindContext
)(__DRIcontext
*ctx
);
506 * Drawable dependent methods. This structure is initialized during the
507 * \c __DRIscreenRec::createDrawable call. \c createDrawable is not called
508 * by libGL at this time. It's currently used via the dri_util.c utility code
511 struct __DRIdrawableRec
{
513 * Method to destroy the private DRI drawable data.
515 void (*destroyDrawable
)(__DRIdrawable
*drawable
);
518 * Method to swap the front and back buffers.
520 void (*swapBuffers
)(__DRIdrawable
*drawable
);
523 * Opaque pointer to private per drawable direct rendering data.
524 * \c NULL if direct rendering is not supported on the display or
525 * screen used to create this drawable. Never dereferenced in libGL.