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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 CheckPendingCommitCounts(true /* flush */); | 86 CheckPendingCommitCounts(true /* flush */); |
| 87 } | 87 } |
| 88 | 88 |
| 89 void BlimpCompositor::SetVisible(bool visible) { | 89 void BlimpCompositor::SetVisible(bool visible) { |
| 90 host_->SetVisible(visible); | 90 host_->SetVisible(visible); |
| 91 | 91 |
| 92 if (!visible) | 92 if (!visible) |
| 93 CheckPendingCommitCounts(true /* flush */); | 93 CheckPendingCommitCounts(true /* flush */); |
| 94 } | 94 } |
| 95 | 95 |
| 96 bool BlimpCompositor::OnTouchEvent(const ui::MotionEvent& motion_event) { | |
| 97 if (input_manager_) | |
| 98 return input_manager_->OnTouchEvent(motion_event); | |
| 99 return false; | |
| 100 } | |
| 101 | |
| 102 void BlimpCompositor::NotifyWhenDonePendingCommits(base::Closure callback) { | 96 void BlimpCompositor::NotifyWhenDonePendingCommits(base::Closure callback) { |
| 103 if (outstanding_commits_ == 0) { | 97 if (outstanding_commits_ == 0) { |
| 104 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); | 98 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); |
| 105 return; | 99 return; |
| 106 } | 100 } |
| 107 | 101 |
| 108 pending_commit_trackers_.push_back( | 102 pending_commit_trackers_.push_back( |
| 109 std::make_pair(outstanding_commits_, callback)); | 103 std::make_pair(outstanding_commits_, callback)); |
| 110 } | 104 } |
| 111 | 105 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 UMA_HISTOGRAM_MEMORY_KB("Blimp.Compositor.CommitSizeKb", | 155 UMA_HISTOGRAM_MEMORY_KB("Blimp.Compositor.CommitSizeKb", |
| 162 (float)message->ByteSize() / 1024); | 156 (float)message->ByteSize() / 1024); |
| 163 default: | 157 default: |
| 164 // We should have a receiver if we're getting compositor messages that | 158 // We should have a receiver if we're getting compositor messages that |
| 165 // are not INITIALIZE_IMPL or CLOSE_IMPL. | 159 // are not INITIALIZE_IMPL or CLOSE_IMPL. |
| 166 DCHECK(remote_proto_channel_receiver_); | 160 DCHECK(remote_proto_channel_receiver_); |
| 167 remote_proto_channel_receiver_->OnProtoReceived(std::move(message)); | 161 remote_proto_channel_receiver_->OnProtoReceived(std::move(message)); |
| 168 } | 162 } |
| 169 } | 163 } |
| 170 | 164 |
| 165 // Returns a reference to the InputHandler owned by layer tree host, which is | |
|
Khushal
2016/10/07 03:40:15
Don't need the comment in the definition.
xingliu
2016/10/10 19:00:17
Done.
| |
| 166 // used to respond to input events on the compositor thread. | |
| 167 const base::WeakPtr<cc::InputHandler>& BlimpCompositor::GetInputHandler() { | |
| 168 DCHECK(host_); | |
|
Khushal
2016/10/07 03:40:15
Don't need to DCHECK if we're de-referencing it.
David Trainor- moved to gerrit
2016/10/07 07:07:08
Yeah std::unique_ptr should check for you, but jus
xingliu
2016/10/10 19:00:17
Done.
| |
| 169 return host_->GetInputHandler(); | |
| 170 } | |
| 171 | |
| 171 void BlimpCompositor::OnContextProvidersCreated( | 172 void BlimpCompositor::OnContextProvidersCreated( |
| 172 const scoped_refptr<cc::ContextProvider>& compositor_context_provider, | 173 const scoped_refptr<cc::ContextProvider>& compositor_context_provider, |
| 173 const scoped_refptr<cc::ContextProvider>& worker_context_provider) { | 174 const scoped_refptr<cc::ContextProvider>& worker_context_provider) { |
| 174 DCHECK(!surface_factory_) << "Any connection to the old CompositorFrameSink " | 175 DCHECK(!surface_factory_) << "Any connection to the old CompositorFrameSink " |
| 175 "should have been destroyed"; | 176 "should have been destroyed"; |
| 176 | 177 |
| 177 // Make sure we still have a host and we're still expecting a | 178 // Make sure we still have a host and we're still expecting a |
| 178 // CompositorFrameSink. This can happen if the host dies while the request is | 179 // CompositorFrameSink. This can happen if the host dies while the request is |
| 179 // outstanding and we build a new one that hasn't asked for a surface yet. | 180 // outstanding and we build a new one that hasn't asked for a surface yet. |
| 180 if (!compositor_frame_sink_request_pending_) | 181 if (!compositor_frame_sink_request_pending_) |
| 181 return; | 182 return; |
| 182 | 183 |
| 183 // Try again if the context creation failed. | 184 // Try again if the context creation failed. |
| 184 if (!compositor_context_provider) { | 185 if (!compositor_context_provider) { |
| 185 GetEmbedderDeps()->GetContextProviders( | 186 GetEmbedderDeps()->GetContextProviders( |
| 186 base::Bind(&BlimpCompositor::OnContextProvidersCreated, | 187 base::Bind(&BlimpCompositor::OnContextProvidersCreated, |
| 187 weak_ptr_factory_.GetWeakPtr())); | 188 weak_ptr_factory_.GetWeakPtr())); |
| 188 return; | 189 return; |
| 189 } | 190 } |
| 190 | 191 |
| 191 auto compositor_frame_sink = base::MakeUnique<BlimpCompositorFrameSink>( | 192 auto compositor_frame_sink = base::MakeUnique<BlimpCompositorFrameSink>( |
| 192 std::move(compositor_context_provider), | 193 std::move(compositor_context_provider), |
| 193 std::move(worker_context_provider), base::ThreadTaskRunnerHandle::Get(), | 194 std::move(worker_context_provider), base::ThreadTaskRunnerHandle::Get(), |
| 194 weak_ptr_factory_.GetWeakPtr()); | 195 weak_ptr_factory_.GetWeakPtr()); |
| 195 | 196 |
| 196 host_->SetCompositorFrameSink(std::move(compositor_frame_sink)); | 197 host_->SetCompositorFrameSink(std::move(compositor_frame_sink)); |
| 197 } | 198 } |
| 198 | 199 |
| 199 void BlimpCompositor::SendWebGestureEvent( | |
| 200 const blink::WebGestureEvent& gesture_event) { | |
| 201 client_->SendWebGestureEvent(gesture_event); | |
| 202 } | |
| 203 | |
| 204 void BlimpCompositor::BindToProxyClient( | 200 void BlimpCompositor::BindToProxyClient( |
| 205 base::WeakPtr<BlimpCompositorFrameSinkProxyClient> proxy_client) { | 201 base::WeakPtr<BlimpCompositorFrameSinkProxyClient> proxy_client) { |
| 206 DCHECK(thread_checker_.CalledOnValidThread()); | 202 DCHECK(thread_checker_.CalledOnValidThread()); |
| 207 DCHECK(!surface_factory_); | 203 DCHECK(!surface_factory_); |
| 208 | 204 |
| 209 proxy_client_ = proxy_client; | 205 proxy_client_ = proxy_client; |
| 210 surface_factory_ = base::MakeUnique<cc::SurfaceFactory>( | 206 surface_factory_ = base::MakeUnique<cc::SurfaceFactory>( |
| 211 frame_sink_id_, GetEmbedderDeps()->GetSurfaceManager(), this); | 207 frame_sink_id_, GetEmbedderDeps()->GetSurfaceManager(), this); |
| 212 } | 208 } |
| 213 | 209 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 302 settings->abort_commit_before_compositor_frame_sink_creation = false; | 298 settings->abort_commit_before_compositor_frame_sink_creation = false; |
| 303 params.settings = settings; | 299 params.settings = settings; |
| 304 | 300 |
| 305 params.animation_host = cc::AnimationHost::CreateMainInstance(); | 301 params.animation_host = cc::AnimationHost::CreateMainInstance(); |
| 306 | 302 |
| 307 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner = | 303 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner = |
| 308 compositor_dependencies_->GetCompositorTaskRunner(); | 304 compositor_dependencies_->GetCompositorTaskRunner(); |
| 309 | 305 |
| 310 host_ = cc::LayerTreeHostInProcess::CreateRemoteClient( | 306 host_ = cc::LayerTreeHostInProcess::CreateRemoteClient( |
| 311 this /* remote_proto_channel */, compositor_task_runner, ¶ms); | 307 this /* remote_proto_channel */, compositor_task_runner, ¶ms); |
| 312 | |
| 313 DCHECK(!input_manager_); | |
| 314 input_manager_ = BlimpInputManager::Create( | |
| 315 this, base::ThreadTaskRunnerHandle::Get(), compositor_task_runner, | |
| 316 host_->GetInputHandler()); | |
| 317 } | 308 } |
| 318 | 309 |
| 319 void BlimpCompositor::DestroyLayerTreeHost() { | 310 void BlimpCompositor::DestroyLayerTreeHost() { |
| 320 DCHECK(host_); | 311 DCHECK(host_); |
| 321 VLOG(1) << "Destroying LayerTreeHost."; | 312 VLOG(1) << "Destroying LayerTreeHost."; |
| 322 | 313 |
| 323 // Tear down the output surface connection with the old LayerTreeHost | 314 // Tear down the output surface connection with the old LayerTreeHost |
| 324 // instance. | 315 // instance. |
| 325 DestroyDelegatedContent(); | 316 DestroyDelegatedContent(); |
| 326 surface_factory_.reset(); | 317 surface_factory_.reset(); |
| 327 | 318 |
| 328 // Destroy the old LayerTreeHost state. | 319 // Destroy the old LayerTreeHost state. |
| 329 host_.reset(); | 320 host_.reset(); |
| 330 | 321 |
| 331 // Destroy the old input manager state. | |
| 332 // It is important to destroy the LayerTreeHost before destroying the input | |
| 333 // manager as it has a reference to the cc::InputHandlerClient owned by the | |
| 334 // BlimpInputManager. | |
| 335 input_manager_.reset(); | |
| 336 | |
| 337 // Cancel any outstanding CompositorFrameSink requests. That way if we get an | 322 // Cancel any outstanding CompositorFrameSink requests. That way if we get an |
| 338 // async callback related to the old request we know to drop it. | 323 // async callback related to the old request we know to drop it. |
| 339 compositor_frame_sink_request_pending_ = false; | 324 compositor_frame_sink_request_pending_ = false; |
| 340 | 325 |
| 341 // Make sure we don't have a receiver at this point. | 326 // Make sure we don't have a receiver at this point. |
| 342 DCHECK(!remote_proto_channel_receiver_); | 327 DCHECK(!remote_proto_channel_receiver_); |
| 343 } | 328 } |
| 344 | 329 |
| 345 void BlimpCompositor::CheckPendingCommitCounts(bool flush) { | 330 void BlimpCompositor::CheckPendingCommitCounts(bool flush) { |
| 346 for (auto it = pending_commit_trackers_.begin(); | 331 for (auto it = pending_commit_trackers_.begin(); |
| 347 it != pending_commit_trackers_.end();) { | 332 it != pending_commit_trackers_.end();) { |
| 348 if (flush || --it->first == 0) { | 333 if (flush || --it->first == 0) { |
| 349 it->second.Run(); | 334 it->second.Run(); |
| 350 it = pending_commit_trackers_.erase(it); | 335 it = pending_commit_trackers_.erase(it); |
| 351 } else { | 336 } else { |
| 352 ++it; | 337 ++it; |
| 353 } | 338 } |
| 354 } | 339 } |
| 355 } | 340 } |
| 356 | 341 |
| 357 } // namespace client | 342 } // namespace client |
| 358 } // namespace blimp | 343 } // namespace blimp |
| OLD | NEW |