Chromium Code Reviews| 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" |
| 11 #include "ui/gl/gl_version_info.h" | 11 #include "ui/gl/gl_version_info.h" |
| 12 | 12 |
| 13 namespace gfx { | 13 namespace gfx { |
| 14 | 14 |
| 15 class TimeElapsedTimerQuery; | 15 class TimeElapsedTimerQuery; |
| 16 class TimerQuery; | 16 class TimerQuery; |
| 17 | 17 |
| 18 int64_t NanoToMicro(uint64_t nano_seconds) { | 18 int64_t NanoToMicro(uint64_t nano_seconds) { |
| 19 const uint64_t up = nano_seconds + base::Time::kNanosecondsPerMicrosecond / 2; | 19 const uint64_t up = nano_seconds + base::Time::kNanosecondsPerMicrosecond / 2; |
| 20 return static_cast<int64_t>(up / base::Time::kNanosecondsPerMicrosecond); | 20 return static_cast<int64_t>(up / base::Time::kNanosecondsPerMicrosecond); |
| 21 } | 21 } |
| 22 | 22 |
| 23 class GPUTimingImpl : public GPUTiming { | 23 class GPUTimingImpl : public GPUTiming { |
| 24 public: | 24 public: |
| 25 GPUTimingImpl(GLContextReal* context); | 25 GPUTimingImpl(GLContextReal* context); |
| 26 ~GPUTimingImpl() override; | 26 ~GPUTimingImpl() override; |
| 27 | 27 |
| 28 void ForceTimeElapsedQuery() { force_time_elapsed_query_ = true; } | 28 void ForceTimeElapsedQuery() { force_time_elapsed_query_ = true; } |
| 29 bool IsForceTimeElapsedQuery() { return force_time_elapsed_query_; } | 29 bool IsForceTimeElapsedQuery() { return force_time_elapsed_query_; } |
| 30 bool ShouldForceTimeElapsedQuery(); | |
| 30 | 31 |
| 31 GPUTiming::TimerType GetTimerType() const { return timer_type_; } | 32 GPUTiming::TimerType GetTimerType() const { return timer_type_; } |
| 32 | 33 |
| 33 uint32_t GetDisjointCount(); | 34 uint32_t GetDisjointCount(); |
| 34 int64_t CalculateTimerOffset(); | 35 int64_t CalculateTimerOffset(); |
| 35 | 36 |
| 36 scoped_refptr<QueryResult> BeginElapsedTimeQuery(); | 37 scoped_refptr<QueryResult> BeginElapsedTimeQuery(); |
| 37 void EndElapsedTimeQuery(scoped_refptr<QueryResult> result); | 38 void EndElapsedTimeQuery(scoped_refptr<QueryResult> result); |
| 38 | 39 |
| 39 scoped_refptr<QueryResult> DoTimeStampQuery(); | 40 scoped_refptr<QueryResult> DoTimeStampQuery(); |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 310 DCHECK(context); | 311 DCHECK(context); |
| 311 const GLVersionInfo* version_info = context->GetVersionInfo(); | 312 const GLVersionInfo* version_info = context->GetVersionInfo(); |
| 312 DCHECK(version_info); | 313 DCHECK(version_info); |
| 313 if (version_info->is_es3 && // glGetInteger64v is supported under ES3. | 314 if (version_info->is_es3 && // glGetInteger64v is supported under ES3. |
| 314 context->HasExtension("GL_EXT_disjoint_timer_query")) { | 315 context->HasExtension("GL_EXT_disjoint_timer_query")) { |
| 315 timer_type_ = GPUTiming::kTimerTypeDisjoint; | 316 timer_type_ = GPUTiming::kTimerTypeDisjoint; |
| 316 } else if (context->HasExtension("GL_ARB_timer_query")) { | 317 } else if (context->HasExtension("GL_ARB_timer_query")) { |
| 317 timer_type_ = GPUTiming::kTimerTypeARB; | 318 timer_type_ = GPUTiming::kTimerTypeARB; |
| 318 } else if (context->HasExtension("GL_EXT_timer_query")) { | 319 } else if (context->HasExtension("GL_EXT_timer_query")) { |
| 319 timer_type_ = GPUTiming::kTimerTypeEXT; | 320 timer_type_ = GPUTiming::kTimerTypeEXT; |
| 320 force_time_elapsed_query_ = true; | |
| 321 } | 321 } |
| 322 force_time_elapsed_query_ = ShouldForceTimeElapsedQuery(); | |
| 322 } | 323 } |
| 323 | 324 |
| 324 GPUTimingImpl::~GPUTimingImpl() { | 325 GPUTimingImpl::~GPUTimingImpl() { |
| 325 } | 326 } |
| 326 | 327 |
| 328 bool GPUTimingImpl::ShouldForceTimeElapsedQuery() { | |
| 329 if (timer_type_ == GPUTiming::kTimerTypeInvalid) { | |
| 330 return false; | |
| 331 } else if (timer_type_ == GPUTiming::kTimerTypeEXT) { | |
| 332 // GL_EXT_timer_query does not support timestamps | |
| 333 return true; | |
| 334 } else { | |
| 335 // Certain drivers such as Mac drivers and ANGLE's D3D11 backend do not | |
|
Geoff Lang
2016/02/11 16:37:02
nit: assert that type is GPUTiming::kTimerTypeDisj
| |
| 336 // support timestamps even though queries for them are valid. This is | |
| 337 // indicated by returning 0 when for GL_TIMESTAMP in GL_QUERY_COUNTER_BITS | |
| 338 GLint timestamp_bits; | |
| 339 glGetQueryiv(GL_TIMESTAMP, GL_QUERY_COUNTER_BITS, ×tamp_bits); | |
| 340 if (timestamp_bits == 0) { | |
|
Geoff Lang
2016/02/11 16:37:02
nit: return timestamp_bits == 0;
| |
| 341 return true; | |
| 342 } else { | |
| 343 return false; | |
| 344 } | |
| 345 } | |
| 346 } | |
| 347 | |
| 327 uint32_t GPUTimingImpl::GetDisjointCount() { | 348 uint32_t GPUTimingImpl::GetDisjointCount() { |
| 328 if (timer_type_ == GPUTiming::kTimerTypeDisjoint) { | 349 if (timer_type_ == GPUTiming::kTimerTypeDisjoint) { |
| 329 GLint disjoint_value = 0; | 350 GLint disjoint_value = 0; |
| 330 glGetIntegerv(GL_GPU_DISJOINT_EXT, &disjoint_value); | 351 glGetIntegerv(GL_GPU_DISJOINT_EXT, &disjoint_value); |
| 331 if (disjoint_value) { | 352 if (disjoint_value) { |
| 332 offset_valid_ = false; | 353 offset_valid_ = false; |
| 333 disjoint_counter_++; | 354 disjoint_counter_++; |
| 334 } | 355 } |
| 335 } | 356 } |
| 336 return disjoint_counter_; | 357 return disjoint_counter_; |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 635 | 656 |
| 636 void GPUTimingClient::ForceTimeElapsedQuery() { | 657 void GPUTimingClient::ForceTimeElapsedQuery() { |
| 637 DCHECK(gpu_timing_); | 658 DCHECK(gpu_timing_); |
| 638 gpu_timing_->ForceTimeElapsedQuery(); | 659 gpu_timing_->ForceTimeElapsedQuery(); |
| 639 } | 660 } |
| 640 | 661 |
| 641 GPUTimingClient::~GPUTimingClient() { | 662 GPUTimingClient::~GPUTimingClient() { |
| 642 } | 663 } |
| 643 | 664 |
| 644 } // namespace gfx | 665 } // namespace gfx |
| OLD | NEW |