• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 /* MESA: A hack to avoid #ifdefs in driver code. */
21 #ifdef ANDROID
22 #include <system/window.h>
23 #include <vulkan/vulkan.h>
24 #else
25 typedef void *buffer_handle_t;
26 #endif
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 #define VK_ANDROID_native_buffer 1
33 
34 #define VK_ANDROID_NATIVE_BUFFER_EXTENSION_NUMBER 11
35 #define VK_ANDROID_NATIVE_BUFFER_SPEC_VERSION     5
36 #define VK_ANDROID_NATIVE_BUFFER_EXTENSION_NAME   "VK_ANDROID_native_buffer"
37 
38 #define VK_ANDROID_NATIVE_BUFFER_ENUM(type,id)    ((type)(1000000000 + (1000 * (VK_ANDROID_NATIVE_BUFFER_EXTENSION_NUMBER - 1)) + (id)))
39 #define VK_STRUCTURE_TYPE_NATIVE_BUFFER_ANDROID   VK_ANDROID_NATIVE_BUFFER_ENUM(VkStructureType, 0)
40 
41 typedef struct {
42     VkStructureType             sType; // must be VK_STRUCTURE_TYPE_NATIVE_BUFFER_ANDROID
43     const void*                 pNext;
44 
45     // Buffer handle and stride returned from gralloc alloc()
46     buffer_handle_t             handle;
47     int                         stride;
48 
49     // Gralloc format and usage requested when the buffer was allocated.
50     int                         format;
51     int                         usage;
52 } VkNativeBufferANDROID;
53 
54 typedef VkResult (VKAPI_PTR *PFN_vkGetSwapchainGrallocUsageANDROID)(VkDevice device, VkFormat format, VkImageUsageFlags imageUsage, int* grallocUsage);
55 typedef VkResult (VKAPI_PTR *PFN_vkAcquireImageANDROID)(VkDevice device, VkImage image, int nativeFenceFd, VkSemaphore semaphore, VkFence fence);
56 typedef VkResult (VKAPI_PTR *PFN_vkQueueSignalReleaseImageANDROID)(VkQueue queue, uint32_t waitSemaphoreCount, const VkSemaphore* pWaitSemaphores, VkImage image, int* pNativeFenceFd);
57 
58 #ifndef VK_NO_PROTOTYPES
59 VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainGrallocUsageANDROID(
60     VkDevice            device,
61     VkFormat            format,
62     VkImageUsageFlags   imageUsage,
63     int*                grallocUsage
64 );
65 VKAPI_ATTR VkResult VKAPI_CALL vkAcquireImageANDROID(
66     VkDevice            device,
67     VkImage             image,
68     int                 nativeFenceFd,
69     VkSemaphore         semaphore,
70     VkFence             fence
71 );
72 VKAPI_ATTR VkResult VKAPI_CALL vkQueueSignalReleaseImageANDROID(
73     VkQueue             queue,
74     uint32_t            waitSemaphoreCount,
75     const VkSemaphore*  pWaitSemaphores,
76     VkImage             image,
77     int*                pNativeFenceFd
78 );
79 // -- DEPRECATED --
80 VKAPI_ATTR VkResult VKAPI_CALL vkImportNativeFenceANDROID(
81     VkDevice            device,
82     VkSemaphore         semaphore,
83     int                 nativeFenceFd
84 );
85 VKAPI_ATTR VkResult VKAPI_CALL vkQueueSignalNativeFenceANDROID(
86     VkQueue             queue,
87     int*                pNativeFenceFd
88 );
89 // ----------------
90 #endif
91 
92 #ifdef __cplusplus
93 }
94 #endif
95 
96 #endif // __VK_ANDROID_NATIVE_BUFFER_H__
97