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/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...) Expand all 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 frame_subscriber_copy_request_pending_(false), | 70 frame_subscriber_copy_request_pending_(false), |
| 68 delegated_frame_evictor_(new DelegatedFrameEvictor(this)) { | 71 delegated_frame_evictor_(new DelegatedFrameEvictor(this)), |
| 72 begin_frame_scheduling_enabled_(begin_frame_scheduling_enabled), | |
| 73 needs_begin_frames_(false) { | |
| 69 ImageTransportFactory::GetInstance()->AddObserver(this); | 74 ImageTransportFactory::GetInstance()->AddObserver(this); |
| 70 } | 75 } |
| 71 | 76 |
| 72 void DelegatedFrameHost::WasShown(const ui::LatencyInfo& latency_info) { | 77 void DelegatedFrameHost::WasShown(const ui::LatencyInfo& latency_info) { |
| 73 delegated_frame_evictor_->SetVisible(true); | 78 delegated_frame_evictor_->SetVisible(true); |
| 74 | 79 |
| 75 if (surface_id_.is_null() && !frame_provider_.get() && | 80 if (surface_id_.is_null() && !frame_provider_.get() && |
| 76 !released_front_lock_.get()) { | 81 !released_front_lock_.get()) { |
| 77 if (compositor_) | 82 if (compositor_) |
| 78 released_front_lock_ = compositor_->GetCompositorLock(); | 83 released_front_lock_ = compositor_->GetCompositorLock(); |
| (...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 848 callback, | 853 callback, |
| 849 subscriber_texture, | 854 subscriber_texture, |
| 850 base::Passed(&release_callback)); | 855 base::Passed(&release_callback)); |
| 851 yuv_readback_pipeline->ReadbackYUV(texture_mailbox.mailbox(), | 856 yuv_readback_pipeline->ReadbackYUV(texture_mailbox.mailbox(), |
| 852 texture_mailbox.sync_point(), | 857 texture_mailbox.sync_point(), |
| 853 video_frame.get(), | 858 video_frame.get(), |
| 854 region_in_frame.origin(), | 859 region_in_frame.origin(), |
| 855 finished_callback); | 860 finished_callback); |
| 856 } | 861 } |
| 857 | 862 |
| 863 void DelegatedFrameHost::OnSetNeedsBeginFrames(bool needs_begin_frames) { | |
| 864 DCHECK(begin_frame_scheduling_enabled_); | |
| 865 | |
| 866 if (needs_begin_frames_ == needs_begin_frames) | |
| 867 return; | |
| 868 | |
| 869 needs_begin_frames_ = needs_begin_frames; | |
| 870 | |
| 871 // In some cases, BeginFrame is needed before |client_|'s window is added | |
| 872 // in the root window hierarchy. | |
| 873 if (!compositor_) | |
| 874 return; | |
| 875 | |
| 876 if (needs_begin_frames) | |
| 877 StartObservingBeginFrames(); | |
| 878 else | |
| 879 StopObservingBeginFrames(); | |
| 880 } | |
| 881 | |
| 858 //////////////////////////////////////////////////////////////////////////////// | 882 //////////////////////////////////////////////////////////////////////////////// |
| 859 // DelegatedFrameHost, ui::CompositorObserver implementation: | 883 // DelegatedFrameHost, ui::CompositorObserver implementation: |
| 860 | 884 |
| 861 void DelegatedFrameHost::OnCompositingDidCommit( | 885 void DelegatedFrameHost::OnCompositingDidCommit( |
| 862 ui::Compositor* compositor) { | 886 ui::Compositor* compositor) { |
| 863 if (can_lock_compositor_ == NO_PENDING_COMMIT) { | 887 if (can_lock_compositor_ == NO_PENDING_COMMIT) { |
| 864 can_lock_compositor_ = YES_CAN_LOCK; | 888 can_lock_compositor_ = YES_CAN_LOCK; |
| 865 if (resize_lock_.get() && resize_lock_->GrabDeferredLock()) | 889 if (resize_lock_.get() && resize_lock_->GrabDeferredLock()) |
| 866 can_lock_compositor_ = YES_DID_LOCK; | 890 can_lock_compositor_ = YES_DID_LOCK; |
| 867 } | 891 } |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 898 can_lock_compositor_ = NO_PENDING_RENDERER_FRAME; | 922 can_lock_compositor_ = NO_PENDING_RENDERER_FRAME; |
| 899 } | 923 } |
| 900 } | 924 } |
| 901 | 925 |
| 902 void DelegatedFrameHost::OnCompositingShuttingDown(ui::Compositor* compositor) { | 926 void DelegatedFrameHost::OnCompositingShuttingDown(ui::Compositor* compositor) { |
| 903 DCHECK_EQ(compositor, compositor_); | 927 DCHECK_EQ(compositor, compositor_); |
| 904 ResetCompositor(); | 928 ResetCompositor(); |
| 905 DCHECK(!compositor_); | 929 DCHECK(!compositor_); |
| 906 } | 930 } |
| 907 | 931 |
| 932 /////////////////////////////////////////////////////////////////////////////// | |
| 933 // ui::CompositorBeginFrameObserver implementation. | |
| 908 void DelegatedFrameHost::OnUpdateVSyncParameters( | 934 void DelegatedFrameHost::OnUpdateVSyncParameters( |
| 909 base::TimeTicks timebase, | 935 base::TimeTicks timebase, |
| 910 base::TimeDelta interval) { | 936 base::TimeDelta interval) { |
| 911 vsync_timebase_ = timebase; | 937 vsync_timebase_ = timebase; |
| 912 vsync_interval_ = interval; | 938 vsync_interval_ = interval; |
| 913 if (client_->DelegatedFrameHostIsVisible()) | 939 if (client_->DelegatedFrameHostIsVisible()) |
| 914 client_->DelegatedFrameHostUpdateVSyncParameters(timebase, interval); | 940 client_->DelegatedFrameHostUpdateVSyncParameters(timebase, interval); |
| 915 } | 941 } |
| 916 | 942 |
| 943 void DelegatedFrameHost::OnSendBeginFrame(const cc::BeginFrameArgs& args) { | |
|
danakj
2015/03/13 20:04:40
This code seems entirely disconnected from the oth
simonhong
2015/03/17 16:11:34
Yep, handling BeginFrame message is not related wi
| |
| 944 DCHECK(begin_frame_scheduling_enabled_); | |
| 945 | |
| 946 client_->DelegatedFrameHostSendBeginFrame(args); | |
| 947 last_sent_begin_frame_args_ = args; | |
| 948 vsync_timebase_ = args.frame_time; | |
| 949 vsync_interval_ = args.interval; | |
| 950 } | |
| 951 | |
| 917 //////////////////////////////////////////////////////////////////////////////// | 952 //////////////////////////////////////////////////////////////////////////////// |
| 918 // DelegatedFrameHost, ImageTransportFactoryObserver implementation: | 953 // DelegatedFrameHost, ImageTransportFactoryObserver implementation: |
| 919 | 954 |
| 920 void DelegatedFrameHost::OnLostResources() { | 955 void DelegatedFrameHost::OnLostResources() { |
| 921 if (frame_provider_.get() || !surface_id_.is_null()) | 956 if (frame_provider_.get() || !surface_id_.is_null()) |
| 922 EvictDelegatedFrame(); | 957 EvictDelegatedFrame(); |
| 923 idle_frame_subscriber_textures_.clear(); | 958 idle_frame_subscriber_textures_.clear(); |
| 924 yuv_readback_pipeline_.reset(); | 959 yuv_readback_pipeline_.reset(); |
| 925 | 960 |
| 926 client_->DelegatedFrameHostOnLostCompositorResources(); | 961 client_->DelegatedFrameHostOnLostCompositorResources(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 966 | 1001 |
| 967 void DelegatedFrameHost::SetCompositor(ui::Compositor* compositor) { | 1002 void DelegatedFrameHost::SetCompositor(ui::Compositor* compositor) { |
| 968 DCHECK(!compositor_); | 1003 DCHECK(!compositor_); |
| 969 if (!compositor) | 1004 if (!compositor) |
| 970 return; | 1005 return; |
| 971 compositor_ = compositor; | 1006 compositor_ = compositor; |
| 972 compositor_->AddObserver(this); | 1007 compositor_->AddObserver(this); |
| 973 DCHECK(!vsync_manager_.get()); | 1008 DCHECK(!vsync_manager_.get()); |
| 974 vsync_manager_ = compositor_->vsync_manager(); | 1009 vsync_manager_ = compositor_->vsync_manager(); |
| 975 vsync_manager_->AddObserver(this); | 1010 vsync_manager_->AddObserver(this); |
| 1011 | |
| 1012 if (begin_frame_scheduling_enabled_ && needs_begin_frames_) | |
| 1013 StartObservingBeginFrames(); | |
| 976 } | 1014 } |
| 977 | 1015 |
| 978 void DelegatedFrameHost::ResetCompositor() { | 1016 void DelegatedFrameHost::ResetCompositor() { |
| 979 if (!compositor_) | 1017 if (!compositor_) |
| 980 return; | 1018 return; |
| 981 RunOnCommitCallbacks(); | 1019 RunOnCommitCallbacks(); |
| 982 if (resize_lock_) { | 1020 if (resize_lock_) { |
| 983 resize_lock_.reset(); | 1021 resize_lock_.reset(); |
| 984 client_->DelegatedFrameHostResizeLockWasReleased(); | 1022 client_->DelegatedFrameHostResizeLockWasReleased(); |
| 985 } | 1023 } |
| 986 if (compositor_->HasObserver(this)) | 1024 if (compositor_->HasObserver(this)) |
| 987 compositor_->RemoveObserver(this); | 1025 compositor_->RemoveObserver(this); |
| 988 if (vsync_manager_.get()) { | 1026 if (vsync_manager_.get()) { |
| 989 vsync_manager_->RemoveObserver(this); | 1027 vsync_manager_->RemoveObserver(this); |
| 990 vsync_manager_ = NULL; | 1028 vsync_manager_ = NULL; |
| 991 } | 1029 } |
| 1030 | |
| 1031 if (begin_frame_scheduling_enabled_ && needs_begin_frames_) | |
| 1032 StopObservingBeginFrames(); | |
| 1033 | |
| 992 compositor_ = nullptr; | 1034 compositor_ = nullptr; |
| 993 } | 1035 } |
| 994 | 1036 |
| 995 void DelegatedFrameHost::LockResources() { | 1037 void DelegatedFrameHost::LockResources() { |
| 996 DCHECK(frame_provider_.get() || !surface_id_.is_null()); | 1038 DCHECK(frame_provider_.get() || !surface_id_.is_null()); |
| 997 delegated_frame_evictor_->LockFrame(); | 1039 delegated_frame_evictor_->LockFrame(); |
| 998 } | 1040 } |
| 999 | 1041 |
| 1000 void DelegatedFrameHost::RequestCopyOfOutput( | 1042 void DelegatedFrameHost::RequestCopyOfOutput( |
| 1001 scoped_ptr<cc::CopyOutputRequest> request) { | 1043 scoped_ptr<cc::CopyOutputRequest> request) { |
| 1002 if (!request_copy_of_output_callback_for_testing_.is_null()) | 1044 if (!request_copy_of_output_callback_for_testing_.is_null()) |
| 1003 request_copy_of_output_callback_for_testing_.Run(request.Pass()); | 1045 request_copy_of_output_callback_for_testing_.Run(request.Pass()); |
| 1004 else | 1046 else |
| 1005 client_->DelegatedFrameHostGetLayer()->RequestCopyOfOutput(request.Pass()); | 1047 client_->DelegatedFrameHostGetLayer()->RequestCopyOfOutput(request.Pass()); |
| 1006 } | 1048 } |
| 1007 | 1049 |
| 1008 void DelegatedFrameHost::UnlockResources() { | 1050 void DelegatedFrameHost::UnlockResources() { |
| 1009 DCHECK(frame_provider_.get() || !surface_id_.is_null()); | 1051 DCHECK(frame_provider_.get() || !surface_id_.is_null()); |
| 1010 delegated_frame_evictor_->UnlockFrame(); | 1052 delegated_frame_evictor_->UnlockFrame(); |
| 1011 } | 1053 } |
| 1012 | 1054 |
| 1055 void DelegatedFrameHost::StartObservingBeginFrames() { | |
| 1056 DCHECK(begin_frame_scheduling_enabled_); | |
| 1057 DCHECK(compositor_); | |
| 1058 | |
| 1059 compositor_->AddBeginFrameObserver(this, last_sent_begin_frame_args_); | |
| 1060 } | |
| 1061 | |
| 1062 void DelegatedFrameHost::StopObservingBeginFrames() { | |
| 1063 DCHECK(begin_frame_scheduling_enabled_); | |
| 1064 DCHECK(compositor_); | |
| 1065 | |
| 1066 compositor_->RemoveBeginFrameObserver(this); | |
| 1067 } | |
| 1068 | |
| 1013 //////////////////////////////////////////////////////////////////////////////// | 1069 //////////////////////////////////////////////////////////////////////////////// |
| 1014 // DelegatedFrameHost, ui::LayerOwnerDelegate implementation: | 1070 // DelegatedFrameHost, ui::LayerOwnerDelegate implementation: |
| 1015 | 1071 |
| 1016 void DelegatedFrameHost::OnLayerRecreated(ui::Layer* old_layer, | 1072 void DelegatedFrameHost::OnLayerRecreated(ui::Layer* old_layer, |
| 1017 ui::Layer* new_layer) { | 1073 ui::Layer* new_layer) { |
| 1018 // The new_layer is the one that will be used by our Window, so that's the one | 1074 // The new_layer is the one that will be used by our Window, so that's the one |
| 1019 // that should keep our frame. old_layer will be returned to the | 1075 // that should keep our frame. old_layer will be returned to the |
| 1020 // RecreateLayer caller, and should have a copy. | 1076 // RecreateLayer caller, and should have a copy. |
| 1021 if (frame_provider_.get()) { | 1077 if (frame_provider_.get()) { |
| 1022 new_layer->SetShowDelegatedContent(frame_provider_.get(), | 1078 new_layer->SetShowDelegatedContent(frame_provider_.get(), |
| 1023 current_frame_size_in_dip_); | 1079 current_frame_size_in_dip_); |
| 1024 } | 1080 } |
| 1025 if (!surface_id_.is_null()) { | 1081 if (!surface_id_.is_null()) { |
| 1026 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 1082 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
| 1027 cc::SurfaceManager* manager = factory->GetSurfaceManager(); | 1083 cc::SurfaceManager* manager = factory->GetSurfaceManager(); |
| 1028 new_layer->SetShowSurface( | 1084 new_layer->SetShowSurface( |
| 1029 surface_id_, base::Bind(&SatisfyCallback, base::Unretained(manager)), | 1085 surface_id_, base::Bind(&SatisfyCallback, base::Unretained(manager)), |
| 1030 base::Bind(&RequireCallback, base::Unretained(manager)), | 1086 base::Bind(&RequireCallback, base::Unretained(manager)), |
| 1031 current_surface_size_, current_scale_factor_, | 1087 current_surface_size_, current_scale_factor_, |
| 1032 current_frame_size_in_dip_); | 1088 current_frame_size_in_dip_); |
| 1033 } | 1089 } |
| 1034 } | 1090 } |
| 1035 | 1091 |
| 1036 } // namespace content | 1092 } // namespace content |
| OLD | NEW |