1c8174fea27f0ffdebc0fe05e0be42216a6a0d92
[platform/core/uifw/vulkan-wsi-tizen.git] / wsi / wsi_factory.hpp
1 /*
2  * Copyright (c) 2019, 2021 Arm Limited.
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24
25 /**
26  * @file
27  * @brief Contains the factory methods for obtaining the specific surface and swapchain implementations.
28  */
29
30 #pragma once
31
32 #include "swapchain_base.hpp"
33 #include "surface_properties.hpp"
34 #include "util/platform_set.hpp"
35
36 #include <unordered_map>
37
38 namespace wsi
39 {
40
41 /**
42  * @brief Obtains the surface properties for the specific surface type.
43  *
44  * @param surface The surface for which to get the properties.
45  *
46  * @return nullptr if surface type is unsupported.
47  */
48 surface_properties *get_surface_properties(VkSurfaceKHR surface);
49
50 /**
51  * @brief Allocates a surface specific swapchain.
52  *
53  * @param surface    The surface for which a swapchain is allocated.
54  * @param dev_data   The device specific data.
55  * @param pAllocator The allocator from which to allocate any memory.
56  *
57  * @return nullptr on failure.
58  */
59 swapchain_base *allocate_surface_swapchain(VkSurfaceKHR surface, layer::device_private_data &dev_data,
60                                            const VkAllocationCallbacks *pAllocator);
61
62 /**
63  * @brief Destroys a swapchain and frees memory. Used with @ref allocate_surface_swapchain.
64  *
65  * @param swapchain  Pointer to the swapchain to destroy.
66  * @param pAllocator The allocator to use for freeing memory.
67  */
68 void destroy_surface_swapchain(swapchain_base *swapchain, const VkAllocationCallbacks *pAllocator);
69
70 /**
71  * @brief Return which platforms the layer can handle for an instance constructed in the specified way.
72  *
73  * @details This function looks at the extensions specified in @p pCreateInfo and based on this returns a list of
74  * platforms that the layer can support. For example, if the @c pCreateInfo.ppEnabledExtensionNames contains the string
75  * "VK_EXT_headless_surface" then the returned platform set will contain @c VK_ICD_WSI_PLATFORM_HEADLESS.
76  *
77  * @param pCreateInfo Structure used when creating the instance in vkCreateInstance().
78  *
79  * @return A list of WS platforms supported by the layer.
80  */
81 util::wsi_platform_set find_enabled_layer_platforms(const VkInstanceCreateInfo *pCreateInfo);
82
83 /**
84  * @brief Add extra extensions that the layer requires to support the specified list of enabled platforms.
85  *
86  * @details Check whether @p phys_dev has support for the extensions required by the layer in order to support the
87  * platforms it implements. The extensions that the layer requires to operate are added to @p extensions_to_enable.
88  *
89  * @param[in] phys_dev The physical device to check.
90  * @param[in] enabled_platforms All the platforms that the layer must enable for @p phys_dev.
91  * @param[in,out] extensions_to_enable All the extensions required by the layer are added to this list.
92  *
93  * @retval @c VK_SUCCESS if the operation was successful.
94  */
95 VkResult add_extensions_required_by_layer(VkPhysicalDevice phys_dev, const util::wsi_platform_set enabled_platforms,
96                                           util::extension_list &extensions_to_enable);
97
98 /**
99  * @brief Return a function pointer for surface specific functions.
100  *
101  * @details This function iterates through the supported platforms and queries them for the
102  * implementation of the @p name function.
103  *
104  * @param name The name of the target function
105  *
106  * @return A pointer to the implementation of the @p name function or null pointer in case this
107  *         function isn't implemented for any platform.
108  */
109 PFN_vkVoidFunction get_proc_addr(const char *name);
110
111 } // namespace wsi