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 "base/bind_helpers.h" | 5 #include "base/bind_helpers.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "cc/surfaces/surface.h" |
| 10 #include "cc/surfaces/surface_factory.h" |
| 11 #include "cc/surfaces/surface_manager.h" |
| 12 #include "cc/surfaces/surface_sequence.h" |
9 #include "content/browser/browser_plugin/browser_plugin_guest.h" | 13 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
| 14 #include "content/browser/compositor/surface_utils.h" |
10 #include "content/browser/frame_host/render_widget_host_view_guest.h" | 15 #include "content/browser/frame_host/render_widget_host_view_guest.h" |
11 #include "content/browser/renderer_host/render_view_host_impl.h" | 16 #include "content/browser/renderer_host/render_view_host_impl.h" |
12 #include "content/common/browser_plugin/browser_plugin_messages.h" | 17 #include "content/common/browser_plugin/browser_plugin_messages.h" |
13 #include "content/common/frame_messages.h" | 18 #include "content/common/frame_messages.h" |
14 #include "content/common/gpu/gpu_messages.h" | 19 #include "content/common/gpu/gpu_messages.h" |
15 #include "content/common/input/web_touch_event_traits.h" | 20 #include "content/common/input/web_touch_event_traits.h" |
16 #include "content/common/view_messages.h" | 21 #include "content/common/view_messages.h" |
17 #include "content/common/webplugin_geometry.h" | 22 #include "content/common/webplugin_geometry.h" |
18 #include "content/public/common/content_switches.h" | 23 #include "content/public/common/content_switches.h" |
19 #include "skia/ext/platform_canvas.h" | 24 #include "skia/ext/platform_canvas.h" |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 guest_->SetTooltipText(tooltip_text); | 204 guest_->SetTooltipText(tooltip_text); |
200 } | 205 } |
201 | 206 |
202 void RenderWidgetHostViewGuest::OnSwapCompositorFrame( | 207 void RenderWidgetHostViewGuest::OnSwapCompositorFrame( |
203 uint32 output_surface_id, | 208 uint32 output_surface_id, |
204 scoped_ptr<cc::CompositorFrame> frame) { | 209 scoped_ptr<cc::CompositorFrame> frame) { |
205 if (!guest_) | 210 if (!guest_) |
206 return; | 211 return; |
207 | 212 |
208 last_scroll_offset_ = frame->metadata.root_scroll_offset; | 213 last_scroll_offset_ = frame->metadata.root_scroll_offset; |
209 guest_->SwapCompositorFrame(output_surface_id, | 214 // When not using surfaces, the frame just gets proxied to |
210 host_->GetProcess()->GetID(), | 215 // the embedder's renderer to be composited. |
211 host_->GetRoutingID(), | 216 if (!frame->delegated_frame_data || !use_surfaces_) { |
212 frame.Pass()); | 217 guest_->SwapCompositorFrame(output_surface_id, |
| 218 host_->GetProcess()->GetID(), |
| 219 host_->GetRoutingID(), |
| 220 frame.Pass()); |
| 221 return; |
| 222 } |
| 223 |
| 224 cc::RenderPass* root_pass = |
| 225 frame->delegated_frame_data->render_pass_list.back(); |
| 226 |
| 227 gfx::Size frame_size = root_pass->output_rect.size(); |
| 228 float scale_factor = frame->metadata.device_scale_factor; |
| 229 |
| 230 guest_->UpdateGuestSizeIfNecessary(frame_size, scale_factor); |
| 231 |
| 232 // Check whether we need to recreate the cc::Surface, which means the child |
| 233 // frame renderer has changed its output surface, or size, or scale factor. |
| 234 if (output_surface_id != last_output_surface_id_ && surface_factory_) { |
| 235 surface_factory_->Destroy(surface_id_); |
| 236 surface_factory_.reset(); |
| 237 } |
| 238 if (output_surface_id != last_output_surface_id_ || |
| 239 frame_size != current_surface_size_ || |
| 240 scale_factor != current_surface_scale_factor_) { |
| 241 if (surface_factory_ && !surface_id_.is_null()) |
| 242 surface_factory_->Destroy(surface_id_); |
| 243 surface_id_ = cc::SurfaceId(); |
| 244 last_output_surface_id_ = output_surface_id; |
| 245 current_surface_size_ = frame_size; |
| 246 current_surface_scale_factor_ = scale_factor; |
| 247 } |
| 248 |
| 249 if (!surface_factory_) { |
| 250 cc::SurfaceManager* manager = GetSurfaceManager(); |
| 251 surface_factory_ = make_scoped_ptr(new cc::SurfaceFactory(manager, this)); |
| 252 } |
| 253 |
| 254 if (surface_id_.is_null()) { |
| 255 surface_id_ = id_allocator_->GenerateId(); |
| 256 // wjm: Next line makes destructor unhappy ... |
| 257 surface_factory_->Create(surface_id_); |
| 258 |
| 259 cc::SurfaceSequence sequence = cc::SurfaceSequence( |
| 260 id_allocator_->id_namespace(), next_surface_sequence_++); |
| 261 // The renderer process will satisfy this dependency when it creates a |
| 262 // SurfaceLayer. |
| 263 cc::SurfaceManager* manager = GetSurfaceManager(); |
| 264 manager->GetSurfaceForId(surface_id_)->AddDestructionDependency(sequence); |
| 265 guest_->SetChildFrameSurface(surface_id_, frame_size, scale_factor, |
| 266 sequence); |
| 267 } |
| 268 |
| 269 cc::SurfaceFactory::DrawCallback ack_callback = base::Bind( |
| 270 &RenderWidgetHostViewChildFrame::SurfaceDrawn, |
| 271 RenderWidgetHostViewChildFrame::AsWeakPtr(), output_surface_id); |
| 272 ack_pending_count_++; |
| 273 // If this value grows very large, something is going wrong. |
| 274 DCHECK(ack_pending_count_ < 1000); |
| 275 surface_factory_->SubmitFrame(surface_id_, frame.Pass(), ack_callback); |
213 } | 276 } |
214 | 277 |
215 bool RenderWidgetHostViewGuest::OnMessageReceived(const IPC::Message& msg) { | 278 bool RenderWidgetHostViewGuest::OnMessageReceived(const IPC::Message& msg) { |
216 if (!platform_view_) { | 279 if (!platform_view_) { |
217 // In theory, we can get here if there's a delay between DestroyGuestView() | 280 // In theory, we can get here if there's a delay between DestroyGuestView() |
218 // being called and when our destructor is invoked. | 281 // being called and when our destructor is invoked. |
219 return false; | 282 return false; |
220 } | 283 } |
221 | 284 |
222 return platform_view_->OnMessageReceived(msg); | 285 return platform_view_->OnMessageReceived(msg); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 } | 445 } |
383 | 446 |
384 void RenderWidgetHostViewGuest::GetScreenInfo(blink::WebScreenInfo* results) { | 447 void RenderWidgetHostViewGuest::GetScreenInfo(blink::WebScreenInfo* results) { |
385 if (!guest_) | 448 if (!guest_) |
386 return; | 449 return; |
387 RenderWidgetHostViewBase* embedder_view = GetOwnerRenderWidgetHostView(); | 450 RenderWidgetHostViewBase* embedder_view = GetOwnerRenderWidgetHostView(); |
388 if (embedder_view) | 451 if (embedder_view) |
389 embedder_view->GetScreenInfo(results); | 452 embedder_view->GetScreenInfo(results); |
390 } | 453 } |
391 | 454 |
392 uint32_t RenderWidgetHostViewGuest::GetSurfaceIdNamespace() { | |
393 // Compositing surfaces not supported. | |
394 return 0; | |
395 } | |
396 | |
397 #if defined(OS_MACOSX) | 455 #if defined(OS_MACOSX) |
398 void RenderWidgetHostViewGuest::SetActive(bool active) { | 456 void RenderWidgetHostViewGuest::SetActive(bool active) { |
399 platform_view_->SetActive(active); | 457 platform_view_->SetActive(active); |
400 } | 458 } |
401 | 459 |
402 void RenderWidgetHostViewGuest::SetWindowVisibility(bool visible) { | 460 void RenderWidgetHostViewGuest::SetWindowVisibility(bool visible) { |
403 platform_view_->SetWindowVisibility(visible); | 461 platform_view_->SetWindowVisibility(visible); |
404 } | 462 } |
405 | 463 |
406 void RenderWidgetHostViewGuest::WindowFrameChanged() { | 464 void RenderWidgetHostViewGuest::WindowFrameChanged() { |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 } | 654 } |
597 | 655 |
598 if (blink::WebInputEvent::isGestureEventType(event->type)) { | 656 if (blink::WebInputEvent::isGestureEventType(event->type)) { |
599 host_->ForwardGestureEvent( | 657 host_->ForwardGestureEvent( |
600 *static_cast<const blink::WebGestureEvent*>(event)); | 658 *static_cast<const blink::WebGestureEvent*>(event)); |
601 return; | 659 return; |
602 } | 660 } |
603 } | 661 } |
604 | 662 |
605 } // namespace content | 663 } // namespace content |
OLD | NEW |