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 "base/time/default_tick_clock.h" | 9 #include "base/time/default_tick_clock.h" |
10 #include "cc/output/compositor_frame.h" | 10 #include "cc/output/compositor_frame.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 | 54 |
55 } // namespace | 55 } // namespace |
56 | 56 |
57 //////////////////////////////////////////////////////////////////////////////// | 57 //////////////////////////////////////////////////////////////////////////////// |
58 // DelegatedFrameHost | 58 // DelegatedFrameHost |
59 | 59 |
60 DelegatedFrameHost::DelegatedFrameHost(DelegatedFrameHostClient* client) | 60 DelegatedFrameHost::DelegatedFrameHost(DelegatedFrameHostClient* client) |
61 : client_(client), | 61 : client_(client), |
62 compositor_(nullptr), | 62 compositor_(nullptr), |
63 use_surfaces_(UseSurfacesEnabled()), | 63 use_surfaces_(UseSurfacesEnabled()), |
| 64 current_begin_frame_source_(nullptr), |
64 tick_clock_(new base::DefaultTickClock()), | 65 tick_clock_(new base::DefaultTickClock()), |
65 last_output_surface_id_(0), | 66 last_output_surface_id_(0), |
66 pending_delegated_ack_count_(0), | 67 pending_delegated_ack_count_(0), |
67 skipped_frames_(false), | 68 skipped_frames_(false), |
68 current_scale_factor_(1.f), | 69 current_scale_factor_(1.f), |
69 can_lock_compositor_(YES_CAN_LOCK), | 70 can_lock_compositor_(YES_CAN_LOCK), |
70 delegated_frame_evictor_(new DelegatedFrameEvictor(this)) { | 71 delegated_frame_evictor_(new DelegatedFrameEvictor(this)) { |
| 72 SetCurrentBeginFrameSource(nullptr); |
71 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 73 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
72 factory->AddObserver(this); | 74 factory->AddObserver(this); |
73 id_allocator_ = factory->GetContextFactory()->CreateSurfaceIdAllocator(); | 75 id_allocator_ = factory->GetContextFactory()->CreateSurfaceIdAllocator(); |
74 } | 76 } |
75 | 77 |
| 78 void DelegatedFrameHost::SetCurrentBeginFrameSource(BeginFrameSource* new_bfs) { |
| 79 if (!new_bfs) { |
| 80 // FIXME(mithro): Add a OrphanedBeginFrameSource |
| 81 // FIXME(mithro): We can probably figure out a better BeginFrameSource to us
e here using what the DelegatedFrameHost. |
| 82 new_bfs = OrphanedBeginFrameSource::getSource(); |
| 83 } |
| 84 |
| 85 // FIXME(mithro): This will need some of the BeginFrameSourceMultiplexer stuff
.... |
| 86 if (new_bfs != current_begin_frame_source_) { |
| 87 if (current_begin_frame_source_) |
| 88 current_begin_frame_source_->RemoveObserver(this); |
| 89 current_begin_frame_source_ = new_bfs; |
| 90 current_begin_frame_source_->AddObserver(this); |
| 91 } |
| 92 } |
| 93 |
76 void DelegatedFrameHost::WasShown(const ui::LatencyInfo& latency_info) { | 94 void DelegatedFrameHost::WasShown(const ui::LatencyInfo& latency_info) { |
77 delegated_frame_evictor_->SetVisible(true); | 95 delegated_frame_evictor_->SetVisible(true); |
78 | 96 |
79 if (surface_id_.is_null() && !frame_provider_.get() && | 97 if (surface_id_.is_null() && !frame_provider_.get() && |
80 !released_front_lock_.get()) { | 98 !released_front_lock_.get()) { |
81 if (compositor_) | 99 if (compositor_) |
82 released_front_lock_ = compositor_->GetCompositorLock(); | 100 released_front_lock_ = compositor_->GetCompositorLock(); |
83 } | 101 } |
84 | 102 |
85 if (compositor_) { | 103 if (compositor_) { |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 } else { | 491 } else { |
474 AddOnCommitCallbackAndDisableLocks(base::Closure()); | 492 AddOnCommitCallbackAndDisableLocks(base::Closure()); |
475 } | 493 } |
476 DidReceiveFrameFromRenderer(damage_rect); | 494 DidReceiveFrameFromRenderer(damage_rect); |
477 if (frame_provider_.get() || !surface_id_.is_null()) | 495 if (frame_provider_.get() || !surface_id_.is_null()) |
478 delegated_frame_evictor_->SwappedFrame( | 496 delegated_frame_evictor_->SwappedFrame( |
479 client_->DelegatedFrameHostIsVisible()); | 497 client_->DelegatedFrameHostIsVisible()); |
480 // Note: the frame may have been evicted immediately. | 498 // Note: the frame may have been evicted immediately. |
481 } | 499 } |
482 | 500 |
| 501 void DelegatedFrameHost::SetBeginFrameSource(SurfaceId id, BeginFrameSource* new
_bfs) { |
| 502 if (id != surface_id_) return; |
| 503 SetCurrentBeginFrameSource(new_bfs); |
| 504 } |
| 505 |
483 void DelegatedFrameHost::SendDelegatedFrameAck(uint32 output_surface_id) { | 506 void DelegatedFrameHost::SendDelegatedFrameAck(uint32 output_surface_id) { |
484 cc::CompositorFrameAck ack; | 507 cc::CompositorFrameAck ack; |
485 if (!surface_returned_resources_.empty()) | 508 if (!surface_returned_resources_.empty()) |
486 ack.resources.swap(surface_returned_resources_); | 509 ack.resources.swap(surface_returned_resources_); |
487 if (resource_collection_.get()) | 510 if (resource_collection_.get()) |
488 resource_collection_->TakeUnusedResourcesForChildCompositor(&ack.resources); | 511 resource_collection_->TakeUnusedResourcesForChildCompositor(&ack.resources); |
489 client_->DelegatedFrameHostSendCompositorSwapAck(output_surface_id, ack); | 512 client_->DelegatedFrameHostSendCompositorSwapAck(output_surface_id, ack); |
490 DCHECK_GT(pending_delegated_ack_count_, 0); | 513 DCHECK_GT(pending_delegated_ack_count_, 0); |
491 pending_delegated_ack_count_--; | 514 pending_delegated_ack_count_--; |
492 } | 515 } |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
934 | 957 |
935 DelegatedFrameHost::~DelegatedFrameHost() { | 958 DelegatedFrameHost::~DelegatedFrameHost() { |
936 DCHECK(!compositor_); | 959 DCHECK(!compositor_); |
937 ImageTransportFactory::GetInstance()->RemoveObserver(this); | 960 ImageTransportFactory::GetInstance()->RemoveObserver(this); |
938 | 961 |
939 if (!surface_id_.is_null()) | 962 if (!surface_id_.is_null()) |
940 surface_factory_->Destroy(surface_id_); | 963 surface_factory_->Destroy(surface_id_); |
941 if (resource_collection_.get()) | 964 if (resource_collection_.get()) |
942 resource_collection_->SetClient(NULL); | 965 resource_collection_->SetClient(NULL); |
943 | 966 |
| 967 DCHECK_EQ(current_begin_frame_source_, OrphanBeginFrameSource::getSource()); |
| 968 current_begin_frame_source_->RemoveObserver(this); |
| 969 current_begin_frame_source_ = NULL; |
| 970 |
944 DCHECK(!vsync_manager_.get()); | 971 DCHECK(!vsync_manager_.get()); |
945 } | 972 } |
946 | 973 |
947 void DelegatedFrameHost::RunOnCommitCallbacks() { | 974 void DelegatedFrameHost::RunOnCommitCallbacks() { |
948 for (std::vector<base::Closure>::const_iterator | 975 for (std::vector<base::Closure>::const_iterator |
949 it = on_compositing_did_commit_callbacks_.begin(); | 976 it = on_compositing_did_commit_callbacks_.begin(); |
950 it != on_compositing_did_commit_callbacks_.end(); ++it) { | 977 it != on_compositing_did_commit_callbacks_.end(); ++it) { |
951 it->Run(); | 978 it->Run(); |
952 } | 979 } |
953 on_compositing_did_commit_callbacks_.clear(); | 980 on_compositing_did_commit_callbacks_.clear(); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1031 cc::SurfaceManager* manager = factory->GetSurfaceManager(); | 1058 cc::SurfaceManager* manager = factory->GetSurfaceManager(); |
1032 new_layer->SetShowSurface( | 1059 new_layer->SetShowSurface( |
1033 surface_id_, base::Bind(&SatisfyCallback, base::Unretained(manager)), | 1060 surface_id_, base::Bind(&SatisfyCallback, base::Unretained(manager)), |
1034 base::Bind(&RequireCallback, base::Unretained(manager)), | 1061 base::Bind(&RequireCallback, base::Unretained(manager)), |
1035 current_surface_size_, current_scale_factor_, | 1062 current_surface_size_, current_scale_factor_, |
1036 current_frame_size_in_dip_); | 1063 current_frame_size_in_dip_); |
1037 } | 1064 } |
1038 } | 1065 } |
1039 | 1066 |
1040 } // namespace content | 1067 } // namespace content |
OLD | NEW |