Chromium Code Reviews| 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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 | 149 |
| 150 Compositor::~Compositor() { | 150 Compositor::~Compositor() { |
| 151 TRACE_EVENT0("shutdown", "Compositor::destructor"); | 151 TRACE_EVENT0("shutdown", "Compositor::destructor"); |
| 152 | 152 |
| 153 CancelCompositorLock(); | 153 CancelCompositorLock(); |
| 154 DCHECK(!compositor_lock_); | 154 DCHECK(!compositor_lock_); |
| 155 | 155 |
| 156 FOR_EACH_OBSERVER(CompositorObserver, observer_list_, | 156 FOR_EACH_OBSERVER(CompositorObserver, observer_list_, |
| 157 OnCompositingShuttingDown(this)); | 157 OnCompositingShuttingDown(this)); |
| 158 | 158 |
| 159 DCHECK(!begin_frame_observer_list_.might_have_observers()); | |
| 160 | |
| 159 if (root_layer_) | 161 if (root_layer_) |
| 160 root_layer_->SetCompositor(NULL); | 162 root_layer_->SetCompositor(NULL); |
| 161 | 163 |
| 162 // Stop all outstanding draws before telling the ContextFactory to tear | 164 // Stop all outstanding draws before telling the ContextFactory to tear |
| 163 // down any contexts that the |host_| may rely upon. | 165 // down any contexts that the |host_| may rely upon. |
| 164 host_.reset(); | 166 host_.reset(); |
| 165 | 167 |
| 166 context_factory_->RemoveCompositor(this); | 168 context_factory_->RemoveCompositor(this); |
| 167 } | 169 } |
| 168 | 170 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 276 void Compositor::RemoveAnimationObserver( | 278 void Compositor::RemoveAnimationObserver( |
| 277 CompositorAnimationObserver* observer) { | 279 CompositorAnimationObserver* observer) { |
| 278 animation_observer_list_.RemoveObserver(observer); | 280 animation_observer_list_.RemoveObserver(observer); |
| 279 } | 281 } |
| 280 | 282 |
| 281 bool Compositor::HasAnimationObserver( | 283 bool Compositor::HasAnimationObserver( |
| 282 const CompositorAnimationObserver* observer) const { | 284 const CompositorAnimationObserver* observer) const { |
| 283 return animation_observer_list_.HasObserver(observer); | 285 return animation_observer_list_.HasObserver(observer); |
| 284 } | 286 } |
| 285 | 287 |
| 288 void Compositor::AddBeginFrameObserver( | |
| 289 CompositorBeginFrameObserver* observer, | |
| 290 const cc::BeginFrameArgs& last_begin_frame_args_sent_to_observer) { | |
| 291 // If |last_begin_frame_args_| is still effective, send it to the new | |
| 292 // |observer| immediately. | |
| 293 if (last_begin_frame_args_sent_to_observer.frame_time != | |
| 294 missed_begin_frame_args_.frame_time) { | |
| 295 observer->OnSendBeginFrame(missed_begin_frame_args_); | |
| 296 } | |
| 297 | |
| 298 if (!begin_frame_observer_list_.might_have_observers()) | |
|
danakj
2015/03/17 18:56:45
From the name "might have", this feels like a bug
brianderson
2015/03/17 22:29:32
Looks like might_have_observers() can return the i
simonhong
2015/03/19 15:48:46
I used it to check whether the list is empty or no
| |
| 299 host_->SetChildrenNeedBeginFrames(true); | |
| 300 begin_frame_observer_list_.AddObserver(observer); | |
| 301 } | |
| 302 | |
| 303 void Compositor::RemoveBeginFrameObserver( | |
| 304 CompositorBeginFrameObserver* observer) { | |
| 305 DCHECK(begin_frame_observer_list_.HasObserver(observer)); | |
| 306 begin_frame_observer_list_.RemoveObserver(observer); | |
| 307 | |
| 308 if (!begin_frame_observer_list_.might_have_observers()) | |
|
danakj
2015/03/17 18:56:45
Dittos
| |
| 309 host_->SetChildrenNeedBeginFrames(false); | |
| 310 } | |
| 311 | |
| 286 void Compositor::BeginMainFrame(const cc::BeginFrameArgs& args) { | 312 void Compositor::BeginMainFrame(const cc::BeginFrameArgs& args) { |
| 287 FOR_EACH_OBSERVER(CompositorAnimationObserver, | 313 FOR_EACH_OBSERVER(CompositorAnimationObserver, |
| 288 animation_observer_list_, | 314 animation_observer_list_, |
| 289 OnAnimationStep(args.frame_time)); | 315 OnAnimationStep(args.frame_time)); |
| 290 if (animation_observer_list_.might_have_observers()) | 316 if (animation_observer_list_.might_have_observers()) |
| 291 host_->SetNeedsAnimate(); | 317 host_->SetNeedsAnimate(); |
| 292 } | 318 } |
| 293 | 319 |
| 294 void Compositor::BeginMainFrameNotExpectedSoon() { | 320 void Compositor::BeginMainFrameNotExpectedSoon() { |
| 295 } | 321 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 338 FOR_EACH_OBSERVER(CompositorObserver, observer_list_, | 364 FOR_EACH_OBSERVER(CompositorObserver, observer_list_, |
| 339 OnCompositingStarted(this, start_time)); | 365 OnCompositingStarted(this, start_time)); |
| 340 } | 366 } |
| 341 | 367 |
| 342 void Compositor::DidAbortSwapBuffers() { | 368 void Compositor::DidAbortSwapBuffers() { |
| 343 FOR_EACH_OBSERVER(CompositorObserver, | 369 FOR_EACH_OBSERVER(CompositorObserver, |
| 344 observer_list_, | 370 observer_list_, |
| 345 OnCompositingAborted(this)); | 371 OnCompositingAborted(this)); |
| 346 } | 372 } |
| 347 | 373 |
| 374 void Compositor::SendBeginFramesToChildren(const cc::BeginFrameArgs& args) { | |
| 375 FOR_EACH_OBSERVER(CompositorBeginFrameObserver, | |
| 376 begin_frame_observer_list_, | |
| 377 OnSendBeginFrame(args)); | |
| 378 missed_begin_frame_args_ = args; | |
| 379 missed_begin_frame_args_.type = cc::BeginFrameArgs::MISSED; | |
| 380 } | |
| 381 | |
| 348 const cc::LayerTreeDebugState& Compositor::GetLayerTreeDebugState() const { | 382 const cc::LayerTreeDebugState& Compositor::GetLayerTreeDebugState() const { |
| 349 return host_->debug_state(); | 383 return host_->debug_state(); |
| 350 } | 384 } |
| 351 | 385 |
| 352 void Compositor::SetLayerTreeDebugState( | 386 void Compositor::SetLayerTreeDebugState( |
| 353 const cc::LayerTreeDebugState& debug_state) { | 387 const cc::LayerTreeDebugState& debug_state) { |
| 354 host_->SetDebugState(debug_state); | 388 host_->SetDebugState(debug_state); |
| 355 } | 389 } |
| 356 | 390 |
| 357 const cc::RendererSettings& Compositor::GetRendererSettings() const { | 391 const cc::RendererSettings& Compositor::GetRendererSettings() const { |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 377 observer_list_, | 411 observer_list_, |
| 378 OnCompositingLockStateChanged(this)); | 412 OnCompositingLockStateChanged(this)); |
| 379 } | 413 } |
| 380 | 414 |
| 381 void Compositor::CancelCompositorLock() { | 415 void Compositor::CancelCompositorLock() { |
| 382 if (compositor_lock_) | 416 if (compositor_lock_) |
| 383 compositor_lock_->CancelLock(); | 417 compositor_lock_->CancelLock(); |
| 384 } | 418 } |
| 385 | 419 |
| 386 } // namespace ui | 420 } // namespace ui |
| OLD | NEW |