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