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