| 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 |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 16 #include "cc/output/copy_output_request.h" | 16 #include "cc/output/copy_output_request.h" |
| 17 #include "cc/output/copy_output_result.h" | 17 #include "cc/output/copy_output_result.h" |
| 18 #include "cc/surfaces/surface.h" | 18 #include "cc/surfaces/surface.h" |
| 19 #include "cc/surfaces/surface_factory.h" | 19 #include "cc/surfaces/surface_factory.h" |
| 20 #include "cc/surfaces/surface_manager.h" | 20 #include "cc/surfaces/surface_manager.h" |
| 21 #include "cc/surfaces/surface_sequence.h" | |
| 22 #include "content/browser/accessibility/browser_accessibility_manager.h" | 21 #include "content/browser/accessibility/browser_accessibility_manager.h" |
| 23 #include "content/browser/browser_plugin/browser_plugin_guest.h" | 22 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
| 24 #include "content/browser/compositor/surface_utils.h" | 23 #include "content/browser/compositor/surface_utils.h" |
| 25 #include "content/browser/frame_host/cross_process_frame_connector.h" | 24 #include "content/browser/frame_host/cross_process_frame_connector.h" |
| 26 #include "content/browser/gpu/compositor_util.h" | 25 #include "content/browser/gpu/compositor_util.h" |
| 27 #include "content/browser/renderer_host/render_view_host_impl.h" | 26 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 28 #include "content/browser/renderer_host/render_widget_host_delegate.h" | 27 #include "content/browser/renderer_host/render_widget_host_delegate.h" |
| 29 #include "content/browser/renderer_host/render_widget_host_impl.h" | 28 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 30 #include "content/browser/renderer_host/render_widget_host_input_event_router.h" | 29 #include "content/browser/renderer_host/render_widget_host_input_event_router.h" |
| 31 #include "content/common/text_input_state.h" | 30 #include "content/common/text_input_state.h" |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 DCHECK_GT(ack_pending_count_, 0U); | 366 DCHECK_GT(ack_pending_count_, 0U); |
| 368 if (host_) { | 367 if (host_) { |
| 369 host_->Send(new ViewMsg_ReclaimCompositorResources( | 368 host_->Send(new ViewMsg_ReclaimCompositorResources( |
| 370 host_->GetRoutingID(), compositor_frame_sink_id, true /* is_swap_ack */, | 369 host_->GetRoutingID(), compositor_frame_sink_id, true /* is_swap_ack */, |
| 371 surface_returned_resources_)); | 370 surface_returned_resources_)); |
| 372 surface_returned_resources_.clear(); | 371 surface_returned_resources_.clear(); |
| 373 } | 372 } |
| 374 ack_pending_count_--; | 373 ack_pending_count_--; |
| 375 } | 374 } |
| 376 | 375 |
| 377 void RenderWidgetHostViewChildFrame::OnSwapCompositorFrame( | 376 bool RenderWidgetHostViewChildFrame::ShouldRecreateSurface( |
| 377 uint32_t compositor_frame_sink_id, |
| 378 const cc::CompositorFrame& frame) { |
| 379 gfx::Size new_frame_size = frame.render_pass_list.back()->output_rect.size(); |
| 380 float new_scale_factor = frame.metadata.device_scale_factor; |
| 381 |
| 382 return compositor_frame_sink_id != last_compositor_frame_sink_id_ || |
| 383 new_frame_size != current_surface_size_ || |
| 384 new_scale_factor != current_surface_scale_factor_; |
| 385 } |
| 386 |
| 387 void RenderWidgetHostViewChildFrame::ProcessCompositorFrame( |
| 378 uint32_t compositor_frame_sink_id, | 388 uint32_t compositor_frame_sink_id, |
| 379 cc::CompositorFrame frame) { | 389 cc::CompositorFrame frame) { |
| 380 TRACE_EVENT0("content", | 390 if (ShouldRecreateSurface(compositor_frame_sink_id, frame)) { |
| 381 "RenderWidgetHostViewChildFrame::OnSwapCompositorFrame"); | |
| 382 | |
| 383 last_scroll_offset_ = frame.metadata.root_scroll_offset; | |
| 384 | |
| 385 if (!frame_connector_) | |
| 386 return; | |
| 387 | |
| 388 cc::RenderPass* root_pass = frame.render_pass_list.back().get(); | |
| 389 | |
| 390 gfx::Size frame_size = root_pass->output_rect.size(); | |
| 391 float scale_factor = frame.metadata.device_scale_factor; | |
| 392 | |
| 393 // Check whether we need to recreate the cc::Surface, which means the child | |
| 394 // frame renderer has changed its frame sink, or size, or scale factor. | |
| 395 if (compositor_frame_sink_id != last_compositor_frame_sink_id_ || | |
| 396 frame_size != current_surface_size_ || | |
| 397 scale_factor != current_surface_scale_factor_) { | |
| 398 ClearCompositorSurfaceIfNecessary(); | 391 ClearCompositorSurfaceIfNecessary(); |
| 399 // If the renderer changed its frame sink, reset the surface factory to | 392 // If the renderer changed its frame sink, reset the surface factory to |
| 400 // avoid returning stale resources. | 393 // avoid returning stale resources. |
| 401 if (compositor_frame_sink_id != last_compositor_frame_sink_id_) | 394 if (compositor_frame_sink_id != last_compositor_frame_sink_id_) |
| 402 surface_factory_->Reset(); | 395 surface_factory_->Reset(); |
| 403 last_compositor_frame_sink_id_ = compositor_frame_sink_id; | 396 last_compositor_frame_sink_id_ = compositor_frame_sink_id; |
| 404 current_surface_size_ = frame_size; | 397 current_surface_size_ = frame.render_pass_list.back()->output_rect.size(); |
| 405 current_surface_scale_factor_ = scale_factor; | 398 current_surface_scale_factor_ = frame.metadata.device_scale_factor; |
| 406 } | 399 } |
| 407 | 400 |
| 408 bool allocated_new_local_frame_id = false; | 401 bool allocated_new_local_frame_id = false; |
| 409 if (!local_frame_id_.is_valid()) { | 402 if (!local_frame_id_.is_valid()) { |
| 410 local_frame_id_ = id_allocator_->GenerateId(); | 403 local_frame_id_ = id_allocator_->GenerateId(); |
| 411 allocated_new_local_frame_id = true; | 404 allocated_new_local_frame_id = true; |
| 412 } | 405 } |
| 413 | 406 |
| 414 cc::SurfaceFactory::DrawCallback ack_callback = | 407 cc::SurfaceFactory::DrawCallback ack_callback = |
| 415 base::Bind(&RenderWidgetHostViewChildFrame::SurfaceDrawn, AsWeakPtr(), | 408 base::Bind(&RenderWidgetHostViewChildFrame::SurfaceDrawn, AsWeakPtr(), |
| 416 compositor_frame_sink_id); | 409 compositor_frame_sink_id); |
| 417 ack_pending_count_++; | 410 ack_pending_count_++; |
| 418 // If this value grows very large, something is going wrong. | 411 // If this value grows very large, something is going wrong. |
| 419 DCHECK_LT(ack_pending_count_, 1000U); | 412 DCHECK_LT(ack_pending_count_, 1000U); |
| 420 surface_factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), | 413 surface_factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), |
| 421 ack_callback); | 414 ack_callback); |
| 422 | 415 |
| 423 if (allocated_new_local_frame_id) { | 416 if (allocated_new_local_frame_id) { |
| 424 cc::SurfaceSequence sequence = | 417 cc::SurfaceSequence sequence = |
| 425 cc::SurfaceSequence(frame_sink_id_, next_surface_sequence_++); | 418 cc::SurfaceSequence(frame_sink_id_, next_surface_sequence_++); |
| 426 // The renderer process will satisfy this dependency when it creates a | 419 // The renderer process will satisfy this dependency when it creates a |
| 427 // SurfaceLayer. | 420 // SurfaceLayer. |
| 428 cc::SurfaceManager* manager = GetSurfaceManager(); | 421 cc::SurfaceManager* manager = GetSurfaceManager(); |
| 429 manager->GetSurfaceForId(cc::SurfaceId(frame_sink_id_, local_frame_id_)) | 422 manager->GetSurfaceForId(cc::SurfaceId(frame_sink_id_, local_frame_id_)) |
| 430 ->AddDestructionDependency(sequence); | 423 ->AddDestructionDependency(sequence); |
| 431 frame_connector_->SetChildFrameSurface( | 424 SendSurfaceInfoToChild(sequence); |
| 432 cc::SurfaceId(frame_sink_id_, local_frame_id_), frame_size, | |
| 433 scale_factor, sequence); | |
| 434 } | 425 } |
| 435 ProcessFrameSwappedCallbacks(); | 426 ProcessFrameSwappedCallbacks(); |
| 436 } | 427 } |
| 437 | 428 |
| 429 void RenderWidgetHostViewChildFrame::SendSurfaceInfoToChild( |
| 430 const cc::SurfaceSequence& sequence) { |
| 431 frame_connector_->SetChildFrameSurface( |
| 432 cc::SurfaceId(frame_sink_id_, local_frame_id_), current_surface_size_, |
| 433 current_surface_scale_factor_, sequence); |
| 434 } |
| 435 |
| 436 void RenderWidgetHostViewChildFrame::OnSwapCompositorFrame( |
| 437 uint32_t compositor_frame_sink_id, |
| 438 cc::CompositorFrame frame) { |
| 439 TRACE_EVENT0("content", |
| 440 "RenderWidgetHostViewChildFrame::OnSwapCompositorFrame"); |
| 441 last_scroll_offset_ = frame.metadata.root_scroll_offset; |
| 442 if (!frame_connector_) |
| 443 return; |
| 444 ProcessCompositorFrame(compositor_frame_sink_id, std::move(frame)); |
| 445 } |
| 446 |
| 438 void RenderWidgetHostViewChildFrame::ProcessFrameSwappedCallbacks() { | 447 void RenderWidgetHostViewChildFrame::ProcessFrameSwappedCallbacks() { |
| 439 // We only use callbacks once, therefore we make a new list for registration | 448 // We only use callbacks once, therefore we make a new list for registration |
| 440 // before we start, and discard the old list entries when we are done. | 449 // before we start, and discard the old list entries when we are done. |
| 441 FrameSwappedCallbackList process_callbacks; | 450 FrameSwappedCallbackList process_callbacks; |
| 442 process_callbacks.swap(frame_swapped_callbacks_); | 451 process_callbacks.swap(frame_swapped_callbacks_); |
| 443 for (std::unique_ptr<base::Closure>& callback : process_callbacks) | 452 for (std::unique_ptr<base::Closure>& callback : process_callbacks) |
| 444 callback->Run(); | 453 callback->Run(); |
| 445 } | 454 } |
| 446 | 455 |
| 447 gfx::Rect RenderWidgetHostViewChildFrame::GetBoundsInRootWindow() { | 456 gfx::Rect RenderWidgetHostViewChildFrame::GetBoundsInRootWindow() { |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 744 | 753 |
| 745 bool RenderWidgetHostViewChildFrame::IsChildFrameForTesting() const { | 754 bool RenderWidgetHostViewChildFrame::IsChildFrameForTesting() const { |
| 746 return true; | 755 return true; |
| 747 } | 756 } |
| 748 | 757 |
| 749 cc::SurfaceId RenderWidgetHostViewChildFrame::SurfaceIdForTesting() const { | 758 cc::SurfaceId RenderWidgetHostViewChildFrame::SurfaceIdForTesting() const { |
| 750 return cc::SurfaceId(frame_sink_id_, local_frame_id_); | 759 return cc::SurfaceId(frame_sink_id_, local_frame_id_); |
| 751 }; | 760 }; |
| 752 | 761 |
| 753 } // namespace content | 762 } // namespace content |
| OLD | NEW |