1 /*------------------------------------------------------------------------- 2 * drawElements Quality Program Tester Core 3 * ---------------------------------------- 4 * 5 * Copyright 2014 The Android Open Source Project 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 X11 Platform. 22 *//*--------------------------------------------------------------------*/ 23 24 #include "tcuX11Platform.hpp" 25 26 #include "deUniquePtr.hpp" 27 #include "gluPlatform.hpp" 28 #include "vkPlatform.hpp" 29 #include "tcuX11.hpp" 30 #include "tcuFunctionLibrary.hpp" 31 #include "deMemory.h" 32 33 #if defined (DEQP_SUPPORT_GLX) 34 # include "tcuX11GlxPlatform.hpp" 35 #endif 36 #if defined (DEQP_SUPPORT_EGL) 37 # include "tcuX11EglPlatform.hpp" 38 #endif 39 40 #include <sys/utsname.h> 41 42 namespace tcu 43 { 44 namespace x11 45 { 46 47 class X11GLPlatform : public glu::Platform 48 { 49 public: 50 void registerFactory (de::MovePtr<glu::ContextFactory> factory) 51 { 52 m_contextFactoryRegistry.registerFactory(factory.release()); 53 } 54 }; 55 56 class VulkanLibrary : public vk::Library 57 { 58 public: 59 VulkanLibrary (void) 60 : m_library ("libvulkan.so.1") 61 , m_driver (m_library) 62 { 63 } 64 65 const vk::PlatformInterface& getPlatformInterface (void) const 66 { 67 return m_driver; 68 } 69 70 private: 71 const tcu::DynamicFunctionLibrary m_library; 72 const vk::PlatformDriver m_driver; 73 }; 74 75 class X11VulkanPlatform : public vk::Platform 76 { 77 public: 78 vk::Library* createLibrary (void) const 79 { 80 return new VulkanLibrary(); 81 } 82 83 void describePlatform (std::ostream& dst) const 84 { 85 utsname sysInfo; 86 87 deMemset(&sysInfo, 0, sizeof(sysInfo)); 88 89 if (uname(&sysInfo) != 0) 90 throw std::runtime_error("uname() failed"); 91 92 dst << "OS: " << sysInfo.sysname << " " << sysInfo.release << " " << sysInfo.version << "\n"; 93 dst << "CPU: " << sysInfo.machine << "\n"; 94 } 95 96 void getMemoryLimits (vk::PlatformMemoryLimits& limits) const 97 { 98 limits.totalSystemMemory = 256*1024*1024; 99 limits.totalDeviceLocalMemory = 128*1024*1024; 100 limits.deviceMemoryAllocationGranularity = 64*1024; 101 limits.devicePageSize = 4096; 102 limits.devicePageTableEntrySize = 8; 103 limits.devicePageTableHierarchyLevels = 3; 104 } 105 }; 106 107 class X11Platform : public tcu::Platform 108 { 109 public: 110 X11Platform (void); 111 bool processEvents (void) { return !m_eventState.getQuitFlag(); } 112 const glu::Platform& getGLPlatform (void) const { return m_glPlatform; } 113 114 #if defined (DEQP_SUPPORT_EGL) 115 const eglu::Platform& getEGLPlatform (void) const { return m_eglPlatform; } 116 #endif // DEQP_SUPPORT_EGL 117 118 const vk::Platform& getVulkanPlatform (void) const { return m_vkPlatform; } 119 120 private: 121 EventState m_eventState; 122 #if defined (DEQP_SUPPORT_EGL) 123 x11::egl::Platform m_eglPlatform; 124 #endif // DEQP_SPPORT_EGL 125 X11GLPlatform m_glPlatform; 126 X11VulkanPlatform m_vkPlatform; 127 }; 128 129 X11Platform::X11Platform (void) 130 #if defined (DEQP_SUPPORT_EGL) 131 : m_eglPlatform (m_eventState) 132 #endif // DEQP_SUPPORT_EGL 133 { 134 #if defined (DEQP_SUPPORT_GLX) 135 m_glPlatform.registerFactory(glx::createContextFactory(m_eventState)); 136 #endif // DEQP_SUPPORT_GLX 137 #if defined (DEQP_SUPPORT_EGL) 138 m_glPlatform.registerFactory(m_eglPlatform.createContextFactory()); 139 #endif // DEQP_SUPPORT_EGL 140 } 141 142 } // x11 143 } // tcu 144 145 tcu::Platform* createPlatform (void) 146 { 147 return new tcu::x11::X11Platform(); 148 } 149