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];
1296 if (!dri2_fill_context_attribs(dri2_ctx
, dri2_dpy
, ctx_attribs
,
1300 if (dri2_dpy
->image_driver
) {
1301 dri2_ctx
->dri_context
=
1302 dri2_dpy
->image_driver
->createContextAttribs(dri2_dpy
->dri_screen
,
1310 dri2_create_context_attribs_error(error
);
1311 } else if (dri2_dpy
->dri2
) {
1312 if (dri2_dpy
->dri2
->base
.version
>= 3) {
1313 dri2_ctx
->dri_context
=
1314 dri2_dpy
->dri2
->createContextAttribs(dri2_dpy
->dri_screen
,
1322 dri2_create_context_attribs_error(error
);
1324 dri2_ctx
->dri_context
=
1325 dri2_dpy
->dri2
->createNewContextForAPI(dri2_dpy
->dri_screen
,
1332 assert(dri2_dpy
->swrast
);
1333 if (dri2_dpy
->swrast
->base
.version
>= 3) {
1334 dri2_ctx
->dri_context
=
1335 dri2_dpy
->swrast
->createContextAttribs(dri2_dpy
->dri_screen
,
1343 dri2_create_context_attribs_error(error
);
1345 dri2_ctx
->dri_context
=
1346 dri2_dpy
->swrast
->createNewContextForAPI(dri2_dpy
->dri_screen
,
1354 if (!dri2_ctx
->dri_context
)
1357 return &dri2_ctx
->base
;
1365 * Called via eglDestroyContext(), drv->API.DestroyContext().
1368 dri2_destroy_context(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLContext
*ctx
)
1370 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
1371 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1373 if (_eglPutContext(ctx
)) {
1374 dri2_dpy
->core
->destroyContext(dri2_ctx
->dri_context
);
1382 dri2_init_surface(_EGLSurface
*surf
, _EGLDisplay
*dpy
, EGLint type
,
1383 _EGLConfig
*conf
, const EGLint
*attrib_list
, EGLBoolean enable_out_fence
)
1385 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
1386 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1388 dri2_surf
->out_fence_fd
= -1;
1389 dri2_surf
->enable_out_fence
= false;
1390 if (dri2_dpy
->fence
&& dri2_dpy
->fence
->base
.version
>= 2 &&
1391 dri2_dpy
->fence
->get_capabilities
&&
1392 (dri2_dpy
->fence
->get_capabilities(dri2_dpy
->dri_screen
) &
1393 __DRI_FENCE_CAP_NATIVE_FD
)) {
1394 dri2_surf
->enable_out_fence
= enable_out_fence
;
1397 return _eglInitSurface(surf
, dpy
, type
, conf
, attrib_list
);
1401 dri2_surface_set_out_fence_fd( _EGLSurface
*surf
, int fence_fd
)
1403 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
1405 if (dri2_surf
->out_fence_fd
>= 0)
1406 close(dri2_surf
->out_fence_fd
);
1408 dri2_surf
->out_fence_fd
= fence_fd
;
1412 dri2_fini_surface(_EGLSurface
*surf
)
1414 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
1416 dri2_surface_set_out_fence_fd(surf
, -1);
1417 dri2_surf
->enable_out_fence
= false;
1421 dri2_destroy_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
)
1423 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1425 if (!_eglPutSurface(surf
))
1428 return dri2_dpy
->vtbl
->destroy_surface(drv
, dpy
, surf
);
1432 dri2_surf_update_fence_fd(_EGLContext
*ctx
,
1433 _EGLDisplay
*dpy
, _EGLSurface
*surf
)
1435 __DRIcontext
*dri_ctx
= dri2_egl_context(ctx
)->dri_context
;
1436 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1437 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
1441 if (!dri2_surf
->enable_out_fence
)
1444 fence
= dri2_dpy
->fence
->create_fence_fd(dri_ctx
, -1);
1446 fence_fd
= dri2_dpy
->fence
->get_fence_fd(dri2_dpy
->dri_screen
,
1448 dri2_dpy
->fence
->destroy_fence(dri2_dpy
->dri_screen
, fence
);
1450 dri2_surface_set_out_fence_fd(surf
, fence_fd
);
1454 * Called via eglMakeCurrent(), drv->API.MakeCurrent().
1457 dri2_make_current(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*dsurf
,
1458 _EGLSurface
*rsurf
, _EGLContext
*ctx
)
1460 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1461 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
1462 _EGLContext
*old_ctx
;
1463 _EGLSurface
*old_dsurf
, *old_rsurf
;
1464 _EGLSurface
*tmp_dsurf
, *tmp_rsurf
;
1465 __DRIdrawable
*ddraw
, *rdraw
;
1470 return _eglError(EGL_NOT_INITIALIZED
, "eglMakeCurrent");
1472 /* make new bindings */
1473 if (!_eglBindContext(ctx
, dsurf
, rsurf
, &old_ctx
, &old_dsurf
, &old_rsurf
)) {
1474 /* _eglBindContext already sets the EGL error (in _eglCheckMakeCurrent) */
1478 /* flush before context switch */
1482 ddraw
= (dsurf
) ? dri2_dpy
->vtbl
->get_dri_drawable(dsurf
) : NULL
;
1483 rdraw
= (rsurf
) ? dri2_dpy
->vtbl
->get_dri_drawable(rsurf
) : NULL
;
1484 cctx
= (dri2_ctx
) ? dri2_ctx
->dri_context
: NULL
;
1487 __DRIcontext
*old_cctx
= dri2_egl_context(old_ctx
)->dri_context
;
1490 dri2_surf_update_fence_fd(old_ctx
, disp
, old_dsurf
);
1491 dri2_dpy
->core
->unbindContext(old_cctx
);
1494 unbind
= (cctx
== NULL
&& ddraw
== NULL
&& rdraw
== NULL
);
1496 if (!unbind
&& !dri2_dpy
->core
->bindContext(cctx
, ddraw
, rdraw
)) {
1497 /* undo the previous _eglBindContext */
1498 _eglBindContext(old_ctx
, old_dsurf
, old_rsurf
, &ctx
, &tmp_dsurf
, &tmp_rsurf
);
1499 assert(&dri2_ctx
->base
== ctx
&&
1500 tmp_dsurf
== dsurf
&&
1501 tmp_rsurf
== rsurf
);
1503 _eglPutSurface(dsurf
);
1504 _eglPutSurface(rsurf
);
1505 _eglPutContext(ctx
);
1507 _eglPutSurface(old_dsurf
);
1508 _eglPutSurface(old_rsurf
);
1509 _eglPutContext(old_ctx
);
1511 /* dri2_dpy->core->bindContext failed. We cannot tell for sure why, but
1512 * setting the error to EGL_BAD_MATCH is surely better than leaving it
1515 return _eglError(EGL_BAD_MATCH
, "eglMakeCurrent");
1518 dri2_destroy_surface(drv
, disp
, old_dsurf
);
1519 dri2_destroy_surface(drv
, disp
, old_rsurf
);
1522 dri2_dpy
->ref_count
++;
1525 EGLDisplay old_disp
= _eglGetDisplayHandle(old_ctx
->Resource
.Display
);
1526 dri2_destroy_context(drv
, disp
, old_ctx
);
1527 dri2_display_release(old_disp
);
1534 dri2_surface_get_dri_drawable(_EGLSurface
*surf
)
1536 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
1538 return dri2_surf
->dri_drawable
;
1542 * Called from eglGetProcAddress() via drv->API.GetProcAddress().
1545 dri2_get_proc_address(_EGLDriver
*drv
, const char *procname
)
1547 return _glapi_get_proc_address(procname
);
1551 dri2_create_window_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
1552 _EGLConfig
*conf
, void *native_window
,
1553 const EGLint
*attrib_list
)
1555 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1556 return dri2_dpy
->vtbl
->create_window_surface(drv
, dpy
, conf
, native_window
,
1561 dri2_create_pixmap_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
1562 _EGLConfig
*conf
, void *native_pixmap
,
1563 const EGLint
*attrib_list
)
1565 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1566 return dri2_dpy
->vtbl
->create_pixmap_surface(drv
, dpy
, conf
, native_pixmap
,
1571 dri2_create_pbuffer_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
1572 _EGLConfig
*conf
, const EGLint
*attrib_list
)
1574 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1575 return dri2_dpy
->vtbl
->create_pbuffer_surface(drv
, dpy
, conf
, attrib_list
);
1579 dri2_swap_interval(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
1582 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1583 if (!dri2_dpy
->vtbl
->swap_interval
)
1585 return dri2_dpy
->vtbl
->swap_interval(drv
, dpy
, surf
, interval
);
1589 * Asks the client API to flush any rendering to the drawable so that we can
1590 * do our swapbuffers.
1593 dri2_flush_drawable_for_swapbuffers(_EGLDisplay
*disp
, _EGLSurface
*draw
)
1595 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1596 __DRIdrawable
*dri_drawable
= dri2_dpy
->vtbl
->get_dri_drawable(draw
);
1598 if (dri2_dpy
->flush
) {
1599 if (dri2_dpy
->flush
->base
.version
>= 4) {
1600 /* We know there's a current context because:
1602 * "If surface is not bound to the calling thread’s current
1603 * context, an EGL_BAD_SURFACE error is generated."
1605 _EGLContext
*ctx
= _eglGetCurrentContext();
1606 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
1608 /* From the EGL 1.4 spec (page 52):
1610 * "The contents of ancillary buffers are always undefined
1611 * after calling eglSwapBuffers."
1613 dri2_dpy
->flush
->flush_with_flags(dri2_ctx
->dri_context
,
1615 __DRI2_FLUSH_DRAWABLE
|
1616 __DRI2_FLUSH_INVALIDATE_ANCILLARY
,
1617 __DRI2_THROTTLE_SWAPBUFFER
);
1619 dri2_dpy
->flush
->flush(dri_drawable
);
1625 dri2_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
)
1627 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1628 _EGLContext
*ctx
= _eglGetCurrentContext();
1631 dri2_surf_update_fence_fd(ctx
, dpy
, surf
);
1632 return dri2_dpy
->vtbl
->swap_buffers(drv
, dpy
, surf
);
1636 dri2_swap_buffers_with_damage(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
1638 const EGLint
*rects
, EGLint n_rects
)
1640 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1641 _EGLContext
*ctx
= _eglGetCurrentContext();
1644 dri2_surf_update_fence_fd(ctx
, dpy
, surf
);
1645 return dri2_dpy
->vtbl
->swap_buffers_with_damage(drv
, dpy
, surf
,
1650 dri2_swap_buffers_region(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
1651 EGLint numRects
, const EGLint
*rects
)
1653 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1654 return dri2_dpy
->vtbl
->swap_buffers_region(drv
, dpy
, surf
, numRects
, rects
);
1658 dri2_set_damage_region(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
1659 EGLint
*rects
, EGLint n_rects
)
1661 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1662 return dri2_dpy
->vtbl
->set_damage_region(drv
, dpy
, surf
, rects
, n_rects
);
1666 dri2_post_sub_buffer(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
1667 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
1669 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1670 return dri2_dpy
->vtbl
->post_sub_buffer(drv
, dpy
, surf
, x
, y
, width
, height
);
1674 dri2_copy_buffers(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
1675 void *native_pixmap_target
)
1677 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1678 return dri2_dpy
->vtbl
->copy_buffers(drv
, dpy
, surf
, native_pixmap_target
);
1682 dri2_query_buffer_age(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
)
1684 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1685 return dri2_dpy
->vtbl
->query_buffer_age(drv
, dpy
, surf
);
1689 dri2_wait_client(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLContext
*ctx
)
1691 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1692 _EGLSurface
*surf
= ctx
->DrawSurface
;
1693 __DRIdrawable
*dri_drawable
= dri2_dpy
->vtbl
->get_dri_drawable(surf
);
1697 /* FIXME: If EGL allows frontbuffer rendering for window surfaces,
1698 * we need to copy fake to real here.*/
1700 if (dri2_dpy
->flush
!= NULL
)
1701 dri2_dpy
->flush
->flush(dri_drawable
);
1707 dri2_wait_native(_EGLDriver
*drv
, _EGLDisplay
*disp
, EGLint engine
)
1712 if (engine
!= EGL_CORE_NATIVE_ENGINE
)
1713 return _eglError(EGL_BAD_PARAMETER
, "eglWaitNative");
1720 dri2_bind_tex_image(_EGLDriver
*drv
,
1721 _EGLDisplay
*disp
, _EGLSurface
*surf
, EGLint buffer
)
1723 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1724 struct dri2_egl_context
*dri2_ctx
;
1726 GLint format
, target
;
1727 __DRIdrawable
*dri_drawable
= dri2_dpy
->vtbl
->get_dri_drawable(surf
);
1729 ctx
= _eglGetCurrentContext();
1730 dri2_ctx
= dri2_egl_context(ctx
);
1732 if (!_eglBindTexImage(drv
, disp
, surf
, buffer
))
1735 switch (surf
->TextureFormat
) {
1736 case EGL_TEXTURE_RGB
:
1737 format
= __DRI_TEXTURE_FORMAT_RGB
;
1739 case EGL_TEXTURE_RGBA
:
1740 format
= __DRI_TEXTURE_FORMAT_RGBA
;
1743 assert(!"Unexpected texture format in dri2_bind_tex_image()");
1744 format
= __DRI_TEXTURE_FORMAT_RGBA
;
1747 switch (surf
->TextureTarget
) {
1748 case EGL_TEXTURE_2D
:
1749 target
= GL_TEXTURE_2D
;
1752 target
= GL_TEXTURE_2D
;
1753 assert(!"Unexpected texture target in dri2_bind_tex_image()");
1756 dri2_dpy
->tex_buffer
->setTexBuffer2(dri2_ctx
->dri_context
,
1764 dri2_release_tex_image(_EGLDriver
*drv
,
1765 _EGLDisplay
*disp
, _EGLSurface
*surf
, EGLint buffer
)
1767 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1768 struct dri2_egl_context
*dri2_ctx
;
1771 __DRIdrawable
*dri_drawable
= dri2_dpy
->vtbl
->get_dri_drawable(surf
);
1773 ctx
= _eglGetCurrentContext();
1774 dri2_ctx
= dri2_egl_context(ctx
);
1776 if (!_eglReleaseTexImage(drv
, disp
, surf
, buffer
))
1779 switch (surf
->TextureTarget
) {
1780 case EGL_TEXTURE_2D
:
1781 target
= GL_TEXTURE_2D
;
1787 if (dri2_dpy
->tex_buffer
->base
.version
>= 3 &&
1788 dri2_dpy
->tex_buffer
->releaseTexBuffer
!= NULL
) {
1789 dri2_dpy
->tex_buffer
->releaseTexBuffer(dri2_ctx
->dri_context
,
1790 target
, dri_drawable
);
1797 dri2_create_image(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLContext
*ctx
,
1798 EGLenum target
, EGLClientBuffer buffer
,
1799 const EGLint
*attr_list
)
1801 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1802 return dri2_dpy
->vtbl
->create_image(drv
, dpy
, ctx
, target
, buffer
,
1807 dri2_create_image_from_dri(_EGLDisplay
*disp
, __DRIimage
*dri_image
)
1809 struct dri2_egl_image
*dri2_img
;
1811 if (dri_image
== NULL
) {
1812 _eglError(EGL_BAD_ALLOC
, "dri2_create_image");
1816 dri2_img
= malloc(sizeof *dri2_img
);
1818 _eglError(EGL_BAD_ALLOC
, "dri2_create_image");
1822 _eglInitImage(&dri2_img
->base
, disp
);
1824 dri2_img
->dri_image
= dri_image
;
1826 return &dri2_img
->base
;
1830 * Translate a DRI Image extension error code into an EGL error code.
1833 egl_error_from_dri_image_error(int dri_error
)
1835 switch (dri_error
) {
1836 case __DRI_IMAGE_ERROR_SUCCESS
:
1838 case __DRI_IMAGE_ERROR_BAD_ALLOC
:
1839 return EGL_BAD_ALLOC
;
1840 case __DRI_IMAGE_ERROR_BAD_MATCH
:
1841 return EGL_BAD_MATCH
;
1842 case __DRI_IMAGE_ERROR_BAD_PARAMETER
:
1843 return EGL_BAD_PARAMETER
;
1844 case __DRI_IMAGE_ERROR_BAD_ACCESS
:
1845 return EGL_BAD_ACCESS
;
1848 return EGL_BAD_ALLOC
;
1853 dri2_create_image_khr_renderbuffer(_EGLDisplay
*disp
, _EGLContext
*ctx
,
1854 EGLClientBuffer buffer
,
1855 const EGLint
*attr_list
)
1857 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1858 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
1859 GLuint renderbuffer
= (GLuint
) (uintptr_t) buffer
;
1860 __DRIimage
*dri_image
;
1862 if (renderbuffer
== 0) {
1863 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
1864 return EGL_NO_IMAGE_KHR
;
1867 if (!disp
->Extensions
.KHR_gl_renderbuffer_image
) {
1868 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
1869 return EGL_NO_IMAGE_KHR
;
1872 if (dri2_dpy
->image
->base
.version
>= 17 &&
1873 dri2_dpy
->image
->createImageFromRenderbuffer2
) {
1874 unsigned error
= ~0;
1876 dri_image
= dri2_dpy
->image
->createImageFromRenderbuffer2(
1877 dri2_ctx
->dri_context
, renderbuffer
, NULL
, &error
);
1879 assert(!!dri_image
== (error
== __DRI_IMAGE_ERROR_SUCCESS
));
1882 _eglError(egl_error_from_dri_image_error(error
), "dri2_create_image_khr");
1883 return EGL_NO_IMAGE_KHR
;
1886 dri_image
= dri2_dpy
->image
->createImageFromRenderbuffer(
1887 dri2_ctx
->dri_context
, renderbuffer
, NULL
);
1889 _eglError(EGL_BAD_ALLOC
, "dri2_create_image_khr");
1890 return EGL_NO_IMAGE_KHR
;
1894 return dri2_create_image_from_dri(disp
, dri_image
);
1897 #ifdef HAVE_WAYLAND_PLATFORM
1899 /* This structure describes how a wl_buffer maps to one or more
1900 * __DRIimages. A wl_drm_buffer stores the wl_drm format code and the
1901 * offsets and strides of the planes in the buffer. This table maps a
1902 * wl_drm format code to a description of the planes in the buffer
1903 * that lets us create a __DRIimage for each of the planes. */
1905 static const struct wl_drm_components_descriptor
{
1906 uint32_t dri_components
;
1909 } wl_drm_components
[] = {
1910 { __DRI_IMAGE_COMPONENTS_RGB
, EGL_TEXTURE_RGB
, 1 },
1911 { __DRI_IMAGE_COMPONENTS_RGBA
, EGL_TEXTURE_RGBA
, 1 },
1912 { __DRI_IMAGE_COMPONENTS_Y_U_V
, EGL_TEXTURE_Y_U_V_WL
, 3 },
1913 { __DRI_IMAGE_COMPONENTS_Y_UV
, EGL_TEXTURE_Y_UV_WL
, 2 },
1914 { __DRI_IMAGE_COMPONENTS_Y_XUXV
, EGL_TEXTURE_Y_XUXV_WL
, 2 },
1918 dri2_create_image_wayland_wl_buffer(_EGLDisplay
*disp
, _EGLContext
*ctx
,
1919 EGLClientBuffer _buffer
,
1920 const EGLint
*attr_list
)
1922 struct wl_drm_buffer
*buffer
;
1923 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1924 const struct wl_drm_components_descriptor
*f
;
1925 __DRIimage
*dri_image
;
1926 _EGLImageAttribs attrs
;
1929 buffer
= wayland_drm_buffer_get(dri2_dpy
->wl_server_drm
,
1930 (struct wl_resource
*) _buffer
);
1934 if (!_eglParseImageAttribList(&attrs
, disp
, attr_list
))
1937 plane
= attrs
.PlaneWL
;
1938 f
= buffer
->driver_format
;
1939 if (plane
< 0 || plane
>= f
->nplanes
) {
1940 _eglError(EGL_BAD_PARAMETER
,
1941 "dri2_create_image_wayland_wl_buffer (plane out of bounds)");
1945 dri_image
= dri2_dpy
->image
->fromPlanar(buffer
->driver_buffer
, plane
, NULL
);
1946 if (dri_image
== NULL
&& plane
== 0)
1947 dri_image
= dri2_dpy
->image
->dupImage(buffer
->driver_buffer
, NULL
);
1948 if (dri_image
== NULL
) {
1949 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_wayland_wl_buffer");
1953 return dri2_create_image_from_dri(disp
, dri_image
);
1958 dri2_get_sync_values_chromium(_EGLDisplay
*dpy
, _EGLSurface
*surf
,
1959 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
1962 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1963 return dri2_dpy
->vtbl
->get_sync_values(dpy
, surf
, ust
, msc
, sbc
);
1967 * Set the error code after a call to
1968 * dri2_egl_image::dri_image::createImageFromTexture.
1971 dri2_create_image_khr_texture_error(int dri_error
)
1973 EGLint egl_error
= egl_error_from_dri_image_error(dri_error
);
1975 if (egl_error
!= EGL_SUCCESS
)
1976 _eglError(egl_error
, "dri2_create_image_khr_texture");
1980 dri2_create_image_khr_texture(_EGLDisplay
*disp
, _EGLContext
*ctx
,
1982 EGLClientBuffer buffer
,
1983 const EGLint
*attr_list
)
1985 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1986 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
1987 struct dri2_egl_image
*dri2_img
;
1988 GLuint texture
= (GLuint
) (uintptr_t) buffer
;
1989 _EGLImageAttribs attrs
;
1995 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
1996 return EGL_NO_IMAGE_KHR
;
1999 if (!_eglParseImageAttribList(&attrs
, disp
, attr_list
))
2000 return EGL_NO_IMAGE_KHR
;
2003 case EGL_GL_TEXTURE_2D_KHR
:
2004 if (!disp
->Extensions
.KHR_gl_texture_2D_image
) {
2005 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
2006 return EGL_NO_IMAGE_KHR
;
2009 gl_target
= GL_TEXTURE_2D
;
2011 case EGL_GL_TEXTURE_3D_KHR
:
2012 if (!disp
->Extensions
.KHR_gl_texture_3D_image
) {
2013 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
2014 return EGL_NO_IMAGE_KHR
;
2017 depth
= attrs
.GLTextureZOffset
;
2018 gl_target
= GL_TEXTURE_3D
;
2020 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR
:
2021 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR
:
2022 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR
:
2023 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR
:
2024 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR
:
2025 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR
:
2026 if (!disp
->Extensions
.KHR_gl_texture_cubemap_image
) {
2027 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
2028 return EGL_NO_IMAGE_KHR
;
2031 depth
= target
- EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR
;
2032 gl_target
= GL_TEXTURE_CUBE_MAP
;
2035 unreachable("Unexpected target in dri2_create_image_khr_texture()");
2036 return EGL_NO_IMAGE_KHR
;
2039 dri2_img
= malloc(sizeof *dri2_img
);
2041 _eglError(EGL_BAD_ALLOC
, "dri2_create_image_khr");
2042 return EGL_NO_IMAGE_KHR
;
2045 _eglInitImage(&dri2_img
->base
, disp
);
2047 dri2_img
->dri_image
=
2048 dri2_dpy
->image
->createImageFromTexture(dri2_ctx
->dri_context
,
2052 attrs
.GLTextureLevel
,
2055 dri2_create_image_khr_texture_error(error
);
2057 if (!dri2_img
->dri_image
) {
2059 return EGL_NO_IMAGE_KHR
;
2061 return &dri2_img
->base
;
2065 dri2_query_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
2066 EGLint attribute
, EGLint
*value
)
2068 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
2069 if (!dri2_dpy
->vtbl
->query_surface
)
2070 return _eglQuerySurface(drv
, dpy
, surf
, attribute
, value
);
2071 return dri2_dpy
->vtbl
->query_surface(drv
, dpy
, surf
, attribute
, value
);
2074 static struct wl_buffer
*
2075 dri2_create_wayland_buffer_from_image(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
2078 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
2079 return dri2_dpy
->vtbl
->create_wayland_buffer_from_image(drv
, dpy
, img
);
2084 dri2_create_image_mesa_drm_buffer(_EGLDisplay
*disp
, _EGLContext
*ctx
,
2085 EGLClientBuffer buffer
, const EGLint
*attr_list
)
2087 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2088 EGLint format
, name
, pitch
;
2089 _EGLImageAttribs attrs
;
2090 __DRIimage
*dri_image
;
2092 name
= (EGLint
) (uintptr_t) buffer
;
2094 if (!_eglParseImageAttribList(&attrs
, disp
, attr_list
))
2097 if (attrs
.Width
<= 0 || attrs
.Height
<= 0 ||
2098 attrs
.DRMBufferStrideMESA
<= 0) {
2099 _eglError(EGL_BAD_PARAMETER
,
2100 "bad width, height or stride");
2104 switch (attrs
.DRMBufferFormatMESA
) {
2105 case EGL_DRM_BUFFER_FORMAT_ARGB32_MESA
:
2106 format
= __DRI_IMAGE_FORMAT_ARGB8888
;
2107 pitch
= attrs
.DRMBufferStrideMESA
;
2110 _eglError(EGL_BAD_PARAMETER
,
2111 "dri2_create_image_khr: unsupported pixmap depth");
2116 dri2_dpy
->image
->createImageFromName(dri2_dpy
->dri_screen
,
2124 return dri2_create_image_from_dri(disp
, dri_image
);
2128 dri2_check_dma_buf_attribs(const _EGLImageAttribs
*attrs
)
2133 * "Required attributes and their values are as follows:
2135 * * EGL_WIDTH & EGL_HEIGHT: The logical dimensions of the buffer in pixels
2137 * * EGL_LINUX_DRM_FOURCC_EXT: The pixel format of the buffer, as specified
2138 * by drm_fourcc.h and used as the pixel_format parameter of the
2139 * drm_mode_fb_cmd2 ioctl."
2143 * "* If <target> is EGL_LINUX_DMA_BUF_EXT, and the list of attributes is
2144 * incomplete, EGL_BAD_PARAMETER is generated."
2146 if (attrs
->Width
<= 0 || attrs
->Height
<= 0 ||
2147 !attrs
->DMABufFourCC
.IsPresent
)
2148 return _eglError(EGL_BAD_PARAMETER
, "attribute(s) missing");
2153 * "If <target> is EGL_LINUX_DMA_BUF_EXT and one or more of the values
2154 * specified for a plane's pitch or offset isn't supported by EGL,
2155 * EGL_BAD_ACCESS is generated."
2157 for (unsigned i
= 0; i
< ARRAY_SIZE(attrs
->DMABufPlanePitches
); ++i
) {
2158 if (attrs
->DMABufPlanePitches
[i
].IsPresent
&&
2159 attrs
->DMABufPlanePitches
[i
].Value
<= 0)
2160 return _eglError(EGL_BAD_ACCESS
, "invalid pitch");
2164 * If <target> is EGL_LINUX_DMA_BUF_EXT, both or neither of the following
2165 * attribute values may be given.
2167 * This is referring to EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT and
2168 * EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT, and the same for other planes.
2170 for (unsigned i
= 0; i
< DMA_BUF_MAX_PLANES
; ++i
) {
2171 if (attrs
->DMABufPlaneModifiersLo
[i
].IsPresent
!=
2172 attrs
->DMABufPlaneModifiersHi
[i
].IsPresent
)
2173 return _eglError(EGL_BAD_PARAMETER
, "modifier attribute lo or hi missing");
2176 /* Although the EGL_EXT_image_dma_buf_import_modifiers spec doesn't
2177 * mandate it, we only accept the same modifier across all planes. */
2178 for (unsigned i
= 1; i
< DMA_BUF_MAX_PLANES
; ++i
) {
2179 if (attrs
->DMABufPlaneFds
[i
].IsPresent
) {
2180 if ((attrs
->DMABufPlaneModifiersLo
[0].IsPresent
!=
2181 attrs
->DMABufPlaneModifiersLo
[i
].IsPresent
) ||
2182 (attrs
->DMABufPlaneModifiersLo
[0].Value
!=
2183 attrs
->DMABufPlaneModifiersLo
[i
].Value
) ||
2184 (attrs
->DMABufPlaneModifiersHi
[0].Value
!=
2185 attrs
->DMABufPlaneModifiersHi
[i
].Value
))
2186 return _eglError(EGL_BAD_PARAMETER
, "modifier attributes not equal");
2193 /* Returns the total number of file descriptors. Zero indicates an error. */
2195 dri2_check_dma_buf_format(const _EGLImageAttribs
*attrs
)
2199 switch (attrs
->DMABufFourCC
.Value
) {
2201 case DRM_FORMAT_RG88
:
2202 case DRM_FORMAT_GR88
:
2203 case DRM_FORMAT_R16
:
2204 case DRM_FORMAT_GR1616
:
2205 case DRM_FORMAT_RGB332
:
2206 case DRM_FORMAT_BGR233
:
2207 case DRM_FORMAT_XRGB4444
:
2208 case DRM_FORMAT_XBGR4444
:
2209 case DRM_FORMAT_RGBX4444
:
2210 case DRM_FORMAT_BGRX4444
:
2211 case DRM_FORMAT_ARGB4444
:
2212 case DRM_FORMAT_ABGR4444
:
2213 case DRM_FORMAT_RGBA4444
:
2214 case DRM_FORMAT_BGRA4444
:
2215 case DRM_FORMAT_XRGB1555
:
2216 case DRM_FORMAT_XBGR1555
:
2217 case DRM_FORMAT_RGBX5551
:
2218 case DRM_FORMAT_BGRX5551
:
2219 case DRM_FORMAT_ARGB1555
:
2220 case DRM_FORMAT_ABGR1555
:
2221 case DRM_FORMAT_RGBA5551
:
2222 case DRM_FORMAT_BGRA5551
:
2223 case DRM_FORMAT_RGB565
:
2224 case DRM_FORMAT_BGR565
:
2225 case DRM_FORMAT_RGB888
:
2226 case DRM_FORMAT_BGR888
:
2227 case DRM_FORMAT_XRGB8888
:
2228 case DRM_FORMAT_XBGR8888
:
2229 case DRM_FORMAT_RGBX8888
:
2230 case DRM_FORMAT_BGRX8888
:
2231 case DRM_FORMAT_ARGB8888
:
2232 case DRM_FORMAT_ABGR8888
:
2233 case DRM_FORMAT_RGBA8888
:
2234 case DRM_FORMAT_BGRA8888
:
2235 case DRM_FORMAT_XRGB2101010
:
2236 case DRM_FORMAT_XBGR2101010
:
2237 case DRM_FORMAT_RGBX1010102
:
2238 case DRM_FORMAT_BGRX1010102
:
2239 case DRM_FORMAT_ARGB2101010
:
2240 case DRM_FORMAT_ABGR2101010
:
2241 case DRM_FORMAT_RGBA1010102
:
2242 case DRM_FORMAT_BGRA1010102
:
2243 case DRM_FORMAT_YUYV
:
2244 case DRM_FORMAT_YVYU
:
2245 case DRM_FORMAT_UYVY
:
2246 case DRM_FORMAT_VYUY
:
2249 case DRM_FORMAT_NV12
:
2250 case DRM_FORMAT_NV21
:
2251 case DRM_FORMAT_NV16
:
2252 case DRM_FORMAT_NV61
:
2255 case DRM_FORMAT_YUV410
:
2256 case DRM_FORMAT_YVU410
:
2257 case DRM_FORMAT_YUV411
:
2258 case DRM_FORMAT_YVU411
:
2259 case DRM_FORMAT_YUV420
:
2260 case DRM_FORMAT_YVU420
:
2261 case DRM_FORMAT_YUV422
:
2262 case DRM_FORMAT_YVU422
:
2263 case DRM_FORMAT_YUV444
:
2264 case DRM_FORMAT_YVU444
:
2268 _eglError(EGL_BAD_ATTRIBUTE
, "invalid format");
2272 for (unsigned i
= plane_n
; i
< DMA_BUF_MAX_PLANES
; i
++) {
2274 * The modifiers extension spec says:
2276 * "Modifiers may modify any attribute of a buffer import, including
2277 * but not limited to adding extra planes to a format which
2278 * otherwise does not have those planes. As an example, a modifier
2279 * may add a plane for an external compression buffer to a
2280 * single-plane format. The exact meaning and effect of any
2281 * modifier is canonically defined by drm_fourcc.h, not as part of
2284 if (attrs
->DMABufPlaneModifiersLo
[i
].IsPresent
&&
2285 attrs
->DMABufPlaneModifiersHi
[i
].IsPresent
) {
2293 * "* If <target> is EGL_LINUX_DMA_BUF_EXT, and the list of attributes is
2294 * incomplete, EGL_BAD_PARAMETER is generated."
2296 for (unsigned i
= 0; i
< plane_n
; ++i
) {
2297 if (!attrs
->DMABufPlaneFds
[i
].IsPresent
||
2298 !attrs
->DMABufPlaneOffsets
[i
].IsPresent
||
2299 !attrs
->DMABufPlanePitches
[i
].IsPresent
) {
2300 _eglError(EGL_BAD_PARAMETER
, "plane attribute(s) missing");
2306 * The spec also says:
2308 * "If <target> is EGL_LINUX_DMA_BUF_EXT, and the EGL_LINUX_DRM_FOURCC_EXT
2309 * attribute indicates a single-plane format, EGL_BAD_ATTRIBUTE is
2310 * generated if any of the EGL_DMA_BUF_PLANE1_* or EGL_DMA_BUF_PLANE2_*
2311 * or EGL_DMA_BUF_PLANE3_* attributes are specified."
2313 for (unsigned i
= plane_n
; i
< DMA_BUF_MAX_PLANES
; ++i
) {
2314 if (attrs
->DMABufPlaneFds
[i
].IsPresent
||
2315 attrs
->DMABufPlaneOffsets
[i
].IsPresent
||
2316 attrs
->DMABufPlanePitches
[i
].IsPresent
) {
2317 _eglError(EGL_BAD_ATTRIBUTE
, "too many plane attributes");
2326 dri2_query_dma_buf_formats(_EGLDriver
*drv
, _EGLDisplay
*disp
,
2327 EGLint max
, EGLint
*formats
, EGLint
*count
)
2329 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2330 if (max
< 0 || (max
> 0 && formats
== NULL
))
2331 return _eglError(EGL_BAD_PARAMETER
, "invalid value for max count of formats");
2333 if (dri2_dpy
->image
->base
.version
< 15 ||
2334 dri2_dpy
->image
->queryDmaBufFormats
== NULL
)
2337 if (!dri2_dpy
->image
->queryDmaBufFormats(dri2_dpy
->dri_screen
, max
,
2345 dri2_query_dma_buf_modifiers(_EGLDriver
*drv
, _EGLDisplay
*disp
, EGLint format
,
2346 EGLint max
, EGLuint64KHR
*modifiers
,
2347 EGLBoolean
*external_only
, EGLint
*count
)
2349 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2352 return _eglError(EGL_BAD_PARAMETER
, "invalid value for max count of formats");
2354 if (max
> 0 && modifiers
== NULL
)
2355 return _eglError(EGL_BAD_PARAMETER
, "invalid modifiers array");
2357 if (dri2_dpy
->image
->base
.version
< 15 ||
2358 dri2_dpy
->image
->queryDmaBufModifiers
== NULL
)
2361 if (dri2_dpy
->image
->queryDmaBufModifiers(dri2_dpy
->dri_screen
, format
,
2363 (unsigned int *) external_only
,
2365 return _eglError(EGL_BAD_PARAMETER
, "invalid format");
2373 * "If eglCreateImageKHR is successful for a EGL_LINUX_DMA_BUF_EXT target, the
2374 * EGL will take a reference to the dma_buf(s) which it will release at any
2375 * time while the EGLDisplay is initialized. It is the responsibility of the
2376 * application to close the dma_buf file descriptors."
2378 * Therefore we must never close or otherwise modify the file descriptors.
2381 dri2_create_image_dma_buf(_EGLDisplay
*disp
, _EGLContext
*ctx
,
2382 EGLClientBuffer buffer
, const EGLint
*attr_list
)
2384 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2386 _EGLImageAttribs attrs
;
2387 __DRIimage
*dri_image
;
2389 int fds
[DMA_BUF_MAX_PLANES
];
2390 int pitches
[DMA_BUF_MAX_PLANES
];
2391 int offsets
[DMA_BUF_MAX_PLANES
];
2393 bool has_modifier
= false;
2399 * ""* If <target> is EGL_LINUX_DMA_BUF_EXT and <buffer> is not NULL, the
2400 * error EGL_BAD_PARAMETER is generated."
2402 if (buffer
!= NULL
) {
2403 _eglError(EGL_BAD_PARAMETER
, "buffer not NULL");
2407 if (!_eglParseImageAttribList(&attrs
, disp
, attr_list
))
2410 if (!dri2_check_dma_buf_attribs(&attrs
))
2413 num_fds
= dri2_check_dma_buf_format(&attrs
);
2417 for (unsigned i
= 0; i
< num_fds
; ++i
) {
2418 fds
[i
] = attrs
.DMABufPlaneFds
[i
].Value
;
2419 pitches
[i
] = attrs
.DMABufPlanePitches
[i
].Value
;
2420 offsets
[i
] = attrs
.DMABufPlaneOffsets
[i
].Value
;
2423 /* dri2_check_dma_buf_attribs ensures that the modifier, if available,
2424 * will be present in attrs.DMABufPlaneModifiersLo[0] and
2425 * attrs.DMABufPlaneModifiersHi[0] */
2426 if (attrs
.DMABufPlaneModifiersLo
[0].IsPresent
) {
2427 modifier
= combine_u32_into_u64(attrs
.DMABufPlaneModifiersHi
[0].Value
,
2428 attrs
.DMABufPlaneModifiersLo
[0].Value
);
2429 has_modifier
= true;
2433 if (dri2_dpy
->image
->base
.version
< 15 ||
2434 dri2_dpy
->image
->createImageFromDmaBufs2
== NULL
) {
2435 _eglError(EGL_BAD_MATCH
, "unsupported dma_buf format modifier");
2436 return EGL_NO_IMAGE_KHR
;
2439 dri2_dpy
->image
->createImageFromDmaBufs2(dri2_dpy
->dri_screen
,
2440 attrs
.Width
, attrs
.Height
, attrs
.DMABufFourCC
.Value
,
2441 modifier
, fds
, num_fds
, pitches
, offsets
,
2442 attrs
.DMABufYuvColorSpaceHint
.Value
,
2443 attrs
.DMABufSampleRangeHint
.Value
,
2444 attrs
.DMABufChromaHorizontalSiting
.Value
,
2445 attrs
.DMABufChromaVerticalSiting
.Value
,
2451 dri2_dpy
->image
->createImageFromDmaBufs(dri2_dpy
->dri_screen
,
2452 attrs
.Width
, attrs
.Height
, attrs
.DMABufFourCC
.Value
,
2453 fds
, num_fds
, pitches
, offsets
,
2454 attrs
.DMABufYuvColorSpaceHint
.Value
,
2455 attrs
.DMABufSampleRangeHint
.Value
,
2456 attrs
.DMABufChromaHorizontalSiting
.Value
,
2457 attrs
.DMABufChromaVerticalSiting
.Value
,
2461 dri2_create_image_khr_texture_error(error
);
2464 return EGL_NO_IMAGE_KHR
;
2466 res
= dri2_create_image_from_dri(disp
, dri_image
);
2471 dri2_create_drm_image_mesa(_EGLDriver
*drv
, _EGLDisplay
*disp
,
2472 const EGLint
*attr_list
)
2474 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2475 struct dri2_egl_image
*dri2_img
;
2476 _EGLImageAttribs attrs
;
2477 unsigned int dri_use
, valid_mask
;
2483 _eglError(EGL_BAD_PARAMETER
, __func__
);
2484 return EGL_NO_IMAGE_KHR
;
2487 if (!_eglParseImageAttribList(&attrs
, disp
, attr_list
))
2488 return EGL_NO_IMAGE_KHR
;
2490 if (attrs
.Width
<= 0 || attrs
.Height
<= 0) {
2491 _eglError(EGL_BAD_PARAMETER
, __func__
);
2492 return EGL_NO_IMAGE_KHR
;
2495 switch (attrs
.DRMBufferFormatMESA
) {
2496 case EGL_DRM_BUFFER_FORMAT_ARGB32_MESA
:
2497 format
= __DRI_IMAGE_FORMAT_ARGB8888
;
2500 _eglError(EGL_BAD_PARAMETER
, __func__
);
2501 return EGL_NO_IMAGE_KHR
;
2505 EGL_DRM_BUFFER_USE_SCANOUT_MESA
|
2506 EGL_DRM_BUFFER_USE_SHARE_MESA
|
2507 EGL_DRM_BUFFER_USE_CURSOR_MESA
;
2508 if (attrs
.DRMBufferUseMESA
& ~valid_mask
) {
2509 _eglError(EGL_BAD_PARAMETER
, __func__
);
2510 return EGL_NO_IMAGE_KHR
;
2514 if (attrs
.DRMBufferUseMESA
& EGL_DRM_BUFFER_USE_SHARE_MESA
)
2515 dri_use
|= __DRI_IMAGE_USE_SHARE
;
2516 if (attrs
.DRMBufferUseMESA
& EGL_DRM_BUFFER_USE_SCANOUT_MESA
)
2517 dri_use
|= __DRI_IMAGE_USE_SCANOUT
;
2518 if (attrs
.DRMBufferUseMESA
& EGL_DRM_BUFFER_USE_CURSOR_MESA
)
2519 dri_use
|= __DRI_IMAGE_USE_CURSOR
;
2521 dri2_img
= malloc(sizeof *dri2_img
);
2523 _eglError(EGL_BAD_ALLOC
, "dri2_create_image_khr");
2524 return EGL_NO_IMAGE_KHR
;
2527 _eglInitImage(&dri2_img
->base
, disp
);
2529 dri2_img
->dri_image
=
2530 dri2_dpy
->image
->createImage(dri2_dpy
->dri_screen
,
2531 attrs
.Width
, attrs
.Height
,
2532 format
, dri_use
, dri2_img
);
2533 if (dri2_img
->dri_image
== NULL
) {
2535 _eglError(EGL_BAD_ALLOC
, "dri2_create_drm_image_mesa");
2536 return EGL_NO_IMAGE_KHR
;
2539 return &dri2_img
->base
;
2543 dri2_export_drm_image_mesa(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLImage
*img
,
2544 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
2546 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2547 struct dri2_egl_image
*dri2_img
= dri2_egl_image(img
);
2551 if (name
&& !dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2552 __DRI_IMAGE_ATTRIB_NAME
, name
))
2553 return _eglError(EGL_BAD_ALLOC
, "dri2_export_drm_image_mesa");
2556 dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2557 __DRI_IMAGE_ATTRIB_HANDLE
, handle
);
2560 dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2561 __DRI_IMAGE_ATTRIB_STRIDE
, stride
);
2567 * Checks if we can support EGL_MESA_image_dma_buf_export on this image.
2569 * The spec provides a boolean return for the driver to reject exporting for
2570 * basically any reason, but doesn't specify any particular error cases. For
2571 * now, we just fail if we don't have a DRM fourcc for the format.
2574 dri2_can_export_dma_buf_image(_EGLDisplay
*disp
, _EGLImage
*img
)
2576 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2577 struct dri2_egl_image
*dri2_img
= dri2_egl_image(img
);
2580 if (!dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2581 __DRI_IMAGE_ATTRIB_FOURCC
, &fourcc
)) {
2589 dri2_export_dma_buf_image_query_mesa(_EGLDriver
*drv
, _EGLDisplay
*disp
,
2591 EGLint
*fourcc
, EGLint
*nplanes
,
2592 EGLuint64KHR
*modifiers
)
2594 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2595 struct dri2_egl_image
*dri2_img
= dri2_egl_image(img
);
2599 if (!dri2_can_export_dma_buf_image(disp
, img
))
2603 dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2604 __DRI_IMAGE_ATTRIB_NUM_PLANES
, nplanes
);
2606 dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2607 __DRI_IMAGE_ATTRIB_FOURCC
, fourcc
);
2616 dri2_export_dma_buf_image_mesa(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLImage
*img
,
2617 int *fds
, EGLint
*strides
, EGLint
*offsets
)
2619 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2620 struct dri2_egl_image
*dri2_img
= dri2_egl_image(img
);
2624 if (!dri2_can_export_dma_buf_image(disp
, img
))
2627 /* rework later to provide multiple fds/strides/offsets */
2629 dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2630 __DRI_IMAGE_ATTRIB_FD
, fds
);
2633 dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2634 __DRI_IMAGE_ATTRIB_STRIDE
, strides
);
2638 bool ret
= dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2639 __DRI_IMAGE_ATTRIB_OFFSET
, &img_offset
);
2641 offsets
[0] = img_offset
;
2652 dri2_create_image_khr(_EGLDriver
*drv
, _EGLDisplay
*disp
,
2653 _EGLContext
*ctx
, EGLenum target
,
2654 EGLClientBuffer buffer
, const EGLint
*attr_list
)
2659 case EGL_GL_TEXTURE_2D_KHR
:
2660 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR
:
2661 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR
:
2662 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR
:
2663 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR
:
2664 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR
:
2665 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR
:
2666 case EGL_GL_TEXTURE_3D_KHR
:
2667 return dri2_create_image_khr_texture(disp
, ctx
, target
, buffer
, attr_list
);
2668 case EGL_GL_RENDERBUFFER_KHR
:
2669 return dri2_create_image_khr_renderbuffer(disp
, ctx
, buffer
, attr_list
);
2671 case EGL_DRM_BUFFER_MESA
:
2672 return dri2_create_image_mesa_drm_buffer(disp
, ctx
, buffer
, attr_list
);
2673 case EGL_LINUX_DMA_BUF_EXT
:
2674 return dri2_create_image_dma_buf(disp
, ctx
, buffer
, attr_list
);
2676 #ifdef HAVE_WAYLAND_PLATFORM
2677 case EGL_WAYLAND_BUFFER_WL
:
2678 return dri2_create_image_wayland_wl_buffer(disp
, ctx
, buffer
, attr_list
);
2681 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
2682 return EGL_NO_IMAGE_KHR
;
2687 dri2_destroy_image_khr(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLImage
*image
)
2689 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2690 struct dri2_egl_image
*dri2_img
= dri2_egl_image(image
);
2694 dri2_dpy
->image
->destroyImage(dri2_img
->dri_image
);
2700 #ifdef HAVE_WAYLAND_PLATFORM
2703 dri2_wl_reference_buffer(void *user_data
, uint32_t name
, int fd
,
2704 struct wl_drm_buffer
*buffer
)
2706 _EGLDisplay
*disp
= user_data
;
2707 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2709 int dri_components
= 0;
2712 img
= dri2_dpy
->image
->createImageFromNames(dri2_dpy
->dri_screen
,
2721 img
= dri2_dpy
->image
->createImageFromFds(dri2_dpy
->dri_screen
,
2733 dri2_dpy
->image
->queryImage(img
, __DRI_IMAGE_ATTRIB_COMPONENTS
, &dri_components
);
2735 buffer
->driver_format
= NULL
;
2736 for (int i
= 0; i
< ARRAY_SIZE(wl_drm_components
); i
++)
2737 if (wl_drm_components
[i
].dri_components
== dri_components
)
2738 buffer
->driver_format
= &wl_drm_components
[i
];
2740 if (buffer
->driver_format
== NULL
)
2741 dri2_dpy
->image
->destroyImage(img
);
2743 buffer
->driver_buffer
= img
;
2747 dri2_wl_release_buffer(void *user_data
, struct wl_drm_buffer
*buffer
)
2749 _EGLDisplay
*disp
= user_data
;
2750 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2752 dri2_dpy
->image
->destroyImage(buffer
->driver_buffer
);
2756 dri2_bind_wayland_display_wl(_EGLDriver
*drv
, _EGLDisplay
*disp
,
2757 struct wl_display
*wl_dpy
)
2759 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2760 const struct wayland_drm_callbacks wl_drm_callbacks
= {
2761 .authenticate
= (int(*)(void *, uint32_t)) dri2_dpy
->vtbl
->authenticate
,
2762 .reference_buffer
= dri2_wl_reference_buffer
,
2763 .release_buffer
= dri2_wl_release_buffer
2770 if (dri2_dpy
->wl_server_drm
)
2773 if (drmGetCap(dri2_dpy
->fd
, DRM_CAP_PRIME
, &cap
) == 0 &&
2774 cap
== (DRM_PRIME_CAP_IMPORT
| DRM_PRIME_CAP_EXPORT
) &&
2775 dri2_dpy
->image
->base
.version
>= 7 &&
2776 dri2_dpy
->image
->createImageFromFds
!= NULL
)
2777 flags
|= WAYLAND_DRM_PRIME
;
2779 dri2_dpy
->wl_server_drm
=
2780 wayland_drm_init(wl_dpy
, dri2_dpy
->device_name
,
2781 &wl_drm_callbacks
, disp
, flags
);
2783 if (!dri2_dpy
->wl_server_drm
)
2786 #ifdef HAVE_DRM_PLATFORM
2787 /* We have to share the wl_drm instance with gbm, so gbm can convert
2788 * wl_buffers to gbm bos. */
2789 if (dri2_dpy
->gbm_dri
)
2790 dri2_dpy
->gbm_dri
->wl_drm
= dri2_dpy
->wl_server_drm
;
2797 dri2_unbind_wayland_display_wl(_EGLDriver
*drv
, _EGLDisplay
*disp
,
2798 struct wl_display
*wl_dpy
)
2800 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2804 if (!dri2_dpy
->wl_server_drm
)
2807 wayland_drm_uninit(dri2_dpy
->wl_server_drm
);
2808 dri2_dpy
->wl_server_drm
= NULL
;
2814 dri2_query_wayland_buffer_wl(_EGLDriver
*drv
, _EGLDisplay
*disp
,
2815 struct wl_resource
*buffer_resource
,
2816 EGLint attribute
, EGLint
*value
)
2818 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2819 struct wl_drm_buffer
*buffer
;
2820 const struct wl_drm_components_descriptor
*format
;
2822 buffer
= wayland_drm_buffer_get(dri2_dpy
->wl_server_drm
, buffer_resource
);
2826 format
= buffer
->driver_format
;
2827 switch (attribute
) {
2828 case EGL_TEXTURE_FORMAT
:
2829 *value
= format
->components
;
2832 *value
= buffer
->width
;
2835 *value
= buffer
->height
;
2844 dri2_egl_ref_sync(struct dri2_egl_sync
*sync
)
2846 p_atomic_inc(&sync
->refcount
);
2850 dri2_egl_unref_sync(struct dri2_egl_display
*dri2_dpy
,
2851 struct dri2_egl_sync
*dri2_sync
)
2853 if (p_atomic_dec_zero(&dri2_sync
->refcount
)) {
2854 switch (dri2_sync
->base
.Type
) {
2855 case EGL_SYNC_REUSABLE_KHR
:
2856 cnd_destroy(&dri2_sync
->cond
);
2858 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
2859 if (dri2_sync
->base
.SyncFd
!= EGL_NO_NATIVE_FENCE_FD_ANDROID
)
2860 close(dri2_sync
->base
.SyncFd
);
2866 if (dri2_sync
->fence
)
2867 dri2_dpy
->fence
->destroy_fence(dri2_dpy
->dri_screen
, dri2_sync
->fence
);
2874 dri2_create_sync(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
2875 EGLenum type
, const EGLAttrib
*attrib_list
)
2877 _EGLContext
*ctx
= _eglGetCurrentContext();
2878 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
2879 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
2880 struct dri2_egl_sync
*dri2_sync
;
2882 pthread_condattr_t attr
;
2884 dri2_sync
= calloc(1, sizeof(struct dri2_egl_sync
));
2886 _eglError(EGL_BAD_ALLOC
, "eglCreateSyncKHR");
2890 if (!_eglInitSync(&dri2_sync
->base
, dpy
, type
, attrib_list
)) {
2896 case EGL_SYNC_FENCE_KHR
:
2897 dri2_sync
->fence
= dri2_dpy
->fence
->create_fence(dri2_ctx
->dri_context
);
2898 if (!dri2_sync
->fence
) {
2899 /* Why did it fail? DRI doesn't return an error code, so we emit
2900 * a generic EGL error that doesn't communicate user error.
2902 _eglError(EGL_BAD_ALLOC
, "eglCreateSyncKHR");
2908 case EGL_SYNC_CL_EVENT_KHR
:
2909 dri2_sync
->fence
= dri2_dpy
->fence
->get_fence_from_cl_event(
2910 dri2_dpy
->dri_screen
,
2911 dri2_sync
->base
.CLEvent
);
2912 /* this can only happen if the cl_event passed in is invalid. */
2913 if (!dri2_sync
->fence
) {
2914 _eglError(EGL_BAD_ATTRIBUTE
, "eglCreateSyncKHR");
2919 /* the initial status must be "signaled" if the cl_event is signaled */
2920 if (dri2_dpy
->fence
->client_wait_sync(dri2_ctx
->dri_context
,
2921 dri2_sync
->fence
, 0, 0))
2922 dri2_sync
->base
.SyncStatus
= EGL_SIGNALED_KHR
;
2925 case EGL_SYNC_REUSABLE_KHR
:
2926 /* intialize attr */
2927 ret
= pthread_condattr_init(&attr
);
2930 _eglError(EGL_BAD_ACCESS
, "eglCreateSyncKHR");
2935 /* change clock attribute to CLOCK_MONOTONIC */
2936 ret
= pthread_condattr_setclock(&attr
, CLOCK_MONOTONIC
);
2939 _eglError(EGL_BAD_ACCESS
, "eglCreateSyncKHR");
2944 ret
= pthread_cond_init(&dri2_sync
->cond
, &attr
);
2947 _eglError(EGL_BAD_ACCESS
, "eglCreateSyncKHR");
2952 /* initial status of reusable sync must be "unsignaled" */
2953 dri2_sync
->base
.SyncStatus
= EGL_UNSIGNALED_KHR
;
2956 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
2957 if (dri2_dpy
->fence
->create_fence_fd
) {
2958 dri2_sync
->fence
= dri2_dpy
->fence
->create_fence_fd(
2959 dri2_ctx
->dri_context
,
2960 dri2_sync
->base
.SyncFd
);
2962 if (!dri2_sync
->fence
) {
2963 _eglError(EGL_BAD_ATTRIBUTE
, "eglCreateSyncKHR");
2970 p_atomic_set(&dri2_sync
->refcount
, 1);
2971 return &dri2_sync
->base
;
2975 dri2_destroy_sync(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSync
*sync
)
2977 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
2978 struct dri2_egl_sync
*dri2_sync
= dri2_egl_sync(sync
);
2979 EGLint ret
= EGL_TRUE
;
2982 /* if type of sync is EGL_SYNC_REUSABLE_KHR and it is not signaled yet,
2983 * then unlock all threads possibly blocked by the reusable sync before
2986 if (dri2_sync
->base
.Type
== EGL_SYNC_REUSABLE_KHR
&&
2987 dri2_sync
->base
.SyncStatus
== EGL_UNSIGNALED_KHR
) {
2988 dri2_sync
->base
.SyncStatus
= EGL_SIGNALED_KHR
;
2989 /* unblock all threads currently blocked by sync */
2990 err
= cnd_broadcast(&dri2_sync
->cond
);
2993 _eglError(EGL_BAD_ACCESS
, "eglDestroySyncKHR");
2998 dri2_egl_unref_sync(dri2_dpy
, dri2_sync
);
3004 dri2_dup_native_fence_fd(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSync
*sync
)
3006 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
3007 struct dri2_egl_sync
*dri2_sync
= dri2_egl_sync(sync
);
3009 assert(sync
->Type
== EGL_SYNC_NATIVE_FENCE_ANDROID
);
3011 if (sync
->SyncFd
== EGL_NO_NATIVE_FENCE_FD_ANDROID
) {
3012 /* try to retrieve the actual native fence fd.. if rendering is
3013 * not flushed this will just return -1, aka NO_NATIVE_FENCE_FD:
3015 sync
->SyncFd
= dri2_dpy
->fence
->get_fence_fd(dri2_dpy
->dri_screen
,
3019 if (sync
->SyncFd
== EGL_NO_NATIVE_FENCE_FD_ANDROID
) {
3020 /* if native fence fd still not created, return an error: */
3021 _eglError(EGL_BAD_PARAMETER
, "eglDupNativeFenceFDANDROID");
3022 return EGL_NO_NATIVE_FENCE_FD_ANDROID
;
3025 return dup(sync
->SyncFd
);
3029 dri2_set_blob_cache_funcs(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
3030 EGLSetBlobFuncANDROID set
,
3031 EGLGetBlobFuncANDROID get
)
3033 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
3034 dri2_dpy
->blob
->set_cache_funcs(dri2_dpy
->dri_screen
,
3040 dri2_client_wait_sync(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSync
*sync
,
3041 EGLint flags
, EGLTime timeout
)
3043 _EGLContext
*ctx
= _eglGetCurrentContext();
3044 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
3045 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
3046 struct dri2_egl_sync
*dri2_sync
= dri2_egl_sync(sync
);
3047 unsigned wait_flags
= 0;
3049 EGLint ret
= EGL_CONDITION_SATISFIED_KHR
;
3051 /* The EGL_KHR_fence_sync spec states:
3053 * "If no context is current for the bound API,
3054 * the EGL_SYNC_FLUSH_COMMANDS_BIT_KHR bit is ignored.
3056 if (dri2_ctx
&& flags
& EGL_SYNC_FLUSH_COMMANDS_BIT_KHR
)
3057 wait_flags
|= __DRI2_FENCE_FLAG_FLUSH_COMMANDS
;
3059 /* the sync object should take a reference while waiting */
3060 dri2_egl_ref_sync(dri2_sync
);
3062 switch (sync
->Type
) {
3063 case EGL_SYNC_FENCE_KHR
:
3064 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
3065 case EGL_SYNC_CL_EVENT_KHR
:
3066 if (dri2_dpy
->fence
->client_wait_sync(dri2_ctx
? dri2_ctx
->dri_context
: NULL
,
3067 dri2_sync
->fence
, wait_flags
,
3069 dri2_sync
->base
.SyncStatus
= EGL_SIGNALED_KHR
;
3071 ret
= EGL_TIMEOUT_EXPIRED_KHR
;
3074 case EGL_SYNC_REUSABLE_KHR
:
3075 if (dri2_ctx
&& dri2_sync
->base
.SyncStatus
== EGL_UNSIGNALED_KHR
&&
3076 (flags
& EGL_SYNC_FLUSH_COMMANDS_BIT_KHR
)) {
3077 /* flush context if EGL_SYNC_FLUSH_COMMANDS_BIT_KHR is set */
3081 /* if timeout is EGL_FOREVER_KHR, it should wait without any timeout.*/
3082 if (timeout
== EGL_FOREVER_KHR
) {
3083 mtx_lock(&dri2_sync
->mutex
);
3084 cnd_wait(&dri2_sync
->cond
, &dri2_sync
->mutex
);
3085 mtx_unlock(&dri2_sync
->mutex
);
3087 /* if reusable sync has not been yet signaled */
3088 if (dri2_sync
->base
.SyncStatus
!= EGL_SIGNALED_KHR
) {
3089 /* timespecs for cnd_timedwait */
3090 struct timespec current
;
3091 struct timespec expire
;
3093 /* We override the clock to monotonic when creating the condition
3095 clock_gettime(CLOCK_MONOTONIC
, ¤t
);
3097 /* calculating when to expire */
3098 expire
.tv_nsec
= timeout
% 1000000000L;
3099 expire
.tv_sec
= timeout
/ 1000000000L;
3101 expire
.tv_nsec
+= current
.tv_nsec
;
3102 expire
.tv_sec
+= current
.tv_sec
;
3104 /* expire.nsec now is a number between 0 and 1999999998 */
3105 if (expire
.tv_nsec
> 999999999L) {
3107 expire
.tv_nsec
-= 1000000000L;
3110 mtx_lock(&dri2_sync
->mutex
);
3111 ret
= cnd_timedwait(&dri2_sync
->cond
, &dri2_sync
->mutex
, &expire
);
3112 mtx_unlock(&dri2_sync
->mutex
);
3114 if (ret
== thrd_busy
) {
3115 if (dri2_sync
->base
.SyncStatus
== EGL_UNSIGNALED_KHR
) {
3116 ret
= EGL_TIMEOUT_EXPIRED_KHR
;
3118 _eglError(EGL_BAD_ACCESS
, "eglClientWaitSyncKHR");
3126 dri2_egl_unref_sync(dri2_dpy
, dri2_sync
);
3132 dri2_signal_sync(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSync
*sync
,
3135 struct dri2_egl_sync
*dri2_sync
= dri2_egl_sync(sync
);
3138 if (sync
->Type
!= EGL_SYNC_REUSABLE_KHR
)
3139 return _eglError(EGL_BAD_MATCH
, "eglSignalSyncKHR");
3141 if (mode
!= EGL_SIGNALED_KHR
&& mode
!= EGL_UNSIGNALED_KHR
)
3142 return _eglError(EGL_BAD_ATTRIBUTE
, "eglSignalSyncKHR");
3144 dri2_sync
->base
.SyncStatus
= mode
;
3146 if (mode
== EGL_SIGNALED_KHR
) {
3147 ret
= cnd_broadcast(&dri2_sync
->cond
);
3149 /* fail to broadcast */
3151 return _eglError(EGL_BAD_ACCESS
, "eglSignalSyncKHR");
3158 dri2_server_wait_sync(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSync
*sync
)
3160 _EGLContext
*ctx
= _eglGetCurrentContext();
3161 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
3162 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
3163 struct dri2_egl_sync
*dri2_sync
= dri2_egl_sync(sync
);
3165 dri2_dpy
->fence
->server_wait_sync(dri2_ctx
->dri_context
,
3166 dri2_sync
->fence
, 0);
3171 dri2_interop_query_device_info(_EGLDisplay
*dpy
, _EGLContext
*ctx
,
3172 struct mesa_glinterop_device_info
*out
)
3174 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
3175 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
3177 if (!dri2_dpy
->interop
)
3178 return MESA_GLINTEROP_UNSUPPORTED
;
3180 return dri2_dpy
->interop
->query_device_info(dri2_ctx
->dri_context
, out
);
3184 dri2_interop_export_object(_EGLDisplay
*dpy
, _EGLContext
*ctx
,
3185 struct mesa_glinterop_export_in
*in
,
3186 struct mesa_glinterop_export_out
*out
)
3188 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
3189 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
3191 if (!dri2_dpy
->interop
)
3192 return MESA_GLINTEROP_UNSUPPORTED
;
3194 return dri2_dpy
->interop
->export_object(dri2_ctx
->dri_context
, in
, out
);
3198 * This is the main entrypoint into the driver, called by libEGL.
3199 * Create a new _EGLDriver object and init its dispatch table.
3202 _eglBuiltInDriver(void)
3204 _EGLDriver
*dri2_drv
= calloc(1, sizeof *dri2_drv
);
3208 _eglInitDriverFallbacks(dri2_drv
);
3209 dri2_drv
->API
.Initialize
= dri2_initialize
;
3210 dri2_drv
->API
.Terminate
= dri2_terminate
;
3211 dri2_drv
->API
.CreateContext
= dri2_create_context
;
3212 dri2_drv
->API
.DestroyContext
= dri2_destroy_context
;
3213 dri2_drv
->API
.MakeCurrent
= dri2_make_current
;
3214 dri2_drv
->API
.CreateWindowSurface
= dri2_create_window_surface
;
3215 dri2_drv
->API
.CreatePixmapSurface
= dri2_create_pixmap_surface
;
3216 dri2_drv
->API
.CreatePbufferSurface
= dri2_create_pbuffer_surface
;
3217 dri2_drv
->API
.DestroySurface
= dri2_destroy_surface
;
3218 dri2_drv
->API
.GetProcAddress
= dri2_get_proc_address
;
3219 dri2_drv
->API
.WaitClient
= dri2_wait_client
;
3220 dri2_drv
->API
.WaitNative
= dri2_wait_native
;
3221 dri2_drv
->API
.BindTexImage
= dri2_bind_tex_image
;
3222 dri2_drv
->API
.ReleaseTexImage
= dri2_release_tex_image
;
3223 dri2_drv
->API
.SwapInterval
= dri2_swap_interval
;
3224 dri2_drv
->API
.SwapBuffers
= dri2_swap_buffers
;
3225 dri2_drv
->API
.SwapBuffersWithDamageEXT
= dri2_swap_buffers_with_damage
;
3226 dri2_drv
->API
.SwapBuffersRegionNOK
= dri2_swap_buffers_region
;
3227 dri2_drv
->API
.SetDamageRegion
= dri2_set_damage_region
;
3228 dri2_drv
->API
.PostSubBufferNV
= dri2_post_sub_buffer
;
3229 dri2_drv
->API
.CopyBuffers
= dri2_copy_buffers
,
3230 dri2_drv
->API
.QueryBufferAge
= dri2_query_buffer_age
;
3231 dri2_drv
->API
.CreateImageKHR
= dri2_create_image
;
3232 dri2_drv
->API
.DestroyImageKHR
= dri2_destroy_image_khr
;
3233 dri2_drv
->API
.CreateWaylandBufferFromImageWL
= dri2_create_wayland_buffer_from_image
;
3234 dri2_drv
->API
.QuerySurface
= dri2_query_surface
;
3236 dri2_drv
->API
.CreateDRMImageMESA
= dri2_create_drm_image_mesa
;
3237 dri2_drv
->API
.ExportDRMImageMESA
= dri2_export_drm_image_mesa
;
3238 dri2_drv
->API
.ExportDMABUFImageQueryMESA
= dri2_export_dma_buf_image_query_mesa
;
3239 dri2_drv
->API
.ExportDMABUFImageMESA
= dri2_export_dma_buf_image_mesa
;
3240 dri2_drv
->API
.QueryDmaBufFormatsEXT
= dri2_query_dma_buf_formats
;
3241 dri2_drv
->API
.QueryDmaBufModifiersEXT
= dri2_query_dma_buf_modifiers
;
3243 #ifdef HAVE_WAYLAND_PLATFORM
3244 dri2_drv
->API
.BindWaylandDisplayWL
= dri2_bind_wayland_display_wl
;
3245 dri2_drv
->API
.UnbindWaylandDisplayWL
= dri2_unbind_wayland_display_wl
;
3246 dri2_drv
->API
.QueryWaylandBufferWL
= dri2_query_wayland_buffer_wl
;
3248 dri2_drv
->API
.GetSyncValuesCHROMIUM
= dri2_get_sync_values_chromium
;
3249 dri2_drv
->API
.CreateSyncKHR
= dri2_create_sync
;
3250 dri2_drv
->API
.ClientWaitSyncKHR
= dri2_client_wait_sync
;
3251 dri2_drv
->API
.SignalSyncKHR
= dri2_signal_sync
;
3252 dri2_drv
->API
.WaitSyncKHR
= dri2_server_wait_sync
;
3253 dri2_drv
->API
.DestroySyncKHR
= dri2_destroy_sync
;
3254 dri2_drv
->API
.GLInteropQueryDeviceInfo
= dri2_interop_query_device_info
;
3255 dri2_drv
->API
.GLInteropExportObject
= dri2_interop_export_object
;
3256 dri2_drv
->API
.DupNativeFenceFDANDROID
= dri2_dup_native_fence_fd
;
3257 dri2_drv
->API
.SetBlobCacheFuncsANDROID
= dri2_set_blob_cache_funcs
;
3259 dri2_drv
->Name
= "DRI2";