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

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: Move common logic to DelegatedFrameHost 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 TRACE_EVENT1("cc",
884 "DelegatedFrameHost::OnSetNeedsBeginFrames",
885 "needs_begin_frames",
886 needs_begin_frames);
887
888 needs_begin_frames_ = needs_begin_frames;
889
890 if (needs_begin_frames)
891 StartObservingBeginFrames();
892 else
893 StopObservingBeginFrames();
894 }
895
868 //////////////////////////////////////////////////////////////////////////////// 896 ////////////////////////////////////////////////////////////////////////////////
869 // DelegatedFrameHost, ui::CompositorObserver implementation: 897 // DelegatedFrameHost, ui::CompositorObserver implementation:
870 898
871 void DelegatedFrameHost::OnCompositingDidCommit( 899 void DelegatedFrameHost::OnCompositingDidCommit(
872 ui::Compositor* compositor) { 900 ui::Compositor* compositor) {
873 RenderWidgetHostImpl* host = client_->GetHost(); 901 RenderWidgetHostImpl* host = client_->GetHost();
874 if (can_lock_compositor_ == NO_PENDING_COMMIT) { 902 if (can_lock_compositor_ == NO_PENDING_COMMIT) {
875 can_lock_compositor_ = YES_CAN_LOCK; 903 can_lock_compositor_ = YES_CAN_LOCK;
876 if (resize_lock_.get() && resize_lock_->GrabDeferredLock()) 904 if (resize_lock_.get() && resize_lock_->GrabDeferredLock())
877 can_lock_compositor_ = YES_DID_LOCK; 905 can_lock_compositor_ = YES_DID_LOCK;
(...skipping 24 matching lines...) Expand all
902 930
903 void DelegatedFrameHost::OnCompositingLockStateChanged( 931 void DelegatedFrameHost::OnCompositingLockStateChanged(
904 ui::Compositor* compositor) { 932 ui::Compositor* compositor) {
905 // A compositor lock that is part of a resize lock timed out. We 933 // A compositor lock that is part of a resize lock timed out. We
906 // should display a renderer frame. 934 // should display a renderer frame.
907 if (!compositor->IsLocked() && can_lock_compositor_ == YES_DID_LOCK) { 935 if (!compositor->IsLocked() && can_lock_compositor_ == YES_DID_LOCK) {
908 can_lock_compositor_ = NO_PENDING_RENDERER_FRAME; 936 can_lock_compositor_ = NO_PENDING_RENDERER_FRAME;
909 } 937 }
910 } 938 }
911 939
940 ///////////////////////////////////////////////////////////////////////////////
941 // ui::CompositorBeginFrameObserver implementation.
942 void DelegatedFrameHost::OnSendBeginFrame(
943 const cc::BeginFrameArgs& args) {
944 DCHECK(begin_frame_scheduling_enabled_);
945
946 TRACE_EVENT0("cc", "DelegatedFrameHost::OnSendBeginFrame");
947 RenderWidgetHostImpl* host = client_->GetHost();
948 DCHECK(host);
949 host->Send(new ViewMsg_BeginFrame(host->GetRoutingID(), args));
950 last_begin_frame_args_ = args;
951 SetVSyncParams(args.frame_time, args.interval);
952 vsync_timebase_ = args.frame_time;
953 vsync_interval_ = args.interval;
954 }
955
956 ///////////////////////////////////////////////////////////////////////////////
957 // ui::CompositorVSyncManager::Observer implementation.
912 void DelegatedFrameHost::OnUpdateVSyncParameters( 958 void DelegatedFrameHost::OnUpdateVSyncParameters(
913 base::TimeTicks timebase, 959 base::TimeTicks timebase,
914 base::TimeDelta interval) { 960 base::TimeDelta interval) {
915 vsync_timebase_ = timebase; 961 DCHECK(!begin_frame_scheduling_enabled_);
916 vsync_interval_ = interval; 962 SetVSyncParams(timebase, interval);
917 RenderWidgetHostImpl* host = client_->GetHost(); 963 RenderWidgetHostImpl* host = client_->GetHost();
918 if (client_->IsVisible()) 964 if (client_->IsVisible())
919 host->UpdateVSyncParameters(timebase, interval); 965 host->UpdateVSyncParameters(timebase, interval);
920 } 966 }
921 967
922 //////////////////////////////////////////////////////////////////////////////// 968 ////////////////////////////////////////////////////////////////////////////////
923 // RenderWidgetHostViewAura, ImageTransportFactoryObserver implementation: 969 // RenderWidgetHostViewAura, ImageTransportFactoryObserver implementation:
924 970
925 void DelegatedFrameHost::OnLostResources() { 971 void DelegatedFrameHost::OnLostResources() {
926 RenderWidgetHostImpl* host = client_->GetHost(); 972 RenderWidgetHostImpl* host = client_->GetHost();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 1008
963 if (!compositor->HasObserver(this)) 1009 if (!compositor->HasObserver(this))
964 compositor->AddObserver(this); 1010 compositor->AddObserver(this);
965 1011
966 can_lock_compositor_ = NO_PENDING_COMMIT; 1012 can_lock_compositor_ = NO_PENDING_COMMIT;
967 if (!callback.is_null()) 1013 if (!callback.is_null())
968 on_compositing_did_commit_callbacks_.push_back(callback); 1014 on_compositing_did_commit_callbacks_.push_back(callback);
969 } 1015 }
970 1016
971 void DelegatedFrameHost::AddedToWindow() { 1017 void DelegatedFrameHost::AddedToWindow() {
1018 // When |begin_frame_scheduling_enabled_| is true, vsync parameter is not used
1019 // in renderer.
1020 if (begin_frame_scheduling_enabled_) {
1021 if (needs_begin_frames_)
1022 StartObservingBeginFrames();
1023 return;
1024 }
1025
972 ui::Compositor* compositor = client_->GetCompositor(); 1026 ui::Compositor* compositor = client_->GetCompositor();
973 if (compositor) { 1027 if (compositor) {
974 DCHECK(!vsync_manager_.get()); 1028 DCHECK(!vsync_manager_.get());
975 vsync_manager_ = compositor->vsync_manager(); 1029 vsync_manager_ = compositor->vsync_manager();
976 vsync_manager_->AddObserver(this); 1030 vsync_manager_->AddObserver(this);
977 } 1031 }
978 } 1032 }
979 1033
980 void DelegatedFrameHost::RemovingFromWindow() { 1034 void DelegatedFrameHost::RemovingFromWindow() {
981 RunOnCommitCallbacks(); 1035 RunOnCommitCallbacks();
982 resize_lock_.reset(); 1036 resize_lock_.reset();
983 client_->GetHost()->WasResized(); 1037 client_->GetHost()->WasResized();
984 ui::Compositor* compositor = client_->GetCompositor(); 1038 ui::Compositor* compositor = client_->GetCompositor();
985 if (compositor && compositor->HasObserver(this)) 1039 if (compositor && compositor->HasObserver(this))
986 compositor->RemoveObserver(this); 1040 compositor->RemoveObserver(this);
987 1041
1042 if (begin_frame_scheduling_enabled_) {
1043 DCHECK(!vsync_manager_) << "Not used with unifed BeginFrame";
1044 if (needs_begin_frames_)
1045 StopObservingBeginFrames();
1046 return;
1047 }
1048
988 if (vsync_manager_.get()) { 1049 if (vsync_manager_.get()) {
989 vsync_manager_->RemoveObserver(this); 1050 vsync_manager_->RemoveObserver(this);
990 vsync_manager_ = NULL; 1051 vsync_manager_ = NULL;
991 } 1052 }
992 } 1053 }
993 1054
994 void DelegatedFrameHost::LockResources() { 1055 void DelegatedFrameHost::LockResources() {
995 DCHECK(frame_provider_.get() || !surface_id_.is_null()); 1056 DCHECK(frame_provider_.get() || !surface_id_.is_null());
996 delegated_frame_evictor_->LockFrame(); 1057 delegated_frame_evictor_->LockFrame();
997 } 1058 }
998 1059
999 void DelegatedFrameHost::UnlockResources() { 1060 void DelegatedFrameHost::UnlockResources() {
1000 DCHECK(frame_provider_.get() || !surface_id_.is_null()); 1061 DCHECK(frame_provider_.get() || !surface_id_.is_null());
1001 delegated_frame_evictor_->UnlockFrame(); 1062 delegated_frame_evictor_->UnlockFrame();
1002 } 1063 }
1003 1064
1065 void DelegatedFrameHost::StartObservingBeginFrames() {
1066 DCHECK(begin_frame_scheduling_enabled_);
1067 DCHECK(client_->GetCompositor());
1068 DCHECK(!client_->GetCompositor()->HasBeginFrameObserver(this));
1069
1070 client_->GetCompositor()->AddBeginFrameObserver(this, last_begin_frame_args_);
1071 }
1072
1073 void DelegatedFrameHost::StopObservingBeginFrames() {
1074 DCHECK(begin_frame_scheduling_enabled_);
1075 DCHECK(client_->GetCompositor());
1076 DCHECK(client_->GetCompositor()->HasBeginFrameObserver(this));
1077
1078 client_->GetCompositor()->RemoveBeginFrameObserver(this);
1079 }
1080
1081 void DelegatedFrameHost::SetVSyncParams(base::TimeTicks timebase,
1082 base::TimeDelta interval) {
1083 vsync_timebase_ = timebase;
1084 vsync_interval_ = interval;
1085 }
1086
1004 //////////////////////////////////////////////////////////////////////////////// 1087 ////////////////////////////////////////////////////////////////////////////////
1005 // DelegatedFrameHost, ui::LayerOwnerDelegate implementation: 1088 // DelegatedFrameHost, ui::LayerOwnerDelegate implementation:
1006 1089
1007 void DelegatedFrameHost::OnLayerRecreated(ui::Layer* old_layer, 1090 void DelegatedFrameHost::OnLayerRecreated(ui::Layer* old_layer,
1008 ui::Layer* new_layer) { 1091 ui::Layer* new_layer) {
1009 // The new_layer is the one that will be used by our Window, so that's the one 1092 // 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 1093 // that should keep our frame. old_layer will be returned to the
1011 // RecreateLayer caller, and should have a copy. 1094 // RecreateLayer caller, and should have a copy.
1012 if (frame_provider_.get()) { 1095 if (frame_provider_.get()) {
1013 new_layer->SetShowDelegatedContent(frame_provider_.get(), 1096 new_layer->SetShowDelegatedContent(frame_provider_.get(),
1014 current_frame_size_in_dip_); 1097 current_frame_size_in_dip_);
1015 } 1098 }
1016 if (!surface_id_.is_null()) { 1099 if (!surface_id_.is_null()) {
1017 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); 1100 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
1018 cc::SurfaceManager* manager = factory->GetSurfaceManager(); 1101 cc::SurfaceManager* manager = factory->GetSurfaceManager();
1019 new_layer->SetShowSurface( 1102 new_layer->SetShowSurface(
1020 surface_id_, base::Bind(&SatisfyCallback, base::Unretained(manager)), 1103 surface_id_, base::Bind(&SatisfyCallback, base::Unretained(manager)),
1021 base::Bind(&RequireCallback, base::Unretained(manager)), 1104 base::Bind(&RequireCallback, base::Unretained(manager)),
1022 current_surface_size_, current_scale_factor_, 1105 current_surface_size_, current_scale_factor_,
1023 current_frame_size_in_dip_); 1106 current_frame_size_in_dip_);
1024 } 1107 }
1025 } 1108 }
1026 1109
1027 } // namespace content 1110 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698