[Mesa-dev] [RFC libdrm 1/5] android: Move gralloc handle struct to libdrm

Rob Herring robh at kernel.org
Wed Dec 13 20:40:10 UTC 2017


On Wed, Dec 13, 2017 at 11:30 AM, Robert Foss <robert.foss at collabora.com> wrote:
> This struct is used in mesa and drm_hwcomposer.
> Versions of if have been implemented in several grallocs:
> drm_gralloc, gbm_gralloc, minigbm and intel-minigbm.
>
> Other than the 1:1 move of the struct a new generic name
> has been chosen and variables have had comments added to them.
>
> Sign-off-by: Robert Foss <robert.foss at collabora.com>
> ---
>  Android.mk                   |  8 +++--
>  Makefile.sources             |  3 ++
>  android/alloc_handle.h       | 84 ++++++++++++++++++++++++++++++++++++++++++++
>  android/gralloc_drm_handle.h |  1 +
>  4 files changed, 94 insertions(+), 2 deletions(-)
>  create mode 100644 android/alloc_handle.h
>  create mode 120000 android/gralloc_drm_handle.h
>
> diff --git a/Android.mk b/Android.mk
> index 292be2360263..209123a56940 100644
> --- a/Android.mk
> +++ b/Android.mk
> @@ -28,7 +28,7 @@ LIBDRM_TOP := $(LOCAL_PATH)
>
>  include $(CLEAR_VARS)
>
> -# Import variables LIBDRM_{,H_,INCLUDE_H_,INCLUDE_VMWGFX_H_}FILES
> +# Import variables LIBDRM_{,H,INCLUDE_H,INCLUDE_ANDROID_H,INCLUDE_VMWGFX_H}_FILES
>  include $(LOCAL_PATH)/Makefile.sources
>
>  #static library for the device (recovery)
> @@ -38,7 +38,8 @@ LOCAL_MODULE := libdrm
>  LOCAL_SRC_FILES := $(LIBDRM_FILES)
>  LOCAL_EXPORT_C_INCLUDE_DIRS := \
>         $(LOCAL_PATH) \
> -       $(LOCAL_PATH)/include/drm
> +       $(LOCAL_PATH)/include/drm \
> +       $(LOCAL_PATH)/include/android

The path doesn't match.

>
>  LOCAL_C_INCLUDES := \
>         $(LOCAL_PATH)/include/drm
> @@ -54,6 +55,9 @@ LOCAL_SRC_FILES := $(LIBDRM_FILES)
>  LOCAL_EXPORT_C_INCLUDE_DIRS := \
>          $(LOCAL_PATH)/include/drm
>
> +LOCAL_SHARED_LIBRARIES := \
> +       libcutils
> +
>  LOCAL_C_INCLUDES := \
>          $(LOCAL_PATH)/include/drm
>
> diff --git a/Makefile.sources b/Makefile.sources
> index 10aa1d0f4b6e..545b5bbb35e5 100644
> --- a/Makefile.sources
> +++ b/Makefile.sources
> @@ -37,5 +37,8 @@ LIBDRM_INCLUDE_H_FILES := \
>         include/drm/via_drm.h \
>         include/drm/virtgpu_drm.h
>
> +LIBDRM_INCLUDE_ANDROID_H_FILES := \
> +       android/alloc_handle.h
> +
>  LIBDRM_INCLUDE_VMWGFX_H_FILES := \
>         include/drm/vmwgfx_drm.h
> diff --git a/android/alloc_handle.h b/android/alloc_handle.h
> new file mode 100644
> index 000000000000..75cb895a962a
> --- /dev/null
> +++ b/android/alloc_handle.h
> @@ -0,0 +1,84 @@
> +/*
> + * 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 (including the next
> + * paragraph) 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
> + * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS 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.
> + */
> +
> +#ifndef __ANDROID_ALLOC_HANDLE_H__
> +#define __ANDROID_ALLOC_HANDLE_H__
> +
> +#include <cutils/native_handle.h>
> +
> +/* support users of drm_gralloc/gbm_gralloc */
> +#define gralloc_gbm_handle_t alloc_handle_t
> +#define gralloc_drm_handle_t alloc_handle_t
> +
> +struct alloc_handle_t {
> +       native_handle_t base;
> +
> +       /* integers */
> +       int magic; /* differentiate between allocator impls */
> +
> +       int prime_fd; /* dma-buf file descriptor */

You changed the order here and it is important that fd's come first.

> +       int width; /* width of buffer in pixels */
> +       int height; /* height of buffer in pixels */
> +       int format; /* pixel format (Android) */
> +       int usage; /* android libhardware usage flags */
> +
> +       int name;   /* the name of the bo */
> +       int stride; /* the stride in bytes */
> +       uint64_t modifier; /* buffer modifiers */
> +
> +       int data_owner; /* owner of data (for validation) */
> +       union {
> +               void *data; /* pointer to struct gralloc_gbm_bo_t */
> +               uint64_t reserved;
> +       } __attribute__((aligned(8)));
> +};
> +
> +#define ALLOC_HANDLE_MAGIC 0x60585350
> +#define ALLOC_HANDLE_NUM_FDS 1
> +#define ALLOC_HANDLE_NUM_INTS (        \
> +       ((sizeof(struct alloc_handle_t) - sizeof(native_handle_t))/sizeof(int)) \
> +        - ALLOC_HANDLE_NUM_FDS)
> +
> +/**
> + * Create a buffer handle.
> + */
> +struct alloc_handle_t *alloc_handle_create(int width, int height, int format,
> +                                              int usage)
> +{
> +       struct alloc_handle_t handle = { .magic = ALLOC_HANDLE_MAGIC };
> +
> +       handle->base.version = sizeof(handle->base);
> +       handle->base.numInts = ALLOC_HANDLE_NUM_INTS;
> +       handle->base.numFds = ALLOC_HANDLE_NUM_FDS;

There's a native_handle API to do this part.

> +
> +       handle->width = width;
> +       handle->height = height;
> +       handle->format = format;
> +       handle->usage = usage;
> +       handle->prime_fd = -1;
> +
> +       handle->data_owner = getpid();
> +       handle->data = bo;
> +
> +       return handle;
> +}
> +
> +#endif
> diff --git a/android/gralloc_drm_handle.h b/android/gralloc_drm_handle.h
> new file mode 120000
> index 000000000000..038f9485f040
> --- /dev/null
> +++ b/android/gralloc_drm_handle.h
> @@ -0,0 +1 @@
> +android/alloc_handle.h
> \ No newline at end of file
> --
> 2.14.1
>


More information about the mesa-dev mailing list