Commit bccc0f37 authored by vmiura@chromium.org's avatar vmiura@chromium.org

Make correct GL context current during gpu_tracer processing

The gpu_tracer reads back GL timer queries as a delayed task.
During processing the associated GL context wasn't made current, so it
was possible to query the wrong context, get incorrect timestamps, or
cause GL errors.

BUG=331161

Review URL: https://codereview.chromium.org/130313002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@244068 0039d316-1c4b-4281-b951-d872f2087c98
parent 17dad9d5
...@@ -2216,7 +2216,7 @@ bool GLES2DecoderImpl::Initialize( ...@@ -2216,7 +2216,7 @@ bool GLES2DecoderImpl::Initialize(
DCHECK(!context_.get()); DCHECK(!context_.get());
set_initialized(); set_initialized();
gpu_tracer_ = GPUTracer::Create(); gpu_tracer_ = GPUTracer::Create(this);
gpu_state_tracer_ = GPUStateTracer::Create(&state_); gpu_state_tracer_ = GPUStateTracer::Create(&state_);
if (CommandLine::ForCurrentProcess()->HasSwitch( if (CommandLine::ForCurrentProcess()->HasSwitch(
......
...@@ -69,11 +69,11 @@ class GPUTracerImpl ...@@ -69,11 +69,11 @@ class GPUTracerImpl
: public GPUTracer, : public GPUTracer,
public base::SupportsWeakPtr<GPUTracerImpl> { public base::SupportsWeakPtr<GPUTracerImpl> {
public: public:
GPUTracerImpl() explicit GPUTracerImpl(gles2::GLES2Decoder* decoder)
: gpu_category_enabled_( : GPUTracer(decoder),
TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED("gpu")), gpu_category_enabled_(
process_posted_(false) { TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED("gpu")),
} process_posted_(false) {}
virtual ~GPUTracerImpl() {} virtual ~GPUTracerImpl() {}
// Implementation of gpu::gles2::GPUTracer // Implementation of gpu::gles2::GPUTracer
...@@ -103,7 +103,7 @@ class GPUTracerImpl ...@@ -103,7 +103,7 @@ class GPUTracerImpl
class GPUTracerARBTimerQuery : public GPUTracerImpl { class GPUTracerARBTimerQuery : public GPUTracerImpl {
public: public:
GPUTracerARBTimerQuery(); explicit GPUTracerARBTimerQuery(gles2::GLES2Decoder* decoder);
virtual ~GPUTracerARBTimerQuery(); virtual ~GPUTracerARBTimerQuery();
// Implementation of GPUTracerImpl // Implementation of GPUTracerImpl
...@@ -204,6 +204,13 @@ bool GPUTracerImpl::End() { ...@@ -204,6 +204,13 @@ bool GPUTracerImpl::End() {
void GPUTracerImpl::Process() { void GPUTracerImpl::Process() {
process_posted_ = false; process_posted_ = false;
// Make owning decoder's GL context current
if (!decoder_->MakeCurrent()) {
// Skip subsequent GL calls if MakeCurrent fails
traces_.clear();
return;
}
while (!traces_.empty() && traces_.front()->IsAvailable()) { while (!traces_.empty() && traces_.front()->IsAvailable()) {
traces_.front()->Process(); traces_.front()->Process();
traces_.pop_front(); traces_.pop_front();
...@@ -233,10 +240,8 @@ void GPUTracerImpl::IssueProcessTask() { ...@@ -233,10 +240,8 @@ void GPUTracerImpl::IssueProcessTask() {
base::TimeDelta::FromMilliseconds(kProcessInterval)); base::TimeDelta::FromMilliseconds(kProcessInterval));
} }
GPUTracerARBTimerQuery::GPUTracerARBTimerQuery() GPUTracerARBTimerQuery::GPUTracerARBTimerQuery(gles2::GLES2Decoder* decoder)
: GPUTracerImpl(), : GPUTracerImpl(decoder), timer_offset_(0), last_offset_check_(0) {
timer_offset_(0),
last_offset_check_(0) {
CalculateTimerOffset(); CalculateTimerOffset();
outputter_ = TraceOutputter::Create("GL_ARB_timer_query"); outputter_ = TraceOutputter::Create("GL_ARB_timer_query");
} }
...@@ -278,11 +283,15 @@ void GPUTracerARBTimerQuery::CalculateTimerOffset() { ...@@ -278,11 +283,15 @@ void GPUTracerARBTimerQuery::CalculateTimerOffset() {
last_offset_check_ = system_now.ToInternalValue(); last_offset_check_ = system_now.ToInternalValue();
} }
scoped_ptr<GPUTracer> GPUTracer::Create() { GPUTracer::GPUTracer(gles2::GLES2Decoder* decoder) : decoder_(decoder) {}
GPUTracer::~GPUTracer() {}
scoped_ptr<GPUTracer> GPUTracer::Create(gles2::GLES2Decoder* decoder) {
if (gfx::g_driver_gl.ext.b_GL_ARB_timer_query) { if (gfx::g_driver_gl.ext.b_GL_ARB_timer_query) {
return scoped_ptr<GPUTracer>(new GPUTracerARBTimerQuery()); return scoped_ptr<GPUTracer>(new GPUTracerARBTimerQuery(decoder));
} }
return scoped_ptr<GPUTracer>(new GPUTracerImpl()); return scoped_ptr<GPUTracer>(new GPUTracerImpl(decoder));
} }
} // namespace gles2 } // namespace gles2
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/threading/thread.h" #include "base/threading/thread.h"
#include "gpu/command_buffer/service/gles2_cmd_decoder.h"
#include "gpu/gpu_export.h" #include "gpu/gpu_export.h"
#include "ui/gl/gl_bindings.h" #include "ui/gl/gl_bindings.h"
...@@ -21,10 +22,10 @@ namespace gles2 { ...@@ -21,10 +22,10 @@ namespace gles2 {
// Traces GPU Commands. // Traces GPU Commands.
class GPUTracer { class GPUTracer {
public: public:
static scoped_ptr<GPUTracer> Create(); static scoped_ptr<GPUTracer> Create(gles2::GLES2Decoder* decoder);
GPUTracer() {} explicit GPUTracer(gles2::GLES2Decoder* decoder);
virtual ~GPUTracer() {} virtual ~GPUTracer();
// Begin a trace. // Begin a trace.
virtual bool Begin(const std::string& name) = 0; virtual bool Begin(const std::string& name) = 0;
...@@ -36,6 +37,8 @@ class GPUTracer { ...@@ -36,6 +37,8 @@ class GPUTracer {
// Returns empty string if no current open trace. // Returns empty string if no current open trace.
virtual const std::string& CurrentName() const = 0; virtual const std::string& CurrentName() const = 0;
gles2::GLES2Decoder* decoder_;
private: private:
DISALLOW_COPY_AND_ASSIGN(GPUTracer); DISALLOW_COPY_AND_ASSIGN(GPUTracer);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment