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