oculus1
annotate libovr/Src/osx/OVR_OSX_DeviceManager.h @ 29:9a973ef0e2a3
fixed the performance issue under MacOSX by replacing glutSolidTeapot (which
uses glEvalMesh) with my own teapot generator.
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 27 Oct 2013 06:31:18 +0200 |
parents | |
children |
rev | line source |
---|---|
nuclear@1 | 1 /************************************************************************************ |
nuclear@1 | 2 |
nuclear@1 | 3 Filename : OVR_OSX_DeviceManager.h |
nuclear@1 | 4 Content : OSX specific DeviceManager header. |
nuclear@1 | 5 Created : March 14, 2013 |
nuclear@1 | 6 Authors : Lee Cooper |
nuclear@1 | 7 |
nuclear@1 | 8 Copyright : Copyright 2013 Oculus VR, Inc. All Rights reserved. |
nuclear@1 | 9 |
nuclear@1 | 10 Use of this software is subject to the terms of the Oculus license |
nuclear@1 | 11 agreement provided at the time of installation or download, or which |
nuclear@1 | 12 otherwise accompanies this software in either electronic or hard copy form. |
nuclear@1 | 13 |
nuclear@1 | 14 *************************************************************************************/ |
nuclear@1 | 15 |
nuclear@1 | 16 #ifndef OVR_OSX_DeviceManager_h |
nuclear@1 | 17 #define OVR_OSX_DeviceManager_h |
nuclear@1 | 18 |
nuclear@1 | 19 #include "OVR_DeviceImpl.h" |
nuclear@1 | 20 |
nuclear@1 | 21 #include "Kernel/OVR_Timer.h" |
nuclear@1 | 22 |
nuclear@1 | 23 #include <IOKit/hid/IOHIDManager.h> |
nuclear@1 | 24 #include <CoreGraphics/CGDirectDisplay.h> |
nuclear@1 | 25 #include <CoreGraphics/CGDisplayConfiguration.h> |
nuclear@1 | 26 |
nuclear@1 | 27 |
nuclear@1 | 28 namespace OVR { namespace OSX { |
nuclear@1 | 29 |
nuclear@1 | 30 class DeviceManagerThread; |
nuclear@1 | 31 |
nuclear@1 | 32 //------------------------------------------------------------------------------------- |
nuclear@1 | 33 // ***** OSX DeviceManager |
nuclear@1 | 34 |
nuclear@1 | 35 class DeviceManager : public DeviceManagerImpl |
nuclear@1 | 36 { |
nuclear@1 | 37 public: |
nuclear@1 | 38 DeviceManager(); |
nuclear@1 | 39 ~DeviceManager(); |
nuclear@1 | 40 |
nuclear@1 | 41 // Initialize/Shutdown manager thread. |
nuclear@1 | 42 virtual bool Initialize(DeviceBase* parent); |
nuclear@1 | 43 virtual void Shutdown(); |
nuclear@1 | 44 |
nuclear@1 | 45 virtual ThreadCommandQueue* GetThreadQueue(); |
nuclear@1 | 46 virtual ThreadId GetThreadId() const; |
nuclear@1 | 47 |
nuclear@1 | 48 virtual DeviceEnumerator<> EnumerateDevicesEx(const DeviceEnumerationArgs& args); |
nuclear@1 | 49 |
nuclear@1 | 50 virtual bool GetDeviceInfo(DeviceInfo* info) const; |
nuclear@1 | 51 |
nuclear@1 | 52 protected: |
nuclear@1 | 53 static void displayReconfigurationCallBack (CGDirectDisplayID display, |
nuclear@1 | 54 CGDisplayChangeSummaryFlags flags, |
nuclear@1 | 55 void *userInfo); |
nuclear@1 | 56 |
nuclear@1 | 57 public: // data |
nuclear@1 | 58 Ptr<DeviceManagerThread> pThread; |
nuclear@1 | 59 }; |
nuclear@1 | 60 |
nuclear@1 | 61 //------------------------------------------------------------------------------------- |
nuclear@1 | 62 // ***** Device Manager Background Thread |
nuclear@1 | 63 |
nuclear@1 | 64 class DeviceManagerThread : public Thread, public ThreadCommandQueue |
nuclear@1 | 65 { |
nuclear@1 | 66 friend class DeviceManager; |
nuclear@1 | 67 enum { ThreadStackSize = 32 * 1024 }; |
nuclear@1 | 68 public: |
nuclear@1 | 69 DeviceManagerThread(); |
nuclear@1 | 70 ~DeviceManagerThread(); |
nuclear@1 | 71 |
nuclear@1 | 72 virtual int Run(); |
nuclear@1 | 73 |
nuclear@1 | 74 // ThreadCommandQueue notifications for CommandEvent handling. |
nuclear@1 | 75 virtual void OnPushNonEmpty_Locked() |
nuclear@1 | 76 { |
nuclear@1 | 77 CFRunLoopSourceSignal(CommandQueueSource); |
nuclear@1 | 78 CFRunLoopWakeUp(RunLoop); |
nuclear@1 | 79 } |
nuclear@1 | 80 |
nuclear@1 | 81 virtual void OnPopEmpty_Locked() {} |
nuclear@1 | 82 |
nuclear@1 | 83 |
nuclear@1 | 84 // Notifier used for different updates (EVENT or regular timing or messages). |
nuclear@1 | 85 class Notifier |
nuclear@1 | 86 { |
nuclear@1 | 87 public: |
nuclear@1 | 88 |
nuclear@1 | 89 // Called when timing ticks are updated. // Returns the largest number of microseconds |
nuclear@1 | 90 // this function can wait till next call. |
nuclear@1 | 91 virtual UInt64 OnTicks(UInt64 ticksMks) |
nuclear@1 | 92 { OVR_UNUSED1(ticksMks); return Timer::MksPerSecond * 1000; } |
nuclear@1 | 93 }; |
nuclear@1 | 94 |
nuclear@1 | 95 // Add notifier that will be called at regular intervals. |
nuclear@1 | 96 bool AddTicksNotifier(Notifier* notify); |
nuclear@1 | 97 bool RemoveTicksNotifier(Notifier* notify); |
nuclear@1 | 98 |
nuclear@1 | 99 CFRunLoopRef GetRunLoop() |
nuclear@1 | 100 { return RunLoop; } |
nuclear@1 | 101 |
nuclear@1 | 102 void Shutdown(); |
nuclear@1 | 103 private: |
nuclear@1 | 104 CFRunLoopRef RunLoop; |
nuclear@1 | 105 |
nuclear@1 | 106 CFRunLoopSourceRef CommandQueueSource; |
nuclear@1 | 107 |
nuclear@1 | 108 static void staticCommandQueueSourceCallback(void* pContext); |
nuclear@1 | 109 void commandQueueSourceCallback(); |
nuclear@1 | 110 |
nuclear@1 | 111 Event StartupEvent; |
nuclear@1 | 112 |
nuclear@1 | 113 // Ticks notifiers. Used for time-dependent events such as keep-alive. |
nuclear@1 | 114 Array<Notifier*> TicksNotifiers; |
nuclear@1 | 115 }; |
nuclear@1 | 116 |
nuclear@1 | 117 }} // namespace OSX::OVR |
nuclear@1 | 118 |
nuclear@1 | 119 #endif // OVR_OSX_DeviceManager_h |