2 * Copyright © 2010 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
25 * Kristian Høgsberg <krh@bitplanet.net>
39 #include <c11/threads.h>
43 #include <drm_fourcc.h>
46 #include <GL/internal/dri_interface.h>
47 #include <sys/types.h>
50 #ifdef HAVE_WAYLAND_PLATFORM
51 #include <wayland-client.h>
52 #include "wayland-drm.h"
53 #include "wayland-drm-client-protocol.h"
54 #include "linux-dmabuf-unstable-v1-client-protocol.h"
57 #ifdef HAVE_X11_PLATFORM
58 #include "X11/Xlibint.h"
62 #include "GL/mesa_glinterop.h"
63 #include "loader/loader.h"
64 #include "util/u_atomic.h"
65 #include "util/u_vector.h"
66 #include "mapi/glapi/glapi.h"
68 #define NUM_ATTRIBS 12
71 dri_set_background_context(void *loaderPrivate
)
73 _EGLContext
*ctx
= _eglGetCurrentContext();
74 _EGLThreadInfo
*t
= _eglGetCurrentThread();
76 _eglBindContextToThread(ctx
, t
);
82 static void (*glFlush
)(void);
83 static mtx_t glFlushMutex
= _MTX_INITIALIZER_NP
;
85 mtx_lock(&glFlushMutex
);
87 glFlush
= _glapi_get_proc_address("glFlush");
88 mtx_unlock(&glFlushMutex
);
90 /* if glFlush is not available things are horribly broken */
92 _eglLog(_EGL_WARNING
, "DRI2: failed to find glFlush entry point");
100 dri_is_thread_safe(void *loaderPrivate
)
102 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
103 _EGLDisplay
*display
= dri2_surf
->base
.Resource
.Display
;
105 #ifdef HAVE_X11_PLATFORM
106 Display
*xdpy
= (Display
*)display
->PlatformDisplay
;
108 /* Check Xlib is running in thread safe mode when running on EGL/X11-xlib
111 * 'lock_fns' is the XLockDisplay function pointer of the X11 display 'dpy'.
112 * It wll be NULL if XInitThreads wasn't called.
114 if (display
->Platform
== _EGL_PLATFORM_X11
&& xdpy
&& !xdpy
->lock_fns
)
118 #ifdef HAVE_WAYLAND_PLATFORM
119 if (display
->Platform
== _EGL_PLATFORM_WAYLAND
)
126 const __DRIbackgroundCallableExtension background_callable_extension
= {
127 .base
= { __DRI_BACKGROUND_CALLABLE
, 2 },
129 .setBackgroundContext
= dri_set_background_context
,
130 .isThreadSafe
= dri_is_thread_safe
,
133 const __DRIuseInvalidateExtension use_invalidate
= {
134 .base
= { __DRI_USE_INVALIDATE
, 1 }
137 static const EGLint dri2_to_egl_attribute_map
[__DRI_ATTRIB_MAX
] = {
138 [__DRI_ATTRIB_BUFFER_SIZE
] = EGL_BUFFER_SIZE
,
139 [__DRI_ATTRIB_LEVEL
] = EGL_LEVEL
,
140 [__DRI_ATTRIB_RED_SIZE
] = EGL_RED_SIZE
,
141 [__DRI_ATTRIB_GREEN_SIZE
] = EGL_GREEN_SIZE
,
142 [__DRI_ATTRIB_BLUE_SIZE
] = EGL_BLUE_SIZE
,
143 [__DRI_ATTRIB_LUMINANCE_SIZE
] = EGL_LUMINANCE_SIZE
,
144 [__DRI_ATTRIB_ALPHA_SIZE
] = EGL_ALPHA_SIZE
,
145 [__DRI_ATTRIB_DEPTH_SIZE
] = EGL_DEPTH_SIZE
,
146 [__DRI_ATTRIB_STENCIL_SIZE
] = EGL_STENCIL_SIZE
,
147 [__DRI_ATTRIB_SAMPLE_BUFFERS
] = EGL_SAMPLE_BUFFERS
,
148 [__DRI_ATTRIB_SAMPLES
] = EGL_SAMPLES
,
149 [__DRI_ATTRIB_MAX_PBUFFER_WIDTH
] = EGL_MAX_PBUFFER_WIDTH
,
150 [__DRI_ATTRIB_MAX_PBUFFER_HEIGHT
] = EGL_MAX_PBUFFER_HEIGHT
,
151 [__DRI_ATTRIB_MAX_PBUFFER_PIXELS
] = EGL_MAX_PBUFFER_PIXELS
,
152 [__DRI_ATTRIB_MAX_SWAP_INTERVAL
] = EGL_MAX_SWAP_INTERVAL
,
153 [__DRI_ATTRIB_MIN_SWAP_INTERVAL
] = EGL_MIN_SWAP_INTERVAL
,
154 [__DRI_ATTRIB_YINVERTED
] = EGL_Y_INVERTED_NOK
,
158 dri2_get_dri_config(struct dri2_egl_config
*conf
, EGLint surface_type
,
161 const bool double_buffer
= surface_type
== EGL_WINDOW_BIT
;
162 const bool srgb
= colorspace
== EGL_GL_COLORSPACE_SRGB_KHR
;
164 return conf
->dri_config
[double_buffer
][srgb
];
168 dri2_match_config(const _EGLConfig
*conf
, const _EGLConfig
*criteria
)
170 if (_eglCompareConfigs(conf
, criteria
, NULL
, EGL_FALSE
) != 0)
173 if (!_eglMatchConfig(conf
, criteria
))
179 struct dri2_egl_config
*
180 dri2_add_config(_EGLDisplay
*disp
, const __DRIconfig
*dri_config
, int id
,
181 EGLint surface_type
, const EGLint
*attr_list
,
182 const unsigned int *rgba_masks
)
184 struct dri2_egl_config
*conf
;
185 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
187 unsigned int attrib
, value
, double_buffer
;
189 EGLint key
, bind_to_texture_rgb
, bind_to_texture_rgba
;
190 unsigned int dri_masks
[4] = { 0, 0, 0, 0 };
191 _EGLConfig
*matching_config
;
192 EGLint num_configs
= 0;
195 _eglInitConfig(&base
, disp
, id
);
198 bind_to_texture_rgb
= 0;
199 bind_to_texture_rgba
= 0;
201 for (int i
= 0; dri2_dpy
->core
->indexConfigAttrib(dri_config
, i
, &attrib
,
204 case __DRI_ATTRIB_RENDER_TYPE
:
205 if (value
& __DRI_ATTRIB_RGBA_BIT
)
206 value
= EGL_RGB_BUFFER
;
207 else if (value
& __DRI_ATTRIB_LUMINANCE_BIT
)
208 value
= EGL_LUMINANCE_BUFFER
;
211 _eglSetConfigKey(&base
, EGL_COLOR_BUFFER_TYPE
, value
);
214 case __DRI_ATTRIB_CONFIG_CAVEAT
:
215 if (value
& __DRI_ATTRIB_NON_CONFORMANT_CONFIG
)
216 value
= EGL_NON_CONFORMANT_CONFIG
;
217 else if (value
& __DRI_ATTRIB_SLOW_BIT
)
218 value
= EGL_SLOW_CONFIG
;
221 _eglSetConfigKey(&base
, EGL_CONFIG_CAVEAT
, value
);
224 case __DRI_ATTRIB_BIND_TO_TEXTURE_RGB
:
225 bind_to_texture_rgb
= value
;
228 case __DRI_ATTRIB_BIND_TO_TEXTURE_RGBA
:
229 bind_to_texture_rgba
= value
;
232 case __DRI_ATTRIB_DOUBLE_BUFFER
:
233 double_buffer
= value
;
236 case __DRI_ATTRIB_RED_MASK
:
237 dri_masks
[0] = value
;
240 case __DRI_ATTRIB_GREEN_MASK
:
241 dri_masks
[1] = value
;
244 case __DRI_ATTRIB_BLUE_MASK
:
245 dri_masks
[2] = value
;
248 case __DRI_ATTRIB_ALPHA_MASK
:
249 dri_masks
[3] = value
;
252 case __DRI_ATTRIB_ACCUM_RED_SIZE
:
253 case __DRI_ATTRIB_ACCUM_GREEN_SIZE
:
254 case __DRI_ATTRIB_ACCUM_BLUE_SIZE
:
255 case __DRI_ATTRIB_ACCUM_ALPHA_SIZE
:
256 /* Don't expose visuals with the accumulation buffer. */
261 case __DRI_ATTRIB_FRAMEBUFFER_SRGB_CAPABLE
:
263 if (!disp
->Extensions
.KHR_gl_colorspace
&& srgb
)
267 case __DRI_ATTRIB_MAX_PBUFFER_WIDTH
:
268 _eglSetConfigKey(&base
, EGL_MAX_PBUFFER_WIDTH
,
269 _EGL_MAX_PBUFFER_WIDTH
);
271 case __DRI_ATTRIB_MAX_PBUFFER_HEIGHT
:
272 _eglSetConfigKey(&base
, EGL_MAX_PBUFFER_HEIGHT
,
273 _EGL_MAX_PBUFFER_HEIGHT
);
277 key
= dri2_to_egl_attribute_map
[attrib
];
279 _eglSetConfigKey(&base
, key
, value
);
285 for (int i
= 0; attr_list
[i
] != EGL_NONE
; i
+= 2)
286 _eglSetConfigKey(&base
, attr_list
[i
], attr_list
[i
+1]);
288 if (rgba_masks
&& memcmp(rgba_masks
, dri_masks
, sizeof(dri_masks
)))
291 base
.NativeRenderable
= EGL_TRUE
;
293 base
.SurfaceType
= surface_type
;
294 if (surface_type
& (EGL_PBUFFER_BIT
|
295 (disp
->Extensions
.NOK_texture_from_pixmap
? EGL_PIXMAP_BIT
: 0))) {
296 base
.BindToTextureRGB
= bind_to_texture_rgb
;
297 if (base
.AlphaSize
> 0)
298 base
.BindToTextureRGBA
= bind_to_texture_rgba
;
301 base
.RenderableType
= disp
->ClientAPIs
;
302 base
.Conformant
= disp
->ClientAPIs
;
304 base
.MinSwapInterval
= dri2_dpy
->min_swap_interval
;
305 base
.MaxSwapInterval
= dri2_dpy
->max_swap_interval
;
307 if (!_eglValidateConfig(&base
, EGL_FALSE
)) {
308 _eglLog(_EGL_DEBUG
, "DRI2: failed to validate config %d", id
);
312 config_id
= base
.ConfigID
;
313 base
.ConfigID
= EGL_DONT_CARE
;
314 base
.SurfaceType
= EGL_DONT_CARE
;
315 num_configs
= _eglFilterArray(disp
->Configs
, (void **) &matching_config
, 1,
316 (_EGLArrayForEach
) dri2_match_config
, &base
);
318 if (num_configs
== 1) {
319 conf
= (struct dri2_egl_config
*) matching_config
;
321 if (!conf
->dri_config
[double_buffer
][srgb
])
322 conf
->dri_config
[double_buffer
][srgb
] = dri_config
;
324 /* a similar config type is already added (unlikely) => discard */
327 else if (num_configs
== 0) {
328 conf
= calloc(1, sizeof *conf
);
332 conf
->dri_config
[double_buffer
][srgb
] = dri_config
;
334 memcpy(&conf
->base
, &base
, sizeof base
);
335 conf
->base
.SurfaceType
= 0;
336 conf
->base
.ConfigID
= config_id
;
338 _eglLinkConfig(&conf
->base
);
346 surface_type
&= ~EGL_PIXMAP_BIT
;
349 /* No support for pbuffer + MSAA for now.
351 * XXX TODO: pbuffer + MSAA does not work and causes crashes.
352 * See QT bugreport: https://bugreports.qt.io/browse/QTBUG-47509
355 surface_type
&= ~EGL_PBUFFER_BIT
;
358 conf
->base
.SurfaceType
|= surface_type
;
364 dri2_lookup_egl_image(__DRIscreen
*screen
, void *image
, void *data
)
366 _EGLDisplay
*disp
= data
;
367 struct dri2_egl_image
*dri2_img
;
372 img
= _eglLookupImage(image
, disp
);
374 _eglError(EGL_BAD_PARAMETER
, "dri2_lookup_egl_image");
378 dri2_img
= dri2_egl_image(image
);
380 return dri2_img
->dri_image
;
383 const __DRIimageLookupExtension image_lookup_extension
= {
384 .base
= { __DRI_IMAGE_LOOKUP
, 1 },
386 .lookupEGLImage
= dri2_lookup_egl_image
389 struct dri2_extension_match
{
395 static const struct dri2_extension_match dri3_driver_extensions
[] = {
396 { __DRI_CORE
, 1, offsetof(struct dri2_egl_display
, core
) },
397 { __DRI_IMAGE_DRIVER
, 1, offsetof(struct dri2_egl_display
, image_driver
) },
401 static const struct dri2_extension_match dri2_driver_extensions
[] = {
402 { __DRI_CORE
, 1, offsetof(struct dri2_egl_display
, core
) },
403 { __DRI_DRI2
, 2, offsetof(struct dri2_egl_display
, dri2
) },
407 static const struct dri2_extension_match dri2_core_extensions
[] = {
408 { __DRI2_FLUSH
, 1, offsetof(struct dri2_egl_display
, flush
) },
409 { __DRI_TEX_BUFFER
, 2, offsetof(struct dri2_egl_display
, tex_buffer
) },
410 { __DRI_IMAGE
, 1, offsetof(struct dri2_egl_display
, image
) },
414 static const struct dri2_extension_match swrast_driver_extensions
[] = {
415 { __DRI_CORE
, 1, offsetof(struct dri2_egl_display
, core
) },
416 { __DRI_SWRAST
, 2, offsetof(struct dri2_egl_display
, swrast
) },
420 static const struct dri2_extension_match swrast_core_extensions
[] = {
421 { __DRI_TEX_BUFFER
, 2, offsetof(struct dri2_egl_display
, tex_buffer
) },
425 static const struct dri2_extension_match optional_core_extensions
[] = {
426 { __DRI2_ROBUSTNESS
, 1, offsetof(struct dri2_egl_display
, robustness
) },
427 { __DRI2_NO_ERROR
, 1, offsetof(struct dri2_egl_display
, no_error
) },
428 { __DRI2_CONFIG_QUERY
, 1, offsetof(struct dri2_egl_display
, config
) },
429 { __DRI2_FENCE
, 1, offsetof(struct dri2_egl_display
, fence
) },
430 { __DRI2_RENDERER_QUERY
, 1, offsetof(struct dri2_egl_display
, rendererQuery
) },
431 { __DRI2_INTEROP
, 1, offsetof(struct dri2_egl_display
, interop
) },
432 { __DRI_IMAGE
, 1, offsetof(struct dri2_egl_display
, image
) },
433 { __DRI2_FLUSH_CONTROL
, 1, offsetof(struct dri2_egl_display
, flush_control
) },
434 { __DRI2_BLOB
, 1, offsetof(struct dri2_egl_display
, blob
) },
439 dri2_bind_extensions(struct dri2_egl_display
*dri2_dpy
,
440 const struct dri2_extension_match
*matches
,
441 const __DRIextension
**extensions
,
447 for (int i
= 0; extensions
[i
]; i
++) {
448 _eglLog(_EGL_DEBUG
, "found extension `%s'", extensions
[i
]->name
);
449 for (int j
= 0; matches
[j
].name
; j
++) {
450 if (strcmp(extensions
[i
]->name
, matches
[j
].name
) == 0 &&
451 extensions
[i
]->version
>= matches
[j
].version
) {
452 field
= ((char *) dri2_dpy
+ matches
[j
].offset
);
453 *(const __DRIextension
**) field
= extensions
[i
];
454 _eglLog(_EGL_INFO
, "found extension %s version %d",
455 extensions
[i
]->name
, extensions
[i
]->version
);
461 for (int j
= 0; matches
[j
].name
; j
++) {
462 field
= ((char *) dri2_dpy
+ matches
[j
].offset
);
463 if (*(const __DRIextension
**) field
== NULL
) {
465 _eglLog(_EGL_DEBUG
, "did not find optional extension %s version %d",
466 matches
[j
].name
, matches
[j
].version
);
468 _eglLog(_EGL_WARNING
, "did not find extension %s version %d",
469 matches
[j
].name
, matches
[j
].version
);
478 static const __DRIextension
**
479 dri2_open_driver(_EGLDisplay
*disp
)
481 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
482 const __DRIextension
**extensions
= NULL
;
483 char path
[PATH_MAX
], *search_paths
, *next
, *end
;
484 char *get_extensions_name
;
485 const __DRIextension
**(*get_extensions
)(void);
488 if (geteuid() == getuid()) {
489 /* don't allow setuid apps to use LIBGL_DRIVERS_PATH */
490 search_paths
= getenv("LIBGL_DRIVERS_PATH");
492 if (search_paths
== NULL
)
493 search_paths
= DEFAULT_DRIVER_DIR
;
495 dri2_dpy
->driver
= NULL
;
496 end
= search_paths
+ strlen(search_paths
);
497 for (char *p
= search_paths
; p
< end
; p
= next
+ 1) {
499 next
= strchr(p
, ':');
505 snprintf(path
, sizeof path
,
506 "%.*s/tls/%s_dri.so", len
, p
, dri2_dpy
->driver_name
);
507 dri2_dpy
->driver
= dlopen(path
, RTLD_NOW
| RTLD_GLOBAL
);
509 if (dri2_dpy
->driver
== NULL
) {
510 snprintf(path
, sizeof path
,
511 "%.*s/%s_dri.so", len
, p
, dri2_dpy
->driver_name
);
512 dri2_dpy
->driver
= dlopen(path
, RTLD_NOW
| RTLD_GLOBAL
);
513 if (dri2_dpy
->driver
== NULL
)
514 _eglLog(_EGL_DEBUG
, "failed to open %s: %s\n", path
, dlerror());
516 /* not need continue to loop all paths once the driver is found */
517 if (dri2_dpy
->driver
!= NULL
)
521 if (dri2_dpy
->driver
== NULL
) {
522 _eglLog(_EGL_WARNING
,
523 "DRI2: failed to open %s (search paths %s)",
524 dri2_dpy
->driver_name
, search_paths
);
528 _eglLog(_EGL_DEBUG
, "DRI2: dlopen(%s)", path
);
530 get_extensions_name
= loader_get_extensions_name(dri2_dpy
->driver_name
);
531 if (get_extensions_name
) {
532 get_extensions
= dlsym(dri2_dpy
->driver
, get_extensions_name
);
533 if (get_extensions
) {
534 extensions
= get_extensions();
536 _eglLog(_EGL_DEBUG
, "driver does not expose %s(): %s\n",
537 get_extensions_name
, dlerror());
539 free(get_extensions_name
);
543 extensions
= dlsym(dri2_dpy
->driver
, __DRI_DRIVER_EXTENSIONS
);
544 if (extensions
== NULL
) {
545 _eglLog(_EGL_WARNING
,
546 "DRI2: driver exports no extensions (%s)", dlerror());
547 dlclose(dri2_dpy
->driver
);
554 dri2_load_driver_dri3(_EGLDisplay
*disp
)
556 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
557 const __DRIextension
**extensions
;
559 extensions
= dri2_open_driver(disp
);
563 if (!dri2_bind_extensions(dri2_dpy
, dri3_driver_extensions
, extensions
, false)) {
564 dlclose(dri2_dpy
->driver
);
567 dri2_dpy
->driver_extensions
= extensions
;
573 dri2_load_driver(_EGLDisplay
*disp
)
575 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
576 const __DRIextension
**extensions
;
578 extensions
= dri2_open_driver(disp
);
582 if (!dri2_bind_extensions(dri2_dpy
, dri2_driver_extensions
, extensions
, false)) {
583 dlclose(dri2_dpy
->driver
);
586 dri2_dpy
->driver_extensions
= extensions
;
592 dri2_load_driver_swrast(_EGLDisplay
*disp
)
594 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
595 const __DRIextension
**extensions
;
597 extensions
= dri2_open_driver(disp
);
601 if (!dri2_bind_extensions(dri2_dpy
, swrast_driver_extensions
, extensions
, false)) {
602 dlclose(dri2_dpy
->driver
);
605 dri2_dpy
->driver_extensions
= extensions
;
611 dri2_renderer_query_integer(struct dri2_egl_display
*dri2_dpy
, int param
)
613 const __DRI2rendererQueryExtension
*rendererQuery
= dri2_dpy
->rendererQuery
;
614 unsigned int value
= 0;
616 if (!rendererQuery
||
617 rendererQuery
->queryInteger(dri2_dpy
->dri_screen
, param
, &value
) == -1)
624 dri2_setup_screen(_EGLDisplay
*disp
)
626 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
627 unsigned int api_mask
;
630 * EGL 1.5 specification defines the default value to 1. Moreover,
631 * eglSwapInterval() is required to clamp requested value to the supported
632 * range. Since the default value is implicitly assumed to be supported,
633 * use it as both minimum and maximum for the platforms that do not allow
634 * changing the interval. Platforms, which allow it (e.g. x11, wayland)
635 * override these values already.
637 dri2_dpy
->min_swap_interval
= 1;
638 dri2_dpy
->max_swap_interval
= 1;
639 dri2_dpy
->default_swap_interval
= 1;
641 if (dri2_dpy
->image_driver
) {
642 api_mask
= dri2_dpy
->image_driver
->getAPIMask(dri2_dpy
->dri_screen
);
643 } else if (dri2_dpy
->dri2
) {
644 api_mask
= dri2_dpy
->dri2
->getAPIMask(dri2_dpy
->dri_screen
);
646 assert(dri2_dpy
->swrast
);
647 api_mask
= 1 << __DRI_API_OPENGL
|
648 1 << __DRI_API_GLES
|
649 1 << __DRI_API_GLES2
|
650 1 << __DRI_API_GLES3
;
653 disp
->ClientAPIs
= 0;
654 if ((api_mask
& (1 <<__DRI_API_OPENGL
)) && _eglIsApiValid(EGL_OPENGL_API
))
655 disp
->ClientAPIs
|= EGL_OPENGL_BIT
;
656 if ((api_mask
& (1 << __DRI_API_GLES
)) && _eglIsApiValid(EGL_OPENGL_ES_API
))
657 disp
->ClientAPIs
|= EGL_OPENGL_ES_BIT
;
658 if ((api_mask
& (1 << __DRI_API_GLES2
)) && _eglIsApiValid(EGL_OPENGL_ES_API
))
659 disp
->ClientAPIs
|= EGL_OPENGL_ES2_BIT
;
660 if ((api_mask
& (1 << __DRI_API_GLES3
)) && _eglIsApiValid(EGL_OPENGL_ES_API
))
661 disp
->ClientAPIs
|= EGL_OPENGL_ES3_BIT_KHR
;
663 assert(dri2_dpy
->image_driver
|| dri2_dpy
->dri2
|| dri2_dpy
->swrast
);
664 disp
->Extensions
.KHR_no_config_context
= EGL_TRUE
;
665 disp
->Extensions
.KHR_surfaceless_context
= EGL_TRUE
;
667 /* Report back to EGL the bitmask of priorities supported */
668 disp
->Extensions
.IMG_context_priority
=
669 dri2_renderer_query_integer(dri2_dpy
,
670 __DRI2_RENDERER_HAS_CONTEXT_PRIORITY
);
672 disp
->Extensions
.EXT_pixel_format_float
= EGL_TRUE
;
674 if (dri2_renderer_query_integer(dri2_dpy
,
675 __DRI2_RENDERER_HAS_FRAMEBUFFER_SRGB
))
676 disp
->Extensions
.KHR_gl_colorspace
= EGL_TRUE
;
678 if (dri2_dpy
->image_driver
||
679 (dri2_dpy
->dri2
&& dri2_dpy
->dri2
->base
.version
>= 3) ||
680 (dri2_dpy
->swrast
&& dri2_dpy
->swrast
->base
.version
>= 3)) {
681 disp
->Extensions
.KHR_create_context
= EGL_TRUE
;
683 if (dri2_dpy
->robustness
)
684 disp
->Extensions
.EXT_create_context_robustness
= EGL_TRUE
;
687 if (dri2_dpy
->no_error
)
688 disp
->Extensions
.KHR_create_context_no_error
= EGL_TRUE
;
690 if (dri2_dpy
->fence
) {
691 disp
->Extensions
.KHR_fence_sync
= EGL_TRUE
;
692 disp
->Extensions
.KHR_wait_sync
= EGL_TRUE
;
693 if (dri2_dpy
->fence
->get_fence_from_cl_event
)
694 disp
->Extensions
.KHR_cl_event2
= EGL_TRUE
;
695 if (dri2_dpy
->fence
->base
.version
>= 2 &&
696 dri2_dpy
->fence
->get_capabilities
) {
697 unsigned capabilities
=
698 dri2_dpy
->fence
->get_capabilities(dri2_dpy
->dri_screen
);
699 disp
->Extensions
.ANDROID_native_fence_sync
=
700 (capabilities
& __DRI_FENCE_CAP_NATIVE_FD
) != 0;
705 disp
->Extensions
.ANDROID_blob_cache
= EGL_TRUE
;
707 disp
->Extensions
.KHR_reusable_sync
= EGL_TRUE
;
709 if (dri2_dpy
->image
) {
710 if (dri2_dpy
->image
->base
.version
>= 10 &&
711 dri2_dpy
->image
->getCapabilities
!= NULL
) {
714 capabilities
= dri2_dpy
->image
->getCapabilities(dri2_dpy
->dri_screen
);
715 disp
->Extensions
.MESA_drm_image
= (capabilities
& __DRI_IMAGE_CAP_GLOBAL_NAMES
) != 0;
717 if (dri2_dpy
->image
->base
.version
>= 11)
718 disp
->Extensions
.MESA_image_dma_buf_export
= EGL_TRUE
;
720 disp
->Extensions
.MESA_drm_image
= EGL_TRUE
;
721 if (dri2_dpy
->image
->base
.version
>= 11)
722 disp
->Extensions
.MESA_image_dma_buf_export
= EGL_TRUE
;
725 disp
->Extensions
.KHR_image_base
= EGL_TRUE
;
726 disp
->Extensions
.KHR_gl_renderbuffer_image
= EGL_TRUE
;
727 if (dri2_dpy
->image
->base
.version
>= 5 &&
728 dri2_dpy
->image
->createImageFromTexture
) {
729 disp
->Extensions
.KHR_gl_texture_2D_image
= EGL_TRUE
;
730 disp
->Extensions
.KHR_gl_texture_cubemap_image
= EGL_TRUE
;
732 if (dri2_renderer_query_integer(dri2_dpy
,
733 __DRI2_RENDERER_HAS_TEXTURE_3D
))
734 disp
->Extensions
.KHR_gl_texture_3D_image
= EGL_TRUE
;
737 if (dri2_dpy
->image
->base
.version
>= 8 &&
738 dri2_dpy
->image
->createImageFromDmaBufs
) {
739 disp
->Extensions
.EXT_image_dma_buf_import
= EGL_TRUE
;
741 if (dri2_dpy
->image
->base
.version
>= 15 &&
742 dri2_dpy
->image
->createImageFromDmaBufs2
&&
743 dri2_dpy
->image
->queryDmaBufFormats
&&
744 dri2_dpy
->image
->queryDmaBufModifiers
) {
745 disp
->Extensions
.EXT_image_dma_buf_import_modifiers
= EGL_TRUE
;
750 if (dri2_dpy
->flush_control
)
751 disp
->Extensions
.KHR_context_flush_control
= EGL_TRUE
;
755 dri2_setup_swap_interval(_EGLDisplay
*disp
, int max_swap_interval
)
757 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
758 GLint vblank_mode
= DRI_CONF_VBLANK_DEF_INTERVAL_1
;
760 /* Allow driconf to override applications.*/
761 if (dri2_dpy
->config
)
762 dri2_dpy
->config
->configQueryi(dri2_dpy
->dri_screen
,
763 "vblank_mode", &vblank_mode
);
764 switch (vblank_mode
) {
765 case DRI_CONF_VBLANK_NEVER
:
766 dri2_dpy
->min_swap_interval
= 0;
767 dri2_dpy
->max_swap_interval
= 0;
768 dri2_dpy
->default_swap_interval
= 0;
770 case DRI_CONF_VBLANK_ALWAYS_SYNC
:
771 dri2_dpy
->min_swap_interval
= 1;
772 dri2_dpy
->max_swap_interval
= max_swap_interval
;
773 dri2_dpy
->default_swap_interval
= 1;
775 case DRI_CONF_VBLANK_DEF_INTERVAL_0
:
776 dri2_dpy
->min_swap_interval
= 0;
777 dri2_dpy
->max_swap_interval
= max_swap_interval
;
778 dri2_dpy
->default_swap_interval
= 0;
781 case DRI_CONF_VBLANK_DEF_INTERVAL_1
:
782 dri2_dpy
->min_swap_interval
= 0;
783 dri2_dpy
->max_swap_interval
= max_swap_interval
;
784 dri2_dpy
->default_swap_interval
= 1;
789 /* All platforms but DRM call this function to create the screen and populate
790 * the driver_configs. DRM inherits that information from its display - GBM.
793 dri2_create_screen(_EGLDisplay
*disp
)
795 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
797 if (dri2_dpy
->image_driver
) {
798 dri2_dpy
->dri_screen
=
799 dri2_dpy
->image_driver
->createNewScreen2(0, dri2_dpy
->fd
,
800 dri2_dpy
->loader_extensions
,
801 dri2_dpy
->driver_extensions
,
802 &dri2_dpy
->driver_configs
,
804 } else if (dri2_dpy
->dri2
) {
805 if (dri2_dpy
->dri2
->base
.version
>= 4) {
806 dri2_dpy
->dri_screen
=
807 dri2_dpy
->dri2
->createNewScreen2(0, dri2_dpy
->fd
,
808 dri2_dpy
->loader_extensions
,
809 dri2_dpy
->driver_extensions
,
810 &dri2_dpy
->driver_configs
, disp
);
812 dri2_dpy
->dri_screen
=
813 dri2_dpy
->dri2
->createNewScreen(0, dri2_dpy
->fd
,
814 dri2_dpy
->loader_extensions
,
815 &dri2_dpy
->driver_configs
, disp
);
818 assert(dri2_dpy
->swrast
);
819 if (dri2_dpy
->swrast
->base
.version
>= 4) {
820 dri2_dpy
->dri_screen
=
821 dri2_dpy
->swrast
->createNewScreen2(0, dri2_dpy
->loader_extensions
,
822 dri2_dpy
->driver_extensions
,
823 &dri2_dpy
->driver_configs
, disp
);
825 dri2_dpy
->dri_screen
=
826 dri2_dpy
->swrast
->createNewScreen(0, dri2_dpy
->loader_extensions
,
827 &dri2_dpy
->driver_configs
, disp
);
831 if (dri2_dpy
->dri_screen
== NULL
) {
832 _eglLog(_EGL_WARNING
, "DRI2: failed to create dri screen");
836 dri2_dpy
->own_dri_screen
= true;
841 dri2_setup_extensions(_EGLDisplay
*disp
)
843 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
844 const struct dri2_extension_match
*mandatory_core_extensions
;
845 const __DRIextension
**extensions
;
847 extensions
= dri2_dpy
->core
->getExtensions(dri2_dpy
->dri_screen
);
849 if (dri2_dpy
->image_driver
|| dri2_dpy
->dri2
)
850 mandatory_core_extensions
= dri2_core_extensions
;
852 mandatory_core_extensions
= swrast_core_extensions
;
854 if (!dri2_bind_extensions(dri2_dpy
, mandatory_core_extensions
, extensions
, false))
857 #ifdef HAVE_DRI3_MODIFIERS
858 dri2_dpy
->multibuffers_available
=
859 (dri2_dpy
->dri3_major_version
> 1 || (dri2_dpy
->dri3_major_version
== 1 &&
860 dri2_dpy
->dri3_minor_version
>= 2)) &&
861 (dri2_dpy
->present_major_version
> 1 || (dri2_dpy
->present_major_version
== 1 &&
862 dri2_dpy
->present_minor_version
>= 2)) &&
863 (dri2_dpy
->image
&& dri2_dpy
->image
->base
.version
>= 15);
866 dri2_bind_extensions(dri2_dpy
, optional_core_extensions
, extensions
, true);
871 * Called via eglInitialize(), GLX_drv->API.Initialize().
873 * This must be guaranteed to be called exactly once, even if eglInitialize is
874 * called many times (without a eglTerminate in between).
877 dri2_initialize(_EGLDriver
*drv
, _EGLDisplay
*disp
)
879 EGLBoolean ret
= EGL_FALSE
;
880 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
882 /* In the case where the application calls eglMakeCurrent(context1),
883 * eglTerminate, then eglInitialize again (without a call to eglReleaseThread
884 * or eglMakeCurrent(NULL) before that), dri2_dpy structure is still
885 * initialized, as we need it to be able to free context1 correctly.
887 * It would probably be safest to forcibly release the display with
888 * dri2_display_release, to make sure the display is reinitialized correctly.
889 * However, the EGL spec states that we need to keep a reference to the
890 * current context (so we cannot call dri2_make_current(NULL)), and therefore
891 * we would leak context1 as we would be missing the old display connection
892 * to free it up correctly.
895 dri2_dpy
->ref_count
++;
899 switch (disp
->Platform
) {
900 case _EGL_PLATFORM_SURFACELESS
:
901 ret
= dri2_initialize_surfaceless(drv
, disp
);
903 case _EGL_PLATFORM_X11
:
904 ret
= dri2_initialize_x11(drv
, disp
);
906 case _EGL_PLATFORM_DRM
:
907 ret
= dri2_initialize_drm(drv
, disp
);
909 case _EGL_PLATFORM_WAYLAND
:
910 ret
= dri2_initialize_wayland(drv
, disp
);
912 case _EGL_PLATFORM_ANDROID
:
913 ret
= dri2_initialize_android(drv
, disp
);
916 unreachable("Callers ensure we cannot get here.");
923 dri2_dpy
= dri2_egl_display(disp
);
924 dri2_dpy
->ref_count
++;
930 * Decrement display reference count, and free up display if necessary.
933 dri2_display_release(_EGLDisplay
*disp
)
935 struct dri2_egl_display
*dri2_dpy
;
940 dri2_dpy
= dri2_egl_display(disp
);
942 assert(dri2_dpy
->ref_count
> 0);
943 dri2_dpy
->ref_count
--;
945 if (dri2_dpy
->ref_count
> 0)
948 _eglCleanupDisplay(disp
);
949 dri2_display_destroy(disp
);
953 dri2_display_destroy(_EGLDisplay
*disp
)
955 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
957 if (dri2_dpy
->own_dri_screen
) {
958 if (dri2_dpy
->vtbl
&& dri2_dpy
->vtbl
->close_screen_notify
)
959 dri2_dpy
->vtbl
->close_screen_notify(disp
);
960 dri2_dpy
->core
->destroyScreen(dri2_dpy
->dri_screen
);
962 if (dri2_dpy
->fd
>= 0)
964 if (dri2_dpy
->driver
)
965 dlclose(dri2_dpy
->driver
);
966 free(dri2_dpy
->driver_name
);
968 #ifdef HAVE_WAYLAND_PLATFORM
969 free(dri2_dpy
->device_name
);
972 switch (disp
->Platform
) {
973 case _EGL_PLATFORM_X11
:
974 dri2_teardown_x11(dri2_dpy
);
976 case _EGL_PLATFORM_DRM
:
977 dri2_teardown_drm(dri2_dpy
);
979 case _EGL_PLATFORM_WAYLAND
:
980 dri2_teardown_wayland(dri2_dpy
);
983 /* TODO: add teardown for other platforms */
987 /* The drm platform does not create the screen/driver_configs but reuses
988 * the ones from the gbm device. As such the gbm itself is responsible
991 if (disp
->Platform
!= _EGL_PLATFORM_DRM
&& dri2_dpy
->driver_configs
) {
992 for (unsigned i
= 0; dri2_dpy
->driver_configs
[i
]; i
++)
993 free((__DRIconfig
*) dri2_dpy
->driver_configs
[i
]);
994 free(dri2_dpy
->driver_configs
);
997 disp
->DriverData
= NULL
;
1001 dri2_egl_surface_alloc_local_buffer(struct dri2_egl_surface
*dri2_surf
,
1002 unsigned int att
, unsigned int format
)
1004 struct dri2_egl_display
*dri2_dpy
=
1005 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
1007 if (att
>= ARRAY_SIZE(dri2_surf
->local_buffers
))
1010 if (!dri2_surf
->local_buffers
[att
]) {
1011 dri2_surf
->local_buffers
[att
] =
1012 dri2_dpy
->dri2
->allocateBuffer(dri2_dpy
->dri_screen
, att
, format
,
1013 dri2_surf
->base
.Width
, dri2_surf
->base
.Height
);
1016 return dri2_surf
->local_buffers
[att
];
1020 dri2_egl_surface_free_local_buffers(struct dri2_egl_surface
*dri2_surf
)
1022 struct dri2_egl_display
*dri2_dpy
=
1023 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
1025 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->local_buffers
); i
++) {
1026 if (dri2_surf
->local_buffers
[i
]) {
1027 dri2_dpy
->dri2
->releaseBuffer(dri2_dpy
->dri_screen
,
1028 dri2_surf
->local_buffers
[i
]);
1029 dri2_surf
->local_buffers
[i
] = NULL
;
1035 * Called via eglTerminate(), drv->API.Terminate().
1037 * This must be guaranteed to be called exactly once, even if eglTerminate is
1038 * called many times (without a eglInitialize in between).
1041 dri2_terminate(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1043 /* Release all non-current Context/Surfaces. */
1044 _eglReleaseDisplayResources(drv
, disp
);
1046 dri2_display_release(disp
);
1052 * Set the error code after a call to
1053 * dri2_egl_display::dri2::createContextAttribs.
1056 dri2_create_context_attribs_error(int dri_error
)
1060 switch (dri_error
) {
1061 case __DRI_CTX_ERROR_SUCCESS
:
1064 case __DRI_CTX_ERROR_NO_MEMORY
:
1065 egl_error
= EGL_BAD_ALLOC
;
1068 /* From the EGL_KHR_create_context spec, section "Errors":
1070 * * If <config> does not support a client API context compatible
1071 * with the requested API major and minor version, [...] context flags,
1072 * and context reset notification behavior (for client API types where
1073 * these attributes are supported), then an EGL_BAD_MATCH error is
1076 * * If an OpenGL ES context is requested and the values for
1077 * attributes EGL_CONTEXT_MAJOR_VERSION_KHR and
1078 * EGL_CONTEXT_MINOR_VERSION_KHR specify an OpenGL ES version that
1079 * is not defined, than an EGL_BAD_MATCH error is generated.
1081 * * If an OpenGL context is requested, the requested version is
1082 * greater than 3.2, and the value for attribute
1083 * EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR has no bits set; has any
1084 * bits set other than EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR and
1085 * EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR; has more than
1086 * one of these bits set; or if the implementation does not support
1087 * the requested profile, then an EGL_BAD_MATCH error is generated.
1089 case __DRI_CTX_ERROR_BAD_API
:
1090 case __DRI_CTX_ERROR_BAD_VERSION
:
1091 case __DRI_CTX_ERROR_BAD_FLAG
:
1092 egl_error
= EGL_BAD_MATCH
;
1095 /* From the EGL_KHR_create_context spec, section "Errors":
1097 * * If an attribute name or attribute value in <attrib_list> is not
1098 * recognized (including unrecognized bits in bitmask attributes),
1099 * then an EGL_BAD_ATTRIBUTE error is generated."
1101 case __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE
:
1102 case __DRI_CTX_ERROR_UNKNOWN_FLAG
:
1103 egl_error
= EGL_BAD_ATTRIBUTE
;
1108 egl_error
= EGL_BAD_MATCH
;
1112 _eglError(egl_error
, "dri2_create_context");
1116 dri2_fill_context_attribs(struct dri2_egl_context
*dri2_ctx
,
1117 struct dri2_egl_display
*dri2_dpy
,
1118 uint32_t *ctx_attribs
,
1119 unsigned *num_attribs
)
1123 assert(*num_attribs
>= NUM_ATTRIBS
);
1125 ctx_attribs
[pos
++] = __DRI_CTX_ATTRIB_MAJOR_VERSION
;
1126 ctx_attribs
[pos
++] = dri2_ctx
->base
.ClientMajorVersion
;
1127 ctx_attribs
[pos
++] = __DRI_CTX_ATTRIB_MINOR_VERSION
;
1128 ctx_attribs
[pos
++] = dri2_ctx
->base
.ClientMinorVersion
;
1130 if (dri2_ctx
->base
.Flags
!= 0 || dri2_ctx
->base
.NoError
) {
1131 /* If the implementation doesn't support the __DRI2_ROBUSTNESS
1132 * extension, don't even try to send it the robust-access flag.
1133 * It may explode. Instead, generate the required EGL error here.
1135 if ((dri2_ctx
->base
.Flags
& EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR
) != 0
1136 && !dri2_dpy
->robustness
) {
1137 _eglError(EGL_BAD_MATCH
, "eglCreateContext");
1141 ctx_attribs
[pos
++] = __DRI_CTX_ATTRIB_FLAGS
;
1142 ctx_attribs
[pos
++] = dri2_ctx
->base
.Flags
|
1143 (dri2_ctx
->base
.NoError
? __DRI_CTX_FLAG_NO_ERROR
: 0);
1146 if (dri2_ctx
->base
.ResetNotificationStrategy
!= EGL_NO_RESET_NOTIFICATION_KHR
) {
1147 /* If the implementation doesn't support the __DRI2_ROBUSTNESS
1148 * extension, don't even try to send it a reset strategy. It may
1149 * explode. Instead, generate the required EGL error here.
1151 if (!dri2_dpy
->robustness
) {
1152 _eglError(EGL_BAD_CONFIG
, "eglCreateContext");
1156 ctx_attribs
[pos
++] = __DRI_CTX_ATTRIB_RESET_STRATEGY
;
1157 ctx_attribs
[pos
++] = __DRI_CTX_RESET_LOSE_CONTEXT
;
1160 if (dri2_ctx
->base
.ContextPriority
!= EGL_CONTEXT_PRIORITY_MEDIUM_IMG
) {
1163 switch (dri2_ctx
->base
.ContextPriority
) {
1164 case EGL_CONTEXT_PRIORITY_HIGH_IMG
:
1165 val
= __DRI_CTX_PRIORITY_HIGH
;
1167 case EGL_CONTEXT_PRIORITY_MEDIUM_IMG
:
1168 val
= __DRI_CTX_PRIORITY_MEDIUM
;
1170 case EGL_CONTEXT_PRIORITY_LOW_IMG
:
1171 val
= __DRI_CTX_PRIORITY_LOW
;
1174 _eglError(EGL_BAD_CONFIG
, "eglCreateContext");
1178 ctx_attribs
[pos
++] = __DRI_CTX_ATTRIB_PRIORITY
;
1179 ctx_attribs
[pos
++] = val
;
1182 if (dri2_ctx
->base
.ReleaseBehavior
== EGL_CONTEXT_RELEASE_BEHAVIOR_NONE_KHR
) {
1183 ctx_attribs
[pos
++] = __DRI_CTX_ATTRIB_RELEASE_BEHAVIOR
;
1184 ctx_attribs
[pos
++] = __DRI_CTX_RELEASE_BEHAVIOR_NONE
;
1193 * Called via eglCreateContext(), drv->API.CreateContext().
1195 static _EGLContext
*
1196 dri2_create_context(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLConfig
*conf
,
1197 _EGLContext
*share_list
, const EGLint
*attrib_list
)
1199 struct dri2_egl_context
*dri2_ctx
;
1200 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1201 struct dri2_egl_context
*dri2_ctx_shared
= dri2_egl_context(share_list
);
1202 __DRIcontext
*shared
=
1203 dri2_ctx_shared
? dri2_ctx_shared
->dri_context
: NULL
;
1204 struct dri2_egl_config
*dri2_config
= dri2_egl_config(conf
);
1205 const __DRIconfig
*dri_config
;
1208 unsigned num_attribs
= NUM_ATTRIBS
;
1209 uint32_t ctx_attribs
[NUM_ATTRIBS
];
1213 dri2_ctx
= malloc(sizeof *dri2_ctx
);
1215 _eglError(EGL_BAD_ALLOC
, "eglCreateContext");
1219 if (!_eglInitContext(&dri2_ctx
->base
, disp
, conf
, attrib_list
))
1222 /* The EGL_EXT_create_context_robustness spec says:
1224 * "Add to the eglCreateContext context creation errors: [...]
1226 * * If the reset notification behavior of <share_context> and the
1227 * newly created context are different then an EGL_BAD_MATCH error is
1230 if (share_list
&& share_list
->ResetNotificationStrategy
!=
1231 dri2_ctx
->base
.ResetNotificationStrategy
) {
1232 _eglError(EGL_BAD_MATCH
, "eglCreateContext");
1236 /* The EGL_KHR_create_context_no_error spec says:
1238 * "BAD_MATCH is generated if the value of EGL_CONTEXT_OPENGL_NO_ERROR_KHR
1239 * used to create <share_context> does not match the value of
1240 * EGL_CONTEXT_OPENGL_NO_ERROR_KHR for the context being created."
1242 if (share_list
&& share_list
->NoError
!= dri2_ctx
->base
.NoError
) {
1243 _eglError(EGL_BAD_MATCH
, "eglCreateContext");
1247 switch (dri2_ctx
->base
.ClientAPI
) {
1248 case EGL_OPENGL_ES_API
:
1249 switch (dri2_ctx
->base
.ClientMajorVersion
) {
1251 api
= __DRI_API_GLES
;
1254 api
= __DRI_API_GLES2
;
1257 api
= __DRI_API_GLES3
;
1260 _eglError(EGL_BAD_PARAMETER
, "eglCreateContext");
1265 case EGL_OPENGL_API
:
1266 if ((dri2_ctx
->base
.ClientMajorVersion
>= 4
1267 || (dri2_ctx
->base
.ClientMajorVersion
== 3
1268 && dri2_ctx
->base
.ClientMinorVersion
>= 2))
1269 && dri2_ctx
->base
.Profile
== EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR
)
1270 api
= __DRI_API_OPENGL_CORE
;
1272 api
= __DRI_API_OPENGL
;
1275 _eglError(EGL_BAD_PARAMETER
, "eglCreateContext");
1281 /* The config chosen here isn't necessarily
1282 * used for surfaces later.
1283 * A pixmap surface will use the single config.
1284 * This opportunity depends on disabling the
1285 * doubleBufferMode check in
1286 * src/mesa/main/context.c:check_compatible()
1288 if (dri2_config
->dri_config
[1][0])
1289 dri_config
= dri2_config
->dri_config
[1][0];
1291 dri_config
= dri2_config
->dri_config
[0][0];
1293 /* EGL_WINDOW_BIT is set only when there is a double-buffered dri_config.
1294 * This makes sure the back buffer will always be used.
1296 if (conf
->SurfaceType
& EGL_WINDOW_BIT
)
1297 dri2_ctx
->base
.WindowRenderBuffer
= EGL_BACK_BUFFER
;
1302 if (!dri2_fill_context_attribs(dri2_ctx
, dri2_dpy
, ctx_attribs
,
1306 if (dri2_dpy
->image_driver
) {
1307 dri2_ctx
->dri_context
=
1308 dri2_dpy
->image_driver
->createContextAttribs(dri2_dpy
->dri_screen
,
1316 dri2_create_context_attribs_error(error
);
1317 } else if (dri2_dpy
->dri2
) {
1318 if (dri2_dpy
->dri2
->base
.version
>= 3) {
1319 dri2_ctx
->dri_context
=
1320 dri2_dpy
->dri2
->createContextAttribs(dri2_dpy
->dri_screen
,
1328 dri2_create_context_attribs_error(error
);
1330 dri2_ctx
->dri_context
=
1331 dri2_dpy
->dri2
->createNewContextForAPI(dri2_dpy
->dri_screen
,
1338 assert(dri2_dpy
->swrast
);
1339 if (dri2_dpy
->swrast
->base
.version
>= 3) {
1340 dri2_ctx
->dri_context
=
1341 dri2_dpy
->swrast
->createContextAttribs(dri2_dpy
->dri_screen
,
1349 dri2_create_context_attribs_error(error
);
1351 dri2_ctx
->dri_context
=
1352 dri2_dpy
->swrast
->createNewContextForAPI(dri2_dpy
->dri_screen
,
1360 if (!dri2_ctx
->dri_context
)
1363 return &dri2_ctx
->base
;
1371 * Called via eglDestroyContext(), drv->API.DestroyContext().
1374 dri2_destroy_context(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLContext
*ctx
)
1376 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
1377 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1379 if (_eglPutContext(ctx
)) {
1380 dri2_dpy
->core
->destroyContext(dri2_ctx
->dri_context
);
1388 dri2_init_surface(_EGLSurface
*surf
, _EGLDisplay
*dpy
, EGLint type
,
1389 _EGLConfig
*conf
, const EGLint
*attrib_list
, EGLBoolean enable_out_fence
)
1391 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
1392 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1394 dri2_surf
->out_fence_fd
= -1;
1395 dri2_surf
->enable_out_fence
= false;
1396 if (dri2_dpy
->fence
&& dri2_dpy
->fence
->base
.version
>= 2 &&
1397 dri2_dpy
->fence
->get_capabilities
&&
1398 (dri2_dpy
->fence
->get_capabilities(dri2_dpy
->dri_screen
) &
1399 __DRI_FENCE_CAP_NATIVE_FD
)) {
1400 dri2_surf
->enable_out_fence
= enable_out_fence
;
1403 return _eglInitSurface(surf
, dpy
, type
, conf
, attrib_list
);
1407 dri2_surface_set_out_fence_fd( _EGLSurface
*surf
, int fence_fd
)
1409 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
1411 if (dri2_surf
->out_fence_fd
>= 0)
1412 close(dri2_surf
->out_fence_fd
);
1414 dri2_surf
->out_fence_fd
= fence_fd
;
1418 dri2_fini_surface(_EGLSurface
*surf
)
1420 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
1422 dri2_surface_set_out_fence_fd(surf
, -1);
1423 dri2_surf
->enable_out_fence
= false;
1427 dri2_destroy_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
)
1429 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1431 if (!_eglPutSurface(surf
))
1434 return dri2_dpy
->vtbl
->destroy_surface(drv
, dpy
, surf
);
1438 dri2_surf_update_fence_fd(_EGLContext
*ctx
,
1439 _EGLDisplay
*dpy
, _EGLSurface
*surf
)
1441 __DRIcontext
*dri_ctx
= dri2_egl_context(ctx
)->dri_context
;
1442 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1443 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
1447 if (!dri2_surf
->enable_out_fence
)
1450 fence
= dri2_dpy
->fence
->create_fence_fd(dri_ctx
, -1);
1452 fence_fd
= dri2_dpy
->fence
->get_fence_fd(dri2_dpy
->dri_screen
,
1454 dri2_dpy
->fence
->destroy_fence(dri2_dpy
->dri_screen
, fence
);
1456 dri2_surface_set_out_fence_fd(surf
, fence_fd
);
1460 * Called via eglMakeCurrent(), drv->API.MakeCurrent().
1463 dri2_make_current(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*dsurf
,
1464 _EGLSurface
*rsurf
, _EGLContext
*ctx
)
1466 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1467 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
1468 _EGLContext
*old_ctx
;
1469 _EGLSurface
*old_dsurf
, *old_rsurf
;
1470 _EGLSurface
*tmp_dsurf
, *tmp_rsurf
;
1471 __DRIdrawable
*ddraw
, *rdraw
;
1476 return _eglError(EGL_NOT_INITIALIZED
, "eglMakeCurrent");
1478 /* make new bindings */
1479 if (!_eglBindContext(ctx
, dsurf
, rsurf
, &old_ctx
, &old_dsurf
, &old_rsurf
)) {
1480 /* _eglBindContext already sets the EGL error (in _eglCheckMakeCurrent) */
1484 /* flush before context switch */
1488 ddraw
= (dsurf
) ? dri2_dpy
->vtbl
->get_dri_drawable(dsurf
) : NULL
;
1489 rdraw
= (rsurf
) ? dri2_dpy
->vtbl
->get_dri_drawable(rsurf
) : NULL
;
1490 cctx
= (dri2_ctx
) ? dri2_ctx
->dri_context
: NULL
;
1493 __DRIcontext
*old_cctx
= dri2_egl_context(old_ctx
)->dri_context
;
1496 dri2_surf_update_fence_fd(old_ctx
, disp
, old_dsurf
);
1497 dri2_dpy
->core
->unbindContext(old_cctx
);
1500 unbind
= (cctx
== NULL
&& ddraw
== NULL
&& rdraw
== NULL
);
1502 if (unbind
|| dri2_dpy
->core
->bindContext(cctx
, ddraw
, rdraw
)) {
1503 dri2_destroy_surface(drv
, disp
, old_dsurf
);
1504 dri2_destroy_surface(drv
, disp
, old_rsurf
);
1507 dri2_dpy
->ref_count
++;
1509 EGLDisplay old_disp
= _eglGetDisplayHandle(old_ctx
->Resource
.Display
);
1510 dri2_destroy_context(drv
, disp
, old_ctx
);
1511 dri2_display_release(old_disp
);
1516 /* undo the previous _eglBindContext */
1517 _eglBindContext(old_ctx
, old_dsurf
, old_rsurf
, &ctx
, &tmp_dsurf
, &tmp_rsurf
);
1518 assert(&dri2_ctx
->base
== ctx
&&
1519 tmp_dsurf
== dsurf
&&
1520 tmp_rsurf
== rsurf
);
1522 _eglPutSurface(dsurf
);
1523 _eglPutSurface(rsurf
);
1524 _eglPutContext(ctx
);
1526 _eglPutSurface(old_dsurf
);
1527 _eglPutSurface(old_rsurf
);
1528 _eglPutContext(old_ctx
);
1530 /* dri2_dpy->core->bindContext failed. We cannot tell for sure why, but
1531 * setting the error to EGL_BAD_MATCH is surely better than leaving it
1534 return _eglError(EGL_BAD_MATCH
, "eglMakeCurrent");
1539 dri2_surface_get_dri_drawable(_EGLSurface
*surf
)
1541 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
1543 return dri2_surf
->dri_drawable
;
1547 * Called from eglGetProcAddress() via drv->API.GetProcAddress().
1550 dri2_get_proc_address(_EGLDriver
*drv
, const char *procname
)
1552 return _glapi_get_proc_address(procname
);
1556 dri2_create_window_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
1557 _EGLConfig
*conf
, void *native_window
,
1558 const EGLint
*attrib_list
)
1560 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1561 return dri2_dpy
->vtbl
->create_window_surface(drv
, dpy
, conf
, native_window
,
1566 dri2_create_pixmap_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
1567 _EGLConfig
*conf
, void *native_pixmap
,
1568 const EGLint
*attrib_list
)
1570 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1571 return dri2_dpy
->vtbl
->create_pixmap_surface(drv
, dpy
, conf
, native_pixmap
,
1576 dri2_create_pbuffer_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
1577 _EGLConfig
*conf
, const EGLint
*attrib_list
)
1579 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1580 return dri2_dpy
->vtbl
->create_pbuffer_surface(drv
, dpy
, conf
, attrib_list
);
1584 dri2_swap_interval(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
1587 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1588 if (!dri2_dpy
->vtbl
->swap_interval
)
1590 return dri2_dpy
->vtbl
->swap_interval(drv
, dpy
, surf
, interval
);
1594 * Asks the client API to flush any rendering to the drawable so that we can
1595 * do our swapbuffers.
1598 dri2_flush_drawable_for_swapbuffers(_EGLDisplay
*disp
, _EGLSurface
*draw
)
1600 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1601 __DRIdrawable
*dri_drawable
= dri2_dpy
->vtbl
->get_dri_drawable(draw
);
1603 if (dri2_dpy
->flush
) {
1604 if (dri2_dpy
->flush
->base
.version
>= 4) {
1605 /* We know there's a current context because:
1607 * "If surface is not bound to the calling thread’s current
1608 * context, an EGL_BAD_SURFACE error is generated."
1610 _EGLContext
*ctx
= _eglGetCurrentContext();
1611 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
1613 /* From the EGL 1.4 spec (page 52):
1615 * "The contents of ancillary buffers are always undefined
1616 * after calling eglSwapBuffers."
1618 dri2_dpy
->flush
->flush_with_flags(dri2_ctx
->dri_context
,
1620 __DRI2_FLUSH_DRAWABLE
|
1621 __DRI2_FLUSH_INVALIDATE_ANCILLARY
,
1622 __DRI2_THROTTLE_SWAPBUFFER
);
1624 dri2_dpy
->flush
->flush(dri_drawable
);
1630 dri2_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
)
1632 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1633 _EGLContext
*ctx
= _eglGetCurrentContext();
1636 dri2_surf_update_fence_fd(ctx
, dpy
, surf
);
1637 return dri2_dpy
->vtbl
->swap_buffers(drv
, dpy
, surf
);
1641 dri2_swap_buffers_with_damage(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
1643 const EGLint
*rects
, EGLint n_rects
)
1645 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1646 _EGLContext
*ctx
= _eglGetCurrentContext();
1649 dri2_surf_update_fence_fd(ctx
, dpy
, surf
);
1650 return dri2_dpy
->vtbl
->swap_buffers_with_damage(drv
, dpy
, surf
,
1655 dri2_swap_buffers_region(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
1656 EGLint numRects
, const EGLint
*rects
)
1658 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1659 return dri2_dpy
->vtbl
->swap_buffers_region(drv
, dpy
, surf
, numRects
, rects
);
1663 dri2_set_damage_region(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
1664 EGLint
*rects
, EGLint n_rects
)
1666 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1667 return dri2_dpy
->vtbl
->set_damage_region(drv
, dpy
, surf
, rects
, n_rects
);
1671 dri2_post_sub_buffer(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
1672 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
1674 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1675 return dri2_dpy
->vtbl
->post_sub_buffer(drv
, dpy
, surf
, x
, y
, width
, height
);
1679 dri2_copy_buffers(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
1680 void *native_pixmap_target
)
1682 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1683 return dri2_dpy
->vtbl
->copy_buffers(drv
, dpy
, surf
, native_pixmap_target
);
1687 dri2_query_buffer_age(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
)
1689 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1690 return dri2_dpy
->vtbl
->query_buffer_age(drv
, dpy
, surf
);
1694 dri2_wait_client(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLContext
*ctx
)
1696 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1697 _EGLSurface
*surf
= ctx
->DrawSurface
;
1698 __DRIdrawable
*dri_drawable
= dri2_dpy
->vtbl
->get_dri_drawable(surf
);
1702 /* FIXME: If EGL allows frontbuffer rendering for window surfaces,
1703 * we need to copy fake to real here.*/
1705 if (dri2_dpy
->flush
!= NULL
)
1706 dri2_dpy
->flush
->flush(dri_drawable
);
1712 dri2_wait_native(_EGLDriver
*drv
, _EGLDisplay
*disp
, EGLint engine
)
1717 if (engine
!= EGL_CORE_NATIVE_ENGINE
)
1718 return _eglError(EGL_BAD_PARAMETER
, "eglWaitNative");
1725 dri2_bind_tex_image(_EGLDriver
*drv
,
1726 _EGLDisplay
*disp
, _EGLSurface
*surf
, EGLint buffer
)
1728 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1729 struct dri2_egl_context
*dri2_ctx
;
1731 GLint format
, target
;
1732 __DRIdrawable
*dri_drawable
= dri2_dpy
->vtbl
->get_dri_drawable(surf
);
1734 ctx
= _eglGetCurrentContext();
1735 dri2_ctx
= dri2_egl_context(ctx
);
1737 if (!_eglBindTexImage(drv
, disp
, surf
, buffer
))
1740 switch (surf
->TextureFormat
) {
1741 case EGL_TEXTURE_RGB
:
1742 format
= __DRI_TEXTURE_FORMAT_RGB
;
1744 case EGL_TEXTURE_RGBA
:
1745 format
= __DRI_TEXTURE_FORMAT_RGBA
;
1748 assert(!"Unexpected texture format in dri2_bind_tex_image()");
1749 format
= __DRI_TEXTURE_FORMAT_RGBA
;
1752 switch (surf
->TextureTarget
) {
1753 case EGL_TEXTURE_2D
:
1754 target
= GL_TEXTURE_2D
;
1757 target
= GL_TEXTURE_2D
;
1758 assert(!"Unexpected texture target in dri2_bind_tex_image()");
1761 dri2_dpy
->tex_buffer
->setTexBuffer2(dri2_ctx
->dri_context
,
1769 dri2_release_tex_image(_EGLDriver
*drv
,
1770 _EGLDisplay
*disp
, _EGLSurface
*surf
, EGLint buffer
)
1772 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1773 struct dri2_egl_context
*dri2_ctx
;
1776 __DRIdrawable
*dri_drawable
= dri2_dpy
->vtbl
->get_dri_drawable(surf
);
1778 ctx
= _eglGetCurrentContext();
1779 dri2_ctx
= dri2_egl_context(ctx
);
1781 if (!_eglReleaseTexImage(drv
, disp
, surf
, buffer
))
1784 switch (surf
->TextureTarget
) {
1785 case EGL_TEXTURE_2D
:
1786 target
= GL_TEXTURE_2D
;
1792 if (dri2_dpy
->tex_buffer
->base
.version
>= 3 &&
1793 dri2_dpy
->tex_buffer
->releaseTexBuffer
!= NULL
) {
1794 dri2_dpy
->tex_buffer
->releaseTexBuffer(dri2_ctx
->dri_context
,
1795 target
, dri_drawable
);
1802 dri2_create_image(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLContext
*ctx
,
1803 EGLenum target
, EGLClientBuffer buffer
,
1804 const EGLint
*attr_list
)
1806 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1807 return dri2_dpy
->vtbl
->create_image(drv
, dpy
, ctx
, target
, buffer
,
1812 dri2_create_image_from_dri(_EGLDisplay
*disp
, __DRIimage
*dri_image
)
1814 struct dri2_egl_image
*dri2_img
;
1816 if (dri_image
== NULL
) {
1817 _eglError(EGL_BAD_ALLOC
, "dri2_create_image");
1821 dri2_img
= malloc(sizeof *dri2_img
);
1823 _eglError(EGL_BAD_ALLOC
, "dri2_create_image");
1827 _eglInitImage(&dri2_img
->base
, disp
);
1829 dri2_img
->dri_image
= dri_image
;
1831 return &dri2_img
->base
;
1835 * Translate a DRI Image extension error code into an EGL error code.
1838 egl_error_from_dri_image_error(int dri_error
)
1840 switch (dri_error
) {
1841 case __DRI_IMAGE_ERROR_SUCCESS
:
1843 case __DRI_IMAGE_ERROR_BAD_ALLOC
:
1844 return EGL_BAD_ALLOC
;
1845 case __DRI_IMAGE_ERROR_BAD_MATCH
:
1846 return EGL_BAD_MATCH
;
1847 case __DRI_IMAGE_ERROR_BAD_PARAMETER
:
1848 return EGL_BAD_PARAMETER
;
1849 case __DRI_IMAGE_ERROR_BAD_ACCESS
:
1850 return EGL_BAD_ACCESS
;
1853 return EGL_BAD_ALLOC
;
1858 dri2_create_image_khr_renderbuffer(_EGLDisplay
*disp
, _EGLContext
*ctx
,
1859 EGLClientBuffer buffer
,
1860 const EGLint
*attr_list
)
1862 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1863 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
1864 GLuint renderbuffer
= (GLuint
) (uintptr_t) buffer
;
1865 __DRIimage
*dri_image
;
1867 if (renderbuffer
== 0) {
1868 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
1869 return EGL_NO_IMAGE_KHR
;
1872 if (!disp
->Extensions
.KHR_gl_renderbuffer_image
) {
1873 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
1874 return EGL_NO_IMAGE_KHR
;
1877 if (dri2_dpy
->image
->base
.version
>= 17 &&
1878 dri2_dpy
->image
->createImageFromRenderbuffer2
) {
1879 unsigned error
= ~0;
1881 dri_image
= dri2_dpy
->image
->createImageFromRenderbuffer2(
1882 dri2_ctx
->dri_context
, renderbuffer
, NULL
, &error
);
1884 assert(!!dri_image
== (error
== __DRI_IMAGE_ERROR_SUCCESS
));
1887 _eglError(egl_error_from_dri_image_error(error
), "dri2_create_image_khr");
1888 return EGL_NO_IMAGE_KHR
;
1891 dri_image
= dri2_dpy
->image
->createImageFromRenderbuffer(
1892 dri2_ctx
->dri_context
, renderbuffer
, NULL
);
1894 _eglError(EGL_BAD_ALLOC
, "dri2_create_image_khr");
1895 return EGL_NO_IMAGE_KHR
;
1899 return dri2_create_image_from_dri(disp
, dri_image
);
1902 #ifdef HAVE_WAYLAND_PLATFORM
1904 /* This structure describes how a wl_buffer maps to one or more
1905 * __DRIimages. A wl_drm_buffer stores the wl_drm format code and the
1906 * offsets and strides of the planes in the buffer. This table maps a
1907 * wl_drm format code to a description of the planes in the buffer
1908 * that lets us create a __DRIimage for each of the planes. */
1910 static const struct wl_drm_components_descriptor
{
1911 uint32_t dri_components
;
1914 } wl_drm_components
[] = {
1915 { __DRI_IMAGE_COMPONENTS_RGB
, EGL_TEXTURE_RGB
, 1 },
1916 { __DRI_IMAGE_COMPONENTS_RGBA
, EGL_TEXTURE_RGBA
, 1 },
1917 { __DRI_IMAGE_COMPONENTS_Y_U_V
, EGL_TEXTURE_Y_U_V_WL
, 3 },
1918 { __DRI_IMAGE_COMPONENTS_Y_UV
, EGL_TEXTURE_Y_UV_WL
, 2 },
1919 { __DRI_IMAGE_COMPONENTS_Y_XUXV
, EGL_TEXTURE_Y_XUXV_WL
, 2 },
1923 dri2_create_image_wayland_wl_buffer(_EGLDisplay
*disp
, _EGLContext
*ctx
,
1924 EGLClientBuffer _buffer
,
1925 const EGLint
*attr_list
)
1927 struct wl_drm_buffer
*buffer
;
1928 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1929 const struct wl_drm_components_descriptor
*f
;
1930 __DRIimage
*dri_image
;
1931 _EGLImageAttribs attrs
;
1934 buffer
= wayland_drm_buffer_get(dri2_dpy
->wl_server_drm
,
1935 (struct wl_resource
*) _buffer
);
1939 if (!_eglParseImageAttribList(&attrs
, disp
, attr_list
))
1942 plane
= attrs
.PlaneWL
;
1943 f
= buffer
->driver_format
;
1944 if (plane
< 0 || plane
>= f
->nplanes
) {
1945 _eglError(EGL_BAD_PARAMETER
,
1946 "dri2_create_image_wayland_wl_buffer (plane out of bounds)");
1950 dri_image
= dri2_dpy
->image
->fromPlanar(buffer
->driver_buffer
, plane
, NULL
);
1951 if (dri_image
== NULL
&& plane
== 0)
1952 dri_image
= dri2_dpy
->image
->dupImage(buffer
->driver_buffer
, NULL
);
1953 if (dri_image
== NULL
) {
1954 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_wayland_wl_buffer");
1958 return dri2_create_image_from_dri(disp
, dri_image
);
1963 dri2_get_sync_values_chromium(_EGLDisplay
*dpy
, _EGLSurface
*surf
,
1964 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
1967 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1968 return dri2_dpy
->vtbl
->get_sync_values(dpy
, surf
, ust
, msc
, sbc
);
1972 * Set the error code after a call to
1973 * dri2_egl_image::dri_image::createImageFromTexture.
1976 dri2_create_image_khr_texture_error(int dri_error
)
1978 EGLint egl_error
= egl_error_from_dri_image_error(dri_error
);
1980 if (egl_error
!= EGL_SUCCESS
)
1981 _eglError(egl_error
, "dri2_create_image_khr_texture");
1985 dri2_create_image_khr_texture(_EGLDisplay
*disp
, _EGLContext
*ctx
,
1987 EGLClientBuffer buffer
,
1988 const EGLint
*attr_list
)
1990 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1991 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
1992 struct dri2_egl_image
*dri2_img
;
1993 GLuint texture
= (GLuint
) (uintptr_t) buffer
;
1994 _EGLImageAttribs attrs
;
2000 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
2001 return EGL_NO_IMAGE_KHR
;
2004 if (!_eglParseImageAttribList(&attrs
, disp
, attr_list
))
2005 return EGL_NO_IMAGE_KHR
;
2008 case EGL_GL_TEXTURE_2D_KHR
:
2009 if (!disp
->Extensions
.KHR_gl_texture_2D_image
) {
2010 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
2011 return EGL_NO_IMAGE_KHR
;
2014 gl_target
= GL_TEXTURE_2D
;
2016 case EGL_GL_TEXTURE_3D_KHR
:
2017 if (!disp
->Extensions
.KHR_gl_texture_3D_image
) {
2018 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
2019 return EGL_NO_IMAGE_KHR
;
2022 depth
= attrs
.GLTextureZOffset
;
2023 gl_target
= GL_TEXTURE_3D
;
2025 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR
:
2026 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR
:
2027 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR
:
2028 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR
:
2029 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR
:
2030 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR
:
2031 if (!disp
->Extensions
.KHR_gl_texture_cubemap_image
) {
2032 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
2033 return EGL_NO_IMAGE_KHR
;
2036 depth
= target
- EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR
;
2037 gl_target
= GL_TEXTURE_CUBE_MAP
;
2040 unreachable("Unexpected target in dri2_create_image_khr_texture()");
2041 return EGL_NO_IMAGE_KHR
;
2044 dri2_img
= malloc(sizeof *dri2_img
);
2046 _eglError(EGL_BAD_ALLOC
, "dri2_create_image_khr");
2047 return EGL_NO_IMAGE_KHR
;
2050 _eglInitImage(&dri2_img
->base
, disp
);
2052 dri2_img
->dri_image
=
2053 dri2_dpy
->image
->createImageFromTexture(dri2_ctx
->dri_context
,
2057 attrs
.GLTextureLevel
,
2060 dri2_create_image_khr_texture_error(error
);
2062 if (!dri2_img
->dri_image
) {
2064 return EGL_NO_IMAGE_KHR
;
2066 return &dri2_img
->base
;
2070 dri2_query_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
2071 EGLint attribute
, EGLint
*value
)
2073 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
2074 if (!dri2_dpy
->vtbl
->query_surface
)
2075 return _eglQuerySurface(drv
, dpy
, surf
, attribute
, value
);
2076 return dri2_dpy
->vtbl
->query_surface(drv
, dpy
, surf
, attribute
, value
);
2079 static struct wl_buffer
*
2080 dri2_create_wayland_buffer_from_image(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
2083 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
2084 return dri2_dpy
->vtbl
->create_wayland_buffer_from_image(drv
, dpy
, img
);
2089 dri2_create_image_mesa_drm_buffer(_EGLDisplay
*disp
, _EGLContext
*ctx
,
2090 EGLClientBuffer buffer
, const EGLint
*attr_list
)
2092 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2093 EGLint format
, name
, pitch
;
2094 _EGLImageAttribs attrs
;
2095 __DRIimage
*dri_image
;
2097 name
= (EGLint
) (uintptr_t) buffer
;
2099 if (!_eglParseImageAttribList(&attrs
, disp
, attr_list
))
2102 if (attrs
.Width
<= 0 || attrs
.Height
<= 0 ||
2103 attrs
.DRMBufferStrideMESA
<= 0) {
2104 _eglError(EGL_BAD_PARAMETER
,
2105 "bad width, height or stride");
2109 switch (attrs
.DRMBufferFormatMESA
) {
2110 case EGL_DRM_BUFFER_FORMAT_ARGB32_MESA
:
2111 format
= __DRI_IMAGE_FORMAT_ARGB8888
;
2112 pitch
= attrs
.DRMBufferStrideMESA
;
2115 _eglError(EGL_BAD_PARAMETER
,
2116 "dri2_create_image_khr: unsupported pixmap depth");
2121 dri2_dpy
->image
->createImageFromName(dri2_dpy
->dri_screen
,
2129 return dri2_create_image_from_dri(disp
, dri_image
);
2133 dri2_check_dma_buf_attribs(const _EGLImageAttribs
*attrs
)
2138 * "Required attributes and their values are as follows:
2140 * * EGL_WIDTH & EGL_HEIGHT: The logical dimensions of the buffer in pixels
2142 * * EGL_LINUX_DRM_FOURCC_EXT: The pixel format of the buffer, as specified
2143 * by drm_fourcc.h and used as the pixel_format parameter of the
2144 * drm_mode_fb_cmd2 ioctl."
2148 * "* If <target> is EGL_LINUX_DMA_BUF_EXT, and the list of attributes is
2149 * incomplete, EGL_BAD_PARAMETER is generated."
2151 if (attrs
->Width
<= 0 || attrs
->Height
<= 0 ||
2152 !attrs
->DMABufFourCC
.IsPresent
)
2153 return _eglError(EGL_BAD_PARAMETER
, "attribute(s) missing");
2158 * "If <target> is EGL_LINUX_DMA_BUF_EXT and one or more of the values
2159 * specified for a plane's pitch or offset isn't supported by EGL,
2160 * EGL_BAD_ACCESS is generated."
2162 for (unsigned i
= 0; i
< ARRAY_SIZE(attrs
->DMABufPlanePitches
); ++i
) {
2163 if (attrs
->DMABufPlanePitches
[i
].IsPresent
&&
2164 attrs
->DMABufPlanePitches
[i
].Value
<= 0)
2165 return _eglError(EGL_BAD_ACCESS
, "invalid pitch");
2169 * If <target> is EGL_LINUX_DMA_BUF_EXT, both or neither of the following
2170 * attribute values may be given.
2172 * This is referring to EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT and
2173 * EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT, and the same for other planes.
2175 for (unsigned i
= 0; i
< DMA_BUF_MAX_PLANES
; ++i
) {
2176 if (attrs
->DMABufPlaneModifiersLo
[i
].IsPresent
!=
2177 attrs
->DMABufPlaneModifiersHi
[i
].IsPresent
)
2178 return _eglError(EGL_BAD_PARAMETER
, "modifier attribute lo or hi missing");
2181 /* Although the EGL_EXT_image_dma_buf_import_modifiers spec doesn't
2182 * mandate it, we only accept the same modifier across all planes. */
2183 for (unsigned i
= 1; i
< DMA_BUF_MAX_PLANES
; ++i
) {
2184 if (attrs
->DMABufPlaneFds
[i
].IsPresent
) {
2185 if ((attrs
->DMABufPlaneModifiersLo
[0].IsPresent
!=
2186 attrs
->DMABufPlaneModifiersLo
[i
].IsPresent
) ||
2187 (attrs
->DMABufPlaneModifiersLo
[0].Value
!=
2188 attrs
->DMABufPlaneModifiersLo
[i
].Value
) ||
2189 (attrs
->DMABufPlaneModifiersHi
[0].Value
!=
2190 attrs
->DMABufPlaneModifiersHi
[i
].Value
))
2191 return _eglError(EGL_BAD_PARAMETER
, "modifier attributes not equal");
2198 /* Returns the total number of file descriptors. Zero indicates an error. */
2200 dri2_check_dma_buf_format(const _EGLImageAttribs
*attrs
)
2204 switch (attrs
->DMABufFourCC
.Value
) {
2206 case DRM_FORMAT_RG88
:
2207 case DRM_FORMAT_GR88
:
2208 case DRM_FORMAT_R16
:
2209 case DRM_FORMAT_GR1616
:
2210 case DRM_FORMAT_RGB332
:
2211 case DRM_FORMAT_BGR233
:
2212 case DRM_FORMAT_XRGB4444
:
2213 case DRM_FORMAT_XBGR4444
:
2214 case DRM_FORMAT_RGBX4444
:
2215 case DRM_FORMAT_BGRX4444
:
2216 case DRM_FORMAT_ARGB4444
:
2217 case DRM_FORMAT_ABGR4444
:
2218 case DRM_FORMAT_RGBA4444
:
2219 case DRM_FORMAT_BGRA4444
:
2220 case DRM_FORMAT_XRGB1555
:
2221 case DRM_FORMAT_XBGR1555
:
2222 case DRM_FORMAT_RGBX5551
:
2223 case DRM_FORMAT_BGRX5551
:
2224 case DRM_FORMAT_ARGB1555
:
2225 case DRM_FORMAT_ABGR1555
:
2226 case DRM_FORMAT_RGBA5551
:
2227 case DRM_FORMAT_BGRA5551
:
2228 case DRM_FORMAT_RGB565
:
2229 case DRM_FORMAT_BGR565
:
2230 case DRM_FORMAT_RGB888
:
2231 case DRM_FORMAT_BGR888
:
2232 case DRM_FORMAT_XRGB8888
:
2233 case DRM_FORMAT_XBGR8888
:
2234 case DRM_FORMAT_RGBX8888
:
2235 case DRM_FORMAT_BGRX8888
:
2236 case DRM_FORMAT_ARGB8888
:
2237 case DRM_FORMAT_ABGR8888
:
2238 case DRM_FORMAT_RGBA8888
:
2239 case DRM_FORMAT_BGRA8888
:
2240 case DRM_FORMAT_XRGB2101010
:
2241 case DRM_FORMAT_XBGR2101010
:
2242 case DRM_FORMAT_RGBX1010102
:
2243 case DRM_FORMAT_BGRX1010102
:
2244 case DRM_FORMAT_ARGB2101010
:
2245 case DRM_FORMAT_ABGR2101010
:
2246 case DRM_FORMAT_RGBA1010102
:
2247 case DRM_FORMAT_BGRA1010102
:
2248 case DRM_FORMAT_YUYV
:
2249 case DRM_FORMAT_YVYU
:
2250 case DRM_FORMAT_UYVY
:
2251 case DRM_FORMAT_VYUY
:
2254 case DRM_FORMAT_NV12
:
2255 case DRM_FORMAT_NV21
:
2256 case DRM_FORMAT_NV16
:
2257 case DRM_FORMAT_NV61
:
2260 case DRM_FORMAT_YUV410
:
2261 case DRM_FORMAT_YVU410
:
2262 case DRM_FORMAT_YUV411
:
2263 case DRM_FORMAT_YVU411
:
2264 case DRM_FORMAT_YUV420
:
2265 case DRM_FORMAT_YVU420
:
2266 case DRM_FORMAT_YUV422
:
2267 case DRM_FORMAT_YVU422
:
2268 case DRM_FORMAT_YUV444
:
2269 case DRM_FORMAT_YVU444
:
2273 _eglError(EGL_BAD_ATTRIBUTE
, "invalid format");
2277 for (unsigned i
= plane_n
; i
< DMA_BUF_MAX_PLANES
; i
++) {
2279 * The modifiers extension spec says:
2281 * "Modifiers may modify any attribute of a buffer import, including
2282 * but not limited to adding extra planes to a format which
2283 * otherwise does not have those planes. As an example, a modifier
2284 * may add a plane for an external compression buffer to a
2285 * single-plane format. The exact meaning and effect of any
2286 * modifier is canonically defined by drm_fourcc.h, not as part of
2289 if (attrs
->DMABufPlaneModifiersLo
[i
].IsPresent
&&
2290 attrs
->DMABufPlaneModifiersHi
[i
].IsPresent
) {
2298 * "* If <target> is EGL_LINUX_DMA_BUF_EXT, and the list of attributes is
2299 * incomplete, EGL_BAD_PARAMETER is generated."
2301 for (unsigned i
= 0; i
< plane_n
; ++i
) {
2302 if (!attrs
->DMABufPlaneFds
[i
].IsPresent
||
2303 !attrs
->DMABufPlaneOffsets
[i
].IsPresent
||
2304 !attrs
->DMABufPlanePitches
[i
].IsPresent
) {
2305 _eglError(EGL_BAD_PARAMETER
, "plane attribute(s) missing");
2311 * The spec also says:
2313 * "If <target> is EGL_LINUX_DMA_BUF_EXT, and the EGL_LINUX_DRM_FOURCC_EXT
2314 * attribute indicates a single-plane format, EGL_BAD_ATTRIBUTE is
2315 * generated if any of the EGL_DMA_BUF_PLANE1_* or EGL_DMA_BUF_PLANE2_*
2316 * or EGL_DMA_BUF_PLANE3_* attributes are specified."
2318 for (unsigned i
= plane_n
; i
< DMA_BUF_MAX_PLANES
; ++i
) {
2319 if (attrs
->DMABufPlaneFds
[i
].IsPresent
||
2320 attrs
->DMABufPlaneOffsets
[i
].IsPresent
||
2321 attrs
->DMABufPlanePitches
[i
].IsPresent
) {
2322 _eglError(EGL_BAD_ATTRIBUTE
, "too many plane attributes");
2331 dri2_query_dma_buf_formats(_EGLDriver
*drv
, _EGLDisplay
*disp
,
2332 EGLint max
, EGLint
*formats
, EGLint
*count
)
2334 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2335 if (max
< 0 || (max
> 0 && formats
== NULL
))
2336 return _eglError(EGL_BAD_PARAMETER
, "invalid value for max count of formats");
2338 if (dri2_dpy
->image
->base
.version
< 15 ||
2339 dri2_dpy
->image
->queryDmaBufFormats
== NULL
)
2342 if (!dri2_dpy
->image
->queryDmaBufFormats(dri2_dpy
->dri_screen
, max
,
2350 dri2_query_dma_buf_modifiers(_EGLDriver
*drv
, _EGLDisplay
*disp
, EGLint format
,
2351 EGLint max
, EGLuint64KHR
*modifiers
,
2352 EGLBoolean
*external_only
, EGLint
*count
)
2354 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2357 return _eglError(EGL_BAD_PARAMETER
, "invalid value for max count of formats");
2359 if (max
> 0 && modifiers
== NULL
)
2360 return _eglError(EGL_BAD_PARAMETER
, "invalid modifiers array");
2362 if (dri2_dpy
->image
->base
.version
< 15 ||
2363 dri2_dpy
->image
->queryDmaBufModifiers
== NULL
)
2366 if (dri2_dpy
->image
->queryDmaBufModifiers(dri2_dpy
->dri_screen
, format
,
2368 (unsigned int *) external_only
,
2370 return _eglError(EGL_BAD_PARAMETER
, "invalid format");
2378 * "If eglCreateImageKHR is successful for a EGL_LINUX_DMA_BUF_EXT target, the
2379 * EGL will take a reference to the dma_buf(s) which it will release at any
2380 * time while the EGLDisplay is initialized. It is the responsibility of the
2381 * application to close the dma_buf file descriptors."
2383 * Therefore we must never close or otherwise modify the file descriptors.
2386 dri2_create_image_dma_buf(_EGLDisplay
*disp
, _EGLContext
*ctx
,
2387 EGLClientBuffer buffer
, const EGLint
*attr_list
)
2389 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2391 _EGLImageAttribs attrs
;
2392 __DRIimage
*dri_image
;
2394 int fds
[DMA_BUF_MAX_PLANES
];
2395 int pitches
[DMA_BUF_MAX_PLANES
];
2396 int offsets
[DMA_BUF_MAX_PLANES
];
2398 bool has_modifier
= false;
2404 * ""* If <target> is EGL_LINUX_DMA_BUF_EXT and <buffer> is not NULL, the
2405 * error EGL_BAD_PARAMETER is generated."
2407 if (buffer
!= NULL
) {
2408 _eglError(EGL_BAD_PARAMETER
, "buffer not NULL");
2412 if (!_eglParseImageAttribList(&attrs
, disp
, attr_list
))
2415 if (!dri2_check_dma_buf_attribs(&attrs
))
2418 num_fds
= dri2_check_dma_buf_format(&attrs
);
2422 for (unsigned i
= 0; i
< num_fds
; ++i
) {
2423 fds
[i
] = attrs
.DMABufPlaneFds
[i
].Value
;
2424 pitches
[i
] = attrs
.DMABufPlanePitches
[i
].Value
;
2425 offsets
[i
] = attrs
.DMABufPlaneOffsets
[i
].Value
;
2428 /* dri2_check_dma_buf_attribs ensures that the modifier, if available,
2429 * will be present in attrs.DMABufPlaneModifiersLo[0] and
2430 * attrs.DMABufPlaneModifiersHi[0] */
2431 if (attrs
.DMABufPlaneModifiersLo
[0].IsPresent
) {
2432 modifier
= (uint64_t) attrs
.DMABufPlaneModifiersHi
[0].Value
<< 32;
2433 modifier
|= (uint64_t) (attrs
.DMABufPlaneModifiersLo
[0].Value
& 0xffffffff);
2434 has_modifier
= true;
2438 if (dri2_dpy
->image
->base
.version
< 15 ||
2439 dri2_dpy
->image
->createImageFromDmaBufs2
== NULL
) {
2440 _eglError(EGL_BAD_MATCH
, "unsupported dma_buf format modifier");
2441 return EGL_NO_IMAGE_KHR
;
2444 dri2_dpy
->image
->createImageFromDmaBufs2(dri2_dpy
->dri_screen
,
2445 attrs
.Width
, attrs
.Height
, attrs
.DMABufFourCC
.Value
,
2446 modifier
, fds
, num_fds
, pitches
, offsets
,
2447 attrs
.DMABufYuvColorSpaceHint
.Value
,
2448 attrs
.DMABufSampleRangeHint
.Value
,
2449 attrs
.DMABufChromaHorizontalSiting
.Value
,
2450 attrs
.DMABufChromaVerticalSiting
.Value
,
2456 dri2_dpy
->image
->createImageFromDmaBufs(dri2_dpy
->dri_screen
,
2457 attrs
.Width
, attrs
.Height
, attrs
.DMABufFourCC
.Value
,
2458 fds
, num_fds
, pitches
, offsets
,
2459 attrs
.DMABufYuvColorSpaceHint
.Value
,
2460 attrs
.DMABufSampleRangeHint
.Value
,
2461 attrs
.DMABufChromaHorizontalSiting
.Value
,
2462 attrs
.DMABufChromaVerticalSiting
.Value
,
2466 dri2_create_image_khr_texture_error(error
);
2469 return EGL_NO_IMAGE_KHR
;
2471 res
= dri2_create_image_from_dri(disp
, dri_image
);
2476 dri2_create_drm_image_mesa(_EGLDriver
*drv
, _EGLDisplay
*disp
,
2477 const EGLint
*attr_list
)
2479 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2480 struct dri2_egl_image
*dri2_img
;
2481 _EGLImageAttribs attrs
;
2482 unsigned int dri_use
, valid_mask
;
2488 _eglError(EGL_BAD_PARAMETER
, __func__
);
2489 return EGL_NO_IMAGE_KHR
;
2492 if (!_eglParseImageAttribList(&attrs
, disp
, attr_list
))
2493 return EGL_NO_IMAGE_KHR
;
2495 if (attrs
.Width
<= 0 || attrs
.Height
<= 0) {
2496 _eglError(EGL_BAD_PARAMETER
, __func__
);
2497 return EGL_NO_IMAGE_KHR
;
2500 switch (attrs
.DRMBufferFormatMESA
) {
2501 case EGL_DRM_BUFFER_FORMAT_ARGB32_MESA
:
2502 format
= __DRI_IMAGE_FORMAT_ARGB8888
;
2505 _eglError(EGL_BAD_PARAMETER
, __func__
);
2506 return EGL_NO_IMAGE_KHR
;
2510 EGL_DRM_BUFFER_USE_SCANOUT_MESA
|
2511 EGL_DRM_BUFFER_USE_SHARE_MESA
|
2512 EGL_DRM_BUFFER_USE_CURSOR_MESA
;
2513 if (attrs
.DRMBufferUseMESA
& ~valid_mask
) {
2514 _eglError(EGL_BAD_PARAMETER
, __func__
);
2515 return EGL_NO_IMAGE_KHR
;
2519 if (attrs
.DRMBufferUseMESA
& EGL_DRM_BUFFER_USE_SHARE_MESA
)
2520 dri_use
|= __DRI_IMAGE_USE_SHARE
;
2521 if (attrs
.DRMBufferUseMESA
& EGL_DRM_BUFFER_USE_SCANOUT_MESA
)
2522 dri_use
|= __DRI_IMAGE_USE_SCANOUT
;
2523 if (attrs
.DRMBufferUseMESA
& EGL_DRM_BUFFER_USE_CURSOR_MESA
)
2524 dri_use
|= __DRI_IMAGE_USE_CURSOR
;
2526 dri2_img
= malloc(sizeof *dri2_img
);
2528 _eglError(EGL_BAD_ALLOC
, "dri2_create_image_khr");
2529 return EGL_NO_IMAGE_KHR
;
2532 _eglInitImage(&dri2_img
->base
, disp
);
2534 dri2_img
->dri_image
=
2535 dri2_dpy
->image
->createImage(dri2_dpy
->dri_screen
,
2536 attrs
.Width
, attrs
.Height
,
2537 format
, dri_use
, dri2_img
);
2538 if (dri2_img
->dri_image
== NULL
) {
2540 _eglError(EGL_BAD_ALLOC
, "dri2_create_drm_image_mesa");
2541 return EGL_NO_IMAGE_KHR
;
2544 return &dri2_img
->base
;
2548 dri2_export_drm_image_mesa(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLImage
*img
,
2549 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
2551 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2552 struct dri2_egl_image
*dri2_img
= dri2_egl_image(img
);
2556 if (name
&& !dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2557 __DRI_IMAGE_ATTRIB_NAME
, name
))
2558 return _eglError(EGL_BAD_ALLOC
, "dri2_export_drm_image_mesa");
2561 dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2562 __DRI_IMAGE_ATTRIB_HANDLE
, handle
);
2565 dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2566 __DRI_IMAGE_ATTRIB_STRIDE
, stride
);
2572 dri2_export_dma_buf_image_query_mesa(_EGLDriver
*drv
, _EGLDisplay
*disp
,
2574 EGLint
*fourcc
, EGLint
*nplanes
,
2575 EGLuint64KHR
*modifiers
)
2577 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2578 struct dri2_egl_image
*dri2_img
= dri2_egl_image(img
);
2584 dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2585 __DRI_IMAGE_ATTRIB_NUM_PLANES
, nplanes
);
2587 dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2588 __DRI_IMAGE_ATTRIB_FOURCC
, fourcc
);
2597 dri2_export_dma_buf_image_mesa(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLImage
*img
,
2598 int *fds
, EGLint
*strides
, EGLint
*offsets
)
2600 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2601 struct dri2_egl_image
*dri2_img
= dri2_egl_image(img
);
2605 /* rework later to provide multiple fds/strides/offsets */
2607 dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2608 __DRI_IMAGE_ATTRIB_FD
, fds
);
2611 dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2612 __DRI_IMAGE_ATTRIB_STRIDE
, strides
);
2616 bool ret
= dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2617 __DRI_IMAGE_ATTRIB_OFFSET
, &img_offset
);
2619 offsets
[0] = img_offset
;
2630 dri2_create_image_khr(_EGLDriver
*drv
, _EGLDisplay
*disp
,
2631 _EGLContext
*ctx
, EGLenum target
,
2632 EGLClientBuffer buffer
, const EGLint
*attr_list
)
2637 case EGL_GL_TEXTURE_2D_KHR
:
2638 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR
:
2639 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR
:
2640 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR
:
2641 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR
:
2642 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR
:
2643 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR
:
2644 case EGL_GL_TEXTURE_3D_KHR
:
2645 return dri2_create_image_khr_texture(disp
, ctx
, target
, buffer
, attr_list
);
2646 case EGL_GL_RENDERBUFFER_KHR
:
2647 return dri2_create_image_khr_renderbuffer(disp
, ctx
, buffer
, attr_list
);
2649 case EGL_DRM_BUFFER_MESA
:
2650 return dri2_create_image_mesa_drm_buffer(disp
, ctx
, buffer
, attr_list
);
2651 case EGL_LINUX_DMA_BUF_EXT
:
2652 return dri2_create_image_dma_buf(disp
, ctx
, buffer
, attr_list
);
2654 #ifdef HAVE_WAYLAND_PLATFORM
2655 case EGL_WAYLAND_BUFFER_WL
:
2656 return dri2_create_image_wayland_wl_buffer(disp
, ctx
, buffer
, attr_list
);
2659 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
2660 return EGL_NO_IMAGE_KHR
;
2665 dri2_destroy_image_khr(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLImage
*image
)
2667 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2668 struct dri2_egl_image
*dri2_img
= dri2_egl_image(image
);
2672 dri2_dpy
->image
->destroyImage(dri2_img
->dri_image
);
2678 #ifdef HAVE_WAYLAND_PLATFORM
2681 dri2_wl_reference_buffer(void *user_data
, uint32_t name
, int fd
,
2682 struct wl_drm_buffer
*buffer
)
2684 _EGLDisplay
*disp
= user_data
;
2685 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2687 int dri_components
= 0;
2690 img
= dri2_dpy
->image
->createImageFromNames(dri2_dpy
->dri_screen
,
2699 img
= dri2_dpy
->image
->createImageFromFds(dri2_dpy
->dri_screen
,
2711 dri2_dpy
->image
->queryImage(img
, __DRI_IMAGE_ATTRIB_COMPONENTS
, &dri_components
);
2713 buffer
->driver_format
= NULL
;
2714 for (int i
= 0; i
< ARRAY_SIZE(wl_drm_components
); i
++)
2715 if (wl_drm_components
[i
].dri_components
== dri_components
)
2716 buffer
->driver_format
= &wl_drm_components
[i
];
2718 if (buffer
->driver_format
== NULL
)
2719 dri2_dpy
->image
->destroyImage(img
);
2721 buffer
->driver_buffer
= img
;
2725 dri2_wl_release_buffer(void *user_data
, struct wl_drm_buffer
*buffer
)
2727 _EGLDisplay
*disp
= user_data
;
2728 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2730 dri2_dpy
->image
->destroyImage(buffer
->driver_buffer
);
2734 dri2_bind_wayland_display_wl(_EGLDriver
*drv
, _EGLDisplay
*disp
,
2735 struct wl_display
*wl_dpy
)
2737 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2738 const struct wayland_drm_callbacks wl_drm_callbacks
= {
2739 .authenticate
= (int(*)(void *, uint32_t)) dri2_dpy
->vtbl
->authenticate
,
2740 .reference_buffer
= dri2_wl_reference_buffer
,
2741 .release_buffer
= dri2_wl_release_buffer
2748 if (dri2_dpy
->wl_server_drm
)
2751 if (drmGetCap(dri2_dpy
->fd
, DRM_CAP_PRIME
, &cap
) == 0 &&
2752 cap
== (DRM_PRIME_CAP_IMPORT
| DRM_PRIME_CAP_EXPORT
) &&
2753 dri2_dpy
->image
->base
.version
>= 7 &&
2754 dri2_dpy
->image
->createImageFromFds
!= NULL
)
2755 flags
|= WAYLAND_DRM_PRIME
;
2757 dri2_dpy
->wl_server_drm
=
2758 wayland_drm_init(wl_dpy
, dri2_dpy
->device_name
,
2759 &wl_drm_callbacks
, disp
, flags
);
2761 if (!dri2_dpy
->wl_server_drm
)
2764 #ifdef HAVE_DRM_PLATFORM
2765 /* We have to share the wl_drm instance with gbm, so gbm can convert
2766 * wl_buffers to gbm bos. */
2767 if (dri2_dpy
->gbm_dri
)
2768 dri2_dpy
->gbm_dri
->wl_drm
= dri2_dpy
->wl_server_drm
;
2775 dri2_unbind_wayland_display_wl(_EGLDriver
*drv
, _EGLDisplay
*disp
,
2776 struct wl_display
*wl_dpy
)
2778 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2782 if (!dri2_dpy
->wl_server_drm
)
2785 wayland_drm_uninit(dri2_dpy
->wl_server_drm
);
2786 dri2_dpy
->wl_server_drm
= NULL
;
2792 dri2_query_wayland_buffer_wl(_EGLDriver
*drv
, _EGLDisplay
*disp
,
2793 struct wl_resource
*buffer_resource
,
2794 EGLint attribute
, EGLint
*value
)
2796 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2797 struct wl_drm_buffer
*buffer
;
2798 const struct wl_drm_components_descriptor
*format
;
2800 buffer
= wayland_drm_buffer_get(dri2_dpy
->wl_server_drm
, buffer_resource
);
2804 format
= buffer
->driver_format
;
2805 switch (attribute
) {
2806 case EGL_TEXTURE_FORMAT
:
2807 *value
= format
->components
;
2810 *value
= buffer
->width
;
2813 *value
= buffer
->height
;
2822 dri2_egl_ref_sync(struct dri2_egl_sync
*sync
)
2824 p_atomic_inc(&sync
->refcount
);
2828 dri2_egl_unref_sync(struct dri2_egl_display
*dri2_dpy
,
2829 struct dri2_egl_sync
*dri2_sync
)
2831 if (p_atomic_dec_zero(&dri2_sync
->refcount
)) {
2832 switch (dri2_sync
->base
.Type
) {
2833 case EGL_SYNC_REUSABLE_KHR
:
2834 cnd_destroy(&dri2_sync
->cond
);
2836 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
2837 if (dri2_sync
->base
.SyncFd
!= EGL_NO_NATIVE_FENCE_FD_ANDROID
)
2838 close(dri2_sync
->base
.SyncFd
);
2844 if (dri2_sync
->fence
)
2845 dri2_dpy
->fence
->destroy_fence(dri2_dpy
->dri_screen
, dri2_sync
->fence
);
2852 dri2_create_sync(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
2853 EGLenum type
, const EGLAttrib
*attrib_list
)
2855 _EGLContext
*ctx
= _eglGetCurrentContext();
2856 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
2857 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
2858 struct dri2_egl_sync
*dri2_sync
;
2860 pthread_condattr_t attr
;
2862 dri2_sync
= calloc(1, sizeof(struct dri2_egl_sync
));
2864 _eglError(EGL_BAD_ALLOC
, "eglCreateSyncKHR");
2868 if (!_eglInitSync(&dri2_sync
->base
, dpy
, type
, attrib_list
)) {
2874 case EGL_SYNC_FENCE_KHR
:
2875 dri2_sync
->fence
= dri2_dpy
->fence
->create_fence(dri2_ctx
->dri_context
);
2876 if (!dri2_sync
->fence
) {
2877 /* Why did it fail? DRI doesn't return an error code, so we emit
2878 * a generic EGL error that doesn't communicate user error.
2880 _eglError(EGL_BAD_ALLOC
, "eglCreateSyncKHR");
2886 case EGL_SYNC_CL_EVENT_KHR
:
2887 dri2_sync
->fence
= dri2_dpy
->fence
->get_fence_from_cl_event(
2888 dri2_dpy
->dri_screen
,
2889 dri2_sync
->base
.CLEvent
);
2890 /* this can only happen if the cl_event passed in is invalid. */
2891 if (!dri2_sync
->fence
) {
2892 _eglError(EGL_BAD_ATTRIBUTE
, "eglCreateSyncKHR");
2897 /* the initial status must be "signaled" if the cl_event is signaled */
2898 if (dri2_dpy
->fence
->client_wait_sync(dri2_ctx
->dri_context
,
2899 dri2_sync
->fence
, 0, 0))
2900 dri2_sync
->base
.SyncStatus
= EGL_SIGNALED_KHR
;
2903 case EGL_SYNC_REUSABLE_KHR
:
2904 /* intialize attr */
2905 ret
= pthread_condattr_init(&attr
);
2908 _eglError(EGL_BAD_ACCESS
, "eglCreateSyncKHR");
2913 /* change clock attribute to CLOCK_MONOTONIC */
2914 ret
= pthread_condattr_setclock(&attr
, CLOCK_MONOTONIC
);
2917 _eglError(EGL_BAD_ACCESS
, "eglCreateSyncKHR");
2922 ret
= pthread_cond_init(&dri2_sync
->cond
, &attr
);
2925 _eglError(EGL_BAD_ACCESS
, "eglCreateSyncKHR");
2930 /* initial status of reusable sync must be "unsignaled" */
2931 dri2_sync
->base
.SyncStatus
= EGL_UNSIGNALED_KHR
;
2934 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
2935 if (dri2_dpy
->fence
->create_fence_fd
) {
2936 dri2_sync
->fence
= dri2_dpy
->fence
->create_fence_fd(
2937 dri2_ctx
->dri_context
,
2938 dri2_sync
->base
.SyncFd
);
2940 if (!dri2_sync
->fence
) {
2941 _eglError(EGL_BAD_ATTRIBUTE
, "eglCreateSyncKHR");
2948 p_atomic_set(&dri2_sync
->refcount
, 1);
2949 return &dri2_sync
->base
;
2953 dri2_destroy_sync(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSync
*sync
)
2955 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
2956 struct dri2_egl_sync
*dri2_sync
= dri2_egl_sync(sync
);
2957 EGLint ret
= EGL_TRUE
;
2960 /* if type of sync is EGL_SYNC_REUSABLE_KHR and it is not signaled yet,
2961 * then unlock all threads possibly blocked by the reusable sync before
2964 if (dri2_sync
->base
.Type
== EGL_SYNC_REUSABLE_KHR
&&
2965 dri2_sync
->base
.SyncStatus
== EGL_UNSIGNALED_KHR
) {
2966 dri2_sync
->base
.SyncStatus
= EGL_SIGNALED_KHR
;
2967 /* unblock all threads currently blocked by sync */
2968 err
= cnd_broadcast(&dri2_sync
->cond
);
2971 _eglError(EGL_BAD_ACCESS
, "eglDestroySyncKHR");
2976 dri2_egl_unref_sync(dri2_dpy
, dri2_sync
);
2982 dri2_dup_native_fence_fd(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSync
*sync
)
2984 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
2985 struct dri2_egl_sync
*dri2_sync
= dri2_egl_sync(sync
);
2987 assert(sync
->Type
== EGL_SYNC_NATIVE_FENCE_ANDROID
);
2989 if (sync
->SyncFd
== EGL_NO_NATIVE_FENCE_FD_ANDROID
) {
2990 /* try to retrieve the actual native fence fd.. if rendering is
2991 * not flushed this will just return -1, aka NO_NATIVE_FENCE_FD:
2993 sync
->SyncFd
= dri2_dpy
->fence
->get_fence_fd(dri2_dpy
->dri_screen
,
2997 if (sync
->SyncFd
== EGL_NO_NATIVE_FENCE_FD_ANDROID
) {
2998 /* if native fence fd still not created, return an error: */
2999 _eglError(EGL_BAD_PARAMETER
, "eglDupNativeFenceFDANDROID");
3000 return EGL_NO_NATIVE_FENCE_FD_ANDROID
;
3003 return dup(sync
->SyncFd
);
3007 dri2_set_blob_cache_funcs(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
3008 EGLSetBlobFuncANDROID set
,
3009 EGLGetBlobFuncANDROID get
)
3011 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
3012 dri2_dpy
->blob
->set_cache_funcs(dri2_dpy
->dri_screen
,
3018 dri2_client_wait_sync(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSync
*sync
,
3019 EGLint flags
, EGLTime timeout
)
3021 _EGLContext
*ctx
= _eglGetCurrentContext();
3022 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
3023 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
3024 struct dri2_egl_sync
*dri2_sync
= dri2_egl_sync(sync
);
3025 unsigned wait_flags
= 0;
3027 EGLint ret
= EGL_CONDITION_SATISFIED_KHR
;
3029 /* The EGL_KHR_fence_sync spec states:
3031 * "If no context is current for the bound API,
3032 * the EGL_SYNC_FLUSH_COMMANDS_BIT_KHR bit is ignored.
3034 if (dri2_ctx
&& flags
& EGL_SYNC_FLUSH_COMMANDS_BIT_KHR
)
3035 wait_flags
|= __DRI2_FENCE_FLAG_FLUSH_COMMANDS
;
3037 /* the sync object should take a reference while waiting */
3038 dri2_egl_ref_sync(dri2_sync
);
3040 switch (sync
->Type
) {
3041 case EGL_SYNC_FENCE_KHR
:
3042 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
3043 case EGL_SYNC_CL_EVENT_KHR
:
3044 if (dri2_dpy
->fence
->client_wait_sync(dri2_ctx
? dri2_ctx
->dri_context
: NULL
,
3045 dri2_sync
->fence
, wait_flags
,
3047 dri2_sync
->base
.SyncStatus
= EGL_SIGNALED_KHR
;
3049 ret
= EGL_TIMEOUT_EXPIRED_KHR
;
3052 case EGL_SYNC_REUSABLE_KHR
:
3053 if (dri2_ctx
&& dri2_sync
->base
.SyncStatus
== EGL_UNSIGNALED_KHR
&&
3054 (flags
& EGL_SYNC_FLUSH_COMMANDS_BIT_KHR
)) {
3055 /* flush context if EGL_SYNC_FLUSH_COMMANDS_BIT_KHR is set */
3059 /* if timeout is EGL_FOREVER_KHR, it should wait without any timeout.*/
3060 if (timeout
== EGL_FOREVER_KHR
) {
3061 mtx_lock(&dri2_sync
->mutex
);
3062 cnd_wait(&dri2_sync
->cond
, &dri2_sync
->mutex
);
3063 mtx_unlock(&dri2_sync
->mutex
);
3065 /* if reusable sync has not been yet signaled */
3066 if (dri2_sync
->base
.SyncStatus
!= EGL_SIGNALED_KHR
) {
3067 /* timespecs for cnd_timedwait */
3068 struct timespec current
;
3069 struct timespec expire
;
3071 /* We override the clock to monotonic when creating the condition
3073 clock_gettime(CLOCK_MONOTONIC
, ¤t
);
3075 /* calculating when to expire */
3076 expire
.tv_nsec
= timeout
% 1000000000L;
3077 expire
.tv_sec
= timeout
/ 1000000000L;
3079 expire
.tv_nsec
+= current
.tv_nsec
;
3080 expire
.tv_sec
+= current
.tv_sec
;
3082 /* expire.nsec now is a number between 0 and 1999999998 */
3083 if (expire
.tv_nsec
> 999999999L) {
3085 expire
.tv_nsec
-= 1000000000L;
3088 mtx_lock(&dri2_sync
->mutex
);
3089 ret
= cnd_timedwait(&dri2_sync
->cond
, &dri2_sync
->mutex
, &expire
);
3090 mtx_unlock(&dri2_sync
->mutex
);
3092 if (ret
== thrd_busy
) {
3093 if (dri2_sync
->base
.SyncStatus
== EGL_UNSIGNALED_KHR
) {
3094 ret
= EGL_TIMEOUT_EXPIRED_KHR
;
3096 _eglError(EGL_BAD_ACCESS
, "eglClientWaitSyncKHR");
3104 dri2_egl_unref_sync(dri2_dpy
, dri2_sync
);
3110 dri2_signal_sync(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSync
*sync
,
3113 struct dri2_egl_sync
*dri2_sync
= dri2_egl_sync(sync
);
3116 if (sync
->Type
!= EGL_SYNC_REUSABLE_KHR
)
3117 return _eglError(EGL_BAD_MATCH
, "eglSignalSyncKHR");
3119 if (mode
!= EGL_SIGNALED_KHR
&& mode
!= EGL_UNSIGNALED_KHR
)
3120 return _eglError(EGL_BAD_ATTRIBUTE
, "eglSignalSyncKHR");
3122 dri2_sync
->base
.SyncStatus
= mode
;
3124 if (mode
== EGL_SIGNALED_KHR
) {
3125 ret
= cnd_broadcast(&dri2_sync
->cond
);
3127 /* fail to broadcast */
3129 return _eglError(EGL_BAD_ACCESS
, "eglSignalSyncKHR");
3136 dri2_server_wait_sync(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSync
*sync
)
3138 _EGLContext
*ctx
= _eglGetCurrentContext();
3139 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
3140 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
3141 struct dri2_egl_sync
*dri2_sync
= dri2_egl_sync(sync
);
3143 dri2_dpy
->fence
->server_wait_sync(dri2_ctx
->dri_context
,
3144 dri2_sync
->fence
, 0);
3149 dri2_interop_query_device_info(_EGLDisplay
*dpy
, _EGLContext
*ctx
,
3150 struct mesa_glinterop_device_info
*out
)
3152 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
3153 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
3155 if (!dri2_dpy
->interop
)
3156 return MESA_GLINTEROP_UNSUPPORTED
;
3158 return dri2_dpy
->interop
->query_device_info(dri2_ctx
->dri_context
, out
);
3162 dri2_interop_export_object(_EGLDisplay
*dpy
, _EGLContext
*ctx
,
3163 struct mesa_glinterop_export_in
*in
,
3164 struct mesa_glinterop_export_out
*out
)
3166 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
3167 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
3169 if (!dri2_dpy
->interop
)
3170 return MESA_GLINTEROP_UNSUPPORTED
;
3172 return dri2_dpy
->interop
->export_object(dri2_ctx
->dri_context
, in
, out
);
3176 * This is the main entrypoint into the driver, called by libEGL.
3177 * Create a new _EGLDriver object and init its dispatch table.
3180 _eglBuiltInDriver(void)
3182 _EGLDriver
*dri2_drv
= calloc(1, sizeof *dri2_drv
);
3186 _eglInitDriverFallbacks(dri2_drv
);
3187 dri2_drv
->API
.Initialize
= dri2_initialize
;
3188 dri2_drv
->API
.Terminate
= dri2_terminate
;
3189 dri2_drv
->API
.CreateContext
= dri2_create_context
;
3190 dri2_drv
->API
.DestroyContext
= dri2_destroy_context
;
3191 dri2_drv
->API
.MakeCurrent
= dri2_make_current
;
3192 dri2_drv
->API
.CreateWindowSurface
= dri2_create_window_surface
;
3193 dri2_drv
->API
.CreatePixmapSurface
= dri2_create_pixmap_surface
;
3194 dri2_drv
->API
.CreatePbufferSurface
= dri2_create_pbuffer_surface
;
3195 dri2_drv
->API
.DestroySurface
= dri2_destroy_surface
;
3196 dri2_drv
->API
.GetProcAddress
= dri2_get_proc_address
;
3197 dri2_drv
->API
.WaitClient
= dri2_wait_client
;
3198 dri2_drv
->API
.WaitNative
= dri2_wait_native
;
3199 dri2_drv
->API
.BindTexImage
= dri2_bind_tex_image
;
3200 dri2_drv
->API
.ReleaseTexImage
= dri2_release_tex_image
;
3201 dri2_drv
->API
.SwapInterval
= dri2_swap_interval
;
3202 dri2_drv
->API
.SwapBuffers
= dri2_swap_buffers
;
3203 dri2_drv
->API
.SwapBuffersWithDamageEXT
= dri2_swap_buffers_with_damage
;
3204 dri2_drv
->API
.SwapBuffersRegionNOK
= dri2_swap_buffers_region
;
3205 dri2_drv
->API
.SetDamageRegion
= dri2_set_damage_region
;
3206 dri2_drv
->API
.PostSubBufferNV
= dri2_post_sub_buffer
;
3207 dri2_drv
->API
.CopyBuffers
= dri2_copy_buffers
,
3208 dri2_drv
->API
.QueryBufferAge
= dri2_query_buffer_age
;
3209 dri2_drv
->API
.CreateImageKHR
= dri2_create_image
;
3210 dri2_drv
->API
.DestroyImageKHR
= dri2_destroy_image_khr
;
3211 dri2_drv
->API
.CreateWaylandBufferFromImageWL
= dri2_create_wayland_buffer_from_image
;
3212 dri2_drv
->API
.QuerySurface
= dri2_query_surface
;
3214 dri2_drv
->API
.CreateDRMImageMESA
= dri2_create_drm_image_mesa
;
3215 dri2_drv
->API
.ExportDRMImageMESA
= dri2_export_drm_image_mesa
;
3216 dri2_drv
->API
.ExportDMABUFImageQueryMESA
= dri2_export_dma_buf_image_query_mesa
;
3217 dri2_drv
->API
.ExportDMABUFImageMESA
= dri2_export_dma_buf_image_mesa
;
3218 dri2_drv
->API
.QueryDmaBufFormatsEXT
= dri2_query_dma_buf_formats
;
3219 dri2_drv
->API
.QueryDmaBufModifiersEXT
= dri2_query_dma_buf_modifiers
;
3221 #ifdef HAVE_WAYLAND_PLATFORM
3222 dri2_drv
->API
.BindWaylandDisplayWL
= dri2_bind_wayland_display_wl
;
3223 dri2_drv
->API
.UnbindWaylandDisplayWL
= dri2_unbind_wayland_display_wl
;
3224 dri2_drv
->API
.QueryWaylandBufferWL
= dri2_query_wayland_buffer_wl
;
3226 dri2_drv
->API
.GetSyncValuesCHROMIUM
= dri2_get_sync_values_chromium
;
3227 dri2_drv
->API
.CreateSyncKHR
= dri2_create_sync
;
3228 dri2_drv
->API
.ClientWaitSyncKHR
= dri2_client_wait_sync
;
3229 dri2_drv
->API
.SignalSyncKHR
= dri2_signal_sync
;
3230 dri2_drv
->API
.WaitSyncKHR
= dri2_server_wait_sync
;
3231 dri2_drv
->API
.DestroySyncKHR
= dri2_destroy_sync
;
3232 dri2_drv
->API
.GLInteropQueryDeviceInfo
= dri2_interop_query_device_info
;
3233 dri2_drv
->API
.GLInteropExportObject
= dri2_interop_export_object
;
3234 dri2_drv
->API
.DupNativeFenceFDANDROID
= dri2_dup_native_fence_fd
;
3235 dri2_drv
->API
.SetBlobCacheFuncsANDROID
= dri2_set_blob_cache_funcs
;
3237 dri2_drv
->Name
= "DRI2";