OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/child_frame_compositing_helper.h" | 5 #include "content/renderer/child_frame_compositing_helper.h" |
6 | 6 |
7 #include "cc/blink/web_layer_impl.h" | 7 #include "cc/blink/web_layer_impl.h" |
8 #include "cc/layers/delegated_frame_provider.h" | 8 #include "cc/layers/delegated_frame_provider.h" |
9 #include "cc/layers/delegated_frame_resource_collection.h" | 9 #include "cc/layers/delegated_frame_resource_collection.h" |
10 #include "cc/layers/delegated_renderer_layer.h" | 10 #include "cc/layers/delegated_renderer_layer.h" |
11 #include "cc/layers/solid_color_layer.h" | 11 #include "cc/layers/solid_color_layer.h" |
| 12 #include "cc/layers/surface_layer.h" |
12 #include "cc/output/context_provider.h" | 13 #include "cc/output/context_provider.h" |
13 #include "cc/output/copy_output_request.h" | 14 #include "cc/output/copy_output_request.h" |
14 #include "cc/output/copy_output_result.h" | 15 #include "cc/output/copy_output_result.h" |
15 #include "cc/resources/single_release_callback.h" | 16 #include "cc/resources/single_release_callback.h" |
16 #include "content/common/browser_plugin/browser_plugin_messages.h" | 17 #include "content/common/browser_plugin/browser_plugin_messages.h" |
17 #include "content/common/frame_messages.h" | 18 #include "content/common/frame_messages.h" |
18 #include "content/common/gpu/client/context_provider_command_buffer.h" | 19 #include "content/common/gpu/client/context_provider_command_buffer.h" |
19 #include "content/renderer/browser_plugin/browser_plugin.h" | 20 #include "content/renderer/browser_plugin/browser_plugin.h" |
20 #include "content/renderer/browser_plugin/browser_plugin_manager.h" | 21 #include "content/renderer/browser_plugin/browser_plugin_manager.h" |
21 #include "content/renderer/render_frame_impl.h" | 22 #include "content/renderer/render_frame_impl.h" |
22 #include "content/renderer/render_frame_proxy.h" | 23 #include "content/renderer/render_frame_proxy.h" |
23 #include "content/renderer/render_thread_impl.h" | 24 #include "content/renderer/render_thread_impl.h" |
24 #include "skia/ext/image_operations.h" | 25 #include "skia/ext/image_operations.h" |
25 #include "third_party/WebKit/public/web/WebFrame.h" | 26 #include "third_party/WebKit/public/web/WebFrame.h" |
26 #include "third_party/WebKit/public/web/WebPluginContainer.h" | 27 #include "third_party/WebKit/public/web/WebPluginContainer.h" |
27 #include "third_party/khronos/GLES2/gl2.h" | 28 #include "third_party/khronos/GLES2/gl2.h" |
28 #include "ui/gfx/geometry/size_conversions.h" | 29 #include "ui/gfx/geometry/size_conversions.h" |
29 #include "ui/gfx/skia_util.h" | 30 #include "ui/gfx/skia_util.h" |
30 | 31 |
31 namespace content { | 32 namespace content { |
32 | 33 |
33 ChildFrameCompositingHelper* | 34 ChildFrameCompositingHelper* |
34 ChildFrameCompositingHelper::CreateForBrowserPlugin( | 35 ChildFrameCompositingHelper::CreateForBrowserPlugin( |
35 const base::WeakPtr<BrowserPlugin>& browser_plugin) { | 36 const base::WeakPtr<BrowserPlugin>& browser_plugin) { |
36 return new ChildFrameCompositingHelper( | 37 return new ChildFrameCompositingHelper( |
37 browser_plugin, NULL, NULL, browser_plugin->render_frame_routing_id()); | 38 browser_plugin, nullptr, nullptr, |
| 39 browser_plugin->render_frame_routing_id()); |
38 } | 40 } |
39 | 41 |
40 ChildFrameCompositingHelper* | 42 ChildFrameCompositingHelper* |
41 ChildFrameCompositingHelper::CreateForRenderFrameProxy( | 43 ChildFrameCompositingHelper::CreateForRenderFrameProxy( |
42 RenderFrameProxy* render_frame_proxy) { | 44 RenderFrameProxy* render_frame_proxy) { |
43 return new ChildFrameCompositingHelper(base::WeakPtr<BrowserPlugin>(), | 45 return new ChildFrameCompositingHelper(base::WeakPtr<BrowserPlugin>(), |
44 render_frame_proxy->web_frame(), | 46 render_frame_proxy->web_frame(), |
45 render_frame_proxy, | 47 render_frame_proxy, |
46 render_frame_proxy->routing_id()); | 48 render_frame_proxy->routing_id()); |
47 } | 49 } |
48 | 50 |
49 ChildFrameCompositingHelper::ChildFrameCompositingHelper( | 51 ChildFrameCompositingHelper::ChildFrameCompositingHelper( |
50 const base::WeakPtr<BrowserPlugin>& browser_plugin, | 52 const base::WeakPtr<BrowserPlugin>& browser_plugin, |
51 blink::WebFrame* frame, | 53 blink::WebFrame* frame, |
52 RenderFrameProxy* render_frame_proxy, | 54 RenderFrameProxy* render_frame_proxy, |
53 int host_routing_id) | 55 int host_routing_id) |
54 : host_routing_id_(host_routing_id), | 56 : host_routing_id_(host_routing_id), |
55 last_route_id_(0), | 57 last_route_id_(0), |
56 last_output_surface_id_(0), | 58 last_output_surface_id_(0), |
57 last_host_id_(0), | 59 last_host_id_(0), |
58 ack_pending_(true), | 60 ack_pending_(true), |
59 opaque_(true), | 61 opaque_(true), |
60 browser_plugin_(browser_plugin), | 62 browser_plugin_(browser_plugin), |
61 render_frame_proxy_(render_frame_proxy), | 63 render_frame_proxy_(render_frame_proxy), |
62 frame_(frame) {} | 64 frame_(frame), |
| 65 weak_factory_(this) { |
| 66 } |
63 | 67 |
64 ChildFrameCompositingHelper::~ChildFrameCompositingHelper() { | 68 ChildFrameCompositingHelper::~ChildFrameCompositingHelper() { |
65 if (resource_collection_.get()) | 69 if (resource_collection_.get()) |
66 resource_collection_->SetClient(NULL); | 70 resource_collection_->SetClient(nullptr); |
67 } | 71 } |
68 | 72 |
69 BrowserPluginManager* ChildFrameCompositingHelper::GetBrowserPluginManager() { | 73 BrowserPluginManager* ChildFrameCompositingHelper::GetBrowserPluginManager() { |
70 if (!browser_plugin_) | 74 if (!browser_plugin_) |
71 return NULL; | 75 return nullptr; |
72 | 76 |
73 return BrowserPluginManager::Get(); | 77 return BrowserPluginManager::Get(); |
74 } | 78 } |
75 | 79 |
76 blink::WebPluginContainer* ChildFrameCompositingHelper::GetContainer() { | 80 blink::WebPluginContainer* ChildFrameCompositingHelper::GetContainer() { |
77 if (!browser_plugin_) | 81 if (!browser_plugin_) |
78 return NULL; | 82 return nullptr; |
79 | 83 |
80 return browser_plugin_->container(); | 84 return browser_plugin_->container(); |
81 } | 85 } |
82 | 86 |
83 int ChildFrameCompositingHelper::GetInstanceID() { | 87 int ChildFrameCompositingHelper::GetInstanceID() { |
84 if (!browser_plugin_) | 88 if (!browser_plugin_) |
85 return 0; | 89 return 0; |
86 | 90 |
87 return browser_plugin_->browser_plugin_instance_id(); | 91 return browser_plugin_->browser_plugin_instance_id(); |
88 } | 92 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 if (enable && !background_layer_.get()) { | 139 if (enable && !background_layer_.get()) { |
136 background_layer_ = | 140 background_layer_ = |
137 cc::SolidColorLayer::Create(cc_blink::WebLayerImpl::LayerSettings()); | 141 cc::SolidColorLayer::Create(cc_blink::WebLayerImpl::LayerSettings()); |
138 background_layer_->SetMasksToBounds(true); | 142 background_layer_->SetMasksToBounds(true); |
139 background_layer_->SetBackgroundColor( | 143 background_layer_->SetBackgroundColor( |
140 SkColorSetARGBInline(255, 255, 255, 255)); | 144 SkColorSetARGBInline(255, 255, 255, 255)); |
141 web_layer_.reset(new cc_blink::WebLayerImpl(background_layer_)); | 145 web_layer_.reset(new cc_blink::WebLayerImpl(background_layer_)); |
142 } | 146 } |
143 | 147 |
144 if (GetContainer()) { | 148 if (GetContainer()) { |
145 GetContainer()->setWebLayer(enable ? web_layer_.get() : NULL); | 149 GetContainer()->setWebLayer(enable ? web_layer_.get() : nullptr); |
146 } else if (frame_) { | 150 } else if (frame_) { |
147 frame_->setRemoteWebLayer(enable ? web_layer_.get() : NULL); | 151 frame_->setRemoteWebLayer(enable ? web_layer_.get() : nullptr); |
148 } | 152 } |
149 } | 153 } |
150 | 154 |
151 void ChildFrameCompositingHelper::CheckSizeAndAdjustLayerProperties( | 155 void ChildFrameCompositingHelper::CheckSizeAndAdjustLayerProperties( |
152 const gfx::Size& new_size, | 156 const gfx::Size& new_size, |
153 float device_scale_factor, | 157 float device_scale_factor, |
154 cc::Layer* layer) { | 158 cc::Layer* layer) { |
155 if (buffer_size_ != new_size) { | 159 if (buffer_size_ != new_size) { |
156 buffer_size_ = new_size; | 160 buffer_size_ = new_size; |
157 // The container size is in DIP, so is the layer size. | 161 // The container size is in DIP, so is the layer size. |
158 // Buffer size is in physical pixels, so we need to adjust | 162 // Buffer size is in physical pixels, so we need to adjust |
159 // it by the device scale factor. | 163 // it by the device scale factor. |
160 gfx::Size device_scale_adjusted_size = gfx::ToFlooredSize( | 164 gfx::Size device_scale_adjusted_size = gfx::ToFlooredSize( |
161 gfx::ScaleSize(buffer_size_, 1.0f / device_scale_factor)); | 165 gfx::ScaleSize(buffer_size_, 1.0f / device_scale_factor)); |
162 layer->SetBounds(device_scale_adjusted_size); | 166 layer->SetBounds(device_scale_adjusted_size); |
163 } | 167 } |
164 | 168 |
165 // Manually manage background layer for transparent webview. | 169 // Manually manage background layer for transparent webview. |
166 if (!opaque_) | 170 if (!opaque_) |
167 background_layer_->SetIsDrawable(false); | 171 background_layer_->SetIsDrawable(false); |
168 } | 172 } |
169 | 173 |
170 void ChildFrameCompositingHelper::OnContainerDestroy() { | 174 void ChildFrameCompositingHelper::OnContainerDestroy() { |
171 // If we have a pending ACK, then ACK now so we don't lose frames in the | 175 // If we have a pending ACK, then ACK now so we don't lose frames in the |
172 // future. | 176 // future. |
173 DidCommitCompositorFrame(); | 177 DidCommitCompositorFrame(); |
174 | 178 |
175 if (GetContainer()) | 179 if (GetContainer()) |
176 GetContainer()->setWebLayer(NULL); | 180 GetContainer()->setWebLayer(nullptr); |
177 | 181 |
178 if (resource_collection_.get()) | 182 if (resource_collection_.get()) |
179 resource_collection_->SetClient(NULL); | 183 resource_collection_->SetClient(nullptr); |
180 | 184 |
181 ack_pending_ = false; | 185 ack_pending_ = false; |
182 resource_collection_ = NULL; | 186 resource_collection_ = nullptr; |
183 frame_provider_ = NULL; | 187 frame_provider_ = nullptr; |
184 delegated_layer_ = NULL; | 188 delegated_layer_ = nullptr; |
185 background_layer_ = NULL; | 189 background_layer_ = nullptr; |
| 190 surface_layer_ = nullptr; |
186 web_layer_.reset(); | 191 web_layer_.reset(); |
187 } | 192 } |
188 | 193 |
189 void ChildFrameCompositingHelper::ChildFrameGone() { | 194 void ChildFrameCompositingHelper::ChildFrameGone() { |
190 background_layer_->SetBackgroundColor(SkColorSetARGBInline(255, 0, 128, 0)); | 195 background_layer_->SetBackgroundColor(SkColorSetARGBInline(255, 0, 128, 0)); |
191 background_layer_->RemoveAllChildren(); | 196 background_layer_->RemoveAllChildren(); |
192 background_layer_->SetIsDrawable(true); | 197 background_layer_->SetIsDrawable(true); |
193 background_layer_->SetContentsOpaque(true); | 198 background_layer_->SetContentsOpaque(true); |
194 } | 199 } |
195 | 200 |
196 void ChildFrameCompositingHelper::OnCompositorFrameSwapped( | 201 void ChildFrameCompositingHelper::OnCompositorFrameSwapped( |
197 scoped_ptr<cc::CompositorFrame> frame, | 202 scoped_ptr<cc::CompositorFrame> frame, |
198 int route_id, | 203 int route_id, |
199 uint32 output_surface_id, | 204 uint32 output_surface_id, |
200 int host_id, | 205 int host_id, |
201 base::SharedMemoryHandle handle) { | 206 base::SharedMemoryHandle handle) { |
202 cc::DelegatedFrameData* frame_data = frame->delegated_frame_data.get(); | 207 cc::DelegatedFrameData* frame_data = frame->delegated_frame_data.get(); |
| 208 |
| 209 // Surface IDs and compositor frames should never be received |
| 210 // interchangeably. |
| 211 DCHECK(!surface_layer_.get()); |
| 212 |
203 // Do nothing if we are getting destroyed or have no frame data. | 213 // Do nothing if we are getting destroyed or have no frame data. |
204 if (!frame_data || !background_layer_.get()) | 214 if (!frame_data || !background_layer_.get()) |
205 return; | 215 return; |
206 | 216 |
207 DCHECK(!frame_data->render_pass_list.empty()); | 217 DCHECK(!frame_data->render_pass_list.empty()); |
208 cc::RenderPass* root_pass = frame_data->render_pass_list.back(); | 218 cc::RenderPass* root_pass = frame_data->render_pass_list.back(); |
209 gfx::Size frame_size = root_pass->output_rect.size(); | 219 gfx::Size frame_size = root_pass->output_rect.size(); |
210 | 220 |
211 if (last_route_id_ != route_id || | 221 if (last_route_id_ != route_id || |
212 last_output_surface_id_ != output_surface_id || | 222 last_output_surface_id_ != output_surface_id || |
213 last_host_id_ != host_id) { | 223 last_host_id_ != host_id) { |
214 // Resource ids are scoped by the output surface. | 224 // Resource ids are scoped by the output surface. |
215 // If the originating output surface doesn't match the last one, it | 225 // If the originating output surface doesn't match the last one, it |
216 // indicates the guest's output surface may have been recreated, in which | 226 // indicates the guest's output surface may have been recreated, in which |
217 // case we should recreate the DelegatedRendererLayer, to avoid matching | 227 // case we should recreate the DelegatedRendererLayer, to avoid matching |
218 // resources from the old one with resources from the new one which would | 228 // resources from the old one with resources from the new one which would |
219 // have the same id. | 229 // have the same id. |
220 frame_provider_ = NULL; | 230 frame_provider_ = nullptr; |
221 | 231 |
222 // Drop the cc::DelegatedFrameResourceCollection so that we will not return | 232 // Drop the cc::DelegatedFrameResourceCollection so that we will not return |
223 // any resources from the old output surface with the new output surface id. | 233 // any resources from the old output surface with the new output surface id. |
224 if (resource_collection_.get()) { | 234 if (resource_collection_.get()) { |
225 resource_collection_->SetClient(NULL); | 235 resource_collection_->SetClient(nullptr); |
226 | 236 |
227 if (resource_collection_->LoseAllResources()) | 237 if (resource_collection_->LoseAllResources()) |
228 SendReturnedDelegatedResources(); | 238 SendReturnedDelegatedResources(); |
229 resource_collection_ = NULL; | 239 resource_collection_ = nullptr; |
230 } | 240 } |
231 last_output_surface_id_ = output_surface_id; | 241 last_output_surface_id_ = output_surface_id; |
232 last_route_id_ = route_id; | 242 last_route_id_ = route_id; |
233 last_host_id_ = host_id; | 243 last_host_id_ = host_id; |
234 } | 244 } |
235 if (!resource_collection_.get()) { | 245 if (!resource_collection_.get()) { |
236 resource_collection_ = new cc::DelegatedFrameResourceCollection; | 246 resource_collection_ = new cc::DelegatedFrameResourceCollection; |
237 resource_collection_->SetClient(this); | 247 resource_collection_->SetClient(this); |
238 } | 248 } |
239 if (!frame_provider_.get() || frame_provider_->frame_size() != frame_size) { | 249 if (!frame_provider_.get() || frame_provider_->frame_size() != frame_size) { |
(...skipping 12 matching lines...) Expand all Loading... |
252 } | 262 } |
253 | 263 |
254 CheckSizeAndAdjustLayerProperties( | 264 CheckSizeAndAdjustLayerProperties( |
255 frame_data->render_pass_list.back()->output_rect.size(), | 265 frame_data->render_pass_list.back()->output_rect.size(), |
256 frame->metadata.device_scale_factor, | 266 frame->metadata.device_scale_factor, |
257 delegated_layer_.get()); | 267 delegated_layer_.get()); |
258 | 268 |
259 ack_pending_ = true; | 269 ack_pending_ = true; |
260 } | 270 } |
261 | 271 |
| 272 // static |
| 273 void ChildFrameCompositingHelper::SatisfyCallback( |
| 274 base::WeakPtr<ChildFrameCompositingHelper> helper, |
| 275 cc::SurfaceSequence sequence) { |
| 276 if (helper && helper->render_frame_proxy_) { |
| 277 helper->render_frame_proxy_->Send( |
| 278 new FrameHostMsg_SatisfySequence(helper->host_routing_id_, sequence)); |
| 279 } |
| 280 } |
| 281 |
| 282 // static |
| 283 void ChildFrameCompositingHelper::RequireCallback( |
| 284 base::WeakPtr<ChildFrameCompositingHelper> helper, |
| 285 cc::SurfaceId id, |
| 286 cc::SurfaceSequence sequence) { |
| 287 if (helper && helper->render_frame_proxy_) { |
| 288 helper->render_frame_proxy_->Send(new FrameHostMsg_RequireSequence( |
| 289 helper->host_routing_id_, id, sequence)); |
| 290 } |
| 291 } |
| 292 |
| 293 void ChildFrameCompositingHelper::OnSetSurface( |
| 294 const cc::SurfaceId& surface_id, |
| 295 const gfx::Size& frame_size, |
| 296 float scale_factor, |
| 297 const cc::SurfaceSequence& sequence) { |
| 298 // Surface IDs and compositor frames should never be received |
| 299 // interchangably. |
| 300 DCHECK(!delegated_layer_.get()); |
| 301 |
| 302 // Do nothing if we are getting destroyed. |
| 303 if (!background_layer_.get()) |
| 304 return; |
| 305 |
| 306 if (!surface_layer_.get()) { |
| 307 cc::SurfaceLayer::SatisfyCallback satisfy_callback = |
| 308 base::Bind(&ChildFrameCompositingHelper::SatisfyCallback, GetWeakPtr()); |
| 309 cc::SurfaceLayer::RequireCallback require_callback = |
| 310 base::Bind(&ChildFrameCompositingHelper::RequireCallback, GetWeakPtr()); |
| 311 surface_layer_ = |
| 312 cc::SurfaceLayer::Create(cc_blink::WebLayerImpl::LayerSettings(), |
| 313 satisfy_callback, require_callback); |
| 314 } |
| 315 surface_layer_->SetSurfaceId(surface_id, scale_factor, frame_size); |
| 316 UpdateVisibility(true); |
| 317 SetContentsOpaque(opaque_); |
| 318 background_layer_->AddChild(surface_layer_); |
| 319 |
| 320 // The RWHV creates a destruction dependency on the surface that needs to be |
| 321 // satisfied. |
| 322 render_frame_proxy_->Send( |
| 323 new FrameHostMsg_SatisfySequence(host_routing_id_, sequence)); |
| 324 |
| 325 CheckSizeAndAdjustLayerProperties(frame_size, scale_factor, |
| 326 surface_layer_.get()); |
| 327 } |
| 328 |
262 void ChildFrameCompositingHelper::UpdateVisibility(bool visible) { | 329 void ChildFrameCompositingHelper::UpdateVisibility(bool visible) { |
263 if (delegated_layer_.get()) | 330 if (delegated_layer_.get()) |
264 delegated_layer_->SetIsDrawable(visible); | 331 delegated_layer_->SetIsDrawable(visible); |
| 332 if (surface_layer_.get()) |
| 333 surface_layer_->SetIsDrawable(visible); |
265 } | 334 } |
266 | 335 |
267 void ChildFrameCompositingHelper::UnusedResourcesAreAvailable() { | 336 void ChildFrameCompositingHelper::UnusedResourcesAreAvailable() { |
268 if (ack_pending_) | 337 if (ack_pending_) |
269 return; | 338 return; |
270 | 339 |
271 SendReturnedDelegatedResources(); | 340 SendReturnedDelegatedResources(); |
272 } | 341 } |
273 | 342 |
274 void ChildFrameCompositingHelper::SendReturnedDelegatedResources() { | 343 void ChildFrameCompositingHelper::SendReturnedDelegatedResources() { |
275 FrameHostMsg_ReclaimCompositorResources_Params params; | 344 FrameHostMsg_ReclaimCompositorResources_Params params; |
276 if (resource_collection_.get()) | 345 if (resource_collection_.get()) |
277 resource_collection_->TakeUnusedResourcesForChildCompositor( | 346 resource_collection_->TakeUnusedResourcesForChildCompositor( |
278 ¶ms.ack.resources); | 347 ¶ms.ack.resources); |
279 DCHECK(!params.ack.resources.empty()); | 348 DCHECK(!params.ack.resources.empty()); |
280 | 349 |
281 params.route_id = last_route_id_; | 350 params.route_id = last_route_id_; |
282 params.output_surface_id = last_output_surface_id_; | 351 params.output_surface_id = last_output_surface_id_; |
283 params.renderer_host_id = last_host_id_; | 352 params.renderer_host_id = last_host_id_; |
284 SendReclaimCompositorResourcesToBrowser(params); | 353 SendReclaimCompositorResourcesToBrowser(params); |
285 } | 354 } |
286 | 355 |
287 void ChildFrameCompositingHelper::SetContentsOpaque(bool opaque) { | 356 void ChildFrameCompositingHelper::SetContentsOpaque(bool opaque) { |
288 opaque_ = opaque; | 357 opaque_ = opaque; |
289 if (delegated_layer_.get()) | 358 if (delegated_layer_.get()) |
290 delegated_layer_->SetContentsOpaque(opaque_); | 359 delegated_layer_->SetContentsOpaque(opaque_); |
| 360 if (surface_layer_.get()) |
| 361 surface_layer_->SetContentsOpaque(opaque_); |
291 } | 362 } |
292 | 363 |
293 } // namespace content | 364 } // namespace content |
OLD | NEW |