summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorapatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-14 20:48:30 +0000
committerapatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-14 20:48:30 +0000
commit66791e38d624490ad5b13f4a62318ca4ea51be01 (patch)
treef6bc56559e4ee3f195bb8dcaa1af9ea7391b7c48
parentaed85a820f0550808b6eee71b796488275b73f8e (diff)
downloadchromium_src-66791e38d624490ad5b13f4a62318ca4ea51be01.zip
chromium_src-66791e38d624490ad5b13f4a62318ca4ea51be01.tar.gz
chromium_src-66791e38d624490ad5b13f4a62318ca4ea51be01.tar.bz2
GLES2DecoderImpl takes ownership of GLContext passed to initialize.
This is to simplify the management of the GLContext lifetime (one per decoder) when we support shared contexts. TEST=try, WebGL demos BUG=none Review URL: http://codereview.chromium.org/2998001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52390 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--gpu/command_buffer/service/gles2_cmd_decoder.cc21
-rw-r--r--gpu/command_buffer/service/gles2_cmd_decoder.h1
-rw-r--r--gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc4
-rw-r--r--gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h2
-rw-r--r--gpu/command_buffer/service/gpu_processor.cc13
-rw-r--r--gpu/command_buffer/service/gpu_processor.h6
-rw-r--r--gpu/command_buffer/service/gpu_processor_linux.cc16
-rw-r--r--gpu/command_buffer/service/gpu_processor_mac.cc30
-rw-r--r--gpu/command_buffer/service/gpu_processor_win.cc16
9 files changed, 60 insertions, 49 deletions
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc
index 2cc4509a..ceabfa7 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder.cc
+++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc
@@ -536,7 +536,7 @@ class GLES2DecoderImpl : public base::SupportsWeakPtr<GLES2DecoderImpl>,
virtual bool UpdateOffscreenFrameBufferSize();
virtual bool MakeCurrent();
virtual GLES2Util* GetGLES2Util() { return &util_; }
- virtual gfx::GLContext* GetGLContext() { return context_; }
+ virtual gfx::GLContext* GetGLContext() { return context_.get(); }
virtual void SetSwapBuffersCallback(Callback0::Type* callback);
@@ -1051,7 +1051,7 @@ class GLES2DecoderImpl : public base::SupportsWeakPtr<GLES2DecoderImpl>,
#undef GLES2_CMD_OP
// The GL context this decoder renders to on behalf of the client.
- gfx::GLContext* context_;
+ scoped_ptr<gfx::GLContext> context_;
// A GLContext that is kept in its default state. It is used to perform
// operations that should not be dependent on client set GLContext state, like
@@ -1397,7 +1397,6 @@ GLES2Decoder* GLES2Decoder::Create(ContextGroup* group) {
GLES2DecoderImpl::GLES2DecoderImpl(ContextGroup* group)
: GLES2Decoder(group),
- context_(NULL),
error_bits_(0),
util_(0), // TODO(gman): Set to actual num compress texture formats.
pack_alignment_(4),
@@ -1431,12 +1430,15 @@ bool GLES2DecoderImpl::Initialize(gfx::GLContext* context,
GLES2Decoder* parent,
uint32 parent_client_texture_id) {
DCHECK(context);
- DCHECK(!context_);
- context_ = context;
+ DCHECK(!context_.get());
+
+ // Take ownership of the GLContext.
+ context_.reset(context);
// Create a GL context that is kept in a default state and shares a namespace
// with the main GL context.
- default_context_.reset(gfx::GLContext::CreateOffscreenGLContext(context_));
+ default_context_.reset(gfx::GLContext::CreateOffscreenGLContext(
+ context_.get()));
if (!default_context_.get()) {
Destroy();
return false;
@@ -1672,7 +1674,7 @@ void GLES2DecoderImpl::DeleteTexturesHelper(
// } // anonymous namespace
bool GLES2DecoderImpl::MakeCurrent() {
- return context_->MakeCurrent();
+ return context_.get() ? context_->MakeCurrent() : false;
}
gfx::Size GLES2DecoderImpl::GetBoundFrameBufferSize() {
@@ -1881,7 +1883,7 @@ void GLES2DecoderImpl::SetSwapBuffersCallback(Callback0::Type* callback) {
}
void GLES2DecoderImpl::Destroy() {
- if (context_) {
+ if (context_.get()) {
MakeCurrent();
if (black_2d_texture_id_) {
@@ -1931,6 +1933,9 @@ void GLES2DecoderImpl::Destroy() {
offscreen_saved_color_texture_->Destroy();
offscreen_saved_color_texture_.reset();
}
+
+ context_->Destroy();
+ context_.reset();
}
if (default_context_.get()) {
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.h b/gpu/command_buffer/service/gles2_cmd_decoder.h
index 6177a32..e94df94 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder.h
+++ b/gpu/command_buffer/service/gles2_cmd_decoder.h
@@ -44,6 +44,7 @@ class GLES2Decoder : public CommonDecoder {
// Initializes the graphics context. Can create an offscreen
// decoder with a frame buffer that can be referenced from the parent.
+ // Takes ownership of GLContext.
// Parameters:
// context: the GL context to render to.
// size: the size if the GL context is offscreen.
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc
index edb5745..97221dc 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc
+++ b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc
@@ -148,10 +148,10 @@ void GLES2DecoderTestBase::SetUp() {
shared_memory_offset_;
shared_memory_id_ = kSharedMemoryId;
- context_.reset(new gfx::StubGLContext);
+ context_ = new gfx::StubGLContext;
decoder_.reset(GLES2Decoder::Create(&group_));
- decoder_->Initialize(context_.get(), gfx::Size(), NULL, 0);
+ decoder_->Initialize(context_, gfx::Size(), NULL, 0);
decoder_->set_engine(engine_.get());
EXPECT_CALL(*gl_, GenBuffersARB(_, _))
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h
index c90a464..511be84 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h
+++ b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h
@@ -216,7 +216,7 @@ class GLES2DecoderTestBase : public testing::Test {
// Use StrictMock to make 100% sure we know how GL will be called.
scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_;
- scoped_ptr<gfx::StubGLContext> context_;
+ gfx::StubGLContext* context_;
scoped_ptr<GLES2Decoder> decoder_;
GLuint client_buffer_id_;
diff --git a/gpu/command_buffer/service/gpu_processor.cc b/gpu/command_buffer/service/gpu_processor.cc
index 7872b22..336dafe 100644
--- a/gpu/command_buffer/service/gpu_processor.cc
+++ b/gpu/command_buffer/service/gpu_processor.cc
@@ -37,11 +37,11 @@ GPUProcessor::~GPUProcessor() {
Destroy();
}
-bool GPUProcessor::InitializeCommon(const gfx::Size& size,
+bool GPUProcessor::InitializeCommon(gfx::GLContext* context,
+ const gfx::Size& size,
gles2::GLES2Decoder* parent_decoder,
uint32 parent_texture_id) {
- // Context should have been created by platform specific Initialize().
- DCHECK(context_.get());
+ DCHECK(context);
// Map the ring buffer and create the parser.
Buffer ring_buffer = command_buffer_->GetRingBuffer();
@@ -58,7 +58,7 @@ bool GPUProcessor::InitializeCommon(const gfx::Size& size,
}
// Initialize the decoder with either the view or pbuffer GLContext.
- if (!decoder_->Initialize(context_.get(),
+ if (!decoder_->Initialize(context,
size,
parent_decoder,
parent_texture_id)) {
@@ -79,11 +79,6 @@ void GPUProcessor::DestroyCommon() {
group_.Destroy(have_context);
- if (context_.get()) {
- context_->Destroy();
- context_.reset();
- }
-
parser_.reset();
}
diff --git a/gpu/command_buffer/service/gpu_processor.h b/gpu/command_buffer/service/gpu_processor.h
index f1b2a5d..f9c941d 100644
--- a/gpu/command_buffer/service/gpu_processor.h
+++ b/gpu/command_buffer/service/gpu_processor.h
@@ -43,12 +43,15 @@ class GPUProcessor : public CommandBufferEngine {
virtual ~GPUProcessor();
+ // Perform platform specific and common initialization.
bool Initialize(gfx::PluginWindowHandle hwnd,
const gfx::Size& size,
GPUProcessor* parent,
uint32 parent_texture_id);
- bool InitializeCommon(const gfx::Size& size,
+ // Perform common initialization. Takes ownership of GLContext.
+ bool InitializeCommon(gfx::GLContext* context,
+ const gfx::Size& size,
gles2::GLES2Decoder* parent_decoder,
uint32 parent_texture_id);
@@ -103,7 +106,6 @@ class GPUProcessor : public CommandBufferEngine {
gles2::ContextGroup group_;
scoped_ptr<gles2::GLES2Decoder> decoder_;
scoped_ptr<CommandParser> parser_;
- scoped_ptr<gfx::GLContext> context_;
#if defined(OS_MACOSX)
scoped_ptr<AcceleratedSurface> surface_;
diff --git a/gpu/command_buffer/service/gpu_processor_linux.cc b/gpu/command_buffer/service/gpu_processor_linux.cc
index dd1fe6a..f23465f 100644
--- a/gpu/command_buffer/service/gpu_processor_linux.cc
+++ b/gpu/command_buffer/service/gpu_processor_linux.cc
@@ -13,10 +13,6 @@ bool GPUProcessor::Initialize(gfx::PluginWindowHandle window,
const gfx::Size& size,
GPUProcessor* parent,
uint32 parent_texture_id) {
- // Cannot reinitialize.
- if (context_.get())
- return false;
-
// Get the parent decoder and the GLContext to share IDs with, if any.
gles2::GLES2Decoder* parent_decoder = NULL;
gfx::GLContext* parent_context = NULL;
@@ -30,19 +26,23 @@ bool GPUProcessor::Initialize(gfx::PluginWindowHandle window,
}
// Create either a view or pbuffer based GLContext.
+ scoped_ptr<gfx::GLContext> context;
if (window) {
DCHECK(!parent_handle);
// TODO(apatrick): support multisampling.
- context_.reset(gfx::GLContext::CreateViewGLContext(window, false));
+ context.reset(gfx::GLContext::CreateViewGLContext(window, false));
} else {
- context_.reset(gfx::GLContext::CreateOffscreenGLContext(parent_context));
+ context.reset(gfx::GLContext::CreateOffscreenGLContext(parent_context));
}
- if (!context_.get())
+ if (!context.get())
return false;
- return InitializeCommon(size, parent_decoder, parent_texture_id);
+ return InitializeCommon(context.release(),
+ size,
+ parent_decoder,
+ parent_texture_id);
}
void GPUProcessor::Destroy() {
diff --git a/gpu/command_buffer/service/gpu_processor_mac.cc b/gpu/command_buffer/service/gpu_processor_mac.cc
index 52fda60..61a45da 100644
--- a/gpu/command_buffer/service/gpu_processor_mac.cc
+++ b/gpu/command_buffer/service/gpu_processor_mac.cc
@@ -13,10 +13,6 @@ bool GPUProcessor::Initialize(gfx::PluginWindowHandle window,
const gfx::Size& size,
GPUProcessor* parent,
uint32 parent_texture_id) {
- // Cannot reinitialize.
- if (context_.get())
- return false;
-
// Get the parent decoder and the GLContext to share IDs with, if any.
gles2::GLES2Decoder* parent_decoder = NULL;
gfx::GLContext* parent_context = NULL;
@@ -28,8 +24,9 @@ bool GPUProcessor::Initialize(gfx::PluginWindowHandle window,
DCHECK(parent_context);
}
- context_.reset(gfx::GLContext::CreateOffscreenGLContext(parent_context));
- if (!context_.get())
+ scoped_ptr<gfx::GLContext> context(
+ gfx::GLContext::CreateOffscreenGLContext(parent_context));
+ if (!context.get())
return false;
// On Mac OS X since we can not render on-screen we don't even
@@ -39,14 +36,21 @@ bool GPUProcessor::Initialize(gfx::PluginWindowHandle window,
// rendering results back to the browser.
if (window) {
surface_.reset(new AcceleratedSurface());
- // TODO(apatrick): AcceleratedSurface will not work with an OSMesa context.
- if (!surface_->Initialize(context_.get(), false)) {
+
+ // Note that although the GLContext is passed to Initialize and the
+ // GLContext will later be owned by the decoder, AcceleratedSurface does
+ // not hold on to the reference. It simply extracts the underlying GL
+ // context in order to share the namespace with another context.
+ if (!surface_->Initialize(context.get(), false)) {
Destroy();
return false;
}
}
- return InitializeCommon(size, parent_decoder, parent_texture_id);
+ return InitializeCommon(context.release(),
+ size,
+ parent_decoder,
+ parent_texture_id);
return true;
}
@@ -54,8 +58,9 @@ bool GPUProcessor::Initialize(gfx::PluginWindowHandle window,
void GPUProcessor::Destroy() {
if (surface_.get()) {
surface_->Destroy();
+ surface_.reset();
}
- surface_.reset();
+
DestroyCommon();
}
@@ -79,7 +84,10 @@ void GPUProcessor::SetTransportDIBAllocAndFree(
}
void GPUProcessor::WillSwapBuffers() {
- DCHECK(context_->IsCurrent());
+ DCHECK(decoder_.get());
+ DCHECK(decoder_->GetGLContext());
+ DCHECK(decoder_->GetGLContext()->IsCurrent());
+
if (surface_.get()) {
surface_->SwapBuffers();
}
diff --git a/gpu/command_buffer/service/gpu_processor_win.cc b/gpu/command_buffer/service/gpu_processor_win.cc
index 85962b9..2df4d50 100644
--- a/gpu/command_buffer/service/gpu_processor_win.cc
+++ b/gpu/command_buffer/service/gpu_processor_win.cc
@@ -15,10 +15,6 @@ bool GPUProcessor::Initialize(gfx::PluginWindowHandle window,
const gfx::Size& size,
GPUProcessor* parent,
uint32 parent_texture_id) {
- // Cannot reinitialize.
- if (context_.get())
- return false;
-
// Get the parent decoder and the GLContext to share IDs with, if any.
gles2::GLES2Decoder* parent_decoder = NULL;
gfx::GLContext* parent_context = NULL;
@@ -31,19 +27,23 @@ bool GPUProcessor::Initialize(gfx::PluginWindowHandle window,
}
// Create either a view or pbuffer based GLContext.
+ scoped_ptr<gfx::GLContext> context;
if (window) {
DCHECK(!parent_context);
// TODO(apatrick): support multisampling.
- context_.reset(gfx::GLContext::CreateViewGLContext(window, false));
+ context.reset(gfx::GLContext::CreateViewGLContext(window, false));
} else {
- context_.reset(gfx::GLContext::CreateOffscreenGLContext(parent_context));
+ context.reset(gfx::GLContext::CreateOffscreenGLContext(parent_context));
}
- if (!context_.get())
+ if (!context.get())
return false;
- return InitializeCommon(size, parent_decoder, parent_texture_id);
+ return InitializeCommon(context.release(),
+ size,
+ parent_decoder,
+ parent_texture_id);
}
void GPUProcessor::Destroy() {