xref: /aosp_15_r20/external/deqp/external/vulkancts/modules/vulkan/wsi/vktNativeObjectsUtil.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 /*-------------------------------------------------------------------------
2  * Vulkan Conformance Tests
3  * ------------------------
4  *
5  * Copyright (c) 2019 The Khronos Group Inc.
6  * Copyright (c) 2019 Valve Corporation.
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  *//*!
21  * \file
22  * \brief WSI Native Objects utility class.
23  *//*--------------------------------------------------------------------*/
24 #include "vktNativeObjectsUtil.hpp"
25 
26 #include "vkQueryUtil.hpp"
27 #include "vkWsiUtil.hpp"
28 
29 #include "tcuPlatform.hpp"
30 
31 #include "deDefs.hpp"
32 
33 namespace vkt
34 {
35 namespace wsi
36 {
37 
createDisplay(const vk::Platform & platform,const NativeObjects::Extensions & supportedExtensions,vk::wsi::Type wsiType)38 de::MovePtr<vk::wsi::Display> NativeObjects::createDisplay(const vk::Platform &platform,
39                                                            const NativeObjects::Extensions &supportedExtensions,
40                                                            vk::wsi::Type wsiType)
41 {
42     try
43     {
44         return de::MovePtr<vk::wsi::Display>(platform.createWsiDisplay(wsiType));
45     }
46     catch (const tcu::NotSupportedError &e)
47     {
48         if (vk::isExtensionStructSupported(supportedExtensions,
49                                            vk::RequiredExtension(vk::wsi::getExtensionName(wsiType))) &&
50             platform.hasDisplay(wsiType))
51         {
52             // If VK_KHR_{platform}_surface was supported, vk::Platform implementation
53             // must support creating native display & window for that WSI type.
54             throw tcu::TestError(e.getMessage());
55         }
56         else
57             throw;
58     }
59 }
60 
createWindow(const vk::wsi::Display & display,const tcu::Maybe<tcu::UVec2> & initialSize)61 de::MovePtr<vk::wsi::Window> NativeObjects::createWindow(const vk::wsi::Display &display,
62                                                          const tcu::Maybe<tcu::UVec2> &initialSize)
63 {
64     try
65     {
66         return de::MovePtr<vk::wsi::Window>(display.createWindow(initialSize));
67     }
68     catch (const tcu::NotSupportedError &e)
69     {
70         // See createDisplay - assuming that wsi::Display was supported platform port
71         // should also support creating a window.
72         throw tcu::TestError(e.getMessage());
73     }
74 }
75 
NativeObjects(Context & context,const Extensions & supportedExtensions,vk::wsi::Type wsiType,size_t windowCount,const tcu::Maybe<tcu::UVec2> & initialWindowSize)76 NativeObjects::NativeObjects(Context &context, const Extensions &supportedExtensions, vk::wsi::Type wsiType,
77                              size_t windowCount, const tcu::Maybe<tcu::UVec2> &initialWindowSize)
78     : display(createDisplay(context.getTestContext().getPlatform().getVulkanPlatform(), supportedExtensions, wsiType))
79 {
80     DE_ASSERT(windowCount > 0u);
81     for (size_t i = 0; i < windowCount; ++i)
82         windows.emplace_back(createWindow(*display, initialWindowSize));
83 }
84 
NativeObjects(NativeObjects && other)85 NativeObjects::NativeObjects(NativeObjects &&other) : display(other.display.move()), windows()
86 {
87     windows.swap(other.windows);
88 }
89 
getDisplay() const90 vk::wsi::Display &NativeObjects::getDisplay() const
91 {
92     return *display;
93 }
94 
getWindow(size_t index) const95 vk::wsi::Window &NativeObjects::getWindow(size_t index) const
96 {
97     DE_ASSERT(index < windows.size());
98     return *windows[index];
99 }
100 
101 } // namespace wsi
102 } // namespace vkt
103