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" |
11 #include "base/numerics/safe_conversions.h" | 11 #include "base/numerics/safe_conversions.h" |
12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
13 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
14 #include "base/threading/thread_local.h" | 14 #include "base/threading/thread_local.h" |
15 #include "base/threading/thread_restrictions.h" | 15 #include "base/threading/thread_restrictions.h" |
16 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
17 #include "blimp/client/core/compositor/blimp_compositor_dependencies.h" | 17 #include "blimp/client/core/compositor/blimp_compositor_dependencies.h" |
18 #include "blimp/client/core/compositor/delegated_output_surface.h" | 18 #include "blimp/client/core/compositor/blimp_compositor_frame_sink.h" |
19 #include "blimp/client/public/compositor/compositor_dependencies.h" | 19 #include "blimp/client/public/compositor/compositor_dependencies.h" |
20 #include "blimp/net/blimp_stats.h" | 20 #include "blimp/net/blimp_stats.h" |
21 #include "cc/animation/animation_host.h" | 21 #include "cc/animation/animation_host.h" |
22 #include "cc/layers/layer.h" | 22 #include "cc/layers/layer.h" |
23 #include "cc/layers/surface_layer.h" | 23 #include "cc/layers/surface_layer.h" |
24 #include "cc/output/output_surface.h" | 24 #include "cc/output/compositor_frame_sink.h" |
25 #include "cc/proto/compositor_message.pb.h" | 25 #include "cc/proto/compositor_message.pb.h" |
26 #include "cc/surfaces/surface.h" | 26 #include "cc/surfaces/surface.h" |
27 #include "cc/surfaces/surface_factory.h" | 27 #include "cc/surfaces/surface_factory.h" |
28 #include "cc/surfaces/surface_id_allocator.h" | 28 #include "cc/surfaces/surface_id_allocator.h" |
29 #include "cc/surfaces/surface_manager.h" | 29 #include "cc/surfaces/surface_manager.h" |
30 #include "cc/trees/layer_tree_host.h" | 30 #include "cc/trees/layer_tree_host.h" |
31 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" | 31 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" |
32 #include "net/base/net_errors.h" | 32 #include "net/base/net_errors.h" |
33 #include "ui/gl/gl_surface.h" | 33 #include "ui/gl/gl_surface.h" |
34 | 34 |
(...skipping 22 matching lines...) Expand all Loading... |
57 | 57 |
58 } // namespace | 58 } // namespace |
59 | 59 |
60 BlimpCompositor::BlimpCompositor( | 60 BlimpCompositor::BlimpCompositor( |
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 proxy_client_(nullptr), |
68 output_surface_request_pending_(false), | 68 compositor_frame_sink_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 outstanding_commits_(0U), |
72 weak_ptr_factory_(this) { | 72 weak_ptr_factory_(this) { |
73 DCHECK(thread_checker_.CalledOnValidThread()); | 73 DCHECK(thread_checker_.CalledOnValidThread()); |
74 | 74 |
75 surface_id_allocator_ = base::MakeUnique<cc::SurfaceIdAllocator>( | 75 surface_id_allocator_ = base::MakeUnique<cc::SurfaceIdAllocator>( |
76 GetEmbedderDeps()->AllocateSurfaceClientId()); | 76 GetEmbedderDeps()->AllocateSurfaceClientId()); |
77 GetEmbedderDeps()->GetSurfaceManager()->RegisterSurfaceClientId( | 77 GetEmbedderDeps()->GetSurfaceManager()->RegisterSurfaceClientId( |
78 surface_id_allocator_->client_id()); | 78 surface_id_allocator_->client_id()); |
(...skipping 26 matching lines...) Expand all Loading... |
105 void BlimpCompositor::NotifyWhenDonePendingCommits(base::Closure callback) { | 105 void BlimpCompositor::NotifyWhenDonePendingCommits(base::Closure callback) { |
106 if (outstanding_commits_ == 0) { | 106 if (outstanding_commits_ == 0) { |
107 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); | 107 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); |
108 return; | 108 return; |
109 } | 109 } |
110 | 110 |
111 pending_commit_trackers_.push_back( | 111 pending_commit_trackers_.push_back( |
112 std::make_pair(outstanding_commits_, callback)); | 112 std::make_pair(outstanding_commits_, callback)); |
113 } | 113 } |
114 | 114 |
115 void BlimpCompositor::RequestNewOutputSurface() { | 115 void BlimpCompositor::RequestNewCompositorFrameSink() { |
116 DCHECK(!surface_factory_); | 116 DCHECK(!surface_factory_); |
117 DCHECK(!output_surface_request_pending_); | 117 DCHECK(!compositor_frame_sink_request_pending_); |
118 | 118 |
119 output_surface_request_pending_ = true; | 119 compositor_frame_sink_request_pending_ = true; |
120 GetEmbedderDeps()->GetContextProviders( | 120 GetEmbedderDeps()->GetContextProviders( |
121 base::Bind(&BlimpCompositor::OnContextProvidersCreated, | 121 base::Bind(&BlimpCompositor::OnContextProvidersCreated, |
122 weak_ptr_factory_.GetWeakPtr())); | 122 weak_ptr_factory_.GetWeakPtr())); |
123 } | 123 } |
124 | 124 |
125 void BlimpCompositor::DidInitializeOutputSurface() { | 125 void BlimpCompositor::DidInitializeCompositorFrameSink() { |
126 output_surface_request_pending_ = false; | 126 compositor_frame_sink_request_pending_ = false; |
127 } | 127 } |
128 | 128 |
129 void BlimpCompositor::DidCommitAndDrawFrame() { | 129 void BlimpCompositor::DidCommitAndDrawFrame() { |
130 BlimpStats::GetInstance()->Add(BlimpStats::COMMIT, 1); | 130 BlimpStats::GetInstance()->Add(BlimpStats::COMMIT, 1); |
131 | 131 |
132 DCHECK_GT(outstanding_commits_, 0U); | 132 DCHECK_GT(outstanding_commits_, 0U); |
133 outstanding_commits_--; | 133 outstanding_commits_--; |
134 | 134 |
135 CheckPendingCommitCounts(false /* flush */); | 135 CheckPendingCommitCounts(false /* flush */); |
136 } | 136 } |
(...skipping 30 matching lines...) Expand all Loading... |
167 // 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 |
168 // are not INITIALIZE_IMPL or CLOSE_IMPL. | 168 // are not INITIALIZE_IMPL or CLOSE_IMPL. |
169 DCHECK(remote_proto_channel_receiver_); | 169 DCHECK(remote_proto_channel_receiver_); |
170 remote_proto_channel_receiver_->OnProtoReceived(std::move(message)); | 170 remote_proto_channel_receiver_->OnProtoReceived(std::move(message)); |
171 } | 171 } |
172 } | 172 } |
173 | 173 |
174 void BlimpCompositor::OnContextProvidersCreated( | 174 void BlimpCompositor::OnContextProvidersCreated( |
175 const scoped_refptr<cc::ContextProvider>& compositor_context_provider, | 175 const scoped_refptr<cc::ContextProvider>& compositor_context_provider, |
176 const scoped_refptr<cc::ContextProvider>& worker_context_provider) { | 176 const scoped_refptr<cc::ContextProvider>& worker_context_provider) { |
177 DCHECK(!surface_factory_) | 177 DCHECK(!surface_factory_) << "Any connection to the old CompositorFrameSink " |
178 << "Any connection to the old output surface should have been destroyed"; | 178 "should have been destroyed"; |
179 | 179 |
180 // Make sure we still have a host and we're still expecting an output surface. | 180 // Make sure we still have a host and we're still expecting a |
181 // This can happen if the host dies while the request is outstanding and we | 181 // CompositorFrameSink. This can happen if the host dies while the request is |
182 // build a new one that hasn't asked for a surface yet. | 182 // outstanding and we build a new one that hasn't asked for a surface yet. |
183 if (!output_surface_request_pending_) | 183 if (!compositor_frame_sink_request_pending_) |
184 return; | 184 return; |
185 | 185 |
186 // Try again if the context creation failed. | 186 // Try again if the context creation failed. |
187 if (!compositor_context_provider) { | 187 if (!compositor_context_provider) { |
188 GetEmbedderDeps()->GetContextProviders( | 188 GetEmbedderDeps()->GetContextProviders( |
189 base::Bind(&BlimpCompositor::OnContextProvidersCreated, | 189 base::Bind(&BlimpCompositor::OnContextProvidersCreated, |
190 weak_ptr_factory_.GetWeakPtr())); | 190 weak_ptr_factory_.GetWeakPtr())); |
191 return; | 191 return; |
192 } | 192 } |
193 | 193 |
194 std::unique_ptr<DelegatedOutputSurface> delegated_output_surface = | 194 auto compositor_frame_sink = base::MakeUnique<BlimpCompositorFrameSink>( |
195 base::MakeUnique<DelegatedOutputSurface>( | 195 std::move(compositor_context_provider), |
196 std::move(compositor_context_provider), | 196 std::move(worker_context_provider), base::ThreadTaskRunnerHandle::Get(), |
197 std::move(worker_context_provider), | 197 weak_ptr_factory_.GetWeakPtr()); |
198 base::ThreadTaskRunnerHandle::Get(), weak_ptr_factory_.GetWeakPtr()); | |
199 | 198 |
200 host_->SetOutputSurface(std::move(delegated_output_surface)); | 199 host_->SetCompositorFrameSink(std::move(compositor_frame_sink)); |
201 } | 200 } |
202 | 201 |
203 void BlimpCompositor::SendWebGestureEvent( | 202 void BlimpCompositor::SendWebGestureEvent( |
204 const blink::WebGestureEvent& gesture_event) { | 203 const blink::WebGestureEvent& gesture_event) { |
205 client_->SendWebGestureEvent(render_widget_id_, gesture_event); | 204 client_->SendWebGestureEvent(render_widget_id_, gesture_event); |
206 } | 205 } |
207 | 206 |
208 void BlimpCompositor::BindToOutputSurface( | 207 void BlimpCompositor::BindToProxyClient( |
209 base::WeakPtr<BlimpOutputSurface> output_surface) { | 208 base::WeakPtr<BlimpCompositorFrameSinkProxyClient> proxy_client) { |
210 DCHECK(thread_checker_.CalledOnValidThread()); | 209 DCHECK(thread_checker_.CalledOnValidThread()); |
211 DCHECK(!surface_factory_); | 210 DCHECK(!surface_factory_); |
212 | 211 |
213 output_surface_ = output_surface; | 212 proxy_client_ = proxy_client; |
214 surface_factory_ = base::MakeUnique<cc::SurfaceFactory>( | 213 surface_factory_ = base::MakeUnique<cc::SurfaceFactory>( |
215 GetEmbedderDeps()->GetSurfaceManager(), this); | 214 GetEmbedderDeps()->GetSurfaceManager(), this); |
216 } | 215 } |
217 | 216 |
218 void BlimpCompositor::SwapCompositorFrame(cc::CompositorFrame frame) { | 217 void BlimpCompositor::SwapCompositorFrame(cc::CompositorFrame frame) { |
219 DCHECK(thread_checker_.CalledOnValidThread()); | 218 DCHECK(thread_checker_.CalledOnValidThread()); |
220 DCHECK(surface_factory_); | 219 DCHECK(surface_factory_); |
221 | 220 |
222 cc::RenderPass* root_pass = | 221 cc::RenderPass* root_pass = |
223 frame.delegated_frame_data->render_pass_list.back().get(); | 222 frame.delegated_frame_data->render_pass_list.back().get(); |
(...skipping 18 matching lines...) Expand all Loading... |
242 content_layer->SetIsDrawable(true); | 241 content_layer->SetIsDrawable(true); |
243 content_layer->SetContentsOpaque(true); | 242 content_layer->SetContentsOpaque(true); |
244 | 243 |
245 layer_->AddChild(content_layer); | 244 layer_->AddChild(content_layer); |
246 } | 245 } |
247 | 246 |
248 surface_factory_->SubmitCompositorFrame(surface_id_, std::move(frame), | 247 surface_factory_->SubmitCompositorFrame(surface_id_, std::move(frame), |
249 base::Closure()); | 248 base::Closure()); |
250 } | 249 } |
251 | 250 |
252 void BlimpCompositor::UnbindOutputSurface() { | 251 void BlimpCompositor::UnbindProxyClient() { |
253 DCHECK(thread_checker_.CalledOnValidThread()); | 252 DCHECK(thread_checker_.CalledOnValidThread()); |
254 DCHECK(surface_factory_); | 253 DCHECK(surface_factory_); |
255 | 254 |
256 DestroyDelegatedContent(); | 255 DestroyDelegatedContent(); |
257 surface_factory_.reset(); | 256 surface_factory_.reset(); |
258 output_surface_ = nullptr; | 257 proxy_client_ = nullptr; |
259 } | 258 } |
260 | 259 |
261 void BlimpCompositor::ReturnResources( | 260 void BlimpCompositor::ReturnResources( |
262 const cc::ReturnedResourceArray& resources) { | 261 const cc::ReturnedResourceArray& resources) { |
263 DCHECK(surface_factory_); | 262 DCHECK(surface_factory_); |
264 compositor_dependencies_->GetCompositorTaskRunner()->PostTask( | 263 compositor_dependencies_->GetCompositorTaskRunner()->PostTask( |
265 FROM_HERE, base::Bind(&BlimpOutputSurface::ReclaimCompositorResources, | 264 FROM_HERE, |
266 output_surface_, resources)); | 265 base::Bind( |
| 266 &BlimpCompositorFrameSinkProxyClient::ReclaimCompositorResources, |
| 267 proxy_client_, resources)); |
267 } | 268 } |
268 | 269 |
269 CompositorDependencies* BlimpCompositor::GetEmbedderDeps() { | 270 CompositorDependencies* BlimpCompositor::GetEmbedderDeps() { |
270 return compositor_dependencies_->GetEmbedderDependencies(); | 271 return compositor_dependencies_->GetEmbedderDependencies(); |
271 } | 272 } |
272 | 273 |
273 void BlimpCompositor::DestroyDelegatedContent() { | 274 void BlimpCompositor::DestroyDelegatedContent() { |
274 if (surface_id_.is_null()) | 275 if (surface_id_.is_null()) |
275 return; | 276 return; |
276 | 277 |
(...skipping 14 matching lines...) Expand all Loading... |
291 params.gpu_memory_buffer_manager = | 292 params.gpu_memory_buffer_manager = |
292 GetEmbedderDeps()->GetGpuMemoryBufferManager(); | 293 GetEmbedderDeps()->GetGpuMemoryBufferManager(); |
293 params.main_task_runner = base::ThreadTaskRunnerHandle::Get(); | 294 params.main_task_runner = base::ThreadTaskRunnerHandle::Get(); |
294 params.image_serialization_processor = | 295 params.image_serialization_processor = |
295 compositor_dependencies_->GetImageSerializationProcessor(); | 296 compositor_dependencies_->GetImageSerializationProcessor(); |
296 | 297 |
297 cc::LayerTreeSettings* settings = | 298 cc::LayerTreeSettings* settings = |
298 compositor_dependencies_->GetLayerTreeSettings(); | 299 compositor_dependencies_->GetLayerTreeSettings(); |
299 // TODO(khushalsagar): This is a hack. Remove when we move the split point | 300 // TODO(khushalsagar): This is a hack. Remove when we move the split point |
300 // out. For details on why this is needed, see crbug.com/586210. | 301 // out. For details on why this is needed, see crbug.com/586210. |
301 settings->abort_commit_before_output_surface_creation = false; | 302 settings->abort_commit_before_compositor_frame_sink_creation = false; |
302 params.settings = settings; | 303 params.settings = settings; |
303 | 304 |
304 params.animation_host = cc::AnimationHost::CreateMainInstance(); | 305 params.animation_host = cc::AnimationHost::CreateMainInstance(); |
305 | 306 |
306 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner = | 307 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner = |
307 compositor_dependencies_->GetCompositorTaskRunner(); | 308 compositor_dependencies_->GetCompositorTaskRunner(); |
308 | 309 |
309 host_ = cc::LayerTreeHost::CreateRemoteClient( | 310 host_ = cc::LayerTreeHost::CreateRemoteClient( |
310 this /* remote_proto_channel */, compositor_task_runner, ¶ms); | 311 this /* remote_proto_channel */, compositor_task_runner, ¶ms); |
311 | 312 |
(...skipping 14 matching lines...) Expand all Loading... |
326 | 327 |
327 // Destroy the old LayerTreeHost state. | 328 // Destroy the old LayerTreeHost state. |
328 host_.reset(); | 329 host_.reset(); |
329 | 330 |
330 // Destroy the old input manager state. | 331 // Destroy the old input manager state. |
331 // It is important to destroy the LayerTreeHost before destroying the input | 332 // It is important to destroy the LayerTreeHost before destroying the input |
332 // manager as it has a reference to the cc::InputHandlerClient owned by the | 333 // manager as it has a reference to the cc::InputHandlerClient owned by the |
333 // BlimpInputManager. | 334 // BlimpInputManager. |
334 input_manager_.reset(); | 335 input_manager_.reset(); |
335 | 336 |
336 // Cancel any outstanding OutputSurface requests. That way if we get an async | 337 // Cancel any outstanding CompositorFrameSink requests. That way if we get an |
337 // callback related to the old request we know to drop it. | 338 // async callback related to the old request we know to drop it. |
338 output_surface_request_pending_ = false; | 339 compositor_frame_sink_request_pending_ = false; |
339 | 340 |
340 // Make sure we don't have a receiver at this point. | 341 // Make sure we don't have a receiver at this point. |
341 DCHECK(!remote_proto_channel_receiver_); | 342 DCHECK(!remote_proto_channel_receiver_); |
342 } | 343 } |
343 | 344 |
344 void BlimpCompositor::CheckPendingCommitCounts(bool flush) { | 345 void BlimpCompositor::CheckPendingCommitCounts(bool flush) { |
345 for (auto it = pending_commit_trackers_.begin(); | 346 for (auto it = pending_commit_trackers_.begin(); |
346 it != pending_commit_trackers_.end();) { | 347 it != pending_commit_trackers_.end();) { |
347 if (flush || --it->first == 0) { | 348 if (flush || --it->first == 0) { |
348 it->second.Run(); | 349 it->second.Run(); |
349 it = pending_commit_trackers_.erase(it); | 350 it = pending_commit_trackers_.erase(it); |
350 } else { | 351 } else { |
351 ++it; | 352 ++it; |
352 } | 353 } |
353 } | 354 } |
354 } | 355 } |
355 | 356 |
356 } // namespace client | 357 } // namespace client |
357 } // namespace blimp | 358 } // namespace blimp |
OLD | NEW |