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/time/time.h" | 7 #include "base/time/time.h" |
8 #include "ui/gl/gl_bindings.h" | 8 #include "ui/gl/gl_bindings.h" |
9 #include "ui/gl/gl_context.h" | 9 #include "ui/gl/gl_context.h" |
10 #include "ui/gl/gl_version_info.h" | 10 #include "ui/gl/gl_version_info.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 } | 23 } |
24 } | 24 } |
25 | 25 |
26 GPUTiming::~GPUTiming() { | 26 GPUTiming::~GPUTiming() { |
27 } | 27 } |
28 | 28 |
29 scoped_refptr<GPUTimingClient> GPUTiming::CreateGPUTimingClient() { | 29 scoped_refptr<GPUTimingClient> GPUTiming::CreateGPUTimingClient() { |
30 return new GPUTimingClient(this); | 30 return new GPUTimingClient(this); |
31 } | 31 } |
32 | 32 |
| 33 uint32_t GPUTiming::GetDisjointCount() { |
| 34 if (timer_type_ == kTimerTypeDisjoint) { |
| 35 GLint disjoint_value = 0; |
| 36 glGetIntegerv(GL_GPU_DISJOINT_EXT, &disjoint_value); |
| 37 if (disjoint_value) { |
| 38 disjoint_counter_++; |
| 39 } |
| 40 } |
| 41 return disjoint_counter_; |
| 42 } |
| 43 |
33 GPUTimer::~GPUTimer() { | 44 GPUTimer::~GPUTimer() { |
34 glDeleteQueriesARB(2, queries_); | 45 glDeleteQueriesARB(2, queries_); |
35 } | 46 } |
36 | 47 |
37 void GPUTimer::Start() { | 48 void GPUTimer::Start() { |
38 // GL_TIMESTAMP and GL_TIMESTAMP_EXT both have the same value. | 49 // GL_TIMESTAMP and GL_TIMESTAMP_EXT both have the same value. |
39 glQueryCounter(queries_[0], GL_TIMESTAMP); | 50 glQueryCounter(queries_[0], GL_TIMESTAMP); |
40 } | 51 } |
41 | 52 |
42 void GPUTimer::End() { | 53 void GPUTimer::End() { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 : gpu_timing_client_(gpu_timing_client) { | 91 : gpu_timing_client_(gpu_timing_client) { |
81 DCHECK(gpu_timing_client_); | 92 DCHECK(gpu_timing_client_); |
82 memset(queries_, 0, sizeof(queries_)); | 93 memset(queries_, 0, sizeof(queries_)); |
83 glGenQueriesARB(2, queries_); | 94 glGenQueriesARB(2, queries_); |
84 } | 95 } |
85 | 96 |
86 GPUTimingClient::GPUTimingClient(GPUTiming* gpu_timing) | 97 GPUTimingClient::GPUTimingClient(GPUTiming* gpu_timing) |
87 : gpu_timing_(gpu_timing) { | 98 : gpu_timing_(gpu_timing) { |
88 if (gpu_timing) { | 99 if (gpu_timing) { |
89 timer_type_ = gpu_timing->GetTimerType(); | 100 timer_type_ = gpu_timing->GetTimerType(); |
| 101 disjoint_counter_ = gpu_timing_->GetDisjointCount(); |
90 } | 102 } |
91 } | 103 } |
92 | 104 |
93 scoped_ptr<GPUTimer> GPUTimingClient::CreateGPUTimer() { | 105 scoped_ptr<GPUTimer> GPUTimingClient::CreateGPUTimer() { |
94 return make_scoped_ptr(new GPUTimer(this)); | 106 return make_scoped_ptr(new GPUTimer(this)); |
95 } | 107 } |
96 | 108 |
97 bool GPUTimingClient::IsAvailable() { | 109 bool GPUTimingClient::IsAvailable() { |
98 return timer_type_ != GPUTiming::kTimerTypeInvalid; | 110 return timer_type_ != GPUTiming::kTimerTypeInvalid; |
99 } | 111 } |
100 | 112 |
101 const char* GPUTimingClient::GetTimerTypeName() const { | 113 const char* GPUTimingClient::GetTimerTypeName() const { |
102 switch (timer_type_) { | 114 switch (timer_type_) { |
103 case GPUTiming::kTimerTypeDisjoint: | 115 case GPUTiming::kTimerTypeDisjoint: |
104 return "GL_EXT_disjoint_timer_query"; | 116 return "GL_EXT_disjoint_timer_query"; |
105 case GPUTiming::kTimerTypeARB: | 117 case GPUTiming::kTimerTypeARB: |
106 return "GL_ARB_timer_query"; | 118 return "GL_ARB_timer_query"; |
107 default: | 119 default: |
108 return "Unknown"; | 120 return "Unknown"; |
109 } | 121 } |
110 } | 122 } |
111 | 123 |
112 bool GPUTimingClient::CheckAndResetTimerErrors() { | 124 bool GPUTimingClient::CheckAndResetTimerErrors() { |
113 if (timer_type_ == GPUTiming::kTimerTypeDisjoint) { | 125 if (timer_type_ == GPUTiming::kTimerTypeDisjoint) { |
114 GLint disjoint_value = 0; | 126 DCHECK(gpu_timing_ != nullptr); |
115 glGetIntegerv(GL_GPU_DISJOINT_EXT, &disjoint_value); | 127 const uint32_t total_disjoint_count = gpu_timing_->GetDisjointCount(); |
116 return disjoint_value != 0; | 128 const bool disjoint_triggered = total_disjoint_count != disjoint_counter_; |
117 } else { | 129 disjoint_counter_ = total_disjoint_count; |
118 return false; | 130 return disjoint_triggered; |
119 } | 131 } |
| 132 return false; |
120 } | 133 } |
121 | 134 |
122 int64 GPUTimingClient::CalculateTimerOffset() { | 135 int64 GPUTimingClient::CalculateTimerOffset() { |
123 if (!offset_valid_) { | 136 if (!offset_valid_) { |
124 GLint64 gl_now = 0; | 137 GLint64 gl_now = 0; |
125 glGetInteger64v(GL_TIMESTAMP, &gl_now); | 138 glGetInteger64v(GL_TIMESTAMP, &gl_now); |
126 int64 now = | 139 int64 now = |
127 cpu_time_for_testing_.is_null() | 140 cpu_time_for_testing_.is_null() |
128 ? base::TimeTicks::NowFromSystemTraceTime().ToInternalValue() | 141 ? base::TimeTicks::NowFromSystemTraceTime().ToInternalValue() |
129 : cpu_time_for_testing_.Run(); | 142 : cpu_time_for_testing_.Run(); |
130 offset_ = now - gl_now / base::Time::kNanosecondsPerMicrosecond; | 143 offset_ = now - gl_now / base::Time::kNanosecondsPerMicrosecond; |
131 offset_valid_ = timer_type_ == GPUTiming::kTimerTypeARB; | 144 offset_valid_ = timer_type_ == GPUTiming::kTimerTypeARB; |
132 } | 145 } |
133 return offset_; | 146 return offset_; |
134 } | 147 } |
135 | 148 |
136 void GPUTimingClient::InvalidateTimerOffset() { | 149 void GPUTimingClient::InvalidateTimerOffset() { |
137 offset_valid_ = false; | 150 offset_valid_ = false; |
138 } | 151 } |
139 | 152 |
140 void GPUTimingClient::SetCpuTimeForTesting( | 153 void GPUTimingClient::SetCpuTimeForTesting( |
141 const base::Callback<int64(void)>& cpu_time) { | 154 const base::Callback<int64(void)>& cpu_time) { |
142 cpu_time_for_testing_ = cpu_time; | 155 cpu_time_for_testing_ = cpu_time; |
143 } | 156 } |
144 | 157 |
145 GPUTimingClient::~GPUTimingClient() { | 158 GPUTimingClient::~GPUTimingClient() { |
146 } | 159 } |
147 | 160 |
148 } // namespace gfx | 161 } // namespace gfx |
OLD | NEW |