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