| 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> |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 DelegatedFrameHost::DelegatedFrameHost(const cc::FrameSinkId& frame_sink_id, | 44 DelegatedFrameHost::DelegatedFrameHost(const cc::FrameSinkId& frame_sink_id, |
| 45 DelegatedFrameHostClient* client) | 45 DelegatedFrameHostClient* client) |
| 46 : frame_sink_id_(frame_sink_id), | 46 : frame_sink_id_(frame_sink_id), |
| 47 client_(client), | 47 client_(client), |
| 48 compositor_(nullptr), | 48 compositor_(nullptr), |
| 49 tick_clock_(new base::DefaultTickClock()), | 49 tick_clock_(new base::DefaultTickClock()), |
| 50 skipped_frames_(false), | 50 skipped_frames_(false), |
| 51 background_color_(SK_ColorRED), | 51 background_color_(SK_ColorRED), |
| 52 current_scale_factor_(1.f), | 52 current_scale_factor_(1.f), |
| 53 delegated_frame_evictor_(new DelegatedFrameEvictor(this)) { | 53 frame_evictor_(new viz::FrameEvictor(this)) { |
| 54 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 54 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
| 55 factory->GetContextFactory()->AddObserver(this); | 55 factory->GetContextFactory()->AddObserver(this); |
| 56 factory->GetContextFactoryPrivate()->GetSurfaceManager()->RegisterFrameSinkId( | 56 factory->GetContextFactoryPrivate()->GetSurfaceManager()->RegisterFrameSinkId( |
| 57 frame_sink_id_); | 57 frame_sink_id_); |
| 58 CreateCompositorFrameSinkSupport(); | 58 CreateCompositorFrameSinkSupport(); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void DelegatedFrameHost::WasShown(const ui::LatencyInfo& latency_info) { | 61 void DelegatedFrameHost::WasShown(const ui::LatencyInfo& latency_info) { |
| 62 delegated_frame_evictor_->SetVisible(true); | 62 frame_evictor_->SetVisible(true); |
| 63 | 63 |
| 64 if (!has_frame_ && !released_front_lock_.get()) { | 64 if (!has_frame_ && !released_front_lock_.get()) { |
| 65 if (compositor_) | 65 if (compositor_) |
| 66 released_front_lock_ = compositor_->GetCompositorLock(nullptr); | 66 released_front_lock_ = compositor_->GetCompositorLock(nullptr); |
| 67 } | 67 } |
| 68 | 68 |
| 69 if (compositor_) { | 69 if (compositor_) { |
| 70 compositor_->SetLatencyInfo(latency_info); | 70 compositor_->SetLatencyInfo(latency_info); |
| 71 } | 71 } |
| 72 } | 72 } |
| 73 | 73 |
| 74 bool DelegatedFrameHost::HasSavedFrame() { | 74 bool DelegatedFrameHost::HasSavedFrame() { |
| 75 return delegated_frame_evictor_->HasFrame(); | 75 return frame_evictor_->HasFrame(); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void DelegatedFrameHost::WasHidden() { | 78 void DelegatedFrameHost::WasHidden() { |
| 79 delegated_frame_evictor_->SetVisible(false); | 79 frame_evictor_->SetVisible(false); |
| 80 released_front_lock_ = NULL; | 80 released_front_lock_ = NULL; |
| 81 } | 81 } |
| 82 | 82 |
| 83 void DelegatedFrameHost::MaybeCreateResizeLock() { | 83 void DelegatedFrameHost::MaybeCreateResizeLock() { |
| 84 DCHECK(!resize_lock_); | 84 DCHECK(!resize_lock_); |
| 85 | 85 |
| 86 if (!compositor_) | 86 if (!compositor_) |
| 87 return; | 87 return; |
| 88 | 88 |
| 89 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 89 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 CheckResizeLock(); | 473 CheckResizeLock(); |
| 474 | 474 |
| 475 UpdateGutters(); | 475 UpdateGutters(); |
| 476 | 476 |
| 477 if (!damage_rect_in_dip.IsEmpty()) { | 477 if (!damage_rect_in_dip.IsEmpty()) { |
| 478 client_->DelegatedFrameHostGetLayer()->OnDelegatedFrameDamage( | 478 client_->DelegatedFrameHostGetLayer()->OnDelegatedFrameDamage( |
| 479 damage_rect_in_dip); | 479 damage_rect_in_dip); |
| 480 } | 480 } |
| 481 | 481 |
| 482 if (has_frame_) { | 482 if (has_frame_) { |
| 483 delegated_frame_evictor_->SwappedFrame( | 483 frame_evictor_->SwappedFrame(client_->DelegatedFrameHostIsVisible()); |
| 484 client_->DelegatedFrameHostIsVisible()); | |
| 485 } | 484 } |
| 486 // Note: the frame may have been evicted immediately. | 485 // Note: the frame may have been evicted immediately. |
| 487 | 486 |
| 488 DidFinishFrame(ack); | 487 DidFinishFrame(ack); |
| 489 } | 488 } |
| 490 | 489 |
| 491 void DelegatedFrameHost::ClearDelegatedFrame() { | 490 void DelegatedFrameHost::ClearDelegatedFrame() { |
| 492 EvictDelegatedFrame(); | 491 EvictDelegatedFrame(); |
| 493 } | 492 } |
| 494 | 493 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 517 void DelegatedFrameHost::OnBeginFrame(const cc::BeginFrameArgs& args) { | 516 void DelegatedFrameHost::OnBeginFrame(const cc::BeginFrameArgs& args) { |
| 518 client_->OnBeginFrame(args); | 517 client_->OnBeginFrame(args); |
| 519 } | 518 } |
| 520 | 519 |
| 521 void DelegatedFrameHost::EvictDelegatedFrame() { | 520 void DelegatedFrameHost::EvictDelegatedFrame() { |
| 522 if (!has_frame_) | 521 if (!has_frame_) |
| 523 return; | 522 return; |
| 524 client_->DelegatedFrameHostGetLayer()->SetShowSolidColorContent(); | 523 client_->DelegatedFrameHostGetLayer()->SetShowSolidColorContent(); |
| 525 support_->EvictFrame(); | 524 support_->EvictFrame(); |
| 526 has_frame_ = false; | 525 has_frame_ = false; |
| 527 delegated_frame_evictor_->DiscardedFrame(); | 526 frame_evictor_->DiscardedFrame(); |
| 528 UpdateGutters(); | 527 UpdateGutters(); |
| 529 } | 528 } |
| 530 | 529 |
| 531 // static | 530 // static |
| 532 void DelegatedFrameHost::ReturnSubscriberTexture( | 531 void DelegatedFrameHost::ReturnSubscriberTexture( |
| 533 base::WeakPtr<DelegatedFrameHost> dfh, | 532 base::WeakPtr<DelegatedFrameHost> dfh, |
| 534 scoped_refptr<OwnedMailbox> subscriber_texture, | 533 scoped_refptr<OwnedMailbox> subscriber_texture, |
| 535 const gpu::SyncToken& sync_token) { | 534 const gpu::SyncToken& sync_token) { |
| 536 if (!subscriber_texture.get()) | 535 if (!subscriber_texture.get()) |
| 537 return; | 536 return; |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 801 vsync_manager_->RemoveObserver(this); | 800 vsync_manager_->RemoveObserver(this); |
| 802 vsync_manager_ = nullptr; | 801 vsync_manager_ = nullptr; |
| 803 } | 802 } |
| 804 | 803 |
| 805 compositor_->RemoveFrameSink(frame_sink_id_); | 804 compositor_->RemoveFrameSink(frame_sink_id_); |
| 806 compositor_ = nullptr; | 805 compositor_ = nullptr; |
| 807 } | 806 } |
| 808 | 807 |
| 809 void DelegatedFrameHost::LockResources() { | 808 void DelegatedFrameHost::LockResources() { |
| 810 DCHECK(local_surface_id_.is_valid()); | 809 DCHECK(local_surface_id_.is_valid()); |
| 811 delegated_frame_evictor_->LockFrame(); | 810 frame_evictor_->LockFrame(); |
| 812 } | 811 } |
| 813 | 812 |
| 814 void DelegatedFrameHost::RequestCopyOfOutput( | 813 void DelegatedFrameHost::RequestCopyOfOutput( |
| 815 std::unique_ptr<cc::CopyOutputRequest> request) { | 814 std::unique_ptr<cc::CopyOutputRequest> request) { |
| 816 // If a specific area has not been requested, set one to ensure correct | 815 // If a specific area has not been requested, set one to ensure correct |
| 817 // clipping occurs. | 816 // clipping occurs. |
| 818 if (!request->has_area()) | 817 if (!request->has_area()) |
| 819 request->set_area(gfx::Rect(current_frame_size_in_dip_)); | 818 request->set_area(gfx::Rect(current_frame_size_in_dip_)); |
| 820 | 819 |
| 821 if (request_copy_of_output_callback_for_testing_.is_null()) { | 820 if (request_copy_of_output_callback_for_testing_.is_null()) { |
| 822 client_->DelegatedFrameHostGetLayer()->RequestCopyOfOutput( | 821 client_->DelegatedFrameHostGetLayer()->RequestCopyOfOutput( |
| 823 std::move(request)); | 822 std::move(request)); |
| 824 } else { | 823 } else { |
| 825 request_copy_of_output_callback_for_testing_.Run(std::move(request)); | 824 request_copy_of_output_callback_for_testing_.Run(std::move(request)); |
| 826 } | 825 } |
| 827 } | 826 } |
| 828 | 827 |
| 829 void DelegatedFrameHost::UnlockResources() { | 828 void DelegatedFrameHost::UnlockResources() { |
| 830 DCHECK(local_surface_id_.is_valid()); | 829 DCHECK(local_surface_id_.is_valid()); |
| 831 delegated_frame_evictor_->UnlockFrame(); | 830 frame_evictor_->UnlockFrame(); |
| 832 } | 831 } |
| 833 | 832 |
| 834 void DelegatedFrameHost::CreateCompositorFrameSinkSupport() { | 833 void DelegatedFrameHost::CreateCompositorFrameSinkSupport() { |
| 835 DCHECK(!support_); | 834 DCHECK(!support_); |
| 836 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 835 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
| 837 support_ = base::MakeUnique<cc::CompositorFrameSinkSupport>( | 836 support_ = base::MakeUnique<cc::CompositorFrameSinkSupport>( |
| 838 this, factory->GetContextFactoryPrivate()->GetSurfaceManager(), | 837 this, factory->GetContextFactoryPrivate()->GetSurfaceManager(), |
| 839 frame_sink_id_, false /* is_root */, | 838 frame_sink_id_, false /* is_root */, |
| 840 false /* handles_frame_sink_id_invalidation */, | 839 false /* handles_frame_sink_id_invalidation */, |
| 841 true /* needs_sync_points */); | 840 true /* needs_sync_points */); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 861 } | 860 } |
| 862 | 861 |
| 863 if (!skipped_frames_) { | 862 if (!skipped_frames_) { |
| 864 latest_confirmed_begin_frame_source_id_ = ack.source_id; | 863 latest_confirmed_begin_frame_source_id_ = ack.source_id; |
| 865 latest_confirmed_begin_frame_sequence_number_ = | 864 latest_confirmed_begin_frame_sequence_number_ = |
| 866 ack.latest_confirmed_sequence_number; | 865 ack.latest_confirmed_sequence_number; |
| 867 } | 866 } |
| 868 } | 867 } |
| 869 | 868 |
| 870 } // namespace content | 869 } // namespace content |
| OLD | NEW |