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