3 * Copyright (c) 2019 Arm Limited.
5 * SPDX-License-Identifier: MIT
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to
9 * deal in the Software without restriction, including without limitation the
10 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
11 * sell copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 * @brief Implements factory methods for obtaining the specific surface and swapchain implementations.
31 #include "wsi_factory.hpp"
36 #include <vulkan/vk_icd.h>
38 #include "headless/surface_properties.hpp"
39 #include "headless/swapchain.hpp"
44 surface_properties *get_surface_properties(VkSurfaceKHR surface)
46 VkIcdSurfaceBase *surface_base = reinterpret_cast<VkIcdSurfaceBase *>(surface);
48 switch (surface_base->platform)
50 case VK_ICD_WSI_PLATFORM_HEADLESS:
51 return &headless::surface_properties::get_instance();
57 template <typename swapchain_type>
58 static swapchain_base *allocate_swapchain(layer::device_private_data &dev_data, const VkAllocationCallbacks *pAllocator)
62 return new swapchain_type(dev_data, pAllocator);
64 void *memory = pAllocator->pfnAllocation(pAllocator->pUserData, sizeof(swapchain_type), alignof(swapchain_type),
65 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
66 return new (memory) swapchain_type(dev_data, pAllocator);
69 swapchain_base *allocate_surface_swapchain(VkSurfaceKHR surface, layer::device_private_data &dev_data,
70 const VkAllocationCallbacks *pAllocator)
72 VkIcdSurfaceBase *surface_base = reinterpret_cast<VkIcdSurfaceBase *>(surface);
74 switch (surface_base->platform)
76 case VK_ICD_WSI_PLATFORM_HEADLESS:
77 return allocate_swapchain<wsi::headless::swapchain>(dev_data, pAllocator);
83 void destroy_surface_swapchain(swapchain_base *swapchain, const VkAllocationCallbacks *pAllocator)
93 swapchain->~swapchain_base();
94 pAllocator->pfnFree(pAllocator->pUserData, reinterpret_cast<void *>(swapchain));