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...) 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_.empty()); |
| 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...) 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(CompositorBeginFrameObserver* observer) { |
| 289 DCHECK(std::find(begin_frame_observer_list_.begin(), |
| 290 begin_frame_observer_list_.end(), observer) == |
| 291 begin_frame_observer_list_.end()); |
| 292 |
| 293 if (begin_frame_observer_list_.empty()) |
| 294 host_->SetChildrenNeedBeginFrames(true); |
| 295 |
| 296 if (missed_begin_frame_args_.IsValid()) |
| 297 observer->OnSendBeginFrame(missed_begin_frame_args_); |
| 298 |
| 299 begin_frame_observer_list_.push_back(observer); |
| 300 } |
| 301 |
| 302 void Compositor::RemoveBeginFrameObserver( |
| 303 CompositorBeginFrameObserver* observer) { |
| 304 auto it = std::find(begin_frame_observer_list_.begin(), |
| 305 begin_frame_observer_list_.end(), observer); |
| 306 DCHECK(it != begin_frame_observer_list_.end()); |
| 307 begin_frame_observer_list_.erase(it); |
| 308 |
| 309 if (begin_frame_observer_list_.empty()) { |
| 310 host_->SetChildrenNeedBeginFrames(false); |
| 311 missed_begin_frame_args_ = cc::BeginFrameArgs(); |
| 312 } |
| 313 } |
| 314 |
286 void Compositor::BeginMainFrame(const cc::BeginFrameArgs& args) { | 315 void Compositor::BeginMainFrame(const cc::BeginFrameArgs& args) { |
287 FOR_EACH_OBSERVER(CompositorAnimationObserver, | 316 FOR_EACH_OBSERVER(CompositorAnimationObserver, |
288 animation_observer_list_, | 317 animation_observer_list_, |
289 OnAnimationStep(args.frame_time)); | 318 OnAnimationStep(args.frame_time)); |
290 if (animation_observer_list_.might_have_observers()) | 319 if (animation_observer_list_.might_have_observers()) |
291 host_->SetNeedsAnimate(); | 320 host_->SetNeedsAnimate(); |
292 } | 321 } |
293 | 322 |
294 void Compositor::BeginMainFrameNotExpectedSoon() { | 323 void Compositor::BeginMainFrameNotExpectedSoon() { |
295 } | 324 } |
(...skipping 42 matching lines...) Loading... |
338 FOR_EACH_OBSERVER(CompositorObserver, observer_list_, | 367 FOR_EACH_OBSERVER(CompositorObserver, observer_list_, |
339 OnCompositingStarted(this, start_time)); | 368 OnCompositingStarted(this, start_time)); |
340 } | 369 } |
341 | 370 |
342 void Compositor::DidAbortSwapBuffers() { | 371 void Compositor::DidAbortSwapBuffers() { |
343 FOR_EACH_OBSERVER(CompositorObserver, | 372 FOR_EACH_OBSERVER(CompositorObserver, |
344 observer_list_, | 373 observer_list_, |
345 OnCompositingAborted(this)); | 374 OnCompositingAborted(this)); |
346 } | 375 } |
347 | 376 |
| 377 void Compositor::SendBeginFramesToChildren(const cc::BeginFrameArgs& args) { |
| 378 for (auto observer : begin_frame_observer_list_) |
| 379 observer->OnSendBeginFrame(args); |
| 380 |
| 381 missed_begin_frame_args_ = args; |
| 382 missed_begin_frame_args_.type = cc::BeginFrameArgs::MISSED; |
| 383 } |
| 384 |
348 const cc::LayerTreeDebugState& Compositor::GetLayerTreeDebugState() const { | 385 const cc::LayerTreeDebugState& Compositor::GetLayerTreeDebugState() const { |
349 return host_->debug_state(); | 386 return host_->debug_state(); |
350 } | 387 } |
351 | 388 |
352 void Compositor::SetLayerTreeDebugState( | 389 void Compositor::SetLayerTreeDebugState( |
353 const cc::LayerTreeDebugState& debug_state) { | 390 const cc::LayerTreeDebugState& debug_state) { |
354 host_->SetDebugState(debug_state); | 391 host_->SetDebugState(debug_state); |
355 } | 392 } |
356 | 393 |
357 const cc::RendererSettings& Compositor::GetRendererSettings() const { | 394 const cc::RendererSettings& Compositor::GetRendererSettings() const { |
(...skipping 19 matching lines...) Loading... |
377 observer_list_, | 414 observer_list_, |
378 OnCompositingLockStateChanged(this)); | 415 OnCompositingLockStateChanged(this)); |
379 } | 416 } |
380 | 417 |
381 void Compositor::CancelCompositorLock() { | 418 void Compositor::CancelCompositorLock() { |
382 if (compositor_lock_) | 419 if (compositor_lock_) |
383 compositor_lock_->CancelLock(); | 420 compositor_lock_->CancelLock(); |
384 } | 421 } |
385 | 422 |
386 } // namespace ui | 423 } // namespace ui |
OLD | NEW |