oculus1

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