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 | |
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 DCHECK(timer_type_ == GPUTiming::kTimerTypeARB || | |
339 timer_type_ == GPUTiming::kTimerTypeDisjoint); | |
340 GLint timestamp_bits; | |
David Yen
2016/02/11 17:53:20
Could we just make these 3 lines a static function
| |
341 glGetQueryiv(GL_TIMESTAMP, GL_QUERY_COUNTER_BITS, ×tamp_bits); | |
342 return (timestamp_bits == 0); | |
343 } | |
344 } | |
345 | |
327 uint32_t GPUTimingImpl::GetDisjointCount() { | 346 uint32_t GPUTimingImpl::GetDisjointCount() { |
328 if (timer_type_ == GPUTiming::kTimerTypeDisjoint) { | 347 if (timer_type_ == GPUTiming::kTimerTypeDisjoint) { |
329 GLint disjoint_value = 0; | 348 GLint disjoint_value = 0; |
330 glGetIntegerv(GL_GPU_DISJOINT_EXT, &disjoint_value); | 349 glGetIntegerv(GL_GPU_DISJOINT_EXT, &disjoint_value); |
331 if (disjoint_value) { | 350 if (disjoint_value) { |
332 offset_valid_ = false; | 351 offset_valid_ = false; |
333 disjoint_counter_++; | 352 disjoint_counter_++; |
334 } | 353 } |
335 } | 354 } |
336 return disjoint_counter_; | 355 return disjoint_counter_; |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
635 | 654 |
636 void GPUTimingClient::ForceTimeElapsedQuery() { | 655 void GPUTimingClient::ForceTimeElapsedQuery() { |
637 DCHECK(gpu_timing_); | 656 DCHECK(gpu_timing_); |
638 gpu_timing_->ForceTimeElapsedQuery(); | 657 gpu_timing_->ForceTimeElapsedQuery(); |
639 } | 658 } |
640 | 659 |
641 GPUTimingClient::~GPUTimingClient() { | 660 GPUTimingClient::~GPUTimingClient() { |
642 } | 661 } |
643 | 662 |
644 } // namespace gfx | 663 } // namespace gfx |
OLD | NEW |