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

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

Issue 859423002: Explicitly specify the ui::Compositor to DelegatedFrameHost (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add aura:: Created 5 years, 11 months 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/output/compositor_frame.h" 9 #include "cc/output/compositor_frame.h"
10 #include "cc/output/compositor_frame_ack.h" 10 #include "cc/output/compositor_frame_ack.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 void DelegatedFrameHostClient::RequestCopyOfOutput( 72 void DelegatedFrameHostClient::RequestCopyOfOutput(
73 scoped_ptr<cc::CopyOutputRequest> request) { 73 scoped_ptr<cc::CopyOutputRequest> request) {
74 GetDelegatedFrameHost()->RequestCopyOfOutput(request.Pass()); 74 GetDelegatedFrameHost()->RequestCopyOfOutput(request.Pass());
75 } 75 }
76 76
77 //////////////////////////////////////////////////////////////////////////////// 77 ////////////////////////////////////////////////////////////////////////////////
78 // DelegatedFrameHost 78 // DelegatedFrameHost
79 79
80 DelegatedFrameHost::DelegatedFrameHost(DelegatedFrameHostClient* client) 80 DelegatedFrameHost::DelegatedFrameHost(DelegatedFrameHostClient* client)
81 : client_(client), 81 : client_(client),
82 compositor_(nullptr),
82 use_surfaces_(UseSurfacesEnabled()), 83 use_surfaces_(UseSurfacesEnabled()),
83 last_output_surface_id_(0), 84 last_output_surface_id_(0),
84 pending_delegated_ack_count_(0), 85 pending_delegated_ack_count_(0),
85 skipped_frames_(false), 86 skipped_frames_(false),
86 current_scale_factor_(1.f), 87 current_scale_factor_(1.f),
87 can_lock_compositor_(YES_CAN_LOCK), 88 can_lock_compositor_(YES_CAN_LOCK),
88 delegated_frame_evictor_(new DelegatedFrameEvictor(this)) { 89 delegated_frame_evictor_(new DelegatedFrameEvictor(this)) {
89 ImageTransportFactory::GetInstance()->AddObserver(this); 90 ImageTransportFactory::GetInstance()->AddObserver(this);
90 } 91 }
91 92
92 void DelegatedFrameHost::WasShown(const ui::LatencyInfo& latency_info) { 93 void DelegatedFrameHost::WasShown(const ui::LatencyInfo& latency_info) {
93 delegated_frame_evictor_->SetVisible(true); 94 delegated_frame_evictor_->SetVisible(true);
94 95
95 if (surface_id_.is_null() && !frame_provider_.get() && 96 if (surface_id_.is_null() && !frame_provider_.get() &&
96 !released_front_lock_.get()) { 97 !released_front_lock_.get()) {
97 ui::Compositor* compositor = client_->GetCompositor(); 98 if (compositor_)
98 if (compositor) 99 released_front_lock_ = compositor_->GetCompositorLock();
99 released_front_lock_ = compositor->GetCompositorLock();
100 } 100 }
101 101
102 ui::Compositor* compositor = client_->GetCompositor(); 102 if (compositor_) {
103 if (compositor) { 103 compositor_->SetLatencyInfo(latency_info);
104 compositor->SetLatencyInfo(latency_info);
105 } 104 }
106 } 105 }
107 106
108 bool DelegatedFrameHost::HasSavedFrame() { 107 bool DelegatedFrameHost::HasSavedFrame() {
109 return delegated_frame_evictor_->HasFrame(); 108 return delegated_frame_evictor_->HasFrame();
110 } 109 }
111 110
112 void DelegatedFrameHost::WasHidden() { 111 void DelegatedFrameHost::WasHidden() {
113 delegated_frame_evictor_->SetVisible(false); 112 delegated_frame_evictor_->SetVisible(false);
114 released_front_lock_ = NULL; 113 released_front_lock_ = NULL;
115 } 114 }
116 115
117 void DelegatedFrameHost::MaybeCreateResizeLock() { 116 void DelegatedFrameHost::MaybeCreateResizeLock() {
118 if (!client_->ShouldCreateResizeLock()) 117 if (!client_->ShouldCreateResizeLock())
119 return; 118 return;
120 DCHECK(client_->GetCompositor()); 119 DCHECK(compositor_);
121 120
122 // Listen to changes in the compositor lock state. 121 // Listen to changes in the compositor lock state.
123 ui::Compositor* compositor = client_->GetCompositor(); 122 if (!compositor_->HasObserver(this))
124 if (!compositor->HasObserver(this)) 123 compositor_->AddObserver(this);
125 compositor->AddObserver(this);
126 124
127 bool defer_compositor_lock = 125 bool defer_compositor_lock =
128 can_lock_compositor_ == NO_PENDING_RENDERER_FRAME || 126 can_lock_compositor_ == NO_PENDING_RENDERER_FRAME ||
129 can_lock_compositor_ == NO_PENDING_COMMIT; 127 can_lock_compositor_ == NO_PENDING_COMMIT;
130 128
131 if (can_lock_compositor_ == YES_CAN_LOCK) 129 if (can_lock_compositor_ == YES_CAN_LOCK)
132 can_lock_compositor_ = YES_DID_LOCK; 130 can_lock_compositor_ = YES_DID_LOCK;
133 131
134 resize_lock_ = client_->CreateResizeLock(defer_compositor_lock); 132 resize_lock_ = client_->CreateResizeLock(defer_compositor_lock);
135 } 133 }
136 134
137 bool DelegatedFrameHost::ShouldCreateResizeLock() { 135 bool DelegatedFrameHost::ShouldCreateResizeLock() {
138 RenderWidgetHostImpl* host = client_->GetHost(); 136 RenderWidgetHostImpl* host = client_->GetHost();
139 137
140 if (resize_lock_) 138 if (resize_lock_)
141 return false; 139 return false;
142 140
143 if (host->auto_resize_enabled()) 141 if (host->auto_resize_enabled())
144 return false; 142 return false;
145 143
146 gfx::Size desired_size = client_->DesiredFrameSize(); 144 gfx::Size desired_size = client_->DesiredFrameSize();
147 if (desired_size == current_frame_size_in_dip_ || desired_size.IsEmpty()) 145 if (desired_size == current_frame_size_in_dip_ || desired_size.IsEmpty())
148 return false; 146 return false;
149 147
150 ui::Compositor* compositor = client_->GetCompositor(); 148 if (!compositor_)
151 if (!compositor)
152 return false; 149 return false;
153 150
154 return true; 151 return true;
155 } 152 }
156 153
157 void DelegatedFrameHost::RequestCopyOfOutput( 154 void DelegatedFrameHost::RequestCopyOfOutput(
158 scoped_ptr<cc::CopyOutputRequest> request) { 155 scoped_ptr<cc::CopyOutputRequest> request) {
159 client_->GetLayer()->RequestCopyOfOutput(request.Pass()); 156 client_->GetLayer()->RequestCopyOfOutput(request.Pass());
160 } 157 }
161 158
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 if (subscriber_texture.get()) { 215 if (subscriber_texture.get()) {
219 request->SetTextureMailbox( 216 request->SetTextureMailbox(
220 cc::TextureMailbox(subscriber_texture->mailbox(), 217 cc::TextureMailbox(subscriber_texture->mailbox(),
221 subscriber_texture->target(), 218 subscriber_texture->target(),
222 subscriber_texture->sync_point())); 219 subscriber_texture->sync_point()));
223 } 220 }
224 client_->RequestCopyOfOutput(request.Pass()); 221 client_->RequestCopyOfOutput(request.Pass());
225 } 222 }
226 223
227 bool DelegatedFrameHost::CanCopyToBitmap() const { 224 bool DelegatedFrameHost::CanCopyToBitmap() const {
228 return client_->GetCompositor() && 225 return compositor_ && client_->GetLayer()->has_external_content();
229 client_->GetLayer()->has_external_content();
230 } 226 }
231 227
232 bool DelegatedFrameHost::CanCopyToVideoFrame() const { 228 bool DelegatedFrameHost::CanCopyToVideoFrame() const {
233 return client_->GetCompositor() && 229 return compositor_ && client_->GetLayer()->has_external_content();
234 client_->GetLayer()->has_external_content();
235 } 230 }
236 231
237 bool DelegatedFrameHost::CanSubscribeFrame() const { 232 bool DelegatedFrameHost::CanSubscribeFrame() const {
238 return true; 233 return true;
239 } 234 }
240 235
241 void DelegatedFrameHost::BeginFrameSubscription( 236 void DelegatedFrameHost::BeginFrameSubscription(
242 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) { 237 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) {
243 frame_subscriber_ = subscriber.Pass(); 238 frame_subscriber_ = subscriber.Pass();
244 } 239 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 271
277 void DelegatedFrameHost::CheckResizeLock() { 272 void DelegatedFrameHost::CheckResizeLock() {
278 if (!resize_lock_ || 273 if (!resize_lock_ ||
279 resize_lock_->expected_size() != current_frame_size_in_dip_) 274 resize_lock_->expected_size() != current_frame_size_in_dip_)
280 return; 275 return;
281 276
282 // Since we got the size we were looking for, unlock the compositor. But delay 277 // Since we got the size we were looking for, unlock the compositor. But delay
283 // the release of the lock until we've kicked a frame with the new texture, to 278 // the release of the lock until we've kicked a frame with the new texture, to
284 // avoid resizing the UI before we have a chance to draw a "good" frame. 279 // avoid resizing the UI before we have a chance to draw a "good" frame.
285 resize_lock_->UnlockCompositor(); 280 resize_lock_->UnlockCompositor();
286 ui::Compositor* compositor = client_->GetCompositor(); 281 if (compositor_) {
287 if (compositor) { 282 if (!compositor_->HasObserver(this))
288 if (!compositor->HasObserver(this)) 283 compositor_->AddObserver(this);
289 compositor->AddObserver(this);
290 } 284 }
291 } 285 }
292 286
293 void DelegatedFrameHost::DidReceiveFrameFromRenderer( 287 void DelegatedFrameHost::DidReceiveFrameFromRenderer(
294 const gfx::Rect& damage_rect) { 288 const gfx::Rect& damage_rect) {
295 if (!frame_subscriber() || !CanCopyToVideoFrame()) 289 if (!frame_subscriber() || !CanCopyToVideoFrame())
296 return; 290 return;
297 291
298 const base::TimeTicks now = gfx::FrameTime::Now(); 292 const base::TimeTicks now = gfx::FrameTime::Now();
299 base::TimeTicks present_time; 293 base::TimeTicks present_time;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 if (resource_collection_.get()) { 372 if (resource_collection_.get()) {
379 resource_collection_->SetClient(NULL); 373 resource_collection_->SetClient(NULL);
380 374
381 if (resource_collection_->LoseAllResources()) 375 if (resource_collection_->LoseAllResources())
382 SendReturnedDelegatedResources(last_output_surface_id_); 376 SendReturnedDelegatedResources(last_output_surface_id_);
383 377
384 resource_collection_ = NULL; 378 resource_collection_ = NULL;
385 } 379 }
386 last_output_surface_id_ = output_surface_id; 380 last_output_surface_id_ = output_surface_id;
387 } 381 }
388 ui::Compositor* compositor = client_->GetCompositor(); 382 bool immediate_ack = !compositor_;
389 bool immediate_ack = !compositor;
390 if (frame_size.IsEmpty()) { 383 if (frame_size.IsEmpty()) {
391 DCHECK(frame_data->resource_list.empty()); 384 DCHECK(frame_data->resource_list.empty());
392 EvictDelegatedFrame(); 385 EvictDelegatedFrame();
393 } else { 386 } else {
394 if (use_surfaces_) { 387 if (use_surfaces_) {
395 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); 388 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
396 cc::SurfaceManager* manager = factory->GetSurfaceManager(); 389 cc::SurfaceManager* manager = factory->GetSurfaceManager();
397 if (!surface_factory_) { 390 if (!surface_factory_) {
398 id_allocator_ = 391 id_allocator_ =
399 factory->GetContextFactory()->CreateSurfaceIdAllocator(); 392 factory->GetContextFactory()->CreateSurfaceIdAllocator();
(...skipping 23 matching lines...) Expand all
423 compositor_frame->metadata.latency_info.insert( 416 compositor_frame->metadata.latency_info.insert(
424 compositor_frame->metadata.latency_info.end(), 417 compositor_frame->metadata.latency_info.end(),
425 latency_info.begin(), 418 latency_info.begin(),
426 latency_info.end()); 419 latency_info.end());
427 420
428 gfx::Size desired_size = client_->DesiredFrameSize(); 421 gfx::Size desired_size = client_->DesiredFrameSize();
429 if (desired_size != frame_size_in_dip && !desired_size.IsEmpty()) 422 if (desired_size != frame_size_in_dip && !desired_size.IsEmpty())
430 immediate_ack = true; 423 immediate_ack = true;
431 424
432 cc::SurfaceFactory::DrawCallback ack_callback; 425 cc::SurfaceFactory::DrawCallback ack_callback;
433 if (compositor && !immediate_ack) { 426 if (compositor_ && !immediate_ack) {
434 ack_callback = base::Bind(&DelegatedFrameHost::SurfaceDrawn, 427 ack_callback = base::Bind(&DelegatedFrameHost::SurfaceDrawn,
435 AsWeakPtr(), output_surface_id); 428 AsWeakPtr(), output_surface_id);
436 } 429 }
437 surface_factory_->SubmitFrame( 430 surface_factory_->SubmitFrame(
438 surface_id_, compositor_frame.Pass(), ack_callback); 431 surface_id_, compositor_frame.Pass(), ack_callback);
439 } else { 432 } else {
440 if (!resource_collection_.get()) { 433 if (!resource_collection_.get()) {
441 resource_collection_ = new cc::DelegatedFrameResourceCollection; 434 resource_collection_ = new cc::DelegatedFrameResourceCollection;
442 resource_collection_->SetClient(this); 435 resource_collection_->SetClient(this);
443 } 436 }
(...skipping 21 matching lines...) Expand all
465 if (!damage_rect_in_dip.IsEmpty()) 458 if (!damage_rect_in_dip.IsEmpty())
466 client_->GetLayer()->OnDelegatedFrameDamage(damage_rect_in_dip); 459 client_->GetLayer()->OnDelegatedFrameDamage(damage_rect_in_dip);
467 460
468 pending_delegated_ack_count_++; 461 pending_delegated_ack_count_++;
469 462
470 if (immediate_ack) { 463 if (immediate_ack) {
471 SendDelegatedFrameAck(output_surface_id); 464 SendDelegatedFrameAck(output_surface_id);
472 } else if (!use_surfaces_) { 465 } else if (!use_surfaces_) {
473 std::vector<ui::LatencyInfo>::const_iterator it; 466 std::vector<ui::LatencyInfo>::const_iterator it;
474 for (it = latency_info.begin(); it != latency_info.end(); ++it) 467 for (it = latency_info.begin(); it != latency_info.end(); ++it)
475 compositor->SetLatencyInfo(*it); 468 compositor_->SetLatencyInfo(*it);
476 // If we've previously skipped any latency infos add them. 469 // If we've previously skipped any latency infos add them.
477 for (it = skipped_latency_info_list_.begin(); 470 for (it = skipped_latency_info_list_.begin();
478 it != skipped_latency_info_list_.end(); 471 it != skipped_latency_info_list_.end();
479 ++it) 472 ++it)
480 compositor->SetLatencyInfo(*it); 473 compositor_->SetLatencyInfo(*it);
481 skipped_latency_info_list_.clear(); 474 skipped_latency_info_list_.clear();
482 AddOnCommitCallbackAndDisableLocks( 475 AddOnCommitCallbackAndDisableLocks(
483 base::Bind(&DelegatedFrameHost::SendDelegatedFrameAck, 476 base::Bind(&DelegatedFrameHost::SendDelegatedFrameAck,
484 AsWeakPtr(), 477 AsWeakPtr(),
485 output_surface_id)); 478 output_surface_id));
486 } else { 479 } else {
487 AddOnCommitCallbackAndDisableLocks(base::Closure()); 480 AddOnCommitCallbackAndDisableLocks(base::Closure());
488 } 481 }
489 DidReceiveFrameFromRenderer(damage_rect); 482 DidReceiveFrameFromRenderer(damage_rect);
490 if (frame_provider_.get() || !surface_id_.is_null()) 483 if (frame_provider_.get() || !surface_id_.is_null())
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 idle_frame_subscriber_textures_.clear(); 937 idle_frame_subscriber_textures_.clear();
945 yuv_readback_pipeline_.reset(); 938 yuv_readback_pipeline_.reset();
946 939
947 host->ScheduleComposite(); 940 host->ScheduleComposite();
948 } 941 }
949 942
950 //////////////////////////////////////////////////////////////////////////////// 943 ////////////////////////////////////////////////////////////////////////////////
951 // DelegatedFrameHost, private: 944 // DelegatedFrameHost, private:
952 945
953 DelegatedFrameHost::~DelegatedFrameHost() { 946 DelegatedFrameHost::~DelegatedFrameHost() {
947 DCHECK(!compositor_);
954 ImageTransportFactory::GetInstance()->RemoveObserver(this); 948 ImageTransportFactory::GetInstance()->RemoveObserver(this);
955 949
956 if (!surface_id_.is_null()) 950 if (!surface_id_.is_null())
957 surface_factory_->Destroy(surface_id_); 951 surface_factory_->Destroy(surface_id_);
958 if (resource_collection_.get()) 952 if (resource_collection_.get())
959 resource_collection_->SetClient(NULL); 953 resource_collection_->SetClient(NULL);
960 954
961 DCHECK(!vsync_manager_.get()); 955 DCHECK(!vsync_manager_.get());
962 } 956 }
963 957
964 void DelegatedFrameHost::RunOnCommitCallbacks() { 958 void DelegatedFrameHost::RunOnCommitCallbacks() {
965 for (std::vector<base::Closure>::const_iterator 959 for (std::vector<base::Closure>::const_iterator
966 it = on_compositing_did_commit_callbacks_.begin(); 960 it = on_compositing_did_commit_callbacks_.begin();
967 it != on_compositing_did_commit_callbacks_.end(); ++it) { 961 it != on_compositing_did_commit_callbacks_.end(); ++it) {
968 it->Run(); 962 it->Run();
969 } 963 }
970 on_compositing_did_commit_callbacks_.clear(); 964 on_compositing_did_commit_callbacks_.clear();
971 } 965 }
972 966
973 void DelegatedFrameHost::AddOnCommitCallbackAndDisableLocks( 967 void DelegatedFrameHost::AddOnCommitCallbackAndDisableLocks(
974 const base::Closure& callback) { 968 const base::Closure& callback) {
975 ui::Compositor* compositor = client_->GetCompositor(); 969 DCHECK(compositor_);
976 DCHECK(compositor);
977 970
978 if (!compositor->HasObserver(this)) 971 if (!compositor_->HasObserver(this))
979 compositor->AddObserver(this); 972 compositor_->AddObserver(this);
980 973
981 can_lock_compositor_ = NO_PENDING_COMMIT; 974 can_lock_compositor_ = NO_PENDING_COMMIT;
982 if (!callback.is_null()) 975 if (!callback.is_null())
983 on_compositing_did_commit_callbacks_.push_back(callback); 976 on_compositing_did_commit_callbacks_.push_back(callback);
984 } 977 }
985 978
986 void DelegatedFrameHost::AddedToWindow() { 979 void DelegatedFrameHost::SetCompositor(ui::Compositor* compositor) {
987 ui::Compositor* compositor = client_->GetCompositor(); 980 DCHECK(!compositor_);
988 if (compositor) { 981 if (!compositor)
989 DCHECK(!vsync_manager_.get()); 982 return;
990 vsync_manager_ = compositor->vsync_manager(); 983 compositor_ = compositor;
991 vsync_manager_->AddObserver(this); 984 DCHECK(!vsync_manager_.get());
992 } 985 vsync_manager_ = compositor_->vsync_manager();
986 vsync_manager_->AddObserver(this);
993 } 987 }
994 988
995 void DelegatedFrameHost::RemovingFromWindow() { 989 void DelegatedFrameHost::ResetCompositor() {
990 if (!compositor_)
991 return;
996 RunOnCommitCallbacks(); 992 RunOnCommitCallbacks();
997 resize_lock_.reset(); 993 resize_lock_.reset();
998 client_->GetHost()->WasResized(); 994 client_->GetHost()->WasResized();
999 ui::Compositor* compositor = client_->GetCompositor(); 995 if (compositor_->HasObserver(this))
1000 if (compositor && compositor->HasObserver(this)) 996 compositor_->RemoveObserver(this);
1001 compositor->RemoveObserver(this);
1002
1003 if (vsync_manager_.get()) { 997 if (vsync_manager_.get()) {
1004 vsync_manager_->RemoveObserver(this); 998 vsync_manager_->RemoveObserver(this);
1005 vsync_manager_ = NULL; 999 vsync_manager_ = NULL;
1006 } 1000 }
1001 compositor_ = nullptr;
1007 } 1002 }
1008 1003
1009 void DelegatedFrameHost::LockResources() { 1004 void DelegatedFrameHost::LockResources() {
1010 DCHECK(frame_provider_.get() || !surface_id_.is_null()); 1005 DCHECK(frame_provider_.get() || !surface_id_.is_null());
1011 delegated_frame_evictor_->LockFrame(); 1006 delegated_frame_evictor_->LockFrame();
1012 } 1007 }
1013 1008
1014 void DelegatedFrameHost::UnlockResources() { 1009 void DelegatedFrameHost::UnlockResources() {
1015 DCHECK(frame_provider_.get() || !surface_id_.is_null()); 1010 DCHECK(frame_provider_.get() || !surface_id_.is_null());
1016 delegated_frame_evictor_->UnlockFrame(); 1011 delegated_frame_evictor_->UnlockFrame();
(...skipping 16 matching lines...) Expand all
1033 cc::SurfaceManager* manager = factory->GetSurfaceManager(); 1028 cc::SurfaceManager* manager = factory->GetSurfaceManager();
1034 new_layer->SetShowSurface( 1029 new_layer->SetShowSurface(
1035 surface_id_, base::Bind(&SatisfyCallback, base::Unretained(manager)), 1030 surface_id_, base::Bind(&SatisfyCallback, base::Unretained(manager)),
1036 base::Bind(&RequireCallback, base::Unretained(manager)), 1031 base::Bind(&RequireCallback, base::Unretained(manager)),
1037 current_surface_size_, current_scale_factor_, 1032 current_surface_size_, current_scale_factor_,
1038 current_frame_size_in_dip_); 1033 current_frame_size_in_dip_);
1039 } 1034 }
1040 } 1035 }
1041 1036
1042 } // namespace content 1037 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698