• 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 #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 struct mesa_glinterop_flush_out;
445 typedef struct __GLsync *GLsync;
446 
447 struct __DRI2interopExtensionRec {
448    __DRIextension base;
449 
450    /** Same as MesaGLInterop*QueryDeviceInfo. */
451    int (*query_device_info)(__DRIcontext *ctx,
452                             struct mesa_glinterop_device_info *out);
453 
454    /** Same as MesaGLInterop*ExportObject. */
455    int (*export_object)(__DRIcontext *ctx,
456                         struct mesa_glinterop_export_in *in,
457                         struct mesa_glinterop_export_out *out);
458 
459    /**
460     * Same as MesaGLInterop*FlushObjects.
461     *
462     * \since 2
463     */
464    int (*flush_objects)(__DRIcontext *ctx,
465                         unsigned count, struct mesa_glinterop_export_in *objects,
466                         struct mesa_glinterop_flush_out *out);
467 };
468 
469 
470 /**
471  * Extension for limiting window system back buffer rendering to user-defined
472  * scissor region.
473  *
474  * Not used by the X server.
475  */
476 
477 #define __DRI2_BUFFER_DAMAGE "DRI2_BufferDamage"
478 #define __DRI2_BUFFER_DAMAGE_VERSION 1
479 
480 struct __DRI2bufferDamageExtensionRec {
481    __DRIextension base;
482 
483    /**
484     * Provides an array of rectangles representing an overriding scissor region
485     * for rendering operations performed to the specified drawable. These
486     * rectangles do not replace client API scissor regions or draw
487     * co-ordinates, but instead inform the driver of the overall bounds of all
488     * operations which will be issued before the next flush.
489     *
490     * Any rendering operations writing pixels outside this region to the
491     * drawable will have an undefined effect on the entire drawable.
492     *
493     * This entrypoint may only be called after the drawable has either been
494     * newly created or flushed, and before any rendering operations which write
495     * pixels to the drawable. Calling this entrypoint at any other time will
496     * have an undefined effect on the entire drawable.
497     *
498     * Calling this entrypoint with @nrects 0 and @rects NULL will reset the
499     * region to the buffer's full size. This entrypoint may be called once to
500     * reset the region, followed by a second call with a populated region,
501     * before a rendering call is made.
502     *
503     * Used to implement EGL_KHR_partial_update.
504     *
505     * \param drawable affected drawable
506     * \param nrects   number of rectangles provided
507     * \param rects    the array of rectangles, lower-left origin
508     */
509    void (*set_damage_region)(__DRIdrawable *drawable, unsigned int nrects,
510                              int *rects);
511 };
512 
513 /*@}*/
514 
515 /**
516  * The following extensions describe loader features that the DRI
517  * driver can make use of.  Some of these are mandatory, such as the
518  * getDrawableInfo extension for DRI and the DRI Loader extensions for
519  * DRI2, while others are optional, and if present allow the driver to
520  * expose certain features.  The loader pass in a NULL terminated
521  * array of these extensions to the driver in the createNewScreen
522  * constructor.
523  */
524 
525 typedef struct __DRIgetDrawableInfoExtensionRec __DRIgetDrawableInfoExtension;
526 typedef struct __DRIsystemTimeExtensionRec __DRIsystemTimeExtension;
527 typedef struct __DRIdamageExtensionRec __DRIdamageExtension;
528 typedef struct __DRIloaderExtensionRec __DRIloaderExtension;
529 typedef struct __DRIswrastLoaderExtensionRec __DRIswrastLoaderExtension;
530 
531 /**
532  * Callback to get system time for media stream counter extensions.
533  *
534  * Not used by the X server.
535  */
536 #define __DRI_SYSTEM_TIME "DRI_SystemTime"
537 #define __DRI_SYSTEM_TIME_VERSION 1
538 struct __DRIsystemTimeExtensionRec {
539     __DRIextension base;
540 
541     /**
542      * Get the 64-bit unadjusted system time (UST).
543      */
544     int (*getUST)(int64_t * ust);
545 
546     /**
547      * Get the media stream counter (MSC) rate.
548      *
549      * Matching the definition in GLX_OML_sync_control, this function returns
550      * the rate of the "media stream counter".  In practical terms, this is
551      * the frame refresh rate of the display.
552      */
553     unsigned char (*getMSCRate)(__DRIdrawable *draw,
554 			    int32_t * numerator, int32_t * denominator,
555 			    void *loaderPrivate);
556 };
557 
558 #define __DRI_SWRAST_IMAGE_OP_DRAW	1
559 #define __DRI_SWRAST_IMAGE_OP_CLEAR	2
560 #define __DRI_SWRAST_IMAGE_OP_SWAP	3
561 
562 /**
563  * SWRast Loader extension.
564  *
565  * Version 1 is advertised by the X server.
566  */
567 #define __DRI_SWRAST_LOADER "DRI_SWRastLoader"
568 #define __DRI_SWRAST_LOADER_VERSION 6
569 struct __DRIswrastLoaderExtensionRec {
570     __DRIextension base;
571 
572     /*
573      * Drawable position and size
574      */
575     void (*getDrawableInfo)(__DRIdrawable *drawable,
576 			    int *x, int *y, int *width, int *height,
577 			    void *loaderPrivate);
578 
579     /**
580      * Put image to drawable
581      */
582     void (*putImage)(__DRIdrawable *drawable, int op,
583 		     int x, int y, int width, int height,
584 		     char *data, void *loaderPrivate);
585 
586     /**
587      * Get image from readable
588      */
589     void (*getImage)(__DRIdrawable *readable,
590 		     int x, int y, int width, int height,
591 		     char *data, void *loaderPrivate);
592 
593     /**
594      * Put image to drawable
595      *
596      * \since 2
597      */
598     void (*putImage2)(__DRIdrawable *drawable, int op,
599                       int x, int y, int width, int height, int stride,
600                       char *data, void *loaderPrivate);
601 
602    /**
603      * Put image to drawable
604      *
605      * \since 3
606      */
607    void (*getImage2)(__DRIdrawable *readable,
608 		     int x, int y, int width, int height, int stride,
609 		     char *data, void *loaderPrivate);
610 
611     /**
612      * Put shm image to drawable
613      *
614      * \since 4
615      */
616     void (*putImageShm)(__DRIdrawable *drawable, int op,
617                         int x, int y, int width, int height, int stride,
618                         int shmid, char *shmaddr, unsigned offset,
619                         void *loaderPrivate);
620     /**
621      * Get shm image from readable
622      *
623      * \since 4
624      */
625     void (*getImageShm)(__DRIdrawable *readable,
626                         int x, int y, int width, int height,
627                         int shmid, void *loaderPrivate);
628 
629    /**
630      * Put shm image to drawable (v2)
631      *
632      * The original version fixes srcx/y to 0, and expected
633      * the offset to be adjusted. This version allows src x,y
634      * to not be included in the offset. This is needed to
635      * avoid certain overflow checks in the X server, that
636      * result in lost rendering.
637      *
638      * \since 5
639      */
640     void (*putImageShm2)(__DRIdrawable *drawable, int op,
641                          int x, int y,
642                          int width, int height, int stride,
643                          int shmid, char *shmaddr, unsigned offset,
644                          void *loaderPrivate);
645 
646     /**
647      * get shm image to drawable (v2)
648      *
649      * There are some cases where GLX can't use SHM, but DRI
650      * still tries, we need to get a return type for when to
651      * fallback to the non-shm path.
652      *
653      * \since 6
654      */
655     unsigned char (*getImageShm2)(__DRIdrawable *readable,
656                                   int x, int y, int width, int height,
657                                   int shmid, void *loaderPrivate);
658 };
659 
660 /**
661  * Invalidate loader extension.  The presence of this extension
662  * indicates to the DRI driver that the loader will call invalidate in
663  * the __DRI2_FLUSH extension, whenever the needs to query for new
664  * buffers.  This means that the DRI driver can drop the polling in
665  * glViewport().
666  *
667  * The extension doesn't provide any functionality, it's only use to
668  * indicate to the driver that it can use the new semantics.  A DRI
669  * driver can use this to switch between the different semantics or
670  * just refuse to initialize if this extension isn't present.
671  *
672  * Advertised by the X server.
673  */
674 #define __DRI_USE_INVALIDATE "DRI_UseInvalidate"
675 #define __DRI_USE_INVALIDATE_VERSION 1
676 
677 typedef struct __DRIuseInvalidateExtensionRec __DRIuseInvalidateExtension;
678 struct __DRIuseInvalidateExtensionRec {
679    __DRIextension base;
680 };
681 
682 /**
683  * Dead, do not use; kept only to allow old Xserver to compile since
684  * this file is a public API.
685  */
686 #define __DRI_DRIVER_EXTENSIONS "__driDriverExtensions"
687 
688 /**
689  * This symbol replaces the __DRI_DRIVER_EXTENSIONS symbol, and will be
690  * suffixed by "_drivername", allowing multiple drivers to be built into one
691  * library, and also giving the driver the chance to return a variable driver
692  * extensions struct depending on the driver name being loaded or any other
693  * system state.
694  *
695  * The function prototype is:
696  *
697  * const __DRIextension **__driDriverGetExtensions_drivername(void);
698  */
699 #define __DRI_DRIVER_GET_EXTENSIONS "__driDriverGetExtensions"
700 
701 /**
702  * Tokens for __DRIconfig attribs.  A number of attributes defined by
703  * GLX or EGL standards are not in the table, as they must be provided
704  * by the loader.  For example, FBConfig ID or visual ID, drawable type.
705  */
706 
707 #define __DRI_ATTRIB_BUFFER_SIZE		 1
708 #define __DRI_ATTRIB_LEVEL			 2
709 #define __DRI_ATTRIB_RED_SIZE			 3
710 #define __DRI_ATTRIB_GREEN_SIZE			 4
711 #define __DRI_ATTRIB_BLUE_SIZE			 5
712 #define __DRI_ATTRIB_LUMINANCE_SIZE		 6
713 #define __DRI_ATTRIB_ALPHA_SIZE			 7
714 #define __DRI_ATTRIB_ALPHA_MASK_SIZE		 8
715 #define __DRI_ATTRIB_DEPTH_SIZE			 9
716 #define __DRI_ATTRIB_STENCIL_SIZE		10
717 #define __DRI_ATTRIB_ACCUM_RED_SIZE		11
718 #define __DRI_ATTRIB_ACCUM_GREEN_SIZE		12
719 #define __DRI_ATTRIB_ACCUM_BLUE_SIZE		13
720 #define __DRI_ATTRIB_ACCUM_ALPHA_SIZE		14
721 #define __DRI_ATTRIB_SAMPLE_BUFFERS		15
722 #define __DRI_ATTRIB_SAMPLES			16
723 #define __DRI_ATTRIB_RENDER_TYPE		17
724 #define __DRI_ATTRIB_CONFIG_CAVEAT		18
725 #define __DRI_ATTRIB_CONFORMANT			19
726 #define __DRI_ATTRIB_DOUBLE_BUFFER		20
727 #define __DRI_ATTRIB_STEREO			21
728 #define __DRI_ATTRIB_AUX_BUFFERS		22
729 #define __DRI_ATTRIB_TRANSPARENT_TYPE		23
730 #define __DRI_ATTRIB_TRANSPARENT_INDEX_VALUE	24
731 #define __DRI_ATTRIB_TRANSPARENT_RED_VALUE	25
732 #define __DRI_ATTRIB_TRANSPARENT_GREEN_VALUE	26
733 #define __DRI_ATTRIB_TRANSPARENT_BLUE_VALUE	27
734 #define __DRI_ATTRIB_TRANSPARENT_ALPHA_VALUE	28
735 #define __DRI_ATTRIB_FLOAT_MODE			29
736 #define __DRI_ATTRIB_RED_MASK			30
737 #define __DRI_ATTRIB_GREEN_MASK			31
738 #define __DRI_ATTRIB_BLUE_MASK			32
739 #define __DRI_ATTRIB_ALPHA_MASK			33
740 #define __DRI_ATTRIB_MAX_PBUFFER_WIDTH		34
741 #define __DRI_ATTRIB_MAX_PBUFFER_HEIGHT		35
742 #define __DRI_ATTRIB_MAX_PBUFFER_PIXELS		36
743 #define __DRI_ATTRIB_OPTIMAL_PBUFFER_WIDTH	37
744 #define __DRI_ATTRIB_OPTIMAL_PBUFFER_HEIGHT	38
745 #define __DRI_ATTRIB_VISUAL_SELECT_GROUP	39
746 #define __DRI_ATTRIB_SWAP_METHOD		40 // Parsed by the X server when our visuals return it as an attrib.
747 #define __DRI_ATTRIB_MAX_SWAP_INTERVAL		41
748 #define __DRI_ATTRIB_MIN_SWAP_INTERVAL		42
749 #define __DRI_ATTRIB_BIND_TO_TEXTURE_RGB	43
750 #define __DRI_ATTRIB_BIND_TO_TEXTURE_RGBA	44
751 #define __DRI_ATTRIB_BIND_TO_MIPMAP_TEXTURE	45
752 #define __DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS	46
753 #define __DRI_ATTRIB_YINVERTED			47
754 #define __DRI_ATTRIB_FRAMEBUFFER_SRGB_CAPABLE	48
755 #define __DRI_ATTRIB_MUTABLE_RENDER_BUFFER	49 /* EGL_MUTABLE_RENDER_BUFFER_BIT_KHR */
756 #define __DRI_ATTRIB_RED_SHIFT			50
757 #define __DRI_ATTRIB_GREEN_SHIFT		51
758 #define __DRI_ATTRIB_BLUE_SHIFT			52
759 #define __DRI_ATTRIB_ALPHA_SHIFT		53
760 #define __DRI_ATTRIB_MAX			54
761 
762 /* __DRI_ATTRIB_RENDER_TYPE */
763 #define __DRI_ATTRIB_RGBA_BIT			0x01
764 #define __DRI_ATTRIB_COLOR_INDEX_BIT		0x02
765 #define __DRI_ATTRIB_LUMINANCE_BIT		0x04
766 #define __DRI_ATTRIB_FLOAT_BIT			0x08
767 #define __DRI_ATTRIB_UNSIGNED_FLOAT_BIT		0x10
768 
769 /* __DRI_ATTRIB_CONFIG_CAVEAT */
770 #define __DRI_ATTRIB_SLOW_BIT			0x01
771 #define __DRI_ATTRIB_NON_CONFORMANT_CONFIG	0x02
772 
773 /* __DRI_ATTRIB_TRANSPARENT_TYPE */
774 #define __DRI_ATTRIB_TRANSPARENT_RGB		0x00
775 #define __DRI_ATTRIB_TRANSPARENT_INDEX		0x01
776 
777 /* __DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS	 */
778 #define __DRI_ATTRIB_TEXTURE_1D_BIT		0x01
779 #define __DRI_ATTRIB_TEXTURE_2D_BIT		0x02
780 #define __DRI_ATTRIB_TEXTURE_RECTANGLE_BIT	0x04
781 
782 /* __DRI_ATTRIB_SWAP_METHOD */
783 /* Note that with the exception of __DRI_ATTRIB_SWAP_NONE, we need to define
784  * the same tokens as GLX. This is because old and current X servers will
785  * transmit the driconf value grabbed from the AIGLX driver untranslated as
786  * the GLX fbconfig value. These defines are kept for X Server suorce compatibility,
787  * since Mesa no longer exposes GLX_OML_swap_method.
788  */
789 #define __DRI_ATTRIB_SWAP_NONE                  0x0000
790 #define __DRI_ATTRIB_SWAP_EXCHANGE              0x8061
791 #define __DRI_ATTRIB_SWAP_COPY                  0x8062
792 #define __DRI_ATTRIB_SWAP_UNDEFINED             0x8063
793 
794 /**
795  * This extension defines the core DRI functionality.  It was introduced when
796  * DRI2 and AIGLX were added.
797  *
798  * Version >= 2 indicates that getConfigAttrib with __DRI_ATTRIB_SWAP_METHOD
799  * returns a reliable value.  The X server requires v1 and uses v2.
800  */
801 #define __DRI_CORE "DRI_Core"
802 #define __DRI_CORE_VERSION 2
803 
804 struct __DRIcoreExtensionRec {
805     __DRIextension base;
806 
807     /* Not used by the X server. */
808     __DRIscreen *(*createNewScreen)(int screen, int fd,
809 				    unsigned int sarea_handle,
810 				    const __DRIextension **extensions,
811 				    const __DRIconfig ***driverConfigs,
812 				    void *loaderPrivate);
813 
814     void (*destroyScreen)(__DRIscreen *screen);
815 
816     const __DRIextension **(*getExtensions)(__DRIscreen *screen);
817 
818     /* Not used by the X server. */
819     int (*getConfigAttrib)(const __DRIconfig *config,
820 			   unsigned int attrib,
821 			   unsigned int *value);
822 
823     /* Not used by the X server. */
824     int (*indexConfigAttrib)(const __DRIconfig *config, int index,
825 			     unsigned int *attrib, unsigned int *value);
826 
827     /* Not used by the X server. */
828     __DRIdrawable *(*createNewDrawable)(__DRIscreen *screen,
829 					const __DRIconfig *config,
830 					unsigned int drawable_id,
831 					unsigned int head,
832 					void *loaderPrivate);
833 
834     /* Used by the X server */
835     void (*destroyDrawable)(__DRIdrawable *drawable);
836 
837     /* Used by the X server in swrast mode. */
838     void (*swapBuffers)(__DRIdrawable *drawable);
839 
840     /* Used by the X server in swrast mode. */
841     __DRIcontext *(*createNewContext)(__DRIscreen *screen,
842 				      const __DRIconfig *config,
843 				      __DRIcontext *shared,
844 				      void *loaderPrivate);
845 
846     /* Used by the X server. */
847     int (*copyContext)(__DRIcontext *dest,
848 		       __DRIcontext *src,
849 		       unsigned long mask);
850 
851     /* Used by the X server. */
852     void (*destroyContext)(__DRIcontext *context);
853 
854     /* Used by the X server. */
855     int (*bindContext)(__DRIcontext *ctx,
856 		       __DRIdrawable *pdraw,
857 		       __DRIdrawable *pread);
858 
859     /* Used by the X server. */
860     int (*unbindContext)(__DRIcontext *ctx);
861 };
862 
863 /**
864  * Stored version of some component (i.e., server-side DRI module, kernel-side
865  * DRM, etc.).
866  *
867  * \todo
868  * There are several data structures that explicitly store a major version,
869  * minor version, and patch level.  These structures should be modified to
870  * have a \c __DRIversionRec instead.
871  *
872  * Not used by the X server since DRI1 was deleted.
873  */
874 struct __DRIversionRec {
875     int    major;        /**< Major version number. */
876     int    minor;        /**< Minor version number. */
877     int    patch;        /**< Patch-level. */
878 };
879 
880 /**
881  * Framebuffer information record.  Used by libGL to communicate information
882  * about the framebuffer to the driver's \c __driCreateNewScreen function.
883  *
884  * In XFree86, most of this information is derrived from data returned by
885  * calling \c XF86DRIGetDeviceInfo.
886  *
887  * \sa XF86DRIGetDeviceInfo __DRIdisplayRec::createNewScreen
888  *     __driUtilCreateNewScreen CallCreateNewScreen
889  *
890  * \bug This structure could be better named.
891  *
892  * Not used by the X server since DRI1 was deleted.
893  */
894 struct __DRIframebufferRec {
895     unsigned char *base;    /**< Framebuffer base address in the CPU's
896 			     * address space.  This value is calculated by
897 			     * calling \c drmMap on the framebuffer handle
898 			     * returned by \c XF86DRIGetDeviceInfo (or a
899 			     * similar function).
900 			     */
901     int size;               /**< Framebuffer size, in bytes. */
902     int stride;             /**< Number of bytes from one line to the next. */
903     int width;              /**< Pixel width of the framebuffer. */
904     int height;             /**< Pixel height of the framebuffer. */
905     int dev_priv_size;      /**< Size of the driver's dev-priv structure. */
906     void *dev_priv;         /**< Pointer to the driver's dev-priv structure. */
907 };
908 
909 
910 /**
911  * This extension provides alternative screen, drawable and context constructors
912  * for swrast DRI functionality.  This is used in conjunction with the core
913  * extension.  Version 1 is required by the X server, and version 3 is used.
914  */
915 #define __DRI_SWRAST "DRI_SWRast"
916 #define __DRI_SWRAST_VERSION 5
917 
918 struct __DRIswrastExtensionRec {
919     __DRIextension base;
920 
921     __DRIscreen *(*createNewScreen)(int screen,
922 				    const __DRIextension **extensions,
923 				    const __DRIconfig ***driver_configs,
924 				    void *loaderPrivate);
925 
926     __DRIdrawable *(*createNewDrawable)(__DRIscreen *screen,
927 					const __DRIconfig *config,
928 					void *loaderPrivate);
929 
930    /* Since version 2 */
931    __DRIcontext *(*createNewContextForAPI)(__DRIscreen *screen,
932                                            int api,
933                                            const __DRIconfig *config,
934                                            __DRIcontext *shared,
935                                            void *data);
936 
937    /**
938     * Create a context for a particular API with a set of attributes
939     *
940     * \since version 3
941     *
942     * \sa __DRIdri2ExtensionRec::createContextAttribs
943     */
944    __DRIcontext *(*createContextAttribs)(__DRIscreen *screen,
945 					 int api,
946 					 const __DRIconfig *config,
947 					 __DRIcontext *shared,
948 					 unsigned num_attribs,
949 					 const uint32_t *attribs,
950 					 unsigned *error,
951 					 void *loaderPrivate);
952 
953    /**
954     * createNewScreen() with the driver extensions passed in.
955     *
956     * \since version 4
957     */
958    __DRIscreen *(*createNewScreen2)(int screen,
959                                     const __DRIextension **loader_extensions,
960                                     const __DRIextension **driver_extensions,
961                                     const __DRIconfig ***driver_configs,
962                                     void *loaderPrivate);
963    /**
964     * \since version 5
965    */
966    int (*queryBufferAge)(__DRIdrawable *drawable);
967 
968 };
969 
970 /** Common DRI function definitions, shared among DRI2 and Image extensions
971  */
972 
973 typedef __DRIscreen *
974 (*__DRIcreateNewScreen2Func)(int screen, int fd,
975                              const __DRIextension **extensions,
976                              const __DRIextension **driver_extensions,
977                              const __DRIconfig ***driver_configs,
978                              void *loaderPrivate);
979 
980 typedef __DRIdrawable *
981 (*__DRIcreateNewDrawableFunc)(__DRIscreen *screen,
982                               const __DRIconfig *config,
983                               void *loaderPrivate);
984 
985 typedef __DRIcontext *
986 (*__DRIcreateContextAttribsFunc)(__DRIscreen *screen,
987                                  int api,
988                                  const __DRIconfig *config,
989                                  __DRIcontext *shared,
990                                  unsigned num_attribs,
991                                  const uint32_t *attribs,
992                                  unsigned *error,
993                                  void *loaderPrivate);
994 
995 typedef unsigned int
996 (*__DRIgetAPIMaskFunc)(__DRIscreen *screen);
997 
998 /**
999  * DRI2 Loader extension.
1000  */
1001 #define __DRI_BUFFER_FRONT_LEFT		0
1002 #define __DRI_BUFFER_BACK_LEFT		1
1003 #define __DRI_BUFFER_FRONT_RIGHT	2
1004 #define __DRI_BUFFER_BACK_RIGHT		3
1005 #define __DRI_BUFFER_DEPTH		4
1006 #define __DRI_BUFFER_STENCIL		5
1007 #define __DRI_BUFFER_ACCUM		6
1008 #define __DRI_BUFFER_FAKE_FRONT_LEFT	7
1009 #define __DRI_BUFFER_FAKE_FRONT_RIGHT	8
1010 #define __DRI_BUFFER_DEPTH_STENCIL	9  /**< Only available with DRI2 1.1 */
1011 #define __DRI_BUFFER_HIZ		10
1012 
1013 /* Inofficial and for internal use. Increase when adding a new buffer token. */
1014 #define __DRI_BUFFER_COUNT		11
1015 
1016 /* Used by the X server. */
1017 struct __DRIbufferRec {
1018     unsigned int attachment;
1019     unsigned int name;
1020     unsigned int pitch;
1021     unsigned int cpp;
1022     unsigned int flags;
1023 };
1024 
1025 /* The X server implements up to version 3 of the DRI2 loader. */
1026 #define __DRI_DRI2_LOADER "DRI_DRI2Loader"
1027 #define __DRI_DRI2_LOADER_VERSION 5
1028 
1029 enum dri_loader_cap {
1030    /* Whether the loader handles RGBA channel ordering correctly. If not,
1031     * only BGRA ordering can be exposed.
1032     */
1033    DRI_LOADER_CAP_RGBA_ORDERING,
1034    DRI_LOADER_CAP_FP16,
1035 };
1036 
1037 struct __DRIdri2LoaderExtensionRec {
1038     __DRIextension base;
1039 
1040     __DRIbuffer *(*getBuffers)(__DRIdrawable *driDrawable,
1041 			       int *width, int *height,
1042 			       unsigned int *attachments, int count,
1043 			       int *out_count, void *loaderPrivate);
1044 
1045     /**
1046      * Flush pending front-buffer rendering
1047      *
1048      * Any rendering that has been performed to the
1049      * \c __DRI_BUFFER_FAKE_FRONT_LEFT will be flushed to the
1050      * \c __DRI_BUFFER_FRONT_LEFT.
1051      *
1052      * \param driDrawable    Drawable whose front-buffer is to be flushed
1053      * \param loaderPrivate  Loader's private data that was previously passed
1054      *                       into __DRIdri2ExtensionRec::createNewDrawable
1055      *
1056      * \since 2
1057      */
1058     void (*flushFrontBuffer)(__DRIdrawable *driDrawable, void *loaderPrivate);
1059 
1060 
1061     /**
1062      * Get list of buffers from the server
1063      *
1064      * Gets a list of buffer for the specified set of attachments.  Unlike
1065      * \c ::getBuffers, this function takes a list of attachments paired with
1066      * opaque \c unsigned \c int value describing the format of the buffer.
1067      * It is the responsibility of the caller to know what the service that
1068      * allocates the buffers will expect to receive for the format.
1069      *
1070      * \param driDrawable    Drawable whose buffers are being queried.
1071      * \param width          Output where the width of the buffers is stored.
1072      * \param height         Output where the height of the buffers is stored.
1073      * \param attachments    List of pairs of attachment ID and opaque format
1074      *                       requested for the drawable.
1075      * \param count          Number of attachment / format pairs stored in
1076      *                       \c attachments.
1077      * \param loaderPrivate  Loader's private data that was previously passed
1078      *                       into __DRIdri2ExtensionRec::createNewDrawable.
1079      *
1080      * \since 3
1081      */
1082     __DRIbuffer *(*getBuffersWithFormat)(__DRIdrawable *driDrawable,
1083 					 int *width, int *height,
1084 					 unsigned int *attachments, int count,
1085 					 int *out_count, void *loaderPrivate);
1086 
1087     /**
1088      * Return a loader capability value. If the loader doesn't know the enum,
1089      * it will return 0.
1090      *
1091      * \param loaderPrivate The last parameter of createNewScreen or
1092      *                      createNewScreen2.
1093      * \param cap           See the enum.
1094      *
1095      * \since 4
1096      */
1097     unsigned (*getCapability)(void *loaderPrivate, enum dri_loader_cap cap);
1098 
1099     /**
1100      * Clean up any loader state associated with an image.
1101      *
1102      * \param loaderPrivate  Loader's private data that was previously passed
1103      *                       into a __DRIimageExtensionRec::createImage function
1104      * \since 5
1105      */
1106     void (*destroyLoaderImageState)(void *loaderPrivate);
1107 };
1108 
1109 /**
1110  * This extension provides alternative screen, drawable and context
1111  * constructors for DRI2.  The X server uses up to version 4.
1112  */
1113 #define __DRI_DRI2 "DRI_DRI2"
1114 #define __DRI_DRI2_VERSION 4
1115 
1116 #define __DRI_API_OPENGL	0	/**< OpenGL compatibility profile */
1117 #define __DRI_API_GLES		1	/**< OpenGL ES 1.x */
1118 #define __DRI_API_GLES2		2	/**< OpenGL ES 2.x */
1119 #define __DRI_API_OPENGL_CORE	3	/**< OpenGL 3.2+ core profile */
1120 #define __DRI_API_GLES3		4	/**< OpenGL ES 3.x */
1121 
1122 #define __DRI_CTX_ATTRIB_MAJOR_VERSION		0
1123 #define __DRI_CTX_ATTRIB_MINOR_VERSION		1
1124 
1125 /* These must alias the GLX/EGL values. */
1126 #define __DRI_CTX_ATTRIB_FLAGS			2
1127 #define __DRI_CTX_FLAG_DEBUG			0x00000001
1128 #define __DRI_CTX_FLAG_FORWARD_COMPATIBLE	0x00000002
1129 #define __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS	0x00000004
1130 #define __DRI_CTX_FLAG_NO_ERROR			0x00000008 /* Deprecated, do not use */
1131 /* Not yet implemented but placed here to reserve the alias with GLX */
1132 #define __DRI_CTX_FLAG_RESET_ISOLATION          0x00000008
1133 
1134 #define __DRI_CTX_ATTRIB_RESET_STRATEGY		3
1135 #define __DRI_CTX_RESET_NO_NOTIFICATION		0
1136 #define __DRI_CTX_RESET_LOSE_CONTEXT		1
1137 
1138 /**
1139  * \name Context priority levels.
1140  */
1141 #define __DRI_CTX_ATTRIB_PRIORITY		4
1142 #define __DRI_CTX_PRIORITY_LOW			0
1143 #define __DRI_CTX_PRIORITY_MEDIUM		1
1144 #define __DRI_CTX_PRIORITY_HIGH			2
1145 
1146 #define __DRI_CTX_ATTRIB_RELEASE_BEHAVIOR	5
1147 #define __DRI_CTX_RELEASE_BEHAVIOR_NONE         0
1148 #define __DRI_CTX_RELEASE_BEHAVIOR_FLUSH        1
1149 
1150 #define __DRI_CTX_ATTRIB_NO_ERROR               6
1151 
1152 /**
1153  * \requires __DRI2_RENDER_HAS_PROTECTED_CONTEXT.
1154  *
1155  */
1156 #define __DRI_CTX_ATTRIB_PROTECTED              7
1157 
1158 
1159 #define __DRI_CTX_NUM_ATTRIBS                   8
1160 
1161 /**
1162  * \name Reasons that __DRIdri2Extension::createContextAttribs might fail
1163  */
1164 /*@{*/
1165 /** Success! */
1166 #define __DRI_CTX_ERROR_SUCCESS			0
1167 
1168 /** Memory allocation failure */
1169 #define __DRI_CTX_ERROR_NO_MEMORY		1
1170 
1171 /** Client requested an API (e.g., OpenGL ES 2.0) that the driver can't do. */
1172 #define __DRI_CTX_ERROR_BAD_API			2
1173 
1174 /** Client requested an API version that the driver can't do. */
1175 #define __DRI_CTX_ERROR_BAD_VERSION		3
1176 
1177 /** Client requested a flag or combination of flags the driver can't do. */
1178 #define __DRI_CTX_ERROR_BAD_FLAG		4
1179 
1180 /** Client requested an attribute the driver doesn't understand. */
1181 #define __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE	5
1182 
1183 /** Client requested a flag the driver doesn't understand. */
1184 #define __DRI_CTX_ERROR_UNKNOWN_FLAG		6
1185 /*@}*/
1186 
1187 struct __DRIdri2ExtensionRec {
1188     __DRIextension base;
1189 
1190     __DRIscreen *(*createNewScreen)(int screen, int fd,
1191 				    const __DRIextension **extensions,
1192 				    const __DRIconfig ***driver_configs,
1193 				    void *loaderPrivate);
1194 
1195    __DRIcreateNewDrawableFunc   createNewDrawable;
1196    __DRIcontext *(*createNewContext)(__DRIscreen *screen,
1197                                      const __DRIconfig *config,
1198                                      __DRIcontext *shared,
1199                                      void *loaderPrivate);
1200 
1201    /* Since version 2 */
1202    __DRIgetAPIMaskFunc          getAPIMask;
1203 
1204    __DRIcontext *(*createNewContextForAPI)(__DRIscreen *screen,
1205 					   int api,
1206 					   const __DRIconfig *config,
1207 					   __DRIcontext *shared,
1208 					   void *data);
1209 
1210    __DRIbuffer *(*allocateBuffer)(__DRIscreen *screen,
1211 				  unsigned int attachment,
1212 				  unsigned int format,
1213 				  int width,
1214 				  int height);
1215    void (*releaseBuffer)(__DRIscreen *screen,
1216 			 __DRIbuffer *buffer);
1217 
1218    /**
1219     * Create a context for a particular API with a set of attributes
1220     *
1221     * \since version 3
1222     *
1223     * \sa __DRIswrastExtensionRec::createContextAttribs
1224     */
1225    __DRIcreateContextAttribsFunc        createContextAttribs;
1226 
1227    /**
1228     * createNewScreen with the driver's extension list passed in.
1229     *
1230     * \since version 4
1231     */
1232    __DRIcreateNewScreen2Func            createNewScreen2;
1233 };
1234 
1235 
1236 /**
1237  * This extension provides functionality to enable various EGLImage
1238  * extensions.
1239  */
1240 #define __DRI_IMAGE "DRI_IMAGE"
1241 #define __DRI_IMAGE_VERSION 20
1242 
1243 /* __DRI_IMAGE_FORMAT_* tokens are no longer exported */
1244 
1245 #define __DRI_IMAGE_USE_SHARE		0x0001
1246 #define __DRI_IMAGE_USE_SCANOUT		0x0002
1247 #define __DRI_IMAGE_USE_CURSOR		0x0004 /* Deprecated */
1248 #define __DRI_IMAGE_USE_LINEAR		0x0008
1249 /* The buffer will only be read by an external process after SwapBuffers,
1250  * in contrary to gbm buffers, front buffers and fake front buffers, which
1251  * could be read after a flush."
1252  */
1253 #define __DRI_IMAGE_USE_BACKBUFFER      0x0010
1254 #define __DRI_IMAGE_USE_PROTECTED       0x0020
1255 #define __DRI_IMAGE_USE_PRIME_BUFFER    0x0040
1256 #define __DRI_IMAGE_USE_FRONT_RENDERING 0x0080
1257 
1258 
1259 #define __DRI_IMAGE_TRANSFER_READ            0x1
1260 #define __DRI_IMAGE_TRANSFER_WRITE           0x2
1261 #define __DRI_IMAGE_TRANSFER_READ_WRITE      \
1262         (__DRI_IMAGE_TRANSFER_READ | __DRI_IMAGE_TRANSFER_WRITE)
1263 
1264 /**
1265  * Extra fourcc formats used internally to Mesa with createImageFromNames.
1266  * The externally-available fourccs are defined by drm_fourcc.h (DRM_FORMAT_*)
1267  * and WL_DRM_FORMAT_* from wayland_drm.h.
1268  *
1269  * \since 5
1270  */
1271 
1272 #define __DRI_IMAGE_FOURCC_SARGB8888	0x83324258
1273 #define __DRI_IMAGE_FOURCC_SABGR8888	0x84324258
1274 #define __DRI_IMAGE_FOURCC_SXRGB8888	0x85324258
1275 
1276 /**
1277  * Queryable on images created by createImageFromNames.
1278  *
1279  * RGB and RGBA might be usable directly as images, but it's still
1280  * recommended to call fromPlanar with plane == 0.
1281  *
1282  * Y_U_V, Y_UV,Y_XUXV and Y_UXVX all requires call to fromPlanar to create
1283  * usable sub-images, sampling from images return raw YUV data and
1284  * color conversion needs to be done in the shader.
1285  *
1286  * \since 5
1287  */
1288 
1289 #define __DRI_IMAGE_COMPONENTS_RGB	0x3001
1290 #define __DRI_IMAGE_COMPONENTS_RGBA	0x3002
1291 #define __DRI_IMAGE_COMPONENTS_Y_U_V	0x3003
1292 #define __DRI_IMAGE_COMPONENTS_Y_UV	0x3004
1293 #define __DRI_IMAGE_COMPONENTS_Y_XUXV	0x3005
1294 #define __DRI_IMAGE_COMPONENTS_Y_UXVX	0x3008
1295 #define __DRI_IMAGE_COMPONENTS_AYUV	0x3009
1296 #define __DRI_IMAGE_COMPONENTS_XYUV	0x300A
1297 #define __DRI_IMAGE_COMPONENTS_R	0x3006
1298 #define __DRI_IMAGE_COMPONENTS_RG	0x3007
1299 
1300 
1301 /**
1302  * queryImage attributes
1303  */
1304 
1305 #define __DRI_IMAGE_ATTRIB_STRIDE	0x2000
1306 #define __DRI_IMAGE_ATTRIB_HANDLE	0x2001
1307 #define __DRI_IMAGE_ATTRIB_NAME		0x2002
1308 #define __DRI_IMAGE_ATTRIB_FORMAT	0x2003 /* available in versions 3+ */
1309 #define __DRI_IMAGE_ATTRIB_WIDTH	0x2004 /* available in versions 4+ */
1310 #define __DRI_IMAGE_ATTRIB_HEIGHT	0x2005
1311 #define __DRI_IMAGE_ATTRIB_COMPONENTS	0x2006 /* available in versions 5+ */
1312 #define __DRI_IMAGE_ATTRIB_FD           0x2007 /* available in versions
1313                                                 * 7+. Each query will return a
1314                                                 * new fd. */
1315 #define __DRI_IMAGE_ATTRIB_FOURCC       0x2008 /* available in versions 11 */
1316 #define __DRI_IMAGE_ATTRIB_NUM_PLANES   0x2009 /* available in versions 11 */
1317 
1318 #define __DRI_IMAGE_ATTRIB_OFFSET 0x200A /* available in versions 13 */
1319 #define __DRI_IMAGE_ATTRIB_MODIFIER_LOWER 0x200B /* available in versions 14 */
1320 #define __DRI_IMAGE_ATTRIB_MODIFIER_UPPER 0x200C /* available in versions 14 */
1321 
1322 enum __DRIYUVColorSpace {
1323    __DRI_YUV_COLOR_SPACE_UNDEFINED = 0,
1324    __DRI_YUV_COLOR_SPACE_ITU_REC601 = 0x327F,
1325    __DRI_YUV_COLOR_SPACE_ITU_REC709 = 0x3280,
1326    __DRI_YUV_COLOR_SPACE_ITU_REC2020 = 0x3281
1327 };
1328 
1329 enum __DRISampleRange {
1330    __DRI_YUV_RANGE_UNDEFINED = 0,
1331    __DRI_YUV_FULL_RANGE = 0x3282,
1332    __DRI_YUV_NARROW_RANGE = 0x3283
1333 };
1334 
1335 enum __DRIChromaSiting {
1336    __DRI_YUV_CHROMA_SITING_UNDEFINED = 0,
1337    __DRI_YUV_CHROMA_SITING_0 = 0x3284,
1338    __DRI_YUV_CHROMA_SITING_0_5 = 0x3285
1339 };
1340 
1341 /**
1342  * \name Reasons that __DRIimageExtensionRec::createImageFromTexture or
1343  * __DRIimageExtensionRec::createImageFromDmaBufs might fail
1344  */
1345 /*@{*/
1346 /** Success! */
1347 #define __DRI_IMAGE_ERROR_SUCCESS       0
1348 
1349 /** Memory allocation failure */
1350 #define __DRI_IMAGE_ERROR_BAD_ALLOC     1
1351 
1352 /** Client requested an invalid attribute */
1353 #define __DRI_IMAGE_ERROR_BAD_MATCH     2
1354 
1355 /** Client requested an invalid texture object */
1356 #define __DRI_IMAGE_ERROR_BAD_PARAMETER 3
1357 
1358 /** Client requested an invalid pitch and/or offset */
1359 #define __DRI_IMAGE_ERROR_BAD_ACCESS    4
1360 /*@}*/
1361 
1362 /**
1363  * \name Capabilities that might be returned by __DRIimageExtensionRec::getCapabilities
1364  */
1365 /*@{*/
1366 #define __DRI_IMAGE_CAP_GLOBAL_NAMES 1
1367 /*@}*/
1368 
1369 /**
1370  * blitImage flags
1371  */
1372 
1373 #define __BLIT_FLAG_FLUSH		0x0001
1374 #define __BLIT_FLAG_FINISH		0x0002
1375 
1376 /**
1377  * Flags for createImageFromDmaBufs3 and createImageFromFds2
1378  */
1379 #define __DRI_IMAGE_PROTECTED_CONTENT_FLAG 0x00000001
1380 #define __DRI_IMAGE_PRIME_LINEAR_BUFFER    0x00000002
1381 
1382 /**
1383  * queryDmaBufFormatModifierAttribs attributes
1384  */
1385 
1386 /* Available in version 16 */
1387 #define __DRI_IMAGE_FORMAT_MODIFIER_ATTRIB_PLANE_COUNT   0x0001
1388 
1389 typedef struct __DRIimageRec          __DRIimage;
1390 typedef struct __DRIimageExtensionRec __DRIimageExtension;
1391 struct __DRIimageExtensionRec {
1392     __DRIextension base;
1393 
1394     __DRIimage *(*createImageFromName)(__DRIscreen *screen,
1395 				       int width, int height, int format,
1396 				       int name, int pitch,
1397 				       void *loaderPrivate);
1398 
1399     /* Deprecated since version 17; see createImageFromRenderbuffer2 */
1400     __DRIimage *(*createImageFromRenderbuffer)(__DRIcontext *context,
1401 					       int renderbuffer,
1402 					       void *loaderPrivate);
1403 
1404     void (*destroyImage)(__DRIimage *image);
1405 
1406     __DRIimage *(*createImage)(__DRIscreen *screen,
1407 			       int width, int height, int format,
1408 			       unsigned int use,
1409 			       void *loaderPrivate);
1410 
1411    unsigned char (*queryImage)(__DRIimage *image, int attrib, int *value);
1412 
1413    /**
1414     * The new __DRIimage will share the content with the old one, see dup(2).
1415     */
1416    __DRIimage *(*dupImage)(__DRIimage *image, void *loaderPrivate);
1417 
1418    /**
1419     * Validate that a __DRIimage can be used a certain way.
1420     *
1421     * \since 2
1422     */
1423    unsigned char (*validateUsage)(__DRIimage *image, unsigned int use);
1424 
1425    /**
1426     * Unlike createImageFromName __DRI_IMAGE_FORMAT is not used but instead
1427     * DRM_FORMAT_*, and strides are in bytes not pixels. Stride is
1428     * also per block and not per pixel (for non-RGB, see gallium blocks).
1429     *
1430     * \since 5
1431     */
1432    __DRIimage *(*createImageFromNames)(__DRIscreen *screen,
1433                                        int width, int height, int fourcc,
1434                                        int *names, int num_names,
1435                                        int *strides, int *offsets,
1436                                        void *loaderPrivate);
1437 
1438    /**
1439     * Create an image out of a sub-region of a parent image.  This
1440     * entry point lets us create individual __DRIimages for different
1441     * planes in a planar buffer (typically yuv), for example.  While a
1442     * sub-image shares the underlying buffer object with the parent
1443     * image and other sibling sub-images, the life times of parent and
1444     * sub-images are not dependent.  Destroying the parent or a
1445     * sub-image doesn't affect other images.  The underlying buffer
1446     * object is free when no __DRIimage remains that references it.
1447     *
1448     * Sub-images may overlap, but rendering to overlapping sub-images
1449     * is undefined.
1450     *
1451     * \since 5
1452     */
1453     __DRIimage *(*fromPlanar)(__DRIimage *image, int plane,
1454                               void *loaderPrivate);
1455 
1456     /**
1457      * Create image from texture.
1458      *
1459      * \since 6
1460      */
1461    __DRIimage *(*createImageFromTexture)(__DRIcontext *context,
1462                                          int target,
1463                                          unsigned texture,
1464                                          int depth,
1465                                          int level,
1466                                          unsigned *error,
1467                                          void *loaderPrivate);
1468    /**
1469     * Like createImageFromNames, but takes a prime fd instead.
1470     *
1471     * \since 7
1472     */
1473    __DRIimage *(*createImageFromFds)(__DRIscreen *screen,
1474                                      int width, int height, int fourcc,
1475                                      int *fds, int num_fds,
1476                                      int *strides, int *offsets,
1477                                      void *loaderPrivate);
1478 
1479    /**
1480     * Like createImageFromFds, but takes additional attributes.
1481     *
1482     * For EGL_EXT_image_dma_buf_import.
1483     *
1484     * \since 8
1485     */
1486    __DRIimage *(*createImageFromDmaBufs)(__DRIscreen *screen,
1487                                          int width, int height, int fourcc,
1488                                          int *fds, int num_fds,
1489                                          int *strides, int *offsets,
1490                                          enum __DRIYUVColorSpace color_space,
1491                                          enum __DRISampleRange sample_range,
1492                                          enum __DRIChromaSiting horiz_siting,
1493                                          enum __DRIChromaSiting vert_siting,
1494                                          unsigned *error,
1495                                          void *loaderPrivate);
1496 
1497    /**
1498     * Blit a part of a __DRIimage to another and flushes
1499     *
1500     * flush_flag:
1501     *    0:                  no flush
1502     *    __BLIT_FLAG_FLUSH:  flush after the blit operation
1503     *    __BLIT_FLAG_FINISH: flush and wait the blit finished
1504     *
1505     * \since 9
1506     */
1507    void (*blitImage)(__DRIcontext *context, __DRIimage *dst, __DRIimage *src,
1508                      int dstx0, int dsty0, int dstwidth, int dstheight,
1509                      int srcx0, int srcy0, int srcwidth, int srcheight,
1510                      int flush_flag);
1511 
1512    /**
1513     * Query for general capabilities of the driver that concern
1514     * buffer sharing and image importing.
1515     *
1516     * \since 10
1517     */
1518    int (*getCapabilities)(__DRIscreen *screen);
1519 
1520    /**
1521     * Returns a map of the specified region of a __DRIimage for the specified usage.
1522     *
1523     * flags may include __DRI_IMAGE_TRANSFER_READ, which will populate the
1524     * mapping with the current buffer content. If __DRI_IMAGE_TRANSFER_READ
1525     * is not included in the flags, the buffer content at map time is
1526     * undefined. Users wanting to modify the mapping must include
1527     * __DRI_IMAGE_TRANSFER_WRITE; if __DRI_IMAGE_TRANSFER_WRITE is not
1528     * included, behaviour when writing the mapping is undefined.
1529     *
1530     * Returns the byte stride in *stride, and an opaque pointer to data
1531     * tracking the mapping in **data, which must be passed to unmapImage().
1532     *
1533     * \since 12
1534     */
1535    void *(*mapImage)(__DRIcontext *context, __DRIimage *image,
1536                      int x0, int y0, int width, int height,
1537                      unsigned int flags, int *stride, void **data);
1538 
1539    /**
1540     * Unmap a previously mapped __DRIimage
1541     *
1542     * \since 12
1543     */
1544    void (*unmapImage)(__DRIcontext *context, __DRIimage *image, void *data);
1545 
1546 
1547    /**
1548     * Creates an image with implementation's favorite modifiers.
1549     *
1550     * This acts like createImage except there is a list of modifiers passed in
1551     * which the implementation may selectively use to create the DRIimage. The
1552     * result should be the implementation selects one modifier (perhaps it would
1553     * hold on to a few and later pick).
1554     *
1555     * The created image should be destroyed with destroyImage().
1556     *
1557     * Returns the new DRIimage. The chosen modifier can be obtained later on
1558     * and passed back to things like the kernel's AddFB2 interface.
1559     *
1560     * \sa __DRIimageRec::createImage
1561     *
1562     * \since 14
1563     */
1564    __DRIimage *(*createImageWithModifiers)(__DRIscreen *screen,
1565                                            int width, int height, int format,
1566                                            const uint64_t *modifiers,
1567                                            const unsigned int modifier_count,
1568                                            void *loaderPrivate);
1569 
1570    /*
1571     * Like createImageFromDmaBufs, but takes also format modifiers.
1572     *
1573     * For EGL_EXT_image_dma_buf_import_modifiers.
1574     *
1575     * \since 15
1576     */
1577    __DRIimage *(*createImageFromDmaBufs2)(__DRIscreen *screen,
1578                                           int width, int height, int fourcc,
1579                                           uint64_t modifier,
1580                                           int *fds, int num_fds,
1581                                           int *strides, int *offsets,
1582                                           enum __DRIYUVColorSpace color_space,
1583                                           enum __DRISampleRange sample_range,
1584                                           enum __DRIChromaSiting horiz_siting,
1585                                           enum __DRIChromaSiting vert_siting,
1586                                           unsigned *error,
1587                                           void *loaderPrivate);
1588 
1589    /*
1590     * dmabuf format query to support EGL_EXT_image_dma_buf_import_modifiers.
1591     *
1592     * \param max      Maximum number of formats that can be accomodated into
1593     *                 \param formats. If zero, no formats are returned -
1594     *                 instead, the driver returns the total number of
1595     *                 supported dmabuf formats in \param count.
1596     * \param formats  Buffer to fill formats into.
1597     * \param count    Count of formats returned, or, total number of
1598     *                 supported formats in case \param max is zero.
1599     *
1600     * Returns true on success.
1601     *
1602     * \since 15
1603     */
1604    bool (*queryDmaBufFormats)(__DRIscreen *screen, int max, int *formats,
1605                               int *count);
1606 
1607    /*
1608     * dmabuf format modifier query for a given format to support
1609     * EGL_EXT_image_dma_buf_import_modifiers.
1610     *
1611     * \param fourcc    The format to query modifiers for. If this format
1612     *                  is not supported by the driver, return false.
1613     * \param max       Maximum number of modifiers that can be accomodated in
1614     *                  \param modifiers. If zero, no modifiers are returned -
1615     *                  instead, the driver returns the total number of
1616     *                  modifiers for \param format in \param count.
1617     * \param modifiers Buffer to fill modifiers into.
1618     * \param count     Count of the modifiers returned, or, total number of
1619     *                  supported modifiers for \param fourcc in case
1620     *                  \param max is zero.
1621     *
1622     * Returns true upon success.
1623     *
1624     * \since 15
1625     */
1626    bool (*queryDmaBufModifiers)(__DRIscreen *screen, int fourcc, int max,
1627                                 uint64_t *modifiers,
1628                                 unsigned int *external_only, int *count);
1629 
1630    /**
1631     * dmabuf format modifier attribute query for a given format and modifier.
1632     *
1633     * \param fourcc    The format to query. If this format is not supported by
1634     *                  the driver, return false.
1635     * \param modifier  The modifier to query. If this format+modifier is not
1636     *                  supported by the driver, return false.
1637     * \param attrib    The __DRI_IMAGE_FORMAT_MODIFIER_ATTRIB to query.
1638     * \param value     A pointer to where to store the result of the query.
1639     *
1640     * Returns true upon success.
1641     *
1642     * \since 16
1643     */
1644    bool (*queryDmaBufFormatModifierAttribs)(__DRIscreen *screen,
1645                                             uint32_t fourcc, uint64_t modifier,
1646                                             int attrib, uint64_t *value);
1647 
1648    /**
1649     * Create a DRI image from the given renderbuffer.
1650     *
1651     * \param context       the current DRI context
1652     * \param renderbuffer  the GL name of the renderbuffer
1653     * \param loaderPrivate for callbacks into the loader related to the image
1654     * \param error         will be set to one of __DRI_IMAGE_ERROR_xxx
1655     * \return the newly created image on success, or NULL otherwise
1656     *
1657     * \since 17
1658     */
1659     __DRIimage *(*createImageFromRenderbuffer2)(__DRIcontext *context,
1660                                                 int renderbuffer,
1661                                                 void *loaderPrivate,
1662                                                 unsigned *error);
1663 
1664    /*
1665     * Like createImageFromDmaBufs2, but with an added flags parameter.
1666     *
1667     * See __DRI_IMAGE_*_FLAG for valid definitions of flags.
1668     *
1669     * \since 18
1670     */
1671    __DRIimage *(*createImageFromDmaBufs3)(__DRIscreen *screen,
1672                                           int width, int height, int fourcc,
1673                                           uint64_t modifier,
1674                                           int *fds, int num_fds,
1675                                           int *strides, int *offsets,
1676                                           enum __DRIYUVColorSpace color_space,
1677                                           enum __DRISampleRange sample_range,
1678                                           enum __DRIChromaSiting horiz_siting,
1679                                           enum __DRIChromaSiting vert_siting,
1680                                           uint32_t flags,
1681                                           unsigned *error,
1682                                           void *loaderPrivate);
1683 
1684    /**
1685     * Creates an image with implementation's favorite modifiers and the
1686     * provided usage flags.
1687     *
1688     * This acts like createImageWithModifiers except usage is also specified.
1689     *
1690     * The created image should be destroyed with destroyImage().
1691     *
1692     * Returns the new DRIimage. The chosen modifier can be obtained later on
1693     * and passed back to things like the kernel's AddFB2 interface.
1694     *
1695     * \sa __DRIimageRec::createImage
1696     *
1697     * \since 19
1698     */
1699    __DRIimage *(*createImageWithModifiers2)(__DRIscreen *screen,
1700                                             int width, int height, int format,
1701                                             const uint64_t *modifiers,
1702                                             const unsigned int modifier_count,
1703                                             unsigned int use,
1704                                             void *loaderPrivate);
1705 
1706    /**
1707     * Like createImageFromFds, but with an added flag parameter.
1708     *
1709     * See __DRI_IMAGE_*_FLAG for valid definitions of flags.
1710     *
1711     * \since 20
1712     */
1713    __DRIimage *(*createImageFromFds2)(__DRIscreen *screen,
1714                                       int width, int height, int fourcc,
1715                                       int *fds, int num_fds,
1716                                       uint32_t flags,
1717                                       int *strides, int *offsets,
1718                                       void *loaderPrivate);
1719 
1720    /**
1721     * Set an in-fence-fd on the image.  If a fence-fd is already set
1722     * (but not yet consumed), the existing and new fence will be merged
1723     *
1724     * This does *not* take ownership of the fd.  The fd does not need
1725     * to be kept alive once the call has returned.
1726     *
1727     * \since 21
1728     */
1729    void (*setInFenceFd)(__DRIimage *image, int fd);
1730 };
1731 
1732 
1733 /**
1734  * This extension must be implemented by the loader and passed to the
1735  * driver at screen creation time.  The EGLImage entry points in the
1736  * various client APIs take opaque EGLImage handles and use this
1737  * extension to map them to a __DRIimage.  At version 1, this
1738  * extensions allows mapping EGLImage pointers to __DRIimage pointers,
1739  * but future versions could support other EGLImage-like, opaque types
1740  * with new lookup functions.
1741  */
1742 #define __DRI_IMAGE_LOOKUP "DRI_IMAGE_LOOKUP"
1743 #define __DRI_IMAGE_LOOKUP_VERSION 2
1744 
1745 typedef struct __DRIimageLookupExtensionRec __DRIimageLookupExtension;
1746 struct __DRIimageLookupExtensionRec {
1747     __DRIextension base;
1748 
1749     /**
1750      * Lookup EGLImage without validated. Equivalent to call
1751      * validateEGLImage() then lookupEGLImageValidated().
1752      *
1753      * \since 1
1754      */
1755     __DRIimage *(*lookupEGLImage)(__DRIscreen *screen, void *image,
1756 				  void *loaderPrivate);
1757 
1758     /**
1759      * Check if EGLImage is associated with the EGL display before lookup with
1760      * lookupEGLImageValidated(). It will hold EGLDisplay.Mutex, so is separated
1761      * out from lookupEGLImage() to avoid deadlock.
1762      *
1763      * \since 2
1764      */
1765     unsigned char (*validateEGLImage)(void *image, void *loaderPrivate);
1766 
1767     /**
1768      * Lookup EGLImage after validateEGLImage(). No lock in this function.
1769      *
1770      * \since 2
1771      */
1772     __DRIimage *(*lookupEGLImageValidated)(void *image, void *loaderPrivate);
1773 };
1774 
1775 /**
1776  * This extension allows for common DRI2 options
1777  */
1778 #define __DRI2_CONFIG_QUERY "DRI_CONFIG_QUERY"
1779 #define __DRI2_CONFIG_QUERY_VERSION 2
1780 
1781 typedef struct __DRI2configQueryExtensionRec __DRI2configQueryExtension;
1782 struct __DRI2configQueryExtensionRec {
1783    __DRIextension base;
1784 
1785    int (*configQueryb)(__DRIscreen *screen, const char *var, unsigned char *val);
1786    int (*configQueryi)(__DRIscreen *screen, const char *var, int *val);
1787    int (*configQueryf)(__DRIscreen *screen, const char *var, float *val);
1788    int (*configQuerys)(__DRIscreen *screen, const char *var, char **val);
1789 };
1790 
1791 /**
1792  * Robust context driver extension.
1793  *
1794  * Existence of this extension means the driver can accept the
1795  * \c __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS flag and the
1796  * \c __DRI_CTX_ATTRIB_RESET_STRATEGY attribute in
1797  * \c __DRIdri2ExtensionRec::createContextAttribs.
1798  *
1799  * Used by the X server.
1800  */
1801 #define __DRI2_ROBUSTNESS "DRI_Robustness"
1802 #define __DRI2_ROBUSTNESS_VERSION 1
1803 
1804 typedef struct __DRIrobustnessExtensionRec __DRIrobustnessExtension;
1805 struct __DRIrobustnessExtensionRec {
1806    __DRIextension base;
1807 };
1808 
1809 /**
1810  * No-error context driver extension (deprecated).
1811  *
1812  * Existence of this extension means the driver can accept the
1813  * __DRI_CTX_FLAG_NO_ERROR flag.
1814  *
1815  * This extension is deprecated, and modern Mesa knows that it's always
1816  * supported.
1817  *
1818  * Not used by the X server.
1819  */
1820 #define __DRI2_NO_ERROR "DRI_NoError"
1821 #define __DRI2_NO_ERROR_VERSION 1
1822 
1823 typedef struct __DRInoErrorExtensionRec {
1824    __DRIextension base;
1825 } __DRInoErrorExtension;
1826 
1827 /*
1828  * Flush control driver extension.
1829  *
1830  * Existence of this extension means the driver can accept the
1831  * \c __DRI_CTX_ATTRIB_RELEASE_BEHAVIOR attribute in
1832  * \c __DRIdri2ExtensionRec::createContextAttribs.
1833  *
1834  * Used by the X server.
1835  */
1836 #define __DRI2_FLUSH_CONTROL "DRI_FlushControl"
1837 #define __DRI2_FLUSH_CONTROL_VERSION 1
1838 
1839 typedef struct __DRI2flushControlExtensionRec __DRI2flushControlExtension;
1840 struct __DRI2flushControlExtensionRec {
1841    __DRIextension base;
1842 };
1843 
1844 /**
1845  * DRI config options extension.
1846  *
1847  * This extension provides the XML string containing driver options for use by
1848  * the loader in supporting the driconf application.
1849  *
1850  * v2:
1851  * - Add the getXml getter function which allows the driver more flexibility in
1852  *   how the XML is provided.
1853  * - Deprecate the direct xml pointer. It is only provided as a fallback for
1854  *   older versions of libGL and must not be used by clients that are aware of
1855  *   the newer version. Future driver versions may set it to NULL.
1856  */
1857 #define __DRI_CONFIG_OPTIONS "DRI_ConfigOptions"
1858 #define __DRI_CONFIG_OPTIONS_VERSION 2
1859 
1860 typedef struct __DRIconfigOptionsExtensionRec {
1861    __DRIextension base;
1862    const char *xml; /**< deprecated since v2, use getXml instead */
1863 
1864    /**
1865     * Get an XML string that describes available driver options for use by a
1866     * config application.
1867     *
1868     * The returned string must be heap-allocated. The caller is responsible for
1869     * freeing it.
1870     */
1871    char *(*getXml)(const char *driver_name);
1872 } __DRIconfigOptionsExtension;
1873 
1874 /**
1875  * Query renderer driver extension
1876  *
1877  * This allows the window system layer (either EGL or GLX) to query aspects of
1878  * hardware and driver support without creating a context.
1879  */
1880 #define __DRI2_RENDERER_QUERY "DRI_RENDERER_QUERY"
1881 #define __DRI2_RENDERER_QUERY_VERSION 1
1882 
1883 #define __DRI2_RENDERER_VENDOR_ID                             0x0000
1884 #define __DRI2_RENDERER_DEVICE_ID                             0x0001
1885 #define __DRI2_RENDERER_VERSION                               0x0002
1886 #define __DRI2_RENDERER_ACCELERATED                           0x0003
1887 #define __DRI2_RENDERER_VIDEO_MEMORY                          0x0004
1888 #define __DRI2_RENDERER_UNIFIED_MEMORY_ARCHITECTURE           0x0005
1889 #define __DRI2_RENDERER_PREFERRED_PROFILE                     0x0006
1890 #define __DRI2_RENDERER_OPENGL_CORE_PROFILE_VERSION           0x0007
1891 #define __DRI2_RENDERER_OPENGL_COMPATIBILITY_PROFILE_VERSION  0x0008
1892 #define __DRI2_RENDERER_OPENGL_ES_PROFILE_VERSION             0x0009
1893 #define __DRI2_RENDERER_OPENGL_ES2_PROFILE_VERSION            0x000a
1894 
1895 #define __DRI2_RENDERER_PREFER_BACK_BUFFER_REUSE              0x000f
1896 
1897 typedef struct __DRI2rendererQueryExtensionRec __DRI2rendererQueryExtension;
1898 struct __DRI2rendererQueryExtensionRec {
1899    __DRIextension base;
1900 
1901    int (*queryInteger)(__DRIscreen *screen, int attribute, unsigned int *val);
1902    int (*queryString)(__DRIscreen *screen, int attribute, const char **val);
1903 };
1904 
1905 /**
1906  * Image Loader extension. Drivers use this to allocate color buffers
1907  */
1908 
1909 /**
1910  * See __DRIimageLoaderExtensionRec::getBuffers::buffer_mask.
1911  */
1912 enum __DRIimageBufferMask {
1913    __DRI_IMAGE_BUFFER_BACK = (1 << 0),
1914    __DRI_IMAGE_BUFFER_FRONT = (1 << 1),
1915 
1916    /**
1917     * A buffer shared between application and compositor. The buffer may be
1918     * simultaneously accessed by each.
1919     *
1920     * A shared buffer is equivalent to an EGLSurface whose EGLConfig contains
1921     * EGL_MUTABLE_RENDER_BUFFER_BIT_KHR and whose active EGL_RENDER_BUFFER (as
1922     * opposed to any pending, requested change to EGL_RENDER_BUFFER) is
1923     * EGL_SINGLE_BUFFER.
1924     *
1925     * If buffer_mask contains __DRI_IMAGE_BUFFER_SHARED, then must contains no
1926     * other bits. As a corollary, a __DRIdrawable that has a "shared" buffer
1927     * has no front nor back buffer.
1928     *
1929     * The loader returns __DRI_IMAGE_BUFFER_SHARED in buffer_mask if and only
1930     * if:
1931     *     - The loader supports __DRI_MUTABLE_RENDER_BUFFER_LOADER.
1932     *     - The driver supports __DRI_MUTABLE_RENDER_BUFFER_DRIVER.
1933     *     - The EGLConfig of the drawable EGLSurface contains
1934     *       EGL_MUTABLE_RENDER_BUFFER_BIT_KHR.
1935     *     - The EGLContext's EGL_RENDER_BUFFER is EGL_SINGLE_BUFFER.
1936     *       Equivalently, the EGLSurface's active EGL_RENDER_BUFFER (as
1937     *       opposed to any pending, requested change to EGL_RENDER_BUFFER) is
1938     *       EGL_SINGLE_BUFFER. (See the EGL 1.5 and
1939     *       EGL_KHR_mutable_render_buffer spec for details about "pending" vs
1940     *       "active" EGL_RENDER_BUFFER state).
1941     *
1942     * A shared buffer is similar to a front buffer in that all rendering to the
1943     * buffer should appear promptly on the screen. It is different from
1944     * a front buffer in that its behavior is independent from the
1945     * GL_DRAW_BUFFER state. Specifically, if GL_DRAW_FRAMEBUFFER is 0 and the
1946     * __DRIdrawable's buffer_mask is __DRI_IMAGE_BUFFER_SHARED, then all
1947     * rendering should appear promptly on the screen if GL_DRAW_BUFFER is not
1948     * GL_NONE.
1949     *
1950     * The difference between a shared buffer and a front buffer is motivated
1951     * by the constraints of Android and OpenGL ES. OpenGL ES does not support
1952     * front-buffer rendering. Android's SurfaceFlinger protocol provides the
1953     * EGL driver only a back buffer and no front buffer. The shared buffer
1954     * mode introduced by EGL_KHR_mutable_render_buffer is a backdoor though
1955     * EGL that allows Android OpenGL ES applications to render to what is
1956     * effectively the front buffer, a backdoor that required no change to the
1957     * OpenGL ES API and little change to the SurfaceFlinger API.
1958     */
1959    __DRI_IMAGE_BUFFER_SHARED = (1 << 2),
1960 };
1961 
1962 struct __DRIimageList {
1963    uint32_t image_mask;
1964    __DRIimage *back;
1965    __DRIimage *front;
1966 };
1967 
1968 #define __DRI_IMAGE_LOADER "DRI_IMAGE_LOADER"
1969 #define __DRI_IMAGE_LOADER_VERSION 4
1970 
1971 struct __DRIimageLoaderExtensionRec {
1972     __DRIextension base;
1973 
1974    /**
1975     * Allocate color buffers.
1976     *
1977     * \param driDrawable
1978     * \param width              Width of allocated buffers
1979     * \param height             Height of allocated buffers
1980     * \param format             one of __DRI_IMAGE_FORMAT_*
1981     * \param stamp              Address of variable to be updated when
1982     *                           getBuffers must be called again
1983     * \param loaderPrivate      The loaderPrivate for driDrawable
1984     * \param buffer_mask        Set of buffers to allocate. A bitmask of
1985     *                           __DRIimageBufferMask.
1986     * \param buffers            Returned buffers
1987     */
1988    int (*getBuffers)(__DRIdrawable *driDrawable,
1989                      unsigned int format,
1990                      uint32_t *stamp,
1991                      void *loaderPrivate,
1992                      uint32_t buffer_mask,
1993                      struct __DRIimageList *buffers);
1994 
1995     /**
1996      * Flush pending front-buffer rendering
1997      *
1998      * Any rendering that has been performed to the
1999      * fake front will be flushed to the front
2000      *
2001      * \param driDrawable    Drawable whose front-buffer is to be flushed
2002      * \param loaderPrivate  Loader's private data that was previously passed
2003      *                       into __DRIdri2ExtensionRec::createNewDrawable
2004      */
2005     void (*flushFrontBuffer)(__DRIdrawable *driDrawable, void *loaderPrivate);
2006 
2007     /**
2008      * Return a loader capability value. If the loader doesn't know the enum,
2009      * it will return 0.
2010      *
2011      * \since 2
2012      */
2013     unsigned (*getCapability)(void *loaderPrivate, enum dri_loader_cap cap);
2014 
2015     /**
2016      * Flush swap buffers
2017      *
2018      * Make sure any outstanding swap buffers have been submitted to the
2019      * device.
2020      *
2021      * \param driDrawable    Drawable whose swaps need to be flushed
2022      * \param loaderPrivate  Loader's private data that was previously passed
2023      *                       into __DRIdri2ExtensionRec::createNewDrawable
2024      *
2025      * \since 3
2026      */
2027     void (*flushSwapBuffers)(__DRIdrawable *driDrawable, void *loaderPrivate);
2028 
2029     /**
2030      * Clean up any loader state associated with an image.
2031      *
2032      * \param loaderPrivate  Loader's private data that was previously passed
2033      *                       into a __DRIimageExtensionRec::createImage function
2034      * \since 4
2035      */
2036     void (*destroyLoaderImageState)(void *loaderPrivate);
2037 };
2038 
2039 /**
2040  * Main DRI3 interface extension.
2041  *
2042  * Not used by the X server.
2043  */
2044 
2045 #define __DRI_IMAGE_DRIVER           "DRI_IMAGE_DRIVER"
2046 #define __DRI_IMAGE_DRIVER_VERSION   1
2047 
2048 struct __DRIimageDriverExtensionRec {
2049    __DRIextension               base;
2050 
2051    /* Common DRI functions, shared with DRI2 */
2052    __DRIcreateNewScreen2Func            createNewScreen2;
2053    __DRIcreateNewDrawableFunc           createNewDrawable;
2054    __DRIcreateContextAttribsFunc        createContextAttribs;
2055    __DRIgetAPIMaskFunc                  getAPIMask;
2056 };
2057 
2058 /**
2059  * Background callable loader extension.
2060  *
2061  * Loaders expose this extension to indicate to drivers that they are capable
2062  * of handling callbacks from the driver's background drawing threads.
2063  */
2064 #define __DRI_BACKGROUND_CALLABLE "DRI_BackgroundCallable"
2065 #define __DRI_BACKGROUND_CALLABLE_VERSION 1
2066 
2067 typedef struct __DRIbackgroundCallableExtensionRec __DRIbackgroundCallableExtension;
2068 struct __DRIbackgroundCallableExtensionRec {
2069    __DRIextension base;
2070 
2071    /**
2072     * Indicate that this thread is being used by the driver as a background
2073     * drawing thread which may make callbacks to the loader.
2074     *
2075     * \param loaderPrivate is the value that was passed to to the driver when
2076     * the context was created.  This can be used by the loader to identify
2077     * which context any callbacks are associated with.
2078     *
2079     * If this function is called more than once from any given thread, each
2080     * subsequent call overrides the loaderPrivate data that was passed in the
2081     * previous call.  The driver can take advantage of this to re-use a
2082     * background thread to perform drawing on behalf of multiple contexts.
2083     *
2084     * It is permissible for the driver to call this function from a
2085     * non-background thread (i.e. a thread that has already been bound to a
2086     * context using __DRIcoreExtensionRec::bindContext()); when this happens,
2087     * the \c loaderPrivate pointer must be equal to the pointer that was
2088     * passed to the driver when the currently bound context was created.
2089     *
2090     * This call should execute quickly enough that the driver can call it with
2091     * impunity whenever a background thread starts performing drawing
2092     * operations (e.g. it should just set a thread-local variable).
2093     */
2094    void (*setBackgroundContext)(void *loaderPrivate);
2095 
2096    /**
2097     * Indicate that it is multithread safe to use glthread.  For GLX/EGL
2098     * platforms using Xlib, that involves calling XInitThreads, before
2099     * opening an X display.
2100     *
2101     * Note: only supported if extension version is at least 2.
2102     *
2103     * \param loaderPrivate is the value that was passed to to the driver when
2104     * the context was created.  This can be used by the loader to identify
2105     * which context any callbacks are associated with.
2106     */
2107    unsigned char (*isThreadSafe)(void *loaderPrivate);
2108 };
2109 
2110 /**
2111  * The driver portion of EGL_KHR_mutable_render_buffer.
2112  *
2113  * If the driver creates a __DRIconfig with
2114  * __DRI_ATTRIB_MUTABLE_RENDER_BUFFER, then it must support this extension.
2115  *
2116  * To support this extension:
2117  *
2118  *    - The driver should create at least one __DRIconfig with
2119  *      __DRI_ATTRIB_MUTABLE_RENDER_BUFFER. This is strongly recommended but
2120  *      not required.
2121  *
2122  *    - The driver must be able to handle __DRI_IMAGE_BUFFER_SHARED if
2123  *      returned by __DRIimageLoaderExtension:getBuffers().
2124  *
2125  *    - When rendering to __DRI_IMAGE_BUFFER_SHARED, it must call
2126  *      __DRImutableRenderBufferLoaderExtension::displaySharedBuffer() in
2127  *      response to glFlush and glFinish.  (This requirement is not documented
2128  *      in EGL_KHR_mutable_render_buffer, but is a de-facto requirement in the
2129  *      Android ecosystem. Android applications expect that glFlush will
2130  *      immediately display the buffer when in shared buffer mode, and Android
2131  *      drivers comply with this expectation).  It :may: call
2132  *      displaySharedBuffer() more often than required.
2133  *
2134  *    - When rendering to __DRI_IMAGE_BUFFER_SHARED, it must ensure that the
2135  *      buffer is always in a format compatible for display because the
2136  *      display engine (usually SurfaceFlinger or hwcomposer) may display the
2137  *      image at any time, even concurrently with 3D rendering. For example,
2138  *      display hardware and the GL hardware may be able to access the buffer
2139  *      simultaneously. In particular, if the buffer is compressed then take
2140  *      care that SurfaceFlinger and hwcomposer can consume the compression
2141  *      format.
2142  *
2143  * Not used by the X server.
2144  *
2145  * \see __DRI_IMAGE_BUFFER_SHARED
2146  * \see __DRI_ATTRIB_MUTABLE_RENDER_BUFFER
2147  * \see __DRI_MUTABLE_RENDER_BUFFER_LOADER
2148  */
2149 #define __DRI_MUTABLE_RENDER_BUFFER_DRIVER "DRI_MutableRenderBufferDriver"
2150 #define __DRI_MUTABLE_RENDER_BUFFER_DRIVER_VERSION 1
2151 
2152 typedef struct __DRImutableRenderBufferDriverExtensionRec __DRImutableRenderBufferDriverExtension;
2153 struct __DRImutableRenderBufferDriverExtensionRec {
2154    __DRIextension base;
2155 };
2156 
2157 /**
2158  * The loader portion of EGL_KHR_mutable_render_buffer.
2159  *
2160  * Requires loader extension DRI_IMAGE_LOADER, through which the loader sends
2161  * __DRI_IMAGE_BUFFER_SHARED to the driver.
2162  *
2163  * Not used by the X server.
2164  *
2165  * \see __DRI_MUTABLE_RENDER_BUFFER_DRIVER
2166  */
2167 #define __DRI_MUTABLE_RENDER_BUFFER_LOADER "DRI_MutableRenderBufferLoader"
2168 #define __DRI_MUTABLE_RENDER_BUFFER_LOADER_VERSION 1
2169 
2170 typedef struct __DRImutableRenderBufferLoaderExtensionRec __DRImutableRenderBufferLoaderExtension;
2171 struct __DRImutableRenderBufferLoaderExtensionRec {
2172    __DRIextension base;
2173 
2174    /**
2175     * Inform the display engine (that is, SurfaceFlinger and/or hwcomposer)
2176     * that the __DRIdrawable has new content.
2177     *
2178     * The display engine may ignore this call, for example, if it continually
2179     * refreshes and displays the buffer on every frame, as in
2180     * EGL_ANDROID_front_buffer_auto_refresh. On the other extreme, the display
2181     * engine may refresh and display the buffer only in frames in which the
2182     * driver calls this.
2183     *
2184     * If the fence_fd is not -1, then the display engine will display the
2185     * buffer only after the fence signals.
2186     *
2187     * The drawable's current __DRIimageBufferMask, as returned by
2188     * __DRIimageLoaderExtension::getBuffers(), must be
2189     * __DRI_IMAGE_BUFFER_SHARED.
2190     */
2191    void (*displaySharedBuffer)(__DRIdrawable *drawable, int fence_fd,
2192                                void *loaderPrivate);
2193 };
2194 
2195 #endif
2196