1 /* 2 * MESA: buffer_handle_t is defined by all Mesa builds, even if 3 * one is building for a non-Android target. This avoids unnecessary 4 * conditionals in driver code. 5 * 6 * We don't need to define buffer_handle_t locally when (__ANDROID__) 7 * or ANDROID are set. Here's the distinction between the two: 8 * 9 * - AOSP always defines ANDROID, since it just means one is using the 10 * AOSP tree. It means the build environment is Android, roughly. 11 * - __ANDROID__ is defined by the toolchain. This typically means the 12 * build target is Android. 13 * 14 * If the build environment is Android, AOSP can provide common Android 15 * headers, such as <cutils/native_handle.h>. This allows one to build 16 * and test certain aspects of Android window system code, on the host 17 * system rather the build target. 18 */ 19 20 #if defined(__ANDROID__) || defined(ANDROID) 21 22 #include <cutils/native_handle.h> 23 #if ANDROID_API_LEVEL < 28 24 /* buffer_handle_t was defined in the deprecated system/window.h */ 25 typedef const native_handle_t *buffer_handle_t; 26 #endif 27 28 #else 29 30 typedef void *buffer_handle_t; 31 32 #endif 33 34 /* 35 * Copyright 2015 The Android Open Source Project 36 * 37 * Licensed under the Apache License, Version 2.0 (the "License"); 38 * you may not use this file except in compliance with the License. 39 * You may obtain a copy of the License at 40 * 41 * http://www.apache.org/licenses/LICENSE-2.0 42 * 43 * Unless required by applicable law or agreed to in writing, software 44 * distributed under the License is distributed on an "AS IS" BASIS, 45 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 46 * See the License for the specific language governing permissions and 47 * limitations under the License. 48 */ 49 50 #ifndef __VK_ANDROID_NATIVE_BUFFER_H__ 51 #define __VK_ANDROID_NATIVE_BUFFER_H__ 52 53 #include <vulkan/vulkan.h> 54 55 #ifdef __cplusplus 56 extern "C" { 57 #endif 58 59 #define VK_ANDROID_native_buffer 1 60 61 #define VK_ANDROID_NATIVE_BUFFER_EXTENSION_NUMBER 11 62 /* 63 * NOTE ON VK_ANDROID_NATIVE_BUFFER_SPEC_VERSION 6 64 * 65 * This version of the extension transitions from gralloc0 to gralloc1 usage 66 * flags (int -> 2x uint64_t). The WSI implementation will temporarily continue 67 * to fill out deprecated fields in VkNativeBufferANDROID, and will call the 68 * deprecated vkGetSwapchainGrallocUsageANDROID if the new 69 * vkGetSwapchainGrallocUsage2ANDROID is not supported. This transitionary 70 * backwards-compatibility support is temporary, and will likely be removed 71 * (along with all gralloc0 support) in a future release. 72 */ 73 /* 74 * NOTE ON VK_ANDROID_NATIVE_BUFFER_SPEC_VERSION 8 75 * 76 * This version of the extension doesn't introduce new types or structs, but is 77 * to accommodate the new struct VkBindImageMemorySwapchainInfoKHR added in 78 * VK_KHR_swapchain spec version 69. When VkBindImageMemorySwapchainInfoKHR is 79 * chained in the pNext chain of VkBindImageMemoryInfo, a VkNativeBufferANDROID 80 * that holds the correct gralloc handle according to the imageIndex specified 81 * in VkBindImageMemorySwapchainInfoKHR will be additionally chained to the 82 * pNext chain of VkBindImageMemoryInfo and passed down to the driver. 83 */ 84 /* 85 * NOTE ON VK_ANDROID_NATIVE_BUFFER_SPEC_VERSION 9 86 * 87 * This version of the extension is largely designed to clean up the mix of 88 * GrallocUsage and GrallocUsage2 89 */ 90 /* 91 * NOTE ON VK_ANDROID_NATIVE_BUFFER_SPEC_VERSION 10 92 * 93 * This version of the extension cleans up a bug introduced in version 9 94 */ 95 /* 96 * NOTE ON VK_ANDROID_NATIVE_BUFFER_SPEC_VERSION 11 97 * 98 * This version of the extension deprecates the last of grallocusage and 99 * extends VkNativeBufferANDROID to support passing AHardwareBuffer* 100 */ 101 #define VK_ANDROID_NATIVE_BUFFER_SPEC_VERSION 11 102 #define VK_ANDROID_NATIVE_BUFFER_EXTENSION_NAME "VK_ANDROID_native_buffer" 103 104 #define VK_ANDROID_NATIVE_BUFFER_ENUM(type, id) \ 105 ((type)(1000000000 + \ 106 (1000 * (VK_ANDROID_NATIVE_BUFFER_EXTENSION_NUMBER - 1)) + (id))) 107 #define VK_STRUCTURE_TYPE_NATIVE_BUFFER_ANDROID \ 108 VK_ANDROID_NATIVE_BUFFER_ENUM(VkStructureType, 0) 109 #define VK_STRUCTURE_TYPE_SWAPCHAIN_IMAGE_CREATE_INFO_ANDROID \ 110 VK_ANDROID_NATIVE_BUFFER_ENUM(VkStructureType, 1) 111 #define VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENTATION_PROPERTIES_ANDROID \ 112 VK_ANDROID_NATIVE_BUFFER_ENUM(VkStructureType, 2) 113 #define VK_STRUCTURE_TYPE_GRALLOC_USAGE_INFO_ANDROID \ 114 VK_ANDROID_NATIVE_BUFFER_ENUM(VkStructureType, 3) 115 #define VK_STRUCTURE_TYPE_GRALLOC_USAGE_INFO_2_ANDROID \ 116 VK_ANDROID_NATIVE_BUFFER_ENUM(VkStructureType, 4) 117 118 /* clang-format off */ 119 typedef enum VkSwapchainImageUsageFlagBitsANDROID { 120 VK_SWAPCHAIN_IMAGE_USAGE_SHARED_BIT_ANDROID = 0x00000001, 121 VK_SWAPCHAIN_IMAGE_USAGE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF 122 } VkSwapchainImageUsageFlagBitsANDROID; 123 typedef VkFlags VkSwapchainImageUsageFlagsANDROID; 124 125 /* 126 * struct VkNativeBufferUsage2ANDROID 127 * 128 * consumer: gralloc1 consumer usage flag 129 * producer: gralloc1 producer usage flag 130 */ 131 typedef struct { 132 uint64_t consumer; 133 uint64_t producer; 134 } VkNativeBufferUsage2ANDROID; 135 136 /* 137 * struct VkNativeBufferANDROID 138 * 139 * sType: VK_STRUCTURE_TYPE_NATIVE_BUFFER_ANDROID 140 * pNext: NULL or a pointer to a structure extending this structure 141 * handle: buffer handle returned from gralloc alloc() 142 * stride: stride returned from gralloc alloc() 143 * format: gralloc format requested when the buffer was allocated 144 * usage: gralloc usage requested when the buffer was allocated 145 * usage2: gralloc usage requested when the buffer was allocated 146 * usage3: gralloc usage requested when the buffer was allocated 147 * ahb: The AHardwareBuffer* from the actual ANativeWindowBuffer. Caller 148 * maintains ownership of resource. AHardwareBuffer pointer is only valid 149 * for the duration of the function call 150 */ 151 typedef struct { 152 VkStructureType sType; 153 const void* pNext; 154 buffer_handle_t handle; 155 int stride; 156 int format; 157 int usage; /* DEPRECATED in SPEC_VERSION 6 */ 158 VkNativeBufferUsage2ANDROID usage2; /* DEPRECATED in SPEC_VERSION 9 */ 159 uint64_t usage3; /* ADDED in SPEC_VERSION 9 */ 160 struct AHardwareBuffer* ahb; /* ADDED in SPEC_VERSION 11 */ 161 } VkNativeBufferANDROID; 162 163 /* 164 * struct VkSwapchainImageCreateInfoANDROID 165 * 166 * sType: VK_STRUCTURE_TYPE_SWAPCHAIN_IMAGE_CREATE_INFO_ANDROID 167 * pNext: NULL or a pointer to a structure extending this structure 168 * usage: is a bitmask of VkSwapchainImageUsageFlagsANDROID 169 */ 170 typedef struct { 171 VkStructureType sType; 172 const void* pNext; 173 VkSwapchainImageUsageFlagsANDROID usage; 174 } VkSwapchainImageCreateInfoANDROID; 175 176 /* 177 * struct VkPhysicalDevicePresentationPropertiesANDROID 178 * 179 * sType: VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENTATION_PROPERTIES_ANDROID 180 * pNext: NULL or a pointer to a structure extending this structure 181 * sharedImage: specifies if the image can be shared with the display system 182 */ 183 typedef struct { 184 VkStructureType sType; 185 const void* pNext; 186 VkBool32 sharedImage; 187 } VkPhysicalDevicePresentationPropertiesANDROID; 188 189 /* 190 * struct VkGrallocUsageInfoANDROID 191 * 192 * sType: VK_STRUCTURE_TYPE_GRALLOC_USAGE_INFO_ANDROID 193 * pNext: NULL or a pointer to a structure extending this structure 194 * format: value specifying the format the image will be created with 195 * imageUsage: bitmask of VkImageUsageFlagBits describing intended usage 196 * 197 * DEPRECATED in SPEC_VERSION 10 198 */ 199 typedef struct { 200 VkStructureType sType; 201 const void* pNext; 202 VkFormat format; 203 VkImageUsageFlags imageUsage; 204 } VkGrallocUsageInfoANDROID; 205 206 /* 207 * struct VkGrallocUsageInfo2ANDROID 208 * 209 * sType: VK_STRUCTURE_TYPE_GRALLOC_USAGE_INFO_2_ANDROID 210 * pNext: NULL or a pointer to a structure extending this structure 211 * format: value specifying the format the image will be created with 212 * imageUsage: bitmask of VkImageUsageFlagBits describing intended usage 213 * swapchainImageUsage: is a bitmask of VkSwapchainImageUsageFlagsANDROID 214 * 215 * DEPRECATED in SPEC_VERSION 11 216 */ 217 typedef struct { 218 VkStructureType sType; 219 const void* pNext; 220 VkFormat format; 221 VkImageUsageFlags imageUsage; 222 VkSwapchainImageUsageFlagsANDROID swapchainImageUsage; 223 } VkGrallocUsageInfo2ANDROID; 224 225 /* DEPRECATED in SPEC_VERSION 6 */ 226 typedef VkResult (VKAPI_PTR *PFN_vkGetSwapchainGrallocUsageANDROID)( 227 VkDevice device, 228 VkFormat format, 229 VkImageUsageFlags imageUsage, 230 int* grallocUsage); 231 232 /* DEPRECATED in SPEC_VERSION 9 */ 233 typedef VkResult (VKAPI_PTR *PFN_vkGetSwapchainGrallocUsage2ANDROID)( 234 VkDevice device, 235 VkFormat format, 236 VkImageUsageFlags imageUsage, 237 VkSwapchainImageUsageFlagsANDROID swapchainImageUsage, 238 uint64_t* grallocConsumerUsage, 239 uint64_t* grallocProducerUsage); 240 241 /* DEPRECATED in SPEC_VERSION 10 */ 242 typedef VkResult (VKAPI_PTR *PFN_vkGetSwapchainGrallocUsage3ANDROID)( 243 VkDevice device, 244 const VkGrallocUsageInfoANDROID* grallocUsageInfo, 245 uint64_t* grallocUsage); 246 247 /* DEPRECATED in SPEC_VERSION 11 */ 248 typedef VkResult (VKAPI_PTR *PFN_vkGetSwapchainGrallocUsage4ANDROID)( 249 VkDevice device, 250 const VkGrallocUsageInfo2ANDROID* grallocUsageInfo, 251 uint64_t* grallocUsage); 252 253 typedef VkResult (VKAPI_PTR *PFN_vkAcquireImageANDROID)( 254 VkDevice device, 255 VkImage image, 256 int nativeFenceFd, 257 VkSemaphore semaphore, 258 VkFence fence); 259 260 typedef VkResult (VKAPI_PTR *PFN_vkQueueSignalReleaseImageANDROID)( 261 VkQueue queue, 262 uint32_t waitSemaphoreCount, 263 const VkSemaphore* pWaitSemaphores, 264 VkImage image, 265 int* pNativeFenceFd); 266 267 #ifndef VK_NO_PROTOTYPES 268 269 /* DEPRECATED in SPEC_VERSION 6 */ 270 VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainGrallocUsageANDROID( 271 VkDevice device, 272 VkFormat format, 273 VkImageUsageFlags imageUsage, 274 int* grallocUsage 275 ); 276 277 /* DEPRECATED in SPEC_VERSION 9 */ 278 VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainGrallocUsage2ANDROID( 279 VkDevice device, 280 VkFormat format, 281 VkImageUsageFlags imageUsage, 282 VkSwapchainImageUsageFlagsANDROID swapchainImageUsage, 283 uint64_t* grallocConsumerUsage, 284 uint64_t* grallocProducerUsage 285 ); 286 287 /* DEPRECATED in SPEC_VERSION 10 */ 288 VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainGrallocUsage3ANDROID( 289 VkDevice device, 290 const VkGrallocUsageInfoANDROID* grallocUsageInfo, 291 uint64_t* grallocUsage 292 ); 293 294 /* DEPRECATED in SPEC_VERSION 11 */ 295 VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainGrallocUsage4ANDROID( 296 VkDevice device, 297 const VkGrallocUsageInfo2ANDROID* grallocUsageInfo, 298 uint64_t* grallocUsage 299 ); 300 301 VKAPI_ATTR VkResult VKAPI_CALL vkAcquireImageANDROID( 302 VkDevice device, 303 VkImage image, 304 int nativeFenceFd, 305 VkSemaphore semaphore, 306 VkFence fence 307 ); 308 309 VKAPI_ATTR VkResult VKAPI_CALL vkQueueSignalReleaseImageANDROID( 310 VkQueue queue, 311 uint32_t waitSemaphoreCount, 312 const VkSemaphore* pWaitSemaphores, 313 VkImage image, 314 int* pNativeFenceFd 315 ); 316 317 #endif 318 /* clang-format on */ 319 320 #ifdef __cplusplus 321 } 322 #endif 323 324 #endif /* __VK_ANDROID_NATIVE_BUFFER_H__ */ 325