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-drm.h"
52 #include "wayland-drm-client-protocol.h"
53 #include "linux-dmabuf-unstable-v1-client-protocol.h"
56 #ifdef HAVE_X11_PLATFORM
57 #include "X11/Xlibint.h"
61 #include "GL/mesa_glinterop.h"
62 #include "loader/loader.h"
63 #include "util/u_atomic.h"
64 #include "util/u_vector.h"
65 #include "mapi/glapi/glapi.h"
67 /* The kernel header drm_fourcc.h defines the DRM formats below. We duplicate
68 * some of the definitions here so that building Mesa won't bleeding-edge
72 #define DRM_FORMAT_R8 fourcc_code('R', '8', ' ', ' ') /* [7:0] R */
75 #ifndef DRM_FORMAT_RG88
76 #define DRM_FORMAT_RG88 fourcc_code('R', 'G', '8', '8') /* [15:0] R:G 8:8 little endian */
79 #ifndef DRM_FORMAT_GR88
80 #define DRM_FORMAT_GR88 fourcc_code('G', 'R', '8', '8') /* [15:0] G:R 8:8 little endian */
83 #ifndef DRM_FORMAT_R16
84 #define DRM_FORMAT_R16 fourcc_code('R', '1', '6', ' ') /* [15:0] R 16 little endian */
87 #ifndef DRM_FORMAT_GR1616
88 #define DRM_FORMAT_GR1616 fourcc_code('G', 'R', '3', '2') /* [31:0] R:G 16:16 little endian */
91 #ifndef DRM_FORMAT_MOD_INVALID
92 #define DRM_FORMAT_MOD_INVALID ((1ULL<<56) - 1)
95 #define NUM_ATTRIBS 12
98 dri_set_background_context(void *loaderPrivate
)
100 _EGLContext
*ctx
= _eglGetCurrentContext();
101 _EGLThreadInfo
*t
= _eglGetCurrentThread();
103 _eglBindContextToThread(ctx
, t
);
109 static void (*glFlush
)(void);
110 static mtx_t glFlushMutex
= _MTX_INITIALIZER_NP
;
112 mtx_lock(&glFlushMutex
);
114 glFlush
= _glapi_get_proc_address("glFlush");
115 mtx_unlock(&glFlushMutex
);
117 /* if glFlush is not available things are horribly broken */
119 _eglLog(_EGL_WARNING
, "DRI2: failed to find glFlush entry point");
127 dri_is_thread_safe(void *loaderPrivate
)
129 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
130 _EGLDisplay
*display
= dri2_surf
->base
.Resource
.Display
;
132 #ifdef HAVE_X11_PLATFORM
133 Display
*xdpy
= (Display
*)display
->PlatformDisplay
;
135 /* Check Xlib is running in thread safe mode when running on EGL/X11-xlib
138 * 'lock_fns' is the XLockDisplay function pointer of the X11 display 'dpy'.
139 * It wll be NULL if XInitThreads wasn't called.
141 if (display
->Platform
== _EGL_PLATFORM_X11
&& xdpy
&& !xdpy
->lock_fns
)
145 #ifdef HAVE_WAYLAND_PLATFORM
146 if (display
->Platform
== _EGL_PLATFORM_WAYLAND
)
153 const __DRIbackgroundCallableExtension background_callable_extension
= {
154 .base
= { __DRI_BACKGROUND_CALLABLE
, 2 },
156 .setBackgroundContext
= dri_set_background_context
,
157 .isThreadSafe
= dri_is_thread_safe
,
160 const __DRIuseInvalidateExtension use_invalidate
= {
161 .base
= { __DRI_USE_INVALIDATE
, 1 }
164 static const EGLint dri2_to_egl_attribute_map
[__DRI_ATTRIB_MAX
] = {
165 [__DRI_ATTRIB_BUFFER_SIZE
] = EGL_BUFFER_SIZE
,
166 [__DRI_ATTRIB_LEVEL
] = EGL_LEVEL
,
167 [__DRI_ATTRIB_RED_SIZE
] = EGL_RED_SIZE
,
168 [__DRI_ATTRIB_GREEN_SIZE
] = EGL_GREEN_SIZE
,
169 [__DRI_ATTRIB_BLUE_SIZE
] = EGL_BLUE_SIZE
,
170 [__DRI_ATTRIB_LUMINANCE_SIZE
] = EGL_LUMINANCE_SIZE
,
171 [__DRI_ATTRIB_ALPHA_SIZE
] = EGL_ALPHA_SIZE
,
172 [__DRI_ATTRIB_DEPTH_SIZE
] = EGL_DEPTH_SIZE
,
173 [__DRI_ATTRIB_STENCIL_SIZE
] = EGL_STENCIL_SIZE
,
174 [__DRI_ATTRIB_SAMPLE_BUFFERS
] = EGL_SAMPLE_BUFFERS
,
175 [__DRI_ATTRIB_SAMPLES
] = EGL_SAMPLES
,
176 [__DRI_ATTRIB_MAX_PBUFFER_WIDTH
] = EGL_MAX_PBUFFER_WIDTH
,
177 [__DRI_ATTRIB_MAX_PBUFFER_HEIGHT
] = EGL_MAX_PBUFFER_HEIGHT
,
178 [__DRI_ATTRIB_MAX_PBUFFER_PIXELS
] = EGL_MAX_PBUFFER_PIXELS
,
179 [__DRI_ATTRIB_MAX_SWAP_INTERVAL
] = EGL_MAX_SWAP_INTERVAL
,
180 [__DRI_ATTRIB_MIN_SWAP_INTERVAL
] = EGL_MIN_SWAP_INTERVAL
,
181 [__DRI_ATTRIB_YINVERTED
] = EGL_Y_INVERTED_NOK
,
185 dri2_get_dri_config(struct dri2_egl_config
*conf
, EGLint surface_type
,
188 const bool double_buffer
= surface_type
== EGL_WINDOW_BIT
;
189 const bool srgb
= colorspace
== EGL_GL_COLORSPACE_SRGB_KHR
;
191 return conf
->dri_config
[double_buffer
][srgb
];
195 dri2_match_config(const _EGLConfig
*conf
, const _EGLConfig
*criteria
)
197 if (_eglCompareConfigs(conf
, criteria
, NULL
, EGL_FALSE
) != 0)
200 if (!_eglMatchConfig(conf
, criteria
))
206 struct dri2_egl_config
*
207 dri2_add_config(_EGLDisplay
*disp
, const __DRIconfig
*dri_config
, int id
,
208 EGLint surface_type
, const EGLint
*attr_list
,
209 const unsigned int *rgba_masks
)
211 struct dri2_egl_config
*conf
;
212 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
214 unsigned int attrib
, value
, double_buffer
;
216 EGLint key
, bind_to_texture_rgb
, bind_to_texture_rgba
;
217 unsigned int dri_masks
[4] = { 0, 0, 0, 0 };
218 _EGLConfig
*matching_config
;
219 EGLint num_configs
= 0;
222 _eglInitConfig(&base
, disp
, id
);
225 bind_to_texture_rgb
= 0;
226 bind_to_texture_rgba
= 0;
228 for (int i
= 0; dri2_dpy
->core
->indexConfigAttrib(dri_config
, i
, &attrib
,
231 case __DRI_ATTRIB_RENDER_TYPE
:
232 if (value
& __DRI_ATTRIB_RGBA_BIT
)
233 value
= EGL_RGB_BUFFER
;
234 else if (value
& __DRI_ATTRIB_LUMINANCE_BIT
)
235 value
= EGL_LUMINANCE_BUFFER
;
238 _eglSetConfigKey(&base
, EGL_COLOR_BUFFER_TYPE
, value
);
241 case __DRI_ATTRIB_CONFIG_CAVEAT
:
242 if (value
& __DRI_ATTRIB_NON_CONFORMANT_CONFIG
)
243 value
= EGL_NON_CONFORMANT_CONFIG
;
244 else if (value
& __DRI_ATTRIB_SLOW_BIT
)
245 value
= EGL_SLOW_CONFIG
;
248 _eglSetConfigKey(&base
, EGL_CONFIG_CAVEAT
, value
);
251 case __DRI_ATTRIB_BIND_TO_TEXTURE_RGB
:
252 bind_to_texture_rgb
= value
;
255 case __DRI_ATTRIB_BIND_TO_TEXTURE_RGBA
:
256 bind_to_texture_rgba
= value
;
259 case __DRI_ATTRIB_DOUBLE_BUFFER
:
260 double_buffer
= value
;
263 case __DRI_ATTRIB_RED_MASK
:
264 dri_masks
[0] = value
;
267 case __DRI_ATTRIB_GREEN_MASK
:
268 dri_masks
[1] = value
;
271 case __DRI_ATTRIB_BLUE_MASK
:
272 dri_masks
[2] = value
;
275 case __DRI_ATTRIB_ALPHA_MASK
:
276 dri_masks
[3] = value
;
279 case __DRI_ATTRIB_ACCUM_RED_SIZE
:
280 case __DRI_ATTRIB_ACCUM_GREEN_SIZE
:
281 case __DRI_ATTRIB_ACCUM_BLUE_SIZE
:
282 case __DRI_ATTRIB_ACCUM_ALPHA_SIZE
:
283 /* Don't expose visuals with the accumulation buffer. */
288 case __DRI_ATTRIB_FRAMEBUFFER_SRGB_CAPABLE
:
290 if (!disp
->Extensions
.KHR_gl_colorspace
&& srgb
)
294 case __DRI_ATTRIB_MAX_PBUFFER_WIDTH
:
295 _eglSetConfigKey(&base
, EGL_MAX_PBUFFER_WIDTH
,
296 _EGL_MAX_PBUFFER_WIDTH
);
298 case __DRI_ATTRIB_MAX_PBUFFER_HEIGHT
:
299 _eglSetConfigKey(&base
, EGL_MAX_PBUFFER_HEIGHT
,
300 _EGL_MAX_PBUFFER_HEIGHT
);
304 key
= dri2_to_egl_attribute_map
[attrib
];
306 _eglSetConfigKey(&base
, key
, value
);
312 for (int i
= 0; attr_list
[i
] != EGL_NONE
; i
+= 2)
313 _eglSetConfigKey(&base
, attr_list
[i
], attr_list
[i
+1]);
315 if (rgba_masks
&& memcmp(rgba_masks
, dri_masks
, sizeof(dri_masks
)))
318 base
.NativeRenderable
= EGL_TRUE
;
320 base
.SurfaceType
= surface_type
;
321 if (surface_type
& (EGL_PBUFFER_BIT
|
322 (disp
->Extensions
.NOK_texture_from_pixmap
? EGL_PIXMAP_BIT
: 0))) {
323 base
.BindToTextureRGB
= bind_to_texture_rgb
;
324 if (base
.AlphaSize
> 0)
325 base
.BindToTextureRGBA
= bind_to_texture_rgba
;
328 base
.RenderableType
= disp
->ClientAPIs
;
329 base
.Conformant
= disp
->ClientAPIs
;
331 base
.MinSwapInterval
= dri2_dpy
->min_swap_interval
;
332 base
.MaxSwapInterval
= dri2_dpy
->max_swap_interval
;
334 if (!_eglValidateConfig(&base
, EGL_FALSE
)) {
335 _eglLog(_EGL_DEBUG
, "DRI2: failed to validate config %d", id
);
339 config_id
= base
.ConfigID
;
340 base
.ConfigID
= EGL_DONT_CARE
;
341 base
.SurfaceType
= EGL_DONT_CARE
;
342 num_configs
= _eglFilterArray(disp
->Configs
, (void **) &matching_config
, 1,
343 (_EGLArrayForEach
) dri2_match_config
, &base
);
345 if (num_configs
== 1) {
346 conf
= (struct dri2_egl_config
*) matching_config
;
348 if (!conf
->dri_config
[double_buffer
][srgb
])
349 conf
->dri_config
[double_buffer
][srgb
] = dri_config
;
351 /* a similar config type is already added (unlikely) => discard */
354 else if (num_configs
== 0) {
355 conf
= calloc(1, sizeof *conf
);
359 conf
->dri_config
[double_buffer
][srgb
] = dri_config
;
361 memcpy(&conf
->base
, &base
, sizeof base
);
362 conf
->base
.SurfaceType
= 0;
363 conf
->base
.ConfigID
= config_id
;
365 _eglLinkConfig(&conf
->base
);
373 surface_type
&= ~EGL_PIXMAP_BIT
;
376 /* No support for pbuffer + MSAA for now.
378 * XXX TODO: pbuffer + MSAA does not work and causes crashes.
379 * See QT bugreport: https://bugreports.qt.io/browse/QTBUG-47509
382 surface_type
&= ~EGL_PBUFFER_BIT
;
385 conf
->base
.SurfaceType
|= surface_type
;
391 dri2_lookup_egl_image(__DRIscreen
*screen
, void *image
, void *data
)
393 _EGLDisplay
*disp
= data
;
394 struct dri2_egl_image
*dri2_img
;
399 img
= _eglLookupImage(image
, disp
);
401 _eglError(EGL_BAD_PARAMETER
, "dri2_lookup_egl_image");
405 dri2_img
= dri2_egl_image(image
);
407 return dri2_img
->dri_image
;
410 const __DRIimageLookupExtension image_lookup_extension
= {
411 .base
= { __DRI_IMAGE_LOOKUP
, 1 },
413 .lookupEGLImage
= dri2_lookup_egl_image
416 struct dri2_extension_match
{
422 static const struct dri2_extension_match dri3_driver_extensions
[] = {
423 { __DRI_CORE
, 1, offsetof(struct dri2_egl_display
, core
) },
424 { __DRI_IMAGE_DRIVER
, 1, offsetof(struct dri2_egl_display
, image_driver
) },
428 static const struct dri2_extension_match dri2_driver_extensions
[] = {
429 { __DRI_CORE
, 1, offsetof(struct dri2_egl_display
, core
) },
430 { __DRI_DRI2
, 2, offsetof(struct dri2_egl_display
, dri2
) },
434 static const struct dri2_extension_match dri2_core_extensions
[] = {
435 { __DRI2_FLUSH
, 1, offsetof(struct dri2_egl_display
, flush
) },
436 { __DRI_TEX_BUFFER
, 2, offsetof(struct dri2_egl_display
, tex_buffer
) },
437 { __DRI_IMAGE
, 1, offsetof(struct dri2_egl_display
, image
) },
441 static const struct dri2_extension_match swrast_driver_extensions
[] = {
442 { __DRI_CORE
, 1, offsetof(struct dri2_egl_display
, core
) },
443 { __DRI_SWRAST
, 2, offsetof(struct dri2_egl_display
, swrast
) },
447 static const struct dri2_extension_match swrast_core_extensions
[] = {
448 { __DRI_TEX_BUFFER
, 2, offsetof(struct dri2_egl_display
, tex_buffer
) },
452 static const struct dri2_extension_match optional_core_extensions
[] = {
453 { __DRI2_ROBUSTNESS
, 1, offsetof(struct dri2_egl_display
, robustness
) },
454 { __DRI2_NO_ERROR
, 1, offsetof(struct dri2_egl_display
, no_error
) },
455 { __DRI2_CONFIG_QUERY
, 1, offsetof(struct dri2_egl_display
, config
) },
456 { __DRI2_FENCE
, 1, offsetof(struct dri2_egl_display
, fence
) },
457 { __DRI2_RENDERER_QUERY
, 1, offsetof(struct dri2_egl_display
, rendererQuery
) },
458 { __DRI2_INTEROP
, 1, offsetof(struct dri2_egl_display
, interop
) },
459 { __DRI_IMAGE
, 1, offsetof(struct dri2_egl_display
, image
) },
460 { __DRI2_FLUSH_CONTROL
, 1, offsetof(struct dri2_egl_display
, flush_control
) },
465 dri2_bind_extensions(struct dri2_egl_display
*dri2_dpy
,
466 const struct dri2_extension_match
*matches
,
467 const __DRIextension
**extensions
,
473 for (int i
= 0; extensions
[i
]; i
++) {
474 _eglLog(_EGL_DEBUG
, "found extension `%s'", extensions
[i
]->name
);
475 for (int j
= 0; matches
[j
].name
; j
++) {
476 if (strcmp(extensions
[i
]->name
, matches
[j
].name
) == 0 &&
477 extensions
[i
]->version
>= matches
[j
].version
) {
478 field
= ((char *) dri2_dpy
+ matches
[j
].offset
);
479 *(const __DRIextension
**) field
= extensions
[i
];
480 _eglLog(_EGL_INFO
, "found extension %s version %d",
481 extensions
[i
]->name
, extensions
[i
]->version
);
487 for (int j
= 0; matches
[j
].name
; j
++) {
488 field
= ((char *) dri2_dpy
+ matches
[j
].offset
);
489 if (*(const __DRIextension
**) field
== NULL
) {
491 _eglLog(_EGL_DEBUG
, "did not find optional extension %s version %d",
492 matches
[j
].name
, matches
[j
].version
);
494 _eglLog(_EGL_WARNING
, "did not find extension %s version %d",
495 matches
[j
].name
, matches
[j
].version
);
504 static const __DRIextension
**
505 dri2_open_driver(_EGLDisplay
*disp
)
507 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
508 const __DRIextension
**extensions
= NULL
;
509 char path
[PATH_MAX
], *search_paths
, *next
, *end
;
510 char *get_extensions_name
;
511 const __DRIextension
**(*get_extensions
)(void);
514 if (geteuid() == getuid()) {
515 /* don't allow setuid apps to use LIBGL_DRIVERS_PATH */
516 search_paths
= getenv("LIBGL_DRIVERS_PATH");
518 if (search_paths
== NULL
)
519 search_paths
= DEFAULT_DRIVER_DIR
;
521 dri2_dpy
->driver
= NULL
;
522 end
= search_paths
+ strlen(search_paths
);
523 for (char *p
= search_paths
; p
< end
; p
= next
+ 1) {
525 next
= strchr(p
, ':');
531 snprintf(path
, sizeof path
,
532 "%.*s/tls/%s_dri.so", len
, p
, dri2_dpy
->driver_name
);
533 dri2_dpy
->driver
= dlopen(path
, RTLD_NOW
| RTLD_GLOBAL
);
535 if (dri2_dpy
->driver
== NULL
) {
536 snprintf(path
, sizeof path
,
537 "%.*s/%s_dri.so", len
, p
, dri2_dpy
->driver_name
);
538 dri2_dpy
->driver
= dlopen(path
, RTLD_NOW
| RTLD_GLOBAL
);
539 if (dri2_dpy
->driver
== NULL
)
540 _eglLog(_EGL_DEBUG
, "failed to open %s: %s\n", path
, dlerror());
542 /* not need continue to loop all paths once the driver is found */
543 if (dri2_dpy
->driver
!= NULL
)
547 if (dri2_dpy
->driver
== NULL
) {
548 _eglLog(_EGL_WARNING
,
549 "DRI2: failed to open %s (search paths %s)",
550 dri2_dpy
->driver_name
, search_paths
);
554 _eglLog(_EGL_DEBUG
, "DRI2: dlopen(%s)", path
);
556 get_extensions_name
= loader_get_extensions_name(dri2_dpy
->driver_name
);
557 if (get_extensions_name
) {
558 get_extensions
= dlsym(dri2_dpy
->driver
, get_extensions_name
);
559 if (get_extensions
) {
560 extensions
= get_extensions();
562 _eglLog(_EGL_DEBUG
, "driver does not expose %s(): %s\n",
563 get_extensions_name
, dlerror());
565 free(get_extensions_name
);
569 extensions
= dlsym(dri2_dpy
->driver
, __DRI_DRIVER_EXTENSIONS
);
570 if (extensions
== NULL
) {
571 _eglLog(_EGL_WARNING
,
572 "DRI2: driver exports no extensions (%s)", dlerror());
573 dlclose(dri2_dpy
->driver
);
580 dri2_load_driver_dri3(_EGLDisplay
*disp
)
582 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
583 const __DRIextension
**extensions
;
585 extensions
= dri2_open_driver(disp
);
589 if (!dri2_bind_extensions(dri2_dpy
, dri3_driver_extensions
, extensions
, false)) {
590 dlclose(dri2_dpy
->driver
);
593 dri2_dpy
->driver_extensions
= extensions
;
599 dri2_load_driver(_EGLDisplay
*disp
)
601 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
602 const __DRIextension
**extensions
;
604 extensions
= dri2_open_driver(disp
);
608 if (!dri2_bind_extensions(dri2_dpy
, dri2_driver_extensions
, extensions
, false)) {
609 dlclose(dri2_dpy
->driver
);
612 dri2_dpy
->driver_extensions
= extensions
;
618 dri2_load_driver_swrast(_EGLDisplay
*disp
)
620 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
621 const __DRIextension
**extensions
;
623 extensions
= dri2_open_driver(disp
);
627 if (!dri2_bind_extensions(dri2_dpy
, swrast_driver_extensions
, extensions
, false)) {
628 dlclose(dri2_dpy
->driver
);
631 dri2_dpy
->driver_extensions
= extensions
;
637 dri2_renderer_query_integer(struct dri2_egl_display
*dri2_dpy
, int param
)
639 const __DRI2rendererQueryExtension
*rendererQuery
= dri2_dpy
->rendererQuery
;
640 unsigned int value
= 0;
642 if (!rendererQuery
||
643 rendererQuery
->queryInteger(dri2_dpy
->dri_screen
, param
, &value
) == -1)
650 dri2_setup_screen(_EGLDisplay
*disp
)
652 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
653 unsigned int api_mask
;
656 * EGL 1.5 specification defines the default value to 1. Moreover,
657 * eglSwapInterval() is required to clamp requested value to the supported
658 * range. Since the default value is implicitly assumed to be supported,
659 * use it as both minimum and maximum for the platforms that do not allow
660 * changing the interval. Platforms, which allow it (e.g. x11, wayland)
661 * override these values already.
663 dri2_dpy
->min_swap_interval
= 1;
664 dri2_dpy
->max_swap_interval
= 1;
665 dri2_dpy
->default_swap_interval
= 1;
667 if (dri2_dpy
->image_driver
) {
668 api_mask
= dri2_dpy
->image_driver
->getAPIMask(dri2_dpy
->dri_screen
);
669 } else if (dri2_dpy
->dri2
) {
670 api_mask
= dri2_dpy
->dri2
->getAPIMask(dri2_dpy
->dri_screen
);
672 assert(dri2_dpy
->swrast
);
673 api_mask
= 1 << __DRI_API_OPENGL
|
674 1 << __DRI_API_GLES
|
675 1 << __DRI_API_GLES2
|
676 1 << __DRI_API_GLES3
;
679 disp
->ClientAPIs
= 0;
680 if ((api_mask
& (1 <<__DRI_API_OPENGL
)) && _eglIsApiValid(EGL_OPENGL_API
))
681 disp
->ClientAPIs
|= EGL_OPENGL_BIT
;
682 if ((api_mask
& (1 << __DRI_API_GLES
)) && _eglIsApiValid(EGL_OPENGL_ES_API
))
683 disp
->ClientAPIs
|= EGL_OPENGL_ES_BIT
;
684 if ((api_mask
& (1 << __DRI_API_GLES2
)) && _eglIsApiValid(EGL_OPENGL_ES_API
))
685 disp
->ClientAPIs
|= EGL_OPENGL_ES2_BIT
;
686 if ((api_mask
& (1 << __DRI_API_GLES3
)) && _eglIsApiValid(EGL_OPENGL_ES_API
))
687 disp
->ClientAPIs
|= EGL_OPENGL_ES3_BIT_KHR
;
689 assert(dri2_dpy
->image_driver
|| dri2_dpy
->dri2
|| dri2_dpy
->swrast
);
690 disp
->Extensions
.KHR_no_config_context
= EGL_TRUE
;
691 disp
->Extensions
.KHR_surfaceless_context
= EGL_TRUE
;
693 /* Report back to EGL the bitmask of priorities supported */
694 disp
->Extensions
.IMG_context_priority
=
695 dri2_renderer_query_integer(dri2_dpy
,
696 __DRI2_RENDERER_HAS_CONTEXT_PRIORITY
);
698 if (dri2_renderer_query_integer(dri2_dpy
,
699 __DRI2_RENDERER_HAS_FRAMEBUFFER_SRGB
))
700 disp
->Extensions
.KHR_gl_colorspace
= EGL_TRUE
;
702 if (dri2_dpy
->image_driver
||
703 (dri2_dpy
->dri2
&& dri2_dpy
->dri2
->base
.version
>= 3) ||
704 (dri2_dpy
->swrast
&& dri2_dpy
->swrast
->base
.version
>= 3)) {
705 disp
->Extensions
.KHR_create_context
= EGL_TRUE
;
707 if (dri2_dpy
->robustness
)
708 disp
->Extensions
.EXT_create_context_robustness
= EGL_TRUE
;
711 if (dri2_dpy
->no_error
)
712 disp
->Extensions
.KHR_create_context_no_error
= EGL_TRUE
;
714 if (dri2_dpy
->fence
) {
715 disp
->Extensions
.KHR_fence_sync
= EGL_TRUE
;
716 disp
->Extensions
.KHR_wait_sync
= EGL_TRUE
;
717 if (dri2_dpy
->fence
->get_fence_from_cl_event
)
718 disp
->Extensions
.KHR_cl_event2
= EGL_TRUE
;
719 if (dri2_dpy
->fence
->base
.version
>= 2 &&
720 dri2_dpy
->fence
->get_capabilities
) {
721 unsigned capabilities
=
722 dri2_dpy
->fence
->get_capabilities(dri2_dpy
->dri_screen
);
723 disp
->Extensions
.ANDROID_native_fence_sync
=
724 (capabilities
& __DRI_FENCE_CAP_NATIVE_FD
) != 0;
728 disp
->Extensions
.KHR_reusable_sync
= EGL_TRUE
;
730 if (dri2_dpy
->image
) {
731 if (dri2_dpy
->image
->base
.version
>= 10 &&
732 dri2_dpy
->image
->getCapabilities
!= NULL
) {
735 capabilities
= dri2_dpy
->image
->getCapabilities(dri2_dpy
->dri_screen
);
736 disp
->Extensions
.MESA_drm_image
= (capabilities
& __DRI_IMAGE_CAP_GLOBAL_NAMES
) != 0;
738 if (dri2_dpy
->image
->base
.version
>= 11)
739 disp
->Extensions
.MESA_image_dma_buf_export
= EGL_TRUE
;
741 disp
->Extensions
.MESA_drm_image
= EGL_TRUE
;
742 if (dri2_dpy
->image
->base
.version
>= 11)
743 disp
->Extensions
.MESA_image_dma_buf_export
= EGL_TRUE
;
746 disp
->Extensions
.KHR_image_base
= EGL_TRUE
;
747 disp
->Extensions
.KHR_gl_renderbuffer_image
= EGL_TRUE
;
748 if (dri2_dpy
->image
->base
.version
>= 5 &&
749 dri2_dpy
->image
->createImageFromTexture
) {
750 disp
->Extensions
.KHR_gl_texture_2D_image
= EGL_TRUE
;
751 disp
->Extensions
.KHR_gl_texture_cubemap_image
= EGL_TRUE
;
753 if (dri2_renderer_query_integer(dri2_dpy
,
754 __DRI2_RENDERER_HAS_TEXTURE_3D
))
755 disp
->Extensions
.KHR_gl_texture_3D_image
= EGL_TRUE
;
758 if (dri2_dpy
->image
->base
.version
>= 8 &&
759 dri2_dpy
->image
->createImageFromDmaBufs
) {
760 disp
->Extensions
.EXT_image_dma_buf_import
= EGL_TRUE
;
762 if (dri2_dpy
->image
->base
.version
>= 15 &&
763 dri2_dpy
->image
->createImageFromDmaBufs2
&&
764 dri2_dpy
->image
->queryDmaBufFormats
&&
765 dri2_dpy
->image
->queryDmaBufModifiers
) {
766 disp
->Extensions
.EXT_image_dma_buf_import_modifiers
= EGL_TRUE
;
771 if (dri2_dpy
->flush_control
)
772 disp
->Extensions
.KHR_context_flush_control
= EGL_TRUE
;
776 dri2_setup_swap_interval(_EGLDisplay
*disp
, int max_swap_interval
)
778 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
779 GLint vblank_mode
= DRI_CONF_VBLANK_DEF_INTERVAL_1
;
781 /* Allow driconf to override applications.*/
782 if (dri2_dpy
->config
)
783 dri2_dpy
->config
->configQueryi(dri2_dpy
->dri_screen
,
784 "vblank_mode", &vblank_mode
);
785 switch (vblank_mode
) {
786 case DRI_CONF_VBLANK_NEVER
:
787 dri2_dpy
->min_swap_interval
= 0;
788 dri2_dpy
->max_swap_interval
= 0;
789 dri2_dpy
->default_swap_interval
= 0;
791 case DRI_CONF_VBLANK_ALWAYS_SYNC
:
792 dri2_dpy
->min_swap_interval
= 1;
793 dri2_dpy
->max_swap_interval
= max_swap_interval
;
794 dri2_dpy
->default_swap_interval
= 1;
796 case DRI_CONF_VBLANK_DEF_INTERVAL_0
:
797 dri2_dpy
->min_swap_interval
= 0;
798 dri2_dpy
->max_swap_interval
= max_swap_interval
;
799 dri2_dpy
->default_swap_interval
= 0;
802 case DRI_CONF_VBLANK_DEF_INTERVAL_1
:
803 dri2_dpy
->min_swap_interval
= 0;
804 dri2_dpy
->max_swap_interval
= max_swap_interval
;
805 dri2_dpy
->default_swap_interval
= 1;
810 /* All platforms but DRM call this function to create the screen and populate
811 * the driver_configs. DRM inherits that information from its display - GBM.
814 dri2_create_screen(_EGLDisplay
*disp
)
816 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
818 if (dri2_dpy
->image_driver
) {
819 dri2_dpy
->dri_screen
=
820 dri2_dpy
->image_driver
->createNewScreen2(0, dri2_dpy
->fd
,
821 dri2_dpy
->loader_extensions
,
822 dri2_dpy
->driver_extensions
,
823 &dri2_dpy
->driver_configs
,
825 } else if (dri2_dpy
->dri2
) {
826 if (dri2_dpy
->dri2
->base
.version
>= 4) {
827 dri2_dpy
->dri_screen
=
828 dri2_dpy
->dri2
->createNewScreen2(0, dri2_dpy
->fd
,
829 dri2_dpy
->loader_extensions
,
830 dri2_dpy
->driver_extensions
,
831 &dri2_dpy
->driver_configs
, disp
);
833 dri2_dpy
->dri_screen
=
834 dri2_dpy
->dri2
->createNewScreen(0, dri2_dpy
->fd
,
835 dri2_dpy
->loader_extensions
,
836 &dri2_dpy
->driver_configs
, disp
);
839 assert(dri2_dpy
->swrast
);
840 if (dri2_dpy
->swrast
->base
.version
>= 4) {
841 dri2_dpy
->dri_screen
=
842 dri2_dpy
->swrast
->createNewScreen2(0, dri2_dpy
->loader_extensions
,
843 dri2_dpy
->driver_extensions
,
844 &dri2_dpy
->driver_configs
, disp
);
846 dri2_dpy
->dri_screen
=
847 dri2_dpy
->swrast
->createNewScreen(0, dri2_dpy
->loader_extensions
,
848 &dri2_dpy
->driver_configs
, disp
);
852 if (dri2_dpy
->dri_screen
== NULL
) {
853 _eglLog(_EGL_WARNING
, "DRI2: failed to create dri screen");
857 dri2_dpy
->own_dri_screen
= true;
862 dri2_setup_extensions(_EGLDisplay
*disp
)
864 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
865 const struct dri2_extension_match
*mandatory_core_extensions
;
866 const __DRIextension
**extensions
;
868 extensions
= dri2_dpy
->core
->getExtensions(dri2_dpy
->dri_screen
);
870 if (dri2_dpy
->image_driver
|| dri2_dpy
->dri2
)
871 mandatory_core_extensions
= dri2_core_extensions
;
873 mandatory_core_extensions
= swrast_core_extensions
;
875 if (!dri2_bind_extensions(dri2_dpy
, mandatory_core_extensions
, extensions
, false))
878 dri2_bind_extensions(dri2_dpy
, optional_core_extensions
, extensions
, true);
883 * Called via eglInitialize(), GLX_drv->API.Initialize().
885 * This must be guaranteed to be called exactly once, even if eglInitialize is
886 * called many times (without a eglTerminate in between).
889 dri2_initialize(_EGLDriver
*drv
, _EGLDisplay
*disp
)
891 EGLBoolean ret
= EGL_FALSE
;
892 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
894 /* In the case where the application calls eglMakeCurrent(context1),
895 * eglTerminate, then eglInitialize again (without a call to eglReleaseThread
896 * or eglMakeCurrent(NULL) before that), dri2_dpy structure is still
897 * initialized, as we need it to be able to free context1 correctly.
899 * It would probably be safest to forcibly release the display with
900 * dri2_display_release, to make sure the display is reinitialized correctly.
901 * However, the EGL spec states that we need to keep a reference to the
902 * current context (so we cannot call dri2_make_current(NULL)), and therefore
903 * we would leak context1 as we would be missing the old display connection
904 * to free it up correctly.
907 dri2_dpy
->ref_count
++;
911 /* not until swrast_dri is supported */
912 if (disp
->Options
.UseFallback
)
915 switch (disp
->Platform
) {
916 #ifdef HAVE_SURFACELESS_PLATFORM
917 case _EGL_PLATFORM_SURFACELESS
:
918 ret
= dri2_initialize_surfaceless(drv
, disp
);
921 #ifdef HAVE_X11_PLATFORM
922 case _EGL_PLATFORM_X11
:
923 ret
= dri2_initialize_x11(drv
, disp
);
926 #ifdef HAVE_DRM_PLATFORM
927 case _EGL_PLATFORM_DRM
:
928 ret
= dri2_initialize_drm(drv
, disp
);
931 #ifdef HAVE_WAYLAND_PLATFORM
932 case _EGL_PLATFORM_WAYLAND
:
933 ret
= dri2_initialize_wayland(drv
, disp
);
936 #ifdef HAVE_ANDROID_PLATFORM
937 case _EGL_PLATFORM_ANDROID
:
938 ret
= dri2_initialize_android(drv
, disp
);
942 _eglLog(_EGL_WARNING
, "No EGL platform enabled.");
949 dri2_dpy
= dri2_egl_display(disp
);
950 dri2_dpy
->ref_count
++;
956 * Decrement display reference count, and free up display if necessary.
959 dri2_display_release(_EGLDisplay
*disp
)
961 struct dri2_egl_display
*dri2_dpy
;
966 dri2_dpy
= dri2_egl_display(disp
);
968 assert(dri2_dpy
->ref_count
> 0);
969 dri2_dpy
->ref_count
--;
971 if (dri2_dpy
->ref_count
> 0)
974 _eglCleanupDisplay(disp
);
975 dri2_display_destroy(disp
);
979 dri2_display_destroy(_EGLDisplay
*disp
)
981 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
983 if (dri2_dpy
->own_dri_screen
) {
984 if (dri2_dpy
->vtbl
->close_screen_notify
)
985 dri2_dpy
->vtbl
->close_screen_notify(disp
);
986 dri2_dpy
->core
->destroyScreen(dri2_dpy
->dri_screen
);
988 if (dri2_dpy
->fd
>= 0)
990 if (dri2_dpy
->driver
)
991 dlclose(dri2_dpy
->driver
);
992 free(dri2_dpy
->driver_name
);
994 #ifdef HAVE_WAYLAND_PLATFORM
995 free(dri2_dpy
->device_name
);
998 switch (disp
->Platform
) {
999 #ifdef HAVE_X11_PLATFORM
1000 case _EGL_PLATFORM_X11
:
1001 if (dri2_dpy
->own_device
) {
1002 xcb_disconnect(dri2_dpy
->conn
);
1006 #ifdef HAVE_DRM_PLATFORM
1007 case _EGL_PLATFORM_DRM
:
1008 if (dri2_dpy
->own_device
) {
1009 gbm_device_destroy(&dri2_dpy
->gbm_dri
->base
);
1013 #ifdef HAVE_WAYLAND_PLATFORM
1014 case _EGL_PLATFORM_WAYLAND
:
1015 if (dri2_dpy
->wl_drm
)
1016 wl_drm_destroy(dri2_dpy
->wl_drm
);
1017 if (dri2_dpy
->wl_dmabuf
)
1018 zwp_linux_dmabuf_v1_destroy(dri2_dpy
->wl_dmabuf
);
1019 if (dri2_dpy
->wl_shm
)
1020 wl_shm_destroy(dri2_dpy
->wl_shm
);
1021 if (dri2_dpy
->wl_registry
)
1022 wl_registry_destroy(dri2_dpy
->wl_registry
);
1023 if (dri2_dpy
->wl_queue
)
1024 wl_event_queue_destroy(dri2_dpy
->wl_queue
);
1025 if (dri2_dpy
->wl_dpy_wrapper
)
1026 wl_proxy_wrapper_destroy(dri2_dpy
->wl_dpy_wrapper
);
1027 u_vector_finish(&dri2_dpy
->wl_modifiers
.argb8888
);
1028 u_vector_finish(&dri2_dpy
->wl_modifiers
.xrgb8888
);
1029 u_vector_finish(&dri2_dpy
->wl_modifiers
.rgb565
);
1030 if (dri2_dpy
->own_device
) {
1031 wl_display_disconnect(dri2_dpy
->wl_dpy
);
1039 /* The drm platform does not create the screen/driver_configs but reuses
1040 * the ones from the gbm device. As such the gbm itself is responsible
1043 if (disp
->Platform
!= _EGL_PLATFORM_DRM
&& dri2_dpy
->driver_configs
) {
1044 for (unsigned i
= 0; dri2_dpy
->driver_configs
[i
]; i
++)
1045 free((__DRIconfig
*) dri2_dpy
->driver_configs
[i
]);
1046 free(dri2_dpy
->driver_configs
);
1049 disp
->DriverData
= NULL
;
1053 dri2_egl_surface_alloc_local_buffer(struct dri2_egl_surface
*dri2_surf
,
1054 unsigned int att
, unsigned int format
)
1056 struct dri2_egl_display
*dri2_dpy
=
1057 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
1059 if (att
>= ARRAY_SIZE(dri2_surf
->local_buffers
))
1062 if (!dri2_surf
->local_buffers
[att
]) {
1063 dri2_surf
->local_buffers
[att
] =
1064 dri2_dpy
->dri2
->allocateBuffer(dri2_dpy
->dri_screen
, att
, format
,
1065 dri2_surf
->base
.Width
, dri2_surf
->base
.Height
);
1068 return dri2_surf
->local_buffers
[att
];
1072 dri2_egl_surface_free_local_buffers(struct dri2_egl_surface
*dri2_surf
)
1074 struct dri2_egl_display
*dri2_dpy
=
1075 dri2_egl_display(dri2_surf
->base
.Resource
.Display
);
1077 for (int i
= 0; i
< ARRAY_SIZE(dri2_surf
->local_buffers
); i
++) {
1078 if (dri2_surf
->local_buffers
[i
]) {
1079 dri2_dpy
->dri2
->releaseBuffer(dri2_dpy
->dri_screen
,
1080 dri2_surf
->local_buffers
[i
]);
1081 dri2_surf
->local_buffers
[i
] = NULL
;
1087 * Called via eglTerminate(), drv->API.Terminate().
1089 * This must be guaranteed to be called exactly once, even if eglTerminate is
1090 * called many times (without a eglInitialize in between).
1093 dri2_terminate(_EGLDriver
*drv
, _EGLDisplay
*disp
)
1095 /* Release all non-current Context/Surfaces. */
1096 _eglReleaseDisplayResources(drv
, disp
);
1098 dri2_display_release(disp
);
1104 * Set the error code after a call to
1105 * dri2_egl_display::dri2::createContextAttribs.
1108 dri2_create_context_attribs_error(int dri_error
)
1112 switch (dri_error
) {
1113 case __DRI_CTX_ERROR_SUCCESS
:
1116 case __DRI_CTX_ERROR_NO_MEMORY
:
1117 egl_error
= EGL_BAD_ALLOC
;
1120 /* From the EGL_KHR_create_context spec, section "Errors":
1122 * * If <config> does not support a client API context compatible
1123 * with the requested API major and minor version, [...] context flags,
1124 * and context reset notification behavior (for client API types where
1125 * these attributes are supported), then an EGL_BAD_MATCH error is
1128 * * If an OpenGL ES context is requested and the values for
1129 * attributes EGL_CONTEXT_MAJOR_VERSION_KHR and
1130 * EGL_CONTEXT_MINOR_VERSION_KHR specify an OpenGL ES version that
1131 * is not defined, than an EGL_BAD_MATCH error is generated.
1133 * * If an OpenGL context is requested, the requested version is
1134 * greater than 3.2, and the value for attribute
1135 * EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR has no bits set; has any
1136 * bits set other than EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR and
1137 * EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR; has more than
1138 * one of these bits set; or if the implementation does not support
1139 * the requested profile, then an EGL_BAD_MATCH error is generated.
1141 case __DRI_CTX_ERROR_BAD_API
:
1142 case __DRI_CTX_ERROR_BAD_VERSION
:
1143 case __DRI_CTX_ERROR_BAD_FLAG
:
1144 egl_error
= EGL_BAD_MATCH
;
1147 /* From the EGL_KHR_create_context spec, section "Errors":
1149 * * If an attribute name or attribute value in <attrib_list> is not
1150 * recognized (including unrecognized bits in bitmask attributes),
1151 * then an EGL_BAD_ATTRIBUTE error is generated."
1153 case __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE
:
1154 case __DRI_CTX_ERROR_UNKNOWN_FLAG
:
1155 egl_error
= EGL_BAD_ATTRIBUTE
;
1160 egl_error
= EGL_BAD_MATCH
;
1164 _eglError(egl_error
, "dri2_create_context");
1168 dri2_fill_context_attribs(struct dri2_egl_context
*dri2_ctx
,
1169 struct dri2_egl_display
*dri2_dpy
,
1170 uint32_t *ctx_attribs
,
1171 unsigned *num_attribs
)
1175 assert(*num_attribs
>= NUM_ATTRIBS
);
1177 ctx_attribs
[pos
++] = __DRI_CTX_ATTRIB_MAJOR_VERSION
;
1178 ctx_attribs
[pos
++] = dri2_ctx
->base
.ClientMajorVersion
;
1179 ctx_attribs
[pos
++] = __DRI_CTX_ATTRIB_MINOR_VERSION
;
1180 ctx_attribs
[pos
++] = dri2_ctx
->base
.ClientMinorVersion
;
1182 if (dri2_ctx
->base
.Flags
!= 0 || dri2_ctx
->base
.NoError
) {
1183 /* If the implementation doesn't support the __DRI2_ROBUSTNESS
1184 * extension, don't even try to send it the robust-access flag.
1185 * It may explode. Instead, generate the required EGL error here.
1187 if ((dri2_ctx
->base
.Flags
& EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR
) != 0
1188 && !dri2_dpy
->robustness
) {
1189 _eglError(EGL_BAD_MATCH
, "eglCreateContext");
1193 ctx_attribs
[pos
++] = __DRI_CTX_ATTRIB_FLAGS
;
1194 ctx_attribs
[pos
++] = dri2_ctx
->base
.Flags
|
1195 (dri2_ctx
->base
.NoError
? __DRI_CTX_FLAG_NO_ERROR
: 0);
1198 if (dri2_ctx
->base
.ResetNotificationStrategy
!= EGL_NO_RESET_NOTIFICATION_KHR
) {
1199 /* If the implementation doesn't support the __DRI2_ROBUSTNESS
1200 * extension, don't even try to send it a reset strategy. It may
1201 * explode. Instead, generate the required EGL error here.
1203 if (!dri2_dpy
->robustness
) {
1204 _eglError(EGL_BAD_CONFIG
, "eglCreateContext");
1208 ctx_attribs
[pos
++] = __DRI_CTX_ATTRIB_RESET_STRATEGY
;
1209 ctx_attribs
[pos
++] = __DRI_CTX_RESET_LOSE_CONTEXT
;
1212 if (dri2_ctx
->base
.ContextPriority
!= EGL_CONTEXT_PRIORITY_MEDIUM_IMG
) {
1215 switch (dri2_ctx
->base
.ContextPriority
) {
1216 case EGL_CONTEXT_PRIORITY_HIGH_IMG
:
1217 val
= __DRI_CTX_PRIORITY_HIGH
;
1219 case EGL_CONTEXT_PRIORITY_MEDIUM_IMG
:
1220 val
= __DRI_CTX_PRIORITY_MEDIUM
;
1222 case EGL_CONTEXT_PRIORITY_LOW_IMG
:
1223 val
= __DRI_CTX_PRIORITY_LOW
;
1226 _eglError(EGL_BAD_CONFIG
, "eglCreateContext");
1230 ctx_attribs
[pos
++] = __DRI_CTX_ATTRIB_PRIORITY
;
1231 ctx_attribs
[pos
++] = val
;
1234 if (dri2_ctx
->base
.ReleaseBehavior
== EGL_CONTEXT_RELEASE_BEHAVIOR_NONE_KHR
) {
1235 ctx_attribs
[pos
++] = __DRI_CTX_ATTRIB_RELEASE_BEHAVIOR
;
1236 ctx_attribs
[pos
++] = __DRI_CTX_RELEASE_BEHAVIOR_NONE
;
1245 * Called via eglCreateContext(), drv->API.CreateContext().
1247 static _EGLContext
*
1248 dri2_create_context(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLConfig
*conf
,
1249 _EGLContext
*share_list
, const EGLint
*attrib_list
)
1251 struct dri2_egl_context
*dri2_ctx
;
1252 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1253 struct dri2_egl_context
*dri2_ctx_shared
= dri2_egl_context(share_list
);
1254 __DRIcontext
*shared
=
1255 dri2_ctx_shared
? dri2_ctx_shared
->dri_context
: NULL
;
1256 struct dri2_egl_config
*dri2_config
= dri2_egl_config(conf
);
1257 const __DRIconfig
*dri_config
;
1260 unsigned num_attribs
= NUM_ATTRIBS
;
1261 uint32_t ctx_attribs
[NUM_ATTRIBS
];
1265 dri2_ctx
= malloc(sizeof *dri2_ctx
);
1267 _eglError(EGL_BAD_ALLOC
, "eglCreateContext");
1271 if (!_eglInitContext(&dri2_ctx
->base
, disp
, conf
, attrib_list
))
1274 /* The EGL_EXT_create_context_robustness spec says:
1276 * "Add to the eglCreateContext context creation errors: [...]
1278 * * If the reset notification behavior of <share_context> and the
1279 * newly created context are different then an EGL_BAD_MATCH error is
1282 if (share_list
&& share_list
->ResetNotificationStrategy
!=
1283 dri2_ctx
->base
.ResetNotificationStrategy
) {
1284 _eglError(EGL_BAD_MATCH
, "eglCreateContext");
1288 /* The EGL_KHR_create_context_no_error spec says:
1290 * "BAD_MATCH is generated if the value of EGL_CONTEXT_OPENGL_NO_ERROR_KHR
1291 * used to create <share_context> does not match the value of
1292 * EGL_CONTEXT_OPENGL_NO_ERROR_KHR for the context being created."
1294 if (share_list
&& share_list
->NoError
!= dri2_ctx
->base
.NoError
) {
1295 _eglError(EGL_BAD_MATCH
, "eglCreateContext");
1299 switch (dri2_ctx
->base
.ClientAPI
) {
1300 case EGL_OPENGL_ES_API
:
1301 switch (dri2_ctx
->base
.ClientMajorVersion
) {
1303 api
= __DRI_API_GLES
;
1306 api
= __DRI_API_GLES2
;
1309 api
= __DRI_API_GLES3
;
1312 _eglError(EGL_BAD_PARAMETER
, "eglCreateContext");
1317 case EGL_OPENGL_API
:
1318 if ((dri2_ctx
->base
.ClientMajorVersion
>= 4
1319 || (dri2_ctx
->base
.ClientMajorVersion
== 3
1320 && dri2_ctx
->base
.ClientMinorVersion
>= 2))
1321 && dri2_ctx
->base
.Profile
== EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR
)
1322 api
= __DRI_API_OPENGL_CORE
;
1324 api
= __DRI_API_OPENGL
;
1327 _eglError(EGL_BAD_PARAMETER
, "eglCreateContext");
1333 /* The config chosen here isn't necessarily
1334 * used for surfaces later.
1335 * A pixmap surface will use the single config.
1336 * This opportunity depends on disabling the
1337 * doubleBufferMode check in
1338 * src/mesa/main/context.c:check_compatible()
1340 if (dri2_config
->dri_config
[1][0])
1341 dri_config
= dri2_config
->dri_config
[1][0];
1343 dri_config
= dri2_config
->dri_config
[0][0];
1345 /* EGL_WINDOW_BIT is set only when there is a double-buffered dri_config.
1346 * This makes sure the back buffer will always be used.
1348 if (conf
->SurfaceType
& EGL_WINDOW_BIT
)
1349 dri2_ctx
->base
.WindowRenderBuffer
= EGL_BACK_BUFFER
;
1354 if (!dri2_fill_context_attribs(dri2_ctx
, dri2_dpy
, ctx_attribs
,
1358 if (dri2_dpy
->image_driver
) {
1359 dri2_ctx
->dri_context
=
1360 dri2_dpy
->image_driver
->createContextAttribs(dri2_dpy
->dri_screen
,
1368 dri2_create_context_attribs_error(error
);
1369 } else if (dri2_dpy
->dri2
) {
1370 if (dri2_dpy
->dri2
->base
.version
>= 3) {
1371 dri2_ctx
->dri_context
=
1372 dri2_dpy
->dri2
->createContextAttribs(dri2_dpy
->dri_screen
,
1380 dri2_create_context_attribs_error(error
);
1382 dri2_ctx
->dri_context
=
1383 dri2_dpy
->dri2
->createNewContextForAPI(dri2_dpy
->dri_screen
,
1390 assert(dri2_dpy
->swrast
);
1391 if (dri2_dpy
->swrast
->base
.version
>= 3) {
1392 dri2_ctx
->dri_context
=
1393 dri2_dpy
->swrast
->createContextAttribs(dri2_dpy
->dri_screen
,
1401 dri2_create_context_attribs_error(error
);
1403 dri2_ctx
->dri_context
=
1404 dri2_dpy
->swrast
->createNewContextForAPI(dri2_dpy
->dri_screen
,
1412 if (!dri2_ctx
->dri_context
)
1415 return &dri2_ctx
->base
;
1423 * Called via eglDestroyContext(), drv->API.DestroyContext().
1426 dri2_destroy_context(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLContext
*ctx
)
1428 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
1429 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1431 if (_eglPutContext(ctx
)) {
1432 dri2_dpy
->core
->destroyContext(dri2_ctx
->dri_context
);
1440 dri2_init_surface(_EGLSurface
*surf
, _EGLDisplay
*dpy
, EGLint type
,
1441 _EGLConfig
*conf
, const EGLint
*attrib_list
, EGLBoolean enable_out_fence
)
1443 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
1444 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1446 dri2_surf
->out_fence_fd
= -1;
1447 dri2_surf
->enable_out_fence
= false;
1448 if (dri2_dpy
->fence
&& dri2_dpy
->fence
->base
.version
>= 2 &&
1449 dri2_dpy
->fence
->get_capabilities
&&
1450 (dri2_dpy
->fence
->get_capabilities(dri2_dpy
->dri_screen
) &
1451 __DRI_FENCE_CAP_NATIVE_FD
)) {
1452 dri2_surf
->enable_out_fence
= enable_out_fence
;
1455 return _eglInitSurface(surf
, dpy
, type
, conf
, attrib_list
);
1459 dri2_surface_set_out_fence_fd( _EGLSurface
*surf
, int fence_fd
)
1461 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
1463 if (dri2_surf
->out_fence_fd
>= 0)
1464 close(dri2_surf
->out_fence_fd
);
1466 dri2_surf
->out_fence_fd
= fence_fd
;
1470 dri2_fini_surface(_EGLSurface
*surf
)
1472 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
1474 dri2_surface_set_out_fence_fd(surf
, -1);
1475 dri2_surf
->enable_out_fence
= false;
1479 dri2_destroy_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
)
1481 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1483 if (!_eglPutSurface(surf
))
1486 return dri2_dpy
->vtbl
->destroy_surface(drv
, dpy
, surf
);
1490 dri2_surf_update_fence_fd(_EGLContext
*ctx
,
1491 _EGLDisplay
*dpy
, _EGLSurface
*surf
)
1493 __DRIcontext
*dri_ctx
= dri2_egl_context(ctx
)->dri_context
;
1494 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1495 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
1499 if (!dri2_surf
->enable_out_fence
)
1502 fence
= dri2_dpy
->fence
->create_fence_fd(dri_ctx
, -1);
1504 fence_fd
= dri2_dpy
->fence
->get_fence_fd(dri2_dpy
->dri_screen
,
1506 dri2_dpy
->fence
->destroy_fence(dri2_dpy
->dri_screen
, fence
);
1508 dri2_surface_set_out_fence_fd(surf
, fence_fd
);
1512 * Called via eglMakeCurrent(), drv->API.MakeCurrent().
1515 dri2_make_current(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*dsurf
,
1516 _EGLSurface
*rsurf
, _EGLContext
*ctx
)
1518 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1519 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
1520 _EGLContext
*old_ctx
;
1521 _EGLSurface
*old_dsurf
, *old_rsurf
;
1522 _EGLSurface
*tmp_dsurf
, *tmp_rsurf
;
1523 __DRIdrawable
*ddraw
, *rdraw
;
1528 return _eglError(EGL_NOT_INITIALIZED
, "eglMakeCurrent");
1530 /* make new bindings */
1531 if (!_eglBindContext(ctx
, dsurf
, rsurf
, &old_ctx
, &old_dsurf
, &old_rsurf
)) {
1532 /* _eglBindContext already sets the EGL error (in _eglCheckMakeCurrent) */
1536 /* flush before context switch */
1540 ddraw
= (dsurf
) ? dri2_dpy
->vtbl
->get_dri_drawable(dsurf
) : NULL
;
1541 rdraw
= (rsurf
) ? dri2_dpy
->vtbl
->get_dri_drawable(rsurf
) : NULL
;
1542 cctx
= (dri2_ctx
) ? dri2_ctx
->dri_context
: NULL
;
1545 __DRIcontext
*old_cctx
= dri2_egl_context(old_ctx
)->dri_context
;
1548 dri2_surf_update_fence_fd(old_ctx
, disp
, old_dsurf
);
1549 dri2_dpy
->core
->unbindContext(old_cctx
);
1552 unbind
= (cctx
== NULL
&& ddraw
== NULL
&& rdraw
== NULL
);
1554 if (unbind
|| dri2_dpy
->core
->bindContext(cctx
, ddraw
, rdraw
)) {
1555 dri2_destroy_surface(drv
, disp
, old_dsurf
);
1556 dri2_destroy_surface(drv
, disp
, old_rsurf
);
1559 dri2_dpy
->ref_count
++;
1561 EGLDisplay old_disp
= _eglGetDisplayHandle(old_ctx
->Resource
.Display
);
1562 dri2_destroy_context(drv
, disp
, old_ctx
);
1563 dri2_display_release(old_disp
);
1568 /* undo the previous _eglBindContext */
1569 _eglBindContext(old_ctx
, old_dsurf
, old_rsurf
, &ctx
, &tmp_dsurf
, &tmp_rsurf
);
1570 assert(&dri2_ctx
->base
== ctx
&&
1571 tmp_dsurf
== dsurf
&&
1572 tmp_rsurf
== rsurf
);
1574 _eglPutSurface(dsurf
);
1575 _eglPutSurface(rsurf
);
1576 _eglPutContext(ctx
);
1578 _eglPutSurface(old_dsurf
);
1579 _eglPutSurface(old_rsurf
);
1580 _eglPutContext(old_ctx
);
1582 /* dri2_dpy->core->bindContext failed. We cannot tell for sure why, but
1583 * setting the error to EGL_BAD_MATCH is surely better than leaving it
1586 return _eglError(EGL_BAD_MATCH
, "eglMakeCurrent");
1591 dri2_surface_get_dri_drawable(_EGLSurface
*surf
)
1593 struct dri2_egl_surface
*dri2_surf
= dri2_egl_surface(surf
);
1595 return dri2_surf
->dri_drawable
;
1599 * Called from eglGetProcAddress() via drv->API.GetProcAddress().
1602 dri2_get_proc_address(_EGLDriver
*drv
, const char *procname
)
1604 return _glapi_get_proc_address(procname
);
1608 dri2_create_window_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
1609 _EGLConfig
*conf
, void *native_window
,
1610 const EGLint
*attrib_list
)
1612 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1613 return dri2_dpy
->vtbl
->create_window_surface(drv
, dpy
, conf
, native_window
,
1618 dri2_create_pixmap_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
1619 _EGLConfig
*conf
, void *native_pixmap
,
1620 const EGLint
*attrib_list
)
1622 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1623 return dri2_dpy
->vtbl
->create_pixmap_surface(drv
, dpy
, conf
, native_pixmap
,
1628 dri2_create_pbuffer_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
1629 _EGLConfig
*conf
, const EGLint
*attrib_list
)
1631 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1632 return dri2_dpy
->vtbl
->create_pbuffer_surface(drv
, dpy
, conf
, attrib_list
);
1636 dri2_swap_interval(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
1639 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1640 if (!dri2_dpy
->vtbl
->swap_interval
)
1642 return dri2_dpy
->vtbl
->swap_interval(drv
, dpy
, surf
, interval
);
1646 * Asks the client API to flush any rendering to the drawable so that we can
1647 * do our swapbuffers.
1650 dri2_flush_drawable_for_swapbuffers(_EGLDisplay
*disp
, _EGLSurface
*draw
)
1652 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1653 __DRIdrawable
*dri_drawable
= dri2_dpy
->vtbl
->get_dri_drawable(draw
);
1655 if (dri2_dpy
->flush
) {
1656 if (dri2_dpy
->flush
->base
.version
>= 4) {
1657 /* We know there's a current context because:
1659 * "If surface is not bound to the calling thread’s current
1660 * context, an EGL_BAD_SURFACE error is generated."
1662 _EGLContext
*ctx
= _eglGetCurrentContext();
1663 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
1665 /* From the EGL 1.4 spec (page 52):
1667 * "The contents of ancillary buffers are always undefined
1668 * after calling eglSwapBuffers."
1670 dri2_dpy
->flush
->flush_with_flags(dri2_ctx
->dri_context
,
1672 __DRI2_FLUSH_DRAWABLE
|
1673 __DRI2_FLUSH_INVALIDATE_ANCILLARY
,
1674 __DRI2_THROTTLE_SWAPBUFFER
);
1676 dri2_dpy
->flush
->flush(dri_drawable
);
1682 dri2_swap_buffers(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
)
1684 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1685 _EGLContext
*ctx
= _eglGetCurrentContext();
1688 dri2_surf_update_fence_fd(ctx
, dpy
, surf
);
1689 return dri2_dpy
->vtbl
->swap_buffers(drv
, dpy
, surf
);
1693 dri2_swap_buffers_with_damage(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
1695 const EGLint
*rects
, EGLint n_rects
)
1697 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1698 _EGLContext
*ctx
= _eglGetCurrentContext();
1701 dri2_surf_update_fence_fd(ctx
, dpy
, surf
);
1702 return dri2_dpy
->vtbl
->swap_buffers_with_damage(drv
, dpy
, surf
,
1707 dri2_swap_buffers_region(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
1708 EGLint numRects
, const EGLint
*rects
)
1710 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1711 return dri2_dpy
->vtbl
->swap_buffers_region(drv
, dpy
, surf
, numRects
, rects
);
1715 dri2_set_damage_region(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
1716 EGLint
*rects
, EGLint n_rects
)
1718 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1719 return dri2_dpy
->vtbl
->set_damage_region(drv
, dpy
, surf
, rects
, n_rects
);
1723 dri2_post_sub_buffer(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
1724 EGLint x
, EGLint y
, EGLint width
, EGLint height
)
1726 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1727 return dri2_dpy
->vtbl
->post_sub_buffer(drv
, dpy
, surf
, x
, y
, width
, height
);
1731 dri2_copy_buffers(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
1732 void *native_pixmap_target
)
1734 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1735 return dri2_dpy
->vtbl
->copy_buffers(drv
, dpy
, surf
, native_pixmap_target
);
1739 dri2_query_buffer_age(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
)
1741 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1742 return dri2_dpy
->vtbl
->query_buffer_age(drv
, dpy
, surf
);
1746 dri2_wait_client(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLContext
*ctx
)
1748 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1749 _EGLSurface
*surf
= ctx
->DrawSurface
;
1750 __DRIdrawable
*dri_drawable
= dri2_dpy
->vtbl
->get_dri_drawable(surf
);
1754 /* FIXME: If EGL allows frontbuffer rendering for window surfaces,
1755 * we need to copy fake to real here.*/
1757 if (dri2_dpy
->flush
!= NULL
)
1758 dri2_dpy
->flush
->flush(dri_drawable
);
1764 dri2_wait_native(_EGLDriver
*drv
, _EGLDisplay
*disp
, EGLint engine
)
1769 if (engine
!= EGL_CORE_NATIVE_ENGINE
)
1770 return _eglError(EGL_BAD_PARAMETER
, "eglWaitNative");
1777 dri2_bind_tex_image(_EGLDriver
*drv
,
1778 _EGLDisplay
*disp
, _EGLSurface
*surf
, EGLint buffer
)
1780 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1781 struct dri2_egl_context
*dri2_ctx
;
1783 GLint format
, target
;
1784 __DRIdrawable
*dri_drawable
= dri2_dpy
->vtbl
->get_dri_drawable(surf
);
1786 ctx
= _eglGetCurrentContext();
1787 dri2_ctx
= dri2_egl_context(ctx
);
1789 if (!_eglBindTexImage(drv
, disp
, surf
, buffer
))
1792 switch (surf
->TextureFormat
) {
1793 case EGL_TEXTURE_RGB
:
1794 format
= __DRI_TEXTURE_FORMAT_RGB
;
1796 case EGL_TEXTURE_RGBA
:
1797 format
= __DRI_TEXTURE_FORMAT_RGBA
;
1800 assert(!"Unexpected texture format in dri2_bind_tex_image()");
1801 format
= __DRI_TEXTURE_FORMAT_RGBA
;
1804 switch (surf
->TextureTarget
) {
1805 case EGL_TEXTURE_2D
:
1806 target
= GL_TEXTURE_2D
;
1809 target
= GL_TEXTURE_2D
;
1810 assert(!"Unexpected texture target in dri2_bind_tex_image()");
1813 dri2_dpy
->tex_buffer
->setTexBuffer2(dri2_ctx
->dri_context
,
1821 dri2_release_tex_image(_EGLDriver
*drv
,
1822 _EGLDisplay
*disp
, _EGLSurface
*surf
, EGLint buffer
)
1824 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1825 struct dri2_egl_context
*dri2_ctx
;
1828 __DRIdrawable
*dri_drawable
= dri2_dpy
->vtbl
->get_dri_drawable(surf
);
1830 ctx
= _eglGetCurrentContext();
1831 dri2_ctx
= dri2_egl_context(ctx
);
1833 if (!_eglReleaseTexImage(drv
, disp
, surf
, buffer
))
1836 switch (surf
->TextureTarget
) {
1837 case EGL_TEXTURE_2D
:
1838 target
= GL_TEXTURE_2D
;
1844 if (dri2_dpy
->tex_buffer
->base
.version
>= 3 &&
1845 dri2_dpy
->tex_buffer
->releaseTexBuffer
!= NULL
) {
1846 dri2_dpy
->tex_buffer
->releaseTexBuffer(dri2_ctx
->dri_context
,
1847 target
, dri_drawable
);
1854 dri2_create_image(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLContext
*ctx
,
1855 EGLenum target
, EGLClientBuffer buffer
,
1856 const EGLint
*attr_list
)
1858 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
1859 return dri2_dpy
->vtbl
->create_image(drv
, dpy
, ctx
, target
, buffer
,
1864 dri2_create_image_from_dri(_EGLDisplay
*disp
, __DRIimage
*dri_image
)
1866 struct dri2_egl_image
*dri2_img
;
1868 if (dri_image
== NULL
) {
1869 _eglError(EGL_BAD_ALLOC
, "dri2_create_image");
1873 dri2_img
= malloc(sizeof *dri2_img
);
1875 _eglError(EGL_BAD_ALLOC
, "dri2_create_image");
1879 _eglInitImage(&dri2_img
->base
, disp
);
1881 dri2_img
->dri_image
= dri_image
;
1883 return &dri2_img
->base
;
1887 * Translate a DRI Image extension error code into an EGL error code.
1890 egl_error_from_dri_image_error(int dri_error
)
1892 switch (dri_error
) {
1893 case __DRI_IMAGE_ERROR_SUCCESS
:
1895 case __DRI_IMAGE_ERROR_BAD_ALLOC
:
1896 return EGL_BAD_ALLOC
;
1897 case __DRI_IMAGE_ERROR_BAD_MATCH
:
1898 return EGL_BAD_MATCH
;
1899 case __DRI_IMAGE_ERROR_BAD_PARAMETER
:
1900 return EGL_BAD_PARAMETER
;
1901 case __DRI_IMAGE_ERROR_BAD_ACCESS
:
1902 return EGL_BAD_ACCESS
;
1905 return EGL_BAD_ALLOC
;
1910 dri2_create_image_khr_renderbuffer(_EGLDisplay
*disp
, _EGLContext
*ctx
,
1911 EGLClientBuffer buffer
,
1912 const EGLint
*attr_list
)
1914 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1915 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
1916 GLuint renderbuffer
= (GLuint
) (uintptr_t) buffer
;
1917 __DRIimage
*dri_image
;
1919 if (renderbuffer
== 0) {
1920 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
1921 return EGL_NO_IMAGE_KHR
;
1924 if (!disp
->Extensions
.KHR_gl_renderbuffer_image
) {
1925 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
1926 return EGL_NO_IMAGE_KHR
;
1929 if (dri2_dpy
->image
->base
.version
>= 17 &&
1930 dri2_dpy
->image
->createImageFromRenderbuffer2
) {
1931 unsigned error
= ~0;
1933 dri_image
= dri2_dpy
->image
->createImageFromRenderbuffer2(
1934 dri2_ctx
->dri_context
, renderbuffer
, NULL
, &error
);
1936 assert(!!dri_image
== (error
== __DRI_IMAGE_ERROR_SUCCESS
));
1939 _eglError(egl_error_from_dri_image_error(error
), "dri2_create_image_khr");
1940 return EGL_NO_IMAGE_KHR
;
1943 dri_image
= dri2_dpy
->image
->createImageFromRenderbuffer(
1944 dri2_ctx
->dri_context
, renderbuffer
, NULL
);
1946 _eglError(EGL_BAD_ALLOC
, "dri2_create_image_khr");
1947 return EGL_NO_IMAGE_KHR
;
1951 return dri2_create_image_from_dri(disp
, dri_image
);
1954 #ifdef HAVE_WAYLAND_PLATFORM
1956 /* This structure describes how a wl_buffer maps to one or more
1957 * __DRIimages. A wl_drm_buffer stores the wl_drm format code and the
1958 * offsets and strides of the planes in the buffer. This table maps a
1959 * wl_drm format code to a description of the planes in the buffer
1960 * that lets us create a __DRIimage for each of the planes. */
1962 static const struct wl_drm_components_descriptor
{
1963 uint32_t dri_components
;
1966 } wl_drm_components
[] = {
1967 { __DRI_IMAGE_COMPONENTS_RGB
, EGL_TEXTURE_RGB
, 1 },
1968 { __DRI_IMAGE_COMPONENTS_RGBA
, EGL_TEXTURE_RGBA
, 1 },
1969 { __DRI_IMAGE_COMPONENTS_Y_U_V
, EGL_TEXTURE_Y_U_V_WL
, 3 },
1970 { __DRI_IMAGE_COMPONENTS_Y_UV
, EGL_TEXTURE_Y_UV_WL
, 2 },
1971 { __DRI_IMAGE_COMPONENTS_Y_XUXV
, EGL_TEXTURE_Y_XUXV_WL
, 2 },
1975 dri2_create_image_wayland_wl_buffer(_EGLDisplay
*disp
, _EGLContext
*ctx
,
1976 EGLClientBuffer _buffer
,
1977 const EGLint
*attr_list
)
1979 struct wl_drm_buffer
*buffer
;
1980 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
1981 const struct wl_drm_components_descriptor
*f
;
1982 __DRIimage
*dri_image
;
1983 _EGLImageAttribs attrs
;
1986 buffer
= wayland_drm_buffer_get(dri2_dpy
->wl_server_drm
,
1987 (struct wl_resource
*) _buffer
);
1991 if (!_eglParseImageAttribList(&attrs
, disp
, attr_list
))
1994 plane
= attrs
.PlaneWL
;
1995 f
= buffer
->driver_format
;
1996 if (plane
< 0 || plane
>= f
->nplanes
) {
1997 _eglError(EGL_BAD_PARAMETER
,
1998 "dri2_create_image_wayland_wl_buffer (plane out of bounds)");
2002 dri_image
= dri2_dpy
->image
->fromPlanar(buffer
->driver_buffer
, plane
, NULL
);
2004 if (dri_image
== NULL
) {
2005 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_wayland_wl_buffer");
2009 return dri2_create_image_from_dri(disp
, dri_image
);
2014 dri2_get_sync_values_chromium(_EGLDisplay
*dpy
, _EGLSurface
*surf
,
2015 EGLuint64KHR
*ust
, EGLuint64KHR
*msc
,
2018 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
2019 return dri2_dpy
->vtbl
->get_sync_values(dpy
, surf
, ust
, msc
, sbc
);
2023 * Set the error code after a call to
2024 * dri2_egl_image::dri_image::createImageFromTexture.
2027 dri2_create_image_khr_texture_error(int dri_error
)
2029 EGLint egl_error
= egl_error_from_dri_image_error(dri_error
);
2031 if (egl_error
!= EGL_SUCCESS
)
2032 _eglError(egl_error
, "dri2_create_image_khr_texture");
2036 dri2_create_image_khr_texture(_EGLDisplay
*disp
, _EGLContext
*ctx
,
2038 EGLClientBuffer buffer
,
2039 const EGLint
*attr_list
)
2041 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2042 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
2043 struct dri2_egl_image
*dri2_img
;
2044 GLuint texture
= (GLuint
) (uintptr_t) buffer
;
2045 _EGLImageAttribs attrs
;
2051 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
2052 return EGL_NO_IMAGE_KHR
;
2055 if (!_eglParseImageAttribList(&attrs
, disp
, attr_list
))
2056 return EGL_NO_IMAGE_KHR
;
2059 case EGL_GL_TEXTURE_2D_KHR
:
2060 if (!disp
->Extensions
.KHR_gl_texture_2D_image
) {
2061 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
2062 return EGL_NO_IMAGE_KHR
;
2065 gl_target
= GL_TEXTURE_2D
;
2067 case EGL_GL_TEXTURE_3D_KHR
:
2068 if (!disp
->Extensions
.KHR_gl_texture_3D_image
) {
2069 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
2070 return EGL_NO_IMAGE_KHR
;
2073 depth
= attrs
.GLTextureZOffset
;
2074 gl_target
= GL_TEXTURE_3D
;
2076 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR
:
2077 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR
:
2078 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR
:
2079 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR
:
2080 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR
:
2081 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR
:
2082 if (!disp
->Extensions
.KHR_gl_texture_cubemap_image
) {
2083 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
2084 return EGL_NO_IMAGE_KHR
;
2087 depth
= target
- EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR
;
2088 gl_target
= GL_TEXTURE_CUBE_MAP
;
2091 unreachable("Unexpected target in dri2_create_image_khr_texture()");
2092 return EGL_NO_IMAGE_KHR
;
2095 dri2_img
= malloc(sizeof *dri2_img
);
2097 _eglError(EGL_BAD_ALLOC
, "dri2_create_image_khr");
2098 return EGL_NO_IMAGE_KHR
;
2101 _eglInitImage(&dri2_img
->base
, disp
);
2103 dri2_img
->dri_image
=
2104 dri2_dpy
->image
->createImageFromTexture(dri2_ctx
->dri_context
,
2108 attrs
.GLTextureLevel
,
2111 dri2_create_image_khr_texture_error(error
);
2113 if (!dri2_img
->dri_image
) {
2115 return EGL_NO_IMAGE_KHR
;
2117 return &dri2_img
->base
;
2121 dri2_query_surface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
2122 EGLint attribute
, EGLint
*value
)
2124 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
2125 if (!dri2_dpy
->vtbl
->query_surface
)
2126 return _eglQuerySurface(drv
, dpy
, surf
, attribute
, value
);
2127 return dri2_dpy
->vtbl
->query_surface(drv
, dpy
, surf
, attribute
, value
);
2130 static struct wl_buffer
*
2131 dri2_create_wayland_buffer_from_image(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
2134 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
2135 return dri2_dpy
->vtbl
->create_wayland_buffer_from_image(drv
, dpy
, img
);
2140 dri2_create_image_mesa_drm_buffer(_EGLDisplay
*disp
, _EGLContext
*ctx
,
2141 EGLClientBuffer buffer
, const EGLint
*attr_list
)
2143 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2144 EGLint format
, name
, pitch
;
2145 _EGLImageAttribs attrs
;
2146 __DRIimage
*dri_image
;
2148 name
= (EGLint
) (uintptr_t) buffer
;
2150 if (!_eglParseImageAttribList(&attrs
, disp
, attr_list
))
2153 if (attrs
.Width
<= 0 || attrs
.Height
<= 0 ||
2154 attrs
.DRMBufferStrideMESA
<= 0) {
2155 _eglError(EGL_BAD_PARAMETER
,
2156 "bad width, height or stride");
2160 switch (attrs
.DRMBufferFormatMESA
) {
2161 case EGL_DRM_BUFFER_FORMAT_ARGB32_MESA
:
2162 format
= __DRI_IMAGE_FORMAT_ARGB8888
;
2163 pitch
= attrs
.DRMBufferStrideMESA
;
2166 _eglError(EGL_BAD_PARAMETER
,
2167 "dri2_create_image_khr: unsupported pixmap depth");
2172 dri2_dpy
->image
->createImageFromName(dri2_dpy
->dri_screen
,
2180 return dri2_create_image_from_dri(disp
, dri_image
);
2184 dri2_check_dma_buf_attribs(const _EGLImageAttribs
*attrs
)
2189 * "Required attributes and their values are as follows:
2191 * * EGL_WIDTH & EGL_HEIGHT: The logical dimensions of the buffer in pixels
2193 * * EGL_LINUX_DRM_FOURCC_EXT: The pixel format of the buffer, as specified
2194 * by drm_fourcc.h and used as the pixel_format parameter of the
2195 * drm_mode_fb_cmd2 ioctl."
2199 * "* If <target> is EGL_LINUX_DMA_BUF_EXT, and the list of attributes is
2200 * incomplete, EGL_BAD_PARAMETER is generated."
2202 if (attrs
->Width
<= 0 || attrs
->Height
<= 0 ||
2203 !attrs
->DMABufFourCC
.IsPresent
)
2204 return _eglError(EGL_BAD_PARAMETER
, "attribute(s) missing");
2209 * "If <target> is EGL_LINUX_DMA_BUF_EXT and one or more of the values
2210 * specified for a plane's pitch or offset isn't supported by EGL,
2211 * EGL_BAD_ACCESS is generated."
2213 for (unsigned i
= 0; i
< ARRAY_SIZE(attrs
->DMABufPlanePitches
); ++i
) {
2214 if (attrs
->DMABufPlanePitches
[i
].IsPresent
&&
2215 attrs
->DMABufPlanePitches
[i
].Value
<= 0)
2216 return _eglError(EGL_BAD_ACCESS
, "invalid pitch");
2220 * If <target> is EGL_LINUX_DMA_BUF_EXT, both or neither of the following
2221 * attribute values may be given.
2223 * This is referring to EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT and
2224 * EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT, and the same for other planes.
2226 for (unsigned i
= 0; i
< DMA_BUF_MAX_PLANES
; ++i
) {
2227 if (attrs
->DMABufPlaneModifiersLo
[i
].IsPresent
!=
2228 attrs
->DMABufPlaneModifiersHi
[i
].IsPresent
)
2229 return _eglError(EGL_BAD_PARAMETER
, "modifier attribute lo or hi missing");
2232 /* Although the EGL_EXT_image_dma_buf_import_modifiers spec doesn't
2233 * mandate it, we only accept the same modifier across all planes. */
2234 for (unsigned i
= 1; i
< DMA_BUF_MAX_PLANES
; ++i
) {
2235 if (attrs
->DMABufPlaneFds
[i
].IsPresent
) {
2236 if ((attrs
->DMABufPlaneModifiersLo
[0].IsPresent
!=
2237 attrs
->DMABufPlaneModifiersLo
[i
].IsPresent
) ||
2238 (attrs
->DMABufPlaneModifiersLo
[0].Value
!=
2239 attrs
->DMABufPlaneModifiersLo
[i
].Value
) ||
2240 (attrs
->DMABufPlaneModifiersHi
[0].Value
!=
2241 attrs
->DMABufPlaneModifiersHi
[i
].Value
))
2242 return _eglError(EGL_BAD_PARAMETER
, "modifier attributes not equal");
2249 /* Returns the total number of file descriptors. Zero indicates an error. */
2251 dri2_check_dma_buf_format(const _EGLImageAttribs
*attrs
)
2255 switch (attrs
->DMABufFourCC
.Value
) {
2257 case DRM_FORMAT_RG88
:
2258 case DRM_FORMAT_GR88
:
2259 case DRM_FORMAT_R16
:
2260 case DRM_FORMAT_GR1616
:
2261 case DRM_FORMAT_RGB332
:
2262 case DRM_FORMAT_BGR233
:
2263 case DRM_FORMAT_XRGB4444
:
2264 case DRM_FORMAT_XBGR4444
:
2265 case DRM_FORMAT_RGBX4444
:
2266 case DRM_FORMAT_BGRX4444
:
2267 case DRM_FORMAT_ARGB4444
:
2268 case DRM_FORMAT_ABGR4444
:
2269 case DRM_FORMAT_RGBA4444
:
2270 case DRM_FORMAT_BGRA4444
:
2271 case DRM_FORMAT_XRGB1555
:
2272 case DRM_FORMAT_XBGR1555
:
2273 case DRM_FORMAT_RGBX5551
:
2274 case DRM_FORMAT_BGRX5551
:
2275 case DRM_FORMAT_ARGB1555
:
2276 case DRM_FORMAT_ABGR1555
:
2277 case DRM_FORMAT_RGBA5551
:
2278 case DRM_FORMAT_BGRA5551
:
2279 case DRM_FORMAT_RGB565
:
2280 case DRM_FORMAT_BGR565
:
2281 case DRM_FORMAT_RGB888
:
2282 case DRM_FORMAT_BGR888
:
2283 case DRM_FORMAT_XRGB8888
:
2284 case DRM_FORMAT_XBGR8888
:
2285 case DRM_FORMAT_RGBX8888
:
2286 case DRM_FORMAT_BGRX8888
:
2287 case DRM_FORMAT_ARGB8888
:
2288 case DRM_FORMAT_ABGR8888
:
2289 case DRM_FORMAT_RGBA8888
:
2290 case DRM_FORMAT_BGRA8888
:
2291 case DRM_FORMAT_XRGB2101010
:
2292 case DRM_FORMAT_XBGR2101010
:
2293 case DRM_FORMAT_RGBX1010102
:
2294 case DRM_FORMAT_BGRX1010102
:
2295 case DRM_FORMAT_ARGB2101010
:
2296 case DRM_FORMAT_ABGR2101010
:
2297 case DRM_FORMAT_RGBA1010102
:
2298 case DRM_FORMAT_BGRA1010102
:
2299 case DRM_FORMAT_YUYV
:
2300 case DRM_FORMAT_YVYU
:
2301 case DRM_FORMAT_UYVY
:
2302 case DRM_FORMAT_VYUY
:
2305 case DRM_FORMAT_NV12
:
2306 case DRM_FORMAT_NV21
:
2307 case DRM_FORMAT_NV16
:
2308 case DRM_FORMAT_NV61
:
2311 case DRM_FORMAT_YUV410
:
2312 case DRM_FORMAT_YVU410
:
2313 case DRM_FORMAT_YUV411
:
2314 case DRM_FORMAT_YVU411
:
2315 case DRM_FORMAT_YUV420
:
2316 case DRM_FORMAT_YVU420
:
2317 case DRM_FORMAT_YUV422
:
2318 case DRM_FORMAT_YVU422
:
2319 case DRM_FORMAT_YUV444
:
2320 case DRM_FORMAT_YVU444
:
2324 _eglError(EGL_BAD_ATTRIBUTE
, "invalid format");
2328 for (unsigned i
= plane_n
; i
< DMA_BUF_MAX_PLANES
; i
++) {
2330 * The modifiers extension spec says:
2332 * "Modifiers may modify any attribute of a buffer import, including
2333 * but not limited to adding extra planes to a format which
2334 * otherwise does not have those planes. As an example, a modifier
2335 * may add a plane for an external compression buffer to a
2336 * single-plane format. The exact meaning and effect of any
2337 * modifier is canonically defined by drm_fourcc.h, not as part of
2340 if (attrs
->DMABufPlaneModifiersLo
[i
].IsPresent
&&
2341 attrs
->DMABufPlaneModifiersHi
[i
].IsPresent
) {
2349 * "* If <target> is EGL_LINUX_DMA_BUF_EXT, and the list of attributes is
2350 * incomplete, EGL_BAD_PARAMETER is generated."
2352 for (unsigned i
= 0; i
< plane_n
; ++i
) {
2353 if (!attrs
->DMABufPlaneFds
[i
].IsPresent
||
2354 !attrs
->DMABufPlaneOffsets
[i
].IsPresent
||
2355 !attrs
->DMABufPlanePitches
[i
].IsPresent
) {
2356 _eglError(EGL_BAD_PARAMETER
, "plane attribute(s) missing");
2362 * The spec also says:
2364 * "If <target> is EGL_LINUX_DMA_BUF_EXT, and the EGL_LINUX_DRM_FOURCC_EXT
2365 * attribute indicates a single-plane format, EGL_BAD_ATTRIBUTE is
2366 * generated if any of the EGL_DMA_BUF_PLANE1_* or EGL_DMA_BUF_PLANE2_*
2367 * or EGL_DMA_BUF_PLANE3_* attributes are specified."
2369 for (unsigned i
= plane_n
; i
< DMA_BUF_MAX_PLANES
; ++i
) {
2370 if (attrs
->DMABufPlaneFds
[i
].IsPresent
||
2371 attrs
->DMABufPlaneOffsets
[i
].IsPresent
||
2372 attrs
->DMABufPlanePitches
[i
].IsPresent
) {
2373 _eglError(EGL_BAD_ATTRIBUTE
, "too many plane attributes");
2382 dri2_query_dma_buf_formats(_EGLDriver
*drv
, _EGLDisplay
*disp
,
2383 EGLint max
, EGLint
*formats
, EGLint
*count
)
2385 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2386 if (max
< 0 || (max
> 0 && formats
== NULL
))
2387 return _eglError(EGL_BAD_PARAMETER
, "invalid value for max count of formats");
2389 if (dri2_dpy
->image
->base
.version
< 15 ||
2390 dri2_dpy
->image
->queryDmaBufFormats
== NULL
)
2393 if (!dri2_dpy
->image
->queryDmaBufFormats(dri2_dpy
->dri_screen
, max
,
2401 dri2_query_dma_buf_modifiers(_EGLDriver
*drv
, _EGLDisplay
*disp
, EGLint format
,
2402 EGLint max
, EGLuint64KHR
*modifiers
,
2403 EGLBoolean
*external_only
, EGLint
*count
)
2405 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2408 return _eglError(EGL_BAD_PARAMETER
, "invalid value for max count of formats");
2410 if (max
> 0 && modifiers
== NULL
)
2411 return _eglError(EGL_BAD_PARAMETER
, "invalid modifiers array");
2413 if (dri2_dpy
->image
->base
.version
< 15 ||
2414 dri2_dpy
->image
->queryDmaBufModifiers
== NULL
)
2417 if (dri2_dpy
->image
->queryDmaBufModifiers(dri2_dpy
->dri_screen
, format
,
2419 (unsigned int *) external_only
,
2421 return _eglError(EGL_BAD_PARAMETER
, "invalid format");
2429 * "If eglCreateImageKHR is successful for a EGL_LINUX_DMA_BUF_EXT target, the
2430 * EGL will take a reference to the dma_buf(s) which it will release at any
2431 * time while the EGLDisplay is initialized. It is the responsibility of the
2432 * application to close the dma_buf file descriptors."
2434 * Therefore we must never close or otherwise modify the file descriptors.
2437 dri2_create_image_dma_buf(_EGLDisplay
*disp
, _EGLContext
*ctx
,
2438 EGLClientBuffer buffer
, const EGLint
*attr_list
)
2440 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2442 _EGLImageAttribs attrs
;
2443 __DRIimage
*dri_image
;
2445 int fds
[DMA_BUF_MAX_PLANES
];
2446 int pitches
[DMA_BUF_MAX_PLANES
];
2447 int offsets
[DMA_BUF_MAX_PLANES
];
2449 bool has_modifier
= false;
2455 * ""* If <target> is EGL_LINUX_DMA_BUF_EXT and <buffer> is not NULL, the
2456 * error EGL_BAD_PARAMETER is generated."
2458 if (buffer
!= NULL
) {
2459 _eglError(EGL_BAD_PARAMETER
, "buffer not NULL");
2463 if (!_eglParseImageAttribList(&attrs
, disp
, attr_list
))
2466 if (!dri2_check_dma_buf_attribs(&attrs
))
2469 num_fds
= dri2_check_dma_buf_format(&attrs
);
2473 for (unsigned i
= 0; i
< num_fds
; ++i
) {
2474 fds
[i
] = attrs
.DMABufPlaneFds
[i
].Value
;
2475 pitches
[i
] = attrs
.DMABufPlanePitches
[i
].Value
;
2476 offsets
[i
] = attrs
.DMABufPlaneOffsets
[i
].Value
;
2479 /* dri2_check_dma_buf_attribs ensures that the modifier, if available,
2480 * will be present in attrs.DMABufPlaneModifiersLo[0] and
2481 * attrs.DMABufPlaneModifiersHi[0] */
2482 if (attrs
.DMABufPlaneModifiersLo
[0].IsPresent
) {
2483 modifier
= (uint64_t) attrs
.DMABufPlaneModifiersHi
[0].Value
<< 32;
2484 modifier
|= (uint64_t) (attrs
.DMABufPlaneModifiersLo
[0].Value
& 0xffffffff);
2485 has_modifier
= true;
2489 if (dri2_dpy
->image
->base
.version
< 15 ||
2490 dri2_dpy
->image
->createImageFromDmaBufs2
== NULL
) {
2491 _eglError(EGL_BAD_MATCH
, "unsupported dma_buf format modifier");
2492 return EGL_NO_IMAGE_KHR
;
2495 dri2_dpy
->image
->createImageFromDmaBufs2(dri2_dpy
->dri_screen
,
2496 attrs
.Width
, attrs
.Height
, attrs
.DMABufFourCC
.Value
,
2497 modifier
, fds
, num_fds
, pitches
, offsets
,
2498 attrs
.DMABufYuvColorSpaceHint
.Value
,
2499 attrs
.DMABufSampleRangeHint
.Value
,
2500 attrs
.DMABufChromaHorizontalSiting
.Value
,
2501 attrs
.DMABufChromaVerticalSiting
.Value
,
2507 dri2_dpy
->image
->createImageFromDmaBufs(dri2_dpy
->dri_screen
,
2508 attrs
.Width
, attrs
.Height
, attrs
.DMABufFourCC
.Value
,
2509 fds
, num_fds
, pitches
, offsets
,
2510 attrs
.DMABufYuvColorSpaceHint
.Value
,
2511 attrs
.DMABufSampleRangeHint
.Value
,
2512 attrs
.DMABufChromaHorizontalSiting
.Value
,
2513 attrs
.DMABufChromaVerticalSiting
.Value
,
2517 dri2_create_image_khr_texture_error(error
);
2520 return EGL_NO_IMAGE_KHR
;
2522 res
= dri2_create_image_from_dri(disp
, dri_image
);
2527 dri2_create_drm_image_mesa(_EGLDriver
*drv
, _EGLDisplay
*disp
,
2528 const EGLint
*attr_list
)
2530 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2531 struct dri2_egl_image
*dri2_img
;
2532 _EGLImageAttribs attrs
;
2533 unsigned int dri_use
, valid_mask
;
2539 _eglError(EGL_BAD_PARAMETER
, __func__
);
2540 return EGL_NO_IMAGE_KHR
;
2543 if (!_eglParseImageAttribList(&attrs
, disp
, attr_list
))
2544 return EGL_NO_IMAGE_KHR
;
2546 if (attrs
.Width
<= 0 || attrs
.Height
<= 0) {
2547 _eglError(EGL_BAD_PARAMETER
, __func__
);
2548 return EGL_NO_IMAGE_KHR
;
2551 switch (attrs
.DRMBufferFormatMESA
) {
2552 case EGL_DRM_BUFFER_FORMAT_ARGB32_MESA
:
2553 format
= __DRI_IMAGE_FORMAT_ARGB8888
;
2556 _eglError(EGL_BAD_PARAMETER
, __func__
);
2557 return EGL_NO_IMAGE_KHR
;
2561 EGL_DRM_BUFFER_USE_SCANOUT_MESA
|
2562 EGL_DRM_BUFFER_USE_SHARE_MESA
|
2563 EGL_DRM_BUFFER_USE_CURSOR_MESA
;
2564 if (attrs
.DRMBufferUseMESA
& ~valid_mask
) {
2565 _eglError(EGL_BAD_PARAMETER
, __func__
);
2566 return EGL_NO_IMAGE_KHR
;
2570 if (attrs
.DRMBufferUseMESA
& EGL_DRM_BUFFER_USE_SHARE_MESA
)
2571 dri_use
|= __DRI_IMAGE_USE_SHARE
;
2572 if (attrs
.DRMBufferUseMESA
& EGL_DRM_BUFFER_USE_SCANOUT_MESA
)
2573 dri_use
|= __DRI_IMAGE_USE_SCANOUT
;
2574 if (attrs
.DRMBufferUseMESA
& EGL_DRM_BUFFER_USE_CURSOR_MESA
)
2575 dri_use
|= __DRI_IMAGE_USE_CURSOR
;
2577 dri2_img
= malloc(sizeof *dri2_img
);
2579 _eglError(EGL_BAD_ALLOC
, "dri2_create_image_khr");
2580 return EGL_NO_IMAGE_KHR
;
2583 _eglInitImage(&dri2_img
->base
, disp
);
2585 dri2_img
->dri_image
=
2586 dri2_dpy
->image
->createImage(dri2_dpy
->dri_screen
,
2587 attrs
.Width
, attrs
.Height
,
2588 format
, dri_use
, dri2_img
);
2589 if (dri2_img
->dri_image
== NULL
) {
2591 _eglError(EGL_BAD_ALLOC
, "dri2_create_drm_image_mesa");
2592 return EGL_NO_IMAGE_KHR
;
2595 return &dri2_img
->base
;
2599 dri2_export_drm_image_mesa(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLImage
*img
,
2600 EGLint
*name
, EGLint
*handle
, EGLint
*stride
)
2602 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2603 struct dri2_egl_image
*dri2_img
= dri2_egl_image(img
);
2607 if (name
&& !dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2608 __DRI_IMAGE_ATTRIB_NAME
, name
))
2609 return _eglError(EGL_BAD_ALLOC
, "dri2_export_drm_image_mesa");
2612 dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2613 __DRI_IMAGE_ATTRIB_HANDLE
, handle
);
2616 dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2617 __DRI_IMAGE_ATTRIB_STRIDE
, stride
);
2623 dri2_export_dma_buf_image_query_mesa(_EGLDriver
*drv
, _EGLDisplay
*disp
,
2625 EGLint
*fourcc
, EGLint
*nplanes
,
2626 EGLuint64KHR
*modifiers
)
2628 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2629 struct dri2_egl_image
*dri2_img
= dri2_egl_image(img
);
2635 dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2636 __DRI_IMAGE_ATTRIB_NUM_PLANES
, nplanes
);
2638 dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2639 __DRI_IMAGE_ATTRIB_FOURCC
, fourcc
);
2648 dri2_export_dma_buf_image_mesa(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLImage
*img
,
2649 int *fds
, EGLint
*strides
, EGLint
*offsets
)
2651 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2652 struct dri2_egl_image
*dri2_img
= dri2_egl_image(img
);
2656 /* rework later to provide multiple fds/strides/offsets */
2658 dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2659 __DRI_IMAGE_ATTRIB_FD
, fds
);
2662 dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2663 __DRI_IMAGE_ATTRIB_STRIDE
, strides
);
2667 bool ret
= dri2_dpy
->image
->queryImage(dri2_img
->dri_image
,
2668 __DRI_IMAGE_ATTRIB_OFFSET
, &img_offset
);
2670 offsets
[0] = img_offset
;
2681 dri2_create_image_khr(_EGLDriver
*drv
, _EGLDisplay
*disp
,
2682 _EGLContext
*ctx
, EGLenum target
,
2683 EGLClientBuffer buffer
, const EGLint
*attr_list
)
2688 case EGL_GL_TEXTURE_2D_KHR
:
2689 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR
:
2690 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR
:
2691 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR
:
2692 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR
:
2693 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR
:
2694 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR
:
2695 case EGL_GL_TEXTURE_3D_KHR
:
2696 return dri2_create_image_khr_texture(disp
, ctx
, target
, buffer
, attr_list
);
2697 case EGL_GL_RENDERBUFFER_KHR
:
2698 return dri2_create_image_khr_renderbuffer(disp
, ctx
, buffer
, attr_list
);
2700 case EGL_DRM_BUFFER_MESA
:
2701 return dri2_create_image_mesa_drm_buffer(disp
, ctx
, buffer
, attr_list
);
2702 case EGL_LINUX_DMA_BUF_EXT
:
2703 return dri2_create_image_dma_buf(disp
, ctx
, buffer
, attr_list
);
2705 #ifdef HAVE_WAYLAND_PLATFORM
2706 case EGL_WAYLAND_BUFFER_WL
:
2707 return dri2_create_image_wayland_wl_buffer(disp
, ctx
, buffer
, attr_list
);
2710 _eglError(EGL_BAD_PARAMETER
, "dri2_create_image_khr");
2711 return EGL_NO_IMAGE_KHR
;
2716 dri2_destroy_image_khr(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLImage
*image
)
2718 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2719 struct dri2_egl_image
*dri2_img
= dri2_egl_image(image
);
2723 dri2_dpy
->image
->destroyImage(dri2_img
->dri_image
);
2729 #ifdef HAVE_WAYLAND_PLATFORM
2732 dri2_wl_reference_buffer(void *user_data
, uint32_t name
, int fd
,
2733 struct wl_drm_buffer
*buffer
)
2735 _EGLDisplay
*disp
= user_data
;
2736 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2738 int dri_components
= 0;
2741 img
= dri2_dpy
->image
->createImageFromNames(dri2_dpy
->dri_screen
,
2750 img
= dri2_dpy
->image
->createImageFromFds(dri2_dpy
->dri_screen
,
2762 dri2_dpy
->image
->queryImage(img
, __DRI_IMAGE_ATTRIB_COMPONENTS
, &dri_components
);
2764 buffer
->driver_format
= NULL
;
2765 for (int i
= 0; i
< ARRAY_SIZE(wl_drm_components
); i
++)
2766 if (wl_drm_components
[i
].dri_components
== dri_components
)
2767 buffer
->driver_format
= &wl_drm_components
[i
];
2769 if (buffer
->driver_format
== NULL
)
2770 dri2_dpy
->image
->destroyImage(img
);
2772 buffer
->driver_buffer
= img
;
2776 dri2_wl_release_buffer(void *user_data
, struct wl_drm_buffer
*buffer
)
2778 _EGLDisplay
*disp
= user_data
;
2779 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2781 dri2_dpy
->image
->destroyImage(buffer
->driver_buffer
);
2785 dri2_bind_wayland_display_wl(_EGLDriver
*drv
, _EGLDisplay
*disp
,
2786 struct wl_display
*wl_dpy
)
2788 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2789 const struct wayland_drm_callbacks wl_drm_callbacks
= {
2790 .authenticate
= (int(*)(void *, uint32_t)) dri2_dpy
->vtbl
->authenticate
,
2791 .reference_buffer
= dri2_wl_reference_buffer
,
2792 .release_buffer
= dri2_wl_release_buffer
2799 if (dri2_dpy
->wl_server_drm
)
2802 if (drmGetCap(dri2_dpy
->fd
, DRM_CAP_PRIME
, &cap
) == 0 &&
2803 cap
== (DRM_PRIME_CAP_IMPORT
| DRM_PRIME_CAP_EXPORT
) &&
2804 dri2_dpy
->image
->base
.version
>= 7 &&
2805 dri2_dpy
->image
->createImageFromFds
!= NULL
)
2806 flags
|= WAYLAND_DRM_PRIME
;
2808 dri2_dpy
->wl_server_drm
=
2809 wayland_drm_init(wl_dpy
, dri2_dpy
->device_name
,
2810 &wl_drm_callbacks
, disp
, flags
);
2812 if (!dri2_dpy
->wl_server_drm
)
2815 #ifdef HAVE_DRM_PLATFORM
2816 /* We have to share the wl_drm instance with gbm, so gbm can convert
2817 * wl_buffers to gbm bos. */
2818 if (dri2_dpy
->gbm_dri
)
2819 dri2_dpy
->gbm_dri
->wl_drm
= dri2_dpy
->wl_server_drm
;
2826 dri2_unbind_wayland_display_wl(_EGLDriver
*drv
, _EGLDisplay
*disp
,
2827 struct wl_display
*wl_dpy
)
2829 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2833 if (!dri2_dpy
->wl_server_drm
)
2836 wayland_drm_uninit(dri2_dpy
->wl_server_drm
);
2837 dri2_dpy
->wl_server_drm
= NULL
;
2843 dri2_query_wayland_buffer_wl(_EGLDriver
*drv
, _EGLDisplay
*disp
,
2844 struct wl_resource
*buffer_resource
,
2845 EGLint attribute
, EGLint
*value
)
2847 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(disp
);
2848 struct wl_drm_buffer
*buffer
;
2849 const struct wl_drm_components_descriptor
*format
;
2851 buffer
= wayland_drm_buffer_get(dri2_dpy
->wl_server_drm
, buffer_resource
);
2855 format
= buffer
->driver_format
;
2856 switch (attribute
) {
2857 case EGL_TEXTURE_FORMAT
:
2858 *value
= format
->components
;
2861 *value
= buffer
->width
;
2864 *value
= buffer
->height
;
2873 dri2_egl_ref_sync(struct dri2_egl_sync
*sync
)
2875 p_atomic_inc(&sync
->refcount
);
2879 dri2_egl_unref_sync(struct dri2_egl_display
*dri2_dpy
,
2880 struct dri2_egl_sync
*dri2_sync
)
2882 if (p_atomic_dec_zero(&dri2_sync
->refcount
)) {
2883 switch (dri2_sync
->base
.Type
) {
2884 case EGL_SYNC_REUSABLE_KHR
:
2885 cnd_destroy(&dri2_sync
->cond
);
2887 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
2888 if (dri2_sync
->base
.SyncFd
!= EGL_NO_NATIVE_FENCE_FD_ANDROID
)
2889 close(dri2_sync
->base
.SyncFd
);
2895 if (dri2_sync
->fence
)
2896 dri2_dpy
->fence
->destroy_fence(dri2_dpy
->dri_screen
, dri2_sync
->fence
);
2903 dri2_create_sync(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
2904 EGLenum type
, const EGLAttrib
*attrib_list
)
2906 _EGLContext
*ctx
= _eglGetCurrentContext();
2907 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
2908 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
2909 struct dri2_egl_sync
*dri2_sync
;
2911 pthread_condattr_t attr
;
2913 dri2_sync
= calloc(1, sizeof(struct dri2_egl_sync
));
2915 _eglError(EGL_BAD_ALLOC
, "eglCreateSyncKHR");
2919 if (!_eglInitSync(&dri2_sync
->base
, dpy
, type
, attrib_list
)) {
2925 case EGL_SYNC_FENCE_KHR
:
2926 dri2_sync
->fence
= dri2_dpy
->fence
->create_fence(dri2_ctx
->dri_context
);
2927 if (!dri2_sync
->fence
) {
2928 /* Why did it fail? DRI doesn't return an error code, so we emit
2929 * a generic EGL error that doesn't communicate user error.
2931 _eglError(EGL_BAD_ALLOC
, "eglCreateSyncKHR");
2937 case EGL_SYNC_CL_EVENT_KHR
:
2938 dri2_sync
->fence
= dri2_dpy
->fence
->get_fence_from_cl_event(
2939 dri2_dpy
->dri_screen
,
2940 dri2_sync
->base
.CLEvent
);
2941 /* this can only happen if the cl_event passed in is invalid. */
2942 if (!dri2_sync
->fence
) {
2943 _eglError(EGL_BAD_ATTRIBUTE
, "eglCreateSyncKHR");
2948 /* the initial status must be "signaled" if the cl_event is signaled */
2949 if (dri2_dpy
->fence
->client_wait_sync(dri2_ctx
->dri_context
,
2950 dri2_sync
->fence
, 0, 0))
2951 dri2_sync
->base
.SyncStatus
= EGL_SIGNALED_KHR
;
2954 case EGL_SYNC_REUSABLE_KHR
:
2955 /* intialize attr */
2956 ret
= pthread_condattr_init(&attr
);
2959 _eglError(EGL_BAD_ACCESS
, "eglCreateSyncKHR");
2964 /* change clock attribute to CLOCK_MONOTONIC */
2965 ret
= pthread_condattr_setclock(&attr
, CLOCK_MONOTONIC
);
2968 _eglError(EGL_BAD_ACCESS
, "eglCreateSyncKHR");
2973 ret
= pthread_cond_init(&dri2_sync
->cond
, &attr
);
2976 _eglError(EGL_BAD_ACCESS
, "eglCreateSyncKHR");
2981 /* initial status of reusable sync must be "unsignaled" */
2982 dri2_sync
->base
.SyncStatus
= EGL_UNSIGNALED_KHR
;
2985 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
2986 if (dri2_dpy
->fence
->create_fence_fd
) {
2987 dri2_sync
->fence
= dri2_dpy
->fence
->create_fence_fd(
2988 dri2_ctx
->dri_context
,
2989 dri2_sync
->base
.SyncFd
);
2991 if (!dri2_sync
->fence
) {
2992 _eglError(EGL_BAD_ATTRIBUTE
, "eglCreateSyncKHR");
2999 p_atomic_set(&dri2_sync
->refcount
, 1);
3000 return &dri2_sync
->base
;
3004 dri2_destroy_sync(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSync
*sync
)
3006 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
3007 struct dri2_egl_sync
*dri2_sync
= dri2_egl_sync(sync
);
3008 EGLint ret
= EGL_TRUE
;
3011 /* if type of sync is EGL_SYNC_REUSABLE_KHR and it is not signaled yet,
3012 * then unlock all threads possibly blocked by the reusable sync before
3015 if (dri2_sync
->base
.Type
== EGL_SYNC_REUSABLE_KHR
&&
3016 dri2_sync
->base
.SyncStatus
== EGL_UNSIGNALED_KHR
) {
3017 dri2_sync
->base
.SyncStatus
= EGL_SIGNALED_KHR
;
3018 /* unblock all threads currently blocked by sync */
3019 err
= cnd_broadcast(&dri2_sync
->cond
);
3022 _eglError(EGL_BAD_ACCESS
, "eglDestroySyncKHR");
3027 dri2_egl_unref_sync(dri2_dpy
, dri2_sync
);
3033 dri2_dup_native_fence_fd(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSync
*sync
)
3035 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
3036 struct dri2_egl_sync
*dri2_sync
= dri2_egl_sync(sync
);
3038 assert(sync
->Type
== EGL_SYNC_NATIVE_FENCE_ANDROID
);
3040 if (sync
->SyncFd
== EGL_NO_NATIVE_FENCE_FD_ANDROID
) {
3041 /* try to retrieve the actual native fence fd.. if rendering is
3042 * not flushed this will just return -1, aka NO_NATIVE_FENCE_FD:
3044 sync
->SyncFd
= dri2_dpy
->fence
->get_fence_fd(dri2_dpy
->dri_screen
,
3048 if (sync
->SyncFd
== EGL_NO_NATIVE_FENCE_FD_ANDROID
) {
3049 /* if native fence fd still not created, return an error: */
3050 _eglError(EGL_BAD_PARAMETER
, "eglDupNativeFenceFDANDROID");
3051 return EGL_NO_NATIVE_FENCE_FD_ANDROID
;
3054 return dup(sync
->SyncFd
);
3058 dri2_client_wait_sync(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSync
*sync
,
3059 EGLint flags
, EGLTime timeout
)
3061 _EGLContext
*ctx
= _eglGetCurrentContext();
3062 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
3063 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
3064 struct dri2_egl_sync
*dri2_sync
= dri2_egl_sync(sync
);
3065 unsigned wait_flags
= 0;
3067 EGLint ret
= EGL_CONDITION_SATISFIED_KHR
;
3069 /* The EGL_KHR_fence_sync spec states:
3071 * "If no context is current for the bound API,
3072 * the EGL_SYNC_FLUSH_COMMANDS_BIT_KHR bit is ignored.
3074 if (dri2_ctx
&& flags
& EGL_SYNC_FLUSH_COMMANDS_BIT_KHR
)
3075 wait_flags
|= __DRI2_FENCE_FLAG_FLUSH_COMMANDS
;
3077 /* the sync object should take a reference while waiting */
3078 dri2_egl_ref_sync(dri2_sync
);
3080 switch (sync
->Type
) {
3081 case EGL_SYNC_FENCE_KHR
:
3082 case EGL_SYNC_NATIVE_FENCE_ANDROID
:
3083 case EGL_SYNC_CL_EVENT_KHR
:
3084 if (dri2_dpy
->fence
->client_wait_sync(dri2_ctx
? dri2_ctx
->dri_context
: NULL
,
3085 dri2_sync
->fence
, wait_flags
,
3087 dri2_sync
->base
.SyncStatus
= EGL_SIGNALED_KHR
;
3089 ret
= EGL_TIMEOUT_EXPIRED_KHR
;
3092 case EGL_SYNC_REUSABLE_KHR
:
3093 if (dri2_ctx
&& dri2_sync
->base
.SyncStatus
== EGL_UNSIGNALED_KHR
&&
3094 (flags
& EGL_SYNC_FLUSH_COMMANDS_BIT_KHR
)) {
3095 /* flush context if EGL_SYNC_FLUSH_COMMANDS_BIT_KHR is set */
3099 /* if timeout is EGL_FOREVER_KHR, it should wait without any timeout.*/
3100 if (timeout
== EGL_FOREVER_KHR
) {
3101 mtx_lock(&dri2_sync
->mutex
);
3102 cnd_wait(&dri2_sync
->cond
, &dri2_sync
->mutex
);
3103 mtx_unlock(&dri2_sync
->mutex
);
3105 /* if reusable sync has not been yet signaled */
3106 if (dri2_sync
->base
.SyncStatus
!= EGL_SIGNALED_KHR
) {
3107 /* timespecs for cnd_timedwait */
3108 struct timespec current
;
3109 struct timespec expire
;
3111 /* We override the clock to monotonic when creating the condition
3113 clock_gettime(CLOCK_MONOTONIC
, ¤t
);
3115 /* calculating when to expire */
3116 expire
.tv_nsec
= timeout
% 1000000000L;
3117 expire
.tv_sec
= timeout
/ 1000000000L;
3119 expire
.tv_nsec
+= current
.tv_nsec
;
3120 expire
.tv_sec
+= current
.tv_sec
;
3122 /* expire.nsec now is a number between 0 and 1999999998 */
3123 if (expire
.tv_nsec
> 999999999L) {
3125 expire
.tv_nsec
-= 1000000000L;
3128 mtx_lock(&dri2_sync
->mutex
);
3129 ret
= cnd_timedwait(&dri2_sync
->cond
, &dri2_sync
->mutex
, &expire
);
3130 mtx_unlock(&dri2_sync
->mutex
);
3132 if (ret
== thrd_busy
) {
3133 if (dri2_sync
->base
.SyncStatus
== EGL_UNSIGNALED_KHR
) {
3134 ret
= EGL_TIMEOUT_EXPIRED_KHR
;
3136 _eglError(EGL_BAD_ACCESS
, "eglClientWaitSyncKHR");
3144 dri2_egl_unref_sync(dri2_dpy
, dri2_sync
);
3150 dri2_signal_sync(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSync
*sync
,
3153 struct dri2_egl_sync
*dri2_sync
= dri2_egl_sync(sync
);
3156 if (sync
->Type
!= EGL_SYNC_REUSABLE_KHR
)
3157 return _eglError(EGL_BAD_MATCH
, "eglSignalSyncKHR");
3159 if (mode
!= EGL_SIGNALED_KHR
&& mode
!= EGL_UNSIGNALED_KHR
)
3160 return _eglError(EGL_BAD_ATTRIBUTE
, "eglSignalSyncKHR");
3162 dri2_sync
->base
.SyncStatus
= mode
;
3164 if (mode
== EGL_SIGNALED_KHR
) {
3165 ret
= cnd_broadcast(&dri2_sync
->cond
);
3167 /* fail to broadcast */
3169 return _eglError(EGL_BAD_ACCESS
, "eglSignalSyncKHR");
3176 dri2_server_wait_sync(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSync
*sync
)
3178 _EGLContext
*ctx
= _eglGetCurrentContext();
3179 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
3180 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
3181 struct dri2_egl_sync
*dri2_sync
= dri2_egl_sync(sync
);
3183 dri2_dpy
->fence
->server_wait_sync(dri2_ctx
->dri_context
,
3184 dri2_sync
->fence
, 0);
3189 dri2_interop_query_device_info(_EGLDisplay
*dpy
, _EGLContext
*ctx
,
3190 struct mesa_glinterop_device_info
*out
)
3192 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
3193 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
3195 if (!dri2_dpy
->interop
)
3196 return MESA_GLINTEROP_UNSUPPORTED
;
3198 return dri2_dpy
->interop
->query_device_info(dri2_ctx
->dri_context
, out
);
3202 dri2_interop_export_object(_EGLDisplay
*dpy
, _EGLContext
*ctx
,
3203 struct mesa_glinterop_export_in
*in
,
3204 struct mesa_glinterop_export_out
*out
)
3206 struct dri2_egl_display
*dri2_dpy
= dri2_egl_display(dpy
);
3207 struct dri2_egl_context
*dri2_ctx
= dri2_egl_context(ctx
);
3209 if (!dri2_dpy
->interop
)
3210 return MESA_GLINTEROP_UNSUPPORTED
;
3212 return dri2_dpy
->interop
->export_object(dri2_ctx
->dri_context
, in
, out
);
3216 * This is the main entrypoint into the driver, called by libEGL.
3217 * Create a new _EGLDriver object and init its dispatch table.
3220 _eglBuiltInDriver(void)
3222 _EGLDriver
*dri2_drv
= calloc(1, sizeof *dri2_drv
);
3226 _eglInitDriverFallbacks(dri2_drv
);
3227 dri2_drv
->API
.Initialize
= dri2_initialize
;
3228 dri2_drv
->API
.Terminate
= dri2_terminate
;
3229 dri2_drv
->API
.CreateContext
= dri2_create_context
;
3230 dri2_drv
->API
.DestroyContext
= dri2_destroy_context
;
3231 dri2_drv
->API
.MakeCurrent
= dri2_make_current
;
3232 dri2_drv
->API
.CreateWindowSurface
= dri2_create_window_surface
;
3233 dri2_drv
->API
.CreatePixmapSurface
= dri2_create_pixmap_surface
;
3234 dri2_drv
->API
.CreatePbufferSurface
= dri2_create_pbuffer_surface
;
3235 dri2_drv
->API
.DestroySurface
= dri2_destroy_surface
;
3236 dri2_drv
->API
.GetProcAddress
= dri2_get_proc_address
;
3237 dri2_drv
->API
.WaitClient
= dri2_wait_client
;
3238 dri2_drv
->API
.WaitNative
= dri2_wait_native
;
3239 dri2_drv
->API
.BindTexImage
= dri2_bind_tex_image
;
3240 dri2_drv
->API
.ReleaseTexImage
= dri2_release_tex_image
;
3241 dri2_drv
->API
.SwapInterval
= dri2_swap_interval
;
3242 dri2_drv
->API
.SwapBuffers
= dri2_swap_buffers
;
3243 dri2_drv
->API
.SwapBuffersWithDamageEXT
= dri2_swap_buffers_with_damage
;
3244 dri2_drv
->API
.SwapBuffersRegionNOK
= dri2_swap_buffers_region
;
3245 dri2_drv
->API
.SetDamageRegion
= dri2_set_damage_region
;
3246 dri2_drv
->API
.PostSubBufferNV
= dri2_post_sub_buffer
;
3247 dri2_drv
->API
.CopyBuffers
= dri2_copy_buffers
,
3248 dri2_drv
->API
.QueryBufferAge
= dri2_query_buffer_age
;
3249 dri2_drv
->API
.CreateImageKHR
= dri2_create_image
;
3250 dri2_drv
->API
.DestroyImageKHR
= dri2_destroy_image_khr
;
3251 dri2_drv
->API
.CreateWaylandBufferFromImageWL
= dri2_create_wayland_buffer_from_image
;
3252 dri2_drv
->API
.QuerySurface
= dri2_query_surface
;
3254 dri2_drv
->API
.CreateDRMImageMESA
= dri2_create_drm_image_mesa
;
3255 dri2_drv
->API
.ExportDRMImageMESA
= dri2_export_drm_image_mesa
;
3256 dri2_drv
->API
.ExportDMABUFImageQueryMESA
= dri2_export_dma_buf_image_query_mesa
;
3257 dri2_drv
->API
.ExportDMABUFImageMESA
= dri2_export_dma_buf_image_mesa
;
3258 dri2_drv
->API
.QueryDmaBufFormatsEXT
= dri2_query_dma_buf_formats
;
3259 dri2_drv
->API
.QueryDmaBufModifiersEXT
= dri2_query_dma_buf_modifiers
;
3261 #ifdef HAVE_WAYLAND_PLATFORM
3262 dri2_drv
->API
.BindWaylandDisplayWL
= dri2_bind_wayland_display_wl
;
3263 dri2_drv
->API
.UnbindWaylandDisplayWL
= dri2_unbind_wayland_display_wl
;
3264 dri2_drv
->API
.QueryWaylandBufferWL
= dri2_query_wayland_buffer_wl
;
3266 dri2_drv
->API
.GetSyncValuesCHROMIUM
= dri2_get_sync_values_chromium
;
3267 dri2_drv
->API
.CreateSyncKHR
= dri2_create_sync
;
3268 dri2_drv
->API
.ClientWaitSyncKHR
= dri2_client_wait_sync
;
3269 dri2_drv
->API
.SignalSyncKHR
= dri2_signal_sync
;
3270 dri2_drv
->API
.WaitSyncKHR
= dri2_server_wait_sync
;
3271 dri2_drv
->API
.DestroySyncKHR
= dri2_destroy_sync
;
3272 dri2_drv
->API
.GLInteropQueryDeviceInfo
= dri2_interop_query_device_info
;
3273 dri2_drv
->API
.GLInteropExportObject
= dri2_interop_export_object
;
3274 dri2_drv
->API
.DupNativeFenceFDANDROID
= dri2_dup_native_fence_fd
;
3276 dri2_drv
->Name
= "DRI2";