From 591766b91bc6482d9a7d5505cb848f6ff972b86b Mon Sep 17 00:00:00 2001 From: "vangelis@chromium.org" Date: Wed, 30 Jun 2010 22:34:22 +0000 Subject: Parent the GL context used by WebGL to the GL context attached to the WebView (and used by the compositor) if gpu compositing is enabled. BUG=47870 TEST=none Review URL: http://codereview.chromium.org/2838031 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51302 0039d316-1c4b-4281-b951-d872f2087c98 --- .../webgraphicscontext3d_command_buffer_impl.cc | 30 ++++++++++++++++------ .../webgraphicscontext3d_command_buffer_impl.h | 3 --- 2 files changed, 22 insertions(+), 11 deletions(-) (limited to 'chrome/renderer') diff --git a/chrome/renderer/webgraphicscontext3d_command_buffer_impl.cc b/chrome/renderer/webgraphicscontext3d_command_buffer_impl.cc index 7501c2c..bffb690 100644 --- a/chrome/renderer/webgraphicscontext3d_command_buffer_impl.cc +++ b/chrome/renderer/webgraphicscontext3d_command_buffer_impl.cc @@ -10,9 +10,13 @@ #include +#include "base/command_line.h" #include "base/logging.h" +#include "chrome/common/chrome_switches.h" #include "chrome/renderer/gpu_channel_host.h" #include "chrome/renderer/render_thread.h" +#include "chrome/renderer/webgles2context_impl.h" +#include "third_party/WebKit/WebKit/chromium/public/WebView.h" WebGraphicsContext3DCommandBufferImpl::WebGraphicsContext3DCommandBufferImpl() : context_(NULL), @@ -28,16 +32,26 @@ WebGraphicsContext3DCommandBufferImpl:: } } -// TODO(vangelis): Properly implement this method once the upstream WebKit -// changes have landed. bool WebGraphicsContext3DCommandBufferImpl::initialize( WebGraphicsContext3D::Attributes attributes, - WebKit::WebView*) { - return initialize(attributes); -} + WebKit::WebView* web_view) { + bool compositing_enabled = CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableAcceleratedCompositing); + ggl::Context* parent_context = NULL; + // 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 GLES2Context 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::WebGLES2Context* view_gles2_context = web_view->gles2Context(); + if (!view_gles2_context) + return false; + WebGLES2ContextImpl* context_impl = + static_cast(view_gles2_context); + parent_context = context_impl->context(); + } -bool WebGraphicsContext3DCommandBufferImpl::initialize( - WebGraphicsContext3D::Attributes attributes) { RenderThread* render_thread = RenderThread::current(); if (!render_thread) return false; @@ -45,7 +59,7 @@ bool WebGraphicsContext3DCommandBufferImpl::initialize( if (!host) return false; DCHECK(host->ready()); - context_ = ggl::CreateOffscreenContext(host, NULL, gfx::Size(1, 1)); + context_ = ggl::CreateOffscreenContext(host, parent_context, gfx::Size(1, 1)); if (!context_) return false; // TODO(gman): Remove this. diff --git a/chrome/renderer/webgraphicscontext3d_command_buffer_impl.h b/chrome/renderer/webgraphicscontext3d_command_buffer_impl.h index 8c7f7b2..d1a7d2c 100644 --- a/chrome/renderer/webgraphicscontext3d_command_buffer_impl.h +++ b/chrome/renderer/webgraphicscontext3d_command_buffer_impl.h @@ -39,9 +39,6 @@ class WebGraphicsContext3DCommandBufferImpl //---------------------------------------------------------------------- // WebGraphicsContext3D methods - // TODO(vangelis): Remove this version of initialize() once the changes - // to WebGraphicsContext3D have been checked in upstream. - virtual bool initialize(WebGraphicsContext3D::Attributes attributes); virtual bool initialize(WebGraphicsContext3D::Attributes attributes, WebKit::WebView*); -- cgit v1.1