From 0c141ef492ae0613463526b35778ad547f17bdad Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Tue, 17 Jun 2025 18:59:05 -0700 Subject: [PATCH] vulkan/android: update helper to initialize u_gralloc once Initialize u_gralloc once upon the initial init or get call. We'll skip updating the backend drivers for this since most usages will be cleaned up later. Reviewed-by: Mary Guillemard Acked-by: Rob Clark Part-of: --- src/vulkan/runtime/vk_android.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/vulkan/runtime/vk_android.c b/src/vulkan/runtime/vk_android.c index 302e92a5873..1c3dcc04c12 100644 --- a/src/vulkan/runtime/vk_android.c +++ b/src/vulkan/runtime/vk_android.c @@ -34,6 +34,7 @@ #include "vk_enum_defines.h" +#include "c11/threads.h" #include "drm-uapi/drm_fourcc.h" #include "util/libsync.h" #include "util/os_file.h" @@ -50,24 +51,29 @@ static struct u_gralloc *_gralloc; +static void +vk_android_init_ugralloc_once(void) +{ + _gralloc = u_gralloc_create(U_GRALLOC_TYPE_AUTO); +} + struct u_gralloc * vk_android_get_ugralloc(void) { + static once_flag once = ONCE_FLAG_INIT; + call_once(&once, vk_android_init_ugralloc_once); return _gralloc; } struct u_gralloc * vk_android_init_ugralloc(void) { - _gralloc = u_gralloc_create(U_GRALLOC_TYPE_AUTO); - - return _gralloc; + return vk_android_get_ugralloc(); } void vk_android_destroy_ugralloc(void) { - u_gralloc_destroy(&_gralloc); } /* If any bits in test_mask are set, then unset them and return true. */