nuclear@1: /************************************************************************************ nuclear@1: nuclear@1: Filename : OVR_OSX_DeviceManager.h nuclear@1: Content : OSX specific DeviceManager header. nuclear@1: Created : March 14, 2013 nuclear@1: Authors : Lee Cooper nuclear@1: nuclear@1: Copyright : Copyright 2013 Oculus VR, Inc. All Rights reserved. nuclear@1: nuclear@1: Use of this software is subject to the terms of the Oculus license nuclear@1: agreement provided at the time of installation or download, or which nuclear@1: otherwise accompanies this software in either electronic or hard copy form. nuclear@1: nuclear@1: *************************************************************************************/ nuclear@1: nuclear@1: #ifndef OVR_OSX_DeviceManager_h nuclear@1: #define OVR_OSX_DeviceManager_h nuclear@1: nuclear@1: #include "OVR_DeviceImpl.h" nuclear@1: nuclear@1: #include "Kernel/OVR_Timer.h" nuclear@1: nuclear@1: #include nuclear@1: #include nuclear@1: #include nuclear@1: nuclear@1: nuclear@1: namespace OVR { namespace OSX { nuclear@1: nuclear@1: class DeviceManagerThread; nuclear@1: nuclear@1: //------------------------------------------------------------------------------------- nuclear@1: // ***** OSX DeviceManager nuclear@1: nuclear@1: class DeviceManager : public DeviceManagerImpl nuclear@1: { nuclear@1: public: nuclear@1: DeviceManager(); nuclear@1: ~DeviceManager(); nuclear@1: nuclear@1: // Initialize/Shutdown manager thread. nuclear@1: virtual bool Initialize(DeviceBase* parent); nuclear@1: virtual void Shutdown(); nuclear@1: nuclear@1: virtual ThreadCommandQueue* GetThreadQueue(); nuclear@1: virtual ThreadId GetThreadId() const; nuclear@1: nuclear@1: virtual DeviceEnumerator<> EnumerateDevicesEx(const DeviceEnumerationArgs& args); nuclear@1: nuclear@1: virtual bool GetDeviceInfo(DeviceInfo* info) const; nuclear@1: nuclear@1: protected: nuclear@1: static void displayReconfigurationCallBack (CGDirectDisplayID display, nuclear@1: CGDisplayChangeSummaryFlags flags, nuclear@1: void *userInfo); nuclear@1: nuclear@1: public: // data nuclear@1: Ptr pThread; nuclear@1: }; nuclear@1: nuclear@1: //------------------------------------------------------------------------------------- nuclear@1: // ***** Device Manager Background Thread nuclear@1: nuclear@1: class DeviceManagerThread : public Thread, public ThreadCommandQueue nuclear@1: { nuclear@1: friend class DeviceManager; nuclear@1: enum { ThreadStackSize = 32 * 1024 }; nuclear@1: public: nuclear@1: DeviceManagerThread(); nuclear@1: ~DeviceManagerThread(); nuclear@1: nuclear@1: virtual int Run(); nuclear@1: nuclear@1: // ThreadCommandQueue notifications for CommandEvent handling. nuclear@1: virtual void OnPushNonEmpty_Locked() nuclear@1: { nuclear@1: CFRunLoopSourceSignal(CommandQueueSource); nuclear@1: CFRunLoopWakeUp(RunLoop); nuclear@1: } nuclear@1: nuclear@1: virtual void OnPopEmpty_Locked() {} nuclear@1: nuclear@1: nuclear@1: // Notifier used for different updates (EVENT or regular timing or messages). nuclear@1: class Notifier nuclear@1: { nuclear@1: public: nuclear@1: nuclear@1: // Called when timing ticks are updated. // Returns the largest number of microseconds nuclear@1: // this function can wait till next call. nuclear@1: virtual UInt64 OnTicks(UInt64 ticksMks) nuclear@1: { OVR_UNUSED1(ticksMks); return Timer::MksPerSecond * 1000; } nuclear@1: }; nuclear@1: nuclear@1: // Add notifier that will be called at regular intervals. nuclear@1: bool AddTicksNotifier(Notifier* notify); nuclear@1: bool RemoveTicksNotifier(Notifier* notify); nuclear@1: nuclear@1: CFRunLoopRef GetRunLoop() nuclear@1: { return RunLoop; } nuclear@1: nuclear@1: void Shutdown(); nuclear@1: private: nuclear@1: CFRunLoopRef RunLoop; nuclear@1: nuclear@1: CFRunLoopSourceRef CommandQueueSource; nuclear@1: nuclear@1: static void staticCommandQueueSourceCallback(void* pContext); nuclear@1: void commandQueueSourceCallback(); nuclear@1: nuclear@1: Event StartupEvent; nuclear@1: nuclear@1: // Ticks notifiers. Used for time-dependent events such as keep-alive. nuclear@1: Array TicksNotifiers; nuclear@1: }; nuclear@1: nuclear@1: }} // namespace OSX::OVR nuclear@1: nuclear@1: #endif // OVR_OSX_DeviceManager_h