nuclear@0: /************************************************************************************ nuclear@0: nuclear@0: Filename : Util_LatencyTest2Reader.cpp nuclear@0: Content : Shared functionality for the DK2 latency tester nuclear@0: Created : July 8, 2014 nuclear@0: Authors : Volga Aksoy, Chris Taylor nuclear@0: nuclear@0: Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved. nuclear@0: nuclear@0: Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); nuclear@0: you may not use the Oculus VR Rift SDK except in compliance with the License, nuclear@0: which is provided at the time of installation or download, or which nuclear@0: otherwise accompanies this software in either electronic or hard copy form. nuclear@0: nuclear@0: You may obtain a copy of the License at nuclear@0: nuclear@0: http://www.oculusvr.com/licenses/LICENSE-3.2 nuclear@0: nuclear@0: Unless required by applicable law or agreed to in writing, the Oculus VR SDK nuclear@0: distributed under the License is distributed on an "AS IS" BASIS, nuclear@0: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. nuclear@0: See the License for the specific language governing permissions and nuclear@0: limitations under the License. nuclear@0: nuclear@0: *************************************************************************************/ nuclear@0: nuclear@0: #include "Util_LatencyTest2Reader.h" nuclear@0: nuclear@0: namespace OVR { namespace Util { nuclear@0: nuclear@0: nuclear@0: //// FrameTimeRecord nuclear@0: nuclear@0: bool FrameTimeRecord::ColorToReadbackIndex(int *readbackIndex, unsigned char color) nuclear@0: { nuclear@0: int compareColor = color - LT2_ColorIncrement/2; nuclear@0: int index = color / LT2_ColorIncrement; // Use color without subtraction due to rounding. nuclear@0: int delta = compareColor - index * LT2_ColorIncrement; nuclear@0: nuclear@0: if ((delta < LT2_PixelTestThreshold) && (delta > -LT2_PixelTestThreshold)) nuclear@0: { nuclear@0: *readbackIndex = index; nuclear@0: return true; nuclear@0: } nuclear@0: return false; nuclear@0: } nuclear@0: nuclear@0: unsigned char FrameTimeRecord::ReadbackIndexToColor(int readbackIndex) nuclear@0: { nuclear@0: OVR_ASSERT(readbackIndex < LT2_IncrementCount); nuclear@0: return (unsigned char)(readbackIndex * LT2_ColorIncrement + LT2_ColorIncrement/2); nuclear@0: } nuclear@0: nuclear@0: nuclear@0: //// FrameTimeRecordSet nuclear@0: nuclear@0: FrameTimeRecordSet::FrameTimeRecordSet() nuclear@0: { nuclear@0: NextWriteIndex = 0; nuclear@0: memset(this, 0, sizeof(FrameTimeRecordSet)); nuclear@0: } nuclear@0: nuclear@0: void FrameTimeRecordSet::AddValue(int readValue, double timeSeconds) nuclear@0: { nuclear@0: Records[NextWriteIndex].ReadbackIndex = readValue; nuclear@0: Records[NextWriteIndex].TimeSeconds = timeSeconds; nuclear@0: NextWriteIndex++; nuclear@0: if (NextWriteIndex == RecordCount) nuclear@0: NextWriteIndex = 0; nuclear@0: } nuclear@0: // Matching should be done starting from NextWrite index nuclear@0: // until wrap-around nuclear@0: nuclear@0: const FrameTimeRecord& FrameTimeRecordSet::operator [] (int i) const nuclear@0: { nuclear@0: return Records[(NextWriteIndex + i) & RecordMask]; nuclear@0: } nuclear@0: nuclear@0: const FrameTimeRecord& FrameTimeRecordSet::GetMostRecentFrame() nuclear@0: { nuclear@0: return Records[(NextWriteIndex - 1) & RecordMask]; nuclear@0: } nuclear@0: nuclear@0: // Advances I to absolute color index nuclear@0: bool FrameTimeRecordSet::FindReadbackIndex(int* i, int readbackIndex) const nuclear@0: { nuclear@0: for (; *i < RecordCount; (*i)++) nuclear@0: { nuclear@0: if ((*this)[*i].ReadbackIndex == readbackIndex) nuclear@0: return true; nuclear@0: } nuclear@0: return false; nuclear@0: } nuclear@0: nuclear@0: bool FrameTimeRecordSet::IsAllZeroes() const nuclear@0: { nuclear@0: for (int i = 0; i < RecordCount; i++) nuclear@0: if (Records[i].ReadbackIndex != 0) nuclear@0: return false; nuclear@0: return true; nuclear@0: } nuclear@0: nuclear@0: nuclear@0: //// RecordStateReader nuclear@0: nuclear@0: void RecordStateReader::GetRecordSet(FrameTimeRecordSet& recordset) nuclear@0: { nuclear@0: if(!Updater) nuclear@0: { nuclear@0: return; nuclear@0: } nuclear@0: nuclear@0: recordset = Updater->SharedLatencyTestState.GetState(); nuclear@0: return; nuclear@0: } nuclear@0: nuclear@0: nuclear@0: }} // namespace OVR::Util