ovr_sdk
diff LibOVR/Src/Kernel/OVR_System.cpp @ 0:1b39a1b46319
initial 0.4.4
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 14 Jan 2015 06:51:16 +0200 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/LibOVR/Src/Kernel/OVR_System.cpp Wed Jan 14 06:51:16 2015 +0200 1.3 @@ -0,0 +1,149 @@ 1.4 +/************************************************************************************ 1.5 + 1.6 +Filename : OVR_System.cpp 1.7 +Content : General kernel initialization/cleanup, including that 1.8 + of the memory allocator. 1.9 +Created : September 19, 2012 1.10 +Notes : 1.11 + 1.12 +Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved. 1.13 + 1.14 +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); 1.15 +you may not use the Oculus VR Rift SDK except in compliance with the License, 1.16 +which is provided at the time of installation or download, or which 1.17 +otherwise accompanies this software in either electronic or hard copy form. 1.18 + 1.19 +You may obtain a copy of the License at 1.20 + 1.21 +http://www.oculusvr.com/licenses/LICENSE-3.2 1.22 + 1.23 +Unless required by applicable law or agreed to in writing, the Oculus VR SDK 1.24 +distributed under the License is distributed on an "AS IS" BASIS, 1.25 +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1.26 +See the License for the specific language governing permissions and 1.27 +limitations under the License. 1.28 + 1.29 +************************************************************************************/ 1.30 + 1.31 +#include "OVR_System.h" 1.32 +#include "OVR_Threads.h" 1.33 +#include "OVR_Timer.h" 1.34 +#include "../Displays/OVR_Display.h" 1.35 +#ifdef OVR_OS_WIN32 1.36 +#include "../Displays/OVR_Win32_ShimFunctions.h" 1.37 +#endif 1.38 + 1.39 +namespace OVR { 1.40 + 1.41 +#ifdef OVR_OS_WIN32 1.42 +extern bool anyRiftsInExtendedMode(); 1.43 +#endif 1.44 + 1.45 +// Stack of destroy listeners (push/pop semantics) 1.46 +static SystemSingletonInternal *SystemShutdownListenerStack = 0; 1.47 +static Lock stackLock; 1.48 +static bool DisplayShimInitialized = false; 1.49 + 1.50 +void SystemSingletonInternal::PushDestroyCallbacks() 1.51 +{ 1.52 + Lock::Locker locker(&stackLock); 1.53 + 1.54 + // Push listener onto the stack 1.55 + NextSingleton = SystemShutdownListenerStack; 1.56 + SystemShutdownListenerStack = this; 1.57 +} 1.58 + 1.59 +void System::DirectDisplayInitialize() 1.60 +{ 1.61 +#ifdef OVR_OS_WIN32 1.62 + // Set up display code for Windows 1.63 + Win32::DisplayShim::GetInstance(); 1.64 + 1.65 + // This code will look for the first display. If it's a display 1.66 + // that's extending the destkop, the code will assume we're in 1.67 + // compatibility mode. Compatibility mode prevents shim loading 1.68 + // and renders only to extended Rifts. 1.69 + // If we find a display and it's application exclusive, 1.70 + // we load the shim so we can render to it. 1.71 + // If no display is available, we revert to whatever the 1.72 + // driver tells us we're in 1.73 + 1.74 + bool anyExtendedRifts = anyRiftsInExtendedMode() || Display::InCompatibilityMode( false ); 1.75 + 1.76 + DisplayShimInitialized = Win32::DisplayShim::GetInstance().Initialize(anyExtendedRifts); 1.77 +#endif 1.78 +} 1.79 + 1.80 +bool System::DirectDisplayEnabled() 1.81 +{ 1.82 + return DisplayShimInitialized; 1.83 +} 1.84 + 1.85 +// Initializes System core, installing allocator. 1.86 +void System::Init(Log* log, Allocator *palloc) 1.87 +{ 1.88 + if (!Allocator::GetInstance()) 1.89 + { 1.90 + Log::SetGlobalLog(log); 1.91 + Timer::initializeTimerSystem(); 1.92 + Allocator::setInstance(palloc); 1.93 + Display::Initialize(); 1.94 + DirectDisplayInitialize(); 1.95 + } 1.96 + else 1.97 + { 1.98 + OVR_DEBUG_LOG(("System::Init failed - duplicate call.")); 1.99 + } 1.100 +} 1.101 + 1.102 +void System::Destroy() 1.103 +{ 1.104 + if (Allocator::GetInstance()) 1.105 + { 1.106 +#ifdef OVR_OS_WIN32 1.107 + Win32::DisplayShim::GetInstance().Shutdown(); 1.108 +#endif 1.109 + 1.110 + // Invoke all of the post-finish callbacks (normal case) 1.111 + for (SystemSingletonInternal *listener = SystemShutdownListenerStack; listener; listener = listener->NextSingleton) 1.112 + { 1.113 + listener->OnThreadDestroy(); 1.114 + } 1.115 + 1.116 +#ifdef OVR_ENABLE_THREADS 1.117 + // Wait for all threads to finish; this must be done so that memory 1.118 + // allocator and all destructors finalize correctly. 1.119 + Thread::FinishAllThreads(); 1.120 +#endif 1.121 + 1.122 + // Invoke all of the post-finish callbacks (normal case) 1.123 + for (SystemSingletonInternal *next, *listener = SystemShutdownListenerStack; listener; listener = next) 1.124 + { 1.125 + next = listener->NextSingleton; 1.126 + 1.127 + listener->OnSystemDestroy(); 1.128 + } 1.129 + 1.130 + SystemShutdownListenerStack = 0; 1.131 + 1.132 + // Shutdown heap and destroy SysAlloc singleton, if any. 1.133 + Allocator::GetInstance()->onSystemShutdown(); 1.134 + Allocator::setInstance(0); 1.135 + 1.136 + Timer::shutdownTimerSystem(); 1.137 + Log::SetGlobalLog(Log::GetDefaultLog()); 1.138 + } 1.139 + else 1.140 + { 1.141 + OVR_DEBUG_LOG(("System::Destroy failed - System not initialized.")); 1.142 + } 1.143 +} 1.144 + 1.145 +// Returns 'true' if system was properly initialized. 1.146 +bool System::IsInitialized() 1.147 +{ 1.148 + return Allocator::GetInstance() != 0; 1.149 +} 1.150 + 1.151 + 1.152 +} // namespace OVR