Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(402)

Unified Diff: ui/gl/gpu_timing.cc

Issue 1647333002: Fix GPUTiming offset so it is stable within significant digits. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Increased fake CPU time in unittest to be greater than 1ms Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ui/gl/gpu_timing_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gl/gpu_timing.cc
diff --git a/ui/gl/gpu_timing.cc b/ui/gl/gpu_timing.cc
index 8989bd55b2a71c9851e03cfba59aca989a2d4e3a..45908c985188f56baaac43086cc62e9c01929248 100644
--- a/ui/gl/gpu_timing.cc
+++ b/ui/gl/gpu_timing.cc
@@ -342,9 +342,19 @@ int64_t GPUTimingImpl::CalculateTimerOffset() {
timer_type_ == GPUTiming::kTimerTypeARB) {
GLint64 gl_now = 0;
glGetInteger64v(GL_TIMESTAMP, &gl_now);
- int64_t micro_now = NanoToMicro(gl_now);
- offset_ = GetCurrentCPUTime() - micro_now;
- offset_valid_ = (timer_type_ == GPUTiming::kTimerTypeARB);
+ const int64_t cpu_time = GetCurrentCPUTime();
+ const int64_t micro_offset = cpu_time - NanoToMicro(gl_now);
+
+ // We cannot expect these instructions to run with the accuracy
+ // within 1 microsecond, instead discard differences which are less
+ // than a single millisecond.
+ base::TimeDelta delta =
+ base::TimeDelta::FromMicroseconds(micro_offset - offset_);
+
+ if (delta.magnitude().InMilliseconds() >= 1) {
+ offset_ = micro_offset;
+ offset_valid_ = (timer_type_ == GPUTiming::kTimerTypeARB);
+ }
} else {
offset_ = 0;
offset_valid_ = true;
« no previous file with comments | « no previous file | ui/gl/gpu_timing_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698