Index: webkit/gpu/webgraphicscontext3d_in_process_impl.cc |
=================================================================== |
--- webkit/gpu/webgraphicscontext3d_in_process_impl.cc (revision 86168) |
+++ webkit/gpu/webgraphicscontext3d_in_process_impl.cc (working copy) |
@@ -90,6 +90,7 @@ |
glDeleteFramebuffersEXT(1, &fbo_); |
gl_context_->Destroy(); |
+ gl_surface_->Destroy(); |
for (ShaderSourceMap::iterator ii = shader_source_map_.begin(); |
ii != shader_source_map_.end(); ++ii) { |
@@ -133,9 +134,9 @@ |
// and from there to the window, and WebViewImpl::paint already |
// correctly handles the case where the compositor is active but |
// the output needs to go to a WebCanvas. |
- scoped_ptr<gfx::GLSurface> surface(gfx::GLSurface::CreateOffscreenGLSurface( |
+ gl_surface_.reset(gfx::GLSurface::CreateOffscreenGLSurface( |
gfx::Size(1, 1))); |
- if (!surface.get()) { |
+ if (!gl_surface_.get()) { |
if (!is_gles2_) |
return false; |
@@ -147,16 +148,34 @@ |
// and force them to drop their contexts, sending a context lost event if |
// necessary. |
webView->mainFrame()->collectGarbage(); |
- surface.reset(gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(1, 1))); |
- if (!surface.get()) |
+ |
+ gl_surface_.reset( |
+ gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(1, 1))); |
+ if (!gl_surface_.get()) |
return false; |
} |
- gl_context_.reset(gfx::GLContext::CreateGLContext(surface.release(), |
- share_context)); |
- if (!gl_context_.get()) |
- return false; |
+ gl_context_.reset(gfx::GLContext::CreateGLContext(share_context, |
+ gl_surface_.get())); |
+ if (!gl_context_.get()) { |
+ if (!is_gles2_) |
+ return false; |
+ // Embedded systems have smaller limit on number of GL contexts. Sometimes |
+ // failure of GL context creation is because of existing GL contexts |
+ // referenced by JavaScript garbages. Collect garbage and try again. |
+ // TODO: Besides this solution, kbr@chromium.org suggested: upon receiving |
+ // a page unload event, iterate down any live WebGraphicsContext3D instances |
+ // and force them to drop their contexts, sending a context lost event if |
+ // necessary. |
+ webView->mainFrame()->collectGarbage(); |
+ |
+ gl_context_.reset(gfx::GLContext::CreateGLContext(share_context, |
+ gl_surface_.get())); |
+ if (!gl_context_.get()) |
+ return false; |
+ } |
+ |
attributes_ = attributes; |
// FIXME: for the moment we disable multisampling for the compositor. |
@@ -170,7 +189,7 @@ |
if (render_directly_to_web_view) |
attributes_.antialias = false; |
- if (!gl_context_->MakeCurrent()) { |
+ if (!gl_context_->MakeCurrent(gl_surface_.get())) { |
gl_context_.reset(); |
return false; |
} |
@@ -265,7 +284,7 @@ |
} |
bool WebGraphicsContext3DInProcessImpl::makeContextCurrent() { |
- return gl_context_->MakeCurrent(); |
+ return gl_context_->MakeCurrent(gl_surface_.get()); |
} |
int WebGraphicsContext3DInProcessImpl::width() { |