2 * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
3 * Copyright 2007-2008 Red Hat, Inc.
4 * (C) Copyright IBM Corporation 2004
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * on the rights to use, copy, modify, merge, publish, distribute, sub
11 * license, and/or sell copies of the Software, and to permit persons to whom
12 * the Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * \file dri_interface.h
30 * This file contains all the types and functions that define the interface
31 * between a DRI driver and driver loader. Currently, the most common driver
32 * loader is the XFree86 libGL.so. However, other loaders do exist, and in
33 * the future the server-side libglx.a will also be a loader.
35 * \author Kevin E. Martin <kevin@precisioninsight.com>
36 * \author Ian Romanick <idr@us.ibm.com>
37 * \author Kristian Høgsberg <krh@redhat.com>
40 #ifndef DRI_INTERFACE_H
41 #define DRI_INTERFACE_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 __DRIconfigRec __DRIconfig
;
57 typedef struct __DRIframebufferRec __DRIframebuffer
;
58 typedef struct __DRIversionRec __DRIversion
;
60 typedef struct __DRIcoreExtensionRec __DRIcoreExtension
;
61 typedef struct __DRIextensionRec __DRIextension
;
62 typedef struct __DRIcopySubBufferExtensionRec __DRIcopySubBufferExtension
;
63 typedef struct __DRIswapControlExtensionRec __DRIswapControlExtension
;
64 typedef struct __DRIallocateExtensionRec __DRIallocateExtension
;
65 typedef struct __DRIframeTrackingExtensionRec __DRIframeTrackingExtension
;
66 typedef struct __DRImediaStreamCounterExtensionRec __DRImediaStreamCounterExtension
;
67 typedef struct __DRItexOffsetExtensionRec __DRItexOffsetExtension
;
68 typedef struct __DRItexBufferExtensionRec __DRItexBufferExtension
;
69 typedef struct __DRIlegacyExtensionRec __DRIlegacyExtension
;
70 typedef struct __DRIswrastExtensionRec __DRIswrastExtension
;
75 * Extension struct. Drivers 'inherit' from this struct by embedding
76 * it as the first element in the extension struct.
78 * We never break API in for a DRI extension. If we need to change
79 * the way things work in a non-backwards compatible manner, we
80 * introduce a new extension. During a transition period, we can
81 * leave both the old and the new extension in the driver, which
82 * allows us to move to the new interface without having to update the
83 * loader(s) in lock step.
85 * However, we can add entry points to an extension over time as long
86 * as we don't break the old ones. As we add entry points to an
87 * extension, we increase the version number. The corresponding
88 * #define can be used to guard code that accesses the new entry
89 * points at compile time and the version field in the extension
90 * struct can be used at run-time to determine how to use the
93 struct __DRIextensionRec
{
99 * The first set of extension are the screen extensions, returned by
100 * __DRIcore::getExtensions(). This entry point will return a list of
101 * extensions and the loader can use the ones it knows about by
102 * casting them to more specific extensions and advertising any GLX
103 * extensions the DRI extensions enables.
107 * Used by drivers to indicate support for setting the read drawable.
109 #define __DRI_READ_DRAWABLE "DRI_ReadDrawable"
110 #define __DRI_READ_DRAWABLE_VERSION 1
113 * Used by drivers that implement the GLX_MESA_copy_sub_buffer extension.
115 #define __DRI_COPY_SUB_BUFFER "DRI_CopySubBuffer"
116 #define __DRI_COPY_SUB_BUFFER_VERSION 1
117 struct __DRIcopySubBufferExtensionRec
{
119 void (*copySubBuffer
)(__DRIdrawable
*drawable
, int x
, int y
, int w
, int h
);
123 * Used by drivers that implement the GLX_SGI_swap_control or
124 * GLX_MESA_swap_control extension.
126 #define __DRI_SWAP_CONTROL "DRI_SwapControl"
127 #define __DRI_SWAP_CONTROL_VERSION 1
128 struct __DRIswapControlExtensionRec
{
130 void (*setSwapInterval
)(__DRIdrawable
*drawable
, unsigned int inteval
);
131 unsigned int (*getSwapInterval
)(__DRIdrawable
*drawable
);
135 * Used by drivers that implement the GLX_MESA_allocate_memory.
137 #define __DRI_ALLOCATE "DRI_Allocate"
138 #define __DRI_ALLOCATE_VERSION 1
139 struct __DRIallocateExtensionRec
{
142 void *(*allocateMemory
)(__DRIscreen
*screen
, GLsizei size
,
143 GLfloat readfreq
, GLfloat writefreq
,
146 void (*freeMemory
)(__DRIscreen
*screen
, GLvoid
*pointer
);
148 GLuint (*memoryOffset
)(__DRIscreen
*screen
, const GLvoid
*pointer
);
152 * Used by drivers that implement the GLX_MESA_swap_frame_usage extension.
154 #define __DRI_FRAME_TRACKING "DRI_FrameTracking"
155 #define __DRI_FRAME_TRACKING_VERSION 1
156 struct __DRIframeTrackingExtensionRec
{
160 * Enable or disable frame usage tracking.
162 * \since Internal API version 20030317.
164 int (*frameTracking
)(__DRIdrawable
*drawable
, GLboolean enable
);
167 * Retrieve frame usage information.
169 * \since Internal API version 20030317.
171 int (*queryFrameTracking
)(__DRIdrawable
*drawable
,
172 int64_t * sbc
, int64_t * missedFrames
,
173 float * lastMissedUsage
, float * usage
);
178 * Used by drivers that implement the GLX_SGI_video_sync extension.
180 #define __DRI_MEDIA_STREAM_COUNTER "DRI_MediaStreamCounter"
181 #define __DRI_MEDIA_STREAM_COUNTER_VERSION 1
182 struct __DRImediaStreamCounterExtensionRec
{
186 * Wait for the MSC to equal target_msc, or, if that has already passed,
187 * the next time (MSC % divisor) is equal to remainder. If divisor is
188 * zero, the function will return as soon as MSC is greater than or equal
191 int (*waitForMSC
)(__DRIdrawable
*drawable
,
192 int64_t target_msc
, int64_t divisor
, int64_t remainder
,
193 int64_t * msc
, int64_t * sbc
);
196 * Get the number of vertical refreshes since some point in time before
197 * this function was first called (i.e., system start up).
199 int (*getDrawableMSC
)(__DRIscreen
*screen
, __DRIdrawable
*drawable
,
204 #define __DRI_TEX_OFFSET "DRI_TexOffset"
205 #define __DRI_TEX_OFFSET_VERSION 1
206 struct __DRItexOffsetExtensionRec
{
210 * Method to override base texture image with a driver specific 'offset'.
211 * The depth passed in allows e.g. to ignore the alpha channel of texture
212 * images where the non-alpha components don't occupy a whole texel.
214 * For GLX_EXT_texture_from_pixmap with AIGLX.
216 void (*setTexOffset
)(__DRIcontext
*pDRICtx
, GLint texname
,
217 unsigned long long offset
, GLint depth
, GLuint pitch
);
221 #define __DRI_TEX_BUFFER "DRI_TexBuffer"
222 #define __DRI_TEX_BUFFER_VERSION 1
223 struct __DRItexBufferExtensionRec
{
227 * Method to override base texture image with the contents of a
230 * For GLX_EXT_texture_from_pixmap with AIGLX.
232 void (*setTexBuffer
)(__DRIcontext
*pDRICtx
,
234 __DRIdrawable
*pDraw
);
239 * XML document describing the configuration options supported by the
242 extern const char __driConfigOptions
[];
247 * The following extensions describe loader features that the DRI
248 * driver can make use of. Some of these are mandatory, such as the
249 * getDrawableInfo extension for DRI and the DRI Loader extensions for
250 * DRI2, while others are optional, and if present allow the driver to
251 * expose certain features. The loader pass in a NULL terminated
252 * array of these extensions to the driver in the createNewScreen
256 typedef struct __DRIgetDrawableInfoExtensionRec __DRIgetDrawableInfoExtension
;
257 typedef struct __DRIsystemTimeExtensionRec __DRIsystemTimeExtension
;
258 typedef struct __DRIdamageExtensionRec __DRIdamageExtension
;
259 typedef struct __DRIloaderExtensionRec __DRIloaderExtension
;
260 typedef struct __DRIswrastLoaderExtensionRec __DRIswrastLoaderExtension
;
264 * Callback to getDrawableInfo protocol
266 #define __DRI_GET_DRAWABLE_INFO "DRI_GetDrawableInfo"
267 #define __DRI_GET_DRAWABLE_INFO_VERSION 1
268 struct __DRIgetDrawableInfoExtensionRec
{
272 * This function is used to get information about the position, size, and
273 * clip rects of a drawable.
275 GLboolean (* getDrawableInfo
) ( __DRIdrawable
*drawable
,
276 unsigned int * index
, unsigned int * stamp
,
277 int * x
, int * y
, int * width
, int * height
,
278 int * numClipRects
, drm_clip_rect_t
** pClipRects
,
279 int * backX
, int * backY
,
280 int * numBackClipRects
, drm_clip_rect_t
** pBackClipRects
,
281 void *loaderPrivate
);
285 * Callback to get system time for media stream counter extensions.
287 #define __DRI_SYSTEM_TIME "DRI_SystemTime"
288 #define __DRI_SYSTEM_TIME_VERSION 1
289 struct __DRIsystemTimeExtensionRec
{
293 * Get the 64-bit unadjusted system time (UST).
295 int (*getUST
)(int64_t * ust
);
298 * Get the media stream counter (MSC) rate.
300 * Matching the definition in GLX_OML_sync_control, this function returns
301 * the rate of the "media stream counter". In practical terms, this is
302 * the frame refresh rate of the display.
304 GLboolean (*getMSCRate
)(__DRIdrawable
*draw
,
305 int32_t * numerator
, int32_t * denominator
,
306 void *loaderPrivate
);
312 #define __DRI_DAMAGE "DRI_Damage"
313 #define __DRI_DAMAGE_VERSION 1
314 struct __DRIdamageExtensionRec
{
318 * Reports areas of the given drawable which have been modified by the
321 * \param drawable which the drawing was done to.
322 * \param rects rectangles affected, with the drawable origin as the
324 * \param x X offset of the drawable within the screen (used in the
326 * \param y Y offset of the drawable within the screen.
327 * \param front_buffer boolean flag for whether the drawing to the
328 * drawable was actually done directly to the front buffer (instead
329 * of backing storage, for example)
330 * \param loaderPrivate the data passed in at createNewDrawable time
332 void (*reportDamage
)(__DRIdrawable
*draw
,
334 drm_clip_rect_t
*rects
, int num_rects
,
335 GLboolean front_buffer
,
336 void *loaderPrivate
);
340 * DRI2 Loader extension. This extension describes the basic
341 * functionality the loader needs to provide for the DRI driver.
343 #define __DRI_LOADER "DRI_Loader"
344 #define __DRI_LOADER_VERSION 1
345 struct __DRIloaderExtensionRec
{
349 * Ping the windowing system to get it to reemit info for the
350 * specified drawable in the DRI2 event buffer.
352 * \param draw the drawable for which to request info
353 * \param tail the new event buffer tail pointer
355 void (*reemitDrawableInfo
)(__DRIdrawable
*draw
, unsigned int *tail
,
356 void *loaderPrivate
);
358 void (*postDamage
)(__DRIdrawable
*draw
, struct drm_clip_rect
*rects
,
359 int num_rects
, void *loaderPrivate
);
362 #define __DRI_SWRAST_IMAGE_OP_DRAW 1
363 #define __DRI_SWRAST_IMAGE_OP_CLEAR 2
364 #define __DRI_SWRAST_IMAGE_OP_SWAP 3
367 * SWRast Loader extension.
369 #define __DRI_SWRAST_LOADER "DRI_SWRastLoader"
370 #define __DRI_SWRAST_LOADER_VERSION 1
371 struct __DRIswrastLoaderExtensionRec
{
375 * Drawable position and size
377 void (*getDrawableInfo
)(__DRIdrawable
*drawable
,
378 int *x
, int *y
, int *width
, int *height
,
379 void *loaderPrivate
);
382 * Put image to drawable
384 void (*putImage
)(__DRIdrawable
*drawable
, int op
,
385 int x
, int y
, int width
, int height
, char *data
,
386 void *loaderPrivate
);
389 * Get image from drawable
391 void (*getImage
)(__DRIdrawable
*drawable
,
392 int x
, int y
, int width
, int height
, char *data
,
393 void *loaderPrivate
);
397 * The remaining extensions describe driver extensions, immediately
398 * available interfaces provided by the driver. To start using the
399 * driver, dlsym() for the __DRI_DRIVER_EXTENSIONS symbol and look for
400 * the extension you need in the array.
402 #define __DRI_DRIVER_EXTENSIONS "__driDriverExtensions"
405 * Tokens for __DRIconfig attribs. A number of attributes defined by
406 * GLX or EGL standards are not in the table, as they must be provided
407 * by the loader. For example, FBConfig ID or visual ID, drawable type.
410 #define __DRI_ATTRIB_BUFFER_SIZE 1
411 #define __DRI_ATTRIB_LEVEL 2
412 #define __DRI_ATTRIB_RED_SIZE 3
413 #define __DRI_ATTRIB_GREEN_SIZE 4
414 #define __DRI_ATTRIB_BLUE_SIZE 5
415 #define __DRI_ATTRIB_LUMINANCE_SIZE 6
416 #define __DRI_ATTRIB_ALPHA_SIZE 7
417 #define __DRI_ATTRIB_ALPHA_MASK_SIZE 8
418 #define __DRI_ATTRIB_DEPTH_SIZE 9
419 #define __DRI_ATTRIB_STENCIL_SIZE 10
420 #define __DRI_ATTRIB_ACCUM_RED_SIZE 11
421 #define __DRI_ATTRIB_ACCUM_GREEN_SIZE 12
422 #define __DRI_ATTRIB_ACCUM_BLUE_SIZE 13
423 #define __DRI_ATTRIB_ACCUM_ALPHA_SIZE 14
424 #define __DRI_ATTRIB_SAMPLE_BUFFERS 15
425 #define __DRI_ATTRIB_SAMPLES 16
426 #define __DRI_ATTRIB_RENDER_TYPE 17
427 #define __DRI_ATTRIB_CONFIG_CAVEAT 18
428 #define __DRI_ATTRIB_CONFORMANT 19
429 #define __DRI_ATTRIB_DOUBLE_BUFFER 20
430 #define __DRI_ATTRIB_STEREO 21
431 #define __DRI_ATTRIB_AUX_BUFFERS 22
432 #define __DRI_ATTRIB_TRANSPARENT_TYPE 23
433 #define __DRI_ATTRIB_TRANSPARENT_INDEX_VALUE 24
434 #define __DRI_ATTRIB_TRANSPARENT_RED_VALUE 25
435 #define __DRI_ATTRIB_TRANSPARENT_GREEN_VALUE 26
436 #define __DRI_ATTRIB_TRANSPARENT_BLUE_VALUE 27
437 #define __DRI_ATTRIB_TRANSPARENT_ALPHA_VALUE 28
438 #define __DRI_ATTRIB_FLOAT_MODE 29
439 #define __DRI_ATTRIB_RED_MASK 30
440 #define __DRI_ATTRIB_GREEN_MASK 31
441 #define __DRI_ATTRIB_BLUE_MASK 32
442 #define __DRI_ATTRIB_ALPHA_MASK 33
443 #define __DRI_ATTRIB_MAX_PBUFFER_WIDTH 34
444 #define __DRI_ATTRIB_MAX_PBUFFER_HEIGHT 35
445 #define __DRI_ATTRIB_MAX_PBUFFER_PIXELS 36
446 #define __DRI_ATTRIB_OPTIMAL_PBUFFER_WIDTH 37
447 #define __DRI_ATTRIB_OPTIMAL_PBUFFER_HEIGHT 38
448 #define __DRI_ATTRIB_VISUAL_SELECT_GROUP 39
449 #define __DRI_ATTRIB_SWAP_METHOD 40
450 #define __DRI_ATTRIB_MAX_SWAP_INTERVAL 41
451 #define __DRI_ATTRIB_MIN_SWAP_INTERVAL 42
452 #define __DRI_ATTRIB_BIND_TO_TEXTURE_RGB 43
453 #define __DRI_ATTRIB_BIND_TO_TEXTURE_RGBA 44
454 #define __DRI_ATTRIB_BIND_TO_MIPMAP_TEXTURE 45
455 #define __DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS 46
456 #define __DRI_ATTRIB_YINVERTED 47
458 /* __DRI_ATTRIB_RENDER_TYPE */
459 #define __DRI_ATTRIB_RGBA_BIT 0x01
460 #define __DRI_ATTRIB_COLOR_INDEX_BIT 0x02
461 #define __DRI_ATTRIB_LUMINANCE_BIT 0x04
463 /* __DRI_ATTRIB_CONFIG_CAVEAT */
464 #define __DRI_ATTRIB_SLOW_BIT 0x01
465 #define __DRI_ATTRIB_NON_CONFORMANT_CONFIG 0x02
467 /* __DRI_ATTRIB_TRANSPARENT_TYPE */
468 #define __DRI_ATTRIB_TRANSPARENT_RGB 0x00
469 #define __DRI_ATTRIB_TRANSPARENT_INDEX 0x01
471 /* __DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS */
472 #define __DRI_ATTRIB_TEXTURE_1D_BIT 0x01
473 #define __DRI_ATTRIB_TEXTURE_2D_BIT 0x02
474 #define __DRI_ATTRIB_TEXTURE_RECTANGLE_BIT 0x04
477 * This extension defines the core DRI functionality.
479 #define __DRI_CORE "DRI_Core"
480 #define __DRI_CORE_VERSION 1
482 struct __DRIcoreExtensionRec
{
485 __DRIscreen
*(*createNewScreen
)(int screen
, int fd
,
486 unsigned int sarea_handle
,
487 const __DRIextension
**extensions
,
488 const __DRIconfig
***driverConfigs
,
489 void *loaderPrivate
);
491 void (*destroyScreen
)(__DRIscreen
*screen
);
493 const __DRIextension
**(*getExtensions
)(__DRIscreen
*screen
);
495 int (*getConfigAttrib
)(const __DRIconfig
*config
,
497 unsigned int *value
);
499 int (*indexConfigAttrib
)(const __DRIconfig
*config
, int index
,
500 unsigned int *attrib
, unsigned int *value
);
502 __DRIdrawable
*(*createNewDrawable
)(__DRIscreen
*screen
,
503 const __DRIconfig
*config
,
504 unsigned int drawable_id
,
506 void *loaderPrivate
);
508 void (*destroyDrawable
)(__DRIdrawable
*drawable
);
510 void (*swapBuffers
)(__DRIdrawable
*drawable
);
512 __DRIcontext
*(*createNewContext
)(__DRIscreen
*screen
,
513 const __DRIconfig
*config
,
514 __DRIcontext
*shared
,
515 void *loaderPrivate
);
517 int (*copyContext
)(__DRIcontext
*dest
,
521 void (*destroyContext
)(__DRIcontext
*context
);
523 int (*bindContext
)(__DRIcontext
*ctx
,
524 __DRIdrawable
*pdraw
,
525 __DRIdrawable
*pread
);
527 int (*unbindContext
)(__DRIcontext
*ctx
);
531 * Stored version of some component (i.e., server-side DRI module, kernel-side
535 * There are several data structures that explicitly store a major version,
536 * minor version, and patch level. These structures should be modified to
537 * have a \c __DRIversionRec instead.
539 struct __DRIversionRec
{
540 int major
; /**< Major version number. */
541 int minor
; /**< Minor version number. */
542 int patch
; /**< Patch-level. */
546 * Framebuffer information record. Used by libGL to communicate information
547 * about the framebuffer to the driver's \c __driCreateNewScreen function.
549 * In XFree86, most of this information is derrived from data returned by
550 * calling \c XF86DRIGetDeviceInfo.
552 * \sa XF86DRIGetDeviceInfo __DRIdisplayRec::createNewScreen
553 * __driUtilCreateNewScreen CallCreateNewScreen
555 * \bug This structure could be better named.
557 struct __DRIframebufferRec
{
558 unsigned char *base
; /**< Framebuffer base address in the CPU's
559 * address space. This value is calculated by
560 * calling \c drmMap on the framebuffer handle
561 * returned by \c XF86DRIGetDeviceInfo (or a
564 int size
; /**< Framebuffer size, in bytes. */
565 int stride
; /**< Number of bytes from one line to the next. */
566 int width
; /**< Pixel width of the framebuffer. */
567 int height
; /**< Pixel height of the framebuffer. */
568 int dev_priv_size
; /**< Size of the driver's dev-priv structure. */
569 void *dev_priv
; /**< Pointer to the driver's dev-priv structure. */
574 * This extension provides alternative screen, drawable and context
575 * constructors for legacy DRI functionality. This is used in
576 * conjunction with the core extension.
578 #define __DRI_LEGACY "DRI_Legacy"
579 #define __DRI_LEGACY_VERSION 1
581 struct __DRIlegacyExtensionRec
{
584 __DRIscreen
*(*createNewScreen
)(int screen
,
585 const __DRIversion
*ddx_version
,
586 const __DRIversion
*dri_version
,
587 const __DRIversion
*drm_version
,
588 const __DRIframebuffer
*frame_buffer
,
589 void *pSAREA
, int fd
,
590 const __DRIextension
**extensions
,
591 const __DRIconfig
***driver_configs
,
592 void *loaderPrivate
);
594 __DRIdrawable
*(*createNewDrawable
)(__DRIscreen
*screen
,
595 const __DRIconfig
*config
,
596 drm_drawable_t hwDrawable
,
597 int renderType
, const int *attrs
,
598 void *loaderPrivate
);
600 __DRIcontext
*(*createNewContext
)(__DRIscreen
*screen
,
601 const __DRIconfig
*config
,
603 __DRIcontext
*shared
,
604 drm_context_t hwContext
,
605 void *loaderPrivate
);
609 * This extension provides alternative screen, drawable and context
610 * constructors for swrast DRI functionality. This is used in
611 * conjunction with the core extension.
613 #define __DRI_SWRAST "DRI_SWRast"
614 #define __DRI_SWRAST_VERSION 1
616 struct __DRIswrastExtensionRec
{
619 __DRIscreen
*(*createNewScreen
)(int screen
,
620 const __DRIextension
**extensions
,
621 const __DRIconfig
***driver_configs
,
622 void *loaderPrivate
);
624 __DRIdrawable
*(*createNewDrawable
)(__DRIscreen
*screen
,
625 const __DRIconfig
*config
,
626 void *loaderPrivate
);