| 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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 void RenderWidgetHostViewChildFrame::Focus() { | 128 void RenderWidgetHostViewChildFrame::Focus() { |
| 129 } | 129 } |
| 130 | 130 |
| 131 bool RenderWidgetHostViewChildFrame::HasFocus() const { | 131 bool RenderWidgetHostViewChildFrame::HasFocus() const { |
| 132 if (frame_connector_) | 132 if (frame_connector_) |
| 133 return frame_connector_->HasFocus(); | 133 return frame_connector_->HasFocus(); |
| 134 return false; | 134 return false; |
| 135 } | 135 } |
| 136 | 136 |
| 137 bool RenderWidgetHostViewChildFrame::IsSurfaceAvailableForCopy() const { | 137 bool RenderWidgetHostViewChildFrame::IsSurfaceAvailableForCopy() const { |
| 138 return local_surface_id_.is_valid(); | 138 return has_frame_; |
| 139 } | 139 } |
| 140 | 140 |
| 141 void RenderWidgetHostViewChildFrame::Show() { | 141 void RenderWidgetHostViewChildFrame::Show() { |
| 142 if (!host_->is_hidden()) | 142 if (!host_->is_hidden()) |
| 143 return; | 143 return; |
| 144 host_->WasShown(ui::LatencyInfo()); | 144 host_->WasShown(ui::LatencyInfo()); |
| 145 } | 145 } |
| 146 | 146 |
| 147 void RenderWidgetHostViewChildFrame::Hide() { | 147 void RenderWidgetHostViewChildFrame::Hide() { |
| 148 if (host_->is_hidden()) | 148 if (host_->is_hidden()) |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 } | 342 } |
| 343 | 343 |
| 344 void RenderWidgetHostViewChildFrame::DidReceiveCompositorFrameAck() { | 344 void RenderWidgetHostViewChildFrame::DidReceiveCompositorFrameAck() { |
| 345 if (!host_) | 345 if (!host_) |
| 346 return; | 346 return; |
| 347 host_->Send(new ViewMsg_ReclaimCompositorResources( | 347 host_->Send(new ViewMsg_ReclaimCompositorResources( |
| 348 host_->GetRoutingID(), last_compositor_frame_sink_id_, | 348 host_->GetRoutingID(), last_compositor_frame_sink_id_, |
| 349 true /* is_swap_ack */, cc::ReturnedResourceArray())); | 349 true /* is_swap_ack */, cc::ReturnedResourceArray())); |
| 350 } | 350 } |
| 351 | 351 |
| 352 bool RenderWidgetHostViewChildFrame::ShouldCreateNewSurfaceId( | |
| 353 uint32_t compositor_frame_sink_id, | |
| 354 const cc::CompositorFrame& frame) { | |
| 355 gfx::Size new_frame_size = frame.render_pass_list.back()->output_rect.size(); | |
| 356 float new_scale_factor = frame.metadata.device_scale_factor; | |
| 357 | |
| 358 return compositor_frame_sink_id != last_compositor_frame_sink_id_ || | |
| 359 new_frame_size != current_surface_size_ || | |
| 360 new_scale_factor != current_surface_scale_factor_; | |
| 361 } | |
| 362 | |
| 363 void RenderWidgetHostViewChildFrame::ProcessCompositorFrame( | 352 void RenderWidgetHostViewChildFrame::ProcessCompositorFrame( |
| 364 uint32_t compositor_frame_sink_id, | 353 uint32_t compositor_frame_sink_id, |
| 365 cc::CompositorFrame frame) { | 354 cc::CompositorFrame frame) { |
| 366 if (ShouldCreateNewSurfaceId(compositor_frame_sink_id, frame)) { | 355 // If the renderer changed its frame sink, reset the |
| 367 ClearCompositorSurfaceIfNecessary(); | 356 // CompositorFrameSinkSupport to avoid returning stale resources. |
| 368 // If the renderer changed its frame sink, reset the | 357 if (compositor_frame_sink_id != last_compositor_frame_sink_id_) { |
| 369 // CompositorFrameSinkSupport to avoid returning stale resources. | 358 ResetCompositorFrameSinkSupport(); |
| 370 if (compositor_frame_sink_id != last_compositor_frame_sink_id_) { | 359 CreateCompositorFrameSinkSupport(); |
| 371 ResetCompositorFrameSinkSupport(); | |
| 372 CreateCompositorFrameSinkSupport(); | |
| 373 } | |
| 374 last_compositor_frame_sink_id_ = compositor_frame_sink_id; | 360 last_compositor_frame_sink_id_ = compositor_frame_sink_id; |
| 361 local_surface_id_ = cc::LocalSurfaceId(); |
| 362 } |
| 363 |
| 364 gfx::Size new_frame_size = frame.render_pass_list.back()->output_rect.size(); |
| 365 float new_scale_factor = frame.metadata.device_scale_factor; |
| 366 bool allocated_new_local_surface_id = false; |
| 367 if (!local_surface_id_.is_valid() || |
| 368 new_frame_size != current_surface_size_ || |
| 369 new_scale_factor != current_surface_scale_factor_) { |
| 370 local_surface_id_ = id_allocator_->GenerateId(); |
| 375 current_surface_size_ = frame.render_pass_list.back()->output_rect.size(); | 371 current_surface_size_ = frame.render_pass_list.back()->output_rect.size(); |
| 376 current_surface_scale_factor_ = frame.metadata.device_scale_factor; | 372 current_surface_scale_factor_ = frame.metadata.device_scale_factor; |
| 377 } | |
| 378 | |
| 379 bool allocated_new_local_surface_id = false; | |
| 380 if (!local_surface_id_.is_valid()) { | |
| 381 local_surface_id_ = id_allocator_->GenerateId(); | |
| 382 allocated_new_local_surface_id = true; | 373 allocated_new_local_surface_id = true; |
| 383 } | 374 } |
| 384 | 375 |
| 385 support_->SubmitCompositorFrame(local_surface_id_, std::move(frame)); | 376 support_->SubmitCompositorFrame(local_surface_id_, std::move(frame)); |
| 386 if (allocated_new_local_surface_id) | 377 has_frame_ = true; |
| 378 |
| 379 if (allocated_new_local_surface_id || HasEmbedderChanged()) |
| 387 SendSurfaceInfoToEmbedder(); | 380 SendSurfaceInfoToEmbedder(); |
| 388 ProcessFrameSwappedCallbacks(); | 381 ProcessFrameSwappedCallbacks(); |
| 389 } | 382 } |
| 390 | 383 |
| 391 void RenderWidgetHostViewChildFrame::SendSurfaceInfoToEmbedder() { | 384 void RenderWidgetHostViewChildFrame::SendSurfaceInfoToEmbedder() { |
| 392 cc::SurfaceSequence sequence = | 385 cc::SurfaceSequence sequence = |
| 393 cc::SurfaceSequence(frame_sink_id_, next_surface_sequence_++); | 386 cc::SurfaceSequence(frame_sink_id_, next_surface_sequence_++); |
| 394 cc::SurfaceManager* manager = GetSurfaceManager(); | 387 cc::SurfaceManager* manager = GetSurfaceManager(); |
| 395 cc::SurfaceId surface_id(frame_sink_id_, local_surface_id_); | 388 cc::SurfaceId surface_id(frame_sink_id_, local_surface_id_); |
| 396 // The renderer process will satisfy this dependency when it creates a | 389 // The renderer process will satisfy this dependency when it creates a |
| 397 // SurfaceLayer. | 390 // SurfaceLayer. |
| 398 manager->GetSurfaceForId(surface_id)->AddDestructionDependency(sequence); | 391 manager->RequireSequence(surface_id, sequence); |
| 399 cc::SurfaceInfo surface_info(surface_id, current_surface_scale_factor_, | 392 cc::SurfaceInfo surface_info(surface_id, current_surface_scale_factor_, |
| 400 current_surface_size_); | 393 current_surface_size_); |
| 401 SendSurfaceInfoToEmbedderImpl(surface_info, sequence); | 394 SendSurfaceInfoToEmbedderImpl(surface_info, sequence); |
| 402 } | 395 } |
| 403 | 396 |
| 404 void RenderWidgetHostViewChildFrame::SendSurfaceInfoToEmbedderImpl( | 397 void RenderWidgetHostViewChildFrame::SendSurfaceInfoToEmbedderImpl( |
| 405 const cc::SurfaceInfo& surface_info, | 398 const cc::SurfaceInfo& surface_info, |
| 406 const cc::SurfaceSequence& sequence) { | 399 const cc::SurfaceSequence& sequence) { |
| 407 frame_connector_->SetChildFrameSurface(surface_info, sequence); | 400 frame_connector_->SetChildFrameSurface(surface_info, sequence); |
| 408 } | 401 } |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 } | 661 } |
| 669 | 662 |
| 670 BrowserAccessibilityManager* | 663 BrowserAccessibilityManager* |
| 671 RenderWidgetHostViewChildFrame::CreateBrowserAccessibilityManager( | 664 RenderWidgetHostViewChildFrame::CreateBrowserAccessibilityManager( |
| 672 BrowserAccessibilityDelegate* delegate, bool for_root_frame) { | 665 BrowserAccessibilityDelegate* delegate, bool for_root_frame) { |
| 673 return BrowserAccessibilityManager::Create( | 666 return BrowserAccessibilityManager::Create( |
| 674 BrowserAccessibilityManager::GetEmptyDocument(), delegate); | 667 BrowserAccessibilityManager::GetEmptyDocument(), delegate); |
| 675 } | 668 } |
| 676 | 669 |
| 677 void RenderWidgetHostViewChildFrame::ClearCompositorSurfaceIfNecessary() { | 670 void RenderWidgetHostViewChildFrame::ClearCompositorSurfaceIfNecessary() { |
| 678 if (support_) | 671 if (!support_) |
| 679 support_->EvictFrame(); | 672 return; |
| 680 local_surface_id_ = cc::LocalSurfaceId(); | 673 support_->EvictFrame(); |
| 674 has_frame_ = false; |
| 681 } | 675 } |
| 682 | 676 |
| 683 bool RenderWidgetHostViewChildFrame::IsChildFrameForTesting() const { | 677 bool RenderWidgetHostViewChildFrame::IsChildFrameForTesting() const { |
| 684 return true; | 678 return true; |
| 685 } | 679 } |
| 686 | 680 |
| 687 cc::SurfaceId RenderWidgetHostViewChildFrame::SurfaceIdForTesting() const { | 681 cc::SurfaceId RenderWidgetHostViewChildFrame::SurfaceIdForTesting() const { |
| 688 return cc::SurfaceId(frame_sink_id_, local_surface_id_); | 682 return cc::SurfaceId(frame_sink_id_, local_surface_id_); |
| 689 }; | 683 }; |
| 690 | 684 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 705 void RenderWidgetHostViewChildFrame::ResetCompositorFrameSinkSupport() { | 699 void RenderWidgetHostViewChildFrame::ResetCompositorFrameSinkSupport() { |
| 706 if (!support_) | 700 if (!support_) |
| 707 return; | 701 return; |
| 708 if (parent_frame_sink_id_.is_valid()) { | 702 if (parent_frame_sink_id_.is_valid()) { |
| 709 GetSurfaceManager()->UnregisterFrameSinkHierarchy(parent_frame_sink_id_, | 703 GetSurfaceManager()->UnregisterFrameSinkHierarchy(parent_frame_sink_id_, |
| 710 frame_sink_id_); | 704 frame_sink_id_); |
| 711 } | 705 } |
| 712 support_.reset(); | 706 support_.reset(); |
| 713 } | 707 } |
| 714 | 708 |
| 709 bool RenderWidgetHostViewChildFrame::HasEmbedderChanged() { |
| 710 return false; |
| 711 } |
| 712 |
| 715 } // namespace content | 713 } // namespace content |
| OLD | NEW |