| 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/renderer_host/delegated_frame_host.h" | 5 #include "content/browser/renderer_host/delegated_frame_host.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/time/default_tick_clock.h" | 15 #include "base/time/default_tick_clock.h" |
| 16 #include "cc/base/switches.h" | 16 #include "cc/base/switches.h" |
| 17 #include "cc/output/compositor_frame.h" | 17 #include "cc/output/compositor_frame.h" |
| 18 #include "cc/output/copy_output_request.h" | 18 #include "cc/output/copy_output_request.h" |
| 19 #include "cc/resources/single_release_callback.h" | 19 #include "cc/resources/single_release_callback.h" |
| 20 #include "cc/resources/texture_mailbox.h" | 20 #include "cc/resources/texture_mailbox.h" |
| 21 #include "cc/surfaces/compositor_frame_sink_support.h" | 21 #include "cc/surfaces/compositor_frame_sink_support.h" |
| 22 #include "cc/surfaces/local_surface_id_allocator.h" | |
| 23 #include "cc/surfaces/surface.h" | 22 #include "cc/surfaces/surface.h" |
| 24 #include "cc/surfaces/surface_factory.h" | 23 #include "cc/surfaces/surface_factory.h" |
| 25 #include "cc/surfaces/surface_hittest.h" | 24 #include "cc/surfaces/surface_hittest.h" |
| 26 #include "cc/surfaces/surface_manager.h" | 25 #include "cc/surfaces/surface_manager.h" |
| 27 #include "components/display_compositor/gl_helper.h" | 26 #include "components/display_compositor/gl_helper.h" |
| 28 #include "content/browser/compositor/surface_utils.h" | 27 #include "content/browser/compositor/surface_utils.h" |
| 29 #include "content/browser/gpu/compositor_util.h" | 28 #include "content/browser/gpu/compositor_util.h" |
| 30 #include "content/browser/renderer_host/render_widget_host_view_frame_subscriber
.h" | 29 #include "content/browser/renderer_host/render_widget_host_view_frame_subscriber
.h" |
| 31 #include "content/browser/renderer_host/resize_lock.h" | 30 #include "content/browser/renderer_host/resize_lock.h" |
| 32 #include "content/public/common/content_switches.h" | 31 #include "content/public/common/content_switches.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 50 compositor_(nullptr), | 49 compositor_(nullptr), |
| 51 tick_clock_(new base::DefaultTickClock()), | 50 tick_clock_(new base::DefaultTickClock()), |
| 52 last_compositor_frame_sink_id_(0), | 51 last_compositor_frame_sink_id_(0), |
| 53 skipped_frames_(false), | 52 skipped_frames_(false), |
| 54 background_color_(SK_ColorRED), | 53 background_color_(SK_ColorRED), |
| 55 current_scale_factor_(1.f), | 54 current_scale_factor_(1.f), |
| 56 can_lock_compositor_(YES_CAN_LOCK), | 55 can_lock_compositor_(YES_CAN_LOCK), |
| 57 delegated_frame_evictor_(new DelegatedFrameEvictor(this)) { | 56 delegated_frame_evictor_(new DelegatedFrameEvictor(this)) { |
| 58 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 57 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
| 59 factory->GetContextFactory()->AddObserver(this); | 58 factory->GetContextFactory()->AddObserver(this); |
| 60 id_allocator_.reset(new cc::LocalSurfaceIdAllocator()); | |
| 61 factory->GetContextFactoryPrivate()->GetSurfaceManager()->RegisterFrameSinkId( | 59 factory->GetContextFactoryPrivate()->GetSurfaceManager()->RegisterFrameSinkId( |
| 62 frame_sink_id_); | 60 frame_sink_id_); |
| 63 CreateCompositorFrameSinkSupport(); | 61 CreateCompositorFrameSinkSupport(); |
| 64 begin_frame_source_ = base::MakeUnique<cc::ExternalBeginFrameSource>(this); | 62 begin_frame_source_ = base::MakeUnique<cc::ExternalBeginFrameSource>(this); |
| 65 client_->SetBeginFrameSource(begin_frame_source_.get()); | 63 client_->SetBeginFrameSource(begin_frame_source_.get()); |
| 66 } | 64 } |
| 67 | 65 |
| 68 void DelegatedFrameHost::WasShown(const ui::LatencyInfo& latency_info) { | 66 void DelegatedFrameHost::WasShown(const ui::LatencyInfo& latency_info) { |
| 69 delegated_frame_evictor_->SetVisible(true); | 67 delegated_frame_evictor_->SetVisible(true); |
| 70 | 68 |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 | 364 |
| 367 // To avoid unnecessary browser composites, try to go directly to the Surface | 365 // To avoid unnecessary browser composites, try to go directly to the Surface |
| 368 // rather than through the Layer (which goes through the browser compositor). | 366 // rather than through the Layer (which goes through the browser compositor). |
| 369 if (has_frame_ && request_copy_of_output_callback_for_testing_.is_null()) { | 367 if (has_frame_ && request_copy_of_output_callback_for_testing_.is_null()) { |
| 370 support_->RequestCopyOfSurface(std::move(request)); | 368 support_->RequestCopyOfSurface(std::move(request)); |
| 371 } else { | 369 } else { |
| 372 RequestCopyOfOutput(std::move(request)); | 370 RequestCopyOfOutput(std::move(request)); |
| 373 } | 371 } |
| 374 } | 372 } |
| 375 | 373 |
| 376 void DelegatedFrameHost::SwapDelegatedFrame(uint32_t compositor_frame_sink_id, | 374 void DelegatedFrameHost::SwapDelegatedFrame( |
| 377 cc::CompositorFrame frame) { | 375 uint32_t compositor_frame_sink_id, |
| 376 const cc::LocalSurfaceId& local_surface_id, |
| 377 cc::CompositorFrame frame) { |
| 378 #if defined(OS_CHROMEOS) | 378 #if defined(OS_CHROMEOS) |
| 379 DCHECK(!resize_lock_ || !client_->IsAutoResizeEnabled()); | 379 DCHECK(!resize_lock_ || !client_->IsAutoResizeEnabled()); |
| 380 #endif | 380 #endif |
| 381 float frame_device_scale_factor = frame.metadata.device_scale_factor; | 381 float frame_device_scale_factor = frame.metadata.device_scale_factor; |
| 382 | 382 |
| 383 DCHECK(!frame.render_pass_list.empty()); | 383 DCHECK(!frame.render_pass_list.empty()); |
| 384 | 384 |
| 385 cc::RenderPass* root_pass = frame.render_pass_list.back().get(); | 385 cc::RenderPass* root_pass = frame.render_pass_list.back().get(); |
| 386 | 386 |
| 387 gfx::Size frame_size = root_pass->output_rect.size(); | 387 gfx::Size frame_size = root_pass->output_rect.size(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 | 433 |
| 434 background_color_ = frame.metadata.root_background_color; | 434 background_color_ = frame.metadata.root_background_color; |
| 435 | 435 |
| 436 if (frame_size.IsEmpty()) { | 436 if (frame_size.IsEmpty()) { |
| 437 DCHECK(frame.resource_list.empty()); | 437 DCHECK(frame.resource_list.empty()); |
| 438 EvictDelegatedFrame(); | 438 EvictDelegatedFrame(); |
| 439 } else { | 439 } else { |
| 440 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 440 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
| 441 cc::SurfaceManager* manager = | 441 cc::SurfaceManager* manager = |
| 442 factory->GetContextFactoryPrivate()->GetSurfaceManager(); | 442 factory->GetContextFactoryPrivate()->GetSurfaceManager(); |
| 443 bool allocated_new_local_surface_id = false; | |
| 444 if (!local_surface_id_.is_valid() || frame_size != current_surface_size_ || | |
| 445 frame_size_in_dip != current_frame_size_in_dip_) { | |
| 446 local_surface_id_ = id_allocator_->GenerateId(); | |
| 447 allocated_new_local_surface_id = true; | |
| 448 } | |
| 449 | 443 |
| 450 frame.metadata.latency_info.insert(frame.metadata.latency_info.end(), | 444 frame.metadata.latency_info.insert(frame.metadata.latency_info.end(), |
| 451 skipped_latency_info_list_.begin(), | 445 skipped_latency_info_list_.begin(), |
| 452 skipped_latency_info_list_.end()); | 446 skipped_latency_info_list_.end()); |
| 453 skipped_latency_info_list_.clear(); | 447 skipped_latency_info_list_.clear(); |
| 454 | 448 |
| 455 support_->SubmitCompositorFrame(local_surface_id_, std::move(frame)); | 449 support_->SubmitCompositorFrame(local_surface_id, std::move(frame)); |
| 456 | 450 |
| 457 if (allocated_new_local_surface_id || !has_frame_) { | 451 if (local_surface_id != local_surface_id_ || !has_frame_) { |
| 458 // manager must outlive compositors using it. | 452 // manager must outlive compositors using it. |
| 459 cc::SurfaceId surface_id(frame_sink_id_, local_surface_id_); | 453 cc::SurfaceId surface_id(frame_sink_id_, local_surface_id); |
| 460 cc::SurfaceInfo surface_info(surface_id, frame_device_scale_factor, | 454 cc::SurfaceInfo surface_info(surface_id, frame_device_scale_factor, |
| 461 frame_size); | 455 frame_size); |
| 462 client_->DelegatedFrameHostGetLayer()->SetShowPrimarySurface( | 456 client_->DelegatedFrameHostGetLayer()->SetShowPrimarySurface( |
| 463 surface_info, manager->reference_factory()); | 457 surface_info, manager->reference_factory()); |
| 464 current_surface_size_ = frame_size; | 458 current_surface_size_ = frame_size; |
| 465 current_scale_factor_ = frame_device_scale_factor; | 459 current_scale_factor_ = frame_device_scale_factor; |
| 466 } | 460 } |
| 467 | 461 |
| 468 has_frame_ = true; | 462 has_frame_ = true; |
| 469 } | 463 } |
| 464 local_surface_id_ = local_surface_id; |
| 465 |
| 470 released_front_lock_ = NULL; | 466 released_front_lock_ = NULL; |
| 471 current_frame_size_in_dip_ = frame_size_in_dip; | 467 current_frame_size_in_dip_ = frame_size_in_dip; |
| 472 CheckResizeLock(); | 468 CheckResizeLock(); |
| 473 | 469 |
| 474 UpdateGutters(); | 470 UpdateGutters(); |
| 475 | 471 |
| 476 if (!damage_rect_in_dip.IsEmpty()) { | 472 if (!damage_rect_in_dip.IsEmpty()) { |
| 477 client_->DelegatedFrameHostGetLayer()->OnDelegatedFrameDamage( | 473 client_->DelegatedFrameHostGetLayer()->OnDelegatedFrameDamage( |
| 478 damage_rect_in_dip); | 474 damage_rect_in_dip); |
| 479 } | 475 } |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 873 | 869 |
| 874 void DelegatedFrameHost::ResetCompositorFrameSinkSupport() { | 870 void DelegatedFrameHost::ResetCompositorFrameSinkSupport() { |
| 875 if (!support_) | 871 if (!support_) |
| 876 return; | 872 return; |
| 877 if (compositor_) | 873 if (compositor_) |
| 878 compositor_->RemoveFrameSink(frame_sink_id_); | 874 compositor_->RemoveFrameSink(frame_sink_id_); |
| 879 support_.reset(); | 875 support_.reset(); |
| 880 } | 876 } |
| 881 | 877 |
| 882 } // namespace content | 878 } // namespace content |
| OLD | NEW |