OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/browser_plugin/browser_plugin_compositing_helper.h" | 5 #include "content/renderer/browser_plugin/browser_plugin_compositing_helper.h" |
6 | 6 |
7 #include "cc/texture_layer.h" | 7 #include "cc/texture_layer.h" |
8 #include "content/common/browser_plugin_messages.h" | 8 #include "content/common/browser_plugin_messages.h" |
9 #include "content/renderer/browser_plugin/browser_plugin_manager.h" | |
9 #include "content/renderer/render_thread_impl.h" | 10 #include "content/renderer/render_thread_impl.h" |
11 #include "third_party/khronos/GLES2/gl2.h" | |
12 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3 D.h" | |
13 #include "third_party/WebKit/Source/Platform/chromium/public/WebSharedGraphicsCo ntext3D.h" | |
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
11 #include "webkit/compositor_bindings/web_layer_impl.h" | 15 #include "webkit/compositor_bindings/web_layer_impl.h" |
12 | 16 |
13 namespace content { | 17 namespace content { |
14 | 18 |
15 static void SendACK(const std::string& mailbox_name, | |
16 int host_route_id, | |
17 int gpu_route_id, | |
18 int gpu_host_id, | |
19 unsigned sync_point) { | |
20 RenderThread::Get()->Send( | |
21 new BrowserPluginHostMsg_BuffersSwappedACK( | |
22 host_route_id, | |
23 gpu_route_id, | |
24 gpu_host_id, | |
25 mailbox_name, | |
26 sync_point)); | |
27 } | |
28 | |
29 BrowserPluginCompositingHelper::BrowserPluginCompositingHelper( | 19 BrowserPluginCompositingHelper::BrowserPluginCompositingHelper( |
30 WebKit::WebPluginContainer* container, | 20 WebKit::WebPluginContainer* container, |
21 BrowserPluginManager* manager, | |
31 int host_routing_id) | 22 int host_routing_id) |
32 : host_routing_id_(host_routing_id), | 23 : host_routing_id_(host_routing_id), |
33 last_mailbox_valid_(false), | 24 last_mailbox_valid_(false), |
34 container_(container) { | 25 ack_pending_(true), |
26 container_(container), | |
27 browser_plugin_manager_(manager) { | |
35 } | 28 } |
36 | 29 |
37 BrowserPluginCompositingHelper::~BrowserPluginCompositingHelper() { | 30 BrowserPluginCompositingHelper::~BrowserPluginCompositingHelper() { |
38 container_->setWebLayer(NULL); | |
39 } | 31 } |
40 | 32 |
41 void BrowserPluginCompositingHelper::EnableCompositing(bool enable) { | 33 void BrowserPluginCompositingHelper::EnableCompositing(bool enable) { |
42 if (enable && !texture_layer_) { | 34 if (enable && !texture_layer_) { |
43 texture_layer_ = cc::TextureLayer::createForMailbox(); | 35 texture_layer_ = cc::TextureLayer::createForMailbox(); |
44 web_layer_.reset(new WebKit::WebLayerImpl(texture_layer_)); | 36 web_layer_.reset(new WebKit::WebLayerImpl(texture_layer_)); |
45 } | 37 } |
46 | 38 |
47 container_->setWebLayer(enable ? web_layer_.get() : NULL); | 39 container_->setWebLayer(enable ? web_layer_.get() : NULL); |
48 } | 40 } |
49 | 41 |
42 void BrowserPluginCompositingHelper::FreeMailboxMemory( | |
43 const std::string& mailbox_name) { | |
44 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.
| |
45 WebKit::WebSharedGraphicsContext3D::mainThreadContext(); | |
46 DCHECK(context); | |
47 unsigned texture_id = context->createTexture(); | |
48 context->bindTexture(GL_TEXTURE_2D, texture_id); | |
49 context->consumeTextureCHROMIUM( | |
50 GL_TEXTURE_2D, | |
51 reinterpret_cast<const int8*>(mailbox_name.data())); | |
52 context->deleteTexture(texture_id); | |
53 } | |
54 | |
55 void BrowserPluginCompositingHelper::MailboxReleased( | |
56 const std::string& mailbox_name, | |
57 int gpu_route_id, | |
58 int gpu_host_id, | |
59 unsigned sync_point) { | |
60 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.
| |
61 FreeMailboxMemory(mailbox_name); | |
62 last_mailbox_valid_ = false; | |
63 return; | |
64 } | |
65 ack_pending_ = false; | |
66 browser_plugin_manager_->Send( | |
67 new BrowserPluginHostMsg_BuffersSwappedACK( | |
68 host_routing_id_, | |
69 gpu_route_id, | |
70 gpu_host_id, | |
71 mailbox_name, | |
72 sync_point)); | |
73 } | |
74 | |
75 void BrowserPluginCompositingHelper::OnContainerDestroy() { | |
76 if (container_) | |
77 container_->setWebLayer(NULL); | |
78 container_ = NULL; | |
79 | |
80 texture_layer_ = NULL; | |
81 web_layer_.reset(); | |
82 } | |
83 | |
50 void BrowserPluginCompositingHelper::OnBuffersSwapped( | 84 void BrowserPluginCompositingHelper::OnBuffersSwapped( |
51 const gfx::Size& size, | 85 const gfx::Size& size, |
52 const std::string& mailbox_name, | 86 const std::string& mailbox_name, |
53 int gpu_route_id, | 87 int gpu_route_id, |
54 int gpu_host_id) { | 88 int gpu_host_id) { |
89 ack_pending_ = true; | |
90 // Browser plugin getting destroyed, do a fast ACK. | |
91 if (!texture_layer_) { | |
92 MailboxReleased(mailbox_name, gpu_route_id, gpu_host_id, 0); | |
93 return; | |
94 } | |
95 | |
55 if (buffer_size_ != size) { | 96 if (buffer_size_ != size) { |
56 buffer_size_ = size; | 97 buffer_size_ = size; |
57 UpdateUVRect(); | 98 UpdateUVRect(); |
58 } | 99 } |
59 if (!last_mailbox_valid_) | |
60 SendACK(std::string(), host_routing_id_, gpu_route_id, gpu_host_id, 0); | |
61 | 100 |
62 bool current_mailbox_valid = !mailbox_name.empty(); | 101 bool current_mailbox_valid = !mailbox_name.empty(); |
63 if (!current_mailbox_valid && !last_mailbox_valid_) | 102 if (!last_mailbox_valid_) { |
64 return; | 103 MailboxReleased(std::string(), gpu_route_id, gpu_host_id, 0); |
104 if (!current_mailbox_valid) | |
105 return; | |
106 } | |
65 | 107 |
66 cc::TextureLayer::MailboxCallback callback; | 108 cc::TextureLayer::MailboxCallback callback; |
67 if (current_mailbox_valid) { | 109 if (current_mailbox_valid) { |
68 callback = base::Bind(&SendACK, | 110 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
| |
111 callback = base::Bind(&BrowserPluginCompositingHelper::MailboxReleased, | |
112 helper, | |
69 mailbox_name, | 113 mailbox_name, |
70 host_routing_id_, | |
71 gpu_route_id, | 114 gpu_route_id, |
72 gpu_host_id); | 115 gpu_host_id); |
73 } | 116 } |
117 | |
74 texture_layer_->setTextureMailbox(mailbox_name, callback); | 118 texture_layer_->setTextureMailbox(mailbox_name, callback); |
75 last_mailbox_valid_ = current_mailbox_valid; | 119 last_mailbox_valid_ = current_mailbox_valid; |
76 } | 120 } |
77 | 121 |
78 void BrowserPluginCompositingHelper::SetContainerSize(const gfx::Size& size) { | 122 void BrowserPluginCompositingHelper::SetContainerSize(const gfx::Size& size) { |
79 if (container_size_ == size) | 123 if (container_size_ == size) |
80 return; | 124 return; |
81 | 125 |
82 container_size_ = size; | 126 container_size_ = size; |
83 UpdateUVRect(); | 127 UpdateUVRect(); |
84 } | 128 } |
85 | 129 |
86 void BrowserPluginCompositingHelper::UpdateUVRect() { | 130 void BrowserPluginCompositingHelper::UpdateUVRect() { |
87 if (!texture_layer_) | 131 if (!texture_layer_) |
88 return; | 132 return; |
89 | 133 |
90 gfx::RectF uv_rect(0, 0, 1, 1); | 134 gfx::RectF uv_rect(0, 0, 1, 1); |
91 if (!buffer_size_.IsEmpty() && !container_size_.IsEmpty()) { | 135 if (!buffer_size_.IsEmpty() && !container_size_.IsEmpty()) { |
92 uv_rect.set_width(static_cast<float>(container_size_.width()) / | 136 uv_rect.set_width(static_cast<float>(container_size_.width()) / |
93 static_cast<float>(buffer_size_.width())); | 137 static_cast<float>(buffer_size_.width())); |
94 uv_rect.set_height(static_cast<float>(container_size_.height()) / | 138 uv_rect.set_height(static_cast<float>(container_size_.height()) / |
95 static_cast<float>(buffer_size_.height())); | 139 static_cast<float>(buffer_size_.height())); |
96 } | 140 } |
97 texture_layer_->setUVRect(uv_rect); | 141 texture_layer_->setUVRect(uv_rect); |
98 } | 142 } |
99 | 143 |
100 } // namespace content | 144 } // namespace content |
OLD | NEW |