1 /* 2 * Copyright 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef __VK_ANDROID_NATIVE_BUFFER_H__ 18 #define __VK_ANDROID_NATIVE_BUFFER_H__ 19 20 #include <cutils/native_handle.h> 21 #include <vulkan/vulkan.h> 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 #define VK_ANDROID_native_buffer 1 28 29 #define VK_ANDROID_NATIVE_BUFFER_EXTENSION_NUMBER 11 30 /* NOTE ON VK_ANDROID_NATIVE_BUFFER_SPEC_VERSION 6 31 * 32 * This version of the extension transitions from gralloc0 to gralloc1 usage 33 * flags (int -> 2x uint64_t). The WSI implementation will temporarily continue 34 * to fill out deprecated fields in VkNativeBufferANDROID, and will call the 35 * deprecated vkGetSwapchainGrallocUsageANDROID if the new 36 * vkGetSwapchainGrallocUsage2ANDROID is not supported. This transitionary 37 * backwards-compatibility support is temporary, and will likely be removed in 38 * (along with all gralloc0 support) in a future release. 39 */ 40 #define VK_ANDROID_NATIVE_BUFFER_SPEC_VERSION 7 41 #define VK_ANDROID_NATIVE_BUFFER_EXTENSION_NAME "VK_ANDROID_native_buffer" 42 43 #define VK_ANDROID_NATIVE_BUFFER_ENUM(type,id) ((type)(1000000000 + (1000 * (VK_ANDROID_NATIVE_BUFFER_EXTENSION_NUMBER - 1)) + (id))) 44 #define VK_STRUCTURE_TYPE_NATIVE_BUFFER_ANDROID VK_ANDROID_NATIVE_BUFFER_ENUM(VkStructureType, 0) 45 #define VK_STRUCTURE_TYPE_SWAPCHAIN_IMAGE_CREATE_INFO_ANDROID VK_ANDROID_NATIVE_BUFFER_ENUM(VkStructureType, 1) 46 #define VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENTATION_PROPERTIES_ANDROID VK_ANDROID_NATIVE_BUFFER_ENUM(VkStructureType, 2) 47 48 typedef enum VkSwapchainImageUsageFlagBitsANDROID { 49 VK_SWAPCHAIN_IMAGE_USAGE_SHARED_BIT_ANDROID = 0x00000001, 50 VK_SWAPCHAIN_IMAGE_USAGE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF 51 } VkSwapchainImageUsageFlagBitsANDROID; 52 typedef VkFlags VkSwapchainImageUsageFlagsANDROID; 53 54 typedef struct { 55 VkStructureType sType; // must be VK_STRUCTURE_TYPE_NATIVE_BUFFER_ANDROID 56 const void* pNext; 57 58 // Buffer handle and stride returned from gralloc alloc() 59 buffer_handle_t handle; 60 int stride; 61 62 // Gralloc format and usage requested when the buffer was allocated. 63 int format; 64 int usage; // DEPRECATED in SPEC_VERSION 6 65 // -- Added in SPEC_VERSION 6 -- 66 struct { 67 uint64_t consumer; 68 uint64_t producer; 69 } usage2; 70 } VkNativeBufferANDROID; 71 72 typedef struct { 73 VkStructureType sType; // must be VK_STRUCTURE_TYPE_SWAPCHAIN_IMAGE_CREATE_INFO_ANDROID 74 const void* pNext; 75 76 VkSwapchainImageUsageFlagsANDROID usage; 77 } VkSwapchainImageCreateInfoANDROID; 78 79 typedef struct { 80 VkStructureType sType; // must be VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENTATION_PROPERTIES_ANDROID 81 const void* pNext; 82 83 VkBool32 sharedImage; 84 } VkPhysicalDevicePresentationPropertiesANDROID; 85 86 // -- DEPRECATED in SPEC_VERSION 6 -- 87 typedef VkResult (VKAPI_PTR *PFN_vkGetSwapchainGrallocUsageANDROID)(VkDevice device, VkFormat format, VkImageUsageFlags imageUsage, int* grallocUsage); 88 // -- ADDED in SPEC_VERSION 6 -- 89 typedef VkResult (VKAPI_PTR *PFN_vkGetSwapchainGrallocUsage2ANDROID)(VkDevice device, VkFormat format, VkImageUsageFlags imageUsage, VkSwapchainImageUsageFlagsANDROID swapchainImageUsage, uint64_t* grallocConsumerUsage, uint64_t* grallocProducerUsage); 90 typedef VkResult (VKAPI_PTR *PFN_vkAcquireImageANDROID)(VkDevice device, VkImage image, int nativeFenceFd, VkSemaphore semaphore, VkFence fence); 91 typedef VkResult (VKAPI_PTR *PFN_vkQueueSignalReleaseImageANDROID)(VkQueue queue, uint32_t waitSemaphoreCount, const VkSemaphore* pWaitSemaphores, VkImage image, int* pNativeFenceFd); 92 93 #ifndef VK_NO_PROTOTYPES 94 95 // -- DEPRECATED in SPEC_VERSION 6 -- 96 VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainGrallocUsageANDROID( 97 VkDevice device, 98 VkFormat format, 99 VkImageUsageFlags imageUsage, 100 int* grallocUsage 101 ); 102 // -- ADDED in SPEC_VERSION 6 -- 103 VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainGrallocUsage2ANDROID( 104 VkDevice device, 105 VkFormat format, 106 VkImageUsageFlags imageUsage, 107 VkSwapchainImageUsageFlagsANDROID swapchainImageUsage, 108 uint64_t* grallocConsumerUsage, 109 uint64_t* grallocProducerUsage 110 ); 111 VKAPI_ATTR VkResult VKAPI_CALL vkAcquireImageANDROID( 112 VkDevice device, 113 VkImage image, 114 int nativeFenceFd, 115 VkSemaphore semaphore, 116 VkFence fence 117 ); 118 VKAPI_ATTR VkResult VKAPI_CALL vkQueueSignalReleaseImageANDROID( 119 VkQueue queue, 120 uint32_t waitSemaphoreCount, 121 const VkSemaphore* pWaitSemaphores, 122 VkImage image, 123 int* pNativeFenceFd 124 ); 125 #endif 126 127 #ifdef __cplusplus 128 } 129 #endif 130 131 #endif // __VK_ANDROID_NATIVE_BUFFER_H__ 132