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 35using de::MovePtr; 36using de::UniquePtr; 37 38namespace tcu 39{ 40namespace osx 41{ 42 43class VulkanWindow : public vk::wsi::MacOSWindowInterface 44{ 45public: 46 VulkanWindow (MovePtr<osx::MetalView> view) 47 : vk::wsi::MacOSWindowInterface(view->getView()) 48 , m_view(view) 49 { 50 } 51 52 void setVisible(bool visible) 53 { 54 } 55 56 void resize (const UVec2& newSize) { 57 m_view->setSize(newSize.x(), newSize.y()); 58 } 59 60 void setMinimized(bool minimized) 61 { 62 DE_UNREF(minimized); 63 TCU_THROW(NotSupportedError, "Minimized on osx is not implemented"); 64 } 65 66private: 67 UniquePtr<osx::MetalView> m_view; 68}; 69 70class VulkanDisplay : public vk::wsi::Display 71{ 72public: 73 VulkanDisplay () 74 { 75 } 76 77 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 85class VulkanLibrary : public vk::Library 86{ 87public: 88 VulkanLibrary (const char* libraryPath) 89 : m_library (libraryPath != DE_NULL ? libraryPath : "libvulkan.dylib") 90 , m_driver (m_library) 91 { 92 } 93 94 const vk::PlatformInterface& getPlatformInterface (void) const 95 { 96 return m_driver; 97 } 98 99 const tcu::FunctionLibrary& getFunctionLibrary (void) const 100 { 101 return m_library; 102 } 103 104private: 105 const DynamicFunctionLibrary m_library; 106 const vk::PlatformDriver m_driver; 107}; 108 109VulkanPlatform::VulkanPlatform () 110{ 111} 112 113vk::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 121bool VulkanPlatform::hasDisplay (vk::wsi::Type wsiType) const 122{ 123 if (wsiType != vk::wsi::TYPE_MACOS) 124 return false; 125 126 return true; 127} 128vk::Library* VulkanPlatform::createLibrary (const char* libraryPath) const 129{ 130 return new VulkanLibrary(libraryPath); 131} 132 133void 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