| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <deque> | 8 #include <deque> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 | 187 |
| 188 CancelCompositorLock(); | 188 CancelCompositorLock(); |
| 189 DCHECK(!compositor_lock_); | 189 DCHECK(!compositor_lock_); |
| 190 | 190 |
| 191 FOR_EACH_OBSERVER(CompositorObserver, observer_list_, | 191 FOR_EACH_OBSERVER(CompositorObserver, observer_list_, |
| 192 OnCompositingShuttingDown(this)); | 192 OnCompositingShuttingDown(this)); |
| 193 | 193 |
| 194 FOR_EACH_OBSERVER(CompositorAnimationObserver, animation_observer_list_, | 194 FOR_EACH_OBSERVER(CompositorAnimationObserver, animation_observer_list_, |
| 195 OnCompositingShuttingDown(this)); | 195 OnCompositingShuttingDown(this)); |
| 196 | 196 |
| 197 DCHECK(begin_frame_observer_list_.empty()); | |
| 198 | |
| 199 if (root_layer_) | 197 if (root_layer_) |
| 200 root_layer_->ResetCompositor(); | 198 root_layer_->ResetCompositor(); |
| 201 | 199 |
| 202 // Stop all outstanding draws before telling the ContextFactory to tear | 200 // Stop all outstanding draws before telling the ContextFactory to tear |
| 203 // down any contexts that the |host_| may rely upon. | 201 // down any contexts that the |host_| may rely upon. |
| 204 host_.reset(); | 202 host_.reset(); |
| 205 | 203 |
| 206 context_factory_->RemoveCompositor(this); | 204 context_factory_->RemoveCompositor(this); |
| 207 } | 205 } |
| 208 | 206 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 CompositorAnimationObserver* observer) { | 350 CompositorAnimationObserver* observer) { |
| 353 animation_observer_list_.RemoveObserver(observer); | 351 animation_observer_list_.RemoveObserver(observer); |
| 354 } | 352 } |
| 355 | 353 |
| 356 bool Compositor::HasAnimationObserver( | 354 bool Compositor::HasAnimationObserver( |
| 357 const CompositorAnimationObserver* observer) const { | 355 const CompositorAnimationObserver* observer) const { |
| 358 return animation_observer_list_.HasObserver(observer); | 356 return animation_observer_list_.HasObserver(observer); |
| 359 } | 357 } |
| 360 | 358 |
| 361 void Compositor::AddBeginFrameObserver(CompositorBeginFrameObserver* observer) { | 359 void Compositor::AddBeginFrameObserver(CompositorBeginFrameObserver* observer) { |
| 362 DCHECK(std::find(begin_frame_observer_list_.begin(), | 360 if (!begin_frame_observer_list_.might_have_observers()) |
| 363 begin_frame_observer_list_.end(), observer) == | 361 host_->SetChildrenNeedBeginFrames(true); |
| 364 begin_frame_observer_list_.end()); | |
| 365 | 362 |
| 366 if (begin_frame_observer_list_.empty()) | 363 begin_frame_observer_list_.AddObserver(observer); |
| 367 host_->SetChildrenNeedBeginFrames(true); | |
| 368 | 364 |
| 369 if (missed_begin_frame_args_.IsValid()) | 365 if (missed_begin_frame_args_.IsValid()) |
| 370 observer->OnSendBeginFrame(missed_begin_frame_args_); | 366 observer->OnSendBeginFrame(missed_begin_frame_args_); |
| 371 | |
| 372 begin_frame_observer_list_.push_back(observer); | |
| 373 } | 367 } |
| 374 | 368 |
| 375 void Compositor::RemoveBeginFrameObserver( | 369 void Compositor::RemoveBeginFrameObserver( |
| 376 CompositorBeginFrameObserver* observer) { | 370 CompositorBeginFrameObserver* observer) { |
| 377 auto it = std::find(begin_frame_observer_list_.begin(), | 371 begin_frame_observer_list_.RemoveObserver(observer); |
| 378 begin_frame_observer_list_.end(), observer); | |
| 379 DCHECK(it != begin_frame_observer_list_.end()); | |
| 380 begin_frame_observer_list_.erase(it); | |
| 381 | 372 |
| 382 if (begin_frame_observer_list_.empty()) { | 373 // As this call may take place while iterating over observers, unsubscription |
| 383 host_->SetChildrenNeedBeginFrames(false); | 374 // from |host_| is performed after iteration in |SendBeginFramesToChildren()|. |
| 384 missed_begin_frame_args_ = cc::BeginFrameArgs(); | |
| 385 } | |
| 386 } | 375 } |
| 387 | 376 |
| 388 void Compositor::BeginMainFrame(const cc::BeginFrameArgs& args) { | 377 void Compositor::BeginMainFrame(const cc::BeginFrameArgs& args) { |
| 389 FOR_EACH_OBSERVER(CompositorAnimationObserver, | 378 FOR_EACH_OBSERVER(CompositorAnimationObserver, |
| 390 animation_observer_list_, | 379 animation_observer_list_, |
| 391 OnAnimationStep(args.frame_time)); | 380 OnAnimationStep(args.frame_time)); |
| 392 if (animation_observer_list_.might_have_observers()) | 381 if (animation_observer_list_.might_have_observers()) |
| 393 host_->SetNeedsAnimate(); | 382 host_->SetNeedsAnimate(); |
| 394 } | 383 } |
| 395 | 384 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 OnCompositingStarted(this, start_time)); | 434 OnCompositingStarted(this, start_time)); |
| 446 } | 435 } |
| 447 | 436 |
| 448 void Compositor::DidAbortSwapBuffers() { | 437 void Compositor::DidAbortSwapBuffers() { |
| 449 FOR_EACH_OBSERVER(CompositorObserver, | 438 FOR_EACH_OBSERVER(CompositorObserver, |
| 450 observer_list_, | 439 observer_list_, |
| 451 OnCompositingAborted(this)); | 440 OnCompositingAborted(this)); |
| 452 } | 441 } |
| 453 | 442 |
| 454 void Compositor::SendBeginFramesToChildren(const cc::BeginFrameArgs& args) { | 443 void Compositor::SendBeginFramesToChildren(const cc::BeginFrameArgs& args) { |
| 455 for (auto observer : begin_frame_observer_list_) | 444 FOR_EACH_OBSERVER(CompositorBeginFrameObserver, begin_frame_observer_list_, |
| 456 observer->OnSendBeginFrame(args); | 445 OnSendBeginFrame(args)); |
| 446 |
| 447 // Unsubscription is performed here, after iteration, to handle the case where |
| 448 // the last BeginFrame observer is removed while iterating over the observers. |
| 449 if (!begin_frame_observer_list_.might_have_observers()) { |
| 450 host_->SetChildrenNeedBeginFrames(false); |
| 451 // Unsubscription should reset |missed_begin_frame_args_|, avoiding stale |
| 452 // BeginFrame dispatch when the next BeginFrame observer is added. |
| 453 missed_begin_frame_args_ = cc::BeginFrameArgs(); |
| 454 return; |
| 455 } |
| 457 | 456 |
| 458 missed_begin_frame_args_ = args; | 457 missed_begin_frame_args_ = args; |
| 459 missed_begin_frame_args_.type = cc::BeginFrameArgs::MISSED; | 458 missed_begin_frame_args_.type = cc::BeginFrameArgs::MISSED; |
| 460 } | 459 } |
| 461 | 460 |
| 462 const cc::LayerTreeDebugState& Compositor::GetLayerTreeDebugState() const { | 461 const cc::LayerTreeDebugState& Compositor::GetLayerTreeDebugState() const { |
| 463 return host_->debug_state(); | 462 return host_->debug_state(); |
| 464 } | 463 } |
| 465 | 464 |
| 466 void Compositor::SetLayerTreeDebugState( | 465 void Compositor::SetLayerTreeDebugState( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 491 observer_list_, | 490 observer_list_, |
| 492 OnCompositingLockStateChanged(this)); | 491 OnCompositingLockStateChanged(this)); |
| 493 } | 492 } |
| 494 | 493 |
| 495 void Compositor::CancelCompositorLock() { | 494 void Compositor::CancelCompositorLock() { |
| 496 if (compositor_lock_) | 495 if (compositor_lock_) |
| 497 compositor_lock_->CancelLock(); | 496 compositor_lock_->CancelLock(); |
| 498 } | 497 } |
| 499 | 498 |
| 500 } // namespace ui | 499 } // namespace ui |
| OLD | NEW |