TickDelta TickDelta::FromMilliseconds( int nTimeDelta) // Tick delta, in 1/1000^1 sec { AssertMsg(nTimeDelta != _I32_MAX, "Use Infinite() to create an infinite TickDelta"); return FromMicroseconds(((int64) nTimeDelta) * ((int64) 1000)); }
TimeStamp VSyncWin::GetAdjustedVsyncTimeStamp(LARGE_INTEGER& aFrequency, QPC_TIME& aQpcVblankTime) { char buf[1024]; TimeStamp vsync = Now(); LARGE_INTEGER qpcNow; QueryPerformanceCounter(&qpcNow); const int microseconds = 1000000; int64_t adjust = qpcNow.QuadPart - aQpcVblankTime; int64_t usAdjust = (adjust * microseconds) / aFrequency.QuadPart; sprintf_s(buf, "\n((((( usadjust %lld and", usAdjust); OutputDebugStringA(buf); sprintf_s(buf, "\n(((((Vsync %llu", aQpcVblankTime); OutputDebugStringA(buf); vsync -= FromMicroseconds((double)usAdjust); //if (IsWin10OrLater()) { // On Windows 10 and on, DWMGetCompositionTimingInfo, mostly // reports the upcoming vsync time, which is in the future. // It can also sometimes report a vblank time in the past. // Since large parts of Gecko assume TimeStamps can't be in future, // use the previous vsync. // Windows 10 and Intel HD vsync timestamps are messy and // all over the place once in a while. Most of the time, // it reports the upcoming vsync. Sometimes, that upcoming // vsync is in the past. Sometimes that upcoming vsync is before // the previously seen vsync. Sometimes, the previous vsync // is still in the future. In these error cases, // we try to normalize to Now(). TimeStamp upcomingVsync = vsync; if (upcomingVsync < mPrevVsync) { // Windows can report a vsync that's before // the previous one. So update it to sometime in the future. upcomingVsync = Now() + FromMilliseconds(1); } vsync = mPrevVsync; sprintf_s(buf, "\n)))) vsync %llu---", vsync); OutputDebugStringA(buf); mPrevVsync = upcomingVsync; } // On Windows 7 and 8, DwmFlush wakes up AFTER qpcVBlankTime // from DWMGetCompositionTimingInfo. We can return the adjusted vsync. // Once in a while, the reported vsync timestamp can be in the future. // Normalize the reported timestamp to now. if (vsync >= Now()) { vsync = Now(); } return vsync; }