android: Introduce the Android buffer info abstraction
authorRoman Stratiienko <r.stratiienko@gmail.com>
Tue, 23 Aug 2022 17:08:22 +0000 (20:08 +0300)
committerMarge Bot <emma+marge@anholt.net>
Sat, 12 Aug 2023 18:46:57 +0000 (18:46 +0000)
commitee42e2166d836251603b2b3e4801705d42d8f83d
tree11c7cd1272834c090aef3523cd7be8dbb37f2907
parent21dcde096f351f83a2df7aa9f42a7276b5454c81
android: Introduce the Android buffer info abstraction

Both EGL and Vulkan implementations require obtaining buffer metadata,
e.g., format, modifier, offsets, strides, etc.

Currently, mesa3d doesn't have a generic solution, and every Vulkan
implementation uses its getters. Most of the getters rely on
kernel metadata storage that is available for x86-based GPU drivers.

ARM-based Vulkan drivers rely on userspace metadata sharing, making it
important to use advanced metadata API. Otherwise, the driver will work
with limited functionality (no YUV, lack of support for modifiers, etc.)

Current EGL buffer getter implementation is advanced enough and used as
a base for a common Android buffer-getter logic.

Use example:

    void
    android_buffer_test(android_handle_type *a_handle)
    {
       // First, get the gralloc object. It will be created if it doesn't
       // exist. Use U_GRALLOC_TYPE_AUTO to let the implementation choose
       // the best gralloc
       struct u_gralloc *gralloc = u_gralloc_create(U_GRALLOC_TYPE_AUTO);

       // Prepare the internal handle structure (hal_format and
       // pixel_stride are required for the fallback implementation).
       // Both Vulkan and EGL clients expose HAL format / pixel stride
       // in their structures.
       u_gralloc_buffer_handle hnd = {
          .handle = a_handle->native_handle,
          .hal_format = a_handle->hal_format,
          .pixel_stride = a_handle->pixel_stride,
       };

       // Get the basic buffer info
       u_gralloc_buffer_basic_info basic_info;
       int ret = u_gralloc_get_buffer_basic_info(gralloc, &hnd, &basic_info);
       if (ret) {
          // Handle the error
       }

       // Get the color info
       u_gralloc_buffer_color_info color_info;
       ret = u_gralloc_get_buffer_color_info(gralloc, &hnd, &color_info);
       if (ret) {
          // Handle the error
       }

       // unref the gralloc object
       u_gralloc_destroy(&gralloc);
    }

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18215>
src/util/meson.build
src/util/u_gralloc/meson.build [new file with mode: 0644]
src/util/u_gralloc/u_gralloc.c [new file with mode: 0644]
src/util/u_gralloc/u_gralloc.h [new file with mode: 0644]
src/util/u_gralloc/u_gralloc_cros_api.c [new file with mode: 0644]
src/util/u_gralloc/u_gralloc_fallback.c [new file with mode: 0644]
src/util/u_gralloc/u_gralloc_imapper4_api.cpp [new file with mode: 0644]
src/util/u_gralloc/u_gralloc_internal.h [new file with mode: 0644]