 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 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()); | |
| 
brianderson
2015/10/21 23:12:59
Why is this no longer valid?
 
jdduke (slow)
2015/10/21 23:46:16
ObserverList does that for us (the second "true" a
 | |
| 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()) | 
| 
brianderson
2015/10/21 23:12:59
Any way to keep this check?
 
jdduke (slow)
2015/10/21 23:46:16
ObserverList also does that for us.
 | |
| 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 if (!begin_frame_observer_list_.might_have_observers()) { | 
| 
danakj
2015/10/22 18:35:59
Do you need to do this here still, since it is don
 
jdduke (slow)
2015/10/22 18:39:00
I considered that, I suppose it depends on the sem
 | |
| 383 host_->SetChildrenNeedBeginFrames(false); | 374 host_->SetChildrenNeedBeginFrames(false); | 
| 384 missed_begin_frame_args_ = cc::BeginFrameArgs(); | 375 missed_begin_frame_args_ = cc::BeginFrameArgs(); | 
| 385 } | 376 } | 
| 386 } | 377 } | 
| 387 | 378 | 
| 388 void Compositor::BeginMainFrame(const cc::BeginFrameArgs& args) { | 379 void Compositor::BeginMainFrame(const cc::BeginFrameArgs& args) { | 
| 389 FOR_EACH_OBSERVER(CompositorAnimationObserver, | 380 FOR_EACH_OBSERVER(CompositorAnimationObserver, | 
| 390 animation_observer_list_, | 381 animation_observer_list_, | 
| 391 OnAnimationStep(args.frame_time)); | 382 OnAnimationStep(args.frame_time)); | 
| 392 if (animation_observer_list_.might_have_observers()) | 383 if (animation_observer_list_.might_have_observers()) | 
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 445 OnCompositingStarted(this, start_time)); | 436 OnCompositingStarted(this, start_time)); | 
| 446 } | 437 } | 
| 447 | 438 | 
| 448 void Compositor::DidAbortSwapBuffers() { | 439 void Compositor::DidAbortSwapBuffers() { | 
| 449 FOR_EACH_OBSERVER(CompositorObserver, | 440 FOR_EACH_OBSERVER(CompositorObserver, | 
| 450 observer_list_, | 441 observer_list_, | 
| 451 OnCompositingAborted(this)); | 442 OnCompositingAborted(this)); | 
| 452 } | 443 } | 
| 453 | 444 | 
| 454 void Compositor::SendBeginFramesToChildren(const cc::BeginFrameArgs& args) { | 445 void Compositor::SendBeginFramesToChildren(const cc::BeginFrameArgs& args) { | 
| 455 for (auto observer : begin_frame_observer_list_) | 446 FOR_EACH_OBSERVER(CompositorBeginFrameObserver, begin_frame_observer_list_, | 
| 456 observer->OnSendBeginFrame(args); | 447 OnSendBeginFrame(args)); | 
| 448 | |
| 449 if (!begin_frame_observer_list_.might_have_observers()) { | |
| 450 host_->SetChildrenNeedBeginFrames(false); | |
| 451 missed_begin_frame_args_ = cc::BeginFrameArgs(); | |
| 452 return; | |
| 453 } | |
| 457 | 454 | 
| 458 missed_begin_frame_args_ = args; | 455 missed_begin_frame_args_ = args; | 
| 459 missed_begin_frame_args_.type = cc::BeginFrameArgs::MISSED; | 456 missed_begin_frame_args_.type = cc::BeginFrameArgs::MISSED; | 
| 460 } | 457 } | 
| 461 | 458 | 
| 462 const cc::LayerTreeDebugState& Compositor::GetLayerTreeDebugState() const { | 459 const cc::LayerTreeDebugState& Compositor::GetLayerTreeDebugState() const { | 
| 463 return host_->debug_state(); | 460 return host_->debug_state(); | 
| 464 } | 461 } | 
| 465 | 462 | 
| 466 void Compositor::SetLayerTreeDebugState( | 463 void Compositor::SetLayerTreeDebugState( | 
| (...skipping 24 matching lines...) Expand all Loading... | |
| 491 observer_list_, | 488 observer_list_, | 
| 492 OnCompositingLockStateChanged(this)); | 489 OnCompositingLockStateChanged(this)); | 
| 493 } | 490 } | 
| 494 | 491 | 
| 495 void Compositor::CancelCompositorLock() { | 492 void Compositor::CancelCompositorLock() { | 
| 496 if (compositor_lock_) | 493 if (compositor_lock_) | 
| 497 compositor_lock_->CancelLock(); | 494 compositor_lock_->CancelLock(); | 
| 498 } | 495 } | 
| 499 | 496 | 
| 500 } // namespace ui | 497 } // namespace ui | 
| OLD | NEW |