From dd9a426e3ee8da7e49867b9791446db3ad602e05 Mon Sep 17 00:00:00 2001 From: Roman Stratiienko Date: Thu, 21 Sep 2023 00:59:36 +0300 Subject: [PATCH] vulkan/android: Add basic u_gralloc support We want to move more Android-related functions into common code. Many of which require interactions with the gralloc. Therefore, struct u_gralloc must be kept in a common code. vk_android_get_ugralloc() must be used for gralloc API calls. vk_android_{init|destroy}_ugralloc() must be used in Vulkan HAL initialization code, e.g.: - In XXXX_hal_open() to initialize the gralloc - In XXXX_hal_close() to destroy the gralloc We do not put gralloc initialization into the generic code because we want it to be initialized by Zygote's Vulkan preloader, which may sometimes preload gralloc shared libraries, thus speeding up the initialization of user applications. Change-Id: I2af643bd132e6cdbfed043c8c18836501764952f Signed-off-by: Roman Stratiienko Tested-by: tarsin Acked-by: David Heidelberg Reviewed-by: Rob Clark Part-of: --- src/vulkan/runtime/vk_android.c | 22 ++++++++++++++++++++++ src/vulkan/runtime/vk_android.h | 25 +++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/src/vulkan/runtime/vk_android.c b/src/vulkan/runtime/vk_android.c index df4efae1b5f..05dc459237e 100644 --- a/src/vulkan/runtime/vk_android.c +++ b/src/vulkan/runtime/vk_android.c @@ -40,6 +40,28 @@ #include +static struct u_gralloc *u_gralloc; + +struct u_gralloc * +vk_android_get_ugralloc(void) +{ + return u_gralloc; +} + +struct u_gralloc * +vk_android_init_ugralloc(void) +{ + u_gralloc = u_gralloc_create(U_GRALLOC_TYPE_AUTO); + + return u_gralloc; +} + +void +vk_android_destroy_ugralloc(void) +{ + u_gralloc_destroy(&u_gralloc); +} + #if ANDROID_API_LEVEL >= 26 #include diff --git a/src/vulkan/runtime/vk_android.h b/src/vulkan/runtime/vk_android.h index 496b6c54751..1945840188a 100644 --- a/src/vulkan/runtime/vk_android.h +++ b/src/vulkan/runtime/vk_android.h @@ -31,6 +31,31 @@ extern "C" { #endif +struct u_gralloc; + +#if DETECT_OS_ANDROID +struct u_gralloc *vk_android_get_ugralloc(void); +struct u_gralloc *vk_android_init_ugralloc(void); +void vk_android_destroy_ugralloc(void); +#else +static inline struct u_gralloc * +vk_android_get_ugralloc(void) +{ + return NULL; +} + +static inline struct u_gralloc * +vk_android_init_ugralloc(void) +{ + return NULL; +} + +static inline void +vk_android_destroy_ugralloc(void) +{ +} +#endif + #if DETECT_OS_ANDROID && ANDROID_API_LEVEL >= 26 VkFormat vk_ahb_format_to_image_format(uint32_t ahb_format);