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_APPLICATION_H_ |
6 | #define FLUTTER_VULKAN_VULKAN_APPLICATION_H_ |
7 | |
8 | #include <memory> |
9 | #include <string> |
10 | #include <vector> |
11 | #include "flutter/fml/macros.h" |
12 | #include "vulkan_debug_report.h" |
13 | #include "vulkan_handle.h" |
14 | |
15 | namespace vulkan { |
16 | |
17 | static const int kGrCacheMaxCount = 8192; |
18 | static const size_t kGrCacheMaxByteSize = 512 * (1 << 20); |
19 | |
20 | class VulkanDevice; |
21 | class VulkanProcTable; |
22 | |
23 | /// Applications using Vulkan acquire a VulkanApplication that attempts to |
24 | /// create a VkInstance (with debug reporting optionally enabled). |
25 | class VulkanApplication { |
26 | public: |
27 | VulkanApplication(VulkanProcTable& vk, // NOLINT |
28 | const std::string& application_name, |
29 | std::vector<std::string> enabled_extensions, |
30 | uint32_t application_version = VK_MAKE_VERSION(1, 0, 0), |
31 | uint32_t api_version = VK_MAKE_VERSION(1, 0, 0), |
32 | bool enable_validation_layers = false); |
33 | |
34 | ~VulkanApplication(); |
35 | |
36 | bool IsValid() const; |
37 | |
38 | uint32_t GetAPIVersion() const; |
39 | |
40 | const VulkanHandle<VkInstance>& GetInstance() const; |
41 | |
42 | void ReleaseInstanceOwnership(); |
43 | |
44 | std::unique_ptr<VulkanDevice> AcquireFirstCompatibleLogicalDevice() const; |
45 | |
46 | private: |
47 | VulkanProcTable& vk; |
48 | VulkanHandle<VkInstance> instance_; |
49 | uint32_t api_version_; |
50 | std::unique_ptr<VulkanDebugReport> debug_report_; |
51 | bool valid_; |
52 | bool enable_validation_layers_; |
53 | |
54 | std::vector<VkPhysicalDevice> GetPhysicalDevices() const; |
55 | std::vector<VkExtensionProperties> GetSupportedInstanceExtensions( |
56 | const VulkanProcTable& vk) const; |
57 | bool ExtensionSupported( |
58 | const std::vector<VkExtensionProperties>& supported_extensions, |
59 | std::string extension_name); |
60 | |
61 | FML_DISALLOW_COPY_AND_ASSIGN(VulkanApplication); |
62 | }; |
63 | |
64 | } // namespace vulkan |
65 | |
66 | #endif // FLUTTER_VULKAN_VULKAN_APPLICATION_H_ |
67 | |