Chromium Code Reviews| Index: content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.cc |
| =================================================================== |
| --- content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.cc (revision 97725) |
| +++ content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.cc (working copy) |
| @@ -75,20 +75,55 @@ |
| RenderThread* render_thread = RenderThread::current(); |
| if (!render_thread) |
| return false; |
| - GpuChannelHost* host = render_thread->EstablishGpuChannelSync( |
| + host_ = render_thread->EstablishGpuChannelSync( |
| content:: |
| CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE); |
| - if (!host) |
| + if (!host_) |
| return false; |
| - DCHECK(host->state() == GpuChannelHost::kConnected); |
| + DCHECK(host_->state() == GpuChannelHost::kConnected); |
| + const GPUInfo& gpu_info = host_->gpu_info(); |
| + UMA_HISTOGRAM_ENUMERATION( |
| + "GPU.WebGraphicsContext3D_Init_CanLoseContext", |
| + attributes.canRecoverFromContextLoss * 2 + gpu_info.can_lose_context, |
| + 4); |
| + if (attributes.canRecoverFromContextLoss == false) { |
| + if (gpu_info.can_lose_context) |
| + return false; |
| + } |
| + |
| + if (web_view && web_view->mainFrame()) |
| + active_url_ = GURL(web_view->mainFrame()->document().url()); |
| + |
| + attributes_ = attributes; |
| + render_directly_to_web_view_ = render_directly_to_web_view; |
| + if (render_directly_to_web_view_) { |
| + RenderView* renderview = RenderView::FromWebView(web_view); |
| + if (!renderview) |
| + return false; |
| + render_view_routing_id_ = renderview->routing_id(), |
| +#ifndef WTF_USE_THREADED_COMPOSITING |
| + web_view_ = web_view; |
| + } else { |
| + web_view_ = NULL; |
| +#endif |
| + } |
| + context_ = NULL; |
| + gl_ = NULL; |
| + return true; |
| +} |
| + |
| +bool WebGraphicsContext3DCommandBufferImpl::InitializeGLES2() { |
| + DCHECK(!context_); |
| + TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::InitializeGLES2"); |
| + |
| // Convert WebGL context creation attributes into RendererGLContext / 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[] = { |
| RendererGLContext::ALPHA_SIZE, alpha_size, |
| RendererGLContext::DEPTH_SIZE, depth_size, |
| @@ -98,49 +133,31 @@ |
| RendererGLContext::NONE, |
| }; |
| - const char* preferred_extensions = attributes.noExtensions ? |
| + const char* preferred_extensions = attributes_.noExtensions ? |
| kWebGLPreferredGLExtensions : "*"; |
| - const GPUInfo& gpu_info = host->gpu_info(); |
| - UMA_HISTOGRAM_ENUMERATION( |
| - "GPU.WebGraphicsContext3D_Init_CanLoseContext", |
| - attributes.canRecoverFromContextLoss * 2 + gpu_info.can_lose_context, |
| - 4); |
| - if (attributes.canRecoverFromContextLoss == false) { |
| - if (gpu_info.can_lose_context) |
| - return false; |
| - } |
| - |
| - GURL active_url; |
| - if (web_view && web_view->mainFrame()) |
| - active_url = GURL(web_view->mainFrame()->document().url()); |
| - |
| // HACK: Assume this is a WebGL context by looking for the noExtensions |
| // attribute. WebGL contexts must not go in the share group because they |
| // rely on destruction of the context to clean up owned resources. Putting |
| // them in a share group would prevent this from happening. |
| RendererGLContext* share_group = NULL; |
| - if (!attributes.noExtensions) { |
| + if (!attributes_.noExtensions) { |
| share_group = g_all_contexts.Pointer()->empty() ? |
| NULL : (*g_all_contexts.Pointer()->begin())->context_; |
| } |
| - render_directly_to_web_view_ = render_directly_to_web_view; |
| - if (render_directly_to_web_view) { |
| -#ifndef WTF_USE_THREADED_COMPOSITING |
| - RenderView* renderview = RenderView::FromWebView(web_view); |
| + if (render_directly_to_web_view_) { |
| + RenderView* renderview = RenderView::FromWebView(web_view_); |
|
jamesr
2011/08/23 01:23:23
this is highly thread unsafe - it depends on a glo
lain Merrick
2011/08/23 01:31:03
Ack, seem to have lost my earlier CL while updatin
|
| if (!renderview) |
| return false; |
| - web_view_ = web_view; |
|
nduca
2011/08/23 05:08:19
I guess this whole block is gonna go away?
|
| -#endif |
| context_ = RendererGLContext::CreateViewContext( |
| - host, |
| - renderview->routing_id(), |
| - !attributes.noExtensions, |
| + host_, |
| + render_view_routing_id_, |
| + !attributes_.noExtensions, |
| share_group, |
| preferred_extensions, |
| attribs, |
| - active_url); |
| + active_url_); |
| if (context_) { |
| context_->SetSwapBuffersCallback( |
| NewCallback(this, |
| @@ -148,16 +165,13 @@ |
| } |
| } else { |
| context_ = RendererGLContext::CreateOffscreenContext( |
| - host, |
| + host_, |
| gfx::Size(1, 1), |
| - !attributes.noExtensions, |
| + !attributes_.noExtensions, |
| share_group, |
| preferred_extensions, |
| attribs, |
| - active_url); |
| -#ifndef WTF_USE_THREADED_COMPOSITING |
| - web_view_ = NULL; |
| -#endif |
| + active_url_); |
| } |
| if (!context_) |
| return false; |
| @@ -175,7 +189,6 @@ |
| // Set attributes_ from created offscreen context. |
| { |
| - attributes_ = attributes; |
| GLint alpha_bits = 0; |
| getIntegerv(GL_ALPHA_BITS, &alpha_bits); |
| attributes_.alpha = alpha_bits > 0; |
| @@ -190,13 +203,18 @@ |
| attributes_.antialias = samples > 0; |
| } |
| - if (!attributes.noExtensions) |
| + if (!attributes_.noExtensions) |
| g_all_contexts.Pointer()->insert(this); |
|
jamesr
2011/08/23 01:23:23
It does not appear that you've made this threadsaf
lain Merrick
2011/08/23 01:31:03
Will fix.
nduca
2011/08/23 05:08:19
Hmm, lets talk about this tomorrow... I'd like to
|
| return true; |
| } |
| bool WebGraphicsContext3DCommandBufferImpl::makeContextCurrent() { |
| + if (!context_) { |
| + if (!InitializeGLES2()) { |
|
nduca
2011/08/23 05:08:19
or maybe InitializeContext
lain Merrick
2011/08/23 15:14:01
That would work, I really don't mind. I think I we
|
| + return false; |
| + } |
| + } |
| return RendererGLContext::MakeCurrent(context_); |
| } |
| @@ -221,7 +239,6 @@ |
| } |
| WebGLId WebGraphicsContext3DCommandBufferImpl::getPlatformTextureId() { |
| - DCHECK(context_); |
| return context_->GetParentTextureId(); |
| } |