| 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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 | 238 |
| 239 if (animation_timeline_) | 239 if (animation_timeline_) |
| 240 host_->animation_host()->RemoveAnimationTimeline(animation_timeline_.get()); | 240 host_->animation_host()->RemoveAnimationTimeline(animation_timeline_.get()); |
| 241 | 241 |
| 242 // Stop all outstanding draws before telling the ContextFactory to tear | 242 // Stop all outstanding draws before telling the ContextFactory to tear |
| 243 // down any contexts that the |host_| may rely upon. | 243 // down any contexts that the |host_| may rely upon. |
| 244 host_.reset(); | 244 host_.reset(); |
| 245 | 245 |
| 246 context_factory_->RemoveCompositor(this); | 246 context_factory_->RemoveCompositor(this); |
| 247 if (context_factory_->GetSurfaceManager()) { | 247 if (context_factory_->GetSurfaceManager()) { |
| 248 for (auto& client : surface_clients_) { |
| 249 if (client.second) { |
| 250 context_factory_->GetSurfaceManager() |
| 251 ->UnregisterSurfaceNamespaceHierarchy(client.second, client.first); |
| 252 } |
| 253 } |
| 248 context_factory_->GetSurfaceManager()->InvalidateSurfaceClientId( | 254 context_factory_->GetSurfaceManager()->InvalidateSurfaceClientId( |
| 249 surface_id_allocator_->client_id()); | 255 surface_id_allocator_->client_id()); |
| 250 } | 256 } |
| 251 } | 257 } |
| 252 | 258 |
| 259 void Compositor::AddSurfaceClient(uint32_t client_id) { |
| 260 // We don't give the client a parent until the ui::Compositor has an |
| 261 // OutputSurface. |
| 262 uint32_t parent_client_id = 0; |
| 263 if (host_->has_output_surface()) { |
| 264 parent_client_id = surface_id_allocator_->client_id(); |
| 265 context_factory_->GetSurfaceManager()->RegisterSurfaceNamespaceHierarchy( |
| 266 parent_client_id, client_id); |
| 267 } |
| 268 surface_clients_[client_id] = parent_client_id; |
| 269 } |
| 270 |
| 271 void Compositor::RemoveSurfaceClient(uint32_t client_id) { |
| 272 auto it = surface_clients_.find(client_id); |
| 273 DCHECK(it != surface_clients_.end()); |
| 274 if (host_->has_output_surface()) { |
| 275 context_factory_->GetSurfaceManager()->UnregisterSurfaceNamespaceHierarchy( |
| 276 it->second, client_id); |
| 277 } |
| 278 surface_clients_.erase(it); |
| 279 } |
| 280 |
| 253 void Compositor::SetOutputSurface( | 281 void Compositor::SetOutputSurface( |
| 254 std::unique_ptr<cc::OutputSurface> output_surface) { | 282 std::unique_ptr<cc::OutputSurface> output_surface) { |
| 255 output_surface_requested_ = false; | 283 output_surface_requested_ = false; |
| 256 host_->SetOutputSurface(std::move(output_surface)); | 284 host_->SetOutputSurface(std::move(output_surface)); |
| 285 // ui::Compositor uses a SingleThreadProxy and so BindToClient will be called |
| 286 // above and SurfaceManager will be made aware of the OutputSurface's client |
| 287 // ID. |
| 288 for (auto& client : surface_clients_) { |
| 289 if (client.second == surface_id_allocator_->client_id()) |
| 290 continue; |
| 291 // If a client already has a parent, then we unregister the existing parent. |
| 292 if (client.second) { |
| 293 context_factory_->GetSurfaceManager() |
| 294 ->UnregisterSurfaceNamespaceHierarchy(client.second, client.first); |
| 295 } |
| 296 context_factory_->GetSurfaceManager()->RegisterSurfaceNamespaceHierarchy( |
| 297 surface_id_allocator_->client_id(), client.first); |
| 298 client.second = surface_id_allocator_->client_id(); |
| 299 } |
| 257 } | 300 } |
| 258 | 301 |
| 259 void Compositor::ScheduleDraw() { | 302 void Compositor::ScheduleDraw() { |
| 260 host_->SetNeedsCommit(); | 303 host_->SetNeedsCommit(); |
| 261 } | 304 } |
| 262 | 305 |
| 263 void Compositor::SetRootLayer(Layer* root_layer) { | 306 void Compositor::SetRootLayer(Layer* root_layer) { |
| 264 if (root_layer_ == root_layer) | 307 if (root_layer_ == root_layer) |
| 265 return; | 308 return; |
| 266 if (root_layer_) | 309 if (root_layer_) |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 // This function should only get called once. | 399 // This function should only get called once. |
| 357 DCHECK(!widget_valid_); | 400 DCHECK(!widget_valid_); |
| 358 widget_ = widget; | 401 widget_ = widget; |
| 359 widget_valid_ = true; | 402 widget_valid_ = true; |
| 360 if (output_surface_requested_) | 403 if (output_surface_requested_) |
| 361 context_factory_->CreateOutputSurface(weak_ptr_factory_.GetWeakPtr()); | 404 context_factory_->CreateOutputSurface(weak_ptr_factory_.GetWeakPtr()); |
| 362 } | 405 } |
| 363 | 406 |
| 364 gfx::AcceleratedWidget Compositor::ReleaseAcceleratedWidget() { | 407 gfx::AcceleratedWidget Compositor::ReleaseAcceleratedWidget() { |
| 365 DCHECK(!IsVisible()); | 408 DCHECK(!IsVisible()); |
| 366 if (!host_->output_surface_lost()) | 409 if (!host_->output_surface_lost()) { |
| 367 host_->ReleaseOutputSurface(); | 410 host_->ReleaseOutputSurface(); |
| 411 for (auto& client : surface_clients_) { |
| 412 context_factory_->GetSurfaceManager() |
| 413 ->UnregisterSurfaceNamespaceHierarchy(client.second, client.first); |
| 414 client.second = 0; |
| 415 } |
| 416 } |
| 368 context_factory_->RemoveCompositor(this); | 417 context_factory_->RemoveCompositor(this); |
| 369 widget_valid_ = false; | 418 widget_valid_ = false; |
| 370 gfx::AcceleratedWidget widget = widget_; | 419 gfx::AcceleratedWidget widget = widget_; |
| 371 widget_ = gfx::kNullAcceleratedWidget; | 420 widget_ = gfx::kNullAcceleratedWidget; |
| 372 return widget; | 421 return widget; |
| 373 } | 422 } |
| 374 | 423 |
| 375 gfx::AcceleratedWidget Compositor::widget() const { | 424 gfx::AcceleratedWidget Compositor::widget() const { |
| 376 DCHECK(widget_valid_); | 425 DCHECK(widget_valid_); |
| 377 return widget_; | 426 return widget_; |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 observer_list_, | 559 observer_list_, |
| 511 OnCompositingLockStateChanged(this)); | 560 OnCompositingLockStateChanged(this)); |
| 512 } | 561 } |
| 513 | 562 |
| 514 void Compositor::CancelCompositorLock() { | 563 void Compositor::CancelCompositorLock() { |
| 515 if (compositor_lock_) | 564 if (compositor_lock_) |
| 516 compositor_lock_->CancelLock(); | 565 compositor_lock_->CancelLock(); |
| 517 } | 566 } |
| 518 | 567 |
| 519 } // namespace ui | 568 } // namespace ui |
| OLD | NEW |