| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/gl/gpu_timing.h" | 5 #include "ui/gl/gpu_timing.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
| 9 #include "ui/gl/gl_bindings.h" | 9 #include "ui/gl/gl_bindings.h" |
| 10 #include "ui/gl/gl_context.h" | 10 #include "ui/gl/gl_context.h" |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 } | 335 } |
| 336 return disjoint_counter_; | 336 return disjoint_counter_; |
| 337 } | 337 } |
| 338 | 338 |
| 339 int64_t GPUTimingImpl::CalculateTimerOffset() { | 339 int64_t GPUTimingImpl::CalculateTimerOffset() { |
| 340 if (!offset_valid_) { | 340 if (!offset_valid_) { |
| 341 if (timer_type_ == GPUTiming::kTimerTypeDisjoint || | 341 if (timer_type_ == GPUTiming::kTimerTypeDisjoint || |
| 342 timer_type_ == GPUTiming::kTimerTypeARB) { | 342 timer_type_ == GPUTiming::kTimerTypeARB) { |
| 343 GLint64 gl_now = 0; | 343 GLint64 gl_now = 0; |
| 344 glGetInteger64v(GL_TIMESTAMP, &gl_now); | 344 glGetInteger64v(GL_TIMESTAMP, &gl_now); |
| 345 int64_t micro_now = NanoToMicro(gl_now); | 345 const int64_t cpu_time = GetCurrentCPUTime(); |
| 346 offset_ = GetCurrentCPUTime() - micro_now; | 346 const int64_t micro_offset = cpu_time - NanoToMicro(gl_now); |
| 347 offset_valid_ = (timer_type_ == GPUTiming::kTimerTypeARB); | 347 |
| 348 // We cannot expect these instructions to run with the accuracy |
| 349 // within 1 microsecond, instead discard differences which are less |
| 350 // than a single millisecond. |
| 351 base::TimeDelta delta = |
| 352 base::TimeDelta::FromMicroseconds(micro_offset - offset_); |
| 353 |
| 354 if (delta.magnitude().InMilliseconds() >= 1) { |
| 355 offset_ = micro_offset; |
| 356 offset_valid_ = (timer_type_ == GPUTiming::kTimerTypeARB); |
| 357 } |
| 348 } else { | 358 } else { |
| 349 offset_ = 0; | 359 offset_ = 0; |
| 350 offset_valid_ = true; | 360 offset_valid_ = true; |
| 351 } | 361 } |
| 352 } | 362 } |
| 353 return offset_; | 363 return offset_; |
| 354 } | 364 } |
| 355 | 365 |
| 356 scoped_refptr<QueryResult> GPUTimingImpl::BeginElapsedTimeQuery() { | 366 scoped_refptr<QueryResult> GPUTimingImpl::BeginElapsedTimeQuery() { |
| 357 DCHECK(timer_type_ != GPUTiming::kTimerTypeInvalid); | 367 DCHECK(timer_type_ != GPUTiming::kTimerTypeInvalid); |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 | 635 |
| 626 void GPUTimingClient::ForceTimeElapsedQuery() { | 636 void GPUTimingClient::ForceTimeElapsedQuery() { |
| 627 DCHECK(gpu_timing_); | 637 DCHECK(gpu_timing_); |
| 628 gpu_timing_->ForceTimeElapsedQuery(); | 638 gpu_timing_->ForceTimeElapsedQuery(); |
| 629 } | 639 } |
| 630 | 640 |
| 631 GPUTimingClient::~GPUTimingClient() { | 641 GPUTimingClient::~GPUTimingClient() { |
| 632 } | 642 } |
| 633 | 643 |
| 634 } // namespace gfx | 644 } // namespace gfx |
| OLD | NEW |