[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | 0f21e858 | 2013-01-11 11:06:56 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 5 | #include "content/renderer/child_frame_compositing_helper.h" |
[email protected] | 0f21e858 | 2013-01-11 11:06:56 | [diff] [blame] | 6 | |
dcheng | 07945f63 | 2015-12-26 07:59:32 | [diff] [blame^] | 7 | #include <utility> |
| 8 | |
[email protected] | 3856462 | 2014-08-19 02:47:18 | [diff] [blame] | 9 | #include "cc/blink/web_layer_impl.h" |
[email protected] | 09f6738 | 2013-10-09 21:03:45 | [diff] [blame] | 10 | #include "cc/layers/delegated_frame_provider.h" |
| 11 | #include "cc/layers/delegated_frame_resource_collection.h" |
[email protected] | f5b4b0f | 2013-04-02 18:16:28 | [diff] [blame] | 12 | #include "cc/layers/delegated_renderer_layer.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 13 | #include "cc/layers/solid_color_layer.h" |
kenrb | fc7c02c9 | 2015-05-29 22:20:58 | [diff] [blame] | 14 | #include "cc/layers/surface_layer.h" |
[email protected] | 7f0d825f | 2013-03-18 07:24:30 | [diff] [blame] | 15 | #include "cc/output/context_provider.h" |
[email protected] | 73405fb | 2013-12-11 04:59:37 | [diff] [blame] | 16 | #include "cc/output/copy_output_request.h" |
| 17 | #include "cc/output/copy_output_result.h" |
[email protected] | 9260757f | 2013-09-17 01:24:16 | [diff] [blame] | 18 | #include "cc/resources/single_release_callback.h" |
jbauman | 38c178eaa | 2015-06-04 04:24:54 | [diff] [blame] | 19 | #include "content/child/thread_safe_sender.h" |
[email protected] | 703dd66 | 2013-03-05 07:37:42 | [diff] [blame] | 20 | #include "content/common/browser_plugin/browser_plugin_messages.h" |
[email protected] | 95d3182 | 2014-01-03 22:21:55 | [diff] [blame] | 21 | #include "content/common/frame_messages.h" |
[email protected] | a45c46e | 2013-03-07 01:04:46 | [diff] [blame] | 22 | #include "content/common/gpu/client/context_provider_command_buffer.h" |
[email protected] | 94224ba6 | 2014-02-04 00:25:24 | [diff] [blame] | 23 | #include "content/renderer/browser_plugin/browser_plugin.h" |
[email protected] | 0d25cb6 | 2013-01-21 15:42:21 | [diff] [blame] | 24 | #include "content/renderer/browser_plugin/browser_plugin_manager.h" |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 25 | #include "content/renderer/render_frame_impl.h" |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame] | 26 | #include "content/renderer/render_frame_proxy.h" |
[email protected] | 0f21e858 | 2013-01-11 11:06:56 | [diff] [blame] | 27 | #include "content/renderer/render_thread_impl.h" |
[email protected] | 73405fb | 2013-12-11 04:59:37 | [diff] [blame] | 28 | #include "skia/ext/image_operations.h" |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 29 | #include "third_party/WebKit/public/web/WebFrame.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 30 | #include "third_party/WebKit/public/web/WebPluginContainer.h" |
[email protected] | 7f0d825f | 2013-03-18 07:24:30 | [diff] [blame] | 31 | #include "third_party/khronos/GLES2/gl2.h" |
tfarina | ebe974f0 | 2015-01-03 04:25:32 | [diff] [blame] | 32 | #include "ui/gfx/geometry/size_conversions.h" |
[email protected] | 73405fb | 2013-12-11 04:59:37 | [diff] [blame] | 33 | #include "ui/gfx/skia_util.h" |
[email protected] | 0f21e858 | 2013-01-11 11:06:56 | [diff] [blame] | 34 | |
| 35 | namespace content { |
| 36 | |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 37 | ChildFrameCompositingHelper* |
[email protected] | c092f5c | 2014-07-18 01:34:33 | [diff] [blame] | 38 | ChildFrameCompositingHelper::CreateForBrowserPlugin( |
[email protected] | 94224ba6 | 2014-02-04 00:25:24 | [diff] [blame] | 39 | const base::WeakPtr<BrowserPlugin>& browser_plugin) { |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 40 | return new ChildFrameCompositingHelper( |
kenrb | fc7c02c9 | 2015-05-29 22:20:58 | [diff] [blame] | 41 | browser_plugin, nullptr, nullptr, |
| 42 | browser_plugin->render_frame_routing_id()); |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | ChildFrameCompositingHelper* |
[email protected] | c092f5c | 2014-07-18 01:34:33 | [diff] [blame] | 46 | ChildFrameCompositingHelper::CreateForRenderFrameProxy( |
| 47 | RenderFrameProxy* render_frame_proxy) { |
lfg | fd437a27 | 2015-11-24 21:24:53 | [diff] [blame] | 48 | return new ChildFrameCompositingHelper( |
| 49 | base::WeakPtr<BrowserPlugin>(), render_frame_proxy->web_frame(), |
| 50 | render_frame_proxy, render_frame_proxy->routing_id()); |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | ChildFrameCompositingHelper::ChildFrameCompositingHelper( |
[email protected] | 94224ba6 | 2014-02-04 00:25:24 | [diff] [blame] | 54 | const base::WeakPtr<BrowserPlugin>& browser_plugin, |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 55 | blink::WebFrame* frame, |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame] | 56 | RenderFrameProxy* render_frame_proxy, |
[email protected] | 0f21e858 | 2013-01-11 11:06:56 | [diff] [blame] | 57 | int host_routing_id) |
[email protected] | 94224ba6 | 2014-02-04 00:25:24 | [diff] [blame] | 58 | : host_routing_id_(host_routing_id), |
[email protected] | f5b4b0f | 2013-04-02 18:16:28 | [diff] [blame] | 59 | last_route_id_(0), |
[email protected] | 53b4cc1 | 2013-07-18 23:02:30 | [diff] [blame] | 60 | last_output_surface_id_(0), |
[email protected] | f5b4b0f | 2013-04-02 18:16:28 | [diff] [blame] | 61 | last_host_id_(0), |
[email protected] | 0d25cb6 | 2013-01-21 15:42:21 | [diff] [blame] | 62 | ack_pending_(true), |
[email protected] | 94224ba6 | 2014-02-04 00:25:24 | [diff] [blame] | 63 | browser_plugin_(browser_plugin), |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame] | 64 | render_frame_proxy_(render_frame_proxy), |
lfg | fd437a27 | 2015-11-24 21:24:53 | [diff] [blame] | 65 | frame_(frame) {} |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 66 | |
lfg | a7d368e | 2015-02-03 23:01:37 | [diff] [blame] | 67 | ChildFrameCompositingHelper::~ChildFrameCompositingHelper() { |
| 68 | if (resource_collection_.get()) |
kenrb | fc7c02c9 | 2015-05-29 22:20:58 | [diff] [blame] | 69 | resource_collection_->SetClient(nullptr); |
lfg | a7d368e | 2015-02-03 23:01:37 | [diff] [blame] | 70 | } |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 71 | |
[email protected] | 94224ba6 | 2014-02-04 00:25:24 | [diff] [blame] | 72 | BrowserPluginManager* ChildFrameCompositingHelper::GetBrowserPluginManager() { |
| 73 | if (!browser_plugin_) |
kenrb | fc7c02c9 | 2015-05-29 22:20:58 | [diff] [blame] | 74 | return nullptr; |
[email protected] | 94224ba6 | 2014-02-04 00:25:24 | [diff] [blame] | 75 | |
fsamuel | 6c1dfeb | 2014-12-18 19:21:33 | [diff] [blame] | 76 | return BrowserPluginManager::Get(); |
[email protected] | 94224ba6 | 2014-02-04 00:25:24 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | blink::WebPluginContainer* ChildFrameCompositingHelper::GetContainer() { |
| 80 | if (!browser_plugin_) |
kenrb | fc7c02c9 | 2015-05-29 22:20:58 | [diff] [blame] | 81 | return nullptr; |
[email protected] | 94224ba6 | 2014-02-04 00:25:24 | [diff] [blame] | 82 | |
| 83 | return browser_plugin_->container(); |
| 84 | } |
| 85 | |
| 86 | int ChildFrameCompositingHelper::GetInstanceID() { |
| 87 | if (!browser_plugin_) |
| 88 | return 0; |
| 89 | |
[email protected] | 2101c4c | 2014-08-22 00:16:16 | [diff] [blame] | 90 | return browser_plugin_->browser_plugin_instance_id(); |
[email protected] | 94224ba6 | 2014-02-04 00:25:24 | [diff] [blame] | 91 | } |
| 92 | |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 93 | void ChildFrameCompositingHelper::SendCompositorFrameSwappedACKToBrowser( |
| 94 | FrameHostMsg_CompositorFrameSwappedACK_Params& params) { |
| 95 | // This function will be removed when BrowserPluginManager is removed and |
| 96 | // BrowserPlugin is modified to use a RenderFrame. |
[email protected] | 94224ba6 | 2014-02-04 00:25:24 | [diff] [blame] | 97 | if (GetBrowserPluginManager()) { |
| 98 | GetBrowserPluginManager()->Send( |
lfg | fd437a27 | 2015-11-24 21:24:53 | [diff] [blame] | 99 | new BrowserPluginHostMsg_CompositorFrameSwappedACK(GetInstanceID(), |
| 100 | params)); |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame] | 101 | } else if (render_frame_proxy_) { |
| 102 | render_frame_proxy_->Send( |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 103 | new FrameHostMsg_CompositorFrameSwappedACK(host_routing_id_, params)); |
| 104 | } |
[email protected] | 0f21e858 | 2013-01-11 11:06:56 | [diff] [blame] | 105 | } |
| 106 | |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 107 | void ChildFrameCompositingHelper::SendReclaimCompositorResourcesToBrowser( |
| 108 | FrameHostMsg_ReclaimCompositorResources_Params& params) { |
| 109 | // This function will be removed when BrowserPluginManager is removed and |
| 110 | // BrowserPlugin is modified to use a RenderFrame. |
[email protected] | 94224ba6 | 2014-02-04 00:25:24 | [diff] [blame] | 111 | if (GetBrowserPluginManager()) { |
| 112 | GetBrowserPluginManager()->Send( |
lfg | fd437a27 | 2015-11-24 21:24:53 | [diff] [blame] | 113 | new BrowserPluginHostMsg_ReclaimCompositorResources(GetInstanceID(), |
| 114 | params)); |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame] | 115 | } else if (render_frame_proxy_) { |
| 116 | render_frame_proxy_->Send( |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 117 | new FrameHostMsg_ReclaimCompositorResources(host_routing_id_, params)); |
| 118 | } |
| 119 | } |
| 120 | |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 121 | void ChildFrameCompositingHelper::DidCommitCompositorFrame() { |
[email protected] | 09f6738 | 2013-10-09 21:03:45 | [diff] [blame] | 122 | if (!resource_collection_.get() || !ack_pending_) |
[email protected] | f5b4b0f | 2013-04-02 18:16:28 | [diff] [blame] | 123 | return; |
[email protected] | 396fbb7 | 2013-01-23 02:33:43 | [diff] [blame] | 124 | |
[email protected] | 95d3182 | 2014-01-03 22:21:55 | [diff] [blame] | 125 | FrameHostMsg_CompositorFrameSwappedACK_Params params; |
| 126 | params.producing_host_id = last_host_id_; |
| 127 | params.producing_route_id = last_route_id_; |
| 128 | params.output_surface_id = last_output_surface_id_; |
| 129 | resource_collection_->TakeUnusedResourcesForChildCompositor( |
| 130 | ¶ms.ack.resources); |
[email protected] | f5b4b0f | 2013-04-02 18:16:28 | [diff] [blame] | 131 | |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 132 | SendCompositorFrameSwappedACKToBrowser(params); |
[email protected] | f5b4b0f | 2013-04-02 18:16:28 | [diff] [blame] | 133 | |
| 134 | ack_pending_ = false; |
| 135 | } |
| 136 | |
lfg | fd437a27 | 2015-11-24 21:24:53 | [diff] [blame] | 137 | void ChildFrameCompositingHelper::UpdateWebLayer(blink::WebLayer* layer) { |
[email protected] | 94224ba6 | 2014-02-04 00:25:24 | [diff] [blame] | 138 | if (GetContainer()) { |
lfg | fd437a27 | 2015-11-24 21:24:53 | [diff] [blame] | 139 | GetContainer()->setWebLayer(layer); |
[email protected] | 94224ba6 | 2014-02-04 00:25:24 | [diff] [blame] | 140 | } else if (frame_) { |
lfg | fd437a27 | 2015-11-24 21:24:53 | [diff] [blame] | 141 | frame_->setRemoteWebLayer(layer); |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 142 | } |
lfg | fd437a27 | 2015-11-24 21:24:53 | [diff] [blame] | 143 | web_layer_.reset(layer); |
[email protected] | 0f21e858 | 2013-01-11 11:06:56 | [diff] [blame] | 144 | } |
| 145 | |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 146 | void ChildFrameCompositingHelper::CheckSizeAndAdjustLayerProperties( |
[email protected] | f5b4b0f | 2013-04-02 18:16:28 | [diff] [blame] | 147 | const gfx::Size& new_size, |
| 148 | float device_scale_factor, |
| 149 | cc::Layer* layer) { |
| 150 | if (buffer_size_ != new_size) { |
| 151 | buffer_size_ = new_size; |
| 152 | // The container size is in DIP, so is the layer size. |
| 153 | // Buffer size is in physical pixels, so we need to adjust |
| 154 | // it by the device scale factor. |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 155 | gfx::Size device_scale_adjusted_size = |
| 156 | gfx::ScaleToFlooredSize(buffer_size_, 1.0f / device_scale_factor); |
[email protected] | f5b4b0f | 2013-04-02 18:16:28 | [diff] [blame] | 157 | layer->SetBounds(device_scale_adjusted_size); |
| 158 | } |
| 159 | } |
| 160 | |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 161 | void ChildFrameCompositingHelper::OnContainerDestroy() { |
fsamuel | 0147b10 | 2014-11-10 17:05:01 | [diff] [blame] | 162 | // If we have a pending ACK, then ACK now so we don't lose frames in the |
| 163 | // future. |
| 164 | DidCommitCompositorFrame(); |
| 165 | |
lfg | fd437a27 | 2015-11-24 21:24:53 | [diff] [blame] | 166 | UpdateWebLayer(nullptr); |
[email protected] | 0d25cb6 | 2013-01-21 15:42:21 | [diff] [blame] | 167 | |
dcheng | 58867a9 | 2014-08-26 02:50:22 | [diff] [blame] | 168 | if (resource_collection_.get()) |
kenrb | fc7c02c9 | 2015-05-29 22:20:58 | [diff] [blame] | 169 | resource_collection_->SetClient(nullptr); |
[email protected] | b0030b7 | 2013-11-15 20:35:53 | [diff] [blame] | 170 | |
[email protected] | 7873fe4e | 2013-11-14 18:35:22 | [diff] [blame] | 171 | ack_pending_ = false; |
kenrb | fc7c02c9 | 2015-05-29 22:20:58 | [diff] [blame] | 172 | resource_collection_ = nullptr; |
| 173 | frame_provider_ = nullptr; |
[email protected] | 0d25cb6 | 2013-01-21 15:42:21 | [diff] [blame] | 174 | } |
| 175 | |
[email protected] | f49722f | 2014-01-30 17:54:50 | [diff] [blame] | 176 | void ChildFrameCompositingHelper::ChildFrameGone() { |
lfg | fd437a27 | 2015-11-24 21:24:53 | [diff] [blame] | 177 | scoped_refptr<cc::SolidColorLayer> crashed_layer = |
| 178 | cc::SolidColorLayer::Create(cc_blink::WebLayerImpl::LayerSettings()); |
| 179 | crashed_layer->SetMasksToBounds(true); |
| 180 | crashed_layer->SetBackgroundColor(SkColorSetARGBInline(255, 0, 128, 0)); |
| 181 | blink::WebLayer* layer = new cc_blink::WebLayerImpl(crashed_layer); |
| 182 | UpdateWebLayer(layer); |
[email protected] | f49722f | 2014-01-30 17:54:50 | [diff] [blame] | 183 | } |
| 184 | |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 185 | void ChildFrameCompositingHelper::OnCompositorFrameSwapped( |
[email protected] | f5b4b0f | 2013-04-02 18:16:28 | [diff] [blame] | 186 | scoped_ptr<cc::CompositorFrame> frame, |
| 187 | int route_id, |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 188 | uint32_t output_surface_id, |
[email protected] | f197008 | 2014-04-09 04:29:56 | [diff] [blame] | 189 | int host_id, |
| 190 | base::SharedMemoryHandle handle) { |
[email protected] | 09f6738 | 2013-10-09 21:03:45 | [diff] [blame] | 191 | cc::DelegatedFrameData* frame_data = frame->delegated_frame_data.get(); |
kenrb | fc7c02c9 | 2015-05-29 22:20:58 | [diff] [blame] | 192 | |
[email protected] | b0030b7 | 2013-11-15 20:35:53 | [diff] [blame] | 193 | // Do nothing if we are getting destroyed or have no frame data. |
lfg | fd437a27 | 2015-11-24 21:24:53 | [diff] [blame] | 194 | if (!frame_data) |
[email protected] | f5b4b0f | 2013-04-02 18:16:28 | [diff] [blame] | 195 | return; |
| 196 | |
[email protected] | 09f6738 | 2013-10-09 21:03:45 | [diff] [blame] | 197 | DCHECK(!frame_data->render_pass_list.empty()); |
vmpstr | a370ef5 | 2015-11-18 10:41:28 | [diff] [blame] | 198 | cc::RenderPass* root_pass = frame_data->render_pass_list.back().get(); |
[email protected] | 09f6738 | 2013-10-09 21:03:45 | [diff] [blame] | 199 | gfx::Size frame_size = root_pass->output_rect.size(); |
| 200 | |
[email protected] | 317f17d | 2013-11-09 05:03:48 | [diff] [blame] | 201 | if (last_route_id_ != route_id || |
| 202 | last_output_surface_id_ != output_surface_id || |
| 203 | last_host_id_ != host_id) { |
| 204 | // Resource ids are scoped by the output surface. |
| 205 | // If the originating output surface doesn't match the last one, it |
| 206 | // indicates the guest's output surface may have been recreated, in which |
| 207 | // case we should recreate the DelegatedRendererLayer, to avoid matching |
| 208 | // resources from the old one with resources from the new one which would |
| 209 | // have the same id. |
kenrb | fc7c02c9 | 2015-05-29 22:20:58 | [diff] [blame] | 210 | frame_provider_ = nullptr; |
[email protected] | 317f17d | 2013-11-09 05:03:48 | [diff] [blame] | 211 | |
| 212 | // Drop the cc::DelegatedFrameResourceCollection so that we will not return |
| 213 | // any resources from the old output surface with the new output surface id. |
dcheng | 58867a9 | 2014-08-26 02:50:22 | [diff] [blame] | 214 | if (resource_collection_.get()) { |
kenrb | fc7c02c9 | 2015-05-29 22:20:58 | [diff] [blame] | 215 | resource_collection_->SetClient(nullptr); |
[email protected] | b0030b7 | 2013-11-15 20:35:53 | [diff] [blame] | 216 | |
| 217 | if (resource_collection_->LoseAllResources()) |
| 218 | SendReturnedDelegatedResources(); |
kenrb | fc7c02c9 | 2015-05-29 22:20:58 | [diff] [blame] | 219 | resource_collection_ = nullptr; |
[email protected] | 317f17d | 2013-11-09 05:03:48 | [diff] [blame] | 220 | } |
| 221 | last_output_surface_id_ = output_surface_id; |
| 222 | last_route_id_ = route_id; |
| 223 | last_host_id_ = host_id; |
| 224 | } |
dcheng | 58867a9 | 2014-08-26 02:50:22 | [diff] [blame] | 225 | if (!resource_collection_.get()) { |
[email protected] | 09f6738 | 2013-10-09 21:03:45 | [diff] [blame] | 226 | resource_collection_ = new cc::DelegatedFrameResourceCollection; |
[email protected] | b0030b7 | 2013-11-15 20:35:53 | [diff] [blame] | 227 | resource_collection_->SetClient(this); |
[email protected] | 09f6738 | 2013-10-09 21:03:45 | [diff] [blame] | 228 | } |
| 229 | if (!frame_provider_.get() || frame_provider_->frame_size() != frame_size) { |
| 230 | frame_provider_ = new cc::DelegatedFrameProvider( |
dcheng | 07945f63 | 2015-12-26 07:59:32 | [diff] [blame^] | 231 | resource_collection_.get(), std::move(frame->delegated_frame_data)); |
lfg | fd437a27 | 2015-11-24 21:24:53 | [diff] [blame] | 232 | scoped_refptr<cc::DelegatedRendererLayer> delegated_layer = |
| 233 | cc::DelegatedRendererLayer::Create( |
| 234 | cc_blink::WebLayerImpl::LayerSettings(), frame_provider_.get()); |
| 235 | delegated_layer->SetIsDrawable(true); |
fsamuel | e9741a3 | 2014-09-09 05:34:07 | [diff] [blame] | 236 | buffer_size_ = gfx::Size(); |
lfg | fd437a27 | 2015-11-24 21:24:53 | [diff] [blame] | 237 | blink::WebLayer* layer = new cc_blink::WebLayerImpl(delegated_layer); |
| 238 | UpdateWebLayer(layer); |
[email protected] | 09f6738 | 2013-10-09 21:03:45 | [diff] [blame] | 239 | } else { |
dcheng | 07945f63 | 2015-12-26 07:59:32 | [diff] [blame^] | 240 | frame_provider_->SetFrameData(std::move(frame->delegated_frame_data)); |
[email protected] | 09f6738 | 2013-10-09 21:03:45 | [diff] [blame] | 241 | } |
| 242 | |
[email protected] | 6d3a46e | 2013-11-25 23:08:53 | [diff] [blame] | 243 | CheckSizeAndAdjustLayerProperties( |
[email protected] | f5b4b0f | 2013-04-02 18:16:28 | [diff] [blame] | 244 | frame_data->render_pass_list.back()->output_rect.size(), |
| 245 | frame->metadata.device_scale_factor, |
lfg | fd437a27 | 2015-11-24 21:24:53 | [diff] [blame] | 246 | static_cast<cc_blink::WebLayerImpl*>(web_layer_.get())->layer()); |
[email protected] | f5b4b0f | 2013-04-02 18:16:28 | [diff] [blame] | 247 | |
[email protected] | f5b4b0f | 2013-04-02 18:16:28 | [diff] [blame] | 248 | ack_pending_ = true; |
| 249 | } |
| 250 | |
kenrb | fc7c02c9 | 2015-05-29 22:20:58 | [diff] [blame] | 251 | // static |
| 252 | void ChildFrameCompositingHelper::SatisfyCallback( |
jbauman | 38c178eaa | 2015-06-04 04:24:54 | [diff] [blame] | 253 | scoped_refptr<ThreadSafeSender> sender, |
| 254 | int host_routing_id, |
kenrb | fc7c02c9 | 2015-05-29 22:20:58 | [diff] [blame] | 255 | cc::SurfaceSequence sequence) { |
jbauman | 38c178eaa | 2015-06-04 04:24:54 | [diff] [blame] | 256 | // This may be called on either the main or impl thread. |
| 257 | sender->Send(new FrameHostMsg_SatisfySequence(host_routing_id, sequence)); |
kenrb | fc7c02c9 | 2015-05-29 22:20:58 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | // static |
wjmaclean | 1e720d2f | 2015-07-14 16:09:52 | [diff] [blame] | 261 | void ChildFrameCompositingHelper::SatisfyCallbackBrowserPlugin( |
| 262 | scoped_refptr<ThreadSafeSender> sender, |
| 263 | int host_routing_id, |
| 264 | int browser_plugin_instance_id, |
| 265 | cc::SurfaceSequence sequence) { |
| 266 | sender->Send(new BrowserPluginHostMsg_SatisfySequence( |
| 267 | host_routing_id, browser_plugin_instance_id, sequence)); |
| 268 | } |
| 269 | |
| 270 | // static |
kenrb | fc7c02c9 | 2015-05-29 22:20:58 | [diff] [blame] | 271 | void ChildFrameCompositingHelper::RequireCallback( |
jbauman | 38c178eaa | 2015-06-04 04:24:54 | [diff] [blame] | 272 | scoped_refptr<ThreadSafeSender> sender, |
| 273 | int host_routing_id, |
kenrb | fc7c02c9 | 2015-05-29 22:20:58 | [diff] [blame] | 274 | cc::SurfaceId id, |
| 275 | cc::SurfaceSequence sequence) { |
jbauman | 38c178eaa | 2015-06-04 04:24:54 | [diff] [blame] | 276 | // This may be called on either the main or impl thread. |
| 277 | sender->Send(new FrameHostMsg_RequireSequence(host_routing_id, id, sequence)); |
kenrb | fc7c02c9 | 2015-05-29 22:20:58 | [diff] [blame] | 278 | } |
| 279 | |
wjmaclean | 53032adf | 2015-06-15 16:49:22 | [diff] [blame] | 280 | void ChildFrameCompositingHelper::RequireCallbackBrowserPlugin( |
| 281 | scoped_refptr<ThreadSafeSender> sender, |
| 282 | int host_routing_id, |
| 283 | int browser_plugin_instance_id, |
| 284 | cc::SurfaceId id, |
| 285 | cc::SurfaceSequence sequence) { |
| 286 | // This may be called on either the main or impl thread. |
| 287 | sender->Send(new BrowserPluginHostMsg_RequireSequence( |
| 288 | host_routing_id, browser_plugin_instance_id, id, sequence)); |
| 289 | } |
| 290 | |
kenrb | fc7c02c9 | 2015-05-29 22:20:58 | [diff] [blame] | 291 | void ChildFrameCompositingHelper::OnSetSurface( |
| 292 | const cc::SurfaceId& surface_id, |
| 293 | const gfx::Size& frame_size, |
| 294 | float scale_factor, |
| 295 | const cc::SurfaceSequence& sequence) { |
lfg | fd437a27 | 2015-11-24 21:24:53 | [diff] [blame] | 296 | scoped_refptr<ThreadSafeSender> sender( |
| 297 | RenderThreadImpl::current()->thread_safe_sender()); |
| 298 | cc::SurfaceLayer::SatisfyCallback satisfy_callback = |
| 299 | render_frame_proxy_ |
| 300 | ? base::Bind(&ChildFrameCompositingHelper::SatisfyCallback, sender, |
| 301 | host_routing_id_) |
| 302 | : base::Bind( |
| 303 | &ChildFrameCompositingHelper::SatisfyCallbackBrowserPlugin, |
| 304 | sender, host_routing_id_, |
| 305 | browser_plugin_->browser_plugin_instance_id()); |
| 306 | cc::SurfaceLayer::RequireCallback require_callback = |
| 307 | render_frame_proxy_ |
| 308 | ? base::Bind(&ChildFrameCompositingHelper::RequireCallback, sender, |
| 309 | host_routing_id_) |
| 310 | : base::Bind( |
| 311 | &ChildFrameCompositingHelper::RequireCallbackBrowserPlugin, |
| 312 | sender, host_routing_id_, |
| 313 | browser_plugin_->browser_plugin_instance_id()); |
| 314 | scoped_refptr<cc::SurfaceLayer> surface_layer = |
| 315 | cc::SurfaceLayer::Create(cc_blink::WebLayerImpl::LayerSettings(), |
| 316 | satisfy_callback, require_callback); |
| 317 | surface_layer->SetSurfaceId(surface_id, scale_factor, frame_size); |
| 318 | blink::WebLayer* layer = new cc_blink::WebLayerImpl(surface_layer); |
| 319 | UpdateWebLayer(layer); |
kenrb | fc7c02c9 | 2015-05-29 22:20:58 | [diff] [blame] | 320 | |
kenrb | fc7c02c9 | 2015-05-29 22:20:58 | [diff] [blame] | 321 | UpdateVisibility(true); |
kenrb | fc7c02c9 | 2015-05-29 22:20:58 | [diff] [blame] | 322 | |
| 323 | // The RWHV creates a destruction dependency on the surface that needs to be |
wjmaclean | 53032adf | 2015-06-15 16:49:22 | [diff] [blame] | 324 | // satisfied. Note: render_frame_proxy_ is null in the case our client is a |
| 325 | // BrowserPlugin; in this case the BrowserPlugin sends its own SatisfySequence |
| 326 | // message. |
| 327 | if (render_frame_proxy_) { |
| 328 | render_frame_proxy_->Send( |
| 329 | new FrameHostMsg_SatisfySequence(host_routing_id_, sequence)); |
| 330 | } else if (browser_plugin_.get()) { |
| 331 | browser_plugin_->SendSatisfySequence(sequence); |
| 332 | } |
kenrb | fc7c02c9 | 2015-05-29 22:20:58 | [diff] [blame] | 333 | |
lfg | fd437a27 | 2015-11-24 21:24:53 | [diff] [blame] | 334 | CheckSizeAndAdjustLayerProperties( |
| 335 | frame_size, scale_factor, |
| 336 | static_cast<cc_blink::WebLayerImpl*>(web_layer_.get())->layer()); |
kenrb | fc7c02c9 | 2015-05-29 22:20:58 | [diff] [blame] | 337 | } |
| 338 | |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 339 | void ChildFrameCompositingHelper::UpdateVisibility(bool visible) { |
lfg | fd437a27 | 2015-11-24 21:24:53 | [diff] [blame] | 340 | if (web_layer_) |
| 341 | web_layer_->setDrawsContent(visible); |
[email protected] | 69b7912 | 2013-02-14 19:16:45 | [diff] [blame] | 342 | } |
| 343 | |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 344 | void ChildFrameCompositingHelper::UnusedResourcesAreAvailable() { |
[email protected] | b0030b7 | 2013-11-15 20:35:53 | [diff] [blame] | 345 | if (ack_pending_) |
| 346 | return; |
| 347 | |
| 348 | SendReturnedDelegatedResources(); |
| 349 | } |
| 350 | |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 351 | void ChildFrameCompositingHelper::SendReturnedDelegatedResources() { |
| 352 | FrameHostMsg_ReclaimCompositorResources_Params params; |
dcheng | 58867a9 | 2014-08-26 02:50:22 | [diff] [blame] | 353 | if (resource_collection_.get()) |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 354 | resource_collection_->TakeUnusedResourcesForChildCompositor( |
| 355 | ¶ms.ack.resources); |
| 356 | DCHECK(!params.ack.resources.empty()); |
[email protected] | b0030b7 | 2013-11-15 20:35:53 | [diff] [blame] | 357 | |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 358 | params.route_id = last_route_id_; |
| 359 | params.output_surface_id = last_output_surface_id_; |
| 360 | params.renderer_host_id = last_host_id_; |
| 361 | SendReclaimCompositorResourcesToBrowser(params); |
[email protected] | b0030b7 | 2013-11-15 20:35:53 | [diff] [blame] | 362 | } |
| 363 | |
[email protected] | 0f21e858 | 2013-01-11 11:06:56 | [diff] [blame] | 364 | } // namespace content |