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(
DCHECK(!context_.get());
set_initialized();
gpu_tracer_ = GPUTracer::Create();
gpu_tracer_ = GPUTracer::Create(this);
gpu_state_tracer_ = GPUStateTracer::Create(&state_);
if (CommandLine::ForCurrentProcess()->HasSwitch(
......
......@@ -69,11 +69,11 @@ class GPUTracerImpl
: public GPUTracer,
public base::SupportsWeakPtr<GPUTracerImpl> {
public:
GPUTracerImpl()
: gpu_category_enabled_(
TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED("gpu")),
process_posted_(false) {
}
explicit GPUTracerImpl(gles2::GLES2Decoder* decoder)
: GPUTracer(decoder),
gpu_category_enabled_(
TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED("gpu")),
process_posted_(false) {}
virtual ~GPUTracerImpl() {}
// Implementation of gpu::gles2::GPUTracer
......@@ -103,7 +103,7 @@ class GPUTracerImpl
class GPUTracerARBTimerQuery : public GPUTracerImpl {
public:
GPUTracerARBTimerQuery();
explicit GPUTracerARBTimerQuery(gles2::GLES2Decoder* decoder);
virtual ~GPUTracerARBTimerQuery();
// Implementation of GPUTracerImpl
......@@ -204,6 +204,13 @@ bool GPUTracerImpl::End() {
void GPUTracerImpl::Process() {
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()) {
traces_.front()->Process();
traces_.pop_front();
......@@ -233,10 +240,8 @@ void GPUTracerImpl::IssueProcessTask() {
base::TimeDelta::FromMilliseconds(kProcessInterval));
}
GPUTracerARBTimerQuery::GPUTracerARBTimerQuery()
: GPUTracerImpl(),
timer_offset_(0),
last_offset_check_(0) {
GPUTracerARBTimerQuery::GPUTracerARBTimerQuery(gles2::GLES2Decoder* decoder)
: GPUTracerImpl(decoder), timer_offset_(0), last_offset_check_(0) {
CalculateTimerOffset();
outputter_ = TraceOutputter::Create("GL_ARB_timer_query");
}
......@@ -278,11 +283,15 @@ void GPUTracerARBTimerQuery::CalculateTimerOffset() {
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) {
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
......
......@@ -12,6 +12,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/threading/thread.h"
#include "gpu/command_buffer/service/gles2_cmd_decoder.h"
#include "gpu/gpu_export.h"
#include "ui/gl/gl_bindings.h"
......@@ -21,10 +22,10 @@ namespace gles2 {
// Traces GPU Commands.
class GPUTracer {
public:
static scoped_ptr<GPUTracer> Create();
static scoped_ptr<GPUTracer> Create(gles2::GLES2Decoder* decoder);
GPUTracer() {}
virtual ~GPUTracer() {}
explicit GPUTracer(gles2::GLES2Decoder* decoder);
virtual ~GPUTracer();
// Begin a trace.
virtual bool Begin(const std::string& name) = 0;
......@@ -36,6 +37,8 @@ class GPUTracer {
// Returns empty string if no current open trace.
virtual const std::string& CurrentName() const = 0;
gles2::GLES2Decoder* decoder_;
private:
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