[Mesa-dev] [PATCH] egl/android: remove flink name support

Chih-Wei Huang cwhuang at android-x86.org
Mon Apr 23 02:17:30 UTC 2018


What's the impact to drm_gralloc?


2018-04-20 5:09 GMT+08:00 Rob Herring <robh at kernel.org>:
> Maintaining both flink names and prime fd support which are provided by
> 2 different gralloc implementations is problematic because we have a
> dependency on a specific gralloc implementation header.
>
> This mostly removes the dependency on the gralloc implementation and
> headers. The dependency on GRALLOC_MODULE_PERFORM_GET_DRM_FD remains for
> now, but the definition is added locally to remove the header
> dependency.
>
> Signed-off-by: Rob Herring <robh at kernel.org>
> ---
> With this plus Robert's probing patch, we remove any gralloc
> implementation dependency (other than it has to be a pre 1.0
> implementation...).
>
>  src/egl/drivers/dri2/egl_dri2.h         |   1 -
>  src/egl/drivers/dri2/platform_android.c | 172 ++++----------------------------
>  2 files changed, 17 insertions(+), 156 deletions(-)
>
> diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
> index cc76c73eab2f..d9e1f466fbeb 100644
> --- a/src/egl/drivers/dri2/egl_dri2.h
> +++ b/src/egl/drivers/dri2/egl_dri2.h
> @@ -61,7 +61,6 @@ struct zwp_linux_dmabuf_v1;
>
>  #include <system/window.h>
>  #include <hardware/gralloc.h>
> -#include <gralloc_drm_handle.h>
>
>  #endif /* HAVE_ANDROID_PLATFORM */
>
> diff --git a/src/egl/drivers/dri2/platform_android.c b/src/egl/drivers/dri2/platform_android.c
> index 4f25cb746915..68c85d7f99fa 100644
> --- a/src/egl/drivers/dri2/platform_android.c
> +++ b/src/egl/drivers/dri2/platform_android.c
> @@ -37,7 +37,6 @@
>  #include "loader.h"
>  #include "egl_dri2.h"
>  #include "egl_dri2_fallbacks.h"
> -#include "gralloc_drm.h"
>
>  #define ALIGN(val, align)      (((val) + (align) - 1) & ~((align) - 1))
>
> @@ -164,12 +163,6 @@ get_native_buffer_fd(struct ANativeWindowBuffer *buf)
>     return (handle && handle->numFds) ? handle->data[0] : -1;
>  }
>
> -static int
> -get_native_buffer_name(struct ANativeWindowBuffer *buf)
> -{
> -   return gralloc_drm_get_gem_handle(buf->handle);
> -}
> -
>  static EGLBoolean
>  droid_window_dequeue_buffer(struct dri2_egl_surface *dri2_surf)
>  {
> @@ -822,50 +815,6 @@ droid_create_image_from_prime_fd(_EGLDisplay *disp, _EGLContext *ctx,
>     return dri2_create_image_dma_buf(disp, ctx, NULL, attr_list);
>  }
>
> -static _EGLImage *
> -droid_create_image_from_name(_EGLDisplay *disp, _EGLContext *ctx,
> -                             struct ANativeWindowBuffer *buf)
> -{
> -   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
> -   struct dri2_egl_image *dri2_img;
> -   int name;
> -   int format;
> -
> -   name = get_native_buffer_name(buf);
> -   if (!name) {
> -      _eglError(EGL_BAD_PARAMETER, "eglCreateEGLImageKHR");
> -      return NULL;
> -   }
> -
> -   format = get_format(buf->format);
> -   if (format == -1)
> -       return NULL;
> -
> -   dri2_img = calloc(1, sizeof(*dri2_img));
> -   if (!dri2_img) {
> -      _eglError(EGL_BAD_ALLOC, "droid_create_image_mesa_drm");
> -      return NULL;
> -   }
> -
> -   _eglInitImage(&dri2_img->base, disp);
> -
> -   dri2_img->dri_image =
> -      dri2_dpy->image->createImageFromName(dri2_dpy->dri_screen,
> -                                          buf->width,
> -                                          buf->height,
> -                                          format,
> -                                          name,
> -                                          buf->stride,
> -                                          dri2_img);
> -   if (!dri2_img->dri_image) {
> -      free(dri2_img);
> -      _eglError(EGL_BAD_ALLOC, "droid_create_image_mesa_drm");
> -      return NULL;
> -   }
> -
> -   return &dri2_img->base;
> -}
> -
>  static EGLBoolean
>  droid_query_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf,
>                      EGLint attribute, EGLint *value)
> @@ -921,7 +870,7 @@ dri2_create_image_android_native_buffer(_EGLDisplay *disp,
>     if (fd >= 0)
>        return droid_create_image_from_prime_fd(disp, ctx, buf, fd);
>
> -   return droid_create_image_from_name(disp, ctx, buf);
> +   return NULL;
>  }
>
>  static _EGLImage *
> @@ -943,82 +892,6 @@ droid_flush_front_buffer(__DRIdrawable * driDrawable, void *loaderPrivate)
>  {
>  }
>
> -static int
> -droid_get_buffers_parse_attachments(struct dri2_egl_surface *dri2_surf,
> -                                    unsigned int *attachments, int count)
> -{
> -   int num_buffers = 0;
> -
> -   /* fill dri2_surf->buffers */
> -   for (int i = 0; i < count * 2; i += 2) {
> -      __DRIbuffer *buf, *local;
> -
> -      assert(num_buffers < ARRAY_SIZE(dri2_surf->buffers));
> -      buf = &dri2_surf->buffers[num_buffers];
> -
> -      switch (attachments[i]) {
> -      case __DRI_BUFFER_BACK_LEFT:
> -         if (dri2_surf->base.Type == EGL_WINDOW_BIT) {
> -            buf->attachment = attachments[i];
> -            buf->name = get_native_buffer_name(dri2_surf->buffer);
> -            buf->cpp = get_format_bpp(dri2_surf->buffer->format);
> -            buf->pitch = dri2_surf->buffer->stride * buf->cpp;
> -            buf->flags = 0;
> -
> -            if (buf->name)
> -               num_buffers++;
> -
> -            break;
> -         }
> -         /* fall through for pbuffers */
> -      case __DRI_BUFFER_DEPTH:
> -      case __DRI_BUFFER_STENCIL:
> -      case __DRI_BUFFER_ACCUM:
> -      case __DRI_BUFFER_DEPTH_STENCIL:
> -      case __DRI_BUFFER_HIZ:
> -         local = dri2_egl_surface_alloc_local_buffer(dri2_surf,
> -               attachments[i], attachments[i + 1]);
> -
> -         if (local) {
> -            *buf = *local;
> -            num_buffers++;
> -         }
> -         break;
> -      case __DRI_BUFFER_FRONT_LEFT:
> -      case __DRI_BUFFER_FRONT_RIGHT:
> -      case __DRI_BUFFER_FAKE_FRONT_LEFT:
> -      case __DRI_BUFFER_FAKE_FRONT_RIGHT:
> -      case __DRI_BUFFER_BACK_RIGHT:
> -      default:
> -         /* no front or right buffers */
> -         break;
> -      }
> -   }
> -
> -   return num_buffers;
> -}
> -
> -static __DRIbuffer *
> -droid_get_buffers_with_format(__DRIdrawable * driDrawable,
> -                            int *width, int *height,
> -                            unsigned int *attachments, int count,
> -                            int *out_count, void *loaderPrivate)
> -{
> -   struct dri2_egl_surface *dri2_surf = loaderPrivate;
> -
> -   if (update_buffers(dri2_surf) < 0)
> -      return NULL;
> -
> -   *out_count = droid_get_buffers_parse_attachments(dri2_surf, attachments, count);
> -
> -   if (width)
> -      *width = dri2_surf->base.Width;
> -   if (height)
> -      *height = dri2_surf->base.Height;
> -
> -   return dri2_surf->buffers;
> -}
> -
>  static unsigned
>  droid_get_capability(void *loaderPrivate, enum dri_loader_cap cap)
>  {
> @@ -1100,6 +973,14 @@ droid_add_configs_for_visuals(_EGLDriver *drv, _EGLDisplay *dpy)
>     return (config_count != 0);
>  }
>
> +enum {
> +        /* perform(const struct gralloc_module_t *mod,
> +         *         int op,
> +         *         int *fd);
> +         */
> +        GRALLOC_MODULE_PERFORM_GET_DRM_FD                = 0x40000002,
> +};
> +
>  static int
>  droid_open_device(struct dri2_egl_display *dri2_dpy)
>  {
> @@ -1141,15 +1022,6 @@ static const struct dri2_egl_display_vtbl droid_display_vtbl = {
>     .get_dri_drawable = dri2_surface_get_dri_drawable,
>  };
>
> -static const __DRIdri2LoaderExtension droid_dri2_loader_extension = {
> -   .base = { __DRI_DRI2_LOADER, 4 },
> -
> -   .getBuffers           = NULL,
> -   .flushFrontBuffer     = droid_flush_front_buffer,
> -   .getBuffersWithFormat = droid_get_buffers_with_format,
> -   .getCapability        = droid_get_capability,
> -};
> -
>  static const __DRIimageLoaderExtension droid_image_loader_extension = {
>     .base = { __DRI_IMAGE_LOADER, 2 },
>
> @@ -1158,13 +1030,6 @@ static const __DRIimageLoaderExtension droid_image_loader_extension = {
>     .getCapability       = droid_get_capability,
>  };
>
> -static const __DRIextension *droid_dri2_loader_extensions[] = {
> -   &droid_dri2_loader_extension.base,
> -   &image_lookup_extension.base,
> -   &use_invalidate.base,
> -   NULL,
> -};
> -
>  static const __DRIextension *droid_image_loader_extensions[] = {
>     &droid_image_loader_extension.base,
>     &image_lookup_extension.base,
> @@ -1216,17 +1081,14 @@ dri2_initialize_android(_EGLDriver *drv, _EGLDisplay *disp)
>     /* render nodes cannot use Gem names, and thus do not support
>      * the __DRI_DRI2_LOADER extension */
>     if (!dri2_dpy->is_render_node) {
> -      dri2_dpy->loader_extensions = droid_dri2_loader_extensions;
> -      if (!dri2_load_driver(disp)) {
> -         err = "DRI2: failed to load driver";
> -         goto cleanup;
> -      }
> -   } else {
> -      dri2_dpy->loader_extensions = droid_image_loader_extensions;
> -      if (!dri2_load_driver_dri3(disp)) {
> -         err = "DRI3: failed to load driver";
> -         goto cleanup;
> -      }
> +      err = "DRI2: driver is not a render node";
> +      goto cleanup;
> +   }
> +
> +   dri2_dpy->loader_extensions = droid_image_loader_extensions;
> +   if (!dri2_load_driver_dri3(disp)) {
> +      err = "DRI3: failed to load driver";
> +      goto cleanup;
>     }
>
>     if (!dri2_create_screen(disp)) {
> --
> 2.14.1
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev



-- 
Chih-Wei
Android-x86 project
http://www.android-x86.org


More information about the mesa-dev mailing list