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>
28 #define WL_HIDE_DEPRECATED
41 #include <c11/threads.h>
45 #include <drm_fourcc.h>
48 #include <GL/internal/dri_interface.h>
49 #include <sys/types.h>
52 #ifdef HAVE_WAYLAND_PLATFORM
53 #include "wayland-drm.h"
54 #include "wayland-drm-client-protocol.h"
55 #include "linux-dmabuf-unstable-v1-client-protocol.h"
58 #ifdef HAVE_X11_PLATFORM
59 #include "X11/Xlibint.h"
63 #include "GL/mesa_glinterop.h"
64 #include "loader/loader.h"
65 #include "util/u_atomic.h"
66 #include "util/u_vector.h"
68 /* The kernel header drm_fourcc.h defines the DRM formats below. We duplicate
69 * some of the definitions here so that building Mesa won't bleeding-edge
73 #define DRM_FORMAT_R8 fourcc_code('R', '8', ' ', ' ') /* [7:0] R */
76 #ifndef DRM_FORMAT_RG88
77 #define DRM_FORMAT_RG88 fourcc_code('R', 'G', '8', '8') /* [15:0] R:G 8:8 little endian */
80 #ifndef DRM_FORMAT_GR88
81 #define DRM_FORMAT_GR88 fourcc_code('G', 'R', '8', '8') /* [15:0] G:R 8:8 little endian */
84 #ifndef DRM_FORMAT_R16
85 #define DRM_FORMAT_R16 fourcc_code('R', '1', '6', ' ') /* [15:0] R 16 little endian */
88 #ifndef DRM_FORMAT_GR1616
89 #define DRM_FORMAT_GR1616 fourcc_code('G', 'R', '3', '2') /* [31:0] R:G 16:16 little endian */
92 #ifndef DRM_FORMAT_MOD_INVALID
93 #define DRM_FORMAT_MOD_INVALID ((1ULL<<56) - 1)
97 dri_set_background_context(void *loaderPrivate
)
99 _EGLContext
*ctx
= _eglGetCurrentContext();
100 _EGLThreadInfo
*t
= _eglGetCurrentThread();
102 _eglBindContextToThread(ctx
, t
);
106 dri_is_thread_safe(void *loaderPrivate
)
108 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
109 _EGLDisplay
*display
= dri2_surf
->base
.Resource
.Display
;
111 #ifdef HAVE_X11_PLATFORM
112 Display
*xdpy
= (Display
*)display
->PlatformDisplay
;
114 /* Check Xlib is running in thread safe mode when running on EGL/X11-xlib
117 * 'lock_fns' is the XLockDisplay function pointer of the X11 display 'dpy'.
118 * It wll be NULL if XInitThreads wasn't called.
120 if (display
->Platform
== _EGL_PLATFORM_X11
&& xdpy
&& !xdpy
->lock_fns
)
124 #ifdef HAVE_WAYLAND_PLATFORM
125 if (display
->Platform
== _EGL_PLATFORM_WAYLAND
)
132 const __DRIbackgroundCallableExtension background_callable_extension
= {
133 .base
= { __DRI_BACKGROUND_CALLABLE
, 2 },
135 .setBackgroundContext
= dri_set_background_context
,
136 .isThreadSafe
= dri_is_thread_safe
,
139 const __DRIuseInvalidateExtension use_invalidate
= {
140 .base
= { __DRI_USE_INVALIDATE
, 1 }
143 static const EGLint dri2_to_egl_attribute_map
[__DRI_ATTRIB_MAX
] = {
144 [__DRI_ATTRIB_BUFFER_SIZE
] = EGL_BUFFER_SIZE
,
145 [__DRI_ATTRIB_LEVEL
] = EGL_LEVEL
,
146 [__DRI_ATTRIB_RED_SIZE
] = EGL_RED_SIZE
,
147 [__DRI_ATTRIB_GREEN_SIZE
] = EGL_GREEN_SIZE
,
148 [__DRI_ATTRIB_BLUE_SIZE
] = EGL_BLUE_SIZE
,
149 [__DRI_ATTRIB_LUMINANCE_SIZE
] = EGL_LUMINANCE_SIZE
,
150 [__DRI_ATTRIB_ALPHA_SIZE
] = EGL_ALPHA_SIZE
,
151 [__DRI_ATTRIB_DEPTH_SIZE
] = EGL_DEPTH_SIZE
,
152 [__DRI_ATTRIB_STENCIL_SIZE
] = EGL_STENCIL_SIZE
,
153 [__DRI_ATTRIB_SAMPLE_BUFFERS
] = EGL_SAMPLE_BUFFERS
,
154 [__DRI_ATTRIB_SAMPLES
] = EGL_SAMPLES
,
155 [__DRI_ATTRIB_MAX_PBUFFER_WIDTH
] = EGL_MAX_PBUFFER_WIDTH
,
156 [__DRI_ATTRIB_MAX_PBUFFER_HEIGHT
] = EGL_MAX_PBUFFER_HEIGHT
,
157 [__DRI_ATTRIB_MAX_PBUFFER_PIXELS
] = EGL_MAX_PBUFFER_PIXELS
,
158 [__DRI_ATTRIB_MAX_SWAP_INTERVAL
] = EGL_MAX_SWAP_INTERVAL
,
159 [__DRI_ATTRIB_MIN_SWAP_INTERVAL
] = EGL_MIN_SWAP_INTERVAL
,
160 [__DRI_ATTRIB_YINVERTED
] = EGL_Y_INVERTED_NOK
,
164 dri2_get_dri_config(struct dri2_egl_config
*conf
, EGLint surface_type
,
167 const bool double_buffer
= surface_type
== EGL_WINDOW_BIT
;
168 const bool srgb
= colorspace
== EGL_GL_COLORSPACE_SRGB_KHR
;
170 return conf
->dri_config
[double_buffer
][srgb
];
174 dri2_match_config(const _EGLConfig
*conf
, const _EGLConfig
*criteria
)
176 if (_eglCompareConfigs(conf
, criteria
, NULL
, EGL_FALSE
) != 0)
179 if (!_eglMatchConfig(conf
, criteria
))
185 struct dri2_egl_config
*
186 dri2_add_config(_EGLDisplay
*disp
, const __DRIconfig
*dri_config
, int id
,
187 EGLint surface_type
, const EGLint
*attr_list
,
188 const unsigned int *rgba_masks
)
190 struct dri2_egl_config
*conf
;
191 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
193 unsigned int attrib
, value
, double_buffer
;
195 EGLint key
, bind_to_texture_rgb
, bind_to_texture_rgba
;
196 unsigned int dri_masks
[4] = { 0, 0, 0, 0 };
197 _EGLConfig
*matching_config
;
198 EGLint num_configs
= 0;
201 _eglInitConfig(&base
, disp
, id
);
204 bind_to_texture_rgb
= 0;
205 bind_to_texture_rgba
= 0;
207 for (int i
= 0; dri2_dpy
->core
->indexConfigAttrib(dri_config
, i
, &attrib
,
210 case __DRI_ATTRIB_RENDER_TYPE
:
211 if (value
& __DRI_ATTRIB_RGBA_BIT
)
212 value
= EGL_RGB_BUFFER
;
213 else if (value
& __DRI_ATTRIB_LUMINANCE_BIT
)
214 value
= EGL_LUMINANCE_BUFFER
;
217 _eglSetConfigKey(&base
, EGL_COLOR_BUFFER_TYPE
, value
);
220 case __DRI_ATTRIB_CONFIG_CAVEAT
:
221 if (value
& __DRI_ATTRIB_NON_CONFORMANT_CONFIG
)
222 value
= EGL_NON_CONFORMANT_CONFIG
;
223 else if (value
& __DRI_ATTRIB_SLOW_BIT
)
224 value
= EGL_SLOW_CONFIG
;
227 _eglSetConfigKey(&base
, EGL_CONFIG_CAVEAT
, value
);
230 case __DRI_ATTRIB_BIND_TO_TEXTURE_RGB
:
231 bind_to_texture_rgb
= value
;
234 case __DRI_ATTRIB_BIND_TO_TEXTURE_RGBA
:
235 bind_to_texture_rgba
= value
;
238 case __DRI_ATTRIB_DOUBLE_BUFFER
:
239 double_buffer
= value
;
242 case __DRI_ATTRIB_RED_MASK
:
243 dri_masks
[0] = value
;
246 case __DRI_ATTRIB_GREEN_MASK
:
247 dri_masks
[1] = value
;
250 case __DRI_ATTRIB_BLUE_MASK
:
251 dri_masks
[2] = value
;
254 case __DRI_ATTRIB_ALPHA_MASK
:
255 dri_masks
[3] = value
;
258 case __DRI_ATTRIB_ACCUM_RED_SIZE
:
259 case __DRI_ATTRIB_ACCUM_GREEN_SIZE
:
260 case __DRI_ATTRIB_ACCUM_BLUE_SIZE
:
261 case __DRI_ATTRIB_ACCUM_ALPHA_SIZE
:
262 /* Don't expose visuals with the accumulation buffer. */
267 case __DRI_ATTRIB_FRAMEBUFFER_SRGB_CAPABLE
:
269 if (!disp
->Extensions
.KHR_gl_colorspace
&& srgb
)
273 case __DRI_ATTRIB_MAX_PBUFFER_WIDTH
:
274 _eglSetConfigKey(&base
, EGL_MAX_PBUFFER_WIDTH
,
275 _EGL_MAX_PBUFFER_WIDTH
);
277 case __DRI_ATTRIB_MAX_PBUFFER_HEIGHT
:
278 _eglSetConfigKey(&base
, EGL_MAX_PBUFFER_HEIGHT
,
279 _EGL_MAX_PBUFFER_HEIGHT
);
283 key
= dri2_to_egl_attribute_map
[attrib
];
285 _eglSetConfigKey(&base
, key
, value
);
291 for (int i
= 0; attr_list
[i
] != EGL_NONE
; i
+= 2)
292 _eglSetConfigKey(&base
, attr_list
[i
], attr_list
[i
+1]);
294 if (rgba_masks
&& memcmp(rgba_masks
, dri_masks
, sizeof(dri_masks
)))
297 base
.NativeRenderable
= EGL_TRUE
;
299 base
.SurfaceType
= surface_type
;
300 if (surface_type
& (EGL_PBUFFER_BIT
|
301 (disp
->Extensions
.NOK_texture_from_pixmap
? EGL_PIXMAP_BIT
: 0))) {
302 base
.BindToTextureRGB
= bind_to_texture_rgb
;
303 if (base
.AlphaSize
> 0)
304 base
.BindToTextureRGBA
= bind_to_texture_rgba
;
307 base
.RenderableType
= disp
->ClientAPIs
;
308 base
.Conformant
= disp
->ClientAPIs
;
310 base
.MinSwapInterval
= dri2_dpy
->min_swap_interval
;
311 base
.MaxSwapInterval
= dri2_dpy
->max_swap_interval
;
313 if (!_eglValidateConfig(&base
, EGL_FALSE
)) {
314 _eglLog(_EGL_DEBUG
, "DRI2: failed to validate config %d", id
);
318 config_id
= base
.ConfigID
;
319 base
.ConfigID
= EGL_DONT_CARE
;
320 base
.SurfaceType
= EGL_DONT_CARE
;
321 num_configs
= _eglFilterArray(disp
->Configs
, (void **) &matching_config
, 1,
322 (_EGLArrayForEach
) dri2_match_config
, &base
);
324 if (num_configs
== 1) {
325 conf
= (struct dri2_egl_config
*) matching_config
;
327 if (!conf
->dri_config
[double_buffer
][srgb
])
328 conf
->dri_config
[double_buffer
][srgb
] = dri_config
;
330 /* a similar config type is already added (unlikely) => discard */
333 else if (num_configs
== 0) {
334 conf
= calloc(1, sizeof *conf
);
338 conf
->dri_config
[double_buffer
][srgb
] = dri_config
;
340 memcpy(&conf
->base
, &base
, sizeof base
);
341 conf
->base
.SurfaceType
= 0;
342 conf
->base
.ConfigID
= config_id
;
344 _eglLinkConfig(&conf
->base
);
352 surface_type
&= ~EGL_PIXMAP_BIT
;
355 /* No support for pbuffer + MSAA for now.
357 * XXX TODO: pbuffer + MSAA does not work and causes crashes.
358 * See QT bugreport: https://bugreports.qt.io/browse/QTBUG-47509
361 surface_type
&= ~EGL_PBUFFER_BIT
;
364 conf
->base
.SurfaceType
|= surface_type
;
370 dri2_lookup_egl_image(__DRIscreen
*screen
, void *image
, void *data
)
372 _EGLDisplay
*disp
= data
;
373 struct dri2_egl_image
*dri2_img
;
378 img
= _eglLookupImage(image
, disp
);
380 _eglError(EGL_BAD_PARAMETER
, "dri2_lookup_egl_image");
384 dri2_img
= dri2_egl_image(image
);
386 return dri2_img
->dri_image
;
389 const __DRIimageLookupExtension image_lookup_extension
= {
390 .base
= { __DRI_IMAGE_LOOKUP
, 1 },
392 .lookupEGLImage
= dri2_lookup_egl_image
395 struct dri2_extension_match
{
401 static const struct dri2_extension_match dri3_driver_extensions
[] = {
402 { __DRI_CORE
, 1, offsetof(struct dri2_egl_display
, core
) },
403 { __DRI_IMAGE_DRIVER
, 1, offsetof(struct dri2_egl_display
, image_driver
) },
407 static const struct dri2_extension_match dri2_driver_extensions
[] = {
408 { __DRI_CORE
, 1, offsetof(struct dri2_egl_display
, core
) },
409 { __DRI_DRI2
, 2, offsetof(struct dri2_egl_display
, dri2
) },
413 static const struct dri2_extension_match dri2_core_extensions
[] = {
414 { __DRI2_FLUSH
, 1, offsetof(struct dri2_egl_display
, flush
) },
415 { __DRI_TEX_BUFFER
, 2, offsetof(struct dri2_egl_display
, tex_buffer
) },
416 { __DRI_IMAGE
, 1, offsetof(struct dri2_egl_display
, image
) },
420 static const struct dri2_extension_match swrast_driver_extensions
[] = {
421 { __DRI_CORE
, 1, offsetof(struct dri2_egl_display
, core
) },
422 { __DRI_SWRAST
, 2, offsetof(struct dri2_egl_display
, swrast
) },
426 static const struct dri2_extension_match swrast_core_extensions
[] = {
427 { __DRI_TEX_BUFFER
, 2, offsetof(struct dri2_egl_display
, tex_buffer
) },
431 static const struct dri2_extension_match optional_core_extensions
[] = {
432 { __DRI2_ROBUSTNESS
, 1, offsetof(struct dri2_egl_display
, robustness
) },
433 { __DRI2_NO_ERROR
, 1, offsetof(struct dri2_egl_display
, no_error
) },
434 { __DRI2_CONFIG_QUERY
, 1, offsetof(struct dri2_egl_display
, config
) },
435 { __DRI2_FENCE
, 1, offsetof(struct dri2_egl_display
, fence
) },
436 { __DRI2_RENDERER_QUERY
, 1, offsetof(struct dri2_egl_display
, rendererQuery
) },
437 { __DRI2_INTEROP
, 1, offsetof(struct dri2_egl_display
, interop
) },
438 { __DRI_IMAGE
, 1, offsetof(struct dri2_egl_display
, image
) },
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
;
633 if (dri2_dpy
->image_driver
) {
634 api_mask
= dri2_dpy
->image_driver
->getAPIMask(dri2_dpy
->dri_screen
);
635 } else if (dri2_dpy
->dri2
) {
636 api_mask
= dri2_dpy
->dri2
->getAPIMask(dri2_dpy
->dri_screen
);
638 assert(dri2_dpy
->swrast
);
639 api_mask
= 1 << __DRI_API_OPENGL
|
640 1 << __DRI_API_GLES
|
641 1 << __DRI_API_GLES2
|
642 1 << __DRI_API_GLES3
;
645 disp
->ClientAPIs
= 0;
646 if ((api_mask
& (1 <<__DRI_API_OPENGL
)) && _eglIsApiValid(EGL_OPENGL_API
))
647 disp
->ClientAPIs
|= EGL_OPENGL_BIT
;
648 if ((api_mask
& (1 << __DRI_API_GLES
)) && _eglIsApiValid(EGL_OPENGL_ES_API
))
649 disp
->ClientAPIs
|= EGL_OPENGL_ES_BIT
;
650 if ((api_mask
& (1 << __DRI_API_GLES2
)) && _eglIsApiValid(EGL_OPENGL_ES_API
))
651 disp
->ClientAPIs
|= EGL_OPENGL_ES2_BIT
;
652 if ((api_mask
& (1 << __DRI_API_GLES3
)) && _eglIsApiValid(EGL_OPENGL_ES_API
))
653 disp
->ClientAPIs
|= EGL_OPENGL_ES3_BIT_KHR
;
655 assert(dri2_dpy
->image_driver
|| dri2_dpy
->dri2
|| dri2_dpy
->swrast
);
656 disp
->Extensions
.KHR_no_config_context
= EGL_TRUE
;
657 disp
->Extensions
.KHR_surfaceless_context
= EGL_TRUE
;
659 if (dri2_renderer_query_integer(dri2_dpy
,
660 __DRI2_RENDERER_HAS_FRAMEBUFFER_SRGB
))
661 disp
->Extensions
.KHR_gl_colorspace
= EGL_TRUE
;
663 if (dri2_dpy
->image_driver
||
664 (dri2_dpy
->dri2
&& dri2_dpy
->dri2
->base
.version
>= 3) ||
665 (dri2_dpy
->swrast
&& dri2_dpy
->swrast
->base
.version
>= 3)) {
666 disp
->Extensions
.KHR_create_context
= EGL_TRUE
;
668 if (dri2_dpy
->robustness
)
669 disp
->Extensions
.EXT_create_context_robustness
= EGL_TRUE
;
672 if (dri2_dpy
->no_error
)
673 disp
->Extensions
.KHR_create_context_no_error
= EGL_TRUE
;
675 if (dri2_dpy
->fence
) {
676 disp
->Extensions
.KHR_fence_sync
= EGL_TRUE
;
677 disp
->Extensions
.KHR_wait_sync
= EGL_TRUE
;
678 if (dri2_dpy
->fence
->get_fence_from_cl_event
)
679 disp
->Extensions
.KHR_cl_event2
= EGL_TRUE
;
680 if (dri2_dpy
->fence
->base
.version
>= 2 &&
681 dri2_dpy
->fence
->get_capabilities
) {
682 unsigned capabilities
=
683 dri2_dpy
->fence
->get_capabilities(dri2_dpy
->dri_screen
);
684 disp
->Extensions
.ANDROID_native_fence_sync
=
685 (capabilities
& __DRI_FENCE_CAP_NATIVE_FD
) != 0;
689 disp
->Extensions
.KHR_reusable_sync
= EGL_TRUE
;
691 if (dri2_dpy
->image
) {
692 if (dri2_dpy
->image
->base
.version
>= 10 &&
693 dri2_dpy
->image
->getCapabilities
!= NULL
) {
696 capabilities
= dri2_dpy
->image
->getCapabilities(dri2_dpy
->dri_screen
);
697 disp
->Extensions
.MESA_drm_image
= (capabilities
& __DRI_IMAGE_CAP_GLOBAL_NAMES
) != 0;
699 if (dri2_dpy
->image
->base
.version
>= 11)
700 disp
->Extensions
.MESA_image_dma_buf_export
= EGL_TRUE
;
702 disp
->Extensions
.MESA_drm_image
= EGL_TRUE
;
703 if (dri2_dpy
->image
->base
.version
>= 11)
704 disp
->Extensions
.MESA_image_dma_buf_export
= EGL_TRUE
;
707 disp
->Extensions
.KHR_image_base
= EGL_TRUE
;
708 disp
->Extensions
.KHR_gl_renderbuffer_image
= EGL_TRUE
;
709 if (dri2_dpy
->image
->base
.version
>= 5 &&
710 dri2_dpy
->image
->createImageFromTexture
) {
711 disp
->Extensions
.KHR_gl_texture_2D_image
= EGL_TRUE
;
712 disp
->Extensions
.KHR_gl_texture_cubemap_image
= EGL_TRUE
;
714 if (dri2_renderer_query_integer(dri2_dpy
,
715 __DRI2_RENDERER_HAS_TEXTURE_3D
))
716 disp
->Extensions
.KHR_gl_texture_3D_image
= EGL_TRUE
;
719 if (dri2_dpy
->image
->base
.version
>= 8 &&
720 dri2_dpy
->image
->createImageFromDmaBufs
) {
721 disp
->Extensions
.EXT_image_dma_buf_import
= EGL_TRUE
;
723 if (dri2_dpy
->image
->base
.version
>= 15 &&
724 dri2_dpy
->image
->createImageFromDmaBufs2
&&
725 dri2_dpy
->image
->queryDmaBufFormats
&&
726 dri2_dpy
->image
->queryDmaBufModifiers
) {
727 disp
->Extensions
.EXT_image_dma_buf_import_modifiers
= EGL_TRUE
;
734 dri2_setup_swap_interval(_EGLDisplay
*disp
, int max_swap_interval
)
736 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
737 GLint vblank_mode
= DRI_CONF_VBLANK_DEF_INTERVAL_1
;
739 /* Allow driconf to override applications.*/
740 if (dri2_dpy
->config
)
741 dri2_dpy
->config
->configQueryi(dri2_dpy
->dri_screen
,
742 "vblank_mode", &vblank_mode
);
743 switch (vblank_mode
) {
744 case DRI_CONF_VBLANK_NEVER
:
745 dri2_dpy
->min_swap_interval
= 0;
746 dri2_dpy
->max_swap_interval
= 0;
747 dri2_dpy
->default_swap_interval
= 0;
749 case DRI_CONF_VBLANK_ALWAYS_SYNC
:
750 dri2_dpy
->min_swap_interval
= 1;
751 dri2_dpy
->max_swap_interval
= max_swap_interval
;
752 dri2_dpy
->default_swap_interval
= 1;
754 case DRI_CONF_VBLANK_DEF_INTERVAL_0
:
755 dri2_dpy
->min_swap_interval
= 0;
756 dri2_dpy
->max_swap_interval
= max_swap_interval
;
757 dri2_dpy
->default_swap_interval
= 0;
760 case DRI_CONF_VBLANK_DEF_INTERVAL_1
:
761 dri2_dpy
->min_swap_interval
= 0;
762 dri2_dpy
->max_swap_interval
= max_swap_interval
;
763 dri2_dpy
->default_swap_interval
= 1;
768 /* All platforms but DRM call this function to create the screen and populate
769 * the driver_configs. DRM inherits that information from its display - GBM.
772 dri2_create_screen(_EGLDisplay
*disp
)
774 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
776 if (dri2_dpy
->image_driver
) {
777 dri2_dpy
->dri_screen
=
778 dri2_dpy
->image_driver
->createNewScreen2(0, dri2_dpy
->fd
,
779 dri2_dpy
->loader_extensions
,
780 dri2_dpy
->driver_extensions
,
781 &dri2_dpy
->driver_configs
,
783 } else if (dri2_dpy
->dri2
) {
784 if (dri2_dpy
->dri2
->base
.version
>= 4) {
785 dri2_dpy
->dri_screen
=
786 dri2_dpy
->dri2
->createNewScreen2(0, dri2_dpy
->fd
,
787 dri2_dpy
->loader_extensions
,
788 dri2_dpy
->driver_extensions
,
789 &dri2_dpy
->driver_configs
, disp
);
791 dri2_dpy
->dri_screen
=
792 dri2_dpy
->dri2
->createNewScreen(0, dri2_dpy
->fd
,
793 dri2_dpy
->loader_extensions
,
794 &dri2_dpy
->driver_configs
, disp
);
797 assert(dri2_dpy
->swrast
);
798 if (dri2_dpy
->swrast
->base
.version
>= 4) {
799 dri2_dpy
->dri_screen
=
800 dri2_dpy
->swrast
->createNewScreen2(0, dri2_dpy
->loader_extensions
,
801 dri2_dpy
->driver_extensions
,
802 &dri2_dpy
->driver_configs
, disp
);
804 dri2_dpy
->dri_screen
=
805 dri2_dpy
->swrast
->createNewScreen(0, dri2_dpy
->loader_extensions
,
806 &dri2_dpy
->driver_configs
, disp
);
810 if (dri2_dpy
->dri_screen
== NULL
) {
811 _eglLog(_EGL_WARNING
, "DRI2: failed to create dri screen");
815 dri2_dpy
->own_dri_screen
= true;
820 dri2_setup_extensions(_EGLDisplay
*disp
)
822 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
823 const struct dri2_extension_match
*mandatory_core_extensions
;
824 const __DRIextension
**extensions
;
826 extensions
= dri2_dpy
->core
->getExtensions(dri2_dpy
->dri_screen
);
828 if (dri2_dpy
->image_driver
|| dri2_dpy
->dri2
)
829 mandatory_core_extensions
= dri2_core_extensions
;
831 mandatory_core_extensions
= swrast_core_extensions
;
833 if (!dri2_bind_extensions(dri2_dpy
, mandatory_core_extensions
, extensions
, false))
836 dri2_bind_extensions(dri2_dpy
, optional_core_extensions
, extensions
, true);
841 * Called via eglInitialize(), GLX_drv->API.Initialize().
843 * This must be guaranteed to be called exactly once, even if eglInitialize is
844 * called many times (without a eglTerminate in between).
847 dri2_initialize(_EGLDriver
*drv
, _EGLDisplay
*disp
)
849 EGLBoolean ret
= EGL_FALSE
;
850 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
852 /* In the case where the application calls eglMakeCurrent(context1),
853 * eglTerminate, then eglInitialize again (without a call to eglReleaseThread
854 * or eglMakeCurrent(NULL) before that), dri2_dpy structure is still
855 * initialized, as we need it to be able to free context1 correctly.
857 * It would probably be safest to forcibly release the display with
858 * dri2_display_release, to make sure the display is reinitialized correctly.
859 * However, the EGL spec states that we need to keep a reference to the
860 * current context (so we cannot call dri2_make_current(NULL)), and therefore
861 * we would leak context1 as we would be missing the old display connection
862 * to free it up correctly.
865 dri2_dpy
->ref_count
++;
869 /* not until swrast_dri is supported */
870 if (disp
->Options
.UseFallback
)
873 /* Nothing to initialize for a test only display */
874 if (disp
->Options
.TestOnly
)
877 switch (disp
->Platform
) {
878 #ifdef HAVE_SURFACELESS_PLATFORM
879 case _EGL_PLATFORM_SURFACELESS
:
880 ret
= dri2_initialize_surfaceless(drv
, disp
);
883 #ifdef HAVE_X11_PLATFORM
884 case _EGL_PLATFORM_X11
:
885 ret
= dri2_initialize_x11(drv
, disp
);
888 #ifdef HAVE_DRM_PLATFORM
889 case _EGL_PLATFORM_DRM
:
890 ret
= dri2_initialize_drm(drv
, disp
);
893 #ifdef HAVE_WAYLAND_PLATFORM
894 case _EGL_PLATFORM_WAYLAND
:
895 ret
= dri2_initialize_wayland(drv
, disp
);
898 #ifdef HAVE_ANDROID_PLATFORM
899 case _EGL_PLATFORM_ANDROID
:
900 ret
= dri2_initialize_android(drv
, disp
);
904 _eglLog(_EGL_WARNING
, "No EGL platform enabled.");
911 dri2_dpy
= dri2_egl_display(disp
);
912 dri2_dpy
->ref_count
++;
918 * Decrement display reference count, and free up display if necessary.
921 dri2_display_release(_EGLDisplay
*disp
)
923 struct dri2_egl_display
*dri2_dpy
;
928 dri2_dpy
= dri2_egl_display(disp
);
930 assert(dri2_dpy
->ref_count
> 0);
931 dri2_dpy
->ref_count
--;
933 if (dri2_dpy
->ref_count
> 0)
936 _eglCleanupDisplay(disp
);
937 dri2_display_destroy(disp
);
941 dri2_display_destroy(_EGLDisplay
*disp
)
943 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
945 if (dri2_dpy
->own_dri_screen
) {
946 if (dri2_dpy
->vtbl
->close_screen_notify
)
947 dri2_dpy
->vtbl
->close_screen_notify(disp
);
948 dri2_dpy
->core
->destroyScreen(dri2_dpy
->dri_screen
);
950 if (dri2_dpy
->fd
>= 0)
952 if (dri2_dpy
->driver
)
953 dlclose(dri2_dpy
->driver
);
954 free(dri2_dpy
->driver_name
);
956 #ifdef HAVE_WAYLAND_PLATFORM
957 free(dri2_dpy
->device_name
);
960 switch (disp
->Platform
) {
961 #ifdef HAVE_X11_PLATFORM
962 case _EGL_PLATFORM_X11
:
963 if (dri2_dpy
->own_device
) {
964 xcb_disconnect(dri2_dpy
->conn
);
968 #ifdef HAVE_DRM_PLATFORM
969 case _EGL_PLATFORM_DRM
:
970 if (dri2_dpy
->own_device
) {
971 gbm_device_destroy(&dri2_dpy
->gbm_dri
->base
);
975 #ifdef HAVE_WAYLAND_PLATFORM
976 case _EGL_PLATFORM_WAYLAND
:
977 if (dri2_dpy
->wl_drm
)
978 wl_drm_destroy(dri2_dpy
->wl_drm
);
979 if (dri2_dpy
->wl_dmabuf
)
980 zwp_linux_dmabuf_v1_destroy(dri2_dpy
->wl_dmabuf
);
981 if (dri2_dpy
->wl_shm
)
982 wl_shm_destroy(dri2_dpy
->wl_shm
);
983 if (dri2_dpy
->wl_registry
)
984 wl_registry_destroy(dri2_dpy
->wl_registry
);
985 if (dri2_dpy
->wl_queue
)
986 wl_event_queue_destroy(dri2_dpy
->wl_queue
);
987 if (dri2_dpy
->wl_dpy_wrapper
)
988 wl_proxy_wrapper_destroy(dri2_dpy
->wl_dpy_wrapper
);
989 u_vector_finish(&dri2_dpy
->wl_modifiers
.argb8888
);
990 u_vector_finish(&dri2_dpy
->wl_modifiers
.xrgb8888
);
991 u_vector_finish(&dri2_dpy
->wl_modifiers
.rgb565
);
992 if (dri2_dpy
->own_device
) {
993 wl_display_disconnect(dri2_dpy
->wl_dpy
);
1001 /* The drm platform does not create the screen/driver_configs but reuses
1002 * the ones from the gbm device. As such the gbm itself is responsible
1005 if (disp
->Platform
!= _EGL_PLATFORM_DRM
&& dri2_dpy
->driver_configs
) {
1006 for (unsigned i
= 0; dri2_dpy
->driver_configs
[i
]; i
++)
1007 free((__DRIconfig
*) dri2_dpy
->driver_configs
[i
]);
1008 free(dri2_dpy
->driver_configs
);
1011 disp
->DriverData
= NULL
;
1015 dri2_egl_surface_alloc_local_buffer(struct dri2_egl_surface
*dri2_surf
,
1016 unsigned int att
, unsigned int format
)
1018 struct dri2_egl_display
*dri2_dpy
=
1019 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
1021 if (att
>= ARRAY_SIZE(dri2_surf
->local_buffers
))
1024 if (!dri2_surf
->local_buffers
[att
]) {
1025 dri2_surf
->local_buffers
[att
] =
1026 dri2_dpy
->dri2
->allocateBuffer(dri2_dpy
->dri_screen
, att
, format
,
1027 dri2_surf
->base
.Width
, dri2_surf
->base
.Height
);
1030 return dri2_surf
->local_buffers
[att
];
1034 dri2_egl_surface_free_local_buffers(struct dri2_egl_surface
*dri2_surf
)
1036 struct dri2_egl_display
*dri2_dpy
=
1037 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
1039 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->local_buffers
); i
++) {
1040 if (dri2_surf
->local_buffers
[i
]) {
1041 dri2_dpy
->dri2
->releaseBuffer(dri2_dpy
->dri_screen
,
1042 dri2_surf
->local_buffers
[i
]);
1043 dri2_surf
->local_buffers
[i
] = NULL
;
1049 * Called via eglTerminate(), drv->API.Terminate().
1051 * This must be guaranteed to be called exactly once, even if eglTerminate is
1052 * called many times (without a eglInitialize in between).
1055 dri2_terminate(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1057 /* Release all non-current Context/Surfaces. */
1058 _eglReleaseDisplayResources(drv
, disp
);
1060 dri2_display_release(disp
);
1066 * Set the error code after a call to
1067 * dri2_egl_display::dri2::createContextAttribs.
1070 dri2_create_context_attribs_error(int dri_error
)
1074 switch (dri_error
) {
1075 case __DRI_CTX_ERROR_SUCCESS
:
1078 case __DRI_CTX_ERROR_NO_MEMORY
:
1079 egl_error
= EGL_BAD_ALLOC
;
1082 /* From the EGL_KHR_create_context spec, section "Errors":
1084 * * If <config> does not support a client API context compatible
1085 * with the requested API major and minor version, [...] context flags,
1086 * and context reset notification behavior (for client API types where
1087 * these attributes are supported), then an EGL_BAD_MATCH error is
1090 * * If an OpenGL ES context is requested and the values for
1091 * attributes EGL_CONTEXT_MAJOR_VERSION_KHR and
1092 * EGL_CONTEXT_MINOR_VERSION_KHR specify an OpenGL ES version that
1093 * is not defined, than an EGL_BAD_MATCH error is generated.
1095 * * If an OpenGL context is requested, the requested version is
1096 * greater than 3.2, and the value for attribute
1097 * EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR has no bits set; has any
1098 * bits set other than EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR and
1099 * EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR; has more than
1100 * one of these bits set; or if the implementation does not support
1101 * the requested profile, then an EGL_BAD_MATCH error is generated.
1103 case __DRI_CTX_ERROR_BAD_API
:
1104 case __DRI_CTX_ERROR_BAD_VERSION
:
1105 case __DRI_CTX_ERROR_BAD_FLAG
:
1106 egl_error
= EGL_BAD_MATCH
;
1109 /* From the EGL_KHR_create_context spec, section "Errors":
1111 * * If an attribute name or attribute value in <attrib_list> is not
1112 * recognized (including unrecognized bits in bitmask attributes),
1113 * then an EGL_BAD_ATTRIBUTE error is generated."
1115 case __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE
:
1116 case __DRI_CTX_ERROR_UNKNOWN_FLAG
:
1117 egl_error
= EGL_BAD_ATTRIBUTE
;
1122 egl_error
= EGL_BAD_MATCH
;
1126 _eglError(egl_error
, "dri2_create_context");
1130 dri2_fill_context_attribs(struct dri2_egl_context
*dri2_ctx
,
1131 struct dri2_egl_display
*dri2_dpy
,
1132 uint32_t *ctx_attribs
,
1133 unsigned *num_attribs
)
1137 assert(*num_attribs
>= 8);
1139 ctx_attribs
[pos
++] = __DRI_CTX_ATTRIB_MAJOR_VERSION
;
1140 ctx_attribs
[pos
++] = dri2_ctx
->base
.ClientMajorVersion
;
1141 ctx_attribs
[pos
++] = __DRI_CTX_ATTRIB_MINOR_VERSION
;
1142 ctx_attribs
[pos
++] = dri2_ctx
->base
.ClientMinorVersion
;
1144 if (dri2_ctx
->base
.Flags
!= 0 || dri2_ctx
->base
.NoError
) {
1145 /* If the implementation doesn't support the __DRI2_ROBUSTNESS
1146 * extension, don't even try to send it the robust-access flag.
1147 * It may explode. Instead, generate the required EGL error here.
1149 if ((dri2_ctx
->base
.Flags
& EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR
) != 0
1150 && !dri2_dpy
->robustness
) {
1151 _eglError(EGL_BAD_MATCH
, "eglCreateContext");
1155 ctx_attribs
[pos
++] = __DRI_CTX_ATTRIB_FLAGS
;
1156 ctx_attribs
[pos
++] = dri2_ctx
->base
.Flags
|
1157 (dri2_ctx
->base
.NoError
? __DRI_CTX_FLAG_NO_ERROR
: 0);
1160 if (dri2_ctx
->base
.ResetNotificationStrategy
!= EGL_NO_RESET_NOTIFICATION_KHR
) {
1161 /* If the implementation doesn't support the __DRI2_ROBUSTNESS
1162 * extension, don't even try to send it a reset strategy. It may
1163 * explode. Instead, generate the required EGL error here.
1165 if (!dri2_dpy
->robustness
) {
1166 _eglError(EGL_BAD_CONFIG
, "eglCreateContext");
1170 ctx_attribs
[pos
++] = __DRI_CTX_ATTRIB_RESET_STRATEGY
;
1171 ctx_attribs
[pos
++] = __DRI_CTX_RESET_LOSE_CONTEXT
;
1180 * Called via eglCreateContext(), drv->API.CreateContext().
1182 static _EGLContext
*
1183 dri2_create_context(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLConfig
*conf
,
1184 _EGLContext
*share_list
, const EGLint
*attrib_list
)
1186 struct dri2_egl_context
*dri2_ctx
;
1187 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1188 struct dri2_egl_context
*dri2_ctx_shared
= dri2_egl_context(share_list
);
1189 __DRIcontext
*shared
=
1190 dri2_ctx_shared
? dri2_ctx_shared
->dri_context
: NULL
;
1191 struct dri2_egl_config
*dri2_config
= dri2_egl_config(conf
);
1192 const __DRIconfig
*dri_config
;
1197 dri2_ctx
= malloc(sizeof *dri2_ctx
);
1199 _eglError(EGL_BAD_ALLOC
, "eglCreateContext");
1203 if (!_eglInitContext(&dri2_ctx
->base
, disp
, conf
, attrib_list
))
1206 /* The EGL_EXT_create_context_robustness spec says:
1208 * "Add to the eglCreateContext context creation errors: [...]
1210 * * If the reset notification behavior of <share_context> and the
1211 * newly created context are different then an EGL_BAD_MATCH error is
1214 if (share_list
&& share_list
->ResetNotificationStrategy
!=
1215 dri2_ctx
->base
.ResetNotificationStrategy
) {
1216 _eglError(EGL_BAD_MATCH
, "eglCreateContext");
1220 /* The EGL_KHR_create_context_no_error spec says:
1222 * "BAD_MATCH is generated if the value of EGL_CONTEXT_OPENGL_NO_ERROR_KHR
1223 * used to create <share_context> does not match the value of
1224 * EGL_CONTEXT_OPENGL_NO_ERROR_KHR for the context being created."
1226 if (share_list
&& share_list
->NoError
!= dri2_ctx
->base
.NoError
) {
1227 _eglError(EGL_BAD_MATCH
, "eglCreateContext");
1231 switch (dri2_ctx
->base
.ClientAPI
) {
1232 case EGL_OPENGL_ES_API
:
1233 switch (dri2_ctx
->base
.ClientMajorVersion
) {
1235 api
= __DRI_API_GLES
;
1238 api
= __DRI_API_GLES2
;
1241 api
= __DRI_API_GLES3
;
1244 _eglError(EGL_BAD_PARAMETER
, "eglCreateContext");
1249 case EGL_OPENGL_API
:
1250 if ((dri2_ctx
->base
.ClientMajorVersion
>= 4
1251 || (dri2_ctx
->base
.ClientMajorVersion
== 3
1252 && dri2_ctx
->base
.ClientMinorVersion
>= 2))
1253 && dri2_ctx
->base
.Profile
== EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR
)
1254 api
= __DRI_API_OPENGL_CORE
;
1256 api
= __DRI_API_OPENGL
;
1259 _eglError(EGL_BAD_PARAMETER
, "eglCreateContext");
1265 /* The config chosen here isn't necessarily
1266 * used for surfaces later.
1267 * A pixmap surface will use the single config.
1268 * This opportunity depends on disabling the
1269 * doubleBufferMode check in
1270 * src/mesa/main/context.c:check_compatible()
1272 if (dri2_config
->dri_config
[1][0])
1273 dri_config
= dri2_config
->dri_config
[1][0];
1275 dri_config
= dri2_config
->dri_config
[0][0];
1277 /* EGL_WINDOW_BIT is set only when there is a double-buffered dri_config.
1278 * This makes sure the back buffer will always be used.
1280 if (conf
->SurfaceType
& EGL_WINDOW_BIT
)
1281 dri2_ctx
->base
.WindowRenderBuffer
= EGL_BACK_BUFFER
;
1286 if (dri2_dpy
->image_driver
) {
1288 unsigned num_attribs
= 8;
1289 uint32_t ctx_attribs
[8];
1291 if (!dri2_fill_context_attribs(dri2_ctx
, dri2_dpy
, ctx_attribs
,
1295 dri2_ctx
->dri_context
=
1296 dri2_dpy
->image_driver
->createContextAttribs(dri2_dpy
->dri_screen
,
1304 dri2_create_context_attribs_error(error
);
1305 } else if (dri2_dpy
->dri2
) {
1306 if (dri2_dpy
->dri2
->base
.version
>= 3) {
1308 unsigned num_attribs
= 8;
1309 uint32_t ctx_attribs
[8];
1311 if (!dri2_fill_context_attribs(dri2_ctx
, dri2_dpy
, ctx_attribs
,
1315 dri2_ctx
->dri_context
=
1316 dri2_dpy
->dri2
->createContextAttribs(dri2_dpy
->dri_screen
,
1324 dri2_create_context_attribs_error(error
);
1326 dri2_ctx
->dri_context
=
1327 dri2_dpy
->dri2
->createNewContextForAPI(dri2_dpy
->dri_screen
,
1334 assert(dri2_dpy
->swrast
);
1335 if (dri2_dpy
->swrast
->base
.version
>= 3) {
1337 unsigned num_attribs
= 8;
1338 uint32_t ctx_attribs
[8];
1340 if (!dri2_fill_context_attribs(dri2_ctx
, dri2_dpy
, ctx_attribs
,
1344 dri2_ctx
->dri_context
=
1345 dri2_dpy
->swrast
->createContextAttribs(dri2_dpy
->dri_screen
,
1353 dri2_create_context_attribs_error(error
);
1355 dri2_ctx
->dri_context
=
1356 dri2_dpy
->swrast
->createNewContextForAPI(dri2_dpy
->dri_screen
,
1364 if (!dri2_ctx
->dri_context
)
1367 return &dri2_ctx
->base
;
1375 * Called via eglDestroyContext(), drv->API.DestroyContext().
1378 dri2_destroy_context(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLContext
*ctx
)
1380 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
1381 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1383 if (_eglPutContext(ctx
)) {
1384 dri2_dpy
->core
->destroyContext(dri2_ctx
->dri_context
);
1392 dri2_init_surface(_EGLSurface
*surf
, _EGLDisplay
*dpy
, EGLint type
,
1393 _EGLConfig
*conf
, const EGLint
*attrib_list
, EGLBoolean enable_out_fence
)
1395 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
1396 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1398 dri2_surf
->out_fence_fd
= -1;
1399 dri2_surf
->enable_out_fence
= false;
1400 if (dri2_dpy
->fence
&& dri2_dpy
->fence
->base
.version
>= 2 &&
1401 dri2_dpy
->fence
->get_capabilities
&&
1402 (dri2_dpy
->fence
->get_capabilities(dri2_dpy
->dri_screen
) &
1403 __DRI_FENCE_CAP_NATIVE_FD
)) {
1404 dri2_surf
->enable_out_fence
= enable_out_fence
;
1407 return _eglInitSurface(surf
, dpy
, type
, conf
, attrib_list
);
1411 dri2_surface_set_out_fence_fd( _EGLSurface
*surf
, int fence_fd
)
1413 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
1415 if (dri2_surf
->out_fence_fd
>=0)
1416 close(dri2_surf
->out_fence_fd
);
1418 dri2_surf
->out_fence_fd
= fence_fd
;
1422 dri2_fini_surface(_EGLSurface
*surf
)
1424 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
1426 dri2_surface_set_out_fence_fd(surf
, -1);
1427 dri2_surf
->enable_out_fence
= false;
1431 dri2_destroy_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
)
1433 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1435 if (!_eglPutSurface(surf
))
1438 return dri2_dpy
->vtbl
->destroy_surface(drv
, dpy
, surf
);
1442 dri2_surf_update_fence_fd(_EGLContext
*ctx
,
1443 _EGLDisplay
*dpy
, _EGLSurface
*surf
)
1445 __DRIcontext
*dri_ctx
= dri2_egl_context(ctx
)->dri_context
;
1446 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1447 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
1451 if (!dri2_surf
->enable_out_fence
)
1454 fence
= dri2_dpy
->fence
->create_fence_fd(dri_ctx
, -1);
1456 fence_fd
= dri2_dpy
->fence
->get_fence_fd(dri2_dpy
->dri_screen
,
1458 dri2_dpy
->fence
->destroy_fence(dri2_dpy
->dri_screen
, fence
);
1460 dri2_surface_set_out_fence_fd(surf
, fence_fd
);
1464 * Called via eglMakeCurrent(), drv->API.MakeCurrent().
1467 dri2_make_current(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*dsurf
,
1468 _EGLSurface
*rsurf
, _EGLContext
*ctx
)
1470 struct dri2_egl_driver
*dri2_drv
= dri2_egl_driver(drv
);
1471 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1472 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
1473 _EGLContext
*old_ctx
;
1474 _EGLSurface
*old_dsurf
, *old_rsurf
;
1475 _EGLSurface
*tmp_dsurf
, *tmp_rsurf
;
1476 __DRIdrawable
*ddraw
, *rdraw
;
1481 return _eglError(EGL_NOT_INITIALIZED
, "eglMakeCurrent");
1483 /* make new bindings */
1484 if (!_eglBindContext(ctx
, dsurf
, rsurf
, &old_ctx
, &old_dsurf
, &old_rsurf
)) {
1485 /* _eglBindContext already sets the EGL error (in _eglCheckMakeCurrent) */
1489 /* flush before context switch */
1491 dri2_drv
->glFlush();
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
;
1500 dri2_surf_update_fence_fd(old_ctx
, disp
, old_dsurf
);
1501 dri2_dpy
->core
->unbindContext(old_cctx
);
1504 unbind
= (cctx
== NULL
&& ddraw
== NULL
&& rdraw
== NULL
);
1506 if (unbind
|| dri2_dpy
->core
->bindContext(cctx
, ddraw
, rdraw
)) {
1507 dri2_destroy_surface(drv
, disp
, old_dsurf
);
1508 dri2_destroy_surface(drv
, disp
, old_rsurf
);
1511 dri2_dpy
->ref_count
++;
1513 EGLDisplay old_disp
= _eglGetDisplayHandle(old_ctx
->Resource
.Display
);
1514 dri2_destroy_context(drv
, disp
, old_ctx
);
1515 dri2_display_release(old_disp
);
1520 /* undo the previous _eglBindContext */
1521 _eglBindContext(old_ctx
, old_dsurf
, old_rsurf
, &ctx
, &tmp_dsurf
, &tmp_rsurf
);
1522 assert(&dri2_ctx
->base
== ctx
&&
1523 tmp_dsurf
== dsurf
&&
1524 tmp_rsurf
== rsurf
);
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");
1543 dri2_surface_get_dri_drawable(_EGLSurface
*surf
)
1545 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
1547 return dri2_surf
->dri_drawable
;
1551 * Called from eglGetProcAddress() via drv->API.GetProcAddress().
1554 dri2_get_proc_address(_EGLDriver
*drv
, const char *procname
)
1556 struct dri2_egl_driver
*dri2_drv
= dri2_egl_driver(drv
);
1558 return dri2_drv
->get_proc_address(procname
);
1562 dri2_create_window_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
1563 _EGLConfig
*conf
, void *native_window
,
1564 const EGLint
*attrib_list
)
1566 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1567 return dri2_dpy
->vtbl
->create_window_surface(drv
, dpy
, conf
, native_window
,
1572 dri2_create_pixmap_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
1573 _EGLConfig
*conf
, void *native_pixmap
,
1574 const EGLint
*attrib_list
)
1576 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1577 return dri2_dpy
->vtbl
->create_pixmap_surface(drv
, dpy
, conf
, native_pixmap
,
1582 dri2_create_pbuffer_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
1583 _EGLConfig
*conf
, const EGLint
*attrib_list
)
1585 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1586 return dri2_dpy
->vtbl
->create_pbuffer_surface(drv
, dpy
, conf
, attrib_list
);
1590 dri2_swap_interval(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
1593 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1594 if (!dri2_dpy
->vtbl
->swap_interval
)
1596 return dri2_dpy
->vtbl
->swap_interval(drv
, dpy
, surf
, interval
);
1600 * Asks the client API to flush any rendering to the drawable so that we can
1601 * do our swapbuffers.
1604 dri2_flush_drawable_for_swapbuffers(_EGLDisplay
*disp
, _EGLSurface
*draw
)
1606 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1607 __DRIdrawable
*dri_drawable
= dri2_dpy
->vtbl
->get_dri_drawable(draw
);
1609 if (dri2_dpy
->flush
) {
1610 if (dri2_dpy
->flush
->base
.version
>= 4) {
1611 /* We know there's a current context because:
1613 * "If surface is not bound to the calling thread’s current
1614 * context, an EGL_BAD_SURFACE error is generated."
1616 _EGLContext
*ctx
= _eglGetCurrentContext();
1617 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
1619 /* From the EGL 1.4 spec (page 52):
1621 * "The contents of ancillary buffers are always undefined
1622 * after calling eglSwapBuffers."
1624 dri2_dpy
->flush
->flush_with_flags(dri2_ctx
->dri_context
,
1626 __DRI2_FLUSH_DRAWABLE
|
1627 __DRI2_FLUSH_INVALIDATE_ANCILLARY
,
1628 __DRI2_THROTTLE_SWAPBUFFER
);
1630 dri2_dpy
->flush
->flush(dri_drawable
);
1636 dri2_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
)
1638 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1639 _EGLContext
*ctx
= _eglGetCurrentContext();
1642 dri2_surf_update_fence_fd(ctx
, dpy
, surf
);
1643 return dri2_dpy
->vtbl
->swap_buffers(drv
, dpy
, surf
);
1647 dri2_swap_buffers_with_damage(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
1649 const EGLint
*rects
, EGLint n_rects
)
1651 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1652 _EGLContext
*ctx
= _eglGetCurrentContext();
1655 dri2_surf_update_fence_fd(ctx
, dpy
, surf
);
1656 return dri2_dpy
->vtbl
->swap_buffers_with_damage(drv
, dpy
, surf
,
1661 dri2_swap_buffers_region(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
1662 EGLint numRects
, const EGLint
*rects
)
1664 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1665 return dri2_dpy
->vtbl
->swap_buffers_region(drv
, dpy
, surf
, numRects
, rects
);
1669 dri2_set_damage_region(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
1670 EGLint
*rects
, EGLint n_rects
)
1672 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1673 return dri2_dpy
->vtbl
->set_damage_region(drv
, dpy
, surf
, rects
, n_rects
);
1677 dri2_post_sub_buffer(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
1678 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
1680 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1681 return dri2_dpy
->vtbl
->post_sub_buffer(drv
, dpy
, surf
, x
, y
, width
, height
);
1685 dri2_copy_buffers(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
1686 void *native_pixmap_target
)
1688 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1689 return dri2_dpy
->vtbl
->copy_buffers(drv
, dpy
, surf
, native_pixmap_target
);
1693 dri2_query_buffer_age(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
)
1695 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1696 return dri2_dpy
->vtbl
->query_buffer_age(drv
, dpy
, surf
);
1700 dri2_wait_client(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLContext
*ctx
)
1702 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1703 _EGLSurface
*surf
= ctx
->DrawSurface
;
1704 __DRIdrawable
*dri_drawable
= dri2_dpy
->vtbl
->get_dri_drawable(surf
);
1708 /* FIXME: If EGL allows frontbuffer rendering for window surfaces,
1709 * we need to copy fake to real here.*/
1711 if (dri2_dpy
->flush
!= NULL
)
1712 dri2_dpy
->flush
->flush(dri_drawable
);
1718 dri2_wait_native(_EGLDriver
*drv
, _EGLDisplay
*disp
, EGLint engine
)
1723 if (engine
!= EGL_CORE_NATIVE_ENGINE
)
1724 return _eglError(EGL_BAD_PARAMETER
, "eglWaitNative");
1731 dri2_bind_tex_image(_EGLDriver
*drv
,
1732 _EGLDisplay
*disp
, _EGLSurface
*surf
, EGLint buffer
)
1734 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1735 struct dri2_egl_context
*dri2_ctx
;
1737 GLint format
, target
;
1738 __DRIdrawable
*dri_drawable
= dri2_dpy
->vtbl
->get_dri_drawable(surf
);
1740 ctx
= _eglGetCurrentContext();
1741 dri2_ctx
= dri2_egl_context(ctx
);
1743 if (!_eglBindTexImage(drv
, disp
, surf
, buffer
))
1746 switch (surf
->TextureFormat
) {
1747 case EGL_TEXTURE_RGB
:
1748 format
= __DRI_TEXTURE_FORMAT_RGB
;
1750 case EGL_TEXTURE_RGBA
:
1751 format
= __DRI_TEXTURE_FORMAT_RGBA
;
1754 assert(!"Unexpected texture format in dri2_bind_tex_image()");
1755 format
= __DRI_TEXTURE_FORMAT_RGBA
;
1758 switch (surf
->TextureTarget
) {
1759 case EGL_TEXTURE_2D
:
1760 target
= GL_TEXTURE_2D
;
1763 target
= GL_TEXTURE_2D
;
1764 assert(!"Unexpected texture target in dri2_bind_tex_image()");
1767 dri2_dpy
->tex_buffer
->setTexBuffer2(dri2_ctx
->dri_context
,
1775 dri2_release_tex_image(_EGLDriver
*drv
,
1776 _EGLDisplay
*disp
, _EGLSurface
*surf
, EGLint buffer
)
1778 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1779 struct dri2_egl_context
*dri2_ctx
;
1782 __DRIdrawable
*dri_drawable
= dri2_dpy
->vtbl
->get_dri_drawable(surf
);
1784 ctx
= _eglGetCurrentContext();
1785 dri2_ctx
= dri2_egl_context(ctx
);
1787 if (!_eglReleaseTexImage(drv
, disp
, surf
, buffer
))
1790 switch (surf
->TextureTarget
) {
1791 case EGL_TEXTURE_2D
:
1792 target
= GL_TEXTURE_2D
;
1798 if (dri2_dpy
->tex_buffer
->base
.version
>= 3 &&
1799 dri2_dpy
->tex_buffer
->releaseTexBuffer
!= NULL
) {
1800 dri2_dpy
->tex_buffer
->releaseTexBuffer(dri2_ctx
->dri_context
,
1801 target
, dri_drawable
);
1808 dri2_create_image(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLContext
*ctx
,
1809 EGLenum target
, EGLClientBuffer buffer
,
1810 const EGLint
*attr_list
)
1812 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1813 return dri2_dpy
->vtbl
->create_image(drv
, dpy
, ctx
, target
, buffer
,
1818 dri2_create_image_from_dri(_EGLDisplay
*disp
, __DRIimage
*dri_image
)
1820 struct dri2_egl_image
*dri2_img
;
1822 if (dri_image
== NULL
) {
1823 _eglError(EGL_BAD_ALLOC
, "dri2_create_image");
1827 dri2_img
= malloc(sizeof *dri2_img
);
1829 _eglError(EGL_BAD_ALLOC
, "dri2_create_image");
1833 _eglInitImage(&dri2_img
->base
, disp
);
1835 dri2_img
->dri_image
= dri_image
;
1837 return &dri2_img
->base
;
1841 dri2_create_image_khr_renderbuffer(_EGLDisplay
*disp
, _EGLContext
*ctx
,
1842 EGLClientBuffer buffer
,
1843 const EGLint
*attr_list
)
1845 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1846 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
1847 GLuint renderbuffer
= (GLuint
) (uintptr_t) buffer
;
1848 __DRIimage
*dri_image
;
1850 if (renderbuffer
== 0) {
1851 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
1852 return EGL_NO_IMAGE_KHR
;
1855 if (!disp
->Extensions
.KHR_gl_renderbuffer_image
) {
1856 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
1857 return EGL_NO_IMAGE_KHR
;
1861 dri2_dpy
->image
->createImageFromRenderbuffer(dri2_ctx
->dri_context
,
1862 renderbuffer
, NULL
);
1864 return dri2_create_image_from_dri(disp
, dri_image
);
1867 #ifdef HAVE_WAYLAND_PLATFORM
1869 /* This structure describes how a wl_buffer maps to one or more
1870 * __DRIimages. A wl_drm_buffer stores the wl_drm format code and the
1871 * offsets and strides of the planes in the buffer. This table maps a
1872 * wl_drm format code to a description of the planes in the buffer
1873 * that lets us create a __DRIimage for each of the planes. */
1875 static const struct wl_drm_components_descriptor
{
1876 uint32_t dri_components
;
1879 } wl_drm_components
[] = {
1880 { __DRI_IMAGE_COMPONENTS_RGB
, EGL_TEXTURE_RGB
, 1 },
1881 { __DRI_IMAGE_COMPONENTS_RGBA
, EGL_TEXTURE_RGBA
, 1 },
1882 { __DRI_IMAGE_COMPONENTS_Y_U_V
, EGL_TEXTURE_Y_U_V_WL
, 3 },
1883 { __DRI_IMAGE_COMPONENTS_Y_UV
, EGL_TEXTURE_Y_UV_WL
, 2 },
1884 { __DRI_IMAGE_COMPONENTS_Y_XUXV
, EGL_TEXTURE_Y_XUXV_WL
, 2 },
1888 dri2_create_image_wayland_wl_buffer(_EGLDisplay
*disp
, _EGLContext
*ctx
,
1889 EGLClientBuffer _buffer
,
1890 const EGLint
*attr_list
)
1892 struct wl_drm_buffer
*buffer
;
1893 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1894 const struct wl_drm_components_descriptor
*f
;
1895 __DRIimage
*dri_image
;
1896 _EGLImageAttribs attrs
;
1899 buffer
= wayland_drm_buffer_get(dri2_dpy
->wl_server_drm
,
1900 (struct wl_resource
*) _buffer
);
1904 if (!_eglParseImageAttribList(&attrs
, disp
, attr_list
))
1907 plane
= attrs
.PlaneWL
;
1908 f
= buffer
->driver_format
;
1909 if (plane
< 0 || plane
>= f
->nplanes
) {
1910 _eglError(EGL_BAD_PARAMETER
,
1911 "dri2_create_image_wayland_wl_buffer (plane out of bounds)");
1915 dri_image
= dri2_dpy
->image
->fromPlanar(buffer
->driver_buffer
, plane
, NULL
);
1917 if (dri_image
== NULL
) {
1918 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_wayland_wl_buffer");
1922 return dri2_create_image_from_dri(disp
, dri_image
);
1927 dri2_get_sync_values_chromium(_EGLDisplay
*dpy
, _EGLSurface
*surf
,
1928 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
1931 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1932 return dri2_dpy
->vtbl
->get_sync_values(dpy
, surf
, ust
, msc
, sbc
);
1936 * Set the error code after a call to
1937 * dri2_egl_image::dri_image::createImageFromTexture.
1940 dri2_create_image_khr_texture_error(int dri_error
)
1944 switch (dri_error
) {
1945 case __DRI_IMAGE_ERROR_SUCCESS
:
1948 case __DRI_IMAGE_ERROR_BAD_ALLOC
:
1949 egl_error
= EGL_BAD_ALLOC
;
1952 case __DRI_IMAGE_ERROR_BAD_MATCH
:
1953 egl_error
= EGL_BAD_MATCH
;
1956 case __DRI_IMAGE_ERROR_BAD_PARAMETER
:
1957 egl_error
= EGL_BAD_PARAMETER
;
1960 case __DRI_IMAGE_ERROR_BAD_ACCESS
:
1961 egl_error
= EGL_BAD_ACCESS
;
1966 egl_error
= EGL_BAD_MATCH
;
1970 _eglError(egl_error
, "dri2_create_image_khr_texture");
1974 dri2_create_image_khr_texture(_EGLDisplay
*disp
, _EGLContext
*ctx
,
1976 EGLClientBuffer buffer
,
1977 const EGLint
*attr_list
)
1979 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1980 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
1981 struct dri2_egl_image
*dri2_img
;
1982 GLuint texture
= (GLuint
) (uintptr_t) buffer
;
1983 _EGLImageAttribs attrs
;
1989 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
1990 return EGL_NO_IMAGE_KHR
;
1993 if (!_eglParseImageAttribList(&attrs
, disp
, attr_list
))
1994 return EGL_NO_IMAGE_KHR
;
1997 case EGL_GL_TEXTURE_2D_KHR
:
1998 if (!disp
->Extensions
.KHR_gl_texture_2D_image
) {
1999 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
2000 return EGL_NO_IMAGE_KHR
;
2003 gl_target
= GL_TEXTURE_2D
;
2005 case EGL_GL_TEXTURE_3D_KHR
:
2006 if (!disp
->Extensions
.KHR_gl_texture_3D_image
) {
2007 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
2008 return EGL_NO_IMAGE_KHR
;
2011 depth
= attrs
.GLTextureZOffset
;
2012 gl_target
= GL_TEXTURE_3D
;
2014 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR
:
2015 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR
:
2016 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR
:
2017 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR
:
2018 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR
:
2019 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR
:
2020 if (!disp
->Extensions
.KHR_gl_texture_cubemap_image
) {
2021 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
2022 return EGL_NO_IMAGE_KHR
;
2025 depth
= target
- EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR
;
2026 gl_target
= GL_TEXTURE_CUBE_MAP
;
2029 unreachable("Unexpected target in dri2_create_image_khr_texture()");
2030 return EGL_NO_IMAGE_KHR
;
2033 dri2_img
= malloc(sizeof *dri2_img
);
2035 _eglError(EGL_BAD_ALLOC
, "dri2_create_image_khr");
2036 return EGL_NO_IMAGE_KHR
;
2039 _eglInitImage(&dri2_img
->base
, disp
);
2041 dri2_img
->dri_image
=
2042 dri2_dpy
->image
->createImageFromTexture(dri2_ctx
->dri_context
,
2046 attrs
.GLTextureLevel
,
2049 dri2_create_image_khr_texture_error(error
);
2051 if (!dri2_img
->dri_image
) {
2053 return EGL_NO_IMAGE_KHR
;
2055 return &dri2_img
->base
;
2059 dri2_query_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
2060 EGLint attribute
, EGLint
*value
)
2062 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
2063 if (!dri2_dpy
->vtbl
->query_surface
)
2064 return _eglQuerySurface(drv
, dpy
, surf
, attribute
, value
);
2065 return dri2_dpy
->vtbl
->query_surface(drv
, dpy
, surf
, attribute
, value
);
2068 static struct wl_buffer
*
2069 dri2_create_wayland_buffer_from_image(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
2072 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
2073 return dri2_dpy
->vtbl
->create_wayland_buffer_from_image(drv
, dpy
, img
);
2078 dri2_create_image_mesa_drm_buffer(_EGLDisplay
*disp
, _EGLContext
*ctx
,
2079 EGLClientBuffer buffer
, const EGLint
*attr_list
)
2081 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2082 EGLint format
, name
, pitch
;
2083 _EGLImageAttribs attrs
;
2084 __DRIimage
*dri_image
;
2086 name
= (EGLint
) (uintptr_t) buffer
;
2088 if (!_eglParseImageAttribList(&attrs
, disp
, attr_list
))
2091 if (attrs
.Width
<= 0 || attrs
.Height
<= 0 ||
2092 attrs
.DRMBufferStrideMESA
<= 0) {
2093 _eglError(EGL_BAD_PARAMETER
,
2094 "bad width, height or stride");
2098 switch (attrs
.DRMBufferFormatMESA
) {
2099 case EGL_DRM_BUFFER_FORMAT_ARGB32_MESA
:
2100 format
= __DRI_IMAGE_FORMAT_ARGB8888
;
2101 pitch
= attrs
.DRMBufferStrideMESA
;
2104 _eglError(EGL_BAD_PARAMETER
,
2105 "dri2_create_image_khr: unsupported pixmap depth");
2110 dri2_dpy
->image
->createImageFromName(dri2_dpy
->dri_screen
,
2118 return dri2_create_image_from_dri(disp
, dri_image
);
2122 dri2_check_dma_buf_attribs(const _EGLImageAttribs
*attrs
)
2127 * "Required attributes and their values are as follows:
2129 * * EGL_WIDTH & EGL_HEIGHT: The logical dimensions of the buffer in pixels
2131 * * EGL_LINUX_DRM_FOURCC_EXT: The pixel format of the buffer, as specified
2132 * by drm_fourcc.h and used as the pixel_format parameter of the
2133 * drm_mode_fb_cmd2 ioctl."
2137 * "* If <target> is EGL_LINUX_DMA_BUF_EXT, and the list of attributes is
2138 * incomplete, EGL_BAD_PARAMETER is generated."
2140 if (attrs
->Width
<= 0 || attrs
->Height
<= 0 ||
2141 !attrs
->DMABufFourCC
.IsPresent
)
2142 return _eglError(EGL_BAD_PARAMETER
, "attribute(s) missing");
2147 * "If <target> is EGL_LINUX_DMA_BUF_EXT and one or more of the values
2148 * specified for a plane's pitch or offset isn't supported by EGL,
2149 * EGL_BAD_ACCESS is generated."
2151 for (unsigned i
= 0; i
< ARRAY_SIZE(attrs
->DMABufPlanePitches
); ++i
) {
2152 if (attrs
->DMABufPlanePitches
[i
].IsPresent
&&
2153 attrs
->DMABufPlanePitches
[i
].Value
<= 0)
2154 return _eglError(EGL_BAD_ACCESS
, "invalid pitch");
2158 * If <target> is EGL_LINUX_DMA_BUF_EXT, both or neither of the following
2159 * attribute values may be given.
2161 * This is referring to EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT and
2162 * EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT, and the same for other planes.
2164 for (unsigned i
= 0; i
< DMA_BUF_MAX_PLANES
; ++i
) {
2165 if (attrs
->DMABufPlaneModifiersLo
[i
].IsPresent
!=
2166 attrs
->DMABufPlaneModifiersHi
[i
].IsPresent
)
2167 return _eglError(EGL_BAD_PARAMETER
, "modifier attribute lo or hi missing");
2170 /* Although the EGL_EXT_image_dma_buf_import_modifiers spec doesn't
2171 * mandate it, we only accept the same modifier across all planes. */
2172 for (unsigned i
= 1; i
< DMA_BUF_MAX_PLANES
; ++i
) {
2173 if (attrs
->DMABufPlaneFds
[i
].IsPresent
) {
2174 if ((attrs
->DMABufPlaneModifiersLo
[0].IsPresent
!=
2175 attrs
->DMABufPlaneModifiersLo
[i
].IsPresent
) ||
2176 (attrs
->DMABufPlaneModifiersLo
[0].Value
!=
2177 attrs
->DMABufPlaneModifiersLo
[i
].Value
) ||
2178 (attrs
->DMABufPlaneModifiersHi
[0].Value
!=
2179 attrs
->DMABufPlaneModifiersHi
[i
].Value
))
2180 return _eglError(EGL_BAD_PARAMETER
, "modifier attributes not equal");
2187 /* Returns the total number of file descriptors. Zero indicates an error. */
2189 dri2_check_dma_buf_format(const _EGLImageAttribs
*attrs
)
2193 switch (attrs
->DMABufFourCC
.Value
) {
2195 case DRM_FORMAT_RG88
:
2196 case DRM_FORMAT_GR88
:
2197 case DRM_FORMAT_R16
:
2198 case DRM_FORMAT_GR1616
:
2199 case DRM_FORMAT_RGB332
:
2200 case DRM_FORMAT_BGR233
:
2201 case DRM_FORMAT_XRGB4444
:
2202 case DRM_FORMAT_XBGR4444
:
2203 case DRM_FORMAT_RGBX4444
:
2204 case DRM_FORMAT_BGRX4444
:
2205 case DRM_FORMAT_ARGB4444
:
2206 case DRM_FORMAT_ABGR4444
:
2207 case DRM_FORMAT_RGBA4444
:
2208 case DRM_FORMAT_BGRA4444
:
2209 case DRM_FORMAT_XRGB1555
:
2210 case DRM_FORMAT_XBGR1555
:
2211 case DRM_FORMAT_RGBX5551
:
2212 case DRM_FORMAT_BGRX5551
:
2213 case DRM_FORMAT_ARGB1555
:
2214 case DRM_FORMAT_ABGR1555
:
2215 case DRM_FORMAT_RGBA5551
:
2216 case DRM_FORMAT_BGRA5551
:
2217 case DRM_FORMAT_RGB565
:
2218 case DRM_FORMAT_BGR565
:
2219 case DRM_FORMAT_RGB888
:
2220 case DRM_FORMAT_BGR888
:
2221 case DRM_FORMAT_XRGB8888
:
2222 case DRM_FORMAT_XBGR8888
:
2223 case DRM_FORMAT_RGBX8888
:
2224 case DRM_FORMAT_BGRX8888
:
2225 case DRM_FORMAT_ARGB8888
:
2226 case DRM_FORMAT_ABGR8888
:
2227 case DRM_FORMAT_RGBA8888
:
2228 case DRM_FORMAT_BGRA8888
:
2229 case DRM_FORMAT_XRGB2101010
:
2230 case DRM_FORMAT_XBGR2101010
:
2231 case DRM_FORMAT_RGBX1010102
:
2232 case DRM_FORMAT_BGRX1010102
:
2233 case DRM_FORMAT_ARGB2101010
:
2234 case DRM_FORMAT_ABGR2101010
:
2235 case DRM_FORMAT_RGBA1010102
:
2236 case DRM_FORMAT_BGRA1010102
:
2237 case DRM_FORMAT_YUYV
:
2238 case DRM_FORMAT_YVYU
:
2239 case DRM_FORMAT_UYVY
:
2240 case DRM_FORMAT_VYUY
:
2243 case DRM_FORMAT_NV12
:
2244 case DRM_FORMAT_NV21
:
2245 case DRM_FORMAT_NV16
:
2246 case DRM_FORMAT_NV61
:
2249 case DRM_FORMAT_YUV410
:
2250 case DRM_FORMAT_YVU410
:
2251 case DRM_FORMAT_YUV411
:
2252 case DRM_FORMAT_YVU411
:
2253 case DRM_FORMAT_YUV420
:
2254 case DRM_FORMAT_YVU420
:
2255 case DRM_FORMAT_YUV422
:
2256 case DRM_FORMAT_YVU422
:
2257 case DRM_FORMAT_YUV444
:
2258 case DRM_FORMAT_YVU444
:
2262 _eglError(EGL_BAD_ATTRIBUTE
, "invalid format");
2266 for (unsigned i
= plane_n
; i
< DMA_BUF_MAX_PLANES
; i
++) {
2268 * The modifiers extension spec says:
2270 * "Modifiers may modify any attribute of a buffer import, including
2271 * but not limited to adding extra planes to a format which
2272 * otherwise does not have those planes. As an example, a modifier
2273 * may add a plane for an external compression buffer to a
2274 * single-plane format. The exact meaning and effect of any
2275 * modifier is canonically defined by drm_fourcc.h, not as part of
2278 if (attrs
->DMABufPlaneModifiersLo
[i
].IsPresent
&&
2279 attrs
->DMABufPlaneModifiersHi
[i
].IsPresent
) {
2287 * "* If <target> is EGL_LINUX_DMA_BUF_EXT, and the list of attributes is
2288 * incomplete, EGL_BAD_PARAMETER is generated."
2290 for (unsigned i
= 0; i
< plane_n
; ++i
) {
2291 if (!attrs
->DMABufPlaneFds
[i
].IsPresent
||
2292 !attrs
->DMABufPlaneOffsets
[i
].IsPresent
||
2293 !attrs
->DMABufPlanePitches
[i
].IsPresent
) {
2294 _eglError(EGL_BAD_PARAMETER
, "plane attribute(s) missing");
2300 * The spec also says:
2302 * "If <target> is EGL_LINUX_DMA_BUF_EXT, and the EGL_LINUX_DRM_FOURCC_EXT
2303 * attribute indicates a single-plane format, EGL_BAD_ATTRIBUTE is
2304 * generated if any of the EGL_DMA_BUF_PLANE1_* or EGL_DMA_BUF_PLANE2_*
2305 * or EGL_DMA_BUF_PLANE3_* attributes are specified."
2307 for (unsigned i
= plane_n
; i
< DMA_BUF_MAX_PLANES
; ++i
) {
2308 if (attrs
->DMABufPlaneFds
[i
].IsPresent
||
2309 attrs
->DMABufPlaneOffsets
[i
].IsPresent
||
2310 attrs
->DMABufPlanePitches
[i
].IsPresent
) {
2311 _eglError(EGL_BAD_ATTRIBUTE
, "too many plane attributes");
2320 dri2_query_dma_buf_formats(_EGLDriver
*drv
, _EGLDisplay
*disp
,
2321 EGLint max
, EGLint
*formats
, EGLint
*count
)
2323 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2324 if (max
< 0 || (max
> 0 && formats
== NULL
))
2325 return _eglError(EGL_BAD_PARAMETER
, "invalid value for max count of formats");
2327 if (dri2_dpy
->image
->base
.version
< 15 ||
2328 dri2_dpy
->image
->queryDmaBufFormats
== NULL
)
2331 if (!dri2_dpy
->image
->queryDmaBufFormats(dri2_dpy
->dri_screen
, max
,
2339 dri2_query_dma_buf_modifiers(_EGLDriver
*drv
, _EGLDisplay
*disp
, EGLint format
,
2340 EGLint max
, EGLuint64KHR
*modifiers
,
2341 EGLBoolean
*external_only
, EGLint
*count
)
2343 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2346 return _eglError(EGL_BAD_PARAMETER
, "invalid value for max count of formats");
2348 if (max
> 0 && modifiers
== NULL
)
2349 return _eglError(EGL_BAD_PARAMETER
, "invalid modifiers array");
2351 if (dri2_dpy
->image
->base
.version
< 15 ||
2352 dri2_dpy
->image
->queryDmaBufModifiers
== NULL
)
2355 if (dri2_dpy
->image
->queryDmaBufModifiers(dri2_dpy
->dri_screen
, format
,
2357 (unsigned int *) external_only
,
2359 return _eglError(EGL_BAD_PARAMETER
, "invalid format");
2367 * "If eglCreateImageKHR is successful for a EGL_LINUX_DMA_BUF_EXT target, the
2368 * EGL will take a reference to the dma_buf(s) which it will release at any
2369 * time while the EGLDisplay is initialized. It is the responsibility of the
2370 * application to close the dma_buf file descriptors."
2372 * Therefore we must never close or otherwise modify the file descriptors.
2375 dri2_create_image_dma_buf(_EGLDisplay
*disp
, _EGLContext
*ctx
,
2376 EGLClientBuffer buffer
, const EGLint
*attr_list
)
2378 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2380 _EGLImageAttribs attrs
;
2381 __DRIimage
*dri_image
;
2383 int fds
[DMA_BUF_MAX_PLANES
];
2384 int pitches
[DMA_BUF_MAX_PLANES
];
2385 int offsets
[DMA_BUF_MAX_PLANES
];
2387 bool has_modifier
= false;
2393 * ""* If <target> is EGL_LINUX_DMA_BUF_EXT and <buffer> is not NULL, the
2394 * error EGL_BAD_PARAMETER is generated."
2396 if (buffer
!= NULL
) {
2397 _eglError(EGL_BAD_PARAMETER
, "buffer not NULL");
2401 if (!_eglParseImageAttribList(&attrs
, disp
, attr_list
))
2404 if (!dri2_check_dma_buf_attribs(&attrs
))
2407 num_fds
= dri2_check_dma_buf_format(&attrs
);
2411 for (unsigned i
= 0; i
< num_fds
; ++i
) {
2412 fds
[i
] = attrs
.DMABufPlaneFds
[i
].Value
;
2413 pitches
[i
] = attrs
.DMABufPlanePitches
[i
].Value
;
2414 offsets
[i
] = attrs
.DMABufPlaneOffsets
[i
].Value
;
2417 /* dri2_check_dma_buf_attribs ensures that the modifier, if available,
2418 * will be present in attrs.DMABufPlaneModifiersLo[0] and
2419 * attrs.DMABufPlaneModifiersHi[0] */
2420 if (attrs
.DMABufPlaneModifiersLo
[0].IsPresent
) {
2421 modifier
= (uint64_t) attrs
.DMABufPlaneModifiersHi
[0].Value
<< 32;
2422 modifier
|= (uint64_t) (attrs
.DMABufPlaneModifiersLo
[0].Value
& 0xffffffff);
2423 has_modifier
= true;
2427 if (dri2_dpy
->image
->base
.version
< 15 ||
2428 dri2_dpy
->image
->createImageFromDmaBufs2
== NULL
) {
2429 _eglError(EGL_BAD_MATCH
, "unsupported dma_buf format modifier");
2430 return EGL_NO_IMAGE_KHR
;
2433 dri2_dpy
->image
->createImageFromDmaBufs2(dri2_dpy
->dri_screen
,
2434 attrs
.Width
, attrs
.Height
, attrs
.DMABufFourCC
.Value
,
2435 modifier
, fds
, num_fds
, pitches
, offsets
,
2436 attrs
.DMABufYuvColorSpaceHint
.Value
,
2437 attrs
.DMABufSampleRangeHint
.Value
,
2438 attrs
.DMABufChromaHorizontalSiting
.Value
,
2439 attrs
.DMABufChromaVerticalSiting
.Value
,
2445 dri2_dpy
->image
->createImageFromDmaBufs(dri2_dpy
->dri_screen
,
2446 attrs
.Width
, attrs
.Height
, attrs
.DMABufFourCC
.Value
,
2447 fds
, num_fds
, pitches
, offsets
,
2448 attrs
.DMABufYuvColorSpaceHint
.Value
,
2449 attrs
.DMABufSampleRangeHint
.Value
,
2450 attrs
.DMABufChromaHorizontalSiting
.Value
,
2451 attrs
.DMABufChromaVerticalSiting
.Value
,
2455 dri2_create_image_khr_texture_error(error
);
2458 return EGL_NO_IMAGE_KHR
;
2460 res
= dri2_create_image_from_dri(disp
, dri_image
);
2465 dri2_create_drm_image_mesa(_EGLDriver
*drv
, _EGLDisplay
*disp
,
2466 const EGLint
*attr_list
)
2468 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2469 struct dri2_egl_image
*dri2_img
;
2470 _EGLImageAttribs attrs
;
2471 unsigned int dri_use
, valid_mask
;
2477 _eglError(EGL_BAD_PARAMETER
, __func__
);
2478 return EGL_NO_IMAGE_KHR
;
2481 if (!_eglParseImageAttribList(&attrs
, disp
, attr_list
))
2482 return EGL_NO_IMAGE_KHR
;
2484 if (attrs
.Width
<= 0 || attrs
.Height
<= 0) {
2485 _eglError(EGL_BAD_PARAMETER
, __func__
);
2486 return EGL_NO_IMAGE_KHR
;
2489 switch (attrs
.DRMBufferFormatMESA
) {
2490 case EGL_DRM_BUFFER_FORMAT_ARGB32_MESA
:
2491 format
= __DRI_IMAGE_FORMAT_ARGB8888
;
2494 _eglError(EGL_BAD_PARAMETER
, __func__
);
2495 return EGL_NO_IMAGE_KHR
;
2499 EGL_DRM_BUFFER_USE_SCANOUT_MESA
|
2500 EGL_DRM_BUFFER_USE_SHARE_MESA
|
2501 EGL_DRM_BUFFER_USE_CURSOR_MESA
;
2502 if (attrs
.DRMBufferUseMESA
& ~valid_mask
) {
2503 _eglError(EGL_BAD_PARAMETER
, __func__
);
2504 return EGL_NO_IMAGE_KHR
;
2508 if (attrs
.DRMBufferUseMESA
& EGL_DRM_BUFFER_USE_SHARE_MESA
)
2509 dri_use
|= __DRI_IMAGE_USE_SHARE
;
2510 if (attrs
.DRMBufferUseMESA
& EGL_DRM_BUFFER_USE_SCANOUT_MESA
)
2511 dri_use
|= __DRI_IMAGE_USE_SCANOUT
;
2512 if (attrs
.DRMBufferUseMESA
& EGL_DRM_BUFFER_USE_CURSOR_MESA
)
2513 dri_use
|= __DRI_IMAGE_USE_CURSOR
;
2515 dri2_img
= malloc(sizeof *dri2_img
);
2517 _eglError(EGL_BAD_ALLOC
, "dri2_create_image_khr");
2518 return EGL_NO_IMAGE_KHR
;
2521 _eglInitImage(&dri2_img
->base
, disp
);
2523 dri2_img
->dri_image
=
2524 dri2_dpy
->image
->createImage(dri2_dpy
->dri_screen
,
2525 attrs
.Width
, attrs
.Height
,
2526 format
, dri_use
, dri2_img
);
2527 if (dri2_img
->dri_image
== NULL
) {
2529 _eglError(EGL_BAD_ALLOC
, "dri2_create_drm_image_mesa");
2530 return EGL_NO_IMAGE_KHR
;
2533 return &dri2_img
->base
;
2537 dri2_export_drm_image_mesa(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLImage
*img
,
2538 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
2540 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2541 struct dri2_egl_image
*dri2_img
= dri2_egl_image(img
);
2545 if (name
&& !dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2546 __DRI_IMAGE_ATTRIB_NAME
, name
))
2547 return _eglError(EGL_BAD_ALLOC
, "dri2_export_drm_image_mesa");
2550 dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2551 __DRI_IMAGE_ATTRIB_HANDLE
, handle
);
2554 dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2555 __DRI_IMAGE_ATTRIB_STRIDE
, stride
);
2561 dri2_export_dma_buf_image_query_mesa(_EGLDriver
*drv
, _EGLDisplay
*disp
,
2563 EGLint
*fourcc
, EGLint
*nplanes
,
2564 EGLuint64KHR
*modifiers
)
2566 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2567 struct dri2_egl_image
*dri2_img
= dri2_egl_image(img
);
2573 dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2574 __DRI_IMAGE_ATTRIB_NUM_PLANES
, nplanes
);
2576 dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2577 __DRI_IMAGE_ATTRIB_FOURCC
, fourcc
);
2586 dri2_export_dma_buf_image_mesa(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLImage
*img
,
2587 int *fds
, EGLint
*strides
, EGLint
*offsets
)
2589 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2590 struct dri2_egl_image
*dri2_img
= dri2_egl_image(img
);
2594 /* rework later to provide multiple fds/strides/offsets */
2596 dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2597 __DRI_IMAGE_ATTRIB_FD
, fds
);
2600 dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2601 __DRI_IMAGE_ATTRIB_STRIDE
, strides
);
2605 bool ret
= dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2606 __DRI_IMAGE_ATTRIB_OFFSET
, &img_offset
);
2608 offsets
[0] = img_offset
;
2619 dri2_create_image_khr(_EGLDriver
*drv
, _EGLDisplay
*disp
,
2620 _EGLContext
*ctx
, EGLenum target
,
2621 EGLClientBuffer buffer
, const EGLint
*attr_list
)
2626 case EGL_GL_TEXTURE_2D_KHR
:
2627 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR
:
2628 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR
:
2629 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR
:
2630 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR
:
2631 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR
:
2632 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR
:
2633 case EGL_GL_TEXTURE_3D_KHR
:
2634 return dri2_create_image_khr_texture(disp
, ctx
, target
, buffer
, attr_list
);
2635 case EGL_GL_RENDERBUFFER_KHR
:
2636 return dri2_create_image_khr_renderbuffer(disp
, ctx
, buffer
, attr_list
);
2638 case EGL_DRM_BUFFER_MESA
:
2639 return dri2_create_image_mesa_drm_buffer(disp
, ctx
, buffer
, attr_list
);
2640 case EGL_LINUX_DMA_BUF_EXT
:
2641 return dri2_create_image_dma_buf(disp
, ctx
, buffer
, attr_list
);
2643 #ifdef HAVE_WAYLAND_PLATFORM
2644 case EGL_WAYLAND_BUFFER_WL
:
2645 return dri2_create_image_wayland_wl_buffer(disp
, ctx
, buffer
, attr_list
);
2648 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
2649 return EGL_NO_IMAGE_KHR
;
2654 dri2_destroy_image_khr(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLImage
*image
)
2656 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2657 struct dri2_egl_image
*dri2_img
= dri2_egl_image(image
);
2661 dri2_dpy
->image
->destroyImage(dri2_img
->dri_image
);
2667 #ifdef HAVE_WAYLAND_PLATFORM
2670 dri2_wl_reference_buffer(void *user_data
, uint32_t name
, int fd
,
2671 struct wl_drm_buffer
*buffer
)
2673 _EGLDisplay
*disp
= user_data
;
2674 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2676 int dri_components
= 0;
2679 img
= dri2_dpy
->image
->createImageFromNames(dri2_dpy
->dri_screen
,
2688 img
= dri2_dpy
->image
->createImageFromFds(dri2_dpy
->dri_screen
,
2700 dri2_dpy
->image
->queryImage(img
, __DRI_IMAGE_ATTRIB_COMPONENTS
, &dri_components
);
2702 buffer
->driver_format
= NULL
;
2703 for (int i
= 0; i
< ARRAY_SIZE(wl_drm_components
); i
++)
2704 if (wl_drm_components
[i
].dri_components
== dri_components
)
2705 buffer
->driver_format
= &wl_drm_components
[i
];
2707 if (buffer
->driver_format
== NULL
)
2708 dri2_dpy
->image
->destroyImage(img
);
2710 buffer
->driver_buffer
= img
;
2714 dri2_wl_release_buffer(void *user_data
, struct wl_drm_buffer
*buffer
)
2716 _EGLDisplay
*disp
= user_data
;
2717 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2719 dri2_dpy
->image
->destroyImage(buffer
->driver_buffer
);
2722 static struct wayland_drm_callbacks wl_drm_callbacks
= {
2723 .authenticate
= NULL
,
2724 .reference_buffer
= dri2_wl_reference_buffer
,
2725 .release_buffer
= dri2_wl_release_buffer
2729 dri2_bind_wayland_display_wl(_EGLDriver
*drv
, _EGLDisplay
*disp
,
2730 struct wl_display
*wl_dpy
)
2732 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2738 if (dri2_dpy
->wl_server_drm
)
2741 wl_drm_callbacks
.authenticate
=
2742 (int(*)(void *, uint32_t)) dri2_dpy
->vtbl
->authenticate
;
2744 if (drmGetCap(dri2_dpy
->fd
, DRM_CAP_PRIME
, &cap
) == 0 &&
2745 cap
== (DRM_PRIME_CAP_IMPORT
| DRM_PRIME_CAP_EXPORT
) &&
2746 dri2_dpy
->image
->base
.version
>= 7 &&
2747 dri2_dpy
->image
->createImageFromFds
!= NULL
)
2748 flags
|= WAYLAND_DRM_PRIME
;
2750 dri2_dpy
->wl_server_drm
=
2751 wayland_drm_init(wl_dpy
, dri2_dpy
->device_name
,
2752 &wl_drm_callbacks
, disp
, flags
);
2754 if (!dri2_dpy
->wl_server_drm
)
2757 #ifdef HAVE_DRM_PLATFORM
2758 /* We have to share the wl_drm instance with gbm, so gbm can convert
2759 * wl_buffers to gbm bos. */
2760 if (dri2_dpy
->gbm_dri
)
2761 dri2_dpy
->gbm_dri
->wl_drm
= dri2_dpy
->wl_server_drm
;
2768 dri2_unbind_wayland_display_wl(_EGLDriver
*drv
, _EGLDisplay
*disp
,
2769 struct wl_display
*wl_dpy
)
2771 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2775 if (!dri2_dpy
->wl_server_drm
)
2778 wayland_drm_uninit(dri2_dpy
->wl_server_drm
);
2779 dri2_dpy
->wl_server_drm
= NULL
;
2785 dri2_query_wayland_buffer_wl(_EGLDriver
*drv
, _EGLDisplay
*disp
,
2786 struct wl_resource
*buffer_resource
,
2787 EGLint attribute
, EGLint
*value
)
2789 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2790 struct wl_drm_buffer
*buffer
;
2791 const struct wl_drm_components_descriptor
*format
;
2793 buffer
= wayland_drm_buffer_get(dri2_dpy
->wl_server_drm
, buffer_resource
);
2797 format
= buffer
->driver_format
;
2798 switch (attribute
) {
2799 case EGL_TEXTURE_FORMAT
:
2800 *value
= format
->components
;
2803 *value
= buffer
->width
;
2806 *value
= buffer
->height
;
2815 dri2_egl_ref_sync(struct dri2_egl_sync
*sync
)
2817 p_atomic_inc(&sync
->refcount
);
2821 dri2_egl_unref_sync(struct dri2_egl_display
*dri2_dpy
,
2822 struct dri2_egl_sync
*dri2_sync
)
2824 if (p_atomic_dec_zero(&dri2_sync
->refcount
)) {
2825 switch (dri2_sync
->base
.Type
) {
2826 case EGL_SYNC_REUSABLE_KHR
:
2827 cnd_destroy(&dri2_sync
->cond
);
2829 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
2830 if (dri2_sync
->base
.SyncFd
!= EGL_NO_NATIVE_FENCE_FD_ANDROID
)
2831 close(dri2_sync
->base
.SyncFd
);
2837 if (dri2_sync
->fence
)
2838 dri2_dpy
->fence
->destroy_fence(dri2_dpy
->dri_screen
, dri2_sync
->fence
);
2845 dri2_create_sync(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
2846 EGLenum type
, const EGLAttrib
*attrib_list
)
2848 _EGLContext
*ctx
= _eglGetCurrentContext();
2849 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
2850 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
2851 struct dri2_egl_sync
*dri2_sync
;
2853 pthread_condattr_t attr
;
2855 dri2_sync
= calloc(1, sizeof(struct dri2_egl_sync
));
2857 _eglError(EGL_BAD_ALLOC
, "eglCreateSyncKHR");
2861 if (!_eglInitSync(&dri2_sync
->base
, dpy
, type
, attrib_list
)) {
2867 case EGL_SYNC_FENCE_KHR
:
2868 dri2_sync
->fence
= dri2_dpy
->fence
->create_fence(dri2_ctx
->dri_context
);
2869 if (!dri2_sync
->fence
) {
2870 /* Why did it fail? DRI doesn't return an error code, so we emit
2871 * a generic EGL error that doesn't communicate user error.
2873 _eglError(EGL_BAD_ALLOC
, "eglCreateSyncKHR");
2879 case EGL_SYNC_CL_EVENT_KHR
:
2880 dri2_sync
->fence
= dri2_dpy
->fence
->get_fence_from_cl_event(
2881 dri2_dpy
->dri_screen
,
2882 dri2_sync
->base
.CLEvent
);
2883 /* this can only happen if the cl_event passed in is invalid. */
2884 if (!dri2_sync
->fence
) {
2885 _eglError(EGL_BAD_ATTRIBUTE
, "eglCreateSyncKHR");
2890 /* the initial status must be "signaled" if the cl_event is signaled */
2891 if (dri2_dpy
->fence
->client_wait_sync(dri2_ctx
->dri_context
,
2892 dri2_sync
->fence
, 0, 0))
2893 dri2_sync
->base
.SyncStatus
= EGL_SIGNALED_KHR
;
2896 case EGL_SYNC_REUSABLE_KHR
:
2897 /* intialize attr */
2898 ret
= pthread_condattr_init(&attr
);
2901 _eglError(EGL_BAD_ACCESS
, "eglCreateSyncKHR");
2906 /* change clock attribute to CLOCK_MONOTONIC */
2907 ret
= pthread_condattr_setclock(&attr
, CLOCK_MONOTONIC
);
2910 _eglError(EGL_BAD_ACCESS
, "eglCreateSyncKHR");
2915 ret
= pthread_cond_init(&dri2_sync
->cond
, &attr
);
2918 _eglError(EGL_BAD_ACCESS
, "eglCreateSyncKHR");
2923 /* initial status of reusable sync must be "unsignaled" */
2924 dri2_sync
->base
.SyncStatus
= EGL_UNSIGNALED_KHR
;
2927 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
2928 if (dri2_dpy
->fence
->create_fence_fd
) {
2929 dri2_sync
->fence
= dri2_dpy
->fence
->create_fence_fd(
2930 dri2_ctx
->dri_context
,
2931 dri2_sync
->base
.SyncFd
);
2933 if (!dri2_sync
->fence
) {
2934 _eglError(EGL_BAD_ATTRIBUTE
, "eglCreateSyncKHR");
2941 p_atomic_set(&dri2_sync
->refcount
, 1);
2942 return &dri2_sync
->base
;
2946 dri2_destroy_sync(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSync
*sync
)
2948 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
2949 struct dri2_egl_sync
*dri2_sync
= dri2_egl_sync(sync
);
2950 EGLint ret
= EGL_TRUE
;
2953 /* if type of sync is EGL_SYNC_REUSABLE_KHR and it is not signaled yet,
2954 * then unlock all threads possibly blocked by the reusable sync before
2957 if (dri2_sync
->base
.Type
== EGL_SYNC_REUSABLE_KHR
&&
2958 dri2_sync
->base
.SyncStatus
== EGL_UNSIGNALED_KHR
) {
2959 dri2_sync
->base
.SyncStatus
= EGL_SIGNALED_KHR
;
2960 /* unblock all threads currently blocked by sync */
2961 err
= cnd_broadcast(&dri2_sync
->cond
);
2964 _eglError(EGL_BAD_ACCESS
, "eglDestroySyncKHR");
2969 dri2_egl_unref_sync(dri2_dpy
, dri2_sync
);
2975 dri2_dup_native_fence_fd(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSync
*sync
)
2977 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
2978 struct dri2_egl_sync
*dri2_sync
= dri2_egl_sync(sync
);
2980 assert(sync
->Type
== EGL_SYNC_NATIVE_FENCE_ANDROID
);
2982 if (sync
->SyncFd
== EGL_NO_NATIVE_FENCE_FD_ANDROID
) {
2983 /* try to retrieve the actual native fence fd.. if rendering is
2984 * not flushed this will just return -1, aka NO_NATIVE_FENCE_FD:
2986 sync
->SyncFd
= dri2_dpy
->fence
->get_fence_fd(dri2_dpy
->dri_screen
,
2990 if (sync
->SyncFd
== EGL_NO_NATIVE_FENCE_FD_ANDROID
) {
2991 /* if native fence fd still not created, return an error: */
2992 _eglError(EGL_BAD_PARAMETER
, "eglDupNativeFenceFDANDROID");
2993 return EGL_NO_NATIVE_FENCE_FD_ANDROID
;
2996 return dup(sync
->SyncFd
);
3000 dri2_client_wait_sync(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSync
*sync
,
3001 EGLint flags
, EGLTime timeout
)
3003 _EGLContext
*ctx
= _eglGetCurrentContext();
3004 struct dri2_egl_driver
*dri2_drv
= dri2_egl_driver(drv
);
3005 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
3006 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
3007 struct dri2_egl_sync
*dri2_sync
= dri2_egl_sync(sync
);
3008 unsigned wait_flags
= 0;
3010 /* timespecs for cnd_timedwait */
3011 struct timespec current
;
3014 EGLint ret
= EGL_CONDITION_SATISFIED_KHR
;
3016 /* The EGL_KHR_fence_sync spec states:
3018 * "If no context is current for the bound API,
3019 * the EGL_SYNC_FLUSH_COMMANDS_BIT_KHR bit is ignored.
3021 if (dri2_ctx
&& flags
& EGL_SYNC_FLUSH_COMMANDS_BIT_KHR
)
3022 wait_flags
|= __DRI2_FENCE_FLAG_FLUSH_COMMANDS
;
3024 /* the sync object should take a reference while waiting */
3025 dri2_egl_ref_sync(dri2_sync
);
3027 switch (sync
->Type
) {
3028 case EGL_SYNC_FENCE_KHR
:
3029 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
3030 case EGL_SYNC_CL_EVENT_KHR
:
3031 if (dri2_dpy
->fence
->client_wait_sync(dri2_ctx
? dri2_ctx
->dri_context
: NULL
,
3032 dri2_sync
->fence
, wait_flags
,
3034 dri2_sync
->base
.SyncStatus
= EGL_SIGNALED_KHR
;
3036 ret
= EGL_TIMEOUT_EXPIRED_KHR
;
3039 case EGL_SYNC_REUSABLE_KHR
:
3040 if (dri2_ctx
&& dri2_sync
->base
.SyncStatus
== EGL_UNSIGNALED_KHR
&&
3041 (flags
& EGL_SYNC_FLUSH_COMMANDS_BIT_KHR
)) {
3042 /* flush context if EGL_SYNC_FLUSH_COMMANDS_BIT_KHR is set */
3043 dri2_drv
->glFlush();
3046 /* if timeout is EGL_FOREVER_KHR, it should wait without any timeout.*/
3047 if (timeout
== EGL_FOREVER_KHR
) {
3048 mtx_lock(&dri2_sync
->mutex
);
3049 cnd_wait(&dri2_sync
->cond
, &dri2_sync
->mutex
);
3050 mtx_unlock(&dri2_sync
->mutex
);
3052 /* if reusable sync has not been yet signaled */
3053 if (dri2_sync
->base
.SyncStatus
!= EGL_SIGNALED_KHR
) {
3054 clock_gettime(CLOCK_MONOTONIC
, ¤t
);
3056 /* calculating when to expire */
3057 expire
.nsec
= timeout
% 1000000000L;
3058 expire
.sec
= timeout
/ 1000000000L;
3060 expire
.nsec
+= current
.tv_nsec
;
3061 expire
.sec
+= current
.tv_sec
;
3063 /* expire.nsec now is a number between 0 and 1999999998 */
3064 if (expire
.nsec
> 999999999L) {
3066 expire
.nsec
-= 1000000000L;
3069 mtx_lock(&dri2_sync
->mutex
);
3070 ret
= cnd_timedwait(&dri2_sync
->cond
, &dri2_sync
->mutex
, &expire
);
3071 mtx_unlock(&dri2_sync
->mutex
);
3073 if (ret
== thrd_busy
) {
3074 if (dri2_sync
->base
.SyncStatus
== EGL_UNSIGNALED_KHR
) {
3075 ret
= EGL_TIMEOUT_EXPIRED_KHR
;
3077 _eglError(EGL_BAD_ACCESS
, "eglClientWaitSyncKHR");
3085 dri2_egl_unref_sync(dri2_dpy
, dri2_sync
);
3091 dri2_signal_sync(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSync
*sync
,
3094 struct dri2_egl_sync
*dri2_sync
= dri2_egl_sync(sync
);
3097 if (sync
->Type
!= EGL_SYNC_REUSABLE_KHR
)
3098 return _eglError(EGL_BAD_MATCH
, "eglSignalSyncKHR");
3100 if (mode
!= EGL_SIGNALED_KHR
&& mode
!= EGL_UNSIGNALED_KHR
)
3101 return _eglError(EGL_BAD_ATTRIBUTE
, "eglSignalSyncKHR");
3103 dri2_sync
->base
.SyncStatus
= mode
;
3105 if (mode
== EGL_SIGNALED_KHR
) {
3106 ret
= cnd_broadcast(&dri2_sync
->cond
);
3108 /* fail to broadcast */
3110 return _eglError(EGL_BAD_ACCESS
, "eglSignalSyncKHR");
3117 dri2_server_wait_sync(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSync
*sync
)
3119 _EGLContext
*ctx
= _eglGetCurrentContext();
3120 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
3121 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
3122 struct dri2_egl_sync
*dri2_sync
= dri2_egl_sync(sync
);
3124 dri2_dpy
->fence
->server_wait_sync(dri2_ctx
->dri_context
,
3125 dri2_sync
->fence
, 0);
3130 dri2_interop_query_device_info(_EGLDisplay
*dpy
, _EGLContext
*ctx
,
3131 struct mesa_glinterop_device_info
*out
)
3133 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
3134 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
3136 if (!dri2_dpy
->interop
)
3137 return MESA_GLINTEROP_UNSUPPORTED
;
3139 return dri2_dpy
->interop
->query_device_info(dri2_ctx
->dri_context
, out
);
3143 dri2_interop_export_object(_EGLDisplay
*dpy
, _EGLContext
*ctx
,
3144 struct mesa_glinterop_export_in
*in
,
3145 struct mesa_glinterop_export_out
*out
)
3147 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
3148 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
3150 if (!dri2_dpy
->interop
)
3151 return MESA_GLINTEROP_UNSUPPORTED
;
3153 return dri2_dpy
->interop
->export_object(dri2_ctx
->dri_context
, in
, out
);
3157 dri2_unload(_EGLDriver
*drv
)
3159 struct dri2_egl_driver
*dri2_drv
= dri2_egl_driver(drv
);
3161 dlclose(dri2_drv
->handle
);
3166 dri2_load(_EGLDriver
*drv
)
3168 struct dri2_egl_driver
*dri2_drv
= dri2_egl_driver(drv
);
3169 #ifdef HAVE_ANDROID_PLATFORM
3170 const char *libname
= "libglapi.so";
3171 #elif defined(__APPLE__)
3172 const char *libname
= "libglapi.0.dylib";
3173 #elif defined(__CYGWIN__)
3174 const char *libname
= "cygglapi-0.dll";
3176 const char *libname
= "libglapi.so.0";
3180 /* RTLD_GLOBAL to make sure glapi symbols are visible to DRI drivers */
3181 handle
= dlopen(libname
, RTLD_LAZY
| RTLD_GLOBAL
);
3183 _eglLog(_EGL_WARNING
, "DRI2: failed to open glapi provider");
3187 dri2_drv
->get_proc_address
= (_EGLProc (*)(const char *))
3188 dlsym(handle
, "_glapi_get_proc_address");
3190 /* if glapi is not available, loading DRI drivers will fail */
3191 if (!dri2_drv
->get_proc_address
) {
3192 _eglLog(_EGL_WARNING
, "DRI2: failed to find _glapi_get_proc_address");
3196 dri2_drv
->glFlush
= (void (*)(void))
3197 dri2_drv
->get_proc_address("glFlush");
3199 /* if glFlush is not available things are horribly broken */
3200 if (!dri2_drv
->glFlush
) {
3201 _eglLog(_EGL_WARNING
, "DRI2: failed to find glFlush entry point");
3205 dri2_drv
->handle
= handle
;
3215 * This is the main entrypoint into the driver, called by libEGL.
3216 * Create a new _EGLDriver object and init its dispatch table.
3219 _eglBuiltInDriverDRI2(const char *args
)
3221 struct dri2_egl_driver
*dri2_drv
;
3225 dri2_drv
= calloc(1, sizeof *dri2_drv
);
3229 if (!dri2_load(&dri2_drv
->base
)) {
3234 _eglInitDriverFallbacks(&dri2_drv
->base
);
3235 dri2_drv
->base
.API
.Initialize
= dri2_initialize
;
3236 dri2_drv
->base
.API
.Terminate
= dri2_terminate
;
3237 dri2_drv
->base
.API
.CreateContext
= dri2_create_context
;
3238 dri2_drv
->base
.API
.DestroyContext
= dri2_destroy_context
;
3239 dri2_drv
->base
.API
.MakeCurrent
= dri2_make_current
;
3240 dri2_drv
->base
.API
.CreateWindowSurface
= dri2_create_window_surface
;
3241 dri2_drv
->base
.API
.CreatePixmapSurface
= dri2_create_pixmap_surface
;
3242 dri2_drv
->base
.API
.CreatePbufferSurface
= dri2_create_pbuffer_surface
;
3243 dri2_drv
->base
.API
.DestroySurface
= dri2_destroy_surface
;
3244 dri2_drv
->base
.API
.GetProcAddress
= dri2_get_proc_address
;
3245 dri2_drv
->base
.API
.WaitClient
= dri2_wait_client
;
3246 dri2_drv
->base
.API
.WaitNative
= dri2_wait_native
;
3247 dri2_drv
->base
.API
.BindTexImage
= dri2_bind_tex_image
;
3248 dri2_drv
->base
.API
.ReleaseTexImage
= dri2_release_tex_image
;
3249 dri2_drv
->base
.API
.SwapInterval
= dri2_swap_interval
;
3250 dri2_drv
->base
.API
.SwapBuffers
= dri2_swap_buffers
;
3251 dri2_drv
->base
.API
.SwapBuffersWithDamageEXT
= dri2_swap_buffers_with_damage
;
3252 dri2_drv
->base
.API
.SwapBuffersRegionNOK
= dri2_swap_buffers_region
;
3253 dri2_drv
->base
.API
.SetDamageRegion
= dri2_set_damage_region
;
3254 dri2_drv
->base
.API
.PostSubBufferNV
= dri2_post_sub_buffer
;
3255 dri2_drv
->base
.API
.CopyBuffers
= dri2_copy_buffers
,
3256 dri2_drv
->base
.API
.QueryBufferAge
= dri2_query_buffer_age
;
3257 dri2_drv
->base
.API
.CreateImageKHR
= dri2_create_image
;
3258 dri2_drv
->base
.API
.DestroyImageKHR
= dri2_destroy_image_khr
;
3259 dri2_drv
->base
.API
.CreateWaylandBufferFromImageWL
= dri2_create_wayland_buffer_from_image
;
3260 dri2_drv
->base
.API
.QuerySurface
= dri2_query_surface
;
3262 dri2_drv
->base
.API
.CreateDRMImageMESA
= dri2_create_drm_image_mesa
;
3263 dri2_drv
->base
.API
.ExportDRMImageMESA
= dri2_export_drm_image_mesa
;
3264 dri2_drv
->base
.API
.ExportDMABUFImageQueryMESA
= dri2_export_dma_buf_image_query_mesa
;
3265 dri2_drv
->base
.API
.ExportDMABUFImageMESA
= dri2_export_dma_buf_image_mesa
;
3266 dri2_drv
->base
.API
.QueryDmaBufFormatsEXT
= dri2_query_dma_buf_formats
;
3267 dri2_drv
->base
.API
.QueryDmaBufModifiersEXT
= dri2_query_dma_buf_modifiers
;
3269 #ifdef HAVE_WAYLAND_PLATFORM
3270 dri2_drv
->base
.API
.BindWaylandDisplayWL
= dri2_bind_wayland_display_wl
;
3271 dri2_drv
->base
.API
.UnbindWaylandDisplayWL
= dri2_unbind_wayland_display_wl
;
3272 dri2_drv
->base
.API
.QueryWaylandBufferWL
= dri2_query_wayland_buffer_wl
;
3274 dri2_drv
->base
.API
.GetSyncValuesCHROMIUM
= dri2_get_sync_values_chromium
;
3275 dri2_drv
->base
.API
.CreateSyncKHR
= dri2_create_sync
;
3276 dri2_drv
->base
.API
.ClientWaitSyncKHR
= dri2_client_wait_sync
;
3277 dri2_drv
->base
.API
.SignalSyncKHR
= dri2_signal_sync
;
3278 dri2_drv
->base
.API
.WaitSyncKHR
= dri2_server_wait_sync
;
3279 dri2_drv
->base
.API
.DestroySyncKHR
= dri2_destroy_sync
;
3280 dri2_drv
->base
.API
.GLInteropQueryDeviceInfo
= dri2_interop_query_device_info
;
3281 dri2_drv
->base
.API
.GLInteropExportObject
= dri2_interop_export_object
;
3282 dri2_drv
->base
.API
.DupNativeFenceFDANDROID
= dri2_dup_native_fence_fd
;
3284 dri2_drv
->base
.Name
= "DRI2";
3285 dri2_drv
->base
.Unload
= dri2_unload
;
3287 return &dri2_drv
->base
;