 Chromium Code Reviews
 Chromium Code Reviews Issue 1414533003:
  Make ui::Compositor BeginFrame subscription robust  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 1414533003:
  Make ui::Compositor BeginFrame subscription robust  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| 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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 | 183 | 
| 184 CancelCompositorLock(); | 184 CancelCompositorLock(); | 
| 185 DCHECK(!compositor_lock_); | 185 DCHECK(!compositor_lock_); | 
| 186 | 186 | 
| 187 FOR_EACH_OBSERVER(CompositorObserver, observer_list_, | 187 FOR_EACH_OBSERVER(CompositorObserver, observer_list_, | 
| 188 OnCompositingShuttingDown(this)); | 188 OnCompositingShuttingDown(this)); | 
| 189 | 189 | 
| 190 FOR_EACH_OBSERVER(CompositorAnimationObserver, animation_observer_list_, | 190 FOR_EACH_OBSERVER(CompositorAnimationObserver, animation_observer_list_, | 
| 191 OnCompositingShuttingDown(this)); | 191 OnCompositingShuttingDown(this)); | 
| 192 | 192 | 
| 193 DCHECK(begin_frame_observer_list_.empty()); | |
| 194 | |
| 195 if (root_layer_) | 193 if (root_layer_) | 
| 196 root_layer_->ResetCompositor(); | 194 root_layer_->ResetCompositor(); | 
| 197 | 195 | 
| 198 // Stop all outstanding draws before telling the ContextFactory to tear | 196 // Stop all outstanding draws before telling the ContextFactory to tear | 
| 199 // down any contexts that the |host_| may rely upon. | 197 // down any contexts that the |host_| may rely upon. | 
| 200 host_.reset(); | 198 host_.reset(); | 
| 201 | 199 | 
| 202 context_factory_->RemoveCompositor(this); | 200 context_factory_->RemoveCompositor(this); | 
| 203 } | 201 } | 
| 204 | 202 | 
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 348 CompositorAnimationObserver* observer) { | 346 CompositorAnimationObserver* observer) { | 
| 349 animation_observer_list_.RemoveObserver(observer); | 347 animation_observer_list_.RemoveObserver(observer); | 
| 350 } | 348 } | 
| 351 | 349 | 
| 352 bool Compositor::HasAnimationObserver( | 350 bool Compositor::HasAnimationObserver( | 
| 353 const CompositorAnimationObserver* observer) const { | 351 const CompositorAnimationObserver* observer) const { | 
| 354 return animation_observer_list_.HasObserver(observer); | 352 return animation_observer_list_.HasObserver(observer); | 
| 355 } | 353 } | 
| 356 | 354 | 
| 357 void Compositor::AddBeginFrameObserver(CompositorBeginFrameObserver* observer) { | 355 void Compositor::AddBeginFrameObserver(CompositorBeginFrameObserver* observer) { | 
| 358 DCHECK(std::find(begin_frame_observer_list_.begin(), | 356 if (!begin_frame_observer_list_.might_have_observers()) | 
| 359 begin_frame_observer_list_.end(), observer) == | 357 host_->SetChildrenNeedBeginFrames(true); | 
| 360 begin_frame_observer_list_.end()); | |
| 361 | 358 | 
| 362 if (begin_frame_observer_list_.empty()) | 359 begin_frame_observer_list_.AddObserver(observer); | 
| 363 host_->SetChildrenNeedBeginFrames(true); | |
| 364 | 360 | 
| 365 if (missed_begin_frame_args_.IsValid()) | 361 if (missed_begin_frame_args_.IsValid()) | 
| 366 observer->OnSendBeginFrame(missed_begin_frame_args_); | 362 observer->OnSendBeginFrame(missed_begin_frame_args_); | 
| 367 | |
| 368 begin_frame_observer_list_.push_back(observer); | |
| 369 } | 363 } | 
| 370 | 364 | 
| 371 void Compositor::RemoveBeginFrameObserver( | 365 void Compositor::RemoveBeginFrameObserver( | 
| 372 CompositorBeginFrameObserver* observer) { | 366 CompositorBeginFrameObserver* observer) { | 
| 373 auto it = std::find(begin_frame_observer_list_.begin(), | 367 begin_frame_observer_list_.RemoveObserver(observer); | 
| 374 begin_frame_observer_list_.end(), observer); | |
| 375 DCHECK(it != begin_frame_observer_list_.end()); | |
| 376 begin_frame_observer_list_.erase(it); | |
| 377 | 368 | 
| 378 if (begin_frame_observer_list_.empty()) { | 369 if (!begin_frame_observer_list_.might_have_observers()) { | 
| 379 host_->SetChildrenNeedBeginFrames(false); | 370 host_->SetChildrenNeedBeginFrames(false); | 
| 
danakj
2015/10/21 20:23:51
What if might_have is true, but actually this was
 
jdduke (slow)
2015/10/21 20:48:12
Good call, we can check after iterating over the o
 | |
| 380 missed_begin_frame_args_ = cc::BeginFrameArgs(); | 371 missed_begin_frame_args_ = cc::BeginFrameArgs(); | 
| 381 } | 372 } | 
| 382 } | 373 } | 
| 383 | 374 | 
| 384 void Compositor::BeginMainFrame(const cc::BeginFrameArgs& args) { | 375 void Compositor::BeginMainFrame(const cc::BeginFrameArgs& args) { | 
| 385 FOR_EACH_OBSERVER(CompositorAnimationObserver, | 376 FOR_EACH_OBSERVER(CompositorAnimationObserver, | 
| 386 animation_observer_list_, | 377 animation_observer_list_, | 
| 387 OnAnimationStep(args.frame_time)); | 378 OnAnimationStep(args.frame_time)); | 
| 388 if (animation_observer_list_.might_have_observers()) | 379 if (animation_observer_list_.might_have_observers()) | 
| 389 host_->SetNeedsAnimate(); | 380 host_->SetNeedsAnimate(); | 
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 441 OnCompositingStarted(this, start_time)); | 432 OnCompositingStarted(this, start_time)); | 
| 442 } | 433 } | 
| 443 | 434 | 
| 444 void Compositor::DidAbortSwapBuffers() { | 435 void Compositor::DidAbortSwapBuffers() { | 
| 445 FOR_EACH_OBSERVER(CompositorObserver, | 436 FOR_EACH_OBSERVER(CompositorObserver, | 
| 446 observer_list_, | 437 observer_list_, | 
| 447 OnCompositingAborted(this)); | 438 OnCompositingAborted(this)); | 
| 448 } | 439 } | 
| 449 | 440 | 
| 450 void Compositor::SendBeginFramesToChildren(const cc::BeginFrameArgs& args) { | 441 void Compositor::SendBeginFramesToChildren(const cc::BeginFrameArgs& args) { | 
| 451 for (auto observer : begin_frame_observer_list_) | 442 FOR_EACH_OBSERVER(CompositorBeginFrameObserver, begin_frame_observer_list_, | 
| 452 observer->OnSendBeginFrame(args); | 443 OnSendBeginFrame(args)); | 
| 453 | 444 | 
| 454 missed_begin_frame_args_ = args; | 445 missed_begin_frame_args_ = args; | 
| 455 missed_begin_frame_args_.type = cc::BeginFrameArgs::MISSED; | 446 missed_begin_frame_args_.type = cc::BeginFrameArgs::MISSED; | 
| 456 } | 447 } | 
| 457 | 448 | 
| 458 const cc::LayerTreeDebugState& Compositor::GetLayerTreeDebugState() const { | 449 const cc::LayerTreeDebugState& Compositor::GetLayerTreeDebugState() const { | 
| 459 return host_->debug_state(); | 450 return host_->debug_state(); | 
| 460 } | 451 } | 
| 461 | 452 | 
| 462 void Compositor::SetLayerTreeDebugState( | 453 void Compositor::SetLayerTreeDebugState( | 
| (...skipping 24 matching lines...) Expand all Loading... | |
| 487 observer_list_, | 478 observer_list_, | 
| 488 OnCompositingLockStateChanged(this)); | 479 OnCompositingLockStateChanged(this)); | 
| 489 } | 480 } | 
| 490 | 481 | 
| 491 void Compositor::CancelCompositorLock() { | 482 void Compositor::CancelCompositorLock() { | 
| 492 if (compositor_lock_) | 483 if (compositor_lock_) | 
| 493 compositor_lock_->CancelLock(); | 484 compositor_lock_->CancelLock(); | 
| 494 } | 485 } | 
| 495 | 486 | 
| 496 } // namespace ui | 487 } // namespace ui | 
| OLD | NEW |