52c98cdff00cb4d07822043593e8ae2f54a0ac0e
[platform/core/uifw/vulkan-wsi-tizen.git] / layer / surface_api.cpp
1 /*
2  * Copyright (c) 2016-2017, 2019 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 #include <cassert>
26
27 #include <wsi/wsi_factory.hpp>
28
29 #include "private_data.hpp"
30 #include "surface_api.hpp"
31
32 extern "C"
33 {
34
35    /**
36     * @brief Implements vkGetPhysicalDeviceSurfaceCapabilitiesKHR Vulkan entrypoint.
37     */
38    VKAPI_ATTR VkResult wsi_layer_vkGetPhysicalDeviceSurfaceCapabilitiesKHR(
39       VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, VkSurfaceCapabilitiesKHR *pSurfaceCapabilities)
40    {
41       wsi::surface_properties *props = wsi::get_surface_properties(surface);
42       if (props)
43       {
44          return props->get_surface_capabilities(physicalDevice, surface, pSurfaceCapabilities);
45       }
46
47       return layer::instance_private_data::get(layer::get_key(physicalDevice))
48          .disp.GetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, surface, pSurfaceCapabilities);
49    }
50
51    /**
52     * @brief Implements vkGetPhysicalDeviceSurfaceFormatsKHR Vulkan entrypoint.
53     */
54    VKAPI_ATTR VkResult wsi_layer_vkGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice,
55                                                                       VkSurfaceKHR surface,
56                                                                       uint32_t *pSurfaceFormatCount,
57                                                                       VkSurfaceFormatKHR *pSurfaceFormats)
58    {
59       wsi::surface_properties *props = wsi::get_surface_properties(surface);
60       if (props)
61       {
62          return props->get_surface_formats(physicalDevice, surface, pSurfaceFormatCount, pSurfaceFormats);
63       }
64
65       return layer::instance_private_data::get(layer::get_key(physicalDevice))
66          .disp.GetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, surface, pSurfaceFormatCount, pSurfaceFormats);
67    }
68
69    /**
70     * @brief Implements vkGetPhysicalDeviceSurfacePresentModesKHR Vulkan entrypoint.
71     */
72    VKAPI_ATTR VkResult wsi_layer_vkGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,
73                                                                            VkSurfaceKHR surface,
74                                                                            uint32_t *pPresentModeCount,
75                                                                            VkPresentModeKHR *pPresentModes)
76    {
77       wsi::surface_properties *props = wsi::get_surface_properties(surface);
78       if (props)
79       {
80          return props->get_surface_present_modes(physicalDevice, surface, pPresentModeCount, pPresentModes);
81       }
82
83       return layer::instance_private_data::get(layer::get_key(physicalDevice))
84          .disp.GetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, surface, pPresentModeCount, pPresentModes);
85    }
86
87    /**
88     * @brief Implements vkGetPhysicalDeviceSurfaceSupportKHR Vulkan entrypoint.
89     */
90    VKAPI_ATTR VkResult wsi_layer_vkGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,
91                                                                       uint32_t queueFamilyIndex, VkSurfaceKHR surface,
92                                                                       VkBool32 *pSupported)
93    {
94       wsi::surface_properties *props = wsi::get_surface_properties(surface);
95       /* We assume that presentation to surface is supported by default */
96       if (props)
97       {
98          *pSupported = VK_TRUE;
99          return VK_SUCCESS;
100       }
101
102       return layer::instance_private_data::get(layer::get_key(physicalDevice))
103          .disp.GetPhysicalDeviceSurfaceSupportKHR(physicalDevice, queueFamilyIndex, surface, pSupported);
104    }
105
106 } /* extern "C" */