Chromium Code Reviews| Index: content/plugin/webplugin_accelerated_surface_proxy_mac.cc |
| =================================================================== |
| --- content/plugin/webplugin_accelerated_surface_proxy_mac.cc (revision 111400) |
| +++ content/plugin/webplugin_accelerated_surface_proxy_mac.cc (working copy) |
| @@ -7,32 +7,55 @@ |
| #include "content/plugin/webplugin_accelerated_surface_proxy_mac.h" |
| #include "base/bind.h" |
| +#include "base/command_line.h" |
| #include "content/plugin/webplugin_proxy.h" |
| +#include "content/public/common/content_switches.h" |
| #include "ui/gfx/surface/accelerated_surface_mac.h" |
| +#include "ui/gfx/surface/io_surface_support_mac.h" |
| #include "ui/gfx/surface/transport_dib.h" |
| -WebPluginAcceleratedSurfaceProxy::WebPluginAcceleratedSurfaceProxy( |
| +WebPluginAcceleratedSurfaceProxy* WebPluginAcceleratedSurfaceProxy::Create( |
| WebPluginProxy* plugin_proxy, |
| - gfx::GpuPreference gpu_preference) |
| - : plugin_proxy_(plugin_proxy), |
| - window_handle_(NULL) { |
| - surface_ = new AcceleratedSurface; |
| - // It's possible for OpenGL to fail to initialze (e.g., if an incompatible |
| + gfx::GpuPreference gpu_preference) { |
| + bool composited = !CommandLine::ForCurrentProcess()->HasSwitch( |
| + switches::kDisableCompositedCoreAnimationPlugins); |
| + |
| + // Require IOSurface support for drawing Core Animation plugins. |
| + if (composited && !IOSurfaceSupport::Initialize()) |
| + return NULL; |
| + |
| + AcceleratedSurface* surface = new AcceleratedSurface; |
| + // It's possible for OpenGL to fail to initialize (e.g., if an incompatible |
| // mode is forced via flags), so handle that gracefully. |
| - if (!surface_->Initialize(NULL, true, gpu_preference)) { |
| - delete surface_; |
| - surface_ = NULL; |
| - return; |
| + if (!surface->Initialize(NULL, true, gpu_preference)) { |
| + delete surface; |
| + surface = NULL; |
| + if (composited) |
|
stuartmorgan
2011/11/28 10:09:04
So if !composited, failure to create a surface ret
Ken Russell (switch to Gerrit)
2011/11/28 23:40:15
That's the way the current code path works and I t
|
| + return NULL; |
| } |
| - // Only used for 10.5 support, but harmless on 10.6+. |
| - surface_->SetTransportDIBAllocAndFree( |
| - base::Bind(&WebPluginProxy::AllocSurfaceDIB, |
| - base::Unretained(plugin_proxy)), |
| - base::Bind(&WebPluginProxy::FreeSurfaceDIB, |
| - base::Unretained(plugin_proxy))); |
| + if (!composited && surface) { |
| + // Only used for 10.5 support, but harmless on 10.6+. |
| + surface->SetTransportDIBAllocAndFree( |
| + base::Bind(&WebPluginProxy::AllocSurfaceDIB, |
| + base::Unretained(plugin_proxy)), |
| + base::Bind(&WebPluginProxy::FreeSurfaceDIB, |
| + base::Unretained(plugin_proxy))); |
| + } |
| + |
| + return new WebPluginAcceleratedSurfaceProxy( |
| + plugin_proxy, surface, composited); |
| } |
| +WebPluginAcceleratedSurfaceProxy::WebPluginAcceleratedSurfaceProxy( |
| + WebPluginProxy* plugin_proxy, |
| + AcceleratedSurface* surface, |
| + bool composited) |
| + : plugin_proxy_(plugin_proxy), |
| + surface_(surface), |
| + composited_(composited) { |
| +} |
| + |
| WebPluginAcceleratedSurfaceProxy::~WebPluginAcceleratedSurfaceProxy() { |
| if (surface_) { |
| surface_->Destroy(); |
| @@ -46,17 +69,28 @@ |
| window_handle_ = window; |
| } |
| +bool WebPluginAcceleratedSurfaceProxy::IsComposited() { |
| + return composited_; |
| +} |
| + |
| 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); |
| + if (composited_) { |
| + uint32 io_surface_id = surface_->SetSurfaceSize(size); |
| + // If allocation fails for some reason, still inform the plugin proxy. |
| + plugin_proxy_->AcceleratedPluginAllocatedIOSurface( |
| + size.width(), size.height(), io_surface_id); |
| } else { |
| - TransportDIB::Handle transport_dib = surface_->SetTransportDIBSize(size); |
| - if (TransportDIB::is_valid_handle(transport_dib)) { |
| - plugin_proxy_->SetAcceleratedDIB(window_handle_, size, transport_dib); |
| + uint32 io_surface_id = surface_->SetSurfaceSize(size); |
| + if (io_surface_id) { |
| + plugin_proxy_->SetAcceleratedSurface(window_handle_, size, io_surface_id); |
| + } else { |
| + TransportDIB::Handle transport_dib = surface_->SetTransportDIBSize(size); |
| + if (TransportDIB::is_valid_handle(transport_dib)) { |
| + plugin_proxy_->SetAcceleratedDIB(window_handle_, size, transport_dib); |
| + } |
| } |
| } |
| } |
| @@ -78,6 +112,10 @@ |
| return; |
| surface_->SwapBuffers(); |
| - plugin_proxy_->AcceleratedFrameBuffersDidSwap( |
| - window_handle_, surface_->GetSurfaceId()); |
| + if (composited_) { |
| + plugin_proxy_->AcceleratedPluginSwappedIOSurface(); |
| + } else { |
| + plugin_proxy_->AcceleratedFrameBuffersDidSwap( |
| + window_handle_, surface_->GetSurfaceId()); |
| + } |
| } |