• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
3  * Copyright 2007-2008 Red Hat, Inc.
4  * (C) Copyright IBM Corporation 2004
5  * All Rights Reserved.
6  *
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:
13  *
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
16  * Software.
17  *
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.
25  */
26 
27 /**
28  * \file dri_interface.h
29  *
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.
34  *
35  * \author Kevin E. Martin <kevin@precisioninsight.com>
36  * \author Ian Romanick <idr@us.ibm.com>
37  * \author Kristian Høgsberg <krh@redhat.com>
38  */
39 
40 #ifndef DRI_INTERFACE_H
41 #define DRI_INTERFACE_H
42 
43 #ifdef HAVE_LIBDRM
44 #include <drm.h>
45 #else
46 typedef unsigned int drm_context_t;
47 typedef unsigned int drm_drawable_t;
48 typedef struct drm_clip_rect drm_clip_rect_t;
49 #endif
50 
51 #include <stdint.h>
52 
53 /**
54  * \name DRI interface structures
55  *
56  * The following structures define the interface between the GLX client
57  * side library and the DRI (direct rendering infrastructure).
58  */
59 /*@{*/
60 typedef struct __DRIdisplayRec		__DRIdisplay;
61 typedef struct __DRIscreenRec		__DRIscreen;
62 typedef struct __DRIcontextRec		__DRIcontext;
63 typedef struct __DRIdrawableRec		__DRIdrawable;
64 typedef struct __DRIconfigRec		__DRIconfig;
65 typedef struct __DRIframebufferRec	__DRIframebuffer;
66 typedef struct __DRIversionRec		__DRIversion;
67 
68 typedef struct __DRIcoreExtensionRec		__DRIcoreExtension;
69 typedef struct __DRIextensionRec		__DRIextension;
70 typedef struct __DRIcopySubBufferExtensionRec	__DRIcopySubBufferExtension;
71 typedef struct __DRIswapControlExtensionRec	__DRIswapControlExtension;
72 typedef struct __DRIframeTrackingExtensionRec	__DRIframeTrackingExtension;
73 typedef struct __DRImediaStreamCounterExtensionRec	__DRImediaStreamCounterExtension;
74 typedef struct __DRItexOffsetExtensionRec	__DRItexOffsetExtension;
75 typedef struct __DRItexBufferExtensionRec	__DRItexBufferExtension;
76 typedef struct __DRIlegacyExtensionRec		__DRIlegacyExtension;
77 typedef struct __DRIswrastExtensionRec		__DRIswrastExtension;
78 typedef struct __DRIbufferRec			__DRIbuffer;
79 typedef struct __DRIdri2ExtensionRec		__DRIdri2Extension;
80 typedef struct __DRIdri2LoaderExtensionRec	__DRIdri2LoaderExtension;
81 typedef struct __DRI2flushExtensionRec	__DRI2flushExtension;
82 typedef struct __DRI2throttleExtensionRec	__DRI2throttleExtension;
83 typedef struct __DRI2fenceExtensionRec          __DRI2fenceExtension;
84 typedef struct __DRI2interopExtensionRec	__DRI2interopExtension;
85 typedef struct __DRI2blobExtensionRec           __DRI2blobExtension;
86 typedef struct __DRI2bufferDamageExtensionRec   __DRI2bufferDamageExtension;
87 
88 typedef struct __DRIimageLoaderExtensionRec     __DRIimageLoaderExtension;
89 typedef struct __DRIimageDriverExtensionRec     __DRIimageDriverExtension;
90 
91 /*@}*/
92 
93 
94 /**
95  * Extension struct.  Drivers 'inherit' from this struct by embedding
96  * it as the first element in the extension struct.
97  *
98  * We never break API in for a DRI extension.  If we need to change
99  * the way things work in a non-backwards compatible manner, we
100  * introduce a new extension.  During a transition period, we can
101  * leave both the old and the new extension in the driver, which
102  * allows us to move to the new interface without having to update the
103  * loader(s) in lock step.
104  *
105  * However, we can add entry points to an extension over time as long
106  * as we don't break the old ones.  As we add entry points to an
107  * extension, we increase the version number.  The corresponding
108  * #define can be used to guard code that accesses the new entry
109  * points at compile time and the version field in the extension
110  * struct can be used at run-time to determine how to use the
111  * extension.
112  */
113 struct __DRIextensionRec {
114     const char *name;
115     int version;
116 };
117 
118 /**
119  * The first set of extension are the screen extensions, returned by
120  * __DRIcore::getExtensions().  This entry point will return a list of
121  * extensions and the loader can use the ones it knows about by
122  * casting them to more specific extensions and advertising any GLX
123  * extensions the DRI extensions enables.
124  */
125 
126 /**
127  * Used by drivers to indicate support for setting the read drawable.
128  */
129 #define __DRI_READ_DRAWABLE "DRI_ReadDrawable"
130 #define __DRI_READ_DRAWABLE_VERSION 1
131 
132 /**
133  * Used by drivers that implement the GLX_MESA_copy_sub_buffer extension.
134  */
135 #define __DRI_COPY_SUB_BUFFER "DRI_CopySubBuffer"
136 #define __DRI_COPY_SUB_BUFFER_VERSION 1
137 struct __DRIcopySubBufferExtensionRec {
138     __DRIextension base;
139     void (*copySubBuffer)(__DRIdrawable *drawable, int x, int y, int w, int h);
140 };
141 
142 /**
143  * Used by drivers that implement the GLX_SGI_swap_control or
144  * GLX_MESA_swap_control extension.
145  */
146 #define __DRI_SWAP_CONTROL "DRI_SwapControl"
147 #define __DRI_SWAP_CONTROL_VERSION 1
148 struct __DRIswapControlExtensionRec {
149     __DRIextension base;
150     void (*setSwapInterval)(__DRIdrawable *drawable, unsigned int inteval);
151     unsigned int (*getSwapInterval)(__DRIdrawable *drawable);
152 };
153 
154 /**
155  * Used by drivers that implement the GLX_SGI_video_sync extension.
156  */
157 #define __DRI_MEDIA_STREAM_COUNTER "DRI_MediaStreamCounter"
158 #define __DRI_MEDIA_STREAM_COUNTER_VERSION 1
159 struct __DRImediaStreamCounterExtensionRec {
160     __DRIextension base;
161 
162     /**
163      * Wait for the MSC to equal target_msc, or, if that has already passed,
164      * the next time (MSC % divisor) is equal to remainder.  If divisor is
165      * zero, the function will return as soon as MSC is greater than or equal
166      * to target_msc.
167      */
168     int (*waitForMSC)(__DRIdrawable *drawable,
169 		      int64_t target_msc, int64_t divisor, int64_t remainder,
170 		      int64_t * msc, int64_t * sbc);
171 
172     /**
173      * Get the number of vertical refreshes since some point in time before
174      * this function was first called (i.e., system start up).
175      */
176     int (*getDrawableMSC)(__DRIscreen *screen, __DRIdrawable *drawable,
177 			  int64_t *msc);
178 };
179 
180 /* Valid values for format in the setTexBuffer2 function below.  These
181  * values match the GLX tokens for compatibility reasons, but we
182  * define them here since the DRI interface can't depend on GLX. */
183 #define __DRI_TEXTURE_FORMAT_NONE        0x20D8
184 #define __DRI_TEXTURE_FORMAT_RGB         0x20D9
185 #define __DRI_TEXTURE_FORMAT_RGBA        0x20DA
186 
187 #define __DRI_TEX_BUFFER "DRI_TexBuffer"
188 #define __DRI_TEX_BUFFER_VERSION 3
189 struct __DRItexBufferExtensionRec {
190     __DRIextension base;
191 
192     /**
193      * Method to override base texture image with the contents of a
194      * __DRIdrawable.
195      *
196      * For GLX_EXT_texture_from_pixmap with AIGLX.  Deprecated in favor of
197      * setTexBuffer2 in version 2 of this interface
198      */
199     void (*setTexBuffer)(__DRIcontext *pDRICtx,
200 			 int target,
201 			 __DRIdrawable *pDraw);
202 
203     /**
204      * Method to override base texture image with the contents of a
205      * __DRIdrawable, including the required texture format attribute.
206      *
207      * For GLX_EXT_texture_from_pixmap with AIGLX.
208      *
209      * \since 2
210      */
211     void (*setTexBuffer2)(__DRIcontext *pDRICtx,
212 			  int target,
213 			  int format,
214 			  __DRIdrawable *pDraw);
215     /**
216      * Method to release texture buffer in case some special platform
217      * need this.
218      *
219      * For GLX_EXT_texture_from_pixmap with AIGLX.
220      *
221      * \since 3
222      */
223     void (*releaseTexBuffer)(__DRIcontext *pDRICtx,
224 			int target,
225 			__DRIdrawable *pDraw);
226 };
227 
228 /**
229  * Used by drivers that implement DRI2
230  */
231 #define __DRI2_FLUSH "DRI2_Flush"
232 #define __DRI2_FLUSH_VERSION 4
233 
234 #define __DRI2_FLUSH_DRAWABLE (1 << 0) /* the drawable should be flushed. */
235 #define __DRI2_FLUSH_CONTEXT  (1 << 1) /* glFlush should be called */
236 #define __DRI2_FLUSH_INVALIDATE_ANCILLARY (1 << 2)
237 
238 enum __DRI2throttleReason {
239    __DRI2_THROTTLE_SWAPBUFFER,
240    __DRI2_THROTTLE_COPYSUBBUFFER,
241    __DRI2_THROTTLE_FLUSHFRONT
242 };
243 
244 struct __DRI2flushExtensionRec {
245     __DRIextension base;
246     void (*flush)(__DRIdrawable *drawable);
247 
248     /**
249      * Ask the driver to call getBuffers/getBuffersWithFormat before
250      * it starts rendering again.
251      *
252      * \param drawable the drawable to invalidate
253      *
254      * \since 3
255      */
256     void (*invalidate)(__DRIdrawable *drawable);
257 
258     /**
259      * This function reduces the number of flushes in the driver by combining
260      * several operations into one call.
261      *
262      * It can:
263      * - throttle
264      * - flush a drawable
265      * - flush a context
266      *
267      * \param context           the context
268      * \param drawable          the drawable to flush
269      * \param flags             a combination of _DRI2_FLUSH_xxx flags
270      * \param throttle_reason   the reason for throttling, 0 = no throttling
271      *
272      * \since 4
273      */
274     void (*flush_with_flags)(__DRIcontext *ctx,
275                              __DRIdrawable *drawable,
276                              unsigned flags,
277                              enum __DRI2throttleReason throttle_reason);
278 };
279 
280 
281 /**
282  * Extension that the driver uses to request
283  * throttle callbacks.
284  */
285 
286 #define __DRI2_THROTTLE "DRI2_Throttle"
287 #define __DRI2_THROTTLE_VERSION 1
288 
289 struct __DRI2throttleExtensionRec {
290    __DRIextension base;
291    void (*throttle)(__DRIcontext *ctx,
292 		    __DRIdrawable *drawable,
293 		    enum __DRI2throttleReason reason);
294 };
295 
296 /**
297  * Extension for EGL_ANDROID_blob_cache
298  */
299 
300 #define __DRI2_BLOB "DRI2_Blob"
301 #define __DRI2_BLOB_VERSION 1
302 
303 typedef void
304 (*__DRIblobCacheSet) (const void *key, signed long keySize,
305                       const void *value, signed long valueSize);
306 
307 typedef signed long
308 (*__DRIblobCacheGet) (const void *key, signed long keySize,
309                       void *value, signed long valueSize);
310 
311 struct __DRI2blobExtensionRec {
312    __DRIextension base;
313 
314    /**
315     * Set cache functions for setting and getting cache entries.
316     */
317    void (*set_cache_funcs) (__DRIscreen *screen,
318                             __DRIblobCacheSet set, __DRIblobCacheGet get);
319 };
320 
321 /**
322  * Extension for fences / synchronization objects.
323  */
324 
325 #define __DRI2_FENCE "DRI2_Fence"
326 #define __DRI2_FENCE_VERSION 2
327 
328 #define __DRI2_FENCE_TIMEOUT_INFINITE     0xffffffffffffffffull
329 
330 #define __DRI2_FENCE_FLAG_FLUSH_COMMANDS  (1 << 0)
331 
332 /**
333  * \name Capabilities that might be returned by __DRI2fenceExtensionRec::get_capabilities
334  */
335 /*@{*/
336 #define __DRI_FENCE_CAP_NATIVE_FD 1
337 /*@}*/
338 
339 struct __DRI2fenceExtensionRec {
340    __DRIextension base;
341 
342    /**
343     * Create and insert a fence into the command stream of the context.
344     */
345    void *(*create_fence)(__DRIcontext *ctx);
346 
347    /**
348     * Get a fence associated with the OpenCL event object.
349     * This can be NULL, meaning that OpenCL interoperability is not supported.
350     */
351    void *(*get_fence_from_cl_event)(__DRIscreen *screen, intptr_t cl_event);
352 
353    /**
354     * Destroy a fence.
355     */
356    void (*destroy_fence)(__DRIscreen *screen, void *fence);
357 
358    /**
359     * This function waits and doesn't return until the fence is signalled
360     * or the timeout expires. It returns true if the fence has been signaled.
361     *
362     * \param ctx     the context where commands are flushed
363     * \param fence   the fence
364     * \param flags   a combination of __DRI2_FENCE_FLAG_xxx flags
365     * \param timeout the timeout in ns or __DRI2_FENCE_TIMEOUT_INFINITE
366     */
367    unsigned char (*client_wait_sync)(__DRIcontext *ctx, void *fence,
368                                      unsigned flags, uint64_t timeout);
369 
370    /**
371     * This function enqueues a wait command into the command stream of
372     * the context and then returns. When the execution reaches the wait
373     * command, no further execution will be done in the context until
374     * the fence is signaled. This is a no-op if the device doesn't support
375     * parallel execution of contexts.
376     *
377     * \param ctx     the context where the waiting is done
378     * \param fence   the fence
379     * \param flags   a combination of __DRI2_FENCE_FLAG_xxx flags that make
380     *                sense with this function (right now there are none)
381     */
382    void (*server_wait_sync)(__DRIcontext *ctx, void *fence, unsigned flags);
383 
384    /**
385     * Query for general capabilities of the driver that concern fences.
386     * Returns a bitmask of __DRI_FENCE_CAP_x
387     *
388     * \since 2
389     */
390    unsigned (*get_capabilities)(__DRIscreen *screen);
391 
392    /**
393     * Create an fd (file descriptor) associated fence.  If the fence fd
394     * is -1, this behaves similarly to create_fence() except that when
395     * rendering is flushed the driver creates a fence fd.  Otherwise,
396     * the driver wraps an existing fence fd.
397     *
398     * This is used to implement the EGL_ANDROID_native_fence_sync extension.
399     *
400     * \since 2
401     *
402     * \param ctx     the context associated with the fence
403     * \param fd      the fence fd or -1
404     */
405    void *(*create_fence_fd)(__DRIcontext *ctx, int fd);
406 
407    /**
408     * For fences created with create_fence_fd(), after rendering is flushed,
409     * this retrieves the native fence fd.  Caller takes ownership of the
410     * fd and will close() it when it is no longer needed.
411     *
412     * \since 2
413     *
414     * \param screen  the screen associated with the fence
415     * \param fence   the fence
416     */
417    int (*get_fence_fd)(__DRIscreen *screen, void *fence);
418 };
419 
420 
421 /**
422  * Extension for API interop.
423  * See GL/mesa_glinterop.h.
424  */
425 
426 #define __DRI2_INTEROP "DRI2_Interop"
427 #define __DRI2_INTEROP_VERSION 1
428 
429 struct mesa_glinterop_device_info;
430 struct mesa_glinterop_export_in;
431 struct mesa_glinterop_export_out;
432 
433 struct __DRI2interopExtensionRec {
434    __DRIextension base;
435 
436    /** Same as MesaGLInterop*QueryDeviceInfo. */
437    int (*query_device_info)(__DRIcontext *ctx,
438                             struct mesa_glinterop_device_info *out);
439 
440    /** Same as MesaGLInterop*ExportObject. */
441    int (*export_object)(__DRIcontext *ctx,
442                         struct mesa_glinterop_export_in *in,
443                         struct mesa_glinterop_export_out *out);
444 };
445 
446 
447 /**
448  * Extension for limiting window system back buffer rendering to user-defined
449  * scissor region.
450  */
451 
452 #define __DRI2_BUFFER_DAMAGE "DRI2_BufferDamage"
453 #define __DRI2_BUFFER_DAMAGE_VERSION 1
454 
455 struct __DRI2bufferDamageExtensionRec {
456    __DRIextension base;
457 
458    /**
459     * Provides an array of rectangles representing an overriding scissor region
460     * for rendering operations performed to the specified drawable. These
461     * rectangles do not replace client API scissor regions or draw
462     * co-ordinates, but instead inform the driver of the overall bounds of all
463     * operations which will be issued before the next flush.
464     *
465     * Any rendering operations writing pixels outside this region to the
466     * drawable will have an undefined effect on the entire drawable.
467     *
468     * This entrypoint may only be called after the drawable has either been
469     * newly created or flushed, and before any rendering operations which write
470     * pixels to the drawable. Calling this entrypoint at any other time will
471     * have an undefined effect on the entire drawable.
472     *
473     * Calling this entrypoint with @nrects 0 and @rects NULL will reset the
474     * region to the buffer's full size. This entrypoint may be called once to
475     * reset the region, followed by a second call with a populated region,
476     * before a rendering call is made.
477     *
478     * Used to implement EGL_KHR_partial_update.
479     *
480     * \param drawable affected drawable
481     * \param nrects   number of rectangles provided
482     * \param rects    the array of rectangles, lower-left origin
483     */
484    void (*set_damage_region)(__DRIdrawable *drawable, unsigned int nrects,
485                              int *rects);
486 };
487 
488 /*@}*/
489 
490 /**
491  * The following extensions describe loader features that the DRI
492  * driver can make use of.  Some of these are mandatory, such as the
493  * getDrawableInfo extension for DRI and the DRI Loader extensions for
494  * DRI2, while others are optional, and if present allow the driver to
495  * expose certain features.  The loader pass in a NULL terminated
496  * array of these extensions to the driver in the createNewScreen
497  * constructor.
498  */
499 
500 typedef struct __DRIgetDrawableInfoExtensionRec __DRIgetDrawableInfoExtension;
501 typedef struct __DRIsystemTimeExtensionRec __DRIsystemTimeExtension;
502 typedef struct __DRIdamageExtensionRec __DRIdamageExtension;
503 typedef struct __DRIloaderExtensionRec __DRIloaderExtension;
504 typedef struct __DRIswrastLoaderExtensionRec __DRIswrastLoaderExtension;
505 
506 /**
507  * Callback to get system time for media stream counter extensions.
508  */
509 #define __DRI_SYSTEM_TIME "DRI_SystemTime"
510 #define __DRI_SYSTEM_TIME_VERSION 1
511 struct __DRIsystemTimeExtensionRec {
512     __DRIextension base;
513 
514     /**
515      * Get the 64-bit unadjusted system time (UST).
516      */
517     int (*getUST)(int64_t * ust);
518 
519     /**
520      * Get the media stream counter (MSC) rate.
521      *
522      * Matching the definition in GLX_OML_sync_control, this function returns
523      * the rate of the "media stream counter".  In practical terms, this is
524      * the frame refresh rate of the display.
525      */
526     unsigned char (*getMSCRate)(__DRIdrawable *draw,
527 			    int32_t * numerator, int32_t * denominator,
528 			    void *loaderPrivate);
529 };
530 
531 /**
532  * Damage reporting
533  */
534 #define __DRI_DAMAGE "DRI_Damage"
535 #define __DRI_DAMAGE_VERSION 1
536 struct __DRIdamageExtensionRec {
537     __DRIextension base;
538 
539     /**
540      * Reports areas of the given drawable which have been modified by the
541      * driver.
542      *
543      * \param drawable which the drawing was done to.
544      * \param rects rectangles affected, with the drawable origin as the
545      *	      origin.
546      * \param x X offset of the drawable within the screen (used in the
547      *	      front_buffer case)
548      * \param y Y offset of the drawable within the screen.
549      * \param front_buffer boolean flag for whether the drawing to the
550      * 	      drawable was actually done directly to the front buffer (instead
551      *	      of backing storage, for example)
552      * \param loaderPrivate the data passed in at createNewDrawable time
553      */
554     void (*reportDamage)(__DRIdrawable *draw,
555 			 int x, int y,
556 			 drm_clip_rect_t *rects, int num_rects,
557 			 unsigned char front_buffer,
558 			 void *loaderPrivate);
559 };
560 
561 #define __DRI_SWRAST_IMAGE_OP_DRAW	1
562 #define __DRI_SWRAST_IMAGE_OP_CLEAR	2
563 #define __DRI_SWRAST_IMAGE_OP_SWAP	3
564 
565 /**
566  * SWRast Loader extension.
567  */
568 #define __DRI_SWRAST_LOADER "DRI_SWRastLoader"
569 #define __DRI_SWRAST_LOADER_VERSION 6
570 struct __DRIswrastLoaderExtensionRec {
571     __DRIextension base;
572 
573     /*
574      * Drawable position and size
575      */
576     void (*getDrawableInfo)(__DRIdrawable *drawable,
577 			    int *x, int *y, int *width, int *height,
578 			    void *loaderPrivate);
579 
580     /**
581      * Put image to drawable
582      */
583     void (*putImage)(__DRIdrawable *drawable, int op,
584 		     int x, int y, int width, int height,
585 		     char *data, void *loaderPrivate);
586 
587     /**
588      * Get image from readable
589      */
590     void (*getImage)(__DRIdrawable *readable,
591 		     int x, int y, int width, int height,
592 		     char *data, void *loaderPrivate);
593 
594     /**
595      * Put image to drawable
596      *
597      * \since 2
598      */
599     void (*putImage2)(__DRIdrawable *drawable, int op,
600                       int x, int y, int width, int height, int stride,
601                       char *data, void *loaderPrivate);
602 
603    /**
604      * Put image to drawable
605      *
606      * \since 3
607      */
608    void (*getImage2)(__DRIdrawable *readable,
609 		     int x, int y, int width, int height, int stride,
610 		     char *data, void *loaderPrivate);
611 
612     /**
613      * Put shm image to drawable
614      *
615      * \since 4
616      */
617     void (*putImageShm)(__DRIdrawable *drawable, int op,
618                         int x, int y, int width, int height, int stride,
619                         int shmid, char *shmaddr, unsigned offset,
620                         void *loaderPrivate);
621     /**
622      * Get shm image from readable
623      *
624      * \since 4
625      */
626     void (*getImageShm)(__DRIdrawable *readable,
627                         int x, int y, int width, int height,
628                         int shmid, void *loaderPrivate);
629 
630    /**
631      * Put shm image to drawable (v2)
632      *
633      * The original version fixes srcx/y to 0, and expected
634      * the offset to be adjusted. This version allows src x,y
635      * to not be included in the offset. This is needed to
636      * avoid certain overflow checks in the X server, that
637      * result in lost rendering.
638      *
639      * \since 5
640      */
641     void (*putImageShm2)(__DRIdrawable *drawable, int op,
642                          int x, int y,
643                          int width, int height, int stride,
644                          int shmid, char *shmaddr, unsigned offset,
645                          void *loaderPrivate);
646 
647     /**
648      * get shm image to drawable (v2)
649      *
650      * There are some cases where GLX can't use SHM, but DRI
651      * still tries, we need to get a return type for when to
652      * fallback to the non-shm path.
653      *
654      * \since 6
655      */
656     unsigned char (*getImageShm2)(__DRIdrawable *readable,
657                                   int x, int y, int width, int height,
658                                   int shmid, void *loaderPrivate);
659 };
660 
661 /**
662  * Invalidate loader extension.  The presence of this extension
663  * indicates to the DRI driver that the loader will call invalidate in
664  * the __DRI2_FLUSH extension, whenever the needs to query for new
665  * buffers.  This means that the DRI driver can drop the polling in
666  * glViewport().
667  *
668  * The extension doesn't provide any functionality, it's only use to
669  * indicate to the driver that it can use the new semantics.  A DRI
670  * driver can use this to switch between the different semantics or
671  * just refuse to initialize if this extension isn't present.
672  */
673 #define __DRI_USE_INVALIDATE "DRI_UseInvalidate"
674 #define __DRI_USE_INVALIDATE_VERSION 1
675 
676 typedef struct __DRIuseInvalidateExtensionRec __DRIuseInvalidateExtension;
677 struct __DRIuseInvalidateExtensionRec {
678    __DRIextension base;
679 };
680 
681 /**
682  * The remaining extensions describe driver extensions, immediately
683  * available interfaces provided by the driver.  To start using the
684  * driver, dlsym() for the __DRI_DRIVER_EXTENSIONS symbol and look for
685  * the extension you need in the array.
686  */
687 #define __DRI_DRIVER_EXTENSIONS "__driDriverExtensions"
688 
689 /**
690  * This symbol replaces the __DRI_DRIVER_EXTENSIONS symbol, and will be
691  * suffixed by "_drivername", allowing multiple drivers to be built into one
692  * library, and also giving the driver the chance to return a variable driver
693  * extensions struct depending on the driver name being loaded or any other
694  * system state.
695  *
696  * The function prototype is:
697  *
698  * const __DRIextension **__driDriverGetExtensions_drivername(void);
699  */
700 #define __DRI_DRIVER_GET_EXTENSIONS "__driDriverGetExtensions"
701 
702 /**
703  * Tokens for __DRIconfig attribs.  A number of attributes defined by
704  * GLX or EGL standards are not in the table, as they must be provided
705  * by the loader.  For example, FBConfig ID or visual ID, drawable type.
706  */
707 
708 #define __DRI_ATTRIB_BUFFER_SIZE		 1
709 #define __DRI_ATTRIB_LEVEL			 2
710 #define __DRI_ATTRIB_RED_SIZE			 3
711 #define __DRI_ATTRIB_GREEN_SIZE			 4
712 #define __DRI_ATTRIB_BLUE_SIZE			 5
713 #define __DRI_ATTRIB_LUMINANCE_SIZE		 6
714 #define __DRI_ATTRIB_ALPHA_SIZE			 7
715 #define __DRI_ATTRIB_ALPHA_MASK_SIZE		 8
716 #define __DRI_ATTRIB_DEPTH_SIZE			 9
717 #define __DRI_ATTRIB_STENCIL_SIZE		10
718 #define __DRI_ATTRIB_ACCUM_RED_SIZE		11
719 #define __DRI_ATTRIB_ACCUM_GREEN_SIZE		12
720 #define __DRI_ATTRIB_ACCUM_BLUE_SIZE		13
721 #define __DRI_ATTRIB_ACCUM_ALPHA_SIZE		14
722 #define __DRI_ATTRIB_SAMPLE_BUFFERS		15
723 #define __DRI_ATTRIB_SAMPLES			16
724 #define __DRI_ATTRIB_RENDER_TYPE		17
725 #define __DRI_ATTRIB_CONFIG_CAVEAT		18
726 #define __DRI_ATTRIB_CONFORMANT			19
727 #define __DRI_ATTRIB_DOUBLE_BUFFER		20
728 #define __DRI_ATTRIB_STEREO			21
729 #define __DRI_ATTRIB_AUX_BUFFERS		22
730 #define __DRI_ATTRIB_TRANSPARENT_TYPE		23
731 #define __DRI_ATTRIB_TRANSPARENT_INDEX_VALUE	24
732 #define __DRI_ATTRIB_TRANSPARENT_RED_VALUE	25
733 #define __DRI_ATTRIB_TRANSPARENT_GREEN_VALUE	26
734 #define __DRI_ATTRIB_TRANSPARENT_BLUE_VALUE	27
735 #define __DRI_ATTRIB_TRANSPARENT_ALPHA_VALUE	28
736 #define __DRI_ATTRIB_FLOAT_MODE			29
737 #define __DRI_ATTRIB_RED_MASK			30
738 #define __DRI_ATTRIB_GREEN_MASK			31
739 #define __DRI_ATTRIB_BLUE_MASK			32
740 #define __DRI_ATTRIB_ALPHA_MASK			33
741 #define __DRI_ATTRIB_MAX_PBUFFER_WIDTH		34
742 #define __DRI_ATTRIB_MAX_PBUFFER_HEIGHT		35
743 #define __DRI_ATTRIB_MAX_PBUFFER_PIXELS		36
744 #define __DRI_ATTRIB_OPTIMAL_PBUFFER_WIDTH	37
745 #define __DRI_ATTRIB_OPTIMAL_PBUFFER_HEIGHT	38
746 #define __DRI_ATTRIB_VISUAL_SELECT_GROUP	39
747 #define __DRI_ATTRIB_SWAP_METHOD		40
748 #define __DRI_ATTRIB_MAX_SWAP_INTERVAL		41
749 #define __DRI_ATTRIB_MIN_SWAP_INTERVAL		42
750 #define __DRI_ATTRIB_BIND_TO_TEXTURE_RGB	43
751 #define __DRI_ATTRIB_BIND_TO_TEXTURE_RGBA	44
752 #define __DRI_ATTRIB_BIND_TO_MIPMAP_TEXTURE	45
753 #define __DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS	46
754 #define __DRI_ATTRIB_YINVERTED			47
755 #define __DRI_ATTRIB_FRAMEBUFFER_SRGB_CAPABLE	48
756 #define __DRI_ATTRIB_MUTABLE_RENDER_BUFFER	49 /* EGL_MUTABLE_RENDER_BUFFER_BIT_KHR */
757 #define __DRI_ATTRIB_RED_SHIFT			50
758 #define __DRI_ATTRIB_GREEN_SHIFT		51
759 #define __DRI_ATTRIB_BLUE_SHIFT			52
760 #define __DRI_ATTRIB_ALPHA_SHIFT		53
761 #define __DRI_ATTRIB_MAX			54
762 
763 /* __DRI_ATTRIB_RENDER_TYPE */
764 #define __DRI_ATTRIB_RGBA_BIT			0x01
765 #define __DRI_ATTRIB_COLOR_INDEX_BIT		0x02
766 #define __DRI_ATTRIB_LUMINANCE_BIT		0x04
767 #define __DRI_ATTRIB_FLOAT_BIT			0x08
768 #define __DRI_ATTRIB_UNSIGNED_FLOAT_BIT		0x10
769 
770 /* __DRI_ATTRIB_CONFIG_CAVEAT */
771 #define __DRI_ATTRIB_SLOW_BIT			0x01
772 #define __DRI_ATTRIB_NON_CONFORMANT_CONFIG	0x02
773 
774 /* __DRI_ATTRIB_TRANSPARENT_TYPE */
775 #define __DRI_ATTRIB_TRANSPARENT_RGB		0x00
776 #define __DRI_ATTRIB_TRANSPARENT_INDEX		0x01
777 
778 /* __DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS	 */
779 #define __DRI_ATTRIB_TEXTURE_1D_BIT		0x01
780 #define __DRI_ATTRIB_TEXTURE_2D_BIT		0x02
781 #define __DRI_ATTRIB_TEXTURE_RECTANGLE_BIT	0x04
782 
783 /* __DRI_ATTRIB_SWAP_METHOD */
784 /* Note that with the exception of __DRI_ATTRIB_SWAP_NONE, we need to define
785  * the same tokens as GLX. This is because old and current X servers will
786  * transmit the driconf value grabbed from the AIGLX driver untranslated as
787  * the GLX fbconfig value. __DRI_ATTRIB_SWAP_NONE is only used by dri drivers
788  * to signal to the dri core that the driconfig is single-buffer.
789  */
790 #define __DRI_ATTRIB_SWAP_NONE                  0x0000
791 #define __DRI_ATTRIB_SWAP_EXCHANGE              0x8061
792 #define __DRI_ATTRIB_SWAP_COPY                  0x8062
793 #define __DRI_ATTRIB_SWAP_UNDEFINED             0x8063
794 
795 /**
796  * This extension defines the core DRI functionality.
797  *
798  * Version >= 2 indicates that getConfigAttrib with __DRI_ATTRIB_SWAP_METHOD
799  * returns a reliable value.
800  */
801 #define __DRI_CORE "DRI_Core"
802 #define __DRI_CORE_VERSION 2
803 
804 struct __DRIcoreExtensionRec {
805     __DRIextension base;
806 
807     __DRIscreen *(*createNewScreen)(int screen, int fd,
808 				    unsigned int sarea_handle,
809 				    const __DRIextension **extensions,
810 				    const __DRIconfig ***driverConfigs,
811 				    void *loaderPrivate);
812 
813     void (*destroyScreen)(__DRIscreen *screen);
814 
815     const __DRIextension **(*getExtensions)(__DRIscreen *screen);
816 
817     int (*getConfigAttrib)(const __DRIconfig *config,
818 			   unsigned int attrib,
819 			   unsigned int *value);
820 
821     int (*indexConfigAttrib)(const __DRIconfig *config, int index,
822 			     unsigned int *attrib, unsigned int *value);
823 
824     __DRIdrawable *(*createNewDrawable)(__DRIscreen *screen,
825 					const __DRIconfig *config,
826 					unsigned int drawable_id,
827 					unsigned int head,
828 					void *loaderPrivate);
829 
830     void (*destroyDrawable)(__DRIdrawable *drawable);
831 
832     void (*swapBuffers)(__DRIdrawable *drawable);
833 
834     __DRIcontext *(*createNewContext)(__DRIscreen *screen,
835 				      const __DRIconfig *config,
836 				      __DRIcontext *shared,
837 				      void *loaderPrivate);
838 
839     int (*copyContext)(__DRIcontext *dest,
840 		       __DRIcontext *src,
841 		       unsigned long mask);
842 
843     void (*destroyContext)(__DRIcontext *context);
844 
845     int (*bindContext)(__DRIcontext *ctx,
846 		       __DRIdrawable *pdraw,
847 		       __DRIdrawable *pread);
848 
849     int (*unbindContext)(__DRIcontext *ctx);
850 };
851 
852 /**
853  * Stored version of some component (i.e., server-side DRI module, kernel-side
854  * DRM, etc.).
855  *
856  * \todo
857  * There are several data structures that explicitly store a major version,
858  * minor version, and patch level.  These structures should be modified to
859  * have a \c __DRIversionRec instead.
860  */
861 struct __DRIversionRec {
862     int    major;        /**< Major version number. */
863     int    minor;        /**< Minor version number. */
864     int    patch;        /**< Patch-level. */
865 };
866 
867 /**
868  * Framebuffer information record.  Used by libGL to communicate information
869  * about the framebuffer to the driver's \c __driCreateNewScreen function.
870  *
871  * In XFree86, most of this information is derrived from data returned by
872  * calling \c XF86DRIGetDeviceInfo.
873  *
874  * \sa XF86DRIGetDeviceInfo __DRIdisplayRec::createNewScreen
875  *     __driUtilCreateNewScreen CallCreateNewScreen
876  *
877  * \bug This structure could be better named.
878  */
879 struct __DRIframebufferRec {
880     unsigned char *base;    /**< Framebuffer base address in the CPU's
881 			     * address space.  This value is calculated by
882 			     * calling \c drmMap on the framebuffer handle
883 			     * returned by \c XF86DRIGetDeviceInfo (or a
884 			     * similar function).
885 			     */
886     int size;               /**< Framebuffer size, in bytes. */
887     int stride;             /**< Number of bytes from one line to the next. */
888     int width;              /**< Pixel width of the framebuffer. */
889     int height;             /**< Pixel height of the framebuffer. */
890     int dev_priv_size;      /**< Size of the driver's dev-priv structure. */
891     void *dev_priv;         /**< Pointer to the driver's dev-priv structure. */
892 };
893 
894 
895 /**
896  * This extension provides alternative screen, drawable and context
897  * constructors for legacy DRI functionality.  This is used in
898  * conjunction with the core extension.
899  */
900 #define __DRI_LEGACY "DRI_Legacy"
901 #define __DRI_LEGACY_VERSION 1
902 
903 struct __DRIlegacyExtensionRec {
904     __DRIextension base;
905 
906     __DRIscreen *(*createNewScreen)(int screen,
907 				    const __DRIversion *ddx_version,
908 				    const __DRIversion *dri_version,
909 				    const __DRIversion *drm_version,
910 				    const __DRIframebuffer *frame_buffer,
911 				    void *pSAREA, int fd,
912 				    const __DRIextension **extensions,
913 				    const __DRIconfig ***driver_configs,
914 				    void *loaderPrivate);
915 
916     __DRIdrawable *(*createNewDrawable)(__DRIscreen *screen,
917 					const __DRIconfig *config,
918 					drm_drawable_t hwDrawable,
919 					int renderType, const int *attrs,
920 					void *loaderPrivate);
921 
922     __DRIcontext *(*createNewContext)(__DRIscreen *screen,
923 				      const __DRIconfig *config,
924 				      int render_type,
925 				      __DRIcontext *shared,
926 				      drm_context_t hwContext,
927 				      void *loaderPrivate);
928 };
929 
930 /**
931  * This extension provides alternative screen, drawable and context
932  * constructors for swrast DRI functionality.  This is used in
933  * conjunction with the core extension.
934  */
935 #define __DRI_SWRAST "DRI_SWRast"
936 #define __DRI_SWRAST_VERSION 4
937 
938 struct __DRIswrastExtensionRec {
939     __DRIextension base;
940 
941     __DRIscreen *(*createNewScreen)(int screen,
942 				    const __DRIextension **extensions,
943 				    const __DRIconfig ***driver_configs,
944 				    void *loaderPrivate);
945 
946     __DRIdrawable *(*createNewDrawable)(__DRIscreen *screen,
947 					const __DRIconfig *config,
948 					void *loaderPrivate);
949 
950    /* Since version 2 */
951    __DRIcontext *(*createNewContextForAPI)(__DRIscreen *screen,
952                                            int api,
953                                            const __DRIconfig *config,
954                                            __DRIcontext *shared,
955                                            void *data);
956 
957    /**
958     * Create a context for a particular API with a set of attributes
959     *
960     * \since version 3
961     *
962     * \sa __DRIdri2ExtensionRec::createContextAttribs
963     */
964    __DRIcontext *(*createContextAttribs)(__DRIscreen *screen,
965 					 int api,
966 					 const __DRIconfig *config,
967 					 __DRIcontext *shared,
968 					 unsigned num_attribs,
969 					 const uint32_t *attribs,
970 					 unsigned *error,
971 					 void *loaderPrivate);
972 
973    /**
974     * createNewScreen() with the driver extensions passed in.
975     *
976     * \since version 4
977     */
978    __DRIscreen *(*createNewScreen2)(int screen,
979                                     const __DRIextension **loader_extensions,
980                                     const __DRIextension **driver_extensions,
981                                     const __DRIconfig ***driver_configs,
982                                     void *loaderPrivate);
983 
984 };
985 
986 /** Common DRI function definitions, shared among DRI2 and Image extensions
987  */
988 
989 typedef __DRIscreen *
990 (*__DRIcreateNewScreen2Func)(int screen, int fd,
991                              const __DRIextension **extensions,
992                              const __DRIextension **driver_extensions,
993                              const __DRIconfig ***driver_configs,
994                              void *loaderPrivate);
995 
996 typedef __DRIdrawable *
997 (*__DRIcreateNewDrawableFunc)(__DRIscreen *screen,
998                               const __DRIconfig *config,
999                               void *loaderPrivate);
1000 
1001 typedef __DRIcontext *
1002 (*__DRIcreateContextAttribsFunc)(__DRIscreen *screen,
1003                                  int api,
1004                                  const __DRIconfig *config,
1005                                  __DRIcontext *shared,
1006                                  unsigned num_attribs,
1007                                  const uint32_t *attribs,
1008                                  unsigned *error,
1009                                  void *loaderPrivate);
1010 
1011 typedef unsigned int
1012 (*__DRIgetAPIMaskFunc)(__DRIscreen *screen);
1013 
1014 /**
1015  * DRI2 Loader extension.
1016  */
1017 #define __DRI_BUFFER_FRONT_LEFT		0
1018 #define __DRI_BUFFER_BACK_LEFT		1
1019 #define __DRI_BUFFER_FRONT_RIGHT	2
1020 #define __DRI_BUFFER_BACK_RIGHT		3
1021 #define __DRI_BUFFER_DEPTH		4
1022 #define __DRI_BUFFER_STENCIL		5
1023 #define __DRI_BUFFER_ACCUM		6
1024 #define __DRI_BUFFER_FAKE_FRONT_LEFT	7
1025 #define __DRI_BUFFER_FAKE_FRONT_RIGHT	8
1026 #define __DRI_BUFFER_DEPTH_STENCIL	9  /**< Only available with DRI2 1.1 */
1027 #define __DRI_BUFFER_HIZ		10
1028 
1029 /* Inofficial and for internal use. Increase when adding a new buffer token. */
1030 #define __DRI_BUFFER_COUNT		11
1031 
1032 struct __DRIbufferRec {
1033     unsigned int attachment;
1034     unsigned int name;
1035     unsigned int pitch;
1036     unsigned int cpp;
1037     unsigned int flags;
1038 };
1039 
1040 #define __DRI_DRI2_LOADER "DRI_DRI2Loader"
1041 #define __DRI_DRI2_LOADER_VERSION 5
1042 
1043 enum dri_loader_cap {
1044    /* Whether the loader handles RGBA channel ordering correctly. If not,
1045     * only BGRA ordering can be exposed.
1046     */
1047    DRI_LOADER_CAP_RGBA_ORDERING,
1048    DRI_LOADER_CAP_FP16,
1049 };
1050 
1051 struct __DRIdri2LoaderExtensionRec {
1052     __DRIextension base;
1053 
1054     __DRIbuffer *(*getBuffers)(__DRIdrawable *driDrawable,
1055 			       int *width, int *height,
1056 			       unsigned int *attachments, int count,
1057 			       int *out_count, void *loaderPrivate);
1058 
1059     /**
1060      * Flush pending front-buffer rendering
1061      *
1062      * Any rendering that has been performed to the
1063      * \c __DRI_BUFFER_FAKE_FRONT_LEFT will be flushed to the
1064      * \c __DRI_BUFFER_FRONT_LEFT.
1065      *
1066      * \param driDrawable    Drawable whose front-buffer is to be flushed
1067      * \param loaderPrivate  Loader's private data that was previously passed
1068      *                       into __DRIdri2ExtensionRec::createNewDrawable
1069      *
1070      * \since 2
1071      */
1072     void (*flushFrontBuffer)(__DRIdrawable *driDrawable, void *loaderPrivate);
1073 
1074 
1075     /**
1076      * Get list of buffers from the server
1077      *
1078      * Gets a list of buffer for the specified set of attachments.  Unlike
1079      * \c ::getBuffers, this function takes a list of attachments paired with
1080      * opaque \c unsigned \c int value describing the format of the buffer.
1081      * It is the responsibility of the caller to know what the service that
1082      * allocates the buffers will expect to receive for the format.
1083      *
1084      * \param driDrawable    Drawable whose buffers are being queried.
1085      * \param width          Output where the width of the buffers is stored.
1086      * \param height         Output where the height of the buffers is stored.
1087      * \param attachments    List of pairs of attachment ID and opaque format
1088      *                       requested for the drawable.
1089      * \param count          Number of attachment / format pairs stored in
1090      *                       \c attachments.
1091      * \param loaderPrivate  Loader's private data that was previously passed
1092      *                       into __DRIdri2ExtensionRec::createNewDrawable.
1093      *
1094      * \since 3
1095      */
1096     __DRIbuffer *(*getBuffersWithFormat)(__DRIdrawable *driDrawable,
1097 					 int *width, int *height,
1098 					 unsigned int *attachments, int count,
1099 					 int *out_count, void *loaderPrivate);
1100 
1101     /**
1102      * Return a loader capability value. If the loader doesn't know the enum,
1103      * it will return 0.
1104      *
1105      * \param loaderPrivate The last parameter of createNewScreen or
1106      *                      createNewScreen2.
1107      * \param cap           See the enum.
1108      *
1109      * \since 4
1110      */
1111     unsigned (*getCapability)(void *loaderPrivate, enum dri_loader_cap cap);
1112 
1113     /**
1114      * Clean up any loader state associated with an image.
1115      *
1116      * \param loaderPrivate  Loader's private data that was previously passed
1117      *                       into a __DRIimageExtensionRec::createImage function
1118      * \since 5
1119      */
1120     void (*destroyLoaderImageState)(void *loaderPrivate);
1121 };
1122 
1123 /**
1124  * This extension provides alternative screen, drawable and context
1125  * constructors for DRI2.
1126  */
1127 #define __DRI_DRI2 "DRI_DRI2"
1128 #define __DRI_DRI2_VERSION 4
1129 
1130 #define __DRI_API_OPENGL	0	/**< OpenGL compatibility profile */
1131 #define __DRI_API_GLES		1	/**< OpenGL ES 1.x */
1132 #define __DRI_API_GLES2		2	/**< OpenGL ES 2.x */
1133 #define __DRI_API_OPENGL_CORE	3	/**< OpenGL 3.2+ core profile */
1134 #define __DRI_API_GLES3		4	/**< OpenGL ES 3.x */
1135 
1136 #define __DRI_CTX_ATTRIB_MAJOR_VERSION		0
1137 #define __DRI_CTX_ATTRIB_MINOR_VERSION		1
1138 
1139 #define __DRI_CTX_ATTRIB_FLAGS			2
1140 #define __DRI_CTX_FLAG_DEBUG			0x00000001
1141 #define __DRI_CTX_FLAG_FORWARD_COMPATIBLE	0x00000002
1142 #define __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS	0x00000004
1143 #define __DRI_CTX_FLAG_NO_ERROR			0x00000008
1144 
1145 #define __DRI_CTX_ATTRIB_RESET_STRATEGY		3
1146 #define __DRI_CTX_RESET_NO_NOTIFICATION		0
1147 #define __DRI_CTX_RESET_LOSE_CONTEXT		1
1148 
1149 #define __DRI_CTX_ATTRIB_PRIORITY		4
1150 #define __DRI_CTX_PRIORITY_LOW			0
1151 #define __DRI_CTX_PRIORITY_MEDIUM		1
1152 #define __DRI_CTX_PRIORITY_HIGH			2
1153 
1154 #define __DRI_CTX_ATTRIB_RELEASE_BEHAVIOR	5
1155 #define __DRI_CTX_RELEASE_BEHAVIOR_NONE         0
1156 #define __DRI_CTX_RELEASE_BEHAVIOR_FLUSH        1
1157 
1158 #define __DRI_CTX_NUM_ATTRIBS                   6
1159 
1160 /**
1161  * \name Reasons that __DRIdri2Extension::createContextAttribs might fail
1162  */
1163 /*@{*/
1164 /** Success! */
1165 #define __DRI_CTX_ERROR_SUCCESS			0
1166 
1167 /** Memory allocation failure */
1168 #define __DRI_CTX_ERROR_NO_MEMORY		1
1169 
1170 /** Client requested an API (e.g., OpenGL ES 2.0) that the driver can't do. */
1171 #define __DRI_CTX_ERROR_BAD_API			2
1172 
1173 /** Client requested an API version that the driver can't do. */
1174 #define __DRI_CTX_ERROR_BAD_VERSION		3
1175 
1176 /** Client requested a flag or combination of flags the driver can't do. */
1177 #define __DRI_CTX_ERROR_BAD_FLAG		4
1178 
1179 /** Client requested an attribute the driver doesn't understand. */
1180 #define __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE	5
1181 
1182 /** Client requested a flag the driver doesn't understand. */
1183 #define __DRI_CTX_ERROR_UNKNOWN_FLAG		6
1184 /*@}*/
1185 
1186 struct __DRIdri2ExtensionRec {
1187     __DRIextension base;
1188 
1189     __DRIscreen *(*createNewScreen)(int screen, int fd,
1190 				    const __DRIextension **extensions,
1191 				    const __DRIconfig ***driver_configs,
1192 				    void *loaderPrivate);
1193 
1194    __DRIcreateNewDrawableFunc   createNewDrawable;
1195    __DRIcontext *(*createNewContext)(__DRIscreen *screen,
1196                                      const __DRIconfig *config,
1197                                      __DRIcontext *shared,
1198                                      void *loaderPrivate);
1199 
1200    /* Since version 2 */
1201    __DRIgetAPIMaskFunc          getAPIMask;
1202 
1203    __DRIcontext *(*createNewContextForAPI)(__DRIscreen *screen,
1204 					   int api,
1205 					   const __DRIconfig *config,
1206 					   __DRIcontext *shared,
1207 					   void *data);
1208 
1209    __DRIbuffer *(*allocateBuffer)(__DRIscreen *screen,
1210 				  unsigned int attachment,
1211 				  unsigned int format,
1212 				  int width,
1213 				  int height);
1214    void (*releaseBuffer)(__DRIscreen *screen,
1215 			 __DRIbuffer *buffer);
1216 
1217    /**
1218     * Create a context for a particular API with a set of attributes
1219     *
1220     * \since version 3
1221     *
1222     * \sa __DRIswrastExtensionRec::createContextAttribs
1223     */
1224    __DRIcreateContextAttribsFunc        createContextAttribs;
1225 
1226    /**
1227     * createNewScreen with the driver's extension list passed in.
1228     *
1229     * \since version 4
1230     */
1231    __DRIcreateNewScreen2Func            createNewScreen2;
1232 };
1233 
1234 
1235 /**
1236  * This extension provides functionality to enable various EGLImage
1237  * extensions.
1238  */
1239 #define __DRI_IMAGE "DRI_IMAGE"
1240 #define __DRI_IMAGE_VERSION 19
1241 
1242 /**
1243  * These formats correspond to the similarly named MESA_FORMAT_*
1244  * tokens, except in the native endian of the CPU.  For example, on
1245  * little endian __DRI_IMAGE_FORMAT_XRGB8888 corresponds to
1246  * MESA_FORMAT_XRGB8888, but MESA_FORMAT_XRGB8888_REV on big endian.
1247  *
1248  * __DRI_IMAGE_FORMAT_NONE is for images that aren't directly usable
1249  * by the driver (YUV planar formats) but serve as a base image for
1250  * creating sub-images for the different planes within the image.
1251  *
1252  * R8, GR88 and NONE should not be used with createImageFromName or
1253  * createImage, and are returned by query from sub images created with
1254  * createImageFromNames (NONE, see above) and fromPlane (R8 & GR88).
1255  */
1256 #define __DRI_IMAGE_FORMAT_RGB565       0x1001
1257 #define __DRI_IMAGE_FORMAT_XRGB8888     0x1002
1258 #define __DRI_IMAGE_FORMAT_ARGB8888     0x1003
1259 #define __DRI_IMAGE_FORMAT_ABGR8888     0x1004
1260 #define __DRI_IMAGE_FORMAT_XBGR8888     0x1005
1261 #define __DRI_IMAGE_FORMAT_R8           0x1006 /* Since version 5 */
1262 #define __DRI_IMAGE_FORMAT_GR88         0x1007
1263 #define __DRI_IMAGE_FORMAT_NONE         0x1008
1264 #define __DRI_IMAGE_FORMAT_XRGB2101010  0x1009
1265 #define __DRI_IMAGE_FORMAT_ARGB2101010  0x100a
1266 #define __DRI_IMAGE_FORMAT_SARGB8       0x100b
1267 #define __DRI_IMAGE_FORMAT_ARGB1555     0x100c
1268 #define __DRI_IMAGE_FORMAT_R16          0x100d
1269 #define __DRI_IMAGE_FORMAT_GR1616       0x100e
1270 #define __DRI_IMAGE_FORMAT_YUYV         0x100f
1271 #define __DRI_IMAGE_FORMAT_XBGR2101010  0x1010
1272 #define __DRI_IMAGE_FORMAT_ABGR2101010  0x1011
1273 #define __DRI_IMAGE_FORMAT_SABGR8       0x1012
1274 #define __DRI_IMAGE_FORMAT_UYVY         0x1013
1275 #define __DRI_IMAGE_FORMAT_XBGR16161616F 0x1014
1276 #define __DRI_IMAGE_FORMAT_ABGR16161616F 0x1015
1277 #define __DRI_IMAGE_FORMAT_SXRGB8       0x1016
1278 #define __DRI_IMAGE_FORMAT_ABGR16161616 0x1017
1279 
1280 #define __DRI_IMAGE_USE_SHARE		0x0001
1281 #define __DRI_IMAGE_USE_SCANOUT		0x0002
1282 #define __DRI_IMAGE_USE_CURSOR		0x0004 /* Deprecated */
1283 #define __DRI_IMAGE_USE_LINEAR		0x0008
1284 /* The buffer will only be read by an external process after SwapBuffers,
1285  * in contrary to gbm buffers, front buffers and fake front buffers, which
1286  * could be read after a flush."
1287  */
1288 #define __DRI_IMAGE_USE_BACKBUFFER      0x0010
1289 #define __DRI_IMAGE_USE_PROTECTED       0x0020
1290 
1291 
1292 #define __DRI_IMAGE_TRANSFER_READ            0x1
1293 #define __DRI_IMAGE_TRANSFER_WRITE           0x2
1294 #define __DRI_IMAGE_TRANSFER_READ_WRITE      \
1295         (__DRI_IMAGE_TRANSFER_READ | __DRI_IMAGE_TRANSFER_WRITE)
1296 
1297 /**
1298  * Extra fourcc formats used internally to Mesa with createImageFromNames.
1299  * The externally-available fourccs are defined by drm_fourcc.h (DRM_FORMAT_*)
1300  * and WL_DRM_FORMAT_* from wayland_drm.h.
1301  *
1302  * \since 5
1303  */
1304 
1305 #define __DRI_IMAGE_FOURCC_SARGB8888	0x83324258
1306 #define __DRI_IMAGE_FOURCC_SABGR8888	0x84324258
1307 #define __DRI_IMAGE_FOURCC_SXRGB8888	0x85324258
1308 #define __DRI_IMAGE_FOURCC_RGBA16161616 0x38344152  /* fourcc_code('R', 'A', '4', '8' ) */
1309 
1310 /**
1311  * Queryable on images created by createImageFromNames.
1312  *
1313  * RGB and RGBA might be usable directly as images, but it's still
1314  * recommended to call fromPlanar with plane == 0.
1315  *
1316  * Y_U_V, Y_UV,Y_XUXV and Y_UXVX all requires call to fromPlanar to create
1317  * usable sub-images, sampling from images return raw YUV data and
1318  * color conversion needs to be done in the shader.
1319  *
1320  * \since 5
1321  */
1322 
1323 #define __DRI_IMAGE_COMPONENTS_RGB	0x3001
1324 #define __DRI_IMAGE_COMPONENTS_RGBA	0x3002
1325 #define __DRI_IMAGE_COMPONENTS_Y_U_V	0x3003
1326 #define __DRI_IMAGE_COMPONENTS_Y_UV	0x3004
1327 #define __DRI_IMAGE_COMPONENTS_Y_XUXV	0x3005
1328 #define __DRI_IMAGE_COMPONENTS_Y_UXVX	0x3008
1329 #define __DRI_IMAGE_COMPONENTS_AYUV	0x3009
1330 #define __DRI_IMAGE_COMPONENTS_XYUV	0x300A
1331 #define __DRI_IMAGE_COMPONENTS_R	0x3006
1332 #define __DRI_IMAGE_COMPONENTS_RG	0x3007
1333 
1334 
1335 /**
1336  * queryImage attributes
1337  */
1338 
1339 #define __DRI_IMAGE_ATTRIB_STRIDE	0x2000
1340 #define __DRI_IMAGE_ATTRIB_HANDLE	0x2001
1341 #define __DRI_IMAGE_ATTRIB_NAME		0x2002
1342 #define __DRI_IMAGE_ATTRIB_FORMAT	0x2003 /* available in versions 3+ */
1343 #define __DRI_IMAGE_ATTRIB_WIDTH	0x2004 /* available in versions 4+ */
1344 #define __DRI_IMAGE_ATTRIB_HEIGHT	0x2005
1345 #define __DRI_IMAGE_ATTRIB_COMPONENTS	0x2006 /* available in versions 5+ */
1346 #define __DRI_IMAGE_ATTRIB_FD           0x2007 /* available in versions
1347                                                 * 7+. Each query will return a
1348                                                 * new fd. */
1349 #define __DRI_IMAGE_ATTRIB_FOURCC       0x2008 /* available in versions 11 */
1350 #define __DRI_IMAGE_ATTRIB_NUM_PLANES   0x2009 /* available in versions 11 */
1351 
1352 #define __DRI_IMAGE_ATTRIB_OFFSET 0x200A /* available in versions 13 */
1353 #define __DRI_IMAGE_ATTRIB_MODIFIER_LOWER 0x200B /* available in versions 14 */
1354 #define __DRI_IMAGE_ATTRIB_MODIFIER_UPPER 0x200C /* available in versions 14 */
1355 
1356 enum __DRIYUVColorSpace {
1357    __DRI_YUV_COLOR_SPACE_UNDEFINED = 0,
1358    __DRI_YUV_COLOR_SPACE_ITU_REC601 = 0x327F,
1359    __DRI_YUV_COLOR_SPACE_ITU_REC709 = 0x3280,
1360    __DRI_YUV_COLOR_SPACE_ITU_REC2020 = 0x3281
1361 };
1362 
1363 enum __DRISampleRange {
1364    __DRI_YUV_RANGE_UNDEFINED = 0,
1365    __DRI_YUV_FULL_RANGE = 0x3282,
1366    __DRI_YUV_NARROW_RANGE = 0x3283
1367 };
1368 
1369 enum __DRIChromaSiting {
1370    __DRI_YUV_CHROMA_SITING_UNDEFINED = 0,
1371    __DRI_YUV_CHROMA_SITING_0 = 0x3284,
1372    __DRI_YUV_CHROMA_SITING_0_5 = 0x3285
1373 };
1374 
1375 /**
1376  * \name Reasons that __DRIimageExtensionRec::createImageFromTexture or
1377  * __DRIimageExtensionRec::createImageFromDmaBufs might fail
1378  */
1379 /*@{*/
1380 /** Success! */
1381 #define __DRI_IMAGE_ERROR_SUCCESS       0
1382 
1383 /** Memory allocation failure */
1384 #define __DRI_IMAGE_ERROR_BAD_ALLOC     1
1385 
1386 /** Client requested an invalid attribute */
1387 #define __DRI_IMAGE_ERROR_BAD_MATCH     2
1388 
1389 /** Client requested an invalid texture object */
1390 #define __DRI_IMAGE_ERROR_BAD_PARAMETER 3
1391 
1392 /** Client requested an invalid pitch and/or offset */
1393 #define __DRI_IMAGE_ERROR_BAD_ACCESS    4
1394 /*@}*/
1395 
1396 /**
1397  * \name Capabilities that might be returned by __DRIimageExtensionRec::getCapabilities
1398  */
1399 /*@{*/
1400 #define __DRI_IMAGE_CAP_GLOBAL_NAMES 1
1401 /*@}*/
1402 
1403 /**
1404  * blitImage flags
1405  */
1406 
1407 #define __BLIT_FLAG_FLUSH		0x0001
1408 #define __BLIT_FLAG_FINISH		0x0002
1409 
1410 /**
1411  * Flags for createImageFromDmaBufs3
1412  */
1413 #define __DRI_IMAGE_PROTECTED_CONTENT_FLAG 0x00000001
1414 
1415 /**
1416  * queryDmaBufFormatModifierAttribs attributes
1417  */
1418 
1419 /* Available in version 16 */
1420 #define __DRI_IMAGE_FORMAT_MODIFIER_ATTRIB_PLANE_COUNT   0x0001
1421 
1422 typedef struct __DRIimageRec          __DRIimage;
1423 typedef struct __DRIimageExtensionRec __DRIimageExtension;
1424 struct __DRIimageExtensionRec {
1425     __DRIextension base;
1426 
1427     __DRIimage *(*createImageFromName)(__DRIscreen *screen,
1428 				       int width, int height, int format,
1429 				       int name, int pitch,
1430 				       void *loaderPrivate);
1431 
1432     /* Deprecated since version 17; see createImageFromRenderbuffer2 */
1433     __DRIimage *(*createImageFromRenderbuffer)(__DRIcontext *context,
1434 					       int renderbuffer,
1435 					       void *loaderPrivate);
1436 
1437     void (*destroyImage)(__DRIimage *image);
1438 
1439     __DRIimage *(*createImage)(__DRIscreen *screen,
1440 			       int width, int height, int format,
1441 			       unsigned int use,
1442 			       void *loaderPrivate);
1443 
1444    unsigned char (*queryImage)(__DRIimage *image, int attrib, int *value);
1445 
1446    /**
1447     * The new __DRIimage will share the content with the old one, see dup(2).
1448     */
1449    __DRIimage *(*dupImage)(__DRIimage *image, void *loaderPrivate);
1450 
1451    /**
1452     * Validate that a __DRIimage can be used a certain way.
1453     *
1454     * \since 2
1455     */
1456    unsigned char (*validateUsage)(__DRIimage *image, unsigned int use);
1457 
1458    /**
1459     * Unlike createImageFromName __DRI_IMAGE_FORMAT is not used but instead
1460     * DRM_FORMAT_*, and strides are in bytes not pixels. Stride is
1461     * also per block and not per pixel (for non-RGB, see gallium blocks).
1462     *
1463     * \since 5
1464     */
1465    __DRIimage *(*createImageFromNames)(__DRIscreen *screen,
1466                                        int width, int height, int fourcc,
1467                                        int *names, int num_names,
1468                                        int *strides, int *offsets,
1469                                        void *loaderPrivate);
1470 
1471    /**
1472     * Create an image out of a sub-region of a parent image.  This
1473     * entry point lets us create individual __DRIimages for different
1474     * planes in a planar buffer (typically yuv), for example.  While a
1475     * sub-image shares the underlying buffer object with the parent
1476     * image and other sibling sub-images, the life times of parent and
1477     * sub-images are not dependent.  Destroying the parent or a
1478     * sub-image doesn't affect other images.  The underlying buffer
1479     * object is free when no __DRIimage remains that references it.
1480     *
1481     * Sub-images may overlap, but rendering to overlapping sub-images
1482     * is undefined.
1483     *
1484     * \since 5
1485     */
1486     __DRIimage *(*fromPlanar)(__DRIimage *image, int plane,
1487                               void *loaderPrivate);
1488 
1489     /**
1490      * Create image from texture.
1491      *
1492      * \since 6
1493      */
1494    __DRIimage *(*createImageFromTexture)(__DRIcontext *context,
1495                                          int target,
1496                                          unsigned texture,
1497                                          int depth,
1498                                          int level,
1499                                          unsigned *error,
1500                                          void *loaderPrivate);
1501    /**
1502     * Like createImageFromNames, but takes a prime fd instead.
1503     *
1504     * \since 7
1505     */
1506    __DRIimage *(*createImageFromFds)(__DRIscreen *screen,
1507                                      int width, int height, int fourcc,
1508                                      int *fds, int num_fds,
1509                                      int *strides, int *offsets,
1510                                      void *loaderPrivate);
1511 
1512    /**
1513     * Like createImageFromFds, but takes additional attributes.
1514     *
1515     * For EGL_EXT_image_dma_buf_import.
1516     *
1517     * \since 8
1518     */
1519    __DRIimage *(*createImageFromDmaBufs)(__DRIscreen *screen,
1520                                          int width, int height, int fourcc,
1521                                          int *fds, int num_fds,
1522                                          int *strides, int *offsets,
1523                                          enum __DRIYUVColorSpace color_space,
1524                                          enum __DRISampleRange sample_range,
1525                                          enum __DRIChromaSiting horiz_siting,
1526                                          enum __DRIChromaSiting vert_siting,
1527                                          unsigned *error,
1528                                          void *loaderPrivate);
1529 
1530    /**
1531     * Blit a part of a __DRIimage to another and flushes
1532     *
1533     * flush_flag:
1534     *    0:                  no flush
1535     *    __BLIT_FLAG_FLUSH:  flush after the blit operation
1536     *    __BLIT_FLAG_FINISH: flush and wait the blit finished
1537     *
1538     * \since 9
1539     */
1540    void (*blitImage)(__DRIcontext *context, __DRIimage *dst, __DRIimage *src,
1541                      int dstx0, int dsty0, int dstwidth, int dstheight,
1542                      int srcx0, int srcy0, int srcwidth, int srcheight,
1543                      int flush_flag);
1544 
1545    /**
1546     * Query for general capabilities of the driver that concern
1547     * buffer sharing and image importing.
1548     *
1549     * \since 10
1550     */
1551    int (*getCapabilities)(__DRIscreen *screen);
1552 
1553    /**
1554     * Returns a map of the specified region of a __DRIimage for the specified usage.
1555     *
1556     * flags may include __DRI_IMAGE_TRANSFER_READ, which will populate the
1557     * mapping with the current buffer content. If __DRI_IMAGE_TRANSFER_READ
1558     * is not included in the flags, the buffer content at map time is
1559     * undefined. Users wanting to modify the mapping must include
1560     * __DRI_IMAGE_TRANSFER_WRITE; if __DRI_IMAGE_TRANSFER_WRITE is not
1561     * included, behaviour when writing the mapping is undefined.
1562     *
1563     * Returns the byte stride in *stride, and an opaque pointer to data
1564     * tracking the mapping in **data, which must be passed to unmapImage().
1565     *
1566     * \since 12
1567     */
1568    void *(*mapImage)(__DRIcontext *context, __DRIimage *image,
1569                      int x0, int y0, int width, int height,
1570                      unsigned int flags, int *stride, void **data);
1571 
1572    /**
1573     * Unmap a previously mapped __DRIimage
1574     *
1575     * \since 12
1576     */
1577    void (*unmapImage)(__DRIcontext *context, __DRIimage *image, void *data);
1578 
1579 
1580    /**
1581     * Creates an image with implementation's favorite modifiers.
1582     *
1583     * This acts like createImage except there is a list of modifiers passed in
1584     * which the implementation may selectively use to create the DRIimage. The
1585     * result should be the implementation selects one modifier (perhaps it would
1586     * hold on to a few and later pick).
1587     *
1588     * The created image should be destroyed with destroyImage().
1589     *
1590     * Returns the new DRIimage. The chosen modifier can be obtained later on
1591     * and passed back to things like the kernel's AddFB2 interface.
1592     *
1593     * \sa __DRIimageRec::createImage
1594     *
1595     * \since 14
1596     */
1597    __DRIimage *(*createImageWithModifiers)(__DRIscreen *screen,
1598                                            int width, int height, int format,
1599                                            const uint64_t *modifiers,
1600                                            const unsigned int modifier_count,
1601                                            void *loaderPrivate);
1602 
1603    /*
1604     * Like createImageFromDmaBufs, but takes also format modifiers.
1605     *
1606     * For EGL_EXT_image_dma_buf_import_modifiers.
1607     *
1608     * \since 15
1609     */
1610    __DRIimage *(*createImageFromDmaBufs2)(__DRIscreen *screen,
1611                                           int width, int height, int fourcc,
1612                                           uint64_t modifier,
1613                                           int *fds, int num_fds,
1614                                           int *strides, int *offsets,
1615                                           enum __DRIYUVColorSpace color_space,
1616                                           enum __DRISampleRange sample_range,
1617                                           enum __DRIChromaSiting horiz_siting,
1618                                           enum __DRIChromaSiting vert_siting,
1619                                           unsigned *error,
1620                                           void *loaderPrivate);
1621 
1622    /*
1623     * dmabuf format query to support EGL_EXT_image_dma_buf_import_modifiers.
1624     *
1625     * \param max      Maximum number of formats that can be accomodated into
1626     *                 \param formats. If zero, no formats are returned -
1627     *                 instead, the driver returns the total number of
1628     *                 supported dmabuf formats in \param count.
1629     * \param formats  Buffer to fill formats into.
1630     * \param count    Count of formats returned, or, total number of
1631     *                 supported formats in case \param max is zero.
1632     *
1633     * Returns true on success.
1634     *
1635     * \since 15
1636     */
1637    unsigned char (*queryDmaBufFormats)(__DRIscreen *screen, int max,
1638                                        int *formats, int *count);
1639 
1640    /*
1641     * dmabuf format modifier query for a given format to support
1642     * EGL_EXT_image_dma_buf_import_modifiers.
1643     *
1644     * \param fourcc    The format to query modifiers for. If this format
1645     *                  is not supported by the driver, return false.
1646     * \param max       Maximum number of modifiers that can be accomodated in
1647     *                  \param modifiers. If zero, no modifiers are returned -
1648     *                  instead, the driver returns the total number of
1649     *                  modifiers for \param format in \param count.
1650     * \param modifiers Buffer to fill modifiers into.
1651     * \param count     Count of the modifiers returned, or, total number of
1652     *                  supported modifiers for \param fourcc in case
1653     *                  \param max is zero.
1654     *
1655     * Returns true upon success.
1656     *
1657     * \since 15
1658     */
1659    unsigned char (*queryDmaBufModifiers)(__DRIscreen *screen, int fourcc,
1660                                          int max, uint64_t *modifiers,
1661                                          unsigned int *external_only,
1662                                          int *count);
1663 
1664    /**
1665     * dmabuf format modifier attribute query for a given format and modifier.
1666     *
1667     * \param fourcc    The format to query. If this format is not supported by
1668     *                  the driver, return false.
1669     * \param modifier  The modifier to query. If this format+modifier is not
1670     *                  supported by the driver, return false.
1671     * \param attrib    The __DRI_IMAGE_FORMAT_MODIFIER_ATTRIB to query.
1672     * \param value     A pointer to where to store the result of the query.
1673     *
1674     * Returns true upon success.
1675     *
1676     * \since 16
1677     */
1678    unsigned char (*queryDmaBufFormatModifierAttribs)(__DRIscreen *screen,
1679                                                      uint32_t fourcc,
1680                                                      uint64_t modifier,
1681                                                      int attrib,
1682                                                      uint64_t *value);
1683 
1684    /**
1685     * Create a DRI image from the given renderbuffer.
1686     *
1687     * \param context       the current DRI context
1688     * \param renderbuffer  the GL name of the renderbuffer
1689     * \param loaderPrivate for callbacks into the loader related to the image
1690     * \param error         will be set to one of __DRI_IMAGE_ERROR_xxx
1691     * \return the newly created image on success, or NULL otherwise
1692     *
1693     * \since 17
1694     */
1695     __DRIimage *(*createImageFromRenderbuffer2)(__DRIcontext *context,
1696                                                 int renderbuffer,
1697                                                 void *loaderPrivate,
1698                                                 unsigned *error);
1699 
1700    /*
1701     * Like createImageFromDmaBufs2, but with an added flags parameter.
1702     *
1703     * See __DRI_IMAGE_*_FLAG for valid definitions of flags.
1704     *
1705     * \since 18
1706     */
1707    __DRIimage *(*createImageFromDmaBufs3)(__DRIscreen *screen,
1708                                           int width, int height, int fourcc,
1709                                           uint64_t modifier,
1710                                           int *fds, int num_fds,
1711                                           int *strides, int *offsets,
1712                                           enum __DRIYUVColorSpace color_space,
1713                                           enum __DRISampleRange sample_range,
1714                                           enum __DRIChromaSiting horiz_siting,
1715                                           enum __DRIChromaSiting vert_siting,
1716                                           uint32_t flags,
1717                                           unsigned *error,
1718                                           void *loaderPrivate);
1719 
1720    /**
1721     * Creates an image with implementation's favorite modifiers and the
1722     * provided usage flags.
1723     *
1724     * This acts like createImageWithModifiers except usage is also specified.
1725     *
1726     * The created image should be destroyed with destroyImage().
1727     *
1728     * Returns the new DRIimage. The chosen modifier can be obtained later on
1729     * and passed back to things like the kernel's AddFB2 interface.
1730     *
1731     * \sa __DRIimageRec::createImage
1732     *
1733     * \since 19
1734     */
1735    __DRIimage *(*createImageWithModifiers2)(__DRIscreen *screen,
1736                                             int width, int height, int format,
1737                                             const uint64_t *modifiers,
1738                                             const unsigned int modifier_count,
1739                                             unsigned int use,
1740                                             void *loaderPrivate);
1741 };
1742 
1743 
1744 /**
1745  * This extension must be implemented by the loader and passed to the
1746  * driver at screen creation time.  The EGLImage entry points in the
1747  * various client APIs take opaque EGLImage handles and use this
1748  * extension to map them to a __DRIimage.  At version 1, this
1749  * extensions allows mapping EGLImage pointers to __DRIimage pointers,
1750  * but future versions could support other EGLImage-like, opaque types
1751  * with new lookup functions.
1752  */
1753 #define __DRI_IMAGE_LOOKUP "DRI_IMAGE_LOOKUP"
1754 #define __DRI_IMAGE_LOOKUP_VERSION 2
1755 
1756 typedef struct __DRIimageLookupExtensionRec __DRIimageLookupExtension;
1757 struct __DRIimageLookupExtensionRec {
1758     __DRIextension base;
1759 
1760     /**
1761      * Lookup EGLImage without validated. Equivalent to call
1762      * validateEGLImage() then lookupEGLImageValidated().
1763      *
1764      * \since 1
1765      */
1766     __DRIimage *(*lookupEGLImage)(__DRIscreen *screen, void *image,
1767 				  void *loaderPrivate);
1768 
1769     /**
1770      * Check if EGLImage is associated with the EGL display before lookup with
1771      * lookupEGLImageValidated(). It will hold EGLDisplay.Mutex, so is separated
1772      * out from lookupEGLImage() to avoid deadlock.
1773      *
1774      * \since 2
1775      */
1776     unsigned char (*validateEGLImage)(void *image, void *loaderPrivate);
1777 
1778     /**
1779      * Lookup EGLImage after validateEGLImage(). No lock in this function.
1780      *
1781      * \since 2
1782      */
1783     __DRIimage *(*lookupEGLImageValidated)(void *image, void *loaderPrivate);
1784 };
1785 
1786 /**
1787  * This extension allows for common DRI2 options
1788  */
1789 #define __DRI2_CONFIG_QUERY "DRI_CONFIG_QUERY"
1790 #define __DRI2_CONFIG_QUERY_VERSION 2
1791 
1792 typedef struct __DRI2configQueryExtensionRec __DRI2configQueryExtension;
1793 struct __DRI2configQueryExtensionRec {
1794    __DRIextension base;
1795 
1796    int (*configQueryb)(__DRIscreen *screen, const char *var, unsigned char *val);
1797    int (*configQueryi)(__DRIscreen *screen, const char *var, int *val);
1798    int (*configQueryf)(__DRIscreen *screen, const char *var, float *val);
1799    int (*configQuerys)(__DRIscreen *screen, const char *var, char **val);
1800 };
1801 
1802 /**
1803  * Robust context driver extension.
1804  *
1805  * Existence of this extension means the driver can accept the
1806  * \c __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS flag and the
1807  * \c __DRI_CTX_ATTRIB_RESET_STRATEGY attribute in
1808  * \c __DRIdri2ExtensionRec::createContextAttribs.
1809  */
1810 #define __DRI2_ROBUSTNESS "DRI_Robustness"
1811 #define __DRI2_ROBUSTNESS_VERSION 1
1812 
1813 typedef struct __DRIrobustnessExtensionRec __DRIrobustnessExtension;
1814 struct __DRIrobustnessExtensionRec {
1815    __DRIextension base;
1816 };
1817 
1818 /**
1819  * No-error context driver extension.
1820  *
1821  * Existence of this extension means the driver can accept the
1822  * __DRI_CTX_FLAG_NO_ERROR flag.
1823  */
1824 #define __DRI2_NO_ERROR "DRI_NoError"
1825 #define __DRI2_NO_ERROR_VERSION 1
1826 
1827 typedef struct __DRInoErrorExtensionRec {
1828    __DRIextension base;
1829 } __DRInoErrorExtension;
1830 
1831 /*
1832  * Flush control driver extension.
1833  *
1834  * Existence of this extension means the driver can accept the
1835  * \c __DRI_CTX_ATTRIB_RELEASE_BEHAVIOR attribute in
1836  * \c __DRIdri2ExtensionRec::createContextAttribs.
1837  */
1838 #define __DRI2_FLUSH_CONTROL "DRI_FlushControl"
1839 #define __DRI2_FLUSH_CONTROL_VERSION 1
1840 
1841 typedef struct __DRI2flushControlExtensionRec __DRI2flushControlExtension;
1842 struct __DRI2flushControlExtensionRec {
1843    __DRIextension base;
1844 };
1845 
1846 /**
1847  * DRI config options extension.
1848  *
1849  * This extension provides the XML string containing driver options for use by
1850  * the loader in supporting the driconf application.
1851  *
1852  * v2:
1853  * - Add the getXml getter function which allows the driver more flexibility in
1854  *   how the XML is provided.
1855  * - Deprecate the direct xml pointer. It is only provided as a fallback for
1856  *   older versions of libGL and must not be used by clients that are aware of
1857  *   the newer version. Future driver versions may set it to NULL.
1858  */
1859 #define __DRI_CONFIG_OPTIONS "DRI_ConfigOptions"
1860 #define __DRI_CONFIG_OPTIONS_VERSION 2
1861 
1862 typedef struct __DRIconfigOptionsExtensionRec {
1863    __DRIextension base;
1864    const char *xml; /**< deprecated since v2, use getXml instead */
1865 
1866    /**
1867     * Get an XML string that describes available driver options for use by a
1868     * config application.
1869     *
1870     * The returned string must be heap-allocated. The caller is responsible for
1871     * freeing it.
1872     */
1873    char *(*getXml)(const char *driver_name);
1874 } __DRIconfigOptionsExtension;
1875 
1876 /**
1877  * This extension provides a driver vtable to a set of common driver helper
1878  * functions (driCoreExtension, driDRI2Extension) within the driver
1879  * implementation, as opposed to having to pass them through a global
1880  * variable.
1881  *
1882  * It is not intended to be public API to the actual loader, and the vtable
1883  * layout may change at any time.
1884  */
1885 #define __DRI_DRIVER_VTABLE "DRI_DriverVtable"
1886 #define __DRI_DRIVER_VTABLE_VERSION 1
1887 
1888 typedef struct __DRIDriverVtableExtensionRec {
1889     __DRIextension base;
1890     const struct __DriverAPIRec *vtable;
1891 } __DRIDriverVtableExtension;
1892 
1893 /**
1894  * Query renderer driver extension
1895  *
1896  * This allows the window system layer (either EGL or GLX) to query aspects of
1897  * hardware and driver support without creating a context.
1898  */
1899 #define __DRI2_RENDERER_QUERY "DRI_RENDERER_QUERY"
1900 #define __DRI2_RENDERER_QUERY_VERSION 1
1901 
1902 #define __DRI2_RENDERER_VENDOR_ID                             0x0000
1903 #define __DRI2_RENDERER_DEVICE_ID                             0x0001
1904 #define __DRI2_RENDERER_VERSION                               0x0002
1905 #define __DRI2_RENDERER_ACCELERATED                           0x0003
1906 #define __DRI2_RENDERER_VIDEO_MEMORY                          0x0004
1907 #define __DRI2_RENDERER_UNIFIED_MEMORY_ARCHITECTURE           0x0005
1908 #define __DRI2_RENDERER_PREFERRED_PROFILE                     0x0006
1909 #define __DRI2_RENDERER_OPENGL_CORE_PROFILE_VERSION           0x0007
1910 #define __DRI2_RENDERER_OPENGL_COMPATIBILITY_PROFILE_VERSION  0x0008
1911 #define __DRI2_RENDERER_OPENGL_ES_PROFILE_VERSION             0x0009
1912 #define __DRI2_RENDERER_OPENGL_ES2_PROFILE_VERSION            0x000a
1913 #define __DRI2_RENDERER_HAS_TEXTURE_3D                        0x000b
1914 /* Whether there is an sRGB format support for every supported 32-bit UNORM
1915  * color format.
1916  */
1917 #define __DRI2_RENDERER_HAS_FRAMEBUFFER_SRGB                  0x000c
1918 
1919 /* Bitmaks of supported/available context priorities - must match
1920  * __EGL_CONTEXT_PRIORITY_LOW_BIT et al
1921  */
1922 #define __DRI2_RENDERER_HAS_CONTEXT_PRIORITY                  0x000d
1923 #define   __DRI2_RENDERER_HAS_CONTEXT_PRIORITY_LOW            (1 << 0)
1924 #define   __DRI2_RENDERER_HAS_CONTEXT_PRIORITY_MEDIUM         (1 << 1)
1925 #define   __DRI2_RENDERER_HAS_CONTEXT_PRIORITY_HIGH           (1 << 2)
1926 
1927 #define __DRI2_RENDERER_HAS_PROTECTED_CONTENT                 0x000e
1928 #define __DRI2_RENDERER_PREFER_BACK_BUFFER_REUSE              0x000f
1929 
1930 typedef struct __DRI2rendererQueryExtensionRec __DRI2rendererQueryExtension;
1931 struct __DRI2rendererQueryExtensionRec {
1932    __DRIextension base;
1933 
1934    int (*queryInteger)(__DRIscreen *screen, int attribute, unsigned int *val);
1935    int (*queryString)(__DRIscreen *screen, int attribute, const char **val);
1936 };
1937 
1938 /**
1939  * Image Loader extension. Drivers use this to allocate color buffers
1940  */
1941 
1942 /**
1943  * See __DRIimageLoaderExtensionRec::getBuffers::buffer_mask.
1944  */
1945 enum __DRIimageBufferMask {
1946    __DRI_IMAGE_BUFFER_BACK = (1 << 0),
1947    __DRI_IMAGE_BUFFER_FRONT = (1 << 1),
1948 
1949    /**
1950     * A buffer shared between application and compositor. The buffer may be
1951     * simultaneously accessed by each.
1952     *
1953     * A shared buffer is equivalent to an EGLSurface whose EGLConfig contains
1954     * EGL_MUTABLE_RENDER_BUFFER_BIT_KHR and whose active EGL_RENDER_BUFFER (as
1955     * opposed to any pending, requested change to EGL_RENDER_BUFFER) is
1956     * EGL_SINGLE_BUFFER.
1957     *
1958     * If buffer_mask contains __DRI_IMAGE_BUFFER_SHARED, then must contains no
1959     * other bits. As a corollary, a __DRIdrawable that has a "shared" buffer
1960     * has no front nor back buffer.
1961     *
1962     * The loader returns __DRI_IMAGE_BUFFER_SHARED in buffer_mask if and only
1963     * if:
1964     *     - The loader supports __DRI_MUTABLE_RENDER_BUFFER_LOADER.
1965     *     - The driver supports __DRI_MUTABLE_RENDER_BUFFER_DRIVER.
1966     *     - The EGLConfig of the drawable EGLSurface contains
1967     *       EGL_MUTABLE_RENDER_BUFFER_BIT_KHR.
1968     *     - The EGLContext's EGL_RENDER_BUFFER is EGL_SINGLE_BUFFER.
1969     *       Equivalently, the EGLSurface's active EGL_RENDER_BUFFER (as
1970     *       opposed to any pending, requested change to EGL_RENDER_BUFFER) is
1971     *       EGL_SINGLE_BUFFER. (See the EGL 1.5 and
1972     *       EGL_KHR_mutable_render_buffer spec for details about "pending" vs
1973     *       "active" EGL_RENDER_BUFFER state).
1974     *
1975     * A shared buffer is similar to a front buffer in that all rendering to the
1976     * buffer should appear promptly on the screen. It is different from
1977     * a front buffer in that its behavior is independent from the
1978     * GL_DRAW_BUFFER state. Specifically, if GL_DRAW_FRAMEBUFFER is 0 and the
1979     * __DRIdrawable's buffer_mask is __DRI_IMAGE_BUFFER_SHARED, then all
1980     * rendering should appear promptly on the screen if GL_DRAW_BUFFER is not
1981     * GL_NONE.
1982     *
1983     * The difference between a shared buffer and a front buffer is motivated
1984     * by the constraints of Android and OpenGL ES. OpenGL ES does not support
1985     * front-buffer rendering. Android's SurfaceFlinger protocol provides the
1986     * EGL driver only a back buffer and no front buffer. The shared buffer
1987     * mode introduced by EGL_KHR_mutable_render_buffer is a backdoor though
1988     * EGL that allows Android OpenGL ES applications to render to what is
1989     * effectively the front buffer, a backdoor that required no change to the
1990     * OpenGL ES API and little change to the SurfaceFlinger API.
1991     */
1992    __DRI_IMAGE_BUFFER_SHARED = (1 << 2),
1993 };
1994 
1995 struct __DRIimageList {
1996    uint32_t image_mask;
1997    __DRIimage *back;
1998    __DRIimage *front;
1999 };
2000 
2001 #define __DRI_IMAGE_LOADER "DRI_IMAGE_LOADER"
2002 #define __DRI_IMAGE_LOADER_VERSION 4
2003 
2004 struct __DRIimageLoaderExtensionRec {
2005     __DRIextension base;
2006 
2007    /**
2008     * Allocate color buffers.
2009     *
2010     * \param driDrawable
2011     * \param width              Width of allocated buffers
2012     * \param height             Height of allocated buffers
2013     * \param format             one of __DRI_IMAGE_FORMAT_*
2014     * \param stamp              Address of variable to be updated when
2015     *                           getBuffers must be called again
2016     * \param loaderPrivate      The loaderPrivate for driDrawable
2017     * \param buffer_mask        Set of buffers to allocate. A bitmask of
2018     *                           __DRIimageBufferMask.
2019     * \param buffers            Returned buffers
2020     */
2021    int (*getBuffers)(__DRIdrawable *driDrawable,
2022                      unsigned int format,
2023                      uint32_t *stamp,
2024                      void *loaderPrivate,
2025                      uint32_t buffer_mask,
2026                      struct __DRIimageList *buffers);
2027 
2028     /**
2029      * Flush pending front-buffer rendering
2030      *
2031      * Any rendering that has been performed to the
2032      * fake front will be flushed to the front
2033      *
2034      * \param driDrawable    Drawable whose front-buffer is to be flushed
2035      * \param loaderPrivate  Loader's private data that was previously passed
2036      *                       into __DRIdri2ExtensionRec::createNewDrawable
2037      */
2038     void (*flushFrontBuffer)(__DRIdrawable *driDrawable, void *loaderPrivate);
2039 
2040     /**
2041      * Return a loader capability value. If the loader doesn't know the enum,
2042      * it will return 0.
2043      *
2044      * \since 2
2045      */
2046     unsigned (*getCapability)(void *loaderPrivate, enum dri_loader_cap cap);
2047 
2048     /**
2049      * Flush swap buffers
2050      *
2051      * Make sure any outstanding swap buffers have been submitted to the
2052      * device.
2053      *
2054      * \param driDrawable    Drawable whose swaps need to be flushed
2055      * \param loaderPrivate  Loader's private data that was previously passed
2056      *                       into __DRIdri2ExtensionRec::createNewDrawable
2057      *
2058      * \since 3
2059      */
2060     void (*flushSwapBuffers)(__DRIdrawable *driDrawable, void *loaderPrivate);
2061 
2062     /**
2063      * Clean up any loader state associated with an image.
2064      *
2065      * \param loaderPrivate  Loader's private data that was previously passed
2066      *                       into a __DRIimageExtensionRec::createImage function
2067      * \since 4
2068      */
2069     void (*destroyLoaderImageState)(void *loaderPrivate);
2070 };
2071 
2072 /**
2073  * DRI extension.
2074  */
2075 
2076 #define __DRI_IMAGE_DRIVER           "DRI_IMAGE_DRIVER"
2077 #define __DRI_IMAGE_DRIVER_VERSION   1
2078 
2079 struct __DRIimageDriverExtensionRec {
2080    __DRIextension               base;
2081 
2082    /* Common DRI functions, shared with DRI2 */
2083    __DRIcreateNewScreen2Func            createNewScreen2;
2084    __DRIcreateNewDrawableFunc           createNewDrawable;
2085    __DRIcreateContextAttribsFunc        createContextAttribs;
2086    __DRIgetAPIMaskFunc                  getAPIMask;
2087 };
2088 
2089 /**
2090  * Background callable loader extension.
2091  *
2092  * Loaders expose this extension to indicate to drivers that they are capable
2093  * of handling callbacks from the driver's background drawing threads.
2094  */
2095 #define __DRI_BACKGROUND_CALLABLE "DRI_BackgroundCallable"
2096 #define __DRI_BACKGROUND_CALLABLE_VERSION 1
2097 
2098 typedef struct __DRIbackgroundCallableExtensionRec __DRIbackgroundCallableExtension;
2099 struct __DRIbackgroundCallableExtensionRec {
2100    __DRIextension base;
2101 
2102    /**
2103     * Indicate that this thread is being used by the driver as a background
2104     * drawing thread which may make callbacks to the loader.
2105     *
2106     * \param loaderPrivate is the value that was passed to to the driver when
2107     * the context was created.  This can be used by the loader to identify
2108     * which context any callbacks are associated with.
2109     *
2110     * If this function is called more than once from any given thread, each
2111     * subsequent call overrides the loaderPrivate data that was passed in the
2112     * previous call.  The driver can take advantage of this to re-use a
2113     * background thread to perform drawing on behalf of multiple contexts.
2114     *
2115     * It is permissible for the driver to call this function from a
2116     * non-background thread (i.e. a thread that has already been bound to a
2117     * context using __DRIcoreExtensionRec::bindContext()); when this happens,
2118     * the \c loaderPrivate pointer must be equal to the pointer that was
2119     * passed to the driver when the currently bound context was created.
2120     *
2121     * This call should execute quickly enough that the driver can call it with
2122     * impunity whenever a background thread starts performing drawing
2123     * operations (e.g. it should just set a thread-local variable).
2124     */
2125    void (*setBackgroundContext)(void *loaderPrivate);
2126 
2127    /**
2128     * Indicate that it is multithread safe to use glthread.  For GLX/EGL
2129     * platforms using Xlib, that involves calling XInitThreads, before
2130     * opening an X display.
2131     *
2132     * Note: only supported if extension version is at least 2.
2133     *
2134     * \param loaderPrivate is the value that was passed to to the driver when
2135     * the context was created.  This can be used by the loader to identify
2136     * which context any callbacks are associated with.
2137     */
2138    unsigned char (*isThreadSafe)(void *loaderPrivate);
2139 };
2140 
2141 /**
2142  * The driver portion of EGL_KHR_mutable_render_buffer.
2143  *
2144  * If the driver creates a __DRIconfig with
2145  * __DRI_ATTRIB_MUTABLE_RENDER_BUFFER, then it must support this extension.
2146  *
2147  * To support this extension:
2148  *
2149  *    - The driver should create at least one __DRIconfig with
2150  *      __DRI_ATTRIB_MUTABLE_RENDER_BUFFER. This is strongly recommended but
2151  *      not required.
2152  *
2153  *    - The driver must be able to handle __DRI_IMAGE_BUFFER_SHARED if
2154  *      returned by __DRIimageLoaderExtension:getBuffers().
2155  *
2156  *    - When rendering to __DRI_IMAGE_BUFFER_SHARED, it must call
2157  *      __DRImutableRenderBufferLoaderExtension::displaySharedBuffer() in
2158  *      response to glFlush and glFinish.  (This requirement is not documented
2159  *      in EGL_KHR_mutable_render_buffer, but is a de-facto requirement in the
2160  *      Android ecosystem. Android applications expect that glFlush will
2161  *      immediately display the buffer when in shared buffer mode, and Android
2162  *      drivers comply with this expectation).  It :may: call
2163  *      displaySharedBuffer() more often than required.
2164  *
2165  *    - When rendering to __DRI_IMAGE_BUFFER_SHARED, it must ensure that the
2166  *      buffer is always in a format compatible for display because the
2167  *      display engine (usually SurfaceFlinger or hwcomposer) may display the
2168  *      image at any time, even concurrently with 3D rendering. For example,
2169  *      display hardware and the GL hardware may be able to access the buffer
2170  *      simultaneously. In particular, if the buffer is compressed then take
2171  *      care that SurfaceFlinger and hwcomposer can consume the compression
2172  *      format.
2173  *
2174  * \see __DRI_IMAGE_BUFFER_SHARED
2175  * \see __DRI_ATTRIB_MUTABLE_RENDER_BUFFER
2176  * \see __DRI_MUTABLE_RENDER_BUFFER_LOADER
2177  */
2178 #define __DRI_MUTABLE_RENDER_BUFFER_DRIVER "DRI_MutableRenderBufferDriver"
2179 #define __DRI_MUTABLE_RENDER_BUFFER_DRIVER_VERSION 1
2180 
2181 typedef struct __DRImutableRenderBufferDriverExtensionRec __DRImutableRenderBufferDriverExtension;
2182 struct __DRImutableRenderBufferDriverExtensionRec {
2183    __DRIextension base;
2184 };
2185 
2186 /**
2187  * The loader portion of EGL_KHR_mutable_render_buffer.
2188  *
2189  * Requires loader extension DRI_IMAGE_LOADER, through which the loader sends
2190  * __DRI_IMAGE_BUFFER_SHARED to the driver.
2191  *
2192  * \see __DRI_MUTABLE_RENDER_BUFFER_DRIVER
2193  */
2194 #define __DRI_MUTABLE_RENDER_BUFFER_LOADER "DRI_MutableRenderBufferLoader"
2195 #define __DRI_MUTABLE_RENDER_BUFFER_LOADER_VERSION 1
2196 
2197 typedef struct __DRImutableRenderBufferLoaderExtensionRec __DRImutableRenderBufferLoaderExtension;
2198 struct __DRImutableRenderBufferLoaderExtensionRec {
2199    __DRIextension base;
2200 
2201    /**
2202     * Inform the display engine (that is, SurfaceFlinger and/or hwcomposer)
2203     * that the __DRIdrawable has new content.
2204     *
2205     * The display engine may ignore this call, for example, if it continually
2206     * refreshes and displays the buffer on every frame, as in
2207     * EGL_ANDROID_front_buffer_auto_refresh. On the other extreme, the display
2208     * engine may refresh and display the buffer only in frames in which the
2209     * driver calls this.
2210     *
2211     * If the fence_fd is not -1, then the display engine will display the
2212     * buffer only after the fence signals.
2213     *
2214     * The drawable's current __DRIimageBufferMask, as returned by
2215     * __DRIimageLoaderExtension::getBuffers(), must be
2216     * __DRI_IMAGE_BUFFER_SHARED.
2217     */
2218    void (*displaySharedBuffer)(__DRIdrawable *drawable, int fence_fd,
2219                                void *loaderPrivate);
2220 };
2221 
2222 #endif
2223