1 | // Copyright 2013 The Flutter Authors. All rights reserved. |
---|---|
2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. |
4 | |
5 | #ifndef FLUTTER_VULKAN_VULKAN_PROC_TABLE_H_ |
6 | #define FLUTTER_VULKAN_VULKAN_PROC_TABLE_H_ |
7 | |
8 | #include "flutter/fml/macros.h" |
9 | #include "flutter/fml/memory/ref_counted.h" |
10 | #include "flutter/fml/memory/ref_ptr.h" |
11 | #include "third_party/skia/include/core/SkRefCnt.h" |
12 | #include "third_party/skia/include/gpu/vk/GrVkBackendContext.h" |
13 | #include "vulkan_handle.h" |
14 | #include "vulkan_interface.h" |
15 | |
16 | namespace vulkan { |
17 | |
18 | class VulkanProcTable : public fml::RefCountedThreadSafe<VulkanProcTable> { |
19 | FML_FRIEND_REF_COUNTED_THREAD_SAFE(VulkanProcTable); |
20 | FML_FRIEND_MAKE_REF_COUNTED(VulkanProcTable); |
21 | |
22 | public: |
23 | template <class T> |
24 | class Proc { |
25 | public: |
26 | using Proto = T; |
27 | |
28 | Proc(T proc = nullptr) : proc_(proc) {} |
29 | |
30 | ~Proc() { proc_ = nullptr; } |
31 | |
32 | Proc operator=(T proc) { |
33 | proc_ = proc; |
34 | return *this; |
35 | } |
36 | |
37 | Proc operator=(PFN_vkVoidFunction proc) { |
38 | proc_ = reinterpret_cast<Proto>(proc); |
39 | return *this; |
40 | } |
41 | |
42 | operator bool() const { return proc_ != nullptr; } |
43 | |
44 | operator T() const { return proc_; } |
45 | |
46 | private: |
47 | T proc_; |
48 | }; |
49 | |
50 | bool HasAcquiredMandatoryProcAddresses() const; |
51 | |
52 | bool IsValid() const; |
53 | |
54 | bool AreInstanceProcsSetup() const; |
55 | |
56 | bool AreDeviceProcsSetup() const; |
57 | |
58 | bool SetupInstanceProcAddresses(const VulkanHandle<VkInstance>& instance); |
59 | |
60 | bool SetupDeviceProcAddresses(const VulkanHandle<VkDevice>& device); |
61 | |
62 | GrVkGetProc CreateSkiaGetProc() const; |
63 | |
64 | #define DEFINE_PROC(name) Proc<PFN_vk##name> name; |
65 | |
66 | DEFINE_PROC(AcquireNextImageKHR); |
67 | DEFINE_PROC(AllocateCommandBuffers); |
68 | DEFINE_PROC(AllocateMemory); |
69 | DEFINE_PROC(BeginCommandBuffer); |
70 | DEFINE_PROC(BindImageMemory); |
71 | DEFINE_PROC(CmdPipelineBarrier); |
72 | DEFINE_PROC(CreateCommandPool); |
73 | DEFINE_PROC(CreateDebugReportCallbackEXT); |
74 | DEFINE_PROC(CreateDevice); |
75 | DEFINE_PROC(CreateFence); |
76 | DEFINE_PROC(CreateImage); |
77 | DEFINE_PROC(CreateInstance); |
78 | DEFINE_PROC(CreateSemaphore); |
79 | DEFINE_PROC(CreateSwapchainKHR); |
80 | DEFINE_PROC(DestroyCommandPool); |
81 | DEFINE_PROC(DestroyDebugReportCallbackEXT); |
82 | DEFINE_PROC(DestroyDevice); |
83 | DEFINE_PROC(DestroyFence); |
84 | DEFINE_PROC(DestroyImage); |
85 | DEFINE_PROC(DestroyInstance); |
86 | DEFINE_PROC(DestroySemaphore); |
87 | DEFINE_PROC(DestroySurfaceKHR); |
88 | DEFINE_PROC(DestroySwapchainKHR); |
89 | DEFINE_PROC(DeviceWaitIdle); |
90 | DEFINE_PROC(EndCommandBuffer); |
91 | DEFINE_PROC(EnumerateDeviceLayerProperties); |
92 | DEFINE_PROC(EnumerateInstanceExtensionProperties); |
93 | DEFINE_PROC(EnumerateInstanceLayerProperties); |
94 | DEFINE_PROC(EnumeratePhysicalDevices); |
95 | DEFINE_PROC(FreeCommandBuffers); |
96 | DEFINE_PROC(FreeMemory); |
97 | DEFINE_PROC(GetDeviceProcAddr); |
98 | DEFINE_PROC(GetDeviceQueue); |
99 | DEFINE_PROC(GetImageMemoryRequirements); |
100 | DEFINE_PROC(GetInstanceProcAddr); |
101 | DEFINE_PROC(GetPhysicalDeviceFeatures); |
102 | DEFINE_PROC(GetPhysicalDeviceQueueFamilyProperties); |
103 | DEFINE_PROC(QueueSubmit); |
104 | DEFINE_PROC(QueueWaitIdle); |
105 | DEFINE_PROC(ResetCommandBuffer); |
106 | DEFINE_PROC(ResetFences); |
107 | DEFINE_PROC(WaitForFences); |
108 | #if OS_ANDROID |
109 | DEFINE_PROC(GetPhysicalDeviceSurfaceCapabilitiesKHR); |
110 | DEFINE_PROC(GetPhysicalDeviceSurfaceFormatsKHR); |
111 | DEFINE_PROC(GetPhysicalDeviceSurfacePresentModesKHR); |
112 | DEFINE_PROC(GetPhysicalDeviceSurfaceSupportKHR); |
113 | DEFINE_PROC(GetSwapchainImagesKHR); |
114 | DEFINE_PROC(QueuePresentKHR); |
115 | DEFINE_PROC(CreateAndroidSurfaceKHR); |
116 | #endif // OS_ANDROID |
117 | #if OS_FUCHSIA |
118 | DEFINE_PROC(GetMemoryZirconHandleFUCHSIA); |
119 | DEFINE_PROC(ImportSemaphoreZirconHandleFUCHSIA); |
120 | #endif // OS_FUCHSIA |
121 | |
122 | #undef DEFINE_PROC |
123 | |
124 | private: |
125 | void* handle_; |
126 | bool acquired_mandatory_proc_addresses_; |
127 | VulkanHandle<VkInstance> instance_; |
128 | VulkanHandle<VkDevice> device_; |
129 | |
130 | VulkanProcTable(); |
131 | ~VulkanProcTable(); |
132 | bool OpenLibraryHandle(); |
133 | bool SetupLoaderProcAddresses(); |
134 | bool CloseLibraryHandle(); |
135 | PFN_vkVoidFunction AcquireProc( |
136 | const char* proc_name, |
137 | const VulkanHandle<VkInstance>& instance) const; |
138 | PFN_vkVoidFunction AcquireProc(const char* proc_name, |
139 | const VulkanHandle<VkDevice>& device) const; |
140 | |
141 | FML_DISALLOW_COPY_AND_ASSIGN(VulkanProcTable); |
142 | }; |
143 | |
144 | } // namespace vulkan |
145 | |
146 | #endif // FLUTTER_VULKAN_VULKAN_PROC_TABLE_H_ |
147 |