OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/compositor/compositor.h" | 5 #include "ui/compositor/compositor.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <deque> | 10 #include <deque> |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 output_surface_requested_(false), | 82 output_surface_requested_(false), |
83 surface_id_allocator_(new cc::SurfaceIdAllocator( | 83 surface_id_allocator_(new cc::SurfaceIdAllocator( |
84 context_factory->AllocateSurfaceClientId())), | 84 context_factory->AllocateSurfaceClientId())), |
85 task_runner_(task_runner), | 85 task_runner_(task_runner), |
86 vsync_manager_(new CompositorVSyncManager()), | 86 vsync_manager_(new CompositorVSyncManager()), |
87 device_scale_factor_(0.0f), | 87 device_scale_factor_(0.0f), |
88 locks_will_time_out_(true), | 88 locks_will_time_out_(true), |
89 compositor_lock_(NULL), | 89 compositor_lock_(NULL), |
90 layer_animator_collection_(this), | 90 layer_animator_collection_(this), |
91 weak_ptr_factory_(this) { | 91 weak_ptr_factory_(this) { |
92 if (context_factory->GetSurfaceManager()) { | 92 context_factory->GetSurfaceManager()->RegisterSurfaceClientId( |
93 context_factory->GetSurfaceManager()->RegisterSurfaceClientId( | 93 surface_id_allocator_->client_id()); |
94 surface_id_allocator_->client_id()); | |
95 } | |
96 root_web_layer_ = cc::Layer::Create(); | 94 root_web_layer_ = cc::Layer::Create(); |
97 | 95 |
98 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 96 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
99 | 97 |
100 cc::LayerTreeSettings settings; | 98 cc::LayerTreeSettings settings; |
101 | 99 |
102 // This will ensure PictureLayers always can have LCD text, to match the | 100 // This will ensure PictureLayers always can have LCD text, to match the |
103 // previous behaviour with ContentLayers, where LCD-not-allowed notifications | 101 // previous behaviour with ContentLayers, where LCD-not-allowed notifications |
104 // were ignored. | 102 // were ignored. |
105 settings.layers_always_allowed_lcd_text = true; | 103 settings.layers_always_allowed_lcd_text = true; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
235 | 233 |
236 if (animation_timeline_) | 234 if (animation_timeline_) |
237 host_->GetLayerTree()->animation_host()->RemoveAnimationTimeline( | 235 host_->GetLayerTree()->animation_host()->RemoveAnimationTimeline( |
238 animation_timeline_.get()); | 236 animation_timeline_.get()); |
239 | 237 |
240 // Stop all outstanding draws before telling the ContextFactory to tear | 238 // Stop all outstanding draws before telling the ContextFactory to tear |
241 // down any contexts that the |host_| may rely upon. | 239 // down any contexts that the |host_| may rely upon. |
242 host_.reset(); | 240 host_.reset(); |
243 | 241 |
244 context_factory_->RemoveCompositor(this); | 242 context_factory_->RemoveCompositor(this); |
245 if (context_factory_->GetSurfaceManager()) { | 243 auto* manager = context_factory_->GetSurfaceManager(); |
246 for (auto& client : surface_clients_) { | 244 for (auto& client : surface_clients_) { |
247 if (client.second) { | 245 DCHECK(client.second); |
248 context_factory_->GetSurfaceManager() | 246 manager->UnregisterSurfaceNamespaceHierarchy(client.second, client.first); |
249 ->UnregisterSurfaceNamespaceHierarchy(client.second, client.first); | |
250 } | |
251 } | |
252 context_factory_->GetSurfaceManager()->InvalidateSurfaceClientId( | |
253 surface_id_allocator_->client_id()); | |
254 } | 247 } |
248 manager->InvalidateSurfaceClientId(surface_id_allocator_->client_id()); | |
255 } | 249 } |
256 | 250 |
257 void Compositor::AddSurfaceClient(uint32_t client_id) { | 251 void Compositor::AddSurfaceClient(uint32_t client_id) { |
258 // We don't give the client a parent until the ui::Compositor has an | 252 uint32_t parent_client_id = surface_id_allocator_->client_id(); |
259 // OutputSurface. | 253 context_factory_->GetSurfaceManager()->RegisterSurfaceNamespaceHierarchy( |
Fady Samuel
2016/08/25 02:43:06
This all kind of goes in the opposite direction of
piman
2016/08/25 03:33:45
Does the SurfaceFactory have to be tied to the Out
| |
260 uint32_t parent_client_id = 0; | 254 parent_client_id, client_id); |
261 if (host_->has_output_surface()) { | |
262 parent_client_id = surface_id_allocator_->client_id(); | |
263 context_factory_->GetSurfaceManager()->RegisterSurfaceNamespaceHierarchy( | |
264 parent_client_id, client_id); | |
265 } | |
266 surface_clients_[client_id] = parent_client_id; | 255 surface_clients_[client_id] = parent_client_id; |
267 } | 256 } |
268 | 257 |
269 void Compositor::RemoveSurfaceClient(uint32_t client_id) { | 258 void Compositor::RemoveSurfaceClient(uint32_t client_id) { |
270 auto it = surface_clients_.find(client_id); | 259 auto it = surface_clients_.find(client_id); |
271 DCHECK(it != surface_clients_.end()); | 260 DCHECK(it != surface_clients_.end()); |
272 if (host_->has_output_surface()) { | 261 DCHECK(it->second); |
273 context_factory_->GetSurfaceManager()->UnregisterSurfaceNamespaceHierarchy( | 262 context_factory_->GetSurfaceManager()->UnregisterSurfaceNamespaceHierarchy( |
274 it->second, client_id); | 263 it->second, it->first); |
275 } | |
276 surface_clients_.erase(it); | 264 surface_clients_.erase(it); |
277 } | 265 } |
278 | 266 |
279 void Compositor::SetOutputSurface( | 267 void Compositor::SetOutputSurface( |
280 std::unique_ptr<cc::OutputSurface> output_surface) { | 268 std::unique_ptr<cc::OutputSurface> output_surface) { |
281 output_surface_requested_ = false; | 269 output_surface_requested_ = false; |
282 host_->SetOutputSurface(std::move(output_surface)); | 270 host_->SetOutputSurface(std::move(output_surface)); |
283 // ui::Compositor uses a SingleThreadProxy and so BindToClient will be called | |
284 // above and SurfaceManager will be made aware of the OutputSurface's client | |
285 // ID. | |
286 for (auto& client : surface_clients_) { | |
287 if (client.second == surface_id_allocator_->client_id()) | |
288 continue; | |
289 // If a client already has a parent, then we unregister the existing parent. | |
290 if (client.second) { | |
291 context_factory_->GetSurfaceManager() | |
292 ->UnregisterSurfaceNamespaceHierarchy(client.second, client.first); | |
293 } | |
294 context_factory_->GetSurfaceManager()->RegisterSurfaceNamespaceHierarchy( | |
295 surface_id_allocator_->client_id(), client.first); | |
296 client.second = surface_id_allocator_->client_id(); | |
297 } | |
298 // Visibility is reset when the output surface is lost, so update it to match | 271 // Visibility is reset when the output surface is lost, so update it to match |
299 // the Compositor's. | 272 // the Compositor's. |
300 context_factory_->SetDisplayVisible(this, host_->visible()); | 273 context_factory_->SetDisplayVisible(this, host_->visible()); |
301 } | 274 } |
302 | 275 |
303 void Compositor::ScheduleDraw() { | 276 void Compositor::ScheduleDraw() { |
304 host_->SetNeedsCommit(); | 277 host_->SetNeedsCommit(); |
305 } | 278 } |
306 | 279 |
307 void Compositor::SetRootLayer(Layer* root_layer) { | 280 void Compositor::SetRootLayer(Layer* root_layer) { |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
411 // This function should only get called once. | 384 // This function should only get called once. |
412 DCHECK(!widget_valid_); | 385 DCHECK(!widget_valid_); |
413 widget_ = widget; | 386 widget_ = widget; |
414 widget_valid_ = true; | 387 widget_valid_ = true; |
415 if (output_surface_requested_) | 388 if (output_surface_requested_) |
416 context_factory_->CreateOutputSurface(weak_ptr_factory_.GetWeakPtr()); | 389 context_factory_->CreateOutputSurface(weak_ptr_factory_.GetWeakPtr()); |
417 } | 390 } |
418 | 391 |
419 gfx::AcceleratedWidget Compositor::ReleaseAcceleratedWidget() { | 392 gfx::AcceleratedWidget Compositor::ReleaseAcceleratedWidget() { |
420 DCHECK(!IsVisible()); | 393 DCHECK(!IsVisible()); |
421 if (!host_->output_surface_lost()) { | 394 host_->ReleaseOutputSurface(); |
422 host_->ReleaseOutputSurface(); | |
423 for (auto& client : surface_clients_) { | |
424 context_factory_->GetSurfaceManager() | |
425 ->UnregisterSurfaceNamespaceHierarchy(client.second, client.first); | |
426 client.second = 0; | |
427 } | |
428 } | |
429 context_factory_->RemoveCompositor(this); | 395 context_factory_->RemoveCompositor(this); |
430 widget_valid_ = false; | 396 widget_valid_ = false; |
431 gfx::AcceleratedWidget widget = widget_; | 397 gfx::AcceleratedWidget widget = widget_; |
432 widget_ = gfx::kNullAcceleratedWidget; | 398 widget_ = gfx::kNullAcceleratedWidget; |
433 return widget; | 399 return widget; |
434 } | 400 } |
435 | 401 |
436 gfx::AcceleratedWidget Compositor::widget() const { | 402 gfx::AcceleratedWidget Compositor::widget() const { |
437 DCHECK(widget_valid_); | 403 DCHECK(widget_valid_); |
438 return widget_; | 404 return widget_; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
499 | 465 |
500 void Compositor::UpdateLayerTreeHost() { | 466 void Compositor::UpdateLayerTreeHost() { |
501 if (!root_layer()) | 467 if (!root_layer()) |
502 return; | 468 return; |
503 SendDamagedRectsRecursive(root_layer()); | 469 SendDamagedRectsRecursive(root_layer()); |
504 } | 470 } |
505 | 471 |
506 void Compositor::RequestNewOutputSurface() { | 472 void Compositor::RequestNewOutputSurface() { |
507 DCHECK(!output_surface_requested_); | 473 DCHECK(!output_surface_requested_); |
508 output_surface_requested_ = true; | 474 output_surface_requested_ = true; |
509 if (widget_valid_) { | 475 if (widget_valid_) |
510 context_factory_->CreateOutputSurface(weak_ptr_factory_.GetWeakPtr()); | 476 context_factory_->CreateOutputSurface(weak_ptr_factory_.GetWeakPtr()); |
511 } | |
512 } | 477 } |
513 | 478 |
514 void Compositor::DidInitializeOutputSurface() { | 479 void Compositor::DidInitializeOutputSurface() { |
515 } | 480 } |
516 | 481 |
517 void Compositor::DidFailToInitializeOutputSurface() { | 482 void Compositor::DidFailToInitializeOutputSurface() { |
518 // The OutputSurface should already be bound/initialized before being given to | 483 // The OutputSurface should already be bound/initialized before being given to |
519 // the Compositor. | 484 // the Compositor. |
520 NOTREACHED(); | 485 NOTREACHED(); |
521 } | 486 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
583 observer_list_, | 548 observer_list_, |
584 OnCompositingLockStateChanged(this)); | 549 OnCompositingLockStateChanged(this)); |
585 } | 550 } |
586 | 551 |
587 void Compositor::CancelCompositorLock() { | 552 void Compositor::CancelCompositorLock() { |
588 if (compositor_lock_) | 553 if (compositor_lock_) |
589 compositor_lock_->CancelLock(); | 554 compositor_lock_->CancelLock(); |
590 } | 555 } |
591 | 556 |
592 } // namespace ui | 557 } // namespace ui |
OLD | NEW |