ovr_sdk

view LibOVR/Src/Util/Util_LatencyTest2Reader.cpp @ 3:f12a8f74fe1f

added the Xcode project
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 21 Jan 2015 11:37:50 +0200
parents
children
line source
1 /************************************************************************************
3 Filename : Util_LatencyTest2Reader.cpp
4 Content : Shared functionality for the DK2 latency tester
5 Created : July 8, 2014
6 Authors : Volga Aksoy, Chris Taylor
8 Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved.
10 Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License");
11 you may not use the Oculus VR Rift SDK except in compliance with the License,
12 which is provided at the time of installation or download, or which
13 otherwise accompanies this software in either electronic or hard copy form.
15 You may obtain a copy of the License at
17 http://www.oculusvr.com/licenses/LICENSE-3.2
19 Unless required by applicable law or agreed to in writing, the Oculus VR SDK
20 distributed under the License is distributed on an "AS IS" BASIS,
21 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 See the License for the specific language governing permissions and
23 limitations under the License.
25 *************************************************************************************/
27 #include "Util_LatencyTest2Reader.h"
29 namespace OVR { namespace Util {
32 //// FrameTimeRecord
34 bool FrameTimeRecord::ColorToReadbackIndex(int *readbackIndex, unsigned char color)
35 {
36 int compareColor = color - LT2_ColorIncrement/2;
37 int index = color / LT2_ColorIncrement; // Use color without subtraction due to rounding.
38 int delta = compareColor - index * LT2_ColorIncrement;
40 if ((delta < LT2_PixelTestThreshold) && (delta > -LT2_PixelTestThreshold))
41 {
42 *readbackIndex = index;
43 return true;
44 }
45 return false;
46 }
48 unsigned char FrameTimeRecord::ReadbackIndexToColor(int readbackIndex)
49 {
50 OVR_ASSERT(readbackIndex < LT2_IncrementCount);
51 return (unsigned char)(readbackIndex * LT2_ColorIncrement + LT2_ColorIncrement/2);
52 }
55 //// FrameTimeRecordSet
57 FrameTimeRecordSet::FrameTimeRecordSet()
58 {
59 NextWriteIndex = 0;
60 memset(this, 0, sizeof(FrameTimeRecordSet));
61 }
63 void FrameTimeRecordSet::AddValue(int readValue, double timeSeconds)
64 {
65 Records[NextWriteIndex].ReadbackIndex = readValue;
66 Records[NextWriteIndex].TimeSeconds = timeSeconds;
67 NextWriteIndex++;
68 if (NextWriteIndex == RecordCount)
69 NextWriteIndex = 0;
70 }
71 // Matching should be done starting from NextWrite index
72 // until wrap-around
74 const FrameTimeRecord& FrameTimeRecordSet::operator [] (int i) const
75 {
76 return Records[(NextWriteIndex + i) & RecordMask];
77 }
79 const FrameTimeRecord& FrameTimeRecordSet::GetMostRecentFrame()
80 {
81 return Records[(NextWriteIndex - 1) & RecordMask];
82 }
84 // Advances I to absolute color index
85 bool FrameTimeRecordSet::FindReadbackIndex(int* i, int readbackIndex) const
86 {
87 for (; *i < RecordCount; (*i)++)
88 {
89 if ((*this)[*i].ReadbackIndex == readbackIndex)
90 return true;
91 }
92 return false;
93 }
95 bool FrameTimeRecordSet::IsAllZeroes() const
96 {
97 for (int i = 0; i < RecordCount; i++)
98 if (Records[i].ReadbackIndex != 0)
99 return false;
100 return true;
101 }
104 //// RecordStateReader
106 void RecordStateReader::GetRecordSet(FrameTimeRecordSet& recordset)
107 {
108 if(!Updater)
109 {
110 return;
111 }
113 recordset = Updater->SharedLatencyTestState.GetState();
114 return;
115 }
118 }} // namespace OVR::Util