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