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
);
344 unreachable("duplicates should not be possible");
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 static const char *search_path_vars
[] = {
487 "LIBGL_DRIVERS_PATH",
491 return loader_open_driver(dri2_dpy
->driver_name
,
497 dri2_load_driver_dri3(_EGLDisplay
*disp
)
499 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
500 const __DRIextension
**extensions
;
502 extensions
= dri2_open_driver(disp
);
506 if (!dri2_bind_extensions(dri2_dpy
, dri3_driver_extensions
, extensions
, false)) {
507 dlclose(dri2_dpy
->driver
);
510 dri2_dpy
->driver_extensions
= extensions
;
516 dri2_load_driver(_EGLDisplay
*disp
)
518 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
519 const __DRIextension
**extensions
;
521 extensions
= dri2_open_driver(disp
);
525 if (!dri2_bind_extensions(dri2_dpy
, dri2_driver_extensions
, extensions
, false)) {
526 dlclose(dri2_dpy
->driver
);
529 dri2_dpy
->driver_extensions
= extensions
;
535 dri2_load_driver_swrast(_EGLDisplay
*disp
)
537 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
538 const __DRIextension
**extensions
;
540 extensions
= dri2_open_driver(disp
);
544 if (!dri2_bind_extensions(dri2_dpy
, swrast_driver_extensions
, extensions
, false)) {
545 dlclose(dri2_dpy
->driver
);
548 dri2_dpy
->driver_extensions
= extensions
;
554 dri2_renderer_query_integer(struct dri2_egl_display
*dri2_dpy
, int param
)
556 const __DRI2rendererQueryExtension
*rendererQuery
= dri2_dpy
->rendererQuery
;
557 unsigned int value
= 0;
559 if (!rendererQuery
||
560 rendererQuery
->queryInteger(dri2_dpy
->dri_screen
, param
, &value
) == -1)
567 dri2_setup_screen(_EGLDisplay
*disp
)
569 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
570 unsigned int api_mask
;
573 * EGL 1.5 specification defines the default value to 1. Moreover,
574 * eglSwapInterval() is required to clamp requested value to the supported
575 * range. Since the default value is implicitly assumed to be supported,
576 * use it as both minimum and maximum for the platforms that do not allow
577 * changing the interval. Platforms, which allow it (e.g. x11, wayland)
578 * override these values already.
580 dri2_dpy
->min_swap_interval
= 1;
581 dri2_dpy
->max_swap_interval
= 1;
582 dri2_dpy
->default_swap_interval
= 1;
584 if (dri2_dpy
->image_driver
) {
585 api_mask
= dri2_dpy
->image_driver
->getAPIMask(dri2_dpy
->dri_screen
);
586 } else if (dri2_dpy
->dri2
) {
587 api_mask
= dri2_dpy
->dri2
->getAPIMask(dri2_dpy
->dri_screen
);
589 assert(dri2_dpy
->swrast
);
590 api_mask
= 1 << __DRI_API_OPENGL
|
591 1 << __DRI_API_GLES
|
592 1 << __DRI_API_GLES2
|
593 1 << __DRI_API_GLES3
;
596 disp
->ClientAPIs
= 0;
597 if ((api_mask
& (1 <<__DRI_API_OPENGL
)) && _eglIsApiValid(EGL_OPENGL_API
))
598 disp
->ClientAPIs
|= EGL_OPENGL_BIT
;
599 if ((api_mask
& (1 << __DRI_API_GLES
)) && _eglIsApiValid(EGL_OPENGL_ES_API
))
600 disp
->ClientAPIs
|= EGL_OPENGL_ES_BIT
;
601 if ((api_mask
& (1 << __DRI_API_GLES2
)) && _eglIsApiValid(EGL_OPENGL_ES_API
))
602 disp
->ClientAPIs
|= EGL_OPENGL_ES2_BIT
;
603 if ((api_mask
& (1 << __DRI_API_GLES3
)) && _eglIsApiValid(EGL_OPENGL_ES_API
))
604 disp
->ClientAPIs
|= EGL_OPENGL_ES3_BIT_KHR
;
606 assert(dri2_dpy
->image_driver
|| dri2_dpy
->dri2
|| dri2_dpy
->swrast
);
607 disp
->Extensions
.KHR_no_config_context
= EGL_TRUE
;
608 disp
->Extensions
.KHR_surfaceless_context
= EGL_TRUE
;
610 /* Report back to EGL the bitmask of priorities supported */
611 disp
->Extensions
.IMG_context_priority
=
612 dri2_renderer_query_integer(dri2_dpy
,
613 __DRI2_RENDERER_HAS_CONTEXT_PRIORITY
);
615 disp
->Extensions
.EXT_pixel_format_float
= EGL_TRUE
;
617 if (dri2_renderer_query_integer(dri2_dpy
,
618 __DRI2_RENDERER_HAS_FRAMEBUFFER_SRGB
))
619 disp
->Extensions
.KHR_gl_colorspace
= EGL_TRUE
;
621 if (dri2_dpy
->image_driver
||
622 (dri2_dpy
->dri2
&& dri2_dpy
->dri2
->base
.version
>= 3) ||
623 (dri2_dpy
->swrast
&& dri2_dpy
->swrast
->base
.version
>= 3)) {
624 disp
->Extensions
.KHR_create_context
= EGL_TRUE
;
626 if (dri2_dpy
->robustness
)
627 disp
->Extensions
.EXT_create_context_robustness
= EGL_TRUE
;
630 if (dri2_dpy
->no_error
)
631 disp
->Extensions
.KHR_create_context_no_error
= EGL_TRUE
;
633 if (dri2_dpy
->fence
) {
634 disp
->Extensions
.KHR_fence_sync
= EGL_TRUE
;
635 disp
->Extensions
.KHR_wait_sync
= EGL_TRUE
;
636 if (dri2_dpy
->fence
->get_fence_from_cl_event
)
637 disp
->Extensions
.KHR_cl_event2
= EGL_TRUE
;
638 if (dri2_dpy
->fence
->base
.version
>= 2 &&
639 dri2_dpy
->fence
->get_capabilities
) {
640 unsigned capabilities
=
641 dri2_dpy
->fence
->get_capabilities(dri2_dpy
->dri_screen
);
642 disp
->Extensions
.ANDROID_native_fence_sync
=
643 (capabilities
& __DRI_FENCE_CAP_NATIVE_FD
) != 0;
648 disp
->Extensions
.ANDROID_blob_cache
= EGL_TRUE
;
650 disp
->Extensions
.KHR_reusable_sync
= EGL_TRUE
;
652 if (dri2_dpy
->image
) {
653 if (dri2_dpy
->image
->base
.version
>= 10 &&
654 dri2_dpy
->image
->getCapabilities
!= NULL
) {
657 capabilities
= dri2_dpy
->image
->getCapabilities(dri2_dpy
->dri_screen
);
658 disp
->Extensions
.MESA_drm_image
= (capabilities
& __DRI_IMAGE_CAP_GLOBAL_NAMES
) != 0;
660 if (dri2_dpy
->image
->base
.version
>= 11)
661 disp
->Extensions
.MESA_image_dma_buf_export
= EGL_TRUE
;
663 disp
->Extensions
.MESA_drm_image
= EGL_TRUE
;
664 if (dri2_dpy
->image
->base
.version
>= 11)
665 disp
->Extensions
.MESA_image_dma_buf_export
= EGL_TRUE
;
668 disp
->Extensions
.KHR_image_base
= EGL_TRUE
;
669 disp
->Extensions
.KHR_gl_renderbuffer_image
= EGL_TRUE
;
670 if (dri2_dpy
->image
->base
.version
>= 5 &&
671 dri2_dpy
->image
->createImageFromTexture
) {
672 disp
->Extensions
.KHR_gl_texture_2D_image
= EGL_TRUE
;
673 disp
->Extensions
.KHR_gl_texture_cubemap_image
= EGL_TRUE
;
675 if (dri2_renderer_query_integer(dri2_dpy
,
676 __DRI2_RENDERER_HAS_TEXTURE_3D
))
677 disp
->Extensions
.KHR_gl_texture_3D_image
= EGL_TRUE
;
680 if (dri2_dpy
->image
->base
.version
>= 8 &&
681 dri2_dpy
->image
->createImageFromDmaBufs
) {
682 disp
->Extensions
.EXT_image_dma_buf_import
= EGL_TRUE
;
684 if (dri2_dpy
->image
->base
.version
>= 15 &&
685 dri2_dpy
->image
->createImageFromDmaBufs2
&&
686 dri2_dpy
->image
->queryDmaBufFormats
&&
687 dri2_dpy
->image
->queryDmaBufModifiers
) {
688 disp
->Extensions
.EXT_image_dma_buf_import_modifiers
= EGL_TRUE
;
693 if (dri2_dpy
->flush_control
)
694 disp
->Extensions
.KHR_context_flush_control
= EGL_TRUE
;
698 dri2_setup_swap_interval(_EGLDisplay
*disp
, int max_swap_interval
)
700 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
701 GLint vblank_mode
= DRI_CONF_VBLANK_DEF_INTERVAL_1
;
703 /* Allow driconf to override applications.*/
704 if (dri2_dpy
->config
)
705 dri2_dpy
->config
->configQueryi(dri2_dpy
->dri_screen
,
706 "vblank_mode", &vblank_mode
);
707 switch (vblank_mode
) {
708 case DRI_CONF_VBLANK_NEVER
:
709 dri2_dpy
->min_swap_interval
= 0;
710 dri2_dpy
->max_swap_interval
= 0;
711 dri2_dpy
->default_swap_interval
= 0;
713 case DRI_CONF_VBLANK_ALWAYS_SYNC
:
714 dri2_dpy
->min_swap_interval
= 1;
715 dri2_dpy
->max_swap_interval
= max_swap_interval
;
716 dri2_dpy
->default_swap_interval
= 1;
718 case DRI_CONF_VBLANK_DEF_INTERVAL_0
:
719 dri2_dpy
->min_swap_interval
= 0;
720 dri2_dpy
->max_swap_interval
= max_swap_interval
;
721 dri2_dpy
->default_swap_interval
= 0;
724 case DRI_CONF_VBLANK_DEF_INTERVAL_1
:
725 dri2_dpy
->min_swap_interval
= 0;
726 dri2_dpy
->max_swap_interval
= max_swap_interval
;
727 dri2_dpy
->default_swap_interval
= 1;
732 /* All platforms but DRM call this function to create the screen and populate
733 * the driver_configs. DRM inherits that information from its display - GBM.
736 dri2_create_screen(_EGLDisplay
*disp
)
738 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
740 if (dri2_dpy
->image_driver
) {
741 dri2_dpy
->dri_screen
=
742 dri2_dpy
->image_driver
->createNewScreen2(0, dri2_dpy
->fd
,
743 dri2_dpy
->loader_extensions
,
744 dri2_dpy
->driver_extensions
,
745 &dri2_dpy
->driver_configs
,
747 } else if (dri2_dpy
->dri2
) {
748 if (dri2_dpy
->dri2
->base
.version
>= 4) {
749 dri2_dpy
->dri_screen
=
750 dri2_dpy
->dri2
->createNewScreen2(0, dri2_dpy
->fd
,
751 dri2_dpy
->loader_extensions
,
752 dri2_dpy
->driver_extensions
,
753 &dri2_dpy
->driver_configs
, disp
);
755 dri2_dpy
->dri_screen
=
756 dri2_dpy
->dri2
->createNewScreen(0, dri2_dpy
->fd
,
757 dri2_dpy
->loader_extensions
,
758 &dri2_dpy
->driver_configs
, disp
);
761 assert(dri2_dpy
->swrast
);
762 if (dri2_dpy
->swrast
->base
.version
>= 4) {
763 dri2_dpy
->dri_screen
=
764 dri2_dpy
->swrast
->createNewScreen2(0, dri2_dpy
->loader_extensions
,
765 dri2_dpy
->driver_extensions
,
766 &dri2_dpy
->driver_configs
, disp
);
768 dri2_dpy
->dri_screen
=
769 dri2_dpy
->swrast
->createNewScreen(0, dri2_dpy
->loader_extensions
,
770 &dri2_dpy
->driver_configs
, disp
);
774 if (dri2_dpy
->dri_screen
== NULL
) {
775 _eglLog(_EGL_WARNING
, "DRI2: failed to create dri screen");
779 dri2_dpy
->own_dri_screen
= true;
784 dri2_setup_extensions(_EGLDisplay
*disp
)
786 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
787 const struct dri2_extension_match
*mandatory_core_extensions
;
788 const __DRIextension
**extensions
;
790 extensions
= dri2_dpy
->core
->getExtensions(dri2_dpy
->dri_screen
);
792 if (dri2_dpy
->image_driver
|| dri2_dpy
->dri2
)
793 mandatory_core_extensions
= dri2_core_extensions
;
795 mandatory_core_extensions
= swrast_core_extensions
;
797 if (!dri2_bind_extensions(dri2_dpy
, mandatory_core_extensions
, extensions
, false))
800 #ifdef HAVE_DRI3_MODIFIERS
801 dri2_dpy
->multibuffers_available
=
802 (dri2_dpy
->dri3_major_version
> 1 || (dri2_dpy
->dri3_major_version
== 1 &&
803 dri2_dpy
->dri3_minor_version
>= 2)) &&
804 (dri2_dpy
->present_major_version
> 1 || (dri2_dpy
->present_major_version
== 1 &&
805 dri2_dpy
->present_minor_version
>= 2)) &&
806 (dri2_dpy
->image
&& dri2_dpy
->image
->base
.version
>= 15);
809 dri2_bind_extensions(dri2_dpy
, optional_core_extensions
, extensions
, true);
814 * Called via eglInitialize(), GLX_drv->API.Initialize().
816 * This must be guaranteed to be called exactly once, even if eglInitialize is
817 * called many times (without a eglTerminate in between).
820 dri2_initialize(_EGLDriver
*drv
, _EGLDisplay
*disp
)
822 EGLBoolean ret
= EGL_FALSE
;
823 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
825 /* In the case where the application calls eglMakeCurrent(context1),
826 * eglTerminate, then eglInitialize again (without a call to eglReleaseThread
827 * or eglMakeCurrent(NULL) before that), dri2_dpy structure is still
828 * initialized, as we need it to be able to free context1 correctly.
830 * It would probably be safest to forcibly release the display with
831 * dri2_display_release, to make sure the display is reinitialized correctly.
832 * However, the EGL spec states that we need to keep a reference to the
833 * current context (so we cannot call dri2_make_current(NULL)), and therefore
834 * we would leak context1 as we would be missing the old display connection
835 * to free it up correctly.
838 dri2_dpy
->ref_count
++;
842 loader_set_logger(_eglLog
);
844 switch (disp
->Platform
) {
845 case _EGL_PLATFORM_SURFACELESS
:
846 ret
= dri2_initialize_surfaceless(drv
, disp
);
848 case _EGL_PLATFORM_X11
:
849 ret
= dri2_initialize_x11(drv
, disp
);
851 case _EGL_PLATFORM_DRM
:
852 ret
= dri2_initialize_drm(drv
, disp
);
854 case _EGL_PLATFORM_WAYLAND
:
855 ret
= dri2_initialize_wayland(drv
, disp
);
857 case _EGL_PLATFORM_ANDROID
:
858 ret
= dri2_initialize_android(drv
, disp
);
861 unreachable("Callers ensure we cannot get here.");
868 dri2_dpy
= dri2_egl_display(disp
);
869 dri2_dpy
->ref_count
++;
875 * Decrement display reference count, and free up display if necessary.
878 dri2_display_release(_EGLDisplay
*disp
)
880 struct dri2_egl_display
*dri2_dpy
;
885 dri2_dpy
= dri2_egl_display(disp
);
887 assert(dri2_dpy
->ref_count
> 0);
888 dri2_dpy
->ref_count
--;
890 if (dri2_dpy
->ref_count
> 0)
893 _eglCleanupDisplay(disp
);
894 dri2_display_destroy(disp
);
898 dri2_display_destroy(_EGLDisplay
*disp
)
900 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
902 if (dri2_dpy
->own_dri_screen
) {
903 if (dri2_dpy
->vtbl
&& dri2_dpy
->vtbl
->close_screen_notify
)
904 dri2_dpy
->vtbl
->close_screen_notify(disp
);
905 dri2_dpy
->core
->destroyScreen(dri2_dpy
->dri_screen
);
907 if (dri2_dpy
->fd
>= 0)
909 if (dri2_dpy
->driver
)
910 dlclose(dri2_dpy
->driver
);
911 free(dri2_dpy
->driver_name
);
913 #ifdef HAVE_WAYLAND_PLATFORM
914 free(dri2_dpy
->device_name
);
917 switch (disp
->Platform
) {
918 case _EGL_PLATFORM_X11
:
919 dri2_teardown_x11(dri2_dpy
);
921 case _EGL_PLATFORM_DRM
:
922 dri2_teardown_drm(dri2_dpy
);
924 case _EGL_PLATFORM_WAYLAND
:
925 dri2_teardown_wayland(dri2_dpy
);
928 /* TODO: add teardown for other platforms */
932 /* The drm platform does not create the screen/driver_configs but reuses
933 * the ones from the gbm device. As such the gbm itself is responsible
936 if (disp
->Platform
!= _EGL_PLATFORM_DRM
&& dri2_dpy
->driver_configs
) {
937 for (unsigned i
= 0; dri2_dpy
->driver_configs
[i
]; i
++)
938 free((__DRIconfig
*) dri2_dpy
->driver_configs
[i
]);
939 free(dri2_dpy
->driver_configs
);
942 disp
->DriverData
= NULL
;
946 dri2_egl_surface_alloc_local_buffer(struct dri2_egl_surface
*dri2_surf
,
947 unsigned int att
, unsigned int format
)
949 struct dri2_egl_display
*dri2_dpy
=
950 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
952 if (att
>= ARRAY_SIZE(dri2_surf
->local_buffers
))
955 if (!dri2_surf
->local_buffers
[att
]) {
956 dri2_surf
->local_buffers
[att
] =
957 dri2_dpy
->dri2
->allocateBuffer(dri2_dpy
->dri_screen
, att
, format
,
958 dri2_surf
->base
.Width
, dri2_surf
->base
.Height
);
961 return dri2_surf
->local_buffers
[att
];
965 dri2_egl_surface_free_local_buffers(struct dri2_egl_surface
*dri2_surf
)
967 struct dri2_egl_display
*dri2_dpy
=
968 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
970 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->local_buffers
); i
++) {
971 if (dri2_surf
->local_buffers
[i
]) {
972 dri2_dpy
->dri2
->releaseBuffer(dri2_dpy
->dri_screen
,
973 dri2_surf
->local_buffers
[i
]);
974 dri2_surf
->local_buffers
[i
] = NULL
;
980 * Called via eglTerminate(), drv->API.Terminate().
982 * This must be guaranteed to be called exactly once, even if eglTerminate is
983 * called many times (without a eglInitialize in between).
986 dri2_terminate(_EGLDriver
*drv
, _EGLDisplay
*disp
)
988 /* Release all non-current Context/Surfaces. */
989 _eglReleaseDisplayResources(drv
, disp
);
991 dri2_display_release(disp
);
997 * Set the error code after a call to
998 * dri2_egl_display::dri2::createContextAttribs.
1001 dri2_create_context_attribs_error(int dri_error
)
1005 switch (dri_error
) {
1006 case __DRI_CTX_ERROR_SUCCESS
:
1009 case __DRI_CTX_ERROR_NO_MEMORY
:
1010 egl_error
= EGL_BAD_ALLOC
;
1013 /* From the EGL_KHR_create_context spec, section "Errors":
1015 * * If <config> does not support a client API context compatible
1016 * with the requested API major and minor version, [...] context flags,
1017 * and context reset notification behavior (for client API types where
1018 * these attributes are supported), then an EGL_BAD_MATCH error is
1021 * * If an OpenGL ES context is requested and the values for
1022 * attributes EGL_CONTEXT_MAJOR_VERSION_KHR and
1023 * EGL_CONTEXT_MINOR_VERSION_KHR specify an OpenGL ES version that
1024 * is not defined, than an EGL_BAD_MATCH error is generated.
1026 * * If an OpenGL context is requested, the requested version is
1027 * greater than 3.2, and the value for attribute
1028 * EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR has no bits set; has any
1029 * bits set other than EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR and
1030 * EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR; has more than
1031 * one of these bits set; or if the implementation does not support
1032 * the requested profile, then an EGL_BAD_MATCH error is generated.
1034 case __DRI_CTX_ERROR_BAD_API
:
1035 case __DRI_CTX_ERROR_BAD_VERSION
:
1036 case __DRI_CTX_ERROR_BAD_FLAG
:
1037 egl_error
= EGL_BAD_MATCH
;
1040 /* From the EGL_KHR_create_context spec, section "Errors":
1042 * * If an attribute name or attribute value in <attrib_list> is not
1043 * recognized (including unrecognized bits in bitmask attributes),
1044 * then an EGL_BAD_ATTRIBUTE error is generated."
1046 case __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE
:
1047 case __DRI_CTX_ERROR_UNKNOWN_FLAG
:
1048 egl_error
= EGL_BAD_ATTRIBUTE
;
1052 assert(!"unknown dri_error code");
1053 egl_error
= EGL_BAD_MATCH
;
1057 _eglError(egl_error
, "dri2_create_context");
1061 dri2_fill_context_attribs(struct dri2_egl_context
*dri2_ctx
,
1062 struct dri2_egl_display
*dri2_dpy
,
1063 uint32_t *ctx_attribs
,
1064 unsigned *num_attribs
)
1068 assert(*num_attribs
>= NUM_ATTRIBS
);
1070 ctx_attribs
[pos
++] = __DRI_CTX_ATTRIB_MAJOR_VERSION
;
1071 ctx_attribs
[pos
++] = dri2_ctx
->base
.ClientMajorVersion
;
1072 ctx_attribs
[pos
++] = __DRI_CTX_ATTRIB_MINOR_VERSION
;
1073 ctx_attribs
[pos
++] = dri2_ctx
->base
.ClientMinorVersion
;
1075 if (dri2_ctx
->base
.Flags
!= 0 || dri2_ctx
->base
.NoError
) {
1076 /* If the implementation doesn't support the __DRI2_ROBUSTNESS
1077 * extension, don't even try to send it the robust-access flag.
1078 * It may explode. Instead, generate the required EGL error here.
1080 if ((dri2_ctx
->base
.Flags
& EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR
) != 0
1081 && !dri2_dpy
->robustness
) {
1082 _eglError(EGL_BAD_MATCH
, "eglCreateContext");
1086 ctx_attribs
[pos
++] = __DRI_CTX_ATTRIB_FLAGS
;
1087 ctx_attribs
[pos
++] = dri2_ctx
->base
.Flags
|
1088 (dri2_ctx
->base
.NoError
? __DRI_CTX_FLAG_NO_ERROR
: 0);
1091 if (dri2_ctx
->base
.ResetNotificationStrategy
!= EGL_NO_RESET_NOTIFICATION_KHR
) {
1092 /* If the implementation doesn't support the __DRI2_ROBUSTNESS
1093 * extension, don't even try to send it a reset strategy. It may
1094 * explode. Instead, generate the required EGL error here.
1096 if (!dri2_dpy
->robustness
) {
1097 _eglError(EGL_BAD_CONFIG
, "eglCreateContext");
1101 ctx_attribs
[pos
++] = __DRI_CTX_ATTRIB_RESET_STRATEGY
;
1102 ctx_attribs
[pos
++] = __DRI_CTX_RESET_LOSE_CONTEXT
;
1105 if (dri2_ctx
->base
.ContextPriority
!= EGL_CONTEXT_PRIORITY_MEDIUM_IMG
) {
1108 switch (dri2_ctx
->base
.ContextPriority
) {
1109 case EGL_CONTEXT_PRIORITY_HIGH_IMG
:
1110 val
= __DRI_CTX_PRIORITY_HIGH
;
1112 case EGL_CONTEXT_PRIORITY_MEDIUM_IMG
:
1113 val
= __DRI_CTX_PRIORITY_MEDIUM
;
1115 case EGL_CONTEXT_PRIORITY_LOW_IMG
:
1116 val
= __DRI_CTX_PRIORITY_LOW
;
1119 _eglError(EGL_BAD_CONFIG
, "eglCreateContext");
1123 ctx_attribs
[pos
++] = __DRI_CTX_ATTRIB_PRIORITY
;
1124 ctx_attribs
[pos
++] = val
;
1127 if (dri2_ctx
->base
.ReleaseBehavior
== EGL_CONTEXT_RELEASE_BEHAVIOR_NONE_KHR
) {
1128 ctx_attribs
[pos
++] = __DRI_CTX_ATTRIB_RELEASE_BEHAVIOR
;
1129 ctx_attribs
[pos
++] = __DRI_CTX_RELEASE_BEHAVIOR_NONE
;
1138 * Called via eglCreateContext(), drv->API.CreateContext().
1140 static _EGLContext
*
1141 dri2_create_context(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLConfig
*conf
,
1142 _EGLContext
*share_list
, const EGLint
*attrib_list
)
1144 struct dri2_egl_context
*dri2_ctx
;
1145 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1146 struct dri2_egl_context
*dri2_ctx_shared
= dri2_egl_context(share_list
);
1147 __DRIcontext
*shared
=
1148 dri2_ctx_shared
? dri2_ctx_shared
->dri_context
: NULL
;
1149 struct dri2_egl_config
*dri2_config
= dri2_egl_config(conf
);
1150 const __DRIconfig
*dri_config
;
1153 unsigned num_attribs
= NUM_ATTRIBS
;
1154 uint32_t ctx_attribs
[NUM_ATTRIBS
];
1158 dri2_ctx
= malloc(sizeof *dri2_ctx
);
1160 _eglError(EGL_BAD_ALLOC
, "eglCreateContext");
1164 if (!_eglInitContext(&dri2_ctx
->base
, disp
, conf
, attrib_list
))
1167 /* The EGL_EXT_create_context_robustness spec says:
1169 * "Add to the eglCreateContext context creation errors: [...]
1171 * * If the reset notification behavior of <share_context> and the
1172 * newly created context are different then an EGL_BAD_MATCH error is
1175 if (share_list
&& share_list
->ResetNotificationStrategy
!=
1176 dri2_ctx
->base
.ResetNotificationStrategy
) {
1177 _eglError(EGL_BAD_MATCH
, "eglCreateContext");
1181 /* The EGL_KHR_create_context_no_error spec says:
1183 * "BAD_MATCH is generated if the value of EGL_CONTEXT_OPENGL_NO_ERROR_KHR
1184 * used to create <share_context> does not match the value of
1185 * EGL_CONTEXT_OPENGL_NO_ERROR_KHR for the context being created."
1187 if (share_list
&& share_list
->NoError
!= dri2_ctx
->base
.NoError
) {
1188 _eglError(EGL_BAD_MATCH
, "eglCreateContext");
1192 switch (dri2_ctx
->base
.ClientAPI
) {
1193 case EGL_OPENGL_ES_API
:
1194 switch (dri2_ctx
->base
.ClientMajorVersion
) {
1196 api
= __DRI_API_GLES
;
1199 api
= __DRI_API_GLES2
;
1202 api
= __DRI_API_GLES3
;
1205 _eglError(EGL_BAD_PARAMETER
, "eglCreateContext");
1210 case EGL_OPENGL_API
:
1211 if ((dri2_ctx
->base
.ClientMajorVersion
>= 4
1212 || (dri2_ctx
->base
.ClientMajorVersion
== 3
1213 && dri2_ctx
->base
.ClientMinorVersion
>= 2))
1214 && dri2_ctx
->base
.Profile
== EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR
)
1215 api
= __DRI_API_OPENGL_CORE
;
1217 api
= __DRI_API_OPENGL
;
1220 _eglError(EGL_BAD_PARAMETER
, "eglCreateContext");
1226 /* The config chosen here isn't necessarily
1227 * used for surfaces later.
1228 * A pixmap surface will use the single config.
1229 * This opportunity depends on disabling the
1230 * doubleBufferMode check in
1231 * src/mesa/main/context.c:check_compatible()
1233 if (dri2_config
->dri_config
[1][0])
1234 dri_config
= dri2_config
->dri_config
[1][0];
1236 dri_config
= dri2_config
->dri_config
[0][0];
1241 if (!dri2_fill_context_attribs(dri2_ctx
, dri2_dpy
, ctx_attribs
,
1245 if (dri2_dpy
->image_driver
) {
1246 dri2_ctx
->dri_context
=
1247 dri2_dpy
->image_driver
->createContextAttribs(dri2_dpy
->dri_screen
,
1255 dri2_create_context_attribs_error(error
);
1256 } else if (dri2_dpy
->dri2
) {
1257 if (dri2_dpy
->dri2
->base
.version
>= 3) {
1258 dri2_ctx
->dri_context
=
1259 dri2_dpy
->dri2
->createContextAttribs(dri2_dpy
->dri_screen
,
1267 dri2_create_context_attribs_error(error
);
1269 dri2_ctx
->dri_context
=
1270 dri2_dpy
->dri2
->createNewContextForAPI(dri2_dpy
->dri_screen
,
1277 assert(dri2_dpy
->swrast
);
1278 if (dri2_dpy
->swrast
->base
.version
>= 3) {
1279 dri2_ctx
->dri_context
=
1280 dri2_dpy
->swrast
->createContextAttribs(dri2_dpy
->dri_screen
,
1288 dri2_create_context_attribs_error(error
);
1290 dri2_ctx
->dri_context
=
1291 dri2_dpy
->swrast
->createNewContextForAPI(dri2_dpy
->dri_screen
,
1299 if (!dri2_ctx
->dri_context
)
1302 return &dri2_ctx
->base
;
1310 * Called via eglDestroyContext(), drv->API.DestroyContext().
1313 dri2_destroy_context(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLContext
*ctx
)
1315 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
1316 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1318 if (_eglPutContext(ctx
)) {
1319 dri2_dpy
->core
->destroyContext(dri2_ctx
->dri_context
);
1327 dri2_init_surface(_EGLSurface
*surf
, _EGLDisplay
*dpy
, EGLint type
,
1328 _EGLConfig
*conf
, const EGLint
*attrib_list
, EGLBoolean enable_out_fence
)
1330 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
1331 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1333 dri2_surf
->out_fence_fd
= -1;
1334 dri2_surf
->enable_out_fence
= false;
1335 if (dri2_dpy
->fence
&& dri2_dpy
->fence
->base
.version
>= 2 &&
1336 dri2_dpy
->fence
->get_capabilities
&&
1337 (dri2_dpy
->fence
->get_capabilities(dri2_dpy
->dri_screen
) &
1338 __DRI_FENCE_CAP_NATIVE_FD
)) {
1339 dri2_surf
->enable_out_fence
= enable_out_fence
;
1342 return _eglInitSurface(surf
, dpy
, type
, conf
, attrib_list
);
1346 dri2_surface_set_out_fence_fd( _EGLSurface
*surf
, int fence_fd
)
1348 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
1350 if (dri2_surf
->out_fence_fd
>= 0)
1351 close(dri2_surf
->out_fence_fd
);
1353 dri2_surf
->out_fence_fd
= fence_fd
;
1357 dri2_fini_surface(_EGLSurface
*surf
)
1359 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
1361 dri2_surface_set_out_fence_fd(surf
, -1);
1362 dri2_surf
->enable_out_fence
= false;
1366 dri2_destroy_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
)
1368 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1370 if (!_eglPutSurface(surf
))
1373 return dri2_dpy
->vtbl
->destroy_surface(drv
, dpy
, surf
);
1377 dri2_surf_update_fence_fd(_EGLContext
*ctx
,
1378 _EGLDisplay
*dpy
, _EGLSurface
*surf
)
1380 __DRIcontext
*dri_ctx
= dri2_egl_context(ctx
)->dri_context
;
1381 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1382 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
1386 if (!dri2_surf
->enable_out_fence
)
1389 fence
= dri2_dpy
->fence
->create_fence_fd(dri_ctx
, -1);
1391 fence_fd
= dri2_dpy
->fence
->get_fence_fd(dri2_dpy
->dri_screen
,
1393 dri2_dpy
->fence
->destroy_fence(dri2_dpy
->dri_screen
, fence
);
1395 dri2_surface_set_out_fence_fd(surf
, fence_fd
);
1399 * Called via eglMakeCurrent(), drv->API.MakeCurrent().
1402 dri2_make_current(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*dsurf
,
1403 _EGLSurface
*rsurf
, _EGLContext
*ctx
)
1405 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1406 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
1407 _EGLDisplay
*old_disp
= NULL
;
1408 struct dri2_egl_display
*old_dri2_dpy
= NULL
;
1409 _EGLContext
*old_ctx
;
1410 _EGLSurface
*old_dsurf
, *old_rsurf
;
1411 _EGLSurface
*tmp_dsurf
, *tmp_rsurf
;
1412 __DRIdrawable
*ddraw
, *rdraw
;
1417 return _eglError(EGL_NOT_INITIALIZED
, "eglMakeCurrent");
1419 /* make new bindings */
1420 if (!_eglBindContext(ctx
, dsurf
, rsurf
, &old_ctx
, &old_dsurf
, &old_rsurf
)) {
1421 /* _eglBindContext already sets the EGL error (in _eglCheckMakeCurrent) */
1426 old_disp
= old_ctx
->Resource
.Display
;
1427 old_dri2_dpy
= dri2_egl_display(old_disp
);
1430 /* flush before context switch */
1434 ddraw
= (dsurf
) ? dri2_dpy
->vtbl
->get_dri_drawable(dsurf
) : NULL
;
1435 rdraw
= (rsurf
) ? dri2_dpy
->vtbl
->get_dri_drawable(rsurf
) : NULL
;
1436 cctx
= (dri2_ctx
) ? dri2_ctx
->dri_context
: NULL
;
1439 __DRIcontext
*old_cctx
= dri2_egl_context(old_ctx
)->dri_context
;
1442 dri2_surf_update_fence_fd(old_ctx
, disp
, old_dsurf
);
1444 /* Disable shared buffer mode */
1445 if (old_dsurf
&& _eglSurfaceInSharedBufferMode(old_dsurf
) &&
1446 old_dri2_dpy
->vtbl
->set_shared_buffer_mode
) {
1447 old_dri2_dpy
->vtbl
->set_shared_buffer_mode(old_disp
, old_dsurf
, false);
1450 dri2_dpy
->core
->unbindContext(old_cctx
);
1453 unbind
= (cctx
== NULL
&& ddraw
== NULL
&& rdraw
== NULL
);
1455 if (!unbind
&& !dri2_dpy
->core
->bindContext(cctx
, ddraw
, rdraw
)) {
1456 /* undo the previous _eglBindContext */
1457 _eglBindContext(old_ctx
, old_dsurf
, old_rsurf
, &ctx
, &tmp_dsurf
, &tmp_rsurf
);
1458 assert(&dri2_ctx
->base
== ctx
&&
1459 tmp_dsurf
== dsurf
&&
1460 tmp_rsurf
== rsurf
);
1462 if (old_dsurf
&& _eglSurfaceInSharedBufferMode(old_dsurf
) &&
1463 old_dri2_dpy
->vtbl
->set_shared_buffer_mode
) {
1464 old_dri2_dpy
->vtbl
->set_shared_buffer_mode(old_disp
, old_dsurf
, true);
1467 _eglPutSurface(dsurf
);
1468 _eglPutSurface(rsurf
);
1469 _eglPutContext(ctx
);
1471 _eglPutSurface(old_dsurf
);
1472 _eglPutSurface(old_rsurf
);
1473 _eglPutContext(old_ctx
);
1475 /* dri2_dpy->core->bindContext failed. We cannot tell for sure why, but
1476 * setting the error to EGL_BAD_MATCH is surely better than leaving it
1479 return _eglError(EGL_BAD_MATCH
, "eglMakeCurrent");
1482 dri2_destroy_surface(drv
, disp
, old_dsurf
);
1483 dri2_destroy_surface(drv
, disp
, old_rsurf
);
1486 dri2_dpy
->ref_count
++;
1489 dri2_destroy_context(drv
, disp
, old_ctx
);
1490 dri2_display_release(old_disp
);
1493 if (dsurf
&& _eglSurfaceHasMutableRenderBuffer(dsurf
) &&
1494 dri2_dpy
->vtbl
->set_shared_buffer_mode
) {
1495 /* Always update the shared buffer mode. This is obviously needed when
1496 * the active EGL_RENDER_BUFFER is EGL_SINGLE_BUFFER. When
1497 * EGL_RENDER_BUFFER is EGL_BACK_BUFFER, the update protects us in the
1498 * case where external non-EGL API may have changed window's shared
1499 * buffer mode since we last saw it.
1501 bool mode
= (dsurf
->ActiveRenderBuffer
== EGL_SINGLE_BUFFER
);
1502 dri2_dpy
->vtbl
->set_shared_buffer_mode(disp
, dsurf
, mode
);
1509 dri2_surface_get_dri_drawable(_EGLSurface
*surf
)
1511 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
1513 return dri2_surf
->dri_drawable
;
1517 * Called from eglGetProcAddress() via drv->API.GetProcAddress().
1520 dri2_get_proc_address(_EGLDriver
*drv
, const char *procname
)
1522 return _glapi_get_proc_address(procname
);
1526 dri2_create_window_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
1527 _EGLConfig
*conf
, void *native_window
,
1528 const EGLint
*attrib_list
)
1530 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1531 return dri2_dpy
->vtbl
->create_window_surface(drv
, dpy
, conf
, native_window
,
1536 dri2_create_pixmap_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
1537 _EGLConfig
*conf
, void *native_pixmap
,
1538 const EGLint
*attrib_list
)
1540 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1541 return dri2_dpy
->vtbl
->create_pixmap_surface(drv
, dpy
, conf
, native_pixmap
,
1546 dri2_create_pbuffer_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
1547 _EGLConfig
*conf
, const EGLint
*attrib_list
)
1549 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1550 return dri2_dpy
->vtbl
->create_pbuffer_surface(drv
, dpy
, conf
, attrib_list
);
1554 dri2_swap_interval(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
1557 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1558 if (!dri2_dpy
->vtbl
->swap_interval
)
1560 return dri2_dpy
->vtbl
->swap_interval(drv
, dpy
, surf
, interval
);
1564 * Asks the client API to flush any rendering to the drawable so that we can
1565 * do our swapbuffers.
1568 dri2_flush_drawable_for_swapbuffers(_EGLDisplay
*disp
, _EGLSurface
*draw
)
1570 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1571 __DRIdrawable
*dri_drawable
= dri2_dpy
->vtbl
->get_dri_drawable(draw
);
1573 if (dri2_dpy
->flush
) {
1574 if (dri2_dpy
->flush
->base
.version
>= 4) {
1575 /* We know there's a current context because:
1577 * "If surface is not bound to the calling thread’s current
1578 * context, an EGL_BAD_SURFACE error is generated."
1580 _EGLContext
*ctx
= _eglGetCurrentContext();
1581 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
1583 /* From the EGL 1.4 spec (page 52):
1585 * "The contents of ancillary buffers are always undefined
1586 * after calling eglSwapBuffers."
1588 dri2_dpy
->flush
->flush_with_flags(dri2_ctx
->dri_context
,
1590 __DRI2_FLUSH_DRAWABLE
|
1591 __DRI2_FLUSH_INVALIDATE_ANCILLARY
,
1592 __DRI2_THROTTLE_SWAPBUFFER
);
1594 dri2_dpy
->flush
->flush(dri_drawable
);
1600 dri2_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
)
1602 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1603 _EGLContext
*ctx
= _eglGetCurrentContext();
1606 dri2_surf_update_fence_fd(ctx
, dpy
, surf
);
1607 return dri2_dpy
->vtbl
->swap_buffers(drv
, dpy
, surf
);
1611 dri2_swap_buffers_with_damage(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
1613 const EGLint
*rects
, EGLint n_rects
)
1615 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1616 _EGLContext
*ctx
= _eglGetCurrentContext();
1619 dri2_surf_update_fence_fd(ctx
, dpy
, surf
);
1620 return dri2_dpy
->vtbl
->swap_buffers_with_damage(drv
, dpy
, surf
,
1625 dri2_swap_buffers_region(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
1626 EGLint numRects
, const EGLint
*rects
)
1628 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1629 return dri2_dpy
->vtbl
->swap_buffers_region(drv
, dpy
, surf
, numRects
, rects
);
1633 dri2_set_damage_region(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
1634 EGLint
*rects
, EGLint n_rects
)
1636 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1637 return dri2_dpy
->vtbl
->set_damage_region(drv
, dpy
, surf
, rects
, n_rects
);
1641 dri2_post_sub_buffer(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
1642 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
1644 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1645 return dri2_dpy
->vtbl
->post_sub_buffer(drv
, dpy
, surf
, x
, y
, width
, height
);
1649 dri2_copy_buffers(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
1650 void *native_pixmap_target
)
1652 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1653 return dri2_dpy
->vtbl
->copy_buffers(drv
, dpy
, surf
, native_pixmap_target
);
1657 dri2_query_buffer_age(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
)
1659 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1660 return dri2_dpy
->vtbl
->query_buffer_age(drv
, dpy
, surf
);
1664 dri2_wait_client(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLContext
*ctx
)
1666 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1667 _EGLSurface
*surf
= ctx
->DrawSurface
;
1668 __DRIdrawable
*dri_drawable
= dri2_dpy
->vtbl
->get_dri_drawable(surf
);
1672 /* FIXME: If EGL allows frontbuffer rendering for window surfaces,
1673 * we need to copy fake to real here.*/
1675 if (dri2_dpy
->flush
!= NULL
)
1676 dri2_dpy
->flush
->flush(dri_drawable
);
1682 dri2_wait_native(_EGLDriver
*drv
, _EGLDisplay
*disp
, EGLint engine
)
1687 if (engine
!= EGL_CORE_NATIVE_ENGINE
)
1688 return _eglError(EGL_BAD_PARAMETER
, "eglWaitNative");
1695 dri2_bind_tex_image(_EGLDriver
*drv
,
1696 _EGLDisplay
*disp
, _EGLSurface
*surf
, EGLint buffer
)
1698 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1699 struct dri2_egl_context
*dri2_ctx
;
1701 GLint format
, target
;
1702 __DRIdrawable
*dri_drawable
= dri2_dpy
->vtbl
->get_dri_drawable(surf
);
1704 ctx
= _eglGetCurrentContext();
1705 dri2_ctx
= dri2_egl_context(ctx
);
1707 if (!_eglBindTexImage(drv
, disp
, surf
, buffer
))
1710 switch (surf
->TextureFormat
) {
1711 case EGL_TEXTURE_RGB
:
1712 format
= __DRI_TEXTURE_FORMAT_RGB
;
1714 case EGL_TEXTURE_RGBA
:
1715 format
= __DRI_TEXTURE_FORMAT_RGBA
;
1718 assert(!"Unexpected texture format in dri2_bind_tex_image()");
1719 format
= __DRI_TEXTURE_FORMAT_RGBA
;
1722 switch (surf
->TextureTarget
) {
1723 case EGL_TEXTURE_2D
:
1724 target
= GL_TEXTURE_2D
;
1727 target
= GL_TEXTURE_2D
;
1728 assert(!"Unexpected texture target in dri2_bind_tex_image()");
1731 dri2_dpy
->tex_buffer
->setTexBuffer2(dri2_ctx
->dri_context
,
1739 dri2_release_tex_image(_EGLDriver
*drv
,
1740 _EGLDisplay
*disp
, _EGLSurface
*surf
, EGLint buffer
)
1742 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1743 struct dri2_egl_context
*dri2_ctx
;
1746 __DRIdrawable
*dri_drawable
= dri2_dpy
->vtbl
->get_dri_drawable(surf
);
1748 ctx
= _eglGetCurrentContext();
1749 dri2_ctx
= dri2_egl_context(ctx
);
1751 if (!_eglReleaseTexImage(drv
, disp
, surf
, buffer
))
1754 switch (surf
->TextureTarget
) {
1755 case EGL_TEXTURE_2D
:
1756 target
= GL_TEXTURE_2D
;
1759 assert(!"missing texture target");
1762 if (dri2_dpy
->tex_buffer
->base
.version
>= 3 &&
1763 dri2_dpy
->tex_buffer
->releaseTexBuffer
!= NULL
) {
1764 dri2_dpy
->tex_buffer
->releaseTexBuffer(dri2_ctx
->dri_context
,
1765 target
, dri_drawable
);
1772 dri2_create_image(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLContext
*ctx
,
1773 EGLenum target
, EGLClientBuffer buffer
,
1774 const EGLint
*attr_list
)
1776 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1777 return dri2_dpy
->vtbl
->create_image(drv
, dpy
, ctx
, target
, buffer
,
1782 dri2_create_image_from_dri(_EGLDisplay
*disp
, __DRIimage
*dri_image
)
1784 struct dri2_egl_image
*dri2_img
;
1786 if (dri_image
== NULL
) {
1787 _eglError(EGL_BAD_ALLOC
, "dri2_create_image");
1791 dri2_img
= malloc(sizeof *dri2_img
);
1793 _eglError(EGL_BAD_ALLOC
, "dri2_create_image");
1797 _eglInitImage(&dri2_img
->base
, disp
);
1799 dri2_img
->dri_image
= dri_image
;
1801 return &dri2_img
->base
;
1805 * Translate a DRI Image extension error code into an EGL error code.
1808 egl_error_from_dri_image_error(int dri_error
)
1810 switch (dri_error
) {
1811 case __DRI_IMAGE_ERROR_SUCCESS
:
1813 case __DRI_IMAGE_ERROR_BAD_ALLOC
:
1814 return EGL_BAD_ALLOC
;
1815 case __DRI_IMAGE_ERROR_BAD_MATCH
:
1816 return EGL_BAD_MATCH
;
1817 case __DRI_IMAGE_ERROR_BAD_PARAMETER
:
1818 return EGL_BAD_PARAMETER
;
1819 case __DRI_IMAGE_ERROR_BAD_ACCESS
:
1820 return EGL_BAD_ACCESS
;
1822 assert(!"unknown dri_error code");
1823 return EGL_BAD_ALLOC
;
1828 dri2_create_image_khr_renderbuffer(_EGLDisplay
*disp
, _EGLContext
*ctx
,
1829 EGLClientBuffer buffer
,
1830 const EGLint
*attr_list
)
1832 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1833 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
1834 GLuint renderbuffer
= (GLuint
) (uintptr_t) buffer
;
1835 __DRIimage
*dri_image
;
1837 if (renderbuffer
== 0) {
1838 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
1839 return EGL_NO_IMAGE_KHR
;
1842 if (!disp
->Extensions
.KHR_gl_renderbuffer_image
) {
1843 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
1844 return EGL_NO_IMAGE_KHR
;
1847 if (dri2_dpy
->image
->base
.version
>= 17 &&
1848 dri2_dpy
->image
->createImageFromRenderbuffer2
) {
1849 unsigned error
= ~0;
1851 dri_image
= dri2_dpy
->image
->createImageFromRenderbuffer2(
1852 dri2_ctx
->dri_context
, renderbuffer
, NULL
, &error
);
1854 assert(!!dri_image
== (error
== __DRI_IMAGE_ERROR_SUCCESS
));
1857 _eglError(egl_error_from_dri_image_error(error
), "dri2_create_image_khr");
1858 return EGL_NO_IMAGE_KHR
;
1861 dri_image
= dri2_dpy
->image
->createImageFromRenderbuffer(
1862 dri2_ctx
->dri_context
, renderbuffer
, NULL
);
1864 _eglError(EGL_BAD_ALLOC
, "dri2_create_image_khr");
1865 return EGL_NO_IMAGE_KHR
;
1869 return dri2_create_image_from_dri(disp
, dri_image
);
1872 #ifdef HAVE_WAYLAND_PLATFORM
1874 /* This structure describes how a wl_buffer maps to one or more
1875 * __DRIimages. A wl_drm_buffer stores the wl_drm format code and the
1876 * offsets and strides of the planes in the buffer. This table maps a
1877 * wl_drm format code to a description of the planes in the buffer
1878 * that lets us create a __DRIimage for each of the planes. */
1880 static const struct wl_drm_components_descriptor
{
1881 uint32_t dri_components
;
1884 } wl_drm_components
[] = {
1885 { __DRI_IMAGE_COMPONENTS_RGB
, EGL_TEXTURE_RGB
, 1 },
1886 { __DRI_IMAGE_COMPONENTS_RGBA
, EGL_TEXTURE_RGBA
, 1 },
1887 { __DRI_IMAGE_COMPONENTS_Y_U_V
, EGL_TEXTURE_Y_U_V_WL
, 3 },
1888 { __DRI_IMAGE_COMPONENTS_Y_UV
, EGL_TEXTURE_Y_UV_WL
, 2 },
1889 { __DRI_IMAGE_COMPONENTS_Y_XUXV
, EGL_TEXTURE_Y_XUXV_WL
, 2 },
1893 dri2_create_image_wayland_wl_buffer(_EGLDisplay
*disp
, _EGLContext
*ctx
,
1894 EGLClientBuffer _buffer
,
1895 const EGLint
*attr_list
)
1897 struct wl_drm_buffer
*buffer
;
1898 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1899 const struct wl_drm_components_descriptor
*f
;
1900 __DRIimage
*dri_image
;
1901 _EGLImageAttribs attrs
;
1904 buffer
= wayland_drm_buffer_get(dri2_dpy
->wl_server_drm
,
1905 (struct wl_resource
*) _buffer
);
1909 if (!_eglParseImageAttribList(&attrs
, disp
, attr_list
))
1912 plane
= attrs
.PlaneWL
;
1913 f
= buffer
->driver_format
;
1914 if (plane
< 0 || plane
>= f
->nplanes
) {
1915 _eglError(EGL_BAD_PARAMETER
,
1916 "dri2_create_image_wayland_wl_buffer (plane out of bounds)");
1920 dri_image
= dri2_dpy
->image
->fromPlanar(buffer
->driver_buffer
, plane
, NULL
);
1921 if (dri_image
== NULL
&& plane
== 0)
1922 dri_image
= dri2_dpy
->image
->dupImage(buffer
->driver_buffer
, NULL
);
1923 if (dri_image
== NULL
) {
1924 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_wayland_wl_buffer");
1928 return dri2_create_image_from_dri(disp
, dri_image
);
1933 dri2_get_sync_values_chromium(_EGLDisplay
*dpy
, _EGLSurface
*surf
,
1934 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
1937 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1938 return dri2_dpy
->vtbl
->get_sync_values(dpy
, surf
, ust
, msc
, sbc
);
1942 * Set the error code after a call to
1943 * dri2_egl_image::dri_image::createImageFromTexture.
1946 dri2_create_image_khr_texture_error(int dri_error
)
1948 EGLint egl_error
= egl_error_from_dri_image_error(dri_error
);
1950 if (egl_error
!= EGL_SUCCESS
)
1951 _eglError(egl_error
, "dri2_create_image_khr_texture");
1955 dri2_create_image_khr_texture(_EGLDisplay
*disp
, _EGLContext
*ctx
,
1957 EGLClientBuffer buffer
,
1958 const EGLint
*attr_list
)
1960 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1961 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
1962 struct dri2_egl_image
*dri2_img
;
1963 GLuint texture
= (GLuint
) (uintptr_t) buffer
;
1964 _EGLImageAttribs attrs
;
1970 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
1971 return EGL_NO_IMAGE_KHR
;
1974 if (!_eglParseImageAttribList(&attrs
, disp
, attr_list
))
1975 return EGL_NO_IMAGE_KHR
;
1978 case EGL_GL_TEXTURE_2D_KHR
:
1979 if (!disp
->Extensions
.KHR_gl_texture_2D_image
) {
1980 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
1981 return EGL_NO_IMAGE_KHR
;
1984 gl_target
= GL_TEXTURE_2D
;
1986 case EGL_GL_TEXTURE_3D_KHR
:
1987 if (!disp
->Extensions
.KHR_gl_texture_3D_image
) {
1988 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
1989 return EGL_NO_IMAGE_KHR
;
1992 depth
= attrs
.GLTextureZOffset
;
1993 gl_target
= GL_TEXTURE_3D
;
1995 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR
:
1996 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR
:
1997 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR
:
1998 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR
:
1999 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR
:
2000 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR
:
2001 if (!disp
->Extensions
.KHR_gl_texture_cubemap_image
) {
2002 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
2003 return EGL_NO_IMAGE_KHR
;
2006 depth
= target
- EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR
;
2007 gl_target
= GL_TEXTURE_CUBE_MAP
;
2010 unreachable("Unexpected target in dri2_create_image_khr_texture()");
2011 return EGL_NO_IMAGE_KHR
;
2014 dri2_img
= malloc(sizeof *dri2_img
);
2016 _eglError(EGL_BAD_ALLOC
, "dri2_create_image_khr");
2017 return EGL_NO_IMAGE_KHR
;
2020 _eglInitImage(&dri2_img
->base
, disp
);
2022 dri2_img
->dri_image
=
2023 dri2_dpy
->image
->createImageFromTexture(dri2_ctx
->dri_context
,
2027 attrs
.GLTextureLevel
,
2030 dri2_create_image_khr_texture_error(error
);
2032 if (!dri2_img
->dri_image
) {
2034 return EGL_NO_IMAGE_KHR
;
2036 return &dri2_img
->base
;
2040 dri2_query_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
2041 EGLint attribute
, EGLint
*value
)
2043 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
2044 if (!dri2_dpy
->vtbl
->query_surface
)
2045 return _eglQuerySurface(drv
, dpy
, surf
, attribute
, value
);
2046 return dri2_dpy
->vtbl
->query_surface(drv
, dpy
, surf
, attribute
, value
);
2049 static struct wl_buffer
*
2050 dri2_create_wayland_buffer_from_image(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
2053 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
2054 return dri2_dpy
->vtbl
->create_wayland_buffer_from_image(drv
, dpy
, img
);
2059 dri2_create_image_mesa_drm_buffer(_EGLDisplay
*disp
, _EGLContext
*ctx
,
2060 EGLClientBuffer buffer
, const EGLint
*attr_list
)
2062 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2063 EGLint format
, name
, pitch
;
2064 _EGLImageAttribs attrs
;
2065 __DRIimage
*dri_image
;
2067 name
= (EGLint
) (uintptr_t) buffer
;
2069 if (!_eglParseImageAttribList(&attrs
, disp
, attr_list
))
2072 if (attrs
.Width
<= 0 || attrs
.Height
<= 0 ||
2073 attrs
.DRMBufferStrideMESA
<= 0) {
2074 _eglError(EGL_BAD_PARAMETER
,
2075 "bad width, height or stride");
2079 switch (attrs
.DRMBufferFormatMESA
) {
2080 case EGL_DRM_BUFFER_FORMAT_ARGB32_MESA
:
2081 format
= __DRI_IMAGE_FORMAT_ARGB8888
;
2082 pitch
= attrs
.DRMBufferStrideMESA
;
2085 _eglError(EGL_BAD_PARAMETER
,
2086 "dri2_create_image_khr: unsupported pixmap depth");
2091 dri2_dpy
->image
->createImageFromName(dri2_dpy
->dri_screen
,
2099 return dri2_create_image_from_dri(disp
, dri_image
);
2103 dri2_check_dma_buf_attribs(const _EGLImageAttribs
*attrs
)
2108 * "Required attributes and their values are as follows:
2110 * * EGL_WIDTH & EGL_HEIGHT: The logical dimensions of the buffer in pixels
2112 * * EGL_LINUX_DRM_FOURCC_EXT: The pixel format of the buffer, as specified
2113 * by drm_fourcc.h and used as the pixel_format parameter of the
2114 * drm_mode_fb_cmd2 ioctl."
2118 * "* If <target> is EGL_LINUX_DMA_BUF_EXT, and the list of attributes is
2119 * incomplete, EGL_BAD_PARAMETER is generated."
2121 if (attrs
->Width
<= 0 || attrs
->Height
<= 0 ||
2122 !attrs
->DMABufFourCC
.IsPresent
)
2123 return _eglError(EGL_BAD_PARAMETER
, "attribute(s) missing");
2128 * "If <target> is EGL_LINUX_DMA_BUF_EXT and one or more of the values
2129 * specified for a plane's pitch or offset isn't supported by EGL,
2130 * EGL_BAD_ACCESS is generated."
2132 for (unsigned i
= 0; i
< ARRAY_SIZE(attrs
->DMABufPlanePitches
); ++i
) {
2133 if (attrs
->DMABufPlanePitches
[i
].IsPresent
&&
2134 attrs
->DMABufPlanePitches
[i
].Value
<= 0)
2135 return _eglError(EGL_BAD_ACCESS
, "invalid pitch");
2139 * If <target> is EGL_LINUX_DMA_BUF_EXT, both or neither of the following
2140 * attribute values may be given.
2142 * This is referring to EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT and
2143 * EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT, and the same for other planes.
2145 for (unsigned i
= 0; i
< DMA_BUF_MAX_PLANES
; ++i
) {
2146 if (attrs
->DMABufPlaneModifiersLo
[i
].IsPresent
!=
2147 attrs
->DMABufPlaneModifiersHi
[i
].IsPresent
)
2148 return _eglError(EGL_BAD_PARAMETER
, "modifier attribute lo or hi missing");
2151 /* Although the EGL_EXT_image_dma_buf_import_modifiers spec doesn't
2152 * mandate it, we only accept the same modifier across all planes. */
2153 for (unsigned i
= 1; i
< DMA_BUF_MAX_PLANES
; ++i
) {
2154 if (attrs
->DMABufPlaneFds
[i
].IsPresent
) {
2155 if ((attrs
->DMABufPlaneModifiersLo
[0].IsPresent
!=
2156 attrs
->DMABufPlaneModifiersLo
[i
].IsPresent
) ||
2157 (attrs
->DMABufPlaneModifiersLo
[0].Value
!=
2158 attrs
->DMABufPlaneModifiersLo
[i
].Value
) ||
2159 (attrs
->DMABufPlaneModifiersHi
[0].Value
!=
2160 attrs
->DMABufPlaneModifiersHi
[i
].Value
))
2161 return _eglError(EGL_BAD_PARAMETER
, "modifier attributes not equal");
2168 /* Returns the total number of planes for the format or zero if it isn't a
2169 * valid fourcc format.
2172 dri2_num_fourcc_format_planes(EGLint format
)
2176 case DRM_FORMAT_RG88
:
2177 case DRM_FORMAT_GR88
:
2178 case DRM_FORMAT_R16
:
2179 case DRM_FORMAT_GR1616
:
2180 case DRM_FORMAT_RGB332
:
2181 case DRM_FORMAT_BGR233
:
2182 case DRM_FORMAT_XRGB4444
:
2183 case DRM_FORMAT_XBGR4444
:
2184 case DRM_FORMAT_RGBX4444
:
2185 case DRM_FORMAT_BGRX4444
:
2186 case DRM_FORMAT_ARGB4444
:
2187 case DRM_FORMAT_ABGR4444
:
2188 case DRM_FORMAT_RGBA4444
:
2189 case DRM_FORMAT_BGRA4444
:
2190 case DRM_FORMAT_XRGB1555
:
2191 case DRM_FORMAT_XBGR1555
:
2192 case DRM_FORMAT_RGBX5551
:
2193 case DRM_FORMAT_BGRX5551
:
2194 case DRM_FORMAT_ARGB1555
:
2195 case DRM_FORMAT_ABGR1555
:
2196 case DRM_FORMAT_RGBA5551
:
2197 case DRM_FORMAT_BGRA5551
:
2198 case DRM_FORMAT_RGB565
:
2199 case DRM_FORMAT_BGR565
:
2200 case DRM_FORMAT_RGB888
:
2201 case DRM_FORMAT_BGR888
:
2202 case DRM_FORMAT_XRGB8888
:
2203 case DRM_FORMAT_XBGR8888
:
2204 case DRM_FORMAT_RGBX8888
:
2205 case DRM_FORMAT_BGRX8888
:
2206 case DRM_FORMAT_ARGB8888
:
2207 case DRM_FORMAT_ABGR8888
:
2208 case DRM_FORMAT_RGBA8888
:
2209 case DRM_FORMAT_BGRA8888
:
2210 case DRM_FORMAT_XRGB2101010
:
2211 case DRM_FORMAT_XBGR2101010
:
2212 case DRM_FORMAT_RGBX1010102
:
2213 case DRM_FORMAT_BGRX1010102
:
2214 case DRM_FORMAT_ARGB2101010
:
2215 case DRM_FORMAT_ABGR2101010
:
2216 case DRM_FORMAT_RGBA1010102
:
2217 case DRM_FORMAT_BGRA1010102
:
2218 case DRM_FORMAT_YUYV
:
2219 case DRM_FORMAT_YVYU
:
2220 case DRM_FORMAT_UYVY
:
2221 case DRM_FORMAT_VYUY
:
2222 case DRM_FORMAT_AYUV
:
2225 case DRM_FORMAT_NV12
:
2226 case DRM_FORMAT_NV21
:
2227 case DRM_FORMAT_NV16
:
2228 case DRM_FORMAT_NV61
:
2231 case DRM_FORMAT_YUV410
:
2232 case DRM_FORMAT_YVU410
:
2233 case DRM_FORMAT_YUV411
:
2234 case DRM_FORMAT_YVU411
:
2235 case DRM_FORMAT_YUV420
:
2236 case DRM_FORMAT_YVU420
:
2237 case DRM_FORMAT_YUV422
:
2238 case DRM_FORMAT_YVU422
:
2239 case DRM_FORMAT_YUV444
:
2240 case DRM_FORMAT_YVU444
:
2248 /* Returns the total number of file descriptors. Zero indicates an error. */
2250 dri2_check_dma_buf_format(const _EGLImageAttribs
*attrs
)
2252 unsigned plane_n
= dri2_num_fourcc_format_planes(attrs
->DMABufFourCC
.Value
);
2254 _eglError(EGL_BAD_MATCH
, "unknown drm fourcc format");
2258 for (unsigned i
= plane_n
; i
< DMA_BUF_MAX_PLANES
; i
++) {
2260 * The modifiers extension spec says:
2262 * "Modifiers may modify any attribute of a buffer import, including
2263 * but not limited to adding extra planes to a format which
2264 * otherwise does not have those planes. As an example, a modifier
2265 * may add a plane for an external compression buffer to a
2266 * single-plane format. The exact meaning and effect of any
2267 * modifier is canonically defined by drm_fourcc.h, not as part of
2270 if (attrs
->DMABufPlaneModifiersLo
[i
].IsPresent
&&
2271 attrs
->DMABufPlaneModifiersHi
[i
].IsPresent
) {
2279 * "* If <target> is EGL_LINUX_DMA_BUF_EXT, and the list of attributes is
2280 * incomplete, EGL_BAD_PARAMETER is generated."
2282 for (unsigned i
= 0; i
< plane_n
; ++i
) {
2283 if (!attrs
->DMABufPlaneFds
[i
].IsPresent
||
2284 !attrs
->DMABufPlaneOffsets
[i
].IsPresent
||
2285 !attrs
->DMABufPlanePitches
[i
].IsPresent
) {
2286 _eglError(EGL_BAD_PARAMETER
, "plane attribute(s) missing");
2292 * The spec also says:
2294 * "If <target> is EGL_LINUX_DMA_BUF_EXT, and the EGL_LINUX_DRM_FOURCC_EXT
2295 * attribute indicates a single-plane format, EGL_BAD_ATTRIBUTE is
2296 * generated if any of the EGL_DMA_BUF_PLANE1_* or EGL_DMA_BUF_PLANE2_*
2297 * or EGL_DMA_BUF_PLANE3_* attributes are specified."
2299 for (unsigned i
= plane_n
; i
< DMA_BUF_MAX_PLANES
; ++i
) {
2300 if (attrs
->DMABufPlaneFds
[i
].IsPresent
||
2301 attrs
->DMABufPlaneOffsets
[i
].IsPresent
||
2302 attrs
->DMABufPlanePitches
[i
].IsPresent
) {
2303 _eglError(EGL_BAD_ATTRIBUTE
, "too many plane attributes");
2312 dri2_query_dma_buf_formats(_EGLDriver
*drv
, _EGLDisplay
*disp
,
2313 EGLint max
, EGLint
*formats
, EGLint
*count
)
2315 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2316 if (max
< 0 || (max
> 0 && formats
== NULL
))
2317 return _eglError(EGL_BAD_PARAMETER
, "invalid value for max count of formats");
2319 if (dri2_dpy
->image
->base
.version
< 15 ||
2320 dri2_dpy
->image
->queryDmaBufFormats
== NULL
)
2323 if (!dri2_dpy
->image
->queryDmaBufFormats(dri2_dpy
->dri_screen
, max
,
2328 /* Assert that all of the formats returned are actually fourcc formats.
2329 * Some day, if we want the internal interface function to be able to
2330 * return the fake fourcc formats defined in dri_interface.h, we'll have
2331 * to do something more clever here to pair the list down to just real
2332 * fourcc formats so that we don't leak the fake internal ones.
2334 for (int i
= 0; i
< *count
; i
++) {
2335 assert(dri2_num_fourcc_format_planes(formats
[i
]) > 0);
2343 dri2_query_dma_buf_modifiers(_EGLDriver
*drv
, _EGLDisplay
*disp
, EGLint format
,
2344 EGLint max
, EGLuint64KHR
*modifiers
,
2345 EGLBoolean
*external_only
, EGLint
*count
)
2347 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2349 if (dri2_num_fourcc_format_planes(format
) == 0)
2350 return _eglError(EGL_BAD_PARAMETER
, "invalid fourcc format");
2353 return _eglError(EGL_BAD_PARAMETER
, "invalid value for max count of formats");
2355 if (max
> 0 && modifiers
== NULL
)
2356 return _eglError(EGL_BAD_PARAMETER
, "invalid modifiers array");
2358 if (dri2_dpy
->image
->base
.version
< 15 ||
2359 dri2_dpy
->image
->queryDmaBufModifiers
== NULL
)
2362 if (dri2_dpy
->image
->queryDmaBufModifiers(dri2_dpy
->dri_screen
, format
,
2364 (unsigned int *) external_only
,
2366 return _eglError(EGL_BAD_PARAMETER
, "invalid format");
2374 * "If eglCreateImageKHR is successful for a EGL_LINUX_DMA_BUF_EXT target, the
2375 * EGL will take a reference to the dma_buf(s) which it will release at any
2376 * time while the EGLDisplay is initialized. It is the responsibility of the
2377 * application to close the dma_buf file descriptors."
2379 * Therefore we must never close or otherwise modify the file descriptors.
2382 dri2_create_image_dma_buf(_EGLDisplay
*disp
, _EGLContext
*ctx
,
2383 EGLClientBuffer buffer
, const EGLint
*attr_list
)
2385 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2387 _EGLImageAttribs attrs
;
2388 __DRIimage
*dri_image
;
2390 int fds
[DMA_BUF_MAX_PLANES
];
2391 int pitches
[DMA_BUF_MAX_PLANES
];
2392 int offsets
[DMA_BUF_MAX_PLANES
];
2394 bool has_modifier
= false;
2400 * ""* If <target> is EGL_LINUX_DMA_BUF_EXT and <buffer> is not NULL, the
2401 * error EGL_BAD_PARAMETER is generated."
2403 if (buffer
!= NULL
) {
2404 _eglError(EGL_BAD_PARAMETER
, "buffer not NULL");
2408 if (!_eglParseImageAttribList(&attrs
, disp
, attr_list
))
2411 if (!dri2_check_dma_buf_attribs(&attrs
))
2414 num_fds
= dri2_check_dma_buf_format(&attrs
);
2418 for (unsigned i
= 0; i
< num_fds
; ++i
) {
2419 fds
[i
] = attrs
.DMABufPlaneFds
[i
].Value
;
2420 pitches
[i
] = attrs
.DMABufPlanePitches
[i
].Value
;
2421 offsets
[i
] = attrs
.DMABufPlaneOffsets
[i
].Value
;
2424 /* dri2_check_dma_buf_attribs ensures that the modifier, if available,
2425 * will be present in attrs.DMABufPlaneModifiersLo[0] and
2426 * attrs.DMABufPlaneModifiersHi[0] */
2427 if (attrs
.DMABufPlaneModifiersLo
[0].IsPresent
) {
2428 modifier
= combine_u32_into_u64(attrs
.DMABufPlaneModifiersHi
[0].Value
,
2429 attrs
.DMABufPlaneModifiersLo
[0].Value
);
2430 has_modifier
= true;
2434 if (dri2_dpy
->image
->base
.version
< 15 ||
2435 dri2_dpy
->image
->createImageFromDmaBufs2
== NULL
) {
2436 _eglError(EGL_BAD_MATCH
, "unsupported dma_buf format modifier");
2437 return EGL_NO_IMAGE_KHR
;
2440 dri2_dpy
->image
->createImageFromDmaBufs2(dri2_dpy
->dri_screen
,
2441 attrs
.Width
, attrs
.Height
, attrs
.DMABufFourCC
.Value
,
2442 modifier
, fds
, num_fds
, pitches
, offsets
,
2443 attrs
.DMABufYuvColorSpaceHint
.Value
,
2444 attrs
.DMABufSampleRangeHint
.Value
,
2445 attrs
.DMABufChromaHorizontalSiting
.Value
,
2446 attrs
.DMABufChromaVerticalSiting
.Value
,
2452 dri2_dpy
->image
->createImageFromDmaBufs(dri2_dpy
->dri_screen
,
2453 attrs
.Width
, attrs
.Height
, attrs
.DMABufFourCC
.Value
,
2454 fds
, num_fds
, pitches
, offsets
,
2455 attrs
.DMABufYuvColorSpaceHint
.Value
,
2456 attrs
.DMABufSampleRangeHint
.Value
,
2457 attrs
.DMABufChromaHorizontalSiting
.Value
,
2458 attrs
.DMABufChromaVerticalSiting
.Value
,
2462 dri2_create_image_khr_texture_error(error
);
2465 return EGL_NO_IMAGE_KHR
;
2467 res
= dri2_create_image_from_dri(disp
, dri_image
);
2472 dri2_create_drm_image_mesa(_EGLDriver
*drv
, _EGLDisplay
*disp
,
2473 const EGLint
*attr_list
)
2475 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2476 struct dri2_egl_image
*dri2_img
;
2477 _EGLImageAttribs attrs
;
2478 unsigned int dri_use
, valid_mask
;
2484 _eglError(EGL_BAD_PARAMETER
, __func__
);
2485 return EGL_NO_IMAGE_KHR
;
2488 if (!_eglParseImageAttribList(&attrs
, disp
, attr_list
))
2489 return EGL_NO_IMAGE_KHR
;
2491 if (attrs
.Width
<= 0 || attrs
.Height
<= 0) {
2492 _eglError(EGL_BAD_PARAMETER
, __func__
);
2493 return EGL_NO_IMAGE_KHR
;
2496 switch (attrs
.DRMBufferFormatMESA
) {
2497 case EGL_DRM_BUFFER_FORMAT_ARGB32_MESA
:
2498 format
= __DRI_IMAGE_FORMAT_ARGB8888
;
2501 _eglError(EGL_BAD_PARAMETER
, __func__
);
2502 return EGL_NO_IMAGE_KHR
;
2506 EGL_DRM_BUFFER_USE_SCANOUT_MESA
|
2507 EGL_DRM_BUFFER_USE_SHARE_MESA
|
2508 EGL_DRM_BUFFER_USE_CURSOR_MESA
;
2509 if (attrs
.DRMBufferUseMESA
& ~valid_mask
) {
2510 _eglError(EGL_BAD_PARAMETER
, __func__
);
2511 return EGL_NO_IMAGE_KHR
;
2515 if (attrs
.DRMBufferUseMESA
& EGL_DRM_BUFFER_USE_SHARE_MESA
)
2516 dri_use
|= __DRI_IMAGE_USE_SHARE
;
2517 if (attrs
.DRMBufferUseMESA
& EGL_DRM_BUFFER_USE_SCANOUT_MESA
)
2518 dri_use
|= __DRI_IMAGE_USE_SCANOUT
;
2519 if (attrs
.DRMBufferUseMESA
& EGL_DRM_BUFFER_USE_CURSOR_MESA
)
2520 dri_use
|= __DRI_IMAGE_USE_CURSOR
;
2522 dri2_img
= malloc(sizeof *dri2_img
);
2524 _eglError(EGL_BAD_ALLOC
, "dri2_create_image_khr");
2525 return EGL_NO_IMAGE_KHR
;
2528 _eglInitImage(&dri2_img
->base
, disp
);
2530 dri2_img
->dri_image
=
2531 dri2_dpy
->image
->createImage(dri2_dpy
->dri_screen
,
2532 attrs
.Width
, attrs
.Height
,
2533 format
, dri_use
, dri2_img
);
2534 if (dri2_img
->dri_image
== NULL
) {
2536 _eglError(EGL_BAD_ALLOC
, "dri2_create_drm_image_mesa");
2537 return EGL_NO_IMAGE_KHR
;
2540 return &dri2_img
->base
;
2544 dri2_export_drm_image_mesa(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLImage
*img
,
2545 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
2547 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2548 struct dri2_egl_image
*dri2_img
= dri2_egl_image(img
);
2552 if (name
&& !dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2553 __DRI_IMAGE_ATTRIB_NAME
, name
))
2554 return _eglError(EGL_BAD_ALLOC
, "dri2_export_drm_image_mesa");
2557 dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2558 __DRI_IMAGE_ATTRIB_HANDLE
, handle
);
2561 dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2562 __DRI_IMAGE_ATTRIB_STRIDE
, stride
);
2568 * Checks if we can support EGL_MESA_image_dma_buf_export on this image.
2570 * The spec provides a boolean return for the driver to reject exporting for
2571 * basically any reason, but doesn't specify any particular error cases. For
2572 * now, we just fail if we don't have a DRM fourcc for the format.
2575 dri2_can_export_dma_buf_image(_EGLDisplay
*disp
, _EGLImage
*img
)
2577 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2578 struct dri2_egl_image
*dri2_img
= dri2_egl_image(img
);
2581 if (!dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2582 __DRI_IMAGE_ATTRIB_FOURCC
, &fourcc
)) {
2590 dri2_export_dma_buf_image_query_mesa(_EGLDriver
*drv
, _EGLDisplay
*disp
,
2592 EGLint
*fourcc
, EGLint
*nplanes
,
2593 EGLuint64KHR
*modifiers
)
2595 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2596 struct dri2_egl_image
*dri2_img
= dri2_egl_image(img
);
2600 if (!dri2_can_export_dma_buf_image(disp
, img
))
2604 dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2605 __DRI_IMAGE_ATTRIB_NUM_PLANES
, nplanes
);
2607 dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2608 __DRI_IMAGE_ATTRIB_FOURCC
, fourcc
);
2617 dri2_export_dma_buf_image_mesa(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLImage
*img
,
2618 int *fds
, EGLint
*strides
, EGLint
*offsets
)
2620 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2621 struct dri2_egl_image
*dri2_img
= dri2_egl_image(img
);
2625 if (!dri2_can_export_dma_buf_image(disp
, img
))
2628 /* rework later to provide multiple fds/strides/offsets */
2630 dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2631 __DRI_IMAGE_ATTRIB_FD
, fds
);
2634 dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2635 __DRI_IMAGE_ATTRIB_STRIDE
, strides
);
2639 bool ret
= dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2640 __DRI_IMAGE_ATTRIB_OFFSET
, &img_offset
);
2642 offsets
[0] = img_offset
;
2653 dri2_create_image_khr(_EGLDriver
*drv
, _EGLDisplay
*disp
,
2654 _EGLContext
*ctx
, EGLenum target
,
2655 EGLClientBuffer buffer
, const EGLint
*attr_list
)
2660 case EGL_GL_TEXTURE_2D_KHR
:
2661 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR
:
2662 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR
:
2663 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR
:
2664 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR
:
2665 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR
:
2666 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR
:
2667 case EGL_GL_TEXTURE_3D_KHR
:
2668 return dri2_create_image_khr_texture(disp
, ctx
, target
, buffer
, attr_list
);
2669 case EGL_GL_RENDERBUFFER_KHR
:
2670 return dri2_create_image_khr_renderbuffer(disp
, ctx
, buffer
, attr_list
);
2672 case EGL_DRM_BUFFER_MESA
:
2673 return dri2_create_image_mesa_drm_buffer(disp
, ctx
, buffer
, attr_list
);
2674 case EGL_LINUX_DMA_BUF_EXT
:
2675 return dri2_create_image_dma_buf(disp
, ctx
, buffer
, attr_list
);
2677 #ifdef HAVE_WAYLAND_PLATFORM
2678 case EGL_WAYLAND_BUFFER_WL
:
2679 return dri2_create_image_wayland_wl_buffer(disp
, ctx
, buffer
, attr_list
);
2682 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
2683 return EGL_NO_IMAGE_KHR
;
2688 dri2_destroy_image_khr(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLImage
*image
)
2690 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2691 struct dri2_egl_image
*dri2_img
= dri2_egl_image(image
);
2695 dri2_dpy
->image
->destroyImage(dri2_img
->dri_image
);
2701 #ifdef HAVE_WAYLAND_PLATFORM
2704 dri2_wl_reference_buffer(void *user_data
, uint32_t name
, int fd
,
2705 struct wl_drm_buffer
*buffer
)
2707 _EGLDisplay
*disp
= user_data
;
2708 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2710 int dri_components
= 0;
2713 img
= dri2_dpy
->image
->createImageFromNames(dri2_dpy
->dri_screen
,
2722 img
= dri2_dpy
->image
->createImageFromFds(dri2_dpy
->dri_screen
,
2734 dri2_dpy
->image
->queryImage(img
, __DRI_IMAGE_ATTRIB_COMPONENTS
, &dri_components
);
2736 buffer
->driver_format
= NULL
;
2737 for (int i
= 0; i
< ARRAY_SIZE(wl_drm_components
); i
++)
2738 if (wl_drm_components
[i
].dri_components
== dri_components
)
2739 buffer
->driver_format
= &wl_drm_components
[i
];
2741 if (buffer
->driver_format
== NULL
)
2742 dri2_dpy
->image
->destroyImage(img
);
2744 buffer
->driver_buffer
= img
;
2748 dri2_wl_release_buffer(void *user_data
, struct wl_drm_buffer
*buffer
)
2750 _EGLDisplay
*disp
= user_data
;
2751 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2753 dri2_dpy
->image
->destroyImage(buffer
->driver_buffer
);
2757 dri2_bind_wayland_display_wl(_EGLDriver
*drv
, _EGLDisplay
*disp
,
2758 struct wl_display
*wl_dpy
)
2760 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2761 const struct wayland_drm_callbacks wl_drm_callbacks
= {
2762 .authenticate
= (int(*)(void *, uint32_t)) dri2_dpy
->vtbl
->authenticate
,
2763 .reference_buffer
= dri2_wl_reference_buffer
,
2764 .release_buffer
= dri2_wl_release_buffer
2771 if (dri2_dpy
->wl_server_drm
)
2774 if (drmGetCap(dri2_dpy
->fd
, DRM_CAP_PRIME
, &cap
) == 0 &&
2775 cap
== (DRM_PRIME_CAP_IMPORT
| DRM_PRIME_CAP_EXPORT
) &&
2776 dri2_dpy
->image
->base
.version
>= 7 &&
2777 dri2_dpy
->image
->createImageFromFds
!= NULL
)
2778 flags
|= WAYLAND_DRM_PRIME
;
2780 dri2_dpy
->wl_server_drm
=
2781 wayland_drm_init(wl_dpy
, dri2_dpy
->device_name
,
2782 &wl_drm_callbacks
, disp
, flags
);
2784 if (!dri2_dpy
->wl_server_drm
)
2787 #ifdef HAVE_DRM_PLATFORM
2788 /* We have to share the wl_drm instance with gbm, so gbm can convert
2789 * wl_buffers to gbm bos. */
2790 if (dri2_dpy
->gbm_dri
)
2791 dri2_dpy
->gbm_dri
->wl_drm
= dri2_dpy
->wl_server_drm
;
2798 dri2_unbind_wayland_display_wl(_EGLDriver
*drv
, _EGLDisplay
*disp
,
2799 struct wl_display
*wl_dpy
)
2801 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2805 if (!dri2_dpy
->wl_server_drm
)
2808 wayland_drm_uninit(dri2_dpy
->wl_server_drm
);
2809 dri2_dpy
->wl_server_drm
= NULL
;
2815 dri2_query_wayland_buffer_wl(_EGLDriver
*drv
, _EGLDisplay
*disp
,
2816 struct wl_resource
*buffer_resource
,
2817 EGLint attribute
, EGLint
*value
)
2819 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2820 struct wl_drm_buffer
*buffer
;
2821 const struct wl_drm_components_descriptor
*format
;
2823 buffer
= wayland_drm_buffer_get(dri2_dpy
->wl_server_drm
, buffer_resource
);
2827 format
= buffer
->driver_format
;
2828 switch (attribute
) {
2829 case EGL_TEXTURE_FORMAT
:
2830 *value
= format
->components
;
2833 *value
= buffer
->width
;
2836 *value
= buffer
->height
;
2845 dri2_egl_ref_sync(struct dri2_egl_sync
*sync
)
2847 p_atomic_inc(&sync
->refcount
);
2851 dri2_egl_unref_sync(struct dri2_egl_display
*dri2_dpy
,
2852 struct dri2_egl_sync
*dri2_sync
)
2854 if (p_atomic_dec_zero(&dri2_sync
->refcount
)) {
2855 switch (dri2_sync
->base
.Type
) {
2856 case EGL_SYNC_REUSABLE_KHR
:
2857 cnd_destroy(&dri2_sync
->cond
);
2859 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
2860 if (dri2_sync
->base
.SyncFd
!= EGL_NO_NATIVE_FENCE_FD_ANDROID
)
2861 close(dri2_sync
->base
.SyncFd
);
2867 if (dri2_sync
->fence
)
2868 dri2_dpy
->fence
->destroy_fence(dri2_dpy
->dri_screen
, dri2_sync
->fence
);
2875 dri2_create_sync(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
2876 EGLenum type
, const EGLAttrib
*attrib_list
)
2878 _EGLContext
*ctx
= _eglGetCurrentContext();
2879 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
2880 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
2881 struct dri2_egl_sync
*dri2_sync
;
2883 pthread_condattr_t attr
;
2885 dri2_sync
= calloc(1, sizeof(struct dri2_egl_sync
));
2887 _eglError(EGL_BAD_ALLOC
, "eglCreateSyncKHR");
2891 if (!_eglInitSync(&dri2_sync
->base
, dpy
, type
, attrib_list
)) {
2897 case EGL_SYNC_FENCE_KHR
:
2898 dri2_sync
->fence
= dri2_dpy
->fence
->create_fence(dri2_ctx
->dri_context
);
2899 if (!dri2_sync
->fence
) {
2900 /* Why did it fail? DRI doesn't return an error code, so we emit
2901 * a generic EGL error that doesn't communicate user error.
2903 _eglError(EGL_BAD_ALLOC
, "eglCreateSyncKHR");
2909 case EGL_SYNC_CL_EVENT_KHR
:
2910 dri2_sync
->fence
= dri2_dpy
->fence
->get_fence_from_cl_event(
2911 dri2_dpy
->dri_screen
,
2912 dri2_sync
->base
.CLEvent
);
2913 /* this can only happen if the cl_event passed in is invalid. */
2914 if (!dri2_sync
->fence
) {
2915 _eglError(EGL_BAD_ATTRIBUTE
, "eglCreateSyncKHR");
2920 /* the initial status must be "signaled" if the cl_event is signaled */
2921 if (dri2_dpy
->fence
->client_wait_sync(dri2_ctx
->dri_context
,
2922 dri2_sync
->fence
, 0, 0))
2923 dri2_sync
->base
.SyncStatus
= EGL_SIGNALED_KHR
;
2926 case EGL_SYNC_REUSABLE_KHR
:
2927 /* intialize attr */
2928 ret
= pthread_condattr_init(&attr
);
2931 _eglError(EGL_BAD_ACCESS
, "eglCreateSyncKHR");
2936 /* change clock attribute to CLOCK_MONOTONIC */
2937 ret
= pthread_condattr_setclock(&attr
, CLOCK_MONOTONIC
);
2940 _eglError(EGL_BAD_ACCESS
, "eglCreateSyncKHR");
2945 ret
= pthread_cond_init(&dri2_sync
->cond
, &attr
);
2948 _eglError(EGL_BAD_ACCESS
, "eglCreateSyncKHR");
2953 /* initial status of reusable sync must be "unsignaled" */
2954 dri2_sync
->base
.SyncStatus
= EGL_UNSIGNALED_KHR
;
2957 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
2958 if (dri2_dpy
->fence
->create_fence_fd
) {
2959 dri2_sync
->fence
= dri2_dpy
->fence
->create_fence_fd(
2960 dri2_ctx
->dri_context
,
2961 dri2_sync
->base
.SyncFd
);
2963 if (!dri2_sync
->fence
) {
2964 _eglError(EGL_BAD_ATTRIBUTE
, "eglCreateSyncKHR");
2971 p_atomic_set(&dri2_sync
->refcount
, 1);
2972 return &dri2_sync
->base
;
2976 dri2_destroy_sync(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSync
*sync
)
2978 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
2979 struct dri2_egl_sync
*dri2_sync
= dri2_egl_sync(sync
);
2980 EGLint ret
= EGL_TRUE
;
2983 /* if type of sync is EGL_SYNC_REUSABLE_KHR and it is not signaled yet,
2984 * then unlock all threads possibly blocked by the reusable sync before
2987 if (dri2_sync
->base
.Type
== EGL_SYNC_REUSABLE_KHR
&&
2988 dri2_sync
->base
.SyncStatus
== EGL_UNSIGNALED_KHR
) {
2989 dri2_sync
->base
.SyncStatus
= EGL_SIGNALED_KHR
;
2990 /* unblock all threads currently blocked by sync */
2991 err
= cnd_broadcast(&dri2_sync
->cond
);
2994 _eglError(EGL_BAD_ACCESS
, "eglDestroySyncKHR");
2999 dri2_egl_unref_sync(dri2_dpy
, dri2_sync
);
3005 dri2_dup_native_fence_fd(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSync
*sync
)
3007 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
3008 struct dri2_egl_sync
*dri2_sync
= dri2_egl_sync(sync
);
3010 assert(sync
->Type
== EGL_SYNC_NATIVE_FENCE_ANDROID
);
3012 if (sync
->SyncFd
== EGL_NO_NATIVE_FENCE_FD_ANDROID
) {
3013 /* try to retrieve the actual native fence fd.. if rendering is
3014 * not flushed this will just return -1, aka NO_NATIVE_FENCE_FD:
3016 sync
->SyncFd
= dri2_dpy
->fence
->get_fence_fd(dri2_dpy
->dri_screen
,
3020 if (sync
->SyncFd
== EGL_NO_NATIVE_FENCE_FD_ANDROID
) {
3021 /* if native fence fd still not created, return an error: */
3022 _eglError(EGL_BAD_PARAMETER
, "eglDupNativeFenceFDANDROID");
3023 return EGL_NO_NATIVE_FENCE_FD_ANDROID
;
3026 return dup(sync
->SyncFd
);
3030 dri2_set_blob_cache_funcs(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
3031 EGLSetBlobFuncANDROID set
,
3032 EGLGetBlobFuncANDROID get
)
3034 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
3035 dri2_dpy
->blob
->set_cache_funcs(dri2_dpy
->dri_screen
,
3041 dri2_client_wait_sync(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSync
*sync
,
3042 EGLint flags
, EGLTime timeout
)
3044 _EGLContext
*ctx
= _eglGetCurrentContext();
3045 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
3046 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
3047 struct dri2_egl_sync
*dri2_sync
= dri2_egl_sync(sync
);
3048 unsigned wait_flags
= 0;
3050 EGLint ret
= EGL_CONDITION_SATISFIED_KHR
;
3052 /* The EGL_KHR_fence_sync spec states:
3054 * "If no context is current for the bound API,
3055 * the EGL_SYNC_FLUSH_COMMANDS_BIT_KHR bit is ignored.
3057 if (dri2_ctx
&& flags
& EGL_SYNC_FLUSH_COMMANDS_BIT_KHR
)
3058 wait_flags
|= __DRI2_FENCE_FLAG_FLUSH_COMMANDS
;
3060 /* the sync object should take a reference while waiting */
3061 dri2_egl_ref_sync(dri2_sync
);
3063 switch (sync
->Type
) {
3064 case EGL_SYNC_FENCE_KHR
:
3065 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
3066 case EGL_SYNC_CL_EVENT_KHR
:
3067 if (dri2_dpy
->fence
->client_wait_sync(dri2_ctx
? dri2_ctx
->dri_context
: NULL
,
3068 dri2_sync
->fence
, wait_flags
,
3070 dri2_sync
->base
.SyncStatus
= EGL_SIGNALED_KHR
;
3072 ret
= EGL_TIMEOUT_EXPIRED_KHR
;
3075 case EGL_SYNC_REUSABLE_KHR
:
3076 if (dri2_ctx
&& dri2_sync
->base
.SyncStatus
== EGL_UNSIGNALED_KHR
&&
3077 (flags
& EGL_SYNC_FLUSH_COMMANDS_BIT_KHR
)) {
3078 /* flush context if EGL_SYNC_FLUSH_COMMANDS_BIT_KHR is set */
3082 /* if timeout is EGL_FOREVER_KHR, it should wait without any timeout.*/
3083 if (timeout
== EGL_FOREVER_KHR
) {
3084 mtx_lock(&dri2_sync
->mutex
);
3085 cnd_wait(&dri2_sync
->cond
, &dri2_sync
->mutex
);
3086 mtx_unlock(&dri2_sync
->mutex
);
3088 /* if reusable sync has not been yet signaled */
3089 if (dri2_sync
->base
.SyncStatus
!= EGL_SIGNALED_KHR
) {
3090 /* timespecs for cnd_timedwait */
3091 struct timespec current
;
3092 struct timespec expire
;
3094 /* We override the clock to monotonic when creating the condition
3096 clock_gettime(CLOCK_MONOTONIC
, ¤t
);
3098 /* calculating when to expire */
3099 expire
.tv_nsec
= timeout
% 1000000000L;
3100 expire
.tv_sec
= timeout
/ 1000000000L;
3102 expire
.tv_nsec
+= current
.tv_nsec
;
3103 expire
.tv_sec
+= current
.tv_sec
;
3105 /* expire.nsec now is a number between 0 and 1999999998 */
3106 if (expire
.tv_nsec
> 999999999L) {
3108 expire
.tv_nsec
-= 1000000000L;
3111 mtx_lock(&dri2_sync
->mutex
);
3112 ret
= cnd_timedwait(&dri2_sync
->cond
, &dri2_sync
->mutex
, &expire
);
3113 mtx_unlock(&dri2_sync
->mutex
);
3115 if (ret
== thrd_busy
) {
3116 if (dri2_sync
->base
.SyncStatus
== EGL_UNSIGNALED_KHR
) {
3117 ret
= EGL_TIMEOUT_EXPIRED_KHR
;
3119 _eglError(EGL_BAD_ACCESS
, "eglClientWaitSyncKHR");
3127 dri2_egl_unref_sync(dri2_dpy
, dri2_sync
);
3133 dri2_signal_sync(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSync
*sync
,
3136 struct dri2_egl_sync
*dri2_sync
= dri2_egl_sync(sync
);
3139 if (sync
->Type
!= EGL_SYNC_REUSABLE_KHR
)
3140 return _eglError(EGL_BAD_MATCH
, "eglSignalSyncKHR");
3142 if (mode
!= EGL_SIGNALED_KHR
&& mode
!= EGL_UNSIGNALED_KHR
)
3143 return _eglError(EGL_BAD_ATTRIBUTE
, "eglSignalSyncKHR");
3145 dri2_sync
->base
.SyncStatus
= mode
;
3147 if (mode
== EGL_SIGNALED_KHR
) {
3148 ret
= cnd_broadcast(&dri2_sync
->cond
);
3150 /* fail to broadcast */
3152 return _eglError(EGL_BAD_ACCESS
, "eglSignalSyncKHR");
3159 dri2_server_wait_sync(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSync
*sync
)
3161 _EGLContext
*ctx
= _eglGetCurrentContext();
3162 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
3163 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
3164 struct dri2_egl_sync
*dri2_sync
= dri2_egl_sync(sync
);
3166 dri2_dpy
->fence
->server_wait_sync(dri2_ctx
->dri_context
,
3167 dri2_sync
->fence
, 0);
3172 dri2_interop_query_device_info(_EGLDisplay
*dpy
, _EGLContext
*ctx
,
3173 struct mesa_glinterop_device_info
*out
)
3175 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
3176 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
3178 if (!dri2_dpy
->interop
)
3179 return MESA_GLINTEROP_UNSUPPORTED
;
3181 return dri2_dpy
->interop
->query_device_info(dri2_ctx
->dri_context
, out
);
3185 dri2_interop_export_object(_EGLDisplay
*dpy
, _EGLContext
*ctx
,
3186 struct mesa_glinterop_export_in
*in
,
3187 struct mesa_glinterop_export_out
*out
)
3189 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
3190 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
3192 if (!dri2_dpy
->interop
)
3193 return MESA_GLINTEROP_UNSUPPORTED
;
3195 return dri2_dpy
->interop
->export_object(dri2_ctx
->dri_context
, in
, out
);
3199 * This is the main entrypoint into the driver, called by libEGL.
3200 * Gets an _EGLDriver object and init its dispatch table.
3203 _eglInitDriver(_EGLDriver
*dri2_drv
)
3205 dri2_drv
->API
.Initialize
= dri2_initialize
;
3206 dri2_drv
->API
.Terminate
= dri2_terminate
;
3207 dri2_drv
->API
.CreateContext
= dri2_create_context
;
3208 dri2_drv
->API
.DestroyContext
= dri2_destroy_context
;
3209 dri2_drv
->API
.MakeCurrent
= dri2_make_current
;
3210 dri2_drv
->API
.CreateWindowSurface
= dri2_create_window_surface
;
3211 dri2_drv
->API
.CreatePixmapSurface
= dri2_create_pixmap_surface
;
3212 dri2_drv
->API
.CreatePbufferSurface
= dri2_create_pbuffer_surface
;
3213 dri2_drv
->API
.DestroySurface
= dri2_destroy_surface
;
3214 dri2_drv
->API
.GetProcAddress
= dri2_get_proc_address
;
3215 dri2_drv
->API
.WaitClient
= dri2_wait_client
;
3216 dri2_drv
->API
.WaitNative
= dri2_wait_native
;
3217 dri2_drv
->API
.BindTexImage
= dri2_bind_tex_image
;
3218 dri2_drv
->API
.ReleaseTexImage
= dri2_release_tex_image
;
3219 dri2_drv
->API
.SwapInterval
= dri2_swap_interval
;
3220 dri2_drv
->API
.SwapBuffers
= dri2_swap_buffers
;
3221 dri2_drv
->API
.SwapBuffersWithDamageEXT
= dri2_swap_buffers_with_damage
;
3222 dri2_drv
->API
.SwapBuffersRegionNOK
= dri2_swap_buffers_region
;
3223 dri2_drv
->API
.SetDamageRegion
= dri2_set_damage_region
;
3224 dri2_drv
->API
.PostSubBufferNV
= dri2_post_sub_buffer
;
3225 dri2_drv
->API
.CopyBuffers
= dri2_copy_buffers
,
3226 dri2_drv
->API
.QueryBufferAge
= dri2_query_buffer_age
;
3227 dri2_drv
->API
.CreateImageKHR
= dri2_create_image
;
3228 dri2_drv
->API
.DestroyImageKHR
= dri2_destroy_image_khr
;
3229 dri2_drv
->API
.CreateWaylandBufferFromImageWL
= dri2_create_wayland_buffer_from_image
;
3230 dri2_drv
->API
.QuerySurface
= dri2_query_surface
;
3232 dri2_drv
->API
.CreateDRMImageMESA
= dri2_create_drm_image_mesa
;
3233 dri2_drv
->API
.ExportDRMImageMESA
= dri2_export_drm_image_mesa
;
3234 dri2_drv
->API
.ExportDMABUFImageQueryMESA
= dri2_export_dma_buf_image_query_mesa
;
3235 dri2_drv
->API
.ExportDMABUFImageMESA
= dri2_export_dma_buf_image_mesa
;
3236 dri2_drv
->API
.QueryDmaBufFormatsEXT
= dri2_query_dma_buf_formats
;
3237 dri2_drv
->API
.QueryDmaBufModifiersEXT
= dri2_query_dma_buf_modifiers
;
3239 #ifdef HAVE_WAYLAND_PLATFORM
3240 dri2_drv
->API
.BindWaylandDisplayWL
= dri2_bind_wayland_display_wl
;
3241 dri2_drv
->API
.UnbindWaylandDisplayWL
= dri2_unbind_wayland_display_wl
;
3242 dri2_drv
->API
.QueryWaylandBufferWL
= dri2_query_wayland_buffer_wl
;
3244 dri2_drv
->API
.GetSyncValuesCHROMIUM
= dri2_get_sync_values_chromium
;
3245 dri2_drv
->API
.CreateSyncKHR
= dri2_create_sync
;
3246 dri2_drv
->API
.ClientWaitSyncKHR
= dri2_client_wait_sync
;
3247 dri2_drv
->API
.SignalSyncKHR
= dri2_signal_sync
;
3248 dri2_drv
->API
.WaitSyncKHR
= dri2_server_wait_sync
;
3249 dri2_drv
->API
.DestroySyncKHR
= dri2_destroy_sync
;
3250 dri2_drv
->API
.GLInteropQueryDeviceInfo
= dri2_interop_query_device_info
;
3251 dri2_drv
->API
.GLInteropExportObject
= dri2_interop_export_object
;
3252 dri2_drv
->API
.DupNativeFenceFDANDROID
= dri2_dup_native_fence_fd
;
3253 dri2_drv
->API
.SetBlobCacheFuncsANDROID
= dri2_set_blob_cache_funcs
;