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/compositor/delegated_frame_host.h" | 5 #include "content/browser/compositor/delegated_frame_host.h" |
6 | 6 |
7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "cc/output/begin_frame_args.h" |
9 #include "cc/output/compositor_frame.h" | 10 #include "cc/output/compositor_frame.h" |
10 #include "cc/output/compositor_frame_ack.h" | 11 #include "cc/output/compositor_frame_ack.h" |
11 #include "cc/output/copy_output_request.h" | 12 #include "cc/output/copy_output_request.h" |
12 #include "cc/resources/single_release_callback.h" | 13 #include "cc/resources/single_release_callback.h" |
13 #include "cc/resources/texture_mailbox.h" | 14 #include "cc/resources/texture_mailbox.h" |
14 #include "cc/surfaces/surface_factory.h" | 15 #include "cc/surfaces/surface_factory.h" |
15 #include "content/browser/compositor/resize_lock.h" | 16 #include "content/browser/compositor/resize_lock.h" |
16 #include "content/common/gpu/client/gl_helper.h" | 17 #include "content/common/gpu/client/gl_helper.h" |
17 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" | 18 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" |
18 #include "content/public/common/content_switches.h" | 19 #include "content/public/common/content_switches.h" |
(...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
752 dfh->AsWeakPtr(), | 753 dfh->AsWeakPtr(), |
753 callback, | 754 callback, |
754 subscriber_texture, | 755 subscriber_texture, |
755 base::Passed(&release_callback)); | 756 base::Passed(&release_callback)); |
756 yuv_readback_pipeline->ReadbackYUV(texture_mailbox.mailbox(), | 757 yuv_readback_pipeline->ReadbackYUV(texture_mailbox.mailbox(), |
757 texture_mailbox.sync_point(), | 758 texture_mailbox.sync_point(), |
758 video_frame.get(), | 759 video_frame.get(), |
759 finished_callback); | 760 finished_callback); |
760 } | 761 } |
761 | 762 |
| 763 void DelegatedFrameHost::UpdateVSyncParameters(const cc::BeginFrameArgs& args) { |
| 764 vsync_timebase_ = args.frame_time; |
| 765 vsync_interval_ = args.interval; |
| 766 } |
| 767 |
762 //////////////////////////////////////////////////////////////////////////////// | 768 //////////////////////////////////////////////////////////////////////////////// |
763 // DelegatedFrameHost, ui::CompositorObserver implementation: | 769 // DelegatedFrameHost, ui::CompositorObserver implementation: |
764 | 770 |
765 void DelegatedFrameHost::OnCompositingDidCommit( | 771 void DelegatedFrameHost::OnCompositingDidCommit( |
766 ui::Compositor* compositor) { | 772 ui::Compositor* compositor) { |
767 RenderWidgetHostImpl* host = client_->GetHost(); | 773 RenderWidgetHostImpl* host = client_->GetHost(); |
768 if (can_lock_compositor_ == NO_PENDING_COMMIT) { | 774 if (can_lock_compositor_ == NO_PENDING_COMMIT) { |
769 can_lock_compositor_ = YES_CAN_LOCK; | 775 can_lock_compositor_ = YES_CAN_LOCK; |
770 if (resize_lock_.get() && resize_lock_->GrabDeferredLock()) | 776 if (resize_lock_.get() && resize_lock_->GrabDeferredLock()) |
771 can_lock_compositor_ = YES_DID_LOCK; | 777 can_lock_compositor_ = YES_DID_LOCK; |
(...skipping 24 matching lines...) Expand all Loading... |
796 | 802 |
797 void DelegatedFrameHost::OnCompositingLockStateChanged( | 803 void DelegatedFrameHost::OnCompositingLockStateChanged( |
798 ui::Compositor* compositor) { | 804 ui::Compositor* compositor) { |
799 // A compositor lock that is part of a resize lock timed out. We | 805 // A compositor lock that is part of a resize lock timed out. We |
800 // should display a renderer frame. | 806 // should display a renderer frame. |
801 if (!compositor->IsLocked() && can_lock_compositor_ == YES_DID_LOCK) { | 807 if (!compositor->IsLocked() && can_lock_compositor_ == YES_DID_LOCK) { |
802 can_lock_compositor_ = NO_PENDING_RENDERER_FRAME; | 808 can_lock_compositor_ = NO_PENDING_RENDERER_FRAME; |
803 } | 809 } |
804 } | 810 } |
805 | 811 |
806 void DelegatedFrameHost::OnUpdateVSyncParameters( | |
807 base::TimeTicks timebase, | |
808 base::TimeDelta interval) { | |
809 vsync_timebase_ = timebase; | |
810 vsync_interval_ = interval; | |
811 RenderWidgetHostImpl* host = client_->GetHost(); | |
812 if (client_->IsVisible()) | |
813 host->UpdateVSyncParameters(timebase, interval); | |
814 } | |
815 | |
816 //////////////////////////////////////////////////////////////////////////////// | 812 //////////////////////////////////////////////////////////////////////////////// |
817 // RenderWidgetHostViewAura, ImageTransportFactoryObserver implementation: | 813 // RenderWidgetHostViewAura, ImageTransportFactoryObserver implementation: |
818 | 814 |
819 void DelegatedFrameHost::OnLostResources() { | 815 void DelegatedFrameHost::OnLostResources() { |
820 RenderWidgetHostImpl* host = client_->GetHost(); | 816 RenderWidgetHostImpl* host = client_->GetHost(); |
821 if (frame_provider_.get() || !surface_id_.is_null()) | 817 if (frame_provider_.get() || !surface_id_.is_null()) |
822 EvictDelegatedFrame(); | 818 EvictDelegatedFrame(); |
823 idle_frame_subscriber_textures_.clear(); | 819 idle_frame_subscriber_textures_.clear(); |
824 yuv_readback_pipeline_.reset(); | 820 yuv_readback_pipeline_.reset(); |
825 | 821 |
826 host->ScheduleComposite(); | 822 host->ScheduleComposite(); |
827 } | 823 } |
828 | 824 |
829 //////////////////////////////////////////////////////////////////////////////// | 825 //////////////////////////////////////////////////////////////////////////////// |
830 // DelegatedFrameHost, private: | 826 // DelegatedFrameHost, private: |
831 | 827 |
832 DelegatedFrameHost::~DelegatedFrameHost() { | 828 DelegatedFrameHost::~DelegatedFrameHost() { |
833 ImageTransportFactory::GetInstance()->RemoveObserver(this); | 829 ImageTransportFactory::GetInstance()->RemoveObserver(this); |
834 | 830 |
835 if (!surface_id_.is_null()) | 831 if (!surface_id_.is_null()) |
836 surface_factory_->Destroy(surface_id_); | 832 surface_factory_->Destroy(surface_id_); |
837 if (resource_collection_.get()) | 833 if (resource_collection_.get()) |
838 resource_collection_->SetClient(NULL); | 834 resource_collection_->SetClient(NULL); |
839 | |
840 DCHECK(!vsync_manager_); | |
841 } | 835 } |
842 | 836 |
843 void DelegatedFrameHost::RunOnCommitCallbacks() { | 837 void DelegatedFrameHost::RunOnCommitCallbacks() { |
844 for (std::vector<base::Closure>::const_iterator | 838 for (std::vector<base::Closure>::const_iterator |
845 it = on_compositing_did_commit_callbacks_.begin(); | 839 it = on_compositing_did_commit_callbacks_.begin(); |
846 it != on_compositing_did_commit_callbacks_.end(); ++it) { | 840 it != on_compositing_did_commit_callbacks_.end(); ++it) { |
847 it->Run(); | 841 it->Run(); |
848 } | 842 } |
849 on_compositing_did_commit_callbacks_.clear(); | 843 on_compositing_did_commit_callbacks_.clear(); |
850 } | 844 } |
851 | 845 |
852 void DelegatedFrameHost::AddOnCommitCallbackAndDisableLocks( | 846 void DelegatedFrameHost::AddOnCommitCallbackAndDisableLocks( |
853 const base::Closure& callback) { | 847 const base::Closure& callback) { |
854 ui::Compositor* compositor = client_->GetCompositor(); | 848 ui::Compositor* compositor = client_->GetCompositor(); |
855 DCHECK(compositor); | 849 DCHECK(compositor); |
856 | 850 |
857 if (!compositor->HasObserver(this)) | 851 if (!compositor->HasObserver(this)) |
858 compositor->AddObserver(this); | 852 compositor->AddObserver(this); |
859 | 853 |
860 can_lock_compositor_ = NO_PENDING_COMMIT; | 854 can_lock_compositor_ = NO_PENDING_COMMIT; |
861 on_compositing_did_commit_callbacks_.push_back(callback); | 855 on_compositing_did_commit_callbacks_.push_back(callback); |
862 } | 856 } |
863 | 857 |
864 void DelegatedFrameHost::AddedToWindow() { | 858 void DelegatedFrameHost::AddedToWindow() { |
865 ui::Compositor* compositor = client_->GetCompositor(); | |
866 if (compositor) { | |
867 DCHECK(!vsync_manager_); | |
868 vsync_manager_ = compositor->vsync_manager(); | |
869 vsync_manager_->AddObserver(this); | |
870 } | |
871 } | 859 } |
872 | 860 |
873 void DelegatedFrameHost::RemovingFromWindow() { | 861 void DelegatedFrameHost::RemovingFromWindow() { |
874 RunOnCommitCallbacks(); | 862 RunOnCommitCallbacks(); |
875 resize_lock_.reset(); | 863 resize_lock_.reset(); |
876 client_->GetHost()->WasResized(); | 864 client_->GetHost()->WasResized(); |
877 ui::Compositor* compositor = client_->GetCompositor(); | 865 ui::Compositor* compositor = client_->GetCompositor(); |
878 if (compositor && compositor->HasObserver(this)) | 866 if (compositor && compositor->HasObserver(this)) |
879 compositor->RemoveObserver(this); | 867 compositor->RemoveObserver(this); |
880 | |
881 if (vsync_manager_) { | |
882 vsync_manager_->RemoveObserver(this); | |
883 vsync_manager_ = NULL; | |
884 } | |
885 } | 868 } |
886 | 869 |
887 void DelegatedFrameHost::LockResources() { | 870 void DelegatedFrameHost::LockResources() { |
888 DCHECK(frame_provider_ || !surface_id_.is_null()); | 871 DCHECK(frame_provider_ || !surface_id_.is_null()); |
889 delegated_frame_evictor_->LockFrame(); | 872 delegated_frame_evictor_->LockFrame(); |
890 } | 873 } |
891 | 874 |
892 void DelegatedFrameHost::UnlockResources() { | 875 void DelegatedFrameHost::UnlockResources() { |
893 DCHECK(frame_provider_ || !surface_id_.is_null()); | 876 DCHECK(frame_provider_ || !surface_id_.is_null()); |
894 delegated_frame_evictor_->UnlockFrame(); | 877 delegated_frame_evictor_->UnlockFrame(); |
(...skipping 10 matching lines...) Expand all Loading... |
905 if (frame_provider_.get()) { | 888 if (frame_provider_.get()) { |
906 new_layer->SetShowDelegatedContent(frame_provider_.get(), | 889 new_layer->SetShowDelegatedContent(frame_provider_.get(), |
907 current_frame_size_in_dip_); | 890 current_frame_size_in_dip_); |
908 } | 891 } |
909 if (!surface_id_.is_null()) { | 892 if (!surface_id_.is_null()) { |
910 new_layer->SetShowSurface(surface_id_, current_frame_size_in_dip_); | 893 new_layer->SetShowSurface(surface_id_, current_frame_size_in_dip_); |
911 } | 894 } |
912 } | 895 } |
913 | 896 |
914 } // namespace content | 897 } // namespace content |
OLD | NEW |