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