oculus1

annotate libovr/Src/Util/Util_LatencyTest.h @ 1:e2f9e4603129

added LibOVR and started a simple vr wrapper.
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 14 Sep 2013 16:14:59 +0300
parents
children b069a5c27388
rev   line source
nuclear@1 1 /************************************************************************************
nuclear@1 2
nuclear@1 3 PublicHeader: OVR.h
nuclear@1 4 Filename : Util_LatencyTest.h
nuclear@1 5 Content : Wraps the lower level LatencyTesterDevice and adds functionality.
nuclear@1 6 Created : February 14, 2013
nuclear@1 7 Authors : Lee Cooper
nuclear@1 8
nuclear@1 9 Copyright : Copyright 2013 Oculus VR, Inc. All Rights reserved.
nuclear@1 10
nuclear@1 11 Use of this software is subject to the terms of the Oculus license
nuclear@1 12 agreement provided at the time of installation or download, or which
nuclear@1 13 otherwise accompanies this software in either electronic or hard copy form.
nuclear@1 14
nuclear@1 15 *************************************************************************************/
nuclear@1 16
nuclear@1 17 #ifndef OVR_Util_LatencyTest_h
nuclear@1 18 #define OVR_Util_LatencyTest_h
nuclear@1 19
nuclear@1 20 #include "../OVR_Device.h"
nuclear@1 21
nuclear@1 22 #include "../Kernel/OVR_String.h"
nuclear@1 23 #include "../Kernel/OVR_List.h"
nuclear@1 24
nuclear@1 25 namespace OVR { namespace Util {
nuclear@1 26
nuclear@1 27
nuclear@1 28 //-------------------------------------------------------------------------------------
nuclear@1 29 // ***** LatencyTest
nuclear@1 30 //
nuclear@1 31 // LatencyTest utility class wraps the low level LatencyTestDevice and manages the scheduling
nuclear@1 32 // of a latency test. A single test is composed of a series of individual latency measurements
nuclear@1 33 // which are used to derive min, max, and an average latency value.
nuclear@1 34 //
nuclear@1 35 // Developers are required to call the following methods:
nuclear@1 36 // SetDevice - Sets the LatencyTestDevice to be used for the tests.
nuclear@1 37 // ProcessInputs - This should be called at the same place in the code where the game engine
nuclear@1 38 // reads the headset orientation from LibOVR (typically done by calling
nuclear@1 39 // 'GetOrientation' on the SensorFusion object). Calling this at the right time
nuclear@1 40 // enables us to measure the same latency that occurs for headset orientation
nuclear@1 41 // changes.
nuclear@1 42 // DisplayScreenColor - The latency tester works by sensing the color of the pixels directly
nuclear@1 43 // beneath it. The color of these pixels can be set by drawing a small
nuclear@1 44 // quad at the end of the rendering stage. The quad should be small
nuclear@1 45 // such that it doesn't significantly impact the rendering of the scene,
nuclear@1 46 // but large enough to be 'seen' by the sensor. See the SDK
nuclear@1 47 // documentation for more information.
nuclear@1 48 // GetResultsString - Call this to get a string containing the most recent results.
nuclear@1 49 // If the string has already been gotten then NULL will be returned.
nuclear@1 50 // The string pointer will remain valid until the next time this
nuclear@1 51 // method is called.
nuclear@1 52 //
nuclear@1 53
nuclear@1 54 class LatencyTest : public NewOverrideBase
nuclear@1 55 {
nuclear@1 56 public:
nuclear@1 57 LatencyTest(LatencyTestDevice* device = NULL);
nuclear@1 58 ~LatencyTest();
nuclear@1 59
nuclear@1 60 // Set the Latency Tester device that we'll use to send commands to and receive
nuclear@1 61 // notification messages from.
nuclear@1 62 bool SetDevice(LatencyTestDevice* device);
nuclear@1 63
nuclear@1 64 // Returns true if this LatencyTestUtil has a Latency Tester device.
nuclear@1 65 bool HasDevice() const
nuclear@1 66 { return Handler.IsHandlerInstalled(); }
nuclear@1 67
nuclear@1 68 void ProcessInputs();
nuclear@1 69 bool DisplayScreenColor(Color& colorToDisplay);
nuclear@1 70 const char* GetResultsString();
nuclear@1 71
nuclear@1 72 // Begin test. Equivalent to pressing the button on the latency tester.
nuclear@1 73 void BeginTest();
nuclear@1 74
nuclear@1 75 private:
nuclear@1 76 LatencyTest* getThis() { return this; }
nuclear@1 77
nuclear@1 78 enum LatencyTestMessageType
nuclear@1 79 {
nuclear@1 80 LatencyTest_None,
nuclear@1 81 LatencyTest_Timer,
nuclear@1 82 LatencyTest_ProcessInputs,
nuclear@1 83 };
nuclear@1 84
nuclear@1 85 UInt32 getRandomComponent(UInt32 range);
nuclear@1 86 void handleMessage(const Message& msg, LatencyTestMessageType latencyTestMessage = LatencyTest_None);
nuclear@1 87 void reset();
nuclear@1 88 void setTimer(UInt32 timeMilliS);
nuclear@1 89 void clearTimer();
nuclear@1 90
nuclear@1 91 class LatencyTestHandler : public MessageHandler
nuclear@1 92 {
nuclear@1 93 LatencyTest* pLatencyTestUtil;
nuclear@1 94 public:
nuclear@1 95 LatencyTestHandler(LatencyTest* latencyTester) : pLatencyTestUtil(latencyTester) { }
nuclear@1 96 ~LatencyTestHandler();
nuclear@1 97
nuclear@1 98 virtual void OnMessage(const Message& msg);
nuclear@1 99 };
nuclear@1 100
nuclear@1 101 bool areResultsComplete();
nuclear@1 102 void processResults();
nuclear@1 103 void updateForTimeouts();
nuclear@1 104
nuclear@1 105 Ptr<LatencyTestDevice> Device;
nuclear@1 106 LatencyTestHandler Handler;
nuclear@1 107
nuclear@1 108 enum TesterState
nuclear@1 109 {
nuclear@1 110 State_WaitingForButton,
nuclear@1 111 State_WaitingForSettlePreCalibrationColorBlack,
nuclear@1 112 State_WaitingForSettlePostCalibrationColorBlack,
nuclear@1 113 State_WaitingForSettlePreCalibrationColorWhite,
nuclear@1 114 State_WaitingForSettlePostCalibrationColorWhite,
nuclear@1 115 State_WaitingToTakeMeasurement,
nuclear@1 116 State_WaitingForTestStarted,
nuclear@1 117 State_WaitingForColorDetected,
nuclear@1 118 State_WaitingForSettlePostMeasurement
nuclear@1 119 };
nuclear@1 120 TesterState State;
nuclear@1 121
nuclear@1 122 bool HaveOldTime;
nuclear@1 123 UInt32 OldTime;
nuclear@1 124 UInt32 ActiveTimerMilliS;
nuclear@1 125
nuclear@1 126 Color RenderColor;
nuclear@1 127
nuclear@1 128 struct MeasurementResult : public ListNode<MeasurementResult>, public NewOverrideBase
nuclear@1 129 {
nuclear@1 130 MeasurementResult()
nuclear@1 131 : DeviceMeasuredElapsedMilliS(0),
nuclear@1 132 TimedOutWaitingForTestStarted(false),
nuclear@1 133 TimedOutWaitingForColorDetected(false),
nuclear@1 134 StartTestTicksMicroS(0),
nuclear@1 135 TestStartedTicksMicroS(0)
nuclear@1 136 {}
nuclear@1 137
nuclear@1 138 Color TargetColor;
nuclear@1 139
nuclear@1 140 UInt32 DeviceMeasuredElapsedMilliS;
nuclear@1 141
nuclear@1 142 bool TimedOutWaitingForTestStarted;
nuclear@1 143 bool TimedOutWaitingForColorDetected;
nuclear@1 144
nuclear@1 145 UInt64 StartTestTicksMicroS;
nuclear@1 146 UInt64 TestStartedTicksMicroS;
nuclear@1 147 };
nuclear@1 148
nuclear@1 149 List<MeasurementResult> Results;
nuclear@1 150 void clearMeasurementResults();
nuclear@1 151
nuclear@1 152 MeasurementResult* getActiveResult();
nuclear@1 153
nuclear@1 154 StringBuffer ResultsString;
nuclear@1 155 String ReturnedResultString;
nuclear@1 156 };
nuclear@1 157
nuclear@1 158 }} // namespace OVR::Util
nuclear@1 159
nuclear@1 160 #endif // OVR_Util_LatencyTest_h