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/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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 pending_delegated_ack_count_(0), | 56 pending_delegated_ack_count_(0), |
57 skipped_frames_(false), | 57 skipped_frames_(false), |
58 can_lock_compositor_(YES_CAN_LOCK), | 58 can_lock_compositor_(YES_CAN_LOCK), |
59 delegated_frame_evictor_(new DelegatedFrameEvictor(this)) { | 59 delegated_frame_evictor_(new DelegatedFrameEvictor(this)) { |
60 ImageTransportFactory::GetInstance()->AddObserver(this); | 60 ImageTransportFactory::GetInstance()->AddObserver(this); |
61 } | 61 } |
62 | 62 |
63 void DelegatedFrameHost::WasShown(const ui::LatencyInfo& latency_info) { | 63 void DelegatedFrameHost::WasShown(const ui::LatencyInfo& latency_info) { |
64 delegated_frame_evictor_->SetVisible(true); | 64 delegated_frame_evictor_->SetVisible(true); |
65 | 65 |
66 if (surface_id_.is_null() && !frame_provider_ && | 66 if (surface_id_.is_null() && !frame_provider_.get() && |
67 !released_front_lock_.get()) { | 67 !released_front_lock_.get()) { |
68 ui::Compositor* compositor = client_->GetCompositor(); | 68 ui::Compositor* compositor = client_->GetCompositor(); |
69 if (compositor) | 69 if (compositor) |
70 released_front_lock_ = compositor->GetCompositorLock(); | 70 released_front_lock_ = compositor->GetCompositorLock(); |
71 } | 71 } |
72 | 72 |
73 ui::Compositor* compositor = client_->GetCompositor(); | 73 ui::Compositor* compositor = client_->GetCompositor(); |
74 if (compositor) { | 74 if (compositor) { |
75 compositor->SetLatencyInfo(latency_info); | 75 compositor->SetLatencyInfo(latency_info); |
76 } | 76 } |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 scoped_ptr<cc::CompositorFrame> compositor_frame = | 379 scoped_ptr<cc::CompositorFrame> compositor_frame = |
380 make_scoped_ptr(new cc::CompositorFrame()); | 380 make_scoped_ptr(new cc::CompositorFrame()); |
381 compositor_frame->delegated_frame_data = frame_data.Pass(); | 381 compositor_frame->delegated_frame_data = frame_data.Pass(); |
382 surface_factory_->SubmitFrame( | 382 surface_factory_->SubmitFrame( |
383 surface_id_, | 383 surface_id_, |
384 compositor_frame.Pass(), | 384 compositor_frame.Pass(), |
385 base::Bind(&DelegatedFrameHost::SendDelegatedFrameAck, | 385 base::Bind(&DelegatedFrameHost::SendDelegatedFrameAck, |
386 AsWeakPtr(), | 386 AsWeakPtr(), |
387 output_surface_id)); | 387 output_surface_id)); |
388 } else { | 388 } else { |
389 if (!resource_collection_) { | 389 if (!resource_collection_.get()) { |
390 resource_collection_ = new cc::DelegatedFrameResourceCollection; | 390 resource_collection_ = new cc::DelegatedFrameResourceCollection; |
391 resource_collection_->SetClient(this); | 391 resource_collection_->SetClient(this); |
392 } | 392 } |
393 // If the physical frame size changes, we need a new |frame_provider_|. If | 393 // If the physical frame size changes, we need a new |frame_provider_|. If |
394 // the physical frame size is the same, but the size in DIP changed, we | 394 // the physical frame size is the same, but the size in DIP changed, we |
395 // need to adjust the scale at which the frames will be drawn, and we do | 395 // need to adjust the scale at which the frames will be drawn, and we do |
396 // this by making a new |frame_provider_| also to ensure the scale change | 396 // this by making a new |frame_provider_| also to ensure the scale change |
397 // is presented in sync with the new frame content. | 397 // is presented in sync with the new frame content. |
398 if (!frame_provider_.get() || | 398 if (!frame_provider_.get() || |
399 frame_size != frame_provider_->frame_size() || | 399 frame_size != frame_provider_->frame_size() || |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 if (frame_provider_.get() || !surface_id_.is_null()) | 442 if (frame_provider_.get() || !surface_id_.is_null()) |
443 delegated_frame_evictor_->SwappedFrame(!host->is_hidden()); | 443 delegated_frame_evictor_->SwappedFrame(!host->is_hidden()); |
444 // Note: the frame may have been evicted immediately. | 444 // Note: the frame may have been evicted immediately. |
445 } | 445 } |
446 | 446 |
447 void DelegatedFrameHost::SendDelegatedFrameAck(uint32 output_surface_id) { | 447 void DelegatedFrameHost::SendDelegatedFrameAck(uint32 output_surface_id) { |
448 RenderWidgetHostImpl* host = client_->GetHost(); | 448 RenderWidgetHostImpl* host = client_->GetHost(); |
449 cc::CompositorFrameAck ack; | 449 cc::CompositorFrameAck ack; |
450 if (!surface_returned_resources_.empty()) | 450 if (!surface_returned_resources_.empty()) |
451 ack.resources.swap(surface_returned_resources_); | 451 ack.resources.swap(surface_returned_resources_); |
452 if (resource_collection_) | 452 if (resource_collection_.get()) |
453 resource_collection_->TakeUnusedResourcesForChildCompositor(&ack.resources); | 453 resource_collection_->TakeUnusedResourcesForChildCompositor(&ack.resources); |
454 RenderWidgetHostImpl::SendSwapCompositorFrameAck(host->GetRoutingID(), | 454 RenderWidgetHostImpl::SendSwapCompositorFrameAck(host->GetRoutingID(), |
455 output_surface_id, | 455 output_surface_id, |
456 host->GetProcess()->GetID(), | 456 host->GetProcess()->GetID(), |
457 ack); | 457 ack); |
458 DCHECK_GT(pending_delegated_ack_count_, 0); | 458 DCHECK_GT(pending_delegated_ack_count_, 0); |
459 pending_delegated_ack_count_--; | 459 pending_delegated_ack_count_--; |
460 } | 460 } |
461 | 461 |
462 void DelegatedFrameHost::UnusedResourcesAreAvailable() { | 462 void DelegatedFrameHost::UnusedResourcesAreAvailable() { |
463 if (pending_delegated_ack_count_) | 463 if (pending_delegated_ack_count_) |
464 return; | 464 return; |
465 | 465 |
466 SendReturnedDelegatedResources(last_output_surface_id_); | 466 SendReturnedDelegatedResources(last_output_surface_id_); |
467 } | 467 } |
468 | 468 |
469 void DelegatedFrameHost::SendReturnedDelegatedResources( | 469 void DelegatedFrameHost::SendReturnedDelegatedResources( |
470 uint32 output_surface_id) { | 470 uint32 output_surface_id) { |
471 RenderWidgetHostImpl* host = client_->GetHost(); | 471 RenderWidgetHostImpl* host = client_->GetHost(); |
472 | 472 |
473 cc::CompositorFrameAck ack; | 473 cc::CompositorFrameAck ack; |
474 if (!surface_returned_resources_.empty()) { | 474 if (!surface_returned_resources_.empty()) { |
475 ack.resources.swap(surface_returned_resources_); | 475 ack.resources.swap(surface_returned_resources_); |
476 } else { | 476 } else { |
477 DCHECK(resource_collection_); | 477 DCHECK(resource_collection_.get()); |
478 resource_collection_->TakeUnusedResourcesForChildCompositor(&ack.resources); | 478 resource_collection_->TakeUnusedResourcesForChildCompositor(&ack.resources); |
479 } | 479 } |
480 DCHECK(!ack.resources.empty()); | 480 DCHECK(!ack.resources.empty()); |
481 | 481 |
482 RenderWidgetHostImpl::SendReclaimCompositorResources( | 482 RenderWidgetHostImpl::SendReclaimCompositorResources( |
483 host->GetRoutingID(), | 483 host->GetRoutingID(), |
484 output_surface_id, | 484 output_surface_id, |
485 host->GetProcess()->GetID(), | 485 host->GetProcess()->GetID(), |
486 ack); | 486 ack); |
487 } | 487 } |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 callback.Run(result); | 645 callback.Run(result); |
646 | 646 |
647 uint32 sync_point = 0; | 647 uint32 sync_point = 0; |
648 if (result) { | 648 if (result) { |
649 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper(); | 649 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper(); |
650 sync_point = gl_helper->InsertSyncPoint(); | 650 sync_point = gl_helper->InsertSyncPoint(); |
651 } | 651 } |
652 if (release_callback) { | 652 if (release_callback) { |
653 // A release callback means the texture came from the compositor, so there | 653 // A release callback means the texture came from the compositor, so there |
654 // should be no |subscriber_texture|. | 654 // should be no |subscriber_texture|. |
655 DCHECK(!subscriber_texture); | 655 DCHECK(!subscriber_texture.get()); |
656 bool lost_resource = sync_point == 0; | 656 bool lost_resource = sync_point == 0; |
657 release_callback->Run(sync_point, lost_resource); | 657 release_callback->Run(sync_point, lost_resource); |
658 } | 658 } |
659 ReturnSubscriberTexture(dfh, subscriber_texture, sync_point); | 659 ReturnSubscriberTexture(dfh, subscriber_texture, sync_point); |
660 } | 660 } |
661 | 661 |
662 // static | 662 // static |
663 void DelegatedFrameHost::CopyFromCompositingSurfaceHasResultForVideo( | 663 void DelegatedFrameHost::CopyFromCompositingSurfaceHasResultForVideo( |
664 base::WeakPtr<DelegatedFrameHost> dfh, | 664 base::WeakPtr<DelegatedFrameHost> dfh, |
665 scoped_refptr<OwnedMailbox> subscriber_texture, | 665 scoped_refptr<OwnedMailbox> subscriber_texture, |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
856 // DelegatedFrameHost, private: | 856 // DelegatedFrameHost, private: |
857 | 857 |
858 DelegatedFrameHost::~DelegatedFrameHost() { | 858 DelegatedFrameHost::~DelegatedFrameHost() { |
859 ImageTransportFactory::GetInstance()->RemoveObserver(this); | 859 ImageTransportFactory::GetInstance()->RemoveObserver(this); |
860 | 860 |
861 if (!surface_id_.is_null()) | 861 if (!surface_id_.is_null()) |
862 surface_factory_->Destroy(surface_id_); | 862 surface_factory_->Destroy(surface_id_); |
863 if (resource_collection_.get()) | 863 if (resource_collection_.get()) |
864 resource_collection_->SetClient(NULL); | 864 resource_collection_->SetClient(NULL); |
865 | 865 |
866 DCHECK(!vsync_manager_); | 866 DCHECK(!vsync_manager_.get()); |
867 } | 867 } |
868 | 868 |
869 void DelegatedFrameHost::RunOnCommitCallbacks() { | 869 void DelegatedFrameHost::RunOnCommitCallbacks() { |
870 for (std::vector<base::Closure>::const_iterator | 870 for (std::vector<base::Closure>::const_iterator |
871 it = on_compositing_did_commit_callbacks_.begin(); | 871 it = on_compositing_did_commit_callbacks_.begin(); |
872 it != on_compositing_did_commit_callbacks_.end(); ++it) { | 872 it != on_compositing_did_commit_callbacks_.end(); ++it) { |
873 it->Run(); | 873 it->Run(); |
874 } | 874 } |
875 on_compositing_did_commit_callbacks_.clear(); | 875 on_compositing_did_commit_callbacks_.clear(); |
876 } | 876 } |
877 | 877 |
878 void DelegatedFrameHost::AddOnCommitCallbackAndDisableLocks( | 878 void DelegatedFrameHost::AddOnCommitCallbackAndDisableLocks( |
879 const base::Closure& callback) { | 879 const base::Closure& callback) { |
880 ui::Compositor* compositor = client_->GetCompositor(); | 880 ui::Compositor* compositor = client_->GetCompositor(); |
881 DCHECK(compositor); | 881 DCHECK(compositor); |
882 | 882 |
883 if (!compositor->HasObserver(this)) | 883 if (!compositor->HasObserver(this)) |
884 compositor->AddObserver(this); | 884 compositor->AddObserver(this); |
885 | 885 |
886 can_lock_compositor_ = NO_PENDING_COMMIT; | 886 can_lock_compositor_ = NO_PENDING_COMMIT; |
887 on_compositing_did_commit_callbacks_.push_back(callback); | 887 on_compositing_did_commit_callbacks_.push_back(callback); |
888 } | 888 } |
889 | 889 |
890 void DelegatedFrameHost::AddedToWindow() { | 890 void DelegatedFrameHost::AddedToWindow() { |
891 ui::Compositor* compositor = client_->GetCompositor(); | 891 ui::Compositor* compositor = client_->GetCompositor(); |
892 if (compositor) { | 892 if (compositor) { |
893 DCHECK(!vsync_manager_); | 893 DCHECK(!vsync_manager_.get()); |
894 vsync_manager_ = compositor->vsync_manager(); | 894 vsync_manager_ = compositor->vsync_manager(); |
895 vsync_manager_->AddObserver(this); | 895 vsync_manager_->AddObserver(this); |
896 } | 896 } |
897 } | 897 } |
898 | 898 |
899 void DelegatedFrameHost::RemovingFromWindow() { | 899 void DelegatedFrameHost::RemovingFromWindow() { |
900 RunOnCommitCallbacks(); | 900 RunOnCommitCallbacks(); |
901 resize_lock_.reset(); | 901 resize_lock_.reset(); |
902 client_->GetHost()->WasResized(); | 902 client_->GetHost()->WasResized(); |
903 ui::Compositor* compositor = client_->GetCompositor(); | 903 ui::Compositor* compositor = client_->GetCompositor(); |
904 if (compositor && compositor->HasObserver(this)) | 904 if (compositor && compositor->HasObserver(this)) |
905 compositor->RemoveObserver(this); | 905 compositor->RemoveObserver(this); |
906 | 906 |
907 if (vsync_manager_) { | 907 if (vsync_manager_.get()) { |
908 vsync_manager_->RemoveObserver(this); | 908 vsync_manager_->RemoveObserver(this); |
909 vsync_manager_ = NULL; | 909 vsync_manager_ = NULL; |
910 } | 910 } |
911 } | 911 } |
912 | 912 |
913 void DelegatedFrameHost::LockResources() { | 913 void DelegatedFrameHost::LockResources() { |
914 DCHECK(frame_provider_ || !surface_id_.is_null()); | 914 DCHECK(frame_provider_.get() || !surface_id_.is_null()); |
915 delegated_frame_evictor_->LockFrame(); | 915 delegated_frame_evictor_->LockFrame(); |
916 } | 916 } |
917 | 917 |
918 void DelegatedFrameHost::UnlockResources() { | 918 void DelegatedFrameHost::UnlockResources() { |
919 DCHECK(frame_provider_ || !surface_id_.is_null()); | 919 DCHECK(frame_provider_.get() || !surface_id_.is_null()); |
920 delegated_frame_evictor_->UnlockFrame(); | 920 delegated_frame_evictor_->UnlockFrame(); |
921 } | 921 } |
922 | 922 |
923 //////////////////////////////////////////////////////////////////////////////// | 923 //////////////////////////////////////////////////////////////////////////////// |
924 // DelegatedFrameHost, ui::LayerOwnerDelegate implementation: | 924 // DelegatedFrameHost, ui::LayerOwnerDelegate implementation: |
925 | 925 |
926 void DelegatedFrameHost::OnLayerRecreated(ui::Layer* old_layer, | 926 void DelegatedFrameHost::OnLayerRecreated(ui::Layer* old_layer, |
927 ui::Layer* new_layer) { | 927 ui::Layer* new_layer) { |
928 // The new_layer is the one that will be used by our Window, so that's the one | 928 // The new_layer is the one that will be used by our Window, so that's the one |
929 // that should keep our frame. old_layer will be returned to the | 929 // that should keep our frame. old_layer will be returned to the |
930 // RecreateLayer caller, and should have a copy. | 930 // RecreateLayer caller, and should have a copy. |
931 if (frame_provider_.get()) { | 931 if (frame_provider_.get()) { |
932 new_layer->SetShowDelegatedContent(frame_provider_.get(), | 932 new_layer->SetShowDelegatedContent(frame_provider_.get(), |
933 current_frame_size_in_dip_); | 933 current_frame_size_in_dip_); |
934 } | 934 } |
935 if (!surface_id_.is_null()) { | 935 if (!surface_id_.is_null()) { |
936 new_layer->SetShowSurface(surface_id_, current_frame_size_in_dip_); | 936 new_layer->SetShowSurface(surface_id_, current_frame_size_in_dip_); |
937 } | 937 } |
938 } | 938 } |
939 | 939 |
940 } // namespace content | 940 } // namespace content |
OLD | NEW |