diff options
author | apatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-19 21:58:05 +0000 |
---|---|---|
committer | apatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-19 21:58:05 +0000 |
commit | ebcc462bff6e2328dbae1fb6a42a3ffc3d2f0e4a (patch) | |
tree | 7fbf6daacb8a0149462b65d4d53eb41bfc85f4bc | |
parent | 46da33beb42f48672659fed469da4b15ed927776 (diff) | |
download | chromium_src-ebcc462bff6e2328dbae1fb6a42a3ffc3d2f0e4a.zip chromium_src-ebcc462bff6e2328dbae1fb6a42a3ffc3d2f0e4a.tar.gz chromium_src-ebcc462bff6e2328dbae1fb6a42a3ffc3d2f0e4a.tar.bz2 |
Reparenting of RendererGLContexts supports going from no parent to having a parent.
RendererGLContext::SetParent is a no-op if the parent did not change to avoid a redundant sync IPC.
Added SetParentContext to WebGraphicsContext3DCommandBufferImpl. WebKit change to follow.
Review URL: http://codereview.chromium.org/7237009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@93106 0039d316-1c4b-4281-b951-d872f2087c98
8 files changed, 61 insertions, 45 deletions
diff --git a/content/renderer/gpu/renderer_gl_context.cc b/content/renderer/gpu/renderer_gl_context.cc index bf2d100..4937a46 100644 --- a/content/renderer/gpu/renderer_gl_context.cc +++ b/content/renderer/gpu/renderer_gl_context.cc @@ -224,6 +224,9 @@ RendererGLContext* RendererGLContext::CreateOffscreenContext( } bool RendererGLContext::SetParent(RendererGLContext* new_parent) { + if (parent_.get() == new_parent) + return true; + // Allocate a texture ID with respect to the parent and change the parent. uint32 new_parent_texture_id = 0; if (command_buffer_) { diff --git a/content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.cc b/content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.cc index ffb997f..57cac38 100644 --- a/content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.cc +++ b/content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.cc @@ -106,7 +106,6 @@ bool WebGraphicsContext3DCommandBufferImpl::initialize( if (web_view && web_view->mainFrame()) active_url = GURL(web_view->mainFrame()->document().url()); - RendererGLContext* parent_context = NULL; if (render_directly_to_web_view) { RenderView* renderview = RenderView::FromWebView(web_view); if (!renderview) @@ -125,22 +124,6 @@ bool WebGraphicsContext3DCommandBufferImpl::initialize( &WebGraphicsContext3DCommandBufferImpl::OnSwapBuffersComplete)); } } else { - bool compositing_enabled = !CommandLine::ForCurrentProcess()->HasSwitch( - switches::kDisableAcceleratedCompositing); - // If GPU compositing is enabled we need to create a GL context that shares - // resources with the compositor's context. - if (compositing_enabled) { - // Asking for the WebGraphicsContext3D on the WebView will force one to - // be created if it doesn't already exist. When the compositor is created - // for the view it will use the same context. - WebKit::WebGraphicsContext3D* view_context = - web_view->graphicsContext3D(); - if (view_context) { - WebGraphicsContext3DCommandBufferImpl* context_impl = - static_cast<WebGraphicsContext3DCommandBufferImpl*>(view_context); - parent_context = context_impl->context_; - } - } context_ = RendererGLContext::CreateOffscreenContext( host, gfx::Size(1, 1), @@ -152,9 +135,6 @@ bool WebGraphicsContext3DCommandBufferImpl::initialize( if (!context_) return false; - if (!context_->SetParent(parent_context)) - return false; - gl_ = context_->GetImplementation(); context_->SetContextLostCallback( NewCallback(this, @@ -202,6 +182,14 @@ bool WebGraphicsContext3DCommandBufferImpl::isGLES2Compliant() { return true; } +bool WebGraphicsContext3DCommandBufferImpl::setParentContext( + WebGraphicsContext3D* parent_context) { + WebGraphicsContext3DCommandBufferImpl* parent_context_impl = + static_cast<WebGraphicsContext3DCommandBufferImpl*>(parent_context); + return context_->SetParent( + parent_context_impl ? parent_context_impl->context() : NULL); +} + WebGLId WebGraphicsContext3DCommandBufferImpl::getPlatformTextureId() { DCHECK(context_); return context_->GetParentTextureId(); diff --git a/content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h b/content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h index 5411502..e291c82 100644 --- a/content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h +++ b/content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h @@ -64,6 +64,8 @@ class WebGraphicsContext3DCommandBufferImpl virtual bool isGLES2Compliant(); + virtual bool setParentContext(WebGraphicsContext3D* parent_context); + virtual void reshape(int width, int height); virtual bool readBackFramebuffer(unsigned char* pixels, size_t buffer_size); diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc index d5bd745..1dcfd51 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder.cc +++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc @@ -470,6 +470,7 @@ class GLES2DecoderImpl : public base::SupportsWeakPtr<GLES2DecoderImpl>, uint32 parent_texture_id); virtual void ResizeOffscreenFrameBuffer(const gfx::Size& size); virtual bool UpdateOffscreenFrameBufferSize(); + void UpdateParentTextureInfo(); virtual bool MakeCurrent(); virtual GLES2Util* GetGLES2Util() { return &util_; } virtual gfx::GLContext* GetGLContext() { return context_.get(); } @@ -2273,21 +2274,36 @@ bool GLES2DecoderImpl::UpdateOffscreenFrameBufferSize() { RestoreClearState(); } - if (parent_ || IsOffscreenBufferMultisampled()) { - DCHECK(offscreen_saved_color_format_); - offscreen_saved_color_texture_->AllocateStorage( - pending_offscreen_size_, offscreen_saved_color_format_); + // Allocate the offscreen saved color texture. + DCHECK(offscreen_saved_color_format_); + offscreen_saved_color_texture_->AllocateStorage( + pending_offscreen_size_, offscreen_saved_color_format_); - offscreen_saved_frame_buffer_->AttachRenderTexture( - offscreen_saved_color_texture_.get()); - if (offscreen_saved_frame_buffer_->CheckStatus() != - GL_FRAMEBUFFER_COMPLETE) { - LOG(ERROR) << "GLES2DecoderImpl::UpdateOffscreenFrameBufferSize failed " - << "because offscreen saved FBO was incomplete."; - return false; - } + offscreen_saved_frame_buffer_->AttachRenderTexture( + offscreen_saved_color_texture_.get()); + if (offscreen_saved_frame_buffer_->CheckStatus() != + GL_FRAMEBUFFER_COMPLETE) { + LOG(ERROR) << "GLES2DecoderImpl::UpdateOffscreenFrameBufferSize failed " + << "because offscreen saved FBO was incomplete."; + return false; + } + + // Clear the offscreen color texture. + { + ScopedFrameBufferBinder binder(this, offscreen_saved_frame_buffer_->id()); + glClearColor(0, 0, 0, 0); + glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + glDisable(GL_SCISSOR_TEST); + glClear(GL_COLOR_BUFFER_BIT); + RestoreClearState(); } + UpdateParentTextureInfo(); + + return true; +} + +void GLES2DecoderImpl::UpdateParentTextureInfo() { if (parent_) { // Update the info about the offscreen saved color texture in the parent. // The reference to the parent is a weak pointer and will become null if the @@ -2331,19 +2347,7 @@ bool GLES2DecoderImpl::UpdateOffscreenFrameBufferSize() { info, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - - // Clear the offscreen color texture. - { - ScopedFrameBufferBinder binder(this, offscreen_saved_frame_buffer_->id()); - glClearColor(0, 0, 0, 0); - glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - glDisable(GL_SCISSOR_TEST); - glClear(GL_COLOR_BUFFER_BIT); - RestoreClearState(); - } } - - return true; } void GLES2DecoderImpl::SetResizeCallback(Callback1<gfx::Size>::Type* callback) { @@ -2441,6 +2445,9 @@ void GLES2DecoderImpl::Destroy() { bool GLES2DecoderImpl::SetParent(GLES2Decoder* new_parent, uint32 new_parent_texture_id) { + if (!offscreen_saved_color_texture_.get()) + return false; + // Remove the saved frame buffer mapping from the parent decoder. The // parent pointer is a weak pointer so it will be null if the parent has // already been destroyed. @@ -2473,6 +2480,8 @@ bool GLES2DecoderImpl::SetParent(GLES2Decoder* new_parent, new_parent_impl->texture_manager()->SetInfoTarget(info, GL_TEXTURE_2D); parent_ = new_parent_impl->AsWeakPtr(); + + UpdateParentTextureInfo(); } else { parent_.reset(); } @@ -6485,7 +6494,7 @@ error::Error GLES2DecoderImpl::HandleSwapBuffers( ScopedFrameBufferBinder binder(this, offscreen_target_frame_buffer_->id()); - if (parent_) { + if (surface_->IsOffscreen()) { // Copy the target frame buffer to the saved offscreen texture. offscreen_saved_color_texture_->Copy( offscreen_saved_color_texture_->size(), diff --git a/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc b/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc index 36858fb..f633323 100644 --- a/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc +++ b/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc @@ -881,6 +881,11 @@ bool WebGraphicsContext3DInProcessCommandBufferImpl::isGLES2Compliant() { return true; } +bool WebGraphicsContext3DInProcessCommandBufferImpl::setParentContext( + WebGraphicsContext3D* parent_context) { + return false; +} + WebGLId WebGraphicsContext3DInProcessCommandBufferImpl::getPlatformTextureId() { DCHECK(context_); return context_->GetParentTextureId(); diff --git a/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h b/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h index 5e2df99..ce6ce46 100644 --- a/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h +++ b/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h @@ -65,6 +65,8 @@ class WebGraphicsContext3DInProcessCommandBufferImpl virtual bool isGLES2Compliant(); + virtual bool setParentContext(WebGraphicsContext3D* parent_context); + virtual void reshape(int width, int height); virtual bool readBackFramebuffer(unsigned char* pixels, size_t buffer_size); diff --git a/webkit/gpu/webgraphicscontext3d_in_process_impl.cc b/webkit/gpu/webgraphicscontext3d_in_process_impl.cc index e7d5757..a729099 100644 --- a/webkit/gpu/webgraphicscontext3d_in_process_impl.cc +++ b/webkit/gpu/webgraphicscontext3d_in_process_impl.cc @@ -298,6 +298,11 @@ bool WebGraphicsContext3DInProcessImpl::isGLES2Compliant() { return is_gles2_; } +bool WebGraphicsContext3DInProcessImpl::setParentContext( + WebGraphicsContext3D* parent_context) { + return false; +} + WebGLId WebGraphicsContext3DInProcessImpl::getPlatformTextureId() { return texture_; } diff --git a/webkit/gpu/webgraphicscontext3d_in_process_impl.h b/webkit/gpu/webgraphicscontext3d_in_process_impl.h index aafff28..05bc06d 100644 --- a/webkit/gpu/webgraphicscontext3d_in_process_impl.h +++ b/webkit/gpu/webgraphicscontext3d_in_process_impl.h @@ -65,6 +65,8 @@ class WebGraphicsContext3DInProcessImpl : public WebGraphicsContext3D { virtual bool isGLES2Compliant(); + virtual bool setParentContext(WebGraphicsContext3D* parent_context); + virtual void reshape(int width, int height); virtual bool readBackFramebuffer(unsigned char* pixels, size_t bufferSize); |