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