diff options
author | stuartmorgan@chromium.org <stuartmorgan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-22 22:49:34 +0000 |
---|---|---|
committer | stuartmorgan@chromium.org <stuartmorgan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-22 22:49:34 +0000 |
commit | d92bec4353b077c5fef2d77d13ba7b3ae5e1d248 (patch) | |
tree | 0465e1ca7e24b75d17c23bea9c929ada64e54484 | |
parent | 921720c8059acd219da442611d226330d9537083 (diff) | |
download | chromium_src-d92bec4353b077c5fef2d77d13ba7b3ae5e1d248.zip chromium_src-d92bec4353b077c5fef2d77d13ba7b3ae5e1d248.tar.gz chromium_src-d92bec4353b077c5fef2d77d13ba7b3ae5e1d248.tar.bz2 |
Make accelerated Mac plugins handle GL initialization failure instead of crashing
BUG=62565
TEST=Run with --use-gl=osmesa on 10.6, and open a YouTube video. The plugin should not crash, and audion should still play (but without video).
Review URL: http://codereview.chromium.org/5233005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@67016 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/plugin/webplugin_accelerated_surface_proxy_mac.cc | 19 | ||||
-rw-r--r-- | webkit/glue/plugins/webplugin_accelerated_surface_mac.h | 1 | ||||
-rw-r--r-- | webkit/glue/plugins/webplugin_delegate_impl_mac.mm | 13 |
3 files changed, 27 insertions, 6 deletions
diff --git a/chrome/plugin/webplugin_accelerated_surface_proxy_mac.cc b/chrome/plugin/webplugin_accelerated_surface_proxy_mac.cc index 6e3540e..9dcacb9 100644 --- a/chrome/plugin/webplugin_accelerated_surface_proxy_mac.cc +++ b/chrome/plugin/webplugin_accelerated_surface_proxy_mac.cc @@ -15,7 +15,13 @@ WebPluginAcceleratedSurfaceProxy::WebPluginAcceleratedSurfaceProxy( : plugin_proxy_(plugin_proxy), window_handle_(NULL) { surface_ = new AcceleratedSurface; - surface_->Initialize(NULL, true); + // It's possible for OpenGL to fail to initialze (e.g., if an incompatible + // mode is forced via flags), so handle that gracefully. + if (!surface_->Initialize(NULL, true)) { + delete surface_; + surface_ = NULL; + return; + } // Only used for 10.5 support, but harmless on 10.6+. surface_->SetTransportDIBAllocAndFree( @@ -37,6 +43,9 @@ void WebPluginAcceleratedSurfaceProxy::SetWindowHandle( } void WebPluginAcceleratedSurfaceProxy::SetSize(const gfx::Size& size) { + if (!surface_) + return; + uint64 io_surface_id = surface_->SetSurfaceSize(size); if (io_surface_id) { plugin_proxy_->SetAcceleratedSurface(window_handle_, size, io_surface_id); @@ -49,15 +58,21 @@ void WebPluginAcceleratedSurfaceProxy::SetSize(const gfx::Size& size) { } CGLContextObj WebPluginAcceleratedSurfaceProxy::context() { - return surface_->context(); + return surface_ ? surface_->context() : NULL; } void WebPluginAcceleratedSurfaceProxy::StartDrawing() { + if (!surface_) + return; + surface_->MakeCurrent(); surface_->Clear(gfx::Rect(surface_->GetSize())); } void WebPluginAcceleratedSurfaceProxy::EndDrawing() { + if (!surface_) + return; + surface_->SwapBuffers(); plugin_proxy_->AcceleratedFrameBuffersDidSwap( window_handle_, surface_->GetSurfaceId()); diff --git a/webkit/glue/plugins/webplugin_accelerated_surface_mac.h b/webkit/glue/plugins/webplugin_accelerated_surface_mac.h index ba3f8ca..13980ca 100644 --- a/webkit/glue/plugins/webplugin_accelerated_surface_mac.h +++ b/webkit/glue/plugins/webplugin_accelerated_surface_mac.h @@ -28,6 +28,7 @@ class WebPluginAcceleratedSurface { virtual void SetSize(const gfx::Size& size) = 0; // Returns the context used to draw into this surface. + // If initializing the surface failed, this will be NULL. virtual CGLContextObj context() = 0; // Readies the surface for drawing. Must be called before any drawing session. diff --git a/webkit/glue/plugins/webplugin_delegate_impl_mac.mm b/webkit/glue/plugins/webplugin_delegate_impl_mac.mm index 33747d9..7b0cb7a 100644 --- a/webkit/glue/plugins/webplugin_delegate_impl_mac.mm +++ b/webkit/glue/plugins/webplugin_delegate_impl_mac.mm @@ -376,9 +376,14 @@ bool WebPluginDelegateImpl::PlatformInitialize() { layer_ = layer; surface_ = plugin_->GetAcceleratedSurface(); - renderer_ = [[CARenderer rendererWithCGLContext:surface_->context() - options:NULL] retain]; - [renderer_ setLayer:layer_]; + // If surface initialization fails for some reason, just continue + // without any drawing; returning false would be a more confusing user + // experience (since it triggers a missing plugin placeholder). + if (surface_->context()) { + renderer_ = [[CARenderer rendererWithCGLContext:surface_->context() + options:NULL] retain]; + [renderer_ setLayer:layer_]; + } plugin_->BindFakePluginWindowHandle(false); } break; @@ -978,7 +983,7 @@ void WebPluginDelegateImpl::SetImeEnabled(bool enabled) { void WebPluginDelegateImpl::DrawLayerInSurface() { // If we haven't plumbed up the surface yet, don't try to draw. - if (!windowed_handle()) + if (!windowed_handle() || !renderer_) return; [renderer_ beginFrameAtTime:CACurrentMediaTime() timeStamp:NULL]; |