diff options
-rw-r--r-- | content/renderer/render_view_impl.cc | 2 | ||||
-rw-r--r-- | content/renderer/renderer_webkitplatformsupport_impl.cc | 2 | ||||
-rw-r--r-- | webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc | 31 | ||||
-rw-r--r-- | webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h | 10 | ||||
-rw-r--r-- | webkit/gpu/webgraphicscontext3d_in_process_impl.cc | 81 | ||||
-rw-r--r-- | webkit/gpu/webgraphicscontext3d_in_process_impl.h | 2 | ||||
-rw-r--r-- | webkit/support/test_webkit_platform_support.cc | 9 | ||||
-rw-r--r-- | webkit/support/webkit_support.cc | 8 | ||||
-rw-r--r-- | webkit/support/webkit_support.h | 1 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell_webkit_init.cc | 2 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_webview_delegate.cc | 4 |
11 files changed, 53 insertions, 99 deletions
diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc index 74af1c5..9b714c4 100644 --- a/content/renderer/render_view_impl.cc +++ b/content/renderer/render_view_impl.cc @@ -1535,7 +1535,7 @@ WebGraphicsContext3D* RenderViewImpl::createGraphicsContext3D( // debugging and bringing up new ports. if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessWebGL)) { return webkit::gpu::WebGraphicsContext3DInProcessImpl::CreateForWebView( - attributes, webview(), direct); + attributes, direct); } else { int surface = direct ? surface_id() : 0; diff --git a/content/renderer/renderer_webkitplatformsupport_impl.cc b/content/renderer/renderer_webkitplatformsupport_impl.cc index 2c1654a..66d15e6 100644 --- a/content/renderer/renderer_webkitplatformsupport_impl.cc +++ b/content/renderer/renderer_webkitplatformsupport_impl.cc @@ -589,7 +589,7 @@ RendererWebKitPlatformSupportImpl::createOffscreenGraphicsContext3D( // debugging and bringing up new ports. if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessWebGL)) { return webkit::gpu::WebGraphicsContext3DInProcessImpl::CreateForWebView( - attributes, NULL, false); + attributes, false); } else { base::WeakPtr<WebGraphicsContext3DSwapBuffersClient> null_client; scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context( diff --git a/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc b/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc index dd831da..a1f735b 100644 --- a/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc +++ b/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc @@ -102,7 +102,6 @@ class GLInProcessContext : public base::SupportsWeakPtr<GLInProcessContext> { GLInProcessContext* context_group, const char* allowed_extensions, const int32* attrib_list, - const GURL& active_url, gfx::GpuPreference gpu_preference); // For an offscreen frame buffer GLInProcessContext, return the texture ID @@ -151,7 +150,6 @@ class GLInProcessContext : public base::SupportsWeakPtr<GLInProcessContext> { GLInProcessContext* context_group, const char* allowed_extensions, const int32* attrib_list, - const GURL& active_url, gfx::GpuPreference gpu_preference); void Destroy(); @@ -220,7 +218,6 @@ GLInProcessContext* GLInProcessContext::CreateOffscreenContext( GLInProcessContext* context_group, const char* allowed_extensions, const int32* attrib_list, - const GURL& active_url, gfx::GpuPreference gpu_preference) { scoped_ptr<GLInProcessContext> context(new GLInProcessContext(parent)); if (!context->Initialize( @@ -228,7 +225,6 @@ GLInProcessContext* GLInProcessContext::CreateOffscreenContext( context_group, allowed_extensions, attrib_list, - active_url, gpu_preference)) return NULL; @@ -345,7 +341,6 @@ bool GLInProcessContext::Initialize(const gfx::Size& size, GLInProcessContext* context_group, const char* allowed_extensions, const int32* attrib_list, - const GURL& active_url, gfx::GpuPreference gpu_preference) { // Use one share group for all contexts. CR_DEFINE_STATIC_LOCAL(scoped_refptr<gfx::GLShareGroup>, share_group, @@ -512,7 +507,6 @@ WebGraphicsContext3DInProcessCommandBufferImpl:: WebGraphicsContext3DInProcessCommandBufferImpl() : context_(NULL), gl_(NULL), - web_view_(NULL), context_lost_callback_(NULL), context_lost_reason_(GL_NO_ERROR), cached_width_(0), @@ -526,10 +520,9 @@ WebGraphicsContext3DInProcessCommandBufferImpl:: g_all_shared_contexts.Pointer()->erase(this); } -bool WebGraphicsContext3DInProcessCommandBufferImpl::initialize( +bool WebGraphicsContext3DInProcessCommandBufferImpl::Initialize( WebGraphicsContext3D::Attributes attributes, - WebKit::WebView* web_view, - bool render_directly_to_web_view) { + WebKit::WebGraphicsContext3D* view_context) { // Convert WebGL context creation attributes into GLInProcessContext / EGL // size requests. const int alpha_size = attributes.alpha ? 8 : 0; @@ -555,20 +548,12 @@ bool WebGraphicsContext3DInProcessCommandBufferImpl::initialize( // discrete GPU is created, or the last one is destroyed. gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; - GURL active_url; - if (web_view && web_view->mainFrame()) - active_url = GURL(web_view->mainFrame()->document().url()); - GLInProcessContext* parent_context = NULL; - if (!render_directly_to_web_view) { - WebKit::WebGraphicsContext3D* view_context = - web_view ? web_view->graphicsContext3D() : NULL; - if (view_context) { - WebGraphicsContext3DInProcessCommandBufferImpl* context_impl = - static_cast<WebGraphicsContext3DInProcessCommandBufferImpl*>( - view_context); - parent_context = context_impl->context_; - } + if (view_context) { + WebGraphicsContext3DInProcessCommandBufferImpl* context_impl = + static_cast<WebGraphicsContext3DInProcessCommandBufferImpl*>( + view_context); + parent_context = context_impl->context_; } WebGraphicsContext3DInProcessCommandBufferImpl* context_group = NULL; @@ -583,9 +568,7 @@ bool WebGraphicsContext3DInProcessCommandBufferImpl::initialize( context_group ? context_group->context_ : NULL, preferred_extensions, attribs, - active_url, gpu_preference); - web_view_ = NULL; if (!context_) return false; diff --git a/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h b/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h index d3e0641..fcce88b 100644 --- a/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h +++ b/webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h @@ -13,7 +13,6 @@ #include "base/memory/scoped_ptr.h" #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsContext3D.h" #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" #include "ui/gfx/native_widget_types.h" #if defined(USE_SKIA) @@ -52,12 +51,11 @@ class WebGraphicsContext3DInProcessCommandBufferImpl WebGraphicsContext3DInProcessCommandBufferImpl(); virtual ~WebGraphicsContext3DInProcessCommandBufferImpl(); + bool Initialize(WebKit::WebGraphicsContext3D::Attributes attributes, + WebKit::WebGraphicsContext3D* view_context); + //---------------------------------------------------------------------- // WebGraphicsContext3D methods - virtual bool initialize(WebGraphicsContext3D::Attributes attributes, - WebKit::WebView*, - bool renderDirectlyToWebView); - virtual bool makeContextCurrent(); virtual int width(); @@ -482,8 +480,6 @@ class WebGraphicsContext3DInProcessCommandBufferImpl // The GLES2Implementation we use for OpenGL rendering. ::gpu::gles2::GLES2Implementation* gl_; - // If rendering directly to WebView, weak pointer to it. - WebKit::WebView* web_view_; WebGraphicsContext3D::WebGraphicsContextLostCallback* context_lost_callback_; WGC3Denum context_lost_reason_; diff --git a/webkit/gpu/webgraphicscontext3d_in_process_impl.cc b/webkit/gpu/webgraphicscontext3d_in_process_impl.cc index 60d7781..8f50137 100644 --- a/webkit/gpu/webgraphicscontext3d_in_process_impl.cc +++ b/webkit/gpu/webgraphicscontext3d_in_process_impl.cc @@ -9,9 +9,11 @@ #include <algorithm> #include <string> +#include "base/lazy_instance.h" #include "base/logging.h" #include "base/string_split.h" #include "base/memory/scoped_ptr.h" +#include "base/synchronization/lock.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" @@ -72,7 +74,17 @@ WebGraphicsContext3DInProcessImpl::WebGraphicsContext3DInProcessImpl( vertex_compiler_(0) { } +// All instances in a process that share resources are in the same share group. +static base::LazyInstance< + std::set<WebGraphicsContext3DInProcessImpl*> > + g_all_shared_contexts = LAZY_INSTANCE_INITIALIZER; +static base::LazyInstance<base::Lock>::Leaky + g_all_shared_contexts_lock = LAZY_INSTANCE_INITIALIZER; + WebGraphicsContext3DInProcessImpl::~WebGraphicsContext3DInProcessImpl() { + base::AutoLock a(g_all_shared_contexts_lock.Get()); + g_all_shared_contexts.Pointer()->erase(this); + if (!initialized_) return; @@ -109,27 +121,17 @@ WebGraphicsContext3DInProcessImpl::~WebGraphicsContext3DInProcessImpl() { WebGraphicsContext3DInProcessImpl* WebGraphicsContext3DInProcessImpl::CreateForWebView( WebGraphicsContext3D::Attributes attributes, - WebView* web_view, bool render_directly_to_web_view) { if (!gfx::GLSurface::InitializeOneOff()) return NULL; - bool is_gles2 = gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2; gfx::GLShareGroup* share_group = 0; - if (!render_directly_to_web_view) { - // Pick up the compositor's context to share resources with. - WebGraphicsContext3D* view_context = web_view ? - web_view->graphicsContext3D() : NULL; - if (view_context) { - WebGraphicsContext3DInProcessImpl* contextImpl = - static_cast<WebGraphicsContext3DInProcessImpl*>(view_context); - share_group = contextImpl->gl_context_->share_group(); - } else { - // The compositor's context didn't get created - // successfully, so conceptually there is no way we can - // render successfully to the WebView. - render_directly_to_web_view = false; - } + + if (attributes.shareResources) { + WebGraphicsContext3DInProcessImpl* context_impl = + g_all_shared_contexts.Pointer()->empty() ? + NULL : *g_all_shared_contexts.Pointer()->begin(); + share_group = context_impl->gl_context_->share_group(); } // This implementation always renders offscreen regardless of whether @@ -140,24 +142,8 @@ WebGraphicsContext3DInProcessImpl::CreateForWebView( scoped_refptr<gfx::GLSurface> gl_surface = gfx::GLSurface::CreateOffscreenGLSurface(false, gfx::Size(1, 1)); - if (!gl_surface.get()) { - if (!is_gles2) - return NULL; - - // 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. - if (web_view) web_view->mainFrame()->collectGarbage(); - - gl_surface = gfx::GLSurface::CreateOffscreenGLSurface(false, - gfx::Size(1, 1)); - if (!gl_surface.get()) - return NULL; - } + if (!gl_surface.get()) + return NULL; // TODO(kbr): This implementation doesn't yet support lost contexts // and therefore can't yet properly support GPU switching. @@ -168,26 +154,9 @@ WebGraphicsContext3DInProcessImpl::CreateForWebView( gl_surface.get(), gpu_preference); - if (!gl_context.get()) { - if (!is_gles2) - return NULL; - - // 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. - if (web_view) - web_view->mainFrame()->collectGarbage(); - - gl_context = gfx::GLContext::CreateGLContext(share_group, - gl_surface.get(), - gpu_preference); - if (!gl_context.get()) - return NULL; - } + if (!gl_context.get()) + return NULL; + scoped_ptr<WebGraphicsContext3DInProcessImpl> context( new WebGraphicsContext3DInProcessImpl( gl_surface.get(), gl_context.get(), render_directly_to_web_view)); @@ -272,6 +241,10 @@ bool WebGraphicsContext3DInProcessImpl::Initialize( initialized_ = true; gl_context_->ReleaseCurrent(gl_surface_.get()); + + if (attributes_.shareResources) + g_all_shared_contexts.Pointer()->insert(this); + return true; } diff --git a/webkit/gpu/webgraphicscontext3d_in_process_impl.h b/webkit/gpu/webgraphicscontext3d_in_process_impl.h index 574ced0..37d9e15e 100644 --- a/webkit/gpu/webgraphicscontext3d_in_process_impl.h +++ b/webkit/gpu/webgraphicscontext3d_in_process_impl.h @@ -39,7 +39,6 @@ using WebKit::WGC3Dsizeiptr; using WebKit::WebGLId; using WebKit::WebString; -using WebKit::WebView; using WebKit::WebGraphicsContext3D; @@ -63,7 +62,6 @@ class WebGraphicsContext3DInProcessImpl : public WebGraphicsContext3D { virtual ~WebGraphicsContext3DInProcessImpl(); static WebGraphicsContext3DInProcessImpl* CreateForWebView( WebGraphicsContext3D::Attributes attributes, - WebView* web_view, bool render_directly_to_webview); static WebGraphicsContext3DInProcessImpl* CreateForWindow( WebGraphicsContext3D::Attributes attributes, diff --git a/webkit/support/test_webkit_platform_support.cc b/webkit/support/test_webkit_platform_support.cc index f811083..65db137 100644 --- a/webkit/support/test_webkit_platform_support.cc +++ b/webkit/support/test_webkit_platform_support.cc @@ -379,11 +379,12 @@ TestWebKitPlatformSupport::createOffscreenGraphicsContext3D( switch (webkit_support::GetGraphicsContext3DImplementation()) { case webkit_support::IN_PROCESS: return webkit::gpu::WebGraphicsContext3DInProcessImpl::CreateForWebView( - attributes, NULL, false); + attributes, false); case webkit_support::IN_PROCESS_COMMAND_BUFFER: { - scoped_ptr<WebKit::WebGraphicsContext3D> context( - new webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl()); - if (!context->initialize(attributes, NULL, false)) + scoped_ptr<webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl> + context(new + webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl()); + if (!context->Initialize(attributes, NULL)) return NULL; return context.release(); } diff --git a/webkit/support/webkit_support.cc b/webkit/support/webkit_support.cc index db6be26..36ab596 100644 --- a/webkit/support/webkit_support.cc +++ b/webkit/support/webkit_support.cc @@ -38,6 +38,7 @@ #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLError.h" #if defined(TOOLKIT_USES_GTK) #include "ui/base/keycodes/keyboard_code_conversion_gtk.h" @@ -384,11 +385,14 @@ WebKit::WebGraphicsContext3D* CreateGraphicsContext3D( switch (webkit_support::GetGraphicsContext3DImplementation()) { case webkit_support::IN_PROCESS: return WebGraphicsContext3DInProcessImpl::CreateForWebView( - attributes, web_view, direct); + attributes, direct); case webkit_support::IN_PROCESS_COMMAND_BUFFER: { + WebKit::WebGraphicsContext3D* view_context = 0; + if (!direct) + view_context = web_view->graphicsContext3D(); scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context( new WebGraphicsContext3DInProcessCommandBufferImpl()); - if (!context->initialize(attributes, web_view, direct)) + if (!context->Initialize(attributes, view_context)) return NULL; return context.release(); } diff --git a/webkit/support/webkit_support.h b/webkit/support/webkit_support.h index 84b65a3..567b89a 100644 --- a/webkit/support/webkit_support.h +++ b/webkit/support/webkit_support.h @@ -29,6 +29,7 @@ class WebThemeEngine; class WebURL; class WebURLRequest; class WebURLResponse; +class WebView; struct WebPluginParams; struct WebURLError; } diff --git a/webkit/tools/test_shell/test_shell_webkit_init.cc b/webkit/tools/test_shell/test_shell_webkit_init.cc index 5fd7761..5ae9083 100644 --- a/webkit/tools/test_shell/test_shell_webkit_init.cc +++ b/webkit/tools/test_shell/test_shell_webkit_init.cc @@ -304,7 +304,7 @@ WebKit::WebGraphicsContext3D* TestShellWebKitInit::createOffscreenGraphicsContext3D( const WebKit::WebGraphicsContext3D::Attributes& attributes) { return webkit::gpu::WebGraphicsContext3DInProcessImpl::CreateForWebView( - attributes, NULL, false); + attributes, false); } void TestShellWebKitInit::GetPlugins( diff --git a/webkit/tools/test_shell/test_webview_delegate.cc b/webkit/tools/test_shell/test_webview_delegate.cc index 5baf744..1bafbae 100644 --- a/webkit/tools/test_shell/test_webview_delegate.cc +++ b/webkit/tools/test_shell/test_webview_delegate.cc @@ -341,10 +341,8 @@ WebStorageNamespace* TestWebViewDelegate::createSessionStorageNamespace( WebGraphicsContext3D* TestWebViewDelegate::createGraphicsContext3D( const WebGraphicsContext3D::Attributes& attributes, bool direct) { - if (!shell_->webView()) - return NULL; return webkit::gpu::WebGraphicsContext3DInProcessImpl::CreateForWebView( - attributes, shell_->webView(), direct); + attributes, direct); } void TestWebViewDelegate::didAddMessageToConsole( |