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.h" | 15 #include "cc/surfaces/surface.h" |
15 #include "cc/surfaces/surface_factory.h" | 16 #include "cc/surfaces/surface_factory.h" |
16 #include "cc/surfaces/surface_manager.h" | 17 #include "cc/surfaces/surface_manager.h" |
17 #include "content/browser/compositor/resize_lock.h" | 18 #include "content/browser/compositor/resize_lock.h" |
18 #include "content/browser/gpu/compositor_util.h" | 19 #include "content/browser/gpu/compositor_util.h" |
19 #include "content/common/gpu/client/gl_helper.h" | 20 #include "content/common/gpu/client/gl_helper.h" |
21 #include "content/common/view_messages.h" | |
20 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" | 22 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" |
21 #include "content/public/common/content_switches.h" | 23 #include "content/public/common/content_switches.h" |
22 #include "media/base/video_frame.h" | 24 #include "media/base/video_frame.h" |
23 #include "media/base/video_util.h" | 25 #include "media/base/video_util.h" |
24 #include "skia/ext/image_operations.h" | 26 #include "skia/ext/image_operations.h" |
25 #include "third_party/skia/include/core/SkCanvas.h" | 27 #include "third_party/skia/include/core/SkCanvas.h" |
26 #include "third_party/skia/include/core/SkPaint.h" | 28 #include "third_party/skia/include/core/SkPaint.h" |
27 #include "third_party/skia/include/effects/SkLumaColorFilter.h" | 29 #include "third_party/skia/include/effects/SkLumaColorFilter.h" |
28 #include "ui/gfx/frame_time.h" | 30 #include "ui/gfx/frame_time.h" |
29 #include "ui/gfx/geometry/dip_util.h" | 31 #include "ui/gfx/geometry/dip_util.h" |
(...skipping 18 matching lines...) Loading... | |
48 return; | 50 return; |
49 } | 51 } |
50 surface->AddDestructionDependency(sequence); | 52 surface->AddDestructionDependency(sequence); |
51 } | 53 } |
52 | 54 |
53 } // namespace | 55 } // namespace |
54 | 56 |
55 //////////////////////////////////////////////////////////////////////////////// | 57 //////////////////////////////////////////////////////////////////////////////// |
56 // DelegatedFrameHost | 58 // DelegatedFrameHost |
57 | 59 |
58 DelegatedFrameHost::DelegatedFrameHost(DelegatedFrameHostClient* client) | 60 DelegatedFrameHost::DelegatedFrameHost(DelegatedFrameHostClient* client, |
61 bool begin_frame_scheduling_enabled) | |
59 : client_(client), | 62 : client_(client), |
60 compositor_(nullptr), | 63 compositor_(nullptr), |
61 use_surfaces_(UseSurfacesEnabled()), | 64 use_surfaces_(UseSurfacesEnabled()), |
62 last_output_surface_id_(0), | 65 last_output_surface_id_(0), |
63 pending_delegated_ack_count_(0), | 66 pending_delegated_ack_count_(0), |
64 skipped_frames_(false), | 67 skipped_frames_(false), |
65 current_scale_factor_(1.f), | 68 current_scale_factor_(1.f), |
66 can_lock_compositor_(YES_CAN_LOCK), | 69 can_lock_compositor_(YES_CAN_LOCK), |
67 delegated_frame_evictor_(new DelegatedFrameEvictor(this)) { | 70 delegated_frame_evictor_(new DelegatedFrameEvictor(this)), |
71 begin_frame_scheduling_enabled_(begin_frame_scheduling_enabled), | |
72 needs_begin_frames_(false) { | |
68 ImageTransportFactory::GetInstance()->AddObserver(this); | 73 ImageTransportFactory::GetInstance()->AddObserver(this); |
69 } | 74 } |
70 | 75 |
71 void DelegatedFrameHost::WasShown(const ui::LatencyInfo& latency_info) { | 76 void DelegatedFrameHost::WasShown(const ui::LatencyInfo& latency_info) { |
72 delegated_frame_evictor_->SetVisible(true); | 77 delegated_frame_evictor_->SetVisible(true); |
73 | 78 |
74 if (surface_id_.is_null() && !frame_provider_.get() && | 79 if (surface_id_.is_null() && !frame_provider_.get() && |
75 !released_front_lock_.get()) { | 80 !released_front_lock_.get()) { |
76 if (compositor_) | 81 if (compositor_) |
77 released_front_lock_ = compositor_->GetCompositorLock(); | 82 released_front_lock_ = compositor_->GetCompositorLock(); |
(...skipping 744 matching lines...) Loading... | |
822 callback, | 827 callback, |
823 subscriber_texture, | 828 subscriber_texture, |
824 base::Passed(&release_callback)); | 829 base::Passed(&release_callback)); |
825 yuv_readback_pipeline->ReadbackYUV(texture_mailbox.mailbox(), | 830 yuv_readback_pipeline->ReadbackYUV(texture_mailbox.mailbox(), |
826 texture_mailbox.sync_point(), | 831 texture_mailbox.sync_point(), |
827 video_frame.get(), | 832 video_frame.get(), |
828 region_in_frame.origin(), | 833 region_in_frame.origin(), |
829 finished_callback); | 834 finished_callback); |
830 } | 835 } |
831 | 836 |
837 void DelegatedFrameHost::OnSetNeedsBeginFrames(bool needs_begin_frames) { | |
838 DCHECK(begin_frame_scheduling_enabled_); | |
839 | |
840 if (needs_begin_frames_ == needs_begin_frames) | |
841 return; | |
842 | |
843 needs_begin_frames_ = needs_begin_frames; | |
844 | |
845 // In some cases, BeginFrame is needed before |client_|'s window is added | |
846 // in the root window hierarchy. | |
847 if (!compositor_) | |
848 return; | |
849 | |
850 if (needs_begin_frames) | |
851 StartObservingBeginFrames(); | |
852 else | |
853 StopObservingBeginFrames(); | |
854 } | |
855 | |
832 //////////////////////////////////////////////////////////////////////////////// | 856 //////////////////////////////////////////////////////////////////////////////// |
833 // DelegatedFrameHost, ui::CompositorObserver implementation: | 857 // DelegatedFrameHost, ui::CompositorObserver implementation: |
834 | 858 |
835 void DelegatedFrameHost::OnCompositingDidCommit( | 859 void DelegatedFrameHost::OnCompositingDidCommit( |
836 ui::Compositor* compositor) { | 860 ui::Compositor* compositor) { |
837 if (can_lock_compositor_ == NO_PENDING_COMMIT) { | 861 if (can_lock_compositor_ == NO_PENDING_COMMIT) { |
838 can_lock_compositor_ = YES_CAN_LOCK; | 862 can_lock_compositor_ = YES_CAN_LOCK; |
839 if (resize_lock_.get() && resize_lock_->GrabDeferredLock()) | 863 if (resize_lock_.get() && resize_lock_->GrabDeferredLock()) |
840 can_lock_compositor_ = YES_DID_LOCK; | 864 can_lock_compositor_ = YES_DID_LOCK; |
841 } | 865 } |
(...skipping 29 matching lines...) Loading... | |
871 can_lock_compositor_ = NO_PENDING_RENDERER_FRAME; | 895 can_lock_compositor_ = NO_PENDING_RENDERER_FRAME; |
872 } | 896 } |
873 } | 897 } |
874 | 898 |
875 void DelegatedFrameHost::OnCompositingShuttingDown(ui::Compositor* compositor) { | 899 void DelegatedFrameHost::OnCompositingShuttingDown(ui::Compositor* compositor) { |
876 DCHECK_EQ(compositor, compositor_); | 900 DCHECK_EQ(compositor, compositor_); |
877 ResetCompositor(); | 901 ResetCompositor(); |
878 DCHECK(!compositor_); | 902 DCHECK(!compositor_); |
879 } | 903 } |
880 | 904 |
881 void DelegatedFrameHost::OnUpdateVSyncParameters( | 905 /////////////////////////////////////////////////////////////////////////////// |
882 base::TimeTicks timebase, | 906 // ui::CompositorBeginFrameObserver implementation. |
883 base::TimeDelta interval) { | 907 void DelegatedFrameHost::OnSendBeginFrame(const cc::BeginFrameArgs& args) { |
884 vsync_timebase_ = timebase; | 908 DCHECK(begin_frame_scheduling_enabled_); |
885 vsync_interval_ = interval; | 909 |
886 if (client_->DelegatedFrameHostIsVisible()) | 910 client_->DelegatedFrameHostSendBeginFrame(args); |
887 client_->DelegatedFrameHostUpdateVSyncParameters(timebase, interval); | 911 last_sent_begin_frame_args_ =args; |
brianderson
2015/03/02 22:38:16
Spaces needed around the =.
simonhong
2015/03/03 22:54:12
Done.
| |
912 vsync_timebase_ = args.frame_time; | |
913 vsync_interval_ = args.interval; | |
888 } | 914 } |
889 | 915 |
890 //////////////////////////////////////////////////////////////////////////////// | 916 //////////////////////////////////////////////////////////////////////////////// |
891 // DelegatedFrameHost, ImageTransportFactoryObserver implementation: | 917 // DelegatedFrameHost, ImageTransportFactoryObserver implementation: |
892 | 918 |
893 void DelegatedFrameHost::OnLostResources() { | 919 void DelegatedFrameHost::OnLostResources() { |
894 if (frame_provider_.get() || !surface_id_.is_null()) | 920 if (frame_provider_.get() || !surface_id_.is_null()) |
895 EvictDelegatedFrame(); | 921 EvictDelegatedFrame(); |
896 idle_frame_subscriber_textures_.clear(); | 922 idle_frame_subscriber_textures_.clear(); |
897 yuv_readback_pipeline_.reset(); | 923 yuv_readback_pipeline_.reset(); |
898 | 924 |
899 client_->DelegatedFrameHostOnLostCompositorResources(); | 925 client_->DelegatedFrameHostOnLostCompositorResources(); |
900 } | 926 } |
901 | 927 |
902 //////////////////////////////////////////////////////////////////////////////// | 928 //////////////////////////////////////////////////////////////////////////////// |
903 // DelegatedFrameHost, private: | 929 // DelegatedFrameHost, private: |
904 | 930 |
905 DelegatedFrameHost::~DelegatedFrameHost() { | 931 DelegatedFrameHost::~DelegatedFrameHost() { |
906 DCHECK(!compositor_); | 932 DCHECK(!compositor_); |
907 ImageTransportFactory::GetInstance()->RemoveObserver(this); | 933 ImageTransportFactory::GetInstance()->RemoveObserver(this); |
908 | 934 |
909 if (!surface_id_.is_null()) | 935 if (!surface_id_.is_null()) |
910 surface_factory_->Destroy(surface_id_); | 936 surface_factory_->Destroy(surface_id_); |
911 if (resource_collection_.get()) | 937 if (resource_collection_.get()) |
912 resource_collection_->SetClient(NULL); | 938 resource_collection_->SetClient(NULL); |
913 | |
914 DCHECK(!vsync_manager_.get()); | |
915 } | 939 } |
916 | 940 |
917 void DelegatedFrameHost::RunOnCommitCallbacks() { | 941 void DelegatedFrameHost::RunOnCommitCallbacks() { |
918 for (std::vector<base::Closure>::const_iterator | 942 for (std::vector<base::Closure>::const_iterator |
919 it = on_compositing_did_commit_callbacks_.begin(); | 943 it = on_compositing_did_commit_callbacks_.begin(); |
920 it != on_compositing_did_commit_callbacks_.end(); ++it) { | 944 it != on_compositing_did_commit_callbacks_.end(); ++it) { |
921 it->Run(); | 945 it->Run(); |
922 } | 946 } |
923 on_compositing_did_commit_callbacks_.clear(); | 947 on_compositing_did_commit_callbacks_.clear(); |
924 } | 948 } |
925 | 949 |
926 void DelegatedFrameHost::AddOnCommitCallbackAndDisableLocks( | 950 void DelegatedFrameHost::AddOnCommitCallbackAndDisableLocks( |
927 const base::Closure& callback) { | 951 const base::Closure& callback) { |
928 DCHECK(compositor_); | 952 DCHECK(compositor_); |
929 | 953 |
930 can_lock_compositor_ = NO_PENDING_COMMIT; | 954 can_lock_compositor_ = NO_PENDING_COMMIT; |
931 if (!callback.is_null()) | 955 if (!callback.is_null()) |
932 on_compositing_did_commit_callbacks_.push_back(callback); | 956 on_compositing_did_commit_callbacks_.push_back(callback); |
933 } | 957 } |
934 | 958 |
935 void DelegatedFrameHost::SetCompositor(ui::Compositor* compositor) { | 959 void DelegatedFrameHost::SetCompositor(ui::Compositor* compositor) { |
936 DCHECK(!compositor_); | 960 DCHECK(!compositor_); |
937 if (!compositor) | 961 if (!compositor) |
938 return; | 962 return; |
939 compositor_ = compositor; | 963 compositor_ = compositor; |
940 compositor_->AddObserver(this); | 964 compositor_->AddObserver(this); |
941 DCHECK(!vsync_manager_.get()); | 965 |
942 vsync_manager_ = compositor_->vsync_manager(); | 966 if (begin_frame_scheduling_enabled_ && needs_begin_frames_) |
943 vsync_manager_->AddObserver(this); | 967 StartObservingBeginFrames(); |
944 } | 968 } |
945 | 969 |
946 void DelegatedFrameHost::ResetCompositor() { | 970 void DelegatedFrameHost::ResetCompositor() { |
947 if (!compositor_) | 971 if (!compositor_) |
948 return; | 972 return; |
949 RunOnCommitCallbacks(); | 973 RunOnCommitCallbacks(); |
950 if (resize_lock_) { | 974 if (resize_lock_) { |
951 resize_lock_.reset(); | 975 resize_lock_.reset(); |
952 client_->DelegatedFrameHostResizeLockWasReleased(); | 976 client_->DelegatedFrameHostResizeLockWasReleased(); |
953 } | 977 } |
954 if (compositor_->HasObserver(this)) | 978 if (compositor_->HasObserver(this)) |
955 compositor_->RemoveObserver(this); | 979 compositor_->RemoveObserver(this); |
956 if (vsync_manager_.get()) { | 980 |
957 vsync_manager_->RemoveObserver(this); | 981 if (begin_frame_scheduling_enabled_ && needs_begin_frames_) |
958 vsync_manager_ = NULL; | 982 StopObservingBeginFrames(); |
959 } | 983 |
960 compositor_ = nullptr; | 984 compositor_ = nullptr; |
961 } | 985 } |
962 | 986 |
963 void DelegatedFrameHost::LockResources() { | 987 void DelegatedFrameHost::LockResources() { |
964 DCHECK(frame_provider_.get() || !surface_id_.is_null()); | 988 DCHECK(frame_provider_.get() || !surface_id_.is_null()); |
965 delegated_frame_evictor_->LockFrame(); | 989 delegated_frame_evictor_->LockFrame(); |
966 } | 990 } |
967 | 991 |
968 void DelegatedFrameHost::RequestCopyOfOutput( | 992 void DelegatedFrameHost::RequestCopyOfOutput( |
969 scoped_ptr<cc::CopyOutputRequest> request) { | 993 scoped_ptr<cc::CopyOutputRequest> request) { |
970 if (!request_copy_of_output_callback_for_testing_.is_null()) | 994 if (!request_copy_of_output_callback_for_testing_.is_null()) |
971 request_copy_of_output_callback_for_testing_.Run(request.Pass()); | 995 request_copy_of_output_callback_for_testing_.Run(request.Pass()); |
972 else | 996 else |
973 client_->DelegatedFrameHostGetLayer()->RequestCopyOfOutput(request.Pass()); | 997 client_->DelegatedFrameHostGetLayer()->RequestCopyOfOutput(request.Pass()); |
974 } | 998 } |
975 | 999 |
976 void DelegatedFrameHost::UnlockResources() { | 1000 void DelegatedFrameHost::UnlockResources() { |
977 DCHECK(frame_provider_.get() || !surface_id_.is_null()); | 1001 DCHECK(frame_provider_.get() || !surface_id_.is_null()); |
978 delegated_frame_evictor_->UnlockFrame(); | 1002 delegated_frame_evictor_->UnlockFrame(); |
979 } | 1003 } |
980 | 1004 |
1005 void DelegatedFrameHost::StartObservingBeginFrames() { | |
1006 DCHECK(begin_frame_scheduling_enabled_); | |
1007 DCHECK(compositor_); | |
1008 | |
1009 compositor_->AddBeginFrameObserver(this, last_sent_begin_frame_args_); | |
1010 } | |
1011 | |
1012 void DelegatedFrameHost::StopObservingBeginFrames() { | |
1013 DCHECK(begin_frame_scheduling_enabled_); | |
1014 DCHECK(compositor_); | |
1015 | |
1016 compositor_->RemoveBeginFrameObserver(this); | |
1017 } | |
1018 | |
981 //////////////////////////////////////////////////////////////////////////////// | 1019 //////////////////////////////////////////////////////////////////////////////// |
982 // DelegatedFrameHost, ui::LayerOwnerDelegate implementation: | 1020 // DelegatedFrameHost, ui::LayerOwnerDelegate implementation: |
983 | 1021 |
984 void DelegatedFrameHost::OnLayerRecreated(ui::Layer* old_layer, | 1022 void DelegatedFrameHost::OnLayerRecreated(ui::Layer* old_layer, |
985 ui::Layer* new_layer) { | 1023 ui::Layer* new_layer) { |
986 // The new_layer is the one that will be used by our Window, so that's the one | 1024 // The new_layer is the one that will be used by our Window, so that's the one |
987 // that should keep our frame. old_layer will be returned to the | 1025 // that should keep our frame. old_layer will be returned to the |
988 // RecreateLayer caller, and should have a copy. | 1026 // RecreateLayer caller, and should have a copy. |
989 if (frame_provider_.get()) { | 1027 if (frame_provider_.get()) { |
990 new_layer->SetShowDelegatedContent(frame_provider_.get(), | 1028 new_layer->SetShowDelegatedContent(frame_provider_.get(), |
991 current_frame_size_in_dip_); | 1029 current_frame_size_in_dip_); |
992 } | 1030 } |
993 if (!surface_id_.is_null()) { | 1031 if (!surface_id_.is_null()) { |
994 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 1032 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
995 cc::SurfaceManager* manager = factory->GetSurfaceManager(); | 1033 cc::SurfaceManager* manager = factory->GetSurfaceManager(); |
996 new_layer->SetShowSurface( | 1034 new_layer->SetShowSurface( |
997 surface_id_, base::Bind(&SatisfyCallback, base::Unretained(manager)), | 1035 surface_id_, base::Bind(&SatisfyCallback, base::Unretained(manager)), |
998 base::Bind(&RequireCallback, base::Unretained(manager)), | 1036 base::Bind(&RequireCallback, base::Unretained(manager)), |
999 current_surface_size_, current_scale_factor_, | 1037 current_surface_size_, current_scale_factor_, |
1000 current_frame_size_in_dip_); | 1038 current_frame_size_in_dip_); |
1001 } | 1039 } |
1002 } | 1040 } |
1003 | 1041 |
1004 } // namespace content | 1042 } // namespace content |
OLD | NEW |