mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-01-10 16:50:13 +01:00
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>
81 lines
1.8 KiB
C
81 lines
1.8 KiB
C
/*
|
|
* Mesa 3-D graphics library
|
|
*
|
|
* Copyright (C) 2022 Roman Stratiienko (r.stratiienko@gmail.com)
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
#ifndef U_GRALLOC_H
|
|
#define U_GRALLOC_H
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#include <cutils/native_handle.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include "util/macros.h"
|
|
#include "GL/internal/dri_interface.h"
|
|
|
|
struct u_gralloc;
|
|
|
|
/* Both Vulkan and EGL API exposes HAL format / pixel stride which is required
|
|
* by the fallback implementation.
|
|
*/
|
|
struct u_gralloc_buffer_handle {
|
|
const native_handle_t *handle;
|
|
int hal_format;
|
|
int pixel_stride;
|
|
};
|
|
|
|
struct u_gralloc_buffer_basic_info {
|
|
uint32_t drm_fourcc;
|
|
uint64_t modifier;
|
|
|
|
int num_planes;
|
|
int fds[4];
|
|
int offsets[4];
|
|
int strides[4];
|
|
};
|
|
|
|
struct u_gralloc_buffer_color_info {
|
|
enum __DRIYUVColorSpace yuv_color_space;
|
|
enum __DRISampleRange sample_range;
|
|
enum __DRIChromaSiting horizontal_siting;
|
|
enum __DRIChromaSiting vertical_siting;
|
|
};
|
|
|
|
enum u_gralloc_type {
|
|
U_GRALLOC_TYPE_AUTO,
|
|
#ifdef USE_IMAPPER4_METADATA_API
|
|
U_GRALLOC_TYPE_GRALLOC4,
|
|
#endif
|
|
U_GRALLOC_TYPE_CROS,
|
|
U_GRALLOC_TYPE_FALLBACK,
|
|
U_GRALLOC_TYPE_COUNT,
|
|
};
|
|
|
|
struct u_gralloc *u_gralloc_create(enum u_gralloc_type type);
|
|
|
|
void u_gralloc_destroy(struct u_gralloc **gralloc NONNULL);
|
|
|
|
int u_gralloc_get_buffer_basic_info(
|
|
struct u_gralloc *gralloc NONNULL,
|
|
struct u_gralloc_buffer_handle *hnd NONNULL,
|
|
struct u_gralloc_buffer_basic_info *out NONNULL);
|
|
|
|
int u_gralloc_get_buffer_color_info(
|
|
struct u_gralloc *gralloc NONNULL,
|
|
struct u_gralloc_buffer_handle *hnd NONNULL,
|
|
struct u_gralloc_buffer_color_info *out NONNULL);
|
|
|
|
int u_gralloc_get_front_rendering_usage(struct u_gralloc *gralloc NONNULL,
|
|
uint64_t *out_usage NONNULL);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* U_GRALLOC_H */
|