Chromium Code Reviews| 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/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 surface_id_allocator_ = base::MakeUnique<cc::SurfaceIdAllocator>(); | 80 surface_id_allocator_ = base::MakeUnique<cc::SurfaceIdAllocator>(); |
| 81 GetEmbedderDeps()->GetSurfaceManager()->RegisterFrameSinkId(frame_sink_id_); | 81 GetEmbedderDeps()->GetSurfaceManager()->RegisterFrameSinkId(frame_sink_id_); |
| 82 CreateLayerTreeHost(); | 82 CreateLayerTreeHost(); |
| 83 | 83 |
| 84 if (use_threaded_layer_tree_host_) { | 84 if (use_threaded_layer_tree_host_) { |
| 85 std::unique_ptr<cc::ClientPictureCache> client_picture_cache = | 85 std::unique_ptr<cc::ClientPictureCache> client_picture_cache = |
| 86 compositor_dependencies_->GetImageSerializationProcessor() | 86 compositor_dependencies_->GetImageSerializationProcessor() |
| 87 ->CreateClientPictureCache(); | 87 ->CreateClientPictureCache(); |
| 88 compositor_state_deserializer_ = | 88 compositor_state_deserializer_ = |
| 89 base::MakeUnique<cc::CompositorStateDeserializer>( | 89 base::MakeUnique<cc::CompositorStateDeserializer>( |
| 90 host_.get(), std::move(client_picture_cache), | 90 host_.get(), std::move(client_picture_cache), this); |
| 91 base::Bind(&BlimpCompositor::LayerScrolled, | |
| 92 weak_ptr_factory_.GetWeakPtr()), | |
| 93 this); | |
| 94 } | 91 } |
| 95 } | 92 } |
| 96 | 93 |
| 97 BlimpCompositor::~BlimpCompositor() { | 94 BlimpCompositor::~BlimpCompositor() { |
| 98 DCHECK(thread_checker_.CalledOnValidThread()); | 95 DCHECK(thread_checker_.CalledOnValidThread()); |
| 99 | 96 |
| 100 DestroyLayerTreeHost(); | 97 DestroyLayerTreeHost(); |
| 101 GetEmbedderDeps()->GetSurfaceManager()->InvalidateFrameSinkId(frame_sink_id_); | 98 GetEmbedderDeps()->GetSurfaceManager()->InvalidateFrameSinkId(frame_sink_id_); |
| 102 | 99 |
| 103 CheckPendingCommitCounts(true /* flush */); | 100 CheckPendingCommitCounts(true /* flush */); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 114 if (outstanding_commits_ == 0) { | 111 if (outstanding_commits_ == 0) { |
| 115 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); | 112 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); |
| 116 return; | 113 return; |
| 117 } | 114 } |
| 118 | 115 |
| 119 pending_commit_trackers_.push_back( | 116 pending_commit_trackers_.push_back( |
| 120 std::make_pair(outstanding_commits_, callback)); | 117 std::make_pair(outstanding_commits_, callback)); |
| 121 } | 118 } |
| 122 | 119 |
| 123 void BlimpCompositor::UpdateLayerTreeHost() { | 120 void BlimpCompositor::UpdateLayerTreeHost() { |
| 121 DCHECK(use_threaded_layer_tree_host_); | |
| 122 | |
| 123 // UpdateLayerTreeHost marks the end of reporting of any deltas from the impl | |
| 124 // thread. So send a client state update if the local state was modified now. | |
| 125 FlushClientState(); | |
| 126 | |
| 124 if (pending_frame_update_) { | 127 if (pending_frame_update_) { |
| 125 DCHECK(use_threaded_layer_tree_host_); | 128 DCHECK(use_threaded_layer_tree_host_); |
| 126 compositor_state_deserializer_->DeserializeCompositorUpdate( | 129 compositor_state_deserializer_->DeserializeCompositorUpdate( |
| 127 pending_frame_update_->layer_tree_host()); | 130 pending_frame_update_->layer_tree_host()); |
| 128 pending_frame_update_ = nullptr; | 131 pending_frame_update_ = nullptr; |
| 129 cc::proto::CompositorMessage frame_ack; | 132 cc::proto::CompositorMessage frame_ack; |
| 130 frame_ack.set_frame_ack(true); | 133 frame_ack.set_frame_ack(true); |
| 131 client_->SendCompositorMessage(frame_ack); | 134 client_->SendCompositorMessage(frame_ack); |
| 132 } | 135 } |
| 136 | |
| 137 // Send back any deltas that have not yet been resolved on the main thread | |
| 138 // back to the impl thread. | |
| 139 compositor_state_deserializer_->SendUnappliedDeltasToLayerTreeHost(); | |
| 140 } | |
| 141 | |
| 142 void BlimpCompositor::ApplyViewportDeltas( | |
| 143 const gfx::Vector2dF& inner_delta, | |
| 144 const gfx::Vector2dF& outer_delta, | |
| 145 const gfx::Vector2dF& elastic_overscroll_delta, | |
| 146 float page_scale, | |
| 147 float top_controls_delta) { | |
| 148 DCHECK(use_threaded_layer_tree_host_); | |
| 149 compositor_state_deserializer_->ApplyViewportDeltas( | |
| 150 inner_delta, outer_delta, elastic_overscroll_delta, page_scale, | |
| 151 top_controls_delta); | |
| 133 } | 152 } |
| 134 | 153 |
| 135 void BlimpCompositor::RequestNewCompositorFrameSink() { | 154 void BlimpCompositor::RequestNewCompositorFrameSink() { |
| 136 DCHECK(!surface_factory_); | 155 DCHECK(!surface_factory_); |
| 137 DCHECK(!compositor_frame_sink_request_pending_); | 156 DCHECK(!compositor_frame_sink_request_pending_); |
| 138 | 157 |
| 139 compositor_frame_sink_request_pending_ = true; | 158 compositor_frame_sink_request_pending_ = true; |
| 140 GetEmbedderDeps()->GetContextProviders( | 159 GetEmbedderDeps()->GetContextProviders( |
| 141 base::Bind(&BlimpCompositor::OnContextProvidersCreated, | 160 base::Bind(&BlimpCompositor::OnContextProvidersCreated, |
| 142 weak_ptr_factory_.GetWeakPtr())); | 161 weak_ptr_factory_.GetWeakPtr())); |
| 143 } | 162 } |
| 144 | 163 |
| 145 void BlimpCompositor::DidInitializeCompositorFrameSink() { | 164 void BlimpCompositor::DidInitializeCompositorFrameSink() { |
| 146 compositor_frame_sink_request_pending_ = false; | 165 compositor_frame_sink_request_pending_ = false; |
| 147 } | 166 } |
| 148 | 167 |
| 149 void BlimpCompositor::DidCommitAndDrawFrame() { | 168 void BlimpCompositor::DidCommitAndDrawFrame() { |
| 150 BlimpStats::GetInstance()->Add(BlimpStats::COMMIT, 1); | 169 BlimpStats::GetInstance()->Add(BlimpStats::COMMIT, 1); |
| 151 | 170 |
| 171 // TODO(khushalsagar): Fix before landing, the code here assumes that every | |
|
aelias_OOO_until_Jul13
2016/10/28 03:40:19
Could you also upload this fix for code review sin
Khushal
2016/10/28 04:11:17
Actually the problem is interesting here. If we wa
Khushal
2016/10/28 07:43:56
I have uploaded a patch for fixing this separately
| |
| 172 // commit came from the engine. :X. | |
| 173 return; | |
| 174 | |
| 152 DCHECK_GT(outstanding_commits_, 0U); | 175 DCHECK_GT(outstanding_commits_, 0U); |
| 153 outstanding_commits_--; | 176 outstanding_commits_--; |
| 154 | 177 |
| 155 CheckPendingCommitCounts(false /* flush */); | 178 CheckPendingCommitCounts(false /* flush */); |
| 156 } | 179 } |
| 157 | 180 |
| 158 void BlimpCompositor::SetProtoReceiver(ProtoReceiver* receiver) { | 181 void BlimpCompositor::SetProtoReceiver(ProtoReceiver* receiver) { |
| 159 DCHECK(!use_threaded_layer_tree_host_); | 182 DCHECK(!use_threaded_layer_tree_host_); |
| 160 remote_proto_channel_receiver_ = receiver; | 183 remote_proto_channel_receiver_ = receiver; |
| 161 } | 184 } |
| 162 | 185 |
| 163 void BlimpCompositor::SendCompositorProto( | 186 void BlimpCompositor::SendCompositorProto( |
| 164 const cc::proto::CompositorMessage& proto) { | 187 const cc::proto::CompositorMessage& proto) { |
| 165 DCHECK(!use_threaded_layer_tree_host_); | 188 DCHECK(!use_threaded_layer_tree_host_); |
| 166 client_->SendCompositorMessage(proto); | 189 client_->SendCompositorMessage(proto); |
| 167 } | 190 } |
| 168 | 191 |
| 169 void BlimpCompositor::OnCompositorMessageReceived( | 192 void BlimpCompositor::OnCompositorMessageReceived( |
| 170 std::unique_ptr<cc::proto::CompositorMessage> message) { | 193 std::unique_ptr<cc::proto::CompositorMessage> message) { |
| 171 if (message->has_to_impl()) { | 194 if (message->has_to_impl()) { |
| 172 HandleCompositorMessageToImpl(std::move(message)); | 195 HandleCompositorMessageToImpl(std::move(message)); |
| 173 return; | 196 return; |
| 174 } | 197 } |
| 175 | 198 |
| 176 DCHECK(use_threaded_layer_tree_host_); | 199 DCHECK(use_threaded_layer_tree_host_); |
| 177 DCHECK(message->has_layer_tree_host()) | 200 cc::proto::CompositorMessage* message_received = message.get(); |
| 178 << "The engine only sends frame updates"; | |
| 179 DCHECK(!pending_frame_update_) | |
| 180 << "We should have only a single frame in flight"; | |
| 181 | 201 |
| 182 UMA_HISTOGRAM_MEMORY_KB("Blimp.Compositor.CommitSizeKb", | 202 if (message_received->has_layer_tree_host()) { |
| 183 (float)message->ByteSize() / 1024); | 203 DCHECK(!pending_frame_update_) |
| 184 pending_frame_update_ = std::move(message); | 204 << "We should have only a single frame in flight"; |
| 185 outstanding_commits_++; | 205 |
| 186 host_->SetNeedsAnimate(); | 206 UMA_HISTOGRAM_MEMORY_KB("Blimp.Compositor.CommitSizeKb", |
| 207 (float)message->ByteSize() / 1024); | |
| 208 pending_frame_update_ = std::move(message); | |
| 209 outstanding_commits_++; | |
| 210 host_->SetNeedsAnimate(); | |
| 211 } | |
| 212 | |
| 213 if (message_received->client_state_update_ack()) { | |
| 214 DCHECK(client_state_update_ack_pending_); | |
| 215 | |
| 216 client_state_update_ack_pending_ = false; | |
| 217 compositor_state_deserializer_->DidApplyStateUpdatesOnEngine(); | |
| 218 | |
| 219 // If there are any updates that we have queued because we were waiting for | |
| 220 // an ack, send them now. | |
| 221 FlushClientState(); | |
| 222 } | |
| 187 } | 223 } |
| 188 | 224 |
| 189 void BlimpCompositor::HandleCompositorMessageToImpl( | 225 void BlimpCompositor::HandleCompositorMessageToImpl( |
| 190 std::unique_ptr<cc::proto::CompositorMessage> message) { | 226 std::unique_ptr<cc::proto::CompositorMessage> message) { |
| 191 DCHECK(!use_threaded_layer_tree_host_); | 227 DCHECK(!use_threaded_layer_tree_host_); |
| 192 DCHECK(message->has_to_impl()); | 228 DCHECK(message->has_to_impl()); |
| 193 | 229 |
| 194 const cc::proto::CompositorMessageToImpl to_impl_proto = message->to_impl(); | 230 const cc::proto::CompositorMessageToImpl to_impl_proto = message->to_impl(); |
| 195 DCHECK(to_impl_proto.has_message_type()); | 231 DCHECK(to_impl_proto.has_message_type()); |
| 196 | 232 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 315 void BlimpCompositor::ReturnResources( | 351 void BlimpCompositor::ReturnResources( |
| 316 const cc::ReturnedResourceArray& resources) { | 352 const cc::ReturnedResourceArray& resources) { |
| 317 DCHECK(surface_factory_); | 353 DCHECK(surface_factory_); |
| 318 compositor_dependencies_->GetCompositorTaskRunner()->PostTask( | 354 compositor_dependencies_->GetCompositorTaskRunner()->PostTask( |
| 319 FROM_HERE, | 355 FROM_HERE, |
| 320 base::Bind( | 356 base::Bind( |
| 321 &BlimpCompositorFrameSinkProxyClient::ReclaimCompositorResources, | 357 &BlimpCompositorFrameSinkProxyClient::ReclaimCompositorResources, |
| 322 proxy_client_, resources)); | 358 proxy_client_, resources)); |
| 323 } | 359 } |
| 324 | 360 |
| 325 bool BlimpCompositor::ShouldRetainClientScroll( | 361 void BlimpCompositor::DidUpdateLocalState() { |
| 326 int engine_layer_id, | 362 client_state_dirty_ = true; |
| 327 const gfx::ScrollOffset& new_offset) { | |
| 328 // TODO(khushalsagar): Update when adding scroll/scale sync. See | |
| 329 // crbug.com/648442. | |
| 330 return true; | |
| 331 } | 363 } |
| 332 | 364 |
| 333 bool BlimpCompositor::ShouldRetainClientPageScale(float new_page_scale) { | 365 void BlimpCompositor::FlushClientState() { |
| 334 // TODO(khushalsagar): Update when adding scroll/scale sync. See | 366 // If the client state has not been modified, we don't need to send an update. |
| 335 // crbug.com/648442. | 367 if (!client_state_dirty_) |
| 336 return true; | 368 return; |
| 337 } | |
| 338 | 369 |
| 339 void BlimpCompositor::LayerScrolled(int engine_layer_id) { | 370 // If we had sent an update and an ack for it is still pending, we can't send |
| 340 DCHECK(use_threaded_layer_tree_host_); | 371 // another update till the ack is received. |
| 372 if (client_state_update_ack_pending_) | |
| 373 return; | |
| 374 | |
| 375 cc::proto::CompositorMessage message; | |
| 376 message.set_frame_ack(false); | |
| 377 compositor_state_deserializer_->PullClientStateUpdate( | |
| 378 message.mutable_client_state_update()); | |
| 379 | |
| 380 client_state_dirty_ = false; | |
| 381 client_state_update_ack_pending_ = true; | |
| 382 client_->SendCompositorMessage(message); | |
| 341 } | 383 } |
| 342 | 384 |
| 343 CompositorDependencies* BlimpCompositor::GetEmbedderDeps() { | 385 CompositorDependencies* BlimpCompositor::GetEmbedderDeps() { |
| 344 return compositor_dependencies_->GetEmbedderDependencies(); | 386 return compositor_dependencies_->GetEmbedderDependencies(); |
| 345 } | 387 } |
| 346 | 388 |
| 347 void BlimpCompositor::DestroyDelegatedContent() { | 389 void BlimpCompositor::DestroyDelegatedContent() { |
| 348 if (local_frame_id_.is_null()) | 390 if (local_frame_id_.is_null()) |
| 349 return; | 391 return; |
| 350 | 392 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 416 it->second.Run(); | 458 it->second.Run(); |
| 417 it = pending_commit_trackers_.erase(it); | 459 it = pending_commit_trackers_.erase(it); |
| 418 } else { | 460 } else { |
| 419 ++it; | 461 ++it; |
| 420 } | 462 } |
| 421 } | 463 } |
| 422 } | 464 } |
| 423 | 465 |
| 424 } // namespace client | 466 } // namespace client |
| 425 } // namespace blimp | 467 } // namespace blimp |
| OLD | NEW |