Chromium Code Reviews| Index: ui/gl/gpu_timing.cc |
| diff --git a/ui/gl/gpu_timing.cc b/ui/gl/gpu_timing.cc |
| index 8989bd55b2a71c9851e03cfba59aca989a2d4e3a..77e803838932346e7d7313a0402ce761c62bbed3 100644 |
| --- a/ui/gl/gpu_timing.cc |
| +++ b/ui/gl/gpu_timing.cc |
| @@ -342,9 +342,24 @@ int64_t GPUTimingImpl::CalculateTimerOffset() { |
| timer_type_ == GPUTiming::kTimerTypeARB) { |
| GLint64 gl_now = 0; |
| glGetInteger64v(GL_TIMESTAMP, &gl_now); |
|
Ken Russell (switch to Gerrit)
2016/01/29 22:54:31
I've recently learned that this query returns 0 on
David Yen
2016/01/30 02:14:11
So this would only apply to the core profile (comp
|
| - 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, round down to nearest milliseconds instead and |
| + // only update if the difference is larger than 1 millisecond. |
| + const int64_t rounded_offset = |
| + (micro_offset / base::Time::kMicrosecondsPerMillisecond) * |
| + base::Time::kMicrosecondsPerMillisecond; |
|
Ken Russell (switch to Gerrit)
2016/01/29 22:54:31
Is there any way to use base::Time to do this roun
David Yen
2016/01/30 02:14:11
Done. This is much better now thank you.
|
| + |
| + const int64_t diff = rounded_offset - offset_; |
| + const int64_t abs_diff = (diff < 0) ? -diff : diff; |
| + |
| + if (abs_diff > 1) { |
| + offset_ = rounded_offset; |
| + offset_valid_ = (timer_type_ == GPUTiming::kTimerTypeARB); |
| + } |
| } else { |
| offset_ = 0; |
| offset_valid_ = true; |