oculus1

diff libovr/Src/Util/Util_LatencyTest.h @ 3:b069a5c27388

added a couple more stuff, fixed all the LibOVR line endings
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 15 Sep 2013 04:10:05 +0300
parents e2f9e4603129
children
line diff
     1.1 --- a/libovr/Src/Util/Util_LatencyTest.h	Sat Sep 14 17:51:03 2013 +0300
     1.2 +++ b/libovr/Src/Util/Util_LatencyTest.h	Sun Sep 15 04:10:05 2013 +0300
     1.3 @@ -1,1 +1,160 @@
     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
   1.165 +/************************************************************************************
   1.166 +
   1.167 +PublicHeader:   OVR.h
   1.168 +Filename    :   Util_LatencyTest.h
   1.169 +Content     :   Wraps the lower level LatencyTesterDevice and adds functionality.
   1.170 +Created     :   February 14, 2013
   1.171 +Authors     :   Lee Cooper
   1.172 +
   1.173 +Copyright   :   Copyright 2013 Oculus VR, Inc. All Rights reserved.
   1.174 +
   1.175 +Use of this software is subject to the terms of the Oculus license
   1.176 +agreement provided at the time of installation or download, or which
   1.177 +otherwise accompanies this software in either electronic or hard copy form.
   1.178 +
   1.179 +*************************************************************************************/
   1.180 +
   1.181 +#ifndef OVR_Util_LatencyTest_h
   1.182 +#define OVR_Util_LatencyTest_h
   1.183 +
   1.184 +#include "../OVR_Device.h"
   1.185 +
   1.186 +#include "../Kernel/OVR_String.h"
   1.187 +#include "../Kernel/OVR_List.h"
   1.188 +
   1.189 +namespace OVR { namespace Util {
   1.190 +
   1.191 +
   1.192 +//-------------------------------------------------------------------------------------
   1.193 +// ***** LatencyTest
   1.194 +//
   1.195 +// LatencyTest utility class wraps the low level LatencyTestDevice and manages the scheduling
   1.196 +// of a latency test. A single test is composed of a series of individual latency measurements
   1.197 +// which are used to derive min, max, and an average latency value.
   1.198 +//
   1.199 +// Developers are required to call the following methods:
   1.200 +//      SetDevice - Sets the LatencyTestDevice to be used for the tests.
   1.201 +//      ProcessInputs - This should be called at the same place in the code where the game engine
   1.202 +//                      reads the headset orientation from LibOVR (typically done by calling
   1.203 +//                      'GetOrientation' on the SensorFusion object). Calling this at the right time
   1.204 +//                      enables us to measure the same latency that occurs for headset orientation
   1.205 +//                      changes.
   1.206 +//      DisplayScreenColor -    The latency tester works by sensing the color of the pixels directly
   1.207 +//                              beneath it. The color of these pixels can be set by drawing a small
   1.208 +//                              quad at the end of the rendering stage. The quad should be small
   1.209 +//                              such that it doesn't significantly impact the rendering of the scene,
   1.210 +//                              but large enough to be 'seen' by the sensor. See the SDK
   1.211 +//                              documentation for more information.
   1.212 +//		GetResultsString -	Call this to get a string containing the most recent results.
   1.213 +//							If the string has already been gotten then NULL will be returned.
   1.214 +//							The string pointer will remain valid until the next time this 
   1.215 +//							method is called.
   1.216 +//
   1.217 +
   1.218 +class LatencyTest : public NewOverrideBase
   1.219 +{
   1.220 +public:
   1.221 +    LatencyTest(LatencyTestDevice* device = NULL);
   1.222 +    ~LatencyTest();
   1.223 +    
   1.224 +    // Set the Latency Tester device that we'll use to send commands to and receive
   1.225 +    // notification messages from.
   1.226 +    bool        SetDevice(LatencyTestDevice* device);
   1.227 +
   1.228 +    // Returns true if this LatencyTestUtil has a Latency Tester device.
   1.229 +    bool        HasDevice() const
   1.230 +    { return Handler.IsHandlerInstalled(); }
   1.231 +
   1.232 +    void        ProcessInputs();
   1.233 +    bool        DisplayScreenColor(Color& colorToDisplay);
   1.234 +	const char*	GetResultsString();
   1.235 +
   1.236 +    // Begin test. Equivalent to pressing the button on the latency tester.
   1.237 +    void BeginTest();
   1.238 +
   1.239 +private:
   1.240 +    LatencyTest* getThis()  { return this; }
   1.241 +
   1.242 +    enum LatencyTestMessageType
   1.243 +    {
   1.244 +        LatencyTest_None,
   1.245 +        LatencyTest_Timer,
   1.246 +        LatencyTest_ProcessInputs,
   1.247 +    };
   1.248 +    
   1.249 +    UInt32 getRandomComponent(UInt32 range);
   1.250 +    void handleMessage(const Message& msg, LatencyTestMessageType latencyTestMessage = LatencyTest_None);
   1.251 +    void reset();
   1.252 +    void setTimer(UInt32 timeMilliS);
   1.253 +    void clearTimer();
   1.254 +
   1.255 +    class LatencyTestHandler : public MessageHandler
   1.256 +    {
   1.257 +        LatencyTest*    pLatencyTestUtil;
   1.258 +    public:
   1.259 +        LatencyTestHandler(LatencyTest* latencyTester) : pLatencyTestUtil(latencyTester) { }
   1.260 +        ~LatencyTestHandler();
   1.261 +
   1.262 +        virtual void OnMessage(const Message& msg);
   1.263 +    };
   1.264 +
   1.265 +    bool areResultsComplete();
   1.266 +    void processResults();
   1.267 +    void updateForTimeouts();
   1.268 +
   1.269 +    Ptr<LatencyTestDevice>      Device;
   1.270 +    LatencyTestHandler          Handler;
   1.271 +
   1.272 +    enum TesterState
   1.273 +    {
   1.274 +        State_WaitingForButton,
   1.275 +        State_WaitingForSettlePreCalibrationColorBlack,
   1.276 +        State_WaitingForSettlePostCalibrationColorBlack,
   1.277 +        State_WaitingForSettlePreCalibrationColorWhite,
   1.278 +        State_WaitingForSettlePostCalibrationColorWhite,
   1.279 +        State_WaitingToTakeMeasurement,
   1.280 +        State_WaitingForTestStarted,
   1.281 +        State_WaitingForColorDetected,
   1.282 +        State_WaitingForSettlePostMeasurement
   1.283 +    };
   1.284 +    TesterState                 State;
   1.285 +
   1.286 +    bool                        HaveOldTime;
   1.287 +    UInt32                      OldTime;
   1.288 +    UInt32                      ActiveTimerMilliS;
   1.289 +
   1.290 +    Color                       RenderColor;
   1.291 +
   1.292 +    struct MeasurementResult : public ListNode<MeasurementResult>, public NewOverrideBase
   1.293 +    {
   1.294 +        MeasurementResult()
   1.295 +         :  DeviceMeasuredElapsedMilliS(0),
   1.296 +            TimedOutWaitingForTestStarted(false),
   1.297 +            TimedOutWaitingForColorDetected(false),
   1.298 +            StartTestTicksMicroS(0),
   1.299 +            TestStartedTicksMicroS(0)
   1.300 +        {}
   1.301 +
   1.302 +        Color                   TargetColor;
   1.303 +
   1.304 +        UInt32                  DeviceMeasuredElapsedMilliS;
   1.305 +
   1.306 +        bool                    TimedOutWaitingForTestStarted;
   1.307 +        bool                    TimedOutWaitingForColorDetected;
   1.308 +
   1.309 +        UInt64                  StartTestTicksMicroS;
   1.310 +        UInt64                  TestStartedTicksMicroS;
   1.311 +    };
   1.312 +
   1.313 +    List<MeasurementResult>     Results;
   1.314 +    void clearMeasurementResults();
   1.315 +
   1.316 +    MeasurementResult*          getActiveResult();
   1.317 +
   1.318 +    StringBuffer			    ResultsString;
   1.319 +	String					    ReturnedResultString;
   1.320 +};
   1.321 +
   1.322 +}} // namespace OVR::Util
   1.323 +
   1.324 +#endif // OVR_Util_LatencyTest_h