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, vk::RequiredExtension(vk::wsi::getExtensionName(wsiType))) &&
49 platform.hasDisplay(wsiType))
50 {
51 // If VK_KHR_{platform}_surface was supported, vk::Platform implementation
52 // must support creating native display & window for that WSI type.
53 throw tcu::TestError(e.getMessage());
54 }
55 else
56 throw;
57 }
58 }
59
createWindow(const vk::wsi::Display & display,const tcu::Maybe<tcu::UVec2> & initialSize)60 de::MovePtr<vk::wsi::Window> NativeObjects::createWindow (const vk::wsi::Display& display, const tcu::Maybe<tcu::UVec2>& initialSize)
61 {
62 try
63 {
64 return de::MovePtr<vk::wsi::Window>(display.createWindow(initialSize));
65 }
66 catch (const tcu::NotSupportedError& e)
67 {
68 // See createDisplay - assuming that wsi::Display was supported platform port
69 // should also support creating a window.
70 throw tcu::TestError(e.getMessage());
71 }
72 }
73
NativeObjects(Context & context,const Extensions & supportedExtensions,vk::wsi::Type wsiType,size_t windowCount,const tcu::Maybe<tcu::UVec2> & initialWindowSize)74 NativeObjects::NativeObjects (Context& context,
75 const Extensions& supportedExtensions,
76 vk::wsi::Type wsiType,
77 size_t windowCount,
78 const tcu::Maybe<tcu::UVec2>& initialWindowSize)
79 : display (createDisplay(context.getTestContext().getPlatform().getVulkanPlatform(), supportedExtensions, wsiType))
80 {
81 DE_ASSERT(windowCount > 0u);
82 for (size_t i = 0; i < windowCount; ++i)
83 windows.emplace_back(createWindow(*display, initialWindowSize));
84 }
85
NativeObjects(NativeObjects && other)86 NativeObjects::NativeObjects (NativeObjects&& other)
87 : display (other.display.move())
88 , windows ()
89 {
90 windows.swap(other.windows);
91 }
92
getDisplay() const93 vk::wsi::Display& NativeObjects::getDisplay () const
94 {
95 return *display;
96 }
97
getWindow(size_t index) const98 vk::wsi::Window& NativeObjects::getWindow (size_t index) const
99 {
100 DE_ASSERT(index < windows.size());
101 return *windows[index];
102 }
103
104 } // wsi
105 } // vkt
106