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/browser/frame_host/render_widget_host_view_child_frame.h" | 5 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 23 matching lines...) Expand all Loading... |
34 #include "content/public/common/browser_plugin_guest_mode.h" | 34 #include "content/public/common/browser_plugin_guest_mode.h" |
35 #include "gpu/ipc/common/gpu_messages.h" | 35 #include "gpu/ipc/common/gpu_messages.h" |
36 #include "ui/gfx/geometry/size_conversions.h" | 36 #include "ui/gfx/geometry/size_conversions.h" |
37 #include "ui/gfx/geometry/size_f.h" | 37 #include "ui/gfx/geometry/size_f.h" |
38 | 38 |
39 namespace content { | 39 namespace content { |
40 | 40 |
41 RenderWidgetHostViewChildFrame::RenderWidgetHostViewChildFrame( | 41 RenderWidgetHostViewChildFrame::RenderWidgetHostViewChildFrame( |
42 RenderWidgetHost* widget_host) | 42 RenderWidgetHost* widget_host) |
43 : host_(RenderWidgetHostImpl::From(widget_host)), | 43 : host_(RenderWidgetHostImpl::From(widget_host)), |
| 44 surface_client_id_(AllocateSurfaceClientId()), |
44 next_surface_sequence_(1u), | 45 next_surface_sequence_(1u), |
45 last_output_surface_id_(0), | 46 last_output_surface_id_(0), |
46 current_surface_scale_factor_(1.f), | 47 current_surface_scale_factor_(1.f), |
47 ack_pending_count_(0), | 48 ack_pending_count_(0), |
48 frame_connector_(nullptr), | 49 frame_connector_(nullptr), |
49 begin_frame_source_(nullptr), | 50 begin_frame_source_(nullptr), |
50 observing_begin_frame_source_(false), | 51 observing_begin_frame_source_(false), |
51 parent_surface_client_id_(0), | 52 parent_surface_client_id_(0), |
52 weak_factory_(this) { | 53 weak_factory_(this) { |
53 id_allocator_ = CreateSurfaceIdAllocator(); | 54 cc::SurfaceManager* manager = GetSurfaceManager(); |
| 55 surface_factory_ = base::WrapUnique( |
| 56 new cc::SurfaceFactory(surface_client_id_, manager, this)); |
54 RegisterSurfaceNamespaceId(); | 57 RegisterSurfaceNamespaceId(); |
55 | 58 |
56 host_->SetView(this); | 59 host_->SetView(this); |
57 } | 60 } |
58 | 61 |
59 RenderWidgetHostViewChildFrame::~RenderWidgetHostViewChildFrame() { | 62 RenderWidgetHostViewChildFrame::~RenderWidgetHostViewChildFrame() { |
60 if (!surface_id_.is_null()) | 63 if (!surface_id_.is_null()) |
61 surface_factory_->Destroy(surface_id_); | 64 surface_factory_->Destroy(surface_id_); |
62 } | 65 } |
63 | 66 |
64 void RenderWidgetHostViewChildFrame::SetCrossProcessFrameConnector( | 67 void RenderWidgetHostViewChildFrame::SetCrossProcessFrameConnector( |
65 CrossProcessFrameConnector* frame_connector) { | 68 CrossProcessFrameConnector* frame_connector) { |
66 if (frame_connector_ == frame_connector) | 69 if (frame_connector_ == frame_connector) |
67 return; | 70 return; |
68 | 71 |
69 if (frame_connector_) { | 72 if (frame_connector_) { |
70 if (parent_surface_client_id_) { | 73 surface_factory_.reset(); |
71 GetSurfaceManager()->UnregisterSurfaceNamespaceHierarchy( | |
72 parent_surface_client_id_, GetSurfaceClientId()); | |
73 } | |
74 // Unregister the client here, as it is not guaranteed in tests that the | |
75 // destructor will be called. | |
76 GetSurfaceManager()->UnregisterSurfaceFactoryClient( | |
77 id_allocator_->client_id()); | |
78 | |
79 parent_surface_client_id_ = 0; | 74 parent_surface_client_id_ = 0; |
80 | 75 |
81 // After the RenderWidgetHostViewChildFrame loses the frame_connector, it | 76 // After the RenderWidgetHostViewChildFrame loses the frame_connector, it |
82 // won't be able to walk up the frame tree anymore. Clean up anything that | 77 // won't be able to walk up the frame tree anymore. Clean up anything that |
83 // needs to be done through the CrossProcessFrameConnector before it's gone. | 78 // needs to be done through the CrossProcessFrameConnector before it's gone. |
84 | 79 |
85 // Unlocks the mouse if this RenderWidgetHostView holds the lock. | 80 // Unlocks the mouse if this RenderWidgetHostView holds the lock. |
86 UnlockMouse(); | 81 UnlockMouse(); |
87 } | 82 } |
88 frame_connector_ = frame_connector; | 83 frame_connector_ = frame_connector; |
89 if (frame_connector_) { | 84 if (frame_connector_) { |
90 GetSurfaceManager()->RegisterSurfaceFactoryClient( | 85 cc::SurfaceManager* manager = GetSurfaceManager(); |
91 id_allocator_->client_id(), this); | 86 surface_factory_.reset( |
| 87 new cc::SurfaceFactory(surface_client_id_, manager, this)); |
92 RenderWidgetHostViewBase* parent_view = | 88 RenderWidgetHostViewBase* parent_view = |
93 frame_connector_->GetParentRenderWidgetHostView(); | 89 frame_connector_->GetParentRenderWidgetHostView(); |
94 if (parent_view) { | 90 if (parent_view) { |
95 parent_surface_client_id_ = parent_view->GetSurfaceClientId(); | 91 parent_surface_client_id_ = parent_view->GetSurfaceClientId(); |
96 DCHECK_NE(parent_surface_client_id_, 0u); | 92 DCHECK_NE(parent_surface_client_id_, 0u); |
97 GetSurfaceManager()->RegisterSurfaceNamespaceHierarchy( | 93 surface_factory_->SetParent(parent_surface_client_id_); |
98 parent_surface_client_id_, GetSurfaceClientId()); | |
99 } | 94 } |
100 } | 95 } |
101 } | 96 } |
102 | 97 |
103 void RenderWidgetHostViewChildFrame::InitAsChild( | 98 void RenderWidgetHostViewChildFrame::InitAsChild( |
104 gfx::NativeView parent_view) { | 99 gfx::NativeView parent_view) { |
105 NOTREACHED(); | 100 NOTREACHED(); |
106 } | 101 } |
107 | 102 |
108 bool RenderWidgetHostViewChildFrame::OnMessageReceived( | 103 bool RenderWidgetHostViewChildFrame::OnMessageReceived( |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 host_->Send(new ViewMsg_ReclaimCompositorResources( | 345 host_->Send(new ViewMsg_ReclaimCompositorResources( |
351 host_->GetRoutingID(), output_surface_id, true /* is_swap_ack */, | 346 host_->GetRoutingID(), output_surface_id, true /* is_swap_ack */, |
352 surface_returned_resources_)); | 347 surface_returned_resources_)); |
353 surface_returned_resources_.clear(); | 348 surface_returned_resources_.clear(); |
354 } | 349 } |
355 ack_pending_count_--; | 350 ack_pending_count_--; |
356 } | 351 } |
357 | 352 |
358 void RenderWidgetHostViewChildFrame::OnSwapCompositorFrame( | 353 void RenderWidgetHostViewChildFrame::OnSwapCompositorFrame( |
359 uint32_t output_surface_id, | 354 uint32_t output_surface_id, |
| 355 const cc::SurfaceId& surface_id, |
360 cc::CompositorFrame frame) { | 356 cc::CompositorFrame frame) { |
361 TRACE_EVENT0("content", | 357 TRACE_EVENT0("content", |
362 "RenderWidgetHostViewChildFrame::OnSwapCompositorFrame"); | 358 "RenderWidgetHostViewChildFrame::OnSwapCompositorFrame"); |
363 | 359 |
364 last_scroll_offset_ = frame.metadata.root_scroll_offset; | 360 last_scroll_offset_ = frame.metadata.root_scroll_offset; |
365 | 361 |
366 if (!frame_connector_) | 362 if (!frame_connector_) |
367 return; | 363 return; |
368 | 364 |
369 cc::RenderPass* root_pass = | 365 cc::RenderPass* root_pass = |
370 frame.delegated_frame_data->render_pass_list.back().get(); | 366 frame.delegated_frame_data->render_pass_list.back().get(); |
371 | 367 |
372 gfx::Size frame_size = root_pass->output_rect.size(); | 368 gfx::Size frame_size = root_pass->output_rect.size(); |
373 float scale_factor = frame.metadata.device_scale_factor; | 369 float scale_factor = frame.metadata.device_scale_factor; |
| 370 current_surface_scale_factor_ = scale_factor; |
| 371 current_surface_size_ = frame_size; |
374 | 372 |
375 // Check whether we need to recreate the cc::Surface, which means the child | 373 // Check whether we need to recreate the cc::Surface, which means the child |
376 // frame renderer has changed its output surface, or size, or scale factor. | 374 // frame renderer has changed its output surface, or size, or scale factor. |
377 if (output_surface_id != last_output_surface_id_ && surface_factory_) { | 375 if (output_surface_id != last_output_surface_id_) { |
378 surface_factory_->Destroy(surface_id_); | 376 if (surface_factory_) |
379 surface_factory_.reset(); | 377 surface_factory_->DestroyAll(); |
380 } | |
381 if (output_surface_id != last_output_surface_id_ || | |
382 frame_size != current_surface_size_ || | |
383 scale_factor != current_surface_scale_factor_) { | |
384 ClearCompositorSurfaceIfNecessary(); | |
385 last_output_surface_id_ = output_surface_id; | 378 last_output_surface_id_ = output_surface_id; |
386 current_surface_size_ = frame_size; | |
387 current_surface_scale_factor_ = scale_factor; | |
388 } | 379 } |
389 | 380 |
390 if (!surface_factory_) { | 381 if (!surface_factory_) { |
391 cc::SurfaceManager* manager = GetSurfaceManager(); | 382 cc::SurfaceManager* manager = GetSurfaceManager(); |
392 surface_factory_ = base::WrapUnique(new cc::SurfaceFactory(manager, this)); | 383 surface_factory_ = base::WrapUnique( |
| 384 new cc::SurfaceFactory(surface_client_id_, manager, this)); |
393 } | 385 } |
394 | 386 |
395 if (surface_id_.is_null()) { | 387 if (surface_id_ != surface_id) { |
396 surface_id_ = id_allocator_->GenerateId(); | 388 if (!surface_id_.is_null()) |
397 surface_factory_->Create(surface_id_); | 389 surface_factory_->Destroy(surface_id_); |
398 | 390 |
399 cc::SurfaceSequence sequence = cc::SurfaceSequence( | 391 surface_id_ = surface_id; |
400 id_allocator_->client_id(), next_surface_sequence_++); | 392 if (!surface_id.is_null()) { |
401 // The renderer process will satisfy this dependency when it creates a | 393 surface_factory_->Create(surface_id); |
402 // SurfaceLayer. | 394 |
403 cc::SurfaceManager* manager = GetSurfaceManager(); | 395 cc::SurfaceSequence sequence = |
404 manager->GetSurfaceForId(surface_id_)->AddDestructionDependency(sequence); | 396 cc::SurfaceSequence(surface_client_id_, next_surface_sequence_++); |
405 frame_connector_->SetChildFrameSurface(surface_id_, frame_size, | 397 // The renderer process will satisfy this dependency when it creates a |
406 scale_factor, sequence); | 398 // SurfaceLayer. |
| 399 cc::SurfaceManager* manager = GetSurfaceManager(); |
| 400 manager->GetSurfaceForId(surface_id_)->AddDestructionDependency(sequence); |
| 401 frame_connector_->SetChildFrameSurface(surface_id, frame_size, |
| 402 scale_factor, sequence); |
| 403 } |
407 } | 404 } |
408 | 405 |
409 cc::SurfaceFactory::DrawCallback ack_callback = | 406 cc::SurfaceFactory::DrawCallback ack_callback = |
410 base::Bind(&RenderWidgetHostViewChildFrame::SurfaceDrawn, AsWeakPtr(), | 407 base::Bind(&RenderWidgetHostViewChildFrame::SurfaceDrawn, AsWeakPtr(), |
411 output_surface_id); | 408 output_surface_id); |
412 ack_pending_count_++; | 409 ack_pending_count_++; |
413 // If this value grows very large, something is going wrong. | 410 // If this value grows very large, something is going wrong. |
414 DCHECK_LT(ack_pending_count_, 1000U); | 411 DCHECK_LT(ack_pending_count_, 1000U); |
415 surface_factory_->SubmitCompositorFrame(surface_id_, std::move(frame), | 412 surface_factory_->SubmitCompositorFrame(surface_id_, std::move(frame), |
416 ack_callback); | 413 ack_callback); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 } | 466 } |
470 | 467 |
471 bool RenderWidgetHostViewChildFrame::IsMouseLocked() { | 468 bool RenderWidgetHostViewChildFrame::IsMouseLocked() { |
472 if (!host_->delegate()) | 469 if (!host_->delegate()) |
473 return false; | 470 return false; |
474 | 471 |
475 return host_->delegate()->HasMouseLock(host_); | 472 return host_->delegate()->HasMouseLock(host_); |
476 } | 473 } |
477 | 474 |
478 uint32_t RenderWidgetHostViewChildFrame::GetSurfaceClientId() { | 475 uint32_t RenderWidgetHostViewChildFrame::GetSurfaceClientId() { |
479 return id_allocator_->client_id(); | 476 return surface_client_id_; |
480 } | 477 } |
481 | 478 |
482 void RenderWidgetHostViewChildFrame::ProcessKeyboardEvent( | 479 void RenderWidgetHostViewChildFrame::ProcessKeyboardEvent( |
483 const NativeWebKeyboardEvent& event) { | 480 const NativeWebKeyboardEvent& event) { |
484 host_->ForwardKeyboardEvent(event); | 481 host_->ForwardKeyboardEvent(event); |
485 } | 482 } |
486 | 483 |
487 void RenderWidgetHostViewChildFrame::ProcessMouseEvent( | 484 void RenderWidgetHostViewChildFrame::ProcessMouseEvent( |
488 const blink::WebMouseEvent& event, | 485 const blink::WebMouseEvent& event, |
489 const ui::LatencyInfo& latency) { | 486 const ui::LatencyInfo& latency) { |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 | 674 |
678 bool RenderWidgetHostViewChildFrame::IsChildFrameForTesting() const { | 675 bool RenderWidgetHostViewChildFrame::IsChildFrameForTesting() const { |
679 return true; | 676 return true; |
680 } | 677 } |
681 | 678 |
682 cc::SurfaceId RenderWidgetHostViewChildFrame::SurfaceIdForTesting() const { | 679 cc::SurfaceId RenderWidgetHostViewChildFrame::SurfaceIdForTesting() const { |
683 return surface_id_; | 680 return surface_id_; |
684 }; | 681 }; |
685 | 682 |
686 } // namespace content | 683 } // namespace content |
OLD | NEW |