oculus1

diff 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
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/libovr/Src/Util/Util_LatencyTest.h	Sat Sep 14 16:14:59 2013 +0300
     1.3 @@ -0,0 +1,1 @@
     1.4 +/************************************************************************************
     1.5 
     1.6 PublicHeader:   OVR.h
     1.7 Filename    :   Util_LatencyTest.h
     1.8 Content     :   Wraps the lower level LatencyTesterDevice and adds functionality.
     1.9 Created     :   February 14, 2013
    1.10 Authors     :   Lee Cooper
    1.11 
    1.12 Copyright   :   Copyright 2013 Oculus VR, Inc. All Rights reserved.
    1.13 
    1.14 Use of this software is subject to the terms of the Oculus license
    1.15 agreement provided at the time of installation or download, or which
    1.16 otherwise accompanies this software in either electronic or hard copy form.
    1.17 
    1.18 *************************************************************************************/
    1.19 
    1.20 #ifndef OVR_Util_LatencyTest_h
    1.21 #define OVR_Util_LatencyTest_h
    1.22 
    1.23 #include "../OVR_Device.h"
    1.24 
    1.25 #include "../Kernel/OVR_String.h"
    1.26 #include "../Kernel/OVR_List.h"
    1.27 
    1.28 namespace OVR { namespace Util {
    1.29 
    1.30 
    1.31 //-------------------------------------------------------------------------------------
    1.32 // ***** LatencyTest
    1.33 //
    1.34 // LatencyTest utility class wraps the low level LatencyTestDevice and manages the scheduling
    1.35 // of a latency test. A single test is composed of a series of individual latency measurements
    1.36 // which are used to derive min, max, and an average latency value.
    1.37 //
    1.38 // Developers are required to call the following methods:
    1.39 //      SetDevice - Sets the LatencyTestDevice to be used for the tests.
    1.40 //      ProcessInputs - This should be called at the same place in the code where the game engine
    1.41 //                      reads the headset orientation from LibOVR (typically done by calling
    1.42 //                      'GetOrientation' on the SensorFusion object). Calling this at the right time
    1.43 //                      enables us to measure the same latency that occurs for headset orientation
    1.44 //                      changes.
    1.45 //      DisplayScreenColor -    The latency tester works by sensing the color of the pixels directly
    1.46 //                              beneath it. The color of these pixels can be set by drawing a small
    1.47 //                              quad at the end of the rendering stage. The quad should be small
    1.48 //                              such that it doesn't significantly impact the rendering of the scene,
    1.49 //                              but large enough to be 'seen' by the sensor. See the SDK
    1.50 //                              documentation for more information.
    1.51 //		GetResultsString -	Call this to get a string containing the most recent results.
    1.52 //							If the string has already been gotten then NULL will be returned.
    1.53 //							The string pointer will remain valid until the next time this 
    1.54 //							method is called.
    1.55 //
    1.56 
    1.57 class LatencyTest : public NewOverrideBase
    1.58 {
    1.59 public:
    1.60     LatencyTest(LatencyTestDevice* device = NULL);
    1.61     ~LatencyTest();
    1.62     
    1.63     // Set the Latency Tester device that we'll use to send commands to and receive
    1.64     // notification messages from.
    1.65     bool        SetDevice(LatencyTestDevice* device);
    1.66 
    1.67     // Returns true if this LatencyTestUtil has a Latency Tester device.
    1.68     bool        HasDevice() const
    1.69     { return Handler.IsHandlerInstalled(); }
    1.70 
    1.71     void        ProcessInputs();
    1.72     bool        DisplayScreenColor(Color& colorToDisplay);
    1.73 	const char*	GetResultsString();
    1.74 
    1.75     // Begin test. Equivalent to pressing the button on the latency tester.
    1.76     void BeginTest();
    1.77 
    1.78 private:
    1.79     LatencyTest* getThis()  { return this; }
    1.80 
    1.81     enum LatencyTestMessageType
    1.82     {
    1.83         LatencyTest_None,
    1.84         LatencyTest_Timer,
    1.85         LatencyTest_ProcessInputs,
    1.86     };
    1.87     
    1.88     UInt32 getRandomComponent(UInt32 range);
    1.89     void handleMessage(const Message& msg, LatencyTestMessageType latencyTestMessage = LatencyTest_None);
    1.90     void reset();
    1.91     void setTimer(UInt32 timeMilliS);
    1.92     void clearTimer();
    1.93 
    1.94     class LatencyTestHandler : public MessageHandler
    1.95     {
    1.96         LatencyTest*    pLatencyTestUtil;
    1.97     public:
    1.98         LatencyTestHandler(LatencyTest* latencyTester) : pLatencyTestUtil(latencyTester) { }
    1.99         ~LatencyTestHandler();
   1.100 
   1.101         virtual void OnMessage(const Message& msg);
   1.102     };
   1.103 
   1.104     bool areResultsComplete();
   1.105     void processResults();
   1.106     void updateForTimeouts();
   1.107 
   1.108     Ptr<LatencyTestDevice>      Device;
   1.109     LatencyTestHandler          Handler;
   1.110 
   1.111     enum TesterState
   1.112     {
   1.113         State_WaitingForButton,
   1.114         State_WaitingForSettlePreCalibrationColorBlack,
   1.115         State_WaitingForSettlePostCalibrationColorBlack,
   1.116         State_WaitingForSettlePreCalibrationColorWhite,
   1.117         State_WaitingForSettlePostCalibrationColorWhite,
   1.118         State_WaitingToTakeMeasurement,
   1.119         State_WaitingForTestStarted,
   1.120         State_WaitingForColorDetected,
   1.121         State_WaitingForSettlePostMeasurement
   1.122     };
   1.123     TesterState                 State;
   1.124 
   1.125     bool                        HaveOldTime;
   1.126     UInt32                      OldTime;
   1.127     UInt32                      ActiveTimerMilliS;
   1.128 
   1.129     Color                       RenderColor;
   1.130 
   1.131     struct MeasurementResult : public ListNode<MeasurementResult>, public NewOverrideBase
   1.132     {
   1.133         MeasurementResult()
   1.134          :  DeviceMeasuredElapsedMilliS(0),
   1.135             TimedOutWaitingForTestStarted(false),
   1.136             TimedOutWaitingForColorDetected(false),
   1.137             StartTestTicksMicroS(0),
   1.138             TestStartedTicksMicroS(0)
   1.139         {}
   1.140 
   1.141         Color                   TargetColor;
   1.142 
   1.143         UInt32                  DeviceMeasuredElapsedMilliS;
   1.144 
   1.145         bool                    TimedOutWaitingForTestStarted;
   1.146         bool                    TimedOutWaitingForColorDetected;
   1.147 
   1.148         UInt64                  StartTestTicksMicroS;
   1.149         UInt64                  TestStartedTicksMicroS;
   1.150     };
   1.151 
   1.152     List<MeasurementResult>     Results;
   1.153     void clearMeasurementResults();
   1.154 
   1.155     MeasurementResult*          getActiveResult();
   1.156 
   1.157     StringBuffer			    ResultsString;
   1.158 	String					    ReturnedResultString;
   1.159 };
   1.160 
   1.161 }} // namespace OVR::Util
   1.162 
   1.163 #endif // OVR_Util_LatencyTest_h
   1.164 \ No newline at end of file