Implement WSI layer swapchain functions for Tizen:
[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 #if BUILD_WSI_TIZEN
33 #include "swapchain_base_tizen.hpp"
34 #else
35 #include "swapchain_base.hpp"
36 #endif
37 #include "surface_properties.hpp"
38 #include "util/platform_set.hpp"
39
40 #include <unordered_map>
41
42 namespace wsi
43 {
44
45 /**
46  * @brief Obtains the surface properties for the specific surface type.
47  *
48  * @param surface The surface for which to get the properties.
49  *
50  * @return nullptr if surface type is unsupported.
51  */
52 surface_properties *get_surface_properties(VkSurfaceKHR surface);
53
54 /**
55  * @brief Allocates a surface specific swapchain.
56  *
57  * @param surface    The surface for which a swapchain is allocated.
58  * @param dev_data   The device specific data.
59  * @param pAllocator The allocator from which to allocate any memory.
60  *
61  * @return nullptr on failure.
62  */
63 swapchain_base *allocate_surface_swapchain(VkSurfaceKHR surface, layer::device_private_data &dev_data,
64                                            const VkAllocationCallbacks *pAllocator);
65
66 /**
67  * @brief Destroys a swapchain and frees memory. Used with @ref allocate_surface_swapchain.
68  *
69  * @param swapchain  Pointer to the swapchain to destroy.
70  * @param pAllocator The allocator to use for freeing memory.
71  */
72 void destroy_surface_swapchain(swapchain_base *swapchain, const VkAllocationCallbacks *pAllocator);
73
74 /**
75  * @brief Return which platforms the layer can handle for an instance constructed in the specified way.
76  *
77  * @details This function looks at the extensions specified in @p pCreateInfo and based on this returns a list of
78  * platforms that the layer can support. For example, if the @c pCreateInfo.ppEnabledExtensionNames contains the string
79  * "VK_EXT_headless_surface" then the returned platform set will contain @c VK_ICD_WSI_PLATFORM_HEADLESS.
80  *
81  * @param pCreateInfo Structure used when creating the instance in vkCreateInstance().
82  *
83  * @return A list of WS platforms supported by the layer.
84  */
85 util::wsi_platform_set find_enabled_layer_platforms(const VkInstanceCreateInfo *pCreateInfo);
86
87 /**
88  * @brief Add extra extensions that the layer requires to support the specified list of enabled platforms.
89  *
90  * @details Check whether @p phys_dev has support for the extensions required by the layer in order to support the
91  * platforms it implements. The extensions that the layer requires to operate are added to @p extensions_to_enable.
92  *
93  * @param[in] phys_dev The physical device to check.
94  * @param[in] enabled_platforms All the platforms that the layer must enable for @p phys_dev.
95  * @param[in,out] extensions_to_enable All the extensions required by the layer are added to this list.
96  *
97  * @retval @c VK_SUCCESS if the operation was successful.
98  */
99 VkResult add_extensions_required_by_layer(VkPhysicalDevice phys_dev, const util::wsi_platform_set enabled_platforms,
100                                           util::extension_list &extensions_to_enable);
101
102 /**
103  * @brief Return a function pointer for surface specific functions.
104  *
105  * @details This function iterates through the supported platforms and queries them for the
106  * implementation of the @p name function.
107  *
108  * @param name The name of the target function
109  *
110  * @return A pointer to the implementation of the @p name function or null pointer in case this
111  *         function isn't implemented for any platform.
112  */
113 PFN_vkVoidFunction get_proc_addr(const char *name);
114
115 } // namespace wsi