From 501354c207cee1b36320783f5664134c47beaa06 Mon Sep 17 00:00:00 2001 From: stuartmorgan Date: Wed, 8 May 2019 23:20:32 -0400 Subject: [PATCH] Fix TimePoint on Windows (flutter/engine#8910) Addresses overflow issues with timer multiplication by using std::chrono instead of QueryPerformanceCounter. The Windows implementation of std::chrono uses QPC, so this should have no impact on performance or clock resolution. Fixes #32121 --- engine/src/flutter/fml/time/time_point.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/engine/src/flutter/fml/time/time_point.cc b/engine/src/flutter/fml/time/time_point.cc index f0a912e92f..695dca8927 100644 --- a/engine/src/flutter/fml/time/time_point.cc +++ b/engine/src/flutter/fml/time/time_point.cc @@ -12,7 +12,7 @@ #elif defined(OS_FUCHSIA) #include #elif defined(OS_WIN) -#include +#include #else #include #endif // defined(OS_MACOSX) || defined(OS_IOS) @@ -53,11 +53,11 @@ TimePoint TimePoint::Now() { #elif defined(OS_WIN) TimePoint TimePoint::Now() { - uint64_t freq = 0; - uint64_t count = 0; - QueryPerformanceFrequency((LARGE_INTEGER*)&freq); - QueryPerformanceCounter((LARGE_INTEGER*)&count); - return TimePoint((count * 1000000000) / freq); + // The base time is arbitrary; use the clock epoch for convenience. + const auto elapsed_time = std::chrono::steady_clock::now().time_since_epoch(); + return TimePoint( + std::chrono::duration_cast(elapsed_time) + .count()); } #else