1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program Tester Core
3 * ----------------------------------------
4 *
5 * Copyright (c) 2018 The Khronos Group Inc.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 *//*!
20 * \file
21 * \brief OSX Vulkan Platform.
22 *//*--------------------------------------------------------------------*/
23
24 #include "tcuOSXVulkanPlatform.hpp"
25 #include "tcuOSXPlatform.hpp"
26 #include "tcuOSXMetalView.hpp"
27 #include "vkWsiPlatform.hpp"
28 #include "gluPlatform.hpp"
29 #include "tcuFunctionLibrary.hpp"
30 #include "deUniquePtr.hpp"
31 #include "deMemory.h"
32
33 #include <sys/utsname.h>
34
35 using de::MovePtr;
36 using de::UniquePtr;
37
38 namespace tcu
39 {
40 namespace osx
41 {
42
43 class VulkanWindow : public vk::wsi::MacOSWindowInterface
44 {
45 public:
VulkanWindow(MovePtr<osx::MetalView> view)46 VulkanWindow (MovePtr<osx::MetalView> view)
47 : vk::wsi::MacOSWindowInterface(view->getView())
48 , m_view(view)
49 {
50 }
51
setVisible(bool visible)52 void setVisible(bool visible)
53 {
54 }
55
resize(const UVec2 & newSize)56 void resize (const UVec2& newSize) {
57 m_view->setSize(newSize.x(), newSize.y());
58 }
59
60 private:
61 UniquePtr<osx::MetalView> m_view;
62 };
63
64 class VulkanDisplay : public vk::wsi::Display
65 {
66 public:
VulkanDisplay()67 VulkanDisplay ()
68 {
69 }
70
createWindow(const Maybe<UVec2> & initialSize) const71 vk::wsi::Window* createWindow (const Maybe<UVec2>& initialSize) const
72 {
73 const deUint32 width = !initialSize ? 400 : initialSize->x();
74 const deUint32 height = !initialSize ? 300 : initialSize->y();
75 return new VulkanWindow(MovePtr<osx::MetalView>(new osx::MetalView(width, height)));
76 }
77 };
78
79 class VulkanLibrary : public vk::Library
80 {
81 public:
VulkanLibrary(void)82 VulkanLibrary (void)
83 : m_library ("libvulkan.dylib")
84 , m_driver (m_library)
85 {
86 }
87
getPlatformInterface(void) const88 const vk::PlatformInterface& getPlatformInterface (void) const
89 {
90 return m_driver;
91 }
92
getFunctionLibrary(void) const93 const tcu::FunctionLibrary& getFunctionLibrary (void) const
94 {
95 return m_library;
96 }
97
98 private:
99 const DynamicFunctionLibrary m_library;
100 const vk::PlatformDriver m_driver;
101 };
102
VulkanPlatform()103 VulkanPlatform::VulkanPlatform ()
104 {
105 }
106
createWsiDisplay(vk::wsi::Type wsiType) const107 vk::wsi::Display* VulkanPlatform::createWsiDisplay (vk::wsi::Type wsiType) const
108 {
109 if (wsiType != vk::wsi::TYPE_MACOS)
110 TCU_THROW(NotSupportedError, "WSI type not supported");
111
112 return new VulkanDisplay();
113 }
114
hasDisplay(vk::wsi::Type wsiType) const115 bool VulkanPlatform::hasDisplay (vk::wsi::Type wsiType) const
116 {
117 if (wsiType != vk::wsi::TYPE_MACOS)
118 return false;
119
120 return true;
121 }
createLibrary(void) const122 vk::Library* VulkanPlatform::createLibrary (void) const
123 {
124 return new VulkanLibrary();
125 }
126
describePlatform(std::ostream & dst) const127 void VulkanPlatform::describePlatform (std::ostream& dst) const
128 {
129 utsname sysInfo;
130 deMemset(&sysInfo, 0, sizeof(sysInfo));
131
132 if (uname(&sysInfo) != 0)
133 throw std::runtime_error("uname() failed");
134
135 dst << "OS: " << sysInfo.sysname << " " << sysInfo.release << " " << sysInfo.version << "\n";
136 dst << "CPU: " << sysInfo.machine << "\n";
137 }
138
139 } // osx
140 } // tcu
141
142