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 © 2021, Google Inc.
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "u_gralloc_internal.h"
|
|
|
|
|
|
|
|
|
|
#include <hardware/gralloc.h>
|
|
|
|
|
|
|
|
|
|
#include "drm-uapi/drm_fourcc.h"
|
|
|
|
|
#include "util/log.h"
|
|
|
|
|
#include "util/macros.h"
|
|
|
|
|
#include "util/u_memory.h"
|
|
|
|
|
|
|
|
|
|
#include <dlfcn.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
struct fallback_gralloc {
|
|
|
|
|
struct u_gralloc base;
|
|
|
|
|
gralloc_module_t *gralloc_module;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* returns # of fds, and by reference the actual fds */
|
|
|
|
|
static unsigned
|
|
|
|
|
get_native_buffer_fds(const native_handle_t *handle, int fds[3])
|
|
|
|
|
{
|
|
|
|
|
if (!handle)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Various gralloc implementations exist, but the dma-buf fd tends
|
|
|
|
|
* to be first. Access it directly to avoid a dependency on specific
|
|
|
|
|
* gralloc versions.
|
|
|
|
|
*/
|
|
|
|
|
for (int i = 0; i < handle->numFds; i++)
|
|
|
|
|
fds[i] = handle->data[i];
|
|
|
|
|
|
|
|
|
|
return handle->numFds;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
fallback_gralloc_get_yuv_info(struct u_gralloc *gralloc,
|
|
|
|
|
struct u_gralloc_buffer_handle *hnd,
|
|
|
|
|
struct u_gralloc_buffer_basic_info *out)
|
|
|
|
|
{
|
|
|
|
|
struct fallback_gralloc *gr = (struct fallback_gralloc *)gralloc;
|
|
|
|
|
gralloc_module_t *gr_mod = gr->gralloc_module;
|
|
|
|
|
struct android_ycbcr ycbcr;
|
|
|
|
|
int num_fds = 0;
|
|
|
|
|
int fds[3];
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
num_fds = get_native_buffer_fds(hnd->handle, fds);
|
|
|
|
|
if (num_fds == 0)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
|
|
if (!gr_mod || !gr_mod->lock_ycbcr) {
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memset(&ycbcr, 0, sizeof(ycbcr));
|
|
|
|
|
ret = gr_mod->lock_ycbcr(gr_mod, hnd->handle, 0, 0, 0, 0, 0, &ycbcr);
|
|
|
|
|
if (ret) {
|
|
|
|
|
/* HACK: See native_window_buffer_get_buffer_info() and
|
|
|
|
|
* https://issuetracker.google.com/32077885.*/
|
|
|
|
|
if (hnd->hal_format == HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED)
|
|
|
|
|
return -EAGAIN;
|
|
|
|
|
|
|
|
|
|
mesa_logw("gralloc->lock_ycbcr failed: %d", ret);
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
gr_mod->unlock(gr_mod, hnd->handle);
|
|
|
|
|
|
2023-10-04 00:59:17 +03:00
|
|
|
ret = bufferinfo_from_ycbcr(&ycbcr, hnd, out);
|
|
|
|
|
if (ret)
|
|
|
|
|
return ret;
|
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
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Since this is EGL_NATIVE_BUFFER_ANDROID don't assume that
|
|
|
|
|
* the single-fd case cannot happen. So handle eithe single
|
|
|
|
|
* fd or fd-per-plane case:
|
|
|
|
|
*/
|
|
|
|
|
if (num_fds == 1) {
|
|
|
|
|
out->fds[1] = out->fds[0] = fds[0];
|
|
|
|
|
if (out->num_planes == 3)
|
|
|
|
|
out->fds[2] = fds[0];
|
|
|
|
|
} else {
|
|
|
|
|
assert(num_fds == out->num_planes);
|
|
|
|
|
out->fds[0] = fds[0];
|
|
|
|
|
out->fds[1] = fds[1];
|
|
|
|
|
out->fds[2] = fds[2];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
fallback_gralloc_get_buffer_info(struct u_gralloc *gralloc,
|
|
|
|
|
struct u_gralloc_buffer_handle *hnd,
|
|
|
|
|
struct u_gralloc_buffer_basic_info *out)
|
|
|
|
|
{
|
|
|
|
|
int num_planes = 0;
|
|
|
|
|
int drm_fourcc = 0;
|
|
|
|
|
int stride = 0;
|
|
|
|
|
|
2024-05-17 07:22:45 +00:00
|
|
|
if (hnd->handle->numFds == 0)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
2023-10-04 00:59:17 +03:00
|
|
|
if (is_hal_format_yuv(hnd->hal_format)) {
|
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
|
|
|
int ret = fallback_gralloc_get_yuv_info(gralloc, hnd, out);
|
|
|
|
|
/*
|
|
|
|
|
* HACK: https://issuetracker.google.com/32077885
|
|
|
|
|
* There is no API available to properly query the
|
|
|
|
|
* IMPLEMENTATION_DEFINED format. As a workaround we rely here on
|
|
|
|
|
* gralloc allocating either an arbitrary YCbCr 4:2:0 or RGBX_8888, with
|
|
|
|
|
* the latter being recognized by lock_ycbcr failing.
|
|
|
|
|
*/
|
|
|
|
|
if (ret != -EAGAIN)
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Non-YUV formats could *also* have multiple planes, such as ancillary
|
|
|
|
|
* color compression state buffer, but the rest of the code isn't ready
|
|
|
|
|
* yet to deal with modifiers:
|
|
|
|
|
*/
|
2024-05-17 07:22:45 +00:00
|
|
|
num_planes = 1;
|
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
|
|
|
|
2023-10-04 00:59:17 +03:00
|
|
|
drm_fourcc = get_fourcc_from_hal_format(hnd->hal_format);
|
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
|
|
|
if (drm_fourcc == -1) {
|
|
|
|
|
mesa_loge("Failed to get drm_fourcc");
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-04 00:59:17 +03:00
|
|
|
stride = hnd->pixel_stride * get_hal_format_bpp(hnd->hal_format);
|
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
|
|
|
if (stride == 0) {
|
|
|
|
|
mesa_loge("Failed to calcuulate stride");
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out->drm_fourcc = drm_fourcc;
|
|
|
|
|
out->modifier = DRM_FORMAT_MOD_INVALID;
|
|
|
|
|
out->num_planes = num_planes;
|
2024-06-19 14:53:32 +01:00
|
|
|
out->fds[0] = hnd->handle->data[0];
|
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
|
|
|
out->strides[0] = stride;
|
|
|
|
|
|
2024-05-17 07:22:45 +00:00
|
|
|
#ifdef HAS_FREEDRENO
|
|
|
|
|
uint32_t gmsm = ('g' << 24) | ('m' << 16) | ('s' << 8) | 'm';
|
|
|
|
|
if (hnd->handle->numInts >= 2 && hnd->handle->data[hnd->handle->numFds] == gmsm) {
|
|
|
|
|
/* This UBWC flag was introduced in a5xx. */
|
|
|
|
|
bool ubwc = hnd->handle->data[hnd->handle->numFds + 1] & 0x08000000;
|
|
|
|
|
out->modifier = ubwc ? DRM_FORMAT_MOD_QCOM_COMPRESSED : DRM_FORMAT_MOD_LINEAR;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
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
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
destroy(struct u_gralloc *gralloc)
|
|
|
|
|
{
|
|
|
|
|
struct fallback_gralloc *gr = (struct fallback_gralloc *)gralloc;
|
|
|
|
|
if (gr->gralloc_module) {
|
|
|
|
|
dlclose(gr->gralloc_module->common.dso);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FREE(gr);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct u_gralloc *
|
|
|
|
|
u_gralloc_fallback_create()
|
|
|
|
|
{
|
|
|
|
|
struct fallback_gralloc *gr = CALLOC_STRUCT(fallback_gralloc);
|
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
|
|
err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID,
|
|
|
|
|
(const hw_module_t **)&gr->gralloc_module);
|
|
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
|
mesa_logw(
|
|
|
|
|
"No gralloc hwmodule detected (video buffers won't be supported)");
|
|
|
|
|
} else if (!gr->gralloc_module->lock_ycbcr) {
|
|
|
|
|
mesa_logw("Gralloc doesn't support lock_ycbcr (video buffers won't be "
|
|
|
|
|
"supported)");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gr->base.ops.get_buffer_basic_info = fallback_gralloc_get_buffer_info;
|
|
|
|
|
gr->base.ops.destroy = destroy;
|
|
|
|
|
|
|
|
|
|
mesa_logi("Using fallback gralloc implementation");
|
|
|
|
|
|
|
|
|
|
return &gr->base;
|
|
|
|
|
}
|