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
setMinimized(bool minimized)60 void setMinimized(bool minimized)
61 {
62 DE_UNREF(minimized);
63 TCU_THROW(NotSupportedError, "Minimized on osx is not implemented");
64 }
65
66 private:
67 UniquePtr<osx::MetalView> m_view;
68 };
69
70 class VulkanDisplay : public vk::wsi::Display
71 {
72 public:
VulkanDisplay()73 VulkanDisplay ()
74 {
75 }
76
createWindow(const Maybe<UVec2> & initialSize) const77 vk::wsi::Window* createWindow (const Maybe<UVec2>& initialSize) const
78 {
79 const deUint32 width = !initialSize ? 400 : initialSize->x();
80 const deUint32 height = !initialSize ? 300 : initialSize->y();
81 return new VulkanWindow(MovePtr<osx::MetalView>(new osx::MetalView(width, height)));
82 }
83 };
84
85 class VulkanLibrary : public vk::Library
86 {
87 public:
VulkanLibrary(const char * libraryPath)88 VulkanLibrary (const char* libraryPath)
89 : m_library (libraryPath != DE_NULL ? libraryPath : "libvulkan.dylib")
90 , m_driver (m_library)
91 {
92 }
93
getPlatformInterface(void) const94 const vk::PlatformInterface& getPlatformInterface (void) const
95 {
96 return m_driver;
97 }
98
getFunctionLibrary(void) const99 const tcu::FunctionLibrary& getFunctionLibrary (void) const
100 {
101 return m_library;
102 }
103
104 private:
105 const DynamicFunctionLibrary m_library;
106 const vk::PlatformDriver m_driver;
107 };
108
VulkanPlatform()109 VulkanPlatform::VulkanPlatform ()
110 {
111 }
112
createWsiDisplay(vk::wsi::Type wsiType) const113 vk::wsi::Display* VulkanPlatform::createWsiDisplay (vk::wsi::Type wsiType) const
114 {
115 if (wsiType != vk::wsi::TYPE_MACOS)
116 TCU_THROW(NotSupportedError, "WSI type not supported");
117
118 return new VulkanDisplay();
119 }
120
hasDisplay(vk::wsi::Type wsiType) const121 bool VulkanPlatform::hasDisplay (vk::wsi::Type wsiType) const
122 {
123 if (wsiType != vk::wsi::TYPE_MACOS)
124 return false;
125
126 return true;
127 }
createLibrary(const char * libraryPath) const128 vk::Library* VulkanPlatform::createLibrary (const char* libraryPath) const
129 {
130 return new VulkanLibrary(libraryPath);
131 }
132
describePlatform(std::ostream & dst) const133 void VulkanPlatform::describePlatform (std::ostream& dst) const
134 {
135 utsname sysInfo;
136 deMemset(&sysInfo, 0, sizeof(sysInfo));
137
138 if (uname(&sysInfo) != 0)
139 throw std::runtime_error("uname() failed");
140
141 dst << "OS: " << sysInfo.sysname << " " << sysInfo.release << " " << sysInfo.version << "\n";
142 dst << "CPU: " << sysInfo.machine << "\n";
143 }
144
145 } // osx
146 } // tcu
147
148