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
);
275 case __DRI_ATTRIB_MUTABLE_RENDER_BUFFER
:
276 if (disp
->Extensions
.KHR_mutable_render_buffer
)
277 surface_type
|= EGL_MUTABLE_RENDER_BUFFER_BIT_KHR
;
280 key
= dri2_to_egl_attribute_map
[attrib
];
282 _eglSetConfigKey(&base
, key
, value
);
288 for (int i
= 0; attr_list
[i
] != EGL_NONE
; i
+= 2)
289 _eglSetConfigKey(&base
, attr_list
[i
], attr_list
[i
+1]);
291 if (rgba_masks
&& memcmp(rgba_masks
, dri_masks
, sizeof(dri_masks
)))
294 base
.NativeRenderable
= EGL_TRUE
;
296 base
.SurfaceType
= surface_type
;
297 if (surface_type
& (EGL_PBUFFER_BIT
|
298 (disp
->Extensions
.NOK_texture_from_pixmap
? EGL_PIXMAP_BIT
: 0))) {
299 base
.BindToTextureRGB
= bind_to_texture_rgb
;
300 if (base
.AlphaSize
> 0)
301 base
.BindToTextureRGBA
= bind_to_texture_rgba
;
304 base
.RenderableType
= disp
->ClientAPIs
;
305 base
.Conformant
= disp
->ClientAPIs
;
307 base
.MinSwapInterval
= dri2_dpy
->min_swap_interval
;
308 base
.MaxSwapInterval
= dri2_dpy
->max_swap_interval
;
310 if (!_eglValidateConfig(&base
, EGL_FALSE
)) {
311 _eglLog(_EGL_DEBUG
, "DRI2: failed to validate config %d", id
);
315 config_id
= base
.ConfigID
;
316 base
.ConfigID
= EGL_DONT_CARE
;
317 base
.SurfaceType
= EGL_DONT_CARE
;
318 num_configs
= _eglFilterArray(disp
->Configs
, (void **) &matching_config
, 1,
319 (_EGLArrayForEach
) dri2_match_config
, &base
);
321 if (num_configs
== 1) {
322 conf
= (struct dri2_egl_config
*) matching_config
;
324 if (!conf
->dri_config
[double_buffer
][srgb
])
325 conf
->dri_config
[double_buffer
][srgb
] = dri_config
;
327 /* a similar config type is already added (unlikely) => discard */
330 else if (num_configs
== 0) {
331 conf
= calloc(1, sizeof *conf
);
335 conf
->dri_config
[double_buffer
][srgb
] = dri_config
;
337 memcpy(&conf
->base
, &base
, sizeof base
);
338 conf
->base
.SurfaceType
= 0;
339 conf
->base
.ConfigID
= config_id
;
341 _eglLinkConfig(&conf
->base
);
349 surface_type
&= ~EGL_PIXMAP_BIT
;
352 /* No support for pbuffer + MSAA for now.
354 * XXX TODO: pbuffer + MSAA does not work and causes crashes.
355 * See QT bugreport: https://bugreports.qt.io/browse/QTBUG-47509
358 surface_type
&= ~EGL_PBUFFER_BIT
;
361 conf
->base
.SurfaceType
|= surface_type
;
367 dri2_lookup_egl_image(__DRIscreen
*screen
, void *image
, void *data
)
369 _EGLDisplay
*disp
= data
;
370 struct dri2_egl_image
*dri2_img
;
375 img
= _eglLookupImage(image
, disp
);
377 _eglError(EGL_BAD_PARAMETER
, "dri2_lookup_egl_image");
381 dri2_img
= dri2_egl_image(image
);
383 return dri2_img
->dri_image
;
386 const __DRIimageLookupExtension image_lookup_extension
= {
387 .base
= { __DRI_IMAGE_LOOKUP
, 1 },
389 .lookupEGLImage
= dri2_lookup_egl_image
392 struct dri2_extension_match
{
398 static const struct dri2_extension_match dri3_driver_extensions
[] = {
399 { __DRI_CORE
, 1, offsetof(struct dri2_egl_display
, core
) },
400 { __DRI_IMAGE_DRIVER
, 1, offsetof(struct dri2_egl_display
, image_driver
) },
404 static const struct dri2_extension_match dri2_driver_extensions
[] = {
405 { __DRI_CORE
, 1, offsetof(struct dri2_egl_display
, core
) },
406 { __DRI_DRI2
, 2, offsetof(struct dri2_egl_display
, dri2
) },
410 static const struct dri2_extension_match dri2_core_extensions
[] = {
411 { __DRI2_FLUSH
, 1, offsetof(struct dri2_egl_display
, flush
) },
412 { __DRI_TEX_BUFFER
, 2, offsetof(struct dri2_egl_display
, tex_buffer
) },
413 { __DRI_IMAGE
, 1, offsetof(struct dri2_egl_display
, image
) },
417 static const struct dri2_extension_match swrast_driver_extensions
[] = {
418 { __DRI_CORE
, 1, offsetof(struct dri2_egl_display
, core
) },
419 { __DRI_SWRAST
, 2, offsetof(struct dri2_egl_display
, swrast
) },
423 static const struct dri2_extension_match swrast_core_extensions
[] = {
424 { __DRI_TEX_BUFFER
, 2, offsetof(struct dri2_egl_display
, tex_buffer
) },
428 static const struct dri2_extension_match optional_core_extensions
[] = {
429 { __DRI2_ROBUSTNESS
, 1, offsetof(struct dri2_egl_display
, robustness
) },
430 { __DRI2_NO_ERROR
, 1, offsetof(struct dri2_egl_display
, no_error
) },
431 { __DRI2_CONFIG_QUERY
, 1, offsetof(struct dri2_egl_display
, config
) },
432 { __DRI2_FENCE
, 1, offsetof(struct dri2_egl_display
, fence
) },
433 { __DRI2_RENDERER_QUERY
, 1, offsetof(struct dri2_egl_display
, rendererQuery
) },
434 { __DRI2_INTEROP
, 1, offsetof(struct dri2_egl_display
, interop
) },
435 { __DRI_IMAGE
, 1, offsetof(struct dri2_egl_display
, image
) },
436 { __DRI2_FLUSH_CONTROL
, 1, offsetof(struct dri2_egl_display
, flush_control
) },
437 { __DRI2_BLOB
, 1, offsetof(struct dri2_egl_display
, blob
) },
438 { __DRI_MUTABLE_RENDER_BUFFER_DRIVER
, 1, offsetof(struct dri2_egl_display
, mutable_render_buffer
) },
443 dri2_bind_extensions(struct dri2_egl_display
*dri2_dpy
,
444 const struct dri2_extension_match
*matches
,
445 const __DRIextension
**extensions
,
451 for (int i
= 0; extensions
[i
]; i
++) {
452 _eglLog(_EGL_DEBUG
, "found extension `%s'", extensions
[i
]->name
);
453 for (int j
= 0; matches
[j
].name
; j
++) {
454 if (strcmp(extensions
[i
]->name
, matches
[j
].name
) == 0 &&
455 extensions
[i
]->version
>= matches
[j
].version
) {
456 field
= ((char *) dri2_dpy
+ matches
[j
].offset
);
457 *(const __DRIextension
**) field
= extensions
[i
];
458 _eglLog(_EGL_INFO
, "found extension %s version %d",
459 extensions
[i
]->name
, extensions
[i
]->version
);
465 for (int j
= 0; matches
[j
].name
; j
++) {
466 field
= ((char *) dri2_dpy
+ matches
[j
].offset
);
467 if (*(const __DRIextension
**) field
== NULL
) {
469 _eglLog(_EGL_DEBUG
, "did not find optional extension %s version %d",
470 matches
[j
].name
, matches
[j
].version
);
472 _eglLog(_EGL_WARNING
, "did not find extension %s version %d",
473 matches
[j
].name
, matches
[j
].version
);
482 static const __DRIextension
**
483 dri2_open_driver(_EGLDisplay
*disp
)
485 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
486 const __DRIextension
**extensions
= NULL
;
487 char path
[PATH_MAX
], *search_paths
, *next
, *end
;
488 char *get_extensions_name
;
489 const __DRIextension
**(*get_extensions
)(void);
492 if (geteuid() == getuid()) {
493 /* don't allow setuid apps to use LIBGL_DRIVERS_PATH */
494 search_paths
= getenv("LIBGL_DRIVERS_PATH");
496 if (search_paths
== NULL
)
497 search_paths
= DEFAULT_DRIVER_DIR
;
499 dri2_dpy
->driver
= NULL
;
500 end
= search_paths
+ strlen(search_paths
);
501 for (char *p
= search_paths
; p
< end
; p
= next
+ 1) {
503 next
= strchr(p
, ':');
509 snprintf(path
, sizeof path
,
510 "%.*s/tls/%s_dri.so", len
, p
, dri2_dpy
->driver_name
);
511 dri2_dpy
->driver
= dlopen(path
, RTLD_NOW
| RTLD_GLOBAL
);
513 if (dri2_dpy
->driver
== NULL
) {
514 snprintf(path
, sizeof path
,
515 "%.*s/%s_dri.so", len
, p
, dri2_dpy
->driver_name
);
516 dri2_dpy
->driver
= dlopen(path
, RTLD_NOW
| RTLD_GLOBAL
);
517 if (dri2_dpy
->driver
== NULL
)
518 _eglLog(_EGL_DEBUG
, "failed to open %s: %s\n", path
, dlerror());
520 /* not need continue to loop all paths once the driver is found */
521 if (dri2_dpy
->driver
!= NULL
)
525 if (dri2_dpy
->driver
== NULL
) {
526 _eglLog(_EGL_WARNING
,
527 "DRI2: failed to open %s (search paths %s)",
528 dri2_dpy
->driver_name
, search_paths
);
532 _eglLog(_EGL_DEBUG
, "DRI2: dlopen(%s)", path
);
534 get_extensions_name
= loader_get_extensions_name(dri2_dpy
->driver_name
);
535 if (get_extensions_name
) {
536 get_extensions
= dlsym(dri2_dpy
->driver
, get_extensions_name
);
537 if (get_extensions
) {
538 extensions
= get_extensions();
540 _eglLog(_EGL_DEBUG
, "driver does not expose %s(): %s\n",
541 get_extensions_name
, dlerror());
543 free(get_extensions_name
);
547 extensions
= dlsym(dri2_dpy
->driver
, __DRI_DRIVER_EXTENSIONS
);
548 if (extensions
== NULL
) {
549 _eglLog(_EGL_WARNING
,
550 "DRI2: driver exports no extensions (%s)", dlerror());
551 dlclose(dri2_dpy
->driver
);
558 dri2_load_driver_dri3(_EGLDisplay
*disp
)
560 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
561 const __DRIextension
**extensions
;
563 extensions
= dri2_open_driver(disp
);
567 if (!dri2_bind_extensions(dri2_dpy
, dri3_driver_extensions
, extensions
, false)) {
568 dlclose(dri2_dpy
->driver
);
571 dri2_dpy
->driver_extensions
= extensions
;
577 dri2_load_driver(_EGLDisplay
*disp
)
579 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
580 const __DRIextension
**extensions
;
582 extensions
= dri2_open_driver(disp
);
586 if (!dri2_bind_extensions(dri2_dpy
, dri2_driver_extensions
, extensions
, false)) {
587 dlclose(dri2_dpy
->driver
);
590 dri2_dpy
->driver_extensions
= extensions
;
596 dri2_load_driver_swrast(_EGLDisplay
*disp
)
598 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
599 const __DRIextension
**extensions
;
601 extensions
= dri2_open_driver(disp
);
605 if (!dri2_bind_extensions(dri2_dpy
, swrast_driver_extensions
, extensions
, false)) {
606 dlclose(dri2_dpy
->driver
);
609 dri2_dpy
->driver_extensions
= extensions
;
615 dri2_renderer_query_integer(struct dri2_egl_display
*dri2_dpy
, int param
)
617 const __DRI2rendererQueryExtension
*rendererQuery
= dri2_dpy
->rendererQuery
;
618 unsigned int value
= 0;
620 if (!rendererQuery
||
621 rendererQuery
->queryInteger(dri2_dpy
->dri_screen
, param
, &value
) == -1)
628 dri2_setup_screen(_EGLDisplay
*disp
)
630 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
631 unsigned int api_mask
;
634 * EGL 1.5 specification defines the default value to 1. Moreover,
635 * eglSwapInterval() is required to clamp requested value to the supported
636 * range. Since the default value is implicitly assumed to be supported,
637 * use it as both minimum and maximum for the platforms that do not allow
638 * changing the interval. Platforms, which allow it (e.g. x11, wayland)
639 * override these values already.
641 dri2_dpy
->min_swap_interval
= 1;
642 dri2_dpy
->max_swap_interval
= 1;
643 dri2_dpy
->default_swap_interval
= 1;
645 if (dri2_dpy
->image_driver
) {
646 api_mask
= dri2_dpy
->image_driver
->getAPIMask(dri2_dpy
->dri_screen
);
647 } else if (dri2_dpy
->dri2
) {
648 api_mask
= dri2_dpy
->dri2
->getAPIMask(dri2_dpy
->dri_screen
);
650 assert(dri2_dpy
->swrast
);
651 api_mask
= 1 << __DRI_API_OPENGL
|
652 1 << __DRI_API_GLES
|
653 1 << __DRI_API_GLES2
|
654 1 << __DRI_API_GLES3
;
657 disp
->ClientAPIs
= 0;
658 if ((api_mask
& (1 <<__DRI_API_OPENGL
)) && _eglIsApiValid(EGL_OPENGL_API
))
659 disp
->ClientAPIs
|= EGL_OPENGL_BIT
;
660 if ((api_mask
& (1 << __DRI_API_GLES
)) && _eglIsApiValid(EGL_OPENGL_ES_API
))
661 disp
->ClientAPIs
|= EGL_OPENGL_ES_BIT
;
662 if ((api_mask
& (1 << __DRI_API_GLES2
)) && _eglIsApiValid(EGL_OPENGL_ES_API
))
663 disp
->ClientAPIs
|= EGL_OPENGL_ES2_BIT
;
664 if ((api_mask
& (1 << __DRI_API_GLES3
)) && _eglIsApiValid(EGL_OPENGL_ES_API
))
665 disp
->ClientAPIs
|= EGL_OPENGL_ES3_BIT_KHR
;
667 assert(dri2_dpy
->image_driver
|| dri2_dpy
->dri2
|| dri2_dpy
->swrast
);
668 disp
->Extensions
.KHR_no_config_context
= EGL_TRUE
;
669 disp
->Extensions
.KHR_surfaceless_context
= EGL_TRUE
;
671 /* Report back to EGL the bitmask of priorities supported */
672 disp
->Extensions
.IMG_context_priority
=
673 dri2_renderer_query_integer(dri2_dpy
,
674 __DRI2_RENDERER_HAS_CONTEXT_PRIORITY
);
676 disp
->Extensions
.EXT_pixel_format_float
= EGL_TRUE
;
678 if (dri2_renderer_query_integer(dri2_dpy
,
679 __DRI2_RENDERER_HAS_FRAMEBUFFER_SRGB
))
680 disp
->Extensions
.KHR_gl_colorspace
= EGL_TRUE
;
682 if (dri2_dpy
->image_driver
||
683 (dri2_dpy
->dri2
&& dri2_dpy
->dri2
->base
.version
>= 3) ||
684 (dri2_dpy
->swrast
&& dri2_dpy
->swrast
->base
.version
>= 3)) {
685 disp
->Extensions
.KHR_create_context
= EGL_TRUE
;
687 if (dri2_dpy
->robustness
)
688 disp
->Extensions
.EXT_create_context_robustness
= EGL_TRUE
;
691 if (dri2_dpy
->no_error
)
692 disp
->Extensions
.KHR_create_context_no_error
= EGL_TRUE
;
694 if (dri2_dpy
->fence
) {
695 disp
->Extensions
.KHR_fence_sync
= EGL_TRUE
;
696 disp
->Extensions
.KHR_wait_sync
= EGL_TRUE
;
697 if (dri2_dpy
->fence
->get_fence_from_cl_event
)
698 disp
->Extensions
.KHR_cl_event2
= EGL_TRUE
;
699 if (dri2_dpy
->fence
->base
.version
>= 2 &&
700 dri2_dpy
->fence
->get_capabilities
) {
701 unsigned capabilities
=
702 dri2_dpy
->fence
->get_capabilities(dri2_dpy
->dri_screen
);
703 disp
->Extensions
.ANDROID_native_fence_sync
=
704 (capabilities
& __DRI_FENCE_CAP_NATIVE_FD
) != 0;
709 disp
->Extensions
.ANDROID_blob_cache
= EGL_TRUE
;
711 disp
->Extensions
.KHR_reusable_sync
= EGL_TRUE
;
713 if (dri2_dpy
->image
) {
714 if (dri2_dpy
->image
->base
.version
>= 10 &&
715 dri2_dpy
->image
->getCapabilities
!= NULL
) {
718 capabilities
= dri2_dpy
->image
->getCapabilities(dri2_dpy
->dri_screen
);
719 disp
->Extensions
.MESA_drm_image
= (capabilities
& __DRI_IMAGE_CAP_GLOBAL_NAMES
) != 0;
721 if (dri2_dpy
->image
->base
.version
>= 11)
722 disp
->Extensions
.MESA_image_dma_buf_export
= EGL_TRUE
;
724 disp
->Extensions
.MESA_drm_image
= EGL_TRUE
;
725 if (dri2_dpy
->image
->base
.version
>= 11)
726 disp
->Extensions
.MESA_image_dma_buf_export
= EGL_TRUE
;
729 disp
->Extensions
.KHR_image_base
= EGL_TRUE
;
730 disp
->Extensions
.KHR_gl_renderbuffer_image
= EGL_TRUE
;
731 if (dri2_dpy
->image
->base
.version
>= 5 &&
732 dri2_dpy
->image
->createImageFromTexture
) {
733 disp
->Extensions
.KHR_gl_texture_2D_image
= EGL_TRUE
;
734 disp
->Extensions
.KHR_gl_texture_cubemap_image
= EGL_TRUE
;
736 if (dri2_renderer_query_integer(dri2_dpy
,
737 __DRI2_RENDERER_HAS_TEXTURE_3D
))
738 disp
->Extensions
.KHR_gl_texture_3D_image
= EGL_TRUE
;
741 if (dri2_dpy
->image
->base
.version
>= 8 &&
742 dri2_dpy
->image
->createImageFromDmaBufs
) {
743 disp
->Extensions
.EXT_image_dma_buf_import
= EGL_TRUE
;
745 if (dri2_dpy
->image
->base
.version
>= 15 &&
746 dri2_dpy
->image
->createImageFromDmaBufs2
&&
747 dri2_dpy
->image
->queryDmaBufFormats
&&
748 dri2_dpy
->image
->queryDmaBufModifiers
) {
749 disp
->Extensions
.EXT_image_dma_buf_import_modifiers
= EGL_TRUE
;
754 if (dri2_dpy
->flush_control
)
755 disp
->Extensions
.KHR_context_flush_control
= EGL_TRUE
;
759 dri2_setup_swap_interval(_EGLDisplay
*disp
, int max_swap_interval
)
761 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
762 GLint vblank_mode
= DRI_CONF_VBLANK_DEF_INTERVAL_1
;
764 /* Allow driconf to override applications.*/
765 if (dri2_dpy
->config
)
766 dri2_dpy
->config
->configQueryi(dri2_dpy
->dri_screen
,
767 "vblank_mode", &vblank_mode
);
768 switch (vblank_mode
) {
769 case DRI_CONF_VBLANK_NEVER
:
770 dri2_dpy
->min_swap_interval
= 0;
771 dri2_dpy
->max_swap_interval
= 0;
772 dri2_dpy
->default_swap_interval
= 0;
774 case DRI_CONF_VBLANK_ALWAYS_SYNC
:
775 dri2_dpy
->min_swap_interval
= 1;
776 dri2_dpy
->max_swap_interval
= max_swap_interval
;
777 dri2_dpy
->default_swap_interval
= 1;
779 case DRI_CONF_VBLANK_DEF_INTERVAL_0
:
780 dri2_dpy
->min_swap_interval
= 0;
781 dri2_dpy
->max_swap_interval
= max_swap_interval
;
782 dri2_dpy
->default_swap_interval
= 0;
785 case DRI_CONF_VBLANK_DEF_INTERVAL_1
:
786 dri2_dpy
->min_swap_interval
= 0;
787 dri2_dpy
->max_swap_interval
= max_swap_interval
;
788 dri2_dpy
->default_swap_interval
= 1;
793 /* All platforms but DRM call this function to create the screen and populate
794 * the driver_configs. DRM inherits that information from its display - GBM.
797 dri2_create_screen(_EGLDisplay
*disp
)
799 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
801 if (dri2_dpy
->image_driver
) {
802 dri2_dpy
->dri_screen
=
803 dri2_dpy
->image_driver
->createNewScreen2(0, dri2_dpy
->fd
,
804 dri2_dpy
->loader_extensions
,
805 dri2_dpy
->driver_extensions
,
806 &dri2_dpy
->driver_configs
,
808 } else if (dri2_dpy
->dri2
) {
809 if (dri2_dpy
->dri2
->base
.version
>= 4) {
810 dri2_dpy
->dri_screen
=
811 dri2_dpy
->dri2
->createNewScreen2(0, dri2_dpy
->fd
,
812 dri2_dpy
->loader_extensions
,
813 dri2_dpy
->driver_extensions
,
814 &dri2_dpy
->driver_configs
, disp
);
816 dri2_dpy
->dri_screen
=
817 dri2_dpy
->dri2
->createNewScreen(0, dri2_dpy
->fd
,
818 dri2_dpy
->loader_extensions
,
819 &dri2_dpy
->driver_configs
, disp
);
822 assert(dri2_dpy
->swrast
);
823 if (dri2_dpy
->swrast
->base
.version
>= 4) {
824 dri2_dpy
->dri_screen
=
825 dri2_dpy
->swrast
->createNewScreen2(0, dri2_dpy
->loader_extensions
,
826 dri2_dpy
->driver_extensions
,
827 &dri2_dpy
->driver_configs
, disp
);
829 dri2_dpy
->dri_screen
=
830 dri2_dpy
->swrast
->createNewScreen(0, dri2_dpy
->loader_extensions
,
831 &dri2_dpy
->driver_configs
, disp
);
835 if (dri2_dpy
->dri_screen
== NULL
) {
836 _eglLog(_EGL_WARNING
, "DRI2: failed to create dri screen");
840 dri2_dpy
->own_dri_screen
= true;
845 dri2_setup_extensions(_EGLDisplay
*disp
)
847 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
848 const struct dri2_extension_match
*mandatory_core_extensions
;
849 const __DRIextension
**extensions
;
851 extensions
= dri2_dpy
->core
->getExtensions(dri2_dpy
->dri_screen
);
853 if (dri2_dpy
->image_driver
|| dri2_dpy
->dri2
)
854 mandatory_core_extensions
= dri2_core_extensions
;
856 mandatory_core_extensions
= swrast_core_extensions
;
858 if (!dri2_bind_extensions(dri2_dpy
, mandatory_core_extensions
, extensions
, false))
861 #ifdef HAVE_DRI3_MODIFIERS
862 dri2_dpy
->multibuffers_available
=
863 (dri2_dpy
->dri3_major_version
> 1 || (dri2_dpy
->dri3_major_version
== 1 &&
864 dri2_dpy
->dri3_minor_version
>= 2)) &&
865 (dri2_dpy
->present_major_version
> 1 || (dri2_dpy
->present_major_version
== 1 &&
866 dri2_dpy
->present_minor_version
>= 2)) &&
867 (dri2_dpy
->image
&& dri2_dpy
->image
->base
.version
>= 15);
870 dri2_bind_extensions(dri2_dpy
, optional_core_extensions
, extensions
, true);
875 * Called via eglInitialize(), GLX_drv->API.Initialize().
877 * This must be guaranteed to be called exactly once, even if eglInitialize is
878 * called many times (without a eglTerminate in between).
881 dri2_initialize(_EGLDriver
*drv
, _EGLDisplay
*disp
)
883 EGLBoolean ret
= EGL_FALSE
;
884 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
886 /* In the case where the application calls eglMakeCurrent(context1),
887 * eglTerminate, then eglInitialize again (without a call to eglReleaseThread
888 * or eglMakeCurrent(NULL) before that), dri2_dpy structure is still
889 * initialized, as we need it to be able to free context1 correctly.
891 * It would probably be safest to forcibly release the display with
892 * dri2_display_release, to make sure the display is reinitialized correctly.
893 * However, the EGL spec states that we need to keep a reference to the
894 * current context (so we cannot call dri2_make_current(NULL)), and therefore
895 * we would leak context1 as we would be missing the old display connection
896 * to free it up correctly.
899 dri2_dpy
->ref_count
++;
903 switch (disp
->Platform
) {
904 case _EGL_PLATFORM_SURFACELESS
:
905 ret
= dri2_initialize_surfaceless(drv
, disp
);
907 case _EGL_PLATFORM_X11
:
908 ret
= dri2_initialize_x11(drv
, disp
);
910 case _EGL_PLATFORM_DRM
:
911 ret
= dri2_initialize_drm(drv
, disp
);
913 case _EGL_PLATFORM_WAYLAND
:
914 ret
= dri2_initialize_wayland(drv
, disp
);
916 case _EGL_PLATFORM_ANDROID
:
917 ret
= dri2_initialize_android(drv
, disp
);
920 unreachable("Callers ensure we cannot get here.");
927 dri2_dpy
= dri2_egl_display(disp
);
928 dri2_dpy
->ref_count
++;
934 * Decrement display reference count, and free up display if necessary.
937 dri2_display_release(_EGLDisplay
*disp
)
939 struct dri2_egl_display
*dri2_dpy
;
944 dri2_dpy
= dri2_egl_display(disp
);
946 assert(dri2_dpy
->ref_count
> 0);
947 dri2_dpy
->ref_count
--;
949 if (dri2_dpy
->ref_count
> 0)
952 _eglCleanupDisplay(disp
);
953 dri2_display_destroy(disp
);
957 dri2_display_destroy(_EGLDisplay
*disp
)
959 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
961 if (dri2_dpy
->own_dri_screen
) {
962 if (dri2_dpy
->vtbl
&& dri2_dpy
->vtbl
->close_screen_notify
)
963 dri2_dpy
->vtbl
->close_screen_notify(disp
);
964 dri2_dpy
->core
->destroyScreen(dri2_dpy
->dri_screen
);
966 if (dri2_dpy
->fd
>= 0)
968 if (dri2_dpy
->driver
)
969 dlclose(dri2_dpy
->driver
);
970 free(dri2_dpy
->driver_name
);
972 #ifdef HAVE_WAYLAND_PLATFORM
973 free(dri2_dpy
->device_name
);
976 switch (disp
->Platform
) {
977 case _EGL_PLATFORM_X11
:
978 dri2_teardown_x11(dri2_dpy
);
980 case _EGL_PLATFORM_DRM
:
981 dri2_teardown_drm(dri2_dpy
);
983 case _EGL_PLATFORM_WAYLAND
:
984 dri2_teardown_wayland(dri2_dpy
);
987 /* TODO: add teardown for other platforms */
991 /* The drm platform does not create the screen/driver_configs but reuses
992 * the ones from the gbm device. As such the gbm itself is responsible
995 if (disp
->Platform
!= _EGL_PLATFORM_DRM
&& dri2_dpy
->driver_configs
) {
996 for (unsigned i
= 0; dri2_dpy
->driver_configs
[i
]; i
++)
997 free((__DRIconfig
*) dri2_dpy
->driver_configs
[i
]);
998 free(dri2_dpy
->driver_configs
);
1001 disp
->DriverData
= NULL
;
1005 dri2_egl_surface_alloc_local_buffer(struct dri2_egl_surface
*dri2_surf
,
1006 unsigned int att
, unsigned int format
)
1008 struct dri2_egl_display
*dri2_dpy
=
1009 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
1011 if (att
>= ARRAY_SIZE(dri2_surf
->local_buffers
))
1014 if (!dri2_surf
->local_buffers
[att
]) {
1015 dri2_surf
->local_buffers
[att
] =
1016 dri2_dpy
->dri2
->allocateBuffer(dri2_dpy
->dri_screen
, att
, format
,
1017 dri2_surf
->base
.Width
, dri2_surf
->base
.Height
);
1020 return dri2_surf
->local_buffers
[att
];
1024 dri2_egl_surface_free_local_buffers(struct dri2_egl_surface
*dri2_surf
)
1026 struct dri2_egl_display
*dri2_dpy
=
1027 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
1029 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->local_buffers
); i
++) {
1030 if (dri2_surf
->local_buffers
[i
]) {
1031 dri2_dpy
->dri2
->releaseBuffer(dri2_dpy
->dri_screen
,
1032 dri2_surf
->local_buffers
[i
]);
1033 dri2_surf
->local_buffers
[i
] = NULL
;
1039 * Called via eglTerminate(), drv->API.Terminate().
1041 * This must be guaranteed to be called exactly once, even if eglTerminate is
1042 * called many times (without a eglInitialize in between).
1045 dri2_terminate(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1047 /* Release all non-current Context/Surfaces. */
1048 _eglReleaseDisplayResources(drv
, disp
);
1050 dri2_display_release(disp
);
1056 * Set the error code after a call to
1057 * dri2_egl_display::dri2::createContextAttribs.
1060 dri2_create_context_attribs_error(int dri_error
)
1064 switch (dri_error
) {
1065 case __DRI_CTX_ERROR_SUCCESS
:
1068 case __DRI_CTX_ERROR_NO_MEMORY
:
1069 egl_error
= EGL_BAD_ALLOC
;
1072 /* From the EGL_KHR_create_context spec, section "Errors":
1074 * * If <config> does not support a client API context compatible
1075 * with the requested API major and minor version, [...] context flags,
1076 * and context reset notification behavior (for client API types where
1077 * these attributes are supported), then an EGL_BAD_MATCH error is
1080 * * If an OpenGL ES context is requested and the values for
1081 * attributes EGL_CONTEXT_MAJOR_VERSION_KHR and
1082 * EGL_CONTEXT_MINOR_VERSION_KHR specify an OpenGL ES version that
1083 * is not defined, than an EGL_BAD_MATCH error is generated.
1085 * * If an OpenGL context is requested, the requested version is
1086 * greater than 3.2, and the value for attribute
1087 * EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR has no bits set; has any
1088 * bits set other than EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR and
1089 * EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR; has more than
1090 * one of these bits set; or if the implementation does not support
1091 * the requested profile, then an EGL_BAD_MATCH error is generated.
1093 case __DRI_CTX_ERROR_BAD_API
:
1094 case __DRI_CTX_ERROR_BAD_VERSION
:
1095 case __DRI_CTX_ERROR_BAD_FLAG
:
1096 egl_error
= EGL_BAD_MATCH
;
1099 /* From the EGL_KHR_create_context spec, section "Errors":
1101 * * If an attribute name or attribute value in <attrib_list> is not
1102 * recognized (including unrecognized bits in bitmask attributes),
1103 * then an EGL_BAD_ATTRIBUTE error is generated."
1105 case __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE
:
1106 case __DRI_CTX_ERROR_UNKNOWN_FLAG
:
1107 egl_error
= EGL_BAD_ATTRIBUTE
;
1112 egl_error
= EGL_BAD_MATCH
;
1116 _eglError(egl_error
, "dri2_create_context");
1120 dri2_fill_context_attribs(struct dri2_egl_context
*dri2_ctx
,
1121 struct dri2_egl_display
*dri2_dpy
,
1122 uint32_t *ctx_attribs
,
1123 unsigned *num_attribs
)
1127 assert(*num_attribs
>= NUM_ATTRIBS
);
1129 ctx_attribs
[pos
++] = __DRI_CTX_ATTRIB_MAJOR_VERSION
;
1130 ctx_attribs
[pos
++] = dri2_ctx
->base
.ClientMajorVersion
;
1131 ctx_attribs
[pos
++] = __DRI_CTX_ATTRIB_MINOR_VERSION
;
1132 ctx_attribs
[pos
++] = dri2_ctx
->base
.ClientMinorVersion
;
1134 if (dri2_ctx
->base
.Flags
!= 0 || dri2_ctx
->base
.NoError
) {
1135 /* If the implementation doesn't support the __DRI2_ROBUSTNESS
1136 * extension, don't even try to send it the robust-access flag.
1137 * It may explode. Instead, generate the required EGL error here.
1139 if ((dri2_ctx
->base
.Flags
& EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR
) != 0
1140 && !dri2_dpy
->robustness
) {
1141 _eglError(EGL_BAD_MATCH
, "eglCreateContext");
1145 ctx_attribs
[pos
++] = __DRI_CTX_ATTRIB_FLAGS
;
1146 ctx_attribs
[pos
++] = dri2_ctx
->base
.Flags
|
1147 (dri2_ctx
->base
.NoError
? __DRI_CTX_FLAG_NO_ERROR
: 0);
1150 if (dri2_ctx
->base
.ResetNotificationStrategy
!= EGL_NO_RESET_NOTIFICATION_KHR
) {
1151 /* If the implementation doesn't support the __DRI2_ROBUSTNESS
1152 * extension, don't even try to send it a reset strategy. It may
1153 * explode. Instead, generate the required EGL error here.
1155 if (!dri2_dpy
->robustness
) {
1156 _eglError(EGL_BAD_CONFIG
, "eglCreateContext");
1160 ctx_attribs
[pos
++] = __DRI_CTX_ATTRIB_RESET_STRATEGY
;
1161 ctx_attribs
[pos
++] = __DRI_CTX_RESET_LOSE_CONTEXT
;
1164 if (dri2_ctx
->base
.ContextPriority
!= EGL_CONTEXT_PRIORITY_MEDIUM_IMG
) {
1167 switch (dri2_ctx
->base
.ContextPriority
) {
1168 case EGL_CONTEXT_PRIORITY_HIGH_IMG
:
1169 val
= __DRI_CTX_PRIORITY_HIGH
;
1171 case EGL_CONTEXT_PRIORITY_MEDIUM_IMG
:
1172 val
= __DRI_CTX_PRIORITY_MEDIUM
;
1174 case EGL_CONTEXT_PRIORITY_LOW_IMG
:
1175 val
= __DRI_CTX_PRIORITY_LOW
;
1178 _eglError(EGL_BAD_CONFIG
, "eglCreateContext");
1182 ctx_attribs
[pos
++] = __DRI_CTX_ATTRIB_PRIORITY
;
1183 ctx_attribs
[pos
++] = val
;
1186 if (dri2_ctx
->base
.ReleaseBehavior
== EGL_CONTEXT_RELEASE_BEHAVIOR_NONE_KHR
) {
1187 ctx_attribs
[pos
++] = __DRI_CTX_ATTRIB_RELEASE_BEHAVIOR
;
1188 ctx_attribs
[pos
++] = __DRI_CTX_RELEASE_BEHAVIOR_NONE
;
1197 * Called via eglCreateContext(), drv->API.CreateContext().
1199 static _EGLContext
*
1200 dri2_create_context(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLConfig
*conf
,
1201 _EGLContext
*share_list
, const EGLint
*attrib_list
)
1203 struct dri2_egl_context
*dri2_ctx
;
1204 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1205 struct dri2_egl_context
*dri2_ctx_shared
= dri2_egl_context(share_list
);
1206 __DRIcontext
*shared
=
1207 dri2_ctx_shared
? dri2_ctx_shared
->dri_context
: NULL
;
1208 struct dri2_egl_config
*dri2_config
= dri2_egl_config(conf
);
1209 const __DRIconfig
*dri_config
;
1212 unsigned num_attribs
= NUM_ATTRIBS
;
1213 uint32_t ctx_attribs
[NUM_ATTRIBS
];
1217 dri2_ctx
= malloc(sizeof *dri2_ctx
);
1219 _eglError(EGL_BAD_ALLOC
, "eglCreateContext");
1223 if (!_eglInitContext(&dri2_ctx
->base
, disp
, conf
, attrib_list
))
1226 /* The EGL_EXT_create_context_robustness spec says:
1228 * "Add to the eglCreateContext context creation errors: [...]
1230 * * If the reset notification behavior of <share_context> and the
1231 * newly created context are different then an EGL_BAD_MATCH error is
1234 if (share_list
&& share_list
->ResetNotificationStrategy
!=
1235 dri2_ctx
->base
.ResetNotificationStrategy
) {
1236 _eglError(EGL_BAD_MATCH
, "eglCreateContext");
1240 /* The EGL_KHR_create_context_no_error spec says:
1242 * "BAD_MATCH is generated if the value of EGL_CONTEXT_OPENGL_NO_ERROR_KHR
1243 * used to create <share_context> does not match the value of
1244 * EGL_CONTEXT_OPENGL_NO_ERROR_KHR for the context being created."
1246 if (share_list
&& share_list
->NoError
!= dri2_ctx
->base
.NoError
) {
1247 _eglError(EGL_BAD_MATCH
, "eglCreateContext");
1251 switch (dri2_ctx
->base
.ClientAPI
) {
1252 case EGL_OPENGL_ES_API
:
1253 switch (dri2_ctx
->base
.ClientMajorVersion
) {
1255 api
= __DRI_API_GLES
;
1258 api
= __DRI_API_GLES2
;
1261 api
= __DRI_API_GLES3
;
1264 _eglError(EGL_BAD_PARAMETER
, "eglCreateContext");
1269 case EGL_OPENGL_API
:
1270 if ((dri2_ctx
->base
.ClientMajorVersion
>= 4
1271 || (dri2_ctx
->base
.ClientMajorVersion
== 3
1272 && dri2_ctx
->base
.ClientMinorVersion
>= 2))
1273 && dri2_ctx
->base
.Profile
== EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR
)
1274 api
= __DRI_API_OPENGL_CORE
;
1276 api
= __DRI_API_OPENGL
;
1279 _eglError(EGL_BAD_PARAMETER
, "eglCreateContext");
1285 /* The config chosen here isn't necessarily
1286 * used for surfaces later.
1287 * A pixmap surface will use the single config.
1288 * This opportunity depends on disabling the
1289 * doubleBufferMode check in
1290 * src/mesa/main/context.c:check_compatible()
1292 if (dri2_config
->dri_config
[1][0])
1293 dri_config
= dri2_config
->dri_config
[1][0];
1295 dri_config
= dri2_config
->dri_config
[0][0];
1300 if (!dri2_fill_context_attribs(dri2_ctx
, dri2_dpy
, ctx_attribs
,
1304 if (dri2_dpy
->image_driver
) {
1305 dri2_ctx
->dri_context
=
1306 dri2_dpy
->image_driver
->createContextAttribs(dri2_dpy
->dri_screen
,
1314 dri2_create_context_attribs_error(error
);
1315 } else if (dri2_dpy
->dri2
) {
1316 if (dri2_dpy
->dri2
->base
.version
>= 3) {
1317 dri2_ctx
->dri_context
=
1318 dri2_dpy
->dri2
->createContextAttribs(dri2_dpy
->dri_screen
,
1326 dri2_create_context_attribs_error(error
);
1328 dri2_ctx
->dri_context
=
1329 dri2_dpy
->dri2
->createNewContextForAPI(dri2_dpy
->dri_screen
,
1336 assert(dri2_dpy
->swrast
);
1337 if (dri2_dpy
->swrast
->base
.version
>= 3) {
1338 dri2_ctx
->dri_context
=
1339 dri2_dpy
->swrast
->createContextAttribs(dri2_dpy
->dri_screen
,
1347 dri2_create_context_attribs_error(error
);
1349 dri2_ctx
->dri_context
=
1350 dri2_dpy
->swrast
->createNewContextForAPI(dri2_dpy
->dri_screen
,
1358 if (!dri2_ctx
->dri_context
)
1361 return &dri2_ctx
->base
;
1369 * Called via eglDestroyContext(), drv->API.DestroyContext().
1372 dri2_destroy_context(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLContext
*ctx
)
1374 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
1375 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1377 if (_eglPutContext(ctx
)) {
1378 dri2_dpy
->core
->destroyContext(dri2_ctx
->dri_context
);
1386 dri2_init_surface(_EGLSurface
*surf
, _EGLDisplay
*dpy
, EGLint type
,
1387 _EGLConfig
*conf
, const EGLint
*attrib_list
, EGLBoolean enable_out_fence
)
1389 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
1390 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1392 dri2_surf
->out_fence_fd
= -1;
1393 dri2_surf
->enable_out_fence
= false;
1394 if (dri2_dpy
->fence
&& dri2_dpy
->fence
->base
.version
>= 2 &&
1395 dri2_dpy
->fence
->get_capabilities
&&
1396 (dri2_dpy
->fence
->get_capabilities(dri2_dpy
->dri_screen
) &
1397 __DRI_FENCE_CAP_NATIVE_FD
)) {
1398 dri2_surf
->enable_out_fence
= enable_out_fence
;
1401 return _eglInitSurface(surf
, dpy
, type
, conf
, attrib_list
);
1405 dri2_surface_set_out_fence_fd( _EGLSurface
*surf
, int fence_fd
)
1407 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
1409 if (dri2_surf
->out_fence_fd
>= 0)
1410 close(dri2_surf
->out_fence_fd
);
1412 dri2_surf
->out_fence_fd
= fence_fd
;
1416 dri2_fini_surface(_EGLSurface
*surf
)
1418 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
1420 dri2_surface_set_out_fence_fd(surf
, -1);
1421 dri2_surf
->enable_out_fence
= false;
1425 dri2_destroy_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
)
1427 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1429 if (!_eglPutSurface(surf
))
1432 return dri2_dpy
->vtbl
->destroy_surface(drv
, dpy
, surf
);
1436 dri2_surf_update_fence_fd(_EGLContext
*ctx
,
1437 _EGLDisplay
*dpy
, _EGLSurface
*surf
)
1439 __DRIcontext
*dri_ctx
= dri2_egl_context(ctx
)->dri_context
;
1440 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1441 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
1445 if (!dri2_surf
->enable_out_fence
)
1448 fence
= dri2_dpy
->fence
->create_fence_fd(dri_ctx
, -1);
1450 fence_fd
= dri2_dpy
->fence
->get_fence_fd(dri2_dpy
->dri_screen
,
1452 dri2_dpy
->fence
->destroy_fence(dri2_dpy
->dri_screen
, fence
);
1454 dri2_surface_set_out_fence_fd(surf
, fence_fd
);
1458 * Called via eglMakeCurrent(), drv->API.MakeCurrent().
1461 dri2_make_current(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*dsurf
,
1462 _EGLSurface
*rsurf
, _EGLContext
*ctx
)
1464 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1465 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
1466 _EGLDisplay
*old_disp
= NULL
;
1467 struct dri2_egl_display
*old_dri2_dpy
= NULL
;
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) */
1485 old_disp
= old_ctx
->Resource
.Display
;
1486 old_dri2_dpy
= dri2_egl_display(old_disp
);
1489 /* flush before context switch */
1493 ddraw
= (dsurf
) ? dri2_dpy
->vtbl
->get_dri_drawable(dsurf
) : NULL
;
1494 rdraw
= (rsurf
) ? dri2_dpy
->vtbl
->get_dri_drawable(rsurf
) : NULL
;
1495 cctx
= (dri2_ctx
) ? dri2_ctx
->dri_context
: NULL
;
1498 __DRIcontext
*old_cctx
= dri2_egl_context(old_ctx
)->dri_context
;
1501 dri2_surf_update_fence_fd(old_ctx
, disp
, old_dsurf
);
1503 /* Disable shared buffer mode */
1504 if (old_dsurf
&& _eglSurfaceInSharedBufferMode(old_dsurf
) &&
1505 old_dri2_dpy
->vtbl
->set_shared_buffer_mode
) {
1506 old_dri2_dpy
->vtbl
->set_shared_buffer_mode(old_disp
, old_dsurf
, false);
1509 dri2_dpy
->core
->unbindContext(old_cctx
);
1512 unbind
= (cctx
== NULL
&& ddraw
== NULL
&& rdraw
== NULL
);
1514 if (!unbind
&& !dri2_dpy
->core
->bindContext(cctx
, ddraw
, rdraw
)) {
1515 /* undo the previous _eglBindContext */
1516 _eglBindContext(old_ctx
, old_dsurf
, old_rsurf
, &ctx
, &tmp_dsurf
, &tmp_rsurf
);
1517 assert(&dri2_ctx
->base
== ctx
&&
1518 tmp_dsurf
== dsurf
&&
1519 tmp_rsurf
== rsurf
);
1521 if (old_dsurf
&& _eglSurfaceInSharedBufferMode(old_dsurf
) &&
1522 old_dri2_dpy
->vtbl
->set_shared_buffer_mode
) {
1523 old_dri2_dpy
->vtbl
->set_shared_buffer_mode(old_disp
, old_dsurf
, true);
1526 _eglPutSurface(dsurf
);
1527 _eglPutSurface(rsurf
);
1528 _eglPutContext(ctx
);
1530 _eglPutSurface(old_dsurf
);
1531 _eglPutSurface(old_rsurf
);
1532 _eglPutContext(old_ctx
);
1534 /* dri2_dpy->core->bindContext failed. We cannot tell for sure why, but
1535 * setting the error to EGL_BAD_MATCH is surely better than leaving it
1538 return _eglError(EGL_BAD_MATCH
, "eglMakeCurrent");
1541 dri2_destroy_surface(drv
, disp
, old_dsurf
);
1542 dri2_destroy_surface(drv
, disp
, old_rsurf
);
1545 dri2_dpy
->ref_count
++;
1548 dri2_destroy_context(drv
, disp
, old_ctx
);
1549 dri2_display_release(old_disp
);
1552 if (dsurf
&& _eglSurfaceHasMutableRenderBuffer(dsurf
) &&
1553 dri2_dpy
->vtbl
->set_shared_buffer_mode
) {
1554 /* Always update the shared buffer mode. This is obviously needed when
1555 * the active EGL_RENDER_BUFFER is EGL_SINGLE_BUFFER. When
1556 * EGL_RENDER_BUFFER is EGL_BACK_BUFFER, the update protects us in the
1557 * case where external non-EGL API may have changed window's shared
1558 * buffer mode since we last saw it.
1560 bool mode
= (dsurf
->ActiveRenderBuffer
== EGL_SINGLE_BUFFER
);
1561 dri2_dpy
->vtbl
->set_shared_buffer_mode(disp
, dsurf
, mode
);
1568 dri2_surface_get_dri_drawable(_EGLSurface
*surf
)
1570 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
1572 return dri2_surf
->dri_drawable
;
1576 * Called from eglGetProcAddress() via drv->API.GetProcAddress().
1579 dri2_get_proc_address(_EGLDriver
*drv
, const char *procname
)
1581 return _glapi_get_proc_address(procname
);
1585 dri2_create_window_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
1586 _EGLConfig
*conf
, void *native_window
,
1587 const EGLint
*attrib_list
)
1589 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1590 return dri2_dpy
->vtbl
->create_window_surface(drv
, dpy
, conf
, native_window
,
1595 dri2_create_pixmap_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
1596 _EGLConfig
*conf
, void *native_pixmap
,
1597 const EGLint
*attrib_list
)
1599 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1600 return dri2_dpy
->vtbl
->create_pixmap_surface(drv
, dpy
, conf
, native_pixmap
,
1605 dri2_create_pbuffer_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
1606 _EGLConfig
*conf
, const EGLint
*attrib_list
)
1608 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1609 return dri2_dpy
->vtbl
->create_pbuffer_surface(drv
, dpy
, conf
, attrib_list
);
1613 dri2_swap_interval(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
1616 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1617 if (!dri2_dpy
->vtbl
->swap_interval
)
1619 return dri2_dpy
->vtbl
->swap_interval(drv
, dpy
, surf
, interval
);
1623 * Asks the client API to flush any rendering to the drawable so that we can
1624 * do our swapbuffers.
1627 dri2_flush_drawable_for_swapbuffers(_EGLDisplay
*disp
, _EGLSurface
*draw
)
1629 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1630 __DRIdrawable
*dri_drawable
= dri2_dpy
->vtbl
->get_dri_drawable(draw
);
1632 if (dri2_dpy
->flush
) {
1633 if (dri2_dpy
->flush
->base
.version
>= 4) {
1634 /* We know there's a current context because:
1636 * "If surface is not bound to the calling thread’s current
1637 * context, an EGL_BAD_SURFACE error is generated."
1639 _EGLContext
*ctx
= _eglGetCurrentContext();
1640 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
1642 /* From the EGL 1.4 spec (page 52):
1644 * "The contents of ancillary buffers are always undefined
1645 * after calling eglSwapBuffers."
1647 dri2_dpy
->flush
->flush_with_flags(dri2_ctx
->dri_context
,
1649 __DRI2_FLUSH_DRAWABLE
|
1650 __DRI2_FLUSH_INVALIDATE_ANCILLARY
,
1651 __DRI2_THROTTLE_SWAPBUFFER
);
1653 dri2_dpy
->flush
->flush(dri_drawable
);
1659 dri2_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
)
1661 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1662 _EGLContext
*ctx
= _eglGetCurrentContext();
1665 dri2_surf_update_fence_fd(ctx
, dpy
, surf
);
1666 return dri2_dpy
->vtbl
->swap_buffers(drv
, dpy
, surf
);
1670 dri2_swap_buffers_with_damage(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
1672 const EGLint
*rects
, EGLint n_rects
)
1674 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1675 _EGLContext
*ctx
= _eglGetCurrentContext();
1678 dri2_surf_update_fence_fd(ctx
, dpy
, surf
);
1679 return dri2_dpy
->vtbl
->swap_buffers_with_damage(drv
, dpy
, surf
,
1684 dri2_swap_buffers_region(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
1685 EGLint numRects
, const EGLint
*rects
)
1687 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1688 return dri2_dpy
->vtbl
->swap_buffers_region(drv
, dpy
, surf
, numRects
, rects
);
1692 dri2_set_damage_region(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
1693 EGLint
*rects
, EGLint n_rects
)
1695 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1696 return dri2_dpy
->vtbl
->set_damage_region(drv
, dpy
, surf
, rects
, n_rects
);
1700 dri2_post_sub_buffer(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
1701 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
1703 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1704 return dri2_dpy
->vtbl
->post_sub_buffer(drv
, dpy
, surf
, x
, y
, width
, height
);
1708 dri2_copy_buffers(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
1709 void *native_pixmap_target
)
1711 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1712 return dri2_dpy
->vtbl
->copy_buffers(drv
, dpy
, surf
, native_pixmap_target
);
1716 dri2_query_buffer_age(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
)
1718 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1719 return dri2_dpy
->vtbl
->query_buffer_age(drv
, dpy
, surf
);
1723 dri2_wait_client(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLContext
*ctx
)
1725 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1726 _EGLSurface
*surf
= ctx
->DrawSurface
;
1727 __DRIdrawable
*dri_drawable
= dri2_dpy
->vtbl
->get_dri_drawable(surf
);
1731 /* FIXME: If EGL allows frontbuffer rendering for window surfaces,
1732 * we need to copy fake to real here.*/
1734 if (dri2_dpy
->flush
!= NULL
)
1735 dri2_dpy
->flush
->flush(dri_drawable
);
1741 dri2_wait_native(_EGLDriver
*drv
, _EGLDisplay
*disp
, EGLint engine
)
1746 if (engine
!= EGL_CORE_NATIVE_ENGINE
)
1747 return _eglError(EGL_BAD_PARAMETER
, "eglWaitNative");
1754 dri2_bind_tex_image(_EGLDriver
*drv
,
1755 _EGLDisplay
*disp
, _EGLSurface
*surf
, EGLint buffer
)
1757 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1758 struct dri2_egl_context
*dri2_ctx
;
1760 GLint format
, target
;
1761 __DRIdrawable
*dri_drawable
= dri2_dpy
->vtbl
->get_dri_drawable(surf
);
1763 ctx
= _eglGetCurrentContext();
1764 dri2_ctx
= dri2_egl_context(ctx
);
1766 if (!_eglBindTexImage(drv
, disp
, surf
, buffer
))
1769 switch (surf
->TextureFormat
) {
1770 case EGL_TEXTURE_RGB
:
1771 format
= __DRI_TEXTURE_FORMAT_RGB
;
1773 case EGL_TEXTURE_RGBA
:
1774 format
= __DRI_TEXTURE_FORMAT_RGBA
;
1777 assert(!"Unexpected texture format in dri2_bind_tex_image()");
1778 format
= __DRI_TEXTURE_FORMAT_RGBA
;
1781 switch (surf
->TextureTarget
) {
1782 case EGL_TEXTURE_2D
:
1783 target
= GL_TEXTURE_2D
;
1786 target
= GL_TEXTURE_2D
;
1787 assert(!"Unexpected texture target in dri2_bind_tex_image()");
1790 dri2_dpy
->tex_buffer
->setTexBuffer2(dri2_ctx
->dri_context
,
1798 dri2_release_tex_image(_EGLDriver
*drv
,
1799 _EGLDisplay
*disp
, _EGLSurface
*surf
, EGLint buffer
)
1801 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1802 struct dri2_egl_context
*dri2_ctx
;
1805 __DRIdrawable
*dri_drawable
= dri2_dpy
->vtbl
->get_dri_drawable(surf
);
1807 ctx
= _eglGetCurrentContext();
1808 dri2_ctx
= dri2_egl_context(ctx
);
1810 if (!_eglReleaseTexImage(drv
, disp
, surf
, buffer
))
1813 switch (surf
->TextureTarget
) {
1814 case EGL_TEXTURE_2D
:
1815 target
= GL_TEXTURE_2D
;
1821 if (dri2_dpy
->tex_buffer
->base
.version
>= 3 &&
1822 dri2_dpy
->tex_buffer
->releaseTexBuffer
!= NULL
) {
1823 dri2_dpy
->tex_buffer
->releaseTexBuffer(dri2_ctx
->dri_context
,
1824 target
, dri_drawable
);
1831 dri2_create_image(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLContext
*ctx
,
1832 EGLenum target
, EGLClientBuffer buffer
,
1833 const EGLint
*attr_list
)
1835 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1836 return dri2_dpy
->vtbl
->create_image(drv
, dpy
, ctx
, target
, buffer
,
1841 dri2_create_image_from_dri(_EGLDisplay
*disp
, __DRIimage
*dri_image
)
1843 struct dri2_egl_image
*dri2_img
;
1845 if (dri_image
== NULL
) {
1846 _eglError(EGL_BAD_ALLOC
, "dri2_create_image");
1850 dri2_img
= malloc(sizeof *dri2_img
);
1852 _eglError(EGL_BAD_ALLOC
, "dri2_create_image");
1856 _eglInitImage(&dri2_img
->base
, disp
);
1858 dri2_img
->dri_image
= dri_image
;
1860 return &dri2_img
->base
;
1864 * Translate a DRI Image extension error code into an EGL error code.
1867 egl_error_from_dri_image_error(int dri_error
)
1869 switch (dri_error
) {
1870 case __DRI_IMAGE_ERROR_SUCCESS
:
1872 case __DRI_IMAGE_ERROR_BAD_ALLOC
:
1873 return EGL_BAD_ALLOC
;
1874 case __DRI_IMAGE_ERROR_BAD_MATCH
:
1875 return EGL_BAD_MATCH
;
1876 case __DRI_IMAGE_ERROR_BAD_PARAMETER
:
1877 return EGL_BAD_PARAMETER
;
1878 case __DRI_IMAGE_ERROR_BAD_ACCESS
:
1879 return EGL_BAD_ACCESS
;
1882 return EGL_BAD_ALLOC
;
1887 dri2_create_image_khr_renderbuffer(_EGLDisplay
*disp
, _EGLContext
*ctx
,
1888 EGLClientBuffer buffer
,
1889 const EGLint
*attr_list
)
1891 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1892 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
1893 GLuint renderbuffer
= (GLuint
) (uintptr_t) buffer
;
1894 __DRIimage
*dri_image
;
1896 if (renderbuffer
== 0) {
1897 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
1898 return EGL_NO_IMAGE_KHR
;
1901 if (!disp
->Extensions
.KHR_gl_renderbuffer_image
) {
1902 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
1903 return EGL_NO_IMAGE_KHR
;
1906 if (dri2_dpy
->image
->base
.version
>= 17 &&
1907 dri2_dpy
->image
->createImageFromRenderbuffer2
) {
1908 unsigned error
= ~0;
1910 dri_image
= dri2_dpy
->image
->createImageFromRenderbuffer2(
1911 dri2_ctx
->dri_context
, renderbuffer
, NULL
, &error
);
1913 assert(!!dri_image
== (error
== __DRI_IMAGE_ERROR_SUCCESS
));
1916 _eglError(egl_error_from_dri_image_error(error
), "dri2_create_image_khr");
1917 return EGL_NO_IMAGE_KHR
;
1920 dri_image
= dri2_dpy
->image
->createImageFromRenderbuffer(
1921 dri2_ctx
->dri_context
, renderbuffer
, NULL
);
1923 _eglError(EGL_BAD_ALLOC
, "dri2_create_image_khr");
1924 return EGL_NO_IMAGE_KHR
;
1928 return dri2_create_image_from_dri(disp
, dri_image
);
1931 #ifdef HAVE_WAYLAND_PLATFORM
1933 /* This structure describes how a wl_buffer maps to one or more
1934 * __DRIimages. A wl_drm_buffer stores the wl_drm format code and the
1935 * offsets and strides of the planes in the buffer. This table maps a
1936 * wl_drm format code to a description of the planes in the buffer
1937 * that lets us create a __DRIimage for each of the planes. */
1939 static const struct wl_drm_components_descriptor
{
1940 uint32_t dri_components
;
1943 } wl_drm_components
[] = {
1944 { __DRI_IMAGE_COMPONENTS_RGB
, EGL_TEXTURE_RGB
, 1 },
1945 { __DRI_IMAGE_COMPONENTS_RGBA
, EGL_TEXTURE_RGBA
, 1 },
1946 { __DRI_IMAGE_COMPONENTS_Y_U_V
, EGL_TEXTURE_Y_U_V_WL
, 3 },
1947 { __DRI_IMAGE_COMPONENTS_Y_UV
, EGL_TEXTURE_Y_UV_WL
, 2 },
1948 { __DRI_IMAGE_COMPONENTS_Y_XUXV
, EGL_TEXTURE_Y_XUXV_WL
, 2 },
1952 dri2_create_image_wayland_wl_buffer(_EGLDisplay
*disp
, _EGLContext
*ctx
,
1953 EGLClientBuffer _buffer
,
1954 const EGLint
*attr_list
)
1956 struct wl_drm_buffer
*buffer
;
1957 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1958 const struct wl_drm_components_descriptor
*f
;
1959 __DRIimage
*dri_image
;
1960 _EGLImageAttribs attrs
;
1963 buffer
= wayland_drm_buffer_get(dri2_dpy
->wl_server_drm
,
1964 (struct wl_resource
*) _buffer
);
1968 if (!_eglParseImageAttribList(&attrs
, disp
, attr_list
))
1971 plane
= attrs
.PlaneWL
;
1972 f
= buffer
->driver_format
;
1973 if (plane
< 0 || plane
>= f
->nplanes
) {
1974 _eglError(EGL_BAD_PARAMETER
,
1975 "dri2_create_image_wayland_wl_buffer (plane out of bounds)");
1979 dri_image
= dri2_dpy
->image
->fromPlanar(buffer
->driver_buffer
, plane
, NULL
);
1980 if (dri_image
== NULL
&& plane
== 0)
1981 dri_image
= dri2_dpy
->image
->dupImage(buffer
->driver_buffer
, NULL
);
1982 if (dri_image
== NULL
) {
1983 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_wayland_wl_buffer");
1987 return dri2_create_image_from_dri(disp
, dri_image
);
1992 dri2_get_sync_values_chromium(_EGLDisplay
*dpy
, _EGLSurface
*surf
,
1993 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
1996 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1997 return dri2_dpy
->vtbl
->get_sync_values(dpy
, surf
, ust
, msc
, sbc
);
2001 * Set the error code after a call to
2002 * dri2_egl_image::dri_image::createImageFromTexture.
2005 dri2_create_image_khr_texture_error(int dri_error
)
2007 EGLint egl_error
= egl_error_from_dri_image_error(dri_error
);
2009 if (egl_error
!= EGL_SUCCESS
)
2010 _eglError(egl_error
, "dri2_create_image_khr_texture");
2014 dri2_create_image_khr_texture(_EGLDisplay
*disp
, _EGLContext
*ctx
,
2016 EGLClientBuffer buffer
,
2017 const EGLint
*attr_list
)
2019 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2020 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
2021 struct dri2_egl_image
*dri2_img
;
2022 GLuint texture
= (GLuint
) (uintptr_t) buffer
;
2023 _EGLImageAttribs attrs
;
2029 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
2030 return EGL_NO_IMAGE_KHR
;
2033 if (!_eglParseImageAttribList(&attrs
, disp
, attr_list
))
2034 return EGL_NO_IMAGE_KHR
;
2037 case EGL_GL_TEXTURE_2D_KHR
:
2038 if (!disp
->Extensions
.KHR_gl_texture_2D_image
) {
2039 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
2040 return EGL_NO_IMAGE_KHR
;
2043 gl_target
= GL_TEXTURE_2D
;
2045 case EGL_GL_TEXTURE_3D_KHR
:
2046 if (!disp
->Extensions
.KHR_gl_texture_3D_image
) {
2047 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
2048 return EGL_NO_IMAGE_KHR
;
2051 depth
= attrs
.GLTextureZOffset
;
2052 gl_target
= GL_TEXTURE_3D
;
2054 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR
:
2055 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR
:
2056 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR
:
2057 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR
:
2058 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR
:
2059 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR
:
2060 if (!disp
->Extensions
.KHR_gl_texture_cubemap_image
) {
2061 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
2062 return EGL_NO_IMAGE_KHR
;
2065 depth
= target
- EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR
;
2066 gl_target
= GL_TEXTURE_CUBE_MAP
;
2069 unreachable("Unexpected target in dri2_create_image_khr_texture()");
2070 return EGL_NO_IMAGE_KHR
;
2073 dri2_img
= malloc(sizeof *dri2_img
);
2075 _eglError(EGL_BAD_ALLOC
, "dri2_create_image_khr");
2076 return EGL_NO_IMAGE_KHR
;
2079 _eglInitImage(&dri2_img
->base
, disp
);
2081 dri2_img
->dri_image
=
2082 dri2_dpy
->image
->createImageFromTexture(dri2_ctx
->dri_context
,
2086 attrs
.GLTextureLevel
,
2089 dri2_create_image_khr_texture_error(error
);
2091 if (!dri2_img
->dri_image
) {
2093 return EGL_NO_IMAGE_KHR
;
2095 return &dri2_img
->base
;
2099 dri2_query_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
2100 EGLint attribute
, EGLint
*value
)
2102 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
2103 if (!dri2_dpy
->vtbl
->query_surface
)
2104 return _eglQuerySurface(drv
, dpy
, surf
, attribute
, value
);
2105 return dri2_dpy
->vtbl
->query_surface(drv
, dpy
, surf
, attribute
, value
);
2108 static struct wl_buffer
*
2109 dri2_create_wayland_buffer_from_image(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
2112 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
2113 return dri2_dpy
->vtbl
->create_wayland_buffer_from_image(drv
, dpy
, img
);
2118 dri2_create_image_mesa_drm_buffer(_EGLDisplay
*disp
, _EGLContext
*ctx
,
2119 EGLClientBuffer buffer
, const EGLint
*attr_list
)
2121 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2122 EGLint format
, name
, pitch
;
2123 _EGLImageAttribs attrs
;
2124 __DRIimage
*dri_image
;
2126 name
= (EGLint
) (uintptr_t) buffer
;
2128 if (!_eglParseImageAttribList(&attrs
, disp
, attr_list
))
2131 if (attrs
.Width
<= 0 || attrs
.Height
<= 0 ||
2132 attrs
.DRMBufferStrideMESA
<= 0) {
2133 _eglError(EGL_BAD_PARAMETER
,
2134 "bad width, height or stride");
2138 switch (attrs
.DRMBufferFormatMESA
) {
2139 case EGL_DRM_BUFFER_FORMAT_ARGB32_MESA
:
2140 format
= __DRI_IMAGE_FORMAT_ARGB8888
;
2141 pitch
= attrs
.DRMBufferStrideMESA
;
2144 _eglError(EGL_BAD_PARAMETER
,
2145 "dri2_create_image_khr: unsupported pixmap depth");
2150 dri2_dpy
->image
->createImageFromName(dri2_dpy
->dri_screen
,
2158 return dri2_create_image_from_dri(disp
, dri_image
);
2162 dri2_check_dma_buf_attribs(const _EGLImageAttribs
*attrs
)
2167 * "Required attributes and their values are as follows:
2169 * * EGL_WIDTH & EGL_HEIGHT: The logical dimensions of the buffer in pixels
2171 * * EGL_LINUX_DRM_FOURCC_EXT: The pixel format of the buffer, as specified
2172 * by drm_fourcc.h and used as the pixel_format parameter of the
2173 * drm_mode_fb_cmd2 ioctl."
2177 * "* If <target> is EGL_LINUX_DMA_BUF_EXT, and the list of attributes is
2178 * incomplete, EGL_BAD_PARAMETER is generated."
2180 if (attrs
->Width
<= 0 || attrs
->Height
<= 0 ||
2181 !attrs
->DMABufFourCC
.IsPresent
)
2182 return _eglError(EGL_BAD_PARAMETER
, "attribute(s) missing");
2187 * "If <target> is EGL_LINUX_DMA_BUF_EXT and one or more of the values
2188 * specified for a plane's pitch or offset isn't supported by EGL,
2189 * EGL_BAD_ACCESS is generated."
2191 for (unsigned i
= 0; i
< ARRAY_SIZE(attrs
->DMABufPlanePitches
); ++i
) {
2192 if (attrs
->DMABufPlanePitches
[i
].IsPresent
&&
2193 attrs
->DMABufPlanePitches
[i
].Value
<= 0)
2194 return _eglError(EGL_BAD_ACCESS
, "invalid pitch");
2198 * If <target> is EGL_LINUX_DMA_BUF_EXT, both or neither of the following
2199 * attribute values may be given.
2201 * This is referring to EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT and
2202 * EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT, and the same for other planes.
2204 for (unsigned i
= 0; i
< DMA_BUF_MAX_PLANES
; ++i
) {
2205 if (attrs
->DMABufPlaneModifiersLo
[i
].IsPresent
!=
2206 attrs
->DMABufPlaneModifiersHi
[i
].IsPresent
)
2207 return _eglError(EGL_BAD_PARAMETER
, "modifier attribute lo or hi missing");
2210 /* Although the EGL_EXT_image_dma_buf_import_modifiers spec doesn't
2211 * mandate it, we only accept the same modifier across all planes. */
2212 for (unsigned i
= 1; i
< DMA_BUF_MAX_PLANES
; ++i
) {
2213 if (attrs
->DMABufPlaneFds
[i
].IsPresent
) {
2214 if ((attrs
->DMABufPlaneModifiersLo
[0].IsPresent
!=
2215 attrs
->DMABufPlaneModifiersLo
[i
].IsPresent
) ||
2216 (attrs
->DMABufPlaneModifiersLo
[0].Value
!=
2217 attrs
->DMABufPlaneModifiersLo
[i
].Value
) ||
2218 (attrs
->DMABufPlaneModifiersHi
[0].Value
!=
2219 attrs
->DMABufPlaneModifiersHi
[i
].Value
))
2220 return _eglError(EGL_BAD_PARAMETER
, "modifier attributes not equal");
2227 /* Returns the total number of planes for the format or zero if it isn't a
2228 * valid fourcc format.
2231 dri2_num_fourcc_format_planes(EGLint format
)
2235 case DRM_FORMAT_RG88
:
2236 case DRM_FORMAT_GR88
:
2237 case DRM_FORMAT_R16
:
2238 case DRM_FORMAT_GR1616
:
2239 case DRM_FORMAT_RGB332
:
2240 case DRM_FORMAT_BGR233
:
2241 case DRM_FORMAT_XRGB4444
:
2242 case DRM_FORMAT_XBGR4444
:
2243 case DRM_FORMAT_RGBX4444
:
2244 case DRM_FORMAT_BGRX4444
:
2245 case DRM_FORMAT_ARGB4444
:
2246 case DRM_FORMAT_ABGR4444
:
2247 case DRM_FORMAT_RGBA4444
:
2248 case DRM_FORMAT_BGRA4444
:
2249 case DRM_FORMAT_XRGB1555
:
2250 case DRM_FORMAT_XBGR1555
:
2251 case DRM_FORMAT_RGBX5551
:
2252 case DRM_FORMAT_BGRX5551
:
2253 case DRM_FORMAT_ARGB1555
:
2254 case DRM_FORMAT_ABGR1555
:
2255 case DRM_FORMAT_RGBA5551
:
2256 case DRM_FORMAT_BGRA5551
:
2257 case DRM_FORMAT_RGB565
:
2258 case DRM_FORMAT_BGR565
:
2259 case DRM_FORMAT_RGB888
:
2260 case DRM_FORMAT_BGR888
:
2261 case DRM_FORMAT_XRGB8888
:
2262 case DRM_FORMAT_XBGR8888
:
2263 case DRM_FORMAT_RGBX8888
:
2264 case DRM_FORMAT_BGRX8888
:
2265 case DRM_FORMAT_ARGB8888
:
2266 case DRM_FORMAT_ABGR8888
:
2267 case DRM_FORMAT_RGBA8888
:
2268 case DRM_FORMAT_BGRA8888
:
2269 case DRM_FORMAT_XRGB2101010
:
2270 case DRM_FORMAT_XBGR2101010
:
2271 case DRM_FORMAT_RGBX1010102
:
2272 case DRM_FORMAT_BGRX1010102
:
2273 case DRM_FORMAT_ARGB2101010
:
2274 case DRM_FORMAT_ABGR2101010
:
2275 case DRM_FORMAT_RGBA1010102
:
2276 case DRM_FORMAT_BGRA1010102
:
2277 case DRM_FORMAT_YUYV
:
2278 case DRM_FORMAT_YVYU
:
2279 case DRM_FORMAT_UYVY
:
2280 case DRM_FORMAT_VYUY
:
2283 case DRM_FORMAT_NV12
:
2284 case DRM_FORMAT_NV21
:
2285 case DRM_FORMAT_NV16
:
2286 case DRM_FORMAT_NV61
:
2289 case DRM_FORMAT_YUV410
:
2290 case DRM_FORMAT_YVU410
:
2291 case DRM_FORMAT_YUV411
:
2292 case DRM_FORMAT_YVU411
:
2293 case DRM_FORMAT_YUV420
:
2294 case DRM_FORMAT_YVU420
:
2295 case DRM_FORMAT_YUV422
:
2296 case DRM_FORMAT_YVU422
:
2297 case DRM_FORMAT_YUV444
:
2298 case DRM_FORMAT_YVU444
:
2306 /* Returns the total number of file descriptors. Zero indicates an error. */
2308 dri2_check_dma_buf_format(const _EGLImageAttribs
*attrs
)
2310 unsigned plane_n
= dri2_num_fourcc_format_planes(attrs
->DMABufFourCC
.Value
);
2312 _eglError(EGL_BAD_ATTRIBUTE
, "invalid format");
2316 for (unsigned i
= plane_n
; i
< DMA_BUF_MAX_PLANES
; i
++) {
2318 * The modifiers extension spec says:
2320 * "Modifiers may modify any attribute of a buffer import, including
2321 * but not limited to adding extra planes to a format which
2322 * otherwise does not have those planes. As an example, a modifier
2323 * may add a plane for an external compression buffer to a
2324 * single-plane format. The exact meaning and effect of any
2325 * modifier is canonically defined by drm_fourcc.h, not as part of
2328 if (attrs
->DMABufPlaneModifiersLo
[i
].IsPresent
&&
2329 attrs
->DMABufPlaneModifiersHi
[i
].IsPresent
) {
2337 * "* If <target> is EGL_LINUX_DMA_BUF_EXT, and the list of attributes is
2338 * incomplete, EGL_BAD_PARAMETER is generated."
2340 for (unsigned i
= 0; i
< plane_n
; ++i
) {
2341 if (!attrs
->DMABufPlaneFds
[i
].IsPresent
||
2342 !attrs
->DMABufPlaneOffsets
[i
].IsPresent
||
2343 !attrs
->DMABufPlanePitches
[i
].IsPresent
) {
2344 _eglError(EGL_BAD_PARAMETER
, "plane attribute(s) missing");
2350 * The spec also says:
2352 * "If <target> is EGL_LINUX_DMA_BUF_EXT, and the EGL_LINUX_DRM_FOURCC_EXT
2353 * attribute indicates a single-plane format, EGL_BAD_ATTRIBUTE is
2354 * generated if any of the EGL_DMA_BUF_PLANE1_* or EGL_DMA_BUF_PLANE2_*
2355 * or EGL_DMA_BUF_PLANE3_* attributes are specified."
2357 for (unsigned i
= plane_n
; i
< DMA_BUF_MAX_PLANES
; ++i
) {
2358 if (attrs
->DMABufPlaneFds
[i
].IsPresent
||
2359 attrs
->DMABufPlaneOffsets
[i
].IsPresent
||
2360 attrs
->DMABufPlanePitches
[i
].IsPresent
) {
2361 _eglError(EGL_BAD_ATTRIBUTE
, "too many plane attributes");
2370 dri2_query_dma_buf_formats(_EGLDriver
*drv
, _EGLDisplay
*disp
,
2371 EGLint max
, EGLint
*formats
, EGLint
*count
)
2373 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2374 if (max
< 0 || (max
> 0 && formats
== NULL
))
2375 return _eglError(EGL_BAD_PARAMETER
, "invalid value for max count of formats");
2377 if (dri2_dpy
->image
->base
.version
< 15 ||
2378 dri2_dpy
->image
->queryDmaBufFormats
== NULL
)
2381 if (!dri2_dpy
->image
->queryDmaBufFormats(dri2_dpy
->dri_screen
, max
,
2386 /* Assert that all of the formats returned are actually fourcc formats.
2387 * Some day, if we want the internal interface function to be able to
2388 * return the fake fourcc formats defined in dri_interface.h, we'll have
2389 * to do something more clever here to pair the list down to just real
2390 * fourcc formats so that we don't leak the fake internal ones.
2392 for (int i
= 0; i
< *count
; i
++) {
2393 assert(dri2_num_fourcc_format_planes(formats
[i
]) > 0);
2401 dri2_query_dma_buf_modifiers(_EGLDriver
*drv
, _EGLDisplay
*disp
, EGLint format
,
2402 EGLint max
, EGLuint64KHR
*modifiers
,
2403 EGLBoolean
*external_only
, EGLint
*count
)
2405 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2407 if (dri2_num_fourcc_format_planes(format
) == 0)
2408 return _eglError(EGL_BAD_PARAMETER
, "invalid fourcc format");
2411 return _eglError(EGL_BAD_PARAMETER
, "invalid value for max count of formats");
2413 if (max
> 0 && modifiers
== NULL
)
2414 return _eglError(EGL_BAD_PARAMETER
, "invalid modifiers array");
2416 if (dri2_dpy
->image
->base
.version
< 15 ||
2417 dri2_dpy
->image
->queryDmaBufModifiers
== NULL
)
2420 if (dri2_dpy
->image
->queryDmaBufModifiers(dri2_dpy
->dri_screen
, format
,
2422 (unsigned int *) external_only
,
2424 return _eglError(EGL_BAD_PARAMETER
, "invalid format");
2432 * "If eglCreateImageKHR is successful for a EGL_LINUX_DMA_BUF_EXT target, the
2433 * EGL will take a reference to the dma_buf(s) which it will release at any
2434 * time while the EGLDisplay is initialized. It is the responsibility of the
2435 * application to close the dma_buf file descriptors."
2437 * Therefore we must never close or otherwise modify the file descriptors.
2440 dri2_create_image_dma_buf(_EGLDisplay
*disp
, _EGLContext
*ctx
,
2441 EGLClientBuffer buffer
, const EGLint
*attr_list
)
2443 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2445 _EGLImageAttribs attrs
;
2446 __DRIimage
*dri_image
;
2448 int fds
[DMA_BUF_MAX_PLANES
];
2449 int pitches
[DMA_BUF_MAX_PLANES
];
2450 int offsets
[DMA_BUF_MAX_PLANES
];
2452 bool has_modifier
= false;
2458 * ""* If <target> is EGL_LINUX_DMA_BUF_EXT and <buffer> is not NULL, the
2459 * error EGL_BAD_PARAMETER is generated."
2461 if (buffer
!= NULL
) {
2462 _eglError(EGL_BAD_PARAMETER
, "buffer not NULL");
2466 if (!_eglParseImageAttribList(&attrs
, disp
, attr_list
))
2469 if (!dri2_check_dma_buf_attribs(&attrs
))
2472 num_fds
= dri2_check_dma_buf_format(&attrs
);
2476 for (unsigned i
= 0; i
< num_fds
; ++i
) {
2477 fds
[i
] = attrs
.DMABufPlaneFds
[i
].Value
;
2478 pitches
[i
] = attrs
.DMABufPlanePitches
[i
].Value
;
2479 offsets
[i
] = attrs
.DMABufPlaneOffsets
[i
].Value
;
2482 /* dri2_check_dma_buf_attribs ensures that the modifier, if available,
2483 * will be present in attrs.DMABufPlaneModifiersLo[0] and
2484 * attrs.DMABufPlaneModifiersHi[0] */
2485 if (attrs
.DMABufPlaneModifiersLo
[0].IsPresent
) {
2486 modifier
= combine_u32_into_u64(attrs
.DMABufPlaneModifiersHi
[0].Value
,
2487 attrs
.DMABufPlaneModifiersLo
[0].Value
);
2488 has_modifier
= true;
2492 if (dri2_dpy
->image
->base
.version
< 15 ||
2493 dri2_dpy
->image
->createImageFromDmaBufs2
== NULL
) {
2494 _eglError(EGL_BAD_MATCH
, "unsupported dma_buf format modifier");
2495 return EGL_NO_IMAGE_KHR
;
2498 dri2_dpy
->image
->createImageFromDmaBufs2(dri2_dpy
->dri_screen
,
2499 attrs
.Width
, attrs
.Height
, attrs
.DMABufFourCC
.Value
,
2500 modifier
, fds
, num_fds
, pitches
, offsets
,
2501 attrs
.DMABufYuvColorSpaceHint
.Value
,
2502 attrs
.DMABufSampleRangeHint
.Value
,
2503 attrs
.DMABufChromaHorizontalSiting
.Value
,
2504 attrs
.DMABufChromaVerticalSiting
.Value
,
2510 dri2_dpy
->image
->createImageFromDmaBufs(dri2_dpy
->dri_screen
,
2511 attrs
.Width
, attrs
.Height
, attrs
.DMABufFourCC
.Value
,
2512 fds
, num_fds
, pitches
, offsets
,
2513 attrs
.DMABufYuvColorSpaceHint
.Value
,
2514 attrs
.DMABufSampleRangeHint
.Value
,
2515 attrs
.DMABufChromaHorizontalSiting
.Value
,
2516 attrs
.DMABufChromaVerticalSiting
.Value
,
2520 dri2_create_image_khr_texture_error(error
);
2523 return EGL_NO_IMAGE_KHR
;
2525 res
= dri2_create_image_from_dri(disp
, dri_image
);
2530 dri2_create_drm_image_mesa(_EGLDriver
*drv
, _EGLDisplay
*disp
,
2531 const EGLint
*attr_list
)
2533 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2534 struct dri2_egl_image
*dri2_img
;
2535 _EGLImageAttribs attrs
;
2536 unsigned int dri_use
, valid_mask
;
2542 _eglError(EGL_BAD_PARAMETER
, __func__
);
2543 return EGL_NO_IMAGE_KHR
;
2546 if (!_eglParseImageAttribList(&attrs
, disp
, attr_list
))
2547 return EGL_NO_IMAGE_KHR
;
2549 if (attrs
.Width
<= 0 || attrs
.Height
<= 0) {
2550 _eglError(EGL_BAD_PARAMETER
, __func__
);
2551 return EGL_NO_IMAGE_KHR
;
2554 switch (attrs
.DRMBufferFormatMESA
) {
2555 case EGL_DRM_BUFFER_FORMAT_ARGB32_MESA
:
2556 format
= __DRI_IMAGE_FORMAT_ARGB8888
;
2559 _eglError(EGL_BAD_PARAMETER
, __func__
);
2560 return EGL_NO_IMAGE_KHR
;
2564 EGL_DRM_BUFFER_USE_SCANOUT_MESA
|
2565 EGL_DRM_BUFFER_USE_SHARE_MESA
|
2566 EGL_DRM_BUFFER_USE_CURSOR_MESA
;
2567 if (attrs
.DRMBufferUseMESA
& ~valid_mask
) {
2568 _eglError(EGL_BAD_PARAMETER
, __func__
);
2569 return EGL_NO_IMAGE_KHR
;
2573 if (attrs
.DRMBufferUseMESA
& EGL_DRM_BUFFER_USE_SHARE_MESA
)
2574 dri_use
|= __DRI_IMAGE_USE_SHARE
;
2575 if (attrs
.DRMBufferUseMESA
& EGL_DRM_BUFFER_USE_SCANOUT_MESA
)
2576 dri_use
|= __DRI_IMAGE_USE_SCANOUT
;
2577 if (attrs
.DRMBufferUseMESA
& EGL_DRM_BUFFER_USE_CURSOR_MESA
)
2578 dri_use
|= __DRI_IMAGE_USE_CURSOR
;
2580 dri2_img
= malloc(sizeof *dri2_img
);
2582 _eglError(EGL_BAD_ALLOC
, "dri2_create_image_khr");
2583 return EGL_NO_IMAGE_KHR
;
2586 _eglInitImage(&dri2_img
->base
, disp
);
2588 dri2_img
->dri_image
=
2589 dri2_dpy
->image
->createImage(dri2_dpy
->dri_screen
,
2590 attrs
.Width
, attrs
.Height
,
2591 format
, dri_use
, dri2_img
);
2592 if (dri2_img
->dri_image
== NULL
) {
2594 _eglError(EGL_BAD_ALLOC
, "dri2_create_drm_image_mesa");
2595 return EGL_NO_IMAGE_KHR
;
2598 return &dri2_img
->base
;
2602 dri2_export_drm_image_mesa(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLImage
*img
,
2603 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
2605 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2606 struct dri2_egl_image
*dri2_img
= dri2_egl_image(img
);
2610 if (name
&& !dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2611 __DRI_IMAGE_ATTRIB_NAME
, name
))
2612 return _eglError(EGL_BAD_ALLOC
, "dri2_export_drm_image_mesa");
2615 dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2616 __DRI_IMAGE_ATTRIB_HANDLE
, handle
);
2619 dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2620 __DRI_IMAGE_ATTRIB_STRIDE
, stride
);
2626 * Checks if we can support EGL_MESA_image_dma_buf_export on this image.
2628 * The spec provides a boolean return for the driver to reject exporting for
2629 * basically any reason, but doesn't specify any particular error cases. For
2630 * now, we just fail if we don't have a DRM fourcc for the format.
2633 dri2_can_export_dma_buf_image(_EGLDisplay
*disp
, _EGLImage
*img
)
2635 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2636 struct dri2_egl_image
*dri2_img
= dri2_egl_image(img
);
2639 if (!dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2640 __DRI_IMAGE_ATTRIB_FOURCC
, &fourcc
)) {
2648 dri2_export_dma_buf_image_query_mesa(_EGLDriver
*drv
, _EGLDisplay
*disp
,
2650 EGLint
*fourcc
, EGLint
*nplanes
,
2651 EGLuint64KHR
*modifiers
)
2653 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2654 struct dri2_egl_image
*dri2_img
= dri2_egl_image(img
);
2658 if (!dri2_can_export_dma_buf_image(disp
, img
))
2662 dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2663 __DRI_IMAGE_ATTRIB_NUM_PLANES
, nplanes
);
2665 dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2666 __DRI_IMAGE_ATTRIB_FOURCC
, fourcc
);
2675 dri2_export_dma_buf_image_mesa(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLImage
*img
,
2676 int *fds
, EGLint
*strides
, EGLint
*offsets
)
2678 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2679 struct dri2_egl_image
*dri2_img
= dri2_egl_image(img
);
2683 if (!dri2_can_export_dma_buf_image(disp
, img
))
2686 /* rework later to provide multiple fds/strides/offsets */
2688 dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2689 __DRI_IMAGE_ATTRIB_FD
, fds
);
2692 dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2693 __DRI_IMAGE_ATTRIB_STRIDE
, strides
);
2697 bool ret
= dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2698 __DRI_IMAGE_ATTRIB_OFFSET
, &img_offset
);
2700 offsets
[0] = img_offset
;
2711 dri2_create_image_khr(_EGLDriver
*drv
, _EGLDisplay
*disp
,
2712 _EGLContext
*ctx
, EGLenum target
,
2713 EGLClientBuffer buffer
, const EGLint
*attr_list
)
2718 case EGL_GL_TEXTURE_2D_KHR
:
2719 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR
:
2720 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR
:
2721 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR
:
2722 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR
:
2723 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR
:
2724 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR
:
2725 case EGL_GL_TEXTURE_3D_KHR
:
2726 return dri2_create_image_khr_texture(disp
, ctx
, target
, buffer
, attr_list
);
2727 case EGL_GL_RENDERBUFFER_KHR
:
2728 return dri2_create_image_khr_renderbuffer(disp
, ctx
, buffer
, attr_list
);
2730 case EGL_DRM_BUFFER_MESA
:
2731 return dri2_create_image_mesa_drm_buffer(disp
, ctx
, buffer
, attr_list
);
2732 case EGL_LINUX_DMA_BUF_EXT
:
2733 return dri2_create_image_dma_buf(disp
, ctx
, buffer
, attr_list
);
2735 #ifdef HAVE_WAYLAND_PLATFORM
2736 case EGL_WAYLAND_BUFFER_WL
:
2737 return dri2_create_image_wayland_wl_buffer(disp
, ctx
, buffer
, attr_list
);
2740 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
2741 return EGL_NO_IMAGE_KHR
;
2746 dri2_destroy_image_khr(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLImage
*image
)
2748 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2749 struct dri2_egl_image
*dri2_img
= dri2_egl_image(image
);
2753 dri2_dpy
->image
->destroyImage(dri2_img
->dri_image
);
2759 #ifdef HAVE_WAYLAND_PLATFORM
2762 dri2_wl_reference_buffer(void *user_data
, uint32_t name
, int fd
,
2763 struct wl_drm_buffer
*buffer
)
2765 _EGLDisplay
*disp
= user_data
;
2766 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2768 int dri_components
= 0;
2771 img
= dri2_dpy
->image
->createImageFromNames(dri2_dpy
->dri_screen
,
2780 img
= dri2_dpy
->image
->createImageFromFds(dri2_dpy
->dri_screen
,
2792 dri2_dpy
->image
->queryImage(img
, __DRI_IMAGE_ATTRIB_COMPONENTS
, &dri_components
);
2794 buffer
->driver_format
= NULL
;
2795 for (int i
= 0; i
< ARRAY_SIZE(wl_drm_components
); i
++)
2796 if (wl_drm_components
[i
].dri_components
== dri_components
)
2797 buffer
->driver_format
= &wl_drm_components
[i
];
2799 if (buffer
->driver_format
== NULL
)
2800 dri2_dpy
->image
->destroyImage(img
);
2802 buffer
->driver_buffer
= img
;
2806 dri2_wl_release_buffer(void *user_data
, struct wl_drm_buffer
*buffer
)
2808 _EGLDisplay
*disp
= user_data
;
2809 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2811 dri2_dpy
->image
->destroyImage(buffer
->driver_buffer
);
2815 dri2_bind_wayland_display_wl(_EGLDriver
*drv
, _EGLDisplay
*disp
,
2816 struct wl_display
*wl_dpy
)
2818 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2819 const struct wayland_drm_callbacks wl_drm_callbacks
= {
2820 .authenticate
= (int(*)(void *, uint32_t)) dri2_dpy
->vtbl
->authenticate
,
2821 .reference_buffer
= dri2_wl_reference_buffer
,
2822 .release_buffer
= dri2_wl_release_buffer
2829 if (dri2_dpy
->wl_server_drm
)
2832 if (drmGetCap(dri2_dpy
->fd
, DRM_CAP_PRIME
, &cap
) == 0 &&
2833 cap
== (DRM_PRIME_CAP_IMPORT
| DRM_PRIME_CAP_EXPORT
) &&
2834 dri2_dpy
->image
->base
.version
>= 7 &&
2835 dri2_dpy
->image
->createImageFromFds
!= NULL
)
2836 flags
|= WAYLAND_DRM_PRIME
;
2838 dri2_dpy
->wl_server_drm
=
2839 wayland_drm_init(wl_dpy
, dri2_dpy
->device_name
,
2840 &wl_drm_callbacks
, disp
, flags
);
2842 if (!dri2_dpy
->wl_server_drm
)
2845 #ifdef HAVE_DRM_PLATFORM
2846 /* We have to share the wl_drm instance with gbm, so gbm can convert
2847 * wl_buffers to gbm bos. */
2848 if (dri2_dpy
->gbm_dri
)
2849 dri2_dpy
->gbm_dri
->wl_drm
= dri2_dpy
->wl_server_drm
;
2856 dri2_unbind_wayland_display_wl(_EGLDriver
*drv
, _EGLDisplay
*disp
,
2857 struct wl_display
*wl_dpy
)
2859 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2863 if (!dri2_dpy
->wl_server_drm
)
2866 wayland_drm_uninit(dri2_dpy
->wl_server_drm
);
2867 dri2_dpy
->wl_server_drm
= NULL
;
2873 dri2_query_wayland_buffer_wl(_EGLDriver
*drv
, _EGLDisplay
*disp
,
2874 struct wl_resource
*buffer_resource
,
2875 EGLint attribute
, EGLint
*value
)
2877 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2878 struct wl_drm_buffer
*buffer
;
2879 const struct wl_drm_components_descriptor
*format
;
2881 buffer
= wayland_drm_buffer_get(dri2_dpy
->wl_server_drm
, buffer_resource
);
2885 format
= buffer
->driver_format
;
2886 switch (attribute
) {
2887 case EGL_TEXTURE_FORMAT
:
2888 *value
= format
->components
;
2891 *value
= buffer
->width
;
2894 *value
= buffer
->height
;
2903 dri2_egl_ref_sync(struct dri2_egl_sync
*sync
)
2905 p_atomic_inc(&sync
->refcount
);
2909 dri2_egl_unref_sync(struct dri2_egl_display
*dri2_dpy
,
2910 struct dri2_egl_sync
*dri2_sync
)
2912 if (p_atomic_dec_zero(&dri2_sync
->refcount
)) {
2913 switch (dri2_sync
->base
.Type
) {
2914 case EGL_SYNC_REUSABLE_KHR
:
2915 cnd_destroy(&dri2_sync
->cond
);
2917 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
2918 if (dri2_sync
->base
.SyncFd
!= EGL_NO_NATIVE_FENCE_FD_ANDROID
)
2919 close(dri2_sync
->base
.SyncFd
);
2925 if (dri2_sync
->fence
)
2926 dri2_dpy
->fence
->destroy_fence(dri2_dpy
->dri_screen
, dri2_sync
->fence
);
2933 dri2_create_sync(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
2934 EGLenum type
, const EGLAttrib
*attrib_list
)
2936 _EGLContext
*ctx
= _eglGetCurrentContext();
2937 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
2938 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
2939 struct dri2_egl_sync
*dri2_sync
;
2941 pthread_condattr_t attr
;
2943 dri2_sync
= calloc(1, sizeof(struct dri2_egl_sync
));
2945 _eglError(EGL_BAD_ALLOC
, "eglCreateSyncKHR");
2949 if (!_eglInitSync(&dri2_sync
->base
, dpy
, type
, attrib_list
)) {
2955 case EGL_SYNC_FENCE_KHR
:
2956 dri2_sync
->fence
= dri2_dpy
->fence
->create_fence(dri2_ctx
->dri_context
);
2957 if (!dri2_sync
->fence
) {
2958 /* Why did it fail? DRI doesn't return an error code, so we emit
2959 * a generic EGL error that doesn't communicate user error.
2961 _eglError(EGL_BAD_ALLOC
, "eglCreateSyncKHR");
2967 case EGL_SYNC_CL_EVENT_KHR
:
2968 dri2_sync
->fence
= dri2_dpy
->fence
->get_fence_from_cl_event(
2969 dri2_dpy
->dri_screen
,
2970 dri2_sync
->base
.CLEvent
);
2971 /* this can only happen if the cl_event passed in is invalid. */
2972 if (!dri2_sync
->fence
) {
2973 _eglError(EGL_BAD_ATTRIBUTE
, "eglCreateSyncKHR");
2978 /* the initial status must be "signaled" if the cl_event is signaled */
2979 if (dri2_dpy
->fence
->client_wait_sync(dri2_ctx
->dri_context
,
2980 dri2_sync
->fence
, 0, 0))
2981 dri2_sync
->base
.SyncStatus
= EGL_SIGNALED_KHR
;
2984 case EGL_SYNC_REUSABLE_KHR
:
2985 /* intialize attr */
2986 ret
= pthread_condattr_init(&attr
);
2989 _eglError(EGL_BAD_ACCESS
, "eglCreateSyncKHR");
2994 /* change clock attribute to CLOCK_MONOTONIC */
2995 ret
= pthread_condattr_setclock(&attr
, CLOCK_MONOTONIC
);
2998 _eglError(EGL_BAD_ACCESS
, "eglCreateSyncKHR");
3003 ret
= pthread_cond_init(&dri2_sync
->cond
, &attr
);
3006 _eglError(EGL_BAD_ACCESS
, "eglCreateSyncKHR");
3011 /* initial status of reusable sync must be "unsignaled" */
3012 dri2_sync
->base
.SyncStatus
= EGL_UNSIGNALED_KHR
;
3015 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
3016 if (dri2_dpy
->fence
->create_fence_fd
) {
3017 dri2_sync
->fence
= dri2_dpy
->fence
->create_fence_fd(
3018 dri2_ctx
->dri_context
,
3019 dri2_sync
->base
.SyncFd
);
3021 if (!dri2_sync
->fence
) {
3022 _eglError(EGL_BAD_ATTRIBUTE
, "eglCreateSyncKHR");
3029 p_atomic_set(&dri2_sync
->refcount
, 1);
3030 return &dri2_sync
->base
;
3034 dri2_destroy_sync(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSync
*sync
)
3036 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
3037 struct dri2_egl_sync
*dri2_sync
= dri2_egl_sync(sync
);
3038 EGLint ret
= EGL_TRUE
;
3041 /* if type of sync is EGL_SYNC_REUSABLE_KHR and it is not signaled yet,
3042 * then unlock all threads possibly blocked by the reusable sync before
3045 if (dri2_sync
->base
.Type
== EGL_SYNC_REUSABLE_KHR
&&
3046 dri2_sync
->base
.SyncStatus
== EGL_UNSIGNALED_KHR
) {
3047 dri2_sync
->base
.SyncStatus
= EGL_SIGNALED_KHR
;
3048 /* unblock all threads currently blocked by sync */
3049 err
= cnd_broadcast(&dri2_sync
->cond
);
3052 _eglError(EGL_BAD_ACCESS
, "eglDestroySyncKHR");
3057 dri2_egl_unref_sync(dri2_dpy
, dri2_sync
);
3063 dri2_dup_native_fence_fd(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSync
*sync
)
3065 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
3066 struct dri2_egl_sync
*dri2_sync
= dri2_egl_sync(sync
);
3068 assert(sync
->Type
== EGL_SYNC_NATIVE_FENCE_ANDROID
);
3070 if (sync
->SyncFd
== EGL_NO_NATIVE_FENCE_FD_ANDROID
) {
3071 /* try to retrieve the actual native fence fd.. if rendering is
3072 * not flushed this will just return -1, aka NO_NATIVE_FENCE_FD:
3074 sync
->SyncFd
= dri2_dpy
->fence
->get_fence_fd(dri2_dpy
->dri_screen
,
3078 if (sync
->SyncFd
== EGL_NO_NATIVE_FENCE_FD_ANDROID
) {
3079 /* if native fence fd still not created, return an error: */
3080 _eglError(EGL_BAD_PARAMETER
, "eglDupNativeFenceFDANDROID");
3081 return EGL_NO_NATIVE_FENCE_FD_ANDROID
;
3084 return dup(sync
->SyncFd
);
3088 dri2_set_blob_cache_funcs(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
3089 EGLSetBlobFuncANDROID set
,
3090 EGLGetBlobFuncANDROID get
)
3092 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
3093 dri2_dpy
->blob
->set_cache_funcs(dri2_dpy
->dri_screen
,
3099 dri2_client_wait_sync(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSync
*sync
,
3100 EGLint flags
, EGLTime timeout
)
3102 _EGLContext
*ctx
= _eglGetCurrentContext();
3103 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
3104 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
3105 struct dri2_egl_sync
*dri2_sync
= dri2_egl_sync(sync
);
3106 unsigned wait_flags
= 0;
3108 EGLint ret
= EGL_CONDITION_SATISFIED_KHR
;
3110 /* The EGL_KHR_fence_sync spec states:
3112 * "If no context is current for the bound API,
3113 * the EGL_SYNC_FLUSH_COMMANDS_BIT_KHR bit is ignored.
3115 if (dri2_ctx
&& flags
& EGL_SYNC_FLUSH_COMMANDS_BIT_KHR
)
3116 wait_flags
|= __DRI2_FENCE_FLAG_FLUSH_COMMANDS
;
3118 /* the sync object should take a reference while waiting */
3119 dri2_egl_ref_sync(dri2_sync
);
3121 switch (sync
->Type
) {
3122 case EGL_SYNC_FENCE_KHR
:
3123 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
3124 case EGL_SYNC_CL_EVENT_KHR
:
3125 if (dri2_dpy
->fence
->client_wait_sync(dri2_ctx
? dri2_ctx
->dri_context
: NULL
,
3126 dri2_sync
->fence
, wait_flags
,
3128 dri2_sync
->base
.SyncStatus
= EGL_SIGNALED_KHR
;
3130 ret
= EGL_TIMEOUT_EXPIRED_KHR
;
3133 case EGL_SYNC_REUSABLE_KHR
:
3134 if (dri2_ctx
&& dri2_sync
->base
.SyncStatus
== EGL_UNSIGNALED_KHR
&&
3135 (flags
& EGL_SYNC_FLUSH_COMMANDS_BIT_KHR
)) {
3136 /* flush context if EGL_SYNC_FLUSH_COMMANDS_BIT_KHR is set */
3140 /* if timeout is EGL_FOREVER_KHR, it should wait without any timeout.*/
3141 if (timeout
== EGL_FOREVER_KHR
) {
3142 mtx_lock(&dri2_sync
->mutex
);
3143 cnd_wait(&dri2_sync
->cond
, &dri2_sync
->mutex
);
3144 mtx_unlock(&dri2_sync
->mutex
);
3146 /* if reusable sync has not been yet signaled */
3147 if (dri2_sync
->base
.SyncStatus
!= EGL_SIGNALED_KHR
) {
3148 /* timespecs for cnd_timedwait */
3149 struct timespec current
;
3150 struct timespec expire
;
3152 /* We override the clock to monotonic when creating the condition
3154 clock_gettime(CLOCK_MONOTONIC
, ¤t
);
3156 /* calculating when to expire */
3157 expire
.tv_nsec
= timeout
% 1000000000L;
3158 expire
.tv_sec
= timeout
/ 1000000000L;
3160 expire
.tv_nsec
+= current
.tv_nsec
;
3161 expire
.tv_sec
+= current
.tv_sec
;
3163 /* expire.nsec now is a number between 0 and 1999999998 */
3164 if (expire
.tv_nsec
> 999999999L) {
3166 expire
.tv_nsec
-= 1000000000L;
3169 mtx_lock(&dri2_sync
->mutex
);
3170 ret
= cnd_timedwait(&dri2_sync
->cond
, &dri2_sync
->mutex
, &expire
);
3171 mtx_unlock(&dri2_sync
->mutex
);
3173 if (ret
== thrd_busy
) {
3174 if (dri2_sync
->base
.SyncStatus
== EGL_UNSIGNALED_KHR
) {
3175 ret
= EGL_TIMEOUT_EXPIRED_KHR
;
3177 _eglError(EGL_BAD_ACCESS
, "eglClientWaitSyncKHR");
3185 dri2_egl_unref_sync(dri2_dpy
, dri2_sync
);
3191 dri2_signal_sync(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSync
*sync
,
3194 struct dri2_egl_sync
*dri2_sync
= dri2_egl_sync(sync
);
3197 if (sync
->Type
!= EGL_SYNC_REUSABLE_KHR
)
3198 return _eglError(EGL_BAD_MATCH
, "eglSignalSyncKHR");
3200 if (mode
!= EGL_SIGNALED_KHR
&& mode
!= EGL_UNSIGNALED_KHR
)
3201 return _eglError(EGL_BAD_ATTRIBUTE
, "eglSignalSyncKHR");
3203 dri2_sync
->base
.SyncStatus
= mode
;
3205 if (mode
== EGL_SIGNALED_KHR
) {
3206 ret
= cnd_broadcast(&dri2_sync
->cond
);
3208 /* fail to broadcast */
3210 return _eglError(EGL_BAD_ACCESS
, "eglSignalSyncKHR");
3217 dri2_server_wait_sync(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSync
*sync
)
3219 _EGLContext
*ctx
= _eglGetCurrentContext();
3220 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
3221 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
3222 struct dri2_egl_sync
*dri2_sync
= dri2_egl_sync(sync
);
3224 dri2_dpy
->fence
->server_wait_sync(dri2_ctx
->dri_context
,
3225 dri2_sync
->fence
, 0);
3230 dri2_interop_query_device_info(_EGLDisplay
*dpy
, _EGLContext
*ctx
,
3231 struct mesa_glinterop_device_info
*out
)
3233 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
3234 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
3236 if (!dri2_dpy
->interop
)
3237 return MESA_GLINTEROP_UNSUPPORTED
;
3239 return dri2_dpy
->interop
->query_device_info(dri2_ctx
->dri_context
, out
);
3243 dri2_interop_export_object(_EGLDisplay
*dpy
, _EGLContext
*ctx
,
3244 struct mesa_glinterop_export_in
*in
,
3245 struct mesa_glinterop_export_out
*out
)
3247 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
3248 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
3250 if (!dri2_dpy
->interop
)
3251 return MESA_GLINTEROP_UNSUPPORTED
;
3253 return dri2_dpy
->interop
->export_object(dri2_ctx
->dri_context
, in
, out
);
3257 * This is the main entrypoint into the driver, called by libEGL.
3258 * Create a new _EGLDriver object and init its dispatch table.
3261 _eglBuiltInDriver(void)
3263 _EGLDriver
*dri2_drv
= calloc(1, sizeof *dri2_drv
);
3267 _eglInitDriverFallbacks(dri2_drv
);
3268 dri2_drv
->API
.Initialize
= dri2_initialize
;
3269 dri2_drv
->API
.Terminate
= dri2_terminate
;
3270 dri2_drv
->API
.CreateContext
= dri2_create_context
;
3271 dri2_drv
->API
.DestroyContext
= dri2_destroy_context
;
3272 dri2_drv
->API
.MakeCurrent
= dri2_make_current
;
3273 dri2_drv
->API
.CreateWindowSurface
= dri2_create_window_surface
;
3274 dri2_drv
->API
.CreatePixmapSurface
= dri2_create_pixmap_surface
;
3275 dri2_drv
->API
.CreatePbufferSurface
= dri2_create_pbuffer_surface
;
3276 dri2_drv
->API
.DestroySurface
= dri2_destroy_surface
;
3277 dri2_drv
->API
.GetProcAddress
= dri2_get_proc_address
;
3278 dri2_drv
->API
.WaitClient
= dri2_wait_client
;
3279 dri2_drv
->API
.WaitNative
= dri2_wait_native
;
3280 dri2_drv
->API
.BindTexImage
= dri2_bind_tex_image
;
3281 dri2_drv
->API
.ReleaseTexImage
= dri2_release_tex_image
;
3282 dri2_drv
->API
.SwapInterval
= dri2_swap_interval
;
3283 dri2_drv
->API
.SwapBuffers
= dri2_swap_buffers
;
3284 dri2_drv
->API
.SwapBuffersWithDamageEXT
= dri2_swap_buffers_with_damage
;
3285 dri2_drv
->API
.SwapBuffersRegionNOK
= dri2_swap_buffers_region
;
3286 dri2_drv
->API
.SetDamageRegion
= dri2_set_damage_region
;
3287 dri2_drv
->API
.PostSubBufferNV
= dri2_post_sub_buffer
;
3288 dri2_drv
->API
.CopyBuffers
= dri2_copy_buffers
,
3289 dri2_drv
->API
.QueryBufferAge
= dri2_query_buffer_age
;
3290 dri2_drv
->API
.CreateImageKHR
= dri2_create_image
;
3291 dri2_drv
->API
.DestroyImageKHR
= dri2_destroy_image_khr
;
3292 dri2_drv
->API
.CreateWaylandBufferFromImageWL
= dri2_create_wayland_buffer_from_image
;
3293 dri2_drv
->API
.QuerySurface
= dri2_query_surface
;
3295 dri2_drv
->API
.CreateDRMImageMESA
= dri2_create_drm_image_mesa
;
3296 dri2_drv
->API
.ExportDRMImageMESA
= dri2_export_drm_image_mesa
;
3297 dri2_drv
->API
.ExportDMABUFImageQueryMESA
= dri2_export_dma_buf_image_query_mesa
;
3298 dri2_drv
->API
.ExportDMABUFImageMESA
= dri2_export_dma_buf_image_mesa
;
3299 dri2_drv
->API
.QueryDmaBufFormatsEXT
= dri2_query_dma_buf_formats
;
3300 dri2_drv
->API
.QueryDmaBufModifiersEXT
= dri2_query_dma_buf_modifiers
;
3302 #ifdef HAVE_WAYLAND_PLATFORM
3303 dri2_drv
->API
.BindWaylandDisplayWL
= dri2_bind_wayland_display_wl
;
3304 dri2_drv
->API
.UnbindWaylandDisplayWL
= dri2_unbind_wayland_display_wl
;
3305 dri2_drv
->API
.QueryWaylandBufferWL
= dri2_query_wayland_buffer_wl
;
3307 dri2_drv
->API
.GetSyncValuesCHROMIUM
= dri2_get_sync_values_chromium
;
3308 dri2_drv
->API
.CreateSyncKHR
= dri2_create_sync
;
3309 dri2_drv
->API
.ClientWaitSyncKHR
= dri2_client_wait_sync
;
3310 dri2_drv
->API
.SignalSyncKHR
= dri2_signal_sync
;
3311 dri2_drv
->API
.WaitSyncKHR
= dri2_server_wait_sync
;
3312 dri2_drv
->API
.DestroySyncKHR
= dri2_destroy_sync
;
3313 dri2_drv
->API
.GLInteropQueryDeviceInfo
= dri2_interop_query_device_info
;
3314 dri2_drv
->API
.GLInteropExportObject
= dri2_interop_export_object
;
3315 dri2_drv
->API
.DupNativeFenceFDANDROID
= dri2_dup_native_fence_fd
;
3316 dri2_drv
->API
.SetBlobCacheFuncsANDROID
= dri2_set_blob_cache_funcs
;
3318 dri2_drv
->Name
= "DRI2";