[Mesa-dev] [PATCH 10/10] egl: add EGL_platform_device support
Eric Engestrom
eric.engestrom at intel.com
Wed Aug 29 11:16:56 UTC 2018
On Friday, 2018-08-03 13:44:26 +0100, Emil Velikov wrote:
> From: Emil Velikov <emil.velikov at collabora.com>
>
> This new 'platform' is added by default with no guards.
>
> It is effectively a copy of the surfaceless one, with updated function
> names and brand new probe function.
>
> Due to the reuse, some of the ifdef HAVE_SURFACELESS_PLATFORM guards
> have been dropped.
>
> A worthy mention are the changes in _egFindDisplay, since the original
> and dup'd fd are required, we make use of the plat_opt argument.
>
> Note that no hacks for eglGetDisplay are added - the API works only with
> the eglGetPlatformDisplay* API.
>
> Signed-off-by: Emil Velikov <emil.velikov at collabora.com>
> ---
> TODO/XXX:
> - fold/reuse more of surfaceless
> - swrast is hacky/broken - needs some DRI changes that I'm working atm.
> - remove local define
> ---
> src/egl/Makefile.am | 3 +
> src/egl/drivers/dri2/egl_dri2.c | 3 +
> src/egl/drivers/dri2/egl_dri2.h | 11 +-
> src/egl/drivers/dri2/platform_device.c | 380 +++++++++++++++++++++++++
> src/egl/main/eglapi.c | 13 +-
> src/egl/main/egldisplay.c | 107 ++++++-
> src/egl/main/egldisplay.h | 11 +
> src/egl/main/eglglobals.c | 1 +
> src/egl/meson.build | 1 +
> 9 files changed, 519 insertions(+), 11 deletions(-)
> create mode 100644 src/egl/drivers/dri2/platform_device.c
>
> diff --git a/src/egl/Makefile.am b/src/egl/Makefile.am
> index b43805d991a..3ff6a20fed4 100644
> --- a/src/egl/Makefile.am
> +++ b/src/egl/Makefile.am
> @@ -107,6 +107,9 @@ if HAVE_PLATFORM_SURFACELESS
> dri2_backend_FILES += drivers/dri2/platform_surfaceless.c
> endif
>
> +# Unconditionally enable platform_device
> +dri2_backend_FILES += drivers/dri2/platform_device.c
> +
> if HAVE_PLATFORM_ANDROID
> AM_CFLAGS += $(ANDROID_CFLAGS)
> libEGL_common_la_LIBADD += $(ANDROID_LIBS)
> diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
> index c3024795a10..4a0ad95dde2 100644
> --- a/src/egl/drivers/dri2/egl_dri2.c
> +++ b/src/egl/drivers/dri2/egl_dri2.c
> @@ -900,6 +900,9 @@ dri2_initialize(_EGLDriver *drv, _EGLDisplay *disp)
> case _EGL_PLATFORM_SURFACELESS:
> ret = dri2_initialize_surfaceless(drv, disp);
> break;
> + case _EGL_PLATFORM_DEVICE:
> + ret = dri2_initialize_device(drv, disp);
> + break;
> case _EGL_PLATFORM_X11:
> ret = dri2_initialize_x11(drv, disp);
> break;
> diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
> index 17f36458b8c..86c186dd043 100644
> --- a/src/egl/drivers/dri2/egl_dri2.h
> +++ b/src/egl/drivers/dri2/egl_dri2.h
> @@ -322,9 +322,9 @@ struct dri2_egl_surface
> } color_buffers[3], *back;
> #endif
>
> -#if defined(HAVE_SURFACELESS_PLATFORM)
> - __DRIimage *front;
> -#endif
> + /* surfaceless and device */
> + __DRIimage *front;
> +
> int out_fence_fd;
> EGLBoolean enable_out_fence;
> };
> @@ -480,6 +480,11 @@ dri2_initialize_surfaceless(_EGLDriver *drv, _EGLDisplay *disp)
> }
> #endif
>
> +EGLBoolean
> +dri2_initialize_device(_EGLDriver *drv, _EGLDisplay *disp);
> +static inline void
> +dri2_teardown_device(struct dri2_egl_display *dri2_dpy) { /* noop */ }
> +
> void
> dri2_flush_drawable_for_swapbuffers(_EGLDisplay *disp, _EGLSurface *draw);
>
> diff --git a/src/egl/drivers/dri2/platform_device.c b/src/egl/drivers/dri2/platform_device.c
> new file mode 100644
> index 00000000000..dc5f43ec2c4
> --- /dev/null
> +++ b/src/egl/drivers/dri2/platform_device.c
> @@ -0,0 +1,380 @@
> +/*
> + * Mesa 3-D graphics library
> + *
> + * Copyright 2018 Collabora
> + *
> + * Based on platform_surfaceless, which has:
> + *
> + * Copyright (c) 2014 The Chromium OS Authors.
> + * Copyright © 2011 Intel Corporation
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included
> + * in all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
> + * DEALINGS IN THE SOFTWARE.
> + */
> +
> +#ifdef HAVE_LIBDRM
> +#include <xf86drm.h>
> +#endif
> +
> +#include <stdlib.h>
> +#include <stdio.h>
> +#include <string.h>
> +#include <dlfcn.h>
> +#include <sys/types.h>
> +#include <sys/stat.h>
> +#include <fcntl.h>
> +#include <unistd.h>
> +
> +#include "egl_dri2.h"
> +#include "egl_dri2_fallbacks.h"
> +#include "loader.h"
> +
> +static void
> +device_free_images(struct dri2_egl_surface *dri2_surf)
> +{
> + struct dri2_egl_display *dri2_dpy =
> + dri2_egl_display(dri2_surf->base.Resource.Display);
> +
> + if (dri2_surf->front) {
> + dri2_dpy->image->destroyImage(dri2_surf->front);
> + dri2_surf->front = NULL;
> + }
> +}
> +
> +static int
> +device_image_get_buffers(__DRIdrawable *driDrawable,
> + unsigned int format,
> + uint32_t *stamp,
> + void *loaderPrivate,
> + uint32_t buffer_mask,
> + struct __DRIimageList *buffers)
> +{
> + struct dri2_egl_surface *dri2_surf = loaderPrivate;
> + struct dri2_egl_display *dri2_dpy =
> + dri2_egl_display(dri2_surf->base.Resource.Display);
> +
> + buffers->image_mask = 0;
> + buffers->front = NULL;
> + buffers->back = NULL;
> +
> + /* The EGL 1.5 spec states that pbuffers are single-buffered. Specifically,
> + * the spec states that they have a back buffer but no front buffer, in
> + * contrast to pixmaps, which have a front buffer but no back buffer.
> + *
> + * Single-buffered surfaces with no front buffer confuse Mesa; so we deviate
> + * from the spec, following the precedent of Mesa's EGL X11 platform. The
> + * X11 platform correctly assigns pbuffers to single-buffered configs, but
> + * assigns the pbuffer a front buffer instead of a back buffer.
> + *
> + * Pbuffers in the X11 platform mostly work today, so let's just copy its
> + * behavior instead of trying to fix (and hence potentially breaking) the
> + * world.
> + */
> +
> + if (buffer_mask & __DRI_IMAGE_BUFFER_FRONT) {
> +
> + if (!dri2_surf->front)
> + dri2_surf->front = dri2_dpy->image->createImage(dri2_dpy->dri_screen,
> + dri2_surf->base.Width,
> + dri2_surf->base.Height,
> + format,
> + 0, NULL);
> +
> + buffers->image_mask |= __DRI_IMAGE_BUFFER_FRONT;
> + buffers->front = dri2_surf->front;
> + }
> +
> + return 1;
> +}
> +
> +static _EGLSurface *
> +dri2_device_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type,
> + _EGLConfig *conf, const EGLint *attrib_list)
> +{
> + struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
> + struct dri2_egl_config *dri2_conf = dri2_egl_config(conf);
> + struct dri2_egl_surface *dri2_surf;
> + const __DRIconfig *config;
> +
> + /* Make sure to calloc so all pointers
> + * are originally NULL.
> + */
> + dri2_surf = calloc(1, sizeof *dri2_surf);
> +
> + if (!dri2_surf) {
> + _eglError(EGL_BAD_ALLOC, "eglCreatePbufferSurface");
> + return NULL;
> + }
> +
> + if (!dri2_init_surface(&dri2_surf->base, disp, type, conf, attrib_list, false))
> + goto cleanup_surface;
> +
> + config = dri2_get_dri_config(dri2_conf, type,
> + dri2_surf->base.GLColorspace);
> +
> + if (!config) {
> + _eglError(EGL_BAD_MATCH, "Unsupported surfacetype/colorspace configuration");
> + goto cleanup_surface;
> + }
> +
> + dri2_surf->dri_drawable =
> + dri2_dpy->image_driver->createNewDrawable(dri2_dpy->dri_screen, config,
> + dri2_surf);
> + if (dri2_surf->dri_drawable == NULL) {
> + _eglError(EGL_BAD_ALLOC, "image->createNewDrawable");
> + goto cleanup_surface;
> + }
> +
> + return &dri2_surf->base;
> +
> + cleanup_surface:
> + free(dri2_surf);
> + return NULL;
> +}
> +
> +static EGLBoolean
> +device_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf)
> +{
> + struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
> + struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
> +
> + device_free_images(dri2_surf);
> +
> + dri2_dpy->core->destroyDrawable(dri2_surf->dri_drawable);
> +
> + dri2_fini_surface(surf);
> + free(dri2_surf);
> + return EGL_TRUE;
> +}
> +
> +static _EGLSurface *
> +dri2_device_create_pbuffer_surface(_EGLDriver *drv, _EGLDisplay *disp,
> + _EGLConfig *conf, const EGLint *attrib_list)
> +{
> + return dri2_device_create_surface(drv, disp, EGL_PBUFFER_BIT, conf,
> + attrib_list);
> +}
> +
> +static EGLBoolean
> +device_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf)
> +{
> + assert(!surf || surf->Type == EGL_PBUFFER_BIT);
> +
> + /* From the EGL 1.5 spec:
> + * If surface is a [...] pbuffer surface, eglSwapBuffers has no effect.
> + */
> + return EGL_TRUE;
> +}
> +
> +static EGLBoolean
> +device_add_configs_for_visuals(_EGLDriver *drv, _EGLDisplay *dpy)
> +{
> + struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy);
> + static const struct {
> + const char *format_name;
> + unsigned int rgba_masks[4];
> + } visuals[] = {
> + { "ARGB8888", { 0xff0000, 0xff00, 0xff, 0xff000000 } },
> + { "RGB888", { 0xff0000, 0xff00, 0xff, 0x0 } },
> + { "RGB565", { 0x00f800, 0x07e0, 0x1f, 0x0 } },
> + };
> + unsigned int format_count[ARRAY_SIZE(visuals)] = { 0 };
> + unsigned int config_count = 0;
> +
> + for (unsigned i = 0; dri2_dpy->driver_configs[i] != NULL; i++) {
> + for (unsigned j = 0; j < ARRAY_SIZE(visuals); j++) {
> + struct dri2_egl_config *dri2_conf;
> +
> + dri2_conf = dri2_add_config(dpy, dri2_dpy->driver_configs[i],
> + config_count + 1, EGL_PBUFFER_BIT, NULL,
> + visuals[j].rgba_masks);
> +
> + if (dri2_conf) {
> + if (dri2_conf->base.ConfigID == config_count + 1)
> + config_count++;
> + format_count[j]++;
> + }
> + }
> + }
> +
> + for (unsigned i = 0; i < ARRAY_SIZE(format_count); i++) {
> + if (!format_count[i]) {
> + _eglLog(_EGL_DEBUG, "No DRI config supports native format %s",
> + visuals[i].format_name);
> + }
> + }
> +
> + return (config_count != 0);
> +}
> +
> +static const struct dri2_egl_display_vtbl dri2_device_display_vtbl = {
> + .create_pixmap_surface = dri2_fallback_create_pixmap_surface,
> + .create_pbuffer_surface = dri2_device_create_pbuffer_surface,
> + .destroy_surface = device_destroy_surface,
> + .create_image = dri2_create_image_khr,
> + .swap_buffers = device_swap_buffers,
> + .swap_buffers_with_damage = dri2_fallback_swap_buffers_with_damage,
> + .swap_buffers_region = dri2_fallback_swap_buffers_region,
> + .set_damage_region = dri2_fallback_set_damage_region,
> + .post_sub_buffer = dri2_fallback_post_sub_buffer,
> + .copy_buffers = dri2_fallback_copy_buffers,
> + .query_buffer_age = dri2_fallback_query_buffer_age,
> + .create_wayland_buffer_from_image = dri2_fallback_create_wayland_buffer_from_image,
> + .get_sync_values = dri2_fallback_get_sync_values,
> + .get_dri_drawable = dri2_surface_get_dri_drawable,
> +};
> +
> +static void
> +device_flush_front_buffer(__DRIdrawable *driDrawable, void *loaderPrivate)
> +{
> +}
> +
> +static const __DRIimageLoaderExtension image_loader_extension = {
> + .base = { __DRI_IMAGE_LOADER, 1 },
> + .getBuffers = device_image_get_buffers,
> + .flushFrontBuffer = device_flush_front_buffer,
> +};
> +
> +static const __DRIextension *image_loader_extensions[] = {
> + &image_loader_extension.base,
> + &image_lookup_extension.base,
> + &use_invalidate.base,
> + NULL,
> +};
> +
> +static EGLBoolean
> +device_probe_device(_EGLDisplay *disp)
> +{
> + _EGLDevice *dev;
> + struct dri2_egl_display *dri2_dpy = disp->DriverData;
> + EGLBoolean swrast;
> + char *node;
> + int fd;
> +
> + /* Extension requires a PlatformDisplay - the EGLDevice. */
> + dev = disp->PlatformDisplay;
> + fd = ((_EGLDeviceDisplayOptions *)disp->Options.Platform)->internal_fd;
> + if (fd != -1) {
> + /* According to the spec - if the FD does not match the EGLDevice
> + * behaviour is undefined.
> + *
> + * Add a trivial sanity check since it doesn't cost us anything.
> + */
> + if (dev != _eglFindDevice(fd, false))
> + return EGL_FALSE;
> +
> + swrast = EGL_FALSE;
> + } else {
> + if (_eglDeviceSupports(dev, _EGL_DEVICE_DRM)) {
> + const char *primary_node;
> +
> + primary_node = _eglQueryDeviceStringEXT(dev, EGL_DRM_DEVICE_FILE_EXT);
> + fd = loader_open_device(primary_node);
> + if (fd < 0)
> + return EGL_FALSE;
> +
> + swrast = EGL_FALSE;
> + } else {
> + fd = -1;
> + swrast = EGL_TRUE;
> + }
> + }
> +
> + if (!swrast) {
> +#ifdef HAVE_LIBDRM
> + /* No EGL_EXT_output* extensions are supported, hence no master perms
> + * are needed. Get the render one - otherwise drivers might error out.
> + */
> + node = drmGetRenderDeviceNameFromFd(fd);
> + close(fd);
> + fd = loader_open_device(node);
> + free(node);
> + if (fd < 0)
> + return EGL_FALSE;
> + dri2_dpy->driver_name = loader_get_driver_for_fd(fd);
> +#else
> + _eglLog(_EGL_FATAL, "Driver bug: Built without libdrm, yet using a HW device");
> + return EGL_FALSE;
> +#endif
> + } else {
> + /* XXX: Should really be a "null" version of kms_swrast */
> + dri2_dpy->driver_name = strdup("swrast");
> + }
> +
> + if (!dri2_dpy->driver_name)
> + return EGL_FALSE;
> +
> + dri2_dpy->fd = fd;
> + disp->Device = dev;
> +
> + if (swrast)
> + return dri2_load_driver_swrast(disp);
> +
> + return dri2_load_driver_dri3(disp);
> +}
> +
> +EGLBoolean
> +dri2_initialize_device(_EGLDriver *drv, _EGLDisplay *disp)
> +{
> + struct dri2_egl_display *dri2_dpy;
> + const char* err;
> +
> + loader_set_logger(_eglLog);
> +
> + dri2_dpy = calloc(1, sizeof *dri2_dpy);
> + if (!dri2_dpy)
> + return _eglError(EGL_BAD_ALLOC, "eglInitialize");
> +
> + dri2_dpy->fd = -1;
> + disp->DriverData = (void *) dri2_dpy;
> +
> + if (!device_probe_device(disp)) {
> + err = "DRI2: failed to load driver";
> + goto cleanup;
> + }
> +
> + dri2_dpy->loader_extensions = image_loader_extensions;
> +
> + if (!dri2_create_screen(disp)) {
> + err = "DRI2: failed to create screen";
> + goto cleanup;
> + }
> +
> + if (!dri2_setup_extensions(disp)) {
> + err = "DRI2: failed to find required DRI extensions";
> + goto cleanup;
> + }
> +
> + dri2_setup_screen(disp);
> +
> + if (!device_add_configs_for_visuals(drv, disp)) {
> + err = "DRI2: failed to add configs";
> + goto cleanup;
> + }
> +
> + /* Fill vtbl last to prevent accidentally calling virtual function during
> + * initialization.
> + */
> + dri2_dpy->vtbl = &dri2_device_display_vtbl;
> +
> + return EGL_TRUE;
> +
> +cleanup:
> + dri2_display_destroy(disp);
> + return _eglError(EGL_NOT_INITIALIZED, err);
> +}
> diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
> index a6388b663cd..2d70d593820 100644
> --- a/src/egl/main/eglapi.c
> +++ b/src/egl/main/eglapi.c
> @@ -404,6 +404,9 @@ _eglGetPlatformDisplayCommon(EGLenum platform, void *native_display,
> dpy = _eglGetSurfacelessDisplay(native_display, attrib_list);
> break;
> #endif
> + case EGL_PLATFORM_DEVICE_EXT:
> + dpy = _eglGetDeviceDisplay(native_display, attrib_list);
> + break;
> default:
> RETURN_EGL_ERROR(NULL, EGL_BAD_PARAMETER, NULL);
> }
> @@ -881,8 +884,8 @@ _eglCreateWindowSurfaceCommon(_EGLDisplay *disp, EGLConfig config,
> if (native_window == NULL)
> RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
>
> -#ifdef HAVE_SURFACELESS_PLATFORM
> - if (disp && disp->Platform == _EGL_PLATFORM_SURFACELESS) {
> + if (disp && (disp->Platform == _EGL_PLATFORM_SURFACELESS ||
> + disp->Platform == _EGL_PLATFORM_DEVICE)) {
> /* From the EGL_MESA_platform_surfaceless spec (v1):
> *
> * eglCreatePlatformWindowSurface fails when called with a <display>
> @@ -897,7 +900,6 @@ _eglCreateWindowSurfaceCommon(_EGLDisplay *disp, EGLConfig config,
> */
> RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
> }
> -#endif
>
> _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
>
> @@ -1005,8 +1007,8 @@ _eglCreatePixmapSurfaceCommon(_EGLDisplay *disp, EGLConfig config,
> _EGLSurface *surf;
> EGLSurface ret;
>
> -#if HAVE_SURFACELESS_PLATFORM
> - if (disp && disp->Platform == _EGL_PLATFORM_SURFACELESS) {
> + if (disp && (disp->Platform == _EGL_PLATFORM_SURFACELESS ||
> + disp->Platform == _EGL_PLATFORM_DEVICE)) {
> /* From the EGL_MESA_platform_surfaceless spec (v1):
> *
> * [Like eglCreatePlatformWindowSurface,] eglCreatePlatformPixmapSurface
> @@ -1019,7 +1021,6 @@ _eglCreatePixmapSurfaceCommon(_EGLDisplay *disp, EGLConfig config,
> */
> RETURN_EGL_ERROR(disp, EGL_BAD_NATIVE_PIXMAP, EGL_NO_SURFACE);
> }
> -#endif
>
> _EGL_CHECK_CONFIG(disp, conf, EGL_NO_SURFACE, drv);
>
> diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c
> index 61b75cbee2c..a2558b93893 100644
> --- a/src/egl/main/egldisplay.c
> +++ b/src/egl/main/egldisplay.c
> @@ -35,12 +35,14 @@
> #include <assert.h>
> #include <stdlib.h>
> #include <string.h>
> +#include <fcntl.h>
> #include "c11/threads.h"
> #include "util/u_atomic.h"
>
> #include "eglcontext.h"
> #include "eglcurrent.h"
> #include "eglsurface.h"
> +#include "egldevice.h"
> #include "egldisplay.h"
> #include "egldriver.h"
> #include "eglglobals.h"
> @@ -207,6 +209,20 @@ _eglFiniDisplay(void)
> _eglGlobal.DisplayList = NULL;
> }
>
> +static int
> +_eglCompareDeviceDisplay(_EGLDisplay *dpy, void *plat_opt)
This is a true/false check, so we I think should return a bool and
change name to reflect which "comparison" returns true, and you could
avoid the inline cast by taking the right param type, so how about:
static bool
_eglSameDeviceDisplay(_EGLDisplay *dpy, _EGLDeviceDisplayOptions *plat_opt)
> +{
> + _EGLDeviceDisplayOptions *opt = dpy->Options.Platform;
> +
> + /* Both opt and plat_opt are non-NULL */
> + if (opt->attrib_fd == ((_EGLDeviceDisplayOptions *)plat_opt)->attrib_fd)
> + return 0;
> +
> + /* Multiple displays for the same native_display are allowed when separate
> + * FDs are used.
> + */
> + return 1;
> +}
>
> /**
> * Find the display corresponding to the specified native display, or create a
> @@ -227,8 +243,13 @@ _eglFindDisplay(_EGLPlatformType plat, void *plat_dpy, void *plat_opt)
> /* search the display list first */
> dpy = _eglGlobal.DisplayList;
> while (dpy) {
> - if (dpy->Platform == plat && dpy->PlatformDisplay == plat_dpy)
> - break;
> + if (dpy->Platform == plat && dpy->PlatformDisplay == plat_dpy) {
> + if (plat != _EGL_PLATFORM_DEVICE)
> + break;
> +
> + if (_eglCompareDeviceDisplay(dpy, plat_opt) == 0)
> + break;
> + }
> dpy = dpy->Next;
> }
>
> @@ -544,3 +565,85 @@ _eglGetSurfacelessDisplay(void *native_display,
> return _eglFindDisplay(_EGL_PLATFORM_SURFACELESS, native_display, NULL);
> }
> #endif /* HAVE_SURFACELESS_PLATFORM */
> +
> +
> +_EGLDisplay*
> +_eglGetDeviceDisplay(void *native_display,
> + const EGLAttrib *attrib_list)
> +{
> + _EGLDevice *dev;
> + _EGLDisplay *display;
> + _EGLDeviceDisplayOptions *opt;
> + int fd = -1;
> +
> + dev = _eglLookupDevice(native_display);
> + if (!dev) {
> + _eglError(EGL_BAD_PARAMETER, "eglGetPlatformDisplay");
> + return NULL;
> + }
> +
> + if (attrib_list) {
> + for (int i = 0; attrib_list[i] != EGL_NONE; i += 2) {
> + EGLAttrib attrib = attrib_list[i];
> + EGLAttrib value = attrib_list[i + 1];
> +
> + /* EGL_EXT_platform_device does not recognize any attributes,
> + * EGL_EXT_device_drm adds the optional EGL_DRM_MASTER_FD_EXT.
> + */
> +
> + /* TODO: add the missing define to the public headers, sync our copy */
Let's do that before this patch lands?
> +#define EGL_DRM_MASTER_FD_EXT 0x333C
> +
> + if (!_eglDeviceSupports(dev, _EGL_DEVICE_DRM) ||
> + attrib != EGL_DRM_MASTER_FD_EXT) {
> + _eglError(EGL_BAD_ATTRIBUTE, "eglGetPlatformDisplay");
> + return NULL;
> + }
> +
> + fd = (int) value;
> + }
> + }
> +
> + opt = malloc(sizeof *opt);
> + if (!opt) {
> + _eglError(EGL_BAD_ALLOC, "eglGetPlatformDisplay");
> + return NULL;
> + }
> +
> + opt->attrib_fd = fd;
> + opt->internal_fd = -1;
> +
> + display = _eglFindDisplay(_EGL_PLATFORM_DEVICE, native_display, (void *)opt);
> + if (!display) {
> + free(opt);
> + _eglError(EGL_BAD_ALLOC, "eglGetPlatformDisplay");
> + return NULL;
> + }
> +
> + /* TODO: Change Options.Platform under a lock, to avoid a race.
> + * X11 handling above need a similar fix.
> + */
I'm assuming you will do this before landing this patch, right?
> +
> + /* Newly allocated display */
> + if (!display->Options.Platform) {
> + display->Options.Platform = opt;
> + } else {
> + free(opt);
> + opt = display->Options.Platform;
> + }
> +
> + /* If the fd is explicitly provided and we did not dup() it yet, do so.
> + * The spec mandates that we do so, since we'll need it past the
> + * eglGetPlatformDispay call.
> + */
> + if (opt->attrib_fd != -1 && opt->internal_fd == -1) {
> + opt->internal_fd = fcntl(fd, F_DUPFD_CLOEXEC, 3);
> + if (opt->internal_fd == -1) {
> + /* Do not (really) need to teardown the display */
> + _eglError(EGL_BAD_ALLOC, "eglGetPlatformDisplay");
> + return NULL;
> + }
> + }
> +
> + return display;
> +}
> diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h
> index b8210c4a3cc..a987e7761b2 100644
> --- a/src/egl/main/egldisplay.h
> +++ b/src/egl/main/egldisplay.h
> @@ -50,6 +50,7 @@ enum _egl_platform_type {
> _EGL_PLATFORM_ANDROID,
> _EGL_PLATFORM_HAIKU,
> _EGL_PLATFORM_SURFACELESS,
> + _EGL_PLATFORM_DEVICE,
>
> _EGL_NUM_PLATFORMS,
> _EGL_INVALID_PLATFORM = -1
> @@ -145,6 +146,12 @@ struct _egl_extensions
> EGLBoolean WL_create_wayland_buffer_from_image;
> };
>
> +struct _egl_device_display_options
> +{
> + int attrib_fd;
> + int internal_fd;
> +};
> +typedef struct _egl_device_display_options _EGLDeviceDisplayOptions;
>
> struct _egl_display
> {
> @@ -297,6 +304,10 @@ _eglGetSurfacelessDisplay(void *native_display,
> const EGLAttrib *attrib_list);
> #endif
>
> +_EGLDisplay*
> +_eglGetDeviceDisplay(void *native_display,
> + const EGLAttrib *attrib_list);
> +
> #ifdef __cplusplus
> }
> #endif
> diff --git a/src/egl/main/eglglobals.c b/src/egl/main/eglglobals.c
> index 77b213a9d0b..48acb36cd38 100644
> --- a/src/egl/main/eglglobals.c
> +++ b/src/egl/main/eglglobals.c
> @@ -82,6 +82,7 @@ struct _egl_global _eglGlobal =
> #ifdef HAVE_SURFACELESS_PLATFORM
> " EGL_MESA_platform_surfaceless"
> #endif
> + " EGL_EXT_platform_device"
> "",
>
> .ClientExtensionString = NULL,
> diff --git a/src/egl/meson.build b/src/egl/meson.build
> index dee95d44876..ccaaa76594a 100644
> --- a/src/egl/meson.build
> +++ b/src/egl/meson.build
> @@ -118,6 +118,7 @@ if not with_platform_haiku
> if with_platform_surfaceless
> files_egl += files('drivers/dri2/platform_surfaceless.c')
> endif
> + files_egl += files('drivers/dri2/platform_surfaceless.c')
typo: s/surfaceless/device/
and I would prefer for this to be added in the `if with_dri2` (around
line 88) instead of in the middle here, where it gets lost in the middle
of the `if with_platform_*` checks.
> if with_platform_wayland
> deps_for_egl += [dep_wayland_client, dep_wayland_server, dep_wayland_egl_headers]
> link_for_egl += libwayland_drm
> --
> 2.18.0
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
More information about the mesa-dev
mailing list