Chromium Code Reviews| Index: webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc |
| diff --git a/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc b/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc |
| index f55d5a3a759f2ee502c827b44c925830702541cf..3caa796ac46b890e3e4ae65b5859d3ba067a7de9 100644 |
| --- a/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc |
| +++ b/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc |
| @@ -544,7 +544,8 @@ void GLInProcessContext::OnContextLost() { |
| WebGraphicsContext3DInProcessCommandBufferImpl:: |
| WebGraphicsContext3DInProcessCommandBufferImpl() |
| - : context_(NULL), |
| + : pending_lazy_initialize_(false), |
| + context_(NULL), |
| gl_(NULL), |
| context_lost_callback_(NULL), |
| context_lost_reason_(GL_NO_ERROR), |
| @@ -560,15 +561,22 @@ WebGraphicsContext3DInProcessCommandBufferImpl:: |
| } |
| bool WebGraphicsContext3DInProcessCommandBufferImpl::Initialize( |
| - WebGraphicsContext3D::Attributes attributes, |
| - WebKit::WebGraphicsContext3D* view_context) { |
| + const WebGraphicsContext3D::Attributes& attributes) { |
| + attributes_ = attributes; |
| + pending_lazy_initialize_ = true; |
| + return true; |
|
piman
2013/03/21 22:29:11
If Initialize doesn't do anything any more and can
boliu
2013/03/21 22:53:23
Done.
|
| +} |
| + |
| +bool WebGraphicsContext3DInProcessCommandBufferImpl::DoInitialize() { |
| + DCHECK(pending_lazy_initialize_); |
| + |
| // Convert WebGL context creation attributes into GLInProcessContext / EGL |
| // size requests. |
| - const int alpha_size = attributes.alpha ? 8 : 0; |
| - const int depth_size = attributes.depth ? 24 : 0; |
| - const int stencil_size = attributes.stencil ? 8 : 0; |
| - const int samples = attributes.antialias ? 4 : 0; |
| - const int sample_buffers = attributes.antialias ? 1 : 0; |
| + const int alpha_size = attributes_.alpha ? 8 : 0; |
| + const int depth_size = attributes_.depth ? 24 : 0; |
| + const int stencil_size = attributes_.stencil ? 8 : 0; |
| + const int samples = attributes_.antialias ? 4 : 0; |
| + const int sample_buffers = attributes_.antialias ? 1 : 0; |
| const int32 attribs[] = { |
| GLInProcessContext::ALPHA_SIZE, alpha_size, |
| GLInProcessContext::DEPTH_SIZE, depth_size, |
| @@ -587,22 +595,14 @@ bool WebGraphicsContext3DInProcessCommandBufferImpl::Initialize( |
| // discrete GPU is created, or the last one is destroyed. |
| gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; |
| - GLInProcessContext* parent_context = NULL; |
| - if (view_context) { |
| - WebGraphicsContext3DInProcessCommandBufferImpl* context_impl = |
| - static_cast<WebGraphicsContext3DInProcessCommandBufferImpl*>( |
| - view_context); |
| - parent_context = context_impl->context_; |
| - } |
| - |
| WebGraphicsContext3DInProcessCommandBufferImpl* context_group = NULL; |
| base::AutoLock lock(g_all_shared_contexts_lock.Get()); |
| - if (attributes.shareResources) |
| + if (attributes_.shareResources) |
| context_group = g_all_shared_contexts.Pointer()->empty() ? |
| NULL : *g_all_shared_contexts.Pointer()->begin(); |
| context_ = GLInProcessContext::CreateOffscreenContext( |
| - parent_context, |
| + NULL, |
|
piman
2013/03/21 22:29:11
note: if we don't use parenting here any more, the
boliu
2013/03/21 22:53:23
Done.
|
| gfx::Size(1, 1), |
| context_group ? context_group->context_ : NULL, |
| preferred_extensions, |
| @@ -614,7 +614,7 @@ bool WebGraphicsContext3DInProcessCommandBufferImpl::Initialize( |
| gl_ = context_->GetImplementation(); |
| - if (gl_ && attributes.noExtensions) |
| + if (gl_ && attributes_.noExtensions) |
| gl_->EnableFeatureCHROMIUM("webgl_enable_glsl_webgl_validation"); |
| context_->SetContextLostCallback( |
| @@ -624,7 +624,6 @@ bool WebGraphicsContext3DInProcessCommandBufferImpl::Initialize( |
| // Set attributes_ from created offscreen context. |
| { |
| - attributes_ = attributes; |
| GLint alpha_bits = 0; |
| getIntegerv(GL_ALPHA_BITS, &alpha_bits); |
| attributes_.alpha = alpha_bits > 0; |
| @@ -638,15 +637,18 @@ bool WebGraphicsContext3DInProcessCommandBufferImpl::Initialize( |
| getIntegerv(GL_SAMPLE_BUFFERS, &sample_buffers); |
| attributes_.antialias = sample_buffers > 0; |
| } |
| - makeContextCurrent(); |
| - if (attributes.shareResources) |
| + if (attributes_.shareResources) |
| g_all_shared_contexts.Pointer()->insert(this); |
| + pending_lazy_initialize_ = false; |
| return true; |
| } |
| bool WebGraphicsContext3DInProcessCommandBufferImpl::makeContextCurrent() { |
| + if (pending_lazy_initialize_ && !DoInitialize()) |
| + return false; |
| + |
| return GLInProcessContext::MakeCurrent(context_); |
| } |