diff options
author | alexst@chromium.org <alexst@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-12 00:26:01 +0000 |
---|---|---|
committer | alexst@chromium.org <alexst@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-12 00:26:01 +0000 |
commit | e8e4ae23db9a412373f1dd998de11b7b1c98110c (patch) | |
tree | ab62a3c23d332ae66d14edad153af3e564606cf1 | |
parent | 1a0b11ca1aed069ce1695b8a05d11712efdf731c (diff) | |
download | chromium_src-e8e4ae23db9a412373f1dd998de11b7b1c98110c.zip chromium_src-e8e4ae23db9a412373f1dd998de11b7b1c98110c.tar.gz chromium_src-e8e4ae23db9a412373f1dd998de11b7b1c98110c.tar.bz2 |
This patch implements the necessary plumbing to allow WebExternalTextureLayerClient to be used with texture mailboxes, which allows WebGL and Canvas2D to work with ubercompositor.
CC part of this patch requests the client to prepare a mailbox instead of a texture. Compositor bindings handle interaction with Blink as well as callbacks associated with mailboxes being released.
BUG=179371
Review URL: https://chromiumcodereview.appspot.com/12374028
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@193807 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | cc/layers/texture_layer.cc | 18 | ||||
-rw-r--r-- | cc/layers/texture_layer.h | 3 | ||||
-rw-r--r-- | cc/layers/texture_layer_client.h | 6 | ||||
-rw-r--r-- | cc/layers/texture_layer_unittest.cc | 8 | ||||
-rw-r--r-- | content/renderer/browser_plugin/browser_plugin_compositing_helper.cc | 2 | ||||
-rw-r--r-- | ui/compositor/layer.cc | 4 | ||||
-rw-r--r-- | ui/compositor/layer.h | 1 | ||||
-rw-r--r-- | webkit/compositor_bindings/compositor_bindings.gyp | 1 | ||||
-rw-r--r-- | webkit/compositor_bindings/web_compositor_support_impl.cc | 8 | ||||
-rw-r--r-- | webkit/compositor_bindings/web_compositor_support_impl.h | 3 | ||||
-rw-r--r-- | webkit/compositor_bindings/web_external_texture_layer_impl.cc | 54 | ||||
-rw-r--r-- | webkit/compositor_bindings/web_external_texture_layer_impl.h | 24 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppapi_plugin_instance.cc | 4 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppapi_plugin_instance.h | 1 |
14 files changed, 118 insertions, 19 deletions
diff --git a/cc/layers/texture_layer.cc b/cc/layers/texture_layer.cc index f6f87bc..e1ce978e 100644 --- a/cc/layers/texture_layer.cc +++ b/cc/layers/texture_layer.cc @@ -34,8 +34,9 @@ scoped_refptr<TextureLayer> TextureLayer::Create(TextureLayerClient* client) { return scoped_refptr<TextureLayer>(new TextureLayer(client, false)); } -scoped_refptr<TextureLayer> TextureLayer::CreateForMailbox() { - return scoped_refptr<TextureLayer>(new TextureLayer(NULL, true)); +scoped_refptr<TextureLayer> TextureLayer::CreateForMailbox( + TextureLayerClient* client) { + return scoped_refptr<TextureLayer>(new TextureLayer(client, true)); } TextureLayer::TextureLayer(TextureLayerClient* client, bool uses_mailbox) @@ -70,7 +71,10 @@ TextureLayer::~TextureLayer() { void TextureLayer::ClearClient() { client_ = NULL; - SetTextureId(0); + if (uses_mailbox_) + SetTextureMailbox(TextureMailbox()); + else + SetTextureId(0); } scoped_ptr<LayerImpl> TextureLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) { @@ -167,7 +171,13 @@ void TextureLayer::Update(ResourceUpdateQueue* queue, const OcclusionTracker* occlusion, RenderingStats* stats) { if (client_) { - texture_id_ = client_->PrepareTexture(queue); + if (uses_mailbox_) { + TextureMailbox mailbox; + if (client_->PrepareTextureMailbox(&mailbox)) + SetTextureMailbox(mailbox); + } else { + texture_id_ = client_->PrepareTexture(queue); + } context_lost_ = client_->Context3d()->getGraphicsResetStatusARB() != GL_NO_ERROR; } diff --git a/cc/layers/texture_layer.h b/cc/layers/texture_layer.h index ad8d44f..cff2e3c 100644 --- a/cc/layers/texture_layer.h +++ b/cc/layers/texture_layer.h @@ -27,7 +27,8 @@ class CC_EXPORT TextureLayer : public Layer { static scoped_refptr<TextureLayer> Create(TextureLayerClient* client); // Used when mailbox names are specified instead of texture IDs. - static scoped_refptr<TextureLayer> CreateForMailbox(); + static scoped_refptr<TextureLayer> CreateForMailbox( + TextureLayerClient* client); void ClearClient(); diff --git a/cc/layers/texture_layer_client.h b/cc/layers/texture_layer_client.h index 39f1e80..b5c0de6 100644 --- a/cc/layers/texture_layer_client.h +++ b/cc/layers/texture_layer_client.h @@ -9,6 +9,7 @@ namespace WebKit { class WebGraphicsContext3D; } namespace cc { class ResourceUpdateQueue; +class TextureMailbox; class TextureLayerClient { public: @@ -21,6 +22,11 @@ class TextureLayerClient { // and detecting lost context. virtual WebKit::WebGraphicsContext3D* Context3d() = 0; + // Returns true and provides a mailbox if a new frame is available. + // Returns false if no new data is available + // and the old mailbox is to be reused. + virtual bool PrepareTextureMailbox(TextureMailbox* mailbox) = 0; + protected: virtual ~TextureLayerClient() {} }; diff --git a/cc/layers/texture_layer_unittest.cc b/cc/layers/texture_layer_unittest.cc index 450c3a1..c6a4549 100644 --- a/cc/layers/texture_layer_unittest.cc +++ b/cc/layers/texture_layer_unittest.cc @@ -234,7 +234,7 @@ class TextureLayerWithMailboxTest : public TextureLayerTest { }; TEST_F(TextureLayerWithMailboxTest, ReplaceMailboxOnMainThreadBeforeCommit) { - scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox(); + scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox(NULL); ASSERT_TRUE(test_layer); EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); @@ -302,7 +302,7 @@ class TextureLayerImplWithMailboxThreadedCallback : public LayerTreeTest { root_->SetAnchorPoint(gfx::PointF()); root_->SetBounds(bounds); - layer_ = TextureLayer::CreateForMailbox(); + layer_ = TextureLayer::CreateForMailbox(NULL); layer_->SetIsDrawable(true); layer_->SetAnchorPoint(gfx::PointF()); layer_->SetBounds(bounds); @@ -521,6 +521,10 @@ class TextureLayerClientTest return context_; } + virtual bool PrepareTextureMailbox(cc::TextureMailbox* mailbox) OVERRIDE { + return false; + } + virtual void SetupTree() OVERRIDE { scoped_refptr<Layer> root = Layer::Create(); root->SetBounds(gfx::Size(10, 10)); diff --git a/content/renderer/browser_plugin/browser_plugin_compositing_helper.cc b/content/renderer/browser_plugin/browser_plugin_compositing_helper.cc index f579bb5..fb32cdc 100644 --- a/content/renderer/browser_plugin/browser_plugin_compositing_helper.cc +++ b/content/renderer/browser_plugin/browser_plugin_compositing_helper.cc @@ -220,7 +220,7 @@ void BrowserPluginCompositingHelper::OnBuffersSwapped( } if (!texture_layer_) { - texture_layer_ = cc::TextureLayer::CreateForMailbox(); + texture_layer_ = cc::TextureLayer::CreateForMailbox(NULL); texture_layer_->SetIsDrawable(true); texture_layer_->SetContentsOpaque(true); diff --git a/ui/compositor/layer.cc b/ui/compositor/layer.cc index ad3c31c..9bb17da 100644 --- a/ui/compositor/layer.cc +++ b/ui/compositor/layer.cc @@ -640,6 +640,10 @@ WebKit::WebGraphicsContext3D* Layer::Context3d() { return texture_->HostContext3D(); } +bool Layer::PrepareTextureMailbox(cc::TextureMailbox* mailbox) { + return false; +} + void Layer::SetForceRenderSurface(bool force) { if (force_render_surface_ == force) return; diff --git a/ui/compositor/layer.h b/ui/compositor/layer.h index d7c6a5e..a5afd6b 100644 --- a/ui/compositor/layer.h +++ b/ui/compositor/layer.h @@ -306,6 +306,7 @@ class COMPOSITOR_EXPORT Layer // TextureLayerClient virtual unsigned PrepareTexture(cc::ResourceUpdateQueue* queue) OVERRIDE; virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE; + virtual bool PrepareTextureMailbox(cc::TextureMailbox* mailbox) OVERRIDE; float device_scale_factor() const { return device_scale_factor_; } diff --git a/webkit/compositor_bindings/compositor_bindings.gyp b/webkit/compositor_bindings/compositor_bindings.gyp index 73cdec4..728fd32 100644 --- a/webkit/compositor_bindings/compositor_bindings.gyp +++ b/webkit/compositor_bindings/compositor_bindings.gyp @@ -69,6 +69,7 @@ 'dependencies': [ '../../base/base.gyp:base', '../../cc/cc.gyp:cc', + '../../gpu/gpu.gyp:gpu', '../../media/media.gyp:media', '../../skia/skia.gyp:skia', '../../ui/ui.gyp:ui', diff --git a/webkit/compositor_bindings/web_compositor_support_impl.cc b/webkit/compositor_bindings/web_compositor_support_impl.cc index caca2cb..dfa2b1b 100644 --- a/webkit/compositor_bindings/web_compositor_support_impl.cc +++ b/webkit/compositor_bindings/web_compositor_support_impl.cc @@ -57,7 +57,13 @@ WebContentLayer* WebCompositorSupportImpl::createContentLayer( WebExternalTextureLayer* WebCompositorSupportImpl::createExternalTextureLayer( WebExternalTextureLayerClient* client) { - return new WebExternalTextureLayerImpl(client); + return new WebExternalTextureLayerImpl(client, false); +} + +WebExternalTextureLayer* +WebCompositorSupportImpl::createExternalTextureLayerForMailbox( + WebExternalTextureLayerClient* client) { + return new WebExternalTextureLayerImpl(client, true); } WebKit::WebImageLayer* WebCompositorSupportImpl::createImageLayer() { diff --git a/webkit/compositor_bindings/web_compositor_support_impl.h b/webkit/compositor_bindings/web_compositor_support_impl.h index a5cb019..bcd2e00 100644 --- a/webkit/compositor_bindings/web_compositor_support_impl.h +++ b/webkit/compositor_bindings/web_compositor_support_impl.h @@ -27,6 +27,9 @@ class WebCompositorSupportImpl : public WebKit::WebCompositorSupport { WebKit::WebContentLayerClient* client); virtual WebKit::WebExternalTextureLayer* createExternalTextureLayer( WebKit::WebExternalTextureLayerClient* client); + virtual WebKit::WebExternalTextureLayer* + createExternalTextureLayerForMailbox( + WebKit::WebExternalTextureLayerClient* client); virtual WebKit::WebImageLayer* createImageLayer(); virtual WebKit::WebSolidColorLayer* createSolidColorLayer(); virtual WebKit::WebScrollbarLayer* createScrollbarLayer( diff --git a/webkit/compositor_bindings/web_external_texture_layer_impl.cc b/webkit/compositor_bindings/web_external_texture_layer_impl.cc index 01f6e79..f93c3e2 100644 --- a/webkit/compositor_bindings/web_external_texture_layer_impl.cc +++ b/webkit/compositor_bindings/web_external_texture_layer_impl.cc @@ -7,6 +7,7 @@ #include "cc/layers/texture_layer.h" #include "cc/resources/resource_update_queue.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebExternalTextureLayerClient.h" +#include "third_party/WebKit/Source/Platform/chromium/public/WebExternalTextureMailbox.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebFloatRect.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" #include "webkit/compositor_bindings/web_layer_impl.h" @@ -17,13 +18,16 @@ using cc::ResourceUpdateQueue; namespace webkit { WebExternalTextureLayerImpl::WebExternalTextureLayerImpl( - WebKit::WebExternalTextureLayerClient* client) - : client_(client) { + WebKit::WebExternalTextureLayerClient* client, + bool mailbox) + : client_(client), + uses_mailbox_(mailbox) { scoped_refptr<TextureLayer> layer; - if (client_) - layer = TextureLayer::Create(this); + cc::TextureLayerClient* cc_client = client_ ? this : NULL; + if (mailbox) + layer = TextureLayer::CreateForMailbox(cc_client); else - layer = TextureLayer::Create(NULL); + layer = TextureLayer::Create(cc_client); layer->SetIsDrawable(true); layer_.reset(new WebLayerImpl(layer)); } @@ -34,6 +38,15 @@ WebExternalTextureLayerImpl::~WebExternalTextureLayerImpl() { WebKit::WebLayer* WebExternalTextureLayerImpl::layer() { return layer_.get(); } +void WebExternalTextureLayerImpl::clearTexture() { + if (uses_mailbox_) { + static_cast<TextureLayer*>(layer_->layer())->SetTextureMailbox( + cc::TextureMailbox()); + } else { + static_cast<TextureLayer*>(layer_->layer())->SetTextureId(0); + } +} + void WebExternalTextureLayerImpl::setTextureId(unsigned id) { static_cast<TextureLayer*>(layer_->layer())->SetTextureId(id); } @@ -94,4 +107,33 @@ WebKit::WebGraphicsContext3D* WebExternalTextureLayerImpl::Context3d() { return client_->context(); } -} // namespace webkit +bool WebExternalTextureLayerImpl::PrepareTextureMailbox( + cc::TextureMailbox* mailbox) { + WebKit::WebExternalTextureMailbox client_mailbox; + if (!client_->prepareMailbox(&client_mailbox)) { + return false; + } + gpu::Mailbox name; + name.SetName(client_mailbox.name); + cc::TextureMailbox::ReleaseCallback callback = + base::Bind(&WebExternalTextureLayerImpl::DidReleaseMailbox, + this->AsWeakPtr(), + client_mailbox); + *mailbox = cc::TextureMailbox(name, callback, client_mailbox.syncPoint); + return true; +} + +void WebExternalTextureLayerImpl::DidReleaseMailbox( + const WebKit::WebExternalTextureMailbox& mailbox, + unsigned sync_point, + bool lost_resource) { + if (lost_resource) + return; + + WebKit::WebExternalTextureMailbox available_mailbox; + memcpy(available_mailbox.name, mailbox.name, sizeof(available_mailbox.name)); + available_mailbox.syncPoint = sync_point; + client_->mailboxReleased(available_mailbox); +} + +} // namespace webkit diff --git a/webkit/compositor_bindings/web_external_texture_layer_impl.h b/webkit/compositor_bindings/web_external_texture_layer_impl.h index e9c33b1..704864a 100644 --- a/webkit/compositor_bindings/web_external_texture_layer_impl.h +++ b/webkit/compositor_bindings/web_external_texture_layer_impl.h @@ -5,41 +5,57 @@ #ifndef WEBKIT_COMPOSITOR_BINDINGS_WEB_EXTERNAL_TEXTURE_LAYER_IMPL_H_ #define WEBKIT_COMPOSITOR_BINDINGS_WEB_EXTERNAL_TEXTURE_LAYER_IMPL_H_ +#include "base/bind.h" #include "base/memory/scoped_ptr.h" #include "cc/layers/texture_layer_client.h" +#include "cc/resources/texture_mailbox.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebExternalTextureLayer.h" #include "webkit/compositor_bindings/webkit_compositor_bindings_export.h" -namespace WebKit { struct WebFloatRect; } +namespace WebKit { +struct WebFloatRect; +struct WebExternalTextureMailbox; +} namespace webkit { class WebLayerImpl; -class WebExternalTextureLayerImpl : public WebKit::WebExternalTextureLayer, - public cc::TextureLayerClient { +class WebExternalTextureLayerImpl + : public WebKit::WebExternalTextureLayer, + public cc::TextureLayerClient, + public base::SupportsWeakPtr<WebExternalTextureLayerImpl> { public: WEBKIT_COMPOSITOR_BINDINGS_EXPORT explicit WebExternalTextureLayerImpl( - WebKit::WebExternalTextureLayerClient*); + WebKit::WebExternalTextureLayerClient*, + bool mailbox); virtual ~WebExternalTextureLayerImpl(); // WebKit::WebExternalTextureLayer implementation. virtual WebKit::WebLayer* layer(); + virtual void clearTexture(); virtual void setTextureId(unsigned texture_id); virtual void setFlipped(bool flipped); virtual void setUVRect(const WebKit::WebFloatRect& uv_rect); virtual void setOpaque(bool opaque); virtual void setPremultipliedAlpha(bool premultiplied); + virtual void willModifyTexture(); virtual void setRateLimitContext(bool rate_limit); // TextureLayerClient implementation. virtual unsigned PrepareTexture(cc::ResourceUpdateQueue*) OVERRIDE; virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE; + virtual bool PrepareTextureMailbox(cc::TextureMailbox* mailbox) OVERRIDE; private: + void DidReleaseMailbox(const WebKit::WebExternalTextureMailbox& mailbox, + unsigned sync_point, + bool lost_resource); + WebKit::WebExternalTextureLayerClient* client_; scoped_ptr<WebLayerImpl> layer_; + bool uses_mailbox_; DISALLOW_COPY_AND_ASSIGN(WebExternalTextureLayerImpl); }; diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc index a46d4d2..33fe94e 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc @@ -2106,6 +2106,10 @@ WebKit::WebGraphicsContext3D* PluginInstance::Context3d() { return bound_graphics_3d_->platform_context()->GetParentContext(); } +bool PluginInstance::PrepareTextureMailbox(cc::TextureMailbox* mailbox) { + return false; +} + 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 b6456ba..7bfcfba 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.h +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.h @@ -465,6 +465,7 @@ class WEBKIT_PLUGINS_EXPORT PluginInstance : // TextureLayerClient implementation. virtual unsigned PrepareTexture(cc::ResourceUpdateQueue* queue) OVERRIDE; virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE; + virtual bool PrepareTextureMailbox(cc::TextureMailbox* mailbox) OVERRIDE; // Reset this instance as proxied. Assigns the instance a new module, resets // cached interfaces to point to the out-of-process proxy and re-sends |