diff options
author | apatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-23 20:34:15 +0000 |
---|---|---|
committer | apatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-23 20:34:15 +0000 |
commit | f62a5abd6205c7a84a19f8b00b45b0792b767f57 (patch) | |
tree | 100e751f4e0302bbb4ecde919fb1cea272aeb7cf /webkit/gpu | |
parent | 97807cbf58afe1e25b2bd014ce758e88e483d08b (diff) | |
download | chromium_src-f62a5abd6205c7a84a19f8b00b45b0792b767f57.zip chromium_src-f62a5abd6205c7a84a19f8b00b45b0792b767f57.tar.gz chromium_src-f62a5abd6205c7a84a19f8b00b45b0792b767f57.tar.bz2 |
GLContext no longer holds a pointer to a GLSurface.
This is part of an ongoing effort to treat GL contexts and GL surfaces as independent entities.
TEST=run WebGL on mac, windows and linux, trybots
BUG=none
Review URL: http://codereview.chromium.org/7021014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86332 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/gpu')
4 files changed, 59 insertions, 23 deletions
diff --git a/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc b/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc index 7b43d63..62439d8 100644 --- a/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc +++ b/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc @@ -133,14 +133,9 @@ bool WebGraphicsContext3DInProcessCommandBufferImpl::initialize( // 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( - gfx::Size(1, 1))); - if (!surface->Initialize()) - return false; + gl_surface_.reset(gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(1, 1))); - gl_context_.reset(gfx::GLContext::CreateGLContext(surface.release(), - share_context)); - if (!gl_context_.get()) { + if (!gl_surface_.get()) { if (!is_gles2_) return false; @@ -153,11 +148,29 @@ bool WebGraphicsContext3DInProcessCommandBufferImpl::initialize( // necessary. webView->mainFrame()->collectGarbage(); - surface.reset(gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(1, 1))); + gl_surface_.reset(gfx::GLSurface::CreateOffscreenGLSurface( + gfx::Size(1, 1))); + if (!gl_surface_.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( - surface.release(), - share_context)); + gl_context_.reset(gfx::GLContext::CreateGLContext(share_context, + gl_surface_.get())); if (!gl_context_.get()) return false; } @@ -175,7 +188,7 @@ bool WebGraphicsContext3DInProcessCommandBufferImpl::initialize( 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; } @@ -270,7 +283,7 @@ void WebGraphicsContext3DInProcessCommandBufferImpl::ResolveMultisampledFramebuf } bool WebGraphicsContext3DInProcessCommandBufferImpl::makeContextCurrent() { - return gl_context_->MakeCurrent(); + return gl_context_->MakeCurrent(gl_surface_.get()); } int WebGraphicsContext3DInProcessCommandBufferImpl::width() { diff --git a/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h b/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h index 1b2c1c2..08c8df1 100644 --- a/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h +++ b/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h @@ -19,6 +19,7 @@ #endif namespace gfx { class GLContext; +class GLSurface; } using WebKit::WGC3Dchar; @@ -464,6 +465,7 @@ class WebGraphicsContext3DInProcessCommandBufferImpl : public WebGraphicsContext std::set<WGC3Denum> synthetic_errors_set_; scoped_ptr<gfx::GLContext> gl_context_; + scoped_ptr<gfx::GLSurface> gl_surface_; ShaderSourceMap shader_source_map_; diff --git a/webkit/gpu/webgraphicscontext3d_in_process_impl.cc b/webkit/gpu/webgraphicscontext3d_in_process_impl.cc index b0d9764..f2fc2e9 100644 --- a/webkit/gpu/webgraphicscontext3d_in_process_impl.cc +++ b/webkit/gpu/webgraphicscontext3d_in_process_impl.cc @@ -90,6 +90,7 @@ WebGraphicsContext3DInProcessImpl::~WebGraphicsContext3DInProcessImpl() { 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 @@ bool WebGraphicsContext3DInProcessImpl::initialize( // 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,15 +148,33 @@ bool WebGraphicsContext3DInProcessImpl::initialize( // 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; @@ -170,7 +189,7 @@ bool WebGraphicsContext3DInProcessImpl::initialize( 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 @@ void WebGraphicsContext3DInProcessImpl::ResolveMultisampledFramebuffer( } bool WebGraphicsContext3DInProcessImpl::makeContextCurrent() { - return gl_context_->MakeCurrent(); + return gl_context_->MakeCurrent(gl_surface_.get()); } int WebGraphicsContext3DInProcessImpl::width() { diff --git a/webkit/gpu/webgraphicscontext3d_in_process_impl.h b/webkit/gpu/webgraphicscontext3d_in_process_impl.h index 5c0264c..ae3fac2 100644 --- a/webkit/gpu/webgraphicscontext3d_in_process_impl.h +++ b/webkit/gpu/webgraphicscontext3d_in_process_impl.h @@ -19,6 +19,7 @@ #endif namespace gfx { class GLContext; +class GLSurface; } using WebKit::WGC3Dchar; @@ -468,6 +469,7 @@ class WebGraphicsContext3DInProcessImpl : public WebGraphicsContext3D { std::set<WGC3Denum> synthetic_errors_set_; scoped_ptr<gfx::GLContext> gl_context_; + scoped_ptr<gfx::GLSurface> gl_surface_; ShaderSourceMap shader_source_map_; |