OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "blimp/client/core/compositor/blimp_compositor.h" | 5 #include "blimp/client/core/compositor/blimp_compositor.h" |
6 | 6 |
7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/numerics/safe_conversions.h" | 10 #include "base/numerics/safe_conversions.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 BlimpCompositorDependencies* compositor_dependencies, | 61 BlimpCompositorDependencies* compositor_dependencies, |
62 BlimpCompositorClient* client) | 62 BlimpCompositorClient* client) |
63 : render_widget_id_(render_widget_id), | 63 : render_widget_id_(render_widget_id), |
64 client_(client), | 64 client_(client), |
65 compositor_dependencies_(compositor_dependencies), | 65 compositor_dependencies_(compositor_dependencies), |
66 host_should_be_visible_(false), | 66 host_should_be_visible_(false), |
67 output_surface_(nullptr), | 67 output_surface_(nullptr), |
68 output_surface_request_pending_(false), | 68 output_surface_request_pending_(false), |
69 layer_(cc::Layer::Create()), | 69 layer_(cc::Layer::Create()), |
70 remote_proto_channel_receiver_(nullptr), | 70 remote_proto_channel_receiver_(nullptr), |
| 71 outstanding_commits_(0U), |
71 weak_ptr_factory_(this) { | 72 weak_ptr_factory_(this) { |
72 DCHECK(thread_checker_.CalledOnValidThread()); | 73 DCHECK(thread_checker_.CalledOnValidThread()); |
73 | 74 |
74 surface_id_allocator_ = base::MakeUnique<cc::SurfaceIdAllocator>( | 75 surface_id_allocator_ = base::MakeUnique<cc::SurfaceIdAllocator>( |
75 GetEmbedderDeps()->AllocateSurfaceClientId()); | 76 GetEmbedderDeps()->AllocateSurfaceClientId()); |
76 GetEmbedderDeps()->GetSurfaceManager()->RegisterSurfaceClientId( | 77 GetEmbedderDeps()->GetSurfaceManager()->RegisterSurfaceClientId( |
77 surface_id_allocator_->client_id()); | 78 surface_id_allocator_->client_id()); |
78 } | 79 } |
79 | 80 |
80 BlimpCompositor::~BlimpCompositor() { | 81 BlimpCompositor::~BlimpCompositor() { |
81 DCHECK(thread_checker_.CalledOnValidThread()); | 82 DCHECK(thread_checker_.CalledOnValidThread()); |
82 | 83 |
83 if (host_) | 84 if (host_) |
84 DestroyLayerTreeHost(); | 85 DestroyLayerTreeHost(); |
85 | 86 |
86 GetEmbedderDeps()->GetSurfaceManager()->InvalidateSurfaceClientId( | 87 GetEmbedderDeps()->GetSurfaceManager()->InvalidateSurfaceClientId( |
87 surface_id_allocator_->client_id()); | 88 surface_id_allocator_->client_id()); |
| 89 |
| 90 CheckPendingCommitCounts(true /* flush */); |
88 } | 91 } |
89 | 92 |
90 void BlimpCompositor::SetVisible(bool visible) { | 93 void BlimpCompositor::SetVisible(bool visible) { |
91 host_should_be_visible_ = visible; | 94 host_should_be_visible_ = visible; |
92 if (host_) | 95 if (host_) |
93 host_->SetVisible(host_should_be_visible_); | 96 host_->SetVisible(host_should_be_visible_); |
| 97 |
| 98 if (!visible) |
| 99 CheckPendingCommitCounts(true /* flush */); |
94 } | 100 } |
95 | 101 |
96 bool BlimpCompositor::OnTouchEvent(const ui::MotionEvent& motion_event) { | 102 bool BlimpCompositor::OnTouchEvent(const ui::MotionEvent& motion_event) { |
97 if (input_manager_) | 103 if (input_manager_) |
98 return input_manager_->OnTouchEvent(motion_event); | 104 return input_manager_->OnTouchEvent(motion_event); |
99 return false; | 105 return false; |
100 } | 106 } |
101 | 107 |
| 108 void BlimpCompositor::NotifyWhenDonePendingCommits(base::Closure callback) { |
| 109 if (outstanding_commits_ == 0 || !host_ || !host_should_be_visible_) { |
| 110 callback.Run(); |
| 111 return; |
| 112 } |
| 113 |
| 114 pending_commit_trackers_.push_back( |
| 115 std::make_pair(outstanding_commits_, callback)); |
| 116 } |
| 117 |
102 void BlimpCompositor::RequestNewOutputSurface() { | 118 void BlimpCompositor::RequestNewOutputSurface() { |
103 DCHECK(!surface_factory_); | 119 DCHECK(!surface_factory_); |
104 DCHECK(!output_surface_request_pending_); | 120 DCHECK(!output_surface_request_pending_); |
105 | 121 |
106 output_surface_request_pending_ = true; | 122 output_surface_request_pending_ = true; |
107 GetEmbedderDeps()->GetContextProviders( | 123 GetEmbedderDeps()->GetContextProviders( |
108 base::Bind(&BlimpCompositor::OnContextProvidersCreated, | 124 base::Bind(&BlimpCompositor::OnContextProvidersCreated, |
109 weak_ptr_factory_.GetWeakPtr())); | 125 weak_ptr_factory_.GetWeakPtr())); |
110 } | 126 } |
111 | 127 |
112 void BlimpCompositor::DidInitializeOutputSurface() { | 128 void BlimpCompositor::DidInitializeOutputSurface() { |
113 output_surface_request_pending_ = false; | 129 output_surface_request_pending_ = false; |
114 } | 130 } |
115 | 131 |
116 void BlimpCompositor::DidCommitAndDrawFrame() { | 132 void BlimpCompositor::DidCommitAndDrawFrame() { |
117 BlimpStats::GetInstance()->Add(BlimpStats::COMMIT, 1); | 133 BlimpStats::GetInstance()->Add(BlimpStats::COMMIT, 1); |
| 134 |
| 135 DCHECK_GT(outstanding_commits_, 0U); |
| 136 outstanding_commits_--; |
| 137 |
| 138 CheckPendingCommitCounts(false /* flush */); |
118 } | 139 } |
119 | 140 |
120 void BlimpCompositor::SetProtoReceiver(ProtoReceiver* receiver) { | 141 void BlimpCompositor::SetProtoReceiver(ProtoReceiver* receiver) { |
121 remote_proto_channel_receiver_ = receiver; | 142 remote_proto_channel_receiver_ = receiver; |
122 } | 143 } |
123 | 144 |
124 void BlimpCompositor::SendCompositorProto( | 145 void BlimpCompositor::SendCompositorProto( |
125 const cc::proto::CompositorMessage& proto) { | 146 const cc::proto::CompositorMessage& proto) { |
126 client_->SendCompositorMessage(render_widget_id_, proto); | 147 client_->SendCompositorMessage(render_widget_id_, proto); |
127 } | 148 } |
128 | 149 |
129 void BlimpCompositor::OnCompositorMessageReceived( | 150 void BlimpCompositor::OnCompositorMessageReceived( |
130 std::unique_ptr<cc::proto::CompositorMessage> message) { | 151 std::unique_ptr<cc::proto::CompositorMessage> message) { |
131 DCHECK(message->has_to_impl()); | 152 DCHECK(message->has_to_impl()); |
132 const cc::proto::CompositorMessageToImpl& to_impl_proto = message->to_impl(); | 153 const cc::proto::CompositorMessageToImpl& to_impl_proto = message->to_impl(); |
133 | 154 |
134 DCHECK(to_impl_proto.has_message_type()); | 155 DCHECK(to_impl_proto.has_message_type()); |
| 156 |
| 157 if (to_impl_proto.message_type() == |
| 158 cc::proto::CompositorMessageToImpl::START_COMMIT) { |
| 159 outstanding_commits_++; |
| 160 } |
| 161 |
135 switch (to_impl_proto.message_type()) { | 162 switch (to_impl_proto.message_type()) { |
136 case cc::proto::CompositorMessageToImpl::UNKNOWN: | 163 case cc::proto::CompositorMessageToImpl::UNKNOWN: |
137 NOTIMPLEMENTED() << "Ignoring message of UNKNOWN type"; | 164 NOTIMPLEMENTED() << "Ignoring message of UNKNOWN type"; |
138 break; | 165 break; |
139 case cc::proto::CompositorMessageToImpl::INITIALIZE_IMPL: | 166 case cc::proto::CompositorMessageToImpl::INITIALIZE_IMPL: |
140 DCHECK(!host_); | 167 DCHECK(!host_); |
141 DCHECK(to_impl_proto.has_initialize_impl_message()); | 168 DCHECK(to_impl_proto.has_initialize_impl_message()); |
142 | 169 |
143 // Create the remote client LayerTreeHost for the compositor. | 170 // Create the remote client LayerTreeHost for the compositor. |
144 CreateLayerTreeHost(to_impl_proto.initialize_impl_message()); | 171 CreateLayerTreeHost(to_impl_proto.initialize_impl_message()); |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 input_manager_.reset(); | 349 input_manager_.reset(); |
323 | 350 |
324 // Cancel any outstanding OutputSurface requests. That way if we get an async | 351 // Cancel any outstanding OutputSurface requests. That way if we get an async |
325 // callback related to the old request we know to drop it. | 352 // callback related to the old request we know to drop it. |
326 output_surface_request_pending_ = false; | 353 output_surface_request_pending_ = false; |
327 | 354 |
328 // Make sure we don't have a receiver at this point. | 355 // Make sure we don't have a receiver at this point. |
329 DCHECK(!remote_proto_channel_receiver_); | 356 DCHECK(!remote_proto_channel_receiver_); |
330 } | 357 } |
331 | 358 |
| 359 void BlimpCompositor::CheckPendingCommitCounts(bool flush) { |
| 360 for (auto it = pending_commit_trackers_.begin(); |
| 361 it != pending_commit_trackers_.end();) { |
| 362 if (flush || --it->first == 0) { |
| 363 it->second.Run(); |
| 364 it = pending_commit_trackers_.erase(it); |
| 365 } else { |
| 366 ++it; |
| 367 } |
| 368 } |
| 369 } |
| 370 |
332 } // namespace client | 371 } // namespace client |
333 } // namespace blimp | 372 } // namespace blimp |
OLD | NEW |