| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 int render_widget_id, | 61 int render_widget_id, |
| 62 BlimpCompositorDependencies* compositor_dependencies, | 62 BlimpCompositorDependencies* compositor_dependencies, |
| 63 BlimpCompositorClient* client) | 63 BlimpCompositorClient* client) |
| 64 : render_widget_id_(render_widget_id), | 64 : render_widget_id_(render_widget_id), |
| 65 client_(client), | 65 client_(client), |
| 66 compositor_dependencies_(compositor_dependencies), | 66 compositor_dependencies_(compositor_dependencies), |
| 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 CreateLayerTreeHost(); | 79 CreateLayerTreeHost(); |
| 79 } | 80 } |
| 80 | 81 |
| 81 BlimpCompositor::~BlimpCompositor() { | 82 BlimpCompositor::~BlimpCompositor() { |
| 82 DCHECK(thread_checker_.CalledOnValidThread()); | 83 DCHECK(thread_checker_.CalledOnValidThread()); |
| 83 | 84 |
| 84 DestroyLayerTreeHost(); | 85 DestroyLayerTreeHost(); |
| 85 GetEmbedderDeps()->GetSurfaceManager()->InvalidateSurfaceClientId( | 86 GetEmbedderDeps()->GetSurfaceManager()->InvalidateSurfaceClientId( |
| 86 surface_id_allocator_->client_id()); | 87 surface_id_allocator_->client_id()); |
| 88 |
| 89 CheckPendingCommitCounts(true /* flush */); |
| 87 } | 90 } |
| 88 | 91 |
| 89 void BlimpCompositor::SetVisible(bool visible) { | 92 void BlimpCompositor::SetVisible(bool visible) { |
| 90 host_->SetVisible(visible); | 93 host_->SetVisible(visible); |
| 94 |
| 95 if (!visible) |
| 96 CheckPendingCommitCounts(true /* flush */); |
| 91 } | 97 } |
| 92 | 98 |
| 93 bool BlimpCompositor::OnTouchEvent(const ui::MotionEvent& motion_event) { | 99 bool BlimpCompositor::OnTouchEvent(const ui::MotionEvent& motion_event) { |
| 94 if (input_manager_) | 100 if (input_manager_) |
| 95 return input_manager_->OnTouchEvent(motion_event); | 101 return input_manager_->OnTouchEvent(motion_event); |
| 96 return false; | 102 return false; |
| 97 } | 103 } |
| 98 | 104 |
| 105 void BlimpCompositor::NotifyWhenDonePendingCommits(base::Closure callback) { |
| 106 if (outstanding_commits_ == 0) { |
| 107 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); |
| 108 return; |
| 109 } |
| 110 |
| 111 pending_commit_trackers_.push_back( |
| 112 std::make_pair(outstanding_commits_, callback)); |
| 113 } |
| 114 |
| 99 void BlimpCompositor::RequestNewOutputSurface() { | 115 void BlimpCompositor::RequestNewOutputSurface() { |
| 100 DCHECK(!surface_factory_); | 116 DCHECK(!surface_factory_); |
| 101 DCHECK(!output_surface_request_pending_); | 117 DCHECK(!output_surface_request_pending_); |
| 102 | 118 |
| 103 output_surface_request_pending_ = true; | 119 output_surface_request_pending_ = true; |
| 104 GetEmbedderDeps()->GetContextProviders( | 120 GetEmbedderDeps()->GetContextProviders( |
| 105 base::Bind(&BlimpCompositor::OnContextProvidersCreated, | 121 base::Bind(&BlimpCompositor::OnContextProvidersCreated, |
| 106 weak_ptr_factory_.GetWeakPtr())); | 122 weak_ptr_factory_.GetWeakPtr())); |
| 107 } | 123 } |
| 108 | 124 |
| 109 void BlimpCompositor::DidInitializeOutputSurface() { | 125 void BlimpCompositor::DidInitializeOutputSurface() { |
| 110 output_surface_request_pending_ = false; | 126 output_surface_request_pending_ = false; |
| 111 } | 127 } |
| 112 | 128 |
| 113 void BlimpCompositor::DidCommitAndDrawFrame() { | 129 void BlimpCompositor::DidCommitAndDrawFrame() { |
| 114 BlimpStats::GetInstance()->Add(BlimpStats::COMMIT, 1); | 130 BlimpStats::GetInstance()->Add(BlimpStats::COMMIT, 1); |
| 131 |
| 132 DCHECK_GT(outstanding_commits_, 0U); |
| 133 outstanding_commits_--; |
| 134 |
| 135 CheckPendingCommitCounts(false /* flush */); |
| 115 } | 136 } |
| 116 | 137 |
| 117 void BlimpCompositor::SetProtoReceiver(ProtoReceiver* receiver) { | 138 void BlimpCompositor::SetProtoReceiver(ProtoReceiver* receiver) { |
| 118 remote_proto_channel_receiver_ = receiver; | 139 remote_proto_channel_receiver_ = receiver; |
| 119 } | 140 } |
| 120 | 141 |
| 121 void BlimpCompositor::SendCompositorProto( | 142 void BlimpCompositor::SendCompositorProto( |
| 122 const cc::proto::CompositorMessage& proto) { | 143 const cc::proto::CompositorMessage& proto) { |
| 123 client_->SendCompositorMessage(render_widget_id_, proto); | 144 client_->SendCompositorMessage(render_widget_id_, proto); |
| 124 } | 145 } |
| 125 | 146 |
| 126 void BlimpCompositor::OnCompositorMessageReceived( | 147 void BlimpCompositor::OnCompositorMessageReceived( |
| 127 std::unique_ptr<cc::proto::CompositorMessage> message) { | 148 std::unique_ptr<cc::proto::CompositorMessage> message) { |
| 128 DCHECK(message->has_to_impl()); | 149 DCHECK(message->has_to_impl()); |
| 129 const cc::proto::CompositorMessageToImpl& to_impl_proto = message->to_impl(); | 150 const cc::proto::CompositorMessageToImpl& to_impl_proto = message->to_impl(); |
| 130 | 151 |
| 131 DCHECK(to_impl_proto.has_message_type()); | 152 DCHECK(to_impl_proto.has_message_type()); |
| 153 |
| 154 if (to_impl_proto.message_type() == |
| 155 cc::proto::CompositorMessageToImpl::START_COMMIT) { |
| 156 outstanding_commits_++; |
| 157 } |
| 158 |
| 132 switch (to_impl_proto.message_type()) { | 159 switch (to_impl_proto.message_type()) { |
| 133 case cc::proto::CompositorMessageToImpl::UNKNOWN: | 160 case cc::proto::CompositorMessageToImpl::UNKNOWN: |
| 134 NOTIMPLEMENTED() << "Ignoring message of UNKNOWN type"; | 161 NOTIMPLEMENTED() << "Ignoring message of UNKNOWN type"; |
| 135 break; | 162 break; |
| 136 case cc::proto::CompositorMessageToImpl::START_COMMIT: | 163 case cc::proto::CompositorMessageToImpl::START_COMMIT: |
| 137 UMA_HISTOGRAM_MEMORY_KB("Blimp.Compositor.CommitSizeKb", | 164 UMA_HISTOGRAM_MEMORY_KB("Blimp.Compositor.CommitSizeKb", |
| 138 (float)message->ByteSize() / 1024); | 165 (float)message->ByteSize() / 1024); |
| 139 default: | 166 default: |
| 140 // We should have a receiver if we're getting compositor messages that | 167 // We should have a receiver if we're getting compositor messages that |
| 141 // are not INITIALIZE_IMPL or CLOSE_IMPL. | 168 // are not INITIALIZE_IMPL or CLOSE_IMPL. |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 input_manager_.reset(); | 334 input_manager_.reset(); |
| 308 | 335 |
| 309 // Cancel any outstanding OutputSurface requests. That way if we get an async | 336 // Cancel any outstanding OutputSurface requests. That way if we get an async |
| 310 // callback related to the old request we know to drop it. | 337 // callback related to the old request we know to drop it. |
| 311 output_surface_request_pending_ = false; | 338 output_surface_request_pending_ = false; |
| 312 | 339 |
| 313 // Make sure we don't have a receiver at this point. | 340 // Make sure we don't have a receiver at this point. |
| 314 DCHECK(!remote_proto_channel_receiver_); | 341 DCHECK(!remote_proto_channel_receiver_); |
| 315 } | 342 } |
| 316 | 343 |
| 344 void BlimpCompositor::CheckPendingCommitCounts(bool flush) { |
| 345 for (auto it = pending_commit_trackers_.begin(); |
| 346 it != pending_commit_trackers_.end();) { |
| 347 if (flush || --it->first == 0) { |
| 348 it->second.Run(); |
| 349 it = pending_commit_trackers_.erase(it); |
| 350 } else { |
| 351 ++it; |
| 352 } |
| 353 } |
| 354 } |
| 355 |
| 317 } // namespace client | 356 } // namespace client |
| 318 } // namespace blimp | 357 } // namespace blimp |
| OLD | NEW |