Bike-X  0.8
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Util_LatencyTest2.h
Go to the documentation of this file.
1 /************************************************************************************
2 
3 PublicHeader: OVR.h
4 Filename : Util_LatencyTest2.h
5 Content : Wraps the lower level LatencyTester interface for DK2 and adds functionality.
6 Created : March 10, 2014
7 Authors : Volga Aksoy
8 
9 Copyright : Copyright 2014 Oculus VR, Inc. All Rights reserved.
10 
11 Licensed under the Oculus VR Rift SDK License Version 3.1 (the "License");
12 you may not use the Oculus VR Rift SDK except in compliance with the License,
13 which is provided at the time of installation or download, or which
14 otherwise accompanies this software in either electronic or hard copy form.
15 
16 You may obtain a copy of the License at
17 
18 http://www.oculusvr.com/licenses/LICENSE-3.1
19 
20 Unless required by applicable law or agreed to in writing, the Oculus VR SDK
21 distributed under the License is distributed on an "AS IS" BASIS,
22 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 See the License for the specific language governing permissions and
24 limitations under the License.
25 
26 *************************************************************************************/
27 
28 #ifndef OVR_Util_LatencyTest2_h
29 #define OVR_Util_LatencyTest2_h
30 
31 #include "../OVR_Device.h"
32 
33 #include "../Kernel/OVR_String.h"
34 #include "../Kernel/OVR_List.h"
35 #include "../Kernel/OVR_Lockless.h"
36 
37 namespace OVR { namespace Util {
38 
39 
40 enum {
45 };
46 
47 //-------------------------------------------------------------------------------------
48 
49 // Describes frame scanout time used for latency testing.
51 {
53  double TimeSeconds;
54 
55  // Utility functions to convert color to readBack indices and back.
56  // The purpose of ReadbackIndex is to allow direct comparison by value.
57 
58  static bool ColorToReadbackIndex(int *readbackIndex, unsigned char color)
59  {
60  int compareColor = color - LT2_ColorIncrement/2;
61  int index = color / LT2_ColorIncrement; // Use color without subtraction due to rounding.
62  int delta = compareColor - index * LT2_ColorIncrement;
63 
64  if ((delta < LT2_PixelTestThreshold) && (delta > -LT2_PixelTestThreshold))
65  {
66  *readbackIndex = index;
67  return true;
68  }
69  return false;
70  }
71 
72  static unsigned char ReadbackIndexToColor(int readbackIndex)
73  {
74  OVR_ASSERT(readbackIndex < LT2_IncrementCount);
75  return (unsigned char)(readbackIndex * LT2_ColorIncrement + LT2_ColorIncrement/2);
76  }
77 };
78 
79 // FrameTimeRecordSet is a container holding multiple consecutive frame timing records
80 // returned from the lock-less state. Used by FrameTimeManager.
81 
83 {
84  enum {
87  };
90 
92  {
93  NextWriteIndex = 0;
94  memset(this, 0, sizeof(FrameTimeRecordSet));
95  }
96 
97  void AddValue(int readValue, double timeSeconds)
98  {
100  Records[NextWriteIndex].TimeSeconds = timeSeconds;
101  NextWriteIndex ++;
103  NextWriteIndex = 0;
104  }
105  // Matching should be done starting from NextWrite index
106  // until wrap-around
107 
108  const FrameTimeRecord& operator [] (int i) const
109  {
110  return Records[(NextWriteIndex + i) & RecordMask];
111  }
112 
114  {
115  return Records[(NextWriteIndex - 1) & RecordMask];
116  }
117 
118  // Advances I to absolute color index
119  bool FindReadbackIndex(int* i, int readbackIndex) const
120  {
121  for (; *i < RecordCount; (*i)++)
122  {
123  if ((*this)[*i].ReadbackIndex == readbackIndex)
124  return true;
125  }
126  return false;
127  }
128 
129  bool IsAllZeroes() const
130  {
131  for (int i = 0; i < RecordCount; i++)
132  if (Records[i].ReadbackIndex != 0)
133  return false;
134  return true;
135  }
136 };
137 
138 
139 //-------------------------------------------------------------------------------------
140 // ***** LatencyTest2
141 //
142 // LatencyTest2 utility class wraps the low level SensorDevice and manages the scheduling
143 // of a latency test. A single test is composed of a series of individual latency measurements
144 // which are used to derive min, max, and an average latency value.
145 //
146 // Developers are required to call the following methods:
147 // SetDevice - Sets the SensorDevice to be used for the tests.
148 // ProcessInputs - This should be called at the same place in the code where the game engine
149 // reads the headset orientation from LibOVR (typically done by calling
150 // 'GetOrientation' on the SensorFusion object). Calling this at the right time
151 // enables us to measure the same latency that occurs for headset orientation
152 // changes.
153 // DisplayScreenColor - The latency tester works by sensing the color of the pixels directly
154 // beneath it. The color of these pixels can be set by drawing a small
155 // quad at the end of the rendering stage. The quad should be small
156 // such that it doesn't significantly impact the rendering of the scene,
157 // but large enough to be 'seen' by the sensor. See the SDK
158 // documentation for more information.
159 // GetResultsString - Call this to get a string containing the most recent results.
160 // If the string has already been gotten then NULL will be returned.
161 // The string pointer will remain valid until the next time this
162 // method is called.
163 //
164 
166 {
167 public:
168  LatencyTest2(SensorDevice* device = NULL);
169  ~LatencyTest2();
170 
171  // Set the Latency Tester device that we'll use to send commands to and receive
172  // notification messages from.
173  bool SetSensorDevice(SensorDevice* device);
174  bool SetDisplayDevice(LatencyTestDevice* device);
175 
176  // Returns true if this LatencyTestUtil has a Latency Tester device.
177  bool HasDisplayDevice() const { return LatencyTesterDev.GetPtr() != NULL; }
178  bool HasDevice() const { return Handler.IsHandlerInstalled(); }
179 
180  bool DisplayScreenColor(Color& colorToDisplay);
181  //const char* GetResultsString();
182 
183  // Begin test. Equivalent to pressing the button on the latency tester.
184  void BeginTest(double startTime = -1.0f);
185  bool IsMeasuringNow() const { return TestActive; }
186  double GetMeasuredLatency() const { return LatencyMeasuredInSeconds; }
187 
188 //
190 
191 private:
192  LatencyTest2* getThis() { return this; }
193 
195  {
199  };
200 
201  void handleMessage(const MessagePixelRead& msg);
202 
204  {
206  public:
207  PixelReadHandler(LatencyTest2* latencyTester) : pLatencyTestUtil(latencyTester) { }
209 
210  virtual void OnMessage(const Message& msg);
211  };
213 
216 
219  unsigned char RenderColorValue;
221  double StartTiming;
222  unsigned int RawStartTiming;
226  unsigned int NumTestsSuccessful;
227 
228  // MA:
229  // Frames are added here, then copied into lockess state
232 };
233 
234 
235 
236 }} // namespace OVR::Util
237 
238 #endif // OVR_Util_LatencyTest2_h
FrameTimeRecordSet GetLocklessState()
Ptr< SensorDevice > HmdDevice
#define NULL
uint32_t UInt32
Definition: OVR_Types.h:253
const FrameTimeRecord & GetMostRecentFrame()
double GetMeasuredLatency() const
virtual void OnMessage(const Message &msg)
Ptr< LatencyTestDevice > LatencyTesterDev
static unsigned char ReadbackIndexToColor(int readbackIndex)
PixelReadHandler(LatencyTest2 *latencyTester)
MessagePixelRead LastPixelReadMsg
void BeginTest(double startTime=-1.0f)
static bool ColorToReadbackIndex(int *readbackIndex, unsigned char color)
LocklessUpdater< FrameTimeRecordSet > LockessRecords
void AddValue(int readValue, double timeSeconds)
LatencyTest2(SensorDevice *device=NULL)
FrameTimeRecordSet RecentFrameSet
#define OVR_ASSERT(p)
FrameTimeRecord Records[RecordCount]
bool DisplayScreenColor(Color &colorToDisplay)
bool IsHandlerInstalled() const
__BEGIN_NAMESPACE_STD void void __END_NAMESPACE_STD void __BEGIN_NAMESPACE_STD void * memset(void *__s, int __c, size_t __n) __THROW __nonnull((1))
bool SetDisplayDevice(LatencyTestDevice *device)
void handleMessage(const MessagePixelRead &msg)
int char * index(const char *__s, int __c) __THROW __attribute_pure__ __nonnull((1))
const FrameTimeRecord & operator[](int i) const
bool SetSensorDevice(SensorDevice *device)
bool FindReadbackIndex(int *i, int readbackIndex) const