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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 weak_ptr_factory_(this) { | 71 weak_ptr_factory_(this) { |
72 DCHECK(thread_checker_.CalledOnValidThread()); | 72 DCHECK(thread_checker_.CalledOnValidThread()); |
73 | 73 |
74 surface_id_allocator_ = base::MakeUnique<cc::SurfaceIdAllocator>( | 74 surface_id_allocator_ = base::MakeUnique<cc::SurfaceIdAllocator>( |
75 GetEmbedderDeps()->AllocateSurfaceId()); | 75 GetEmbedderDeps()->AllocateSurfaceClientId()); |
76 GetEmbedderDeps()->GetSurfaceManager()->RegisterSurfaceClientId( | 76 GetEmbedderDeps()->GetSurfaceManager()->RegisterSurfaceClientId( |
77 surface_id_allocator_->client_id()); | 77 surface_id_allocator_->client_id()); |
78 } | 78 } |
79 | 79 |
80 BlimpCompositor::~BlimpCompositor() { | 80 BlimpCompositor::~BlimpCompositor() { |
81 DCHECK(thread_checker_.CalledOnValidThread()); | 81 DCHECK(thread_checker_.CalledOnValidThread()); |
82 | 82 |
83 if (host_) | 83 if (host_) |
84 DestroyLayerTreeHost(); | 84 DestroyLayerTreeHost(); |
85 | 85 |
(...skipping 11 matching lines...) Expand all Loading... |
97 if (input_manager_) | 97 if (input_manager_) |
98 return input_manager_->OnTouchEvent(motion_event); | 98 return input_manager_->OnTouchEvent(motion_event); |
99 return false; | 99 return false; |
100 } | 100 } |
101 | 101 |
102 void BlimpCompositor::RequestNewOutputSurface() { | 102 void BlimpCompositor::RequestNewOutputSurface() { |
103 DCHECK(!surface_factory_); | 103 DCHECK(!surface_factory_); |
104 DCHECK(!output_surface_request_pending_); | 104 DCHECK(!output_surface_request_pending_); |
105 | 105 |
106 output_surface_request_pending_ = true; | 106 output_surface_request_pending_ = true; |
107 GetEmbedderDeps()->GetContextProvider( | 107 GetEmbedderDeps()->GetContextProviders( |
108 base::Bind(&BlimpCompositor::OnContextProviderCreated, | 108 base::Bind(&BlimpCompositor::OnContextProvidersCreated, |
109 weak_ptr_factory_.GetWeakPtr())); | 109 weak_ptr_factory_.GetWeakPtr())); |
110 } | 110 } |
111 | 111 |
112 void BlimpCompositor::DidInitializeOutputSurface() { | 112 void BlimpCompositor::DidInitializeOutputSurface() { |
113 output_surface_request_pending_ = false; | 113 output_surface_request_pending_ = false; |
114 } | 114 } |
115 | 115 |
116 void BlimpCompositor::DidCommitAndDrawFrame() { | 116 void BlimpCompositor::DidCommitAndDrawFrame() { |
117 BlimpStats::GetInstance()->Add(BlimpStats::COMMIT, 1); | 117 BlimpStats::GetInstance()->Add(BlimpStats::COMMIT, 1); |
118 } | 118 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 DestroyLayerTreeHost(); | 150 DestroyLayerTreeHost(); |
151 break; | 151 break; |
152 default: | 152 default: |
153 // We should have a receiver if we're getting compositor messages that | 153 // We should have a receiver if we're getting compositor messages that |
154 // are not INITIALIZE_IMPL or CLOSE_IMPL. | 154 // are not INITIALIZE_IMPL or CLOSE_IMPL. |
155 DCHECK(remote_proto_channel_receiver_); | 155 DCHECK(remote_proto_channel_receiver_); |
156 remote_proto_channel_receiver_->OnProtoReceived(std::move(message)); | 156 remote_proto_channel_receiver_->OnProtoReceived(std::move(message)); |
157 } | 157 } |
158 } | 158 } |
159 | 159 |
160 void BlimpCompositor::OnContextProviderCreated( | 160 void BlimpCompositor::OnContextProvidersCreated( |
161 const scoped_refptr<cc::ContextProvider>& provider) { | 161 const scoped_refptr<cc::ContextProvider>& compositor_context_provider, |
| 162 const scoped_refptr<cc::ContextProvider>& worker_context_provider) { |
162 DCHECK(!surface_factory_) | 163 DCHECK(!surface_factory_) |
163 << "Any connection to the old output surface should have been destroyed"; | 164 << "Any connection to the old output surface should have been destroyed"; |
164 | 165 |
165 // Make sure we still have a host and we're still expecting an output surface. | 166 // Make sure we still have a host and we're still expecting an output surface. |
166 // This can happen if the host dies while the request is outstanding and we | 167 // This can happen if the host dies while the request is outstanding and we |
167 // build a new one that hasn't asked for a surface yet. | 168 // build a new one that hasn't asked for a surface yet. |
168 if (!output_surface_request_pending_) | 169 if (!output_surface_request_pending_) |
169 return; | 170 return; |
170 | 171 |
171 // TODO(khushalsagar): Make a worker context and bind it to the current | 172 // Try again if the context creation failed. |
172 // thread: | 173 if (!compositor_context_provider) { |
173 // Worker context is bound to the main thread in RenderThreadImpl. One day | 174 GetEmbedderDeps()->GetContextProviders( |
174 // that will change and then this will have to be removed. | 175 base::Bind(&BlimpCompositor::OnContextProvidersCreated, |
175 // worker_context_provider->BindToCurrentThread(); | 176 weak_ptr_factory_.GetWeakPtr())); |
| 177 return; |
| 178 } |
| 179 |
176 std::unique_ptr<DelegatedOutputSurface> delegated_output_surface = | 180 std::unique_ptr<DelegatedOutputSurface> delegated_output_surface = |
177 base::MakeUnique<DelegatedOutputSurface>( | 181 base::MakeUnique<DelegatedOutputSurface>( |
178 provider, nullptr, base::ThreadTaskRunnerHandle::Get(), | 182 std::move(compositor_context_provider), |
179 weak_ptr_factory_.GetWeakPtr()); | 183 std::move(worker_context_provider), |
| 184 base::ThreadTaskRunnerHandle::Get(), weak_ptr_factory_.GetWeakPtr()); |
180 | 185 |
181 host_->SetOutputSurface(std::move(delegated_output_surface)); | 186 host_->SetOutputSurface(std::move(delegated_output_surface)); |
182 } | 187 } |
183 | 188 |
184 void BlimpCompositor::SendWebGestureEvent( | 189 void BlimpCompositor::SendWebGestureEvent( |
185 const blink::WebGestureEvent& gesture_event) { | 190 const blink::WebGestureEvent& gesture_event) { |
186 client_->SendWebGestureEvent(render_widget_id_, gesture_event); | 191 client_->SendWebGestureEvent(render_widget_id_, gesture_event); |
187 } | 192 } |
188 | 193 |
189 void BlimpCompositor::BindToOutputSurface( | 194 void BlimpCompositor::BindToOutputSurface( |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 | 273 |
269 // Create the LayerTreeHost | 274 // Create the LayerTreeHost |
270 cc::LayerTreeHost::InitParams params; | 275 cc::LayerTreeHost::InitParams params; |
271 params.client = this; | 276 params.client = this; |
272 params.task_graph_runner = compositor_dependencies_->GetTaskGraphRunner(); | 277 params.task_graph_runner = compositor_dependencies_->GetTaskGraphRunner(); |
273 params.gpu_memory_buffer_manager = | 278 params.gpu_memory_buffer_manager = |
274 GetEmbedderDeps()->GetGpuMemoryBufferManager(); | 279 GetEmbedderDeps()->GetGpuMemoryBufferManager(); |
275 params.main_task_runner = base::ThreadTaskRunnerHandle::Get(); | 280 params.main_task_runner = base::ThreadTaskRunnerHandle::Get(); |
276 params.image_serialization_processor = | 281 params.image_serialization_processor = |
277 compositor_dependencies_->GetImageSerializationProcessor(); | 282 compositor_dependencies_->GetImageSerializationProcessor(); |
278 params.settings = GetEmbedderDeps()->GetLayerTreeSettings(); | 283 |
| 284 cc::LayerTreeSettings* settings = |
| 285 compositor_dependencies_->GetLayerTreeSettings(); |
| 286 // TODO(khushalsagar): This is a hack. Remove when we move the split point |
| 287 // out. For details on why this is needed, see crbug.com/586210. |
| 288 settings->abort_commit_before_output_surface_creation = false; |
| 289 params.settings = settings; |
| 290 |
279 params.animation_host = cc::AnimationHost::CreateMainInstance(); | 291 params.animation_host = cc::AnimationHost::CreateMainInstance(); |
280 | 292 |
281 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner = | 293 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner = |
282 compositor_dependencies_->GetCompositorTaskRunner(); | 294 compositor_dependencies_->GetCompositorTaskRunner(); |
283 | 295 |
284 host_ = cc::LayerTreeHost::CreateRemoteClient( | 296 host_ = cc::LayerTreeHost::CreateRemoteClient( |
285 this /* remote_proto_channel */, compositor_task_runner, ¶ms); | 297 this /* remote_proto_channel */, compositor_task_runner, ¶ms); |
286 host_->SetVisible(host_should_be_visible_); | 298 host_->SetVisible(host_should_be_visible_); |
287 | 299 |
288 DCHECK(!input_manager_); | 300 DCHECK(!input_manager_); |
(...skipping 23 matching lines...) Expand all Loading... |
312 // Cancel any outstanding OutputSurface requests. That way if we get an async | 324 // Cancel any outstanding OutputSurface requests. That way if we get an async |
313 // callback related to the old request we know to drop it. | 325 // callback related to the old request we know to drop it. |
314 output_surface_request_pending_ = false; | 326 output_surface_request_pending_ = false; |
315 | 327 |
316 // Make sure we don't have a receiver at this point. | 328 // Make sure we don't have a receiver at this point. |
317 DCHECK(!remote_proto_channel_receiver_); | 329 DCHECK(!remote_proto_channel_receiver_); |
318 } | 330 } |
319 | 331 |
320 } // namespace client | 332 } // namespace client |
321 } // namespace blimp | 333 } // namespace blimp |
OLD | NEW |