From 4586c978061839a925dd557e2469a38acdfaf0df Mon Sep 17 00:00:00 2001 From: "jnd@chromium.org" Date: Mon, 21 Feb 2011 03:36:58 +0000 Subject: 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. By collecting garbage and trying again on GL context creation failure, we can reduce the chance of failures. BUG=70736 Review URL: http://codereview.chromium.org/6283015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75533 0039d316-1c4b-4281-b951-d872f2087c98 --- webkit/gpu/webgraphicscontext3d_in_process_impl.cc | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'webkit/gpu') diff --git a/webkit/gpu/webgraphicscontext3d_in_process_impl.cc b/webkit/gpu/webgraphicscontext3d_in_process_impl.cc index 3e97073..6093ba6 100644 --- a/webkit/gpu/webgraphicscontext3d_in_process_impl.cc +++ b/webkit/gpu/webgraphicscontext3d_in_process_impl.cc @@ -13,6 +13,7 @@ #include "app/gfx/gl/gl_context.h" #include "app/gfx/gl/gl_implementation.h" #include "base/logging.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" @@ -121,6 +122,8 @@ bool WebGraphicsContext3DInProcessImpl::initialize( } } + is_gles2_ = gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2; + // This implementation always renders offscreen regardless of // whether render_directly_to_web_view is true. Both DumpRenderTree // and test_shell paint first to an intermediate offscreen buffer @@ -128,8 +131,22 @@ bool WebGraphicsContext3DInProcessImpl::initialize( // correctly handles the case where the compositor is active but // the output needs to go to a WebCanvas. gl_context_.reset(gfx::GLContext::CreateOffscreenGLContext(share_context)); - if (!gl_context_.get()) - return false; + 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::CreateOffscreenGLContext(share_context)); + if (!gl_context_.get()) + return false; + } attributes_ = attributes; @@ -144,7 +161,6 @@ bool WebGraphicsContext3DInProcessImpl::initialize( if (render_directly_to_web_view) attributes_.antialias = false; - is_gles2_ = gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2; const char* extensions = reinterpret_cast(glGetString(GL_EXTENSIONS)); have_ext_framebuffer_object_ = -- cgit v1.1