OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "gpu/command_buffer/service/gpu_tracer.h" | 5 #include "gpu/command_buffer/service/gpu_tracer.h" |
6 | 6 |
7 #include <deque> | 7 #include <deque> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 private: | 62 private: |
63 virtual ~NoopTrace() {} | 63 virtual ~NoopTrace() {} |
64 | 64 |
65 DISALLOW_COPY_AND_ASSIGN(NoopTrace); | 65 DISALLOW_COPY_AND_ASSIGN(NoopTrace); |
66 }; | 66 }; |
67 | 67 |
68 class GPUTracerImpl | 68 class GPUTracerImpl |
69 : public GPUTracer, | 69 : public GPUTracer, |
70 public base::SupportsWeakPtr<GPUTracerImpl> { | 70 public base::SupportsWeakPtr<GPUTracerImpl> { |
71 public: | 71 public: |
72 GPUTracerImpl() | 72 explicit GPUTracerImpl(gles2::GLES2Decoder* decoder) |
73 : gpu_category_enabled_( | 73 : GPUTracer(decoder), |
74 TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED("gpu")), | 74 gpu_category_enabled_( |
75 process_posted_(false) { | 75 TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED("gpu")), |
76 } | 76 process_posted_(false) {} |
77 virtual ~GPUTracerImpl() {} | 77 virtual ~GPUTracerImpl() {} |
78 | 78 |
79 // Implementation of gpu::gles2::GPUTracer | 79 // Implementation of gpu::gles2::GPUTracer |
80 virtual bool Begin(const std::string& name) OVERRIDE; | 80 virtual bool Begin(const std::string& name) OVERRIDE; |
81 virtual bool End() OVERRIDE; | 81 virtual bool End() OVERRIDE; |
82 virtual const std::string& CurrentName() const OVERRIDE; | 82 virtual const std::string& CurrentName() const OVERRIDE; |
83 | 83 |
84 // Process any completed traces. | 84 // Process any completed traces. |
85 virtual void Process(); | 85 virtual void Process(); |
86 | 86 |
87 protected: | 87 protected: |
88 // Create a new trace. | 88 // Create a new trace. |
89 virtual scoped_refptr<Trace> CreateTrace(const std::string& name); | 89 virtual scoped_refptr<Trace> CreateTrace(const std::string& name); |
90 | 90 |
91 const unsigned char* gpu_category_enabled_; | 91 const unsigned char* gpu_category_enabled_; |
92 | 92 |
93 private: | 93 private: |
94 void IssueProcessTask(); | 94 void IssueProcessTask(); |
95 | 95 |
96 scoped_refptr<Trace> current_trace_; | 96 scoped_refptr<Trace> current_trace_; |
97 std::deque<scoped_refptr<Trace> > traces_; | 97 std::deque<scoped_refptr<Trace> > traces_; |
98 | 98 |
99 bool process_posted_; | 99 bool process_posted_; |
100 | 100 |
101 DISALLOW_COPY_AND_ASSIGN(GPUTracerImpl); | 101 DISALLOW_COPY_AND_ASSIGN(GPUTracerImpl); |
102 }; | 102 }; |
103 | 103 |
104 class GPUTracerARBTimerQuery : public GPUTracerImpl { | 104 class GPUTracerARBTimerQuery : public GPUTracerImpl { |
105 public: | 105 public: |
106 GPUTracerARBTimerQuery(); | 106 explicit GPUTracerARBTimerQuery(gles2::GLES2Decoder* decoder); |
107 virtual ~GPUTracerARBTimerQuery(); | 107 virtual ~GPUTracerARBTimerQuery(); |
108 | 108 |
109 // Implementation of GPUTracerImpl | 109 // Implementation of GPUTracerImpl |
110 virtual void Process() OVERRIDE; | 110 virtual void Process() OVERRIDE; |
111 | 111 |
112 private: | 112 private: |
113 // Implementation of GPUTracerImpl. | 113 // Implementation of GPUTracerImpl. |
114 virtual scoped_refptr<Trace> CreateTrace(const std::string& name) OVERRIDE; | 114 virtual scoped_refptr<Trace> CreateTrace(const std::string& name) OVERRIDE; |
115 | 115 |
116 void CalculateTimerOffset(); | 116 void CalculateTimerOffset(); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 traces_.push_back(current_trace_); | 197 traces_.push_back(current_trace_); |
198 current_trace_ = NULL; | 198 current_trace_ = NULL; |
199 | 199 |
200 IssueProcessTask(); | 200 IssueProcessTask(); |
201 return true; | 201 return true; |
202 } | 202 } |
203 | 203 |
204 void GPUTracerImpl::Process() { | 204 void GPUTracerImpl::Process() { |
205 process_posted_ = false; | 205 process_posted_ = false; |
206 | 206 |
| 207 // Make owning decoder's GL context current |
| 208 if (!decoder_->MakeCurrent()) { |
| 209 // Skip subsequent GL calls if MakeCurrent fails |
| 210 traces_.clear(); |
| 211 return; |
| 212 } |
| 213 |
207 while (!traces_.empty() && traces_.front()->IsAvailable()) { | 214 while (!traces_.empty() && traces_.front()->IsAvailable()) { |
208 traces_.front()->Process(); | 215 traces_.front()->Process(); |
209 traces_.pop_front(); | 216 traces_.pop_front(); |
210 } | 217 } |
211 | 218 |
212 IssueProcessTask(); | 219 IssueProcessTask(); |
213 } | 220 } |
214 | 221 |
215 const std::string& GPUTracerImpl::CurrentName() const { | 222 const std::string& GPUTracerImpl::CurrentName() const { |
216 if (!current_trace_.get()) | 223 if (!current_trace_.get()) |
217 return base::EmptyString(); | 224 return base::EmptyString(); |
218 return current_trace_->name(); | 225 return current_trace_->name(); |
219 } | 226 } |
220 | 227 |
221 scoped_refptr<Trace> GPUTracerImpl::CreateTrace(const std::string& name) { | 228 scoped_refptr<Trace> GPUTracerImpl::CreateTrace(const std::string& name) { |
222 return new NoopTrace(name); | 229 return new NoopTrace(name); |
223 } | 230 } |
224 | 231 |
225 void GPUTracerImpl::IssueProcessTask() { | 232 void GPUTracerImpl::IssueProcessTask() { |
226 if (traces_.empty() || process_posted_) | 233 if (traces_.empty() || process_posted_) |
227 return; | 234 return; |
228 | 235 |
229 process_posted_ = true; | 236 process_posted_ = true; |
230 base::MessageLoop::current()->PostDelayedTask( | 237 base::MessageLoop::current()->PostDelayedTask( |
231 FROM_HERE, | 238 FROM_HERE, |
232 base::Bind(&GPUTracerImpl::Process, base::AsWeakPtr(this)), | 239 base::Bind(&GPUTracerImpl::Process, base::AsWeakPtr(this)), |
233 base::TimeDelta::FromMilliseconds(kProcessInterval)); | 240 base::TimeDelta::FromMilliseconds(kProcessInterval)); |
234 } | 241 } |
235 | 242 |
236 GPUTracerARBTimerQuery::GPUTracerARBTimerQuery() | 243 GPUTracerARBTimerQuery::GPUTracerARBTimerQuery(gles2::GLES2Decoder* decoder) |
237 : GPUTracerImpl(), | 244 : GPUTracerImpl(decoder), timer_offset_(0), last_offset_check_(0) { |
238 timer_offset_(0), | |
239 last_offset_check_(0) { | |
240 CalculateTimerOffset(); | 245 CalculateTimerOffset(); |
241 outputter_ = TraceOutputter::Create("GL_ARB_timer_query"); | 246 outputter_ = TraceOutputter::Create("GL_ARB_timer_query"); |
242 } | 247 } |
243 | 248 |
244 GPUTracerARBTimerQuery::~GPUTracerARBTimerQuery() { | 249 GPUTracerARBTimerQuery::~GPUTracerARBTimerQuery() { |
245 } | 250 } |
246 | 251 |
247 scoped_refptr<Trace> GPUTracerARBTimerQuery::CreateTrace( | 252 scoped_refptr<Trace> GPUTracerARBTimerQuery::CreateTrace( |
248 const std::string& name) { | 253 const std::string& name) { |
249 if (*gpu_category_enabled_) | 254 if (*gpu_category_enabled_) |
(...skipping 21 matching lines...) Expand all Loading... |
271 glGetQueryObjectui64v(query, GL_QUERY_RESULT, &gl_now); | 276 glGetQueryObjectui64v(query, GL_QUERY_RESULT, &gl_now); |
272 base::TimeTicks system_now = base::TimeTicks::NowFromSystemTraceTime(); | 277 base::TimeTicks system_now = base::TimeTicks::NowFromSystemTraceTime(); |
273 | 278 |
274 gl_now /= base::Time::kNanosecondsPerMicrosecond; | 279 gl_now /= base::Time::kNanosecondsPerMicrosecond; |
275 timer_offset_ = system_now.ToInternalValue() - gl_now; | 280 timer_offset_ = system_now.ToInternalValue() - gl_now; |
276 glDeleteQueries(1, &query); | 281 glDeleteQueries(1, &query); |
277 | 282 |
278 last_offset_check_ = system_now.ToInternalValue(); | 283 last_offset_check_ = system_now.ToInternalValue(); |
279 } | 284 } |
280 | 285 |
281 scoped_ptr<GPUTracer> GPUTracer::Create() { | 286 GPUTracer::GPUTracer(gles2::GLES2Decoder* decoder) : decoder_(decoder) {} |
| 287 |
| 288 GPUTracer::~GPUTracer() {} |
| 289 |
| 290 scoped_ptr<GPUTracer> GPUTracer::Create(gles2::GLES2Decoder* decoder) { |
282 if (gfx::g_driver_gl.ext.b_GL_ARB_timer_query) { | 291 if (gfx::g_driver_gl.ext.b_GL_ARB_timer_query) { |
283 return scoped_ptr<GPUTracer>(new GPUTracerARBTimerQuery()); | 292 return scoped_ptr<GPUTracer>(new GPUTracerARBTimerQuery(decoder)); |
284 } | 293 } |
285 return scoped_ptr<GPUTracer>(new GPUTracerImpl()); | 294 return scoped_ptr<GPUTracer>(new GPUTracerImpl(decoder)); |
286 } | 295 } |
287 | 296 |
288 } // namespace gles2 | 297 } // namespace gles2 |
289 } // namespace gpu | 298 } // namespace gpu |
OLD | NEW |