Chromium Code Reviews| 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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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(uint32_t compositor_frame_sink_id, |
| 375 cc::LocalSurfaceId local_surface_id, | |
|
Fady Samuel
2017/03/15 12:05:48
const cc::LocalSurfaceId&
Saman Sami
2017/03/16 18:33:07
Done.
| |
| 377 cc::CompositorFrame frame) { | 376 cc::CompositorFrame frame) { |
| 378 #if defined(OS_CHROMEOS) | 377 #if defined(OS_CHROMEOS) |
| 379 DCHECK(!resize_lock_ || !client_->IsAutoResizeEnabled()); | 378 DCHECK(!resize_lock_ || !client_->IsAutoResizeEnabled()); |
| 380 #endif | 379 #endif |
| 381 float frame_device_scale_factor = frame.metadata.device_scale_factor; | 380 float frame_device_scale_factor = frame.metadata.device_scale_factor; |
| 382 | 381 |
| 383 DCHECK(!frame.render_pass_list.empty()); | 382 DCHECK(!frame.render_pass_list.empty()); |
| 384 | 383 |
| 385 cc::RenderPass* root_pass = frame.render_pass_list.back().get(); | 384 cc::RenderPass* root_pass = frame.render_pass_list.back().get(); |
| 386 | 385 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 433 | 432 |
| 434 background_color_ = frame.metadata.root_background_color; | 433 background_color_ = frame.metadata.root_background_color; |
| 435 | 434 |
| 436 if (frame_size.IsEmpty()) { | 435 if (frame_size.IsEmpty()) { |
| 437 DCHECK(frame.resource_list.empty()); | 436 DCHECK(frame.resource_list.empty()); |
| 438 EvictDelegatedFrame(); | 437 EvictDelegatedFrame(); |
| 439 } else { | 438 } else { |
| 440 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 439 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
| 441 cc::SurfaceManager* manager = | 440 cc::SurfaceManager* manager = |
| 442 factory->GetContextFactoryPrivate()->GetSurfaceManager(); | 441 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 | 442 |
| 450 frame.metadata.latency_info.insert(frame.metadata.latency_info.end(), | 443 frame.metadata.latency_info.insert(frame.metadata.latency_info.end(), |
| 451 skipped_latency_info_list_.begin(), | 444 skipped_latency_info_list_.begin(), |
| 452 skipped_latency_info_list_.end()); | 445 skipped_latency_info_list_.end()); |
| 453 skipped_latency_info_list_.clear(); | 446 skipped_latency_info_list_.clear(); |
| 454 | 447 |
| 455 support_->SubmitCompositorFrame(local_surface_id_, std::move(frame)); | 448 support_->SubmitCompositorFrame(local_surface_id, std::move(frame)); |
| 456 | 449 |
| 457 if (allocated_new_local_surface_id || !has_frame_) { | 450 if (local_surface_id != local_surface_id_ || !has_frame_) { |
| 458 // manager must outlive compositors using it. | 451 // manager must outlive compositors using it. |
| 459 cc::SurfaceId surface_id(frame_sink_id_, local_surface_id_); | 452 cc::SurfaceId surface_id(frame_sink_id_, local_surface_id); |
| 460 cc::SurfaceInfo surface_info(surface_id, frame_device_scale_factor, | 453 cc::SurfaceInfo surface_info(surface_id, frame_device_scale_factor, |
| 461 frame_size); | 454 frame_size); |
| 462 client_->DelegatedFrameHostGetLayer()->SetShowPrimarySurface( | 455 client_->DelegatedFrameHostGetLayer()->SetShowPrimarySurface( |
| 463 surface_info, manager->reference_factory()); | 456 surface_info, manager->reference_factory()); |
| 464 current_surface_size_ = frame_size; | 457 current_surface_size_ = frame_size; |
| 465 current_scale_factor_ = frame_device_scale_factor; | 458 current_scale_factor_ = frame_device_scale_factor; |
| 466 } | 459 } |
| 467 | 460 |
| 468 has_frame_ = true; | 461 has_frame_ = true; |
| 469 } | 462 } |
| 463 local_surface_id_ = local_surface_id; | |
| 464 | |
| 470 released_front_lock_ = NULL; | 465 released_front_lock_ = NULL; |
| 471 current_frame_size_in_dip_ = frame_size_in_dip; | 466 current_frame_size_in_dip_ = frame_size_in_dip; |
| 472 CheckResizeLock(); | 467 CheckResizeLock(); |
| 473 | 468 |
| 474 UpdateGutters(); | 469 UpdateGutters(); |
| 475 | 470 |
| 476 if (!damage_rect_in_dip.IsEmpty()) { | 471 if (!damage_rect_in_dip.IsEmpty()) { |
| 477 client_->DelegatedFrameHostGetLayer()->OnDelegatedFrameDamage( | 472 client_->DelegatedFrameHostGetLayer()->OnDelegatedFrameDamage( |
| 478 damage_rect_in_dip); | 473 damage_rect_in_dip); |
| 479 } | 474 } |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 849 | 844 |
| 850 void DelegatedFrameHost::ResetCompositorFrameSinkSupport() { | 845 void DelegatedFrameHost::ResetCompositorFrameSinkSupport() { |
| 851 if (!support_) | 846 if (!support_) |
| 852 return; | 847 return; |
| 853 if (compositor_) | 848 if (compositor_) |
| 854 compositor_->RemoveFrameSink(frame_sink_id_); | 849 compositor_->RemoveFrameSink(frame_sink_id_); |
| 855 support_.reset(); | 850 support_.reset(); |
| 856 } | 851 } |
| 857 | 852 |
| 858 } // namespace content | 853 } // namespace content |
| OLD | NEW |