Chromium Code Reviews| Index: content/renderer/browser_plugin/browser_plugin_compositing_helper.cc |
| diff --git a/content/renderer/browser_plugin/browser_plugin_compositing_helper.cc b/content/renderer/browser_plugin/browser_plugin_compositing_helper.cc |
| index dd7d84fc51a1b3e65cbcb4d13e53a24e79b05aec..2365c1345d97837b82b797ec3f7c764a59d81fd7 100644 |
| --- a/content/renderer/browser_plugin/browser_plugin_compositing_helper.cc |
| +++ b/content/renderer/browser_plugin/browser_plugin_compositing_helper.cc |
| @@ -6,36 +6,28 @@ |
| #include "cc/texture_layer.h" |
| #include "content/common/browser_plugin_messages.h" |
| +#include "content/renderer/browser_plugin/browser_plugin_manager.h" |
| #include "content/renderer/render_thread_impl.h" |
| +#include "third_party/khronos/GLES2/gl2.h" |
| +#include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3D.h" |
| +#include "third_party/WebKit/Source/Platform/chromium/public/WebSharedGraphicsContext3D.h" |
| #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
| #include "webkit/compositor_bindings/web_layer_impl.h" |
| namespace content { |
| -static void SendACK(const std::string& mailbox_name, |
| - int host_route_id, |
| - int gpu_route_id, |
| - int gpu_host_id, |
| - unsigned sync_point) { |
| - RenderThread::Get()->Send( |
| - new BrowserPluginHostMsg_BuffersSwappedACK( |
| - host_route_id, |
| - gpu_route_id, |
| - gpu_host_id, |
| - mailbox_name, |
| - sync_point)); |
| -} |
| - |
| BrowserPluginCompositingHelper::BrowserPluginCompositingHelper( |
| WebKit::WebPluginContainer* container, |
| + BrowserPluginManager* manager, |
| int host_routing_id) |
| : host_routing_id_(host_routing_id), |
| last_mailbox_valid_(false), |
| - container_(container) { |
| + ack_pending_(true), |
| + container_(container), |
| + browser_plugin_manager_(manager) { |
| } |
| BrowserPluginCompositingHelper::~BrowserPluginCompositingHelper() { |
| - container_->setWebLayer(NULL); |
| } |
| void BrowserPluginCompositingHelper::EnableCompositing(bool enable) { |
| @@ -47,30 +39,82 @@ void BrowserPluginCompositingHelper::EnableCompositing(bool enable) { |
| container_->setWebLayer(enable ? web_layer_.get() : NULL); |
| } |
| +void BrowserPluginCompositingHelper::FreeMailboxMemory( |
| + const std::string& mailbox_name) { |
| + WebKit::WebGraphicsContext3D *context = |
|
Fady Samuel
2013/01/17 19:18:45
I don't really understand what this is doing. Coul
alexst (slow to review)
2013/01/18 18:49:44
Done.
|
| + WebKit::WebSharedGraphicsContext3D::mainThreadContext(); |
| + DCHECK(context); |
| + unsigned texture_id = context->createTexture(); |
| + context->bindTexture(GL_TEXTURE_2D, texture_id); |
| + context->consumeTextureCHROMIUM( |
| + GL_TEXTURE_2D, |
| + reinterpret_cast<const int8*>(mailbox_name.data())); |
| + context->deleteTexture(texture_id); |
| +} |
| + |
| +void BrowserPluginCompositingHelper::MailboxReleased( |
| + const std::string& mailbox_name, |
| + int gpu_route_id, |
| + int gpu_host_id, |
| + unsigned sync_point) { |
| + if (!ack_pending_) { |
|
Fady Samuel
2013/01/17 19:18:45
More description here as well.
alexst (slow to review)
2013/01/18 18:49:44
Done.
|
| + FreeMailboxMemory(mailbox_name); |
| + last_mailbox_valid_ = false; |
| + return; |
| + } |
| + ack_pending_ = false; |
| + browser_plugin_manager_->Send( |
| + new BrowserPluginHostMsg_BuffersSwappedACK( |
| + host_routing_id_, |
| + gpu_route_id, |
| + gpu_host_id, |
| + mailbox_name, |
| + sync_point)); |
| +} |
| + |
| +void BrowserPluginCompositingHelper::OnContainerDestroy() { |
| + if (container_) |
| + container_->setWebLayer(NULL); |
| + container_ = NULL; |
| + |
| + texture_layer_ = NULL; |
| + web_layer_.reset(); |
| +} |
| + |
| void BrowserPluginCompositingHelper::OnBuffersSwapped( |
| const gfx::Size& size, |
| const std::string& mailbox_name, |
| int gpu_route_id, |
| int gpu_host_id) { |
| + ack_pending_ = true; |
| + // Browser plugin getting destroyed, do a fast ACK. |
| + if (!texture_layer_) { |
| + MailboxReleased(mailbox_name, gpu_route_id, gpu_host_id, 0); |
| + return; |
| + } |
| + |
| if (buffer_size_ != size) { |
| buffer_size_ = size; |
| UpdateUVRect(); |
| } |
| - if (!last_mailbox_valid_) |
| - SendACK(std::string(), host_routing_id_, gpu_route_id, gpu_host_id, 0); |
| bool current_mailbox_valid = !mailbox_name.empty(); |
| - if (!current_mailbox_valid && !last_mailbox_valid_) |
| - return; |
| + if (!last_mailbox_valid_) { |
| + MailboxReleased(std::string(), gpu_route_id, gpu_host_id, 0); |
| + if (!current_mailbox_valid) |
| + return; |
| + } |
| cc::TextureLayer::MailboxCallback callback; |
| if (current_mailbox_valid) { |
| - callback = base::Bind(&SendACK, |
| + scoped_refptr<BrowserPluginCompositingHelper> helper(this); |
|
Fady Samuel
2013/01/17 19:18:45
Why do we have this here?
alexst (slow to review)
2013/01/18 18:49:44
I left it there to make it explicit that this is m
|
| + callback = base::Bind(&BrowserPluginCompositingHelper::MailboxReleased, |
| + helper, |
| mailbox_name, |
| - host_routing_id_, |
| gpu_route_id, |
| gpu_host_id); |
| } |
| + |
| texture_layer_->setTextureMailbox(mailbox_name, callback); |
| last_mailbox_valid_ = current_mailbox_valid; |
| } |