1 /*
2 * Copyright © 2023 Collabora, Ltd.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23 #ifndef VK_ANDROID_H
24 #define VK_ANDROID_H
25
26 #include <stdbool.h>
27
28 #include "vulkan/vulkan_core.h"
29
30 #include "util/detect_os.h"
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 struct u_gralloc;
37 struct vk_device;
38 struct vk_image;
39 struct AHardwareBuffer;
40
41 #if DETECT_OS_ANDROID
42 struct u_gralloc *vk_android_get_ugralloc(void);
43 struct u_gralloc *vk_android_init_ugralloc(void);
44 void vk_android_destroy_ugralloc(void);
45 VkResult vk_android_import_anb(struct vk_device *device,
46 const VkImageCreateInfo *pCreateInfo,
47 const VkAllocationCallbacks *alloc,
48 struct vk_image *image);
49 VkResult vk_android_get_anb_layout(
50 const VkImageCreateInfo *pCreateInfo,
51 VkImageDrmFormatModifierExplicitCreateInfoEXT *out,
52 VkSubresourceLayout *out_layouts, int max_planes);
53 VkResult vk_android_get_ahb_layout(
54 struct AHardwareBuffer *ahardware_buffer,
55 VkImageDrmFormatModifierExplicitCreateInfoEXT *out,
56 VkSubresourceLayout *out_layouts, int max_planes);
57 #else
58 static inline struct u_gralloc *
vk_android_get_ugralloc(void)59 vk_android_get_ugralloc(void)
60 {
61 return NULL;
62 }
63
64 static inline struct u_gralloc *
vk_android_init_ugralloc(void)65 vk_android_init_ugralloc(void)
66 {
67 return NULL;
68 }
69
70 static inline void
vk_android_destroy_ugralloc(void)71 vk_android_destroy_ugralloc(void)
72 {
73 }
74
75 static inline VkResult
vk_android_import_anb(struct vk_device * device,const VkImageCreateInfo * pCreateInfo,const VkAllocationCallbacks * alloc,struct vk_image * image)76 vk_android_import_anb(struct vk_device *device,
77 const VkImageCreateInfo *pCreateInfo,
78 const VkAllocationCallbacks *alloc,
79 struct vk_image *image)
80 {
81 return VK_ERROR_FEATURE_NOT_PRESENT;
82 }
83
84 static inline VkResult
vk_android_get_anb_layout(const VkImageCreateInfo * pCreateInfo,VkImageDrmFormatModifierExplicitCreateInfoEXT * out,VkSubresourceLayout * out_layouts,int max_planes)85 vk_android_get_anb_layout(
86 const VkImageCreateInfo *pCreateInfo,
87 VkImageDrmFormatModifierExplicitCreateInfoEXT *out,
88 VkSubresourceLayout *out_layouts, int max_planes)
89 {
90 return VK_ERROR_FEATURE_NOT_PRESENT;
91 }
92
93 static inline VkResult
vk_android_get_ahb_layout(struct AHardwareBuffer * ahardware_buffer,VkImageDrmFormatModifierExplicitCreateInfoEXT * out,VkSubresourceLayout * out_layouts,int max_planes)94 vk_android_get_ahb_layout(
95 struct AHardwareBuffer *ahardware_buffer,
96 VkImageDrmFormatModifierExplicitCreateInfoEXT *out,
97 VkSubresourceLayout *out_layouts, int max_planes)
98 {
99 return VK_ERROR_FEATURE_NOT_PRESENT;
100 }
101
102 #endif
103
104 #if DETECT_OS_ANDROID && ANDROID_API_LEVEL >= 26
105
106 VkFormat vk_ahb_format_to_image_format(uint32_t ahb_format);
107
108 uint32_t vk_image_format_to_ahb_format(VkFormat vk_format);
109
110 uint64_t vk_image_usage_to_ahb_usage(const VkImageCreateFlags vk_create,
111 const VkImageUsageFlags vk_usage);
112
113 bool vk_ahb_probe_format(VkFormat vk_format,
114 VkImageCreateFlags vk_create,
115 VkImageUsageFlags vk_usage);
116
117 struct AHardwareBuffer *
118 vk_alloc_ahardware_buffer(const VkMemoryAllocateInfo *pAllocateInfo);
119
120 #else /* DETECT_OS_ANDROID && ANDROID_API_LEVEL >= 26 */
121
122 static inline VkFormat
vk_ahb_format_to_image_format(uint32_t ahb_format)123 vk_ahb_format_to_image_format(uint32_t ahb_format)
124 {
125 return VK_FORMAT_UNDEFINED;
126 }
127
128 static inline uint32_t
vk_image_format_to_ahb_format(VkFormat vk_format)129 vk_image_format_to_ahb_format(VkFormat vk_format)
130 {
131 return 0;
132 }
133
134 static inline uint64_t
vk_image_usage_to_ahb_usage(const VkImageCreateFlags vk_create,const VkImageUsageFlags vk_usage)135 vk_image_usage_to_ahb_usage(const VkImageCreateFlags vk_create,
136 const VkImageUsageFlags vk_usage)
137 {
138 return 0;
139 }
140
141 static inline bool
vk_ahb_probe_format(VkFormat vk_format,VkImageCreateFlags vk_create,VkImageUsageFlags vk_usage)142 vk_ahb_probe_format(VkFormat vk_format,
143 VkImageCreateFlags vk_create,
144 VkImageUsageFlags vk_usage)
145 {
146 return false;
147 }
148
149 static inline struct AHardwareBuffer *
vk_alloc_ahardware_buffer(const VkMemoryAllocateInfo * pAllocateInfo)150 vk_alloc_ahardware_buffer(const VkMemoryAllocateInfo *pAllocateInfo)
151 {
152 return NULL;
153 }
154
155 #endif /* ANDROID_API_LEVEL >= 26 */
156
157 #ifdef __cplusplus
158 }
159 #endif
160
161 #endif /* VK_ANDROID_H */
162