mesa/src/util/u_gralloc/u_gralloc_internal.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

57 lines
1.6 KiB
C
Raw Normal View History

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>
2022-08-23 20:08:22 +03:00
/*
* Mesa 3-D graphics library
*
* Copyright (C) 2023 Roman Stratiienko (r.stratiienko@gmail.com)
* SPDX-License-Identifier: MIT
*/
#ifndef U_GRALLOC_INTERNAL_H
#define U_GRALLOC_INTERNAL_H
#ifdef __cplusplus
extern "C" {
#endif
#include "u_gralloc.h"
struct u_gralloc_ops {
int (*get_buffer_basic_info)(struct u_gralloc *gralloc,
struct u_gralloc_buffer_handle *hnd,
struct u_gralloc_buffer_basic_info *out);
int (*get_buffer_color_info)(struct u_gralloc *gralloc,
struct u_gralloc_buffer_handle *hnd,
struct u_gralloc_buffer_color_info *out);
int (*get_front_rendering_usage)(struct u_gralloc *gralloc,
uint64_t *out_usage);
int (*destroy)(struct u_gralloc *gralloc);
};
struct u_gralloc {
struct u_gralloc_ops ops;
int type;
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>
2022-08-23 20:08:22 +03:00
};
extern struct u_gralloc *u_gralloc_cros_api_create(void);
#ifdef USE_IMAPPER4_METADATA_API
extern struct u_gralloc *u_gralloc_imapper_api_create(void);
#endif
extern struct u_gralloc *u_gralloc_qcom_create(void);
extern struct u_gralloc *u_gralloc_libdrm_create(void);
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>
2022-08-23 20:08:22 +03:00
extern struct u_gralloc *u_gralloc_fallback_create(void);
/* Helpers for legacy grallocs */
struct android_ycbcr;
bool is_hal_format_yuv(int native);
int get_hal_format_bpp(int native);
int get_fourcc_from_hal_format(int native);
int bufferinfo_from_ycbcr(const struct android_ycbcr *ycbcr,
struct u_gralloc_buffer_handle *hnd,
struct u_gralloc_buffer_basic_info *out);
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>
2022-08-23 20:08:22 +03:00
#ifdef __cplusplus
}
#endif
#endif /* U_GRALLOC_INTERNAL_H */