2 * Copyright (c) 2019, 2021 Arm Limited.
4 * SPDX-License-Identifier: MIT
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:
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
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
27 * @brief Contains the factory methods for obtaining the specific surface and swapchain implementations.
32 #include "swapchain_base.hpp"
33 #include "surface_properties.hpp"
34 #include "util/platform_set.hpp"
36 #include <unordered_map>
42 * @brief Obtains the surface properties for the specific surface type.
44 * @param surface The surface for which to get the properties.
46 * @return nullptr if surface type is unsupported.
48 surface_properties *get_surface_properties(VkSurfaceKHR surface);
51 * @brief Allocates a surface specific swapchain.
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.
57 * @return nullptr on failure.
59 swapchain_base *allocate_surface_swapchain(VkSurfaceKHR surface, layer::device_private_data &dev_data,
60 const VkAllocationCallbacks *pAllocator);
63 * @brief Destroys a swapchain and frees memory. Used with @ref allocate_surface_swapchain.
65 * @param swapchain Pointer to the swapchain to destroy.
66 * @param pAllocator The allocator to use for freeing memory.
68 void destroy_surface_swapchain(swapchain_base *swapchain, const VkAllocationCallbacks *pAllocator);
71 * @brief Return which platforms the layer can handle for an instance constructed in the specified way.
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.
77 * @param pCreateInfo Structure used when creating the instance in vkCreateInstance().
79 * @return A list of WS platforms supported by the layer.
81 util::wsi_platform_set find_enabled_layer_platforms(const VkInstanceCreateInfo *pCreateInfo);
84 * @brief Add extra extensions that the layer requires to support the specified list of enabled platforms.
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.
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.
93 * @retval @c VK_SUCCESS if the operation was successful.
95 VkResult add_extensions_required_by_layer(VkPhysicalDevice phys_dev, const util::wsi_platform_set enabled_platforms,
96 util::extension_list &extensions_to_enable);
99 * @brief Return a function pointer for surface specific functions.
101 * @details This function iterates through the supported platforms and queries them for the
102 * implementation of the @p name function.
104 * @param name The name of the target function
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.
109 PFN_vkVoidFunction get_proc_addr(const char *name);