| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 | 64 |
| 65 DelegatedFrameHost::DelegatedFrameHost(DelegatedFrameHostClient* client) | 65 DelegatedFrameHost::DelegatedFrameHost(DelegatedFrameHostClient* client) |
| 66 : client_(client), | 66 : client_(client), |
| 67 compositor_(nullptr), | 67 compositor_(nullptr), |
| 68 tick_clock_(new base::DefaultTickClock()), | 68 tick_clock_(new base::DefaultTickClock()), |
| 69 last_output_surface_id_(0), | 69 last_output_surface_id_(0), |
| 70 pending_delegated_ack_count_(0), | 70 pending_delegated_ack_count_(0), |
| 71 skipped_frames_(false), | 71 skipped_frames_(false), |
| 72 current_scale_factor_(1.f), | 72 current_scale_factor_(1.f), |
| 73 can_lock_compositor_(YES_CAN_LOCK), | 73 can_lock_compositor_(YES_CAN_LOCK), |
| 74 delegated_frame_evictor_(new DelegatedFrameEvictor(this)) { | 74 delegated_frame_evictor_(new DelegatedFrameEvictor(this)), |
| 75 begin_frame_source_(nullptr) { |
| 75 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 76 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
| 76 factory->AddObserver(this); | 77 factory->AddObserver(this); |
| 77 id_allocator_ = factory->GetContextFactory()->CreateSurfaceIdAllocator(); | 78 id_allocator_ = factory->GetContextFactory()->CreateSurfaceIdAllocator(); |
| 79 factory->GetSurfaceManager()->RegisterSurfaceFactoryClient( |
| 80 id_allocator_->id_namespace(), this); |
| 78 } | 81 } |
| 79 | 82 |
| 80 void DelegatedFrameHost::WasShown(const ui::LatencyInfo& latency_info) { | 83 void DelegatedFrameHost::WasShown(const ui::LatencyInfo& latency_info) { |
| 81 delegated_frame_evictor_->SetVisible(true); | 84 delegated_frame_evictor_->SetVisible(true); |
| 82 | 85 |
| 83 if (surface_id_.is_null() && | 86 if (surface_id_.is_null() && |
| 84 !released_front_lock_.get()) { | 87 !released_front_lock_.get()) { |
| 85 if (compositor_) | 88 if (compositor_) |
| 86 released_front_lock_ = compositor_->GetCompositorLock(); | 89 released_front_lock_ = compositor_->GetCompositorLock(); |
| 87 } | 90 } |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 } | 508 } |
| 506 | 509 |
| 507 void DelegatedFrameHost::WillDrawSurface(cc::SurfaceId id, | 510 void DelegatedFrameHost::WillDrawSurface(cc::SurfaceId id, |
| 508 const gfx::Rect& damage_rect) { | 511 const gfx::Rect& damage_rect) { |
| 509 if (id != surface_id_) | 512 if (id != surface_id_) |
| 510 return; | 513 return; |
| 511 AttemptFrameSubscriberCapture(damage_rect); | 514 AttemptFrameSubscriberCapture(damage_rect); |
| 512 } | 515 } |
| 513 | 516 |
| 514 void DelegatedFrameHost::SetBeginFrameSource( | 517 void DelegatedFrameHost::SetBeginFrameSource( |
| 515 cc::SurfaceId surface_id, | |
| 516 cc::BeginFrameSource* begin_frame_source) { | 518 cc::BeginFrameSource* begin_frame_source) { |
| 517 // TODO(tansell): Hook this up. | 519 // TODO(enne): forward this to DelegatedFrameHostClient to observe and then to |
| 520 // the renderer as an external begin frame source. |
| 518 } | 521 } |
| 519 | 522 |
| 520 void DelegatedFrameHost::EvictDelegatedFrame() { | 523 void DelegatedFrameHost::EvictDelegatedFrame() { |
| 521 client_->DelegatedFrameHostGetLayer()->SetShowSolidColorContent(); | 524 client_->DelegatedFrameHostGetLayer()->SetShowSolidColorContent(); |
| 522 if (!surface_id_.is_null()) { | 525 if (!surface_id_.is_null()) { |
| 523 surface_factory_->Destroy(surface_id_); | 526 surface_factory_->Destroy(surface_id_); |
| 524 surface_id_ = cc::SurfaceId(); | 527 surface_id_ = cc::SurfaceId(); |
| 525 } | 528 } |
| 526 delegated_frame_evictor_->DiscardedFrame(); | 529 delegated_frame_evictor_->DiscardedFrame(); |
| 527 } | 530 } |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 yuv_readback_pipeline_.reset(); | 759 yuv_readback_pipeline_.reset(); |
| 757 | 760 |
| 758 client_->DelegatedFrameHostOnLostCompositorResources(); | 761 client_->DelegatedFrameHostOnLostCompositorResources(); |
| 759 } | 762 } |
| 760 | 763 |
| 761 //////////////////////////////////////////////////////////////////////////////// | 764 //////////////////////////////////////////////////////////////////////////////// |
| 762 // DelegatedFrameHost, private: | 765 // DelegatedFrameHost, private: |
| 763 | 766 |
| 764 DelegatedFrameHost::~DelegatedFrameHost() { | 767 DelegatedFrameHost::~DelegatedFrameHost() { |
| 765 DCHECK(!compositor_); | 768 DCHECK(!compositor_); |
| 766 ImageTransportFactory::GetInstance()->RemoveObserver(this); | 769 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
| 770 factory->RemoveObserver(this); |
| 767 | 771 |
| 768 if (!surface_id_.is_null()) | 772 if (!surface_id_.is_null()) |
| 769 surface_factory_->Destroy(surface_id_); | 773 surface_factory_->Destroy(surface_id_); |
| 774 factory->GetSurfaceManager()->RegisterSurfaceFactoryClient( |
| 775 id_allocator_->id_namespace(), nullptr); |
| 770 | 776 |
| 771 DCHECK(!vsync_manager_.get()); | 777 DCHECK(!vsync_manager_.get()); |
| 772 } | 778 } |
| 773 | 779 |
| 774 void DelegatedFrameHost::RunOnCommitCallbacks() { | 780 void DelegatedFrameHost::RunOnCommitCallbacks() { |
| 775 for (std::vector<base::Closure>::const_iterator | 781 for (std::vector<base::Closure>::const_iterator |
| 776 it = on_compositing_did_commit_callbacks_.begin(); | 782 it = on_compositing_did_commit_callbacks_.begin(); |
| 777 it != on_compositing_did_commit_callbacks_.end(); ++it) { | 783 it != on_compositing_did_commit_callbacks_.end(); ++it) { |
| 778 it->Run(); | 784 it->Run(); |
| 779 } | 785 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 791 | 797 |
| 792 void DelegatedFrameHost::SetCompositor(ui::Compositor* compositor) { | 798 void DelegatedFrameHost::SetCompositor(ui::Compositor* compositor) { |
| 793 DCHECK(!compositor_); | 799 DCHECK(!compositor_); |
| 794 if (!compositor) | 800 if (!compositor) |
| 795 return; | 801 return; |
| 796 compositor_ = compositor; | 802 compositor_ = compositor; |
| 797 compositor_->AddObserver(this); | 803 compositor_->AddObserver(this); |
| 798 DCHECK(!vsync_manager_.get()); | 804 DCHECK(!vsync_manager_.get()); |
| 799 vsync_manager_ = compositor_->vsync_manager(); | 805 vsync_manager_ = compositor_->vsync_manager(); |
| 800 vsync_manager_->AddObserver(this); | 806 vsync_manager_->AddObserver(this); |
| 807 |
| 808 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
| 809 uint32_t parent = compositor->surface_id_allocator()->id_namespace(); |
| 810 factory->GetSurfaceManager()->RegisterSurfaceNamespaceHierarchy( |
| 811 parent, id_allocator_->id_namespace()); |
| 801 } | 812 } |
| 802 | 813 |
| 803 void DelegatedFrameHost::ResetCompositor() { | 814 void DelegatedFrameHost::ResetCompositor() { |
| 804 if (!compositor_) | 815 if (!compositor_) |
| 805 return; | 816 return; |
| 806 RunOnCommitCallbacks(); | 817 RunOnCommitCallbacks(); |
| 807 if (resize_lock_) { | 818 if (resize_lock_) { |
| 808 resize_lock_.reset(); | 819 resize_lock_.reset(); |
| 809 client_->DelegatedFrameHostResizeLockWasReleased(); | 820 client_->DelegatedFrameHostResizeLockWasReleased(); |
| 810 } | 821 } |
| 811 if (compositor_->HasObserver(this)) | 822 if (compositor_->HasObserver(this)) |
| 812 compositor_->RemoveObserver(this); | 823 compositor_->RemoveObserver(this); |
| 813 if (vsync_manager_.get()) { | 824 if (vsync_manager_.get()) { |
| 814 vsync_manager_->RemoveObserver(this); | 825 vsync_manager_->RemoveObserver(this); |
| 815 vsync_manager_ = NULL; | 826 vsync_manager_ = NULL; |
| 816 } | 827 } |
| 828 |
| 829 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
| 830 uint32_t parent = compositor_->surface_id_allocator()->id_namespace(); |
| 831 factory->GetSurfaceManager()->UnregisterSurfaceNamespaceHierarchy( |
| 832 parent, id_allocator_->id_namespace()); |
| 833 |
| 817 compositor_ = nullptr; | 834 compositor_ = nullptr; |
| 818 } | 835 } |
| 819 | 836 |
| 820 void DelegatedFrameHost::SetVSyncParameters(const base::TimeTicks& timebase, | 837 void DelegatedFrameHost::SetVSyncParameters(const base::TimeTicks& timebase, |
| 821 const base::TimeDelta& interval) { | 838 const base::TimeDelta& interval) { |
| 822 vsync_timebase_ = timebase; | 839 vsync_timebase_ = timebase; |
| 823 vsync_interval_ = interval; | 840 vsync_interval_ = interval; |
| 824 } | 841 } |
| 825 | 842 |
| 826 void DelegatedFrameHost::LockResources() { | 843 void DelegatedFrameHost::LockResources() { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 856 cc::SurfaceManager* manager = factory->GetSurfaceManager(); | 873 cc::SurfaceManager* manager = factory->GetSurfaceManager(); |
| 857 new_layer->SetShowSurface( | 874 new_layer->SetShowSurface( |
| 858 surface_id_, base::Bind(&SatisfyCallback, base::Unretained(manager)), | 875 surface_id_, base::Bind(&SatisfyCallback, base::Unretained(manager)), |
| 859 base::Bind(&RequireCallback, base::Unretained(manager)), | 876 base::Bind(&RequireCallback, base::Unretained(manager)), |
| 860 current_surface_size_, current_scale_factor_, | 877 current_surface_size_, current_scale_factor_, |
| 861 current_frame_size_in_dip_); | 878 current_frame_size_in_dip_); |
| 862 } | 879 } |
| 863 } | 880 } |
| 864 | 881 |
| 865 } // namespace content | 882 } // namespace content |
| OLD | NEW |