Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(470)

Side by Side Diff: content/browser/compositor/delegated_frame_host.cc

Issue 775143003: cc: Implement unified BeginFrame on aura (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/base/switches.h"
10 #include "cc/output/begin_frame_args.h"
9 #include "cc/output/compositor_frame.h" 11 #include "cc/output/compositor_frame.h"
10 #include "cc/output/compositor_frame_ack.h" 12 #include "cc/output/compositor_frame_ack.h"
11 #include "cc/output/copy_output_request.h" 13 #include "cc/output/copy_output_request.h"
12 #include "cc/resources/single_release_callback.h" 14 #include "cc/resources/single_release_callback.h"
13 #include "cc/resources/texture_mailbox.h" 15 #include "cc/resources/texture_mailbox.h"
14 #include "cc/surfaces/surface.h" 16 #include "cc/surfaces/surface.h"
15 #include "cc/surfaces/surface_factory.h" 17 #include "cc/surfaces/surface_factory.h"
16 #include "cc/surfaces/surface_manager.h" 18 #include "cc/surfaces/surface_manager.h"
17 #include "content/browser/compositor/resize_lock.h" 19 #include "content/browser/compositor/resize_lock.h"
18 #include "content/browser/gpu/compositor_util.h" 20 #include "content/browser/gpu/compositor_util.h"
19 #include "content/common/gpu/client/gl_helper.h" 21 #include "content/common/gpu/client/gl_helper.h"
22 #include "content/common/view_messages.h"
20 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" 23 #include "content/public/browser/render_widget_host_view_frame_subscriber.h"
21 #include "content/public/common/content_switches.h" 24 #include "content/public/common/content_switches.h"
22 #include "media/base/video_frame.h" 25 #include "media/base/video_frame.h"
23 #include "media/base/video_util.h" 26 #include "media/base/video_util.h"
24 #include "skia/ext/image_operations.h" 27 #include "skia/ext/image_operations.h"
25 #include "third_party/skia/include/core/SkCanvas.h" 28 #include "third_party/skia/include/core/SkCanvas.h"
26 #include "third_party/skia/include/core/SkPaint.h" 29 #include "third_party/skia/include/core/SkPaint.h"
27 #include "third_party/skia/include/effects/SkLumaColorFilter.h" 30 #include "third_party/skia/include/effects/SkLumaColorFilter.h"
28 #include "ui/gfx/frame_time.h" 31 #include "ui/gfx/frame_time.h"
29 #include "ui/gfx/geometry/dip_util.h" 32 #include "ui/gfx/geometry/dip_util.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 // DelegatedFrameHost 81 // DelegatedFrameHost
79 82
80 DelegatedFrameHost::DelegatedFrameHost(DelegatedFrameHostClient* client) 83 DelegatedFrameHost::DelegatedFrameHost(DelegatedFrameHostClient* client)
81 : client_(client), 84 : client_(client),
82 use_surfaces_(UseSurfacesEnabled()), 85 use_surfaces_(UseSurfacesEnabled()),
83 last_output_surface_id_(0), 86 last_output_surface_id_(0),
84 pending_delegated_ack_count_(0), 87 pending_delegated_ack_count_(0),
85 skipped_frames_(false), 88 skipped_frames_(false),
86 current_scale_factor_(1.f), 89 current_scale_factor_(1.f),
87 can_lock_compositor_(YES_CAN_LOCK), 90 can_lock_compositor_(YES_CAN_LOCK),
88 delegated_frame_evictor_(new DelegatedFrameEvictor(this)) { 91 delegated_frame_evictor_(new DelegatedFrameEvictor(this)),
92 begin_frame_scheduling_enabled_(false),
93 needs_begin_frames_(false) {
89 ImageTransportFactory::GetInstance()->AddObserver(this); 94 ImageTransportFactory::GetInstance()->AddObserver(this);
95 begin_frame_scheduling_enabled_ =
96 base::CommandLine::ForCurrentProcess()->HasSwitch(
97 cc::switches::kEnableBeginFrameScheduling);
90 } 98 }
91 99
92 void DelegatedFrameHost::WasShown(const ui::LatencyInfo& latency_info) { 100 void DelegatedFrameHost::WasShown(const ui::LatencyInfo& latency_info) {
93 delegated_frame_evictor_->SetVisible(true); 101 delegated_frame_evictor_->SetVisible(true);
94 102
95 if (surface_id_.is_null() && !frame_provider_.get() && 103 if (surface_id_.is_null() && !frame_provider_.get() &&
96 !released_front_lock_.get()) { 104 !released_front_lock_.get()) {
97 ui::Compositor* compositor = client_->GetCompositor(); 105 ui::Compositor* compositor = client_->GetCompositor();
98 if (compositor) 106 if (compositor)
99 released_front_lock_ = compositor->GetCompositorLock(); 107 released_front_lock_ = compositor->GetCompositorLock();
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 dfh->AsWeakPtr(), 866 dfh->AsWeakPtr(),
859 callback, 867 callback,
860 subscriber_texture, 868 subscriber_texture,
861 base::Passed(&release_callback)); 869 base::Passed(&release_callback));
862 yuv_readback_pipeline->ReadbackYUV(texture_mailbox.mailbox(), 870 yuv_readback_pipeline->ReadbackYUV(texture_mailbox.mailbox(),
863 texture_mailbox.sync_point(), 871 texture_mailbox.sync_point(),
864 video_frame.get(), 872 video_frame.get(),
865 finished_callback); 873 finished_callback);
866 } 874 }
867 875
876 void DelegatedFrameHost::OnSetNeedsBeginFrames(bool needs_begin_frames) {
877 DCHECK(begin_frame_scheduling_enabled_);
878 DCHECK(client_->GetCompositor());
879
880 if (needs_begin_frames_ == needs_begin_frames)
881 return;
882
883 needs_begin_frames_ = needs_begin_frames;
884
885 if (needs_begin_frames)
886 StartObservingBeginFrames();
887 else
888 StopObservingBeginFrames();
889 }
890
868 //////////////////////////////////////////////////////////////////////////////// 891 ////////////////////////////////////////////////////////////////////////////////
869 // DelegatedFrameHost, ui::CompositorObserver implementation: 892 // DelegatedFrameHost, ui::CompositorObserver implementation:
870 893
871 void DelegatedFrameHost::OnCompositingDidCommit( 894 void DelegatedFrameHost::OnCompositingDidCommit(
872 ui::Compositor* compositor) { 895 ui::Compositor* compositor) {
873 RenderWidgetHostImpl* host = client_->GetHost(); 896 RenderWidgetHostImpl* host = client_->GetHost();
874 if (can_lock_compositor_ == NO_PENDING_COMMIT) { 897 if (can_lock_compositor_ == NO_PENDING_COMMIT) {
875 can_lock_compositor_ = YES_CAN_LOCK; 898 can_lock_compositor_ = YES_CAN_LOCK;
876 if (resize_lock_.get() && resize_lock_->GrabDeferredLock()) 899 if (resize_lock_.get() && resize_lock_->GrabDeferredLock())
877 can_lock_compositor_ = YES_DID_LOCK; 900 can_lock_compositor_ = YES_DID_LOCK;
(...skipping 24 matching lines...) Expand all
902 925
903 void DelegatedFrameHost::OnCompositingLockStateChanged( 926 void DelegatedFrameHost::OnCompositingLockStateChanged(
904 ui::Compositor* compositor) { 927 ui::Compositor* compositor) {
905 // A compositor lock that is part of a resize lock timed out. We 928 // A compositor lock that is part of a resize lock timed out. We
906 // should display a renderer frame. 929 // should display a renderer frame.
907 if (!compositor->IsLocked() && can_lock_compositor_ == YES_DID_LOCK) { 930 if (!compositor->IsLocked() && can_lock_compositor_ == YES_DID_LOCK) {
908 can_lock_compositor_ = NO_PENDING_RENDERER_FRAME; 931 can_lock_compositor_ = NO_PENDING_RENDERER_FRAME;
909 } 932 }
910 } 933 }
911 934
935 ///////////////////////////////////////////////////////////////////////////////
936 // ui::CompositorBeginFrameObserver implementation.
937 void DelegatedFrameHost::OnSendBeginFrame(
938 const cc::BeginFrameArgs& args) {
939 DCHECK(begin_frame_scheduling_enabled_);
940
941 client_->OnSendBeginFrame(args);
942 last_sent_begin_frame_args_ = args;
943 SetVSyncParams(args.frame_time, args.interval);
944 }
945
946 ///////////////////////////////////////////////////////////////////////////////
947 // ui::CompositorVSyncManager::Observer implementation.
912 void DelegatedFrameHost::OnUpdateVSyncParameters( 948 void DelegatedFrameHost::OnUpdateVSyncParameters(
913 base::TimeTicks timebase, 949 base::TimeTicks timebase,
914 base::TimeDelta interval) { 950 base::TimeDelta interval) {
915 vsync_timebase_ = timebase; 951 DCHECK(!begin_frame_scheduling_enabled_);
916 vsync_interval_ = interval; 952 SetVSyncParams(timebase, interval);
917 RenderWidgetHostImpl* host = client_->GetHost(); 953 RenderWidgetHostImpl* host = client_->GetHost();
918 if (client_->IsVisible()) 954 if (client_->IsVisible())
919 host->UpdateVSyncParameters(timebase, interval); 955 host->UpdateVSyncParameters(timebase, interval);
920 } 956 }
921 957
922 //////////////////////////////////////////////////////////////////////////////// 958 ////////////////////////////////////////////////////////////////////////////////
923 // RenderWidgetHostViewAura, ImageTransportFactoryObserver implementation: 959 // RenderWidgetHostViewAura, ImageTransportFactoryObserver implementation:
924 960
925 void DelegatedFrameHost::OnLostResources() { 961 void DelegatedFrameHost::OnLostResources() {
926 RenderWidgetHostImpl* host = client_->GetHost(); 962 RenderWidgetHostImpl* host = client_->GetHost();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 998
963 if (!compositor->HasObserver(this)) 999 if (!compositor->HasObserver(this))
964 compositor->AddObserver(this); 1000 compositor->AddObserver(this);
965 1001
966 can_lock_compositor_ = NO_PENDING_COMMIT; 1002 can_lock_compositor_ = NO_PENDING_COMMIT;
967 if (!callback.is_null()) 1003 if (!callback.is_null())
968 on_compositing_did_commit_callbacks_.push_back(callback); 1004 on_compositing_did_commit_callbacks_.push_back(callback);
969 } 1005 }
970 1006
971 void DelegatedFrameHost::AddedToWindow() { 1007 void DelegatedFrameHost::AddedToWindow() {
1008 // When |begin_frame_scheduling_enabled_| is true, vsync parameter is not used
1009 // in renderer.
1010 if (begin_frame_scheduling_enabled_) {
1011 if (needs_begin_frames_)
1012 StartObservingBeginFrames();
1013 return;
1014 }
1015
972 ui::Compositor* compositor = client_->GetCompositor(); 1016 ui::Compositor* compositor = client_->GetCompositor();
973 if (compositor) { 1017 if (compositor) {
974 DCHECK(!vsync_manager_.get()); 1018 DCHECK(!vsync_manager_.get());
975 vsync_manager_ = compositor->vsync_manager(); 1019 vsync_manager_ = compositor->vsync_manager();
976 vsync_manager_->AddObserver(this); 1020 vsync_manager_->AddObserver(this);
977 } 1021 }
978 } 1022 }
979 1023
980 void DelegatedFrameHost::RemovingFromWindow() { 1024 void DelegatedFrameHost::RemovingFromWindow() {
981 RunOnCommitCallbacks(); 1025 RunOnCommitCallbacks();
982 resize_lock_.reset(); 1026 resize_lock_.reset();
983 client_->GetHost()->WasResized(); 1027 client_->GetHost()->WasResized();
984 ui::Compositor* compositor = client_->GetCompositor(); 1028 ui::Compositor* compositor = client_->GetCompositor();
985 if (compositor && compositor->HasObserver(this)) 1029 if (compositor && compositor->HasObserver(this))
986 compositor->RemoveObserver(this); 1030 compositor->RemoveObserver(this);
987 1031
1032 if (begin_frame_scheduling_enabled_) {
1033 DCHECK(!vsync_manager_) << "Not used with unifed BeginFrame";
1034 if (needs_begin_frames_)
1035 StopObservingBeginFrames();
1036 return;
1037 }
1038
988 if (vsync_manager_.get()) { 1039 if (vsync_manager_.get()) {
989 vsync_manager_->RemoveObserver(this); 1040 vsync_manager_->RemoveObserver(this);
990 vsync_manager_ = NULL; 1041 vsync_manager_ = NULL;
991 } 1042 }
992 } 1043 }
993 1044
994 void DelegatedFrameHost::LockResources() { 1045 void DelegatedFrameHost::LockResources() {
995 DCHECK(frame_provider_.get() || !surface_id_.is_null()); 1046 DCHECK(frame_provider_.get() || !surface_id_.is_null());
996 delegated_frame_evictor_->LockFrame(); 1047 delegated_frame_evictor_->LockFrame();
997 } 1048 }
998 1049
999 void DelegatedFrameHost::UnlockResources() { 1050 void DelegatedFrameHost::UnlockResources() {
1000 DCHECK(frame_provider_.get() || !surface_id_.is_null()); 1051 DCHECK(frame_provider_.get() || !surface_id_.is_null());
1001 delegated_frame_evictor_->UnlockFrame(); 1052 delegated_frame_evictor_->UnlockFrame();
1002 } 1053 }
1003 1054
1055 void DelegatedFrameHost::StartObservingBeginFrames() {
1056 DCHECK(begin_frame_scheduling_enabled_);
1057 DCHECK(client_->GetCompositor());
1058
1059 client_->GetCompositor()->AddBeginFrameObserver(this,
1060 last_sent_begin_frame_args_);
1061 }
1062
1063 void DelegatedFrameHost::StopObservingBeginFrames() {
1064 DCHECK(begin_frame_scheduling_enabled_);
1065 DCHECK(client_->GetCompositor());
1066
1067 client_->GetCompositor()->RemoveBeginFrameObserver(this);
1068 }
1069
1070 void DelegatedFrameHost::SetVSyncParams(base::TimeTicks timebase,
1071 base::TimeDelta interval) {
1072 vsync_timebase_ = timebase;
1073 vsync_interval_ = interval;
1074 }
1075
1004 //////////////////////////////////////////////////////////////////////////////// 1076 ////////////////////////////////////////////////////////////////////////////////
1005 // DelegatedFrameHost, ui::LayerOwnerDelegate implementation: 1077 // DelegatedFrameHost, ui::LayerOwnerDelegate implementation:
1006 1078
1007 void DelegatedFrameHost::OnLayerRecreated(ui::Layer* old_layer, 1079 void DelegatedFrameHost::OnLayerRecreated(ui::Layer* old_layer,
1008 ui::Layer* new_layer) { 1080 ui::Layer* new_layer) {
1009 // The new_layer is the one that will be used by our Window, so that's the one 1081 // The new_layer is the one that will be used by our Window, so that's the one
1010 // that should keep our frame. old_layer will be returned to the 1082 // that should keep our frame. old_layer will be returned to the
1011 // RecreateLayer caller, and should have a copy. 1083 // RecreateLayer caller, and should have a copy.
1012 if (frame_provider_.get()) { 1084 if (frame_provider_.get()) {
1013 new_layer->SetShowDelegatedContent(frame_provider_.get(), 1085 new_layer->SetShowDelegatedContent(frame_provider_.get(),
1014 current_frame_size_in_dip_); 1086 current_frame_size_in_dip_);
1015 } 1087 }
1016 if (!surface_id_.is_null()) { 1088 if (!surface_id_.is_null()) {
1017 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); 1089 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
1018 cc::SurfaceManager* manager = factory->GetSurfaceManager(); 1090 cc::SurfaceManager* manager = factory->GetSurfaceManager();
1019 new_layer->SetShowSurface( 1091 new_layer->SetShowSurface(
1020 surface_id_, base::Bind(&SatisfyCallback, base::Unretained(manager)), 1092 surface_id_, base::Bind(&SatisfyCallback, base::Unretained(manager)),
1021 base::Bind(&RequireCallback, base::Unretained(manager)), 1093 base::Bind(&RequireCallback, base::Unretained(manager)),
1022 current_surface_size_, current_scale_factor_, 1094 current_surface_size_, current_scale_factor_,
1023 current_frame_size_in_dip_); 1095 current_frame_size_in_dip_);
1024 } 1096 }
1025 } 1097 }
1026 1098
1027 } // namespace content 1099 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698