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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 // When impl-side painting is enabled, this will ensure PictureLayers always | 87 // When impl-side painting is enabled, this will ensure PictureLayers always |
88 // can have LCD text, to match the previous behaviour with ContentLayers, | 88 // can have LCD text, to match the previous behaviour with ContentLayers, |
89 // where LCD-not-allowed notifications were ignored. | 89 // where LCD-not-allowed notifications were ignored. |
90 settings.layers_always_allowed_lcd_text = true; | 90 settings.layers_always_allowed_lcd_text = true; |
91 settings.renderer_settings.refresh_rate = | 91 settings.renderer_settings.refresh_rate = |
92 context_factory_->DoesCreateTestContexts() ? kTestRefreshRate | 92 context_factory_->DoesCreateTestContexts() ? kTestRefreshRate |
93 : kDefaultRefreshRate; | 93 : kDefaultRefreshRate; |
94 settings.main_frame_before_activation_enabled = false; | 94 settings.main_frame_before_activation_enabled = false; |
95 settings.throttle_frame_production = | 95 settings.throttle_frame_production = |
96 !command_line->HasSwitch(switches::kDisableGpuVsync); | 96 !command_line->HasSwitch(switches::kDisableGpuVsync); |
| 97 settings.forward_begin_frames_to_children = |
| 98 command_line->HasSwitch(cc::switches::kEnableBeginFrameScheduling); |
97 #if !defined(OS_MACOSX) | 99 #if !defined(OS_MACOSX) |
98 settings.renderer_settings.partial_swap_enabled = | 100 settings.renderer_settings.partial_swap_enabled = |
99 !command_line->HasSwitch(cc::switches::kUIDisablePartialSwap); | 101 !command_line->HasSwitch(cc::switches::kUIDisablePartialSwap); |
100 #endif | 102 #endif |
101 #if defined(OS_CHROMEOS) | 103 #if defined(OS_CHROMEOS) |
102 settings.per_tile_painting_enabled = true; | 104 settings.per_tile_painting_enabled = true; |
103 #endif | 105 #endif |
104 #if defined(OS_WIN) | 106 #if defined(OS_WIN) |
105 settings.disable_hi_res_timer_tasks_on_battery = | 107 settings.disable_hi_res_timer_tasks_on_battery = |
106 !context_factory_->DoesCreateTestContexts(); | 108 !context_factory_->DoesCreateTestContexts(); |
(...skipping 23 matching lines...) Expand all Loading... |
130 command_line->HasSwitch(cc::switches::kUIShowNonOccludingRects); | 132 command_line->HasSwitch(cc::switches::kUIShowNonOccludingRects); |
131 | 133 |
132 settings.initial_debug_state.SetRecordRenderingStats( | 134 settings.initial_debug_state.SetRecordRenderingStats( |
133 command_line->HasSwitch(cc::switches::kEnableGpuBenchmarking)); | 135 command_line->HasSwitch(cc::switches::kEnableGpuBenchmarking)); |
134 | 136 |
135 settings.impl_side_painting = IsUIImplSidePaintingEnabled(); | 137 settings.impl_side_painting = IsUIImplSidePaintingEnabled(); |
136 settings.use_zero_copy = IsUIZeroCopyEnabled(); | 138 settings.use_zero_copy = IsUIZeroCopyEnabled(); |
137 | 139 |
138 base::TimeTicks before_create = base::TimeTicks::Now(); | 140 base::TimeTicks before_create = base::TimeTicks::Now(); |
139 if (compositor_thread_loop_.get()) { | 141 if (compositor_thread_loop_.get()) { |
| 142 // Unified BeginFrame scheduling shouldn't be enabled with threaded |
| 143 // compositing. |
| 144 DCHECK(!settings.forward_begin_frames_to_children); |
140 host_ = cc::LayerTreeHost::CreateThreaded( | 145 host_ = cc::LayerTreeHost::CreateThreaded( |
141 this, | 146 this, |
142 context_factory_->GetSharedBitmapManager(), | 147 context_factory_->GetSharedBitmapManager(), |
143 context_factory_->GetGpuMemoryBufferManager(), | 148 context_factory_->GetGpuMemoryBufferManager(), |
144 settings, | 149 settings, |
145 task_runner_, | 150 task_runner_, |
146 compositor_thread_loop_, | 151 compositor_thread_loop_, |
147 nullptr); | 152 nullptr); |
148 } else { | 153 } else { |
149 host_ = cc::LayerTreeHost::CreateSingleThreaded( | 154 host_ = cc::LayerTreeHost::CreateSingleThreaded( |
(...skipping 11 matching lines...) Expand all Loading... |
161 host_->set_surface_id_namespace(surface_id_allocator_->id_namespace()); | 166 host_->set_surface_id_namespace(surface_id_allocator_->id_namespace()); |
162 host_->SetLayerTreeHostClientReady(); | 167 host_->SetLayerTreeHostClientReady(); |
163 } | 168 } |
164 | 169 |
165 Compositor::~Compositor() { | 170 Compositor::~Compositor() { |
166 TRACE_EVENT0("shutdown", "Compositor::destructor"); | 171 TRACE_EVENT0("shutdown", "Compositor::destructor"); |
167 | 172 |
168 CancelCompositorLock(); | 173 CancelCompositorLock(); |
169 DCHECK(!compositor_lock_); | 174 DCHECK(!compositor_lock_); |
170 | 175 |
| 176 DCHECK(!begin_frame_observer_list_.might_have_observers()); |
| 177 |
171 if (root_layer_) | 178 if (root_layer_) |
172 root_layer_->SetCompositor(NULL); | 179 root_layer_->SetCompositor(NULL); |
173 | 180 |
174 // Stop all outstanding draws before telling the ContextFactory to tear | 181 // Stop all outstanding draws before telling the ContextFactory to tear |
175 // down any contexts that the |host_| may rely upon. | 182 // down any contexts that the |host_| may rely upon. |
176 host_.reset(); | 183 host_.reset(); |
177 | 184 |
178 context_factory_->RemoveCompositor(this); | 185 context_factory_->RemoveCompositor(this); |
179 } | 186 } |
180 | 187 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 void Compositor::RemoveAnimationObserver( | 302 void Compositor::RemoveAnimationObserver( |
296 CompositorAnimationObserver* observer) { | 303 CompositorAnimationObserver* observer) { |
297 animation_observer_list_.RemoveObserver(observer); | 304 animation_observer_list_.RemoveObserver(observer); |
298 } | 305 } |
299 | 306 |
300 bool Compositor::HasAnimationObserver( | 307 bool Compositor::HasAnimationObserver( |
301 const CompositorAnimationObserver* observer) const { | 308 const CompositorAnimationObserver* observer) const { |
302 return animation_observer_list_.HasObserver(observer); | 309 return animation_observer_list_.HasObserver(observer); |
303 } | 310 } |
304 | 311 |
| 312 void Compositor::AddBeginFrameObserver( |
| 313 CompositorBeginFrameObserver* observer, |
| 314 const cc::BeginFrameArgs& last_begin_frame_args_sent_to_observer) { |
| 315 // If |last_begin_frame_args_| is still effective, send it to the new |
| 316 // |observer| immediately. |
| 317 if (!last_begin_frame_args_sent_to_observer.deadline.is_null() && |
| 318 last_begin_frame_args_sent_to_observer != missed_begin_frame_args_) { |
| 319 observer->OnSendBeginFrame(missed_begin_frame_args_); |
| 320 } |
| 321 |
| 322 if (!begin_frame_observer_list_.might_have_observers()) |
| 323 SetChildrenNeedBeginFrames(true); |
| 324 begin_frame_observer_list_.AddObserver(observer); |
| 325 } |
| 326 |
| 327 void Compositor::RemoveBeginFrameObserver( |
| 328 CompositorBeginFrameObserver* observer) { |
| 329 DCHECK(begin_frame_observer_list_.HasObserver(observer)); |
| 330 begin_frame_observer_list_.RemoveObserver(observer); |
| 331 |
| 332 if (!begin_frame_observer_list_.might_have_observers()) |
| 333 SetChildrenNeedBeginFrames(false); |
| 334 } |
| 335 |
305 void Compositor::BeginMainFrame(const cc::BeginFrameArgs& args) { | 336 void Compositor::BeginMainFrame(const cc::BeginFrameArgs& args) { |
306 FOR_EACH_OBSERVER(CompositorAnimationObserver, | 337 FOR_EACH_OBSERVER(CompositorAnimationObserver, |
307 animation_observer_list_, | 338 animation_observer_list_, |
308 OnAnimationStep(args.frame_time)); | 339 OnAnimationStep(args.frame_time)); |
309 if (animation_observer_list_.might_have_observers()) | 340 if (animation_observer_list_.might_have_observers()) |
310 host_->SetNeedsAnimate(); | 341 host_->SetNeedsAnimate(); |
311 } | 342 } |
312 | 343 |
313 void Compositor::Layout() { | 344 void Compositor::Layout() { |
314 // We're sending damage that will be addressed during this composite | 345 // We're sending damage that will be addressed during this composite |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 FOR_EACH_OBSERVER(CompositorObserver, observer_list_, | 383 FOR_EACH_OBSERVER(CompositorObserver, observer_list_, |
353 OnCompositingStarted(this, start_time)); | 384 OnCompositingStarted(this, start_time)); |
354 } | 385 } |
355 | 386 |
356 void Compositor::DidAbortSwapBuffers() { | 387 void Compositor::DidAbortSwapBuffers() { |
357 FOR_EACH_OBSERVER(CompositorObserver, | 388 FOR_EACH_OBSERVER(CompositorObserver, |
358 observer_list_, | 389 observer_list_, |
359 OnCompositingAborted(this)); | 390 OnCompositingAborted(this)); |
360 } | 391 } |
361 | 392 |
| 393 void Compositor::SendBeginFramesToChildren(const cc::BeginFrameArgs& args) { |
| 394 FOR_EACH_OBSERVER(CompositorBeginFrameObserver, |
| 395 begin_frame_observer_list_, |
| 396 OnSendBeginFrame(args)); |
| 397 missed_begin_frame_args_ = args; |
| 398 missed_begin_frame_args_.type = cc::BeginFrameArgs::MISSED; |
| 399 } |
| 400 |
362 const cc::LayerTreeDebugState& Compositor::GetLayerTreeDebugState() const { | 401 const cc::LayerTreeDebugState& Compositor::GetLayerTreeDebugState() const { |
363 return host_->debug_state(); | 402 return host_->debug_state(); |
364 } | 403 } |
365 | 404 |
366 void Compositor::SetLayerTreeDebugState( | 405 void Compositor::SetLayerTreeDebugState( |
367 const cc::LayerTreeDebugState& debug_state) { | 406 const cc::LayerTreeDebugState& debug_state) { |
368 host_->SetDebugState(debug_state); | 407 host_->SetDebugState(debug_state); |
369 } | 408 } |
370 | 409 |
371 const cc::RendererSettings& Compositor::GetRendererSettings() const { | 410 const cc::RendererSettings& Compositor::GetRendererSettings() const { |
(...skipping 18 matching lines...) Expand all Loading... |
390 FOR_EACH_OBSERVER(CompositorObserver, | 429 FOR_EACH_OBSERVER(CompositorObserver, |
391 observer_list_, | 430 observer_list_, |
392 OnCompositingLockStateChanged(this)); | 431 OnCompositingLockStateChanged(this)); |
393 } | 432 } |
394 | 433 |
395 void Compositor::CancelCompositorLock() { | 434 void Compositor::CancelCompositorLock() { |
396 if (compositor_lock_) | 435 if (compositor_lock_) |
397 compositor_lock_->CancelLock(); | 436 compositor_lock_->CancelLock(); |
398 } | 437 } |
399 | 438 |
| 439 void Compositor::SetChildrenNeedBeginFrames(bool need_begin_frames) { |
| 440 host_->SetChildrenNeedBeginFrames(need_begin_frames); |
| 441 } |
| 442 |
| 443 void Compositor::SetAuthoritativeVSyncInterval(base::TimeDelta interval) const { |
| 444 host_->SetAuthoritativeVSyncInterval(interval); |
| 445 } |
| 446 |
400 } // namespace ui | 447 } // namespace ui |
OLD | NEW |