diff options
author | piman@chromium.org <piman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-17 21:57:51 +0000 |
---|---|---|
committer | piman@chromium.org <piman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-17 21:57:51 +0000 |
commit | a2ad0a8f6d5cb023206426cb1e9fb29ea8eb774c (patch) | |
tree | 1e8281c2e86f3077c5a018d96e5a2b8b2fe0a8b4 /webkit/plugins | |
parent | fe50512cd915b9d48237c940658ac7bbe7a088e5 (diff) | |
download | chromium_src-a2ad0a8f6d5cb023206426cb1e9fb29ea8eb774c.zip chromium_src-a2ad0a8f6d5cb023206426cb1e9fb29ea8eb774c.tar.gz chromium_src-a2ad0a8f6d5cb023206426cb1e9fb29ea8eb774c.tar.bz2 |
plugins: use new WebPluginContainer::setWebLayer API for compositing.
BUG=164095
Review URL: https://chromiumcodereview.appspot.com/11567054
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@173545 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/plugins')
-rw-r--r-- | webkit/plugins/npapi/webplugin_impl.cc | 47 | ||||
-rw-r--r-- | webkit/plugins/npapi/webplugin_impl.h | 8 | ||||
-rw-r--r-- | webkit/plugins/ppapi/plugin_delegate.h | 7 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppapi_plugin_instance.cc | 97 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppapi_plugin_instance.h | 34 |
5 files changed, 123 insertions, 70 deletions
diff --git a/webkit/plugins/npapi/webplugin_impl.cc b/webkit/plugins/npapi/webplugin_impl.cc index 702e373..23a8349 100644 --- a/webkit/plugins/npapi/webplugin_impl.cc +++ b/webkit/plugins/npapi/webplugin_impl.cc @@ -12,6 +12,7 @@ #include "base/stringprintf.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" +#include "cc/io_surface_layer.h" #include "googleurl/src/gurl.h" #include "googleurl/src/url_util.h" #include "net/base/escape.h" @@ -41,6 +42,7 @@ #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" #include "ui/gfx/rect.h" #include "webkit/appcache/web_application_cache_host_impl.h" +#include "webkit/compositor_bindings/web_layer_impl.h" #include "webkit/glue/multipart_response_delegate.h" #include "webkit/plugins/npapi/plugin_host.h" #include "webkit/plugins/npapi/plugin_instance.h" @@ -787,21 +789,34 @@ void WebPluginImpl::AcceleratedPluginAllocatedIOSurface(int32 width, } void WebPluginImpl::AcceleratedPluginSwappedIOSurface() { - if (container_) { - // Deferring the call to setBackingIOSurfaceId is an attempt to - // work around garbage occasionally showing up in the plugin's - // area during live resizing of Core Animation plugins. The - // assumption was that by the time this was called, the plugin - // process would have populated the newly allocated IOSurface. It - // is not 100% clear at this point why any garbage is getting - // through. More investigation is needed. http://crbug.com/105346 - if (next_io_surface_allocated_) { - container_->setBackingIOSurfaceId(next_io_surface_width_, - next_io_surface_height_, - next_io_surface_id_); - next_io_surface_allocated_ = false; + if (!container_) + return; + // Deferring the call to setBackingIOSurfaceId is an attempt to + // work around garbage occasionally showing up in the plugin's + // area during live resizing of Core Animation plugins. The + // assumption was that by the time this was called, the plugin + // process would have populated the newly allocated IOSurface. It + // is not 100% clear at this point why any garbage is getting + // through. More investigation is needed. http://crbug.com/105346 + if (next_io_surface_allocated_) { + if (next_io_surface_id_) { + if (!io_surface_layer_.get()) { + io_surface_layer_ = cc::IOSurfaceLayer::create(); + web_layer_.reset(new WebKit::WebLayerImpl(io_surface_layer_)); + container_->setWebLayer(web_layer_.get()); + } + io_surface_layer_->setIOSurfaceProperties( + next_io_surface_id_, + gfx::Size(next_io_surface_width_, next_io_surface_height_)); + } else { + container_->setWebLayer(NULL); + web_layer_.reset(); + io_surface_layer_ = NULL; } - container_->commitBackingTexture(); + next_io_surface_allocated_ = false; + } else { + if (io_surface_layer_) + io_surface_layer_->setNeedsDisplay(); } } #endif @@ -1391,8 +1406,10 @@ void WebPluginImpl::TearDownPluginInstance( // The container maintains a list of JSObjects which are related to this // plugin. Tell the frame we're gone so that it can invalidate all of // those sub JSObjects. - if (container_) + if (container_) { container_->clearScriptObjects(); + container_->setWebLayer(NULL); + } if (delegate_) { // Call PluginDestroyed() first to prevent the plugin from calling us back diff --git a/webkit/plugins/npapi/webplugin_impl.h b/webkit/plugins/npapi/webplugin_impl.h index 682bfd5..f940ff0 100644 --- a/webkit/plugins/npapi/webplugin_impl.h +++ b/webkit/plugins/npapi/webplugin_impl.h @@ -11,6 +11,7 @@ #include "base/basictypes.h" #include "base/file_path.h" +#include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "googleurl/src/gurl.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h" @@ -23,8 +24,13 @@ #include "webkit/plugins/npapi/webplugin.h" #include "webkit/plugins/webkit_plugins_export.h" +namespace cc { +class IOSurfaceLayer; +} + namespace WebKit { class WebFrame; +class WebLayer; class WebPluginContainer; class WebURLResponse; class WebURLLoader; @@ -274,6 +280,8 @@ class WEBKIT_PLUGINS_EXPORT WebPluginImpl : int32 next_io_surface_width_; int32 next_io_surface_height_; uint32 next_io_surface_id_; + scoped_refptr<cc::IOSurfaceLayer> io_surface_layer_; + scoped_ptr<WebKit::WebLayer> web_layer_; #endif bool accepts_input_events_; base::WeakPtr<WebPluginPageDelegate> page_delegate_; diff --git a/webkit/plugins/ppapi/plugin_delegate.h b/webkit/plugins/ppapi/plugin_delegate.h index 695b0f7..9c22ce9 100644 --- a/webkit/plugins/ppapi/plugin_delegate.h +++ b/webkit/plugins/ppapi/plugin_delegate.h @@ -40,6 +40,10 @@ class TransportDIB; struct PP_HostResolver_Private_Hint; struct PP_NetAddress_Private; +namespace WebKit { +class WebGraphicsContext3D; +} + namespace base { class MessageLoopProxy; class Time; @@ -209,6 +213,9 @@ class PluginDelegate { // compositors namespace. Otherwise return 0. Returns 0 by default. virtual unsigned GetBackingTextureId() = 0; + // Returns the parent context that allocated the backing texture ID. + virtual WebKit::WebGraphicsContext3D* GetParentContext() = 0; + // Returns true if the backing texture is always opaque. virtual bool IsOpaque() = 0; diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc index 7e5b8d8..83145f1 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc @@ -15,6 +15,7 @@ #include "base/time.h" #include "base/utf_offset_string_conversions.h" #include "base/utf_string_conversions.h" +#include "cc/texture_layer.h" #include "ppapi/c/dev/ppb_find_dev.h" #include "ppapi/c/dev/ppb_zoom_dev.h" #include "ppapi/c/dev/ppp_find_dev.h" @@ -65,6 +66,7 @@ #include "ui/base/range/range.h" #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" #include "ui/gfx/rect_conversions.h" +#include "webkit/compositor_bindings/web_layer_impl.h" #include "webkit/plugins/plugin_constants.h" #include "webkit/plugins/ppapi/common.h" #include "webkit/plugins/ppapi/content_decryptor_delegate.h" @@ -454,6 +456,8 @@ void PluginInstance::Delete() { fullscreen_container_->Destroy(); fullscreen_container_ = NULL; } + bound_graphics_3d_ = NULL; + UpdateLayer(); container_ = NULL; } @@ -508,8 +512,8 @@ void PluginInstance::ScrollRect(int dx, int dy, const gfx::Rect& rect) { } unsigned PluginInstance::GetBackingTextureId() { - if (GetBoundGraphics3D()) - return GetBoundGraphics3D()->GetBackingTextureId(); + if (bound_graphics_3d_.get()) + return bound_graphics_3d_->GetBackingTextureId(); return 0; } @@ -517,8 +521,8 @@ unsigned PluginInstance::GetBackingTextureId() { void PluginInstance::CommitBackingTexture() { if (fullscreen_container_) fullscreen_container_->Invalidate(); - else if (container_) - container_->commitBackingTexture(); + else if (texture_layer_) + texture_layer_->setNeedsDisplay(); } void PluginInstance::InstanceCrashed() { @@ -912,15 +916,15 @@ void PluginInstance::PageVisibilityChanged(bool is_visible) { void PluginInstance::ViewWillInitiatePaint() { if (GetBoundGraphics2D()) GetBoundGraphics2D()->ViewWillInitiatePaint(); - else if (GetBoundGraphics3D()) - GetBoundGraphics3D()->ViewWillInitiatePaint(); + else if (bound_graphics_3d_.get()) + bound_graphics_3d_->ViewWillInitiatePaint(); } void PluginInstance::ViewInitiatedPaint() { if (GetBoundGraphics2D()) GetBoundGraphics2D()->ViewInitiatedPaint(); - else if (GetBoundGraphics3D()) - GetBoundGraphics3D()->ViewInitiatedPaint(); + else if (bound_graphics_3d_.get()) + bound_graphics_3d_->ViewInitiatedPaint(); } void PluginInstance::ViewFlushedPaint() { @@ -928,8 +932,8 @@ void PluginInstance::ViewFlushedPaint() { scoped_refptr<PluginInstance> ref(this); if (GetBoundGraphics2D()) GetBoundGraphics2D()->ViewFlushedPaint(); - else if (GetBoundGraphics3D()) - GetBoundGraphics3D()->ViewFlushedPaint(); + else if (bound_graphics_3d_.get()) + bound_graphics_3d_->ViewFlushedPaint(); } bool PluginInstance::GetBitmapForOptimizedPluginPaint( @@ -1466,8 +1470,8 @@ void PluginInstance::FlashSetFullscreen(bool fullscreen, bool delay_report) { VLOG(1) << "Setting fullscreen to " << (fullscreen ? "on" : "off"); if (fullscreen) { DCHECK(!fullscreen_container_); - setBackingTextureId(0, false); fullscreen_container_ = delegate_->CreateFullscreenContainer(this); + UpdateLayer(); } else { DCHECK(fullscreen_container_); fullscreen_container_->Destroy(); @@ -1492,15 +1496,14 @@ void PluginInstance::UpdateFlashFullscreenState(bool flash_fullscreen) { return; } - PPB_Graphics3D_Impl* graphics_3d = GetBoundGraphics3D(); + PPB_Graphics3D_Impl* graphics_3d = bound_graphics_3d_.get(); if (graphics_3d) { if (flash_fullscreen) { fullscreen_container_->ReparentContext(graphics_3d->platform_context()); } else { delegate_->ReparentContext(graphics_3d->platform_context()); - setBackingTextureId(graphics_3d->GetBackingTextureId(), - graphics_3d->IsOpaque()); } + UpdateLayer(); } bool old_plugin_focus = PluginHasFocus(); @@ -1710,28 +1713,30 @@ PluginDelegate::PlatformGraphics2D* PluginInstance::GetBoundGraphics2D() const { return bound_graphics_2d_platform_; } -PPB_Graphics3D_Impl* PluginInstance::GetBoundGraphics3D() const { - if (bound_graphics_3d_.get() == NULL) - return NULL; - return static_cast<PPB_Graphics3D_Impl*>(bound_graphics_3d_.get()); -} +void PluginInstance::UpdateLayer() { + if (!container_) + return; -void PluginInstance::setBackingTextureId(unsigned int id, bool is_opaque) { - // If we have a fullscreen_container_ (under PPB_FlashFullscreen) - // or desired_fullscreen_state is true (under PPB_Fullscreen), - // then the plugin is fullscreen or transitioning to fullscreen - // and the parent context is not the one for the browser page, - // but for the fullscreen window, and so the parent texture ID - // doesn't correspond to anything in the page's context. - // - // TODO(alokp): It would be better at some point to have the equivalent - // in the FullscreenContainer so that we don't need to poll - if (fullscreen_container_ || desired_fullscreen_state_) + // If we have a fullscreen_container_ (under PPB_FlashFullscreen) then the + // plugin is fullscreen (for Flash) or transitioning to fullscreen. In either + // case we do not want a layer. + bool want_layer = GetBackingTextureId() && !fullscreen_container_; + + if (want_layer == !!texture_layer_.get()) return; - if (container_) { - container_->setBackingTextureId(id); - container_->setOpaque(is_opaque); + if (!want_layer) { + texture_layer_->willModifyTexture(); + texture_layer_->clearClient(); + container_->setWebLayer(NULL); + web_layer_.reset(); + texture_layer_ = NULL; + } else { + DCHECK(bound_graphics_3d_.get()); + texture_layer_ = cc::TextureLayer::create(this); + web_layer_.reset(new WebKit::WebLayerImpl(texture_layer_)); + container_->setWebLayer(web_layer_.get()); + texture_layer_->setContentsOpaque(bound_graphics_3d_->IsOpaque()); } } @@ -1873,12 +1878,10 @@ PP_Bool PluginInstance::BindGraphics(PP_Instance instance, PP_Resource device) { TRACE_EVENT0("ppapi", "PluginInstance::BindGraphics"); // The Graphics3D instance can't be destroyed until we call - // setBackingTextureId. - scoped_refptr< ::ppapi::Resource> old_graphics = bound_graphics_3d_; + // UpdateLayer(). + scoped_refptr< ::ppapi::Resource> old_graphics = bound_graphics_3d_.get(); if (bound_graphics_3d_.get()) { - if (GetBoundGraphics3D()) { - GetBoundGraphics3D()->BindToInstance(false); - } + bound_graphics_3d_->BindToInstance(false); bound_graphics_3d_ = NULL; } if (bound_graphics_2d_platform_) { @@ -1888,7 +1891,7 @@ PP_Bool PluginInstance::BindGraphics(PP_Instance instance, // Special-case clearing the current device. if (!device) { - setBackingTextureId(0, false); + UpdateLayer(); InvalidateRect(gfx::Rect()); return PP_TRUE; } @@ -1907,9 +1910,6 @@ PP_Bool PluginInstance::BindGraphics(PP_Instance instance, if (bound_graphics_2d_platform_) { if (!bound_graphics_2d_platform_->BindToInstance(this)) return PP_FALSE; // Can't bind to more than one instance. - - setBackingTextureId(0, bound_graphics_2d_platform_->IsAlwaysOpaque()); - // BindToInstance will have invalidated the plugin if necessary. } else if (graphics_3d) { // Make sure graphics can only be bound to the instance it is // associated with. @@ -1919,12 +1919,11 @@ PP_Bool PluginInstance::BindGraphics(PP_Instance instance, return PP_FALSE; bound_graphics_3d_ = graphics_3d; - setBackingTextureId(graphics_3d->GetBackingTextureId(), - graphics_3d->IsOpaque()); } else { // The device is not a valid resource type. return PP_FALSE; } + UpdateLayer(); return PP_TRUE; } @@ -2106,6 +2105,16 @@ void PluginInstance::DeliverSamples(PP_Instance instance, content_decryptor_delegate_->DeliverSamples(audio_frames, block_info); } +unsigned PluginInstance::prepareTexture(cc::ResourceUpdateQueue&) { + return GetBackingTextureId(); +} + +WebKit::WebGraphicsContext3D* PluginInstance::context() { + DCHECK(bound_graphics_3d_.get()); + DCHECK(bound_graphics_3d_->platform_context()); + return bound_graphics_3d_->platform_context()->GetParentContext(); +} + void PluginInstance::NumberOfFindResultsChanged(PP_Instance instance, int32_t total, PP_Bool final_result) { diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.h b/webkit/plugins/ppapi/ppapi_plugin_instance.h index 3abb4b1..ff7a0e5 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.h +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.h @@ -15,6 +15,7 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "base/string16.h" +#include "cc/texture_layer_client.h" #include "googleurl/src/gurl.h" #include "ppapi/c/dev/pp_cursor_type_dev.h" #include "ppapi/c/dev/ppp_printing_dev.h" @@ -61,6 +62,7 @@ class TransportDIB; namespace WebKit { class WebInputEvent; +class WebLayer; class WebMouseEvent; class WebPluginContainer; struct WebCompositionUnderline; @@ -68,6 +70,10 @@ struct WebCursorInfo; struct WebPrintParams; } +namespace cc { +class TextureLayer; +} + namespace ppapi { struct InputEventData; struct PPP_Instance_Combined; @@ -99,7 +105,8 @@ class PPB_URLLoader_Impl; class WEBKIT_PLUGINS_EXPORT PluginInstance : public base::RefCounted<PluginInstance>, public base::SupportsWeakPtr<PluginInstance>, - public ::ppapi::PPB_Instance_Shared { + public ::ppapi::PPB_Instance_Shared, + public NON_EXPORTED_BASE(cc::TextureLayerClient) { public: // Create and return a PluginInstance object which supports the most recent // version of PPP_Instance possible by querying the given get_plugin_interface @@ -452,6 +459,10 @@ class WEBKIT_PLUGINS_EXPORT PluginInstance : PP_Resource audio_frames, const PP_DecryptedBlockInfo* block_info) OVERRIDE; + // TextureLayerClient implementation. + virtual unsigned prepareTexture(cc::ResourceUpdateQueue&) OVERRIDE; + virtual WebKit::WebGraphicsContext3D* context() OVERRIDE; + // Reset this instance as proxied. Resets cached interfaces to point to the // proxy and re-sends DidCreate, DidChangeView, and HandleDocumentLoad (if // necessary). @@ -523,15 +534,14 @@ class WEBKIT_PLUGINS_EXPORT PluginInstance : // null if the context is not 2D. PluginDelegate::PlatformGraphics2D* GetBoundGraphics2D() const; - // Get the bound 3D graphics context. - // Returns NULL if bound graphics is not a 3D context. - PPB_Graphics3D_Impl* GetBoundGraphics3D() const; - - // Sets the id of the texture that the plugin draws to. The id is in the - // compositor space so it can use it to composite with rest of the page. - // A value of zero indicates the plugin is not backed by a texture. - // is_opaque is true if the plugin contents are always opaque. - void setBackingTextureId(unsigned int id, bool is_opaque); + // Updates the layer for compositing. This creates a layer and attaches to the + // container if: + // - we have a bound Graphics3D + // - the Graphics3D has a texture + // - we are not in Flash full-screen mode (or transitioning to it) + // Otherwise it destroys the layer. + // It does either operation lazily. + void UpdateLayer(); // Internal helper function for PrintPage(). bool PrintPageHelper(PP_PrintPageNumberRange_Dev* page_ranges, @@ -581,6 +591,8 @@ class WEBKIT_PLUGINS_EXPORT PluginInstance : // NULL until we have been initialized. WebKit::WebPluginContainer* container_; + scoped_refptr<cc::TextureLayer> texture_layer_; + scoped_ptr<WebKit::WebLayer> web_layer_; // Plugin URL. GURL plugin_url_; @@ -608,7 +620,7 @@ class WEBKIT_PLUGINS_EXPORT PluginInstance : base::WeakPtrFactory<PluginInstance> view_change_weak_ptr_factory_; // The current device context for painting in 2D and 3D. - scoped_refptr< ::ppapi::Resource> bound_graphics_3d_; + scoped_refptr<PPB_Graphics3D_Impl> bound_graphics_3d_; PluginDelegate::PlatformGraphics2D* bound_graphics_2d_platform_; // We track two types of focus, one from WebKit, which is the focus among |